ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerChatBox.py
@@ -16,7 +16,7 @@
#-------------------------------------------------------------------------------
import GameWorld
import ShareDefine
import PlayerHJG
import PlayerControl
import IPY_GameWorld
import ChPyNetSendPack
@@ -24,25 +24,23 @@
import NetPackCommon
import ItemCommon
import ChConfig
import ObjPool
import time
def OnPlayerLogin(curPlayer):
    SyncChatBoxInfo(curPlayer)
    SyncEmojiPackInfo(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)
    for index in range(ipyDataMgr.GetChatBoxCount()):
        ipyData = ipyDataMgr.GetChatBoxByIndex(index)
        boxID = ipyData.GetBoxID()
        if ipyData.GetUnlockDefault():
            # 默认激活的不处理
            continue
        if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBubbleBoxState, boxID):
        if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBoxState, boxID):
            # 未激活的不处理
            continue
        endTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ChatBoxEndTime % boxID)
@@ -55,38 +53,51 @@
    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")
#    # 表情包
#    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):
def AddChatBox(curPlayer, boxID, setExpireTimes=None, isFree=False):
    if boxID <= 0:
        return
    playerID = curPlayer.GetPlayerID()
    ipyData = IpyGameDataPY.GetIpyGameData("ChatBubbleBox", boxID)
    ipyData = IpyGameDataPY.GetIpyGameData("ChatBox", boxID)
    if not ipyData:
        return
    if ipyData.GetUnlockDefault():
        GameWorld.DebugLog("气泡框默认解锁的不用添加: boxID=%s" % (boxID), playerID)
    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_ChatBubbleBoxState, boxID)
    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)
@@ -95,23 +106,23 @@
    # 指定时长的,如GM指定
    if setExpireTimes >= 0:
        updEndTime = curTime + setExpireTimes
        GameWorld.Log("    指定气泡框时长: boxID=%s,updEndTime=%s" % (boxID, updEndTime), playerID)
        GameWorld.Log("    指定时长: boxID=%s,updEndTime=%s" % (boxID, updEndTime), playerID)
        
    # 永久
    elif ipyExpireSeconds == 0:
        updEndTime = 0
        GameWorld.Log("    添加永久气泡框: boxID=%s,updEndTime=%s" % (boxID, updEndTime), playerID)
        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)
            GameWorld.Log("    累加时长: boxID=%s,updEndTime=%s" % (boxID, updEndTime), playerID)
        else:
            updEndTime = curTime + ipyExpireSeconds
            GameWorld.Log("    重新激活气泡框: boxID=%s,updEndTime=%s" % (boxID, updEndTime), playerID)
            GameWorld.Log("    重新激活: boxID=%s,updEndTime=%s" % (boxID, updEndTime), playerID)
            
    GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBubbleBoxState, boxID, 1)
    GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBoxState, boxID, 1)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ChatBoxEndTime % boxID, updEndTime)
    RefreshBoxAttr(curPlayer)
    SyncChatBoxInfo(curPlayer, [boxID])
@@ -119,19 +130,19 @@
def DelChatBox(curPlayer, boxID, isRefreshAttr=True, notifyMail=""):
    playerID = curPlayer.GetPlayerID()
    ipyData = IpyGameDataPY.GetIpyGameData("ChatBubbleBox", boxID)
    ipyData = IpyGameDataPY.GetIpyGameData("ChatBox", boxID)
    if not ipyData:
        return
    if ipyData.GetUnlockDefault():
    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_ChatBubbleBoxState, boxID, 0)
    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.GetChatBubbleBox(curPlayer) == boxID:
    if PlayerControl.GetChatBox(curPlayer) == boxID:
        canUseID = GetCanUseBoxID(curPlayer)
        PlayerControl.SetChatBubbleBox(curPlayer, canUseID)
        PlayerControl.SetChatBox(curPlayer, canUseID)
        GameWorld.DebugLog("玩家聊天气泡框被删除,重新设置可用ID=%s" % canUseID, playerID)
        
    if isRefreshAttr:
@@ -144,8 +155,8 @@
def GetCanUseBoxID(curPlayer):
    ## 获取一个可用的气泡框
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for index in range(ipyDataMgr.GetChatBubbleBoxCount())[::-1]:
        ipyData = ipyDataMgr.GetChatBubbleBoxByIndex(index)
    for index in range(ipyDataMgr.GetChatBoxCount())[::-1]:
        ipyData = ipyDataMgr.GetChatBoxByIndex(index)
        boxID = ipyData.GetBoxID()
        if IsBoxCanUse(curPlayer, boxID, ipyData):
            return boxID
