Skip to content

ZH TW API UO CountEx

Codex edited this page Oct 17, 2026 · 3 revisions

Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

UO.CountEx

int UO.CountEx(object? objType, object? color, object? container);

計算容器直接內容的物品數量,不搜尋巢狀袋子。地面搜尋也會計入符合條件的角色/NPC,每個算一個。FindDistance、FindVertical 與 Ignore 仍然有效。不會改變 FindItem、FindCount、FindFullQuantity 或 GetFoundItems。

objType 是圖形/type,不是序號;color 是色調。-1 或 0xFFFF 表示任何類型/色調。container 是容器 ID:背包使用 UO.Backpack(),地面使用 UO.Ground()。傳回 int,為 max(1, Amount) 的總和,0 表示沒有符合項目。只計算已收到的內容,不會自動開啟袋子。

範例

int goldUnits = UO.CountEx(0x0EED, -1, UO.Backpack());
UO.Print(goldUnits.ToString());
UO.FindTypeEx(0x0EED, -1, UO.Backpack(), false);
int previousFoundItem = UO.FindItem();
int bandages = UO.CountEx(0x0E21, -1, UO.Backpack());
bool searchPreserved = UO.FindItem() == previousFoundItem;
UO.Print($"{bandages}; {searchPreserved}");
int units = CountBackpackUnits(0x0EED);
UO.Print(units.ToString());

int CountBackpackUnits(int graphic)
{
    return UO.CountEx(graphic, -1, UO.Backpack());
}
var counter = new InventoryCounter(UO);
UO.Print(counter.CountGold().ToString());

class InventoryCounter(ClassicUO.CSharp.CSharpGameApi api)
{
    public int CountGold() => api.CountEx(0x0EED, -1, api.Backpack());
}

實作

ClassicUOInjectionApiBridge.CountDirectItems → MatchesFindIdentity / MatchesFindContainer / MatchesFindMobile.

Clone this wiki locally