public async Task AddWarpStart(AuthorizationTokenContainer tokenContainer, SelectedShipContainer selectedShipContainer) { GetPlayerByAccessTokenResponse playerByAccessTokenResponse = _authService.GetPlayerByAccessToken(tokenContainer.Token); if (playerByAccessTokenResponse.Success && playerByAccessTokenResponse.Player.IsAdmin == true) { GetShipsByPlayerIdResponse serviceResult = _gameService.GetShipByPlayerId(playerByAccessTokenResponse.Player.Id, selectedShipContainer.ShipId); if (serviceResult.Success) { Ship ship = serviceResult.Ships.First(); CreateSpaceObjectResult spaceObjectResult = _objectService.SpawnWarpGate(ship.X, ship.Y, ship.Z); if (spaceObjectResult.Success == true) { await Clients.Caller.ReceiveMessage("Space object #" + spaceObjectResult.SpaceObject.Id + " created."); } else { await Clients.Caller.ReceiveMessage("Space object could not be created."); } } else { await Clients.Caller.ReceiveError(new ErrorFromServer("Could not retrieve the ship you are piloting for object placement or selection purposes.")); } } else { await Clients.Caller.ReceiveError(new ErrorFromServer("Warp start selection is only available to administrators.")); } }
public CreateSpaceObjectResult SpawnWarpGate(int x, int y, int z) { var result = new CreateSpaceObjectResult(); int count = _wrapper.SpaceObjectRepository.GetAll <SpaceObject>(f => f.X == x && f.Y == y && f.Z == z && f.ObjectType == "Warpgate").Count; if (count == 0) { var newObject = new SpaceObject("Warpgate", "Unnamed warpgate"); newObject.X = x; newObject.Y = y; newObject.Z = z; newObject.DestinationSpaceObjectId = Guid.Empty; _wrapper.SpaceObjectRepository.AddOne <SpaceObject>(newObject); result.Success = true; result.SpaceObject = newObject; } else { result.Success = false; } return(result); }