88 lines
2.7 KiB
C#
88 lines
2.7 KiB
C#
using Godot;
|
|
using System;
|
|
using Chickensoft.AutoInject;
|
|
using Chickensoft.Introspection;
|
|
using Movementtests.interfaces;using Movementtests.managers;
|
|
using Movementtests.systems;
|
|
|
|
[Meta(
|
|
typeof(IAutoOn),
|
|
typeof(IAutoConnect),
|
|
typeof(IProvider)
|
|
)]
|
|
public partial class MainSceneTemplate : Node3D, IProvide<InventoryManager>
|
|
{
|
|
public override void _Notification(int what) => this.Notify(what);
|
|
|
|
#region Nodes
|
|
|
|
[Node("PlayerFellRespawn")] public required Marker3D PlayerRespawnMarker { get; set; }
|
|
[Node("AnimationPlayer")] public required AnimationPlayer AnimationPlayer { get; set; }
|
|
[Node("PlayerFellTP")] public required Area3D PlayerFellPlane { get; set; }
|
|
[Node("DeathPlane")] public required Area3D DeathPlane { get; set; }
|
|
|
|
#endregion
|
|
|
|
private Node3D? Respawnabble { get; set; }
|
|
|
|
#region Exports
|
|
|
|
[Export] public WeaponInventory? InitialWeaponInventory { get; set; }
|
|
|
|
#endregion
|
|
|
|
public required InventoryManager InventoryManager { get; set; }
|
|
InventoryManager IProvide<InventoryManager>.Value() => InventoryManager;
|
|
|
|
public void OnReady()
|
|
{
|
|
PlayerFellPlane.BodyEntered += StartResetPlayerAnimation;
|
|
DeathPlane.BodyEntered += KillEnemy;
|
|
|
|
InventoryManager = new InventoryManager();
|
|
if (InitialWeaponInventory != null)
|
|
InventoryManager.InitializeFromResource(InitialWeaponInventory);
|
|
|
|
AddChild(InventoryManager);
|
|
this.Provide();
|
|
}
|
|
|
|
public void OnProvided()
|
|
{
|
|
// You can optionally implement this method. It gets called once you call
|
|
// this.Provide() to inform AutoInject that the provided values are now
|
|
// available.
|
|
}
|
|
|
|
public void ResetPlayerPosition()
|
|
{
|
|
if (Respawnabble == null || PlayerRespawnMarker == null) throw new Exception("Player or respawn marker is null");
|
|
Respawnabble.GlobalPosition = PlayerRespawnMarker.GlobalPosition;
|
|
}
|
|
|
|
public void StartResetPlayerAnimation(Node3D body)
|
|
{
|
|
if (body is WeaponSystem weapon)
|
|
{
|
|
if (PlayerRespawnMarker == null) throw new Exception("Respawn marker is null");
|
|
weapon.GlobalPosition = PlayerRespawnMarker.GlobalPosition;
|
|
weapon.SetLinearVelocity(Vector3.Down);
|
|
return;
|
|
}
|
|
Respawnabble = body as PlayerController;
|
|
if (Respawnabble == null || AnimationPlayer == null) throw new Exception("Player or anim player is null");
|
|
AnimationPlayer.Play("player_fell");
|
|
}
|
|
|
|
public void KillEnemy(Node3D body)
|
|
{
|
|
if (body is not (IKillable killable and IHealthable healthable))
|
|
{
|
|
body.QueueFree();
|
|
return;
|
|
}
|
|
|
|
killable.Kill(healthable);
|
|
}
|
|
}
|