77 lines
2.1 KiB
C#
77 lines
2.1 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
namespace DataServer.Data;
|
|
|
|
/// <summary>
|
|
/// Records individual match results for Void Scavengers
|
|
/// </summary>
|
|
public sealed class MatchHistory
|
|
{
|
|
public ulong Id { get; set; }
|
|
public string MatchId { get; set; } = ""; // The game's match ID
|
|
public ulong AccountId { get; set; }
|
|
|
|
// Result
|
|
public MatchResult Result { get; set; }
|
|
public int Placement { get; set; } // 1st, 2nd, etc.
|
|
public int TotalPlayers { get; set; }
|
|
|
|
// Match performance
|
|
public int Kills { get; set; }
|
|
public int Deaths { get; set; }
|
|
public int DamageDealt { get; set; }
|
|
public int DamageTaken { get; set; }
|
|
|
|
// Resources
|
|
public int ScrapCollected { get; set; }
|
|
public int EnergyCollected { get; set; }
|
|
public int RareCollected { get; set; }
|
|
public int ItemsCrafted { get; set; }
|
|
|
|
// Time
|
|
public int SurvivalTimeSeconds { get; set; }
|
|
public int MatchDurationSeconds { get; set; }
|
|
|
|
// Elo change
|
|
public int EloChange { get; set; }
|
|
public int EloAfter { get; set; }
|
|
|
|
// Timestamp
|
|
public DateTime PlayedAt { get; set; }
|
|
|
|
// Navigation
|
|
public Account Account { get; set; } = null!;
|
|
}
|
|
|
|
public enum MatchResult
|
|
{
|
|
Loss = 0,
|
|
Win = 1,
|
|
Extracted = 2, // Special win type
|
|
Disconnected = 3
|
|
}
|
|
|
|
public sealed class MatchHistoryConfig : IEntityTypeConfiguration<MatchHistory>
|
|
{
|
|
public void Configure(EntityTypeBuilder<MatchHistory> e)
|
|
{
|
|
e.ToTable("match_history");
|
|
e.HasKey(x => x.Id);
|
|
e.Property(x => x.Id).ValueGeneratedOnAdd();
|
|
|
|
e.HasIndex(x => x.AccountId);
|
|
e.HasIndex(x => x.MatchId);
|
|
e.HasIndex(x => x.PlayedAt);
|
|
|
|
e.Property(x => x.MatchId).HasMaxLength(32).IsRequired();
|
|
|
|
e.HasOne(x => x.Account)
|
|
.WithMany()
|
|
.HasForeignKey(x => x.AccountId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
e.Property(x => x.PlayedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)");
|
|
}
|
|
}
|