137 lines
6.8 KiB
C#
137 lines
6.8 KiB
C#
using Audio;
|
|
using Platform;
|
|
|
|
namespace Harmony.BlockSecureLootPatches
|
|
{
|
|
[HarmonyPatch(typeof(BlockSecureLoot))]
|
|
[HarmonyPatch("Init")]
|
|
public class InitPatch
|
|
{
|
|
public static void Postfix(BlockSecureLoot __instance, ref BlockActivationCommand[] ___cmds)
|
|
{
|
|
Array.Resize<BlockActivationCommand>(ref ___cmds, 7);
|
|
___cmds[0] = new BlockActivationCommand("Search", "search", false, false);
|
|
___cmds[1] = new BlockActivationCommand("lock", "lock", false, false);
|
|
___cmds[2] = new BlockActivationCommand("unlock", "unlock", false, false);
|
|
___cmds[3] = new BlockActivationCommand("keypad", "keypad", false, false);
|
|
___cmds[4] = new BlockActivationCommand("pick", "unlock", false, false);
|
|
___cmds[5] = new BlockActivationCommand("trigger", "wrench", true, false);
|
|
___cmds[6] = new BlockActivationCommand("take", "hand", false, false);
|
|
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(BlockSecureLoot))]
|
|
[HarmonyPatch("HasBlockActivationCommands")]
|
|
public class HasBlockActivationCommandsPatch
|
|
{
|
|
public static void Postfix(BlockSecureLoot __instance, ref bool __result, WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, global::EntityAlive _entityFocusing)
|
|
{
|
|
__result = RebirthUtilities.CanBeLooted(_blockPos, _blockValue, _clrIdx);
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(BlockSecureLoot))]
|
|
[HarmonyPatch("GetBlockActivationCommands")]
|
|
public class GetBlockActivationCommandsPatch
|
|
{
|
|
public static void Postfix(BlockSecureLoot __instance, ref BlockActivationCommand[] __result, WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, global::EntityAlive _entityFocusing,
|
|
BlockActivationCommand[] ___cmds,
|
|
string ___lockPickItem
|
|
)
|
|
{
|
|
TileEntitySecureLootContainer tileEntityLootContainer = _world.GetTileEntity(_clrIdx, _blockPos) as TileEntitySecureLootContainer;
|
|
BlockActivationCommand[] result;
|
|
if (tileEntityLootContainer == null)
|
|
{
|
|
result = new BlockActivationCommand[0];
|
|
}
|
|
else
|
|
{
|
|
PlatformUserIdentifierAbs internalLocalUserIdentifier = PlatformManager.InternalLocalUserIdentifier;
|
|
PersistentPlayerData playerData = _world.GetGameManager().GetPersistentPlayerList().GetPlayerData(tileEntityLootContainer.GetOwner());
|
|
bool flag = tileEntityLootContainer.LocalPlayerIsOwner();
|
|
bool flag2 = !flag && (playerData != null && playerData.ACL != null) && playerData.ACL.Contains(internalLocalUserIdentifier);
|
|
___cmds[0].enabled = true;
|
|
___cmds[1].enabled = (!tileEntityLootContainer.IsLocked() && (flag || flag2));
|
|
___cmds[2].enabled = (tileEntityLootContainer.IsLocked() && flag);
|
|
___cmds[3].enabled = ((!tileEntityLootContainer.IsUserAllowed(internalLocalUserIdentifier) && tileEntityLootContainer.HasPassword() && tileEntityLootContainer.IsLocked()) || flag);
|
|
___cmds[4].enabled = (___lockPickItem != null && tileEntityLootContainer.IsLocked() && !flag);
|
|
___cmds[5].enabled = (_world.IsEditor() && !GameUtils.IsWorldEditor());
|
|
___cmds[6].enabled = tileEntityLootContainer.IsEmpty() && tileEntityLootContainer.bTouched;
|
|
|
|
//Log.Out("BlockPatches-GetBlockActivationCommands HAS TAKE DELAY");
|
|
}
|
|
|
|
__result = ___cmds;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(BlockSecureLoot))]
|
|
[HarmonyPatch("OnBlockActivated")]
|
|
[HarmonyPatch(new Type[] { typeof(string), typeof(WorldBase), typeof(int), typeof(Vector3i), typeof(BlockValue), typeof(EntityPlayerLocal) })]
|
|
public class OnBlockActivatedPatch
|
|
{
|
|
public static bool Prefix(BlockLoot __instance, ref bool __result, string _commandName, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityPlayerLocal _player)
|
|
{
|
|
if ((_commandName == "Search" || _commandName == "pick") && !RebirthUtilities.CanBeLooted(_blockPos, _blockValue, _cIdx))
|
|
{
|
|
Manager.PlayInsidePlayerHead("ui_denied");
|
|
GameManager.ShowTooltip(_player as EntityPlayerLocal, Localization.Get("ttBelongsToTrader"), string.Empty, "ui_denied", null);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public static void Postfix(BlockSecureLoot __instance, ref bool __result, string _commandName, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityPlayerLocal _player)
|
|
{
|
|
float takeDelay = RebirthVariables.takeDelay;
|
|
string replacementBlockName = "";
|
|
int numBlocks = 1;
|
|
bool isReplacementItem = false;
|
|
|
|
if (((World)_world).IsWithinTraderArea(_blockPos))
|
|
{
|
|
bool optionProtectTrader = RebirthVariables.customProtectTraderArea;
|
|
|
|
if (optionProtectTrader)
|
|
{
|
|
Manager.PlayInsidePlayerHead("ui_denied");
|
|
GameManager.ShowTooltip(_player as EntityPlayerLocal, Localization.Get("ttBelongsToTrader"), string.Empty, "ui_denied", null);
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (__instance.Properties.Contains("TakeDelay"))
|
|
{
|
|
__instance.Properties.ParseFloat("TakeDelay", ref takeDelay);
|
|
}
|
|
if (__instance.Properties.Contains("ReplacementBlockName"))
|
|
{
|
|
__instance.Properties.ParseString("ReplacementBlockName", ref replacementBlockName);
|
|
}
|
|
if (__instance.Properties.Contains("numBlocks"))
|
|
{
|
|
__instance.Properties.ParseInt("numBlocks", ref numBlocks);
|
|
}
|
|
if (__instance.Properties.Contains("isReplacementItem"))
|
|
{
|
|
__instance.Properties.ParseBool("isReplacementItem", ref isReplacementItem);
|
|
}
|
|
|
|
//Log.Out("BlockPatches-OnBlockActivated _commandName: " + _commandName);
|
|
|
|
if (_commandName == "take")
|
|
{
|
|
/*Log.Out("BlockPatches-OnBlockActivated takeDelay: " + takeDelay);
|
|
Log.Out("BlockPatches-OnBlockActivated replacementBlockName: " + replacementBlockName);
|
|
Log.Out("BlockPatches-OnBlockActivated numBlocks: " + numBlocks);
|
|
Log.Out("BlockPatches-OnBlockActivated isReplacementItem: " + isReplacementItem);*/
|
|
RebirthUtilities.TakeItemWithTimer(_world, _cIdx, _blockPos, _blockValue, _player, takeDelay, null, replacementBlockName, numBlocks, isReplacementItem);
|
|
__result = true;
|
|
}
|
|
}
|
|
}
|
|
}
|