From 6f469af556dea71dea202a9431f1062745d8c10d Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期一, 15 十二月 2025 18:51:32 +0800
Subject: [PATCH] 121 【武将】武将系统-服务端(寻宝系数增加心愿物品规则;武将招募保底产出增加受永久卡限制;武将招募首次获得武将增加全服广播;)

---
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/PyNetPack.ini                   |    5 
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChPyNetPack.py           |  122 +++++++++------
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChPyNetSendPack.py       |   60 +++++++
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/IpyGameDataPY.py         |   20 +
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerTreasure.py |  239 +++++++++++++++++++++++++++--
 PySysDB/PySysDBPY.h                                                                          |    5 
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChConfig.py              |    1 
 7 files changed, 381 insertions(+), 71 deletions(-)

diff --git a/PySysDB/PySysDBPY.h b/PySysDB/PySysDBPY.h
index d1e46da..718fda7 100644
--- a/PySysDB/PySysDBPY.h
+++ b/PySysDB/PySysDBPY.h
@@ -1558,6 +1558,9 @@
 	char		NotifyKey;	//广播key
 	BYTE		AwardMoneyType;	//额外奖励货币类型
 	WORD		AwardMoneyValue;	//单次奖励货币数
+	BYTE		WishOutput;	//心愿产出规则
+	BYTE		WishReset;	//心愿重置规则
+	dict		WishLibSelect;	//心愿库选择数
 };
 
 //寻宝产出库表
@@ -1581,10 +1584,12 @@
 
 struct tagTreasureItemLib
 {
+	WORD		ID;	//ID
 	WORD		_LibID;	//库ID
 	DWORD		ItemID;	//物品ID
 	DWORD		ItemCount;	//物品个数
 	DWORD		ItemWeight;	//物品权重
+	BYTE		WishOutCnt;	//心愿产出次数
 };
 
 //寻宝累计次数奖励表
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/PyNetPack.ini b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/PyNetPack.ini
index 7880763..29922f9 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/PyNetPack.ini
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/PyNetPack.ini
@@ -765,12 +765,15 @@
 Writer = hxp
 Releaser = hxp
 RegType = 0
-RegisterPackCount = 1
+RegisterPackCount = 2
 
 PacketCMD_1=0xA5
 PacketSubCMD_1=0x68
 PacketCallFunc_1=OnRequestTreasure
 
+PacketCMD_2=0xA5
+PacketSubCMD_2=0x69
+PacketCallFunc_2=OnTreasureWishSelect
 
 ;时装
 [PlayerCoat]
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChConfig.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChConfig.py
index 660534b..b789cf7 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChConfig.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChConfig.py
@@ -3265,6 +3265,7 @@
 Def_PDict_TreasureLuck = "TreasureLuck_%s"  # 寻宝当前幸运值, 参数(寻宝类型)
 Def_PDict_TreasureCntAward = "TreasureCntAward_%s"  # 累计寻宝次数对应物品奖励领奖状态, 参数(寻宝类型)
 Def_PDict_TreasureGridCnt = "TreasureGridCnt_%s_%s"  # 格子对应累计产出次数, 参数(寻宝类型, 格子编号)
+Def_PDict_TreasureWish = "TreasureWish_%s_%s_%s"  # 心愿物品产出次数, 参数(寻宝类型, 库ID, 选择编号索引)  WishID*100+已产出次数
 
 Def_Player_Dict_LastAutoOpenPackTick = "LastAutoOpenPackTick219_%s"   #上一次自动购买的tick<背包类型>
 
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChPyNetPack.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChPyNetPack.py
index df6e0dc..07fd443 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChPyNetPack.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChPyNetPack.py
@@ -6834,54 +6834,6 @@
 
 
 #------------------------------------------------------
