'use strict';
mode.versus={
game:{
getVideoName:function(){
var str=get.translation(game.me.name);
if(game.me.name2){
str+='/'+get.translation(game.me.name2);
}
var name=[
str,'对决 - '+lib.storage.number+'v'+lib.storage.number
];
return name;
},
start:function(){
var next=game.createEvent('game',false);
next.content=function(){
"step 0"
if(lib.db&&!_status.characterLoaded){
_status.waitingForCharacters=true;
game.pause();
}
"step 1"
var playback=localStorage.getItem(lib.configprefix+'playback');
if(playback){
ui.create.me();
ui.arena.style.display='none';
ui.system.style.display='none';
_status.playback=playback;
localStorage.removeItem(lib.configprefix+'playback');
var store=lib.db.transaction(['video'],'readwrite').objectStore('video');
store.get(parseInt(playback)).onsuccess=function(e){
if(e.target.result){
game.playVideoContent(e.target.result.video);
}
else{
alert('播放失败:找不到录像');
game.reload();
}
}
event.finish();
return;
}
if(lib.storage.choice==undefined) game.save('choice',20);
if(lib.storage.zhu==undefined) game.save('zhu',true);
if(lib.storage.noreplace_end==undefined) game.save('noreplace_end',true);
if(lib.storage.die_stop==undefined) game.save('die_stop',true);
if(lib.storage.autoreplaceinnerhtml==undefined) game.save('autoreplaceinnerhtml',true);
// if(lib.storage.only_zhu==undefined) game.save('only_zhu',true);
if(lib.storage.single_control==undefined) game.save('single_control',true);
if(lib.storage.number==undefined) game.save('number',3);
if(lib.storage.versus_reward==undefined) game.save('versus_reward',3);
if(lib.storage.versus_punish==undefined) game.save('versus_punish','弃牌');
if(lib.storage.replace_number==undefined) game.save('replace_number',3);
// if(lib.storage.control_all==undefined) game.save('control_all',true);
switch(lib.storage.seat_order){
case '交叉':lib.storage.cross_seat=true;lib.storage.random_seat=false;break;
case '随机':lib.storage.cross_seat=false;lib.storage.random_seat=true;break;
default:lib.storage.cross_seat=false;lib.storage.random_seat=false;
}
game.save('only_zhu',true);
game.save('control_all',true);
ui.create.cards();
game.finishCards();
ui.auto.hide();
ui.wuxie.hide();
game.delay();
"step 2"
game.chooseCharacter();
"step 3"
event.trigger('gameStart');
game.gameDraw(game.players[0]);
_status.round=0;
if(lib.storage.single_control){
lib.skill.global.push('versus_swap');
ui.autoreplace=ui.create.div('.caption.normal');
ui.autoreplace.innerHTML='
自动换人
';
ui.autoreplace.style.textAlign='center';
if(lib.storage.autoreplaceinnerhtml){
ui.autoreplace.classList.add('on')
}
ui.autoreplace.listen(game.switchAutoreplace);
// ui.versusreplace=ui.create.system('换人',null,true);
// lib.setPopped(ui.versusreplace,game.versusHoverReplace);
if(game.players.length>2){
ui.versushs=ui.create.system('手牌',null,true);
lib.setPopped(ui.versushs,game.versusHoverHandcards);
}
}
_status.friendCount=ui.create.system('友军: '+get.cnNumber(_status.friend.length,true),null,true);
_status.enemyCount=ui.create.system('敌军: '+get.cnNumber(_status.friend.length,true),null,true);
// _status.friendCount=ui.create.system('友方',null,true);
// _status.enemyCount=ui.create.system('敌方',null,true);
lib.setPopped(_status.friendCount,game.versusHoverFriend);
lib.setPopped(_status.enemyCount,game.versusHoverEnemy);
if(lib.storage.zhu){
_status.currentSide=true;
game.versusPhaseLoop((_status.currentSide==game.me.side)?game.friendZhu:game.enemyZhu);
}
else{
game.versusPhaseLoop(game.players[Math.floor(Math.random()*game.players.length)]);
}
}
},
chooseCharacter:function(){
var next=game.createEvent('chooseCharacter',false);
next.showConfig=true;
next.content=function(){
"step 0"
event.check=function(){
this.dialog.classList.add('fullwidth');
this.dialog.classList.add('fullheight');
this.dialog.classList.add('noslide');
for(var i=0;ib?1:-1;
}
if(lib.storage.choice=='∞'){
list.sort(sortByGroup);
}
else{
list.randomSort();
}
_status.list=list;
var choice=(lib.storage.choice=='∞')?list.length:lib.storage.choice;
event.dialog=ui.create.dialog('选择角色',[list.slice(0,choice),'character']);
// for(var i=0;i=dialog.versus_number.link+dialog.replace_number.link){
event.fill.firstChild.innerHTML='开始';
_status.choosefinished=true;
}
game.save('zhu',dialog.versus_zhu.link);
if(lib.storage.zhu){
// dialog.versus_only_zhu.parentNode.classList.remove('disabled');
dialog.versus_main_zhu.parentNode.classList.remove('disabled');
}
else{
// dialog.versus_only_zhu.parentNode.classList.add('disabled');
dialog.versus_main_zhu.parentNode.classList.add('disabled');
}
// game.save('only_zhu',dialog.versus_only_zhu.link);
game.save('main_zhu',dialog.versus_main_zhu.link);
game.save('assign_enemy',dialog.versus_assign_enemy.link);
game.save('seat_order',dialog.versus_seat_order.link);
// game.save('cross_seat',dialog.versus_cross_seat.link);
game.save('noreplace_end',dialog.versus_noreplace_end.link);
game.save('single_control',dialog.versus_single_control.link);
// if(lib.storage.cross_seat){
// dialog.versus_random_seat.parentNode.classList.add('disabled');
// }
// else{
// dialog.versus_random_seat.parentNode.classList.remove('disabled');
// if(lib.storage.random_seat){
// dialog.versus_cross_seat.parentNode.classList.add('disabled');
// }
// else{
// dialog.versus_cross_seat.parentNode.classList.remove('disabled');
// }
// }
switch(lib.storage.seat_order){
case '交叉':lib.storage.cross_seat=true;lib.storage.random_seat=false;break;
case '随机':lib.storage.cross_seat=false;lib.storage.random_seat=true;break;
default:lib.storage.cross_seat=false;lib.storage.random_seat=false;
}
// if(lib.storage.single_control){
// dialog.versus_control_all.parentNode.classList.remove('disabled');
// }
// else{
// dialog.versus_control_all.parentNode.classList.add('disabled');
// }
// game.save('control_all',dialog.versus_control_all.link);
game.save('die_stop',dialog.versus_die_stop.link);
game.save('number',dialog.versus_number.link);
game.save('versus_reward',dialog.versus_reward.link);
game.save('versus_punish',dialog.versus_punish.link);
game.save('replace_number',dialog.replace_number.link);
game.save('choice',dialog.choice.link);
var count,i;
if(dialog.buttons.length>lib.storage.choice){
count=dialog.buttons.length-lib.storage.choice;
var removed=[];
for(i=dialog.buttons.length-1;i>=0&&count>0;i--){
if(dialog.buttons[i].classList.contains('target')==false&&
dialog.buttons[i].classList.contains('glow')==false){
dialog.buttons[i].remove();
_status.list.remove(dialog.buttons[i].link);
removed.push(dialog.buttons[i].link)
dialog.buttons.splice(i,1);
count--;
}
}
for(i=0;i=4){
ui.arena.dataset.number=parseInt(ui.arena.dataset.number)+1;
for(var i=0;i=4){
// ui.fakemebg.show();
game.onSwapControl();
}
var players=get.players(lib.sort.position);
var info=[];
for(var i=0;i=4);
game.addVideo('init',null,info);
}
},
versusPhaseLoop:function(player){
var next=game.createEvent('phaseLoop');
next.player=player;
next.content=function(){
"step 0"
if(lib.storage.zhu){
player.classList.add('acted');
}
player.phase();
"step 1"
if(lib.storage.zhu){
_status.currentSide=!_status.currentSide;
_status.round++;
if(_status.round>=2*Math.max(game.friend.length,game.enemy.length)){
_status.round=0;
for(var i=0;ib.num('j')) return 1;
return a.hp-b.hp;
})
event.player=list[0];
event.goto(0);
}
else{
game.me.chooseTarget('选择要行动的角色',true,function(card,player,target){
return (target.classList.contains('acted')==false&&target.side==game.me.side);
})
}
}
else{
event.player=event.player.next;
event.goto(0);
}
"step 2"
event.player=result.targets[0];
event.goto(0);
}
},
replacePlayer:function(player){
var next=game.createEvent('replacePlayer');
next.source=player;
next.content=function(){
"step 0"
var list=(source.side==game.me.side)?_status.friend:_status.enemy;
if(list.length==0){
// if(game.friend.contains(source)){
// game.over(false);
// }
// else{
// game.over(true);
// }
game.friend.remove(source);
game.enemy.remove(source);
if(game.friend.length==0) game.over(false);
else if(game.enemy.length==0) game.over(true);
if(game.friendZhu&&game.friendZhu.classList.contains('dead')&&game.friend.length){
game.friendZhu=game.friend[0];
game.friendZhu.setIdentity(_status.color+'Zhu');
}
if(game.enemyZhu&&game.enemyZhu.classList.contains('dead')&&game.enemy.length){
game.enemyZhu=game.enemy[0];
game.enemyZhu.setIdentity(!_status.color+'Zhu');
}
event.finish();
return;
}
if(source.side==game.me.side&&list.length>1&&(game.me==game.friendZhu||(lib.storage.zhu&&lib.storage.single_control))&&
!_status.auto){
event.dialog=ui.create.dialog('选择替补角色',[list,'character']);
event.filterButton=function(){return true;};
event.player=game.me;
event.forced=true;
event.custom.replace.confirm=function(){
event.character=ui.selected.buttons[0].link;
event.dialog.close();
if(ui.confirm) ui.confirm.close();
delete event.player;
game.resume();
}
game.check();
game.pause();
}
else{
event.character=list[Math.floor(Math.random()*list.length)];
}
"step 1"
_status.friend.remove(event.character);
_status.enemy.remove(event.character);
source.revive();
game.additionaldead.push({
name:source.name,
stat:source.stat
});
game.addVideo('reinit',source,[event.character,get.translation(source.side+'Color')]);
source.uninit();
source.init(event.character);
source.node.identity.dataset.color=get.translation(source.side+'Color');
source.draw(4);
if(lib.storage.die_stop){
_status.event.parent.parent.parent.untrigger(true);
}
if(lib.storage.single_control&&lib.storage.control_all){
game.onSwapControl();
}
}
},
versusClickToSwap:function(e){
if(_status.dragged) return;
if(this.link==game.me){
if(!this.classList.contains('buttonclick')){
this.animate('buttonclick');
}
}
else if(_status.event.player==game.me&&!_status.auto){
game.me.popup('请稍后再换人');
e.stopPropagation();
}
else{
game.modeSwapPlayer(this.link);
}
},
versusCheckHandcards:function(){
_status.clicked=true;
if(ui.intro){
ui.intro.close();
if(ui.intro.source=='versusCheckHandcards'){
delete ui.intro;
ui.control.show();
game.resume2();
return;
}
}
game.pause2();
ui.control.hide();
ui.intro=ui.create.dialog();
ui.intro.source='versusCheckHandcards';
ui.intro.add(ui.autoreplace);
var players=[];
for(var i=0;i2)){
if(game.friend.contains(this)){
game.over(false);
}
else{
game.over(true);
}
}
else if(game.friend.length==1&&this==game.friend[0]&&_status.friend.length==0){
game.over(false);
}
else if(game.enemy.length==1&&this==game.enemy[0]&&_status.enemy.length==0){
game.over(true);
}
else{
if(source){
if(source.side!=this.side){
if(lib.storage.versus_reward){
source.draw(lib.storage.versus_reward);
}
}
else{
if(lib.storage.versus_punish=='弃牌'){
source.discard(source.get('he'));
}
else if(lib.storage.versus_punish=='摸牌'&&lib.storage.versus_reward){
source.draw(lib.storage.versus_reward);
}
}
}
else{
game.delay();
}
game.replacePlayer(this);
}
}
}
},
ai:{
get:{
attitude:function(from,to){
if(from.side==to.side){
if(to.identity=='zhu'&&lib.storage.main_zhu) return 10;
return 6;
}
if(to.identity=='zhu'&&lib.storage.main_zhu) return -10;
return -6;
},
}
},
config:['change_choice','ban_weak']
}