2025-10-04 12:25:29 +01:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.Events;
|
|
|
|
|
using EasyTalk.Controller;
|
|
|
|
|
using EasyTalk.Nodes;
|
|
|
|
|
|
2025-10-06 15:32:09 +01:00
|
|
|
[RequireComponent(typeof(CharacterController))]
|
|
|
|
|
public abstract class Character : MonoBehaviour, IInteractable
|
2025-10-04 12:25:29 +01:00
|
|
|
{
|
2025-10-06 15:32:09 +01:00
|
|
|
public enum Attitude { Friendly, Neutral, Hostile }
|
|
|
|
|
public Attitude attitude = Attitude.Neutral;
|
2025-10-04 12:25:29 +01:00
|
|
|
[Header("Stats")]
|
|
|
|
|
public int CurHp;
|
|
|
|
|
public int MaxHp;
|
2025-10-06 15:32:09 +01:00
|
|
|
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;
|
2025-10-04 12:25:29 +01:00
|
|
|
|
|
|
|
|
[Header("Components")]
|
|
|
|
|
public CharacterController Controller;
|
|
|
|
|
protected Character target;
|
|
|
|
|
public string charName = "Character";
|
|
|
|
|
public Dialogue dialogue;
|
|
|
|
|
protected DialogueController dialogueController;
|
|
|
|
|
public event UnityAction onTakeDamage;
|
2025-10-06 15:32:09 +01:00
|
|
|
public Inventory Inventory { get { return inventory; } }
|
|
|
|
|
private Inventory inventory;
|
2025-10-04 12:25:29 +01:00
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
|
{
|
|
|
|
|
dialogueController = FindFirstObjectByType<DialogueController>();
|
|
|
|
|
CurHp = MaxHp;
|
2025-10-06 15:32:09 +01:00
|
|
|
// Get the Inventory component attached to this same GameObject
|
|
|
|
|
inventory = GetComponent<Inventory>();
|
2025-10-04 12:25:29 +01:00
|
|
|
}
|
|
|
|
|
public void TakeDamage(int damageToTake)
|
|
|
|
|
{
|
|
|
|
|
CurHp -= damageToTake;
|
|
|
|
|
onTakeDamage?.Invoke();
|
|
|
|
|
|
|
|
|
|
if (CurHp <= 0)
|
|
|
|
|
Die();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Die ()
|
|
|
|
|
{
|
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetTarget (Character t)
|
|
|
|
|
{
|
|
|
|
|
target = t;
|
|
|
|
|
}
|
2025-10-06 15:32:09 +01:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-04 12:25:29 +01:00
|
|
|
}
|