Example #1
0
    public void RemoveEquipment(InventoryItems item, bool willEquip = false)
    {
        var equip = equipment[item.GetType().ToString()];

        if (equip == null)
        {
            return;
        }
        if (item.GetType() == typeof(Lightsource))
        {
            Lightsource temp = equip.item as Lightsource;
            CharacterStats.sightBonusFromItems -= temp.lightRadius;
        }
        else if (item.GetType() == typeof(Weapon))
        {
            References.rf.playerMovement.meleeWeapon = null;
            AnimationClip idleClip = animations.DefaultIdleClip("One_handedMelee");
            AnimationClip walkClip = animations.DefaultWalkClip("One_handedMelee");
            overrider["BaseIdle"]          = idleClip;
            overrider["BaseWalk"]          = walkClip;
            anim.runtimeAnimatorController = overrider;
            anim.SetLayerWeight(1, 1f);
        }
        else
        {
            Armor armor = item as Armor;
            if (item.GetType() == typeof(Chestgear))
            {
                foreach (var obj in chestgearEquipment)
                {
                    obj.Value.sprite = null;
                }
            }
            Info.AddDefenses(armor, true);
        }
        if (equip.obj != null)
        {
            Destroy(equip.obj);
        }
        ApplyGearEffects(equip.item, true);
        if (!willEquip)
        {
            CalculateStats();
            StartCoroutine("UpdateInventoryGear");
        }
        equip.item = null;
    }
Example #2
0
    public void DisplayDetails(InventoryItems item, bool _equipped = false)
    {
        itemName.text        = item.name;
        itemDescription.text = item.description;
        itemType.text        = item.GetType().ToString() + " - Weight " + item.weight;
        equipped.enabled     = _equipped;

        if (item is Weapon)  // WEAPONS HERE
        {
            Weapon _item = item as Weapon;
            itemType.text   = _item.hands.ToString().Replace("_", " ") + " " + _item.weaponType + " - Weight " + item.weight;
            details[0].text = $"Physical damage {TextColor.Yellow}{_item.physicalMin} {TextColor.White}-{TextColor.Yellow} {_item.physicalMax}";
            details[1].text = $"Spectral damage {TextColor.Purple}{_item.spectralMin} {TextColor.White}-{TextColor.Purple} {_item.spectralMax}";
            details[2].text = $"Fire damage {TextColor.Red}{_item.fireMin} {TextColor.White}-{TextColor.Red} {_item.fireMax}";
            details[3].text = $"Critical hit chance {TextColor.Return("yellow")}{_item.criticalHitChance}{TextColor.Return()}%";
            details[4].text = $"Attack speed {TextColor.Return("yellow")}{_item.attackRate}{TextColor.Return()} times per second";
        }
        else if (item is Lightsource)
        {
            Lightsource _item = item as Lightsource;
            details[0].text = $"Increases sight radius by {TextColor.Yellow}{_item.lightRadius}{TextColor.White} points.";
        }
        else if (item is Consumable) // CONSUMABLES HERE
        {
            Consumable _item = item as Consumable;
            for (int i = 0; i < _item.itemEffect.Length; i++)
            {
                details[i].text = ItemEffectText(_item.itemEffect[i]);
            }
        }
        else if (item is Ammo)
        {
        }
        else
        {
            Armor armor = item as Armor;
            details[0].text = $"Physical Defense {TextColor.Return("yellow")}{armor.defense}";
            details[1].text = $"Spectral Defense {TextColor.Return("purple")}{armor.spectralDefense}";
            details[2].text = $"Fire Defense {TextColor.Return("red")}{armor.fireDefense}";
        }

        CheckForGearEffects(item);
    }
Example #3
0
    private void CheckForGearEffects(InventoryItems item)
    {
        var _gearEffects = item.GetType().GetField("gearEffects");

        if (_gearEffects == null)
        {
            return;
        }
        var gearEffects = (GearEffect[])_gearEffects.GetValue(item);

        if (gearEffects == null || gearEffects.Length == 0)
        {
            return;
        }

        for (int i = 0; i < gearEffects.Length; i++)
        {
            details[i + 6].text = GearEffectText(gearEffects[i]);
        }
    }
Example #4
0
    public void AddEquipment(GameObject obj, InventoryItems item)
    {
        var equip = equipment[item.GetType().ToString()];

        if (equip.item != null && equip.item.Equals(item))
        {
            return;
        }
        if (equip.item != null)
        {
            RemoveEquipment(equip.item, true);
        }
        equip.item = item;

        if (item.GetType() != typeof(Chestgear))
        {
            var srs = obj.GetComponentsInChildren <SpriteRenderer>();
            foreach (var sr in srs)
            {
                sr.material = item.material == null ? defaultMat : item.material;
            }
            if (equip.obj != null)
            {
                Destroy(equip.obj);
            }
            equip.obj = Instantiate(obj);
            if (equip.item.modifiedMat != null)
            {
                equip.obj.GetComponent <SpriteRenderer>().material = equip.item.modifiedMat;
            }
            equip.obj.transform.SetParent(equip.trans, false);
        }

        if (equip.item.GetType() == typeof(Lightsource))
        {
            Lightsource temp = equip.item as Lightsource;
            Debug.Log(equip.obj.transform.rotation);
            Weapon wep = CharacterStats.characterEquipment.weapon;
            if (wep != null)
            {
                if (wep.hands == Hands.One_handed)
                {
                    equip.obj.transform.SetParent(oneHandedLightSource, false);
                }
                else
                {
                    equip.obj.transform.SetParent(twoHandedLightSource, false);
                }
            }
            else
            {
                equip.obj.transform.SetParent(oneHandedLightSource);
            }

            CharacterStats.sightBonusFromItems += temp.lightRadius;
        }

        else if (equip.item.GetType() == typeof(Weapon))
        {
            Weapon   temp   = equip.item as Weapon;
            string   defWep = temp.weaponType == WeaponType.Melee ? "Melee" : "Ranged";
            Equipped ls     = equipment["Lightsource"];
            if (ls.obj != null)
            {
                if (temp.hands == Hands.One_handed)
                {
                    ls.obj.transform.SetParent(oneHandedLightSource, false);
                }
                else
                {
                    ls.obj.transform.SetParent(twoHandedLightSource, false);
                }
            }

            AnimationClip attackClip = temp.attackAnimation == null?animations.DefaultAttackClip(temp.hands + defWep) : temp.attackAnimation;

            AnimationClip idleClip = animations.DefaultIdleClip(temp.hands + defWep);
            AnimationClip walkClip = animations.DefaultWalkClip(temp.hands + defWep);
            overrider["BaseAttack"]        = attackClip;
            overrider["BaseIdle"]          = idleClip;
            overrider["BaseWalk"]          = walkClip;
            anim.runtimeAnimatorController = overrider;
            anim.SetLayerWeight(1, 1f);
            ParticleSystem trail = equip.obj.GetComponentInChildren <ParticleSystem>();
            if (trail != null)
            {
                References.rf.playerMovement.weaponTrailRenderer = trail;
                if (temp.weaponType == WeaponType.Melee || temp.weaponType == WeaponType.Flamethrower)
                {
                    trail.Stop();
                }
            }
            if (temp.weaponType == WeaponType.Melee)
            {
                References.rf.playerMovement.meleeWeapon = equip.obj.GetComponent <MeleeWeaponHit>();
            }
        }

        else
        {
            Armor armor = equip.item as Armor;
            if (equip.item.GetType() == typeof(Chestgear))
            {
                foreach (Transform trans in obj.transform)
                {
                    chestgearEquipment[trans.name].sprite   = trans.GetComponent <SpriteRenderer>().sprite;
                    chestgearEquipment[trans.name].material = item.material == null ? defaultMat : item.material;
                }
            }
            Info.AddDefenses(armor);
        }

        ApplyGearEffects(equip.item, false);
        CalculateStats();
        StartCoroutine("UpdateInventoryGear");
    }
Example #5
0
    private void ApplyGearEffects(InventoryItems item, bool unequip)
    {
        GearEffect[] gearEffects = (GearEffect[])item.GetType().GetField("gearEffects").GetValue(item);
        if (gearEffects == null || gearEffects.Length == 0)
        {
            return;
        }
        foreach (var effect in gearEffects)
        {
            switch (effect.effect)
            {
            case _GearEffect.Increases_Strength:
                CharacterStats.strength += !unequip ? (int)effect.amount : (int)-effect.amount;
                break;

            case _GearEffect.Increases_Dexterity:
                CharacterStats.dexterity += !unequip ? (int)effect.amount : (int)-effect.amount;
                break;

            case _GearEffect.Increases_Perception:
                CharacterStats.perception += !unequip ? (int)effect.amount : (int)-effect.amount;
                break;

            case _GearEffect.Increases_Constitution:
                CharacterStats.constitution += !unequip ? (int)effect.amount : (int)-effect.amount;
                break;

            case _GearEffect.Increases_Luck:
                CharacterStats.luck += !unequip ? (int)effect.amount : (int)-effect.amount;
                break;

            case _GearEffect.Light_Radius:
                CharacterStats.sightBonusPercentage += !unequip ? effect.amount : -effect.amount;
                break;

            case _GearEffect.Increases_Health:
                CharacterStats.healthBonusFromItems += !unequip ? effect.amount : -effect.amount;
                break;

            case _GearEffect.Increases_Stamina:
                CharacterStats.staminaBonusFromItems += !unequip ? effect.amount : -effect.amount;
                break;

            case _GearEffect.Movement_Speed:
                CharacterStats.moveSpeed = !unequip ? CharacterStats.moveSpeed *= 1f + effect.amount / 100f : CharacterStats.moveSpeed /= 1f + effect.amount / 100f;
                break;

            case _GearEffect.Increases_Critical_Hit_Chance:
                CharacterStats.criticalBonusPercentage += !unequip ? effect.amount : -effect.amount;
                break;

            case _GearEffect.Increases_PhysicalDamagePoints:
                Info.extraPhys += !unequip ? effect.amount : -effect.amount;
                break;

            case _GearEffect.Increases_FireDamagePoints:
                Info.extraFire += !unequip ? effect.amount : -effect.amount;
                break;

            case _GearEffect.Increases_SpectralDamagePoints:
                Info.extraSpec += !unequip ? effect.amount : -effect.amount;
                break;

            case _GearEffect.Increases_PhysicalDamagePercent:
                Info.extraPhysPercent += !unequip ? effect.amount : -effect.amount;
                break;

            case _GearEffect.Increases_FireDamagePercent:
                Info.extraFirePercent += !unequip ? effect.amount : -effect.amount;
                break;

            case _GearEffect.Increases_SpectralDamagePercent:
                Info.extraSpecPercent += !unequip ? effect.amount : -effect.amount;
                break;
            }
        }
    }