Ignore:
Timestamp:
06/30/10 18:47:25 (9 years ago)
Author:
beliar
Message:

Patch by Beliar.

  • Minor modifications to dialogue files that check for an active quest and the quest variable instead of only for the quest variable
  • Containers now have a "replaceItem" method that can be used to replace an item with another. The new item will be at the same item position the old one was
  • Added "UseAction?" class that can be used when you need to execute commands that need a carryable item
  • Added ReplaceItem? command to UseAction?. This replaces the item, that the command is called on, with a new item of the given object type
  • Changed Box to have a "Use" Action with the display text "Open" that replaces the Box with Boots and sets the "open_box" variable of the fedex quest to 1
  • Added replace_stuff command to dialogues, this replaces an item, in either the pc's or npc's inventory (who), of the given item_id (old_item) with an new object of the given object_type(new_item)
  • When the player has opened the box it is possible to tell Janie who rewraps the Boots (replaces the boots in the pc's inventory with the Box)
  • checkAttributes method in GameModel? now does a deep copy instead of a shallow one.
Location:
trunk/game/scripts/objects
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/scripts/objects/action.py

    r568 r571  
    11#!/usr/bin/python 
    2 from winioctlcon import UNLOCK_ELEMENT 
    3  
    42#   This file is part of PARPG. 
    53 
     
    2826 
    2927 
    30     def __init__(self, model, commands = None): 
     28    def __init__(self, controller, commands = None): 
    3129        """Basic action constructor 
    32         @param model: A reference to the game model. 
    33         @type model: scripts.GameModel 
    34         @param commands: Special commands that are executed 
    35         @type commands: Dictionary  
    36         """ 
    37         self.commands = commands or {} 
    38         self.model = model 
     30        @param controller: A reference to the GameSceneController. 
     31        @type controller: scripts.GameSceneController 
     32        @param commands: Special commands that are executed 
     33        @type commands: Dictionary  
     34        """ 
     35        self.commands = commands or () 
     36        self.controller = controller 
     37        self.model = controller.model 
    3938     
    4039    def execute(self): 
     
    5554class ChangeMapAction(Action): 
    5655    """A change map scheduled""" 
    57     def __init__(self, model, view, target_map_name, target_pos, commands = None): 
     56    def __init__(self, controller, target_map_name, target_pos, commands = None): 
    5857        """Initiates a change of the position of the character 
    5958        possibly flagging a new map to be loaded. 
    60         @param model: A reference to the game model. 
    61         @type model: scripts.GameModel 
     59        @param controller: A reference to the GameSceneController. 
     60        @type controller: scripts.GameSceneController 
    6261        @param commands: Special commands that are executed 
    6362        @type commands: Dictionary  
     
    6968        @param target_pos: (X, Y) coordinates on the target map. 
    7069        @return: None""" 
    71         Action.__init__(self, model, commands) 
    72         self.model = model 
    73         self.view = view 
     70        super(ChangeMapAction, self).__init__(controller, commands) 
     71        self.view = controller.view 
    7472        self.target_pos = target_pos 
    7573        self.target_map_name = target_map_name 
     
    7977        self.model.changeMap(self.target_map_name, 
    8078                              self.target_pos) 
    81         Action.execute(self) 
     79        super(ChangeMapAction, self).execute() 
    8280        
    8381class OpenBoxAction(Action): 
    8482    """Open a box. Needs to be more generic, but will do for now.""" 
    85     def __init__(self, model, view, container, commands = None): 
    86         """ 
    87         @param model: A reference to the game model. 
    88         @type model: scripts.GameModel 
     83    def __init__(self, controller, container, commands = None): 
     84        """ 
     85        @param controller: A reference to the GameSceneController. 
     86        @type controller: scripts.GameSceneController 
    8987        @param commands: Special commands that are executed 
    9088        @type commands: Dictionary  
     
    9391        @param container: A reference to the container 
    9492        """ 
    95         Action.__init__(self, model, commands) 
    96         self.view = view 
     93        super(OpenBoxAction, self).__init__(controller, commands) 
     94        self.view = controller.view 
    9795        self.container = container 
    9896         
     
    103101            self.view.hud.createBoxGUI(self.container.name, \ 
    104102                                              self.container) 
    105             Action.execute(self) 
     103            super(OpenBoxAction, self).execute() 
    106104 
    107105        except ValueError: 
     
    111109class UnlockBoxAction(Action): 
    112110    """Unlocks a box. Needs to be more generic, but will do for now.""" 
    113     def __init__(self, model, container, commands = None): 
    114         """ 
    115         @param model: A reference to the game model. 
    116         @type model: scripts.GameModel 
     111    def __init__(self, controller, container, commands = None): 
     112        """ 
     113        @param controller: A reference to the GameSceneController. 
     114        @type controller: scripts.GameSceneController 
    117115        @param commands: Special commands that are executed 
    118116        @type commands: Dictionary  
    119117        @param container: A reference to the container 
    120118        """ 
    121         Action.__init__(self, model, commands) 
     119        super(UnlockBoxAction, self).__init__(controller, commands) 
    122120        self.container = container 
    123121     
     
    125123        """Open the box.""" 
    126124        self.container.unlock() 
    127         Action.execute(self) 
     125        super(UnlockBoxAction, self).execute() 
    128126         
    129127class LockBoxAction(Action): 
    130128    """Locks a box. Needs to be more generic, but will do for now.""" 
    131     def __init__(self, model, container, commands = None): 
    132         """ 
    133         @param model: A reference to the game model. 
    134         @type model: scripts.GameModel 
     129    def __init__(self, controller, container, commands = None): 
     130        """ 
     131        @param controller: A reference to the GameSceneController. 
     132        @type controller: scripts.GameSceneController 
    135133        @param commands: Special commands that are executed 
    136134        @type commands: Dictionary  
    137135        @param container: A reference to the container 
    138136        """ 
    139         Action.__init__(self, model, commands) 
     137        super(LockBoxAction, self).__init__(controller, commands) 
    140138        self.container = container 
    141139         
     
    143141        """Lock the box.""" 
    144142        self.container.lock() 
    145         Action.execute(self) 
     143        super(LockBoxAction, self).execute() 
    146144 
    147145 
    148146class ExamineBoxAction(Action): 
    149147    """Examine a box. Needs to be more generic, but will do for now.""" 
    150     def __init__(self, model, view, examine_name, examine_desc, commands = None): 
    151         """ 
    152         @param model: A reference to the game model. 
    153         @type model: scripts.GameModel 
     148    def __init__(self, controller, examine_name, examine_desc, commands = None): 
     149        """ 
     150        @param controller: A reference to the GameSceneController. 
     151        @type controller: scripts.GameSceneController 
    154152        @param commands: Special commands that are executed 
    155153        @type commands: Dictionary  
     
    161159        @param examine_name: Description of the object to be examined. 
    162160        """ 
    163         Action.__init__(self, model, commands) 
    164         self.view = view 
     161        super(ExamineBoxAction, self).__init__(controller, commands) 
     162        self.view = controller.view 
    165163        self.examine_name = examine_name 
    166164        self.examine_desc = examine_desc 
     
    170168        self.view.hud.createExamineBox(self.examine_name, \ 
    171169                                              self.examine_desc) 
    172         Action.execute(self) 
     170        super(ExamineBoxAction, self).execute() 
    173171 
    174172class ReadAction(Action): 
    175173    """Read a text.""" 
    176     def __init__(self, model, view, text_name, text, commands = None): 
    177         """ 
    178         @param model: A reference to the game model. 
    179         @type model: scripts.GameModel 
     174    def __init__(self, controller, text_name, text, commands = None): 
     175        """ 
     176        @param controller: A reference to the GameSceneController. 
     177        @type controller: scripts.GameSceneController 
    180178        @param commands: Special commands that are executed 
    181179        @type commands: Dictionary  
     
    187185        @type text: String 
    188186        """ 
    189         Action.__init__(self, model, commands) 
    190         self.view = view 
     187        super(ReadAction, self).__init__(controller, commands) 
     188        self.view = controller.view 
    191189        self.text_name = text_name 
    192190        self.text = text 
     
    198196        #self.view.hud.createExamineBox(self.text_name, \ 
    199197        #                                      self.text) 
    200         Action.execute(self) 
     198        super(ReadAction, self).execute() 
    201199 
    202200class TalkAction(Action): 
    203201    """An action to represent starting a dialogue""" 
    204     def __init__(self, model, view, npc, commands = None): 
    205         """ 
    206         @param model: A reference to the game model. 
    207         @type model: scripts.GameModel 
     202    def __init__(self, controller, npc, commands = None): 
     203        """ 
     204        @param controller: A reference to the GameSceneController. 
     205        @type controller: scripts.GameSceneController 
    208206        @param commands: Special commands that are executed 
    209207        @type commands: Dictionary  
     
    213211        @param npc: NPC to interact with. 
    214212        """ 
    215         Action.__init__(self, model, commands) 
    216         self.view = view 
     213        super(TalkAction, self).__init__(controller, commands) 
     214        self.view = controller.view 
    217215        self.npc = npc 
    218216         
     
    237235                         self.npc.getLocation(). 
    238236                         getLayerCoordinates().y],  
    239                         TalkAction(self.model, 
    240                                    self.view, 
    241                                    self.npc))         
     237                        TalkAction(self.controller, 
     238                                   self.npc, self.commands))         
    242239        else: 
    243240            player_char.behaviour.agent.act('stand', self.npc.getLocation()) 
     
    251248            self.model.game_state.PlayerCharacter.behaviour.idle() 
    252249            self.model.game_state.PlayerCharacter.nextAction = None 
    253             Action.execute(self) 
     250            super(TalkAction, self).execute() 
     251 
     252class UseAction(Action): 
     253    """Action for carryable items. It executes special commands that can be only 
     254    used on carryable utens""" 
     255 
     256 
     257    def __init__(self, controller, item, commands = None): 
     258        """ 
     259        @param controller: A reference to the GameSceneController. 
     260        @type controller: scripts.GameSceneController 
     261        @param item: Item on which the action is called 
     262        @type item: CarryableItem 
     263        @param commands: Special commands that are executed 
     264        @type commands: Dictionary  
     265        """ 
     266        super(UseAction, self).__init__(controller, commands) 
     267        self.view = controller.view 
     268        self.item = item 
     269     
     270    def execute(self): 
     271        #Check if there are special commands and execute them 
     272        for command_data in self.commands: 
     273            command = command_data["Command"] 
     274            if command == "ReplaceItem": 
     275                object_id = command_data["ID"] 
     276                object_type = command_data["ObjectType"] 
     277                container = self.item.in_container 
     278                inst_dict = {} 
     279                inst_dict["ID"] = object_id 
     280                inst_dict["object_type"] = object_type 
     281                new_item = self.model.createContainerObject(inst_dict) 
     282                container.replaceItem(self.item, new_item) 
     283                self.view.hud.inventory.updateInventoryButtons() 
     284        super(UseAction, self).execute() 
    254285 
    255286ACTIONS = {"ChangeMap":ChangeMapAction,  
     
    259290           "Examine":ExamineBoxAction, 
    260291           "Read":ReadAction, 
    261            "Talk":TalkAction} 
     292           "Talk":TalkAction, 
     293           "Use":UseAction} 
  • trunk/game/scripts/objects/base.py

    r569 r571  
    294294        item.in_container = self 
    295295        if index == None: 
    296             self.placeAtVacant(item) 
     296            self._placeAtVacant(item) 
    297297        else: 
    298298            if index in self.items : 
     
    308308            pass 
    309309 
    310     def placeAtVacant(self, item): 
     310    def _placeAtVacant(self, item): 
    311311        """Places an item at a vacant slot""" 
    312312        vacant = None 
     
    317317            vacant = len(self.items) 
    318318        self.items[vacant] = item 
    319  
    320  
     319     
    321320    def takeItem (self, item): 
    322321        """Takes the listed item out of the inventory.  
    323            Runs an 'ontakeItem' script"""         
     322           Runs an 'onTakeItem' script"""         
    324323        if not item in self.items.values(): 
    325324            raise ValueError ('I do not contain this item: %s' % item) 
     
    332331        except AttributeError : 
    333332            pass 
     333     
     334    def replaceItem(self, old_item, new_item): 
     335        """Replaces the old item with the new one 
     336        @param old_item: Old item which is removed 
     337        @type old_item: Carryable 
     338        @param new_item: New item which is added 
     339        @type new_item: Carryable 
     340        """ 
     341        old_index = self.indexOf(old_item.ID) 
     342        self.removeItem(old_item) 
     343        self.placeItem(new_item, old_index) 
     344         
     345    def removeItem(self, item): 
     346        """Removes an item from the container, basically the same as 'takeItem' 
     347        but does run a different script. This should be used when an item is 
     348        destroyed rather than moved out. 
     349        Runs 'onRemoveItem' script 
     350        """ 
     351        if not item in self.items.values(): 
     352            raise ValueError ('I do not contain this item: %s' % item) 
     353        del self.items[self.items.keys()[self.items.values().index(item)]] 
     354 
     355        # Run any scripts associated with popping an item out of the container 
     356        try: 
     357            if self.trueAttr ('scriptable'): 
     358                self.runScript('onRemoveItem') 
     359        except AttributeError : 
     360            pass 
    334361 
    335362    def count (self): 
     
    340367        """Bulk of the container contents""" 
    341368        return sum((item.bulk for item in self.items.values())) 
     369 
     370    def indexOf(self, ID): 
     371        """Returns the index of the item with the passed ID""" 
     372        for index in self.items : 
     373            if self.items[index].ID == ID: 
     374                return index 
     375        return None 
    342376 
    343377    def findItemByID(self, ID): 
Note: See TracChangeset for help on using the changeset viewer.