RuneHive-Game
Loading...
Searching...
No Matches
Herblore.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.herblore;
2
3import com.runehive.Config;
4import com.runehive.content.skillcape.SkillCape;
5import com.runehive.content.activity.randomevent.RandomEventHandler;
6import com.runehive.content.clanchannel.content.ClanTaskKey;
7import com.runehive.net.packet.out.SendInputAmount;
8import com.runehive.game.Animation;
9import com.runehive.game.action.Action;
10import com.runehive.game.action.policy.WalkablePolicy;
11import com.runehive.game.world.entity.mob.player.Player;
12import com.runehive.content.achievement.AchievementHandler;
13import com.runehive.content.achievement.AchievementKey;
14import com.runehive.content.dialogue.ChatBoxItemDialogue;
15import com.runehive.content.event.impl.ItemInteractionEvent;
16import com.runehive.content.event.impl.ItemOnItemInteractionEvent;
17import com.runehive.game.world.entity.skill.Skill;
18import com.runehive.game.world.items.Item;
19import com.runehive.util.StringUtils;
20import com.runehive.util.Utility;
21
22/**
23 * Handles the herblore skill.
24 *
25 * @author Daniel
26 */
27public class Herblore extends Skill {
28
29 /** Constructs a new <code>Herblore</code>. */
30 public Herblore(int level, double experience) {
31 super(Skill.HERBLORE, level, experience);
32 }
33
34 @Override
35 protected double modifier() {
37 }
38
39 @Override
40 protected boolean clickItem(Player player, ItemInteractionEvent event) {
41 final int slot = event.getSlot();
42 final Item item = player.inventory.get(slot);
43
44 if (item == null) {
45 return false;
46 }
47
48 if (!GrimyHerb.forId(item.getId()).isPresent()) {
49 return false;
50 }
51
52 GrimyHerb herb = GrimyHerb.forId(item.getId()).get();
53
54 if (getLevel() < herb.getLevel()) {
55 final String name = herb.getGrimy().getName();
56 player.dialogueFactory.sendStatement("You need a Herblore level of " + herb.getLevel() + " to clean " + Utility.getAOrAn(name) + " " + name + ".").execute();
57 return false;
58 }
59
60 player.inventory.remove(item);
61 player.inventory.add(herb.getClean());
62 player.skills.addExperience(Skill.HERBLORE, herb.getExperience() * modifier());
64 return true;
65 }
66
67 @Override
68 protected boolean useItem(Player player, ItemOnItemInteractionEvent e) {
69 final int useSlot = e.getFirstSlot();
70 final int withSlot = e.getSecondSlot();
71 final Item use = player.inventory.get(useSlot);
72 final Item with = player.inventory.get(withSlot);
73
74 if (use == null || with == null) {
75 return false;
76 }
77
78 final Potion potion = UnfinishedPotion.get(use, with) == null ? FinishedPotion.get(use, with) : UnfinishedPotion.get(use, with);
79
80 if (potion == null) {
81 return false;
82 }
83
84 if (getLevel() < potion.getLevel()) {
85 final String name = potion.getProduct().getName();
86 player.dialogueFactory.sendStatement("<col=369>You need a Herblore level of " + potion.getLevel() + " to make " + StringUtils.getAOrAn(name) + " " + name + " potion.").execute();
87 return true;
88 }
89
90 if (player.inventory.computeAmountForId(use.getId()) == 1 || player.inventory.computeAmountForId(with.getId()) == 1) {
91 player.inventory.set(useSlot > withSlot ? withSlot : useSlot, potion.getProduct(), true);
92 player.inventory.set(useSlot < withSlot ? withSlot : useSlot, null, true);
93 player.animate(new Animation(potion.getAnimation()));
94 } else {
95 ChatBoxItemDialogue.sendInterface(player, 1746, potion.getProduct(), 170);
96 player.chatBoxItemDialogue = new ChatBoxItemDialogue(player) {
97 @Override
98 public void firstOption(Player player) {
99 player.action.execute(mix(player, potion, 1), true);
100 }
101
102 @Override
103 public void secondOption(Player player) {
104 player.action.execute(mix(player, potion, 5), true);
105 }
106
107 @Override
108 public void thirdOption(Player player) {
109 player.send(new SendInputAmount("Enter amount", 10, input -> player.action.execute(mix(player, potion, Integer.parseInt(input)), true)));
110 }
111
112 @Override
113 public void fourthOption(Player player) {
114 player.action.execute(mix(player, potion, 14), true);
115 }
116 };
117 }
118 return true;
119 }
120
121 /** Handles the potion mixing action. */
122 private Action<Player> mix(Player player, Potion potion, int amount) {
123 return new Action<Player>(player, 2) {
124 int ticks = 0;
125
126 @Override
127 public void execute() {
128 if (!player.inventory.containsAll(potion.getIngredients())) {
129 cancel();
130 return;
131 }
132
133 player.animate(new Animation(potion.getAnimation()));
134 final boolean saveIngredient = SkillCape.isEquipped(player, SkillCape.HERBLORE) && Utility.random(1, 3) == 1;
135 if (!saveIngredient) {
136 player.inventory.removeAll(potion.getIngredients());
137 }
138 player.inventory.addOrDrop(potion.getProduct());
139 player.skills.addExperience(Skill.HERBLORE, potion.getExperience() * modifier());
143
144 if (potion == FinishedPotion.SUPER_RESTORE) {
145 getMob().forClan(channel -> channel.activateTask(ClanTaskKey.SUPER_RESTORE_POTION, getMob().getName()));
146 }
147
148 if (++ticks == amount) {
149 cancel();
150 }
151 }
152
153 @Override
154 public String getName() {
155 return "Herblore mix";
156 }
157
158 @Override
159 public boolean prioritized() {
160 return false;
161 }
162
163 @Override
164 public WalkablePolicy getWalkablePolicy() {
166 }
167 };
168 }
169}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final double HERBLORE_MODIFICATION
The experience modification for herblore.
Definition Config.java:262
static void activate(Player player, AchievementKey achievement)
Activates the achievement for the individual player.
static void sendInterface(Player player, int interfaceId, Item item, int zoom)
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.
boolean useItem(Player player, ItemOnItemInteractionEvent e)
Definition Herblore.java:68
Herblore(int level, double experience)
Constructs a new Herblore.
Definition Herblore.java:30
boolean clickItem(Player player, ItemInteractionEvent event)
Definition Herblore.java:40
Action< Player > mix(Player player, Potion potion, int amount)
Handles the potion mixing action.
Class that models a single animation used by an entity.
Represents an action an entity can execute.
Definition Action.java:12
public< A extends Action<?> > void execute(A action)
This class represents a character controlled by a player.
Definition Player.java:125
static String getName(int skill)
Gets the name for a skill id.
Definition Skill.java:465
double experience
The current skill experience.
Definition Skill.java:179
int getLevel()
Gets the current skill level.
Definition Skill.java:205
int level
The current level of the skill.
Definition Skill.java:173
Skill(int skill, int level, double experience)
Constructs a new Skill.
Definition Skill.java:184
void addExperience(int id, double experience)
Adds experience to a given skill.
The container class that represents an item that can be interacted with.
Definition Item.java:21
final int getId()
Gets the identification of this item.
Definition Item.java:324
final int computeAmountForId(int id)
Computes the total quantity of the Items in this container with id.
boolean remove(Item item)
Attempts to withdraw item from this container.
final Item get(int index)
Gets the Item located on index.
boolean add(Item item)
Attempts to deposit item into this container.
boolean removeAll(Collection<? extends Item > items)
Attempts to withdraw items in bulk from this container.
final boolean containsAll(int... identifiers)
Determines if this container contains all identifiers.
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...
static String getAOrAn(String nextWord)
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 FinishedPotion get(Item use, Item with)
Gets the finished potion data.
double getExperience()
Gets the experience for cleaning a herb.
int getLevel()
Gets the level to clean the herb.
static Optional< GrimyHerb > forId(int id)
Gets the herb data from the item identification.
static UnfinishedPotion get(Item use, Item with)
static boolean isEquipped(Player player, SkillCape cape)
A queue policy determines whether the action can occur while walking.
NON_WALKABLE
This indicates actions cannot occur while walking.
The potion making itemcontainer.
Definition Potion.java:10
Item getProduct()
Gets the potion product.
int getAnimation()
Gets the potion animation.
Item[] getIngredients()
Gets the ingredients required for the potion.
double getExperience()
Gets the experience rewarded.
int getLevel()
Gets the level required for making the potion.