121 【武将】武将系统-服务端(武将属性计算不取整,精确3位小数;战斗时属性使用原值小数计算,仅血量、怒气取整;)
| | |
| | | self._initAttrDict = initAttrDict
|
| | | self._batAttrDict = {}
|
| | | self._batAttrDict.update(initAttrDict)
|
| | | self.__onUpdBatAttr()
|
| | | self._skillTempAttrDict = {}
|
| | | self._xp = initXP
|
| | | self._hp = initAttrDict.get(ChConfig.AttrID_MaxHP, 1)
|
| | | self.SetXP(initXP, False)
|
| | | self.SetHPFull(False)
|
| | | TurnBuff.RefreshBuffAttr(self)
|
| | | TurnPassive.RefreshPassive(self)
|
| | | return
|
| | |
| | | def ResetBattleEffect(self):
|
| | | self._batAttrDict = {}
|
| | | self._batAttrDict.update(self._initAttrDict)
|
| | | self.__onUpdBatAttr()
|
| | | return self._batAttrDict
|
| | |
|
| | | def GetTFGUID(self): return self.tfGUID # 所属的某场战斗
|
| | |
| | | def SetDead(self):
|
| | | self._isAlive = False
|
| | | self._hp = 0
|
| | | def GetMaxHP(self): return self._batAttrDict.get(ChConfig.AttrID_MaxHP, 0)
|
| | | def GetMaxHP(self): return int(self._batAttrDict.get(ChConfig.AttrID_MaxHP, 0))
|
| | | def SetMaxHP(self, maxHP, isNotify=False):
|
| | | maxHP = int(maxHP)
|
| | | self._batAttrDict[ChConfig.AttrID_MaxHP] = maxHP
|
| | | if isNotify:
|
| | | NotifyObjInfoRefresh(self, ChConfig.AttrID_MaxHP, maxHP)
|
| | | return
|
| | | def GetHP(self): return self._hp
|
| | | def SetHP(self, hp, isNotify=False):
|
| | | hp = int(hp)
|
| | | self._hp = hp
|
| | | if isNotify:
|
| | | NotifyObjInfoRefresh(self, ChConfig.AttrID_HP, hp)
|
| | |
| | | def SetHPFull(self, isNotify=True): self.SetHP(self.GetMaxHP(), isNotify)
|
| | | def GetXP(self): return self._xp
|
| | | def SetXP(self, xp, isNotify=True):
|
| | | xp = int(xp)
|
| | | self._xp = xp
|
| | | if isNotify:
|
| | | NotifyObjInfoRefresh(self, ChConfig.AttrID_XP, xp)
|
| | |
| | | value += self._skillTempAttrDict[attrID] # 支持正负值
|
| | | #value = max(1, value)
|
| | | return value
|
| | | def SetBatAttrValue(self, attrID, value): self._batAttrDict[attrID] = value
|
| | | def SetBatAttrValue(self, attrID, value):
|
| | | self._batAttrDict[attrID] = value
|
| | | self.__onUpdBatAttr()
|
| | | return
|
| | | def __onUpdBatAttr(self):
|
| | | for attrID in [ChConfig.AttrID_MaxHP]:
|
| | | self._batAttrDict[attrID] = int(self._batAttrDict.get(attrID, 0))
|
| | | return
|
| | | def AddSkillTempAttr(self, attrID, value):
|
| | | ## 增加技能临时属性,支持正负值
|
| | | # @param value: 正值-加属性;负值-减属性
|
| | |
| | | #GameWorld.Log('ClearCompileFormulaDist Sucess AllFormulaDist = %s'%(AllFormulaDist))
|
| | | return
|
| | |
|
| | | def Eval(formulaKey, formula, paramDict, toInt=True, ceil=False, playerID=0):
|
| | | def Eval(formulaKey, formula, paramDict, toInt=True, ceil=False, ndigits=0, playerID=0):
|
| | | """ 动态计算
|
| | | :param formulaKey: 公式编译缓存key
|
| | | :param formula: 公式字符串,如 "int(Atk*10 + MaxHP)"
|
| | | :param paramDict: 参数字典,如 {'Atk': 100, 'MaxHP': 5000}
|
| | | :param toInt: 是否转为整数
|
| | | :param ceil: 是否向上取整
|
| | | :param ndigits: 小数精确位数
|
| | | :return: 计算结果
|
| | | """
|
| | | compileFormula = GetCompileFormula(formulaKey, formula)
|
| | |
| | | try:
|
| | | # 执行计算
|
| | | value = eval(compileFormula, safe_env)
|
| | | if ndigits > 0:
|
| | | value = round(value, ndigits)
|
| | | if ceil:
|
| | | value = math.ceil(value)
|
| | | if toInt:
|
| | |
| | | posNumList.sort()
|
| | | for posNum in posNumList:
|
| | | lineupHero = lineup.GetLineupHero(posNum)
|
| | | GameWorld.DebugAnswer(curPlayer, "---位置:%s,武将(%s) 战力: %s" % (posNum, lineupHero.heroID, lineupHero.fightPower))
|
| | | GameWorld.DebugAnswer(curPlayer, "技能:%s,战力:%s" % (lineupHero.heroSkillIDList, lineupHero.skillFightPower))
|
| | | GameWorld.DebugAnswer(curPlayer, "●位置:%s,武将(%s) 战力: %s" % (posNum, lineupHero.heroID, lineupHero.fightPower))
|
| | | GameWorld.DebugAnswer(curPlayer, "技能:%s,技能战力:%s" % (lineupHero.heroSkillIDList, lineupHero.skillFightPower))
|
| | | attrInfo = ""
|
| | | for attrID in ChConfig.AttrIDList:
|
| | | attrValue = lineupHero.heroBatAttrDict.get(attrID, 0)
|
| | | if not attrValue:
|
| | | continue
|
| | | if attrInfo:
|
| | | attrInfo += "; "
|
| | | attrInfo += "%s-%s" % (attrID, attrValue)
|
| | | attrInfo += ";"
|
| | | attrInfo += "[%s-%s]" % (attrID, attrValue)
|
| | | GameWorld.DebugAnswer(curPlayer, "属性:%s" % attrInfo)
|
| | |
|
| | | return
|
| | |
| | | }
|
| | |
|
| | | if attrID in ChConfig.BaseAttrIDList:
|
| | | attrValue = FormulaControl.Eval("baseAttrFormula", baseAttrFormula, attrParamDict)
|
| | | attrValue = FormulaControl.Eval("baseAttrFormula", baseAttrFormula, attrParamDict, toInt=False, ndigits=3)
|
| | | else:
|
| | | attrValue = FormulaControl.Eval("otherAttrFormula", otherAttrFormula, attrParamDict)
|
| | | attrValue = FormulaControl.Eval("otherAttrFormula", otherAttrFormula, attrParamDict, toInt=False, ndigits=3)
|
| | | #GameWorld.DebugLog(" attrID=%s,attrValue=%s,attrParamDict=%s" % (attrID, attrValue, attrParamDict))
|
| | |
|
| | | attrIpyData = IpyGameDataPY.GetIpyGameData("PlayerAttr", attrID)
|
| | |
| | | logAttrDict["%s-%s" % (attrID, attrName)] = attrValue
|
| | |
|
| | | # 计算战力
|
| | | fightPower = FormulaControl.Eval("fightPowerFormula", fightPowerFormula, fightPowerParamDict)
|
| | | fightPower = FormulaControl.Eval("fightPowerFormula", fightPowerFormula, fightPowerParamDict, toInt=True)
|
| | |
|
| | | GameWorld.DebugLog(" heroID=%s,fightPower=%s,heroSkillIDList=%s" % (heroID, fightPower, lineupHero.heroSkillIDList), playerID)
|
| | | skillTypeIDDict = {}
|
| | |
| | | skillID = skillData.GetSkillID()
|
| | | lineupHero.heroSkillIDList.append(skillID)
|
| | | paramDict = {"SkillPower":skillData.GetFightPower(), "PlayerLV":PlayerLV, "OfficialLV":OfficialLV}
|
| | | sFightPower = FormulaControl.Eval("skillFPFormula", skillFPFormula, paramDict)
|
| | | sFightPower = FormulaControl.Eval("skillFPFormula", skillFPFormula, paramDict, toInt=True)
|
| | | skillFightPower += sFightPower
|
| | | GameWorld.DebugLog(" skillFightPower=%s,heroSkillIDList=%s" % (skillFightPower, lineupHero.heroSkillIDList), playerID)
|
| | |
|
| | |
| | | attrValue = batObj.GetBatAttrValue(attrID, False)
|
| | | if attrValue <= 0:
|
| | | continue
|
| | | updValue = int(attrValue * (10000 + attrPerValue) / 10000.0)
|
| | | updValue = attrValue * (10000 + attrPerValue) / 10000.0
|
| | | #updValue = max(0, updValue) # 最多减到0,最大无上限
|
| | | batObj.SetBatAttrValue(attrID, updValue)
|
| | | GameWorld.DebugLog(" attrID=%s(PerID:%s),attrValue=%s(PerValue:%s),updValue=%s" % (attrID, attrPerID, attrValue, attrPerValue, updValue))
|