68 lines
2.1 KiB
C#
68 lines
2.1 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
namespace DataServer.Data;
|
|
|
|
/// <summary>
|
|
/// Tracks player statistics for Void Scavengers
|
|
/// </summary>
|
|
public sealed class PlayerStats
|
|
{
|
|
public ulong Id { get; set; }
|
|
public ulong AccountId { get; set; }
|
|
|
|
// Match stats
|
|
public int MatchesPlayed { get; set; }
|
|
public int Wins { get; set; }
|
|
public int Losses { get; set; }
|
|
public int Extractions { get; set; } // Successful extractions (counts as win)
|
|
|
|
// Combat stats
|
|
public int Kills { get; set; }
|
|
public int Deaths { get; set; }
|
|
public long TotalDamageDealt { get; set; }
|
|
public long TotalDamageTaken { get; set; }
|
|
|
|
// Resource stats
|
|
public long TotalScrapCollected { get; set; }
|
|
public long TotalEnergyCollected { get; set; }
|
|
public long TotalRareCollected { get; set; }
|
|
public int ItemsCrafted { get; set; }
|
|
|
|
// Time stats
|
|
public long TotalPlayTimeSeconds { get; set; }
|
|
public int LongestSurvivalSeconds { get; set; }
|
|
|
|
// Ratings
|
|
public int Elo { get; set; } = 1000; // Starting Elo rating
|
|
|
|
// Timestamps
|
|
public DateTime CreatedAt { get; set; }
|
|
public DateTime UpdatedAt { get; set; }
|
|
|
|
// Navigation
|
|
public Account Account { get; set; } = null!;
|
|
}
|
|
|
|
public sealed class PlayerStatsConfig : IEntityTypeConfiguration<PlayerStats>
|
|
{
|
|
public void Configure(EntityTypeBuilder<PlayerStats> e)
|
|
{
|
|
e.ToTable("player_stats");
|
|
e.HasKey(x => x.Id);
|
|
e.Property(x => x.Id).ValueGeneratedOnAdd();
|
|
|
|
e.HasIndex(x => x.AccountId).IsUnique();
|
|
|
|
e.HasOne(x => x.Account)
|
|
.WithOne()
|
|
.HasForeignKey<PlayerStats>(x => x.AccountId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
e.Property(x => x.Elo).HasDefaultValue(1000);
|
|
e.Property(x => x.CreatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)");
|
|
e.Property(x => x.UpdatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)")
|
|
.ValueGeneratedOnAddOrUpdate();
|
|
}
|
|
}
|