comparison gamemodel.py @ 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
comparison
equal deleted inserted replaced
98:c0db5f521695 99:6e4daff93e7d
397 new_map = GameMap(self.engine, self) 397 new_map = GameMap(self.engine, self)
398 self.game_state.maps[map_name] = new_map 398 self.game_state.maps[map_name] = new_map
399 new_map.load(map_file) 399 new_map.load(map_file)
400 400
401 def createAgent(self, agent, inst_id, world): 401 def createAgent(self, agent, inst_id, world):
402 if self.game_state.hasObject(inst_id):
403 return None
402 entity_data = deepcopy(agent["Entity"]) 404 entity_data = deepcopy(agent["Entity"])
403 entity_data["fifeagent"] = {} 405 entity_data["fifeagent"] = {}
404 if agent.has_key("Template"): 406 if agent.has_key("Template"):
405 entity_data = self.checkAttributes(entity_data, agent["Template"]) 407 entity_data = self.checkAttributes(entity_data, agent["Template"])
406 object_id = entity_data["graphics"]["gfx"] \ 408 object_id = entity_data["graphics"]["gfx"] \
456 obj.container.children = list() 458 obj.container.children = list()
457 for x in xrange(slots): 459 for x in xrange(slots):
458 obj.container.children.append(None) 460 obj.container.children.append(None)
459 items = inv["Items"] if inv.has_key("Items") else list() 461 items = inv["Items"] if inv.has_key("Items") else list()
460 for data in items: 462 for data in items:
461 item_type = data["type"] 463 item = None
462 item_data = {} 464 if data.has_key("type"):
463 item_data = self.checkAttributes(item_data, item_type) 465 item_type = data["type"]
464 if item_data.has_key("containable"): 466 item_data = {}
465 item = self.create_item(item_data, world, item_type, data) 467 item_data = self.checkAttributes(item_data, item_type)
466 container.put_item(obj.container, item.containable) 468 if item_data.has_key("containable"):
469 item = self.create_item(item_data, world, item_type, data)
470 else:
471 raise Exception("Item %s is not containable." % item_type)
467 else: 472 else:
468 raise Exception("Item %s is not containable." % item_type) 473 identifier = data["ID"]
474 if self.game_state.hasObject(identifier):
475 item = self.game_state.getObjectById(identifier)
476 else:
477 agents = self.getAgentsOfActiveMap()
478 item_data = agents[identifier]
479 item = self.createAgent(identifier, item_data, world)
480
481 container.put_item(obj.container, item.containable)
469 482
470 if agent.has_key("Equipment"): 483 if agent.has_key("Equipment"):
471 for slot, data in agent["Equipment"].iteritems(): 484 for slot, data in agent["Equipment"].iteritems():
472 item_type = data["type"] 485 item = None
473 item_data = {} 486 if data.has_key("type"):
474 item_data = self.checkAttributes(item_data, item_type) 487 item_type = data["type"]
475 if item_data.has_key("containable") and item_data.has_key("equipable"): 488 item_data = {}
476 item = self.create_item(item_data, world, item_type, data) 489 item_data = self.checkAttributes(item_data, item_type)
477 equip.equip(obj.equip, item.equipable, slot) 490 if item_data.has_key("containable") and item_data.has_key("equipable"):
491 item = self.create_item(item_data, world, item_type, data)
492 else:
493 raise Exception("Item %s is not containable or equipable." % item_type)
478 else: 494 else:
479 raise Exception("Item %s is not containable or equipable." % item_type) 495 identifier = data["ID"]
496 if self.game_state.hasObject(identifier):
497 item = self.game_state.getObjectById(identifier)
498 else:
499 agents = self.getAgentsOfActiveMap()
500 item_data = agents[identifier]
501 item = self.createAgent(identifier, item_data, world)
502 equip.equip(obj.equip, item.equipable, slot)
503 return obj
480 504
481 def create_item(self, item_data, world, item_type, data): 505 def create_item(self, item_data, world, item_type, data):
482 identifier = self.createUniqueID(data["ID"]) 506 identifier = self.createUniqueID(data["ID"])
483 item = createEntity(item_data, identifier, world, None) 507 item = createEntity(item_data, identifier, world, None)
484 item.containable.item_type = item_type 508 item.containable.item_type = item_type