CalculateHelper.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using cfg.GfgCfg;
  3. namespace GFGGame
  4. {
  5. /// <summary>
  6. /// 前后端共享计算类,谨慎修改!!!
  7. /// </summary>
  8. public class CalculateHelper
  9. {
  10. /// <summary>
  11. /// 获取物品实际属性分数值
  12. /// </summary>
  13. public static int GetItemAttribute(int scoreBase, int percentAdd, int scoreadd)
  14. {
  15. return (int)Math.Ceiling((scoreBase * (1f + percentAdd / 10000f) + scoreadd));
  16. }
  17. /// <summary>
  18. /// 获取物品属性存储的key值
  19. /// </summary>
  20. public static int GetItemScoreKey(int typeAttribute, int typeAction)
  21. {
  22. return typeAttribute *10 + typeAction;
  23. }
  24. /// <summary>
  25. /// 根据得分和配置计算星数
  26. /// </summary>
  27. public static int GetStoryChapterStar(int levelID, int score)
  28. {
  29. StoryLevelCfg levelCfg = CommonDataManager.Tables.TblStoryLevelCfg.GetOrDefault(levelID);
  30. StoryFightCfg fightCfg = CommonDataManager.Tables.TblStoryFightCfg.GetOrDefault(int.Parse(levelCfg.FightID));
  31. int starCount = 0;
  32. if (score > fightCfg.Score1)
  33. {
  34. if (score > fightCfg.Score3)
  35. {
  36. starCount = 3;
  37. }
  38. else if (score > fightCfg.Score2)
  39. {
  40. starCount = 2;
  41. }
  42. else
  43. {
  44. starCount = 1;
  45. }
  46. }
  47. return starCount;
  48. }
  49. //生成章节宝箱奖励状态
  50. public static int GenerateChapterBoxStates(int[] statesArr)
  51. {
  52. int valueBonusState = 0;
  53. for (var i = 0; i < statesArr.Length; i++)
  54. {
  55. var state = statesArr[i];
  56. if(i > 0)
  57. {
  58. valueBonusState += state * (int)Math.Pow(10d, (double)i);
  59. }
  60. else
  61. {
  62. valueBonusState += state;
  63. }
  64. }
  65. return valueBonusState;
  66. }
  67. //生成章节宝箱奖励状态
  68. public static void GenerateChapterBoxStates(int[] statesArr, int stateInt)
  69. {
  70. int value = stateInt;
  71. for (var i = statesArr.Length - 1; i >= 0; i--)
  72. {
  73. if (i > 0)
  74. {
  75. int temp = (int)Math.Pow(10d, (double)i);
  76. statesArr[i] = value / temp;
  77. value = value % temp;
  78. }
  79. else
  80. {
  81. statesArr[i] = value;
  82. }
  83. }
  84. }
  85. //获取副本通关关卡的key值
  86. public static int GenerateInstanceZonesLevelStateKey(int type, int subType, int chapterId)
  87. {
  88. return subType + type*10 + chapterId * 1000;
  89. }
  90. }
  91. }