#!/usr/bin/python
|
# -*- coding: GBK -*-
|
#-------------------------------------------------------------------------------
|
#
|
#-------------------------------------------------------------------------------
|
#
|
##@package PlayerManorWar
|
#
|
# @todo:ÁìµØÕù¶áÕ½
|
# @author hxp
|
# @date 2014-04-26
|
# @version 1.6
|
#
|
# ÏêϸÃèÊö: ÁìµØÕù¶áÕ½
|
# @change: "2014-04-29 06:00" hxp ÐÞ¸´Í¨ÓÃÊý¾Ý´æ´¢ÀàÐÍ´íÎóbug
|
# @change: "2014-11-12 20:00" hxp Ôö¼ÓÁìµØÊ¤Àû³É¾Í
|
# @change: "2016-08-10 20:00" hxp ÐÞ¸´×îºóÒ»·ÖÖÓ²¹Ê±½×¶ÎPK»á¼ÓPKÖµµÄbug
|
# @change: "2016-11-03 21:30" hxp Ôö¼ÓÉèÖõ±ÈÕ¿ªÆô״̬
|
# @change: "2016-11-09 21:30" xdh ÿ´Î»î¶¯ÖØÐ¿ªÊ¼Ê±ÖØÖÃÕ¼ÁìȨ
|
# @change: "2016-12-28 00:00" hxp Ôö¼ÓÕ¼ÁìÕ½ÃËÃËÖ÷ID£»¼Ç¼ÉÏÒ»³¡Õ¼ÁìÕ½Ã˼Ò×åID£»¼Ç¼»î¶¯ÖÐÁÙʱռÁìµÄ¼Ò×åID
|
#
|
#---------------------------------------------------------------------
|
#"""Version = 2016-12-28 00:00"""
|
#---------------------------------------------------------------------
|
|
import ShareDefine
|
import GameWorld
|
import ChConfig
|
import ReadChConfig
|
import ChPyNetSendPack
|
import NetPackCommon
|
import PlayerFamily
|
import PlayerControl
|
import PlayerDBGSEvent
|
|
|
WorldKey_ManorWarResultState = "ManorWarResultState" # ¸÷ÁìµØÊÇ·ñ½áÊø×´Ì¬
|
|
Def_Action_ReadyOver = 98 # ×¼±¸½áÊø
|
Def_Action_DoOver = 99 # ½áÊø
|
|
## µØÍ¼·þÎñÆ÷Æô¶¯OK
|
# @param None
|
# @return None
|
def OnMapServerInitOK():
|
# ֪ͨռÁì¼Ò×å
|
manorWarMapIDList = __GetManorWarMapID()
|
for mapID in manorWarMapIDList:
|
manorRec = __GetManorRecData(mapID)
|
if not manorRec:
|
continue
|
|
familyID = manorRec.GetValue2()
|
leaderID = manorRec.GetValue4()
|
lastFamilyID = manorRec.GetValue5()
|
GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_ManorWarWinFamilyID % mapID, familyID)
|
GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_ManorWarFamilyLeaderID % mapID, leaderID)
|
tempFamilyID = GameWorld.GetGameWorld().GetDictByKey(ShareDefine.Def_Notify_WorldKey_ManorWarTempFamilyID % mapID)
|
GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_ManorWarTempFamilyID % mapID, tempFamilyID)
|
GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_ManorWarLastFamilyID % mapID, lastFamilyID)
|
|
# ֪ͨ»î¶¯Ê±µÄ¿ª·þÌìÊý
|
warServerDay = PlayerDBGSEvent.GetDBGSTrig_ByKey(PlayerDBGSEvent.Def_LastManorWarServerDay)
|
GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_ManorWarServerDay, warServerDay)
|
|
# ֪ͨ»î¶¯×´Ì¬£¬»î¶¯×´Ì¬±ØÐëÔÚ×îºó֪ͨ
|
warState = GameWorld.GetGameWorld().GetDictByKey(ShareDefine.Def_Notify_WorldKey_ManorWar)
|
GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_ManorWar, warState)
|
return
|
|
## »ñÈ¡ÁìµØÕ½µØÍ¼Áбí
|
# @param None
|
# @return None
|
def __GetManorWarMapID():
|
return ReadChConfig.GetEvalChConfig("ManorWarMapID")
|
|
## ÁìµØÕ½OnDay
|
# @param None
|
# @return None
|
def OnDay():
|
|
# Ôö¼ÓÕ¼ÁìÌìÊý
|
manorWarMapIDList = __GetManorWarMapID()
|
for mapID in manorWarMapIDList:
|
manorRec = __GetManorRecData(mapID)
|
if not manorRec:
|
continue
|
|
familyID = manorRec.GetValue2()
|
occupyDays = manorRec.GetValue3()
|
|
if familyID > 0:
|
manorRec.SetValue3(occupyDays + 1)
|
|
# ֪ͨËùÓÐÔÚÏßÍæ¼Ò
|
__Sync_ManorRecData()
|
return
|
|
|
## ÁìµØÕ½Login
|
# @param curPlayer
|
# @return None
|
def OnPlayerLogin(curPlayer):
|
# ֪ͨսÃËÕ¼ÁìÇé¿ö
|
__Sync_ManorRecData(curPlayer)
|
return
|
|
|
##ÁìµØÕù¶áÕ½»î¶¯×´Ì¬±ä¸ü»Øµ÷
|
# @param isOpen ÊÇ·ñ¿ªÆô
|
# @return None
|
# @remarks
|
def ManorWar_ChangeState(state):
|
if state == ChConfig.Def_Action_Open:
|
__OnOpen()
|
|
elif state == Def_Action_ReadyOver:
|
__TryManorWarOver()
|
|
# Ç¿ÖÆ´¦Àí»î¶¯½áÊø£¬·ÀÖ¹ÓеØÍ¼ÎÞ·¨Õý³£½áË㣬µ¼Ö»ÎÞ·¨½áÊø£¬Ò»°ãʱ¼ä¿ÉÉèÖÃΪ»î¶¯½áÊøºó1·ÖÖÓ
|
elif state == Def_Action_DoOver:
|
__DoManorWarOver()
|
|
return
|
|
|
## ÁìµØÕ½__OnOpen
|
# @param None
|
# @return None
|
def __OnOpen():
|
GameWorld.GetGameWorld().SetDict(WorldKey_ManorWarResultState, 0) # ÖØÖø÷ÁìµØ½áÊø×´Ì¬
|
#ÖØÖÃÕ¼Áì״̬
|
manorWarMapIDList = __GetManorWarMapID()
|
for mapID in manorWarMapIDList:
|
GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_ManorWarWinFamilyID % mapID, 0)
|
GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_ManorWarFamilyLeaderID % mapID, 0)
|
GameWorld.GetGameWorld().SetDict(ShareDefine.Def_Notify_WorldKey_ManorWarTempFamilyID % mapID, 0)
|
GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_ManorWarTempFamilyID % mapID, 0)
|
|
manorRec = __GetManorRecData(mapID)
|
if not manorRec:
|
continue
|
|
lastFamilyID = manorRec.GetValue2()
|
GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_ManorWarLastFamilyID % mapID, lastFamilyID)
|
manorRec.SetValue5(lastFamilyID) # ÉèÖÃÉÏ´ÎÕ¼ÁìµÄÕ½ÃËID
|
manorRec.SetValue2(0) # ÖØÖÃÕ¼ÁìÕ½ÃËID
|
manorRec.SetValue3(0) # ÖØÖÃÕ¼ÁìÌìÊý
|
manorRec.SetValue4(0) # ÖØÖÃÃËÖ÷ID
|
manorRec.SetStrValue1("") # ÖØÖÃÕ½ÃËÃû
|
manorRec.SetStrValue2("") # ÖØÖÃÃËÖ÷Ãû
|
|
# ֪ͨսÃËÕ¼ÁìÇé¿ö
|
__Sync_ManorRecData()
|
|
# ¼Ç¼»î¶¯¿ªÆôʱµÄ¿ª·þÌìÊý£¬Í¬²½MapServer
|
openServerDay = PlayerDBGSEvent.GetDBGSTrig_ByKey(PlayerDBGSEvent.Def_ServerDay)
|
PlayerDBGSEvent.SetDBGSTrig_ByKey(PlayerDBGSEvent.Def_LastManorWarServerDay, openServerDay)
|
GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_ManorWarServerDay, openServerDay)
|
|
# ÉèÖýñÈÕ¿ªÆô¹ý
|
PlayerFamily.SetFamilyActivityDayOpen(ShareDefine.Def_FamActivity_Manor)
|
return
|
|
|
## ÁìµØÕ½²ÉÆìÏûºÄ
|
# @param resultName
|
# @return None
|
def ManorWarGetFlagCost(resultName):
|
GameWorld.Log('ÊÕµ½µØÍ¼·þÎñÆ÷ÁìµØÕù¶áÕ½¿Û³ý°ÎÆìÏûºÄ = %s' % (resultName))
|
mapID, familyID, value = resultName
|
|
# ¹ã²¥µØÍ¼»î¶¯ÖÐÁÙʱռÁìµÄÕ½ÃËID
|
GameWorld.GetGameWorld().SetDict(ShareDefine.Def_Notify_WorldKey_ManorWarTempFamilyID % mapID, familyID)
|
GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_ManorWarTempFamilyID % mapID, familyID)
|
|
curFamily = GameWorld.GetFamilyManager().FindFamily(familyID)
|
|
if not curFamily:
|
GameWorld.ErrLog('ÎÞ·¨»ñµÃ¼Ò×åID= %s,%s' % (familyID))
|
return
|
|
curFamily.SetMoney(max(0, curFamily.GetMoney() - value))
|
|
#֪ͨ¿Í»§¶ËË¢ÐÂ
|
curFamily.Broadcast_FamilyChange()
|
#֪ͨµØÍ¼·þÎñÆ÷Ë¢ÐÂ
|
PlayerFamily.SendPack_MapServer_PlayerFamilyRefresh(curFamily)
|
return
|
|
|
## ½ÓÊÕMapServer·¢Ë͵ÄÁìµØÕ¼ÁìʤÀûÕ½ÃË
|
# @param msgList
|
# @return None
|
def DoMapServerManorWarWinner(msgList):
|
# [mapID, Õ¼ÁìÕ½ÃËid]
|
mapID, winFamilyID = msgList
|
GameWorld.DebugLog("DoMapServerManorWarWinner msgList=%s" % str(msgList))
|
|
manorWarMapIDList = __GetManorWarMapID()
|
if mapID not in manorWarMapIDList:
|
return
|
|
winFamily = GameWorld.GetFamilyManager().FindFamily(winFamilyID)
|
if not winFamily:
|
return
|
|
familyName = winFamily.GetName()
|
leaderName = winFamily.GetLeaderName()
|
leaderID = winFamily.GetLeaderID()
|
|
manorRec = __GetManorRecData(mapID)
|
|
recFamilyID = manorRec.GetValue2()
|
|
# ʤÀûÕ½ÃËÓë¼Ç¼սÃ˲»Ò»Ö£¬ÖØÖÃÕ¼ÁìȨ
|
if recFamilyID != winFamilyID:
|
manorRec.SetValue2(winFamilyID)
|
manorRec.SetValue3(0) # ÖØÖÃÕ¼ÁìÌìÊý
|
|
manorRec.SetStrValue1(familyName)
|
manorRec.SetStrValue2(leaderName)
|
manorRec.SetValue4(leaderID) # ÃËÖ÷ID
|
|
PlayerControl.WorldNotify(0, "PK_liubo_70569", [familyName, mapID])
|
|
# ֪ͨµØÍ¼¸üÐÂÁìµØÕ¼ÁìÕ½ÃË
|
GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_ManorWarWinFamilyID % mapID, winFamilyID)
|
GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_ManorWarFamilyLeaderID % mapID, leaderID)
|
|
# ÉèÖøÃÁìµØÒѽáËã
|
__SetManorWarStateOver(mapID, manorWarMapIDList)
|
|
# ³¢ÊԻ½áÊø´¦Àí
|
__TryManorWarOver()
|
return
|
|
|
## ÉèÖÃÁìµØÕ½×´Ì¬½áÊø
|
# @param mapID
|
# @param manorWarMapIDList
|
# @return None
|
def __SetManorWarStateOver(mapID, manorWarMapIDList):
|
|
if mapID not in manorWarMapIDList:
|
return
|
|
index = manorWarMapIDList.index(mapID)
|
|
nowState = GameWorld.GetGameWorld().GetDictByKey(WorldKey_ManorWarResultState)
|
updState = nowState|pow(2, index)
|
GameWorld.GetGameWorld().SetDict(WorldKey_ManorWarResultState, updState)
|
return
|
|
|
## ³¢ÊÔÁìµØÕ½½áËã
|
# @param None
|
# @return None
|
def __TryManorWarOver():
|
# »î¶¯½áÊøÌõ¼þ
|
# 1. »î¶¯×´Ì¬½áÊø
|
# 2. ËùÓÐÁìµØµØÍ¼¶¼½áËãÍê±Ï
|
|
# »î¶¯»¹ÔÚ½øÐÐÖУ¬²»´¦Àí½áÊø
|
warState = GameWorld.GetGameWorld().GetDictByKey(ShareDefine.Def_Notify_WorldKey_ManorWar)
|
if warState == ChConfig.Def_Action_Open:
|
GameWorld.DebugLog("__TryManorWarOver »î¶¯»¹ÔÚ½øÐÐÖУ¬²»´¦Àí½áÊø...")
|
return
|
|
# ÅжÏÊÇ·ñËùÓеØÍ¼¶¼½áËã
|
manorWarMapIDList = __GetManorWarMapID()
|
nowState = GameWorld.GetGameWorld().GetDictByKey(WorldKey_ManorWarResultState)
|
for index in xrange(len(manorWarMapIDList)):
|
if not nowState&pow(2, index):
|
GameWorld.DebugLog("__TryManorWarOver µØÍ¼Ë÷Òý=%s»¹Î´½áË㣬²»´¦Àí½áÊø..." % index)
|
return
|
|
__DoManorWarOver()
|
return
|
|
|
## Ö´ÐÐÁìµØÕ½½áËã
|
# @param None
|
# @return None
|
def __DoManorWarOver():
|
GameWorld.DebugLog("Ö´ÐÐÁìµØÕ½½áËã __DoManorWarOver() ...")
|
dictName = ShareDefine.Def_Notify_WorldKey_ManorWar
|
gameWorld = GameWorld.GetGameWorld()
|
manorWarState = gameWorld.GetDictByKey(dictName)
|
|
# Èç¹û²»ÊÇÇ¿ÖÆ½áËãµÄ£¬Ôò֪ͨµØÍ¼½áËã£¨Ç¿ÖÆ½áËãÔÚActionControl.txtÖÐÅäÖÿØÖÆ£©
|
# Ç¿ÖÆ½áËãÅäÖÃÖ÷Òª·ÀÖ¹ÓÐÁìµØÎÞ·¨Í¬²½½á¹ûÉÏÀ´£¬µ¼Ö»ÎÞ·¨½áËã
|
if manorWarState != Def_Action_DoOver:
|
GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_ManorWar, Def_Action_DoOver)
|
# ×¢£ºÕâÀïGameServer²»ÉèÖÃDoOverÖµ£¬·Àֹͬһ·ÖÖÓÄÚDoOverÓëCloseÖµ½»»¥Ìæ»»
|
#gameWorld.SetDict(dictName, Def_Action_DoOver)
|
|
familyWinMapDict = {} # Õ½ÃËÕ¼ÁìÁìµØÇé¿ö{familyID:[[mapID,ÌìÊý],...],...}
|
manorWarMapIDList = __GetManorWarMapID()
|
for mapID in manorWarMapIDList:
|
manorRec = __GetManorRecData(mapID)
|
if not manorRec:
|
continue
|
|
#mapID = manorRec.GetValue1()
|
familyID = manorRec.GetValue2()
|
occupyDays = manorRec.GetValue3() # Õ¼ÁìÌìÊý
|
|
if familyID <= 0:
|
continue
|
|
winFamily = GameWorld.GetFamilyManager().FindFamily(familyID)
|
if winFamily:
|
leaderID = winFamily.GetLeaderID()
|
manorRec.SetValue4(leaderID) # ×ܽáËãʱͳһ¸üÐÂÒ»´Î½áËãʱµÄÃËÖ÷ID
|
GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_ManorWarFamilyLeaderID % mapID, leaderID)
|
|
familyWinMapList = familyWinMapDict.get(familyID, [])
|
familyWinMapList.append([mapID, occupyDays])
|
familyWinMapDict[familyID] = familyWinMapList
|
|
GameWorld.DebugLog(" familyWinMapDict=%s" % str(familyWinMapDict))
|
|
for winFamilyID, winMapList in familyWinMapDict.items():
|
|
winFamily = GameWorld.GetFamilyManager().FindFamily(winFamilyID)
|
if not winFamily:
|
continue
|
|
for i in range(0, winFamily.GetCount()):
|
notifyMember = winFamily.GetAt(i)
|
|
curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(notifyMember.GetPlayerID())
|
if curPlayer == None:
|
continue
|
|
winMapCnt = len(winMapList)
|
|
# Àۼӳɹ¦Õ¼Áì¶àÉÙ¸öÁìµØ³É¾Í
|
#PlayerControl.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_ManorWarWin, winMapCnt)
|
# Ò»´ÎÀÛ¼ÆÕ¼Áì¶àÉÙ¸öÁìµØ³É¾Í
|
#PlayerControl.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_ManorWarWinMore, 1, winMapCnt)
|
|
# ֪ͨËùÓÐÍæ¼ÒËùÓÐÁìµØÕ¼Áì½á¹û
|
__Sync_ManorRecData()
|
return
|
|
|
## ͬ²½ÁìµØÕ½Êý¾Ý
|
# @param curPlayer
|
# @return None
|
def __Sync_ManorRecData(curPlayer=None):
|
manorWarInfo = ChPyNetSendPack.tagGCManorWarInfo()
|
manorWarInfo.Clear()
|
|
manorWarInfo.ManorInfoList = []
|
|
manorWarMapIDList = __GetManorWarMapID()
|
for mapID in manorWarMapIDList:
|
manorRec = __GetManorRecData(mapID)
|
if not manorRec:
|
continue
|
|
manorInfo = ChPyNetSendPack.tagGCManorInfo()
|
|
manorInfo.MapID = manorRec.GetValue1()
|
manorInfo.FamilyID = manorRec.GetValue2()
|
manorInfo.FamilyName = manorRec.GetStrValue1()
|
manorInfo.FNameLen = len(manorInfo.FamilyName)
|
manorInfo.LeaderName = manorRec.GetStrValue2()
|
manorInfo.LNameLen = len(manorInfo.LeaderName)
|
manorInfo.OccupyDays = manorRec.GetValue3()
|
manorInfo.LastFamilyID = manorRec.GetValue5()
|
|
manorWarInfo.ManorInfoList.append(manorInfo)
|
|
|
manorWarInfo.ManorCnt = len(manorWarInfo.ManorInfoList)
|
|
if curPlayer:
|
NetPackCommon.SendFakePack(curPlayer, manorWarInfo)
|
else:
|
playerManager = GameWorld.GetPlayerManager()
|
for i in range(0, playerManager.GetPlayerCount()):
|
curPlayer = playerManager.GetPlayerByIndex(i)
|
if curPlayer == None or not curPlayer.GetInitOK():
|
continue
|
|
NetPackCommon.SendFakePack(curPlayer, manorWarInfo)
|
|
return
|
|
|
## »ñÈ¡ÁìµØÕ½Êý¾Ý
|
# @param mapID£º ÁìµØµØÍ¼id
|
# @return None
|
def __GetManorRecData(mapID):
|
recType = ShareDefine.Def_UniversalGameRecType_ManorWarInfo
|
universalRecMgr = GameWorld.GetUniversalRecMgr()
|
recTypeListData = universalRecMgr.GetTypeList(recType)
|
|
manorRec = None
|
for index in range(recTypeListData.Count()):
|
universalRecData = recTypeListData.At(index)
|
if universalRecData.GetValue1() == mapID:
|
manorRec = universalRecData
|
break
|
|
if manorRec == None:
|
#»¹Î´¼Ç¼£¬ÔòÌí¼ÓÒ»¸ö¼Ç¼¶ÔÏó
|
manorRec = recTypeListData.AddRec()
|
manorRec.SetValue1(mapID)
|
|
return manorRec
|
|
## »ñÈ¡ÁìµØÕù¶áÕ½µÚÒ»ÃûµÄÐÅÏ¢ {'leaderName':µÚÒ»ÃûÕ½ÃËÃËÖ÷Ãû,'familyName':µÚÒ»ÃûÕ½ÃËÃû, 'fightPower':Õ½ÃË×ÜÕ½Á¦, 'leaderLV':ÃËÖ÷µÈ¼¶}
|
def GetManorWarFirstOrderInfo():
|
resultDcit = {'leaderName':'', 'familyName':'', 'fightPower':0, 'leaderLV':0}
|
familyWinMapDict = {}
|
familyInfoDict = {}
|
manorWarMapIDList = __GetManorWarMapID()
|
for mapID in manorWarMapIDList:
|
manorRec = __GetManorRecData(mapID)
|
if not manorRec:
|
continue
|
familyID = manorRec.GetValue2()
|
if not familyID:
|
continue
|
familyName = manorRec.GetStrValue1()
|
leaderName = manorRec.GetStrValue2()
|
#leaderID = manorRec.GetValue4()
|
familyWinMapDict[familyID] = familyWinMapDict.get(familyID, 0) + 1
|
familyInfoDict[familyID] = [familyName, leaderName]
|
|
#GameWorld.Log(' »ñÈ¡ÁìµØÕù¶áÕ½µÚÒ»ÃûµÄÐÅÏ¢ familyWinMapDict=%s'%familyWinMapDict)
|
if familyWinMapDict:
|
familyList = sorted(familyWinMapDict.iteritems(), key=lambda asd:asd[1], reverse=True)
|
firstFamilyid = familyList[0][0]
|
familyName, leaderName = familyInfoDict[firstFamilyid]
|
totalFightPower = PlayerFamily.GetFamilyTotalFightPowerByID(firstFamilyid)
|
|
resultDcit['leaderName'] = leaderName
|
resultDcit['leaderLV'] = PlayerFamily.GetFamilyLeaderLV(firstFamilyid)
|
resultDcit['familyName'] = familyName
|
resultDcit['fightPower'] = totalFightPower
|
return resultDcit
|