RuneHive-Game
Loading...
Searching...
No Matches
NpcMeleeStrategy.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.strategy.npc;
2
3import com.runehive.game.Animation;
4import com.runehive.game.UpdatePriority;
5import com.runehive.game.world.entity.combat.CombatType;
6import com.runehive.game.world.entity.combat.attack.FightType;
7import com.runehive.game.world.entity.combat.effect.impl.CombatPoisonEffect;
8import com.runehive.game.world.entity.combat.effect.impl.CombatVenomEffect;
9import com.runehive.game.world.entity.combat.hit.CombatHit;
10import com.runehive.game.world.entity.combat.hit.Hit;
11import com.runehive.game.world.entity.combat.strategy.basic.MeleeStrategy;
12import com.runehive.game.world.entity.mob.Mob;
13import com.runehive.game.world.entity.mob.npc.Npc;
14import com.runehive.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) {
61 }
62
63 @Override
64 public boolean canAttack(Npc attacker, Mob defender) {
65 return true;
66 }
67
68 @Override
70 return CombatType.MELEE;
71 }
72
73 public static NpcMeleeStrategy get() {
74 return INSTANCE;
75 }
76
77}
Class that models a single animation used by an entity.
The combat effect applied when a character needs to be poisoned.
static Optional< PoisonType > getPoisonType(Item item)
Gets the PoisonType for item wrapped in an optional.
The combat effect applied when a character needs to be venomed.
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
void hit(T attacker, Mob defender, Hit hit)
Called when the attacking mob performs an attack on the defender.
int getAttackDelay(Npc attacker, Mob defender, FightType fightType)
Handles the mob class.
Definition Mob.java:66
void venom()
Applies venom to the entity.
Definition Mob.java:508
Represents a non-player character in the in-game world.
Definition Npc.java:29
A static-util class that provides additional functionality for generating pseudo-random numbers.
static boolean success(double value)
Determines if a pseudorandomly generated double rounded to two decimal places is below or equal to va...
Represents different priorities for updating.
The enumerated type whose elements represent the fighting types.