public override void Initialize()
        {
            base.Initialize();
            _ammoContainer = ContainerManagerComponent.Ensure <Container>($"{Name}-magazine", Owner, out var existing);

            if (existing)
            {
                if (_ammoContainer.ContainedEntities.Count > Capacity)
                {
                    throw new InvalidOperationException("Initialized capacity of magazine higher than its actual capacity");
                }

                foreach (var entity in _ammoContainer.ContainedEntities)
                {
                    _spawnedAmmo.Push(entity);
                    _unspawnedCount--;
                }
            }

            if (Owner.TryGetComponent(out AppearanceComponent appearanceComponent))
            {
                _appearanceComponent = appearanceComponent;
            }

            _appearanceComponent?.SetData(MagazineBarrelVisuals.MagLoaded, true);
        }
 private void UpdateMagazineAppearance(AppearanceComponent?appearance, bool magLoaded, int count, int capacity)
 {
     // Copy the magazine's appearance data
     appearance?.SetData(AmmoVisuals.MagLoaded, magLoaded);
     appearance?.SetData(AmmoVisuals.AmmoCount, count);
     appearance?.SetData(AmmoVisuals.AmmoMax, capacity);
 }
        public override void Initialize()
        {
            base.Initialize();

            _ammoContainer =
                ContainerManagerComponent.Ensure <Container>($"{Name}-ammo-container", Owner, out var existing);

            if (existing)
            {
                foreach (var entity in _ammoContainer.ContainedEntities)
                {
                    _spawnedAmmo.Push(entity);
                    _unspawnedCount--;
                }
            }

            _chamberContainer =
                ContainerManagerComponent.Ensure <ContainerSlot>($"{Name}-chamber-container", Owner, out existing);
            if (existing)
            {
                _unspawnedCount--;
            }

            if (Owner.TryGetComponent(out AppearanceComponent appearanceComponent))
            {
                _appearanceComponent = appearanceComponent;
            }

            _appearanceComponent?.SetData(MagazineBarrelVisuals.MagLoaded, true);
            Dirty();
            UpdateAppearance();
        }
 public void UpdateAppearance()
 {
     _appearanceComponent?.SetData(MagazineBarrelVisuals.MagLoaded, _powerCellContainer.ContainedEntity != null);
     _appearanceComponent?.SetData(AmmoVisuals.AmmoCount, ShotsLeft);
     _appearanceComponent?.SetData(AmmoVisuals.AmmoMax, Capacity);
     Dirty();
 }
