clean up RemoteDialogueTrigger a bit

This commit is contained in:
JohnCorby 2022-01-25 22:58:07 -08:00
parent 87d5c26dcb
commit 2c10e12304
3 changed files with 29 additions and 40 deletions

View File

@ -6,30 +6,24 @@ namespace QSB.ConversationSync.Messages
{
internal class EnterRemoteDialogueMessage : QSBWorldObjectMessage<QSBRemoteDialogueTrigger>
{
private int ActivatedDialogueIndex;
private int ListDialoguesIndex;
private int DialogueIndex;
public EnterRemoteDialogueMessage(int activatedIndex, int listIndex)
{
ActivatedDialogueIndex = activatedIndex;
ListDialoguesIndex = listIndex;
}
public EnterRemoteDialogueMessage(int dialogueIndex)
=> DialogueIndex = dialogueIndex;
public override void Serialize(NetworkWriter writer)
{
base.Serialize(writer);
writer.Write(ActivatedDialogueIndex);
writer.Write(ListDialoguesIndex);
writer.Write(DialogueIndex);
}
public override void Deserialize(NetworkReader reader)
{
base.Deserialize(reader);
ActivatedDialogueIndex = reader.Read<int>();
ListDialoguesIndex = reader.Read<int>();
DialogueIndex = reader.Read<int>();
}
public override void OnReceiveRemote()
=> WorldObject.RemoteEnterDialogue(ActivatedDialogueIndex, ListDialoguesIndex);
=> WorldObject.RemoteEnterDialogue(DialogueIndex);
}
}

View File

@ -100,66 +100,60 @@ namespace QSB.ConversationSync.Patches
public static bool ConversationTriggeredReplacement(RemoteDialogueTrigger __instance, ref bool __result, out RemoteDialogueTrigger.RemoteDialogueCondition dialogue)
{
dialogue = default;
var maxValue = int.MaxValue;
var num = -1;
var sharedInstance = DialogueConditionManager.SharedInstance;
var dialogueIndex = -1;
for (var i = 0; i < __instance._listDialogues.Length; i++)
{
if (!__instance._activatedDialogues[i])
{
var flag = true;
var flag2 = false;
if (__instance._listDialogues[i].prereqConditions.Length == 0)
{
flag2 = true;
}
var allConditionsMet = true;
var anyConditionsMet = __instance._listDialogues[i].prereqConditions.Length == 0;
for (int j = 0; j < __instance._listDialogues[i].prereqConditions.Length; j++)
foreach (var prereqCondition in __instance._listDialogues[i].prereqConditions)
{
if (sharedInstance.GetConditionState(__instance._listDialogues[i].prereqConditions[j]))
if (DialogueConditionManager.SharedInstance.GetConditionState(prereqCondition))
{
flag2 = true;
anyConditionsMet = true;
}
else
{
flag = false;
allConditionsMet = false;
}
}
bool flag3 = false;
RemoteDialogueTrigger.MultiConditionType prereqConditionType = __instance._listDialogues[i].prereqConditionType;
var conditionsMet = false;
var prereqConditionType = __instance._listDialogues[i].prereqConditionType;
if (prereqConditionType != RemoteDialogueTrigger.MultiConditionType.OR)
{
if (prereqConditionType == RemoteDialogueTrigger.MultiConditionType.AND && flag)
if (prereqConditionType == RemoteDialogueTrigger.MultiConditionType.AND && allConditionsMet)
{
flag3 = true;
conditionsMet = true;
}
}
else if (flag2)
else if (anyConditionsMet)
{
flag3 = true;
conditionsMet = true;
}
if (flag3 && __instance._listDialogues[i].priority < maxValue)
if (conditionsMet && __instance._listDialogues[i].priority < int.MaxValue)
{
dialogue = __instance._listDialogues[i];
num = i;
dialogueIndex = i;
}
}
}
if (num == -1)
if (dialogueIndex == -1)
{
__result = false;
return false;
}
__instance._activatedDialogues[num] = true;
__instance._activatedDialogues[dialogueIndex] = true;
__result = true;
__instance.GetWorldObject<QSBRemoteDialogueTrigger>()
.SendMessage(new EnterRemoteDialogueMessage(num, __instance._listDialogues.IndexOf(dialogue)));
.SendMessage(new EnterRemoteDialogueMessage(dialogueIndex));
__result = true;
return false;
}

View File

@ -9,12 +9,13 @@ namespace QSB.ConversationSync.WorldObjects
// todo SendResyncInfo
}
public void RemoteEnterDialogue(int activatedIndex, int listIndex)
public void RemoteEnterDialogue(int dialogueIndex)
{
var dialogueCondition = AttachedObject._listDialogues[listIndex];
var dialogueCondition = AttachedObject._listDialogues[dialogueIndex];
AttachedObject._activeRemoteDialogue = dialogueCondition.dialogue;
AttachedObject._inRemoteDialogue = true;
AttachedObject._activatedDialogues[activatedIndex] = true;
AttachedObject._activatedDialogues[dialogueIndex] = true;
}
}
}