Exemplo n.º 1
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(trigger))
     {
         DadCell   cell2 = this.GetComponentInParent <DadCell>();
         ClickItem item  = cell2.GetComponentInChildren <ClickItem>();
         if (item != null)
         {
             if (item.type == ClickItem.Type.consumable)
             {
                 DadItem.eat(cell, item);
             }
             if (item.type == ClickItem.Type.weapon)
             {
                 if (item.value == 1)
                 {
                     DadItem.attack(cell, item);
                 }
                 if (item.value == 2)
                 {
                     DadItem.burn(cell, item);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
    private bool awaked = false;                                                // Gameobject was awaked and initialized

    void OnEnable()
    {
        DadItem.OnItemDragStartEvent += OnAnyItemDragStart;                     // Handle any item drag start
        DadItem.OnItemDragEndEvent   += OnAnyItemDragEnd;                       // Handle any item drag end

        myDadItem = GetDadItem();
        UpdateBackgroundState();
    }
Exemplo n.º 3
0
    /// <summary>
    /// Get item from this cell.
    /// </summary>
    /// <returns> Item </returns>
    public GameObject GetItem()
    {
        GameObject res     = null;
        DadItem    dadItem = GetDadItem();

        if (dadItem != null)
        {
            res = dadItem.gameObject;
        }
        return(res);
    }
Exemplo n.º 4
0
    /// <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;
                }
            }
        }
    }
Exemplo n.º 5
0
    private void printDadCells()
    {
        print("Dad Cells Content =============");
        for (int i = 0; i < dadCells.Length; i++)
        {
            DadItem dadItem = dadCells[i].GetComponentInChildren <DadItem>();

            string    myItem    = dadItem != null ? dadItem.name : "";
            StackItem stackItem = dadCells[i].GetComponentInChildren <StackItem>();

            print(i + ": " + dadCells[i] + " , " + myItem + " , " + stackItem);
        }
    }
Exemplo n.º 6
0
 /// <summary>
 /// Put item into this cell.
 /// </summary>
 /// <param name="item">Item.</param>
 /// <param name="destroyOldItem">If set to <c>true</c> destroy old item.</param>
 private void PlaceItem(GameObject item, bool destroyOldItem)
 {
     if (item != null)
     {
         if (destroyOldItem == true)
         {
             DestroyItem();                                                                  // Remove current item from this cell
             myDadItem = null;
         }
         DadItem dadItem = item.GetComponent <DadItem>();
         if (dadItem != null)
         {
             // Put new item into this cell
             item.transform.SetParent(transform, false);
             item.transform.localPosition = Vector3.zero;
             dadItem.MakeRaycast(true);
             myDadItem = dadItem;
         }
     }
     UpdateBackgroundState();
 }
Exemplo n.º 7
0
    public void ClearInv()
    {
        print("ClearInv() ==========");
        printDadCells();
        for (int i = 0; i < dadCells.Length; i++)
        {
            int       stack     = 0;
            StackCell stackCell = dadCells[i].GetComponentInParent <StackCell>();
            DadItem   dadItem   = dadCells[i].GetComponentInChildren <DadItem>();
            StackItem stackItem = dadCells[i].GetComponentInChildren <StackItem>();
            if (dadItem != null)
            {
                stack = stackItem.GetStack();
                print(i + " : removing in ClearInv() , " + stackItem + stack);

                stackGroup.RemoveItem(stackItem, stack);

                print(i + " : removed in ClearInv() , " + stackItem);
            }
        }
    }
Exemplo n.º 8
0
    /// <summary>
    /// Destroy item in this cell
    /// </summary>
    private void DestroyItem()
    {
        UpdateMyItem();
        GameObject item = GetItem();

        if (item != null)
        {
            DadEventDescriptor desc = new DadEventDescriptor();
            // Fill event descriptor
            desc.triggerType     = TriggerType.ItemWillBeDestroyed;
            desc.sourceCell      = this;
            desc.destinationCell = this;
            // Send notification about item destruction
            SendGroupNotification(desc.destinationCell.gameObject, desc);
            if (item != null)
            {
                Destroy(item);
            }
        }
        myDadItem = null;
        UpdateBackgroundState();
    }
Exemplo n.º 9
0
    public void GetInv()
    {
        print("GetInv() ==========");

        Inventory.Clear();

        for (int i = 0; i < dadCells.Length; i++)
        {
            GameObject item      = null;
            int        stack     = 0;
            DadItem    dadItem   = dadCells[i].GetComponentInChildren <DadItem>();
            StackItem  stackItem = dadCells[i].GetComponentInChildren <StackItem>();
            if (dadItem != null)
            {
                item  = dadItem.gameObject;
                stack = stackItem.GetStack();
                if (Inventory.Keys.Contains(item.name))
                {
                    Inventory.Add(item.name, stack++); // SEB : Adding item to player inventory
                }
                Inventory.Add(item.name, stack);       // SEB : Adding item to player inventory
            }
        }
    }
Exemplo n.º 10
0
 /// <summary>
 /// Updates my item
 /// </summary>
 public void UpdateMyItem()
 {
     myDadItem = GetComponentInChildren <DadItem>();
 }
Exemplo n.º 11
0
 /// <summary>
 /// Updates my item
 /// </summary>
 public void UpdateMyItem()
 {
     //print(7);
     myDadItem = GetComponentInChildren <DadItem>();
 }