1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/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 NetPackCommon
import IpyGameDataPY
import PlayerControl
import ChPyNetSendPack
import PlayerGatherTheSoul
import ItemControler
import IPY_GameWorld
import PlayerGubao
import ChConfig
import time
 
# Õ½ÁîÀàÐÍ
ZhanlingTypeList = (
ZhanlingType_LV,
ZhanlingType_Realm,
ZhanlingType_SkyTower,
ZhanlingType_GubaoStar,
ZhanlingType_Login,
ZhanlingType_GatherTheSoulLV,
) = range(1, 1 + 6)
 
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 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)
    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])
        
    return
 
def SyncZhanlingInfo(curPlayer, zhanlingType, ipyData=None):
    
    ipyDataList = []
    if ipyData == None:
        ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition("Zhanling", {"ZhanlingType":zhanlingType}, True)
    else:
        ipyDataList = [ipyData]
        
    if not ipyDataList:
        return
            
    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