优化孙翎鸾AI,新增临时缓存函数
This commit is contained in:
parent
c1941a7531
commit
fe08161875
|
@ -128,6 +128,59 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
|||
var source=player.storage.dcpandi_effect;
|
||||
return get.itemtype(source)!='player'||!source.isIn();
|
||||
},
|
||||
pandi_wrapKey:function(){
|
||||
var str = "";
|
||||
for(var arg of arguments){
|
||||
if(arg === null || arg === undefined){
|
||||
str += (arg + "-");
|
||||
continue;
|
||||
}
|
||||
switch(get.itemtype(arg)){
|
||||
case 'player':
|
||||
str+=("p:"+arg.playerid);
|
||||
break;
|
||||
case 'card':
|
||||
if(arg.cardid){
|
||||
str+=("c:"+arg.cardid);
|
||||
}else{
|
||||
str+=("c:"+arg.name);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
str+=("n:"+arg);
|
||||
break;
|
||||
}
|
||||
str+="-";
|
||||
}
|
||||
return str;
|
||||
},
|
||||
pandi_effect:function(target,card,player,viewer){
|
||||
if(!_status.event)return get.effect(target,card,player,viewer);
|
||||
var key = lib.skill.dcpandi.pandi_wrapKey.apply(null,arguments);
|
||||
var effect = _status.event.getTempCache('effect',key);
|
||||
if(effect !== undefined)return effect;
|
||||
effect = get.effect(target,card,player,viewer);
|
||||
_status.event.putTempCache('effect',key,effect);
|
||||
return effect;
|
||||
},
|
||||
pandi_canUse:function(player,card,target,arg1,arg2){
|
||||
if(!_status.event)return player.canUse(card,target,arg1,arg2);
|
||||
var key = lib.skill.dcpandi.pandi_wrapKey.apply(null,arguments);
|
||||
var effect = _status.event.getTempCache('canUse',key);
|
||||
if(effect !== undefined)return effect;
|
||||
effect = player.canUse(card,target,arg1,arg2);
|
||||
_status.event.putTempCache('canUse',key,effect);
|
||||
return effect;
|
||||
},
|
||||
pandi_effect_use:function(target,card,player,viewer){
|
||||
if(!_status.event)return get.effect_use(target,card,player,viewer);
|
||||
var key = lib.skill.dcpandi.pandi_wrapKey.apply(null,arguments);
|
||||
var effect = _status.event.getTempCache('effect_use',key);
|
||||
if(effect !== undefined)return effect;
|
||||
effect = get.effect_use(target,card,player,viewer);
|
||||
_status.event.putTempCache('effect_use',key,effect);
|
||||
return effect;
|
||||
},
|
||||
onChooseToUse:function(event){
|
||||
if(!game.online&&event.type=='phase'){
|
||||
var players=game.filterPlayer(function(current){
|
||||
|
@ -162,15 +215,32 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
|||
if(typeof(card)=='string'){
|
||||
card={name:card,isCard:true};
|
||||
}
|
||||
var key = lib.skill.dcpandi.pandi_wrapKey(card,player,viewer);
|
||||
if(_status.event){
|
||||
var uv = _status.event.getTempCache('getUseValue',key);
|
||||
if(uv!==undefined){
|
||||
return uv;
|
||||
}
|
||||
}
|
||||
var targets=game.filterPlayer();
|
||||
var value=[];
|
||||
var min=0;
|
||||
var info=get.info(card);
|
||||
if(!info||info.notarget) return 0;
|
||||
if(!info||info.notarget){
|
||||
if(_status.event){
|
||||
_status.event.putTempCache('getUseValue',key,0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
var range;
|
||||
var select=get.copy(info.selectTarget);
|
||||
if(select==undefined){
|
||||
if(info.filterTarget==undefined) return true;
|
||||
if(info.filterTarget==undefined) {
|
||||
if(_status.event){
|
||||
_status.event.putTempCache('getUseValue',key,true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
range=[1,1];
|
||||
}
|
||||
else if(typeof select=='number') range=[select,select];
|
||||
|
@ -178,11 +248,16 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
|||
else if(typeof select=='function') range=select(card,player);
|
||||
if(info.singleCard) range=[1,1];
|
||||
game.checkMod(card,player,range,'selectTarget',player);
|
||||
if(!range) return 0;
|
||||
if(!range){
|
||||
if(_status.event){
|
||||
_status.event.putTempCache('getUseValue',key,0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(var i=0;i<targets.length;i++){
|
||||
if(player.canUse(card,targets[i],null,true)){
|
||||
var eff=get.effect(targets[i],card,player,viewer);
|
||||
if(lib.skill.dcpandi.pandi_canUse(player,card,targets[i],null,true)){
|
||||
var eff=lib.skill.dcpandi.pandi_effect(targets[i],card,player,viewer);
|
||||
value.push(eff);
|
||||
}
|
||||
}
|
||||
|
@ -193,6 +268,9 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
|||
if(i==range[1]||range[1]!=-1&&value[i]<=0) break;
|
||||
min+=value[i];
|
||||
}
|
||||
if(_status.event){
|
||||
_status.event.putTempCache('getUseValue',key,min);
|
||||
}
|
||||
return min;
|
||||
},
|
||||
subSkill:{
|
||||
|
@ -223,7 +301,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
|||
if(typeof card!='object') return;
|
||||
var source=player.storage.dcpandi_effect;
|
||||
if(!source.isIn()||get.itemtype(source)!='player'||get.itemtype(source.storage.dcpandi_effect)=='player') return;
|
||||
return [0,get.effect_use(target,card,source,player),0,get.effect(target,card,source,target)]
|
||||
return [0,lib.skill.dcpandi.pandi_effect_use(target,card,source,player),0,lib.skill.dcpandi.pandi_effect(target,card,source,target)]
|
||||
},
|
||||
},
|
||||
mod:{
|
||||
|
|
19
game/game.js
19
game/game.js
|
@ -27380,6 +27380,25 @@
|
|||
finish:function(){
|
||||
this.finished=true;
|
||||
},
|
||||
putTempCache:function(key1,key2,value){
|
||||
if(!this._tempCache){
|
||||
this._tempCache = {};
|
||||
}
|
||||
if(!this._tempCache[key1]){
|
||||
this._tempCache[key1] = {};
|
||||
}
|
||||
this._tempCache[key1][key2] = value;
|
||||
console.log("put:"+key1+" "+key2+" "+value);
|
||||
},
|
||||
getTempCache:function(key1,key2){
|
||||
if(!this._tempCache){
|
||||
return undefined;
|
||||
}
|
||||
if(!this._tempCache[key1]){
|
||||
return undefined;
|
||||
}
|
||||
return this._tempCache[key1][key2];
|
||||
},
|
||||
cancel:function(arg1,arg2,notrigger){
|
||||
this.untrigger.call(this,arguments);
|
||||
this.finish();
|
||||
|
|
Loading…
Reference in New Issue