fix:修复职业报错的情况
This commit is contained in:
@@ -7,7 +7,7 @@ from fastapi.responses import JSONResponse
|
|||||||
|
|
||||||
from api.core.exception import ResponseException
|
from api.core.exception import ResponseException
|
||||||
|
|
||||||
logFormatter = logging.Formatter(
|
logFormatter = logging.Formatter(
|
||||||
"""
|
"""
|
||||||
[start]
|
[start]
|
||||||
%(asctime)s
|
%(asctime)s
|
||||||
@@ -15,19 +15,24 @@ logFormatter = logging.Formatter(
|
|||||||
%(message)s
|
%(message)s
|
||||||
[end]
|
[end]
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def all_exception_handler(request: Request, ex: Exception):
|
def format_exception() -> str:
|
||||||
# api = str(request.url).split("api/")[1]
|
lines = traceback.format_exc().strip().splitlines()
|
||||||
info = ''
|
if lines and lines[0].startswith('Traceback '):
|
||||||
if not isinstance(ex, ResponseException):
|
lines = lines[1:]
|
||||||
info = traceback.format_exc(limit=-1).strip().split('\n')[1:]
|
return '\r'.join(lines)
|
||||||
info[0] = info[0].split('\\')[-1].replace('"', ':').replace(',', '')
|
|
||||||
info = '\r'.join(info)
|
|
||||||
if request.client.host != '127.0.0.1':
|
async def all_exception_handler(request: Request, ex: Exception):
|
||||||
from fastapi.logger import logger
|
# api = str(request.url).split("api/")[1]
|
||||||
logger.setLevel(logging.ERROR)
|
info = ''
|
||||||
|
if not isinstance(ex, ResponseException):
|
||||||
|
info = format_exception()
|
||||||
|
if request.client.host != '127.0.0.1':
|
||||||
|
from fastapi.logger import logger
|
||||||
|
logger.setLevel(logging.ERROR)
|
||||||
logger.name = 'dcalc'
|
logger.name = 'dcalc'
|
||||||
log_directory = 'logs'
|
log_directory = 'logs'
|
||||||
import os
|
import os
|
||||||
@@ -42,12 +47,15 @@ async def all_exception_handler(request: Request, ex: Exception):
|
|||||||
try:
|
try:
|
||||||
import pathlib
|
import pathlib
|
||||||
pathlib.Path(log_directory).mkdir(parents=True, exist_ok=True)
|
pathlib.Path(log_directory).mkdir(parents=True, exist_ok=True)
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
print('创建日志目录logs失败,请确认是否限制了基础的运行权限')
|
print('创建日志目录logs失败,请确认是否限制了基础的运行权限')
|
||||||
logFunc = logger.error
|
logFunc = logger.error
|
||||||
logFunc(info)
|
try:
|
||||||
info = '服务器内部错误'
|
logFunc(info)
|
||||||
fileHandler.close()
|
info = '服务器内部错误'
|
||||||
|
finally:
|
||||||
|
logger.removeHandler(fileHandler)
|
||||||
|
fileHandler.close()
|
||||||
else:
|
else:
|
||||||
info = ex.args[0]
|
info = ex.args[0]
|
||||||
# traceback.print_last(sys.exc_info())
|
# traceback.print_last(sys.exc_info())
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ def skill_detail_for_level(skill_data: dict[str, Any], level: int | None) -> dic
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
attribute = {**level_info, **detail}
|
attribute = {**level_info, **detail}
|
||||||
attribute['detail'] = attribute.get('optionDesc', '')
|
option_desc = attribute.get('optionDesc')
|
||||||
|
attribute['detail'] = option_desc if isinstance(option_desc, str) else ''
|
||||||
|
|
||||||
for key, value in (attribute.get('optionValue') or {}).items():
|
for key, value in (attribute.get('optionValue') or {}).items():
|
||||||
attribute['detail'] = attribute['detail'].replace(f'{{{key}}}', str(value))
|
attribute['detail'] = attribute['detail'].replace(f'{{{key}}}', str(value))
|
||||||
|
|||||||
@@ -1,8 +1,23 @@
|
|||||||
|
import inspect
|
||||||
|
|
||||||
from ..formula import 获取基础属性
|
from ..formula import 获取基础属性
|
||||||
from core.basic.property import CharacterInfo
|
from core.basic.property import CharacterInfo
|
||||||
from .base import CharacterBase
|
from .base import CharacterBase
|
||||||
|
|
||||||
|
|
||||||
|
def _skill_error_context(char: CharacterBase, skill, mode: str) -> str:
|
||||||
|
skill_class = skill.__class__
|
||||||
|
skill_file = inspect.getsourcefile(skill_class) or inspect.getfile(skill_class)
|
||||||
|
return (
|
||||||
|
f'角色={getattr(char, "角色", "")}, '
|
||||||
|
f'职业={getattr(char, "职业", "")}, '
|
||||||
|
f'技能={getattr(skill, "name", "")}, '
|
||||||
|
f'技能类={skill_class.__name__}, '
|
||||||
|
f'mode={mode}, '
|
||||||
|
f'文件={skill_file}'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class CalcCarryMixin(CharacterBase):
|
class CalcCarryMixin(CharacterBase):
|
||||||
"""输出角色技能伤害计算相关方法"""
|
"""输出角色技能伤害计算相关方法"""
|
||||||
|
|
||||||
@@ -51,7 +66,10 @@ class CalcCarryMixin(CharacterBase):
|
|||||||
for i in self.skills:
|
for i in self.skills:
|
||||||
if i.damage and i.lv > 0:
|
if i.damage and i.lv > 0:
|
||||||
for mode in i.mode:
|
for mode in i.mode:
|
||||||
temp = i.skillInfo(mode)
|
try:
|
||||||
|
temp = i.skillInfo(mode)
|
||||||
|
except Exception as ex:
|
||||||
|
raise RuntimeError(f'职业技能计算失败: {_skill_error_context(self, i, mode)}') from ex
|
||||||
if temp[0] > 0:
|
if temp[0] > 0:
|
||||||
skillInfos.append(
|
skillInfos.append(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -200,8 +200,8 @@ class Skill11(ActiveSkill):
|
|||||||
self._ratio = value
|
self._ratio = value
|
||||||
|
|
||||||
# 技能等级变化的时候,系数对应的数值变化
|
# 技能等级变化的时候,系数对应的数值变化
|
||||||
def update_skill_attribute(self,skill, type, old, new, data,ratio = 100,weapon = []):
|
def update_skill_attribute(self, skill, type, old, new, data, ratio=100, weapon=(), weapon_type=None, weapon_options=()):
|
||||||
super().update_skill_attribute(skill, type, old, new, data, ratio / self.ratio, weapon)
|
super().update_skill_attribute(skill, type, old, new, data, ratio / self.ratio, weapon, weapon_type, weapon_options)
|
||||||
|
|
||||||
|
|
||||||
# 虚无之球 보이드
|
# 虚无之球 보이드
|
||||||
@@ -300,8 +300,8 @@ class Skill16(PassiveSkill):
|
|||||||
self._ratio = value
|
self._ratio = value
|
||||||
|
|
||||||
# 技能等级变化的时候,系数对应的数值变化
|
# 技能等级变化的时候,系数对应的数值变化
|
||||||
def update_skill_attribute(self,skill, type, old, new, data,ratio = 100,weapon = []):
|
def update_skill_attribute(self, skill, type, old, new, data, ratio=100, weapon=(), weapon_type=None, weapon_options=()):
|
||||||
super().update_skill_attribute(skill, type, old, new, data, ratio / self.ratio, weapon)
|
super().update_skill_attribute(skill, type, old, new, data, ratio / self.ratio, weapon, weapon_type, weapon_options)
|
||||||
|
|
||||||
# 天雷 썬더 콜링
|
# 天雷 썬더 콜링
|
||||||
# https://api.neople.co.kr/df/skills/3909d0b188e9c95311399f776e331da5/d2c6df5105577fb59fb92529a36165a0?apikey=fdvit1Kj64EAJm0qfB3JEAD8FLExLDD0
|
# https://api.neople.co.kr/df/skills/3909d0b188e9c95311399f776e331da5/d2c6df5105577fb59fb92529a36165a0?apikey=fdvit1Kj64EAJm0qfB3JEAD8FLExLDD0
|
||||||
|
|||||||
@@ -1677,7 +1677,7 @@ class Skill45(ActiveSkill):
|
|||||||
# 3层信仰效果时神圣之力持续时间 : {value6}秒
|
# 3层信仰效果时神圣之力持续时间 : {value6}秒
|
||||||
data6 = get_data(f'{prefix}/{uuid}', 6)
|
data6 = get_data(f'{prefix}/{uuid}', 6)
|
||||||
|
|
||||||
def skillInfo(self):
|
def skillInfo(self,mode=""):
|
||||||
prep = self.char.BuffSkill.skillInfo()
|
prep = self.char.BuffSkill.skillInfo()
|
||||||
ratio = self.data2[self.lv] * 5 / 100
|
ratio = self.data2[self.lv] * 5 / 100
|
||||||
return prep[0] * ratio, [prep[1][0] * ratio, prep[1][1], prep[1][2] * ratio], [prep[2][0] * ratio, prep[2][1], prep[2][2] * ratio], 0, self.getSkillCD()
|
return prep[0] * ratio, [prep[1][0] * ratio, prep[1][1], prep[1][2] * ratio], [prep[2][0] * ratio, prep[2][1], prep[2][2] * ratio], 0, self.getSkillCD()
|
||||||
@@ -1843,7 +1843,7 @@ class Skill49(ActiveSkill):
|
|||||||
# 力量、 智力增加 : [天启之光]数值的{value6}%
|
# 力量、 智力增加 : [天启之光]数值的{value6}%
|
||||||
data6 = get_data(f'{prefix}/{uuid}', 6)
|
data6 = get_data(f'{prefix}/{uuid}', 6)
|
||||||
|
|
||||||
def skillInfo(self):
|
def skillInfo(self,mode=""):
|
||||||
"""技能信息"""
|
"""技能信息"""
|
||||||
prep = self.char.AwakeSkill.skillInfo()
|
prep = self.char.AwakeSkill.skillInfo()
|
||||||
ratio = 0
|
ratio = 0
|
||||||
|
|||||||
@@ -345,11 +345,11 @@ class Skill19(ActiveSkill):
|
|||||||
skill.endpower *= raito
|
skill.endpower *= raito
|
||||||
self._maxLayer = value
|
self._maxLayer = value
|
||||||
|
|
||||||
def update_skill_attribute(self, skill, type, old, new, data, ratio, weapon=[]):
|
def update_skill_attribute(self, skill, type, old, new, data, ratio=100, weapon=(), weapon_type=None, weapon_options=()):
|
||||||
if len(data) == 0:
|
if len(data) == 0:
|
||||||
data = getattr(self, f'data{int(self.maxLayer)}')
|
data = getattr(self, f'data{int(self.maxLayer)}')
|
||||||
data = [i - 100 if i > 100 else 0 for i in data]
|
data = [i - 100 if i > 100 else 0 for i in data]
|
||||||
super().update_skill_attribute(skill, type, old, new, data, ratio, weapon)
|
super().update_skill_attribute(skill, type, old, new, data, ratio, weapon, weapon_type, weapon_options)
|
||||||
|
|
||||||
|
|
||||||
# 弧光连闪
|
# 弧光连闪
|
||||||
|
|||||||
Reference in New Issue
Block a user