RuneHive-Game
Loading...
Searching...
No Matches
ObstacleInteraction.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.agility.obstacle;
2
3import com.runehive.Config;
4import com.runehive.content.achievement.AchievementHandler;
5import com.runehive.content.achievement.AchievementKey;
6import com.runehive.content.activity.randomevent.RandomEventHandler;
7import com.runehive.content.clanchannel.content.ClanTaskKey;
8import com.runehive.content.skill.impl.agility.Agility;
9import com.runehive.game.Animation;
10import com.runehive.game.task.Task;
11import com.runehive.game.world.World;
12import com.runehive.game.world.entity.mob.MobAnimation;
13import com.runehive.game.world.entity.mob.UpdateFlag;
14import com.runehive.game.world.entity.mob.data.LockType;
15import com.runehive.game.world.entity.mob.player.Player;
16import com.runehive.game.world.entity.skill.Skill;
17import com.runehive.game.world.items.Item;
18import com.runehive.game.world.items.ground.GroundItem;
19import com.runehive.game.world.position.Area;
20import com.runehive.game.world.position.Position;
21import com.runehive.net.packet.out.SendMessage;
22import com.runehive.util.Utility;
23
24import java.util.concurrent.TimeUnit;
25
26public interface ObstacleInteraction {
27
29
30 String getPreMessage();
31
33
34 default void start(Player player) {}
35
37
38 default void onCancellation(Player player) {}
39
40 default void execute(Player player, Obstacle next, Position start, Position end, int level, float experience, int ordinal) {
41 if (!canExecute(player, level))
42 return;
43
44 if (player.locking.locked(LockType.MASTER))
45 return;
46
47 player.getCombat().reset();
48 player.locking.lock();
49
50 World.schedule(new Task(true, 1) {
51 private final MobAnimation ANIMATION = player.mobAnimation.copy();
52 private final boolean RUNNING = player.movement.isRunning();
53 private boolean started = false;
54 private Obstacle nextObstacle = next;
55
56 @Override
57 protected void onSchedule() {
58 player.movement.setRunningToggled(false);
59 if (getPreMessage() != null)
60 player.send(new SendMessage(getPreMessage()));
61 start(player);
62 attach(player);
63 }
64
65 @Override
66 protected void execute() {
67 if (nextObstacle != null && player.getPosition().equals(nextObstacle.getEnd())) {
68 if (canExecute(player, level)) {
69 nextObstacle.getType().getInteraction().start(player);
70 nextObstacle.getType().getInteraction().onExecution(player, nextObstacle.getStart(), nextObstacle.getEnd());
71 if (nextObstacle.getType().getInteraction().getPreMessage() != null)
72 player.send(new SendMessage(nextObstacle.getType().getInteraction().getPreMessage()));
73 }
74 if (nextObstacle.getNext() == null) {
75 this.cancel();
76 return;
77 }
78 nextObstacle.getType().getInteraction().onCancellation(player);
79 nextObstacle = nextObstacle.getNext();
80 } else if (player.getPosition().equals(end)) {
81 if (nextObstacle != null) {
82 if (canExecute(player, level)) {
83 nextObstacle.getType().getInteraction().start(player);
84 nextObstacle.getType().getInteraction().onExecution(player, nextObstacle.getStart(), nextObstacle.getEnd());
85 if (nextObstacle.getType().getInteraction().getPreMessage() != null) {
86 player.send(new SendMessage(nextObstacle.getType().getInteraction().getPreMessage()));
87 }
88 }
89 if (nextObstacle.getNext() != null) {
90 nextObstacle.getType().getInteraction().onCancellation(player);
91 nextObstacle = nextObstacle.getNext();
92 } else {
93 this.cancel();
94 return;
95 }
96 } else {
97 this.cancel();
98 return;
99 }
100 }
101 if (!started) {
102 started = true;
103 onExecution(player, start, end);
104 if (ordinal > -1 && Utility.random(50) == 0) {
105
106 if (!Area.inWildernessResource(player) || !Area.inBarbarianCourse(player) || !Area.inGnomeCourse(player)) {
107 GroundItem.create(player, new Item(11849, 1));
108 player.send(new SendMessage("<col=C60DDE>There appears to be a wild Grace mark near you."));
109 }
110 }
111 }
112 }
113
114 @Override
115 protected void onCancel(boolean logout) {
116 if (logout) {
117 player.move(start);
118 return;
119 }
120 if (getPostMessage() != null)
121 player.send(new SendMessage(getPostMessage()));
122 if (experience > 0)
123 player.skills.addExperience(Skill.AGILITY, experience * 25);
124 if (ordinal > -1) {
125 if (ordinal == 0) {
126 player.attributes.set("AGILITY_FLAGS", 1 << ordinal);
127 } else {
128 int i = player.attributes.get("AGILITY_FLAGS", Integer.class) | (1 << ordinal);
129 player.attributes.set("AGILITY_FLAGS", i);
130 }
131 }
132
133 if (Area.inGnomeCourse(player)) {
134 rewards(player, "Gnome Agility", Agility.GNOME_FLAGS, 39);
135 } else if (Area.inBarbarianCourse(player)) {
136 rewards(player, "Barbarian Agility", Agility.BARBARIAN_FLAGS, 46.5f);
137 } else if (Area.inWildernessCourse(player)) {
138 rewards(player, "Wilderness Agility", Agility.WILDERNESS_FLAGS, 498.9f);
139 } else if (Area.inSeersCourse(player)) {
140 rewards(player, "Seers Agility", Agility.SEERS_FLAGS, 435);
141 } else if (Area.inArdougneCourse(player)) {
142 rewards(player, "Ardougne Agility", Agility.ARDOUGNE_FLAGS, 529);
143 }
144
145 player.mobAnimation = ANIMATION;
146 player.animate(new Animation(65535));
148 player.movement.setRunningToggled(RUNNING);
149 Position nextPosition = nextObstacle != null ? nextObstacle.getEnd() : end;
150 if (!player.getPosition().equals(nextPosition)) {
151 player.move(nextPosition);
152 } else {
153 int time = player.attributes.get("AGILITY_TYPE", ObstacleType.class) == ObstacleType.WILDERNESS_COURSE ? 1199 : 599;
154 player.locking.lock(time, TimeUnit.MILLISECONDS, LockType.MASTER);
155 }
156 onCancellation(player);
157 }
158 });
159 }
160
161 default boolean canExecute(Player player, int level) {
162 if (player.skills.getLevel(Skill.AGILITY) < level) {
163 player.dialogueFactory.sendStatement("You need an agility level of " + level + " to do this!").execute();
164 return false;
165 }
166 return true;
167 }
168
169 default boolean rewards(Player player, String course, int flags, float bonus) {
170 int flag = player.attributes.get("AGILITY_FLAGS", Integer.class);
171 if ((flag & flags) != flags) {
172 return false;
173 }
174
176 player.send(new SendMessage("You have completed the " + course + " course and receive 5 tickets."));
177 player.forClan(channel -> channel.activateTask(ClanTaskKey.AGILITY_COURSE, player.getName()));
181 player.inventory.addOrDrop(new Item(2996, 5));
182 player.attributes.set("AGILITY_FLAGS", 0);
183 return true;
184 }
185
186}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final double AGILITY_MODIFICATION
The experience modification for agility.
Definition Config.java:247
static void activate(Player player, AchievementKey achievement)
Activates the achievement for the individual player.
final DialogueFactory execute()
Retrieves the next dialogue in the chain and executes it.
final DialogueFactory sendStatement(String... lines)
Appends a StatementDialogue to the current dialogue chain.
Created by Daniel on 2017-11-02.
Definition Agility.java:21
Class that models a single animation used by an entity.
A game representing a cyclic unit of work.
Definition Task.java:11
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
boolean locked()
Checks if the mob is locked.
Definition Locking.java:52
final EnumSet< UpdateFlag > updateFlags
Definition Mob.java:94
final GenericAttributes attributes
Definition Mob.java:95
void move(Position position)
Moves the mob to a set position.
Definition Mob.java:340
boolean isRunning()
Checks if any running flag is set.
void setRunningToggled(boolean runToggled)
Sets the run toggled flag.
Definition Movement.java:93
This class represents a character controlled by a player.
Definition Player.java:125
void forClan(Consumer< ClanChannel > action)
Definition Player.java:568
String getName()
Gets the name of this entity.
Definition Player.java:774
Combat< Player > getCombat()
The combat of the mob.
Definition Player.java:759
Represents a trainable and usable skill.
Definition Skill.java:18
static final int AGILITY
The agility skill id.
Definition Skill.java:69
void addExperience(int id, double experience)
Adds experience to a given skill.
int getLevel(int id)
Gets the level of a skill.
The container class that represents an item that can be interacted with.
Definition Item.java:21
void addOrDrop(List< Item > items)
Attempts to deposit an item to the players inventory, if there is no space it'll bank the item instea...
Represents a single Ground item on the world map.
static GroundItem create(Player player, Item item)
Creates a new GroundItem object for a player and an item.
Handles checking if mobs are in a certain area.
Definition Area.java:13
static boolean inArdougneCourse(Interactable entity)
Definition Area.java:167
static boolean inSeersCourse(Interactable entity)
Definition Area.java:163
static boolean inBarbarianCourse(Interactable entity)
Definition Area.java:159
static boolean inWildernessCourse(Interactable entity)
Definition Area.java:171
static boolean inGnomeCourse(Interactable entity)
Definition Area.java:155
static boolean inWildernessResource(Interactable entity)
Definition Area.java:175
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 int random(int bound)
Definition Utility.java:239
public< K, E > E get(K key)
Gets a generic attribute.
public< K, E > void set(K key, E attribute)
Sets a generic attribute.
void onExecution(Player player, Position start, Position end)
default boolean rewards(Player player, String course, int flags, float bonus)
default void execute(Player player, Obstacle next, Position start, Position end, int level, float experience, int ordinal)