private void VerifyUnit(GameDef gameDef, PlayerImmutable player, UnitImmutable unit) { gameDef.ValidateUnitDefId(unit.UnitDefId, $"Player '{player.PlayerId}' Units"); if (!gameDef.GetUnitsByPlayerType(player.PlayerType).Any(x => x.Id.Equals(unit.UnitDefId))) { throw new InvalidGameDefException($"Unit {unit.UnitDefId} does not match player's type '{player.PlayerType}'"); } }
public static UnitViewModel ToUnitViewModel(this UnitImmutable unit, UnitRepository unitRepository, CurrentUserContext currentUserContext, GameDef gameDef) { var unitDef = gameDef.GetUnitDef(unit.UnitDefId); if (unitDef == null) { throw new InvalidGameDefException($"Unit '{unit.UnitDefId}' not found"); } return(new UnitViewModel { UnitId = unit.UnitId.Id, Definition = UnitDefinitionViewModel.Create(unitDef, unitRepository.PrerequisitesMet(currentUserContext.PlayerId, unitDef)), Count = unit.Count, PositionPlayerId = unit.Position?.Id }); }