58 lines
1.5 KiB
C#
58 lines
1.5 KiB
C#
using Chickensoft.AutoInject;
|
|
using Chickensoft.Introspection;
|
|
using Godot;
|
|
using System;
|
|
using Zennysoft.Ma.Adapter;
|
|
using Zennysoft.Ma.Adapter.Entity;
|
|
|
|
[Meta(typeof(IAutoNode))]
|
|
public partial class SetItem : RigidBody3D
|
|
{
|
|
public override void _Notification(int what) => this.Notify(what);
|
|
|
|
[Node] public AnimationTree AnimationTree { get; set; }
|
|
|
|
[Node] public Area3D ExplosionArea { get; set; }
|
|
|
|
[Dependency] public IPlayer Player => this.DependOn<IPlayer>();
|
|
|
|
protected AnimationNodeStateMachinePlayback _stateMachine;
|
|
|
|
protected readonly string _parametersPlayback = "parameters/playback";
|
|
|
|
public void OnReady()
|
|
{
|
|
_stateMachine = (AnimationNodeStateMachinePlayback)AnimationTree.Get(_parametersPlayback);
|
|
ExplosionArea.AreaEntered += ExplosionArea_AreaEntered;
|
|
AnimationTree.AnimationFinished += AnimationTree_AnimationFinished;
|
|
}
|
|
|
|
private void AnimationTree_AnimationFinished(StringName animName)
|
|
{
|
|
if (animName == "explode")
|
|
QueueFree();
|
|
}
|
|
|
|
private void ExplosionArea_AreaEntered(Area3D area)
|
|
{
|
|
if (area.GetOwner() is ExplodableWall wall)
|
|
// door.Demolish();
|
|
if (area.GetOwner() is IEnemy enemy)
|
|
enemy.HealthComponent.Damage(10);
|
|
}
|
|
|
|
public async void Set()
|
|
{
|
|
AddCollisionExceptionWith((Node)Player);
|
|
GlobalPosition = Player.GlobalPosition + Vector3.Up;
|
|
ApplyCentralImpulse(-Player.GlobalBasis.Z.Normalized() * 5.0f);
|
|
await ToSignal(GetTree().CreateTimer(1), "timeout");
|
|
Explode();
|
|
}
|
|
|
|
public void Explode()
|
|
{
|
|
_stateMachine.Travel("timer");
|
|
}
|
|
}
|