SHARE
TWEET

EquippableItem

Rakshalpha Oct 14th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Assets.Scripts.Stats;
  5.  
  6. /* An Item that can be equipped. */
  7.  
  8. public enum EquipmentType { Helmet, Chest, Gloves, Boots, Weapon1, Weapon2, Accessory1, Accessory2, Belt }
  9. public enum EquipmentMeshRegion { Head, Torso, Arms, Legs, Feet }; // Coresponds to body blendshapes.
  10.  
  11. [CreateAssetMenu(fileName = "New Equipment", menuName = "Inventory/Equipment")]
  12. public class EquippableItem : Item
  13. {
  14.     public SkinnedMeshRenderer mesh;
  15.     public EquipmentMeshRegion[] coveredMeshRegions;
  16.  
  17.     public int Damage;
  18.     public int Defense;
  19.     [Space]
  20.     [Tooltip("Flat strength value")]
  21.     public int StrengthBonus;
  22.     public int AgilityBonus;
  23.     public int IntelligenceBonus;
  24.     public int VitalityBonus;
  25.     [Space]
  26.     public float StrengthPercentBonus;
  27.     public float AgilityPercentBonus;
  28.     public float IntelligencePercentBonus;
  29.     public float VitalityPercentBonus;
  30.     [Space]
  31.     public EquipmentType EquipmentType;
  32.  
  33.     public override Item GetCopy()
  34.     {
  35.         return Instantiate(this);
  36.     }
  37.  
  38.     public override void Destroy()
  39.     {
  40.         Destroy(this);
  41.     }
  42.  
  43.     public void Equip(Character c)
  44.     {
  45.  
  46.         if (Damage != 0)
  47.             c.Damage.AddModifier(new Modifier(Damage, StatModType.Flat, this));
  48.         if (Defense != 0)
  49.             c.Defense.AddModifier(new Modifier(Defense, StatModType.Flat, this));
  50.  
  51.         if (StrengthBonus != 0)
  52.             c.Strength.AddModifier(new Modifier(StrengthBonus, StatModType.Flat, this));
  53.         if (AgilityBonus != 0)
  54.             c.Agility.AddModifier(new Modifier(AgilityBonus, StatModType.Flat, this));
  55.         if (IntelligenceBonus != 0)
  56.             c.Intelligence.AddModifier(new Modifier(IntelligenceBonus, StatModType.Flat, this));
  57.         if (VitalityBonus != 0)
  58.             c.Vitality.AddModifier(new Modifier(VitalityBonus, StatModType.Flat, this));
  59.  
  60.         if (StrengthPercentBonus != 0)
  61.             c.Strength.AddModifier(new Modifier(StrengthPercentBonus, StatModType.PercentMult, this));
  62.         if (AgilityPercentBonus != 0)
  63.             c.Agility.AddModifier(new Modifier(AgilityPercentBonus, StatModType.PercentMult, this));
  64.         if (IntelligencePercentBonus != 0)
  65.             c.Intelligence.AddModifier(new Modifier(IntelligencePercentBonus, StatModType.PercentMult, this));
  66.         if (VitalityPercentBonus != 0)
  67.             c.Vitality.AddModifier(new Modifier(VitalityPercentBonus, StatModType.PercentMult, this));
  68.     }
  69.  
  70.     public void Unequip(Character c)
  71.     {
  72.         c.Strength.RemoveAllModifiersFromSource(this);
  73.         c.Agility.RemoveAllModifiersFromSource(this);
  74.         c.Intelligence.RemoveAllModifiersFromSource(this);
  75.         c.Vitality.RemoveAllModifiersFromSource(this);
  76.         c.Damage.RemoveAllModifiersFromSource(this);
  77.         c.Defense.RemoveAllModifiersFromSource(this);
  78.     }
  79.  
  80.     public override string GetItemType()
  81.     {
  82.         return EquipmentType.ToString();
  83.     }
  84.  
  85.     public override string GetItemDescription()
  86.     {
  87.         sb.Length = 0;
  88.  
  89.         AddStat(StrengthBonus, "Strength");
  90.         AddStat(AgilityBonus, "Agility");
  91.         AddStat(IntelligenceBonus, "Intelligence");
  92.         AddStat(VitalityBonus, "Vitality");
  93.  
  94.         AddStat(StrengthPercentBonus, "Strength", isPercent: true);
  95.         AddStat(AgilityPercentBonus, "Agility", isPercent: true);
  96.         AddStat(IntelligencePercentBonus, "Intelligence", isPercent: true);
  97.         AddStat(VitalityPercentBonus, "Vitality", isPercent: true);
  98.         return sb.ToString();
  99.     }
  100.  
  101.  
  102.     private void AddStat(float value, string statName, bool isPercent = false)
  103.     {
  104.         if (value != 0)
  105.         {
  106.             if (sb.Length > 0)
  107.                 sb.AppendLine();
  108.  
  109.             if (value > 0)
  110.                 sb.Append("+");
  111.  
  112.             if (isPercent)
  113.             {
  114.                 sb.Append(value * 100);
  115.                 sb.Append("% ");
  116.             }
  117.             else
  118.             {
  119.                 sb.Append(value);
  120.                 sb.Append(" ");
  121.             }
  122.             sb.Append(statName);
  123.         }
  124.     }
  125. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top