#!/usr/bin/python # -*- coding: GBK -*- #------------------------------------------------------------------------------- # ##@package PlayerFamilyEmblem # # @todo:ÏÉÃË»ÕÕ # @author hxp # @date 2024-09-09 # @version 1.0 # # ÏêϸÃèÊö: ÏÉÃË»ÕÕ # #------------------------------------------------------------------------------- #"""Version = 2024-09-09 15:30""" #------------------------------------------------------------------------------- import GameWorld import ShareDefine import PlayerFamilyAction import IpyGameDataPY import PlayerFamily import random import time def GetActionEmblemID(emblemActionObj): return emblemActionObj.GetValue1() def SetActionEmblemID(emblemActionObj, emblemID): return emblemActionObj.SetValue1(emblemID) def GetActionEmblemEndTime(emblemActionObj): return emblemActionObj.GetValue2() def SetActionEmblemEndTime(emblemActionObj, endTime): return emblemActionObj.SetValue2(endTime) def GetDefaultFamilyEmblemIDList(): ## »ñȡĬÈϵÄÏÉÃË»ÕÕÂIDÁÐ±í£¬¼´ËùÓнâËøµÈ¼¶Îª1µÄ»ÕÕÂID defaultEmblemIDList = [] ipyDataMgr = IpyGameDataPY.IPY_Data() for index in range(ipyDataMgr.GetFamilyEmblemCount()): ipyData = ipyDataMgr.GetFamilyEmblemByIndex(index) emblemID = ipyData.GetEmblemID() if ipyData.GetUnlockFamilyLV() == 1: defaultEmblemIDList.append(emblemID) return defaultEmblemIDList def CheckExpireEmblem(): ## ¼ì²é¹ýÆÚµÄѫՠdefaultEmblemIDList = [] curTime = int(time.time()) actionType = ShareDefine.Def_ActionType_FamilyEmblem familyManager = GameWorld.GetFamilyManager() familyActionMgr = GameWorld.GetFamilyActionManager() for i in xrange(familyManager.GetCount()): family = familyManager.GetAt(i) if not family: continue familyID = family.GetID() familyAction = familyActionMgr.GetFamilyAction(familyID, actionType) for index in range(familyAction.Count())[::-1]: # ¿ÉÄÜ´¥·¢É¾³ý£¬µ¹Ðò±éÀú emblemActionObj = familyAction.At(index) emblemID = GetActionEmblemID(emblemActionObj) endTime = GetActionEmblemEndTime(emblemActionObj) if not endTime or endTime > curTime: #GameWorld.Log("¼ì²éÏÉÃË»ÕÕÂδ¹ýÆÚ! familyID=%s,emblemID=%s,endTime=%s" % (familyID, emblemID, endTime)) continue familyAction.DelAction(index) GameWorld.Log("ɾ³ý¹ýÆÚÏÉÃË»ÕÕÂ! familyID=%s,emblemID=%s,endTime=%s" % (familyID, emblemID, endTime)) if PlayerFamily.GetFamilyEmblemID(family) == emblemID: if not defaultEmblemIDList: defaultEmblemIDList = GetDefaultFamilyEmblemIDList() updEmblemID = random.choice(defaultEmblemIDList) if defaultEmblemIDList else 0 GameWorld.Log("ÏÉÃËÅå´÷»ÕÕ¹ýÆÚ»Ö¸´Ëæ»úĬÈÏ»ÕÕÂ! familyID=%s,emblemID=%s,endTime=%s,updEmblemID=%s" % (familyID, emblemID, endTime, updEmblemID)) PlayerFamily.SetFamilyEmblemID(family, updEmblemID) family.Broadcast_FamilyChange() return def GetFamilyEmblemActionData(familyID, emblemID): ## »ñÈ¡ÏÉÃËʱЧ»ÕÕÂActionÊý¾Ý actionType = ShareDefine.Def_ActionType_FamilyEmblem familyAction = GameWorld.GetFamilyActionManager().GetFamilyAction(familyID, actionType) for index in range(familyAction.Count()): familyActionObj = familyAction.At(index) if emblemID == familyActionObj.GetValue1(): return familyActionObj return def AddFamilyEmblem(familyID, emblemID, setExpireTimes=None): ## Ìí¼ÓÏÉÃË»ÕÕ # @param setExpireTimes: Ö¸¶¨µÄÓÐЧʱ³¤Ã룬0-ÓÀ¾Ã£¬>0-ÓÐЧʱ³¤Ã룻ûÓÐÖ¸¶¨Ê±Ö±½Ó¶ÁÅäÖýøÐÐÀÛ¼Ó ipyData = IpyGameDataPY.GetIpyGameData("FamilyEmblem", emblemID) if not ipyData: return if ipyData.GetCustomFamilyID(): GameWorld.Log("ÏÉÃ˶¨ÖÆ»ÕÕ²»ÐèÒªÌí¼Ó! familyID=%s,emblemID=%s" % (familyID, emblemID)) return unlockFamilyLV = ipyData.GetUnlockFamilyLV() if unlockFamilyLV: GameWorld.Log("ÏÉÃ˽âËøµÄ»ÕÕ²»ÐèÒªÌí¼Ó! familyID=%s,emblemID=%s" % (familyID, emblemID)) return ipyExpireSeconds = ipyData.GetExpireMinutes() * 60 curTime = int(time.time()) emblemActionObj = GetFamilyEmblemActionData(familyID, emblemID) if not emblemActionObj: actionType = ShareDefine.Def_ActionType_FamilyEmblem familyAction = GameWorld.GetFamilyActionManager().GetFamilyAction(familyID, actionType) emblemActionObj = familyAction.AddAction() emblemActionObj.SetTime(curTime) emblemActionObj.SetFamilyId(familyID) emblemActionObj.SetActionType(actionType) if not emblemActionObj: return endTime = GetActionEmblemEndTime(emblemActionObj) updEndTime = endTime # Ö¸¶¨Ê±³¤µÄ£¬ÈçGMÖ¸¶¨ if setExpireTimes > 0: updEndTime = curTime + setExpireTimes # ÓÀ¾Ã elif ipyExpireSeconds == 0 or setExpireTimes == 0: updEndTime = 0 else: # δ¹ýÆÚ if endTime > curTime: updEndTime = endTime + ipyExpireSeconds else: updEndTime = curTime + ipyExpireSeconds GameWorld.Log("Ìí¼ÓÏÉÃË»ÕÕÂ! familyID=%s,emblemID=%s,setExpireTimes=%s,endTime=%s,updEndTime=%s" % (familyID, emblemID, setExpireTimes, endTime, updEndTime)) SetActionEmblemID(emblemActionObj, emblemID) SetActionEmblemEndTime(emblemActionObj, updEndTime) # ֪ͨ PlayerFamilyAction.SendFamilyAction(emblemActionObj) return emblemActionObj def OnChangeFamilyEmblem(curPlayer, emblemID): ## ÐÞ¸ÄÏÉÃË»ÕÕ playerID = curPlayer.GetPlayerID() curFamily = curPlayer.GetFamily() if not curFamily: return familyID = curFamily.GetID() if curFamily.GetLeaderID() != playerID: GameWorld.DebugLog("Ö»ÓÐÃËÖ÷¿ÉÒÔÐ޸ĻÕÕÂ!", playerID) return ipyData = IpyGameDataPY.GetIpyGameData("FamilyEmblem", emblemID) if not ipyData: return unlockFamilyLV = ipyData.GetUnlockFamilyLV() customFamilyID = ipyData.GetCustomFamilyID() if customFamilyID: if familyID != customFamilyID: GameWorld.DebugLog("²»ÊǸö¨ÖÆ»ÕÕÂËùÊôÏÉÃË£¬ÎÞ·¨Ê¹ÓøûÕÕÂ! emblemID=%s,customFamilyID=%s != %s" % (emblemID, customFamilyID, familyID), playerID) return elif unlockFamilyLV: if curFamily.GetLV() < unlockFamilyLV: GameWorld.DebugLog("ÏÉÃ˵ȼ¶²»×㣬ÎÞ·¨Ê¹ÓøûÕÕÂ! emblemID=%s,unlockFamilyLV=%s" % (emblemID, unlockFamilyLV), playerID) return else: emblemActionObj = GetFamilyEmblemActionData(familyID, emblemID) if not emblemActionObj: GameWorld.DebugLog("¸Ã»ÕÕÂδ¼¤»î! emblemID=%s" % (emblemID), playerID) return endTime = GetActionEmblemEndTime(emblemActionObj) if endTime and endTime <= int(time.time()): GameWorld.Log("¸Ã»ÕÕÂÒѹýÆÚ! familyID=%s,emblemID=%s,endTime=%s" % (familyID, emblemID, endTime)) return GameWorld.DebugLog("¸ü»»ÏÉÃË»ÕÕÂ! familyID=%s,emblemID=%s" % (familyID, emblemID), playerID) PlayerFamily.SetFamilyEmblemID(curFamily, emblemID) PlayerFamily.SendPack_MapServer_PlayerFamilyRefresh(curFamily) curFamily.Broadcast_FamilyChange() return