Beispiel #1
0
    public InventoryItemObject Unequip(Item.EquipmentSlot eSlot, ref Attributes playerAttributes)
    {
        InventoryItemObject oldItem = null;// new InventoryItemObject();

        // retrieve the slot that takes that type of item
        int slot = Convert.ToInt32(eSlot);

        if (_equipmentSlots[slot].GetItem() != null)
        {
            oldItem = _equipmentSlots[slot]?.GetInventoryItemObject();
        }

        // retrieve the old stats and remove them from the attributes
        if (_equipmentSlots[slot].GetItem()?.GetItemType() == Item.ItemType.Weapon)
        {
            foreach (Weapon.Stat stat in (_equipmentSlots[slot].GetItem() as Weapon).GetStats())
            {
                if (stat._isBasicStat)
                {
                    string enumString             = stat._stat.ToString();
                    Attributes.StatTypes statType = (Attributes.StatTypes)Enum.Parse(typeof(Attributes.StatTypes), enumString);
                    playerAttributes.DecrementStat(new Attributes.Stat(statType, (int)stat._value));
                }
                else
                {
                    Weapon.Stat weapStat = playerAttributes.GetWeaponStats().Find(x => x._stat == stat._stat);
                    weapStat -= stat;
                    playerAttributes.SetWeaponStat(weapStat);
                }
            }

            _equipmentSlots[slot].SetItemNull();
        }
        else if (_equipmentSlots[slot].GetItem()?.GetItemType() == Item.ItemType.Armor)
        {
            foreach (Armor.Stat stat in (_equipmentSlots[slot].GetItem() as Armor).GetStats())
            {
                if (stat._isBasicStat)
                {
                    string enumString             = stat._stat.ToString();
                    Attributes.StatTypes statType = (Attributes.StatTypes)Enum.Parse(typeof(Attributes.StatTypes), enumString);
                    playerAttributes.DecrementStat(new Attributes.Stat(statType, (int)stat._value));
                }
                else
                {
                    Armor.Stat armorStat = playerAttributes.GetArmorStats().Find(x => x._stat == stat._stat);
                    armorStat -= stat;
                    playerAttributes.SetArmorStat(armorStat);
                }
            }

            _equipmentSlots[slot].SetItemNull();
        }


        return(oldItem);
    }
Beispiel #2
0
 public void SetWeaponStat(Weapon.Stat stat)
 {
     foreach (Weapon.Stat s in _weaponStats)
     {
         if (s._stat == stat._stat)
         {
             s._value = stat._value;
         }
     }
 }
Beispiel #3
0
    public Weapon.Stat GetWeaponStat(Weapon.Stat statType)
    {
        foreach (Weapon.Stat s in _weaponStats)
        {
            if (s._stat == statType._stat)
            {
                return(s);
            }
        }

        return(null);
    }
Beispiel #4
0
    public void IncrementWeaponStat(Weapon.Stat stat)
    {
        int index = _weaponStats.IndexOf(_weaponStats.Find(x => x._stat == stat._stat));

        _weaponStats[index]._value += stat._value;
    }
