public void OnParentProductSelected(InventoryProductDetails selectedItem) { // query db, get all variations for this item inventoryItems = inventoryDAL.GetAllVariations(selectedItem.inventoryItem); inventoryItemsOrig = inventoryItems.Clone(); PopulateDataGridView(inventoryItems); }
private void UndoChanges(InventoryProductEditorUndoChanges obj) { // // NOTE: We don't really need the clone. I think we can just pass "inventoryItems", since I'm not // updating the class as the datagrid gets updated. // inventoryItems = inventoryItemsOrig.Clone(); PopulateDataGridView(inventoryItems); }
public bool ReceiveItem(InventoryItem itemToBeGrabbed) { if (AddItem(itemToBeGrabbed.Clone())) { return(true); } else { return(false); } }
public bool UpdateInventoryItem(InventoryItem item) { if (_inventoryItems.ContainsKey(item.Id)) { _inventoryItems[item.Id] = item.Clone(); } else { throw new Exception("Item does not exist."); } return(true); }
/// <summary> /// Add an InventoryItem to Inventory /// </summary> /// <param name="item">Item to add</param> /// <param name="forceAdd">Optional ignore CanInventoryItemBePutIntoSlot</param> /// <param name="targetSlotIndex">Optional target slot</param> /// <returns>Whether the inventory item was completely added or not</returns> public bool AddItem(InventoryItem item, bool forceAdd = false, byte?targetSlotIndex = null) { if (!CanAddItemToInventory() && !forceAdd) { return(false); } var canStack = !item.HasDurability(); if (canStack) { MergeItem(item); } if (item.GetCount() == 0) { return(true); } if (targetSlotIndex.HasValue) { if (_slots[targetSlotIndex.Value] != null) { CombineStacks(_slots[targetSlotIndex.Value], item); } } for (var slotIndex = 0; slotIndex < _slots.Length; ++slotIndex) { if (_slots[slotIndex] != null && _slots[slotIndex].GetCount() > 0) { continue; } if (!CanSlotAccomodateItem(slotIndex, item)) { continue; } _slots[slotIndex] = item.Clone(this); _slots[slotIndex].OnItemChanged += StackChanged; if (item.Inventory != null) { item.SetCount(0); } StackChanged((byte)slotIndex); return(true); } return(false); }
public InventoryItem GetInventoryItem(int inventoryId) { InventoryItem item = null; if (_inventoryItems.ContainsKey(inventoryId)) { item = _inventoryItems[inventoryId]; } else { throw new Exception("Item does not exist."); } return(item.Clone()); }
public void EquipItem(InventoryItem item) { PlayableCharacter character = CurrentPartyMember; switch (item.ItemType) { case ItemType.Weapon: DebugMessage(string.Format("Swapping {0}'s {1} for a {2}", character.Name, character.Weapon.Name, item.Name)); InventoryItem equippedWeapon = character.Weapon; _inventory.GainItem(equippedWeapon.Clone()); character.UnequipItem(ItemType.Weapon); character.EquipItem(ItemType.Weapon, item); _equipment.ReloadAccessoryStats(character.Weapon); break; case ItemType.Armor: DebugMessage(string.Format("Swapping {0}'s {1} for a {2}", character.Name, character.Armor.Name, item.Name)); InventoryItem equippedArmor = character.Armor; _inventory.GainItem(equippedArmor.Clone()); character.UnequipItem(ItemType.Armor); character.EquipItem(ItemType.Armor, item); _equipment.ReloadAccessoryStats(character.Armor); break; case ItemType.Accessory: DebugMessage(string.Format("Swapping {0}'s {1} for a {2}", character.Name, character.Accessory.Name, item.Name)); InventoryItem equippedAccessory = character.Accessory; _inventory.GainItem(equippedAccessory.Clone()); character.UnequipItem(ItemType.Accessory); character.EquipItem(ItemType.Accessory, item); _equipment.ReloadAccessoryStats(character.Accessory); break; default: throw new Exception("Unexpected item type: " + item.ItemType); } _inventory.LoseItem(item); _member.ReloadCharacterStats(character); OpenEquipment(); }
/// <summary> /// Try and store an InventoryItem (or stack) into this inventory space. /// Will return NotEnoughSpace if some or all of the items cannot be stored. /// Otherwise, will return Success if all the items are stored. /// /// The input item will have its count decremented by the /// amount that was stored in this inventory space. /// </summary> public InventoryResult Store(InventoryItem item) { if (!isAccessible) { return(InventoryResult.SpaceNotAccessible); } if (item != null || !item.IsValid) { return(InventoryResult.InvalidItem); } // See if we can store (some of) the items in an existing stack. InventoryItem dest = GetItemWithSpace(item); if (dest != null) { TransferItems(item, dest); } // If we still have items left after trying to transfer // to existing stack, then create a new InventoryItem to store them. while (Available >= item.unitVolume && item.count > 0) { InventoryItem newStack = item.Clone(); items.Add(newStack); TransferItems(item, newStack); } // If not everything was moved over, then return that there's // not enough space. if (item.count > 0) { return(InventoryResult.NotEnoughSpace); } else { return(InventoryResult.Success); } }
/// <summary> /// Copy an InventoryItem into a slot of this Inventory. /// </summary> /// <param name="slotIndex">Slot index</param> /// <param name="item">InventoryItem to use as a source</param> /// <returns>The cloned InventoryItem</returns> public InventoryItem SetItem(byte slotIndex, InventoryItem item) { if (item != null) { if (item.GetCount() == 0) { _slots[slotIndex] = null; } else { _slots[slotIndex] = item.Clone(this); _slots[slotIndex].OnItemChanged += StackChanged; } } else { _slots[slotIndex] = null; } StackChanged(slotIndex); return(_slots[slotIndex]); }
public int AddInventoryItem(InventoryItem item) { item.Id = _inventoryId++; _inventoryItems.Add(item.Id, item.Clone()); return(item.Id); }
virtual public InventoryItem GetItem() { return(item.Clone()); }
public void Draggable_OnMousePressed(DragAreaIndicator dragAreaIndicator, Vector3 diffFromStart, Vector3 deltaFromLastFrame) { void ResumePausedDrag() { InventoryItem.GridPos_Matrix = dragStartGridPos_Matrix; UIInventory.RemoveItem(InventoryItem, true); Destroy(gameObject); DragManager.Instance.ResumePausedDrag(); } if (dragAreaIndicator == UIInventory.DragAreaIndicator) { if (UIInventory.RotateItemKeyDownHandler != null && UIInventory.RotateItemKeyDownHandler.Invoke()) { Rotate(); } if (diffFromStart.magnitude > Draggable_DragMinDistance) { Vector2 diffLocal = RectTransform.parent.InverseTransformVector(diffFromStart); Vector2 currentLocalPos = dragStartLocalPos + diffLocal; GridPosR diff_world = GridPos.GetGridPosByPointXY(diffLocal, UIInventory.GridSize); diff_world.orientation = InventoryItem.GridPos_Matrix.orientation; GridPosR diff_matrix = UIInventory.CoordinateTransformationHandler_FromPosToMatrixIndex(diff_world); GridPosR gp_matrix = dragStartGridPos_Matrix + diff_matrix; gp_matrix.orientation = InventoryItem.GridPos_Matrix.orientation; InventoryItem.GridPos_Matrix = gp_matrix; SetVirtualGridPos(InventoryItem.GridPos_World); RectTransform.anchoredPosition = currentLocalPos; } } else { Vector2 diffLocal = RectTransform.parent.InverseTransformVector(diffFromStart); Vector2 currentLocalPos = dragStartLocalPos + diffLocal; RectTransform.anchoredPosition = currentLocalPos; UIInventory.UIInventoryPanel.UIInventoryVirtualOccupationQuadRoot.Clear(); if (dragAreaIndicator != null) // drag to other DragAreas { if (DragManager.Instance.PausedDrag != null) { ResumePausedDrag(); } else { // only when mouse move to available grid then generate previewItem if (dragAreaIndicator is UIInventoryDragAreaIndicator uiDAI) { uiDAI.UIInventory.UIInventoryPanel.UIInventoryDragAreaIndicator.GetMousePosOnThisArea(out Vector3 pos_world, out Vector3 pos_local, out Vector3 pos_matrix, out GridPos gp_matrix); GridPosR gpr = gp_matrix; gpr.orientation = InventoryItem.GridPos_Matrix.orientation; InventoryItem previewItem = new InventoryItem(InventoryItem.Clone().ItemContentInfo, uiDAI.UIInventory, gpr); uiDAI.UIInventory.AddPreviewItem(previewItem); UIInventoryItem uiInventoryItem = uiDAI.UIInventory.UIInventoryPanel.GetUIInventoryItem(previewItem.GUID); DragManager.Instance.PauseDrag(); DragManager.Instance.CurrentDrag = uiInventoryItem.Draggable; uiInventoryItem.Draggable.SetOnDrag(true, uiDAI.UIInventory.UIInventoryPanel.UIInventoryDragAreaIndicator.BoxCollider, UIInventory.DragProcessor); } } } else // drag to non-DragArea { if (DragManager.Instance.PausedDrag != null) { ResumePausedDrag(); } } } }
public InventoryItem Combine(InventoryItem item) { return(item.Clone()); //Todo crafting in separate Craft-class }