From 6264dea0e06199a7e786be0ddddf324dd6b6dcb6 Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期一, 13 十月 2025 11:23:14 +0800
Subject: [PATCH] 16 卡牌服务端(邮件过期删除优化;邮件支持发送定制属性装备;Mail命令优化支持发送指定天数、物品、定制属性物品邮件;)

---
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyMongoDB/GMToolLogicProcess/Commands/GMT_AddPersonalCompensation.py |   18 ++++++++-
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/CommFunc.py                                                          |    4 ++
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerMail.py                                                 |   33 ++++++++++------
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GM/Commands/Mail.py                                                  |   43 +++++++++++++++++++++
 4 files changed, 82 insertions(+), 16 deletions(-)

diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/CommFunc.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/CommFunc.py
index 7f0f50b..c1db2ce 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/CommFunc.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/CommFunc.py
@@ -31,6 +31,7 @@
 import traceback
 import shutil
 import zlib
+import json
 #---------------------------------------------------------------------
 #全局变量
 
@@ -436,6 +437,9 @@
     except ZeroDivisionError:
         return "Division is Zero"
 
+def JsonDump(dumpObj):
+    return json.dumps(dumpObj, ensure_ascii=False)
+
 ##生成指定文件(如par:r'E:\开发版本\Data\logo\formName1.log')
 #def MakeAppointFile(par):
 #    dir = os.path.dirname(par)  # 获得文件目录
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GM/Commands/Mail.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GM/Commands/Mail.py
index 521242a..e4848fb 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GM/Commands/Mail.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GM/Commands/Mail.py
@@ -19,7 +19,10 @@
 import PlayerMail
 import ShareDefine
 import DataRecordPack
+import IpyGameDataPY
 import DBDataMgr
+import ItemCommon
+import CommFunc
 import random
 
 ## 执行逻辑
@@ -33,6 +36,8 @@
         GameWorld.DebugAnswer(curPlayer, "发送邮件: Mail 几封 物品数 [模板key 参数1 ...]")
         GameWorld.DebugAnswer(curPlayer, "输出邮件: Mail p")
         GameWorld.DebugAnswer(curPlayer, "发送全服: Mail s 物品数 [天数]")
+        GameWorld.DebugAnswer(curPlayer, "发送邮件: Mail pw 天数 物品ID 个数 [ID 个数 ...]")
+        GameWorld.DebugAnswer(curPlayer, "个数:如果是装备则个数默认1个,个数参数改为定制属性ID")
         return
     
     value = gmList[0]
@@ -49,10 +54,46 @@
         SendServerMail(curPlayer, gmList)
         return
     
+    if value == "pw":
+        SendPlayerMailItem(curPlayer, gmList)
+        return
+    
     if value > 0:
         SendPlayerMail(curPlayer, gmList)
         return
     
+    return
+
+def SendPlayerMailItem(curPlayer, gmList):
+    playerID = curPlayer.GetPlayerID()
+    limitDays = gmList[1] if len(gmList) > 1 else 1
+    itemList = gmList[2:]
+    
+    mailItemList = []
+    while len(itemList) >= 2:
+        itemID = itemList.pop(0)
+        itemCount = itemList.pop(0)
+        
+        itemData = GameWorld.GetGameData().GetItemByTypeID(itemID)
+        if not itemData:
+            GameWorld.DebugAnswer(curPlayer, "物品ID不存在! %s" % itemID)
+            continue
+        
+        if ItemCommon.GetIsEquip(itemData):
+            appointID = itemCount
+            ipyData = IpyGameDataPY.GetIpyGameData("AppointItem", appointID)
+            if not ipyData:
+                GameWorld.DebugAnswer(curPlayer, "定制属性ID不存在! %s" % appointID)
+                continue
+            userData = CommFunc.JsonDump({ShareDefine.Def_CItemKey_AppointID:appointID})
+            itemInfo = [itemID, 1, 0, userData] # 装备默认1个
+        else:
+            itemInfo = [itemID, itemCount]
+                
+        mailItemList.append(itemInfo)
+        
+    PlayerMail.SendMailByKey("", playerID, mailItemList, limitDays=limitDays)
+    GameWorld.DebugAnswer(curPlayer, "发送个人邮件物品OK")
     return
 
 def SendPlayerMail(curPlayer, gmList):
@@ -66,7 +107,7 @@
     mailCntBef = mailMgr.GetPersonalMailCount(playerID)
     for _ in range(sendCnt):
         itemList = __randMailItem(mailItemCnt)
-        PlayerMail.SendMailByKey(mailTypeKey, playerID, itemList, paramList)
+        PlayerMail.SendMailByKey(mailTypeKey, playerID, itemList, paramList, limitDays=random.randint(1, 7))
         
     mailCntAft = mailMgr.GetPersonalMailCount(playerID)
     GameWorld.DebugAnswer(curPlayer, "发送个人邮件OK:%s, %s~%s" % (sendCnt, mailCntBef, mailCntAft))
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerMail.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerMail.py
index c0eddf8..e9a083a 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerMail.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerMail.py
@@ -51,9 +51,10 @@
         if not mailObj:
             continue
         createTime = GameWorld.ChangeTimeStrToNum(mailObj.GetCreateTime())
