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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerSuperDiscount
#
# @todo:ÖÁ×ð¿¨ÕÛ¿Û
# @author hxp
# @date 2024-10-18
# @version 1.0
#
# ÏêϸÃèÊö: ÖÁ×ð¿¨ÕÛ¿Û£¬½«³äÖµÔ­¼Û¹ºÂò±ä³É1ÕÛ£¬Ó¢Îİæ×¨ÓÃ
#
#-------------------------------------------------------------------------------
#"""Version = 2024-10-18 15:00"""
#-------------------------------------------------------------------------------
 
import GameWorld
import IpyGameDataPY
import PlayerControl
import ChPyNetSendPack
import NetPackCommon
import ItemControler
import IPY_GameWorld
import ShareDefine
import ChConfig
import random
import time
 
PrizeType_Gold = 1 # ½ð±Ò = 10ÍòÍ­Ç®
PrizeType_Xianyu = 2 # ÏÉÓñ±Ò = 10ÏÉÓñ
PrizeType_Redpack = 3 # ºì°ü
PrizeType_Super = 4 # ³¬¼¶½±Àø
 
PrizeMoneyTypeList = [1, 2, 3] # ±¾¹¦Äܿɲú³öµÄ»õ±ÒÀàÐÍ
 
Sign_NewVerPlayer = 1 # Ð°汾ºó¶Ë´¦ÀíÍæ¼Ò 
Sign_OldVerPlayer = 2 # Àϰ汾ǰ¶Ë´¦ÀíÍæ¼Ò 
 
def __InitOldPlayerTjb(curPlayer):
    ## ÀÏÍæ¼ÒÍÆ½ð±ÒĬÈϽ±³Ø´¦Àí
    if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiSign):
        #GameWorld.DebugLog("ÍÆ½ð±ÒÍæ¼Ò±ê¼ÇÒÑ´¦Àí: %s" % curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiSign), curPlayer.GetPlayerID())
        return
    sign = Sign_NewVerPlayer
    for moneyType in PrizeMoneyTypeList:
        if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiMoney % moneyType):
            sign = Sign_OldVerPlayer # ÓÐʵ¼Ê»ñµÃ¹ý½±ÀøÊÓΪÀÏÍæ¼Ò
            break
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TuiJinbiSign, sign)
    if sign != Sign_OldVerPlayer:
        return
    # ¸øÀÏÍæ¼Ò³õÊ¼Ì¨Ãæ
    initPrizeList = IpyGameDataPY.GetFuncEvalCfg("EnSuperDiscount", 5)
    for prizeType, prizeCount in initPrizeList:
        if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiPool % prizeType):
            continue
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TuiJinbiPool % prizeType, prizeCount)
    GameWorld.Log("ÍÆ½ð±ÒÀÏÍæ¼ÒÉèÖóõÊ¼Ì¨ÃæÊý¾Ý: %s" % str(initPrizeList), curPlayer.GetPlayerID())
    return
 
def OnPlayerLogin(curPlayer):
    __InitOldPlayerTjb(curPlayer)
    SyncTuijinbiInfo(curPlayer)
    return
 
def PlayerOnDay(curPlayer):
    GiveTuijinbiByDay(curPlayer)
    return
 
def GiveTuijinbiByDay(curPlayer):
    tuibanTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiBanTime)
    tuibanDayAwardInfo = IpyGameDataPY.GetFuncEvalCfg("EnSuperDiscount", 4)
    if tuibanTime and tuibanDayAwardInfo and len(tuibanDayAwardInfo) == 2:
        diffDays = GameWorld.GetDiff_Day(int(time.time()), tuibanTime) + 1
        giveMoney, maxDays = tuibanDayAwardInfo
        if diffDays <= maxDays:
            GameWorld.DebugLog("°´Ìì¸øÍÆ½ð±Ò´ÎÊý! diffDays=%s, maxDays=%s" % (diffDays, maxDays), curPlayer.GetPlayerID())
            PlayerControl.GiveMoney(curPlayer, ShareDefine.TYPE_Price_Tuijinbi, giveMoney, "tuibanonday")
    return
 
def GetSuperDiscountState(curPlayer):
    ## ÖÁ×ðÕÛ¿Û¿¨¼¤»î״̬
    return curPlayer.GetLV2() == 1
 
def ActSuperDiscountByCTG(curPlayer, ctgID):
    ## ³äÖµ¼¤»î
    if ctgID and ctgID == IpyGameDataPY.GetFuncCfg("EnSuperDiscount", 1):
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TuiJinbiBanTime, int(time.time()))
        GameWorld.DebugLog("±ê¼ÇÒѹºÂò³¬¼¶Íưåʱ¼ä´Á!", curPlayer.GetPlayerID())
        GiveTuijinbiByDay(curPlayer) # ¸øµÚÒ»Ìì½±Àø
    return
 
