Mercurial > parpg-core
comparison src/parpg/gamemodel.py @ 187:f612b4638744
Statistics are being saved and loaded.
author | KarstenBock@gmx.net |
---|---|
date | Sat, 05 Nov 2011 16:04:59 +0100 |
parents | 8cc26e89398c |
children | d0aa0f3eecc1 |
comparison
equal
deleted
inserted
replaced
186:8cc26e89398c | 187:f612b4638744 |
---|---|
31 from common.utils import parseBool | 31 from common.utils import parseBool |
32 from parpg.dialogueparsers import YamlDialogueParser, DialogueFormatError | 32 from parpg.dialogueparsers import YamlDialogueParser, DialogueFormatError |
33 from parpg.entities import createEntity | 33 from parpg.entities import createEntity |
34 from parpg import behaviours | 34 from parpg import behaviours |
35 from parpg import components | 35 from parpg import components |
36 from parpg.components import fifeagent, container, equip | 36 from parpg.components import fifeagent, container, equip, character_statistics |
37 import characterstatistics as char_stats | |
37 | 38 |
38 try: | 39 try: |
39 import xml.etree.cElementTree as ElementTree | 40 import xml.etree.cElementTree as ElementTree |
40 except ImportError: | 41 except ImportError: |
41 import xml.etree.ElementTree as ElementTree | 42 import xml.etree.ElementTree as ElementTree |
51 the fife view here. This also prevents us from just having a | 52 the fife view here. This also prevents us from just having a |
52 function heavy controller.""" | 53 function heavy controller.""" |
53 ALL_AGENTS_KEY = "All" | 54 ALL_AGENTS_KEY = "All" |
54 MAX_ID_NUMBER = 1000 | 55 MAX_ID_NUMBER = 1000 |
55 GENERIC_ITEM_GFX = "generic_item" | 56 GENERIC_ITEM_GFX = "generic_item" |
57 DEFAULT_STAT_VALUE = 50 | |
56 | 58 |
57 def __init__(self, engine, settings): | 59 def __init__(self, engine, settings): |
58 """Initialize the instance. | 60 """Initialize the instance. |
59 @param engine: A fife.Engine object | 61 @param engine: A fife.Engine object |
60 @type emgome: fife.Engine | 62 @type emgome: fife.Engine |
105 # vfs.VFS.open('character_scripts/secondary_stats.xml') | 107 # vfs.VFS.open('character_scripts/secondary_stats.xml') |
106 #self.secondary_stats = XmlSerializer.deserialize(secondary_stats_file) | 108 #self.secondary_stats = XmlSerializer.deserialize(secondary_stats_file) |
107 self.primary_stats = [] | 109 self.primary_stats = [] |
108 self.secondary_stats = [] | 110 self.secondary_stats = [] |
109 | 111 |
112 def create_stats(self, entity): | |
113 for primary_stat in self.primary_stats: | |
114 long_name = primary_stat.long_name | |
115 entity.characterstats.primary_stats[long_name] = ( | |
116 char_stats.PrimaryStatisticValue( | |
117 primary_stat, entity.characterstats, | |
118 self.DEFAULT_STAT_VALUE) | |
119 ) | |
120 for secondary_stat in self.secondary_stats: | |
121 name = secondary_stat.name | |
122 entity.characterstats.secondary_stats[name] = ( | |
123 char_stats.SecondaryStatisticValue(secondary_stat, | |
124 entity.characterstats | |
125 ) | |
126 ) | |
127 | |
110 def checkAttributes(self, attributes, template): | 128 def checkAttributes(self, attributes, template): |
111 """Checks for attributes that where not given in the map file | 129 """Checks for attributes that where not given in the map file |
112 and fills them with values from the object database | 130 and fills them with values from the object database |
113 @param attributes: attributes to check | 131 @param attributes: attributes to check |
114 @type attributes: Dictionary | 132 @type attributes: Dictionary |
432 entity_data["dialogue"] = {} | 450 entity_data["dialogue"] = {} |
433 entity_data["dialogue"]["dialogue"] = self.dialogues[inst_id] | 451 entity_data["dialogue"]["dialogue"] = self.dialogues[inst_id] |
434 if (entity_data.has_key("containable") and not | 452 if (entity_data.has_key("containable") and not |
435 entity_data["containable"].has_key("item_type") | 453 entity_data["containable"].has_key("item_type") |
436 ): | 454 ): |
437 entity_data["containable"]["item_type"] = template | 455 entity_data["containable"]["item_type"] = template |
438 | 456 |
439 | |
440 obj = self.createMapObject(self.active_map.agent_layer, | 457 obj = self.createMapObject(self.active_map.agent_layer, |
441 entity_data, inst_id, world) | 458 entity_data, inst_id, world) |
459 | |
460 if agent.has_key("Statistics"): | |
461 self.create_stats(obj) | |
462 for name, val in agent["Statistics"].iteritems(): | |
463 obj.characterstats.primary_stats[name].value = val | |
442 | 464 |
443 if agent.has_key("Inventory"): | 465 if agent.has_key("Inventory"): |
444 inv = agent["Inventory"] | 466 inv = agent["Inventory"] |
445 self.createInventoryItems(inv, obj, world) | 467 self.createInventoryItems(inv, obj, world) |
446 | 468 |
747 loc = inst.getLocation().getExactLayerCoordinates() | 769 loc = inst.getLocation().getExactLayerCoordinates() |
748 agent_data["Position"] = (loc.x, loc.y, loc.z) | 770 agent_data["Position"] = (loc.x, loc.y, loc.z) |
749 if all_agents.has_key(identifier): | 771 if all_agents.has_key(identifier): |
750 agent_data["Map"] = map_id | 772 agent_data["Map"] = map_id |
751 agent_data["Rotation"] = inst.getRotation() | 773 agent_data["Rotation"] = inst.getRotation() |
774 elif name == "characterstats": | |
775 agent_data["Statistics"] = ( | |
776 character_statistics.get_stat_values( | |
777 entity.characterstats | |
778 )["primary"] | |
779 ) | |
752 elif name == "container" and hasattr(comp_vals, | 780 elif name == "container" and hasattr(comp_vals, |
753 "children"): | 781 "children"): |
754 inventory_data = {} | 782 inventory_data = {} |
755 inventory_data["Slots"] = len(comp_vals.children) | 783 inventory_data["Slots"] = len(comp_vals.children) |
756 items = [] | 784 items = [] |
772 equip_data[field] = { | 800 equip_data[field] = { |
773 "ID": | 801 "ID": |
774 equipable.entity.general.identifier | 802 equipable.entity.general.identifier |
775 } | 803 } |
776 agent_data["Equipment"] = equip_data | 804 agent_data["Equipment"] = equip_data |
777 agent_data["Entity"] = entity_data | 805 agent_data["Entity"] = entity_data |
778 | |
779 | 806 |
780 def getAgentImportFiles(self): | 807 def getAgentImportFiles(self): |
781 """Searches the agents directory for import files """ | 808 """Searches the agents directory for import files """ |
782 filepaths = locateFiles("*.xml", self.objects_directory) | 809 filepaths = locateFiles("*.xml", self.objects_directory) |
783 for filepath in filepaths: | 810 for filepath in filepaths: |