RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
ToxicBlowpipeStrategy.java
1package com.osroyale.game.world.entity.combat.strategy.player.custom;
2
3import com.osroyale.game.Animation;
4import com.osroyale.game.UpdatePriority;
5import com.osroyale.game.world.entity.combat.CombatType;
6import com.osroyale.game.world.entity.combat.attack.FightType;
7import com.osroyale.game.world.entity.combat.effect.impl.CombatPoisonEffect;
8import com.osroyale.game.world.entity.combat.hit.CombatHit;
9import com.osroyale.game.world.entity.combat.hit.Hit;
10import com.osroyale.game.world.entity.combat.ranged.RangedAmmunition;
11import com.osroyale.game.world.entity.combat.strategy.basic.RangedStrategy;
12import com.osroyale.game.world.entity.mob.Mob;
13import com.osroyale.game.world.entity.mob.player.Player;
14import com.osroyale.game.world.entity.mob.player.PlayerRight;
15import com.osroyale.game.world.items.Item;
16import com.osroyale.game.world.items.containers.equipment.Equipment;
17import com.osroyale.game.world.items.ground.GroundItem;
18import com.osroyale.game.world.position.Area;
19import com.osroyale.game.world.position.Position;
20import com.osroyale.net.packet.out.SendMessage;
21import com.osroyale.util.RandomUtils;
22
23public class ToxicBlowpipeStrategy extends RangedStrategy<Player> {
24
25 private static final ToxicBlowpipeStrategy INSTANCE = new ToxicBlowpipeStrategy();
26
27 @Override
28 public boolean canAttack(Player attacker, Mob defender) {
29 Item weapon = attacker.equipment.get(Equipment.WEAPON_SLOT);
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
116 public CombatType getCombatType() {
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}