mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-08 20:25:54 +00:00
Moved events inside the player
This commit is contained in:
parent
11a22684d4
commit
7d9db8cfb6
7 changed files with 57 additions and 75 deletions
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
|
|
@ -7,6 +8,7 @@ namespace Cirno.Scripts.Components.Actors;
|
|||
|
||||
public partial class PlayerWeaponProvider : Node2D
|
||||
{
|
||||
[Export] public PackedScene WeaponTemplate { get; private set; }
|
||||
public Array<Weapon> EquippedWeapons { get; set; } = new Array<Weapon>();
|
||||
public int CurrentWeaponIndex { get; set; } = 0;
|
||||
|
||||
|
|
@ -21,6 +23,16 @@ public partial class PlayerWeaponProvider : Node2D
|
|||
public override void _Ready()
|
||||
{
|
||||
_inventoryManager = this.GetInventoryManager();
|
||||
|
||||
_inventoryManager.WeaponEquip += this.EquipWeapon;
|
||||
|
||||
_inventoryManager.ItemAdded += (LootItem item, int amount) =>
|
||||
{
|
||||
if (item.Item == ItemTypes.Weapon)
|
||||
{
|
||||
SpawnPlayerWeapon(item);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void Init(PlayerMovement parent)
|
||||
|
|
@ -81,4 +93,23 @@ public partial class PlayerWeaponProvider : Node2D
|
|||
EquippedWeapon.Shoot();
|
||||
}
|
||||
|
||||
private void SpawnPlayerWeapon(LootItem startingItem)
|
||||
{
|
||||
if (WeaponTemplate == null)
|
||||
{
|
||||
GD.Print("Could not spawn weapon because template is null");
|
||||
return;
|
||||
}
|
||||
|
||||
var weapon = this.CreateSibling<Weapon>(WeaponTemplate);
|
||||
weapon.WeaponData = startingItem.WeaponData;
|
||||
|
||||
this.AddWeapon(weapon);
|
||||
|
||||
if (this.EquippedWeapon == null)
|
||||
{
|
||||
this.EquipWeapon(weapon);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue