source: trunk/game/scripts/objects/containers.py @ 541

Revision 539, 4.4 KB checked in by beliar, 10 years ago (diff)
  • Added the shanty door to the database
  • Removed redundant information from the maps
  • Changed the text of the door in map2.xml
  • Property svn:eol-style set to native
Line 
1#!/usr/bin/python
2
3#   This file is part of PARPG.
4
5#   PARPG is free software: you can redistribute it and/or modify
6#   it under the terms of the GNU General Public License as published by
7#   the Free Software Foundation, either version 3 of the License, or
8#   (at your option) any later version.
9
10#   PARPG is distributed in the hope that it will be useful,
11#   but WITHOUT ANY WARRANTY; without even the implied warranty of
12#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13#   GNU General Public License for more details.
14
15#   You should have received a copy of the GNU General Public License
16#   along with PARPG.  If not, see <http://www.gnu.org/licenses/>.
17
18"""Containes classes defining concrete container game objects like crates,
19   barrels, chests, etc."""
20
21__all__ = ["WoodenCrate", "Footlocker"]
22
23_AGENT_STATE_NONE, _AGENT_STATE_OPENED, _AGENT_STATE_CLOSED, \
24_AGENT_STATE_OPENING, _AGENT_STATE_CLOSING = xrange(5)
25
26from composed import ImmovableContainer
27from composed import CarryableItem
28from fife import fife
29
30class WoodenCrate (ImmovableContainer):
31    def __init__(self, object_id, name = 'Wooden Crate',
32                 text = 'A battered crate', gfx = 'crate', **kwargs):
33        ImmovableContainer.__init__(self, ID = object_id, name = name, 
34                                    gfx = gfx, text = text, **kwargs)
35        self.placeItem(CarryableItem(ID=987, name="Dagger456"))
36       
37class ContainerBehaviour(fife.InstanceActionListener):
38    def __init__(self, parent = None, agent_layer = None):
39        fife.InstanceActionListener.__init__(self)
40        self.parent = parent
41        self.layer = agent_layer
42        self.state = _AGENT_STATE_CLOSED
43        self.agent = None
44
45    def attachToLayer(self, agent_id):
46        """ Attaches to a certain layer
47            @type agent_id: String
48            @param agent_id: ID of the layer to attach to.
49            @return: None"""
50        self.agent = self.layer.getInstance(agent_id)
51        self.agent.addActionListener(self)
52        self.state = _AGENT_STATE_CLOSED
53        self.agent.act('closed', self.agent.getLocation())
54       
55    def onInstanceActionFinished(self, instance, action):
56        """What the Actor does when it has finished an action.
57           Called by the engine and required for InstanceActionListeners.
58           @type instance: fife.Instance
59           @param instance: self.agent (the Actor listener is listening for this
60            instance)
61           @type action: ???
62           @param action: ???
63           @return: None"""
64        if self.state == _AGENT_STATE_OPENING:
65            self.agent.act('opened', self.agent.getFacingLocation(), True)
66            self.state = _AGENT_STATE_OPENED
67        if self.state == _AGENT_STATE_CLOSING:
68            self.agent.act('closed', self.agent.getFacingLocation(), True)
69            self.state = _AGENT_STATE_CLOSED
70       
71    def open (self):
72        if self.state != _AGENT_STATE_OPENED and self.state != \
73                                                _AGENT_STATE_OPENING:
74            self.agent.act('open', self.agent.getLocation())
75            self.state = _AGENT_STATE_OPENING
76
77    def close(self):
78        if self.state != _AGENT_STATE_CLOSED and self.state != \
79                                                _AGENT_STATE_CLOSING:
80            self.agent.act('close', self.agent.getLocation())
81            self.state = _AGENT_STATE_CLOSING 
82   
83class Footlocker(ImmovableContainer):
84    def __init__ (self, object_id, agent_layer=None, name = 'Footlocker',
85                  text = 'A Footlocker', gfx = 'lock_box_metal01', **kwargs):
86        ImmovableContainer.__init__(self, ID = object_id, name = name, 
87                                    gfx = gfx, text = text, **kwargs)
88        self.behaviour = None
89        self.placeItem(CarryableItem(ID=987, name="Dagger456"))
90
91        self.is_AnimatedContainer = True
92        self.createBehaviour(agent_layer)       
93       
94    def __getstate__(self):
95        odict = self.__dict__.copy()
96        del odict["behaviour"]
97        return odict
98   
99    def __setstate__(self, state):
100        self.__dict__.update(state)
101   
102    def createBehaviour(self, layer):
103        self.behaviour = ContainerBehaviour(self, layer)
104
105    def setup(self):
106        """@return: None"""
107        self.behaviour.attachToLayer(self.ID)
108
109    def open (self):
110        super (Footlocker, self).open()
111        self.behaviour.open()
112
113    def close(self):
114        super (Footlocker, self).close()
115        self.behaviour.close()
Note: See TracBrowser for help on using the repository browser.