inherit,group,subSkill套娃

This commit is contained in:
kuangshen04 2023-10-02 16:40:02 +08:00
parent d04957377f
commit 21f66e784b
1 changed files with 138 additions and 129 deletions

View File

@ -26153,15 +26153,12 @@
return list; return list;
}, },
addSkillTrigger:function(skill,hidden,triggeronly){ addSkillTrigger:function(skill,hidden,triggeronly){
var info=lib.skill[skill]; let skills=game.expandSkills([skill]);
if(!info) return; for(let skill of skills){
if(typeof info.group=='string'){ let info=lib.skill[skill];
this.addSkillTrigger(info.group,hidden); if(!info){
} console.trace(`Cannot find skill: ${skill}\nPlease check if game.expandSkills is overwritten`);
else if(Array.isArray(info.group)){ continue;
for(var i=0;i<info.group.length;i++){
this.addSkillTrigger(info.group[i],hidden);
}
} }
if(!triggeronly){ if(!triggeronly){
if(info.global&&(!hidden||info.globalSilent)){ if(info.global&&(!hidden||info.globalSilent)){
@ -26169,20 +26166,18 @@
game.addGlobalSkill(info.global,this); game.addGlobalSkill(info.global,this);
} }
else{ else{
for(var j=0;j<info.global.length;j++){ for(let j=0;j<info.global.length;j++){
game.addGlobalSkill(info.global[j],this); game.addGlobalSkill(info.global[j],this);
} }
} }
} }
if(this.initedSkills.contains(skill)) return this; if(this.initedSkills.contains(skill)) return this;
this.initedSkills.push(skill); this.initedSkills.push(skill);
if(info.init&&!_status.video){ if(info.init&&!_status.video) info.init(this,skill);
info.init(this,skill);
}
} }
if(info.trigger&&this.playerid){ if(info.trigger&&this.playerid){
var playerid=this.playerid; let playerid=this.playerid;
var setTrigger=function(i,evt){ let setTrigger=function(i,evt){
if(i=='global'){ if(i=='global'){
if(!lib.hook.globaltrigger[evt]){ if(!lib.hook.globaltrigger[evt]){
lib.hook.globaltrigger[evt]={}; lib.hook.globaltrigger[evt]={};
@ -26193,32 +26188,25 @@
lib.hook.globaltrigger[evt][playerid].add(skill); lib.hook.globaltrigger[evt][playerid].add(skill);
} }
else{ else{
var name=playerid+'_'+i+'_'+evt; let name=playerid+'_'+i+'_'+evt;
if(!lib.hook[name]){ if(!lib.hook[name]) lib.hook[name]=[];
lib.hook[name]=[];
}
lib.hook[name].add(skill); lib.hook[name].add(skill);
} }
lib.hookmap[evt]=true; lib.hookmap[evt]=true;
} }
for(var i in info.trigger){ for(let i in info.trigger){
if(typeof info.trigger[i]=='string'){ if(typeof info.trigger[i]=='string') setTrigger(i,info.trigger[i]);
setTrigger(i,info.trigger[i]);
}
else if(Array.isArray(info.trigger[i])){ else if(Array.isArray(info.trigger[i])){
for(var j=0;j<info.trigger[i].length;j++){ for(let trigger of info.trigger[i]) setTrigger(i,trigger);
setTrigger(i,info.trigger[i][j]);
}
} }
} }
} }
if(info.hookTrigger){ if(info.hookTrigger){
if(!this._hookTrigger){ if(!this._hookTrigger) this._hookTrigger=[];
this._hookTrigger=[];
}
this._hookTrigger.add(skill); this._hookTrigger.add(skill);
} }
if(_status.event&&_status.event.addTrigger) _status.event.addTrigger(skill,this); if(_status.event&&_status.event.addTrigger) _status.event.addTrigger(skill,this);
}
return this; return this;
}, },
addSkillLog:function(skill){ addSkillLog:function(skill){
@ -26506,22 +26494,19 @@
return this; return this;
}, },
removeSkillTrigger:function(skill,triggeronly){ removeSkillTrigger:function(skill,triggeronly){
var info=lib.skill[skill]; let skills=game.expandSkills([skill]);
if(!info) return; for(let skill of skills){
if(typeof info.group=='string'){ let info=lib.skill[skill];
this.removeSkillTrigger(info.group); if(!info){
} console.trace(`Cannot find skill: ${skill}\nPlease check if game.expandSkills is overwritten`);
else if(Array.isArray(info.group)){ continue;
for(var i=0;i<info.group.length;i++){
this.removeSkillTrigger(info.group[i]);
}
} }
if(!triggeronly) this.initedSkills.remove(skill); if(!triggeronly) this.initedSkills.remove(skill);
if(info.trigger){ if(info.trigger){
var playerid=this.playerid; let playerid=this.playerid;
var removeTrigger=function(i,evt){ let removeTrigger=function(i,evt){
if(i=='global'){ if(i=='global'){
for(var j in lib.hook.globaltrigger){ for(let j in lib.hook.globaltrigger){
if(lib.hook.globaltrigger[j][playerid]){ if(lib.hook.globaltrigger[j][playerid]){
lib.hook.globaltrigger[j][playerid].remove(skill); lib.hook.globaltrigger[j][playerid].remove(skill);
if(lib.hook.globaltrigger[j][playerid].length==0){ if(lib.hook.globaltrigger[j][playerid].length==0){
@ -26534,31 +26519,24 @@
} }
} }
else{ else{
var name=playerid+'_'+i+'_'+evt; let name=playerid+'_'+i+'_'+evt;
if(lib.hook[name]){ if(lib.hook[name]){
lib.hook[name].remove(skill); lib.hook[name].remove(skill);
if(lib.hook[name].length==0){ if(lib.hook[name].length==0) delete lib.hook[name];
delete lib.hook[name];
} }
} }
} }
} for(let i in info.trigger){
for(var i in info.trigger){ if(typeof info.trigger[i]=='string') removeTrigger(i,info.trigger[i]);
if(typeof info.trigger[i]=='string'){
removeTrigger(i,info.trigger[i]);
}
else if(Array.isArray(info.trigger[i])){ else if(Array.isArray(info.trigger[i])){
for(var j=0;j<info.trigger[i].length;j++){ for(let trigger of info.trigger[i]) removeTrigger(i,trigger);
removeTrigger(i,info.trigger[i][j]);
}
} }
} }
} }
if(info.hookTrigger){ if(info.hookTrigger){
if(this._hookTrigger){ if(this._hookTrigger){
this._hookTrigger.remove(skill); this._hookTrigger.remove(skill);
if(!this._hookTrigger.length){ if(!this._hookTrigger.length) delete this._hookTrigger;
delete this._hookTrigger;
} }
} }
} }
@ -40194,7 +40172,7 @@
if(drawDeck&&drawDeck.drawDeck) players[0].draw(num2,drawDeck); if(drawDeck&&drawDeck.drawDeck) players[0].draw(num2,drawDeck);
else players[0].draw(num2); else players[0].draw(num2);
}, },
finishSkill:(i,sub)=>{ finishSkill:(i,history)=>{
const mode=get.mode(),info=lib.skill[i],iInfo=`${i}_info`; const mode=get.mode(),info=lib.skill[i],iInfo=`${i}_info`;
if(info.alter){ if(info.alter){
lib.translate[`${iInfo}_origin`]=lib.translate[iInfo]; lib.translate[`${iInfo}_origin`]=lib.translate[iInfo];
@ -40237,14 +40215,25 @@
}); });
} }
if(info.inherit){ if(info.inherit){
const skill=lib.skill[info.inherit]; var inheritHistory=[];
if(skill) Object.keys(skill).forEach(value=>{ while(true){
if(!info.inherit) break;
if(inheritHistory.includes(info.inherit)){
console.trace(`Inherit Error: ${info.inherit} in ${i}'s inherit forms a deadlock`);
break;
}
inheritHistory.push(info.inherit);
const inheritInfo=lib.skill[info.inherit];
if(inheritInfo) Object.keys(inheritInfo).forEach(value=>{
if(info[value]!=undefined) return; if(info[value]!=undefined) return;
if(value=='audio'&&(typeof info[value]=='number'||typeof info[value]=='boolean')) info[value]=info.inherit; if(value=='audio'&&(typeof info[value]=='number'||typeof info[value]=='boolean')) info[value]=info.inherit;
else info[value]=skill[value]; else info[value]=inheritInfo[value];
}); });
if(lib.translate[i]==undefined) lib.translate[i]=lib.translate[info.inherit]; if(lib.translate[i]==undefined) lib.translate[i]=lib.translate[info.inherit];
if(lib.translate[iInfo]==undefined) lib.translate[iInfo]=lib.translate[`${info.inherit}_info`]; if(lib.translate[`${i}_info`]==undefined) lib.translate[`${i}_info`]=lib.translate[`${info.inherit}_info`];
if(!inheritInfo||!inheritInfo.inherit) info.inherit=void 0;
}
} }
if(info.limited){ if(info.limited){
if(info.mark===undefined) info.mark=true; if(info.mark===undefined) info.mark=true;
@ -40253,7 +40242,16 @@
if(info.skillAnimation===undefined) info.skillAnimation=true; if(info.skillAnimation===undefined) info.skillAnimation=true;
if(info.init===undefined) info.init=(player,skill)=>player.storage[skill]=false; if(info.init===undefined) info.init=(player,skill)=>player.storage[skill]=false;
} }
if(info.subSkill&&!sub) Object.keys(info.subSkill).forEach(value=>{ if(info.subSkill){
let subSkillHistory=Array.isArray(history)?history:[];
for(let value in info.subSkill){
if(subSkillHistory.includes(value)){
console.trace(`SubSkill Error: ${value} in ${i} forms a deadlock`);
continue;
}
let history=subSkillHistory.slice(0);
history.push(value);
const iValue=`${i}_${value}`; const iValue=`${i}_${value}`;
lib.skill[iValue]=info.subSkill[value]; lib.skill[iValue]=info.subSkill[value];
lib.skill[iValue].sub=true; lib.skill[iValue].sub=true;
@ -40261,8 +40259,9 @@
else lib.translate[iValue]=lib.translate[iValue]||lib.translate[i]; else lib.translate[iValue]=lib.translate[iValue]||lib.translate[i];
if(info.subSkill[value].description) lib.translate[`${iValue}_info`]=info.subSkill[value].description; if(info.subSkill[value].description) lib.translate[`${iValue}_info`]=info.subSkill[value].description;
if(info.subSkill[value].marktext) lib.translate[`${iValue}_bg`]=info.subSkill[value].marktext; if(info.subSkill[value].marktext) lib.translate[`${iValue}_bg`]=info.subSkill[value].marktext;
game.finishSkill(iValue,true); game.finishSkill(iValue,history);
}); }
}
if(info.round){ if(info.round){
const k=`${i}_roundcount`; const k=`${i}_roundcount`;
if(typeof info.group=='string') info.group=[info.group,k]; if(typeof info.group=='string') info.group=[info.group,k];
@ -41165,15 +41164,25 @@
if(!player.storage.skill_blocker||!player.storage.skill_blocker.length) return out; if(!player.storage.skill_blocker||!player.storage.skill_blocker.length) return out;
return out.filter(value=>exclude&&exclude.includes(value)||!get.is.blocked(value,player)); return out.filter(value=>exclude&&exclude.includes(value)||!get.is.blocked(value,player));
}, },
expandSkills:skills=>skills.addArray(skills.reduce((previousValue,currentValue)=>{ expandSkills:(skill,oldHistory)=>{
const info=get.info(currentValue); let history=[];
if(info){ if(oldHistory) history.addArray(oldHistory);
if(Array.isArray(info.group)) previousValue.push(...info.group); if(Array.isArray(skill)){
else if(info.group) previousValue.push(info.group); return skill.reduce((previous,current)=>previous.addArray(game.expandSkills(current,history)),[]);
} }
else console.log(currentValue);
return previousValue; let info=get.info(skill);
},[])), if(!info){
console.trace(`Cannot find skill: ${skill}`);
return history;
}
history.add(skill);
if(info.group){
let group=Array.isArray(info.group)?info.group:[info.group];
history.addArray(game.expandSkills([].addArray(group.filter(skill=>!history.includes(skill))),history));
}
return history;
},
css:style=>Object.keys(style).forEach(value=>{ css:style=>Object.keys(style).forEach(value=>{
let uiStyle=ui.style[value]; let uiStyle=ui.style[value];
if(!uiStyle){ if(!uiStyle){