From 9ec66731c8a551035958aebe1fa974a140b99cf1 Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期三, 02 七月 2025 17:34:10 +0800
Subject: [PATCH] 129 【战斗】战斗系统-服务端(初版战斗,支持基础的三维属性战斗,支持简单的普攻技能、怒气技能、回血技能;主线章节关卡过关支持;阵容保存支持多阵容;)

---
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/BaseAttack.py |  142 +++++++++++++++++++++++++++++++---------------
 1 files changed, 95 insertions(+), 47 deletions(-)

diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/BaseAttack.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/BaseAttack.py
index 00ff334..dbd61de 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/BaseAttack.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Attack/BaseAttack.py
@@ -40,6 +40,7 @@
 import NetPackCommon
 import PassiveBuffEffMng
 import IpyGameDataPY
+import TurnAttack
 #---------------------------------------------------------------------
 g_skillHurtList = IPY_GameWorld.IPY_HurtList()
 
@@ -1365,6 +1366,9 @@
 #  @return None
 #  @remarks 函数详细说明.
 def __Sync_AttackResult(attacker, defender, curSkill):
+    battleType = AttackCommon.GetBattleType(attacker, curSkill)
+    turnBattleType = attacker.GetDictByKey(ChConfig.Def_Obj_Dict_TurnBattleType)
+    battleType = turnBattleType * 10 + battleType # 通知的battle修改: 回合攻击战斗类型*10+原战斗类型
     #普通攻击
     if not curSkill:
         #GameWorld.Log("玩家普通攻击成功")
@@ -1374,10 +1378,8 @@
                                                            g_skillHurtList.GetHurtCount()))
         else:
             curHurt = g_skillHurtList.GetHurtAt(0)
-            attacker.BaseAttack(curHurt.GetObjID(), curHurt.GetObjType(),
-                                AttackCommon.GetBattleType(attacker, curSkill),
-                                curHurt.GetAttackType(), curHurt.GetHurtHP(), curHurt.GetHurtHPEx(), curHurt.GetCurHP(), curHurt.GetCurHPEx())
-        
+            PYView_BaseAttack(attacker, curHurt, battleType)
+            
         #//返回值无意义
         return
     
@@ -1386,7 +1388,7 @@
     changeSkillID = PassiveBuffEffMng.GetPassiveSkillValueByTriggerTypeEx(attacker, None, curSkill, ChConfig.TriggerType_ChangeSkillEff)
     if changeSkillID:
         skillID = changeSkillID
-    battleType = AttackCommon.GetBattleType(attacker, curSkill)
+        
     #无目标类技能
     if not defender:
         #玩家处理
@@ -1435,7 +1437,7 @@
         # 为了客户端表现特殊处理,冲锋通知地板坐标而不是敌方坐标
         if curSkill.GetAtkType() == 9:
             useSkillPosX, useSkillPosY = attacker.GetUseSkillPosX(), attacker.GetUseSkillPosY()
-        PYView_UseSkillPos(attacker, skillID, battleType, useSkillPosX, useSkillPosY, g_skillHurtList, False)
+        PYView_UseSkillPos(attacker, skillID, battleType, useSkillPosX, useSkillPosY, g_skillHurtList, False, defender)
         PYView_UseSkillPos_NotifySelf(attacker, skillID, battleType, useSkillPosX, useSkillPosY, g_skillHurtList)
     else:
         if attacker.GetDictByKey(ChConfig.Def_NPC_Dict_AtkMovePosX):
@@ -1443,7 +1445,7 @@
             useSkillPosY = attacker.GetDictByKey(ChConfig.Def_NPC_Dict_AtkMovePosY)
 
         # NPC没有C++View_UseSkillPos接口
-        PYView_UseSkillPos(attacker, skillID, battleType, useSkillPosX, useSkillPosY, g_skillHurtList, False)
+        PYView_UseSkillPos(attacker, skillID, battleType, useSkillPosX, useSkillPosY, g_skillHurtList, False, defender)
     
     return
 
@@ -1695,28 +1697,32 @@
 
 # 属性击晕
 def AttackFaintRate(attacker, defender, curSkill, tick):
-    if attacker.GetGameObjType() != IPY_GameWorld.gotPlayer:
-        return
+    #if attacker.GetGameObjType() != IPY_GameWorld.gotPlayer:
+    #    return
     
-    faintRate = PlayerControl.GetFaintRate(attacker)
+    faintRate = GameObj.GetFaintRate(attacker)
     if not faintRate:
         #GameWorld.DebugLog("没有击晕概率!", attacker.GetID())
         return
     
-    if curSkill:
-        useSkillData = attacker.GetUseSkill()
-        # 非主动性技能不触发
-        if not useSkillData:
-            return
-        if useSkillData.GetSkillID() != curSkill.GetSkillID():
-            return
-        
-    if not defender:
-        useSkillTagID = attacker.GetUseSkillTagID()
-        useSkillTagType = attacker.GetUseSkillTagType()
-        defender = GameWorld.GetObj(useSkillTagID, useSkillTagType)
+    if attacker.GetGameObjType() == IPY_GameWorld.gotPlayer:
+        if curSkill:
+            useSkillData = attacker.GetUseSkill()
+            # 非主动性技能不触发
+            if not useSkillData:
+                return
+            if useSkillData.GetSkillID() != curSkill.GetSkillID():
+                return
+            
         if not defender:
-            return
+            useSkillTagID = attacker.GetUseSkillTagID()
+            useSkillTagType = attacker.GetUseSkillTagType()
+            defender = GameWorld.GetObj(useSkillTagID, useSkillTagType)
+            if not defender:
+                return
+            
+    if not defender:
+        return
     
     if attacker.GetID() == defender.GetID():
         return
@@ -1724,11 +1730,11 @@
     if GameObj.GetHP(defender) <= 0:
         return
 
-    tagFaintRate = PlayerControl.GetFaintDefRate(defender) if defender.GetGameObjType() == IPY_GameWorld.gotPlayer else 0
-
+    tagFaintDefRate = GameObj.GetFaintDefRate(defender)
+    
     # 添加最高60%击晕效果
     maxRate = IpyGameDataPY.GetFuncCfg("PassiveSkillFaint", 1)
-    rate = min(max(faintRate - tagFaintRate, 0), maxRate)
+    rate = min(max(faintRate - tagFaintDefRate, 0), maxRate)
     if not GameWorld.CanHappen(rate):
         return
     
@@ -1737,12 +1743,11 @@
         lastTick = attacker.GetDictByKey(ChConfig.Def_PlayerKey_AttrFaintCD)
         remainTick = faintCD - (tick - lastTick)
         if remainTick > 0:
-            GameWorld.DebugLog("击晕CD中! rate=%s,剩余tick=%s" % (rate, remainTick), attacker.GetID())
+            GameWorld.DebugLog("        击晕CD中! rate=%s,剩余tick=%s,atkID=%s" % (rate, remainTick, attacker.GetID()))
             return
         attacker.SetDict(ChConfig.Def_PlayerKey_AttrFaintCD, tick)
-        GameWorld.DebugLog("触发击晕! rate=%s" % rate, attacker.GetID())
-        
-    SkillCommon.AddBuffBySkillType(defender, ChConfig.Def_SkillID_AtkerFaint, tick)
+    GameWorld.DebugLog("        可触发击晕! rate=%s,atkID=%s,defID=%s" % (rate, attacker.GetID(), defender.GetID()))
+    SkillCommon.AddBuffBySkillType(defender, ChConfig.Def_SkillID_AtkerFaint, tick, buffOwner=attacker)
     return
 
 
@@ -1796,7 +1801,7 @@
 #  @param tick 当前时间
 #  @return None
 #  @remarks 设置玩家属性消耗,如魔法,XP点,HP
-def SetSkillLostAttr(curPlayer, curSkill, tick):
+def SetSkillLostAttr(curObj, curSkill, tick):
     #===========================================================================
     # #-----------扣魔法
     # lostMPValue = curSkill.GetMP()
@@ -1811,31 +1816,22 @@
     #    #自动回魔
     #    PlayerControl.PlayerAutoRestoreMP(curPlayer, tick)
     # 
-    # #----------扣XP点
-    # lostXPValue = curSkill.GetXP()
-    # curPlayerXP = curPlayer.GetXP()
-    # 
-    # if curPlayerXP < lostXPValue:
-    #    GameWorld.ErrLog('释放技能 = %s异常, XP点 = %s不足 = %s' % (
-    #                        curSkill.GetSkillTypeID(), curPlayerXP, lostXPValue))
-    # 
-    # if lostXPValue > 0:
-    #    remain = curPlayer.GetXP() - lostXPValue
-    #    remain = max(0, remain)
-    #    curPlayer.SetDict(ChConfig.Def_PlayerKey_RecordXPValue, remain)
-    #    curPlayer.SetXP(remain)
     #===========================================================================
+    
+    #----------扣XP点
+    if SkillCommon.isXPSkill(curSkill):
+        GameObj.SetXP(curObj, 0)
 
     #----------扣HP点
     lostHPValue = curSkill.GetHP()
-    curPlayerHP = GameObj.GetHP(curPlayer)
+    curPlayerHP = GameObj.GetHP(curObj)
     
     if curPlayerHP < lostHPValue:
         GameWorld.ErrLog('释放技能 = %s异常, HP点 = %s不足 = %s' % (
                             curSkill.GetSkillTypeID(), curPlayerHP, lostHPValue))
     
     if lostHPValue > 0:
