hxp
2 天以前 388823edfe6308cba6f76ca6dc4f20022c5cb2be
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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
#
##@package PlayerOnlinePrize
#
# @todo: ´´½Ç7ÌìÔÚÏß½±Àø
# @author xdh
# @date 2018-03-06 17:00
# @version 1.0
#
#---------------------------------------------------------------------
#"""Version = 2018-03-06 17:00"""
#---------------------------------------------------------------------
 
import ChPyNetSendPack
import ChConfig
import GameWorld
import ItemControler
import NetPackCommon
import PlayerControl
import IpyGameDataPY
import PlayerTJG
 
import time
 
#//A5 06 Íæ¼ÒÁìÈ¡ÔÚÏß½±Àø #tagCMGetOnlinePrize
#
#struct   tagCMGetOnlinePrize
#
#{
#    tagHead         Head;
#    BYTE        Index;    // ½±ÀøË÷Òý,ÆäËû°´Ë³Ðò
#    BYTE        IsDaily;    // ÊÇ·ñÁìȡÿÈÕÈÕ³£µÄ½±Àø£¬ÊÇ·¢1£¬Èç¹ûÁìÈ¡¶¨ÖÆ´´½ÇÌì½±ÀøµÄÔòĬÈÏ·¢0¼´¿É
#};
def GetOnlinePrize(index, clientPack, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    creatRoleDay = GameWorld.GetCreateRoleDays(curPlayer)
    prizeIndex = clientPack.Index
    if prizeIndex <= 0:
        GameWorld.DebugLog("prizeIndexÐèÒª´Ó1¿ªÊ¼£¬ÎÒÒ²²»Ï룬±£ÁôÔ­Âß¼­°É£¡£¡£¡")
        return
    ipyData = IpyGameDataPY.GetIpyGameDataNotLog('OnlineAwardNew', creatRoleDay)
    if ipyData:
        dayID = creatRoleDay
        GameWorld.DebugLog("ÁìÈ¡´´½ÇÌìÔÚÏß½±Àø: creatRoleDay=%s,prizeIndex=%s" % (creatRoleDay, prizeIndex))
    else:
        dayID = 0
        ipyData = IpyGameDataPY.GetIpyGameData('OnlineAwardNew', 0)
        GameWorld.DebugLog("ÁìȡÿÌìÔÚÏß½±Àø: creatRoleDay=%s,prizeIndex=%s" % (creatRoleDay, prizeIndex))
        
    if not ipyData:
        return
    #ÏȾÀÕýÒ»´Îʱ¼ä
    onlineTime = GetOnlineTime(curPlayer)
    
    #ÒÑÁì
    awardInfo = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OnlinePrizeNote)
    awardMark = pow(2, prizeIndex - 1)
    if awardInfo & awardMark:
        #ÒÑÁìÈ¡
        GameWorld.DebugLog("ÒÑÁìÈ¡½±Àø£¡dayID=%s,prizeIndex=%s" % (dayID, prizeIndex))
        return
    stageTimeList = ipyData.GetStageTime()
    
    if prizeIndex - 1 >= len(stageTimeList):
        GameWorld.DebugLog("²»´æÔÚ¸ÃÔÚÏß½±ÀøË÷Òý!")
        return
    needTime = stageTimeList[prizeIndex - 1]
    if needTime * 60 > onlineTime:
        GameWorld.DebugLog("ÔÚÏßʱ¼ä²»×㣡dayID=%s,prizeIndex=%s,needTime=%s" % (dayID, prizeIndex, needTime))
        return
    
    awardDict = ipyData.GetReward()
    if str(prizeIndex) not in awardDict:
        GameWorld.DebugLog("ûÓÐÅäÖøÃË÷Òý¶ÔÓ¦ÔÚÏß½±Àø!")
        return
    itemList = awardDict[str(prizeIndex)]
    if not itemList:
        return
    updAwardNote = awardInfo | awardMark
    GameWorld.DebugLog("ÔÚÏß½±Àø: %s, updAwardNote=%s" % (itemList, updAwardNote))
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_OnlinePrizeNote, updAwardNote)
    ItemControler.GivePlayerItemOrMail(curPlayer, itemList, event=["OnlinePrize", False, {}])
    SendOnlinePrizeInfo(curPlayer)
    return
 
