Files
project-reset/Assets/Scripts/Units/PlayerInventory.cs
Chris 96c43c6369 feat: better state handling for combat
melee weapon now spawns in hand
melee substate cleaned up to work with above
added new playerinventory script on player
added new playeranimation script on player
changed inventory to IInventory
animations tweaked to avoid a lockout
2026-01-08 01:22:45 -05:00

76 lines
2.2 KiB
C#

using System.Collections.Generic;
using NodeCanvas.Tasks.Actions;
using Reset.Items;
using UnityEngine;
namespace Reset.Units{
public class PlayerInventory : UnitComponent, IInventory {
public Weapon rangedWeapon;
public Weapon meleeWeapon;
public Ability spellAbility1;
public Ability spellAbility2;
public Ability toolAbility1;
public Ability toolAbility2;
public List<Item> storedItems { get; set; }
private IEquipable currentWeapon;
private GameObject currentWeaponItem;
public void OnDrawWeapon(){
// Remove a current weapon
if (currentWeapon != null) {
Destroy(currentWeaponItem);
currentWeaponItem = null;
}
// Add weapon to status and hand
currentWeapon = meleeWeapon;
currentWeaponItem = meleeWeapon.PlaceInHand();
// Move item to hand
currentWeaponItem.transform.SetParent((Unit.Animation as PlayerAnimation).rightHand);
currentWeaponItem.transform.localPosition = meleeWeapon.handPositionOffset;
currentWeaponItem.transform.rotation = (Unit.Animation as PlayerAnimation).rightHand.rotation * Quaternion.Euler(meleeWeapon.handRotationOffset);
Debug.Log(currentWeapon);
//
// Unit.Graph.SendEvent("Draw Weapon");
}
public void OnHolsterWeapon(){
Destroy(currentWeaponItem);
currentWeaponItem = null;
currentWeapon = null;
Debug.Log(currentWeapon);
//
// Unit.Graph.SendEvent("Holster Weapon");
}
public void EquipToCharacter(Item item){
if (item is not IEquipable) {
Debug.LogError("This item is not equippable.", item);
return;
}
if (item is Weapon thisWeapon) {
if (meleeWeapon != null) {
storedItems.Add(meleeWeapon);
}
meleeWeapon = thisWeapon;
}
}
// Update is called once per frame
void Update(){
}
}
}