RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
NpcMeleeStrategy.java
1package com.osroyale.game.world.entity.combat.strategy.npc;
2
3import com.osroyale.game.Animation;
4import com.osroyale.game.UpdatePriority;
5import com.osroyale.game.world.entity.combat.CombatType;
6import com.osroyale.game.world.entity.combat.attack.FightType;
7import com.osroyale.game.world.entity.combat.effect.impl.CombatPoisonEffect;
8import com.osroyale.game.world.entity.combat.effect.impl.CombatVenomEffect;
9import com.osroyale.game.world.entity.combat.hit.CombatHit;
10import com.osroyale.game.world.entity.combat.hit.Hit;
11import com.osroyale.game.world.entity.combat.strategy.basic.MeleeStrategy;
12import com.osroyale.game.world.entity.mob.Mob;
13import com.osroyale.game.world.entity.mob.npc.Npc;
14import com.osroyale.util.RandomUtils;
15
16public class NpcMeleeStrategy extends MeleeStrategy<Npc> {
17
18 private static final NpcMeleeStrategy INSTANCE = new NpcMeleeStrategy();
19
20 protected NpcMeleeStrategy() {
21 }
22
23 @Override
24 public void start(Npc attacker, Mob defender, Hit[] hits) {
25 attacker.animate(getAttackAnimation(attacker, defender), true);
26 }
27
28 @Override
29 public void attack(Npc attacker, Mob defender, Hit hit) {
30 if (!attacker.definition.isPoisonous()) {
31 return;
32 }
33
34 if (CombatVenomEffect.isVenomous(attacker) && RandomUtils.success(0.25)) {
35 defender.venom();
36 } else {
37 CombatPoisonEffect.getPoisonType(attacker.id).ifPresent(defender::poison);
38 }
39 }
40
41 @Override
42 public int getAttackDelay(Npc attacker, Mob defender, FightType fightType) {
43 return attacker.definition.getAttackDelay();
44 }
45
46 @Override
47 public int getAttackDistance(Npc attacker, FightType fightType) {
48/* final NpcDefinition definition = attacker.definition;
49 return definition == null ? 1 : definition.getSize();*/
50 return 1;
51 }
52
53 @Override
54 public CombatHit[] getHits(Npc attacker, Mob defender) {
55 return new CombatHit[]{nextMeleeHit(attacker, defender)};
56 }
57
58 @Override
59 public Animation getAttackAnimation(Npc attacker, Mob defender) {
60 return new Animation(attacker.definition.getAttackAnimation(), UpdatePriority.HIGH);
61 }
62
63 @Override
64 public boolean canAttack(Npc attacker, Mob defender) {
65 return true;
66 }
67
68 @Override
69 public CombatType getCombatType() {
70 return CombatType.MELEE;
71 }
72
73 public static NpcMeleeStrategy get() {
74 return INSTANCE;
75 }
76
77}