Advertisement
Krythic

GameItem

Jun 5th, 2020
1,048
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.59 KB | None | 0 0
  1. using SharpDX.Direct2D1;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using VoidwalkerEngine.Framework.Collections;
  6. using VoidwalkerEngine.Framework.DataTypes;
  7. using VoidwalkerEngine.Framework.Logic;
  8. using VoidwalkerEngine.Framework.Systems.Enchanting;
  9. using VoidwalkerEngine.Framework.Systems.GameProperties;
  10.  
  11. namespace VoidwalkerEngine.Framework.Systems.Items.Base
  12. {
  13.  
  14.     public class GameItem
  15.     {
  16.         public string Identifier { get; set; }
  17.         public string Header { get; set; }
  18.         public string Name { get; set; }
  19.         public string Description { get; set; }
  20.         public ItemType Category { get; set; }
  21.         public int Icon { get; set; }
  22.         public string FlavorText { get; set; }
  23.         public QualityType Quality { get; set; }
  24.         public int Level { get; set; }
  25.         public int Capacity { get; set; }
  26.         public int Durability { get; set; }
  27.         public List<Enchantment> Enchantments { get; set; }
  28.         public GamePrice BaseSellPrice { get; set; }
  29.         public int BaseDamage { get; set; }
  30.         public int BaseBlockChance { get; set; }
  31.         public int BaseArmorRating { get; set; }
  32.         public int BaseDurability { get; set; }
  33.         public bool IsSpawnable { get; set; }
  34.         public bool IsEthereal { get; set; }
  35.         public bool IsNew { get; set; }
  36.         public bool IsConjured { get; set; }
  37.  
  38.         public int Quantity { get; set; } = 1;
  39.  
  40.         public bool IsStackable
  41.         {
  42.             get
  43.             {
  44.                 return Category.IsStackable();
  45.             }
  46.         }
  47.  
  48.         public bool IsEnchantable
  49.         {
  50.             get
  51.             {
  52.                 return Category.IsEnchantable();
  53.             }
  54.         }
  55.  
  56.         public bool IsStackableWith(GameItem other)
  57.         {
  58.             return this.Identifier.Equals(other.Identifier) && this.IsStackable;
  59.         }
  60.  
  61.         public GameItem()
  62.         {
  63.  
  64.         }
  65.  
  66.         public bool IsEnchanted
  67.         {
  68.             get
  69.             {
  70.                 return Enchantments != null && this.Enchantments.Count > 0;
  71.             }
  72.         }
  73.  
  74.         public bool IsIndestructible
  75.         {
  76.             get
  77.             {
  78.                 if (this.Enchantments != null)
  79.                 {
  80.                     foreach (Enchantment enchantment in this.Enchantments)
  81.                     {
  82.                         if (enchantment.Properties != null)
  83.                         {
  84.                             foreach (GameProperty property in enchantment.Properties)
  85.                             {
  86.                                 if (property is IndestructibleProperty)
  87.                                 {
  88.                                     return true;
  89.                                 }
  90.                             }
  91.                         }
  92.                     }
  93.                 }
  94.                 return false;
  95.             }
  96.         }
  97.  
  98.         public void Break()
  99.         {
  100.             this.Durability = 0;
  101.         }
  102.  
  103.         public void Repair()
  104.         {
  105.             this.Durability = GetMaximumDurability();
  106.         }
  107.  
  108.         public double GetAttackSpeed()
  109.         {
  110.             if (this.Category.IsWeapon())
  111.             {
  112.                 return this.Category.ToWeaponCategory().GetAttackSpeed();
  113.             }
  114.             return 0;
  115.         }
  116.  
  117.         public int GetMaximumDamage()
  118.         {
  119.             int multiplier = 100;
  120.             foreach (Enchantment enchantment in this.Enchantments)
  121.             {
  122.                 foreach (GameProperty effect in enchantment.Properties)
  123.                 {
  124.                     if (effect is ModifyGameItemProperty itemEffect)
  125.                     {
  126.                         if (itemEffect.Attribute == GameItemAttributeType.WeaponDamage)
  127.                         {
  128.                             multiplier += itemEffect.Value;
  129.                         }
  130.                     }
  131.                 }
  132.             }
  133.             if (this.IsEthereal)
  134.             {
  135.                 multiplier += 25;
  136.             }
  137.             return (int)Math.Floor(this.BaseDamage * (multiplier / 100D));
  138.         }
  139.  
  140.         public int GetMaximumArmorRating()
  141.         {
  142.             int multiplier = 100;
  143.             foreach (Enchantment enchantment in this.Enchantments)
  144.             {
  145.                 foreach (GameProperty effect in enchantment.Properties)
  146.                 {
  147.                     if (effect is ModifyGameItemProperty itemEffect)
  148.                     {
  149.                         if (itemEffect.Attribute == GameItemAttributeType.ArmorRating)
  150.                         {
  151.                             multiplier += itemEffect.Value;
  152.                         }
  153.                     }
  154.                 }
  155.             }
  156.             if (this.IsEthereal)
  157.             {
  158.                 multiplier += 25;
  159.             }
  160.             return (int)Math.Round(this.BaseArmorRating * (multiplier / 100D));
  161.         }
  162.  
  163.         public int GetMaximumDurability()
  164.         {
  165.             int multiplier = 100;
  166.             foreach (Enchantment enchantment in this.Enchantments)
  167.             {
  168.                 foreach (GameProperty effect in enchantment.Properties)
  169.                 {
  170.                     if (effect is ModifyGameItemProperty itemEffect)
  171.                     {
  172.                         if (itemEffect.Attribute == GameItemAttributeType.Durability)
  173.                         {
  174.                             multiplier += itemEffect.Value;
  175.                         }
  176.                     }
  177.                 }
  178.             }
  179.             if (this.IsEthereal)
  180.             {
  181.                 multiplier += 25;
  182.             }
  183.             return (int)Math.Round(this.BaseArmorRating * (multiplier / 100D));
  184.         }
  185.  
  186.         public int GetMaximumBlockChance()
  187.         {
  188.             int multiplier = 100;
  189.             foreach (Enchantment enchantment in this.Enchantments)
  190.             {
  191.                 foreach (GameProperty effect in enchantment.Properties)
  192.                 {
  193.                     if (effect is ModifyGameItemProperty itemEffect)
  194.                     {
  195.                         if (itemEffect.Attribute == GameItemAttributeType.BlockChance)
  196.                         {
  197.                             multiplier += itemEffect.Value;
  198.                         }
  199.                     }
  200.                 }
  201.             }
  202.             return (int)Math.Round(this.BaseBlockChance * (multiplier / 100D));
  203.         }
  204.  
  205.         public GamePrice GetMaximumSellPrice()
  206.         {
  207.             // Include price multipliers from enchantments
  208.             // Include Ethereal price multiplier,
  209.             // Include Quality Type Price Multiplier
  210.             return BaseSellPrice;
  211.         }
  212.  
  213.         /// <summary>
  214.         ///
  215.         /// </summary>
  216.         /// <param name="other"></param>
  217.         public void Copy(GameItem other)
  218.         {
  219.             this.Identifier = other.Identifier;
  220.             this.Header = other.Header;
  221.             this.Name = other.Name;
  222.             this.Description = other.Description;
  223.             this.Category = other.Category;
  224.             this.Icon = other.Icon;
  225.             this.FlavorText = other.FlavorText;
  226.             this.Quality = other.Quality;
  227.             this.Level = other.Level;
  228.             this.Capacity = other.Capacity;
  229.             this.Durability = other.Durability;
  230.             this.Enchantments = other.Enchantments?.ToList();
  231.             this.BaseSellPrice = other.BaseSellPrice;
  232.             this.BaseDamage = other.BaseDamage;
  233.             this.BaseBlockChance = other.BaseBlockChance;
  234.             this.Quantity = other.Quantity;
  235.             this.BaseArmorRating = other.BaseArmorRating;
  236.             this.BaseDurability = other.BaseDurability;
  237.             this.IsSpawnable = other.IsSpawnable;
  238.             this.IsEthereal = other.IsEthereal;
  239.             this.IsNew = other.IsNew;
  240.             this.IsConjured = other.IsConjured;
  241.         }
  242.  
  243.         public GameItem MakeCopy()
  244.         {
  245.             GameItem copy = new GameItem();
  246.             copy.Copy(this);
  247.             return copy;
  248.         }
  249.  
  250.         #region Static Item Prototype Creation
  251.         public static GameItem CreateWeapon(WeaponType category, string identifier, string header, string name, QualityType quality, int icon, List<Enchantment> enchantments,
  252.             string flavorText, int level, int baseDamage, int baseDurability, bool isSpawnable, bool isEthereal)
  253.         {
  254.             return new GameItem
  255.             {
  256.                 Category = category.ToItemCategory(),
  257.                 Identifier = identifier,
  258.                 Header = header,
  259.                 Name = name,
  260.                 Quality = quality,
  261.                 Icon = icon,
  262.                 Enchantments = enchantments,
  263.                 FlavorText = flavorText,
  264.                 Level = level,
  265.                 BaseDamage = baseDamage,
  266.                 BaseDurability = baseDurability,
  267.                 IsSpawnable = isSpawnable,
  268.                 IsEthereal = isEthereal
  269.             };
  270.         }
  271.  
  272.         public static GameItem CreateArmor(ArmorType category, string identifier, string header, string name, QualityType quality, int icon, List<Enchantment> enchantments,
  273.             string flavorText, int level, int baseArmorRating, int baseDurability, bool isSpawnable, bool isEthereal)
  274.         {
  275.             return new GameItem
  276.             {
  277.                 Category = category.ToItemCategory(),
  278.                 Identifier = identifier,
  279.                 Header = header,
  280.                 Name = name,
  281.                 Quality = quality,
  282.                 Icon = icon,
  283.                 Enchantments = enchantments,
  284.                 FlavorText = flavorText,
  285.                 Level = level,
  286.                 BaseArmorRating = baseArmorRating,
  287.                 BaseDurability = baseDurability,
  288.                 IsSpawnable = isSpawnable,
  289.                 IsEthereal = isEthereal
  290.             };
  291.         }
  292.  
  293.         public static GameItem CreateJewelry(JewelryType category, string identifier, string header, string name, QualityType quality, int icon, List<Enchantment> enchantments,
  294.             string flavorText, int level, int baseDurability, bool isSpawnable, bool isEthereal)
  295.         {
  296.             return new GameItem
  297.             {
  298.                 Category = category.ToItemCategory(),
  299.                 Identifier = identifier,
  300.                 Header = header,
  301.                 Name = name,
  302.                 Quality = quality,
  303.                 Icon = icon,
  304.                 Enchantments = enchantments,
  305.                 FlavorText = flavorText,
  306.                 Level = level,
  307.                 BaseDurability = baseDurability,
  308.                 IsSpawnable = isSpawnable,
  309.                 IsEthereal = isEthereal
  310.             };
  311.         }
  312.  
  313.         public static GameItem CreateHeldItem(HeldItemType category, string identifier, string header, string name, QualityType quality, int icon, List<Enchantment> enchantments,
  314.             string flavorText, int level, int baseArmorRating, int baseDurability, bool isSpawnable, bool isEthereal)
  315.         {
  316.             return new GameItem
  317.             {
  318.                 Category = category.ToItemCategory(),
  319.                 Identifier = identifier,
  320.                 Header = header,
  321.                 Name = name,
  322.                 Quality = quality,
  323.                 Icon = icon,
  324.                 Enchantments = enchantments,
  325.                 FlavorText = flavorText,
  326.                 Level = level,
  327.                 BaseArmorRating = baseArmorRating,
  328.                 BaseDurability = baseDurability,
  329.                 IsSpawnable = isSpawnable,
  330.                 IsEthereal = isEthereal
  331.             };
  332.         }
  333.         #endregion
  334.     }
  335. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement