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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
#
##@package Player.PlayerArrestTask
#
# @todo:Íæ¼ÒÐüÉÍÈÎÎñ
# @author xdh
# @date 2017-07-15
# @version 2.5
#
# ÏêϸÃèÊö: Íæ¼ÒÐüÉÍÈÎÎñ
#---------------------------------------------------------------------
#"""Version = 2017-07-15 17:30"""
#---------------------------------------------------------------------
 
import ReadChConfig
import ChConfig
import ChPyNetSendPack
import NetPackCommon
import ShareDefine
import GameWorld
import ItemCommon
import IPY_GameWorld
import PlayerControl
import ItemControler
import QuestCommon
import EventShell
import PlayerActivity
import GameFuncComm
 
## OnDay
#  @param curPlayer Íæ¼ÒʵÀý
#  @return
def OnDay(curPlayer):
    #ÖØÖý±Àø¡¢»ý·Ö
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_ArrestTaskAwardRecord, 0)
    #PlayerControl.SetPlayerCurrency(curPlayer, ShareDefine.TYPE_Price_ArrestPoint, 0)
    #ÉèÖÃÐüÉÍÈÎÎñ´ÎÊý
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_ArrestTaskFinishCnt, 0)
    #ɾ³ýÒÑÁìÈ¡µÄÈÎÎñ
    if curPlayer.FindMission(ChConfig.Def_ArrestMissionID):
        QuestCommon.DeleteMission(curPlayer, ChConfig.Def_ArrestMissionID)
 
    OnDeleteArrestTask(curPlayer)
    return
 
 
## OnLogin
#  @param curPlayer Íæ¼ÒʵÀý
#  @return
def OnLogin(curPlayer):
    taskData = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_ArrestTaskData % 1)
    if not taskData:
        #ÈôδˢйýÔòË¢ÐÂÈÎÎñ
        __RefreshArrestTaskNPC(curPlayer)
    #֪ͨ¿Í»§¶Ë¿É½ÓÐüÉÍÈÎÎñµÈ¼¶
    Sync_ArrestTaskInfo(curPlayer)
    return
 
## ÐüÉÍÈÎÎñ¹¦ÄÜ¿ªÆô
def DoArrestTaslOpen(curPlayer):
    __RefreshArrestTaskNPC(curPlayer)
    #֪ͨ¿Í»§¶Ë¿É½ÓÐüÉÍÈÎÎñµÈ¼¶
    Sync_ArrestTaskInfo(curPlayer)
    return
 
## ÅжÏÍæ¼ÒÐüÉÍÈÎÎñ¹¦ÄÜÊÇ·ñ¿ªÆô
#  @param curPlayer Íæ¼ÒʵÀý
#  @return None
def __IsArrestTaskFuncOpen(curPlayer):
    # ÅжÏÍæ¼ÒÐüÉÍÈÎÎñ¹¦ÄÜÊÇ·ñ¿ªÆô
    if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_ArrestTask):
        return False
    return True
 
