Changeset 722


Ignore:
Timestamp:
02/11/11 22:53:39 (8 years ago)
Author:
technomage
Message:

Patch by Technomage

  • Added a new module, scripts/characterstatistics.py, which implements primary and secondary character stats logic;
  • Added a yEdit UML diagram describing the new character statistics module;
  • Added a few "mock" primary and secondary character stats XML scripts in the new character_scripts directory - the syntax is mostly solidified;
  • Modified the CharacterBase? class in scripts/objects/actors.py by adding a primary_stats and secondary_stats attribute which can be initialized in the constructor;
  • Fixed a bug in the dedent_chomp method defined in scripts/common/utils.py which caused an extra space to be added to the last line of the output string;
Location:
branches/active/character_customization/game
Files:
6 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/active/character_customization/game/scripts/common/utils.py

    r707 r722  
    5252    """Remove common leading whitespace and chomp each non-blank line.""" 
    5353    dedented_string = dedent(string).strip() 
    54     lines = [] 
    55     for line in dedented_string.splitlines(): 
    56         if not line or line.isspace(): 
     54    lines = dedented_string.splitlines() 
     55    formatted_lines = [] 
     56    for index in range(len(lines)): 
     57        line = lines[index] 
     58        if index == len(lines) - 1: 
     59            # Don't do anything to the last line. 
     60            pass 
     61        elif not line or line.isspace(): 
    5762            line = '\n\n' 
    5863        else: 
    5964            line = ''.join([line, ' ']) 
    60         lines.append(line) 
    61     result = ''.join(lines) 
     65        formatted_lines.append(line) 
     66    result = ''.join(formatted_lines) 
    6267    return result 
  • branches/active/character_customization/game/scripts/objects/actors.py

    r704 r722  
    2828"""All actors go here. Concrete classes only.""" 
    2929 
    30 __all__ = ["PlayerCharacter", "NonPlayerCharacter",] 
     30__all__ = ["PlayerCharacter", "NonPlayerCharacter", ] 
    3131 
    3232Settings = loadSettings() 
     
    5353        self.state = _AGENT_STATE_NONE 
    5454        # TODO: rework/improve 
    55         self.speed = Settings.get("PARPG", "PCSpeed")-1 
     55        self.speed = Settings.get("PARPG", "PCSpeed") - 1 
    5656         
    5757    def getX(self): 
     
    8686 
    8787class PCBehaviour (ActorBehaviour): 
    88     def __init__(self, parent = None, layer = None): 
     88    def __init__(self, parent=None, layer=None): 
    8989        super(PCBehaviour, self).__init__(layer)         
    9090        self.parent = parent 
     
    116116 
    117117class NPCBehaviour(ActorBehaviour): 
    118     def __init__(self, Parent = None, Layer = None): 
     118    def __init__(self, Parent=None, Layer=None): 
    119119        super(NPCBehaviour, self).__init__(Layer) 
    120120         
     
    193193            self.agent.act('stand', self.pc.getLocation()) 
    194194             
    195 class CharacterBase(GameObject, Living, CharStats): 
     195class CharacterBase(GameObject, CharStats, Living): 
    196196    """Base class for Characters""" 
    197     def __init__(self, ID, agent_layer = None, inventory = None,  
    198                  text = "", **kwargs): 
    199         GameObject.__init__( self, ID, text = text, **kwargs ) 
    200         Living.__init__( self, **kwargs ) 
    201         CharStats.__init__( self, **kwargs ) 
    202          
     197    def __init__(self, ID, agent_layer=None, inventory=None, text="", 
     198                 primary_stats=None, secondary_stats=None, **kwargs): 
     199        GameObject.__init__(self, ID, text=text, **kwargs) 
     200        CharStats.__init__(self, **kwargs) 
     201        Living.__init__(self, **kwargs) 
     202        self.statistics = {} 
     203        if primary_stats is not None: 
     204            for primary_stat in primary_stats: 
     205                name = primary_stat.name 
     206                self.statistics[name] = primary_stat 
     207        if secondary_stats is not None: 
     208            for secondary_stat in primary_stats: 
     209                long_name = secondary_stat.long_name 
     210                self.statistics[long_name] = secondary_stat 
     211                short_name = secondary_stat.short_name 
     212                self.statistics[short_name] = secondary_stat 
     213                secondary_stat.attach(self) 
    203214        self.behaviour = None 
    204          
    205215        if inventory == None: 
    206216            self.inventory = Inventory() 
    207217        else: 
    208218            self.inventory = inventory 
    209  
    210219        self.state = _AGENT_STATE_NONE 
    211220        self.layer_id = agent_layer.getId() 
     
    249258        @type item_type: str 
    250259        @return: True when the item is present, False when not""" 
    251         return self.inventory.findItem(item_type = item_type) 
    252  
    253     def itemCount(self, item_type = ""): 
     260        return self.inventory.findItem(item_type=item_type) 
     261 
     262    def itemCount(self, item_type=""): 
    254263        """Returns number of all items or items specified by item_type  
    255264        the player has. 
     
    273282        self.state = _AGENT_STATE_RUN 
    274283        self.behaviour.nextAction = None 
    275         self.behaviour.agent.move('run', location, self.behaviour.speed+1) 
     284        self.behaviour.agent.move('run', location, self.behaviour.speed + 1) 
    276285 
    277286    def walk(self, location): 
     
    282291        self.state = _AGENT_STATE_RUN 
    283292        self.behaviour.nextAction = None  
    284         self.behaviour.agent.move('walk', location, self.behaviour.speed-1) 
     293        self.behaviour.agent.move('walk', location, self.behaviour.speed - 1) 
    285294 
    286295    def getStateForSaving(self): 
     
    293302    def _getCoords(self): 
    294303        """Get-er property function""" 
    295         return (self.getLocation().getMapCoordinates().x,  
     304        return (self.getLocation().getMapCoordinates().x, 
    296305                self.getLocation().getMapCoordinates().y) 
    297306     
     
    302311        self.teleport(map_coords) 
    303312     
    304     coords = property (_getCoords, _setCoords,  
    305         doc = "Property allowing you to get and set the object's \ 
     313    coords = property (_getCoords, _setCoords, 
     314        doc="Property allowing you to get and set the object's \ 
    306315                coordinates via tuples") 
    307316            
    308317class PlayerCharacter (CharacterBase): 
    309318    """PC class""" 
    310     def __init__ (self, ID, agent_layer = None, inventory = None,  
    311                   text = "Its you. Who would've thought that?", **kwargs): 
     319    def __init__ (self, ID, agent_layer=None, inventory=None, 
     320                  text="Its you. Who would've thought that?", **kwargs): 
    312321        if inventory == None: 
    313322            inventory = Inventory() 
    314323            inventory.placeItem(CarryableItem(ID=456, name="Dagger123")) 
    315324            inventory.placeItem(CarryableItem(ID=555, name="Beer")) 
    316             inventory.placeItem(CarryableItem(ID = 616, 
    317                                     name = "Pamphlet", 
    318                                     image = "/gui/inv_images/inv_pamphlet.png")) 
     325            inventory.placeItem(CarryableItem(ID=616, 
     326                                    name="Pamphlet", 
     327                                    image="/gui/inv_images/inv_pamphlet.png")) 
    319328        CharacterBase.__init__(self, ID, agent_layer, inventory, text, **kwargs) 
    320329        self.people_i_know = set() 
     
    350359        self.behaviour = PCBehaviour(self, layer) 
    351360  
    352     def approach(self, location, action = None): 
     361    def approach(self, location, action=None): 
    353362        """Approaches a location and then perform an action (if set). 
    354363           @type loc: fife.Location 
     
    362371        l = fife.Location(self.behaviour.agent.getLocation()) 
    363372        l.setLayerCoordinates(fife.ModelCoordinate(*boxLocation)) 
    364         self.behaviour.agent.move('run', l, self.behaviour.speed+1) 
     373        self.behaviour.agent.move('run', l, self.behaviour.speed + 1) 
    365374     
    366375class NonPlayerCharacter(CharacterBase, Scriptable): 
    367376    """NPC class""" 
    368377    def __init__(self, ID, agent_layer=None, name='NPC', \ 
    369                  text = 'A nonplayer character', inventory = None,  
    370                  real_name = 'NPC', dialogue = None, **kwargs): 
     378                 text='A nonplayer character', inventory=None, 
     379                 real_name='NPC', dialogue=None, **kwargs): 
    371380        # init game object 
    372         CharacterBase.__init__(self, ID, agent_layer = agent_layer,  
    373                                inventory = inventory, name=name,  
    374                                real_name=real_name, text = text, **kwargs) 
     381        CharacterBase.__init__(self, ID, agent_layer=agent_layer, 
     382                               inventory=inventory, name=name, 
     383                               real_name=real_name, text=text, **kwargs) 
    375384        Scriptable.__init__(self, **kwargs) 
    376385 
     
    404413           @param location: Where the NPC will walk to. 
    405414           @return: None""" 
    406         self.behaviour.agent.move('walk', location, self.behaviour.speed-1) 
     415        self.behaviour.agent.move('walk', location, self.behaviour.speed - 1) 
    407416 
    408417    def talk(self, pc): 
Note: See TracChangeset for help on using the changeset viewer.