示例#5
0
        private void UpdateLight(EntityUid uid,
                                 PoweredLightComponent?light             = null,
                                 ApcPowerReceiverComponent?powerReceiver = null,
                                 AppearanceComponent?appearance          = null)
        {
            if (!Resolve(uid, ref light, ref powerReceiver))
            {
                return;
            }

            // Optional component.
            Resolve(uid, ref appearance, false);

            // check if light has bulb
            var bulbUid = GetBulb(uid, light);

            if (bulbUid == null || !EntityManager.TryGetComponent(bulbUid.Value, out LightBulbComponent? lightBulb))
            {
                SetLight(uid, false, light: light);
                powerReceiver.Load = 0;
                appearance?.SetData(PoweredLightVisuals.BulbState, PoweredLightState.Empty);
                return;
            }
            else
            {
                switch (lightBulb.State)
                {
                case LightBulbState.Normal:
                    if (powerReceiver.Powered && light.On)
                    {
                        SetLight(uid, true, lightBulb.Color, light, lightBulb.LightRadius, lightBulb.LightEnergy, lightBulb.LightSoftness);
                        appearance?.SetData(PoweredLightVisuals.BulbState, PoweredLightState.On);
                        var time = _gameTiming.CurTime;
                        if (time > light.LastThunk + ThunkDelay)
                        {
                            light.LastThunk = time;
                            SoundSystem.Play(light.TurnOnSound.GetSound(), Filter.Pvs(uid), uid, AudioParams.Default.WithVolume(-10f));
                        }
                    }
                    else
                    {
                        SetLight(uid, false, light: light);
                        appearance?.SetData(PoweredLightVisuals.BulbState, PoweredLightState.Off);
                    }
                    break;

                case LightBulbState.Broken:
                    SetLight(uid, false, light: light);
                    appearance?.SetData(PoweredLightVisuals.BulbState, PoweredLightState.Broken);
                    break;

                case LightBulbState.Burned:
                    SetLight(uid, false, light: light);
                    appearance?.SetData(PoweredLightVisuals.BulbState, PoweredLightState.Burned);
                    break;
                }

                powerReceiver.Load = (light.On && lightBulb.State == LightBulbState.Normal) ? lightBulb.PowerUse : 0;
            }
        }
        public override void Startup()
        {
            base.Startup();

            _bulletContainer =
                ContainerManagerComponent.Ensure <Container>("magazine_bullet_container", Owner, out var existed);

            if (existed)
            {
                foreach (var entity in _bulletContainer.ContainedEntities)
                {
                    _loadedBullets.Push(entity);
                }
                _updateAppearance();
            }
            else if (_fillType != null)
            {
                // Load up bullets from fill.
                for (var i = 0; i < Capacity; i++)
                {
                    var bullet = Owner.EntityManager.SpawnEntity(_fillType);
                    AddBullet(bullet);
                }
            }

            OnAmmoCountChanged?.Invoke();
            _appearance.SetData(BallisticMagazineVisuals.AmmoCapacity, Capacity);
        }
 public void UpdateAppearance()
 {
     _appearanceComponent?.SetData(MagazineBarrelVisuals.MagLoaded, EntitySystem.Get <PowerCellSystem>().TryGetBatteryFromSlot(Owner, out _));
     _appearanceComponent?.SetData(AmmoVisuals.AmmoCount, ShotsLeft);
     _appearanceComponent?.SetData(AmmoVisuals.AmmoMax, Capacity);
     Dirty();
 }
示例#8
0
 public void SetCore()
 {
     if (_isCore)
     {
         return;
     }
     _isCore = true;
     _appearance?.SetData(AMEShieldVisuals.Core, "isCore");
 }
 private void SetState(ItemTeleporterState newState)
 {
     if (newState == ItemTeleporterState.Cooldown)
     {
         _appearanceComponent.SetData(TeleporterVisuals.VisualState, TeleporterVisualState.Charging);
     }
     else
     {
         _appearanceComponent.SetData(TeleporterVisuals.VisualState, TeleporterVisualState.Ready);
     }
     _state = newState;
 }
        public override void OnChangeData(AppearanceComponent component)
        {
            if (component.Owner.Deleted)
            {
                return;
            }

            if (!component.Owner.TryGetComponent <ISpriteComponent>(out var sprite))
            {
                return;
            }
            if (!component.Owner.TryGetComponent <AnimationPlayerComponent>(out var animPlayer))
            {
                return;
            }
            if (!component.TryGetData(RadiationCollectorVisuals.VisualState, out RadiationCollectorVisualState state))
            {
                state = RadiationCollectorVisualState.Deactive;
            }

            switch (state)
            {
            case RadiationCollectorVisualState.Active:
                sprite.LayerSetState(RadiationCollectorVisualLayers.Main, "ca_on");
                break;

            case RadiationCollectorVisualState.Activating:
                if (!animPlayer.HasRunningAnimation(AnimationKey))
                {
                    animPlayer.Play(ActivateAnimation, AnimationKey);
                    animPlayer.AnimationCompleted += _ =>
                                                     component.SetData(RadiationCollectorVisuals.VisualState,
                                                                       RadiationCollectorVisualState.Active);
                }
                break;

            case RadiationCollectorVisualState.Deactivating:
                if (!animPlayer.HasRunningAnimation(AnimationKey))
                {
                    animPlayer.Play(DeactiveAnimation, AnimationKey);
                    animPlayer.AnimationCompleted += _ =>
                                                     component.SetData(RadiationCollectorVisuals.VisualState,
                                                                       RadiationCollectorVisualState.Deactive);
                }
                break;

            case RadiationCollectorVisualState.Deactive:
                sprite.LayerSetState(RadiationCollectorVisualLayers.Main, "ca_off");
                break;
            }
        }
