Files
systemrevivalserver/data/entities/Old_Character.cs
T
2025-12-06 11:20:32 -05:00

65 lines
2.2 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Server.Data;
public sealed class Old_Character
{
public ulong Id { get; set; }
public ulong AccountId { get; set; }
public string Name { get; set; } = "";
public uint Level { get; set; } = 1;
public ulong Xp { get; set; } = 0;
public uint StatStrength { get; set; } = 1;
public uint StatDexterity { get; set; } = 1;
public uint StatWisdom { get; set; } = 1;
public uint StatIntelligence { get; set; } = 1;
public uint StatEndurance { get; set; } = 1;
public uint HpCurrent { get; set; } = 10;
public uint HpMax { get; set; } = 10;
public uint MpCurrent { get; set; } = 0;
public uint MpMax { get; set; } = 0;
public uint StaminaCurrent { get; set; } = 0;
public uint StaminaMax { get; set; } = 0;
public ulong ZoneId { get; set; }
public double PosX { get; set; }
public double PosY { get; set; }
public double PosZ { get; set; }
public float FacingDeg { get; set; }
// store as JSON in MySQL 8
public string? AppearanceJson { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
public Account? Account { get; set; }
public Zone? Zone { get; set; }
}
public sealed class CharacterConfig : IEntityTypeConfiguration<Old_Character>
{
public void Configure(EntityTypeBuilder<Old_Character> e)
{
e.ToTable("characters");
e.HasKey(x => x.Id);
e.Property(x => x.Id).ValueGeneratedOnAdd();
e.Property(x => x.Name).HasMaxLength(32).IsRequired();
e.HasIndex(x => x.AccountId).IsUnique(); // 1 character per account (change later if needed)
e.HasIndex(x => x.ZoneId);
e.Property(x => x.AppearanceJson).HasColumnType("json");
e.Property(x => x.CreatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)");
e.Property(x => x.UpdatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)")
.ValueGeneratedOnAddOrUpdate();
e.HasOne(x => x.Account).WithMany(a => a.Characters).HasForeignKey(x => x.AccountId).OnDelete(DeleteBehavior.Cascade);
e.HasOne(x => x.Zone).WithMany().HasForeignKey(x => x.ZoneId).OnDelete(DeleteBehavior.Restrict);
}
}