## Ë¢ÐÂÐüÉÍÈÎÎñ
def OnRefreshArrestTask(index, clientData, tick):
    # ¿ç·þ·þÎñÆ÷¹¦ÄÜÏÞÖÆ
    if GameWorld.IsCrossServer():
        return
    
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    
    if not __IsArrestTaskFuncOpen(curPlayer):
        GameWorld.DebugLog("OnRefreshArrestTask() ¹¦ÄÜ먦Æô")
        return
    
    if curPlayer.FindMission(ChConfig.Def_ArrestMissionID):
        GameWorld.DebugLog("OnRefreshArrestTask Íæ¼ÒÒÑÓÐÐüÉÍÈÎÎñ")
        return
    
    if __IsArrestTaskFullCnt(curPlayer):
        GameWorld.DebugLog("OnRefreshArrestTask Íæ¼Ò½ñÈÕÐüÉÍÈÎÎñ´ÎÊýÒÑ´ïÉÏÏÞ")
        return
    
    curArrestTaskStar = max(1, curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_ArrestTaskStar))  # µ±Ç°ÐüÉÍÈÎÎñÐǼ¶
    
    arrestTaskRefreshDict = ReadChConfig.GetEvalChConfig("ArrestTaskRefresh")
    if curArrestTaskStar not in arrestTaskRefreshDict:
        return
    
    if curArrestTaskStar >= max(arrestTaskRefreshDict):
        GameWorld.DebugLog("ÐüÉÍÈÎÎñÒÑÂú¼¶!")
        return
    
    refreshMoneyType = clientData.MoneyType #½ðÇ®ÀàÐÍ
    
    costMoneyInfoDict = arrestTaskRefreshDict[curArrestTaskStar]
    
    if refreshMoneyType not in costMoneyInfoDict:
        GameWorld.DebugLog("OnRefreshArrestTask ArrestTaskRefresh.txt Î´ÅäÖøýðÇ®ÀàÐÍ curArrestTaskStar=%s,refreshMoneyType=%s" % (curArrestTaskStar, refreshMoneyType))
        return
    
 
    drDict = {"star":curArrestTaskStar}
  
   
    upLvRate, moneyCnt, upLv, downLv = costMoneyInfoDict[refreshMoneyType]
    
    if not PlayerControl.HaveMoney(curPlayer, refreshMoneyType, moneyCnt):
        return
    
    
    if GameWorld.CanHappen(upLvRate, ChConfig.Def_MaxRateValue):
        arrestTaskLv = upLv
    else:
        arrestTaskLv = downLv
    
    if arrestTaskLv <= 0 or arrestTaskLv > len(arrestTaskRefreshDict):
        #ˢкóµÈ¼¶´íÎó
        GameWorld.ErrLog("    OnRefreshArrestTask After arrestTaskLv = %s error!" % (arrestTaskLv))
        return
 
    drDict[ChConfig.Def_Cost_Reason_SonKey] = "Refresh"
    PlayerControl.PayMoney(curPlayer, refreshMoneyType, moneyCnt, ChConfig.Def_Cost_RefreshArrestTask, drDict)
    
    #ÉèÖÃÐüÉÍÈÎÎñµÈ¼¶
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_ArrestTaskStar, arrestTaskLv)
    
    #Ë¢ÐÂÈÎÎñ
    __RefreshArrestTaskNPC(curPlayer)
        
    #֪ͨ¿Í»§¶Ë¿É½ÓÐüÉÍÈÎÎñµÈ¼¶
    Sync_ArrestTaskInfo(curPlayer)
    GameWorld.DebugLog("    Ë¢Ð½á¹û: upLvRate=%s,updTruckLv=%s,drDict=%s" 
                       % (upLvRate, arrestTaskLv, drDict), curPlayer.GetPlayerID()) 
    return
 
## Ë¢ÐÂÈÎÎñ¹Ö
def __RefreshArrestTaskNPC(curPlayer):
    if not __IsArrestTaskFuncOpen(curPlayer):
        GameWorld.DebugLog("OnRefreshArrestTask() ¹¦ÄÜ먦Æô")
        return
    
    arrestTaskRefreshDict = ReadChConfig.GetEvalChConfig("ArrestTaskRefresh")
    needRefreshCnt = len(arrestTaskRefreshDict)
    heroLV = curPlayer.GetLV()
    
    arrestTaskNPCIDDict = ReadChConfig.GetEvalChConfig("ArrestTaskNPCID")
    arrestTaskNPCIDList = sorted(arrestTaskNPCIDDict.iteritems(), key=lambda asd:asd[1])
 
    findNPCIDList = []
    for npcidList, needLV in arrestTaskNPCIDList:
 
        if heroLV < needLV:
            #µÍÓÚµØͼ½øÈëµÈ¼¶µÄ
            break
        isOver = False
        for npcID, npcCnt in npcidList:
            if len(findNPCIDList) < needRefreshCnt -1:
                findNPCIDList.append([npcID, npcCnt])
            else:
                curNPC = GameWorld.GetGameData().FindNPCDataByID(npcID)
                NPCLV = curNPC.GetLV()
                #GameWorld.Log('npcID=%s, NPCLV=%s'%(npcID,NPCLV))
                findNPCIDList.append([npcID, npcCnt])
                
                if heroLV < NPCLV:
                    isOver = True
                    break
        if isOver:
            break
    
    if len(findNPCIDList) < needRefreshCnt:
        GameWorld.DebugLog('    ÐüÉÍÈÎÎñˢРÊýÁ¿²»×ã%s¸ö£¬ findNPCIDList=%s' % (needRefreshCnt, findNPCIDList))
        return
    findNPCIDList = findNPCIDList[-needRefreshCnt:]
    
    GameWorld.DebugLog('    ÐüÉÍÈÎÎñˢР findNPCIDList=%s' % (findNPCIDList))
    #¼Ç¼Êý¾Ý
    for i, npcinfo in enumerate(findNPCIDList):
        npcID, npcCnt = npcinfo
        taskData = __GetArrestTaskData(npcID, npcCnt)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_ArrestTaskData % (i+1), taskData)
    
    
    return 
 
 
 
