Code:
package com.rs.game.player.actions.magic;
/**
* @author Sagacity
* Date: 25/09/2021
*/
import com.rs.game.Animation;
import com.rs.game.Graphics;
import com.rs.game.item.Item;
import com.rs.game.player.Player;
import com.rs.game.player.Skills;
import com.rs.game.player.actions.crafting.Enchanting;
import com.rs.game.player.content.ItemConstants;
import com.rs.game.player.content.Shop;
import com.rs.game.player.content.interfaces.achievements.Achievements;
import com.rs.utils.Utils;
public class MagicOnItem {
public static final int LOW_ALCHEMY = 38;
public static final int HIGH_ALCHEMY = 59;
public static final int SUPER_HEAT = 50;
public static final int LV1_ENCHANT = 29;
public static final int LV2_ENCHANT = 41;
public static final int LV3_ENCHANT = 53;
public static final int LV4_ENCHANT = 61;
public static final int LV5_ENCHANT = 76;
public static final int LV6_ENCHANT = 88;
private static final Graphics SUPERHEAT = new Graphics(148, 0, 100);
/**
* Handles the magic spell
* @Param player The player
* @Param magicId The magicId
* @Param item The item
*/
public static void handleMagic(Player player, int magicId, Item item) {
int itemId = item.getId();
switch (magicId) {
case LOW_ALCHEMY:
processAlchemy(player, itemId, item, true);
break;
case HIGH_ALCHEMY:
processAlchemy(player, itemId, item, false);
break;
case SUPER_HEAT:
processSuperheat(player, itemId);
break;
case LV1_ENCHANT:
Enchanting.startEnchant(player, itemId, 1);
break;
case LV2_ENCHANT:
Enchanting.startEnchant(player, itemId, 2);
break;
case LV3_ENCHANT:
Enchanting.startEnchant(player, itemId, 3);
break;
case LV4_ENCHANT:
Enchanting.startEnchant(player, itemId, 4);
break;
case LV5_ENCHANT:
Enchanting.startEnchant(player, itemId, 5);
break;
case LV6_ENCHANT:
Enchanting.startEnchant(player, itemId, 6);
break;
default:
player.getPackets().sendGameMessage("Invalid Magic Id: " + magicId + "");
break;
}
}
/**
* Processes the alchemy
* @Param player The player
* @Param itemId The itemId
* @Param item
* @Param low {@code True} for low alchemy, {@code False} for high
*/
public static void processAlchemy(Player player, int itemId, Item item, boolean low) {
if (!ItemConstants.isTradeable(item)) {
player.getPackets().sendGameMessage("That item is untradeable.");
return;
}
if (!player.canAlch()) {
player.getPackets().sendGameMessage("You need to wait 2 seconds to cast this spell.");
return;
}
if (player.getSkills().getLevel(Skills.MAGIC) < (low ? 21 : 55)) {
player.getPackets().sendGameMessage("You do not have the required level to cast this spell.");
return;
}
if (itemId == 995 || itemId == 4278) {
player
.getPackets()
.sendGameMessage("You can't " + (low ? "low" : "high") + " alch this!");
return;
}
if (player.hasFireStaff()) {
if (!player.getInventory().containsItem(561, 1)) {
player
.getPackets()
.sendGameMessage("You do not have the required runes to cast this spell.");
return;
}
} else {
if (!player.getInventory().containsItem(554, (low ? 3 : 5)) && !player.getInventory().containsItem(561, 1)) {
player
.getPackets()
.sendGameMessage("You do not have the required runes to cast this spell.");
return;
}
}
if (!player.hasFireStaff()) {
player.setNextAnimation(new Animation(low ? 712 : 713));
player.setNextGraphics(new Graphics(low ? 112 : 113));
} else {
player.setNextAnimation(new Animation(low ? 9625 : 9633));
player.setNextGraphics(new Graphics(low ? 1692 : 1693));
}
player.getInventory().deleteItem(561, 1);
if (!player.hasFireStaff()) {
player.getInventory().deleteItem(554, (low ? 3 : 5));
}
player.getInventory().deleteItem(itemId, 1);
int baseValue = Shop.getAlchPrice((itemId));
int value = baseValue / (low ? 3 : 2);
player.getInventory().addItem(995, value);
// player.getPouch().handleMoneyPouch(true, false, false, 0, -30);
player.getSkills().addXp(Skills.MAGIC, (low ? 50 : 65));
if (low) {
player.checkAchievementStatus(Achievements.Store.ALCHIMICUS, 1);
} else {
player.checkAchievementStatus(Achievements.Store.MASTER_ALCHIMICUS, 1);
}
player.setAlchDelay(1000L);
player.doAfterDelay(1, () -> {
player.getPackets().sendGlobalConfig(168, 7);
});
}
/**
* Processes the superheat
* @Param player The player
* @Param itemId The itemId
*/
public static void processSuperheat(Player player, int itemId) {
if (!player.canAlch()) {
player.getPackets().sendGameMessage("You need to wait 2 seconds to cast this spell.");
return;
}
if (player.getSkills().getLevel(Skills.MAGIC) < 43) {
player.getPackets().sendGameMessage("You do not have the required level to cast this spell.");
return;
}
// Items different than these cannot be superheated
if (itemId != 436 && itemId != 438 && itemId != 440 && itemId != 444 && itemId != 442 && itemId != 447 && itemId != 449 && itemId != 451 && itemId != 453) {
player.getPackets().sendGameMessage("This item can not be superheated!");
return;
}
if (player.hasFireStaff()) {
if (!player.getInventory().containsItem(561, 1)) {
player
.getPackets()
.sendGameMessage("You do not have the required runes to cast this spell.");
return;
}
} else {
if (!player.getInventory().containsItem(554, 4)) {
player
.getPackets()
.sendGameMessage("You do not have the required runes to cast this spell.");
return;
}
}
// Sends the superheats
switch (itemId) {
case 436: // bronze
case 438:
sendSuperheat(player, 1, itemId, new Item(itemId == 436 ? 438 : 436, 1), 2349, 12.5, false);
break;
case 440: // iron & steel
if (player.getInventory().containsItem(453, 3)) {
sendSuperheat(player, 30, itemId, new Item(453, 2), 2353, 22.5, true);
} else {
sendSuperheat(player, 15, itemId, null, 2351, 13.7, false);
}
break;
case 442: // silver
sendSuperheat(player, 20, itemId, null, 2355, 17.5, false);
break;
case 444: // gold
sendSuperheat(player, 40, itemId, null, 2357, 22.5, false);
break;
case 447: // mithril
sendSuperheat(player, 50, itemId, new Item(453, 4), 2359, 30, false);
break;
case 449: // adamant
sendSuperheat(player, 70, itemId, new Item(453, 6), 2361, 37.5, false);
break;
case 451: // rune
sendSuperheat(player, 85, itemId, new Item(453, 8), 2363, 50, false);
break;
}
}
/**
* Sends the superheating action
* @Param player The player
* @Param smithingRequired The smithing level required
* @Param mainOre The main ore we're smelting
* @Param secondaryOre The secondary ore - {@code null} if no not needed
* @Param superHeated The superheated item
* @Param magicXp The magic xp
* @Param isSteel Is it any other smelting than steel
*/
private static void sendSuperheat(Player player, int smithingRequired, int mainOre, Item secondaryOre, int superHeated, double magicXp, boolean isSteel) {
double SMITHING_XP = 45;
if (player.getSkills().getLevel(Skills.SMITHING) <= smithingRequired) {
player.getPackets().sendGameMessage("You need at least " + smithingRequired + " Smithing to superheat this ore.");
return;
}
if (player.getInventory().containsItem(mainOre, 1) && secondaryOre == null) {
player.getInventory().deleteItem(new Item(mainOre, 1));
} else if (secondaryOre != null && player.getInventory().containsItem(mainOre, 1)
&& player.getInventory().containsItem(secondaryOre.getId(), secondaryOre.getAmount())) {
player.getInventory().deleteItem(new Item(mainOre, 1));
player.getInventory().deleteItem(new Item(secondaryOre.getId(), secondaryOre.getAmount()));
} else {
Item main = new Item(mainOre);
player.getPackets().sendGameMessage("You don't have enough ores to superheat this ore");
if (secondaryOre != null) {
Item second = new Item(secondaryOre);
Item product = new Item(superHeated);
player.sm("Each <col=ff0000>"+product.getName()+"</col> needs <col=ff0000>" + main.getAmount() + "x " + main.getName() + "</col> and <col=ff0000>" + second.getAmount() + "x " + second.getName()+"</col> to be superheated!");
}
return;
}
// Delete the runes
player.getInventory().deleteItem(561, 1);
if (!player.hasFireStaff()) {
player.getInventory().deleteItem(554, 4);
}
player.setNextAnimation(new Animation(725));
player.setNextGraphics(SUPERHEAT);
Item item = new Item(superHeated, 1);
boolean successIron = false;
if (mainOre == 440 && player.getEquipment().getRingId() != 2568 && !isSteel) { // ring of forging | if not equipped, 50% chance of losing the bar
if (Utils.random(2) == 1) {
player.getInventory().addItem(item);
successIron = true;
} else {
player.sm("The ore was too impure and turned into dust causing its loss, perhaps I should use a Ring of forging while smelting these.");
}
} else {
player.getInventory().addItem(item);
}
// Goldsmith gloves gives * 1.2 more xp
boolean goldSmithGauntlets = mainOre == 444 && player.getEquipment().getGlovesId() == 776;
player.setAlchDelay(1000L);
player.doAfterDelay(1, ()-> {
player.getSkills().addXp(Skills.SMITHING, goldSmithGauntlets ? SMITHING_XP * 1.2 : SMITHING_XP);
player.getSkills().addXp(Skills.MAGIC, magicXp);
player.doAfterDelay(1, () -> player.getPackets().sendGlobalConfig(168, 7));
});
if (!successIron)
return;
player.getPackets().sendGameMessage("You've successfully superheat " + Utils.formatAorAn(item).toLowerCase() + ".");
}
}
Media: