RuneHive-Game
Loading...
Searching...
No Matches
ChaosFanatic.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.world.World;
8import com.runehive.game.world.entity.combat.CombatType;
9import com.runehive.game.world.entity.combat.attack.FightType;
10import com.runehive.game.world.entity.combat.hit.CombatHit;
11import com.runehive.game.world.entity.combat.hit.Hit;
12import com.runehive.game.world.entity.combat.projectile.CombatProjectile;
13import com.runehive.game.world.entity.combat.strategy.CombatStrategy;
14import com.runehive.game.world.entity.combat.strategy.npc.MultiStrategy;
15import com.runehive.game.world.entity.combat.strategy.npc.NpcMagicStrategy;
16import com.runehive.game.world.entity.combat.strategy.npc.NpcMeleeStrategy;
17import com.runehive.game.world.entity.combat.strategy.npc.NpcRangedStrategy;
18import com.runehive.game.world.entity.mob.Mob;
19import com.runehive.game.world.entity.mob.npc.Npc;
20import com.runehive.game.world.entity.mob.player.Player;
21import com.runehive.game.world.items.Item;
22import com.runehive.game.world.position.Position;
23import com.runehive.net.packet.out.SendMessage;
24import com.runehive.util.Utility;
25
26import static com.runehive.game.world.entity.combat.CombatUtil.createStrategyArray;
27import static com.runehive.game.world.entity.combat.CombatUtil.randomStrategy;
28import static com.runehive.game.world.entity.combat.projectile.CombatProjectile.getDefinition;
29
30/**
31 * @author Daniel
32 */
33public class ChaosFanatic extends MultiStrategy {
34 private static RainAttack RAIN = new RainAttack();
35 private static RangeAttack RANGE = new RangeAttack();
36 private static final CombatStrategy<Npc>[] FULL_STRATEGIES = createStrategyArray(RAIN, RANGE, NpcMeleeStrategy.get(), RANGE, NpcMeleeStrategy.get());
37 private static final CombatStrategy<Npc>[] NON_MELEE = createStrategyArray(RAIN, RANGE, RANGE, RANGE, RANGE);
38
39 private static final String[] MESSAGES = {
40 "Burn!",
41 "WEUGH!",
42 "Develish Oxen Roll!",
43 "All your wilderness are belong to them!",
44 "AhehHeheuhHhahueHuUEehEahAH",
45 "I shall call him squidgy and he shall be my squidgy!",
46 };
47
48 public ChaosFanatic() {
49 currentStrategy = randomStrategy(NON_MELEE);
50 }
51
52 @Override
53 public boolean canAttack(Npc attacker, Mob defender) {
54 if (!currentStrategy.withinDistance(attacker, defender)) {
55 currentStrategy = randomStrategy(NON_MELEE);
56 }
57 return currentStrategy.canAttack(attacker, defender);
58 }
59
60 @Override
61 public void block(Mob attacker, Npc defender, Hit hit, CombatType combatType) {
62 currentStrategy.block(attacker, defender, hit, combatType);
63 defender.getCombat().attack(attacker);
64 }
65
66 @Override
67 public void finishOutgoing(Npc attacker, Mob defender) {
68 currentStrategy.finishOutgoing(attacker, defender);
69 if (NpcMeleeStrategy.get().withinDistance(attacker, defender)) {
70 currentStrategy = randomStrategy(FULL_STRATEGIES);
71 } else {
72 currentStrategy = randomStrategy(NON_MELEE);
73 }
75 }
76
77 @Override
78 public int getAttackDelay(Npc attacker, Mob defender, FightType fightType) {
79 return attacker.definition.getAttackDelay();
80 }
81
82 private static class RainAttack extends NpcMagicStrategy {
83 public RainAttack() {
84 super(CombatProjectile.getDefinition("EMPTY"));
85 }
86
87 @Override
88 public void hit(Npc attacker, Mob defender, Hit hit) { }
89
90 @Override
91 public void start(Npc attacker, Mob defender, Hit[] hits) {
92 attacker.animate(new Animation(1162, UpdatePriority.VERY_HIGH));
93 for (int i = 0; i < 3; i++) {
94 int offsetX = defender.getX() - attacker.getX();
95 int offsetY = defender.getY() - attacker.getY();
96 if (i == 0 || i == 2) {
97 offsetX += i == 0 ? -1 : 1;
98 offsetY++;
99 }
100 World.sendProjectile(new Projectile(551, 46, 80, 43, 31), attacker.getPosition(), attacker.instance,-1, (byte) offsetX, (byte) offsetY);
101 Position end = new Position(attacker.getX() + offsetX, attacker.getY() + offsetY, 0);
102 World.schedule(3, () -> {
103 World.sendGraphic(new Graphic(131, UpdatePriority.HIGH), end, attacker.instance);
104 if (defender.getPosition().equals(end)) {
105 defender.damage(nextMagicHit(attacker, defender, 31));
106 if (defender.isPlayer()) {
107 Player player = defender.getPlayer();
108 Item[] equipment = player.equipment.toNonNullArray();
109 if (equipment.length == 0)
110 return;
111 if (player.inventory.isFull()) {
112 return;
113 }
114 Item disarm = Utility.randomElement(equipment);
115 if (disarm == null)
116 return;
117 player.equipment.unEquip(disarm);
118 player.send(new SendMessage("Chaos fanatic has removed your " + Utility.formatName(disarm.getEquipmentType().name().toLowerCase()) + "."));
119 player.graphic(new Graphic(557, true, UpdatePriority.HIGH));
120 }
121 }
122 });
123 }
124 }
125
126 @Override
127 public void attack(Npc attacker, Mob defender, Hit hit) {
128 }
129
130 @Override
131 public CombatHit[] getHits(Npc attacker, Mob defender) {
132 CombatHit hit = nextMagicHit(attacker, defender, 31);
133 hit.setAccurate(false);
134 return new CombatHit[]{hit};
135 }
136
137 @Override
138 public int modifyAccuracy(Npc attacker, Mob defender, int roll) {
139 return roll + 50_000;
140 }
141 }
142
143 private static class RangeAttack extends NpcRangedStrategy {
144 public RangeAttack() {
145 super(getDefinition("Chaos Fanatic Range"));
146 }
147 }
148}
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 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 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)
int getAttackDelay(Npc attacker, Mob defender, FightType fightType)
void block(Mob attacker, Npc defender, Hit hit, CombatType combatType)
Handles the mob class.
Definition Mob.java:66
void speak(String forceChat)
Sets the mob's forced chat.
Definition Mob.java:127
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
Combat< Npc > getCombat()
The combat of the mob.
Definition Npc.java:156
This class represents a character controlled by a player.
Definition Player.java:125
The container class that represents an item that can be interacted with.
Definition Item.java:21
EquipmentType getEquipmentType()
Definition Item.java:441
Represents a single tile on the game world.
Definition Position.java:14
The OutgoingPacket that sends a message to a Players chatbox in the client.
Handles miscellaneous methods.
Definition Utility.java:27
static String formatName(final String input)
Definition Utility.java:645
static< T > T randomElement(Collection< T > collection)
Picks a random element out of any array type.
Definition Utility.java:248
Represents different priorities for updating.
The enumerated type whose elements represent the fighting types.