示例#11
0
        public override void OnChangeData(AppearanceComponent component)
        {
            base.OnChangeData(component);

            var entities = IoCManager.Resolve <IEntityManager>();

            if (!entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite))
            {
                return;
            }
            if (!entities.TryGetComponent(component.Owner, out AnimationPlayerComponent? animPlayer))
            {
                return;
            }
            if (!component.TryGetData(RadiationCollectorVisuals.VisualState, out RadiationCollectorVisualState state))
            {
                state = RadiationCollectorVisualState.Deactive;
            }

            switch (state)
            {
            case RadiationCollectorVisualState.Active:
                sprite.LayerSetState(RadiationCollectorVisualLayers.Main, "ca_on");
                break;

            case RadiationCollectorVisualState.Activating:
                if (!animPlayer.HasRunningAnimation(AnimationKey))
                {
                    animPlayer.Play(ActivateAnimation, AnimationKey);
                    animPlayer.AnimationCompleted += _ =>
                                                     component.SetData(RadiationCollectorVisuals.VisualState,
                                                                       RadiationCollectorVisualState.Active);
                }
                break;

            case RadiationCollectorVisualState.Deactivating:
                if (!animPlayer.HasRunningAnimation(AnimationKey))
                {
                    animPlayer.Play(DeactiveAnimation, AnimationKey);
                    animPlayer.AnimationCompleted += _ =>
                                                     component.SetData(RadiationCollectorVisuals.VisualState,
                                                                       RadiationCollectorVisualState.Deactive);
                }
                break;

            case RadiationCollectorVisualState.Deactive:
                sprite.LayerSetState(RadiationCollectorVisualLayers.Main, "ca_off");
                break;
            }
        }
        public void OnUpdate()
        {
            var newState = CalcChargeState();

            if (newState != LastChargeState)
            {
                LastChargeState = newState;
                Appearance.SetData(ApcVisuals.ChargeState, newState);
            }

            var newCharge = Storage.Charge;

            if (newCharge != _lastCharge)
            {
                _lastCharge = newCharge;
                _uiDirty    = true;
            }

            var extPowerState = CalcExtPowerState();

            if (extPowerState != _lastExternalPowerState)
            {
                _lastExternalPowerState = extPowerState;
                _uiDirty = true;
            }

            if (_uiDirty)
            {
                _userInterface.SetState(new ApcBoundInterfaceState(_provider.MainBreaker, extPowerState,
                                                                   newCharge / Storage.Capacity));
                _uiDirty = false;
            }
        }
示例#13
0
 private void SetAppearance(MicrowaveVisualState state)
 {
     if (_appearance != null || Owner.TryGetComponent(out _appearance))
     {
         _appearance.SetData(PowerDeviceVisuals.VisualState, state);
     }
 }
