From 7d1a57c98494cdade3bbd9b7ece9e6d1ac516463 Mon Sep 17 00:00:00 2001 From: raphaeIl Date: Thu, 30 May 2024 12:46:17 +0800 Subject: [PATCH] MemoryLobby, Scenario, basic Account Profile --- .../ModelExtensions/AccountExtensions.cs | 22 + SCHALE.Common/Database/SCHALEContext.cs | 16 +- SCHALE.Common/Database/dbs.cs | 23 + ...42248_MemoryLobby_and_Scenario.Designer.cs | 597 ++++++++++++++++++ ...20240530042248_MemoryLobby_and_Scenario.cs | 76 +++ .../Migrations/SCHALEContextModelSnapshot.cs | 71 +++ .../Commands/InventoryCommand.cs | 4 + .../Api/ProtocolHandlers/Account.cs | 49 ++ .../Api/ProtocolHandlers/Scenario.cs | 53 +- SCHALE.GameServer/SCHALE.GameServer.csproj | 4 + SCHALE.GameServer/Utils/InventoryUtils.cs | 41 +- 11 files changed, 951 insertions(+), 5 deletions(-) create mode 100644 SCHALE.Common/Migrations/20240530042248_MemoryLobby_and_Scenario.Designer.cs create mode 100644 SCHALE.Common/Migrations/20240530042248_MemoryLobby_and_Scenario.cs diff --git a/SCHALE.Common/Database/ModelExtensions/AccountExtensions.cs b/SCHALE.Common/Database/ModelExtensions/AccountExtensions.cs index 450c252..0212b6b 100644 --- a/SCHALE.Common/Database/ModelExtensions/AccountExtensions.cs +++ b/SCHALE.Common/Database/ModelExtensions/AccountExtensions.cs @@ -76,5 +76,27 @@ return [.. echelons]; } + + public static List AddMemoryLobbies(this AccountDB account, SCHALEContext context, params MemoryLobbyDB[] memoryLobbies) + { + foreach (var lobby in memoryLobbies) + { + lobby.AccountServerId = account.ServerId; + context.MemoryLobbies.Add(lobby); + } + + return [.. memoryLobbies]; + } + + public static List AddScenarios(this AccountDB account, SCHALEContext context, params ScenarioHistoryDB[] scenarios) + { + foreach (var scenario in scenarios) + { + scenario.AccountServerId = account.ServerId; + context.Scenarios.Add(scenario); + } + + return [.. scenarios]; + } } } diff --git a/SCHALE.Common/Database/SCHALEContext.cs b/SCHALE.Common/Database/SCHALEContext.cs index 5983715..f6aff9e 100644 --- a/SCHALE.Common/Database/SCHALEContext.cs +++ b/SCHALE.Common/Database/SCHALEContext.cs @@ -17,11 +17,13 @@ namespace SCHALE.Common.Database public DbSet Equipment { get; set; } public DbSet Weapons { get; set; } public DbSet Gears { get; set; } + + public DbSet MemoryLobbies { get; set; } + public DbSet Scenarios { get; set; } public DbSet Echelons { get; set; } public DbSet AccountTutorials { get; set; } - public static SCHALEContext Create(string connectionString) => new(new DbContextOptionsBuilder() .UseSqlServer(connectionString) @@ -68,7 +70,17 @@ namespace SCHALE.Common.Database .WithOne(x => x.Account) .HasForeignKey(x => x.AccountServerId) .IsRequired(); - + modelBuilder.Entity() + .HasMany(x => x.MemoryLobbies) + .WithOne(x => x.Account) + .HasForeignKey(x => x.AccountServerId) + .IsRequired(); + modelBuilder.Entity() + .HasMany(x => x.Scenarios) + .WithOne(x => x.Account) + .HasForeignKey(x => x.AccountServerId) + .IsRequired(); + modelBuilder.Entity(x => x.Property(b => b.RaidInfo).HasJsonConversion()); modelBuilder.Entity().Property(x => x.ServerId).ValueGeneratedOnAdd(); modelBuilder.Entity().Property(x => x.ServerId).ValueGeneratedOnAdd(); diff --git a/SCHALE.Common/Database/dbs.cs b/SCHALE.Common/Database/dbs.cs index ac2e5a9..4294923 100644 --- a/SCHALE.Common/Database/dbs.cs +++ b/SCHALE.Common/Database/dbs.cs @@ -342,6 +342,12 @@ namespace SCHALE.Common.Database [JsonIgnore] public virtual ICollection Gears { get; } + [JsonIgnore] + public virtual ICollection MemoryLobbies { get; } + + [JsonIgnore] + public virtual ICollection Scenarios { get; } + [JsonIgnore] public virtual RaidInfo RaidInfo { get; set; } @@ -1733,10 +1739,19 @@ namespace SCHALE.Common.Database { public override ParcelType Type { get => ParcelType.MemoryLobby; } + [NotMapped] [JsonIgnore] public override IEnumerable ParcelInfos { get; } + [JsonIgnore] + public virtual AccountDB Account { get; set; } + + [JsonIgnore] public long AccountServerId { get; set; } + + [Key] + public long ServerId { get; set; } + public long MemoryLobbyUniqueId { get; set; } } @@ -2197,7 +2212,15 @@ namespace SCHALE.Common.Database public class ScenarioHistoryDB { + [JsonIgnore] + public virtual AccountDB Account { get; set; } + + [JsonIgnore] public long AccountServerId { get; set; } + + [Key] + public long ServerId { get; set; } + public long ScenarioUniqueId { get; set; } public DateTime ClearDateTime { get; set; } } diff --git a/SCHALE.Common/Migrations/20240530042248_MemoryLobby_and_Scenario.Designer.cs b/SCHALE.Common/Migrations/20240530042248_MemoryLobby_and_Scenario.Designer.cs new file mode 100644 index 0000000..4fd8785 --- /dev/null +++ b/SCHALE.Common/Migrations/20240530042248_MemoryLobby_and_Scenario.Designer.cs @@ -0,0 +1,597 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SCHALE.Common.Database; + +#nullable disable + +namespace SCHALE.Common.Migrations +{ + [DbContext(typeof(SCHALEContext))] + [Migration("20240530042248_MemoryLobby_and_Scenario")] + partial class MemoryLobby_and_Scenario + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.2") + .HasAnnotation("Proxies:ChangeTracking", false) + .HasAnnotation("Proxies:CheckEquality", false) + .HasAnnotation("Proxies:LazyLoading", true) + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("SCHALE.Common.Database.AccountDB", b => + { + b.Property("ServerId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ServerId")); + + b.Property("BirthDay") + .HasColumnType("datetime2"); + + b.Property("CallName") + .HasColumnType("nvarchar(max)"); + + b.Property("CallNameUpdateTime") + .HasColumnType("datetime2"); + + b.Property("Comment") + .HasColumnType("nvarchar(max)"); + + b.Property("CreateDate") + .HasColumnType("datetime2"); + + b.Property("DevId") + .HasColumnType("nvarchar(max)"); + + b.Property("Exp") + .HasColumnType("bigint"); + + b.Property("LastConnectTime") + .HasColumnType("datetime2"); + + b.Property("Level") + .HasColumnType("int"); + + b.Property("LinkRewardDate") + .HasColumnType("datetime2"); + + b.Property("LobbyMode") + .HasColumnType("int"); + + b.Property("MemoryLobbyUniqueId") + .HasColumnType("bigint"); + + b.Property("Nickname") + .HasColumnType("nvarchar(max)"); + + b.Property("PublisherAccountId") + .HasColumnType("bigint"); + + b.Property("RaidInfo") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("RepresentCharacterServerId") + .HasColumnType("int"); + + b.Property("RetentionDays") + .HasColumnType("int"); + + b.Property("State") + .HasColumnType("int"); + + b.Property("UnReadMailCount") + .HasColumnType("int"); + + b.Property("VIPLevel") + .HasColumnType("int"); + + b.HasKey("ServerId"); + + b.ToTable("Accounts"); + }); + + modelBuilder.Entity("SCHALE.Common.Database.CharacterDB", b => + { + b.Property("ServerId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ServerId")); + + b.Property("AccountServerId") + .HasColumnType("bigint"); + + b.Property("EquipmentServerIds") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("EquipmentSlotAndDBIds") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ExSkillLevel") + .HasColumnType("int"); + + b.Property("Exp") + .HasColumnType("bigint"); + + b.Property("ExtraPassiveSkillLevel") + .HasColumnType("int"); + + b.Property("FavorExp") + .HasColumnType("bigint"); + + b.Property("FavorRank") + .HasColumnType("int"); + + b.Property("IsFavorite") + .HasColumnType("bit"); + + b.Property("IsLocked") + .HasColumnType("bit"); + + b.Property("LeaderSkillLevel") + .HasColumnType("int"); + + b.Property("Level") + .HasColumnType("int"); + + b.Property("PassiveSkillLevel") + .HasColumnType("int"); + + b.Property("PotentialStats") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PublicSkillLevel") + .HasColumnType("int"); + + b.Property("StarGrade") + .HasColumnType("int"); + + b.Property("UniqueId") + .HasColumnType("bigint"); + + b.HasKey("ServerId"); + + b.HasIndex("AccountServerId"); + + b.ToTable("Characters"); + }); + + modelBuilder.Entity("SCHALE.Common.Database.EchelonDB", b => + { + b.Property("ServerId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ServerId")); + + b.Property("AccountServerId") + .HasColumnType("bigint"); + + b.Property("CombatStyleIndex") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("EchelonNumber") + .HasColumnType("bigint"); + + b.Property("EchelonType") + .HasColumnType("int"); + + b.Property("ExtensionType") + .HasColumnType("int"); + + b.Property("LeaderServerId") + .HasColumnType("bigint"); + + b.Property("MainSlotServerIds") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SkillCardMulliganCharacterIds") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SupportSlotServerIds") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TSSInteractionServerId") + .HasColumnType("bigint"); + + b.Property("UsingFlag") + .HasColumnType("int"); + + b.HasKey("ServerId"); + + b.HasIndex("AccountServerId"); + + b.ToTable("Echelons"); + }); + + modelBuilder.Entity("SCHALE.Common.Database.EquipmentDB", b => + { + b.Property("ServerId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ServerId")); + + b.Property("AccountServerId") + .HasColumnType("bigint"); + + b.Property("BoundCharacterServerId") + .HasColumnType("bigint"); + + b.Property("Exp") + .HasColumnType("bigint"); + + b.Property("IsLocked") + .HasColumnType("bit"); + + b.Property("Level") + .HasColumnType("int"); + + b.Property("StackCount") + .HasColumnType("bigint"); + + b.Property("Tier") + .HasColumnType("int"); + + b.Property("UniqueId") + .HasColumnType("bigint"); + + b.HasKey("ServerId"); + + b.HasIndex("AccountServerId"); + + b.ToTable("Equipment"); + }); + + modelBuilder.Entity("SCHALE.Common.Database.GearDB", b => + { + b.Property("ServerId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ServerId")); + + b.Property("AccountServerId") + .HasColumnType("bigint"); + + b.Property("BoundCharacterServerId") + .HasColumnType("bigint"); + + b.Property("Exp") + .HasColumnType("bigint"); + + b.Property("Level") + .HasColumnType("int"); + + b.Property("SlotIndex") + .HasColumnType("bigint"); + + b.Property("Tier") + .HasColumnType("int"); + + b.Property("UniqueId") + .HasColumnType("bigint"); + + b.HasKey("ServerId"); + + b.HasIndex("AccountServerId"); + + b.ToTable("Gears"); + }); + + modelBuilder.Entity("SCHALE.Common.Database.ItemDB", b => + { + b.Property("ServerId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ServerId")); + + b.Property("AccountServerId") + .HasColumnType("bigint"); + + b.Property("IsLocked") + .HasColumnType("bit"); + + b.Property("StackCount") + .HasColumnType("bigint"); + + b.Property("UniqueId") + .HasColumnType("bigint"); + + b.HasKey("ServerId"); + + b.HasIndex("AccountServerId"); + + b.ToTable("Items"); + }); + + modelBuilder.Entity("SCHALE.Common.Database.MemoryLobbyDB", b => + { + b.Property("ServerId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ServerId")); + + b.Property("AccountServerId") + .HasColumnType("bigint"); + + b.Property("MemoryLobbyUniqueId") + .HasColumnType("bigint"); + + b.HasKey("ServerId"); + + b.HasIndex("AccountServerId"); + + b.ToTable("MemoryLobbies"); + }); + + modelBuilder.Entity("SCHALE.Common.Database.MissionProgressDB", b => + { + b.Property("ServerId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ServerId")); + + b.Property("AccountServerId") + .HasColumnType("bigint"); + + b.Property("Complete") + .HasColumnType("bit"); + + b.Property("MissionUniqueId") + .HasColumnType("bigint"); + + b.Property("ProgressParameters") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("StartTime") + .HasColumnType("datetime2"); + + b.HasKey("ServerId"); + + b.HasIndex("AccountServerId"); + + b.ToTable("MissionProgresses"); + }); + + modelBuilder.Entity("SCHALE.Common.Database.Models.AccountTutorial", b => + { + b.Property("AccountServerId") + .HasColumnType("bigint"); + + b.Property("TutorialIds") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("AccountServerId"); + + b.ToTable("AccountTutorials"); + }); + + modelBuilder.Entity("SCHALE.Common.Database.Models.GuestAccount", b => + { + b.Property("Uid") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Uid")); + + b.Property("DeviceId") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Token") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Uid"); + + b.ToTable("GuestAccounts"); + }); + + modelBuilder.Entity("SCHALE.Common.Database.ScenarioHistoryDB", b => + { + b.Property("ServerId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ServerId")); + + b.Property("AccountServerId") + .HasColumnType("bigint"); + + b.Property("ClearDateTime") + .HasColumnType("datetime2"); + + b.Property("ScenarioUniqueId") + .HasColumnType("bigint"); + + b.HasKey("ServerId"); + + b.HasIndex("AccountServerId"); + + b.ToTable("Scenarios"); + }); + + modelBuilder.Entity("SCHALE.Common.Database.WeaponDB", b => + { + b.Property("ServerId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ServerId")); + + b.Property("AccountServerId") + .HasColumnType("bigint"); + + b.Property("BoundCharacterServerId") + .HasColumnType("bigint"); + + b.Property("Exp") + .HasColumnType("bigint"); + + b.Property("IsLocked") + .HasColumnType("bit"); + + b.Property("Level") + .HasColumnType("int"); + + b.Property("StarGrade") + .HasColumnType("int"); + + b.Property("UniqueId") + .HasColumnType("bigint"); + + b.HasKey("ServerId"); + + b.HasIndex("AccountServerId"); + + b.ToTable("Weapons"); + }); + + modelBuilder.Entity("SCHALE.Common.Database.CharacterDB", b => + { + b.HasOne("SCHALE.Common.Database.AccountDB", "Account") + .WithMany("Characters") + .HasForeignKey("AccountServerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + }); + + modelBuilder.Entity("SCHALE.Common.Database.EchelonDB", b => + { + b.HasOne("SCHALE.Common.Database.AccountDB", "Account") + .WithMany("Echelons") + .HasForeignKey("AccountServerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + }); + + modelBuilder.Entity("SCHALE.Common.Database.EquipmentDB", b => + { + b.HasOne("SCHALE.Common.Database.AccountDB", "Account") + .WithMany("Equipment") + .HasForeignKey("AccountServerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + }); + + modelBuilder.Entity("SCHALE.Common.Database.GearDB", b => + { + b.HasOne("SCHALE.Common.Database.AccountDB", "Account") + .WithMany("Gears") + .HasForeignKey("AccountServerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + }); + + modelBuilder.Entity("SCHALE.Common.Database.ItemDB", b => + { + b.HasOne("SCHALE.Common.Database.AccountDB", "Account") + .WithMany("Items") + .HasForeignKey("AccountServerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + }); + + modelBuilder.Entity("SCHALE.Common.Database.MemoryLobbyDB", b => + { + b.HasOne("SCHALE.Common.Database.AccountDB", "Account") + .WithMany("MemoryLobbies") + .HasForeignKey("AccountServerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + }); + + modelBuilder.Entity("SCHALE.Common.Database.MissionProgressDB", b => + { + b.HasOne("SCHALE.Common.Database.AccountDB", "Account") + .WithMany("MissionProgresses") + .HasForeignKey("AccountServerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + }); + + modelBuilder.Entity("SCHALE.Common.Database.ScenarioHistoryDB", b => + { + b.HasOne("SCHALE.Common.Database.AccountDB", "Account") + .WithMany("Scenarios") + .HasForeignKey("AccountServerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + }); + + modelBuilder.Entity("SCHALE.Common.Database.WeaponDB", b => + { + b.HasOne("SCHALE.Common.Database.AccountDB", "Account") + .WithMany("Weapons") + .HasForeignKey("AccountServerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + }); + + modelBuilder.Entity("SCHALE.Common.Database.AccountDB", b => + { + b.Navigation("Characters"); + + b.Navigation("Echelons"); + + b.Navigation("Equipment"); + + b.Navigation("Gears"); + + b.Navigation("Items"); + + b.Navigation("MemoryLobbies"); + + b.Navigation("MissionProgresses"); + + b.Navigation("Scenarios"); + + b.Navigation("Weapons"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SCHALE.Common/Migrations/20240530042248_MemoryLobby_and_Scenario.cs b/SCHALE.Common/Migrations/20240530042248_MemoryLobby_and_Scenario.cs new file mode 100644 index 0000000..ad454b7 --- /dev/null +++ b/SCHALE.Common/Migrations/20240530042248_MemoryLobby_and_Scenario.cs @@ -0,0 +1,76 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SCHALE.Common.Migrations +{ + /// + public partial class MemoryLobby_and_Scenario : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "MemoryLobbies", + columns: table => new + { + ServerId = table.Column(type: "bigint", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + AccountServerId = table.Column(type: "bigint", nullable: false), + MemoryLobbyUniqueId = table.Column(type: "bigint", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_MemoryLobbies", x => x.ServerId); + table.ForeignKey( + name: "FK_MemoryLobbies_Accounts_AccountServerId", + column: x => x.AccountServerId, + principalTable: "Accounts", + principalColumn: "ServerId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Scenarios", + columns: table => new + { + ServerId = table.Column(type: "bigint", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + AccountServerId = table.Column(type: "bigint", nullable: false), + ScenarioUniqueId = table.Column(type: "bigint", nullable: false), + ClearDateTime = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Scenarios", x => x.ServerId); + table.ForeignKey( + name: "FK_Scenarios_Accounts_AccountServerId", + column: x => x.AccountServerId, + principalTable: "Accounts", + principalColumn: "ServerId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_MemoryLobbies_AccountServerId", + table: "MemoryLobbies", + column: "AccountServerId"); + + migrationBuilder.CreateIndex( + name: "IX_Scenarios_AccountServerId", + table: "Scenarios", + column: "AccountServerId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "MemoryLobbies"); + + migrationBuilder.DropTable( + name: "Scenarios"); + } + } +} diff --git a/SCHALE.Common/Migrations/SCHALEContextModelSnapshot.cs b/SCHALE.Common/Migrations/SCHALEContextModelSnapshot.cs index c6f5f58..81ede21 100644 --- a/SCHALE.Common/Migrations/SCHALEContextModelSnapshot.cs +++ b/SCHALE.Common/Migrations/SCHALEContextModelSnapshot.cs @@ -322,6 +322,27 @@ namespace SCHALE.Common.Migrations b.ToTable("Items"); }); + modelBuilder.Entity("SCHALE.Common.Database.MemoryLobbyDB", b => + { + b.Property("ServerId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ServerId")); + + b.Property("AccountServerId") + .HasColumnType("bigint"); + + b.Property("MemoryLobbyUniqueId") + .HasColumnType("bigint"); + + b.HasKey("ServerId"); + + b.HasIndex("AccountServerId"); + + b.ToTable("MemoryLobbies"); + }); + modelBuilder.Entity("SCHALE.Common.Database.MissionProgressDB", b => { b.Property("ServerId") @@ -388,6 +409,30 @@ namespace SCHALE.Common.Migrations b.ToTable("GuestAccounts"); }); + modelBuilder.Entity("SCHALE.Common.Database.ScenarioHistoryDB", b => + { + b.Property("ServerId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ServerId")); + + b.Property("AccountServerId") + .HasColumnType("bigint"); + + b.Property("ClearDateTime") + .HasColumnType("datetime2"); + + b.Property("ScenarioUniqueId") + .HasColumnType("bigint"); + + b.HasKey("ServerId"); + + b.HasIndex("AccountServerId"); + + b.ToTable("Scenarios"); + }); + modelBuilder.Entity("SCHALE.Common.Database.WeaponDB", b => { b.Property("ServerId") @@ -479,6 +524,17 @@ namespace SCHALE.Common.Migrations b.Navigation("Account"); }); + modelBuilder.Entity("SCHALE.Common.Database.MemoryLobbyDB", b => + { + b.HasOne("SCHALE.Common.Database.AccountDB", "Account") + .WithMany("MemoryLobbies") + .HasForeignKey("AccountServerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + }); + modelBuilder.Entity("SCHALE.Common.Database.MissionProgressDB", b => { b.HasOne("SCHALE.Common.Database.AccountDB", "Account") @@ -490,6 +546,17 @@ namespace SCHALE.Common.Migrations b.Navigation("Account"); }); + modelBuilder.Entity("SCHALE.Common.Database.ScenarioHistoryDB", b => + { + b.HasOne("SCHALE.Common.Database.AccountDB", "Account") + .WithMany("Scenarios") + .HasForeignKey("AccountServerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + }); + modelBuilder.Entity("SCHALE.Common.Database.WeaponDB", b => { b.HasOne("SCHALE.Common.Database.AccountDB", "Account") @@ -513,8 +580,12 @@ namespace SCHALE.Common.Migrations b.Navigation("Items"); + b.Navigation("MemoryLobbies"); + b.Navigation("MissionProgresses"); + b.Navigation("Scenarios"); + b.Navigation("Weapons"); }); #pragma warning restore 612, 618 diff --git a/SCHALE.GameServer/Commands/InventoryCommand.cs b/SCHALE.GameServer/Commands/InventoryCommand.cs index e0592a5..4428368 100644 --- a/SCHALE.GameServer/Commands/InventoryCommand.cs +++ b/SCHALE.GameServer/Commands/InventoryCommand.cs @@ -26,6 +26,8 @@ namespace SCHALE.GameServer.Commands InventoryUtils.AddAllEquipment(connection); InventoryUtils.AddAllItems(connection); InventoryUtils.AddAllGears(connection); + InventoryUtils.AddAllMemoryLobbies(connection); + InventoryUtils.AddAllScenarios(connection); connection.SendChatMessage("Added Everything!"); break; @@ -36,6 +38,8 @@ namespace SCHALE.GameServer.Commands context.Equipment.RemoveRange(context.Equipment.Where(x => x.AccountServerId == connection.AccountServerId)); context.Items.RemoveRange(context.Items.Where(x => x.AccountServerId == connection.AccountServerId)); context.Gears.RemoveRange(context.Gears.Where(x => x.AccountServerId == connection.AccountServerId)); + context.MemoryLobbies.RemoveRange(context.MemoryLobbies.Where(x => x.AccountServerId == connection.AccountServerId)); + context.Scenarios.RemoveRange(context.Scenarios.Where(x => x.AccountServerId == connection.AccountServerId)); connection.SendChatMessage("Removed Everything!"); break; diff --git a/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Account.cs b/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Account.cs index e169066..c981da9 100644 --- a/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Account.cs +++ b/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Account.cs @@ -400,6 +400,12 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers { EchelonDBs = [.. account.Echelons] }, + + MemoryLobbyListResponse = new MemoryLobbyListResponse() + { + MemoryLobbyDBs = [.. account.MemoryLobbies] + }, + EventContentPermanentListResponse = new EventContentPermanentListResponse() { PermanentDBs = @@ -435,6 +441,11 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers AccountClanMemberDB = new() { AccountId = account.ServerId } }, + ScenarioListResponse = new ScenarioListResponse() + { + ScenarioHistoryDBs = [.. account.Scenarios] + }, + EliminateRaidLoginResponse = new EliminateRaidLoginResponse() { SeasonType = RaidSeasonType.Open, @@ -489,6 +500,24 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers return new AccountSetTutorialResponse(); } + + [ProtocolHandler(Protocol.Account_SetRepresentCharacterAndComment)] + public ResponsePacket SetRepresentCharacterAndCommentHandler(AccountSetRepresentCharacterAndCommentRequest req) + { + var account = sessionKeyService.GetAccount(req.SessionKey); + + account.RepresentCharacterServerId = req.RepresentCharacterServerId; + account.Comment = req.Comment; + + context.SaveChanges(); + + return new AccountSetRepresentCharacterAndCommentResponse() + { + AccountDB = account, + RepresentCharacterDB = account.Characters.FirstOrDefault(x => x.ServerId == req.RepresentCharacterServerId) + }; + } + // TODO: others handlers, move to different handler group later [ProtocolHandler(Protocol.NetworkTime_Sync)] public ResponsePacket NetworkTime_SyncHandler(NetworkTimeSyncRequest req) @@ -571,5 +600,25 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers { return new MiniGameMissionListResponse(); } + + [ProtocolHandler(Protocol.Attachment_EmblemAcquire)] + public ResponsePacket Attachment_EmblemAcquireHandler(AttachmentEmblemAcquireRequest req) + { + return new AttachmentEmblemAcquireResponse(); + } + + [ProtocolHandler(Protocol.Friend_List)] + public ResponsePacket Attachment_EmblemAcquireHandler(FriendListRequest req) + { + return new FriendListResponse(); + } + + [ProtocolHandler(Protocol.Friend_GetIdCard)] + public ResponsePacket Friend_GetIdCardHandler(FriendGetIdCardRequest req) + { + return new FriendGetIdCardResponse(); + } + + } } diff --git a/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Scenario.cs b/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Scenario.cs index 13a875c..7797b41 100644 --- a/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Scenario.cs +++ b/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Scenario.cs @@ -1,11 +1,23 @@ -using SCHALE.Common.NetworkProtocol; +using SCHALE.Common.Database; +using SCHALE.Common.Database.ModelExtensions; +using SCHALE.Common.NetworkProtocol; +using SCHALE.GameServer.Services; using Serilog; namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers { public class Scenario : ProtocolHandlerBase { - public Scenario(IProtocolHandlerFactory protocolHandlerFactory) : base(protocolHandlerFactory) { } + private readonly ISessionKeyService sessionKeyService; + private readonly SCHALEContext context; + private readonly ExcelTableService excelTableService; + + public Scenario(IProtocolHandlerFactory protocolHandlerFactory, ISessionKeyService _sessionKeyService, SCHALEContext _context, ExcelTableService _excelTableService) : base(protocolHandlerFactory) + { + sessionKeyService = _sessionKeyService; + context = _context; + excelTableService = _excelTableService; + } [ProtocolHandler(Protocol.Scenario_Skip)] public ResponsePacket SkipHandler(ScenarioSkipRequest req) @@ -24,5 +36,42 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers { return new ScenarioGroupHistoryUpdateResponse(); } + + [ProtocolHandler(Protocol.Scenario_LobbyStudentChange)] + public ResponsePacket LobbyStudentChangeHandler(ScenarioLobbyStudentChangeRequest req) + { + return new ScenarioLobbyStudentChangeResponse(); + } + + [ProtocolHandler(Protocol.Scenario_AccountStudentChange)] + public ResponsePacket AccountStudentChangeHandler(ScenarioAccountStudentChangeRequest req) + { + return new ScenarioAccountStudentChangeResponse(); + } + + [ProtocolHandler(Protocol.Scenario_Clear)] + public ResponsePacket ClearHandler(ScenarioClearRequest req) + { + var account = sessionKeyService.GetAccount(req.SessionKey); + + var scenario = account.Scenarios.FirstOrDefault(x => x.ScenarioUniqueId == req.ScenarioId); + + if (scenario == null) + { + scenario = new ScenarioHistoryDB() + { + ScenarioUniqueId = req.ScenarioId, + ClearDateTime = DateTime.UtcNow, + }; + + account.AddScenarios(context, [scenario]); + context.SaveChanges(); + } + + return new ScenarioClearResponse() + { + ScenarioHistoryDB = scenario + }; + } } } diff --git a/SCHALE.GameServer/SCHALE.GameServer.csproj b/SCHALE.GameServer/SCHALE.GameServer.csproj index d9be2df..d759da9 100644 --- a/SCHALE.GameServer/SCHALE.GameServer.csproj +++ b/SCHALE.GameServer/SCHALE.GameServer.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/SCHALE.GameServer/Utils/InventoryUtils.cs b/SCHALE.GameServer/Utils/InventoryUtils.cs index 3d4ef86..83c6ef4 100644 --- a/SCHALE.GameServer/Utils/InventoryUtils.cs +++ b/SCHALE.GameServer/Utils/InventoryUtils.cs @@ -56,7 +56,7 @@ namespace SCHALE.Common.Utils { IsNew = true, UniqueId = x.Id, - StackCount = 5555, + StackCount = 1000, }; }).ToList(); @@ -113,6 +113,45 @@ namespace SCHALE.Common.Utils connection.SendChatMessage("Added all gears!"); } + public static void AddAllMemoryLobbies(IrcConnection connection) + { + var account = connection.Account; + var context = connection.Context; + + var memoryLobbyExcel = connection.ExcelTableService.GetTable().UnPack().DataList; + var allMemoryLobbies = memoryLobbyExcel.Select(x => + { + return new MemoryLobbyDB() + { + MemoryLobbyUniqueId = x.Id, + }; + }).ToList(); + + account.AddMemoryLobbies(context, [.. allMemoryLobbies]); + context.SaveChanges(); + + connection.SendChatMessage("Added all Memory Lobbies!"); + } + + public static void AddAllScenarios(IrcConnection connection) + { + var account = connection.Account; + var context = connection.Context; + + var scenarioModeExcel = connection.ExcelTableService.GetTable().UnPack().DataList; + var allScenarios = scenarioModeExcel.Select(x => + { + return new ScenarioHistoryDB() + { + ScenarioUniqueId = x.ModeId, + }; + }).ToList(); + + account.AddScenarios(context, [.. allScenarios]); + context.SaveChanges(); + + connection.SendChatMessage("Added all Scenarios!"); + } public static void RemoveAllCharacters(IrcConnection connection) // removing default characters breaks game {