ascnet/AscNet.GameServer/Commands/LevelCommand.cs

62 lines
2.2 KiB
C#
Raw Normal View History

2023-11-28 14:13:37 +00:00
using AscNet.Common.MsgPack;
using AscNet.Common.Util;
using AscNet.GameServer.Handlers;
2023-11-28 12:51:39 +00:00
using AscNet.Table.V2.share.player;
namespace AscNet.GameServer.Commands
{
[CommandName("level")]
internal class LevelCommand : Command
{
public LevelCommand(Session session, string[] args, bool validate = true) : base(session, args, validate) { }
public override string Help => "Command to change the Commandant level";
[Argument(0, @"^[0-9]+$|^max$", "The target level, value is number or 'max'")]
string Level { get; set; } = string.Empty;
public override void Execute()
{
2023-11-28 14:13:37 +00:00
List<PlayerTable> playerLevels = TableReaderV2.Parse<PlayerTable>();
2023-11-28 12:51:39 +00:00
int level = Miscs.ParseIntOr(Level);
if (Level == "max")
{
2023-11-28 14:13:37 +00:00
session.player.PlayerData.Level = playerLevels.OrderByDescending(x => x.Level).First().Level;
NotifyPlayerLevel notifyPlayerLevel = new()
{
Level = (int)session.player.PlayerData.Level
};
session.SendPush(notifyPlayerLevel);
2023-11-28 12:51:39 +00:00
session.ExpSanityCheck();
}
2023-11-28 14:13:37 +00:00
else if (playerLevels.Any(x => x.Level == level))
2023-11-28 12:51:39 +00:00
{
2023-11-28 14:13:37 +00:00
if (session.player.PlayerData.Level > level)
{
session.player.PlayerData.Level = level;
// Waiting for SendChatResponse, pls fix later
Task.Run(() =>
{
// ReconnectPlayerLogout
session.SendPush(new ForceLogoutNotify() { Code = 1030 });
session.DisconnectProtocol();
});
return;
}
2023-11-28 12:51:39 +00:00
session.player.PlayerData.Level = level;
2023-11-28 14:13:37 +00:00
NotifyPlayerLevel notifyPlayerLevel = new()
{
Level = (int)session.player.PlayerData.Level
};
session.SendPush(notifyPlayerLevel);
2023-11-28 12:51:39 +00:00
session.ExpSanityCheck();
}
else
{
throw new ArgumentException("Invalid Level!");
}
}
}
}