RuneHive-Game
Loading...
Searching...
No Matches
Callisto.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.Projectile;
6import com.runehive.game.UpdatePriority;
7import com.runehive.game.task.impl.ForceMovementTask;
8import com.runehive.game.world.World;
9import com.runehive.game.world.entity.combat.CombatType;
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.projectile.CombatProjectile;
14import com.runehive.game.world.entity.combat.strategy.CombatStrategy;
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.Direction;
19import com.runehive.game.world.entity.mob.Mob;
20import com.runehive.game.world.entity.mob.npc.Npc;
21import com.runehive.game.world.entity.mob.player.ForceMovement;
22import com.runehive.game.world.pathfinding.path.SimplePathChecker;
23import com.runehive.game.world.position.Position;
24import com.runehive.net.packet.out.SendMessage;
25import com.runehive.util.RandomUtils;
26import com.runehive.util.Utility;
27
28import static com.runehive.game.world.entity.combat.CombatUtil.createStrategyArray;
29import static com.runehive.game.world.entity.combat.CombatUtil.randomStrategy;
30import static com.runehive.game.world.entity.combat.projectile.CombatProjectile.getDefinition;
31
32/** @author Daniel */
33public class Callisto extends MultiStrategy {
34
35 private static Roar ROAR = new Roar();
36 private static Shockwave SHOCKWAVE = new Shockwave();
37 private static Melee MELEE = new Melee();
38 private static final CombatStrategy<Npc>[] FULL = createStrategyArray(MELEE, MELEE, MELEE, SHOCKWAVE);
39
40 public Callisto() {
42 }
43
44 @Override
45 public boolean canAttack(Npc attacker, Mob defender) {
46 if (!currentStrategy.withinDistance(attacker, defender)) {
47 if (RandomUtils.success(0.10)) {
49 } else {
51 }
52 }
53 return currentStrategy.canAttack(attacker, defender);
54 }
55
56 @Override
57 public void block(Mob attacker, Npc defender, Hit hit, CombatType combatType) {
58 currentStrategy.block(attacker, defender, hit, combatType);
59 defender.getCombat().attack(attacker);
60 }
61
62 @Override
63 public void finishOutgoing(Npc attacker, Mob defender) {
64 currentStrategy.finishOutgoing(attacker, defender);
65 if (RandomUtils.success(0.10)) {
67 } else {
68 currentStrategy = randomStrategy(FULL);
69 }
70 }
71
72 @Override
73 public int getAttackDelay(Npc attacker, Mob defender, FightType fightType) {
74 return attacker.definition.getAttackDelay();
75 }
76
77 private static class Roar extends NpcMagicStrategy {
78 Roar() {
79 super(CombatProjectile.getDefinition("EMPTY"));
80 }
81
82 @Override
83 public void start(Npc attacker, Mob defender, Hit[] hits) {
84 attacker.animate(new Animation(4921, UpdatePriority.VERY_HIGH));
85 World.sendProjectile(attacker, defender, new Projectile(395, 46, 80, 43, 31));
86 World.schedule(1, () -> {
87 if (defender.isPlayer()) {
88 Position current = defender.getPosition();
89 Position best = Utility.findBestInside(defender, attacker);
90 int dx = current.getX() - best.getX();
91 int dy = current.getY() - best.getY();
92
93 Direction opposite = Direction.getFollowDirection(attacker.getPosition(), defender.getPosition());
94// for (int x = 1; x <= 2; x++) {
95 int y = dy / (dx == 0 ? dy : dx);
96 Position destination = current.transform(dx, y);
97 if (SimplePathChecker.checkLine(defender, destination))
98 current = destination;
99// }
100 defender.damage(new Hit(Utility.random(1, 3)));
101 defender.interact(attacker);
102 defender.getPlayer().send(new SendMessage("Callisto's roar throws you backwards."));
103
104 Position offset = new Position(current.getX() - defender.getX(), current.getY() - defender.getY());
105 ForceMovement movement = new ForceMovement(defender.getPosition().copy(), offset, 33, 60, Direction.getOppositeDirection(opposite));
106
107 int anim = defender.mobAnimation.getWalk();
108 World.schedule(new ForceMovementTask(defender, 3, 0, movement, new Animation(1157, UpdatePriority.VERY_HIGH)) {
109 @Override
110 protected void onSchedule() {
111 super.onSchedule();
112 defender.mobAnimation.setWalk(1157);
113 defender.locking.lock();
114 }
115
116 @Override
117 protected void onCancel(boolean logout) {
118 super.onCancel(logout);
119 defender.mobAnimation.setWalk(anim);
120 defender.locking.unlock();
121 }
122 });
123 }
124 });
125 }
126
127 @Override
128 public void hit(Npc attacker, Mob defender, Hit hit) {
129 }
130
131 @Override
132 public void attack(Npc attacker, Mob defender, Hit hit) {
133 }
134
135 @Override
136 public CombatHit[] getHits(Npc attacker, Mob defender) {
137 CombatHit hit = nextMagicHit(attacker, defender, 3);
138 hit.setAccurate(true);
139 return new CombatHit[]{hit};
140 }
141 }
142
143 private static class Shockwave extends NpcMagicStrategy {
144 private static final Animation ANIMATION = new Animation(4922, UpdatePriority.HIGH);
145
147 super(getDefinition("Callisto Shockwave"));
148 }
149
150 @Override
151 public void hit(Npc attacker, Mob defender, Hit hit) {
152 super.hit(attacker, defender, hit);
153 if (defender.isPlayer()) {
154 defender.getPlayer().send(new SendMessage("Callisto's fury sends an almighty shockwave through you."));
155 defender.graphic(new Graphic(80, true));
156 }
157 }
158
159 @Override
160 public CombatHit[] getHits(Npc attacker, Mob defender) {
161 CombatHit hit = nextMagicHit(attacker, defender, 23);
162 hit.setAccurate(true);
163 return new CombatHit[]{hit};
164 }
165
166 @Override
167 public Animation getAttackAnimation(Npc attacker, Mob defender) {
168 return ANIMATION;
169 }
170 }
171
172 private static final class Melee extends NpcMeleeStrategy {
173 private static final Animation ANIMATION = new Animation(4925, UpdatePriority.HIGH);
174
175 @Override
176 public int getAttackDistance(Npc attacker, FightType fightType) {
177 return 2;
178 }
179
180 @Override
181 public Animation getAttackAnimation(Npc attacker, Mob defender) {
182 return ANIMATION;
183 }
184
185 @Override
186 public CombatHit[] getHits(Npc attacker, Mob defender) {
187 return new CombatHit[]{nextMeleeHit(attacker, defender)};
188 }
189 }
190}
Class that models a single animation used by an entity.
Represents a single graphic that can be used by entities.
Definition Graphic.java:10
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
static void sendProjectile(Projectile projectile, Position position, int instance, int lock, byte offsetX, byte offsetY)
Sends a world projectile.
Definition World.java:295
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 Callisto.java:83
void block(Mob attacker, Npc defender, Hit hit, CombatType combatType)
Definition Callisto.java:57
int getAttackDelay(Npc attacker, Mob defender, FightType fightType)
Definition Callisto.java:73
Handles the mob class.
Definition Mob.java:66
void interact(Mob mob)
Sets the mob interacting with another mob.
Definition Mob.java:278
final boolean isPlayer()
Check if an entity is a player.
Definition Mob.java:564
Optional< Graphic > graphic
Definition Mob.java:91
Represents a non-player character in the in-game world.
Definition Npc.java:29
Combat< Npc > getCombat()
The combat of the mob.
Definition Npc.java:156
Represents a PathFinder which is meant to be used to check projectiles passage in a straight line.
static boolean checkLine(Interactable source, Interactable target)
Represents a single tile on the game world.
Definition Position.java:14
int getY()
Gets the absolute y coordinate.
Definition Position.java:46
int getX()
Gets the absolute x coordinate.
Definition Position.java:41
Position transform(int diffX, int diffY, int diffZ)
Creates a new location based on this location.
Position copy()
Creates a deep copy of this location.
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 boolean success(double value)
Determines if a pseudorandomly generated double rounded to two decimal places is below or equal to va...
Handles miscellaneous methods.
Definition Utility.java:27
static int random(int bound)
Definition Utility.java:239
static Position findBestInside(Interactable source, Interactable target)
Definition Utility.java:498
Represents different priorities for updating.
The enumerated type whose elements represent the fighting types.
Represents the enumerated directions an entity can walk or face.
static Direction getFollowDirection(Position source, Position target)
static Direction getOppositeDirection(Direction direction)