#!/usr/bin/python
|
# -*- coding: GBK -*-
|
#-------------------------------------------------------------------------------
|
#
|
##@package Player.PlayerAssist
|
#
|
# @todo:ÐÖúϵͳ
|
# @author hxp
|
# @date 2019-12-06
|
# @version 1.0
|
#
|
# ÏêϸÃèÊö: ÐÖúϵͳ
|
#
|
#-------------------------------------------------------------------------------
|
#"""Version = 2019-12-06 21:00"""
|
#-------------------------------------------------------------------------------
|
|
import GameWorld
|
import IpyGameDataPY
|
import PlayerControl
|
import NPCHurtManager
|
import ChPyNetSendPack
|
import NetPackCommon
|
import IPY_GameWorld
|
import ItemControler
|
import ItemCommon
|
import ChConfig
|
import ShareDefine
|
import PyGameData
|
import FBCommon
|
|
def DoPlayerOnDay(curPlayer):
|
## ¹ýÌì´¦Àí
|
|
ipyDataMgr = IpyGameDataPY.IPY_Data()
|
for index in xrange(ipyDataMgr.GetAssistThanksGiftCount()):
|
ipyData = ipyDataMgr.GetAssistThanksGiftByIndex(index)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GetThanksGiftCount % ipyData.GetGiftID(), 0)
|
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TodayAssistMoney, 0)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TodayAssistMoneySocial, 0)
|
Sync_TodayAssistMoneyInfo(curPlayer)
|
return
|
|
def OnPlayerLogin(curPlayer):
|
if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayAssistMoney):
|
Sync_TodayAssistMoneyInfo(curPlayer)
|
return
|
|
def OnPlayerLeaveMap(curPlayer):
|
## Íæ¼ÒÀ뿪µØͼ´¦Àí
|
|
NPCHurtManager.OnPlayerLeaveMap(curPlayer)
|
|
mapID = curPlayer.GetMapID()
|
if GameWorld.GetMap().GetMapFBTypeByMapID(mapID) == IPY_GameWorld.fbtTeam:
|
mapAssistGiftDict = IpyGameDataPY.GetFuncEvalCfg("AssistAward", 2, {})
|
if str(mapID) in mapAssistGiftDict and PlayerControl.GetAssistTagPlayerID(curPlayer):
|
lineID = PlayerControl.GetFBFuncLineID(curPlayer)
|
OnCancelAssistTeamFB(curPlayer.GetPlayerID(), mapID, lineID, "LeaveMap")
|
|
return
|
|
#// B0 10 ÇëÇóÐÖúBoss #tagCMRequestAssistBoss
|
#
|
#struct tagCMRequestAssistBoss
|
#
|
#{
|
# tagHead Head;
|
# DWORD ObjID;
|
# DWORD NPCID;
|
#};
|
def OnRequestAssistBoss(index, clientData, tick):
|
curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
|
playerID = curPlayer.GetPlayerID()
|
objID = clientData.ObjID
|
npcID = clientData.NPCID
|
|
if not GameWorld.IsCrossServer():
|
if not curPlayer.GetFamilyID():
|
GameWorld.DebugLog("±¾·þbossûÓÐÏÉÃ˲»ÄÜÇëÇóÐÖú!", playerID)
|
return
|
|
curNPC = GameWorld.FindNPCByNPCID(npcID)
|
if not curNPC:
|
GameWorld.DebugLog("ÐÖúNPC²»´æÔÚÎÞ·¨ÐÖú!npcID=%s" % npcID, playerID)
|
return
|
if curNPC.GetID() != objID:
|
GameWorld.DebugLog("ÐÖúNPCʵÀýID²»Ò»ÖÂÎÞ·¨ÐÖú!npcID=%s,curNPC.GetID()=%s,sendObjID=%s" % (npcID, curNPC.GetID(), objID), playerID)
|
return
|
|
ipyData = IpyGameDataPY.GetIpyGameDataNotLog('BOSSInfo', npcID)
|
if not ipyData or not ipyData.GetCanAssist():
|
GameWorld.DebugLog("¸ÃNPC²»ÄÜÐÖú!npcID=%s" % npcID, playerID)
|
return
|
|
hurtList = NPCHurtManager.GetPlayerHurtList(curNPC)
|
if not hurtList.IsNoAssistPlayer(playerID):
|
GameWorld.DebugLog("²»ÊǸÃbossµÄ·ÇÖúÕ½ÉËѪÍæ¼Ò£¬ÎÞ·¨·¢ÆðÐÖú!npcID=%s" % npcID, playerID)
|
return
|
|
if not GameWorld.SetPlayerTickTime(curPlayer, ChConfig.TYPE_Player_Tick_RequestAssist, tick):
|
GameWorld.DebugLog("ÇëÇóÐÖúCDÖÐ!npcID=%s" % npcID, playerID)
|
return
|
|
npcLV = curNPC.GetLV()
|
mapID = curPlayer.GetMapID()
|
lineID = NPCHurtManager.GetBossLineID(npcID)
|
serverGroupID = PlayerControl.GetPlayerServerGroupID(curPlayer)
|
queryData = [mapID, lineID, npcID, objID, npcLV, serverGroupID]
|
QueryGameServer_PlayerAssist(playerID, "RequestAssistBoss", queryData)
|
return
|
|
|
#// B0 11 ÇëÇóÐÖú×é¶Ó¸±±¾ #tagCMRequestAssistTeamFB
|
#
|
#struct tagCMRequestAssistTeamFB
|
#
|
#{
|
# tagHead Head;
|
# WORD MapID;
|
# WORD LineID;
|
#};
|
def OnRequestAssistTeamFB(index, clientData, tick):
|
curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
|
playerID = curPlayer.GetPlayerID()
|
mapID = clientData.MapID
|
lineID = clientData.LineID
|
|
if GameWorld.IsCrossServer():
|
return
|
|
if not curPlayer.GetFamilyID():
|
GameWorld.DebugLog("ûÓÐÏÉÃ˲»ÄÜÇëÇóÐÖú!", playerID)
|
return
|
|
if GameWorld.GetMap().GetMapFBTypeByMapID(mapID) != IPY_GameWorld.fbtTeam:
|
GameWorld.DebugLog("·Ç×é¶Ó¸±±¾²»ÄÜÇëÇóÐÖú!mapID=%s" % mapID, playerID)
|
return
|
|
if not GameWorld.SetPlayerTickTime(curPlayer, ChConfig.TYPE_Player_Tick_RequestAssist, tick):
|
GameWorld.DebugLog("ÇëÇóÐÖúCDÖÐ!mapID=%s,lineID=%s" % (mapID, lineID), playerID)
|
return
|
|
mapAssistGiftDict = IpyGameDataPY.GetFuncEvalCfg("AssistAward", 2, {})
|
if str(mapID) not in mapAssistGiftDict:
|
return
|
|
teamID = curPlayer.GetTeamID()
|
if teamID:
|
if curPlayer.GetTeamLV() != IPY_GameWorld.tmlLeader:
|
GameWorld.DebugLog("·Ç¶Ó³¤£¬ÎÞ·¨·¢²¼¸±±¾ÐÖú!")
|
return
|
|
fbIpyData = FBCommon.GetFBIpyData(mapID)
|
fbLineIpyData = FBCommon.GetFBLineIpyData(mapID, lineID)
|
if PlayerControl.CheckMoveToFB(curPlayer, mapID, lineID, fbIpyData, fbLineIpyData, tick) != ShareDefine.EntFBAskRet_OK:
|
return
|
|
queryData = [mapID, lineID]
|
QueryGameServer_PlayerAssist(playerID, "RequestAssistTeamFB", queryData)
|
return
|
|
def OnStartAssistTeamFB(playerID, mapID, lineID, tagPlayerID):
|
## ¿ªÊ¼ÐÖú×é¶Ó¸±±¾£¬ÐÖúÍæ¼Ò½øÈ븱±¾µ÷ÓÃ
|
queryData = [mapID, lineID, tagPlayerID]
|
QueryGameServer_PlayerAssist(playerID, "OnStartAssistTeamFB", queryData)
|
return
|
|
def OnCancelAssistTeamFB(playerID, mapID, lineID, reason):
|
## È¡Ïû¸±±¾ÐÖú
|
queryData = [mapID, lineID, reason]
|
QueryGameServer_PlayerAssist(playerID, "OnCancelAssistTeamFB", queryData)
|
return
|
|
def QueryGameServer_PlayerAssist(playerID, queryType, queryData):
|
msgInfo = str([queryType, queryData])
|
GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(playerID, 0, 0, "PlayerAssist", msgInfo, len(msgInfo))
|
GameWorld.DebugLog("ÐÖúÐÅÏ¢·¢ËÍ GameServer: playerID=%s,queryType=%s,queryData=%s" % (playerID, queryType, queryData))
|
return
|
|
def QueryResult_PlayerAssist(curPlayer, resultList):
|
## ÐÖúÐÅÏ¢GameServer·µ»Ø´¦Àí
|
if len(resultList) != 3:
|
return
|
queryType, queryData, result = resultList
|
|
# ʹÓÃÐÖú¸ÐлÀñºÐ¸ø½±Àø
|
if queryType == "UseAssistThanksGift":
|
itemID = queryData[0]
|
giftItem = ItemCommon.FindItemInPackByItemID(curPlayer, itemID, IPY_GameWorld.rptItem)
|
if not giftItem:
|
return
|
ItemCommon.DelItem(curPlayer, giftItem, 1)
|
|
ipyData = IpyGameDataPY.GetIpyGameData("AssistThanksGift", itemID)
|
if ipyData:
|
awardItemID, awardItemCount = ipyData.GetRequestPlayerAward()
|
ItemControler.GivePlayerItemOrMail(curPlayer, [[awardItemID, awardItemCount, 0]])
|
|
# ½ÓÊÕÐÖú¸ÐлÀñºÐ½±Àø¸ø½±Àø
|
elif queryType == "GetAssistThanksGift":
|
itemID, isExtraAward, isCurDailyDate, updateTodayGiftCount = queryData
|
if isCurDailyDate:
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GetThanksGiftCount % itemID, updateTodayGiftCount)
|
|
if isExtraAward:
|
ipyData = IpyGameDataPY.GetIpyGameData("AssistThanksGift", itemID)
|
if ipyData:
|
awardItemID, awardItemCount = ipyData.GetAssistPlayerAward()
|
ItemControler.GivePlayerItemOrMail(curPlayer, [[awardItemID, awardItemCount, 0]])
|
|
# ¿ç·þ·¢²¼ÐÖúÍæ¼Ò½±Àø
|
elif queryType == "CrossNoAssistPlayerAward":
|
assistAwardItemID = queryData[0]
|
ItemControler.GivePlayerItemOrMail(curPlayer, [[assistAwardItemID, 1, 0]])
|
|
# ¿ç·þÐÖúÍæ¼Ò½±Àø
|
elif queryType == "CrossAssistPlayerAward":
|
assistMoney, isFriend = queryData
|
assistMoneyType = ShareDefine.TYPE_Price_FamilyActivity
|
AddTodayAssistMoney(curPlayer, assistMoneyType, assistMoney, isFriend)
|
|
return
|
|
def GameServer_AssistBossMsg(assistData):
|
## GameServerÍÆË͵½Ö¸¶¨bossµØͼµÄÐÅÏ¢
|
|
GameWorld.DebugLog("GameServerͬ²½BossÐÖúÐÅÏ¢: %s" % assistData)
|
|
msgType = assistData[0]
|
|
# ¿ªÊ¼ÐÖú
|
if msgType == "Start":
|
assistGUID, assistPlayerID, assistPlayerName, isFriend, tagPlayerID, tagPlayerName, tagTeamID, lineID, objID, npcID, serverGroupID = assistData[1:]
|
npchurtList = NPCHurtManager.GetPlayerHurtListEx(lineID, objID, npcID)
|
if not npchurtList:
|
return
|
|
npchurtList.AddAssistPlayer(assistPlayerID, assistPlayerName, isFriend, tagPlayerID, tagPlayerName, tagTeamID)
|
QueryGameServer_PlayerAssist(0, "AddAssistBossPlayerOK", [assistGUID, assistPlayerID, tagPlayerID, serverGroupID])
|
|
# È¡ÏûÐÖú
|
elif msgType == "Cancel":
|
assistPlayerID, lineID, objID, npcID = assistData[1:]
|
npchurtList = NPCHurtManager.GetPlayerHurtListEx(lineID, objID, npcID)
|
if not npchurtList:
|
return
|
npchurtList.DelHurtPlayer(assistPlayerID, "Cancel", isMapServerDel=False)
|
|
return
|
|
def OnPlayerEnterAssistFB(curPlayer, mapID, lineID=0):
|
## Íæ¼Ò½øÈëÐÖú¸±±¾
|
|
if GameWorld.GetMap().GetMapFBTypeByMapID(mapID) != IPY_GameWorld.fbtTeam:
|
return
|
|
mapAssistGiftDict = IpyGameDataPY.GetFuncEvalCfg("AssistAward", 2, {})
|
if str(mapID) not in mapAssistGiftDict:
|
return
|
|
playerID = curPlayer.GetPlayerID()
|
gameFB = GameWorld.GetGameFB()
|
noAssistPlayerID = gameFB.GetGameFBDictByKey("FBNoAssistPlayerID")
|
if noAssistPlayerID:
|
if playerID != noAssistPlayerID:
|
OnStartAssistTeamFB(playerID, mapID, lineID, noAssistPlayerID)
|
return
|
|
if curPlayer.GetTeamID():
|
if curPlayer.GetTeamLV() != IPY_GameWorld.tmlLeader:
|
# ·Ç¶Ó³¤ÏȽøÈëµÄ£¬Ôݲ»´¦Àí£¬µÈ´ý¶Ó³¤½øÈëºóͳһ´¦Àí
|
return
|
|
noAssistPlayerID = playerID # ¶Ó³¤»òÎÞ¶ÓÎé½øÈëÔòΪ·ÇÐÖúÍæ¼Ò
|
gameFB.SetGameFBDict("FBNoAssistPlayerID", noAssistPlayerID)
|
GameWorld.DebugLog("ÉèÖø±±¾·ÇÐÖúÍæ¼Ò: noAssistPlayerID=%s" % noAssistPlayerID)
|
|
copyPlayerManager = GameWorld.GetMapCopyPlayerManager()
|
for index in xrange(copyPlayerManager.GetPlayerCount()):
|
player = copyPlayerManager.GetPlayerByIndex(index)
|
if not player:
|
continue
|
fbPlayerID = player.GetPlayerID()
|
if fbPlayerID == noAssistPlayerID:
|
continue
|
if PlayerControl.GetAssistTagPlayerID(player) != noAssistPlayerID:
|
OnStartAssistTeamFB(fbPlayerID, mapID, lineID, noAssistPlayerID)
|
|
return
|
|
def OnFBAssistOver(isPass, mapID, lineID=0):
|
''' ¸±±¾ÐÖú½áÊø
|
@return: noAssistPlayerID, assistMoneyType, assistPlayerMoneyDict
|
µ± noAssistPlayerID Ϊ0ʱ´ú±íûÓгɹ¦½áËãÐÖú£¬¸±±¾¶îÍâµÄÐÖú½±ÀøÒ²²»ÄܽáË㣬·ÀÖ¹±»Ë¢ÐÖú½±Àø
|
'''
|
assistPlayerMoneyDict = {}
|
assistMoneyType = ShareDefine.TYPE_Price_FamilyActivity
|
defaultReturn = (0, assistMoneyType, assistPlayerMoneyDict)
|
gameFB = GameWorld.GetGameFB()
|
noAssistPlayerID = gameFB.GetGameFBDictByKey("FBNoAssistPlayerID")
|
GameWorld.DebugLog("¸±±¾ÐÖú½áËã: isPass=%s,mapID=%s,lineID=%s,noAssistPlayerID=%s" % (isPass, mapID, lineID, noAssistPlayerID))
|
|
if not isPass or not noAssistPlayerID:
|
return defaultReturn
|
|
copyPlayerManager = GameWorld.GetMapCopyPlayerManager()
|
noAssistPlayer = copyPlayerManager.FindPlayerByID(noAssistPlayerID)
|
if not noAssistPlayer:
|
GameWorld.DebugLog(" ·ÇÐÖúÍæ¼Ò²»ÔÚ£¬²»½áËãÐÖú½±Àø!")
|
return defaultReturn
|
|
mapAssistGiftDict = IpyGameDataPY.GetFuncEvalCfg("AssistAward", 2, {})
|
if str(mapID) not in mapAssistGiftDict:
|
return defaultReturn
|
liheItemID, assistMoney = mapAssistGiftDict[str(mapID)]
|
|
friendList, memFamilyIDDict = [], {}
|
teamID = GameWorld.GetGameWorld().GetPropertyID()
|
if teamID in PyGameData.g_teamFBMemRelationDict:
|
friendList, memFamilyIDDict = PyGameData.g_teamFBMemRelationDict[teamID][:2]
|
noAssistPlayerFamilyID = memFamilyIDDict.get(noAssistPlayerID, 0)
|
|
assistAwardItemID = liheItemID
|
assistPlayerDict = {}
|
for index in xrange(copyPlayerManager.GetPlayerCount()):
|
curPlayer = copyPlayerManager.GetPlayerByIndex(index)
|
if not curPlayer:
|
continue
|
|
playerID = curPlayer.GetPlayerID()
|
if playerID == noAssistPlayerID:
|
continue
|
|
assistPlayer = curPlayer
|
assistPlayerID = playerID
|
isFriend = [noAssistPlayerID, playerID] in friendList or [playerID, noAssistPlayerID] in friendList
|
assistFamilyID = assistPlayer.GetFamilyID()
|
|
addAssistMoney = AddTodayAssistMoney(curPlayer, assistMoneyType, assistMoney, isFriend)
|
assistPlayerMoneyDict[assistPlayerID] = addAssistMoney
|
GameWorld.DebugLog("ÐÖú·½¸ø»îÔ¾Áî½±Àø: assistPlayerID=%s,assistMoney=%s,isFriend=%s,addAssistMoney=%s"
|
% (assistPlayerID, assistMoney, isFriend, addAssistMoney), mapID, lineID)
|
|
todayGiftCount = assistPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GetThanksGiftCount % liheItemID)
|
assistPlayerDict[assistPlayerID] = {"PlayerName":assistPlayer.GetPlayerName(), "Job":assistPlayer.GetJob(),
|
"LV":assistPlayer.GetLV(), "RealmLV":assistPlayer.GetOfficialRank(),
|
"TodayGiftCount":todayGiftCount, "Face":assistPlayer.GetFace(), "FacePic":assistPlayer.GetFacePic()}
|
|
# Ôݶ¨Ö§³Öͬ¶ÓÎ鲻ͬÏÉÃ˼äÐÖú
|
if assistFamilyID and assistFamilyID == noAssistPlayerFamilyID:
|
notifyParam = [assistPlayer.GetPlayerName(), noAssistPlayer.GetPlayerName(), mapID]
|
PlayerControl.FamilyNotify(assistFamilyID, "AssistFBFinish", notifyParam)
|
|
if assistPlayerDict:
|
GameWorld.DebugLog("·¢²¼·½¸ø¸ÐлÀñºÐ½±Àø: noAssistPlayerID=%s,assistAwardItemID=%s" % (noAssistPlayerID, assistAwardItemID), mapID, lineID)
|
ItemControler.GivePlayerItemOrMail(noAssistPlayer, [[assistAwardItemID, 1, 0]])
|
|
queryData = [mapID, lineID, noAssistPlayerID, assistAwardItemID, assistPlayerDict]
|
QueryGameServer_PlayerAssist(0, "OnFBAssistOver", queryData)
|
return noAssistPlayerID, assistMoneyType, assistPlayerMoneyDict
|
|
def AddTodayAssistMoney(curPlayer, moneyType, addMoney, isSocialEx):
|
''' Ôö¼Ó½ñÈÕÐÖú»õ±Ò½±Àø
|
@param moneyType: »õ±ÒÀàÐÍ
|
@param addMoney: ³£¹æÔö¼Ó£¬ÓÐÿÈÕÉÏÏÞ
|
@param isSocialEx: ÊÇ·ñÉç½»¼Ó³É£¬²»¼ÆÈë³£¹æÉÏÏÞ
|
'''
|
|
todayAssistMoney = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayAssistMoney)
|
socialMoney = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayAssistMoneySocial)
|
todayAssistMoneyMax = IpyGameDataPY.GetFuncCfg("AssistAward", 4)
|
if todayAssistMoney >= todayAssistMoneyMax:
|
return 0
|
|
addValue = min(addMoney, todayAssistMoneyMax - todayAssistMoney)
|
socialEx = 0
|
if isSocialEx:
|
friendAddAssistMoneyPer = IpyGameDataPY.GetFuncCfg("AssistAward", 3)
|
socialEx = int(addValue * friendAddAssistMoneyPer / 100.0)
|
|
realAdd = addValue + socialEx
|
|
if not GameWorld.IsCrossServer():
|
PlayerControl.GiveMoney(curPlayer, moneyType, realAdd)
|
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TodayAssistMoney, todayAssistMoney + addValue)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TodayAssistMoneySocial, socialMoney + socialEx)
|
|
Sync_TodayAssistMoneyInfo(curPlayer)
|
return realAdd
|
|
def Sync_TodayAssistMoneyInfo(curPlayer):
|
## ֪ͨ½ñÈÕÒÑ»ñµÃÐÖú»õ±ÒÐÅÏ¢
|
infoPack = ChPyNetSendPack.tagMCTodayAssistMoneyInfo()
|
infoPack.TodayAssistMoney = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayAssistMoney)
|
infoPack.SocialMoney = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayAssistMoneySocial)
|
NetPackCommon.SendFakePack(curPlayer, infoPack)
|
return
|
|