RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
BrutalDragon.java
1package com.osroyale.game.world.entity.combat.attack.listener.npc.dragon;
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.attack.FightType;
9import com.osroyale.game.world.entity.combat.attack.listener.NpcCombatListenerSignature;
10import com.osroyale.game.world.entity.combat.attack.listener.SimplifiedListener;
11import com.osroyale.game.world.entity.combat.hit.CombatHit;
12import com.osroyale.game.world.entity.combat.hit.Hit;
13import com.osroyale.game.world.entity.combat.projectile.CombatProjectile;
14import com.osroyale.game.world.entity.combat.strategy.CombatStrategy;
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.impl.BrutalDragonfireStrategy;
18import com.osroyale.game.world.entity.combat.strategy.npc.impl.DragonfireStrategy;
19import com.osroyale.game.world.entity.mob.Mob;
20import com.osroyale.game.world.entity.mob.npc.Npc;
21import com.osroyale.util.Utility;
22
23import static com.osroyale.game.world.entity.combat.CombatUtil.createStrategyArray;
24import static com.osroyale.game.world.entity.combat.CombatUtil.randomStrategy;
25import static com.osroyale.game.world.entity.combat.projectile.CombatProjectile.getDefinition;
26
292918, 7273, 7274, 7275, 8081, 8087, 8092
30})
64
65public class BrutalDragon extends SimplifiedListener<Npc> {
66 private static BrutalDragonfireStrategy DRAGONFIRE;
67 private static CombatStrategy<Npc>[] STRATEGIES;
68
69 static {
70 try {
71 DRAGONFIRE = new BrutalDragonfireStrategy(getDefinition("Chromatic dragonfire"));
72 STRATEGIES = createStrategyArray(new CrushMelee(), new StabMelee());
73 } catch (Exception e) {
74 e.printStackTrace();
75 }
76 }
77
78 @Override
79 public boolean canAttack(Npc attacker, Mob defender) {
80 final var style = Utility.random(NpcMeleeStrategy.get().withinDistance(attacker, defender) ? 1 : 2);
81 if (style == 0) {
82 attacker.setStrategy(DRAGONFIRE);
83 } else if (style == 1) {
84 attacker.setStrategy(new MagicAttack());
85 } else {
86 attacker.setStrategy(randomStrategy(STRATEGIES));
87 }
88 return attacker.getStrategy().canAttack(attacker, defender);
89 }
90
91 @Override
92 public void finishOutgoing(Npc attacker, Mob defender) {
93 final var style = Utility.random(NpcMeleeStrategy.get().withinDistance(attacker, defender) ? 1 : 2);
94 if (style == 0) {
95 attacker.setStrategy(DRAGONFIRE);
96 } else if (style == 1) {
97 attacker.setStrategy(new MagicAttack());
98 } else {
99 attacker.setStrategy(randomStrategy(STRATEGIES));
100 }
101 }
102
103 private static final class CrushMelee extends NpcMeleeStrategy {
104 private static final Animation ANIMATION = new Animation(80, UpdatePriority.HIGH);
105
106 @Override
107 public int getAttackDistance(Npc attacker, FightType fightType) {
108 return 1;
109 }
110
111 @Override
112 public Animation getAttackAnimation(Npc attacker, Mob defender) {
113 return ANIMATION;
114 }
115
116 @Override
117 public CombatHit[] getHits(Npc attacker, Mob defender) {
118 return new CombatHit[]{nextMeleeHit(attacker, defender)};
119 }
120 }
121
122 private static final class StabMelee extends NpcMeleeStrategy {
123 private static final Animation ANIMATION = new Animation(91, UpdatePriority.HIGH);
124
125 @Override
126 public int getAttackDistance(Npc attacker, FightType fightType) {
127 return 1;
128 }
129
130 @Override
131 public Animation getAttackAnimation(Npc attacker, Mob defender) {
132 return ANIMATION;
133 }
134
135 @Override
136 public CombatHit[] getHits(Npc attacker, Mob defender) {
137 return new CombatHit[]{nextMeleeHit(attacker, defender)};
138 }
139 }
140
141 private static class MagicAttack extends NpcMagicStrategy {
142 private MagicAttack() {
143 super(getDefinition("EMPTY"));
144 }
145
146 @Override
147 public Animation getAttackAnimation(Npc attacker, Mob defender) {
148 World.sendProjectile(attacker, defender, getMagicProjectile(attacker.getId()));
149 return new Animation(6722, UpdatePriority.VERY_HIGH);
150 }
151
152 @Override
153 public CombatHit[] getHits(Npc attacker, Mob defender) {
154 CombatHit combatHit = nextMagicHit(attacker, defender, getMaxHit(attacker.getId()));
155 combatHit.setAccurate(true);
156 return new CombatHit[] { combatHit };
157 }
158 }
159
160 private static int getMaxHit(int npcId) {
161 return switch (npcId) {
162 case 2918, 8081 -> 18; //green
163 case 7273 -> 21; //blue
164 case 7274, 8087 -> 22; //red
165 case 7275, 8092 -> 29; //black
166 default -> -1;
167 };
168 }
169
170 private static Projectile getMagicProjectile(int npcId) {
171 return switch (npcId) {
172 case 2918, 8081 -> new Projectile(136, 40, 90, 27, 30, 5); //green
173 case 7273 -> new Projectile(133, 40, 90, 27, 30, 5); //blue
174 case 7274, 8087 -> new Projectile(130, 40, 90, 27, 30, 5); //red
175 case 7275, 8092 -> new Projectile(88, 40, 90, 27, 30, 5); //black
176 default -> null;
177 };
178 }
179
180}
static void sendProjectile(Projectile projectile, Position position, int instance, int lock, byte offsetX, byte offsetY)
Definition World.java:332
CombatStrategy< Npc > getStrategy()
Definition Npc.java:198