Files
GameJamDungeon/src/boss/Boss.cs
2024-09-30 23:35:52 -07:00

76 lines
1.8 KiB
C#

using Chickensoft.AutoInject;
using Chickensoft.GodotNodeInterfaces;
using Chickensoft.Introspection;
using Godot;
namespace GameJamDungeon
{
public interface IBoss : ICharacterBody3D
{
public AnimationTree AnimationTree { get; }
public Timer AttackTimer { get; }
public void Activate();
}
[Meta(typeof(IAutoNode))]
public partial class Boss : CharacterBody3D, IBoss, IProvide<IBossLogic>
{
public override void _Notification(int what) => this.Notify(what);
public IBossLogic BossLogic { get; set; } = default!;
IBossLogic IProvide<IBossLogic>.Value() => BossLogic;
public BossLogic.IBinding BossBinding { get; set; } = default!;
[Dependency] public IGameRepo GameRepo => this.DependOn<IGameRepo>();
[Node] public AnimationTree AnimationTree { get; set; } = default!;
[Node] public Timer AttackTimer { get; set; } = default!;
public void Setup()
{
BossLogic = new BossLogic();
BossLogic.Set(this as IBoss);
BossLogic.Set(GameRepo);
SetPhysicsProcess(false);
Hide();
}
public void OnResolved()
{
BossBinding = BossLogic.Bind();
this.Provide();
BossLogic.Start();
AttackTimer.Timeout += AttackTimer_Timeout;
}
public void Activate()
{
BossLogic.Input(new BossLogic.Input.Activate());
}
private void AttackTimer_Timeout()
{
var random = new RandomNumberGenerator();
random.Randomize();
var selection = random.RandWeighted([0.2f, 0.8f]);
if (selection == 0)
BossLogic.Input(new BossLogic.Input.SecondaryAttack());
else
BossLogic.Input(new BossLogic.Input.PrimaryAttack());
}
public void OnPhysicsProcess(double delta)
{
BossLogic.Input(new BossLogic.Input.PhysicsTick(delta));
MoveAndSlide();
}
}
}