Mercurial > fife-parpg
annotate demos/rpg/scripts/actors/baseactor.py @ 660:b0733d998d0f
* Updated the REAMDE
* Changed any 0.3.1 references to 0.3.2 in preparation for the upcoming release
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Wed, 03 Nov 2010 13:44:12 +0000 |
parents | 872a7a94563e |
children |
rev | line source |
---|---|
513
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 #!/usr/bin/env python |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 # -*- coding: utf-8 -*- |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 # #################################################################### |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
6 # Copyright (C) 2005-2010 by the FIFE team |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
7 # http://www.fifengine.net |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
8 # This file is part of FIFE. |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
9 # |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 # FIFE is free software; you can redistribute it and/or |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
11 # modify it under the terms of the GNU Lesser General Public |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 # License as published by the Free Software Foundation; either |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
13 # version 2.1 of the License, or (at your option) any later version. |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
14 # |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
15 # This library is distributed in the hope that it will be useful, |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 # Lesser General Public License for more details. |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
19 # |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
20 # You should have received a copy of the GNU Lesser General Public |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 # License along with this library; if not, write to the |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 # Free Software Foundation, Inc., |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 # #################################################################### |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 import sys, os, re, math, random, shutil |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 from fife import fife |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 from fife.extensions.loaders import loadMapFile |
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 |
520
b6bd314df28a
Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
519
diff
changeset
|
31 from scripts.objects.baseobject import ObjectActionListener, BaseGameObject, GameObjectTypes |
543
cb7ec12214a9
Items can now be serialized/deserialized to/from disk. I haven't finished actors yet. This allows for persistent states when you enter/leave maps.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
540
diff
changeset
|
32 from scripts.objects.items import GoldStack |
560
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
33 from scripts.misc.serializer import Serializer |
517
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
34 |
519
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
35 Actions = {'NONE':0, |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
36 'PICKUP':1, |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
37 'TALK':2, |
535
9fbe3dce925a
Added custom exceptions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
534
diff
changeset
|
38 'ATTACK':3, |
520
b6bd314df28a
Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
519
diff
changeset
|
39 'OPEN':4, |
b6bd314df28a
Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
519
diff
changeset
|
40 'ENTER':5} |
519
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
41 |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
42 class BaseAction(object): |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
43 def __init__(self): |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
44 self._actiontype = Actions['NONE'] |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
45 |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
46 def execute(self): |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
47 pass |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
48 |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
49 class TalkAction(BaseAction): |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
50 def __init__(self, sourceobj, destobj): |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
51 self._actiontype = Actions['TALK'] |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
52 self._source = sourceobj |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
53 self._dest = destobj |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
54 |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
55 def execute(self): |
524
6037f79b0dcf
Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
523
diff
changeset
|
56 if self._dest.type == GameObjectTypes["QUESTGIVER"]: |
6037f79b0dcf
Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
523
diff
changeset
|
57 if self._dest.haveQuest(): |
6037f79b0dcf
Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
523
diff
changeset
|
58 if not self._dest.activequest: |
6037f79b0dcf
Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
523
diff
changeset
|
59 self._dest.offerNextQuest() |
6037f79b0dcf
Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
523
diff
changeset
|
60 else: |
6037f79b0dcf
Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
523
diff
changeset
|
61 self._dest.completeQuest() |
521
494c60cf61cf
Player can now receive a quest, accept it, and complete it. Quests do not have any requirements (i.e. bring me back an item.. etc etc) to be completed at this time.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
520
diff
changeset
|
62 else: |
560
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
63 self._dest.showNoQuestDialog() |
523
d01eb65b2726
Enabling the FloatingTextRenderer for the RPG demo. The NPC now complains at you if he doesn't have a quest to give you.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
521
diff
changeset
|
64 else: |
563
f85762e634c5
- Added the AttackAction along with a test enemy on level 1.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
560
diff
changeset
|
65 self._dest.say("Hello there!") |
f85762e634c5
- Added the AttackAction along with a test enemy on level 1.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
560
diff
changeset
|
66 |
f85762e634c5
- Added the AttackAction along with a test enemy on level 1.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
560
diff
changeset
|
67 class AttackAction(BaseAction): |
f85762e634c5
- Added the AttackAction along with a test enemy on level 1.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
560
diff
changeset
|
68 def __init__(self, attacker, defender): |
f85762e634c5
- Added the AttackAction along with a test enemy on level 1.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
560
diff
changeset
|
69 self._actiontype = Actions['ATTACK'] |
f85762e634c5
- Added the AttackAction along with a test enemy on level 1.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
560
diff
changeset
|
70 self._attacker = attacker |
f85762e634c5
- Added the AttackAction along with a test enemy on level 1.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
560
diff
changeset
|
71 self._defender = defender |
f85762e634c5
- Added the AttackAction along with a test enemy on level 1.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
560
diff
changeset
|
72 |
f85762e634c5
- Added the AttackAction along with a test enemy on level 1.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
560
diff
changeset
|
73 def execute(self): |
f85762e634c5
- Added the AttackAction along with a test enemy on level 1.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
560
diff
changeset
|
74 if self._defender.type == GameObjectTypes["ENEMY"]: |
f85762e634c5
- Added the AttackAction along with a test enemy on level 1.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
560
diff
changeset
|
75 self._defender.say("Ouch") |
528
796d49ab9380
Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
524
diff
changeset
|
76 |
796d49ab9380
Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
524
diff
changeset
|
77 class PickUpItemAction(BaseAction): |
796d49ab9380
Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
524
diff
changeset
|
78 def __init__(self, actor, item): |
796d49ab9380
Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
524
diff
changeset
|
79 self._actiontype = Actions['PICKUP'] |
796d49ab9380
Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
524
diff
changeset
|
80 self._actor = actor |
796d49ab9380
Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
524
diff
changeset
|
81 self._item = item |
796d49ab9380
Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
524
diff
changeset
|
82 |
796d49ab9380
Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
524
diff
changeset
|
83 def execute(self): |
796d49ab9380
Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
524
diff
changeset
|
84 self._actor.pickUpItem(self._item) |
540
2e739ae9a8bc
Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
536
diff
changeset
|
85 |
2e739ae9a8bc
Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
536
diff
changeset
|
86 class EnterPortalAction(BaseAction): |
2e739ae9a8bc
Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
536
diff
changeset
|
87 def __init__(self, actor, portal): |
2e739ae9a8bc
Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
536
diff
changeset
|
88 self._actiontype = Actions["ENTER"] |
2e739ae9a8bc
Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
536
diff
changeset
|
89 self._actor = actor |
2e739ae9a8bc
Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
536
diff
changeset
|
90 self._portal = portal |
2e739ae9a8bc
Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
536
diff
changeset
|
91 |
2e739ae9a8bc
Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
536
diff
changeset
|
92 def execute(self): |
2e739ae9a8bc
Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
536
diff
changeset
|
93 self._actor.enterPortal(self._portal) |
519
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
94 |
517
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
95 ActorStates = {'STAND':0, |
516
d70fc46c8aa5
Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
513
diff
changeset
|
96 'WALK':1, |
d70fc46c8aa5
Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
513
diff
changeset
|
97 'ATTACK':2} |
d70fc46c8aa5
Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
513
diff
changeset
|
98 |
517
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
99 class ActorActionListener(ObjectActionListener): |
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
100 def __init__(self, gamecontroller, obj): |
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
101 super(ActorActionListener, self).__init__(gamecontroller, obj) |
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
102 |
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
103 def onInstanceActionFinished(self, instance, action): |
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
104 if action.getId() == 'walk': |
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
105 self._object.stand() |
519
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
106 self._object.performNextAction() |
517
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
107 |
560
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
108 class ActorAttributes(Serializer): |
575
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
109 def __init__(self, strength=0, dexterity=0, intelligence=0, health=0, walkspeed=0): |
560
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
110 self._str = strength |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
111 self._dex = dexterity |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
112 self._int = intelligence |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
113 self._hp = health |
575
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
114 self._walkspeed = walkspeed |
560
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
115 |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
116 def serialize(self): |
575
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
117 lvars = {} |
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
118 |
560
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
119 lvars['str'] = self._str |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
120 lvars['dex'] = self._dex |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
121 lvars['int'] = self._int |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
122 lvars['hp'] = self._hp |
575
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
123 lvars['walk_speed'] = self._walkspeed |
560
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
124 |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
125 return lvars |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
126 |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
127 def deserialize(self, valuedict): |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
128 if valuedict.has_key("str"): |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
129 self._str = int(valuedict['str']) |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
130 if valuedict.has_key("dex"): |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
131 self._dex = int(valuedict['dex']) |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
132 if valuedict.has_key("int"): |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
133 self._int = int(valuedict['int']) |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
134 if valuedict.has_key("hp"): |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
135 self._hp = int(valuedict['hp']) |
575
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
136 if valuedict.has_key("walk_speed"): |
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
137 self._walkspeed = float(valuedict['walk_speed']) |
560
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
138 |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
139 def _getStrength(self): |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
140 return self._str |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
141 |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
142 def _setStrength(self, strength): |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
143 self._str = strength |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
144 |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
145 def _getDexterity(self): |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
146 return self._dexterity |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
147 |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
148 def _setDexterity(self, dexterity): |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
149 self._dexterity = dexterity |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
150 |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
151 def _getIntelligence(self): |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
152 return self._int |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
153 |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
154 def _setIntelligence(self, intelligence): |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
155 self._int = intelligence |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
156 |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
157 def _getHealth(self): |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
158 return self._hp |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
159 |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
160 def _setHealth(self, health): |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
161 self._hp = health |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
162 |
575
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
163 def _getWalkSpeed(self): |
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
164 return self._walkspeed |
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
165 |
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
166 def _setWalkSpeed(self, walkspeed): |
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
167 self._walkspeed = walkspeed |
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
168 |
560
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
169 |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
170 strength = property(_getStrength, _setStrength) |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
171 dexterity = property(_getDexterity, _setDexterity) |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
172 intelligence = property(_getIntelligence, _setIntelligence) |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
173 health = property(_getHealth, _setHealth) |
575
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
174 walkspeed = property(_getWalkSpeed, _setWalkSpeed) |
560
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
175 |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
176 |
517
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
177 class Actor(BaseGameObject): |
546
8fee2d2286e9
Rewrote the object serializing routines to use a "template" idea for loading an object from disk. This allows for multiple objects to load the same base object template but be unique on the scene AND have different values. Useful for say more than one gold stack on the ground with different gold values. TODO: fix the "spawn" console command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
543
diff
changeset
|
178 def __init__(self, gamecontroller, layer, typename, baseobjectname, instancename, instanceid=None, createInstance=False): |
8fee2d2286e9
Rewrote the object serializing routines to use a "template" idea for loading an object from disk. This allows for multiple objects to load the same base object template but be unique on the scene AND have different values. Useful for say more than one gold stack on the ground with different gold values. TODO: fix the "spawn" console command.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
543
diff
changeset
|
179 super(Actor, self).__init__(gamecontroller, layer, typename, baseobjectname, instancename, instanceid, createInstance) |
543
cb7ec12214a9
Items can now be serialized/deserialized to/from disk. I haven't finished actors yet. This allows for persistent states when you enter/leave maps.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
540
diff
changeset
|
180 |
519
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
181 self._nextaction = None |
529
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
182 self._inventory = [] |
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
183 self._maxinventoryitems = 20 |
560
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
184 |
529
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
185 self._gold = 0 |
560
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
186 self._attributes = ActorAttributes() |
575
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
187 |
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
188 #set the default walkspeed |
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
189 self._attributes.walkspeed = self._gamecontroller.settings.get("RPG", "DefaultActorWalkSpeed", 4.0) |
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
190 |
517
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
191 self.stand() |
540
2e739ae9a8bc
Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
536
diff
changeset
|
192 |
517
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
193 def stand(self): |
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
194 self._state = ActorStates["STAND"] |
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
195 self._instance.act('stand', self._instance.getFacingLocation()) |
513
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
196 |
516
d70fc46c8aa5
Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
513
diff
changeset
|
197 def walk(self, location): |
d70fc46c8aa5
Added some placeholder graphics for the warrior. The player can now walk around the map.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
513
diff
changeset
|
198 self._state = ActorStates["WALK"] |
575
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
199 self._instance.move('walk', location, self._attributes.walkspeed) |
517
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
200 |
529
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
201 def say(self, text): |
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
202 self._instance.say(text, 2500) |
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
203 |
519
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
204 def performNextAction(self): |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
205 if self._nextaction: |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
206 self._nextaction.execute() |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
207 self._nextaction = None |
528
796d49ab9380
Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
524
diff
changeset
|
208 |
796d49ab9380
Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
524
diff
changeset
|
209 def pickUpItem(self, item): |
560
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
210 if self.addItemToInventory(item): |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
211 item.onPickUp() |
529
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
212 else: |
560
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
213 #could do something cool like throw the item back on the ground |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
214 pass |
529
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
215 |
540
2e739ae9a8bc
Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
536
diff
changeset
|
216 def enterPortal(self, portal): |
2e739ae9a8bc
Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
536
diff
changeset
|
217 if self._id == "player": |
2e739ae9a8bc
Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
536
diff
changeset
|
218 self._gamecontroller.switchMap(portal.dest) |
2e739ae9a8bc
Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
536
diff
changeset
|
219 else: |
2e739ae9a8bc
Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
536
diff
changeset
|
220 self._gamecontroller.scene.removeObjectFromScene(self._id) |
560
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
221 |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
222 def addItemToInventory(self, item): |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
223 if len(self._inventory) >= self._maxinventoryitems: |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
224 return False |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
225 else: |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
226 if type(item) == GoldStack: |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
227 self._gold += item.value |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
228 else: |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
229 self._inventory.append(item) |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
230 |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
231 return True |
540
2e739ae9a8bc
Some misc code cleanup.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
536
diff
changeset
|
232 |
529
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
233 def removeItemFromInventory(self, itemid): |
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
234 itemtoremove = None |
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
235 for item in self._inventory: |
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
236 if item.id == itemid: |
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
237 itemtoremove = item |
528
796d49ab9380
Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
524
diff
changeset
|
238 |
529
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
239 if itemtoremove: |
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
240 self._inventory.remove(itemtoremove) |
547
e59ece21ab3e
Item serialization will now assume some default values if they are not found in the save files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
546
diff
changeset
|
241 |
e59ece21ab3e
Item serialization will now assume some default values if they are not found in the save files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
546
diff
changeset
|
242 def serialize(self): |
e59ece21ab3e
Item serialization will now assume some default values if they are not found in the save files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
546
diff
changeset
|
243 lvars = super(Actor, self).serialize() |
e59ece21ab3e
Item serialization will now assume some default values if they are not found in the save files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
546
diff
changeset
|
244 |
e59ece21ab3e
Item serialization will now assume some default values if they are not found in the save files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
546
diff
changeset
|
245 lvars['gold'] = self._gold |
529
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
246 |
575
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
247 att_vars = self._attributes.serialize() |
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
248 for key, value in att_vars.items(): |
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
249 lvars[key] = value |
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
250 |
547
e59ece21ab3e
Item serialization will now assume some default values if they are not found in the save files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
546
diff
changeset
|
251 return lvars |
e59ece21ab3e
Item serialization will now assume some default values if they are not found in the save files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
546
diff
changeset
|
252 |
e59ece21ab3e
Item serialization will now assume some default values if they are not found in the save files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
546
diff
changeset
|
253 def deserialize(self, valuedict): |
e59ece21ab3e
Item serialization will now assume some default values if they are not found in the save files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
546
diff
changeset
|
254 super(Actor, self).deserialize(valuedict) |
e59ece21ab3e
Item serialization will now assume some default values if they are not found in the save files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
546
diff
changeset
|
255 |
e59ece21ab3e
Item serialization will now assume some default values if they are not found in the save files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
546
diff
changeset
|
256 if valuedict.has_key("gold"): |
e59ece21ab3e
Item serialization will now assume some default values if they are not found in the save files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
546
diff
changeset
|
257 self._gold = int(valuedict['gold']) |
e59ece21ab3e
Item serialization will now assume some default values if they are not found in the save files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
546
diff
changeset
|
258 else: |
e59ece21ab3e
Item serialization will now assume some default values if they are not found in the save files.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
546
diff
changeset
|
259 self._gold = 0 |
560
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
260 |
575
872a7a94563e
- Updated the soundmanager extension to reflect changes made in last commit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
563
diff
changeset
|
261 self._attributes.deserialize(valuedict) |
519
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
262 |
517
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
263 def _getState(self): |
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
264 return self._state |
513
edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
265 |
517
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
266 def _setState(self, state): |
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
267 self._state = state |
519
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
268 |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
269 def _getNextAction(self): |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
270 return self._nextaction |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
271 |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
272 def _setNextAction(self, action): |
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
273 self._nextaction = action |
517
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
274 |
529
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
275 def _getGold(self): |
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
276 return self._gold |
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
277 |
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
278 def _setGold(self, gold): |
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
279 self._gold = gold |
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
280 |
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
281 def _getInventory(self): |
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
282 return self._inventory |
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
283 |
560
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
284 def _getAttributes(self): |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
285 return self._attributes |
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
286 |
517
c3a026cdd91b
Added the BaseGameObject class and put it in it's own file. All game object will inherit it. Added instance action listeners.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
516
diff
changeset
|
287 state = property(_getState, _setState) |
519
14f777be6b94
Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
517
diff
changeset
|
288 nextaction = property(_getNextAction, _setNextAction) |
529
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
289 gold = property(_getGold, _setGold) |
d0bce896a526
Changed the quest format in the object xml file.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
528
diff
changeset
|
290 inventory = property(_getInventory) |
560
69d50e751c9a
Lots of changes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
547
diff
changeset
|
291 attributes = property(_getAttributes) |