Mercurial > parpg-core
changeset 185:756ce052ac85
Changed CharacterStatistic classes to work with components.
author | KarstenBock@gmx.net |
---|---|
date | Sat, 05 Nov 2011 14:42:12 +0100 |
parents | 9d9c4ccc081e |
children | 8cc26e89398c |
files | src/parpg/charactercreationcontroller.py src/parpg/characterstatistics.py src/parpg/components/character_statistics.py |
diffstat | 3 files changed, 30 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parpg/charactercreationcontroller.py Wed Oct 26 13:01:49 2011 +0200 +++ b/src/parpg/charactercreationcontroller.py Sat Nov 05 14:42:12 2011 +0100 @@ -89,12 +89,12 @@ def reset_character(self): # FIXME M. George Hansen 2011-06-06: character stats scripts aren't # finished, unfortunately. -# primary_stats_file = \ -# vfs.VFS.open('character_scripts/primary_stats.xml') -# primary_stats = XmlSerializer.deserialize(primary_stats_file) -# secondary_stats_file = \ -# vfs.VFS.open('character_scripts/secondary_stats.xml') -# secondary_stats = XmlSerializer.deserialize(secondary_stats_file) + #primary_stats_file = \ + # vfs.VFS.open('character_scripts/primary_stats.xml') + #primary_stats = XmlSerializer.deserialize(primary_stats_file) + #secondary_stats_file = \ + # vfs.VFS.open('character_scripts/secondary_stats.xml') + #secondary_stats = XmlSerializer.deserialize(secondary_stats_file) primary_stats = [] secondary_stats = [] inventory = [] @@ -110,15 +110,18 @@ self.PICTURES[self.GENDERS[0]][0] ) for primary_stat in primary_stats: - short_name = primary_stat.short_name - self.char_data.characterstats.primary_stats[short_name] = ( + long_name = primary_stat.long_name + self.char_data.characterstats.primary_stats[long_name] = ( char_stats.PrimaryStatisticValue( - primary_stat, self, DEFAULT_STAT_VALUE) + primary_stat, self.char_data.characterstats, + DEFAULT_STAT_VALUE) ) for secondary_stat in secondary_stats: name = secondary_stat.name self.char_data.characterstats.secondary_stats[name] = ( - char_stats.SecondaryStatisticValue(secondary_stat, self) + char_stats.SecondaryStatisticValue(secondary_stat, + self.char_data. + characterstats) ) self.char_data.container.max_bulk = self.MAX_BULK self.char_data.container.children = inventory
--- a/src/parpg/characterstatistics.py Wed Oct 26 13:01:49 2011 +0200 +++ b/src/parpg/characterstatistics.py Sat Nov 05 14:42:12 2011 +0100 @@ -19,6 +19,8 @@ from .serializers import SerializableRegistry +from components import character_statistics + class AbstractCharacterStatistic(object): __metaclass__ = ABCMeta @@ -144,7 +146,8 @@ character = self.character() value = sum( - character.statistics[name].value * modifier for name, modifier in + character_statistics.get_statistic(character, name).value * + modifier for name, modifier in stat_modifiers.items() ) assert 0 <= value <= 100
--- a/src/parpg/components/character_statistics.py Wed Oct 26 13:01:49 2011 +0200 +++ b/src/parpg/components/character_statistics.py Sat Nov 05 14:42:12 2011 +0100 @@ -26,4 +26,16 @@ fields = self.fields.keys() fields.remove("primary_stats") fields.remove("secondary_stats") - return fields \ No newline at end of file + return fields + +def get_statistic(stats, name): + """Gets the statistic by its name""" + if name in stats.primary_stats: + return stats.primary_stats[name] + elif name in stats.secondary_stats: + return stats.secondary_stats[name] + else: + for stat in stats.primary_stats: + if stat.statistic_type.short_name == name: + return stat + return None \ No newline at end of file