#!/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 PlayerHJG
|
import PlayerControl
|
import IPY_GameWorld
|
import ChPyNetSendPack
|
import IpyGameDataPY
|
import NetPackCommon
|
import ItemCommon
|
import ChConfig
|
import ObjPool
|
|
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.GetChatBoxCount()):
|
ipyData = ipyDataMgr.GetChatBoxByIndex(index)
|
boxID = ipyData.GetBoxID()
|
if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBoxState, 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, isFree=False):
|
if boxID <= 0:
|
return
|
playerID = curPlayer.GetPlayerID()
|
ipyData = IpyGameDataPY.GetIpyGameData("ChatBox", boxID)
|
if not ipyData:
|
return
|
if ipyData.GetUnlockWay() != 2:
|
GameWorld.DebugLog("·ÇµÀ¾ß¼¤»îµÄ²»ÓÃÌí¼Ó: boxID=%s" % (boxID), playerID)
|
return
|
if not isFree:
|
itemID = ipyData.GetUnlockValue()
|
itemCount = ipyData.GetUnlockNeedCnt()
|
if not itemID or not itemCount:
|
return
|
needItemList = [[itemID, itemCount]]
|
itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
|
lackItemDict, delInfoDict = ItemCommon.GetCostItemIndexList(needItemList, itemPack)
|
if lackItemDict:
|
GameWorld.DebugLog("¼¤»îËùÐèÎïÆ·²»×ã! boxID=%s,lackItemDict=%s" % (boxID, lackItemDict), playerID)
|
return
|
ItemCommon.DelCostItem(curPlayer, itemPack, delInfoDict, "AddChatBox")
|
|
ipyExpireSeconds = ipyData.GetExpireMinutes() * 60
|
|
curTime = int(time.time())
|
state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBoxState, 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_ChatBoxState, 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("ChatBox", boxID)
|
if not ipyData:
|
return
|
if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBoxState, boxID):
|
return
|
GameWorld.Log("ɾ³ýÆøÅÝ¿ò: boxID=%s,notifyMail=%s" % (boxID, notifyMail), playerID)
|
GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBoxState, boxID, 0)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ChatBoxEndTime % boxID, 0)
|
# ÐǼ¶²»ÖØÖã¬ÖØÐ¼¤»îºóÔÙ´ÎÉúЧ
|
|
if PlayerControl.GetChatBox(curPlayer) == boxID:
|
canUseID = GetCanUseBoxID(curPlayer)
|
PlayerControl.SetChatBox(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.GetChatBoxCount())[::-1]:
|
ipyData = ipyDataMgr.GetChatBoxByIndex(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_ChatBoxState, boxID)
|
if state:
|
return True
|
|
if not ipyData:
|
ipyData = IpyGameDataPY.GetIpyGameData("ChatBox", boxID)
|
if ipyData:
|
unlockWay = ipyData.GetUnlockWay()
|
if unlockWay == 1: # ĬÈϼ¤»îµÄ
|
return True
|
|
return False
|
|
def RefreshBoxAttr(curPlayer):
|
PlayerHJG.RefreshHJGAttr(curPlayer)
|
return
|
|
def OnUseChatBox(curPlayer, useBoxID):
|
playerID = curPlayer.GetPlayerID()
|
if not IsBoxCanUse(curPlayer, useBoxID):
|
GameWorld.DebugLog("ÁÄÌìÆøÅÝ¿ò²»¿ÉÓã¬ÎÞ·¨ÉèÖÃ! useBoxID=%s" % useBoxID, playerID)
|
return
|
GameWorld.DebugLog("ÉèÖÃʹÓõÄÁÄÌìÆøÅÝ¿òID: useBoxID=%s" % useBoxID, playerID)
|
PlayerControl.SetChatBox(curPlayer, useBoxID)
|
return
|
|
def OnChatBoxStarUP(curPlayer, boxID):
|
playerID = curPlayer.GetPlayerID()
|
if not IsBoxCanUse(curPlayer, boxID):
|
GameWorld.DebugLog("ÁÄÌìÆøÅÝ¿ò²»¿ÉÓÃ! boxID=%s" % (boxID), playerID)
|
return
|
ipyData = IpyGameDataPY.GetIpyGameData("ChatBox", boxID)
|
if not ipyData:
|
return
|
starMax = ipyData.GetStarMax()
|
curStar = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ChatBoxStar % boxID)
|
if curStar >= starMax:
|
GameWorld.DebugLog("ÐǼ¶ÒÑÂú! boxID=%s,curStar=%s >= %s" % (boxID, curStar, starMax), playerID)
|
return
|
if ipyData.GetUnlockWay() != 2:
|
return
|
itemID = ipyData.GetUnlockValue()
|
itemCount = ipyData.GetUnlockNeedCnt()
|
if not itemID or not itemCount:
|
return
|
needItemList = [[itemID, itemCount]]
|
itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
|
lackItemDict, delInfoDict = ItemCommon.GetCostItemIndexList(needItemList, itemPack)
|
if lackItemDict:
|
GameWorld.DebugLog("ÉýÐÇËùÐèÎïÆ·²»×ã! boxID=%s,lackItemDict=%s" % (boxID, lackItemDict), playerID)
|
return
|
ItemCommon.DelCostItem(curPlayer, itemPack, delInfoDict, "ChatBoxStarUP")
|
|
nextStar = curStar + 1
|
GameWorld.DebugLog("ÉýÐÇ! boxID=%s,nextStar=%s" % (boxID, nextStar), playerID)
|
SetChatBoxStar(curPlayer, boxID, nextStar)
|
return
|
|
def SetChatBoxStar(curPlayer, boxID, setStar):
|
if not IsBoxCanUse(curPlayer, boxID):
|
return
|
ipyData = IpyGameDataPY.GetIpyGameData("ChatBox", boxID)
|
if not ipyData:
|
return
|
setStar = min(setStar, ipyData.GetStarMax())
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ChatBoxStar % boxID, setStar)
|
RefreshBoxAttr(curPlayer)
|
SyncChatBoxInfo(curPlayer, [boxID])
|
return True
|
|
def SyncChatBoxInfo(curPlayer, boxIDList=None):
|
if boxIDList == None:
|
syncIDList = []
|
ipyDataMgr = IpyGameDataPY.IPY_Data()
|
for index in range(ipyDataMgr.GetChatBoxCount()):
|
ipyData = ipyDataMgr.GetChatBoxByIndex(index)
|
syncIDList.append(ipyData.GetBoxID())
|
else:
|
syncIDList = boxIDList
|
|
boxList = []
|
for boxID in syncIDList:
|
state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBoxState, boxID)
|
if not state and boxIDList == None:
|
continue
|
box = ObjPool.GetPoolMgr().acquire(ChPyNetSendPack.tagSCChatBox)
|
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 = ObjPool.GetPoolMgr().acquire(ChPyNetSendPack.tagSCChatBoxInfo)
|
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
|