Advertisement
Krythic

GameItemScaling

Feb 20th, 2022
1,059
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using VoidwalkerEngine.Framework.DataTypes;
  4. using VoidwalkerEngine.Framework.Game.Systems.GameItems;
  5. using VoidwalkerEngine.Framework.Logic;
  6. using VoidwalkerEngine.Framework.Maths;
  7.  
  8. namespace VoidwalkerEngine.Framework.Algorithms
  9. {
  10.     public static class GameItemScaling
  11.     {
  12.         public static List<ItemProperty> ScaleEquipmentAttributes(GameItem item)
  13.         {
  14.             return ScaleItemStats(item.ItemType, item.Quality, item.ItemLevel, item.BaseItemProperties);
  15.         }
  16.  
  17.         public static List<ItemProperty> ScaleItemStats(GameItemType itemType, QualityType quality, int level, List<ItemPropertyType> baseStats)
  18.         {
  19.             if (quality.IsGreaterThanOrEqual(QualityType.Uncommon) && baseStats != null)
  20.             {
  21.                 List<ItemProperty> results = new List<ItemProperty>();
  22.                 for (int i = 0; i < baseStats.Count; i++)
  23.                 {
  24.                     ItemPropertyType statType = baseStats[i];
  25.                     ItemProperty stat = new ItemProperty();
  26.                     stat.StatType = statType;
  27.                     if (statType.IsRange())
  28.                     {
  29.                         int maximum = ScaleAttribute(statType.ToBaseValue(), level, quality, itemType);
  30.                         if(maximum < 1)
  31.                         {
  32.                             maximum = 1;
  33.                         }
  34.                         int minimum = (int)Math.Floor(maximum * statType.ToRangeVariance());
  35.                         if(minimum < 1)
  36.                         {
  37.                             minimum = 1;
  38.                         }
  39.                         stat.Range = new Range(minimum, maximum);
  40.                     }
  41.                     else
  42.                     {
  43.                         int value = ScaleAttribute(statType.ToBaseValue(), level, quality, itemType);
  44.                         if(value < 1)
  45.                         {
  46.                             value = 1;
  47.                         }
  48.                         stat.Value = value;
  49.                     }
  50.                     results.Add(stat);
  51.                 }
  52.                 return results;
  53.             }
  54.             return null;
  55.         }
  56.  
  57.         public static int ScaleAttribute(double baseStat, int level, QualityType quality, GameItemType itemType)
  58.         {
  59.             int result = (int)(((baseStat * quality.ToAttributeScalingMultiplier()) * level / 100D) * itemType.ToAttributeScalingMultiplier());
  60.             return result < 0 ? 0 : result;
  61.         }
  62.     }
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement