-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbanking.csx
131 lines (104 loc) · 3.2 KB
/
banking.csx
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
#load "Specs.csx"
#load "common.csx"
#load "container.csx"
#load "area.csx"
using System;
using System.Collections.Generic;
using Infusion;
using Infusion.Commands;
public static class Banking
{
private static Dictionary<Area, Action> commandByArea = new Dictionary<Area, Action>();
public static void OpenBank()
{
var command = GetHouseMenuCommand();
if (command != null)
{
if (OpenBankViaHouseMenu(command))
return;
}
OpenBankViaBanker();
}
public static void OpenBankViaBanker(string bankerName = null)
{
Gump gump;
int failedCount = 0;
do
{
if (!string.IsNullOrEmpty(bankerName))
UO.Say(bankerName + " hi");
else
UO.Say("banker hi");
gump = UO.WaitForGump(true, TimeSpan.FromSeconds(10));
if (gump == null)
{
failedCount++;
if (failedCount > 5)
UO.ClientPrint("Cannot open bank", UO.Me);
}
} while (gump == null);
UO.Wait(1000);
UO.SelectGumpButton("Bankovni sluzby", GumpLabelPosition.After);
UO.WaitForGump();
UO.Wait(1000);
UO.SelectGumpButton("Otevrit banku.", GumpLabelPosition.After);
Common.WaitForContainer();
}
public static bool OpenBankViaHouseMenu(string equipCommand)
=> OpenBankViaHouseMenu(() => UO.Say(equipCommand));
public static bool OpenBankViaHouseMenu(Action command = null)
{
if (command == null)
command = GetHouseMenuCommand();
if (command == null)
{
var menu = UO.Items.Matching(Specs.HouseMenu).OrderByDistance().FirstOrDefault();
if (menu != null)
UO.Use(menu);
else
return false;
}
else
{
command();
}
UO.WaitForGump();
UO.SelectGumpButton("Otevrit banku", GumpLabelPosition.Before);
Common.WaitForContainer();
return true;
}
public static void SetHouseMenuCommand(Area area, string command)
{
SetHouseMenuCommand(area, () => UO.Say(command));
}
public static void SetHouseMenuCommand(Area area, Action command)
{
commandByArea[area] = command;
}
public static Action GetHouseMenuCommand()
{
foreach (var pair in commandByArea)
{
var area = pair.Key;
if (area.InArea())
return pair.Value;
}
return null;
}
}
public class BankContainer : IContainer
{
public ObjectId Id => UO.Me.BankBox.Id;
public Item Item => UO.Me.BankBox;
public bool Contains(Item item)
=> item.ContainerId.HasValue && item.ContainerId.Value == Id;
public void Open()
{
if (UO.Me.BankBox == null || !OpenContainerTracker.IsOpen(UO.Me.BankBox.Id))
{
Banking.OpenBank();
OpenContainerTracker.SetOpen(UO.Me.BankBox.Id);
}
}
}
UO.RegisterCommand("bank-open", Banking.OpenBank);