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
#!/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 ItemControler
import IPY_GameWorld
import PlayerGubao
import ChConfig
 
# Õ½ÁîÀàÐÍ
ZhanlingTypeList = (
ZhanlingType_LV,
ZhanlingType_Realm,
ZhanlingType_SkyTower,
ZhanlingType_GubaoStar,
) = range(1, 1 + 4)
 
def OnPlayerLogin(curPlayer):
    for zhanlingType in ZhanlingTypeList:
        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
    
    return
 
def GetZhanlingReward(curPlayer, zhanlingType, rewardID):
    ## ÁìȡսÁî½±Àø
    rewardID = GameWorld.ToIntDef(rewardID)
    needValue, isFree = rewardID/10, rewardID%10
    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)
    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 not isFree:
        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,isFree=%s" % (zhanlingType, state, isFree), playerID)
            return
        
    if GameWorld.GetDictValueByBit(curPlayer, rewardKey, rewardIndex, True, [zhanlingType]):
        GameWorld.DebugLog("ÒѾ­ÁìÈ¡¹ý¸ÃÕ½Áî½±Àø! zhanlingType=%s,needValue=%s,isFree=%s" % (zhanlingType, needValue, isFree), 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,isFree=%s" % (zhanlingType, needValue, isFree), 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
        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.RewardList = rewardList
    clientPack.RewardCount = len(clientPack.RewardList)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return