From 1ba3e9700f52e08179d4c99ddc646740d28323f1 Mon Sep 17 00:00:00 2001 From: KT Date: Fri, 28 Jul 2023 08:49:08 +0800 Subject: [PATCH 1/2] =?UTF-8?q?modify:=20=E6=B7=B1=E6=B7=B5=E7=B9=AA?= =?UTF-8?q?=E8=A3=BD=E5=9C=96=E7=89=87=E5=89=8D=E5=85=88=20defer=20respons?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit issue #43 --- cogs/abyss/ui.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cogs/abyss/ui.py b/cogs/abyss/ui.py index ab037a3..3c6fcf5 100644 --- a/cogs/abyss/ui.py +++ b/cogs/abyss/ui.py @@ -107,13 +107,14 @@ async def callback(self, interaction: discord.Interaction): embed=EmbedTemplate.error("僅限本人才能操作"), ephemeral=True ) else: # 繪製樓層圖片 + await interaction.response.defer() fp = await genshin_py.draw_abyss_card( self.abyss_data.abyss.floors[int(self.values[0])], self.abyss_data.characters, ) fp.seek(0) self.embed.set_image(url="attachment://image.jpeg") - await interaction.response.edit_message( + await interaction.edit_original_response( embed=self.embed, attachments=[discord.File(fp, "image.jpeg")] ) From 8255aad8486ebd225b7700dff1bad82121442488 Mon Sep 17 00:00:00 2001 From: KT Date: Sat, 29 Jul 2023 12:49:59 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E6=98=9F=E9=90=B5=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E6=AB=83=E5=A2=9E=E5=8A=A0=E5=89=AF=E8=A9=9E=E6=A2=9D?= =?UTF-8?q?=E6=95=B8=E9=87=8F=E7=B5=B1=E8=A8=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cogs/showcase/ui_starrail.py | 1 + star_rail/showcase.py | 92 ++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/cogs/showcase/ui_starrail.py b/cogs/showcase/ui_starrail.py index 3c2b128..cc67796 100644 --- a/cogs/showcase/ui_starrail.py +++ b/cogs/showcase/ui_starrail.py @@ -85,6 +85,7 @@ def __init__(self, showcase: Showcase, character_index: int | None = None): if character_index is not None: self.add_item(ShowcaseButton("面板", showcase.get_character_stat_embed, character_index)) self.add_item(ShowcaseButton("遺器", showcase.get_relic_stat_embed, character_index)) + self.add_item(ShowcaseButton("詞條", showcase.get_relic_score_embed, character_index)) if len(showcase.data.characters) > 0: self.add_item(ShowcaseCharactersDropdown(showcase)) diff --git a/star_rail/showcase.py b/star_rail/showcase.py index 4b309a7..6a6a88e 100644 --- a/star_rail/showcase.py +++ b/star_rail/showcase.py @@ -137,6 +137,98 @@ def get_relic_stat_embed(self, index: int) -> discord.Embed: return embed + def get_relic_score_embed(self, index: int) -> discord.Embed: + """取得角色遺器詞條數的嵌入訊息""" + + embed = self.get_default_embed(index) + embed.title = (embed.title + "詞條數") if embed.title is not None else "詞條數" + + character = self.data.characters[index] + relics = character.relics + if relics is None: + return embed + + substat_sum: dict[str, float] = { # 副詞條數量統計 + "攻擊力": 0.0, + "生命值": 0.0, + "防禦力": 0.0, + "速度": 0.0, + "暴擊率": 0.0, + "暴擊傷害": 0.0, + "效果命中": 0.0, + "效果抗性": 0.0, + "擊破特攻": 0.0, + } + crit_value: float = 0.0 # 雙爆分 + + base_hp = float(next(s for s in character.stats if s.name == "生命值").base) # 生命白值 + base_atk = float(next(s for s in character.stats if s.name == "攻擊力").base) # 攻擊白值 + base_def = float(next(s for s in character.stats if s.name == "防禦力").base) # 防禦白值 + + for relic in relics: + main = relic.main_property + if main.name == "暴擊率": + crit_value += float(main.value.removesuffix("%")) * 2 + if main.name == "暴擊傷害": + crit_value += float(main.value.removesuffix("%")) + for prop in relic.sub_property: + v = prop.value + match prop.name: + case "生命值": + p = float(v.removesuffix("%")) if v.endswith("%") else float(v) / base_hp + substat_sum["生命值"] += p / 3.89 + case "攻擊力": + p = float(v.removesuffix("%")) if v.endswith("%") else float(v) / base_atk + substat_sum["攻擊力"] += p / 3.89 + case "防禦力": + p = float(v.removesuffix("%")) if v.endswith("%") else float(v) / base_def + substat_sum["防禦力"] += p / 4.86 + case "速度": + substat_sum["速度"] += float(v) / 2.3 + case "暴擊率": + p = float(v.removesuffix("%")) + crit_value += p * 2.0 + substat_sum["暴擊率"] += p / 2.92 + case "暴擊傷害": + p = float(v.removesuffix("%")) + crit_value += p + substat_sum["暴擊傷害"] += p / 5.83 + case "效果命中": + substat_sum["效果命中"] += float(v.removesuffix("%")) / 3.89 + case "效果抗性": + substat_sum["效果抗性"] += float(v.removesuffix("%")) / 3.89 + case "擊破特攻": + substat_sum["擊破特攻"] += float(v.removesuffix("%")) / 5.83 + embed.add_field( + name="詞條數", + value="\n".join( + [f"{k.ljust(4, ' ')}:{round(v, 1)}" for k, v in substat_sum.items() if v > 0] + ), + ) + + # 詞條組合統計 + def sum_substat(name: str, *args: str) -> str: + total = 0.0 + for arg in args: + total += substat_sum[arg] + # 要超過 (4 * 詞條種類數量) 條以上才會顯示 + return f"{name.ljust(4, ' ')}:{round(total, 1)}\n" if total > 4 * len(args) else "" + + embed_value = f"雙暴 {round(crit_value)} 分\n" + embed_value += sum_substat("攻雙暴", "攻擊力", "暴擊率", "暴擊傷害") + embed_value += sum_substat("攻速雙暴", "攻擊力", "速度", "暴擊率", "暴擊傷害") + embed_value += sum_substat("攻命雙暴", "攻擊力", "效果命中", "暴擊率", "暴擊傷害") + embed_value += sum_substat("生速雙暴", "生命值", "速度", "暴擊率", "暴擊傷害") + embed_value += sum_substat("生攻速暴", "生命值", "攻擊力", "速度", "暴擊率", "暴擊傷害") + embed_value += sum_substat("生速抗", "生命值", "速度", "效果抗性") + embed_value += sum_substat("生防速", "生命值", "防禦力", "速度") + embed_value += sum_substat("防速抗", "防禦力", "速度", "效果抗性") + embed_value += sum_substat("防速命抗", "防禦力", "速度", "效果命中", "效果抗性") + + embed.add_field(name="總詞條統計", value=embed_value) + + return embed + def get_default_embed(self, index: int) -> discord.Embed: """取得角色的基本嵌入訊息"""