1package com.osroyale.content.skill.impl.agility.obstacle;
3import com.osroyale.Config;
4import com.osroyale.content.achievement.AchievementHandler;
5import com.osroyale.content.achievement.AchievementKey;
6import com.osroyale.content.activity.randomevent.RandomEventHandler;
7import com.osroyale.content.clanchannel.content.ClanTaskKey;
8import com.osroyale.content.skill.impl.agility.Agility;
9import com.osroyale.game.Animation;
10import com.osroyale.game.task.Task;
11import com.osroyale.game.world.World;
12import com.osroyale.game.world.entity.mob.MobAnimation;
13import com.osroyale.game.world.entity.mob.UpdateFlag;
14import com.osroyale.game.world.entity.mob.data.LockType;
15import com.osroyale.game.world.entity.mob.player.Player;
16import com.osroyale.game.world.entity.skill.Skill;
17import com.osroyale.game.world.items.Item;
18import com.osroyale.game.world.items.ground.GroundItem;
19import com.osroyale.game.world.position.Area;
20import com.osroyale.game.world.position.Position;
21import com.osroyale.net.packet.out.SendMessage;
22import com.osroyale.util.Utility;
24import java.util.concurrent.TimeUnit;
26public interface ObstacleInteraction {
30 String getPreMessage();
32 String getPostMessage();
34 default void start(Player player) {}
36 void onExecution(Player player, Position start, Position end);
38 default void onCancellation(Player player) {}
40 default void execute(Player player, Obstacle next, Position start, Position end,
int level,
float experience,
int ordinal) {
41 if (!canExecute(player, level))
44 if (player.locking.locked(LockType.MASTER))
47 player.getCombat().reset();
48 player.locking.lock();
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;
57 protected void onSchedule() {
58 player.movement.setRunningToggled(
false);
59 if (getPreMessage() !=
null)
60 player.send(
new SendMessage(getPreMessage()));
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()));
74 if (nextObstacle.getNext() ==
null) {
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()));
89 if (nextObstacle.getNext() !=
null) {
90 nextObstacle.getType().getInteraction().onCancellation(player);
91 nextObstacle = nextObstacle.getNext();
103 onExecution(player, start, end);
104 if (ordinal > -1 && Utility.random(50) == 0) {
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."));
115 protected void onCancel(
boolean logout) {
120 if (getPostMessage() !=
null)
121 player.send(
new SendMessage(getPostMessage()));
123 player.skills.addExperience(Skill.AGILITY, experience * 25);
126 player.attributes.set(
"AGILITY_FLAGS", 1 << ordinal);
128 int i = player.attributes.get(
"AGILITY_FLAGS", Integer.class) | (1 << ordinal);
129 player.attributes.set(
"AGILITY_FLAGS", i);
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);
145 player.mobAnimation = ANIMATION;
146 player.animate(
new Animation(65535));
147 player.updateFlags.add(UpdateFlag.APPEARANCE);
148 player.movement.setRunningToggled(RUNNING);
149 Position nextPosition = nextObstacle !=
null ? nextObstacle.getEnd() : end;
150 if (!player.getPosition().equals(nextPosition)) {
151 player.move(nextPosition);
153 int time = player.attributes.get(
"AGILITY_TYPE", ObstacleType.class) == ObstacleType.WILDERNESS_COURSE ? 1199 : 599;
154 player.locking.lock(time, TimeUnit.MILLISECONDS, LockType.MASTER);
156 onCancellation(player);
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();
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) {
175 player.skills.addExperience(Skill.AGILITY, bonus * Config.AGILITY_MODIFICATION);
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()));
178 player.playerAssistant.activateSkilling(1);
179 RandomEventHandler.trigger(player);
180 AchievementHandler.activate(player, AchievementKey.AGILITY, 1);
181 player.inventory.addOrDrop(
new Item(2996, 5));
182 player.attributes.set(
"AGILITY_FLAGS", 0);