Designing Structure of Spells Classes

Discussion in 'Plugin Development' started by Side8StarLite, Mar 11, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    Side8StarLite

    Hello!

    I want to make a spells plugin, where if a player right-clicks a stick, they can cycle through available spells and cast them.
    There will be a parent abstract class which holds general methods for every spell class such as cast(), getName(), etc etc... Plus, a static array which holds the names of all the Spells so that Players can see what kind of spells there are.
    But the cast() method still bothers me.
    Not concerning the nuts and blots of everything, how would I achieve the design structure of this?
    Should I create an enum class, where each Spell is an enumerated instance? Since static methods cannot be abstract, should the cast() method not be static? Should the Spells override non-static methods of the parent class instead of having static cast() methods?
    I've tried using Spell classes with non-static cast methods, and instantiating each spell into an array when the plugin is loaded. Is this a correct design? Would spells be considered "objects"?
    In short, how would I achieve a hierarchy system of this cast() method, without having to make instances of Spells?

    Hopefully that made sense. I'm trying to get back into the Java mindset, so please forgive me if I sound weird or down-right senseless.
     
  2. Offline

    Zombie_Striker

    @Side8StarLite
    For this, you either want to use a SuperClass or an Interface. Use superclasses if you want to use the same existing methods/fields for each sub-class (each individual spell). If you just want to know if each method will have a "cast" and "getName" method, but have it where no spell shares the same actual fields/code, use interfaces.
     
  3. Offline

    Side8StarLite

    Ty :)
    One more thing: if I wanted to make a list of all the spell names, should I manually make an array during compile time, or is there some way to add them automatically with a static block or something in each class?
    Thanks again in advance
     
  4. Online

    timtower Administrator Administrator Moderator

    @Side8StarLite You need to register the spells in some way, how do you want to do that?
     
  5. Offline

    Side8StarLite

    Originally I made an array of spell instances, and just called them from there. But I want to avoid doing that because spells aren't "objects", and I'd like to use a static cast() method instead. Like @Zombie_Striker said, I could use interfaces instead, but I don't know how I would register the names of the spells without making instances of Spells. Is this impossible?

    On a side note, I've been taking a look at DarkBlade12's ParticleEffect library, and he used enums for particle instances. Should I be looking into this as well?
     
  6. Online

    timtower Administrator Administrator Moderator

  7. Offline

    Side8StarLite

    If a player right clicks a stick, I'd like to do something along the lines of <spellName>.cast(), wherein spellName could be "DeathSpell", "WinterSpell", or any other kind of spell. On the other hand, if a player left clicks a stick, it cycles through available spells, and sets the "active" spell to the chosen one.
     
  8. Online

    timtower Administrator Administrator Moderator

    @Side8StarLite But how do you know which spell needs to be casted? You need some kind of check for that.
     
  9. Offline

    Side8StarLite

    "Cast" as in cast to a Spell class, or cast as in the method to activate the spell?
     
  10. Online

    timtower Administrator Administrator Moderator

    @Side8StarLite You have multiple spells.
    How do you know which spell is being used?
     
  11. Offline

    Side8StarLite

    Ooh
    I keep an array of Magician objects, which stores a Player and an int indicating which spell is "active". Whenever a Player right clicks I increment their active spell. If a Player left clicks, I get the active spell by looping through the array, and cast() a spell accordingly.
     
Thread Status:
Not open for further replies.

Share This Page