diff src/parpg/gamemodel.py @ 129:7583965ddcd6

If Items in containers or being equipped have no type the game will now try to get the object using the ID.
author KarstenBock@gmx.net
date Wed, 28 Sep 2011 12:58:18 +0200
parents 2a661e259b8b
children 9fcff924eb6f
line wrap: on
line diff
--- a/src/parpg/gamemodel.py	Tue Sep 27 16:29:39 2011 +0200
+++ b/src/parpg/gamemodel.py	Wed Sep 28 12:58:18 2011 +0200
@@ -399,6 +399,8 @@
             new_map.load(map_file)    
 
     def createAgent(self, agent, inst_id, world):
+        if self.game_state.hasObject(inst_id):
+            return None
         entity_data = deepcopy(agent["Entity"])
         entity_data["fifeagent"] = {}
         if agent.has_key("Template"):
@@ -458,25 +460,47 @@
                 obj.container.children.append(None)
             items = inv["Items"] if inv.has_key("Items") else list()
             for data in items:
-                item_type = data["type"]
-                item_data = {}
-                item_data = self.checkAttributes(item_data, item_type)
-                if item_data.has_key("containable"):
-                    item = self.create_item(item_data, world, item_type, data)
-                    container.put_item(obj.container, item.containable)
+                item = None
+                if data.has_key("type"):
+                    item_type = data["type"]
+                    item_data = {}
+                    item_data = self.checkAttributes(item_data, item_type)
+                    if item_data.has_key("containable"):
+                        item = self.create_item(item_data, world, item_type, data)
+                    else:
+                        raise Exception("Item %s is not containable." % item_type)
                 else:
-                    raise Exception("Item %s is not containable." % item_type)
+                    identifier = data["ID"]
+                    if self.game_state.hasObject(identifier):
+                        item = self.game_state.getObjectById(identifier)
+                    else:
+                        agents = self.getAgentsOfActiveMap()
+                        item_data = agents[identifier]
+                        item = self.createAgent(identifier, item_data, world)
+                        
+                container.put_item(obj.container, item.containable)
 
         if agent.has_key("Equipment"):
             for slot, data in agent["Equipment"].iteritems():
-                item_type = data["type"]
-                item_data = {}
-                item_data = self.checkAttributes(item_data, item_type)
-                if item_data.has_key("containable") and item_data.has_key("equipable"):
-                    item = self.create_item(item_data, world, item_type, data)
-                    equip.equip(obj.equip, item.equipable, slot)
+                item = None
+                if data.has_key("type"):
+                    item_type = data["type"]
+                    item_data = {}
+                    item_data = self.checkAttributes(item_data, item_type)
+                    if item_data.has_key("containable") and item_data.has_key("equipable"):
+                        item = self.create_item(item_data, world, item_type, data)
+                    else:
+                        raise Exception("Item %s is not containable or equipable." % item_type)
                 else:
-                    raise Exception("Item %s is not containable or equipable." % item_type)
+                    identifier = data["ID"]
+                    if self.game_state.hasObject(identifier):
+                        item = self.game_state.getObjectById(identifier)
+                    else:
+                        agents = self.getAgentsOfActiveMap()
+                        item_data = agents[identifier]
+                        item = self.createAgent(identifier, item_data, world)
+                equip.equip(obj.equip, item.equipable, slot)
+        return obj
 
     def create_item(self, item_data, world, item_type, data):
         identifier = self.createUniqueID(data["ID"])