Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion API/Configs/AbilityConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

using Interfaces;

using YamlDotNet.Serialization;

public class AbilityConfig
{
public Type[] AbilityTypes { get; set; }
public string[] AbilityTypes { get; set; }

[YamlIgnore]
public IAbility[] Abilities { get; set; }
}
}
8 changes: 7 additions & 1 deletion API/Controller/CooldownController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ public class CooldownController : MonoBehaviour

public void Init(AbilityConfig abilityConfig)
{
_abilityCooldown = abilityConfig.Abilities.ToDictionary(a => a.Name, _ => 0f);
_abilityCooldown = [];

foreach (string name in abilityConfig.AbilityTypes)
{
_abilityCooldown.Add(name, 0);
}

InvokeRepeating(nameof(UpdateCooldown), 0f, 1f);
Log.Debug($"[CooldownController] Invoke the cooldown cycle");
}
Expand Down
1 change: 0 additions & 1 deletion API/ExtendedRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public static IReadOnlyDictionary<Player, ObjectManager> Instances

public abstract AudioConfig AudioConfig { get; set; }

[YamlIgnore]
public abstract AbilityConfig AbilityConfig { get; set; }

public abstract List<EffectConfig> Effects { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion API/Interfaces/Ability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private void OnKeybindActivateAbility(ReferenceHub referenceHub, ServerSpecificS
// Check player and role
if (!Player.TryGet(referenceHub, out Player player) ||
!ExtendedRole.Instances.TryGetValue(player, out ObjectManager manager) ||
!manager.AllowedAbilities.Contains(GetType()))
!manager.AllowedAbilities.Contains(GetType().Name))
{
return;
}
Expand Down
19 changes: 16 additions & 3 deletions API/Managers/AbilityRegistrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,33 @@

public static class AbilityRegistrator
{
public static IAbility[] RegisterAbilities(Type[] abilityTypes)
public static IAbility[] RegisterAbilities(string[] abilityTypes)
{
List<IAbility> abilities = new();
foreach (Type type in abilityTypes)

foreach (string name in abilityTypes)
{
Type type = Type.GetType(name);

if (type == null)
{
Log.Error($"Type {name} not found.");
continue;
}

if (Activator.CreateInstance(type) is IAbility activator)
{
abilities.Add(activator);
activator.Register();
Log.Debug($"Register the {activator.Name} ability.");
}
else
{
Log.Debug($"Provided type {name} is not IAbility.");
}
}

return abilities.ToArray();
return [.. abilities];
}
}
}
2 changes: 1 addition & 1 deletion API/Managers/ObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public sealed class ObjectManager

public CooldownController CooldownController { get; set; }

public Type[] AllowedAbilities { get; set; }
public string[] AllowedAbilities { get; set; }

public void CreateObjects(Player player, ExtendedRole config)
{
Expand Down