annotate objects/action.py @ 145:46570c1ee4ca

Changed DropItemFromContainerAction to work with components.
author KarstenBock@gmx.net
date Sun, 09 Oct 2011 20:50:01 +0200
parents 658e06a20fa5
children
rev   line source
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
1 # This file is part of PARPG.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
2
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
3 # PARPG is free software: you can redistribute it and/or modify
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
4 # it under the terms of the GNU General Public License as published by
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
5 # the Free Software Foundation, either version 3 of the License, or
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
6 # (at your option) any later version.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
7
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
8 # PARPG is distributed in the hope that it will be useful,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
11 # GNU General Public License for more details.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
12
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
13 # You should have received a copy of the GNU General Public License
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
14 # along with PARPG. If not, see <http://www.gnu.org/licenses/>.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
15
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
16 #exceptions
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
17
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
18 import logging
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
19
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
20 logger = logging.getLogger('action')
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
21
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
22 from parpg.gui import drag_drop_data as data_drag
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
23 from parpg.dialoguecontroller import DialogueController
104
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
24 from parpg.components import container, lockable
85
04af237dde10 Fixed PickUpAction. Items can be picked up again.
KarstenBock@gmx.net
parents: 54
diff changeset
25
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
26
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
27 class NoSuchQuestException(Exception):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
28 """NoQuestException is used when there is no active quest with the id"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
29 pass
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
30
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
31 #classes
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
32
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
33 class Action(object):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
34 """Base Action class, to define the structure"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
35
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
36
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
37 def __init__(self, controller, commands = None):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
38 """Basic action constructor
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
39 @param controller: A reference to the GameSceneController.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
40 @type controller: parpg.GameSceneController
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
41 @param commands: Special commands that are executed
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
42 @type commands: Dictionary
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
43 """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
44 self.commands = commands or ()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
45 self.controller = controller
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
46 self.model = controller.model
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
47
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
48 def execute(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
49 """To be overwritten"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
50 #Check if there are special commands and execute them
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
51 for command_data in self.commands:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
52 command = command_data["Command"]
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
53 if command == "SetQuestVariable":
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
54 quest_id = command_data["ID"]
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
55 variable = command_data["Variable"]
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
56 value = command_data["Value"]
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
57 quest_engine = self.model.game_state.quest_engine
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
58 if quest_engine.hasQuest(quest_id):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
59 quest_engine[quest_id].setValue(variable, value)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
60 else:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
61 raise NoSuchQuestException
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
62 elif command == "ResetMouseCursor":
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
63 self.controller.resetMouseCursor()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
64 elif command == "StopDragging":
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
65 data_drag.dragging = False
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
66
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
67 class ChangeMapAction(Action):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
68 """A change map scheduled"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
69 def __init__(self, controller, target_map_name, target_pos, commands=None):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
70 """Initiates a change of the position of the character
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
71 possibly flagging a new map to be loaded.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
72 @param controller: A reference to the GameSceneController.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
73 @type controller: parpg.GameSceneController
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
74 @param commands: Special commands that are executed
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
75 @type commands: Dictionary
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
76 @type view: class derived from parpg.ViewBase
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
77 @param view: The view
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
78 @type target_map_name: String
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
79 @param target_map_name: Target map id
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
80 @type target_pos: Tuple
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
81 @param target_pos: (X, Y) coordinates on the target map.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
82 @return: None"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
83 super(ChangeMapAction, self).__init__(controller, commands)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
84 self.view = controller.view
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
85 self.target_pos = target_pos
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
86 self.target_map_name = target_map_name
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
87
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
88 def execute(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
89 """Executes the map change."""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
90 self.model.changeMap(self.target_map_name,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
91 self.target_pos)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
92 super(ChangeMapAction, self).execute()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
93
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
94 class OpenAction(Action):
104
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
95 """Open an lockable"""
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
96 def __init__(self, controller, lockable, commands=None):
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
97 """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
98 @param controller: A reference to the GameSceneController.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
99 @type controller: parpg.GameSceneController
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
100 @param commands: Special commands that are executed
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
101 @type commands: Dictionary
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
102 @type view: class derived from parpg.ViewBase
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
103 @param view: The view
104
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
104 @param lockable: A reference to the lockable
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
105 """
104
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
106 Action.__init__(self, controller, commands)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
107 self.view = controller.view
104
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
108 self.lockable = lockable
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
109
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
110 def execute(self):
104
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
111 """Open the lockable."""
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
112 try:
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
113 lockable.open(self.lockable.lockable)
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
114 self.lockable.fifeagent.behaviour.animate("open")
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
115 self.lockable.fifeagent.behaviour.queue_animation("opened",
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
116 repeating=True)
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
117 except lockable.LockedError:
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
118 self.view.hud.createExamineBox(self.lockable.description.view_name,
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
119 "Locked")
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
120 Action.execute(self)
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
121
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
122 class CloseAction(Action):
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
123 """Close an lockable"""
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
124 def __init__(self, controller, lockable, commands=None):
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
125 """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
126 @param controller: A reference to the GameSceneController.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
127 @type controller: parpg.GameSceneController
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
128 @param commands: Special commands that are executed
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
129 @type commands: Dictionary
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
130 @type view: class derived from parpg.ViewBase
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
131 @param view: The view
104
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
132 @param lockable: A reference to the lockable
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
133 """
104
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
134 Action.__init__(self, controller, commands)
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
135 self.lockable = lockable
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
136
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
137 def execute(self):
104
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
138 """Close the lockable."""
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
139 lockable.close(self.lockable.lockable)
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
140 self.lockable.fifeagent.behaviour.animate("close")
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
141 self.lockable.fifeagent.behaviour.queue_animation("closed",
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
142 repeating=True)
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
143 Action.execute(self)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
144
104
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
145 class UnlockAction(Action):
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
146 """Unlocks a lockable."""
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
147 def __init__(self, controller, lockable, commands = None):
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
148 """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
149 @param controller: A reference to the GameSceneController.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
150 @type controller: parpg.GameSceneController
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
151 @param commands: Special commands that are executed
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
152 @type commands: Dictionary
104
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
153 @param lockable: A reference to the lockable
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
154 """
104
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
155 Action.__init__(self, controller, commands)
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
156 self.lockable = lockable
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
157
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
158 def execute(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
159 """Open the box."""
104
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
160 lockable.unlock(self.lockable.lockable)
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
161 Action.execute(self)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
162
104
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
163 class LockAction(Action):
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
164 """Locks a lockable."""
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
165 def __init__(self, controller, lockable, commands = None):
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
166 """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
167 @param controller: A reference to the GameSceneController.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
168 @type controller: parpg.GameSceneController
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
169 @param commands: Special commands that are executed
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
170 @type commands: Dictionary
104
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
171 @param lockable: A reference to the lockable
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
172 """
104
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
173 Action.__init__(self, controller, commands)
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
174 self.lockable = lockable
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
175 self.view = controller.view
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
176
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
177 def execute(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
178 """Lock the box."""
104
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
179 try:
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
180 lockable.lock(self.lockable.lockable)
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
181 except lockable.OpenError:
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
182 self.view.hud.createExamineBox(self.lockable.description.view_name,
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
183 "Is open")
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
184
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
185 Action.execute(self)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
186
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
187
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
188 class ExamineAction(Action):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
189 """Examine an object."""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
190 def __init__(self, controller, examine_id, examine_name, examine_desc=None, commands=None):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
191 """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
192 @param controller: A reference to the GameSceneController.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
193 @type controller: parpg.GameSceneController
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
194 @param examine_id: An object id
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
195 @type examine_id: integer
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
196 @param examine_name: An object name
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
197 @type examine_name: string
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
198 @param examine_desc: A description of the object that will be displayed.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
199 @type examine_desc: string
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
200 @param commands: Special commands that are executed
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
201 @type commands: Dictionary
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
202 """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
203 super(ExamineAction, self).__init__(controller, commands)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
204 self.view = controller.view
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
205 self.examine_id = examine_id
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
206 self.examine_name = examine_name
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
207 if examine_desc is not None:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
208 self.examine_desc = examine_desc
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
209 else:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
210 self.examine_desc = "No Description"
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
211
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
212 def execute(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
213 """Display the text."""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
214 action_text = self.examine_desc
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
215 self.view.hud.addAction(unicode(action_text))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
216 logger.debug(action_text)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
217 #this code will cut the line up into smaller lines that will be displayed
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
218 place = 25
54
de09adb7a736 Fixed bug in the text splitting code of ExamineAction.
KarstenBock@gmx.net
parents: 51
diff changeset
219 while place < len(action_text):
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
220 if action_text[place] == ' ':
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
221 action_text = action_text[:place] +'\n'+action_text[place:]
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
222 place += 26 #plus 1 character to offset the new line
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
223 else: place += 1
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
224 self.view.displayObjectText(self.examine_id, unicode(action_text), time=3000)
107
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
225 Action.execute(self)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
226
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
227 class ExamineItemAction(Action):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
228 """Examine an item."""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
229 def __init__(self, controller, examine_name, examine_desc, commands = None):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
230 """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
231 @param controller: A reference to the GameSceneController.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
232 @type controller: parpg.GameSceneController
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
233 @param commands: Special commands that are executed
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
234 @type commands: Dictionary
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
235 @type view: class derived from parpg.ViewBase
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
236 @param view: The view
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
237 @type examine_name: String
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
238 @param examine_name: Name of the object to be examined.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
239 @type examine_name: String
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
240 @param examine_name: Description of the object to be examined.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
241 """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
242 super(ExamineItemAction, self).__init__(controller, commands)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
243 self.view = controller.view
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
244 self.examine_name = examine_name
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
245 self.examine_desc = examine_desc
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
246
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
247 def execute(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
248 """Display the text."""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
249 action_text = unicode(self.examine_desc)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
250 self.view.hud.addAction(action_text)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
251 logger.debug(action_text)
107
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
252 Action.execute(self)
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
253
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
254 class ExamineContentsAction(Action):
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
255 """Examine the contens of an container"""
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
256 def __init__(self, controller, container, commands=None):
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
257 """
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
258 @param controller: A reference to the GameSceneController.
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
259 @type controller: parpg.GameSceneController
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
260 @param container: The container
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
261 @type container: parpg.entities.General
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
262 @param commands: Special commands that are executed
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
263 @type commands: Dictionary
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
264 """
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
265 Action.__init__(self, controller, commands)
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
266 self.view = controller.view
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
267 self.container = container
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
268
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
269 def execute(self):
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
270 """Examine the contents"""
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
271 self.view.hud.createBoxGUI(self.container.description.view_name,
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
272 self.container.container)
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
273 Action.execute(self)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
274
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
275 class ReadAction(Action):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
276 """Read a text."""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
277 def __init__(self, controller, text_name, text, commands = None):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
278 """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
279 @param controller: A reference to the GameSceneController.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
280 @type controller: parpg.GameSceneController
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
281 @param commands: Special commands that are executed
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
282 @type commands: Dictionary
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
283 @param view: The view
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
284 @type view: class derived from parpg.ViewBase
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
285 @param text_name: Name of the object containing the text
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
286 @type text_name: String
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
287 @param text: Text to be displayied
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
288 @type text: String
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
289 """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
290 super(ReadAction, self).__init__(controller, commands)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
291 self.view = controller.view
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
292 self.text_name = text_name
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
293 self.text = text
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
294
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
295 def execute(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
296 """Examine the box."""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
297 action_text = unicode('\n'.join(["You read " + self.text_name + ".",
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
298 self.text]))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
299 self.view.hud.addAction(action_text)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
300 logger.debug(action_text)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
301 super(ReadAction, self).execute()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
302
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
303 class TalkAction(Action):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
304 """An action to represent starting a dialogue"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
305 def __init__(self, controller, npc, commands = None):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
306 """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
307 @param controller: A reference to the GameSceneController.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
308 @type controller: parpg.GameSceneController
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
309 @param commands: Special commands that are executed
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
310 @type commands: Dictionary
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
311 @type view: class derived from parpg.ViewBase
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
312 @param view: The view
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
313 @type npc: NonPlayerCharacter
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
314 @param npc: NPC to interact with.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
315 """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
316 super(TalkAction, self).__init__(controller, commands)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
317 self.view = controller.view
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
318 self.npc = npc
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
319
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
320 def execute(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
321 """Talk with the NPC when close enough, otherwise move closer.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
322 @return: None"""
51
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
323 player_char = self.model.game_state.\
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
324 getObjectById("PlayerCharacter").fifeagent
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
325 npc_coordinates = self.npc.fifeagent.behaviour.getLocation().\
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
326 getLayerCoordinates()
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
327 pc_coordinates = player_char.behaviour.agent.\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
328 getLocation().getLayerCoordinates()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
329
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
330 distance_squared = (npc_coordinates.x - pc_coordinates.x) *\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
331 (npc_coordinates.x - pc_coordinates.x) +\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
332 (npc_coordinates.y - pc_coordinates.y) *\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
333 (npc_coordinates.y - pc_coordinates.y)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
334
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
335 # If we are too far away, we approach the NPC again
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
336 if distance_squared > 2:
51
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
337 player_char.behaviour.approach(
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
338 [npc_coordinates.x, npc_coordinates.y],
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
339 TalkAction(self.controller,
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
340 self.npc,
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
341 self.commands
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
342 )
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
343 )
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
344 else:
51
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
345 player_char.behaviour.agent.act(
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
346 'stand',
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
347 self.npc.fifeagent.behaviour.getLocation()
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
348 )
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
349
51
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
350 if self.npc.dialogue.dialogue is not None:
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
351 dialogue_controller = DialogueController(
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
352 self.controller.engine,
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
353 self.view,
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
354 self.model,
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
355 self.controller.application
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
356 )
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
357 self.controller.application.manager.push_mode(
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
358 dialogue_controller
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
359 )
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
360 dialogue_controller.startTalk(self.npc)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
361 else:
51
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
362 self.npc.fifeagent.behaviour.agent.say("Leave me alone!", 1000)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
363
51
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
364 self.model.game_state.getObjectById("PlayerCharacter").\
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
365 fifeagent.behaviour.idle()
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
366 self.model.game_state.getObjectById("PlayerCharacter").\
d3a9caba067b Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents: 44
diff changeset
367 fifeagent.behaviour.nextAction = None
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
368 super(TalkAction, self).execute()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
369
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
370 class UseAction(Action):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
371 """Action for carryable items. It executes special commands that can be only
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
372 used on carryable utens"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
373
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
374
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
375 def __init__(self, controller, item, commands = None):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
376 """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
377 @param controller: A reference to the GameSceneController.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
378 @type controller: parpg.GameSceneController
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
379 @param item: Item on which the action is called
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
380 @type item: CarryableItem
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
381 @param commands: Special commands that are executed
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
382 @type commands: Dictionary
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
383 """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
384 super(UseAction, self).__init__(controller, commands)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
385 self.view = controller.view
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
386 self.item = item
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
387
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
388 def execute(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
389 #Check if there are special commands and execute them
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
390 for command_data in self.commands:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
391 command = command_data["Command"]
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
392 if command == "ReplaceItem":
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
393 object_id = command_data["ID"]
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
394 object_type = command_data["ObjectType"]
136
9397f3e4516d Fixed UseAction.
KarstenBock@gmx.net
parents: 134
diff changeset
395 containable = self.item.containable
9397f3e4516d Fixed UseAction.
KarstenBock@gmx.net
parents: 134
diff changeset
396 new_item = self.model.createItemByType(object_type,
9397f3e4516d Fixed UseAction.
KarstenBock@gmx.net
parents: 134
diff changeset
397 object_id,
9397f3e4516d Fixed UseAction.
KarstenBock@gmx.net
parents: 134
diff changeset
398 self.item.world)
9397f3e4516d Fixed UseAction.
KarstenBock@gmx.net
parents: 134
diff changeset
399 container.put_item(containable.container,
9397f3e4516d Fixed UseAction.
KarstenBock@gmx.net
parents: 134
diff changeset
400 new_item.containable,
9397f3e4516d Fixed UseAction.
KarstenBock@gmx.net
parents: 134
diff changeset
401 containable.slot)
141
658e06a20fa5 ReplaceItem in UseAction will now delete the old object from the database and the world.
KarstenBock@gmx.net
parents: 136
diff changeset
402 self.model.deleteObject(self.item.general.identifier)
658e06a20fa5 ReplaceItem in UseAction will now delete the old object from the database and the world.
KarstenBock@gmx.net
parents: 136
diff changeset
403 self.item.delete()
136
9397f3e4516d Fixed UseAction.
KarstenBock@gmx.net
parents: 134
diff changeset
404 self.view.hud.inventory.updateImages()
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
405 super(UseAction, self).execute()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
406
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
407 class PickUpAction(Action):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
408 """Action for picking up items from a map"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
409
85
04af237dde10 Fixed PickUpAction. Items can be picked up again.
KarstenBock@gmx.net
parents: 54
diff changeset
410 def __init__(self, controller, item, commands = None):
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
411 super(PickUpAction, self).__init__(controller, commands)
85
04af237dde10 Fixed PickUpAction. Items can be picked up again.
KarstenBock@gmx.net
parents: 54
diff changeset
412 self.item = item
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
413 self.view = controller.view
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
414
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
415 def execute(self):
85
04af237dde10 Fixed PickUpAction. Items can be picked up again.
KarstenBock@gmx.net
parents: 54
diff changeset
416 real_item = self.item.containable
101
824f3068ef2a Fixed Saving and Loading.
KarstenBock@gmx.net
parents: 86
diff changeset
417 self.item.fifeagent = None
85
04af237dde10 Fixed PickUpAction. Items can be picked up again.
KarstenBock@gmx.net
parents: 54
diff changeset
418 player = self.model.game_state.getObjectById("PlayerCharacter")
86
a9cc5559ec2a Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents: 85
diff changeset
419 self.model.moveObject(self.item.general.identifier, None)
128
a93b38d7e02b PickUpAction now calls updateObjectDB of the GameModel class.
KarstenBock@gmx.net
parents: 127
diff changeset
420 self.model.updateObjectDB(self.item.world)
85
04af237dde10 Fixed PickUpAction. Items can be picked up again.
KarstenBock@gmx.net
parents: 54
diff changeset
421 container.put_item(player.container, real_item)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
422 super(PickUpAction, self).execute()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
423
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
424 class DropItemAction(Action):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
425 """Action for dropping an items on a map"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
426 def __init__(self, controller, item, commands = None):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
427 super(DropItemAction, self).__init__(controller, commands)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
428 self.item = item
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
429
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
430 def execute(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
431 map_name = self.model.game_state.current_map_name
116
7f7f54c4077b Fixed dropping items on the map.
KarstenBock@gmx.net
parents: 107
diff changeset
432 identifier = self.item.entity.general.identifier
7f7f54c4077b Fixed dropping items on the map.
KarstenBock@gmx.net
parents: 107
diff changeset
433 agent_values = self.model.items[identifier]
7f7f54c4077b Fixed dropping items on the map.
KarstenBock@gmx.net
parents: 107
diff changeset
434 coords = (self.model.game_state.getObjectById("PlayerCharacter").
7f7f54c4077b Fixed dropping items on the map.
KarstenBock@gmx.net
parents: 107
diff changeset
435 fifeagent.behaviour.getLocation().getExactLayerCoordinates()
7f7f54c4077b Fixed dropping items on the map.
KarstenBock@gmx.net
parents: 107
diff changeset
436 )
7f7f54c4077b Fixed dropping items on the map.
KarstenBock@gmx.net
parents: 107
diff changeset
437 agent_values["Position"] = (coords.x, coords.y)
7f7f54c4077b Fixed dropping items on the map.
KarstenBock@gmx.net
parents: 107
diff changeset
438 agent_values["Rotation"] = 0
127
18623b5c2b45 Fixed that dropped items cannot be picked up.
KarstenBock@gmx.net
parents: 125
diff changeset
439 agent_values["Map"] = map_name
116
7f7f54c4077b Fixed dropping items on the map.
KarstenBock@gmx.net
parents: 107
diff changeset
440 self.model.deleteObject(identifier)
127
18623b5c2b45 Fixed that dropped items cannot be picked up.
KarstenBock@gmx.net
parents: 125
diff changeset
441 self.model.addAgent(self.model.ALL_AGENTS_KEY,
18623b5c2b45 Fixed that dropped items cannot be picked up.
KarstenBock@gmx.net
parents: 125
diff changeset
442 {identifier: agent_values})
116
7f7f54c4077b Fixed dropping items on the map.
KarstenBock@gmx.net
parents: 107
diff changeset
443 self.model.placeAgents(self.item.entity.world)
125
452bbc3d915d Fixed that items in the player characters inventory could not be dropped.
KarstenBock@gmx.net
parents: 116
diff changeset
444 self.model.updateObjectDB(self.item.entity.world)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
445 super(DropItemAction, self).execute()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
446
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
447 class DropItemFromContainerAction(DropItemAction):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
448 """Action for dropping an items from the Inventory to a map"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
449
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
450 def __init__(self, controller, item, container_gui, commands = None):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
451 super(DropItemFromContainerAction, self).__init__(controller, item, commands)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
452 self.container_gui = container_gui
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
453
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
454 def execute(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
455 super(DropItemFromContainerAction, self).execute()
145
46570c1ee4ca Changed DropItemFromContainerAction to work with components.
KarstenBock@gmx.net
parents: 141
diff changeset
456 container.remove_item(self.item.container, self.item.slot)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
457 self.container_gui.updateImages()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
458
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
459 class BrewBeerAction(Action):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
460 """Action for brewing beer in a pot"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
461 def __init__(self, controller, pot, commands = None):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
462 super(BrewBeerAction, self).__init__(controller, commands)
134
73b7188a461d Changed BrewBeerAction to work with components.
KarstenBock@gmx.net
parents: 128
diff changeset
463 self.pot = pot.container
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
464 self.view = controller.view
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
465
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
466 def execute(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
467 """Brew the beer"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
468 has_water = False
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
469 has_yeast = False
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
470 has_fruit = False
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
471 has_wood = False
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
472 has_bottle = False
134
73b7188a461d Changed BrewBeerAction to work with components.
KarstenBock@gmx.net
parents: 128
diff changeset
473 player_character = (self.model.game_state.
73b7188a461d Changed BrewBeerAction to work with components.
KarstenBock@gmx.net
parents: 128
diff changeset
474 getObjectById("PlayerCharacter").container)
73b7188a461d Changed BrewBeerAction to work with components.
KarstenBock@gmx.net
parents: 128
diff changeset
475 for item in self.pot.children:
73b7188a461d Changed BrewBeerAction to work with components.
KarstenBock@gmx.net
parents: 128
diff changeset
476 if not item:
73b7188a461d Changed BrewBeerAction to work with components.
KarstenBock@gmx.net
parents: 128
diff changeset
477 continue
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
478 if item.item_type == "Questionable water":
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
479 if has_water:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
480 self.view.hud.addAction(unicode(\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
481 "Please put only 1 water in the pot"))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
482 return
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
483 has_water = True
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
484 water_type = 1
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
485 water = item
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
486 elif item.item_type == "Pure water":
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
487 if has_water:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
488 self.view.hud.addAction(unicode(\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
489 "Please put only 1 water in the pot"))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
490 return
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
491 has_water = True
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
492 water_type = 2
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
493 water = item
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
494 elif item.item_type == "Grain":
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
495 if has_fruit:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
496 self.view.hud.addAction(unicode(\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
497 "Please put only 1 fruit in the pot"))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
498 return
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
499 has_fruit = True
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
500 fruit_type = 3
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
501 fruit = item
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
502 elif item.item_type == "Wild potato":
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
503 if has_fruit:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
504 self.view.hud.addAction(unicode(\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
505 "Please put only 1 fruit in the pot"))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
506 return
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
507 has_fruit = True
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
508 fruit_type = 2
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
509 fruit = item
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
510 elif item.item_type == "Rotten yam":
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
511 if has_fruit:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
512 self.view.hud.addAction(unicode(\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
513 "Please put only 1 fruit in the pot"))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
514 return
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
515 has_fruit = True
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
516 fruit_type = 1
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
517 fruit = item
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
518 elif item.item_type == "Yeast":
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
519 if has_yeast:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
520 self.view.hud.addAction(unicode(\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
521 "Please put only 1 yeast in the pot"))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
522 return
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
523 has_yeast = True
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
524 yeast = item
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
525 else:
134
73b7188a461d Changed BrewBeerAction to work with components.
KarstenBock@gmx.net
parents: 128
diff changeset
526 self.view.hud.addAction(unicode(
73b7188a461d Changed BrewBeerAction to work with components.
KarstenBock@gmx.net
parents: 128
diff changeset
527 "Item " + (item.entity.description.view_name) +
73b7188a461d Changed BrewBeerAction to work with components.
KarstenBock@gmx.net
parents: 128
diff changeset
528 " is not needed for brewing beer"))
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
529 self.view.hud.addAction(unicode(\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
530 "Please put only ingredients for the beer in the pot.\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
531 Things like bottles and wood have to be in your inventory"))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
532 return
134
73b7188a461d Changed BrewBeerAction to work with components.
KarstenBock@gmx.net
parents: 128
diff changeset
533 wood = container.get_item(player_character, "Wood")
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
534 if wood:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
535 has_wood = True
134
73b7188a461d Changed BrewBeerAction to work with components.
KarstenBock@gmx.net
parents: 128
diff changeset
536 bottle = container.get_item(player_character, "Empty beer bottle")
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
537 if bottle:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
538 has_bottle = True
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
539 if has_water and has_fruit and has_wood and has_bottle:
134
73b7188a461d Changed BrewBeerAction to work with components.
KarstenBock@gmx.net
parents: 128
diff changeset
540 container.remove_item(self.pot, water.slot)
73b7188a461d Changed BrewBeerAction to work with components.
KarstenBock@gmx.net
parents: 128
diff changeset
541 container.remove_item(self.pot, fruit.slot)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
542 if has_yeast:
134
73b7188a461d Changed BrewBeerAction to work with components.
KarstenBock@gmx.net
parents: 128
diff changeset
543 container.remove_item(self.pot, yeast.slot)
73b7188a461d Changed BrewBeerAction to work with components.
KarstenBock@gmx.net
parents: 128
diff changeset
544 container.remove_item(player_character, wood.slot)
73b7188a461d Changed BrewBeerAction to work with components.
KarstenBock@gmx.net
parents: 128
diff changeset
545 new_item = (self.model.createItemByType("Beer", "Beer",
73b7188a461d Changed BrewBeerAction to work with components.
KarstenBock@gmx.net
parents: 128
diff changeset
546 self.pot.entity.world)
73b7188a461d Changed BrewBeerAction to work with components.
KarstenBock@gmx.net
parents: 128
diff changeset
547 )
73b7188a461d Changed BrewBeerAction to work with components.
KarstenBock@gmx.net
parents: 128
diff changeset
548 container.put_item(player_character, new_item.containable)
73b7188a461d Changed BrewBeerAction to work with components.
KarstenBock@gmx.net
parents: 128
diff changeset
549 self.view.hud.inventory.updateImages()
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
550 beer_quality = 0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
551 if water_type == 1:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
552 if fruit_type == 1:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
553 beer_quality = -1
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
554 elif fruit_type == 2:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
555 beer_quality = 2
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
556 elif fruit_type == 3:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
557 beer_quality = 3
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
558 if water_type == 2:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
559 if fruit_type == 1:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
560 beer_quality = 1
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
561 elif fruit_type == 2:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
562 beer_quality = 3
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
563 elif fruit_type == 3:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
564 beer_quality = 4
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
565 if beer_quality > 0 and has_yeast:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
566 beer_quality += 1
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
567 self.model.game_state.quest_engine.quests["beer"].\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
568 setValue("beer_quality", beer_quality)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
569 else:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
570 self.view.hud.addAction(unicode(
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
571 """For brewing beer you need at least:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
572 In the pot:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
573 Fruit (like grain, potato, yam)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
574 Water
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
575 Optionally:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
576 Good quality yeast.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
577 Wild yeast will be used if none present.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
578 In the inventory:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
579 Wood
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
580 Empty bottle"""))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
581 super(BrewBeerAction, self).execute()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
582
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
583 ACTIONS = {"ChangeMap":ChangeMapAction,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
584 "Open":OpenAction,
104
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
585 "Close":CloseAction,
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
586 "Unlock":UnlockAction,
c9afad46091b Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents: 101
diff changeset
587 "Lock":LockAction,
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
588 "ExamineItem":ExamineItemAction,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
589 "Examine":ExamineAction,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
590 "Look":ExamineItemAction,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
591 "Read":ReadAction,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
592 "Talk":TalkAction,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
593 "Use":UseAction,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
594 "PickUp":PickUpAction,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
595 "DropFromInventory":DropItemFromContainerAction,
107
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
596 "BrewBeer":BrewBeerAction,
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
597 "ExamineContents": ExamineContentsAction,
100a39fa64a2 Added ExamineContentsAction.
KarstenBock@gmx.net
parents: 104
diff changeset
598 }