-        GameObj.SetHP(curPlayer, GameObj.GetHP(curPlayer) - lostHPValue)
+        GameObj.SetHP(curObj, GameObj.GetHP(curObj) - lostHPValue)
         
     return
 
@@ -1885,6 +1881,9 @@
     #技能使用成功
     if curSkill:
         skillTypeID = curSkill.GetSkillTypeID()
+        
+        #扣属性,如魔法,XP点
+        SetSkillLostAttr(curNPC, curSkill, tick)
         
         #技能使用成功
         curNPCSkill = curNPC.GetSkillManager().FindSkillBySkillTypeID(skillTypeID)
@@ -2760,9 +2759,32 @@
     PlayerControl.PyNotifyAll(curPlayer, sendPack, notifySelf=True, notifyCnt=-1)
     return
 
+def PYView_BaseAttack(attacker, curHurt, battleType):
+    #attacker.BaseAttack(curHurt.GetObjID(), curHurt.GetObjType(),
+    #                    battleType,
+    #                    curHurt.GetAttackType(), curHurt.GetHurtHP(), curHurt.GetHurtHPEx(), curHurt.GetCurHP(), curHurt.GetCurHPEx())
+    #ChangeAction(laNPCAttack);
+    sendPack = ChNetSendPack.tagObjBaseAttack()
+    sendPack.Clear()
+    sendPack.AttackerID = attacker.GetID()
+    sendPack.AttackerObjType = attacker.GetGameObjType()
+    sendPack.ObjID = curHurt.GetObjID()
+    sendPack.ObjType = curHurt.GetObjType()
+    sendPack.BattleType = battleType
+    sendPack.AttackType = curHurt.GetAttackType()
+    sendPack.Value = curHurt.GetHurtHP()
+    sendPack.ValueEx = curHurt.GetHurtHPEx()
+    sendPack.RemainHP = curHurt.GetCurHP()
+    sendPack.RemainHPEx = curHurt.GetCurHPEx()
+    turnFight = TurnAttack.GetTurnFightMgr().getNPCTurnFight(attacker.GetID())
+    if turnFight:
+        turnFight.addBatPack(sendPack)
+        return
+    attacker.NotifyAll(sendPack.GetBuffer(), sendPack.GetLength())
+    return
 
 # py重现View_UseSkillPos效果,对地通知,只用于玩家
-def PYView_UseSkillPos(attacker, skillID, battleType, useSkillPosX, useSkillPosY, skillHurtList, notifySelf):
+def PYView_UseSkillPos(attacker, skillID, battleType, useSkillPosX, useSkillPosY, skillHurtList, notifySelf, defender=None):
     #===========================================================================
     # C++ 此处代码PY已处理,暂不加入
     # SetAttackTick(GetGameWorldManager()->GetTick());
@@ -2770,6 +2792,32 @@
     # m_LastBattleTick = GetGameWorldManager()->GetTick();
     #===========================================================================
     
+    turnFight = TurnAttack.GetTurnFightMgr().getNPCTurnFight(attacker.GetID())
+    if turnFight:
+        sendPack = ChNetSendPack.tagUseSkillAttack()
+        sendPack.ObjID = attacker.GetID()
+        sendPack.ObjType = attacker.GetGameObjType()
+        sendPack.BattleType = battleType
+        sendPack.SkillID = skillID
+        sendPack.AttackID = defender.GetID() if defender else 0 # 主攻击目标
+        sendPack.AttackObjType = defender.GetGameObjType() if defender else 0
+        
+        for i in range(skillHurtList.GetHurtCount()):
+            hurtObj = skillHurtList.GetHurtAt(i)
+            hurtList = ChNetSendPack.tagSkillHurtObj()
+            hurtList.ObjType = hurtObj.GetObjType()
+            hurtList.ObjID = hurtObj.GetObjID()
+            hurtList.AttackType = hurtObj.GetAttackType()
+            hurtList.HurtHP = hurtObj.GetHurtHP()
+            hurtList.HurtHPEx = hurtObj.GetHurtHPEx()
+            hurtList.CurHP = hurtObj.GetCurHP()
+            hurtList.CurHPEx = hurtObj.GetCurHPEx()
+            
+            sendPack.HurtList.append(hurtList)
+        sendPack.HurtCount = len(sendPack.HurtList)
+        turnFight.addBatPack(sendPack)
+        return
+    
     sendPack = ChNetSendPack.tagUseSkillPos()
     sendPack.Clear()
     sendPack.ObjID = attacker.GetID()

--
Gitblit v1.8.0