mirror of
https://github.com/baiqwerdvd/StarRailUID.git
synced 2025-05-08 04:55:47 +08:00
🚧 更新一部分计算
This commit is contained in:
parent
9c65d01497
commit
26c867d493
@ -1,65 +1,63 @@
|
||||
# import re
|
||||
# import json
|
||||
# from typing import Tuple
|
||||
import re
|
||||
|
||||
# from PIL import Image
|
||||
# import json
|
||||
from typing import Tuple
|
||||
|
||||
from PIL import Image
|
||||
from gsuid_core.sv import SV
|
||||
from gsuid_core.bot import Bot
|
||||
from gsuid_core.models import Event
|
||||
|
||||
from .to_card import enka_to_card
|
||||
|
||||
# from .get_enka_img import draw_char_info_img
|
||||
from .to_card import api_to_card
|
||||
from ..utils.convert import get_uid
|
||||
from ..utils.error_reply import UID_HINT
|
||||
|
||||
# from ..utils.image.convert import convert_img
|
||||
from ..utils.image.convert import convert_img
|
||||
from .draw_char_img import draw_char_info_img
|
||||
|
||||
# from ..utils.map.GS_MAP_PATH import alias_data
|
||||
# from .draw_char_rank import draw_cahrcard_list
|
||||
# from .get_enka_img import draw_enka_img, get_full_char
|
||||
# from ..utils.resource.RESOURCE_PATH import TEMP_PATH
|
||||
from ..utils.resource.RESOURCE_PATH import TEMP_PATH
|
||||
|
||||
sv_char_info_config = SV('sr面板设置', pm=2)
|
||||
sv_get_char_info = SV('sr面板查询', priority=10)
|
||||
sv_get_sr_original_pic = SV('sr查看面板原图', priority=5)
|
||||
|
||||
|
||||
# @sv_get_char_info.on_prefix('查询')
|
||||
# async def send_char_info(bot: Bot, ev: Event):
|
||||
# # im = await _get_char_info(bot, ev, ev.text)
|
||||
# im = ''
|
||||
# if isinstance(im, str):
|
||||
# await bot.send(im)
|
||||
# elif isinstance(im, Tuple):
|
||||
# if isinstance(im[0], Image.Image):
|
||||
# img = await convert_img(im[0])
|
||||
# else:
|
||||
# img = im[0]
|
||||
# await bot.send(img)
|
||||
# if im[1]:
|
||||
# with open(TEMP_PATH / f'{ev.msg_id}.jpg', 'wb') as f:
|
||||
# f.write(im[1])
|
||||
# elif im is None:
|
||||
# return
|
||||
# else:
|
||||
# await bot.send('发生未知错误')
|
||||
@sv_get_char_info.on_prefix('sr查询')
|
||||
async def send_char_info(bot: Bot, ev: Event):
|
||||
im = await _get_char_info(bot, ev, ev.text)
|
||||
if isinstance(im, str):
|
||||
await bot.send(im)
|
||||
elif isinstance(im, Tuple):
|
||||
if isinstance(im[0], Image.Image):
|
||||
img = await convert_img(im[0])
|
||||
else:
|
||||
img = im[0]
|
||||
await bot.send(img)
|
||||
if im[1]:
|
||||
with open(TEMP_PATH / f'{ev.msg_id}.jpg', 'wb') as f:
|
||||
f.write(im[1])
|
||||
elif im is None:
|
||||
return
|
||||
else:
|
||||
await bot.send('发生未知错误')
|
||||
|
||||
|
||||
# async def _get_char_info(bot: Bot, ev: Event, text: str):
|
||||
# # 获取角色名
|
||||
# msg = ''.join(re.findall('[\u4e00-\u9fa5 ]', text))
|
||||
# if not msg:
|
||||
# return
|
||||
# await bot.logger.info('开始执行[查询角色面板]')
|
||||
# # 获取uid
|
||||
# uid = await get_uid(bot, ev)
|
||||
# if uid is None:
|
||||
# return await bot.send(UID_HINT)
|
||||
# await bot.logger.info('[查询角色面板]uid: {}'.format(uid))
|
||||
#
|
||||
# im = await draw_char_info_img(msg, uid, ev.image)
|
||||
# return im
|
||||
async def _get_char_info(bot: Bot, ev: Event, text: str):
|
||||
# 获取角色名
|
||||
msg = ''.join(re.findall('[\u4e00-\u9fa5 ]', text))
|
||||
if not msg:
|
||||
return
|
||||
await bot.logger.info('开始执行[查询角色面板]')
|
||||
# 获取uid
|
||||
uid = await get_uid(bot, ev)
|
||||
if uid is None:
|
||||
return await bot.send(UID_HINT)
|
||||
await bot.logger.info('[查询角色面板]uid: {}'.format(uid))
|
||||
|
||||
im = await draw_char_info_img(msg, uid, ev.image)
|
||||
return im
|
||||
|
||||
|
||||
@sv_get_char_info.on_command('sr强制刷新')
|
||||
@ -68,6 +66,6 @@ async def send_card_info(bot: Bot, ev: Event):
|
||||
if uid is None:
|
||||
return await bot.send(UID_HINT)
|
||||
await bot.logger.info('[sr强制刷新]uid: {}'.format(uid))
|
||||
im = await enka_to_card(uid)
|
||||
im = await api_to_card(uid)
|
||||
await bot.logger.info(f'UID{uid}获取角色数据成功!')
|
||||
await bot.send(im)
|
||||
|
50
StarRailUID/starrailuid_charinfo/draw_char_img.py
Normal file
50
StarRailUID/starrailuid_charinfo/draw_char_img.py
Normal file
@ -0,0 +1,50 @@
|
||||
import re
|
||||
import json
|
||||
from typing import Dict, Union, Optional
|
||||
|
||||
from gsuid_core.utils.error_reply import CHAR_HINT
|
||||
|
||||
from .mono.Character import Character
|
||||
from ..utils.resource.RESOURCE_PATH import PLAYER_PATH
|
||||
from ..utils.map.name_covert import name_to_avatar_id, alias_to_char_name
|
||||
|
||||
|
||||
async def draw_char_info_img(raw_mes: str, sr_uid: str, url: Optional[str]):
|
||||
# 获取角色名
|
||||
char_name = ' '.join(re.findall('[\u4e00-\u9fa5]+', raw_mes))
|
||||
|
||||
char_data = await get_char_data(sr_uid, char_name)
|
||||
print(char_data)
|
||||
await cal_char_info(char_data)
|
||||
|
||||
|
||||
async def cal_char_info(char_data: dict):
|
||||
await Character(char_data).get_equipment_info()
|
||||
|
||||
|
||||
async def get_char_data(
|
||||
sr_uid: str, char_name: str, enable_self: bool = True
|
||||
) -> Union[Dict, str]:
|
||||
player_path = PLAYER_PATH / str(sr_uid)
|
||||
SELF_PATH = player_path / 'SELF'
|
||||
print(char_name)
|
||||
char_id = await name_to_avatar_id(char_name)
|
||||
print(char_id)
|
||||
if '开拓者' in char_name:
|
||||
char_name = '开拓者'
|
||||
else:
|
||||
char_name = await alias_to_char_name(char_id, char_name)
|
||||
|
||||
char_path = player_path / f'{char_name}.json'
|
||||
char_self_path = SELF_PATH / f'{char_name}.json'
|
||||
|
||||
if char_path.exists():
|
||||
path = char_path
|
||||
elif enable_self and char_self_path.exists():
|
||||
path = char_self_path
|
||||
else:
|
||||
return CHAR_HINT.format(char_name)
|
||||
|
||||
with open(path, 'r', encoding='utf8') as fp:
|
||||
char_data = json.load(fp)
|
||||
return char_data
|
107
StarRailUID/starrailuid_charinfo/mono/Character.py
Normal file
107
StarRailUID/starrailuid_charinfo/mono/Character.py
Normal file
@ -0,0 +1,107 @@
|
||||
from typing import Dict, Tuple
|
||||
|
||||
from mpmath import mp
|
||||
|
||||
from ...utils.map.SR_MAP_PATH import EquipmentID2AbilityProperty
|
||||
|
||||
mp.dps = 14
|
||||
|
||||
|
||||
class Character:
|
||||
def __init__(self, card_prop: Dict):
|
||||
# 面板数据
|
||||
self.card_prop: Dict = card_prop
|
||||
|
||||
self.char_level: int = int(card_prop['avatarLevel'])
|
||||
self.char_id: str = card_prop['avatarId']
|
||||
self.char_name: str = card_prop['avatarName']
|
||||
self.char_element = card_prop['avatarElement']
|
||||
self.char_promotion = card_prop['avatarPromotion']
|
||||
self.char_skill = card_prop['avatarSkill']
|
||||
self.extra_ability = card_prop['avatarExtraAbility']
|
||||
self.attribute_bonus = card_prop['avatarAttributeBonus']
|
||||
self.char_relic = card_prop['RelicInfo']
|
||||
self.base_attributes = card_prop['baseAttributes']
|
||||
self.add_attr = {}
|
||||
self.equipment = card_prop['equipmentInfo']
|
||||
self.rarity = card_prop['avatarRarity']
|
||||
|
||||
# 角色的圣遗物总分
|
||||
self.artifacts_all_score: float = 0
|
||||
self.percent: str = '0.0'
|
||||
self.dmg_data: Dict = {}
|
||||
self.seq_str: str = '无匹配'
|
||||
|
||||
async def get_equipment_info(self):
|
||||
base_attr = self.base_attributes
|
||||
equip = self.equipment
|
||||
ability_property = EquipmentID2AbilityProperty[
|
||||
str(equip['equipmentID'])
|
||||
]
|
||||
equip_rank = equip['equipmentRank']
|
||||
|
||||
equip_ability_property = ability_property[str(equip_rank)]
|
||||
|
||||
equip_add_base_attr = equip['baseAttributes']
|
||||
hp = mp.mpf(base_attr['hp']) + mp.mpf(equip_add_base_attr['hp'])
|
||||
attack = mp.mpf(base_attr['attack']) + mp.mpf(
|
||||
equip_add_base_attr['attack']
|
||||
)
|
||||
defence = mp.mpf(base_attr['defence']) + mp.mpf(
|
||||
equip_add_base_attr['defence']
|
||||
)
|
||||
base_attr['hp'] = str(hp)
|
||||
base_attr['attack'] = str(attack)
|
||||
base_attr['defence'] = str(defence)
|
||||
self.base_attributes = base_attr
|
||||
|
||||
for equip_ability in equip_ability_property:
|
||||
property_type = equip_ability['PropertyType']
|
||||
value = equip_ability['Value']['Value']
|
||||
if property_type in self.add_attr:
|
||||
self.add_attr[property_type] += value
|
||||
else:
|
||||
self.add_attr[property_type] = value
|
||||
print(self.base_attributes)
|
||||
print(self.add_attr)
|
||||
|
||||
|
||||
async def p2v(power: str, power_plus: int) -> Tuple[float, float]:
|
||||
"""
|
||||
将power转换为value
|
||||
"""
|
||||
# 如果存在123%+123%形式的
|
||||
if '+' in power:
|
||||
power_percent = (
|
||||
float(power.split('+')[0].replace('%', '')) / 100
|
||||
) * power_plus
|
||||
power_value = power.split('+')[1]
|
||||
if '%' in power_value:
|
||||
power_percent += (
|
||||
float(power_value.replace('%', '')) / 100 * power_plus
|
||||
)
|
||||
power_value = 0
|
||||
else:
|
||||
power_value = float(power_value)
|
||||
elif '%' in power:
|
||||
power_percent = float(power.replace('%', '')) / 100 * power_plus
|
||||
power_value = 0
|
||||
else:
|
||||
power_percent = 0
|
||||
power_value = float(power)
|
||||
|
||||
return power_percent, power_value
|
||||
|
||||
|
||||
# async def get_artifacts_value(raw_data: Dict) -> List[str]:
|
||||
# # 计算圣遗物效果
|
||||
# all_effects = []
|
||||
# for equip in raw_data['equipList']:
|
||||
# statNmae = equip['reliquaryMainstat']['statName']
|
||||
# statValue = equip['reliquaryMainstat']['statValue']
|
||||
# all_effects.append(await text_to_effect(statNmae, statValue))
|
||||
# for sub in equip['reliquarySubstats']:
|
||||
# sub_name = sub['statName']
|
||||
# sub_value = sub['statValue']
|
||||
# all_effects.append(await text_to_effect(sub_name, sub_value))
|
||||
# return all_effects
|
@ -22,22 +22,13 @@ from ..utils.map.SR_MAP_PATH import (
|
||||
skillId2Type,
|
||||
avatarId2Name,
|
||||
avatarId2EnName,
|
||||
avatarId2Rarity,
|
||||
characterSkillTree,
|
||||
avatarId2DamageType,
|
||||
)
|
||||
|
||||
mp.dps = 14
|
||||
|
||||
PROP_ATTR_MAP = {
|
||||
'Anemo': '44',
|
||||
'Cryo': '46',
|
||||
'Dendro': '43',
|
||||
'Electro': '41',
|
||||
'Geo': '45',
|
||||
'Hydro': '42',
|
||||
'Pyro': '40',
|
||||
}
|
||||
|
||||
|
||||
async def api_to_dict(
|
||||
sr_uid: str, sr_data: Optional[EnkaData] = None
|
||||
@ -114,6 +105,7 @@ async def get_data(char: dict, sr_data: dict, sr_uid: str):
|
||||
'avatarId': char['AvatarID'],
|
||||
'avatarName': avatarId2Name[str(char['AvatarID'])],
|
||||
'avatarElement': avatarId2DamageType[str(char['AvatarID'])],
|
||||
'avatarRarity': avatarId2Rarity[str(char['AvatarID'])],
|
||||
'avatarPromotion': char['Promotion'],
|
||||
'avatarLevel': char['Level'],
|
||||
'avatarSkill': [],
|
||||
|
@ -22,6 +22,9 @@ rankId2Name_fileName = f'rankId2Name_mapping_{version}.json'
|
||||
characterSkillTree_fileName = f'characterSkillTree_mapping_{version}.json'
|
||||
avatarId2DamageType_fileName = f'avatarId2DamageType_mapping_{version}.json'
|
||||
avatarId2Rarity_fileName = f'avatarId2Rarity_mapping_{version}.json'
|
||||
EquipmentID2AbilityProperty_fileName = (
|
||||
f'EquipmentID2AbilityProperty_mapping_{version}.json'
|
||||
)
|
||||
|
||||
|
||||
class TS(TypedDict):
|
||||
@ -70,3 +73,10 @@ with open(MAP / 'char_alias.json', 'r', encoding='UTF-8') as f:
|
||||
|
||||
with open(MAP / avatarId2Rarity_fileName, 'r', encoding='UTF-8') as f:
|
||||
avatarId2Rarity = msgjson.decode(f.read(), type=Dict[str, str])
|
||||
|
||||
with open(
|
||||
MAP / EquipmentID2AbilityProperty_fileName, 'r', encoding='UTF-8'
|
||||
) as f:
|
||||
EquipmentID2AbilityProperty = msgjson.decode(
|
||||
f.read(), type=Dict[str, Dict[str, List]]
|
||||
)
|
||||
|
File diff suppressed because one or more lines are too long
6
poetry.lock
generated
6
poetry.lock
generated
@ -510,14 +510,14 @@ files = [
|
||||
|
||||
[[package]]
|
||||
name = "nodeenv"
|
||||
version = "1.7.0"
|
||||
version = "1.8.0"
|
||||
description = "Node.js virtual environment builder"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*"
|
||||
files = [
|
||||
{file = "nodeenv-1.7.0-py2.py3-none-any.whl", hash = "sha256:27083a7b96a25f2f5e1d8cb4b6317ee8aeda3bdd121394e5ac54e498028a042e"},
|
||||
{file = "nodeenv-1.7.0.tar.gz", hash = "sha256:e0e7f7dfb85fc5394c6fe1e8fa98131a2473e04311a45afb6508f7cf1836fa2b"},
|
||||
{file = "nodeenv-1.8.0-py2.py3-none-any.whl", hash = "sha256:df865724bb3c3adc86b3876fa209771517b0cfe596beff01a92700e0e8be4cec"},
|
||||
{file = "nodeenv-1.8.0.tar.gz", hash = "sha256:d51e0c37e64fbf47d017feac3145cdbb58836d7eee8c6f6d3b6880c5456227d2"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
|
Loading…
x
Reference in New Issue
Block a user