hxp
2019-10-29 2941a7635bb04ca59afa820b51a23aca9dc70eb9
ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerCompensation.py
@@ -76,24 +76,24 @@
    #curItemData.GUID = curItemDict['GUID']
    curItemData.ItemID = curItemDict['ItemID']
    curItemData.Count = curItemDict['Count']
    curItemData.IsBind = curItemDict.get('IsBind',0)
    #curItemData.IsBind = curItemDict.get('IsBind',0)
    curItemData.IsBind = curItemDict.get('IsAuctionItem',0)
    curItemData.UserData = curItemDict.get('UserData', '')
    return curItemData
#  此处货币playerIDList发放统一,如根据玩家不同而变,则应需修改
## 功能发放物品补偿/奖励邮件
#  @param addItemList [(itemID, itemCnt, isBind), {或物品信息字典}, ...]
#  @param addItemList [(itemID, itemCnt, 是否拍品), {或物品信息字典}, ...]
#  @return GUID
def SendPersonalItemMailEx(title, content, getDays, playerIDList, addItemList,
                           gold = 0, goldPaper = 0, silver = 0, sourceType = ChConfig.Mail_Type_Default, detail=""):
def SendPersonalItemMailEx(title, content, getDays, playerIDList, addItemList, gold = 0, goldPaper = 0, silver = 0,
                           detail="", moneySource=ChConfig.Def_GiveMoney_Mail):
    limitTime = str(GameWorld.GetDatetimeByDiffDays(getDays))
    limitTime = limitTime.split(".")[0]
    return SendPersonalItemMail(title, content, limitTime, playerIDList, addItemList,
                                gold, goldPaper, silver, sourceType, detail=detail)
    return SendPersonalItemMail(title, content, limitTime, playerIDList, addItemList, gold, goldPaper, silver, detail, moneySource)
    
def SendPersonalItemMailBatch(batchMailInfoList):
    ## 批量发送邮件
    mailTypeKey, batchPlayerIDList, batchAddItemList, batchParamList, batchGold, batchGoldPaper, batchSilver, batchDetail = batchMailInfoList
    mailTypeKey, batchPlayerIDList, batchAddItemList, batchParamList, batchGold, batchGoldPaper, batchSilver, batchDetail, moneySource = batchMailInfoList
    
    lenPlayerID = len(batchPlayerIDList)
    lenItem = len(batchAddItemList)
@@ -116,26 +116,36 @@
        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)
        SendPersonalItemMail(title, content, limitTime, playerIDList, addItemList, gold, goldPaper, silver, detail=detail, moneySource=moneySource)
        
    return
def SendMailByKey(mailTypeKey, playerIDList, addItemList, paramList=[], gold=0, goldPaper=0, silver=0, detail=""):
def SendMailByKey(mailTypeKey, playerIDList, addItemList, paramList=[], gold=0, goldPaper=0, silver=0,
                  detail="", moneySource=ChConfig.Def_GiveMoney_Mail):
    if not mailTypeKey:
        mailTypeKey = ShareDefine.DefaultLackSpaceMailType
    GameWorld.DebugLog("SendMailByKey %s, playerIDList=%s, addItemList=%s, paramList=%s, gold=%s, goldPaper=%s, silver=%s"
                       % (mailTypeKey, playerIDList, addItemList, paramList, gold, goldPaper, silver))
    GameWorld.DebugLog("SendMailByKey %s, playerIDList=%s, addItemList=%s, paramList=%s, gold=%s, goldPaper=%s, silver=%s, moneySource=%s"
                       % (mailTypeKey, playerIDList, addItemList, paramList, gold, goldPaper, silver, moneySource))
    title = ""
    content = "<MailTemplate>%s</MailTemplate>%s" % (mailTypeKey, json.dumps(paramList, ensure_ascii=False))
    return SendPersonalItemMailEx(title, content, 30, playerIDList, addItemList, gold, goldPaper, silver, detail=detail)
    return SendPersonalItemMailEx(title, content, 30, playerIDList, addItemList, gold, goldPaper, silver, detail, moneySource)
