Beispiel #1
0
    bool PickupItem(PickupPoint pickupPoint)
    {
        if (IsHoldingItem())
        {
            return(false);
        }
        if (!pickupPoint.GetItem())
        {
            return(false);
        }

        currentItem = pickupPoint.GetItem();
        pickupPoint.RemoveItem();
        currentItem.transform.SetParent(itemHolder);
        currentItem.transform.SetPositionAndRotation(itemHolder.transform.position, Quaternion.identity);
        currentItem.transform.localScale = Vector3.one;

        SpriteRenderer spriteRenderer = currentItem.GetComponent <SpriteRenderer>();

        itemSortingOrderCache       = spriteRenderer.sortingOrder;
        spriteRenderer.sortingOrder = itemHolderSortingOrder;

        OnPimPickedUpItemEvent(this, currentItem.GetComponent <Item>());

        return(true);
    }
Beispiel #2
0
    IEnumerator SlideItemToPickupPoint(GameObject item, int pickupPointIndex, bool forceIgnoreDropEffect)
    {
        while (true)
        {
            if (item == null)
            {
                break;
            }
            if (pickupPointIndex >= pickupPoints.Length)
            {
                break;
            }

            PickupPoint pickupPoint = pickupPoints[pickupPointIndex];

            if (item.transform.position.x >= pickupPoint.transform.position.x)
            {
                // The current Item have reached the first pickupPoint!
                pickupPoint.AddItem(item, forceIgnoreDropEffect);

                item = null;
                AudioManager.instance.PlaySfx("Blip_Select17");
                EZCameraShake.CameraShaker.Instance.ShakeOnce(0.2f, 5.0f, 0.2f, 0.2f);
                break;
            }
            else
            {
                if (item.transform.position.x >= pickupPoint.transform.position.x - 1)
                {
                    if (pickupPoint.GetItem() != null)
                    {
                        int nextPickupPointIndex = pickupPointIndex + 1;
                        StartCoroutine(SlideItemToPickupPoint(pickupPoint.GetItem(), nextPickupPointIndex, pickupPoint.forceIgnoreDropEffectOnNextPickupPoint));

                        pickupPoint.RemoveItem();
                    }
                }

                Vector3 currentItemPos = item.transform.position;
                currentItemPos.x       += Time.deltaTime;
                item.transform.position = currentItemPos;
            }

            // Yield execution of this coroutine and return to the main loop until next frame
            yield return(null);
        }
    }
Beispiel #3
0
    void HighlightInteractableTiles(Pim pim, Item item)
    {
        List <GameObject>  gos          = GameObject.FindGameObjectsWithTag("PickupPoint").ToList <GameObject>();
        List <PickupPoint> pickupPoints = new List <PickupPoint>();

        foreach (var go in gos)
        {
            PickupPoint pickupPoint = go.GetComponent <PickupPoint>();
            if (pickupPoint)
            {
                pickupPoints.Add(pickupPoint);
            }
        }

        foreach (PickupPoint pickupPoint in pickupPoints)
        {
            //if (pickupPoint.CanDropHere()) {
            if (pickupPoint.IsOccupied())
            {
                GameObject recipesObj = GameObject.FindGameObjectWithTag("Recipes");
                Recipes    recipes    = recipesObj.GetComponent <Recipes>();

                GameObject itemObject = pickupPoint.GetItem();
                if (itemObject != null)
                {
                    Item anItem = itemObject.GetComponent <Item>();
                    if (anItem != null)
                    {
                        ItemType itemType       = anItem.itemType;
                        Item     currentItemObj = currentItem.GetComponent <Item>();
                        if (currentItem != null)
                        {
                            Recipes.Recipe foundRecipe = recipes.GetRecipe(itemType, currentItemObj.itemType);

                            if (foundRecipe.output != null)
                            {
                                GameObject go = Instantiate(mergableEffect, pickupPoint.gameObject.transform.position, Quaternion.identity);
                                highlightEffectCache.Add(go);
                                go.transform.SetParent(itemObject.transform);
                            }
                        }
                    }
                }
            }
            else
            {
                if (pickupPoint.CanDropHere())
                {
                    GameObject go = Instantiate(highlightEffect, pickupPoint.gameObject.transform.position, Quaternion.identity);
                    highlightEffectCache.Add(go);
                }
            }
            //}
        }
    }
Beispiel #4
0
    bool DropItem(PickupPoint pickupPoint)
    {
        if (!IsHoldingItem())
        {
            return(false);
        }
        if (pickupPoint == null)
        {
            return(false);
        }
        if (pickupPoint.GetItem())
        {
            return(false);
        }

        if (pickupPoint.AddItem(currentItem, false))
        {
            currentItem.GetComponent <SpriteRenderer>().sortingOrder = itemSortingOrderCache;
            OnPimDroppedItemEvent(this, currentItem.GetComponent <Item>());
            currentItem = null;
        }

        return(true);
    }
Beispiel #5
0
    public void Interact()
    {
        List <GameObject> pickupPoints = GameObject.FindGameObjectsWithTag("PickupPoint").ToList <GameObject>();

        pickupPoints = pickupPoints.OrderBy(x => GetDistanceToObject(x)).ToList();

        foreach (GameObject pickupPointObj in pickupPoints)
        {
            PickupPoint pickupPoint = pickupPointObj.GetComponent <PickupPoint>();
            if (pickupPoint != null)
            {
                Collider2D pickupPointCollider = pickupPointObj.GetComponent <Collider2D>();
                if (pickupPointCollider != null)
                {
                    bool standingOnPickupPoint = pickupPointCollider.OverlapPoint(transform.position);

                    if (standingOnPickupPoint)
                    {
                        if (pickupPoint.GetItem() != null)
                        {
                            if (pickupPoint.CanPickupHere())
                            {
                                bool pickedUpItem = PickupItem(pickupPoint);

                                if (pickedUpItem)
                                {
                                    AudioManager.instance.PlaySfx("Blip_Select5");
                                }
                                else if (!pickedUpItem)
                                {
                                    if (pickupPoint.MergeItem(currentItem))
                                    {
                                        ClearAllHighlightedTiles(this, currentItem.GetComponent <Item>());
                                        Destroy(currentItem);
                                        currentItem = null;
                                        PickupItem(pickupPoint);


                                        if (currentItem)
                                        {
                                            Item mergedItem = currentItem.GetComponent <Item>();
                                            if (mergedItem)
                                            {
                                                if (mergedItem.itemType.name == "Black Matter")
                                                {
                                                    GameObject go = Instantiate(blackMatterMergeEffect, transform.position, Quaternion.identity);
                                                    go.transform.SetParent(transform);
                                                    AudioManager.instance.PlaySfx("BlackMattert");
                                                }
                                                else
                                                {
                                                    GameObject go = Instantiate(successfulMergeEffect, transform.position, Quaternion.identity);
                                                    go.transform.SetParent(transform);
                                                    AudioManager.instance.PlaySfx("Blip_Select10");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (pickupPoint.CanDropHere())
                            {
                                if (DropItem(pickupPoint))
                                {
                                    AudioManager.instance.PlaySfx("Blip_Select7");
                                    EZCameraShake.CameraShaker.Instance.ShakeOnce(0.2f, 5.0f, 0.2f, 0.2f);
                                }
                            }
                        }
                    }
                }
            }
        }
    }