From e69b192c2ccb59c86d8c64cb95dd8d02c65a91cf Mon Sep 17 00:00:00 2001 From: raphaeIl Date: Sat, 9 Nov 2024 04:11:59 -0500 Subject: [PATCH] Implement Basic Cafe, Furniture & Cafe Command --- .../ModelExtensions/AccountExtensions.cs | 24 + SCHALE.Common/Database/SCHALEContext.cs | 21 + SCHALE.Common/Database/dbs.cs | 46 +- ...241108220342_CafeAndFurnitures.Designer.cs | 713 ++++++++++++++++++ .../20241108220342_CafeAndFurnitures.cs | 90 +++ .../SCHALEContextModelSnapshot.cs | 118 ++- SCHALE.GameServer/Commands/CafeCommand.cs | 110 +++ .../Api/ProtocolHandlers/Account.cs | 249 +++--- .../Controllers/Api/ProtocolHandlers/Cafe.cs | 83 ++ 9 files changed, 1285 insertions(+), 169 deletions(-) create mode 100644 SCHALE.Common/Migrations/SqlServerMigrations/20241108220342_CafeAndFurnitures.Designer.cs create mode 100644 SCHALE.Common/Migrations/SqlServerMigrations/20241108220342_CafeAndFurnitures.cs create mode 100644 SCHALE.GameServer/Commands/CafeCommand.cs create mode 100644 SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Cafe.cs diff --git a/SCHALE.Common/Database/ModelExtensions/AccountExtensions.cs b/SCHALE.Common/Database/ModelExtensions/AccountExtensions.cs index 8d940a9..b7e2ed8 100644 --- a/SCHALE.Common/Database/ModelExtensions/AccountExtensions.cs +++ b/SCHALE.Common/Database/ModelExtensions/AccountExtensions.cs @@ -108,5 +108,29 @@ return [.. scenarios]; } + + public static List AddCafes(this AccountDB account, SCHALEContext context, params CafeDB[] cafes) + { + foreach (var cafe in cafes) + { + cafe.AccountServerId = account.ServerId; + context.Cafes.Add(cafe); + } + + return [.. cafes]; + } + + public static List AddFurnitures(this AccountDB account, SCHALEContext context, params FurnitureDB[] furnitures) + { + foreach (var furniture in furnitures) + { + furniture.AccountServerId = account.ServerId; + context.Furnitures.Add(furniture); + } + + return [.. furnitures]; + } + + } } diff --git a/SCHALE.Common/Database/SCHALEContext.cs b/SCHALE.Common/Database/SCHALEContext.cs index 8b13cef..42a9746 100644 --- a/SCHALE.Common/Database/SCHALEContext.cs +++ b/SCHALE.Common/Database/SCHALEContext.cs @@ -24,6 +24,9 @@ namespace SCHALE.Common.Database public DbSet Echelons { get; set; } public DbSet AccountTutorials { get; set; } + public DbSet Cafes { get; set; } + public DbSet Furnitures { get; set; } + public static SCHALEContext Create(string connectionString) => new(new DbContextOptionsBuilder() .UseSqlServer(connectionString) @@ -84,6 +87,16 @@ namespace SCHALE.Common.Database .WithOne(x => x.Account) .HasForeignKey(x => x.AccountServerId) .IsRequired(); + modelBuilder.Entity() + .HasMany(x => x.Cafes) + .WithOne(x => x.Account) + .HasForeignKey(x => x.AccountServerId) + .IsRequired(); + modelBuilder.Entity() + .HasMany(x => x.Furnitures) + .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(); @@ -93,6 +106,14 @@ namespace SCHALE.Common.Database modelBuilder.Entity().Property(x => x.ServerId).ValueGeneratedOnAdd(); + modelBuilder.Entity().Property(x => x.CafeDBId).ValueGeneratedOnAdd(); + + modelBuilder.Entity().Property(x => x.CafeVisitCharacterDBs).HasJsonConversion(); + modelBuilder.Entity().Property(x => x.CurrencyDict_Obsolete).HasJsonConversion(); + modelBuilder.Entity().Property(x => x.UpdateTimeDict_Obsolete).HasJsonConversion(); + + modelBuilder.Entity().Property(x => x.ServerId).ValueGeneratedOnAdd(); + modelBuilder.Entity().Property(x => x.ServerId).ValueGeneratedOnAdd(); modelBuilder.Entity().Property(x => x.EquipmentSlotAndDBIds).HasJsonConversion(); modelBuilder.Entity().Property(x => x.PotentialStats).HasJsonConversion(); diff --git a/SCHALE.Common/Database/dbs.cs b/SCHALE.Common/Database/dbs.cs index 64390a9..532338a 100644 --- a/SCHALE.Common/Database/dbs.cs +++ b/SCHALE.Common/Database/dbs.cs @@ -349,6 +349,13 @@ namespace SCHALE.Common.Database [JsonIgnore] public virtual ICollection Scenarios { get; } + [JsonIgnore] + public virtual ICollection Cafes { get; } + + [JsonIgnore] + public virtual ICollection Furnitures { get; } + + [JsonIgnore] public virtual RaidInfo RaidInfo { get; set; } @@ -362,6 +369,8 @@ namespace SCHALE.Common.Database Gears = new List(); MemoryLobbies = new List(); Scenarios = new List(); + Cafes = new List(); + Furnitures = new List(); } public AccountDB(long publisherAccountId) : this() @@ -605,8 +614,17 @@ namespace SCHALE.Common.Database public class CafeDB { + [JsonIgnore] + public virtual AccountDB Account { get; set; } + + [JsonIgnore] + public long AccountServerId { get; set; } + + [Key] public long CafeDBId { get; set; } + public long CafeId { get; set; } + public long AccountId { get; set; } public int CafeRank { get; set; } public DateTime LastUpdate { get; set; } @@ -615,11 +633,30 @@ namespace SCHALE.Common.Database [NotMapped] public bool IsNew { get; set; } public Dictionary CafeVisitCharacterDBs { get; set; } - public List FurnitureDBs { get; set; } + public DateTime ProductionAppliedTime { get; set; } - public CafeProductionDB ProductionDB { get; set; } - public Dictionary CurrencyDict_Obsolete { get; set; } - public Dictionary UpdateTimeDict_Obsolete { get; set; } + + + [NotMapped] + public List FurnitureDBs { get => Account.Furnitures.Where(x => x.CafeDBId == CafeDBId).ToList(); } + + // TODO: fix this, probably needs another db for this, and link in OnModelCreate + [NotMapped] + public CafeProductionDB ProductionDB + { + get => new() + { + CafeDBId = 1, + AppliedDate = DateTime.UtcNow, + ProductionParcelInfos = [ + new() { Key = { Type = ParcelType.Currency, Id = 1 } }, // id 1 + new() { Key = { Type = ParcelType.Currency, Id = 5 } } + ], + }; + } + + public Dictionary CurrencyDict_Obsolete { get; set; } = new Dictionary(); + public Dictionary UpdateTimeDict_Obsolete { get; set; } = new Dictionary(); } public class CafeProductionParcelInfo @@ -1579,6 +1616,7 @@ namespace SCHALE.Common.Database { public override ParcelType Type { get => ParcelType.Furniture; } + [NotMapped] [JsonIgnore] public override IEnumerable ParcelInfos { get; } diff --git a/SCHALE.Common/Migrations/SqlServerMigrations/20241108220342_CafeAndFurnitures.Designer.cs b/SCHALE.Common/Migrations/SqlServerMigrations/20241108220342_CafeAndFurnitures.Designer.cs new file mode 100644 index 0000000..0363ec2 --- /dev/null +++ b/SCHALE.Common/Migrations/SqlServerMigrations/20241108220342_CafeAndFurnitures.Designer.cs @@ -0,0 +1,713 @@ +// +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.SqlServerMigrations +{ + [DbContext(typeof(SCHALEContext))] + [Migration("20241108220342_CafeAndFurnitures")] + partial class CafeAndFurnitures + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.6") + .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.CafeDB", b => + { + b.Property("CafeDBId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("CafeDBId")); + + b.Property("AccountId") + .HasColumnType("bigint"); + + b.Property("AccountServerId") + .HasColumnType("bigint"); + + b.Property("CafeId") + .HasColumnType("bigint"); + + b.Property("CafeRank") + .HasColumnType("int"); + + b.Property("CafeVisitCharacterDBs") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CurrencyDict_Obsolete") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("LastSummonDate") + .HasColumnType("datetime2"); + + b.Property("LastUpdate") + .HasColumnType("datetime2"); + + b.Property("ProductionAppliedTime") + .HasColumnType("datetime2"); + + b.Property("UpdateTimeDict_Obsolete") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("CafeDBId"); + + b.HasIndex("AccountServerId"); + + b.ToTable("Cafes"); + }); + + 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.FurnitureDB", b => + { + b.Property("ServerId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ServerId")); + + b.Property("AccountServerId") + .HasColumnType("bigint"); + + b.Property("CafeDBId") + .HasColumnType("bigint"); + + b.Property("ItemDeploySequence") + .HasColumnType("bigint"); + + b.Property("Location") + .HasColumnType("int"); + + b.Property("PositionX") + .HasColumnType("real"); + + b.Property("PositionY") + .HasColumnType("real"); + + b.Property("Rotation") + .HasColumnType("real"); + + b.Property("StackCount") + .HasColumnType("bigint"); + + b.Property("UniqueId") + .HasColumnType("bigint"); + + b.HasKey("ServerId"); + + b.HasIndex("AccountServerId"); + + b.ToTable("Furnitures"); + }); + + 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.CafeDB", b => + { + b.HasOne("SCHALE.Common.Database.AccountDB", "Account") + .WithMany("Cafes") + .HasForeignKey("AccountServerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + }); + + 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.FurnitureDB", b => + { + b.HasOne("SCHALE.Common.Database.AccountDB", "Account") + .WithMany("Furnitures") + .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("Cafes"); + + b.Navigation("Characters"); + + b.Navigation("Echelons"); + + b.Navigation("Equipment"); + + b.Navigation("Furnitures"); + + 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/SqlServerMigrations/20241108220342_CafeAndFurnitures.cs b/SCHALE.Common/Migrations/SqlServerMigrations/20241108220342_CafeAndFurnitures.cs new file mode 100644 index 0000000..de2dfa1 --- /dev/null +++ b/SCHALE.Common/Migrations/SqlServerMigrations/20241108220342_CafeAndFurnitures.cs @@ -0,0 +1,90 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SCHALE.Common.Migrations.SqlServerMigrations +{ + /// + public partial class CafeAndFurnitures : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Cafes", + columns: table => new + { + CafeDBId = table.Column(type: "bigint", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + AccountServerId = table.Column(type: "bigint", nullable: false), + CafeId = table.Column(type: "bigint", nullable: false), + AccountId = table.Column(type: "bigint", nullable: false), + CafeRank = table.Column(type: "int", nullable: false), + LastUpdate = table.Column(type: "datetime2", nullable: false), + LastSummonDate = table.Column(type: "datetime2", nullable: true), + CafeVisitCharacterDBs = table.Column(type: "nvarchar(max)", nullable: false), + ProductionAppliedTime = table.Column(type: "datetime2", nullable: false), + CurrencyDict_Obsolete = table.Column(type: "nvarchar(max)", nullable: false), + UpdateTimeDict_Obsolete = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Cafes", x => x.CafeDBId); + table.ForeignKey( + name: "FK_Cafes_Accounts_AccountServerId", + column: x => x.AccountServerId, + principalTable: "Accounts", + principalColumn: "ServerId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Furnitures", + columns: table => new + { + ServerId = table.Column(type: "bigint", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Location = table.Column(type: "int", nullable: false), + CafeDBId = table.Column(type: "bigint", nullable: false), + PositionX = table.Column(type: "real", nullable: false), + PositionY = table.Column(type: "real", nullable: false), + Rotation = table.Column(type: "real", nullable: false), + ItemDeploySequence = table.Column(type: "bigint", nullable: false), + AccountServerId = table.Column(type: "bigint", nullable: false), + UniqueId = table.Column(type: "bigint", nullable: false), + StackCount = table.Column(type: "bigint", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Furnitures", x => x.ServerId); + table.ForeignKey( + name: "FK_Furnitures_Accounts_AccountServerId", + column: x => x.AccountServerId, + principalTable: "Accounts", + principalColumn: "ServerId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Cafes_AccountServerId", + table: "Cafes", + column: "AccountServerId"); + + migrationBuilder.CreateIndex( + name: "IX_Furnitures_AccountServerId", + table: "Furnitures", + column: "AccountServerId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Cafes"); + + migrationBuilder.DropTable( + name: "Furnitures"); + } + } +} diff --git a/SCHALE.Common/Migrations/SqlServerMigrations/SCHALEContextModelSnapshot.cs b/SCHALE.Common/Migrations/SqlServerMigrations/SCHALEContextModelSnapshot.cs index c3741a4..b6efea5 100644 --- a/SCHALE.Common/Migrations/SqlServerMigrations/SCHALEContextModelSnapshot.cs +++ b/SCHALE.Common/Migrations/SqlServerMigrations/SCHALEContextModelSnapshot.cs @@ -17,7 +17,7 @@ namespace SCHALE.Common.Migrations.SqlServerMigrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "8.0.2") + .HasAnnotation("ProductVersion", "8.0.6") .HasAnnotation("Proxies:ChangeTracking", false) .HasAnnotation("Proxies:CheckEquality", false) .HasAnnotation("Proxies:LazyLoading", true) @@ -99,6 +99,54 @@ namespace SCHALE.Common.Migrations.SqlServerMigrations b.ToTable("Accounts"); }); + modelBuilder.Entity("SCHALE.Common.Database.CafeDB", b => + { + b.Property("CafeDBId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("CafeDBId")); + + b.Property("AccountId") + .HasColumnType("bigint"); + + b.Property("AccountServerId") + .HasColumnType("bigint"); + + b.Property("CafeId") + .HasColumnType("bigint"); + + b.Property("CafeRank") + .HasColumnType("int"); + + b.Property("CafeVisitCharacterDBs") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CurrencyDict_Obsolete") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("LastSummonDate") + .HasColumnType("datetime2"); + + b.Property("LastUpdate") + .HasColumnType("datetime2"); + + b.Property("ProductionAppliedTime") + .HasColumnType("datetime2"); + + b.Property("UpdateTimeDict_Obsolete") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("CafeDBId"); + + b.HasIndex("AccountServerId"); + + b.ToTable("Cafes"); + }); + modelBuilder.Entity("SCHALE.Common.Database.CharacterDB", b => { b.Property("ServerId") @@ -259,6 +307,48 @@ namespace SCHALE.Common.Migrations.SqlServerMigrations b.ToTable("Equipment"); }); + modelBuilder.Entity("SCHALE.Common.Database.FurnitureDB", b => + { + b.Property("ServerId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ServerId")); + + b.Property("AccountServerId") + .HasColumnType("bigint"); + + b.Property("CafeDBId") + .HasColumnType("bigint"); + + b.Property("ItemDeploySequence") + .HasColumnType("bigint"); + + b.Property("Location") + .HasColumnType("int"); + + b.Property("PositionX") + .HasColumnType("real"); + + b.Property("PositionY") + .HasColumnType("real"); + + b.Property("Rotation") + .HasColumnType("real"); + + b.Property("StackCount") + .HasColumnType("bigint"); + + b.Property("UniqueId") + .HasColumnType("bigint"); + + b.HasKey("ServerId"); + + b.HasIndex("AccountServerId"); + + b.ToTable("Furnitures"); + }); + modelBuilder.Entity("SCHALE.Common.Database.GearDB", b => { b.Property("ServerId") @@ -469,6 +559,17 @@ namespace SCHALE.Common.Migrations.SqlServerMigrations b.ToTable("Weapons"); }); + modelBuilder.Entity("SCHALE.Common.Database.CafeDB", b => + { + b.HasOne("SCHALE.Common.Database.AccountDB", "Account") + .WithMany("Cafes") + .HasForeignKey("AccountServerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + }); + modelBuilder.Entity("SCHALE.Common.Database.CharacterDB", b => { b.HasOne("SCHALE.Common.Database.AccountDB", "Account") @@ -502,6 +603,17 @@ namespace SCHALE.Common.Migrations.SqlServerMigrations b.Navigation("Account"); }); + modelBuilder.Entity("SCHALE.Common.Database.FurnitureDB", b => + { + b.HasOne("SCHALE.Common.Database.AccountDB", "Account") + .WithMany("Furnitures") + .HasForeignKey("AccountServerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + }); + modelBuilder.Entity("SCHALE.Common.Database.GearDB", b => { b.HasOne("SCHALE.Common.Database.AccountDB", "Account") @@ -570,12 +682,16 @@ namespace SCHALE.Common.Migrations.SqlServerMigrations modelBuilder.Entity("SCHALE.Common.Database.AccountDB", b => { + b.Navigation("Cafes"); + b.Navigation("Characters"); b.Navigation("Echelons"); b.Navigation("Equipment"); + b.Navigation("Furnitures"); + b.Navigation("Gears"); b.Navigation("Items"); diff --git a/SCHALE.GameServer/Commands/CafeCommand.cs b/SCHALE.GameServer/Commands/CafeCommand.cs new file mode 100644 index 0000000..c2d7c10 --- /dev/null +++ b/SCHALE.GameServer/Commands/CafeCommand.cs @@ -0,0 +1,110 @@ +using SCHALE.Common.Database; +using SCHALE.Common.Database.ModelExtensions; +using SCHALE.Common.FlatData; +using SCHALE.Common.Utils; +using SCHALE.GameServer.Controllers.Api.ProtocolHandlers; +using SCHALE.GameServer.Services; +using SCHALE.GameServer.Services.Irc; + +namespace SCHALE.GameServer.Commands +{ + [CommandHandler("cafe", "Command to manage the cafe", "/cafe [id/amount]")] + internal class CafeCommand : Command + { + + // /cafe character add 123 + // /cafe character addall + // /cafe character removeall + + public CafeCommand(IrcConnection connection, string[] args, bool validate = true) : base(connection, args, validate) { } + + [Argument(0, @"^character$|^furniture$", "The target type", ArgumentFlags.IgnoreCase)] + public string Type { get; set; } = string.Empty; + + [Argument(1, @"^add$|^addall$|^removeall$", "The operation selected (add, addall, removeall)", ArgumentFlags.IgnoreCase)] + public string Op { get; set; } = string.Empty; + + [Argument(2, @"^[0-9]+$", "The target character id / the add amount for addall", ArgumentFlags.Optional)] + public string Target { get; set; } = string.Empty; + + public override void Execute() + { + var context = connection.Context; + var targetCafe = connection.Account.Cafes.FirstOrDefault(); + + switch (Type.ToLower()) + { + case "character": + { + switch (Op.ToLower()) + { + case "add": + { + if (uint.TryParse(Target, out uint characterId)) + { + if (!targetCafe.CafeVisitCharacterDBs.ContainsKey(characterId)) + { + targetCafe.CafeVisitCharacterDBs.Add(characterId, new CafeCharacterDB() { UniqueId = characterId }); + + connection.SendChatMessage($"Character {characterId} added to your cafe!"); + } + else + { + connection.SendChatMessage("That character is already in the cafe, skipped."); + } + } else + { + connection.SendChatMessage($"Invalid character id"); + } + + break; + } + + + case "addall": + { + int amount = 50; + + if (int.TryParse(Target, out int targetAmount)) + { + amount = targetAmount; + } + + var characterExcel = connection.ExcelTableService.GetTable().UnPack().DataList; + + var allCharacters = characterExcel.Where(x => + x is + { + IsPlayable: true, + IsPlayableCharacter: true, + IsNpc: false, + ProductionStep: ProductionStep.Release, + } + ).Select(x => x.Id).ToList(); + + var cafeVisitCharacterDBs = allCharacters.Take(amount).ToDictionary(id => id, id => new CafeCharacterDB { UniqueId = id }); + + targetCafe.CafeVisitCharacterDBs = cafeVisitCharacterDBs; + connection.SendChatMessage($"Added {amount} characters to your cafe!"); + + break; + } + + + case "removeall": + { + targetCafe.CafeVisitCharacterDBs = new Dictionary(); + + connection.SendChatMessage("Removed all characters from your cafe!"); + break; + } + } + + break; + } + } + + context.SaveChanges(); + } + } +} diff --git a/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Account.cs b/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Account.cs index d642aec..db0176e 100644 --- a/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Account.cs +++ b/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Account.cs @@ -3,6 +3,8 @@ using SCHALE.Common.Database.ModelExtensions; using SCHALE.Common.FlatData; using SCHALE.Common.NetworkProtocol; using SCHALE.GameServer.Services; +using Serilog; +using System.Globalization; using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers @@ -255,6 +257,27 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers } context.SaveChanges(); + // Default cafe + CafeDB defaultCafe = new CafeDB() + { + CafeId = 1, + CafeRank = 1, + AccountId = account.ServerId, + LastUpdate = DateTime.UtcNow, + LastSummonDate = DateTime.UtcNow, + IsNew = true, + CafeVisitCharacterDBs = GetRandomCharactersId(5).ToDictionary(id => id, id => new CafeCharacterDB { UniqueId = id, ServerId = id }), + ProductionAppliedTime = DateTime.UtcNow, + //ProductionDB = + }; + + var defaultFurnitures = GetDefaultFurnitures(1); + + account.AddCafes(context, [defaultCafe]); + account.AddFurnitures(context, [.. defaultFurnitures]); + + context.SaveChanges(); + return new AccountCreateResponse() { SessionKey = sessionKeyService.Create(account.PublisherAccountId) @@ -282,63 +305,8 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers { CafeGetInfoResponse = new CafeGetInfoResponse() { - CafeDBs = [ - new CafeDB() { - CafeDBId = 3091193, - CafeId = 1, - AccountId = 1, - CafeRank = 1, - LastUpdate = DateTime.Parse("2024-04-21T07: 29: 57"), - LastSummonDate = DateTime.Parse("0001-01-01T00: 00: 00"), - IsNew = true, - CafeVisitCharacterDBs = new Dictionary() - { - { 26008, new CafeCharacterDB() { UniqueId = 26008 } }, - { 10005, new CafeCharacterDB() { UniqueId = 10005 } }, - { 13004, new CafeCharacterDB() { UniqueId = 13004 } }, - { 10058, new CafeCharacterDB() { UniqueId = 10058 } }, - }, - - FurnitureDBs = [ - new() { Location = Common.FlatData.FurnitureLocation.Floor, CafeDBId = 3091193, ItemDeploySequence = 368862451, ServerId = 368862451, UniqueId = 1, StackCount = 1}, - new() { Location = Common.FlatData.FurnitureLocation.WallRight, CafeDBId = 3091193, ItemDeploySequence = 368862452, ServerId = 368862452, UniqueId = 2, StackCount = 1}, - new() { Location = Common.FlatData.FurnitureLocation.WallLeft, CafeDBId = 3091193, ItemDeploySequence = 368862453, ServerId = 368862453, UniqueId = 3, StackCount = 1}, - new() { Location = Common.FlatData.FurnitureLocation.WallRight, CafeDBId = 3091193, PositionX = 8.5f, PositionY = 3.0f, ItemDeploySequence = 368862454, ServerId = 368862454, UniqueId = 4, StackCount = 1}, - new() { Location = Common.FlatData.FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 3.0f, PositionY = 1.5f, Rotation = 270.0f, ItemDeploySequence = 368862455, ServerId = 368862455, UniqueId = 5, StackCount = 1}, - new() { Location = Common.FlatData.FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 7.5f, PositionY = 8.5f, ItemDeploySequence = 368862456, ServerId = 368862456, UniqueId = 6, StackCount = 1}, - new() { Location = Common.FlatData.FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 7.5f, PositionY = 6.5f, ItemDeploySequence = 368862457, ServerId = 368862457, UniqueId = 7, StackCount = 1}, - new() { Location = Common.FlatData.FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 9.5f, PositionY = 8.5f, ItemDeploySequence = 368862458, ServerId = 368862458, UniqueId = 8, StackCount = 1}, - new() { Location = Common.FlatData.FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 4.5f, PositionY = 0.5f, ItemDeploySequence = 368862459, ServerId = 368862459, UniqueId = 9, StackCount = 1}, - new() { Location = Common.FlatData.FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 7.5f, PositionY = 8.5f, ItemDeploySequence = 368862460, ServerId = 368862460, UniqueId = 10, StackCount = 1}, - new() { Location = Common.FlatData.FurnitureLocation.WallLeft, CafeDBId = 3091193, PositionX = 7.5f, PositionY = 3.0f, ItemDeploySequence = 368862461, ServerId = 368862461, UniqueId = 11, StackCount = 1} - ], - - ProductionAppliedTime = DateTime.Parse("2024-04-21T07: 29: 50"), - - ProductionDB = new () { - CafeDBId = 3091193, - AppliedDate = DateTime.Parse("2024-04-21T07: 29: 50"), - ProductionParcelInfos = [ - new() { Key = { Type = ParcelType.Currency, Id = 1 } }, - new() { Key = { Type = ParcelType.Currency, Id = 5 } } - ], - } - }, - ], - - FurnitureDBs = [ - new() { Location = FurnitureLocation.Floor, CafeDBId = 3091193, ItemDeploySequence = 368862451, ServerId = 368862451, UniqueId = 1, StackCount = 1}, - new() { Location = FurnitureLocation.WallRight, CafeDBId = 3091193, ItemDeploySequence = 368862452, ServerId = 368862452, UniqueId = 2, StackCount = 1}, - new() { Location = FurnitureLocation.WallLeft, CafeDBId = 3091193, ItemDeploySequence = 368862453, ServerId = 368862453, UniqueId = 3, StackCount = 1}, - new() { Location = FurnitureLocation.WallRight, CafeDBId = 3091193, PositionX = 8.5f, PositionY = 3.0f, ItemDeploySequence = 368862454, ServerId = 368862454, UniqueId = 4, StackCount = 1}, - new() { Location = FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 3.0f, PositionY = 1.5f, Rotation = 270.0f, ItemDeploySequence = 368862455, ServerId = 368862455, UniqueId = 5, StackCount = 1}, - new() { Location = FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 7.5f, PositionY = 8.5f, ItemDeploySequence = 368862456, ServerId = 368862456, UniqueId = 6, StackCount = 1}, - new() { Location = FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 7.5f, PositionY = 6.5f, ItemDeploySequence = 368862457, ServerId = 368862457, UniqueId = 7, StackCount = 1}, - new() { Location = FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 9.5f, PositionY = 8.5f, ItemDeploySequence = 368862458, ServerId = 368862458, UniqueId = 8, StackCount = 1}, - new() { Location = FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 4.5f, PositionY = 0.5f, ItemDeploySequence = 368862459, ServerId = 368862459, UniqueId = 9, StackCount = 1}, - new() { Location = FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 7.5f, PositionY = 8.5f, ItemDeploySequence = 368862460, ServerId = 368862460, UniqueId = 10, StackCount = 1}, - new() { Location = FurnitureLocation.WallLeft, CafeDBId = 3091193, PositionX = 7.5f, PositionY = 3.0f, ItemDeploySequence = 368862461, ServerId = 368862461, UniqueId = 11, StackCount = 1}], - + CafeDBs = [.. account.Cafes], + FurnitureDBs = [.. account.Furnitures] }, AccountCurrencySyncResponse = new AccountCurrencySyncResponse() { @@ -579,6 +547,66 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers }; } + // Utils stuff + private List GetDefaultFurnitures(int cafeDbId) + { + var defaultFurnitureExcels = excelTableService.GetTable().UnPack().DataList; + + var defaultCharacters = defaultFurnitureExcels.Select((df, i) => new FurnitureDB() + { + CafeDBId = cafeDbId, + Location = df.Location, + ItemDeploySequence = i, + UniqueId = df.Id, + PositionX = RemoveScientificNotation(df.PositionX), + PositionY = RemoveScientificNotation(df.PositionY), + Rotation = RemoveScientificNotation(df.Rotation), + StackCount = 1, + }).ToList(); + + return defaultCharacters; + } + + private List GetRandomCharactersId(int amount) + { + var randomCharacters = new List(); + + var characterExcel = excelTableService.GetTable().UnPack().DataList; + + var allCharacters = characterExcel.Where(x => x is + { + IsPlayable: true, + IsPlayableCharacter: true, + IsNpc: false, + ProductionStep: ProductionStep.Release, + }).Select(x => x.Id).ToList(); + + while (randomCharacters.Count < amount) + { + int randIndex = new Random().Next() % allCharacters.Count; + randomCharacters.Add(allCharacters[randIndex]); + } + + return randomCharacters; + } + + public static float RemoveScientificNotation(float value) + { + float result = value; + + while (result < 1f) + { + result *= 10.0f; + } + + while (result > 19.0f) + { + result /= 10.0f; + } + + return result; + } + // TODO: others handlers, move to different handler group later [ProtocolHandler(Protocol.NetworkTime_Sync)] public ResponsePacket NetworkTime_SyncHandler(NetworkTimeSyncRequest req) @@ -679,112 +707,5 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers { return new FriendGetIdCardResponse(); } - - [ProtocolHandler(Protocol.Cafe_Get)] - public ResponsePacket Cafe_Get(CafeGetInfoRequest req) - { - - List cafeDBs = [ - new CafeDB() { - CafeDBId = 3091193, - CafeId = 1, - AccountId = 1, - CafeRank = 1, - LastUpdate = DateTime.Parse("2024-04-21T07: 29: 57"), - LastSummonDate = DateTime.Parse("0001-01-01T00: 00: 00"), - IsNew = true, - CafeVisitCharacterDBs = new Dictionary() - { - { 26008, new CafeCharacterDB() { UniqueId = 26008 } }, - { 10005, new CafeCharacterDB() { UniqueId = 10005 } }, - { 13004, new CafeCharacterDB() { UniqueId = 13004 } }, - { 10058, new CafeCharacterDB() { UniqueId = 10058 } }, - }, - - FurnitureDBs = [ - new() { Location = Common.FlatData.FurnitureLocation.Floor, CafeDBId = 3091193, ItemDeploySequence = 368862451, ServerId = 368862451, UniqueId = 1, StackCount = 1}, - new() { Location = Common.FlatData.FurnitureLocation.WallRight, CafeDBId = 3091193, ItemDeploySequence = 368862452, ServerId = 368862452, UniqueId = 2, StackCount = 1}, - new() { Location = Common.FlatData.FurnitureLocation.WallLeft, CafeDBId = 3091193, ItemDeploySequence = 368862453, ServerId = 368862453, UniqueId = 3, StackCount = 1}, - new() { Location = Common.FlatData.FurnitureLocation.WallRight, CafeDBId = 3091193, PositionX = 8.5f, PositionY = 3.0f, ItemDeploySequence = 368862454, ServerId = 368862454, UniqueId = 4, StackCount = 1}, - new() { Location = Common.FlatData.FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 3.0f, PositionY = 1.5f, Rotation = 270.0f, ItemDeploySequence = 368862455, ServerId = 368862455, UniqueId = 5, StackCount = 1}, - new() { Location = Common.FlatData.FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 7.5f, PositionY = 8.5f, ItemDeploySequence = 368862456, ServerId = 368862456, UniqueId = 6, StackCount = 1}, - new() { Location = Common.FlatData.FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 7.5f, PositionY = 6.5f, ItemDeploySequence = 368862457, ServerId = 368862457, UniqueId = 7, StackCount = 1}, - new() { Location = Common.FlatData.FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 9.5f, PositionY = 8.5f, ItemDeploySequence = 368862458, ServerId = 368862458, UniqueId = 8, StackCount = 1}, - new() { Location = Common.FlatData.FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 4.5f, PositionY = 0.5f, ItemDeploySequence = 368862459, ServerId = 368862459, UniqueId = 9, StackCount = 1}, - new() { Location = Common.FlatData.FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 7.5f, PositionY = 8.5f, ItemDeploySequence = 368862460, ServerId = 368862460, UniqueId = 10, StackCount = 1}, - new() { Location = Common.FlatData.FurnitureLocation.WallLeft, CafeDBId = 3091193, PositionX = 7.5f, PositionY = 3.0f, ItemDeploySequence = 368862461, ServerId = 368862461, UniqueId = 11, StackCount = 1} - ], - - ProductionAppliedTime = DateTime.Parse("2024-04-21T07: 29: 50"), - - ProductionDB = new () { - CafeDBId = 3091193, - AppliedDate = DateTime.Parse("2024-04-21T07: 29: 50"), - ProductionParcelInfos = [ - new() { Key = { Type = ParcelType.Currency, Id = 1 } }, - new() { Key = { Type = ParcelType.Currency, Id = 5 } } - ], - } - }, - ]; - - var characterExcel = excelTableService.GetTable().UnPack().DataList; - - var allCharacters = characterExcel.Where(x => - x is - { - IsPlayable: true, - IsPlayableCharacter: true, - IsNpc: false, - ProductionStep: ProductionStep.Release, - } - ).Select(x => x.Id).ToList(); - - - - var cafeVisitCharacterDBs = allCharacters.Take(10).ToDictionary(id => id, id => new CafeCharacterDB { UniqueId = id }); - - //cafeVisitCharacterDBs.Add(1, new CafeCharacterDB()); - - cafeDBs[0].CafeVisitCharacterDBs = cafeVisitCharacterDBs; - - return new CafeGetInfoResponse() - { - CafeDBs = cafeDBs, - - FurnitureDBs = [ - new() { Location = FurnitureLocation.Floor, CafeDBId = 3091193, ItemDeploySequence = 368862451, ServerId = 368862451, UniqueId = 1, StackCount = 1}, - new() { Location = FurnitureLocation.WallRight, CafeDBId = 3091193, ItemDeploySequence = 368862452, ServerId = 368862452, UniqueId = 2, StackCount = 1}, - new() { Location = FurnitureLocation.WallLeft, CafeDBId = 3091193, ItemDeploySequence = 368862453, ServerId = 368862453, UniqueId = 3, StackCount = 1}, - new() { Location = FurnitureLocation.WallRight, CafeDBId = 3091193, PositionX = 8.5f, PositionY = 3.0f, ItemDeploySequence = 368862454, ServerId = 368862454, UniqueId = 4, StackCount = 1}, - new() { Location = FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 3.0f, PositionY = 1.5f, Rotation = 270.0f, ItemDeploySequence = 368862455, ServerId = 368862455, UniqueId = 5, StackCount = 1}, - new() { Location = FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 7.5f, PositionY = 8.5f, ItemDeploySequence = 368862456, ServerId = 368862456, UniqueId = 6, StackCount = 1}, - new() { Location = FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 7.5f, PositionY = 6.5f, ItemDeploySequence = 368862457, ServerId = 368862457, UniqueId = 7, StackCount = 1}, - new() { Location = FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 9.5f, PositionY = 8.5f, ItemDeploySequence = 368862458, ServerId = 368862458, UniqueId = 8, StackCount = 1}, - new() { Location = FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 4.5f, PositionY = 0.5f, ItemDeploySequence = 368862459, ServerId = 368862459, UniqueId = 9, StackCount = 1}, - new() { Location = FurnitureLocation.Floor, CafeDBId = 3091193, PositionX = 7.5f, PositionY = 8.5f, ItemDeploySequence = 368862460, ServerId = 368862460, UniqueId = 10, StackCount = 1}, - new() { Location = FurnitureLocation.WallLeft, CafeDBId = 3091193, PositionX = 7.5f, PositionY = 3.0f, ItemDeploySequence = 368862461, ServerId = 368862461, UniqueId = 11, StackCount = 1}], - }; - } - - [ProtocolHandler(Protocol.Cafe_Ack)] - public ResponsePacket Cafe_Ack(CafeAckRequest req) - { - return new CafeAckResponse(); - } - - [ProtocolHandler(Protocol.Cafe_Open)] - public ResponsePacket Cafe_Open(CafeOpenRequest req) - { - return new CafeOpenResponse(); - } - - [ProtocolHandler(Protocol.Cafe_Interact)] - public ResponsePacket Cafe_Interact(CafeInteractWithCharacterRequest req) - { - return new CafeInteractWithCharacterResponse(); - } - - } } diff --git a/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Cafe.cs b/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Cafe.cs new file mode 100644 index 0000000..74338fb --- /dev/null +++ b/SCHALE.GameServer/Controllers/Api/ProtocolHandlers/Cafe.cs @@ -0,0 +1,83 @@ +using Microsoft.IdentityModel.Tokens; +using SCHALE.Common.Database; +using SCHALE.Common.Database.ModelExtensions; +using SCHALE.Common.FlatData; +using SCHALE.Common.NetworkProtocol; +using SCHALE.GameServer.Services; +using Serilog; +using System.Transactions; + +namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers +{ + public class Cafe : ProtocolHandlerBase + { + private readonly ISessionKeyService sessionKeyService; + private readonly SCHALEContext context; + private readonly ExcelTableService excelTableService; + + public Cafe(IProtocolHandlerFactory protocolHandlerFactory, ISessionKeyService _sessionKeyService, SCHALEContext _context, ExcelTableService _excelTableService) : base(protocolHandlerFactory) + { + sessionKeyService = _sessionKeyService; + context = _context; + excelTableService = _excelTableService; + } + + [ProtocolHandler(Protocol.Cafe_Get)] + public ResponsePacket Cafe_Get(CafeGetInfoRequest req) + { + var account = sessionKeyService.GetAccount(req.SessionKey); + + return new CafeGetInfoResponse() + { + CafeDBs = [.. account.Cafes], + FurnitureDBs = [.. account.Furnitures] + }; + } + + [ProtocolHandler(Protocol.Cafe_Ack)] + public ResponsePacket AckHandler(CafeAckRequest req) + { + return new CafeAckResponse(); + } + + [ProtocolHandler(Protocol.Cafe_Open)] + public ResponsePacket OpenHandler(CafeOpenRequest req) + { + return new CafeOpenResponse(); + } + + [ProtocolHandler(Protocol.Cafe_Interact)] + public ResponsePacket InteractHandler(CafeInteractWithCharacterRequest req) + { + return new CafeInteractWithCharacterResponse(); + } + + + [ProtocolHandler(Protocol.Cafe_Relocate)] + public ResponsePacket RelocateHandler(CafeRelocateFurnitureRequest req) + { + var account = sessionKeyService.GetAccount(req.SessionKey); + + var targetCafe = account.Cafes.Where(x => x.CafeDBId == req.CafeDBId).SingleOrDefault(); + var targetFurniture = targetCafe.FurnitureDBs.Where(x => x.CafeDBId == req.CafeDBId && x.ServerId == req.FurnitureDB.ServerId).SingleOrDefault(); + + if (targetFurniture == null) + { + Log.Error("Target Furniture with Id: " + req.FurnitureDB.ServerId + " was not found."); + return new ErrorPacket(); + } + + targetFurniture.PositionX = req.FurnitureDB.PositionX; + targetFurniture.PositionY = req.FurnitureDB.PositionY; + targetFurniture.Rotation = req.FurnitureDB.Rotation; + + context.SaveChanges(); + + return new CafeRelocateFurnitureResponse() + { + CafeDB = targetCafe, + RelocatedFurnitureDB = targetFurniture, + }; + } + } +}