Advertisement
Guest User

setstats

a guest
Feb 25th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.31 KB | None | 0 0
  1. # -*- coding: UTF-8 -*-
  2.  
  3. from evennia import CmdSet
  4. from commands.command import MuxCommand
  5. from evennia.utils.evmenu import EvMenu
  6. from world import traitcalcs, rulebook
  7.  
  8. from random import randint
  9.  
  10.  
  11. class StatsCmdSet(CmdSet):
  12.     key = "setstats"
  13.  
  14.     def at_cmdset_creation(self):
  15.         """
  16.        Add command to the set - this set will be attached to
  17.        the object (item or room) where setstats is to be done.
  18.        """
  19.         self.add(CmdSetStats())
  20.  
  21.  
  22. class CmdSetStats(MuxCommand):
  23.     """
  24.    Sends initial mesg[0] if never rolled before, then enters into the menu
  25.    asking for roll order, then rolls sets stats as traits and exits.
  26.    """
  27.     key = "setstats"
  28.     locks = "cmd:all()"
  29.  
  30.     def func(self):
  31.         account_caller = True
  32.         char = self.caller
  33.         char.db.setStat = True
  34.         mesg = ("Mercadia uses a method of rolling the dice to create character attributes. "
  35.                 "These attributes are: strength, dexterity, constitution, intelligence, "
  36.                 "wisdom, and charisma. Choose the order of your attributes from the most "
  37.                 "important to your character to the least important.\n\n"
  38.                 "An example is as follows: strength dexterity constitution intelligence "
  39.                 "wisdom charisma\n\n"
  40.                 "You will only be able to roll up to 25 times, so when you see a decent "
  41.                 "roll, you should accept it.", "You may only roll your stats once.")
  42.         if char.traits.STR.actual > 5 or char.traits.INT.actual > 5 or char.traits.WIS.actual > 5 or \
  43.            char.traits.DEX.actual > 5 or char.traits.CON > 5 or char.traits.CHA.actual > 5:
  44.             return self.caller.msg(mesg[1])
  45.         else:
  46.             self.caller.msg(mesg[0])
  47.  
  48.         EvMenu(self.caller, "commands.setstats", startnode="menu_start",
  49.                cmd_on_exit=None, persistent=False,
  50.                stats={"STR": "Strength", "INT": "Intelligence", "WIS": "Wisdom",
  51.                       "DEX": "Dexterity", "CON": "Constitution", "CHA": "Charisma"},
  52.                choice=[], remaining_choices=[], rolls=[], roll_count=25)
  53.  
  54.  
  55. def menu_start(caller, raw_string):
  56.     menu = caller.ndb._menutree
  57.     options = ()
  58.     restart = "x" in raw_string  # Denotes restarting the stat selection process
  59.     choice = menu.choice if menu.choice and not restart else []
  60.     remain = menu.stats.keys() if restart or not menu.remaining_choices else menu.remaining_choices
  61.     start_text = "Choose stat order high to low from the following:\n"
  62.     if raw_string.strip().isdigit() and 1 <= int(raw_string.strip()) <= len(remain):
  63.         # If a stats choice is made, ( 1 through highest choice, up to 6 )
  64.         choice.append(remain.pop(int(raw_string.strip()) - 1))  # move the choice to list of choices.
  65.     text = ("Current Stat order high to low is:\n|w" + ", ".join(choice) + "|n") if choice else start_text
  66.     if len(choice) == 6 and len(remain) == 0:  # if all choices made and none remain...
  67.         text += ("\nAll stats priorities have been chosen."
  68.                  "\nPress [|w|lc|ltEnter|le]|n to begin rolling stat values.")
  69.         if not restart:
  70.             options = ({"key": "_default", "goto": "make_rolls"},)
  71.     else:
  72.         for each in remain:
  73.             options += ({"desc": menu.stats[each], "goto": "menu_start"},)
  74.         options += ({"key": "_default", "goto": "menu_start"},)
  75.     options += ({"desc": "Start again", "key": "X", "goto": "menu_start"},)
  76.     menu.choice = choice
  77.     menu.remaining_choices = remain
  78.     return text, options
  79.  
  80.  
  81. def make_rolls(caller):
  82.     menu = caller.ndb._menutree
  83.     roll_count = menu.roll_count
  84.     roll_count -= 1
  85.     plural = "s" if roll_count != 1 else ""
  86.     rolls = []
  87.     for _ in range(6):
  88.         rolls.append(rulebook.d_roll('4d6-1L'))
  89.     rolls.sort(reverse=True)
  90.     show = []
  91.     choice = menu.choice
  92.     for each in range(6):  # Combine sorted rolls with stat priorities.
  93.         show.append(choice[each] + ": " + str(rolls[each]))
  94.     text = ", ".join(show) + "\n"  # Add newline; more text to come!
  95.     if roll_count:  # Rolls remain to be made.
  96.         text += "You have {count} roll{plural} remaining.".format(count=roll_count, plural=plural)
  97.         options = ({"desc": "Accept this roll.", "key": "A", "goto": "show_stats"},)
  98.         options += ({"desc": "Press [|w|lc|ltEnter|le|n] to roll again.",
  99.                      "key": "E", "goto": "make_rolls"},)
  100.         options += ({"key": "_default", "goto": "make_rolls"},)
  101.     else:  # All rolls have been used.
  102.         text += "Last roll completed. Press enter to continue."
  103.         options = ({"key": "_default", "goto": "show_stats"},)
  104.     menu.rolls = rolls
  105.     menu.roll_count = roll_count
  106.     return text, options
  107.  
  108.  
  109. def show_stats(caller):
  110.  
  111.     menu = caller.ndb._menutree
  112.     rolls = menu.rolls
  113.     choice = menu.choice
  114.     text = "Stats: (before adding race modifiers)\n"
  115.  
  116.     for index, each in enumerate(choice):
  117.         if caller.traits[each] is None:
  118.             caller.traits.add(each, menu.stats[each], "static", rolls[index])
  119.  
  120.         else:
  121.             caller.traits[each].base = rolls[index]
  122.  
  123.         traitcalcs.calculate_secondary_traits(caller.traits)
  124.  
  125.     text += "\n".join([str(caller.traits[each].base) for each in menu.stats.keys()])
  126.     options = None
  127.     return text, options
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement