'use strict'; mode.chess={ canvasUpdates2:[], element:{ card:{ moveTo:function(player,method){ this.fixed=true; if(this.parentNode==ui.arena){ var rect=player.getBoundingClientRect(); this.style.left=(rect.left+8)+'px'; this.style.top=(rect.top+8)+'px'; } else{ this.style.left=''; this.style.top=''; this.dataset.position=player.dataset.position; } if(method=='flip'){ this.style.transition='all 0.5s'; this.style.webkitTransform='rotate'+(Math.random()<0.5?'X':'Y')+'(180deg) perspective(1000px)'; } else if(method=='rotate'){ this.style.transition='all 0.5s'; this.style.webkitTransform='rotate(180deg)'; } return this; }, }, player:{ createRangeShadow:function(num,move){ num++; var shadows=this.parentNode.getElementsByClassName('playergrid'); while(shadows.length){ shadows[0].remove(); } for(var i=1-num;i=ui.chesswidth){ x=ui.chesswidth-1; } if(y>=ui.chessheight){ y=ui.chessheight-1; } // console.log(x,y); var pos=y*ui.chesswidth+x; if(!lib.posmap[pos]){ delete lib.posmap[this.dataset.position]; this.dataset.position=pos; lib.posmap[pos]=this; this.chessFocus(); } return this; }, chessFocus:function(){ if(ui.chess._chessdrag) return; if(_status.chessscrolling) return; var player=this; var dx=0,dy=0; if(player.offsetLeft-ui.chessContainer.scrollLeft<14){ dx=player.offsetLeft-ui.chessContainer.scrollLeft-14; } else if(player.offsetLeft-ui.chessContainer.scrollLeft>ui.chessContainer.offsetWidth-134){ dx=player.offsetLeft-ui.chessContainer.scrollLeft-ui.chessContainer.offsetWidth+134; } if(player.offsetTop-ui.chessContainer.scrollTop<14){ dy=player.offsetTop-ui.chessContainer.scrollTop-14; } else if(player.offsetTop+ui.chess.offsetTop-ui.chessContainer.scrollTop>ui.chessContainer.offsetHeight-134){ dy=player.offsetTop+ui.chess.offsetTop-ui.chessContainer.scrollTop-ui.chessContainer.offsetHeight+134; } if(_status.currentChessFocus){ clearInterval(_status.currentChessFocus); } var count=12; var ddx=Math.floor(dx/12); var ddy=Math.floor(dy/12); if(dx||dy){ _status.currentChessFocus=setInterval(function(){ if(count--){ ui.chessContainer.scrollLeft+=ddx; ui.chessContainer.scrollTop+=ddy; } else{ ui.chessContainer.scrollLeft+=dx%12; ui.chessContainer.scrollTop+=dy%12; clearInterval(_status.currentChessFocus); delete _status.currentChessFocus; } },16); } }, getXY:function(){ var pos=parseInt(this.dataset.position); var x=pos%ui.chesswidth; var y=Math.floor(pos/ui.chesswidth); return [x,y]; }, getDataPos:function(x,y){ var xy=this.getXY(); if(typeof x!='number') x=0; if(typeof y!='number') y=0; x+=xy[0]; y+=xy[1]; return x+y*ui.chesswidth; }, getNeighbour:function(x,y){ return lib.posmap[this.getDataPos(x,y)]||null; }, movable:function(x,y){ var xy=this.getXY(); if(xy[0]+x<0) return false; if(xy[1]+y<0) return false; if(xy[0]+x>=ui.chesswidth) return false; if(xy[1]+y>=ui.chessheight) return false; return !this.getNeighbour(x,y); }, moveRight:function(){ if(this.movable(1,0)){ this.move(1,0); return true; } return false; }, moveLeft:function(){ if(this.movable(-1,0)){ this.move(-1,0); return true; } return false; }, moveUp:function(){ if(this.movable(0,-1)){ this.move(0,-1); return true; } return false; }, moveDown:function(){ if(this.movable(0,1)){ this.move(0,1); return true; } return false; }, dieAfter:function(source){ var player=this; delete lib.posmap[player.dataset.position]; setTimeout(function(){ player.delete(); },500); for(var i=0;i1){ if(cards){ that.$draw(cards) } else{ that.$draw(num-1) } } }, $gainmod:function(num){ var cards,node; if(get.itemtype(num)=='cards'){ cards=num; num=cards.length; } else if(get.itemtype(num)=='card'){ cards=[num]; num=1; } if(cards){ cards=cards.slice(0); node=cards.shift().copy('thrown','hidden'); } else{ node=ui.create.div('.card.thrown.hidden'); } node.fixed=true; game.$randomMove(this,node,100,30); var ot=node.style.webkitTransform; node.style.webkitTransform+='scale(0.6)'; node.dataset.position=this.dataset.position; this.parentNode.appendChild(node); ui.refresh(node); node.show(); node.style.webkitTransform=ot; setTimeout(function(){ node.style.webkitTransform=''; node.delete(); },500); var that=this; if(num&&num>1){ if(cards){ that.$gain(cards) } else{ that.$gain(num-1) } } }, $throw:function(card,time){ this.chessFocus(); if(get.itemtype(card)=='cards'){ for(var i=0;i=0){ for(var i=0;ipxy[0]&&randomMove.contains('moveRight')){ if(player.moveRight()){ event.moved=true;break; } } else if(txy[0]pxy[1]&&randomMove.contains('moveDown')){ if(player.moveDown()){ event.moved=true;break; } } else if(txy[1]pxy[1]&&randomMove.contains('moveDown')){ if(player.moveDown()){ event.moved=true;break; } } else if(txy[1]pxy[0]&&randomMove.contains('moveRight')){ if(player.moveRight()){ event.moved=true;break; } } else if(txy[0]=ui.chessContainer.offsetWidth){ tx=-Math.abs(tx); } if(rect.top<=80){ ty=Math.abs(ty); } else if(rect.top+rect.height+80>=ui.chessContainer.offsetHeight){ ty=-Math.abs(ty); } node.style.webkitTransform='translate('+tx+'px,'+ty+'px)'; }, draw2:function(func){ lib.canvasUpdates2.push(func); if(!lib.status.canvas2){ lib.status.canvas2=true; game.update(game.updateCanvas2); } }, updateCanvas2:function(time){ if(lib.canvasUpdates2.length===0){ lib.status.canvas2=false; return false; } ui.canvas2.width=ui.chess.offsetWidth; ui.canvas2.height=ui.chess.offsetHeight; ui.canvas2.style.left=0; ui.canvas2.style.top=0; var ctx=ui.ctx2; ctx.shadowBlur=5; ctx.shadowColor='rgba(0,0,0,0.3)'; ctx.fillStyle='white'; ctx.strokeStyle='white'; ctx.lineWidth=3; ctx.save(); for(var i=0;i.player'+pos+ '{left:'+(14+i*148)+'px;top:'+(14+j*148)+'px}',0); ui.chesssheet.sheet.insertRule('#arena.chess #chess>.card'+pos+ '{left:'+(22+i*148)+'px;top:'+(22+j*148)+'px}',0); if(j==ui.chessheight-1){ ui.chesssheet.sheet.insertRule('#arena.chess #chess>.popup'+pos+ '{left:'+(19+i*148)+'px;top:'+(-19+j*148)+'px}',0); } else{ ui.chesssheet.sheet.insertRule('#arena.chess #chess>.popup'+pos+ '{left:'+(19+i*148)+'px;top:'+(142+j*148)+'px}',0); } } } var grids=[]; var gridnum=ui.chessheight*ui.chesswidth; for(var i=0;i7){ game.players[i].popup('距离:'+dist,'thunder'); } else{ game.players[i].popup('距离:'+dist); } } } },true); ui.create.me(); ui.create.fakeme(); ui.create.cards(); ui.chessinfo=ui.create.div('.fakeme.player',ui.me); game.finishCards(); game.arrangePlayers(); "step 2" var p; for(var i=0;i1||event.targets[0]!=player); }, forced:true, popup:false, content:function(){ player.addTempSkill('noactpunish','phaseAfter'); } }, noactpunish:{}, _phasequeue:{ trigger:{player:'phaseBegin'}, forced:true, popup:false, content:function(){ var current=ui.chessinfo.querySelector('.glow2'); if(current){ current.classList.remove('glow2'); } for(var i=0;i1; var nh=player.num('h'); if(!player.num('h','sha')&& !player.num('h','shunshou')&& !player.num('h','bingliang')){ if(nh<=Math.min(3,player.hp)) return Math.random()-0.3; else if(nh<=Math.min(2,player.hp)) return Math.random()-0.4; return Math.random()-0.5; } var neighbour; neighbour=player.getNeighbour(0,1); if(neighbour&&neighbour.side!=player.side){ return range?1:0; } neighbour=player.getNeighbour(0,-1); if(neighbour&&neighbour.side!=player.side){ return range?1:0; } neighbour=player.getNeighbour(1,0); if(neighbour&&neighbour.side!=player.side){ return range?1:0; } neighbour=player.getNeighbour(-1,0); if(neighbour&&neighbour.side!=player.side){ return range?1:0; } return 1; } } } }, _chessswap:{ trigger:{player:['phaseBegin','chooseToUseBegin','chooseToRespondBegin','chooseToDiscardBegin','chooseToCompareBegin', 'chooseButtonBegin','chooseCardBegin','chooseTargetBegin','chooseCardTargetBegin','chooseControlBegin', 'chooseBoolBegin','choosePlayerCardBegin','discardPlayerCardBegin','gainPlayerCardBegin']}, forced:true, priority:100, popup:false, filter:function(event,player){ if(event.autochoose&&event.autochoose()) return false; return !_status.auto&&player.isUnderControl(); }, content:function(){ game.modeSwapPlayer(player); }, }, _chesscenter:{ trigger:{player:['phaseBegin','useCardBegin','useSkillBegin','respondBegin','damageBegin','loseHpBegin'], target:'useCardToBegin'}, forced:true, priority:100, popup:false, content:function(){ player.chessFocus(); }, }, }, translate:{ friend:'友', enemy:'敌', trueColor:"zhu", falseColor:"wei", _chessmove:'移动', chessscroll_speed_config:'边缘滚动速度' }, ui:{ create:{ playergrid:function(player,x,y){ var node=ui.create.div('.player.minskin.playergrid',player.parentNode); node.link=player; node.dataset.position=player.getDataPos(x,y); return node; }, fakeme:function(){ if(ui.fakeme){ ui.fakeme.delete(); } ui.fakeme=ui.create.div('.fakeme.avatar',ui.me); ui.fakeme.style.backgroundImage=game.me.node.avatar.style.backgroundImage; } }, click:{ playergrid:function(){ if(!_status.paused) return; delete lib.posmap[this.link.dataset.position]; this.link.dataset.position=this.dataset.position; lib.posmap[this.link.dataset.position]=this.link; if(ui.movegrids){ while(ui.movegrids.length){ ui.movegrids.shift().delete(); } } game.resume(); } } }, ai:{ get:{ attitude:function(from,to){ return (from.side==to.side?1:-1)*5; } } }, posmap:{}, help:{ '战棋模式':'
  • n人对战n人的模式,由单人控制,开始游戏后随机分配位置与出牌顺序
  • '+ '每人在出牌阶段有一次移动的机会,若一名角色在移动之前使用过指定其他角色为目标的牌,该回合可移动的最大距离为2,否则最大距离为1
  • '+ '任何卡牌或技能无法指定位置相隔8个格以上的角色为目标
  • '+ '杀死对方阵营的角色可摸一张牌,杀死本方阵营无惩罚' }, config:['battle_number','ban_weak','free_choose','change_choice', function(lib,get,ui){ var current=get.config('chessscroll_speed'); if(typeof current!=='number'){ game.saveConfig('chessscroll_speed',20,true); current=20; } return ui.create.switcher('chessscroll_speed',[0,10,20,30],10,ui.click.sidebar.local); }], }