RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
WarriorGuild.java
1package com.osroyale.content.activity.impl.warriorguild;
2
3import com.osroyale.Config;
4import com.osroyale.content.activity.Activity;
5import com.osroyale.content.activity.ActivityDeathType;
6import com.osroyale.content.activity.ActivityType;
7import com.osroyale.content.activity.panel.ActivityPanel;
8import com.osroyale.content.collectionlog.CollectionLog;
9import com.osroyale.content.collectionlog.CollectionLogData;
10import com.osroyale.content.dialogue.impl.KamfreenaDialogue;
11import com.osroyale.content.event.impl.ItemOnObjectInteractionEvent;
12import com.osroyale.content.event.impl.NpcInteractionEvent;
13import com.osroyale.content.event.impl.ObjectInteractionEvent;
14import com.osroyale.content.event.impl.PickupItemInteractionEvent;
15import com.osroyale.content.skillcape.SkillCape;
16import com.osroyale.content.store.Store;
17import com.osroyale.game.Animation;
18import com.osroyale.game.UpdatePriority;
19import com.osroyale.game.task.Task;
20import com.osroyale.game.task.impl.WarriorGuildCyclopEvent;
21import com.osroyale.game.world.World;
22import com.osroyale.game.world.entity.mob.Mob;
23import com.osroyale.game.world.entity.mob.data.LockType;
24import com.osroyale.game.world.entity.mob.npc.Npc;
25import com.osroyale.game.world.entity.mob.npc.NpcDeath;
26import com.osroyale.game.world.entity.mob.player.Player;
27import com.osroyale.game.world.items.Item;
28import com.osroyale.game.world.position.Area;
29import com.osroyale.game.world.position.Position;
30import com.osroyale.net.packet.out.SendEntityHintArrow;
31import com.osroyale.net.packet.out.SendMessage;
32import com.osroyale.util.Utility;
33
34import java.util.Optional;
35
73
74* This class handles the warrior's guild activity.
75 *
76 * @author Daniel
77 */
78public class WarriorGuild extends Activity {
79
81 private final Player player;
82
84 private Npc animated;
85
88
89 private Item item;
90
92 private final WarriorGuildActivityListener listener = new WarriorGuildActivityListener(this);
93
95 private WarriorGuild(Player player) {
96 super(3, Mob.DEFAULT_INSTANCE);
97 this.player = player;
98 }
99
101 public static WarriorGuild create(Player player) {
102 WarriorGuild minigame = new WarriorGuild(player);
103 minigame.state = WarriorGuildState.ANIMATOR;
104 minigame.add(player);
105 return minigame;
106 }
107
109 public void end() {
110 cleanup();
111 finish();
112 }
113
115 private void summon(int index, AnimatorData animator) {
116 boolean walk_state = player.movement.isRunningToggled();
117
118 animated = new Npc(WarriorGuildUtility.ANIMATED[index], animator.objectPosition);
119 animated.owner = player;
120 animated.setVisible(false);
121 add(animated);
122
123 player.movement.setRunningToggled(false);
124 player.locking.lock(LockType.MASTER_WITH_MOVEMENT);
125
126 for (int i = 0; i < WarriorGuildUtility.ARMOUR[index].length; i++) {
127 player.inventory.remove(WarriorGuildUtility.ARMOUR[index][i]);
128 }
129
130 World.schedule(new Task(1) {
131 int count = 0;
132
133 @Override
134 protected void execute() {
135 if (count == 0) {
136 player.animate(new Animation(827, UpdatePriority.HIGH));
137 player.send(new SendMessage("You place the armour pieces inside the animator..."));
138 } else if (count == 2) {
139 player.send(new SendMessage("The animator begins to hum, something appears to be working..."));
140 player.walkExactlyTo(animator.walkToPosition);
141 } else if (count == 7) {
142 animated.setVisible(true);
143 animated.animate(4166);
144 animated.speak("I'M ALIVE!");
145 animated.getCombat().attack(player);
146 player.face(animated);
147 player.send(new SendEntityHintArrow(animated));
148 player.send(new SendMessage("The animated armour comes to life!"));
149 cancel();
150 }
151 count++;
152 }
153
154 @Override
155 protected void onCancel(boolean logout) {
156 player.blockFace = false;
157 player.locking.unlock();
158 player.movement.reset();
159 player.movement.setRunningToggled(walk_state);
160
161 }
162 });
163 }
164
165 @Override
166 protected void start() {
167
168 }
169
170 @Override
171 public void finish() {
172 remove(player);
173 ActivityPanel.clear(player);
174 }
175
176 @Override
177 public void cleanup() {
178 if (animated != null) {
179 remove(animated);
180 }
181 }
182
183 @Override
184 protected boolean clickObject(Player player, ObjectInteractionEvent event) {
185 int object = event.getObject().getId();
186 if (object == 16671) {
187 player.move(new Position(2841, 3538, 2));
188 return true;
189 }
190 if (object == 24303) {
191 player.move(new Position(2841, 3538, 0));
192 return true;
193 }
194 if (object == 24306 || object == 24309) {
195 if (state == WarriorGuildState.ANIMATOR) {
196 if (!SkillCape.isEquipped(player, SkillCape.ATTACK)) {
197 if (!player.inventory.contains(new Item(8851, 25))) {
198 player.dialogueFactory.sendStatement("You need at least 25 warrior guild tokens to enter.").execute();
199 return true;
200 }
201 }
202 player.inventory.remove(new Item(8851, 25));
203 state = WarriorGuildState.CYCLOPS;
204 player.move(new Position(player.getX() + 1, player.getY(), 2));
205 World.schedule(new WarriorGuildCyclopEvent(player));
206 } else if (state == WarriorGuildState.CYCLOPS) {
207 player.move(new Position(player.getX() - 2, player.getY(), 2));
208 state = WarriorGuildState.ANIMATOR;
209 }
210 return true;
211 }
212 return false;
213 }
214
215 @Override
216 protected boolean clickNpc(Player player, NpcInteractionEvent event) {
217 int npc = event.getNpc().id;
218 if (npc == 2461) {
219 player.dialogueFactory.sendDialogue(new KamfreenaDialogue());
220 return true;
221 }
222 if (npc == 2462) {
223 Store.STORES.get("Shanomi's Armour Store").open(player);
224 return true;
225 }
226 return false;
227 }
228
229 @Override
230 protected boolean useItem(Player player, ItemOnObjectInteractionEvent event) {
231 if (animated != null) {
232 player.dialogueFactory.sendStatement("You already have an animated armour spawned!").execute();
233 return false;
234 }
235
236 int object = event.getObject().getId();
237
238 if (object != 23955) {
239 return false;
240 }
241
242 Item used = event.getItem();
243 int armourIndex = WarriorGuildUtility.contains(player, used.getId());
244
245 if (armourIndex == -1) {
246 return true;
247 }
248
249 Optional<AnimatorData> animator = AnimatorData.getAnimator(event.getObject().getPosition());
250
251 if (!animator.isPresent()) {
252 return true;
253 }
254
255 if (!player.getPosition().equals(animator.get().standPosition)) {
256 player.dialogueFactory.sendStatement("Please stand in front of the animator!").execute();
257 return true;
258 }
259
260 summon(armourIndex, animator.get());
261 return true;
262 }
263
264 @Override
265 protected boolean pickupItem(Player player, PickupItemInteractionEvent event) {
266 if (WarriorGuildUtility.getDefender(player) == event.getItem().getId()) {
267 player.pickup(event.getItem(), event.getPosition());
268 CollectionLog.logItem(player, CollectionLogData.WARRIORS_GUILD, item.getId(), 1);
269 return true;
270 }
271 return false;
272 }
273
274 @Override
275 public void onLogout(Player player) {
276 if (state == WarriorGuildState.CYCLOPS)
277 player.move(new Position(2846, 3540, 2));
278 cleanup();
279 finish();
280 }
281
282 @Override
283 public void onRegionChange(Player player) {
284 if (!Area.inWarriorGuild(player)) {
285 if (animated != null) {
286 player.send(new SendMessage("The animated armour vanishes as you have leave the region, taking your armour"));
287 player.send(new SendMessage("with him."));
288 }
289 cleanup();
290 finish();
291 }
292 }
293
294 @Override
295 public void onDeath(Mob mob) {
296 if (mob.isNpc()) {
297 World.schedule(new NpcDeath(mob.getNpc()));
298 player.send(new SendEntityHintArrow(player, true));
299 animated = null;
300 return;
301 }
302 remove(mob);
304 end();
305 }
306
307 @Override
308 public void update() {
309 if (state == WarriorGuildState.ANIMATOR)
310 return;
311 if (state == WarriorGuildState.CYCLOPS) {
312 int current = WarriorGuildUtility.getDefenderIndex(player);
313 int progress = (int) Utility.getPercentageAmount(current + 1, 8);
314 Item defender = new Item(WarriorGuildUtility.getDefender(player), 1);
315 ActivityPanel.update(player, progress, "Warrior Guild", defender, "Cyclops will be dropping:", "<col=FF5500>" + defender.getName(), "Chance: <col=FF5500>1/20</col>");
316 }
317 }
318
319 @Override
320 public boolean canTeleport(Player player) {
321 return true;
322 }
323
324 @Override
325 public void sequence() {
326 }
327
328 @Override
329 public ActivityDeathType deathType() {
330 return ActivityDeathType.NORMAL;
331 }
332
333 @Override
334 protected Optional<WarriorGuildActivityListener> getListener() {
335 return Optional.of(listener);
336 }
337
338 @Override
339 public ActivityType getType() {
340 return ActivityType.WARRIOR_GUILD;
341 }
342}
static final Position DEFAULT_POSITION
Definition Config.java:235
Activity(int cooldown, int instance)
Definition Activity.java:92
Optional< WarriorGuildActivityListener > getListener()
static void update(Player player, int amount, String title, String footer, String... strings)
final DialogueFactory sendStatement(String... lines)
static void schedule(Task task)
Definition World.java:284
void move(Position position)
Definition Mob.java:377
void face(GameObject object)
Definition Mob.java:326
void speak(String forceChat)
Definition Mob.java:164
static double getPercentageAmount(int progress, int total)
Definition Utility.java:73
static Optional< AnimatorData > getAnimator(Position position)