#!/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
|