1package com.osroyale.game.world.entity.skill;
3import com.osroyale.Config;
4import com.osroyale.content.WellOfGoodwill;
5import com.osroyale.content.achievement.AchievementHandler;
6import com.osroyale.content.achievement.AchievementKey;
7import com.osroyale.content.event.InteractionEvent;
8import com.osroyale.content.lms.LMSGame;
9import com.osroyale.content.skill.impl.cooking.Cooking;
10import com.osroyale.content.skill.impl.crafting.Crafting;
11import com.osroyale.content.skill.impl.farming.Farming;
12import com.osroyale.content.skill.impl.firemaking.Firemaking;
13import com.osroyale.content.skill.impl.fishing.Fishing;
14import com.osroyale.content.skill.impl.fletching.Fletching;
15import com.osroyale.content.skill.impl.herblore.Herblore;
16import com.osroyale.content.skill.impl.hunter.Hunter;
17import com.osroyale.content.skill.impl.mining.Mining;
18import com.osroyale.content.skill.impl.prayer.BoneSacrifice;
19import com.osroyale.content.skill.impl.runecrafting.Runecraft;
20import com.osroyale.content.skill.impl.smithing.Smelting;
21import com.osroyale.content.skill.impl.smithing.Smithing;
22import com.osroyale.content.skill.impl.thieving.Thieving;
23import com.osroyale.content.skill.impl.woodcutting.Woodcutting;
24import com.osroyale.game.Graphic;
25import com.osroyale.game.UpdatePriority;
26import com.osroyale.game.world.World;
27import com.osroyale.game.world.entity.EntityType;
28import com.osroyale.game.world.entity.mob.Mob;
29import com.osroyale.game.world.entity.mob.UpdateFlag;
30import com.osroyale.game.world.entity.mob.player.Player;
31import com.osroyale.game.world.entity.mob.prayer.Prayer;
32import com.osroyale.net.discord.DiscordPlugin;
33import com.osroyale.net.packet.out.*;
34import com.osroyale.util.Utility;
36import java.util.LinkedList;
38import java.util.function.Function;
39import java.util.stream.IntStream;
86 private final Mob mob;
92 private Skill[] skills;
95 private double combatLevel;
101 for (
int index = 0; index < skills.length; index++) {
102 boolean hitpoints = mob.isPlayer() && index == 3;
103 skills[index] = hitpoints ?
new Skill(index, 10, 1154) :
new Skill(index, 1, 0);
105 if (mob.isPlayer()) {
123 public static double calculateCombat(
int attack,
int defence,
int strength,
int hp,
int prayer,
int ranged,
int magic) {
124 int combat = (defence + hp + prayer / 2) * 250;
125 int melee = (attack + strength) * 325;
126 int range = (ranged / 2 + ranged) * 325;
127 int mage = (magic / 2 + magic) * 325;
128 combat += Math.max(Math.max(melee, range), mage);
129 return combat / 1000.0;
134 if (id < 0 || id >= skills.length) {
135 throw new IllegalArgumentException(
"The skill id is out of bounds! id=" +
id);
159 if (mob.isPlayer() &&
id <=
Skill.
MAGIC && !mob.getPlayer().quickPrayers.getEnabled().isEmpty()) {
160 List<Prayer> deactivate =
new LinkedList<>();
161 for (
Prayer prayer : mob.getPlayer().quickPrayers.getEnabled())
162 if (!prayer.canToggle(mob.getPlayer()))
163 deactivate.add(prayer);
164 if (!deactivate.isEmpty())
165 mob.getPlayer().quickPrayers.deactivate(deactivate.toArray(
new Prayer[deactivate.size()]));
171 Skill skill =
get(id);
173 skill.setLevel(level);
174 skill.setMaxLevel(level);
175 skill.setExperience(experience);
181 Skill skill =
get(id);
183 skill.setMaxLevel(level);
187 public void modifyLevel(Function<Integer, Integer> modification,
int id,
int lowerBound,
int upperBound) {
188 Skill skill =
get(id);
189 skill.
modifyLevel(modification, lowerBound, upperBound);
194 Skill s =
get(skill);
205 public void modifyLevel(Function<Integer, Integer> modification,
int id) {
206 Skill skill =
get(id);
213 for (
Skill skill : skills) {
214 total += skill.getMaxLevel();
219 public long getTotalXp() {
221 for (
Skill skill : skills) {
222 totalXp += skill.getExperience();
229 for (
final Skill skill : skills) {
236 Skill skill =
get(id);
237 skill.
setLevel(skill.getMaxLevel());
243 IntStream.range(0, skills.length).forEach(this::restore);
248 Smelting.clearInterfaces(mob.getPlayer());
260 mob.getPlayer().send(
new SendMessage(
"You have successfully mastered all skills."));
265 if (mob.isPlayer()) {
266 Skill skill =
get(id);
267 mob.getPlayer().send(
new SendSkill(skill));
275 for (
int index = 0; index < maxCount; index++) {
287 return count == maxCount;
294 boolean success =
false;
295 for (
final Skill skill : skills) {
296 success |= skill.onEvent(player, interactionEvent);
314 public void addExperience(
int id,
double experience,
boolean levelUp,
boolean counter) {
315 if (!mob.isPlayer() || mob.getPlayer().settings.lockExperience)
319 Skill skill =
get(id);
321 double modified_experience = experience;
324 player.send(
new SendExpCounter(skill.getSkill(), (
int) modified_experience, counter));
331 bonusXp = Math.ceil((experience *
Farming.getBonus(player)) / 100);
334 bonusXp = Math.ceil((experience *
Fishing.getBonus(player)) / 100);
337 bonusXp = Math.ceil((experience *
Mining.getBonus(player)) / 100);
340 bonusXp = Math.ceil((experience *
Prayer.getBonus(player)) / 100);
343 bonusXp = Math.ceil((experience *
Firemaking.getBonus(player)) / 100);
346 bonusXp = Math.ceil((experience *
Woodcutting.getBonus(player)) / 100);
350 modified_experience += bonusXp;
353 modified_experience *= 2;
364 player.send(
new SendExpCounter(skill.getSkill(), (
int) modified_experience, counter));
367 updateSkill(player, maxLevel, newMax, skill, levelUp, combatSkill);
369 if (skill.getExperience() >= 200_000_000) {
377 private void updateSkill(
Player player,
int maxLevel,
int newMax,
Skill skill,
boolean levelUp,
boolean combat) {
378 if (maxLevel < 99 && newMax != maxLevel) {
379 skill.setMaxLevel(newMax);
381 if (skill.getLevel() <= newMax) {
382 skill.modifyLevel(level -> (newMax - maxLevel) + level);
389 showLevelUpInterface(player, skill);
390 if (newMax == 99 && !combat) {
392 "<col=7B44B3>Tarnish: <col=" + player.right.getColor() +
">" + player.
getName() +
" </col>has just reached level 99 in <col=7B44B3>" +
Skill.
getName(skill.
getSkill()) +
"</col> with a prestige of " +player.prestige.
totalPrestige +
"!");
399 if (SkillData.values()[skill.
getSkill()].isCombatSkill()) {
404 AchievementHandler.activate(player, AchievementKey.SKILL_MASTERY, 1);
407 AchievementHandler.set(player, AchievementKey.TOTAL_LEVEL,
getTotalLevel());
411 private void showLevelUpInterface(Player player, Skill skill) {
412 SkillData skillData = SkillData.values()[skill.
getSkill()];
413 String line1 =
"Congratulations! You've just advanced " + Utility.getAOrAn(skillData.toString()) +
" " + skillData +
" level!";
414 String line2 =
"You have reached level " + skill.
getMaxLevel() +
"!";
415 player.send(
new SendString(line1, skillData.getFirstLine()));
416 player.send(
new SendString(line2, skillData.getSecondLine()));
417 player.send(
new SendChatBoxInterface(skillData.getChatbox()));
418 if(skillData == SkillData.HUNTER) {
419 player.send(
new SendMoveComponent(0, 5, 311));
420 player.send(
new SendInterfaceConfig(311, 200, 9951));
422 if(skillData == SkillData.FARMING) {
423 player.send(
new SendMoveComponent(0, 30, 311));
424 player.send(
new SendInterfaceConfig(311, 200, 5340));
426 String name = Skill.getName(skill.
getSkill());
427 player.send(
new SendMessage(
"Congratulations, you just advanced " + Utility.getAOrAn(name) +
" " + name +
" level."));
428 player.graphic(
new Graphic(199, UpdatePriority.VERY_HIGH));
429 player.dialogueFactory.setActive(
true);
433 private void updateCombat() {
437 if (newLevel != oldLevel) {
438 mob.updateFlags.add(UpdateFlag.APPEARANCE);
439 mob.getPlayer().send(
new SendMessage(
"You've reached a combat level of " + newLevel +
"."));
447 for (
Skill skill : skills) {
453 public void resetSkilling() {
454 boolean doingSkill =
false;
455 for (
Skill skill : skills) {
456 if (skill.isDoingSkill()) {
458 skill.setDoingSkill(
false);
462 mob.resetAnimation();
478 return (
int) combatLevel;
493 this.skills = skills;
494 if (mob.isPlayer()) {
512 public String toString() {
513 return super.toString();
static void activate(Player player, AchievementKey achievement)
static boolean inGameArea(Player player)
static void sendMessage(String... messages)
static final int CONSTRUCTION
static String getName(int skill)
static final int HERBLORE
static final int SMITHING
static final int getExperienceForLevel(int level)
static final int RUNECRAFTING
void modifyLevel(Function< Integer, Integer > function)
static final int SKILL_COUNT
static final int WOODCUTTING
static final int FLETCHING
static final int STRENGTH
static final int THIEVING
static final int FIREMAKING
static final int HITPOINTS
static final int CRAFTING
static final byte getLevelForExperience(double experience)
void addExperience(int id, double experience)
void addExperience(int id, double experience, boolean levelUp)
void setExperience(int id, double experience)
void setMaxLevel(int id, int level)
void setSkills(Skill[] skills)
void modifyLevel(Function< Integer, Integer > modification, int id)
static double calculateCombat(int attack, int defence, int strength, int hp, int prayer, int ranged, int magic)
void setLevel(int id, int level)
void setNpcMaxLevel(int id, int level)
void modifyLevel(Function< Integer, Integer > modification, int id, int lowerBound, int upperBound)
void addExperience(int id, double experience, boolean levelUp, boolean counter)
boolean onEvent(InteractionEvent interactionEvent)
static String getAOrAn(String nextWord)
final boolean isCombatSkill()