| | |
| | | import time
|
| | | import json
|
| | |
|
| | | TimelineSet = 10000 # 单回合最大时间轴
|
| | | PosNumMax = 7 # 最大站位编号
|
| | | ActionNumStart = -1 # 起始行动位置编号,一般是从1开始,如果有加主公、红颜等则扣除相应位置值,如从0或-1开始
|
| | |
|
| | |
| | | self.beautyObjIDDict = {} # 红颜战斗单位 {位置编号:batObjID, ...}
|
| | | self.actionNum = ActionNumStart # 行动位置,从1开始
|
| | | self.totalHurt = 0 # 阵容总输出
|
| | | |
| | | #特殊
|
| | | self.bossID = 0
|
| | | self.bossPosView = 0
|
| | | return
|
| | |
|
| | | def getPlayerID(self): return self.turnFight.playerID # 发起的玩家ID
|
| | |
| | | self.ownerID = lineupInfo.get("PlayerID", 0) # 阵容所属的玩家ID
|
| | | self.shapeType = lineupInfo.get("ShapeType", 0)
|
| | | self.fightPower = lineupInfo.get("FightPower", 0)
|
| | | self.bossID = lineupInfo.get("BossID", 0)
|
| | | self.bossPosView = lineupInfo.get("BossPosView", 0)
|
| | | SummonLineupObjs(self, self.faction, self.num, lineupInfo, self.getPlayerID())
|
| | | return
|
| | |
|
| | |
| | | self.fightPower = 0
|
| | | self.totalHurt = 0
|
| | | return
|
| | | |
| | | def getDeadObjCnt(self):
|
| | | ## 获取本阵容目前死亡队员数
|
| | | deadCnt = 0
|
| | | batObjMgr = BattleObj.GetBatObjMgr()
|
| | | for objID in self.posObjIDDict.values():
|
| | | batObj = batObjMgr.getBatObj(objID)
|
| | | if not batObj:
|
| | | continue
|
| | | if batObj.IsAlive():
|
| | | continue
|
| | | deadCnt += 1
|
| | | return deadCnt
|
| | |
|
| | | class BatFaction():
|
| | | ## 战斗阵营
|
| | |
| | | self.state = -1 # -1 代表未战斗
|
| | | self.turnNum = 1 # 当前第x回合,默认第1回合开始
|
| | | self.turnMax = 15 # 最大回合数
|
| | | self.turnNumStart = 0 # 已处理第x回合开始
|
| | | self.enterLogic = False # 是否已执行进场逻辑
|
| | | self.winFaction = 0 # 本场战斗结束标记,获胜阵营,为0时代表未结束,所有小队打完或失败才有结果,0-未结束,>0-获胜的阵营
|
| | | self.isWin = False
|
| | |
| | |
|
| | | self.factionDict = {} # 战斗阵营 {faction:BatFaction, ...},一般是只有两个阵营,faction为1或2,每个阵营支持多个阵容
|
| | | self.actionSortList = [] # 阵容行动顺序 [[faction, num], ...]
|
| | | self.actionIndex = 0 # 行动顺序索引 |
| | | self.timeline = 0 # 时间轴节点 turnNum*1000+actionIndex*100++actionNum
|
| | | self.actionIndex = 0 # 行动顺序索引
|
| | | self.startTime = 0 # 开始时间戳,支持毫秒小数
|
| | | self.costTime = 0 # 单场战斗总耗时,支持毫秒小数
|
| | | self._oneActionUseSkillCntDict = {} # 某对象行动开始后所有对象累计使用技能次数,用于单对象单次行动中限制每个对象的最高触发技能次数 {objID:useCnt, ...}
|
| | |
| | | def nextTurnFight(self, msgDict={}):
|
| | | ## 一般用于玩家发起的战斗,在需要保留玩家阵容属性及状态的情况下,重置回合进入下一场战斗
|
| | | self.turnNum = 1
|
| | | self.turnNumStart = 0
|
| | | self.enterLogic = False
|
| | | self.winFaction = 0
|
| | | self.isWin = False
|
| | | self.msgDict.update(msgDict)
|
| | | self.timeline = 0
|
| | | self.startTime = time.time()
|
| | | self.costTime = 0
|
| | | ResetByNextTeam(self)
|
| | |
| | | GameWorld.DebugLog("阵容战力排序[isPlayer, fp, sortV, f, n]: %s" % sortList)
|
| | | GameWorld.DebugLog("阵容行动顺序[f, n]: %s" % self.actionSortList)
|
| | | return
|
| | | |
| | | def getTurnNumStartTimelin(self, turnNum): return turnNum * TimelineSet + 0 # 每回合的时间节点起点
|
| | | def getTimeline(self): return self.timeline
|
| | | def setTimeline(self, timeline, isEmpty=False):
|
| | | '''回合战斗的时间轴节点 ,即第几回合开始,每个回合支持9999个行动节点
|
| | | @param turnNum: 第x回合
|
| | | '''
|
| | | self.timeline = timeline
|
| | | GameWorld.DebugLog("[时间节点更新]: %s" % self.timeline)
|
| | | if isEmpty:
|
| | | # 空位置的节点可直接跳过
|
| | | return timeline
|
| | | |
| | | OnTimelineChange(self)
|
| | | return timeline
|
| | |
|
| | | def getBatFaction(self, faction=ChConfig.Def_FactionA):
|
| | | ## 默认阵营1
|
| | |
| | | ## 准备就绪,开始战斗
|
| | | self.state = FightState_Start
|
| | | self.turnNum = 1
|
| | | self.timeline = self.getTurnNumStartTimelin(self.turnNum)
|
| | | self.turnNumStart = 0
|
| | | self.syncInit()
|
| | | return
|
| | |
|
| | |
| | | tfObj.MaxHP = batObj.GetMaxHP() % ChConfig.Def_PerPointValue
|
| | | tfObj.MaxHPEx = batObj.GetMaxHP() / ChConfig.Def_PerPointValue
|
| | | tfObj.LV = batObj.GetLV()
|
| | | tfObj.PosNum = posNum
|
| | | if batLineup.bossPosView and batLineup.bossID == batObj.GetNPCID():
|
| | | tfObj.PosNum = batLineup.bossPosView
|
| | | else:
|
| | | tfObj.PosNum = posNum |
| | | tfObj.AngreXP = batObj.GetXP()
|
| | | tfLineup.ObjList.append(tfObj)
|
| | | tfLineup.ObjCnt = len(tfLineup.ObjList)
|
| | |
| | | ## 回合战斗管理器
|
| | |
|
| | | def __init__(self):
|
| | | self.lastRequestTick = 0
|
| | | self.turnFightDict = {} # {guid:TurnFight, ...}
|
| | | return
|
| | |
|
| | |
| | | ## 获取玩家阵容
|
| | | olPlayer = PlayerOnline.GetOnlinePlayer(curPlayer)
|
| | | lineup = olPlayer.GetLineup(lineupID)
|
| | | if not lineup.lineupHeroDict:
|
| | | if lineup.IsEmpty():
|
| | | GameWorld.DebugLog("玩家没有目标阵容默认取主阵容! lineupID=%s" % lineupID)
|
| | | lineup = olPlayer.GetLineup(ShareDefine.Lineup_Main)
|
| | | return lineup
|
| | |
| | |
|
| | | playerID = curPlayer.GetPlayerID()
|
| | | lineup = GetPlayerLineup(curPlayer, lineupID)
|
| | | if not lineup.lineupHeroDict:
|
| | | if lineup.IsEmpty():
|
| | | return {}
|
| | |
|
| | | heroDict = {}
|
| | | curPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptHero)
|
| | | for posNum in lineup.lineupHeroDict.keys():
|
| | | for posNum in lineup.GetPosNumList():
|
| | | hero = lineup.GetLineupHero(posNum)
|
| | | heroID = hero.heroID
|
| | | itemIndex = hero.itemIndex
|
| | |
| | | ipyData = IpyGameDataPY.GetIpyGameData("NPCLineup", lineupID)
|
| | | if not ipyData:
|
| | | return {}
|
| | | bossID = ipyData.GetBossID()
|
| | | bossPosView = ipyData.GetBossPosView()
|
| | |
|
| | | heroDict = {}
|
| | | for posNum in range(1, 1 + 10):
|
| | | for posNum in range(1, 1 + 6):
|
| | | if not hasattr(ipyData, "GetPosNPCID%s" % posNum):
|
| | | break
|
| | | npcID = getattr(ipyData, "GetPosNPCID%s" % posNum)()
|
| | |
| | | continue
|
| | | heroDict[str(posNum)] = battleDict
|
| | |
|
| | | lineupInfo = {"NPCLineupID":lineupID, "Hero":heroDict}
|
| | | lineupInfo = {"NPCLineupID":lineupID, "Hero":heroDict, "BossID":bossID, "BossPosView":bossPosView}
|
| | | return lineupInfo
|
| | |
|
| | | def GetNPCBattleDict(lineupIpyData, npcID, strongerLV=0, difficulty=0):
|
| | |
| | | if not batObj.IsAlive():
|
| | | GameWorld.DebugLog(" 已被击杀不处理! %s" % (objName))
|
| | | continue
|
| | | GameWorld.DebugLog(" 重置武将: %s, HP:%s/%s, XP:%s" % (objName, batObj.GetHP(), batObj.GetMaxHP(), batObj.GetXP()))
|
| | | |
| | | batObj.TurnReset()
|
| | | GameWorld.DebugLog("重置武将: %s, HP:%s/%s, XP:%s" % (objName, batObj.GetHP(), batObj.GetMaxHP(), batObj.GetXP()))
|
| | |
|
| | | # 清除buff
|
| | | buffMgr = batObj.GetBuffManager()
|
| | | buffMgr.ClearBuff()
|
| | |
|
| | | # 重置CD
|
| | | # 重置技能
|
| | | batObj.ResetSkillUseCnt()
|
| | | ResetObjSkillCD(batObj)
|
| | |
|
| | | # 重刷属性、被动
|
| | | TurnBuff.RefreshBuffAttr(batObj)
|
| | | TurnPassive.RefreshPassive(batObj)
|
| | |
|
| | | return
|
| | |
|
| | | def CheckFightCD(curPlayer, tick, selfKey):
|
| | | ## 是否战斗请求CD中
|
| | | |
| | | # 所有玩家公共CD,待扩展
|
| | | tfMgr = GetTurnFightMgr()
|
| | | pubCD = IpyGameDataPY.GetFuncCfg("TurnFightCD", 1)
|
| | | if pubCD:
|
| | | if tfMgr.lastRequestTick and tick - tfMgr.lastRequestTick <= pubCD:
|
| | | GameWorld.DebugLog("回合制战斗请求服务器公共CD中!")
|
| | | PlayerControl.NotifyCode(curPlayer, "BattleCoolDown")
|
| | | return True
|
| | | |
| | | # 个人CD
|
| | | selfCD = IpyGameDataPY.GetFuncCfg("TurnFightCD", 2)
|
| | | lastTick = curPlayer.GetDictByKey(selfKey)
|
| | | if selfCD and lastTick and tick - lastTick <= selfCD:
|
| | | GameWorld.DebugLog("回合制战斗请求CD中: %s" % selfKey)
|
| | | PlayerControl.NotifyCode(curPlayer, "BattleCoolDown")
|
| | | return True
|
| | | |
| | | tfMgr.lastRequestTick = tick
|
| | | curPlayer.SetDict(selfKey, tick)
|
| | | return False
|
| | |
|
| | | #// B4 10 回合制战斗 #tagCMTurnFight
|
| | | #
|
| | |
| | | if atkLineupID not in ShareDefine.LineupList or defLineupID not in ShareDefine.LineupList:
|
| | | return
|
| | |
|
| | | if CheckFightCD(curPlayer, tick, "TurnFightReqTick"):
|
| | | return
|
| | | |
| | | # 玩家
|
| | | if tagType == 1:
|
| | | OnTurnFightVSPlayer(curPlayer, mapID, funcLineID, atkLineupID, defLineupID, tagID)
|
| | | if not OnTurnFightVSPlayer(curPlayer, mapID, funcLineID, atkLineupID, defLineupID, tagID):
|
| | | return
|
| | |
|
| | | # NPC
|
| | | else:
|
| | |
| | | if not ret:
|
| | | return
|
| | | npcLineupIDList, strongerLV, difficulty = ret
|
| | | OnTurnFightVSNPC(curPlayer, mapID, funcLineID, atkLineupID, npcLineupIDList, strongerLV, difficulty)
|
| | | if not OnTurnFightVSNPC(curPlayer, mapID, funcLineID, atkLineupID, npcLineupIDList, strongerLV, difficulty):
|
| | | return
|
| | |
|
| | | return
|
| | | return True
|
| | |
|
| | | def OnTurnFightVSNPC(curPlayer, mapID, funcLineID, atkLineupID, npcLineupIDList, strongerLV, difficulty):
|
| | | playerID = curPlayer.GetPlayerID()
|
| | |
| | | PlayerOnline.GetOnlinePlayer(curPlayer).SetLastBatBuffer(guid, turnFight.batBuffer)
|
| | | SyncTurnFightReport(curPlayer, guid, turnFight.batBuffer)
|
| | | tfMgr.delTurnFight(guid)
|
| | | return
|
| | | return True
|
| | |
|
| | | def OnTurnFightVSPlayer(curPlayer, mapID, funcLineID, atkLineupID, defLineupID, tagPlayerID):
|
| | | playerID = curPlayer.GetPlayerID()
|
| | |
| | | PlayerOnline.GetOnlinePlayer(curPlayer).SetLastBatBuffer(guid, turnFight.batBuffer)
|
| | | SyncTurnFightReport(curPlayer, guid, turnFight.batBuffer)
|
| | | tfMgr.delTurnFight(guid)
|
| | | return
|
| | | return True
|
| | |
|
| | | def GetTurnMax(mapID):
|
| | | if mapID == ChConfig.Def_FBMapID_Main:
|
| | |
| | |
|
| | | # 限制请求CD
|
| | | if tick:
|
| | | key = "MainFightReqTick"
|
| | | lastTick = curPlayer.GetDictByKey(key)
|
| | | if lastTick and tick - lastTick <= 1000:
|
| | | GameWorld.DebugLog("主线战斗请求CD中")
|
| | | if CheckFightCD(curPlayer, tick, "MainFightReqTick"):
|
| | | return
|
| | | curPlayer.SetDict(key, tick)
|
| | |
|
| | | mainFightMgr = GetMainFightMgr(curPlayer)
|
| | | turnFight = mainFightMgr.turnFight
|
| | |
| | | batObjMgr = BattleObj.GetBatObjMgr()
|
| | | turnNum = turnFight.turnNum
|
| | | turnMax = turnFight.turnMax
|
| | | turnNumStart = turnFight.turnNumStart
|
| | | for turnNum in range(turnNum, turnMax + 1):
|
| | | if turnFight.winFaction:
|
| | | break
|
| | | turnTimeline = turnFight.getTurnNumStartTimelin(turnNum) # 本回合起始时间节点
|
| | | curTimeline = turnFight.getTimeline()
|
| | |
|
| | | # 回合开始
|
| | | turnTimeline += 1 # 每回合开始算一个时间节点
|
| | | if curTimeline < turnTimeline:
|
| | | curTimeline = turnFight.setTimeline(turnTimeline)
|
| | | GameWorld.DebugLog("【----- 回合制战斗轮次: %s -----】 curTimeline=%s" % (turnNum, curTimeline))
|
| | | if turnNumStart < turnNum:
|
| | | GameWorld.DebugLog("【----- 回合制战斗轮次: %s -----】 " % (turnNum))
|
| | | turnFight.turnNum = turnNum
|
| | | turnFight.turnNumStart = turnNum
|
| | | if curPlayer:
|
| | | turnFight.syncState(FightState_Fighting)
|
| | | |
| | | for faction, num in turnFight.actionSortList:
|
| | | GameWorld.DebugLog("大回合开始逻辑: turnNum=%s,faction=%s, num=%s" % (turnNum, faction, num))
|
| | | batFaction = turnFight.getBatFaction(faction)
|
| | | batLineup = batFaction.getBatlineup(num)
|
| | | batLineup.actionNum = 1
|
| | | for objID in batLineup.posObjIDDict.values():
|
| | | batObj = batObjMgr.getBatObj(objID)
|
| | | TurnFightPerTurnBigStart(turnFight, batObj, turnNum)
|
| | | |
| | | TurnFightPerTurnBigStart(turnFight, turnNum)
|
| | | |
| | | # 红颜
|
| | | # 灵兽
|
| | |
|
| | |
| | | batFaction = turnFight.getBatFaction(faction)
|
| | | batLineup = batFaction.getBatlineup(num)
|
| | | for posNum in range(batLineup.actionNum, PosNumMax + 1):
|
| | | # 每个武将位算一个时间节点
|
| | | #GameWorld.DebugLog("武将节点: faction=%s,posNum=%s,curTimeline=%s" % (faction, posNum, curTimeline))
|
| | | #GameWorld.DebugLog("武将位置: faction=%s,posNum=%s" % (faction, posNum))
|
| | | if posNum not in batLineup.posObjIDDict:
|
| | | batLineup.actionNum = posNum + 1
|
| | | curTimeline = turnFight.setTimeline(curTimeline + 1, True)
|
| | | #GameWorld.DebugLog("空位节点: faction=%s,posNum=%s,curTimeline=%s" % (faction, posNum, curTimeline))
|
| | | #GameWorld.DebugLog("没有武将: faction=%s,posNum=%s" % (faction, posNum))
|
| | | continue
|
| | |
|
| | | objID = batLineup.posObjIDDict[posNum]
|
| | |
| | | # 玩家自己阵营,预判可否行动
|
| | | if checkBreakpoint and faction == ChConfig.Def_FactionA and batObj:
|
| | | if batObj.CanAction():
|
| | | GameWorld.DebugLog("玩家阵容下一个可行动的武将,断点: curTimeline=%s,nextPosNum=%s" % (curTimeline, posNum))
|
| | | GameWorld.DebugLog("玩家阵容下一个可行动的武将,断点: nextPosNum=%s" % (posNum))
|
| | | return
|
| | |
|
| | | batLineup.actionNum = posNum + 1
|
| | | curTimeline = turnFight.setTimeline(curTimeline + 1)
|
| | | |
| | | TurnFightHeroTurnStart(turnFight, batObj, turnNum)
|
| | | if not OnObjAction(turnFight, batObj):
|
| | | isAction = OnObjAction(turnFight, batObj)
|
| | | TurnFightHeroTurnEnd(turnFight, batObj, turnNum)
|
| | | |
| | | if not isAction:
|
| | | continue
|
| | |
|
| | | if not checkBreakpoint and faction == ChConfig.Def_FactionA:
|
| | |
| | | break
|
| | |
|
| | | # 回合结束
|
| | | curTimeline = turnFight.setTimeline(curTimeline + 1) # 每回合结束算一个时间节点
|
| | | for faction, num in turnFight.actionSortList:
|
| | | GameWorld.DebugLog("回合结束逻辑: turnNum=%s,faction=%s, num=%s" % (turnNum, faction, num))
|
| | | batFaction = turnFight.getBatFaction(faction)
|
| | | batLineup = batFaction.getBatlineup(num)
|
| | | for objID in batLineup.posObjIDDict.values():
|
| | | batObj = batObjMgr.getBatObj(objID)
|
| | | TurnFightPerTurnBigEnd(turnFight, batObj, turnNum)
|
| | | |
| | | TurnFightPerTurnBigEnd(turnFight, turnNum)
|
| | | |
| | | if not turnFight.winFaction:
|
| | | OnTurnAllOver(turnFight.guid)
|
| | |
|
| | |
| | | break
|
| | | turnFight.turnNum = turnNum
|
| | | GameWorld.DebugLog("【----- 回合制战斗轮次: %s -----】" % turnNum)
|
| | | curTimeline = turnFight.getTurnNumStartTimelin(turnNum) # 本回合起始时间节点
|
| | | curTimeline = turnFight.setTimeline(curTimeline + 1)
|
| | | if curPlayer:
|
| | | turnFight.syncState(FightState_Fighting)
|
| | |
|
| | | # 回合开始
|
| | | for faction, num in turnFight.actionSortList:
|
| | | GameWorld.DebugLog("大回合开始逻辑: turnNum=%s,faction=%s, num=%s" % (turnNum, faction, num))
|
| | | batFaction = turnFight.getBatFaction(faction)
|
| | | batLineup = batFaction.getBatlineup(num)
|
| | | batLineup.actionNum = 1
|
| | | for objID in batLineup.posObjIDDict.values():
|
| | | batObj = batObjMgr.getBatObj(objID)
|
| | | TurnFightPerTurnBigStart(turnFight, batObj, turnNum)
|
| | | |
| | | |
| | | TurnFightPerTurnBigStart(turnFight, turnNum)
|
| | | |
| | | # 红颜
|
| | | # 灵兽
|
| | |
|
| | |
| | | for posNum in range(batLineup.actionNum, PosNumMax + 1):
|
| | | batLineup.actionNum = posNum + 1
|
| | | if posNum not in batLineup.posObjIDDict:
|
| | | curTimeline = turnFight.setTimeline(curTimeline + 1, True)
|
| | | continue
|
| | | curTimeline = turnFight.setTimeline(curTimeline + 1) # 每个武将位算一个时间节点
|
| | | objID = batLineup.posObjIDDict[posNum]
|
| | | batObj = batObjMgr.getBatObj(objID)
|
| | | TurnFightHeroTurnStart(turnFight, batObj, turnNum)
|
| | | if not OnObjAction(turnFight, batObj):
|
| | | isAction = OnObjAction(turnFight, batObj)
|
| | | TurnFightHeroTurnEnd(turnFight, batObj, turnNum)
|
| | | if not isAction:
|
| | | continue
|
| | | |
| | | break
|
| | |
|
| | | if turnFight.actionIndex >= len(turnFight.actionSortList) - 1:
|
| | |
| | | break
|
| | |
|
| | | # 回合结束
|
| | | curTimeline = turnFight.setTimeline(curTimeline + 1) # 每回合结束算一个时间节点
|
| | | for faction, num in turnFight.actionSortList:
|
| | | GameWorld.DebugLog("回合结束逻辑: turnNum=%s,faction=%s, num=%s" % (turnNum, faction, num))
|
| | | batFaction = turnFight.getBatFaction(faction)
|
| | | batLineup = batFaction.getBatlineup(num)
|
| | | for objID in batLineup.posObjIDDict.values():
|
| | | batObj = batObjMgr.getBatObj(objID)
|
| | | TurnFightPerTurnBigEnd(turnFight, batObj, turnNum)
|
| | | |
| | | TurnFightPerTurnBigEnd(turnFight, turnNum)
|
| | | |
| | | if not turnFight.winFaction:
|
| | | OnTurnAllOver(turnFight.guid)
|
| | | return
|
| | |
| | | turnFight.enterLogic = True
|
| | | return True
|
| | |
|
| | | def OnTimelineChange(turnFight):
|
| | | ## 每个时间节点变化时处理
|
| | | |
| | | nowTimeline = turnFight.getTimeline()
|
| | | def TurnFightPerTurnBigStart(turnFight, turnNum):
|
| | | ## 大回合开始时
|
| | |
|
| | | batObjMgr = BattleObj.GetBatObjMgr()
|
| | | for batFaction in turnFight.factionDict.values():
|
| | | for batLineup in batFaction.lineupDict.values():
|
| | | for objID in batLineup.posObjIDDict.values():
|
| | | batObj = batObjMgr.getBatObj(objID)
|
| | | #GameWorld.DebugLog("OnTimelineChange! objID=%s" % (objID))
|
| | | if not batObj or not batObj.IsAlive():
|
| | | continue
|
| | | |
| | | curID = batObj.GetID()
|
| | | skillManager = batObj.GetSkillManager()
|
| | | for index in range(0, skillManager.GetSkillCount()):
|
| | | curSkill = skillManager.GetSkillByIndex(index)
|
| | | if not curSkill:
|
| | | continue
|
| | | remainTime = curSkill.GetRemainTime()
|
| | | if not remainTime:
|
| | | continue
|
| | | calcTimeline = curSkill.GetCalcTime()
|
| | | passTurn = __calcPassturn(calcTimeline, nowTimeline, True)
|
| | | if passTurn <= 0:
|
| | | continue
|
| | | skillID = curSkill.GetSkillID()
|
| | | updRemainTime = max(0, remainTime - passTurn)
|
| | | curSkill.SetRemainTime(updRemainTime)
|
| | | curSkill.SetCalcTime(nowTimeline)
|
| | | GameWorld.DebugLog("更新技能剩余回合数: curID=%s,skillID=%s,updRemainTime=%s,calcTimeline=%s,passTurn=%s" |
| | | % (curID, skillID, updRemainTime, calcTimeline, passTurn))
|
| | | |
| | | buffMgr = batObj.GetBuffManager()
|
| | | for index in range(buffMgr.GetBuffCount())[::-1]:
|
| | | buff = buffMgr.GetBuffByIndex(index)
|
| | | buffID = buff.GetBuffID()
|
| | | skillID = buff.GetSkillID()
|
| | | skillData = buff.GetSkillData()
|
| | | if skillData.GetSkillType() in ChConfig.Def_LstBuff_List:
|
| | | #GameWorld.DebugLog(" 持续类buff由触发时机决定剩余时间! curID=%s,index=%s,skillID=%s,buffID=%s" % (curID, index, skillID, buffID))
|
| | | continue
|
| | | remainTime = buff.GetRemainTime()
|
| | | if not remainTime:
|
| | | # 永久buff不处理
|
| | | #GameWorld.DebugLog(" 永久buff不处理! curID=%s,index=%s,skillID=%s" % (curID, index, skillID))
|
| | | continue
|
| | | calcTimeline = buff.GetCalcTime()
|
| | | passTurn = __calcPassturn(calcTimeline, nowTimeline, True)
|
| | | if passTurn <= 0:
|
| | | #GameWorld.DebugLog(" passTurn <= 0 passTurn=%s,calcTimeline=%s,nowTimeline=%s,skillID=%s" % (passTurn, calcTimeline, nowTimeline, skillID))
|
| | | continue
|
| | | |
| | | updRemainTime = max(0, remainTime - passTurn)
|
| | | GameWorld.DebugLog("更新buff剩余回合数: curID=%s,buffID=%s,skillID=%s,updRemainTime=%s,calcTimeline=%s,passTurn=%s" |
| | | % (curID, buffID, skillID, updRemainTime, calcTimeline, passTurn))
|
| | | if updRemainTime > 0:
|
| | | buff.SetRemainTime(updRemainTime)
|
| | | buff.SetCalcTime(nowTimeline)
|
| | | TurnBuff.SyncBuffRefresh(turnFight, batObj, buff)
|
| | | else:
|
| | | TurnBuff.DoBuffDel(turnFight, batObj, buff)
|
| | | |
| | | for faction, num in turnFight.actionSortList:
|
| | | GameWorld.DebugLog("大回合开始逻辑: turnNum=%s,faction=%s, num=%s" % (turnNum, faction, num))
|
| | | batFaction = turnFight.getBatFaction(faction)
|
| | | batLineup = batFaction.getBatlineup(num)
|
| | | batLineup.actionNum = 1
|
| | | for objID in batLineup.posObjIDDict.values():
|
| | | batObj = batObjMgr.getBatObj(objID)
|
| | | if not batObj:
|
| | | continue
|
| | | if not batObj.IsAlive():
|
| | | continue
|
| | | |
| | | turnFight.ResetOneActionUseSkillCnt()
|
| | | batObj.SetTiming(ChConfig.TurnTiming_Before) # 重置时机到回合前
|
| | | RefreshObjSkillByTurn(batObj) # 优先刷技能CD
|
| | | |
| | | TurnPassive.OnTriggerPassiveEffect(turnFight, batObj, ChConfig.TriggerWay_BigTurnStart)
|
| | | |
| | | return
|
| | |
|
| | | def __calcPassturn(calcTimeline, nowTimeline, equalOK):
|
| | | ## 计算已经过了的回合数
|
| | | # @param equalOK: 时间节点相同时是否算1回合,一般技能可以算,buff可算可不算,具体看需求调整
|
| | | calcTurnNum = calcTimeline / TimelineSet
|
| | | calcTimeNode = calcTimeline % TimelineSet
|
| | | nowTurnNum = nowTimeline / TimelineSet
|
| | | nowTimeNode = nowTimeline % TimelineSet
|
| | | if equalOK:
|
| | | if nowTimeNode >= calcTimeNode:
|
| | | return max(0, nowTurnNum - calcTurnNum)
|
| | | return max(0, nowTurnNum - calcTurnNum - 1)
|
| | | else:
|
| | | if nowTimeNode > calcTimeNode:
|
| | | return max(0, nowTurnNum - calcTurnNum)
|
| | | return max(0, nowTurnNum - calcTurnNum - 1)
|
| | | return 0
|
| | |
|
| | | def TurnFightPerTurnBigStart(turnFight, batObj, turnNum):
|
| | | ## 大回合开始时
|
| | | if not batObj:
|
| | | return
|
| | | |
| | | if batObj.GetHP() <= 0:
|
| | | return
|
| | | |
| | | turnFight.ResetOneActionUseSkillCnt()
|
| | | TurnPassive.OnTriggerPassiveEffect(turnFight, batObj, ChConfig.TriggerWay_BigTurnStart)
|
| | | return
|
| | |
|
| | | def TurnFightPerTurnBigEnd(turnFight, batObj, turnNum):
|
| | | def TurnFightPerTurnBigEnd(turnFight, turnNum):
|
| | | ## 大回合结束时
|
| | | if not batObj:
|
| | | return
|
| | |
|
| | | if batObj.GetHP() <= 0:
|
| | | return
|
| | | |
| | | TurnPassive.OnTriggerPassiveEffect(turnFight, batObj, ChConfig.TriggerWay_BigTurnEnd)
|
| | | batObjMgr = BattleObj.GetBatObjMgr()
|
| | | for faction, num in turnFight.actionSortList:
|
| | | GameWorld.DebugLog("回合结束逻辑: turnNum=%s,faction=%s, num=%s" % (turnNum, faction, num))
|
| | | batFaction = turnFight.getBatFaction(faction)
|
| | | batLineup = batFaction.getBatlineup(num)
|
| | | for objID in batLineup.posObjIDDict.values():
|
| | | batObj = batObjMgr.getBatObj(objID)
|
| | | if not batObj:
|
| | | continue
|
| | | if not batObj.IsAlive():
|
| | | continue
|
| | | |
| | | turnFight.ResetOneActionUseSkillCnt()
|
| | | TurnPassive.OnTriggerPassiveEffect(turnFight, batObj, ChConfig.TriggerWay_BigTurnEnd)
|
| | | |
| | | return
|
| | |
|
| | | def TurnFightHeroTurnStart(turnFight, batObj, turnNum):
|
| | |
| | | if not batObj:
|
| | | return
|
| | |
|
| | | if batObj.GetHP() <= 0:
|
| | | if not batObj.IsAlive():
|
| | | return
|
| | |
|
| | | GameWorld.DebugLog("---[武将回合开始时] : curID=%s,curHP=%s/%s" % (batObj.GetID(), batObj.GetHP(), batObj.GetMaxHP()))
|
| | | GameWorld.DebugLog("---[武将回合开始] : curID=%s,curHP=%s/%s" % (batObj.GetID(), batObj.GetHP(), batObj.GetMaxHP()))
|
| | | turnFight.ResetOneActionUseSkillCnt()
|
| | | RefreshObjBuffTime(turnFight, batObj)
|
| | | TurnPassive.OnTriggerPassiveEffect(turnFight, batObj, ChConfig.TriggerWay_HeroTurnStart)
|
| | | |
| | | # 最后设置时机为回合后,说明:回合开启前的逻辑处理完后,其他的均默认为回合后
|
| | | batObj.SetTiming(ChConfig.TurnTiming_After)
|
| | | return
|
| | |
|
| | | def TurnFightHeroTurnEnd(turnFight, batObj, turnNum):
|
| | | ## 武将回合结束时,不能行动也要触发
|
| | | if not batObj:
|
| | | return
|
| | | |
| | | if not batObj.IsAlive():
|
| | | return
|
| | | |
| | | GameWorld.DebugLog("---[武将回合结束] : curID=%s,curHP=%s/%s" % (batObj.GetID(), batObj.GetHP(), batObj.GetMaxHP()))
|
| | | turnFight.ResetOneActionUseSkillCnt()
|
| | | RefreshObjBuffTime(turnFight, batObj)
|
| | | return
|
| | |
|
| | | def ResetObjSkillCD(batObj):
|
| | | ## 重置所有技能CD
|
| | | skillManager = batObj.GetSkillManager()
|
| | | for index in range(0, skillManager.GetSkillCount()):
|
| | | curSkill = skillManager.GetSkillByIndex(index)
|
| | | if not curSkill:
|
| | | continue
|
| | | remainTime = curSkill.GetRemainTime()
|
| | | if remainTime <= 0:
|
| | | continue
|
| | | curSkill.SetRemainTime(0)
|
| | | return
|
| | |
|
| | | def RefreshObjSkillByTurn(batObj):
|
| | | '''按回合刷新技能:默认以大回合统一减1回合,使用技能后设置剩余CD统一默认加1回合,即配置1回合,设置的CD是2
|
| | | '''
|
| | | curID = batObj.GetID()
|
| | | skillManager = batObj.GetSkillManager()
|
| | | for index in range(0, skillManager.GetSkillCount()):
|
| | | curSkill = skillManager.GetSkillByIndex(index)
|
| | | if not curSkill:
|
| | | continue
|
| | | skillID = curSkill.GetSkillID()
|
| | | preTurnUseCnt = batObj.GetSkillTurnUseCnt(skillID)
|
| | | batObj.ResetSkillTurnUseCnt() # 重置回合使用次数
|
| | | remainTime = curSkill.GetRemainTime()
|
| | | if remainTime <= 0:
|
| | | continue
|
| | | if preTurnUseCnt > 0:
|
| | | GameWorld.DebugLog(" 上回合有使用技能本回合不刷新CD: curID=%s,skillID=%s,remainTime=%s,preTurnUseCnt=%s" % (curID, skillID, remainTime, preTurnUseCnt))
|
| | | continue
|
| | | remainTime -= 1
|
| | | curSkill.SetRemainTime(remainTime)
|
| | | GameWorld.DebugLog(" 更新技能CD: curID=%s,skillID=%s,remainTime=%s" % (curID, skillID, remainTime))
|
| | | |
| | | return
|
| | |
|
| | | def RefreshObjBuffTime(turnFight, batObj):
|
| | | '''刷新buff持续时间:以武将自身回合前、回合后处理buff持续时间
|
| | | 回合前添加的buff在回合开始减1,回合后添加的buff在回合结束减1
|
| | | '''
|
| | | curID = batObj.GetID()
|
| | | curTiming = batObj.GetTiming() # 时间节点 0-回合前;1-回合后
|
| | | buffMgr = batObj.GetBuffManager()
|
| | | for index in range(buffMgr.GetBuffCount())[::-1]:
|
| | | buff = buffMgr.GetBuffByIndex(index)
|
| | | buffID = buff.GetBuffID()
|
| | | skillID = buff.GetSkillID()
|
| | | skillData = buff.GetSkillData()
|
| | | if skillData.GetSkillType() in ChConfig.Def_LstBuff_List:
|
| | | #GameWorld.DebugLog(" 持续类buff由触发时机决定剩余时间! curID=%s,index=%s,skillID=%s,buffID=%s" % (curID, index, skillID, buffID))
|
| | | continue
|
| | | remainTime = buff.GetRemainTime()
|
| | | if remainTime <= 0:
|
| | | # 永久buff不处理
|
| | | #GameWorld.DebugLog(" 永久buff不处理! curID=%s,index=%s,skillID=%s" % (curID, index, skillID))
|
| | | continue
|
| | | addTiming = buff.GetAddTiming()
|
| | | if not buff.GetRefreshState():
|
| | | GameWorld.DebugLog(" 未刷新过的buff更新为刷新过! curID=%s,index=%s,skillID=%s,buffID=%s,addTiming=%s" % (curID, index, skillID, buffID, addTiming))
|
| | | buff.SetRefreshState(1)
|
| | | continue
|
| | | if addTiming != curTiming:
|
| | | GameWorld.DebugLog(" buff添加时机不同不处理! curID=%s,index=%s,skillID=%s,buffID=%s,addTiming=%s" % (curID, index, skillID, buffID, addTiming))
|
| | | continue
|
| | | remainTime -= 1
|
| | | GameWorld.DebugLog(" 更新buff回合: curID=%s,buffID=%s,skillID=%s,remainTime=%s,addTiming=%s" % (curID, buffID, skillID, remainTime, addTiming))
|
| | | if remainTime > 0:
|
| | | buff.SetRemainTime(remainTime)
|
| | | TurnBuff.SyncBuffRefresh(turnFight, batObj, buff)
|
| | | else:
|
| | | TurnBuff.DoBuffDel(turnFight, batObj, buff)
|
| | | return
|
| | | |
| | | def AddTurnObjCureHP(curObj, srcObj, addValue, cureHP, skillID=0):
|
| | | ## 回合对象添加治疗值
|
| | | # @param curObj: 获得治疗的对象
|
| | |
| | |
|
| | | def OnObjAction(turnFight, curBatObj, isExtra=False):
|
| | | ## 战斗单位行动
|
| | | # @param isExtra: 是否额外行动的
|
| | | if not curBatObj:
|
| | | return
|
| | |
|
| | |
| | | atk = curBatObj.GetAtk()
|
| | | curXP = curBatObj.GetXP()
|
| | | GameWorld.DebugLog("★回合%s %s %s行动 : atk=%s,curHP=%s/%s,curXP=%s" % (turnNum, objName, "额外" if isExtra else "", atk, curHP, curBatObj.GetMaxHP(), curXP))
|
| | | turnFight.ResetOneActionUseSkillCnt()
|
| | | turnFight.syncObjAction(turnNum, objID)
|
| | |
|
| | | TurnPassive.OnTriggerPassiveEffect(turnFight, curBatObj, ChConfig.TriggerWay_HeroActionStart)
|
| | |
| | | skillID = useSkill.GetSkillID()
|
| | | # 常规攻击优先xp
|
| | | if SkillCommon.isAngerSkill(useSkill):
|
| | | if curXP < xpMax:
|
| | | if curXP < xpMax and not useSkill.GetEffectByID(ChConfig.SkillEff_AngerSkillNoXP):
|
| | | continue
|
| | | if curBatObj.CheckInState(ChConfig.BatObjState_Sneer):
|
| | | GameWorld.DebugLog("嘲讽状态下,无法主动释放怒技!") # 可被动释放怒技,如怒技追击
|
| | | GameWorld.DebugLog("嘲讽状态下,无法主动释放怒技! skillID=%s" % skillID) # 可被动释放怒技,如怒技追击
|
| | | continue
|
| | | useCnt = -1 # xp技能优先释放
|
| | | else:
|
| | | if useSkill.GetEffectByID(ChConfig.SkillEff_ActionUseInvalid): # 配置该效果时如果被嘲讽,相当于无法行动
|
| | | GameWorld.DebugLog("行动时无法释放该技能! skillID=%s" % skillID)
|
| | | continue
|
| | | useCnt = curBatObj.GetSkillUseCnt(skillID)
|
| | | useSkillList.append([useCnt, skillID, useSkill])
|
| | |
|
| | |
| | |
|
| | | # 非主线的PVE目标怪物
|
| | | if npcID and curPlayer and turnFight.isFBMap() and gameObj.GetFaction() != ChConfig.Def_FactionA:
|
| | | if not FBLogic.OnFBNPCKilledBefore(curPlayer, turnFight, gameObj, killer):
|
| | | if not FBLogic.OnFBNPCKilledBefore(curPlayer, turnFight, gameObj, killer, useSkill):
|
| | | return
|
| | |
|
| | | objID = gameObj.GetID()
|