Esempio n. 1
0
        public Task <IVehicle> SpawnVehicleAsync(Vector3 position, string vehicleId, IVehicleState state = null)
        {
            async UniTask <IVehicle> VehicleSpawnTask()
            {
                await UniTask.SwitchToMainThread();

                if (!ushort.TryParse(vehicleId, out var parsedVehicleId))
                {
                    throw new Exception($"Invalid vehicle id: {vehicleId}");
                }

                var vehicleAsset = (ItemAsset)Assets.find(EAssetType.ITEM, parsedVehicleId);

                if (vehicleAsset == null || vehicleAsset.isPro)
                {
                    return(null);
                }

                if (state != null)
                {
                    // todo: use state like VehicleManager.load() does
                }

                var vehicle = VehicleManager.spawnVehicleV2(vehicleAsset.id, position.ToUnityVector(), Quaternion.identity);

                return(new UnturnedVehicle(vehicle));
            }

            return(VehicleSpawnTask().AsTask());
        }
        void Awake()
        {
            agent = GetComponent <NavMeshAgent>();

            currentState = new VehicleOperableState();
            currentState.Execute(this);
        }
Esempio n. 3
0
        public async Task <IVehicleState> SendEvent(IVehicleState state, string IMEI, string Vin = null)
        {
            var simulatedEvent = _container.Resolve <IMachineRequest>();

            simulatedEvent.IMEI            = IMEI;
            simulatedEvent.DeviceTime      = DateTimeOffset.UtcNow;
            simulatedEvent.Vehicle         = state.Vehicle;
            simulatedEvent.TelematicDevice = state?.TelematicDevice;
            if (simulatedEvent.TelematicDevice == null)
            {
                simulatedEvent.TelematicDevice = _container.Resolve <IMachineTelematicDevice>();
            }
            simulatedEvent.Vehicle.VIN          = Vin;
            simulatedEvent.TelematicDevice.IMEI = IMEI;

            var result = await Client.Simulate(simulatedEvent);

            if (result.Success)
            {
                var id = Guid.Empty;
                Guid.TryParse(result.Response, out id);
                state.MessageId = id;
            }
            return(state);
        }
Esempio n. 4
0
        private IMachineRequest PrepareStateRequest(IVehicleState state, string IMEI, string Vin = null, bool ignitionState = true, bool isFirstMessage = false)
        {
            var simulatedEvent = _container.Resolve <IMachineRequest>();

            simulatedEvent.IMEI       = IMEI;
            simulatedEvent.DeviceTime = DateTimeOffset.UtcNow;
            simulatedEvent.Vehicle    = state.Vehicle;

            if (simulatedEvent.Vehicle.IgnitionState == null)
            {
                simulatedEvent.Vehicle.IgnitionState = _container.Resolve <IState>();
            }
            simulatedEvent.Vehicle.IgnitionState.Value = ignitionState;
            if (isFirstMessage)
            {
                simulatedEvent.EventCode = 6010; //6010 vehicle switch
            }
            else
            {
                simulatedEvent.EventCode = 4050; //4050 regular driving status update
            }
            simulatedEvent.TelematicDevice = state?.TelematicDevice;
            if (simulatedEvent.TelematicDevice == null)
            {
                simulatedEvent.TelematicDevice = _container.Resolve <IMachineTelematicDevice>();
            }
            simulatedEvent.Vehicle.VIN          = Vin;
            simulatedEvent.TelematicDevice.IMEI = IMEI;

            return(simulatedEvent);
        }
Esempio n. 5
0
        static void OnGameUpdate(int index, IVehicleState state)
        {
            string changingTire = state.IsChangingTire ? "Проколото колесо" : "Все в порядке      ";
            string traveled     = String.Format("{0,5:0}", state.Traveled);
            string info         = $"{state.Vehicle.Name} : Пройдено {traveled} м. : {changingTire}";

            Console.SetCursorPosition(0, 10 + index);
            Console.WriteLine(info);
        }
Esempio n. 6
0
    public void ChangeState(IVehicleState newState)
    {
        if (currentState != null)
        {
            currentState.Exit();
            previousState = currentState;
        }

        currentState = newState;
        currentState.Enter();
    }
Esempio n. 7
0
        private VehicleState(LastPosition position, Dispositivo dispositivo)
        {
            DeviceId = dispositivo.Id;

            for (var i = 0; i < 16; i++)
            {
                _infraccion[i] = (byte)dispositivo.GetInfraccionNivel(i);
                _excesos[i]    = (byte)dispositivo.GetExcesoNivel(i);
            }

            _infraccion[16] = (byte)dispositivo.GetInfraccionNivel(-1);
            _excesos[16]    = (byte)dispositivo.GetExcesoNivel(-1);

            _qtreeKey = dispositivo.GetQtreeType() + "|" + dispositivo.GetQtreeFile();

            _vhState = new VechicleNormal(position);
        }
Esempio n. 8
0
        public Task <IVehicle> SpawnVehicleAsync(Vector3 position, string vehicleId, IVehicleState state = null)
        {
            async UniTask <IVehicle> VehicleSpawnTask()
            {
                await UniTask.SwitchToMainThread();

                if (!ushort.TryParse(vehicleId, out var parsedVehicleId))
                {
                    throw new Exception($"Invalid vehicle id: {vehicleId}");
                }

                if (Assets.find(EAssetType.VEHICLE, parsedVehicleId) is not VehicleAsset)
                {
                    return(null);
                }

                UnturnedVehicle vehicle = null;

                if (state != null && state is UnturnedVehicleState)
                {
                    ReadState(state.StateData, out _ /* id doesn't require i guess? */, out ushort skinID, out ushort mythicID,
                              out float roadPosition, out ushort fuel, out ushort health, out ushort batteryCharge,
                              out CSteamID owner, out CSteamID group, out bool locked, out byte[][] turrets,
                              out uint instanceID, out byte tireAliveMask, out ItemJar[] items);
Esempio n. 9
0
 public VehicleStateContext(IVehicleState state)
 {
     this.state = state;
 }
Esempio n. 10
0
 public void SetState(IVehicleState nextState)
 {
     state = nextState;
 }
 public void Damaged()
 {
     currentState = new VehicleDamagedState();
     currentState.Execute(this);
 }
 public void UnOperable()
 {
     currentState = new VehicleUnOperableState();
     currentState.Execute(this);
 }
Esempio n. 13
0
 public void TurnRight()
 {
     VehicleState = VehicleState.TurnRight();
 }
Esempio n. 14
0
 public void TurnLeft()
 {
     VehicleState = VehicleState.TurnLeft();
 }
Esempio n. 15
0
 private void SetState(IVehicleState newState)
 {
     _vhState = newState;
 }