mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Helper methods to calculate and apply checks
This commit is contained in:
parent
678c1e13ea
commit
ad3c18517e
103
NewHorizons/Handlers/ConditionalsHandler.cs
Normal file
103
NewHorizons/Handlers/ConditionalsHandler.cs
Normal file
@ -0,0 +1,103 @@
|
||||
using NewHorizons.External.Modules.Conditionals;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NewHorizons.Handlers
|
||||
{
|
||||
public static class ConditionalsHandler
|
||||
{
|
||||
public static bool Check(ConditionalCheckConditionsInfo check)
|
||||
{
|
||||
var dcm = DialogueConditionManager.SharedInstance;
|
||||
|
||||
var passed = true;
|
||||
if (check.allConditionsSet != null && check.allConditionsSet.Length > 0)
|
||||
{
|
||||
passed = passed && check.allConditionsSet.All(c => dcm.GetConditionState(c));
|
||||
}
|
||||
if (check.anyConditionsSet != null && check.anyConditionsSet.Length > 0)
|
||||
{
|
||||
passed = passed && check.anyConditionsSet.Any(c => dcm.GetConditionState(c));
|
||||
}
|
||||
if (check.allPersistentConditionsSet != null && check.allPersistentConditionsSet.Length > 0)
|
||||
{
|
||||
passed = passed && check.allPersistentConditionsSet.All(c => PlayerData.GetPersistentCondition(c));
|
||||
}
|
||||
if (check.anyPersistentConditionsSet != null && check.anyPersistentConditionsSet.Length > 0)
|
||||
{
|
||||
passed = passed && check.anyPersistentConditionsSet.Any(c => PlayerData.GetPersistentCondition(c));
|
||||
}
|
||||
if (check.allFactsRevealed != null && check.allFactsRevealed.Length > 0)
|
||||
{
|
||||
passed = passed && check.allFactsRevealed.All(f => ShipLogHandler.KnowsFact(f));
|
||||
}
|
||||
if (check.anyFactsRevealed != null && check.anyFactsRevealed.Length > 0)
|
||||
{
|
||||
passed = passed && check.anyFactsRevealed.Any(f => ShipLogHandler.KnowsFact(f));
|
||||
}
|
||||
if (check.invert)
|
||||
{
|
||||
passed = !passed;
|
||||
}
|
||||
|
||||
return passed;
|
||||
}
|
||||
|
||||
public static void ApplyEffects(ConditionalCheckEffectsInfo effects, bool checkPassed)
|
||||
{
|
||||
if ((checkPassed || effects.reversible) && effects.setConditions != null)
|
||||
{
|
||||
foreach (var condition in effects.setConditions)
|
||||
{
|
||||
if (DialogueConditionManager.SharedInstance.GetConditionState(condition) != checkPassed)
|
||||
{
|
||||
DialogueConditionManager.SharedInstance.SetConditionState(condition, checkPassed);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((!checkPassed || effects.reversible) && effects.unsetConditions != null)
|
||||
{
|
||||
foreach (var condition in effects.unsetConditions)
|
||||
{
|
||||
if (DialogueConditionManager.SharedInstance.GetConditionState(condition) != !checkPassed)
|
||||
{
|
||||
DialogueConditionManager.SharedInstance.SetConditionState(condition, !checkPassed);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((checkPassed || effects.reversible) && effects.setPersistentConditions != null)
|
||||
{
|
||||
foreach (var condition in effects.setPersistentConditions)
|
||||
{
|
||||
if (!PlayerData.GetPersistentCondition(condition) != checkPassed)
|
||||
{
|
||||
PlayerData.SetPersistentCondition(condition, checkPassed);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((!checkPassed || effects.reversible) && effects.unsetPersistentConditions != null)
|
||||
{
|
||||
foreach (var condition in effects.unsetPersistentConditions)
|
||||
{
|
||||
if (PlayerData.GetPersistentCondition(condition) != !checkPassed)
|
||||
{
|
||||
PlayerData.SetPersistentCondition(condition, !checkPassed);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (checkPassed && effects.revealFacts != null)
|
||||
{
|
||||
foreach (var fact in effects.revealFacts)
|
||||
{
|
||||
if (!ShipLogHandler.KnowsFact(fact))
|
||||
{
|
||||
Locator.GetShipLogManager().RevealFact(fact);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user