diff gamescenecontroller.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 7b9f6e3513d4
line wrap: on
line diff
--- a/gamescenecontroller.py	Thu Sep 08 15:17:28 2011 +0200
+++ b/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