RuneHive-Game
Loading...
Searching...
No Matches
FightCavesListener.java
Go to the documentation of this file.
1package com.runehive.content.activity.impl.fightcaves;
2
3import com.runehive.game.world.entity.combat.CombatType;
4import com.runehive.game.world.entity.combat.hit.Hit;
5import com.runehive.game.world.entity.mob.Mob;
6import com.runehive.game.world.entity.mob.npc.Npc;
7import com.runehive.content.activity.ActivityListener;
8import com.runehive.util.Utility;
9
10/**
11 * The {@link FightCaves} combat listener for all mobs in the activity.
12 *
13 * @author Michael | Chex
14 */
15public class FightCavesListener extends ActivityListener<FightCaves> {
16
17 /** Constructs a new {@code FightCavesListener} object for a specific {@link FightCaves} activity. */
18 public FightCavesListener(FightCaves minigame) {
19 super(minigame);
20 }
21
22 @Override
23 public void block(Mob attacker, Mob defender, Hit hit, CombatType combatType) {
24 if (!defender.isNpc())
25 return;
26 if (defender.id != 3127)
27 return;
28 if (Utility.getPercentageAmount(defender.getCurrentHealth(), defender.getMaximumHealth()) > 49)
29 return;
30 for (Npc npc : activity.npcs) {
31 if (npc.id == 3128 && (npc.getCombat().inCombatWith(attacker) || Utility.withinDistance(defender, npc, 5))) {
32 defender.heal(1);
33 }
34 }
35 }
36
37 @Override
38 public void onDeath(Mob attacker, Mob defender, Hit hit) {
39 activity.handleDeath(defender);
40 }
41}
void hit(Mob attacker, Mob defender, Hit hit)
ActivityListener(T activity)
Constructs a new ActivityListener for a activity.
FightCavesListener(FightCaves minigame)
Constructs a new FightCavesListener object for a specific FightCaves activity.
void block(Mob attacker, Mob defender, Hit hit, CombatType combatType)
A Hit object holds the damage amount and hitsplat data.
Definition Hit.java:10
Handles the mob class.
Definition Mob.java:66
final boolean isNpc()
Check if an entity is an npc.
Definition Mob.java:550
Represents a non-player character in the in-game world.
Definition Npc.java:29
Combat< Npc > getCombat()
The combat of the mob.
Definition Npc.java:156
Handles miscellaneous methods.
Definition Utility.java:27
static double getPercentageAmount(int progress, int total)
Gets a percentage amount.
Definition Utility.java:36
static boolean withinDistance(Interactable source, Interactable target, int radius)
Definition Utility.java:470