示例#14
0
        public void Update()
        {
            var newState = CalcChargeState();

            if (newState != _lastChargeState && _lastChargeStateChange + TimeSpan.FromSeconds(VisualsChangeDelay) < _gameTiming.CurTime)
            {
                _lastChargeState       = newState;
                _lastChargeStateChange = _gameTiming.CurTime;
                _appearance.SetData(ApcVisuals.ChargeState, newState);
            }
            var newCharge = Battery.CurrentCharge;

            if (newCharge != _lastCharge && _lastChargeChange + TimeSpan.FromSeconds(VisualsChangeDelay) < _gameTiming.CurTime)
            {
                _lastCharge       = newCharge;
                _lastChargeChange = _gameTiming.CurTime;
                _uiDirty          = true;
            }
            var extPowerState = CalcExtPowerState();

            if (extPowerState != _lastExternalPowerState && _lastExternalPowerStateChange + TimeSpan.FromSeconds(VisualsChangeDelay) < _gameTiming.CurTime)
            {
                _lastExternalPowerState       = extPowerState;
                _lastExternalPowerStateChange = _gameTiming.CurTime;
                _uiDirty = true;
            }
            if (_uiDirty)
            {
                _userInterface.SetState(new ApcBoundInterfaceState(MainBreakerEnabled, extPowerState, newCharge / Battery.MaxCharge));
                _uiDirty = false;
            }
        }
        public bool Stand(EntityUid uid,
                          StandingStateComponent?standingState = null,
                          AppearanceComponent?appearance       = null)
        {
            // TODO: This should actually log missing comps...
            if (!Resolve(uid, ref standingState, false))
            {
                return(false);
            }

            // Optional component.
            Resolve(uid, ref appearance, false);

            if (standingState.Standing)
            {
                return(true);
            }

            var msg = new StandAttemptEvent();

            RaiseLocalEvent(uid, msg, false);

            if (msg.Cancelled)
            {
                return(false);
            }

            standingState.Standing = true;
            standingState.Dirty();
            RaiseLocalEvent(uid, new StoodEvent(), false);

            appearance?.SetData(RotationVisuals.RotationState, RotationState.Vertical);
            return(true);
        }
 private void ToggleInjection()
 {
     if (!_injecting)
     {
         _appearance?.SetData(AMEControllerVisuals.DisplayState, "on");
     }
     else
     {
         _appearance?.SetData(AMEControllerVisuals.DisplayState, "off");
         if (_powerSupplier != null)
         {
             _powerSupplier.MaxSupply = 0;
         }
     }
     _injecting = !_injecting;
     UpdateUserInterface();
 }
        private void Scrub(GasVentScrubberComponent scrubber, AppearanceComponent?appearance, TileAtmosphere?tile, PipeNode outlet)
        {
            // Cannot scrub if tile is null or air-blocked.
            if (tile?.Air == null)
            {
                return;
            }

            // Cannot scrub if pressure too high.
            if (outlet.Air.Pressure >= 50 * Atmospherics.OneAtmosphere)
            {
                return;
            }

            if (scrubber.PumpDirection == ScrubberPumpDirection.Scrubbing)
            {
                appearance?.SetData(ScrubberVisuals.State, scrubber.WideNet ? ScrubberState.WideScrub : ScrubberState.Scrub);
                var transferMoles = MathF.Min(1f, (scrubber.VolumeRate / tile.Air.Volume) * tile.Air.TotalMoles);

                // Take a gas sample.
                var removed = tile.Air.Remove(transferMoles);

                // Nothing left to remove from the tile.
                if (MathHelper.CloseTo(removed.TotalMoles, 0f))
                {
                    return;
                }

                // TODO: Entity system dependency
                Get <AtmosphereSystem>().ScrubInto(removed, outlet.Air, scrubber.FilterGases);

                // Remix the gases.
                tile.AssumeAir(removed);
            }
            else if (scrubber.PumpDirection == ScrubberPumpDirection.Siphoning)
            {
                appearance?.SetData(ScrubberVisuals.State, ScrubberState.Siphon);
                var transferMoles = tile.Air.TotalMoles * (scrubber.VolumeRate / tile.Air.Volume);

                var removed = tile.Air.Remove(transferMoles);

                outlet.AssumeAir(removed);
                tile.Invalidate();
            }
        }
        /// <summary>
        ///     Updates the light's power drain, sprite and actual light state.
        /// </summary>
        public void UpdateLight()
        {
            var powerReceiver = Owner.GetComponent <ApcPowerReceiverComponent>();

            if (LightBulb == null) // No light bulb.
            {
                SetLight(false);
                powerReceiver.Load = 0;
                _appearance?.SetData(PoweredLightVisuals.BulbState, PoweredLightState.Empty);
                return;
            }

            switch (LightBulb.State)
            {
            case LightBulbState.Normal:
                if (powerReceiver.Powered && _on)
                {
                    SetLight(true, LightBulb.Color);
                    powerReceiver.Load = LightBulb.PowerUse;
                    _appearance?.SetData(PoweredLightVisuals.BulbState, PoweredLightState.On);
                    var time = _gameTiming.CurTime;
                    if (time > _lastThunk + _thunkDelay)
                    {
                        _lastThunk = time;
                        SoundSystem.Play(Filter.Pvs(Owner), _turnOnSound.GetSound(), Owner, AudioParams.Default.WithVolume(-10f));
                    }
                }
                else
                {
                    SetLight(false);
                    _appearance?.SetData(PoweredLightVisuals.BulbState, PoweredLightState.Off);
                }
                break;

            case LightBulbState.Broken:
                SetLight(false);
                _appearance?.SetData(PoweredLightVisuals.BulbState, PoweredLightState.Broken);
                break;

            case LightBulbState.Burned:
                SetLight(false);
                _appearance?.SetData(PoweredLightVisuals.BulbState, PoweredLightState.Burned);
                break;
            }
        }
