From 2cf397da7fae744eca128d169b9ec7ca27a6650d Mon Sep 17 00:00:00 2001 From: shijian <2954700422@qq.com> Date: Thu, 26 Oct 2023 11:21:30 +0800 Subject: [PATCH] =?UTF-8?q?player.when=E6=96=B0=E5=A2=9Evars=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=EF=BC=8C=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8Dthen?= =?UTF-8?q?=E4=B8=AD=E7=AE=AD=E5=A4=B4=E5=87=BD=E6=95=B0=E4=B8=8D=E5=B8=A6?= =?UTF-8?q?=E5=A4=A7=E6=8B=AC=E5=8F=B7=E6=8A=A5=E9=94=99=E6=88=91=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/game.js | 70 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/game/game.js b/game/game.js index 8c7d2e753..a44bc4503 100644 --- a/game/game.js +++ b/game/game.js @@ -20741,7 +20741,7 @@ this.markSkill('stratagem_fury'); } /** - * version 1.4 + * version 1.6 * * 链式创建一次性技能的api。 * @@ -20779,7 +20779,7 @@ //triggerNames = [ 'xxAfter', 'yyBegin' ] if(triggerNames.every(t=>typeof t=='string')) trigger={player:triggerNames}; //triggerNames = [ {player: 'xxAfter'}, {global: 'yyBegin'} ] - //此处不做特殊的合并处理,由使用者自行把握 + //此处不做特殊的合并处理,由使用者自行把握,同名属性后者覆盖前者 else if(triggerNames.every(t=>get.is.object(t))) trigger=triggerNames.reduce((pre,cur)=>Object.assign(pre,cur)); } if(!trigger) throw 'player.when传参数类型错误:'+triggerNames; @@ -20787,12 +20787,13 @@ do{ skillName='player_when_'+Math.random().toString(36).slice(-8); }while(lib.skill[skillName]!=null); - let after=`${skillName}After`; + const after=`${skillName}After`; if(!trigger.player) trigger.player=after; else if(Array.isArray(trigger.player)) trigger.player.add(after); else if(typeof trigger.player=='string') trigger.player=[trigger.player,after]; + const vars={}; let skill={ - trigger, + trigger:trigger, forced:true, charlotte:true, popup:false, @@ -20801,6 +20802,10 @@ //充分条件 filter2Funs:[], contentFuns:[], + //外部变量 + get vars() { + return vars; + }, get filter(){ return (event,player,name)=>{ if(name==`${skillName}After`){ @@ -20818,6 +20823,35 @@ }; } }; + const warnVars=['event','step','source','player','target','targets', + 'card','cards','skill','forced','num','trigger','result']; + const errVars=['_status','lib','game','ui','get','ai']; + const createContent=()=>{ + let varstr=''; + for (const key in vars) { + if(warnVars.includes(key)) console.warn(`Variable '${key}' should not be referenced by vars objects`); + if(errVars.includes(key)) throw new Error(`Variable '${key}' should not be referenced by vars objects`); + varstr+=`var ${key}=lib.skill['${skillName}'].vars['${key}'];\n`; + } + let str=` + function content(){ + ${varstr}if(event.triggername=='${skillName}After'){ + player.removeSkill('${skillName}'); + delete lib.skill['${skillName}']; + delete lib.translate['${skillName}']; + return event.finish(); + } + `; + for(let i=0;ixxx的情况 + const begin=a.indexOf("{")==a.indexOf("}")&&a.indexOf("{")==-1?a.indexOf("=>")+2:a.indexOf("{")+1; + const str2=a.slice(begin,a.lastIndexOf("}")!=-1?a.lastIndexOf("}"):undefined).trim(); + str+=`'step ${i}'\n\t${str2}\n\t`; + } + skill.content=eval(str+`\n};content;`); + }; Object.defineProperty(lib.skill,skillName,{ configurable:true, //这类技能不需要被遍历到 @@ -20834,6 +20868,7 @@ forced:true, charlotte:true, popup:false, + vars:{}, } }); },skillName); @@ -20863,23 +20898,7 @@ then(fun){ if(lib.skill[skillName]!=skill) throw `This skill has been destroyed`; skill.contentFuns.push(fun); - let str=` - function content(){ - if(event.triggername=='${skillName}After'){ - player.removeSkill('${skillName}'); - delete lib.skill['${skillName}']; - delete lib.translate['${skillName}']; - return event.finish(); - } - `; - for(let i=0;i