Ticket #137: ObjectAnimation.diff

File ObjectAnimation.diff, 6.9 KB (added by Beliar, 10 years ago)
  • engine.py

     
    242242                    actions.append(["Open", "Open",  
    243243                                    self.game_state.PC.approach, \ 
    244244                                    [obj.X, obj.Y], \ 
    245                                     OpenBoxAction(self, "Box")]) 
     245                                    OpenBoxAction(self, "Box", obj)]) 
     246                    actions.append(["Unlock", "Unlock",  
     247                                    self.game_state.PC.approach, \ 
     248                                    [obj.X, obj.Y], \ 
     249                                    UnlockBoxAction(self, "Box", obj)]) 
     250                    actions.append(["Lock", "Lock",  
     251                                    self.game_state.PC.approach, \ 
     252                                    [obj.X, obj.Y], \ 
     253                                    LockBoxAction(self, "Box", obj)]) 
    246254                # can you pick it up? 
    247255                if obj.trueAttr("carryable"): 
    248256                    actions.append(["Pick Up", "Pick Up", self.nullFunc, obj]) 
  • objects/action.py

     
    4747        
    4848class OpenBoxAction(Action): 
    4949    """Open a box. Needs to be more generic, but will do for now.""" 
    50     def __init__(self, engine, box_title): 
     50    def __init__(self, engine, box_title, container): 
    5151        """@type engine: Engine reference 
    5252           @param engine: A reference to the engine. 
    5353           @type box_title: String 
    5454           @param box_title: Box title. 
     55           @param container: A reference to the container 
    5556           """ 
    5657        self.engine = engine 
    5758        self.box_title = box_title 
     59        self.container = container 
    5860     
    5961    def execute(self): 
    6062        """Open the box.""" 
    61         self.engine.view.hud.createBoxGUI(self.box_title) 
     63        try: 
     64            self.container.open() 
     65            self.engine.view.hud.createBoxGUI(self.box_title) 
     66        except ValueError: 
     67            self.engine.view.hud.createExamineBox(self.container.name, \ 
     68                                              "The container is locked") 
    6269         
     70class UnlockBoxAction(Action): 
     71    """Unlocks a box. Needs to be more generic, but will do for now.""" 
     72    def __init__(self, engine, box_title, container): 
     73        """@type engine: Engine reference 
     74           @param engine: A reference to the engine. 
     75           @type box_title: String 
     76           @param box_title: Box title. 
     77           @param container: A reference to the container 
     78           """ 
     79        self.engine = engine 
     80        self.container = container 
     81     
     82    def execute(self): 
     83        """Open the box.""" 
     84        self.container.unlock() 
     85         
     86class LockBoxAction(Action): 
     87    """Locks a box. Needs to be more generic, but will do for now.""" 
     88    def __init__(self, engine, box_title, container): 
     89        """@type engine: Engine reference 
     90           @param engine: A reference to the engine. 
     91           @type box_title: String 
     92           @param box_title: Box title. 
     93           @param container: A reference to the container 
     94           """ 
     95        self.engine = engine 
     96        self.container = container 
     97    def execute(self): 
     98        """Lock the box.""" 
     99        self.container.lock() 
     100 
     101 
    63102class ExamineBoxAction(Action): 
    64103    """Examine a box. Needs to be more generic, but will do for now.""" 
    65104    def __init__(self, engine, examine_name, examine_desc): 
  • objects/base.py

     
    147147        @param is_open: Keyword boolean argument sets the initial open state. It is ignored if locked is True -- locked objects are always closed. 
    148148        """ 
    149149        self.is_lockable = True 
     150        if locked == True: #HACK: For some reason locked appears to NOT be a bool. Needs investigation 
     151            locked = True 
     152        else: locked = False 
    150153        self.locked = locked 
    151154        if locked : 
    152155            is_open=False 
  • objects/containers.py

     
    1818"""Containes classes defining concrete container game objects like crates, 
    1919barrels, chests, etc.""" 
    2020 
    21 __all__ = ["WoodenCrate",] 
     21__all__ = ["WoodenCrate", "Footlocker"] 
    2222 
     23_AGENT_STATE_NONE, _AGENT_STATE_OPENED, _AGENT_STATE_CLOSED, _AGENT_STATE_OPENING, _AGENT_STATE_CLOSING = xrange(5) 
     24 
    2325from composed import ImmovableContainer 
     26import fife 
    2427 
    2528class WoodenCrate (ImmovableContainer): 
    2629    def __init__ (self, ID, name = 'Wooden Crate', \ 
    2730            text = 'A battered crate', gfx = 'crate', **kwargs): 
    2831        ImmovableContainer.__init__(self, ID = ID, name = name, gfx = gfx, \ 
    2932                text = text, **kwargs) 
     33 
     34class Footlocker(ImmovableContainer, fife.InstanceActionListener): 
     35    def __init__ (self, ID, agent_layer=None, name = 'Footlocker', \ 
     36               text = 'A Footlocker', gfx = 'lock_box_metal01', **kwargs): 
     37        ImmovableContainer.__init__(self, ID = ID, name = name, gfx = gfx, \ 
     38                text = text, **kwargs) 
     39        fife.InstanceActionListener.__init__(self) 
     40        self.layer = agent_layer 
     41        self.agent = self.layer.getInstance(self.ID) 
     42        self.agent.addActionListener(self) 
     43        self.state = _AGENT_STATE_CLOSED 
     44        self.agent.act('closed', self.agent.getLocation()) 
     45         
     46    def onInstanceActionFinished(self, instance, action): 
     47        """What the NPC does when it has finished an action. 
     48           Called by the engine and required for InstanceActionListeners. 
     49           @type instance: fife.Instance 
     50           @param instance: self.agent (the NPC listener is listening for this 
     51            instance) 
     52           @type action: ??? 
     53           @param action: ??? 
     54           @return: None""" 
     55        if self.state == _AGENT_STATE_OPENING: 
     56            self.agent.act('opened', self.agent.getFacingLocation(), True) 
     57            self.state = _AGENT_STATE_OPENED 
     58        if self.state == _AGENT_STATE_CLOSING: 
     59            self.agent.act('closed', self.agent.getFacingLocation(), True) 
     60            self.state = _AGENT_STATE_CLOSED 
     61         
     62    def open (self, *args, **kwargs): 
     63        super (Footlocker,self).open(*args,**kwargs) 
     64        if self.state != _AGENT_STATE_OPENED and self.state != _AGENT_STATE_OPENING: 
     65            self.agent.act('open', self.agent.getLocation()) 
     66            self.state = _AGENT_STATE_OPENING 
     67 
     68    def close(self, *args, **kwargs): 
     69        super (Footlocker,self).close(*args,**kwargs) 
     70        if self.state != _AGENT_STATE_CLOSED and self.state != _AGENT_STATE_CLOSING: 
     71            self.agent.act('close', self.agent.getLocation()) 
     72            self.state = _AGENT_STATE_CLOSING