Fxed an issue with random encounters, added a repeatable property, add event for abandoning encounters

This commit is contained in:
Sebastian Bularca
2026-05-22 13:53:00 +02:00
parent d14c5cdc2d
commit 0902836a61
6 changed files with 51 additions and 23 deletions

View File

@@ -11,7 +11,9 @@ namespace Jovian.EncounterSystem {
private readonly Dictionary<string, IEncounter> encounters = new();
public Dictionary<string, IEncounter> GetEncounters() => encounters;
public Dictionary<string, IEncounter> GetEncounters() {
return encounters;
}
public void RegisterEncounter(IEncounter encounter) {
var id = encounter?.EncounterDefinition?.internalId;
@@ -38,19 +40,19 @@ namespace Jovian.EncounterSystem {
return;
}
for(int c = 0; c < encounterCollections.Length; c++) {
for(var c = 0; c < encounterCollections.Length; c++) {
var collection = encounterCollections[c];
if(collection?.encounterTables == null) {
continue;
}
for(int t = 0; t < collection.encounterTables.Length; t++) {
for(var t = 0; t < collection.encounterTables.Length; t++) {
var table = collection.encounterTables[t];
if(table?.encounters == null) {
continue;
}
for(int i = 0; i < table.encounters.Count; i++) {
for(var i = 0; i < table.encounters.Count; i++) {
RegisterEncounter(table.encounters[i]);
}
}
@@ -67,12 +69,12 @@ namespace Jovian.EncounterSystem {
return null;
}
public IEncounter GetRandomEncounter(string encounterTableId) {
var table = GetEncounterTable(encounterTableId);
if(!table) {
return null;
}
var ec = table.encounters;
public IEncounter GetRandomEncounter(string encounterTableId) {
var table = GetEncounterTable(encounterTableId);
if(!table) {
return null;
}
var ec = table.encounters;
return ec[UnityEngine.Random.Range(0, ec.Count)];
}
@@ -86,7 +88,7 @@ namespace Jovian.EncounterSystem {
IEncounter selected = null;
var seen = 0;
for(var i = 0; i < encounters.Count; i++) {
for(var i = 0; i < table.encounters.Count; i++) {
var encounter = table.encounters[i];
if(encounter == null || encounter.GetType() != encounterKind.GetType()) {
continue;