| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package Player.RemoteQuery.GY_Query_GMTDelPlayerItem  | 
| #  | 
| # @todo:GM¹¤¾ß¿Û³ýÍæ¼ÒÎïÆ·  | 
| # @author hxp  | 
| # @date 2021-03-18  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: GM¹¤¾ß¿Û³ýÍæ¼ÒÎïÆ·  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #"""Version = 2021-03-18 19:00"""  | 
| #-------------------------------------------------------------------------------  | 
|   | 
| import GMCommon  | 
| import ItemCommon  | 
| import ShareDefine  | 
| import GameWorld  | 
| import ChConfig  | 
|   | 
| ## ÇëÇóÂß¼  | 
| #  @param query_Type ÇëÇóÀàÐÍ  | 
| #  @param query_ID ÇëÇóµÄÍæ¼ÒID  | 
| #  @param packCMDList ·¢°üÃüÁî [ ]  | 
| #  @param tick µ±Ç°Ê±¼ä  | 
| #  @return resultDisc  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷.  | 
| def DoLogic(query_Type, query_ID, packCMDList, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(query_ID)  | 
|       | 
|     if not curPlayer or curPlayer.IsEmpty():  | 
|         return ''  | 
|     orderId, gmCmdDict = packCMDList  | 
|     GameWorld.Log("GY_Query_GMTDelPlayerItem: %s" % gmCmdDict, query_ID)  | 
|     itemID = GameWorld.ToIntDef(gmCmdDict.get("itemID", 0))  | 
|     delItemCount = GameWorld.ToIntDef(gmCmdDict.get("delItemCount", 0))  | 
|       | 
|     Result = GMCommon.Def_Success  | 
|     retMsg = {"itemID":itemID, "delItemCount":delItemCount, "accID":curPlayer.GetAccID()}  | 
|       | 
|     # É¾³ýÎïÆ·  | 
|     _DoGMDelItem(curPlayer, gmCmdDict, itemID, delItemCount, retMsg)  | 
|       | 
|     # ²éѯʣÓàÎïÆ·Ã÷ϸ  | 
|     findItemDict = {}  | 
|     for packIndex in xrange(ShareDefine.rptMax):  | 
|         itemPack = curPlayer.GetItemManager().GetPack(packIndex)  | 
|         if not itemPack:  | 
|             continue  | 
|         itemList = []  | 
|         for index in xrange(itemPack.GetCount()):  | 
|             curItem = itemPack.GetAt(index)  | 
|             if not curItem or curItem.IsEmpty():  | 
|                 continue  | 
|             if curItem.GetItemTypeID() != itemID:  | 
|                 continue  | 
|             itemList.append(_GetItemInfo(curItem))  | 
|         if itemList:  | 
|             findItemDict[str(packIndex)] = itemList  | 
|     retMsg["findItemDict"] = findItemDict  | 
|       | 
|     resultMsg = str([orderId, retMsg, 'GMT_DelPlayerItem', Result])  | 
|     GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(0, 0, 0, 'GMToolResult', resultMsg, len(resultMsg))  | 
|     return ''  | 
|       | 
| def _DoGMDelItem(curPlayer, gmCmdDict, itemID, delItemCount, retMsg):  | 
|       | 
|     delRemark = gmCmdDict.get("delRemark", "")  | 
|     delGUIDInfo = gmCmdDict.get("delGUIDInfo", "")  | 
|     delGUIDInfo = eval(delGUIDInfo) if (delGUIDInfo.startswith("{") and delGUIDInfo.endswith("}")) else {}  | 
|     if not delGUIDInfo:  | 
|         return  | 
|     GameWorld.DebugLog("delGUIDInfo: %s" % delGUIDInfo)  | 
|     succDelItemDict = {}  | 
|     succDelCount = 0  | 
|     for delGUID, delItemInfo in delGUIDInfo.items():  | 
|         packIndex, delIndex = delItemInfo  | 
|         GameWorld.DebugLog("delGUID=%s,packIndex=%s,delIndex=%s" % (delGUID, packIndex, delIndex))  | 
|         itemPack = curPlayer.GetItemManager().GetPack(int(packIndex))  | 
|         if not itemPack:  | 
|             continue  | 
|         if delIndex >= itemPack.GetCount():  | 
|             continue  | 
|         curItem = itemPack.GetAt(delIndex)  | 
|         if not curItem or curItem.IsEmpty():  | 
|             continue  | 
|         if curItem.GetItemTypeID() != itemID:  | 
|             continue  | 
|         if curItem.GetGUID() != delGUID:  | 
|             continue  | 
|           | 
|         remainDelCount = delItemCount - succDelCount # »¹ÐèҪɾ³ýµÄ¸öÊý  | 
|         if remainDelCount <= 0:  | 
|             break  | 
|         curCount = curItem.GetCount()  | 
|         delCnt = min(remainDelCount, curCount)  | 
|         itemInfo = _GetItemInfo(curItem)  | 
|         GameWorld.DebugLog("        delCnt=%s" % delCnt)  | 
|           | 
|         infoDict = {ChConfig.Def_Cost_Reason_SonKey:delRemark}  | 
|         ItemCommon.DelItem(curPlayer, curItem, delCnt, False, "GM", infoDict, isForceDR=True)  | 
|           | 
|         itemInfo["Count"] = "-%s" % delCnt  | 
|         succDelCount += delCnt  | 
|           | 
|         if str(packIndex) not in succDelItemDict:  | 
|             succDelItemDict[str(packIndex)] = []  | 
|         itemList = succDelItemDict[str(packIndex)]  | 
|         itemList.append(itemInfo)  | 
|           | 
|     retMsg["succDelItemDict"] = succDelItemDict  | 
|     retMsg["succDelCount"] = succDelCount  | 
|     return  | 
|   | 
| def _GetItemInfo(curItem):  | 
|     curItemInfo = {"ItemGUID":curItem.GetGUID(),  | 
|                    "ItemTypeID":curItem.GetItemTypeID(),  | 
|                    "ItemName":curItem.GetName().decode(ShareDefine.Def_Game_Character_Encoding).encode(GameWorld.GetCharacterEncoding()),  | 
|                    "Count":curItem.GetCount(),  | 
|                    "UserData":curItem.GetUserData(),  | 
|                    "IsBind":curItem.GetIsBind(),  | 
|                    "IsSuite":1 if curItem.GetSuiteID() else 0,  | 
|                    "RemainHour":curItem.GetRemainHour(),  | 
|                    "GearScore":curItem.GetGearScore(),  | 
|                    "CreateTime":curItem.GetCreateTime(),  | 
|                    "ItemPlaceIndex":curItem.GetItemPlaceIndex()  | 
|                    }  | 
|     return curItemInfo  | 
|   | 
|       | 
|       | 
|       | 
|       |