4/12
So I originally was going to have my Spell hold a 2D sprite and show that sprite when it fires.
This worked great until I realized it was only showing on the client side and not for everyone
So I started making my spell creation on the server side and have it shown to clients
Now for a few reasons, we need the ScriptableObject to hold a prefab of the spell
- One reason is because we need to show the spell’s visuals
The question then is how much data and behavior should be on the SO and on the prefab?
- We can just forget the SO and make every spell have their behavior/data on the prefab
- Not very modular and annoying when you have spells with similar effects
- For example, most spells move forward. Changing speed globally will be really annoying
- We can put the base details in the SO and have the prefab behavior only customized when it’s doing something really specific
- E.g. You have two spells, fireball and tether. They both move forward but on collision fireball deals damage and tether pulls and drains
- SO defines range, speed, etc. Then the base spell prefab will read that data and move the spell forward
- When a spell collides, it will get the customized effect from the prefab
- This is more modular and easier to maintain but would be very difficult for modders to add anything significant
The second idea is good, but I landed on using the Factory pattern
- SO has data for everything
- Basic details like range, lifespan, damage, push, etc
- It also has Triggers and Effects
- Triggers check for a particular event (e.g. x time passed, user pressed the button again, spell died)
- Events do something (e.g. turn 90 degrees, go invisible, explode)
- Upon startup, the game can read each SO and use the Factory pattern to create spell prefabs
- E.g.
- Base spells will read SO base data to know speed and so on
- Based on the triggers and effects, it can attach functionality to the prefab by adding triggers and events to its TriggerArray and EventArray
- Then it just needs to check for which trigger is activated and perform events
This is nice as it separates the compex spell details from the functionality and also lets modders create new kinds of spells by combining triggers and events (I just need to add a bunch of triggers and events).
4/13
There are more issues.