1package com.runehive.game.world.entity.skill;
3import com.runehive.Config;
4import com.runehive.content.WellOfGoodwill;
5import com.runehive.content.achievement.AchievementHandler;
6import com.runehive.content.achievement.AchievementKey;
7import com.runehive.content.event.InteractionEvent;
8import com.runehive.content.lms.LMSGame;
9import com.runehive.content.skill.impl.cooking.Cooking;
10import com.runehive.content.skill.impl.crafting.Crafting;
11import com.runehive.content.skill.impl.farming.Farming;
12import com.runehive.content.skill.impl.firemaking.Firemaking;
13import com.runehive.content.skill.impl.fishing.Fishing;
14import com.runehive.content.skill.impl.fletching.Fletching;
15import com.runehive.content.skill.impl.herblore.Herblore;
16import com.runehive.content.skill.impl.hunter.Hunter;
17import com.runehive.content.skill.impl.mining.Mining;
18import com.runehive.content.skill.impl.prayer.BoneSacrifice;
19import com.runehive.content.skill.impl.runecrafting.Runecraft;
20import com.runehive.content.skill.impl.smithing.Smelting;
21import com.runehive.content.skill.impl.smithing.Smithing;
22import com.runehive.content.skill.impl.thieving.Thieving;
23import com.runehive.content.skill.impl.woodcutting.Woodcutting;
24import com.runehive.game.Graphic;
25import com.runehive.game.UpdatePriority;
26import com.runehive.game.world.World;
27import com.runehive.game.world.entity.EntityType;
28import com.runehive.game.world.entity.mob.Mob;
29import com.runehive.game.world.entity.mob.UpdateFlag;
30import com.runehive.game.world.entity.mob.player.Player;
31import com.runehive.game.world.entity.mob.prayer.Prayer;
32import com.runehive.net.packet.out.*;
33import com.runehive.util.Utility;
35import java.util.LinkedList;
37import java.util.function.Function;
38import java.util.stream.IntStream;
63 for (
int index = 0; index <
skills.length; index++) {
64 boolean hitpoints =
mob.isPlayer() && index == 3;
65 skills[index] = hitpoints ?
new Skill(index, 10, 1154) :
new Skill(index, 1, 0);
85 public static double calculateCombat(
int attack,
int defence,
int strength,
int hp,
int prayer,
int ranged,
int magic) {
86 int combat = (defence + hp + prayer / 2) * 250;
87 int melee = (attack + strength) * 325;
88 int range = (ranged / 2 + ranged) * 325;
89 int mage = (magic / 2 + magic) * 325;
90 combat += Math.max(Math.max(melee, range), mage);
96 if (id < 0 || id >=
skills.length) {
97 throw new IllegalArgumentException(
"The skill id is out of bounds! id=" +
id);
121 if (
mob.isPlayer() &&
id <=
Skill.
MAGIC && !
mob.getPlayer().quickPrayers.getEnabled().isEmpty()) {
122 List<Prayer> deactivate =
new LinkedList<>();
123 for (
Prayer prayer :
mob.getPlayer().quickPrayers.getEnabled())
124 if (!prayer.canToggle(
mob.getPlayer()))
125 deactivate.add(prayer);
126 if (!deactivate.isEmpty())
127 mob.getPlayer().quickPrayers.deactivate(deactivate.toArray(
new Prayer[deactivate.size()]));
135 skill.setLevel(level);
136 skill.setMaxLevel(level);
137 skill.setExperience(experience);
144 skill.setLevel(level);
145 skill.setMaxLevel(level);
149 public void modifyLevel(Function<Integer, Integer> modification,
int id,
int lowerBound,
int upperBound) {
151 skill.modifyLevel(modification, lowerBound, upperBound);
167 public void modifyLevel(Function<Integer, Integer> modification,
int id) {
169 skill.modifyLevel(modification);
176 total +=
skill.getMaxLevel();
184 totalXp +=
skill.getExperience();
205 IntStream.range(0,
skills.length).forEach(this::restore);
222 mob.getPlayer().send(
new SendMessage(
"You have successfully mastered all skills."));
227 if (
mob.isPlayer()) {
237 for (
int index = 0; index < maxCount; index++) {
249 return count == maxCount;
256 boolean success =
false;
258 success |=
skill.onEvent(player, interactionEvent);
276 public void addExperience(
int id,
double experience,
boolean levelUp,
boolean counter) {
277 if (!
mob.isPlayer() ||
mob.getPlayer().settings.lockExperience)
282 double old =
skill.getExperience();
283 double modified_experience = experience;
299 bonusXp = Math.ceil((experience *
Mining.
getBonus(player)) / 100);
302 bonusXp = Math.ceil((experience *
Prayer.
getBonus(player)) / 100);
312 modified_experience += bonusXp;
315 modified_experience *= 2;
331 if (
skill.getExperience() >= 200_000_000) {
340 if (maxLevel < 99 && newMax != maxLevel) {
341 skill.setMaxLevel(newMax);
343 if (
skill.getLevel() <= newMax) {
344 skill.modifyLevel(level -> (newMax - maxLevel) + level);
352 if (newMax == 99 && !
combat) {
365 if (
skill.getMaxLevel() == 99) {
375 String line1 =
"Congratulations! You've just advanced " +
Utility.
getAOrAn(skillData.
toString()) +
" " + skillData +
" level!";
376 String line2 =
"You have reached level " +
skill.getMaxLevel() +
"!";
399 if (newLevel != oldLevel) {
401 mob.getPlayer().send(
new SendMessage(
"You've reached a combat level of " + newLevel +
"."));
416 boolean doingSkill =
false;
418 if (
skill.isDoingSkill()) {
420 skill.setDoingSkill(
false);
424 mob.resetAnimation();
456 if (
mob.isPlayer()) {
475 return super.toString();
The class that contains setting-related constants for the server.
static boolean DOUBLE_EXPERIENCE
Handles contribution towards the well of goodwill.
static boolean isActive()
Handles the achievements.
static void activate(Player player, AchievementKey achievement)
Activates the achievement for the individual player.
static void set(Player player, AchievementKey achievement, int increase)
void setActive(boolean active)
static boolean inGameArea(Player player)
Handles checking if the player is in the LMS game area.
int totalPrestige
The total amount of prestiges.
Handles the cooking skill.
Handles the crafting skill.
static double getBonus(Player player)
static double getBonus(Player player)
Handles the fishing skill.
static double getBonus(Player player)
Handles the fletching skill.
Handles the herblore skill.
Handles the hunter skill.
Handles the mining skill.
static double getBonus(Player player)
Handles sacrificing bones to an altar.
Handles the runecrafting skill.
static void clearInterfaces(Player player)
Sends the items on the smelting itemcontainer.
Handles the thieving skill.
static double getBonus(Player player)
Represents a single graphic that can be used by entities.
Represents the game world.
static void sendMessage(String... messages)
Sends a global message.
Optional< Graphic > graphic
This class represents a character controlled by a player.
String getName()
Gets the name of this entity.
DialogueFactory dialogueFactory
void send(OutgoingPacket encoder)
Represents a trainable and usable skill.
static final int WOODCUTTING
The woodcutting skill id.
static String getName(int skill)
Gets the name for a skill id.
static final byte getLevelForExperience(double experience)
Gets the level for a given experience amount.
void modifyLevel(Function< Integer, Integer > function)
Modifies the current level with a given function.
static final int PRAYER
The prayer skill id.
static final int RANGED
The ranged skill id.
static final int CRAFTING
The crafting skill id.
static final int HERBLORE
The herblore skill id.
static final int SMITHING
The smithing skill id.
static final int FISHING
The fishing skill id.
static final int DEFENCE
The defence skill id.
static final int CONSTRUCTION
The construction skill id.
static final int SKILL_COUNT
The amount of available skills.
int getLevel()
Gets the current skill level.
static final int FLETCHING
The fletching skill id.
static final int FIREMAKING
The firemaking skill id.
static final int MAGIC
The magic skill id.
static final int ATTACK
The attack skill id.
static final int FARMING
The farming skill id.
static final int THIEVING
The thieving skill id.
static final int HUNTER
The hunter skill id.
static final int STRENGTH
The strength skill id.
static final int COOKING
The cooking skill id.
static final int getExperienceForLevel(int level)
Gets the experience for a given level.
static final int MINING
The mining skill id.
int getMaxLevel()
Gets the maximum skill level.
static final int HITPOINTS
The hitpoints skill id.
static final int RUNECRAFTING
The runecrafting skill id.
void updateCombat()
Handles updating the combat level.
void addExperience(int id, double experience)
Adds experience to a given skill.
void modifyLevel(Function< Integer, Integer > modification, int id, int lowerBound, int upperBound)
Sets the level of a skill.
void addExperience(int id, double experience, boolean levelUp)
Adds experience to a given skill.
void master()
Handles mastering all skills.
double experienceCounter
The experience counter.
void restore(int id)
Restores a specific skill.
Skill[] getSkills()
Gets the skills of the mob.
static double calculateCombat(int attack, int defence, int strength, int hp, int prayer, int ranged, int magic)
Calculates the combat level of an mob.
void setMaxLevel(int id, int level)
Sets the max level of a skill.
int getLevel(int id)
Gets the level of a skill.
void setSkills(Skill[] skills)
Sets the skills of the mob.
int getCombatLevel()
Gets the mob's combat level.
int getMaxLevel(int id)
Gets the highest possible level of a skill.
void updateSkill(Player player, int maxLevel, int newMax, Skill skill, boolean levelUp, boolean combat)
Handles updating a skill.
double calculateCombat()
Calculates the combat level of an mob.
void setNpcMaxLevel(int id, int level)
Sets the experience for a npc skill.
void setCombatLevel()
Sets the mob's combat level.
void sendSkills()
Sends all skills to this player's client.
void showLevelUpInterface(Player player, Skill skill)
void addExperience(int id, double experience, boolean levelUp, boolean counter)
Adds experience to a given skill.
void login()
Handles a player logging in.
void refresh()
Refreshes all the skills for the mob.
void setExperience(int id, double experience)
Sets the experience for a skill.
int getTotalLevel()
Gets the total level of the mob.
void modifyLevel(Function< Integer, Integer > modification, int id)
Sets the level of a skill.
double combatLevel
The mob's combat level.
boolean isMaxed()
Checks if the mob is maxed in all skills.
boolean onEvent(InteractionEvent interactionEvent)
The interactionEvent listener.
void regress(int skill)
Handles regressing the skills.
final Mob mob
The mob to manage for.
SkillManager(Mob mob)
Constructs a new SkillManager object.
void setLevel(int id, int level)
Sets the level of a skill.
void refresh(int id)
Refreshes a skill to a player's client if this class's mob is a player.
Skill[] skills
An array of skills that belong to an mob.
int getExpCounter()
Gets the experience counter value.
void restoreAll()
Restores all the skills.
Sends experience to the client's experience counter.
The OutgoingPacket that sends a message to a Players chatbox in the client.
Sends a skill to a client.
The OutgoingPacket that sends a string to a Players itemcontainer in the client.
Handles miscellaneous methods.
static String getAOrAn(String nextWord)
A or an.
Represents different priorities for updating.
VERY_HIGH
A very high priority.
static String getColor(PlayerRight right)
static double getBonus(Player player)
The enumerated type whose elements represent data for the skills.
final int getSecondLine()
Gets the second line that level up text will be printed on.
final int getChatbox()
Gets the chatbox itemcontainer displayed on level up.
final int getFirstLine()
Gets the first line that level up text will be printed on.
final boolean isCombatSkill()
Gets if the skill is combat related.