commit 1ae050c3b2bc90c7d7c86413530ff947bfc7852e Author: silverwizard Date: Fri Jun 18 21:19:40 2021 -0400 Created basic tools for Shadowrun dice diff --git a/README.md b/README.md new file mode 100644 index 0000000..b338411 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +A simple plugin for [JJMumbleBot](https://duckboss.github.io/JJMumbleBot/wiki/new/whats_new.html) which should do basic dice. See the !help shadowdice command for options. + +Simply drop this file in the extensions folder for JJMumbleBot and it should just start working diff --git a/__pycache__/shadowdice.cpython-38.pyc b/__pycache__/shadowdice.cpython-38.pyc new file mode 100644 index 0000000..2b9659b Binary files /dev/null and b/__pycache__/shadowdice.cpython-38.pyc differ diff --git a/aliases.csv b/aliases.csv new file mode 100644 index 0000000..18daf09 --- /dev/null +++ b/aliases.csv @@ -0,0 +1,2 @@ +alias,command +predge,(preedge) diff --git a/help.html b/help.html new file mode 100644 index 0000000..19f638d --- /dev/null +++ b/help.html @@ -0,0 +1,9 @@ +All commands can be run by typing it in the chat or privately messaging JJMumbleBot.
+!init: Roll init dice !init 4 11 will roll 4d6+11
+!srun: Roll a bunch of dice, count successes and ones !srun 12 will roll a pool of 12 dice
+!preedge: Roll a pool with exploding 6s, counts successes, ones, and explosions !preedge 12 will roll a poll of 12 dice
+!assensing: Prints the Shadowrun assensing table
+!concealability: Prints the Shadowrun concealability modifiers table
+!perception_mods: Prints the Shadowrun perception modifiers table
+!delivery: Prints the Shadowrun delivery times table
+!environmental: Prints the Shadowrun environmental modifiers table
diff --git a/metadata.ini b/metadata.ini new file mode 100644 index 0000000..9c7d0ce --- /dev/null +++ b/metadata.ini @@ -0,0 +1,29 @@ +[Plugin Information] +PluginVersion = 1.0.0 +PluginName = Shadow Dice +PluginDescription = A plugin for rolling dice in Shadowrun 5e. +PluginLanguage = EN +PluginCommands: [ + "init", + "srun", + "preedge", + "assensing", + "delivery", + "perception_mods", + "environmental", + "concealability" + ] + +[Plugin Settings] +; List commands that need the core thread to wait for completion. +; This may include processes that require multiple commands in succession. +; For example: [Youtube Plugin - !yt -> !p] process requires 2 commands in that order. +ThreadWaitForCommands: [] +UseSingleThread = False + +[Plugin Type] +ControllablePlugin = True +AudioPlugin = False +ImagePlugin = False +CorePlugin = False +ExtensionPlugin = True diff --git a/privileges.csv b/privileges.csv new file mode 100644 index 0000000..f2deeff --- /dev/null +++ b/privileges.csv @@ -0,0 +1,5 @@ +command,level +init,1 +srun,1 +preedge,1 +assensing,1 diff --git a/resources/__pycache__/strings.cpython-38.pyc b/resources/__pycache__/strings.cpython-38.pyc new file mode 100644 index 0000000..1ec22b7 Binary files /dev/null and b/resources/__pycache__/strings.cpython-38.pyc differ diff --git a/resources/strings.py b/resources/strings.py new file mode 100644 index 0000000..c92797f --- /dev/null +++ b/resources/strings.py @@ -0,0 +1,10 @@ +from JJMumbleBot.lib.utils.runtime_utils import get_command_token + +########################################################################### +# RANDOMIZER PLUGIN CONFIG PARAMETER STRINGS + +# COMMAND ERROR STRINGS +CMD_INVALID_CUSTOM_ROLL = [ + "ERROR: Incorrect command formatting!", + f"Format: {get_command_token()}customroll 'number_of_dice' 'dice_faces'" +] diff --git a/shadowdice.py b/shadowdice.py new file mode 100644 index 0000000..8c9c7ec --- /dev/null +++ b/shadowdice.py @@ -0,0 +1,141 @@ +from JJMumbleBot.lib.plugin_template import PluginBase +from JJMumbleBot.lib.utils.plugin_utils import PluginUtilityService +from JJMumbleBot.lib.utils.logging_utils import log +from JJMumbleBot.lib.utils.print_utils import PrintMode +from JJMumbleBot.plugins.extensions.randomizer.resources.strings import CMD_INVALID_CUSTOM_ROLL +from JJMumbleBot.settings import global_settings as gs +from JJMumbleBot.lib.resources.strings import * +import os +import random + + +class Plugin(PluginBase): + def __init__(self): + super().__init__() + from json import loads + self.plugin_name = os.path.basename(__file__).rsplit('.')[0] + self.metadata = PluginUtilityService.process_metadata(f'plugins/extensions/{self.plugin_name}') + self.plugin_cmds = loads(self.metadata.get(C_PLUGIN_INFO, P_PLUGIN_CMDS)) + self.is_running = True + log( + INFO, + f"{self.metadata[C_PLUGIN_INFO][P_PLUGIN_NAME]} v{self.metadata[C_PLUGIN_INFO][P_PLUGIN_VERS]} Plugin Initialized.", + origin=L_STARTUP, + print_mode=PrintMode.REG_PRINT.value + ) + + def quit(self): + self.is_running = False + log( + INFO, + f"Exiting {self.plugin_name} plugin...", + origin=L_SHUTDOWN, + print_mode=PrintMode.REG_PRINT.value + ) + + def stop(self): + if self.is_running: + self.quit() + + def start(self): + if not self.is_running: + self.__init__() + + def cmd_init(self, data): + all_data = data.message.strip().split() + try: + number_of_dice = int(all_data[1]) + init_bonus = int(all_data[2]) + ret_text = "
Init Roll:
" + result = 0 + for i in range(number_of_dice): + random.seed(int.from_bytes(os.urandom(8), byteorder="big")) + this_die = random.randint(1,6) + result = result + this_die + ret_text += f"{this_die} + " + result = result + init_bonus + ret_text += f" {init_bonus}
{result}" + gs.gui_service.quick_gui(ret_text, text_type='header', box_align='left') + return + except IndexError: + log(ERROR, CMD_INVALID_CUSTOM_ROLL, + origin=L_COMMAND, error_type=CMD_INVALID_ERR, print_mode=PrintMode.VERBOSE_PRINT.value) + gs.gui_service.quick_gui(CMD_INVALID_CUSTOM_ROLL, + text_type='header', box_align='left') + return + + def cmd_srun(self, data): + all_data = data.message.strip().split() + try: + number_of_dice = int(all_data[1]) + ret_text = "
Die Pool:
" + successes = 0 + ones = 0 + for i in range(number_of_dice): + random.seed(int.from_bytes(os.urandom(8), byteorder="big")) + this_die = random.randint(1,6) + ret_text += f"{this_die}, " + if this_die > 4: + successes = successes + 1 + if this_die == 1: + ones = ones + 1 + ret_text += f"
Successes: {successes} , Ones: {ones}" + gs.gui_service.quick_gui(ret_text, text_type='header', box_align='left') + return + except IndexError: + log(ERROR, CMD_INVALID_CUSTOM_ROLL, + origin=L_COMMAND, error_type=CMD_INVALID_ERR, print_mode=PrintMode.VERBOSE_PRINT.value) + gs.gui_service.quick_gui(CMD_INVALID_CUSTOM_ROLL, + text_type='header', box_align='left') + return + + def cmd_preedge(self, data): + all_data = data.message.strip().split() + try: + number_of_dice = int(all_data[1]) + ret_text = "
Die Pool:
" + successes = 0 + ones = 0 + explosions = 0 + i = 0 + while i < number_of_dice: + random.seed(int.from_bytes(os.urandom(8), byteorder="big")) + this_die = random.randint(1,6) + ret_text += f"{this_die}, " + if this_die > 4: + successes = successes + 1 + if this_die == 1: + ones = ones + 1 + if this_die == 6: + i = i-1 + explosions = explosions + 1 + i = i + 1 + ret_text += f"
Successes: {successes} , Ones: {ones} , Explosions: {explosions}" + gs.gui_service.quick_gui(ret_text, text_type='header', box_align='left') + return + except IndexError: + log(ERROR, CMD_INVALID_CUSTOM_ROLL, + origin=L_COMMAND, error_type=CMD_INVALID_ERR, print_mode=PrintMode.VERBOSE_PRINT.value) + gs.gui_service.quick_gui(CMD_INVALID_CUSTOM_ROLL, + text_type='header', box_align='left') + return + + def cmd_assensing(self, data): + ret_text = "
ASSENSING TABLE
HITSINFORMATION GAINED
0None
1The general state of the subject’s health (healthy, injured, ill, etc.). The subject’s general emotional state or impression (happy, sad, angry, etc.). Whether the subject is mundane or Awakened.
2The presence and location of cyberware implants. The class of a magical subject (fire elemental, manipulation spell, power focus, curse ritual, and so on). If you have seen the subject’s aura before, you may recognize it, regardless of physical disguises or alterations
3The presence and location of alphaware cyber implants. Whether the subject’s Essence and Magic are higher, lower, or equal to your own. Whether the subject’s Force is higher, lower, or equal to your Magic. A general diagnosis for any maladies (diseases or toxins) the subject suffers. Any astral signatures present on the subject.
4The presence and location of bioware implants and betaware cyber implants. The exact Essence, Magic, and Force of the subject. The general cause of any astral signature (combat spell, alchemical combat spell, air spirit, and so on).
5+The presence and location of deltaware implants, gene treatments, and nanotech. An accurate diagnosis of any disease or toxins which afflict the subject. The fact that a subject is a technomancer.
" + gs.gui_service.quick_gui(ret_text, text_type='header', box_align='center') + + def cmd_delivery(self, data): + ret_text = "
DELIVERY TIMES TABLE
GEAR COST DELIVERY TIME
Up to 100¥ 6 hours
101¥ to 1,000¥ 1 day
1,000¥ to 10,000¥ 2 days
10,001 to 100,000¥ 1 week
More than 100,000¥ 1 month
" + gs.gui_service.quick_gui(ret_text, text_type='header', box_align='center') + + def cmd_concealability(self, data): + ret_text = "
CONCEALABILITY MODIFIERS *Applies to observer
MODIFIER* EXAMPLE ITEMS
–6 RFID tag, bug slap patch, microdrone, contact lenses
–4 Hold-out pistol, monowhip, ammo clip, credstick, chips/softs, sequencer/passkey, autopicker, lockpick set, commlink, glasses
–2 Light pistol, knife, sap, minidrone, microgrenade, flash-pak, jammer, cyberdeck, rigger command console
0 Heavy pistol, machine pistol with folding stock collapsed, grenade, goggles, ammo belt/drum, club, extendable baton (collapsed)
+2 SMG, machine pistol with folding stock extended, medkit, small drone, extendable baton (extended), stun baton
+4 Sword, sawed-off shotgun, bullpup assault rifle
+6 Katana, monosword, shotgun, assault rifle, sport rifle, crossbow
+8 Sniper rifle, bow, grenade launcher, medium drone
+10/Forget about it Machine gun, rocket launcher, missile launcher, staff, claymore, metahuman body
" + gs.gui_service.quick_gui(ret_text, text_type='header', box_align='center') + + def cmd_perception_mods(self, data): + ret_text = "
PERCEPTION TEST MODIFIERS
SITUATION DICE POOL MODIFIER
Perceiver is distracted -2
Perciever is specifically looking/listening for it +3
Object/sound not in immediate vicinity -2
Object/sound far away -3
Object/sound stands out in some way +2
Interfering sight/odor/sound -2
Perceiver has active enhancements + Rating
Visibility and Light Environmental Factors (Above)
PERCEPTION THRESHOLDS
ITEM/EVENT IS: THRESHOLD EXAMPLES
Obvious 1 Neon sign, running crowd, yelling, gunfire
Normal 2 Street sign, pedestrian, conversation, silenced gunfire
Obscured/Small/Muffled 3 Item dropped under table, contact lens, whispering
Hidden/Micro/Silent 4 Secret door, needle in haystack, subvocal speech
" + gs.gui_service.quick_gui(ret_text, text_type='header', box_align='center') + + def cmd_environmental(self, data): + ret_text = "
ENVIRONMENTAL
VISIBILITY LIGHT / GLARE WIND RANGE MODIFIER
Clear Full Light / No Glare None / Light Breeze Short 0
Light Rain / Fog / Smoke Partial Light / Weak Glare Light Winds / Light Breeze Medium -1
Moderate Rain / Fog / Smoke Dim Light / Moderate Glare Moderate Winds / Light Breeze Long -3
Heavy Rain / Fog / Smoke Total Darkness/ Blinding Glare Strong Winds / Light Breeze Extreme -6
Combination of two or more conditions at the -6 level row -10
" + gs.gui_service.quick_gui(ret_text, text_type='header', box_align='center') diff --git a/tests/test_randomizer_metadata.py b/tests/test_randomizer_metadata.py new file mode 100644 index 0000000..f3abda3 --- /dev/null +++ b/tests/test_randomizer_metadata.py @@ -0,0 +1,23 @@ +import configparser +from json import loads +from JJMumbleBot.lib.utils.dir_utils import get_extension_plugin_dir +from JJMumbleBot.lib.resources.strings import C_PLUGIN_INFO, P_PLUGIN_VERS, P_PLUGIN_CMDS, C_PLUGIN_SET +from JJMumbleBot.plugins.extensions.randomizer.randomizer import Plugin + + +class TestRandomizer: + def setup_method(self): + # Initialize configs. + self.cfg = configparser.ConfigParser() + self.cfg.read(f"{get_extension_plugin_dir()}/randomizer/metadata.ini") + + def test_plugin_version(self): + assert self.cfg[C_PLUGIN_INFO][P_PLUGIN_VERS] == "1.0.0" + + def test_commands_list_size(self): + commands_list = list(loads(self.cfg[C_PLUGIN_INFO][P_PLUGIN_CMDS])) + assert len(commands_list) == 3 + + def test_match_commands_to_methods(self): + method_list = [item for item in dir(Plugin) if callable(getattr(Plugin, item)) and item.startswith("cmd_")] + assert len(method_list) == len(list(loads(self.cfg[C_PLUGIN_INFO][P_PLUGIN_CMDS])))