伤害计算重构

This commit is contained in:
a376148946 2023-10-21 11:42:56 +08:00
parent 42f82956ec
commit 99fd1d2cbb
10 changed files with 1530 additions and 42 deletions

View File

@ -7,7 +7,7 @@ from gsuid_core.sv import SV
from gsuid_core.bot import Bot
from gsuid_core.models import Event
from .cal_damage import cal_info
from .cal_damage import cal, cal_info
from .to_card import api_to_card
from ..utils.convert import get_uid
from ..utils.sr_prefix import PREFIX
@ -40,10 +40,10 @@ async def send_damage_msg(bot: Bot, ev: Event):
if isinstance(char_data, str):
return await bot.send(char_data)
im_list = []
im = await cal_info(char_data)
im = await cal(char_data)
for info_im in im:
con = f"{info_im['name']}"
con = f"{con} 暴击伤害{info_im['damagelist'][0]} 期望伤害{info_im['damagelist'][1]} 满配辅助末日兽伤害{info_im['damagelist'][2]}"
con = f"{info_im[0]}"
con = f"{con} 暴击伤害{info_im[1]} 期望伤害{info_im[2]} 满配辅助末日兽伤害{info_im[3]}"
im_list.append(con)
await bot.send(im_list)
return None

View File

@ -316,7 +316,6 @@
}
},
"1208": {
"Normal": [0, 0, 0, 0, 0, 0, 0, 0, 0],
"Normal_HP": [
0.2500000004656613, 0.3000000005587935, 0.3500000006519258,
0.4000000007450581, 0.4500000008381903, 0.5000000000931323,
@ -336,7 +335,6 @@
0.120000000372529, 0.126000000372529, 0.132000000372529,
0.138000000372529, 0.144000000372529, 0.150000000372529
],
"Ultra": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"Ultra_HP": [
0.600000000372529, 0.640000000372529, 0.680000000372529,
0.720000000372529, 0.760000000372529, 0.800000000372529,
@ -344,13 +342,6 @@
1.000000000372529, 1.040000000372529, 1.080000000372529,
1.120000000372529, 1.160000000372529, 1.200000000372529
],
"Talent": [
0.220000000372529, 0.242000000372529, 0.264000000372529,
0.286000000372529, 0.308000000372529, 0.330000000372529,
0.357500000372529, 0.385000000372529, 0.412500000372529,
0.440000000372529, 0.462000000372529, 0.484000000372529,
0.506000000372529, 0.528000000372529, 0.550000000372529
],
"Maze": [20],
"Ultra_Use": [135],
"skillList": {
@ -573,7 +564,7 @@
"BPSkill1": [
1.2500000005122274, 1.3750000006705523, 1.500000000828877,
1.625000000558794, 1.750000000214204, 1.875000000372529,
0.031250000745058, 2.187500000419095, 2.343750000860302,
2.031250000745058, 2.187500000419095, 2.343750000860302,
2.500000000232831, 2.6250000003911555, 2.75000000054948,
2.875000000707805, 3.00000000086613, 3.12500000093132
],
@ -613,7 +604,7 @@
0.8000000007450581, 0.9000000008381903, 1.0000000000931323,
1.1000000001862645, 1.2000000002793968, 1.3000000002793968
],
"BPSkill": [
"Talent": [
0.7500000005122274, 0.8250000006705523, 0.900000000828877,
0.975000000558794, 1.050000000214204, 1.125000000372529,
1.218750000745058, 1.312500000419095, 1.406250000860302,
@ -643,6 +634,55 @@
],
"Maze": [20],
"Ultra_Use": [140],
"skillList": {
"Normal": ["attack", "普攻", 1, "Talent", "Normal"],
"Talent": ["attack", "账账", 1, "Talent", "Talent"],
"Talent1": ["attack", "强化账账", 1, "Talent", "Talent"]
}
},
"1302": {
"Normal": [
0.5000000004656613, 0.6000000005587935, 0.7000000006519258,
0.8000000007450581, 0.9000000008381903, 1.0000000000931323,
1.1000000001862645, 1.2000000002793968, 1.3000000002793968
],
"BPSkill": [
0.5500000005122274, 0.6050000002142042, 0.6600000006146729,
0.7150000003166497, 0.7700000007171184, 0.8250000004190952,
0.89375000144355, 0.962500001071021, 1.0312500004656613,
1.1000000000931323, 1.154999999795109, 1.2100000001955777,
1.2649999998975545, 1.3200000002980232, 1.375
],
"Ultra": [
1.0200000000186265, 1.0879999995231628, 1.1559999997261912,
1.2239999999292195, 1.2920000001322478, 1.3600000003352761,
1.4450000000651926, 1.530000000493601, 1.6150000002235174,
1.7000000006519258, 1.7680000001564622, 1.8360000003594905,
1.9040000005625188, 1.9720000007655472, 2.040000000037253
],
"Ultra1": [
1.6800000006332994, 1.792000000597909, 1.9040000005625188,
2.015999999595806, 2.1279999995604157, 2.2400000002235174,
2.3800000003539026, 2.5200000004842877, 2.660000000614673,
2.800000000745058, 2.912000000709668, 3.023999999742955,
3.1359999997075647, 3.2479999996721745, 3.360000000335276
],
"Ultra_add": [
0.5700000005308539, 0.6080000000074506, 0.6460000001825392,
0.6840000003576279, 0.7220000005327165, 0.7600000007078052,
0.80750000057742, 0.8550000004470348, 0.9025000010151416,
0.9500000008847564, 0.9880000003613532, 1.0259999996051192,
1.0639999997802079, 1.1019999999552965, 1.1400000001303852
],
"Talent": [
0.010000000009313226, 0.011500000255182385, 0.012999999802559614,
0.014500000048428774, 0.015999999595806003, 0.017499999841675162,
0.019375000149011612, 0.02125000045634806, 0.02312500006519258,
0.0249999996740371, 0.02649999991990626, 0.027999999467283487,
0.029499999713152647, 0.030999999959021807, 0.032500000204890966
],
"Maze": [20],
"Ultra_Use": [180],
"skillList": {
"Normal": ["attack", "普攻", 1, "Talent", "Normal"],
"BPSkill": ["attack", "账账", 1, "Talent", "BPSkill"],

View File

@ -91,6 +91,14 @@
]
}
},
"23018": {
"Param": {
"r_dmg": [
0.0036000001709908247, 0.00419999985024333, 0.004800000227987766,
0.005399999907240272, 0.005999999586492777
]
}
},
"20002": {
"Param": {
"a_dmg": [

View File

@ -1,5 +1,5 @@
from typing import Dict
import copy
from gsuid_core.logger import logger
from .utils import merge_attribute
@ -13,19 +13,24 @@ async def calculate_damage(
element: str,
skill_multiplier: float,
level: int,
is_hp = 0,
):
logger.info(f'Skill Multiplier: {skill_multiplier}')
logger.info(f'Skill Type: {skill_type}')
logger.info(f'Level: {level}')
# logger.info(f'attribute_bonus: {attribute_bonus}')
attribute_bonus = apply_attribute_bonus(
attribute_bonus, skill_type, add_skill_type
add_attr_bonus = copy.deepcopy(attribute_bonus)
add_attr_bonus = apply_attribute_bonus(
add_attr_bonus, skill_type, add_skill_type
)
merged_attr = await merge_attribute(base_attr, attribute_bonus)
merged_attr = await merge_attribute(base_attr, add_attr_bonus)
# logger.info(f'merged_attr: {merged_attr}')
if is_hp == 1:
attack = merged_attr.get('hp', 0)
else:
attack = merged_attr.get('attack', 0)
logger.info(f'Attack: {attack}')
@ -110,21 +115,21 @@ async def calculate_damage(
def apply_attribute_bonus(
attribute_bonus: Dict[str, float],
add_attr_bonus: Dict[str, float],
skill_type: str,
add_skill_type: str,
):
# Apply attribute bonuses to attack and status probability
for attr in attribute_bonus:
for attr in add_attr_bonus:
if 'AttackAddedRatio' in attr and attr.split('AttackAddedRatio')[
0
] in (skill_type, add_skill_type):
attribute_bonus['AttackAddedRatio'] += attribute_bonus[attr]
add_attr_bonus['AttackAddedRatio'] += add_attr_bonus[attr]
if 'StatusProbabilityBase' in attr and attr.split(
'StatusProbabilityBase'
)[0] in (skill_type, add_skill_type):
attribute_bonus['StatusProbabilityBase'] += attribute_bonus[attr]
return attribute_bonus
add_attr_bonus['StatusProbabilityBase'] += add_attr_bonus[attr]
return add_attr_bonus
def calculate_damage_reduction(level: int):

View File

@ -1,9 +1,9 @@
import json
from typing import Dict
from pathlib import Path
from typing import Dict
from ..Base.WeaponBase import BaseWeapon
from ..Base.model import DamageInstanceWeapon
from ..Base.WeaponBase import BaseWeapon
path = Path(__file__).parent.parent
with Path.open(path / 'Excel' / 'weapon_effect.json', encoding='utf-8') as f:
@ -1668,10 +1668,10 @@ class Thisbodyisasword(BaseWeapon):
)
resistance_penetration = attribute_bonus.get(
'AllResistancePenetration', 0
'AllDamageResistancePenetration', 0
)
attribute_bonus[
'AllResistancePenetration'
'AllDamageResistancePenetration'
] = resistance_penetration + (
weapon_effect['23014']['Param']['ResistancePenetration'][
self.weapon_rank - 1
@ -1747,11 +1747,41 @@ class WorrisomeBlissf(BaseWeapon):
)
return attribute_bonus
# 片刻,留在眼底
class AnInstanceBeforeAGaze(BaseWeapon):
weapon_base_attributes: Dict
def __init__(self, weapon: DamageInstanceWeapon):
super().__init__(weapon)
async def check(self):
# 当装备者施放终结技时根据装备者的能量上限提高装备者终结技造成的伤害每点能量提高0.36%最多计入180点。
return True
async def weapon_ability(
self,
Ultra_Use: float,
base_attr: Dict[str, float],
attribute_bonus: Dict[str, float],
):
if await self.check():
critical_chance_base = attribute_bonus.get('UltraDmgAdd', 0)
attribute_bonus['UltraDmgAdd'] = (
critical_chance_base
+ (
weapon_effect['23018']['Param']['r_dmg'][
self.weapon_rank - 1
]
)
* Ultra_Use
)
return attribute_bonus
class Weapon:
@classmethod
def create(cls, weapon: DamageInstanceWeapon):
if weapon.id_ in [
23018,
23011,
23007,
21005,
@ -1812,6 +1842,8 @@ class Weapon:
23014,
23016,
]:
if weapon.id_ == 23018:
return AnInstanceBeforeAGaze(weapon)
if weapon.id_ == 23016:
return WorrisomeBlissf(weapon)
if weapon.id_ == 23012:

View File

@ -37,3 +37,38 @@ async def merge_attribute(
logger.info(f'未知的属性加成: {attribute}, 采用覆盖模式')
merged_attr[attribute] = attribute_bonus[attribute]
return merged_attr
def merge_attribute_dam(
base_attr: Dict[str, float], attribute_bonus: Dict[str, float]
) -> Dict[str, float]:
merged_attr = base_attr.copy()
for attribute, value in attribute_bonus.items():
if attribute.endswith('Delta'):
attr = attribute.split('Delta')[0].lower()
if attr in merged_attr:
merged_attr[attr] += value
else:
merged_attr[attribute] = attribute_bonus[attribute]
elif attribute.endswith('AddedRatio'):
attr = attribute.split('AddedRatio')[0].lower()
if attr in merged_attr:
merged_attr[attr] += base_attr[attr] * value
else:
merged_attr[attribute] = attribute_bonus[attribute]
elif attribute in [
'ignore_defence',
'Atk_buff',
'Normal_buff',
'shield_added_ratio',
]:
merged_attr[attribute] = base_attr.get(attribute, 0) + value
elif attribute.endswith(
('ResistancePenetration', 'DmgAdd', 'DmgRatio')
):
merged_attr[attribute] = base_attr.get(attribute, 0) + value
elif attribute.endswith('Base'):
merged_attr[attribute] = base_attr.get(attribute, 0) + value
else:
logger.info(f'未知的属性加成: {attribute}, 采用覆盖模式')
merged_attr[attribute] = attribute_bonus[attribute]
return merged_attr

View File

@ -3,7 +3,7 @@ import math
import textwrap
from pathlib import Path
from typing import Dict, Union
import copy
from PIL import Image, ImageDraw
from gsuid_core.logger import logger
from gsuid_core.utils.image.convert import convert_img
@ -11,7 +11,7 @@ from gsuid_core.utils.image.image_tools import draw_text_by_line
from .to_data import api_to_dict
from ..utils.error_reply import CHAR_HINT
from .cal_damage import cal, cal_char_info
from .cal_damage import cal, cal_char_info, cal_info
from ..utils.fonts.first_world import fw_font_28
from ..utils.excel.read_excel import light_cone_ranks
from ..utils.map.name_covert import name_to_avatar_id, alias_to_char_name
@ -38,7 +38,7 @@ from ..utils.fonts.starrail_fonts import (
sr_font_38,
)
Excel_path = Path(__file__).parent / 'effect'
Excel_path = Path(__file__).parent / 'damage'
with Path.open(Excel_path / 'Excel' / 'SkillData.json', encoding='utf-8') as f:
skill_dict = json.load(f)
@ -100,8 +100,9 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str):
char = await cal_char_info(char_data)
damage_len = 0
if str(char.char_id) in skill_dict:
skill_list = skill_dict[str(char.char_id)]['skillList']
damage_len = len(skill_list)
damage_data = copy.deepcopy(char_data)
damage_list = await cal_info(damage_data)
damage_len = len(damage_list)
bg_height = 0
if damage_len > 0:
bg_height = 48 * (1 + damage_len) + 48
@ -360,7 +361,7 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str):
weapon_bg = Image.open(TEXT_PATH / 'weapon_bg.png')
weapon_id = char.equipment['equipmentID']
weapon_img = Image.open(WEAPON_PATH / f'{weapon_id}.png').resize(
(190, 180)
(170, 180)
)
weapon_bg.paste(weapon_img, (20, 90), weapon_img)
weapon_bg_draw = ImageDraw.Draw(weapon_bg)
@ -610,7 +611,7 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str):
if damage_len > 0:
damage_title_img = Image.open(TEXT_PATH / 'base_info_pure.png')
char_info.paste(damage_title_img, (0, 2028), damage_title_img)
damage_list = await cal(char_data)
# damage_list = await cal(char_data)
# 写伤害
char_img_draw.text(
(55, 2048),
@ -655,12 +656,12 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str):
)
char_img_draw.text(
(55, 2048 + damage_num * 48),
f'{damage_info[0]}',
f'{damage_info["name"]}',
white_color,
sr_font_26,
'lm',
)
damage1 = math.floor(damage_info[1]) # type: ignore
damage1 = math.floor(damage_info['damagelist'][0]) # type: ignore
char_img_draw.text(
(370, 2048 + damage_num * 48),
f'{damage1}',
@ -668,7 +669,7 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str):
sr_font_26,
'lm',
)
damage2 = math.floor(damage_info[2]) # type: ignore
damage2 = math.floor(damage_info['damagelist'][1]) # type: ignore
char_img_draw.text(
(560, 2048 + damage_num * 48),
f'{damage2}',
@ -676,7 +677,7 @@ async def draw_char_img(char_data: Dict, sr_uid: str, msg: str):
sr_font_26,
'lm',
)
damage3 = math.floor(damage_info[3]) # type: ignore
damage3 = math.floor(damage_info['damagelist'][2]) # type: ignore
char_img_draw.text(
(750, 2048 + damage_num * 48),
f'{damage3}',

View File

@ -502,5 +502,41 @@
"StatusProbabilityBase": 1.0,
"StatusResistanceBase": 0.0,
"AttributeAddedRatio": 1
},
{
"role": "托帕&账账",
"HPDelta": 0.0,
"HPAddedRatio": 0.0,
"AttackDelta": 0.75,
"AttackAddedRatio": 0.75,
"DefenceDelta": 0.0,
"DefenceAddedRatio": 0.0,
"SpeedDelta": 0.75,
"CriticalChanceBase": 1,
"CriticalDamageBase": 1,
"BreakDamageAddedRatioBase": 0.0,
"HealRatio": 0,
"SPRatio": 0.5,
"StatusProbabilityBase": 0.0,
"StatusResistanceBase": 0.0,
"AttributeAddedRatio": 1
},
{
"role": "银枝",
"HPDelta": 0.0,
"HPAddedRatio": 0.0,
"AttackDelta": 0.75,
"AttackAddedRatio": 0.75,
"DefenceDelta": 0.0,
"DefenceAddedRatio": 0.0,
"SpeedDelta": 0.75,
"CriticalChanceBase": 1,
"CriticalDamageBase": 1,
"BreakDamageAddedRatioBase": 0.0,
"HealRatio": 0,
"SPRatio": 0.5,
"StatusProbabilityBase": 0.0,
"StatusResistanceBase": 0.0,
"AttributeAddedRatio": 1
}
]

View File

@ -113,6 +113,12 @@
"卢卡",
"铁臂卢卡",
"熔锤镇的卢卡"
],
"1112": [
"托帕&账账",
"托帕",
"账账",
"账账启动器"
],
"1201": [
"青雀",
@ -160,12 +166,18 @@
"1211": [
"白露",
"衔药龙女"
],
"1212": [
"镜流"
],
"1213": [
"丹恒•饮月",
"饮月君",
"饮月",
"龙丹"
],
"1302": [
"银枝"
],
"8000": [
"开拓者",
@ -417,6 +429,10 @@
"23007": [
"雨一直下"
],
"23016": [
"烦恼着,幸福着",
"烦恼着幸福着"
],
"23008": [
"棺的回响"
],
@ -438,6 +454,11 @@
],
"23015": [
"比阳光更明亮的"
],
"23018": [
"片刻,留在眼底",
"片刻留在眼底",
"留在眼底"
],
"24000": [
"记一位星神的陨落",