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