| | |
| | |
|
| | | import ChConfig
|
| | | import PlayerTask
|
| | | import PlayerActivity
|
| | | import PlayerViewCache
|
| | | import ChPyNetSendPack
|
| | | import NetPackCommon
|
| | |
| | | import TurnPassive
|
| | | import TurnSkill
|
| | | import TurnBuff
|
| | | import FBCommon
|
| | | import CommFunc
|
| | | import ObjPool
|
| | | import FBLogic
|
| | |
| | | self.lingshouObjIDDict = {} # 灵兽战斗单位 {位置编号:batObjID, ...}
|
| | | self.beautyObjIDDict = {} # 红颜战斗单位 {位置编号:batObjID, ...}
|
| | | self.actionNum = ActionNumStart # 行动位置,从1开始
|
| | | self.totalHurt = 0 # 阵容总输出
|
| | | return
|
| | |
|
| | | def getPlayerID(self): return self.turnFight.playerID # 发起的玩家ID
|
| | |
| | | self.lingshouObjIDDict = {}
|
| | | self.beautyObjIDDict = {}
|
| | | self.fightPower = 0
|
| | | self.totalHurt = 0
|
| | | return
|
| | |
|
| | | class BatFaction():
|
| | |
| | | self.turnFight = turnFight # TurnFight
|
| | | self.faction = faction
|
| | | self.lineupDict = {} # 该阵营所有阵容信息 {编号:BatLineup, ...}
|
| | | self.totalHurt = 0 # 阵营总输出
|
| | | return
|
| | |
|
| | | def getBatlineup(self, num=1):
|
| | |
| | | lineup = BatLineup(self.faction, num, self.turnFight)
|
| | | self.lineupDict[num] = lineup
|
| | | return lineup
|
| | | |
| | | def getTotalHurt(self): return self.totalHurt # 阵营总输出
|
| | |
|
| | | def clearLineups(self):
|
| | | ## 清除所有战斗阵容
|
| | |
| | | self.batBuffer = "" # 战报buffer,战报暂时只保留最后一个小队的
|
| | | self.isNeedReport = isNeedReport # 是否需要战报
|
| | | self.msgDict = {} # 扩展信息字典,一般由MapID绑定的功能决定信息内容 {k:v, ...}
|
| | | self._kvDict = {} # 自定义信息字典,不会被重置 {k:v, ...}
|
| | |
|
| | | self.factionDict = {} # 战斗阵营 {faction:BatFaction, ...},一般是只有两个阵营,faction为1或2,每个阵营支持多个阵容
|
| | | self.actionSortList = [] # 阵容行动顺序 [[faction, num], ...]
|
| | |
| | | self.setPVE()
|
| | | self.setPVP()
|
| | | self.msgDict = {}
|
| | | self._kvDict = {}
|
| | | self.nextTurnFight(msgDict)
|
| | | return
|
| | |
|
| | |
| | | self.tagViewCache = tagViewCache
|
| | | return
|
| | |
|
| | | def isFBMap(self):
|
| | | ## 是否副本地图中,非主线的均视为副本
|
| | | return self.mapID not in [ChConfig.Def_FBMapID_Main, ChConfig.Def_FBMapID_MainBoss]
|
| | | |
| | | def GetDictByKey(self, key): return self._kvDict.get(key, 0)
|
| | | def SetDict(self, key, value): self._kvDict[key] = value
|
| | | |
| | | #def setPVPTeam(self):
|
| | | # return
|
| | |
|
| | | def nextTurnFight(self, msgDict={}, resetByNextTeam=False):
|
| | | def nextTurnFight(self, msgDict={}):
|
| | | ## 一般用于玩家发起的战斗,在需要保留玩家阵容属性及状态的情况下,重置回合进入下一场战斗
|
| | | self.turnNum = 1
|
| | | self.enterLogic = False
|
| | |
| | | self.timeline = 0
|
| | | self.startTime = time.time()
|
| | | self.costTime = 0
|
| | | if resetByNextTeam:
|
| | | ResetByNextTeam(self)
|
| | | ResetByNextTeam(self)
|
| | | return
|
| | |
|
| | | def haveNextLineup(self):
|
| | |
| | | self.addBatPack(clientPack)
|
| | | return
|
| | |
|
| | | def syncHelp(self, msgDict):
|
| | | ## 通知帮助信息,一般是副本用
|
| | | self.syncState(self.state, msgDict)
|
| | | return
|
| | | |
| | | def syncState(self, state, msgDict={}):
|
| | | self.state = state
|
| | | msg = json.dumps(msgDict, ensure_ascii=False)
|
| | |
| | | ## 回合战斗管理器
|
| | |
|
| | | 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
|
| | |
| | | if not curPlayer:
|
| | | return
|
| | |
|
| | | tfGUID = batLineup.turnFight.guid
|
| | | turnFight = batLineup.turnFight
|
| | | tfGUID = turnFight.guid
|
| | | lineupPlayerID = lineupInfo.get("PlayerID", 0) # 阵容所属玩家ID
|
| | | heroDict = lineupInfo.get("Hero", {})
|
| | |
|
| | |
| | |
|
| | | batLineup.posObjIDDict[posNum] = objID
|
| | | GameWorld.DebugLog("AddBatObj %s,skill=%s" % (GetObjName(batObj), skillManager.GetSkillIDList()))
|
| | | if npcID:
|
| | | #副本指定NPC属性
|
| | | fbNPCInitAttrDict = FBLogic.GetFBNPCInitAttr(curPlayer, turnFight, batObj)
|
| | | if fbNPCInitAttrDict:
|
| | | GameWorld.DebugLog("副本指定NPC初始化属性: npcID=%s, %s" % (npcID, fbNPCInitAttrDict))
|
| | | attrDict = {str(k):v for k, v in fbNPCInitAttrDict.items()} # 统一格式
|
| | | batObj.InitBatAttr({int(k):v for k, v in attrDict.items()}, initXP)
|
| | |
|
| | | return
|
| | |
| | |
|
| | | 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
|
| | | #
|
| | | #struct tagCMTurnFight
|
| | |
| | | tagID = clientData.TagID
|
| | | valueList = clientData.ValueList
|
| | |
|
| | | GameWorld.DebugLog("回合制战斗请求: mapID=%s,funcLineID=%s,tagType=%s,tagID=%s,valueList=%s" |
| | | GameWorld.DebugLog("----- 回合制战斗请求: mapID=%s,funcLineID=%s,tagType=%s,tagID=%s,valueList=%s" |
| | | % (mapID, funcLineID, tagType, tagID, valueList), curPlayer.GetPlayerID())
|
| | |
|
| | | reqRet = FBLogic.OnTurnFightRequest(curPlayer, mapID, funcLineID, tagType, tagID, valueList)
|
| | | if not reqRet:
|
| | | return
|
| | | funcLineID = reqRet[1] if len(reqRet) > 1 else funcLineID
|
| | |
|
| | | fbIpyData = FBCommon.GetFBIpyData(mapID)
|
| | | fbLineIpyData = FBCommon.GetFBLineIpyData(mapID, funcLineID, False)
|
| | | if fbIpyData:
|
| | | if not fbLineIpyData:
|
| | | GameWorld.DebugLog("不存在该副本功能线路! mapID=%s,funcLineID=%s" % (mapID, funcLineID))
|
| | | return
|
| | | if FBCommon.CheckCanEnterFBComm(curPlayer, mapID, funcLineID, fbIpyData, fbLineIpyData) != ShareDefine.EntFBAskRet_OK:
|
| | | return
|
| | | |
| | | # 攻防方所使用的阵容ID
|
| | | atkLineupID, defLineupID = FBLogic.GetFBPlayerLineupID(curPlayer, mapID, funcLineID)
|
| | | if atkLineupID not in ShareDefine.LineupList or defLineupID not in ShareDefine.LineupList:
|
| | | return
|
| | | |
| | | if CheckFightCD(curPlayer, tick, "TurnFightReqTick"):
|
| | | return
|
| | |
|
| | | # 玩家
|
| | |
| | |
|
| | | # NPC
|
| | | else:
|
| | | ret = FBLogic.GetFBNPCLineupInfo(curPlayer, mapID, funcLineID)
|
| | | if not ret:
|
| | | return
|
| | | npcLineupIDList, strongerLV, difficulty = ret
|
| | | npcLineupIDList, strongerLV, difficulty = [], 0, 0
|
| | | if fbLineIpyData:
|
| | | npcLineupIDList = fbLineIpyData.GetLineupIDList()
|
| | | strongerLV = fbLineIpyData.GetNPCLV()
|
| | | difficulty = fbLineIpyData.GetDifficulty()
|
| | | |
| | | if not npcLineupIDList:
|
| | | ret = FBLogic.GetFBNPCLineupInfo(curPlayer, mapID, funcLineID)
|
| | | if not ret:
|
| | | return
|
| | | npcLineupIDList, strongerLV, difficulty = ret
|
| | | OnTurnFightVSNPC(curPlayer, mapID, funcLineID, atkLineupID, npcLineupIDList, strongerLV, difficulty)
|
| | |
|
| | | return
|
| | |
| | | turnFight.lineupIndex = index
|
| | | GameWorld.DebugLog("对战NPC阵容: index=%s, lineupID=%s" % (index, lineupID))
|
| | | if index > 0:
|
| | | turnFight.nextTurnFight(resetByNextTeam=True)
|
| | | turnFight.nextTurnFight()
|
| | | turnFight.setFactionLineup(ChConfig.Def_FactionB, {1:GetNPCLineupInfo(lineupID, strongerLV, difficulty)})
|
| | | turnFight.sortActionQueue()
|
| | | turnFight.startFight()
|
| | |
| | | __doSetFightPoint(curPlayer, reqValue)
|
| | | return
|
| | |
|
| | | GameWorld.DebugLog("主线战斗请求: reqType=%s" % reqType, curPlayer.GetPlayerID())
|
| | | GameWorld.DebugLog("------------------- 主线战斗请求: reqType=%s" % reqType, curPlayer.GetPlayerID())
|
| | | clientPack = ChPyNetSendPack.tagSCTurnFightReportSign()
|
| | | clientPack.Sign = 0
|
| | | NetPackCommon.SendFakePack(curPlayer, clientPack) # 标记开始
|
| | |
| | |
|
| | | # 限制请求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
|
| | |
| | | if nextLineupID:
|
| | | GameWorld.DebugLog("---开始进入下一小队: lineupIndex=%s,nextLineupID=%s,%s" % (turnFight.lineupIndex, nextLineupID, turnFight.lineupIDList))
|
| | |
|
| | | turnFight.nextTurnFight(resetByNextTeam=True)
|
| | | turnFight.nextTurnFight()
|
| | | # 切换小队时,玩家阵容不需要处理,保留状态
|
| | | turnFight.setFactionLineup(ChConfig.Def_FactionB, {1:GetNPCLineupInfo(nextLineupID, turnFight.strongerLV, turnFight.difficulty)})
|
| | | turnFight.sortActionQueue()
|
| | |
| | | turnNum = turnFight.turnNum
|
| | | turnMax = turnFight.turnMax
|
| | | for turnNum in range(turnNum, turnMax + 1):
|
| | | if turnFight.winFaction:
|
| | | break
|
| | | turnTimeline = turnFight.getTurnNumStartTimelin(turnNum) # 本回合起始时间节点
|
| | | curTimeline = turnFight.getTimeline()
|
| | |
|
| | |
| | | # 红颜
|
| | | # 灵兽
|
| | |
|
| | | if turnFight.checkOverByKilled():
|
| | | if turnFight.winFaction:
|
| | | break
|
| | |
|
| | | # 武将
|
| | | doMax = PosNumMax * len(turnFight.actionSortList)
|
| | | doCnt = 0
|
| | | while doCnt < doMax and turnFight.actionIndex < len(turnFight.actionSortList):
|
| | | while doCnt < doMax and turnFight.actionIndex < len(turnFight.actionSortList) and not turnFight.winFaction:
|
| | | doCnt += 1
|
| | | faction, num = turnFight.actionSortList[turnFight.actionIndex]
|
| | | batFaction = turnFight.getBatFaction(faction)
|
| | |
| | | else:
|
| | | turnFight.actionIndex += 1
|
| | |
|
| | | if turnFight.winFaction:
|
| | | break
|
| | | |
| | | # 回合结束
|
| | | curTimeline = turnFight.setTimeline(curTimeline + 1) # 每回合结束算一个时间节点
|
| | | for faction, num in turnFight.actionSortList:
|
| | |
| | | batObj = batObjMgr.getBatObj(objID)
|
| | | TurnFightPerTurnBigEnd(turnFight, batObj, turnNum)
|
| | |
|
| | | if turnFight.checkOverByKilled():
|
| | | break
|
| | | |
| | | if not turnFight.winFaction:
|
| | | OnTurnAllOver(turnFight.guid)
|
| | |
|
| | |
| | | EntryLogic(turnFight)
|
| | | batObjMgr = BattleObj.GetBatObjMgr()
|
| | | for turnNum in range(1, turnMax + 1):
|
| | | if turnFight.winFaction:
|
| | | break
|
| | | turnFight.turnNum = turnNum
|
| | | GameWorld.DebugLog("【----- 回合制战斗轮次: %s -----】" % turnNum)
|
| | | curTimeline = turnFight.getTurnNumStartTimelin(turnNum) # 本回合起始时间节点
|
| | |
| | | # 红颜
|
| | | # 灵兽
|
| | |
|
| | | if turnFight.checkOverByKilled():
|
| | | if turnFight.winFaction:
|
| | | break
|
| | |
|
| | | # 武将
|
| | | doMax = PosNumMax * len(turnFight.actionSortList)
|
| | | doCnt = 0
|
| | | while doCnt < doMax and turnFight.actionIndex < len(turnFight.actionSortList):
|
| | | while doCnt < doMax and turnFight.actionIndex < len(turnFight.actionSortList) and not turnFight.winFaction:
|
| | | doCnt += 1
|
| | | faction, num = turnFight.actionSortList[turnFight.actionIndex]
|
| | | batFaction = turnFight.getBatFaction(faction)
|
| | |
| | | else:
|
| | | turnFight.actionIndex += 1
|
| | |
|
| | | if turnFight.winFaction:
|
| | | break
|
| | | |
| | | # 回合结束
|
| | | curTimeline = turnFight.setTimeline(curTimeline + 1) # 每回合结束算一个时间节点
|
| | | for faction, num in turnFight.actionSortList:
|
| | |
| | | batObj = batObjMgr.getBatObj(objID)
|
| | | TurnFightPerTurnBigEnd(turnFight, batObj, turnNum)
|
| | |
|
| | | if turnFight.checkOverByKilled():
|
| | | break
|
| | | |
| | | if not turnFight.winFaction:
|
| | | OnTurnAllOver(turnFight.guid)
|
| | | return
|
| | |
| | | return True
|
| | |
|
| | | def SetObjKilled(turnFight, gameObj, killer=None, useSkill=None):
|
| | | curPlayer = turnFight.curPlayer
|
| | | npcID = gameObj.GetNPCID()
|
| | | |
| | | # 非主线的PVE目标怪物
|
| | | if npcID and curPlayer and turnFight.isFBMap() and gameObj.GetFaction() != ChConfig.Def_FactionA:
|
| | | if not FBLogic.OnFBNPCKilledBefore(curPlayer, turnFight, gameObj, killer):
|
| | | return
|
| | | |
| | | objID = gameObj.GetID()
|
| | | killerObjID = killer.GetID() if killer else 0
|
| | | skillID = useSkill.GetSkillID() if useSkill else 0
|
| | |
| | | clientPack.SkillID = skillID
|
| | | turnFight.addBatPack(clientPack)
|
| | |
|
| | | curPlayer = turnFight.curPlayer
|
| | | # 暂时只算主线小怪
|
| | | if curPlayer and turnFight.mapID == ChConfig.Def_FBMapID_Main and gameObj.GetFaction() != ChConfig.Def_FactionA:
|
| | | PlayerTask.AddTaskValue(curPlayer, ChConfig.TaskType_KillNPC, 1) |
| | | PlayerTask.AddTaskValue(curPlayer, ChConfig.TaskType_KillNPC, 1)
|
| | | PlayerActivity.AddDailyTaskValue(curPlayer, ChConfig.DailyTask_KillNPC, 1)
|
| | | return True
|
| | |
|
| | | def OnTurnAllOver(guid):
|
| | |
| | | statInfo[str(faction)] = {}
|
| | | facStatInfo = statInfo[str(faction)]
|
| | | batFaction = turnFight.getBatFaction(faction)
|
| | | batFaction.totalHurt = 0
|
| | | for num in batFaction.lineupDict.keys():
|
| | | if str(num) not in facStatInfo:
|
| | | facStatInfo[str(num)] = {}
|
| | | lineupStatInfo = facStatInfo[str(num)]
|
| | | batLineup = batFaction.getBatlineup(num)
|
| | | batLineup.totalHurt = 0
|
| | | GameWorld.DebugLog("阵容明细: faction=%s,num=%s" % (faction, num))
|
| | | for posNum, objID in batLineup.posObjIDDict.items():
|
| | | batObj = batObjMgr.getBatObj(objID)
|
| | |
| | | atkHurt = batObj.hurtStat
|
| | | defHurt = batObj.defStat
|
| | | cureHP = batObj.cureStat
|
| | | batLineup.totalHurt += atkHurt
|
| | | batFaction.totalHurt += atkHurt
|
| | | GameWorld.DebugLog(" Pos:%s ID=%s,npcID=%s,heroID=%s,HP=%s/%s, 输出=%s,承伤=%s,治疗=%s"
|
| | | % (posNum, objID, npcID, heroID, batObj.GetHP(), batObj.GetMaxHP(), atkHurt, defHurt, cureHP))
|
| | | lineupStatInfo[str(posNum)] = {"ObjID":objID, "HeroID":heroID, "NPCID":npcID, "AtkHurt":atkHurt, "DefHurt":defHurt, "CureHP":cureHP}
|