From 9a635fc2a0a0dda52836b7e71f7184b3226517c7 Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期四, 18 九月 2025 16:40:52 +0800
Subject: [PATCH] 121 【武将】武将系统-服务端(武将属性计算不取整,精确3位小数;战斗时属性使用原值小数计算,仅血量、怒气取整;)
---
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GM/Commands/PrintFightPower.py | 8 ++++----
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Skill/TurnBuff.py | 2 +-
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerOnline.py | 8 ++++----
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/BattleObj.py | 20 ++++++++++++++++----
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/FormulaControl.py | 5 ++++-
5 files changed, 29 insertions(+), 14 deletions(-)
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/BattleObj.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/BattleObj.py
index c2e9bc6..433c306 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/BattleObj.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/BattleObj.py
@@ -726,9 +726,10 @@
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
@@ -752,6 +753,7 @@
def ResetBattleEffect(self):
self._batAttrDict = {}
self._batAttrDict.update(self._initAttrDict)
+ self.__onUpdBatAttr()
return self._batAttrDict
def GetTFGUID(self): return self.tfGUID # 所属的某场战斗
@@ -856,14 +858,16 @@
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)
@@ -871,6 +875,7 @@
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)
@@ -886,7 +891,14 @@
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: 正值-加属性;负值-减属性
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/FormulaControl.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/FormulaControl.py
index 514a9a4..0428a46 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/FormulaControl.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/FormulaControl.py
@@ -79,13 +79,14 @@
#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)
@@ -110,6 +111,8 @@
try:
# 执行计算
value = eval(compileFormula, safe_env)
+ if ndigits > 0:
+ value = round(value, ndigits)
if ceil:
value = math.ceil(value)
if toInt:
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GM/Commands/PrintFightPower.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GM/Commands/PrintFightPower.py
index 485683e..b9cc836 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GM/Commands/PrintFightPower.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GM/Commands/PrintFightPower.py
@@ -65,16 +65,16 @@
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
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerOnline.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerOnline.py
index f639650..2f18462 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerOnline.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerOnline.py
@@ -717,9 +717,9 @@
}
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)
@@ -735,7 +735,7 @@
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 = {}
@@ -759,7 +759,7 @@
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)
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Skill/TurnBuff.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Skill/TurnBuff.py
index 0db2ee1..b75f844 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Skill/TurnBuff.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Skill/TurnBuff.py
@@ -328,7 +328,7 @@
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))
--
Gitblit v1.8.0