Exemple #1
0
        public bool Receive(LocoShunterActionPacket packet, ClientId client)
        {
            if (packet.Id != Id)
            {
                return(false);
            }

            Logging <TrainCarSync> .LogDebug($"LocoShunterActionPacket: {packet.Flags} / {packet.TargetThrottle} / {packet.TargetBrake} / {packet.TargetIndependentBrake}");

            _controller.SetThrottle(packet.TargetThrottle);
            _controller.SetBrake(packet.TargetBrake);
            _controller.SetIndependentBrake(packet.TargetIndependentBrake);
            _controller.SetReverser(packet.Reverser);
            _controller.SetEngineRunning((packet.Flags & ShunterStateFlags.EngineOn) != 0);
            _controller.SetSandersOn((packet.Flags & ShunterStateFlags.SandOn) != 0);
            _controller.backlight = (packet.Flags & ShunterStateFlags.LightOn) != 0;
            _controller.fan       = (packet.Flags & ShunterStateFlags.FanOn) != 0;
            _controller.headlights.SetActive((packet.Flags & ShunterStateFlags.HeadlightOn) != 0);

            return(true);
        }
        static void Prefix(LocoControllerDiesel __instance, ToggleDirection toggle)
        {
            TrainCar targetCar = __instance.GetComponent <TrainCar>();
            Trainset trainset  = targetCar.trainset;

            if (trainset == null)
            {
                return;
            }

            for (int i = 0; i < trainset.cars.Count; i++)
            {
                TrainCar car = trainset.cars[i];

                if (targetCar.Equals(car))
                {
                    continue;
                }

                if (car.carType == TrainCarType.LocoShunter)
                {
                    LocoControllerShunter locoController = car.GetComponent <LocoControllerShunter>();

                    if (locoController != null)
                    {
                        locoController.SetSandersOn(toggle == ToggleDirection.UP);
                    }
                }
                else if (car.carType == TrainCarType.LocoDiesel)
                {
                    LocoControllerDiesel locoController = car.GetComponent <LocoControllerDiesel>();

                    if (locoController != null)
                    {
                        locoController.SetSandersOn(toggle == ToggleDirection.UP);
                    }
                }
            }
        }
        static IEnumerator <object> AttachListeners()
        {
            yield return((object)null);

            DV.CabControls.ControlImplBase sandDeployCtrl = instance.sandDeployBtn.GetComponent <DV.CabControls.ControlImplBase>();

            sandDeployCtrl.ValueChanged += (e =>
            {
                if (PlayerManager.Car == null || PlayerManager.Car.trainset == null)
                {
                    return;
                }

                for (int i = 0; i < PlayerManager.Car.trainset.cars.Count; i++)
                {
                    TrainCar car = PlayerManager.Car.trainset.cars[i];

                    if (PlayerManager.Car.Equals(car))
                    {
                        continue;
                    }

                    if (car.carType == TrainCarType.LocoShunter)
                    {
                        LocoControllerShunter locoController = car.GetComponent <LocoControllerShunter>();

                        if (locoController)
                        {
                            locoController.SetSandersOn(e.newValue >= 0.5f);
                        }
                    }
                    else if (car.carType == TrainCarType.LocoDiesel)
                    {
                        LocoControllerDiesel locoController = car.GetComponent <LocoControllerDiesel>();

                        if (locoController)
                        {
                            locoController.SetSandersOn(e.newValue >= 0.5f);
                        }
                    }
                }
            });

            DV.CabControls.ControlImplBase fanCtrl = instance.fanSwitchButton.GetComponent <DV.CabControls.ControlImplBase>();

            fanCtrl.ValueChanged += (e =>
            {
                if (PlayerManager.Car == null || PlayerManager.Car.trainset == null)
                {
                    return;
                }

                for (int i = 0; i < PlayerManager.Car.trainset.cars.Count; i++)
                {
                    TrainCar car = PlayerManager.Car.trainset.cars[i];

                    if (PlayerManager.Car.Equals(car))
                    {
                        continue;
                    }

                    if (car.carType == TrainCarType.LocoShunter)
                    {
                        LocoControllerShunter locoController = car.GetComponent <LocoControllerShunter>();

                        if (locoController)
                        {
                            locoController.SetFan(e.newValue >= 0.5f);
                        }
                    }
                    else if (car.carType == TrainCarType.LocoDiesel)
                    {
                        LocoControllerDiesel locoController = car.GetComponent <LocoControllerDiesel>();

                        if (locoController)
                        {
                            locoController.SetFan(e.newValue >= 0.5f);
                        }
                    }
                }
            });
        }
Exemple #4
0
 /// <inheritdoc />
 public override void GetActions(ShunterLocoActions actions)
 {
     _base.GetActions(actions);
     actions.SetSander   = val => _inner.SetSandersOn(val >= 0.5f);
     actions.SetEngineOn = on => _inner.EngineOn = on;
 }