RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
InterfaceManager.java
1package com.osroyale.game.world.entity.mob.player;
2
3import com.osroyale.Config;
4import com.osroyale.content.store.Store;
5import com.osroyale.content.tradingpost.TradingPost;
6import com.osroyale.game.world.entity.mob.player.exchange.ExchangeSessionType;
7import com.osroyale.net.packet.out.*;
8
40
41public class InterfaceManager {
42
44 private Player player;
45
47 private int main = -1;
48
50 private int overlay = -1;
51
53 private int walkable = -1;
54
56 private int dialogue = -1;
57
58 private int[] sidebars = new int[15];
59
61 InterfaceManager(Player player) {
62 this.player = player;
63 }
64
66 public void open(int identification) {
67 open(identification, true);
68 }
69
71 public void open(int identification, boolean secure) {
72 if (secure) {
73 if (player.isBot || main == identification) {
74 return;
75 }
76
77 if (player.getCombat().inCombat()) {
78 player.send(new SendMessage("You can't do this right now!"));
79 return;
80 }
81
82 if (player.dialogueFactory.isActive() || player.dialogueFactory.isOption()) {
83 player.dialogueFactory.clear();
84 }
85 }
86
87 main = identification;
88 player.movement.reset();
89 player.send(new SendInterface(identification));
90 player.send(new SendString("[CLOSE_MENU]", 0));
91 setSidebar(Config.LOGOUT_TAB, -1);
92 }
93
95 public void openWalkable(int identification) {
96 if (walkable == identification) {
97 return;
98 }
99 walkable = identification;
100 player.send(new SendWalkableInterface(identification));
101 }
102
104 public void openInventory(int identification, int overlay) {
105 if (player.isBot || main == identification && this.overlay == overlay) {
106 return;
107 }
108
109 main = identification;
110 this.overlay = overlay;
111 player.movement.reset();
112 player.send(new SendString("[CLOSE_MENU]", 0));
113 player.send(new SendInventoryInterface(identification, overlay));
114 setSidebar(Config.LOGOUT_TAB, -1);
115
116 }
117
118 public void close(int interfaceId) {
119 if (isInterfaceOpen(interfaceId)) {
120 close();
121 }
122 }
123
125 public void close() {
126 close(true);
127 }
128
130 public void close(boolean walkable) {
131 if (player.isBot) {
132 return;
133 }
134
135 if (player.attributes.has("SHOP")) {
136 Store.closeShop(player);
137 }
138
139 if (player.attributes.is("BANK_KEY")) {
140 player.bank.close();
141 }
142
143 if (player.attributes.is("PRICE_CHECKER_KEY")) {
144 player.priceChecker.close();
145 }
146
147 if (player.attributes.is("TRADE_KEY")) {
148 player.exchangeSession.reset(ExchangeSessionType.TRADE);
149 }
150
151 if (player.attributes.is("DUEL_KEY")) {
152 player.exchangeSession.reset(ExchangeSessionType.DUEL);
153 }
154
155 if (player.attributes.is("DONATOR_DEPOSIT_KEY")) {
156 player.donatorDeposit.close();
157 }
158
159 if(main == TradingPost.BUYING_PAGE_INTERFACE_ID) {
160 player.tradingPost.cleanUp();
161 }
162
163 if (walkable) {
164 openWalkable(-1);
165 }
166
167 main = -1;
168 dialogue = -1;
169 player.dialogueFactory.clear();
170 player.send(new SendRemoveInterface());
171// player.send(new SendString("[CLOSE_MENU]", 0));
172 setSidebar(Config.LOGOUT_TAB, 2449);
173 }
174
175 public void setSidebar(int tab, int id) {
176 if (sidebars[tab] == id && id != -1) {
177 return;
178 }
179 sidebars[tab] = id;
180 player.send(new SendSideBarInterface(tab, id));
181
182 }
183
185 public boolean isInterfaceOpen(int id) {
186 return main == id;
187 }
188
189 public boolean hasAnyOpen(int... ids) {
190 for (int id : ids) {
191 if (main == id)
192 return true;
193 }
194 return false;
195 }
196
198 public boolean isClear() {
199 return main == -1 && dialogue == -1 && walkable == -1;
200 }
201
203 public boolean isMainClear() {
204 return main == -1;
205 }
206
208 public boolean isDialogueClear() {
209 return dialogue == -1;
210 }
211
213 public void setMain(int currentInterface) {
214 this.main = currentInterface;
215 }
216
218 public int getMain() {
219 return main;
220 }
221
223 public int getDialogue() {
224 return dialogue;
225 }
226
228 public void setDialogue(int dialogueInterface) {
229 this.dialogue = dialogueInterface;
230 }
231
233 public int getWalkable() {
234 return walkable;
235 }
236
238 public void setWalkable(int walkableInterface) {
239 this.walkable = walkableInterface;
240 }
241
242 public int getSidebar(int tab) {
243 if (tab > sidebars.length) {
244 return -1;
245 }
246 return sidebars[tab];
247 }
248
249 public boolean isSidebar(int tab, int id) {
250 return tab <= sidebars.length && sidebars[tab] == id;
251 }
252
253 public boolean hasSidebar(int id) {
254 for (int sidebar : sidebars) {
255 if (sidebar == id) {
256 return true;
257 }
258 }
259 return false;
260 }
261}