hxp
2025-10-09 e37a3c136624264a1f862795ad2e5468dabe0c9d
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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerSignDay
#
# @todo:Ç©µ½
# @author hxp
# @date 2025-10-09
# @version 1.0
#
# ÏêϸÃèÊö: Ç©µ½
#
#-------------------------------------------------------------------------------
#"""Version = 2025-10-09 16:30"""
#-------------------------------------------------------------------------------
 
import ObjPool
import DBDataMgr
import PlayerMail
import ShareDefine
import NetPackCommon
import ItemControler
import ChPyNetSendPack
import PlayerControl
import IpyGameDataPY
import GameWorld
import ChConfig
 
SignInState_None = 0
SignInState_Sign = 1 # ÒÑÇ©µ½
SignInState_Supplement = 2 # ¿É²¹Ç©
SignInState_Got = 3 # ÒÑÁìÈ¡
 
#//A5 09 Íæ¼ÒÇ©µ½Áì½± #tagCSDaySign
#
#struct    tagCSDaySign
#{
#    tagHead         Head;
#    BYTE        Day;    // µÚxÌ죬´Ó1¿ªÊ¼
#};
def OnSignDay(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    signDay = clientData.Day
    
    bit = signDay - 1
    state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_SignInState, bit, False)
    if state == SignInState_Got:
        GameWorld.DebugLog("¸ÃÌìÒÑÇ©µ½Áì½±¹ýÁË£¡ signDay=%s" % signDay)
        return
    
    ipyData = IpyGameDataPY.GetIpyGameData("SignIn", signDay)
    if not ipyData:
        return
    awardItemList = ipyData.GetAwardItemList()
    if not awardItemList:
        return
    
    moneyType, moneyValue = 0, 0
    # ²¹Ç©
    if state == SignInState_Supplement:
        moneyType, moneyValue = IpyGameDataPY.GetFuncEvalCfg("SignInSet", 1)
        if not PlayerControl.HaveMoney(curPlayer, moneyType, moneyValue):
            return
    elif state != SignInState_Sign:
        GameWorld.DebugLog("µ±Ç°ÌìÇ©µ½×´Ì¬²»¿ÉÁìȡǩµ½½±Àø! signDay=%s,state=%s" % (signDay, state))
        return
    
    if moneyType and moneyValue:
        PlayerControl.PayMoney(curPlayer, moneyType, moneyValue, ChConfig.Def_Cost_AddSignDay)
    befValue, updValue = GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_SignInState, bit, SignInState_Got, False)
    GameWorld.DebugLog("Ç©µ½Áì½±: signDay=%s,state=%s,befValue=%s,updValue=%s" % (signDay, state, befValue, updValue))
    
    ItemControler.GivePlayerItemOrMail(curPlayer, awardItemList, event=["SignDay", False, {}])
    Sync_SignDayInfo(curPlayer)
    return
 
## Ç©µ½×ܽ±ÀøÌìÊý
def GetSignAwardCountMax(): return IpyGameDataPY.IPY_Data().GetSignInCount()
 
def SignDayOnLogin(curPlayer):
    __doAutoSingIn(curPlayer)
    return
 
def SignDayOnDay(curPlayer):
    __doAutoSingIn(curPlayer)
    return
 
def ResetDaySign(curPlayer):
    ## ÖØÖÃÇ©µ½
    
    signInMax = GetSignAwardCountMax()
    GameWorld.DebugLog("ÖØÖÃÇ©µ½: signInMax=%s" % (signInMax), curPlayer.GetPlayerID())
    
    #²¹·¢Î´ÁìÈ¡½±Àø
    mailItemDict = {}
    for day in range(1, 1 + signInMax):
        state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_SignInState, day - 1, False)
        if state != SignInState_Sign: # ÒÑÇ©µ½Î´ÁìÈ¡µÄ
            continue
        ipyData = IpyGameDataPY.GetIpyGameData("SignIn", day)
        if not ipyData:
            break
        awardItemList = ipyData.GetAwardItemList()
        for itemInfo in awardItemList:
            itemID, itemCount = itemInfo[:2]
            mailItemDict[itemID] = mailItemDict.get(itemID, 0) + itemCount
        GameWorld.DebugLog("Ç©µ½Î´ÁìÈ¡½±Àø²¹·¢: day=%s,awardItemList=%s,%s" % (day, awardItemList, mailItemDict), curPlayer.GetPlayerID())
    if mailItemDict:
        PlayerMail.SendMailByKey("SignDay", curPlayer.GetPlayerID(), mailItemDict)
        
    keyNumMax = signInMax / 9 + 1 # Ã¿¸ö¿ÉÒԼǼ9ÌìµÄ״̬
    for num in range(keyNumMax):
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_SignInState % num, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_SignInLastDay, 0)
    __doAutoSingIn(curPlayer)
    return
 
def __doAutoSingIn(curPlayer):
    ## Ö´ÐÐ×Ô¶¯Ç©µ½£¬½ö×öÇ©µ½±ê¼Ç£¬·ÇÁì½±
    
    signInMax = GetSignAwardCountMax()
    lastDay = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_SignInLastDay)
    
    isMixServer = DBDataMgr.GetEventTrigMgr().GetValue(ShareDefine.Def_IsMixServer)
    if isMixServer:
        serverDay = DBDataMgr.GetEventTrigMgr().GetValue(ShareDefine.Def_MixServerDay) + 1
    else:
        serverDay = DBDataMgr.GetEventTrigMgr().GetValue(ShareDefine.Def_ServerDay) + 1
        
    if lastDay:
        signInRound = (serverDay - 1) / signInMax
        signInRoundLast = (lastDay - 1) / signInMax
        if signInRound != signInRoundLast:
            ResetDaySign(curPlayer)
            return
        
    canSignInMax = (serverDay - 1) % signInMax + 1
    for day in range(1, 1 + canSignInMax):
        bit = day - 1
        if GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_SignInState, bit, False):
            continue
        state = SignInState_Sign if day == canSignInMax else SignInState_Supplement
        GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_SignInState, bit, state, False)
        GameWorld.DebugLog("¸üÐÂÇ©µ½×´Ì¬: day=%s/%s,state=%s,isMixServer=%s,serverDay=%s" % (day, signInMax, state, isMixServer, serverDay))
        
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_SignInLastDay, serverDay)
    Sync_SignDayInfo(curPlayer)
    return True
 
def Sync_SignDayInfo(curPlayer):
    signInMax = GetSignAwardCountMax()
    clientPack = ObjPool.GetPoolMgr().acquire(ChPyNetSendPack.tagSCDaySignInfo)
    clientPack.SignStateList = []
    for bit in range(signInMax):
        state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_SignInState, bit, False)
        clientPack.SignStateList.append(state)
    clientPack.Count = len(clientPack.SignStateList)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return