Custom quest condition not being checked for next quest's node.
Posted: Mon Jul 22, 2024 5:24 pm
I have a simple quest with:
1. Start node
2. Condition node
3. Success node
I have applied my custom condition to quest autostart, it works great - starts my quest and transitions to Conditon node.
Now I've applied the same condition to my condition node and it seems to never be checked as if StartChecking() is never run and the quest is stuck in condition node.
My custom condition:
1. Start node
2. Condition node
3. Success node
I have applied my custom condition to quest autostart, it works great - starts my quest and transitions to Conditon node.
Now I've applied the same condition to my condition node and it seems to never be checked as if StartChecking() is never run and the quest is stuck in condition node.
My custom condition:
Code: Select all
using System.Collections.Generic;
using PixelCrushers.QuestMachine;
using UnityEngine;
public class ItemCountQuestCondition : QuestCondition {
public ItemDescription itemType;
public CounterValueConditionMode comparison = CounterValueConditionMode.AtLeast;
public QuestNumber requiredValue = new QuestNumber();
public override string GetEditorName() {
return "Inventory has " + comparison + " " + requiredValue.GetValue(quest) + " " + itemType;
}
public override void StartChecking(System.Action trueAction) {
base.StartChecking(trueAction);
if (IsTrue()) {
SetTrue();
} else {
Inventory.ItemAdded += Inventory_OnChange;
Inventory.ItemRemoved += Inventory_OnChange;
}
}
public override void StopChecking() {
base.StopChecking();
}
private void Inventory_OnChange(Inventory i, InventoryItem item, int quantity) {
if (IsTrue()) {
SetTrue();
Debug.Log("Item count condition is true");
}
}
private bool IsTrue() {
List<Unit> playersUnits = GameActors.Instance.PlayerActor.units;
foreach (Unit unit in playersUnits) {
Inventory inventory = unit.GetInventory();
if (inventory == null) {
continue;
}
InventoryItem item = inventory.TryGetItem(itemType);
if (item == null) {
continue;
};
switch (comparison) {
case CounterValueConditionMode.AtLeast:
if (item.quantity >= requiredValue.GetValue(quest)) return true;
break;
case CounterValueConditionMode.AtMost:
if (item.quantity <= requiredValue.GetValue(quest)) return true;
break;
}
}
return false;
}
}