/// <summary> /// Raises the pointer click event. /// </summary> /// <param name="eventData">Event data.</param> public void OnPointerClick(PointerEventData eventData) { DadCell cell = this.GetComponentInParent <DadCell>(); if (cell.loc == DadCell.Location.crate) { DadCell[] cells = FindObjectsOfType <DadCell>(); for (int i = 0; i < cells.Length; i++) { if (cells[i].GetDadItem() == null && cells[i].loc == DadCell.Location.backpack) { if (cell.GetComponentInChildren <ClickItem>().type == Type.scroll) { int win = 0; DadCell[] cellsI = FindObjectOfType <DummyInventoryControl>().inventory.GetComponentsInChildren <DadCell>(); for (int j = 0; j < cellsI.Length; j++) { if (cellsI[j].GetItem() != null && cellsI[j].GetComponentInChildren <ClickItem>().type == ClickItem.Type.scroll) { win++; } } if (win == 8) { TimeController.butterflies = 9; SceneManager.LoadScene("DeathScene"); } } cells[i].AddItem(cell.GetItem()); cell.RemoveItem(); cell.UpdateBackgroundState(); break; } } } else if (cell.loc == DadCell.Location.backpack && this.type == Type.consumable) { DadItem.eat(cell, this); } else if (cell.loc == DadCell.Location.backpack && this.type == Type.weapon) { DadCell[] cells = FindObjectsOfType <DadCell>(); for (int i = 0; i < cells.Length; i++) { if (cells[i].GetDadItem() == null && cells[i].loc == DadCell.Location.body) { cells[i].AddItem(cell.GetItem()); cell.RemoveItem(); cell.UpdateBackgroundState(); break; } } } }
/// <summary> /// Item is dropped into this cell. /// </summary> /// <param name="data"></param> public void OnDrop(PointerEventData data) { if (DadItem.icon != null) { DadCell sourceCell = DadItem.sourceCell; if (sourceCell != this) { DadEventDescriptor desc = new DadEventDescriptor(); desc.sourceCell = sourceCell; desc.destinationCell = this; if (SendGroupRequest(desc) == true) // Send group request { SendCellRequest(desc); // Send cell request } StartCoroutine(NotifyOnDragEnd(desc)); // Send notification after drop will be finished if (desc.cellPermission == true && desc.groupPermission == true) // If drop permitted { SwapItems(sourceCell, this); // Swap items between cells } } UpdateMyItem(); UpdateBackgroundState(); sourceCell.UpdateMyItem(); sourceCell.UpdateBackgroundState(); } }
/// <summary> /// Swaps DaD items between cells. /// </summary> /// <param name="firstDadCell">First DaD cell.</param> /// <param name="secondDadCell">Second DaD cell.</param> public static void SwapItems(DadCell firstDadCell, DadCell secondDadCell) { if ((firstDadCell != null) && (secondDadCell != null)) { GameObject firstItem = firstDadCell.GetItem(); // Get item from first cell GameObject secondItem = secondDadCell.GetItem(); // Get item from second cell // Swap items firstDadCell.PlaceItem(secondItem, false); secondDadCell.PlaceItem(firstItem, false); // Update states firstDadCell.UpdateMyItem(); secondDadCell.UpdateMyItem(); firstDadCell.UpdateBackgroundState(); secondDadCell.UpdateBackgroundState(); } }