def CrossServerMsg_SendMail(msgData):
    ## 收到跨服服务器同步的发送邮件
    mailTypeKey = msgData["MailTypeKey"]
    playerIDList = msgData["Player"]
    addItemList = msgData.get("Item", [])
    paramList = msgData.get("Param", [])
    SendMailByKey(mailTypeKey, playerIDList, addItemList, paramList)
    return
#  此处货币playerIDList发放统一,如根据玩家不同而变,则应需修改
## 功能发放物品补偿/奖励邮件
#  @param addItemList [(itemID, itemCnt, isBind), {或物品信息字典}, ...]
#  @param addItemList [(itemID, itemCnt, 是否拍品), {或物品信息字典}, ...]
#  @return GUID
#  @remarks addItemList支持append字典
def SendPersonalItemMail(title, content, limitTime, playerIDList, addItemList,
                         gold = 0, goldPaper = 0, silver = 0, sourceType = ChConfig.Mail_Type_Default, detail=""):
def SendPersonalItemMail(title, content, limitTime, playerIDList, addItemList, gold = 0, goldPaper = 0, silver = 0,
                         detail="", moneySource=ChConfig.Def_GiveMoney_Mail):
    if not playerIDList:
        return ""
    
@@ -156,14 +166,14 @@
        
        
        if len(itemInfo) == 3:
            itemID, itemCnt, isBind = itemInfo
            itemID, itemCnt, isAuctionItem = itemInfo
        else:
            continue
            
        addItemDict = {}
        addItemDict['ItemID'] = itemID
        addItemDict['Count'] = itemCnt
        addItemDict['IsBind'] = isBind
        addItemDict['IsAuctionItem'] = isAuctionItem
        addItemDictList.append(addItemDict)
        
    perMailItemCnt = IpyGameDataPY.GetFuncCfg("MailMaxItemCnt")
@@ -173,19 +183,18 @@
        GUID = str(uuid.uuid1())
        AddPersonalItem(GUID, addItemDictList[startIndex:startIndex + perMailItemCnt], playerIDList, 
                                           limitTime, "%s<$_$>%s<$_$>%s" % (ChConfig.Def_Mail_SenderSys, title, content),
                                           gold, goldPaper, silver, sourceType, detail)
                                           gold, goldPaper, silver, detail, moneySource)
    return GUID
## 发送纯文字个人补偿
#  @param limitTime 可以传空
#  @param sourceType 查看 Mail_Type_Default 相关定义
#  @return None
def SendPersonalAsTextMail(PlayerID, title, content, limitTime, sourceType = ChConfig.Mail_Type_Default):
def SendPersonalAsTextMail(PlayerID, title, content, limitTime):
    if GameWorld.IsCrossServer():
        return
    GUID = str(uuid.uuid1())
    PyAddPersonalCompensation(GUID, PlayerID, GameWorld.GetCurrentDataTimeStr(), limitTime, 
                              "%s<$_$>%s<$_$>%s" % (ChConfig.Def_Mail_SenderSys,title, content), sourceType)
                              "%s<$_$>%s<$_$>%s" % (ChConfig.Def_Mail_SenderSys,title, content))
    return
def GetEntireCompensationInfo(checkState, limitLVType, limitLV):
@@ -264,7 +273,7 @@
        
    compensationDict = {"GUID":GUID, "CheckState":checkState, "LimitLVType":limitLVType, "LimitLV":limitLV,
                        "Gold":compensation.Gold, "GoldPaper":compensation.GoldPaper, "Silver":compensation.Silver,
                        "PlayerJob":compensation.PlayerJob, "Sender":sender, "Title":title, "Content":content,
                        "PlayerJob":compensation.PlayerJob, "Sender":sender, "Title":title, "Content":content, "OnlyServerID":compensation.ServerID,
                        "CreateTime":compensation.CreateTime, "LimitTime":compensation.LimitTime, "ItemList":itemList}
    return compensationDict
