RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
ZulrahActivity.java
1package com.osroyale.content.activity.impl.zulrah;
2
3
4import com.osroyale.content.activity.Activity;
5import com.osroyale.content.activity.ActivityDeathType;
6import com.osroyale.content.activity.ActivityListener;
7import com.osroyale.content.activity.ActivityType;
8import com.osroyale.game.Animation;
9import com.osroyale.game.Graphic;
10import com.osroyale.game.world.World;
11import com.osroyale.game.world.entity.combat.hit.Hit;
12import com.osroyale.game.world.entity.combat.hit.Hitsplat;
13import com.osroyale.game.world.entity.combat.strategy.npc.boss.Zulrah;
14import com.osroyale.game.world.entity.mob.Mob;
15import com.osroyale.game.world.entity.mob.npc.Npc;
16import com.osroyale.game.world.entity.mob.npc.NpcDeath;
17import com.osroyale.game.world.entity.mob.player.Player;
18import com.osroyale.game.world.object.CustomGameObject;
19import com.osroyale.game.world.object.GameObject;
20import com.osroyale.game.world.position.Area;
21import com.osroyale.game.world.position.Position;
22import com.osroyale.net.packet.out.SendMessage;
23import com.osroyale.util.RandomUtils;
24import com.osroyale.util.Stopwatch;
25import com.osroyale.util.Utility;
26
27import java.util.*;
28
65
66public class ZulrahActivity extends Activity {
68 protected final Player player;
69
71 protected Npc zulrah;
72
74 protected Stopwatch stopwatch = Stopwatch.start();
75
77 protected int count;
78
81
83 ZulrahPhase phase = ZulrahPhase.INITIALIZATION;
84
86 List<Npc> snakes = new ArrayList<>();
87
89 List<CustomGameObject> clouds = new ArrayList<>();
90
92 private final ActivityListener<? extends Activity> LISTENER = new ZulrahListener(this);
93
95 private ZulrahActivity(Player player, int instance) {
96 super(1, instance);
97 this.player = player;
98 }
99
101 public static ZulrahActivity create(Player player) {
102 ZulrahActivity activity = new ZulrahActivity(player, player.playerAssistant.instance());
103 activity.add(player);
104 activity.resetCooldown();
105 player.gameRecord.start();
106 player.dialogueFactory.sendStatement("Welcome to Zulrah's shrine.").execute();
107 return activity;
108 }
109
111 void increment() {
112 count++;
113 }
114
116 void reset() {
117 player.getCombat().reset();
118 zulrah.getCombat().reset();
119 zulrah.resetFace();
120 stopwatch.reset();
121 count = -1;
122 }
123
125 int nextForm() {
126 int next = RandomUtils.randomExclude(ZulrahConstants.ZULRAH_IDS, zulrah.id);
127 if (next == 2042) {
128 ((Zulrah) zulrah.getStrategy()).setRanged();
129 } else if (next == 2043) {
130 ((Zulrah) zulrah.getStrategy()).setMelee();
131 } else if (next == 2044) {
132 ((Zulrah) zulrah.getStrategy()).setMagic();
133 }
134 return next;
135 }
136
138 ZulrahPhase nextPhase() {
139 if (zulrah.id == 2043) {
140 return ZulrahPhase.ATTACKING;
141 }
142 Set<ZulrahPhase> states = new HashSet<>();
143 states.add(ZulrahPhase.ATTACKING);
144 if (clouds.size() < ZulrahConstants.MAXIMUM_CLOUDS) {
145 states.add(ZulrahPhase.POISONOUS_CLOUD);
146 }
147 if (snakes.size() < ZulrahConstants.MAXIMUM_SNAKELINGS) {
148 states.add(ZulrahPhase.SNAKELINGS);
149 }
150 return Utility.randomElement(states);
151 }
152
154 Position getSnakelingPosition() {
155 Set<Position> positions = new HashSet<>(Arrays.asList(ZulrahConstants.SNAKELINGS_POSITIONS));
156 for (Npc snake : snakes) {
157 if (positions.contains(snake.getPosition())) {
158 positions.remove(snake.getPosition());
159 }
160 }
161 return Utility.randomElement(positions);
162 }
163
165 Position getCloudPosition() {
166 Set<Position> positions = new HashSet<>(Arrays.asList(ZulrahConstants.CLOUD_POSITIONS));
167 for (GameObject cloud : clouds) {
168 if (positions.contains(cloud.getPosition())) {
169 positions.remove(cloud.getPosition());
170 }
171 }
172 return Utility.randomElement(positions);
173 }
174
176 private void cloudEffect() {
177 for (CustomGameObject cloud : clouds) {
178 if (Utility.inside(cloud.getPosition(), 2, 2, player.getPosition(), 1, 1))
179 player.damage(new Hit(RandomUtils.inclusive(1, 5), Hitsplat.VENOM));
180 }
181 }
182
183 @Override
184 protected void start() {
185 cloudEffect();
186
187 boolean valid = zulrah != null;
188
189 if (valid && zulrah.isDead()) {
190 return;
191 }
192
193 phase.execute(this);
194
195 if (valid) {
196 zulrah.getCombat().cooldown(2);
197 }
198 }
199
200 @Override
201 public void finish() {
202 cleanup();
203 remove(player);
204 player.animate(Animation.RESET, true);
205 player.graphic(Graphic.RESET, true);
206 if (zulrah.isDead()) {
207 player.send(new SendMessage("Fight duration: @red@" + Utility.getTime(player.gameRecord.end(ActivityType.ZULRAH)) + "</col>."));
208 }
209 }
210
211 @Override
212 public void cleanup() {
213 if (zulrah != null) {
214 remove(zulrah);
215 }
216 for (Npc snakeling : snakes) {
217 remove(snakeling);
218 }
219 for (GameObject cloud : clouds) {
220 cloud.unregister();
221 }
222 snakes.clear();
223 clouds.clear();
224 }
225
226 @Override
228 if (!Area.inZulrah(player)) {
229 cleanup();
230 remove(player);
231 player.animate(Animation.RESET, true);
232 player.graphic(Graphic.RESET, true);
233
234 }
235 }
236
237 @Override
238 public void onDeath(Mob mob) {
239 if (mob.isNpc()) {
240 Npc npc = mob.getNpc();
241
242 if (mob.equals(zulrah)) {
243 World.schedule(new NpcDeath(npc, this::finish));
244 }
245
246 if (snakes.contains(npc)) {
247 World.schedule(new NpcDeath(npc, () -> {
248 remove(npc);
249 snakes.remove(npc);
250 }));
251 }
252
253 return;
254 }
255
256 super.onDeath(mob);
257 }
258
259 @Override
260 public ActivityType getType() {
261 return ActivityType.ZULRAH;
262 }
263
264 @Override
265 public boolean canTeleport(Player player) {
266 return true;
267 }
268
269 @Override
270 public ActivityDeathType deathType() {
271 return ActivityDeathType.PURCHASE;
272 }
273
274 @Override
275 protected Optional<? extends ActivityListener<? extends Activity>> getListener() {
276 return Optional.of(LISTENER);
277 }
278
279}
Activity(int cooldown, int instance)
Definition Activity.java:92
Optional<? extends ActivityListener<? extends Activity > > getListener()
static void schedule(Task task)
Definition World.java:284
CombatStrategy< Npc > getStrategy()
Definition Npc.java:198
static String getTime()
Definition Utility.java:178