RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
Netting.java
1package com.osroyale.content.skill.impl.hunter.net;
2
3import com.osroyale.Config;
4import com.osroyale.content.activity.randomevent.RandomEventHandler;
5import com.osroyale.content.skill.impl.hunter.net.impl.Impling;
6import com.osroyale.game.action.impl.HunterRespawnTask;
7import com.osroyale.game.task.Task;
8import com.osroyale.game.world.World;
9import com.osroyale.game.world.entity.mob.npc.Npc;
10import com.osroyale.game.world.entity.mob.player.Player;
11import com.osroyale.game.world.entity.skill.Skill;
12import com.osroyale.game.world.items.ItemDefinition;
13import com.osroyale.game.world.position.Position;
14import com.osroyale.net.packet.out.SendMessage;
15import com.osroyale.util.Utility;
16
50
51public class Netting extends Task {
52 private final Player player;
53 private final Npc npc;
54 private final Position position;
55 private final int experience;
56 private final int levelRequired;
57 private final int jar;
58 private final int reward;
59
60 public Netting(Player player, Npc npc, int experience, int levelRequired, int jar, int reward) {
61 super(false, 3);
62 this.player = player;
63 this.npc = npc;
64 this.position = npc.getPosition();
65 this.experience = experience;
66 this.levelRequired = levelRequired;
67 this.jar = jar;
68 this.reward = reward;
69 }
70
71 @Override
72 protected boolean canSchedule() {
73 if (player.skills.getMaxLevel(Skill.HUNTER) < levelRequired) {
74 player.message("You need a hunter level of " + levelRequired + " to do this!");
75 return false;
76 }
77
78 var canBarehandImpling = Impling.forId(npc.id).isPresent() && player.skills.getMaxLevel(Skill.HUNTER) > levelRequired + 9;
79 if (!player.equipment.contains(10010) && !canBarehandImpling) {
80 player.send(new SendMessage("You need to be wielding a butterfly net to do this!"));
81 return false;
82 }
83
84 if (!player.inventory.contains(jar)) {
85 String name = ItemDefinition.get(jar).getName();
86 player.message("You need " + Utility.getAOrAn(name) + " " + name + " to do this!");
87 return false;
88 }
89
90 if (player.inventory.isFull()) {
91 player.message("You do not have any free inventory spaces to do this!");
92 return false;
93 }
94
95 return !player.locking.locked();
96 }
97
98 @Override
99 protected void onSchedule() {
100 player.locking.lock();
101 player.face(position);
102 var anim = !player.equipment.contains(10010) ? 7171 : 6606;
103 player.animate(anim);
104 }
105
106 @Override
107 protected void execute() {
108 boolean success = true;
109
110 if (!npc.getPosition().equals(position) || Utility.random(3) == 1) {
111 success = false;
112 }
113
114 if (success) {
115 player.inventory.remove(jar);
116 player.inventory.add(reward, 1);
117 player.skills.addExperience(Skill.HUNTER, experience * Config.HUNTER_MODIFICATION);
118 player.message("You catch the " + npc.getName() + " and place it in the jar.");
120 RandomEventHandler.trigger(player);
121 player.playerAssistant.activateSkilling(1);
122 } else {
123 player.message("You fail to catch the " + npc.getName() + ".");
124 }
125
126 cancel();
127 }
128
129 @Override
130 protected void onCancel(boolean logout) {
131 player.locking.unlock();
132 }
133}
static final double HUNTER_MODIFICATION
Definition Config.java:307
synchronized final void cancel()
Definition Task.java:147
Task(boolean instant, int delay)
Definition Task.java:75
static void schedule(Task task)
Definition World.java:284
static String getAOrAn(String nextWord)
Definition Utility.java:153