Thread: FireSpell.java re-write

Results 1 to 4 of 4
  1. #1 FireSpell.java re-write 
    Registered Member
    Join Date
    May 2018
    Posts
    19
    Thanks given
    2
    Thanks received
    2
    Rep Power
    23
    this pretty much gives proper tome of fire support since there is none in kronos, enjoy.

    Code:
    package io.ruin.model.skills.magic.spells.modern;
    
    import io.ruin.cache.ItemDef;
    import io.ruin.model.combat.Hit;
    import io.ruin.model.entity.Entity;
    import io.ruin.model.entity.player.Player;
    import io.ruin.model.item.actions.impl.chargable.TomeOfFire;
    import io.ruin.model.item.containers.Equipment;
    import io.ruin.model.skills.magic.spells.TargetSpell;
    
    /**
     *
     * @Author Morrigan
     *
     * checks for tome before & after properly
     *
     *
     */
    
    public class FireSpell extends TargetSpell {
    
        static {
            ItemDef.cached.values().stream().filter(def -> def.name.toLowerCase().contains("tome of fire")).forEach(def -> def.tomeOfFire = true);
        }
    
        public static boolean hasTomeEquipped(Player player) {
            ItemDef def = player.getEquipment().getDef(Equipment.SLOT_SHIELD);
            return def != null && ((ItemDef) def).tomeOfFire;
        }
    
        @Override
        protected void beforeHit(Hit hit, Entity target) {
            super.beforeHit(hit, target);
            if (hit.attacker != null && hit.attacker.player != null) {
                if (hasTomeEquipped(hit.attacker.player)) {
                    TomeOfFire.consumeCharge(hit.attacker.player);
                    hit.boostDamage(0.5);
                }
            }
        }
    
        @Override
        public void afterHit(Hit hit, Entity target) {
            if(hit.damage > 0 && target.player != null) {
            if (!hasTomeEquipped(hit.attacker.player)) {
                return;
            }
            }
        }
    
    }
    thanks @Polar for guidance and helping me clean it up a bit
    Reply With Quote  
     

  2. Thankful user:


  3. #2  
    Donator

    Join Date
    Jun 2010
    Posts
    670
    Thanks given
    89
    Thanks received
    26
    Rep Power
    54
    This is wrong and won't remove any charges. You don't have to change anything in firespell class at all...

    Replace your consumeCharge boolean in TomeOfFire.java with this and it should work:

    Code:
    public static boolean consumeCharge(Player player) {
            Item item = player.getEquipment().get(Equipment.SLOT_SHIELD);
            if(item == null || item.getId()!=CHARGED)
                return false;
            int charges = AttributeExtensions.getCharges(item);
            item.putAttribute(AttributeTypes.CHARGES, charges - 1);
            if (charges == 0) {
                player.sendMessage(Color.RED.wrap("Your tome has ran out of charges!"));
                item.setId(UNCHARGED);
            }
            return true;
        }
    The issue was that it couldn't find the item because the finditem method only looks for items without attribute hash.
    Reply With Quote  
     

  4. #3  
    Registered Member
    Join Date
    Apr 2022
    Posts
    11
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by MarkQ View Post
    This is wrong and won't remove any charges. You don't have to change anything in firespell class at all...

    Replace your consumeCharge boolean in TomeOfFire.java with this and it should work:

    Code:
    public static boolean consumeCharge(Player player) {
            Item item = player.getEquipment().get(Equipment.SLOT_SHIELD);
            if(item == null || item.getId()!=CHARGED)
                return false;
            int charges = AttributeExtensions.getCharges(item);
            item.putAttribute(AttributeTypes.CHARGES, charges - 1);
            if (charges == 0) {
                player.sendMessage(Color.RED.wrap("Your tome has ran out of charges!"));
                item.setId(UNCHARGED);
            }
            return true;
        }
    The issue was that it couldn't find the item because the finditem method only looks for items without attribute hash.
    When using this snippet code I get an error loading server. Cant find get(Equipment.SLOT_SHIELD);
    Reply With Quote  
     

  5. #4  
    Registered Member
    Join Date
    Nov 2020
    Posts
    6
    Thanks given
    0
    Thanks received
    2
    Rep Power
    0
    Quote Originally Posted by bigvloei View Post
    When using this snippet code I get an error loading server. Cant find get(Equipment.SLOT_SHIELD);
    Did you make sure to import the Equipment class?
    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. [PI] Connection.java re-written
    By Arithium in forum Snippets
    Replies: 8
    Last Post: 09-24-2012, 11:03 AM
  2. Re-write C program (paying)
    By endofpures in forum Homework
    Replies: 3
    Last Post: 04-05-2012, 09:47 PM
  3. [PI] Re-writing NPC Drops
    By Vault in forum Help
    Replies: 21
    Last Post: 12-23-2010, 10:03 PM
  4. Could someone re-write this?
    By Th3Sinz in forum Help
    Replies: 0
    Last Post: 01-24-2010, 12:45 AM
  5. Making a Java File Write Content on Websites
    By Nima304 in forum Application Development
    Replies: 2
    Last Post: 03-09-2009, 05:13 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
  •