quantum-space-buddies/QSB/EyeOfTheUniverse/GalaxyMap/QSBDialogueNode.cs

154 lines
3.6 KiB
C#
Raw Normal View History

2021-12-23 11:37:37 +00:00
using System.Collections.Generic;
2022-03-03 03:46:33 +00:00
namespace QSB.EyeOfTheUniverse.GalaxyMap;
2023-07-28 18:30:57 +00:00
public class QSBDialogueNode
2021-12-23 11:37:37 +00:00
{
2022-03-03 03:46:33 +00:00
private List<string> _listPagesToDisplay;
public string Name { get; set; }
public List<DialogueOption> ListDialogueOptions { get; set; }
public List<string> ListEntryCondition { get; set; }
public List<string> ConditionsToSet { get; set; }
public string PersistentConditionToSet { get; set; }
public string PersistentConditionToDisable { get; set; }
public string[] DBEntriesToSet { get; set; }
public DialogueText DisplayTextData { get; set; }
public string TargetName { get; set; }
public List<string> ListTargetCondition { get; set; }
public QSBDialogueNode Target { get; set; }
public int CurrentPage { get; private set; }
public QSBDialogueNode()
{
2022-03-03 03:46:33 +00:00
Name = "";
CurrentPage = -1;
TargetName = "";
Target = null;
ListEntryCondition = new List<string>();
_listPagesToDisplay = new List<string>();
ListTargetCondition = new List<string>();
ListDialogueOptions = new List<DialogueOption>();
ConditionsToSet = new List<string>();
PersistentConditionToSet = string.Empty;
PersistentConditionToDisable = string.Empty;
DBEntriesToSet = new string[0];
}
2021-12-23 11:37:37 +00:00
2022-03-03 03:46:33 +00:00
public void RefreshConditionsData() => _listPagesToDisplay = DisplayTextData.GetDisplayStringList();
2022-03-03 03:46:33 +00:00
public void GetNextPage(out string mainText, ref List<DialogueOption> options)
{
if (HasNext())
2021-12-23 11:37:37 +00:00
{
2022-03-03 03:46:33 +00:00
CurrentPage++;
2021-12-23 11:37:37 +00:00
}
2022-03-03 03:46:33 +00:00
mainText = _listPagesToDisplay[CurrentPage].Trim();
if (!HasNext())
2021-12-23 11:37:37 +00:00
{
for (var i = 0; i < ListDialogueOptions.Count; i++)
{
2022-03-03 03:46:33 +00:00
options.Add(ListDialogueOptions[i]);
}
2022-03-03 03:46:33 +00:00
}
}
2022-03-03 03:46:33 +00:00
public bool HasNext() => CurrentPage + 1 < _listPagesToDisplay.Count;
public string GetOptionsText(out int count)
{
var text = "";
count = 0;
for (var i = 0; i < ListDialogueOptions.Count; i++)
{
text += ListDialogueOptions[i].Text;
text += "\n";
count++;
}
2021-12-23 11:37:37 +00:00
2022-03-03 03:46:33 +00:00
return text;
}
public bool EntryConditionsSatisfied()
{
var result = true;
if (ListEntryCondition.Count == 0)
{
2022-03-03 03:46:33 +00:00
return false;
}
2022-03-03 03:46:33 +00:00
var sharedInstance = DialogueConditionManager.SharedInstance;
for (var i = 0; i < ListEntryCondition.Count; i++)
{
var text = ListEntryCondition[i];
if (sharedInstance.ConditionExists(text))
{
2022-03-03 03:46:33 +00:00
if (!sharedInstance.GetConditionState(text))
{
2022-03-03 03:46:33 +00:00
result = false;
}
2022-03-03 03:46:33 +00:00
}
else if (!PlayerData.PersistentConditionExists(text))
{
if (!PlayerData.GetPersistentCondition(text))
2021-12-23 11:37:37 +00:00
{
result = false;
}
}
2022-03-03 03:46:33 +00:00
else
{
result = false;
}
}
return result;
}
2021-12-23 11:37:37 +00:00
2022-03-03 03:46:33 +00:00
public bool TargetNodeConditionsSatisfied()
{
var result = true;
if (ListTargetCondition.Count == 0)
{
2021-12-23 11:37:37 +00:00
return result;
}
2022-03-03 03:46:33 +00:00
for (var i = 0; i < ListTargetCondition.Count; i++)
2021-12-23 11:37:37 +00:00
{
2022-03-03 03:46:33 +00:00
var id = ListTargetCondition[i];
if (!Locator.GetShipLogManager().IsFactRevealed(id))
2021-12-23 11:37:37 +00:00
{
2022-03-03 03:46:33 +00:00
result = false;
2021-12-23 11:37:37 +00:00
}
2022-03-03 03:46:33 +00:00
}
2021-12-23 11:37:37 +00:00
2022-03-03 03:46:33 +00:00
return result;
}
2021-12-23 11:37:37 +00:00
2022-03-03 03:46:33 +00:00
public void SetNodeCompleted()
{
CurrentPage = -1;
var sharedInstance = DialogueConditionManager.SharedInstance;
for (var i = 0; i < ConditionsToSet.Count; i++)
{
sharedInstance.SetConditionState(ConditionsToSet[i], true);
2021-12-23 11:37:37 +00:00
}
2022-03-03 03:46:33 +00:00
if (PersistentConditionToSet != string.Empty)
2021-12-23 11:37:37 +00:00
{
2022-03-03 03:46:33 +00:00
PlayerData.SetPersistentCondition(PersistentConditionToSet, true);
sharedInstance.SetConditionState(PersistentConditionToSet, true);
}
2021-12-23 11:37:37 +00:00
2022-03-03 03:46:33 +00:00
if (PersistentConditionToDisable != string.Empty)
{
PlayerData.SetPersistentCondition(PersistentConditionToDisable, false);
sharedInstance.SetConditionState(PersistentConditionToDisable);
}
2022-03-03 03:46:33 +00:00
for (var j = 0; j < DBEntriesToSet.Length; j++)
{
Locator.GetShipLogManager().RevealFact(DBEntriesToSet[j]);
2021-12-23 11:37:37 +00:00
}
}
}