Optimize code and fix more bugs.

This commit is contained in:
Tipx-L 2023-10-23 20:13:00 -07:00
parent 661813cdc8
commit f976299a0e
2 changed files with 157 additions and 138 deletions

View File

@ -625,7 +625,9 @@
['sha',event=>{
if(event.step!=1) return;
game.log(event.player,'触发了强化效果');
game.log(event.card,'抵消所需要的',`#y【${get.translation('shan')}`,'数+1');
game.log(event.card,'抵消所需要的',new lib.element.VCard({
name:'shan'
}),'数+1');
const map=event.customArgs;
game.players.concat(game.dead).forEach(current=>{
const id=current.playerid;
@ -637,8 +639,12 @@
['shan',event=>{
if(event.step!=1) return;
game.log(event.player,'触发了强化效果');
game.log(event.card,'视为两张',`#y【${get.translation('shan')}`,'的效果');
event.getParent(2).decrease('shanRequired',1);
game.log('使用',event.card,'时视为两张',new lib.element.VCard({
name:'shan'
}),'的效果');
event.player.when('useCard').filter(evt=>evt==event).then(()=>{
trigger.getParent(2).decrease('shanRequired',1);
});
}],
['juedou',event=>{
if(event.step!=1) return;
@ -25344,55 +25350,37 @@
return next;
}
damage(){
var next=game.createEvent('damage');
const next=game.createEvent('damage');
//next.forceDie=true;
next.player=this;
var nocard,nosource;
var event=_status.event;
for(var i=0;i<arguments.length;i++){
if(get.itemtype(arguments[i])=='cards'){
next.cards=arguments[i].slice(0);
}
else if(get.itemtype(arguments[i])=='card'){
next.card=arguments[i];
}
else if(typeof arguments[i]=='number'){
next.num=arguments[i];
}
else if(get.itemtype(arguments[i])=='player'){
next.source=arguments[i];
}
else if(typeof arguments[i]=='object'&&arguments[i]&&arguments[i].name){
next.card=arguments[i];
}
else if(arguments[i]=='nocard'){
nocard=true;
}
else if(arguments[i]=='nosource'){
nosource=true;
}
else if(arguments[i]=='notrigger'){
let noCard,noSource;
const event=_status.event;
for(const argument of arguments){
if(get.itemtype(argument)=='cards') next.cards=argument.slice();
else if(get.itemtype(argument)=='card') next.card=argument;
else if(typeof argument=='number') next.num=argument;
else if(get.itemtype(argument)=='player') next.source=argument;
else if(argument&&typeof argument=='object'&&argument.name) next.card=argument;
else if(argument=='nocard') noCard=true;
else if(argument=='nosource') noSource=true;
else if(argument=='notrigger'){
next._triggered=null;
next.notrigger=true;
}
else if(arguments[i]=='unreal'){
next.unreal=true
}
else if(get.itemtype(arguments[i])=='nature'&&arguments[i]!='stab'){
next.nature=arguments[i];
}
else if(get.itemtype(arguments[i])=='natures'){
var natures=arguments[i].split(lib.natureSeparator);
natures.remove('stab');
else if(argument=='unreal') next.unreal=true;
else if(get.itemtype(argument)=='nature'&&argument!='stab') next.nature=argument;
else if(get.itemtype(argument)=='natures'){
const natures=argument.split(lib.natureSeparator).remove('stab');
if(natures.length) next.nature=natures.join(lib.natureSeparator);
}
}
if(next.card==undefined&&!nocard) next.card=event.card;
if(next.cards==undefined&&!nocard) next.cards=event.cards;
if(next.source==undefined&&!nosource) next.source=event.customSource||event.player;
if(next.source&&next.source.isDead()) delete next.source;
if(next.unreal==undefined) next.unreal=false;
if(next.num==undefined) next.num=(event.baseDamage||1)+(event.extraDamage||0);
if(!next.card&&!noCard) next.card=event.card;
if(!next.cards&&!noCard) next.cards=event.cards;
if(!next.source&&!noSource){
const source=event.customSource||event.player;
if(source&&!source.isDead()) next.source=source;
}
if(typeof next.num!='number') next.num=(event.baseDamage||1)+(event.extraDamage||0);
next.original_num=next.num;
next.change_history=[];
next.hasNature=function(nature){
@ -30882,6 +30870,9 @@
}
return this;
}
/**
* @param {ArrayLike<Function> | Function | keyof typeof lib.element.content} item
*/
setContent(item){
switch(typeof item){
case "object":
@ -31500,6 +31491,7 @@
}
/**
* @throws {'Do not call this method'}
* @returns {never}
*/
typeAnnotation(){
/**
@ -31546,6 +31538,34 @@
* @type {Record<string, any>}
*/
this._result;
/**
* @type {number}
*/
this.baseDamage;
/**
* @type {Player}
*/
this.customSource;
/**
* @type {number}
*/
this.extraDamage;
/**
* @type {string}
*/
this.nature;
/**
* @type {boolean}
*/
this.notrigger;
/**
* @type {number}
*/
this.original_num;
/**
* @type {boolean}
*/
this.unreal;
throw 'Do not call this method';
}
},
@ -53988,9 +54008,8 @@
list2.push(list2[0]);
for(var i=0;i<list2.length;i++){
if(this.firstChild.innerHTML==list[list2[i]]){
var identity=list2[i+1];
this.firstChild.innerHTML=list[identity];
this.dataset.color=identity=='you'?'friend2':(identity=='di'?'enemy':identity);
this.firstChild.innerHTML=list[list2[i+1]];
this.dataset.color=list2[i+1];
break;
}
}
@ -54044,7 +54063,7 @@
node.listen(function(){
var info=this.link;
info[0].firstChild.innerHTML=info[1];
info[0].dataset.color=info[2]=='you'?'friend2':(info[2]=='di'?'enemy':info[2]);
info[0].dataset.color=info[2];
_status.clicked=false;
});
}
@ -58091,8 +58110,8 @@
},
/**
* 判断传入的参数的属性是否相同参数可以为卡牌卡牌信息属性等
* @param ...infos 要判断的属性列表
* @param every {boolean} 是否判断每一个传入的属性是否完全相同而不是存在部分相同
* @param {...} infos 要判断的属性列表
* @param {boolean} every 是否判断每一个传入的属性是否完全相同而不是存在部分相同
*/
sameNature(){
let processedArguments=[],every=false;
@ -61930,7 +61949,7 @@
var event=_status.event;
var eventskill=null;
if(player==undefined) player=_status.event.player;
if(typeof card=='object') card=get.autoViewAs(card);
if(card&&typeof card=='object'&&'name' in card) card=get.autoViewAs(card);
if(typeof card!='string'&&(typeof card!='object'||!card.name)){
var skillinfo=get.info(event.skill);
if(event.skill&&skillinfo.viewAs==undefined) card=_status.event.skill;
@ -62125,7 +62144,7 @@
var event=_status.event;
var eventskill=null;
if(player==undefined) player=_status.event.player;
if(typeof card=='object') card=get.autoViewAs(card);
if(card&&typeof card=='object'&&'name' in card) card=get.autoViewAs(card);
if(typeof card!='string'&&(typeof card!='object'||!card.name)){
var skillinfo=get.info(event.skill);
if(event.skill&&skillinfo.viewAs==undefined) card=_status.event.skill;
@ -62545,7 +62564,7 @@
}
}
},
get:get
get
};
/**
* @template T

View File

@ -1271,7 +1271,7 @@ game.import('mode',function(lib,game,ui,get,ai,_status){
['stratagem_gain','stratagem_insight','stratagem_expose'].forEach(globalSkill=>game.addGlobalSkill(globalSkill));
game.players.forEach(current=>{
current.storage.zhibi=[];
current.storage.zhibi_for=[];
current.storage.stratagem_expose=[];
current.markSkill('stratagem_fury');
});
@ -2085,7 +2085,7 @@ game.import('mode',function(lib,game,ui,get,ai,_status){
['stratagem_gain','stratagem_insight','stratagem_expose'].forEach(globalSkill=>game.addGlobalSkill(globalSkill));
game.players.forEach(i=>{
i.storage.zhibi=[];
i.storage.zhibi_for=[];
i.storage.stratagem_expose=[];
i.markSkill('stratagem_fury');
});
}
@ -3159,9 +3159,9 @@ game.import('mode',function(lib,game,ui,get,ai,_status){
if(num){
return x/num;
}
var real=get.realAttitude(from,to),zhibi=from.storage.zhibi,zhibi_for=from.storage.zhibi_for,followCamouflage=true;
var real=get.realAttitude(from,to),zhibi=from.storage.zhibi,stratagem_expose=from.storage.stratagem_expose,followCamouflage=true;
if(to.ai.shown) return to.ai.shown*(real+(from.identity==to.identity||from.identity=='zhu'&&to.identity=='zhong'||from.identity=='zhong'&&to.identity=='zhu'||(to.identity=='nei'&&get.situation()<=0&&['zhu','zhong'].contains(from.identity)||get.situation()>=3&&from.identity=='fan')?3:-3))
if(from==to||to.identityShown||((zhibi_for&&zhibi_for.contains(to))||(zhibi&&zhibi.contains(to)))&&!to.ai.stratagemCamouflage) return real*1.1;
if(from==to||to.identityShown||((stratagem_expose&&stratagem_expose.contains(to))||(zhibi&&zhibi.contains(to)))&&!to.ai.stratagemCamouflage) return real*1.1;
if(from.identity=='nei'&&to.ai.stratagemCamouflage) return real*1.1;
if(to.identity=='nei'){
if(from.identity=='fan'){
@ -3170,7 +3170,7 @@ game.import('mode',function(lib,game,ui,get,ai,_status){
var dead=game.dead.slice();
for(var current of dead){
if(from.storage.zhibi.contains(current)&&current.ai.stratagemCamouflage){
if(from.storage.zhibi_for&&from.storage.zhibi_for.contains(to)) return -7;
if(from.storage.stratagem_expose&&from.storage.stratagem_expose.contains(to)) return -7;
}
}
if(zhibi.contains(to)) return 3;
@ -3181,7 +3181,7 @@ game.import('mode',function(lib,game,ui,get,ai,_status){
if(to.identity=='fan'&&from.identity=='nei'&&zhibi.contains(game.zhu)&&game.players.filter(i=>i!=from&&!zhibi.contains(i)).map(i=>i.identity).reduce((p,c)=>(!p.contains(c)?(p.push(c)&&p):p),[]).length==1) return real;
for(var fan of game.dead){
if(fan.identity!='fan'||!fan.storage.stratagem_revitalization) continue;
for(var current of fan.storage.zhibi_for){
for(var current of fan.storage.stratagem_expose){
if(to==current){
return real;
}
@ -3191,26 +3191,26 @@ game.import('mode',function(lib,game,ui,get,ai,_status){
if(from.ai.stratagemCamouflage){
var zhu=game.zhu&&game.zhu.isZhu&&game.zhu.identityShown?game.zhu:undefined;
if(zhu){
if(zhu.storage.zhibi_for&&zhu.storage.zhibi_for.contains(to)) return 0;
if(zhu.storage.stratagem_expose&&zhu.storage.stratagem_expose.contains(to)) return 0;
}
if(zhibi&&zhibi.contains(to)) return -7;
}
if(to.ai.stratagemCamouflage){
var zhu=game.zhu&&game.zhu.isZhu&&game.zhu.identityShown?game.zhu:undefined;
if(zhu){
if(zhu.storage.zhibi_for&&zhu.storage.zhibi_for.contains(to)) return 0;
if(zhu.storage.stratagem_expose&&zhu.storage.stratagem_expose.contains(to)) return 0;
}
if(zhibi&&zhibi.contains(to)) return -7;
}
}
if(from.identity!='nei'&&zhibi&&zhibi.contains(to)&&!to.identityShown&&(followCamouflage&&to.ai.stratagemCamouflage)) return -5;
if(from.identity!='nei'&&zhibi_for&&zhibi_for.contains(to)&&!to.identityShown) return -5;
if(from.identity!='nei'&&stratagem_expose&&stratagem_expose.contains(to)&&!to.identityShown) return -5;
if(zhibi){
for(var to2 of zhibi){
if(to2.storage.zhibi_for){
if(to2.storage.stratagem_expose){
if(to2.ai.stratagemCamouflage){
for(var to3 of to2.storage.zhibi_for){
if(zhibi.slice().addArray(zhibi_for).contains(to3)){
for(var to3 of to2.storage.stratagem_expose){
if(zhibi.slice().addArray(stratagem_expose).contains(to3)){
if(to==to2){
return real;
}
@ -3219,8 +3219,8 @@ game.import('mode',function(lib,game,ui,get,ai,_status){
}
}
}else{
for(var to3 of to2.storage.zhibi_for){
if(!zhibi.slice().addArray(zhibi_for).contains(to3)&&to==to3){
for(var to3 of to2.storage.stratagem_expose){
if(!zhibi.slice().addArray(stratagem_expose).contains(to3)&&to==to3){
return get.rawAttitude(to3,to)*Math.sign(real);
}
}
@ -3708,36 +3708,37 @@ game.import('mode',function(lib,game,ui,get,ai,_status){
stratagem_insight:{
trigger:{
source:'damageSource',
global:'loseHpEnd',
global:'loseHpEnd'
},
filter:function(event,player){
if(event.player.identityShown) return false;
var source=event.source;
filter:(event,player)=>{
if(!player.storage.stratagem_fury) return false;
const target=event.player;
if(target==player||!target.isIn()||target.identityShown) return false;
let source=event.source;
if(event.name=='loseHp'){
if(event.getParent()._trigger) source=event.getParent()._trigger.source;
const trigger=event.getParent()._trigger;
if(trigger) source=trigger.source;
}
return player==source&&player.storage.stratagem_fury>0&&event.player&&event.player.isIn()&&event.player!=player;
return player==source;
},
logTarget:'player',
prompt2:function(event,player){
return '消耗1点怒气洞察'+get.translation(event.player)+'的身份';
},
check:function(event,player){
if(player.storage.zhibi&&player.storage.zhibi.contains(event.player)||player.storage.zhibi_for&&player.storage.zhibi_for.contains(event.player)) return false;
prompt2:event=>`消耗1点怒气洞察${get.translation(event.player)}的身份`,
check:(event,player)=>{
const storage=player.storage,zhibi=storage.zhibi;
if(zhibi&&zhibi.includes(event.player)) return false;
const stratagemExpose=storage.stratagem_expose;
if(stratagemExpose&&stratagemExpose.includes(event.player)) return false;
if(get.population('zhong')==0&&player.identity=='fan') return false;
return Math.abs(get.attitude(player,event.player))<=1;
},
content:function(){
content:()=>{
player.changeFury(-1,true);
player.insightInto(trigger.player);
},
ai:{
order:15,
}
},
stratagem_monarchy:{
trigger:{
player:['dying','phaseBefore'],
player:['dying','phaseZhunbeiBegin'],
global:'dieAfter',
},
forced:true,
@ -3748,54 +3749,46 @@ game.import('mode',function(lib,game,ui,get,ai,_status){
silent:true,
charlotte:true,
ruleSkill:true,
filter:function(event,player){
if(player.storage.stratagem_monarchy) return false;
if(player.identity=='zhu'){
if(event.player==player){
if(event.name=='dying') return true;
return game.roundNumber>=Math.max(Math.round(get.population()/2),3);
}
if(event.name=='die') return game.dead.length>=Math.max(Math.round(get.population()/3),2);
}
return false;
filter:(event,player,name)=>{
if(player.storage.stratagem_monarchy||player.identity!='zhu') return false;
if(name=='dieAfter') return game.dead.length>=Math.max(Math.round(get.population()/3),2);
return name=='dying'||game.roundNumber>=Math.max(Math.round(get.population()/2),3);
},
content:function(){
content:()=>{
'step 0'
if(trigger.name=='dying') game.delayx();
if(event.triggername=='dying') game.delayx();
'step 1'
player.storage.stratagem_monarchy=true;
game.zhu=game.zhu||player;
game.broadcastAll(function(player){
game.zhu=player;
game.zhu.identityShown=true;
game.zhu.ai.shown=1;
game.zhu.setIdentity();
game.zhu.isZhu=true;
game.zhu.node.identity.classList.remove('guessing');
if(lib.config.animation&&!lib.config.low_performance) game.zhu.$legend();
if(_status.clickingidentity&&_status.clickingidentity[0]==game.zhu){
for(var i=0;i<_status.clickingidentity[1].length;i++){
_status.clickingidentity[1][i].delete();
_status.clickingidentity[1][i].style.transform='';
}
game.broadcastAll(clientPlayer=>{
if(!game.zhu) game.zhu=clientPlayer;
clientPlayer.identityShown=true;
clientPlayer.ai.shown=1;
clientPlayer.setIdentity();
clientPlayer.isZhu=true;
clientPlayer.node.identity.classList.remove('guessing');
var config=lib.config;
if(config.animation&&!config.low_performance) clientPlayer.$legend();
var clickingIdentity=_status.clickingidentity;
if(!clickingIdentity||clickingIdentity[0]!=clientPlayer) return;
clickingIdentity[1].forEach(element=>{
element.delete();
element.style.transform='';
});
delete _status.clickingidentity;
}
},game.zhu);
},player);
game.addVideo('showIdentity',player,'zhu');
game.delay(2);
game.zhu.playerfocus(1000);
_status.event.trigger('zhuUpdate');
player.playerfocus(1000);
event.trigger('zhuUpdate');
'step 2'
player.recover();
player.draw();
var skills=player.getStockSkills(true,true).filter(skill=>{
if(player.hasSkill(skill)) return false;
var info=get.info(skill);
return info&&info.zhuSkill;
player.getStockSkills(true,true).forEach(stockSkill=>{
if(player.hasSkill(stockSkill)) return;
var info=get.info(stockSkill);
if(!info||!info.zhuSkill) return;
player.addSkillLog(stockSkill);
});
if(skills.length){
for(var i of skills) player.addSkillLog(i);
}
}
},
stratagem_revitalization:{
@ -3807,20 +3800,21 @@ game.import('mode',function(lib,game,ui,get,ai,_status){
silent:true,
charlotte:true,
ruleSkill:true,
filter:function(event,player){
return player.ai.stratagemCamouflage&&event.player==player&&game.dead.length<Math.max(Math.round(get.population()/6),1)&&player.storage.stratagem_fury>=2&&!player.storage.stratagem_revitalization;
filter:(event,player)=>{
const storage=player.storage;
return !storage.stratagem_revitalization&&player.ai.stratagemCamouflage&&game.dead.length<Math.max(Math.round(get.population()/6),1)&&storage.stratagem_fury>=2;
},
content:function(){
content:()=>{
'step 0'
game.delayx();
'step 1'
player.storage.stratagem_revitalization=true;
game.broadcastAll(function(player){
player.identityShown=true;
player.ai.shown=1;
player.setIdentity();
player.node.identity.classList.remove('guessing');
if(lib.config.animation&&!lib.config.low_performance) player.$thunder();
game.broadcastAll(clientPlayer=>{
clientPlayer.identityShown=true;
clientPlayer.ai.shown=1;
clientPlayer.setIdentity();
clientPlayer.node.identity.classList.remove('guessing');
if(lib.config.animation&&!lib.config.low_performance) clientPlayer.$thunder();
},player);
game.addVideo('showIdentity',player,'fan');
game.delay(2);
@ -3839,14 +3833,20 @@ game.import('mode',function(lib,game,ui,get,ai,_status){
forced:true,
silent:true,
popup:false,
filter:function(event,player){
if(event.targets[0]==player) return false;
return event.targets.length==1&&event.targets[0]&&((player.storage.zhibi.contains(event.targets[0])||event.targets[0].identityShown) ||
game.players.slice().concat(game.dead).filter(current=>(current.storage.stratagem_revitalization||current.storage.stratagem_monarchy)&&current.identityShown&&current.storage.zhibi_for.contains(event.targets[0])).length);
filter:(event,player)=>{
const targets=event.targets;
if(targets.length!=1) return false;
const target=targets[0];
return target==player&&(target.identityShown||player.storage.zhibi.includes(target)||game.hasPlayer2(current=>{
if(!current.identityShown) return false;
const storage=current.storage;
return (storage.stratagem_revitalization||storage.stratagem_monarchy)&&storage.stratagem_expose.includes(target);
}));
},
content:function(){
if(!trigger.targets[0].storage.zhibi_for) trigger.targets[0].storage.zhibi_for=[];
if(!trigger.targets[0].storage.zhibi_for.contains(player)) trigger.targets[0].storage.zhibi_for.push(player);
content:()=>{
var storage=trigger.targets[0].storage;
if(!storage.stratagem_expose) storage.stratagem_expose=[];
storage.stratagem_expose.add(player);
}
},
yexinbilu:{
@ -4095,7 +4095,7 @@ game.import('mode',function(lib,game,ui,get,ai,_status){
'谋攻模式':'<div style="margin:10px">模式命名由来</div><ul style="margin-top:0"><li>《谋攻篇》一词出自《孙子兵法·谋攻篇》,是春秋时期兵法家孙武创作的一篇散文。《谋攻篇》故知胜有五:知可以战与不可以战者胜,识众寡之用者胜,上下同欲者胜,以虞待不虞者胜,将能而君不御者胜。</ul>'+
'<div style="margin:10px">游戏规则</div><ul style="margin-top:0"><li>谋攻篇模式为六名玩家参与的全暗身份模式,引入新机制“怒气”,玩家可以消耗怒气探查其他角色的身份是敌人或者队友,或使用怒气强化手牌,以达到识别出队友并击杀敌人的目标。'+
'<li>各身份玩家的胜利条件与身份局中对应身份的胜利条件一致,且该模式下没有奖惩。'+
'<li>当主公进入濒死、场上有两名角色阵亡、第三轮的主公回合开始时主公将会翻开身份牌回复1点体力并摸一张牌并获得武将牌上的主公技。'+
'<li>当主公进入濒死、场上有两名角色阵亡、第三轮的主公准备阶段主公将会翻开身份牌回复1点体力并摸一张牌并获得武将牌上的主公技。'+
'<li>内奸在游戏开始时将会得知一名反贼的身份并令该反贼被“伪装”。本局游戏内被“伪装”的反贼在被任何人探查身份时结果都提示为“敌人”。作为补偿其第一次进入濒死时若场上没有角色死亡且其怒气值不小于2其弃置区域内所有牌重置武将牌将体力回复至2点并摸三张牌。'+
'<li>特殊地,内奸在被所有角色探查时,都提示为“队友”;内奸在进行探查时,直接得知目标的身份。</ul>'+
'<div style="margin:10px">新机制“怒气”</div><ul style="margin-top:0"><li>一名角色在回合开始时或受到1点伤害后将获得1点怒气怒气上限为3。<li>一名角色令其他角色扣减体力后该角色可以消耗1点怒气查探扣减体力的角色是敌或友。</ul>'+