RuneHive-Game
Loading...
Searching...
No Matches
Scorpia.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.strategy.npc.boss.scorpia;
2
3import com.google.common.base.Stopwatch;
4import com.runehive.game.Animation;
5import com.runehive.game.world.entity.combat.CombatType;
6import com.runehive.game.world.entity.combat.attack.FightType;
7import com.runehive.game.world.entity.combat.hit.CombatHit;
8import com.runehive.game.world.entity.combat.hit.Hit;
9import com.runehive.game.world.entity.combat.projectile.CombatProjectile;
10import com.runehive.game.world.entity.combat.strategy.npc.MultiStrategy;
11import com.runehive.game.world.entity.combat.strategy.npc.NpcMeleeStrategy;
12import com.runehive.game.world.entity.mob.Mob;
13import com.runehive.game.world.entity.mob.movement.waypoint.Waypoint;
14import com.runehive.game.world.entity.mob.npc.Npc;
15import com.runehive.game.world.position.Position;
16import com.runehive.util.RandomUtils;
17import com.runehive.util.Utility;
18
19/** @author Daniel */
20public class Scorpia extends MultiStrategy {
21 private boolean hasGuardians;
22
23 public Scorpia() {
24 currentStrategy = new Melee();
25 }
26
27 @Override
28 public void block(Mob attacker, Npc defender, Hit hit, CombatType combatType) {
29 currentStrategy.block(attacker, defender, hit, combatType);
30 defender.getCombat().attack(attacker);
31 }
32
33 @Override
34 public void hit(Npc attacker, Mob defender, Hit hit) {
35 super.hit(attacker, defender, hit);
36 if (hasGuardians || attacker.getCurrentHealth() >= 100) {
37 return;
38 }
39 hasGuardians = true;
40 for (int i = 0; i < 2; i++) {
42 Npc guardian = new Guardian(spawn, attacker);
43 guardian.register();
44 guardian.definition.setRespawnTime(-1);
45 }
46 }
47
48 @Override
49 public int getAttackDelay(Npc attacker, Mob defender, FightType fightType) {
50 return attacker.definition.getAttackDelay();
51 }
52
53 private class GuardianWaypoint extends Waypoint {
54 final Npc scorpia;
55
57 super(guardian, scorpia);
58 this.scorpia = scorpia;
59 }
60
61 @Override
62 protected void onDestination() {
63 CombatProjectile.getDefinition("Scorpia guardian").getProjectile().ifPresent(projectile -> projectile.send(mob, scorpia));
64 mob.animate(new Animation(6261));
65 scorpia.heal(2);
66 ((Guardian) mob).lastHeal.reset();
67 }
68 }
69
70 private class Guardian extends Npc {
71 private final Stopwatch lastHeal = Stopwatch.createStarted();
72
73 private Guardian(Position spawn, Npc scorpia) {
74 super(6617, spawn);
75 setWaypoint(new Waypoint(this, scorpia) {
76 @Override
77 protected void onDestination() {
78 CombatProjectile.getDefinition("Scorpia guardian").getProjectile().ifPresent(projectile -> projectile.send(mob, scorpia));
79 lastHeal.reset();
80 lastHeal.start();
81 mob.animate(new Animation(6261));
82 scorpia.heal(2);
83 }
84 });
85 }
86
87 @Override
88 public void sequence() {
89 super.sequence();
90 long millis = lastHeal.elapsed().toMillis();
91 if (millis > 15_000) {
92 unregister();
93 }
94 }
95 }
96
97 private static final class Melee extends NpcMeleeStrategy {
98 @Override
99 public CombatHit[] getHits(Npc attacker, Mob defender) {
100 return new CombatHit[]{nextMeleeHit(attacker, defender, 16)};
101 }
102 }
103}
Class that models a single animation used by an entity.
A wrapper for a Hit object, adding additional variables for hit and hitsplat delays.
A Hit object holds the damage amount and hitsplat data.
Definition Hit.java:10
void block(Mob attacker, Npc defender, Hit hit, CombatType combatType)
Definition Scorpia.java:28
int getAttackDelay(Npc attacker, Mob defender, FightType fightType)
Definition Scorpia.java:49
Handles the mob class.
Definition Mob.java:66
void setWaypoint(Waypoint waypoint)
Definition Mob.java:434
Represents a non-player character in the in-game world.
Definition Npc.java:29
Npc(int id, Position position)
Definition Npc.java:46
void register()
Registers an entity to the World.
Definition Npc.java:112
void unregister()
Unregisters an entity from the World.
Definition Npc.java:126
Combat< Npc > getCombat()
The combat of the mob.
Definition Npc.java:156
Represents a single tile on the game world.
Definition Position.java:14
A static-util class that provides additional functionality for generating pseudo-random numbers.
static< T > T random(T[] array)
Pseudo-randomly retrieves a element from array.
Handles miscellaneous methods.
Definition Utility.java:27
static Position[] getInnerBoundaries(Position position, int width, int length)
Definition Utility.java:621
The enumerated type whose elements represent the fighting types.