RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
Barrows.java
1package com.osroyale.content.activity.impl.barrows;
2
3import com.osroyale.content.activity.Activity;
4import com.osroyale.content.activity.ActivityDeathType;
5import com.osroyale.content.activity.ActivityType;
6import com.osroyale.content.activity.panel.ActivityPanel;
7import com.osroyale.content.dialogue.DialogueFactory;
8import com.osroyale.content.event.impl.NpcInteractionEvent;
9import com.osroyale.content.event.impl.ObjectInteractionEvent;
10import com.osroyale.game.world.World;
11import com.osroyale.game.world.entity.mob.Mob;
12import com.osroyale.game.world.entity.mob.npc.Npc;
13import com.osroyale.game.world.entity.mob.npc.NpcDeath;
14import com.osroyale.game.world.entity.mob.player.Player;
15import com.osroyale.game.world.items.Item;
16import com.osroyale.game.world.position.Area;
17import com.osroyale.game.world.position.Position;
18import com.osroyale.net.packet.out.SendEntityHintArrow;
19import com.osroyale.net.packet.out.SendMessage;
20import com.osroyale.util.Utility;
21
51
52public class Barrows extends Activity {
53
54 private Player player;
55
56 private Npc brotherNpc;
57
58 private Barrows(Player player) {
59 super(10, Mob.DEFAULT_INSTANCE);
60 this.player = player;
61 }
62
63 public static Barrows create(Player player) {
64 Barrows minigame = new Barrows(player);
65 minigame.add(player);
66 return minigame;
67 }
68
69 private void summon(BrotherData brother) {
70 if (player.barrowKills[brother.ordinal()]) {
71 player.dialogueFactory.sendPlayerChat("I have already killed this brother.").execute();
72 return;
73 }
74 if (brotherNpc != null) {
75 player.dialogueFactory.sendPlayerChat("Maybe I should finish killing the other one first.").execute();
76 return;
77 }
78 if (player.hiddenBrother == brother && player.barrowsKillCount != 5) {
79 player.dialogueFactory.sendPlayerChat("I should return when I've killed the others.").execute();
80 return;
81 } else if (player.hiddenBrother == brother && player.barrowsKillCount == 5) {
82 player.dialogueFactory.sendOption("Enter the tunnel.", () -> {
83 player.move(new Position(3551, 9691, 0));
84 }, "No, I'm not ready yet.", () -> {
85 player.dialogueFactory.clear();
86 }).execute();
87 return;
88 }
89 brotherNpc = new Npc(brother.getNpcId(), player.getPosition());
90 add(brotherNpc);
91 brotherNpc.speak("How dare you disturb my rest!");
92 brotherNpc.getCombat().attack(player);
93 brotherNpc.owner = player;
94 player.send(new SendEntityHintArrow(brotherNpc));
95 }
96
97 private void move(Position position) {
98 if (brotherNpc != null && !brotherNpc.isDead()) {
99 remove(brotherNpc);
100 brotherNpc = null;
101 }
102 player.move(position);
103 }
104
105 @Override
106 public void onDeath(Mob mob) {
107 if (mob.isPlayer() && mob.equals(player)) {
108 finish();
109 return;
110 }
111 if (mob.isNpc()) {
112 BrotherData bro = BrotherData.getBarrowsBrother(mob.getNpc());
113 if (bro != null) {
114 brotherNpc = null;
115 player.barrowsKillCount += 1;
116 player.barrowKills[bro.ordinal()] = true;
117 if (player.barrowsKillCount == 1) {
118 player.hiddenBrother = BarrowsUtility.getHiddenBrother(player);
119 }
120 World.schedule(new NpcDeath(mob.getNpc()));
121 }
122 }
123 }
124
125 @Override
126 protected void start() {
127
128 }
129
130 @Override
131 public void finish() {
132 cleanup();
133 remove(player);
134 ActivityPanel.clear(player);
135 }
136
137 @Override
138 public void cleanup() {
139 if (brotherNpc != null) {
140 remove(brotherNpc);
141 }
142 }
143
144 @Override
145 public void onLogout(Player player) {
146 finish();
147 }
148
149 @Override
150 public void onRegionChange(Player player) {
151 if (!Area.inBarrows(player)) {
152 finish();
153 }
154 }
155
156 private void reset() {
157 player.barrowsKillCount = 0;
158 player.barrowKills = new boolean[BrotherData.values().length];
159 player.hiddenBrother = null;
160 update();
161 }
162
163 @Override
164 public void update() {
165 int killed = player.barrowsKillCount;
166 int total = BrotherData.values().length;
167 int percentage = (int) Utility.getPercentageAmount(killed, total);
168 String ahrim = player.barrowKills[BrotherData.AHRIM.ordinal()] ? "@red@Ahrim the Blighted" : "@gre@Ahrim the Blighted";
169 String dharok = player.barrowKills[BrotherData.DHAROK.ordinal()] ? "@red@Dharok the Wretched" : "@gre@Dharok the Wretched";
170 String guthan = player.barrowKills[BrotherData.GUTHAN.ordinal()] ? "@red@Guthan the Infested" : "@gre@Guthan the Infested";
171 String karil = player.barrowKills[BrotherData.KARIL.ordinal()] ? "@red@Karil the Tainted" : "@gre@Karil the Tainted";
172 String torag = player.barrowKills[BrotherData.TORAG.ordinal()] ? "@red@Torag the Corrupted" : "@gre@Torag the Corrupted";
173 String verac = player.barrowKills[BrotherData.VERAC.ordinal()] ? "@red@Verac the Defiled" : "@gre@Verac the Defiled";
174 ActivityPanel.update(player, percentage, "Barrows", new Item(19629, 0), "Killed: <col=FF5500>" + killed + "</col> - Remaining: <col=FF5500>" + (total - killed) + "</col>", ahrim, dharok, guthan, karil, torag, verac);
175 }
176
177 @Override
178 public boolean canTeleport(Player player) {
179 return true;
180 }
181
182 @Override
183 protected boolean clickNpc(Player player, NpcInteractionEvent event) {
184 if (event.getOpcode() == 0 && event.getNpc().id == 1671) {
185 DialogueFactory factory = player.dialogueFactory;
186
187 factory.sendNpcChat(1671, "Hello #name,", "would you like me to reset your barrows?");
188 factory.sendOption("Yes please", () -> {
189 reset();
190 factory.sendNpcChat(1671, "I have reset your barrows!");
191 }, "No thanks", factory::execute);
192 factory.execute();
193 return true;
194 }
195 return false;
196 }
197
198 @Override
199 protected boolean clickObject(Player player, ObjectInteractionEvent event) {
200 int id = event.getObject().getId();
201 switch (id) {
202 case 20973:
203 if (player.barrowsKillCount == 6) {
204 if (player.inventory.getFreeSlots() < 5) {
205 player.dialogueFactory.sendPlayerChat("I should free up some inventory slots first.").execute();
206 return true;
207 }
208 reset();
209 BarrowsUtility.generateRewards(player);
210 player.send(new SendMessage("You have completed the barrows minigame, well done!"));
211 finish();
212 } else if (player.barrowsKillCount == 5) {
213 if (brotherNpc == null) {
214 brotherNpc = new Npc(player.hiddenBrother.getNpcId(), player.getPosition());
215 add(brotherNpc);
216 brotherNpc.speak("How dare you disturb my slumber!");
217 brotherNpc.getCombat().attack(player);
218 brotherNpc.owner = player;
219 player.send(new SendEntityHintArrow(brotherNpc));
220 }
221 return true;
222 }
223 break;
224 case 20667:
225 move(BrotherData.AHRIM.getHillPosition());
226 return true;
227 case 20770:
228 summon(BrotherData.AHRIM);
229 return true;
230 case 20672:
231 move(BrotherData.VERAC.getHillPosition());
232 return true;
233 case 20772:
234 summon(BrotherData.VERAC);
235 return true;
236 case 20668:
237 move(BrotherData.DHAROK.getHillPosition());
238 return true;
239 case 20720:
240 summon(BrotherData.DHAROK);
241 return true;
242 case 20671:
243 move(BrotherData.TORAG.getHillPosition());
244 return true;
245 case 20721:
246 summon(BrotherData.TORAG);
247 return true;
248 case 20669:
249 move(BrotherData.GUTHAN.getHillPosition());
250 return true;
251 case 20722:
252 summon(BrotherData.GUTHAN);
253 return true;
254 case 20670:
255 move(BrotherData.KARIL.getHillPosition());
256 return true;
257 case 20771:
258 summon(BrotherData.KARIL);
259 return true;
260 }
261 return false;
262 }
263
264 @Override
265 public ActivityDeathType deathType() {
266 return ActivityDeathType.NORMAL;
267 }
268
269 @Override
270 public ActivityType getType() {
271 return ActivityType.BARROWS;
272 }
273}
Activity(int cooldown, int instance)
Definition Activity.java:92
static void update(Player player, int amount, String title, String footer, String... strings)
final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2)
final DialogueFactory sendPlayerChat(String... lines)
final DialogueFactory sendNpcChat(int id, String... lines)
static void schedule(Task task)
Definition World.java:284
void speak(String forceChat)
Definition Mob.java:164
static double getPercentageAmount(int progress, int total)
Definition Utility.java:73