Thread: [Elvarg 3.2] Fixing autocasting

Results 1 to 2 of 2
  1. #1 [Elvarg 3.2] Fixing autocasting 
    Registered Member
    Join Date
    Jan 2022
    Posts
    49
    Thanks given
    1
    Thanks received
    10
    Rep Power
    11
    Hey guys,

    Just thought i'd start posting some fixes as I find them. So on Elvarg, by default the autocast buttons on staff weapon interfaces are disabled. Players can autocast any spell at any time. The downside of this is the spell gets deactivated when a new weapon is equipped. This is frustrating and makes switching/bridding very painful.

    Expected behaviour:
    -Player should be able to select autocast spells from the buttons on the weapon interface, when a staff is equipped
    -Player shouldn't be able to autocast without having a staff equipped
    -Autocast spell should be remembered if player switches to e.g. magic short bow then back to their staff

    I spent a few hours before work fixing it this morning.

    Since we're in 2022, here's a .patch which should be applied pretty smooth:
    Code:
    Index: ElvargServer/src/main/java/com/elvarg/game/model/container/impl/Equipment.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    diff --git a/ElvargServer/src/main/java/com/elvarg/game/model/container/impl/Equipment.java b/ElvargServer/src/main/java/com/elvarg/game/model/container/impl/Equipment.java
    --- a/ElvargServer/src/main/java/com/elvarg/game/model/container/impl/Equipment.java	(revision 2670d90145af0480770ea1fa813bf2926931c89e)
    +++ b/ElvargServer/src/main/java/com/elvarg/game/model/container/impl/Equipment.java	(date 1660208660557)
    @@ -1,5 +1,6 @@
     package com.elvarg.game.model.container.impl;
     
    +import com.elvarg.game.content.combat.WeaponInterfaces;
     import com.elvarg.game.definition.ItemDefinition;
     import com.elvarg.game.entity.impl.player.Player;
     import com.elvarg.game.model.Item;
    @@ -146,4 +147,14 @@
             }
             return count >= 3;
         }
    +
    +    public boolean hasStaffEquipped() {
    +        Item staff = get(Equipment.WEAPON_SLOT);
    +        return (staff != null && (getPlayer().getWeapon() == WeaponInterfaces.WeaponInterface.STAFF
    +                || getPlayer().getWeapon() == WeaponInterfaces.WeaponInterface.ANCIENT_STAFF));
    +    }
    +
    +    public Item getWeapon() {
    +        return get(Equipment.WEAPON_SLOT);
    +    }
     }
    Index: ElvargServer/src/main/java/com/elvarg/net/packet/impl/ButtonClickPacketListener.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    diff --git a/ElvargServer/src/main/java/com/elvarg/net/packet/impl/ButtonClickPacketListener.java b/ElvargServer/src/main/java/com/elvarg/net/packet/impl/ButtonClickPacketListener.java
    --- a/ElvargServer/src/main/java/com/elvarg/net/packet/impl/ButtonClickPacketListener.java	(revision 2670d90145af0480770ea1fa813bf2926931c89e)
    +++ b/ElvargServer/src/main/java/com/elvarg/net/packet/impl/ButtonClickPacketListener.java	(date 1660199519028)
    @@ -60,10 +60,7 @@
     	private static final int PRICE_CHECKER_DEPOSIT_ALL = 18252;
     	private static final int TOGGLE_EXP_LOCK = 476;
     	private static final int OPEN_WORLD_MAP = 156;
    -	
    -	// Autocast buttons
    -	private static final int AUTOCAST_BUTTON_1 = 349;
    -	private static final int AUTOCAST_BUTTON_2 = 24111;
    +
     	// Trade buttons
     	private static final int TRADE_ACCEPT_BUTTON_1 = 3420;
     	private static final int TRADE_ACCEPT_BUTTON_2 = 3546;
    @@ -83,7 +80,9 @@
     		if (PrayerHandler.togglePrayer(player, button)) {
     			return true;
     		}
    -		if (Autocasting.toggleAutocast(player, button)) {
    +		if (Autocasting.handleWeaponInterface(player, button)
    +				|| Autocasting.handleAutocastTab(player, button)
    +				|| Autocasting.toggleAutocast(player, button)) {
     			return true;
     		}
     		if (WeaponInterfaces.changeCombatSettings(player, button)) {
    @@ -248,13 +247,6 @@
     		case CANCEL_DESTROY_ITEM:
     			player.getPacketSender().sendInterfaceRemoval();
     			break;
    -
    -		case AUTOCAST_BUTTON_1:
    -		case AUTOCAST_BUTTON_2:
    -			player.getPacketSender()
    -					.sendMessage("A spell can be autocast by simply right-clicking on it in your Magic spellbook and ")
    -					.sendMessage("selecting the \"Autocast\" option.");
    -			break;
     
     		case TOGGLE_EXP_LOCK:
     			player.setExperienceLocked(!player.experienceLocked());
    Index: ElvargServer/src/main/java/com/elvarg/game/model/container/ItemContainer.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    diff --git a/ElvargServer/src/main/java/com/elvarg/game/model/container/ItemContainer.java b/ElvargServer/src/main/java/com/elvarg/game/model/container/ItemContainer.java
    --- a/ElvargServer/src/main/java/com/elvarg/game/model/container/ItemContainer.java	(revision 2670d90145af0480770ea1fa813bf2926931c89e)
    +++ b/ElvargServer/src/main/java/com/elvarg/game/model/container/ItemContainer.java	(date 1660196864988)
    @@ -862,4 +862,13 @@
     
             return Long.toString(value);
         }
    +
    +    public boolean hasAt(int slot, int item) {
    +        Item at = items[slot];
    +        return at != null && at.getId() == item;
    +    }
    +
    +    public boolean hasAt(int slot) {
    +        return slot >= 0 & slot < items.length && items[slot] != null;
    +    }
     }
    Index: ElvargServer/src/main/java/com/elvarg/game/content/combat/magic/Autocasting.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    diff --git a/ElvargServer/src/main/java/com/elvarg/game/content/combat/magic/Autocasting.java b/ElvargServer/src/main/java/com/elvarg/game/content/combat/magic/Autocasting.java
    --- a/ElvargServer/src/main/java/com/elvarg/game/content/combat/magic/Autocasting.java	(revision 2670d90145af0480770ea1fa813bf2926931c89e)
    +++ b/ElvargServer/src/main/java/com/elvarg/game/content/combat/magic/Autocasting.java	(date 1660212862463)
    @@ -1,11 +1,130 @@
     package com.elvarg.game.content.combat.magic;
     
    +import com.elvarg.game.content.combat.FightType;
    +import com.elvarg.game.content.combat.WeaponInterfaces;
     import com.elvarg.game.entity.impl.player.Player;
    +import com.elvarg.game.model.MagicSpellbook;
     import com.elvarg.game.model.Skill;
     import com.elvarg.game.model.equipment.BonusManager;
     
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Set;
    +
    +import static com.elvarg.util.ItemIdentifiers.*;
    +
     public class Autocasting {
     
    +    // Autocast buttons
    +    private static final int REGULAR_AUTOCAST_BUTTON = 349;
    +    private static final int DEFENSIVE_AUTOCAST_BUTTON = 24111;
    +    private static final int CLOSE_REGULAR_AUTOCAST_BUTTON = 2004;
    +    private static final int CLOSE_ANCIENT_AUTOCAST_BUTTON = 6161;
    +
    +    private static final int REGULAR_AUTOCAST_TAB = 1829;
    +    private static final int ANCIENT_AUTOCAST_TAB = 1689;
    +    private static final int IBANS_AUTOCAST_TAB = 12050;
    +
    +    public static final Set<Integer> ANCIENT_SPELL_AUTOCAST_STAFFS = Set.of(KODAI_WAND, MASTER_WAND,
    +            ANCIENT_STAFF,NIGHTMARE_STAFF,VOLATILE_NIGHTMARE_STAFF,ELDRITCH_NIGHTMARE_STAFF, TOXIC_STAFF_OF_THE_DEAD, ELDER_WAND, STAFF_OF_THE_DEAD, STAFF_OF_LIGHT);
    +
    +    public static HashMap<Integer, CombatSpells> AUTOCAST_SPELLS = new HashMap<>();
    +
    +    static {
    +        // Modern
    +        AUTOCAST_SPELLS.put(1830, CombatSpells.WIND_STRIKE);
    +        AUTOCAST_SPELLS.put(1831, CombatSpells.WATER_STRIKE);
    +        AUTOCAST_SPELLS.put(1832, CombatSpells.EARTH_STRIKE);
    +        AUTOCAST_SPELLS.put(1833, CombatSpells.FIRE_STRIKE);
    +        AUTOCAST_SPELLS.put(1834, CombatSpells.WIND_BOLT);
    +        AUTOCAST_SPELLS.put(1835, CombatSpells.WATER_BOLT);
    +        AUTOCAST_SPELLS.put(1836, CombatSpells.EARTH_BOLT);
    +        AUTOCAST_SPELLS.put(1837, CombatSpells.FIRE_BOLT);
    +        AUTOCAST_SPELLS.put(1838, CombatSpells.WIND_BLAST);
    +        AUTOCAST_SPELLS.put(1839, CombatSpells.WATER_BLAST);
    +        AUTOCAST_SPELLS.put(1840, CombatSpells.EARTH_BLAST);
    +        AUTOCAST_SPELLS.put(1841, CombatSpells.FIRE_BLAST);
    +        AUTOCAST_SPELLS.put(1842, CombatSpells.WIND_WAVE);
    +        AUTOCAST_SPELLS.put(1843, CombatSpells.WATER_WAVE);
    +        AUTOCAST_SPELLS.put(1844, CombatSpells.EARTH_WAVE);
    +        AUTOCAST_SPELLS.put(1845, CombatSpells.FIRE_WAVE);
    +
    +        // Ancients
    +        AUTOCAST_SPELLS.put(13189, CombatSpells.SMOKE_RUSH);
    +        AUTOCAST_SPELLS.put(13241, CombatSpells.SHADOW_RUSH);
    +        AUTOCAST_SPELLS.put(13247, CombatSpells.BLOOD_RUSH);
    +        AUTOCAST_SPELLS.put(6162, CombatSpells.ICE_RUSH);
    +        AUTOCAST_SPELLS.put(13215, CombatSpells.SMOKE_BURST);
    +        AUTOCAST_SPELLS.put(13267, CombatSpells.SHADOW_BURST);
    +        AUTOCAST_SPELLS.put(13167, CombatSpells.BLOOD_BURST);
    +        AUTOCAST_SPELLS.put(13125, CombatSpells.ICE_BURST);
    +        AUTOCAST_SPELLS.put(13202, CombatSpells.SMOKE_BLITZ);
    +        AUTOCAST_SPELLS.put(13254, CombatSpells.SHADOW_BLITZ);
    +        AUTOCAST_SPELLS.put(13158, CombatSpells.BLOOD_BLITZ);
    +        AUTOCAST_SPELLS.put(13114, CombatSpells.ICE_BLITZ);
    +        AUTOCAST_SPELLS.put(13228, CombatSpells.SMOKE_BARRAGE);
    +        AUTOCAST_SPELLS.put(13280, CombatSpells.SHADOW_BARRAGE);
    +        AUTOCAST_SPELLS.put(13178, CombatSpells.BLOOD_BARRAGE);
    +        AUTOCAST_SPELLS.put(13136, CombatSpells.ICE_BARRAGE);
    +    }
    +
    +    public static boolean handleAutocastTab(final Player player, int actionButtonId) {
    +        if (AUTOCAST_SPELLS.containsKey(actionButtonId)) {
    +            setAutocast(player, AUTOCAST_SPELLS.get(actionButtonId).getSpell());
    +            WeaponInterfaces.assign(player);
    +            return true;
    +        }
    +
    +        switch(actionButtonId) {
    +            case CLOSE_REGULAR_AUTOCAST_BUTTON:
    +            case CLOSE_ANCIENT_AUTOCAST_BUTTON:
    +                setAutocast(player, null); // When clicking cancel, remove autocast?
    +                player.getPacketSender().sendTabInterface(0, player.getWeapon().getInterfaceId());
    +                return true;
    +        }
    +
    +        return false;
    +    }
    +
    +    public static boolean handleWeaponInterface(final Player player, int actionButtonId) {
    +        if (actionButtonId != REGULAR_AUTOCAST_BUTTON && actionButtonId != DEFENSIVE_AUTOCAST_BUTTON) {
    +            return false;
    +        }
    +
    +        if (player.getSpellbook() == MagicSpellbook.LUNAR) {
    +            player.getPacketSender().sendMessage("You can't autocast lunar spells.");
    +            return true;
    +        }
    +
    +        if (!player.getEquipment().hasStaffEquipped()) {
    +            return true;
    +        }
    +
    +        switch (player.getSpellbook()) {
    +            case ANCIENT -> {
    +                if (!ANCIENT_SPELL_AUTOCAST_STAFFS.contains(player.getEquipment().getWeapon().getId()) && player.getEquipment().getWeapon().getId() != AHRIMS_STAFF) {
    +                    // Ensure this is a staff capable of casting ancients. Ahrims staff can cast both regular and ancients.
    +                    player.getPacketSender().sendMessage("You can only autocast regular offensive spells with this staff.");
    +                    return true;
    +                }
    +
    +                player.getPacketSender().sendTabInterface(0, ANCIENT_AUTOCAST_TAB);
    +            }
    +
    +            case NORMAL -> {
    +                if (player.getEquipment().getWeapon().getId() == ANCIENT_STAFF) {
    +                    player.getPacketSender().sendMessage("You can only autocast ancient magicks with that.");
    +                    return true;
    +                }
    +
    +                player.getPacketSender().sendTabInterface(0, REGULAR_AUTOCAST_TAB);
    +            }
    +        }
    +
    +        player.getPacketSender().sendMessage("You can set a default autocast spell any time from the magic tab.");
    +        return true;
    +    }
    +
         public static boolean toggleAutocast(final Player player, int actionButtonId) {
             CombatSpell cbSpell = CombatSpells.getCombatSpell(actionButtonId);
             if (cbSpell == null) {
    @@ -29,17 +148,40 @@
                 setAutocast(player, cbSpell);
     
             }
    +
             return true;
         }
     
         public static void setAutocast(Player player, CombatSpell spell) {
    +        // First, set the Player's preferred autocast spell
    +        player.getCombat().setAutocastSpell(spell);
    +
    +        if (!player.getEquipment().hasStaffEquipped() && spell != null) {
    +            player.getPacketSender().sendMessage("Default spell set. Please equip a staff to use autocast.");
    +            return;
    +        }
    +
             if (spell == null) {
                 player.getPacketSender().sendAutocastId(-1).sendConfig(108, 3);
             } else {
                 player.getPacketSender().sendAutocastId(spell.spellId()).sendConfig(108, 1);
             }
    -        player.getCombat().setAutocastSpell(spell);
     
             BonusManager.update(player);
    +        updateConfigsOnAutocast(player, spell != null);
    +    }
    +
    +    private static final List<FightType> STAFF_FIGHT_TYPES = List.of(
    +            FightType.STAFF_BASH,
    +            FightType.STAFF_FOCUS,
    +            FightType.STAFF_POUND
    +    );
    +
    +    private static void updateConfigsOnAutocast(final Player player, boolean autocast) {
    +        if (autocast) {
    +            for (final FightType type : STAFF_FIGHT_TYPES) {
    +                player.getPacketSender().sendConfig(type.getParentId(), 3);
    +            }
    +        }
         }
     }
    Index: ElvargServer/src/main/java/com/elvarg/net/packet/impl/EquipPacketListener.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    diff --git a/ElvargServer/src/main/java/com/elvarg/net/packet/impl/EquipPacketListener.java b/ElvargServer/src/main/java/com/elvarg/net/packet/impl/EquipPacketListener.java
    --- a/ElvargServer/src/main/java/com/elvarg/net/packet/impl/EquipPacketListener.java	(revision 2670d90145af0480770ea1fa813bf2926931c89e)
    +++ b/ElvargServer/src/main/java/com/elvarg/net/packet/impl/EquipPacketListener.java	(date 1660208700347)
    @@ -33,10 +33,6 @@
     		}
     		player.getPacketSender().sendSpecialAttackState(false);
     		WeaponInterfaces.assign(player);
    -		if (player.getCombat().getAutocastSpell() != null) {
    -			Autocasting.setAutocast(player, null);
    -			player.getPacketSender().sendMessage("Autocast spell cleared.");
    -		}
     	}
     
     	@Override
    Index: ElvargServer/src/main/java/com/elvarg/game/content/combat/CombatFactory.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    diff --git a/ElvargServer/src/main/java/com/elvarg/game/content/combat/CombatFactory.java b/ElvargServer/src/main/java/com/elvarg/game/content/combat/CombatFactory.java
    --- a/ElvargServer/src/main/java/com/elvarg/game/content/combat/CombatFactory.java	(revision 2670d90145af0480770ea1fa813bf2926931c89e)
    +++ b/ElvargServer/src/main/java/com/elvarg/game/content/combat/CombatFactory.java	(date 1660207087835)
    @@ -111,7 +111,9 @@
     			p.getCombat().setRangedWeapon(RangedWeapon.getFor(p));
     
     			// Check if player is maging..
    -			if (p.getCombat().getCastSpell() != null || p.getCombat().getAutocastSpell() != null) {
    +			if (p.getCombat().getCastSpell() != null ||
    +					// Ensure player needs staff equipped to use autocast
    +					(p.getCombat().getAutocastSpell() != null && p.getEquipment().hasStaffEquipped())) {
     				return MAGIC_COMBAT;
     			}
    To import, save the code in a .patch file, go into IntelliJ, Git > Patch > Apply Patch (or apply from clipboard)

    You will be presented with a diff of all files changed.

    Please note: This doesnt fix the button highlights, that would require a lot more client work etc. This just gets the basic functionality working. I will be fixing the button highlights in my elvarg repo and webclient.
    If you want more fixes like this and get automatic improvements in the future, please fork my copy of Elvarg: https://github.com/RSPSApp/elvarg-rsps

    Attached image
    Reply With Quote  
     

  2. Thankful user:


  3. #2  
    Registered Member
    Join Date
    Dec 2023
    Posts
    10
    Thanks given
    0
    Thanks received
    2
    Rep Power
    60
    hey can you help me fix auto casting on my 317 wen u tele it keeps casting ucan get a easy 99 and same with burying bones
    Reply With Quote  
     


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. [Elvarg/OSRS PK]Fixing broken textures
    By Zion in forum Snippets
    Replies: 12
    Last Post: 08-11-2019, 11:55 AM
  2. Replies: 15
    Last Post: 07-21-2017, 03:06 PM
  3. [OSRSPK/Elvarg] Duel Glitch fix needed.
    By kev2017 in forum Help
    Replies: 3
    Last Post: 07-09-2017, 10:31 AM
  4. Impact 2.0 Fixing Autocasting paying $10!
    By FuckThePolice in forum Help
    Replies: 3
    Last Post: 06-07-2011, 10:53 PM
  5. Fix autocasting
    By Loony. in forum Help
    Replies: 6
    Last Post: 06-22-2009, 08:27 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
  •