Files
project-reset/Assets/Scripts/Units/PlayerInventory.cs
2026-01-10 21:03:49 -05:00

84 lines
2.4 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);
//
(currentWeapon as Weapon).AddActorScript();
//
// Unit.Graph.SendEvent("Draw Weapon");
}
public GameObject GetCurrentWeaponItem(){
return currentWeaponItem;
}
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(){
}
}
}