예제 #1
0
    //COLLISION
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (_OnPlayer && _OnBuilding)
        {
            Debug.LogWarning("Cant have a collider set to building and player!...");
        }

        if (_OnPlayer)
        {
            if (this.transform.parent)
            {
                Transform t = this.transform.parent;

                //This all gets double checked in PM, but not refactoring till this is final.

                if (collision.gameObject == _MoveDummy && !_DigCollider)
                {
                    t.GetComponent <PlayerMovement>().OnTriggerEnter2D(collision);
                }

                else if (collision.transform.GetComponent <Searchable>() && !_DigCollider)
                {
                    t.GetComponent <PlayerMovement>().OnTriggerEnter2D(collision);
                }
                else if (collision.transform.GetComponent <DiggableTile>() && _DigCollider)
                {
                    t.GetComponent <PlayerMovement>().OnTriggerEnter2D(collision);
                }
                else if (collision.transform.parent && !_DigCollider)
                {
                    // handle if collider is agro range or base range
                    if (collision.transform.GetComponent <BaseHitBox>())
                    {
                        if (collision.transform.parent.GetComponent <BuildableObject>())
                        {
                            //Add to our list of interactable things in range
                            t.GetComponent <PlayerMovement>().OnTriggerEnter2D(collision);
                        }

                        else if (collision.transform.parent.GetComponent <Rodent>())
                        {
                            //Add to our list of interactable things in range
                            t.GetComponent <PlayerMovement>().OnTriggerEnter2D(collision);
                        }
                    }
                }
            }
        }
        else if (_OnBuilding)
        {
            if (this.transform.parent)
            {
                Transform t = this.transform.parent;
                if (t)
                {
                    bBanner banner = t.GetComponent <bBanner>();
                    if (banner)
                    {
                        // handle if collider is agro range or base range
                        if (collision.transform.GetComponent <AttackRadius>())
                        {
                            Transform colliderParent = collision.gameObject.transform.parent;
                            if (colliderParent)
                            {
                                // Debug.Log(banner.gameObject.name
                                //    + " Collided with :" + colliderParent.gameObject);

                                Rodent r = colliderParent.GetComponent <Rodent>();
                                if (r)
                                {
                                    //Set Max HP
                                    //Debug.Log("HP was:" + r.getHpMax());
                                    r.setHpMax(r.getHpMax() * banner.getHPBonus());
                                    // Debug.Log("HP now:" + r.getHpMax());

                                    // Set HP
                                    r.setHp(r.getHp() * banner.getHPBonus());

                                    //set Gathering Bonuses
                                    // print(r.name + " gather was: " + r.getGatherRate());
                                    r.setGatherRate((int)(r.getGatherRate() * banner.getGatherBonus()));
                                    //  print(r.name + " gather is now: " + r.getGatherRate());
                                }
                            }
                        }
                    }
                }
            }
        }
    }
예제 #2
0
    private void OnTriggerExit2D(Collider2D collision)
    {
        if (_OnPlayer)
        {
            if (this.transform.parent)
            {
                Transform t = this.transform.parent;


                if (collision.transform.GetComponent <Searchable>() && !_DigCollider)
                {
                    t.GetComponent <PlayerMovement>().OnTriggerExit2D(collision);
                }
                else if (collision.transform.GetComponent <DiggableTile>() && _DigCollider)
                {
                    t.GetComponent <PlayerMovement>().OnTriggerExit2D(collision);
                }
                else if (collision.transform.parent && !_DigCollider)
                {
                    // handle if collider is agro range or base range
                    if (collision.transform.GetComponent <BaseHitBox>())
                    {
                        if (collision.transform.parent.GetComponent <BuildableObject>())
                        {
                            //Add to our list of interactable things in range
                            t.GetComponent <PlayerMovement>().OnTriggerExit2D(collision);
                        }

                        else if (collision.transform.parent.GetComponent <Rodent>())
                        {
                            //Add to our list of interactable things in range
                            t.GetComponent <PlayerMovement>().OnTriggerExit2D(collision);
                        }
                    }
                }
            }
        }
        else if (_OnBuilding)
        {
            if (this.transform.parent)
            {
                Transform t = this.transform.parent;
                if (t)
                {
                    bBanner banner = t.GetComponent <bBanner>();
                    if (banner)
                    {
                        // handle if collider is agro range or base range
                        if (collision.transform.GetComponent <AttackRadius>())
                        {
                            Transform colliderParent = collision.gameObject.transform.parent;
                            if (colliderParent)
                            {
                                // Debug.Log(banner.gameObject.name
                                //    + " Collided with :" + colliderParent.gameObject);

                                Rodent r = colliderParent.GetComponent <Rodent>();
                                if (r)
                                {
                                    //Set Max HP
                                    // Debug.Log("HP was:" + r.getHpMax());
                                    r.setHpMax(r.getHpMax() / banner.getHPBonus());
                                    // Debug.Log("HP now:" + r.getHpMax());

                                    // Set HP
                                    r.setHp(r.getHp() / banner.getHPBonus());

                                    //Undo Gather bonus
                                    r.setGatherRate((int)(r.getGatherRate() / banner.getGatherBonus()));
                                }
                            }
                        }
                    }
                }
            }
        }
    }