//-------------------------------------------------------------------------------------- // AddItem: Add an item to the inventory system. // // Param: // oStack: The item stack to add to the inventory system. // // Return: // bool: return the status of the item adding. //-------------------------------------------------------------------------------------- public bool AddItem(ItemStack oStack) { // loop through each item stack in the inventory foreach (ItemStack i in m_aoItems) { // is the stack empty if (i.IsStackEmpty()) { // set the stack to passed in stack i.SetStack(oStack); // return true, item added return(true); } // is the stack equal to passed in stack if (ItemStack.AreItemsEqual(oStack, i)) { // is it possible to add items to this stack if (i.IsItemAddable(oStack.GetItemCount())) { // increase the stack count i.IncreaseStack(oStack.GetItemCount()); // return true, item added return(true); } // else if the item is not addable else { // new int var, get the difference between passed in stack and current stack int nDifference = (i.GetItemCount() + oStack.GetItemCount()) - i.GetItem().m_nMaxStackSize; // set the count of the stack to the max stack size of the stacks item i.SetItemCount(i.GetItem().m_nMaxStackSize); // set the count of the passed in stack to the stack differnce oStack.SetItemCount(nDifference); } } } // return false, item not added. return(false); }
//-------------------------------------------------------------------------------------- // OnRightClick: What the item slot will do on a right click. // // Param: // oCurrentSelectedStack: an ItemStack of the current stack. // oCurrentStackCopy: and ItemStack of the copy of the item stack. //-------------------------------------------------------------------------------------- private void OnRightClick(ItemStack oCurrentSelectedStack, ItemStack oCurrentStackCopy) { // if the current stack is not empty and the selected stack is empty if (!m_oCurrentStack.IsStackEmpty() && oCurrentSelectedStack.IsStackEmpty()) { // split the current stack in half ItemStack oSplitStack = oCurrentStackCopy.SplitStack(oCurrentStackCopy.GetItemCount() / 2); // set the currently selected stack to the split stack. m_gInventoryManger.SetSelectedStack(oSplitStack); // set the contentto the copy of the current stack. SetSlotContent(oCurrentStackCopy); // deactivate the tooltip SetTooltip(string.Empty); } // if the current stack is empty and the selected stack is not empty if (m_oCurrentStack.IsStackEmpty() && !oCurrentSelectedStack.IsStackEmpty()) { // Set the slot content of a new item stack SetSlotContent(new ItemStack(oCurrentSelectedStack.GetItem(), 1)); // get a copy of the currently selected stack ItemStack oCurrentSelectedStackCopy = oCurrentSelectedStack.CopyStack(); // decrease the currently selected count by 1 oCurrentSelectedStackCopy.DecreaseStack(1); // set the currently selected stack in the manager to this one m_gInventoryManger.SetSelectedStack(oCurrentSelectedStackCopy); // deactivate the tooltip SetTooltip(string.Empty); } // if both current stack and selected stack are empty if (!m_oCurrentStack.IsStackEmpty() && !oCurrentSelectedStack.IsStackEmpty()) { // if the items stacks are equal if (ItemStack.AreItemsEqual(oCurrentStackCopy, oCurrentSelectedStack)) { // if the current stack has room to add one item if (m_oCurrentStack.IsItemAddable(1)) { // increase the count of the current stack oCurrentStackCopy.IncreaseStack(1); // set the content of the current slot SetSlotContent(oCurrentStackCopy); // get a copy of the currently selected stack ItemStack oCurrentSelectedStackCopy = oCurrentSelectedStack.CopyStack(); // decrease the count oCurrentSelectedStackCopy.DecreaseStack(1); // set the currently selected stack in the manager to this new one m_gInventoryManger.SetSelectedStack(oCurrentSelectedStackCopy); // deactivate the tooltip SetTooltip(string.Empty); } } } }
//-------------------------------------------------------------------------------------- // OnLeftClick: What the item slot will do on a left click. // // Param: // oCurrentSelectedStack: an ItemStack of the currently slected stack. // oCurrentStackCopy: and ItemStack of the copy of the item stack. //-------------------------------------------------------------------------------------- private void OnLeftClick(ItemStack oCurrentSelectedStack, ItemStack oCurrentStackCopy) { // if the current stack is not empty and the selected stack is empty if (!m_oCurrentStack.IsStackEmpty() && oCurrentSelectedStack.IsStackEmpty()) { // set the selected stack to the current stack copy m_gInventoryManger.SetSelectedStack(oCurrentStackCopy); // Set the slot content to empty SetSlotContent(ItemStack.m_oEmpty); // deactivate the tooltip SetTooltip(string.Empty); } // if the current stack is empty and the selected stack is not empty if (m_oCurrentStack.IsStackEmpty() && !oCurrentSelectedStack.IsStackEmpty()) { // Set the slot content to the current selected stack SetSlotContent(oCurrentSelectedStack); // set the current selected stack to empty m_gInventoryManger.SetSelectedStack(ItemStack.m_oEmpty); // activate the tooltip SetTooltip(m_oCurrentStack.GetItem().m_strTitle); } // if both current stack and selected stack are empty if (!m_oCurrentStack.IsStackEmpty() && !oCurrentSelectedStack.IsStackEmpty()) { // are the stacks equal if (ItemStack.AreItemsEqual(oCurrentStackCopy, oCurrentSelectedStack)) { // Can you add to the stack copy if (oCurrentStackCopy.IsItemAddable(oCurrentSelectedStack.GetItemCount())) { // increase the current stack copy count by the selected stack count oCurrentStackCopy.IncreaseStack(oCurrentSelectedStack.GetItemCount()); // set the slot conent to the current stack copy SetSlotContent(oCurrentStackCopy); // set the currently selected stack to empty m_gInventoryManger.SetSelectedStack(ItemStack.m_oEmpty); // activate the tooltip SetTooltip(m_oCurrentStack.GetItem().m_strTitle); } // else if the item is not addable else { // new int var, get the difference between current copied stak and currently selected stack int nDifference = (oCurrentStackCopy.GetItemCount() + oCurrentSelectedStack.GetItemCount()) - oCurrentStackCopy.GetItem().m_nMaxStackSize; // set the current copy stack count to the max stack size of the stacks item oCurrentStackCopy.SetItemCount(m_oCurrentStack.GetItem().m_nMaxStackSize); // get a copy of the currently selected stack ItemStack oCurrentSelectedStackCopy = oCurrentSelectedStack.CopyStack(); // set the count of the copied current selected stack to the differnce oCurrentSelectedStackCopy.SetItemCount(nDifference); // set the content of the stack to the current stack copy SetSlotContent(oCurrentStackCopy); // set the currently selected stack to the current selected stack copy m_gInventoryManger.SetSelectedStack(oCurrentSelectedStackCopy); // deactivate the tooltip SetTooltip(string.Empty); } } // if the stacks arent equal else { // set the slot content to the currently selected stack SetSlotContent(oCurrentSelectedStack); // set the currently selected stack to the current selected stack copy m_gInventoryManger.SetSelectedStack(oCurrentStackCopy); // deactivate the tooltip SetTooltip(string.Empty); } } }
//-------------------------------------------------------------------------------------- // AddItemAtPosition: Add an item to the inventory system at a set position. // // Param: // oStack: The item stack to add to the inventory system. // nIndex: The position in the inventory to add the item. // // Return: // bool: return the status of the item adding. //-------------------------------------------------------------------------------------- public bool AddItemAtPosition(ItemStack oStack, int nIndex) { // check if the item attempting to add to the inventory is incompatible if (CheckIfIncompatible(oStack.GetItem().m_eItemType, m_aeIncompatibleItems)) { // return false, item not added. return(false); } // is the stack empty if (m_aoItems[nIndex].IsStackEmpty()) { // set the stack to passed in stack m_aoItems[nIndex].SetStack(oStack); // Call Item Stack Added Callback and pass // in item that is being added to the inventory if (OnItemStackAddedCallback != null) { OnItemStackAddedCallback(nIndex); } // return true, item added return(true); } // is the stack equal to passed in stack if (ItemStack.AreItemsEqual(oStack, m_aoItems[nIndex])) { // is it possible to add items to this stack if (m_aoItems[nIndex].IsItemAddable(oStack.GetItemCount())) { // increase the stack count m_aoItems[nIndex].IncreaseStack(oStack.GetItemCount()); // Call Item Stack Updated Callback and pass // in item that is being updated in the inventory if (OnItemStackUpdatedCallback != null) { OnItemStackUpdatedCallback(nIndex); } // return true, item added return(true); } // else if the item is not addable else { // new int var, get the difference between passed in stack and current stack int nDifference = (m_aoItems[nIndex].GetItemCount() + oStack.GetItemCount()) - m_aoItems[nIndex].GetItem().m_nMaxStackSize; // set the count of the stack to the max stack size of the stacks item m_aoItems[nIndex].SetItemCount(m_aoItems[nIndex].GetItem().m_nMaxStackSize); // set the count of the passed in stack to the stack differnce oStack.SetItemCount(nDifference); // Call Item Stack Updated Callback and pass // in item that is being updated in the inventory if (OnItemStackUpdatedCallback != null) { OnItemStackUpdatedCallback(nIndex); } } } // return false, item not added. return(false); }