71 lines
3.4 KiB
C#
71 lines
3.4 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace Harmony.ItemActionEntryUsePatches
|
|
{
|
|
internal class ItemActionEntryUsePatches
|
|
{
|
|
|
|
[HarmonyPatch(typeof(ItemActionEntryUse))]
|
|
[HarmonyPatch("OnActivated")]
|
|
public class OnActivatedPatch
|
|
{
|
|
public static bool Prefix(ItemActionEntryUse __instance,
|
|
ItemActionEntryUse.ConsumeType ___consumeType,
|
|
int ___oldToolbeltFocusID
|
|
)
|
|
{
|
|
//Log.Out("ItemActionEntryUsePatches-OnActivated START");
|
|
|
|
if (__instance.ItemController.xui.isUsingItemActionEntryUse)
|
|
return false;
|
|
XUiC_ItemStack stackControl = (XUiC_ItemStack)__instance.ItemController;
|
|
|
|
if (!stackControl.ItemStack.itemValue.ItemClass.CanExecuteAction(0, (global::EntityAlive)__instance.ItemController.xui.playerUI.entityPlayer, stackControl.ItemStack.itemValue) || !stackControl.ItemStack.itemValue.ItemClass.CanExecuteAction(1, (global::EntityAlive)__instance.ItemController.xui.playerUI.entityPlayer, stackControl.ItemStack.itemValue))
|
|
{
|
|
string strRequirement = "";
|
|
EntityAlive player = __instance.ItemController.xui.playerUI.entityPlayer;
|
|
|
|
//Log.Out("ItemActionEntryUsePatches-OnActivated entityPlayer.name: " + player.name);
|
|
//Log.Out("ItemActionEntryUsePatches-OnActivated Item: " + stackControl.ItemStack.itemValue.ItemClass.Name);
|
|
|
|
//Log.Out("ItemActionEntryUsePatches-OnActivated CanExecuteAction: " + stackControl.ItemStack.itemValue.ItemClass.CanExecuteAction(1, (global::EntityAlive)__instance.ItemController.xui.playerUI.entityPlayer, stackControl.ItemStack.itemValue));
|
|
|
|
bool flag2 = true;
|
|
|
|
player.MinEventContext.ItemValue = stackControl.ItemStack.itemValue;
|
|
if (stackControl.ItemStack.itemValue.ItemClass.Actions[0].ExecutionRequirements != null)
|
|
{
|
|
List<IRequirement> executionRequirements2 = stackControl.ItemStack.itemValue.ItemClass.Actions[0].ExecutionRequirements;
|
|
for (int j = 0; j < executionRequirements2.Count; j++)
|
|
{
|
|
List<string> list = new List<string>();
|
|
executionRequirements2[j].GetInfoStrings(ref list);
|
|
if (list.Count > 0)
|
|
{
|
|
strRequirement = list[0];
|
|
//Log.Out("ItemActionEntryUsePatches-OnActivated strRequirement: " + strRequirement);
|
|
}
|
|
|
|
bool isValid = executionRequirements2[j].IsValid(player.MinEventContext);
|
|
|
|
if (!isValid)
|
|
{
|
|
flag2 = false;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!flag2)
|
|
{
|
|
RebirthUtilities.DisplayRequirementCaption(__instance.ItemController.xui.playerUI.entityPlayer, strRequirement);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
} |