I’ve created an NPCInventory script so that the NPC’s can hold items in a list. I have included the ISaveable interface so that this list of items is saved and loaded and that is working fine, however I also included the Interface IPredicateEvaluator so that I can display certain dialogues if the NPC does or does not have certain items in their list of items. The problem is the Evaluator seems to produce random results, and it is hard to debug as to why. My Evaluator is based off of the Player’s Inventory.cs and that seems to Evaluate correctly if I have a dialogue checking if a Player has a certain item in their inventory…
Here is the NPC’s Evaluator, I’m not sure where to look or how to debug this…
My only thought was perhaps the game does not have a reference for which NPC you’re referring to…
Any help would be great. thanks
public bool? Evaluate(PredicateType predicate, string[] parameters)
{
switch (predicate)
{
case PredicateType.NPCHasItem:
for (int i = 0; i < parameters.Length; i++)
{
InventoryItem itemParameter = InventoryItem.GetFromID(parameters[i]);
if (NPCHasItem(itemParameter))
{
return true;
}
}
return false;
case PredicateType.NPCHasItems: //Only works for stackable items.
InventoryItem item = InventoryItem.GetFromID(parameters[0]);
int stack = FindStack(item);
if (stack == -1) return false;
if (int.TryParse(parameters[1].ToString(), out int result))
{
return inventoryItems[stack].number >= result;
}
return false;
}
return null;
}