-# A5 69 刷新寻宝免费次数 #tagCMRefreshTreasureFreeCnt
-
-class  tagCMRefreshTreasureFreeCnt(Structure):
-    _pack_ = 1
-    _fields_ = [
-                  ("Cmd", c_ubyte),
-                  ("SubCmd", c_ubyte),
-                  ]
-
-    def __init__(self):
-        self.Clear()
-        self.Cmd = 0xA5
-        self.SubCmd = 0x69
-        return
-
-    def ReadData(self, stringData, _pos=0, _len=0):
-        self.Clear()
-        memmove(addressof(self), stringData[_pos:], self.GetLength())
-        return _pos + self.GetLength()
-
-    def Clear(self):
-        self.Cmd = 0xA5
-        self.SubCmd = 0x69
-        return
-
-    def GetLength(self):
-        return sizeof(tagCMRefreshTreasureFreeCnt)
-
-    def GetBuffer(self):
-        return string_at(addressof(self), self.GetLength())
-
-    def OutputString(self):
-        DumpString = '''// A5 69 刷新寻宝免费次数 //tagCMRefreshTreasureFreeCnt:
-                                Cmd:%s,
-                                SubCmd:%s
-                                '''\
-                                %(
-                                self.Cmd,
-                                self.SubCmd
-                                )
-        return DumpString
-
-
-m_NAtagCMRefreshTreasureFreeCnt=tagCMRefreshTreasureFreeCnt()
-ChNetPackDict[eval("0x%02x%02x"%(m_NAtagCMRefreshTreasureFreeCnt.Cmd,m_NAtagCMRefreshTreasureFreeCnt.SubCmd))] = m_NAtagCMRefreshTreasureFreeCnt
-
-
-#------------------------------------------------------
 # A5 37 请求邮件操作 #tagCMRequestMail
 
 class  tagCMRequestMail(Structure):
@@ -7331,6 +7283,80 @@
 
 
 #------------------------------------------------------
+# A5 69 寻宝心愿物品选择 #tagCSTreasureWishSelect
+
+class  tagCSTreasureWishSelect(Structure):
+    Head = tagHead()
+    TreasureType = 0    #(BYTE TreasureType)//寻宝类型
+    WishCnt = 0    #(BYTE WishCnt)
+    WishIDList = list()    #(vector<DWORD> WishIDList)// 选择的寻宝物品库中的数据ID,注意不是库ID
+    data = None
+
+    def __init__(self):
+        self.Clear()
+        self.Head.Cmd = 0xA5
+        self.Head.SubCmd = 0x69
+        return
+
+    def ReadData(self, _lpData, _pos=0, _Len=0):
+        self.Clear()
+        _pos = self.Head.ReadData(_lpData, _pos)
+        self.TreasureType,_pos = CommFunc.ReadBYTE(_lpData, _pos)
+        self.WishCnt,_pos = CommFunc.ReadBYTE(_lpData, _pos)
+        for i in range(self.WishCnt):
+            value,_pos=CommFunc.ReadDWORD(_lpData,_pos)
+            self.WishIDList.append(value)
+        return _pos
+
+    def Clear(self):
+        self.Head = tagHead()
+        self.Head.Clear()
+        self.Head.Cmd = 0xA5
+        self.Head.SubCmd = 0x69
+        self.TreasureType = 0
+        self.WishCnt = 0
+        self.WishIDList = list()
+        return
+
+    def GetLength(self):
+        length = 0
+        length += self.Head.GetLength()
+        length += 1
+        length += 1
+        length += 4 * self.WishCnt
+
+        return length
+
+    def GetBuffer(self):
+        data = ''
+        data = CommFunc.WriteString(data, self.Head.GetLength(), self.Head.GetBuffer())
+        data = CommFunc.WriteBYTE(data, self.TreasureType)
+        data = CommFunc.WriteBYTE(data, self.WishCnt)
+        for i in range(self.WishCnt):
+            data = CommFunc.WriteDWORD(data, self.WishIDList[i])
+        return data
+
+    def OutputString(self):
+        DumpString = '''
+                                Head:%s,
+                                TreasureType:%d,
+                                WishCnt:%d,
+                                WishIDList:%s
+                                '''\
+                                %(
+                                self.Head.OutputString(),
+                                self.TreasureType,
+                                self.WishCnt,
+                                "..."
+                                )
+        return DumpString
+
+
+m_NAtagCSTreasureWishSelect=tagCSTreasureWishSelect()
+ChNetPackDict[eval("0x%02x%02x"%(m_NAtagCSTreasureWishSelect.Head.Cmd,m_NAtagCSTreasureWishSelect.Head.SubCmd))] = m_NAtagCSTreasureWishSelect
+
+
+#------------------------------------------------------
 # A5 73 解锁命格孔 #tagCMUnLockBirthChartHole
 
 class  tagCMUnLockBirthChartHole(Structure):
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChPyNetSendPack.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChPyNetSendPack.py
index c12717b..7a7f487 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChPyNetSendPack.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChPyNetSendPack.py
@@ -8677,6 +8677,45 @@
 #------------------------------------------------------
 # A3 51 寻宝功能信息 #tagMCTreasureInfo
 
+class  tagMCTreasureWish(Structure):
+    _pack_ = 1
+    _fields_ = [
+                  ("WishID", c_ushort),    # 寻宝物品库中的数据ID,注意不是库ID
+                  ("OutCnt", c_ubyte),    # 做为心愿物品时已产出次数,有产出过的无法重新选择,未产出的可任意修改选择
+                  ]
+
+    def __init__(self):
+        self.Clear()
+        return
+
+    def ReadData(self, stringData, _pos=0, _len=0):
+        self.Clear()
+        memmove(addressof(self), stringData[_pos:], self.GetLength())
+        return _pos + self.GetLength()
+
+    def Clear(self):
+        self.WishID = 0
+        self.OutCnt = 0
+        return
+
+    def GetLength(self):
+        return sizeof(tagMCTreasureWish)
+
+    def GetBuffer(self):
+        return string_at(addressof(self), self.GetLength())
+
+    def OutputString(self):
+        DumpString = '''// A3 51 寻宝功能信息 //tagMCTreasureInfo:
+                                WishID:%d,
+                                OutCnt:%d
+                                '''\
+                                %(
+                                self.WishID,
+                                self.OutCnt
+                                )
+        return DumpString
+
+
 class  tagMCTreasureGridLimit(Structure):
     _pack_ = 1
     _fields_ = [
@@ -8725,6 +8764,8 @@
     TreasureCntAward = 0    #(DWORD TreasureCntAward)//累计寻宝次数对应奖励领奖状态,按奖励记录索引二进制记录是否已领取
     GridLimitCnt = 0    #(BYTE GridLimitCnt)
     GridLimitCntList = list()    #(vector<tagMCTreasureGridLimit> GridLimitCntList)//有限制抽取次数的格子次数信息
+    WishCnt = 0    #(BYTE WishCnt)
+    WishList = list()    #(vector<tagMCTreasureWish> WishList)//心愿物品信息
     data = None
 
     def __init__(self):
@@ -8744,6 +8785,11 @@
             temGridLimitCntList = tagMCTreasureGridLimit()
             _pos = temGridLimitCntList.ReadData(_lpData, _pos)
             self.GridLimitCntList.append(temGridLimitCntList)
+        self.WishCnt,_pos = CommFunc.ReadBYTE(_lpData, _pos)
+        for i in range(self.WishCnt):
+            temWishList = tagMCTreasureWish()
+            _pos = temWishList.ReadData(_lpData, _pos)
+            self.WishList.append(temWishList)
         return _pos
 
     def Clear(self):
@@ -8755,6 +8801,8 @@
         self.TreasureCntAward = 0
         self.GridLimitCnt = 0
         self.GridLimitCntList = list()
+        self.WishCnt = 0
+        self.WishList = list()
         return
 
     def GetLength(self):
@@ -8768,6 +8816,9 @@
         length += 1
         for i in range(self.GridLimitCnt):
             length += self.GridLimitCntList[i].GetLength()
+        length += 1
+        for i in range(self.WishCnt):
+            length += self.WishList[i].GetLength()
 
         return length
 
@@ -8782,6 +8833,9 @@
         data = CommFunc.WriteBYTE(data, self.GridLimitCnt)
         for i in range(self.GridLimitCnt):
             data = CommFunc.WriteString(data, self.GridLimitCntList[i].GetLength(), self.GridLimitCntList[i].GetBuffer())
+        data = CommFunc.WriteBYTE(data, self.WishCnt)
+        for i in range(self.WishCnt):
+            data = CommFunc.WriteString(data, self.WishList[i].GetLength(), self.WishList[i].GetBuffer())
         return data
 
     def OutputString(self):
@@ -8793,7 +8847,9 @@
                                 FreeCountToday:%d,
                                 TreasureCntAward:%d,
                                 GridLimitCnt:%d,
-                                GridLimitCntList:%s
+                                GridLimitCntList:%s,
+                                WishCnt:%d,
+                                WishList:%s
                                 '''\
                                 %(
                                 self.TreasureType,
@@ -8803,6 +8859,8 @@
                                 self.FreeCountToday,
                                 self.TreasureCntAward,
                                 self.GridLimitCnt,
+                                "...",
+                                self.WishCnt,
                                 "..."
                                 )
         return DumpString
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/IpyGameDataPY.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/IpyGameDataPY.py
index cbd6e77..b2a4aff 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/IpyGameDataPY.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/IpyGameDataPY.py
@@ -1267,6 +1267,9 @@
                         ("char", "NotifyKey", 0),
                         ("BYTE", "AwardMoneyType", 0),
                         ("WORD", "AwardMoneyValue", 0),
+                        ("BYTE", "WishOutput", 0),
+                        ("BYTE", "WishReset", 0),
+                        ("dict", "WishLibSelect", 0),
                         ),
 
                 "TreasureHouse":(
@@ -1284,10 +1287,12 @@
                         ),
 
                 "TreasureItemLib":(
+                        ("WORD", "ID", 0),
                         ("WORD", "LibID", 1),
                         ("DWORD", "ItemID", 0),
                         ("DWORD", "ItemCount", 0),
                         ("DWORD", "ItemWeight", 0),
+                        ("BYTE", "WishOutCnt", 0),
                         ),
 
                 "TreasureCntAward":(
@@ -4013,7 +4018,10 @@
     def GetNotifyGridNumList(self): return self.attrTuple[17] # 需要额外广播的格子 list
     def GetNotifyKey(self): return self.attrTuple[18] # 广播key char
     def GetAwardMoneyType(self): return self.attrTuple[19] # 额外奖励货币类型 BYTE
-    def GetAwardMoneyValue(self): return self.attrTuple[20] # 单次奖励货币数 WORD
+    def GetAwardMoneyValue(self): return self.attrTuple[20] # 单次奖励货币数 WORD
+    def GetWishOutput(self): return self.attrTuple[21] # 心愿产出规则 BYTE
+    def GetWishReset(self): return self.attrTuple[22] # 心愿重置规则 BYTE
+    def GetWishLibSelect(self): return self.attrTuple[23] # 心愿库选择数 dict
 
 # 寻宝产出库表
 class IPY_TreasureHouse():
@@ -4041,10 +4049,12 @@
         self.attrTuple = None
         return
         
-    def GetLibID(self): return self.attrTuple[0] # 库ID WORD
-    def GetItemID(self): return self.attrTuple[1] # 物品ID DWORD
-    def GetItemCount(self): return self.attrTuple[2] # 物品个数 DWORD
-    def GetItemWeight(self): return self.attrTuple[3] # 物品权重 DWORD
+    def GetID(self): return self.attrTuple[0] # ID WORD
+    def GetLibID(self): return self.attrTuple[1] # 库ID WORD
+    def GetItemID(self): return self.attrTuple[2] # 物品ID DWORD
+    def GetItemCount(self): return self.attrTuple[3] # 物品个数 DWORD
+    def GetItemWeight(self): return self.attrTuple[4] # 物品权重 DWORD
+    def GetWishOutCnt(self): return self.attrTuple[5] # 心愿产出次数 BYTE
 
 # 寻宝累计次数奖励表
 class IPY_TreasureCntAward():
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerTreasure.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerTreasure.py
index 5ca8203..ebc0dea 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerTreasure.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerTreasure.py
@@ -27,6 +27,7 @@
 import PlayerActYunshi
 import PlayerActivity
 import PlayerSuccess
+import PlayerGoldInvest
 import OpenServerActivity
 import PlayerBillboard
 import ShareDefine
@@ -76,6 +77,18 @@
         syncTypeList.append(treasureType)
         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureCountToday % (treasureType), 0)
         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureFreeCount % (treasureType), 0)
+        
+        # 每日心愿重置
+        wishLibSelect = ipyData.GetWishLibSelect()
+        wishReset = ipyData.GetWishReset()
+        if wishReset == 1:
+            for libIDStr, wishCnt in wishLibSelect.items():
+                for wishIndex in range(wishCnt):
+                    wishID, outCnt = GetWishInfo(curPlayer, treasureType, libIDStr, wishIndex)
+                    SetWishInfo(curPlayer, treasureType, libIDStr, wishIndex, wishID, 0)
+                    GameWorld.DebugLog("寻宝每日心愿重置: treasureType=%s,libID=%s,wishIndex=%s,wishID=%s,昨日心愿产出次数=%s" 
+                                       % (treasureType, libIDStr, wishIndex, wishID, outCnt))
+                    
     if syncTypeList:
         Sync_TreasureInfo(curPlayer, syncTypeList)
     return
@@ -110,6 +123,98 @@
         return True
     return False
 
+def GetWishInfo(curPlayer, treasureType, libID, wishIndex):
+    ## 心愿信息
+    # @return: 心愿ID, 已产出次数
+    info = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureWish % (treasureType, libID, wishIndex))
+    wishID, outCnt = info / 100, info % 100
+    return wishID, outCnt
+def SetWishInfo(curPlayer, treasureType, libID, wishIndex, wishID, outCnt):
+    info = wishID * 100 + min(outCnt, 99)
+    info = PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureWish % (treasureType, libID, wishIndex), info)
+    return info
+
+#// A5 69 寻宝心愿物品选择 #tagCSTreasureWishSelect
+#
+#struct tagCSTreasureWishSelect
+#{
+#    tagHead        Head;
+#    BYTE        TreasureType;    //寻宝类型
+#    BYTE        WishCnt;
+#    WORD        WishIDList[WishCnt];    // 选择的寻宝物品库中的数据ID,注意不是库ID
+#};
+def OnTreasureWishSelect(index, clientData, tick):
+    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
+    treasureType = clientData.TreasureType
+    reqSelectWishIDList = clientData.WishIDList
+    
+    setIpyData = IpyGameDataPY.GetIpyGameData("TreasureSet", treasureType)
+    if not setIpyData:
+        return
+    wishLibSelect = setIpyData.GetWishLibSelect()    
+    if not wishLibSelect:
+        GameWorld.DebugLog("该寻宝类型没有心愿物品功能! treasureType=%s" % (treasureType))
+        return
+    
+    GameWorld.DebugLog("寻宝选择心愿物品: treasureType=%s,reqSelectWishIDList=%s" % (treasureType, reqSelectWishIDList))
+    
+    selectLibItemDict = {} # 重新选择的心愿物品汇总 {libID:[wishID, ...], ...}
+    for wishID in reqSelectWishIDList:
+        libItemIpyData = IpyGameDataPY.GetIpyGameDataByCondition("TreasureItemLib", {"ID":wishID}, False)
+        if not libItemIpyData:
+            return
+        
+        itemID = libItemIpyData.GetItemID()
+        if not libItemIpyData.GetWishOutCnt():
+            GameWorld.DebugLog("非心愿物品,不可选择! wishID=%s" % (wishID))
+            return
+        
+        # 按所属库归类汇总
+        libID = libItemIpyData.GetLibID()
+        if libID not in selectLibItemDict:
+            selectLibItemDict[libID] = []
+        selectLibWishIDList = selectLibItemDict[libID]
+        if wishID not in selectLibWishIDList:
+            selectLibWishIDList.append(wishID)
+            
+        # 武将招募,额外限制
+        if treasureType in TreasureType_HeroCallList:
+            heroIpyData = IpyGameDataPY.GetIpyGameData("Hero", itemID)
+            if not heroIpyData:
+                return
+            if heroIpyData.GetRecruitBySelf() and not PlayerHero.GetHeroActivite(curPlayer, itemID):
+                GameWorld.DebugLog("需要激活本体的武将未激活不可选择!itemID=%s" % itemID)
+                return
+            
+    hisOutDict = {} # 历史选择已产出过的心愿物品记录 {wishID:outCnt, ...}
+    for libIDStr, wishCnt in wishLibSelect.items():
+        libID = int(libIDStr)
+        selectLibWishIDList = selectLibItemDict.get(libID, [])
+        if len(selectLibWishIDList) != wishCnt:
+            GameWorld.DebugLog("选择心愿库的物品数量与设定的心愿物品数量不一致!libID=%s,wishCnt=%s,selectCnt=%s,%s" 
+                               % (libID, wishCnt, len(selectLibWishIDList), selectLibWishIDList))
+            return
+        
+        for wishIndex in range(wishCnt):
+            wishID, outCnt = GetWishInfo(curPlayer, treasureType, libID, wishIndex)
+            if not outCnt:
+                continue
+            if wishID not in selectLibWishIDList:
+                GameWorld.DebugLogEx("已经产出过的心愿物品不可从选择中去除! outCnt=%s,wishID=%s not in %s", outCnt, wishID, selectLibWishIDList)
+                return
+            hisOutDict[wishID] = outCnt
+            
+    # 验证通过,保存
+    for libID, wishIDList in selectLibItemDict.items():
+        for wishIndex, wishID in enumerate(wishIDList):
+            outCnt = hisOutDict.get(wishID, 0)
+            SetWishInfo(curPlayer, treasureType, libID, wishIndex, wishID, outCnt)
+            GameWorld.DebugLog("保存心愿选择: libID=%s,wishIndex=%s,wishID=%s,outCnt=%s" % (libID, wishIndex, wishID, outCnt))
+            
+    Sync_TreasureInfo(curPlayer, [treasureType])
+    return
+
+                
 #// A5 68 请求寻宝 #tagCMRequestTreasure
 #
 #struct tagCMRequestTreasure
@@ -275,8 +380,45 @@
     if curIndexCount <= maxIndexCount and curIndexCount in beSureCountByIndexDict:
         beSureCountByIndexCfg = beSureCountByIndexDict[curIndexCount]
         
+    gridItemInfoDict = ipyData.GetGridItemInfo() # 格子对应物品信息 {"格子编号":[物品ID, 数量], ...}
+    gridLibInfoDict = ipyData.GetGridLibInfo() # 格子编号对应库ID {"编号":物品库ID, ...}
+    
+    # 心愿
+    wishSelectState = False # 心愿物品是否已选择
+    canOutWishDict = {} # 还可产出的心愿物品 {libID:{wishID:[wishIndex, canOut], ...}, ...}
+    wishOutputRule = setIpyData.GetWishOutput() # 心愿产出规则:心愿产出完毕后:  0 - 可继续产出该库物品; 1 - 不可再产出该库物品
+    wishLibSelect = setIpyData.GetWishLibSelect()
+    for libIDStr, selectCnt in wishLibSelect.items():
+        libID = int(libIDStr)
+        if libID not in canOutWishDict:
+            canOutWishDict[libID] = {}
+        for wishIndex in range(selectCnt):
+            wishID, outCnt = GetWishInfo(curPlayer, treasureType, libID, wishIndex)
+            if not wishID:
+                continue
+            wishSelectState = True
+            libItemIpyData = IpyGameDataPY.GetIpyGameDataByCondition("TreasureItemLib", {"ID":wishID}, False)
+            if not libItemIpyData:
+                continue
+            outCntLimit = libItemIpyData.GetWishOutCnt()
+            if not outCntLimit:
+                # 非心愿物品
+                continue
+            if outCnt >= outCntLimit:
+                # 该心愿物品产出次数已用完
+                continue
+            libWishCanOutDict = canOutWishDict[libID]
+            canOut = outCntLimit - outCnt
+            libWishCanOutDict[wishID] = [wishIndex, canOut]
+    if canOutWishDict:
+        if not wishSelectState:
+            GameWorld.DebugLog("心愿物品还未选择!", playerID)
+        else:
+            GameWorld.DebugLog("还可产出的心愿库对应WishID还可产出次数: %s" % canOutWishDict, playerID)
+            
     # 单抽产出优先级: 幸运物品 > 必出 > 保底 > 普通
     # 连抽没有优先级限制,只要满足条件即可产出
+    luckyOut = False # 幸运物品理论产出状态,不一定是真实产出,可能受终身卡限制
     getGridResult = []
     for tIndex in range(treasureCount):
         updLuck = min(updLuck + addLuck, maxLuck)
@@ -306,9 +448,13 @@
             
         # 满幸运必出
         if not curRateList and stageLuck and updLuck >= stageLuck and luckItemRateList:
-            curRateList = GetRemoveLimitGridRateList(luckItemRateList, gridNumCountInfo, gridNumMaxLimitInfo)
-            GameWorld.DebugLog("    【满幸运必出饼图】: %s" % curRateList, playerID)
-            
+            luckyOut = True
+            if treasureType in TreasureType_HeroCallList and not PlayerGoldInvest.GetInvestState(curPlayer, ChConfig.InvestType_Life):
+                GameWorld.DebugLog("    【满幸运必出饼图】: 终身卡未开通,武将招募幸运不产出", playerID)
+            else:
+                curRateList = GetRemoveLimitGridRateList(luckItemRateList, gridNumCountInfo, gridNumMaxLimitInfo)
+                GameWorld.DebugLog("    【满幸运必出饼图】: %s" % curRateList, playerID)
+                
         # 次数必出
         if not curRateList and updTreasureCount in beSureCountDict:
             besureGridRateList = beSureCountDict[updTreasureCount]
@@ -332,19 +478,34 @@
                 GameWorld.DebugLog("    幸运物品已经出过,不再重复产出! gridNum=%s in %s" % (gridNum, getGridResult))
                 continue
             
-            # 其他产出限制...
-            
+            # 心愿产出限制
+            gridNumStr = str(gridNum)
+            wishLibID = 0
+            if wishLibSelect and gridNumStr in gridLibInfoDict and gridLibInfoDict[gridNumStr] in canOutWishDict:
+                wishLibID = gridLibInfoDict[gridNumStr]
+                if wishOutputRule == 1: # 心愿物品产出完毕后,不可再产出该库物品,该模式下,未选择心愿的,也视为无可产出的心愿物品
+                    if not canOutWishDict[wishLibID]:
+                        GameWorld.DebugLog("    没有可产出的心愿物品,不产出! gridNum=%s,wishLibID=%s" % (gridNum, wishLibID), playerID)
+                        continue
+                    
             if not gridNum:
                 continue
             
             getGridResult.append(gridNum)
-            GameWorld.DebugLog("    本次产出: gridNum=%s, %s" % (gridNum, getGridResult), playerID)
-            if gridNum in luckyGridNumList:
+            GameWorld.DebugLog("    本次产出: gridNum=%s, %s, doCount=%s" % (gridNum, getGridResult, doCount), playerID)
+            if gridNum in luckyGridNumList or luckyOut:
+                luckyOut = False
                 if gridNum == setLuckyGridNum or updLuck >= maxLuck:
                     updLuck = 0
                 else:
                     updLuck = stageLuck # 直接切换到下一阶段幸运
-                GameWorld.DebugLog("    【产出幸运格子】: gridNum=%s,updLuck=%s" % (gridNum, updLuck), playerID)
+                if gridNum in luckyGridNumList:
+                    GameWorld.DebugLog("    【产出幸运格子】: gridNum=%s,updLuck=%s" % (gridNum, updLuck), playerID)
+                else:
+                    GameWorld.DebugLog("    【理论产出幸运格子,实际没有产出】: gridNum=%s,updLuck=%s,luckyGridNumList=%s" % (gridNum, updLuck, luckyGridNumList), playerID)
+            if wishLibID:
+                GameWorld.DebugLog("    【产出的是心愿库物品】: gridNum=%s,wishLibID=%s" % (gridNum, wishLibID), playerID)
+                
             if gridNum in gridNumCountInfo:
                 gridNumCountInfo[gridNum] = gridNumCountInfo[gridNum] + 1
                 GameWorld.DebugLog("    【更新产出次数】: gridNum=%s, %s" % (gridNum, gridNumCountInfo), playerID)
@@ -357,12 +518,11 @@
     
     isBind = 0 # 暂时默认不绑定
     job = curPlayer.GetJob()
-    gridItemInfoDict = ipyData.GetGridItemInfo() # 格子对应物品信息 {"格子编号":[物品ID, 数量], ...}
-    gridLibInfoDict = ipyData.GetGridLibInfo() # 格子编号对应库ID {"编号":物品库ID, ...}
     jobItemList = ipyData.GetJobItemList()
     treasureResult = []
     randItemIDDict = IpyGameDataPY.GetFuncEvalCfg("TreasureSet", 2)
     
+    wishAddOutDict = {} # 本次心愿物品预计增加产出 {wishID:addOut, ...}
     for gridNum in getGridResult:
         gridNum = str(gridNum)
         if gridNum in gridItemInfoDict:
@@ -391,19 +551,34 @@
             libItemList = IpyGameDataPY.GetIpyGameDataList("TreasureItemLib", libID)
             if not libItemList:
                 return
+            
+            libWishCanOutDict = canOutWishDict.get(libID, {})
+            wishWeightList = [] # 心愿物品权重
             itemWeightList = []
             for libItem in libItemList:
+                curID = libItem.GetID()
                 itemWeight, itemID, itemCount = libItem.GetItemWeight(), libItem.GetItemID(), libItem.GetItemCount()
                 if not itemWeight:
                     continue
                 if not __checkItemCanTreasure(curPlayer, treasureType, itemID):
                     continue
                 itemWeightList.append([itemWeight, [itemID, itemCount]])
+                if curID in libWishCanOutDict:
+                    _, canOut = libWishCanOutDict[curID]
+                    if canOut - wishAddOutDict.get(curID, 0) > 0:
+                        wishWeightList.append([itemWeight, [itemID, itemCount, curID]])
+                        
             if not itemWeightList:
                 GameWorld.ErrLog("寻宝随机格子没有可随机的物品!treasureType=%s,treasureIndex=%s,gridNum=%s,libID=%s" 
                                  % (treasureType, treasureIndex, gridNum, libID), playerID)
                 return
-            itemID, itemCount = GameWorld.GetResultByWeightList(itemWeightList)
+            # 优先产出选择的心愿物品
+            if wishWeightList:
+                itemID, itemCount, curID = GameWorld.GetResultByWeightList(wishWeightList)
+                wishAddOutDict[curID] = wishAddOutDict.get(curID, 0) + 1
+                GameWorld.DebugLog("优先产出心愿物品: gridNum=%s,libID=%s,wishID=%s,itemID=%s" % (gridNum, libID, curID, itemID), playerID)
+            else:
+                itemID, itemCount = GameWorld.GetResultByWeightList(itemWeightList)
         else:
             GameWorld.ErrLog("寻宝格子不存在!treasureType=%s,gridNum=%s" % (treasureType, gridNum), playerID)
             return
@@ -437,8 +612,18 @@
     if curIndexCount <= maxIndexCount:
         treasureCountEx = GameWorld.ChangeDataByDigitPlace(treasureCountEx, treasureIndex, curIndexCount)
         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureCountEx % (treasureType), treasureCountEx)
-        GameWorld.DebugLog("更新第x次x抽次数: treasureIndex=%s,curIndexCount=%s,maxIndexCount=%s,treasureCountEx=%s" % (treasureIndex, curIndexCount, maxIndexCount, treasureCountEx))
-        
+        GameWorld.DebugLog("更新第x次x抽次数: treasureIndex=%s,curIndexCount=%s,maxIndexCount=%s,treasureCountEx=%s" % (treasureIndex, curIndexCount, maxIndexCount, treasureCountEx), playerID)
+    # 心愿产出次数
+    for curID, addOut in wishAddOutDict.items():
+        for libID, libWishCanOutDict in canOutWishDict.items():
+            if curID not in libWishCanOutDict:
+                continue
+            wishIndex, canOut = libWishCanOutDict[curID]
+            wishID, outCnt = GetWishInfo(curPlayer, treasureType, libID, wishIndex)
+            updOut = outCnt + addOut
+            SetWishInfo(curPlayer, treasureType, libID, wishIndex, wishID, updOut)
+            GameWorld.DebugLog("更新心愿物品已产出次数: libID=%s,wishIndex=%s,wishID=%s,updOut=%s" % (libID, wishIndex, wishID, updOut), playerID)
+            
     addScoreType = setIpyData.GetAwardMoneyType() # 额外奖励货币类型
     addScore = setIpyData.GetAwardMoneyValue() # 单次奖励货币数
     if addScoreType and addScore:
@@ -463,7 +648,17 @@
         mailItemDict = ItemCommon.GetMailItemDict(itemObj)
         
         if int(gridNum) in notifyGridNumList and notifyKey:
-            PlayerControl.WorldNotify(0, notifyKey, [curPlayer.GetPlayerName(), itemID, itemObj.GetUserData(), itemCount])
+            if treasureType in TreasureType_HeroCallList:
+                if PlayerHero.GetHeroActivite(curPlayer, itemID):
+                    notifyKey = ""
+                    GameWorld.DebugLog("招募武将非首次获得的不广播了! itemID=%s" % itemID, playerID)
+                else:
+                    heroIpyData = IpyGameDataPY.GetIpyGameData("Hero", itemID)
+                    if heroIpyData:
+                        heroQuality = heroIpyData.GetQuality()
+                        PlayerControl.WorldNotify(0, notifyKey, [curPlayer.GetPlayerName(), heroQuality, itemID])
+            else:
+                PlayerControl.WorldNotify(0, notifyKey, [curPlayer.GetPlayerName(), itemID, itemObj.GetUserData(), itemCount])
             
         if mailItemList or not itemControl.PutInItem(packType, itemObj, event=[ChConfig.ItemGive_Treasure, False, {}]):
             mailItemList.append(mailItemDict)
@@ -522,12 +717,12 @@
         if not heroIpyData:
             return
         if heroIpyData.GetRecruitBySelf() and not PlayerHero.GetHeroActivite(curPlayer, itemID):
-            GameWorld.DebugLog("武将未激活不产出!itemID=%s" % itemID, playerID)
+            GameWorld.DebugLog("武将未激活不产出! itemID=%s" % itemID, playerID)
             return
         
     elif itemData.GetType() == ChConfig.Def_ItemType_Rune:
         if not PlayerRune.GetIsOpenByRuneID(curPlayer, itemID):
-            GameWorld.DebugLog("未解锁的符印不产出!itemID=%s" % itemID, playerID)
+            GameWorld.DebugLog("未解锁的符印不产出! itemID=%s" % itemID, playerID)
             return
         
     return True
@@ -652,6 +847,18 @@
             gridLimit.GridCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureGridCnt % (tType, gridNum))
             tTypeInfo.GridLimitCntList.append(gridLimit)
         tTypeInfo.GridLimitCnt = len(tTypeInfo.GridLimitCntList)
+        
+        wishLibSelect = setIpyData.GetWishLibSelect()
+        for libIDStr, wishCnt in wishLibSelect.items():
+            libID = int(libIDStr)
+            for wishIndex in range(wishCnt):
+                wishID, outCnt = GetWishInfo(curPlayer, tType, libID, wishIndex)
+                wish = ChPyNetSendPack.tagMCTreasureWish()
+                wish.WishID = wishID
+                wish.OutCnt = outCnt
+                tTypeInfo.WishList.append(wish)
+        tTypeInfo.WishCnt = len(tTypeInfo.WishList)
+        
         treasureInfoPack.TreasuerInfoList.append(tTypeInfo)
     treasureInfoPack.InfoCount = len(treasureInfoPack.TreasuerInfoList)
     NetPackCommon.SendFakePack(curPlayer, treasureInfoPack)

--
Gitblit v1.8.0