RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
Fishing.java
1package com.osroyale.content.skill.impl.fishing;
2
3import com.osroyale.content.event.impl.NpcInteractionEvent;
4import com.osroyale.content.skill.SkillRepository;
5import com.osroyale.game.world.entity.mob.npc.Npc;
6import com.osroyale.game.world.entity.mob.player.Player;
7import com.osroyale.game.world.entity.skill.Skill;
8import com.osroyale.game.world.items.Item;
9import com.osroyale.game.world.items.ItemDefinition;
10import com.osroyale.util.Utility;
11
44
45public class Fishing extends Skill {
46
47 public Fishing(int level, double experience) {
48 super(Skill.FISHING, level, experience);
49 }
50 public static double getBonus(Player player) {
51 double bonus = 0;
52 if(player.equipment.getId(0) == 13258)
53 bonus += 0.4;
54 if(player.equipment.getId(4) == 13259)
55 bonus += 0.8;
56 if(player.equipment.getId(7) == 13260)
57 bonus += 0.6;
58 if(player.equipment.getId(10) == 13261)
59 bonus += 0.2;
60
61 if(player.equipment.containsAll(13258, 13259, 13260, 13261))
62 bonus = 2.5;
63
64 return bonus;
65 }
66
67
68
69 static boolean canFish(Player player, Fishable fish, boolean message) {
70 if (player.skills.get(Skill.FISHING).getLevel() < fish.getRequiredLevel()) {
71 if (message) player.message("You need a fishing level of " + fish.getRequiredLevel() + " to fish here.");
72 return false;
73 }
74 return hasFishingItems(player, fish, message);
75 }
76
77 private static boolean hasFishingItems(Player player, Fishable fish, boolean message) {
78 int tool = fish.getToolId();
79 int bait = fish.getBaitRequired();
80 boolean hasDragonHarpoon;
81 if (tool == 311) {
82 hasDragonHarpoon = player.inventory.contains(new Item(21028, 1));
83 if (!player.inventory.contains(new Item(tool, 1)) && !hasDragonHarpoon) {
84 String name = ItemDefinition.get(tool).getName();
85 player.message("You need " + Utility.getAOrAn(name) + " " + name + " to fish here.");
86 return false;
87 }
88 } else {
89 if (!player.inventory.contains(new Item(tool, 1)) && message) {
90 String name = ItemDefinition.get(tool).getName();
91 player.message("You need " + Utility.getAOrAn(name) + " " + name + " to fish here.");
92 return false;
93 }
94 }
95 if (bait > -1 && !player.inventory.contains(new Item(bait, 1))) {
96 String name = ItemDefinition.get(bait).getName();
97 if (message) {
98 player.message("You need " + Utility.getAOrAn(name) + " " + name + " to fish here.");
99 }
100 return false;
101 }
102 return true;
103 }
104
105 public static boolean success(Player player, Fishable fish) {
106 var usingDragonHarpoon = (player.inventory.contains(new Item(21028, 1))
107 || player.equipment.contains(new Item(21028, 1))) && player.skills.get(Skill.FISHING).getLevel() > 60;
108 if (usingDragonHarpoon && (fish.getToolId() == 311 || fish.getToolId() == 21028)) {
109 return SkillRepository.isSuccess(player, Skill.FISHING, fish.getRequiredLevel(), true);
110 }
111 return SkillRepository.isSuccess(player, Skill.FISHING, fish.getRequiredLevel(), false);
112 }
113
114 @Override
115 protected boolean clickNpc(Player player, NpcInteractionEvent event) {
116 Npc npc = event.getNpc();
117 int opcode = event.getOpcode();
118 FishingSpot spot = FishingSpot.forId(npc.id);
119
120 if (spot == null) {
121 return false;
122 }
123 if (player.skills.get(Skill.FISHING).isDoingSkill()) {
124 return true;
125 }
126
127 int amount = 0;
128 Fishable[] fish;
129 Fishable[] fishable = new Fishable[3];
130
131 switch (opcode) {
132 case 0:
133 fish = spot.getFirstOption();
134 for (int i = 0; i < fish.length; i++) {
135 if (canFish(player, fish[i], i == 0)) {
136 fishable[i] = fish[i];
137 amount++;
138 }
139 }
140 break;
141 case 1:
142 fish = spot.getSecondOption();
143 for (int i = 0; i < fish.length; i++) {
144 if (canFish(player, fish[i], i == 0)) {
145 fishable[i] = fish[i];
146 amount++;
147 }
148 }
149 }
150
151 if (amount == 0)
152 return true;
153
154 Fishable[] fishing = new Fishable[amount];
155 System.arraycopy(fishable, 0, fishing, 0, amount);
156 start(player, fishing, 0);
157 return true;
158 }
159
160 public void start(Player player, Fishable[] fishing, int option) {
161 if (fishing == null || fishing[option] == null || fishing[option].getToolId() == -1) {
162 return;
163 }
164
165 FishingTool tool = FishingTool.forId(fishing[option].getToolId());
166
167 if (!hasFishingItems(player, fishing[option], true)) {
168 return;
169 }
170
171 player.action.execute(new FishingAction(player, tool, fishing));
172 player.skills.get(Skill.FISHING).setDoingSkill(true);
173 }
174}
Skill(int skill, int level, double experience)
Definition Skill.java:221
static String getAOrAn(String nextWord)
Definition Utility.java:153