UpgradeUtil.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. public class UpgradeUtil
  5. {
  6. public enum Quality
  7. {
  8. Common = 0,
  9. Rare = 1,
  10. Epic = 2,
  11. Legendary = 3,
  12. // Heirloom = 4,
  13. }
  14. private static System.Array qualityArr = System.Enum.GetValues(typeof(Quality));
  15. public static Quality GetQualityByCode(int code)
  16. {
  17. return (Quality)qualityArr.GetValue (code);
  18. }
  19. private static Color[] qualityBorderColorArr = new Color[]{
  20. new Color(1f, 1f, 1f, 1f),
  21. new Color(75f/255f, 150f/255f, 255f/255f, 1f),
  22. new Color(219f/255f, 135f/255f, 255f/255f, 1f),
  23. new Color(255f/255f, 175f/255f, 135f/255f, 1f)
  24. };
  25. private static Color[] qualityTxtColorArr = new Color[]{
  26. new Color(1f, 1f, 1f, 1f),
  27. new Color(58f/255f, 157f/255f, 255f/255f, 1f),
  28. new Color(130f/255f, 58f/255f, 255f/255f, 1f),
  29. new Color(255f/255f, 136f/255f, 58f/255f, 1f)
  30. };
  31. private static int[] UpgradeCountArr = new int[]{ 2, 4, 10, 20, 40, 80, 150, 300, 600, 1200, 2400, 4800 };
  32. private static int[] MaxLevelArr = new int[]{12, 10, 8, 5};
  33. private static int[] price0 = new int[]{5, 20, 50, 150, 400, 1000, 2000, 4000, 8000, 16000, 32000};
  34. private static int[] price1 = new int[]{50, 150, 400, 1000, 2000, 4000, 8000, 16000, 32000};
  35. private static int[] price2 = new int[]{400, 1000, 2000, 4000, 8000, 16000, 32000};
  36. private static int[] price3 = new int[]{4000, 8000, 16000, 32000};
  37. private static List<int[]> priceList = new List<int[]>{ price0, price1, price2, price3};
  38. public static int GetUpgradeCount(int level)
  39. {
  40. int index = level - 1;
  41. if (index < 0)
  42. return 0;
  43. if(index >= UpgradeCountArr.Length)
  44. return UpgradeCountArr[UpgradeCountArr.Length - 1];
  45. return UpgradeCountArr[index];
  46. }
  47. public static int GetUpgradePrice(int level, Quality quality)
  48. {
  49. int index = level - 1;
  50. if (index < 0)
  51. return 0;
  52. int[] priceArr = priceList [quality.GetHashCode ()];
  53. if (index >= priceArr.Length)
  54. return 0;
  55. return priceArr [index];
  56. }
  57. public static Color GetCommonBorderColor()
  58. {
  59. return qualityBorderColorArr [Quality.Common.GetHashCode ()];
  60. }
  61. public static Color GetBorderColor(Quality quality)
  62. {
  63. return qualityBorderColorArr [quality.GetHashCode ()];
  64. }
  65. public static Color GetTextColor(Quality quality)
  66. {
  67. return qualityTxtColorArr [quality.GetHashCode ()];
  68. }
  69. public static int GetMaxLevel(Quality quality)
  70. {
  71. return MaxLevelArr [quality.GetHashCode ()];
  72. }
  73. public static float HpBase = 300f; // 1% hp
  74. public static float DmgBase = 10f; // 1% damage per second
  75. public static float GetHp(float value)
  76. {
  77. return value * HpBase;
  78. }
  79. public static float GetDamage(float value)
  80. {
  81. return value * DmgBase;
  82. }
  83. }