@@ -378,38 +387,33 @@
# 检查邮件是否已达到保存上限,如超过则先删除旧邮件
# @param LimitTime 参数可传空,个人邮件不限制领取期限,只限制保存数量, 
def PyAddPersonalCompensation(GUID, PlayerID, CreateTime, LimitTime, Text, sourceType,
                              gold = 0, goldPaper = 0, silver = 0):
def PyAddPersonalCompensation(GUID, PlayerID, CreateTime, LimitTime, Text, gold = 0, goldPaper = 0, silver = 0, moneySource=ChConfig.Def_GiveMoney_Mail):
    curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(PlayerID)
    cnt = GameWorld.GetCompensationMgr().GetPersonalCompensationCountByType(PlayerID, sourceType)
    totalCount = GameWorld.GetCompensationMgr().GetPersonalCompensationCount(PlayerID)
    #待支持py读表
    tmpDict = {ChConfig.Mail_Type_Default:IpyGameDataPY.GetFuncCfg("MailDefaultCount"),
               ChConfig.Mail_Type_Market:IpyGameDataPY.GetFuncCfg("MailMarketCount")}
    delcnt = cnt - tmpDict[sourceType] + 1
    #GameWorld.DebugLog("PyAddPersonalCompensation typecnt = %s-%s"%(cnt, delcnt))
    if delcnt > 0:
    maxMailCount = IpyGameDataPY.GetFuncCfg("MailDefaultCount")
    delCount = totalCount - maxMailCount + 1
    GameWorld.DebugLog("新增个人邮件: totalCount=%s,maxMailCount=%s" % (totalCount, maxMailCount), PlayerID)
    if delCount > 0:
        GameWorld.Log("个人邮件达到上限,需要删除!delCount=%s" % (delCount), PlayerID)
        #先取得要删除的GUID
        delGUIDs = []
        for i in xrange(delcnt):
            tmpGuid = GameWorld.GetCompensationMgr().AtGUIDInPersonalTypesByType(PlayerID, sourceType, i)
            if not tmpGuid:
                #GameWorld.DebugLog("PyAddPersonalCompensation not GUID = %s"%tmpGuid)
                continue
            delGUIDs.append(tmpGuid)
        for guid in delGUIDs:
        for i in xrange(delCount):
            curIpyPersonalData = GameWorld.GetCompensationMgr().PersonalCompensationAt(PlayerID, i)
            delGUIDs.append(curIpyPersonalData.GUID)
        for guid in delGUIDs:
            ClearPersonalCompensation(PlayerID, guid)
            #GameWorld.DebugLog("PyAddPersonalCompensation DeletePersonalCompensation GUID = %s"%guid)
            GameWorld.Log("    DeletePersonalCompensation GUID = %s" % guid, PlayerID)
            
            if curPlayer:
                NotifyCompensationResult(curPlayer, guid, 1)
            #未补流向
    #GameWorld.DebugLog("PyAddPersonalCompensation CreateTime %s"%CreateTime)
    #此处没有下发通知
    mailType = moneySource - ChConfig.Def_GiveMoney_Unknown # type类型为byte,存值时需要处理下
    GameWorld.GetCompensationMgr().AddPersonalCompensation(GUID, PlayerID, CreateTime,
                                                           LimitTime, Text, sourceType, gold, goldPaper, silver)
                                                           LimitTime, Text, mailType, gold, goldPaper, silver)
    return
@@ -417,8 +421,7 @@
## 添加个人补偿
#  @param addItemDict, PlayerIDList, LimitTime, Text 
#  @return None
def AddPersonalItem(GUID, addItemDictList, PlayerIDList, LimitTime, Text,
                    gold = 0, goldPaper = 0, silver = 0, sourceType = ChConfig.Mail_Type_Default, detail=""):
def AddPersonalItem(GUID, addItemDictList, PlayerIDList, LimitTime, Text, gold = 0, goldPaper = 0, silver = 0, detail="", moneySource=ChConfig.Def_GiveMoney_Mail):
    if GameWorld.IsCrossServer():
        return
    GameWorld.DebugLog("Compensation### AddPersonalItem GUID:%s ItemDict:\n%s "%(GUID, addItemDictList))
@@ -433,8 +436,7 @@
    #批量添加玩家个人补偿领取表
    createTime = GameWorld.GetCurrentDataTimeStr()
    for PlayerID in PlayerIDList:
        PyAddPersonalCompensation(GUID, PlayerID, createTime, LimitTime,
                                  Text, sourceType, gold, goldPaper, silver)
        PyAddPersonalCompensation(GUID, PlayerID, createTime, LimitTime, Text, gold, goldPaper, silver, moneySource)
        # 针对个人补偿,如果是在线玩家,则立即推送给客户端
        curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(PlayerID)
        if curPlayer:
@@ -454,7 +456,7 @@
    
    #添加流向
    addDict = {"LimitTime":LimitTime, "Text":Text, "Gold":gold, "GoldPaper":goldPaper, "Silver":silver, 
               "ItemListLen":len(addItemDictList), "Detail":detail}
               "ItemListLen":len(addItemDictList), "Detail":detail, "MoneySource":moneySource}
    DataRecordPack.DR_AddPersonalCompensation(PlayerIDList, GUID, addItemDictList, addDict)
    return
@@ -615,6 +617,11 @@
                SetPrizeState(curPlayerID, curRequire.GUID, Disable_State, readState)
                continue
            
        if curRequire.ServerID and curRequire.ServerID != GameWorld.GetPlayerServerID(curPlayer):
            # 指定服务器邮件
            SetPrizeState(curPlayerID, curRequire.GUID, Disable_State, readState)
            continue
        #可以用的奖励
        if Enable_State != curState:
            SetPrizeState(curPlayerID, curRequire.GUID, Enable_State, readState)
@@ -680,7 +687,6 @@
        curPlayer.SetDict(Def_RequestState, 0)#解锁
        GameWorld.DebugLog("Compensation### OnMGRequestCompensation no found")
        return
    Text, gold, goldPaper, silver = curEntireRequire.Text, curEntireRequire.Gold, curEntireRequire.GoldPaper, curEntireRequire.Silver
    #校验背包剩余空间是否足够
    #===========================================================================
    # curCUIDItemCount = GameWorld.GetCompensationMgr().FindItemCount(GUID)
@@ -690,7 +696,7 @@
    #    return
    #===========================================================================
    #发送到MapServer给予奖励
    SendGMRequestCompensationResult(routeIndex, mapID, curPlayer, GUID, compensationType, Text, gold, goldPaper, silver)
    SendGMRequestCompensationResult(routeIndex, mapID, curPlayer, GUID, compensationType, curEntireRequire)
    GameWorld.DebugLog("Compensation### OnMGRequestCompensation out")
    
##请求领取物品
@@ -766,17 +772,24 @@
##发送封包 03 02 玩家领取补偿结果#tagGMRequestCompensationResult
#  @param routeIndex, mapID, curPlayer, curItem
#  @return None
def SendGMRequestCompensationResult(routeIndex, mapID, curPlayer, GUID, compensationType, Text,
                                    gold, goldPaper, silver):
def SendGMRequestCompensationResult(routeIndex, mapID, curPlayer, GUID, compensationType, curEntireRequire):
    Text, gold, goldPaper, silver, createTime = curEntireRequire.Text, curEntireRequire.Gold, \
        curEntireRequire.GoldPaper, curEntireRequire.Silver, curEntireRequire.CreateTime
    # 全服邮件没有 Type 字段
    moneySource = curEntireRequire.Type if compensationType == Personal_CompensationType else 0
    sendPack = ChGameToMapPyPack.tagGMRequestCompensationResult() 
    sendPack.PlayerID = curPlayer.GetID()
    sendPack.CompensationType = compensationType
    sendPack.GUID = GUID
    sendPack.CreateTime = createTime
    sendPack.Text = Text
    sendPack.TextLen = len(Text)
    sendPack.Gold = gold
    sendPack.GoldPaper = goldPaper
    sendPack.Silver = silver
    sendPack.MoneySource = moneySource
    curGUIDItemCount = GameWorld.GetCompensationMgr().FindItemCount(GUID)
    
    for i in xrange(curGUIDItemCount):
