add many item and inventory related hooks

This commit is contained in:
Evil Factory
2021-10-16 17:58:24 -03:00
parent fad7d2d001
commit 3a7355ed21
3 changed files with 21 additions and 2 deletions

View File

@@ -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;

View File

@@ -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)

View File

@@ -348,6 +348,7 @@ namespace Barotrauma
UserData.RegisterType<Holdable>();
UserData.RegisterType<CustomInterface>();
UserData.RegisterType<Inventory>();
UserData.RegisterType<ItemInventory>();
UserData.RegisterType<ItemContainer>();
UserData.RegisterType<PowerContainer>();
UserData.RegisterType<Pickable>();
@@ -442,8 +443,6 @@ namespace Barotrauma
AddCallMetaMember(UserData.RegisterType<GUIListBox>());
AddCallMetaMember(UserData.RegisterType<GUIScrollBar>());
AddCallMetaMember(UserData.RegisterType<GUIDropDown>());
#endif
lua = new Script(CoreModules.Preset_SoftSandbox);