Example #1
0
        protected override void Init()
        {
            base.Init();

            _car = GetComponent <TrainCar>();

            if (Authoritative)
            {
                _cargoState = new CargoStateUpdatePacket {
                    Id = Id
                };
            }
            else
            {
                GetComponent <DamageController>()?.SetupListeners(false);
                GetComponent <CarDamageModel>()?.SetupListeners(false);
                GetComponent <CargoDamageModel>()?.SetupListeners(false);
            }

            _coupleState = new CoupleStateUpdatePacket[_car.couplers.Length];
            for (var i = 0; i < _car.couplers.Length; i++)
            {
                _coupleState[i] = new CoupleStateUpdatePacket()
                {
                    Id = Id
                };
                PopulateCoupleStatePacket(_coupleState[i], i);
            }
        }
Example #2
0
        private bool PopulateCargoStatePacket(CargoStateUpdatePacket state)
        {
            var logicCar = _car.logicCar;

            return(SetStateValue(ref state.CargoType, logicCar.CurrentCargoTypeInCar) |
                   SetStateValue(ref state.LastUnloadedCargo, logicCar.LastUnloadedCargoType) |
                   SetStateValue(ref state.LoadedAmount, logicCar.LoadedCargoAmount));
        }
Example #3
0
        public bool Receive(CargoStateUpdatePacket packet, ClientId client)
        {
            if (packet.Id != Id)
            {
                return(false);
            }

            var logicCar = _car.logicCar;

            logicCar.LoadCargo(packet.LoadedAmount - logicCar.LoadedCargoAmount, packet.CargoType);
            logicCar.LoadedCargoAmount     = packet.LoadedAmount;
            logicCar.CurrentCargoTypeInCar = packet.CargoType;
            logicCar.LastUnloadedCargoType = packet.LastUnloadedCargo;

            return(true);
        }