RuneHive-Game
Loading...
Searching...
No Matches
FishingAction.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.fishing;
2
3import com.runehive.Config;
4import com.runehive.content.activity.randomevent.RandomEventHandler;
5import com.runehive.content.clanchannel.content.ClanTaskKey;
6import com.runehive.content.pet.PetData;
7import com.runehive.content.pet.Pets;
8import com.runehive.content.prestige.PrestigePerk;
9import com.runehive.game.Animation;
10import com.runehive.game.action.Action;
11import com.runehive.game.action.policy.WalkablePolicy;
12import com.runehive.game.world.entity.mob.player.Player;
13import com.runehive.game.world.entity.skill.Skill;
14import com.runehive.game.world.items.Item;
15import com.runehive.game.world.items.ItemDefinition;
16import com.runehive.util.RandomUtils;
17import com.runehive.util.Utility;
18
19/**
20 * Created by Daniel on 2017-12-18.
21 */
22public class FishingAction extends Action<Player> {
23 private final FishingTool tool;
24 private final Fishable[] fishing;
25
27 super(player, 6, false);
28 this.tool = tool;
29 this.fishing = fishing;
30 }
31
32 private boolean fish(Player player, Fishable[] fishing) {
33 if (fishing == null)
34 return false;
35
36 Fishable[] fish = new Fishable[5];
37
38 byte c = 0;
39
40 for (Fishable aFishing : fishing) {
41 if (Fishing.canFish(player, aFishing, false)) {
42 fish[c] = aFishing;
43 c = (byte) (c + 1);
44 }
45 }
46 if (c == 0) {
47 return false;
48 }
49
51
52 if (player.inventory.getFreeSlots() == 0) {
53 player.dialogueFactory.sendStatement("You can't carry anymore fish.").execute();
54 player.animate(Animation.RESET, true);
55 return false;
56 }
57
58 if (Fishing.success(player, f)) {
59 if (f.getBaitRequired() != -1) {
60 player.inventory.remove(new Item(f.getBaitRequired(), 1));
61 if (!player.inventory.contains(f.getBaitRequired(), 1)) {
62 player.dialogueFactory.sendStatement("You have run out of bait.").execute();
63 player.animate(Animation.RESET, true);
64 return false;
65 }
66 }
67
68 boolean infernalHarpoon = player.equipment.contains(21031) && Utility.random(3) == 0 && (f.equals(Fishable.SWORD_FISH) || f.equals(Fishable.SWORD_FISH2) || f.equals(Fishable.SWORD_FISH) || f.equals(Fishable.TUNA) || f.equals(Fishable.TUNA2) || f.equals(Fishable.SHARK));
69
70 int id = f.getRawFishId();
71 String name = ItemDefinition.get(id).getName();
72 if(!infernalHarpoon)
73 player.inventory.add(new Item(id, 1));
74 else {
75 double xp = f.equals(Fishable.SWORD_FISH) || f.equals(Fishable.SWORD_FISH2) ? 70 : f.equals(Fishable.TUNA) || f.equals(Fishable.TUNA2) ? 50 : 105;
77 }
78
80
81 player.message(true, "You manage to catch a " + name + ".");
84 Pets.onReward(player, PetData.HERON.getItem(), 7500);
85
87 player.inventory.addOrDrop(new Item(id, 1));
88 }
89
90 if (id == 383) {
91 player.forClan(channel -> channel.activateTask(ClanTaskKey.SHARK, player.getName()));
92 } else if (id == 11934) {
93 player.forClan(channel -> channel.activateTask(ClanTaskKey.DARK_CRAB, player.getName()));
94 }
95 }
96 return true;
97 }
98
99 @Override
100 protected boolean canSchedule() {
101 return !getMob().skills.get(Skill.FISHING).isDoingSkill();
102 }
103
104 @Override
105 protected void onSchedule() {
106 getMob().animate(tool.getAnimationId());
107 }
108
109 @Override
110 public void execute() {
111 if (!getMob().skills.get(Skill.FISHING).isDoingSkill()) {
112 cancel();
113 return;
114 }
115
116 getMob().animate(tool.getAnimationId());
117
118 if (!fish(getMob(), fishing)) {
119 cancel();
120 }
121 }
122
123 @Override
124 protected void onCancel(boolean logout) {
125 getMob().resetFace();
126 getMob().skills.get(Skill.FISHING).setDoingSkill(false);
127 }
128
129 @Override
133
134 @Override
135 public String getName() {
136 return "fishing-action";
137 }
138}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final double COOKING_MODIFICATION
The experience modification for cooking.
Definition Config.java:250
static final double FISHING_MODIFICATION
The experience modification for fishing.
Definition Config.java:292
final DialogueFactory execute()
Retrieves the next dialogue in the chain and executes it.
final DialogueFactory sendStatement(String... lines)
Appends a StatementDialogue to the current dialogue chain.
Handles spawning, rewarding and picking up of pets.
Definition Pets.java:27
static void onReward(Player player, int item, int chance)
Handles calculating the chance of a player receiving a skilling pet.
Definition Pets.java:33
boolean hasPerk(PrestigePerk perk)
String getName()
Gets the name of this action.
boolean canSchedule()
A function executed on registration.
boolean fish(Player player, Fishable[] fishing)
WalkablePolicy getWalkablePolicy()
Gets the WalkablePolicy of this action.
FishingAction(Player player, FishingTool tool, Fishable[] fishing)
void execute()
A function representing the unit of work that will be carried out.
void onCancel(boolean logout)
A function executed on cancellation.
void onSchedule()
A function executed on registration.
static boolean success(Player player, Fishable fish)
Definition Fishing.java:77
static boolean canFish(Player player, Fishable fish, boolean message)
Definition Fishing.java:41
Class that models a single animation used by an entity.
static final Animation RESET
T getMob()
Gets the player.
Definition Action.java:44
Action(T mob, int delay, boolean instant)
Creates a new Action randomevent.
Definition Action.java:24
synchronized final void cancel()
Cancels all subsequent executions.
Definition Task.java:113
This class represents a character controlled by a player.
Definition Player.java:125
void forClan(Consumer< ClanChannel > action)
Definition Player.java:568
String getName()
Gets the name of this entity.
Definition Player.java:774
Represents a trainable and usable skill.
Definition Skill.java:18
static final int FISHING
The fishing skill id.
Definition Skill.java:51
static final int COOKING
The cooking skill id.
Definition Skill.java:42
void addExperience(int id, double experience)
Adds experience to a given skill.
Represents all of an in-game Item's attributes.
static ItemDefinition get(int id)
Gets an item definition.
The container class that represents an item that can be interacted with.
Definition Item.java:21
boolean remove(Item item)
Attempts to withdraw item from this container.
boolean add(Item item)
Attempts to deposit item into this container.
boolean contains(int id)
Determines if this container contains id.
boolean contains(int[] bowsWithNoArrowsRequired)
void addOrDrop(List< Item > items)
Attempts to deposit an item to the players inventory, if there is no space it'll bank the item instea...
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...
Handles miscellaneous methods.
Definition Utility.java:27
static int random(int bound)
Definition Utility.java:239
Holds the data for pets.
Definition PetData.java:14
Handles the perk rewards from prestiging.
A queue policy determines whether the action can occur while walking.
NON_WALKABLE
This indicates actions cannot occur while walking.