Add new resources and presenters for item pickups and effects
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using CryptonymThunder.Code.Resources;
|
||||
using GameCore.Attributes;
|
||||
using GameCore.Combat;
|
||||
using GameCore.Combat.Interfaces;
|
||||
using GameCore.ECS.Interfaces;
|
||||
using GameCore.Input;
|
||||
using GameCore.Inventory;
|
||||
@@ -62,12 +63,17 @@ public class ComponentFactory
|
||||
if (resource.WeaponData == null) return null;
|
||||
var weaponData = resource.WeaponData;
|
||||
|
||||
var fireCosts = weaponData.FireCosts
|
||||
.Select(_effectFactory.Create)
|
||||
.OfType<ICostEffect>()
|
||||
.ToList();
|
||||
var onFireEffects = weaponData.OnFireEffects.Select(_effectFactory.Create).ToList();
|
||||
var onHitEffects = weaponData.OnHitEffects.Select(_effectFactory.Create).ToList();
|
||||
|
||||
return new WeaponComponent
|
||||
{
|
||||
FireRate = resource.WeaponData.FireRate,
|
||||
FireCosts = fireCosts,
|
||||
OnFireEffects = onFireEffects,
|
||||
OnHitEffects = onHitEffects,
|
||||
};
|
||||
@@ -83,11 +89,16 @@ public class ComponentFactory
|
||||
|
||||
private PickupComponent CreatePickupComponent(PickupComponentResource resource)
|
||||
{
|
||||
var onAcquireEffects = resource.OnAcquireEffects
|
||||
.Select(_effectFactory.Create)
|
||||
.ToList();
|
||||
|
||||
return new PickupComponent
|
||||
{
|
||||
ItemId = resource.ItemId,
|
||||
Quantity = resource.Quantity,
|
||||
IsInstantUse = resource.IsInstantUse
|
||||
IsInstantUse = resource.IsInstantUse,
|
||||
OnAcquireEffects = onAcquireEffects,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ public class EffectFactory
|
||||
new BulkProjectileEffect(fire.ProjectileArchetypeId, fire.Count, fire.SpreadAngle, fire.ProjectileSpeed),
|
||||
DamageEffectResource damage => new DamageEffect(damage.Amount),
|
||||
HitscanEffectResource hitscan => new HitscanEffect(hitscan.Range),
|
||||
ConsumeAmmoCostResource consumeAmmo => new ConsumeAmmoCost(consumeAmmo.AmmoId, consumeAmmo.Amount),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(resource),
|
||||
$"Effect type {resource.GetType().Name} not recognized")
|
||||
};
|
||||
|
||||
@@ -57,6 +57,7 @@ public partial class GamePresenter : Node
|
||||
_world.RegisterSystem(new AttributeSystem());
|
||||
_world.RegisterSystem(new PickupSystem());
|
||||
_world.RegisterSystem(new InventorySystem(_world));
|
||||
_world.RegisterSystem(new ItemAcquisitionSystem(_world));
|
||||
|
||||
_world.RegisterSystem(new WeaponSystem());
|
||||
_world.RegisterSystem(new ProjectileSystem());
|
||||
@@ -75,7 +76,7 @@ public partial class GamePresenter : Node
|
||||
_presenters.Add(playerData.Entity.Id, playerData.Presenter);
|
||||
_presenterComponents.Add(playerData.Entity.Id, playerData.Components);
|
||||
}
|
||||
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
_inputService?.HandleInputEvent(@event);
|
||||
|
||||
@@ -21,6 +21,7 @@ public partial class PickupPresenter : Area3D, IEntityPresenter, IPresenterCompo
|
||||
{
|
||||
if (_presenterRegistry.TryGetEntity(body.GetInstanceId(), out var hitEntity))
|
||||
{
|
||||
GD.Print($"Collision detected between {CoreEntity.Id} and {hitEntity.Id}");
|
||||
_world.AddComponent(hitEntity, new CollisionEventComponent(CoreEntity));
|
||||
}
|
||||
}
|
||||
@@ -30,7 +31,6 @@ public partial class PickupPresenter : Area3D, IEntityPresenter, IPresenterCompo
|
||||
CoreEntity = coreEntity;
|
||||
_world = world;
|
||||
_presenterRegistry = GetNode<PresenterRegistry>("/root/PresenterRegistry");
|
||||
BodyEntered += OnBodyEnter;
|
||||
}
|
||||
|
||||
public void SyncToPresentation(float delta)
|
||||
|
||||
1
Code/Presenters/PickupPresenter.cs.uid
Normal file
1
Code/Presenters/PickupPresenter.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://ck82xby5qe680
|
||||
10
Code/Resources/Effects/ConsumeAmmoCostResource.cs
Normal file
10
Code/Resources/Effects/ConsumeAmmoCostResource.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Godot;
|
||||
|
||||
namespace CryptonymThunder.Code.Resources.Effects;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class ConsumeAmmoCostResource : EffectResource
|
||||
{
|
||||
[Export] public string AmmoId { get; set; } = "ammo_bullets";
|
||||
[Export(PropertyHint.Range, "1,100,1")] public int Amount { get; set; } = 1;
|
||||
}
|
||||
1
Code/Resources/Effects/ConsumeAmmoCostResource.cs.uid
Normal file
1
Code/Resources/Effects/ConsumeAmmoCostResource.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b6argm77cho2t
|
||||
1
Code/Resources/InventoryComponentResource.cs.uid
Normal file
1
Code/Resources/InventoryComponentResource.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dhcbayl5iwvf3
|
||||
@@ -8,4 +8,5 @@ public partial class PickupComponentResource : Resource
|
||||
[Export] public string ItemId { get; set; }
|
||||
[Export] public int Quantity { get; set; } = 1;
|
||||
[Export] public bool IsInstantUse { get; set; } = false;
|
||||
[Export] public Godot.Collections.Array<EffectResource> OnAcquireEffects { get; set; } = [];
|
||||
}
|
||||
1
Code/Resources/PickupComponentResource.cs.uid
Normal file
1
Code/Resources/PickupComponentResource.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cg8upylcrj8le
|
||||
@@ -9,6 +9,7 @@ public partial class WeaponResource : Resource
|
||||
[Export] public float FireRate { get; set; } = 1.0f;
|
||||
|
||||
[ExportGroup("Effects")]
|
||||
[Export] public Godot.Collections.Array<EffectResource> FireCosts { get; set; } = [];
|
||||
[Export] public Godot.Collections.Array<EffectResource> OnFireEffects { get; set; } = [];
|
||||
[Export] public Godot.Collections.Array<EffectResource> OnHitEffects { get; set; } = [];
|
||||
}
|
||||
Reference in New Issue
Block a user