using System;
using cfg.GfgCfg;
namespace GFGGame
{
///
/// 前后端共享计算类,谨慎修改!!!
///
public class CalculateHelper
{
///
/// 获取物品实际属性分数值
///
public static int GetItemAttribute(int scoreBase, int percentAdd, int scoreadd)
{
return (int)Math.Ceiling((scoreBase * (1f + percentAdd / 10000f) + scoreadd));
}
///
/// 获取物品属性存储的key值
///
public static int GetItemScoreKey(int typeAttribute, int typeAction)
{
return typeAttribute *10 + typeAction;
}
///
/// 根据得分和配置计算星数
///
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;
}
}
}