Mercurial > parpg-source
changeset 99:6e4daff93e7d
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 | c0db5f521695 |
children | 485d866a847f |
files | gamemodel.py |
diffstat | 1 files changed, 38 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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"])