Added some data

This commit is contained in:
Sebastian Bularca
2026-03-24 16:43:14 +01:00
parent 96baba24b4
commit 4a9c00212a
6 changed files with 114 additions and 25 deletions

View File

@@ -6,14 +6,14 @@ namespace Nox.Game {
public interface IPerkFactory {
IReadOnlyCollection<PerkDefinition> GetAll();
PerkDefinition GetById(string perkId);
PerkDefinition GetById(PerksIds perkId);
IReadOnlyCollection<PerkDefinition> GetPerksFor(CharacterDefinition character);
bool TryAddPerk(CharacterDefinition character, string perkId);
bool TryAddPerk(CharacterDefinition character, PerksIds perkId);
}
[Serializable]
public sealed class PerkDefinition {
public string id;
public PerksIds id;
public string name;
public ModifiersData modifiers = new ();
}
@@ -24,7 +24,7 @@ namespace Nox.Game {
}
public sealed class PerkFactory : IPerkFactory {
private readonly Dictionary<string, PerkDefinition> perkPool = new ();
private readonly Dictionary<PerksIds, PerkDefinition> perkPool = new ();
public PerkFactory(PerksRegistry perksRegistry) {
if(!perksRegistry) {
@@ -40,11 +40,7 @@ namespace Nox.Game {
return perkPool.Values.ToList();
}
public PerkDefinition GetById(string perkId) {
if(string.IsNullOrWhiteSpace(perkId)) {
return null;
}
public PerkDefinition GetById(PerksIds perkId) {
perkPool.TryGetValue(perkId, out var perk);
return perk;
}
@@ -55,15 +51,14 @@ namespace Nox.Game {
}
var ownedPerkIds = character.perksData.perks
.Where(p => p != null && !string.IsNullOrWhiteSpace(p.id))
.Select(p => p.id)
.ToHashSet();
return perkPool.Values.Where(p => !ownedPerkIds.Contains(p.id)).ToList();
}
public bool TryAddPerk(CharacterDefinition character, string perkId) {
if(character == null || string.IsNullOrWhiteSpace(perkId)) {
public bool TryAddPerk(CharacterDefinition character, PerksIds perkId) {
if(character == null) {
return false;
}
@@ -71,7 +66,7 @@ namespace Nox.Game {
return false;
}
if(!perkPool.TryGetValue(perkId, out PerkDefinition perk)) {
if(!perkPool.TryGetValue(perkId, out var perk)) {
return false;
}