RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.content.skill.impl.cooking.Cooking Class Reference

Handles the cooking skill. More...

Inheritance diagram for com.runehive.content.skill.impl.cooking.Cooking:
Collaboration diagram for com.runehive.content.skill.impl.cooking.Cooking:

Public Member Functions

 Cooking (int level, double experience)
Public Member Functions inherited from com.runehive.game.world.entity.skill.Skill
double addExperience (double amount)
 Adds experiences to this skill by the given amount.
void addLevel (int amount)
 Adds levels to this skill by the given amount.
void divideExperience (double amount)
 Divides the current experience of this skill by a given amount.
void divideLevel (double amount)
 Divides the current level of this skill by a given amount.
double getExperience ()
 Gets the skill experience.
int getLevel ()
 Gets the current skill level.
int getMaxLevel ()
 Gets the maximum skill level.
int getRoundedExperience ()
 Gets the floor experience.
int getSkill ()
 Gets the skill id.
boolean isDoingSkill ()
double modifyExperience (Function< Double, Double > function)
 Modifies the current experience with a given function.
double modifyExperience (Function< Double, Double > function, int lowerBounds, int upperBounds)
 Modifies the current experience with a given function.
void modifyLevel (Function< Integer, Integer > function)
 Modifies the current level with a given function.
void modifyLevel (Function< Integer, Integer > function, int lowerBounds, int upperBounds)
 Modifies the current level with a given function.
void multiplyExperience (double amount)
 Multiplies the current experience of this skill by a given amount.
void multiplyLevel (double amount)
 Multiplies the current level of this skill by a given amount.
boolean onEvent (Player player, InteractionEvent interactionEvent)
void removeExperience (double amount)
 Removes experiences from this skill by the given amount.
void removeLevel (int amount)
 Removes levels from this skill by the given amount.
boolean reqLevel (int level)
 Determines if your level is greater than or equal to level.
void setDoingSkill (boolean doingSkill)
void setExperience (double experience)
 Sets the experience for this skill.
void setLevel (int level)
 Sets the level for this skill.
void setMaxLevel (int maxLevel)
 Sets the maximum level for this skill.
 Skill (int skill, int level, double experience)
 Constructs a new Skill.
String toString ()

Protected Member Functions

double modifier ()
boolean useItem (Player player, ItemOnObjectInteractionEvent event)
Protected Member Functions inherited from com.runehive.game.world.entity.skill.Skill
boolean clickButton (Player player, ClickButtonInteractionEvent event)
boolean clickItem (Player player, ItemInteractionEvent event)
boolean clickNpc (Player player, NpcInteractionEvent event)
boolean clickObject (Player player, ObjectInteractionEvent event)
boolean itemContainerAction (Player player, ItemContainerInteractionEvent event)
boolean useItem (Player player, ItemOnItemInteractionEvent event)

Private Member Functions

Action< Playercook (Player player, CookData cook, int amount)
boolean cookableObject (GameObject object)
boolean success (Player player, int level, int noBurn)

Private Attributes

transient final String[] objects = { "range", "fire", "oven", "stove", "cooking range", "fireplace" }

Additional Inherited Members

Static Public Member Functions inherited from com.runehive.game.world.entity.skill.Skill
static Function< Integer, Integer > add (int amount)
 Creates a function that adds a number by an amount.
static Function< Integer, Integer > divide (double amount)
 Creates a function that divides a number by an amount.
static final int getExperienceForLevel (int level)
 Gets the experience for a given level.
static final byte getLevelForExperience (double experience)
 Gets the level for a given experience amount.
static String getName (int skill)
 Gets the name for a skill id.
static Function< Integer, Integer > multiply (double amount)
 Creates a function that multiplies a number by an amount.
static Function< Integer, Integer > subtract (int amount)
 Creates a function that subtracts a number by an amount.
Public Attributes inherited from com.runehive.game.world.entity.skill.Skill
transient final Stopwatch stopwatch = Stopwatch.start()
Static Public Attributes inherited from com.runehive.game.world.entity.skill.Skill
static final int AGILITY = 16
 The agility skill id.
static final int ATTACK = 0
 The attack skill id.
static final int CONSTRUCTION = 21
 The construction skill id.
static final int COOKING = 7
 The cooking skill id.
static final int CRAFTING = 12
 The crafting skill id.
static final int DEFENCE = 1
 The defence skill id.
static final int FARMING = 19
 The farming skill id.
static final int FIREMAKING = 11
 The firemaking skill id.
static final int FISHING = 10
 The fishing skill id.
static final int FLETCHING = 9
 The fletching skill id.
static final int HERBLORE = 15
 The herblore skill id.
static final int HITPOINTS = 3
 The hitpoints skill id.
static final int HUNTER = 22
 The hunter skill id.
static final int[][] INTERFACE_DATA
 Skill tab string data.
static final int MAGIC = 6
 The magic skill id.
static final int MINING = 14
 The mining skill id.
static final int PRAYER = 5
 The prayer skill id.
static final int RANGED = 4
 The ranged skill id.
static final int RUNECRAFTING = 20
 The runecrafting skill id.
static final int SKILL_COUNT = 23
 The amount of available skills.
static final int SLAYER = 18
 The slayer skill id.
static final int SMITHING = 13
 The smithing skill id.
static final int STRENGTH = 2
 The strength skill id.
static final int THIEVING = 17
 The thieving skill id.
static final int TOTAL_SKILL_LEVEL = 99 * SKILL_COUNT
 The total skill amount.
static final int WOODCUTTING = 8
 The woodcutting skill id.

Detailed Description

Handles the cooking skill.

Author
Daniel

Definition at line 27 of file Cooking.java.

