33 lines
1.2 KiB
C#
33 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
|
|
public class RoundsInInventory : RequirementBase
|
|
{
|
|
private static Dictionary<string, ItemValue> cached = new Dictionary<string, ItemValue>();
|
|
|
|
public static bool TryGetValue(string ammoName, out ItemValue ammoValue)
|
|
{
|
|
if (!cached.TryGetValue(ammoName, out ammoValue))
|
|
{
|
|
ammoValue = ItemClass.GetItem(ammoName, false);
|
|
if (ammoValue == null)
|
|
return false;
|
|
cached.Add(ammoName, ammoValue);
|
|
}
|
|
return true;
|
|
}
|
|
public override bool IsValid(MinEventParams _params)
|
|
{
|
|
if (!this.ParamsValid(_params))
|
|
return invert;
|
|
|
|
ItemValue itemValue = _params.ItemValue;
|
|
if (itemValue.IsEmpty() || !(_params.ItemActionData is ItemActionRanged.ItemActionDataRanged _rangedData))
|
|
return invert;
|
|
|
|
string ammoName = ((ItemActionRanged)itemValue.ItemClass.Actions[_rangedData.indexInEntityOfAction]).MagazineItemNames[itemValue.SelectedAmmoTypeIndex];
|
|
if (TryGetValue(ammoName, out var ammoValue))
|
|
return compareValues(_params.Self.GetItemCount(ammoValue), this.operation, this.value) ^ invert;
|
|
return invert;
|
|
}
|
|
}
|