Mercurial > parpg-core
changeset 78:c25c734bd2a7
Modifications to make talking with npcs possible again. Special actions won't work yet though.
author | KarstenBock@gmx.net |
---|---|
date | Thu, 08 Sep 2011 15:18:39 +0200 |
parents | 8a7bb62f9f5d |
children | 62cff91a19cb |
files | src/parpg/dialoguecontroller.py src/parpg/gamescenecontroller.py src/parpg/gui/dialoguegui.py src/parpg/objects/action.py src/parpg/world.py |
diffstat | 5 files changed, 90 insertions(+), 72 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parpg/dialoguecontroller.py Thu Sep 08 15:17:28 2011 +0200 +++ b/src/parpg/dialoguecontroller.py Thu Sep 08 15:18:39 2011 +0200 @@ -44,7 +44,10 @@ def startTalk(self, npc): if npc.dialogue is not None: self.model.active_map.centerCameraOnPlayer() - npc.talk(self.model.game_state.getObjectById("PlayerCharacter").fifeagent) + npc.fifeagent.behaviour.talk( + self.model.game_state.\ + getObjectById("PlayerCharacter").fifeagent + ) self.dialogue = self.view.hud.showDialogue(npc) self.dialogue.initiateDialogue() self.model.pause(True)
--- a/src/parpg/gamescenecontroller.py Thu Sep 08 15:17:28 2011 +0200 +++ b/src/parpg/gamescenecontroller.py Thu Sep 08 15:18:39 2011 +0200 @@ -408,14 +408,15 @@ """ Starts the PlayerCharacter talking to an NPC. """ # TODO: work more on this when we get NPCData and HeroData straightened # out - npc = self.model.game_state.getObjectById(npc_info.ID, - self.model.game_state.\ - current_map_name) - self.model.game_state.getObjectById("PlayerCharacter").fifeagent.approach([npc.getLocation().\ - getLayerCoordinates().x, - npc.getLocation().\ - getLayerCoordinates().y], - TalkAction(self, npc)) + npc = self.model.game_state.getObjectById( + npc_info.fifeagent.identifier, + self.model.game_state.current_map_name + ) + npc_pos = npc.fifeagent.behaviour.getLocation().getLayerCoordinates() + self.model.game_state.getObjectById("PlayerCharacter").fifeagent.\ + behaviour.approach([npc_pos.x, + npc_pos.y], + TalkAction(self, npc)) def getItemActions(self, obj_id): """Given the objects ID, return the text strings and callbacks. @@ -424,55 +425,53 @@ @rtype: list @return: List of text and callbacks""" actions = [] - # note: ALWAYS check NPC's first! obj = self.model.game_state.\ getObjectById(obj_id, self.model.game_state.current_map_name) + player = self.model.game_state.getObjectById("PlayerCharacter") + + #TODO: Check all actions to be compatible with the grease components if obj is not None: - if obj.trueAttr("NPC"): - # keep it simple for now, None to be replaced by callbacks + if obj.dialogue: actions.append(["Talk", "Talk", self.initTalk, obj]) + if obj.characterstats: actions.append(["Attack", "Attack", self.nullFunc, obj]) - else: + if obj.description: actions.append(["Examine", "Examine", - self.model.game_state.\ - player_character.approach, - [obj.X, obj.Y], + player.fifeagent.behaviour.approach, + [obj.fifeagent.pos.x, obj.fifeagent.pos.y], ExamineAction(self, - obj_id, obj.name, - obj.text)]) - # is it a Door? - if obj.trueAttr("door"): - actions.append(["Change Map", "Change Map", - self.model.game_state.getObjectById("PlayerCharacter").fifeagent.approach, - [obj.X, obj.Y], - ChangeMapAction(self, obj.target_map_name, - obj.target_pos)]) - # is it a container? - if obj.trueAttr("container"): - actions.append(["Open", "Open", - self.model.game_state.\ - player_character.approach, - [obj.X, obj.Y], - OpenBoxAction(self, obj)]) - actions.append(["Unlock", "Unlock", - self.model.game_state.\ - player_character.approach, - [obj.X, obj.Y], - UnlockBoxAction(self, obj)]) - actions.append(["Lock", "Lock", - self.model.game_state.\ - player_character.approach, - [obj.X, obj.Y], - LockBoxAction(self, obj)]) - # can you pick it up? - if obj.trueAttr("carryable"): - actions.append(["Pick Up", "Pick Up", - self.model.game_state.\ - player_character.approach, - [obj.X, obj.Y], - PickUpAction(self, obj)]) + obj_id, obj.description.view_name, + obj.description.desc)]) + #WORKAROUND: To get rid of exception in gamescenecontroller + if obj.change_map: + actions.append(["Change Map", "Change Map", + player.fifeagent.behaviour.approach, + [obj.fifeagent.pos.x, obj.fifeagent.pos.y], + ChangeMapAction(self, obj.target_map_name, + obj.target_pos)]) + + # is it a container? + if obj.lockable: + actions.append(["Open", "Open", + player.fifeagent.behaviour.approach, + [obj.fifeagent.pos.x, obj.fifeagent.pos.y], + OpenBoxAction(self, obj)]) + actions.append(["Unlock", "Unlock", + player.fifeagent.behaviour.approach, + [obj.fifeagent.pos.x, obj.fifeagent.pos.y], + UnlockBoxAction(self, obj)]) + actions.append(["Lock", "Lock", + player.fifeagent.behaviour.approach, + [obj.fifeagent.pos.x, obj.fifeagent.pos.y], + LockBoxAction(self, obj)]) + # can you pick it up? + if obj.containable: + actions.append(["Pick Up", "Pick Up", + player.fifeagent.behaviour.approach, + [obj.fifeagent.pos.x, obj.fifeagent.pos.y], + PickUpAction(self, obj)]) return actions
--- a/src/parpg/gui/dialoguegui.py Thu Sep 08 15:17:28 2011 +0200 +++ b/src/parpg/gui/dialoguegui.py Thu Sep 08 15:18:39 2011 +0200 @@ -49,13 +49,13 @@ } self.dialogue_gui.mapEvents(events) self.dialogue_gui.show() - self.setNpcName(self.npc.name) - self.setAvatarImage(self.npc.dialogue.avatar_path) + self.setNpcName(self.npc.description.view_name) + self.setAvatarImage(self.npc.dialogue.dialogue.avatar_path) game_state = {'npc': self.npc, 'pc': self.player_character, 'quest': self.quest_engine} try: - self.dialogue_processor = DialogueProcessor(self.npc.dialogue, + self.dialogue_processor = DialogueProcessor(self.npc.dialogue.dialogue, game_state) self.dialogue_processor.initiateDialogue() except (TypeError) as error: @@ -106,8 +106,8 @@ GUI or from within the conversation itself.""" self.dialogue_gui.hide() self.responses = [] - self.npc.behaviour.state = 1 - self.npc.behaviour.idle() + self.npc.fifeagent.behaviour.state = 1 + self.npc.fifeagent.behaviour.idle() self.active = False def setNpcName(self, name):
--- a/src/parpg/objects/action.py Thu Sep 08 15:17:28 2011 +0200 +++ b/src/parpg/objects/action.py Thu Sep 08 15:18:39 2011 +0200 @@ -289,8 +289,10 @@ def execute(self): """Talk with the NPC when close enough, otherwise move closer. @return: None""" - player_char = self.model.game_state.getObjectById("PlayerCharacter").fifeagent - npc_coordinates = self.npc.getLocation().getLayerCoordinates() + player_char = self.model.game_state.\ + getObjectById("PlayerCharacter").fifeagent + npc_coordinates = self.npc.fifeagent.behaviour.getLocation().\ + getLayerCoordinates() pc_coordinates = player_char.behaviour.agent.\ getLocation().getLayerCoordinates() @@ -301,27 +303,37 @@ # If we are too far away, we approach the NPC again if distance_squared > 2: - player_char.approach([self.npc.getLocation(). - getLayerCoordinates().x, - self.npc.getLocation(). - getLayerCoordinates().y], - TalkAction(self.controller, - self.npc, self.commands)) + player_char.behaviour.approach( + [npc_coordinates.x, npc_coordinates.y], + TalkAction(self.controller, + self.npc, + self.commands + ) + ) else: - player_char.behaviour.agent.act('stand', self.npc.getLocation()) + player_char.behaviour.agent.act( + 'stand', + self.npc.fifeagent.behaviour.getLocation() + ) - if self.npc.dialogue is not None: - dialogue_controller = DialogueController(self.controller.engine, - self.view, - self.model, - self.controller.application) - self.controller.application.manager.push_mode(dialogue_controller) + if self.npc.dialogue.dialogue is not None: + dialogue_controller = DialogueController( + self.controller.engine, + self.view, + self.model, + self.controller.application + ) + self.controller.application.manager.push_mode( + dialogue_controller + ) dialogue_controller.startTalk(self.npc) else: - self.npc.behaviour.agent.say("Leave me alone!", 1000) + self.npc.fifeagent.behaviour.agent.say("Leave me alone!", 1000) - self.model.game_state.getObjectById("PlayerCharacter").fifeagent.behaviour.idle() - self.model.game_state.getObjectById("PlayerCharacter").fifeagent.nextAction = None + self.model.game_state.getObjectById("PlayerCharacter").\ + fifeagent.behaviour.idle() + self.model.game_state.getObjectById("PlayerCharacter").\ + fifeagent.behaviour.nextAction = None super(TalkAction, self).execute() class UseAction(Action):
--- a/src/parpg/world.py Thu Sep 08 15:17:28 2011 +0200 +++ b/src/parpg/world.py Thu Sep 08 15:18:39 2011 +0200 @@ -1,4 +1,5 @@ from bGrease.world import * +from bGrease.component import Component from parpg.mode import FifeMode from parpg import components @@ -19,6 +20,9 @@ self.components.fifeagent = components.FifeAgent() self.components.lockable = components.Lockable() self.components.usable = components.Usable() + + #WORKAROUND: To get rid of exception in gamescenecontroller + self.components.change_map = Component() def pump(self, dt): for component in self.components: