解决长期以来的技能解析一出错就永远错误的问题

This commit is contained in:
枫谷剑仙 2022-10-16 01:49:28 +08:00
parent 7876e8fa31
commit e7c80aa433
7 changed files with 56 additions and 38 deletions

View File

@ -25,6 +25,7 @@
force_reload_data: "強制刷新數據",
skill_parse: {
skill: {
error: tp`😫技能解析发生错误,请将角色 ID 反馈给开发者。`,
unknown: tp`未知的技能類型:${'type'}`, //type
active_turns: tp`${'turns'} 回合內,${'actionSkill'}`, //turns, actionSkill
random_skills: tp`隨機發動以下技能:${'skills'}`, //skills

View File

@ -25,6 +25,7 @@
force_reload_data: "强制刷新数据",
skill_parse: {
skill: {
error: tp`😫技能解析发生错误,请将角色 ID 反馈给开发者。`,
unknown: tp`未知的技能类型:${'type'}`, //type
active_turns: tp`${'turns'} 回合内,${'actionSkill'}`, //turns, actionSkill
random_skills: tp`随机发动以下技能:${'skills'}`, //skills

View File

@ -39,6 +39,7 @@ let localTranslating = {
force_reload_data: `Force refresh data`,
skill_parse: {
skill: {
error: tp`😫An error occurred in skill parsing, please feedback the Card ID to the developer.`,
unknown: tp`Unkonwn skill type: ${'type'}`,
active_turns: tp`${'actionSkill'}, for ${'turns'} turns`,
random_skills: tp`Random Activates these skills:${'skills'}`,

View File

@ -417,6 +417,7 @@ const SkillPowerUpKind = {
};
const SkillKinds = {
Error: "error",
Unknown: "unknown",
ActiveTurns: "active-turns",
DamageEnemy: "damage-enemy",
@ -1783,6 +1784,11 @@ function renderSkill(skill, option = {})
return frg;
}
switch (skill.kind) {
case SkillKinds.Error: {
let dict = { type: skill.kind };
frg.ap(tsp.skill.error(dict));
break;
}
case SkillKinds.Unknown: {
let dict = {
type: skill.kind
@ -1984,7 +1990,7 @@ function renderSkill(skill, option = {})
case SkillKinds.DamageEnemy: { //大炮和固伤
let attr = skill.attr, target = skill.target, damage = skill.damage, times = skill.times;
if (attr == null) break; //没有属性时编号为0的空技能
dict = {
let dict = {
target: target === 'all' ? tsp.target.enemy_all() : target === 'single' ? tsp.target.enemy_one() : tsp.target.enemy_attr({attr: renderAttrs(target, {affix: true})}),
damage: renderValue(damage, {unit: tsp.unit.point}),
attr: renderAttrs(attr, {affix: (attr === 'self' || attr === 'fixed') ? false : true}),
@ -2056,7 +2062,7 @@ function renderSkill(skill, option = {})
break;
}
case SkillKinds.BindSkill: {
dict = {
let dict = {
icon: createIcon(skill.kind)
};
frg.ap(tsp.skill.bind_skill(dict));
@ -2064,7 +2070,7 @@ function renderSkill(skill, option = {})
}
case SkillKinds.BoardChange: { //洗版
const attrs = skill.attrs;
dict = {
let dict = {
orbs: renderOrbs(attrs),
};
frg.ap(tsp.skill.board_change(dict));
@ -2144,7 +2150,7 @@ function renderSkill(skill, option = {})
damage: renderValue(damage),
attr: renderAttrs(attr, {affix: (attr === 'self' || attr === 'fixed') ? false : true}),
};
dict = {
let dict = {
icon: createIcon("heal", "hp-incr"),
damage_enemy: tsp.skill.damage_enemy(_dict),
heal: renderValue(heal, {percent: true}),
@ -2154,7 +2160,7 @@ function renderSkill(skill, option = {})
}
case SkillKinds.CounterAttack: { //反击
let attr = skill.attr, prob = skill.prob, value = skill.value;
dict = {
let dict = {
icon: createIcon(skill.kind),
target: tsp.target.enemy(),
chance: prob.value < 1 ? tsp.value.prob({value: renderValue(prob, { percent:true })}) : null,
@ -2169,7 +2175,7 @@ function renderSkill(skill, option = {})
let subDocument = [];
for (const change of changes)
{
dict = {
let dict = {
from: renderOrbs(change.from),
to: renderOrbs(change.to),
};
@ -2180,7 +2186,7 @@ function renderSkill(skill, option = {})
}
case SkillKinds.GenerateOrbs: { //产生珠子
let orbs = skill.orbs, exclude = skill.exclude, count = skill.count;
dict = {
let dict = {
exclude: exclude?.length ? tsp.word.affix_exclude({cotent: renderOrbs(exclude)}) : void 0,
orbs: renderOrbs(orbs),
value: count,
@ -2206,7 +2212,7 @@ function renderSkill(skill, option = {})
for (const generate of generates)
{
let orb = generate.orbs?.[0];
dict = {
let dict = {
orbs: renderOrbs(orb),
};
if (generate.type == 'shape')
@ -2245,7 +2251,7 @@ function renderSkill(skill, option = {})
case SkillKinds.OrbDropIncrease: { //增加天降
let attrs = skill.attrs, value = skill.value, flag = skill.flag;
dict = {
let dict = {
value: value && renderValue(value, {percent: true}) || null,
chance: value && tsp.value.prob({
value: renderValue(value, {percent: true})
@ -2274,7 +2280,7 @@ function renderSkill(skill, option = {})
}
case SkillKinds.ChangeAttribute: {
let attr = skill.attr, target = skill.target;
dict = {
let dict = {
attrs: renderAttrs(attr, {affix: true}),
target: target === 'opponent' ? tsp.target.enemy_all() : tsp.target.self(),
};
@ -2283,7 +2289,7 @@ function renderSkill(skill, option = {})
}
case SkillKinds.SetOrbState: {
let orbs = skill.orbs, state = skill.state, arg = skill.arg;
dict = {
let dict = {
orbs: renderOrbs(orbs, {className: state, affix: true}),
icon: createIcon('orb-' + state),
};
@ -2313,7 +2319,7 @@ function renderSkill(skill, option = {})
}
case SkillKinds.RateMultiply: {
let rate = skill.rate, value = skill.value;
dict = {
let dict = {
rate: tsp.skill["rate_multiply_" + rate]({icon: createIcon(skill.kind + "-" + rate)}),
value: renderValue(value),
};
@ -2322,7 +2328,7 @@ function renderSkill(skill, option = {})
}
case SkillKinds.ReduceDamage: {
let attrs = skill.attrs, percent = skill.percent, condition = skill.condition, prob = skill.prob;
dict = {
let dict = {
icon: createIcon(skill.kind),
attrs: renderAttrs(attrs, {affix: true}),
value: renderValue(percent, {percent: true}),
@ -2334,7 +2340,7 @@ function renderSkill(skill, option = {})
}
case SkillKinds.PowerUp: {
let attrs = skill.attrs, types = skill.types, targets = skill.targets, condition = skill.condition, value = skill.value, reduceDamage = skill.reduceDamage, additional = skill.additional;
dict = {
let dict = {
icon: createIcon(skill.kind),
};
if (condition) dict.condition = renderCondition(condition);
@ -2403,7 +2409,7 @@ function renderSkill(skill, option = {})
let dom = cardN(id);
dom.monDom.onclick = changeToIdInSkillDetail;
return dom; })
dict = {
let dict = {
cards: doms.nodeJoin(),
}
frg.ap(random ?
@ -2413,7 +2419,7 @@ function renderSkill(skill, option = {})
break;
}
case SkillKinds.VoidPoison: { //毒无效
dict = {
let dict = {
poison: renderOrbs([7,8], {affix: true})
}
frg.ap(tsp.skill.void_poison(dict));
@ -2421,7 +2427,7 @@ function renderSkill(skill, option = {})
}
case SkillKinds.SkillProviso: { //条件限制才能用技能
let cond = skill.cond;
dict = {
let dict = {
condition: renderCondition(cond)
}
frg.ap(tsp.skill.skill_proviso(dict));
@ -2429,7 +2435,7 @@ function renderSkill(skill, option = {})
}
case SkillKinds.ImpartAwakenings: { //赋予队员觉醒
let attrs = skill.attrs, types = skill.types, awakenings = skill.awakenings;
dict = {
let dict = {
awakenings: renderAwakenings(awakenings, {affix: true}),
}
@ -2455,7 +2461,7 @@ function renderSkill(skill, option = {})
case SkillKinds.ObstructOpponent: { //条件限制才能用技能
let type = skill.type, pos = skill.pos, enemy_skills = skill.enemy_skills;
let slight_pause = tsp.word.slight_pause().textContent;
dict = {
let dict = {
skills: enemy_skills.join(slight_pause)
}
let targetDict = { positions: pos?.map(p=>p+1).join(slight_pause)}
@ -2483,7 +2489,7 @@ function renderSkill(skill, option = {})
}
case SkillKinds.IncreaseDamageCap: { //增加伤害上限
const {cap, targets} = skill;
dict = {
let dict = {
icon: createIcon(skill.kind),
targets: targets.map(target=>
tsp?.target[target.replaceAll("-","_")]?.())
@ -2498,7 +2504,7 @@ function renderSkill(skill, option = {})
const boardsBar = merge_skill ? null : new BoardSet(new Board(), new Board(null,7,6), new Board(null,5,4));
const slight_pause = tsp.word.slight_pause().textContent;
dict = {
let dict = {
icon: createIcon('board-' + state),
state: tsp.board[state](),
position: posType == 'random' ? tsp.position.random() : tsp.position.shape(),
@ -2517,7 +2523,7 @@ function renderSkill(skill, option = {})
const [width, height] = skill.size;
dict.size = tsp.value.size({ width, height});
boardsBar?.boards?.forEach(board=>{
board.generateBlockStates('clouds', count, size, positions);
board.generateBlockStates('clouds', count, [width, height], positions);
});
}
if (state == 'immobility') { //封条
@ -2550,7 +2556,7 @@ function renderSkill(skill, option = {})
case SkillKinds.BoardSizeChange: { //改变版面大小
const { width, height } = skill;
dict = {
let dict = {
icon: createIcon(skill.kind),
size: tsp.value.size({ width, height}),
};

View File

@ -878,7 +878,6 @@ function descriptionToHTML(str)
}
//默认的技能解释的显示行为
function parseSkillDescription(skill) {
return descriptionToHTML(skill?.description);
}
//大数字缩短长度,默认返回本地定义字符串

View File

@ -3709,14 +3709,24 @@ function initialize(event) {
const card = Cards[this.mid] || Cards[0];
if (!card) return;
const activeSkill = skillParser(card.activeSkillId);
toggleDomClassName(
activeSkill.some(skill=>skill.kind == SkillKinds.EvolvedSkills),
"evolved-skill", skillBox);
skillDetailParsed.innerHTML = "";
skillDetailParsed.appendChild(renderSkillEntry(activeSkill));
lskillDetailParsed.innerHTML = "";
lskillDetailParsed.appendChild(renderSkillEntry(skillParser(card.leaderSkillId)));
try {
skillDetailParsed.innerHTML = "";
const parsedActiveSkill = skillParser(card.activeSkillId);
const isEvolvedSkill = parsedActiveSkill.some(skill=>skill.kind == SkillKinds.EvolvedSkills);
skillBox.classList.toggle("evolved-skill", isEvolvedSkill);
skillDetailParsed.appendChild(renderSkillEntry(parsedActiveSkill));
} catch (error) {
console.error("%o 主动技 %d 解析出错", card, card.activeSkillId, error);
skillDetailParsed.appendChild(renderSkillEntry([{kind: SkillKinds.Error}]));
}
try {
lskillDetailParsed.innerHTML = "";
const parsedLeaderSkill = skillParser(card.leaderSkillId);
lskillDetailParsed.appendChild(renderSkillEntry(parsedLeaderSkill));
} catch (error) {
console.error("%o 队长技 %d 解析出错", card, card.leaderSkillId, error);
lskillDetailParsed.appendChild(renderSkillEntry([{kind: SkillKinds.Error}]));
}
};
//合并技能开关

View File

@ -6411,19 +6411,19 @@ const cachesMap = new Map([
],
[
"script-json_data.js",
"d28f5e59828817e8b4714567c0362a7b"
"83cbe83aac41ec85c5030f1944ab0857"
],
[
"script-skill-parser.js",
"b8d6e652d1ca38358d46816cb093749e"
"b7d2f728613342d120c90da80289be15"
],
[
"script-universal_function.js",
"8ebe963ec3181f8107c2cd1efa6bc331"
"d5a8ec8d3fe8ba9c19c4158396a75615"
],
[
"script.js",
"04c4e80d69ec027dc0648d684470baf0"
"9a8d5eafe032d11fb235ff7f8ee98086"
],
[
"solo.html",
@ -6495,7 +6495,7 @@ const cachesMap = new Map([
],
[
"languages/zh-TW.js",
"8a536ceda4bcbdfdb2ed4a16ea6a0fb1"
"44dd3143a97b18de2d6ab61ce00497fc"
],
[
"languages/zh.css",
@ -6503,7 +6503,7 @@ const cachesMap = new Map([
],
[
"languages/zh.js",
"5774931127a656c8122e164e56b1013b"
"1504d9cff230fa280adaef668754bdc3"
],
[
"images/attrs.png",