new hooks and item removing
This commit is contained in:
@@ -231,6 +231,11 @@ namespace Barotrauma
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void RemoveItem(Item item)
|
||||||
|
{
|
||||||
|
EntitySpawner.Spawner.AddToRemoveQueue(item);
|
||||||
|
}
|
||||||
|
|
||||||
public static Submarine GetRespawnSub()
|
public static Submarine GetRespawnSub()
|
||||||
{
|
{
|
||||||
return GameMain.Server.RespawnManager.RespawnShuttle;
|
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()
|
public LuaSetup()
|
||||||
{
|
{
|
||||||
PrintMessage("Lua!");
|
PrintMessage("Lua!");
|
||||||
@@ -124,6 +133,10 @@ namespace Barotrauma
|
|||||||
UserData.RegisterType<Ragdoll>();
|
UserData.RegisterType<Ragdoll>();
|
||||||
UserData.RegisterType<ChatMessage>();
|
UserData.RegisterType<ChatMessage>();
|
||||||
UserData.RegisterType<CharacterHealth.LimbHealth>();
|
UserData.RegisterType<CharacterHealth.LimbHealth>();
|
||||||
|
UserData.RegisterType<InputType>();
|
||||||
|
UserData.RegisterType<AttackResult>();
|
||||||
|
UserData.RegisterType<Entity>();
|
||||||
|
UserData.RegisterType<MapEntity>();
|
||||||
|
|
||||||
lua = new Script(CoreModules.Preset_SoftSandbox | CoreModules.LoadMethods);
|
lua = new Script(CoreModules.Preset_SoftSandbox | CoreModules.LoadMethods);
|
||||||
|
|
||||||
|
|||||||
@@ -410,7 +410,7 @@ namespace Barotrauma
|
|||||||
if (targetLimb == null)
|
if (targetLimb == null)
|
||||||
{
|
{
|
||||||
#if SERVER
|
#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())
|
if (should != null && should.CastToBool())
|
||||||
{
|
{
|
||||||
@@ -526,6 +526,15 @@ namespace Barotrauma
|
|||||||
return;
|
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)
|
foreach (Affliction newAffliction in attackResult.Afflictions)
|
||||||
{
|
{
|
||||||
if (newAffliction.Prefab.LimbSpecific)
|
if (newAffliction.Prefab.LimbSpecific)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ using System.Linq;
|
|||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Barotrauma.Extensions;
|
using Barotrauma.Extensions;
|
||||||
using Barotrauma.MapCreatures.Behavior;
|
using Barotrauma.MapCreatures.Behavior;
|
||||||
|
using MoonSharp.Interpreter;
|
||||||
|
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
@@ -2258,6 +2259,15 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
if (condition == 0.0f) { return; }
|
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;
|
bool remove = false;
|
||||||
|
|
||||||
foreach (ItemComponent ic in components)
|
foreach (ItemComponent ic in components)
|
||||||
@@ -2289,6 +2299,15 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public void ApplyTreatment(Character user, Character character, Limb targetLimb)
|
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
|
//can't apply treatment to dead characters
|
||||||
if (character.IsDead) return;
|
if (character.IsDead) return;
|
||||||
if (!UseInHealthInterface) return;
|
if (!UseInHealthInterface) return;
|
||||||
@@ -2345,6 +2364,15 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public void Drop(Character dropper, bool createNetworkEvent = true)
|
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 (createNetworkEvent)
|
||||||
{
|
{
|
||||||
if (parentInventory != null && !parentInventory.Owner.Removed && !Removed &&
|
if (parentInventory != null && !parentInventory.Owner.Removed && !Removed &&
|
||||||
@@ -2395,6 +2423,15 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public void Equip(Character character)
|
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)
|
if (Removed)
|
||||||
{
|
{
|
||||||
DebugConsole.ThrowError($"Tried to equip a removed item ({Name}).\n{Environment.StackTrace.CleanupStackTrace()}");
|
DebugConsole.ThrowError($"Tried to equip a removed item ({Name}).\n{Environment.StackTrace.CleanupStackTrace()}");
|
||||||
@@ -2406,6 +2443,15 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public void Unequip(Character character)
|
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); }
|
foreach (ItemComponent ic in components) { ic.Unequip(character); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user