comparison src/parpg/gamemodel.py @ 161:d1f9652d0651

Fixed contents of containers, that are contained in other containers, not correctly restoring.
author KarstenBock@gmx.net
date Fri, 07 Oct 2011 18:15:09 +0200
parents db6403c1a7a1
children 79c186b69603
comparison
equal deleted inserted replaced
160:ca699b402790 161:d1f9652d0651
422 422
423 obj = self.createMapObject(self.active_map.agent_layer, entity_data, inst_id, world) 423 obj = self.createMapObject(self.active_map.agent_layer, entity_data, inst_id, world)
424 424
425 if agent.has_key("Inventory"): 425 if agent.has_key("Inventory"):
426 inv = agent["Inventory"] 426 inv = agent["Inventory"]
427 slots = inv["Slots"] 427 self.create_inventory_items(inv, obj, world)
428 obj.container.children = list()
429 for x in xrange(slots):
430 obj.container.children.append(None)
431 items = inv["Items"] if inv.has_key("Items") else list()
432 for data in items:
433 item = None
434 slot = data["Slot"] if data.has_key("Slot") else -1
435 if data.has_key("type"):
436 item_type = data["type"]
437 item_data = {}
438 item_data = self.checkAttributes(item_data, item_type)
439 if item_data.has_key("containable"):
440 item = self.create_item(
441 self.createUniqueID(data["ID"]),
442 item_data, world, item_type)
443 else:
444 raise Exception("Item %s is not containable." % item_type)
445 else:
446 identifier = data["ID"]
447 if self.game_state.hasObject(identifier):
448 item = self.game_state.getObjectById(identifier)
449 else:
450 item_data = self.items[identifier]["Entity"]
451 item_type = item_data["containable"]["item_type"]
452 item = self.create_item(identifier, item_data,
453 world, item_type)
454
455 container.put_item(obj.container, item.containable, slot)
456 428
457 if agent.has_key("Equipment"): 429 if agent.has_key("Equipment"):
458 for slot, data in agent["Equipment"].iteritems(): 430 for slot, data in agent["Equipment"].iteritems():
459 item = None 431 item = None
460 if data.has_key("type"): 432 if data.has_key("type"):
478 world, item_type) 450 world, item_type)
479 equip.equip(obj.equip, item.equipable, slot) 451 equip.equip(obj.equip, item.equipable, slot)
480 if (obj.fifeagent and (obj.lockable and not obj.lockable.closed)): 452 if (obj.fifeagent and (obj.lockable and not obj.lockable.closed)):
481 obj.fifeagent.behaviour.animate("opened", repeating=True) 453 obj.fifeagent.behaviour.animate("opened", repeating=True)
482 return obj 454 return obj
455
456 def create_inventory_items(self, inv, obj, world):
457 slots = inv["Slots"]
458 obj.container.children = list()
459 for x in xrange(slots):
460 obj.container.children.append(None)
461 items = inv["Items"] if inv.has_key("Items") else list()
462 for data in items:
463 item = None
464 slot = data["Slot"] if data.has_key("Slot") else -1
465 if data.has_key("type"):
466 item_type = data["type"]
467 item_data = {}
468 item_data = self.checkAttributes(item_data, item_type)
469 if item_data.has_key("containable"):
470 item = self.create_item(
471 self.createUniqueID(data["ID"]),
472 item_data, world, item_type)
473 else:
474 raise Exception("Item %s is not containable." % item_type)
475 else:
476 identifier = data["ID"]
477 if self.game_state.hasObject(identifier):
478 item = self.game_state.getObjectById(identifier)
479 else:
480 agent_data = self.items[identifier]
481 item_data = agent_data["Entity"]
482 item_type = item_data["containable"]["item_type"]
483 item = self.create_item(identifier, item_data,
484 world, item_type)
485 if item.container and agent_data.has_key("Inventory"):
486 self.create_inventory_items(agent_data["Inventory"],
487 item, world)
488
489 container.put_item(obj.container, item.containable, slot)
483 490
484 def create_item(self, identifier, item_data, world, item_type): 491 def create_item(self, identifier, item_data, world, item_type):
485 if not item_data["description"].has_key("view_name"): 492 if not item_data["description"].has_key("view_name"):
486 item_data["description"]["view_name"] = ( 493 item_data["description"]["view_name"] = (
487 item_data["description"]["real_name"]) 494 item_data["description"]["real_name"])