Advertisement
Krythic

Weapon

Nov 25th, 2019
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using VoidwalkerEngine.Framework.Collections;
  4. using VoidwalkerEngine.Framework.Interfaces;
  5. using VoidwalkerEngine.Framework.Logic;
  6. using VoidwalkerEngine.Framework.Maths;
  7. using VoidwalkerEngine.Framework.Systems.Items.Base;
  8.  
  9. namespace VoidwalkerEngine.Framework.Systems.Items
  10. {
  11.     public class Weapon : GameItem, IEquippable, IDamageProvider,
  12.         IDynamicModifierProvider, IDurabilityProvider, ISocketable
  13.     {
  14.         public WeaponCategory Category { get; set; }
  15.         public Range BaseDamage { get; set; }
  16.         public ItemModifierList ImplicitModifiers { get; set; }
  17.         public ItemModifierList ExplicitModifiers { get; set; }
  18.         public int BaseDurability { get; set; }
  19.         public int Durability { get; set; }
  20.         public List<IAugmentation> Augmentations { get; set; }
  21.         public int BaseMaximumSocketCount { get; set; }
  22.  
  23.         public Weapon()
  24.         {
  25.  
  26.         }
  27.  
  28.         public double AttackSpeed
  29.         {
  30.             get
  31.             {
  32.                 return Category.GetAttackSpeed();
  33.             }
  34.         }
  35.  
  36.         public bool IsBroken
  37.         {
  38.             get
  39.             {
  40.                 return this.Durability == 0;
  41.             }
  42.         }
  43.  
  44.         public override void Copy(GameItem other)
  45.         {
  46.             if (other is Weapon item)
  47.             {
  48.                 base.Copy(other);
  49.                 this.Category = item.Category;
  50.                 this.BaseDamage = item.BaseDamage;
  51.             }
  52.         }
  53.  
  54.         public Range GetMaximumDamage()
  55.         {
  56.             double multiplier = 1.0;
  57.             ItemModifierList modifiers = this.GetModifiers();
  58.             if (modifiers != null)
  59.             {
  60.                 if (modifiers.Contains(ItemModifierTrait.EnhancedWeaponDamage, out int value))
  61.                 {
  62.                     multiplier += value / 100D;
  63.                 }
  64.                 if (modifiers.Contains(ItemModifierTrait.Ethereal))
  65.                 {
  66.                     multiplier += 0.25D;
  67.                 }
  68.             }
  69.             return new Range(
  70.                 (int)Math.Floor(this.BaseDamage.Minimum * multiplier),
  71.                 (int)Math.Floor(this.BaseDamage.Maximum * multiplier));
  72.         }
  73.  
  74.         public ItemModifierList GetModifiers()
  75.         {
  76.             ItemModifierList results = new ItemModifierList();
  77.             if (this.ImplicitModifiers != null)
  78.             {
  79.                 results.Add(this.ImplicitModifiers);
  80.             }
  81.             if (this.ExplicitModifiers != null)
  82.             {
  83.                 results.Add(this.ExplicitModifiers);
  84.             }
  85.             if (this.Augmentations != null)
  86.             {
  87.                 foreach (IAugmentation augmentation in this.Augmentations)
  88.                 {
  89.                     switch (augmentation)
  90.                     {
  91.                         case IModifierProvider modifierProvider:
  92.                             if (modifierProvider.Modifiers != null)
  93.                             {
  94.                                 results.Add(modifierProvider.Modifiers);
  95.                             }
  96.                             break;
  97.                         case IConditionalModifierProvider conditionalProvider:
  98.                             if (conditionalProvider.WeaponModifiers != null)
  99.                             {
  100.                                 results.Add(conditionalProvider.WeaponModifiers);
  101.                             }
  102.                             break;
  103.                     }
  104.                 }
  105.             }
  106.             return results;
  107.         }
  108.  
  109.         public EquipmentSlot GetEquipmentSlot()
  110.         {
  111.             switch (this.Category)
  112.             {
  113.  
  114.                 case WeaponCategory.Dagger:
  115.                     return EquipmentSlot.Ambidextrious;
  116.                 case WeaponCategory.Sickle:
  117.                     return EquipmentSlot.MainHand;
  118.                 case WeaponCategory.Fist:
  119.                     return EquipmentSlot.Ambidextrious;
  120.                 case WeaponCategory.OneHandedAxe:
  121.                     return EquipmentSlot.Ambidextrious;
  122.                 case WeaponCategory.OneHandedMace:
  123.                     return EquipmentSlot.Ambidextrious;
  124.                 case WeaponCategory.OneHandedSword:
  125.                     return EquipmentSlot.Ambidextrious;
  126.                 case WeaponCategory.Scythe:
  127.                 case WeaponCategory.Staff:
  128.                 case WeaponCategory.TwoHandedAxe:
  129.                 case WeaponCategory.TwoHandedMace:
  130.                 case WeaponCategory.TwoHandedSword:
  131.                 case WeaponCategory.Bow:
  132.                     return EquipmentSlot.Bimanual;
  133.                 case WeaponCategory.Wand:
  134.                     return EquipmentSlot.MainHand;
  135.                 default:
  136.                     return EquipmentSlot.None;
  137.             }
  138.         }
  139.  
  140.         public void Break()
  141.         {
  142.             this.Durability = 0;
  143.         }
  144.  
  145.         public void Repair()
  146.         {
  147.             this.Durability = GetMaximumDurability();
  148.         }
  149.  
  150.         public int GetMaximumDurability()
  151.         {
  152.             double multiplier = 1.0;
  153.             ItemModifierList modifiers = this.GetModifiers();
  154.             if (modifiers != null)
  155.             {
  156.                 if (modifiers.Contains(ItemModifierTrait.EnhancedDurability, out int value))
  157.                 {
  158.                     multiplier += value / 100D;
  159.                 }
  160.                 if (modifiers.Contains(ItemModifierTrait.Ethereal))
  161.                 {
  162.                     multiplier += 0.25D;
  163.                 }
  164.             }
  165.             return (int)Math.Round(this.BaseDurability * multiplier);
  166.         }
  167.  
  168.         /// <summary>
  169.         /// Gets the total number of sockets that are currently
  170.         /// available on this item, regardless if they're currently filled
  171.         /// with augmentations.
  172.         /// </summary>
  173.         /// <returns></returns>
  174.         public int GetAvailableSocketCount()
  175.         {
  176.             ItemModifierList modifiers = this.GetModifiers();
  177.             if (modifiers.Contains(ItemModifierTrait.Socketed, out int value))
  178.             {
  179.                 if (value <= this.BaseMaximumSocketCount)
  180.                 {
  181.                     return value;
  182.                 }
  183.                 return this.BaseMaximumSocketCount;
  184.             }
  185.             return 0;
  186.         }
  187.  
  188.         public int GetEmptySocketCount()
  189.         {
  190.             if (this.Augmentations == null)
  191.             {
  192.                 return this.GetAvailableSocketCount();
  193.             }
  194.             return this.GetAvailableSocketCount() - this.Augmentations.Count;
  195.         }
  196.     }
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement