more
This commit is contained in:
@@ -124,6 +124,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MoonSharp" Version="2.0.0" />
|
||||
<PackageReference Include="MoonSharp.Debugger.VsCode" Version="2.0.0" />
|
||||
<PackageReference Include="NVorbis" Version="0.8.6" />
|
||||
<PackageReference Include="RestSharp" Version="106.6.10" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -12,6 +12,7 @@ using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Xml.Linq;
|
||||
using MoonSharp.Interpreter;
|
||||
using MoonSharp.VsCodeDebugger;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -135,6 +136,7 @@ namespace Barotrauma
|
||||
CheckContentPackage();
|
||||
|
||||
Lua = new LuaSetup();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -361,7 +363,7 @@ namespace Barotrauma
|
||||
TaskPool.Update();
|
||||
CoroutineManager.Update((float)Timing.Step, (float)Timing.Step);
|
||||
|
||||
GameMain.Lua.hook.Call("think", new DynValue[] { DynValue.NewNumber(elapsedTime) });
|
||||
GameMain.Lua.hook.Call("think", new DynValue[] { DynValue.NewNumber(elapsedTime), DynValue.NewNumber(Timing.TotalTime) });
|
||||
|
||||
Timing.Accumulator -= Timing.Step;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,22 @@ namespace Barotrauma
|
||||
{
|
||||
Console.WriteLine(s);
|
||||
|
||||
script.DoFile(s); // i hate windows
|
||||
try
|
||||
{
|
||||
script.DoFile(s); // i hate windows
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e is InterpreterException)
|
||||
{
|
||||
|
||||
Console.WriteLine(((InterpreterException)e).DecoratedMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using Barotrauma.Networking;
|
||||
using MoonSharp.Interpreter;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Threading.Tasks;
|
||||
using MoonSharp.VsCodeDebugger;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -15,6 +16,7 @@ namespace Barotrauma
|
||||
public Script lua;
|
||||
public Hook hook;
|
||||
|
||||
public bool overrideTraitors = false;
|
||||
|
||||
public void DoString(string code)
|
||||
{
|
||||
@@ -24,7 +26,36 @@ namespace Barotrauma
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
if (e is InterpreterException)
|
||||
{
|
||||
|
||||
Console.WriteLine(((InterpreterException)e).DecoratedMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void RunFunction(DynValue func)
|
||||
{
|
||||
try
|
||||
{
|
||||
lua.Call(func);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e is InterpreterException)
|
||||
{
|
||||
|
||||
Console.WriteLine(((InterpreterException)e).DecoratedMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,11 +117,23 @@ namespace Barotrauma
|
||||
|
||||
private class Game
|
||||
{
|
||||
LuaSetup env;
|
||||
|
||||
public Game(LuaSetup e)
|
||||
{
|
||||
env = e;
|
||||
}
|
||||
|
||||
public static void SendMessage(string msg, int messageType = 0, Client sender = null, Character character = null)
|
||||
{
|
||||
GameMain.Server.SendChatMessage(msg, (ChatMessageType)messageType, sender, character);
|
||||
}
|
||||
|
||||
public static void SendTraitorMessage(Client client, string msg, int type)
|
||||
{
|
||||
GameMain.Server.SendTraitorMessage(client, msg, "", (TraitorMessageType)type);
|
||||
}
|
||||
|
||||
public static void SendDirectChatMessage(string sendername, string text, Character sender, int messageType = 0, Client client = null)
|
||||
{
|
||||
|
||||
@@ -100,6 +143,11 @@ namespace Barotrauma
|
||||
|
||||
}
|
||||
|
||||
public void OverrideTraitors(bool o)
|
||||
{
|
||||
env.overrideTraitors = o;
|
||||
}
|
||||
|
||||
public static void Log(string message, int type)
|
||||
{
|
||||
GameServer.Log(message, (ServerLog.MessageType)type);
|
||||
@@ -128,16 +176,22 @@ namespace Barotrauma
|
||||
|
||||
private class LuaTimer
|
||||
{
|
||||
public Script env;
|
||||
public LuaSetup env;
|
||||
|
||||
public LuaTimer(Script e)
|
||||
public LuaTimer(LuaSetup e)
|
||||
{
|
||||
env = e;
|
||||
}
|
||||
|
||||
public void Simple(int time, DynValue function)
|
||||
{
|
||||
Task.Delay(new TimeSpan(0, 0, 0, 0, time)).ContinueWith(o => { env.Call(function); });
|
||||
|
||||
Task.Delay(time).ContinueWith(o => { env.RunFunction(function); });
|
||||
}
|
||||
|
||||
public static double GetTime()
|
||||
{
|
||||
return Timing.TotalTime;
|
||||
}
|
||||
|
||||
|
||||
@@ -207,7 +261,7 @@ namespace Barotrauma
|
||||
hookFunctions.Add(new HookFunction(name, hookName, function));
|
||||
}
|
||||
|
||||
public void Call(string name, DynValue[] args)
|
||||
public DynValue Call(string name, DynValue[] args)
|
||||
{
|
||||
foreach(HookFunction hf in hookFunctions)
|
||||
{
|
||||
@@ -215,22 +269,31 @@ namespace Barotrauma
|
||||
{
|
||||
try
|
||||
{
|
||||
env.Call(hf.function, args);
|
||||
}catch(Exception e)
|
||||
return env.Call(hf.function, args);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
if (e is InterpreterException)
|
||||
{
|
||||
|
||||
Console.WriteLine(((InterpreterException)e).DecoratedMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public LuaSetup()
|
||||
{
|
||||
|
||||
Console.WriteLine("Lua!");
|
||||
|
||||
LuaCustomConverters.RegisterAll();
|
||||
|
||||
LuaScriptLoader luaScriptLoader = new LuaScriptLoader();
|
||||
|
||||
@@ -253,10 +316,10 @@ namespace Barotrauma
|
||||
hook = new Hook(lua);
|
||||
|
||||
lua.Globals["Player"] = new Player();
|
||||
lua.Globals["Game"] = new Game();
|
||||
lua.Globals["Game"] = new Game(this);
|
||||
lua.Globals["Hook"] = hook;
|
||||
lua.Globals["Random"] = new LuaRandom();
|
||||
lua.Globals["Timer"] = new LuaTimer(lua);
|
||||
lua.Globals["Timer"] = new LuaTimer(this);
|
||||
|
||||
luaScriptLoader.RunFolder("Lua/autorun", lua);
|
||||
|
||||
|
||||
@@ -127,6 +127,21 @@ namespace Barotrauma.Networking
|
||||
return;
|
||||
}
|
||||
|
||||
var should = GameMain.Lua.hook.Call("chatMessage", new DynValue[] { DynValue.NewString(txt), UserData.Create(c) });
|
||||
|
||||
|
||||
if(should != null)
|
||||
{
|
||||
if (should.CastToBool())
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (type == ChatMessageType.Order)
|
||||
{
|
||||
if (c.Character == null || c.Character.SpeechImpediment >= 100.0f || c.Character.IsDead) { return; }
|
||||
@@ -178,9 +193,6 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
|
||||
GameMain.Lua.hook.Call("chatMessage", new DynValue[] { DynValue.NewString(txt), UserData.Create(c) });
|
||||
|
||||
|
||||
}
|
||||
|
||||
public int EstimateLengthBytesServer(Client c)
|
||||
|
||||
@@ -2345,8 +2345,11 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (!(GameMain.GameSession?.GameMode is CampaignMode))
|
||||
{
|
||||
TraitorManager = new TraitorManager();
|
||||
TraitorManager.Start(this);
|
||||
if (!GameMain.Lua.overrideTraitors)
|
||||
{
|
||||
TraitorManager = new TraitorManager();
|
||||
TraitorManager.Start(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MoonSharp" Version="2.0.0" />
|
||||
<PackageReference Include="MoonSharp.Debugger.VsCode" Version="2.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Sourced from https://stackoverflow.com/a/45248069 -->
|
||||
|
||||
Reference in New Issue
Block a user