Skip to content

Instantly share code, notes, and snippets.

@Petteri
Created October 14, 2022 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Petteri/c2671c5959e74f19c3b01cdfa5949641 to your computer and use it in GitHub Desktop.
Save Petteri/c2671c5959e74f19c3b01cdfa5949641 to your computer and use it in GitHub Desktop.
Cthulhu Skillroll
def ct(bot, trigger):
def help():
bot.say("ohje [kykyheitto]: .ct kyky <arvo>")
bot.say("ohje [kokemusheitt]: .cti kyky <arvo>")
bot.say("esimerkki: .ct psykologia 50")
def validate_skill_value(value):
skillnumber = 0
bonus = 0
penalty = 0
if "e" in value: # etu
skillnumber, bonus = value.split("e")
elif "s" in value: # sakko
skillnumber, penalty = value.split("s")
else:
skillnumber = int(value)
bonus = int(bonus) - int(penalty)
return (int(skillnumber), int(bonus))
def dice_rolls(bonus):
rolls = list()
for x in range(0, abs(bonus) +1):
if x == 0:
d100 = random.randint(1, 100)
ones = d100%10
rolls.append(d100)
else:
bonus_roll = int("%d%d" % (random.randint(0, 9), ones))
if bonus_roll == 0:
bonus_roll = 100
rolls.append(bonus_roll)
orig_roll = rolls[0]
if bonus < 0:
rolls = sorted(rolls, reverse=True)
elif bonus > 0:
rolls = sorted(rolls)
return (orig_roll, rolls)
if trigger.group(2) is None:
return help()
else:
cmd = str(trigger.group(2))
try:
cmd_tokens = cmd.split()
value = cmd_tokens[-1]
skill = " ".join(cmd_tokens[:-1])
value, bonus = validate_skill_value(value)
except:
return help()
success_regular = value
success_hard = math.floor(value/2)
success_extreme = math.floor(value/5)
orig_roll, rolls = dice_rolls(bonus)
dice_roll = rolls[0]
rolls_str = bold(str(rolls[0]))
i_str = ""
if len(rolls) > 1:
orig_handled = False
for i in rolls:
if i == orig_roll and orig_handled == False:
i_str += bold("%s" % i)
orig_handled = True
else:
i_str += "%s" % i
i_str += ", "
i_str = "[%s]" % i_str[:-2]
rolls_str = "%s %s" % (rolls_str, i_str)
prefix = "%s %s (%d/%d): d100 = %s" % \
(skill, bold(str(success_regular)),
success_hard, success_extreme,
rolls_str)
if dice_roll == 1:
suffix = "%s" % (color("kriittinen onnistuminen", colors.PINK))
elif success_extreme >= dice_roll:
suffix = "%s" % (color("äärimmäinen onnistuminen", colors.RED))
elif success_hard >= dice_roll:
suffix = "%s" % (color("vaikea onnistuminen", colors.YELLOW))
elif success_regular >= dice_roll:
suffix = "%s" % (color("onnistuminen", colors.GREEN))
elif (value >= 50 and dice_roll == 100) or \
(value < 50 and dice_roll > 95):
suffix = "%s 😖" % ("kompurointi")
else:
suffix = "epäonnistuminen"
bot.reply("%s %s" % (prefix, suffix))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment