comparison src/parpg/objects/action.py @ 134:c938a828a38a

Added actions for lockable components (Open, Close, Lock and Unlock).
author KarstenBock@gmx.net
date Fri, 30 Sep 2011 14:05:16 +0200
parents 0ffebdca7ba3
children 140e5e93f026
comparison
equal deleted inserted replaced
133:ecac92680bef 134:c938a828a38a
19 19
20 logger = logging.getLogger('action') 20 logger = logging.getLogger('action')
21 21
22 from parpg.gui import drag_drop_data as data_drag 22 from parpg.gui import drag_drop_data as data_drag
23 from parpg.dialoguecontroller import DialogueController 23 from parpg.dialoguecontroller import DialogueController
24 from parpg.components import container 24 from parpg.components import container, lockable
25 25
26 26
27 class NoSuchQuestException(Exception): 27 class NoSuchQuestException(Exception):
28 """NoQuestException is used when there is no active quest with the id""" 28 """NoQuestException is used when there is no active quest with the id"""
29 pass 29 pass
90 self.model.changeMap(self.target_map_name, 90 self.model.changeMap(self.target_map_name,
91 self.target_pos) 91 self.target_pos)
92 super(ChangeMapAction, self).execute() 92 super(ChangeMapAction, self).execute()
93 93
94 class OpenAction(Action): 94 class OpenAction(Action):
95 """Open a container""" 95 """Open an lockable"""
96 def __init__(self, controller, container, commands=None): 96 def __init__(self, controller, lockable, commands=None):
97 """ 97 """
98 @param controller: A reference to the GameSceneController. 98 @param controller: A reference to the GameSceneController.
99 @type controller: parpg.GameSceneController 99 @type controller: parpg.GameSceneController
100 @param commands: Special commands that are executed 100 @param commands: Special commands that are executed
101 @type commands: Dictionary 101 @type commands: Dictionary
102 @type view: class derived from parpg.ViewBase 102 @type view: class derived from parpg.ViewBase
103 @param view: The view 103 @param view: The view
104 @param container: A reference to the container 104 @param lockable: A reference to the lockable
105 """ 105 """
106 super(OpenAction, self).__init__(controller, commands) 106 Action.__init__(self, controller, commands)
107 self.view = controller.view 107 self.view = controller.view
108 self.container = container 108 self.lockable = lockable
109
110 def execute(self):
111 """Open the lockable."""
112 try:
113 lockable.open(self.lockable.lockable)
114 self.lockable.fifeagent.behaviour.animate("open")
115 self.lockable.fifeagent.behaviour.queue_animation("opened",
116 repeating=True)
117 except lockable.LockedError:
118 self.view.hud.createExamineBox(self.lockable.description.view_name,
119 "Locked")
120 Action.execute(self)
121
122 class CloseAction(Action):
123 """Close an lockable"""
124 def __init__(self, controller, lockable, commands=None):
125 """
126 @param controller: A reference to the GameSceneController.
127 @type controller: parpg.GameSceneController
128 @param commands: Special commands that are executed
129 @type commands: Dictionary
130 @type view: class derived from parpg.ViewBase
131 @param view: The view
132 @param lockable: A reference to the lockable
133 """
134 Action.__init__(self, controller, commands)
135 self.lockable = lockable
136
137 def execute(self):
138 """Close the lockable."""
139 lockable.close(self.lockable.lockable)
140 self.lockable.fifeagent.behaviour.animate("close")
141 self.lockable.fifeagent.behaviour.queue_animation("closed",
142 repeating=True)
143 Action.execute(self)
144
145 class UnlockAction(Action):
146 """Unlocks a lockable."""
147 def __init__(self, controller, lockable, commands = None):
148 """
149 @param controller: A reference to the GameSceneController.
150 @type controller: parpg.GameSceneController
151 @param commands: Special commands that are executed
152 @type commands: Dictionary
153 @param lockable: A reference to the lockable
154 """
155 Action.__init__(self, controller, commands)
156 self.lockable = lockable
157
109 def execute(self): 158 def execute(self):
110 """Open the box.""" 159 """Open the box."""
111 self.view.hud.createBoxGUI(self.container.name, \ 160 lockable.unlock(self.lockable.lockable)
112 self.container) 161 Action.execute(self)
113 super(OpenAction, self).execute() 162
114 163 class LockAction(Action):
115 164 """Locks a lockable."""
116 class OpenBoxAction(OpenAction): 165 def __init__(self, controller, lockable, commands = None):
117 """Open a box. Needs to be more generic, but will do for now.""" 166 """
118 def __init__(self, controller, container, commands = None): 167 @param controller: A reference to the GameSceneController.
119 """ 168 @type controller: parpg.GameSceneController
120 @param controller: A reference to the GameSceneController. 169 @param commands: Special commands that are executed
121 @type controller: parpg.GameSceneController 170 @type commands: Dictionary
122 @param commands: Special commands that are executed 171 @param lockable: A reference to the lockable
123 @type commands: Dictionary 172 """
124 @type view: class derived from parpg.ViewBase 173 Action.__init__(self, controller, commands)
125 @param view: The view 174 self.lockable = lockable
126 @param container: A reference to the container 175 self.view = controller.view
127 """ 176
128 super(OpenBoxAction, self).__init__(controller, commands) 177 def execute(self):
129 self.view = controller.view 178 """Lock the box."""
130 self.container = container
131
132 def execute(self):
133 """Open the box."""
134 try: 179 try:
135 self.container.open() 180 lockable.lock(self.lockable.lockable)
136 super(OpenBoxAction, self).execute() 181 except lockable.OpenError:
137 182 self.view.hud.createExamineBox(self.lockable.description.view_name,
138 except ValueError: 183 "Is open")
139 self.view.hud.createExamineBox(self.container.name, \ 184
140 "The container is locked") 185 Action.execute(self)
141
142 class UnlockBoxAction(Action):
143 """Unlocks a box. Needs to be more generic, but will do for now."""
144 def __init__(self, controller, container, commands = None):
145 """
146 @param controller: A reference to the GameSceneController.
147 @type controller: parpg.GameSceneController
148 @param commands: Special commands that are executed
149 @type commands: Dictionary
150 @param container: A reference to the container
151 """
152 super(UnlockBoxAction, self).__init__(controller, commands)
153 self.container = container
154
155 def execute(self):
156 """Open the box."""
157 self.container.unlock()
158 super(UnlockBoxAction, self).execute()
159
160 class LockBoxAction(Action):
161 """Locks a box. Needs to be more generic, but will do for now."""
162 def __init__(self, controller, container, commands = None):
163 """
164 @param controller: A reference to the GameSceneController.
165 @type controller: parpg.GameSceneController
166 @param commands: Special commands that are executed
167 @type commands: Dictionary
168 @param container: A reference to the container
169 """
170 super(LockBoxAction, self).__init__(controller, commands)
171 self.container = container
172
173 def execute(self):
174 """Lock the box."""
175 self.container.lock()
176 super(LockBoxAction, self).execute()
177 186
178 187
179 class ExamineAction(Action): 188 class ExamineAction(Action):
180 """Examine an object.""" 189 """Examine an object."""
181 def __init__(self, controller, examine_id, examine_name, examine_desc=None, commands=None): 190 def __init__(self, controller, examine_id, examine_name, examine_desc=None, commands=None):
545 Empty bottle""")) 554 Empty bottle"""))
546 super(BrewBeerAction, self).execute() 555 super(BrewBeerAction, self).execute()
547 556
548 ACTIONS = {"ChangeMap":ChangeMapAction, 557 ACTIONS = {"ChangeMap":ChangeMapAction,
549 "Open":OpenAction, 558 "Open":OpenAction,
550 "OpenBox":OpenBoxAction, 559 "Close":CloseAction,
551 "Unlock":UnlockBoxAction, 560 "Unlock":UnlockAction,
552 "Lock":LockBoxAction, 561 "Lock":LockAction,
553 "ExamineItem":ExamineItemAction, 562 "ExamineItem":ExamineItemAction,
554 "Examine":ExamineAction, 563 "Examine":ExamineAction,
555 "Look":ExamineItemAction, 564 "Look":ExamineItemAction,
556 "Read":ReadAction, 565 "Read":ReadAction,
557 "Talk":TalkAction, 566 "Talk":TalkAction,