RuneHive-Game
Loading...
Searching...
No Matches
PrayerListener.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.attack.listener.other;
2
3import com.runehive.game.Graphic;
4import com.runehive.game.UpdatePriority;
5import com.runehive.game.world.entity.combat.CombatType;
6import com.runehive.game.world.entity.combat.CombatUtil;
7import com.runehive.game.world.entity.combat.attack.listener.SimplifiedListener;
8import com.runehive.game.world.entity.combat.hit.Hit;
9import com.runehive.game.world.entity.combat.hit.HitIcon;
10import com.runehive.game.world.entity.mob.Mob;
11import com.runehive.game.world.entity.mob.prayer.Prayer;
12import com.runehive.game.world.entity.skill.Skill;
13import com.runehive.game.world.position.Area;
14import com.runehive.util.RandomUtils;
15
16public class PrayerListener extends SimplifiedListener<Mob> {
17
18 private static final PrayerListener INSTANCE = new PrayerListener();
19
20 private PrayerListener() {}
21
22 @Override
23 public void hit(Mob attacker, Mob defender, Hit hit) {
24 if (attacker.prayer.isActive(Prayer.SMITE)) {
25 defender.skills.get(Skill.PRAYER).removeLevel(hit.getDamage() / 4);
26 defender.skills.refresh(Skill.PRAYER);
27 }
28 }
29
30 @Override
31 public void block(Mob attacker, Mob defender, Hit hit, CombatType combatType) {
32 int health = defender.getCurrentHealth() - hit.getDamage();
33 if (defender.prayer.isActive(Prayer.REDEMPTION) && health < defender.getMaximumHealth() / 10) {
34 Skill skill = defender.skills.get(Skill.PRAYER);
35 int amount = skill.getLevel() / 4;
36 defender.heal(amount);
37 defender.graphic(new Graphic(436, UpdatePriority.HIGH));
38 if (defender.isPlayer())
39 defender.getPlayer().playerAssistant.drainPrayer(skill.getLevel());
40 }
41 }
42
43 @Override
44 public void preDeath(Mob attacker, Mob defender, Hit hit) {
45 if (defender.prayer.isActive(Prayer.RETRIBUTION)) {
46 int max = defender.skills.getMaxLevel(Skill.PRAYER) / 4;
47 defender.graphic(new Graphic(437, UpdatePriority.HIGH));
48
49 if (!Area.inMulti(defender)) {
50 attacker.damage(new Hit(RandomUtils.inclusive(max), HitIcon.NONE));
51 } else {
52 CombatUtil.areaAction(defender, 3 * 3, 1, other -> {
53 int damage = RandomUtils.inclusive(max);
54 other.damage(new Hit(damage, HitIcon.NONE));
55 });
56 }
57 }
58 }
59
60 public static PrayerListener get() {
61 return INSTANCE;
62 }
63
64}
Represents a single graphic that can be used by entities.
Definition Graphic.java:10
A collection of util methods and constants related to combat.
static void areaAction(Mob mob, Consumer< Mob > action)
Executes an action for mobs within a 3x3 square, including the source mob.
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 isPlayer()
Check if an entity is a player.
Definition Mob.java:564
Optional< Graphic > graphic
Definition Mob.java:91
boolean isActive(Prayer... prayers)
Checks if all given prayers are active.
Represents a trainable and usable skill.
Definition Skill.java:18
static final int PRAYER
The prayer skill id.
Definition Skill.java:36
void removeLevel(int amount)
Removes levels from this skill by the given amount.
Definition Skill.java:325
int getMaxLevel(int id)
Gets the highest possible level of a skill.
Skill get(int id)
Gets the skill for an id.
void refresh()
Refreshes all the skills for the mob.
Handles checking if mobs are in a certain area.
Definition Area.java:13
static boolean inMulti(Entity entity)
Definition Area.java:263
A static-util class that provides additional functionality for generating pseudo-random numbers.
static int inclusive(int min, int max)
Returns a pseudo-random int value between inclusive min and inclusive max.
Represents different priorities for updating.
The enumerated type whose elements represent the hit icon of a Hit.
Definition HitIcon.java:8