@@ -153,141 +164,92 @@
def IsBoxCanUse(curPlayer, boxID, ipyData=None):
    ## 气泡框是否可用
    state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBubbleBoxState, boxID)
    state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBoxState, boxID)
    if state:
        return True
    
    if not ipyData:
        ipyData = IpyGameDataPY.GetIpyGameData("ChatBubbleBox", boxID)
        ipyData = IpyGameDataPY.GetIpyGameData("ChatBox", 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
        if needLV:
        unlockWay = ipyData.GetUnlockWay()
        if unlockWay == 1: # 默认激活的
            return True
        
    return False
def RefreshBoxAttr(curPlayer):
    CalcBoxAttr(curPlayer)
    PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    PlayerHJG.RefreshHJGAttr(curPlayer)
    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)
    PlayerControl.SetMFPExFightPower(curPlayer, 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
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.SetChatBubbleBox(curPlayer, useBoxID)
    PlayerControl.SetChatBox(curPlayer, useBoxID)
    return
#// A2 36 聊天气泡框升星 #tagCMChatBubbleBoxStarUP
#
#struct    tagCMChatBubbleBoxStarUP
#{
#    tagHead         Head;
#    WORD        BoxID;    //气泡ID
#};
def OnChatBubbleBoxStarUP(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
def OnChatBoxStarUP(curPlayer, boxID):
    playerID = curPlayer.GetPlayerID()
    boxID = clientData.BoxID
    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)        
    nextStar = curStar + 1
    nextIpyData = IpyGameDataPY.GetIpyGameData("ChatBubbleBoxStar", boxID, nextStar)
    if not nextIpyData:
        GameWorld.DebugLog("不存在该气泡框星级! boxID=%s,nextStar=%s" % (boxID, nextStar), playerID)
    if curStar >= starMax:
        GameWorld.DebugLog("星级已满! boxID=%s,curStar=%s >= %s" % (boxID, curStar, starMax), playerID)
        return
    needItemList = nextIpyData.GetStarUpNeedItemList()
    if not needItemList:
    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,nextStar=%s,needItemList=%s,lackItemDict=%s"
                           % (boxID, nextStar, needItemList, lackItemDict), playerID)
        GameWorld.DebugLog("升星所需物品不足! boxID=%s,lackItemDict=%s" % (boxID, lackItemDict), playerID)
        return
    ItemCommon.DelCostItem(curPlayer, itemPack, delInfoDict, "ChatBoxStarUP")
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ChatBoxStar % boxID, nextStar)
    nextStar = curStar + 1
    GameWorld.DebugLog("升星! boxID=%s,nextStar=%s" % (boxID, nextStar), playerID)
    SetChatBoxStar(curPlayer, boxID, nextStar)
    return
    
    GameWorld.DebugLog("气泡框升星! boxID=%s,curStar=%s,nextStar=%s" % (boxID, curStar, nextStar), playerID)
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
    return True
def SyncChatBoxInfo(curPlayer, boxIDList=None):
    if boxIDList == None:
        syncIDList = []
        ipyDataMgr = IpyGameDataPY.IPY_Data()
        for index in range(ipyDataMgr.GetChatBubbleBoxCount()):
            ipyData = ipyDataMgr.GetChatBubbleBoxByIndex(index)
        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_ChatBubbleBoxState, boxID)
        state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ChatBoxState, boxID)
        if not state and boxIDList == None:
            continue
        box = ChPyNetSendPack.tagMCChatBubbleBox()
        box = ObjPool.GetPoolMgr().acquire(ChPyNetSendPack.tagSCChatBox)
        box.BoxID = boxID
        box.State = state
        box.EndTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ChatBoxEndTime % boxID)
@@ -297,7 +259,7 @@
    if not boxList:
        return
    
    clientPack = ChPyNetSendPack.tagMCChatBubbleBoxState()
    clientPack = ObjPool.GetPoolMgr().acquire(ChPyNetSendPack.tagSCChatBoxInfo)
    clientPack.BoxList = boxList
    clientPack.Count = len(clientPack.BoxList)
    NetPackCommon.SendFakePack(curPlayer, clientPack)