Skip to content

Commit

Permalink
Blades in the Dark - Detail and Welcome update (#474)
Browse files Browse the repository at this point in the history
* Blades in the Dark - Detail and Welcome update

* update dice evaluator lib
  • Loading branch information
twonirwana authored Mar 18, 2024
1 parent f525604 commit dd7b3b5
Show file tree
Hide file tree
Showing 35 changed files with 519 additions and 315 deletions.
8 changes: 5 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Please let me know if you have a good new preset or an improved version for an e
|===
|`A Song of Ice and Fire`
|`Blades in the Dark`
|`Blades in the Dark - Detail`
|`Blades in the Dark without Dice Images`
|`Bluebeard's Bride`
|`Call of Cthulhu 7th Edition`
Expand Down Expand Up @@ -581,7 +582,7 @@ All operators are case insensitiv.
|===
|Name |Notation |Example |Description |Precedent |Associativity |Left parameter |Right parameter
|Repeat |`<number>x<expression>` |`3x2d6` |Repeats the expression separately a number of times given in <number>. This should be used outside other expressions and will not work inside most expressions |0 |left |a single integer number between 1-10 | a expression
|List Repeat |`<number>r<expression>` |`3r(2d6=)` |Repeats the expression a number of times given in <number> and combines the results in one list. |1 |left |a single integer number between 0-10 | a expression
|List Repeat |`<number>r<expression>` |`3r(2d6=)` |Repeats the expression a number of times given in <number> and combines the results in one list. |1 |left |a single integer number between 0-20 | a expression
| Concat |`<expression>_<expression>` |`d20_'dmg''` | Combines the result of both expression into on single element |2 |left |one or more elements | one or more elements
|Or |`<boolean>\|\|<boolean>` |`d6=?5 \|\| d6=?6` | Boolean or operation of the two boolean values | 3 |left | boolean value | boolean value
|And |`<boolean>&&<boolean>` |`d6=?5 && d6=?6` | Boolean and operation of the two boolean values | 4 |left | boolean value | boolean value
Expand All @@ -596,7 +597,7 @@ All operators are case insensitiv.
|Modulo |`<left> mod <right>` |`d6 mod 2` | returns the remainder of the division |13 |left |a single integer number |a single non zero integer number
|Multiply |`<left> * <right>` |`2 * 6` |Multiplies the right number with the left number |14|left |a single number |a single number
|Divide |`<left> / <right>` |`4 / 2` |Divides the right number with the left number and rounds down to the next full number |15 |left |a single integer number |a single integer number
|Decimal Divide |`<left> // <right>` |`4 / 2` |Divides the right number with the left number and provides a decimal number with up to 5 decimal digital |16 |left |a single number |a single number
|Decimal Divide |`<left> // <right>` |`4 // 3` |Divides the right number with the left number and provides a decimal number with up to 5 decimal digital |16 |left |a single number |a single number
|Count |`<list> c` |`3d6>3c` |Counts the number of elements in a list |17 |left |a list |-
|Greater Then Filter |`<list> > <number>` |`3d6>3` |Keeps only the elements of the left list that are bigger as the right number. Applies only to elements with the same tag. |18 |left |one or more numbers |a single number
|Lesser Then Filter |`<list> < <number>` |`3d6<3` |Keeps only the elements of the left list that are lesser as the right number. Applies only to elements with the same tag. |19 |left |one or more numbers |a single number
Expand Down Expand Up @@ -627,7 +628,8 @@ All functions are case insensitiv.
|sort asc |`asc(<expression1>, <expression2> ...)` |`asc(4d6)` |sorts all elements ascending of one or more inner expressions. Text is compared alphabetically
|sort desc |`desc(<expression1>, <expression2> ...)` |`desc(4d6)` |sorts all elements descending of one or more inner expressions. Text is compared alphabetically
|cancel |`cancel(<expression>, <listA>, <listB>)` |`cancel(8d10, 10, 1)` |the elements of listA and listB (can also be single elements) cancel each other and remove each other from the result.
|replace |`replace(<expression>, <find>, <replace> ...)` |`replace(8d10, [9/10], 'bonus')` | each element in `<expression>` that matches on of the elements in `<find>` will be replaced with the elements in `<replace>`. `<replace>` can be an empty list `[]` or literal `''` and thereby removing the found elements. It is possible to add multiple <find>/<replace> pairs to replace different elements in one replace.
|replace |`replace(<expression>, <find>, <replace> ...)` |`replace(8d10, [9/10], 'bonus')` | each element in `<expression>` that matches on of the elements in `<find>` will be replaced with the elements in `<replace>`. `<replace>` can be an empty list `[]` or literal `''` and thereby removing the found elements. It is possible to add multiple <find>/<replace> pairs to replace different elements in one replace. If the <replace> expression contains dice then they will only be rolled on a matching find element and for each matching element again.
|explode |`exp(<roll>,<rerollOnList>,<numberOfRerolls>` |`exp(d[1/2/3],[2/3])` or `exp(d[1/2/3],[2/3], 2)` | Rerolls the `<roll>` expression if any of its result elements are in the elements of `<rerollOnList>` and returns the original result and all reroll results. If `<roll>` contain more then one die then all are rerolled, even if only on result of one die matches the reroll list. `<numberOfRerolls>` define the maximum number of rerolls bevor the function stops with rerolls and returns the current result. `<numberOfRerolls>` must be a number between 0 and 100. If `<numberOfRerolls>` is not provided as argument then 100 will be used.
|if |`if(<boolean>,<true>,<false>)` |`if(1d6=?6,'six','not six')` or `if(1d6=?6,'six')` or `val('$r',1d6), if('$r'=?1,'one','$r'=?2,'two','else') |if `<boolean>` equal true then return the `<true>` expression or else the `<false>` expression. The `<false>` expression is optional, if it is missing and `<boolean>` is `false` then the result empty. It is possible to add more than `<boolean>,<true>` pair in the function, the result will be the `<true>` of the first true `<boolean>`, coming from left. All <boolean> must be non-empty and contain only on element (therefor can't contain only `val`). `val` are will only set in the first <true>. Use the following structure to use `if` to set different value in a `val`: `if(1d6>?4, val('$a',10), val('$a',-10))`, this will set '$a' to 10 if the 1d6 roll is bigger than 4 and to -10 otherwise.
|group count |`groupC(<expression1>, <expression2> ...)` |`groupC(20d6)` | counts all elements of with the same value and provides the results as list in the format of `<count>x<value>`
|concatenate |`concat(<expression1>, <expression2> ...)` |`concat('Attack: ', 2d20, ' Damage:', 3d6+5=)` | Joining all expressions together to a single result.
Expand Down
2 changes: 1 addition & 1 deletion bot/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repositories {
dependencies {
implementation(project(":discord-connector"))
implementation("com.github.twonirwana:dice-parser:0.7.1")
implementation("io.github.twonirwana:dice-evaluator:v0.5.8")
implementation("io.github.twonirwana:dice-evaluator:v0.6.1")

implementation(libs.log4j.to.slf4j)
implementation(libs.reactor.core)
Expand Down
7 changes: 5 additions & 2 deletions bot/src/main/java/de/janno/discord/bot/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


import com.google.common.base.Strings;
import de.janno.discord.bot.command.FetchCommand;
import de.janno.discord.bot.command.ClearCommand;
import de.janno.discord.bot.command.FetchCommand;
import de.janno.discord.bot.command.channelConfig.ChannelConfigCommand;
import de.janno.discord.bot.command.countSuccesses.CountSuccessesCommand;
import de.janno.discord.bot.command.customDice.CustomDiceCommand;
Expand Down Expand Up @@ -54,7 +54,10 @@ public static void main(final String[] args) throws Exception {
Set<Long> allGuildIdsInPersistence = persistenceManager.getAllGuildIds();
CachingDiceEvaluator cachingDiceEvaluator = new CachingDiceEvaluator(new RandomNumberSupplier(),
Config.getInt("diceEvaluator.maxNumberOfDice", 1000),
Config.getInt("diceEvaluator.cacheSize", 10_000));
Config.getInt("diceEvaluator.cacheSize", 10_000),
Config.getInt("diceEvaluator.maxNumberOfElements", 10_000),
Config.getBool("diceEvaluator.keepChildrenRolls", false)
);

CustomDiceCommand customDiceCommand = new CustomDiceCommand(persistenceManager, cachingDiceEvaluator);
CustomParameterCommand customParameterCommand = new CustomParameterCommand(persistenceManager, cachingDiceEvaluator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ private boolean hasAnySelectedValues(@Nullable State<CustomParameterStateData> s
@Override
protected @NonNull Optional<String> getStartOptionsValidationMessage(@NonNull CommandInteractionOption options, long channelId, long userId, @NonNull Locale userLocale) {
String baseExpression = options.getStringSubOptionWithName(EXPRESSION_OPTION_NAME).orElse("");
log.info("Start validating: {}", baseExpression.replace("\n", " "));
log.trace("Start validating: {}", baseExpression.replace("\n", " "));
int variableCount = 0;
Matcher variableMatcher = PARAMETER_VARIABLE_PATTERN.matcher(baseExpression);
while (variableMatcher.find()) {
Expand Down Expand Up @@ -559,7 +559,7 @@ private Optional<String> validateAllPossibleStates(CustomParameterConfig config)
.map(s -> validateStateWithCustomIdAndParameter(config, s))
.filter(Objects::nonNull)
.findFirst();
log.info("{} with parameter options {} in {}ms validated",
log.debug("{} with parameter options {} in {}ms validated",
config.getBaseExpression().replace("\n", " "),
config.getParameters(),
stopwatch.elapsed(TimeUnit.MILLISECONDS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import de.janno.discord.connector.api.message.EmbedOrMessageDefinition;
import lombok.AllArgsConstructor;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
Expand Down Expand Up @@ -94,6 +95,9 @@ public static Config createConfig(PresetId presetId, Locale userLocale) {
case BLADES_IN_THE_DARK_IMAGE ->
new CustomParameterConfig(null, I18n.getMessage("rpg.system.command.preset.BLADES_IN_THE_DARK.expression", userLocale),
DiceParserSystem.DICE_EVALUATOR, AnswerFormatType.without_expression, null, new DiceStyleAndColor(DiceImageStyle.polyhedral_RdD, DiceImageStyle.polyhedral_RdD.getDefaultColor()), userLocale);
case BLADES_IN_THE_DARK_DETAIL ->
new CustomParameterConfig(null, I18n.getMessage("rpg.system.command.preset.BLADES_IN_THE_DARK_DETAIL.expression", userLocale),
DiceParserSystem.DICE_EVALUATOR, AnswerFormatType.without_expression, null, new DiceStyleAndColor(DiceImageStyle.polyhedral_RdD, DiceImageStyle.polyhedral_RdD.getDefaultColor()), userLocale);
//7th Edition Call of Cthulhu: custom_dice start buttons: 1d100; 2d100L1@1d100 Advantage; 2d100K1@1d100 Penalty; 1d3; 1d4; 1d6; 1d8; 1d10; 1d12; 1d20; 3d6
case CALL_OF_CTHULHU_7ED ->
new CustomDiceConfig(null, ButtonHelper.parseString(I18n.getMessage("rpg.system.command.preset.CALL_OF_CTHULHU_7ED.expression", userLocale)),
Expand Down Expand Up @@ -242,6 +246,7 @@ public enum PresetId {
TRAVELLER,
BLADES_IN_THE_DARK,
BLADES_IN_THE_DARK_IMAGE,
BLADES_IN_THE_DARK_DETAIL,
CALL_OF_CTHULHU_7ED,
EXALTED_3ED,
VAMPIRE_5ED,
Expand Down Expand Up @@ -284,5 +289,9 @@ public List<String> getSynonymes(Locale locale) {
}
return List.of(aliasString);
}

public static boolean isValid(String in) {
return Arrays.stream(PresetId.values()).anyMatch(s -> s.name().equals(in));
}
}
}
Loading

0 comments on commit dd7b3b5

Please sign in to comment.