From caace426c6cb047cf1b734486615111853225771 Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期四, 17 六月 2021 18:31:35 +0800
Subject: [PATCH] 8988 【主干】【BT2】【BT2-1.100.1】【后端】神装进阶功能

---
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Event/EventSrc/Operate_EquipEvolve.py |  251 ++++++++++++++++++++++++-------------------------
 1 files changed, 124 insertions(+), 127 deletions(-)

diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Event/EventSrc/Operate_EquipEvolve.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Event/EventSrc/Operate_EquipEvolve.py
index 27cf224..051efea 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Event/EventSrc/Operate_EquipEvolve.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Event/EventSrc/Operate_EquipEvolve.py
@@ -6,13 +6,13 @@
 #
 # @todo:装备神装进阶
 # @author hxp
-# @date 2019-10-07
+# @date 2021-06-17
 # @version 1.0
 #
 # 详细描述: 装备神装进阶
 #
 #-------------------------------------------------------------------------------
-#"""Version = 2019-10-07 19:00"""
+#"""Version = 2021-06-17 18:30"""
 #-------------------------------------------------------------------------------
 
 import GameWorld
@@ -20,10 +20,15 @@
 import IPY_GameWorld
 import PlayerControl
 import IpyGameDataPY
+import ChPyNetSendPack
+import NetPackCommon
 import ItemControler
 import ShareDefine
 import ChConfig
 import ChEquip
+
+import math
+import json
 
 
 #// A3 30 装备神装进阶 #tagCMEquipEvolve
@@ -32,75 +37,46 @@
 #{
 #    tagHead        Head;
 #    BYTE        EquipIndex;    // 要进阶的装备在装备背包中索引
-#    BYTE        NeedEquipIDIndex;        // 所需固定装备B在背包中索引
-#    BYTE        NeedItemIDIndexCnt;    // 附加材料在背包中索引个数
-#    BYTE        NeedItemIDIndex[NeedItemIDIndexCnt];    // 附加材料在背包的索引列表
-#    BYTE        NeedSuitIndexCnt;    // 所需套装材料在背包中索引个数
-#    BYTE        NeedSuitIndex[NeedSuitIndexCnt];    // 所需套装材料在背包的索引列表
 #};
-def OnEquipWashEvolve(index, clientData, tick):
+def OnEquipEvolve(index, clientData, tick):
     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
     playerID = curPlayer.GetPlayerID()
     equipIndex = clientData.EquipIndex
-    needEquipIDIndex = clientData.NeedEquipIDIndex
-    needItemIDIndexList = clientData.NeedItemIDIndex
-    needSuitIndexList = clientData.NeedSuitIndex
-    
+    GameWorld.DebugLog("神装进阶: equipIndex=%s" % equipIndex)
     equipPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptEquip)
     curEquip = equipPack.GetAt(equipIndex)
     if not ItemCommon.CheckItemCanUse(curEquip):
         return
     equipItemID = curEquip.GetItemTypeID()
     equipClassLV = ItemCommon.GetItemClassLV(curEquip)
+    GameWorld.DebugLog("    equipItemID=%s,equipClassLV=%s" % (equipItemID, equipClassLV))
     ipyData = IpyGameDataPY.GetIpyGameData("EquipShenEvolve", equipItemID)
     if not ipyData:
         return
     evolveEquipID = ipyData.GetEvolveEquipID()
-    needItemIDInfo = ipyData.GetEvolveNeedItemIDInfo()
-    needSuitCount = ipyData.GetEvolveNeedSuitCount()
-    needEquipID = ipyData.GetEvolveNeedEquipID()
+    needItemIDInfoList = ipyData.GetEvolveNeedItemIDInfo()
     
     evolveEquipItemData = GameWorld.GetGameData().GetItemByTypeID(evolveEquipID)
     if not evolveEquipItemData:
         return
     
-    # 验证所需材料
     itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
-    needItemCount = 0
-    if needItemIDInfo:
-        needItemCount = __CheckNeedItem(curPlayer, needItemIDInfo, needItemIDIndexList, itemPack)
-        if needItemCount == None:
-            return
-        
-    if needSuitCount:
-        if not __CheckNeedSuitEquip(curPlayer, needSuitCount, equipClassLV, needSuitIndexList, itemPack):
-            return
-        
-    if needEquipID:
-        if not __CheckNeedEquipID(curPlayer, needEquipID, needEquipIDIndex, itemPack):
-            return
-        
-    drDict = {"equipItemID":equipItemID, "evolveEquipID":evolveEquipID}
-    # 扣除材料
-    if needItemCount:
-        ItemCommon.ReduceItem(curPlayer, itemPack, needItemIDIndexList, needItemCount, 
-                              False, ChConfig.ItemDel_EquipEvolve, drDict)
+    lackItemDict, delInfoDict = ItemCommon.GetCostItemIndexList(needItemIDInfoList, itemPack)
+    if lackItemDict:
+        GameWorld.DebugLog("    所需进阶材料不足!equipItemID=%s,evolveEquipID=%s,needItemIDInfoList=%s,lackItemDict=%s"
+                           % (equipItemID, evolveEquipID, needItemIDInfoList, lackItemDict), playerID)
+        return
     
-    if needSuitCount:
-        ItemCommon.ReduceItem(curPlayer, itemPack, needSuitIndexList, needSuitCount, 
-                              False, ChConfig.ItemDel_EquipEvolve, drDict)
-        
-    if needEquipID:
-        ItemCommon.ReduceItem(curPlayer, itemPack, [needEquipIDIndex], 1, 
-                              False, ChConfig.ItemDel_EquipEvolve, drDict)
-        
+    #扣消耗
+    ItemCommon.DelCostItem(curPlayer, itemPack, delInfoDict, "EquipEvolve")
+    
     # 原装备替换成进阶装备
     evolveEquip = ItemControler.GetOutPutItemObj(evolveEquipID, curPlayer=curPlayer)
     if not evolveEquip:
         return
     curEquip.AssignItem(evolveEquip)
     curPlayer.Sync_MakeItemAnswer(ShareDefine.Def_mitEquipEvolve, ChConfig.Def_ComposeState_Sucess)
-    GameWorld.DebugLog("进阶神装成功! equipItemID=%s,evolveEquipID=%s" % (equipItemID, evolveEquipID), playerID)
+    GameWorld.Log("进阶神装成功! equipItemID=%s,evolveEquipID=%s" % (equipItemID, evolveEquipID), playerID)
     
     #刷新属性
     ChEquip.RefreshPlayerEquipAttribute(curPlayer, equipClassLV)
@@ -108,96 +84,117 @@
     playControl.RefreshPlayerAttrState()
     return
 
-def __CheckNeedItem(curPlayer, needItemIDInfo, needItemIDIndexList, itemPack):
-    ## 检查所需额外材料物品
+
+#// A3 31 装备神装拆解 #tagCMEquipShenDecompose
+#
+#struct    tagCMEquipShenDecompose
+#{
+#    tagHead        Head;
+#    BYTE        Count;        //所在背包索引的数量
+#    WORD        IndexList[Count];    //所在背包索引列表
+#};
+def OnEquipShenDecompose(index, clientData, tick):
+    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
+    indexList = clientData.IndexList
     
-    playerID = curPlayer.GetPlayerID()
-    needItemID, needItemCount = needItemIDInfo
-    maxPackCount = itemPack.GetCount()
-    totalCount = 0
-    for index in needItemIDIndexList:
-        if index >= maxPackCount:
-            GameWorld.DebugLog("该物品材料格子索引不存在!无法进阶!index=%s,maxPackCount=%s" 
-                               % (index, maxPackCount), playerID)
-            return
-        curItem = itemPack.GetAt(index)
-        if not ItemCommon.CheckItemCanUse(curItem):
-            GameWorld.DebugLog("该物品材料不可使用!无法进阶! index=%s" % (index), playerID)
-            return
-        itemID = curItem.GetItemTypeID()
-        if itemID != needItemID:
-            GameWorld.DebugLog("该物品材料不可用于进阶!index=%s,itemID=%s != needItemID=%s" 
-                               % (index, itemID, needItemID), playerID)
-            return
-        totalCount += curItem.GetCount()
+    GameWorld.DebugLog("神装分解: indexList=%s" % indexList)
+    
+    isAuctionItem = 0
+    decomposeEquipIDList = [] # 已分解的神装装备ID列表
+    getItemCountDict = {} # 分解后获得的物品列表
+    itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
+    for index in indexList:
+        curEquip = itemPack.GetAt(index)
         
