SupaLidlGame/Characters/Doc.cs

148 lines
3.6 KiB
C#
Raw Normal View History

2023-07-13 23:46:58 -07:00
using Godot;
2023-07-24 21:29:14 -07:00
using SupaLidlGame.Extensions;
2023-08-06 01:07:30 -07:00
using SupaLidlGame.BoundingBoxes;
2023-07-13 23:46:58 -07:00
namespace SupaLidlGame.Characters;
2023-07-22 20:23:48 -07:00
public partial class Doc : Boss
2023-07-13 23:46:58 -07:00
{
2023-07-22 20:23:48 -07:00
public AnimationPlayer TelegraphAnimation { get; set; }
2023-07-17 09:30:49 -07:00
2023-07-25 03:47:31 -07:00
public AnimationPlayer MiscAnimation { get; set; }
2023-07-23 23:39:20 -07:00
[Export]
public Items.Weapons.Sword Lance { get; set; }
2023-07-25 03:47:31 -07:00
[Export]
public override bool IsActive
{
get => base.IsActive;
set
{
2023-08-16 21:02:37 -07:00
// if player not alive or doesn't exist then don't activate
if (!this.GetWorld()?.CurrentPlayer?.IsAlive ?? true)
{
if (value)
{
return;
}
}
2023-07-25 03:47:31 -07:00
base.IsActive = value;
var introState = BossStateMachine
.GetNode<State.NPC.Doc.DocIntroState>("Intro");
BossStateMachine.ChangeState(introState);
2023-08-06 01:07:30 -07:00
if (IsActive)
{
var trig = GetNode<InteractionTrigger>("InteractionTrigger");
var coll = trig.GetNode<CollisionShape2D>("CollisionShape2D");
coll.Disabled = true;
}
2023-08-17 01:37:19 -07:00
else
{
Reset();
}
2023-07-25 03:47:31 -07:00
}
}
2023-07-22 20:23:48 -07:00
public override float Health
{
get => base.Health;
set
{
if (IsActive)
{
base.Health = value;
}
else
{
// play opening animation
// then become active when it finishes
base.Health = value;
}
}
}
public override int Intensity
2023-07-18 00:57:28 -07:00
{
get
{
switch (Health)
{
2023-07-24 21:29:14 -07:00
case < 300:
2023-07-18 00:57:28 -07:00
return 3;
2023-07-24 21:29:14 -07:00
case < 600:
2023-07-18 00:57:28 -07:00
return 2;
default:
return 1;
}
}
}
2023-07-22 20:23:48 -07:00
public Doc()
{
ShouldMove = false;
}
2023-07-17 09:30:49 -07:00
public override void _Ready()
{
2023-07-22 20:23:48 -07:00
TelegraphAnimation = GetNode<AnimationPlayer>("Animations/Telegraph");
2023-07-25 03:47:31 -07:00
MiscAnimation = GetNode<AnimationPlayer>("Animations/Misc");
2023-07-17 09:30:49 -07:00
base._Ready();
2023-07-23 11:05:01 -07:00
2023-07-31 01:12:47 -07:00
var dialog = GD.Load<Resource>("res://Assets/Dialogue/doc.dialogue");
2023-07-25 03:47:31 -07:00
GetNode<BoundingBoxes.InteractionTrigger>("InteractionTrigger")
.Interaction += () =>
{
//DialogueManager.ShowExampleDialogueBalloon(dialog, "duel");
2023-08-03 16:17:34 -07:00
this.GetWorld().DialogueBalloon
2023-07-25 03:47:31 -07:00
.Start(dialog, "duel");
//.Call("start", dialog, "duel");
};
GetNode<State.Global.GlobalState>("/root/GlobalState")
.SummonBoss += (string name) =>
{
if (name == "Doc")
{
IsActive = true;
Inventory.SelectedItem = Lance;
}
};
2023-07-24 21:29:14 -07:00
2023-08-16 21:02:37 -07:00
CanAttack = false;
2023-07-23 11:05:01 -07:00
// when we are hurt, start the boss fight
2023-08-07 02:38:51 -07:00
Hurt += (Events.HurtArgs args) =>
2023-07-23 11:05:01 -07:00
{
2023-08-16 21:02:37 -07:00
if (this.GetWorld().CurrentPlayer.IsAlive && !IsActive)
2023-07-23 11:05:01 -07:00
{
IsActive = true;
2023-07-23 23:39:20 -07:00
Inventory.SelectedItem = Lance;
2023-07-23 11:05:01 -07:00
}
};
2023-07-17 09:30:49 -07:00
}
2023-08-01 23:49:48 -07:00
2023-07-13 23:46:58 -07:00
public override void _Process(double delta)
{
2023-07-22 20:23:48 -07:00
if (IsActive)
{
BossStateMachine.Process(delta);
}
2023-07-13 23:46:58 -07:00
base._Process(delta);
}
2023-08-17 01:37:19 -07:00
protected override void Reset()
{
base.Reset();
GlobalPosition = Vector2.Zero;
var trig = GetNode<InteractionTrigger>("InteractionTrigger");
var coll = trig.GetNode<CollisionShape2D>("CollisionShape2D");
coll.Disabled = false;
}
2023-07-13 23:46:58 -07:00
}