RuneHive-Game
Loading...
Searching...
No Matches
ToxicBlowpipeStrategy.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.strategy.player.custom;
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.hit.CombatHit;
9import com.runehive.game.world.entity.combat.hit.Hit;
10import com.runehive.game.world.entity.combat.ranged.RangedAmmunition;
11import com.runehive.game.world.entity.combat.strategy.basic.RangedStrategy;
12import com.runehive.game.world.entity.mob.Mob;
13import com.runehive.game.world.entity.mob.player.Player;
14import com.runehive.game.world.entity.mob.player.PlayerRight;
15import com.runehive.game.world.items.Item;
16import com.runehive.game.world.items.containers.equipment.Equipment;
17import com.runehive.game.world.items.ground.GroundItem;
18import com.runehive.game.world.position.Area;
19import com.runehive.game.world.position.Position;
20import com.runehive.net.packet.out.SendMessage;
21import com.runehive.util.RandomUtils;
22
23public class ToxicBlowpipeStrategy extends RangedStrategy<Player> {
24
26
27 @Override
28 public boolean canAttack(Player attacker, Mob defender) {
30
31 if (weapon == null) {
32 attacker.getCombat().reset();
33 return false;
34 }
35
36 Item ammo = attacker.blowpipeDarts;
37
38 if (ammo == null) {
39 return false;
40 }
41
42 RangedAmmunition ammu = RangedAmmunition.find(null, ammo);
43 if (ammu == null || !ammu.isDart()) {
44 attacker.message("Your blowpipe is not using darts for ammunition!");
45 return false;
46 }
47
48 if (ammo.getAmount() >= 1) {
49 if (attacker.blowpipeScales >= 3) {
50 return true;
51 }
52 attacker.send(new SendMessage("Your blowpipe requires more scales!"));
53 } else {
54 attacker.send(new SendMessage("You need some ammunition to use this weapon!"));
55 }
56
57 attacker.getCombat().reset();
58 return false;
59 }
60
61 @Override
62 public void start(Player attacker, Mob defender, Hit[] hits) {
63 if (attacker.isSpecialActivated()) {
64 attacker.getCombatSpecial().drain(attacker);
65 }
66
67 if (attacker.getCombat().getDefender() == defender) {
68 attacker.animate(getAttackAnimation(attacker, defender), true);
69 attacker.rangedAmmo.sendProjectile(attacker, defender);
70
71 if (!defender.isPlayer() || !PlayerRight.isIronman(attacker)) {
72 addCombatExperience(attacker, hits);
73 }
74 }
75 }
76
77 @Override
78 public void attack(Player attacker, Mob defender, Hit hit) {
79 Item darts = attacker.blowpipeDarts;
80 removeAmmunition(attacker, defender);
81
82 if (hit.getDamage() > 1) {
83 if (RandomUtils.success(0.25)) {
84 defender.venom();
85 } else {
86 CombatPoisonEffect.getPoisonType(darts).ifPresent(defender::poison);
87 }
88 }
89 }
90
91 @Override
92 public Animation getAttackAnimation(Player attacker, Mob defender) {
93 int animation = attacker.getCombat().getFightType().getAnimation();
94 return new Animation(animation, UpdatePriority.HIGH);
95 }
96
97 @Override
98 public int getAttackDelay(Player attacker, Mob defender, FightType fightType) {
99 int delay = attacker.getCombat().getFightType().getDelay();
100 if (defender.isNpc())
101 return delay - 1;
102 return delay;
103 }
104
105 @Override
106 public int getAttackDistance(Player attacker, FightType fightType) {
107 return fightType.getDistance();
108 }
109
110 @Override
111 public CombatHit[] getHits(Player attacker, Mob defender) {
112 return new CombatHit[]{nextRangedHit(attacker, defender)};
113 }
114
115 @Override
117 return CombatType.RANGED;
118 }
119
120 private void removeAmmunition(Player attacker, Mob defender) {
121 Item darts = attacker.blowpipeDarts;
122 attacker.blowpipeScales -= 1.5f;
123 if (RandomUtils.success(0.80)) {
124 if (Equipment.hasAssembler(attacker)) {//ok maybe that will work lol
125 return;
126 }
127
128 else if (Equipment.hasAccumulator(attacker) && RandomUtils.success(0.90)) {
129 return;
130 }
131
132 if (Equipment.hasAttractor(attacker) && RandomUtils.success(0.80)) {
133 return;
134 }
135
136 Position dropPoisition = defender.getPosition();
137
138 if (Area.inKraken(attacker) || Area.inZulrah(attacker)) {
139 dropPoisition = attacker.getPosition();
140 }
141 darts.decrementAmount();
142 GroundItem.create(attacker, darts.createWithAmount(1), dropPoisition);
143 }
144
145 if (darts.getAmount() == 0) {
146 attacker.send(new SendMessage("That was the last of your ammunition!"));
147 attacker.blowpipeDarts = null;
148 }
149
150 if (attacker.blowpipeScales == 0) {
151 attacker.send(new SendMessage("Your blowpipe has run out of charges!"));
152 }
153 }
154
155 public static ToxicBlowpipeStrategy get() {
156 return INSTANCE;
157 }
158
159}
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.
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
final CombatHit nextRangedHit(T attacker, Mob defender)
void hit(T attacker, Mob defender, Hit hit)
Called when the attacking mob performs an attack on the defender.
Handles the mob class.
Definition Mob.java:66
final boolean isNpc()
Check if an entity is an npc.
Definition Mob.java:550
final boolean isPlayer()
Check if an entity is a player.
Definition Mob.java:564
void venom()
Applies venom to the entity.
Definition Mob.java:508
This class represents a character controlled by a player.
Definition Player.java:125
Combat< Player > getCombat()
The combat of the mob.
Definition Player.java:759
The container class that represents an item that can be interacted with.
Definition Item.java:21
final void decrementAmount()
Decrements the amount by 1.
Definition Item.java:284
final int getAmount()
Gets the quantity of this item.
Definition Item.java:342
Item createWithAmount(int newAmount)
Creates a new item with newAmount and the same identifier as this instance.
Definition Item.java:158
final Item get(int index)
Gets the Item located on index.
The container that manages the equipment for a player.
Represents a single Ground item on the world map.
static GroundItem create(Player player, Item item)
Creates a new GroundItem object for a player and an item.
Handles checking if mobs are in a certain area.
Definition Area.java:13
static boolean inZulrah(Interactable entity)
Definition Area.java:320
static boolean inKraken(Interactable entity)
Definition Area.java:237
Represents a single tile on the game world.
Definition Position.java:14
The OutgoingPacket that sends a message to a Players chatbox in the client.
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.
static RangedAmmunition find(Item weapon, Item item)
void drain(Player player)
Drains the special bar for player.
static boolean isIronman(Player player)
Checks if the player is an ironman.