ysd新增香菱、申鹤伤害计算,fix bug

This commit is contained in:
CMHopeSunshine 2022-07-04 19:56:29 +08:00
parent 004112d43b
commit 92e2ed7b6d
11 changed files with 264 additions and 30 deletions

View File

@ -1,11 +1,11 @@
import os from pathlib import Path
import time import time
import xlsxwriter import xlsxwriter
from .meta_data import * from .meta_data import *
data_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'user_data', 'gacha_log_data') data_path = Path() / 'data' / 'LittlePaimon' / 'user_data' / 'gacha_log_data'
def id_generator(): def id_generator():
@ -48,7 +48,7 @@ def convertUIGF(gachaLog, uid):
def writeXLSX(uid, gachaLog, gachaTypeIds): def writeXLSX(uid, gachaLog, gachaTypeIds):
t = time.strftime("%Y%m%d%H%M%S", time.localtime()) t = time.strftime("%Y%m%d%H%M%S", time.localtime())
workbook = xlsxwriter.Workbook(os.path.join(data_path, f"gachaExport-{uid}.xlsx")) workbook = xlsxwriter.Workbook(data_path / f"gachaExport-{uid}.xlsx")
for id in gachaTypeIds: for id in gachaTypeIds:
gachaDictList = gachaLog[id] gachaDictList = gachaLog[id]
gachaTypeName = gachaQueryTypeDict[id] gachaTypeName = gachaQueryTypeDict[id]

View File

@ -1,14 +1,15 @@
import json import json
import os from pathlib import Path
from asyncio import sleep from asyncio import sleep
from littlepaimon_utils import aiorequests from littlepaimon_utils import aiorequests
from littlepaimon_utils.files import load_json, save_json
from .UIGF_and_XLSX import convertUIGF, writeXLSX from .UIGF_and_XLSX import convertUIGF, writeXLSX
from .api import getApi from .api import getApi
from .meta_data import gachaQueryTypeIds, gachaQueryTypeDict from .meta_data import gachaQueryTypeIds, gachaQueryTypeDict
data_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'user_data', 'gacha_log_data') data_path = Path() / 'data' / 'LittlePaimon' / 'user_data' / 'gacha_log_data'
async def getGachaLogs(url, gachaTypeId): async def getGachaLogs(url, gachaTypeId):
@ -73,21 +74,18 @@ async def get_data(url):
uid_flag = 0 uid_flag = 0
uid = gachaData["uid"] uid = gachaData["uid"]
localDataFilePath = os.path.join(data_path, f"gachaData-{uid}.json") localDataFilePath = data_path / f"gachaData-{uid}.json"
if os.path.isfile(localDataFilePath): if localDataFilePath.is_file():
with open(localDataFilePath, "r", encoding="utf-8") as f: localData = load_json(localDataFilePath)
localData = json.load(f)
mergeData = mergeDataFunc(localData, gachaData) mergeData = mergeDataFunc(localData, gachaData)
else: else:
mergeData = gachaData mergeData = gachaData
mergeData["gachaType"] = gachaQueryTypeDict mergeData["gachaType"] = gachaQueryTypeDict
# 写入json # 写入json
with open(localDataFilePath, "w", encoding="utf-8") as f: save_json(mergeData, localDataFilePath)
json.dump(mergeData, f, ensure_ascii=False, sort_keys=False, indent=4)
# 写入UIGF、json # 写入UIGF、json
with open(os.path.join(data_path, f"UIGF_gachaData-{uid}.json"), "w", encoding="utf-8") as f: UIGF_data = convertUIGF(mergeData['gachaLog'], uid)
UIGF_data = convertUIGF(mergeData['gachaLog'], uid) save_json(UIGF_data, data_path / f"UIGF_gachaData-{uid}.json")
json.dump(UIGF_data, f, ensure_ascii=False, sort_keys=False, indent=4)
# 写入xlsx # 写入xlsx
writeXLSX(uid, mergeData['gachaLog'], gachaQueryTypeIds) writeXLSX(uid, mergeData['gachaLog'], gachaQueryTypeIds)

View File

@ -585,7 +585,7 @@ async def _(event: MessageEvent, state: T_State, msg: Message = CommandArg()):
@role_info.got('uid', prompt='请把要查询的uid给派蒙哦~') @role_info.got('uid', prompt='请把要查询的uid给派蒙哦~')
@exception_handler() # @exception_handler()
async def _(event: MessageEvent, state: T_State): async def _(event: MessageEvent, state: T_State):
uid = transform_uid(state['uid']) uid = transform_uid(state['uid'])
if uid: if uid:

View File

@ -2,13 +2,17 @@ from .zhongli import draw_zhongli_dmg
from .hutao import draw_hutao_dmg from .hutao import draw_hutao_dmg
from .leishen import draw_leishen_dmg from .leishen import draw_leishen_dmg
from .xiao import draw_xiao_dmg from .xiao import draw_xiao_dmg
from .xiangling import draw_xiangling_dmg
from .shenhe import draw_shenhe_dmg
# 支持的角色列表 # 支持的角色列表
roles_list = { roles_list = {
'钟离': draw_zhongli_dmg, '钟离': draw_zhongli_dmg,
'胡桃': draw_hutao_dmg, '胡桃': draw_hutao_dmg,
'雷电将军': draw_leishen_dmg, '雷电将军': draw_leishen_dmg,
'': draw_xiao_dmg '': draw_xiao_dmg,
'香菱': draw_xiangling_dmg,
'申鹤': draw_shenhe_dmg
} }

View File

@ -0,0 +1,122 @@
from copy import deepcopy
from pathlib import Path
from typing import Tuple
from PIL import Image, ImageDraw
from littlepaimon_utils.files import load_json, load_image
from littlepaimon_utils.images import get_font, draw_center_text
from .common import resistance_coefficient as rc, defense_coefficient as dc, attr_common_fix, q_fix, e_fix, a_fix, \
growth_reaction, text_font, number_font
skill_data = load_json(path=Path(__file__).parent.parent.parent / 'utils' / 'json_data' / 'roles_data.json')['申鹤'][
'skill']
def cal_e_value(data: dict) -> float:
"""
计算申鹤e提供的加成
:param data: 角色数据
:return: 角色数据
"""
attack = data['属性']['基础攻击'] + data['属性']['额外攻击']
skill_level = data['天赋'][1]['等级'] - 1
percent_value = float(skill_data['仰灵威召将役咒']['数值']['伤害值提升'][skill_level].replace('%', '')) / 100.0
return percent_value * attack
def cal_e_dmg(data: dict, extra: dict) -> Tuple[float, float]:
"""
计算申鹤e技能
:param data: 角色数据
:param extra: 针对元素战技的额外数值
:return: 期望伤害和暴击后伤害
"""
role_level = data['等级']
skill_level = data['天赋'][1]['等级'] - 1
q_skill_level = data['天赋'][2]['等级'] - 1
attack = data['属性']['基础攻击'] + data['属性']['额外攻击']
cr = data['属性']['暴击率'] + extra['暴击率']
cd = data['属性']['暴击伤害']
dmg_bonus = 1 + data['属性']['伤害加成'][1] + extra['增伤']
dmg_bonus += 0.15 if role_level >= 40 else 0
percent_value_q = float(skill_data['神女遣灵真诀']['数值']['抗性降低'][q_skill_level].replace('%', '')) / 100.0
percent_value = float(skill_data['仰灵威召将役咒']['数值']['长按技能伤害'][skill_level].replace('%', '')) / 100.0
damage = (attack * percent_value) * (1 + cr * cd) * dmg_bonus * rc(0.1, percent_value_q) * dc(role_level)
return damage, damage / (1 + cr * cd) * (1 + cd)
def cal_q_dmg(data: dict, extra: dict) -> Tuple[float, float]:
"""
计算申鹤q的伤害
:param data: 角色数据
:param extra: 针对大招的额外数值
:return: 期望伤害和暴击后伤害
"""
role_level = data['等级']
skill_level = data['天赋'][2]['等级'] - 1
attack = data['属性']['基础攻击'] + data['属性']['额外攻击']
cr = data['属性']['暴击率'] + extra['暴击率']
cd = data['属性']['暴击伤害']
dmg_bonus = 1 + data['属性']['伤害加成'][1] + extra['增伤']
dmg_bonus += 0.15 if role_level >= 40 else 0
dmg_bonus += 0.15 if role_level >= 70 else 0
percent_value = float(skill_data['神女遣灵真诀']['数值']['持续伤害'][skill_level].replace('%', '')) / 100.0
percent_value_rc = float(skill_data['神女遣灵真诀']['数值']['抗性降低'][skill_level].replace('%', '')) / 100.0
damage = (attack * percent_value) * (1 + cr * cd) * dmg_bonus * rc(0.1, percent_value_rc) * dc(role_level)
return damage, damage / (1 + cr * cd) * (1 + cd)
def draw_shenhe_dmg(data: dict):
mask_top = load_image(path=Path() / 'resources' / 'LittlePaimon' / 'player_card2' / '遮罩top.png')
mask_body = load_image(path=Path() / 'resources' / 'LittlePaimon' / 'player_card2' / '遮罩body.png')
mask_bottom = load_image(path=Path() / 'resources' / 'LittlePaimon' / 'player_card2' / '遮罩bottom.png')
data = deepcopy(data)
height = 3 * 60 - 20
data['伤害描述'] = []
data = attr_common_fix(data)
data, q_value = q_fix(data)
data, e_value = e_fix(data)
data, a_value = a_fix(data)
if data['伤害描述']:
height += 60
bg = Image.new('RGBA', (948, height + 80), (0, 0, 0, 0))
bg.alpha_composite(mask_top, (0, 0))
bg.alpha_composite(mask_body.resize((948, height)), (0, 60))
bg.alpha_composite(mask_bottom, (0, height + 60))
bg_draw = ImageDraw.Draw(bg)
# 画线
bg_draw.line((250, 0, 250, 948), (255, 255, 255, 75), 2)
bg_draw.line((599, 0, 599, 60), (255, 255, 255, 75), 2)
bg_draw.line((599, 120, 599, 240), (255, 255, 255, 75), 2)
bg_draw.line((0, 60, 948, 60), (255, 255, 255, 75), 2)
bg_draw.line((0, 120, 948, 120), (255, 255, 255, 75), 2)
bg_draw.line((0, 180, 948, 180), (255, 255, 255, 75), 2)
# 顶栏
draw_center_text(bg_draw, '伤害计算', 0, 250, 11, 'white', get_font(30, text_font))
draw_center_text(bg_draw, '期望伤害', 250, 599, 11, 'white', get_font(30, text_font))
draw_center_text(bg_draw, '暴击伤害', 599, 948, 11, 'white', get_font(30, text_font))
draw_center_text(bg_draw, '冰翎加成', 0, 250, 73, 'white', get_font(30, text_font))
expect_dmg = cal_e_value(data)
draw_center_text(bg_draw, str(int(expect_dmg)), 250, 948, 76, 'white', get_font(30, number_font))
draw_center_text(bg_draw, '战技长按', 0, 250, 133, 'white', get_font(30, text_font))
expect_dmg, crit_dmg = cal_e_dmg(data, e_value)
draw_center_text(bg_draw, str(int(expect_dmg)), 250, 599, 136, 'white', get_font(30, number_font))
draw_center_text(bg_draw, str(int(crit_dmg)), 599, 948, 136, 'white', get_font(30, number_font))
draw_center_text(bg_draw, '大招持续伤害', 0, 250, 193, 'white', get_font(30, text_font))
expect_dmg, crit_dmg = cal_q_dmg(data, q_value)
draw_center_text(bg_draw, str(int(expect_dmg)), 250, 599, 196, 'white', get_font(30, number_font))
draw_center_text(bg_draw, str(int(crit_dmg)), 599, 948, 196, 'white', get_font(30, number_font))
# 额外说明
if data['伤害描述']:
bg_draw.line((0, 240, 948, 240), (255, 255, 255, 75), 2)
draw_center_text(bg_draw, '额外说明', 0, 250, 253, 'white', get_font(30, text_font))
draw_center_text(bg_draw, ''.join(data['伤害描述']), 250, 948, 256, 'white', get_font(30, text_font))
return bg

View File

@ -0,0 +1,111 @@
from copy import deepcopy
from pathlib import Path
from typing import Tuple
from PIL import Image, ImageDraw
from littlepaimon_utils.files import load_json, load_image
from littlepaimon_utils.images import get_font, draw_center_text
from .common import resistance_coefficient as rc, defense_coefficient as dc, attr_common_fix, q_fix, e_fix, a_fix, \
growth_reaction, text_font, number_font
skill_data = load_json(path=Path(__file__).parent.parent.parent / 'utils' / 'json_data' / 'roles_data.json')['香菱']['skill']
def cal_e_dmg(data: dict, extra: dict) -> Tuple[float, float]:
"""
计算香菱锅巴的伤害
:param data: 角色数据
:param extra: 针对元素战技的额外数值
:return: 期望伤害和暴击后伤害
"""
role_level = data['等级']
skill_level = data['天赋'][1]['等级'] - 1
attack = data['属性']['基础攻击'] + data['属性']['额外攻击']
cr = data['属性']['暴击率'] + extra['暴击率']
cd = data['属性']['暴击伤害']
dmg_bonus = 1 + data['属性']['伤害加成'][1] + extra['增伤']
percent_value = float(skill_data['锅巴出击']['数值']['喷火伤害'][skill_level].replace('%', '')) / 100.0
if len(data['命座']) >= 1:
damage = (attack * percent_value) * (1 + cr * cd) * dmg_bonus * rc(0.1, 0.15) * dc(role_level)
else:
damage = (attack * percent_value) * (1 + cr * cd) * dmg_bonus * rc() * dc(role_level)
return damage, damage / (1 + cr * cd) * (1 + cd)
def cal_q_dmg(data: dict, extra: dict) -> Tuple[float, float]:
"""
计算香菱大招的伤害
:param data: 角色数据
:param extra: 针对大招的额外数值
:return: 期望伤害和暴击后伤害
"""
role_level = data['等级']
skill_level = data['天赋'][2]['等级'] - 1
attack = data['属性']['基础攻击'] + data['属性']['额外攻击']
cr = data['属性']['暴击率'] + extra['暴击率']
cd = data['属性']['暴击伤害']
dmg_bonus = 1 + data['属性']['伤害加成'][1] + extra['增伤']
percent_value = float(skill_data['旋火轮']['数值']['旋火轮伤害'][skill_level].replace('%', '')) / 100.0
if len(data['命座']) >= 1:
damage = (attack * percent_value) * (1 + cr * cd) * dmg_bonus * rc(0.1, 0.15) * dc(role_level)
else:
damage = (attack * percent_value) * (1 + cr * cd) * dmg_bonus * rc() * dc(role_level)
return damage, damage / (1 + cr * cd) * (1 + cd)
def draw_xiangling_dmg(data: dict):
mask_top = load_image(path=Path() / 'resources' / 'LittlePaimon' / 'player_card2' / '遮罩top.png')
mask_body = load_image(path=Path() / 'resources' / 'LittlePaimon' / 'player_card2' / '遮罩body.png')
mask_bottom = load_image(path=Path() / 'resources' / 'LittlePaimon' / 'player_card2' / '遮罩bottom.png')
data = deepcopy(data)
height = 3 * 60 - 20
data['伤害描述'] = [] if len(data['命座']) < 1 else ['锅巴减抗']
data = attr_common_fix(data)
data, q_value = q_fix(data)
data, e_value = e_fix(data)
data, a_value = a_fix(data)
if data['伤害描述']:
height += 60
# 蒸发系数
if '蒸发系数' in data['属性']:
zf = growth_reaction(data['属性']['元素精通'], 1.5, 0.15)
else:
zf = growth_reaction(data['属性']['元素精通'], 1.5)
bg = Image.new('RGBA', (948, height + 80), (0, 0, 0, 0))
bg.alpha_composite(mask_top, (0, 0))
bg.alpha_composite(mask_body.resize((948, height)), (0, 60))
bg.alpha_composite(mask_bottom, (0, height + 60))
bg_draw = ImageDraw.Draw(bg)
# 画线
bg_draw.line((250, 0, 250, 948), (255, 255, 255, 75), 2)
bg_draw.line((599, 0, 599, 240), (255, 255, 255, 75), 2)
bg_draw.line((0, 60, 948, 60), (255, 255, 255, 75), 2)
bg_draw.line((0, 120, 948, 120), (255, 255, 255, 75), 2)
bg_draw.line((0, 180, 948, 180), (255, 255, 255, 75), 2)
# 顶栏
draw_center_text(bg_draw, '伤害计算', 0, 250, 11, 'white', get_font(30, text_font))
draw_center_text(bg_draw, '期望伤害', 250, 599, 11, 'white', get_font(30, text_font))
draw_center_text(bg_draw, '暴击伤害', 599, 948, 11, 'white', get_font(30, text_font))
draw_center_text(bg_draw, '锅巴喷火', 0, 250, 73, 'white', get_font(30, text_font))
expect_dmg, crit_dmg = cal_e_dmg(data, e_value)
draw_center_text(bg_draw, str(int(expect_dmg)), 250, 599, 76, 'white', get_font(30, number_font))
draw_center_text(bg_draw, str(int(crit_dmg)), 599, 948, 76, 'white', get_font(30, number_font))
draw_center_text(bg_draw, '旋火轮', 0, 250, 133, 'white', get_font(30, text_font))
expect_dmg, crit_dmg = cal_q_dmg(data, q_value)
draw_center_text(bg_draw, str(int(expect_dmg)), 250, 599, 136, 'white', get_font(30, number_font))
draw_center_text(bg_draw, str(int(crit_dmg)), 599, 948, 136, 'white', get_font(30, number_font))
draw_center_text(bg_draw, '旋火轮蒸发', 0, 250, 193, 'white', get_font(30, text_font))
draw_center_text(bg_draw, str(int(expect_dmg * zf)), 250, 599, 196, 'white', get_font(30, number_font))
draw_center_text(bg_draw, str(int(crit_dmg * zf)), 599, 948, 196, 'white', get_font(30, number_font))
# 额外说明
if data['伤害描述']:
bg_draw.line((0, 240, 948, 240), (255, 255, 255, 75), 2)
draw_center_text(bg_draw, '额外说明', 0, 250, 253, 'white', get_font(30, text_font))
draw_center_text(bg_draw, ''.join(data['伤害描述']), 250, 948, 256, 'white', get_font(30, text_font))
return bg

View File

@ -66,11 +66,12 @@ def draw_xiao_dmg(data: dict):
data = deepcopy(data) data = deepcopy(data)
height = 3 * 60 - 20 height = 3 * 60 - 20
if '伤害描述' in data and data['伤害描述']: data['伤害描述'] = []
height += 60
data = attr_common_fix(data) data = attr_common_fix(data)
data, e_value = e_fix(data) data, e_value = e_fix(data)
data, a_value = a_fix(data) data, a_value = a_fix(data)
if data['伤害描述']:
height += 60
bg = Image.new('RGBA', (948, height + 80), (0, 0, 0, 0)) bg = Image.new('RGBA', (948, height + 80), (0, 0, 0, 0))
bg.alpha_composite(mask_top, (0, 0)) bg.alpha_composite(mask_top, (0, 0))

View File

@ -108,7 +108,7 @@ def draw_zhongli_dmg(data: dict):
data = deepcopy(data) data = deepcopy(data)
height = 5 * 60 - 20 height = 5 * 60 - 20
data['伤害描述'] = ['护盾减抗,无双岩'] data['伤害描述'] = ['护盾减抗']
data = attr_common_fix(data) data = attr_common_fix(data)
data, q_value = q_fix(data) data, q_value = q_fix(data)
data, e_value = e_fix(data) data, e_value = e_fix(data)

View File

@ -8,9 +8,6 @@
<a href="https://cdn.jsdelivr.net/gh/CMHopeSunshine/LittlePaimon@master/LICENSE"><img src="https://img.shields.io/github/license/CMHopeSunshine/LittlePaimon" alt="license"></a> <a href="https://cdn.jsdelivr.net/gh/CMHopeSunshine/LittlePaimon@master/LICENSE"><img src="https://img.shields.io/github/license/CMHopeSunshine/LittlePaimon" alt="license"></a>
<img src="https://img.shields.io/badge/Python-3.8+-yellow" alt="python"> <img src="https://img.shields.io/badge/Python-3.8+-yellow" alt="python">
<img src="https://img.shields.io/badge/Nonebot-2.0.0b4-green" alt="python"> <img src="https://img.shields.io/badge/Nonebot-2.0.0b4-green" alt="python">
<a href="https://pypi.python.org/pypi/LittlePaimon">
<img src="https://img.shields.io/pypi/v/LittlePaimon" alt="pypi">
</a>
<a href="https://qun.qq.com/qqweb/qunpro/share?_wv=3&_wwv=128&inviteCode=MmWrI&from=246610&biz=ka"><img src="https://img.shields.io/badge/QQ频道交流-尘世闲游-blue?style=flat-square" alt="QQ guild"></a> <a href="https://qun.qq.com/qqweb/qunpro/share?_wv=3&_wwv=128&inviteCode=MmWrI&from=246610&biz=ka"><img src="https://img.shields.io/badge/QQ频道交流-尘世闲游-blue?style=flat-square" alt="QQ guild"></a>
</p> </p>
@ -61,20 +58,17 @@
> README只展示最近更新全部更新日志详见[这里](https://github.com/CMHopeSunshine/LittlePaimon/blob/nonebot2/UPDATE_LOG.md) > README只展示最近更新全部更新日志详见[这里](https://github.com/CMHopeSunshine/LittlePaimon/blob/nonebot2/UPDATE_LOG.md)
+ 7.3 + 7.3
- 重构部分代码 - 重构部分代码
- ~~修改了插件加载方式~~
- 不改了,回档了,依旧是用`nonebot.load_plugins`
- **修改静态资源和用户数据目录** - **修改静态资源和用户数据目录**
- 理论上会**自动迁移**,但`git pull`更新可能会将资源删除,所以最好**手动迁移,同时备份** - 理论上会**自动迁移**,但`git pull`更新可能会将资源删除,所以最好**手动迁移,同时备份**
- 1、将派蒙的`res`文件夹改名`LittlePaimon`移到nonebot根目录的`resources`中(没有`resources`就新建一个) - 1、将派蒙的`res`文件夹改名`LittlePaimon`移到nonebot根目录的`resources`中(没有`resources`就新建一个)
- 2、将派蒙的`user_data`文件夹移到nonebot根目录的`data/LittlePaimon`目录中(同理,没有就新建) - 2、将派蒙的`user_data`文件夹移到nonebot根目录的`data/LittlePaimon`目录中(同理,没有就新建)
- 静态资源改为启动时自动下载 - 静态资源改为启动时自动下载
- ~~上传至`pypi`~~
- ~~意味着你可以通过pip等包管理工具来下载派蒙例子见下面的部署方法~~
- ~~上面的修改基本上都是为了上传`pypi`,以及减少仓库体积~~
- pip安装的话加载时存在导包问题无法正确加载~~算了吧~~
+ 7.4 + 7.4
- 回档部分7.3的修改 - 回档部分7.3的修改
- `ysd`新增`香菱、申鹤`伤害计算
- 修复`60秒早报`接口bug - 修复`60秒早报`接口bug
- 修复神里绫人被识别为绫华别名的bug
- 修复抽卡记录获取bug
## 丨功能列表 ## 丨功能列表

View File

@ -76,4 +76,8 @@
- pip安装的话加载时存在导包问题无法正确加载~~算了吧~~ - pip安装的话加载时存在导包问题无法正确加载~~算了吧~~
+ 7.4 + 7.4
- 回档部分7.3的修改 - 回档部分7.3的修改
- `ysd`新增`香菱、申鹤`伤害计算
- 修复`60秒早报`接口bug - 修复`60秒早报`接口bug
- 修复神里绫人被识别为绫华别名的bug
- 修复抽卡记录获取bug

View File

@ -75,9 +75,9 @@ def get_match_alias(msg: str, type: str = 'roles', single_to_dict: bool = False)
if msg in match_list: if msg in match_list:
return {alias[0]: role_id} if single_to_dict else alias[0] return {alias[0]: role_id} if single_to_dict else alias[0]
elif match_list: elif match_list:
if len(match_list) == 1:
return {alias[0]: role_id} if single_to_dict else alias[0]
possible[alias[0]] = role_id possible[alias[0]] = role_id
if len(possible) == 1:
return {list(possible.keys())[0]: possible[list(possible.keys())[0]]} if single_to_dict else list(possible.keys())[0]
return possible return possible
elif type == 'weapons': elif type == 'weapons':
possible = [] possible = []