Thread: Nearly perfect Alchemy & Superheating

Results 1 to 2 of 2
  1. #1 Nearly perfect Alchemy & Superheating 
    Onyxia

    Sagacity's Avatar
    Join Date
    Dec 2012
    Age
    25
    Posts
    706
    Thanks given
    299
    Thanks received
    90
    Discord
    View profile
    Rep Power
    137
    If you see parts of your code here, ask for partial credits, cause this method was refactored by me to look better, and I have no idea who wrote it before (the alchemy part) but the superheating was written by me

    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:
    https://imgur.com/a/uZTS2o5
    Last edited by Sagacity; 09-26-2021 at 09:29 PM.

    Check out my 667/718 Interfaces services, I have more than 15 vouches and will be happy to help you out for affordable prices

    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    WVWVWVWVWVWVWVW

    _jordan's Avatar
    Join Date
    Nov 2012
    Age
    24
    Posts
    2,975
    Thanks given
    96
    Thanks received
    1,706
    Discord
    View profile
    Rep Power
    5000
    Thanks really been needing this.
    Reply With Quote  
     

  4. Thankful users:



Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Perfect SuperHeating?
    By Kastro in forum Show-off
    Replies: 11
    Last Post: 11-10-2009, 10:52 PM
  2. Replies: 11
    Last Post: 10-14-2007, 06:29 PM
  3. 100% 377 cache perfect item's! wear & levels!
    By littleplop in forum Tutorials
    Replies: 22
    Last Post: 08-24-2007, 01:00 AM
  4. Perfect Chick!
    By Inside Sin in forum Showcase
    Replies: 3
    Last Post: 07-31-2007, 08:48 PM
  5. Replies: 3
    Last Post: 06-13-2007, 09:36 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •