Skip to content

Commit

Permalink
<jx3>[feat]shanhaixinjue dps calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
HornCopper committed Sep 8, 2024
1 parent 72030b0 commit 128294f
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/constant/jx3/schoolcolors.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
"无方": "#16708a",
"灵素": "#39bf9b",
"孤锋诀": "#6bb7f2",
"山海心诀": "#FFFFFF",
"山海心诀": "#dca53e",
"老板": "#FFFFFF"
}
29 changes: 25 additions & 4 deletions src/plugins/jx3/calculator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
dj_calculator, # 毒经
wf_calculator, # 无方
ylj_calculator, # 隐龙诀
shxj_calculator, # 山海心诀
)

from .wf import *

calc_dj = on_command("jx3_calculator_dj", aliases={"毒经计算器"}, priority=5, force_whitespace=True) # 目前先对毒经的计算器进行响应,后续尽可能多地支持

@calc_dj.handle()
Expand Down Expand Up @@ -60,7 +59,7 @@ async def _(event: GroupMessageEvent, args: Message = CommandArg()):
data = get_content_local(data)
await calc_wf.finish(ms.image(data))

calc_ylj = on_command("jx3_calculator_lyj", aliases={"凌雪计算器"}, priority=5, force_whitespace=True) # 目前先对无方的计算器进行响应,后续尽可能多地支持
calc_ylj = on_command("jx3_calculator_lyj", aliases={"凌雪计算器"}, priority=5, force_whitespace=True) # 目前先对凌雪阁的计算器进行响应,后续尽可能多地支持

@calc_ylj.handle()
async def _(event: GroupMessageEvent, args: Message = CommandArg()):
Expand All @@ -80,4 +79,26 @@ async def _(event: GroupMessageEvent, args: Message = CommandArg()):
await calc_ylj.finish(data[0])
elif isinstance(data, str):
data = get_content_local(data)
await calc_ylj.finish(ms.image(data))
await calc_ylj.finish(ms.image(data))

calc_shxj = on_command("jx3_calculator_shxj", aliases={"万灵计算器"}, priority=5, force_whitespace=True) # 目前先对万灵的计算器进行响应,后续尽可能多地支持

@calc_shxj.handle()
async def _(event: GroupMessageEvent, args: Message = CommandArg()):
if args.extract_plain_text() == "":
return
arg = args.extract_plain_text().split(" ")
if len(arg) not in [1, 2]:
await calc_shxj.finish("唔……参数不正确哦,请检查后重试~")
if len(arg) == 1:
server = None
id = arg[0]
elif len(arg) == 2:
server = arg[0]
id = arg[1]
data = await shxj_calculator(server, id, str(event.group_id))
if isinstance(data, list):
await calc_shxj.finish(data[0])
elif isinstance(data, str):
data = get_content_local(data)
await calc_shxj.finish(ms.image(data))
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ def check_set_effects(equip_list):

def get_key_qixue(qixue_list: list):
for qx in qixue_list:
if qx["name"] == "曲致":
return "曲致"
if qx["name"] == "固灵":
return "固灵"
return "曲致"
Expand All @@ -115,13 +113,13 @@ async def analyze_attrs(attrs_raw_data: dict) -> ExcelRequest:
suit = []
for equip in attrs_raw_data["data"]["Equips"]:
if equip["Icon"]["Kind"] == "武器" and equip["Icon"]["SubKind"] != "投掷囊":
if equip["Name"] == "十方断魂笛·虫魂" and equip["Quality"] == "13200":
if (equip["Name"], equip["Quality"]) == ("十方断魂笛·虫魂", "13200"):
weapon = "龙门飞剑"
if equip["Name"] == "墨语沉香" and equip["Quality"] == "12500":
if (equip["Name"], equip["Quality"]) == ("墨语沉香", "12500"):
weapon = "墨语沉香"
if equip["Name"] == "悠哉乐土":
weapon = "13950水特效"
if equip["Name"] == "死生往复·牵丝" and equip["Quality"] == "11650":
if (equip["Name"], equip["Quality"]) == ("死生往复·牵丝", "11650"):
weapon = "小橙武特效"
if equip["Icon"]["SubKind"] == "腰坠":
if equip["Name"] == "秋风韵":
Expand Down
34 changes: 18 additions & 16 deletions src/plugins/jx3/calculator/online_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ class FiveStone(BaseModel):
level: str = ""
max: str = ""
min: str = ""
icon: str = ""
kind: str = ""
subKind: str = ""
icon: Optional[str] = ""
kind: Optional[str] = ""
subKind: Optional[str] = ""
desc: str = ""
percent: bool = False

Expand Down Expand Up @@ -239,19 +239,21 @@ async def analyze_equip_list(self) -> Union[list, Literal[False]]:
EquipType=_EquipType(**equip["EquipType"]),
ID=equip["ID"],
UID=equip["UID"],
fiveStone=[
FiveStone(
name=item["Name"],
level=item["Level"],
max=item["Param1Max"],
min=item["Param1Min"],
icon=item["Icon"]["FileName"],
kind=item["Icon"]["Kind"],
subKind=item["Icon"]["SubKind"],
desc=item["Attrib"]["GeneratedMagic"],
percent=False
) for item in equip["FiveStone"]
] if equip["Icon"]["SubKind"] != "戒指" else [],
fiveStone = [
(
FiveStone(
name=item["Name"],
level=item["Level"],
max=item["Param1Max"],
min=item["Param1Min"],
icon=item["Icon"]["FileName"] if "Icon" in item and item["Icon"] is not None else None,
kind=item["Icon"]["Kind"] if "Icon" in item and item["Icon"] is not None else None,
subKind=item["Icon"]["SubKind"] if "Icon" in item and item["Icon"] is not None else None,
desc=item["Attrib"]["GeneratedMagic"],
percent=False
) if "Icon" in item and item["Icon"] is not None else FiveStone()
) for item in equip.get("FiveStone", [])
] if "Icon" not in equip or (equip["Icon"] and equip["Icon"].get("SubKind") != "戒指") else [],
permanentEnchant=[
PermanentEnchant(
id=equip["WPermanentEnchant"]["ID"],
Expand Down
79 changes: 79 additions & 0 deletions src/plugins/jx3/calculator/shanhaixinjue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# DPS计算器 山海心诀

from typing import Optional
from jinja2 import Template
from pathlib import Path

from src.constant.jx3 import color_list

from src.tools.basic.server import server_mapping
from src.tools.basic.prompts import PROMPT
from src.tools.utils.path import ASSETS, CACHE, VIEWS
from src.tools.utils.file import read, write
from src.tools.generate import generate, get_uuid

from src.plugins.jx3.bind.role import get_player_local_data

from .online_calculator import get_calculated_data

msgbox_shanhaixinjue = """
<div class="element">
<div class="cell-title"><span>理论DPS</span></div>
<div class="cell">{{ dps }}</div>
</div>"""

template_calculator_shanhaixinjue = """
<tr>
<td class="short-column">{{ skill }}</td>
<td class="short-column">
<div class="progress-bar" style="margin: 0 auto;">
<div class="progress" style="width: {{ display }};"></div>
<span class="progress-text">{{ percent }}</span>
</div>
</td>
<td class="short-column">{{ count }}</td>
<td class="short-column">{{ value }}</td>
</tr>"""

async def generate_calculator_img_shanhaixinjue(server: Optional[str], name: str, group_id: str = ""):
server = server_mapping(server, group_id)
if not server:
return [PROMPT.ServerNotExist]
role_data = await get_player_local_data(role_name=name, server_name=server)
if role_data.format_jx3api()["code"] != 200:
return [PROMPT.PlayerNotExist]
data = await get_calculated_data(server, name, group_id, "山海心诀")
if not data:
return ["唔……无法计算玩家数据!请检查装备、属性、职业!"]
stake_data = data["data"]["木桩计算结果"]
result = stake_data["秒伤"]
tables = []
for skill_data in stake_data["技能统计显示"]:
tables.append(
Template(template_calculator_shanhaixinjue).render(**{
"skill": skill_data["显示名称"],
"display": str(round(((skill_data["技能总输出"]/stake_data["总伤"]) / (stake_data["技能统计显示"][0]["技能总输出"]/stake_data["总伤"]))*100, 2)) + "%",
"percent": str(round(skill_data["技能总输出"]/stake_data["总伤"]*100, 2)) + "%",
"count": str(skill_data["技能数量"]) + "(" + str(round(skill_data["会心几率"]*100, 2)) + "%" + "会心)",
"value": str(int(skill_data["技能总输出"]))
})
)
html = Template(read(VIEWS + "/jx3/calculator/calculator.html")).render(**{
"font": ASSETS + "/font/custom.ttf",
"yozai": ASSETS + "/font/Yozai-Medium.ttf",
"msgbox": Template(msgbox_shanhaixinjue).render(**{
"dps": result
}),
"tables": "\n".join(tables),
"school": "山海心诀",
"color": color_list["山海心诀"],
"server": server,
"name": name,
"calculator": "在线DPS计算器 by 唐宋(循环数据作者请到计算器页面查看)<br>当前循环:朝仪_丛云"
})
final_html = CACHE + "/" + get_uuid() + ".html"
write(final_html, html)
final_path = await generate(final_html, False, ".total", False)
if not isinstance(final_path, str):
return
return Path(final_path).as_uri()
7 changes: 4 additions & 3 deletions src/plugins/jx3/calculator/universe.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .dj import generate_calculator_img_dujing as dj_calculator
from .wf import generate_calculator_img_wufang as wf_calculator
from .ylj import generate_calculator_img_yinlongjue as ylj_calculator
from .dujing import generate_calculator_img_dujing as dj_calculator
from .wufang import generate_calculator_img_wufang as wf_calculator
from .yinlongjue import generate_calculator_img_yinlongjue as ylj_calculator
from .shanhaixinjue import generate_calculator_img_shanhaixinjue as shxj_calculator
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 隐龙诀

from typing import Tuple, Literal, Optional, List, Union
from typing import Tuple, Literal, Optional, List, Union, Dict, Callable
from jinja2 import Template
from pathlib import Path

Expand Down Expand Up @@ -149,7 +149,7 @@ async def get_tuilan_raw_data(server: str, uid: str) -> dict:
return equip_data

class JX3Attributes:
map = {
map: Dict[str, Tuple[Callable, str]] = {
"基础攻击力": (lambda percent: percent, "jcgj"),
"会心": (lambda percent: percent/100*78622.5, "jchx"),
"会心效果": (lambda percent: (percent-175)/100*27513.75, "jchxxg"),
Expand All @@ -173,7 +173,7 @@ def weapon_damage(self) -> Tuple[int, int]:


@property
def panel(self):
def panel(self) -> dict:
panel: list = self.data["data"]["PersonalPanel"]
min_weapon, max_weapon = self.weapon_damage
new_dict = {
Expand All @@ -189,7 +189,7 @@ def panel(self):
return new_dict

@property
def special(self):
def special(self) -> list:
equip_list: list = self.data["data"]["Equips"]
result = []
equip_map = {
Expand Down Expand Up @@ -236,7 +236,7 @@ def effect(self) -> List[Optional[str]]:
return []

@property
def enchant(self):
def enchant(self) -> list:
enchant_ = []
for place in ["帽子", "上衣", "腰带", "护臂", "鞋"]:
flag = False
Expand Down

0 comments on commit 128294f

Please sign in to comment.