147 lines
4.0 KiB
C#
147 lines
4.0 KiB
C#
using Chickensoft.AutoInject;
|
|
using Chickensoft.Introspection;
|
|
using DialogueManagerRuntime;
|
|
using Godot;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Zennysoft.Game.Ma;
|
|
using Zennysoft.Ma;
|
|
using Zennysoft.Ma.Adapter;
|
|
|
|
[Meta(typeof(IAutoNode))]
|
|
public partial class Sarco : Node3D
|
|
{
|
|
public override void _Notification(int what) => this.Notify(what);
|
|
|
|
[Dependency] protected IPlayer _player => this.DependOn(() => GetParent().GetChildren().OfType<IPlayer>().Single());
|
|
|
|
[Dependency] public IGame _game => this.DependOn<IGame>();
|
|
|
|
[Dependency] private IGameRepo _gameRepo => this.DependOn<IGameRepo>();
|
|
|
|
[Export]
|
|
public ElementType Affinity { get; set; }
|
|
|
|
[Export]
|
|
public Resource Dialogue { get; set; }
|
|
|
|
[Node] public AnimationPlayer AnimationPlayer { get; set; }
|
|
|
|
[Node] public Area3D InteractZone { get; set; }
|
|
|
|
private bool _isInInteractZone = false;
|
|
|
|
private bool _interactionComplete = false;
|
|
|
|
public string AffinityString => Affinity.ToString();
|
|
|
|
public void OnReady()
|
|
{
|
|
SetPhysicsProcess(true);
|
|
InteractZone.BodyEntered += InteractZone_BodyEntered;
|
|
InteractZone.BodyExited += InteractZone_BodyExited;
|
|
}
|
|
|
|
public void OnResolved()
|
|
{
|
|
_interactionComplete = GetSaveDataByAffinity();
|
|
if (_interactionComplete)
|
|
ShowFlower();
|
|
}
|
|
|
|
public override void _Input(InputEvent @event)
|
|
{
|
|
if (Dialogue != null && @event.IsActionPressed(GameInputs.Interact) && _isInInteractZone && !_interactionComplete)
|
|
{
|
|
GetTree().Paused = true;
|
|
DialogueController.ShowDialogue(Dialogue, "general", [this]);
|
|
}
|
|
}
|
|
|
|
public async Task EquipAffinity()
|
|
{
|
|
_player.SetSigil(GetSigilByAffinity());
|
|
}
|
|
|
|
public async Task ShowFlower()
|
|
{
|
|
AnimationPlayer.Play("fade_in");
|
|
}
|
|
|
|
public async Task Finish()
|
|
{
|
|
GetTree().Paused = false;
|
|
_interactionComplete = true;
|
|
SetSaveDataByAffinity();
|
|
await _game.Save();
|
|
}
|
|
|
|
private void InteractZone_BodyEntered(Node3D body)
|
|
{
|
|
_isInInteractZone = true;
|
|
}
|
|
|
|
private void InteractZone_BodyExited(Node3D body)
|
|
{
|
|
_isInInteractZone = false;
|
|
}
|
|
|
|
private bool GetSaveDataByAffinity()
|
|
{
|
|
if (Affinity == ElementType.Aeolic)
|
|
return _game.SarcoData.AeolicSarcoAcquired;
|
|
if (Affinity == ElementType.Igneous)
|
|
return _game.SarcoData.IgneousSarcoAcquired;
|
|
if (Affinity == ElementType.Telluric)
|
|
return _game.SarcoData.TelluricSarcoAcquired;
|
|
if (Affinity == ElementType.Hydric)
|
|
return _game.SarcoData.HydricSarcoAcquired;
|
|
if (Affinity == ElementType.Ferrum)
|
|
return _game.SarcoData.FerrumSarcoAcquired;
|
|
if (Affinity == ElementType.Sankta)
|
|
return _game.SarcoData.SanktaSarcoAcquired;
|
|
if (Affinity == ElementType.Shura)
|
|
return _game.SarcoData.ShuraSarcoAcquired;
|
|
|
|
return false;
|
|
}
|
|
|
|
private void SetSaveDataByAffinity()
|
|
{
|
|
if (Affinity == ElementType.Aeolic)
|
|
_game.SarcoData.AeolicSarcoAcquired = true;
|
|
if (Affinity == ElementType.Igneous)
|
|
_game.SarcoData.IgneousSarcoAcquired = true;
|
|
if (Affinity == ElementType.Telluric)
|
|
_game.SarcoData.TelluricSarcoAcquired = true;
|
|
if (Affinity == ElementType.Hydric)
|
|
_game.SarcoData.HydricSarcoAcquired = true;
|
|
if (Affinity == ElementType.Ferrum)
|
|
_game.SarcoData.FerrumSarcoAcquired = true;
|
|
if (Affinity == ElementType.Sankta)
|
|
_game.SarcoData.SanktaSarcoAcquired = true;
|
|
if (Affinity == ElementType.Shura)
|
|
_game.SarcoData.ShuraSarcoAcquired = true;
|
|
}
|
|
|
|
private ISigil GetSigilByAffinity()
|
|
{
|
|
if (Affinity == ElementType.Aeolic)
|
|
return new AeolicSigil();
|
|
if (Affinity == ElementType.Igneous)
|
|
return new IgneousSigil();
|
|
if (Affinity == ElementType.Telluric)
|
|
return new TelluricSigil();
|
|
if (Affinity == ElementType.Hydric)
|
|
return new HydricSigil();
|
|
if (Affinity == ElementType.Ferrum)
|
|
return new FerrumSigil();
|
|
if (Affinity == ElementType.Sankta)
|
|
return new SanktaSigil();
|
|
if (Affinity == ElementType.Shura)
|
|
return new ShuraSigil();
|
|
|
|
return new NoneSigil();
|
|
}
|
|
}
|