Move files and folders to new repo format to enable multi-project format
This commit is contained in:
64
Zennysoft.Game.Ma/src/npc/Npc.cs
Normal file
64
Zennysoft.Game.Ma/src/npc/Npc.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class Npc : Node3D
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Node] public Area3D DialogueZone { get; set; } = default!;
|
||||
|
||||
[Node] public Area3D Hitbox { get; set; } = default!;
|
||||
|
||||
[Export]
|
||||
public Resource Dialogue { get; set; } = default!;
|
||||
|
||||
private bool _isInDialogueZone = false;
|
||||
private bool _isIntroductionComplete = false;
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
SetPhysicsProcess(true);
|
||||
DialogueZone.BodyEntered += DialogueZone_BodyEntered;
|
||||
DialogueZone.BodyExited += DialogueZone_BodyExited;
|
||||
Hitbox.AreaEntered += Hitbox_AreaEntered;
|
||||
|
||||
}
|
||||
|
||||
private void Hitbox_AreaEntered(Area3D area)
|
||||
{
|
||||
DialogueController.ShowDialogue(Dialogue, "hit");
|
||||
}
|
||||
|
||||
private void Hitbox_BodyEntered(Node body)
|
||||
{
|
||||
DialogueController.ShowDialogue(Dialogue, "hit");
|
||||
}
|
||||
|
||||
private void DialogueZone_BodyExited(Node3D body)
|
||||
{
|
||||
_isInDialogueZone = false;
|
||||
DialogueController.Interrupt();
|
||||
}
|
||||
|
||||
private void DialogueZone_BodyEntered(Node3D body)
|
||||
{
|
||||
_isInDialogueZone = true;
|
||||
}
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
if (@event.IsActionPressed(GameInputs.Interact) && _isInDialogueZone)
|
||||
{
|
||||
if (_isIntroductionComplete)
|
||||
DialogueController.ShowDialogue(Dialogue, "general");
|
||||
else
|
||||
{
|
||||
DialogueController.ShowDialogue(Dialogue, "introduction");
|
||||
_isIntroductionComplete = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user