|  |  |  | 
|---|
|  |  |  | import GameObj | 
|---|
|  |  |  | import time | 
|---|
|  |  |  | import random | 
|---|
|  |  |  | import ChConfig | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #{(标识点):[npcid,单个点数量,刷新间隔秒, 每次刷新只数, 第一次刷新只数]} | 
|---|
|  |  |  | #{(101,102,103):[20302001,1,'20', 2, 10]} | 
|---|
|  |  |  | #{(标识点):[npcid,单个点数量,刷新间隔秒, 每次刷新只数, 第一次刷新只数, 总个数上限]} | 
|---|
|  |  |  | #{(101,102,103):[20302001,1,'20', 2, 10,30]} | 
|---|
|  |  |  | ( | 
|---|
|  |  |  | Def_NPCID, | 
|---|
|  |  |  | Def_MaxCnt, | 
|---|
|  |  |  | Def_TimeFormula, | 
|---|
|  |  |  | Def_RefreshCnt, | 
|---|
|  |  |  | Def_FirstRefreshCnt | 
|---|
|  |  |  | ) = range(5) | 
|---|
|  |  |  | Def_FirstRefreshCnt, | 
|---|
|  |  |  | Def_TotalLimit, | 
|---|
|  |  |  | ) = range(6) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map_Dogzfb_LastRefreshTime = "Dogzfb_LastRefreshTime%s"  # 刷新时间 参数npcid | 
|---|
|  |  |  | Map_Dogzfb_NextNeedTime = "NextNeedTime%s"  # 下次刷新需要时间 参数npcid | 
|---|
|  |  |  | Map_Dogzfb_LastCheckTick = "LastCheckTick"  # 上次检查时间 | 
|---|
|  |  |  | Map_Dogzfb_NPCRemainCnt = 'NPCRemainCnt_%s'   # NPC剩余数量 | 
|---|
|  |  |  | Map_Dogzfb_CollectLostHPTick = 'CollectLostHPTick'   # 采集掉线Tick | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map_Dogzfb_CollectLostHPTick = 'CollectLostHPTick'   # 采集掉血Tick | 
|---|
|  |  |  | Map_Dogzfb_CollectLostHPCnt = 'CollectLostHPCnt'   # 采集掉血次数 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ## 是否能够通过活动查询进入 | 
|---|
|  |  |  | #  @param curPlayer 玩家实例 | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ## 开始采集 | 
|---|
|  |  |  | #  @param curPlayer 当前玩家 | 
|---|
|  |  |  | #  @param curNPC 当前NPC | 
|---|
|  |  |  | #  @return None or False | 
|---|
|  |  |  | #  @remarks 函数详细说明. | 
|---|
|  |  |  | def OnBeginCollect(curPlayer, curNPC): | 
|---|
|  |  |  | playerID = curPlayer.GetID() | 
|---|
|  |  |  | tick = GameWorld.GetGameWorld().GetTick() | 
|---|
|  |  |  | gameFB = GameWorld.GetGameFB() | 
|---|
|  |  |  | gameFB.SetPlayerGameFBDict(playerID, Map_Dogzfb_CollectLostHPTick, tick) | 
|---|
|  |  |  | gameFB.SetPlayerGameFBDict(playerID, Map_Dogzfb_CollectLostHPCnt, 0) | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ## 收集中 | 
|---|
|  |  |  | def OnCollecting(curPlayer, tick): | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | curNPC = GameWorld.GetNPCManager().GetNPCByIndex(tagObj.GetIndex()) | 
|---|
|  |  |  | npcID = curNPC.GetNPCID() | 
|---|
|  |  |  | __DoCollectLostHP(curPlayer, npcID, tick) | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def __DoCollectLostHP(curPlayer, npcID, tick): | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | playerID = curPlayer.GetID() | 
|---|
|  |  |  | gameFB = GameWorld.GetGameFB() | 
|---|
|  |  |  | collectLostHPTick = gameFB.GetPlayerGameFBDictByKey(playerID, Map_Dogzfb_CollectLostHPTick) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | lostHPCnt = gameFB.GetPlayerGameFBDictByKey(playerID, Map_Dogzfb_CollectLostHPCnt) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | lostCD = IpyGameDataPY.GetFuncEvalCfg('DogzFBCollect', 1, {}).get(npcID, 1) | 
|---|
|  |  |  | lostTime = (tick - collectLostHPTick) / 1000/lostCD # 掉血次数 | 
|---|
|  |  |  | if lostTime >3: | 
|---|
|  |  |  | gameFB.SetPlayerGameFBDict(playerID, Map_Dogzfb_CollectLostHPTick, tick) | 
|---|
|  |  |  | return | 
|---|
|  |  |  | lostTime = (tick - collectLostHPTick) / (1000*lostCD)-lostHPCnt | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if not lostTime: | 
|---|
|  |  |  | return | 
|---|
|  |  |  | gameFB.SetGameFBDict(Map_Dogzfb_CollectLostHPTick, tick) | 
|---|
|  |  |  | gameFB.SetPlayerGameFBDict(playerID, Map_Dogzfb_CollectLostHPCnt, lostHPCnt+lostTime) | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | lostHPPer = IpyGameDataPY.GetFuncEvalCfg('DogzFBCollect', 2, {}).get(npcID, 1) | 
|---|
|  |  |  | 
|---|
|  |  |  | lostValue = min(int(GameObj.GetMaxHP(curPlayer) * lostHPPer / 100.0) * lostTime, GameObj.GetHP(curPlayer)-1) | 
|---|
|  |  |  | if lostValue <=0: | 
|---|
|  |  |  | return | 
|---|
|  |  |  | #GameWorld.DebugLog("OnCollecting npcID=%s, lostHPPer=%s,lostTime=%s,lostValue=%s" % (npcID, lostHPPer, lostTime, lostValue)) | 
|---|
|  |  |  | GameWorld.DebugLog("OnCollecting npcID=%s, lostHPPer=%s,lostTime=%s,lostValue=%s" % (npcID, lostHPPer, lostTime, lostValue)) | 
|---|
|  |  |  | SkillCommon.SkillLostHP(curPlayer, skillTypeID, buffOwner, lostValue, tick) | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ##玩家收集成功(塔, 旗) | 
|---|
|  |  |  | # @param curPlayer 玩家实例 | 
|---|
|  |  |  | # @param tick 时间戳 | 
|---|
|  |  |  | # @return 无意义 | 
|---|
|  |  |  | # @remarks | 
|---|
|  |  |  | def OnCollectOK(curPlayer, npcID, tick): | 
|---|
|  |  |  | __DoCollectLostHP(curPlayer, npcID, tick) | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ##---副本总逻辑计时器--- | 
|---|
|  |  |  | # @param tick:时间戳 | 
|---|
|  |  |  | 
|---|
|  |  |  | continue | 
|---|
|  |  |  | rmark = npcRefresh.GetRefreshMark() | 
|---|
|  |  |  | npcCntDict[rmark] = npcCntDict.get(rmark, 0) + npcRefresh.GetCount() | 
|---|
|  |  |  |  | 
|---|
|  |  |  | isNeedSync = False #是否需要通知 | 
|---|
|  |  |  | for markInfo, refreshInfo in refreshDict.items(): | 
|---|
|  |  |  | npcID = refreshInfo[Def_NPCID] | 
|---|
|  |  |  | refreshCnt = refreshInfo[Def_FirstRefreshCnt] if isFirst else refreshInfo[Def_RefreshCnt] | 
|---|
|  |  |  | gameWorld.SetGameWorldDict(Map_Dogzfb_LastRefreshTime % npcID, curTime) | 
|---|
|  |  |  | maxCnt = refreshInfo[Def_MaxCnt] | 
|---|
|  |  |  | markList = [markInfo] if isinstance(markInfo, int) else list(markInfo) | 
|---|
|  |  |  | random.shuffle(markList) | 
|---|
|  |  |  | curTotalCnt = 0 | 
|---|
|  |  |  | for rMark in markList: | 
|---|
|  |  |  | if refreshCnt <=0: | 
|---|
|  |  |  | break | 
|---|
|  |  |  | curCnt = npcCntDict.get(rMark, 0) | 
|---|
|  |  |  | if curCnt >= maxCnt: | 
|---|
|  |  |  | continue | 
|---|
|  |  |  | needRefreshCnt = min(refreshCnt, maxCnt - curCnt) | 
|---|
|  |  |  | refreshCnt -= needRefreshCnt | 
|---|
|  |  |  | NPCCustomRefresh.SetNPCRefresh(rMark, [(npcID, needRefreshCnt)], needRefreshCnt + curCnt, needRefreshCnt) | 
|---|
|  |  |  | curTotalCnt += npcCntDict.get(rMark, 0) | 
|---|
|  |  |  | refreshCnt = min(refreshCnt, refreshInfo[Def_TotalLimit] - curTotalCnt) | 
|---|
|  |  |  | if refreshCnt > 0: | 
|---|
|  |  |  | random.shuffle(markList) | 
|---|
|  |  |  | for rMark in markList: | 
|---|
|  |  |  | if refreshCnt <=0: | 
|---|
|  |  |  | break | 
|---|
|  |  |  | curCnt = npcCntDict.get(rMark, 0) | 
|---|
|  |  |  | if curCnt >= maxCnt: | 
|---|
|  |  |  | continue | 
|---|
|  |  |  | needRefreshCnt = min(refreshCnt, maxCnt - curCnt) | 
|---|
|  |  |  | refreshCnt -= needRefreshCnt | 
|---|
|  |  |  | NPCCustomRefresh.SetNPCRefresh(rMark, [(npcID, needRefreshCnt)], needRefreshCnt + curCnt, needRefreshCnt) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #计算下次多久刷新 | 
|---|
|  |  |  | __UpdateBossTime(npcID, refreshInfo[Def_TimeFormula]) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if npcID in IpyGameDataPY.GetFuncEvalCfg('DogzFBRefreshCfg', 3): | 
|---|
|  |  |  | isNeedSync = True | 
|---|
|  |  |  | #通知时间 | 
|---|
|  |  |  | SyncNPCRefreshTime() | 
|---|
|  |  |  | if isNeedSync: | 
|---|
|  |  |  | SyncNPCRefreshTime() | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def OnOnlineCntChange(key, tick): | 
|---|
|  |  |  | if GameWorld.GetMap().GetMapID() != ChConfig.Def_FBMapID_Dogz: | 
|---|
|  |  |  | return | 
|---|
|  |  |  | bossid = IpyGameDataPY.GetFuncCfg('DogzFBRefreshCfg', 2) | 
|---|
|  |  |  | if str(bossid) not in key: | 
|---|
|  |  |  | return | 
|---|
|  |  |  | 
|---|
|  |  |  | nextNeedTime = gameWorldMgr.GetGameWorldDictByKey(Map_Dogzfb_NextNeedTime % npcID) | 
|---|
|  |  |  | return max(0, nextNeedTime - curTime + lastRefreshTime) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def SyncNPCRefreshTime(playerid=0): | 
|---|
|  |  |  | curTime = int(time.time()) | 
|---|
|  |  |  | def SyncNPCRefreshTime(): | 
|---|
|  |  |  | syncNPCIDList = IpyGameDataPY.GetFuncEvalCfg('DogzFBRefreshCfg', 3) | 
|---|
|  |  |  | syncDict = {} | 
|---|
|  |  |  | for npcID in syncNPCIDList: | 
|---|
|  |  |  | refreshTime = GetDogzNPCRefreshTime(curTime, npcID) | 
|---|
|  |  |  | syncDict[npcID] = refreshTime | 
|---|
|  |  |  | msgStr = str([playerid, syncDict]) | 
|---|
|  |  |  | gameWorldMgr = GameWorld.GetGameWorld() | 
|---|
|  |  |  | lastRefreshTime = gameWorldMgr.GetGameWorldDictByKey(Map_Dogzfb_LastRefreshTime % npcID) | 
|---|
|  |  |  | nextNeedTime = gameWorldMgr.GetGameWorldDictByKey(Map_Dogzfb_NextNeedTime % npcID) | 
|---|
|  |  |  | syncDict[npcID] = [lastRefreshTime, nextNeedTime] | 
|---|
|  |  |  | msgStr = str(syncDict) | 
|---|
|  |  |  | GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(0, 0, 0, 'DogzNPCTime', msgStr, len(msgStr)) | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|