using Unity.Entities; using Unity.NetCode; using EE2Clone.Core; namespace EE2Clone.Components { [GhostComponent(PrefabType = GhostPrefabType.All)] public struct PlayerStateComponent : IComponentData { [GhostField] public int PlayerId; [GhostField] public Epoch CurrentEpoch; [GhostField] public int PopulationCurrent; [GhostField] public int PopulationMax; [GhostField] public int CivilizationId; [GhostField] public bool IsAlive; } [GhostComponent(PrefabType = GhostPrefabType.All)] public struct PlayerResourcesComponent : IComponentData { [GhostField] public int Food; [GhostField] public int Wood; [GhostField] public int Stone; [GhostField] public int Gold; [GhostField] public int Tin; public int GetResource(ResourceType type) { return type switch { ResourceType.Food => Food, ResourceType.Wood => Wood, ResourceType.Stone => Stone, ResourceType.Gold => Gold, ResourceType.Tin => Tin, _ => 0 }; } public void AddResource(ResourceType type, int amount) { switch (type) { case ResourceType.Food: Food += amount; break; case ResourceType.Wood: Wood += amount; break; case ResourceType.Stone: Stone += amount; break; case ResourceType.Gold: Gold += amount; break; case ResourceType.Tin: Tin += amount; break; } } public bool TrySpend(ResourceType type, int amount) { if (GetResource(type) < amount) return false; AddResource(type, -amount); return true; } } }