using SCHALE.Common.FlatData; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Text.Json.Serialization; using System.Threading.Tasks; namespace SCHALE.Common.Database { public class AccountDB { [JsonIgnore] public virtual ICollection Items { get; } [JsonIgnore] public virtual ICollection Characters { get; } [JsonIgnore] public virtual ICollection MissionProgresses { get; } [JsonIgnore] public virtual ICollection Echelons { get; } [JsonIgnore] public virtual ICollection Equipment { get; } [JsonIgnore] public virtual ICollection Weapons { get; } [JsonIgnore] public virtual ICollection Gears { get; } [JsonIgnore] public virtual ICollection MemoryLobbies { get; } [JsonIgnore] public virtual ICollection Scenarios { get; } [JsonIgnore] public virtual ICollection Cafes { get; } [JsonIgnore] public virtual ICollection Furnitures { get; } [JsonIgnore] public virtual ICollection ScenarioGroups { get; } [JsonIgnore] public virtual ICollection Currencies { get; } [JsonIgnore] public virtual ICollection MultiFloorRaids { get; } [JsonIgnore] public virtual ICollection WeekDungeonStageHistories { get; } [JsonIgnore] public virtual ICollection SchoolDungeonStageHistories { get; } [JsonIgnore] public virtual ICollection CampaignStageHistories { get; } [JsonIgnore] public virtual ICollection Mails { get; } [JsonIgnore] public virtual RaidInfo RaidInfo { get; set; } public AccountDB() { Items = new List(); Characters = new List(); MissionProgresses = new List(); Echelons = new List(); Equipment = new List(); Weapons = new List(); Gears = new List(); MemoryLobbies = new List(); Scenarios = new List(); Cafes = new List(); Furnitures = new List(); ScenarioGroups = new List(); Currencies = new List(); MultiFloorRaids = new List(); WeekDungeonStageHistories = new List(); SchoolDungeonStageHistories = new List(); CampaignStageHistories = new List(); Mails = new List(); } public AccountDB(long publisherAccountId) : this() { PublisherAccountId = publisherAccountId; State = AccountState.Normal; Level = 1; LastConnectTime = DateTime.Now; CreateDate = DateTime.Now; RaidInfo = new() { SeasonId = 1, // default BestRankingPoint = 0, TotalRankingPoint = 0, }; } [Key] public long ServerId { get; set; } public string? Nickname { get; set; } public string? CallName { get; set; } public string? DevId { get; set; } public AccountState State { get; set; } public int Level { get; set; } public long Exp { get; set; } public string? Comment { get; set; } public int? LobbyMode { get; set; } public long RepresentCharacterServerId { get; set; } public long MemoryLobbyUniqueId { get; set; } public DateTime LastConnectTime { get; set; } public DateTime BirthDay { get; set; } public DateTime CallNameUpdateTime { get; set; } public long PublisherAccountId { get; set; } public Nullable RetentionDays { get; set; } public Nullable VIPLevel { get; set; } public DateTime CreateDate { get; set; } public Nullable UnReadMailCount { get; set; } public Nullable LinkRewardDate { get; set; } } public class FurnitureDB : ConsumableItemBaseDB { public override ParcelType Type { get => ParcelType.Furniture; } [NotMapped] [JsonIgnore] public override IEnumerable ParcelInfos { get; } [JsonIgnore] public override bool CanConsume { get => false; } public FurnitureLocation Location { get; set; } public long CafeDBId { get; set; } public float PositionX { get; set; } public float PositionY { get; set; } public float Rotation { get; set; } public long ItemDeploySequence { get; set; } } public class MissionProgressDB : IEquatable, IMemoryPackable, IMemoryPackFormatterRegister { [Key] [JsonIgnore] public long ServerId { get; set; } [JsonIgnore] public virtual AccountDB Account { get; set; } [JsonIgnore] public long AccountServerId { get; set; } public long MissionUniqueId { get; set; } public bool Complete { get; set; } public DateTime StartTime { get; set; } public Dictionary ProgressParameters { get; set; } = []; public bool Equals(MissionProgressDB other) { return default; } } public abstract class ConsumableItemBaseDB : ParcelBase { [JsonIgnore] public virtual AccountDB Account { get; set; } [JsonIgnore] public abstract bool CanConsume { get; } [JsonIgnore] public ParcelKeyPair Key { get; } [JsonIgnore] public long AccountServerId { get; set; } [Key] public long ServerId { get; set; } public long UniqueId { get; set; } public long StackCount { get; set; } } public class ItemDB : ConsumableItemBaseDB { [NotMapped] public override ParcelType Type => ParcelType.Item; [NotMapped] [JsonIgnore] public override IEnumerable ParcelInfos { get; } [NotMapped] [JsonIgnore] public override bool CanConsume => true; } public class CharacterDB : ParcelBase { [NotMapped] public override ParcelType Type { get => ParcelType.Character; } [JsonIgnore] public virtual AccountDB Account { get; set; } [JsonIgnore] public long AccountServerId { get; set; } [JsonIgnore] [NotMapped] public override IEnumerable ParcelInfos { get; } [Key] public long ServerId { get; set; } public long UniqueId { get; set; } public int StarGrade { get; set; } public int Level { get; set; } public long Exp { get; set; } public int FavorRank { get; set; } public long FavorExp { get; set; } public int PublicSkillLevel { get; set; } public int ExSkillLevel { get; set; } public int PassiveSkillLevel { get; set; } public int ExtraPassiveSkillLevel { get; set; } public int LeaderSkillLevel { get; set; } public bool IsFavorite { get; set; } public List EquipmentServerIds { get; set; } = []; public Dictionary PotentialStats { get; set; } = []; [JsonIgnore] public Dictionary EquipmentSlotAndDBIds { get; } = []; } public class EquipmentDB : ConsumableItemBaseDB { [NotMapped] public override ParcelType Type { get => ParcelType.Equipment; } [NotMapped] [JsonIgnore] public override IEnumerable ParcelInfos { get; } [JsonIgnore] public override bool CanConsume { get => false; } public int Level { get; set; } public long Exp { get; set; } public int Tier { get; set; } public long BoundCharacterServerId { get; set; } } public class WeaponDB : ParcelBase { [NotMapped] public override ParcelType Type { get => ParcelType.CharacterWeapon; } [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 UniqueId { get; set; } public int Level { get; set; } public long Exp { get; set; } public int StarGrade { get; set; } public long BoundCharacterServerId { get; set; } } public class GearDB : ParcelBase { [NotMapped] public override ParcelType Type { get => ParcelType.CharacterGear; } [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 UniqueId { get; set; } public int Level { get; set; } public long Exp { get; set; } public int Tier { get; set; } public long SlotIndex { get; set; } public long BoundCharacterServerId { get; set; } [JsonIgnore] public EquipmentDB ToEquipmentDB { get; } } public class MemoryLobbyDB : ParcelBase { 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; } } 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; } } public class ScenarioGroupHistoryDB { [JsonIgnore] public virtual AccountDB Account { get; set; } [JsonIgnore] public long AccountServerId { get; set; } [Key] public long ServerId { get; set; } public long ScenarioGroupUqniueId { get; set; } public long ScenarioType { get; set; } public Nullable EventContentId { get; set; } public DateTime ClearDateTime { get; set; } public bool IsReturn { get; set; } } public class EchelonDB { [Key] [JsonIgnore] public long ServerId { get; set; } [JsonIgnore] public virtual AccountDB Account { get; set; } [JsonIgnore] public long AccountServerId { get; set; } public EchelonType EchelonType { get; set; } public long EchelonNumber { get; set; } public EchelonExtensionType ExtensionType { get; set; } public long LeaderServerId { get; set; } [JsonIgnore] public int MainSlotCount { get; } [JsonIgnore] public int SupportSlotCount { get; } public List MainSlotServerIds { get; set; } = []; public List SupportSlotServerIds { get; set; } = []; public long TSSInteractionServerId { get; set; } public EchelonStatusFlag UsingFlag { get; set; } [JsonIgnore] public bool IsUsing { get; } [JsonIgnore] public List AllCharacterServerIds { get; } = []; [JsonIgnore] public List AllCharacterWithoutTSSServerIds { get; } = []; [JsonIgnore] public List AllCharacterWithEmptyServerIds { get; } = []; [JsonIgnore] public List BattleCharacterServerIds { get; } = []; public List SkillCardMulliganCharacterIds { get; set; } = []; public int[] CombatStyleIndex { get; set; } = []; } public class CampaignSubStageSaveDB : ContentSaveDB { public override ContentType ContentType { get => ContentType.CampaignSubStage; } } public class CampaignTutorialStageSaveDB : ContentSaveDB { public override ContentType ContentType { get => ContentType.CampaignTutorialStage; } } 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; } public Nullable LastSummonDate { get; set; } [NotMapped] public bool IsNew { get; set; } public Dictionary CafeVisitCharacterDBs { get; set; } [NotMapped] public List FurnitureDBs { get => Account.Furnitures.Where(x => x.CafeDBId == CafeDBId).ToList(); } public DateTime ProductionAppliedTime { get; set; } [NotMapped] public CafeProductionDB ProductionDB { get => new() { CafeDBId = 1, AppliedDate = DateTime.UtcNow, ProductionParcelInfos = [ new(){ Key = new ParcelKeyPair { Type = ParcelType.Currency, Id = 1 } }, // id 1 new() { Key = new ParcelKeyPair { Type = ParcelType.Currency, Id = 5 } } ], }; } [JsonIgnore] public Dictionary CurrencyDict_Obsolete { get; set; } = new Dictionary(); [JsonIgnore] public Dictionary UpdateTimeDict_Obsolete { get; set; } = new Dictionary(); } public class RaidInfo // custom class for all raid stuff needed { public long SeasonId { get; set; } public long CurrentRaidUniqueId { get; set; } public Difficulty CurrentDifficulty { get; set; } public long BestRankingPoint { get; set; } public long TotalRankingPoint { get; set; } } public class AcademyDB { public long AccountId { get; set; } public DateTime LastUpdate { get; set; } public Dictionary> ZoneVisitCharacterDBs { get; set; } public Dictionary> ZoneScheduleGroupRecords { get; set; } } public class CampaignStageHistoryDB { [JsonIgnore] public virtual AccountDB Account { get; set; } [JsonIgnore] public long AccountServerId { get; set; } [Key] public long ServerId { get; set; } public long StoryUniqueId { get; set; } public long ChapterUniqueId { get; set; } public long StageUniqueId { get; set; } public long TacticClearCountWithRankSRecord { get; set; } public long ClearTurnRecord { get; set; } [JsonIgnore] public long BestStarRecord { get; } public bool Star1Flag { get; set; } public bool Star2Flag { get; set; } public bool Star3Flag { get; set; } public DateTime LastPlay { get; set; } public long TodayPlayCount { get; set; } public long TodayPurchasePlayCountHardStage { get; set; } public Nullable FirstClearRewardReceive { get; set; } public Nullable StarRewardReceive { get; set; } [JsonIgnore] public bool IsClearedEver { get; } public long TodayPlayCountForUI { get; } } public class MailDB { [JsonIgnore] public virtual AccountDB Account { get; set; } [Key] public long ServerId { get; set; } [JsonIgnore] public long AccountServerId { get; set; } public MailType Type { get; set; } public long UniqueId { get; set; } public string Sender { get; set; } public string Comment { get; set; } public DateTime SendDate { get; set; } public Nullable ReceiptDate { get; set; } public Nullable ExpireDate { get; set; } [NotMapped] // TODO: implement storing these two with ef core, this is very nessary since these parcel infos are the items given in the mail, must be stored public List ParcelInfos { get; set; } // remove [NotMapped] if implemented storing [NotMapped] public List RemainParcelInfos { get; set; } } public class CampaignChapterClearRewardHistoryDB { public long AccountServerId { get; set; } public long ChapterUniqueId { get; set; } public StageDifficulty RewardType { get; set; } public DateTime ReceiveDate { get; set; } } public class AccountCurrencyDB { [JsonIgnore] public virtual AccountDB Account { get; set; } [JsonIgnore] public long AccountServerId { get; set; } [Key] public long ServerId { get; set; } public long AccountLevel { get; set; } public long AcademyLocationRankSum { get; set; } public Dictionary CurrencyDict { get; set; } public Dictionary UpdateTimeDict { get; set; } } public class MultiFloorRaidDB { [JsonIgnore] public virtual AccountDB Account { get; set; } [JsonIgnore] public long AccountServerId { get; set; } [Key] public long ServerId { get; set; } public long SeasonId { get; set; } public int ClearedDifficulty { get; set; } public DateTime LastClearDate { get; set; } public int RewardDifficulty { get; set; } public DateTime LastRewardDate { get; set; } public int ClearBattleFrame { get; set; } [JsonIgnore] public bool AllCleared { get; } = false; [JsonIgnore] public bool HasReceivableRewards { get; } = false; [JsonIgnore] public List TotalReceivableRewards { get; } = new List(); [JsonIgnore] public List TotalReceivedRewards { get; } = new List(); } public class WeekDungeonStageHistoryDB { [JsonIgnore] public virtual AccountDB Account { get; set; } [Key] public long ServerId { get; set; } [JsonIgnore] public long AccountServerId { get; set; } public long StageUniqueId { get; set; } public Dictionary StarGoalRecord { get; set; } [JsonIgnore] public bool IsCleardEver { get; } } public class SchoolDungeonStageHistoryDB { [JsonIgnore] public virtual AccountDB Account { get; set; } [JsonIgnore] public long AccountServerId { get; set; } [Key] public long ServerId { get; set; } public long StageUniqueId { get; set; } [JsonIgnore] public long BestStarRecord { get; } public bool[] StarFlags { get; set; } [JsonIgnore] public bool Star1Flag { get; } [JsonIgnore] public bool Star2Flag { get; } [JsonIgnore] public bool Star3Flag { get; } [JsonIgnore] public bool IsClearedEver { get; } } [Serializable] public struct BasisPoint : IEquatable, IComparable { private static readonly long Multiplier; private static readonly double OneOver10_4 = 1.0 / 10000.0; public static readonly BasisPoint Zero; public static readonly BasisPoint One; public static readonly BasisPoint Epsilon; public static readonly double DoubleEpsilon; [JsonIgnore] public long RawValue { get; } private long rawValue; public BasisPoint(long rawValue) { this.rawValue = rawValue; } public bool Equals(BasisPoint other) { return this.rawValue == other.rawValue; } public int CompareTo(BasisPoint other) { return rawValue.CompareTo(other.rawValue); } public static long operator *(long value, BasisPoint other) { return MultiplyLong(value, other); } public static long MultiplyLong(long value, BasisPoint other) { double result = OneOver10_4 * ((double)other.rawValue * value); if (double.IsInfinity(result)) return long.MaxValue; return (long)result; } } }