[Libgdx] Spell class

Hello, i would like to know how i should make the spell class? So Monsters and Players should be able to use. Asfar i have made is a effect class.

public class Effects {

    private ParticleEffect effect;
    private ParticleEffectPool effectPool;
    private Array<ParticleEffectPool.PooledEffect> effects;

    public Effects(ParticleEffect particle) {
        effect = particle;
        effect.scaleEffect(0.12f);
        effect.start();

        effectPool = new ParticleEffectPool(effect, 1, 2);
        effects = new Array<ParticleEffectPool.PooledEffect>();
    }

    public void render(SpriteBatch batch, float deltaTime) {
        // Update and draw effects:
        for (int i = effects.size - 1; i >= 0; i--) {
            ParticleEffectPool.PooledEffect effect = effects.get(i);
            effect.draw(batch, deltaTime);
            update(deltaTime);

            if (effect.isComplete()) {
                effect.free();
                effects.removeIndex(i);
            }
        }
    }
}

Are you just asking how to get both monster class and player class to use the spell class?

Yes, What would be the best way create a spell class that has variable such as What kind of particle effect, level, mana, damage, cooldown, target and etc…

Monster and Player share the Base class named Entity.

There is no best way. Do whatever makes sense to you.

What have you tried? Which approaches did you like the best? Which didn’t you like? Why did you like or dislike them?

The way i did it i added a hasmap in the entity class HashMap<String, Spell> spells; But is it even a good idea that each entity has their own hasmap with that. Or should i have a spellList with only strings in each entiyt and a global hashmap with the string, spell.

It looks like you have a setup to create a spell and draw it out.

So, when the character casts the spell, you would create a new effect.

You may want an array of available spells that a character can cast… there’s not enough info for a complete answer.

Yes that was the way i thougt about. That the spells should be globally loaded into the game and each entity should have their own unique list of which spells they can cast. Since the thougt is for example a healing spell. Almost all entity should be able to use it. So it will be overkill to deserialize same spell for all entity when they can cast exact same spell.

How would you build your spell class, for example. Since we need render and update the particles.

That depends on how you set things up.
If you start with an entity base class, you will have a spell caster class who will have a series of spells and among the actions is to create an instance of the spell that gets created when the conditions are met.

The way I would do it; first thoughts, in the entity control system if an entity has the required components to cast the spell and the command is sent, I would attach a spell component to that entity and then the spell system would take care of the spell and the render system would draw it out.

Some friendly advice: you’re overthinking things.

One of the most amazing, and frustrating, things about programming is that there is never just one way to do something. There are a million ways to do it.

That also makes it hard to answer general “how do I do this” type questions. The best thing you can do is just try something and see what you like best.

Then if you get stuck, you can post a small example class that demonstrates exactly what you’re working on, along with a more specific “I tried X, expected Y, but got Z instead” type question.

Good luck!

Thanks, You spelt it out perfectly…

I went through the same thing, asking the big questions, that would essentially be writing classes, I didn’t realize that’s what I was asking and I guess it’s the same here.

That’s why these dev forums get silent of pros… (I’m not a pro)