I’m trying to make abilities using ECS and I’m a bit stuck. Currently, I have a player entity with a class component that holds data for that specific class (abilities it has and stats such as walk speed and jump power)
-- Player Entity
World:spawn(
Components.Class({ -- each class (i.e: Warrior) has different stats and abilities so makes sense to include the values in one component.
walkSpeed = 25,
jumpPower = 55,
health = 100,
abilites = {
["Ability1"] = "GuardRush",
["Ability2"] = "GaleSlashes",
["Ability3"] = "EtherealWhirlwind",
},
}),
)
I then have an ability system that listens for input and makes a new entity for the ability with components for what the ability should do. So Ability1 makes you dash and gives you 10 shield.
local function AbilitySystem(world)
for id, class, input in world:query(Components.Class, Components.Input) do
for _, inputObject, gp in Matter.useEvent(UIS, "InputBegan") do
if inputObject.KeyCode == input.Keys.Ability1 then
world:spawn(
Components.Ability({owner = id}),
Components.Dash(),
Components.Shield({amount = 10})
)
end
if inputObject.KeyCode == input.Keys.Ability2 then
world:spawn(
Components.Ability({owner = id}),
Components.Damage({amount = 10})
)
end
if inputObject.KeyCode == input.Keys.Ability3 then
world:spawn(
Components.Ability({owner = id}),
Components.Dash(),
Components.Damage({amount = 10})
)
end
end
end
end
The issue is this is currently hardcoded and I need a way to store these components or even the entity somewhere so that when the input is made I can just retrieve it and then it works for any ability I add.