Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0a3beb2d74 | ||
| 67cffae431 | |||
| 19ff90284a | |||
|
|
6bf306dcc7 | ||
|
|
a215647947 | ||
| 741276e477 | |||
| 4da0d7b1f0 | |||
|
|
2ca9ad6f5a |
@@ -42,6 +42,8 @@ services:
|
|||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- "8080:8080"
|
- "8080:8080"
|
||||||
|
environment:
|
||||||
|
DICE_LIMIT: 30 # OPTIONAL: amount of dice allowed to roll (default: 30)
|
||||||
```
|
```
|
||||||
Run the container with:
|
Run the container with:
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.arindy</groupId>
|
<groupId>de.arindy</groupId>
|
||||||
<artifactId>dice-tower</artifactId>
|
<artifactId>dice-tower</artifactId>
|
||||||
<version>1.2.3</version>
|
<version>1.2.5</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<compiler-plugin.version>3.13.0</compiler-plugin.version>
|
<compiler-plugin.version>3.13.0</compiler-plugin.version>
|
||||||
|
|||||||
@@ -14,12 +14,19 @@ import jakarta.ws.rs.sse.OutboundSseEvent
|
|||||||
import jakarta.ws.rs.sse.Sse
|
import jakarta.ws.rs.sse.Sse
|
||||||
import jakarta.ws.rs.sse.SseBroadcaster
|
import jakarta.ws.rs.sse.SseBroadcaster
|
||||||
import jakarta.ws.rs.sse.SseEventSink
|
import jakarta.ws.rs.sse.SseEventSink
|
||||||
|
import org.eclipse.microprofile.config.inject.ConfigProperty
|
||||||
|
import java.util.Optional
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
|
private const val LIMIT = 30
|
||||||
|
|
||||||
@Path("/dice/{id}")
|
@Path("/dice/{id}")
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
final class DiceResource(@Context val sse: Sse) {
|
final class DiceResource(@Context val sse: Sse) {
|
||||||
|
|
||||||
|
@ConfigProperty(name = "dice.limit")
|
||||||
|
private lateinit var diceLimit: Optional<Int>
|
||||||
|
|
||||||
private var eventBuilder: OutboundSseEvent.Builder = sse.newEventBuilder()
|
private var eventBuilder: OutboundSseEvent.Builder = sse.newEventBuilder()
|
||||||
private var sseBroadcasters: MutableMap<String, SseBroadcaster> = HashMap()
|
private var sseBroadcasters: MutableMap<String, SseBroadcaster> = HashMap()
|
||||||
|
|
||||||
@@ -30,16 +37,25 @@ final class DiceResource(@Context val sse: Sse) {
|
|||||||
data.user = id.split(":")[1]
|
data.user = id.split(":")[1]
|
||||||
|
|
||||||
val results = ArrayList<Results>()
|
val results = ArrayList<Results>()
|
||||||
|
var numberOfDice = 0
|
||||||
data.command.split(" ", "&", "and").filter { it.isNotEmpty() }.map { it.trim() }.toTypedArray<String>().forEach { command ->
|
data.command.split(" ", "&", "and").filter { it.isNotEmpty() }.map { it.trim() }.toTypedArray<String>().forEach { command ->
|
||||||
val dice = command.split("d")
|
val dice = command.split("d")
|
||||||
val result = IntArray(dice[0].toInt())
|
var amount = dice[0].toInt()
|
||||||
|
val limit = diceLimit.orElse(LIMIT)
|
||||||
|
if (limit < numberOfDice + amount) {
|
||||||
|
amount = limit - numberOfDice
|
||||||
|
}
|
||||||
|
numberOfDice += amount
|
||||||
|
if (amount > 0) {
|
||||||
|
val result = IntArray(amount)
|
||||||
val sides = dice[1].split("+", "-")
|
val sides = dice[1].split("+", "-")
|
||||||
val modifier = if (dice[1].contains("+")) sides[1].toInt() else if (dice[1].contains("+")) -1 * sides[1].toInt() else 0
|
val modifier = if (dice[1].contains("+")) sides[1].toInt() else if (dice[1].contains("+")) -1 * sides[1].toInt() else 0
|
||||||
repeat(dice[0].toInt()) { index ->
|
repeat(amount) { index ->
|
||||||
result[index] = (Math.random() * sides[0].toInt() + 1).toInt()
|
result[index] = (Math.random() * sides[0].toInt() + 1).toInt()
|
||||||
}
|
}
|
||||||
results.add(Results(sides[0].toInt(), modifier, result.sum() + modifier, result.map { Roll(it) }.toTypedArray()))
|
results.add(Results(sides[0].toInt(), modifier, result.sum() + modifier, result.map { Roll(it) }.toTypedArray()))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
val map = results.map { r ->
|
val map = results.map { r ->
|
||||||
"${r.rolls.size}d${r.sides}@${
|
"${r.rolls.size}d${r.sides}@${
|
||||||
if (r.sides == 100) r.rolls.map { roll -> Roll(roll.value / 10 * 10) }
|
if (r.sides == 100) r.rolls.map { roll -> Roll(roll.value / 10 * 10) }
|
||||||
|
|||||||
@@ -89,7 +89,7 @@
|
|||||||
<button style="border: transparent; border-radius: 100%; font-size: large; font-weight: bold; height: 50px; width: 50px"
|
<button style="border: transparent; border-radius: 100%; font-size: large; font-weight: bold; height: 50px; width: 50px"
|
||||||
onclick="addDice()">+
|
onclick="addDice()">+
|
||||||
</button>
|
</button>
|
||||||
<button style="font-size: large; font-weight: bold;" onclick="rollEasy('d2')">D2</button>
|
<!--<button style="font-size: large; font-weight: bold;" onclick="rollEasy('d2')">D2</button><-->
|
||||||
<button style="font-size: large; font-weight: bold;" onclick="rollEasy('d4')">D4</button>
|
<button style="font-size: large; font-weight: bold;" onclick="rollEasy('d4')">D4</button>
|
||||||
<button style="font-size: large; font-weight: bold;" onclick="rollEasy('d6')">D6</button>
|
<button style="font-size: large; font-weight: bold;" onclick="rollEasy('d6')">D6</button>
|
||||||
<button style="font-size: large; font-weight: bold;" onclick="rollEasy('d8')">D8</button>
|
<button style="font-size: large; font-weight: bold;" onclick="rollEasy('d8')">D8</button>
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
foreground: data.numberColor
|
foreground: data.numberColor
|
||||||
}
|
}
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
diceBox.roll(data.roll.join('&'));
|
diceBox.roll(data.roll.filter(it => it.split('@')[0].split('d')[1] !== "2").join('&'));
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user