示例#19
0
        public void OnUpdate()
        {
            var newLevel = CalcChargeLevel();

            if (newLevel != LastChargeLevel)
            {
                LastChargeLevel = newLevel;
                Appearance.SetData(SmesVisuals.LastChargeLevel, newLevel);
            }

            var newState = Storage.GetChargeState();

            if (newState != LastChargeState)
            {
                LastChargeState = newState;
                Appearance.SetData(SmesVisuals.LastChargeState, newState);
            }
        }
示例#20
0
        public override void Update(float frameTime)
        {
            var newLevel = CalcChargeLevel();

            if (newLevel != LastChargeLevel)
            {
                LastChargeLevel = newLevel;
                Appearance.SetData(SmesVisuals.LastChargeLevel, newLevel);
            }

            var newState = Storage.GetChargeState();

            if (newState != LastChargeState)
            {
                LastChargeState = newState;
                Appearance.SetData(SmesVisuals.LastChargeState, newState);
            }
        }
        protected override void Startup()
        {
            base.Startup();

            _foodContainer =
                ContainerManagerComponent.Ensure <Container>("food_container", Owner, out var existed);

            if (existed)
            {
                foreach (var entity in _foodContainer.ContainedEntities)
                {
                    _loadedFood.Push(entity);
                }
            }

            _updateAppearance();
            _appearanceComponent?.SetData(DrinkFoodContainerVisuals.Capacity, Capacity);
        }
示例#22
0
        public override void Update(float frameTime)
        {
            var newState = CalcChargeState();

            if (newState != LastChargeState)
            {
                LastChargeState = newState;
                Appearance.SetData(ApcVisuals.ChargeState, newState);
            }
        }
示例#23
0
        private void UpdateVisualizer()
        {
            _appearance?.SetData(ExpendableLightVisuals.State, CurrentState);

            switch (CurrentState)
            {
            case ExpendableLightState.Lit:
                _appearance?.SetData(ExpendableLightVisuals.Behavior, TurnOnBehaviourID);
                break;

            case ExpendableLightState.Fading:
                _appearance?.SetData(ExpendableLightVisuals.Behavior, FadeOutBehaviourID);
                break;

            case ExpendableLightState.Dead:
                _appearance?.SetData(ExpendableLightVisuals.Behavior, string.Empty);
                break;
            }
        }
        protected void UpdateStatus()
        {
            // Not called UpdateAppearance just because it messes with the load
            var status = GetStatus();

            if (_status == status)
            {
                return;
            }

            _status = status;

            switch (_status)
            {
            // Update load just in case
            case CellChargerStatus.Off:
                _powerDevice.Load = 0;
                _appearanceComponent?.SetData(CellVisual.Light, CellChargerStatus.Off);
                break;

            case CellChargerStatus.Empty:
                _powerDevice.Load = 0;
                _appearanceComponent?.SetData(CellVisual.Light, CellChargerStatus.Empty);;
                break;

            case CellChargerStatus.Charging:
                _appearanceComponent?.SetData(CellVisual.Light, CellChargerStatus.Charging);
                break;

            case CellChargerStatus.Charged:
                _powerDevice.Load = 0;
                _appearanceComponent?.SetData(CellVisual.Light, CellChargerStatus.Charged);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            _appearanceComponent?.SetData(CellVisual.Occupied, _container.ContainedEntity != null);

            _status = status;
        }
示例#25
0
        public void Open()
        {
            if (_state != DoorState.Closed)
            {
                return;
            }

            _state = DoorState.Opening;
            _appearance.SetData(DoorVisuals.VisualState, DoorVisualState.Opening);

            Timer.Spawn(OpenTimeOne, async() =>
            {
                collidableComponent.IsHardCollidable = false;

                await Timer.Delay(OpenTimeTwo);

                _state = DoorState.Open;
                _appearance.SetData(DoorVisuals.VisualState, DoorVisualState.Open);
            });
        }
示例#26
0
        public void OnUpdate()
        {
            var newLevel = GetNewChargeLevel();

            if (newLevel != _lastChargeLevel && _lastChargeLevelChange + TimeSpan.FromSeconds(VisualsChangeDelay) < _gameTiming.CurTime)
            {
                _lastChargeLevel       = newLevel;
                _lastChargeLevelChange = _gameTiming.CurTime;
                _appearance.SetData(SmesVisuals.LastChargeLevel, newLevel);
            }

            var newChargeState = GetNewChargeState();

            if (newChargeState != _lastChargeState && _lastChargeStateChange + TimeSpan.FromSeconds(VisualsChangeDelay) < _gameTiming.CurTime)
            {
                _lastChargeState       = newChargeState;
                _lastChargeStateChange = _gameTiming.CurTime;
                _appearance.SetData(SmesVisuals.LastChargeState, newChargeState);
            }
        }
示例#27
0
        public void EnterState(IEntity entity, AppearanceComponent appearance)
        {
            var newstate = SpeciesComponent.MobState.Down;

            appearance.SetData(SpeciesComponent.MobVisuals.RotationState, newstate);
            if (!entity.TryGetComponent <PlayerInputMoverComponent>(out var mover))
            {
                return;
            }
            mover.Disabled = true;
        }
        /// <inheritdoc />
        protected override void Startup()
        {
            base.Startup();

            _bulletContainer =
                ContainerManagerComponent.Ensure <Container>("magazine_bullet_container", Owner, out var existed);

            if (existed)
            {
                foreach (var entity in _bulletContainer.ContainedEntities)
                {
                    _loadedBullets.Push(entity);
                }
            }

            _updateAppearance();

            OnAmmoCountChanged?.Invoke();
            _appearance.SetData(BallisticMagazineVisuals.AmmoCapacity, Capacity);
        }
        public bool Down(EntityUid uid, bool playSound        = true, bool dropHeldItems = true,
                         StandingStateComponent?standingState = null,
                         AppearanceComponent?appearance       = null,
                         SharedHandsComponent?hands           = null)
        {
            // TODO: This should actually log missing comps...
            if (!Resolve(uid, ref standingState, false))
            {
                return(false);
            }

            // Optional component.
            Resolve(uid, ref appearance, ref hands, false);

            if (!standingState.Standing)
            {
                return(true);
            }

            // This is just to avoid most callers doing this manually saving boilerplate
            // 99% of the time you'll want to drop items but in some scenarios (e.g. buckling) you don't want to.
            // We do this BEFORE downing because something like buckle may be blocking downing but we want to drop hand items anyway
            // and ultimately this is just to avoid boilerplate in Down callers + keep their behavior consistent.
            if (dropHeldItems && hands != null)
            {
                RaiseLocalEvent(uid, new DropHandItemsEvent(), false);
            }

            var msg = new DownAttemptEvent();

            RaiseLocalEvent(uid, msg, false);

            if (msg.Cancelled)
            {
                return(false);
            }

            standingState.Standing = false;
            standingState.Dirty();
            RaiseLocalEvent(uid, new DownedEvent(), false);

            // Seemed like the best place to put it
            appearance?.SetData(RotationVisuals.RotationState, RotationState.Horizontal);

            // Currently shit is only downed by server but when it's predicted we can probably only play this on server / client
            if (playSound)
            {
                SoundSystem.Play(Filter.Pvs(uid), standingState.DownSoundCollection.GetSound(), uid, AudioHelpers.WithVariation(0.25f));
            }

            return(true);
        }
        public void TryChangeState(PortalState targetState)
        {
            if (Owner == null)
            {
                return;
            }

            _state = targetState;
            if (_appearanceComponent != null)
            {
                _appearanceComponent.SetData(PortalVisuals.State, _state);
            }
        }