#!/usr/bin/python
|
# -*- coding: GBK -*-
|
#-------------------------------------------------------------------------------
|
#
|
##@package GameWorldLogic.FBProcess.GameLogic_CrossGrassland
|
#
|
# @todo:¿ç·þ²ÝÔ°
|
# @author hxp
|
# @date 2019-04-15
|
# @version 1.0
|
#
|
# ÏêϸÃèÊö: ¿ç·þ²ÝÔ°
|
#
|
#-------------------------------------------------------------------------------
|
#"""Version = 2019-04-15 16:30"""
|
#-------------------------------------------------------------------------------
|
|
import GameWorld
|
import GameWorldProcess
|
import PlayerFairyDomain
|
import NPCCustomRefresh
|
import IpyGameDataPY
|
import PyGameData
|
import NPCCommon
|
import PlayerControl
|
import ChConfig
|
import FBCommon
|
import ItemControler
|
import random
|
|
FBDict_SyncFBNPC = 'SyncFBNPC' #ÊÇ·ñÐèҪͬ²½¸±±¾NPC
|
|
def DoResetCrossGrassland(curPlayer, eventType, fdeventID):
|
## ²ÝÔ°ÖØÖÃ
|
|
resetCollectType = 10 + eventType
|
NPCCommon.DoResetCollectNPCTimeByType(curPlayer, [resetCollectType])
|
|
# ±¦Ïä¹Ö´ÎÊýÖØÖÃ
|
if eventType == PlayerFairyDomain.FDEventType_GrasslandXian:
|
npcID = IpyGameDataPY.GetFuncCfg("CrossGrasslandCfg", 1)
|
if npcID:
|
NPCCommon.UpdateNPCAttackCount(curPlayer, npcID, 0)
|
|
ResetGrasslandAwardRecord(curPlayer)
|
return
|
|
## ÊÇ·ñÐèÒª×ö½øÈ븱±¾Í¨Óüì²éÌõ¼þÂß¼£¬Ä¬ÈÏÐèÒª¼ì²é
|
def OnNeedCheckCanEnterFBComm(curPlayer, mapID, lineID):
|
curState = PlayerFairyDomain.GetFairyDomainFBEventState(curPlayer, mapID, lineID)
|
return curState != PlayerFairyDomain.FDEventState_Visiting
|
|
def OnEnterFBEvent(curPlayer, mapID, lineID, tick):
|
curState = PlayerFairyDomain.GetFairyDomainFBEventState(curPlayer, mapID, lineID)
|
return curState in [PlayerFairyDomain.FDEventState_CanVisit, PlayerFairyDomain.FDEventState_Visiting]
|
|
## ½øÈë¿ç·þ¸±±¾×¢²áÊý¾ÝǰÂß¼
|
## @return: ÊÇ·ñ¿ÉÒÔ×¢²áǰÍù¿ç·þ¸±±¾£¬´Îº¯ÊýÖпÉÒÔдһЩ¿Û³ýÏûºÄÂß¼µÈ
|
def OnRegEnterCrossFB(curPlayer, mapID, lineID):
|
curState = PlayerFairyDomain.GetFairyDomainFBEventState(curPlayer, mapID, lineID)
|
if curState == PlayerFairyDomain.FDEventState_CanVisit:
|
delResult = FBCommon.DelFBEnterTicket(curPlayer, mapID, lineID)
|
isOK = delResult[0]
|
if not isOK:
|
return False
|
return PlayerFairyDomain.SetFairyDomainFBEventState(curPlayer, mapID, lineID, PlayerFairyDomain.FDEventState_Visiting)
|
|
if curState == PlayerFairyDomain.FDEventState_Visiting:
|
return True
|
|
return False
|
|
## ¿ç·þ¹¦ÄÜÏß·Êý¾Ý»º´æ£¬Ï´οªÆôͬÑù¹¦ÄÜÏß·ʱ»áÓøÃÊý¾Ý½øÐл¹Ô֮ǰµÄ¸±±¾×´Ì¬
|
def OnGetCrossFuncLineDataCache():
|
refreshNPCInfo = NPCCustomRefresh.GetCopyMapRandomRefreshNPCInfo()
|
return refreshNPCInfo
|
|
## ¿ªÆô¸±±¾
|
def OnOpenFB(tick):
|
gameWorld = GameWorld.GetGameWorld()
|
realMapID, copyMapID = gameWorld.GetRealMapID(), gameWorld.GetCopyMapID()
|
key = (realMapID, copyMapID)
|
if key in PyGameData.g_crossFuncLineDataCache:
|
refreshNPCInfo = PyGameData.g_crossFuncLineDataCache.pop(key)
|
GameWorld.DebugLog("¸±±¾¿ªÆô¸ù¾Ý±£´æµÄÐéÄâÏß·±êÊÔµãË¢¹ÖÐÅϢˢ¹Ö: realMapID=%s,copyMapID=%s,refreshNPCInfo=%s" % (realMapID, copyMapID, refreshNPCInfo))
|
NPCCustomRefresh.OnFBOpenSetRandomRefreshNPCInfo(refreshNPCInfo, tick)
|
|
return
|
|
## ½ø¸±±¾
|
def DoEnterFB(curPlayer, tick):
|
playerID = curPlayer.GetPlayerID()
|
zoneID = FBCommon.GetCrossDynamicLineMapZoneID()
|
funcLineID = FBCommon.GetCrossDynamicLineMapFuncLineID()
|
crossMapID = PlayerControl.GetCrossMapID(curPlayer)
|
GameWorld.Log("DoEnterFB zoneID=%s,funcLineID=%s,crossMapID=%s" % (zoneID, funcLineID, crossMapID), playerID)
|
FBCommon.Sync_FBNPC(curPlayer=curPlayer)
|
if crossMapID == ChConfig.Def_FBMapID_CrossGrasslandXian:
|
boxNPCID = IpyGameDataPY.GetFuncCfg("CrossGrasslandCfg", 1)
|
if boxNPCID:
|
NPCCommon.SyncNPCAttackCount(curPlayer, [boxNPCID])
|
return
|
|
## ¸±±¾×ÜÂß¼¼ÆÊ±Æ÷
|
def OnProcess(tick):
|
gameFB = GameWorld.GetGameFB()
|
if gameFB.GetGameFBDictByKey(FBDict_SyncFBNPC):
|
gameFB.SetGameFBDict(FBDict_SyncFBNPC, 0)
|
FBCommon.Sync_FBNPC()
|
|
return
|
#
|
### ¹Ø±Õ¸±±¾
|
#def OnCloseFB(tick):
|
# return
|
#
|
### Íæ¼ÒÍ˳ö¸±±¾
|
#def DoExitFB(curPlayer, tick):
|
# return
|
|
##Íæ¼ÒÖ÷¶¯À뿪¸±±¾.
|
def DoPlayerLeaveFB(curPlayer, tick):
|
|
gameWorld = GameWorld.GetGameWorld()
|
#×îºóÒ»ÈËÍ˳ö¸±±¾Ôò¹Ø±ÕµØÍ¼
|
if gameWorld.GetMapCopyPlayerManager().GetPlayerCount() == 1:
|
GameWorldProcess.CloseFB(tick)
|
|
return
|
|
## ¿Í»§¶Ë½øÈë×Ô¶¨Ò峡¾°
|
def OnEnterCustomScene(curPlayer, mapID, lineID):
|
curState = PlayerFairyDomain.GetFairyDomainFBEventState(curPlayer, mapID, lineID)
|
PlayerFairyDomain.SetFairyDomainFBEventState(curPlayer, mapID, lineID, PlayerFairyDomain.FDEventState_Visiting)
|
|
if curState == PlayerFairyDomain.FDEventState_CanVisit:
|
refreshMapNPCDict = IpyGameDataPY.GetFuncEvalCfg("CrossGrasslandCfg", 2)
|
npcCountDict = refreshMapNPCDict.get((mapID, lineID), {})
|
for npcID, npcCount in npcCountDict.items():
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GrasslandNPCCount % npcID, npcCount)
|
|
if mapID == ChConfig.Def_FBMapID_CrossGrasslandXian:
|
FBCommon.DelFBEnterTicket(curPlayer, mapID, lineID)
|
else:
|
DoCheckUpdateGrasslandEnd(curPlayer)
|
|
SyncCustomSceneNPCCount(curPlayer, mapID, lineID)
|
if mapID == ChConfig.Def_FBMapID_CrossGrasslandXian:
|
boxNPCID = IpyGameDataPY.GetFuncCfg("CrossGrasslandCfg", 1)
|
if boxNPCID:
|
NPCCommon.SyncNPCAttackCount(curPlayer, [boxNPCID])
|
|
return
|
|
## ×Ô¶¨Ò峡¾°²É¼¯OK£¬Ðè×Ô´øÊÇ·ñÔÊÐí²É¼¯µÄÅжÏ
|
def OnCustomSceneCollectOK(curPlayer, mapID, lineID, npcID):
|
curState = PlayerFairyDomain.GetFairyDomainFBEventState(curPlayer, mapID, lineID)
|
if curState != PlayerFairyDomain.FDEventState_Visiting:
|
return False
|
curCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GrasslandNPCCount % npcID)
|
if not curCount:
|
return False
|
return True
|
|
def DecCustomSceneNPCCount(curPlayer, npcID):
|
## ¼õÉÙ²ÝÔ°×Ô¶¨Ò峡¾°NPC£¬Ä¬ÈϼõÉÙÒ»¸ö
|
mapID, lineID = GetGrasslandMapID(curPlayer)
|
if not mapID:
|
return
|
curCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GrasslandNPCCount % npcID)
|
updCount = max(0, curCount - 1)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GrasslandNPCCount % npcID, updCount)
|
SyncCustomSceneNPCCount(curPlayer, mapID, lineID)
|
return
|
|
def SyncCustomSceneNPCCount(curPlayer, mapID, lineID):
|
## ֪ͨ×Ô¶¨Ò峡¾°NPCÊý
|
refreshMapNPCDict = IpyGameDataPY.GetFuncEvalCfg("CrossGrasslandCfg", 2)
|
npcCountDict = refreshMapNPCDict.get((mapID, lineID), {})
|
npcNowCountDict = {}
|
for npcID in npcCountDict.keys():
|
npcNowCountDict[npcID] = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GrasslandNPCCount % npcID)
|
if mapID == ChConfig.Def_FBMapID_CrossGrasslandXian:
|
boxNPCID = IpyGameDataPY.GetFuncCfg("CrossGrasslandCfg", 1)
|
if boxNPCID:
|
npcNowCountDict[boxNPCID] = 1
|
NPCCommon.SyncNPCCntInfo(curPlayer, mapID, npcNowCountDict)
|
return
|
|
def RecordGrasslandAward(curPlayer, addItemList):
|
## ¼Ç¼²ÝÔ°½±ÀøÐÅÏ¢
|
mapID = GetGrasslandMapID(curPlayer)[0]
|
if not mapID:
|
return
|
|
for itemInfo in addItemList:
|
if not isinstance(itemInfo, list):
|
continue
|
itemID, itemCount = itemInfo[:2]
|
|
newIndex = None
|
for i in xrange(20):
|
itemCountInfo = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GrasslandDropCount % i)
|
if not itemCountInfo:
|
newIndex = i
|
break
|
recItemID = itemCountInfo/100
|
if recItemID == itemID:
|
updRecValue = itemCountInfo + itemCount
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GrasslandDropCount % i, updRecValue)
|
break
|
if newIndex != None:
|
newRecValue = itemID*100 + itemCount
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GrasslandDropCount % newIndex, newRecValue)
|
|
return
|
|
def ResetGrasslandAwardRecord(curPlayer):
|
## ÖØÖòÝÔ°½±ÀøÐÅÏ¢¼Ç¼
|
for i in xrange(20):
|
itemCountInfo = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GrasslandDropCount % i)
|
if not itemCountInfo:
|
break
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GrasslandDropCount % i, 0)
|
return
|
|
|
def GetGrasslandMapID(curPlayer):
|
grasslandMapIDList = [ChConfig.Def_FBMapID_CrossGrasslandLing, ChConfig.Def_FBMapID_CrossGrasslandXian]
|
crossMapID = PlayerControl.GetCrossMapID(curPlayer)
|
customMapID = PlayerControl.GetCustomMapID(curPlayer)
|
if crossMapID in grasslandMapIDList:
|
mapID = crossMapID
|
lineID = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_ReqCrossFBFuncLine)
|
elif customMapID in grasslandMapIDList:
|
mapID = customMapID
|
lineID = PlayerControl.GetCustomLineID(curPlayer)
|
else:
|
return 0, 0
|
return mapID, lineID
|
|
def DoCheckUpdateGrasslandEnd(curPlayer):
|
## ¼ì²é¸üвÝÔ°ÒѰݷÃÍê³É
|
|
mapID, lineID = GetGrasslandMapID(curPlayer)
|
if not mapID:
|
return
|
|
# ²É¼¯´ÎÊýÊÇ·ñÒÑÓÃÍê
|
if mapID == PlayerControl.GetCustomMapID(curPlayer):
|
refreshMapNPCDict = IpyGameDataPY.GetFuncEvalCfg("CrossGrasslandCfg", 2)
|
npcCountDict = refreshMapNPCDict.get((mapID, lineID), {})
|
npcIDList = npcCountDict.keys()
|
else:
|
collNPCIpyDataList = IpyGameDataPY.GetIpyGameDataListNotLog("MapRefreshNPC", mapID)
|
if not collNPCIpyDataList:
|
return
|
|
npcIDList = []
|
for collIpyData in collNPCIpyDataList:
|
npcIDList += collIpyData.GetNPCIDList()
|
|
for npcID in npcIDList:
|
collectNPCIpyData = IpyGameDataPY.GetIpyGameData("CollectNPC", npcID)
|
if not collectNPCIpyData:
|
return
|
limitMaxTime = collectNPCIpyData.GetMaxCollectCount()
|
totalCollTime = NPCCommon.GetTodayCollectCount(curPlayer, npcID)
|
if totalCollTime < limitMaxTime:
|
GameWorld.DebugLog("²ÝÔ°NPC²É¼¯´ÎÊýδÓÃÍê! npcID=%s,totalCollTime=%s < limitMaxTime=%s" % (npcID, totalCollTime, limitMaxTime))
|
return
|
|
# ±¦Ïä¹Ö¹¥»÷´ÎÊýÊÇ·ñÒÑÓÃÍê
|
boxNPCID = IpyGameDataPY.GetFuncCfg("CrossGrasslandCfg", 1)
|
if mapID == ChConfig.Def_FBMapID_CrossGrasslandXian and boxNPCID:
|
boxNPCIpyData = IpyGameDataPY.GetIpyGameDataNotLog("TreasureNPC", boxNPCID)
|
if not boxNPCIpyData:
|
return
|
attackCountDropWeightInfo = boxNPCIpyData.GetAttackCountDropWeightInfo()
|
if not attackCountDropWeightInfo:
|
return
|
maxAttackCount = max(attackCountDropWeightInfo)
|
attackCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_NPCAttackCount % boxNPCID)
|
if attackCount < maxAttackCount:
|
GameWorld.DebugLog("²ÝÔ°±¦Ïä¹Ö¹¥»÷´ÎÊýδÓÃÍê! boxNPCID=%s,attackCount=%s < maxAttackCount=%s" % (boxNPCID, attackCount, maxAttackCount))
|
return
|
|
PlayerFairyDomain.SetFairyDomainFBEventState(curPlayer, mapID, lineID, PlayerFairyDomain.FDEventState_Visited)
|
PlayerControl.SetCustomMap(curPlayer, 0, 0)
|
GameWorld.DebugLog("ÉèÖòÝÔ°ÒÑÍê³É!mapID=%s, lineID=%s" % (mapID, lineID))
|
|
# ֪ͨ½áËã
|
awardItemList = []
|
for i in xrange(20):
|
itemCountInfo = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GrasslandDropCount % i)
|
if not itemCountInfo:
|
break
|
isAuctionItem = 0
|
itemID, itemCount = itemCountInfo/100, itemCountInfo%100
|
awardItemList.append([itemID, itemCount, isAuctionItem])
|
extraAward = [] #¶îÍâÎïÆ·½±Àø
|
ipyData = IpyGameDataPY.GetIpyGameDataByCondition("FairyDomain", {"MapID":mapID, "LineID":lineID})
|
if ipyData:
|
fdEventID = ipyData.GetID()
|
extraAward = PlayerFairyDomain.GetFairyAppointAward(curPlayer, fdEventID)
|
if not extraAward:
|
extraAward = FBCommon.GetFBLineReward(mapID, lineID)
|
if extraAward:
|
ItemControler.GivePlayerItemOrMail(curPlayer, extraAward)
|
awardItemList += extraAward
|
overDict = {FBCommon.Over_itemInfo:FBCommon.GetJsonItemList(awardItemList)}
|
FBCommon.NotifyFBOver(curPlayer, mapID, lineID, 1, overDict)
|
ResetGrasslandAwardRecord(curPlayer)
|
return
|
|
def DoFB_NPCDead(curNPC):
|
#GameWorld.DebugLog("DoFB_NPCDead ÉèÖÃÐèҪͬ²½¸±±¾NPC!")
|
GameWorld.GetGameFB().SetGameFBDict(FBDict_SyncFBNPC, 1)
|
return
|
|
def OnNPCRebornInFB(curNPC):
|
#GameWorld.DebugLog("OnNPCRebornInFB ÉèÖÃÐèҪͬ²½¸±±¾NPC!")
|
GameWorld.GetGameFB().SetGameFBDict(FBDict_SyncFBNPC, 1)
|
return
|
|
|
## ¿É·ñɨµ´
|
def OnPlayerFBSweepAsk(curPlayer, mapID, lineID, sweepCnt, isFinish, dataEx):
|
curState = PlayerFairyDomain.GetFairyDomainFBEventState(curPlayer, mapID, lineID)
|
if curState not in [PlayerFairyDomain.FDEventState_CanVisit, PlayerFairyDomain.FDEventState_Visiting]:
|
GameWorld.DebugLog("çÎç¿ÎÞ·¨É¨µ´! ²»´æÔÚ¸Ãʼþ»òÎÞ·¨½øÈ룡 mapID=%s,lineID=%s,curState=%s" % (mapID, lineID, curState))
|
return False
|
return True
|
|
## ɨµ´½á¹û
|
def OnPlayerFBSweepResult(curPlayer, mapID, lineID, sweepCnt, isFinish, dataEx):
|
|
jsonItemList = []
|
refreshMapNPCDict = IpyGameDataPY.GetFuncEvalCfg("CrossGrasslandCfg", 2)
|
npcCountDict = refreshMapNPCDict.get((mapID, lineID), {})
|
GameWorld.DebugLog("²Ý԰ɨµ´: mapID=%s,lineID=%s,npcCountDict=%s" % (mapID, lineID, npcCountDict))
|
if npcCountDict:
|
npcIDList = npcCountDict.keys()
|
doCount = sum(npcCountDict.values()) * 2
|
while npcIDList and doCount >= 0:
|
doCount -= 1
|
npcID = random.choice(npcIDList)
|
collectNPCIpyData = IpyGameDataPY.GetIpyGameData("CollectNPC", npcID)
|
if not collectNPCIpyData:
|
npcIDList.remove(npcID)
|
continue
|
awardItemInfo = NPCCommon.DoGiveCollectNPCAward(curPlayer, npcID, collectNPCIpyData, isSweep=True)
|
if awardItemInfo == None:
|
npcIDList.remove(npcID)
|
GameWorld.DebugLog(" ɨµ´npcID=%s,ûÓн±ÀøÁË£¬ÒƳý£¡ npcIDList=%s" % (npcID, npcIDList))
|
continue
|
jsonItemList.extend(awardItemInfo)
|
GameWorld.DebugLog(" npcID=%s,awardItemInfo=%s" % (npcID, awardItemInfo))
|
|
|
extraAward = FBCommon.GetFBLineReward(mapID, lineID)
|
if extraAward:
|
ItemControler.GivePlayerItemOrMail(curPlayer, extraAward)
|
jsonItemList += FBCommon.GetJsonItemList(extraAward)
|
GameWorld.DebugLog(" ɨµ´jsonItemList=%s" % jsonItemList)
|
|
ipyData = IpyGameDataPY.GetIpyGameDataByCondition('FairyDomain', {'MapID':mapID, 'LineID':lineID})
|
if ipyData:
|
fdeventID = ipyData.GetID()
|
PlayerFairyDomain.SetFairyDomainEventState(curPlayer, fdeventID, PlayerFairyDomain.FDEventState_Visited)
|
|
isPass = 1
|
overDict = {FBCommon.Over_itemInfo:jsonItemList, FBCommon.Over_isSweep:1}
|
FBCommon.NotifyFBOver(curPlayer, mapID, lineID, isPass, overDict)
|
return
|
|
|