def GetOnlineTime(curPlayer):
    onlineTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DayOnlineTime)
    markTick = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OnlineStartTick)
    if not markTick:
        return onlineTime
    curTime = int(time.time())
    passTick = curTime - markTick
    if passTick <= 0:
        return onlineTime
    return onlineTime + passTick
 
##ÀëÏ߸üмǼÔÚÏßʱ³¤
# @param notify ÊÇ·ñ֪ͨ¿Í»§¶Ë
# @return None
def CalcOnlineTime(curPlayer):
    if PlayerTJG.GetIsTJG(curPlayer):
        return 0
    onlineTime = GetOnlineTime(curPlayer)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DayOnlineTime, onlineTime)
    SetStartCalcOnlineTick(curPlayer, 0)
    GameWorld.DebugLog("¸üмǼÔÚÏßʱ³¤: %s" % onlineTime)
    return onlineTime
 
    
##·¢Ëͽ±ÀøÐÅÏ¢°ü
# @param None
# @return None
def SendOnlinePrizeInfo(curPlayer):
    dataCount = IpyGameDataPY.IPY_Data().GetOnlineAwardNewCount()
    if not dataCount:
        return
    sendPack = ChPyNetSendPack.tagMCOnlinePrizeNew()
    sendPack.Clear()
    sendPack.OnlineTime = GetOnlineTime(curPlayer) * 1000
    sendPack.PrizeInfo = [curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OnlinePrizeNote)] # ¹Ì¶¨Ö»·¢µ±ÌìµÄ
    sendPack.Len = len(sendPack.PrizeInfo)
    #֪ͨ¿Í»§¶Ëʱ¼ä
    NetPackCommon.SendFakePack(curPlayer, sendPack)
    return
 
 
##ÉèÖÿªÊ¼¼ÆÊ±Ê±¼ä
# @param None
# @return None
def SetStartCalcOnlineTick(curPlayer, newTime=-1):
    if newTime == -1:
        newTime=int(time.time())
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_OnlineStartTick, newTime)
    return
 
## µÇ¼
#  @param curPlayer
#  @return None
def OnPlayerLogin(curPlayer):
    SetStartCalcOnlineTick(curPlayer)
    SendOnlinePrizeInfo(curPlayer)
    return
 
##ONDAYÖØÖÃ, Í¨Öª¿Í»§¶Ë
# @param None
# @return None
def ResetPrizeInfoOnDay(curPlayer):
    __OnlineMailPrize(curPlayer)
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DayOnlineTime, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_OnlinePrizeNote, 0) # ÖØÖÃÿÈÕÔÚÏß½±Àø
   
    if PlayerTJG.GetIsTJG(curPlayer):
        return
    SetStartCalcOnlineTick(curPlayer)
    
    SendOnlinePrizeInfo(curPlayer)
    return
 
def __OnlineMailPrize(curPlayer):
    #Óʼþ²¹·¢½±Àø
    creatRoleDay = GameWorld.GetCreateRoleDays(curPlayer)
    if creatRoleDay <= 1:
        return
    mailAwardDay = creatRoleDay - 1
    ipyData = IpyGameDataPY.GetIpyGameDataNotLog('OnlineAwardNew', mailAwardDay)
    if not ipyData:
        ipyData = IpyGameDataPY.GetIpyGameDataNotLog('OnlineAwardNew', 0)
        if not ipyData:
            return
        mailAwardDay = 0 # ×òÈշǶ¨ÖƵģ¬ÇÒÓÐÅäÖÃ0³£¹æµÄ£¬Ôò²¹·¢0µÄ
        
    prizeInfo = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OnlinePrizeNote)
    onlineTime = GetOnlineTime(curPlayer)
    needTimeList = ipyData.GetStageTime()
    awardDict = ipyData.GetReward()
    itemList = []
    for i, needTime in enumerate(needTimeList):
        if onlineTime >= needTime * 60 and not prizeInfo & pow(2, i):
            for itemID, itemCnt in awardDict[str(i + 1)]:
                itemList.append([itemID, itemCnt, 1])
            prizeInfo|=pow(2, i)
    
    if not itemList:
        return
    GameWorld.DebugLog('²¹·¢×òÈÕÔÚÏß½±Àø: mailAwardDay=%s,onlineTime=%s' % (mailAwardDay, onlineTime))
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_OnlinePrizeNote, prizeInfo)
    PlayerControl.SendMailByKey('OnLineAward1', [curPlayer.GetID()], itemList)
    return