Exemplo n.º 1
0
        public void RemoveItem(NitroxId ownerId, bool silent = false)
        {
            GameObject             owner   = NitroxEntity.RequireObjectFrom(ownerId);
            Optional <EnergyMixin> opMixin = Optional.OfNullable(owner.GetComponent <EnergyMixin>());

            if (opMixin.HasValue)
            {
                EnergyMixin mixin = opMixin.Value;
                StorageSlot slot  = (StorageSlot)mixin.ReflectionGet("batterySlot");

                // Suppress sound when silent is active
                // Will be used to suppress swap sound at the initialisation of the game
                bool allowedToPlaySounds = true;
                if (silent)
                {
                    allowedToPlaySounds = (bool)mixin.ReflectionGet("allowedToPlaySounds");
                    mixin.ReflectionSet("allowedToPlaySounds", !silent);
                }
                using (packetSender.Suppress <StorageSlotItemRemove>())
                {
                    slot.RemoveItem();
                }
                if (silent)
                {
                    mixin.ReflectionSet("allowedToPlaySounds", allowedToPlaySounds);
                }
            }
            else
            {
                Log.Error("Removing storage slot item: Could not find storage slot field on object " + owner.name);
            }
        }
Exemplo n.º 2
0
        public void AddItem(GameObject item, NitroxId containerId, bool silent = false)
        {
            Optional <GameObject> owner = NitroxEntity.GetObjectFrom(containerId);

            if (!owner.HasValue)
            {
                Log.Error("Could not place " + item.name + " in storageSlot container with id " + containerId);
                return;
            }

            // only need to watch EnergyMixin slots for now (only other type will be propulsion cannon)
            Optional <EnergyMixin> opEnergy = Optional.OfNullable(owner.Value.GetComponent <EnergyMixin>());

            if (opEnergy.HasValue)
            {
                EnergyMixin mixin = opEnergy.Value;
                StorageSlot slot  = (StorageSlot)mixin.ReflectionGet("batterySlot");

                Pickupable pickupable = item.RequireComponent <Pickupable>();

                // Suppress sound when silent is active
                // Will be used to suppress swap sound at the initialisation of the game
                bool allowedToPlaySounds = true;
                if (silent)
                {
                    allowedToPlaySounds = (bool)mixin.ReflectionGet("allowedToPlaySounds");
                    mixin.ReflectionSet("allowedToPlaySounds", !silent);
                }
                using (packetSender.Suppress <StorageSlotItemAdd>())
                {
                    slot.AddItem(new InventoryItem(pickupable));
                }
                if (silent)
                {
                    mixin.ReflectionSet("allowedToPlaySounds", allowedToPlaySounds);
                }
            }
        }
Exemplo n.º 3
0
        public void AddItem(GameObject item, NitroxId containerId, bool silent = false)
        {
            GameObject owner = NitroxEntity.RequireObjectFrom(containerId);

            // only need to watch EnergyMixin slots for now (only other type will be propulsion cannon)
            Optional <EnergyMixin> opEnergy = Optional <EnergyMixin> .OfNullable(owner.GetComponent <EnergyMixin>());

            if (opEnergy.IsPresent())
            {
                EnergyMixin mixin = opEnergy.Get();
                StorageSlot slot  = (StorageSlot)mixin.ReflectionGet("batterySlot");

                Pickupable pickupable = item.RequireComponent <Pickupable>();

                // Suppress sound when silent is active
                // Will be used to suppress swap sound at the initialisation of the game
                bool allowedToPlaySounds = true;
                if (silent)
                {
                    allowedToPlaySounds = (bool)mixin.ReflectionGet("allowedToPlaySounds");
                    mixin.ReflectionSet("allowedToPlaySounds", !silent);
                }
                using (packetSender.Suppress <StorageSlotItemAdd>())
                {
                    slot.AddItem(new InventoryItem(pickupable));
                }
                if (silent)
                {
                    mixin.ReflectionSet("allowedToPlaySounds", allowedToPlaySounds);
                }
            }
            else
            {
                Log.Error("Add storage slot item: Could not find BatterySource field on object " + owner.name);
            }
        }