| | |
| | | import ChConfig
|
| | | import ItemCommon
|
| | | import PlayerBillboard
|
| | | import QuestCommon
|
| | |
|
| | | Def_SuperLibType = 9 # 大奖库类型固定为9
|
| | |
|
| | | def OnPlayerLogin(curPlayer):
|
| | |
|
| | |
| | | # 活动中同步活动信息
|
| | | if actInfo.get(ShareDefine.ActKey_State):
|
| | | Sync_GarbageSortingActionInfo(curPlayer, actNum)
|
| | | Sync_GarbageSortingPlayerInfo(curPlayer, actNum)
|
| | | Sync_GarbageTaskInfo(curPlayer, actNum)
|
| | | return
|
| | |
|
| | |
| | | GameWorld.DebugLog("垃圾分类重置! actNum=%s,actID=%s,playerActID=%s,state=%s,cfgID=%s"
|
| | | % (actNum, actID, playerActID, state, cfgID), playerID)
|
| | |
|
| | | guideTaskID = IpyGameDataPY.GetFuncCfg("GarbageSorting", 1)
|
| | | if guideTaskID:
|
| | | if state:
|
| | | curMission = QuestCommon.AddNewMission(curPlayer, guideTaskID)
|
| | | if curMission:
|
| | | QuestCommon.SetPlayerMissionState(curPlayer, curMission, 1)
|
| | | else:
|
| | | QuestCommon.DeleteMission(curPlayer, guideTaskID)
|
| | | |
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageSortingID % actNum, actID)
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageSortingWorldLV % actNum, actWorldLV)
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageGuideState % actNum, 0)
|
| | | for taskID in ChConfig.GarbageTaskList:
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageTaskValue % (actNum, taskID), 0)
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageTaskFinishCount % (actNum, taskID), 0)
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageEnvironmentValue % actNum, 0)
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageEnvironmentValueHis % actNum, 0)
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageAwardLayerInfo % actNum, 0)
|
| | |
|
| | | ipyData = IpyGameDataPY.GetIpyGameData("ActGarbageSorting", cfgID) if cfgID else None
|
| | | templateID = ipyData.GetTemplateID() if ipyData else 0
|
| | | awardIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActGarbageAward", templateID) if templateID else []
|
| | | if awardIpyDataList:
|
| | | for awardIpyData in awardIpyDataList:
|
| | | libType = awardIpyData.GetAwardLibType()
|
| | | libItemCount = awardIpyData.GetAwardItemCount()
|
| | | for num in xrange(libItemCount):
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageAwardItemInfo % (actNum, libType, num), 0)
|
| | | |
| | | itemAwardTimesTotalInfo = awardIpyData.GetItemAwardTimesTotalInfo()
|
| | | for itemID in itemAwardTimesTotalInfo.keys():
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageAwardItemTimes % (actNum, libType, itemID), 0)
|
| | | |
| | | # 活动中,生成新奖池 |
| | | if state:
|
| | | __RefreshGarbageAwardPool(curPlayer, actInfo, awardIpyDataList)
|
| | | |
| | | # 清除垃圾背包物品、重置环保值
|
| | | ItemControler.ClearPack(curPlayer, ShareDefine.rptGarbage)
|
| | | PlayerControl.SetPlayerCurrency(curPlayer, ShareDefine.TYPE_Price_Environment, 0)
|
| | | |
| | | Sync_GarbageSortingActionInfo(curPlayer, actNum)
|
| | | Sync_GarbageSortingPlayerInfo(curPlayer, actNum)
|
| | | Sync_GarbageTaskInfo(curPlayer, actNum)
|
| | | return True
|
| | |
|
| | | def OnFinishTask(curPlayer, taskID):
|
| | | guideTaskID = IpyGameDataPY.GetFuncCfg("GarbageSorting", 1)
|
| | | if not guideTaskID:
|
| | | return
|
| | | |
| | | if taskID != guideTaskID:
|
| | | return
|
| | | |
| | | for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_GarbageSorting, {}).values():
|
| | | if not actInfo.get(ShareDefine.ActKey_State):
|
| | | continue
|
| | | actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageGuideState % actNum, 1)
|
| | | Sync_GarbageSortingPlayerInfo(curPlayer, actNum)
|
| | | |
| | | return
|
| | |
|
| | | def AddActGarbageTaskProgress(curPlayer, taskID, addValue=1, valueInfo=None):
|
| | | ## 增加垃圾收集任务进度
|
| | |
| | | if not addEnvValueTotal:
|
| | | return
|
| | |
|
| | | curEnvValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GarbageEnvironmentValue % actNum) + addEnvValueTotal
|
| | | hisEnvValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GarbageEnvironmentValueHis % actNum) + addEnvValueTotal
|
| | | PlayerControl.GiveMoney(curPlayer, ShareDefine.TYPE_Price_Environment, addEnvValueTotal)
|
| | | actEnvValueTotal = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GarbageEnvironmentValue % actNum) + addEnvValueTotal
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageEnvironmentValue % actNum, actEnvValueTotal) |
| | | GameWorld.DebugLog(" addEnvValueTotal=%s,actEnvValueTotal=%s,curEnvValue=%s" |
| | | % (addEnvValueTotal, actEnvValueTotal, PlayerControl.GetMoney(curPlayer, ShareDefine.TYPE_Price_Environment)), playerID)
|
| | |
|
| | | GameWorld.DebugLog(" addEnvValueTotal=%s,curEnvValue=%s,hisEnvValue=%s" % (addEnvValueTotal, curEnvValue, hisEnvValue), playerID)
|
| | | |
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageEnvironmentValue % actNum, curEnvValue)
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageEnvironmentValueHis % actNum, hisEnvValue)
|
| | | |
| | | PlayerBillboard.UpdatePlayerBillboard(curPlayer, ShareDefine.Def_BT_Environment, hisEnvValue)
|
| | | |
| | | Sync_GarbageSortingPlayerInfo(curPlayer, actNum)
|
| | | PlayerBillboard.UpdatePlayerBillboard(curPlayer, ShareDefine.Def_BT_Environment, actEnvValueTotal)
|
| | | return
|
| | |
|
| | |
|
| | |
| | | actNum = clientData.ActNum
|
| | | taskID = clientData.GarbageTaskID
|
| | | __DoCheckFinishGarbageTask(curPlayer, actNum, taskID)
|
| | | return
|
| | |
|
| | |
|
| | | #// AA 16 垃圾分类活动选择大奖 #tagCMActGarbageChooseSuperItem
|
| | | #
|
| | | #struct tagCMActGarbageChooseSuperItem
|
| | | #{
|
| | | # tagHead Head;
|
| | | # BYTE ActNum; //活动编号
|
| | | # BYTE SuperItemCount; //选择物品数量
|
| | | # DWORD SuperItemIDList[SuperItemCount]; //选择的大奖库物品ID列表,每次重新选择需要发送全部已选择的大奖物品ID,不能只发单个物品ID;
|
| | | #};
|
| | | def OnActGarbageChooseSuperItem(index, clientData, tick):
|
| | | curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
|
| | | actNum = clientData.ActNum
|
| | | superItemIDList = clientData.SuperItemIDList
|
| | | |
| | | GameWorld.DebugLog("垃圾分类活动选择大奖: actNum=%s,superItemIDList=%s" % (actNum, superItemIDList))
|
| | | |
| | | actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_GarbageSorting, actNum)
|
| | | if not actInfo.get(ShareDefine.ActKey_State):
|
| | | return
|
| | | |
| | | cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
|
| | | ipyData = IpyGameDataPY.GetIpyGameData("ActGarbageSorting", cfgID)
|
| | | if not ipyData:
|
| | | return
|
| | | |
| | | templateID = ipyData.GetTemplateID()
|
| | | if not templateID:
|
| | | return
|
| | | |
| | | actWorldLV = actInfo.get(ShareDefine.ActKey_WorldLV, 0)
|
| | | awardIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActGarbageAward", templateID)
|
| | | if not awardIpyDataList:
|
| | | return
|
| | | |
| | | superAwardIpyData = None
|
| | | for awardIpyData in awardIpyDataList:
|
| | | libType = awardIpyData.GetAwardLibType()
|
| | | if libType == Def_SuperLibType:
|
| | | superAwardIpyData = awardIpyData
|
| | | break
|
| | | |
| | | if not superAwardIpyData:
|
| | | GameWorld.ErrLog("没有配置垃圾分类活动大奖库! cfgID=%s,actNum=%s,templateID=%s" % (cfgID, actNum, templateID))
|
| | | return
|
| | | |
| | | superLibItemCount = superAwardIpyData.GetAwardItemCount()
|
| | | if len(superItemIDList) != superLibItemCount:
|
| | | GameWorld.ErrLog("垃圾分类活动选择大奖个数错误! cfgID=%s,actNum=%s,templateID=%s,superLibItemCount=%s,reqSuperItemIDList=%s" |
| | | % (cfgID, actNum, templateID, superLibItemCount, superItemIDList)) |
| | | return
|
| | | |
| | | posNumItemIDList = [] # 已抽中的大奖物品ID
|
| | | libType = superAwardIpyData.GetAwardLibType()
|
| | | for num in xrange(superLibItemCount):
|
| | | itemInfoValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GarbageAwardItemInfo % (actNum, libType, num))
|
| | | if not itemInfoValue:
|
| | | break
|
| | | itemID, posNum = itemInfoValue / 100, itemInfoValue % 100
|
| | | if posNum and itemID not in superItemIDList:
|
| | | GameWorld.ErrLog("垃圾分类活动选择大奖ID错误! 已抽中的大奖ID为必选ID! posNum=%s, itemID=%s not in superItemIDList=%s" |
| | | % (posNum, itemID, superItemIDList))
|
| | | return
|
| | | |
| | | if posNum:
|
| | | posNumItemIDList.append(itemID)
|
| | | |
| | | GameWorld.DebugLog(" 已抽中的大奖ID! %s" % posNumItemIDList)
|
| | | |
| | | layerInfoValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GarbageAwardLayerInfo % actNum)
|
| | | layerNum = layerInfoValue % 100
|
| | | |
| | | libItemDict = __GetGarbageAwardLibItem(superAwardIpyData.GetLibItemInfo(), actWorldLV)
|
| | | layerLimitInfo = superAwardIpyData.GetItemLayerLimitInfo()
|
| | | awardTimesTotalInfo = superAwardIpyData.GetItemAwardTimesTotalInfo()
|
| | | |
| | | replaceSuperItemIDList = [] # 需要替换的大奖ID列表
|
| | | |
| | | for selectItemID in superItemIDList:
|
| | | if selectItemID in posNumItemIDList:
|
| | | GameWorld.DebugLog(" 已抽中的大奖ID,不验证!selectItemID=%s" % (selectItemID))
|
| | | continue
|
| | | |
| | | if selectItemID not in libItemDict:
|
| | | GameWorld.ErrLog("垃圾分类活动选择大奖ID错误! 大奖ID不存在大奖库中! selectItemID=%s not in libItemDict=%s" |
| | | % (selectItemID, libItemDict))
|
| | | return
|
| | | |
| | | layerLimit = layerLimitInfo.get(selectItemID, 0)
|
| | | if layerLimit > layerNum:
|
| | | GameWorld.ErrLog("垃圾分类活动选择大奖ID错误! 大奖ID该层不能选择! selectItemID=%s layerLimit(%s) > layerNum(%s)" |
| | | % (selectItemID, layerLimit, layerNum))
|
| | | return
|
| | | |
| | | totalTimesLimit = awardTimesTotalInfo.get(selectItemID, 0)
|
| | | if totalTimesLimit:
|
| | | totalTimesNow = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GarbageAwardItemTimes % (actNum, libType, selectItemID))
|
| | | if totalTimesNow >= totalTimesLimit:
|
| | | GameWorld.ErrLog("垃圾分类活动选择大奖ID错误! 大奖ID已达到最大奖励次数,不能选择! selectItemID=%s totalTimesNow(%s) >= totalTimesLimit(%s)" |
| | | % (selectItemID, totalTimesNow, totalTimesLimit))
|
| | | return
|
| | | |
| | | replaceSuperItemIDList.append(selectItemID)
|
| | | |
| | | GameWorld.DebugLog(" 验证通过,可替换大奖ID! replaceSuperItemIDList=%s" % replaceSuperItemIDList)
|
| | | if not replaceSuperItemIDList:
|
| | | return
|
| | | |
| | | for num in xrange(superLibItemCount):
|
| | | itemInfoValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GarbageAwardItemInfo % (actNum, libType, num))
|
| | | itemID, posNum = itemInfoValue / 100, itemInfoValue % 100
|
| | | if itemID in posNumItemIDList:
|
| | | GameWorld.DebugLog(" 已抽中的大奖ID,不替换!itemID=%s" % (itemID))
|
| | | continue
|
| | | replaceSuperItemID = replaceSuperItemIDList.pop(0)
|
| | | updItemInfoValue = replaceSuperItemID * 100 + posNum
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageAwardItemInfo % (actNum, libType, num), updItemInfoValue)
|
| | | GameWorld.DebugLog(" 替换大奖ID选择!num=%s,itemID=%s,posNum=%s,replaceSuperItemID=%s,updItemInfoValue=%s" |
| | | % (num, itemID, posNum, replaceSuperItemID, updItemInfoValue))
|
| | | |
| | | if not replaceSuperItemIDList:
|
| | | break
|
| | | |
| | | Sync_GarbageSortingActionInfo(curPlayer, actNum)
|
| | | return
|
| | |
|
| | | #// AA 18 垃圾分类活动奖池刷新 #tagCMGarbageAwardPoolRefresh
|
| | | #
|
| | | #struct tagCMGarbageAwardPoolRefresh
|
| | | #{
|
| | | # tagHead Head;
|
| | | # BYTE ActNum; //活动编号
|
| | | #};
|
| | | def OnActGarbageAwardPoolRefresh(index, clientData, tick):
|
| | | curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
|
| | | actNum = clientData.ActNum
|
| | | |
| | | GameWorld.DebugLog("垃圾分类活动奖池刷新: actNum=%s" % (actNum))
|
| | | |
| | | actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_GarbageSorting, actNum)
|
| | | if not actInfo.get(ShareDefine.ActKey_State):
|
| | | return
|
| | | |
| | | cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
|
| | | ipyData = IpyGameDataPY.GetIpyGameData("ActGarbageSorting", cfgID)
|
| | | if not ipyData:
|
| | | return
|
| | | |
| | | templateID = ipyData.GetTemplateID()
|
| | | if not templateID:
|
| | | return
|
| | | |
| | | awardIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActGarbageAward", templateID)
|
| | | if not awardIpyDataList:
|
| | | return
|
| | | |
| | | if not __RefreshGarbageAwardPool(curPlayer, actInfo, awardIpyDataList):
|
| | | return
|
| | | |
| | | Sync_GarbageSortingActionInfo(curPlayer, actNum)
|
| | | return
|
| | |
|
| | | def __RefreshGarbageAwardPool(curPlayer, actInfo, awardIpyDataList):
|
| | | ## 刷新垃圾收集环保奖池物品
|
| | | |
| | | cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
|
| | | actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
|
| | | actWorldLV = actInfo.get(ShareDefine.ActKey_WorldLV, 0)
|
| | | |
| | | layerInfoValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GarbageAwardLayerInfo % actNum)
|
| | | layerNum = layerInfoValue % 100
|
| | | |
| | | GameWorld.DebugLog("刷新垃圾收集环保奖池物品: cfgID=%s,actNum=%s,actWorldLV=%s,layerNum=%s" % (cfgID, actNum, actWorldLV, layerNum))
|
| | | |
| | | if layerNum:
|
| | | # 非0层,验证大奖是否已抽完,抽完才可以刷新奖池层
|
| | | superLib = False
|
| | | for awardIpyData in awardIpyDataList:
|
| | | libType = awardIpyData.GetAwardLibType()
|
| | | if libType != Def_SuperLibType:
|
| | | continue
|
| | | superLib = True
|
| | | libItemCount = awardIpyData.GetAwardItemCount()
|
| | | for num in xrange(libItemCount):
|
| | | itemInfoValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GarbageAwardItemInfo % (actNum, libType, num))
|
| | | itemID, posNum = itemInfoValue / 100, itemInfoValue % 100
|
| | | if itemID and not posNum:
|
| | | GameWorld.ErrLog("有大奖未抽中!无法刷新环保奖池! cfgID=%s,actNum=%s,layerNum=%s,num=%s,itemID=%s,posNum=%s" |
| | | % (cfgID, actNum, layerNum, num, itemID, posNum))
|
| | | return
|
| | | break
|
| | | if not superLib:
|
| | | GameWorld.ErrLog("奖池配置没有大奖库!无法刷新环保奖池! cfgID=%s,actNum=%s,layerNum=%s,superLib=%s" % (cfgID, actNum, layerNum, superLib))
|
| | | return
|
| | | |
| | | layerNum += 1 # 可刷新奖池,默认+1层
|
| | | GameWorld.DebugLog(" 可刷新奖池!下一层: layerNum=%s" % (layerNum))
|
| | | |
| | | refreshLibDict = {}
|
| | | for awardIpyData in awardIpyDataList:
|
| | | libType = awardIpyData.GetAwardLibType()
|
| | | libItemCount = awardIpyData.GetAwardItemCount()
|
| | | libItemDict = __GetGarbageAwardLibItem(awardIpyData.GetLibItemInfo(), actWorldLV)
|
| | | layerLimitInfo = awardIpyData.GetItemLayerLimitInfo()
|
| | | awardTimesTotalInfo = awardIpyData.GetItemAwardTimesTotalInfo()
|
| | | |
| | | canRandItemDict = {}
|
| | | for itemID, libItemInfo in libItemDict.items():
|
| | | _, weight = libItemInfo
|
| | | |
| | | layerLimit = layerLimitInfo.get(itemID, 0)
|
| | | if layerLimit > layerNum:
|
| | | GameWorld.DebugLog(" 该层不能选择该奖品! itemID=%s layerLimit(%s) > layerNum(%s)" |
| | | % (itemID, layerLimit, layerNum))
|
| | | continue
|
| | | |
| | | totalTimesLimit = awardTimesTotalInfo.get(itemID, 0)
|
| | | if totalTimesLimit:
|
| | | totalTimesNow = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GarbageAwardItemTimes % (actNum, libType, itemID))
|
| | | if totalTimesNow >= totalTimesLimit:
|
| | | GameWorld.DebugLog(" 奖品ID已达到最大奖励次数,不能选择! itemID=%s totalTimesNow(%s) >= totalTimesLimit(%s)" |
| | | % (itemID, totalTimesNow, totalTimesLimit))
|
| | | continue
|
| | | |
| | | canRandItemDict[itemID] = [weight, itemID]
|
| | | |
| | | if libItemCount > len(canRandItemDict):
|
| | | GameWorld.ErrLog("奖品库配置可选择奖品个数不够!无法刷新环保奖池! cfgID=%s,actNum=%s,libType=%s,layerNum=%s,libItemCount=%s > %s canRandItemDict(%s)" |
| | | % (cfgID, actNum, libType, layerNum, libItemCount, len(canRandItemDict), canRandItemDict))
|
| | | return
|
| | | |
| | | refreshLibDict[libType] = [libItemCount, canRandItemDict]
|
| | | |
| | | for libType, refreshInfo in refreshLibDict.items():
|
| | | libItemCount, canRandItemDict = refreshInfo
|
| | | GameWorld.DebugLog(" 随机奖池物品: libType=%s,libItemCount=%s,canRandItemDict=%s, %s" % (libType, libItemCount, len(canRandItemDict), canRandItemDict))
|
| | | |
| | | if libType == Def_SuperLibType:
|
| | | # 大奖直接重置,系统不生成,由玩家手动选择
|
| | | for num in xrange(libItemCount):
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageAwardItemInfo % (actNum, libType, num), 0)
|
| | | continue
|
| | | |
| | | for num in xrange(libItemCount):
|
| | | weightList = canRandItemDict.values()
|
| | | randItemID = GameWorld.GetResultByWeightList(weightList)
|
| | | canRandItemDict.pop(randItemID, None)
|
| | | |
| | | posNum = 0
|
| | | itemInfoValue = randItemID * 100 + posNum
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageAwardItemInfo % (actNum, libType, num), itemInfoValue)
|
| | | GameWorld.DebugLog(" 随机生成奖品! libType=%s,num=%s,randItemID=%s" % (libType, num, randItemID))
|
| | | |
| | | playCount = 0 # 每层重置抽奖次数
|
| | | layerInfoValue = playCount * 100 + layerNum
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageAwardLayerInfo % actNum, layerInfoValue)
|
| | | GameWorld.DebugLog(" 刷新完成! playCount=%s,layerNum=%s,layerInfoValue=%s" % (playCount, layerNum, layerInfoValue))
|
| | | return True
|
| | |
|
| | | #// AA 17 垃圾分类活动抽奖 #tagCMActGarbageLottery
|
| | | #
|
| | | #struct tagCMActGarbageLottery
|
| | | #{
|
| | | # tagHead Head;
|
| | | # BYTE ActNum; //活动编号
|
| | | # BYTE PosNum; //玩家点击的奖励位置编号,从1开始
|
| | | #};
|
| | | def OnActGarbageLottery(index, clientData, tick):
|
| | | curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
|
| | | actNum = clientData.ActNum
|
| | | reqPosNum = clientData.PosNum
|
| | | |
| | | GameWorld.DebugLog("垃圾分类活动抽奖: actNum=%s,reqPosNum=%s" % (actNum, reqPosNum))
|
| | | |
| | | if reqPosNum <= 0:
|
| | | return
|
| | | |
| | | actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_GarbageSorting, actNum)
|
| | | if not actInfo.get(ShareDefine.ActKey_State):
|
| | | return
|
| | | |
| | | cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
|
| | | ipyData = IpyGameDataPY.GetIpyGameData("ActGarbageSorting", cfgID)
|
| | | if not ipyData:
|
| | | return
|
| | | |
| | | templateID = ipyData.GetTemplateID()
|
| | | if not templateID:
|
| | | return
|
| | | |
| | | actWorldLV = actInfo.get(ShareDefine.ActKey_WorldLV, 0)
|
| | | awardIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActGarbageAward", templateID)
|
| | | if not awardIpyDataList:
|
| | | return
|
| | | |
| | | costEnvValue = IpyGameDataPY.GetFuncCfg("GarbageSorting", 3)
|
| | | curEnvValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GarbageEnvironmentValue % actNum)
|
| | | if curEnvValue < costEnvValue:
|
| | | GameWorld.DebugLog(" 环保值不足,无法抽奖! curEnvValue(%s) < costEnvValue(%s)" % (curEnvValue, costEnvValue))
|
| | | return
|
| | | |
| | | layerInfoValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GarbageAwardLayerInfo % actNum)
|
| | | playCount, layerNum = layerInfoValue / 100, layerInfoValue % 100
|
| | | |
| | | posNumMax = 0
|
| | | randLibItemDict = {}
|
| | | for awardIpyData in awardIpyDataList:
|
| | | libType = awardIpyData.GetAwardLibType()
|
| | | libItemCount = awardIpyData.GetAwardItemCount()
|
| | | unlockLimitTimes = awardIpyData.GetUnlockAwardLimitTimes()
|
| | | libWeight = awardIpyData.GetAwardLibWeight()
|
| | | posNumMax += libItemCount
|
| | | |
| | | if libType == Def_SuperLibType:
|
| | | for num in xrange(libItemCount):
|
| | | itemInfoValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GarbageAwardItemInfo % (actNum, libType, num))
|
| | | if not itemInfoValue:
|
| | | GameWorld.DebugLog(" 未选择大奖!无法抽奖! libType=%s,num=%s,itemInfoValue=%s" % (libType, num, itemInfoValue)) |
| | | return
|
| | | |
| | | if unlockLimitTimes and playCount < unlockLimitTimes:
|
| | | GameWorld.DebugLog(" 该库当前抽奖次数无法解锁! libType=%s,playCount(%s) < unlockLimitTimes(%s)" % (libType, playCount, unlockLimitTimes))
|
| | | continue
|
| | | |
| | | awardTimesTotalInfo = awardIpyData.GetItemAwardTimesTotalInfo()
|
| | | libItemDict = __GetGarbageAwardLibItem(awardIpyData.GetLibItemInfo(), actWorldLV)
|
| | | canRandItemList = []
|
| | | for num in xrange(libItemCount):
|
| | | itemInfoValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GarbageAwardItemInfo % (actNum, libType, num))
|
| | | if not itemInfoValue: |
| | | return
|
| | | |
| | | itemID, posNum = itemInfoValue / 100, itemInfoValue % 100
|
| | | if itemID not in libItemDict:
|
| | | continue
|
| | | |
| | | if posNum:
|
| | | GameWorld.DebugLog(" 该奖品已被抽中! libType=%s,itemID=%s,posNum=%s" % (libType, itemID, posNum))
|
| | | if posNum == reqPosNum:
|
| | | GameWorld.ErrLog(" 该位置已经有抽奖结果,无法重复选择抽奖! libType=%s,num=%s,itemInfoValue=%s,posNum=%s" |
| | | % (libType, num, itemInfoValue, posNum)) |
| | | return |
| | | continue
|
| | | |
| | | itemCount, weight = libItemDict[itemID]
|
| | | isAddTimes = (itemID in awardTimesTotalInfo)
|
| | | canRandItemList.append([weight, itemID, itemCount, num, isAddTimes])
|
| | | |
| | | if canRandItemList:
|
| | | randLibItemDict[libType] = [libWeight, libType, canRandItemList]
|
| | | GameWorld.DebugLog(" 该库有机会抽到物品: libType=%s,libWeight=%s,canRandItemList=%s" % (libType, libWeight, canRandItemList))
|
| | | else:
|
| | | GameWorld.DebugLog(" 该库物品已全被抽完: libType=%s,libWeight=%s,canRandItemList=%s" % (libType, libWeight, canRandItemList))
|
| | | |
| | | if reqPosNum > posNumMax:
|
| | | GameWorld.DebugLog(" 请求位置异常,无法抽奖! reqPosNum(%s) > posNumMax(%s)" % (reqPosNum, posNumMax))
|
| | | return
|
| | | |
| | | if not randLibItemDict:
|
| | | GameWorld.DebugLog(" 没有可抽奖的奖品了,无法抽奖!")
|
| | | return
|
| | | |
| | | randLibInfo = GameWorld.GetResultByWeightList(randLibItemDict.values())
|
| | | if not randLibInfo:
|
| | | return
|
| | | libType, canRandItemList = randLibInfo
|
| | | randItemInfo = GameWorld.GetResultByWeightList(canRandItemList)
|
| | | if not randItemInfo:
|
| | | return
|
| | | itemID, itemCount, num, isAddTimes = randItemInfo
|
| | | |
| | | # 扣除抽奖消耗环保值
|
| | | updEnvValue = curEnvValue - costEnvValue
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageEnvironmentValue % actNum, updEnvValue)
|
| | | |
| | | # 更新已抽中值
|
| | | updItemInfoValue = itemID * 100 + reqPosNum
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageAwardItemInfo % (actNum, libType, num), updItemInfoValue)
|
| | | |
| | | totalTimesNow = 0
|
| | | if isAddTimes:
|
| | | totalTimesNow = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GarbageAwardItemTimes % (actNum, libType, itemID)) + 1
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageAwardItemTimes % (actNum, libType, itemID), totalTimesNow)
|
| | | |
| | | playCount += 1
|
| | | layerInfoValue = playCount * 100 + layerNum
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GarbageAwardLayerInfo % actNum, layerInfoValue)
|
| | | |
| | | GameWorld.DebugLog(" 抽中物品: layerNum=%s,libType=%s,itemID=%s,itemCount=%s,num=%s,reqPosNum=%s,updItemInfoValue=%s,totalTimesNow=%s,updEnvValue=%s,playCount=%s(%s)" |
| | | % (layerNum, libType, itemID, itemCount, num, reqPosNum, updItemInfoValue, totalTimesNow, updEnvValue, playCount, layerInfoValue))
|
| | | |
| | | # 给物品
|
| | | isAuctionItem = 0
|
| | | itemList = [[itemID, itemCount, isAuctionItem]]
|
| | | ItemControler.GivePlayerItemOrMail(curPlayer, itemList, event=["ActGarbageLottery", False, {}])
|
| | | |
| | | # 广播
|
| | | if libType == Def_SuperLibType:
|
| | | PlayerControl.WorldNotify(0, "GarbageSorting%s" % actNum, [curPlayer.GetPlayerName(), itemID, itemCount])
|
| | | |
| | | # ֪ͨ
|
| | | awardItemInfo = [libType, itemID, itemCount, reqPosNum, totalTimesNow]
|
| | | Sync_GarbageSortingPlayerInfo(curPlayer, actNum, awardItemInfo)
|
| | | return
|
| | |
|
| | | def Sync_GarbageTaskInfo(curPlayer, actNum, taskID=0, awardItemList=None):
|
| | |
| | | NetPackCommon.SendFakePack(curPlayer, clientPack)
|
| | | return
|
| | |
|
| | | def Sync_GarbageSortingPlayerInfo(curPlayer, actNum, awardItemInfo=None):
|
| | | ## 通知玩家数据信息
|
| | | # @param awardItemInfo: 抽奖物品信息 [libType, itemID, itemCount, posNum, totalTimesNow]
|
| | | |
| | | actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_GarbageSorting, actNum)
|
| | | if not actInfo.get(ShareDefine.ActKey_State):
|
| | | return
|
| | | |
| | | cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
|
| | | ipyData = IpyGameDataPY.GetIpyGameData("ActGarbageSorting", cfgID)
|
| | | if not ipyData:
|
| | | return
|
| | | |
| | | guideTaskID = IpyGameDataPY.GetFuncCfg("GarbageSorting", 1)
|
| | | |
| | | clientPack = ChPyNetSendPack.tagMCActGarbagePlayerInfo()
|
| | | clientPack.ActNum = actNum
|
| | | clientPack.GuideTaskFinish = 1 if not guideTaskID else curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GarbageGuideState % actNum)
|
| | | clientPack.EnvironmentValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GarbageEnvironmentValue % actNum)
|
| | | clientPack.EnvironmentValueHis = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GarbageEnvironmentValueHis % actNum)
|
| | | |
| | | if awardItemInfo:
|
| | | libType, itemID, itemCount, posNum, totalTimesNow = awardItemInfo
|
| | | awardItem = ChPyNetSendPack.tagMCActGarbageAwardItemResult()
|
| | | awardItem.ItemLibType = libType
|
| | | awardItem.ItemID = itemID
|
| | | awardItem.ItemCount = itemCount
|
| | | awardItem.PosNum = posNum
|
| | | awardItem.TotalTimesNow = totalTimesNow
|
| | | clientPack.AwardItemResult = awardItem
|
| | | NetPackCommon.SendFakePack(curPlayer, clientPack)
|
| | | return
|
| | |
|
| | | def Sync_GarbageSortingActionInfo(curPlayer, actNum):
|
| | | ## 通知活动信息
|
| | |
|
| | |
| | | if not ipyData:
|
| | | return
|
| | |
|
| | | templateID = ipyData.GetTemplateID()
|
| | | if not templateID:
|
| | | return
|
| | | |
| | | actWorldLV = actInfo.get(ShareDefine.ActKey_WorldLV, 0)
|
| | | openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay) + 1
|
| | | |
| | | layerInfoValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GarbageAwardLayerInfo % actNum)
|
| | | layerNum = layerInfoValue % 100
|
| | | |
| | | clientPack = ChPyNetSendPack.tagMCActGarbageSortingInfo()
|
| | | clientPack.ActNum = actNum
|
| | | clientPack.StartDate = GameWorld.GetOperationActionDateStr(ipyData.GetStartDate(), openServerDay)
|
| | | clientPack.EndtDate = GameWorld.GetOperationActionDateStr(ipyData.GetEndDate(), openServerDay)
|
| | | clientPack.LimitLV = ipyData.GetLVLimit()
|
| | | clientPack.LayerNum = layerNum
|
| | | clientPack.AwardItemList = [] # 奖池物品列表
|
| | | awardIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActGarbageAward", templateID)
|
| | | if awardIpyDataList:
|
| | | for awardIpyData in awardIpyDataList:
|
| | | libType = awardIpyData.GetAwardLibType()
|
| | | libItemCount = awardIpyData.GetAwardItemCount()
|
| | | libItemDict = __GetGarbageAwardLibItem(awardIpyData.GetLibItemInfo(), actWorldLV)
|
| | | layerLimitInfo = awardIpyData.GetItemLayerLimitInfo()
|
| | | awardTimesTotalInfo = awardIpyData.GetItemAwardTimesTotalInfo()
|
| | | |
| | | # 奖池物品列表,已生成的,包含已选择的大奖物品
|
| | | for num in xrange(libItemCount):
|
| | | itemInfoValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GarbageAwardItemInfo % (actNum, libType, num))
|
| | | if not itemInfoValue:
|
| | | break
|
| | | itemID, posNum = itemInfoValue / 100, itemInfoValue % 100
|
| | | if itemID not in libItemDict:
|
| | | continue
|
| | | libItemInfo = libItemDict[itemID]
|
| | | |
| | | awardItem = ChPyNetSendPack.tagMCActGarbageAwardItem()
|
| | | awardItem.ItemLibType = libType
|
| | | awardItem.ItemID = itemID
|
| | | awardItem.ItemCount = libItemInfo[0]
|
| | | awardItem.PosNum = posNum
|
| | | awardItem.TotalTimesMax = awardTimesTotalInfo.get(itemID, 0)
|
| | | awardItem.TotalTimesNow = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GarbageAwardItemTimes % (actNum, libType, itemID))
|
| | | awardItem.LayerLimit = layerLimitInfo.get(itemID, 0)
|
| | | clientPack.AwardItemList.append(awardItem)
|
| | | |
| | | # 大奖物品待选择库,全部同步
|
| | | if libType == Def_SuperLibType:
|
| | | for itemID, libItemInfo in libItemDict.items():
|
| | | awardItem = ChPyNetSendPack.tagMCActGarbageAwardItem()
|
| | | awardItem.ItemLibType = libType
|
| | | awardItem.ItemID = itemID
|
| | | awardItem.ItemCount = libItemInfo[0]
|
| | | awardItem.TotalTimesMax = awardTimesTotalInfo.get(itemID, 0)
|
| | | awardItem.LayerLimit = layerLimitInfo.get(itemID, 0)
|
| | | clientPack.SuperItemList.append(awardItem)
|
| | | clientPack.SuperItemCount = len(clientPack.SuperItemList)
|
| | | clientPack.SuperItemCanChooseCount = libItemCount
|
| | | |
| | | clientPack.AwardItemCount = len(clientPack.AwardItemList)
|
| | | clientPack.ResetType = ipyData.GetResetType()
|
| | | NetPackCommon.SendFakePack(curPlayer, clientPack)
|
| | | return
|
| | |
|
| | | def __GetGarbageAwardLibItem(libItemInfo, actWorldLV):
|
| | | ## 获取奖励库物品信息字典,支持按世界等级范围配置的格式
|
| | | keyList = libItemInfo.keys()
|
| | | if not keyList:
|
| | | return {}
|
| | | if isinstance(keyList[0], tuple) and len(keyList[0]) == 2:
|
| | | return GameWorld.GetDictValueByRangeKey(libItemInfo, actWorldLV, {})
|
| | | return libItemInfo
|
| | |
|