# HG changeset patch # User KarstenBock@gmx.net # Date 1317207498 -7200 # Node ID 6e4daff93e7d40c5250dcd8b56ae57e5af02a699 # Parent c0db5f521695dae2de31d023af3560955ccaf371 If Items in containers or being equipped have no type the game will now try to get the object using the ID. diff -r c0db5f521695 -r 6e4daff93e7d gamemodel.py --- a/gamemodel.py Tue Sep 27 16:29:39 2011 +0200 +++ b/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"])