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
279
280
281
282
283
284
285
286
#!/usr/bin/python
# -*- coding: GBK -*-
#
#
##@package PlayerSignDay
#
# @todo: Ã¿ÈÕÇ©µ½
#
# @author jiang
# @date 2012-03-23
# @version 1.8
# @note:
# @change: "2013-03-13 17:00" wdb É¾³ý·â°ü
# @change: "2013-10-31 11:00" hxp ÐÞ¸ÄÿÈÕÇ©µ½Âß¼­
# @change: "2013-11-05 20:20" hxp Ôö¼Ó¹ýÌì֪ͨǩµ½¼Ç¼Çé¿ö
# @change: "2014-04-03 22:00" xmnathan Ã¿ÈÕÇ©µ½Âß¼­Ð޸ģ¬Ôö¼ÓVIP²¹Ç©
# @change: "2015-06-16 15:40" ljd Ð޸ijÉÀàµÇ½½±Àø£¬²¹µÇ
# @change: "2015-08-03 16:40" ljd ²¹Ç©´ÎÊý´ÓVIP Å²µ½ ¹ó×å
# @change: "2015-08-24 14:40" zqx Ôö¼ÓÇ©µ½³É¾Í
# @change: "2016-10-26 11:00" hxp Ç©µ½Âß¼­ÐÞ¸Ä
#-------------------------------------------------------------------------------
#"""Version = 2016-10-26 11:00"""
#-------------------------------------------------------------------------------
 
import ShareDefine
import NetPackCommon
import IPY_GameWorld
import ItemControler
import DataRecordPack
import ChPyNetSendPack
import PlayerMagicWeapon
import PlayerTongTianLing
import PlayerActTask
import PlayerPet
import PlayerControl
import GameWorld
import ChConfig
import GameFuncComm
import IpyGameDataPY
import ItemCommon
 
import time
#===============================================================================
#//A5 09 Íæ¼ÒÇ©µ½ #tagCMDaySign
# struct    tagCMDaySign
#{
#    tagHead        Head;
#    BYTE        Day;    //ĬÈÏ0±íʾµ±ÈÕÇ©µ½£¬´Ó1±íʾ²¹Ç©¡£
# }; 
#===============================================================================
## Íæ¼ÒÇ©µ½·â°üÈë¿Ú
#  @param index: Íæ¼ÒË÷Òý
#  @param clientData: ·â°ü½á¹¹Ìå
#  @param tick: Ê±¼ä´Á
#  @return: None
def OnSignDay(index, clientData, tick):
    # ¿ç·þ·þÎñÆ÷¹¦ÄÜÏÞÖÆ
    if GameWorld.IsCrossServer():
        return
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)   
    #¹¦ÄÜ¿ªÆôÅжÏ
    if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_SignDay):
        GameWorld.DebugLog("Íæ¼ÒµÈ¼¶²»×㣬먦ÆôÇ©µ½¹¦ÄÜ PlayerLv=%s" % curPlayer.GetLV())
        return  
    
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    signDay = clientData.Day # 0-Õý³£Ç©µ½£»1-²¹Ç©
    isAddLogin = 1 if signDay else 0 # ÊÇ·ñ²¹Ç©
    
    if not isAddLogin:
        #ÊÇ·ñ½ñÌìÒѾ­Ç©µ½
        signState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DayLoginSignState)
        if signState:
            GameWorld.DebugLog("½ñÈÕÒÑÇ©µ½¹ý£¡")
            return
        signCost = 0
    else:
        #±¾ÂÖÀۼƿɲ¹Ç©´ÎÊý
        canAddSignNum = GetCanAddSignNum(curPlayer)
        #ÊÇ·ñÓÐÊ£Óಹǩ´ÎÊý
        if canAddSignNum <= 0:
            GameWorld.DebugLog("ÒѾ­Ã»Óв¹Ç©´ÎÊý£¬²¹Ç©Ê§°Ü£¡canAddSignNum=%s" % canAddSignNum)
            return
        #»ñÈ¡ÐèÒªÏûºÄÍæ¼ÒÏÉÓñ   
        signCost = IpyGameDataPY.GetFuncCfg("SignConsumption")
        if not PlayerControl.HaveMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, signCost, True):
            GameWorld.DebugLog("²¹Ç©ËùÐè»õ±Ò²»×ã! signCost=%s" % signCost)
            return
          
    #»ñµÃÇ©µ½ÌìÊý
    curSignNum = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DayLoginSignNum) + 1
    totalSignNum = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TotalSignNum) + 1
    
    #»ñµÃÇ©µ½Àۼƽ±Àø±íijÈÕÐÅÏ¢ 
    awardInfo = IpyGameDataPY.GetIpyGameData("SignAward", curSignNum)
    if not awardInfo:
        GameWorld.DebugLog("ÕÒ²»µ½Ç©µ½½±Àø! Ç©µ½µÚ(%s)´Î" % curSignNum)
        return
       
    #»ñµÃÁÐÐÅÏ¢
    itemIDList = awardInfo.GetItemID()
    ordinaryNumList = awardInfo.GetOrdinaryNum()
    isBind = awardInfo.GetIsBind()
    vipLv = awardInfo.GetVipLv()
    vipMultiple = awardInfo.GetVipMultiple()
    #ÅжÏÊÇ·ñÊǵڶþÔÂÒÔºó
    isMulti = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DayLoginSignIsMulti)
    if not isMulti:
        itemID = itemIDList[0]
        ordinaryNum = ordinaryNumList[0]
    else:
        itemID = itemIDList[1]
        ordinaryNum = ordinaryNumList[1]    
    #ÅжÏÊÇ·ñÐèÒªVip¶à±¶ 
    curVipLV = curPlayer.GetVIPLv()
    if curVipLV >= vipLv:
        ordinaryNum *= vipMultiple
     
    #¼Ç¼ǩµ½ÐÅÏ¢
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DayLoginSignNum, curSignNum)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TotalSignNum, totalSignNum)
    if not isAddLogin:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DayLoginSignState, 1)
     
    #Ö§¸¶ÏÉÓñ
    if signCost > 0:
        PlayerControl.PayMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, signCost, ChConfig.Def_Cost_AddSignDay)
      
    #Ç©µ½½±ÀøÐÅÏ¢
    awardInfoList = [[itemID, ordinaryNum, isBind]]
    
    #¸øÓèÇ©µ½½±ÀøÎïÆ·
    __GivePlayerItemByItemInfoList(curPlayer, awardInfoList, "SignToPlayer")
    
    #ÀÛ¼ÆÇ©µ½½±ÀøÐÅÏ¢
    contineAwardInfoList = []
    
    #»ñµÃÁ¬ÐøÇ©µ½½±Àø±íÐÅÏ¢
    contineAwardInfo = IpyGameDataPY.GetIpyGameData("ContineSignAward", curSignNum)
    if not contineAwardInfo:
        GameWorld.DebugLog("ÕÒ²»µ½Á¬ÐøÇ©µ½½±Àø! Ç©µ½µÚ(%s)´Î" % curSignNum)
    else:
        jobItemList = contineAwardInfo.GetJobItemList()
        itemIDList = contineAwardInfo.GetItemID()
        itemNumList = contineAwardInfo.GetItemNum()
        awardIndex = 1 if (len(itemIDList) > 1 and isMulti) else 0
        itemID = itemIDList[awardIndex]
        itemCount = itemNumList[awardIndex]
        if itemID in jobItemList and curPlayer.GetJob() <= len(jobItemList):
            itemID = jobItemList[curPlayer.GetJob() - 1]
        contineAwardInfoList = [[itemID, itemCount, contineAwardInfo.GetIsBind()]]
        #for index in xrange(len(itemIDList)): 
        #    contineAwardInfoList.append([itemIDList[index], itemNumList[index], itemIsBind])
        
    #¸øÓèÀۼƽ±ÀøÎïÆ·  
    __GivePlayerItemByItemInfoList(curPlayer, contineAwardInfoList, "ContineSignToPlayer")
    PlayerControl.NotifyCode(curPlayer, 'SignInText')
    #ͬ²½¿Í»§¶Ë                
    Sync_SignDayInfo(curPlayer)
    
    addDataDict = {"signNum":curSignNum, "vipLV":curVipLV, "itemInfo":str(awardInfoList + contineAwardInfoList),
                   "isAddSign":isAddLogin, "CostMoney":str([IPY_GameWorld.TYPE_Price_Gold_Money, signCost])}
    DataRecordPack.DR_FuncGiveItem(curPlayer, "DayLoginSignAward", addDataDict)
    GameWorld.DebugLog("%s: %s" % ("²¹Ç©" if isAddLogin else "Ç©µ½", addDataDict), curPlayer.GetPlayerID())
    ItemControler.NotifyGiveAwardInfo(curPlayer, awardInfoList + contineAwardInfoList, "SignDay")
    
    # Ë¢Ç©µ½¸½¼Ó¹¦ÄÜÊôÐÔ
    PlayerMagicWeapon.CalcMagicWeaponAttr(curPlayer)
    PlayerPet.CalcPetItemAddPlayerAttr(curPlayer)
    PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    
    mwID = IpyGameDataPY.GetFuncCfg('MWSignDayAttr', 2)
    if mwID:
        effDict = IpyGameDataPY.GetFuncEvalCfg('MWSignDayAttr', 1, {})
        if PlayerMagicWeapon.GetIsActiveMagicWeapon(curPlayer, mwID) and effDict:
            PlayerControl.NotifyCode(curPlayer, "SignInText1", [mwID, effDict.keys()[0], effDict.values()[0]])
            
    
    petLearnSkillList, petPassiveSkillList = PlayerPet.GetPetLearnSkill(curPlayer)
    if ChConfig.Def_SkillID_PetSignDay in petPassiveSkillList:
        signDayAttrSkill = GameWorld.GetGameData().GetSkillBySkillID(ChConfig.Def_SkillID_PetSignDay)
        if signDayAttrSkill:
            curEffect = signDayAttrSkill.GetEffect(0)
            PlayerControl.NotifyCode(curPlayer, "SignInText2", [ChConfig.Def_SkillID_PetSignDay, curEffect.GetEffectID(), curEffect.GetEffectValue(0)])
            
    PlayerTongTianLing.AddTongTianTaskValue(curPlayer, ChConfig.TTLTaskType_Sign, 1)
    PlayerActTask.AddActTaskValue(curPlayer, ChConfig.ActTaskType_Sign)
    return
 
