55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
using Godot;
|
|
using System;
|
|
using System.Linq;
|
|
using Chickensoft.AutoInject;
|
|
using Chickensoft.Introspection;
|
|
using Gamesmiths.Forge.Core;
|
|
using Gamesmiths.Forge.Cues;
|
|
using Gamesmiths.Forge.Tags;
|
|
using Movementtests.interfaces;
|
|
using Movementtests.tools;
|
|
|
|
[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_projectile.png"), Meta(typeof(IAutoNode))]
|
|
public partial class Explosion : Area3D, IProvide<CuesManager>
|
|
{
|
|
public override void _Notification(int what) => this.Notify(what);
|
|
|
|
[Dependency]
|
|
public CuesManager CuesManager => this.DependOn<CuesManager>();
|
|
CuesManager IProvide<CuesManager>.Value() => CuesManager;
|
|
|
|
[Export] public float Damage { get; set; } = 1.0f;
|
|
[Export] public float Radius { get; set; } = 1.0f;
|
|
[Export] public float ExplosionTime { get; set; } = 0.2f;
|
|
|
|
[Node("CollisionShape3D")] public required CollisionShape3D CollisionShape { get; set; }
|
|
[Node("MeshInstance3D")] public required MeshInstance3D CollisionMesh { get; set; }
|
|
[Node("ForgeEntityNode")] public required ForgeEntityNode ForgeEntityNode { get; set; }
|
|
|
|
public void OnReady()
|
|
{
|
|
if (CollisionShape.Shape is SphereShape3D sphereShape) sphereShape.Radius = Radius;
|
|
if (CollisionMesh.Mesh is not SphereMesh sphereMesh) return;
|
|
sphereMesh.Radius = Radius;
|
|
sphereMesh.Height = Radius * 2f;
|
|
}
|
|
|
|
public void OnResolved()
|
|
{
|
|
this.Provide();
|
|
GetTree().CreateTimer(ExplosionTime).Timeout += TriggerExplosion;
|
|
}
|
|
|
|
public void TriggerExplosion()
|
|
{
|
|
var bodies = GetOverlappingBodies();
|
|
foreach (var body in bodies)
|
|
{
|
|
if (body is not IForgeEntity target) continue;
|
|
foreach (var ability in ForgeEntityNode.Abilities.GrantedAbilities.Where(ability => ability.CanActivate(out _, target)))
|
|
ability.Activate(out _, target, Damage);
|
|
}
|
|
QueueFree();
|
|
}
|
|
}
|