using System;
using System.Collections.Generic;
using UnityEngine;
namespace Jovian.EncounterSystem {
///
/// A ScriptableObject asset holding a named list of encounters. Encounters inside the list are
/// authored via [SerializeReference] so different implementations
/// and payloads can coexist.
///
[CreateAssetMenu(fileName = "EncounterTable", menuName = "Jovian/Encounter System/Encounter Table", order = 1)]
public class EncounterTable : ScriptableObject {
/// Designer-facing table identifier (free-form).
public string id;
/// Ordered encounter list. Each element is a concrete whose
/// type-specific payload is carried by its (set in the inspector
/// via the SubclassSelector dropdown on ).
public List encounters;
/// Pick a uniformly random encounter, or null if the table is empty.
public IEncounter GetRandomEncounter() {
if(encounters == null || encounters.Count == 0) {
return null;
}
return encounters[UnityEngine.Random.Range(0, encounters.Count)];
}
/// Pick a uniformly random encounter whose runtime type matches ,
/// or null if none match.
/// The concrete runtime type to filter on.
public IEncounter GetRandomEncounter(Type type) {
if(encounters == null || encounters.Count == 0) {
return null;
}
var encountersOfType = encounters.FindAll(encounter => encounter.GetType() == type);
if(encountersOfType.Count > 0) {
return encountersOfType[UnityEngine.Random.Range(0, encountersOfType.Count)];
}
return null;
}
/// Pick a uniformly random encounter matching , or null
/// if no element passes. Used by integration to exclude
/// gated quest encounters from rolls.
/// Predicate applied to each encounter before rolling.
public IEncounter GetRandomEncounter(Predicate filter) {
if(encounters == null || encounters.Count == 0 || filter == null) {
return GetRandomEncounter();
}
var pool = encounters.FindAll(filter);
if(pool.Count == 0) {
return null;
}
return pool[UnityEngine.Random.Range(0, pool.Count)];
}
}
}