public void Consume()
    {
        if (buffs)
        {
            // late bind recipient
            if (!buffs.GetRecipient())
            {
                buffs.SetRecipient(GetRecipient());
            }

            buffs.Apply();

            // check if item isPassive
            IsPassive passive = gameObject.GetComponent <IsPassive>();
            if (passive == null)
            {
                // if not passive - remove from scene after usage
                Destroy(this.gameObject);
            }
            else
            {
                // do not destroy if passive so temp buffs can be applied that expire over time
                passive.Activate();
                passive.SetRecipient(this.GetRecipient());

                // hide after item is collected
                Hide();
            }
        }
    }
Exemple #2
0
    public void Insert()
    {
        if (recipient)
        {
            CollectionData[] cdata = recipient.GetComponents <CollectionData>();
            for (int i = 0; i < cdata.Length; i++)
            {
                CollectionData coldat = cdata[i];

                // find the collection we should insert into, by name
                if (coldat.name == collectionName)
                {
                    coldat.Insert(this);

                    // really, only activate passive aspects if we
                    // successfully inserted into inventory
                    IsPassive pas = GetComponent <IsPassive>();
                    if (pas)
                    {
                        pas.Activate();
                        pas.SetRecipient(this.GetRecipient());
                    }

                    Hide();

                    break;
                }
            }
        }
    }
Exemple #3
0
    public void OnCollisionEnter2D(Collision2D other)
    {
        foreach (string s in TouchTypes)
        {
            if (other.gameObject.GetComponent(s))
            {
                // pass reference to this, to consumable if this is consumable
                // ie. consume item immediately after pickup
                IsConsumable cons = GetComponent <IsConsumable>();
                if (cons)
                {
                    cons.SetRecipient(other.gameObject);
                }

                // stote in Player's inventory
                IsInventoriable inv = GetComponent <IsInventoriable>();
                if (inv)
                {
                    inv.SetRecipient(other.gameObject);
                }

                // store in item collection ie. gold in coin purse
                IsCollectible col = GetComponent <IsCollectible>();
                if (col)
                {
                    col.SetRecipient(other.gameObject);
                }

                IsPassive pas = GetComponent <IsPassive>();
                if (pas)
                {
                    pas.SetRecipient(other.gameObject);
                }

                // sendmessage if we actually find a component who can listen for this
                SendMessage(OnTouchCB);
            }
        }
    }