Hi, first of all I’m probably aiming way too far for a game idea. I did successfully make what I want, but I can’t help but always think I’m doing things wrong. The main intention of posting this here is to let others comment on how I designed the whole system.
Prototype is here: http://dl.dropboxusercontent.com/u/81093784/GotGWeb.html
The game I’m making is a fully 3d shooter. It’s online, and I’ll have it read/write to external file about the player’s character like stats, skills, items(not in the game yet), etc.
Basically there are several ways to cast spells. Shot, Projectile, Cursor, Target, Self.
Shot is typical gun shot ish, sending raycast.
Projectile spawns a projectile object with velocity, and upon hitting it’ll apply damage.
Cursor means you spawn(or do the skill) where your mouse is. Say, you’re charging an AoE spell, or EarthSpike from the selected ground.
Target means it needs a target locked on(there’s a targetting system)
Self, you just hit the button and it’ll do the spell(or charge it first or something, depends).
I thought this is all I need to define how all the spells will fly around and be shot. Apparently not.
Some spells I already have:
FireBolt - Projectile. Shoots a projectile and goes boom on hit. I want the boom to do an area splash.
StormGust - Cursor to select the area. Upon releasing the cast, spawns a sphere with yet another script called FieldEffect that applies water element damage over time in that area.
EarthSpike - Also cursor, and when releasing(if mouse raycast hits ground), spawns a projectile from ground up that hits everything along its path(doesn’t go boom and disappear on first contact).
As I make the spells, the more things I have to hardcode. I don’t mind hardcoding its effects(each spell has a list of effects, on hit, applies all of them). What I’m having problem is how messy each spell acts, casting-wise and, say, how it behaves when it hits. I ended up with a lot of switch-case statements telling how each spell should act. What if I shoot a projectile spell, and it spawns 6 more projectiles on all direction when hit?
Is there a way to make a category on all of them?
Any suggestions?
I have:
-
PlayerInput class - Detects input.
-
Hotkey class - What’s currently in the hotkey. I make this because it relates to the hotkey GUI, and other things that can also be assigned to the hotkey slot. This together with PlayerInput determines what each hotkey does when pressed. (I think this is my first mistake. PlayerInput shouldn’t depend on what’s in Hotkey. PlayerInput should only care about what is pressed, and sends the event to the scripts that needs to know it, right?)
-
ActiveSkills class - It has the name, enum SpiritType element, enum CastType, and a
public static Dictionary<string, ActiveSkill> activesDB = new Dictionary<string, ActiveSkill> ();
- PlayerSkills script - One of the variable in ActiveSkills, the castType is this
public enum CastType{Shot, Projectile, Cursor, Target, Self};
This script goes to the player, it has
public List<ActiveSkill> learnedActives = new List<ActiveSkill>();
public void Shot(string sk, float charge){
// Basically the typical gun type. Sends raycast, etc. Works properly.
}
public void Projectile(string skillname, float charge){
// Instantiates, or get from pool, some sphere with velocity. The projectile has a script called projectile
}
public void Target(string skillname, GameObject target, float charge){
// Skills that need target. Directly calculates damage on the target
}
public void Self(string skillname, float charge){
// Doesn't need target. Aura spells, self buff, etc.
}
-
Projectiles script - Attached to projectiles that is shot. It contains the skill name, the charge when it is shot
Again, in here, depending on the skill of the projectile, I have to hardcode each behavior. FireBolt disappears upon hit, while the projectile for EarthSpike doesn’t(can multi hit along its path). -
Attribute class - Contains float variables like str, agi, castSpeed, movementSpeed, with appropriate get/set. For example, like so:
private float _HpRegen;
public float HpRegen{
get{ return _HpRegen + (float)(_Vit / 15); }
set{ _HpRegen = value - (float)(_Vit / 15); }
- Entity class - which has Attribute myStat = new Attribute();
This is also where most of the damage gets calculated. I’m also having a hard time figuring out how to make, say, an aura effect. Lets say it’s a burning aura effect. Does it go here, and apply damage to everything around the player, because this is also where I keep track of status effect like burn, frozen, etc?
I only started coding casually around beginning of this year. I’m aware that I’m missing a lot of basic, fundamental knowledge about coding. I’ve been reading around this skill stuff(haven’t found the one specifically related to my problem. Mostly about skill composition and effects, which I think I can figure out), and have been trying to apply using interface, but I just can’t figure out where’s a good place to do that.
For instance, I thought I could put an interface called ICast, and have each skill be categorized by their castType(so I’ll have a class called Projectile, Shot, etc, then in the skillDB.add(“FireBolt”, new Projectile(“FireBolt”, Fire, etc)). And then have all of those class implement ICast. But then I’ll need a target GameObject parameter for Target skills, vector3 for Aoe, etc, so I don’t know where the interface could come in handy.
I could clean up a bit here and there, but I really think I’m approaching this in a very amateur-ish way. I’m ready to learn something new, and possibly remake everything from scratch if only someone can point me on the right direction.
Thanks!