Example #1
0
    public void GiveAllItemsToPlayerOrDrop(Vector3 position, Vector2 rangeX, Vector2 rangeY)
    {
        if (items == null)
        {
            return;
        }

        foreach (var item in items)
        {
            if (item != null && item.item != null && item.item.itemSO != null)
            {
                ItemData leftItem = GameManager.Instance.player.inventory.AddItem(item.item);

                if (leftItem.count != 0)
                {
                    //TODO: Inventory full popup text
                    Vector3 pos = GameManager.Instance.player.transform.position;
                    ItemOnGround.CreateOnGround(
                        leftItem,
                        position + new Vector3(rangeX.GetRandomValueFloat(), rangeY.GetRandomValueFloat())
                        );
                    leftItem.itemSO = null;
                }

                item.item.itemSO = null;
                item.item.count  = 0;
            }
        }
    }
Example #2
0
File: Cell.cs Project: Team-on/LD48
    public void Mine(float deltaTime, float mineToolForce, bool isNeedLoot = true)
    {
        if (foregroundBlock)
        {
            currMineTime += deltaTime * (mineToolForce - foregroundBlock.neededForceToBroke + 1);
            float brokePersent = currMineTime / foregroundBlock.neededTimeToBroke;

            if (brokePersent >= 1)
            {
                currMineTime = 0;
                destoyVisual.UpdateVisual(0);

                if (isNeedLoot)
                {
                    ItemOnGround.CreateOnGround(
                        foregroundBlock.itemToDrop.item.CloneItem().SetCount(1),
                        transform.position + new Vector3(Random.Range(-MyGrid.cellSize.x / 2 * 0.8f, MyGrid.cellSize.x / 2 * 0.8f), Random.Range(-MyGrid.cellSize.y / 2 * 0.8f, MyGrid.cellSize.y / 2 * 0.8f))
                        );
                }

                if (foregroundBlock.craftPlace)
                {
                    foregroundBlock.craftPlace.OnMined();
                }
                foregroud = CellContentForegroud.None;
                RecreateVisualAfterChangeType();
            }
            else
            {
                destoyVisual.UpdateVisual(brokePersent);
            }
        }
        else if (oreBlock && isNeedLoot)
        {
            currMineTime += deltaTime * (mineToolForce - oreBlock.neededForceToBroke + 1);
            float brokePersent = currMineTime / oreBlock.neededTimeToBroke;

            if (brokePersent >= 1)
            {
                currMineTime -= oreBlock.neededTimeToBroke;
                destoyVisual.UpdateVisual(0);

                ItemOnGround.CreateOnGround(
                    oreBlock.itemToDrop.item.CloneItem().SetCount(1),
                    transform.position + new Vector3(Random.Range(-MyGrid.cellSize.x / 2 * 0.8f, MyGrid.cellSize.x / 2 * 0.8f), Random.Range(-MyGrid.cellSize.y / 2 * 0.8f, MyGrid.cellSize.y / 2 * 0.8f))
                    );
            }
            else
            {
                destoyVisual.UpdateVisual(brokePersent);
            }
        }

        FillDebugText();
    }
Example #3
0
    public void SelectOtherCraft()
    {
        previousCraft = selectedCraft;
        selectedCraft = null;

        if (isCrafting)
        {
            foreach (var ingradient in previousCraft.ingradients)
            {
                ItemData leftItem = GameManager.Instance.player.inventory.AddItem(ingradient.CloneItem());

                if (leftItem.count != 0)
                {
                    //TODO: Inventory full popup text
                    Vector3 pos = GameManager.Instance.player.transform.position;
                    ItemOnGround.CreateOnGround(leftItem, pos);
                    leftItem.itemSO = null;
                }
            }

            craftingPlace.AbortCraft();
        }

        inventoryToAddItem.GiveAllItemsToPlayerOrDrop(
            myBlock.MyCell.transform.position,
            new Vector2(-myBlock.MyCell.MyGrid.cellSize.x / 2, myBlock.MyCell.MyGrid.cellSize.x / 2) * 0.8f,
            new Vector2(-myBlock.MyCell.MyGrid.cellSize.y / 2, myBlock.MyCell.MyGrid.cellSize.y / 2) * 0.8f
            );
        inventoryToRemoveItem.GiveAllItemsToPlayerOrDrop(
            myBlock.MyCell.transform.position,
            new Vector2(-myBlock.MyCell.MyGrid.cellSize.x / 2, myBlock.MyCell.MyGrid.cellSize.x / 2) * 0.8f,
            new Vector2(-myBlock.MyCell.MyGrid.cellSize.y / 2, myBlock.MyCell.MyGrid.cellSize.y / 2) * 0.8f
            );


        cgCraftingPlace.interactable = cgCraftingPlace.blocksRaycasts = false;
        LeanTween.cancel(cgCraftingPlace.gameObject, false);
        LeanTweenEx.ChangeAlpha(cgCraftingPlace, 0.0f, 0.2f).setEase(LeanTweenType.easeInOutQuad);

        cgSelectCraft.interactable = cgSelectCraft.blocksRaycasts = true;
        LeanTween.cancel(cgSelectCraft.gameObject, false);
        LeanTweenEx.ChangeAlpha(cgSelectCraft, 1.0f, 0.2f).setEase(LeanTweenType.easeInOutQuad);
    }
Example #4
0
    public void DropAllItemsToGround(Vector3 position, Vector2 rangeX, Vector2 rangeY)
    {
        if (items == null)
        {
            return;
        }

        foreach (var item in items)
        {
            if (item != null && item.item != null && item.item.itemSO != null)
            {
                ItemOnGround.CreateOnGround(
                    item.item,
                    position + new Vector3(rangeX.GetRandomValueFloat(), rangeY.GetRandomValueFloat())
                    );

                item.item.itemSO = null;
                item.item.count  = 0;
            }
        }
    }
Example #5
0
    public void OnEndDrag(PointerEventData eventData)
    {
        if (draggingSlot == null)
        {
            return;
        }

        if (eventData.hovered.Count == 0)
        {
            Cell cell = GameManager.Instance.GetCellAtMousePosWithInteractClamp(out Vector2 dropPos);

            if (cell && cell.foregroud == Cell.CellContentForegroud.None)
            {
                ItemOnGround.CreateOnGround(item, dropPos);
                item.itemSO = null;
            }
        }

        draggingSlot = null;
        DrawItem();
        inventory?.onInventoryChangeEvent();
    }
Example #6
0
    void OnClickOnItemInQueue(CraftingQueueItemUI craftItemUI)
    {
        foreach (var ingradient in craftItemUI.craft.ingradients)
        {
            ItemData leftItem = GameManager.Instance.player.inventory.AddItem(ingradient.CloneItem());

            if (leftItem.count != 0)
            {
                //TODO: Inventory full popup text
                Vector3 pos = GameManager.Instance.player.transform.position;
                ItemOnGround.CreateOnGround(leftItem, pos);
                leftItem.itemSO = null;
            }
        }

        if (craftItemUI == currCraft)
        {
            craftingPlace.AbortCraft();
        }
        else
        {
            Destroy(craftItemUI.gameObject);
        }
    }