def __DoActiveSuperDiscount(curPlayer):
    ## ¼¤»îÖÁ×ð¿¨
    if GetSuperDiscountState(curPlayer):
        GameWorld.DebugLog("ÖÁ×ð¿¨ÒѼ¤»î!")
        return
    
    # Ã»ÓйºÂò³¬¼¶ÍưåµÄ£¬ÑéÖ¤Ãâ·Ñ¼¤»î
    tuibanTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiBanTime)
    if not tuibanTime:
        needCreateRoleDays = IpyGameDataPY.GetFuncCfg("EnSuperDiscount", 2)
        createRoleDays = GameWorld.GetCreateRoleDays(curPlayer)
        if createRoleDays < needCreateRoleDays:
            GameWorld.ErrLog("´´½ÇÌìÊý²»×㣬ÎÞ·¨Ãâ·Ñ¼¤»îÖÁ×ð¿¨! createRoleDays=%s < %s" % (createRoleDays, needCreateRoleDays), curPlayer.GetPlayerID())
            return
        
    GameWorld.DebugLog("¼¤»îÖÁ×ð¿¨: tuibanTime=%s" % (tuibanTime), curPlayer.GetPlayerID())
    curPlayer.SetLV2(1)
    return
 
#// AA 02 Íƽð±Ò #tagCMTuijinbi
#
#struct     tagCMTuijinbi
#{
#    tagHead        Head;
#    BYTE        OpType;    // ²Ù×÷ÀàÐÍ: 0-³é½±£»1-»ñµÃ½±Àø£»2-¼¤»îÖÁ×ð¿¨
#    DWORD        Value1;    // ÀàÐÍ1ʱΪ½±ÀøÀàÐÍ
#    DWORD        Value2;    // ÀàÐÍ1ʱΪ½±ÀøÊýÖµ
#};
def OnTuijinbi(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    opType = clientData.OpType
    value1 = clientData.Value1
    value2 = clientData.Value2
    
    if opType == 0:
        __DoDraw(curPlayer)
        
    elif opType == 1:
        __DoGivePrize(curPlayer, value1, value2)
        
    elif opType == 2:
        __DoActiveSuperDiscount(curPlayer)
        
    return
 
def __DoDraw(curPlayer):
    ## ³é½±
    
    if not PlayerControl.HaveMoney(curPlayer, ShareDefine.TYPE_Price_Tuijinbi, 1):
        return
    
    playerID = curPlayer.GetPlayerID()
    prizeSetList = IpyGameDataPY.GetFuncEvalCfg("PushCoin", 1) # ½±³Ø [[ÀàÐÍ, ¸ÅÂÊ, ÊýÁ¿], ...]
    prizeRateList = []
    for setInfo in prizeSetList:
        prizeRateList.append([setInfo[1], [setInfo[0], setInfo[2]]])
    playerSign = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiSign)
    tuijinbiCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiCnt)
    GameWorld.DebugLog("ÍÆ½ð±Ò³é½±: playerSign=%s,tuijinbiCnt=%s,prizeRateList=%s" % (playerSign, tuijinbiCnt, prizeRateList), playerID)
    
    addPoolPrizeInfo = {} # Ôö¼ÓÌ¨Ãæ½±³ØÐÅÏ¢
    drawIndex, drawInfo = GameWorld.GetResultIndexByRandomList(prizeRateList)
    if playerSign == Sign_NewVerPlayer and not tuijinbiCnt: # ÐÂ°æ±¾Íæ¼ÒÊ×´ÎÍÆ
        for _ in range(100):
            if drawInfo and drawInfo[0] in [PrizeType_Gold, PrizeType_Xianyu]: # Ê×´ÎÖ»Äܲú³ö½ð±Ò»òÏÉÓñ±Ò
                break
            drawIndex, drawInfo = GameWorld.GetResultIndexByRandomList(prizeRateList)
            
        # Ê״θ½¼ÓĬÈϳõʼ½±Àø
        initPrizeList = IpyGameDataPY.GetFuncEvalCfg("EnSuperDiscount", 5)
        for prizeType, prizeCnt in initPrizeList:
            addPoolPrizeInfo[prizeType] = prizeCnt
        GameWorld.DebugLog("ÐÂÊÖÊ×´ÎÍÆ¶îÍâ½±Àø: %s" % addPoolPrizeInfo, playerID)
        
    if not drawInfo or len(drawInfo) != 2:
        return
    drawType, drawCount = drawInfo
    GameWorld.DebugLog("³éµ½: drawIndex=%s,drawInfo=%s,drawType=%s,drawCount=%s" % (drawIndex, drawInfo, drawType, drawCount), playerID)
    PlayerControl.PayMoney(curPlayer, ShareDefine.TYPE_Price_Tuijinbi, 1, isNotify=False)    
    
    # ºì°ü£¬Ö±½Ó¸ø½±Àø
    if drawType == PrizeType_Redpack:
        randMoneyList = IpyGameDataPY.GetFuncEvalCfg("PushCoin", 3)
        GameWorld.DebugLog("ºì°üÖ±½Ó¸ø: %s" % str(randMoneyList), playerID)
        for randMoney in randMoneyList:
            if randMoney and len(randMoney) == 2:
                __GiveMoney(curPlayer, randMoney[0], randMoney[1])
            
    # ³¬¼¶½±Àø
    elif drawType == PrizeType_Super:
        randPrizeList = IpyGameDataPY.GetFuncEvalCfg("PushCoin", 2)
        GameWorld.DebugLog("³¬¼¶½±Àø: %s" % str(randPrizeList), playerID)
        for randPrize in randPrizeList:
            if randPrize and len(randPrize) == 2:
                randPrizeType, randValue = randPrize
                addPoolPrizeInfo[randPrizeType] = addPoolPrizeInfo.get(randPrizeType, 0) + randValue
    else:
        GameWorld.DebugLog("Ìí¼Ó½±³Ø: drawType=%s,drawCount=%s" % (drawType, drawCount), playerID)
        addPoolPrizeInfo[drawType] = addPoolPrizeInfo.get(drawType, 0) + drawCount
            
    for prizeType, addCnt in addPoolPrizeInfo.items():
        curCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiPool % prizeType)
        updCnt = curCnt + addCnt
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TuiJinbiPool % prizeType, updCnt)
        GameWorld.DebugLog("ÍÆ½ð±Ò¸üÐÂÌ¨Ãæ: prizeType=%s,curCnt=%s,addCnt=%s,updCnt=%s" % (prizeType, curCnt, addCnt, updCnt), playerID)
        
    tuijinbiCnt += 1
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TuiJinbiCnt, tuijinbiCnt)
    GameWorld.DebugLog("¸üÐÂÀÛ¼ÆÍƽð±Ò´ÎÊý: %s" % (tuijinbiCnt), playerID)
    SyncTuijinbiInfo(curPlayer, drawIndex + 1)
    return
 
