diff --git a/BLHX.Server.Common/Data/Data.cs b/BLHX.Server.Common/Data/Data.cs index 89eaa62..f700e59 100644 --- a/BLHX.Server.Common/Data/Data.cs +++ b/BLHX.Server.Common/Data/Data.cs @@ -31,6 +31,9 @@ public static class Data [LoadData("task_data_template.json", LoadDataType.ShareCfgData)] public static Dictionary TaskDataTemplate { get; private set; } = null!; + [LoadData("item_data_statistics.json", LoadDataType.ShareCfgData)] + public static Dictionary ItemDataStatistics { get; private set; } = null!; + public static void Load() { foreach (var prop in typeof(Data).GetProperties().Where(x => x.GetCustomAttribute() is not null)) diff --git a/BLHX.Server.Common/Data/Model/ItemDataStatistics.cs b/BLHX.Server.Common/Data/Model/ItemDataStatistics.cs new file mode 100644 index 0000000..adee440 --- /dev/null +++ b/BLHX.Server.Common/Data/Model/ItemDataStatistics.cs @@ -0,0 +1,86 @@ +using System.Text.Json.Serialization; + +namespace BLHX.Server.Common.Data; + +public class ItemDataStatistics : Model { + [JsonPropertyName("combination_display")] + public int[] CombinationDisplay { get; set; } // Empty array implies List + + [JsonPropertyName("compose_number")] + public int ComposeNumber { get; set; } + + [JsonPropertyName("display")] + public string Display { get; set; } + + [JsonPropertyName("display_effect")] + public string DisplayEffect { get; set; } + + [JsonPropertyName("display_icon")] + public object DisplayIcon { get; set; } + + [JsonPropertyName("icon")] + public string Icon { get; set; } + + [JsonPropertyName("id")] + public int Id { get; set; } + + [JsonPropertyName("index")] + public int[] Index { get; set; } // Assuming empty array + + [JsonPropertyName("is_world")] + public int IsWorld { get; set; } + + [JsonPropertyName("limit")] + public string Limit { get; set; } + + [JsonPropertyName("link_id")] + public int LinkId { get; set; } + + [JsonPropertyName("max_num")] + public int MaxNum { get; set; } + + [JsonPropertyName("name")] + public string Name { get; set; } + + [JsonPropertyName("open_directly")] + public int OpenDirectly { get; set; } + + [JsonPropertyName("order")] + public int Order { get; set; } + + [JsonPropertyName("other_item_cost")] + public string OtherItemCost { get; set; } + + [JsonPropertyName("other_resource_cost")] + public string OtherResourceCost { get; set; } + + [JsonPropertyName("price")] + public object Price { get; set; } + + [JsonPropertyName("rarity")] + public int Rarity { get; set; } + + [JsonPropertyName("replace_item")] + public int ReplaceItem { get; set; } + + [JsonPropertyName("shiptrans_id")] + public int[] ShiptransId { get; set; } // Assuming empty array + + [JsonPropertyName("target_id")] + public int TargetId { get; set; } + + [JsonPropertyName("time_limit")] + public int TimeLimit { get; set; } + + [JsonPropertyName("type")] + public int Type { get; set; } + + [JsonPropertyName("usage")] + public string Usage { get; set; } + + [JsonPropertyName("usage_arg")] + public object UsageArg { get; set; } + + [JsonPropertyName("virtual_type")] + public int VirtualType { get; set; } +} diff --git a/BLHX.Server.Game/BLHX.Server.Game.csproj b/BLHX.Server.Game/BLHX.Server.Game.csproj index 0342417..fefcd06 100644 --- a/BLHX.Server.Game/BLHX.Server.Game.csproj +++ b/BLHX.Server.Game/BLHX.Server.Game.csproj @@ -10,4 +10,8 @@ + + + + diff --git a/BLHX.Server.Game/Commands/ItemCommand.cs b/BLHX.Server.Game/Commands/ItemCommand.cs index 058edfb..f05345c 100644 --- a/BLHX.Server.Game/Commands/ItemCommand.cs +++ b/BLHX.Server.Game/Commands/ItemCommand.cs @@ -16,38 +16,44 @@ namespace BLHX.Server.Game.Commands { public override void Execute(Dictionary args, Connection connection) { base.Execute(args); - uint amount = 1; + //uint amount = 1; - if (Amount is not null) { - uint.TryParse(Amount, out uint parsedAmount); - amount = parsedAmount; - } + //if (Amount is not null) { + // uint.TryParse(Amount, out uint parsedAmount); + // amount = parsedAmount; + //} - if (Unlock is not null) { - if (Unlock.Equals("all", StringComparison.CurrentCultureIgnoreCase)) { - // ... - } else if (uint.TryParse(Unlock, out uint itemId)) { - //connection.player.DoResource(itemId, amount); - PlayerResource? item = DBManager.PlayerContext.Resources.Where(res => res.Id == itemId).FirstOrDefault(); + //if (Unlock is not null) { + // if (Unlock.Equals("all", StringComparison.CurrentCultureIgnoreCase)) { + // // ... + // } else if (uint.TryParse(Unlock, out uint itemId)) { + // //connection.player.DoResource(itemId, amount); + // PlayerResource? item = DBManager.PlayerContext.Resources.Where(res => res.Id == itemId).FirstOrDefault(); - if (item is null) { - DBManager.PlayerContext.Resources.Add(new PlayerResource() { Id = itemId, PlayerUid = connection.player.Uid, Num = 1 }); - //connection.player.DoResource(itemId, 1); + // if (item is null) { + // DBManager.PlayerContext.Resources.Add(new PlayerResource() { Id = itemId, PlayerUid = connection.player.Uid, Num = 1 }); + // //connection.player.DoResource(itemId, 1); - //item = DBManager.PlayerContext.Resources.Where(res => res.Id == itemId).FirstOrDefault(); - } else { - item.Num += amount; - connection.SendSystemMsg($"{amount} item of itemid: {itemId} added!"); - } + // //item = DBManager.PlayerContext.Resources.Where(res => res.Id == itemId).FirstOrDefault(); + // } else { + // item.Num += amount; + // connection.SendSystemMsg($"{amount} item of itemid: {itemId} added!"); + // } + + + // } else { + // connection.SendSystemMsg($"Invalid ItemId: {itemId}"); + // } + //} + + connection.player.DoResource(1, 938493849); + connection.player.DoResource(4, 39843294); - } else { - connection.SendSystemMsg($"Invalid ItemId: {itemId}"); - } - } DBManager.PlayerContext.Save(); connection.NotifyPlayerData(); + connection.NotifyBagData(); base.NotifySuccess(connection); } } diff --git a/BLHX.Server.Game/Commands/ShipCommand.cs b/BLHX.Server.Game/Commands/ShipCommand.cs index 00d993c..19e0aeb 100644 --- a/BLHX.Server.Game/Commands/ShipCommand.cs +++ b/BLHX.Server.Game/Commands/ShipCommand.cs @@ -31,7 +31,7 @@ namespace BLHX.Server.Game.Commands { all_ship_ids = Data.ShipDataStatistics.Where(ship_data => all_ship_ids.Contains(ship_data.Key) && ship_data.Value.Rarity == rarity).ToDictionary().Keys.ToList(); } - List all_ships = all_ship_ids.Select(ship_id => CreateShipFromId((uint)ship_id, connection.player.Uid)).Take(amount).ToList(); + List all_ships = all_ship_ids.Select(ship_id => CreateShipFromId((uint)ship_id, connection.player.Uid)).ToList(); all_ships.AddRange(GetDefaultShips(connection.player.Ships)); // add the defaults connection.player.Ships = all_ships; diff --git a/BLHX.Server.Game/Handlers/P12.cs b/BLHX.Server.Game/Handlers/P12.cs index ef2d81d..bb9c81a 100644 --- a/BLHX.Server.Game/Handlers/P12.cs +++ b/BLHX.Server.Game/Handlers/P12.cs @@ -1,13 +1,12 @@ using BLHX.Server.Common.Proto; using BLHX.Server.Common.Proto.p12; +using BLHX.Server.Common.Utils; +using BLHX.Server.Common.Proto.common; -namespace BLHX.Server.Game.Handlers -{ - internal static class P12 - { +namespace BLHX.Server.Game.Handlers { + internal static class P12 { [PacketHandler(Command.Cs12102, SaveDataAfterRun = true)] - static void UpdateFleetHandler(Connection connection, Packet packet) - { + static void UpdateFleetHandler(Connection connection, Packet packet) { var fleet = packet.Decode(); var toUpdate = connection.player.Fleets.Find(x => x.Id == fleet.Id); @@ -20,47 +19,63 @@ namespace BLHX.Server.Game.Handlers } [PacketHandler(Command.Cs12202, SaveDataAfterRun = true)] - static void SetShipSkinHandler(Connection connection, Packet packet) - { + static void SetShipSkinHandler(Connection connection, Packet packet) { var req = packet.Decode(); 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()); } + + [PacketHandler(Command.Cs12002, SaveDataAfterRun = true)] + static void UseResourceHandler(Connection connection, Packet packet) { + var req = packet.Decode(); + + Logger.c.Log("Id: " + req.Id); + Logger.c.Log("Cost Type: " + req.Costtype); + Logger.c.Log("Count: " + req.Count); + + + + connection.Send(new Sc12003() { + BuildInfoes = [ + new Buildinfo() { BuildId = req.Id, FinishTime = 0, Time = 0 }, + ] + }); + } + + [PacketHandler(Command.Cs12008, SaveDataAfterRun = true)] + static void FinishAllBuildHandler(Connection connection, Packet packet) { + var req = packet.Decode(); + + connection.Send(new Sc12009() { PosLists = req.PosLists }); + } + } - static class P12ConnectionNotifyExtensions - { - public static void NotifyShipData(this Connection connection) - { - if (connection.player is not null) - { - connection.Send(new Sc12001() - { + static class P12ConnectionNotifyExtensions { + public static void NotifyShipData(this Connection connection) { + if (connection.player is not null) { + connection.Send(new Sc12001() { Shiplists = connection.player.Ships.Select(x => x.ToProto()).ToList() }); } } - public static void NotifyShipSkinData(this Connection connection) - { + public static void NotifyShipSkinData(this Connection connection) { connection.Send(new Sc12201() { SkinLists = connection.player.ShipSkins }); } - public static void NotifyFleetData(this Connection connection) - { - if (connection.player is not null) - { - connection.Send(new Sc12101() - { + public static void NotifyFleetData(this Connection connection) { + if (connection.player is not null) { + connection.Send(new Sc12101() { GroupLists = connection.player.Fleets }); } + } - public static void NotifyBuildShipData(this Connection connection) - { + public static void NotifyBuildShipData(this Connection connection) { connection.Send(new Sc12024()); } } diff --git a/BLHX.Server.Game/Handlers/P15.cs b/BLHX.Server.Game/Handlers/P15.cs index 84a39bb..72e6e81 100644 --- a/BLHX.Server.Game/Handlers/P15.cs +++ b/BLHX.Server.Game/Handlers/P15.cs @@ -1,24 +1,28 @@ using BLHX.Server.Common.Proto.p15; +using BLHX.Server.Common.Data; +using BLHX.Server.Common.Utils; -namespace BLHX.Server.Game.Handlers -{ - internal static class P15 - { +namespace BLHX.Server.Game.Handlers { + internal static class P15 { } - static class P15ConnectionNotifyExtensions - { - public static void NotifyBagData(this Connection connection) - { - connection.Send(new Sc15001() - { - ItemLists = [ - new Iteminfo() { Id = 20001, Count = 5 }, - new Iteminfo() { Id = 15003, Count = 10 }, - new Iteminfo() { Id = 50002, Count = 10 }, - new Iteminfo() { Id = 50001, Count = 10 } - ] - }); + static class P15ConnectionNotifyExtensions { + public static void NotifyBagData(this Connection connection) { + //List AllItemsKeys = Data.ItemDataStatistics.Where(data => data.Value.Type == 2 && data.Value.Rarity >= 6).ToDictionary().Keys.ToList(); + List AllItemsKeys = Data.ItemDataStatistics.ToDictionary().Keys.ToList(); + List ItemLists = AllItemsKeys.Select(item_id => new Iteminfo { Id = (uint)item_id, Count = 3954783433 }).ToList(); + + connection.Send(new Sc15001() { ItemLists = ItemLists }); + + //connection.Send(new Sc15001() { + // ItemLists = [ + // new Iteminfo() { Id = 20001, Count = 8394785 }, + // new Iteminfo() { Id = 15003, Count = 10 }, + // new Iteminfo() { Id = 50002, Count = 10 }, + // new Iteminfo() { Id = 50001, Count = 10 } + // ] + //}); + } } }