Constructor & Destructor Documentation

◆ Cooking()

com.runehive.content.skill.impl.cooking.Cooking.Cooking ( int level,
double experience )

Definition at line 31 of file Cooking.java.

31 {
32 super(Skill.COOKING, level, experience);
33 }

References com.runehive.game.world.entity.skill.Skill.experience, com.runehive.game.world.entity.skill.Skill.level, and com.runehive.game.world.entity.skill.Skill.Skill().

Here is the call graph for this function:

Member Function Documentation

◆ cook()

Action< Player > com.runehive.content.skill.impl.cooking.Cooking.cook ( Player player,
CookData cook,
int amount )
private

Definition at line 116 of file Cooking.java.

116 {
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));
145 player.playerAssistant.activateSkilling(1);
146 RandomEventHandler.trigger(player);
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() {
175 return WalkablePolicy.NON_WALKABLE;
176 }
177 };
178 }

References com.runehive.game.world.entity.mob.player.PlayerAssistant.activateSkilling(), com.runehive.game.world.items.containers.ItemContainer.add(), com.runehive.game.world.entity.skill.SkillManager.addExperience(), com.runehive.game.world.entity.mob.Mob.animate(), com.runehive.game.world.items.containers.ItemContainer.contains(), cook(), com.runehive.game.world.entity.skill.SkillManager.get(), com.runehive.game.world.items.ItemDefinition.get(), com.runehive.game.world.entity.skill.Skill.getName(), com.runehive.game.world.items.ItemDefinition.getName(), com.runehive.game.world.entity.mob.player.Player.inventory, com.runehive.game.world.entity.skill.Skill.isDoingSkill(), modifier(), com.runehive.game.action.policy.WalkablePolicy.NON_WALKABLE, com.runehive.game.world.entity.mob.player.Player.playerAssistant, com.runehive.game.world.items.containers.ItemContainer.remove(), com.runehive.game.world.entity.mob.Mob.resetFace(), com.runehive.game.world.entity.mob.player.Player.send(), com.runehive.game.world.entity.skill.Skill.setDoingSkill(), com.runehive.game.world.entity.skill.Skill.Skill(), com.runehive.game.world.entity.mob.Mob.skills, success(), and com.runehive.content.activity.randomevent.RandomEventHandler.trigger().

Referenced by cook(), and useItem().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cookableObject()

boolean com.runehive.content.skill.impl.cooking.Cooking.cookableObject ( GameObject object)
private

Definition at line 35 of file Cooking.java.

35 {
36 String name = object.getDefinition().getName().toLowerCase();
37 return Arrays.stream(objects).anyMatch(name::contains);
38 }

References objects.

Referenced by useItem().

Here is the caller graph for this function:

◆ modifier()

double com.runehive.content.skill.impl.cooking.Cooking.modifier ( )
protected

Reimplemented from com.runehive.game.world.entity.skill.Skill.

Definition at line 58 of file Cooking.java.

58 {
59 return Config.COOKING_MODIFICATION;
60 }

References com.runehive.Config.COOKING_MODIFICATION.

Referenced by cook().

Here is the caller graph for this function:

◆ success()

boolean com.runehive.content.skill.impl.cooking.Cooking.success ( Player player,
int level,
int noBurn )
private

Definition at line 40 of file Cooking.java.

40 {
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 }

References com.runehive.game.world.items.containers.equipment.Equipment.contains(), com.runehive.content.skillcape.SkillCape.COOKING, com.runehive.game.world.entity.mob.player.Player.equipment, com.runehive.game.world.entity.skill.SkillManager.getLevel(), com.runehive.content.skillcape.SkillCape.isEquipped(), com.runehive.game.world.entity.skill.Skill.level, com.runehive.util.Utility.random(), com.runehive.game.world.entity.skill.Skill.Skill(), and com.runehive.game.world.entity.mob.Mob.skills.

Referenced by cook().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ useItem()

boolean com.runehive.content.skill.impl.cooking.Cooking.useItem ( Player player,
ItemOnObjectInteractionEvent event )
protected

Reimplemented from com.runehive.game.world.entity.skill.Skill.

Definition at line 63 of file Cooking.java.

63 {
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 }

References com.runehive.game.world.entity.mob.Mob.action, com.runehive.game.world.items.containers.ItemContainer.computeAmountForId(), cook(), cookableObject(), com.runehive.game.world.entity.mob.player.Player.dialogueFactory, com.runehive.content.dialogue.DialogueFactory.execute(), com.runehive.game.action.ActionManager.execute(), com.runehive.content.skill.impl.cooking.CookData.forId(), com.runehive.game.world.entity.skill.SkillManager.get(), com.runehive.game.world.items.Item.getId(), com.runehive.game.world.entity.skill.Skill.getLevel(), com.runehive.game.world.entity.mob.player.Player.inventory, com.runehive.game.world.entity.skill.Skill.isDoingSkill(), com.runehive.game.world.entity.mob.player.Player.send(), com.runehive.content.dialogue.ChatBoxItemDialogue.sendInterface(), com.runehive.content.dialogue.DialogueFactory.sendStatement(), com.runehive.game.world.entity.skill.Skill.Skill(), and com.runehive.game.world.entity.mob.Mob.skills.

Here is the call graph for this function:

Member Data Documentation

◆ objects

transient final String [] com.runehive.content.skill.impl.cooking.Cooking.objects = { "range", "fire", "oven", "stove", "cooking range", "fireplace" }
private

Definition at line 29 of file Cooking.java.

29{ "range", "fire", "oven", "stove", "cooking range", "fireplace" };

Referenced by cookableObject().


The documentation for this class was generated from the following file: