new hooks and item removing

This commit is contained in:
Evil Factory
2021-08-09 23:43:38 -03:00
parent 7f0fac3553
commit 64ed424a6b
4 changed files with 74 additions and 1 deletions
@@ -410,7 +410,7 @@ namespace Barotrauma
if (targetLimb == null)
{
#if SERVER
var should = GameMain.Lua.hook.Call("afflictionApplied", new DynValue[] { UserData.Create(this), UserData.Create(affliction) });
var should = GameMain.Lua.hook.Call("afflictionApplied", new DynValue[] { LuaSetup.CreateUserDataSafe(this), LuaSetup.CreateUserDataSafe(affliction) });
if (should != null && should.CastToBool())
{
@@ -526,6 +526,15 @@ namespace Barotrauma
return;
}
#if SERVER
var should = GameMain.Lua.hook.Call("afflictionApplied", new DynValue[] { LuaSetup.CreateUserDataSafe(this), LuaSetup.CreateUserDataSafe(attackResult), LuaSetup.CreateUserDataSafe(hitLimb) });
if (should != null && should.CastToBool())
{
return;
}
#endif
foreach (Affliction newAffliction in attackResult.Afflictions)
{
if (newAffliction.Prefab.LimbSpecific)
@@ -11,6 +11,7 @@ using System.Linq;
using System.Xml.Linq;
using Barotrauma.Extensions;
using Barotrauma.MapCreatures.Behavior;
using MoonSharp.Interpreter;
#if CLIENT
using Microsoft.Xna.Framework.Graphics;
@@ -2258,6 +2259,15 @@ namespace Barotrauma
{
if (condition == 0.0f) { return; }
#if SERVER
var should = GameMain.Lua.hook.Call("itemSecondaryUse", new DynValue[] { LuaSetup.CreateUserDataSafe(this), LuaSetup.CreateUserDataSafe(character)});
if (should != null && should.CastToBool())
{
return;
}
#endif
bool remove = false;
foreach (ItemComponent ic in components)
@@ -2289,6 +2299,15 @@ namespace Barotrauma
public void ApplyTreatment(Character user, Character character, Limb targetLimb)
{
#if SERVER
var should = GameMain.Lua.hook.Call("itemApplyTreatment", new DynValue[] { LuaSetup.CreateUserDataSafe(this), LuaSetup.CreateUserDataSafe(user), LuaSetup.CreateUserDataSafe(character), LuaSetup.CreateUserDataSafe(targetLimb) });
if (should != null && should.CastToBool())
{
return;
}
#endif
//can't apply treatment to dead characters
if (character.IsDead) return;
if (!UseInHealthInterface) return;
@@ -2345,6 +2364,15 @@ namespace Barotrauma
public void Drop(Character dropper, bool createNetworkEvent = true)
{
#if SERVER
var should = GameMain.Lua.hook.Call("itemDrop", new DynValue[] { LuaSetup.CreateUserDataSafe(this), LuaSetup.CreateUserDataSafe(dropper)});
if (should != null && should.CastToBool())
{
return;
}
#endif
if (createNetworkEvent)
{
if (parentInventory != null && !parentInventory.Owner.Removed && !Removed &&
@@ -2395,6 +2423,15 @@ namespace Barotrauma
public void Equip(Character character)
{
#if SERVER
var should = GameMain.Lua.hook.Call("itemEquip", new DynValue[] { LuaSetup.CreateUserDataSafe(this), LuaSetup.CreateUserDataSafe(character)});
if (should != null && should.CastToBool())
{
return;
}
#endif
if (Removed)
{
DebugConsole.ThrowError($"Tried to equip a removed item ({Name}).\n{Environment.StackTrace.CleanupStackTrace()}");
@@ -2406,6 +2443,15 @@ namespace Barotrauma
public void Unequip(Character character)
{
#if SERVER
var should = GameMain.Lua.hook.Call("itemUnequip", new DynValue[] { LuaSetup.CreateUserDataSafe(this), LuaSetup.CreateUserDataSafe(character)});
if (should != null && should.CastToBool())
{
return;
}
#endif
foreach (ItemComponent ic in components) { ic.Unequip(character); }
}