From f5cd3e2c7831b5f7e8865475804580ec713702ad Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期五, 26 十一月 2021 11:24:41 +0800
Subject: [PATCH] 9341 【BT5】【主干】【后端】情缘系统(吃喜糖改为随机获得一种物品)

---
 ServerPython/CoreServerGroup/GameServer/Script/GameWorld.py          |    6 +++---
 ServerPython/CoreServerGroup/GameServer/Script/IpyGameDataPY.py      |    9 ++++++---
 ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerLove.py  |   14 ++++++++++++--
 ServerPython/CoreServerGroup/GameServer/Script/GM/Commands/Couple.py |   16 +++++++++-------
 PySysDB/PySysDBG.h                                                   |    3 ++-
 5 files changed, 32 insertions(+), 16 deletions(-)

diff --git a/PySysDB/PySysDBG.h b/PySysDB/PySysDBG.h
index 9d6c4c2..cb665b4 100644
--- a/PySysDB/PySysDBG.h
+++ b/PySysDB/PySysDBG.h
@@ -882,7 +882,8 @@
 	BYTE		IsDayReset;	//是否每日重置
 	DWORD		Prosperity;	//初始繁荣度
 	WORD		CandyTimes;	//喜糖持续时间秒
-	list		CandyItemInfo;	//喜糖物品列表[[物品ID,个数,是否拍品], ...]
+	list		CandyItemWeightInfo;	//喜糖物品库权重列表[[权重, 物品ID,个数,是否拍品], ...]
+	list		CandyNotifyItemInfo;	//喜糖需要广播的物品ID列表
 	list		BrideGiftItemInfo;	//聘礼物品列表[[物品ID,个数,是否拍品], ...]
 	char		WorldNotifyKey;	//广播key
 };
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/GM/Commands/Couple.py b/ServerPython/CoreServerGroup/GameServer/Script/GM/Commands/Couple.py
index f5164e8..50dc7d3 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/GM/Commands/Couple.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/GM/Commands/Couple.py
@@ -26,7 +26,7 @@
     GameWorld.DebugAnswer(curPlayer, "---------- %s" % GameWorld.GetCurrentDataTimeStr())
     GameWorld.DebugAnswer(curPlayer, "清除伴侣: Couple 0")
     GameWorld.DebugAnswer(curPlayer, "重置聘礼: Couple 0 1")
-    GameWorld.DebugAnswer(curPlayer, "设置伴侣: Couple 1 目标ID [可选聘礼ID]")
+    GameWorld.DebugAnswer(curPlayer, "设置成亲: Couple 1 伴侣ID [可选聘礼ID]")
     GameWorld.DebugAnswer(curPlayer, "设亲密度: Couple 2 目标ID 亲密度")
     GameWorld.DebugAnswer(curPlayer, "增加密度: Couple 3 目标ID 亲密度")
     return
@@ -67,19 +67,21 @@
             
         return
     
-    # 设置伴侣
+    # 设置成亲
     elif value1 == 1:
-        if couple:
-            GameWorld.DebugAnswer(curPlayer, "已有伴侣! coupleID=%s" % couple.GetCoupleID(playerID))
-            return
         tagPlayerID = gmList[1] if len(gmList) > 1 else 0
         if not tagPlayerID or tagPlayerID == playerID:
             GameWorld.DebugAnswer(curPlayer, "非法伴侣玩家ID:%s,playerID=%s" % (tagPlayerID, playerID))
             return
+        if couple:
+            if couple.GetCoupleID(playerID) != tagPlayerID:
+                GameWorld.DebugAnswer(curPlayer, "已有伴侣! coupleID=%s" % couple.GetCoupleID(playerID))
+                return
         tagCouple = coupleMgr.GetCouple(tagPlayerID)
         if tagCouple:
-            GameWorld.DebugAnswer(curPlayer, "对方已有伴侣! tagCoupleID=%s" % tagCouple.GetCoupleID(tagPlayerID))
-            return
+            if tagCouple.GetCoupleID(tagPlayerID) != playerID:
+                GameWorld.DebugAnswer(curPlayer, "对方已有伴侣! tagCoupleID=%s" % tagCouple.GetCoupleID(tagPlayerID))
+                return
         
         bridePriceID = gmList[2] if len(gmList) > 2 else 1
         
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/GameWorld.py b/ServerPython/CoreServerGroup/GameServer/Script/GameWorld.py
index 40c7c07..0bcfc8e 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/GameWorld.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/GameWorld.py
@@ -985,16 +985,16 @@
 
 ## 从列表中产生物品,[[权重, object], ....]
 #  @param weightList 待选列表
-def GetResultByWeightList(weightList):
+def GetResultByWeightList(weightList, defValue=None):
     randList = []
     weight = 0
     for info in weightList:
         weight += info[0]
         randList.append([weight, info[1] if len(info) == 2 else info[1:]])
     if not randList:
-        return
+        return defValue
     rate = random.randint(1, randList[-1][0])
-    return GetResultByRiseList(randList, rate)
+    return GetResultByRiseList(randList, rate, defValue)
 
 ## 获得对应数位的值
 #  @param numValue 数值
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/IpyGameDataPY.py b/ServerPython/CoreServerGroup/GameServer/Script/IpyGameDataPY.py
index 9972bfd..cf44f8f 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/IpyGameDataPY.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/IpyGameDataPY.py
@@ -722,7 +722,8 @@
                         ("BYTE", "IsDayReset", 0),
                         ("DWORD", "Prosperity", 0),
                         ("WORD", "CandyTimes", 0),
-                        ("list", "CandyItemInfo", 0),
+                        ("list", "CandyItemWeightInfo", 0),
+                        ("list", "CandyNotifyItemInfo", 0),
                         ("list", "BrideGiftItemInfo", 0),
                         ("char", "WorldNotifyKey", 0),
                         ),
@@ -2231,7 +2232,8 @@
         self.IsDayReset = 0
         self.Prosperity = 0
         self.CandyTimes = 0
-        self.CandyItemInfo = []
+        self.CandyItemWeightInfo = []
+        self.CandyNotifyItemInfo = []
         self.BrideGiftItemInfo = []
         self.WorldNotifyKey = ""
         return
@@ -2241,7 +2243,8 @@
     def GetIsDayReset(self): return self.IsDayReset # 是否每日重置
     def GetProsperity(self): return self.Prosperity # 初始繁荣度
     def GetCandyTimes(self): return self.CandyTimes # 喜糖持续时间秒
-    def GetCandyItemInfo(self): return self.CandyItemInfo # 喜糖物品列表[[物品ID,个数,是否拍品], ...]
+    def GetCandyItemWeightInfo(self): return self.CandyItemWeightInfo # 喜糖物品库权重列表[[权重, 物品ID,个数,是否拍品], ...]
+    def GetCandyNotifyItemInfo(self): return self.CandyNotifyItemInfo # 喜糖需要广播的物品ID列表
     def GetBrideGiftItemInfo(self): return self.BrideGiftItemInfo # 聘礼物品列表[[物品ID,个数,是否拍品], ...]
     def GetWorldNotifyKey(self): return self.WorldNotifyKey # 广播key
 
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerLove.py b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerLove.py
index e0b6f71..7eeaebd 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerLove.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerLove.py
@@ -928,7 +928,9 @@
     ipyData = IpyGameDataPY.GetIpyGameData("Marry", bridePriceID)
     if not ipyData:
         return
-    candyItemInfo = ipyData.GetCandyItemInfo()
+    candyItemInfo = []
+    candyItemWeightInfo = ipyData.GetCandyItemWeightInfo()
+    candyNotifyItemInfo = ipyData.GetCandyNotifyItemInfo()
     
     playerFreeEatCount = candyObj.playerFreeEatCountDict.get(playerID, 0)
     playerFireworksCount = candyObj.fireworksCountDict.get(playerID, 0)
@@ -951,7 +953,15 @@
         
         updProsperity = candyObj.prosperity
         updPlayerFreeEatCount = candyObj.playerFreeEatCountDict.get(playerID, 0)
-        GameWorld.Log("更新喜糖宴会: updProsperity=%s,updPlayerFreeEatCount=%s" % (updProsperity, updPlayerFreeEatCount), playerID)
+        
+        getCandyItemInfo = GameWorld.GetResultByWeightList(candyItemWeightInfo, [])
+        if getCandyItemInfo:
+            candyItemInfo.append(getCandyItemInfo)
+            itemID, itemCount = getCandyItemInfo[:2]
+            if itemID in candyNotifyItemInfo:
+                PlayerControl.WorldNotify(0, "EatCandyItemNotify", [curPlayer.GetName(), itemID, itemCount])
+        GameWorld.Log("更新喜糖宴会: updProsperity=%s,updPlayerFreeEatCount=%s,getCandyItemInfo=%s" 
+                      % (updProsperity, updPlayerFreeEatCount, getCandyItemInfo), playerID)
         
     return canBuy, isFree, costMoneyType, costMoneyValue, candyItemInfo
 

--
Gitblit v1.8.0