## Í¨Öª¿Í»§¶Ë¿É½ÓÐüÉÍÈÎÎñµÈ¼¶
def Sync_ArrestTaskInfo(curPlayer):
    if not __IsArrestTaskFuncOpen(curPlayer):
        GameWorld.DebugLog("OnRefreshArrestTask() ¹¦ÄÜ먦Æô")
        return
    arrestTaskPack = ChPyNetSendPack.tagMCArrestTaskInfo()
    arrestTaskPack.Clear()
    arrestTaskPack.TaskStar = max(1, curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_ArrestTaskStar))
    arrestTaskPack.CompleteCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_ArrestTaskFinishCnt)
    arrestTaskPack.AwardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_ArrestTaskAwardRecord)
    
    arrestTaskPack.TaskDataList = []
    arrestTaskRefreshDict = ReadChConfig.GetEvalChConfig("ArrestTaskRefresh")
    arrestTaskPack.Count = len(arrestTaskRefreshDict)
    for i in range(len(arrestTaskRefreshDict)):
        taskData = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_ArrestTaskData % (i+1))
        arrestTaskPack.TaskDataList.append(taskData)
    NetPackCommon.SendFakePack(curPlayer, arrestTaskPack)
    return
 
 
## ½ÓÐüÉÍÈÎÎñ
def OnAcceptArrestTask(curPlayer):
    # ¿ç·þ·þÎñÆ÷¹¦ÄÜÏÞÖÆ
    if GameWorld.IsCrossServer():
        return
    if not __IsArrestTaskFuncOpen(curPlayer):
        GameWorld.DebugLog("OnRefreshArrestTask() ¹¦ÄÜ먦Æô")
        return
    if curPlayer.FindMission(ChConfig.Def_ArrestMissionID):
        GameWorld.DebugLog("OnAcceptArrestTask Íæ¼ÒÒÑÓÐÐüÉÍÈÎÎñ")
        return
    
    if __IsArrestTaskFullCnt(curPlayer):
        GameWorld.DebugLog("OnAcceptArrestTask Íæ¼Ò½ñÈÕÐüÉÍÈÎÎñ´ÎÊýÒÑ´ïÉÏÏÞ")
        return
    
    taskStar = max(1, curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_ArrestTaskStar))
    taskData = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_ArrestTaskData % taskStar)
    npcid = __GetArrestTaskNPCID(taskData)
    npcCnt = __GetArrestTaskNPCCnt(taskData)
    
    curMission = QuestCommon.AddNewMission(curPlayer, ChConfig.Def_ArrestMissionID)
    
    curMission.SetProperty(QuestCommon.Def_Kill_Npc_ID, npcid)
    curMission.SetProperty(QuestCommon.Def_Kill_Npc_ID_Count, npcCnt)
 
    
    QuestCommon.SetPlayerMissionState(curPlayer, curMission, 1)
    curMission.SetMissionState(1)
    #֪ͨ¿Í»§¶Ë
    EventShell.NotifyOneMission(curPlayer, curMission)
    GameWorld.DebugLog("½ÓÐüÉÍÈÎÎñ star=%s,npcid=%s,npcCnt=%s" % (taskStar, npcid, npcCnt))
    return
 
##»ñÈ¡ÅÜ»·ÈÎÎñ½±Àø
# @param curPlayer Íæ¼ÒʵÀý
# @param curMission ÈÎÎñʵÀý
# @param isQuick ÊÇ·ñÒ»¼ü¿ìËÙÍê³É
# @return curExp, curMoney, pfavalue  ÕÒ²»µ½·µ»ØNone
def __GetArrestTaskReward(curPlayer, star):
    reLV = curPlayer.GetLV()                    #²Î¿¼µÈ¼¶
    reExp = PlayerControl.GetPlayerReExp(curPlayer) #²Î¿¼¾­Ñé
    
    
    ArrestTaskAwardDict = ReadChConfig.GetEvalChConfig("ArrestTaskAward")
    curExp = eval(ArrestTaskAwardDict['Exp'])
    curSoul = eval(ArrestTaskAwardDict['Soul'])
    curPoint = eval(ArrestTaskAwardDict['Point'])
    return curExp, curSoul, curPoint
 
## ÐüÉÍÈÎÎñÍê³É ¸ø½±Àø
def OnArrestTaskOver(curPlayer):
    #»îÔ¾
    #PlayerActivity.AddActivityFinishCnt(curPlayer, ShareDefine.ActivityNum_ArrestMission)
    
    #½±Àø
    curMission = curPlayer.FindMission(ChConfig.Def_ArrestMissionID)
    taskStar = max(1, curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_ArrestTaskStar))
    exp, soul, point = __GetArrestTaskReward(curPlayer, taskStar)
    
    playerControl = PlayerControl.PlayerControl(curPlayer)
    if exp > 0:
        playerControl.AddExp(exp)
    #ÐüÉÍ»ý·Ö
    if point:
        PlayerControl.GiveMoney(curPlayer, ShareDefine.TYPE_Price_ArrestPoint, point, ChConfig.Def_GiveMoney_Mission)
    if soul:
        PlayerControl.PlayerAddZhenQi(curPlayer, soul, True, True, "Mission", {"MissionID":ChConfig.Def_ArrestMissionID})
    
    
    
    
    #ÀÛ¼Ó´ÎÊý
    finishCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_ArrestTaskFinishCnt)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_ArrestTaskFinishCnt, finishCnt+1)
    
    GameWorld.DebugLog("ÐüÉÍÈÎÎñ£º%d taskStar=%s, »ñµÃ¾­Ñé:%d,»ý·Ö=%s,ÁéÁ¦=%s,finishCnt=%s" 
                       % (curMission.GetMissionID(), taskStar, exp, point, soul, finishCnt+1))
    
    #ÖØÖÃ
    OnDeleteArrestTask(curPlayer)
    return
 
## ·ÅÆúÈÎÎñºó´¦Àí
def OnDeleteArrestTask(curPlayer):
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_ArrestTaskStar, 1)
    #Ë¢ÐÂÈÎÎñ
    __RefreshArrestTaskNPC(curPlayer)
    #֪ͨ¿Í»§¶Ë¿É½ÓÐüÉÍÈÎÎñµÈ¼¶
    Sync_ArrestTaskInfo(curPlayer)
    return
 
## ÐüÉÍÈÎÎñ½ñÈÕ´ÎÊýÊÇ·ñÒÑÂú
def __IsArrestTaskFullCnt(curPlayer):
    finishCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_ArrestTaskFinishCnt)
    return finishCnt >= ReadChConfig.GetEvalChConfig("ArrestTaskMaxCnt")
 
 
## ÁìÈ¡ÐüÉÍ»ý·Ö½±Àø
def OnGetArrestPointAward(curPlayer, scoreIndex):
    arrestPointPrizeList = ReadChConfig.GetEvalChConfig("ArrestPointPrize")
    if scoreIndex < 0 or scoreIndex >= len(arrestPointPrizeList):
        return
    needScore, awardItemList = arrestPointPrizeList[scoreIndex]
    curScore = PlayerControl.GetMoney(curPlayer, ShareDefine.TYPE_Price_ArrestPoint)
    if curScore < needScore:
        GameWorld.DebugLog('    ÁìÈ¡ÐüÉÍ»ý·Ö½±Àø, »ý·Ö²»×㣬curScore=%s,needScore=%s' % (curScore, needScore))
        return
    awardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_ArrestTaskAwardRecord)
    if awardRecord & pow(2, scoreIndex):
        GameWorld.DebugLog('    ÁìÈ¡ÐüÉÍ»ý·Ö½±Àø, ÒÑÁìÈ¡¹ý£¬scoreIndex=%s' % (scoreIndex))
        return
    
    emptySpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem)
    if emptySpace < len(awardItemList):
        return
    
    for itemID, itemCnt, isBind in awardItemList:
            ItemControler.GivePlayerItem(curPlayer, itemID, itemCnt, 0, [IPY_GameWorld.rptItem, IPY_GameWorld.rptAnyWhere])
    
    #¸üмǼ
    awardRecord |= pow(2, scoreIndex)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_ArrestTaskAwardRecord, awardRecord)
    
    Sync_ArrestTaskInfo(curPlayer)
    return
 
 
## »ñÈ¡ÐüÉÍÈÎÎñÊý¾Ý 
def __GetArrestTaskData(npcid, npcCnt):return npcid + npcCnt * 100000
def __GetArrestTaskNPCID(taskData):return taskData % 100000
def __GetArrestTaskNPCCnt(taskData):return taskData / 100000