comparison objects/action.py @ 51:d3a9caba067b

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 98f26f7636d8
children de09adb7a736
comparison
equal deleted inserted replaced
50:b4a525456c99 51:d3a9caba067b
287 self.npc = npc 287 self.npc = npc
288 288
289 def execute(self): 289 def execute(self):
290 """Talk with the NPC when close enough, otherwise move closer. 290 """Talk with the NPC when close enough, otherwise move closer.
291 @return: None""" 291 @return: None"""
292 player_char = self.model.game_state.getObjectById("PlayerCharacter").fifeagent 292 player_char = self.model.game_state.\
293 npc_coordinates = self.npc.getLocation().getLayerCoordinates() 293 getObjectById("PlayerCharacter").fifeagent
294 npc_coordinates = self.npc.fifeagent.behaviour.getLocation().\
295 getLayerCoordinates()
294 pc_coordinates = player_char.behaviour.agent.\ 296 pc_coordinates = player_char.behaviour.agent.\
295 getLocation().getLayerCoordinates() 297 getLocation().getLayerCoordinates()
296 298
297 distance_squared = (npc_coordinates.x - pc_coordinates.x) *\ 299 distance_squared = (npc_coordinates.x - pc_coordinates.x) *\
298 (npc_coordinates.x - pc_coordinates.x) +\ 300 (npc_coordinates.x - pc_coordinates.x) +\
299 (npc_coordinates.y - pc_coordinates.y) *\ 301 (npc_coordinates.y - pc_coordinates.y) *\
300 (npc_coordinates.y - pc_coordinates.y) 302 (npc_coordinates.y - pc_coordinates.y)
301 303
302 # If we are too far away, we approach the NPC again 304 # If we are too far away, we approach the NPC again
303 if distance_squared > 2: 305 if distance_squared > 2:
304 player_char.approach([self.npc.getLocation(). 306 player_char.behaviour.approach(
305 getLayerCoordinates().x, 307 [npc_coordinates.x, npc_coordinates.y],
306 self.npc.getLocation(). 308 TalkAction(self.controller,
307 getLayerCoordinates().y], 309 self.npc,
308 TalkAction(self.controller, 310 self.commands
309 self.npc, self.commands)) 311 )
312 )
310 else: 313 else:
311 player_char.behaviour.agent.act('stand', self.npc.getLocation()) 314 player_char.behaviour.agent.act(
315 'stand',
316 self.npc.fifeagent.behaviour.getLocation()
317 )
312 318
313 if self.npc.dialogue is not None: 319 if self.npc.dialogue.dialogue is not None:
314 dialogue_controller = DialogueController(self.controller.engine, 320 dialogue_controller = DialogueController(
315 self.view, 321 self.controller.engine,
316 self.model, 322 self.view,
317 self.controller.application) 323 self.model,
318 self.controller.application.manager.push_mode(dialogue_controller) 324 self.controller.application
325 )
326 self.controller.application.manager.push_mode(
327 dialogue_controller
328 )
319 dialogue_controller.startTalk(self.npc) 329 dialogue_controller.startTalk(self.npc)
320 else: 330 else:
321 self.npc.behaviour.agent.say("Leave me alone!", 1000) 331 self.npc.fifeagent.behaviour.agent.say("Leave me alone!", 1000)
322 332
323 self.model.game_state.getObjectById("PlayerCharacter").fifeagent.behaviour.idle() 333 self.model.game_state.getObjectById("PlayerCharacter").\
324 self.model.game_state.getObjectById("PlayerCharacter").fifeagent.nextAction = None 334 fifeagent.behaviour.idle()
335 self.model.game_state.getObjectById("PlayerCharacter").\
336 fifeagent.behaviour.nextAction = None
325 super(TalkAction, self).execute() 337 super(TalkAction, self).execute()
326 338
327 class UseAction(Action): 339 class UseAction(Action):
328 """Action for carryable items. It executes special commands that can be only 340 """Action for carryable items. It executes special commands that can be only
329 used on carryable utens""" 341 used on carryable utens"""