Files
territory-autobattler/microservices/LocationsApi/Models/Dto.cs
T

123 lines
4.6 KiB
C#

namespace LocationsApi.Models;
public class UpsertLocationRequest
{
public int Q { get; set; }
public int R { get; set; }
public string Terrain { get; set; } = "Field";
public string? Label { get; set; }
public int Level { get; set; } = 1;
}
public class ClaimLocationRequest
{
public int Q { get; set; }
public int R { get; set; }
}
public class BuildLocationRequest
{
public int Q { get; set; }
public int R { get; set; }
public string BuildingType { get; set; } = "LogCamp";
}
public class AssignWorkerRequest
{
public int Q { get; set; }
public int R { get; set; }
public string UnitId { get; set; } = "";
}
public class DeassignWorkerRequest
{
public int Q { get; set; }
public int R { get; set; }
}
public class TerritoryLocationRequest
{
public int Q { get; set; }
public int R { get; set; }
}
public class LocationResponse
{
public string Id { get; set; } = "";
public int Q { get; set; }
public int R { get; set; }
public string Terrain { get; set; } = "Field";
public string Kind { get; set; } = "Open";
public string? OwnerUsername { get; set; }
public string? Label { get; set; }
public int Level { get; set; }
public string? BuildingType { get; set; }
public string? BuildingStatus { get; set; }
public DateTime? BuildingStartedAtUtc { get; set; }
public DateTime? BuildingCompletesAtUtc { get; set; }
public DateTime? BuildingBuiltAtUtc { get; set; }
public string? WorkerUnitId { get; set; }
public string? WorkerUnitType { get; set; }
public int StoredResourceAmount { get; set; }
public int StoredResourceCapacity { get; set; }
public DateTime? LastResourceGeneratedAtUtc { get; set; }
public DateTime? HomeAssignedAtUtc { get; set; }
public DateTime UpdatedAtUtc { get; set; }
public bool IsVisible { get; set; } = true;
public static LocationResponse FromLocation(Location location, bool revealDetails = true) => new()
{
Id = location.Id,
Q = location.Q,
R = location.R,
Terrain = location.Terrain,
Kind = location.Kind,
OwnerUsername = location.OwnerUsername,
Label = location.Label,
Level = location.Level,
BuildingType = revealDetails ? location.BuildingType : null,
BuildingStatus = revealDetails && (location.BuildingType == "LogCamp" || location.BuildingType == "Mine" || location.BuildingType == "Barracks" || location.BuildingType == "Farm") && string.IsNullOrWhiteSpace(location.BuildingStatus)
? "Built"
: revealDetails ? location.BuildingStatus : null,
BuildingStartedAtUtc = revealDetails ? location.BuildingStartedAtUtc : null,
BuildingCompletesAtUtc = revealDetails ? location.BuildingCompletesAtUtc : null,
BuildingBuiltAtUtc = revealDetails ? location.BuildingBuiltAtUtc : null,
WorkerUnitId = revealDetails ? location.WorkerUnitId : null,
WorkerUnitType = revealDetails ? location.WorkerUnitType : null,
StoredResourceAmount = revealDetails ? location.StoredResourceAmount : 0,
StoredResourceCapacity = revealDetails ? location.StoredResourceCapacity : 0,
LastResourceGeneratedAtUtc = revealDetails ? location.LastResourceGeneratedAtUtc : null,
HomeAssignedAtUtc = location.HomeAssignedAtUtc,
UpdatedAtUtc = location.UpdatedAtUtc,
IsVisible = true
};
public static LocationResponse FromIntel(LocationIntel intel) => new()
{
Id = intel.Id,
Q = intel.Q,
R = intel.R,
Terrain = intel.Terrain,
Kind = intel.Kind,
OwnerUsername = intel.OwnerUsername,
Label = intel.Label,
Level = intel.Level,
BuildingType = intel.BuildingType,
BuildingStatus = (intel.BuildingType == "LogCamp" || intel.BuildingType == "Mine" || intel.BuildingType == "Barracks" || intel.BuildingType == "Farm") && string.IsNullOrWhiteSpace(intel.BuildingStatus)
? "Built"
: intel.BuildingStatus,
BuildingStartedAtUtc = intel.BuildingStartedAtUtc,
BuildingCompletesAtUtc = intel.BuildingCompletesAtUtc,
BuildingBuiltAtUtc = intel.BuildingBuiltAtUtc,
WorkerUnitId = intel.WorkerUnitId,
WorkerUnitType = intel.WorkerUnitType,
StoredResourceAmount = intel.StoredResourceAmount,
StoredResourceCapacity = intel.StoredResourceCapacity,
LastResourceGeneratedAtUtc = intel.LastResourceGeneratedAtUtc,
HomeAssignedAtUtc = intel.HomeAssignedAtUtc,
UpdatedAtUtc = intel.ObservedAtUtc,
IsVisible = true
};
}