1package com.osroyale.game.world.entity.combat.strategy;
3import com.osroyale.game.Animation;
4import com.osroyale.game.Graphic;
5import com.osroyale.game.Projectile;
6import com.osroyale.game.world.entity.combat.CombatType;
7import com.osroyale.game.world.entity.combat.attack.FightType;
8import com.osroyale.game.world.entity.combat.attack.FormulaFactory;
9import com.osroyale.game.world.entity.combat.attack.listener.CombatListener;
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.mob.Mob;
15import java.util.Optional;
17import static com.osroyale.game.world.entity.combat.CombatUtil.getHitDelay;
18import static com.osroyale.game.world.entity.combat.CombatUtil.getHitsplatDelay;
19import static com.osroyale.game.world.entity.combat.attack.FormulaFactory.getMaxHit;
23 public abstract int getAttackDelay(T attacker, Mob defender, FightType fightType);
25 public abstract int getAttackDistance(T attacker, FightType fightType);
27 public abstract CombatHit[] getHits(T attacker, Mob defender);
29 public abstract Animation getAttackAnimation(T attacker, Mob defender);
32 public abstract boolean canAttack(T attacker, Mob defender);
35 public boolean canOtherAttack(Mob attacker, T defender) {
40 public void start(T attacker, Mob defender, Hit[] hits) {
44 public void attack(T attacker, Mob defender, Hit hit) {
48 public void hit(T attacker, Mob defender, Hit hit) {
52 public void hitsplat(T attacker, Mob defender, Hit hit) {
56 public void block(Mob attacker, T defender, Hit hit, CombatType combatType) {
60 public void preDeath(Mob attacker, T defender, Hit hit) {
64 public void onDeath(Mob attacker, T defender, Hit hit) {
68 public void preKill(Mob attacker, Mob defender, Hit hit) {
72 public void onKill(T attacker, Mob defender, Hit hit) {
76 public void finishOutgoing(T attacker, Mob defender) {
80 public void finishIncoming(Mob attacker, T defender) {
83 public abstract CombatType getCombatType();
87 protected CombatHit nextMeleeHit(T attacker, Mob defender) {
88 int max = getMaxHit(attacker, defender, CombatType.MELEE);
89 return nextMeleeHit(attacker, defender, max,
false);
92 protected final CombatHit nextRangedHit(T attacker, Mob defender) {
93 int max = getMaxHit(attacker, defender, CombatType.RANGED);
94 return nextRangedHit(attacker, defender, max);
97 protected final CombatHit nextMagicHit(T attacker, Mob defender) {
98 int max = getMaxHit(attacker, defender, CombatType.MAGIC);
99 return nextMagicHit(attacker, defender, max);
104 protected CombatHit nextMeleeHit(T attacker, Mob defender,
int max) {
105 int hitDelay = getHitDelay(attacker, defender, CombatType.MELEE);
106 int hitsplatDelay = getHitsplatDelay(CombatType.MELEE);
107 return nextMeleeHit(attacker, defender, max, hitDelay, hitsplatDelay,
false);
110 protected CombatHit nextMeleeHit(T attacker, Mob defender,
int max,
boolean multipleHitsAllowed) {
111 int hitDelay = getHitDelay(attacker, defender, CombatType.MELEE);
112 int hitsplatDelay = getHitsplatDelay(CombatType.MELEE);
113 return nextMeleeHit(attacker, defender, max, hitDelay, hitsplatDelay, multipleHitsAllowed);
116 protected final CombatHit nextRangedHit(T attacker, Mob defender,
int max) {
117 int hitDelay = getHitDelay(attacker, defender, CombatType.RANGED);
118 int hitsplatDelay = getHitsplatDelay(CombatType.RANGED);
119 return nextRangedHit(attacker, defender, max, hitDelay, hitsplatDelay);
122 protected final CombatHit nextMagicHit(T attacker, Mob defender,
int max) {
123 int hitDelay = getHitDelay(attacker, defender, CombatType.MAGIC);
124 int hitsplatDelay = getHitsplatDelay(CombatType.MAGIC);
125 return nextMagicHit(attacker, defender, max, hitDelay, hitsplatDelay);
130 protected final CombatHit nextRangedHit(T attacker, Mob defender,
int max, CombatProjectile projectile) {
131 int hitDelay = getHitDelay(attacker, defender, CombatType.RANGED);
132 int hitsplatDelay = getHitsplatDelay(CombatType.RANGED);
133 hitDelay = projectile.getHitDelay().orElse(hitDelay);
134 hitsplatDelay = projectile.getHitsplatDelay().orElse(hitsplatDelay);
135 return nextRangedHit(attacker, defender, max, hitDelay, hitsplatDelay);
138 protected CombatHit nextMagicHit(T attacker, Mob defender,
int max, CombatProjectile projectile) {
139 int hitDelay = getHitDelay(attacker, defender, CombatType.MAGIC);
140 int hitsplatDelay = getHitsplatDelay(CombatType.MAGIC);
141 hitDelay = projectile.getHitDelay().orElse(hitDelay);
142 hitsplatDelay = projectile.getHitsplatDelay().orElse(hitsplatDelay);
143 return nextMagicHit(attacker, defender, max, hitDelay, hitsplatDelay);
148 protected final CombatHit nextRangedHit(T attacker, Mob defender, CombatProjectile projectile) {
149 int max = getMaxHit(attacker, defender, CombatType.RANGED);
150 return nextRangedHit(attacker, defender, max, projectile);
153 protected CombatHit nextMagicHit(T attacker, Mob defender, CombatProjectile projectile) {
154 int max = projectile.getMaxHit();
155 return nextMagicHit(attacker, defender, max, projectile);
160 protected CombatHit nextMeleeHit(T attacker, Mob defender,
int max,
int hitDelay,
int hitsplatDelay) {
161 return nextMeleeHit(attacker, defender, max, hitDelay, hitsplatDelay,
false);
164 protected CombatHit nextMeleeHit(T attacker, Mob defender,
int max,
int hitDelay,
int hitsplatDelay,
boolean multipleHitsAllowed) {
165 Hit hit = FormulaFactory.nextMeleeHit(attacker, defender, max, multipleHitsAllowed);
167 if(hit.getMultipleHits() !=
null)
168 return new CombatHit(hit.getMultipleHits(), hitDelay, hitsplatDelay);
170 return new CombatHit(hit, hitDelay, hitsplatDelay);
173 protected CombatHit nextRangedHit(T attacker, Mob defender,
int max,
int hitDelay,
int hitsplatDelay) {
174 return new CombatHit(FormulaFactory.nextRangedHit(attacker, defender, max), hitDelay, hitsplatDelay);
177 protected final CombatHit nextMagicHit(T attacker, Mob defender,
int max,
int hitDelay,
int hitsplatDelay) {
178 return new CombatHit(FormulaFactory.nextMagicHit(attacker, defender, max), hitDelay, hitsplatDelay);
182 public void onDamage(T defender, Hit hit) {
186 public static int getProjectileDuration(
final CombatProjectile combatProjectile) {
187 final Optional<Projectile> optProjectile = combatProjectile.getProjectile();
188 if (optProjectile.isPresent()) {
189 final Projectile projectile = optProjectile.get();
190 return projectile.getClientTicks();
195 public static Graphic getEndGraphic(
final CombatProjectile combatProjectile,
196 final boolean splash,
final Graphic splashGraphic) {
197 final int duration = getProjectileDuration(combatProjectile);
198 return getEndGraphic(combatProjectile.getEnd(), splash, splashGraphic, duration);
201 public static Graphic getEndGraphic(
final CombatProjectile combatProjectile,
202 final boolean splash,
final Graphic splashGraphic,
203 final int duration) {
204 return getEndGraphic(combatProjectile.getEnd(), splash, splashGraphic, duration);
207 public static Graphic getEndGraphic(
final Optional<Graphic> end,
208 final boolean splash,
final Graphic splashGraphic,
209 final int duration) {
210 final Graphic base = splash ? splashGraphic : end.orElse(
null);
211 return base ==
null ? null :
new Graphic(base.getId(), duration, base.getHeight());
214 public static boolean missed(
final Hit... hits) {
215 for (
final Hit hit : hits) {
216 if (hit.isAccurate()) {
223 public CombatProjectile getCombatProjectile() {
227 public boolean isAlwaysAccurate() {