mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:45:33 +00:00
Moved weapon equipment logic to submodule
This commit is contained in:
parent
af46098aca
commit
11a22684d4
8 changed files with 128 additions and 59 deletions
|
|
@ -62,17 +62,9 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
[ExportCategory("Particles")]
|
||||
[Export] private PackedScene _deathParticles;
|
||||
[Export] private GpuParticles2D _shieldParticles;
|
||||
public Weapon EquippedWeapon { get; set; }
|
||||
|
||||
private PlayerState _state;
|
||||
|
||||
public Array<Weapon> EquippedWeapons { get; set; } = new Array<Weapon>();
|
||||
|
||||
public int CurrentWeaponIndex { get; set; } = 0;
|
||||
|
||||
//private float _currentHealth = 0f;
|
||||
//private float _currentShield = 0f;
|
||||
|
||||
private bool _isDestroyed = false;
|
||||
|
||||
private GameManager _gameManager;
|
||||
|
|
@ -86,6 +78,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
private bool _canMove = true;
|
||||
|
||||
public Weapon EquippedWeapon => _weaponProvider.EquippedWeapon;
|
||||
|
||||
[Signal]
|
||||
public delegate void HealthChangedEventHandler(float newHealth, float maxHealth);
|
||||
|
||||
|
|
@ -121,6 +115,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
set => _lastCheckPointPosition = value;
|
||||
}
|
||||
|
||||
private PlayerWeaponProvider _weaponProvider;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
// CurrentHealth = MaxHealth;
|
||||
|
|
@ -128,6 +124,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
_state = PlayerState.Active;
|
||||
|
||||
_weaponProvider = GetNode<PlayerWeaponProvider>("WeaponProvider");
|
||||
|
||||
_animatedSprite = GetNode<AnimatedSprite2D>("./Smoothing2D/AnimatedSprite2D");
|
||||
_crosshair = GetNode<Sprite2D>("./Smoothing2D/Crosshair");
|
||||
|
||||
|
|
@ -212,17 +210,12 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
public void AddWeapon(Weapon weapon)
|
||||
{
|
||||
EquippedWeapons.Add(weapon);
|
||||
_weaponProvider.AddWeapon(weapon);
|
||||
}
|
||||
|
||||
public void EquipWeapon(string itemKey)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(itemKey)) return;
|
||||
var weapon = EquippedWeapons.FirstOrDefault(x => x.WeaponData.ItemKey == itemKey);
|
||||
|
||||
if (weapon is null) return;
|
||||
|
||||
EquipWeapon(weapon);
|
||||
_weaponProvider.EquipWeapon(itemKey);
|
||||
}
|
||||
|
||||
public void UseItem(LootItem item, int currentAmount)
|
||||
|
|
@ -264,30 +257,17 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
// Triggered by event in inventorymanager
|
||||
public void EquipWeapon(Weapon weapon)
|
||||
{
|
||||
EquippedWeapon = weapon;
|
||||
CurrentWeaponIndex = EquippedWeapons.IndexOf(weapon);
|
||||
_weaponProvider.EquipWeapon(weapon);
|
||||
}
|
||||
|
||||
public void NextWeapon()
|
||||
{
|
||||
CurrentWeaponIndex += 1;
|
||||
if (CurrentWeaponIndex > EquippedWeapons.Count - 1)
|
||||
{
|
||||
CurrentWeaponIndex = EquippedWeapons.Count - 1;
|
||||
}
|
||||
|
||||
EquipWeapon(EquippedWeapons[CurrentWeaponIndex]);
|
||||
_weaponProvider.NextWeapon();
|
||||
}
|
||||
|
||||
public void PreviousWeapon()
|
||||
{
|
||||
CurrentWeaponIndex -= 1;
|
||||
if (CurrentWeaponIndex < 0)
|
||||
{
|
||||
CurrentWeaponIndex = 0;
|
||||
}
|
||||
|
||||
EquipWeapon(EquippedWeapons[CurrentWeaponIndex]);
|
||||
_weaponProvider.PreviousWeapon();
|
||||
}
|
||||
|
||||
private void FindInteractable()
|
||||
|
|
@ -312,11 +292,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
private void HandleShoot()
|
||||
{
|
||||
if (EquippedWeapon == null) return;
|
||||
if (!Input.IsActionPressed(_shootActionName)) return;
|
||||
|
||||
EquippedWeapon.ShootDirection = this._facingDirection;
|
||||
EquippedWeapon.Shoot();
|
||||
_weaponProvider.Shoot(this._facingDirection);
|
||||
}
|
||||
|
||||
private void SetAnimation()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue