Add weapon database and equipment component resources with associated services

This commit is contained in:
2025-10-29 01:26:45 +01:00
parent 87169b17ae
commit 626f81cd85
16 changed files with 245 additions and 11 deletions

View File

@@ -0,0 +1,55 @@
using System.Linq;
using CryptonymThunder.Code.Factories;
using CryptonymThunder.Code.Resources;
using GameCore.Combat;
using GameCore.Combat.Interfaces;
using Godot;
namespace CryptonymThunder.Code.Services;
public class GodotWeaponDataService : IWeaponDataService
{
private readonly WeaponDatabase _database;
private readonly EffectFactory _effectFactory;
public GodotWeaponDataService(WeaponDatabase database, EffectFactory effectFactory)
{
_database = database;
_effectFactory = effectFactory;
}
public WeaponData GetWeaponData(string weaponId)
{
if (!_database.WeaponData.TryGetValue(weaponId, out var weaponResource))
{
GD.PrintErr($"Weapon ID not found in database: {weaponId}");
return null;
}
var fireCosts = weaponResource.FireCosts
.Select(_effectFactory.Create)
.OfType<ICostEffect>()
.ToList();
var onFireEffects = weaponResource.OnFireEffects
.Select(_effectFactory.Create)
.ToList();
var onHitEffects = weaponResource.OnHitEffects
.Select(_effectFactory.Create)
.ToList();
return new WeaponData(
weaponResource.FireRate,
fireCosts,
onFireEffects,
onHitEffects
);
}
public bool TryGetWeaponData(string weaponId, out WeaponData weaponData)
{
weaponData = GetWeaponData(weaponId);
return weaponData != null;
}
}