Exemplo n.º 1
0
        public ConnectWarpgateResult ConnectWarpGate(int x, int y, int z, Guid startWarpgateId)
        {
            var         result = new ConnectWarpgateResult();
            int         count  = _wrapper.SpaceObjectRepository.GetAll <SpaceObject>(f => f.X == x && f.Y == y && f.Z == z && f.ObjectType == "Warpgate").Count;
            SpaceObject destinationObject;

            if (count == 0)
            {
                destinationObject   = new SpaceObject("Warpgate", "Unnamed warpgate");
                destinationObject.X = x;
                destinationObject.Y = y;
                destinationObject.Z = z;
                destinationObject.DestinationSpaceObjectId = Guid.Empty;
                _wrapper.SpaceObjectRepository.AddOne <SpaceObject>(destinationObject);
            }
            else
            {
                destinationObject = _wrapper.SpaceObjectRepository.GetOne <SpaceObject>(f => f.X == x && f.Y == y && f.Z == z && f.ObjectType == "Warpgate");
            }
            destinationObject.DestinationSpaceObjectId = startWarpgateId;
            SpaceObject startingObject = _wrapper.SpaceObjectRepository.GetOne <SpaceObject>(f => f.Id == startWarpgateId);

            startingObject.DestinationSpaceObjectId = destinationObject.Id;
            _wrapper.SpaceObjectRepository.UpdateOne <SpaceObject>(destinationObject);
            _wrapper.SpaceObjectRepository.UpdateOne <SpaceObject>(startingObject);
            result.Success             = true;
            result.SourceObjectId      = startingObject.Id;
            result.DestinationObjectId = destinationObject.Id;
            return(result);
        }
Exemplo n.º 2
0
        public async Task AddWarpEnd(AuthorizationTokenContainer tokenContainer, SelectedShipContainer selectedShipContainer, SelectedWarpStartContainer selectedWarpStart)
        {
            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();
                    ConnectWarpgateResult connectResult = _objectService.ConnectWarpGate(ship.X, ship.Y, ship.Z, selectedWarpStart.WarpStartId);
                    if (connectResult.Success == true)
                    {
                        await Clients.Caller.ReceiveMessage("Connected warpgates together: " + connectResult.SourceObjectId + " --> " + connectResult.DestinationObjectId);
                    }
                    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 ending spot creation is only available to administrators."));
            }
        }