RuneHive-Game
Loading...
Searching...
No Matches
Cooking.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.cooking;
2
3import com.runehive.Config;
4import com.runehive.content.activity.randomevent.RandomEventHandler;
5import com.runehive.content.dialogue.ChatBoxItemDialogue;
6import com.runehive.content.event.impl.ItemOnObjectInteractionEvent;
7import com.runehive.content.skillcape.SkillCape;
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.game.world.entity.skill.Skill;
13import com.runehive.game.world.items.Item;
14import com.runehive.game.world.items.ItemDefinition;
15import com.runehive.game.world.object.GameObject;
16import com.runehive.net.packet.out.SendInputAmount;
17import com.runehive.net.packet.out.SendMessage;
18import com.runehive.util.Utility;
19
20import java.util.Arrays;
21
22/**
23 * Handles the cooking skill.
24 *
25 * @author Daniel
26 */
27public class Cooking extends Skill {
28
29 private transient final String[] objects = { "range", "fire", "oven", "stove", "cooking range", "fireplace" };
30
31 public Cooking(int level, double experience) {
32 super(Skill.COOKING, level, experience);
33 }
34
35 private boolean cookableObject(GameObject object) {
36 String name = object.getDefinition().getName().toLowerCase();
37 return Arrays.stream(objects).anyMatch(name::contains);
38 }
39
40 private boolean success(Player player, int level, int noBurn) {
41 if (SkillCape.isEquipped(player, SkillCape.COOKING) || player.skills.getLevel(Skill.COOKING) >= noBurn || player.equipment.contains(775)) {
42 return true;
43 }
44
45
46 int burn_bonus = 3;
47 double burn_chance = (45.0 - burn_bonus);
48 double cook_level = player.skills.getLevel(Skill.COOKING);
49 double multi_a = ((double) noBurn - (double) level);
50 double burn_dec = (burn_chance / multi_a);
51 double multi_b = (cook_level - (double) level);
52 burn_chance -= (multi_b * burn_dec);
53 double random_number = Utility.random(100);
54 return burn_chance <= random_number;
55 }
56
57 @Override
58 protected double modifier() {
60 }
61
62 @Override
63 protected boolean useItem(Player player, ItemOnObjectInteractionEvent event) {
64 Item item = event.getItem();
65 GameObject object = event.getObject();
66
67 if (!cookableObject(object)) {
68 return false;
69 }
70
71 if (!CookData.forId(item.getId()).isPresent()) {
72 return false;
73 }
74
75 if (player.skills.get(Skill.COOKING).isDoingSkill()) {
76 return true;
77 }
78
79 CookData cook = CookData.forId(item.getId()).get();
80
81 if (getLevel() < cook.getLevel()) {
82 player.dialogueFactory.sendStatement("You need a cooking level of " + cook.getLevel() + " to cook this!").execute();
83 return true;
84 }
85
86
87 if (player.inventory.computeAmountForId(item.getId()) == 1) {
88 player.action.execute(cook(player, cook, 1), true);
89 } else {
90 ChatBoxItemDialogue.sendInterface(player, 1746, cook.getCooked(), 0, -5, 170);
91 player.chatBoxItemDialogue = new ChatBoxItemDialogue(player) {
92 @Override
93 public void firstOption(Player player) {
94 player.action.execute(cook(player, cook, 1), true);
95 }
96
97 @Override
98 public void secondOption(Player player) {
99 player.action.execute(cook(player, cook, 5), true);
100 }
101
102 @Override
103 public void thirdOption(Player player) {
104 player.send(new SendInputAmount("Enter amount of fish you would like to cook", 10, input -> player.action.execute(cook(player, cook, Integer.parseInt(input)), true)));
105 }
106
107 @Override
108 public void fourthOption(Player player) {
109 player.action.execute(cook(player, cook, 28), true);
110 }
111 };
112 }
113 return true;
114 }
115
116 private Action<Player> cook(Player player, CookData cook, int amount) {
117 return new Action<Player>(player, 3, true) {
118 int ticks = 0;
119
120 @Override
121 protected void onSchedule() {
122 player.skills.get(Skill.COOKING).setDoingSkill(true);
123 }
124
125 @Override
126 public void execute() {
127 if (!player.skills.get(Skill.COOKING).isDoingSkill()) {
128 cancel();
129 return;
130 }
131
132 if (!player.inventory.contains(cook.getItem())) {
133 cancel();
134 player.send(new SendMessage("<col=369>You have run out of materials."));
135 return;
136 }
137 player.animate(new Animation(883));
138 String name = ItemDefinition.get(cook.getCooked()).getName();
139 player.inventory.remove(cook.getItem(), 1);
140
141 if (success(player, cook.getLevel(), cook.getNoBurn())) {
142 player.inventory.add(cook.getCooked(), 1);
143 player.skills.addExperience(Skill.COOKING, cook.getExp() * modifier());
144 player.send(new SendMessage("You successfully cook the " + name + ".", true));
147 } else {
148 player.inventory.add(cook.getBurnt(), 1);
149 player.send(new SendMessage("You accidently burn the " + name + ".", true));
150 }
151
152 if (++ticks == amount) {
153 cancel();
154 }
155 }
156
157 @Override
158 protected void onCancel(boolean logout) {
159 player.resetFace();
160 player.skills.get(Skill.COOKING).setDoingSkill(false);
161 }
162
163 @Override
164 public String getName() {
165 return "Cooking";
166 }
167
168 @Override
169 public boolean prioritized() {
170 return false;
171 }
172
173 @Override
174 public WalkablePolicy getWalkablePolicy() {
176 }
177 };
178 }
179}
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 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.
Cooking(int level, double experience)
Definition Cooking.java:31
Action< Player > cook(Player player, CookData cook, int amount)
Definition Cooking.java:116
boolean cookableObject(GameObject object)
Definition Cooking.java:35
boolean useItem(Player player, ItemOnObjectInteractionEvent event)
Definition Cooking.java:63
boolean success(Player player, int level, int noBurn)
Definition Cooking.java:40
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)
void resetFace()
Resets the mob's face location.
Definition Mob.java:330
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
void setDoingSkill(boolean doingSkill)
Definition Skill.java:489
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.
int getLevel(int id)
Gets the level of a skill.
Skill get(int id)
Gets the skill for an id.
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
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.
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)
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 Optional< CookData > forId(int id)
Definition CookData.java:82
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.