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

Revision 477, 3.3 KB checked in by maximinus_parpg, 10 years ago (diff)

More clean up of the code.
Finshed first pass.
So should be at least stands compliant.

  • 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, ID, name = 'Wooden Crate',
32                  text = 'A battered crate', gfx = 'crate', **kwargs):
33        ImmovableContainer.__init__(self, ID = ID, name = name, gfx = gfx, \
34                text = text, **kwargs)
35        self.placeItem(CarryableItem(ID=987,name="Dagger456"))
36       
37class Footlocker(ImmovableContainer, fife.InstanceActionListener):
38    def __init__ (self, ID, agent_layer=None, name = 'Footlocker',
39                  text = 'A Footlocker', gfx = 'lock_box_metal01', **kwargs):
40        ImmovableContainer.__init__(self, ID = ID, name = name, gfx = gfx,
41                                    text = text, **kwargs)
42        self.placeItem(CarryableItem(ID=987,name="Dagger456"))
43
44        fife.InstanceActionListener.__init__(self)
45        self.layer = agent_layer
46        self.agent = self.layer.getInstance(self.ID)
47        self.agent.addActionListener(self)
48        self.state = _AGENT_STATE_CLOSED
49        self.agent.act('closed', self.agent.getLocation())
50       
51    def onInstanceActionFinished(self, instance, action):
52        """What the NPC does when it has finished an action.
53           Called by the engine and required for InstanceActionListeners.
54           @type instance: fife.Instance
55           @param instance: self.agent (the NPC listener is listening for this
56            instance)
57           @type action: ???
58           @param action: ???
59           @return: None"""
60        if self.state == _AGENT_STATE_OPENING:
61            self.agent.act('opened', self.agent.getFacingLocation(), True)
62            self.state = _AGENT_STATE_OPENED
63        if self.state == _AGENT_STATE_CLOSING:
64            self.agent.act('closed', self.agent.getFacingLocation(), True)
65            self.state = _AGENT_STATE_CLOSED
66       
67    def open (self):
68        super (Footlocker,self).open()
69        if self.state != _AGENT_STATE_OPENED and self.state != _AGENT_STATE_OPENING:
70            self.agent.act('open', self.agent.getLocation())
71            self.state = _AGENT_STATE_OPENING
72
73    def close(self):
74        super (Footlocker,self).close()
75        if self.state != _AGENT_STATE_CLOSED and self.state != _AGENT_STATE_CLOSING:
76            self.agent.act('close', self.agent.getLocation())
77            self.state = _AGENT_STATE_CLOSING
Note: See TracBrowser for help on using the repository browser.