hxp
2022-03-15 27851e45dc926af04efcbdefbeb951d3560deb58
ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerCompensation.py
@@ -286,6 +286,8 @@
#  @param curItemDict 
#  @return IpyCompensationItem
def MakeCompensationItem(curItemDict):
    if not __checkMailItemDict(curItemDict):
        return
    curItemData = IPY_GameServer.IpyCompensationItem()
    #curItemData.GUID = curItemDict['GUID']
    curItemData.ItemID = curItemDict['ItemID']
@@ -307,7 +309,7 @@
    
def SendPersonalItemMailBatch(batchMailInfoList):
    ## 批量发送邮件
    mailTypeKey, batchPlayerIDList, batchAddItemList, batchParamList, batchGold, batchGoldPaper, batchSilver, batchDetail, moneySource = batchMailInfoList
    mailTypeKey, batchPlayerIDList, batchAddItemList, batchParamList, batchGold, batchGoldPaper, batchSilver, batchDetail, moneySource, crossMail = batchMailInfoList
    
    lenPlayerID = len(batchPlayerIDList)
    lenItem = len(batchAddItemList)
@@ -332,7 +334,7 @@
        silver = batchSilver[i] if lenSilver == lenPlayerID else 0
        detail = batchDetail[i] if lenDetail == lenPlayerID else ""
        content = "<MailTemplate>%s</MailTemplate>%s" % (mailTypeKey, str(paramList))
        SendPersonalItemMail(title, content, limitTime, playerIDList, addItemList, gold, goldPaper, silver, detail=detail, moneySource=moneySource)
        SendPersonalItemMail(title, content, limitTime, playerIDList, addItemList, gold, goldPaper, silver, detail=detail, moneySource=moneySource, crossMail=crossMail)
        
    return
@@ -355,6 +357,55 @@
    SendMailByKey(mailTypeKey, playerIDList, addItemList, paramList)
    return
def __checkMailItemIDCount(itemID, itemCount, isAuctionItem):
    ## 检查是否合法的邮件物品ID Count 数据
    if not (isinstance(itemID, int) or isinstance(itemID, long)):
        return
    if not (isinstance(itemCount, int) or isinstance(itemCount, long)):
        return
    if not (isinstance(isAuctionItem, int) or isinstance(isAuctionItem, long) or isinstance(isAuctionItem, bool)):
        return
    if itemID > ShareDefine.Def_UpperLimit_DWord or itemCount > ShareDefine.Def_UpperLimit_DWord or isAuctionItem > 255:
        return
    return True
def __checkMailItemDict(curItemDict):
    ## 检查是否合法的邮件物品dict信息  {"ItemID":xxx, "Count":xxx, "IsAuctionItem":xxx}
    if not isinstance(curItemDict, dict):
        return
    if "ItemID" not in curItemDict or "Count" not in curItemDict:
        return
    itemID = curItemDict["ItemID"]
    itemCount = curItemDict["Count"]
    isAuctionItem = curItemDict.get("IsAuctionItem", 0)
    if not __checkMailItemIDCount(itemID, itemCount, isAuctionItem):
        return
    return curItemDict
def __checkMailItemList(addItemList):
    ## 检查是否合法的邮件物品列表
    addItemDictList = []
    for itemInfo in addItemList:
        if isinstance(itemInfo, dict):
            if not __checkMailItemDict(itemInfo):
                return False, []
            addItemDictList.append(itemInfo)
            continue
        if (isinstance(itemInfo, list) or isinstance(itemInfo, tuple)) and (len(itemInfo) == 3 or len(itemInfo) == 2):
            itemID, itemCount = itemInfo[:2]
            isAuctionItem = itemInfo[2] if len(itemInfo) > 2 else 0
            if not __checkMailItemIDCount(itemID, itemCount, isAuctionItem):
                return False, []
            addItemDict = {}
            addItemDict['ItemID'] = itemID
            addItemDict['Count'] = itemCount
            addItemDict['IsAuctionItem'] = isAuctionItem
            addItemDictList.append(addItemDict)
        else:
            return False, []
    return True, addItemDictList
