# HG changeset patch # User KarstenBock@gmx.net # Date 1317207498 -7200 # Node ID 7583965ddcd6509aaf0a1d34b49ed51b6e8d5f96 # Parent 2a661e259b8b015fed5c5932d4f73a57b1967b47 If Items in containers or being equipped have no type the game will now try to get the object using the ID. diff -r 2a661e259b8b -r 7583965ddcd6 src/parpg/gamemodel.py --- 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"])