Skip to content

ZH TW API UO WaitingForMenu

LIHACHTETAN edited this page Nov 28, 2026 · 3 revisions

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

UO.WaitingForMenu

家 · C# · IDE · UO API · A–Z · 範例 · Languages

C# 簽章

int UO.WaitingForMenu(object? delay);
int UO.WaitingForMenu(object? delay, object? menuCount);
int UO.WaitingForMenu(object? delay, object? menuCount, object? blockMenu);
int UO.WaitingForMenu(object? delay, object? menuCount, object? blockMenu, object? menuName);
int UO.WaitingForMenu(object? delayValue, object? menuCountValue, object? blockMenuValue, object? menuNameValue, object? skillOrSerial);

所需的伺服器選單出現次數是有限的。

參數

  • delay — int 超時(以毫秒為單位),負數變為 0。即使使用0,也會執行一項檢查。
  • delayValue — int 超時(以毫秒為單位),負數變為 0。即使使用0,也會執行一項檢查。
  • menuCount — 可選出現次數,最少1;預設為1。這不是菜單項目的數量。
  • menuCountValue — 可選出現次數,最少1;預設為1。這不是菜單項目的數量。
  • blockMenu — 可選的非零數字,當滿足條件時關閉選單; 0離開了他。
  • blockMenuValue — 可選的非零數字,當滿足條件時關閉選單; 0離開了他。
  • menuName - 可選的精確標題,區分大小寫;空允許任何人。
  • menuNameValue - 可選的精確標題,區分大小寫;空允許任何人。
  • skillOrSerial - 可選的最後一個參數:TriggerWaitAction可以先使用名為serial的技能或物件。預設情況下,0 不執行任何操作。

傳回值

數字標誌int:1 - 至少注意到menuCount不同的出現,並且最後一個具有所需的標題; 0 - 超時。現有的菜單可以立即統計。

行為

  • TriggerWaitAction讀取GetLastMenuIdentity後;新身分增加了計數器。空標識會重置前一個選單的內存,因此在關閉/重新開啟後可以再次計數相同的選單。
  • 僅使用新身分檢查計數邊界。如果 和 匹配,blockMenu 關閉選單。檢查之間 UO.Wait 到 25 ms;標頭由序數而不是子字串檢查。

獨立的 C# 腳本

每個範例都可以儲存為單獨的檔案.csx並在IDE中運行。 UO物件和等待函數提供當前遊戲會話的主機。將演示 serial 名稱、座標和地址替換為您自己的。

簡單範例

將這段程式碼存為獨立的 .csx 檔案執行。參數直接出現在呼叫中;請將範例名稱、serial 和網址替換成自己的值。

將一次呼叫的結果輸出到日誌。數值不會轉換成 bool;若結果是陣列,則顯示元素數量。

var result = UO.WaitingForMenu(3000);
UO.Print("WaitingForMenu: " + Convert.ToString(result));

1。直接呼叫-直接腳本

參數與執行流程:

  • 所需的伺服器選單出現次數是有限的。
UO.Print(UO.WaitingForMenu(3000));

2。明確選項 - 腳本函數

參數與執行流程:

  • TriggerWaitAction讀取GetLastMenuIdentity後;新身分增加了計數器。空標識會重置前一個選單的內存,因此在關閉/重新開啟後可以再次計數相同的選單。
return  RunScenario();
 object? RunScenario()
{
    UO.Print(UO.WaitingForMenu(3000, 1, 1, "Craft"));
    return null;
}

3。完整的輔助函數 - 腳本類

參數與執行流程:

  • 僅使用新身分檢查計數邊界。如果 和 匹配,blockMenu 關閉選單。檢查之間 UO.Wait 到 25 ms;標頭由序數而不是子字串檢查。
return  new ScriptScenario(UO, WaitAsync, Args, Cancellation, Checkpoint).RunScenario();
class ScriptScenario
{
    private readonly global::ClassicUO.CSharp.CSharpGameApi UO;
    private readonly Func<int, Task> WaitAsync;
    private readonly string[] Args;
    private readonly CancellationToken Cancellation;
    private readonly Action Checkpoint;
    public ScriptScenario(global::ClassicUO.CSharp.CSharpGameApi api, Func<int, Task> wait, string[] args, CancellationToken cancellation, Action checkpoint)
    {
        UO = api;
        WaitAsync = wait;
        Args = args;
        Cancellation = cancellation;
        Checkpoint = checkpoint;
    }

     public object? RunScenario()
    {
        var found = UO.WaitingForMenu(3000, 1, 0, "Craft", "lasttarget");
        if (Truth(found))
        {
            UO.Print(UO.GetLastMenuItems());
        }

        return null;
    }

    bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;
}

命令實作

C# 區分大小寫。請使用正確的 UO 名稱。數值旗標應與 0 比較;只有回傳型別為 bool 時才使用 bool。

UO.WaitingForMenu(delay) — UO.WaitingForMenu(Any)

參數: delay (Any)

結果: int / Integer.

呼叫時:

內部實作程式碼,不能作為獨立腳本執行。

public int WaitingForMenu(InjectionValue delay) => WaitingForMenu(delay, InjectionValue.Zero, InjectionValue.Zero, new InjectionValue(string.Empty), InjectionValue.Zero);

UO.WaitingForMenu(delay, menuCount) — UO.WaitingForMenu(Any,Any)

參數: delay (Any), menuCount (Any)

結果: int / Integer.

呼叫時:

內部實作程式碼,不能作為獨立腳本執行。

public int WaitingForMenu(InjectionValue delay, InjectionValue menuCount) => WaitingForMenu(delay, menuCount, InjectionValue.Zero, new InjectionValue(string.Empty), InjectionValue.Zero);

UO.WaitingForMenu(delay, menuCount, blockMenu) — UO.WaitingForMenu(Any,Any,Any)

參數: delay (Any), menuCount (Any), blockMenu (Any)

結果: int / Integer.

呼叫時:

內部實作程式碼,不能作為獨立腳本執行。

public int WaitingForMenu(InjectionValue delay, InjectionValue menuCount, InjectionValue blockMenu) => WaitingForMenu(delay, menuCount, blockMenu, new InjectionValue(string.Empty), InjectionValue.Zero);

UO.WaitingForMenu(delay, menuCount, blockMenu, menuName) — UO.WaitingForMenu(Any,Any,Any,Any)

參數: delay (Any), menuCount (Any), blockMenu (Any), menuName (Any)

結果: int / Integer.

呼叫時:

內部實作程式碼,不能作為獨立腳本執行。

public int WaitingForMenu(InjectionValue delay, InjectionValue menuCount, InjectionValue blockMenu, InjectionValue menuName) => WaitingForMenu(delay, menuCount, blockMenu, menuName, InjectionValue.Zero);

UO.WaitingForMenu(delayValue, menuCountValue, blockMenuValue, menuNameValue, skillOrSerial) — UO.WaitingForMenu(Any,Any,Any,Any,Any)

參數: delayValue (Any), menuCountValue (Any), blockMenuValue (Any), menuNameValue (Any), skillOrSerial (Any)

結果: int / Integer.

呼叫時:

內部實作程式碼,不能作為獨立腳本執行。

public int WaitingForMenu(InjectionValue delayValue, InjectionValue menuCountValue, InjectionValue blockMenuValue, InjectionValue menuNameValue, InjectionValue skillOrSerial)

        {

            int delay = Math.Max(0, NumberConversions.ToInt(delayValue));

            int requiredMenuCount = Math.Max(1, NumberConversions.ToInt(menuCountValue));

            bool blockMenu = NumberConversions.ToInt(blockMenuValue) != 0;

            string expectedName = menuNameValue.ToString() ?? string.Empty;

            DateTime deadline = timeSource.Now.AddMilliseconds(delay);

            string previousIdentity = string.Empty;

            int observedMenuCount = 0;



            TriggerWaitAction(skillOrSerial);



            do

            {

                string identity = bridge.GetLastMenuIdentity() ?? string.Empty;

                if (identity.Length == 0)

                {

                    // Reset between server menus so an identical menu opened again

                    // still counts as a new appearance.

                    previousIdentity = string.Empty;

                }

                else if (!identity.Equals(previousIdentity, StringComparison.Ordinal))

                {

                    previousIdentity = identity;

                    observedMenuCount++;

                    string caption = bridge.GetLastMenuCaption() ?? string.Empty;

                    bool nameMatches = expectedName.Length == 0

                        || caption.Equals(expectedName, StringComparison.Ordinal);

                    if (observedMenuCount >= requiredMenuCount && nameMatches)

                    {

                        if (blockMenu)

                            bridge.CloseMenu();

                        return 1;

                    }

                }



                if (timeSource.Now >= deadline)

                    break;

                bridge.Wait(Math.Min(25, Math.Max(1, delay)));

            }

            while (true);



            return 0;

        }

Clone this wiki locally