add handbook

This commit is contained in:
Somebody
2024-04-05 18:48:32 +08:00
parent f67b2f9d81
commit 5f1601ef9d
4 changed files with 129 additions and 1 deletions

View File

@@ -8,6 +8,8 @@ namespace EggLink.DanhengServer.Data.Excel
{
public int SubMissionID { get; set; }
public HashName TargetText { get; set; } = new();
[JsonIgnore()]
public int MainMissionID { get; set; }
[JsonIgnore()]

View File

@@ -2,7 +2,7 @@
namespace EggLink.DanhengServer.Command.Cmd
{
[CommandInfo("mission", "Manage the missions", "/mission <pass>")]
[CommandInfo("mission", "Get the running missions or finish the mission", "/mission <finish [submissionId]>/<running>")]
public class CommandMission : ICommand
{
[CommandMethod("0 pass")]

View File

@@ -0,0 +1,116 @@
using EggLink.DanhengServer.Data;
using EggLink.DanhengServer.Program;
using EggLink.DanhengServer.Util;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EggLink.DanhengServer.Handbook
{
public static class HandbookGenerator
{
public static readonly string HandbookPath = "Config/Handbook.txt";
public static void Generate()
{
var config = ConfigManager.Config;
var textMapPath = config.Path.ResourcePath + "/TextMap/TextMap" + config.ServerOption.Language + ".json";
if (!File.Exists(textMapPath))
{
Logger.GetByClassName().Error("TextMap file not found: " + textMapPath);
return;
}
var textMap = JsonConvert.DeserializeObject<Dictionary<long, string>>(File.ReadAllText(textMapPath));
if (textMap == null)
{
Logger.GetByClassName().Error("Failed to load TextMap file: " + textMapPath);
return;
}
var builder = new StringBuilder();
builder.AppendLine("Handbook generated in " + DateTime.Now.ToString("yyyy/MM/dd HH:mm"));
GenerateCmd(builder);
builder.AppendLine();
builder.AppendLine("#Avatar");
builder.AppendLine();
GenerateAvatar(builder, textMap);
builder.AppendLine();
builder.AppendLine("#Item");
builder.AppendLine();
GenerateItem(builder, textMap);
builder.AppendLine();
builder.AppendLine("#MainMission");
builder.AppendLine();
GenerateMainMissionId(builder, textMap);
builder.AppendLine();
builder.AppendLine("#SubMission");
builder.AppendLine();
GenerateSubMissionId(builder, textMap);
builder.AppendLine();
WriteToFile(builder.ToString());
Logger.GetByClassName().Info("Handbook generated successfully.");
}
public static void GenerateCmd(StringBuilder builder)
{
foreach (var cmd in EntryPoint.CommandManager.CommandInfo)
{
builder.Append("Command: " + cmd.Key);
builder.Append(" --- Description: " + cmd.Value.Description);
builder.Append(" --- Usage: " + cmd.Value.Usage);
builder.AppendLine();
}
}
public static void GenerateItem(StringBuilder builder, Dictionary<long, string> map)
{
foreach (var item in GameData.ItemConfigData.Values)
{
var name = map.TryGetValue(item.ItemName.Hash, out var value) ? value : $"[{item.ItemName.Hash}]";
builder.AppendLine(item.ID + ": " + name);
}
}
public static void GenerateAvatar(StringBuilder builder, Dictionary<long, string> map)
{
foreach (var avatar in GameData.AvatarConfigData.Values)
{
var name = map.TryGetValue(avatar.AvatarName.Hash, out var value) ? value : $"[{avatar.AvatarName.Hash}]";
builder.AppendLine(avatar.AvatarID + ": " + name);
}
}
public static void GenerateMainMissionId(StringBuilder builder, Dictionary<long, string> map)
{
foreach (var mission in GameData.MainMissionData.Values)
{
var name = map.TryGetValue(mission.Name.Hash, out var value) ? value : $"[{mission.Name.Hash}]";
builder.AppendLine(mission.MainMissionID + ": " + name);
}
}
public static void GenerateSubMissionId(StringBuilder builder, Dictionary<long, string> map)
{
foreach (var mission in GameData.SubMissionData.Values)
{
var name = map.TryGetValue(mission.TargetText.Hash, out var value) ? value : $"[{mission.TargetText.Hash}]";
builder.AppendLine(mission.SubMissionID + ": " + name);
}
}
public static void WriteToFile(string content)
{
File.WriteAllText(HandbookPath, content);
}
}
}

View File

@@ -9,6 +9,7 @@ using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using EggLink.DanhengServer.Command;
using System.Runtime.InteropServices;
using EggLink.DanhengServer.Handbook;
namespace EggLink.DanhengServer.Program
{
@@ -35,9 +36,11 @@ namespace EggLink.DanhengServer.Program
break;
}
}
Logger.SetLogFile(file);
// Starting the server
logger.Info("Starting DanhengServer...");
// Load the config
logger.Info("Loading config...");
try
@@ -49,6 +52,7 @@ namespace EggLink.DanhengServer.Program
Console.ReadLine();
return;
}
// Load the game data
logger.Info("Loading game data...");
try
@@ -60,6 +64,7 @@ namespace EggLink.DanhengServer.Program
Console.ReadLine();
return;
}
// Initialize the database
try
{
@@ -70,6 +75,7 @@ namespace EggLink.DanhengServer.Program
Console.ReadLine();
return;
}
try
{
CommandManager.RegisterCommand();
@@ -79,6 +85,10 @@ namespace EggLink.DanhengServer.Program
Console.ReadLine();
return;
}
// generate the handbook
HandbookGenerator.Generate();
SetConsoleCtrlHandler(new ConsoleCtrlDelegate(ConsoleCtrlHandler), true);
WebProgram.Main([$"--urls=http://{GetConfig().HttpServer.PublicAddress}:{GetConfig().HttpServer.PublicPort}/"]);
logger.Info($"Dispatch Server is running on http://{GetConfig().HttpServer.PublicAddress}:{GetConfig().HttpServer.PublicPort}/");