RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
ObstacleInteraction.java
1package com.osroyale.content.skill.impl.agility.obstacle;
2
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;
23
24import java.util.concurrent.TimeUnit;
25
26public interface ObstacleInteraction {
27
28 int getAnimation();
29
30 String getPreMessage();
31
32 String getPostMessage();
33
34 default void start(Player player) {}
35
36 void onExecution(Player player, Position start, Position end);
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));
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);
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
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);
183 return true;
184 }
185
186}