Beispiel #5
0
    private void OnTriggerEnter(Collider other)
    {
        // determine if it was a crit , Use enemy resistance as well as player stats or vice versa TODO
        bool crit = false;

        if (gameObject.layer == LayerMask.NameToLayer("PlayerProjectile"))
        {
            float bonusDamage = 0;

            if (other.tag == "Enemy")
            {
                switch (abilityType)
                {
                case Ability.AbilityType.Magic:
                    bonusDamage = (_owner.GetComponent <Player>().GetAttributes().GetStat(Attributes.StatTypes.Magic).value *Attributes.Bonus_Mod);
                    break;

                case Ability.AbilityType.Melee:
                    bonusDamage = (_owner.GetComponent <Player>().GetAttributes().GetStat(Attributes.StatTypes.Strength).value *Attributes.Bonus_Mod);
                    break;

                case Ability.AbilityType.Ranged:
                    bonusDamage = (_owner.GetComponent <Player>().GetAttributes().GetStat(Attributes.StatTypes.Dexterity).value *Attributes.Bonus_Mod);
                    break;
                }


                float critRate     = 0f;
                float weaponDamage = 0f;

                Weapon playerWeapon = _owner.GetComponent <Equipment>().GetItem(Item.EquipmentSlot.Weapon) as Weapon;
                if (playerWeapon != null)
                {
                    if (playerWeapon.GetMagicDamage() > 0)
                    {
                        weaponDamage = Random.Range(playerWeapon.GetMagicDamage() * 0.8f, playerWeapon.GetMagicDamage() * 1.2f);
                    }
                    else
                    {
                        weaponDamage = Random.Range(playerWeapon.GetMinDamage(), playerWeapon.GetMaxDamage());
                    }

                    Weapon.Stat stat = playerWeapon.GetStats().Find(x => x._stat == Weapon.Stats.CritRate);

                    if (stat == null)
                    {
                        critRate = 5;
                    }
                    else
                    {
                        critRate = stat._value;
                    }
                    crit = Random.Range(0, 100f) < critRate;
                }
                other.gameObject.GetComponent <Enemy>().Damage(damage + weaponDamage + bonusDamage, effect, crit, _owner);
            }
        }
        else if (gameObject.layer == LayerMask.NameToLayer("EnemyProjectile"))
        {
            if (other.tag == "Player")
            {
                other.gameObject.GetComponent <Player>().Damage(damage, effect, crit, _owner);
            }
        }

        // destroy on collide with anything
        DestroyOb();
    }
Beispiel #6
0
    public void Equip(InventoryItemObject item, ref Attributes playerAttributes)
    {
        Item.EquipmentSlot eSlot;
        Item newItem = item.GetItem();

        if (newItem is Weapon)
        {
            eSlot = Item.EquipmentSlot.Weapon;
        }
        else
        {
            eSlot = ((Armor)item.GetItem()).GetEquipmentSlot();
        }

        int slot = Convert.ToInt32(eSlot);

        InventoryItemObject oldItem = Unequip(eSlot, ref playerAttributes);

        // add the new stats
        if (item.GetItem()?.GetItemType() == Item.ItemType.Weapon)
        {
            foreach (Weapon.Stat stat in (item.GetItem() as Weapon).GetStats())
            {
                if (stat._isBasicStat)
                {
                    string enumString             = stat._stat.ToString();
                    Attributes.StatTypes statType = (Attributes.StatTypes)Enum.Parse(typeof(Attributes.StatTypes), enumString);
                    playerAttributes.IncrementStat(new Attributes.Stat(statType, (int)stat._value));
                }
                else
                {
                    Weapon.Stat weapStat = playerAttributes.GetWeaponStats().Find(x => x._stat == stat._stat);
                    if (stat._flatValue)
                    {
                        weapStat += stat;
                    }
                    else
                    {
                        weapStat *= (1 + (stat._value / 100f));
                    }

                    playerAttributes.SetWeaponStat(weapStat);
                }
            }
        }
        else if (item.GetItem()?.GetItemType() == Item.ItemType.Armor)
        {
            foreach (Armor.Stat stat in (item.GetItem() as Armor).GetStats())
            {
                if (stat._isBasicStat)
                {
                    string enumString             = stat._stat.ToString();
                    Attributes.StatTypes statType = (Attributes.StatTypes)Enum.Parse(typeof(Attributes.StatTypes), enumString);
                    playerAttributes.IncrementStat(new Attributes.Stat(statType, (int)stat._value));
                }
                else
                {
                    Armor.Stat armorStat = playerAttributes.GetArmorStats().Find(x => x._stat == stat._stat);
                    if (stat._flatValue)
                    {
                        armorStat += stat;
                    }
                    else
                    {
                        armorStat *= (1 + (stat._value / 100f));
                    }

                    playerAttributes.SetArmorStat(armorStat);
                }
            }
        }

        // equip it
        _equipmentSlots[slot].SetItem(item);
        item.SetEquipped(true);

        if (oldItem != null)
        {
            oldItem.SetEquipped(false);
            _player.GetInventory().AddExistingItem(oldItem); // put the old item back into the inventory
        }
    }