-        limitTime = createTime + (mailObj.GetLimitDays() + 7) * 3600 * 24
-        if curTime < limitTime:
-            #GameWorld.DebugLog("全服邮件未超时,不删除! %s,createTime=%s,limitTime=%s" % (guid, mailObj.GetCreateTime(), GameWorld.ChangeTimeNumToStr(limitTime)))
+        passDays = GameWorld.GetDiff_Day(curTime, createTime) + 1 # 过期判断按0点算天数
+        limitDays = mailObj.GetLimitDays()
+        if passDays <= limitDays:
+            #GameWorld.DebugLog("全服邮件未超时,不删除! %s,createTime=%s,passDays=%s <= limitDays=%s" % (guid, mailObj.GetCreateTime(), passDays, limitDays))
             continue
         
         DelServerMail(guid, "Timeout")
@@ -85,16 +86,17 @@
         notifyGUIDState = {}
         for guid, mailObj in mailDict.items():
             createTime = GameWorld.ChangeTimeStrToNum(mailObj.GetCreateTime())
-            limitTime = createTime + (mailObj.GetLimitDays() + 0) * 3600 * 24
-            if curTime < limitTime:
-                #GameWorld.DebugLog("个人邮件未超时,不删除! %s,createTime=%s,limitTime=%s" % (guid, mailObj.GetCreateTime(), GameWorld.ChangeTimeNumToStr(limitTime)), playerID)
+            passDays = GameWorld.GetDiff_Day(curTime, createTime) + 1 # 过期判断按0点算天数
+            limitDays = mailObj.GetLimitDays()
+            if passDays <= limitDays:
+                #GameWorld.DebugLog("个人邮件未超时,不删除! %s,createTime=%s,passDays=%s <= limitDays=%s" % (guid, mailObj.GetCreateTime(), passDays, limitDays), playerID)
                 continue
             
-            mailState = mailObj.GetMailState()
-            mailItemCount = mailMgr.GetMailItemCount(guid)
-            if mailItemCount and mailState != ShareDefine.MailState_Got:
-                #GameWorld.DebugLog("个人邮件有物品未领取不删除! %s" % guid, playerID)
-                continue
+            #mailState = mailObj.GetMailState()
+            #mailItemCount = mailMgr.GetMailItemCount(guid)
+            #if mailItemCount and mailState != ShareDefine.MailState_Got:
+            #    #GameWorld.DebugLog("个人邮件有物品未领取不删除! %s" % guid, playerID)
+            #    continue
             
             mailMgr.DelPersonalMail(playerID, guid)
             DataRecordPack.DR_MailDel(playerID, guid, "Timeout")
@@ -326,9 +328,14 @@
             itemCount = mailItem.GetCount()
             isBind = mailItem.GetIsBind()
             userData = mailItem.GetUserData()
-            #setAttrDict = {} if not userData else eval(userData) 之后扩展有指定属性的,可参考砍树版本
+            setAttrDict = None
+            if userData:
+                try:
+                    setAttrDict = eval(userData)
+                except:
+                    setAttrDict = None
             if not ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isBind, [IPY_GameWorld.rptItem], 
-                                                event=[ChConfig.ItemGive_Mail, False, {"MailGUID":guid}]):
+                                                event=[ChConfig.ItemGive_Mail, False, {"MailGUID":guid}], setAttrDict=setAttrDict):
                 continue
             
         DataRecordPack.DR_MailGiveSuccess(playerID, guid)
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyMongoDB/GMToolLogicProcess/Commands/GMT_AddPersonalCompensation.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyMongoDB/GMToolLogicProcess/Commands/GMT_AddPersonalCompensation.py
index 70d7893..e3efab1 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyMongoDB/GMToolLogicProcess/Commands/GMT_AddPersonalCompensation.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyMongoDB/GMToolLogicProcess/Commands/GMT_AddPersonalCompensation.py
@@ -19,6 +19,9 @@
 import GMCommon
 import DataRecordPack
 import PlayerMail
+import IpyGameDataPY
+import ShareDefine
+import CommFunc
 
 ## 收到gm命令执行
 # @param gmCmdDict:gm命令字典
@@ -61,10 +64,21 @@
         itemCount = GameWorld.ToIntDef(gmCmdDict.get('ItemCnt%s' % itemIndexStr, '0'))
         if not itemCount:
             continue
+        itemData = GameWorld.GetGameData().GetItemByTypeID(itemID)
+        if not itemData:
+            GameWorld.ErrLog("GM发送邮件物品不存在! itemID=%s,itemCount=%s" % (itemID, itemCount))
+            continue
         isBind = GameWorld.ToIntDef(gmCmdDict.get('IsBind%s' % itemIndexStr, '0'))
-        
+        appointID = GameWorld.ToIntDef(gmCmdDict.get('AppointID%s' % itemIndexStr, '0'))
+        userData = ""
+        if appointID:
+            ipyData = IpyGameDataPY.GetIpyGameData("AppointItem", appointID)
+            if not ipyData:
+                continue
+            userData = CommFunc.JsonDump({ShareDefine.Def_CItemKey_AppointID:appointID})
+            
         #添加到物品信息列表
-        itemList.append([itemID, itemCount, isBind])
+        itemList.append([itemID, itemCount, isBind, userData])
         
     GameWorld.DebugLog("GetGMTMailItemList %s" % itemList)
     return itemList

--
Gitblit v1.8.0