refactor hooks with new LuaResult
This commit is contained in:
@@ -117,19 +117,13 @@ namespace Barotrauma.Networking
|
||||
return;
|
||||
}
|
||||
|
||||
var should = GameMain.Lua.hook.Call("chatMessage", new object[] { txt, c, type });
|
||||
var should = new LuaResult(GameMain.Lua.hook.Call("chatMessage", new object[] { txt, c, type }));
|
||||
|
||||
|
||||
if(should != null)
|
||||
{
|
||||
if (should is DynValue dyn)
|
||||
{
|
||||
if (dyn.CastToBool())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (should.Bool())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == ChatMessageType.Order)
|
||||
{
|
||||
|
||||
@@ -3112,18 +3112,11 @@ namespace Barotrauma.Networking
|
||||
|
||||
var hookChatMsg = ChatMessage.Create(senderName, message, (ChatMessageType)type, senderCharacter, senderClient, changeType);
|
||||
|
||||
var should = GameMain.Lua.hook.Call("modifyChatMessage", new object[] { hookChatMsg, senderRadio });
|
||||
var should = new LuaResult(GameMain.Lua.hook.Call("modifyChatMessage", new object[] { hookChatMsg, senderRadio }));
|
||||
|
||||
if (should != null)
|
||||
{
|
||||
if (should is DynValue dyn)
|
||||
{
|
||||
if (dyn.CastToBool())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (should.Bool())
|
||||
return;
|
||||
|
||||
|
||||
//check which clients can receive the message and apply distance effects
|
||||
foreach (Client client in ConnectedClients)
|
||||
|
||||
@@ -94,29 +94,20 @@ namespace Barotrauma.Networking
|
||||
ChatMessage.CanUseRadio(sender.Character, out WifiComponent senderRadio) &&
|
||||
ChatMessage.CanUseRadio(recipient.Character, out WifiComponent recipientRadio))
|
||||
{
|
||||
var should = GameMain.Lua.hook.Call("canUseVoiceRadio", new object[] { sender, recipient });
|
||||
var should = new LuaResult(GameMain.Lua.hook.Call("canUseVoiceRadio", new object[] { sender, recipient }));
|
||||
|
||||
if (should != null)
|
||||
{
|
||||
if (should is DynValue dyn)
|
||||
{
|
||||
return dyn.CastToBool();
|
||||
}
|
||||
}
|
||||
if (!should.IsNull() && should.Bool())
|
||||
return should.Bool();
|
||||
|
||||
if (recipientRadio.CanReceive(senderRadio)) { return true; }
|
||||
}
|
||||
|
||||
var should2 = GameMain.Lua.hook.Call("changeLocalVoiceRange", new object[] { sender, recipient });
|
||||
var should2 = new LuaResult(GameMain.Lua.hook.Call("changeLocalVoiceRange", new object[] { sender, recipient }));
|
||||
float range = 1.0f;
|
||||
|
||||
if (should2 != null)
|
||||
{
|
||||
if (should2 is DynValue dyn)
|
||||
{
|
||||
range = (float)dyn.CastToNumber();
|
||||
}
|
||||
}
|
||||
if (!should2.IsNull())
|
||||
range = should2.Float();
|
||||
|
||||
|
||||
//otherwise do a distance check
|
||||
return ChatMessage.GetGarbleAmount(recipient.Character, sender.Character, ChatMessage.SpeakRange) < range;
|
||||
|
||||
Reference in New Issue
Block a user