#!/usr/bin/python # -*- coding: GBK -*- #------------------------------------------------------------------------------- # ##@package Player.PlayerZhanling # # @todo:Õ½Áî # @author hxp # @date 2023-12-05 # @version 1.0 # # ÏêϸÃèÊö: Õ½Áî # #------------------------------------------------------------------------------- #"""Version = 2023-12-05 15:30""" #------------------------------------------------------------------------------- import GameWorld import ShareDefine import NetPackCommon import IpyGameDataPY import PlayerControl import ChPyNetSendPack import PlayerGatherTheSoul import PlayerActHorsePetTrain import PlayerActGubao import ItemControler import IPY_GameWorld import PlayerGubao import ChConfig import time # Õ½ÁîÀàÐÍ ZhanlingTypeList = ( ZhanlingType_LV, # µÈ¼¶ 1 ZhanlingType_Realm, # ¾³½ç 2 ZhanlingType_SkyTower, # ÌìÐÇËþ 3 ZhanlingType_GubaoStar, # ¹Å±¦×ÜÐÇÊý 4 ZhanlingType_Login, # µÇ¼ 5 ZhanlingType_GatherTheSoulLV, # ¾Û»ê 6 ZhanlingType_HorsePetTrain, # Æï³èÑø³É 7 ZhanlingType_GubaoTrain, # ¹Å±¦Ñø³É 8 ZhanlingType_Xianyuan, # ÏÉÔµ 9 ZhanlingType_Huanjingge, # »Ã¾³¸ó 10 ) = range(1, 1 + 10) def OnPlayerLogin(curPlayer): for zhanlingType in ZhanlingTypeList: if zhanlingType == ZhanlingType_Login: value1 = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ZhanlingValue1 % zhanlingType) if not value1: firstLoginTime = int(time.time()) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ZhanlingValue1 % zhanlingType, firstLoginTime) GameWorld.DebugLog("ÉèÖõǼսÁîÊ״εǼʱ¼ä: %s" % firstLoginTime, curPlayer.GetPlayerID()) SyncZhanlingInfo(curPlayer, zhanlingType) return def OnActiviteByCTGID(curPlayer, ctgID): zhanlingCTGIDDict = IpyGameDataPY.GetFuncEvalCfg("Zhanling", 1) for zhanlingTypeStr, ctgIDList in zhanlingCTGIDDict.items(): if ctgID not in ctgIDList: continue zhanlingType = int(zhanlingTypeStr) state = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ZhanlingState) if state&pow(2, zhanlingType): break updState = state|pow(2, zhanlingType) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ZhanlingState, updState) SyncZhanlingInfo(curPlayer, zhanlingType) GameWorld.Log("¼¤»îÕ½ÁîÆÕͨ: zhanlingType=%s,updState=%s" % (zhanlingType, updState), curPlayer.GetPlayerID()) break # ¸ß¼¶Õ½Áî zhanlingCTGIDDictH = IpyGameDataPY.GetFuncEvalCfg("Zhanling", 3) for zhanlingTypeStr, ctgIDList in zhanlingCTGIDDictH.items(): if ctgID not in ctgIDList: continue zhanlingType = int(zhanlingTypeStr) state = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ZhanlingStateH) if state&pow(2, zhanlingType): break updState = state|pow(2, zhanlingType) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ZhanlingStateH, updState) SyncZhanlingInfo(curPlayer, zhanlingType) GameWorld.Log("¼¤»îÕ½Áî¸ß¼¶: zhanlingType=%s,updState=%s" % (zhanlingType, updState), curPlayer.GetPlayerID()) break return def ResetZhanling(curPlayer, zhanlingType, backValue=None): ''' ÖØÖÃÕ½Áî @param zhanlingType: Õ½ÁîÀàÐÍ @param backValue: ÖØÖÃÕ½ÁîʱµÄÕ½Áî½±ÀøÖµ£¬ÓÃÓÚ·µ»¹Î´ÁìÈ¡½±Àø ''' state = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ZhanlingState) stateH = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ZhanlingStateH) updState = GameWorld.SetBitValue(state, zhanlingType, 0) updStateH = GameWorld.SetBitValue(stateH, zhanlingType, 0) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ZhanlingState, updState) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ZhanlingStateH, updStateH) if zhanlingType == ZhanlingType_Xianyuan: backValue = PlayerControl.GetMoney(curPlayer, ShareDefine.TYPE_Price_XianyuanScore) PlayerControl.SetMoney(curPlayer, ShareDefine.TYPE_Price_XianyuanScore, 0) GameWorld.Log("ÖØÖÃÕ½Áî: zhanlingType=%s,backValue=%s,state=(%s to %s) stateH=(%s to %s)" % (zhanlingType, backValue, state, updState, stateH, updStateH), curPlayer.GetPlayerID()) if backValue: __giveUngetAward(curPlayer, zhanlingType, backValue, state&pow(2, zhanlingType), stateH&pow(2, zhanlingType)) for keyNum in range(10): PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ZhanlingReward % (zhanlingType, keyNum), 0) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ZhanlingRewardH % (zhanlingType, keyNum), 0) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ZhanlingRewardFree % (zhanlingType, keyNum), 0) SyncZhanlingInfo(curPlayer, zhanlingType) return def __giveUngetAward(curPlayer, zhanlingType, backValue, activeState, activeStateH): ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition("Zhanling", {"ZhanlingType":zhanlingType}, True) if not ipyDataList: return if not backValue: return playerID = curPlayer.GetPlayerID() GameWorld.DebugLog("´¦ÀíÕ½ÁîÖØÖò¹·¢½±Àø: zhanlingType=%s,backValue=%s,activeState=%s,activeStateH=%s" % (zhanlingType, backValue, activeState, activeStateH), playerID) ungetItemDict = {} for ipyData in ipyDataList: needValue = ipyData.GetNeedValue() rewardIndex = ipyData.GetRewardIndex() if backValue < needValue: break if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ZhanlingRewardFree, rewardIndex, True, [zhanlingType]): rewardItemList = ipyData.GetFreeRewardItemList() for itemID, itemCount, _ in rewardItemList: ungetItemDict[itemID] = ungetItemDict.get(itemID, 0) + itemCount GameWorld.DebugLog(" Õ½Áî²¹·¢Ãâ·Ñ½±Àø: rewardIndex=%s,needValue=%s,%s, %s" % (rewardIndex, needValue, rewardItemList, ungetItemDict), playerID) if activeState and not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ZhanlingReward, rewardIndex, True, [zhanlingType]): rewardItemList = ipyData.GetZLRewardItemList() for itemID, itemCount, _ in rewardItemList: ungetItemDict[itemID] = ungetItemDict.get(itemID, 0) + itemCount GameWorld.DebugLog(" Õ½Áî²¹·¢ÆÕͨ½±Àø: rewardIndex=%s,needValue=%s,%s, %s" % (rewardIndex, needValue, rewardItemList, ungetItemDict), playerID) if activeStateH and not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ZhanlingRewardH, rewardIndex, True, [zhanlingType]): rewardItemList = ipyData.GetZLRewardItemListH() for itemID, itemCount, _ in rewardItemList: ungetItemDict[itemID] = ungetItemDict.get(itemID, 0) + itemCount GameWorld.DebugLog(" Õ½Áî²¹·¢¸ß¼¶½±Àø: rewardIndex=%s,needValue=%s,%s, %s" % (rewardIndex, needValue, rewardItemList, ungetItemDict), playerID) if not ungetItemDict: return paramList = [zhanlingType] itemList = [] for itemID, itemCount in ungetItemDict.items(): itemList.append([itemID, itemCount, 0]) GameWorld.DebugLog(" Õ½Áî²¹·¢½±Àø»ã×Ü: %s, %s" % (itemList, ungetItemDict), playerID) PlayerControl.SendMailByKey("ZhanlingRewardUnget", [playerID], itemList, paramList) return def AddZhanlingValue(curPlayer, zhanlingType, addValue=1): if zhanlingType not in [ZhanlingType_Huanjingge]: return curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ZhanlingValue1 % zhanlingType) updValue = min(ChConfig.Def_UpperLimit_DWord, curValue + addValue) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ZhanlingValue1 % zhanlingType, updValue) GameWorld.DebugLog("Ôö¼ÓÕ½Áî½ø¶È: zhanlingType=%s,addValue=%s,curValue=%s,updValue=%s" % (zhanlingType, addValue, curValue, updValue), curPlayer.GetPlayerID()) SyncZhanlingInfo(curPlayer, zhanlingType, []) return updValue def SetZhanlingValue(curPlayer, zhanlingType, value1): if zhanlingType not in [ZhanlingType_Huanjingge]: return PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ZhanlingValue1 % zhanlingType, value1) GameWorld.DebugLog("ÉèÖÃÕ½Áî½ø¶È: zhanlingType=%s,value1=%s" % (zhanlingType, value1), curPlayer.GetPlayerID()) SyncZhanlingInfo(curPlayer, zhanlingType, []) return value1 def GetZhanlingReward(curPlayer, zhanlingType, rewardID): ## ÁìÈ¡Õ½Áî½±Àø rewardID = GameWorld.ToIntDef(rewardID) needValue, rewardType = rewardID/10, rewardID%10 # rewardType£º 0-Ãâ·Ñ£»1-ÆÕͨ£»2-¸ß¼¶ playerID = curPlayer.GetPlayerID() ipyData = IpyGameDataPY.GetIpyGameData("Zhanling", zhanlingType, needValue) if not ipyData: return curValue = 0 if zhanlingType == ZhanlingType_LV: curValue = curPlayer.GetLV() elif zhanlingType == ZhanlingType_Realm: curValue = curPlayer.GetOfficialRank() elif zhanlingType == ZhanlingType_SkyTower: curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_SkyTowerFloor) elif zhanlingType == ZhanlingType_GubaoStar: _, curValue = PlayerGubao.GetGubaoTotalLVStar(curPlayer) elif zhanlingType == ZhanlingType_Login: firstLoginTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ZhanlingValue1 % zhanlingType) if not firstLoginTime: return curValue = GameWorld.GetDiff_Day(int(time.time()), firstLoginTime) + 1 elif zhanlingType == ZhanlingType_GatherTheSoulLV: curValue = PlayerGatherTheSoul.GetGatherTheSoulTotalLV(curPlayer) elif zhanlingType == ZhanlingType_HorsePetTrain: curValue = PlayerActHorsePetTrain.GetActHorsePetTrainScore(curPlayer) elif zhanlingType == ZhanlingType_GubaoTrain: curValue = PlayerActGubao.GetActGubaoTrainScore(curPlayer) elif zhanlingType == ZhanlingType_Xianyuan: curValue = PlayerControl.GetMoney(curPlayer, ShareDefine.TYPE_Price_XianyuanScore) elif zhanlingType == ZhanlingType_Huanjingge: curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ZhanlingValue1 % zhanlingType) else: return if curValue < needValue: GameWorld.DebugLog("Õ½ÁîËùÐèÖµ²»×㣬ÎÞ·¨Áì½±: zhanlingType=%s,curValue=%s < %s" % (zhanlingType, curValue, needValue), playerID) return rewardIndex = ipyData.GetRewardIndex() itemList = ipyData.GetFreeRewardItemList() rewardKey = ChConfig.Def_PDict_ZhanlingRewardFree if rewardType == 1: itemList = ipyData.GetZLRewardItemList() rewardKey = ChConfig.Def_PDict_ZhanlingReward state = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ZhanlingState) if not state&pow(2, zhanlingType): GameWorld.DebugLog("ÆÕͨսÁîδ¼¤»î£¬ÎÞ·¨ÁìÈ¡Õ½Áî½±Àø: zhanlingType=%s,state=%s" % (zhanlingType, state), playerID) return elif rewardType == 2: itemList = ipyData.GetZLRewardItemListH() rewardKey = ChConfig.Def_PDict_ZhanlingRewardH state = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ZhanlingStateH) if not state&pow(2, zhanlingType): GameWorld.DebugLog("¸ß¼¶Õ½Áîδ¼¤»î£¬ÎÞ·¨ÁìÈ¡Õ½Áî½±Àø: zhanlingType=%s,state=%s" % (zhanlingType, state), playerID) return if not itemList: GameWorld.DebugLog("ûÓиÃÕ½Áî½±Àø! zhanlingType=%s,needValue=%s,rewardType=%s" % (zhanlingType, needValue, rewardType), playerID) return if GameWorld.GetDictValueByBit(curPlayer, rewardKey, rewardIndex, True, [zhanlingType]): GameWorld.DebugLog("ÒѾ­ÁìÈ¡¹ý¸ÃÕ½Áî½±Àø! zhanlingType=%s,needValue=%s,rewardType=%s" % (zhanlingType, needValue, rewardType), playerID) return # ¼ì²é±³°ü if not ItemControler.CheckPackSpaceEnough(curPlayer, itemList): return # ¸üÐÂÒÑÁìÈ¡³É¹¦±ê¼Ç GameWorld.SetDictValueByBit(curPlayer, rewardKey, rewardIndex, 1, True, [zhanlingType]) SyncZhanlingInfo(curPlayer, zhanlingType, [ipyData]) GameWorld.DebugLog("ÁìÈ¡Õ½Áî½±Àø: zhanlingType=%s,needValue=%s,rewardType=%s,itemList=%s" % (zhanlingType, needValue, rewardType, itemList), playerID) # ¸øÎïÆ· for itemID, itemCount, isAuctionItem in itemList: ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isAuctionItem, [IPY_GameWorld.rptItem]) ItemControler.NotifyGiveAwardInfo(curPlayer, itemList, "Zhanling") return def SyncZhanlingInfo(curPlayer, zhanlingType, ipyDataList=None): if ipyDataList == None: ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition("Zhanling", {"ZhanlingType":zhanlingType}, True) rewardList = [] for ipyData in ipyDataList: rewardIndex = ipyData.GetRewardIndex() reward = ChPyNetSendPack.tagMCZhanling() reward.Clear() reward.NeedValue = ipyData.GetNeedValue() reward.FreeRewardState = 1 if GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ZhanlingRewardFree, rewardIndex, True, [zhanlingType]) else 0 reward.ZLRewardState = 1 if GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ZhanlingReward, rewardIndex, True, [zhanlingType]) else 0 reward.ZLRewardStateH = 1 if GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ZhanlingRewardH, rewardIndex, True, [zhanlingType]) else 0 rewardList.append(reward) clientPack = ChPyNetSendPack.tagMCZhanlingInfo() clientPack.Clear() clientPack.ZhanlingType = zhanlingType clientPack.IsActivite = 1 if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ZhanlingState)&pow(2, zhanlingType) else 0 clientPack.IsActiviteH = 1 if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ZhanlingStateH)&pow(2, zhanlingType) else 0 clientPack.Value1 = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ZhanlingValue1 % zhanlingType) clientPack.RewardList = rewardList clientPack.RewardCount = len(clientPack.RewardList) NetPackCommon.SendFakePack(curPlayer, clientPack) return