Go to the documentation of this file.00001 '''
00002 Stats implements the StatsManager for all sorts of functionality to do with player and non player character stats.
00003 We act solely on Actor data and this modules purpose is mainly to separate some functionality away from Actor
00004 so that that class' code doesnt grow too much
00005
00006 Anoria (c) Gsk 2010
00007 '''
00008
00009
00010 import BigWorld
00011 from Resources import ResourceDB as RDB
00012
00013 from config import consts
00014 from config import event
00015
00016
00017 class Stat():
00018 ''' The Stat object manages all aspects of a specific
00019 player or non player character stat '''
00020 def __init__(self, stat):
00021 self.stat = stat
00022
00023 def _sumMods(self):
00024 sum = 0
00025 mods = self.stat.modifiers
00026 for n in mods:
00027 sum += n
00028 return sum
00029
00030 def getCurrent(self):
00031 ''' retrieve the current value of this stat; includes all modifier values '''
00032 return self.stat.curValue + self._sumMods()
00033
00034 def applyEffect(self, effect):
00035 '''
00036 stores a value in the given modifier slot as defined by the passed in StatsEffect
00037 @param effect is a StatsEffect object describing the modifier to be applied to this stat
00038 '''
00039 print 'Stat.applyEffect() applying effect: slot=%d modifier=%d ' % (effect.slot, effect.value)
00040 self.stat.modifiers[effect.slot] = effect.value
00041
00042 class StatsManager():
00043
00044 def __init__(self, isServer=False):
00045 self.isServer = isServer
00046 self.stats = {}
00047
00048 def applyStatsEffect(self, effectId):
00049 effect = RDB.effects[effectId]
00050 print 'StatsManager.applyStatsEffect(): stat=%s slot=%s modifier=%d ' % (effect.stat, effect.slot, effect.value)
00051 stat = self.stats[effect.stat]
00052 stat.applyEffect(effect)
00053
00054
00055
00056 eventname = 'STAT_UPDATE_%s' % (effect.stat)
00057 eventcode = event.EVENTS.index(eventname)
00058 self.client.rpcProcessEvent(self.id, eventcode, stat.getCurrent())
00059
00060
00061 def initStatsData(self):
00062
00063
00064
00065
00066 stat = self.characterStats.CON
00067 self.stats['CON'] = Stat(stat)
00068 if self.isServer:
00069 stat.curValue = 20
00070 stat.maxValue = 20
00071
00072 stat = self.characterStats.STR
00073 self.stats['STR'] = Stat(stat)
00074 if self.isServer:
00075 stat.curValue = 20
00076 stat.maxValue = 20
00077
00078 stat = self.characterStats.DEX
00079 self.stats['DEX'] = Stat(stat)
00080 if self.isServer:
00081 stat.curValue = 20
00082 stat.maxValue = 20
00083
00084 stat = self.characterStats.INT
00085 self.stats['INT'] = Stat(stat)
00086 if self.isServer:
00087 stat.curValue = 20
00088 stat.maxValue = 20
00089
00090
00091 if self.isServer:
00092 self.characterStats.HP.curValue = self.characterStats.CON.curValue * consts.STATCONV_CON2HP
00093 self.characterStats.HP.maxValue = self.characterStats.CON.maxValue * consts.STATCONV_CON2HP
00094 self.characterStats.PWR.curValue = self.characterStats.STR.curValue * consts.STATCONV_CON2HP
00095 self.characterStats.PWR.maxValue = self.characterStats.STR.maxValue * consts.STATCONV_CON2HP
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 def getStat(self, statName):
00107 '''
00108 stats current value accessor
00109 @param statName is the name of the character stat to be retrieved
00110 @return current strength stat value including all modifiers '''
00111 stat = self.stats[statName]
00112 return stat.getCurrent()
00113
00114