示例#1
0
        private void RemoveItem(IEntity user)
        {
            var heldItem = _container.ContainedEntity;

            if (heldItem == null)
            {
                return;
            }

            _container.Remove(heldItem);
            _heldBattery = null;
            if (user.TryGetComponent(out HandsComponent? handsComponent))
            {
                handsComponent.PutInHandOrDrop(heldItem.GetComponent <ItemComponent>());
            }

            if (heldItem.TryGetComponent(out ServerBatteryBarrelComponent? batteryBarrelComponent))
            {
                batteryBarrelComponent.UpdateAppearance();
            }

            UpdateStatus();
        }
示例#2
0
        /// <summary>
        ///     Ejects the bulb to a mob's hand if possible.
        /// </summary>
        private void EjectBulb(IEntity user)
        {
            if (LightBulb == null)
            {
                return;
            }

            var bulb = LightBulb;

            bulb.OnLightBulbStateChange -= UpdateLight;
            bulb.OnLightColorChange     -= UpdateLight;

            if (!_lightBulbContainer.Remove(bulb.Owner))
            {
                return;
            }

            if (!user.TryGetComponent(out HandsComponent hands) ||
                !hands.PutInHand(bulb.Owner.GetComponent <ItemComponent>()))
            {
                bulb.Owner.Transform.GridPosition = user.Transform.GridPosition;
            }
        }
示例#3
0
        /// <summary>
        /// This will remove the item directly into the user's hand / floor
        /// </summary>
        /// <param name="user"></param>
        public void RemoveItem(EntityUid user)
        {
            if (Container.ContainedEntity is not {
                Valid : true
            } heldItem)
            {
                return;
            }

            Container.Remove(heldItem);
            _heldBattery = null;
            if (_entMan.TryGetComponent(user, out HandsComponent? handsComponent))
            {
                handsComponent.PutInHandOrDrop(_entMan.GetComponent <SharedItemComponent>(heldItem));
            }

            if (_entMan.TryGetComponent(heldItem, out ServerBatteryBarrelComponent? batteryBarrelComponent))
            {
                batteryBarrelComponent.UpdateAppearance();
            }

            UpdateStatus();
        }
示例#4
0
        public bool TryGetItem(IEntity user)
        {
            if (_itemContainer.ContainedEntity == null)
            {
                return(false);
            }

            Owner.PopupMessage(user, Loc.GetString("There was something inside {0}!", _secretPartName));

            if (user.TryGetComponent(out HandsComponent? hands))
            {
                if (!_itemContainer.ContainedEntity.TryGetComponent(out ItemComponent? item))
                {
                    return(false);
                }
                hands.PutInHandOrDrop(item);
            }
            else if (_itemContainer.Remove(_itemContainer.ContainedEntity))
            {
                _itemContainer.ContainedEntity.Transform.Coordinates = Owner.Transform.Coordinates;
            }

            return(true);
        }
        public bool EjectMagazine(bool playSound = true)
        {
            var entity = Magazine;

            if (entity == null)
            {
                return(false);
            }
            if (_magazineSlot.Remove(entity))
            {
                entity.Transform.GridPosition = Owner.Transform.GridPosition;
                if (_magOutSound != null && playSound)
                {
                    EntitySystem.Get <AudioSystem>().PlayFromEntity(_magOutSound, Owner, AudioParams.Default.WithVolume(20));
                }
                UpdateAppearance();
                Dirty();
                entity.GetComponent <BallisticMagazineComponent>().OnAmmoCountChanged -= MagazineAmmoCountChanged;
                return(true);
            }
            UpdateAppearance();
            Dirty();
            return(false);
        }
        /// <summary>
        /// Try get item and place it in users hand
        /// If user can't take it by hands, will drop item from container
        /// </summary>
        /// <param name="user"></param>
        /// <returns>True if user recieved item</returns>
        public bool TryGetItem(IEntity user)
        {
            if (_itemContainer.ContainedEntity == null)
            {
                return(false);
            }

            Owner.PopupMessage(user, Loc.GetString("comp-secret-stash-action-get-item-found-something", ("stash", SecretPartName)));

            if (user.TryGetComponent(out HandsComponent? hands))
            {
                if (!_itemContainer.ContainedEntity.TryGetComponent(out ItemComponent? item))
                {
                    return(false);
                }
                hands.PutInHandOrDrop(item);
            }
            else if (_itemContainer.Remove(_itemContainer.ContainedEntity))
            {
                _itemContainer.ContainedEntity.Transform.Coordinates = Owner.Transform.Coordinates;
            }

            return(true);
        }
        public override IEntity TakeProjectile(GridCoordinates spawnAtGrid, MapCoordinates spawnAtMap)
        {
            var powerCellEntity = _powerCellContainer.ContainedEntity;

            if (powerCellEntity == null)
            {
                return(null);
            }

            var capacitor = powerCellEntity.GetComponent <BatteryComponent>();

            if (capacitor.CurrentCharge < _lowerChargeLimit)
            {
                return(null);
            }

            // Can fire confirmed
            // Multiply the entity's damage / whatever by the percentage of charge the shot has.
            IEntity entity;
            var     chargeChange = Math.Min(capacitor.CurrentCharge, _baseFireCost);

            capacitor.UseCharge(chargeChange);
            var energyRatio = chargeChange / _baseFireCost;

            if (_ammoContainer.ContainedEntity != null)
            {
                entity = _ammoContainer.ContainedEntity;
                _ammoContainer.Remove(entity);
            }
            else
            {
                entity = Owner.Transform.GridID != GridId.Invalid ?
                         Owner.EntityManager.SpawnEntity(_ammoPrototype, Owner.Transform.GridPosition)
                    : Owner.EntityManager.SpawnEntity(_ammoPrototype, Owner.Transform.MapPosition);
            }

            if (entity.TryGetComponent(out ProjectileComponent projectileComponent))
            {
                if (energyRatio < 1.0)
                {
                    var newDamages = new Dictionary <DamageType, int>(projectileComponent.Damages.Count);
                    foreach (var(damageType, damage) in projectileComponent.Damages)
                    {
                        newDamages.Add(damageType, (int)(damage * energyRatio));
                    }

                    projectileComponent.Damages = newDamages;
                }
            }
            else if (entity.TryGetComponent(out HitscanComponent hitscanComponent))
            {
                hitscanComponent.Damage       *= energyRatio;
                hitscanComponent.ColorModifier = energyRatio;
            }
            else
            {
                throw new InvalidOperationException("Ammo doesn't have hitscan or projectile?");
            }

            UpdateAppearance();
            //Dirty();
            return(entity);
        }
示例#8
0
 public void EjectBody()
 {
     _bodyContainer.Remove(_bodyContainer.ContainedEntity);
     UpdateUserInterface();
     UpdateAppearance();
 }