|  |  |  | 
|---|
|  |  |  | import PyGameData | 
|---|
|  |  |  | import GameFuncComm | 
|---|
|  |  |  | import EventShell | 
|---|
|  |  |  | import PlayerTJG | 
|---|
|  |  |  | import PlayerPet | 
|---|
|  |  |  | import datetime | 
|---|
|  |  |  | import time | 
|---|
|  |  |  | 
|---|
|  |  |  | #struct    tagCMActivityPlaceStart | 
|---|
|  |  |  | #{ | 
|---|
|  |  |  | #    tagHead        Head; | 
|---|
|  |  |  | #    BYTE        RewardEndType;    //是否结算探索,后端处理奖励后自动启动下一次放置探索;0-无结算启动,1-倒计时结束结算,2-快速结算; | 
|---|
|  |  |  | #}; | 
|---|
|  |  |  | def OnActivityPlaceStart(index, clientData, tick): | 
|---|
|  |  |  | curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index) | 
|---|
|  |  |  | rewardEndType = clientData.RewardEndType | 
|---|
|  |  |  |  | 
|---|
|  |  |  | rewardCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRewardCount) | 
|---|
|  |  |  | maxRewardCount = IpyGameDataPY.GetFuncCfg("ActivityPlace", 4) # 最大累计放置奖励次数 | 
|---|
|  |  |  | if rewardCount >= maxRewardCount: | 
|---|
|  |  |  | GameWorld.ErrLog("活跃放置奖励累计次数已达上限,无法启动") | 
|---|
|  |  |  | remainCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRemainCount) | 
|---|
|  |  |  | rewardCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRewardCount) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | maxCanStartCount = maxRewardCount - remainCount - rewardCount | 
|---|
|  |  |  | if maxCanStartCount <= 0: | 
|---|
|  |  |  | GameWorld.DebugLog("活跃放置奖励累计次数已达上限,无法启动!remainCount=%s + rewardCount=%s >= maxRewardCount=%s" | 
|---|
|  |  |  | % (remainCount, rewardCount, maxRewardCount)) | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | placeState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceState) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | endCount, nextStartReduceSeconds = 1, 0 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 无结算启动 | 
|---|
|  |  |  | if rewardEndType == 0: | 
|---|
|  |  |  | if placeState: | 
|---|
|  |  |  | GameWorld.DebugLog("已在放置探索中!") | 
|---|
|  |  |  | costPoint = IpyGameDataPY.GetFuncCfg("ActivityPlace", 2) # 单次放置消耗的活跃点数 | 
|---|
|  |  |  | canUseActivityPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityCanCostTotalPoint) | 
|---|
|  |  |  | pointCanUseCount = canUseActivityPoint / costPoint | 
|---|
|  |  |  | startCount = min(maxCanStartCount, pointCanUseCount) | 
|---|
|  |  |  | if startCount <= 0: | 
|---|
|  |  |  | GameWorld.DebugLog("可用活跃不足,无法添加次数启动!canUseActivityPoint=%s,costPoint=%s" % (canUseActivityPoint, costPoint)) | 
|---|
|  |  |  | return | 
|---|
|  |  |  | __DoActivityPlaceStart(curPlayer) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 倒计时结束结算 | 
|---|
|  |  |  | elif rewardEndType == 1: | 
|---|
|  |  |  | if not placeState: | 
|---|
|  |  |  | GameWorld.DebugLog("非放置探索中,无法结算!") | 
|---|
|  |  |  | return | 
|---|
|  |  |  | startTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceStartTime) | 
|---|
|  |  |  | if not startTime: | 
|---|
|  |  |  | return | 
|---|
|  |  |  | needSeconds = IpyGameDataPY.GetFuncCfg("ActivityPlace", 3) # 单次放置奖励持续时间,秒 | 
|---|
|  |  |  | updRemainCount = remainCount + startCount | 
|---|
|  |  |  | GameWorld.DebugLog("添加活跃放置次数: startCount=%s,rewardCount=%s,remainCount=%s,updRemainCount=%s" | 
|---|
|  |  |  | % (startCount, rewardCount, remainCount, updRemainCount)) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | costPointTotal = costPoint * startCount | 
|---|
|  |  |  | CostActivityPoint(curPlayer, costPointTotal) | 
|---|
|  |  |  | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceRemainCount, updRemainCount) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if not remainCount: | 
|---|
|  |  |  | curTime = int(time.time()) | 
|---|
|  |  |  | passTime = curTime - startTime | 
|---|
|  |  |  | if passTime < needSeconds: | 
|---|
|  |  |  | GameWorld.DebugLog("探索时间未到,无法结算! curTime=%s,startTime=%s,passTime=%s < %s" % (curTime, startTime, passTime, needSeconds)) | 
|---|
|  |  |  | return | 
|---|
|  |  |  | endCount = passTime / needSeconds | 
|---|
|  |  |  | nextStartReduceSeconds = passTime % needSeconds | 
|---|
|  |  |  | __DoActivityPlaceRewardEnd(curPlayer, endCount, nextStartReduceSeconds) | 
|---|
|  |  |  | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceStartTime, curTime) | 
|---|
|  |  |  | GameWorld.DebugLog("    没有剩余次数,更新启动时间: %s" % curTime) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 快速结算 | 
|---|
|  |  |  | elif rewardEndType == 2: | 
|---|
|  |  |  | if not placeState: | 
|---|
|  |  |  | GameWorld.DebugLog("非放置探索中,无法快速结算!") | 
|---|
|  |  |  | Sync_ActivityPlaceInfo(curPlayer) | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #// B0 28 活跃放置快速完成 #tagCMActivityPlaceQuickFinish | 
|---|
|  |  |  | # | 
|---|
|  |  |  | #struct    tagCMActivityPlaceQuickFinish | 
|---|
|  |  |  | #{ | 
|---|
|  |  |  | #    tagHead        Head; | 
|---|
|  |  |  | #}; | 
|---|
|  |  |  | def OnActivityPlaceQuickFinish(index, clientData, tick): | 
|---|
|  |  |  | curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | remainCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRemainCount) | 
|---|
|  |  |  | if not remainCount: | 
|---|
|  |  |  | GameWorld.DebugLog("没有剩余活跃放置次数,无法快速完成!") | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | costItemID, costGoldParper = IpyGameDataPY.GetFuncEvalCfg("ActivityPlace", 5) | 
|---|
|  |  |  | costItemCount = 1 | 
|---|
|  |  |  | costItemCount = 1 # 默认扣一个 | 
|---|
|  |  |  | endCount = 1 # 只快速结算一次 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | costItemIndexList, bindCnt, unBindCnt = ItemCommon.GetPackItemBindStateIndexInfo(curPlayer, costItemID, costItemCount) | 
|---|
|  |  |  | lackCnt = costItemCount - bindCnt - unBindCnt | 
|---|
|  |  |  | 
|---|
|  |  |  | else: | 
|---|
|  |  |  | ItemCommon.DelCostItemByBind(curPlayer, costItemIndexList, bindCnt, unBindCnt, costItemCount, ChConfig.ItemDel_ActivityPlace) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | __DoActivityPlaceRewardEnd(curPlayer, endCount, nextStartReduceSeconds) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Sync_ActivityPlaceInfo(curPlayer) | 
|---|
|  |  |  | __DoActivityPlaceRewardEnd(curPlayer, endCount) | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def __DoActivityPlaceRewardEnd(curPlayer, endCount, nextStartReduceSeconds): | 
|---|
|  |  |  | def ProcessActivityPlace(curPlayer): | 
|---|
|  |  |  | ## 活跃放置定时处理 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | remainCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRemainCount) | 
|---|
|  |  |  | if remainCount <= 0: | 
|---|
|  |  |  | #GameWorld.DebugLog("没有剩余放置次数不处理!") | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | curTime = int(time.time()) | 
|---|
|  |  |  | startTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceStartTime) | 
|---|
|  |  |  | if not startTime: | 
|---|
|  |  |  | startTime = curTime | 
|---|
|  |  |  | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceStartTime, curTime) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | needSeconds = IpyGameDataPY.GetFuncCfg("ActivityPlace", 3) # 单次放置奖励持续时间,秒 | 
|---|
|  |  |  | passTime = curTime - startTime | 
|---|
|  |  |  | if passTime < needSeconds: | 
|---|
|  |  |  | #GameWorld.DebugLog("探索时间未到,不结算! curTime=%s,startTime=%s,passTime=%s < %s" % (curTime, startTime, passTime, needSeconds)) | 
|---|
|  |  |  | return | 
|---|
|  |  |  | endCount = passTime / needSeconds | 
|---|
|  |  |  | nextStartReduceSeconds = passTime % needSeconds | 
|---|
|  |  |  | __DoActivityPlaceRewardEnd(curPlayer, endCount, nextStartReduceSeconds) | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def __DoActivityPlaceRewardEnd(curPlayer, endCount, nextStartReduceSeconds=0): | 
|---|
|  |  |  | ## 放置活跃奖励结算 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if not endCount: | 
|---|
|  |  |  | remainCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRemainCount) | 
|---|
|  |  |  | endCount = min(endCount, remainCount) | 
|---|
|  |  |  | if endCount <= 0: | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if PlayerTJG.GetIsTJG(curPlayer): | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | countDataDict = {} | 
|---|
|  |  |  | lvDataDict = {} | 
|---|
|  |  |  | ipyDataMgr = IpyGameDataPY.IPY_Data() | 
|---|
|  |  |  | 
|---|
|  |  |  | if not lvRewardIpyData: | 
|---|
|  |  |  | lvRewardIpyData = lvDataDict[lvList[-1]] | 
|---|
|  |  |  |  | 
|---|
|  |  |  | costPoint = IpyGameDataPY.GetFuncCfg("ActivityPlace", 2) # 单次放置消耗的活跃点数 | 
|---|
|  |  |  | maxRewardCount = IpyGameDataPY.GetFuncCfg("ActivityPlace", 4) # 最大累计放置奖励次数 | 
|---|
|  |  |  | maxAppointCount = max(countDataDict) # 最大定制奖励次数 | 
|---|
|  |  |  | rewardCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRewardCount) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | isStop = False | 
|---|
|  |  |  | rewardItemDict = {} | 
|---|
|  |  |  | GameWorld.DebugLog("结算放置活跃奖励: rewardCount=%s,endCount=%s,maxRewardCount=%s,maxAppointCount=%s" % (rewardCount, endCount, maxRewardCount, maxAppointCount)) | 
|---|
|  |  |  | for endIndex in xrange(endCount): | 
|---|
|  |  |  | #GameWorld.DebugLog("endIndex=%s" % endIndex) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 超过1次的需要补扣活跃消耗 | 
|---|
|  |  |  | if endCount > 1 and endIndex != 0: | 
|---|
|  |  |  | if not CostActivityPoint(curPlayer, costPoint): | 
|---|
|  |  |  | isStop = True | 
|---|
|  |  |  | GameWorld.DebugLog("    可消耗的活跃不足,无法继续结算奖励!") | 
|---|
|  |  |  | break | 
|---|
|  |  |  |  | 
|---|
|  |  |  | rewardIpyData = None | 
|---|
|  |  |  | rewardTotalCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRewardTotalCount) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | rewardItemDict = {} | 
|---|
|  |  |  | GameWorld.DebugLog("结算放置活跃奖励: remainCount=%s,rewardCount=%s,endCount=%s,maxAppointCount=%s" % (remainCount, rewardCount, endCount, maxAppointCount)) | 
|---|
|  |  |  | for _ in xrange(endCount): | 
|---|
|  |  |  |  | 
|---|
|  |  |  | rewardIpyData = None | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 加奖励次数 | 
|---|
|  |  |  | remainCount -= 1 | 
|---|
|  |  |  | rewardCount += 1 | 
|---|
|  |  |  | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceRewardCount, rewardCount) | 
|---|
|  |  |  | if rewardTotalCount < maxAppointCount: | 
|---|
|  |  |  | rewardTotalCount += 1 | 
|---|
|  |  |  | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceRewardTotalCount, rewardTotalCount) | 
|---|
|  |  |  | if rewardTotalCount in countDataDict: | 
|---|
|  |  |  | rewardIpyData = countDataDict[rewardTotalCount] | 
|---|
|  |  |  | #GameWorld.DebugLog("    取定制次数奖励") | 
|---|
|  |  |  | #GameWorld.DebugLog("    取定制次数奖励: rewardTotalCount=%s" % rewardTotalCount) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if not rewardIpyData: | 
|---|
|  |  |  | rewardIpyData = lvRewardIpyData | 
|---|
|  |  |  | 
|---|
|  |  |  | if itemID: | 
|---|
|  |  |  | rewardItemDict[itemID] = rewardItemDict.get(itemID, 0) + 1 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GameWorld.DebugLog("    rewardCount=%s,rewardTotalCount=%s, %s" % (rewardCount, rewardTotalCount, rewardItemDict)) | 
|---|
|  |  |  | GameWorld.DebugLog("    remainCount=%s,rewardCount=%s,rewardTotalCount=%s, %s" % (remainCount, rewardCount, rewardTotalCount, rewardItemDict)) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if rewardCount >= maxRewardCount: | 
|---|
|  |  |  | isStop = True | 
|---|
|  |  |  | GameWorld.DebugLog("    放置活跃奖励次数已达上限!rewardCount=%s" % rewardCount) | 
|---|
|  |  |  | break | 
|---|
|  |  |  | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceRemainCount, remainCount) | 
|---|
|  |  |  | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceRewardCount, rewardCount) | 
|---|
|  |  |  | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceRewardTotalCount, rewardTotalCount) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if remainCount > 0: | 
|---|
|  |  |  | nextStartTime = int(time.time()) - nextStartReduceSeconds | 
|---|
|  |  |  | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceStartTime, nextStartTime) | 
|---|
|  |  |  | GameWorld.DebugLog("    还有剩余次数,更新启动时间: %s, nextStartReduceSeconds=%s" % (nextStartTime, nextStartReduceSeconds)) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 存储奖励 | 
|---|
|  |  |  | rewardItemCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRewardItem) | 
|---|
|  |  |  | 
|---|
|  |  |  | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceRewardItem, rewardItemCount) | 
|---|
|  |  |  | #GameWorld.DebugLog("    新增探索奖励: itemID=%s,itemCount=%s,rewardItemCount=%s" % (itemID, itemCount, rewardItemCount)) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if isStop: | 
|---|
|  |  |  | GameWorld.DebugLog("    停止探索!") | 
|---|
|  |  |  | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceState, 0) | 
|---|
|  |  |  | else: | 
|---|
|  |  |  | __DoActivityPlaceStart(curPlayer, nextStartReduceSeconds) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Sync_ActivityPlaceInfo(curPlayer) | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def __DoActivityPlaceStart(curPlayer, reduceSeconds=0): | 
|---|
|  |  |  |  | 
|---|
|  |  |  | costPoint = IpyGameDataPY.GetFuncCfg("ActivityPlace", 2) # 单次放置消耗的活跃点数 | 
|---|
|  |  |  | canUseActivityPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityCanCostTotalPoint) | 
|---|
|  |  |  | if canUseActivityPoint < costPoint: | 
|---|
|  |  |  | GameWorld.DebugLog("活跃度不足,无法启动放置探索!canUseActivityPoint=%s" % canUseActivityPoint) | 
|---|
|  |  |  | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceState, 0) | 
|---|
|  |  |  | return | 
|---|
|  |  |  | startTime = int(time.time()) - reduceSeconds | 
|---|
|  |  |  | GameWorld.DebugLog("    启动新一轮放置探索!reduceSeconds=%s" % reduceSeconds) | 
|---|
|  |  |  | CostActivityPoint(curPlayer, costPoint) | 
|---|
|  |  |  | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceState, 1) | 
|---|
|  |  |  | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceStartTime, startTime) | 
|---|
|  |  |  | return True | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def GetActivityPlaceReward(curPlayer): | 
|---|
|  |  |  | ## 领取活跃放置奖励 | 
|---|
|  |  |  | 
|---|
|  |  |  | itemCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRewardItemCount % i) | 
|---|
|  |  |  | rewardItemInfo.append([itemID, itemCount]) | 
|---|
|  |  |  | placeInfo = ChPyNetSendPack.tagMCActivityPlaceInfo() | 
|---|
|  |  |  | placeInfo.PlaceState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceState) | 
|---|
|  |  |  | placeInfo.StartTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceStartTime) | 
|---|
|  |  |  | placeInfo.PlaceCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRemainCount) | 
|---|
|  |  |  | placeInfo.RewardCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRewardCount) | 
|---|
|  |  |  | placeInfo.RewardInfo = str(rewardItemInfo) | 
|---|
|  |  |  | placeInfo.RewardLen = len(placeInfo.RewardInfo) | 
|---|