static void Postfix(LocoControllerBase __instance, float nextTargetBrake) { TrainCar currentCar = __instance.GetComponent <TrainCar>(); TrainCar targetCar = null; Trainset trainset = null; if (Main.remoteCar) { targetCar = Main.remoteCar; trainset = targetCar.trainset; } else if (PlayerManager.Car != null) { targetCar = PlayerManager.Car; trainset = PlayerManager.Car.trainset; } if (currentCar == null || targetCar == null || !targetCar.Equals(currentCar) || trainset == null || trainset.cars.Count < 2) { 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) { locoController.SetBrake(nextTargetBrake); } } else if (car.carType == TrainCarType.LocoDiesel) { LocoControllerDiesel locoController = car.GetComponent <LocoControllerDiesel>(); if (locoController) { locoController.SetBrake(nextTargetBrake); } } } }
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); }