|  |  | 
 |  |  | import math
 | 
 |  |  | import json
 | 
 |  |  | #领取状态  个位数标识 (可领取即已通知过玩家该封邮件,需要在邮件发生时和上线时设置状态
 | 
 |  |  | #0 未通知,1 不可领取, 2 可领取, 3 已领取
 | 
 |  |  | #0 未通知,1 不可领取, 2 可领取, 3 已领取,4 已删除
 | 
 |  |  | (
 | 
 |  |  | Unknown_State,
 | 
 |  |  | Disable_State,
 | 
 |  |  | Enable_State,
 | 
 |  |  | Yet_State
 | 
 |  |  | ) = range(4)
 | 
 |  |  | Yet_State,
 | 
 |  |  | Del_State
 | 
 |  |  | ) = range(5)
 | 
 |  |  | 
 | 
 |  |  | CheckState_OK = 0 # 已审核
 | 
 |  |  | CheckState_No = 1 # 未审核
 | 
 |  |  | 
 |  |  | #  @return GUID
 | 
 |  |  | #  @remarks addItemList支持append字典
 | 
 |  |  | def SendPersonalItemMail(title, content, limitTime, playerIDList, addItemList, gold = 0, goldPaper = 0, silver = 0, 
 | 
 |  |  |                          detail="", moneySource=ChConfig.Def_GiveMoney_Mail, crossMail=False):
 | 
 |  |  |                          detail="", moneySource=ChConfig.Def_GiveMoney_Mail, crossMail=False, mailType=0):
 | 
 |  |  |     if not playerIDList:
 | 
 |  |  |         return ""
 | 
 |  |  |     
 | 
 |  |  | 
 |  |  |         startIndex = i*perMailItemCnt
 | 
 |  |  |         GUID = str(uuid.uuid1())
 | 
 |  |  |         AddPersonalItem(GUID, addItemDictList[startIndex:startIndex + perMailItemCnt], playerIDList, 
 | 
 |  |  |                                            limitTime, "%s<$_$>%s<$_$>%s" % (ChConfig.Def_Mail_SenderSys, title, content),
 | 
 |  |  |                                            limitTime, GetMailText(title, content, mailType),
 | 
 |  |  |                                            gold, goldPaper, silver, detail, moneySource, crossMail)
 | 
 |  |  |     return GUID
 | 
 |  |  | 
 | 
 |  |  | ## 发送纯文字个人补偿
 | 
 |  |  | #  @param limitTime 可以传空
 | 
 |  |  | #  @return None
 | 
 |  |  | def SendPersonalAsTextMail(PlayerID, title, content, limitTime):
 | 
 |  |  | def SendPersonalAsTextMail(PlayerID, title, content, limitTime, mailType=0):
 | 
 |  |  |     if GameWorld.IsCrossServer():
 | 
 |  |  |         return
 | 
 |  |  |     GUID = str(uuid.uuid1())
 | 
 |  |  |     PyAddPersonalCompensation(GUID, PlayerID, GameWorld.GetCurrentDataTimeStr(), limitTime, 
 | 
 |  |  |                               "%s<$_$>%s<$_$>%s" % (ChConfig.Def_Mail_SenderSys,title, content))
 | 
 |  |  |                               GetMailText(title, content, mailType))
 | 
 |  |  |     return
 | 
 |  |  | 
 | 
 |  |  | def GetMailText(title, content, mailType=0, sender=ChConfig.Def_Mail_SenderSys):
 | 
 |  |  |     ## 获取邮件字段 Text 内容
 | 
 |  |  |     return "%s<$_$>%s<$_$>%s<$_$>%s" % (sender, title, content, mailType)
 | 
 |  |  | 
 | 
 |  |  | def GetEntireCompensationInfo(checkState, limitLVType, limitLV):
 | 
 |  |  |     return checkState * 1000000 + limitLVType * 100000 + limitLV
 | 
 |  |  | 
 |  |  |         compensation = compensationMgr.PersonalCompensationAt(playerID, i)
 | 
 |  |  |         
 | 
 |  |  |         contentList = compensation.Text.split("<$_$>")
 | 
 |  |  |         if len(contentList) != 3:
 | 
 |  |  |         if len(contentList) < 3:
 | 
 |  |  |             continue
 | 
 |  |  |         sender, title, content = contentList
 | 
 |  |  |         sender, title, content = contentList[:3]
 | 
 |  |  |         mailType = GameWorld.ToIntDef(contentList[3]) if len(contentList) > 3 else 0
 | 
 |  |  |         
 | 
 |  |  |         if tempSign in content and tempSignEnd in content:
 | 
 |  |  |             title = content[content.index(tempSign) + len(tempSign):content.index(tempSignEnd)]
 | 
 |  |  | 
 |  |  |         recState = compensationMgr.FindPlayerRecState(playerID, GUID)
 | 
 |  |  |         
 | 
 |  |  |         infoDict = {"GUID":GUID, "Gold":compensation.Gold, "GoldPaper":compensation.GoldPaper, "Silver":compensation.Silver,
 | 
 |  |  |                     "Sender":sender, "Title":title, "Content":content, "RecState":recState,
 | 
 |  |  |                     "Sender":sender, "Title":title, "Content":content, "RecState":recState, "MailType":mailType,
 | 
 |  |  |                     "CreateTime":compensation.CreateTime, "LimitTime":compensation.LimitTime, "ItemList":itemList}
 | 
 |  |  |         
 | 
 |  |  |         retList.append(infoDict)
 | 
 |  |  | 
 |  |  |         return
 | 
 |  |  |     
 | 
 |  |  |     contentList = compensation.Text.split("<$_$>")
 | 
 |  |  |     if len(contentList) != 3:
 | 
 |  |  |     if len(contentList) < 3:
 | 
 |  |  |         return
 | 
 |  |  |     sender, title, content = contentList
 | 
 |  |  |     sender, title, content = contentList[:3]
 | 
 |  |  |     mailType = GameWorld.ToIntDef(contentList[3]) if len(contentList) > 3 else 0
 | 
 |  |  |     
 | 
 |  |  |     if searchTitle and searchTitle not in title:
 | 
 |  |  |         return
 | 
 |  |  | 
 |  |  |             continue
 | 
 |  |  |         itemList.append([itemID, curItem.Count, curItem.IsBind, curItem.UserData])
 | 
 |  |  |         
 | 
 |  |  |     compensationDict = {"GUID":GUID, "CheckState":checkState, "LimitLVType":limitLVType, "LimitLV":limitLV,
 | 
 |  |  |     compensationDict = {"GUID":GUID, "CheckState":checkState, "LimitLVType":limitLVType, "LimitLV":limitLV, "MailType":mailType,
 | 
 |  |  |                         "Gold":compensation.Gold, "GoldPaper":compensation.GoldPaper, "Silver":compensation.Silver,
 | 
 |  |  |                         "PlayerJob":compensation.PlayerJob, "Sender":sender, "Title":title, "Content":content, "OnlyServerID":compensation.ServerID,
 | 
 |  |  |                         "CreateTime":compensation.CreateTime, "LimitTime":compensation.LimitTime, "ItemList":itemList}
 | 
 |  |  | 
 |  |  |     return successGUIDList
 | 
 |  |  | 
 | 
 |  |  | def SendEntireMail(mailTypeKey, getDays, limitLV, limitLVType, addItemList=[], paramList=[], \
 | 
 |  |  |                    gold=0, goldPaper=0, silver=0, detail="", moneySource=ChConfig.Def_GiveMoney_Mail, GUID=""):
 | 
 |  |  |                    gold=0, goldPaper=0, silver=0, detail="", moneySource=ChConfig.Def_GiveMoney_Mail, GUID="", mailType=0):
 | 
 |  |  |     ''' 发送全服邮件
 | 
 |  |  |     @param mailTypeKey: 邮件模板key
 | 
 |  |  |     @param getDays: 有效天数
 | 
 |  |  | 
 |  |  |     PlayerJob = 127 # 默认全职业可领
 | 
 |  |  |     serverID = 0 # 默认所有服务器ID
 | 
 |  |  |     
 | 
 |  |  |     AddEntireItem(GUID, addItemDictList, limitTime, mailInfo, PlayerJob, "%s<$_$>%s<$_$>%s" % (sender, title, content),  | 
 |  |  |     AddEntireItem(GUID, addItemDictList, limitTime, mailInfo, PlayerJob, GetMailText(title, content, mailType, sender),  | 
 |  |  |                   gold, goldPaper, silver, detail, serverID)
 | 
 |  |  |     return
 | 
 |  |  | 
 | 
 |  |  | 
 |  |  | def SetPrizeState(curPlayerID, GUID, prizeState, readState):
 | 
 |  |  |     state = readState*10 + prizeState
 | 
 |  |  |     GameWorld.GetCompensationMgr().AddPlayerRec(curPlayerID, GUID, state)
 | 
 |  |  |     return
 | 
 |  |  | 
 | 
 |  |  | def GetPrizeGetState(curPlayerID, GUID):
 | 
 |  |  |     ## 获取领取状态
 | 
 |  |  |     return GameWorld.GetCompensationMgr().FindPlayerRecState(curPlayerID, GUID) % 10
 | 
 |  |  | 
 | 
 |  |  | ##查找玩家可领取的补偿列表
 | 
 |  |  | #  @param curPlayer 
 | 
 |  |  | 
 |  |  |         states = GameWorld.GetCompensationMgr().FindPlayerRecState(curPlayerID, curRequire.GUID)
 | 
 |  |  |         readState = states/10    # 可读       
 | 
 |  |  |         curState = states%10    # 领取状态
 | 
 |  |  |         if curState in (Disable_State, Yet_State):
 | 
 |  |  |         if curState in (Disable_State, Del_State):
 | 
 |  |  |             #不可领 或 已领
 | 
 |  |  |              | 
 |  |  |             #GameWorld.DebugLog("该玩家当前全服邮件状态不下发: curState=%s,GUID=%s" % (curState, curRequire.GUID), curPlayerID)
 | 
 |  |  |             continue
 | 
 |  |  |         
 | 
 |  |  |         limitTime = datetime.datetime.strptime(curRequire.LimitTime, ChConfig.TYPE_Time_Format)
 | 
 |  |  | 
 |  |  |             SetPrizeState(curPlayerID, curRequire.GUID, Disable_State, readState)
 | 
 |  |  |             continue
 | 
 |  |  |         
 | 
 |  |  |         if limitLVType == LimitLVType_Not and curPlayer.GetCreateRoleTime() > curRequire.CreateTime:
 | 
 |  |  |             #GameWorld.DebugLog("升级后不可领取的邮件发送时间后创角的玩家默认不可领取! CreateRoleTime=%s > %s" % (curPlayer.GetCreateRoleTime(), curRequire.CreateTime))
 | 
 |  |  |             SetPrizeState(curPlayerID, curRequire.GUID, Disable_State, readState)
 | 
 |  |  |             continue
 | 
 |  |  | 
 | 
 |  |  |         if limitLV > curLV:
 | 
 |  |  |             #等级不足
 | 
 |  |  |             if limitLVType == LimitLVType_Not:
 | 
 |  |  | 
 |  |  |             continue
 | 
 |  |  |         
 | 
 |  |  |         #可以用的奖励
 | 
 |  |  |         if Enable_State != curState:
 | 
 |  |  |         if Enable_State != curState and curState != Yet_State:
 | 
 |  |  |             SetPrizeState(curPlayerID, curRequire.GUID, Enable_State, readState)
 | 
 |  |  |         allList.append((curRequire.GUID, curRequire.Text, curRequire.CreateTime,
 | 
 |  |  |                         curRequire.Gold, curRequire.GoldPaper, curRequire.Silver))
 | 
 |  |  | 
 |  |  |         subPack.Gold = gold
 | 
 |  |  |         subPack.GoldPaper = goldPaper
 | 
 |  |  |         subPack.Silver = silver 
 | 
 |  |  |         subPack.IsRead = GameWorld.GetCompensationMgr().FindPlayerRecState(curPlayer.GetPlayerID(), GUID)/10
 | 
 |  |  |         resState = GameWorld.GetCompensationMgr().FindPlayerRecState(curPlayer.GetPlayerID(), GUID)
 | 
 |  |  |         if resState % 10 == Yet_State:
 | 
 |  |  |             subPack.IsRead = Yet_State # 已领取
 | 
 |  |  |         else:
 | 
 |  |  |             subPack.IsRead = resState / 10 # 是否已读
 | 
 |  |  |         for index in xrange(curGUIDItemCount):
 | 
 |  |  |             curItem = GameWorld.GetCompensationMgr().FindItemAt(GUID, index)
 | 
 |  |  |             subPackItem = ChPyNetSendPack.tagGCCompensationItem()
 | 
 |  |  | 
 |  |  |         sendPack.PackList.append(subPack)
 | 
 |  |  |     sendPack.Count = len(sendPack.PackList)
 | 
 |  |  |     NetPackCommon.SendFakePack(curPlayer, sendPack)
 | 
 |  |  |     return
 | 
 |  |  | 
 | 
 |  |  | def SyncQueryCompensationResultByGUID(curPlayer, notifyGUIDList):
 | 
 |  |  |     curPlayerID = curPlayer.GetPlayerID()
 | 
 |  |  |     notifyList = []
 | 
 |  |  |     compensationMgr = GameWorld.GetCompensationMgr()
 | 
 |  |  |     for GUID in notifyGUIDList:
 | 
 |  |  |         findCompensation = compensationMgr.FindPersonalCompensation(curPlayerID, GUID)
 | 
 |  |  |         if findCompensation.PlayerID != curPlayerID:
 | 
 |  |  |             findCompensation = compensationMgr.FindEntireCompensation(GUID)
 | 
 |  |  |             if findCompensation.GUID != GUID:
 | 
 |  |  |                 # 找不到邮件
 | 
 |  |  |                 continue
 | 
 |  |  |         notifyList.append((findCompensation.GUID, findCompensation.Text, findCompensation.CreateTime,  | 
 |  |  |                            findCompensation.Gold, findCompensation.GoldPaper, findCompensation.Silver))
 | 
 |  |  |     if not notifyList:
 | 
 |  |  |         return
 | 
 |  |  |     SyncQueryCompensationResult(curPlayer, notifyList)
 | 
 |  |  |     return
 | 
 |  |  | 
 | 
 |  |  | ##03 03 玩家请求领取补偿#tagMGRequestCompensation
 | 
 |  |  | 
 |  |  |     GameWorld.DebugLog("Compensation### OnMGRequestCompensation myPlayerID %s GUID %s"%(myPlayerID, GUID))
 | 
 |  |  |     
 | 
 |  |  |     compensationType, curEntireRequire = CheckRequestCompensation(curPlayer, GUID) 
 | 
 |  |  |     if compensationType == Unknow_CompensationType:
 | 
 |  |  |     if compensationType == Unknow_CompensationType or not curEntireRequire:
 | 
 |  |  |         #领取失败
 | 
 |  |  |         curPlayer.SetDict(Def_RequestState, 0)#解锁
 | 
 |  |  |         GameWorld.DebugLog("Compensation### OnMGRequestCompensation no found")
 | 
 |  |  | 
 |  |  | def CheckRequestCompensation(curPlayer, GUID, isPersonnal = True):
 | 
 |  |  |     curPlayerID = curPlayer.GetID()
 | 
 |  |  |     
 | 
 |  |  |     states = GameWorld.GetCompensationMgr().FindPlayerRecState(curPlayerID, GUID)
 | 
 |  |  |     readState = states/10    # 可读        | 
 |  |  |     curState = states%10    # 领取状态
 | 
 |  |  |      | 
 |  |  |     if curState in (Disable_State, Yet_State, Del_State):
 | 
 |  |  |         #不可领 或 已领
 | 
 |  |  |         #GameWorld.DebugLog("当前邮件不可领取或已领: states=%s,curState=%s,GUID=%s" % (states, curState, GUID), curPlayerID)
 | 
 |  |  |         return Unknow_CompensationType, None
 | 
 |  |  |      | 
 |  |  |     if isPersonnal:
 | 
 |  |  |         #在个人补偿中
 | 
 |  |  |         curPersonalCompensation = GameWorld.GetCompensationMgr().FindPersonalCompensation(curPlayerID, GUID)
 | 
 |  |  | 
 |  |  |         
 | 
 |  |  |     #---------
 | 
 |  |  |     #在全服补偿中
 | 
 |  |  |     states = GameWorld.GetCompensationMgr().FindPlayerRecState(curPlayerID, GUID)
 | 
 |  |  |     readState = states/10    # 可读        | 
 |  |  |     curState = states%10    # 领取状态
 | 
 |  |  |      | 
 |  |  |     if curState in (Disable_State, Yet_State):
 | 
 |  |  |         #不可领 或 已领
 | 
 |  |  |         return Unknow_CompensationType, None
 | 
 |  |  |     curEntireRequire = GameWorld.GetCompensationMgr().FindEntireCompensation(GUID)
 | 
 |  |  |     if curEntireRequire.GUID != GUID:
 | 
 |  |  |         #不再全服补偿中,删除记录
 | 
 |  |  | 
 |  |  | ##玩家领取补偿物品发放成功
 | 
 |  |  | #  @param curPlayer, GUID
 | 
 |  |  | #  @return None
 | 
 |  |  | def GiveCompensationSuccess(curPlayer, GUID, CompensationType):
 | 
 |  |  | def GiveCompensationSuccess(curPlayer, GUID, CompensationType, isDel=False):
 | 
 |  |  |     curPlayerID = curPlayer.GetID()
 | 
 |  |  |     NotifyCompensationResult(curPlayer, GUID, 1)
 | 
 |  |  |      | 
 |  |  |     SetPrizeState(curPlayerID, GUID, Yet_State, Read_State_Yes) # 设置为已领取
 | 
 |  |  |     #流向记录
 | 
 |  |  |     DataRecordPack.DR_GiveCompensationSuccess(curPlayerID, GUID)
 | 
 |  |  |     if not isDel:
 | 
 |  |  |         SyncQueryCompensationResultByGUID(curPlayer, [GUID])
 | 
 |  |  |         return
 | 
 |  |  |      | 
 |  |  |     NotifyCompensationResult(curPlayer, GUID, 1)
 | 
 |  |  |      | 
 |  |  |     #全服奖励领取记录变更为已领取
 | 
 |  |  |     if CompensationType == Entire_CompensationType:
 | 
 |  |  |         GameWorld.GetCompensationMgr().AddPlayerRec(curPlayerID, GUID, 10 + Yet_State)
 | 
 |  |  |         SetPrizeState(curPlayerID, GUID, Del_State, Read_State_Yes)
 | 
 |  |  |         return
 | 
 |  |  |     #个人奖励领取条目执行删除
 | 
 |  |  |     if CompensationType == Personal_CompensationType:
 | 
 |  |  | 
 |  |  |         
 | 
 |  |  |         mailText = curMail.Text
 | 
 |  |  |         # 通知类模板邮件,过天可直接删除
 | 
 |  |  |         if tempSign in mailText and tempSignEnd in mailText and CheckCanDelCompensation(curMail, curMail.GUID):
 | 
 |  |  |         if tempSign in mailText and tempSignEnd in mailText and CheckCanDelCompensation(curMail, curMail.GUID, curMail.PlayerID):
 | 
 |  |  |             tempKey = mailText[mailText.index(tempSign) + len(tempSign):mailText.index(tempSignEnd)]
 | 
 |  |  |             notClearMailKeyList = IpyGameDataPY.GetFuncEvalCfg("MailSet", 1)
 | 
 |  |  |             if tempKey not in notClearMailKeyList:
 | 
 |  |  | 
 |  |  |     #在个人补偿中
 | 
 |  |  |     curPersonalCompensation = GameWorld.GetCompensationMgr().FindPersonalCompensation(curPlayerID, GUID)
 | 
 |  |  |     if curPersonalCompensation.PlayerID == curPlayerID:
 | 
 |  |  |         if not CheckCanDelCompensation(curPersonalCompensation, GUID):
 | 
 |  |  |         if not CheckCanDelCompensation(curPersonalCompensation, GUID, curPlayerID):
 | 
 |  |  |             #有附件不可删除
 | 
 |  |  |             GameWorld.DebugLog("该个人邮件不可删除: %s" % GUID, curPlayerID)
 | 
 |  |  |             NotifyCompensationResult(curPlayer, GUID, 0)
 | 
 |  |  |             return
 | 
 |  |  |         
 | 
 |  |  | 
 |  |  |     #全服邮件
 | 
 |  |  |     curEntireRequire = GameWorld.GetCompensationMgr().FindEntireCompensation(GUID)
 | 
 |  |  |     if curEntireRequire.GUID == GUID:
 | 
 |  |  |         if not CheckCanDelCompensation(curEntireRequire, GUID):
 | 
 |  |  |         if not CheckCanDelCompensation(curEntireRequire, GUID, curPlayerID):
 | 
 |  |  |             #有附件不可删除
 | 
 |  |  |             GameWorld.DebugLog("该全服邮件不可删除: %s" % GUID, curPlayerID)
 | 
 |  |  |             NotifyCompensationResult(curPlayer, GUID, 0)
 | 
 |  |  |             return
 | 
 |  |  |         
 | 
 |  |  |         SetPrizeState(curPlayerID, GUID, Disable_State, GameWorld.GetCompensationMgr().FindPlayerRecState(curPlayerID, GUID)/10)
 | 
 |  |  |         SetPrizeState(curPlayerID, GUID, Del_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):
 | 
 |  |  | def CheckCanDelCompensation(mailObj, GUID, playerID=0):
 | 
 |  |  |     if playerID:
 | 
 |  |  |         if GetPrizeGetState(playerID, GUID) == Yet_State:
 | 
 |  |  |             #GameWorld.DebugLog("已领取的邮件可删除: %s" % GUID, playerID)
 | 
 |  |  |             return True
 | 
 |  |  |          | 
 |  |  |     if mailObj.Gold or mailObj.GoldPaper or mailObj.Silver:
 | 
 |  |  |         # 有附加货币不可删除
 | 
 |  |  |         return False
 |