Ejemplo n.º 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);
    }
Ejemplo n.º 2
0
    public override IEnumerator ItemUseAction(Inventory userInventory, int itemIndex)
    {
        Aimer getAimer = userInventory.GetComponent <Aimer>();
        Mover getMover = userInventory.GetComponent <Mover>();

        //GridSelector getGridSelector = userInventory.GetComponent<GridSelector>();

        if (getMover.IsMovementFrozen)
        {
            yield break;
        }

        Vector2 attackLocation = (Vector2)userInventory.transform.position + (getAimer.GetAimDirection() * attackDistance);

        //Vector2 attackLocation = getGridSelector.GetGridWorldSelectionPosition();

        getAimer.LookAt(attackLocation);

        BodyAnimation[] getEntityAnimator = userInventory.GetComponentsInChildren <BodyAnimation>();

        float animationTime = 0;

        for (int i = 0; i < getEntityAnimator.Length; i++)
        {
            switch (attackType)
            {
            case AttackType.Smash:
                animationTime = getEntityAnimator[i].ApplySmashAnimation(speed, userInventory.GetItem(itemIndex).Data.Icon);
                break;

            case AttackType.Slash:
                animationTime = getEntityAnimator[i].ApplySlashAnimation(speed, userInventory.GetItem(itemIndex).Data.Icon);
                break;

            default:
                break;
            }
        }

        getMover.FreezeMovement(true);

        yield return(new WaitForSeconds(animationTime * 0.5f));

        GameObject damageVolume = damageVolumePool.Retrieve(attackLocation, new Quaternion());

        damageVolume.GetComponent <DamageVolume>().Configure(new DamageVolumeConfiguration()
        {
            Damage               = damage,
            Owner                = userInventory.gameObject,
            ActiveTime           = 0.5f,
            TargetTags           = targetTags,
            AllowDuplicateDamage = true,
            CanDamageMultiple    = hitMultipleTargets,
            Size = new Vector2(0.10f, 0.10f)
        });

        yield return(new WaitForSeconds(animationTime * 0.5f));

        getMover.FreezeMovement(false);

        yield return(null);
    }