RuneHive-Game
Loading...
Searching...
No Matches
Barrows.java
Go to the documentation of this file.
1package com.runehive.content.activity.impl.barrows;
2
3import com.runehive.content.activity.Activity;
4import com.runehive.content.activity.ActivityDeathType;
5import com.runehive.content.activity.ActivityType;
6import com.runehive.content.activity.panel.ActivityPanel;
7import com.runehive.content.dialogue.DialogueFactory;
8import com.runehive.content.event.impl.NpcInteractionEvent;
9import com.runehive.content.event.impl.ObjectInteractionEvent;
10import com.runehive.game.world.World;
11import com.runehive.game.world.entity.mob.Mob;
12import com.runehive.game.world.entity.mob.npc.Npc;
13import com.runehive.game.world.entity.mob.npc.NpcDeath;
14import com.runehive.game.world.entity.mob.player.Player;
15import com.runehive.game.world.items.Item;
16import com.runehive.game.world.position.Area;
17import com.runehive.game.world.position.Position;
18import com.runehive.net.packet.out.SendEntityHintArrow;
19import com.runehive.net.packet.out.SendMessage;
20import com.runehive.util.Utility;
21
22public class Barrows extends Activity {
23
24 private Player player;
25
26 private Npc brotherNpc;
27
29 super(10, Mob.DEFAULT_INSTANCE);
30 this.player = player;
31 }
32
33 public static Barrows create(Player player) {
34 Barrows minigame = new Barrows(player);
35 minigame.add(player);
36 return minigame;
37 }
38
39 private void summon(BrotherData brother) {
40 if (player.barrowKills[brother.ordinal()]) {
41 player.dialogueFactory.sendPlayerChat("I have already killed this brother.").execute();
42 return;
43 }
44 if (brotherNpc != null) {
45 player.dialogueFactory.sendPlayerChat("Maybe I should finish killing the other one first.").execute();
46 return;
47 }
48 if (player.hiddenBrother == brother && player.barrowsKillCount != 5) {
49 player.dialogueFactory.sendPlayerChat("I should return when I've killed the others.").execute();
50 return;
51 } else if (player.hiddenBrother == brother && player.barrowsKillCount == 5) {
52 player.dialogueFactory.sendOption("Enter the tunnel.", () -> {
53 player.move(new Position(3551, 9691, 0));
54 }, "No, I'm not ready yet.", () -> {
55 player.dialogueFactory.clear();
56 }).execute();
57 return;
58 }
59 brotherNpc = new Npc(brother.getNpcId(), player.getPosition());
61 brotherNpc.speak("How dare you disturb my rest!");
62 brotherNpc.getCombat().attack(player);
63 brotherNpc.owner = player;
65 }
66
67 private void move(Position position) {
68 if (brotherNpc != null && !brotherNpc.isDead()) {
69 remove(brotherNpc);
70 brotherNpc = null;
71 }
72 player.move(position);
73 }
74
75 @Override
76 public void onDeath(Mob mob) {
77 if (mob.isPlayer() && mob.equals(player)) {
78 finish();
79 return;
80 }
81 if (mob.isNpc()) {
83 if (bro != null) {
84 brotherNpc = null;
85 player.barrowsKillCount += 1;
86 player.barrowKills[bro.ordinal()] = true;
87 if (player.barrowsKillCount == 1) {
88 player.hiddenBrother = BarrowsUtility.getHiddenBrother(player);
89 }
90 World.schedule(new NpcDeath(mob.getNpc()));
91 }
92 }
93 }
94
95 @Override
96 protected void start() {
97
98 }
99
100 @Override
101 public void finish() {
102 cleanup();
103 remove(player);
105 }
106
107 @Override
108 public void cleanup() {
109 if (brotherNpc != null) {
110 remove(brotherNpc);
111 }
112 }
113
114 @Override
115 public void onLogout(Player player) {
116 finish();
117 }
118
119 @Override
121 if (!Area.inBarrows(player)) {
122 finish();
123 }
124 }
125
126 private void reset() {
127 player.barrowsKillCount = 0;
128 player.barrowKills = new boolean[BrotherData.values().length];
129 player.hiddenBrother = null;
130 update();
131 }
132
133 @Override
134 public void update() {
135 int killed = player.barrowsKillCount;
136 int total = BrotherData.values().length;
137 int percentage = (int) Utility.getPercentageAmount(killed, total);
138 String ahrim = player.barrowKills[BrotherData.AHRIM.ordinal()] ? "@red@Ahrim the Blighted" : "@gre@Ahrim the Blighted";
139 String dharok = player.barrowKills[BrotherData.DHAROK.ordinal()] ? "@red@Dharok the Wretched" : "@gre@Dharok the Wretched";
140 String guthan = player.barrowKills[BrotherData.GUTHAN.ordinal()] ? "@red@Guthan the Infested" : "@gre@Guthan the Infested";
141 String karil = player.barrowKills[BrotherData.KARIL.ordinal()] ? "@red@Karil the Tainted" : "@gre@Karil the Tainted";
142 String torag = player.barrowKills[BrotherData.TORAG.ordinal()] ? "@red@Torag the Corrupted" : "@gre@Torag the Corrupted";
143 String verac = player.barrowKills[BrotherData.VERAC.ordinal()] ? "@red@Verac the Defiled" : "@gre@Verac the Defiled";
144 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);
145 }
146
147 @Override
148 public boolean canTeleport(Player player) {
149 return true;
150 }
151
152 @Override
154 if (event.getOpcode() == 0 && event.getNpc().id == 1671) {
155 DialogueFactory factory = player.dialogueFactory;
156
157 factory.sendNpcChat(1671, "Hello #name,", "would you like me to reset your barrows?");
158 factory.sendOption("Yes please", () -> {
159 reset();
160 factory.sendNpcChat(1671, "I have reset your barrows!");
161 }, "No thanks", factory::execute);
162 factory.execute();
163 return true;
164 }
165 return false;
166 }
167
168 @Override
170 int id = event.getObject().getId();
171 switch (id) {
172 case 20973:
173 if (player.barrowsKillCount == 6) {
174 if (player.inventory.getFreeSlots() < 5) {
175 player.dialogueFactory.sendPlayerChat("I should free up some inventory slots first.").execute();
176 return true;
177 }
178 reset();
180 player.send(new SendMessage("You have completed the barrows minigame, well done!"));
181 finish();
182 } else if (player.barrowsKillCount == 5) {
183 if (brotherNpc == null) {
184 brotherNpc = new Npc(player.hiddenBrother.getNpcId(), player.getPosition());
186 brotherNpc.speak("How dare you disturb my slumber!");
187 brotherNpc.getCombat().attack(player);
188 brotherNpc.owner = player;
190 }
191 return true;
192 }
193 break;
194 case 20667:
195 move(BrotherData.AHRIM.getHillPosition());
196 return true;
197 case 20770:
199 return true;
200 case 20672:
201 move(BrotherData.VERAC.getHillPosition());
202 return true;
203 case 20772:
205 return true;
206 case 20668:
207 move(BrotherData.DHAROK.getHillPosition());
208 return true;
209 case 20720:
211 return true;
212 case 20671:
213 move(BrotherData.TORAG.getHillPosition());
214 return true;
215 case 20721:
217 return true;
218 case 20669:
219 move(BrotherData.GUTHAN.getHillPosition());
220 return true;
221 case 20722:
223 return true;
224 case 20670:
225 move(BrotherData.KARIL.getHillPosition());
226 return true;
227 case 20771:
229 return true;
230 }
231 return false;
232 }
233
234 @Override
238
239 @Override
241 return ActivityType.BARROWS;
242 }
243}
Activity(int cooldown, int instance)
Constructs a new SequencedMinigame object.
Definition Activity.java:55
void add(Mob mob)
Adds a mob to the activity.
boolean clickNpc(Player player, NpcInteractionEvent event)
Definition Barrows.java:153
void start()
Starts the next activity stage.
Definition Barrows.java:96
boolean canTeleport(Player player)
Called when the player attempts to teleport.
Definition Barrows.java:148
void onDeath(Mob mob)
Called when the player die.
Definition Barrows.java:76
void onLogout(Player player)
Called when the player logs out.
Definition Barrows.java:115
void cleanup()
Cleans up the activity when finished.
Definition Barrows.java:108
boolean clickObject(Player player, ObjectInteractionEvent event)
Definition Barrows.java:169
void onRegionChange(Player player)
Called when the player changes region.
Definition Barrows.java:120
static void update(Player player, int amount, String title, String footer, String... strings)
Sends all the information for the activity panel.
static void clear(Player player)
Clears the activity panel.
Represents a factory class that contains important functions for building dialogues.
final DialogueFactory execute()
Retrieves the next dialogue in the chain and executes it.
final DialogueFactory sendNpcChat(int id, String... lines)
Appends an NpcDialogue to the current dialogue chain.
final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2)
Appends the OptionDialogue onto the current dialogue chain.
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
abstract boolean equals(Object obj)
Handles the mob class.
Definition Mob.java:66
final boolean isNpc()
Check if an entity is an npc.
Definition Mob.java:550
final boolean isPlayer()
Check if an entity is a player.
Definition Mob.java:564
Represents a non-player character in the in-game world.
Definition Npc.java:29
This class represents a character controlled by a player.
Definition Player.java:125
The container class that represents an item that can be interacted with.
Definition Item.java:21
Handles checking if mobs are in a certain area.
Definition Area.java:13
static boolean inBarrows(Entity entity)
Definition Area.java:254
Represents a single tile on the game world.
Definition Position.java:14
The OutgoingPacket that sends a message to a Players chatbox in the client.
Handles miscellaneous methods.
Definition Utility.java:27
static double getPercentageAmount(int progress, int total)
Gets a percentage amount.
Definition Utility.java:36
Holds all activity types that are timed.
int getNpcId()
Gets the npc id of the barrows brother.