mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15: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
84
Scripts/Components/Actors/PlayerWeaponProvider.cs
Normal file
84
Scripts/Components/Actors/PlayerWeaponProvider.cs
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Cirno.Scripts.Components.Actors;
|
||||
|
||||
public partial class PlayerWeaponProvider : Node2D
|
||||
{
|
||||
public Array<Weapon> EquippedWeapons { get; set; } = new Array<Weapon>();
|
||||
public int CurrentWeaponIndex { get; set; } = 0;
|
||||
|
||||
private InventoryManager _inventoryManager;
|
||||
|
||||
public Weapon EquippedWeapon { get; set; }
|
||||
|
||||
//private PlayerMovement _parent;
|
||||
|
||||
//public Vector2 FacingDirection
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_inventoryManager = this.GetInventoryManager();
|
||||
}
|
||||
|
||||
public void Init(PlayerMovement parent)
|
||||
{
|
||||
//_parent = parent;
|
||||
}
|
||||
|
||||
public void AddWeapon(Weapon weapon)
|
||||
{
|
||||
EquippedWeapons.Add(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);
|
||||
}
|
||||
|
||||
// Triggered by event in inventorymanager
|
||||
public void EquipWeapon(Weapon weapon)
|
||||
{
|
||||
EquippedWeapon = weapon;
|
||||
CurrentWeaponIndex = EquippedWeapons.IndexOf(weapon);
|
||||
}
|
||||
|
||||
public void NextWeapon()
|
||||
{
|
||||
CurrentWeaponIndex += 1;
|
||||
if (CurrentWeaponIndex > EquippedWeapons.Count - 1)
|
||||
{
|
||||
CurrentWeaponIndex = EquippedWeapons.Count - 1;
|
||||
}
|
||||
|
||||
EquipWeapon(EquippedWeapons[CurrentWeaponIndex]);
|
||||
}
|
||||
|
||||
public void PreviousWeapon()
|
||||
{
|
||||
CurrentWeaponIndex -= 1;
|
||||
if (CurrentWeaponIndex < 0)
|
||||
{
|
||||
CurrentWeaponIndex = 0;
|
||||
}
|
||||
|
||||
EquipWeapon(EquippedWeapons[CurrentWeaponIndex]);
|
||||
}
|
||||
|
||||
public void Shoot(Vector2 direction)
|
||||
{
|
||||
if (EquippedWeapon == null) return;
|
||||
|
||||
|
||||
EquippedWeapon.ShootDirection = direction;
|
||||
EquippedWeapon.Shoot();
|
||||
}
|
||||
|
||||
}
|
||||
1
Scripts/Components/Actors/PlayerWeaponProvider.cs.uid
Normal file
1
Scripts/Components/Actors/PlayerWeaponProvider.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b4nixnxhj5qhw
|
||||
1
Scripts/Components/FSM/Player/Active.cs.uid
Normal file
1
Scripts/Components/FSM/Player/Active.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bl0o35xt8wxtg
|
||||
1
Scripts/Components/FSM/PlayerStateMachine.cs.uid
Normal file
1
Scripts/Components/FSM/PlayerStateMachine.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bw2hakslndaxm
|
||||
Loading…
Add table
Add a link
Reference in a new issue