#  此处货币playerIDList发放统一,如根据玩家不同而变,则应需修改
## 功能发放物品补偿/奖励邮件
#  @param addItemList [(itemID, itemCnt, 是否拍品), {或物品信息字典}, ...]
@@ -373,25 +424,16 @@
    if not curServerTime or curServerTime >= limitTime:
        GameWorld.DebugLog("功能发放物品补偿/奖励邮件,领取时间已超时,默认不添加!LimitTime=%s" % limitTime)
        return ""
    isOK, addItemDictList = __checkMailItemList(addItemList)
    if not isOK:
        GameWorld.ErrLog("发送个人邮件错误: title=%s,content=%s,playerIDList=%s,addItemList=%s,gold=%s,goldPaper=%s,silver=%s,detail=%s,moneySource=%s,crossMail=%s"
                         % (title, content, playerIDList, addItemList, gold, goldPaper, silver, detail, moneySource, crossMail))
        return
    
    addItemDictList = []
    for itemInfo in addItemList:
        if isinstance(itemInfo, dict):
            addItemDictList.append(itemInfo)
            continue
        if len(itemInfo) == 3:
            itemID, itemCnt, isAuctionItem = itemInfo
        else:
            continue
        addItemDict = {}
        addItemDict['ItemID'] = itemID
        addItemDict['Count'] = itemCnt
        addItemDict['IsAuctionItem'] = isAuctionItem
        addItemDictList.append(addItemDict)
    gold = min(gold, ShareDefine.Def_UpperLimit_DWord)
    goldPaper = min(goldPaper, ShareDefine.Def_UpperLimit_DWord)
    silver = min(silver, ShareDefine.Def_UpperLimit_DWord)
    perMailItemCnt = IpyGameDataPY.GetFuncCfg("MailMaxItemCnt")
    mailCnt = max(1, int(math.ceil(len(addItemDictList)/float(perMailItemCnt)))) # 一封邮件最多5个物品
    for i in xrange(mailCnt):
@@ -608,23 +650,16 @@
    if not mailTypeKey or getDays <= 0:
        return
    
    addItemDictList = []
    for itemInfo in addItemList:
        if isinstance(itemInfo, dict):
            addItemDictList.append(itemInfo)
            continue
        if len(itemInfo) == 3:
            itemID, itemCnt, isAuctionItem = itemInfo
        else:
            continue
        addItemDict = {}
        addItemDict['ItemID'] = itemID
        addItemDict['Count'] = itemCnt
        addItemDict['IsAuctionItem'] = isAuctionItem
        addItemDictList.append(addItemDict)
    isOK, addItemDictList = __checkMailItemList(addItemList)
    if not isOK:
        GameWorld.ErrLog("发送全服邮件错误: mailTypeKey=%s,addItemList=%s,paramList=%s,gold=%s,goldPaper=%s,silver=%s,detail=%s,moneySource=%s"
                     % (mailTypeKey, addItemList, paramList, gold, goldPaper, silver, detail, moneySource))
        return
    gold = min(gold, ShareDefine.Def_UpperLimit_DWord)
    goldPaper = min(goldPaper, ShareDefine.Def_UpperLimit_DWord)
    silver = min(silver, ShareDefine.Def_UpperLimit_DWord)
    if not GUID:
        GUID = str(uuid.uuid1())
        
@@ -659,11 +694,16 @@
    #添加补偿包的所有物品
    for addItemDict in addItemDictList:
        curItemData = MakeCompensationItem(addItemDict)
        if not curItemData:
            return
        GameWorld.GetCompensationMgr().AddCompensationItem(GUID, curItemData)
        
    createTime = GameWorld.GetCurrentDataTimeStr()
    
    #添加全服领取补偿条件
    gold = min(gold, ShareDefine.Def_UpperLimit_DWord)
    goldPaper = min(goldPaper, ShareDefine.Def_UpperLimit_DWord)
    silver = min(silver, ShareDefine.Def_UpperLimit_DWord)
    GameWorld.GetCompensationMgr().AddEntireCompensationItem(GUID, createTime, LimitTime, mailInfo, 
                                                             PlayerJob, Text, gold, goldPaper, silver, serverID)
    checkState, limitLVType, limitLV = ParseEntireCompensationInfo(mailInfo)
@@ -705,14 +745,19 @@
    GameWorld.DebugLog("新增个人邮件: totalCount=%s,maxMailCount=%s" % (totalCount, maxMailCount), PlayerID)
    if delCount > 0:
        GameWorld.Log("个人邮件达到上限,需要删除!delCount=%s" % (delCount), PlayerID)
        delGUIDList = GetPlayerDelMailGUIDList(PlayerID)
        #先取得要删除的GUID
        delGUIDs = []
        for i in xrange(delCount):
            curIpyPersonalData = GameWorld.GetCompensationMgr().PersonalCompensationAt(PlayerID, i)
            delGUIDs.append(curIpyPersonalData.GUID)
        for _ in xrange(delCount):
            if not delGUIDList:
                break
            delGUID = delGUIDList.pop(0)
            curIpyPersonalData = GameWorld.GetCompensationMgr().FindPersonalCompensation(PlayerID, delGUID)
            if curIpyPersonalData.GUID == delGUID:
                delGUIDs.append(curIpyPersonalData.GUID)
            
        for guid in delGUIDs:
            ClearPersonalCompensation(PlayerID, guid)
            ClearPersonalCompensation(PlayerID, guid, "MaxCountLimiit")
            GameWorld.Log("    DeletePersonalCompensation GUID = %s" % guid, PlayerID)
            
            if curPlayer:
@@ -721,10 +766,34 @@
            
    #此处没有下发通知
    mailType = moneySource - ChConfig.Def_GiveMoney_Unknown # type类型为byte,存值时需要处理下
    gold = min(gold, ShareDefine.Def_UpperLimit_DWord)
    goldPaper = min(goldPaper, ShareDefine.Def_UpperLimit_DWord)
    silver = min(silver, ShareDefine.Def_UpperLimit_DWord)
    GameWorld.GetCompensationMgr().AddPersonalCompensation(GUID, PlayerID, CreateTime,
                                                           LimitTime, Text, mailType, gold, goldPaper, silver)
    if PlayerID in PyGameData.g_playerDelMailGUIDDict:
        guidList = PyGameData.g_playerDelMailGUIDDict[PlayerID]
        guidList.append(GUID)
    return
def GetPlayerDelMailGUIDList(playerID):
    ## 获取待删除的个人邮件GUID列表
    if playerID not in PyGameData.g_playerDelMailGUIDDict:
        timeGUIDList = []
        curPersonalCount = GameWorld.GetCompensationMgr().GetPersonalCompensationCount(playerID)
        for i in xrange(curPersonalCount):
            curMail = GameWorld.GetCompensationMgr().PersonalCompensationAt(playerID, i)
            timeGUIDList.append([curMail.CreateTime, curMail.GUID])
        timeGUIDList.sort() # 按创建时间升序排序
        delGUIDList = []
        for _, guid in timeGUIDList:
            if guid not in delGUIDList:
                delGUIDList.append(guid)
        PyGameData.g_playerDelMailGUIDDict[playerID] = delGUIDList
    return PyGameData.g_playerDelMailGUIDDict[playerID]
#  此处货币playerIDList发放统一,如根据玩家不同而变,则应需修改
## 添加个人补偿
@@ -741,6 +810,8 @@
    #添加补偿包的所有物品
    for addItemDict in addItemDictList:
        curItemData = MakeCompensationItem(addItemDict)
        if not curItemData:
            return
        GameWorld.GetCompensationMgr().AddCompensationItem(GUID, curItemData)
        
    #offlinePlayerIDList = []
@@ -858,13 +929,21 @@
    return
# 删除个人邮件表 状态表,同一个GUID 可以多人领取,不能同时删除物品
def ClearPersonalCompensation(curPlayerID, curGUID):
def ClearPersonalCompensation(curPlayerID, curGUID, eventName=""):
    GameWorld.GetCompensationMgr().DeletePersonalCompensation(curPlayerID, curGUID)
    GameWorld.GetCompensationMgr().DeletePlayerCompensationRec(curPlayerID, curGUID)
    
    #存在多人邮件的情况,故删除物品需检查是否最后一个领取者才可删除
    if GameWorld.GetCompensationMgr().GetPersonalCountByGUID(curGUID) == 0:
        GameWorld.GetCompensationMgr().DeleteCompensationItem(curGUID)
    if curPlayerID in PyGameData.g_playerDelMailGUIDDict:
        guidList = PyGameData.g_playerDelMailGUIDDict[curPlayerID]
        if curGUID in guidList:
            guidList.remove(curGUID)
    if eventName:
        # 有特殊操作删除的才记录,常规领取删除的默认无eventName,不记录
        DataRecordPack.DR_DelPersonalCompensation(curPlayerID, curGUID, eventName)
    return
# 设置领取状态
@@ -1189,11 +1268,27 @@
#  @return None
def ClearUpPersonalCompensation():
    #校验过期补偿
    tempSign = "<MailTemplate>"
    tempSignEnd = "</MailTemplate>"
    curTime = datetime.datetime.today()
    needClearGUIDList = []
    allCnt = GameWorld.GetCompensationMgr().GetAllPersonalCompensationCount()
    for i in xrange(allCnt):
        curMail = GameWorld.GetCompensationMgr().AtAllPersonalCompensation(i)
        mailText = curMail.Text
        # 通知类模板邮件,过天可直接删除
        if tempSign in mailText and tempSignEnd in mailText and CheckCanDelCompensation(curMail, curMail.GUID):
            tempKey = mailText[mailText.index(tempSign) + len(tempSign):mailText.index(tempSignEnd)]
            notClearMailKeyList = IpyGameDataPY.GetFuncEvalCfg("MailSet", 1)
            if tempKey not in notClearMailKeyList:
                #GameWorld.DebugLog("过天删除无附件通知类邮件模板! tempKey=%s %s, %s" % (tempKey, curMail.PlayerID, curMail.GUID))
                needClearGUIDList.append([curMail.PlayerID, curMail.GUID])
                player = GameWorld.GetPlayerManager().FindPlayerByID(curMail.PlayerID)
                if player and player.GetInitOK():
                    NotifyCompensationResult(player, curMail.GUID, 1)
                continue
        # 超过接收邮件30天则完全删除此邮件
        limitTime = datetime.datetime.strptime(curMail.CreateTime, ChConfig.TYPE_Time_Format) + datetime.timedelta(days = 30)
        if limitTime < curTime:
@@ -1203,7 +1298,7 @@
        
    #删除过期补偿信息, 没有主动通知在线玩家
    for playerID, GUID in needClearGUIDList:
        ClearPersonalCompensation(playerID, GUID)
        ClearPersonalCompensation(playerID, GUID, "Timeout")
    return
## 清理超时补偿, 个人邮件在超过上限后才会自动删除
@@ -1272,7 +1367,7 @@
            NotifyCompensationResult(curPlayer, GUID, 0)
            return
        
        ClearPersonalCompensation(curPlayerID, GUID)
        ClearPersonalCompensation(curPlayerID, GUID, "ClientDel")
        NotifyCompensationResult(curPlayer, GUID, 1)
        #GameWorld.DebugLog("个人补偿中OnDelCompensation:%s"%GUID)
        return