RuneHive-Game
Loading...
Searching...
No Matches
Netting.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.hunter.net;
2
3import com.runehive.Config;
4import com.runehive.content.activity.randomevent.RandomEventHandler;
5import com.runehive.content.skill.impl.hunter.net.impl.Impling;
6import com.runehive.game.action.impl.HunterRespawnTask;
7import com.runehive.game.task.Task;
8import com.runehive.game.world.World;
9import com.runehive.game.world.entity.mob.npc.Npc;
10import com.runehive.game.world.entity.mob.player.Player;
11import com.runehive.game.world.entity.skill.Skill;
12import com.runehive.game.world.items.ItemDefinition;
13import com.runehive.game.world.position.Position;
14import com.runehive.net.packet.out.SendMessage;
15import com.runehive.util.Utility;
16
17/**
18 * Created by Daniel on 2018-02-07.
19 */
20public class Netting extends Task {
21 private final Player player;
22 private final Npc npc;
23 private final Position position;
24 private final int experience;
25 private final int levelRequired;
26 private final int jar;
27 private final int reward;
28
29 public Netting(Player player, Npc npc, int experience, int levelRequired, int jar, int reward) {
30 super(false, 3);
31 this.player = player;
32 this.npc = npc;
33 this.position = npc.getPosition();
34 this.experience = experience;
35 this.levelRequired = levelRequired;
36 this.jar = jar;
37 this.reward = reward;
38 }
39
40 @Override
41 protected boolean canSchedule() {
42 if (player.skills.getMaxLevel(Skill.HUNTER) < levelRequired) {
43 player.message("You need a hunter level of " + levelRequired + " to do this!");
44 return false;
45 }
46
47 var canBarehandImpling = Impling.forId(npc.id).isPresent() && player.skills.getMaxLevel(Skill.HUNTER) > levelRequired + 9;
48 if (!player.equipment.contains(10010) && !canBarehandImpling) {
49 player.send(new SendMessage("You need to be wielding a butterfly net to do this!"));
50 return false;
51 }
52
53 if (!player.inventory.contains(jar)) {
54 String name = ItemDefinition.get(jar).getName();
55 player.message("You need " + Utility.getAOrAn(name) + " " + name + " to do this!");
56 return false;
57 }
58
59 if (player.inventory.isFull()) {
60 player.message("You do not have any free inventory spaces to do this!");
61 return false;
62 }
63
64 return !player.locking.locked();
65 }
66
67 @Override
68 protected void onSchedule() {
69 player.locking.lock();
70 player.face(position);
71 var anim = !player.equipment.contains(10010) ? 7171 : 6606;
72 player.animate(anim);
73 }
74
75 @Override
76 protected void execute() {
77 boolean success = true;
78
79 if (!npc.getPosition().equals(position) || Utility.random(3) == 1) {
80 success = false;
81 }
82
83 if (success) {
84 player.inventory.remove(jar);
85 player.inventory.add(reward, 1);
86 player.skills.addExperience(Skill.HUNTER, experience * Config.HUNTER_MODIFICATION);
87 player.message("You catch the " + npc.getName() + " and place it in the jar.");
90 player.playerAssistant.activateSkilling(1);
91 } else {
92 player.message("You fail to catch the " + npc.getName() + ".");
93 }
94
95 cancel();
96 }
97
98 @Override
99 protected void onCancel(boolean logout) {
100 player.locking.unlock();
101 }
102}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final double HUNTER_MODIFICATION
The experience modification for hunter.
Definition Config.java:265
void onCancel(boolean logout)
A function executed on cancellation.
Definition Netting.java:99
boolean canSchedule()
A function executed on registration.
Definition Netting.java:41
Netting(Player player, Npc npc, int experience, int levelRequired, int jar, int reward)
Definition Netting.java:29
void execute()
A function representing the unit of work that will be carried out.
Definition Netting.java:76
void onSchedule()
A function executed on registration.
Definition Netting.java:68
Teleports an entity to another part of the world.
synchronized final void cancel()
Cancels all subsequent executions.
Definition Task.java:113
Task(boolean instant, int delay)
Creates a new Task.
Definition Task.java:41
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
Represents a non-player character in the in-game world.
Definition Npc.java:29
This class represents a character controlled by a player.
Definition Player.java:125
Represents a trainable and usable skill.
Definition Skill.java:18
static final int HUNTER
The hunter skill id.
Definition Skill.java:87
Represents all of an in-game Item's attributes.
static ItemDefinition get(int id)
Gets an item definition.
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.
Handles miscellaneous methods.
Definition Utility.java:27
static int random(int bound)
Definition Utility.java:239
static String getAOrAn(String nextWord)
A or an.
Definition Utility.java:116
static Optional< Impling > forId(int impling)
Definition Impling.java:38