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

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

Added chewies patch to make parpg FIFE 0.3.0 compatible.
Thanks to the FIFE devs for all their work!
You now need FIFE 0.3.0 to run parpg.

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