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) =>
|
||||
{
|
||||
GameMain.Lua = new LuaSetup();
|
||||
GameMain.Lua.Initialize();
|
||||
}));
|
||||
|
||||
|
||||
|
||||
@@ -137,6 +137,8 @@ namespace Barotrauma
|
||||
NetLobbyScreen = new NetLobbyScreen();
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
partial class LuaSetup
|
||||
{
|
||||
private static Vector2 CreateVector2(float x, float y)
|
||||
@@ -40,13 +41,12 @@ namespace Barotrauma
|
||||
|
||||
public static List<Client> GetAllClients()
|
||||
{
|
||||
|
||||
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)
|
||||
@@ -89,7 +89,7 @@ namespace Barotrauma
|
||||
|
||||
public static void SetSpectatorPos(Client client, Vector2 pos)
|
||||
{
|
||||
client.SpectatePos = pos;
|
||||
|
||||
}
|
||||
|
||||
public static void SetRadioRange(Character character, float range)
|
||||
@@ -610,6 +610,8 @@ namespace Barotrauma
|
||||
{
|
||||
if (hf.function is Closure)
|
||||
lastResult = env.lua.Call(hf.function, args);
|
||||
// else if (hf.function is NLua.LuaFunction luaFunction)
|
||||
// lastResult = luaFunction.Call(args);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -13,8 +13,10 @@ namespace Barotrauma
|
||||
{
|
||||
partial class LuaSetup
|
||||
{
|
||||
public static LuaSetup luaSetup;
|
||||
|
||||
public Script lua;
|
||||
|
||||
public LuaHook hook;
|
||||
public LuaGame game;
|
||||
|
||||
@@ -22,9 +24,9 @@ namespace Barotrauma
|
||||
|
||||
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);
|
||||
else
|
||||
PrintMessage(((InterpreterException)ex).DecoratedMessage);
|
||||
@@ -70,12 +72,12 @@ namespace Barotrauma
|
||||
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
|
||||
{
|
||||
return lua.DoFile(file, globalContext, codeStringFriendly);
|
||||
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -133,11 +135,11 @@ namespace Barotrauma
|
||||
|
||||
public static DynValue CreateUserDataSafe(object o)
|
||||
{
|
||||
if(o == null)
|
||||
if (o == null)
|
||||
return DynValue.Nil;
|
||||
|
||||
return UserData.Create(o);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -146,15 +148,22 @@ namespace Barotrauma
|
||||
luaScriptLoader.ModulePaths = str;
|
||||
}
|
||||
|
||||
public LuaSetup()
|
||||
public float TestFunction(float value)
|
||||
{
|
||||
return value * 2;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
luaSetup = this;
|
||||
|
||||
PrintMessage("Lua!");
|
||||
|
||||
luaScriptLoader = new LuaScriptLoader(this);
|
||||
luaScriptLoader.ModulePaths = new string[] { };
|
||||
|
||||
LuaCustomConverters.RegisterAll();
|
||||
|
||||
|
||||
UserData.RegisterType<TraitorMessageType>();
|
||||
UserData.RegisterType<JobPrefab>();
|
||||
UserData.RegisterType<CharacterInfo>();
|
||||
@@ -203,8 +212,8 @@ namespace Barotrauma
|
||||
UserData.RegisterType<ItemComponent>();
|
||||
UserData.RegisterType<WifiComponent>();
|
||||
UserData.RegisterType<LightComponent>();
|
||||
UserData.RegisterType<CustomInterface>();
|
||||
UserData.RegisterType<Holdable>();
|
||||
UserData.RegisterType<CustomInterface>();
|
||||
UserData.RegisterType<Inventory>();
|
||||
UserData.RegisterType<CharacterInventory>();
|
||||
UserData.RegisterType<Hull>();
|
||||
@@ -229,10 +238,12 @@ namespace Barotrauma
|
||||
lua.Options.DebugPrint = PrintMessage;
|
||||
|
||||
lua.Options.ScriptLoader = luaScriptLoader;
|
||||
|
||||
|
||||
hook = new LuaHook(this);
|
||||
game = new LuaGame(this);
|
||||
|
||||
lua.Globals["TestFunction"] = (Func<float, float>)TestFunction;
|
||||
|
||||
lua.Globals["printNoLog"] = (Action<object>)PrintMessageNoLog;
|
||||
|
||||
lua.Globals["dofile"] = (Func<string, Table, string, DynValue>)DoFile;
|
||||
@@ -258,6 +269,7 @@ namespace Barotrauma
|
||||
lua.Globals["Submarine"] = UserData.CreateStatic<Submarine>();
|
||||
lua.Globals["Client"] = UserData.CreateStatic<Client>();
|
||||
lua.Globals["Character"] = UserData.CreateStatic<Character>();
|
||||
lua.Globals["CharacterInfo"] = UserData.CreateStatic<CharacterInfo>();
|
||||
lua.Globals["Item"] = UserData.CreateStatic<Item>();
|
||||
lua.Globals["Level"] = UserData.CreateStatic<Level>();
|
||||
lua.Globals["PositionType"] = UserData.CreateStatic<Level.PositionType>();
|
||||
@@ -265,7 +277,7 @@ namespace Barotrauma
|
||||
lua.Globals["TraitorMessageType"] = UserData.CreateStatic<TraitorMessageType>();
|
||||
lua.Globals["CauseOfDeathType"] = UserData.CreateStatic<CauseOfDeathType>();
|
||||
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["Vector3"] = UserData.CreateStatic<Vector3>();
|
||||
lua.Globals["Vector4"] = UserData.CreateStatic<Vector3>();
|
||||
@@ -279,12 +291,13 @@ namespace Barotrauma
|
||||
lua.Globals["ContentPackage"] = UserData.CreateStatic<ContentPackage>();
|
||||
lua.Globals["ClientPermissions"] = UserData.CreateStatic<ClientPermissions>();
|
||||
|
||||
|
||||
if (File.Exists("Lua/MoonsharpSetup.lua")) // try the default loader
|
||||
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");
|
||||
else // fallback to c# script loading
|
||||
{
|
||||
{
|
||||
List<string> modulePaths = new List<string>();
|
||||
|
||||
foreach (string d in Directory.GetDirectories("Mods"))
|
||||
@@ -299,6 +312,11 @@ namespace Barotrauma
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
GameMain.Lua = new LuaSetup();
|
||||
GameMain.Lua.Initialize();
|
||||
|
||||
TickRate = serverSettings.TickRate;
|
||||
|
||||
@@ -3844,7 +3844,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
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.Server.ServerSettings.ServerLog.WriteLine(line, messageType);
|
||||
|
||||
Reference in New Issue
Block a user