def __DoGivePrize(curPlayer, prizeType, prizeCount):
    if prizeType not in [PrizeType_Gold, PrizeType_Xianyu]:
        return
    curCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiPool % prizeType)
    giveCnt = min(prizeCount, curCnt)
    if not giveCnt:
        return
    updCnt = curCnt - giveCnt
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TuiJinbiPool % prizeType, updCnt)
    GameWorld.DebugLog("µôÂä¸üÐÂÌ¨Ãæ: prizeType=%s,prizeCount=%s,curCnt=%s,giveCnt=%s,updCnt=%s" 
                       % (prizeType, prizeCount, curCnt, giveCnt, updCnt), curPlayer.GetPlayerID())
    if prizeType == PrizeType_Gold:
        __GiveMoney(curPlayer, IPY_GameWorld.TYPE_Price_Silver_Money, 100000 * giveCnt)
    elif prizeType == PrizeType_Xianyu:
        __GiveMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, 10 * giveCnt)
    SyncTuijinbiInfo(curPlayer)
    return
 
def __GiveMoney(curPlayer, moneyType, moneyValue):
    moneyTotal = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiMoney % moneyType)
    updMoneyTotal = min(moneyTotal + moneyValue, ChConfig.Def_UpperLimit_DWord)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TuiJinbiMoney % moneyType, updMoneyTotal)
    GameWorld.DebugLog("¸üÐÂÍÆ½ð±ÒÀۼƽ±Àø»õ±Ò: moneyType=%s,moneyValue=%s,updMoneyTotal=%s" 
                       % (moneyType, moneyValue, updMoneyTotal), curPlayer.GetPlayerID())
    PlayerControl.GiveMoney(curPlayer, moneyType, moneyValue, "Tuijinbi")
    return
 
def SyncTuijinbiInfo(curPlayer, drawNum=0):
    poolPrizeList = [] # Ì¨ÃæÐÅÏ¢
    for prizeType in [PrizeType_Gold, PrizeType_Xianyu]:
        prizeCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiPool % prizeType)
        if not prizeCount:
            continue
        poolInfo = ChPyNetSendPack.tagMCTuijinbiPool()
        poolInfo.PrizeType = prizeType
        poolInfo.PrizeCount = prizeCount
        poolPrizeList.append(poolInfo)
        
    clientPack = ChPyNetSendPack.tagMCTuijinbiInfo()
    clientPack.DrawNum = drawNum
    clientPack.PoolPrizeList = poolPrizeList
    clientPack.PoolPrizeCnt = len(clientPack.PoolPrizeList)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return