Changeset 395 for trunk/game/scripts/objects
- Timestamp:
- 11/24/09 19:27:58 (10 years ago)
- Location:
- trunk/game/scripts/objects
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/game/scripts/objects/action.py
r360 r395 48 48 class OpenBoxAction(Action): 49 49 """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, container): 51 51 """@type engine: Engine reference 52 52 @param engine: A reference to the engine. 53 @type box_title: String 54 @param box_title: Box title. 53 @param container: A reference to the container 55 54 """ 56 55 self.engine = engine 57 self.box_title = box_title 56 self.container = container 57 58 def execute(self): 59 """Open the box.""" 60 try: 61 self.container.open() 62 except ValueError: 63 self.engine.view.hud.createExamineBox(self.container.name, \ 64 "The container is locked") 65 66 class UnlockBoxAction(Action): 67 """Unlocks a box. Needs to be more generic, but will do for now.""" 68 def __init__(self, container): 69 """@param container: A reference to the container 70 """ 71 self.container = container 58 72 59 73 def execute(self): 60 74 """Open the box.""" 61 self. engine.view.hud.createBoxGUI(self.box_title)75 self.container.unlock() 62 76 77 class LockBoxAction(Action): 78 """Locks a box. Needs to be more generic, but will do for now.""" 79 def __init__(self, container): 80 """@param container: A reference to the container 81 """ 82 self.container = container 83 def execute(self): 84 """Lock the box.""" 85 self.container.lock() 86 87 63 88 class ExamineBoxAction(Action): 64 89 """Examine a box. Needs to be more generic, but will do for now.""" -
trunk/game/scripts/objects/base.py
r346 r395 54 54 from settings import Setting 55 55 from random import randrange 56 from scripts.gui.popups import ExaminePopup, ContainerGUI 56 57 57 58 class GameObject (object): … … 140 141 class Lockable (Openable): 141 142 """Allows objects to be locked""" 142 def __init__ (self, locked = False, is_open =True, **kwargs):143 def __init__ (self, locked = False, is_open = True, **kwargs): 143 144 """Init operation for lockable objects 144 145 @type locked: Boolean … … 148 149 """ 149 150 self.is_lockable = True 151 if locked == True: #HACK: For some reason locked appears to NOT be a bool. Needs investigation 152 locked = True 153 else: locked = False 150 154 self.locked = locked 151 155 if locked : … … 178 182 class Container (object): 179 183 """Gives objects the capability to hold other objects""" 180 def __init__ (self, **kwargs): 184 def __init__ (self, 185 events = {}, 186 items = ["empty", "empty", "empty", "empty", "empty","empty", "empty", "empty", "empty"], 187 engine = None, **kwargs): 181 188 self.is_container = True 182 self.items = [] 189 self.items = items 190 self.events = events 191 if not self.events: 192 self.events = {'takeAllButton':self.hideContainer, 193 'closeButton':self.hideContainer} 194 self.containergui = engine.view.hud.createBoxGUI(self.name, self.items, self.events) 183 195 184 196 def placeItem (self, item): … … 212 224 return len(self.items) 213 225 226 def showContainer (self): 227 self.containergui.showContainer() 228 229 def hideContainer(self): 230 self.containergui.hideContainer() 214 231 215 232 class Living (object): -
trunk/game/scripts/objects/containers.py
r262 r395 19 19 barrels, chests, etc.""" 20 20 21 __all__ = ["WoodenCrate",] 21 __all__ = ["WoodenCrate", "Footlocker"] 22 23 _AGENT_STATE_NONE, _AGENT_STATE_OPENED, _AGENT_STATE_CLOSED, _AGENT_STATE_OPENING, _AGENT_STATE_CLOSING = xrange(5) 22 24 23 25 from composed import ImmovableContainer 26 import fife 24 27 25 28 class WoodenCrate (ImmovableContainer): 26 29 def __init__ (self, ID, name = 'Wooden Crate', \ 27 30 text = 'A battered crate', gfx = 'crate', **kwargs): 31 events = {'takeAllButton':self.close, 32 'closeButton':self.close} 28 33 ImmovableContainer.__init__(self, ID = ID, name = name, gfx = gfx, \ 29 text = text, **kwargs) 34 text = text, events = events, items = ["dagger01", "empty", "empty", "empty", "empty", 35 "empty", "empty", "empty", "empty"], **kwargs) 36 37 def close(self, *args, **kwargs): 38 self.hideContainer() 39 super (WoodenCrate,self).close() 40 41 def open(self, *args, **kwargs): 42 super (WoodenCrate,self).open(*args,**kwargs) 43 self.showContainer() 44 45 class Footlocker(ImmovableContainer, fife.InstanceActionListener): 46 def __init__ (self, ID, agent_layer=None, name = 'Footlocker', \ 47 text = 'A Footlocker', gfx = 'lock_box_metal01', **kwargs): 48 events = {'takeAllButton':self.close, 49 'closeButton':self.close} 50 ImmovableContainer.__init__(self, ID = ID, name = name, gfx = gfx, \ 51 text = text, events = events, items = ["dagger01", "empty", "empty", "empty", "empty", 52 "empty", "empty", "empty", "empty"], **kwargs) 53 fife.InstanceActionListener.__init__(self) 54 self.layer = agent_layer 55 self.agent = self.layer.getInstance(self.ID) 56 self.agent.addActionListener(self) 57 self.state = _AGENT_STATE_CLOSED 58 self.agent.act('closed', self.agent.getLocation()) 59 60 def onInstanceActionFinished(self, instance, action): 61 """What the NPC does when it has finished an action. 62 Called by the engine and required for InstanceActionListeners. 63 @type instance: fife.Instance 64 @param instance: self.agent (the NPC listener is listening for this 65 instance) 66 @type action: ??? 67 @param action: ??? 68 @return: None""" 69 if self.state == _AGENT_STATE_OPENING: 70 self.agent.act('opened', self.agent.getFacingLocation(), True) 71 self.state = _AGENT_STATE_OPENED 72 self.showContainer() 73 if self.state == _AGENT_STATE_CLOSING: 74 self.agent.act('closed', self.agent.getFacingLocation(), True) 75 self.state = _AGENT_STATE_CLOSED 76 77 def open (self): 78 super (Footlocker,self).open() 79 if self.state != _AGENT_STATE_OPENED and self.state != _AGENT_STATE_OPENING: 80 self.agent.act('open', self.agent.getLocation()) 81 self.state = _AGENT_STATE_OPENING 82 83 def close(self): 84 super (Footlocker,self).close() 85 self.hideContainer() 86 if self.state != _AGENT_STATE_CLOSED and self.state != _AGENT_STATE_CLOSING: 87 self.agent.act('close', self.agent.getLocation()) 88 self.state = _AGENT_STATE_CLOSING
Note: See TracChangeset
for help on using the changeset viewer.