hxp
2025-06-03 887a4882a958e29923e58805bf552f3f13499693
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerTask
#
# @todo:Íæ¼ÒÈÎÎñ
# @author hxp
# @date 2025-05-28
# @version 1.0
#
# ÏêϸÃèÊö: Íæ¼ÒÈÎÎñ
#
#-------------------------------------------------------------------------------
#"""Version = 2025-05-28 16:00"""
#-------------------------------------------------------------------------------
 
import GameWorld
import IpyGameDataPY
import PlayerControl
import NetPackCommon
import ChPyNetSendPack
import ItemControler
import IPY_GameWorld
import GameFuncComm
import ShareDefine
import ChConfig
 
def GetTaskIDList(taskGroup):
    ## »ñȡij¸öÈÎÎñ·Ö×éËùÓÐÈÎÎñIDÁбí
    key = "TaskIDListDict"
    taskIDListDict = IpyGameDataPY.GetConfigEx(key)
    if not taskIDListDict:
        taskIDListDict = {}
        ipyDataMgr = IpyGameDataPY.IPY_Data()
        for index in xrange(ipyDataMgr.GetTaskCount()):
            ipyData = ipyDataMgr.GetTaskByIndex(index)
            taskGroup = ipyData.GetTaskGroup()
            taskID = ipyData.GetTaskID()
            if taskGroup not in taskIDListDict:
                taskIDListDict[taskGroup] = []
            taskIDList = taskIDListDict[taskGroup]
            if taskID not in taskIDList:
                taskIDList.append(taskID)
        IpyGameDataPY.SetConfigEx(key, taskIDListDict)
        GameWorld.Log("ÈÎÎñIDÁбí: %s" % taskIDListDict)
    return taskIDListDict.get(taskGroup, [])
 
def OnPlayerLogin(curPlayer):
    __fixRefreshTask(curPlayer)
    if not __giveNewTask(curPlayer, ChConfig.TaskGroup_Main):
        SyncTaskInfo(curPlayer)
    return
 
def __fixRefreshTask(curPlayer):
    ## ¾ÀÕýË¢ÐÂÈÎÎñֵ״̬µÈ£¬Ò»°ãÓÃÓÚÐÞ¸ÄÈÎÎñÅäÖõȣ¬Íæ¼ÒµÇ¼¼ì²é
    
    playerID = curPlayer.GetPlayerID()
    fixGroupList = []
    for taskGroup in ChConfig.TaskGroupList:
        taskID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskID % taskGroup)
        if not taskID:
            continue
        ipyData = IpyGameDataPY.GetIpyGameData("Task", taskID)
        if not ipyData:
            continue
        
        curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskValue % taskGroup)
        curState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskState % taskGroup)
        if curState == ChConfig.TaskState_CanGet:
            continue
        
        needFix = False
        
        needValue = ipyData.GetNeedValue()
        taskValue = __GetTaskValue(curPlayer, ipyData)
        
        # ¿ÉÄÜÐÞ¸ÄÌõ¼þÅäÖú󣬵¼ÖÂÈÎÎñÖµ²»Ò»Ö£¬ÐèÒªÐÞÕý
        if taskValue and taskValue != curValue:
            GameWorld.Log("ÐèÒªÐÞÕýÈÎÎñ½ø¶È: taskID=%s,curValue=%s,taskValue=%s" % (taskID, curValue, taskValue), playerID)
            curValue = taskValue
            needFix = True
            
        # ¿ÉÄÜÐ޸ĽµµÍÁËËùÐèÈÎÎñÖµ£¬ÐèÒªÐÞÕýÏÂÍê³É״̬
        if curValue >= needValue and curState != ChConfig.TaskState_CanGet:
            GameWorld.Log("ÐèÒªÐÞÕýÈÎÎñ״̬: taskID=%s,curValue=%s,needValue=%s,curState=%s" % (taskID, curValue, needValue, curState), playerID)
            needFix = True
            
        if not needFix:
            continue
                
        SetTaskValue(curPlayer, ipyData, taskValue, False)
        fixGroupList.append(taskGroup)
        
    if fixGroupList:
        SyncTaskInfo(curPlayer, fixGroupList)
        
    return
 
def __giveNewTask(curPlayer, taskGroup=ChConfig.TaskGroup_Main):
    ## ¸øÐÂÈÎÎñ
    taskIDList = GetTaskIDList(taskGroup)
    if not taskIDList:
        return
    playerID = curPlayer.GetPlayerID()
    taskID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskID % taskGroup)
    lastTaskID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskIDLast % taskGroup)
    newTaskID = 0
    if not taskID and not lastTaskID:
        newTaskID = taskIDList[0]
        GameWorld.DebugLog("¸øµÚÒ»¸öÈÎÎñ: taskGroup=%s,newTaskID=%s" % (taskGroup, newTaskID), playerID)
        
    elif not taskID and lastTaskID:
        # Ã»Óе±Ç°ÈÎÎñ£¬¸øÏÂÒ»¸öÈÎÎñ
        if lastTaskID not in taskIDList:
            GameWorld.ErrLog("ÕÒ²»µ½ÉÏÒ»´ÎÍê³ÉµÄÈÎÎñID! taskGroup=%s,lastTaskID=%s" % (taskGroup, lastTaskID), playerID)
            return
        lastIndex = taskIDList.index(lastTaskID)
        if lastIndex >= len(taskIDList) - 1:
            GameWorld.DebugLog("ÒѾ­Íê³ÉÁËËùÓÐÈÎÎñ: taskGroup=%s,lastTaskID=%s" % (taskGroup, lastTaskID), playerID)
            return
        newTaskID = taskIDList[lastIndex + 1]
        GameWorld.DebugLog("¸øÏÂÒ»¸öÈÎÎñ: taskGroup=%s,newTaskID=%s,lastTaskID=%s" % (taskGroup, newTaskID, lastTaskID), playerID)
        
    if not newTaskID:
        return
    ipyData = IpyGameDataPY.GetIpyGameData("Task", newTaskID)
    if not ipyData:
        return
    taskValue = __GetTaskValue(curPlayer, ipyData)
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TaskID % taskGroup, newTaskID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TaskValue % taskGroup, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TaskState % taskGroup, ChConfig.TaskState_Doing)
    GameWorld.DebugLog("½Óµ½ÐÂÈÎÎñ: taskGroup=%s,newTaskID=%s" % (taskGroup, newTaskID), playerID)
    return SetTaskValue(curPlayer, ipyData, taskValue)
 
def __GetTaskValue(curPlayer, ipyData):
    ## »ñÈ¡ÈÎÎñÀàÐ͵±Ç°½ø¶ÈÖµ£¬Ò»°ãÖ±½Ó UpdTaskValue µÄÀàÐÍ»áÓõ½
    taskValue = 0 # Ä¬ÈÏ0
    taskType = ipyData.GetTaskType()
    conds = ipyData.GetTaskConds()
    
    if taskType == ChConfig.TaskType_LV:
        taskValue = curPlayer.GetLV()
        
    elif taskType == ChConfig.TaskType_FBPass:
        if len(conds) != 2:
            return 0
        mapID, lineID = conds
        passLineID = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FBPassLineID % mapID)
        taskValue = 1 if passLineID >= lineID else 0
        
    elif taskType == ChConfig.TaskType_TreeLV:
        taskValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreeLV)
        
    elif taskType == ChConfig.TaskType_RealmLV:
        taskValue = curPlayer.GetOfficialRank()
        
    return taskValue
 
def UpdTaskValue(curPlayer, taskType):
    ## ¸üÐÂÈÎÎñ½ø¶È
    for taskGroup in ChConfig.TaskGroupList:
        ipyData = __GetDoingTaskIpyData(curPlayer, taskGroup, taskType)
        if not ipyData:
            continue
        curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskValue % taskGroup)
        taskValue = __GetTaskValue(curPlayer, ipyData)
        if taskValue <= curValue:
            # ÓÐÔö³¤²Å¸üÐÂ
            continue
        SetTaskValue(curPlayer, ipyData, taskValue)
    return
 
def AddTaskValue(curPlayer, taskType, addValue=1, conds=None):
    ## Ôö¼ÓÈÎÎñ½ø¶È
    for taskGroup in ChConfig.TaskGroupList:
        ipyData = __GetDoingTaskIpyData(curPlayer, taskGroup, taskType)
        if not ipyData:
            continue
        if not __CheckTaskCondition(ipyData, conds):
            continue
        curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskValue % taskGroup) + addValue
        SetTaskValue(curPlayer, ipyData, curValue)
    return
 
def __GetDoingTaskIpyData(curPlayer, taskGroup, taskType):
    ## »ñÈ¡ÕýÔÚ½øÐÐÖеÄÈÎÎñipyData
    taskID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskID % taskGroup)
    if not taskID:
        return
    curState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskState % taskGroup)
    if curState != ChConfig.TaskState_Doing:
        return
    ipyData = IpyGameDataPY.GetIpyGameData("Task", taskID)
    if not ipyData:
        return
    if ipyData.GetTaskType() != taskType:
        return
    return ipyData
 
def __CheckTaskCondition(ipyData, conds=None):
    ## ¼ì²éÈÎÎñÌõ¼þÊÇ·ñÂú×ã
    taskType = ipyData.GetTaskType()
    
    # »ñµÃ»õ±Ò
    if taskType == ChConfig.TaskType_GetMoney:
        taskConds = ipyData.GetTaskConds()
        if not conds or len(conds) != len(taskConds):
            return
        if conds[0] != taskConds[0]:
            return
        
    return True
 
