comparison gamemodel.py @ 78:a57ec730e753

Fixed item_type not being set when creating items.
author KarstenBock@gmx.net
date Fri, 23 Sep 2011 13:30:41 +0200
parents 4cf150131139
children 43e7a8d94446
comparison
equal deleted inserted replaced
77:180cbd2b5da8 78:a57ec730e753
442 obj.container.children = list() 442 obj.container.children = list()
443 for x in xrange(slots): 443 for x in xrange(slots):
444 obj.container.children.append(None) 444 obj.container.children.append(None)
445 items = inv["Items"] if inv.has_key("Items") else list() 445 items = inv["Items"] if inv.has_key("Items") else list()
446 for data in items: 446 for data in items:
447 item_type = data["type"]
447 item_data = {} 448 item_data = {}
448 item_data = self.checkAttributes(item_data, data["type"]) 449 item_data = self.checkAttributes(item_data, item_type)
449 if item_data.has_key("containable"): 450 if item_data.has_key("containable"):
450 item = createEntity(item_data, world, None) 451 item = self.create_item(item_data, world, item_type, data)
451 self.game_state.addObject(self.createUniqueID(data["ID"]), None, item)
452 container.put_item(obj.container, item.containable) 452 container.put_item(obj.container, item.containable)
453 else: 453 else:
454 raise Exception("Item %s is not containable." % data["type"]) 454 raise Exception("Item %s is not containable." % item_type)
455 455
456 if agent.has_key("Equipment"): 456 if agent.has_key("Equipment"):
457 for slot, data in agent["Equipment"].iteritems(): 457 for slot, data in agent["Equipment"].iteritems():
458 item_type = data["type"]
458 item_data = {} 459 item_data = {}
459 item_data = self.checkAttributes(item_data, data["type"]) 460 item_data = self.checkAttributes(item_data, item_type)
460 if item_data.has_key("containable") and item_data.has_key("equipable"): 461 if item_data.has_key("containable") and item_data.has_key("equipable"):
461 item = createEntity(item_data, world, None) 462 item = self.create_item(item_data, world, item_type, data)
462 self.game_state.addObject(self.createUniqueID(data["ID"]), None, item)
463 equip.equip(obj.equip, item.equipable, slot) 463 equip.equip(obj.equip, item.equipable, slot)
464 else: 464 else:
465 raise Exception("Item %s is not containable or equipable." % data["type"]) 465 raise Exception("Item %s is not containable or equipable." % item_type)
466
467 def create_item(self, item_data, world, item_type, data):
468 item = createEntity(item_data, world, None)
469 item.containable.item_type = item_type
470 self.game_state.addObject(self.createUniqueID(data["ID"]), None, item)
471 return item
466 472
467 def placeAgents(self, world): 473 def placeAgents(self, world):
468 """Places the current maps agents """ 474 """Places the current maps agents """
469 if not self.active_map: 475 if not self.active_map:
470 return 476 return