public void SellItem(Inventory_Slot slot) { Item itemToSell = tradersInventory.FindItemInSlot(slot); //print("Selling Item"); thisInventory.AddItemToInventory(tradersInventory.FindItemInSlot(slot), -1); tradersInventory.RemoveItemFromInventory(null, tradersInventory.WhichInventorySlot(slot.GetComponentInChildren <InventorySlotIcon>())); thisInventory.RemoveMoney(itemToSell.GetValue()); tradersInventory.AddMoney(itemToSell.GetValue()); shopUIManager.UpdateUI(); }
public void BuyItem(Inventory_Slot slot) { Item itemToBuy = thisInventory.FindItemInSlot(slot); Money convertedAmount = CalculateAmountToPay(itemToBuy.GetValue(), shopsSellRate); if (tradersInventory.EnoughMoney(convertedAmount)) { tradersInventory.RemoveMoney(convertedAmount); thisInventory.AddMoney(convertedAmount); thisInventory.RemoveItemFromInventory(null, thisInventory.WhichInventorySlot(slot.GetComponentInChildren <InventorySlotIcon>())); shopUIManager.UpdateUI(); tradersInventory.AddItemToInventory(itemToBuy, -1); } else { print("You do not have enough money"); } }
public static bool TakeControl(Inventory_Slot slot1) { if (slot == null) { Debug.Log("elimizde eleman yok alıyorsun..."); if (slot1.getItem() == null) { Debug.Log("elimizde eleman yok alıyorsun... ama burası boş"); return(false); } Debug.Log("elimizde eleman yok alıyorsun... ve aldın"); slot = slot1; moving = true; slot.makeTransparent(); return(true); } return(false); }
void DragItemInEquipSlot(Inventory_Slot slot, int numOfSlot) //here is where we check what to do with the lot we are placing on { bool equiped = false; if (slot.item.equipType == eDisplay.equipment.container[numOfSlot].allowedEquip[0]) { if (eDisplay.equipment.container[numOfSlot].item == null) //if its empty { eDisplay.equipment.container[numOfSlot].item = slot.item; //fill the equipment slot eDisplay.equipment.container[numOfSlot].amount = slot.amount; equiped = true; } else { //remember the game object we are replacing GameObject remember = eDisplay.equipDisplay[eDisplay.equipment.container[numOfSlot]]; eDisplay.equipDisplay.Remove(eDisplay.objToEquipment[eDisplay.equipDisplay[eDisplay.equipment.container[numOfSlot]]]); //remove the current from the display iDisplay.inventory.AddItem(eDisplay.equipment.container[numOfSlot].item, eDisplay.equipment.container[numOfSlot].amount); //and the one we replaced back to the inventory Destroy(remember); //destroy the object we are replacing eDisplay.equipment.container[numOfSlot].item = slot.item; //fill the equipment slot eDisplay.equipment.container[numOfSlot].amount = slot.amount; equiped = true; } } else { //if the type doesn't match return the object objectToDrag.position = originalPosition; slotOfTheObjHolder.occupied = true; } //if it fits remove it from inventory if (equiped) { iDisplay.objToItems.Remove(objectToDrag.gameObject); iDisplay.itemsDisplayed.Remove(slot); iDisplay.inventory.container.Remove(slot); Destroy(objectToDrag.gameObject); } }
private void DropIcon() { if (OverAnotherEquipmentSlot()) // Droping onto an equipment slot { isHoldIcon = false; selectedIcon.transform.SetParent(selectedIconOrginalHome.transform); selectedIcon.transform.position = selectedIconOrginalHome.transform.position; Inventory_Slot tempInventorySlot = selectedIcon.GetComponentInParent <Inventory_Slot>(); print(tempInventorySlot); SwapEquipmentAndInventory(OverAnotherEquipmentSlot(), tempInventorySlot); return; } if (OverAnotherInventorySlot() == null || OverAnotherInventorySlot() == selectedIconOrginalHome.GetComponent <Inventory_Slot>()) { isHoldIcon = false; selectedIcon.transform.SetParent(selectedIconOrginalHome.transform); selectedIcon.transform.position = selectedIconOrginalHome.transform.position; //print(selectedIcon.transform.position); } else { isHoldIcon = false; selectedIcon.transform.SetParent(selectedIconOrginalHome.transform); selectedIcon.transform.position = selectedIconOrginalHome.transform.position; if (selectedIconOrginalHome.GetComponent <Inventory_Slot>() != null) { print("Test1"); inventoryManager.SwitchBagSlots(selectedIcon.GetComponent <InventorySlotIcon>(), OverAnotherInventorySlot().GetComponentInChildren <InventorySlotIcon>()); } if (selectedIconOrginalHome.GetComponent <Equipment_Slot>() != null) // Droping from and equipment slot onto and inventory { Equipment_Slot tempEquipmentSlot = selectedIcon.GetComponentInParent <Equipment_Slot>(); SwapEquipmentAndInventory(tempEquipmentSlot, OverAnotherInventorySlot()); return; } } }
public static bool PutControl(Inventory_Slot slot1) { if (slot != null) { Debug.Log("şu anda yerleştiriyorsun"); if (slot1.getItem() != null) { Debug.Log("burası dolu kardeşim"); return(false); } Debug.Log("koyuyorsun"); slot.makeNonTransparent(); slot1.AddItem(slot.getItem()); slot.ClearSlot(); slot = null; moving = false; return(true); } return(false); }
//=====Equipment Management with Inventory===== public void SwapEquipmentAndInventory(Equipment_Slot equipmentSlot, Inventory_Slot inventorySlot) { Item tempEquipSlotItem = equipmentManager.WhichItemInSlot(equipmentSlot); Item tempInventoryItem = inventoryManager.FindItemInSlot(inventorySlot); if (equipmentManager.DoesEquipmentMatchSlot(tempInventoryItem, equipmentSlot) == true) { Debug.Log("Slot is correct"); inventoryManager.RemoveItemFromInventory(null, inventoryManager.WhichInventorySlot(inventorySlot.GetComponentInChildren <InventorySlotIcon>())); inventoryManager.AddItemToInventory(tempEquipSlotItem, inventoryManager.WhichInventorySlot(inventorySlot.GetComponentInChildren <InventorySlotIcon>())); //equipmentManager.UnEquipSlot(equipmentSlot); Was stopping flow of execution, not sure why. equipmentManager.EquipEquipmentInSlot(tempInventoryItem, equipmentSlot); // TODO, Semi cheaty as it does not remove before adding new ones it just overides } else if (tempInventoryItem == null && tempEquipSlotItem != null) { inventoryManager.AddItemToInventory(tempEquipSlotItem, inventoryManager.WhichInventorySlot(inventorySlot.GetComponentInChildren <InventorySlotIcon>())); equipmentManager.EquipEquipmentInSlot(tempInventoryItem, equipmentSlot); } else { Debug.Log("Slot not correct"); } }
public void UseItemAbility(Inventory_Slot slot) { Item itemToUse = FindItemInSlot(slot); if (itemToUse.GetItemType() == ItemType.Consumable) { if (characterStats.Consume(itemToUse)) { RemoveItemFromInventory(null, WhichInventorySlot(slot.GetComponentInChildren <InventorySlotIcon>())); } } if (itemToUse.GetEquipmentSlotType() == EquipmentSlotType.RHWeapon) // DO WHEN ADDING NEW SLOTS { Equipment_Slot tempEquipmentSlot = equipmentManager.GetUIRightHand().GetComponent <Equipment_Slot>(); Inventory_Slot tempInventorySlot = uIInventorySlotsIcons[FindItemInBagSlot(itemToUse)].GetComponentInParent <Inventory_Slot>(); uiInventoryManager.SwapEquipmentAndInventory(tempEquipmentSlot, tempInventorySlot); } if (itemToUse.GetEquipmentSlotType() == EquipmentSlotType.BodyArmour) { Equipment_Slot tempEquipmentSlot = equipmentManager.GetUIBodyArmour().GetComponent <Equipment_Slot>(); Inventory_Slot tempInventorySlot = uIInventorySlotsIcons[FindItemInBagSlot(itemToUse)].GetComponentInParent <Inventory_Slot>(); uiInventoryManager.SwapEquipmentAndInventory(tempEquipmentSlot, tempInventorySlot); } }
void Update() { if (!uis[0].activeSelf && !uis[1].activeSelf) { if (objectToDrag != null) { objectToDrag.position = originalPosition; slotOfTheObjHolder.occupied = true; objectToDragImage.raycastTarget = true; objectToDrag = null; } dragging = false; clicked = false; } #region hover if (GetDraggableTransformUnderMouse()) { target = GetDraggableTransformUnderMouse(); if (target != null) { if (Input.GetKeyDown(KeyCode.Delete)) { Inventory_Slot newSlot = iDisplay.objToItems[target.gameObject]; GameObject clone = Instantiate(prefab, GameObject.FindObjectOfType <Player_Input>().gameObject.transform.position + new Vector3(0, -3, 0), Quaternion.identity); clone.GetComponent <Item_Component>().itemType = iDisplay.objToItems[target.gameObject].item; clone.GetComponent <Item_Component>().amount = iDisplay.objToItems[target.gameObject].amount; GameObject remember = target.gameObject; iDisplay.objToItems.Remove(target.gameObject); iDisplay.itemsDisplayed.Remove(newSlot); Destroy(remember); iDisplay.inventory.container.Remove(newSlot); slotOfTheObjHolder.occupied = false; } toolTip.panel.SetActive(true); Inventory_Slot slot; if (iDisplay.objToItems.ContainsKey(target.gameObject)) { slot = iDisplay.objToItems[target.gameObject]; toolTip.slot = slot; } else if (eDisplay.objToEquipment.ContainsKey(target.gameObject)) { slot = eDisplay.objToEquipment[target.gameObject]; toolTip.slot = slot; } else { toolTip.slot = null; } } else { toolTip.slot = null; } } else { toolTip.slot = null; toolTip.panel.SetActive(false); } #endregion #region RightClick equip if (Input.GetMouseButtonDown(1) && !dragging) { //later try doing this with iDs target = GetDraggableTransformUnderMouse(); Inventory_Slot slot; bool equiped = false; if (target != null) { if (iDisplay.objToItems.ContainsKey(target.gameObject)) { slot = iDisplay.objToItems[target.gameObject]; //Move the item from inventory to equip for (int i = 0; i < eDisplay.equipment.container.Count; i++) { if (slot.item.equipType == eDisplay.equipment.container[i].allowedEquip[0]) { if (eDisplay.equipment.container[i].item == null) { eDisplay.equipment.container[i].item = slot.item; eDisplay.equipment.container[i].amount = slot.amount; equiped = true; break; } } } if (!equiped) { for (int i = 0; i < eDisplay.equipment.container.Count; i++) { if (slot.item.equipType == eDisplay.equipment.container[i].allowedEquip[0]) { if (eDisplay.equipment.container[i].item != null) { //remember the game object GameObject remember = eDisplay.equipDisplay[eDisplay.equipment.container[i]]; eDisplay.equipDisplay.Remove(eDisplay.objToEquipment[eDisplay.equipDisplay[eDisplay.equipment.container[i]]]); iDisplay.inventory.AddItem(eDisplay.equipment.container[i].item, eDisplay.equipment.container[i].amount); Destroy(remember); eDisplay.equipment.container[i].item = slot.item; eDisplay.equipment.container[i].amount = slot.amount; break; } } } } //now remove that item from the inventory if (slot.item.type == ItemType.Equipable) { slotOfTheObjHolder.occupied = false; iDisplay.objToItems.Remove(target.gameObject); iDisplay.itemsDisplayed.Remove(slot); iDisplay.inventory.container.Remove(slot); Destroy(target.gameObject); } } else if (eDisplay.objToEquipment.ContainsKey(target.gameObject)) { slot = eDisplay.objToEquipment[target.gameObject]; iDisplay.inventory.AddItem(slot.item, slot.amount); print("Removed"); //remove the f****r eDisplay.objToEquipment.Remove(target.gameObject); eDisplay.equipDisplay.Remove(slot); eDisplay.equipment.container[eDisplay.equipment.container.IndexOf(slot)].item = null; eDisplay.equipment.container[eDisplay.equipment.container.IndexOf(slot)].amount = 0; Destroy(target.gameObject); } } } #endregion #region ConsumeItem if (Input.GetMouseButtonDown(2)) { target = GetDraggableTransformUnderMouse(); if (target != null) { Inventory_Slot slot; slot = iDisplay.objToItems[target.gameObject]; if (slot.item.type == ItemType.Default && slot.item.buffs.Length > 0) { slot.amount--; if (slot.amount <= 0) { slotOfTheObjHolder.occupied = false; } } } } #endregion #region pick up and dragg if (dragging) { objectToDrag.position = Input.mousePosition; clicked = true; } if (Input.GetMouseButtonDown(0) && !dragging) { objectToDrag = GetDraggableTransformUnderMouse(); if (objectToDrag != null) { itsOnInventory = OnInvDisplay(); itsOnEquipment = OnEquipDisplay(); dragging = true; objectToDrag.SetAsLastSibling(); originalPosition = objectToDrag.position; objectToDragImage = objectToDrag.GetComponentInChildren <Image>(); objectToDragImage.raycastTarget = false; slotOfTheObjHolder.occupied = false; } } if (Input.GetMouseButtonDown(0) && clicked) { if (objectToDrag != null) { var objectToReplace = GetDraggableTransformUnderMouse(); //Found an object if (objectToReplace != null) { OrganizeItem(objectToReplace); } else { if (eDisplay.objToEquipment.ContainsKey(objectToDrag.gameObject)) { Inventory_Slot slot = eDisplay.objToEquipment[objectToDrag.gameObject]; GameObject clone = Instantiate(prefab, GameObject.FindObjectOfType <Player_Input>().gameObject.transform.position + new Vector3(0, -3, 0), Quaternion.identity); clone.GetComponent <Item_Component>().itemType = eDisplay.objToEquipment[objectToDrag.gameObject].item; clone.GetComponent <Item_Component>().amount = eDisplay.objToEquipment[objectToDrag.gameObject].amount; GameObject remember = objectToDrag.gameObject; eDisplay.objToEquipment.Remove(objectToDrag.gameObject); eDisplay.equipDisplay.Remove(slot); Destroy(remember); eDisplay.equipment.container.Remove(slot); slotOfTheObjHolder.occupied = false; } else { Inventory_Slot slot = iDisplay.objToItems[objectToDrag.gameObject]; GameObject clone = Instantiate(prefab, GameObject.FindObjectOfType <Player_Input>().gameObject.transform.position + new Vector3(0, -3, 0), Quaternion.identity); clone.GetComponent <Item_Component>().itemType = iDisplay.objToItems[objectToDrag.gameObject].item; clone.GetComponent <Item_Component>().amount = iDisplay.objToItems[objectToDrag.gameObject].amount; GameObject remember = objectToDrag.gameObject; iDisplay.objToItems.Remove(objectToDrag.gameObject); iDisplay.itemsDisplayed.Remove(slot); Destroy(remember); iDisplay.inventory.container.Remove(slot); slotOfTheObjHolder.occupied = false; } } objectToDragImage.raycastTarget = true; objectToDrag = null; } dragging = false; clicked = false; } #endregion }
void OrganizeItem(Transform objToReplace) { //check where the picked up item came from if (iDisplay.objToItems.ContainsKey(objectToDrag.gameObject)) { //check where we are leaving it itsOnInventory = OnInvDisplay(); itsOnEquipment = OnEquipDisplay(); if (itsOnInventory) { //regulary do your thing if (objToReplace.GetComponent <Slot_Component>()) //first check if its over an empty slot { objectToDrag.position = objToReplace.position; slotOfTheObjHolder.occupied = false; //set the slot we took it from to unoccupied objToReplace.GetComponent <Slot_Component>().occupied = true; } else { objectToDrag.position = objToReplace.position; objToReplace.position = originalPosition; slotOfTheObjHolder.occupied = true; //because you are just switching out values in the slot they both stay occupied } } else if (itsOnEquipment) { //so its on equipment now, time to mess about and see what we hit if (objToReplace.GetComponent <Slot_Component>()) //first check if its over an empty slot { //check which type the slot is int numOfSlot = eDisplay.equipSlots.IndexOf(objToReplace.GetComponentInParent <Slot_Component>().transform); //first get the number of that slot //then compare it with the equip type Inventory_Slot slot = iDisplay.objToItems[objectToDrag.gameObject]; DragItemInEquipSlot(slot, numOfSlot); } else { //check which type the slot is int numOfSlot = eDisplay.equipSlots.IndexOf(objToReplace.GetComponentInParent <Slot_Component>().transform); //first get the number of that slot print(numOfSlot); //then compare it with the equip type Inventory_Slot slot = iDisplay.objToItems[objectToDrag.gameObject]; DragItemInEquipSlot(slot, numOfSlot); } } } if (eDisplay.objToEquipment.ContainsKey(objectToDrag.gameObject)) { print("It belongs to equipment"); //check where we are leaving it itsOnInventory = OnInvDisplay(); itsOnEquipment = OnEquipDisplay(); if (itsOnInventory) { int numOfSlot = eDisplay.equipSlots.IndexOf(objectToDrag.GetComponentInParent <Slot_Component>().transform); //first get the number of that slot Inventory_Slot slot = eDisplay.objToEquipment[objectToDrag.gameObject]; iDisplay.inventory.AddItem(eDisplay.equipment.container[numOfSlot].item, eDisplay.equipment.container[numOfSlot].amount); eDisplay.equipment.container[numOfSlot].item = null; eDisplay.objToEquipment.Remove(objectToDrag.gameObject); eDisplay.equipDisplay.Remove(slot); Destroy(objectToDrag.gameObject); objectToDrag.position = objToReplace.position; slotOfTheObjHolder.occupied = false; //set the slot we took it from to unoccupied } else if (itsOnEquipment) { //so its on equipment now, time to mess about and see what we hit if (objToReplace.GetComponent <Slot_Component>()) //first check if its over an empty slot { //check which type the slot is int numOfSlot = eDisplay.equipSlots.IndexOf(objToReplace.GetComponentInParent <Slot_Component>().transform); //first get the number of that slot //then compare it with the equip type Inventory_Slot slot = eDisplay.objToEquipment[objectToDrag.gameObject]; DragItemInEquipSlot(slot, numOfSlot); } else { //check which type the slot is int numOfSlot = eDisplay.equipSlots.IndexOf(objToReplace.GetComponentInParent <Slot_Component>().transform); //first get the number of that slot print(numOfSlot); //then compare it with the equip type Inventory_Slot slot = eDisplay.objToEquipment[objectToDrag.gameObject]; DragItemInEquipSlot(slot, numOfSlot); } } } }
public Item FindItemInSlot(Inventory_Slot slot) // Finds what item is in a spesific slot { return(inventoryItems[WhichInventorySlot(slot.GetComponentInChildren <InventorySlotIcon>())]); }