Skip to content

Commit

Permalink
feat: 添加副词条挡位权重选择
Browse files Browse the repository at this point in the history
  • Loading branch information
weiduhuo committed Nov 17, 2023
1 parent f25c822 commit 127a93f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
2 changes: 2 additions & 0 deletions utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ class SRAData(metaclass=SRADataMeta):
"""是否在打印遗器信息时显示拓展信息"""
ndigits_for_relic: int = 2
"""在打印遗器信息时的小数精度"""
stats_weight_for_relic: int = 0
"""遗器副词条档位权重:0-空,1-主流赋值,2-真实比例赋值,3-主流赋值比例矫正"""


def __init__(self) -> None:
Expand Down
46 changes: 43 additions & 3 deletions utils/relic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import Any, Dict, List, Literal, Optional, Tuple, Union

import utils.questionary.questionary as questionary
from utils.questionary.questionary import Choice
from utils.questionary.questionary import Choice, Separator
# 改用本地的questionary模块,使之具备show_description功能,基于'tmbo/questionary/pull/330'
# import questionary # questionary原项目更新并具备当前功能后,可进行替换
from .relic_constants import *
Expand All @@ -20,6 +20,7 @@
from .log import log
pp = pprint.PrettyPrinter(indent=1, width=40, sort_dicts=False)
IS_PC = True # paltform flag (同时保存了模拟器与PC的识别位点)
INDENT = "\n" + " " * 5 # description的一级缩进


class StatsWeight:
Expand Down Expand Up @@ -136,6 +137,8 @@ def __init__(self, title=_("崩坏:星穹铁道")):
"""是否在打印遗器信息时显示详细信息 (如各副词条的强化次数、档位积分,以及提高原数据的小数精度)"""
self.ndigits: Literal[0, 1, 2, 3] = sra_config_obj.ndigits_for_relic
"""在打印遗器信息时的小数精度"""
self.subs_stats_iter_weight: Literal[0, 1, 2, 3] = sra_config_obj.stats_weight_for_relic
"""副词条档位权重选择:0-空,1-主流赋值,2-真实比例赋值,3-主流赋值的比例矫正"""
self.activate_conditional = False
"""在打印面板信息时激活条件效果"""

Expand Down Expand Up @@ -170,6 +173,24 @@ def __init__(self, title=_("崩坏:星穹铁道")):
# 校验队伍配装规范
if not self.check_team_data():
log.error(_("怀疑为手动错误修改json文件导致"))
# 首次启动权值进行选择
if self.subs_stats_iter_weight == 0:
msg = _("仅首次启动进行选择")+INDENT+_("后续可在'config.json'中的'stats_weight_for_relic'设置")
self.subs_stats_iter_weight = questionary.select(
_("请选择副词条三个档位的权值"),
choices = [
Choice(SUBS_STATS_TIER_WEIGHT[1][-1], value = 1,
description = INDENT+_("主流赋值")+INDENT+msg),
Choice(SUBS_STATS_TIER_WEIGHT[2][-1], value = 2,
description = INDENT+_("真实比例,除了五星遗器'速度'属性的真实比例为 [0.7692, 0.8846, 1.0]")+INDENT+msg),
Choice(SUBS_STATS_TIER_WEIGHT[3][-1], value = 3,
description = INDENT+_("主流赋值比例矫正后的结果")+INDENT+msg),
Separator(" ")
],
instruction = _("(将影响词条计算与遗器评分)"),
use_shortcuts = True,
).ask()
sra_config_obj.stats_weight_for_relic = self.subs_stats_iter_weight # 修改配置文件

def relic_entrance(self):
"""
Expand Down Expand Up @@ -1215,7 +1236,7 @@ def get_base_stats_detail(self, data: Tuple[str, float], rarity: int, level: int
return None
return result

def get_subs_stats_detail(self, data: Tuple[str, float], rarity: int, stats_index: Optional[int]=None) -> Optional[Tuple[int, int, float]]:
def get_subs_stats_detail(self, data: Tuple[str, float], rarity: int, stats_index: Optional[int]=None, check=True) -> Optional[Tuple[int, int, float]]:
"""
说明:
计算副词条的详细信息 (如强化次数、档位积分,以及提高原数据的小数精度)
Expand All @@ -1226,6 +1247,7 @@ def get_subs_stats_detail(self, data: Tuple[str, float], rarity: int, stats_inde
:param data: 遗器副词条键值对
:param stats_index: 遗器副词条索引
:param rarity: 遗器稀有度
:param check: 开启校验
返回:
:return level: 强化次数: 0次强化记为1,最高5次强化为6
:return score: 档位总积分: 1档记0分, 2档记1分, 3档记2分
Expand All @@ -1248,6 +1270,10 @@ def get_subs_stats_detail(self, data: Tuple[str, float], rarity: int, stats_inde
level -= 1
score = math.ceil((value - a_*level) / d - 1.e-6)
result = round(a*level + d*score, 4) # 四舍五入 (考虑浮点数运算的数值损失)
# 不启用校验,用于统计词条使用
if not check:
log.debug(f"({name}, {value}): [{a}, {d}], l={level}, s={score}, r={result}")
return (level, score, result)
# 校验数据
check = result - value
if check < 0 or \
Expand All @@ -1258,4 +1284,18 @@ def get_subs_stats_detail(self, data: Tuple[str, float], rarity: int, stats_inde
log.error(_(f"校验失败,原数据或计算方法有误: {data}"))
log.debug(f"[{a}, {d}], l={level}, s={score}, r={result}")
return None
return (level, score, result)
return (level, score, result)

def get_num_of_stats(self, stats_detail: Tuple[int, int, Any], rarity: int=5) -> Optional[float]:
"""
说明:
计算词条数量
"""
if rarity not in [4,5]:
return None
level, score, __ = stats_detail
level_w, score_w, __ = SUBS_STATS_TIER_WEIGHT[self.subs_stats_iter_weight]
num = level*level_w + score*score_w
if rarity == 4: # 四星与五星遗器比值为 0.8
num *= 0.8
return num
8 changes: 8 additions & 0 deletions utils/relic_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@
WEIGHT_STATS_NAME: List[str] = np.vstack((STATS_NAME[:3],STATS_NAME[6:7],STATS_NAME[8:]))[:, -1].tolist()
"""供设定权重的属性名称"""

SUBS_STATS_TIER_WEIGHT = [
None,
(0.9, 0.1, "[0.9, 1.0, 1.1]"), # 主流赋值
(0.8, 0.1, "[0.8, 0.9, 1.0]"), # 真实比例赋值,除五星遗器'速度'属性的真实比例为 [0.7692, 0.8846, 1.0]
(1-1/9, 1/9, "[0.888~, 1.0, 1.111~]"), # 主流赋值比例矫正
]
"""副词条档位权重:0-空,1-主流赋值,2-真实比例赋值,3-主流赋值比例矫正 (五星遗器*1,四星遗器*0.8)"""

SUBS_STATS_TIER = [
[(27.096, 3.3870 ), (13.548 , 1.6935 ), (13.548 , 1.6935 ), (2.7648, 0.3456), (2.7648, 0.3456), (3.456, 0.4320), # 四星遗器数值
(1.60, 0.20), (2.0736, 0.2592), (4.1472, 0.5184), (2.7648, 0.3456), (2.7648, 0.3456), (4.1472, 0.5184)],
Expand Down

0 comments on commit 127a93f

Please sign in to comment.