#!/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 GetActionEmblemExpireTimes(emblemActionObj): return emblemActionObj.GetValue2() def SetActionEmblemExpireTimes(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) isExpired, endTime = IsEmblemExpired(emblemActionObj, curTime) if not isExpired: #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 IsEmblemExpired(emblemActionObj, curTime): ## Ñ«ÕÂÊÇ·ñ¹ýÆÚ # @return: ÊÇ·ñ¹ýÆÚ, endTime endTime = -1 if not emblemActionObj: return True, endTime createTime = emblemActionObj.GetTime() expireTimes = GetEmblemExpireTimes(emblemActionObj) if expireTimes == 0: # ÓÀ¾ÃµÄ return False, 0 if expireTimes > 0: endTime = createTime + expireTimes if endTime >= curTime: # δ¹ýÆÚ return False, endTime return True, endTime def GetEmblemExpireTimes(emblemActionObj): ## »ñȡѫÕÂÓÐЧʱ³¤£¬Ãë # @return: 0-ÓÀ¾Ã£»-1-ÎÞЧ£»>0-ÓÐЧÃëÊý expireTimes = GetActionEmblemExpireTimes(emblemActionObj) # ÓÐЧʱ³¤£¬Ãë if not expireTimes: emblemID = GetActionEmblemID(emblemActionObj) ipyData = IpyGameDataPY.GetIpyGameData("FamilyEmblem", emblemID) if not ipyData: return -1 expireTimes = ipyData.GetExpireMinutes() * 60 return expireTimes 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 unlockFamilyLV = ipyData.GetUnlockFamilyLV() if unlockFamilyLV: GameWorld.Log("ÏÉÃ˽âËøµÄ»ÕÕ²»ÐèÒªÌí¼Ó! familyID=%s,emblemID=%s" % (familyID, emblemID)) return if setExpireTimes >= 0: expireTimes = setExpireTimes else: expireTimes = ipyData.GetExpireMinutes() * 60 GameWorld.Log("Ìí¼ÓÏÉÃË»ÕÕÂ! familyID=%s,emblemID=%s,setExpireTimes=%s,expireTimes=%s" % (familyID, emblemID, setExpireTimes, expireTimes)) 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) else: isExpired, endTime = IsEmblemExpired(emblemActionObj, curTime) if setExpireTimes >= 0: emblemActionObj.SetTime(curTime) GameWorld.Log("Ö±½ÓÉèÖÃÑ«ÕÂÊ£Óàʱ³¤£¬ÖØÐÂÉèÖûñµÃʱ¼ä! familyID=%s,emblemID=%s" % (familyID, emblemID)) elif isExpired: emblemActionObj.SetTime(curTime) GameWorld.Log("»ñµÃÑ«ÕÂʱÒѹýÆÚ£¬ÖØÐÂÉèÖûñµÃʱ¼ä! familyID=%s,emblemID=%s,endTime=%s" % (familyID, emblemID, endTime)) else: # δ¹ýÆÚ£¬·ÇÓÀ¾ÃµÄÖ±½ÓÀÛ¼Óʱ³¤ if expireTimes > 0: expireTimes += GetActionEmblemExpireTimes(emblemActionObj) GameWorld.Log("»ñµÃÑ«ÕÂʱδ¹ýÆÚ£¬ÀÛ¼ÓÓÐЧʱ³¤! familyID=%s,emblemID=%s,expireTimes=%s" % (familyID, emblemID, expireTimes)) SetActionEmblemID(emblemActionObj, emblemID) SetActionEmblemExpireTimes(emblemActionObj, expireTimes) # ֪ͨ 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() if unlockFamilyLV: if curFamily.GetLV() < unlockFamilyLV: GameWorld.DebugLog("ÏÉÃ˵ȼ¶²»×㣬ÎÞ·¨Ê¹ÓøûÕÕÂ! emblemID=%s,unlockFamilyLV=%s" % (emblemID, unlockFamilyLV), playerID) return else: emblemActionObj = GetFamilyEmblemActionData(familyID, emblemID) isExpired, endTime = IsEmblemExpired(emblemActionObj, int(time.time())) if isExpired: GameWorld.DebugLog("¸Ã»ÕÕ²»´æÔÚ»òÒѹýÆÚ! emblemID=%s,endTime=%s" % (emblemID, endTime), playerID) return GameWorld.DebugLog("¸ü»»ÏÉÃË»ÕÕÂ! familyID=%s,emblemID=%s" % (familyID, emblemID), playerID) PlayerFamily.SetFamilyEmblemID(curFamily, emblemID) PlayerFamily.SendPack_MapServer_PlayerFamilyRefresh(curFamily) curFamily.Broadcast_FamilyChange() return