making things more organized, turning Player deprecated, preparing for nlua and using partial classes for additions to another barotrauma classes
This commit is contained in:
@@ -1250,7 +1250,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
commands.Add(new Command("reloadlua", "reloads lua", (string[] args) =>
|
commands.Add(new Command("reloadlua", "reloads lua", (string[] args) =>
|
||||||
{
|
{
|
||||||
GameMain.Lua = new LuaSetup();
|
GameMain.Lua.Initialize();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -137,6 +137,8 @@ namespace Barotrauma
|
|||||||
NetLobbyScreen = new NetLobbyScreen();
|
NetLobbyScreen = new NetLobbyScreen();
|
||||||
|
|
||||||
CheckContentPackage();
|
CheckContentPackage();
|
||||||
|
|
||||||
|
Lua = new LuaSetup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Barotrauma.Networking
|
||||||
|
{
|
||||||
|
partial class Client
|
||||||
|
{
|
||||||
|
public static List<Client> ClientList
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return GameMain.Server.ConnectedClients;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetClientCharacter(Character character)
|
||||||
|
{
|
||||||
|
GameMain.Server.SetClientCharacter(this, character);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Kick(string reason = "")
|
||||||
|
{
|
||||||
|
GameMain.Server.KickClient(this.Connection, reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Ban(string reason = "", bool range = false, float seconds = -1)
|
||||||
|
{
|
||||||
|
if (seconds == -1)
|
||||||
|
{
|
||||||
|
GameMain.Server.BanClient(this, reason, range, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GameMain.Server.BanClient(this, reason, range, TimeSpan.FromSeconds(seconds));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Unban(string player, string endpoint)
|
||||||
|
{
|
||||||
|
GameMain.Server.UnbanPlayer(player, endpoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CheckPermission(ClientPermissions permissions)
|
||||||
|
{
|
||||||
|
return this.Permissions.HasFlag(permissions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Barotrauma
|
||||||
|
{
|
||||||
|
partial class CharacterInfo
|
||||||
|
{
|
||||||
|
public static CharacterInfo Create(string speciesName, string name = "", JobPrefab jobPrefab = null, string ragdollFileName = null, int variant = 0, Rand.RandSync randSync = Rand.RandSync.Unsynced, string npcIdentifier = "")
|
||||||
|
{
|
||||||
|
return new CharacterInfo(speciesName, name, name, jobPrefab, ragdollFileName, variant, randSync, npcIdentifier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ using System.Xml.Linq;
|
|||||||
|
|
||||||
namespace Barotrauma
|
namespace Barotrauma
|
||||||
{
|
{
|
||||||
|
|
||||||
partial class LuaSetup
|
partial class LuaSetup
|
||||||
{
|
{
|
||||||
private static Vector2 CreateVector2(float x, float y)
|
private static Vector2 CreateVector2(float x, float y)
|
||||||
@@ -40,13 +41,12 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public static List<Client> GetAllClients()
|
public static List<Client> GetAllClients()
|
||||||
{
|
{
|
||||||
|
|
||||||
return GameMain.Server.ConnectedClients;
|
return GameMain.Server.ConnectedClients;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CharacterInfo CreateCharacterInfo(string speciesName, string name = "", JobPrefab jobPrefab = null, string ragdollFileName = null, int variant = 0, Rand.RandSync randSync = Rand.RandSync.Unsynced)
|
public static CharacterInfo CreateCharacterInfo(string speciesName, string name = "", JobPrefab jobPrefab = null, string ragdollFileName = null, int variant = 0, Rand.RandSync randSync = Rand.RandSync.Unsynced, string npcIdentifier = "")
|
||||||
{
|
{
|
||||||
return new CharacterInfo(speciesName, name, name, jobPrefab, ragdollFileName, variant, randSync);
|
return new CharacterInfo(speciesName, name, name, jobPrefab, ragdollFileName, variant, randSync, npcIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetClientCharacter(Client client, Character character)
|
public static void SetClientCharacter(Client client, Character character)
|
||||||
@@ -89,7 +89,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public static void SetSpectatorPos(Client client, Vector2 pos)
|
public static void SetSpectatorPos(Client client, Vector2 pos)
|
||||||
{
|
{
|
||||||
client.SpectatePos = pos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetRadioRange(Character character, float range)
|
public static void SetRadioRange(Character character, float range)
|
||||||
@@ -610,6 +610,8 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
if (hf.function is Closure)
|
if (hf.function is Closure)
|
||||||
lastResult = env.lua.Call(hf.function, args);
|
lastResult = env.lua.Call(hf.function, args);
|
||||||
|
// else if (hf.function is NLua.LuaFunction luaFunction)
|
||||||
|
// lastResult = luaFunction.Call(args);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,8 +13,10 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
partial class LuaSetup
|
partial class LuaSetup
|
||||||
{
|
{
|
||||||
|
public static LuaSetup luaSetup;
|
||||||
|
|
||||||
public Script lua;
|
public Script lua;
|
||||||
|
|
||||||
public LuaHook hook;
|
public LuaHook hook;
|
||||||
public LuaGame game;
|
public LuaGame game;
|
||||||
|
|
||||||
@@ -22,9 +24,9 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public void HandleLuaException(Exception ex)
|
public void HandleLuaException(Exception ex)
|
||||||
{
|
{
|
||||||
if(ex is InterpreterException)
|
if (ex is InterpreterException)
|
||||||
{
|
{
|
||||||
if(((InterpreterException)ex).DecoratedMessage == null)
|
if (((InterpreterException)ex).DecoratedMessage == null)
|
||||||
PrintMessage(((InterpreterException)ex).Message);
|
PrintMessage(((InterpreterException)ex).Message);
|
||||||
else
|
else
|
||||||
PrintMessage(((InterpreterException)ex).DecoratedMessage);
|
PrintMessage(((InterpreterException)ex).DecoratedMessage);
|
||||||
@@ -70,12 +72,12 @@ namespace Barotrauma
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DynValue DoFile(string file, Table globalContext=null, string codeStringFriendly = null)
|
public DynValue DoFile(string file, Table globalContext = null, string codeStringFriendly = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return lua.DoFile(file, globalContext, codeStringFriendly);
|
return lua.DoFile(file, globalContext, codeStringFriendly);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -133,11 +135,11 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public static DynValue CreateUserDataSafe(object o)
|
public static DynValue CreateUserDataSafe(object o)
|
||||||
{
|
{
|
||||||
if(o == null)
|
if (o == null)
|
||||||
return DynValue.Nil;
|
return DynValue.Nil;
|
||||||
|
|
||||||
return UserData.Create(o);
|
return UserData.Create(o);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -146,15 +148,22 @@ namespace Barotrauma
|
|||||||
luaScriptLoader.ModulePaths = str;
|
luaScriptLoader.ModulePaths = str;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LuaSetup()
|
public float TestFunction(float value)
|
||||||
{
|
{
|
||||||
|
return value * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Initialize()
|
||||||
|
{
|
||||||
|
luaSetup = this;
|
||||||
|
|
||||||
PrintMessage("Lua!");
|
PrintMessage("Lua!");
|
||||||
|
|
||||||
luaScriptLoader = new LuaScriptLoader(this);
|
luaScriptLoader = new LuaScriptLoader(this);
|
||||||
luaScriptLoader.ModulePaths = new string[] { };
|
luaScriptLoader.ModulePaths = new string[] { };
|
||||||
|
|
||||||
LuaCustomConverters.RegisterAll();
|
LuaCustomConverters.RegisterAll();
|
||||||
|
|
||||||
UserData.RegisterType<TraitorMessageType>();
|
UserData.RegisterType<TraitorMessageType>();
|
||||||
UserData.RegisterType<JobPrefab>();
|
UserData.RegisterType<JobPrefab>();
|
||||||
UserData.RegisterType<CharacterInfo>();
|
UserData.RegisterType<CharacterInfo>();
|
||||||
@@ -203,8 +212,8 @@ namespace Barotrauma
|
|||||||
UserData.RegisterType<ItemComponent>();
|
UserData.RegisterType<ItemComponent>();
|
||||||
UserData.RegisterType<WifiComponent>();
|
UserData.RegisterType<WifiComponent>();
|
||||||
UserData.RegisterType<LightComponent>();
|
UserData.RegisterType<LightComponent>();
|
||||||
UserData.RegisterType<CustomInterface>();
|
|
||||||
UserData.RegisterType<Holdable>();
|
UserData.RegisterType<Holdable>();
|
||||||
|
UserData.RegisterType<CustomInterface>();
|
||||||
UserData.RegisterType<Inventory>();
|
UserData.RegisterType<Inventory>();
|
||||||
UserData.RegisterType<CharacterInventory>();
|
UserData.RegisterType<CharacterInventory>();
|
||||||
UserData.RegisterType<Hull>();
|
UserData.RegisterType<Hull>();
|
||||||
@@ -229,10 +238,12 @@ namespace Barotrauma
|
|||||||
lua.Options.DebugPrint = PrintMessage;
|
lua.Options.DebugPrint = PrintMessage;
|
||||||
|
|
||||||
lua.Options.ScriptLoader = luaScriptLoader;
|
lua.Options.ScriptLoader = luaScriptLoader;
|
||||||
|
|
||||||
hook = new LuaHook(this);
|
hook = new LuaHook(this);
|
||||||
game = new LuaGame(this);
|
game = new LuaGame(this);
|
||||||
|
|
||||||
|
lua.Globals["TestFunction"] = (Func<float, float>)TestFunction;
|
||||||
|
|
||||||
lua.Globals["printNoLog"] = (Action<object>)PrintMessageNoLog;
|
lua.Globals["printNoLog"] = (Action<object>)PrintMessageNoLog;
|
||||||
|
|
||||||
lua.Globals["dofile"] = (Func<string, Table, string, DynValue>)DoFile;
|
lua.Globals["dofile"] = (Func<string, Table, string, DynValue>)DoFile;
|
||||||
@@ -258,6 +269,7 @@ namespace Barotrauma
|
|||||||
lua.Globals["Submarine"] = UserData.CreateStatic<Submarine>();
|
lua.Globals["Submarine"] = UserData.CreateStatic<Submarine>();
|
||||||
lua.Globals["Client"] = UserData.CreateStatic<Client>();
|
lua.Globals["Client"] = UserData.CreateStatic<Client>();
|
||||||
lua.Globals["Character"] = UserData.CreateStatic<Character>();
|
lua.Globals["Character"] = UserData.CreateStatic<Character>();
|
||||||
|
lua.Globals["CharacterInfo"] = UserData.CreateStatic<CharacterInfo>();
|
||||||
lua.Globals["Item"] = UserData.CreateStatic<Item>();
|
lua.Globals["Item"] = UserData.CreateStatic<Item>();
|
||||||
lua.Globals["Level"] = UserData.CreateStatic<Level>();
|
lua.Globals["Level"] = UserData.CreateStatic<Level>();
|
||||||
lua.Globals["PositionType"] = UserData.CreateStatic<Level.PositionType>();
|
lua.Globals["PositionType"] = UserData.CreateStatic<Level.PositionType>();
|
||||||
@@ -265,7 +277,7 @@ namespace Barotrauma
|
|||||||
lua.Globals["TraitorMessageType"] = UserData.CreateStatic<TraitorMessageType>();
|
lua.Globals["TraitorMessageType"] = UserData.CreateStatic<TraitorMessageType>();
|
||||||
lua.Globals["CauseOfDeathType"] = UserData.CreateStatic<CauseOfDeathType>();
|
lua.Globals["CauseOfDeathType"] = UserData.CreateStatic<CauseOfDeathType>();
|
||||||
lua.Globals["AfflictionPrefab"] = UserData.CreateStatic<AfflictionPrefab>();
|
lua.Globals["AfflictionPrefab"] = UserData.CreateStatic<AfflictionPrefab>();
|
||||||
lua.Globals["CharacterTeamType"] = UserData.CreateStatic<CharacterTeamType>();
|
lua.Globals["CharacterTeamType"] = UserData.CreateStatic<CharacterTeamType>();
|
||||||
lua.Globals["Vector2"] = UserData.CreateStatic<Vector2>();
|
lua.Globals["Vector2"] = UserData.CreateStatic<Vector2>();
|
||||||
lua.Globals["Vector3"] = UserData.CreateStatic<Vector3>();
|
lua.Globals["Vector3"] = UserData.CreateStatic<Vector3>();
|
||||||
lua.Globals["Vector4"] = UserData.CreateStatic<Vector3>();
|
lua.Globals["Vector4"] = UserData.CreateStatic<Vector3>();
|
||||||
@@ -279,12 +291,13 @@ namespace Barotrauma
|
|||||||
lua.Globals["ContentPackage"] = UserData.CreateStatic<ContentPackage>();
|
lua.Globals["ContentPackage"] = UserData.CreateStatic<ContentPackage>();
|
||||||
lua.Globals["ClientPermissions"] = UserData.CreateStatic<ClientPermissions>();
|
lua.Globals["ClientPermissions"] = UserData.CreateStatic<ClientPermissions>();
|
||||||
|
|
||||||
|
|
||||||
if (File.Exists("Lua/MoonsharpSetup.lua")) // try the default loader
|
if (File.Exists("Lua/MoonsharpSetup.lua")) // try the default loader
|
||||||
DoFile("Lua/MoonsharpSetup.lua");
|
DoFile("Lua/MoonsharpSetup.lua");
|
||||||
else if(File.Exists("Mods/LuaForBarotrauma/Lua/MoonsharpSetup.lua")) // in case its the workshop version
|
else if (File.Exists("Mods/LuaForBarotrauma/Lua/MoonsharpSetup.lua")) // in case its the workshop version
|
||||||
DoFile("Mods/LuaForBarotrauma/Lua/MoonsharpSetup.lua");
|
DoFile("Mods/LuaForBarotrauma/Lua/MoonsharpSetup.lua");
|
||||||
else // fallback to c# script loading
|
else // fallback to c# script loading
|
||||||
{
|
{
|
||||||
List<string> modulePaths = new List<string>();
|
List<string> modulePaths = new List<string>();
|
||||||
|
|
||||||
foreach (string d in Directory.GetDirectories("Mods"))
|
foreach (string d in Directory.GetDirectories("Mods"))
|
||||||
@@ -299,6 +312,11 @@ namespace Barotrauma
|
|||||||
|
|
||||||
luaScriptLoader.ModulePaths = modulePaths.ToArray();
|
luaScriptLoader.ModulePaths = modulePaths.ToArray();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public LuaSetup()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Barotrauma
|
||||||
|
{
|
||||||
|
partial class LuaSetup
|
||||||
|
{
|
||||||
|
//private void NLua_HookException(object sender, NLua.Event.HookExceptionEventArgs e)
|
||||||
|
//{
|
||||||
|
// HandleLuaException(e.Exception);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -197,7 +197,7 @@ namespace Barotrauma.Networking
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
GameMain.Lua = new LuaSetup();
|
GameMain.Lua.Initialize();
|
||||||
|
|
||||||
TickRate = serverSettings.TickRate;
|
TickRate = serverSettings.TickRate;
|
||||||
|
|
||||||
@@ -3844,7 +3844,7 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
if (GameMain.Server == null || !GameMain.Server.ServerSettings.SaveServerLogs) { return; }
|
if (GameMain.Server == null || !GameMain.Server.ServerSettings.SaveServerLogs) { return; }
|
||||||
|
|
||||||
if(GameMain.Lua != null)
|
if(GameMain.Lua.hook != null)
|
||||||
GameMain.Lua.hook.Call("serverLog", new object[] { line, messageType });
|
GameMain.Lua.hook.Call("serverLog", new object[] { line, messageType });
|
||||||
|
|
||||||
GameMain.Server.ServerSettings.ServerLog.WriteLine(line, messageType);
|
GameMain.Server.ServerSettings.ServerLog.WriteLine(line, messageType);
|
||||||
|
|||||||
Reference in New Issue
Block a user