public void OnHandClick(GUIHand hand) { EnergyMixin mixin = shark.energyInterface.sources[0]; if (mixin.HasItem() && mixin.charge == 0f) { InventoryItem item = mixin.batterySlot.storedItem; mixin.batterySlot.RemoveItem(); Destroy(item.item.gameObject); Pickupable ionCube = CraftData.InstantiateFromPrefab(Shark.depletedIonCube).GetComponent <Pickupable>(); ionCube.transform.position = transform.position + transform.up; if (Player.main.HasInventoryRoom(ionCube)) { Inventory.main.Pickup(ionCube); } } if (!mixin.HasItem()) { if (Inventory.main.GetPickupCount(TechType.PrecursorIonCrystal) >= 1) { Inventory.main.container.RemoveItem(TechType.PrecursorIonCrystal); Pickupable battery = CraftData.InstantiateFromPrefab(Shark.internalBattery).GetComponent <Pickupable>(); InventoryItem item = mixin.batterySlot.AddItem(battery); mixin.NotifyHasBattery(item); } } }
public static void RemoveRandomBattery() { PlayerTool[] playerTools = Inventory.main.gameObject.GetAllComponentsInChildren <PlayerTool>(); List <EnergyMixin> toolMixins = new List <EnergyMixin>(); foreach (PlayerTool playerTool in playerTools) { EnergyMixin toolEnergyMixin = playerTool.GetComponent <EnergyMixin>(); // This is a tool, not something like a floater if (toolEnergyMixin != null && toolEnergyMixin.HasItem()) { toolMixins.Add(toolEnergyMixin); } } if (toolMixins.Count == 0) { // Prevent OutOfBounds errors return; } System.Random random = new System.Random(); int randomMixin = random.Next(0, toolMixins.Count); EnergyMixin energyMixin = toolMixins[randomMixin]; InventoryItem storedBattery = energyMixin.batterySlot.storedItem; energyMixin.batterySlot.RemoveItem(); Inventory.main.ForcePickup(storedBattery.item); }
public void OnHandHover(GUIHand hand) { HandReticle reticle = HandReticle.main; if (!reticle) { return; } EnergyMixin mixin = shark.energyInterface.sources[0]; if (mixin.HasItem()) { if (mixin.charge > 0f) { isValidHandTarget = false; reticle.SetInteractText("Ion Cube", $"{Mathf.Round(mixin.charge / mixin.capacity * 100f)}% Remaining", false, false, HandReticle.Hand.None); } else { isValidHandTarget = true; reticle.SetInteractText("Ion Cube", $"Click to remove", false, false, HandReticle.Hand.Left); } } else { isValidHandTarget = true; reticle.SetInteractText("Insert Ion Cube", false, HandReticle.Hand.Left); } }