mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 09:55:35 +00:00
Added weapon switching cooldown
This commit is contained in:
parent
ddadb9bd04
commit
9362f66fdf
2 changed files with 36 additions and 1 deletions
|
|
@ -12,9 +12,14 @@ public partial class PlayerWeaponProvider : Node2D
|
|||
{
|
||||
[Export] public PlayerStorageModule StorageModule { get; set; }
|
||||
[Export] public PackedScene WeaponTemplate { get; private set; }
|
||||
|
||||
[Export] public double WeaponSwitchCooldown { get; private set; } = 0.5d;
|
||||
public Array<Weapon> EquippedWeapons { get; set; } = [];
|
||||
|
||||
private int _currentWeaponIndex = 0;
|
||||
|
||||
private double _switchCooldown = 0d;
|
||||
private bool _switching = false;
|
||||
|
||||
private int CurrentWeaponIndex
|
||||
{
|
||||
|
|
@ -22,14 +27,16 @@ public partial class PlayerWeaponProvider : Node2D
|
|||
|
||||
set
|
||||
{
|
||||
if (value > EquippedWeapons.Count)
|
||||
if (value > EquippedWeapons.Count - 1)
|
||||
{
|
||||
_currentWeaponIndex = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (value < 0)
|
||||
{
|
||||
_currentWeaponIndex = EquippedWeapons.Count - 1;
|
||||
return;
|
||||
}
|
||||
|
||||
_currentWeaponIndex = value;
|
||||
|
|
@ -55,6 +62,17 @@ public partial class PlayerWeaponProvider : Node2D
|
|||
EquipStartupWeapon();
|
||||
}
|
||||
|
||||
public void Update(double delta)
|
||||
{
|
||||
if (!_switching) return;
|
||||
_switchCooldown += delta;
|
||||
if (_switchCooldown >= WeaponSwitchCooldown)
|
||||
{
|
||||
_switching = false;
|
||||
_switchCooldown = 0d;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInventoryWeaponEquipped(string itemKey)
|
||||
{
|
||||
Equip(itemKey, true);
|
||||
|
|
@ -94,9 +112,22 @@ public partial class PlayerWeaponProvider : Node2D
|
|||
// Triggered by event in inventorymanager
|
||||
private void EquipWeapon(Weapon weapon)
|
||||
{
|
||||
if (EquippedWeapon == weapon)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Need to start cooldown
|
||||
EquippedWeapon?.Hide();
|
||||
|
||||
EquippedWeapon = weapon;
|
||||
CurrentWeaponIndex = EquippedWeapons.IndexOf(weapon);
|
||||
GlobalState.Session.EquippedWeaponId = weapon.WeaponData.ItemKey;
|
||||
|
||||
EquippedWeapon.Show();
|
||||
|
||||
_switching = true;
|
||||
_switchCooldown = 0d;
|
||||
}
|
||||
|
||||
public void NextWeapon()
|
||||
|
|
@ -116,6 +147,7 @@ public partial class PlayerWeaponProvider : Node2D
|
|||
public void Shoot(Vector2 direction)
|
||||
{
|
||||
if (EquippedWeapon == null) return;
|
||||
if (_switching) return;
|
||||
|
||||
EquippedWeapon.ShootDirection = direction;
|
||||
EquippedWeapon.Shoot();
|
||||
|
|
|
|||
|
|
@ -166,6 +166,9 @@ public partial class Active : PlayerStateBase
|
|||
_animationProvider.SetAnimationSpeed(MainObject.Velocity);
|
||||
_animationProvider.SetAnimation(FacingDirection);
|
||||
|
||||
HandleWeaponSwitch();
|
||||
_weaponProvider.Update(delta);
|
||||
|
||||
//_crosshairProvider.UpdatePosition(FacingDirection);
|
||||
|
||||
HandleShoot();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue