From 3a7355ed21bbd4f32070b87a4e32a7f5cb50b572 Mon Sep 17 00:00:00 2001 From: Evil Factory <36804725+evilfactory@users.noreply.github.com> Date: Sat, 16 Oct 2021 17:58:24 -0300 Subject: [PATCH] add many item and inventory related hooks --- .../BarotraumaShared/SharedSource/Items/Inventory.cs | 10 ++++++++++ Barotrauma/BarotraumaShared/SharedSource/Items/Item.cs | 10 ++++++++++ .../BarotraumaShared/SharedSource/Lua/LuaSetup.cs | 3 +-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Barotrauma/BarotraumaShared/SharedSource/Items/Inventory.cs b/Barotrauma/BarotraumaShared/SharedSource/Items/Inventory.cs index a259d4246..3602260ca 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Items/Inventory.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Items/Inventory.cs @@ -523,6 +523,11 @@ namespace Barotrauma return; } + var should = new LuaResult(GameMain.Lua.hook.Call("inventoryPutItem", new object[] { this, item, user, i, removeItem })); + + if (should.Bool()) + return; + if (Owner == null) { return; } Inventory prevInventory = item.ParentInventory; @@ -624,6 +629,11 @@ namespace Barotrauma { if (item?.ParentInventory == null || !slots[index].Any()) { return false; } + var should = new LuaResult(GameMain.Lua.hook.Call("inventoryItemSwap", new object[] { this, item, user, index, swapWholeStack })); + + if (!should.IsNull()) + return should.Bool(); + //swap to InvSlotType.Any if possible Inventory otherInventory = item.ParentInventory; bool otherIsEquipped = false; diff --git a/Barotrauma/BarotraumaShared/SharedSource/Items/Item.cs b/Barotrauma/BarotraumaShared/SharedSource/Items/Item.cs index 5b776d411..2d6a462eb 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Items/Item.cs @@ -2089,6 +2089,11 @@ namespace Barotrauma public bool TryInteract(Character picker, bool ignoreRequiredItems = false, bool forceSelectKey = false, bool forceActionKey = false) { + var should = new LuaResult(GameMain.Lua.hook.Call("itemInteract", new object[] { this, picker, ignoreRequiredItems, forceSelectKey, forceActionKey })); + + if (!should.IsNull()) + return should.Bool(); + if (CampaignInteractionType != CampaignMode.InteractionType.None) { return false; } bool picked = false, selected = false; @@ -2349,6 +2354,11 @@ namespace Barotrauma public bool Combine(Item item, Character user) { + var should = new LuaResult(GameMain.Lua.hook.Call("itemCombine", new object[] { this, item, user })); + + if (!should.IsNull()) + return should.Bool(); + if (item == this) { return false; } bool isCombined = false; foreach (ItemComponent ic in components) diff --git a/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaSetup.cs b/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaSetup.cs index 2ae5c1568..a3206369b 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaSetup.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaSetup.cs @@ -348,6 +348,7 @@ namespace Barotrauma UserData.RegisterType(); UserData.RegisterType(); UserData.RegisterType(); + UserData.RegisterType(); UserData.RegisterType(); UserData.RegisterType(); UserData.RegisterType(); @@ -442,8 +443,6 @@ namespace Barotrauma AddCallMetaMember(UserData.RegisterType()); AddCallMetaMember(UserData.RegisterType()); AddCallMetaMember(UserData.RegisterType()); - - #endif lua = new Script(CoreModules.Preset_SoftSandbox);