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
@@ -231,6 +231,11 @@ namespace Barotrauma
return error;
}
public static void RemoveItem(Item item)
{
EntitySpawner.Spawner.AddToRemoveQueue(item);
}
public static Submarine GetRespawnSub()
{
return GameMain.Server.RespawnManager.RespawnShuttle;
@@ -82,6 +82,15 @@ namespace Barotrauma
}
public static DynValue CreateUserDataSafe(object o)
{
if(o == null)
return DynValue.Nil;
return UserData.Create(o);
}
public LuaSetup()
{
PrintMessage("Lua!");
@@ -124,6 +133,10 @@ namespace Barotrauma
UserData.RegisterType<Ragdoll>();
UserData.RegisterType<ChatMessage>();
UserData.RegisterType<CharacterHealth.LimbHealth>();
UserData.RegisterType<InputType>();
UserData.RegisterType<AttackResult>();
UserData.RegisterType<Entity>();
UserData.RegisterType<MapEntity>();
lua = new Script(CoreModules.Preset_SoftSandbox | CoreModules.LoadMethods);
@@ -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); }
}