mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-04-30 03:22:04 -04:00
- Moved the Kasino shop models to their own file
- Added investments as a derivative of assets - Added profile state flags which can retain basic states like IsSponsored - Added profile state data using EF Core's JSON functionality so it should automatically serialize / deserialize the accompanying model for convenience (OnModelCreating code commented out due to the models not yet having a DbSet as I won't bake them in until KasinoShop is ready)
This commit is contained in:
@@ -12,8 +12,8 @@ public class ApplicationDbContext : DbContext
|
|||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
base.OnModelCreating(modelBuilder);
|
//modelBuilder.Entity<KasinoShopProfileDbModel>()
|
||||||
|
// .OwnsOne(p => p.StateData, b => b.ToJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
public DbSet<UserDbModel> Users { get; set; }
|
public DbSet<UserDbModel> Users { get; set; }
|
||||||
|
|||||||
305
KfChatDotNetBot/Models/DbModels/KasinoShopDbModels.cs
Normal file
305
KfChatDotNetBot/Models/DbModels/KasinoShopDbModels.cs
Normal file
@@ -0,0 +1,305 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace KfChatDotNetBot.Models.DbModels;
|
||||||
|
|
||||||
|
public class KasinoShopProfileDbModel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// ID for the database row
|
||||||
|
/// </summary>
|
||||||
|
public int Id { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Shop profiles belong to a user, not their gambler ID
|
||||||
|
/// they persist even if the user abandons their profile
|
||||||
|
/// </summary>
|
||||||
|
public required UserDbModel User { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Assets held by this profile
|
||||||
|
/// </summary>
|
||||||
|
public required List<KasinoShopProfileAssetDbModel> Assets { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Loans taken out by this profile
|
||||||
|
/// </summary>
|
||||||
|
[InverseProperty(nameof(KasinoShopProfileLoanDbModel.Borrower))]
|
||||||
|
public required List<KasinoShopProfileLoanDbModel> LoansTaken { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Loans owed to this profile
|
||||||
|
/// </summary>
|
||||||
|
[InverseProperty(nameof(KasinoShopProfileLoanDbModel.Lender))]
|
||||||
|
public required List<KasinoShopProfileLoanDbModel> LoansOwed { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// State of the profile
|
||||||
|
/// </summary>
|
||||||
|
public required KasinoShopProfileStateFlags State { get; set; } = KasinoShopProfileStateFlags.None;
|
||||||
|
/// <summary>
|
||||||
|
/// JSON object containing data related to the above states
|
||||||
|
/// </summary>
|
||||||
|
public required KasinoShopProfileStateDataModel StateData { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Profile balance in the "Krypto" currency
|
||||||
|
/// </summary>
|
||||||
|
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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Profile credit score for determining creditworthiness etc.
|
||||||
|
/// </summary>
|
||||||
|
// Actually considered making this uint but I like the idea of negative credit
|
||||||
|
public required int KreditScore { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Amount this user has wagered towards their sponsor requirement
|
||||||
|
/// </summary>
|
||||||
|
public decimal? SponsorWagerAmount { get; set; } = null;
|
||||||
|
/// <summary>
|
||||||
|
/// The sponsor's wager requirement
|
||||||
|
/// </summary>
|
||||||
|
public decimal? SponsorWagerRequirement { get; set; } = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Modifier that alters the house edge for your gambler entity
|
||||||
|
/// </summary>
|
||||||
|
public required decimal HouseEdgeModifier { get; set; } = 1;
|
||||||
|
/// <summary>
|
||||||
|
/// How much crack you've smoked?
|
||||||
|
/// </summary>
|
||||||
|
public required int CrackCounter { get; set; } = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// How many floor nugs you got embedded in the carpet
|
||||||
|
/// </summary>
|
||||||
|
public required int FloorNugs { get; set; } = 0;
|
||||||
|
/// <summary>
|
||||||
|
/// Time when your weed buff ends
|
||||||
|
/// </summary>
|
||||||
|
public required DateTimeOffset WeedBuffEnds { get; set; } = DateTimeOffset.UtcNow;
|
||||||
|
/// <summary>
|
||||||
|
/// Time when your crack buff ends
|
||||||
|
/// </summary>
|
||||||
|
public required DateTimeOffset CrackBuffEnds { get; set; } = DateTimeOffset.UtcNow;
|
||||||
|
/// <summary>
|
||||||
|
/// Dodgy stat tracking
|
||||||
|
/// </summary>
|
||||||
|
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;
|
||||||
|
/// <summary>
|
||||||
|
/// Track wager statistics by game
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<WagerGame, decimal> StatTracker { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class KasinoShopProfileLoanDbModel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// ID for the database row
|
||||||
|
/// </summary>
|
||||||
|
public int Id { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Profile of the user who owns this loan
|
||||||
|
/// </summary>
|
||||||
|
public required KasinoShopProfileDbModel Borrower { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Profile of the user to whom this loan is owed/payable to
|
||||||
|
/// </summary>
|
||||||
|
public required KasinoShopProfileDbModel Lender { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Amount loaned
|
||||||
|
/// </summary>
|
||||||
|
public required decimal Amount { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Amount to be paid out to the loaner
|
||||||
|
/// </summary>
|
||||||
|
public required decimal PayoutAmount { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Date and time loan entry was created
|
||||||
|
/// </summary>
|
||||||
|
public required DateTimeOffset Created { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// State of this loan
|
||||||
|
/// </summary>
|
||||||
|
public required LoanState State { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class KasinoShopProfileAssetDbModel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// ID for the database row
|
||||||
|
/// </summary>
|
||||||
|
public int Id { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Profile of the user who owns this asset
|
||||||
|
/// </summary>
|
||||||
|
public required KasinoShopProfileDbModel Profile { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Value of the item at the time of acquisition in Krypto
|
||||||
|
/// </summary>
|
||||||
|
public required decimal OriginalValue { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// What the value of the item is right now
|
||||||
|
/// </summary>
|
||||||
|
public required decimal CurrentValue { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Asset name
|
||||||
|
/// </summary>
|
||||||
|
public required string Name { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Asset type
|
||||||
|
/// </summary>
|
||||||
|
public required AssetType AssetType { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Date and time the asset was acquired
|
||||||
|
/// </summary>
|
||||||
|
public required DateTimeOffset Acquired { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// History of value changes (e.g. interest events)
|
||||||
|
/// </summary>
|
||||||
|
public required List<KasinoShopProfileAssetValueChangeDbModel> ValueChangeReports { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 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)
|
||||||
|
/// </summary>
|
||||||
|
public int? AssetSubType { get; set; } = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Serialized JSON for extra information where the schema can't accommodate for you
|
||||||
|
/// </summary>
|
||||||
|
public string? Extra { get; set; } = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class KasinoShopProfileAssetInvestmentDbModel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// ID for the database row
|
||||||
|
/// </summary>
|
||||||
|
public int Id { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Related asset for this investment
|
||||||
|
/// </summary>
|
||||||
|
public required KasinoShopProfileAssetDbModel Asset { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// What type of investment it is
|
||||||
|
/// </summary>
|
||||||
|
public required InvestmentType InvestmentType { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Last time interest was calculated
|
||||||
|
/// </summary>
|
||||||
|
public required DateTimeOffset LastInterestCalculation { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Low point for interest calculations
|
||||||
|
/// </summary>
|
||||||
|
public required float InterestRangeMin { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// High point for interest calculations
|
||||||
|
/// </summary>
|
||||||
|
public required float InterestRangeMax { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 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)
|
||||||
|
/// </summary>
|
||||||
|
public int? InvestmentSubType { get; set; } = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Serialized JSON for extra information where the schema can't accommodate for you
|
||||||
|
/// </summary>
|
||||||
|
public string? Extra { get; set; } = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class KasinoShopProfileAssetValueChangeDbModel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// ID for the database row
|
||||||
|
/// </summary>
|
||||||
|
public int Id { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Related asset
|
||||||
|
/// </summary>
|
||||||
|
public required KasinoShopProfileAssetDbModel Asset { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Effect of the change
|
||||||
|
/// </summary>
|
||||||
|
public required decimal ValueChangeEffect { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Change percent as a decimal fraction?
|
||||||
|
/// </summary>
|
||||||
|
public required decimal ValueChangePercent { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Descriptive text for the value change (like the source of it)
|
||||||
|
/// </summary>
|
||||||
|
public required string Description { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Flags]
|
||||||
|
public enum KasinoShopProfileStateFlags : ulong
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
IsSponsored,
|
||||||
|
IsWeeded,
|
||||||
|
IsCracked,
|
||||||
|
IsInWithdrawal,
|
||||||
|
IsLoanable
|
||||||
|
}
|
||||||
|
|
||||||
|
[Flags]
|
||||||
|
public enum KasinoShopProfileAssetState : ulong
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
/// <summary>
|
||||||
|
/// Only applicable to smashable objects (e.g. PC peripherals)
|
||||||
|
/// </summary>
|
||||||
|
IsSmashed
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum AssetType
|
||||||
|
{
|
||||||
|
Investment,
|
||||||
|
Smashable,
|
||||||
|
Car,
|
||||||
|
Random
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum InvestmentType
|
||||||
|
{
|
||||||
|
Shoes,
|
||||||
|
Stake,
|
||||||
|
Gold,
|
||||||
|
Silver,
|
||||||
|
Skin,
|
||||||
|
House,
|
||||||
|
Random
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum LoanState
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Loan not fully paid but borrower still in good standing
|
||||||
|
/// </summary>
|
||||||
|
Active,
|
||||||
|
/// <summary>
|
||||||
|
/// Past due but not yet a serious violation of terms
|
||||||
|
/// </summary>
|
||||||
|
Delinquent,
|
||||||
|
/// <summary>
|
||||||
|
/// Loan terms violated, time to collect
|
||||||
|
/// </summary>
|
||||||
|
Default,
|
||||||
|
/// <summary>
|
||||||
|
/// Loan settled by agreement to amended terms (e.g. paid off less than the full amount)
|
||||||
|
/// </summary>
|
||||||
|
Settled,
|
||||||
|
/// <summary>
|
||||||
|
/// Loan fully repaid for the total amount and closed out
|
||||||
|
/// </summary>
|
||||||
|
Repaid,
|
||||||
|
/// <summary>
|
||||||
|
/// Written off debt due to being unable to collect
|
||||||
|
/// </summary>
|
||||||
|
Uncollectible,
|
||||||
|
/// <summary>
|
||||||
|
/// Administrative state for loans canceled due to serious malfeasance
|
||||||
|
/// </summary>
|
||||||
|
Canceled
|
||||||
|
}
|
||||||
@@ -202,113 +202,6 @@ public class GamblerPerkDbModel
|
|||||||
public decimal? Payout { get; set; }
|
public decimal? Payout { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class KasinoShopProfileDbModel
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// ID for the database row
|
|
||||||
/// </summary>
|
|
||||||
public int Id { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Shop profiles belong to a user, not their gambler ID
|
|
||||||
/// they persist even if the user abandons their profile
|
|
||||||
/// </summary>
|
|
||||||
public required UserDbModel User { get; set; }
|
|
||||||
public required List<KasinoShopProfileAssetDbModel> Assets { get; set; }
|
|
||||||
public required List<KasinoShopProfileLoanDbModel> Loans { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class KasinoShopProfileLoanDbModel
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// ID for the database row
|
|
||||||
/// </summary>
|
|
||||||
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; }
|
|
||||||
/// <summary>
|
|
||||||
/// Profile of the user who owns this loan
|
|
||||||
/// </summary>
|
|
||||||
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; }
|
|
||||||
/// <summary>
|
|
||||||
/// Profile of the user to whom this loan is owed/payable to
|
|
||||||
/// </summary>
|
|
||||||
public required KasinoShopProfileDbModel PayableTo { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Amount loaned
|
|
||||||
/// </summary>
|
|
||||||
public required decimal Amount { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Amount to be paid out to the loaner
|
|
||||||
/// </summary>
|
|
||||||
public required decimal PayoutAmount { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Date and time loan entry was created
|
|
||||||
/// </summary>
|
|
||||||
public required DateTimeOffset Created { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class KasinoShopProfileAssetDbModel
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// ID for the database row
|
|
||||||
/// </summary>
|
|
||||||
public int Id { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Profile of the user who owns this asset
|
|
||||||
/// </summary>
|
|
||||||
public required KasinoShopProfileDbModel Profile { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Value of the item at the time of acquisition in Krypto
|
|
||||||
/// </summary>
|
|
||||||
public required decimal OriginalValue { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Asset name
|
|
||||||
/// </summary>
|
|
||||||
public required string Name { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Asset type
|
|
||||||
/// </summary>
|
|
||||||
public required AssetType AssetType { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Date and time the asset was acquired
|
|
||||||
/// </summary>
|
|
||||||
public required DateTimeOffset Acquired { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// History of value changes (e.g. interest events)
|
|
||||||
/// </summary>
|
|
||||||
public required List<KasinoShopProfileAssetValueChangeDbModel> ValueChangeReports { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Serialized JSON for extra information useful for certain assets (e.g. car model)
|
|
||||||
/// </summary>
|
|
||||||
public string? Extra { get; set; } = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class KasinoShopProfileAssetValueChangeDbModel
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// ID for the database row
|
|
||||||
/// </summary>
|
|
||||||
public int Id { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Related asset
|
|
||||||
/// </summary>
|
|
||||||
public required KasinoShopProfileAssetDbModel Asset { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Effect of the change
|
|
||||||
/// </summary>
|
|
||||||
public required decimal ValueChangeEffect { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Change percent as a decimal fraction?
|
|
||||||
/// </summary>
|
|
||||||
public required decimal ValueChangePercent { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Descriptive text for the value change (like the source of it)
|
|
||||||
/// </summary>
|
|
||||||
public required string Description { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum GamblerPerkType
|
public enum GamblerPerkType
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
9
KfChatDotNetBot/Models/KasinoShopModels.cs
Normal file
9
KfChatDotNetBot/Models/KasinoShopModels.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace KfChatDotNetBot.Models;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Holds state information for the kasino shop
|
||||||
|
/// </summary>
|
||||||
|
public class KasinoShopStateModel
|
||||||
|
{
|
||||||
|
public required decimal DefaultHouseEdgeModifier { get; set; } = 0;
|
||||||
|
}
|
||||||
@@ -1,18 +1,9 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using KfChatDotNetBot.Extensions;
|
using KfChatDotNetBot.Extensions;
|
||||||
using KfChatDotNetBot.Models;
|
|
||||||
using KfChatDotNetBot.Models.DbModels;
|
using KfChatDotNetBot.Models.DbModels;
|
||||||
using KfChatDotNetBot.Settings;
|
using KfChatDotNetBot.Settings;
|
||||||
using NLog;
|
using NLog;
|
||||||
using StackExchange.Redis;
|
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 Microsoft.EntityFrameworkCore;
|
||||||
using RandN;
|
using RandN;
|
||||||
using RandN.Compat;
|
using RandN.Compat;
|
||||||
|
|||||||
Reference in New Issue
Block a user