started working inventory system
This commit is contained in:
@@ -5,11 +5,20 @@ using UnityEngine.Events;
|
||||
using EasyTalk.Controller;
|
||||
using EasyTalk.Nodes;
|
||||
|
||||
public abstract class Character : MonoBehaviour
|
||||
[RequireComponent(typeof(CharacterController))]
|
||||
public abstract class Character : MonoBehaviour, IInteractable
|
||||
{
|
||||
public enum Attitude { Friendly, Neutral, Hostile }
|
||||
public Attitude attitude = Attitude.Neutral;
|
||||
[Header("Stats")]
|
||||
public int CurHp;
|
||||
public int MaxHp;
|
||||
public int Damage;
|
||||
public int level = 1;
|
||||
public float AttackRange = 2.0f;
|
||||
public float ChaseRange = 5.0f;
|
||||
public float AttackRate = 1.0f;
|
||||
public float MoveSpeed = 5.0f;
|
||||
|
||||
[Header("Components")]
|
||||
public CharacterController Controller;
|
||||
@@ -18,16 +27,19 @@ public abstract class Character : MonoBehaviour
|
||||
public Dialogue dialogue;
|
||||
protected DialogueController dialogueController;
|
||||
public event UnityAction onTakeDamage;
|
||||
public Inventory Inventory { get { return inventory; } }
|
||||
private Inventory inventory;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
dialogueController = FindFirstObjectByType<DialogueController>();
|
||||
CurHp = MaxHp;
|
||||
// Get the Inventory component attached to this same GameObject
|
||||
inventory = GetComponent<Inventory>();
|
||||
}
|
||||
public void TakeDamage(int damageToTake)
|
||||
{
|
||||
CurHp -= damageToTake;
|
||||
|
||||
onTakeDamage?.Invoke();
|
||||
|
||||
if (CurHp <= 0)
|
||||
@@ -43,4 +55,38 @@ public abstract class Character : MonoBehaviour
|
||||
{
|
||||
target = t;
|
||||
}
|
||||
public virtual string GetInteractPrompt()
|
||||
{
|
||||
switch (attitude)
|
||||
{
|
||||
case Attitude.Friendly:
|
||||
return $"Talk to {charName}";
|
||||
case Attitude.Neutral:
|
||||
return $"Talk to {charName}";
|
||||
case Attitude.Hostile:
|
||||
return $"Attack {charName}";
|
||||
default:
|
||||
return $"Interact with {charName}";
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnInteract()
|
||||
{
|
||||
switch (attitude)
|
||||
{
|
||||
case Attitude.Friendly:
|
||||
case Attitude.Neutral:
|
||||
// Start dialogue for friendly or neutral characters
|
||||
if (dialogue != null && dialogueController != null)
|
||||
{
|
||||
dialogueController.ChangeDialogue(dialogue);
|
||||
dialogueController.PlayDialogue();
|
||||
}
|
||||
break;
|
||||
case Attitude.Hostile:
|
||||
// Interacting with a hostile character could set them as the combat target
|
||||
Player.Current.SetTarget(this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user