hxp
5 小时以前 e1fb8828f3e3ade575522e1717322a27e0521daf
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerGoldInvest
#
# @todo:Ͷ×Ê
# @author hxp
# @date 2025-11-10
# @version 1.0
#
# ÏêϸÃèÊö: Í¶×Ê
#
#-------------------------------------------------------------------------------
#"""Version = 2025-11-10 20:30"""
#-------------------------------------------------------------------------------
 
import GameWorld
import IpyGameDataPY
import NetPackCommon
import ChPyNetSendPack
import ItemControler
import PlayerControl
import PlayerMail
import ChConfig
 
import time
 
def OnLogin(curPlayer):
    for investType in ChConfig.InvestTypeList:
        if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestTime % investType):
            # ÓÐͶ×ʹý¾Íͬ²½
            continue
        Sync_InvestInfo(curPlayer, investType)
    return
 
def OnDay(curPlayer):
    dayAwardDict = IpyGameDataPY.GetFuncEvalCfg("InvestDay", 3, {})
    for investType in ChConfig.InvestTypeList:
        if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestTime % investType):
            continue
        
        # Ã¿ÈÕÏàͬ½±ÀøµÄ
        if str(investType) in dayAwardDict:                
            __GiveUnGetPerDayReward(curPlayer, investType, dayAwardDict[str(investType)])
            
        Sync_InvestInfo(curPlayer, investType)
        
    return
 
def __GiveUnGetPerDayReward(curPlayer, investType, dayAwardItemList):
    ## ²¹·¢Î´ÁìÈ¡µÄÿÈÕ½±Àø£¬Ò»°ãÓÃÓڠÿÈÕ¿ÉÁìÈ¡µÄ¹Ì¶¨½±Àø£¬ÈçÓÀ¾Ã¿¨µÈ
    
    if not dayAwardItemList:
        return
    
    playerID = curPlayer.GetPlayerID()
    lastRewardTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestRewardTime % investType)
    if not lastRewardTime:
        investTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestTime % investType)
        if not investTime:
            return
        lastRewardTime = investTime - 3600 * 24 # Èü¤»îµ±ÌìÒ²¿ÉÒÔÁì
        #GameWorld.DebugLog("´ÓδÁì½±¹ý")
        
    curTime = int(time.time())
    passDays = GameWorld.GetDiff_Day(curTime, lastRewardTime)
    #GameWorld.DebugLog("²¹·¢½±ÀøÊ±£¬¾àÀëÉÏ´ÎÁì½±ÒѹýÌìÊý: %s" % passDays, playerID)
    if not GetInvestState(curPlayer, investType):
        rewardDays = passDays
        endTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestEndTime % investType)
        if not endTime:
            return
        rewardDayMax = GameWorld.GetDiff_Day(endTime, lastRewardTime)
        if rewardDayMax <= 0:
            return
        GameWorld.DebugLog("ÒѹýÆÚ: ×î´ó»¹¿É½±ÀøÌìÊý: %s" % rewardDayMax, playerID)
        if rewardDays > rewardDayMax:
            rewardDays = rewardDayMax
            GameWorld.DebugLog("ÐÞÕý×î´ó»¹¿É²¹·¢µÄ½±ÀøÌìÊý: %s" % rewardDays, playerID)
    else:
        rewardDays = passDays - 1 # # ÐèÒª²¹·¢µÄ½±ÀøÌìÊý£¬Ö»²¹µ½×òÌ죬²»Ëãµ±Ìì
        GameWorld.DebugLog("δ¹ýÆÚ: rewardDays=%s" % rewardDays, playerID)
        
    if rewardDays <= 0:
        GameWorld.DebugLog("²»Óò¹·¢Í¶×Ê¿¨Ã¿ÈÕ½±Àø: investType=%s,rewardDays=%s" % (investType, rewardDays), playerID)
        return
    updRewardTime = curTime - 3600 * 24 # ×îºóÒ»´ÎÁì½±Ç¿ÖÆÉèÖõ½×òÌì
    
    mailItemList = []
    for itemInfo in dayAwardItemList:
        itemID = itemInfo[0]
        itemCount = itemInfo[1]
        mailItemList.append([itemID, itemCount * rewardDays])
        
    GameWorld.DebugLog("Óʼþ²¹·¢Í¶×Ê¿¨Ã¿ÈÕ½±Àø! investType=%s, rewardDays=%s, updRewardTime=%s, mailItemList=%s" 
                       % (investType, rewardDays, updRewardTime, mailItemList), playerID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_InvestRewardTime % investType, updRewardTime)
    PlayerMail.SendMailByKey("InvestDayReward_%s" % investType, playerID, mailItemList, [rewardDays])
    return
 
def __GetInvestPassDays(curPlayer, investType):
    ## »ñȡͶ×ÊÒѹýÌìÊý£¬Í¶×ʵ±ÌìΪµÚÒ»Ì죬¼´´Ó 1 ¿ªÊ¼£» 0´ú±íδͶ×Ê
    investTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestTime % investType)
    if not investTime:
        return 0
    curTime = int(time.time())
    return max(0, GameWorld.GetDiff_Day(curTime, investTime) + 1)
 
def GetInvestState(curPlayer, investType):
    ## »ñȡͶ×Ê¿¨×´Ì¬ 0-δͶ×Ê£»1-Ͷ×ÊÉúЧÖУ»
    investTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestTime % investType)
    if not investTime:
        return 0
    endTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestEndTime % investType)
    if endTime: # Óе½ÆÚʱ¼äµÄ¼ì²éµ½ÆÚ
        expiredDays = GameWorld.GetDiff_Day(int(time.time()), endTime)
        if expiredDays > 0: # ÒѹýÆÚ
            return 0
    return 1
 
#// A5 40 Í¶×ÊÀí²Æ #tagCMGoldInvest
#
#struct    tagCMGoldInvest
#{
#    tagHead        Head;
#    BYTE        InvestType; // Í¶×ÊÀàÐÍ
#    DWORD        InvestGold; // Í¶×ʶî¶È
#};
def OnGoldInvest(index, clientData, tick):
    #curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    #investType = clientData.InvestType
    return
 
def InvestByCTG(curPlayer, ctgID):
    ## ³äÖµÖ±¹ºÍ¶×Ê
    ctgInvestDict = IpyGameDataPY.GetFuncEvalCfg("InvestCost", 1, {})
    for investType, ctgIDList in ctgInvestDict.items():
        if ctgID in ctgIDList:
            DoLogicInvest(curPlayer, int(investType))
            break
    return
 
def DoLogicInvest(curPlayer, investType):
    ## Ö´ÐÐͶ×ÊÂß¼­
    buyDaysDict = IpyGameDataPY.GetFuncEvalCfg("InvestDay", 1, {}) # ¹ºÂòÌìÊý 
    buyDays = buyDaysDict.get(str(investType), 0)
    curState = GetInvestState(curPlayer, investType)
    GameWorld.DebugLog("¹ºÂòͶ×Ê: investType=%s,buyDays=%s,curState=%s" % (investType, buyDays, curState))
    
    curTime = int(time.time())
    # ÒѹýÆÚµÄÖØÖÃͶ×ÊÏà¹ØÊý¾Ý
    if not curState:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_InvestTime % investType, curTime)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_InvestEndTime % investType, 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_InvestRewardTime % investType, 0)
        
    # Ö§³ÖÖØ¸´¹ºÂò£¬ÀÛ¼Óµ½ÆÚʱ¼ä
    # ÓÀ¾Ã
    if buyDays <= 0:
        updEndTime = 0
        
    # ÓÐÌìÊýÏÞÖÆ
    elif buyDays > 0:
        endTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestEndTime % investType)
        if endTime > curTime:
            updEndTime = endTime + buyDays * 24 * 3600
            GameWorld.Log("    ÀÛ¼Óʱ³¤: investType=%s,endTime=%s,updEndTime=%s" 
                          % (investType, GameWorld.ChangeTimeNumToStr(endTime), GameWorld.ChangeTimeNumToStr(updEndTime)))
        else:
            updEndTime = GameWorld.GetEndTimeByZeroTime(curTime, buyDays)
            GameWorld.Log("    ÖØÐ¼¤»î: investType=%s,updEndTime=%s" % (investType, GameWorld.ChangeTimeNumToStr(updEndTime)))
            
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_InvestEndTime % investType, updEndTime)
    GameWorld.DebugLog("Ͷ×ÊÀí²Æ³É¹¦: investType=%s" % (investType))
    Sync_InvestInfo(curPlayer, investType)
    return
 
def GetAddFBCnt(curPlayer, mapID):
    ## »ñÈ¡Ôö¼ÓµÄ¸±±¾Ãâ·Ñ´ÎÊýÉÏÏÞ
    addFBCnt = 0
    return addFBCnt
 
def GetAddFBBuyCnt(curPlayer, mapID):
    ## »ñÈ¡Ôö¼ÓµÄ¸±±¾¹ºÂò´ÎÊýÉÏÏÞ
    addFBBuyCnt = 0
    addFBBuyCntDict = IpyGameDataPY.GetFuncEvalCfg("InvestPower", 1, {})
    for investType, fbMapIDAddDict in addFBBuyCntDict.items():
        addCnt = fbMapIDAddDict.get(str(mapID), 0)
        if not addCnt:
            continue
        if not GetInvestState(curPlayer, int(investType)):
            continue
        addFBBuyCnt += addCnt
    return addFBBuyCnt
 
def IsFBCntBuyFree(curPlayer, mapID):
    ## ¸±±¾¸¶·Ñ´ÎÊý¹ºÂòÃâ·Ñ
    freeSweepDict = IpyGameDataPY.GetFuncEvalCfg("InvestPower", 2, {})
    for investType, fbMapIDList in freeSweepDict.items():
        if mapID not in fbMapIDList:
            continue
        if not GetInvestState(curPlayer, int(investType)):
            continue
        return True
    return False
 
def GetArenaTicketMax(curPlayer):
    ## ÑÝÎ䳡ÃÅÆ±ÉÏÏÞ
    addMax = 0
    arenaCntDict = IpyGameDataPY.GetFuncEvalCfg("InvestPower", 3, {})
    for investType, addCnt in arenaCntDict.items():
        if not GetInvestState(curPlayer, int(investType)):
            continue
        addMax += addCnt
    return addMax
 
#// A5 41 ÁìȡͶ×ÊÀí²Æ»Ø±¨ #tagCMGetInvestReward
#
#struct    tagCMGetInvestReward
#{
#    tagHead        Head;
#    BYTE        InvestType; // Í¶×ÊÀàÐÍ
#    BYTE        RewardIndex; // »Ø±¨Ë÷Òý
#};
def OnGetInvestReward(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    investType = clientData.InvestType
    rewardIndex = clientData.RewardIndex
    GameWorld.DebugLog("ÁìȡͶ×ÊÀí²Æ»Ø±¨£ºinvestType=%s,rewardIndex=%s" % (investType, rewardIndex))
    
    if investType not in ChConfig.InvestTypeList:
        #GameWorld.DebugLog("²»´æÔÚ¸ÃͶ×ÊÀàÐÍ!")
        return
    
    if GetInvestState(curPlayer, investType) != 1:
        GameWorld.DebugLog("    Î´Í¶×Ê»òÒѹýÆÚ£¬ÎÞ·¨Áì½±!")
        return
    
    curTime = int(time.time())
    rewardItemList = []
    # °´Ã¿Ìì¹Ì¶¨½±ÀøµÄ
    if rewardIndex == 0:
        lastRewardTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestRewardTime % investType)
        if lastRewardTime:
            if GameWorld.GetDiff_Day(curTime, lastRewardTime) == 0:
                GameWorld.DebugLog("    ÒÑÁìÈ¡¹ý¸ÃË÷Òý½±Àø! rewardIndex=%s" % rewardIndex)
                return
            
        dayAwardDict = IpyGameDataPY.GetFuncEvalCfg("InvestDay", 3, {})
        if str(investType) in dayAwardDict:
            rewardItemList = dayAwardDict[str(investType)]
            
    if not rewardItemList:
        return
    
    if rewardIndex == 0:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_InvestRewardTime % (investType), int(time.time()))
    GameWorld.DebugLog("¸üÐÂÁì½±£ºinvestType=%s,rewardItemList=%s" % (investType, rewardItemList))
    Sync_InvestInfo(curPlayer, investType)
    ItemControler.GivePlayerItemOrMail(curPlayer, rewardItemList, event=["Invest", False, {}])
    return
 
def __todayAwardState(curPlayer, investType):
    lastRewardTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestRewardTime % investType)
    if lastRewardTime:
        if GameWorld.GetDiff_Day(int(time.time()), lastRewardTime) == 0:
            return 1
    return 0
 
def Sync_InvestInfo(curPlayer, investType):
    clientPack = ChPyNetSendPack.tagSCInvestInfo()
    clientPack.InvestType = investType
    clientPack.InvestBuyTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestTime % investType)
    clientPack.InvestEndTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestEndTime % investType)
    clientPack.AwardState = __todayAwardState(curPlayer, investType)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return