228 lines
No EOL
6.1 KiB
C#
228 lines
No EOL
6.1 KiB
C#
namespace HRServer.Models
|
|
{
|
|
public enum Gender
|
|
{
|
|
Male,
|
|
Female
|
|
}
|
|
public static class HorseFactory
|
|
{
|
|
// Thread-safe Dictionary, um gleichzeitigen Zugriff zu ermöglichen
|
|
private static readonly Dictionary<ulong, Horse> Horses = new();
|
|
|
|
// Methode, um ein Pferd nach ID zu suchen
|
|
public static Horse? GetHorse(ulong id)
|
|
{
|
|
// Verwende Dictionary.TryGetValue für bessere Performance und Lesbarkeit
|
|
return Horses.TryGetValue(id, out var horse) ? horse : null;
|
|
}
|
|
|
|
// Methode, um ein Pferd hinzuzufügen oder zu aktualisieren
|
|
public static void AddOrUpdateHorse(Horse horse)
|
|
{
|
|
if (horse == null || horse.Id == null)
|
|
throw new ArgumentNullException(nameof(horse), "Horse or its ID cannot be null.");
|
|
|
|
Horses[horse.Id.Value] = horse;
|
|
}
|
|
|
|
// Methode, um alle Pferde zu holen (z. B. für Debugging oder Verarbeitung)
|
|
public static IReadOnlyDictionary<ulong, Horse> GetAllHorses()
|
|
{
|
|
return Horses;
|
|
}
|
|
}
|
|
|
|
public class Horse
|
|
{
|
|
// Basic Information
|
|
private ulong? _id;
|
|
private int? _age;
|
|
private string _horseName = string.Empty;
|
|
private string _gender = string.Empty;
|
|
private string _breed = string.Empty;
|
|
private string _link = string.Empty;
|
|
|
|
public ulong? Id
|
|
{
|
|
get => _id;
|
|
set
|
|
{
|
|
_id = value;
|
|
LoadState.BasicInfoLoaded = true;
|
|
}
|
|
}
|
|
|
|
public int? Age
|
|
{
|
|
get => _age;
|
|
set
|
|
{
|
|
_age = value;
|
|
LoadState.BasicInfoLoaded = true;
|
|
}
|
|
}
|
|
|
|
public string HorseName
|
|
{
|
|
get => _horseName;
|
|
set
|
|
{
|
|
_horseName = value;
|
|
LoadState.BasicInfoLoaded = true;
|
|
}
|
|
}
|
|
|
|
public string Gender
|
|
{
|
|
get => _gender;
|
|
set
|
|
{
|
|
_gender = value;
|
|
LoadState.BasicInfoLoaded = true;
|
|
}
|
|
}
|
|
|
|
public string Breed
|
|
{
|
|
get => _breed;
|
|
set
|
|
{
|
|
_breed = value;
|
|
LoadState.BasicInfoLoaded = true;
|
|
}
|
|
}
|
|
|
|
public string Link
|
|
{
|
|
get => _link;
|
|
set
|
|
{
|
|
_link = value;
|
|
LoadState.BasicInfoLoaded = true;
|
|
}
|
|
}
|
|
|
|
// Other Sections
|
|
private HorseSummary _summary = new();
|
|
public HorseSummary Summary
|
|
{
|
|
get => _summary;
|
|
set
|
|
{
|
|
_summary = value;
|
|
LoadState.SummaryLoaded = true;
|
|
}
|
|
}
|
|
|
|
private HorseTraining _training = new();
|
|
public HorseTraining Training
|
|
{
|
|
get => _training;
|
|
set
|
|
{
|
|
_training = value;
|
|
LoadState.TrainingLoaded = true;
|
|
}
|
|
}
|
|
|
|
private HorseGenetics _genetics = new();
|
|
public HorseGenetics Genetics
|
|
{
|
|
get => _genetics;
|
|
set
|
|
{
|
|
_genetics = value;
|
|
LoadState.GeneticsLoaded = true;
|
|
}
|
|
}
|
|
|
|
private HorseAchievements _achievements = new();
|
|
public HorseAchievements Achievements
|
|
{
|
|
get => _achievements;
|
|
set
|
|
{
|
|
_achievements = value;
|
|
LoadState.AchievementsLoaded = true;
|
|
}
|
|
}
|
|
|
|
private HorseHealth _health = new();
|
|
public HorseHealth Health
|
|
{
|
|
get => _health;
|
|
set
|
|
{
|
|
_health = value;
|
|
LoadState.HealthLoaded = true;
|
|
}
|
|
}
|
|
|
|
// Load State
|
|
public DataLoadState LoadState { get; set; } = new();
|
|
|
|
// Helper Methods
|
|
public bool IsAllDataLoaded()
|
|
{
|
|
return LoadState.IsAllDataLoaded();
|
|
}
|
|
|
|
public void PrintLoadState()
|
|
{
|
|
Console.WriteLine("Load State of Horse Data:");
|
|
Console.WriteLine($"- Basic Info Loaded: {LoadState.BasicInfoLoaded}");
|
|
Console.WriteLine($"- Summary Loaded: {LoadState.SummaryLoaded}");
|
|
Console.WriteLine($"- Training Loaded: {LoadState.TrainingLoaded}");
|
|
Console.WriteLine($"- Genetics Loaded: {LoadState.GeneticsLoaded}");
|
|
Console.WriteLine($"- Achievements Loaded: {LoadState.AchievementsLoaded}");
|
|
Console.WriteLine($"- Health Loaded: {LoadState.HealthLoaded}");
|
|
}
|
|
}
|
|
|
|
// Class to track the loading state of data
|
|
public class DataLoadState
|
|
{
|
|
public bool BasicInfoLoaded { get; set; } = false;
|
|
public bool SummaryLoaded { get; set; } = false;
|
|
public bool TrainingLoaded { get; set; } = false;
|
|
public bool GeneticsLoaded { get; set; } = false;
|
|
public bool AchievementsLoaded { get; set; } = false;
|
|
public bool HealthLoaded { get; set; } = false;
|
|
|
|
// Method to check if all data is loaded
|
|
public bool IsAllDataLoaded()
|
|
{
|
|
return BasicInfoLoaded && SummaryLoaded && TrainingLoaded && GeneticsLoaded && AchievementsLoaded && HealthLoaded;
|
|
}
|
|
}
|
|
|
|
// Other classes
|
|
public class HorseSummary
|
|
{
|
|
public List<ulong> RelatedIds { get; set; } = new();
|
|
}
|
|
|
|
public class HorseTraining
|
|
{
|
|
public string Training { get; set; } = string.Empty;
|
|
}
|
|
|
|
public class HorseGenetics
|
|
{
|
|
public int GP { get; set; }
|
|
public Dictionary<string, int> Features { get; set; } = new();
|
|
public string Extension { get; set; } = string.Empty;
|
|
}
|
|
|
|
public class HorseAchievements
|
|
{
|
|
public Dictionary<string, int> Conformation { get; set; } = new();
|
|
public string ShortConformation { get; set; } = string.Empty;
|
|
}
|
|
|
|
public class HorseHealth
|
|
{
|
|
public string Fertility { get; set; } = string.Empty;
|
|
}
|
|
} |