2023-07-22 20:23:48 -07:00
|
|
|
using Godot;
|
2023-08-03 16:17:34 -07:00
|
|
|
using SupaLidlGame.Extensions;
|
2023-07-22 20:23:48 -07:00
|
|
|
|
|
|
|
namespace SupaLidlGame.Characters;
|
|
|
|
|
|
|
|
public abstract partial class Boss : Enemy
|
|
|
|
{
|
|
|
|
[Export]
|
|
|
|
public State.NPC.NPCStateMachine BossStateMachine { get; set; }
|
|
|
|
|
2023-07-23 11:05:01 -07:00
|
|
|
[Export]
|
|
|
|
public string BossName { get; set; }
|
|
|
|
|
2023-07-23 23:39:20 -07:00
|
|
|
[Export]
|
|
|
|
public AudioStream Music { get; set; }
|
|
|
|
|
2023-08-07 02:38:51 -07:00
|
|
|
[Export]
|
|
|
|
public Vector2 InitialPosition { get; set; }
|
|
|
|
|
2023-07-22 20:23:48 -07:00
|
|
|
public abstract int Intensity { get; }
|
|
|
|
|
2023-07-23 11:05:01 -07:00
|
|
|
private bool _isActive;
|
2023-08-15 11:27:03 -07:00
|
|
|
private Events.EventBus _eventBus;
|
2023-07-23 11:05:01 -07:00
|
|
|
|
2023-07-22 20:23:48 -07:00
|
|
|
[Export]
|
2023-07-25 03:47:31 -07:00
|
|
|
public virtual bool IsActive
|
2023-07-23 11:05:01 -07:00
|
|
|
{
|
|
|
|
get => _isActive;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
_isActive = value;
|
|
|
|
|
|
|
|
// register or deregister ourselves when we are active/inactive
|
2023-08-15 11:27:03 -07:00
|
|
|
_eventBus.EmitSignal(
|
|
|
|
Events.EventBus.SignalName.RegisteredBoss,
|
|
|
|
_isActive ? this : null
|
|
|
|
);
|
2023-07-23 11:05:01 -07:00
|
|
|
}
|
|
|
|
}
|
2023-07-24 21:29:14 -07:00
|
|
|
|
2023-08-17 01:37:19 -07:00
|
|
|
[Export]
|
|
|
|
public float MaxHealth { get; set; }
|
|
|
|
|
2023-07-24 21:29:14 -07:00
|
|
|
public override void _Ready()
|
|
|
|
{
|
|
|
|
base._Ready();
|
2023-08-01 23:49:48 -07:00
|
|
|
|
2023-08-07 02:38:51 -07:00
|
|
|
Death += (Events.HurtArgs args) =>
|
2023-08-01 23:49:48 -07:00
|
|
|
{
|
|
|
|
UpdateBossStatus(true);
|
|
|
|
};
|
2023-08-07 02:38:51 -07:00
|
|
|
|
|
|
|
this.GetWorld().CurrentPlayer.Death += (args) =>
|
|
|
|
{
|
2023-08-17 01:37:19 -07:00
|
|
|
IsActive = false;
|
2023-08-07 02:38:51 -07:00
|
|
|
};
|
2023-08-15 11:27:03 -07:00
|
|
|
|
|
|
|
_eventBus = this.GetEventBus();
|
2023-08-01 23:49:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void UpdateBossStatus(bool status)
|
|
|
|
{
|
|
|
|
GetNode<State.Global.GlobalState>("/root/GlobalState")
|
|
|
|
.Progression.BossStatus[SceneFilePath] = status;
|
2023-07-24 21:29:14 -07:00
|
|
|
}
|
2023-08-07 02:38:51 -07:00
|
|
|
|
|
|
|
protected virtual void Reset()
|
|
|
|
{
|
|
|
|
// reset animations
|
|
|
|
foreach (var child in GetNode("Animations").GetChildren())
|
|
|
|
{
|
|
|
|
if (child is AnimationPlayer anim)
|
|
|
|
{
|
|
|
|
if (anim.HasAnimation("RESET"))
|
|
|
|
{
|
|
|
|
anim.Play("RESET");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StateMachine.ChangeState(StateMachine.InitialState);
|
|
|
|
ThinkerStateMachine.ChangeState(ThinkerStateMachine.InitialState);
|
2023-08-17 01:37:19 -07:00
|
|
|
Health = MaxHealth;
|
2023-08-07 02:38:51 -07:00
|
|
|
}
|
2023-07-22 20:23:48 -07:00
|
|
|
}
|