Mercurial > parpg-source
annotate charactercreationcontroller.py @ 180:0d0422243490
The getGameEnvironment method of GameState will now return a globals dictionary where __builtins__ is disabled.
author | Beliar |
---|---|
date | Sat, 10 Mar 2012 13:31:47 +0100 |
parents | b3b82c2aebee |
children | 2a12e2843984 |
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 """Provides the controller that defines the behaviour of the character creation |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
16 screen.""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
17 |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
18 from parpg import vfs |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
19 from controllerbase import ControllerBase |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
20 from gamescenecontroller import GameSceneController |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
21 from gamesceneview import GameSceneView |
113 | 22 from parpg.world import World |
23 from parpg.entities import General | |
155 | 24 from parpg.components import character_statistics |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
25 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
26 def getStatCost(offset): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
27 """Gets and returns the cost to increase stat based on the offset""" |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
28 |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
29 if offset < 0: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
30 offset *= -1 |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
31 |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
32 if offset < 22: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
33 return 1 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
34 elif offset < 29: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
35 return 2 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
36 elif offset < 32: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
37 return 3 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
38 elif offset < 35: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
39 return 4 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
40 elif offset < 36: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
41 return 5 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
42 elif offset < 38: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
43 return 6 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
44 elif offset < 39: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
45 return 7 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
46 elif offset < 40: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
47 return 8 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
48 elif offset < 41: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
49 return 9 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
50 else: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
51 return 10 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
52 |
113 | 53 class CharacterCreationController(ControllerBase, World): |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
54 """Controller defining the behaviour of the character creation screen.""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
55 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
56 #TODO: Change to actual values |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
57 MAX_TRAITS = 3 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
58 MIN_AGE = 16 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
59 MAX_AGE = 40 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
60 ORIGINS = {"None": None,} |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
61 GENDERS = ["Male", "Female",] |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
62 PICTURES = {"Male": ["None",], "Female": ["None",],} |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
63 TRAITS = {} |
113 | 64 MAX_BULK = 100 |
65 INV_SLOTS = 20 | |
66 | |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
67 def __init__(self, engine, view, model, application): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
68 """Construct a new L{CharacterCreationController} instance. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
69 @param engine: Rendering engine used to display the associated view. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
70 @type engine: L{fife.Engine} |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
71 @param view: View used to display the character creation screen. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
72 @type view: L{ViewBase} |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
73 @param model: Model of the game state. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
74 @type model: L{GameModel} |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
75 @param application: Application used to glue the various MVC |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
76 components together. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
77 @type application: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
78 L{fife.extensions.basicapplication.ApplicationBase}""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
79 ControllerBase.__init__(self, engine, view, model, application) |
113 | 80 World.__init__(self) |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
81 self.settings = self.model.settings |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
82 self.view.start_new_game_callback = self.startNewGame |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
83 self.view.cancel_new_game_callback = self.cancelNewGame |
114 | 84 |
85 def reset_character(self): | |
113 | 86 inventory = [] |
87 for x in xrange(self.INV_SLOTS): | |
88 inventory.append(None) | |
89 self.char_data = General(self, "PlayerCharacter") | |
90 self.char_data.description.view_name = "Player" | |
91 self.char_data.description.real_name = "Enter name here" | |
92 self.char_data.characterstats.gender = self.GENDERS[0] | |
93 self.char_data.characterstats.origin = self.ORIGINS.keys()[0] | |
94 self.char_data.characterstats.age = 20 | |
95 self.char_data.characterstats.picture = ( | |
96 self.PICTURES[self.GENDERS[0]][0] | |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
97 ) |
155 | 98 self.model.create_stats(self.char_data) |
113 | 99 self.char_data.container.max_bulk = self.MAX_BULK |
100 self.char_data.container.children = inventory | |
155 | 101 self._stat_points = 200 |
102 | |
103 def update_agent(self): | |
104 """Updates the player agent data in the model""" | |
105 agent_data = ( | |
106 self.model.agents[self.model.ALL_AGENTS_KEY]["PlayerCharacter"] | |
107 ) | |
108 agent_data["Statistics"] = ( | |
109 character_statistics.get_stat_values( | |
110 self.char_data.characterstats | |
111 )["primary"] | |
112 ) | |
113 | |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
114 def startNewGame(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
115 """Create the new character and start a new game. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
116 @return: None""" |
155 | 117 self.update_agent() |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
118 view = GameSceneView(self.engine, self.model) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
119 controller = GameSceneController(self.engine, view, self.model, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
120 self.application) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
121 self.application.view = view |
17
7b31de1dc964
FifeManager no longer subclasses ApplicationBase
KarstenBock@gmx.net
parents:
8
diff
changeset
|
122 self.application.manager.swap_modes(controller) |
167
b3b82c2aebee
Using fife settings module again instead of our own.
Beliar <KarstenBock@gmx.net>
parents:
155
diff
changeset
|
123 start_map = self.settings.get("parpg", "Map") |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
124 self.model.changeMap(start_map) |
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 def cancelNewGame(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
127 """Exit the character creation view and return the to main menu. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
128 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
129 # KLUDGE Technomage 2010-12-24: This is to prevent a circular import |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
130 # but a better fix needs to be thought up. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
131 from mainmenucontroller import MainMenuController |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
132 from mainmenuview import MainMenuView |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
133 view = MainMenuView(self.engine, self.model) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
134 controller = MainMenuController(self.engine, view, self.model, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
135 self.application) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
136 self.application.view = view |
17
7b31de1dc964
FifeManager no longer subclasses ApplicationBase
KarstenBock@gmx.net
parents:
8
diff
changeset
|
137 self.application.manager.activate_mode(controller) |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
138 |
113 | 139 def on_activate(self): |
140 self.reset_character() | |
141 self.view.show() | |
142 | |
8
708a6f651c31
Modifications to use the grease manager and modes
KarstenBock@gmx.net
parents:
2
diff
changeset
|
143 def on_deactivate(self): |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
144 """Called when the controller is removed from the list. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
145 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
146 self.view.hide() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
147 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
148 @property |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
149 def name(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
150 """Returns the name of the character. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
151 @return: Name of the character""" |
113 | 152 return self.char_data.description.real_name |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
153 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
154 @property |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
155 def age(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
156 """Returns the age of the character. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
157 @return: Age of the character""" |
113 | 158 return self.char_data.characterstats.age |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
159 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
160 @property |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
161 def gender(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
162 """Returns the gender of the character. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
163 @return: Gender of the character""" |
113 | 164 return self.char_data.characterstats.gender |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
165 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
166 @property |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
167 def origin(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
168 """Returns the origin of the character. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
169 @return: Origin of the character""" |
113 | 170 return self.char_data.characterstats.origin |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
171 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
172 @property |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
173 def picture(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
174 """Returns the ID of the current picture of the character.""" |
113 | 175 return self.char_data.characterstats.picture |
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 getStatPoints(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
178 """Returns the remaining statistic points that can be distributed""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
179 return self._stat_points |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
180 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
181 def increaseStatistic(self, statistic): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
182 """Increases the given statistic by one. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
183 @param statistic: Name of the statistic to increase |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
184 @type statistic: string""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
185 if self.canIncreaseStatistic(statistic): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
186 cost = self.getStatisticIncreaseCost(statistic) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
187 if cost <= self._stat_points: |
113 | 188 (self.char_data.characterstats. |
189 primary_stats[statistic].value) += 1 | |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
190 self._stat_points -= cost |
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 def getStatisticIncreaseCost(self, statistic): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
193 """Calculate and return the cost to increase the statistic |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
194 @param statistic: Name of the statistic to increase |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
195 @type statistic: string |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
196 @return cost to increase the statistic""" |
113 | 197 cur_value = (self.char_data.characterstats. |
198 primary_stats[statistic].value) | |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
199 new_value = cur_value + 1 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
200 offset = new_value - DEFAULT_STAT_VALUE |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
201 return getStatCost(offset) |
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 def canIncreaseStatistic(self, statistic): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
204 """Checks whether the given statistic can be increased or not. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
205 @param statistic: Name of the statistic to check |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
206 @type statistic: string |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
207 @return: True if the statistic can be increased, False if not.""" |
113 | 208 stat = self.char_data.characterstats.primary_stats[statistic].value |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
209 return stat < stat.statistic_type.maximum |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
210 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
211 def decreaseStatistic(self, statistic): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
212 """Decreases the given statistic by one. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
213 @param statistic: Name of the statistic to decrease |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
214 @type statistic: string""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
215 if self.canDecreaseStatistic(statistic): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
216 gain = self.getStatisticDecreaseGain(statistic) |
113 | 217 self.char_data.characterstats.primary_stats[statistic].value -= 1 |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
218 self._stat_points += gain |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
219 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
220 def getStatisticDecreaseGain(self, statistic): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
221 """Calculate and return the gain of decreasing the statistic |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
222 @param statistic: Name of the statistic to decrease |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
223 @type statistic: string |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
224 @return cost to decrease the statistic""" |
113 | 225 cur_value = (self.char_data.characterstats. |
226 primary_stats[statistic].value) | |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
227 new_value = cur_value - 1 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
228 offset = new_value - DEFAULT_STAT_VALUE |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
229 return getStatCost(offset) |
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 def canDecreaseStatistic(self, statistic): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
232 """Checks whether the given statistic can be decreased or not. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
233 @param statistic: Name of the statistic to check |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
234 @type statistic: string |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
235 @return: True if the statistic can be decreased, False if not.""" |
113 | 236 stat = self.char_data.characterstats.primary_stats[statistic].value |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
237 return stat > stat.statistic_type.minimum |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
238 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
239 def getStatisticValue(self, statistic): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
240 """Returns the value of the given statistic. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
241 @param statistic: Name of the primary or secondary statistic |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
242 @type statistic: string |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
243 @return: Value of the given statistic""" |
113 | 244 if self.char_data.characterstats.primary_stats.has_key: |
245 return self.char_data.characterstats.primary_stats[statistic] | |
246 else: | |
247 return self.char_data.characterstats.secondary_stats[statistic] | |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
248 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
249 def areAllStatisticsValid(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
250 """Checks if all statistics are inside the minimum/maximum values |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
251 @return True if all statistics are valid False if not""" |
113 | 252 all_stats = self.char_data.characterstats.primary_stats.items() |
253 all_stats.extend(self.char_data.characterstats.secondary_stats.items()) | |
254 for stat in all_stats: | |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
255 if not (stat.value > stat.statistic_type.minumum and\ |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
256 stat.value < stat.statistic_type.maximum): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
257 return False |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
258 return True |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
259 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
260 def setName(self, name): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
261 """Sets the name of the character to the given value. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
262 @param name: New name |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
263 @type name: string""" |
113 | 264 self.char_data.description.real_name = name |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
265 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
266 def isNameValid(self, name): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
267 """Checks whether the name is valid. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
268 @param name: Name to check |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
269 @type name: string |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
270 @return: True if the name is valid, False if not""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
271 if name: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
272 return True |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
273 return False |
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 def changeOrigin(self, origin): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
276 """Changes the origin of the character to the given value. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
277 @param origin: New origin |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
278 @type origin: string""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
279 if self.isOriginValid(origin): |
113 | 280 self.char_data.characterstats.origin = origin |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
281 #TODO: Make changes according to origin |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
282 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
283 def isOriginValid(self, origin): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
284 """Checks whether the origin is valid. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
285 @param origin: Origin to check |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
286 @type origin: string |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
287 @return: True if the origin is valid, False if not""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
288 return origin in self.ORIGINS |
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 def changeGender(self, gender): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
291 """Changes the gender of the character to the given value. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
292 @param gender: New gender |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
293 @param gender: string""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
294 if self.isGenderValid(gender): |
113 | 295 self.char_data.characterstats.gender = gender |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
296 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
297 def isGenderValid(self, gender): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
298 """Checks whether the gender is valid. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
299 @param gender: Gender to check |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
300 @type gender: string? |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
301 @return: True if the origin is valid, False if not""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
302 return gender in self.GENDERS |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
303 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
304 def changeAge(self, age): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
305 """Sets the age of the character to the given value. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
306 @param age: New age |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
307 @type age: integer |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
308 """ |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
309 if self.isAgeValid(age): |
113 | 310 self.char_data.characterstats.age = age |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
311 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
312 def isAgeValid(self, age): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
313 """Checks whether the age is valid. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
314 @param age: Age to check |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
315 @type age: integer |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
316 @return: True if the origin is valid, False if not""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
317 return age >= self.MIN_AGE and age <= self.MAX_AGE |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
318 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
319 def setPicture(self, picture): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
320 """Set picture of the character. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
321 @param picture: ID of the new picture |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
322 @type picture: string""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
323 if self.isPictureValid(picture): |
113 | 324 self.char_data.characterstats.picture = picture |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
325 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
326 def isPictureValid(self, picture): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
327 """Checks whether the picture is valid. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
328 @param picture: ID of the picture to check |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
329 @type picture: string |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
330 @return: True if the picture is valid, False if not""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
331 return picture in self.PICTURES[self.gender] |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
332 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
333 def addTrait(self, trait): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
334 """Adds a trait to the character. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
335 @param trait: ID of the trait to add |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
336 @type trait: string""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
337 if self.canAddAnotherTrait() and self.isTraitValid(trait)\ |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
338 and not self.hasTrait(trait): |
113 | 339 self.char_data.characterstats.traits.append(trait) |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
340 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
341 def canAddAnotherTrait(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
342 """Checks whether another trait can be added. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
343 @return: True if another trait can be added, False if not""" |
113 | 344 return len(self.char_data.characterstats.traits) < self.MAX_TRAITS |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
345 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
346 def removeTrait(self, trait): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
347 """Remove trait from character. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
348 @param trait: ID of the trait to remove |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
349 @type trait: string""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
350 if self.hasTrait(trait): |
113 | 351 self.char_data.characterstats.traits.remove(trait) |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
352 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
353 def hasTrait(self, trait): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
354 """Checks whether the character has the trait. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
355 @param trait: ID of the trait to check |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
356 @type trait: string |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
357 @return: True if the character has the trait, False if not""" |
113 | 358 return trait in self.char_data.characterstats.traits |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
359 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
360 def isTraitValid(self, trait): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
361 """Checks whether the trait is valid. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
362 @param trait: ID of the trait to check |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
363 @type trait: string |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
364 @return: True if the trait is valid, False if not""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
365 return trait in self.TRAITS |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
366 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
367 def areCurrentTraitsValid(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
368 """Checks whether the characters traits are valid. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
369 @return: True if the traits are valid, False if not""" |
113 | 370 if len(self.char_data.characterstats.traits) > self.MAX_TRAITS: |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
371 return False |
113 | 372 for trait in self.char_data.characterstats.traits: |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
373 if not self.isTraitValid(trait): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
374 return False |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
375 return True |
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 def isCharacterValid(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
378 """Checks whether the character as a whole is valid. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
379 @return: True if the character is valid, False if not""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
380 #Single checks can be disabled by putting a "#" in front of them |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
381 if True\ |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
382 and self._stat_points >= 0\ |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
383 and self.areAllStatisticsValid() \ |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
384 and self.areCurrentTraitsValid() \ |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
385 and self.isNameValid(self.name)\ |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
386 and self.isPictureValid(self.picture)\ |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
387 and self.isAgeValid(self.age)\ |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
388 and self.isGenderValid(self.gender)\ |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
389 and self.isOriginValid(self.origin)\ |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
390 : |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
391 return True |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
392 return False |