-    if totalCount < needItemCount:
-        GameWorld.DebugLog("所需额外材料个数不足,无法进阶! needItemIDIndexList=%s,totalCount=%s < needItemCount=%s" 
-                               % (needItemIDIndexList, totalCount, needItemCount), playerID)
-        return
-    
-    return needItemCount
-
-
-def __CheckNeedSuitEquip(curPlayer, needSuitCount, equipClassLV, needSuitIndexList, itemPack):
-    ## 检查所需套装材料
-    
-    playerID = curPlayer.GetPlayerID()
-    maxPackCount = itemPack.GetCount()
-    totalCount = 0
-    for index in needSuitIndexList:
-        if index >= maxPackCount:
-            GameWorld.DebugLog("该套装格子索引不存在!无法进阶!index=%s,maxPackCount=%s" 
-                               % (index, maxPackCount), playerID)
-            return
-        curItem = itemPack.GetAt(index)
-        if not ItemCommon.CheckItemCanUse(curItem):
-            GameWorld.DebugLog("该套装不可使用!无法进阶! index=%s" % (index), playerID)
-            return
-        classLV = ItemCommon.GetItemClassLV(curItem)
-        if classLV != equipClassLV:
-            GameWorld.DebugLog("该套装材料阶不相同,不可用于进阶!index=%s,classLV=%s != equipClassLV=%s" 
-                               % (index, classLV, equipClassLV), playerID)
-            return
-        color = curItem.GetItemColor()
-        if color != ChConfig.Def_Quality_Orange:
-            GameWorld.DebugLog("该套装材料非橙装,不可用于进阶!index=%s,color=%s" % (index, color), playerID)
-            return
-        suieID = curItem.GetSuiteID()
-        if not suieID:
-            GameWorld.DebugLog("该套装材料非套装装备,不可用于进阶!index=%s,suieID=%s" % (index, suieID), playerID)
-            return
-        if not ItemCommon.CheckJob(curPlayer, curItem):
-            GameWorld.DebugLog("该套装材料非本职业,不可用于进阶!index=%s" % (index), playerID)
-            return
-        totalCount += 1
+        if not ItemCommon.CheckItemCanUse(curEquip):
+            continue
         
-    if totalCount < needSuitCount:
-        GameWorld.DebugLog("所需套装个数不足,无法进阶! needSuitIndexList=%s,totalCount=%s < needSuitCount=%s" 
-                               % (needSuitIndexList, totalCount, needSuitCount), playerID)
+        getItemIDCountDict = {}
+        equipItemID = curEquip.GetItemTypeID()
+        GameWorld.DebugLog("    检查分解神装: index=%s,equipItemID=%s" % (index, equipItemID))
+        getEquipItemID = CheckEquipShenDecompose(equipItemID, getItemIDCountDict)
+        if equipItemID == getEquipItemID:
+            continue
+        
+        getItemList = [[itemID, itemCount, isAuctionItem] for itemID, itemCount in getItemIDCountDict.items()]
+        GameWorld.DebugLog("        分解后可获得装备: getEquipItemID=%s, getItemList=%s" % (getEquipItemID, getItemList))
+        if not ItemControler.CheckPackSpaceEnough(curPlayer, getItemList):
+            break
+        
+        getEquipObj = ItemControler.GetOutPutItemObj(getEquipItemID, curPlayer=curPlayer)
+        if not getEquipObj:
+            continue
+        
+        # 给分解后的物品及材料
+        curEquip.AssignItem(getEquipObj)
+        for itemID, itemCount, isAuctionItem in getItemList:
+            ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isAuctionItem, [IPY_GameWorld.rptItem],
+                                         event=["EquipShenDecompose", False, {"equipItemID":equipItemID}])
+            getItemCountDict[itemID] = getItemCountDict.get(itemID, 0) + itemCount
+            
+        # 统计累加
+        decomposeEquipIDList.append(equipItemID)
+        getItemCountDict[getEquipItemID] = getItemCountDict.get(getEquipItemID, 0) + 1
+        
+        
+    ## 通知分解结果
+    if not getItemCountDict:
         return
     
