From 3046a7d20eb7ab40cda2923916f234994d2df638 Mon Sep 17 00:00:00 2001 From: rfi Date: Sun, 25 Feb 2024 22:22:59 +0700 Subject: [PATCH] dummy chapter handling + OpMove PoC --- .../Data/Model/ChapterTemplate.cs | 32 ++++- BLHX.Server.Common/Database/Player.cs | 30 +++++ BLHX.Server.Game/Handlers/P13.cs | 118 ++++++++++++++++-- 3 files changed, 171 insertions(+), 9 deletions(-) diff --git a/BLHX.Server.Common/Data/Model/ChapterTemplate.cs b/BLHX.Server.Common/Data/Model/ChapterTemplate.cs index aa3fe00..63c86d2 100644 --- a/BLHX.Server.Common/Data/Model/ChapterTemplate.cs +++ b/BLHX.Server.Common/Data/Model/ChapterTemplate.cs @@ -3,6 +3,34 @@ using System.Text.Json.Serialization; namespace BLHX.Server.Common.Data; +public enum ChapterAttachFlag +{ + AttachNone = 0, + AttachBorn = 1, + AttachBox = 2, + AttachSupply = 3, + AttachElite = 4, + AttachAmbush = 5, + AttachEnemy = 6, + AttachTorpedo_Enemy = 7, + AttachBoss = 8, + AttachStory = 9, + AttachAreaBoss = 11, + AttachChampion = 12, + AttachTorpedo_Fleet = 14, + AttachChampionPatrol = 15, + AttachBorn_Sub = 16, + AttachTransport = 17, + AttachTransport_Target = 18, + AttachChampionSub = 19, + AttachOni = 20, + AttachOni_Target = 21, + AttachBomb_Enemy = 24, + AttachBarrier = 25, + AttachHugeSupply = 26, + AttachLandbase = 100 +} + public class ChapterTemplate : Model { [JsonIgnore] @@ -10,7 +38,7 @@ public class ChapterTemplate : Model { get { - return Grids.Select(x => new GridItem() { Row = x[0].GetUInt32(), Column = x[1].GetUInt32(), Blocking = x[2].GetBoolean(), Flag = x[3].GetInt32() }).ToList(); + return Grids.Select(x => new GridItem() { Row = x[0].GetUInt32(), Column = x[1].GetUInt32(), Blocking = x[2].GetBoolean(), Flag = (ChapterAttachFlag)x[3].GetInt32() }).ToList(); } } @@ -219,5 +247,5 @@ public readonly struct GridItem public uint Row { get; init; } public uint Column { get; init; } public bool Blocking { get; init; } - public int Flag { get; init; } + public ChapterAttachFlag Flag { get; init; } } \ No newline at end of file diff --git a/BLHX.Server.Common/Database/Player.cs b/BLHX.Server.Common/Database/Player.cs index 719dc0c..7482980 100644 --- a/BLHX.Server.Common/Database/Player.cs +++ b/BLHX.Server.Common/Database/Player.cs @@ -477,5 +477,35 @@ namespace BLHX.Server.Common.Database Time = (uint)new DateTimeOffset(Time).ToUnixTimeSeconds() }; } + + public static ChapterInfo FromProto(Currentchapterinfo chapterInfo, uint uid) + { + return new() + { + Id = chapterInfo.Id, + AiLists = chapterInfo.AiLists, + BattleStatistics = chapterInfo.BattleStatistics, + BuffLists = chapterInfo.BuffLists, + CellFlagLists = chapterInfo.CellFlagLists, + CellLists = chapterInfo.CellLists, + ChapterHp = chapterInfo.ChapterHp, + ChapterStrategyLists = chapterInfo.ChapterStrategyLists, + ContinuousKillCount = chapterInfo.ContinuousKillCount, + EscortLists = chapterInfo.EscortLists, + ExtraFlagLists = chapterInfo.ExtraFlagLists, + FleetDuties = chapterInfo.FleetDuties, + GroupLists = chapterInfo.GroupLists, + InitShipCount = chapterInfo.InitShipCount, + IsSubmarineAutoAttack = Convert.ToBoolean(chapterInfo.IsSubmarineAutoAttack), + KillCount = chapterInfo.KillCount, + LoopFlag = chapterInfo.LoopFlag, + ModelActCount = chapterInfo.ModelActCount, + MoveStepCount = chapterInfo.MoveStepCount, + OperationBuffs = chapterInfo.OperationBuffs, + Round = chapterInfo.Round, + Time = DateTimeOffset.FromUnixTimeSeconds(chapterInfo.Time).DateTime, + PlayerUid = uid + }; + } } } diff --git a/BLHX.Server.Game/Handlers/P13.cs b/BLHX.Server.Game/Handlers/P13.cs index 71b92e0..6e9cb97 100644 --- a/BLHX.Server.Game/Handlers/P13.cs +++ b/BLHX.Server.Game/Handlers/P13.cs @@ -1,4 +1,5 @@ using BLHX.Server.Common.Data; +using BLHX.Server.Common.Database; using BLHX.Server.Common.Proto; using BLHX.Server.Common.Proto.p13; @@ -6,7 +7,7 @@ namespace BLHX.Server.Game.Handlers { internal static class P13 { - [PacketHandler(Command.Cs13101)] + [PacketHandler(Command.Cs13101, SaveDataAfterRun = true)] static void TrackingHandler(Connection connection, Packet packet) { var req = packet.Decode(); @@ -18,17 +19,100 @@ namespace BLHX.Server.Game.Handlers return; } - // TODO: Populate values, pls make managers + connection.player.DoResource(2, chapterTemplate.Oil * -1); + + var cells = chapterTemplate.GridItems.Select(x => + { + var cellInfo = new Chaptercellinfo() + { + Pos = new Chaptercellpos() { Column = x.Column, Row = x.Row } + }; + + if (x.Flag == ChapterAttachFlag.AttachEnemy) + { + cellInfo.ItemType = (uint)x.Flag; + cellInfo.ItemId = (uint)chapterTemplate.ExpeditionIdWeightList[Random.Shared.Next(chapterTemplate.ExpeditionIdWeightList.Length)][0]; + } + + if (x.Flag == ChapterAttachFlag.AttachBoss && chapterTemplate.BossRefresh == 0) + { + cellInfo.ItemType = (uint)x.Flag; + cellInfo.ItemId = (uint)chapterTemplate.BossExpeditionId[Random.Shared.Next(chapterTemplate.BossExpeditionId.Length)]; + } + + return cellInfo; + }).ToList(); + var born = chapterTemplate.GridItems.Find(x => x.Flag == ChapterAttachFlag.AttachBorn); + var chapter = new Currentchapterinfo() + { + Id = req.Id, + Time = (uint)new DateTimeOffset(DateTime.Now.AddSeconds(chapterTemplate.Time)).ToUnixTimeSeconds(), + CellLists = cells, + GroupLists = req.GroupIdLists.Select(x => + { + var fleet = connection.player.Fleets.Find(y => y.Id == x); + + return new Groupinchapter() + { + Id = x, + ShipLists = fleet?.ShipLists.Select(x => new Shipinchapter() { Id = x, HpRant = 10000 }).ToList(), + Pos = new Chaptercellpos() { Column = born.Column, Row = born.Row }, + Bullet = 5, + StartPos = new(), + FleetId = x + }; + }).ToList(), + IsSubmarineAutoAttack = 1, + InitShipCount = (uint)connection.player.Fleets.Where(x => req.GroupIdLists.Contains(x.Id)).Sum(x => x.ShipLists.Count) + }; + + if (connection.player.ChapterInfoes.Any(x => x.Id == chapter.Id)) + { + connection.player.ChapterInfoes.Remove(connection.player.ChapterInfoes.First(x => x.Id == chapter.Id)); + } + connection.player.ChapterInfoes.Add(ChapterInfo.FromProto(chapter, connection.player.Uid)); + connection.player.CurrentChapter = chapter.Id; + connection.Send(new Sc13102() { - CurrentChapter = new() - { - Id = req.Id, - Time = (uint)(DateTimeOffset.Now.ToUnixTimeSeconds() + chapterTemplate.Time) - } + CurrentChapter = chapter }); } + [PacketHandler(Command.Cs13103)] + static void ChapterOPHandler(Connection connection, Packet packet) + { + var req = packet.Decode(); + var rsp = new Sc13104(); + + switch ((ChapterOP)req.Act) + { + case ChapterOP.OpMove: + rsp.MovePaths.Add(new() { Row = req.ActArg1, Column = req.ActArg2 }); + break; + case ChapterOP.OpRetreat: + case ChapterOP.OpBox: + case ChapterOP.OpAmbush: + case ChapterOP.OpStrategy: + case ChapterOP.OpRepair: + case ChapterOP.OpSupply: + case ChapterOP.OpEnemyRound: + case ChapterOP.OpSubState: + case ChapterOP.OpStory: + case ChapterOP.OpBarrier: + case ChapterOP.OpSubTeleport: + case ChapterOP.OpPreClear: + case ChapterOP.OpRequest: + case ChapterOP.OpSwitch: + case ChapterOP.OpSkipBattle: + rsp.Result = 1; + connection.Send(rsp); + throw new NotImplementedException($"{nameof(Cs13103)}, {JSON.Stringify(req)}"); + } + + connection.Send(rsp); + } + [PacketHandler(Command.Cs13505)] static void RemasterInfoRequestHandler(Connection connection, Packet packet) { @@ -43,4 +127,24 @@ namespace BLHX.Server.Game.Handlers connection.Send(new Sc13001() { ReactChapter = new() }); } } + + enum ChapterOP + { + OpRetreat = 0, + OpMove = 1, + OpBox = 2, + OpAmbush = 4, + OpStrategy = 5, + OpRepair = 6, + OpSupply = 7, + OpEnemyRound = 8, + OpSubState = 9, + OpStory = 10, + OpBarrier = 16, + OpSubTeleport = 19, + OpPreClear = 30, + OpRequest = 49, + OpSwitch = 98, + OpSkipBattle = 99 + } }