public void SpawnDefaultBatteries(GameObject constructedObject, List <InteractiveChildObjectIdentifier> childIdentifiers) { Optional <EnergyMixin> opEnergy = Optional.OfNullable(constructedObject.GetComponent <EnergyMixin>()); if (opEnergy.HasValue) { EnergyMixin mixin = opEnergy.Value; mixin.ReflectionSet("allowedToPlaySounds", false); mixin.SetBattery(mixin.defaultBattery, 1); mixin.ReflectionSet("allowedToPlaySounds", true); } foreach (InteractiveChildObjectIdentifier identifier in childIdentifiers) { Optional <GameObject> opChildGameObject = NitroxEntity.GetObjectFrom(identifier.Id); if (opChildGameObject.HasValue) { Optional <EnergyMixin> opEnergyMixin = Optional.OfNullable(opChildGameObject.Value.GetComponent <EnergyMixin>()); if (opEnergyMixin.HasValue) { EnergyMixin mixin = opEnergyMixin.Value; mixin.ReflectionSet("allowedToPlaySounds", false); mixin.SetBattery(mixin.defaultBattery, 1); mixin.ReflectionSet("allowedToPlaySounds", true); } } } }
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); } }
// As the normal spawn is suppressed, spawn default batteries afterwards private void SpawnDefaultBatteries(GameObject constructedObject, List <InteractiveChildObjectIdentifier> childIdentifiers) { Optional <EnergyMixin> opEnergy = Optional <EnergyMixin> .OfNullable(constructedObject.GetComponent <EnergyMixin>()); if (opEnergy.IsPresent()) { EnergyMixin mixin = opEnergy.Get(); mixin.ReflectionSet("allowedToPlaySounds", false); mixin.SetBattery(mixin.defaultBattery, 1); mixin.ReflectionSet("allowedToPlaySounds", true); } foreach (InteractiveChildObjectIdentifier identifier in childIdentifiers) { Optional <GameObject> opChildGameObject = GuidHelper.GetObjectFrom(identifier.Guid); if (opChildGameObject.IsPresent()) { opChildGameObject.Get().AddComponent <NitroxEntity>(); Optional <EnergyMixin> opEnergyMixin = Optional <EnergyMixin> .OfNullable(opChildGameObject.Get().GetComponent <EnergyMixin>()); if (opEnergyMixin.IsPresent()) { EnergyMixin mixin = opEnergyMixin.Get(); mixin.ReflectionSet("allowedToPlaySounds", false); mixin.SetBattery(mixin.defaultBattery, 1); mixin.ReflectionSet("allowedToPlaySounds", true); } } } }
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); } } }
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); } }