annotate demos/rpg/scripts/actors/baseactor.py @ 528:796d49ab9380

Cleaned up the createScene function. Items can now be picked up.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 28 May 2010 14:52:56 +0000
parents 6037f79b0dcf
children d0bce896a526
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 # This is the rio de hola client for 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
26
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 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
28
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 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
30 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
31
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
32 from scripts.objects.baseobject import ObjectActionListener, BaseGameObject, GameObjectTypes
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
33
519
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
34 Actions = {'NONE':0,
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
35 'PICKUP':1,
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
36 'TALK':2,
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
37 'HIT':3,
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
38 'OPEN':4,
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
39 'ENTER':5}
519
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
40
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
41 class BaseAction(object):
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
42 def __init__(self):
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
43 self._actiontype = Actions['NONE']
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
44
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
45 def execute(self):
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
46 pass
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
47
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
48 class TalkAction(BaseAction):
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
49 def __init__(self, sourceobj, destobj):
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
50 self._actiontype = Actions['TALK']
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
51 self._source = sourceobj
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
52 self._dest = destobj
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
53
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
54 def execute(self):
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
55 print "talking to: " + self._dest.instance.getId()
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
56
524
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
57 if self._dest.type == GameObjectTypes["QUESTGIVER"]:
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
58 if self._dest.haveQuest():
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
59 if not self._dest.activequest:
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
60 self._dest.offerNextQuest()
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
61 else:
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
62 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
63 else:
524
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
64 self._dest.instance.say("I've got nothing for you... leave me alone.", 2500)
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
65 else:
524
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
66 self._dest.instance.say("Hello there!")
528
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
67
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
68 class PickUpItemAction(BaseAction):
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
69 def __init__(self, actor, item):
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
70 self._actiontype = Actions['PICKUP']
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
71 self._actor = actor
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
72 self._item = item
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
73
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
74 def execute(self):
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
75 self._actor.pickUpItem(self._item)
519
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
76
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
77 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
78 '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
79 '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
80
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
81 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
82 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
83 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
84
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
85 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
86 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
87 self._object.stand()
519
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
88 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
89
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
90 class Actor(BaseGameObject):
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
91 def __init__(self, gamecontroller, instancename, instanceid=None, createInstance=False):
524
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
92
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
93 if not hasattr(self, "_type"):
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
94 self._type = GameObjectTypes["NPC"]
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
95
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
96 super(Actor, self).__init__(gamecontroller, instancename, instanceid, createInstance)
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
97
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
98 self._walkspeed = self._gamecontroller.settings.get("RPG", "DefaultActorWalkSpeed", 4.0)
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
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 self._actionlistener = ActorActionListener(self._gamecontroller, self)
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
101
519
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
102 self._nextaction = None
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
103
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
104 self.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
105
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
106 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
107 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
108 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
109
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
110 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
111 self._state = ActorStates["WALK"]
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
112 self._instance.move('walk', location, self._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
113
519
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
114 def performNextAction(self):
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
115 if self._nextaction:
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
116 self._nextaction.execute()
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
117 self._nextaction = None
528
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
118
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
119 def pickUpItem(self, item):
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
120 self._inventory.append(item)
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
121
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
122 #removes it from FIFE (to stop rendering the item)
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
123 item.destroy()
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
124
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
125 #remove it from the scene
796d49ab9380 Cleaned up the createScene function.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 524
diff changeset
126 del self._gamecontroller.scene.objectlist[item.id]
519
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
127
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
128 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
129 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
130
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
131 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
132 self._state = state
519
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
133
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
134 def _getNextAction(self):
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
135 return self._nextaction
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
136
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
137 def _setNextAction(self, action):
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
138 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
139
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
140 state = property(_getState, _setState)
519
14f777be6b94 Added a rudimentary Action class.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 517
diff changeset
141 nextaction = property(_getNextAction, _setNextAction)
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
142
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
143 class Quest(object):
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
144 def __init__(self, owner, questname, questtext):
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
145 self._owner = owner
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
146 self._name = questname
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
147 self._text = questtext
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
148
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
149 def _getOwner(self):
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
150 return self._owner
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
151
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
152 def _getName(self):
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
153 return self._name
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
154
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
155 def _setName(self, questname):
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
156 self._name = questname
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
157
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
158 def _getText(self):
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
159 return self._text
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
160
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
161 def _setText(self, questtext):
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
162 self._text = questtext
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
163
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
164 owner = property(_getOwner)
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
165 name = property(_getName, _setName)
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
166 text = property(_getText, _setText)
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
167
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
168 class QuestGiver(Actor):
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
169 def __init__(self, gamecontroller, instancename, instanceid=None, createInstance=False):
524
6037f79b0dcf Multiple quests now work.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 523
diff changeset
170 self._type = GameObjectTypes["QUESTGIVER"]
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
171 super(QuestGiver, self).__init__(gamecontroller, instancename, instanceid, createInstance)
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
172
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
173 self._quests = []
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
174
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
175 self._activequest = None
520
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
176
b6bd314df28a Added a quest dialog.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 519
diff changeset
177 def addQuest(self, quest):
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
178 self._quests.append(quest)
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
179
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
180 def offerNextQuest(self):
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
181 if self._activequest:
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
182 return
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
183
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
184 if len(self._quests) > 0:
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
185 self._gamecontroller.guicontroller.showQuestDialog(self)
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
186
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
187 def getNextQuest(self):
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
188 if len(self._quests) > 0:
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
189 return self._quests[0]
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
190
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
191 return None
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
192
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
193 def activateQuest(self, quest):
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
194 self._activequest = quest
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
195
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
196 def completeQuest(self):
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
197 #@todo check to see if requirements are met
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
198 if self._activequest in self._quests:
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
199 print "quest completed"
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
200 self._quests.remove(self._activequest)
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
201 self._activequest = None
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
202 else:
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
203 #something went wrong
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
204 self._activequest = None
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
205
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
206 def haveQuest(self):
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
207 return len(self._quests) > 0
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
208
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
209 def _getActiveQuest(self):
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
210 return self._activequest
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
211
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
212 activequest = property(_getActiveQuest)