Skip to content

Commit

Permalink
add Cyberpunk Alias (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
twonirwana authored Sep 3, 2024
1 parent fb36af2 commit dd356b0
Show file tree
Hide file tree
Showing 11 changed files with 874 additions and 533 deletions.
1 change: 1 addition & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ See <<_channel_config>> for channel config
|===
| Alias Name | Alias Function

|`Cyberpunk Red - Alias` | roll with `cp`
|`Dungeon & Dragons 5e - Alias` | roll advantage with `adv` and disadvantage with `dis`
|`Fate - Alias` | roll four fate dice with `4dF`
|`nWod / Chronicles of Darkness - Alias` | roll with `w` e.g. `8w`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ public static Config createConfig(PresetId presetId, Locale userLocale) {
case HEROES_OF_CERULEA ->
new CustomDiceConfig(null, ButtonHelper.parseString(I18n.getMessage("rpg.system.command.preset.HEROES_OF_CERULEA.expression", userLocale)),
AnswerFormatType.without_expression, AnswerInteractionType.none, null, new DiceStyleAndColor(DiceImageStyle.polyhedral_3d, DiceImageStyle.polyhedral_3d.getDefaultColor()), userLocale);
//custom_parameter start expression: val('$fRoll',1d6 col 'white') val('$mRoll',1d6 col 'red') val('$rRoll',1d6 col 'white') val('$modi',{Modificator:-3<=>9}) if(('$fRoll' + '$mRoll' + '$rRoll'=) =? 3,val('$res','$fRoll' + '$mRoll' + '$rRoll'), val('$res','$fRoll' + replace('$mRoll',1,6) + '$rRoll')) val('$total', '$res' + '$modi'=) val('$resTotal','$res' _ ' = ' _ '$total') if('$mRoll'=?1, if(('$fRoll' + '$rRoll'=) =? 12,'$resTotal' _ ' Ultra Fantastic!', ('$fRoll' + '$rRoll'=) =? 2, '$resTotal' _ ' Botch!', '$resTotal' _' Fantastic!'), '$resTotal') answer_format: without_expression dice_image_style: d6_marvel_v2 dice_image_color: white
//custom_parameter start expression: val('$fRoll',1d6 col 'white') val('$mRoll',1d6 col 'red') val('$rRoll',1d6 col 'white') val('$modi',{Modificator:-3<=>9}) if(('$fRoll' + '$mRoll' + '$rRoll'=) =? 3,val('$res','$fRoll' + '$mRoll' + '$rRoll'), val('$res','$fRoll' + replace('$mRoll',1,6) + '$rRoll')) val('$total', '$res' + '$modi'=) val('$resTotal','$res' _ ' = ' _ '$total') if('$mRoll'=?1, if(('$fRoll' + '$rRoll'=) =? 12,'$resTotal' _ ' Ultra Fantastic!', ('$fRoll' + '$rRoll'=) =? 2, '$resTotal' _ ' Botch!', '$resTotal' _' Fantastic!'), '$resTotal') answer_format: without_expression dice_image_style: d6_marvel_v2 dice_image_color: white answer_interaction: reroll
case MARVEL ->
new CustomParameterConfig(null, I18n.getMessage("rpg.system.command.preset.MARVEL.expression", userLocale), AnswerFormatType.without_expression, AnswerInteractionType.none, null, new DiceStyleAndColor(DiceImageStyle.d6_marvel_v2, D6MarvelV2.WHITE), userLocale);
new CustomParameterConfig(null, I18n.getMessage("rpg.system.command.preset.MARVEL.expression", userLocale), AnswerFormatType.without_expression, AnswerInteractionType.reroll, null, new DiceStyleAndColor(DiceImageStyle.d6_marvel_v2, D6MarvelV2.WHITE), userLocale);
case DND5_CALC2 ->
new SumCustomSetConfig(null, ButtonHelper.parseString(I18n.getMessage("rpg.system.command.preset.DND5_CALC2.expression", userLocale)), true, true, false, null, null, AnswerFormatType.without_expression, AnswerInteractionType.none, null, new DiceStyleAndColor(DiceImageStyle.polyhedral_alies_v2, "blue_and_silver"), userLocale);
case PBTA ->
Expand Down Expand Up @@ -235,6 +235,9 @@ public static Config createConfig(PresetId presetId, Locale userLocale) {
// (?<numberOfDice>\\\\d+)b::val('diceRoll', if(${numberOfDice}=?0,2d6L1, ${numberOfDice}d6)) val('sixes','diceRoll'==6c) val('partials','diceRoll'>3<6c) if('sixes'>?1,'Critical Success - You do it with increased effect.', 'sixes'=?1,'Success - You do it.','partials' >? 0,'Partial Success - You do it but suffer severe harm, a serious complication or have reduced effect.','Failure - You suffer severe harm, a serious complication occurs, or you lose this opportunity for action.')@${numberOfDice} Dice
case BLADES_IN_THE_DARK_ALIAS ->
new AliasConfig(ChannelConfigCommand.parseStringToMultiAliasList(I18n.getMessage("rpg.system.command.preset.BLADES_IN_THE_DARK_ALIAS.expression", userLocale)));
case CYBERPUNK_RED_ALIAS ->
new AliasConfig(ChannelConfigCommand.parseStringToMultiAliasList(I18n.getMessage("rpg.system.command.preset.CYBERPUNK_RED_ALIAS.expression", userLocale)));

};
}

Expand Down Expand Up @@ -349,7 +352,8 @@ public enum PresetId {
IRONSWORN,
SALVAGE_UNION,
FALLOUT,
FORBIDDEN_LANDS;
FORBIDDEN_LANDS,
CYBERPUNK_RED_ALIAS;

public static boolean isValid(String in) {
return Arrays.stream(PresetId.values()).anyMatch(s -> s.name().equals(in));
Expand Down
5 changes: 4 additions & 1 deletion bot/src/main/resources/botMessages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ rpg.system.command.preset.OWOD_ALIAS.expression=(?<numberOfDice>\\\\d+)r(?<targe
rpg.system.command.preset.SHADOWRUN_ALIAS.expression=(?<numberOfDice>\\\\d+)sr::val('roll',${numberOfDice}d6) concat('roll'>4c, if('roll'==1c >? 'roll'c/2,' - Glitch!'))@${numberOfDice}d6
rpg.system.command.preset.SAVAGE_WORLDS_ALIAS.expression=r:d!!;sw(?<sides>\\\\d+)::1d!!${sides} + 1d!!6 k1@d${sides} Wildcard
rpg.system.command.preset.BLADES_IN_THE_DARK_ALIAS.expression=(?<numberOfDice>\\\\d+)b::val('diceRoll', if(${numberOfDice}=?0,2d6L1, ${numberOfDice}d6)) val('sixes','diceRoll'==6c) val('partials','diceRoll'>3<6c) if('sixes'>?1,'Critical Success - You do it with increased effect.', 'sixes'=?1,'Success - You do it.','partials' >? 0,'Partial Success - You do it but suffer severe harm, a serious complication or have reduced effect.','Failure - You suffer severe harm, a serious complication occurs, or you lose this opportunity for action.')@${numberOfDice} Dice
rpg.system.command.preset.CYBERPUNK_RED_ALIAS.expression=cp:val('$roll', 1d!10) if('$roll'=?1, '$roll'-1d!10, '$roll')@Roll
#Rpg presets names
rpg.system.command.preset.FATE.name=Fate without Dice Images
rpg.system.command.preset.FATE_IMAGE.name=Fate
Expand Down Expand Up @@ -400,6 +401,7 @@ rpg.system.command.preset.OWOD_ALIAS.name=oWod / Storyteller System - Alias
rpg.system.command.preset.SHADOWRUN_ALIAS.name=Shadowrun - Alias
rpg.system.command.preset.SAVAGE_WORLDS_ALIAS.name=Savage Worlds - Alias
rpg.system.command.preset.BLADES_IN_THE_DARK_ALIAS.name=Blades in the Dark - Alias
rpg.system.command.preset.CYBERPUNK_RED_ALIAS.name=Cyberpunk - Alias
##Rpg presets aliases separated by ;
rpg.system.command.preset.FATE.aliases=Fudge
rpg.system.command.preset.FATE_IMAGE.aliases=Fudge
Expand Down Expand Up @@ -458,4 +460,5 @@ rpg.system.command.preset.NWOD_ALIAS.aliases=World of Darkness;Vampire the Requi
rpg.system.command.preset.OWOD_ALIAS.aliases=World of Darkness;Vampire the Masquerade
rpg.system.command.preset.SHADOWRUN_ALIAS.aliases=
rpg.system.command.preset.SAVAGE_WORLDS_ALIAS.aliases=
rpg.system.command.preset.BLADES_IN_THE_DARK_ALIAS.aliases=
rpg.system.command.preset.BLADES_IN_THE_DARK_ALIAS.aliases=
rpg.system.command.preset.CYBERPUNK_RED_ALIAS.aliases=
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package de.janno.discord.bot.command;

import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;

public final class IncrementingUUIDSupplier implements Supplier<UUID> {

private final AtomicInteger counter = new AtomicInteger(0);

private IncrementingUUIDSupplier() {
}

public static Supplier<UUID> create() {
return new IncrementingUUIDSupplier();
}

@Override
public UUID get() {
return UUID.fromString("00000000-0000-0000-0001-%012d".formatted(counter.getAndIncrement()));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import de.janno.discord.bot.ButtonEventAdaptorMock;
import de.janno.discord.bot.I18n;
import de.janno.discord.bot.SlashEventAdaptorMock;
import de.janno.discord.bot.command.IncrementingUUIDSupplier;
import de.janno.discord.bot.command.channelConfig.AliasHelper;
import de.janno.discord.bot.command.channelConfig.ChannelConfigCommand;
import de.janno.discord.bot.command.customDice.CustomDiceCommand;
Expand All @@ -26,6 +27,7 @@
import reactor.test.StepVerifier;

import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -146,9 +148,10 @@ void quickstartAlias_directRoll(RpgSystemCommandPreset.PresetId presetId, String
void config2CommandString_slashCommand_firstButton(RpgSystemCommandPreset.PresetId presetId, Locale userLocale) {
PersistenceManager persistenceManager = new PersistenceManagerImpl("jdbc:h2:mem:" + UUID.randomUUID(), null, null);
CachingDiceEvaluator cachingDiceEvaluator = new CachingDiceEvaluator((minExcl, maxIncl) -> minExcl + 1);
CustomDiceCommand customDiceCommand = new CustomDiceCommand(persistenceManager, cachingDiceEvaluator);
CustomParameterCommand customParameterCommand = new CustomParameterCommand(persistenceManager, cachingDiceEvaluator);
SumCustomSetCommand sumCustomSetCommand = new SumCustomSetCommand(persistenceManager, cachingDiceEvaluator);
Supplier<UUID> uuidSupplier = IncrementingUUIDSupplier.create();
CustomDiceCommand customDiceCommand = new CustomDiceCommand(persistenceManager, cachingDiceEvaluator, uuidSupplier);
CustomParameterCommand customParameterCommand = new CustomParameterCommand(persistenceManager, cachingDiceEvaluator, uuidSupplier);
SumCustomSetCommand sumCustomSetCommand = new SumCustomSetCommand(persistenceManager, cachingDiceEvaluator, uuidSupplier);
ChannelConfigCommand channelConfigCommand = new ChannelConfigCommand(persistenceManager);

String command = RpgSystemCommandPreset.getCommandString(presetId, userLocale);
Expand All @@ -160,21 +163,21 @@ void config2CommandString_slashCommand_firstButton(RpgSystemCommandPreset.Preset
.name("start")
.options(getOptionsFromString(commandOptions, customDiceCommand))
.build()), userLocale);
slashRes = customDiceCommand.handleSlashCommandEvent(slashEventAdaptor, () -> UUID.fromString("00000000-0000-0000-0000-000000000000"), userLocale);
slashRes = customDiceCommand.handleSlashCommandEvent(slashEventAdaptor, uuidSupplier, userLocale);
} else if (command.startsWith("/custom_parameter start")) {
String commandOptions = command.substring(23);
slashEventAdaptor = new SlashEventAdaptorMock(List.of(CommandInteractionOption.builder()
.name("start")
.options(getOptionsFromString(commandOptions, customParameterCommand))
.build()), userLocale);
slashRes = customParameterCommand.handleSlashCommandEvent(slashEventAdaptor, () -> UUID.fromString("00000000-0000-0000-0000-000000000000"), userLocale);
slashRes = customParameterCommand.handleSlashCommandEvent(slashEventAdaptor, uuidSupplier, userLocale);
} else if (command.startsWith("/sum_custom_set start")) {
String commandOptions = command.substring(21);
slashEventAdaptor = new SlashEventAdaptorMock(List.of(CommandInteractionOption.builder()
.name("start")
.options(getOptionsFromString(commandOptions, sumCustomSetCommand))
.build()), userLocale);
slashRes = sumCustomSetCommand.handleSlashCommandEvent(slashEventAdaptor, () -> UUID.fromString("00000000-0000-0000-0000-000000000000"), userLocale);
slashRes = sumCustomSetCommand.handleSlashCommandEvent(slashEventAdaptor, uuidSupplier, userLocale);
} else if (command.startsWith("/channel_config alias multi_save aliases")) {
String aliases = command.substring(41, command.indexOf("scope:") - 1);
slashEventAdaptor = new SlashEventAdaptorMock(List.of(CommandInteractionOption.builder()
Expand All @@ -191,7 +194,7 @@ void config2CommandString_slashCommand_firstButton(RpgSystemCommandPreset.Preset
.stringValue("all_users_in_this_channel")
.build())
.build()), userLocale);
slashRes = channelConfigCommand.handleSlashCommandEvent(slashEventAdaptor, () -> UUID.fromString("00000000-0000-0000-0000-000000000000"), userLocale);
slashRes = channelConfigCommand.handleSlashCommandEvent(slashEventAdaptor, uuidSupplier, userLocale);
} else {
throw new IllegalStateException("Unknown command for " + presetId);
}
Expand Down
Loading

0 comments on commit dd356b0

Please sign in to comment.