添加game.parseDieTextMap

This commit is contained in:
Spmario233 2024-05-05 01:34:28 +08:00
parent 0413276f94
commit 40dfb97076
3 changed files with 75 additions and 28 deletions

View File

@ -1580,6 +1580,61 @@ export class Game {
return getAudioList(skill, { audioname: [], history: [] }, skillInfo);
}
/**
* 获取角色死亡时能播放的所有阵亡语音
* @param { string | Player } player 角色名
* @returns { any[] } 语音地址列表
*/
parseDieTextMap(player){
let name, rawName;
if (typeof player === "string") {
name = player;
rawName = name;
}
else if (get.itemtype(player) === "player") {
// @ts-ignore
name = player.skin.name || player.name;
rawName = player.name;
}
const info = get.character(name), datas = [];
let dieAudios;
if(info && info.dieAudios.length > 0){
dieAudios = info.dieAudios;
}
//@mengxinzxz写的屎山
else if(rawName !== name && lib.characterSubstitute[rawName] && lib.characterSubstitute[rawName].some((i) => i[0] == name)){
const trashes = lib.characterSubstitute[rawName].find((i) => i[0] == name)[1];
const newCharacter = get.convertedCharacter(['','',0,[],trashes]);
dieAudios = newCharacter.dieAudios;
}
if(dieAudios && dieAudios.length > 0){
dieAudios.forEach(item => {
let key, file;
if(item.startsWith("ext:")){
const audioData = item.split(":");
key = audioData[2];
file = item;
}
else {
key = item;
file = `die/${item}.mp3`;
}
const data = {key, file}
if(lib.translate[`#${key}:die`]) data.text = lib.translate[`#${key}:die`];
datas.push(data);
});
}
else {
const data = {
key: name,
file: `die/${name}.mp3`,
isDefault: true,
}
if(lib.translate[`#${name}:die`]) data.text = lib.translate[`#${name}:die`];
datas.push(data);
}
return datas;
}
/**
*
* @param { string } skill

View File

@ -145,6 +145,11 @@ export class Character {
* @type { string[] }
**/
clans = [];
/**
* 武将牌拥有的全部阵亡语音
* @type { string[] }
**/
dieAudios = [];
/**
* 武将牌无法享受到的主公/地主红利
* @type { string[] }
@ -191,6 +196,7 @@ export class Character {
this.clans = [];
this.initFilters = [];
this.trashBin = [];
this.dieAudios = [];
}
/**
* @param { any[] } trash
@ -248,6 +254,10 @@ export class Character {
clans.push(item.slice(5));
} else if (item.startsWith("InitFilter:")) {
this.initFilters = item.slice(11).split(":");
} else if (item.startsWith("die:")){
this.dieAudios.push(item.slice(4));
} else if (item.startsWith("die_audio:")){
this.dieAudios = item.slice(10).split(":");
} else {
keptTrashes.push(item);
}
@ -369,6 +379,10 @@ export class Character {
if (character.initFilters.length > 0) {
trashes.push(`InitFilters:${character.initFilters.join(":")}`);
}
if (character.dieAudios.length > 0) {
if (character.dieAudios.length === 1) trashes.push(`die:${character.dieAudios[0]}`)
else trashes.push(`die_audio:${character.dieAudios.join(":")}`);
}
return new Proxy(trashes.concat(character.trashBin), {
set(target, prop, newValue) {

View File

@ -8786,38 +8786,16 @@ export const Content = {
_status.dying.remove(player);
if (lib.config.background_speak) {
const name = player.skin.name || player.name;
const goon = !lib.character[name];
if (goon)
lib.character[name] = [
"",
"",
0,
[],
((lib.characterSubstitute[player.name] || []).find((i) => i[0] == name) || [
name,
[],
])[1],
];
if (lib.character[name][4].some((tag) => /^die:.+$/.test(tag))) {
var tag = lib.character[name][4].find((tag) => /^die:.+$/.test(tag));
var reg = new RegExp("^ext:(.+)?/");
var match = tag.match(/^die:(.+)$/);
if (match) {
var path = match[1];
if (reg.test(path)) path = path.replace(reg, (_o, p) => `../extension/${p}/`);
game.playAudio(path);
}
} else if (lib.character[name][4].some((tag) => tag.startsWith("die_audio"))) {
var tag = lib.character[name][4].find((tag) => tag.startsWith("die_audio"));
var list = tag.split(":").slice(1);
game.playAudio("die", list.length ? list.randomGet() : name);
} else {
const audios = game.parseDieTextMap(player).randomGet();
if (audios.isDefault) {
const name = audios.key;
game.playAudio("die", name, function () {
game.playAudio("die", name.slice(name.indexOf("_") + 1));
});
}
if (goon) delete lib.character[name];
else{
game.playAudio(audios.file);
}
}
}, player);