def SetTaskValue(curPlayer, taskIpyData, value=0, isNotify=True):
    ## ÉèÖõ±Ç°ÈÎÎñ½ø¶ÈÖµ£¬Í³Ò»´¦ÀíÈÎÎñ״̬¡¢´¥·¢¶îÍâÂß¼­µÈ
    if not taskIpyData:
        return
    playerID = curPlayer.GetPlayerID()
    taskGroup = taskIpyData.GetTaskGroup()
    taskID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskID % taskGroup)
    if taskIpyData.GetTaskID() != taskID:
        return
    curState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskState % taskGroup)
    if curState == ChConfig.TaskState_CanGet:
        return
    taskType = taskIpyData.GetTaskType()
    finishNeedValue = taskIpyData.GetNeedValue()
    value = min(value, finishNeedValue, ShareDefine.Def_UpperLimit_DWord)
    GameWorld.DebugLog("¸üÐÂÈÎÎñ½ø¶È: taskGroup=%s,taskType=%s,taskID=%s,value=%s/%s" 
                       % (taskGroup, taskType, taskID, value, finishNeedValue), playerID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TaskValue % taskGroup, value)
    if value >= finishNeedValue:
        __OnTaskFinish(curPlayer, taskGroup, taskID, taskIpyData)
        
    if isNotify:
        SyncTaskInfo(curPlayer, [taskGroup])
        
    return True
 
def __OnTaskFinish(curPlayer, taskGroup, taskID, taskIpyData):
    GameWorld.DebugLog("ÈÎÎñ½ø¶ÈÍê³É: taskGroup=%s,taskID=%s" % (taskGroup, taskID), curPlayer.GetPlayerID())
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TaskState % taskGroup, ChConfig.TaskState_CanGet)
    return
 
def IsTaskFinish(curPlayer, taskID):
    ## ÈÎÎñÊÇ·ñÒÑÍê³É - ¹æ¶¨Áì½±²ÅËãÍê³É
    ipyData = IpyGameDataPY.GetIpyGameData("Task", taskID)
    if not ipyData:
        return
    taskGroup = ipyData.GetTaskGroup()
    finishTaskID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskIDLast % taskGroup)
    
    if taskID == finishTaskID:
        return True
    
    taskIDList = GetTaskIDList(taskGroup)
    if finishTaskID not in taskIDList or taskID not in taskIDList:
        return
    return taskIDList.index(finishTaskID) >= taskIDList.index(taskID)
 
def GetTaskAward(curPlayer, taskID):
    ## ÁìÈ¡ÈÎÎñ½±Àø
    playerID = curPlayer.GetPlayerID()
    ipyData = IpyGameDataPY.GetIpyGameData("Task", taskID)
    if not ipyData:
        return
    taskGroup = ipyData.GetTaskGroup()
    curTaskID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskID % taskGroup)
    if taskID != curTaskID:
        GameWorld.DebugLog("·Çµ±Ç°ÈÎÎñ: curTaskID=%s" % curTaskID, playerID)
        return
    needValue = ipyData.GetNeedValue()
    awardItemList = ipyData.GetAwardItemList()
    curState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskState % taskGroup)
    curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskValue % taskGroup)
    if curState != ChConfig.TaskState_CanGet:
        GameWorld.DebugLog("ÈÎÎñδÍê³ÉÎÞ·¨Áì½±: taskID=%s,curValue=%s/%s,curState=%s" % (taskID, curValue, needValue, curState), playerID)
        return
    if not ItemControler.CheckPackSpaceEnough(curPlayer, awardItemList):
        return
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TaskIDLast % taskGroup, taskID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TaskID % taskGroup, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TaskValue % taskGroup, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TaskState % taskGroup, 0)
    
    for itemID, itemCount, isAuctionItem in awardItemList:
        ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isAuctionItem, [IPY_GameWorld.rptItem])
        
    if not __giveNewTask(curPlayer, taskGroup):
        SyncTaskInfo(curPlayer, [taskGroup])
        
    GameFuncComm.DoFuncOpenLogic(curPlayer, [taskID])
    return
 
def SyncTaskInfo(curPlayer, taskGroupList=None):
    syncGroupList = taskGroupList if taskGroupList != None else ChConfig.TaskGroupList
    if not syncGroupList:
        return
    
    taskList = []
    for taskGroup in syncGroupList:
        task = ChPyNetSendPack.tagMCTask()
        task.TaskGroup = taskGroup
        task.TaskID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskID % taskGroup)
        task.CurValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskValue % taskGroup)
        task.State = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskState % taskGroup)
        taskList.append(task)
        
    if not taskList:
        return
    
    clientPack = ChPyNetSendPack.tagMCTaskInfo()
    clientPack.TaskList = taskList
    clientPack.TaskCount = len(clientPack.TaskList)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return