Can you think of any way to make some changes with the Quest Machine Invector calls that could work better using Mirror??
Figured might ask if you had looked into or another person had before trying to rewrite things that may break with updates to your stuff.
For example the Invector scripts
Code: Select all
using UnityEngine;
using PixelCrushers.QuestMachine.InvectorSupport;
using Invector.vItemManager;
namespace PixelCrushers.QuestMachine
{
public class InvectorHasItemsQuestCondition : QuestCondition
{
[Tooltip("ID of item to check.")]
[SerializeField]
private int m_itemID = 0;
[Tooltip("How the player's current amount applies to the required amount.")]
[SerializeField]
private CounterValueConditionMode m_valueMode = CounterValueConditionMode.AtLeast;
[Tooltip("Required amount.")]
[SerializeField]
private QuestNumber m_requiredAmount = new QuestNumber();
[Tooltip("If assigned, keep this quest counter updated while waiting for this condition to be true. Inspect the quest's main info to view/edit counters.")]
[SerializeField]
private int m_counterIndex;
public int itemID
{
get { return m_itemID; }
set { m_itemID = value; }
}
public CounterValueConditionMode valueMode
{
get { return m_valueMode; }
set { m_valueMode = value; }
}
public QuestNumber requiredAmount
{
get { return m_requiredAmount; }
set { m_requiredAmount = value; }
}
public int counterIndex
{
get { return m_counterIndex; }
set { m_counterIndex = value; }
}
private QuestCounter counter { get; set; }
public override string GetEditorName()
{
return "Invector player has " + valueMode + " " + requiredAmount.GetValue(quest) + " of item ID " + itemID;
}
#if USE_INVECTOR_INVENTORY
public override void StartChecking(System.Action trueAction)
{
base.StartChecking(trueAction);
counter = quest.GetCounter(counterIndex);
var itemManager = QuestMachine_InvectorUtils.GetItemManager();
if (itemManager != null)
{
itemManager.onAddItem.AddListener(OnHandleItem);
itemManager.onChangeItemAmount.AddListener(OnHandleItem);
itemManager.onDestroyItem.AddListener(OnChangeItem);
itemManager.onDropItem.AddListener(OnChangeItem);
CheckItemCount();
}
}
public override void StopChecking()
{
base.StopChecking();
var itemManager = QuestMachine_InvectorUtils.GetItemManager();
if (itemManager != null)
{
itemManager.onAddItem.RemoveListener(OnHandleItem);
itemManager.onChangeItemAmount.RemoveListener(OnHandleItem);
itemManager.onDestroyItem.RemoveListener(OnChangeItem);
itemManager.onDropItem.RemoveListener(OnChangeItem);
}
}
private void OnHandleItem(vItem item)
{
CheckItemCount();
}
private void OnChangeItem(vItem item, int amount)
{
CheckItemCount();
}
public void CheckItemCount()
{
var currentAmount = QuestMachine_InvectorUtils.GetItemAmount(itemID);
if (counter != null) counter.currentValue = currentAmount;
var actualRequiredAmount = requiredAmount.GetValue(quest);
bool isRequirementMet = false;
switch (valueMode)
{
default:
case CounterValueConditionMode.AtLeast:
isRequirementMet = currentAmount >= actualRequiredAmount;
break;
case CounterValueConditionMode.AtMost:
isRequirementMet = currentAmount <= actualRequiredAmount;
break;
}
if (isRequirementMet)
{
if (QuestMachine.debug) Debug.Log("Quest Machine: InvectorHasItemsQuestCondition player has " + valueMode + " " + requiredAmount.GetValue(quest) + " of item ID " + itemID + " is true.");
StopChecking();
SetTrue();
}
}
#else
public override void StartChecking(System.Action trueAction)
{
base.StartChecking(trueAction);
Debug.LogError(GetType().Name + ": You must define the scripting symbol USE_INVECTOR_INVENTORY to use Invector inventory features in Quest Machine.");
}
#endif
}
}
Code: Select all
using UnityEngine;
namespace PixelCrushers.QuestMachine.InvectorSupport
{
public static class QuestMachine_InvectorUtils
{
public static Invector.vCharacterController.vThirdPersonController GetController()
{
return GameObject.FindObjectOfType<Invector.vCharacterController.vThirdPersonController>();
}
public static void AddHealth(int v)
{
var controller = GetController();
if (controller != null) controller.ChangeHealth(v);
}
public static void AddMaxHealth(int v)
{
var controller = GetController();
if (controller != null) controller.ChangeMaxHealth(v);
}
#if USE_INVECTOR_INVENTORY
public static Invector.vItemManager.vItemManager GetItemManager()
{
return GameObject.FindObjectOfType<Invector.vItemManager.vItemManager>();
}
public static int GetItemAmount(int itemID)
{
var itemManager = GetItemManager();
if (itemManager)
{
int total = 0;
var allItems = itemManager.GetItems(itemID);
foreach (var item in allItems)
{
if (item.id == itemID)
{
total += item.amount;
}
}
return total;
}
return 0;
}
public static void AddItem(int itemID, int amount, bool autoEquip)
{
var itemManager = GetItemManager();
if (itemManager == null || amount == 0) return;
if (amount > 0)
{
var reference = new Invector.vItemManager.ItemReference(itemID);
reference.amount = amount;
reference.autoEquip = autoEquip;
reference.addToEquipArea = autoEquip;
itemManager.AddItem(reference);
}
else
{
var allItems = itemManager.GetItems();
for (int i = allItems.Count - 1; i >= 0; i--)
{
var item = allItems[i];
if (item.id == itemID)
{
itemManager.DestroyItem(item, -amount);
}
}
}
}
#else
public static int GetItemAmount(int itemID)
{
Debug.LogError("You must define the scripting symbol USE_INVECTOR_INVENTORY to use Invector inventory features in Quest Machine.");
return 0;
}
public static void AddItem(int itemID, int amount, bool autoEquip)
{
Debug.LogError("You must define the scripting symbol USE_INVECTOR_INVENTORY to use Invector inventory features in Quest Machine.");
}
#endif
}
}