RuneHive-Game
Loading...
Searching...
No Matches
WarriorGuildCyclopEvent.java
Go to the documentation of this file.
1package com.runehive.game.task.impl;
2
3import com.runehive.game.task.Task;
4import com.runehive.net.packet.out.SendMessage;
5import com.runehive.game.world.entity.mob.player.Player;
6import com.runehive.game.world.items.Item;
7import com.runehive.game.world.position.Area;
8import com.runehive.game.world.position.Position;
9
10/**
11 * An randomevent which handles the warrior guild cyclops randomevent.
12 *
13 * @author Daniel | Obey
14 */
15public class WarriorGuildCyclopEvent extends Task {
16
17 /** The player instance. */
18 private final Player player;
19
20 /** Constructs a new <code>WarriorGuildCyclopEvent</code>. */
22 super(50);
23 this.player = player;
24 this.attach(player);
25 }
26
27 @Override
28 protected boolean canSchedule() {
29 return !player.warriorGuidTask;
30 }
31
32 @Override
33 protected void onSchedule() {
34 player.warriorGuidTask = true;
35 }
36
37 @Override
38 protected void onCancel(boolean logout) {
39 player.warriorGuidTask = false;
40 }
41
42 @Override
43 public void execute() {
44 if (player.isDead() || !player.isValid() || !player.inActivity() || !Area.inCyclops(player)) {
45 cancel();
46 return;
47 }
48
49 if (!player.inventory.contains(new Item(8851, 10))) {
50 if (Area.inCyclops(player)) {
51 player.move(new Position(2846, 3540, 2));
52 }
53 player.dialogueFactory.sendStatement("You have been removed from the Cyclops", "room as you have run out of tokens.").execute();
54 cancel();
55 return;
56 }
57
58 player.inventory.remove(new Item(8851, 10));
59 player.message("10 tokens have been removed from your inventory.");
60
61 if (!player.inventory.contains(new Item(8851, 10))) {
62 if (Area.inCyclops(player)) {
63 player.move(new Position(2846, 3540, 2));
64 }
65 player.dialogueFactory.sendStatement("You have been removed from the Cyclops", "room as you have run out of tokens.").execute();
66 }
67 }
68}
synchronized final void cancel()
Cancels all subsequent executions.
Definition Task.java:113
Task attach(Object newKey)
Attaches a new key.
Definition Task.java:148
Task(boolean instant, int delay)
Creates a new Task.
Definition Task.java:41
WarriorGuildCyclopEvent(Player player)
Constructs a new WarriorGuildCyclopEvent.
void execute()
A function representing the unit of work that will be carried out.
boolean canSchedule()
A function executed on registration.
void onCancel(boolean logout)
A function executed on cancellation.
void onSchedule()
A function executed on registration.
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 inCyclops(Interactable entity)
Definition Area.java:140
Represents a single tile on the game world.
Definition Position.java:14