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
This commit is contained in:
Chris
2026-01-08 01:22:45 -05:00
parent 2e28fe17cd
commit 96c43c6369
24 changed files with 362 additions and 88 deletions

View File

@@ -1,6 +1,7 @@
using System;
using Drawing;
using NodeCanvas.StateMachines;
using Reset.Units;
using UnityEngine;
namespace Reset.Items{
@@ -9,6 +10,9 @@ namespace Reset.Items{
public GameObject weaponModel;
public NodeCanvas.Framework.Graph weaponFSM;
public Vector3 handPositionOffset;
public Vector3 handRotationOffset;
void Awake(){
}
@@ -18,5 +22,9 @@ namespace Reset.Items{
Draw.ingame.Label2D(position + Vector3.up * 1.6f, "Damage goes here");
Draw.ingame.Label2D(position + Vector3.up * 1.35f, "Speed goes here");
}
public GameObject PlaceInHand(){
return GameObject.Instantiate(weaponModel);
}
}
}

View File

@@ -5,12 +5,12 @@ using UnityEngine.InputSystem;
namespace Reset.Units{
public class InteractionHandler : MonoBehaviour{
private PlayerEnvironmentManager envManager;
private Inventory inventory;
private IInventory inventory;
private EnvironmentObserver observer;
void Awake(){
envManager = GetComponent<PlayerEnvironmentManager>();
inventory = GetComponent<Inventory>();
inventory = GetComponent<IInventory>();
observer = envManager.FindObserverFromString("itemdrop");

View File

@@ -1,47 +1,13 @@
using System.Collections.Generic;
using NodeCanvas.Tasks.Actions;
using System.Collections.Generic;
using Reset.Items;
using UnityEngine;
namespace Reset.Units{
public class Inventory : MonoBehaviour{
public Weapon rangedWeapon;
public Weapon meleeWeapon;
public Ability spellAbility1;
public Ability spellAbility2;
public Ability toolAbility1;
public Ability toolAbility2;
public interface IInventory{
public List<Item> storedItems{ get; set; }
public List<Item> storedItems = new List<Item>(15);
void Start(){
}
public void AddToInventory(Item newItem){
storedItems.Add(newItem);
}
public void Equip(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(){
}
}
}
}

View File

@@ -1,2 +1,3 @@
fileFormatVersion: 2
guid: d57ab8ec1cbbdcf46813f268625d3494
fileFormatVersion: 2
guid: daf46ad8d27d4133a55f13a0c8a4efd3
timeCreated: 1767808174

View File

@@ -0,0 +1,8 @@
using UnityEngine;
namespace Reset.Units{
public class PlayerAnimation : UnitAnimation{
public Transform rightHand;
public Transform leftHand;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6974bcad59fb407296da5a7ed7f7a79c
timeCreated: 1767815017

View File

@@ -0,0 +1,75 @@
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(){
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d57ab8ec1cbbdcf46813f268625d3494

View File

@@ -31,6 +31,15 @@ namespace Reset.Units{
return _combat;
}
}
private UnitAnimation _animation;
internal UnitAnimation Animation{
get {
if (_animation == null) { _animation = GetComponent<UnitAnimation>(); }
return _animation;
}
}
// Debug and Gizmos
public NetworkVariable<FixedString64Bytes> graphStateAsString;