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() .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; } }