#!/usr/bin/python # -*- coding: GBK -*- #------------------------------------------------------------------------------- # ##@package Player.PlayerChatBox # # @todo:ÁÄÌìÆøÅݱíÇé # @author hxp # @date 2024-09-13 # @version 1.0 # # ÏêϸÃèÊö: ÁÄÌìÆøÅݱíÇé # #------------------------------------------------------------------------------- #"""Version = 2024-09-13 16:30""" #------------------------------------------------------------------------------- import GameWorld import ShareDefine import PlayerControl import IPY_GameWorld import ChPyNetSendPack import IpyGameDataPY import NetPackCommon import ItemCommon import ChConfig import time def OnPlayerLogin(curPlayer): SyncChatBoxInfo(curPlayer) SyncEmojiPackInfo(curPlayer) return def OnMinute(curPlayer): curTime = int(time.time()) delBoxList = [] ipyDataMgr = IpyGameDataPY.IPY_Data() for index in range(ipyDataMgr.GetChatBubbleBoxCount()): ipyData = ipyDataMgr.GetChatBubbleBoxByIndex(index) boxID = ipyData.GetBoxID() if ipyData.GetUnlockDefault(): # ĬÈϼ¤»îµÄ²»´¦Àí continue if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBubbleBoxState, boxID): # δ¼¤»îµÄ²»´¦Àí continue endTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ChatBoxEndTime % boxID) if not endTime or endTime > curTime: # ÓÀ¾Ã»òδ¹ýÆÚ continue if DelChatBox(curPlayer, boxID, False, "ChatBoxTimeout"): delBoxList.append(boxID) if delBoxList: RefreshBoxAttr(curPlayer) # ±íÇé°ü for index in range(ipyDataMgr.GetEmojiPackCount()): ipyData = ipyDataMgr.GetEmojiPackByIndex(index) packID = ipyData.GetEmojiPackID() if ipyData.GetUnlockDefault(): # ĬÈϼ¤»îµÄ²»´¦Àí continue if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_EmojiPackState, packID): # δ¼¤»îµÄ²»´¦Àí continue endTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_EmojiPackEndTime % packID) if not endTime or endTime > curTime: # ÓÀ¾Ã»òδ¹ýÆÚ continue DelEmojiPack(curPlayer, packID, "EmojiPackTimeout") return def AddChatBox(curPlayer, boxID, setExpireTimes=None): if boxID <= 0: return playerID = curPlayer.GetPlayerID() ipyData = IpyGameDataPY.GetIpyGameData("ChatBubbleBox", boxID) if not ipyData: return if ipyData.GetUnlockDefault(): GameWorld.DebugLog("ÆøÅÝ¿òĬÈϽâËøµÄ²»ÓÃÌí¼Ó: boxID=%s" % (boxID), playerID) return ipyExpireSeconds = ipyData.GetExpireMinutes() * 60 curTime = int(time.time()) state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBubbleBoxState, boxID) endTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ChatBoxEndTime % boxID) GameWorld.Log("Ìí¼ÓÆøÅÝ¿ò: boxID=%s,setExpireTimes=%s,state=%s,endTime=%s,ipyExpireSeconds=%s,curTime=%s" % (boxID, setExpireTimes, state, endTime, ipyExpireSeconds, curTime), playerID) updEndTime = endTime # Ö¸¶¨Ê±³¤µÄ£¬ÈçGMÖ¸¶¨ if setExpireTimes >= 0: updEndTime = curTime + setExpireTimes GameWorld.Log(" Ö¸¶¨ÆøÅÝ¿òʱ³¤: boxID=%s,updEndTime=%s" % (boxID, updEndTime), playerID) # ÓÀ¾Ã elif ipyExpireSeconds == 0: updEndTime = 0 GameWorld.Log(" Ìí¼ÓÓÀ¾ÃÆøÅÝ¿ò: boxID=%s,updEndTime=%s" % (boxID, updEndTime), playerID) else: # δ¹ýÆÚ if endTime > curTime: updEndTime = endTime + ipyExpireSeconds GameWorld.Log(" ÀÛ¼ÓÆøÅÝ¿òʱ³¤: boxID=%s,updEndTime=%s" % (boxID, updEndTime), playerID) else: updEndTime = curTime + ipyExpireSeconds GameWorld.Log(" ÖØÐ¼¤»îÆøÅÝ¿ò: boxID=%s,updEndTime=%s" % (boxID, updEndTime), playerID) GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBubbleBoxState, boxID, 1) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ChatBoxEndTime % boxID, updEndTime) RefreshBoxAttr(curPlayer) SyncChatBoxInfo(curPlayer, [boxID]) return True def DelChatBox(curPlayer, boxID, isRefreshAttr=True, notifyMail=""): playerID = curPlayer.GetPlayerID() ipyData = IpyGameDataPY.GetIpyGameData("ChatBubbleBox", boxID) if not ipyData: return if ipyData.GetUnlockDefault(): return GameWorld.Log("ɾ³ýÍæ¼ÒÁÄÌìÆøÅÝ¿ò: boxID=%s,notifyMail=%s" % (boxID, notifyMail), playerID) GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBubbleBoxState, boxID, 0) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ChatBoxEndTime % boxID, 0) # ÐǼ¶²»ÖØÖã¬ÖØÐ¼¤»îºóÔÙ´ÎÉúЧ if PlayerControl.GetChatBubbleBox(curPlayer) == boxID: canUseID = GetCanUseBoxID(curPlayer) PlayerControl.SetChatBubbleBox(curPlayer, canUseID) GameWorld.DebugLog("Íæ¼ÒÁÄÌìÆøÅÝ¿ò±»É¾³ý£¬ÖØÐÂÉèÖÿÉÓÃID=%s" % canUseID, playerID) if isRefreshAttr: RefreshBoxAttr(curPlayer) SyncChatBoxInfo(curPlayer, [boxID]) if notifyMail: PlayerControl.SendMailByKey(notifyMail, [playerID], [], [boxID]) return True def GetCanUseBoxID(curPlayer): ## »ñȡһ¸ö¿ÉÓÃµÄÆøÅÝ¿ò ipyDataMgr = IpyGameDataPY.IPY_Data() for index in range(ipyDataMgr.GetChatBubbleBoxCount())[::-1]: ipyData = ipyDataMgr.GetChatBubbleBoxByIndex(index) boxID = ipyData.GetBoxID() if IsBoxCanUse(curPlayer, boxID, ipyData): return boxID return 0 def IsBoxCanUse(curPlayer, boxID, ipyData=None): ## ÆøÅÝ¿òÊÇ·ñ¿ÉÓà state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBubbleBoxState, boxID) if state: return True if not ipyData: ipyData = IpyGameDataPY.GetIpyGameData("ChatBubbleBox", boxID) if ipyData: if ipyData.GetUnlockDefault(): return True needLV = ipyData.GetNeedLV() if needLV and curPlayer.GetLV() < needLV: #GameWorld.DebugLog(" µÈ¼¶²»×㣬ÎÞ·¨Ê¹ÓÃ¸ÃÆøÅÝ¿ò£¡needLV=%s" % needLV, curPlayer.GetPlayerID()) return False needVIPLVGift = ipyData.GetNeedVIPLVGift() # ¼æÈÝÒѹºÂòVIPÀñ°üµÄÀϺÅÓà if needVIPLVGift: record = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_VipAwardRecord) hasBuy = record & pow(2, needVIPLVGift) if not hasBuy: #GameWorld.DebugLog(" δ¹ºÂòVIPÀñ°ü£¬ÎÞ·¨Ê¹ÓÃ¸ÃÆøÅÝ¿ò£¡needVIPLVGift=%s" % needVIPLVGift, curPlayer.GetPlayerID()) return False if needLV or needVIPLVGift: return True return False def RefreshBoxAttr(curPlayer): CalcBoxAttr(curPlayer) PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState() return def CalcBoxAttr(curPlayer): fightPowerEx = 0 allAttrList = [{} for i in range(4)] ipyDataMgr = IpyGameDataPY.IPY_Data() for index in range(ipyDataMgr.GetChatBubbleBoxCount()): ipyData = ipyDataMgr.GetChatBubbleBoxByIndex(index) boxID = ipyData.GetBoxID() if not IsBoxCanUse(curPlayer, boxID, ipyData): continue fightPowerEx += ipyData.GetLightFightPower() # ¼¤»îÊôÐÔ lightAttrType = ipyData.GetLightAttrType() lightAttrValue = ipyData.GetLightAttrValue() for i, attrID in enumerate(lightAttrType): attrValue = lightAttrValue[i] PlayerControl.CalcAttrDict_Type(attrID, attrValue, allAttrList) # ÐǼ¶ÊôÐÔ boxStar = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ChatBoxStar % boxID) starIpyData = IpyGameDataPY.GetIpyGameDataNotLog("ChatBubbleBoxStar", boxID, boxStar) if starIpyData: starAttrType = starIpyData.GetStarAttrType() starAttrValue = starIpyData.GetStarAttrValue() for i, attrID in enumerate(starAttrType): attrValue = starAttrValue[i] PlayerControl.CalcAttrDict_Type(attrID, attrValue, allAttrList) # ±£´æ¼ÆËãÖµ PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_ChatBox, allAttrList) curPlayer.SetDict(ChConfig.Def_PlayerKey_MFPEx % ShareDefine.Def_MFPType_ChatBox, fightPowerEx) return #// A2 30 ÉèÖÃÁÄÌìÆøÅÝ¿ò #tagCMSetChatBubbleBox # #struct tagCMSetChatBubbleBox #{ # tagHead Head; # BYTE BubbleBoxType; //ÆøÅÝ¿òÀàÐÍ #}; def OnSetChatBubbleBox(index, clientData, tick): curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index) useBoxID = clientData.BubbleBoxType playerID = curPlayer.GetPlayerID() if not IsBoxCanUse(curPlayer, useBoxID): GameWorld.DebugLog("ÁÄÌìÆøÅÝ¿ò²»¿ÉÓã¬ÎÞ·¨ÉèÖÃ! useBoxID=%s" % useBoxID, playerID) return GameWorld.DebugLog("ÉèÖÃʹÓõÄÁÄÌìÆøÅÝ¿òID: useBoxID=%s" % useBoxID, playerID) PlayerControl.SetChatBubbleBox(curPlayer, useBoxID) return #// A2 36 ÁÄÌìÆøÅÝ¿òÉýÐÇ #tagCMChatBubbleBoxStarUP # #struct tagCMChatBubbleBoxStarUP #{ # tagHead Head; # WORD BoxID; //ÆøÅÝID #}; def OnChatBubbleBoxStarUP(index, clientData, tick): curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index) playerID = curPlayer.GetPlayerID() boxID = clientData.BoxID if not IsBoxCanUse(curPlayer, boxID): GameWorld.DebugLog("ÁÄÌìÆøÅÝ¿ò²»¿ÉÓÃ! boxID=%s" % (boxID), playerID) return curStar = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ChatBoxStar % boxID) nextStar = curStar + 1 nextIpyData = IpyGameDataPY.GetIpyGameData("ChatBubbleBoxStar", boxID, nextStar) if not nextIpyData: GameWorld.DebugLog("²»´æÔÚ¸ÃÆøÅÝ¿òÐǼ¶! boxID=%s,nextStar=%s" % (boxID, nextStar), playerID) return needItemList = nextIpyData.GetStarUpNeedItemList() if not needItemList: return itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem) lackItemDict, delInfoDict = ItemCommon.GetCostItemIndexList(needItemList, itemPack) if lackItemDict: GameWorld.DebugLog("ÆøÅÝ¿òÉýÐÇËùÐèÎïÆ·²»×ã! boxID=%s,nextStar=%s,needItemList=%s,lackItemDict=%s" % (boxID, nextStar, needItemList, lackItemDict), playerID) return ItemCommon.DelCostItem(curPlayer, itemPack, delInfoDict, "ChatBoxStarUP") PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ChatBoxStar % boxID, nextStar) GameWorld.DebugLog("ÆøÅÝ¿òÉýÐÇ! boxID=%s,curStar=%s,nextStar=%s" % (boxID, curStar, nextStar), playerID) RefreshBoxAttr(curPlayer) SyncChatBoxInfo(curPlayer, [boxID]) return def SyncChatBoxInfo(curPlayer, boxIDList=None): if boxIDList == None: syncIDList = [] ipyDataMgr = IpyGameDataPY.IPY_Data() for index in range(ipyDataMgr.GetChatBubbleBoxCount()): ipyData = ipyDataMgr.GetChatBubbleBoxByIndex(index) syncIDList.append(ipyData.GetBoxID()) else: syncIDList = boxIDList boxList = [] for boxID in syncIDList: state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBubbleBoxState, boxID) if not state and boxIDList == None: continue box = ChPyNetSendPack.tagMCChatBubbleBox() box.BoxID = boxID box.State = state box.EndTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ChatBoxEndTime % boxID) box.Star = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ChatBoxStar % boxID) boxList.append(box) if not boxList: return clientPack = ChPyNetSendPack.tagMCChatBubbleBoxState() clientPack.BoxList = boxList clientPack.Count = len(clientPack.BoxList) NetPackCommon.SendFakePack(curPlayer, clientPack) return ##------------------------------------------------------------------------------------------------- def AddEmojiPack(curPlayer, packID, setExpireTimes=None): if packID <= 0: return playerID = curPlayer.GetPlayerID() ipyData = IpyGameDataPY.GetIpyGameData("EmojiPack", packID) if not ipyData: return if ipyData.GetUnlockDefault(): GameWorld.DebugLog("±íÇé°üĬÈϽâËøµÄ²»ÓÃÌí¼Ó: packID=%s" % (packID), playerID) return ipyExpireSeconds = ipyData.GetExpireMinutes() * 60 curTime = int(time.time()) state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_EmojiPackState, packID) endTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_EmojiPackEndTime % packID) GameWorld.Log("Ìí¼Ó±íÇé°ü: packID=%s,setExpireTimes=%s,state=%s,endTime=%s,ipyExpireSeconds=%s,curTime=%s" % (packID, setExpireTimes, state, endTime, ipyExpireSeconds, curTime), playerID) updEndTime = endTime # Ö¸¶¨Ê±³¤µÄ£¬ÈçGMÖ¸¶¨ if setExpireTimes >= 0: updEndTime = curTime + setExpireTimes GameWorld.Log(" Ö¸¶¨±íÇé°üʱ³¤: packID=%s,updEndTime=%s" % (packID, updEndTime), playerID) # ÓÀ¾Ã elif ipyExpireSeconds == 0: updEndTime = 0 GameWorld.Log(" Ìí¼ÓÓÀ¾Ã±íÇé°ü: packID=%s,updEndTime=%s" % (packID, updEndTime), playerID) else: # δ¹ýÆÚ if endTime > curTime: updEndTime = endTime + ipyExpireSeconds GameWorld.Log(" ÀÛ¼Ó±íÇé°üʱ³¤: packID=%s,updEndTime=%s" % (packID, updEndTime), playerID) else: updEndTime = curTime + ipyExpireSeconds GameWorld.Log(" ÖØÐ¼¤»î±íÇé°ü: packID=%s,updEndTime=%s" % (packID, updEndTime), playerID) GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_EmojiPackState, packID, 1) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_EmojiPackEndTime % packID, updEndTime) SyncEmojiPackInfo(curPlayer, [packID]) return True def DelEmojiPack(curPlayer, packID, notifyMail=""): playerID = curPlayer.GetPlayerID() ipyData = IpyGameDataPY.GetIpyGameData("EmojiPack", packID) if not ipyData: return if ipyData.GetUnlockDefault(): return GameWorld.Log("ɾ³ýÍæ¼ÒÁÄÌì±íÇé°ü: packID=%s,notifyMail=%s" % (packID, notifyMail), playerID) GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_EmojiPackState, packID, 0) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_EmojiPackEndTime % packID, 0) SyncEmojiPackInfo(curPlayer, [packID]) if notifyMail: PlayerControl.SendMailByKey(notifyMail, [playerID], [], [packID]) return True def SyncEmojiPackInfo(curPlayer, packIDList=None): if packIDList == None: syncIDList = [] ipyDataMgr = IpyGameDataPY.IPY_Data() for index in range(ipyDataMgr.GetEmojiPackCount()): ipyData = ipyDataMgr.GetEmojiPackByIndex(index) syncIDList.append(ipyData.GetEmojiPackID()) else: syncIDList = packIDList packList = [] for packID in syncIDList: state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_EmojiPackState, packID) if not state and packIDList == None: continue pack = ChPyNetSendPack.tagMCEmojiPack() pack.PackID = packID pack.State = state pack.EndTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_EmojiPackEndTime % packID) packList.append(pack) if not packList: return clientPack = ChPyNetSendPack.tagMCEmojiPackInfo() clientPack.EmojiPackList = packList clientPack.Count = len(clientPack.EmojiPackList) NetPackCommon.SendFakePack(curPlayer, clientPack) return