2024-12-23 14:40:57 -05:00
|
|
|
using Arrowgene.Ddon.GameServer.Scripting;
|
|
|
|
|
using Arrowgene.Ddon.Server.Scripting.utils;
|
2025-02-25 00:52:52 -05:00
|
|
|
using Arrowgene.Ddon.Server.Settings;
|
2024-12-23 14:40:57 -05:00
|
|
|
using Arrowgene.Ddon.Shared.Model;
|
|
|
|
|
using Microsoft.CodeAnalysis;
|
|
|
|
|
using Microsoft.CodeAnalysis.Scripting;
|
2025-02-25 00:52:52 -05:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2024-12-23 14:40:57 -05:00
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace Arrowgene.Ddon.Server.Scripting.modules
|
|
|
|
|
{
|
|
|
|
|
public class GameServerSettingsModule : ScriptModule
|
|
|
|
|
{
|
|
|
|
|
public override string ModuleRoot => "settings";
|
|
|
|
|
public override string Filter => "*.csx";
|
|
|
|
|
public override bool ScanSubdirectories => true;
|
|
|
|
|
public override bool EnableHotLoad => true;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Settings data is organized as ScriptName.FieldName
|
|
|
|
|
/// </summary>
|
|
|
|
|
private ScriptableSettings SettingsData { get; set; }
|
2025-02-25 00:52:52 -05:00
|
|
|
|
|
|
|
|
public GameSettings GameSettings { get; private set; }
|
|
|
|
|
|
|
|
|
|
private List<IGameSettings> DefaultSettings { get; set; }
|
|
|
|
|
|
|
|
|
|
public string TemplatesDirectory {get; private set;}
|
2024-12-23 14:40:57 -05:00
|
|
|
|
2025-04-12 18:34:55 -04:00
|
|
|
public GameServerSettingsModule(string scriptsRoot)
|
2024-12-23 14:40:57 -05:00
|
|
|
{
|
2025-04-12 18:34:55 -04:00
|
|
|
TemplatesDirectory = Path.Combine(scriptsRoot, "settings/templates");
|
2025-02-25 00:52:52 -05:00
|
|
|
|
2024-12-23 14:40:57 -05:00
|
|
|
SettingsData = new ScriptableSettings();
|
2025-02-25 00:52:52 -05:00
|
|
|
GameSettings = new GameSettings(SettingsData);
|
|
|
|
|
|
|
|
|
|
// Provide a list of all the settings objects
|
|
|
|
|
// that defaults need to be assigned for
|
|
|
|
|
DefaultSettings = new List<IGameSettings>()
|
|
|
|
|
{
|
2025-06-12 01:13:59 -04:00
|
|
|
GameSettings.DebugSettings,
|
2025-02-25 00:52:52 -05:00
|
|
|
GameSettings.GameServerSettings,
|
|
|
|
|
GameSettings.ChatCommandsSettings,
|
|
|
|
|
GameSettings.SeasonalEventsSettings,
|
|
|
|
|
GameSettings.PointModifiersSettings,
|
2024-08-23 16:49:44 -04:00
|
|
|
GameSettings.EmblemSettings,
|
2025-02-25 00:52:52 -05:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreateTemplate(string outputRootPath, Type type)
|
|
|
|
|
{
|
|
|
|
|
string outputPath = Path.Combine(outputRootPath, $"{type.Name}.csx");
|
|
|
|
|
SettingsTemplate.Generate(outputPath, type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
if (!Directory.Exists(TemplatesDirectory))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(TemplatesDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var defaultSetting in DefaultSettings)
|
|
|
|
|
{
|
|
|
|
|
defaultSetting.InitializeDefaults();
|
|
|
|
|
CreateTemplate(TemplatesDirectory, defaultSetting.GetType());
|
|
|
|
|
}
|
2024-12-23 14:40:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override ScriptOptions Options()
|
|
|
|
|
{
|
|
|
|
|
return ScriptOptions.Default
|
2025-02-25 00:52:52 -05:00
|
|
|
.AddReferences(MetadataReference.CreateFromFile(typeof(GameSettings).Assembly.Location))
|
2024-12-23 14:40:57 -05:00
|
|
|
.AddReferences(MetadataReference.CreateFromFile(typeof(WalletType).Assembly.Location))
|
2024-12-26 22:26:23 -05:00
|
|
|
.AddReferences(MetadataReference.CreateFromFile(typeof(LibUtils).Assembly.Location))
|
2024-12-23 14:40:57 -05:00
|
|
|
.AddImports("System", "System.Collections", "System.Collections.Generic")
|
2024-12-26 22:26:23 -05:00
|
|
|
.AddImports("Arrowgene.Ddon.Server.Scripting")
|
2026-04-23 08:46:45 -04:00
|
|
|
.AddImports("Arrowgene.Ddon.Server.Settings")
|
2024-12-23 14:40:57 -05:00
|
|
|
.AddImports("Arrowgene.Ddon.Shared.Model")
|
|
|
|
|
.AddImports("Arrowgene.Ddon.Shared.Model.Quest");
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-29 02:07:13 -07:00
|
|
|
public override bool EvaluateResult(string path, object result, IDictionary<string, object> variables)
|
2024-12-23 14:40:57 -05:00
|
|
|
{
|
2025-02-25 00:52:52 -05:00
|
|
|
if (path.Contains(TemplatesDirectory))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-23 14:40:57 -05:00
|
|
|
var scriptName = Path.GetFileNameWithoutExtension(path);
|
|
|
|
|
|
2025-06-29 02:07:13 -07:00
|
|
|
foreach (var (name, value) in variables)
|
2024-12-23 14:40:57 -05:00
|
|
|
{
|
2025-06-29 02:07:13 -07:00
|
|
|
SettingsData.Set(scriptName, name, value);
|
2024-12-23 14:40:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|