comparison src/parpg/gamescenecontroller.py @ 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 ad75fa042b99
children 84d03dc70904
comparison
equal deleted inserted replaced
77:8a7bb62f9f5d 78:c25c734bd2a7
406 406
407 def initTalk(self, npc_info): 407 def initTalk(self, npc_info):
408 """ Starts the PlayerCharacter talking to an NPC. """ 408 """ Starts the PlayerCharacter talking to an NPC. """
409 # TODO: work more on this when we get NPCData and HeroData straightened 409 # TODO: work more on this when we get NPCData and HeroData straightened
410 # out 410 # out
411 npc = self.model.game_state.getObjectById(npc_info.ID, 411 npc = self.model.game_state.getObjectById(
412 self.model.game_state.\ 412 npc_info.fifeagent.identifier,
413 current_map_name) 413 self.model.game_state.current_map_name
414 self.model.game_state.getObjectById("PlayerCharacter").fifeagent.approach([npc.getLocation().\ 414 )
415 getLayerCoordinates().x, 415 npc_pos = npc.fifeagent.behaviour.getLocation().getLayerCoordinates()
416 npc.getLocation().\ 416 self.model.game_state.getObjectById("PlayerCharacter").fifeagent.\
417 getLayerCoordinates().y], 417 behaviour.approach([npc_pos.x,
418 TalkAction(self, npc)) 418 npc_pos.y],
419 TalkAction(self, npc))
419 420
420 def getItemActions(self, obj_id): 421 def getItemActions(self, obj_id):
421 """Given the objects ID, return the text strings and callbacks. 422 """Given the objects ID, return the text strings and callbacks.
422 @type obj_id: string 423 @type obj_id: string
423 @param obj_id: ID of object 424 @param obj_id: ID of object
424 @rtype: list 425 @rtype: list
425 @return: List of text and callbacks""" 426 @return: List of text and callbacks"""
426 actions = [] 427 actions = []
427 # note: ALWAYS check NPC's first!
428 obj = self.model.game_state.\ 428 obj = self.model.game_state.\
429 getObjectById(obj_id, 429 getObjectById(obj_id,
430 self.model.game_state.current_map_name) 430 self.model.game_state.current_map_name)
431 431 player = self.model.game_state.getObjectById("PlayerCharacter")
432
433
434 #TODO: Check all actions to be compatible with the grease components
432 if obj is not None: 435 if obj is not None:
433 if obj.trueAttr("NPC"): 436 if obj.dialogue:
434 # keep it simple for now, None to be replaced by callbacks
435 actions.append(["Talk", "Talk", self.initTalk, obj]) 437 actions.append(["Talk", "Talk", self.initTalk, obj])
438 if obj.characterstats:
436 actions.append(["Attack", "Attack", self.nullFunc, obj]) 439 actions.append(["Attack", "Attack", self.nullFunc, obj])
437 else: 440 if obj.description:
438 actions.append(["Examine", "Examine", 441 actions.append(["Examine", "Examine",
439 self.model.game_state.\ 442 player.fifeagent.behaviour.approach,
440 player_character.approach, 443 [obj.fifeagent.pos.x, obj.fifeagent.pos.y],
441 [obj.X, obj.Y],
442 ExamineAction(self, 444 ExamineAction(self,
443 obj_id, obj.name, 445 obj_id, obj.description.view_name,
444 obj.text)]) 446 obj.description.desc)])
445 # is it a Door? 447 #WORKAROUND: To get rid of exception in gamescenecontroller
446 if obj.trueAttr("door"): 448 if obj.change_map:
447 actions.append(["Change Map", "Change Map", 449 actions.append(["Change Map", "Change Map",
448 self.model.game_state.getObjectById("PlayerCharacter").fifeagent.approach, 450 player.fifeagent.behaviour.approach,
449 [obj.X, obj.Y], 451 [obj.fifeagent.pos.x, obj.fifeagent.pos.y],
450 ChangeMapAction(self, obj.target_map_name, 452 ChangeMapAction(self, obj.target_map_name,
451 obj.target_pos)]) 453 obj.target_pos)])
452 # is it a container? 454
453 if obj.trueAttr("container"): 455 # is it a container?
454 actions.append(["Open", "Open", 456 if obj.lockable:
455 self.model.game_state.\ 457 actions.append(["Open", "Open",
456 player_character.approach, 458 player.fifeagent.behaviour.approach,
457 [obj.X, obj.Y], 459 [obj.fifeagent.pos.x, obj.fifeagent.pos.y],
458 OpenBoxAction(self, obj)]) 460 OpenBoxAction(self, obj)])
459 actions.append(["Unlock", "Unlock", 461 actions.append(["Unlock", "Unlock",
460 self.model.game_state.\ 462 player.fifeagent.behaviour.approach,
461 player_character.approach, 463 [obj.fifeagent.pos.x, obj.fifeagent.pos.y],
462 [obj.X, obj.Y], 464 UnlockBoxAction(self, obj)])
463 UnlockBoxAction(self, obj)]) 465 actions.append(["Lock", "Lock",
464 actions.append(["Lock", "Lock", 466 player.fifeagent.behaviour.approach,
465 self.model.game_state.\ 467 [obj.fifeagent.pos.x, obj.fifeagent.pos.y],
466 player_character.approach, 468 LockBoxAction(self, obj)])
467 [obj.X, obj.Y], 469 # can you pick it up?
468 LockBoxAction(self, obj)]) 470 if obj.containable:
469 # can you pick it up? 471 actions.append(["Pick Up", "Pick Up",
470 if obj.trueAttr("carryable"): 472 player.fifeagent.behaviour.approach,
471 actions.append(["Pick Up", "Pick Up", 473 [obj.fifeagent.pos.x, obj.fifeagent.pos.y],
472 self.model.game_state.\ 474 PickUpAction(self, obj)])
473 player_character.approach,
474 [obj.X, obj.Y],
475 PickUpAction(self, obj)])
476 475
477 return actions 476 return actions
478 477
479 def saveGame(self, *args, **kwargs): 478 def saveGame(self, *args, **kwargs):
480 """Saves the game state, delegates call to engine.Engine 479 """Saves the game state, delegates call to engine.Engine