| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using System;
- using cfg.GfgCfg;
- namespace GFGGame
- {
- /// <summary>
- /// 前后端共享计算类,谨慎修改!!!
- /// </summary>
- public class CalculateHelper
- {
- /// <summary>
- /// 获取物品实际属性分数值
- /// </summary>
- public static int GetItemAttribute(int scoreBase, int percentAdd, int scoreadd)
- {
- return (int)Math.Ceiling((scoreBase * (1f + percentAdd / 10000f) + scoreadd));
- }
- /// <summary>
- /// 获取物品属性存储的key值
- /// </summary>
- public static int GetItemScoreKey(int typeAttribute, int typeAction)
- {
- return typeAttribute *10 + typeAction;
- }
- /// <summary>
- /// 根据得分和配置计算星数
- /// </summary>
- public static int GetStoryChapterStar(int levelID, int score)
- {
- StoryLevelCfg levelCfg = CommonDataManager.Tables.TblStoryLevelCfg.GetOrDefault(levelID);
- StoryFightCfg fightCfg = CommonDataManager.Tables.TblStoryFightCfg.GetOrDefault(int.Parse(levelCfg.FightID));
- int starCount = 0;
- if (score > fightCfg.Score1)
- {
- if (score > fightCfg.Score3)
- {
- starCount = 3;
- }
- else if (score > fightCfg.Score2)
- {
- starCount = 2;
- }
- else
- {
- starCount = 1;
- }
- }
- return starCount;
- }
- //生成章节宝箱奖励状态
- public static int GenerateChapterBoxStates(int[] statesArr)
- {
- int valueBonusState = 0;
- for (var i = 0; i < statesArr.Length; i++)
- {
- var state = statesArr[i];
- if(i > 0)
- {
- valueBonusState += state * (int)Math.Pow(10d, (double)i);
- }
- else
- {
- valueBonusState += state;
- }
- }
- return valueBonusState;
- }
- //生成章节宝箱奖励状态
- public static void GenerateChapterBoxStates(int[] statesArr, int stateInt)
- {
- int value = stateInt;
- for (var i = statesArr.Length - 1; i >= 0; i--)
- {
- if (i > 0)
- {
- int temp = (int)Math.Pow(10d, (double)i);
- statesArr[i] = value / temp;
- value = value % temp;
- }
- else
- {
- statesArr[i] = value;
- }
- }
- }
- //获取副本通关关卡的key值
- public static int GenerateInstanceZonesLevelStateKey(int type, int subType, int chapterId)
- {
- return subType + type*10 + chapterId * 1000;
- }
- }
- }
|