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 Player.PlayerActivity
#
# @todo:ÈÕ³£»îÔ¾ÈÎÎñ
# @author hxp
# @date 2025-10-16
# @version 1.0
#
# ÏêϸÃèÊö: ÈÕ³£»îÔ¾ÈÎÎñ
#
#-------------------------------------------------------------------------------
#"""Version = 2025-10-16 19:30"""
#-------------------------------------------------------------------------------
 
import ChConfig
import ShareDefine
import NetPackCommon
import PlayerControl
import ChPyNetSendPack
import PlayerZhanling
import ItemControler
import IpyGameDataPY
import GameWorld
import DBDataMgr
import ObjPool
 
def OnDay(curPlayer):
    CheckResetWeekActivity(curPlayer)
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityTotal, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityAward, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DailyTaskState, 0)
    
    syncTaskCondList = []
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for index in range(ipyDataMgr.GetDailyTaskCount()):
        ipyData = ipyDataMgr.GetDailyTaskByIndex(index)
        taskType = ipyData.GetTaskType()
        conds = ipyData.GetTaskConds()
        tcList = [taskType, conds]
        if tcList in syncTaskCondList:
            continue
        if not GetDailyTaskValue(curPlayer, taskType, conds):
            continue
        SetDailyTaskValue(curPlayer, taskType, conds, 0)
        syncTaskCondList.append(tcList)
    SyncDailyTaskInfo(curPlayer, isAll=True)
    return
 
def OnPlayerLogin(curPlayer):
    CheckResetWeekActivity(curPlayer)
    SyncDailyTaskInfo(curPlayer, isAll=True)
    return
 
def CheckResetWeekActivity(curPlayer):
    ## ¼ì²éÖØÖÃÿÖÜ»îÔ¾½±ÀøÕ½Áî
    playerActivityWeek = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityWeek)
    serverDay = DBDataMgr.GetEventTrigMgr().GetValue(ShareDefine.Def_ServerDay) + 1
    nowActivityWeek = (serverDay - 1) / 7 # Ôݶ¨7ÌìÒ»ÂÖ£¬°´¿ª·þÌìËã
    GameWorld.DebugLog("¼ì²éÖØÖÃÖÜ»îÔ¾½±ÀøÕ½Áî! serverDay=%s,nowActivityWeek=%s,playerActivityWeek=%s" 
                       % (serverDay, nowActivityWeek, playerActivityWeek), curPlayer.GetPlayerID())
    if nowActivityWeek and playerActivityWeek != nowActivityWeek:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityWeek, nowActivityWeek)
        PlayerZhanling.ResetZhanling(curPlayer, PlayerZhanling.ZhanlingType_WeekActivity)
    return
 
def AddDailyTaskValue(curPlayer, taskType, addValue=1, conds=[]):
    ## Ôö¼ÓÈÎÎñ½ø¶È
    ipyDataList = IpyGameDataPY.GetIpyGameDataListNotLog("DailyTask", taskType)
    if not ipyDataList:
        return
    
    maxValue = 0
    for ipyData in ipyDataList:
        taskConds = ipyData.GetTaskConds()
        if conds or taskConds:
            # ¿É°´ÈÎÎñÀàÐÍÀ©Õ¹²»Í¬µÄÌõ¼þÑéÖ¤·½Ê½
            if taskConds != tuple(conds):
                #GameWorld.DebugLog("Ìõ¼þ²»Í¬taskConds=%s,conds=%s" % (taskConds, conds))
                continue
        needValue = ipyData.GetNeedValue()
        maxValue = max(maxValue, needValue)
        
    curValue = GetDailyTaskValue(curPlayer, taskType, conds)
    if curValue >= maxValue:
        return
    updValue = min(curValue + addValue, maxValue)
    SetDailyTaskValue(curPlayer, taskType, conds, updValue)
    SyncDailyTaskInfo(curPlayer, taskType, conds)
    return
 
def GetDailyTaskValue(curPlayer, taskType, conds=[]):
    ##»ñÈ¡Íê³É¶È
    condition = "" if not conds else str(list(conds)).replace(" ", "")[1:-1]
    return curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyTaskValue % (taskType, condition))
def SetDailyTaskValue(curPlayer, taskType, conds, value):
    ##ÉèÖÃÍê³É¶È
    condition = "" if not conds else str(list(conds)).replace(" ", "")[1:-1]
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DailyTaskValue % (taskType, condition), value)
    GameWorld.DebugLog("¸üÐÂÿÈÕÈÎÎñ½ø¶ÈÖµ: taskType=%s,conds=%s,value=%s" % (taskType, condition, value), curPlayer.GetPlayerID())
    return
 
def GetDailyTaskAward(curPlayer, taskID):
    playerID = curPlayer.GetPlayerID()
    ipyData = IpyGameDataPY.GetIpyGameDataByCondition("DailyTask", {"TaskID":taskID})
    if not ipyData:
        return
    
    taskState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyTaskState)
    if taskState&pow(2, taskID):
        GameWorld.DebugLog("ÿÈÕÈÎÎñÒѾ­ÁìÈ¡¹ý½±Àø! taskID=%s,taskState=%s" % (taskID, taskState), playerID)
        return
    
    taskType = ipyData.GetTaskType()
    conds = ipyData.GetTaskConds()
    needValue = ipyData.GetNeedValue()
    curValue = GetDailyTaskValue(curPlayer, taskType, conds)
    if curValue < needValue:
        GameWorld.DebugLog("ÿÈÕÈÎÎñ½ø¶È²»×㣬ÎÞ·¨Áì½±! taskID=%s,taskType=%s,conds=%s,curValue=%s < %s" % (taskID, taskType, conds, curValue, needValue), playerID)
        return
    
    updState = taskState|pow(2, taskID)
    GameWorld.DebugLog("ÿÈÕÈÎÎñÁì½±! taskID=%s,updState=%s" % (taskID, updState), playerID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DailyTaskState, updState)
    DoAddActivity(curPlayer, ipyData.GetAwardLiveness())
    return
 
def DoAddActivity(curPlayer, addValue):
    ## Ôö¼Ó»îÔ¾Öµ
    updValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityTotal) + addValue
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityTotal, updValue)
    SyncDailyTaskInfo(curPlayer)
    GameWorld.DebugLog("Ôö¼Ó»îÔ¾¶È: addValue=%s,updValue=%s" % (addValue, updValue), curPlayer.GetPlayerID())
    PlayerZhanling.AddZhanlingValue(curPlayer, PlayerZhanling.ZhanlingType_WeekActivity, addValue)
    return updValue
 
def GetActivityAward(curPlayer, awardID):
    ## ÁìÈ¡»îÔ¾¶È½±Àø
    
    playerID = curPlayer.GetPlayerID()
    ipyData = IpyGameDataPY.GetIpyGameData("DailyLivenessReward", awardID)
    if not ipyData:
        return
    
    awardState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityAward)
    if awardState&pow(2, awardID):
        GameWorld.DebugLog("»îÔ¾½±ÀøIDÒÑÁìÈ¡! awardID=%s,awardState=%s" % (awardID, awardState), playerID)
        return
    needActivity = ipyData.GetNeedLiveness()
    activityTotal = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityTotal)
    # ÅжϻîÔ¾¶È
    if activityTotal < needActivity:
        GameWorld.DebugLog("Áì½±»îÔ¾¶È²»×ã! awardID=%s,activityTotal=%s < %s" % (awardID, activityTotal, needActivity), playerID)
        return
    
    awardItemList = ipyData.GetAwardItemList()
    updState = awardState|pow(2, awardID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityAward, updState)
    GameWorld.DebugLog("Áì½±»îÔ¾¶È! awardID=%s,updState=%s,awardItemList=%s" % (awardID, updState, awardItemList), playerID)
    ItemControler.GivePlayerItemOrMail(curPlayer, awardItemList, event=["ActivityAward", False, {}])
    SyncDailyTaskInfo(curPlayer)
    return
 
def SyncDailyTaskInfo(curPlayer, taskType=0, conds=[], isAll=False):
    clientPack = ObjPool.GetPoolMgr().acquire(ChPyNetSendPack.tagSCDailyTaskInfo)
    clientPack.ActivityTotal = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityTotal)
    clientPack.ActivityAward = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityAward)
    clientPack.DailyTaskState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyTaskState)
    syncTaskCondList = []
    if isAll:
        ipyDataMgr = IpyGameDataPY.IPY_Data()
        for index in range(ipyDataMgr.GetDailyTaskCount()):
            ipyData = ipyDataMgr.GetDailyTaskByIndex(index)
            taskType = ipyData.GetTaskType()
            conds = ipyData.GetTaskConds()
            tcList = [taskType, conds]
            if tcList in syncTaskCondList:
                continue
            syncTaskCondList.append(tcList)
    elif taskType:
        syncTaskCondList = [[taskType, conds]]
        
    clientPack.TaskList = []
    for taskType, conds in syncTaskCondList:
        task = ObjPool.GetPoolMgr().acquire(ChPyNetSendPack.tagSCDailyTask)
        task.TaskType = taskType
        task.Conds = conds
        task.CLen = len(task.Conds)
        task.CurValue = GetDailyTaskValue(curPlayer, taskType, conds)
        clientPack.TaskList.append(task)
    clientPack.TaskCount = len(clientPack.TaskList)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return