public void AddItem(ItemSlot fromSlot) { if (fromSlot == null || fromSlot.IsEmpty || ((fromSlot.ItemObject.GetComponent <Grindable>() == null && fromSlot.ItemObject.GetComponent <Juiceable>() == null) && !fromSlot.ItemAttributes.HasTrait(CommonTraits.Instance.Beaker))) { return; } if (fromSlot.ItemAttributes.HasTrait(CommonTraits.Instance.Beaker)) { if (itemSlot.IsEmpty) { Inventory.ServerTransfer(fromSlot, itemStorage.GetIndexedItemSlot(0)); } return; } // If there's a stackable component, add one at a time. Stackable stack = fromSlot.ItemObject.GetComponent <Stackable>(); if (stack == null || stack.Amount == 1) { Inventory.ServerTransfer(fromSlot, itemStorage.GetNextFreeIndexedSlot()); } else { var item = stack.ServerRemoveOne(); Inventory.ServerAdd(item, itemStorage.GetNextFreeIndexedSlot()); } }
public void AddItem(ItemSlot fromSlot) { if (fromSlot == null || fromSlot.IsEmpty || fromSlot.ItemObject.GetComponent <Fermentable>() == null || closed) { return; } ItemSlot storageSlot = itemStorage.GetNextFreeIndexedSlot(); bool added = false; // If there's a stackable component, add one at a time. Stackable stack = fromSlot.ItemObject.GetComponent <Stackable>(); if (stack == null || stack.Amount == 1) { added = Inventory.ServerTransfer(fromSlot, storageSlot); } else { var item = stack.ServerRemoveOne(); Inventory.ServerAdd(item, storageSlot); } if (storageSlot.ItemObject.TryGetComponent(out Fermentable fermentable)) { storedFermentables.Add(storageSlot, fermentable); } }
public void PopulateItemStorage(ItemStorage ItemStorage, PopulationContext context) { foreach (var gameObject in DeprecatedContents) { var ItemSlot = ItemStorage.GetNextFreeIndexedSlot(); var spawn = Spawn.ServerPrefab(gameObject, PrePickRandom: true); Inventory.ServerAdd(spawn.GameObject, ItemSlot, IgnoreRestraints: true); } if (SlotContents.Count == 0) { return; } foreach (var namedSlotPopulatorEntry in SlotContents) { ItemSlot ItemSlot; if (namedSlotPopulatorEntry.UesIndex) { ItemSlot = ItemStorage.GetIndexedItemSlot(namedSlotPopulatorEntry.IndexSlot); } else { ItemSlot = ItemStorage.GetNamedItemSlot(namedSlotPopulatorEntry.NamedSlot); } if (ItemSlot == null) { continue; } var spawn = Spawn.ServerPrefab(namedSlotPopulatorEntry.Prefab, PrePickRandom: true); Inventory.ServerAdd(spawn.GameObject, ItemSlot, namedSlotPopulatorEntry.ReplacementStrategy, true); Inventory.PopulateSubInventory(spawn.GameObject, namedSlotPopulatorEntry.namedSlotPopulatorEntrys); } }
public override void PopulateItemStorage(ItemStorage toPopulate, PopulationContext context) { //if appending, start at first free slot index var start = 0; if (MergeMode == IndexedMergeMode.Append) { var freeSlot = toPopulate.GetNextFreeIndexedSlot(); if (freeSlot == null) { Logger.LogTraceFormat("Can't populate {0}, no more free slots.", Category.Inventory, toPopulate); return; } start = freeSlot.SlotIdentifier.SlotIndex; } for (var i = start; i < SlotPopulators.Length; i++) { var slot = toPopulate.GetIndexedItemSlot(i); if (slot == null) { Logger.LogErrorFormat("Storage {0} does not have a slot with index {1}. Please ensure" + " the Contents don't exceed the number of slots in the ItemStorage.", Category.Inventory, toPopulate, i); return; } if (slot.Item != null && MergeMode == IndexedMergeMode.Overwrite) { Inventory.ServerDespawn(slot); } SlotPopulators[i].PopulateSlot(slot, context); } }
private void UpdateTrapVisual() { if (trapContent.GetNextFreeIndexedSlot() != null) { trapPreview.Empty(); return; } //We assume that there will be only one item on each mouse trap (for now) var slot = trapContent.GetTopOccupiedIndexedSlot(); var sprite = slot.Item.gameObject.GetComponentInChildren <SpriteHandler>(); if (sprite.GetCurrentSpriteSO() == null) { trapPreview.SetSprite(sprite.CurrentSprite); return; } trapPreview.SetSpriteSO(sprite.GetCurrentSpriteSO()); }
private bool IsFull(GameObject usedObject, GameObject player) { if (itemStorage.GetNextFreeIndexedSlot() == null && usedObject != null) { Chat.AddExamineMsg(player, $"<color=red>The {usedObject.ExpensiveName()} won't fit in the {itemStorage.gameObject.ExpensiveName()}. Make some space!</color>"); return(true); } return(false); }
private void AddItem(ItemSlot fromSlot) { if (fromSlot == null || fromSlot.IsEmpty || fromSlot.ItemObject.GetComponent <Dryable>() == null) { return; } // If there's a stackable component, add one at a time. Stackable stack = fromSlot.ItemObject.GetComponent <Stackable>(); if (stack == null || stack.Amount == 1) { Inventory.ServerTransfer(fromSlot, storage.GetNextFreeIndexedSlot()); } else { var item = stack.ServerRemoveOne(); Inventory.ServerAdd(item, storage.GetNextFreeIndexedSlot()); } }
public void PopulateItemStorage(ItemStorage toPopulate, PopulationContext context) { //if appending, start at first free slot index var start = 0; if (MergeMode == IndexedStoragePopulator.IndexedMergeMode.Append) { var freeSlot = toPopulate.GetNextFreeIndexedSlot(); if (freeSlot == null) { Logger.LogTraceFormat("Can't populate {0}, no more free slots.", Category.Inventory, toPopulate); return; } start = freeSlot.SlotIdentifier.SlotIndex; } for (var i = start; i < Contents.Count; i++) { // General protection against missing items if (Contents[i] == null) { continue; // Will skip the missing item } var slot = toPopulate.GetIndexedItemSlot(i); if (slot == null) { Logger.LogErrorFormat("Storage {0} does not have a slot with index {1}. Please ensure" + " the Contents don't exceed the number of slots in the ItemStorage.", Category.Inventory, toPopulate, i); return; } if (slot.Item != null && MergeMode == IndexedStoragePopulator.IndexedMergeMode.Overwrite) { Inventory.ServerDespawn(slot); } var spawned = Spawn.ServerPrefab(Contents[i]).GameObject; Inventory.ServerAdd(spawned, slot); } }
private bool TryTransferToMicrowave(PositionalHandApply interaction) { // Close the microwave if nothing is held. if (interaction == null || interaction.UsedObject == null) { SoundManager.PlayNetworkedAtPos(doorSFX.GetRandomClip(), WorldPosition, sourceObj: gameObject); return(false); } // Add held item to the microwave. ItemSlot storageSlot = storage.GetNextFreeIndexedSlot(); bool added = false; if (interaction.HandSlot.ItemObject.TryGetComponent(out Stackable stack)) { if (stack.Amount == 1) { added = Inventory.ServerTransfer(interaction.HandSlot, storageSlot); } else { var item = stack.ServerRemoveOne(); added = Inventory.ServerAdd(item, storageSlot); if (!added) { stack.ServerIncrease(1); // adds back the lost amount to prevent microwaves from eating stackable items } } } else { added = Inventory.ServerTransfer(interaction.HandSlot, storageSlot); } if (storageSlot == null || added == false) { Chat.AddActionMsgToChat(interaction, "The microwave's matter bins are full!", string.Empty); return(true); } if (storageSlot.ItemObject.TryGetComponent(out Cookable cookable) && cookable.CookableBy.HasFlag(CookSource.Microwave)) { storedCookables.Add(storageSlot, cookable); }
private bool TryTransferToMicrowave(PositionalHandApply interaction) { // Close the microwave if nothing is held. if (interaction == null || interaction.UsedObject == null) { SoundManager.PlayNetworkedAtPos(doorSFX.GetRandomClip(), WorldPosition, sourceObj: gameObject); return(false); } // Add held item to the microwave. ItemSlot storageSlot = storage.GetNextFreeIndexedSlot(); if (storageSlot == null || Inventory.ServerTransfer(interaction.HandSlot, storageSlot) == false) { Chat.AddActionMsgToChat(interaction, "The microwave's matter bins are full!", string.Empty); return(true); } if (storageSlot.ItemObject.TryGetComponent(out Cookable cookable) && cookable.CookableBy.HasFlag(CookSource.Microwave)) { storedCookables.Add(storageSlot, cookable); }
public override void PopulateItemStorage(ItemStorage ItemStorage, PopulationContext context) { //Uses the old contents for now foreach (var gameObject in DeprecatedContents) { var ItemSlot = ItemStorage.GetNextFreeIndexedSlot(); var spawn = Spawn.ServerPrefab(gameObject, PrePickRandom: true); Inventory.ServerAdd(spawn.GameObject, ItemSlot, IgnoreRestraints: true); } if (SlotContents.Count == 0) { return; } //Look through the specified slots, and tries to find it on the storage and populates if so, //and then attempts recursion foreach (var namedSlotPopulatorEntry in SlotContents) { ItemSlot ItemSlot; if (namedSlotPopulatorEntry.UesIndex) { ItemSlot = ItemStorage.GetIndexedItemSlot(namedSlotPopulatorEntry.IndexSlot); } else { ItemSlot = ItemStorage.GetNamedItemSlot(namedSlotPopulatorEntry.NamedSlot); } if (ItemSlot == null) { continue; } var spawn = Spawn.ServerPrefab(namedSlotPopulatorEntry.Prefab, PrePickRandom: true); Inventory.ServerAdd(spawn.GameObject, ItemSlot, namedSlotPopulatorEntry.ReplacementStrategy, true); Inventory.PopulateSubInventory(spawn.GameObject, namedSlotPopulatorEntry.namedSlotPopulatorEntrys); } }
// Interaction when clicking the bin public void ServerPerformInteraction(HandApply interaction) { var handObj = interaction.HandObject; if (handObj == null) { var pna = interaction.Performer.GetComponent <PlayerNetworkActions>(); // Pen comes out before the paper if (storedPen) { Chat.AddExamineMsgFromServer(interaction.Performer, "You take the pen out of the paper bin."); Inventory.ServerTransfer(penSlot, interaction.HandSlot); SyncStoredPen(storedPen, null); return; } // Player is picking up a piece of paper if (!HasPaper()) { Chat.AddExamineMsgFromServer(interaction.Performer, "The paper bin is empty!"); return; } Chat.AddExamineMsgFromServer(interaction.Performer, "You take the paper out of the paper bin."); if (!HasPaper()) { throw new InvalidOperationException(); } // First, get the papers that players have put in the bin var occupiedSlot = itemStorage.GetTopOccupiedIndexedSlot(); if (occupiedSlot != null) { //remove it from the slot Inventory.ServerTransfer(occupiedSlot, interaction.HandSlot); } else // Otherwise, take from blank paper stash { var paper = Spawn.ServerPrefab(blankPaper).GameObject; var targetSlot = itemStorage.GetNextFreeIndexedSlot(); Inventory.ServerAdd(paper, interaction.HandSlot); } SyncPaperCount(paperCount, paperCount - 1); } else { // Player is adding a piece of paper or a pen if (handObj.GetComponent <Pen>()) { SyncStoredPen(storedPen, handObj); Chat.AddExamineMsgFromServer(interaction.Performer, "You put the pen in the paper bin."); Inventory.ServerTransfer(interaction.HandSlot, penSlot); return; } var freeSlot = itemStorage.GetNextFreeIndexedSlot(); if (freeSlot == null) { Chat.AddExamineMsgFromServer(interaction.Performer, "The bin is full."); } Chat.AddExamineMsgFromServer(interaction.Performer, "You put the paper in the paper bin."); Inventory.ServerTransfer(interaction.HandSlot, freeSlot); SyncPaperCount(paperCount, paperCount + 1); } }