mirror of
https://github.com/rafi1212122/BLHX.Server.git
synced 2025-12-12 14:34:39 +01:00
ship skin comamnd and changing skin
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using BLHX.Server.Common.Utils;
|
||||
using BLHX.Server.Game.Handlers;
|
||||
using System.Reflection;
|
||||
|
||||
namespace BLHX.Server.Game.Commands;
|
||||
@@ -77,6 +78,11 @@ public abstract class Command
|
||||
Execute(args);
|
||||
}
|
||||
|
||||
public virtual void NotifySuccess(Connection connection)
|
||||
{
|
||||
connection.SendSystemMsg($"{GetType().Name} success!");
|
||||
}
|
||||
|
||||
protected T Parse<T>(string? value, T fallback = default!)
|
||||
{
|
||||
var tryParseMethod = typeof(T).GetMethod("TryParse", [typeof(string), typeof(T).MakeByRefType()]);
|
||||
|
||||
@@ -25,7 +25,7 @@ public class HelpCommand : Command
|
||||
}
|
||||
|
||||
if (attr != null)
|
||||
sb.AppendLine($" {attr.Name} - {attr.Description} (Example: {attr.Example}), Usage: {command.Usage}");
|
||||
sb.AppendLine($" {attr.Name} - {attr.Description} (Example: {attr.Example})");
|
||||
}
|
||||
|
||||
Console.Write(sb.ToString());
|
||||
|
||||
54
BLHX.Server.Game/Commands/SkinCommand.cs
Normal file
54
BLHX.Server.Game/Commands/SkinCommand.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using BLHX.Server.Common.Data;
|
||||
using BLHX.Server.Common.Database;
|
||||
using BLHX.Server.Common.Proto.common;
|
||||
using BLHX.Server.Game.Handlers;
|
||||
|
||||
namespace BLHX.Server.Game.Commands
|
||||
{
|
||||
[CommandHandler("skin", "Unlock skins of a character or all characters", "skin unlock=all")]
|
||||
public class SkinCommand : Command
|
||||
{
|
||||
[Argument("unlock")]
|
||||
public string? Unlock { get; set; }
|
||||
|
||||
public override void Execute(Dictionary<string, string> args, Connection connection)
|
||||
{
|
||||
base.Execute(args);
|
||||
|
||||
if (Unlock is not null)
|
||||
{
|
||||
if (Unlock.Equals("all", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
connection.player.ShipSkins = connection.player.Ships.SelectMany(x =>
|
||||
{
|
||||
ShipDataTemplate? template = Data.ShipDataTemplate.FirstOrDefault(y => y.Value.Id == x.TemplateId).Value;
|
||||
return Data.ShipSkinTemplate.Where(x => x.Value.ShipGroup == template.GroupType).Select(x => new Idtimeinfo() { Id = x.Value.Id });
|
||||
}).DistinctBy(x => x.Id).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
var shipId = Parse(Unlock, uint.MinValue);
|
||||
if (connection.player.Ships.Any(x => x.TemplateId == shipId))
|
||||
{
|
||||
ShipDataTemplate? template = Data.ShipDataTemplate.FirstOrDefault(y => y.Value.Id == shipId).Value;
|
||||
connection.player.ShipSkins.AddRange(Data.ShipSkinTemplate.Where(x => x.Value.ShipGroup == template.GroupType).Select(x => new Idtimeinfo() { Id = x.Value.Id }));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!Data.ShipSkinTemplate.Any(x => x.Value.ShipGroup == shipId))
|
||||
{
|
||||
connection.SendSystemMsg($"You don't own a ship with a template/group id of {shipId}");
|
||||
return;
|
||||
}
|
||||
|
||||
connection.player.ShipSkins.AddRange(Data.ShipSkinTemplate.Where(x => x.Value.ShipGroup == shipId).Select(x => new Idtimeinfo() { Id = x.Value.Id }));
|
||||
}
|
||||
}
|
||||
connection.NotifyShipSkinData();
|
||||
}
|
||||
|
||||
base.NotifySuccess(connection);
|
||||
DBManager.PlayerContext.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,16 +139,19 @@ namespace BLHX.Server.Game
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
foreach (var resourceField in player.ResourceFields)
|
||||
if (player is not null)
|
||||
{
|
||||
resourceField.CalculateYield();
|
||||
}
|
||||
foreach (var resourceField in player.ResourceFields)
|
||||
{
|
||||
resourceField.CalculateYield();
|
||||
}
|
||||
|
||||
DBManager.PlayerContext.Save();
|
||||
this.NotifyResourceList();
|
||||
DBManager.PlayerContext.Save();
|
||||
this.NotifyResourceList();
|
||||
#if DEBUG
|
||||
c.Log("Ticked!");
|
||||
c.Log("Ticked!");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public void InitClientData()
|
||||
@@ -172,6 +175,7 @@ namespace BLHX.Server.Game
|
||||
this.NotifyActivityData();
|
||||
this.NotifyDormData();
|
||||
this.NotifyNavalAcademy();
|
||||
this.NotifyWorldData();
|
||||
}
|
||||
|
||||
public void SendHttpResponse(string rsp, string type = "text/plain")
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace BLHX.Server.Game.Handlers
|
||||
connection.Send(rsp);
|
||||
}
|
||||
|
||||
[PacketHandler(Command.Cs10100)]
|
||||
[PacketHandler(Command.Cs10100, IsNotifyHandler = true)]
|
||||
static void HeartbeatHandler(Connection connection, Packet packet)
|
||||
{
|
||||
connection.Send(new Sc10101() { State = 1 });
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using BLHX.Server.Common.Proto;
|
||||
using BLHX.Server.Common.Data;
|
||||
using BLHX.Server.Common.Proto;
|
||||
using BLHX.Server.Common.Proto.common;
|
||||
using BLHX.Server.Common.Proto.p12;
|
||||
|
||||
namespace BLHX.Server.Game.Handlers
|
||||
@@ -18,6 +20,16 @@ namespace BLHX.Server.Game.Handlers
|
||||
|
||||
connection.Send(new Sc12103());
|
||||
}
|
||||
|
||||
[PacketHandler(Command.Cs12202, SaveDataAfterRun = true)]
|
||||
static void SetShipSkinHandler(Connection connection, Packet packet)
|
||||
{
|
||||
var req = packet.Decode<Cs12202>();
|
||||
if (connection.player.Ships.Any(x => x.Id == req.ShipId))
|
||||
connection.player.Ships.First(x => x.Id == req.ShipId).SkinId = req.SkinId;
|
||||
|
||||
connection.Send(new Sc12203());
|
||||
}
|
||||
}
|
||||
|
||||
static class P12ConnectionNotifyExtensions
|
||||
@@ -35,7 +47,7 @@ namespace BLHX.Server.Game.Handlers
|
||||
|
||||
public static void NotifyShipSkinData(this Connection connection)
|
||||
{
|
||||
connection.Send(new Sc12201());
|
||||
connection.Send(new Sc12201() { SkinLists = connection.player.ShipSkins });
|
||||
}
|
||||
|
||||
public static void NotifyFleetData(this Connection connection)
|
||||
|
||||
18
BLHX.Server.Game/Handlers/P33.cs
Normal file
18
BLHX.Server.Game/Handlers/P33.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using BLHX.Server.Common.Proto.p33;
|
||||
|
||||
namespace BLHX.Server.Game.Handlers
|
||||
{
|
||||
internal class P33
|
||||
{
|
||||
}
|
||||
static class P33ConnectionNotifyExtensions
|
||||
{
|
||||
public static void NotifyWorldData(this Connection connection)
|
||||
{
|
||||
connection.Send(new Sc33114()
|
||||
{
|
||||
IsWorldOpen = 1
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,5 +14,11 @@ namespace BLHX.Server.Game.Handlers
|
||||
MetaShipLists = req.GroupIds.Select(x => new MetaShipInfo() { GroupId = x }).ToList()
|
||||
});
|
||||
}
|
||||
|
||||
[PacketHandler(Command.Cs34501)]
|
||||
static void GetWorldBossHandler(Connection connection, Packet packet)
|
||||
{
|
||||
connection.Send(new Sc34502());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user