RuneHive-Game
Loading...
Searching...
No Matches
CombatPoisonEffect.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.effect.impl;
2
3import com.runehive.game.world.entity.combat.PoisonType;
4import com.runehive.game.world.entity.combat.effect.CombatEffect;
5import com.runehive.game.world.entity.combat.hit.Hit;
6import com.runehive.game.world.entity.combat.hit.HitIcon;
7import com.runehive.game.world.entity.combat.hit.Hitsplat;
8import com.runehive.game.world.entity.mob.Mob;
9import com.runehive.game.world.entity.mob.npc.definition.NpcDefinition;
10import com.runehive.game.world.entity.mob.player.Player;
11import com.runehive.game.world.items.Item;
12import com.runehive.game.world.items.containers.equipment.Equipment;
13import com.runehive.net.packet.out.SendMessage;
14import com.runehive.net.packet.out.SendPoison;
15
16import java.util.Optional;
17
18/**
19 * The combat effect applied when a character needs to be poisoned.
20 *
21 * @author lare96 <http://github.com/lare96>
22 */
23public final class CombatPoisonEffect extends CombatEffect {
24
25 /** The amount of times this player has been hit. */
26 private int amount;
27
28 /** Creates a new {@link CombatPoisonEffect}. */
30 super(25);
31 }
32
33 @Override
34 public boolean apply(Mob mob) {
35 if (mob.getPoisonType() == null || mob.isPoisoned() || mob.isVenomed()) {
36 return false;
37 }
38
39 if (mob.isNpc() && mob.getNpc().definition.hasPoisonImmunity()) {
40 return false;
41 }
42
43 if (mob.isPlayer() && mob.getPlayer().equipment
44 .retrieve(Equipment.HELM_SLOT)
45 .filter(helm -> helm.getId() == 13197 || helm.getId() == 13199 || helm.getId() == 12931)
46 .isPresent()) {
47 return false;
48 }
49
50 if (mob.isPlayer()) {
51 Player player = mob.getPlayer();
52 if (player.getPoisonImmunity().get() > 0 || mob.isDead())
53 return false;
54 player.send(new SendMessage("You have been poisoned!"));
56 }
57 mob.getPoisonDamage().set(mob.getPoisonType().getDamage());
58 amount = 4;
59 return true;
60 }
61
62 @Override
63 public boolean removeOn(Mob mob) {
64 boolean remove = mob.isVenomed() || !mob.isPoisoned() || mob.isDead();
65 if (remove && mob.isPlayer()) {
66 Player player = (Player) mob;
68 }
69 return remove;
70 }
71
72 @Override
73 public void process(Mob mob) {
74 amount--;
75 mob.damage(new Hit(mob.getPoisonDamage().get(), Hitsplat.POISON, HitIcon.NONE));
76 if (amount == 0) {
77 amount = 4;
78 mob.getPoisonDamage().decrementAndGet();
79 }
80 }
81
82 @Override
83 public boolean onLogin(Mob mob) {
84 boolean poisoned = mob.isPoisoned();
85 if (poisoned && mob.isPlayer()) {
86 mob.getPlayer().send(new SendPoison(SendPoison.PoisonType.REGULAR));
87 }
88 return poisoned;
89 }
90
91 /**
92 * Gets the {@link PoisonType} for {@code item} wrapped in an optional. If a
93 * poison type doesn't exist for the item then an empty optional is
94 * returned.
95 *
96 * @param item the item to get the poison type for
97 * @return the poison type for this item wrapped in an optional, or an empty
98 * optional if no poison type exists
99 */
100 public static Optional<PoisonType> getPoisonType(Item item) {
101 if (item != null) {
102 String name = item.getName();
103 if (name.endsWith("(p)")) {
104 return Optional.of(PoisonType.DEFAULT_MELEE);
105 }
106 if (name.endsWith("(p+)")) {
107 return Optional.of(PoisonType.STRONG_MELEE);
108 }
109 if (name.endsWith("(p++)")) {
110 return Optional.of(PoisonType.SUPER_MELEE);
111 }
112 }
113 return Optional.empty();
114 }
115
116 /**
117 * Gets the {@link PoisonType} for {@code npc} wrapped in an optional. If a
118 * poison type doesn't exist for the NPC then an empty optional is returned.
119 *
120 * @param npc the NPC to get the poison type for
121 * @return the poison type for this NPC wrapped in an optional, or an empty
122 * optional if no poison type exists
123 */
124 public static Optional<PoisonType> getPoisonType(int npc) {
126
127 if (def == null || !def.isAttackable() || !def.isPoisonous()) {
128 return Optional.empty();
129 }
130
131 if (def.getCombatLevel() < 25) {
132 return Optional.of(PoisonType.WEAK_NPC);
133 }
134
135 if (def.getCombatLevel() < 75) {
136 return Optional.of(PoisonType.DEFAULT_NPC);
137 }
138
139 if (def.getCombatLevel() < 200) {
140 return Optional.of(PoisonType.STRONG_NPC);
141 }
142
143 if (def.getCombatLevel() < 225) {
144 return Optional.of(PoisonType.SUPER_NPC);
145 }
146
147 return Optional.of(PoisonType.EXTRAORDINARY_NPC);
148 }
149}
CombatEffect(int delay)
Creates a new CombatEffect.
static Optional< PoisonType > getPoisonType(Item item)
Gets the PoisonType for item wrapped in an optional.
boolean removeOn(Mob mob)
Removes this effect from mob if needed.
void process(Mob mob)
Provides processing for this effect on mob.
boolean onLogin(Mob mob)
Executed on login, primarily used to re-apply the effect to mob.
static Optional< PoisonType > getPoisonType(int npc)
Gets the PoisonType for npc wrapped in an optional.
A Hit object holds the damage amount and hitsplat data.
Definition Hit.java:10
Handles the mob class.
Definition Mob.java:66
static final NpcDefinition[] DEFINITIONS
The array of npc definitions.
This class represents a character controlled by a player.
Definition Player.java:125
The container class that represents an item that can be interacted with.
Definition Item.java:21
The container that manages the equipment for a player.
The OutgoingPacket that sends a message to a Players chatbox in the client.
int get()
Gets the value present within this counter.
The enumerated type whose elements represent the different levels of poison.
SUPER_NPC
The strongest poison type for poisonous NPCs.
STRONG_MELEE
The stronger poison type for melee weapons.
DEFAULT_MELEE
The default poison type for melee weapons.
SUPER_MELEE
The strongest poison type for melee weapons.
WEAK_NPC
The default poison type for poisonous NPCs.
STRONG_NPC
The stronger poison type for poisonous NPCs.
DEFAULT_NPC
The default poison type for poisonous NPCs.
The enumerated type whose elements represent the hit icon of a Hit.
Definition HitIcon.java:8