1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package PyMongoDB.GMToolLogicProcess.Commands.GMT_PlayerItemInfo
#
# @todo:²é¿´Íæ¼ÒÎïÆ·
# @author hxp
# @date 2025-12-12
# @version 1.0
#
# ÏêϸÃèÊö: ²é¿´Íæ¼ÒÎïÆ·
#
#-------------------------------------------------------------------------------
#"""Version = 2025-12-12 15:00"""
#-------------------------------------------------------------------------------
 
import GMCommon
from Collections.CollectionDefine import (UCN_RoleItem)
#from Collections import (DataServerPlayerData)
import IPY_GameWorld
import ShareDefine
import PyGameData
import GameWorld
 
# ËùÓб³°ü
ShowAllPack = -1
 
## ÊÕµ½gmÃüÁîÖ´ÐÐ
# @param gmCmdDict:gmÃüÁî×Öµä
# @return None 
def OnExec(gmCmdDict):
    
    from GMToolLogicProcess import ProjSpecialProcess
    Result, curPlayer = ProjSpecialProcess.GMCmdPlayerValidation(gmCmdDict, False)
    
    packIndex = GameWorld.ToIntDef(gmCmdDict.get(GMCommon.Def_GMKey_PackIndex, ''))
    if packIndex == ShowAllPack:
        # Ôݲ»Ìṩ²éѯËùÓеÄÎïÆ·
        return GMCommon.Def_ParamErr, "Not allowed to query all package items."
    
    if packIndex < IPY_GameWorld.rptDeleted or packIndex > ShareDefine.rptMax:
        return GMCommon.Def_ParamErr, "packType error."
    
    if Result == GMCommon.Def_PlayerOfLine:
        dbPlayer = curPlayer
        itemList = __getPlayerItemByDB(dbPlayer, packIndex)
        
    elif Result == GMCommon.Def_Success:
        itemList = __getPlayerItemByPlayer(curPlayer, packIndex)
        
    else:
        return Result
    
    totalItemCount = len(itemList)
    resultMsg = {"PackIndex":packIndex, "TotalItemCount":totalItemCount, "ItemList":itemList}
    # ²»´óÓëword
    #if len(str(resultMsg)) > 65000:
    #    return GMCommon.Def_MaxLimit, ''
    return GMCommon.Def_Success, resultMsg
 
def __getPlayerItemByPlayer(curPlayer, packIndex):
    ## ´ÓÔÚÏßÈ¡
    if not curPlayer:
        return []
    
    itemPack = curPlayer.GetItemManager().GetPack(packIndex)
    itemList = []
    for index in range(itemPack.GetCount()):
        curItem = itemPack.GetAt(index)
        if curItem == None or curItem.IsEmpty():
            continue
        curItemInfo = {"ItemGUID":curItem.GetGUID(),
                       "ItemTypeID":curItem.GetItemTypeID(),
                       "CreateTime":curItem.GetCreateTime(),
                       "ItemPlaceIndex":curItem.GetItemPlaceIndex()
                       }
        if curItem.GetSuiteID():        
            curItemInfo["IsSuite"] = 1
        if curItem.GetCount() > 1:
            curItemInfo["Count"] = curItem.GetCount()
        if curItem.GetUserData() not in ["", "{}"]:
            curItemInfo["UserData"] = curItem.GetUserData()
        if curItem.GetIsBind():
            curItemInfo["IsBind"] = curItem.GetIsBind()
        if curItem.GetRemainHour():
            curItemInfo["RemainHour"] = curItem.GetRemainHour()
        if curItem.GetGearScore():
            curItemInfo["GearScore"] = curItem.GetGearScore()
        itemList.append(curItemInfo)
        
    return itemList
 
def __getPlayerItemByDB(dbPlayer, packIndex):
    if not dbPlayer:
        return []
    
    userdb = PyGameData.g_usrCtrlDB.db
    
    # »ñµÃÍæ¼ÒÎïÆ·
    itemCollection = userdb[UCN_RoleItem]
    itemFind = itemCollection.find({'PlayerID':dbPlayer.PlayerID})
    
    itemList = []
    # ÎÞÎïÆ·
    if itemFind.count() > 0:
        itemInfo = itemFind[0]
        # ±éÀúËùÓÐÎïÆ·
        for itemIndex in range(1, itemInfo['Count'] + 1):        
            itemDict = itemInfo.get('%s'%itemIndex, {})
            # ÓÐÖ¸¶¨±³°üÀàÐÍ£¬Ôò¸ù¾Ý±³°üÀàÐ͹ýÂËÎïÆ·
            if packIndex != itemDict['ItemPlaceType']:
                continue
            #    "ItemGUID" : "096389AD-904F-4DAA-B7ED155B8663CE45",
            #    "ItemTypeID" : NumberLong(3901),
            #    "Count" : 100,
            #    "IsBind" : 0,
            #    "UserData" : "{}",
            #    "IsSuite" : 0,
            #    "RemainHour" : 0,
            #    "GearScore" : NumberLong(0),
            #    "CreateTime" : "2019-10-16 20:12:17"
                
            #    "ItemPlaceIndex" : 1,
            #    "PlayerID" : NumberLong(268902),
            #    "ItemPlaceType" : 2,
            #    "UserDataLen" : NumberLong(2),
            #    "IsLocked" : 0,
            #    "SID" : -1135840175,
            #    "VerNO" : NumberLong(1),
            curItemInfo = {}
            for k, v in itemDict.items():
                if k in ["UserDataLen", "ItemPlaceType", "PlayerID", "IsLocked", "SID", "VerNO"]:
                    continue
                if not v or v == "{}":
                    continue
                curItemInfo[k] = v
        
            itemList.append(curItemInfo)
            
    return itemList