rebase: 优化代码,移动模型

This commit is contained in:
bietiaop 2024-07-26 16:45:15 +08:00
parent 47e76adf80
commit 52b9a5b1b3
10 changed files with 653 additions and 459 deletions

View file

@ -1,9 +1,13 @@
import { element } from '../lib/convert.js';
import { element, property } from '../lib/convert.js';
import { getRoleImage, getSquareAvatar } from '../lib/download.js';
import { imageResourcesPath } from '../lib/path.js';
import { Equip, Weapon } from './equip.js';
import { Property } from './property.js';
import { Skill } from './skill.js';
import { relice_ability } from './damage/relice.js';
import { weapon_ability } from './damage/weapon.js';
import { avatar_ability } from './damage/avatar.js';
import _ from 'lodash';
import fs from 'fs';
import path from 'path';
@ -185,42 +189,6 @@ export class ZZZAvatarInfo {
* }} data
*/
constructor(data) {
// 类型标注
/** @type {number} */
this.id;
/** @type {number} */
this.level;
/** @type {string} */
this.name_mi18n;
/** @type {string} */
this.full_name_mi18n;
/** @type {number} */
this.element_type;
/** @type {string} */
this.camp_name_mi18n;
/** @type {number} */
this.avatar_profession;
/** @type {string} */
this.rarity;
/** @type {string} */
this.group_icon_path;
/** @type {string} */
this.hollow_icon_path;
/** @type {Equip[]} */
this.equip;
/** @type {Weapon} */
this.weapon;
/** @type {Property[]} */
this.properties;
/** @type {Skill[]} */
this.skills;
/** @type {number} */
this.rank;
/** @type {Rank[]} */
this.ranks;
/** @type {boolean} */
this.isNew;
const {
id,
level,
@ -240,31 +208,50 @@ export class ZZZAvatarInfo {
ranks,
isNew,
} = data;
logger.debug('ZZZAvatarInfo', data);
/** @type {number} */
this.id = id;
/** @type {number} */
this.level = level;
/** @type {string} */
this.name_mi18n = name_mi18n;
/** @type {string} */
this.full_name_mi18n = full_name_mi18n;
/** @type {number} */
this.element_type = element_type;
/** @type {string} */
this.camp_name_mi18n = camp_name_mi18n;
/** @type {number} */
this.avatar_profession = avatar_profession;
/** @type {string} */
this.rarity = rarity;
/** @type {string} */
this.group_icon_path = group_icon_path;
/** @type {string} */
this.hollow_icon_path = hollow_icon_path;
/** @type {Equip[]} */
this.equip =
equip &&
(Array.isArray(equip)
? equip.map(equip => new Equip(equip))
: new Equip(equip));
(equip &&
(Array.isArray(equip)
? equip.map(equip => new Equip(equip))
: new Equip(equip))) ||
[];
/** @type {Weapon} */
this.weapon = weapon ? new Weapon(weapon) : null;
/** @type {Property[]} */
this.properties =
properties && properties.map(property => new Property(property));
/** @type {Skill[]} */
this.skills = skills && skills.map(skill => new Skill(skill));
/** @type {number} */
this.rank = rank;
/** @type {Rank[]} */
this.ranks = ranks && ranks.map(rank => new Rank(rank));
/** @type {number} */
this.ranks_num = this.ranks.filter(rank => rank.is_unlocked).length;
/** @type {string} */
this.element_str = element.IDToElement(element_type);
/** @type {boolean} */
this.isNew = isNew;
}
@ -272,6 +259,18 @@ export class ZZZAvatarInfo {
return this.properties.find(property => property.property_name === name);
}
/** @type {{
* hpmax: Property;
* attack: Property;
* def: Property;
* breakstun: Property;
* crit: Property;
* critdam: Property;
* elementabnormalpower: Property;
* elementmystery: Property;
* penratio: Property;
* sprecover: Property;
* }} */
get basic_properties() {
const data = {
hpmax: this.getProperty('生命值'),
@ -289,8 +288,113 @@ export class ZZZAvatarInfo {
return data;
}
/** @type {{
* base_detail: {
* hp: number;
* attack: number;
* defence: number;
* ImpactRatio: number;
* CriticalChanceBase: number;
* CriticalDamageBase: number;
* ElementAbnormalPower: number;
* ElementMystery: number;
* PenRatioBase: number;
* SpGetRatio: number;
* }
* bonus_detail: Record<string, number>;
* set_detail: Record<string, number>;
* }} */
get damage_basic_properties() {
const base_detail = {
hp: Number(this.basic_properties.hpmax.final),
attack: Number(this.basic_properties.attack.final),
defence: Number(this.basic_properties.def.final),
ImpactRatio: Number(this.basic_properties.breakstun.final),
CriticalChanceBase:
Number(this.basic_properties.crit.final.replace('%', '')) / 100,
CriticalDamageBase:
Number(this.basic_properties.critdam.final.replace('%', '')) / 100,
ElementAbnormalPower: Number(
this.basic_properties.elementabnormalpower.final
),
ElementMystery: Number(this.basic_properties.elementmystery.final),
PenRatioBase:
Number(this.basic_properties.penratio.final.replace('%', '')) / 100,
SpGetRatio: Number(this.basic_properties.sprecover.final),
};
/** 穿
* 穿透值23203
* 伤害加成31503-31703
*/
const bonus_detail = {};
/** 计算套装数量 */
const set_detail = {};
for (const equip_detail of this.equip) {
bonus_detail['PenDelta'] =
_.get(bonus_detail, 'PenDelta', 0) + equip_detail.get_property(23203);
if (equip_detail.equipment_type == 5) {
const propname = property.idToName(
equip_detail.main_properties[0].property_id
);
if (propname.includes('属性伤害提高')) {
const propenname = property.idToSignName(
equip_detail.main_properties[0].property_id
);
bonus_detail[propenname] =
_.get(bonus_detail, propenname, 0) +
Number(equip_detail.main_properties[0].base.replace('%', '')) / 100;
}
}
const suit_id = String(equip_detail.equip_suit.suit_id);
set_detail[suit_id] = _.get(set_detail, suit_id, 0) + 1;
}
logger.debug('base_detail', base_detail);
logger.debug('bonus_detail', bonus_detail);
logger.debug('set_detail', set_detail);
const retuan_detail = {
base_detail: base_detail,
bonus_detail: bonus_detail,
set_detail: set_detail,
};
return retuan_detail;
}
/** @type {{
* title: string;
* value: {name: string, value: number}[]
* }[]} */
get damages() {
/** 处理基础数据 */
let base_detail = this.damage_basic_properties.base_detail;
let bonus_detail = this.damage_basic_properties.bonus_detail;
let set_detail = this.damage_basic_properties.set_detail;
/** 处理驱动盘套装加成 */
let set_detailkeys = Object.keys(set_detail);
for (const set_id of set_detailkeys) {
const set_num = set_detail[set_id];
if (set_num >= 2)
bonus_detail = relice_ability(
set_id,
set_num,
base_detail,
bonus_detail
);
}
logger.debug('bonus_detail', bonus_detail);
/** 处理音频加成 */
bonus_detail = weapon_ability(this.weapon, base_detail, bonus_detail);
logger.debug('bonus_detail', bonus_detail);
/** 处理角色加成 */
const damagelist = avatar_ability(this, base_detail, bonus_detail);
return damagelist;
}
async get_basic_assets() {
const result = await getSquareAvatar(this.id);
/** @type {string} */
this.square_icon = result;
}
@ -312,7 +416,7 @@ export class ZZZAvatarInfo {
if (!role_icon) {
role_icon = await getRoleImage(this.id);
}
/** @type {string} */
this.role_icon = role_icon;
await this?.weapon?.get_assets?.();
for (const equip of this.equip) {