| | |
| | | #GameWorld.Log('ClearCompileFormulaDist Sucess AllFormulaDist = %s'%(AllFormulaDist))
|
| | | return
|
| | |
|
| | | def Eval(formulaKey, formula, paramDict, toInt=True, ceil=False, playerID=0):
|
| | | def Eval(formulaKey, formula, paramDict, toInt=True, ceil=False, ndigits=0, playerID=0):
|
| | | """ 动态计算
|
| | | :param formulaKey: 公式编译缓存key
|
| | | :param formula: 公式字符串,如 "int(Atk*10 + MaxHP)"
|
| | | :param paramDict: 参数字典,如 {'Atk': 100, 'MaxHP': 5000}
|
| | | :param toInt: 是否转为整数
|
| | | :param ceil: 是否向上取整
|
| | | :param ndigits: 小数精确位数
|
| | | :return: 计算结果
|
| | | """
|
| | | compileFormula = GetCompileFormula(formulaKey, formula)
|
| | |
| | | try:
|
| | | # 执行计算
|
| | | value = eval(compileFormula, safe_env)
|
| | | if ndigits > 0:
|
| | | value = round(value, ndigits)
|
| | | if ceil:
|
| | | value = math.ceil(value)
|
| | | if toInt:
|