# HG changeset patch
# User prock@33b003aa-7bff-0310-803a-e67f0ece8222
# Date 1277414831 0
# Node ID f85762e634c5bc2e8441263baf53db30a1f80159
# Parent e34b44afd4281e3ecc53c941f13214d055f20370
- Added the AttackAction along with a test enemy on level 1.
- Removed the getModuleByType() helper function.
diff -r e34b44afd428 -r f85762e634c5 demos/rpg/maps/allobjects.xml
--- a/demos/rpg/maps/allobjects.xml Thu Jun 24 19:58:59 2010 +0000
+++ b/demos/rpg/maps/allobjects.xml Thu Jun 24 21:27:11 2010 +0000
@@ -10,6 +10,7 @@
type : GOLD ; modelname : GoldStack ; value : 5000
type : PORTAL ; modelname : TempleEntrance ; dest : town
- type : QUESTGIVER ; modelname : Quiller ; stat1 : 20 ; stat2 : 343
+ type : QUESTGIVER ; modelname : Quiller
+ type : ENEMY ; modelname : Quiller
diff -r e34b44afd428 -r f85762e634c5 demos/rpg/maps/level1_objects.xml
--- a/demos/rpg/maps/level1_objects.xml Thu Jun 24 19:58:59 2010 +0000
+++ b/demos/rpg/maps/level1_objects.xml Thu Jun 24 21:27:11 2010 +0000
@@ -1,8 +1,9 @@
- gstack2 ; townportal
+ gstack2 ; townportal ; sign1
objectname : goldstack ; value : 5000 ; posx : -3.0 ; posy : -3.0
objectname : templeportal ; dest : town ; posx : 3.0 ; posy : 2.0
+ objectname : signenemy1 ; posx : 1.0 ; posy : 1.0
diff -r e34b44afd428 -r f85762e634c5 demos/rpg/scripts/actors/baseactor.py
--- a/demos/rpg/scripts/actors/baseactor.py Thu Jun 24 19:58:59 2010 +0000
+++ b/demos/rpg/scripts/actors/baseactor.py Thu Jun 24 21:27:11 2010 +0000
@@ -62,7 +62,17 @@
else:
self._dest.showNoQuestDialog()
else:
- self._dest.instance.say("Hello there!")
+ self._dest.say("Hello there!")
+
+class AttackAction(BaseAction):
+ def __init__(self, attacker, defender):
+ self._actiontype = Actions['ATTACK']
+ self._attacker = attacker
+ self._defender = defender
+
+ def execute(self):
+ if self._defender.type == GameObjectTypes["ENEMY"]:
+ self._defender.say("Ouch")
class PickUpItemAction(BaseAction):
def __init__(self, actor, item):
@@ -155,8 +165,6 @@
def __init__(self, gamecontroller, layer, typename, baseobjectname, instancename, instanceid=None, createInstance=False):
super(Actor, self).__init__(gamecontroller, layer, typename, baseobjectname, instancename, instanceid, createInstance)
- self._type = GameObjectTypes["DEFAULT"]
-
self._nextaction = None
self._inventory = []
self._maxinventoryitems = 20
diff -r e34b44afd428 -r f85762e634c5 demos/rpg/scripts/actors/player.py
--- a/demos/rpg/scripts/actors/player.py Thu Jun 24 19:58:59 2010 +0000
+++ b/demos/rpg/scripts/actors/player.py Thu Jun 24 21:27:11 2010 +0000
@@ -40,9 +40,8 @@
class Player(Actor):
def __init__(self, gamecontroller, layer, playermodelname):
- super(Player, self).__init__(gamecontroller, layer, "Player", "player", playermodelname, "player", True)
- self._type = GameObjectTypes["PLAYER"]
-
+ super(Player, self).__init__(gamecontroller, layer, "PLAYER", "player", playermodelname, "player", True)
+
self._actionlistener = PlayerActionListener(self._gamecontroller, self)
self._actionlistener.attachActionListener()
diff -r e34b44afd428 -r f85762e634c5 demos/rpg/scripts/gamecontroller.py
--- a/demos/rpg/scripts/gamecontroller.py Thu Jun 24 19:58:59 2010 +0000
+++ b/demos/rpg/scripts/gamecontroller.py Thu Jun 24 21:27:11 2010 +0000
@@ -32,7 +32,7 @@
from scripts.scene import Scene
from scripts.guicontroller import GUIController
-from scripts.actors.baseactor import TalkAction, PickUpItemAction, EnterPortalAction
+from scripts.actors.baseactor import TalkAction, AttackAction, PickUpItemAction, EnterPortalAction
from scripts.objects.baseobject import GameObjectTypes
from scripts.misc.exceptions import ObjectNotFoundError, ObjectAlreadyInSceneError
from scripts.quests.questmanager import QuestManager
@@ -133,6 +133,12 @@
if obj.type == GameObjectTypes["QUESTGIVER"]:
action = TalkAction(self._gamecontroller.scene.player, obj)
self._gamecontroller.scene.player.nextaction = action
+ elif obj.type == GameObjectTypes["ENEMY"]:
+ action = AttackAction(self._gamecontroller.scene.player, obj)
+ self._gamecontroller.scene.player.nextaction = action
+ else:
+ action = TalkAction(self._gamecontroller.scene.player, obj)
+ self._gamecontroller.scene.player.nextaction = action
if item_instances:
obj = self._gamecontroller.scene.objectlist[item_instances[0].getId()]
diff -r e34b44afd428 -r f85762e634c5 demos/rpg/scripts/objects/baseobject.py
--- a/demos/rpg/scripts/objects/baseobject.py Thu Jun 24 19:58:59 2010 +0000
+++ b/demos/rpg/scripts/objects/baseobject.py Thu Jun 24 21:27:11 2010 +0000
@@ -42,16 +42,6 @@
"PORTAL":7
}
-def getModuleByType(objtype):
- if objtype == GameObjectTypes["ITEM"] or objtype == GameObjectTypes["GOLD"] or objtype == GameObjectTypes["PORTAL"]:
- module = "items"
- elif objtype == GameObjectTypes["QUESTGIVER"] or objtype == GameObjectTypes["ENEMY"]:
- module = "npcs"
- else:
- module = "unknown"
-
- return module
-
class ObjectActionListener(fife.InstanceActionListener):
def __init__(self, gamecontroller, obj):
fife.InstanceActionListener.__init__(self)
@@ -84,6 +74,7 @@
self._fifeobject = None
self._typename = typename
+ self._type = GameObjectTypes[typename]
self._baseobjectname = baseobjectname
self._name = instancename
@@ -97,8 +88,6 @@
self._actionlistener = None
- self._type = GameObjectTypes["DEFAULT"]
-
self._layer = layer
if createInstance:
diff -r e34b44afd428 -r f85762e634c5 demos/rpg/scripts/objects/items.py
--- a/demos/rpg/scripts/objects/items.py Thu Jun 24 19:58:59 2010 +0000
+++ b/demos/rpg/scripts/objects/items.py Thu Jun 24 21:27:11 2010 +0000
@@ -27,7 +27,7 @@
from fife import fife
-from scripts.objects.baseobject import BaseGameObject, GameObjectTypes, getModuleByType
+from scripts.objects.baseobject import BaseGameObject, GameObjectTypes
class BaseItem(BaseGameObject):
diff -r e34b44afd428 -r f85762e634c5 demos/rpg/scripts/scene.py
--- a/demos/rpg/scripts/scene.py Thu Jun 24 19:58:59 2010 +0000
+++ b/demos/rpg/scripts/scene.py Thu Jun 24 21:27:11 2010 +0000
@@ -34,7 +34,7 @@
from scripts.actors.questgiver import QuestGiver
from scripts.quests.basequest import Quest, ReturnItemQuest, QuestTypes
from scripts.actors.player import Player
-from scripts.objects.baseobject import GameObjectTypes, getModuleByType
+from scripts.objects.baseobject import GameObjectTypes
from scripts.objects.items import BaseItem, GoldStack, Portal
from scripts.misc.exceptions import ObjectNotFoundError, ObjectAlreadyInSceneError
from scripts.misc.serializer import Serializer
@@ -75,7 +75,7 @@
newobject = Portal(self._gamecontroller, self.itemlayer, objdict["type"], objectname, modeldict["model"], identifier)
elif objdict["type"] == "QUESTGIVER":
newobject = QuestGiver(self._gamecontroller, self.actorlayer, objdict["type"], objectname, modeldict["model"], identifier, True)
- elif objdict["type"] == "NPC":
+ elif objdict["type"] == "ENEMY":
newobject = Actor(self._gamecontroller, self.actorlayer, objdict["type"], objectname, modeldict["model"], identifier, True)
else:
return None