RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
Herblore.java
1package com.osroyale.content.skill.impl.herblore;
2
3import com.osroyale.Config;
4import com.osroyale.content.skillcape.SkillCape;
5import com.osroyale.content.activity.randomevent.RandomEventHandler;
6import com.osroyale.content.clanchannel.content.ClanTaskKey;
7import com.osroyale.net.packet.out.SendInputAmount;
8import com.osroyale.game.Animation;
9import com.osroyale.game.action.Action;
10import com.osroyale.game.action.policy.WalkablePolicy;
11import com.osroyale.game.world.entity.mob.player.Player;
12import com.osroyale.content.achievement.AchievementHandler;
13import com.osroyale.content.achievement.AchievementKey;
14import com.osroyale.content.dialogue.ChatBoxItemDialogue;
15import com.osroyale.content.event.impl.ItemInteractionEvent;
16import com.osroyale.content.event.impl.ItemOnItemInteractionEvent;
17import com.osroyale.game.world.entity.skill.Skill;
18import com.osroyale.game.world.items.Item;
19import com.osroyale.util.StringUtils;
20import com.osroyale.util.Utility;
21
57
58public class Herblore extends Skill {
59
61 public Herblore(int level, double experience) {
62 super(Skill.HERBLORE, level, experience);
63 }
64
65 @Override
66 protected double modifier() {
68 }
69
70 @Override
71 protected boolean clickItem(Player player, ItemInteractionEvent event) {
72 final int slot = event.getSlot();
73 final Item item = player.inventory.get(slot);
74
75 if (item == null) {
76 return false;
77 }
78
79 if (!GrimyHerb.forId(item.getId()).isPresent()) {
80 return false;
81 }
82
83 GrimyHerb herb = GrimyHerb.forId(item.getId()).get();
84
85 if (getLevel() < herb.getLevel()) {
86 final String name = herb.getGrimy().getName();
87 player.dialogueFactory.sendStatement("You need a Herblore level of " + herb.getLevel() + " to clean " + Utility.getAOrAn(name) + " " + name + ".").execute();
88 return false;
89 }
90
91 player.inventory.remove(item);
92 player.inventory.add(herb.getClean());
93 player.skills.addExperience(Skill.HERBLORE, herb.getExperience() * modifier());
94 RandomEventHandler.trigger(player);
95 return true;
96 }
97
98 @Override
99 protected boolean useItem(Player player, ItemOnItemInteractionEvent e) {
100 final int useSlot = e.getFirstSlot();
101 final int withSlot = e.getSecondSlot();
102 final Item use = player.inventory.get(useSlot);
103 final Item with = player.inventory.get(withSlot);
104
105 if (use == null || with == null) {
106 return false;
107 }
108
109 final Potion potion = UnfinishedPotion.get(use, with) == null ? FinishedPotion.get(use, with) : UnfinishedPotion.get(use, with);
110
111 if (potion == null) {
112 return false;
113 }
114
115 if (getLevel() < potion.getLevel()) {
116 final String name = potion.getProduct().getName();
117 player.dialogueFactory.sendStatement("<col=369>You need a Herblore level of " + potion.getLevel() + " to make " + StringUtils.getAOrAn(name) + " " + name + " potion.").execute();
118 return true;
119 }
120
121 if (player.inventory.computeAmountForId(use.getId()) == 1 || player.inventory.computeAmountForId(with.getId()) == 1) {
122 player.inventory.set(useSlot > withSlot ? withSlot : useSlot, potion.getProduct(), true);
123 player.inventory.set(useSlot < withSlot ? withSlot : useSlot, null, true);
124 player.animate(new Animation(potion.getAnimation()));
125 } else {
126 ChatBoxItemDialogue.sendInterface(player, 1746, potion.getProduct(), 170);
127 player.chatBoxItemDialogue = new ChatBoxItemDialogue(player) {
128 @Override
129 public void firstOption(Player player) {
130 player.action.execute(mix(player, potion, 1), true);
131 }
132
133 @Override
134 public void secondOption(Player player) {
135 player.action.execute(mix(player, potion, 5), true);
136 }
137
138 @Override
139 public void thirdOption(Player player) {
140 player.send(new SendInputAmount("Enter amount", 10, input -> player.action.execute(mix(player, potion, Integer.parseInt(input)), true)));
141 }
142
143 @Override
144 public void fourthOption(Player player) {
145 player.action.execute(mix(player, potion, 14), true);
146 }
147 };
148 }
149 return true;
150 }
151
153 private Action<Player> mix(Player player, Potion potion, int amount) {
154 return new Action<Player>(player, 2) {
155 int ticks = 0;
156
157 @Override
158 public void execute() {
159 if (!player.inventory.containsAll(potion.getIngredients())) {
160 cancel();
161 return;
162 }
163
164 player.animate(new Animation(potion.getAnimation()));
165 final boolean saveIngredient = SkillCape.isEquipped(player, SkillCape.HERBLORE) && Utility.random(1, 3) == 1;
166 if (!saveIngredient) {
167 player.inventory.removeAll(potion.getIngredients());
168 }
169 player.inventory.addOrDrop(potion.getProduct());
170 player.skills.addExperience(Skill.HERBLORE, potion.getExperience() * modifier());
171 player.playerAssistant.activateSkilling(1);
172 AchievementHandler.activate(player, AchievementKey.HERBLORE, 1);
173 RandomEventHandler.trigger(player);
174
175 if (potion == FinishedPotion.SUPER_RESTORE) {
176 getMob().forClan(channel -> channel.activateTask(ClanTaskKey.SUPER_RESTORE_POTION, getMob().getName()));
177 }
178
179 if (++ticks == amount) {
180 cancel();
181 }
182 }
183
184 @Override
185 public String getName() {
186 return "Herblore mix";
187 }
188
189 @Override
190 public boolean prioritized() {
191 return false;
192 }
193
194 @Override
195 public WalkablePolicy getWalkablePolicy() {
196 return WalkablePolicy.NON_WALKABLE;
197 }
198 };
199 }
200}
static final double HERBLORE_MODIFICATION
Definition Config.java:304
final DialogueFactory sendStatement(String... lines)
static String getName(int skill)
Definition Skill.java:502
Skill(int skill, int level, double experience)
Definition Skill.java:221
void addExperience(int id, double experience)
static String getAOrAn(String nextWord)
Definition Utility.java:153
static Optional< GrimyHerb > forId(int id)