89 lines
2.9 KiB
C#
89 lines
2.9 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);
|
|
|
|
[Node("PlayerFellRespawn")] private Marker3D? PlayerRespawnMarker { get; set; }
|
|
private AnimationPlayer? _animationPlayer;
|
|
private Node3D? _respawnabble;
|
|
|
|
private Area3D? _playerFellPlane;
|
|
private Area3D? _deathPlane;
|
|
|
|
public required InventoryManager InventoryManager { get; set; }
|
|
InventoryManager IProvide<InventoryManager>.Value() => InventoryManager;
|
|
|
|
public void OnReady()
|
|
{
|
|
_animationPlayer = GetNode<AnimationPlayer>("AnimationPlayer");
|
|
|
|
_playerFellPlane = GetNode<Area3D>("PlayerFellTP");
|
|
_deathPlane = GetNode<Area3D>("DeathPlane");
|
|
|
|
if (PlayerRespawnMarker == null) throw new Exception("Player respawn marker is null");
|
|
if (_animationPlayer == null) throw new Exception("Animation player is null");
|
|
if (_playerFellPlane == null) throw new Exception("Player reset plane is null");
|
|
if (_deathPlane == null) throw new Exception("Enemy death plane is null");
|
|
|
|
_playerFellPlane.BodyEntered += StartResetPlayerAnimation;
|
|
_deathPlane.BodyEntered += KillEnemy;
|
|
|
|
InventoryManager = new InventoryManager();
|
|
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)
|
|
{
|
|
body.QueueFree();
|
|
return;
|
|
}
|
|
if (killable is not IHealthable healthable)
|
|
{
|
|
body.QueueFree();
|
|
return;
|
|
}
|
|
killable.Kill(healthable);
|
|
}
|
|
}
|