RuneHive-Game
Loading...
Searching...
No Matches
Vetion.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.strategy.npc.boss;
2
3import com.runehive.game.Animation;
4import com.runehive.game.Graphic;
5import com.runehive.game.UpdatePriority;
6import com.runehive.game.task.Task;
7import com.runehive.game.world.World;
8import com.runehive.game.world.entity.combat.CombatType;
9import com.runehive.game.world.entity.combat.CombatUtil;
10import com.runehive.game.world.entity.combat.attack.FightType;
11import com.runehive.game.world.entity.combat.hit.CombatHit;
12import com.runehive.game.world.entity.combat.hit.Hit;
13import com.runehive.game.world.entity.combat.hit.HitIcon;
14import com.runehive.game.world.entity.combat.projectile.CombatProjectile;
15import com.runehive.game.world.entity.combat.strategy.npc.MultiStrategy;
16import com.runehive.game.world.entity.combat.strategy.npc.NpcMagicStrategy;
17import com.runehive.game.world.entity.combat.strategy.npc.NpcMeleeStrategy;
18import com.runehive.game.world.entity.mob.Mob;
19import com.runehive.game.world.entity.mob.npc.Npc;
20import com.runehive.game.world.position.Position;
21import com.runehive.game.world.region.RegionManager;
22import com.runehive.net.packet.out.SendMessage;
23import com.runehive.util.RandomUtils;
24import com.runehive.util.Utility;
25
26import java.util.Arrays;
27import java.util.LinkedList;
28
29/** @author Daniel */
30public class Vetion extends MultiStrategy {
31 private static Earthquake EARTHQUAKE = new Earthquake();
32 private static Magic MAGIC = new Magic();
33
34 private Npc pet1, pet2;
35 private boolean spawnPets, secondTrans;
36
37 public Vetion() {
39 }
40
41 @Override
42 public boolean withinDistance(Npc attacker, Mob defender) {
43 if (!currentStrategy.withinDistance(attacker, defender)) {
45 }
46 return currentStrategy.withinDistance(attacker, defender);
47 }
48
49 @Override
50 public boolean canAttack(Npc attacker, Mob defender) {
51 if (!currentStrategy.withinDistance(attacker, defender)) {
53 }
54 return currentStrategy.canAttack(attacker, defender);
55 }
56
57 @Override
58 public boolean canOtherAttack(Mob attacker, Npc defender) {
59 if (pet1 != null || pet2 != null) {
60 if (attacker.isPlayer()) {
61 attacker.getPlayer().message("You must kill his hellhounds before dealing damage!");
62 }
63 return false;
64 }
65 return currentStrategy.canOtherAttack(attacker, defender);
66 }
67
68 @Override
69 public void onDeath(Mob attacker, Npc defender, Hit hit) {
70 if (pet1 != null) pet1.unregister();
71 if (pet2 != null) pet2.unregister();
72 }
73
74 @Override
75 public void preDeath(Mob attacker, Npc defender, Hit hit) {
76 super.preDeath(attacker, defender, hit);
77
78 if (secondTrans) {
79 return;
80 }
81
82 secondTrans = true;
83 spawnPets = false;
84 defender.setDead(false);
85 defender.heal(255);
86 defender.transform(6612);
87 defender.speak("Do it again!");
88 defender.getCombat().attack(attacker);
89
90 World.schedule(new Task(500) {
91 @Override
92 public void execute() {
93 cancel();
94 if (defender.isDead())
95 return;
96 defender.transform(6611);
97 defender.getCombat().reset();
98 secondTrans = false;
99 spawnPets = false;
100 }
101 });
102 }
103
104 @Override
105 public void finishIncoming(Mob attacker, Npc defender) {
106 if (spawnPets || defender.getCurrentHealth() > defender.getMaximumHealth() / 2) {
107 return;
108 }
109
110 Position[] innerBoundary = Utility.getInnerBoundaries(defender.getPosition().transform(-2, -2), defender.width() + 4, defender.length() + 4);
111 defender.speak(defender.id == 6611 ? "Kill, my pets!" : "Bahh! Go, dogs!!");
112 spawnPets = true;
113
114 if (!secondTrans) {
115 pet1 = new Npc(6613, RandomUtils.random(innerBoundary)) {
116 @Override
117 public void appendDeath() {
118 super.appendDeath();
119 pet1 = null;
120 }
121 };
122 pet2 = new Npc(6613, RandomUtils.random(innerBoundary)) {
123 @Override
124 public void appendDeath() {
125 super.appendDeath();
126 pet2 = null;
127 }
128 };
129 } else {
130 pet1 = new Npc(6614, RandomUtils.random(innerBoundary)) {
131 @Override
132 public void appendDeath() {
133 super.appendDeath();
134 pet1 = null;
135 }
136 };
137 pet2 = new Npc(6614, RandomUtils.random(innerBoundary)) {
138 @Override
139 public void appendDeath() {
140 super.appendDeath();
141 pet2 = null;
142 }
143 };
144 }
145 pet1.register();
146 pet2.register();
147 pet1.definition.setRespawnTime(-1);
148 pet2.definition.setRespawnTime(-1);
149 pet1.speak("GRRRRRRRRRRRR");
150 pet2.speak("GRRRRRRRRRRRR");
151 pet1.getCombat().attack(attacker);
152 pet2.getCombat().attack(attacker);
153 }
154
155 @Override
156 public void block(Mob attacker, Npc defender, Hit hit, CombatType combatType) {
157 currentStrategy.block(attacker, defender, hit, combatType);
158 defender.getCombat().attack(attacker);
159 }
160
161 @Override
162 public void finishOutgoing(Npc attacker, Mob defender) {
163 currentStrategy.finishOutgoing(attacker, defender);
164 if (!NpcMeleeStrategy.get().withinDistance(attacker, defender)) {
166 } else if (RandomUtils.success(0.25)) {
168 } else {
170 }
171 }
172
173 @Override
174 public int getAttackDelay(Npc attacker, Mob defender, FightType fightType) {
175 return attacker.definition.getAttackDelay();
176 }
177
178 private static final class Earthquake extends NpcMeleeStrategy {
179 private static final Animation ANIMATION = new Animation(9974, UpdatePriority.HIGH);
180
181 @Override
182 public void hit(Npc attacker, Mob defender, Hit hit) {
183 RegionManager.forNearbyPlayer(defender, 11, player -> {
184 player.send(new SendMessage("Vet'ion pummels the ground sending a shattering earthquake shockwave through you."));
185 if (player.equals(defender)) {
186 hit.setDamage(25 + RandomUtils.inclusive(20));
187 return;
188 }
189 player.damage(new Hit(25 + RandomUtils.inclusive(20), HitIcon.MELEE));
190 });
191 }
192
193 @Override
194 public Animation getAttackAnimation(Npc attacker, Mob defender) {
195 return ANIMATION;
196 }
197
198 @Override
199 public CombatHit[] getHits(Npc attacker, Mob defender) {
200 return new CombatHit[]{nextMeleeHit(attacker, defender)};
201 }
202 }
203
204 private static final class Magic extends NpcMagicStrategy {
205 private static final Animation ANIMATION = new Animation(9969, UpdatePriority.HIGH);
206
207 public Magic() {
208 super(CombatProjectile.getDefinition("Vet'ion"));
209 }
210
211 @Override
212 public void start(Npc attacker, Mob defender, Hit[] hits) {
213 Position[] bounds = Utility.getInnerBoundaries(defender.getPosition().transform(-1, -1), defender.width() + 2, defender.length() + 2);
214 LinkedList<Position> positions = new LinkedList<>(Arrays.asList(bounds));
215 for (int index = 0; index < 3; index++) {
216 Position bound = index == 0 ? defender.getPosition() : RandomUtils.random(positions);
217 positions.remove(bound);
218 combatProjectile.getProjectile().ifPresent(projectile -> World.sendProjectile(attacker, bound, projectile));
219 World.sendGraphic(new Graphic(775, 100), bound, attacker.instance);
220 World.schedule(CombatUtil.getHitDelay(attacker, defender, CombatType.MAGIC) + 2, () -> RegionManager.forNearbyPlayer(bound, 0, player -> {
221 player.speak("OUCH!");
222 player.damage(new Hit(RandomUtils.inclusive(45), HitIcon.MAGIC));
223 }));
224 }
225 }
226
227 @Override
228 public void hit(Npc attacker, Mob defender, Hit hit) {
229 hit.setAccurate(false);
230 }
231
232 @Override
233 public Animation getAttackAnimation(Npc attacker, Mob defender) {
234 return ANIMATION;
235 }
236
237 @Override
238 public CombatHit[] getHits(Npc attacker, Mob defender) {
239 return new CombatHit[]{nextMagicHit(attacker, defender)};
240 }
241 }
242
243}
Class that models a single animation used by an entity.
Represents a single graphic that can be used by entities.
Definition Graphic.java:10
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
static void sendGraphic(Graphic graphic, Position position, int instance)
Sends a graphic to the world.
Definition World.java:268
static void sendProjectile(Projectile projectile, Position position, int instance, int lock, byte offsetX, byte offsetY)
Sends a world projectile.
Definition World.java:295
A collection of util methods and constants related to combat.
static int getHitDelay(final Mob attacker, final Mob defender, final CombatType type)
Gets the hit delay for the specified type.
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
final CombatHit nextMagicHit(T attacker, Mob defender)
void start(Npc attacker, Mob defender, Hit[] hits)
Definition Vetion.java:212
boolean canOtherAttack(Mob attacker, Npc defender)
Definition Vetion.java:58
void block(Mob attacker, Npc defender, Hit hit, CombatType combatType)
Definition Vetion.java:156
boolean withinDistance(Npc attacker, Mob defender)
Definition Vetion.java:42
void onDeath(Mob attacker, Npc defender, Hit hit)
Definition Vetion.java:69
void preDeath(Mob attacker, Npc defender, Hit hit)
Definition Vetion.java:75
int getAttackDelay(Npc attacker, Mob defender, FightType fightType)
Definition Vetion.java:174
Handles the mob class.
Definition Mob.java:66
void speak(String forceChat)
Sets the mob's forced chat.
Definition Mob.java:127
void transform(int transformId)
Definition Mob.java:201
final boolean isPlayer()
Check if an entity is a player.
Definition Mob.java:564
Represents a non-player character in the in-game world.
Definition Npc.java:29
void appendDeath()
Handles the mob death.
Definition Npc.java:147
Combat< Npc > getCombat()
The combat of the mob.
Definition Npc.java:156
Represents a single tile on the game world.
Definition Position.java:14
Position transform(int diffX, int diffY, int diffZ)
Creates a new location based on this location.
static void forNearbyPlayer(Mob mob, int distance, Consumer< Player > action)
Sends an action to Mob instance which is within a distance.
The OutgoingPacket that sends a message to a Players chatbox in the client.
A static-util class that provides additional functionality for generating pseudo-random numbers.
static int inclusive(int min, int max)
Returns a pseudo-random int value between inclusive min and inclusive max.
static boolean success(double value)
Determines if a pseudorandomly generated double rounded to two decimal places is below or equal to va...
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
Represents different priorities for updating.
The enumerated type whose elements represent the fighting types.
The enumerated type whose elements represent the hit icon of a Hit.
Definition HitIcon.java:8
MELEE
Represents the melee sword hit icon.
Definition HitIcon.java:14