Optimize game.countPlayer2.

(cherry picked from commit e6af8abe7b7826bb6c7dc005f8f6c8106cc59c06)
This commit is contained in:
Tipx-L 2023-08-24 06:39:26 -07:00
parent d0e1063a9b
commit ed19d18f75
1 changed files with 9 additions and 17 deletions

View File

@ -38756,23 +38756,15 @@
} }
return num; return num;
}, },
countPlayer2:function(func,includeOut){ countPlayer2:(func,includeOut)=>{
var num=0; if(typeof func!='function') func=lib.filter.all;
if(typeof func!='function'){ return game.players.concat(game.dead).reduce((previousValue,currentValue)=>{
func=lib.filter.all; if(!includeOut&&currentValue.isOut()) return previousValue;
} const result=func(currentValue);
var players=game.players.slice(0).concat(game.dead); if(typeof result=='number') previousValue+=result;
for(var i=0;i<players.length;i++){ else if(result) previousValue++;
if(!includeOut&&players[i].isOut()) continue; return previousValue;
var result=func(players[i]); },0);
if(typeof result=='number'){
num+=result;
}
else if(result){
num++;
}
}
return num;
}, },
filterPlayer:(func,list,includeOut)=>{ filterPlayer:(func,list,includeOut)=>{
if(!Array.isArray(list)) list=[]; if(!Array.isArray(list)) list=[];