## Ç©µ½×ܽ±ÀøÌìÊý
def GetSignAwardCountMax(): return IpyGameDataPY.IPY_Data().GetSignAwardCount()
 
def DoSignDayOpen(curPlayer):
    ResetDaySign(curPlayer)
    return
 
def SignDayOnLogin(curPlayer):
    ''' Íæ¼ÒÉÏÏß '''
    #¹¦ÄÜ¿ªÆôÅжÏ
    if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_SignDay):
        #GameWorld.DebugLog("Íæ¼Ò먦ÆôÇ©µ½¹¦ÄÜ PlayerLv=%s" % curPlayer.GetLV())
        return       
    Sync_SignDayInfo(curPlayer)
    return
 
def SignDayOnDay(curPlayer):
    ''' Íæ¼Ò¹ýÌì '''
    #¹¦ÄÜ¿ªÆôÅжÏ
    if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_SignDay):
        GameWorld.DebugLog("Íæ¼Ò¹¥»÷²»×㣬먦ÆôÇ©µ½¹¦ÄÜ PlayerLv=%s" % curPlayer.GetLV())
        return  
    curSignNum = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DayLoginSignNum)
    #Ç©µ½ÌìÊýÒÑÂú×î´óÖµ£¬Ë¢Ð°ñµ¥
    if curSignNum >= GetSignAwardCountMax():
        GameWorld.DebugLog("ÀÛ¼ÆÇ©µ½ÌìÊýÂúÖØÖÃ! curSignNum=%s" % curSignNum)
        ResetDaySign(curPlayer, 1)
        return
    
    #Ë¢ÐÂÊÇ·ñÇ©µ½¼Ç¼
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DayLoginSignState, 0)
    Sync_SignDayInfo(curPlayer)
    return
 
