diff --git a/KfChatDotNetBot/ApplicationDbContext.cs b/KfChatDotNetBot/ApplicationDbContext.cs index f4f5db1..6b8e6ff 100644 --- a/KfChatDotNetBot/ApplicationDbContext.cs +++ b/KfChatDotNetBot/ApplicationDbContext.cs @@ -12,8 +12,8 @@ public class ApplicationDbContext : DbContext protected override void OnModelCreating(ModelBuilder modelBuilder) { - base.OnModelCreating(modelBuilder); - + //modelBuilder.Entity() + // .OwnsOne(p => p.StateData, b => b.ToJson()); } public DbSet Users { get; set; } diff --git a/KfChatDotNetBot/Models/DbModels/KasinoShopDbModels.cs b/KfChatDotNetBot/Models/DbModels/KasinoShopDbModels.cs new file mode 100644 index 0000000..439cb47 --- /dev/null +++ b/KfChatDotNetBot/Models/DbModels/KasinoShopDbModels.cs @@ -0,0 +1,305 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace KfChatDotNetBot.Models.DbModels; + +public class KasinoShopProfileDbModel +{ + /// + /// ID for the database row + /// + public int Id { get; set; } + /// + /// Shop profiles belong to a user, not their gambler ID + /// they persist even if the user abandons their profile + /// + public required UserDbModel User { get; set; } + /// + /// Assets held by this profile + /// + public required List Assets { get; set; } + /// + /// Loans taken out by this profile + /// + [InverseProperty(nameof(KasinoShopProfileLoanDbModel.Borrower))] + public required List LoansTaken { get; set; } + /// + /// Loans owed to this profile + /// + [InverseProperty(nameof(KasinoShopProfileLoanDbModel.Lender))] + public required List LoansOwed { get; set; } + /// + /// State of the profile + /// + public required KasinoShopProfileStateFlags State { get; set; } = KasinoShopProfileStateFlags.None; + /// + /// JSON object containing data related to the above states + /// + public required KasinoShopProfileStateDataModel StateData { get; set; } + /// + /// Profile balance in the "Krypto" currency + /// + public required decimal KryptoBalance { get; set; } +} + +// Note this is serialized to JSON by Entity Framework so you can go wild shoving random bullshit in here +public class KasinoShopProfileStateDataModel +{ + /// + /// Profile credit score for determining creditworthiness etc. + /// + // Actually considered making this uint but I like the idea of negative credit + public required int KreditScore { get; set; } + /// + /// Amount this user has wagered towards their sponsor requirement + /// + public decimal? SponsorWagerAmount { get; set; } = null; + /// + /// The sponsor's wager requirement + /// + public decimal? SponsorWagerRequirement { get; set; } = null; + /// + /// Modifier that alters the house edge for your gambler entity + /// + public required decimal HouseEdgeModifier { get; set; } = 1; + /// + /// How much crack you've smoked? + /// + public required int CrackCounter { get; set; } = 0; + /// + /// How many floor nugs you got embedded in the carpet + /// + public required int FloorNugs { get; set; } = 0; + /// + /// Time when your weed buff ends + /// + public required DateTimeOffset WeedBuffEnds { get; set; } = DateTimeOffset.UtcNow; + /// + /// Time when your crack buff ends + /// + public required DateTimeOffset CrackBuffEnds { get; set; } = DateTimeOffset.UtcNow; + /// + /// Dodgy stat tracking + /// + public required KasinoShopStatTrackerModel StatTracker { get; set; } = new(); +} + +public class KasinoShopStatTrackerModel +{ + public decimal TotalDeposited { get; set; } = 0; + public decimal TotalWithdrawn { get; set; } = 0; + public decimal TotalLossback { get; set; } = 0; + /// + /// Track wager statistics by game + /// + public Dictionary StatTracker { get; set; } = new(); +} + +public class KasinoShopProfileLoanDbModel +{ + /// + /// ID for the database row + /// + public int Id { get; set; } + /// + /// Profile of the user who owns this loan + /// + public required KasinoShopProfileDbModel Borrower { get; set; } + /// + /// Profile of the user to whom this loan is owed/payable to + /// + public required KasinoShopProfileDbModel Lender { get; set; } + /// + /// Amount loaned + /// + public required decimal Amount { get; set; } + /// + /// Amount to be paid out to the loaner + /// + public required decimal PayoutAmount { get; set; } + /// + /// Date and time loan entry was created + /// + public required DateTimeOffset Created { get; set; } + /// + /// State of this loan + /// + public required LoanState State { get; set; } +} + +public class KasinoShopProfileAssetDbModel +{ + /// + /// ID for the database row + /// + public int Id { get; set; } + /// + /// Profile of the user who owns this asset + /// + public required KasinoShopProfileDbModel Profile { get; set; } + /// + /// Value of the item at the time of acquisition in Krypto + /// + public required decimal OriginalValue { get; set; } + /// + /// What the value of the item is right now + /// + public required decimal CurrentValue { get; set; } + /// + /// Asset name + /// + public required string Name { get; set; } + /// + /// Asset type + /// + public required AssetType AssetType { get; set; } + /// + /// Date and time the asset was acquired + /// + public required DateTimeOffset Acquired { get; set; } + /// + /// History of value changes (e.g. interest events) + /// + public required List ValueChangeReports { get; set; } + /// + /// Use this to store enum values for assets that have a subtype (e.g. Car Type) + /// but were otherwise not special enough to have their own table (e.g. Car) + /// + public int? AssetSubType { get; set; } = null; + /// + /// Serialized JSON for extra information where the schema can't accommodate for you + /// + public string? Extra { get; set; } = null; +} + +public class KasinoShopProfileAssetInvestmentDbModel +{ + /// + /// ID for the database row + /// + public int Id { get; set; } + /// + /// Related asset for this investment + /// + public required KasinoShopProfileAssetDbModel Asset { get; set; } + /// + /// What type of investment it is + /// + public required InvestmentType InvestmentType { get; set; } + /// + /// Last time interest was calculated + /// + public required DateTimeOffset LastInterestCalculation { get; set; } + /// + /// Low point for interest calculations + /// + public required float InterestRangeMin { get; set; } + /// + /// High point for interest calculations + /// + public required float InterestRangeMax { get; set; } + /// + /// Use this to store enum values for investments that have a subtype (e.g. Shoe Brand) + /// but were otherwise not special enough to have their own table (e.g. Shoe) + /// + public int? InvestmentSubType { get; set; } = null; + /// + /// Serialized JSON for extra information where the schema can't accommodate for you + /// + public string? Extra { get; set; } = null; +} + +public class KasinoShopProfileAssetValueChangeDbModel +{ + /// + /// ID for the database row + /// + public int Id { get; set; } + /// + /// Related asset + /// + public required KasinoShopProfileAssetDbModel Asset { get; set; } + /// + /// Effect of the change + /// + public required decimal ValueChangeEffect { get; set; } + /// + /// Change percent as a decimal fraction? + /// + public required decimal ValueChangePercent { get; set; } + /// + /// Descriptive text for the value change (like the source of it) + /// + public required string Description { get; set; } +} + +[Flags] +public enum KasinoShopProfileStateFlags : ulong +{ + None, + IsSponsored, + IsWeeded, + IsCracked, + IsInWithdrawal, + IsLoanable +} + +[Flags] +public enum KasinoShopProfileAssetState : ulong +{ + None, + /// + /// Only applicable to smashable objects (e.g. PC peripherals) + /// + IsSmashed +} + +public enum AssetType +{ + Investment, + Smashable, + Car, + Random +} + +public enum InvestmentType +{ + Shoes, + Stake, + Gold, + Silver, + Skin, + House, + Random +} + +public enum LoanState +{ + /// + /// Loan not fully paid but borrower still in good standing + /// + Active, + /// + /// Past due but not yet a serious violation of terms + /// + Delinquent, + /// + /// Loan terms violated, time to collect + /// + Default, + /// + /// Loan settled by agreement to amended terms (e.g. paid off less than the full amount) + /// + Settled, + /// + /// Loan fully repaid for the total amount and closed out + /// + Repaid, + /// + /// Written off debt due to being unable to collect + /// + Uncollectible, + /// + /// Administrative state for loans canceled due to serious malfeasance + /// + Canceled +} \ No newline at end of file diff --git a/KfChatDotNetBot/Models/DbModels/MoneyDbModels.cs b/KfChatDotNetBot/Models/DbModels/MoneyDbModels.cs index aa9fb3e..0337c03 100644 --- a/KfChatDotNetBot/Models/DbModels/MoneyDbModels.cs +++ b/KfChatDotNetBot/Models/DbModels/MoneyDbModels.cs @@ -202,113 +202,6 @@ public class GamblerPerkDbModel public decimal? Payout { get; set; } } -public class KasinoShopProfileDbModel -{ - /// - /// ID for the database row - /// - public int Id { get; set; } - /// - /// Shop profiles belong to a user, not their gambler ID - /// they persist even if the user abandons their profile - /// - public required UserDbModel User { get; set; } - public required List Assets { get; set; } - public required List Loans { get; set; } -} - -public class KasinoShopProfileLoanDbModel -{ - /// - /// ID for the database row - /// - public int Id { get; set; } - // Foreign key that the powers that be told me I need for the fancy navigation property - public int ProfileId { get; set; } - /// - /// Profile of the user who owns this loan - /// - public required KasinoShopProfileDbModel Profile { get; set; } - // Foreign key that the powers that be told me I need for the fancy navigation property - public int PayableToId { get; set; } - /// - /// Profile of the user to whom this loan is owed/payable to - /// - public required KasinoShopProfileDbModel PayableTo { get; set; } - /// - /// Amount loaned - /// - public required decimal Amount { get; set; } - /// - /// Amount to be paid out to the loaner - /// - public required decimal PayoutAmount { get; set; } - /// - /// Date and time loan entry was created - /// - public required DateTimeOffset Created { get; set; } -} - -public class KasinoShopProfileAssetDbModel -{ - /// - /// ID for the database row - /// - public int Id { get; set; } - /// - /// Profile of the user who owns this asset - /// - public required KasinoShopProfileDbModel Profile { get; set; } - /// - /// Value of the item at the time of acquisition in Krypto - /// - public required decimal OriginalValue { get; set; } - /// - /// Asset name - /// - public required string Name { get; set; } - /// - /// Asset type - /// - public required AssetType AssetType { get; set; } - /// - /// Date and time the asset was acquired - /// - public required DateTimeOffset Acquired { get; set; } - /// - /// History of value changes (e.g. interest events) - /// - public required List ValueChangeReports { get; set; } - /// - /// Serialized JSON for extra information useful for certain assets (e.g. car model) - /// - public string? Extra { get; set; } = null; -} - -public class KasinoShopProfileAssetValueChangeDbModel -{ - /// - /// ID for the database row - /// - public int Id { get; set; } - /// - /// Related asset - /// - public required KasinoShopProfileAssetDbModel Asset { get; set; } - /// - /// Effect of the change - /// - public required decimal ValueChangeEffect { get; set; } - /// - /// Change percent as a decimal fraction? - /// - public required decimal ValueChangePercent { get; set; } - /// - /// Descriptive text for the value change (like the source of it) - /// - public required string Description { get; set; } -} - public enum GamblerPerkType { /// diff --git a/KfChatDotNetBot/Models/KasinoShopModels.cs b/KfChatDotNetBot/Models/KasinoShopModels.cs new file mode 100644 index 0000000..ae32dfb --- /dev/null +++ b/KfChatDotNetBot/Models/KasinoShopModels.cs @@ -0,0 +1,9 @@ +namespace KfChatDotNetBot.Models; + +/// +/// Holds state information for the kasino shop +/// +public class KasinoShopStateModel +{ + public required decimal DefaultHouseEdgeModifier { get; set; } = 0; +} \ No newline at end of file diff --git a/KfChatDotNetBot/Services/KasinoShop.cs b/KfChatDotNetBot/Services/KasinoShop.cs index 5667778..c83c90b 100644 --- a/KfChatDotNetBot/Services/KasinoShop.cs +++ b/KfChatDotNetBot/Services/KasinoShop.cs @@ -1,18 +1,9 @@ using System.Text.Json; using KfChatDotNetBot.Extensions; -using KfChatDotNetBot.Models; using KfChatDotNetBot.Models.DbModels; using KfChatDotNetBot.Settings; using NLog; using StackExchange.Redis; -using System.Text.Json.Serialization; -using System.Text.RegularExpressions; -using KfChatDotNetBot.Extensions; -using KfChatDotNetBot.Models; -using KfChatDotNetBot.Models.DbModels; -using KfChatDotNetBot.Services; -using KfChatDotNetBot.Settings; -using KfChatDotNetWsClient.Models.Events; using Microsoft.EntityFrameworkCore; using RandN; using RandN.Compat;