Ejemplo n.º 1
0
    public void TransferToContainer(IContainer container)
    {
        if (inventoryItemPrefab != null)
        {
            container.AddItem((GameObject.Instantiate(inventoryItemPrefab, Vector3.zero, Quaternion.identity) as GameObject).GetComponent <IItem>());
        }

        GameObject.Destroy(this.gameObject);
    }
Ejemplo n.º 2
0
    public void TransferToContainer(IContainer container)
    {
        if (container == null)
        {
            return;
        }

        if (itemPrefab != null)
        {
            container.AddItem((GameObject.Instantiate(itemPrefab, Vector3.zero, Quaternion.identity) as GameObject).GetComponent <IItem>());
        }

        ScriptableObject.Destroy(this);
    }
Ejemplo n.º 3
0
    public void TransferToContainer(IContainer container)
    {
        if (ItemPrefab != null)
        {
            IItem item = GameObject.Instantiate(ItemPrefab as Behaviour, Vector3.zero, Quaternion.identity) as IItem;
            if (item is ItemAmmo)
            {
                (item as ItemAmmo).ammoLeft = ammoLeft;
            }

            container.AddItem(item);
        }

        ScriptableObject.Destroy(this);
    }
Ejemplo n.º 4
0
 public void Use(InteractManager user, UsableArgs args)
 {
     if (pickedItemPrefab != null)
     {
         IContainer container = user.gameObject.GetComponentInChildren <IContainer>();
         GameObject itemgo    = GameObject.Instantiate(pickedItemPrefab, Vector3.zero, Quaternion.identity) as GameObject;
         IItem      item      = itemgo.GetComponent <IItem>();
         if (item != null)
         {
             item.OnPickup(this);
             if (container != null && container.AddItem(item))
             {
                 GameObject.Destroy(this.gameObject);
             }
         }
     }
 }
Ejemplo n.º 5
0
    private static bool TransferItem(IContainer source, IContainer destination, IItem item)
    {
        if (item == null)
        {
            return(false);
        }

        if (!source.RemoveItem(item))
        {
            Debug.LogWarning("Item not found in source !");
            return(false);
        }

        if (!destination.AddItem(item))
        {
            Debug.Log("Destination is full !");
            source.AddItem(item);
            return(false);
        }

        return(true);
    }
Ejemplo n.º 6
0
        public static IContainer CreateContainer(IContainer oldContainer, IContainer newContainer, SpriteBatch batch)
        {
            Slot <UIObject>[] backup = new Slot <UIObject> [oldContainer.Slots.Count];
            oldContainer.Slots.CopyTo(backup);
            oldContainer.Slots.Clear();

            newContainer.Position = new Point(568, 100);
            newContainer.Initialize();
            newContainer.Setup();
            newContainer.AddSpriteRenderer(batch);
            newContainer.AddStringRenderer(batch);

            newContainer.Position = new Point(568, 100);

            for (int i = 0; i < backup.Length; i++)
            {
                backup[i].Item.ResetSize();
                newContainer.AddItem(backup[i].Position, backup[i].Item, backup[i].Item.Priority);
            }
            newContainer.UpdateLayout();
            return(newContainer);
        }
Ejemplo n.º 7
0
    public void GenerateLoot(IContainer container)
    {
        float rand = Random.Range(0.0f, 1.0f);

        if (rand > lootChance)
        {
            return;
        }

        uint addedItemCount = 0;

        foreach (var loot in lootTable)
        {
            if (addedItemCount >= maxItemNumber)
            {
                break;
            }

            rand = Random.Range(0.0f, 1.0f);
            if (rand <= loot.dropChance)
            {
                if (loot.itemGo == null)
                {
                    Debug.Log("Loot gameobject is null : " + loot.ToString());
                }

                GameObject itemgo = GameObject.Instantiate(loot.itemGo, Vector3.zero, Quaternion.identity) as GameObject;
                IItem      item   = itemgo.GetComponent <IItem>();

                if (!container.AddItem(item))
                {
                    GameObject.Destroy(itemgo);
                }

                addedItemCount++;
            }
        }
    }