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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerTask
#
# @todo:Íæ¼ÒÈÎÎñ
# @author hxp
# @date 2023-12-20
# @version 1.0
#
# ÏêϸÃèÊö: Íæ¼ÒÈÎÎñ£¬¼ò»¯°æÈÎÎñ£¬ÓÐÇÒ½öÓÐÒ»¸ö½øÐÐÖеÄÈÎÎñ
#
#-------------------------------------------------------------------------------
#"""Version = 2023-12-20 12:30"""
#-------------------------------------------------------------------------------
 
import GameWorld
import IpyGameDataPY
import PlayerControl
import NetPackCommon
import ChPyNetSendPack
import ItemControler
import IPY_GameWorld
import ShareDefine
import ChConfig
 
def OnPlayerLogin(curPlayer):
    __giveNewTask(curPlayer)
    SyncTaskInfo(curPlayer)
    return
 
def __giveNewTask(curPlayer):
    ## ¸øÐÂÈÎÎñ
    taskIDList = GetTaskIDList()
    if not taskIDList:
        return
    playerID = curPlayer.GetPlayerID()
    taskID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskID)
    lastTaskID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskIDLast)
    newTaskID = 0
    if not taskID and not lastTaskID:
        newTaskID = taskIDList[0]
        GameWorld.DebugLog("¸øµÚÒ»¸öÈÎÎñ: newTaskID=%s" % (newTaskID), playerID)
        
    elif not taskID and lastTaskID:
        # Ã»Óе±Ç°ÈÎÎñ£¬¸øÏÂÒ»¸öÈÎÎñ
        if lastTaskID not in taskIDList:
            GameWorld.ErrLog("ÕÒ²»µ½ÉÏÒ»´ÎÍê³ÉµÄÈÎÎñID! lastTaskID=%s" % lastTaskID, playerID)
            return
        lastIndex = taskIDList.index(lastTaskID)
        if lastIndex >= len(taskIDList) - 1:
            GameWorld.DebugLog("ÒѾ­Íê³ÉÁËËùÓÐÈÎÎñ: lastTaskID=%s" % (lastTaskID), playerID)
            return
        newTaskID = taskIDList[lastIndex + 1]
        GameWorld.DebugLog("¸øÏÂÒ»¸öÈÎÎñ: newTaskID=%s,lastTaskID=%s" % (newTaskID, lastTaskID), playerID)
        
    if not newTaskID:
        return
    ipyData = IpyGameDataPY.GetIpyGameData("Task", newTaskID)
    if not ipyData:
        return
    taskType = ipyData.GetTaskType()
    conds = ipyData.GetTaskConds()
    needValue = ipyData.GetNeedValue()
    taskValue = 0
    
    if taskType == ChConfig.TaskType_LV:
        taskValue = curPlayer.GetLV()
    elif taskType == ChConfig.TaskType_FBPass:
        if len(conds) != 2:
            return
        mapID, lineID = conds
        grade = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_Player_Dict_PlayerFBStar_MapId, lineID, False, [mapID])
        taskValue = 1 if grade > 0 else 0
        
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TaskIDLast, taskID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TaskID, newTaskID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TaskValue, taskValue)
    GameWorld.DebugLog("½Óµ½ÐÂÈÎÎñ: newTaskID=%s,taskValue=%s/%s" % (newTaskID, taskValue, needValue), playerID)
    return
 
def GetTaskIDList():
    ## »ñÈ¡ËùÓеÄÈÎÎñIDÁбí
    key = "TaskIDList"
    taskIDList = IpyGameDataPY.GetConfigEx(key)
    if not taskIDList:
        taskIDList = []
        ipyDataMgr = IpyGameDataPY.IPY_Data()
        for index in xrange(ipyDataMgr.GetTaskCount()):
            ipyData = ipyDataMgr.GetTaskByIndex(index)
            taskIDList.append(ipyData.GetTaskID())
        IpyGameDataPY.SetConfigEx(key, taskIDList)
        GameWorld.Log("ÈÎÎñIDÁбí: %s" % taskIDList)
    return taskIDList
 
def UpdTaskValue(curPlayer, taskType, setValue):
    ## ¸üÐÂÈÎÎñ½ø¶È
    taskID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskID)
    if not taskID:
        return
    ipyData = IpyGameDataPY.GetIpyGameData("Task", taskID)
    if not ipyData:
        return
    if ipyData.GetTaskType() != taskType:
        return
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TaskValue, setValue)
    SyncTaskInfo(curPlayer)
    GameWorld.DebugLog("¸üÐÂÈÎÎñ½ø¶È: taskType=%s,taskID=%s,setValue=%s" % (taskType, taskID, setValue), curPlayer.GetPlayerID())
    return
 
def AddTaskValue(curPlayer, taskType, addValue=1, conds=[]):
    ## Ôö¼ÓÈÎÎñ½ø¶È
    taskID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskID)
    if not taskID:
        return
    ipyData = IpyGameDataPY.GetIpyGameData("Task", taskID)
    if not ipyData:
        return
    if ipyData.GetTaskType() != taskType:
        return
    if taskType == ChConfig.TaskType_FBPass:
        taskConds = ipyData.GetTaskConds()
        if len(conds) != 2 or len(taskConds) != 2:
            return
        if conds[0] != taskConds[0]:
            return
        if conds[1] < taskConds[1]:
            return
    finishNeedValue = ipyData.GetNeedValue()
    curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskValue)
    if curValue >= finishNeedValue:
        return
    updValue = min(curValue + addValue, ShareDefine.Def_UpperLimit_DWord)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TaskValue, updValue)
    SyncTaskInfo(curPlayer)
    GameWorld.DebugLog("Ôö¼ÓÈÎÎñ½ø¶È: taskType=%s,taskID=%s,addValue=%s,updValue=%s" % (taskType, taskID, addValue, updValue), curPlayer.GetPlayerID())
    return
 
def GetTaskAward(curPlayer, taskID):
    ## ÁìÈ¡ÈÎÎñ½±Àø
    playerID = curPlayer.GetPlayerID()
    curTaskID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskID)
    if taskID != curTaskID:
        GameWorld.DebugLog("·Çµ±Ç°ÈÎÎñ: curTaskID=%s" % curTaskID, playerID)
        return
    ipyData = IpyGameDataPY.GetIpyGameData("Task", taskID)
    if not ipyData:
        return
    needValue = ipyData.GetNeedValue()
    awardItemList = ipyData.GetAwardItemList()
    curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskValue)
    if curValue < needValue:
        GameWorld.DebugLog("ÈÎÎñ½ø¶È²»×ãÎÞ·¨Áì½±: taskID=%s,curValue=%s < %s" % (taskID, curValue, needValue), playerID)
        return
    if not ItemControler.CheckPackSpaceEnough(curPlayer, awardItemList):
        return
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TaskIDLast, taskID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TaskID, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TaskValue, 0)
    
    for itemID, itemCount, isAuctionItem in awardItemList:
        ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isAuctionItem, [IPY_GameWorld.rptItem])
        
    __giveNewTask(curPlayer)
    SyncTaskInfo(curPlayer)
    return
 
def SyncTaskInfo(curPlayer):
    clientPack = ChPyNetSendPack.tagMCTaskInfo()
    clientPack.TaskID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskID)
    clientPack.CurValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TaskValue)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return