Optimizations

This commit is contained in:
Sebastian Bularca
2026-04-20 09:51:08 +02:00
parent 2b48af8d3e
commit e7595bdc89
7 changed files with 152 additions and 48 deletions

View File

@@ -14,11 +14,19 @@ namespace Jovian.EncounterSystem {
public Dictionary<string, IEncounter> GetEncounters() => encounters;
public void RegisterEncounter(IEncounter encounter) {
encounters?.TryAdd(encounter?.EncounterDefinition?.internalId, encounter);
var id = encounter?.EncounterDefinition?.internalId;
if(string.IsNullOrEmpty(id)) {
return;
}
encounters.TryAdd(id, encounter);
}
public void UnregisterEncounter(IEncounter encounter) {
encounters.Remove(encounter.EncounterDefinition.internalId);
var id = encounter?.EncounterDefinition?.internalId;
if(string.IsNullOrEmpty(id)) {
return;
}
encounters.Remove(id);
}
public void ClearEncounters() {
@@ -26,10 +34,24 @@ namespace Jovian.EncounterSystem {
}
public void PopulateEncounters() {
foreach(var collection in encounterCollections) {
foreach(var encounter in collection.encounterTables) {
foreach(var encounterInstance in encounter.encounters) {
RegisterEncounter(encounterInstance);
if(encounterCollections == null) {
return;
}
for(int c = 0; c < encounterCollections.Length; c++) {
var collection = encounterCollections[c];
if(collection?.encounterTables == null) {
continue;
}
for(int 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++) {
RegisterEncounter(table.encounters[i]);
}
}
}