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