Mercurial > parpg-source
diff gamemodel.py @ 155:f017f8cac2c2
Statistics are being saved and loaded.
author | KarstenBock@gmx.net |
---|---|
date | Sat, 05 Nov 2011 16:04:59 +0100 |
parents | 4dc7951c3bfc |
children | 0655f2f0f3cd |
line wrap: on
line diff
--- a/gamemodel.py Sat Nov 05 14:53:12 2011 +0100 +++ b/gamemodel.py Sat Nov 05 16:04:59 2011 +0100 @@ -33,7 +33,8 @@ from parpg.entities import createEntity from parpg import behaviours from parpg import components -from parpg.components import fifeagent, container, equip +from parpg.components import fifeagent, container, equip, character_statistics +import characterstatistics as char_stats try: import xml.etree.cElementTree as ElementTree @@ -53,6 +54,7 @@ ALL_AGENTS_KEY = "All" MAX_ID_NUMBER = 1000 GENERIC_ITEM_GFX = "generic_item" + DEFAULT_STAT_VALUE = 50 def __init__(self, engine, settings): """Initialize the instance. @@ -107,6 +109,22 @@ self.primary_stats = [] self.secondary_stats = [] + def create_stats(self, entity): + for primary_stat in self.primary_stats: + long_name = primary_stat.long_name + entity.characterstats.primary_stats[long_name] = ( + char_stats.PrimaryStatisticValue( + primary_stat, entity.characterstats, + self.DEFAULT_STAT_VALUE) + ) + for secondary_stat in self.secondary_stats: + name = secondary_stat.name + entity.characterstats.secondary_stats[name] = ( + char_stats.SecondaryStatisticValue(secondary_stat, + entity.characterstats + ) + ) + def checkAttributes(self, attributes, template): """Checks for attributes that where not given in the map file and fills them with values from the object database @@ -434,12 +452,16 @@ if (entity_data.has_key("containable") and not entity_data["containable"].has_key("item_type") ): - entity_data["containable"]["item_type"] = template - - + entity_data["containable"]["item_type"] = template + obj = self.createMapObject(self.active_map.agent_layer, entity_data, inst_id, world) + if agent.has_key("Statistics"): + self.create_stats(obj) + for name, val in agent["Statistics"].iteritems(): + obj.characterstats.primary_stats[name].value = val + if agent.has_key("Inventory"): inv = agent["Inventory"] self.createInventoryItems(inv, obj, world) @@ -749,6 +771,12 @@ if all_agents.has_key(identifier): agent_data["Map"] = map_id agent_data["Rotation"] = inst.getRotation() + elif name == "characterstats": + agent_data["Statistics"] = ( + character_statistics.get_stat_values( + entity.characterstats + )["primary"] + ) elif name == "container" and hasattr(comp_vals, "children"): inventory_data = {} @@ -774,8 +802,7 @@ equipable.entity.general.identifier } agent_data["Equipment"] = equip_data - agent_data["Entity"] = entity_data - + agent_data["Entity"] = entity_data def getAgentImportFiles(self): """Searches the agents directory for import files """