Thread: Lunar spells base

Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1 Lunar spells base 
    Registered Member
    Join Date
    Dec 2013
    Posts
    419
    Thanks given
    127
    Thanks received
    85
    Rep Power
    349
    I made this base for lunar spells for somebody. Just more of an OOP approach I guess.
    Didn't want to scrap it so posting this for whoever wants to use this design.

    I don't need feedback, thanks

    Code:
    public interface Spell {
        public abstract void execute(Player player);
        public abstract Item[] getItemRequirements(); //runes
        public abstract int getLevelRequirement();
    }
    Code:
    public abstract class LunarSpell extends Spell {
    
    }
    I chose to use a static factory for convenience I guess.

    Code:
    public class LunarFactory {
            //spell id, spell
    	private static Map<Integer, LunarSpell> spells = new HashMap<>();
    	static {
    		bind(30186, new StringJewlarySpell());
    		bind(30242, new PlankMakeSpell());
    		bind(30322, new SpellbookSwapSpell());
    		bind(30091, new CureMeSpell());
    		bind(30202, new MagicImbueSpell());
    		bind(30293, new NPCContactSpell());
    		bind(30154, new SuperGlassMakeSpell());
    	}
    	
    	public static void execute(Player player, int buttonId) {
    		LunarSpell spell = spells.get(buttonId);
    		if (spell != null) {
    			
    			if (player.getSkillManager().getCurrentLevel(Skill.MAGIC) < spell.getLevelRequirement()) {
    				player.sendMessage("You do not have the required magic level to cast this spell.");
    				return;
    			}
    			
    			if (!player.getInventory().contains(spell.getItemRequirements())) {
    				player.sendMessage("You do not have enough runes to cast this spell.");
    				return;
    			}
    			
    			spell.execute(player);
    			
    		} else {
    			System.err.println(buttonId + " has not been binded.");
    		}
    	}
    	
    	private static void bind(int buttonId, LunarSpell spell) {
    		spells.put(buttonId, spell);
    	}
    }
    Code:
    public class CureMe extends LunarSpell {
    
    	@Override
    	public void execute(Player player) {
    		if (player.isPoisoned()) {
    			player.setPoison(false);
    			player.sendMessage("You have been cured of poison.");
    		} else {
    			player.sendMessage("You are not poisoned.");
    		}
    	}
    
    	@Override
    	public Item[] getItemRequirements() {
    		return new Item[] {
    		  ...
    		};
    	}
    
    	@Override
    	public int getLevelRequirement() {
    		return 71;
    	}
    
    }
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    May 2014
    Posts
    57
    Thanks given
    10
    Thanks received
    21
    Rep Power
    25
    Well it's better then most I've seen out there but meh, if you don't wanna scrap it post it.
    Reply With Quote  
     

  3. #3  
    Registered Member

    Join Date
    Nov 2015
    Age
    24
    Posts
    1,980
    Thanks given
    334
    Thanks received
    1,051
    Rep Power
    5000
    Code:
    			if (player.getInventory().contains(spell.getItemRequirements())) {
    				player.sendMessage("You do not have enough runes to cast this spell.");
    				return;
    			}
    wrong if statement
    Reply With Quote  
     

  4. Thankful user:


  5. #4  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    Yeah if this was complete, it'd definitely be far better than any I've seen so far (I've only seen like 3 different approaches to this). Should add a few other things to this though, such as the delay between the usage of spells (so the players can't just spamclick it).. and possibly some other things.
    Looks good though. Most people are unfortunately dumber than a pair of socks and won't know what the hell to even do with this.
    Attached image
    Reply With Quote  
     

  6. #5  
    Registered Member
    Join Date
    Apr 2017
    Posts
    301
    Thanks given
    34
    Thanks received
    59
    Rep Power
    65
    It's a base, fairly standard however at least your effort is nice. Good job
    Reply With Quote  
     

  7. #6  
    Registered Member
    Join Date
    Dec 2013
    Posts
    419
    Thanks given
    127
    Thanks received
    85
    Rep Power
    349
    Quote Originally Posted by ashi View Post
    Well it's better then most I've seen out there but meh, if you don't wanna scrap it post it.
    Pretty much

    Quote Originally Posted by tommeh View Post
    Code:
    			if (player.getInventory().contains(spell.getItemRequirements())) {
    				player.sendMessage("You do not have enough runes to cast this spell.");
    				return;
    			}
    wrong if statement
    It's not, my contain method accepted an array.

    Quote Originally Posted by Kris View Post
    Yeah if this was complete, it'd definitely be far better than any I've seen so far (I've only seen like 3 different approaches to this). Should add a few other things to this though, such as the delay between the usage of spells (so the players can't just spamclick it).. and possibly some other things.
    Looks good though. Most people are unfortunately dumber than a pair of socks and won't know what the hell to even do with this.
    Unfortunantly people can't or won't need to do.

    Your delays etc would be done in the execute method however changing the code to use a scheduler is pretty trivial to do with the small factory.

    Quote Originally Posted by VenomRS View Post
    It's a base, fairly standard however at least your effort is nice. Good job
    Standard in what way? I could give you 10 other classes that would just require you to bind(id, spell); - I think that is pretty good. However I can already see improvements that can be made to the overall design (which you guys won't care about )
    Reply With Quote  
     

  8. #7  
    Blurite

    Corey's Avatar
    Join Date
    Feb 2012
    Age
    26
    Posts
    1,491
    Thanks given
    1,245
    Thanks received
    1,729
    Rep Power
    5000
    Quote Originally Posted by Kiissmyswagb View Post
    It's not, my contain method accepted an array.
    He meant you did the logic wrong:

    If you have all the runes to perform a spell, you're not allowed to perform the spell.

    Should be:
    Code:
    if (!player.getInventory().contains(spell.getItemRequirements())) {
    Attached image
    Reply With Quote  
     

  9. Thankful users:


  10. #8  
    Registered Member
    Join Date
    Dec 2013
    Posts
    419
    Thanks given
    127
    Thanks received
    85
    Rep Power
    349
    Quote Originally Posted by Tesla View Post
    He meant you did the logic wrong:

    If you have all the runes to perform a spell, you're not allowed to perform the spell.

    Should be:
    Code:
    if (!player.getInventory().contains(spell.getItemRequirements())) {
    Oh my bad, it was a typo.
    Reply With Quote  
     

  11. #9  
    Registered Member

    Join Date
    Nov 2014
    Posts
    253
    Thanks given
    39
    Thanks received
    146
    Rep Power
    248
    Quote Originally Posted by Kiissmyswagb View Post
    Standard in what way? I could give you 10 other classes that would just require you to bind(id, spell); - I think that is pretty good. However I can already see improvements that can be made to the overall design (which you guys won't care about )
    Because this does nothing for you? You just threw an extremely basic "factory pattern" together, a basic interface, and then released it and called it a base. Also I don't understand the inherit difference between a lunar spell book and any other spell book. Generalize it (especialyl if you insist on doing it this way).

    At least provide base classes for common spells:

    TeleportSpell(int anim, int gfx, int delay, Location loc),

    LunarTeleport(Location loc) exnds Teleport
    super(LUNAR_TELEPORT_ANIM, ..GFX, ..DELAY, loc);

    DamageSpell(int anim, int gfx, int projectileGfx, int projectileSpeed, int minDamage, int maxDamage, Type type)

    StrikeSpell(...) etends DamageSpell you get the point, you can also load a lot of data from JSON or XML instead of hard coding - at least provide a base for that.
    Code:
    enum Type {
    FIRE,
    WATER,
    ...
    ICE {
    @Override void effect(final Entity victim) {
    //freeze logic
    }
    
    //default
    void effect(final Entity victim) {
    //nothing? idk how RS works exactly
    }
    
    boolean isWeak(final Npc victim) {
    return victim.getStats().getWeakness().equals(this);
    }
    }

    Non-standard would be releasing an editor or at least using a scripting language to implement the spells (hard-coding up to n classes is idiotic).

    I don't expect you to do anything of the sort - its your choice on what you want to release, but don't act like this is a gift from god himself if you're gonna slap some shit in our faces and call it a base.
    Reply With Quote  
     

  12. Thankful user:


  13. #10  
    Registered Member

    Join Date
    Dec 2015
    Posts
    166
    Thanks given
    77
    Thanks received
    87
    Rep Power
    404
    Quote Originally Posted by Intrice Joe View Post
    ...
    not even a factory pattern because factories should gives you a type of value or instance back and this doesn't
    "It's all a matter of perspective. There is no single path in life that is right and fair and does no harm."
    Reply With Quote  
     

Page 1 of 2 12 LastLast

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. Replies: 3
    Last Post: 08-02-2013, 02:49 PM
  2. [503]Dream Lunar spell heal 20 HP[503]
    By k1ng 0f k1ngs in forum Tutorials
    Replies: 12
    Last Post: 02-13-2009, 11:11 AM
  3. My custom Lunar spells! Plus sprites
    By Jairiya in forum Tutorials
    Replies: 61
    Last Post: 07-20-2008, 10:06 PM
  4. My Lunar Spells...
    By Naughty Panda in forum RS 503+ Client & Server
    Replies: 24
    Last Post: 07-14-2008, 04:35 PM
  5. Healing Group Lunar Spell
    By Hybrid Isle in forum Tutorials
    Replies: 25
    Last Post: 05-25-2008, 04:37 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
  •