From 67dfd45b1eb0a23b030c3a78927ab6c2cd748ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=82ngelo=20Tadeucci?= Date: Thu, 6 Mar 2025 04:01:53 -0300 Subject: [PATCH 1/4] Fix: Cube Portals --- .../Field/FieldManager/FieldManager.cs | 24 ++----------------- .../Field/FieldManager/HomeFieldManager.cs | 18 +++++++++++++- .../Containers/ChannelClientLookup.cs | 4 ++++ 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs b/Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs index e6d6327e3..0b0a3f694 100644 --- a/Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs +++ b/Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs @@ -120,7 +120,7 @@ public virtual void Init() { FieldInstance = new FieldInstance(blockChangeChannel: true, instanceField.Type, instanceField.InstanceId); } - if (ugcMetadata.Plots.Count > 0) { + if (ugcMetadata.Plots.Count > 0 && this is not HomeFieldManager) { using GameStorage.Request db = GameStorage.Context(); foreach (Plot plot in db.LoadPlotsForMap(MapId)) { Plots[plot.Number] = plot; @@ -134,24 +134,6 @@ public virtual void Init() { SpawnPortal(portal); } - if (MapId is Constant.DefaultHomeMapId) { - List cubePortals = Plots.FirstOrDefault().Value.Cubes.Values - .Where(x => x.Interact?.PortalSettings is not null) - .ToList(); - - foreach (PlotCube cubePortal in cubePortals) { - SpawnCubePortal(cubePortal); - } - - List lifeSkillCubes = Plots.FirstOrDefault().Value.Cubes.Values - .Where(x => x.HousingCategory is HousingCategory.Ranching or HousingCategory.Farming) - .ToList(); - - foreach (PlotCube cube in lifeSkillCubes) { - AddFieldFunctionInteract(cube); - } - } - foreach ((Guid guid, BreakableActor breakable) in Entities.BreakableActors) { AddBreakable(guid.ToString("N"), breakable); } @@ -427,9 +409,7 @@ public bool UsePortal(GameSession session, int portalId, string password) { session.Player.MoveToPosition(destinationCube.Position, default); return true; case CubePortalDestination.SelectedMap: - session.Send(session.PrepareField(srcPortal.TargetMapId, portalId: srcPortal.TargetPortalId) - ? FieldEnterPacket.Request(session.Player) - : FieldEnterPacket.Error(MigrationError.s_move_err_default)); + session.MigrateOutOfInstance(srcPortal.TargetMapId); return true; case CubePortalDestination.FriendHome: { using GameStorage.Request db = session.GameStorage.Context(); diff --git a/Maple2.Server.Game/Manager/Field/FieldManager/HomeFieldManager.cs b/Maple2.Server.Game/Manager/Field/FieldManager/HomeFieldManager.cs index 61651a85d..bf97a02eb 100644 --- a/Maple2.Server.Game/Manager/Field/FieldManager/HomeFieldManager.cs +++ b/Maple2.Server.Game/Manager/Field/FieldManager/HomeFieldManager.cs @@ -1,4 +1,5 @@ using Maple2.Database.Storage; +using Maple2.Model.Enum; using Maple2.Model.Game; using Maple2.Model.Metadata; @@ -22,8 +23,23 @@ public override void Init() { foreach (Plot plot in db.LoadPlotsForMap(MapId, OwnerId)) { Plots[plot.Number] = plot; } - } + List cubePortals = Plots.FirstOrDefault().Value.Cubes.Values + .Where(x => x.Interact?.PortalSettings is not null) + .ToList(); + + foreach (PlotCube cubePortal in cubePortals) { + SpawnCubePortal(cubePortal); + } + + List lifeSkillCubes = Plots.FirstOrDefault().Value.Cubes.Values + .Where(x => x.HousingCategory is HousingCategory.Ranching or HousingCategory.Farming) + .ToList(); + + foreach (PlotCube cube in lifeSkillCubes) { + AddFieldFunctionInteract(cube); + } + } public void SetHomeSurvey(HomeSurvey survey) { HomeSurvey = survey; diff --git a/Maple2.Server.World/Containers/ChannelClientLookup.cs b/Maple2.Server.World/Containers/ChannelClientLookup.cs index 2a2c3daad..8e0f73e92 100644 --- a/Maple2.Server.World/Containers/ChannelClientLookup.cs +++ b/Maple2.Server.World/Containers/ChannelClientLookup.cs @@ -179,7 +179,9 @@ private async Task MonitorChannel(Channel channel, CancellationTokenSource cance if (channel.Status is ChannelStatus.Active) { logger.Information("Channel {Channel} has become inactive due to {Status}", channel.Id, response.Status); channel.Status = ChannelStatus.Inactive; +#if !DEBUG await cancellationTokenSource.CancelAsync(); +#endif } break; } @@ -189,7 +191,9 @@ private async Task MonitorChannel(Channel channel, CancellationTokenSource cance } if (channel.Status is ChannelStatus.Active) { logger.Information("Channel {Channel} has become inactive", channel.Id); +#if !DEBUG await cancellationTokenSource.CancelAsync(); +#endif } channel.Status = ChannelStatus.Inactive; } From 3c977fe45dd6a34fb67b1daecd77808d91025c56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=82ngelo=20Tadeucci?= Date: Thu, 6 Mar 2025 15:03:27 -0300 Subject: [PATCH 2/4] revert --- .../Manager/Field/FieldManager/FieldManager.cs | 18 +++++++++++++++++- .../Field/FieldManager/HomeFieldManager.cs | 17 ----------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs b/Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs index 0b0a3f694..b8ed7b5e1 100644 --- a/Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs +++ b/Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs @@ -120,7 +120,7 @@ public virtual void Init() { FieldInstance = new FieldInstance(blockChangeChannel: true, instanceField.Type, instanceField.InstanceId); } - if (ugcMetadata.Plots.Count > 0 && this is not HomeFieldManager) { + if (ugcMetadata.Plots.Count > 0) { using GameStorage.Request db = GameStorage.Context(); foreach (Plot plot in db.LoadPlotsForMap(MapId)) { Plots[plot.Number] = plot; @@ -134,6 +134,22 @@ public virtual void Init() { SpawnPortal(portal); } + List cubePortals = Plots.FirstOrDefault().Value.Cubes.Values + .Where(x => x.Interact?.PortalSettings is not null) + .ToList(); + + foreach (PlotCube cubePortal in cubePortals) { + SpawnCubePortal(cubePortal); + } + + List lifeSkillCubes = Plots.FirstOrDefault().Value.Cubes.Values + .Where(x => x.HousingCategory is HousingCategory.Ranching or HousingCategory.Farming) + .ToList(); + + foreach (PlotCube cube in lifeSkillCubes) { + AddFieldFunctionInteract(cube); + } + foreach ((Guid guid, BreakableActor breakable) in Entities.BreakableActors) { AddBreakable(guid.ToString("N"), breakable); } diff --git a/Maple2.Server.Game/Manager/Field/FieldManager/HomeFieldManager.cs b/Maple2.Server.Game/Manager/Field/FieldManager/HomeFieldManager.cs index bf97a02eb..6a12891f8 100644 --- a/Maple2.Server.Game/Manager/Field/FieldManager/HomeFieldManager.cs +++ b/Maple2.Server.Game/Manager/Field/FieldManager/HomeFieldManager.cs @@ -1,5 +1,4 @@ using Maple2.Database.Storage; -using Maple2.Model.Enum; using Maple2.Model.Game; using Maple2.Model.Metadata; @@ -23,22 +22,6 @@ public override void Init() { foreach (Plot plot in db.LoadPlotsForMap(MapId, OwnerId)) { Plots[plot.Number] = plot; } - - List cubePortals = Plots.FirstOrDefault().Value.Cubes.Values - .Where(x => x.Interact?.PortalSettings is not null) - .ToList(); - - foreach (PlotCube cubePortal in cubePortals) { - SpawnCubePortal(cubePortal); - } - - List lifeSkillCubes = Plots.FirstOrDefault().Value.Cubes.Values - .Where(x => x.HousingCategory is HousingCategory.Ranching or HousingCategory.Farming) - .ToList(); - - foreach (PlotCube cube in lifeSkillCubes) { - AddFieldFunctionInteract(cube); - } } public void SetHomeSurvey(HomeSurvey survey) { From 047ae8d74408c546e7773d795d0e415baa029865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=82ngelo=20Tadeucci?= Date: Thu, 6 Mar 2025 15:04:32 -0300 Subject: [PATCH 3/4] Update FieldManager.cs --- .../Field/FieldManager/FieldManager.cs | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs b/Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs index b8ed7b5e1..16ea00be4 100644 --- a/Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs +++ b/Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs @@ -134,20 +134,22 @@ public virtual void Init() { SpawnPortal(portal); } - List cubePortals = Plots.FirstOrDefault().Value.Cubes.Values - .Where(x => x.Interact?.PortalSettings is not null) - .ToList(); + if (MapId is Constant.DefaultHomeMapId) { + List cubePortals = Plots.FirstOrDefault().Value.Cubes.Values + .Where(x => x.Interact?.PortalSettings is not null) + .ToList(); - foreach (PlotCube cubePortal in cubePortals) { - SpawnCubePortal(cubePortal); - } + foreach (PlotCube cubePortal in cubePortals) { + SpawnCubePortal(cubePortal); + } - List lifeSkillCubes = Plots.FirstOrDefault().Value.Cubes.Values - .Where(x => x.HousingCategory is HousingCategory.Ranching or HousingCategory.Farming) - .ToList(); + List lifeSkillCubes = Plots.FirstOrDefault().Value.Cubes.Values + .Where(x => x.HousingCategory is HousingCategory.Ranching or HousingCategory.Farming) + .ToList(); - foreach (PlotCube cube in lifeSkillCubes) { - AddFieldFunctionInteract(cube); + foreach (PlotCube cube in lifeSkillCubes) { + AddFieldFunctionInteract(cube); + } } foreach ((Guid guid, BreakableActor breakable) in Entities.BreakableActors) { @@ -428,16 +430,16 @@ public bool UsePortal(GameSession session, int portalId, string password) { session.MigrateOutOfInstance(srcPortal.TargetMapId); return true; case CubePortalDestination.FriendHome: { - using GameStorage.Request db = session.GameStorage.Context(); - Home? home = db.GetHome(fieldPortal.HomeId); - if (home is null) { - session.Send(FieldEnterPacket.Error(MigrationError.s_move_err_no_server)); - return false; - } - - session.MigrateToInstance(home.Indoor.MapId, home.Indoor.OwnerId); - return true; + using GameStorage.Request db = session.GameStorage.Context(); + Home? home = db.GetHome(fieldPortal.HomeId); + if (home is null) { + session.Send(FieldEnterPacket.Error(MigrationError.s_move_err_no_server)); + return false; } + + session.MigrateToInstance(home.Indoor.MapId, home.Indoor.OwnerId); + return true; + } } return false; case PortalType.LeaveDungeon: From fb1b20ac16554aeebd20d3af872bbdafba9bc3cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=82ngelo=20Tadeucci?= Date: Thu, 6 Mar 2025 15:08:27 -0300 Subject: [PATCH 4/4] format --- .../Manager/Field/FieldManager/FieldManager.cs | 18 +++++++++--------- .../20250304061437_InteractCubeFix.cs | 12 ++++-------- .../Migrations/20250306005429_DungeonInfo.cs | 18 ++++++------------ 3 files changed, 19 insertions(+), 29 deletions(-) diff --git a/Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs b/Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs index 16ea00be4..de50067fa 100644 --- a/Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs +++ b/Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs @@ -430,16 +430,16 @@ public bool UsePortal(GameSession session, int portalId, string password) { session.MigrateOutOfInstance(srcPortal.TargetMapId); return true; case CubePortalDestination.FriendHome: { - using GameStorage.Request db = session.GameStorage.Context(); - Home? home = db.GetHome(fieldPortal.HomeId); - if (home is null) { - session.Send(FieldEnterPacket.Error(MigrationError.s_move_err_no_server)); - return false; + using GameStorage.Request db = session.GameStorage.Context(); + Home? home = db.GetHome(fieldPortal.HomeId); + if (home is null) { + session.Send(FieldEnterPacket.Error(MigrationError.s_move_err_no_server)); + return false; + } + + session.MigrateToInstance(home.Indoor.MapId, home.Indoor.OwnerId); + return true; } - - session.MigrateToInstance(home.Indoor.MapId, home.Indoor.OwnerId); - return true; - } } return false; case PortalType.LeaveDungeon: diff --git a/Maple2.Server.World/Migrations/20250304061437_InteractCubeFix.cs b/Maple2.Server.World/Migrations/20250304061437_InteractCubeFix.cs index b7fcc5c4f..7cfa98f82 100644 --- a/Maple2.Server.World/Migrations/20250304061437_InteractCubeFix.cs +++ b/Maple2.Server.World/Migrations/20250304061437_InteractCubeFix.cs @@ -2,21 +2,17 @@ #nullable disable -namespace Maple2.Server.World.Migrations -{ +namespace Maple2.Server.World.Migrations { /// - public partial class InteractCubeFix : Migration - { + public partial class InteractCubeFix : Migration { /// - protected override void Up(MigrationBuilder migrationBuilder) - { + protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.Sql("DELETE FROM `game-server`.`ugcmap-cube` WHERE `Interact` IS NOT NULL AND `Interact` <> '';"); migrationBuilder.Sql("DELETE FROM `game-server`.`home-layout-cube` WHERE `Interact` IS NOT NULL AND `Interact` <> '';"); } /// - protected override void Down(MigrationBuilder migrationBuilder) - { + protected override void Down(MigrationBuilder migrationBuilder) { } } diff --git a/Maple2.Server.World/Migrations/20250306005429_DungeonInfo.cs b/Maple2.Server.World/Migrations/20250306005429_DungeonInfo.cs index 4ac0b6868..513fa4502 100644 --- a/Maple2.Server.World/Migrations/20250306005429_DungeonInfo.cs +++ b/Maple2.Server.World/Migrations/20250306005429_DungeonInfo.cs @@ -3,14 +3,11 @@ #nullable disable -namespace Maple2.Server.World.Migrations -{ +namespace Maple2.Server.World.Migrations { /// - public partial class DungeonInfo : Migration - { + public partial class DungeonInfo : Migration { /// - protected override void Up(MigrationBuilder migrationBuilder) - { + protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "DungeonRankRewards", table: "character-unlock", @@ -20,8 +17,7 @@ protected override void Up(MigrationBuilder migrationBuilder) migrationBuilder.CreateTable( name: "dungeon-record", - columns: table => new - { + columns: table => new { DungeonId = table.Column(type: "int", nullable: false), OwnerId = table.Column(type: "bigint", nullable: false), ClearTime = table.Column(type: "datetime(6)", nullable: false), @@ -35,8 +31,7 @@ protected override void Up(MigrationBuilder migrationBuilder) DailyResetTime = table.Column(type: "datetime(6)", nullable: false), WeeklyResetTime = table.Column(type: "datetime(6)", nullable: false) }, - constraints: table => - { + constraints: table => { table.PrimaryKey("PK_dungeon-record", x => new { x.OwnerId, x.DungeonId }); table.ForeignKey( name: "FK_dungeon-record_character_OwnerId", @@ -49,8 +44,7 @@ protected override void Up(MigrationBuilder migrationBuilder) } /// - protected override void Down(MigrationBuilder migrationBuilder) - { + protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "dungeon-record");