-    return True
+    getItemDataList = [[itemID, itemCount, isAuctionItem] for itemID, itemCount in getItemCountDict.items()]
+    GameWorld.DebugLog("    已分解装备ID: %s" % decomposeEquipIDList)
+    GameWorld.DebugLog("    获得物品列表: %s" % getItemDataList)
+    
+    getItemInfo = json.dumps(getItemDataList, ensure_ascii=False)
+    clientPack = ChPyNetSendPack.tagMCEquipDecomposeRet()
+    clientPack.Clear()
+    clientPack.DecomposeEquipIDList = decomposeEquipIDList
+    clientPack.DecomposeEquipIDCount = len(clientPack.DecomposeEquipIDList)
+    clientPack.GetItemData = str(getItemInfo)
+    clientPack.GetItemLen = len(clientPack.GetItemData)
+    NetPackCommon.SendFakePack(curPlayer, clientPack) 
+    return
 
-def __CheckNeedEquipID(curPlayer, needEquipID, needEquipIDIndex, itemPack):
-    ## 检查所需额外装备
+def CheckEquipShenDecompose(equipItemID, getItemIDCountDict):
+    # 非神装无法分解
+    ipyData = IpyGameDataPY.GetIpyGameDataNotLog("EquipShenAttr", equipItemID)
+    if not ipyData:
+        GameWorld.DebugLog("        非神装,无法分解!equipItemID=%s" % equipItemID)
+        return equipItemID
     
-    playerID = curPlayer.GetPlayerID()
-    maxPackCount = itemPack.GetCount()
-    if needEquipIDIndex >= maxPackCount:
-        GameWorld.DebugLog("该额外装备索引不存在!无法进阶!needEquipIDIndex=%s,maxPackCount=%s" 
-                           % (needEquipIDIndex, maxPackCount), playerID)
-        return
-    curItem = itemPack.GetAt(needEquipIDIndex)
-    if not ItemCommon.CheckItemCanUse(curItem):
-        GameWorld.DebugLog("该额外装备不可使用!无法进阶! needEquipIDIndex=%s" % (needEquipIDIndex), playerID)
-        return
-    itemID = curItem.GetItemTypeID()
-    if itemID != needEquipID:
-        GameWorld.DebugLog("该额外装备ID错误,不可用于进阶!needEquipIDIndex=%s,itemID=%s != needEquipID=%s" 
-                           % (needEquipIDIndex, itemID, needEquipID), playerID)
-        return
+    EquipShenDecomposeIDMap = GetEquipShenDecomposeIDMap()
+    if equipItemID not in EquipShenDecomposeIDMap:
+        GameWorld.DebugLog("        未找到原进化装备,无法分解!equipItemID=%s" % equipItemID)
+        return equipItemID
     
-    return True
+    decomposeID = EquipShenDecomposeIDMap[equipItemID]
+    evolveIpyData = IpyGameDataPY.GetIpyGameData("EquipShenEvolve", decomposeID)
+    if not evolveIpyData:
+        return equipItemID
+    
+    getItemIDInfoList = evolveIpyData.GetEvolveNeedItemIDInfo()
+    decomposeGetItemPer = IpyGameDataPY.GetFuncCfg("EquipShenDecompose", 1)
+    GameWorld.DebugLog("        可分解神装: equipItemID=%s,decomposeID=%s,getItemIDInfoList=%s" 
+                       % (equipItemID, decomposeID, getItemIDInfoList))
+    
+    # 分解获得80%原材料,个数向上取整
+    for getItemID, srcCount in getItemIDInfoList:
+        getCount = int(math.ceil(srcCount * decomposeGetItemPer / 100.0))
+        getItemIDCountDict[getItemID] = getItemIDCountDict.get(getItemID, 0) + getCount
+        
+    return CheckEquipShenDecompose(decomposeID, getItemIDCountDict)
 
+def GetEquipShenDecomposeIDMap():
+    key = "EquipShenDecomposeIDMap"
+    EquipShenDecomposeIDMap = IpyGameDataPY.GetConfigEx(key)
+    if not EquipShenDecomposeIDMap:
+        EquipShenDecomposeIDMap = {}
+        ipyDataMgr = IpyGameDataPY.IPY_Data()
+        for index in xrange(ipyDataMgr.GetEquipShenEvolveCount()):
+            ipyData = ipyDataMgr.GetEquipShenEvolveByIndex(index)
+            equipID = ipyData.GetEquipItemID()
+            evolveEquipID = ipyData.GetEvolveEquipID()
+            EquipShenDecomposeIDMap[evolveEquipID] = equipID # 分解的则反向映射
+        IpyGameDataPY.SetConfigEx(key, EquipShenDecomposeIDMap)
+    return EquipShenDecomposeIDMap
 

--
Gitblit v1.8.0