hxp
2024-12-17 71a26587b4adb83f1ce0810a1b67b1a48c525a8b
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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerCustomAward
#
# @todo:×Ô¶¨Òå½±Àø
# @author hxp
# @date 2023-09-22
# @version 1.0
#
# ÏêϸÃèÊö: ×Ô¶¨Òå½±Àø
#
#-------------------------------------------------------------------------------
#"""Version = 2023-09-22 13:30"""
#-------------------------------------------------------------------------------
 
import GameWorld
import NetPackCommon
import ChPyNetSendPack
import IpyGameDataPY
import ItemCommon
import ChConfig
 
def OnPlayerLogin(curPlayer):
    Sync_CustomAwardInfo(curPlayer)
    return
 
def SetCustomAwardCanGet(curPlayer, awardID, canGet=1):
    ipyData = IpyGameDataPY.GetIpyGameData("CustomAward", awardID)
    if not ipyData:
        return
    GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_CustomAwardCanGet, awardID, canGet)
    Sync_CustomAwardInfo(curPlayer, awardID)
    return
 
## ÁìÈ¡×Ô¶¨Òå½±Àø
def OnGetCustomAward(curPlayer, awardID):
    if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_CustomAwardCanGet, awardID):
        GameWorld.Log("¸Ã×Ô¶¨Òå½±Àøµ±Ç°²»¿ÉÁìÈ¡, awardID=%s" % awardID, curPlayer.GetPlayerID())
        return
    if GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_CustomAwardGetState, awardID):
        GameWorld.Log("¸Ã×Ô¶¨Òå½±ÀøÒѾ­ÁìÈ¡¹ý, awardID=%s" % awardID, curPlayer.GetPlayerID())
        return
    ipyData = IpyGameDataPY.GetIpyGameData("CustomAward", awardID)
    if not ipyData:
        return
    awardItemList = ipyData.GetAwardItemList()
    
    if not ItemCommon.GiveAwardItem(curPlayer, awardItemList):
        return
    
    GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_CustomAwardGetState, awardID, 1)
    GameWorld.Log("ÁìÈ¡×Ô¶¨Òå½±Àø, awardID=%s" % awardID, curPlayer.GetPlayerID())
    Sync_CustomAwardInfo(curPlayer, awardID)
    return
 
## Í¨Öª×Ô¶¨Òå½±Àø¼Ç¼
def Sync_CustomAwardInfo(curPlayer, awardID=None, force=False):
    if awardID == None:
        awardIDList = []
        ipyDataMgr = IpyGameDataPY.IPY_Data()
        for index in range(ipyDataMgr.GetCustomAwardCount()):
            ipyData = ipyDataMgr.GetCustomAwardByIndex(index)
            awardIDList.append(ipyData.GetAwardID())
    else:
        awardIDList = [awardID]
        
    keyNumList = []
    for aID in awardIDList:
        keyNum = GameWorld.GetDictKeyNumByBit(aID)
        if keyNum not in keyNumList:
            keyNumList.append(keyNum)
    
    if not keyNumList:
        return
    
    recordStateList = []
    for keyNum in keyNumList:
        canGet = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CustomAwardCanGet % keyNum)
        getState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CustomAwardGetState % keyNum)
        if not canGet and not getState and not force:
            continue
        awardState = ChPyNetSendPack.tagMCCustomAwardState()
        awardState.KeyNum = keyNum
        awardState.CanGetState = canGet
        awardState.GetState = getState
        recordStateList.append(awardState)
        
    if not recordStateList:
        return
    
    clientPack = ChPyNetSendPack.tagMCCustomAwardInfo()
    clientPack.Clear()
    clientPack.RecordStateList = recordStateList
    clientPack.RecordStateCnt = len(clientPack.RecordStateList)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return