hxp
2019-03-11 4c25e5894f824dfd4c0fcbb443ebc51bb7b8a47b
ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerCompensation.py
@@ -22,7 +22,7 @@
#------------------------------------------------------------------------------ 
import GameWorld
import ChConfig
#import ShareDefine
import ShareDefine
import IPY_GameServer
import ChGameToMapPyPack
import NetPackCommon
@@ -84,16 +84,15 @@
## 功能发放物品补偿/奖励邮件
#  @param addItemList [(itemID, itemCnt, isBind), {或物品信息字典}, ...]
#  @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,24 +115,27 @@
        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=""):
    GameWorld.DebugLog("SendMailByKey %s, playerIDList=%s, addItemList=%s, paramList=%s, gold=%s, goldPaper=%s, silver=%s"
                       % (mailTypeKey, playerIDList, addItemList, paramList, gold, goldPaper, silver))
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, 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)
#  此处货币playerIDList发放统一,如根据玩家不同而变,则应需修改
## 功能发放物品补偿/奖励邮件
#  @param addItemList [(itemID, itemCnt, isBind), {或物品信息字典}, ...]
#  @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 ""
    
@@ -171,19 +173,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):
    if GameWorld.IsMergeServer():
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):
@@ -328,11 +329,11 @@
#  @param addItemDictList, LimitTime, mailInfo, PlayerJob,  Text 
#  @return None
def AddEntireItem(GUID, addItemDictList, LimitTime, mailInfo, PlayerJob, Text,
                  gold = 0, goldPaper = 0, silver = 0, detail=""):
                  gold = 0, goldPaper = 0, silver = 0, detail="", serverID=0):
    '''
    @param mailInfo: GetEntireCompensationInfo 的返回值, 目前暂存字段 PlayerLV 中
    '''
    if GameWorld.IsMergeServer():
    if GameWorld.IsCrossServer():
        return
    #GameWorld.DebugLog("Compensation### AddEntireItem GUID:%s ItemDict:\n%s "%(GUID, addItemDictList))
    
@@ -342,9 +343,10 @@
        GameWorld.GetCompensationMgr().AddCompensationItem(GUID, curItemData)
        
    createTime = GameWorld.GetCurrentDataTimeStr()
    #添加全服领取补偿条件
    GameWorld.GetCompensationMgr().AddEntireCompensationItem(GUID, createTime, LimitTime, mailInfo, 
                                                             PlayerJob, Text, gold, goldPaper, silver)
                                                             PlayerJob, Text, gold, goldPaper, silver, serverID)
    checkState, limitLVType, limitLV = ParseEntireCompensationInfo(mailInfo)
    addDict = {"LimitTime":LimitTime, "LimitLV":limitLV, "LimitLVType":limitLVType, "CheckState":checkState, "PlayerJob":PlayerJob, "Text":Text, 
               "Gold":gold, "GoldPaper":goldPaper, "Silver":silver, "ItemList":addItemDictList, "Detail":detail}
@@ -375,38 +377,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
@@ -414,9 +411,8 @@
## 添加个人补偿
#  @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=""):
    if GameWorld.IsMergeServer():
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))
    
@@ -430,8 +426,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:
@@ -451,7 +446,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
@@ -677,7 +672,7 @@
        curPlayer.SetDict(Def_RequestState, 0)#解锁
        GameWorld.DebugLog("Compensation### OnMGRequestCompensation no found")
        return
    Text, gold, goldPaper, silver = curEntireRequire.Text, curEntireRequire.Gold, curEntireRequire.GoldPaper, curEntireRequire.Silver
    Text, gold, goldPaper, silver, moneySource = curEntireRequire.Text, curEntireRequire.Gold, curEntireRequire.GoldPaper, curEntireRequire.Silver, curEntireRequire.Type
    #校验背包剩余空间是否足够
    #===========================================================================
    # curCUIDItemCount = GameWorld.GetCompensationMgr().FindItemCount(GUID)
@@ -687,7 +682,7 @@
    #    return
    #===========================================================================
    #发送到MapServer给予奖励
    SendGMRequestCompensationResult(routeIndex, mapID, curPlayer, GUID, compensationType, Text, gold, goldPaper, silver)
    SendGMRequestCompensationResult(routeIndex, mapID, curPlayer, GUID, compensationType, Text, gold, goldPaper, silver, moneySource)
    GameWorld.DebugLog("Compensation### OnMGRequestCompensation out")
    
##请求领取物品
@@ -749,7 +744,12 @@
        if (curEntireRequire.PlayerJob&pow(2,curJob)) == 0:
            SetPrizeState(curPlayerID, GUID, Disable_State, readState)
            return Unknow_CompensationType, None
    if curEntireRequire.ServerID and curEntireRequire.ServerID != GameWorld.GetPlayerServerID(curPlayer):
        # 指定服务器邮件
        SetPrizeState(curPlayerID, GUID, Disable_State, readState)
        return Unknow_CompensationType, None
    #可以用的奖励
    SetPrizeState(curPlayerID, GUID, Enable_State, readState)
    #返回物品信息   
@@ -759,7 +759,7 @@
#  @param routeIndex, mapID, curPlayer, curItem
#  @return None
def SendGMRequestCompensationResult(routeIndex, mapID, curPlayer, GUID, compensationType, Text,
                                    gold, goldPaper, silver):
                                    gold, goldPaper, silver, moneySource):
    sendPack = ChGameToMapPyPack.tagGMRequestCompensationResult() 
    sendPack.PlayerID = curPlayer.GetID()
    sendPack.CompensationType = compensationType
@@ -769,6 +769,7 @@
    sendPack.Gold = gold
    sendPack.GoldPaper = goldPaper
    sendPack.Silver = silver
    sendPack.MoneySource = moneySource
    curGUIDItemCount = GameWorld.GetCompensationMgr().FindItemCount(GUID)
    
    for i in xrange(curGUIDItemCount):