def ResetDaySign(curPlayer, isMulti=0):
    ''' ÖØÖÃÇ©µ½ 
    @param isMulti: ÊÇ·ñ´ÎÔÂÆð
    '''
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DayLoginSignIsMulti, isMulti)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DayLoginSignNum, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DayLoginSignState, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DayLoginSignStartTime, int(time.time()))
    if isMulti:
        Sync_SignDayInfo(curPlayer)
    else:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TotalSignNum, 0)
    return
 
def GetCanAddSignNum(curPlayer):
    ## »ñÈ¡¿É²¹Ç©ÌìÊý
    curTime = int(time.time())
    startTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DayLoginSignStartTime) # ¿ªÊ¼Ê±¼ä
    if not startTime:
        return 0
    if curTime < startTime:
        return 0
    signNumMax = GetSignAwardCountMax()
    signNumMax = min(GameWorld.GetDiff_Day(curTime, startTime) + 1, signNumMax) # ×î´ó¿ÉÇ©µ½´ÎÊý
    signState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DayLoginSignState) # ½ñÈÕÊÇ·ñÒÑÇ©µ½
    signCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DayLoginSignNum) # ÒÑÇ©µ½´ÎÊý
    signNumRemain = signNumMax - signCount # Ê£Óà¿ÉÇ©µ½´ÎÊý
    if not signState:
        signNumRemain -= 1
    signNumRemain = max(0, signNumRemain)
    #GameWorld.DebugLog("×î´ó¿ÉÇ©µ½´ÎÊý=%s,ÒÑÇ©µ½´ÎÊý=%s,½ñÌìÊÇ·ñÒÑÇ©µ½=%s,¿É²¹Ç©´ÎÊý=%s" 
    #                   % (signNumMax, signCount, signState, signNumRemain), curPlayer.GetPlayerID())
    return signNumRemain
 
## Í¨ÖªÇ©µ½´ÎÊý½±ÀøÁìÈ¡Çé¿ö
#  @param curPlayer: Íæ¼ÒʵÀý
#  @return: None
def Sync_SignDayInfo(curPlayer):
    signInfo = ChPyNetSendPack.tagMCDaySignInfo()
    signInfo.Clear()
    signInfo.DaySignCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DayLoginSignNum)
    signInfo.ReplenishSignCount = GetCanAddSignNum(curPlayer)
    signInfo.IsSign = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DayLoginSignState)
    isFrist = 0 if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DayLoginSignIsMulti) else 1
    signInfo.IsFrist = isFrist
    signInfo.TotalSignCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TotalSignNum)
    NetPackCommon.SendFakePack(curPlayer, signInfo)
    return
 
##¸øÓèÍæ¼ÒÎïÆ·
def __GivePlayerItemByItemInfoList(curPlayer, awardInfoList, mailTypeKey):   
    signCount = len(awardInfoList)
    
    packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, signCount)
    if packSpace >= signCount:
        for awardInfo in awardInfoList:
            ItemControler.GivePlayerItem(curPlayer, awardInfo[0], awardInfo[1], 0, [IPY_GameWorld.rptItem]) 
    else:       
        GameWorld.DebugLog("±³°üÒÑÂú Óʼþ·¢ËÍÎïÆ·")
        PlayerControl.SendMailByKey(mailTypeKey, [curPlayer.GetPlayerID()], awardInfoList)
    return