示例#1
0
 public void Equip(Armor newArmor, Weapon newWeapon)
 {
     if (newArmor != null)
     {
         currentArmor.currentArmor = newArmor;
         currentArmor.EquipArmor();
     }
 }
示例#2
0
    public void ApplyItemEffect(int itemIndex)
    {
        //Sets clickedItem to the item in player's inventory
        clickedItem = playerInventory.inventory[itemIndex];
        currentBuffs.AddBuff(clickedItem);
        switch (clickedItem.itemType)
        {
            #region Item is a consumable
        case Item.ItemType.Consumable:
            currentConsumable = (Consumable)playerInventory.inventory[itemIndex];

            #region Setting most used Consumables
            if (usedConsumables.Contains(currentConsumable))
            {
                consumableUses[usedConsumables.IndexOf(currentConsumable)]++;
            }
            else
            {
                usedConsumables.Add(currentConsumable);
                consumableUses.Add(1);
            }
            topThreeConsumables = new Consumable[3];
            int tempMax = 0, firstIndex = 0, secondIndex = 0;
            for (int i = 0; i < usedConsumables.Count; i++)     //Setting the total max value from the uses Counter. At the end, firstIndex should point the the most used consumable
            {
                if (consumableUses[i] > tempMax)
                {
                    firstIndex = i;
                    tempMax    = consumableUses[i];
                }
            }
            topThreeConsumables[0] = usedConsumables[firstIndex];
            tempMax = 0;
            for (int i = 0; i < usedConsumables.Count; i++)     //Sees which value is the highest, while still being lower than the highest value. secondIndex should point to the second highest value
            {
                if (consumableUses[i] > tempMax && usedConsumables[i] != usedConsumables[firstIndex])
                {
                    secondIndex = i;
                    tempMax     = consumableUses[i];
                }
            }
            topThreeConsumables[1] = usedConsumables[secondIndex];
            tempMax = 0;
            for (int i = 0; i < usedConsumables.Count; i++)
            {
                if (consumableUses[i] > tempMax && usedConsumables[i] != usedConsumables[secondIndex])
                {
                    firstIndex = 1;
                    tempMax    = consumableUses[1];
                }
            }
            topThreeConsumables[2] = usedConsumables[firstIndex];

            if (topThreeConsumables[1] == topThreeConsumables[0])
            {
                topThreeConsumables[1] = null;
            }
            if (topThreeConsumables[2] == topThreeConsumables[0])
            {
                topThreeConsumables[2] = null;
            }
            if (topThreeConsumables[2] == topThreeConsumables[1])
            {
                topThreeConsumables[2] = null;
            }
            if (topThreeConsumables[2] == topThreeConsumables[1] && topThreeConsumables[1] == topThreeConsumables[0])
            {
                topThreeConsumables[1] = null;
                topThreeConsumables[2] = null;
            }
            #endregion

            switch (currentConsumable.consumableType)
            {
            case Consumable.Type.HealthPotion:
                HealthSinglePlayer health = playerInventory.gameObject.GetComponent <HealthSinglePlayer>();
                if (currentConsumable.amountNumberType == Consumable.NumberType.Percentage)
                {
                    float tempPercentage;
                    if (currentConsumable.amountToAffectBy > 100)
                    {
                        tempPercentage = 100;
                    }
                    else
                    {
                        tempPercentage = currentConsumable.amountToAffectBy;
                    }
                    health.HealPercentage(tempPercentage);
                }
                else
                {
                    health.HealNumber(currentConsumable.amountToAffectBy);
                }
                break;

            case Consumable.Type.StealthPotion:
                if (currentConsumable.amountNumberType == Consumable.NumberType.Percentage)
                {
                    StartCoroutine(ApplyStealthPotion(currentConsumable.effectTime, currentConsumable.amountToAffectBy, true));
                }
                else
                {
                    StartCoroutine(ApplyStealthPotion(currentConsumable.effectTime, currentConsumable.amountToAffectBy, false));
                }
                break;

            case Consumable.Type.SpeedPotion:
                if (currentConsumable.amountNumberType == Consumable.NumberType.Percentage)
                {
                    StartCoroutine(ApplySpeedPotion(currentConsumable.effectTime, currentConsumable.amountToAffectBy, true));
                }
                else
                {
                    StartCoroutine(ApplySpeedPotion(currentConsumable.effectTime, currentConsumable.amountToAffectBy, false));
                }
                break;

            case Consumable.Type.StaminaPotion:
                if (currentConsumable.effectTime == -1)
                {
                    if (currentConsumable.amountNumberType == Consumable.NumberType.FlatNumber)
                    {
                        StartCoroutine(ApplyStaminaPotionImmediately(currentConsumable.amountToAffectBy, false));
                    }
                    else
                    {
                        StartCoroutine(ApplyStaminaPotionImmediately(currentConsumable.amountToAffectBy, true));
                    }
                }
                else
                {
                    if (currentConsumable.amountNumberType == Consumable.NumberType.FlatNumber)
                    {
                        StartCoroutine(ApplyStaminaPotionOverTime(currentConsumable.effectTime, currentConsumable.amountToAffectBy, false));
                    }
                    else
                    {
                        StartCoroutine(ApplyStaminaPotionOverTime(currentConsumable.effectTime, currentConsumable.amountToAffectBy, true));
                    }
                }
                break;

            case Consumable.Type.AccuracyPotion:
                break;

            case Consumable.Type.JumpPotion:
                if (currentConsumable.amountNumberType == Consumable.NumberType.FlatNumber)
                {
                    StartCoroutine(ApplyJumpPotion(currentConsumable.effectTime, currentConsumable.amountToAffectBy, false));
                }
                else
                {
                    StartCoroutine(ApplyJumpPotion(currentConsumable.effectTime, currentConsumable.amountToAffectBy, true));
                }
                break;

            case Consumable.Type.ReloadSpeed:
                if (currentConsumable.amountNumberType == Consumable.NumberType.FlatNumber)
                {
                    StartCoroutine(ApplyReloadSpeedPotion(currentConsumable.effectTime, currentConsumable.amountToAffectBy, false));
                }
                else
                {
                    StartCoroutine(ApplyReloadSpeedPotion(currentConsumable.effectTime, currentConsumable.amountToAffectBy, true));
                }
                break;
            }

            break;
            #endregion

            #region Item is armor
        case Item.ItemType.Armor:
            Armor currentArmor  = (Armor)clickedItem;
            Armor returnedArmor = playerArmor.EquipArmor(currentArmor);
            playerHealth.ChangeDamageReduction(currentArmor.damageReductionAmount);
            switch (currentArmor.additionalEffectType)
            {
            case Armor.AdditionalEffectType.IncreaseAccuracy:
                if (currentArmor.additionalEffectNumberType == Armor.AdditionalEffectNumberType.FlatNumber)
                {
                    float tempNum = currentArmor.additionalEffectAmount;
                    playerProperties.ChangeAccuracyModifierFlatNumber(tempNum);
                }
                else
                {
                    playerProperties.ChangeAccuracyModifierPercentage(currentArmor.additionalEffectAmount);
                }
                break;

            case Armor.AdditionalEffectType.IncreaseStealth:
                if (currentArmor.additionalEffectNumberType == Armor.AdditionalEffectNumberType.FlatNumber)
                {
                    playerProperties.ChangeDetectionModifierFlatNumber(currentArmor.additionalEffectAmount);
                }
                else
                {
                    playerProperties.ChangeDetectionModifierPercentage(currentArmor.additionalEffectAmount);
                }
                break;

            case Armor.AdditionalEffectType.MaxHealth:
                if (currentArmor.additionalEffectNumberType == Armor.AdditionalEffectNumberType.FlatNumber)
                {
                    playerHealth.IncreaseMaxHealthFlatNumber(currentArmor.additionalEffectAmount);
                }
                else
                {
                    playerHealth.IncreaseMaxHealthPercentage(currentArmor.additionalEffectAmount);
                }
                break;

            case Armor.AdditionalEffectType.MaxStamina:
                if (currentArmor.additionalEffectNumberType == Armor.AdditionalEffectNumberType.FlatNumber)
                {
                    playerStamina.IncreaseMaxStaminaFlatNumber(currentArmor.additionalEffectAmount);
                }
                else
                {
                    playerStamina.IncreaseMaxStaminaPercentage(currentArmor.additionalEffectAmount);
                }
                break;

            case Armor.AdditionalEffectType.MaxWeight:
                break;

            case Armor.AdditionalEffectType.NoAdditionalEffect:
                break;
            }
            if (returnedArmor != null)
            {
                playerHealth.ChangeDamageReduction(0 - returnedArmor.damageReductionAmount);
                switch (returnedArmor.additionalEffectType)
                {
                case Armor.AdditionalEffectType.IncreaseAccuracy:
                    if (returnedArmor.additionalEffectNumberType == Armor.AdditionalEffectNumberType.FlatNumber)
                    {
                        playerProperties.ChangeAccuracyModifierFlatNumber(0 - returnedArmor.additionalEffectAmount);
                    }
                    else
                    {
                        float tempAmountToIncrease, tempPercentage;

                        tempPercentage       = returnedArmor.additionalEffectAmount;
                        tempPercentage       = 100 - tempPercentage;
                        tempPercentage      /= 100;
                        tempAmountToIncrease = playerProperties.accuracyModifier / tempPercentage;
                        tempAmountToIncrease = tempAmountToIncrease - playerProperties.accuracyModifier;
                        playerProperties.ChangeAccuracyModifierFlatNumber(0 - tempAmountToIncrease);
                    }
                    break;

                case Armor.AdditionalEffectType.IncreaseStealth:
                    if (returnedArmor.additionalEffectNumberType == Armor.AdditionalEffectNumberType.FlatNumber)
                    {
                        playerProperties.ChangeDetectionModifierFlatNumber(0 - returnedArmor.additionalEffectAmount);
                    }
                    else
                    {
                        float tempAmountToIncrease, tempPercentage;

                        tempPercentage       = returnedArmor.additionalEffectAmount;
                        tempPercentage       = 100 - tempPercentage;
                        tempPercentage      /= 100;
                        tempAmountToIncrease = playerProperties.detectionModifier / tempPercentage;
                        tempAmountToIncrease = tempAmountToIncrease - playerProperties.detectionModifier;
                        playerProperties.ChangeDetectionModifierFlatNumber(0 - tempAmountToIncrease);
                    }
                    break;

                case Armor.AdditionalEffectType.MaxHealth:
                    if (returnedArmor.additionalEffectNumberType == Armor.AdditionalEffectNumberType.FlatNumber)
                    {
                        playerHealth.IncreaseMaxHealthFlatNumber(0 - returnedArmor.additionalEffectAmount);
                    }
                    else
                    {
                        float tempAmountToIncrease, tempPercentage;
                        tempPercentage       = returnedArmor.additionalEffectAmount;
                        tempPercentage      /= 100;
                        tempAmountToIncrease = playerHealth.maxHealth / (tempPercentage + 1);
                        tempAmountToIncrease = playerHealth.maxHealth - tempAmountToIncrease;
                        playerHealth.IncreaseMaxHealthFlatNumber(0 - tempAmountToIncrease);
                    }
                    break;

                case Armor.AdditionalEffectType.MaxStamina:
                    if (returnedArmor.additionalEffectNumberType == Armor.AdditionalEffectNumberType.FlatNumber)
                    {
                        playerStamina.IncreaseMaxStaminaFlatNumber(0 - returnedArmor.additionalEffectAmount);
                    }
                    else
                    {
                        float tempAmountToIncrease, tempPercentage;
                        tempPercentage       = returnedArmor.additionalEffectAmount;
                        tempPercentage      /= 100;
                        tempAmountToIncrease = playerStamina.maxStamina / (tempPercentage + 1);
                        tempAmountToIncrease = playerStamina.maxStamina - tempAmountToIncrease;
                        playerStamina.IncreaseMaxStaminaFlatNumber(0 - tempAmountToIncrease);
                    }
                    break;

                case Armor.AdditionalEffectType.MaxWeight:

                    break;
                }
            }
            break;
            #endregion

            #region Item is Attachment
        case Item.ItemType.Attachment:
            tempAttachment = (Attachment)clickedItem;
            attachmentUI.SetAttachment(tempAttachment);
            StartCoroutine("SelectWeaponToAttach", itemIndex);

            break;
            #endregion

        case Item.ItemType.Ammo:
            Ammo ammo = (Ammo)clickedItem;
            playerAmmo.AddAmmo(playerInventory.itemNumberInStack[itemIndex], ammo.ammoType);
            break;

        default:
            break;
        }
        if (clickedItem.itemType != Item.ItemType.Attachment)
        {
            playerInventory.itemNumberInStack[itemIndex]--;
        }
        if (playerInventory.itemNumberInStack[itemIndex] <= 0)
        {
            playerInventory.inventory.RemoveAt(itemIndex);
            playerInventory.itemNumberInStack.RemoveAt(itemIndex);
        }
    }
示例#3
0
 public void QuickEquip()
 {
     playerWeapon.currentWeapon = inventory.storedWeapons[inventory.storedWeapons.Count - 1];
     playerArmor.currentArmor   = inventory.storedArmor[inventory.storedArmor.Count - 1];
     playerArmor.EquipArmor();
 }