RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
ChaosFanatic.java
1package com.osroyale.game.world.entity.combat.strategy.npc.boss;
2
3import com.osroyale.game.Animation;
4import com.osroyale.game.Graphic;
5import com.osroyale.game.Projectile;
6import com.osroyale.game.UpdatePriority;
7import com.osroyale.game.world.World;
8import com.osroyale.game.world.entity.combat.CombatType;
9import com.osroyale.game.world.entity.combat.attack.FightType;
10import com.osroyale.game.world.entity.combat.hit.CombatHit;
11import com.osroyale.game.world.entity.combat.hit.Hit;
12import com.osroyale.game.world.entity.combat.projectile.CombatProjectile;
13import com.osroyale.game.world.entity.combat.strategy.CombatStrategy;
14import com.osroyale.game.world.entity.combat.strategy.npc.MultiStrategy;
15import com.osroyale.game.world.entity.combat.strategy.npc.NpcMagicStrategy;
16import com.osroyale.game.world.entity.combat.strategy.npc.NpcMeleeStrategy;
17import com.osroyale.game.world.entity.combat.strategy.npc.NpcRangedStrategy;
18import com.osroyale.game.world.entity.mob.Mob;
19import com.osroyale.game.world.entity.mob.npc.Npc;
20import com.osroyale.game.world.entity.mob.player.Player;
21import com.osroyale.game.world.items.Item;
22import com.osroyale.game.world.position.Position;
23import com.osroyale.net.packet.out.SendMessage;
24import com.osroyale.util.Utility;
25
26import static com.osroyale.game.world.entity.combat.CombatUtil.createStrategyArray;
27import static com.osroyale.game.world.entity.combat.CombatUtil.randomStrategy;
28import static com.osroyale.game.world.entity.combat.projectile.CombatProjectile.getDefinition;
29
68
69public class ChaosFanatic extends MultiStrategy {
70 private static RainAttack RAIN = new RainAttack();
71 private static RangeAttack RANGE = new RangeAttack();
72 private static final CombatStrategy<Npc>[] FULL_STRATEGIES = createStrategyArray(RAIN, RANGE, NpcMeleeStrategy.get(), RANGE, NpcMeleeStrategy.get());
73 private static final CombatStrategy<Npc>[] NON_MELEE = createStrategyArray(RAIN, RANGE, RANGE, RANGE, RANGE);
74
75 private static final String[] MESSAGES = {
76 "Burn!",
77 "WEUGH!",
78 "Develish Oxen Roll!",
79 "All your wilderness are belong to them!",
80 "AhehHeheuhHhahueHuUEehEahAH",
81 "I shall call him squidgy and he shall be my squidgy!",
82 };
83
84 public ChaosFanatic() {
85 currentStrategy = randomStrategy(NON_MELEE);
86 }
87
88 @Override
89 public boolean canAttack(Npc attacker, Mob defender) {
90 if (!currentStrategy.withinDistance(attacker, defender)) {
91 currentStrategy = randomStrategy(NON_MELEE);
92 }
93 return currentStrategy.canAttack(attacker, defender);
94 }
95
96 @Override
97 public void block(Mob attacker, Npc defender, Hit hit, CombatType combatType) {
98 currentStrategy.block(attacker, defender, hit, combatType);
99 defender.getCombat().attack(attacker);
100 }
101
102 @Override
103 public void finishOutgoing(Npc attacker, Mob defender) {
104 currentStrategy.finishOutgoing(attacker, defender);
105 if (NpcMeleeStrategy.get().withinDistance(attacker, defender)) {
106 currentStrategy = randomStrategy(FULL_STRATEGIES);
107 } else {
108 currentStrategy = randomStrategy(NON_MELEE);
109 }
110 attacker.speak(Utility.randomElement(MESSAGES));
111 }
112
113 @Override
114 public int getAttackDelay(Npc attacker, Mob defender, FightType fightType) {
115 return attacker.definition.getAttackDelay();
116 }
117
118 private static class RainAttack extends NpcMagicStrategy {
119 public RainAttack() {
120 super(CombatProjectile.getDefinition("EMPTY"));
121 }
122
123 @Override
124 public void hit(Npc attacker, Mob defender, Hit hit) { }
125
126 @Override
127 public void start(Npc attacker, Mob defender, Hit[] hits) {
128 attacker.animate(new Animation(1162, UpdatePriority.VERY_HIGH));
129 for (int i = 0; i < 3; i++) {
130 int offsetX = defender.getX() - attacker.getX();
131 int offsetY = defender.getY() - attacker.getY();
132 if (i == 0 || i == 2) {
133 offsetX += i == 0 ? -1 : 1;
134 offsetY++;
135 }
136 World.sendProjectile(new Projectile(551, 46, 80, 43, 31), attacker.getPosition(), attacker.instance,-1, (byte) offsetX, (byte) offsetY);
137 Position end = new Position(attacker.getX() + offsetX, attacker.getY() + offsetY, 0);
138 World.schedule(3, () -> {
139 World.sendGraphic(new Graphic(131, UpdatePriority.HIGH), end, attacker.instance);
140 if (defender.getPosition().equals(end)) {
141 defender.damage(nextMagicHit(attacker, defender, 31));
142 if (defender.isPlayer()) {
143 Player player = defender.getPlayer();
144 Item[] equipment = player.equipment.toNonNullArray();
145 if (equipment.length == 0)
146 return;
147 if (player.inventory.isFull()) {
148 return;
149 }
150 Item disarm = Utility.randomElement(equipment);
151 if (disarm == null)
152 return;
153 player.equipment.unEquip(disarm);
154 player.send(new SendMessage("Chaos fanatic has removed your " + Utility.formatName(disarm.getEquipmentType().name().toLowerCase()) + "."));
155 player.graphic(new Graphic(557, true, UpdatePriority.HIGH));
156 }
157 }
158 });
159 }
160 }
161
162 @Override
163 public void attack(Npc attacker, Mob defender, Hit hit) {
164 }
165
166 @Override
167 public CombatHit[] getHits(Npc attacker, Mob defender) {
168 CombatHit hit = nextMagicHit(attacker, defender, 31);
169 hit.setAccurate(false);
170 return new CombatHit[]{hit};
171 }
172
173 @Override
174 public int modifyAccuracy(Npc attacker, Mob defender, int roll) {
175 return roll + 50_000;
176 }
177 }
178
179 private static class RangeAttack extends NpcRangedStrategy {
180 public RangeAttack() {
181 super(getDefinition("Chaos Fanatic Range"));
182 }
183 }
184}
static void sendGraphic(Graphic graphic, Position position, int instance)
Definition World.java:305
static void schedule(Task task)
Definition World.java:284
static void sendProjectile(Projectile projectile, Position position, int instance, int lock, byte offsetX, byte offsetY)
Definition World.java:332
void speak(String forceChat)
Definition Mob.java:164
abstract Combat<? extends Mob > getCombat()
static< T > T randomElement(Collection< T > collection)
Definition Utility.java:285