#!/usr/bin/python
|
# -*- coding: GBK -*-
|
#-------------------------------------------------------------------------------
|
#
|
#-------------------------------------------------------------------------------
|
#
|
##@package Player.PlayerFairyDomain
|
#
|
# @todo:çÎç¿ÏÉÓò
|
# @author xdh
|
# @date 2019-04-04
|
# @version 1.0
|
#
|
# ÏêϸÃèÊö: çÎç¿ÏÉÓò
|
#---------------------------------------------------------------------
|
#"""Version = 2019-04-04"""
|
#---------------------------------------------------------------------
|
|
import ChConfig
|
import ChPyNetSendPack
|
import NetPackCommon
|
import ShareDefine
|
import GameWorld
|
import PlayerControl
|
import IpyGameDataPY
|
import PlayerActivity
|
|
import copy
|
|
#0-ÆæÓö 1-±¦²Ø 2-ÏÉ²Ý 3-ÑýÍõ 4-Áé²Ý
|
(
|
FDEventType0,
|
FDEventType1,
|
FDEventType2,
|
FDEventType3,
|
FDEventType4,
|
) = range(5)
|
|
(
|
FDEventState_No, #²»¿É°Ý·Ã0
|
FDEventState_CanVisit, #¿É°Ý·Ã1
|
FDEventState_Visiting, #°Ý·ÃÖÐ2
|
FDEventState_Visited, #ÒѰݷÃ3
|
) = range(4)
|
|
|
def OnLogin(curPlayer):
|
NotifyVisitFairyDomainInfo(curPlayer)
|
return
|
|
|
#// A5 26 Ѱ·ÃÏÉÓò #tagCMVisitFairyDomain
|
#
|
#struct tagCMVisitFairyDomain
|
#{
|
# tagHead Head;
|
# BYTE Type; //0-¿ªÊ¼Ñ°·Ã 1-½áÊøÑ°·Ã
|
#};
|
def OnVisitFairyDomain(index, clientData, tick):
|
curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
|
dailyID = ShareDefine.DailyActionID_FairyDomain
|
hasOpen = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_DailyActionState % dailyID)
|
if not hasOpen:
|
GameWorld.DebugLog(" Ѱ·ÃÏÉÓò»î¶¯Î´¿ªÆô£¡")
|
return
|
otherCntRateList = IpyGameDataPY.GetFuncEvalCfg('ImmortalDomain', 2)
|
maxEventCnt = max([info[1] for info in otherCntRateList]) + 1 #×î´ó¿É³öÏÖʼþ¸öÊý
|
|
if clientData.Type == 1: #½áÊøÑ°·Ã
|
if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainState):
|
GameWorld.DebugLog(" δ¿ªÊ¼Ñ°·ÃÏÉÓò£¬ ÎÞ·¨½áÊø")
|
return
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyDomainState, 0)
|
for i in xrange(maxEventCnt):
|
fdEventID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainEventID % i)
|
if fdEventID:
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyDomainEventID%i, 0)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyDomainEventState%fdEventID, 0)
|
|
NotifyVisitFairyDomainInfo(curPlayer)
|
return
|
|
#ÊÇ·ñѰ·ÃÖÐ
|
if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainState):
|
GameWorld.DebugLog(" ÕýÔÚѰ·ÃÏÉÓòÖУ¡ÇëÏÈÍ˳öѰ·Ã")
|
return
|
|
if not PlayerActivity.AddDailyActionFinishCnt(curPlayer, dailyID):
|
GameWorld.DebugLog(" Ѱ·ÃÏÉÓò´ÎÊý²»×㣡")
|
return
|
|
#Ëæ»úʼþ ÖØÖÃʼþ״̬
|
visitCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainVisitCnt)
|
specialVisitDict = IpyGameDataPY.GetFuncEvalCfg('ImmortalDomain', 5, {})
|
maxSpecialCnt = max(specialVisitDict) if specialVisitDict else 0
|
if visitCnt + 1 in specialVisitDict:
|
fdEventIDList = specialVisitDict[visitCnt + 1]
|
else:
|
fdEventTypeDict = {}
|
#ÏÈËæ»úÆæÓöʼþ
|
fortuitousEventRate = IpyGameDataPY.GetFuncCfg('ImmortalDomain')
|
if GameWorld.CanHappen(fortuitousEventRate):
|
fdEventTypeDict[FDEventType0] = 1
|
|
otherCnt = GameWorld.GetResultByRandomList(otherCntRateList, 0)
|
if otherCnt:
|
otherEventRateList = copy.deepcopy(IpyGameDataPY.GetFuncEvalCfg('ImmortalDomain', 3))
|
unRepeatTypeList = IpyGameDataPY.GetFuncEvalCfg('ImmortalDomain', 4)
|
for _ in xrange(otherCnt):
|
otherEventType = GameWorld.GetResultByRandomList(otherEventRateList, 0)
|
if not otherEventType:
|
continue
|
if otherEventType in unRepeatTypeList:
|
for index, info in enumerate(otherEventRateList):
|
if otherEventType == info[1]:
|
otherEventRateList = GameWorld.ResetRiseList(otherEventRateList, index)
|
break
|
fdEventTypeDict[otherEventType] = fdEventTypeDict.get(otherEventType, 0) + 1
|
|
fdEventIDList = []
|
for eventType, cnt in fdEventTypeDict.items():
|
fdEventIDList += __RandomFDEventByType(curPlayer, eventType, cnt)
|
if not fdEventIDList:
|
GameWorld.Log('Ѱ·ÃÏÉÓò, ûÓÐËæ»ú³öʼþ£¡£¡')
|
return
|
|
if visitCnt < maxSpecialCnt:
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyDomainVisitCnt, visitCnt + 1)
|
#ÉèÖÃʼþ
|
for i in xrange(maxEventCnt):
|
fdEventID = fdEventIDList[i] if i < len(fdEventIDList) else 0
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyDomainEventID % i, fdEventID)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyDomainEventState % fdEventID, FDEventState_CanVisit)
|
#ÉèÖÃѰ·ÃÖÐ
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyDomainState, 1)
|
#ÉèÖóõʼÌåÁ¦
|
initEnergy = IpyGameDataPY.GetFuncCfg('ImmortalDomainStrength')
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyDomainEnergy, initEnergy)
|
GameWorld.DebugLog('Ѱ·ÃÏÉÓò Ëæ»ú½á¹û fdEventIDList=%s, visitCnt=%s' % (fdEventIDList, visitCnt))
|
#֪ͨ
|
NotifyVisitFairyDomainInfo(curPlayer, fdEventIDList)
|
return
|
|
|
def __RandomFDEventByType(curPlayer, eventType, cnt):
|
##¸ù¾ÝʼþÀàÐÍËæ»úʼþ
|
ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition('FairyDomain', {'EventType':eventType}, True)
|
if not ipyDataList:
|
return []
|
randomRateList = []
|
rate = 0
|
for ipyData in ipyDataList:
|
needAlchemyLV = ipyData.GetNeedAlchemyLV()
|
curAlchemyLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_AlchemyLV)
|
if curAlchemyLV < needAlchemyLV - 1:
|
#µ¤Â¯µÈ¼¶²»×ã
|
continue
|
rate += ipyData.GetWeight()
|
randomRateList.append([rate, ipyData.GetID()])
|
if not randomRateList:
|
GameWorld.DebugLog(' çÎç¿ÏÉÓòË¢ÐÂ³Ø Ëæ»ú¿â»ñÈ¡´íÎó £¡eventType=%s' % eventType, curPlayer.GetID())
|
return []
|
randomResultList = GameWorld.GetResultByRandomListEx(randomRateList, cnt, [])
|
|
return randomResultList
|
|
|
def SetFairyDomainEventState(curPlayer, fdeventID, state):
|
## ÉèÖÃçÎç¿Ê¼þ״̬£¬ return ÊÇ·ñ³É¹¦
|
if state not in [FDEventState_Visiting, FDEventState_Visited]: # 1-δ°Ý·Ã 2-°Ý·ÃÖÐ 3-ÒѰݷÃ
|
GameWorld.Log('çÎç¿ÏÉÓòʼþ״̬ÉèÖôíÎó£¬state=%s' % state)
|
return
|
curState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainEventState % fdeventID)
|
if state == FDEventState_Visiting:
|
if curState != FDEventState_CanVisit:
|
GameWorld.Log('çÎç¿ÏÉÓòʼþ״̬ÉèÖôíÎó£¬fdeventID=%s, state=%s, curState=%s' % (fdeventID, state, curState))
|
return
|
ipyData = IpyGameDataPY.GetIpyGameData('FairyDomain', fdeventID)
|
if not ipyData:
|
return
|
costEnergy = ipyData.GetCostEnergy()
|
curEnergy = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainEnergy)
|
if curEnergy < costEnergy:
|
GameWorld.Log('çÎç¿ÏÉÓòʼþ״̬ÉèÖÃ,ÌåÁ¦²»×㣡£¬fdeventID=%s, costEnergy=%s, curEnergy=%s' % (fdeventID, costEnergy, curEnergy))
|
return
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyDomainEnergy, curEnergy - costEnergy)
|
elif state == FDEventState_Visited:
|
if curState != FDEventState_Visiting:
|
GameWorld.Log('çÎç¿ÏÉÓòʼþ״̬ÉèÖôíÎó£¬fdeventID=%s, state=%s, curState=%s' % (fdeventID, state, curState))
|
return
|
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyDomainEventState % fdeventID, state)
|
NotifyVisitFairyDomainInfo(curPlayer, fdeventID)
|
return True
|
|
|
def NotifyVisitFairyDomainInfo(curPlayer, fdEventList=[]):
|
if not fdEventList:
|
otherCntRateList = IpyGameDataPY.GetFuncEvalCfg('ImmortalDomain', 2)
|
maxEventCnt = max([info[1] for info in otherCntRateList]) + 1 #×î´ó¿É³öÏÖʼþ¸öÊý
|
for i in xrange(maxEventCnt):
|
fdEventID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainEventID % i)
|
if fdEventID:
|
fdEventList.append(fdEventID)
|
|
packData = ChPyNetSendPack.tagMCFairyDomainInfo()
|
packData.State = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainState)
|
packData.Energy = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainEnergy)
|
packData.InfoList = []
|
for fdeventID in fdEventList:
|
fdeventData = ChPyNetSendPack.tagMCFairyDomainEvent()
|
fdeventData.EventID = fdeventID
|
fdeventData.EventState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainEventState % fdeventID)
|
packData.InfoList.append(fdeventData)
|
packData.Count = len(packData.InfoList)
|
NetPackCommon.SendFakePack(curPlayer, packData)
|
return
|