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); }
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); }
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); }
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); }
public void ChangeState(IVehicleState newState) { if (currentState != null) { currentState.Exit(); previousState = currentState; } currentState = newState; currentState.Enter(); }
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); }
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);
public VehicleStateContext(IVehicleState state) { this.state = state; }
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); }
public void TurnRight() { VehicleState = VehicleState.TurnRight(); }
public void TurnLeft() { VehicleState = VehicleState.TurnLeft(); }
private void SetState(IVehicleState newState) { _vhState = newState; }