public async Task <ActionResult> ReplaceBoat(Guid id, [FromBody] BoatEntity replacementBoat)
        {
            if (id == null || id == Guid.Empty)
            {
                return(BadRequest());
            }

            if (replacementBoat == null)
            {
                return(BadRequest("The body must contain Json."));
            }

            if (replacementBoat.Name == null)
            {
                return(BadRequest($"The request body must have a name for the boat."));
            }

            if (replacementBoat.Type == null)
            {
                return(BadRequest("The request body must have a type for the boat."));
            }

            if (replacementBoat.Length <= 0)
            {
                return(BadRequest("invalid length."));
            }

            if (replacementBoat.Id != Guid.Empty)
            {
                return(BadRequest("The id cannot be included."));
            }

            replacementBoat.Id    = id;
            replacementBoat.AtSea = true;

            BoatEntity boat;

            try
            {
                boat = await _boatService.GetAsync(id);
            }
            catch (DocumentClientException ex)
            {
                if (ex.Message.Contains("Resource Not Found"))
                {
                    return(BadRequest("Boat does not exist"));
                }
            }

            try
            {
                await _boatService.UpsertAsync(replacementBoat);

                return(Ok(new BoatResponseEntity(replacementBoat)));
            }
            catch
            {
                return(StatusCode(500));
            }
        }
Beispiel #2
0
            public static List <VehicleEntity> VehicleToDalObjects(List <Vehicle> vehicles)
            {
                var vehiclesToSave = new List <VehicleEntity>();

                vehiclesToSave = vehicles.Select(a => {
                    VehicleEntity v = null;
                    if (a is AirPlane aPlane)
                    {
                        v = new AirPlaneEntity
                        {
                            NumberOfAirPlaneWings = aPlane.NumberOfAirPlaneWings
                        };
                    }
                    else if (a is Boat aBoat)
                    {
                        v = new BoatEntity
                        {
                            NumberOfBoatSails = aBoat.NumberOfBoatSails
                        };
                    }
                    else if (a is Bus aBuss)
                    {
                        v = new BusEntity
                        {
                            BusMaxNumberOfStandingPassengers = aBuss.BusMaxNumberOfStandingPassengers
                        };
                    }
                    else if (a is Car aCar)
                    {
                        v = new CarEntity
                        {
                            NumberOfCarSeats = aCar.NumberOfCarSeats
                        };
                    }
                    else if (a is MotorCycle aMc)
                    {
                        v = new MotorCycleEntity
                        {
                            MotorCycleTopSpeed = aMc.MotorCycleTopSpeed
                        };
                    }

                    if (v == null)
                    {
                        throw new Exception("Unhandled Vehicle Type");
                    }

                    v.LicenseNo      = a.LicenseNo;
                    v.Color          = ColorHelperDAL.ParseColor(a.Color.ToString());
                    v.NumberOfWheels = a.NumberOfWheels;
                    return(v);
                }).ToList();

                return(vehiclesToSave);
            }
        public async Task <ActionResult> DeleteSlip(Guid id)
        {
            if (id == null || id == Guid.Empty)
            {
                return(BadRequest());
            }

            SlipEntity slip;

            try
            {
                slip = await _slipService.GetAsync(id);
            }
            catch (DocumentClientException ex)
            {
                if (ex.Message.Contains("Resource Not Found"))
                {
                    return(BadRequest("Slip does not exist"));
                }

                return(StatusCode(500));
            }

            if (slip.CurrentBoat.HasValue)
            {
                try
                {
                    BoatEntity boat = await _boatService.GetAsync(slip.CurrentBoat.Value);

                    boat.AtSea = true;
                    await _boatService.UpsertAsync(boat);
                }
                catch (DocumentClientException ex)
                {
                    if (!ex.Message.Contains("Resource Not Found"))
                    {
                        return(StatusCode(500));
                    }
                }
            }

            try
            {
                await _slipService.DeleteAsync(slip.Id);

                return(Ok());
            }
            catch
            {
                return(StatusCode(500));
            }
        }
Beispiel #4
0
    public static void SpawnProjectile(Packet packet)
    {
        int            id             = packet.ReadInt();
        ProjectileType type           = (ProjectileType)packet.ReadInt();
        int            boatId         = packet.ReadInt();
        int            boatEntityId   = packet.ReadInt();
        BoatEntityType boatEntityType = (BoatEntityType)packet.ReadInt();


        Boat               boat               = BoatManager.Boats[boatId];
        BoatEntity         boatEntity         = boat.boatEntitiesByType[boatEntityType][boatEntityId];
        ProjectileLauncher projectileLauncher = boatEntity as ProjectileLauncher;
        Transform          launcher           = projectileLauncher != null?projectileLauncher.GetLauncher() : boatEntity.transform;

        Projectile projectile = GameObject.Instantiate <Projectile>(ProjectileByType[(ProjectileType)type], launcher.position, launcher.rotation);

        projectile.TargetPosition = launcher.position;
        Projectiles.Add(id, projectile);
    }
    public static void RecieveBoatsFromServer(Packet packet)
    {
        Debug.Log("Recieving Boats");
        int boatCount = packet.ReadInt();

        for (int i = 1; i <= boatCount; i++)
        {
            int        id  = packet.ReadInt();
            Vector3    pos = packet.ReadVector3();
            Quaternion rot = packet.ReadQuaternion();

            Boat boat = GameObject.Instantiate <Boat>(instance.boatPrefab, pos, rot);
            boat.Init(id);

            int boatEntityTypeCount = packet.ReadInt();

            for (int ii = 1; ii <= boatEntityTypeCount; ii++)
            {
                BoatEntityType boatEntityType    = (BoatEntityType)packet.ReadInt();
                int            entityOfTypeCount = packet.ReadInt();

                for (int iii = 1; iii <= entityOfTypeCount; iii++)
                {
                    int        entiyId       = packet.ReadInt();
                    Vector3    localPosition = packet.ReadVector3();
                    Quaternion localRotation = packet.ReadQuaternion();
                    Vector3    localScale    = packet.ReadVector3();

                    BoatEntity entity = Instantiate <BoatEntity>(BoatEntityByType[boatEntityType], boat.transform);
                    entity.id = entiyId;
                    entity.transform.localPosition = localPosition;
                    entity.transform.localRotation = localRotation;
                    entity.transform.localScale    = localScale;
                    entity.ReadDataFromPacket(packet);

                    boat.boatEntitiesByType[boatEntityType][entity.id] = entity;
                }
            }

            Boats.Add(boat.id, boat);
        }
    }
        public async Task <ActionResult> AddBoat([FromBody] BoatEntity boat)
        {
            if (boat == null)
            {
                return(BadRequest("The body must contain Json."));
            }

            if (boat.Name == null)
            {
                return(BadRequest($"The request body must have a name for the boat."));
            }

            if (boat.Type == null)
            {
                return(BadRequest("The request body must have a type for the boat."));
            }

            if (boat.Length <= 0)
            {
                return(BadRequest("invalid length."));
            }

            if (boat.Id != Guid.Empty)
            {
                return(BadRequest("The id cannot be included."));
            }

            boat.Id    = Guid.NewGuid();
            boat.AtSea = true;

            try
            {
                await _boatService.UpsertAsync(boat);

                return(Ok(new BoatResponseEntity(boat)));
            }
            catch
            {
                return(StatusCode(500));
            }
        }
    public static void HandleBoatTransformUpdate(Packet packet)
    {
        int        id  = packet.ReadInt();
        Vector3    pos = packet.ReadVector3();
        Quaternion rot = packet.ReadQuaternion();

        if (!BoatManager.Boats.ContainsKey(id))
        {
            return;
        }

        Boat boat = BoatManager.Boats[id];

        boat.TargetPosition     = pos;
        boat.transform.rotation = rot;

        int boatEntityTypeCount = packet.ReadInt();

        for (int ii = 1; ii <= boatEntityTypeCount; ii++)
        {
            BoatEntityType boatEntityType    = (BoatEntityType)packet.ReadInt();
            int            entityOfTypeCount = packet.ReadInt();

            for (int iii = 1; iii <= entityOfTypeCount; iii++)
            {
                int        entiyyId      = packet.ReadInt();
                Vector3    localPosition = packet.ReadVector3();
                Quaternion localRotation = packet.ReadQuaternion();
                Vector3    localScale    = packet.ReadVector3();

                BoatEntity entity = boat.boatEntitiesByType[boatEntityType][entiyyId];
                entity.transform.localPosition = localPosition;
                entity.transform.localRotation = localRotation;
                entity.transform.localScale    = localScale;
                entity.ReadDataFromPacket(packet);
            }
        }
    }
        public async Task <ActionResult> ModifyBoat(Guid id, [FromBody] BoatEntity inputBoat)
        {
            // Input validation. Catch easy errors before going to data layer

            if (id == null || id == Guid.Empty)
            {
                return(BadRequest());
            }

            if (inputBoat == null)
            {
                return(BadRequest("At least one property must be modified."));
            }

            if (inputBoat.Length < 0)
            {
                return(BadRequest("Boat length cannot be negative."));
            }

            // Now pull the boat from the data layer and modify it if needed

            BoatEntity boat;

            try
            {
                boat = await _boatService.GetAsync(id);
            }
            catch (DocumentClientException ex)
            {
                if (ex.Message.Contains("Resource Not Found"))
                {
                    return(BadRequest("Boat does not exist"));
                }

                return(StatusCode(500));
            }

            bool changed = false;

            if (inputBoat.Name != null)
            {
                boat.Name = inputBoat.Name;
                changed   = true;
            }

            if (inputBoat.Type != null)
            {
                boat.Type = inputBoat.Type;
                changed   = true;
            }

            if (inputBoat.Length > 0)
            {
                boat.Length = inputBoat.Length;
                changed     = true;
            }

            if (changed == true)
            {
                await _boatService.UpsertAsync(boat);
            }

            return(Ok(new BoatResponseEntity(boat)));
        }