@@ -857,11 +870,35 @@
    return
##清理超时30天的个人邮件, 否则流失玩家在不断合服情况下数据会累积
# 个人邮件暂无过期时间设定,只有30天清理逻辑,以创建时间为准
#  @param None
#  @return None
def ClearUpPersonalCompensation():
    #校验过期补偿
    curTime = datetime.datetime.today()
    needClearGUIDList = []
    allCnt = GameWorld.GetCompensationMgr().GetAllPersonalCompensationCount()
    for i in xrange(allCnt):
        curMail = GameWorld.GetCompensationMgr().AtAllPersonalCompensation(i)
        # 超过接收邮件30天则完全删除此邮件
        limitTime = datetime.datetime.strptime(curMail.CreateTime, ChConfig.TYPE_Time_Format) + datetime.timedelta(days = 30)
        if limitTime < curTime:
            needClearGUIDList.append([curMail.PlayerID, curMail.GUID])
    GameWorld.Log("ClearUpPersonalCompensation count=%s"%len(needClearGUIDList))
    #删除过期补偿信息, 没有主动通知在线玩家
    for playerID, GUID in needClearGUIDList:
        ClearPersonalCompensation(playerID, GUID)
    return
## 清理超时补偿, 个人邮件在超过上限后才会自动删除
#  @param None
#  @return None
def ClearUpTimeOutCompensation():
    
    ClearUpPersonalCompensation()
    ClearUpEntireCompensation()
    return
@@ -917,6 +954,11 @@
    #在个人补偿中
    curPersonalCompensation = GameWorld.GetCompensationMgr().FindPersonalCompensation(curPlayerID, GUID)
    if curPersonalCompensation.PlayerID == curPlayerID:
        if not CheckCanDelCompensation(curPersonalCompensation, GUID):
            #有附件不可删除
            NotifyCompensationResult(curPlayer, GUID, 0)
            return
        ClearPersonalCompensation(curPlayerID, GUID)
        NotifyCompensationResult(curPlayer, GUID, 1)
        #GameWorld.DebugLog("个人补偿中OnDelCompensation:%s"%GUID)
@@ -932,12 +974,28 @@
    #全服邮件
    curEntireRequire = GameWorld.GetCompensationMgr().FindEntireCompensation(GUID)
    if curEntireRequire.GUID == GUID:
        if not CheckCanDelCompensation(curEntireRequire, GUID):
            #有附件不可删除
            NotifyCompensationResult(curPlayer, GUID, 0)
            return
        SetPrizeState(curPlayerID, GUID, Disable_State, GameWorld.GetCompensationMgr().FindPlayerRecState(curPlayerID, GUID)/10)
        NotifyCompensationResult(curPlayer, GUID, 1)
        #GameWorld.DebugLog("全服邮件OnDelCompensation:%s"%GUID)
        return
    NotifyCompensationResult(curPlayer, GUID, 0)
# 有附件的情况玩家不可主动删除邮件,避免误操作;系统可删除不用调用此接口
def CheckCanDelCompensation(mailObj, GUID):
    if mailObj.Gold or mailObj.GoldPaper or mailObj.Silver:
        # 有附加货币不可删除
        return False
    if GameWorld.GetCompensationMgr().FindItemCount(GUID):
        # 有附件物品不可删除
        return False
    return True
        
# 邮件删除情况   
def NotifyCompensationResult(curPlayer, GUID, result):