Advertisement
Kovitikus

Remove hands from inventory.

Aug 16th, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.74 KB | None | 0 0
  1. """
  2. The code I'm trying to emulate to check for typeclass, so that the hands aren't listed in the inventory.
  3. https://github.com/evennia/ainneve/blob/develop/world/chargen.py#L614
  4. """
  5.  
  6. """
  7. Traceback (most recent call last):
  8.  File "d:\muddev\evennia\evennia\commands\cmdhandler.py", line 591, in _run_command
  9.    ret = cmd.func()
  10.  File ".\commands\command.py", line 147, in func
  11.    if not item['typeclass'] in ("typeclasses.objects.ObjHands",):
  12. TypeError: 'ObjHands' object is not subscriptable
  13.  
  14. An untrapped error occurred.
  15. (Traceback was logged 19-08-17 00:44:17-04).
  16. """
  17.  
  18. class CmdInventory(Command):
  19.     """
  20.    view inventory
  21.    Usage:
  22.      inventory
  23.      inv
  24.    Shows your inventory.
  25.    """
  26.     key = "inventory"
  27.     aliases = ["inv", "i"]
  28.     locks = "cmd:all()"
  29.     arg_regex = r"$"
  30.  
  31.     def func(self):
  32.         """check inventory"""
  33.         items = self.caller.contents
  34.         if not items:
  35.             string = "You are not carrying anything."
  36.         else:
  37.             table = self.styled_table(border="header")
  38.             for item in items:
  39.                 if not item['typeclass'] in ("typeclasses.objects.ObjHands",):
  40.                     table.add_row("|C%s|n" % item.name, item.db.desc or "")
  41.             string = "|wYou are carrying:\n%s" % table
  42.         self.caller.msg(string)
  43.  
  44.  
  45. """ objects.py where the ObjHands class resides. It's currently empty until I can think of what to put in it."""
  46. from evennia import DefaultObject
  47.  
  48.  
  49. class Object(DefaultObject):
  50.     pass
  51.  
  52. class ObjHands(DefaultObject):
  53.     pass
  54.  
  55.  
  56. """ characters.py where the hands are created """
  57. from evennia import DefaultCharacter
  58. from evennia.utils.create import create_object
  59. from evennia.utils.utils import (list_to_string, inherits_from, lazy_property)
  60. from world.combat_handler import CombatHandler
  61.  
  62.  
  63. class Character(DefaultCharacter):
  64.     pass
  65.  
  66. class Player_Character(DefaultCharacter):
  67.  
  68.     @lazy_property
  69.     def combat(self):
  70.         return CombatHandler(self)
  71.  
  72.     def at_object_creation(self):
  73.         # Stats
  74.         self.attributes.add('gsp', 10)
  75.         self.attributes.add('hp', {'max_hp': 100, 'current_hp': 100})
  76.  
  77.         # Statuses
  78.         self.attributes.add('approached', [])
  79.         self.attributes.add('ko', False)
  80.         self.attributes.add('feinted', None)
  81.         self.attributes.add('busy', False)
  82.  
  83.         # Skills
  84.         self.attributes.add('def_skills', {'weapon': {'high': {}, 'mid': {}, 'low':{}}, 'dodge': {'high': {}, 'mid': {}, 'low':{}}, 'shield': {'high': {}, 'mid': {}, 'low':{}}})
  85.         self.attributes.add('def_rb', {'high': 0, 'mid': 0, 'low': 0})
  86.  
  87.         # Hands
  88.         if not 'left hand' or 'right hand' in self.contents:
  89.             left_hand = create_object(typeclass='objects.ObjHands', key='left hand', location=self, home=self)
  90.             right_hand = create_object(typeclass='objects.ObjHands', key='right hand', location=self, home=self)
  91.             self.attributes.add('left_hand', left_hand.contents)
  92.             self.attributes.add('right_hand', right_hand.contents)
  93.        
  94.        
  95.  
  96.     def return_appearance(self, looker, **kwargs):
  97.         if not looker:
  98.             return ""
  99.        
  100.         # get description, build string
  101.         string  = self.create_desc()
  102.         return string
  103.  
  104.     def create_desc(self):
  105.         desc = ""
  106.        
  107.         figure = self.db.figure
  108.         facial = self.db.facial
  109.         hair = self.db.hair
  110.  
  111.         height = figure.get('height')
  112.         build = figure.get('build')
  113.         sex = figure.get('gender')
  114.  
  115.         eye_color = facial.get('eye_color')
  116.         nose = facial.get('nose')
  117.         lips = facial.get('lips')
  118.         chin = facial.get('chin')
  119.         face = facial.get('face')
  120.         skin_color = facial.get('skin_color')
  121.  
  122.         length = hair.get('length')
  123.         texture = hair.get('texture')
  124.         hair_color = hair.get('hair_color')
  125.         style = hair.get('style')
  126.  
  127.         # The figure should result in "You see a <height> <build> <gender>."
  128.         gender = ('man' if sex == 'male' else 'woman')
  129.         desc += f"You see a {height} {build} {gender}. "
  130.        
  131.         # The facial should result in "He has <color> eyes set above an <shape> nose, <shape> lips and a <shape> chin in a <shape> <color> face."
  132.         gender = ('He' if sex == 'male' else 'She')
  133.         desc += (f"{gender} has {eye_color} eyes set above a {nose} nose, "
  134.                 f"{lips} lips and a {chin} chin in a {face} {skin_color} face. ")
  135.  
  136.         # The hair should result in "<gender> has <length> <texture> <color> hair <style>."
  137.         if length == 'bald':
  138.             desc += f"{gender} is {length}. "
  139.         else:
  140.             desc += f"{gender} has {length} {texture} {hair_color} hair {style}. "
  141.         return desc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement