Merge pull request #577 from kuangshen04/PR-Branch

完善trySkillAudio注释/拆分
This commit is contained in:
Spmario233 2023-10-26 22:44:48 +08:00 committed by GitHub
commit 65d4f92a9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 96 additions and 66 deletions

View File

@ -36853,52 +36853,68 @@
}); });
return audio; return audio;
}, },
trySkillAudio:function(skill,player,directaudio,nobroadcast/*,index*/){ /**
if(!nobroadcast) game.broadcast(game.trySkillAudio,skill,player,directaudio,nobroadcast/*,index*/); * 根据skill中的audio,audioname,audioname2和player来获取音频地址列表
var info=get.info(skill); * @param {String} skill 技能名
if(!info) return; * @param {Player|String} player 角色/角色名
if(!lib.config.background_speak) return; * @returns {Array<string|[string]>} 分析完的语音地址列表
if(info.direct&&!directaudio) return; */
if(lib.skill.global.includes(skill)&&!lib.skill[skill].forceaudio) return; parseSkillAudio:function(skill,player){
if(typeof player=='string') player={name:player}; if(typeof player=='string') player={name:player};
else if(get.itemtype(player)!='player') player={};
function getAudioList(skill,player,history,fixedNum){ /**
* 处理 audioInfo 外的参数
* @param {String} skill 技能名
* @param {Player|{name:string}} player 角色
* @param {Array<string>} audioname audioname历史
* @param {Array<string>} history 判断deadlock
* @param {Number} fixedNum [audioname, number] 中的第二个参数用来限制语音数
* @returns {Array<string|[string]>} 音频地址数组有需要playSkillAudio的为[skillname])
*/
function getAudioList(skill,player,audioname,history,fixedNum){
let info=lib.skill[skill]; let info=lib.skill[skill];
if(!info) return []; if(!info) return [];
if(!history) history=[]; if(!history) history=[];
if(history.includes(skill)){//直接跳出 if(history.includes(skill)){//判断deadlock
console.trace(`${skill} in ${history} forms a deadlock`); console.trace(`${skill} in ${history} forms a deadlock`);
if(info.audio!==false) return [[skill]];//标记为playSkillAudio if(info.audio!==false) return [[skill]];
return []; return [];
} }
history.push(skill); history.push(skill);
let audioInfo=info.audio; let audioInfo=info.audio;
if(info.audioname2&&player){ if(info.audioname2){
if(info.audioname2[player.name]) audioInfo=info.audioname2[player.name]; if(info.audioname2[player.name]) audioInfo=info.audioname2[player.name];
else if(info.audioname2[player.name1]) audioInfo=info.audioname2[player.name1]; else if(info.audioname2[player.name1]) audioInfo=info.audioname2[player.name1];
else if(info.audioname2[player.name2]) audioInfo=info.audioname2[player.name2]; else if(info.audioname2[player.name2]) audioInfo=info.audioname2[player.name2];
} }
if(typeof audioInfo=='function') audioInfo=audioInfo(player); if(typeof audioInfo=='function') audioInfo=audioInfo(player);
let audioname=''; if(!audioname) audioname=[];
if(Array.isArray(info.audioname)&&player){ if(Array.isArray(info.audioname)) audioname.addArray(info.audioname);
if(info.audioname.includes(player.name)) audioname=`_${player.name}`;
else if(info.audioname.includes(player.name1)) audioname=`_${player.name1}`;
else if(info.audioname.includes(player.name2)) audioname=`_${player.name2}`;
}
let audioList=parseAudio(skill,audioInfo,audioname,player,history,fixedNum); let audioList=parseAudio(skill,audioInfo,audioname,player,history,fixedNum);
if(fixedNum&&fixedNum<audioList.length) audioList.length=fixedNum; if(fixedNum&&fixedNum<audioList.length) audioList.length=fixedNum;
if(audioList.length) return audioList;//所有要的音频地址 if(audioList.length) return audioList;
if(info.audio!==false) return [[skill]];//标记为playSkillAudio if(info.audio!==false) return [[skill]];
return []; return [];
} }
/**
* 分析 audioInfo 获取音频地址数组
* @param {String} skill 技能名
* @param {any} audioInfo info.audio
* @param {Array<string>} audioname 要判断的audioname
* @param {Player|{name:string}} player 角色
* @param {Array<string>} history 判断deadlock
* @param {Number} fixedNum [audioname, number] 中的第二个参数用来限制语音数
* @returns {Array<string|[string]>} 音频地址数组有需要playSkillAudio的为[skillname])
*/
function parseAudio(skill,audioInfo,audioname,player,history,fixedNum){ function parseAudio(skill,audioInfo,audioname,player,history,fixedNum){
if(Array.isArray(audioInfo)){ if(Array.isArray(audioInfo)){
if(typeof audioInfo[1]=='number'/* ||(typeof audioInfo[1]=='string'&&/^\d*$/.test(audioInfo[1])) */){//['XXX',num] if(typeof audioInfo[0]=='string'&&typeof audioInfo[1]=='number'){// [audioname, number]
if(lib.skill[audioInfo[0]]) return getAudioList(audioInfo[0],player,history,fixedNum||audioInfo[1]); if(lib.skill[audioInfo[0]]) return getAudioList(audioInfo[0],player,audioname,history,fixedNum||audioInfo[1]);
return parseAudio(audioInfo[0],audioInfo[1],audioname,player,history,fixedNum||audioInfo[1]); return parseAudio(audioInfo[0],audioInfo[1],audioname,player,history,fixedNum||audioInfo[1]);
} }
return audioInfo.reduce((total,i)=>total.addArray(parseAudio(skill,i,audioname,player,history,fixedNum)),[]); return audioInfo.reduce((total,i)=>total.addArray(parseAudio(skill,i,audioname,player,history,fixedNum)),[]);
@ -36906,18 +36922,23 @@
if(!['string','number','boolean'].includes(typeof audioInfo)) return []; if(!['string','number','boolean'].includes(typeof audioInfo)) return [];
if(audioInfo===false) return []; if(audioInfo===false) return [];
if(typeof audioInfo=='string'&&lib.skill[audioInfo]) return getAudioList(audioInfo,player,history,fixedNum); if(typeof audioInfo=='string'&&lib.skill[audioInfo]) return getAudioList(audioInfo,player,audioname,history,fixedNum);
audioInfo=String(audioInfo);
let audioList=[]; let audioList=[];
audioInfo=String(audioInfo);
let list=audioInfo.match(/(?:(.*):|^)(true|\d*)(?::(.*)|$)/); let list=audioInfo.match(/(?:(.*):|^)(true|\d*)(?::(.*)|$)/);
if(list&&list[2]){ if(list&&list[2]){
list=list.slice(1);//形如[路径,number/true,格式]的形式 let _audioname='';
if(list[1]=='true') audioList.add(`${list[0]||'skill'}/${skill}${audioname}.${list[2]||'mp3'}`); if(audioname.includes(player.name)) _audioname=`_${player.name}`;
else if(audioname.includes(player.name1)) _audioname=`_${player.name1}`;
else if(audioname.includes(player.name2)) _audioname=`_${player.name2}`;
list=list.slice(1);//[路径,number/true,格式]
if(list[1]=='true') audioList.add(`${list[0]||'skill'}/${skill}${_audioname}.${list[2]||'mp3'}`);
else{ else{
list[1]=parseInt(list[1]); list[1]=parseInt(list[1]);
for(let i=1;i<=list[1];i++){ for(let i=1;i<=list[1];i++){
audioList.add(`${list[0]||'skill'}/${skill}${audioname}${i}.${list[2]||'mp3'}`); audioList.add(`${list[0]||'skill'}/${skill}${_audioname}${i}.${list[2]||'mp3'}`);
} }
} }
} }
@ -36925,8 +36946,17 @@
return audioList; return audioList;
} }
let list=getAudioList(skill,player); return getAudioList(skill,player);
// console.log(skill,lib.skill[skill]&&lib.skill[skill].audio,list); },
trySkillAudio:function(skill,player,directaudio,nobroadcast/*,index*/){
if(!nobroadcast) game.broadcast(game.trySkillAudio,skill,player,directaudio,nobroadcast/*,index*/);
var info=get.info(skill);
if(!info) return;
if(!lib.config.background_speak) return;
if(info.direct&&!directaudio) return;
if(lib.skill.global.includes(skill)&&!lib.skill[skill].forceaudio) return;
let list=game.parseSkillAudio(skill,player);
if(!list.length) return; if(!list.length) return;
// if(index) index=index%list.length||list.length; // if(index) index=index%list.length||list.length;
// let audio=list[index?index-1:Math.floor(Math.random()*list.length)]; // let audio=list[index?index-1:Math.floor(Math.random()*list.length)];