Beispiel #1
0
    public void DropItem(int slotIndex)
    {
        if (!GetItem(slotIndex).Data.IsRemoveable)
        {
            return;
        }

        isDirty = true;

        LootableItem lootable = droppableItemPrefab.Retrieve <LootableItem>();

        if (lootable != null)
        {
            Aimer   getAimer     = this.GetComponent <Aimer>();
            Vector2 aimDirection = Vector2.zero;

            if (getAimer != null)
            {
                aimDirection = getAimer.GetAimDirection();
            }

            lootable.transform.position = (Vector2)this.transform.position + (aimDirection * (lootable.PickupDistance() * 1.05f));
            lootable.Configure(GetItem(slotIndex).Data, GetItem(slotIndex).Amount);
            lootable.gameObject.SetActive(true);

            foreach (var dispatcher in eventDispatchers.Values)
            {
                dispatcher.DispatchDropItem(slotIndex, lootable);
            }
        }

        RemoveItem(slotIndex);
    }
Beispiel #2
0
        public void DispatchDropItem(int index, LootableItem lootable)
        {
            int count = dropInterfaces.Count;

            for (int i = 0; i < count; i++)
            {
                dropInterfaces[i].OnDropItem(index, lootable);
            }
        }
Beispiel #3
0
 private void MakeLoot()
 {
     if (thisLoot != null)
     {
         LootableItem current = thisLoot.LootPowerUp();
         if (current != null)
         {
             Instantiate(current.gameObject, transform.position, Quaternion.identity);
         }
     }
 }
Beispiel #4
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        Debug.Log(collision.gameObject.name);
        if (collision.gameObject.tag.Equals("Lootable"))
        {
            LootableItem lootable = collision.gameObject.GetComponent <LootableItem>();

            if (playerState != null)
            {
                if (lootable.ItemType == LootType.RobotPart)
                {
                    if (playerState.ReceivePart(lootable as RobotPartItem))
                    {
                        Destroy(collision.gameObject);
                        UpdateAnimation();
                    }
                }
                else if (lootable.ItemType == LootType.ShipPart)
                {
                    if (playerState.CarryItem(lootable as ShipPartItem))
                    {
                        Destroy(collision.gameObject);
                    }
                }
                else if (lootable.ItemType == LootType.EnergyItem)
                {
                    playerState.GiveEnergy((lootable as EnergyItem));
                    Destroy(collision.gameObject);
                }
                else if (lootable.ItemType == LootType.HpItem)
                {
                    playerState.GiveHP((lootable as HPItem));
                    Destroy(collision.gameObject);
                }
            }

            Debug.Log(lootable.ItemType);
        }

        if (collision.gameObject.tag.Equals("Ship"))
        {
            if (playerState != null)
            {
                if (playerState.carriedItem.Value != null)
                {
                    if (ServiceLocator.Instance.GetInstanceOfType <ShipState>().ReceiveItem(playerState.carriedItem.Value))
                    {
                        playerState.carriedItem.Value = null;
                    }
                }
            }
        }
    }
Beispiel #5
0
    public void Drop(Vector2 location)
    {
        for (int i = 0; i < itemsToDrop.Length; i++)
        {
            int dropCount = Random.Range(itemsToDrop[i].dropCount.x, itemsToDrop[i].dropCount.y);

            for (int i2 = 0; i2 < dropCount; i2++)
            {
                LootableItem lootableItem = lootableItemPool?.Retrieve <LootableItem>();

                if (lootableItem != null)
                {
                    int itemCount = Random.Range(itemsToDrop[i].itemAmount.x, itemsToDrop[i].itemAmount.y);

                    lootableItem.Configure(itemsToDrop[i].itemData, itemCount);
                    lootableItem.transform.position = location + ((Vector2)Random.insideUnitSphere * dropRadius);
                    lootableItem.gameObject.SetActive(true);
                }
            }
        }
    }