#!/usr/bin/python # -*- coding: GBK -*- #------------------------------------------------------------------------------- # ##@package Event.EventSrc.Operate_ItemCompound # # @todo:ÎïÆ·ºÏ³É # @author hxp # @date 2017-07-27 # @version 1.0 # # ÏêϸÃèÊö: ÎïÆ·ºÏ³É # #------------------------------------------------------------------------------- #"""Version = 2017-07-27 17:30""" #------------------------------------------------------------------------------- import GameWorld import ItemCommon import ShareDefine import IPY_GameWorld import PlayerControl import ItemControler import IpyGameDataPY import ChConfig import PlayerSuccess import DataRecordPack import random import math #//A3 03 ÎïÆ·ºÏ³É #tagCMItemCompound # #struct tagCMItemCompound #{ # tagHead Head; # DWORD ID; // ºÏ³ÉID # WORD CompoundCnt; //ºÏ³ÉÊýÁ¿(´ÎÊý) # BYTE UnfixedItemIndexCnt; // ²»¹Ì¶¨ÎïÆ·ÔÚ±³°üÖÐË÷Òý¸öÊý # BYTE UnfixedItemIndex[UnfixedItemIndexCnt]; // ²»¹Ì¶¨ÎïÆ·ÔÚ±³°üµÄË÷ÒýÁбí # BYTE FixedItemIndexCnt; // ¹Ì¶¨ÎïÆ·ÔÚ±³°üÖÐË÷Òý¸öÊý # BYTE FixedItemIndex[FixedItemIndexCnt]; // ¹Ì¶¨ÎïÆ·ÔÚ±³°üµÄË÷ÒýÁбí # BYTE AddonsItemIndexCnt; // ¸½¼ÓÎïÆ·ÔÚ±³°üÖÐË÷Òý¸öÊý # BYTE AddonsItemIndex[AddonsItemIndexCnt]; // ¸½¼ÓÎïÆ·ÔÚ±³°üµÄË÷ÒýÁбí # BYTE AddonsItemCount[AddonsItemIndexCnt]; // ¸½¼ÓÎïÆ·ÔÚ±³°üµÄË÷Òý¶ÔÓ¦¿Û³ýÊýÁ¿Áбí # BYTE RateIncreaseItemIndexCnt; // ÌáÉý¸ÅÂÊÎïÆ·ÔÚ±³°üÖÐË÷Òý¸öÊý # BYTE RateIncreaseItemIndex[RateIncreaseItemIndexCnt]; // ÌáÉý¸ÅÂÊÎïÆ·ÔÚ±³°üµÄË÷ÒýÁбí #}; def OnItemCompound(index, clientData, tick): curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index) playerID = curPlayer.GetPlayerID() compoundID = clientData.ID compoundCnt = max(1, clientData.CompoundCnt) # ÖÁÉٺϳÉÒ»¸ö unfixedItemIndexList = clientData.UnfixedItemIndex fixedItemIndexList = clientData.FixedItemIndex #addonsItemIndexList = clientData.AddonsItemIndex #addonsItemCountList = clientData.AddonsItemCount incRateItemIndexList = clientData.RateIncreaseItemIndex GameWorld.DebugLog("ÎïÆ·ºÏ³É: ID=%s,compoundCnt=%s,unfixedItemIndexList=%s,fixedItemIndexList=%s,incRateItemIndexList=%s" % (compoundID, compoundCnt, unfixedItemIndexList, fixedItemIndexList, incRateItemIndexList), playerID) ipyData = IpyGameDataPY.GetIpyGameData("ItemCompound", compoundID) if not ipyData: GameWorld.ErrLog("ÕÒ²»µ½¸ÃºÏ³É±íÊý¾ÝÅäÖã¡ ID=%s" % compoundID) return makeIDList = ipyData.GetMakeID() unfixedItemIDList = ipyData.GetUnfixedItemID() fixedItemIDList = ipyData.GetFixedItemID() fixedItemCountList = ipyData.GetFixedItemCount() makeItemID = random.choice(makeIDList) # ´Ó¿ÉºÏ³ÉÎïÆ·ÁбíÀïËæ»úÒ»¸ö makeItemData = GameWorld.GetGameData().GetItemByTypeID(makeItemID) if not makeItemData: GameWorld.ErrLog("²»´æÔڸúϳÉÎïÆ·! makeItemID=%s" % makeItemID) return if not ItemCommon.CheckJob(curPlayer, makeItemData): if makeItemData.GetType() in [ChConfig.Def_ItemType_retPeerlessWeapon, ChConfig.Def_ItemType_retPeerlessWeapon2]: PlayerControl.NotifyCode(curPlayer, "ItemCompoundJoblimit") return packType = ChConfig.GetItemPackType(makeItemData, IPY_GameWorld.rptItem) GameWorld.DebugLog("makeItemID=%s,packType=%s" % (makeItemID, packType), playerID) needSpace = int(math.ceil(float(compoundCnt) / makeItemData.GetPackCount())) emptySpace = ItemCommon.GetItemPackSpace(curPlayer, packType, needSpace) #ÑéÖ¤±³°ü¿Õ¼ä if needSpace > emptySpace and packType not in [ShareDefine.rptDogzItem]: #PlayerControl.NotifyCode(curPlayer, "GeRen_lhs_202580") PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_676165", [packType]) GameWorld.DebugLog("±³°ü¿Õ¼ä²»×㣡packType=%s,needSpace=%s > emptySpace=%s" % (packType, needSpace, emptySpace), playerID) return compoundBindCnt = 0 needUnfixedItemCount = ipyData.GetUnfixedItemCount() needMoney = ipyData.GetNeedMoney() successRate = ipyData.GetSuccessRate() successRateMax = ipyData.GetSuccessRateMax() successRateIncrease = ipyData.GetSuccessRateIncrease() # ¿ÉʹÓ÷ǹ̶¨µÀ¾ß »ò ¸½¼ÓµÀ¾ßµÄ µ¥´ÎºÏ³ÉÊýĬÈÏΪ1 if unfixedItemIDList or incRateItemIndexList: compoundCnt = 1 totalNeedMoney = needMoney * compoundCnt if totalNeedMoney and not PlayerControl.HaveMoney(curPlayer, IPY_GameWorld.TYPE_Price_Silver_Money, totalNeedMoney): GameWorld.DebugLog("»õ±Ò²»×ãºÏ³É! totalNeedMoney=%s" % totalNeedMoney, playerID) return itemPack = curPlayer.GetItemManager().GetPack(packType) itemExpireTime = 0 # ¼ì²é²»¹Ì¶¨ÏûºÄµÀ¾ß if unfixedItemIDList: unfixedItem = GameWorld.GetGameData().GetItemByTypeID(unfixedItemIDList[0]) if not unfixedItem: return unfixedItemCostInfo = __CheckUnfixedItem(curPlayer, compoundID, makeItemData, itemPack, unfixedItemIndexList, unfixedItemIDList, needUnfixedItemCount) if not unfixedItemCostInfo: return unfixedItemCostList, expireTime = unfixedItemCostInfo if expireTime: itemExpireTime = expireTime if not itemExpireTime else min(itemExpireTime, expireTime) # ¼ì²é¹Ì¶¨ÏûºÄµÀ¾ß if fixedItemIDList: fixedItemInfo = __CheckFixedItem(playerID, compoundID, itemPack, fixedItemIndexList, fixedItemIDList, fixedItemCountList, compoundCnt) if not fixedItemInfo: return fixedItemIndexDict, fixedItemNeedCntDict, compoundBindCnt, expireTime = fixedItemInfo if expireTime: itemExpireTime = expireTime if not itemExpireTime else min(itemExpireTime, expireTime) # ¼ì²éÌáÉý¸ÅÂʵÀ¾ß incRateItemCostList, needIncRateItemCount, incRate = [], 0, 0 if successRateIncrease and len(successRateIncrease) == 3 and incRateItemIndexList: incRateItemID, needIncRateItemCount, incRate = successRateIncrease incRateItemInfo = __CheckIncRateItem(playerID, compoundID, itemPack, incRateItemIndexList, incRateItemID, needIncRateItemCount) if not incRateItemInfo: return incRateItemCostList, expireTime = incRateItemInfo if expireTime: itemExpireTime = expireTime if not itemExpireTime else min(itemExpireTime, expireTime) # ¿ÛÍ­Ç® if totalNeedMoney: PlayerControl.PayMoney(curPlayer, IPY_GameWorld.TYPE_Price_Silver_Money, totalNeedMoney, ChConfig.Def_Cost_ItemProduce, {ChConfig.Def_Cost_Reason_SonKey:makeItemID, "CompoundCount":compoundCnt}) drDict = {"CompoundID":compoundID, "MakeItemID":makeItemID, "CompoundCount":compoundCnt, "itemExpireTime":itemExpireTime, "PackType":packType} makeItemBind = False # ¿Û²»¹Ì¶¨ÏûºÄÎïÆ· if unfixedItemIDList: bindUnfixedIndexList, unbindUnfixedIndexList = unfixedItemCostList hasBind = ItemCommon.ReduceItem(curPlayer, itemPack, bindUnfixedIndexList + unbindUnfixedIndexList, needUnfixedItemCount, False, ChConfig.ItemDel_ItemCompound, drDict) makeItemBind = True if hasBind else makeItemBind # ¿Û¹Ì¶¨ÏûºÄÎïÆ· if fixedItemIDList: for fixedItemID, countInfo in fixedItemNeedCntDict.items(): delBindCnt, delUnBindCnt = countInfo bindFixedIndexList, unbindFixedIndexList = fixedItemIndexDict[fixedItemID] if delBindCnt: makeItemBind = True ItemCommon.ReduceItem(curPlayer, itemPack, bindFixedIndexList, delBindCnt, False, ChConfig.ItemDel_ItemCompound, drDict) if delUnBindCnt: ItemCommon.ReduceItem(curPlayer, itemPack, unbindFixedIndexList, delUnBindCnt, False, ChConfig.ItemDel_ItemCompound, drDict) # ¿ÛÌáÉý¸ÅÂʵÀ¾ß if incRateItemCostList: bindIncRateItemIndexList, unBindIncRateItemIndexList = incRateItemCostList hasBind = ItemCommon.ReduceItem(curPlayer, itemPack, bindIncRateItemIndexList + unBindIncRateItemIndexList, needIncRateItemCount, False, ChConfig.ItemDel_ItemCompound, drDict) if compoundCnt == 1 and makeItemBind: compoundBindCnt = 1 # ¸øºÏ³ÉÎïÆ· totalSuccRate = successRate + incRate if successRateMax: totalSuccRate = min(successRateMax, totalSuccRate) GameWorld.DebugLog("ºÏ³É³É¹¦ÂÊ: successRate=%s,incRate=%s,successRateMax=%s,totalSuccRate=%s" % (successRate, incRate, successRateMax, totalSuccRate), playerID) # ºÏ³É³É¹¦ maxRateValue = ShareDefine.Def_MaxRateValue randValue = random.randint(1, maxRateValue) canHappen = randValue <= totalSuccRate GameWorld.DebugLog("canHappen=%s,randValue=%s,totalSuccRate=%s,maxRateValue=%s" % (canHappen, randValue, totalSuccRate, maxRateValue), playerID) #if drDict: # DataRecordPack.SendEventPack("ItemCompound_Liantai", drDict, curPlayer) # ²»Êǰٷְٳɹ¦µÄ¼Ç¼ºÏ³ÉÁ÷Ïò if successRate != maxRateValue: drDict = {"PlayerID":curPlayer.GetPlayerID(), "AccID":curPlayer.GetAccID(), "ID":compoundID, "MakeItemID":makeItemID, "IsSuccess":canHappen, "RateInfo":{"totalSuccRate":"%s(%s+%s)" % (totalSuccRate, successRate, incRate), "randValue":randValue, "maxRateValue":maxRateValue}, "PackType":packType, } DataRecordPack.SendEventPack("ItemCompound", drDict, curPlayer) if canHappen: GameWorld.DebugLog("ºÏ³É³É¹¦: makeItemID=%s,compoundCnt=%s,compoundBindCnt=%s,itemExpireTime=%s" % (makeItemID, compoundCnt, compoundBindCnt, itemExpireTime), playerID) userData = GiveNewCompoundItem(curPlayer, packType, makeItemID, compoundCnt, compoundBindCnt, itemExpireTime) msgMark = ipyData.GetSysMark() paramType = ipyData.GetSysMarkParamType() if msgMark not in ['0', '', '-']: if paramType == 2 and fixedItemIDList and fixedItemCountList: PlayerControl.WorldNotify(0, msgMark, [curPlayer.GetName(), fixedItemCountList[0], fixedItemIDList[0], makeItemID, userData]) else: PlayerControl.WorldNotify(0, msgMark, [curPlayer.GetName(), makeItemID, userData]) # ֪ͨºÏ³É³É¹¦ ItemCommon.SyncMakeItemAnswer(curPlayer, ShareDefine.Def_mitItemCompound, ChConfig.Def_ComposeState_Sucess, makeItemID) #³É¹¦ºÏ³É1¸öÎïÆ·³É¾Í PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_CompoundItemEx, compoundCnt, [makeItemID]) #ºÏ³ÉX½×XÑÕÉ«XÐǼ¶ÒÔÉÏ×°±¸, ÐǼ¶¸ÄΪװ±¸Î»ÁË£¬ÔÝʱûÓÐÓã¬ÆÁ±Î #classLV = ItemCommon.GetItemClassLV(makeItemData) #itemColor = makeItemData.GetItemColor() #itemQuality = makeItemData.GetItemQuality() #PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_CompoundEquip, compoundCnt, [classLV, itemColor, itemQuality]) # ºÏ³Éʧ°Ü else: GameWorld.DebugLog("ºÏ³Éʧ°Ü£¡") ItemCommon.SyncMakeItemAnswer(curPlayer, ShareDefine.Def_mitItemCompound, ChConfig.Def_ComposeState_Fail, 0) #curPlayer.Sync_MakeItemAnswer(ShareDefine.Def_mitItemCompound, ChConfig.Def_ComposeState_Fail) # ×°±¸ºÏ³ÉÊôÐÔÖ§³Ö... ´ýÀ©Õ¹ # ºÏ³ÉÁ÷Ïò¼Ç¼µÈ #DataRecordPack.DR_EquipCompound(curPlayer, "EquipCompound_NewItem", newItemID, 1, recordData) return def __CheckUnfixedItem(curPlayer, compoundID, makeItemData, itemPack, unfixedItemIndexList, unfixedItemIDList, needUnfixedItemCount): ## ¼ì²é²»¹Ì¶¨ÏûºÄµÀ¾ß, Ö»Òª¿Í»§¶ËÌá½»µÄÊý¾ÝÓв»·ûºÏÒªÇóµÄ£¬ÔòÖ±½Ó·µ»Ø None expireTime = 0 unfixedItemTotalCount = 0 unfixedItemCostList = [[], []] # [[°ó¶¨Ë÷Òý], [·Ç°ó¶¨Ë÷Òý]] maxPackCount = itemPack.GetCount() playerID = curPlayer.GetPlayerID() #makeItemID = makeItemData.GetItemTypeID() for index in unfixedItemIndexList: if index >= maxPackCount: GameWorld.Log("¸ÃÎïÆ·¸ñ×ÓË÷Òý²»´æÔÚ!ÎÞ·¨ºÏ³É£¡index=%s,maxPackCount=%s" % (index, maxPackCount), playerID) return curItem = itemPack.GetAt(index) if not __CheckItemCanUseCompound(playerID, index, curItem): GameWorld.Log("¸ÃÎïÆ·²»¿ÉʹÓÃ!ÎÞ·¨ºÏ³É! ID=%s,index=%s" % (compoundID, index), playerID) return itemID = curItem.GetItemTypeID() if itemID not in unfixedItemIDList: GameWorld.Log("¸ÃÎïÆ·²»¿ÉÓÃÓںϳÉÄ¿±êÎïÆ·!ID=%s,index=%s,itemID=%s not in unfixedItemIDList=%s" % (compoundID, index, itemID, unfixedItemIDList), playerID) return isExpireItem, remainingTime = ItemCommon.GetItemRemainingTime(curItem) if isExpireItem: if not remainingTime: GameWorld.Log("²»¹Ì¶¨ÏûºÄµÀ¾ßʱЧÎïÆ·ÒÑʧЧ£¬ÎÞ·¨ºÏ³É! index=%s,itemID=%s" % (index, itemID), playerID) return expireTime = remainingTime if not expireTime else min(expireTime, remainingTime) isBind = curItem.GetIsBind() itemCount = curItem.GetCount() unfixedItemTotalCount += itemCount unfixedItemCostList[0].append(index) if isBind else unfixedItemCostList[1].append(index) if unfixedItemTotalCount < needUnfixedItemCount: GameWorld.Log("²»¹Ì¶¨ÏûºÄµÀ¾ß²»×㣬ÎÞ·¨ºÏ³É!ID=%s,unfixedItemIDList=%s,needUnfixedItemCount=%s > unfixedItemTotalCount=%s" % (compoundID, unfixedItemIDList, needUnfixedItemCount, unfixedItemTotalCount), playerID) return return unfixedItemCostList, expireTime def __CheckFixedItem(playerID, compoundID, itemPack, fixedItemIndexList, fixedItemIDList, fixedItemCountList, compoundCnt): ## ¼ì²é¹Ì¶¨ÏûºÄµÀ¾ß, Ö»Òª¿Í»§¶ËÌá½»µÄÊý¾ÝÓв»·ûºÏÒªÇóµÄ£¬ÔòÖ±½Ó·µ»Ø None maxPackCount = itemPack.GetCount() fixedItemIndexDict = {} # {itemID:[[°ó¶¨Ë÷Òý], [·Ç°ó¶¨Ë÷Òý]], ...} fixedItemCntDict = {} # {itemID:[°ó¶¨¸öÊý, ·Ç°ó¶¨¸öÊý], ...} if len(fixedItemIDList) != len(fixedItemCountList): GameWorld.Log("¹Ì¶¨ÏûºÄÅäÖôíÎó!ÎÞ·¨ºÏ³É£¡fixedItemIDList=%s,fixedItemCountList=%s" % (fixedItemIDList, fixedItemCountList), playerID) return expireTime = 0 for index in fixedItemIndexList: if index >= maxPackCount: GameWorld.Log("¸ÃÎïÆ·¸ñ×ÓË÷Òý²»´æÔÚ!ÎÞ·¨ºÏ³É£¡index=%s,maxPackCount=%s" % (index, maxPackCount), playerID) return curItem = itemPack.GetAt(index) if not __CheckItemCanUseCompound(playerID, index, curItem): GameWorld.Log("¸ÃÎïÆ·²»¿ÉʹÓÃ!ÎÞ·¨ºÏ³É! ID=%s,index=%s" % (compoundID, index), playerID) return fixedItemID = curItem.GetItemTypeID() if fixedItemID not in fixedItemIDList: GameWorld.Log("¸ÃÎïÆ·²»¿ÉÓÃÓںϳÉÄ¿±êÎïÆ·!ID=%s,index=%s,fixedItemID=%s not in fixedItemIDList=%s" % (compoundID, index, fixedItemID, fixedItemIDList), playerID) return isExpireItem, remainingTime = ItemCommon.GetItemRemainingTime(curItem) if isExpireItem: if not remainingTime: GameWorld.Log("¹Ì¶¨ÏûºÄµÀ¾ßʱЧÎïÆ·ÒÑʧЧ£¬ÎÞ·¨ºÏ³É! index=%s,fixedItemID=%s" % (index, fixedItemID), playerID) return expireTime = remainingTime if not expireTime else min(expireTime, remainingTime) isBind = curItem.GetIsBind() itemCount = curItem.GetCount() bindIndex = 0 if isBind else 1 fixedItemCntList = fixedItemCntDict.get(fixedItemID, [0, 0]) fixedItemCntList[bindIndex] += itemCount fixedItemCntDict[fixedItemID] = fixedItemCntList fixedItemIndexinfoList = fixedItemIndexDict.get(fixedItemID, [[], []]) fixedItemIndexinfoList[bindIndex].append(index) fixedItemIndexDict[fixedItemID] = fixedItemIndexinfoList GameWorld.DebugLog("¹Ì¶¨ÏûºÄÎïÆ·IDË÷Òý:%s, ¸öÊý[°ó,²»°ó]:%s" % (fixedItemIndexDict, fixedItemCntDict)) # ×°±¸¡¢³á°òºÏ³ÉÓÅÏÈÑ¡Ôñ²»°ó¶¨£» µÀ¾ß¡¢ÃÅÆ±ºÏ³ÉÓÅÏÈÑ¡Ôñ°ó¶¨£¨³ÌÐò£© # ÒòΪװ±¸¡¢³á°òĬÈÏÖ»ÄܺϳÉ1¸ö£¬ËùÒÔÈ«ÓÉǰ¶ËÑ¡ÔñµÄ²ÄÁÏÀ´¾ö¶¨°ó¶¨Óë·ñ # ÕâÀïÖ»´¦ÀíµÀ¾ßÀ࣬ĬÈÏÓÅÏÈ°ó¶¨ # ÏÈͳ¼ÆÇ°¶ËÌá½»µÄ²ÄÁÏË÷Òý×ܲÄÁÏÊý¿ÉºÏ³ÉµÄ×ÜÊý canCompoundBindCount = -1 # ×ܿɺϳɴ¿°ó¸öÊý, ¶àÖÖ²ÄÁÏÈ¡×îСµÄÄǸö canCompoundUnBindCount = -1 # ×ܿɺϳɴ¿·Ç°ó¸öÊý, ¶àÖÖ²ÄÁÏÈ¡×îСµÄÄǸö for index, fixedItemID in enumerate(fixedItemIDList): needCount = fixedItemCountList[index] totalNeedCount = needCount * compoundCnt bindCnt, unBindCnt = fixedItemCntDict.get(fixedItemID, [0, 0]) itemTotalCnt = bindCnt + unBindCnt if itemTotalCnt < totalNeedCount: GameWorld.Log("¹Ì¶¨ÏûºÄµÀ¾ß²»×㣬ÎÞ·¨ºÏ³É!ID=%s,fixedItemID=%s,totalNeedCount=%s*%s(%s) > itemTotalCnt=%s" % (compoundID, fixedItemID, needCount, compoundCnt, totalNeedCount, itemTotalCnt), playerID) return if canCompoundBindCount == -1: canCompoundBindCount = bindCnt / needCount else: canCompoundBindCount = min(canCompoundBindCount, bindCnt / needCount) if canCompoundUnBindCount == -1: canCompoundUnBindCount = unBindCnt / needCount else: canCompoundUnBindCount = min(canCompoundUnBindCount, unBindCnt / needCount) canCompoundBindCount = max(0, canCompoundBindCount) canCompoundUnBindCount = max(0, canCompoundUnBindCount) # °ó¶¨ÓÅÏÈ bindFirst = True compoundBindCnt = 0 compoundUnBindCnt = 0 lackCnt = 0 # ´¿µÄ¹» if (canCompoundBindCount + canCompoundUnBindCount) >= compoundCnt: if bindFirst: compoundBindCnt = min(compoundCnt, canCompoundBindCount) compoundUnBindCnt = compoundCnt - compoundBindCnt else: compoundUnBindCnt = min(compoundCnt, canCompoundUnBindCount) compoundBindCnt = compoundCnt - compoundUnBindCnt else: compoundUnBindCnt = canCompoundUnBindCount compoundBindCnt = canCompoundBindCount lackCnt = compoundCnt - compoundUnBindCnt - compoundBindCnt GameWorld.DebugLog("×ܿɺϳÉ: ´¿°ó=%s, ´¿²»°ó=%s, »¹²î=%s" % (canCompoundBindCount, canCompoundUnBindCount, lackCnt)) compoundBindCnt += lackCnt # ·Ç´¿µÄ¶¼Áбí°ó¶¨Êý GameWorld.DebugLog("×îÖպϳÉ: °ó=%s, ²»°ó=%s" % (compoundBindCnt, compoundUnBindCnt)) fixedItemNeedCntDict = {} # {itemID:[¿Û³ý°ó¶¨¸öÊý, ¿Û³ý·Ç°ó¶¨¸öÊý], ...} for index, fixedItemID in enumerate(fixedItemIDList): needCount = fixedItemCountList[index] totalNeedCount = needCount * compoundCnt bindCnt, unBindCnt = fixedItemCntDict.get(fixedItemID, [0, 0]) costBindCnt = min(bindCnt, compoundBindCnt * needCount) costUnBindCnt = totalNeedCount - costBindCnt fixedItemNeedCntDict[fixedItemID] = [costBindCnt, costUnBindCnt] costTotalCnt = costBindCnt + costUnBindCnt if costTotalCnt < totalNeedCount: GameWorld.ErrLog("×îÖÕ¼ÆËãÏûºÄ×ÜÊýÓëʵ¼ÊËùÐè²»·û!ÎÞ·¨ºÏ³É!costBindCnt(%s) + costUnBindCnt(%s)=%s < totalNeedCount(%s)" % (costBindCnt, costUnBindCnt, costTotalCnt, totalNeedCount)) return GameWorld.DebugLog("×îÖÕÏûºÄ²ÄÁϸöÊý: %s" % (fixedItemNeedCntDict)) return fixedItemIndexDict, fixedItemNeedCntDict, compoundBindCnt, expireTime def __CheckIncRateItem(playerID, compoundID, itemPack, incRateItemIndexList, incRateItemID, needIncRateItemCount): ## ¼ì²éÌáÉý¸ÅÂʵÀ¾ß, Ö»Òª¿Í»§¶ËÌá½»µÄÊý¾ÝÓв»·ûºÏÒªÇóµÄ£¬ÔòÖ±½Ó·µ»Ø None expireTime = 0 incRateItemTotalCount = 0 incRateItemCostList = [[], []] # [[°ó¶¨Ë÷Òý], [·Ç°ó¶¨Ë÷Òý]] maxPackCount = itemPack.GetCount() for index in incRateItemIndexList: if index >= maxPackCount: GameWorld.Log("¸ÃÎïÆ·¸ñ×ÓË÷Òý²»´æÔÚ!ÎÞ·¨ºÏ³É£¡index=%s,maxPackCount=%s" % (index, maxPackCount), playerID) return curItem = itemPack.GetAt(index) if not __CheckItemCanUseCompound(playerID, index, curItem): GameWorld.Log("¸ÃÎïÆ·²»¿ÉʹÓÃ!ÎÞ·¨ºÏ³É! ID=%s,index=%s" % (compoundID, index), playerID) return itemID = curItem.GetItemTypeID() if itemID != incRateItemID: GameWorld.Log("¸ÃÎïÆ·²»¿ÉÓÃÓÚÌáÉýºÏ³ÉÄ¿±êÎïÆ·¸ÅÂÊ!ID=%s,index=%s,itemID=%s != incRateItemID=%s" % (compoundID, index, itemID, incRateItemID), playerID) return isExpireItem, remainingTime = ItemCommon.GetItemRemainingTime(curItem) if isExpireItem: if not remainingTime: GameWorld.Log("ÌáÉý¸ÅÂÊʱЧÎïÆ·ÒÑʧЧ£¬ÎÞ·¨ºÏ³É! index=%s,itemID=%s" % (index, itemID), playerID) return expireTime = remainingTime if not expireTime else min(expireTime, remainingTime) isBind = curItem.GetIsBind() itemCount = curItem.GetCount() incRateItemTotalCount += itemCount incRateItemCostList[0].append(index) if isBind else incRateItemCostList[1].append(index) if incRateItemTotalCount < needIncRateItemCount: GameWorld.Log("ÌáÉý¸ÅÂÊÏûºÄµÀ¾ß²»×㣬ÎÞ·¨ºÏ³É!ID=%s,incRateItemID=%s,needIncRateItemCount=%s > incRateItemTotalCount=%s" % (compoundID, incRateItemID, needIncRateItemCount, incRateItemTotalCount), playerID) return return incRateItemCostList, expireTime def __CheckItemCanUseCompound(playerID, index, curItem): if not ItemCommon.CheckItemCanUse(curItem): GameWorld.DebugLog("¸ÃÎïÆ·²»¿ÉʹÓÃ!ÎÞ·¨ºÏ³É! index=%s" % (index), playerID) return # ÓÐÏâǶ±¦Ê¯£¬Ì××°ÊôÐÔ£¬Ï´Á·ÊôÐÔµÄ×°±¸ÎÞ·¨×÷ΪºÏ³É²ÄÁÏʹÓà if ItemCommon.CheckHasStone(curItem): GameWorld.DebugLog("¸ÃÎïÆ·ÓÐÏâǶ±¦Ê¯!ÎÞ·¨ºÏ³É! index=%s" % (index), playerID) return if curItem.GetIsSuite(): GameWorld.DebugLog("¸ÃÎïÆ·ÎªÌ××°!ÎÞ·¨ºÏ³É! index=%s" % (index), playerID) return # Ï´Á·ÊôÐÔ´ýÌí¼Ó... return True ## ¸øÓèкϳɵÄÎïÆ· # @param curPlayer: Íæ¼Ò # @param newItem: ÐÂÎïÆ· # @param itemCount: ºÏ³ÉÊýÁ¿ # @return None def GiveNewCompoundItem(curPlayer, packType, newItemID, itemCount, compoundBindCnt, itemExpireTime): compoundUnBindCnt = itemCount - compoundBindCnt if compoundBindCnt > 0: userData = __GivePlayerCompoundItem(curPlayer, packType, newItemID, compoundBindCnt, True, itemExpireTime) if compoundUnBindCnt > 0: userData = __GivePlayerCompoundItem(curPlayer, packType, newItemID, compoundUnBindCnt, False, itemExpireTime) if not userData: return "" return userData def __GivePlayerCompoundItem(curPlayer, packType, newItemID, itemCount, isBind, expireTime): playerID = curPlayer.GetPlayerID() curSingleItem = ItemControler.GetOutPutItemObj(newItemID, itemCount, False, expireTime, curPlayer=curPlayer) if not curSingleItem: GameWorld.ErrLog("´´ÔìÎïÆ·Ê§°Ü, give item itemid:%s,count:%s" % (newItemID, itemCount), playerID) return userData = curSingleItem.GetUserData() if not ItemControler.PlayerItemControler(curPlayer).PutInItem(packType, curSingleItem, event=[ChConfig.ItemGive_ItemCompound, False, {}]): GameWorld.ErrLog("¸øºÏ³ÉÎïÆ·Ê§°Ü, give item itemid:%s,count:%s" % (newItemID, itemCount), playerID) curSingleItem.Clear() return return userData #// A3 13 ÎïÆ·²ð½â #tagCMItemDecompound # #struct tagCMItemDecompound #{ # tagHead Head; # BYTE Index; // ²ð½âÎïÆ·ËùÔÚ±³°üË÷Òý #}; def OnItemDecompound(index, clientData, tick): curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index) playerID = curPlayer.GetPlayerID() decompoundItemIndex = clientData.Index GameWorld.DebugLog("Íæ¼Ò²ð½âÎïÆ·: decompoundItemIndex=%s" % decompoundItemIndex, playerID) itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem) if decompoundItemIndex < 0 or decompoundItemIndex >= itemPack.GetCount(): return curEquip = itemPack.GetAt(decompoundItemIndex) if not ItemCommon.CheckItemCanUse(curEquip): return attrCount = curEquip.GetUserAttrCount(ShareDefine.Def_IudetItemDecompound) if not attrCount: GameWorld.DebugLog(" ¸ÃÎïÆ·Ã»ÓмǼ²ð½âÎïÆ·ÐÅÏ¢£¬ÎÞ·¨²ð½â£¡", playerID) return giveItemList = [] giveEquipID = curEquip.GetUserAttrByIndex(ShareDefine.Def_IudetItemDecompound, 0) if giveEquipID: giveItemList.append([giveEquipID, 1, curEquip.GetIsBind()]) if attrCount > 1: for i in range(1, attrCount)[::3]: if i + 3 > attrCount: break itemID = curEquip.GetUserAttrByIndex(ShareDefine.Def_IudetItemDecompound, i) itemCount = curEquip.GetUserAttrByIndex(ShareDefine.Def_IudetItemDecompound, i + 1) isBind = curEquip.GetUserAttrByIndex(ShareDefine.Def_IudetItemDecompound, i + 2) giveItemList.append([itemID, itemCount, isBind]) needSpace = len(giveItemList) emptySpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, needSpace) #ÑéÖ¤±³°ü¿Õ¼ä if needSpace > emptySpace: PlayerControl.NotifyCode(curPlayer, "GeRen_lhs_202580") return decompoundItemNoteDict = ItemCommon.GetItemNoteDict(curEquip, curEquip.GetCount()) # ɾ³ý²ð½âµÄÎïÆ· saveDataDict = {"giveItemList":giveItemList} ItemCommon.DelItem(curPlayer, curEquip, curEquip.GetCount(), False, "ItemDecompound", saveDataDict, isForceDR=True) # ·µ»¹ÎïÆ· for itemID, itemCount, isBind in giveItemList: ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, 0, [IPY_GameWorld.rptItem], event=["ItemDecompound", True, {"decompoundItemNoteDict":decompoundItemNoteDict}]) GameWorld.Log("²ð½âÎïÆ·³É¹¦: decompoundItemNoteDict=%s" % str(decompoundItemNoteDict), playerID) GameWorld.Log(" giveItemList=%s" % str(giveItemList), playerID) return