webxoss-client/webxoss.js
2017-05-10 02:09:21 +08:00

3 lines
No EOL
64 KiB
JavaScript

"use strict";function callConstructor(t){var e=t.bind.apply(t,arguments);return new e}function applyToConstructor(t,e){var i=concat(null,toArr(e)),n=t.bind.apply(t,i);return new n}function nextTick(t){setTimeout(t,0)}function MessageBox(){this.eWarp=document.getElementById("msgbox-warp"),this.eWin=document.getElementById("msgbox-window"),this.eMsg=document.getElementById("msgbox-msg"),this.eInput=document.getElementById("msgbox-input"),this.ePreset=document.getElementById("msgbox-preset"),this.eOk=document.getElementById("msgbox-button-ok"),this.eCancel=document.getElementById("msgbox-button-cancel")}function IO(t){this.socket=t,this.listener=null,this.sendingMsg=null,this.datas=[],this.id=0,this.inputBlocked=!1,this.outputBlocked=!1,this.socket.removeAllListeners("gameMessage"),this.socket.on("gameMessage",this.receiveGameMessage.bind(this))}function Card(t,e){createjs.Container.prototype.initialize.call(this),this.game=t,this.isWhiteBack=e,this.width=Card.WIDTH,this.height=Card.HEIGHT,this.pid=0,this.zone=null,this.zIndex=0,this.changed=!0,this.isSide=!1,this.renderLayer=new createjs.Container,this.addChild(this.renderLayer),this.renderLayer.regX=this.width/2,this.renderLayer.regY=this.height/2,this.bitmap=new CardBitmap("",t.imageManager.noimage),this.renderLayer.addChild(this.bitmap),this.stateLayer=new createjs.Container,this.renderLayer.addChild(this.stateLayer),this.effectShape=new createjs.Shape,this.renderLayer.addChild(this.effectShape),this.buttonLayer=new ButtonList,this.buttonLayer.x=this.width/2,this.buttonLayer.y=this.height/2,this.renderLayer.addChild(this.buttonLayer),this.style=new Style({x:0,y:0,zIndex:0,top:!1,covered:!1,offX:0,offY:0,rotation:0,scaleX:-1,shadowColor:"#f7ff00",shadowBlur:0,flash:0,shine:0}),this.style.checkSkip=function(){return this.game.skip}.bind(this),this.on("mouseover",this.handleMouseover),this.on("mouseout",this.handleMouseout),this.game.addCard(this)}function CardBitmap(t,e){createjs.Container.prototype.initialize.call(this),this.setAltImage(t,e),this.setWidthHeight(Card.WIDTH,Card.HEIGHT),this.complete=e.complete,this.text=new createjs.Text(t),this.bitmap=new createjs.Bitmap(e),this.addChild(this.text,this.bitmap),this.changed=!0}function StateBitmap(t){var e=new createjs.Bitmap(t);return e.width=Card.WIDTH,e.height=Card.HEIGHT,e}function Style(t){this.transitingStyle={};for(var e in t)this.transitingStyle[e]=new TransitingValue(t[e]);this.changed=!0,this.checkSkip=null}function TransitingValue(t){this.changeTime=0,this.startValue=t,this.endValue=t,this.duration=0,this.timing=TransitingValue.cubic,this.done=!1}function Zone(t){createjs.Container.prototype.initialize.call(this),this.game=t.game,this.name=t.name,this.x=t.x,this.y=t.y,this.showAmount=!!t.showAmount,this._amount=0,this.opposite=!!t.opposite,this.checkable=!!t.checkable,this.cards=[],this.changed=!0,this.text=new createjs.Text("","bold 12px monospace"),this.text.textAlign="center",this.addChild(this.text),this.opposite&&(this.rotation=180,this.text.rotation=180),this.buttonLayer=new ButtonList,this.buttonLayer.rotation=-this.rotation,this.addChild(this.buttonLayer),this.checkable&&(this.viewCardsButton=new Button(Localize("buttonTitle","VIEW"),function(){this.game.dialog.showCards(Localize("buttonTitle","VIEW"),this.cards,function(){})}.bind(this)),this.viewCardsButton.alpha=.8),this.game.addZone(this)}function StackZone(t){Zone.apply(this,arguments),this.showPower=!!t.showPower,this.changed=!0,this._power=0,this.power=0,t.centerText?this.text.textBaseline="middle":(this.text.textBaseline="top",this.text.y=Card.HEIGHT/2,this.opposite&&(this.text.rotation=180,this.text.textBaseline="bottom")),this.stateLayer=new createjs.Container,this.stateShape=new createjs.Shape,this.stateLayer.addChild(this.stateShape),this.addChild(this.stateLayer)}function TileZone(t){Zone.apply(this,arguments),this.up=t.up,this.horizontal=t.horizontal,this.center=t.center,this.width=t.width,this.spacing=t.spacing,this.showAmount=!!t.showAmount,this.horizontal?(this.text.textBaseline="middle",this.opposite?this.text.textAlign="left":this.text.textAlign="right"):(this.text.textAlign="center",this.opposite?this.text.textBaseline="top":this.text.textBaseline="bottom"),this.checkable&&(this.buttonLayer.y+=this.width/2,this.buttonLayer.addButton(this.viewCardsButton))}function Game(t,e,i,n){this.io=t,this.audio=e,this.ongameover=i,this.io.listener=function(t){console.log(t),this.addMsgs(t),this.update()}.bind(this),this.onidle=null,this.gameDiv=document.getElementById("GameDiv"),this.canvasContainer=document.getElementById("BattleField"),this.canvasContainer.innerHTML="",this.canvas=document.createElement("canvas"),this.canvas.width=576,this.canvas.height=734,this.canvasContainer.appendChild(this.canvas),this.stage=new createjs.Stage(this.canvas),this.stage.enableDOMEvents(!0),this.stage.enableMouseOver(10),this.dialog=new Dialog(this),this.selector=new Selector(this,n),this.objList=[],this.background=new GameBackground(this),this.stage.addChild(this.background),this.cards=[],this.cardLayer=new createjs.Container,this.stage.addChild(this.cardLayer),this.zones=[],this.zoneLayer=new createjs.Container,this.stage.addChild(this.zoneLayer),this.msgQueue=[],this._packageCount=0,this.imageManager=new ImageManager,this.cardDetail=new CardDetail(this.imageManager),this.initZones(),this.skip=!1}function Button(t,e){createjs.Container.prototype.initialize.call(this),this.changed=!0;var i=5,n=8,o=Button.HEIGHT,s=o+'px "Segoe UI", Arial, "Microsoft Yahei", Simsun, sans-serif';this.text=new createjs.Text(t,s),this.text.textBaseline="middle",this.height=o+2*i,this.width=this.text.getMeasuredWidth()+2*n,this.regX=this.width/2,this.regY=this.height/2,this.text.x=n,this.text.y=this.height/2,this.background=new createjs.Shape,this.toDefaultStyle(),this.addChild(this.background,this.text),this.on("click",e),this.on("mouseover",this.toHoverStyle),this.on("mouseout",this.toDefaultStyle)}function ButtonList(){createjs.Container.prototype.initialize.call(this),this.changed=!1,this.buttons=[]}function Selector(t,e){this.game=t,this.msgs=[],this.selectedIndexes=[],this._autoPopMsg=null,this.spectating=e}function Dialog(t){this.game=t,this.searcher=new Searcher,this.warpDiv=this.newElement("div"),this.dialogDiv=this.newElement("div"),this.titleDiv=this.newElement("div"),this.closeIcon=this.newElement("div"),this.bodyDiv=this.newElement("div"),this.footerDiv=this.newElement("div"),this.footSpan=this.newElement("span"),this.okBtn=this.newElement("button"),this.cancelBtn=this.newElement("button"),this.okBtn.textContent=Localize("common","OK"),this.cancelBtn.textContent=Localize("common","CANCEL"),this.closeIcon.onclick=this.close.bind(this),this.warpDiv.classList.add("warp"),this.dialogDiv.classList.add("dialog"),this.titleDiv.classList.add("title"),this.closeIcon.classList.add("closeIcon"),this.bodyDiv.classList.add("body"),this.footerDiv.classList.add("footer"),this.okBtn.classList.add("okBtn"),this.cancelBtn.classList.add("cancelBtn"),this.warpDiv.appendChild(this.dialogDiv),this.dialogDiv.appendChild(this.closeIcon),this.dialogDiv.appendChild(this.titleDiv),this.dialogDiv.appendChild(this.bodyDiv),this.dialogDiv.appendChild(this.footerDiv),this.footerDiv.appendChild(this.footSpan),this.footerDiv.appendChild(this.okBtn),this.footerDiv.appendChild(this.cancelBtn),this.warpDiv.style.display="none",t.stage.canvas.parentElement.appendChild(this.warpDiv)}function GameBackground(t){createjs.Container.prototype.initialize.call(this),this.game=t,this.width=t.stage.canvas.width,this.height=t.stage.canvas.height,this.changed=!0,this.mask=new createjs.Shape,this.addChild(this.mask)}function GameAudio(){this.bgm=document.getElementById("audio-bgm"),this.soundEffect=document.getElementById("audio-sound-effect"),this.bgmCheckBox=document.getElementById("checkbox-bgm"),this.seCheckBox=document.getElementById("checkbox-sound-effect"),this.bgmDisabled=!1,this.seDisabled=!1,this.lastPlay="",this.map={white:"WhiteAng",black:"DarkFßen",red:"reLEIdEN",blue:"Süblueß",green:"GreenWi",NevWorry:"NevWorry",main:"Love Your Enemies.W",Battle:"バトル!"},this.loadSettings()}function ChatManager(t){this.socket=t,this.dialogue=document.getElementById("chat-dialogue"),this.input=document.getElementById("chat-input"),this.input.onkeypress=function(t){var e=t.keyCode||t.which||t.charCode;13===e&&(this.sendMsg(this.input.value),this.input.value=null)}.bind(this)}function hide(t){t.style.display="none"}function show(t,e){1===arguments.length?t.style.display="":t.disabled=e?"":"none"}function disable(t){t.disabled=!0}function enable(t,e){1===arguments.length?t.disabled=!1:t.disabled=!e}function setClass(t,e,i){i?t.classList.add(e):t.classList.remove(e)}function newElement(t){for(var e=document.createElement(t),i=1;i<arguments.length;i++)e.classList.add(arguments[i]);return e}function newImage(t){var e=new Image;return e.src=t,e}function getProxy(){var t=localStorage.getItem("proxy"),e={"cloudflare.webxoss.com":"cloudflare.webxoss.com:2053","cloudflare.webxoss.com:2015":"cloudflare.webxoss.com:2053","incapsula.webxoss.com":"","shanghai.webxoss.com:10086":""};return t in e&&(t=e[t],localStorage.setItem("proxy",t)),localStorage.getItem("proxy")||""}function initLanguage(){Localize.init(),Localize.DOM("index"),$("select-language").value=localStorage.getItem("language")}function initHall(){game=null,socket.io.reconnection(!1),position="",mayusRoom=!0,blocking=!1,inroom=!1,watchingLive=!1,playingReplay=!1,roomMsgObj=null,document.body.removeAttribute("self"),document.body.removeAttribute("opponent"),document.body.classList.remove("gaming"),hide($("GameDiv")),hide($("Room")),hide($("Chat")),show($("Hall")),chatManager.clear(),audio.playBgm("main")}function initInputValues(){var t=localStorage.getItem("nickname");t&&($("input-nickame").value=t);var e=localStorage.getItem("room name");e&&($("input-room-name").value=e);var i=localStorage.getItem("password");i&&($("input-create-room-password").value=i);var n=localStorage.getItem("live");null!==n?$("input-live").checked=n:$("input-live").checked=!0}function reload(){window.onbeforeunload=null,window.location=window.location.href}function checkVersion(){return serverVersion?VERSION==serverVersion||(msgBox.alert(Localize.index("REQUIRE_UPDATE")),window.applicationCache&&window.applicationCache.update&&window.applicationCache.update(),!1):(msgBox.alert(Localize.index("NOT_CONNECTED")),!1)}function gameStart(t){if(hide($("Hall")),hide($("Room")),show($("GameDiv")),game&&game.destroy(),"replay"===t){hide($("Chat")),show($("div-replay-controls"));var e=(734-$("button-replay-step").clientHeight)/2;$("div-replay-controls").style.top=e+"px"}else hide($("div-replay-controls")),"live"!==t?show($("Chat")):hide($("Chat"));var i="replay"===t||"live"===t||isSpectator();i?(hide($("span-surrender")),show($("span-leave-game"))):(show($("span-surrender")),hide($("span-leave-game")),socket.io.reconnection(!0)),game=new Game(new IO(socket),audio,ongameover,i),document.body.classList.add("gaming")}function ongameover(t,e,i){socket.io.reconnection(!1),askForSupport(t);var n=t?"WIN":"LOSE",o=newElement("div");setClass(o,"gameover",!0);var s=newElement("div");t?s.textContent=e?Localize.index("OPPONENT_SURRENDERED"):"YOU WIN!":s.textContent=e?Localize.index("SURRENDERED"):"YOU LOSE!",o.appendChild(s);var a=objToBlob(createReplayObj(i,t,e)),r=blobToUrl(a),c=null;if(r){c=newElement("a"),setClass(c,"replay",!0),c.target="_blank";var h=(new Date).toISOString().replace("T"," ").substr(0,19).replace(/:/g,"-"),l=h+".wxrep";c.download=l,c.href=r,c.textContent=Localize.index("SAVE_REPLAY"),navigator.msSaveBlob&&(c.onclick=function(t){return t.preventDefault(),navigator.msSaveBlob(a,l),!1})}game.dialog.pop(n,o,c,!1,function(){game=null,r&&window.URL&&window.URL.revokeObjectURL(r),roomMsgObj&&!watchingLive?updateRoom(roomMsgObj):initHall()})}function askForSupport(t){}function createReplayObj(t,e,i){return{format:"WEBXOSS Replay",version:"1",content:{clientVersion:VERSION,_timestamp:(new Date).getTime(),win:!!e,surrender:!!i,messagePacks:t}}}function blobToUrl(t){if(!t)return"";var e=window.URL||window.webkitURL||window.mozURL;if(!e)return"";var i;try{i=e.createObjectURL(t)}catch(t){return""}return i}function objToBlob(t){var e=window.Blob||window.WebKitBlob||window.mozBlob,i=window.JSON;if(!e||!i)return"";var n,o;try{n=i.stringify(t),o=new e([n],{type:"application/octet-stream"})}catch(t){return null}return o}function initDeckOptions(){$("select-decks").innerHTML="";var t=[],e=deckManager.getDeckNames();return e.forEach(function(e){var i=deckManager.loadDeck(e);deckManager.checkDeck(i,mayusRoom)&&t.push(e)}),t.length?(t.forEach(function(t){var e=newElement("option");e.value=t,e.textContent=t,$("select-decks").appendChild(e)}),!0):(msgBox.alert(Localize.index("NO_VALID_DECK")),!1)}function isHost(){return"host"===position}function isGuest(){return"guest"===position}function isSpectator(){return"host-spectator"===position||"guest-spectator"===position}function clearOnclicks(){elements.forEach(function(t){t.onclick=null})}function setClickableStyle(){elements.forEach(function(t){setClass(t,"clickable",t.onclick)})}function updateRoom(t){roomMsgObj=t,game||(mayusRoom=!!t.mayusRoom,inroom||initDeckOptions(),inroom=!0,blocking=!1,hide($("Hall")),hide($("GameDiv")),show($("Room")),show($("Chat")),document.body.removeAttribute("self"),document.body.removeAttribute("opponent"),document.body.classList.remove("gaming"),position=t.me,audio.playBgm("main"),isHost()&&!$("room-guest-nickname").classList.contains("ready")&&t.guestReady&&audio.playSoundEffect("JoinRoom"),$("room-name").textContent=t.roomName,$("room-host-nickname").textContent=t.host,$("room-guest-nickname").textContent=t.guest,setClass($("room-guest-nickname"),"ready",t.guestReady),$("Room").setAttribute("data-position",position),clearOnclicks(),t.hostSpectatorList.forEach(function(t,e){var i=$("host-spectator-"+e),n=!isStr(t);i.textContent=t||"",setClass(i,"locked",n),isHost()?n?i.onclick=function(t){blocking||(socket.emit("unlockSpec",e),blocking=!0)}:i.onclick=function(t){blocking||(socket.emit("lockSpec",e),blocking=!0)}:n||t||(i.onclick=function(t){blocking||(socket.emit("changePosition",{position:"host-spectator",i:e}),blocking=!0)})},this),t.guestSpectatorList.forEach(function(t,e){var i=$("guest-spectator-"+e),n=!isStr(t);i.textContent=t||"",setClass(i,"locked",n),isHost()||n||t||(i.onclick=function(t){blocking||(socket.emit("changePosition",{position:"guest-spectator",i:e}),blocking=!0)})},this),isSpectator()&&!t.guest&&($("room-guest-nickname").onclick=function(t){blocking||(socket.emit("changePosition",{position:"guest",i:0}),blocking=!0)}),setClickableStyle(),isHost()?(show($("button-start-game")),show($("select-decks")),enable($("select-decks")),hide($("container-ready")),show($("container-live")),enable($("button-start-game"),t.guestReady)):isGuest()?(hide($("button-start-game")),show($("select-decks")),show($("container-ready")),hide($("container-live")),t.guestReady?($("input-ready").checked=!0,disable($("select-decks"))):($("input-ready").checked=!1,enable($("select-decks")))):(hide($("button-start-game")),hide($("select-decks")),hide($("container-ready")),hide($("container-live"))))}function joinRoom(t,e){if(t&&checkVersion()){if(!$("input-nickame").value)return void msgBox.alert(Localize.index("PLEASE_INPUT_A_NICKNAME"),function(){$("input-nickame").focus()});if(initDeckOptions())return e?void msgBox.prompt(Localize.index("INPUT_PASSWORD"),function(e){e&&doJoinRoom(t,e)}):void doJoinRoom(t)}}function doJoinRoom(t,e){localStorage.setItem("nickname",$("input-nickame").value),socket.emit("joinRoom",{roomName:t,nickname:$("input-nickame").value,password:e||""})}function watchLive(t){checkVersion()&&(socket.emit("watchLive",{roomName:t}),msgBox.alert(Localize.index("FETCHING_DATA"),function(){stopFetchingLive++,socket.emit("leaveRoom")}))}function updateReplayList(){stopFetchingReplay=!1,socket.emit("getReplayList")}function getReplayContent(t){socket.emit("getReplayContent",t),msgBox.alert(Localize.index("FETCHING_DATA"),function(){stopFetchingReplay=!0})}function readAndPlayReplayFile(){var t=$("input-replay-file").files[0];t&&($("input-replay-file").value=null,readReplayFile(t,function(t){return t?(msgBox.close(),void playReplayContent(t.content)):void msgBox.alert(Localize.index("FAILED_TO_PARSE_REPLAY"),initHall)}))}function playReplayContent(t){function e(){n&&(n=!1,game.addMsgs(t.messagePacks[i++]))}if(t.clientVersion>VERSION)return void msgBox.alert(Localize.index("UNSUPPORTED_REPLAY_VERSION"),initHall);playingReplay=!0,gameStart("replay");var i=0,n=!0,o=!1;game.onidle=function(){n=!0,i>=t.messagePacks.length?($("button-replay-auto").onclick=null,$("button-replay-step").onclick=null,t.surrender&&(t.win?game.win(!0):game.lose(!0))):o&&setTimeout(e,500)},e(),$("button-replay-auto").onclick=function(t){o=!0,e()},$("button-replay-step").onclick=function(t){return o?void(o=!1):void e()}}function readReplayFile(t,e){if(!t||!window.FileReader||!window.JSON)return void e(null);var i=new FileReader;i.onload=function(t){var n=i.result,o=null;try{o=JSON.parse(n)}catch(t){return e(null)}return checkReplayObj(o)?void e(o):e(null)},i.onerror=function(t){e(null)},i.readAsText(t)}function checkReplayObj(t){return!!isObj(t)&&("WEBXOSS Replay"===t.format&&("1"===t.version&&!!isObj(t.content)))}function checkDomain(){var t=location.hostname;"127.0.0.1"!==t&&(t.match(/^(.*\.)?webxoss\.com$/)||msgBox.preset("warn"))}var concat=Array.prototype.concat.bind([]),toArr=function(t){return t?"string"==typeof t?[]:Array.prototype.slice.call(t,0):[]},isArr=Array.isArray,inArr=function(t,e){return toArr(e).indexOf(t)!=-1},removeFromArr=function(t,e){var i=e.indexOf(t);return!(i<0)&&(e.splice(i,1),!0)},isStr=function(t){return"string"==typeof t},isObj=function(t){return t&&"object"==typeof t&&!isArr(t)},isNum=function(t){return"number"==typeof t},isFunc=function(t){return"function"==typeof t},pEach=function(t,e,i){return t.reduce(function(t,i){return t.then(function(){return e(i)})},Promise.resolve())};MessageBox.prototype.alert=function(t,e){this.eWin.className="alert",this.eMsg.textContent=t,this.eWarp.classList.add("shown"),this.eOk.focus(),this.eOk.onclick=function(t){this.close(),e&&e()}.bind(this)},MessageBox.prototype.confirm=function(t,e){this.eWin.className="confirm",this.eMsg.textContent=t,this.eWarp.classList.add("shown"),this.eCancel.focus(),this.eOk.onclick=function(t){this.close(),e&&e(!0)}.bind(this),this.eCancel.onclick=function(t){this.close(),e&&e(!1)}.bind(this)},MessageBox.prototype.prompt=function(t,e,i){2===arguments.length&&(e="",i=arguments[1]),this.eWin.className="prompt",this.eMsg.textContent=t,this.eInput.value=e,this.eWarp.classList.add("shown"),this.eInput.select();var n=function(t){this.close(),i&&i(t||"")}.bind(this);this.eOk.onclick=function(t){n(this.eInput.value)}.bind(this),this.eCancel.onclick=function(t){n()}.bind(this),this.eInput.onkeypress=function(t){var e=t.keyCode||t.which||t.charCode;13===e&&n(this.eInput.value)}.bind(this)},MessageBox.prototype.preset=function(t){this.eWin.className="preset";for(var e=this.ePreset.children,i=0;i<e.length;i++){var n=e[i];n.style.display="none"}document.getElementById("preset-"+t).style.display="",this.eWarp.classList.add("shown")},MessageBox.prototype.close=function(){this.eWarp.classList.remove("shown"),this.eWin.className=""},IO.prototype.receiveGameMessage=function(t){this.inputBlocked||t.buffer.forEach(function(t){if(!(t.id<this.datas.length)){if(t.id!==this.datas.length)return void console.error("buf.id !== this.datas.length");this.sendingMsg=null,this.datas.push(t.data),this.listener&&this.listener(t.data)}},this)},IO.prototype.send=function(t){this.id++,this.sendingMsg={id:this.id,data:t},this.outputBlocked||this.socket.emit("gameMessage",this.sendingMsg)},IO.prototype.resend=function(){this.sendingMsg&&this.socket.emit("gameMessage",this.sendingMsg)},IO.prototype.getDatas=function(){return this.datas},IO.prototype.toggleIn=function(){return this.inputBlocked=!this.inputBlocked},IO.prototype.toggleOut=function(){return this.outputBlocked=!this.outputBlocked},Card.WIDTH=63,Card.HEIGHT=88,Card.prototype=new createjs.Container,Card.prototype.constructor=Card,Card.prototype.up=function(){var t=this.zone.opposite?180:0;this.style.transit("rotation",t,.2)},Card.prototype.down=function(){var t=this.zone.opposite?180:0;t+=90,this.style.transit("rotation",t,.2)},Card.prototype.faceup=function(){this.style.transit("scaleX",1,.2)},Card.prototype.facedown=function(){this.style.transit("scaleX",-1,.2)},Card.prototype.move=function(t,e,i,n,o,s){this.pid=t,this.isSide=s,this.floatdown(),this.zone&&this.zone.removeCard(this),this.zone=e,this.zone.addCard(this,o),i?this.up():this.down(),n?this.faceup():this.facedown()},Card.prototype.moveTo=function(t,e,i,n){var o=this.isSide?0:.2;this.style.transit("x",t,o),this.style.transit("y",e,o),t===this.x&&e===this.y||(this.style.set("top",!0),this.style.transit("top",!1,o)),this.style.set("covered",i),this.style.transit("covered",n,o)},Card.prototype.floatup=function(){this.style.set("top",!0)},Card.prototype.floatdown=function(){this.style.set("top",!1)},Card.prototype.outlineOn=function(){this.style.transit("shadowBlur",5,.2,Style.linear)},Card.prototype.outlineOff=function(){this.style.transit("shadowBlur",0,.2,Style.linear)},Card.prototype.flash=function(){this.style.set("flash",0),this.style.transit("flash",3,.3,Style.linear)},Card.prototype.shine=function(){this.style.set("shine",0),this.style.transit("shine",1,.3,Style.linear)},Card.prototype.addStates=function(t){this.changed=!0,this.stateLayer.visible=!0,t.forEach(function(t){var e=this.game.imageManager.getStateImage(t),i=new createjs.Bitmap(e);this.stateLayer.addChild(i)},this)},Card.prototype.removeStates=function(){this.changed=!0,this.stateLayer.visible=!1,this.stateLayer.removeAllChildren()},Card.prototype.addButton=function(t,e){if(t.constructor===Button){var i=t;return void this.buttonLayer.addButton(i)}var i=new Button(t,e.bind(this,this));this.buttonLayer.addButton(i)},Card.prototype.shouldUseDialog=function(){var t=this.zone.name;return this.zone.constructor===TileZone&&this.zone!==this.game.player.handZone||(!!inArr(t,["MainDeck","LrigDeck","TrashZone","LrigTrashZone"])||("CheckZone"===t&&this.zone.cards.length>1||!(!inArr(t,["SigniZone","LrigZone"])||0===this.zone.getCardIndex(this))))},Card.prototype.removeButtons=function(){this.buttonLayer.removeAllButtons()},Card.prototype.update=function(){var t=this.style.isChanged()||this.changed;if(concat(this.buttonLayer,this.bitmap).forEach(function(e){e.update()&&(t=!0)},this),!t)return!1;this.changed=!1;var e=this.renderLayer,i=(this.effectShape,this.bitmap),n=this.style.getComputedStyle();this.x=n.x,this.y=n.y,this.rotation=n.rotation,this.buttonLayer.rotation=-n.rotation,this.alpha=1-n.flash%1,e.x=n.offX,e.y=n.offY;var o=this.pid?Localize.cardName(CardInfo[this.pid]):"???";if(n.scaleX>0?this.bitmap.setAltImage(o,this.game.imageManager.getImageByPid(this.pid)):this.bitmap.setAltImage(o,this.game.imageManager.getBackImage(this.isWhiteBack)),e.scaleX=Math.abs(n.scaleX),i.shadow=new createjs.Shadow(n.shadowColor,0,0,n.shadowBlur),n.shine>0){var s=40,a=n.shine*(this.width+s)-s,r=n.shine*(this.height+s)-s,c=a+s,h=r+s;this.effectShape.graphics.clear().beginLinearGradientFill(["rgba(255,255,255,0)","white","rgba(255,255,255,0)"],[0,.5,1],a,r,c,h).drawRect(0,0,this.width,this.height)}return this.zIndex=n.top?512:n.zIndex,this.visible=n.top||!n.covered,!0},Card.prototype.handleMouseover=function(t){this.game.cardDetail.show(this.pid),this.zone.opposite||"HandZone"!==this.zone.name||this.floatup()},Card.prototype.handleMouseout=function(t){this.zone.opposite||"HandZone"!==this.zone.name||this.floatdown()},CardBitmap.prototype=new createjs.Container,CardBitmap.prototype.constructor=CardBitmap,CardBitmap.prototype.setAltImage=function(t,e){t===this.alt&&e===this.img||(this.changed=!0,this.alt=t,this.img=e)},CardBitmap.prototype.setWidthHeight=function(t,e){t===this.width&&e===this.height||(this.changed=!0,this.width=t,this.height=e)},CardBitmap.prototype.update=function(){return this.complete!=this.img.complete&&(this.changed=!0),!!this.changed&&(this.changed=!1,this.complete=this.img.complete,this.text.text=this.alt,this.img.complete&&0!==this.img.naturalWidth?(this.bitmap.image=this.img,this.bitmap.scaleX=this.width/this.img.width,this.bitmap.scaleY=this.height/this.img.height,this.bitmap.visible=!0,this.text.visible=!1):(this.bitmap.visible=!1,this.text.visible=!0),!0)},Style.linear=function(t){return t},Style.prototype.transit=function(t,e,i,n){this.checkSkip&&this.checkSkip()&&(i=0),this.transitingStyle[t].transitTo(e,i,n),this.changed=!0},Style.prototype.set=function(t,e){this.transit(t,e)},Style.prototype.getComputedStyle=function(){var t={};for(var e in this.transitingStyle)t[e]=this.transitingStyle[e].getValue(),this.transitingStyle[e].isDone()||(this.changed=!0);return t},Style.prototype.isChanged=function(){var t=this.changed;return this.changed=!1,t},TransitingValue.linear=function(t){return t},TransitingValue.cubic=function(t){var e=1-t;return 1-e*e*e},TransitingValue.prototype.now=function(){return Date.now()},TransitingValue.prototype.transitTo=function(t,e,i){this.startValue=this.getValue(),this.endValue=t,this.duration=e||0,this.timing=i||TransitingValue.cubic,this.changeTime=this.now(),this.done=!1},TransitingValue.prototype.getValue=function(){var t=this.now(),e=this.changeTime,i=e+1e3*this.duration;if(t<e)return this.startValue;if(t>=i||this.startValue===this.endValue)return this.done=!0,this.endValue;if(!isNum(this.endValue))return this.startValue;var n=this.timing((t-e)/(i-e));return this.startValue+n*(this.endValue-this.startValue)},TransitingValue.prototype.isDone=function(){return this.done},Zone.prototype=new createjs.Container,Zone.prototype.constructor=Zone,Zone.prototype.sortCards=function(){var t=this.cards.length;this.cards.forEach(function(e,i){e.style.set("zIndex",t-i)},this)},Zone.prototype.addCard=function(t,e){"SigniZone"===this.name&&"LrigZone"===this.name||t.removeStates(),e?this.cards.push(t):this.cards.unshift(t),this.sortCards(),this.updateCardPosition()},Zone.prototype.removeCard=function(t,e){removeFromArr(t,this.cards),this.sortCards(),this.updateCardPosition()},Zone.prototype.getCardIndex=function(t){return this.cards.indexOf(t)},Zone.prototype.updateCardPosition=function(){},Zone.prototype.update=function(){var t=this.cards.filter(function(t){return!t.isSide},this).length;if(this.showAmount&&this._amount!==t){this._amount=t;var e=0===this._amount?"":this._amount;this.setText(e)}var i=this.buttonLayer.update()||this.changed;return this.changed=!1,i},Zone.prototype.addButton=function(t,e){var i=new Button(t,e.bind(this,this));this.buttonLayer.addButton(i)},Zone.prototype.removeButtons=function(){this.buttonLayer.removeAllButtons(),this.checkable&&this.cards.length>1&&("SigniZone"===this.name?this.cards[0].addButton(this.viewCardsButton):this.buttonLayer.addButton(this.viewCardsButton))},Zone.prototype.setText=function(t){return this.changed=!0,t?(this.text.visible=!0,void(this.text.text=t)):void(this.text.visible=!1)},Zone.prototype.setTextColor=function(t){this.changed=!0,"EnerZone"===this.name?this.text.color="white":this.text.color=t},Zone.prototype.shouldUseDialog=function(){return!1},StackZone.prototype=Object.create(Zone.prototype),StackZone.prototype.constructor=StackZone,StackZone.prototype.updateCardPosition=function(){var t=!1;this.cards.forEach(function(e,i){e.moveTo(this.x,this.y,t,!!i),e.x===this.x&&e.y===this.y&&(t=!0)},this)},StackZone.prototype.addViewCardsButton=function(){this.buttonLayer.addButton(this.viewCardsButton)},Zone.prototype.addStates=function(t){this.changed=!0,this.stateLayer.visible=!0,t.forEach(function(t){var e=this.stateShape.graphics,i=Card.WIDTH,n=Card.HEIGHT;"powerDown"===t?e.f("rgba(164,96,222,0.3)").r(-i/2,-n/2,i,n):"disabled"===t?e.f("rgba(0,0,0,0.7)").r(-i/2,-n/2,i,n):"infected"===t&&e.f("rgba(255,0,0,0.3)").r(-i/2,-n/2,i,n)},this)},Zone.prototype.removeStates=function(){this.changed=!0,this.stateLayer.visible=!1,this.stateShape.graphics.clear()},StackZone.prototype.update=function(){var t=this.changed;return this.showPower?(this._amount!==this.cards.length&&(this._amount=this.cards.length,this.power=this._power=0,this.setText("")),this._power!==this.power&&(this._power=this.power,this.setText(this._power))):Zone.prototype.update.call(this)&&(t=!0),this.changed=!1,t},TileZone.prototype=Object.create(Zone.prototype),TileZone.prototype.constructor=TileZone,TileZone.prototype.updateCardPosition=function(){if(this.cards.length){var t,e=this.spacing;t=this.horizontal?this.up?Card.WIDTH:Card.HEIGHT:this.up?Card.HEIGHT:Card.WIDTH;var i,n,o=this.opposite?-1:1;(t+e)*this.cards.length-e<=this.width?(n=t+e,i=this.center?-n*(this.cards.length-1)/2:t/2):(n=(this.width-t)/(this.cards.length-1),i=this.center?t/2-this.width/2:t/2);var s=this.cards.length;this.horizontal?this.cards.forEach(function(t,e){var a=s-e-1;t.moveTo(this.x+o*(i+a*n),this.y)},this):this.cards.forEach(function(t,e){var a=s-e-1;t.moveTo(this.x,this.y+o*(i+a*n))},this)}},TileZone.prototype.update=function(){return this.buttonLayer.visible=this.cards.length>4,Zone.prototype.update.call(this)},Game.prototype.setSid=function(t,e){t.sid=e,this.objList[e]=t},Game.prototype.getObjBySid=function(t){return this.objList[t]},Game.prototype.addCard=function(t){this.cards.push(t),this.cardLayer.addChild(t)},Game.prototype.addZone=function(t){this.zones.push(t),this.zoneLayer.addChild(t)},Game.prototype.handleInit=function(t){function e(t,e){this.setSid(t.mainDeck,e.mainDeck),this.setSid(t.lrigDeck,e.lrigDeck),this.setSid(t.handZone,e.handZone),this.setSid(t.lrigZone,e.lrigZone),this.setSid(t.signiZones[0],e.signiZones[0]),this.setSid(t.signiZones[1],e.signiZones[1]),this.setSid(t.signiZones[2],e.signiZones[2]),this.setSid(t.enerZone,e.enerZone),this.setSid(t.checkZone,e.checkZone),this.setSid(t.trashZone,e.trashZone),this.setSid(t.lrigTrashZone,e.lrigTrashZone),this.setSid(t.lifeClothZone,e.lifeClothZone),this.setSid(t.excludedZone,e.excludedZone),e.mainDeckCards.forEach(function(e){var i=new Card(this,!1);this.setSid(i,e),i.move(0,t.mainDeck,!0,!1,!1)},this),e.lrigDeckCards.forEach(function(i,n){var o=new Card(this,!0);this.setSid(o,i);var s=e.lrigDeckCardInfos[n];o.move(s.pid,t.lrigDeck,!0,!1,!1,s.isSide)},this)}return this.setSid(this.player,t.player),this.setSid(this.opponent,t.opponent),e.call(this,this.player,t.playerZones),e.call(this,this.opponent,t.opponentZones),!0},Game.prototype.handleSetColor=function(t){document.body.setAttribute("self",t.selfColor),document.body.setAttribute("opponent",t.opponentColor);var e={white:"black",black:"yellow",red:"white",blue:"yellow",green:"white"};this.zones.forEach(function(i){var n=i.opposite?e[t.opponentColor]:e[t.selfColor];i.setTextColor(n)},this);var i=this.audio;return i.bgmFadeOut(function(){i.playBgm(t.selfColor)}),!0},Game.prototype.handlePackedMsgStart=function(){return this._packageCount++,!0},Game.prototype.handlePackedMsgEnd=function(){return this._packageCount--,!0},Game.prototype.handleMoveCard=function(t){var e=this.getObjBySid(t.card),i=this.getObjBySid(t.zone);return e.move(t.pid,i,t.up,t.faceup,t.bottom,t.isSide),!1},Game.prototype.handleUpCard=function(t){var e=this.getObjBySid(t.card);return e.up(),!1},Game.prototype.handleDownCard=function(t){var e=this.getObjBySid(t.card);return e.down(),!1},Game.prototype.handleFaceupCard=function(t){var e=this.getObjBySid(t.card);return e.pid=t.pid,e.faceup(),!1},Game.prototype.handleFacedownCard=function(t){var e=this.getObjBySid(t.card);return e.facedown(),!1},Game.prototype.handleShuffle=function(t){return t.cards.forEach(function(t){var e=this.getObjBySid(t);e.pid=0},this),!0},Game.prototype.handleSelect=function(t){return console.log(t),!!this.skip||(this.selector.addMsg(t),!0);
},Game.prototype.handlePayEner=function(t){if(console.log("handlePayEner",t),this.skip)return!0;var e=t.cards.map(function(t){return this.getObjBySid(t)},this),i=this,n=null;return t.cancelable&&(n=function(){i.input("PAY_ENER",null)}),this.dialog.selectEner(Localize("buttonTitle","PAY_ENER"),e,t.colors,t,function(t){i.input("PAY_ENER",t)},n),!0},Game.prototype.handleShowCards=function(t){if(this.skip)return!0;var e=t.cards.map(function(e,i){var n=this.getObjBySid(e);return n.pid=t.pids[i],n},this),i=this,n=t.label||"CONFIRM";return this.dialog.showCards(Localize("buttonTitle",n),e,function(){i.input("OK")}),!0},Game.prototype.handleShowCardsById=function(t){if(this.skip)return!0;var e=t.ids.map(function(t,e){return{pid:t}},this),i=this,n=t.label||"CONFIRM";return this.dialog.showCards(Localize("buttonTitle",n),e,function(){i.input("OK")}),!0},Game.prototype.handleShowColors=function(t){if(this.skip)return!0;var e=t.colors.map(function(t){return Localize.color(t)}),i=this;return this.dialog.showText(Localize("buttonTitle","COLOR"),e.join(","),function(){i.input("OK")}),!0},Game.prototype.handleShowTypes=function(t){if(this.skip)return!0;var e=t.types.map(function(t){return Localize("cardType",t)}),i=this;return this.dialog.showText(Localize("prop","cardType"),e.join(","),function(){i.input("OK")}),!0},Game.prototype.handleShowEffects=function(t){if(this.skip)return!0;var e=t.effects.map(function(t){return Localize.desc(t)}).join("\n"),i=this;return this.dialog.showText(Localize("gameText","SHOW_EFFECTS_DIALOG_TITLE"),e,function(){i.input("OK")}),!0},Game.prototype.handleShowText=function(t){if(this.skip)return!0;var e="";"number"===t.type?e=t.content:"text"===t.type&&(e=Localize("gameText",t.content));var i=this;return this.dialog.showText(Localize.labelToDialogTitle(t.title),e,function(){i.input("OK")}),!0},Game.prototype.handleInformCards=function(t){return t.cards.forEach(function(e,i){var n=this.getObjBySid(e);n.pid=t.pids[i]},this),!0},Game.prototype.handleCardStates=function(t){var e=t.signiInfos,i=t.lrigInfos,n=t.zoneInfos;return e.forEach(function(t){var e=this.getObjBySid(t.card);e.zone.power=t.power,e.removeStates(),e.addStates(t.states)},this),i.forEach(function(t){var e=this.getObjBySid(t.card);e.removeStates(),e.addStates(t.states)},this),n&&n.forEach(function(t){var e=this.getObjBySid(t.zone);e.removeStates(),e.addStates(t.states)},this),!0},Game.prototype.handleActivate=function(t){var e=this.getObjBySid(t.card);return e.shine(),!1},Game.prototype.handleCardSelected=function(t){var e=this.getObjBySid(t.card);return e.flash(),!1},Game.prototype.handleSelectNumber=function(t){if(this.skip)return!0;var e=t.label,i=t.min,n=t.max,o=t.defaultValue||0,s=Localize.labelToDialogTitle(e),a=this;return this.dialog.selectNumber(s,i,n,o,!1,function(t){a.input(e,t)}),!0},Game.prototype.handleSelectText=function(t){if(this.skip)return!0;var e=t.label,i=Localize.labelToDialogTitle(e),n=t.type||"gameText",o=t.texts.map(function(t){return Localize(n,t)},this),s=this;return this.dialog.selectText(i,o,!1,function(t){s.input(e,t)}),!0},Game.prototype.handleSelectCardId=function(t){if(this.skip)return!0;try{var e=this,i=t.label,n=Localize.labelToDialogTitle(i);this.dialog.selectCardId(n,function(t){e.input(i,t)})}catch(t){window.alert(t.name+t.message)}return!0},Game.prototype.handleCoinChange=function(t){var e=t.player===this.player.sid?this.player:this.opponent;return e.coinZone.setText("Coin"+t.coin),!0},Game.prototype.handleConfirm=function(t){if(this.skip)return!0;var e=Localize.labelToDialogTitle("CONFIRM"),i=Localize("gameText",t.text),n=this;return this.dialog.confirm(e,i,function(t){n.input("OK",t)}),!0},Game.prototype.handleWin=function(t){this.win()},Game.prototype.win=function(t){this.ongameover(!0,t,this.getMessagePacks())},Game.prototype.handleLose=function(t){this.lose()},Game.prototype.lose=function(t){this.ongameover(!1,t,this.getMessagePacks())},Game.prototype.getMessagePacks=function(){return this.io.getDatas()},Game.prototype.handleMsg=function(t){if(!t)return!1;var e={INIT:this.handleInit,SET_COLOR:this.handleSetColor,PACKED_MSG_START:this.handlePackedMsgStart,PACKED_MSG_END:this.handlePackedMsgEnd,MOVE_CARD:this.handleMoveCard,UP_CARD:this.handleUpCard,DOWN_CARD:this.handleDownCard,FACEUP_CARD:this.handleFaceupCard,FACEDOWN_CARD:this.handleFacedownCard,SHUFFLE:this.handleShuffle,SELECT:this.handleSelect,PAY_ENER:this.handlePayEner,SHOW_CARDS:this.handleShowCards,SHOW_CARDS_BY_ID:this.handleShowCardsById,SHOW_COLORS:this.handleShowColors,SHOW_TYPES:this.handleShowTypes,SHOW_EFFECTS:this.handleShowEffects,SHOW_TEXT:this.handleShowText,INFORM_CARDS:this.handleInformCards,CARD_STATES:this.handleCardStates,ACTIVATE:this.handleActivate,CARD_SELECTED:this.handleCardSelected,SELECT_NUMBER:this.handleSelectNumber,SELECT_TEXT:this.handleSelectText,SELECT_CARD_ID:this.handleSelectCardId,CONFIRM:this.handleConfirm,COIN_CHANGE:this.handleCoinChange,WIN:this.handleWin,LOSE:this.handleLose},i=e[t.type];return i?i.call(this,t.content)||this.skip:(console.warn(t),window.alert('Unknown message type: "'+t.type+'" .'),!0)},Game.prototype.handleMsgQueue=function(){if(this.msgQueue.length){this.buttonZone.setText(""),this.background.setWaiting(!1);for(var t,e=!0;(t=this.msgQueue.shift())&&(this.handleMsg(t)||(e=!1),e||this._packageCount););this.msgQueue.length||this.handleIdle()}},Game.prototype.handleIdle=function(){this.selector.removeButtons(),this.selector.showButtons(),this.selector.autoPop(),this.selector.msgs.length||(this.buttonZone.setText(Localize.waitingMsg()),this.background.setWaiting(!0)),this.onidle&&this.onidle()},Game.prototype.addMsgs=function(t){this.selector.clear(),this.msgQueue=this.msgQueue.concat(t),t.length||this.handleIdle()},Game.prototype.input=function(t,e){void 0===e&&(e=[]),this.removeButtons(),this.io.send({label:t,input:e}),this.background.setWaiting(!0)},Game.prototype.removeButtons=function(){this.cards.forEach(function(t){t.removeButtons()},this),this.zones.forEach(function(t){t.removeButtons()},this)},Game.prototype.update=function(){var t=!1;concat(this.cards,this.zones,this.background).forEach(function(e){e.update()&&(t=!0)},this),t?(this.cardLayer.sortChildren(function(t,e){return t.zIndex-e.zIndex}),this.stage.update()):this.handleMsgQueue()},Game.prototype.initZones=function(){this.player={enerZone:new TileZone({game:this,name:"EnerZone",x:92,y:377,up:!1,horizontal:!1,center:!1,width:259,spacing:5,showAmount:!0,checkable:!0}),signiZones:[new StackZone({game:this,name:"SigniZone",x:190,y:421,checkable:!0,showPower:!0}),new StackZone({game:this,name:"SigniZone",x:288,y:421,checkable:!0,showPower:!0}),new StackZone({game:this,name:"SigniZone",x:386,y:421,checkable:!0,showPower:!0})],mainDeck:new StackZone({game:this,name:"MainDeck",x:471.5,y:421,showAmount:!0}),lrigDeck:new StackZone({game:this,name:"LrigDeck",x:544.5,y:421,showAmount:!0,checkable:!0}),checkZone:new StackZone({game:this,name:"CheckZone",x:190,y:519}),lrigZone:new StackZone({game:this,name:"LrigZone",x:288,y:519,showAmount:!0}),trashZone:new StackZone({game:this,name:"TrashZone",x:471.5,y:519,showAmount:!0,checkable:!0}),lrigTrashZone:new StackZone({game:this,name:"LrigTrashZone",x:544.5,y:519,showAmount:!0,checkable:!0}),lifeClothZone:new TileZone({game:this,name:"LifeClothZone",x:158.5,y:604.5,up:!1,horizontal:!0,center:!1,width:3*Card.HEIGHT,spacing:2*-Card.HEIGHT/3,showAmount:!0}),coinZone:new StackZone({game:this,name:"CoinZone",x:471.5,y:604.5,centerText:!0}),excludedZone:new StackZone({game:this,name:"ExcludedZone",x:617.5,y:421}),handZone:new TileZone({game:this,name:"HandZone",x:288,y:690,up:!0,horizontal:!0,center:!0,width:576,spacing:8})},this.opponent={enerZone:new TileZone({game:this,name:"EnerZone",x:484,y:357,opposite:!0,up:!1,horizontal:!1,center:!1,width:259,spacing:5,showAmount:!0,checkable:!0}),signiZones:[new StackZone({game:this,name:"SigniZone",x:386,y:313,checkable:!0,showPower:!0,opposite:!0}),new StackZone({game:this,name:"SigniZone",x:288,y:313,checkable:!0,showPower:!0,opposite:!0}),new StackZone({game:this,name:"SigniZone",x:190,y:313,checkable:!0,showPower:!0,opposite:!0})],mainDeck:new StackZone({game:this,name:"MainDeck",x:104.5,y:313,showAmount:!0,opposite:!0}),lrigDeck:new StackZone({game:this,name:"LrigDeck",x:31.5,y:313,showAmount:!0,opposite:!0}),lrigZone:new StackZone({game:this,name:"LrigZone",x:288,y:215,showAmount:!0,opposite:!0}),checkZone:new StackZone({game:this,name:"CheckZone",x:386,y:215,opposite:!0}),trashZone:new StackZone({game:this,name:"TrashZone",x:104.5,y:215,showAmount:!0,opposite:!0,checkable:!0}),lrigTrashZone:new StackZone({game:this,name:"LrigTrashZone",x:31.5,y:215,showAmount:!0,opposite:!0,checkable:!0}),lifeClothZone:new TileZone({game:this,name:"LifeClothZone",x:417.5,y:129.5,opposite:!0,up:!1,horizontal:!0,center:!1,width:3*Card.HEIGHT,spacing:2*-Card.HEIGHT/3,showAmount:!0}),coinZone:new StackZone({game:this,name:"CoinZone",x:104.5,y:129.5,centerText:!0}),excludedZone:new StackZone({game:this,name:"ExcludedZone",x:-41.5,y:313,opposite:!0}),handZone:new TileZone({game:this,name:"HandZone",x:288,y:44,opposite:!0,up:!0,horizontal:!0,center:!0,width:576,spacing:8})},this.buttonZone=new StackZone({game:this,name:"ButtonZone",x:386,y:519,centerText:!0}),this.player.coinZone.text.font="14px monospace",this.opponent.coinZone.text.font="14px monospace"},Button.HEIGHT=11,Button.prototype=new createjs.Container,Button.prototype.constructor=Button,Button.prototype.toDefaultStyle=function(){this.changed=!0,this.text.color="#444",this.background.graphics.clear().beginStroke("#c0c0c0").beginLinearGradientFill(["#ededed","#ededed","#dedede"],[0,.38,1],0,0,0,this.height).drawRoundRect(0,0,this.width,this.height,2)},Button.prototype.toHoverStyle=function(){this.changed=!0,this.text.color="#000",this.background.graphics.clear().beginStroke("#afafaf").beginLinearGradientFill(["#f0f0f0","#f0f0f0","#e0e0e0"],[0,.38,1],0,0,0,this.height).drawRoundRect(0,0,this.width,this.height,2)},Button.prototype.update=function(){var t=this.changed;return this.changed=!1,t},ButtonList.prototype=new createjs.Container,ButtonList.prototype.constructor=ButtonList,ButtonList.prototype.addButton=function(t){this.changed=!0,this.buttons.push(t),this.addChild(t)},ButtonList.prototype.setButtonPositions=function(){var t=-this.buttons.length/2+.5;this.buttons.forEach(function(e,i){e.x=0,e.y=(t+i)*e.height})},ButtonList.prototype.removeButton=function(t){removeFromArr(t,this.buttons),this.removeChild(t)&&(this.changed=!0)},ButtonList.prototype.removeAllButtons=function(){this.buttons.length&&(this.changed=!0,this.buttons.length=0,this.removeAllChildren())},ButtonList.prototype.update=function(){this.changed&&this.setButtonPositions();var t=this.changed;return this.buttons.forEach(function(e){e.update()&&(t=!0)}),this.changed=!1,t},Selector.prototype.addMsg=function(t){this.msgs.push(this.parseMsg(t))},Selector.prototype.parseMsg=function(t){var e={label:t.label,min:t.min,max:t.max,careOrder:t.careOrder};return e.title=Localize.labelToTitle(t.label),e.cards=t.options.map(function(t){return this.game.getObjBySid(t)},this),e.extraCards=t.extraCards.map(function(e,i){var n=this.game.getObjBySid(e);return n.pid=t.extraPids[i],n},this),e.extraCards.length||(e.extraCards=e.cards.slice()),e.descriptions=t.descriptions.map(function(t){return Localize.desc(t)},this),e},Selector.prototype.showButtons=function(){this.msgs.forEach(function(t){var e=t.extraCards;if(e.length)if("USE_ACTION_EFFECT"===t.label){var i=[];t.cards.forEach(function(e,n){var o,s=t.descriptions[n];o=e.shouldUseDialog()?e.zone.constructor===TileZone?this.game.buttonZone:e.zone:e,"EnerZone"===e.zone.name&&(o=e.zone.cards.length>4?e.zone:e);for(var a,r=0;r<i.length;r++){var a=i[r];if(a.buttonCarrier===o)return a.cards.push(e),a.descriptions.push(s),void a.indexes.push(n)}i.push({buttonCarrier:o,cards:[e],descriptions:[s],indexes:[n]})},this),i.forEach(function(e){e.buttonCarrier.addButton(t.title,function(){if(1===e.cards.length&&e.buttonCarrier.constructor===Card)this.send(t,[e.indexes[0]]);else{var i={min:1,max:1,texts:e.descriptions,canClose:!0,careOrder:!1,targets:e.cards};this.game.dialog.selectSomeCards(t.title,e.cards,i,function(i){var n=i[0];this.send(t,[e.indexes[n]])}.bind(this))}}.bind(this))},this)}else{var n=t.descriptions.length||e.some(function(t){return t.shouldUseDialog()},this);if(n){this._autoPopMsg=t;var o=e[0].zone,s=e.every(function(t){return t.zone===o},this);s&&o.constructor!==TileZone?"GROW"===t.label&&(o=this.game.player.lrigZone):o=this.game.buttonZone,o.addButton(t.title,this.popDialogBind(t)),t.min||this.game.buttonZone.addButton(Localize.giveUp(t.label),this.sendBind(t))}else this.showMsgButtons(t)}else this.game.buttonZone.addButton(Localize.noOptions(t.label),this.selectBind(t))},this)},Selector.prototype.select=function(t,e){if(!this.spectating){if(isNum(e)&&this.selectedIndexes.push(e),this.selectedIndexes.length>=t.max)return void this.send(t);this.removeButtons(),this.showMsgButtons(t)}},Selector.prototype.selectBind=function(t,e){return this.select.bind(this,t,e)},Selector.prototype.unselect=function(t,e){this.spectating||(removeFromArr(e,this.selectedIndexes),this.removeButtons(),this.selectedIndexes.length?this.showMsgButtons(t):this.showButtons())},Selector.prototype.unselectBind=function(t,e){return this.unselect.bind(this,t,e)},Selector.prototype.showMsgButtons=function(t){if(t.cards.forEach(function(e,i){inArr(i,this.selectedIndexes)?e.addButton("-"+t.title,this.unselectBind(t,i)):e.addButton(t.title,this.selectBind(t,i))},this),this.selectedIndexes.length>=t.min){var e;e=this.selectedIndexes.length?Localize("buttonTitle","END_SELECT"):Localize.giveUp(t.label),this.game.buttonZone.addButton(e,this.sendBind(t))}},Selector.prototype.send=function(t,e){this.spectating||(isArr(e)||(e=this.selectedIndexes),this.game.input(t.label,e.slice()),console.log('game.input("'+t.label+'",['+e.toString()+"]);"),this.clear())},Selector.prototype.sendBind=function(t){return this.send.bind(this,t)},Selector.prototype.popDialog=function(t){var e=Localize.labelToDialogTitle(t.label),i=t.extraCards,n={min:t.min,max:t.max,texts:t.descriptions,canClose:!0,careOrder:t.careOrder,targets:t.cards};this.game.dialog.selectSomeCards(e,i,n,this.sendBind(t))},Selector.prototype.popDialogBind=function(t){return this.popDialog.bind(this,t)},Selector.prototype.removeButtons=function(){this.game.removeButtons()},Selector.prototype.autoPop=function(){if(1===this.msgs.length&&this._autoPopMsg){if("SPELL_CUT_IN"===this._autoPopMsg.label)return;this.popDialog(this._autoPopMsg)}},Selector.prototype.clear=function(){this.removeButtons(),this.game.dialog.close(),this.selectedIndexes.length=0,this.msgs.length=0,this._autoPopMsg=null},Dialog.prototype.newElement=function(t){return document.createElement(t)},Dialog.prototype.newCardImg=function(t){var e=this.newElement("img");return e.src=this.game.imageManager.getUrlByPid(t),e},Dialog.prototype.mouseover=function(t,e){t.onmouseover=this.game.cardDetail.show.bind(this.game.cardDetail,e)},Dialog.prototype.center=function(t){var e=t.parentElement;t.style.top="0",t.style.left="0",t.style.top=(e.offsetHeight-t.offsetHeight)/2+"px",t.style.left=(e.offsetWidth-t.offsetWidth)/2+"px"},Dialog.prototype.pop=function(t,e,i,n,o,s){var a=this;this.titleDiv.textContent=t,this.footSpan.innerHTML="",i&&this.footSpan.appendChild(i),this.bodyDiv.innerHTML="",this.bodyDiv.style.width="",this.bodyDiv.appendChild(e),this.closeIcon.style.display=n?"":"none",o?(this.okBtn.onclick=function(t){a.close(),o()},this.footerDiv.style.display=""):(this.okBtn.onclick=null,this.footerDiv.style.display="none"),s?(this.cancelBtn.onclick=function(t){a.close(),s()},this.cancelBtn.style.display=""):(this.cancelBtn.onclick=null,this.cancelBtn.style.display="none"),this.warpDiv.style.opacity="0",this.warpDiv.style.display="",this.center(this.dialogDiv),this.warpDiv.style.opacity="1"},Dialog.prototype.close=function(){this.okBtn.disabled=!1,this.warpDiv.style.display="none"},Dialog.prototype.showText=function(t,e,i){var n=document.createTextNode(e);this.pop(t,n,null,!1,i)},Dialog.prototype.confirm=function(t,e,i){var n=document.createTextNode(e);this.pop(t,n,null,!1,i.bind(null,!0),i.bind(null,!1))},Dialog.prototype.selectText=function(t,e,i,n){var o=this,s=this.newElement("div");e.forEach(function(t,e){var i=this.newElement("div");i.classList.add("option"),i.textContent=t,s.appendChild(i),i.onclick=function(t){o.close(),n(e)}},this),this.pop(t,s,null,i,null)},Dialog.prototype.selectNumber=function(t,e,i,n,o,s){for(var a=this.newElement("div"),r=this.newElement("select"),c=e;c<=i;c++){var h=this.newElement("option");h.value=c,h.textContent=c,r.appendChild(h)}r.value=n,a.appendChild(r),this.pop(t,a,null,o,function(){s(r.value)})},Dialog.prototype.showCards=function(t,e,i){var n=this.newElement("div");e.length?e.forEach(function(t){var e=this.newElement("div"),i=this.newCardImg(t.pid);e.appendChild(i),e.classList.add("card"),this.mouseover(e,t.pid),n.appendChild(e)},this):n.textContent=Localize("common","NO_CARDS"),this.pop(t,n,null,!1,i)},Dialog.prototype.selectCardId=function(t,e){function i(){var t=c.value;d=a.search(t),n()}function n(){p=0,h.innerHTML="",o()}function o(){for(var t=0;t<u;t++){var i=p;if(i>=d.length)break;var n=d[i].pid,o=s.newElement("div"),a=s.newCardImg(n);o.appendChild(a),o.classList.add("card"),s.mouseover(o,n),o.onclick=function(t){s.close(),e(t)}.bind(null,n),h.appendChild(o),p++}}var s=this,a=this.searcher,r=this.newElement("div");r.style.textAlign="center";var c=this.newElement("input");c.setAttribute("placeholder","Search..."),c.type="text",c.style.textAlign="center",c.style.width="90%";var h=this.newElement("div");h.style.maxHeight="450px",h.style["overflow-y"]="auto",h.style.textAlign="left";var l=this.newElement("div");l.textContent="Show More...",l.style.color="blue",l.style.cursor="pointer",l.style.margin="1em 0",r.appendChild(c),r.appendChild(h),r.appendChild(l);var d=[],u=9,p=0;l.onclick=o,c.onchange=c.onkeyup=i,i(),this.pop(t,r,null,!1,null),r.style.minWidth=r.offsetWidth+"px",c.focus()},Dialog.prototype.selectCard=function(t,e,i,n){var o=this,s=this.newElement("div");e.forEach(function(t,e){var i=this.newElement("div"),a=this.newCardImg(t.pid);i.appendChild(a),i.classList.add("card"),this.mouseover(i,t.pid),i.onclick=function(t){o.close(),n(e)},s.appendChild(i)},this),this.pop(t,s,null,i,null)},Dialog.prototype.selectCardAdvanced=function(t,e,i,n,o,s,a,r){function c(){u.forEach(function(t,e){t.opt.classList.remove("disabled")},this);var t=s(d,h);l.okBtn.disabled=!t,o&&u.forEach(function(t,e){var i=d.indexOf(e)+1;t.num.textContent=i||"",l.center(t.num)},this)}function h(t){u[t].opt.classList.add("disabled")}i||(i=[]);var l=this,d=[],u=[],p=this.newElement("div");e.forEach(function(t,e){var n=this.newElement("div"),o=this.newCardImg(t.pid),s=this.newElement("div");s.textContent=i[e]||"";var a=this.newElement("div"),r=this.newElement("div");n.appendChild(o),n.appendChild(s),n.appendChild(a),n.appendChild(r),n.classList.add("card"),s.classList.add("txt"),a.classList.add("msk"),r.classList.add("num"),this.mouseover(n,t.pid);var h={opt:n,txt:s,msk:a,num:r};u[e]=h,n.onclick=function(t){!n.classList.contains("selected")&&n.classList.contains("disabled")||(n.classList.contains("selected")?removeFromArr(e,d):d.push(e),n.classList.toggle("selected"),c())},p.appendChild(n)},this),c(),l.pop(t,p,null,n,a.bind(null,d),r),u.forEach(function(t){this.center(t.txt)},this)},Dialog.prototype.selectSomeCards=function(t,e,i,n){var o=i.min||0,s=i.max;s||(s=i.targets?i.targets.length:e.length);var a,r=i.texts,c=i.canClose,h=i.careOrder,l=i.targets;a=o?null:n.bind(null,[]),this.selectCardAdvanced(t,e,r,c,h,function(t,i){l&&l.length&&e.forEach(function(t,e){inArr(t,l)||i(e)},this);var n=t.length;return n>=s?(e.forEach(function(t,e){i(e)},this),!0):n&&n>=o},function(t){l&&l.length&&l.length!==e.length&&(t=t.map(function(t){return l.indexOf(e[t])})),n(t)},a)},Dialog.prototype.selectEner=function(t,e,i,n,o,s){function a(t,o){var s={},a=0;if(["colorless","white","black","red","blue","green","multi"].forEach(function(t){s[t]=n[t]||0,a+=s[t]},this),t.length>=a)return e.forEach(function(t,e){o(e)},this),!0;var r=[];return t.forEach(function(t){var e=i[t];if("multi"!==e)return isArr(e)?void r.push(e):void(s[e]>0?s[e]-=1:s.colorless-=1)},this),r.forEach(function(t){for(var e=0;e<t.length;e++){var i=t[e];if(s[i]>0)return void(s[i]-=1)}s.colorless-=1}),!(s.colorless>0)&&void e.forEach(function(t,e){var n=i[e];if("multi"!==n){if(isArr(n)){if(n.some(function(t){return s[t]>0}))return;return o(e)}s[n]||o(e)}},this)}var r=e.map(function(t){return t.sid===n.source?"WARN":""},this);this.selectCardAdvanced(t,e,r,!1,!1,a,o,s)},GameBackground.prototype=new createjs.Container,GameBackground.prototype.constructor=GameBackground,GameBackground.prototype.setWaiting=function(t){t?this.mask.graphics.clear().beginFill("rgba(0,0,0,0.25)").drawRect(0,0,this.width,this.height):this.mask.graphics.clear(),this.changed=!0},GameBackground.prototype.update=function(){var t=this.changed;return this.changed=!1,t},window.FakeSocket=function(){function t(t){this._win=t,this._listeners={},this.id="<"+e.push(this)+">",this.io={reconnection:function(){},opts:{query:""}}}var e=[];return window.addEventListener("message",function(t){var i=t.source,n=t.data.name,o=t.data.data;"tick"!==n&&"tock"!==n&&console.log(JSON.stringify(t.data));for(var s=0;s<e.length;s++){var a=e[s];if(a._win===i)return void a._doEmit(n,o)}}),t.prototype.on=function(t,e){this._listeners[t]||(this._listeners[t]=[]),this._listeners[t].push(e)},t.prototype.emit=function(t,e){this._win.postMessage({name:t,data:e},"*")},t.prototype._doEmit=function(t,e){var i=this._listeners[t];i&&i.forEach(function(t){t(e)})},t.prototype.disconnect=function(){this.emit("disconnect")},t.prototype.removeAllListeners=function(t){var e=this._listeners[t];e&&(e.length=0)},t}(),GameAudio.prototype.loadSettings=function(){"disabled"===localStorage.getItem("bgm")&&(this.bgmDisabled=!0),"disabled"===localStorage.getItem("sound effect")&&(this.seDisabled=!0),this.bgmCheckBox.checked=!this.bgmDisabled,this.seCheckBox.checked=!this.seDisabled},GameAudio.prototype.disableBgm=function(t){t?(this.bgmDisabled=!0,localStorage.setItem("bgm","disabled"),this.bgm.pause(),this.bgm.src=""):(this.bgmDisabled=!1,localStorage.setItem("bgm","enabled"),this.bgm.src=this.lastPlay,this.bgm.play())},GameAudio.prototype.disableSoundEffect=function(t){t?(this.seDisabled=!0,localStorage.setItem("sound effect","disabled")):(this.bgmDisabled=!1,localStorage.setItem("sound effect","enabled"))},GameAudio.prototype.bgmFadeOut=function(t){var e=this.bgm,i=setInterval(function(){return e.volume<=.2?(e.volume=0,clearInterval(i),void t()):void(e.volume-=.2)},200)},GameAudio.prototype.playBgm=function(t){if(!t)return this.bgm.src="",void(this.lastPlay="");var e="./background/"+this.map[t]+".mp3";this.lastPlay!==e&&(this.lastPlay=e,this.bgmDisabled||(this.bgm.src=e,this.bgm.volume=1,this.bgm.play()))},GameAudio.prototype.playSoundEffect=function(t){this.seDisabled||(this.soundEffect.src="./background/"+t+".mp3",this.soundEffect.play())},ChatManager.prototype.sendMsg=function(t){t&&this.socket.emit("chat",t)},ChatManager.prototype.addSysMsg=function(t){var e=document.createElement("div");e.classList.add("sys"),e.textContent=t,this.dialogue.appendChild(e),this.dialogue.scrollTop=this.dialogue.scrollHeight},ChatManager.prototype.addMsg=function(t,e,i,n){var o=document.createElement("div");i&&o.classList.add("opponent"),n&&o.classList.add("spectator");var s=document.createElement("span");s.classList.add("name"),s.textContent=t;var a=document.createElement("span");a.classList.add("content"),a.textContent=e,o.appendChild(s),o.appendChild(a),this.dialogue.appendChild(o),this.dialogue.children.length>64&&this.dialogue.removeChild(this.dialogue.firstChild),this.dialogue.scrollTop=this.dialogue.scrollHeight},ChatManager.prototype.clear=function(){this.dialogue.innerHTML=""};var $=document.getElementById.bind(document);window.applicationCache&&(applicationCache.addEventListener("progress",function(t){if($("div-notice").classList.add("shown"),t.loaded===t.total){$("div-notice").classList.add("green");var e=document.createElement("a");e.href=location.href,e.textContent=Localize.index("UPDATE_READY"),$("span-notice").innerHTML="",$("span-notice").appendChild(e)}else{var i=(t.loaded/t.total*100).toFixed(0)+"%";$("span-notice").textContent=Localize.index("UPDATING")+i}},!1),applicationCache.addEventListener("error",function(t){console.warn(t)},!1));var VERSION=68,serverVersion,clientId=0,game=null,position="",mayusRoom=!0,inroom=!1,blocking=!1,roomMsgObj=null,audio=new GameAudio,msgBox=new MessageBox,deckManager=new DeckManager,socket;if("?local=true"===location.search)socket=new FakeSocket(window.opener),window.socket=socket,window.game=game;else{console.log=function(){window._lastLog=arguments};var host=getProxy();host||(host=/:\d*$/.test(location.host)?location.host.replace(/:\d*$/,":2015"):location.host+":2015");var url=location.protocol+"//"+host;socket=io(url,{reconnection:!1,reconnectionDelay:3e3,reconnectionDelayMax:3e4,reconnectionAttempts:10})}"?debug"===location.search&&(window.socket=socket);var chatManager=new ChatManager(socket);$("span-set-proxy").onclick=function(){$("select-proxy").value=getProxy(),msgBox.preset("proxy")},$("proxy-button-ok").onclick=function(){var t=$("select-proxy").value;return getProxy()===t?void msgBox.close():(localStorage.setItem("proxy",t),void reload())},$("select-proxy").onchange=function(){"provide"===$("select-proxy").value&&msgBox.alert(Localize.index("PROVIDE_PROXY_SERVER"))},createjs.Ticker.on("tick",function(t){game&&game.update()}),initLanguage(),initInputValues(),initHall(),$("select-language").onchange=function(){Localize.setLanguage($("select-language").value),Localize.DOM("index")},socket.on("error",function(t){return audio.playBgm(),"MAX_SOCKETS_PER_IP"===t||"MAX_SOCKETS"===t?void msgBox.alert(t):void msgBox.alert(Localize.index("NET_WORK_ERROR"),reload)}),socket.on("disconnect",function(t){console.log("disconnect"),socket.io.reconnection()?msgBox.preset("reconnect"):(game=null,audio.playBgm(),msgBox.alert(Localize.index("DISCONNECTED"),reload))}),socket.on("reconnect_failed",function(t){msgBox.alert("RECONNECT_FAILED",reload)}),socket.on("reconnect_attempt",function(){console.log("reconnect_attempt"),socket.io.opts.query="clientId="+clientId}),socket.on("reconnect",function(t){console.log("reconnect")}),socket.on("error message",function(t){msgBox.alert(t)}),socket.on("client id",function(t){clientId=t,console.log("clientId = %s",t)}),socket.on("game reconnect",function(){console.log("game reconnect"),msgBox.close(),game.io.resend()}),socket.on("game reconnect failed",function(){console.log("game reconnect failed"),msgBox.alert(Localize.index("DROPPED"),initHall)}),socket.on("wait for reconnect",function(){console.log("wait for reconnect"),socket.io.reconnection(!1),enable($("wait-for-reconnect-button-drop"),!isSpectator()),msgBox.preset("wait-for-reconnect")}),$("wait-for-reconnect-button-drop").onclick=function(t){disable(this),socket.emit("drop")},socket.on("opponent reconnect",function(){console.log("opponent reconnect"),socket.io.reconnection(!0),msgBox.close()}),socket.on("version",function(t){serverVersion=t}),socket.on("game start",function(t){gameStart()}),socket.on("update room list",function(t){$("room-list").innerHTML="";var e=[];t.forEach(function(t){var i=document.createElement("li");t.mayusRoom||i.classList.add("no-mayus-room"),t.live?(i.textContent=t.roomName,i.classList.add("live"),i.onclick=watchLive.bind(null,t.roomName),e.push(i)):(i.textContent=t.roomName+" ("+t.count+"/"+t.total+")",t.passwordRequired&&i.classList.add("password-required"),i.onclick=joinRoom.bind(null,t.roomName,t.passwordRequired),$("room-list").appendChild(i))}),e.forEach(function(t){$("room-list").appendChild(t)})}),socket.on("update online counter",function(t){$("span-online-counter").textContent=t}),function(){function t(){i=!1,e=Date.now(),socket.emit("tick"),setTimeout(function(){i||($("span-latency").classList.add("warn"),$("span-latency").textContent=">500ms")},1e3)}var e=0,i=!1;socket.on("tock",function(){i=!0;var n=Math.round((Date.now()-e)/2);n<500&&($("span-latency").textContent=n+"ms",$("span-latency").classList.remove("warn")),setTimeout(t,1e3)}),t()}();for(var elements=[$("room-guest-nickname")],i=0;i<5;i++){elements.push($("host-spectator-"+i)),elements.push($("guest-spectator-"+i));var checkbox=$("checkbox-spectator-"+i);checkbox.onchange=function(t,e){return blocking?e.returnValue=!1:(this.checked?socket.emit("unlockSpec",t):socket.emit("lockSpec",t),void(blocking=!0))}.bind(checkbox,i)}socket.on("update room",function(t){roomMsgObj=t,updateRoom(t)}),socket.on("host left",function(){initHall()}),socket.on("kicked",function(){initHall()}),$("span-leave-room").onclick=function(){socket.emit("leaveRoom"),initHall()},socket.on("wrong password",function(){msgBox.alert(Localize.index("WRONG_PASSWORD"))}),socket.on("host disconnected",function(){if(game){var t=Localize.index("OPPONENT_DISCONNECTED");"host-spectator"===position&&(t=Localize.index("SELF_DISCONNECTED")),msgBox.alert(t,initHall)}else initHall()}),socket.on("guest disconnected",function(){var t=Localize.index("OPPONENT_DISCONNECTED");"guest-spectator"===position&&(t=Localize.index("SELF_DISCONNECTED")),msgBox.alert(t,initHall)}),$("span-surrender").onclick=function(){game&&msgBox.confirm(Localize.index("CONFIRM_SURRENDER"),function(t){t&&socket.emit("surrender")})},$("span-leave-game").onclick=function(){game&&(playingReplay||socket.emit("leaveRoom"),initHall())},socket.on("surrendered",function(){game&&game.lose(!0)}),socket.on("opponent surrendered",function(){game&&game.win(!0)}),$("button-create-room").onclick=function(t){if(checkVersion()){if(!$("input-nickame").value)return void msgBox.alert(Localize.index("PLEASE_INPUT_A_NICKNAME"),function(){$("input-nickame").focus()});if(!$("input-room-name").value)return void msgBox.alert(Localize.index("PLEASE_INPUT_A_ROOM_NAME"),function(){$("input-room-name").focus()});mayusRoom=$("checkbox-mayus-room").checked,initDeckOptions()&&(localStorage.setItem("room name",$("input-room-name").value),localStorage.setItem("nickname",$("input-nickame").value),localStorage.setItem("password",$("input-create-room-password").value),socket.emit("createRoom",{roomName:$("input-room-name").value,nickname:$("input-nickame").value,password:$("input-create-room-password").value,mayusRoom:mayusRoom}))}},$("input-ready").onchange=function(t){if(blocking)return t.returnValue=!1;if($("input-ready").checked){var e=deckManager.loadDeck($("select-decks").value);if(!e)return void msgBox.alert(Localize.index("FAILED_TO_READ_DECK"),function(){$("input-ready").checked=!1});disable($("select-decks")),socket.emit("ready",e),blocking=!0}else enable($("select-decks")),socket.emit("unready"),blocking=!0},$("button-start-game").onclick=function(t){if(blocking)return t.returnValue=!1;var e=deckManager.loadDeck($("select-decks").value);if(!e)return void msgBox.alert(Localize.index("FAILED_TO_READ_DECK"));var i=e;i.live=$("input-live").checked,localStorage.setItem("live",i.live),socket.emit("startGame",i),blocking=!0},$("link-edit-deck").onclick=function(t){return window.open($("link-edit-deck").href),t.preventDefault(),!1};var stopFetchingLive=0,watchingLive=!1;socket.on("liveData",function(t){return stopFetchingLive?void stopFetchingLive--:t?(msgBox.close(),watchingLive=!0,gameStart("live"),game.skip=!0,t.forEach(function(t,e){game.io.receiveGameMessage({buffer:[{id:e,data:t}]})}),game.handleMsgQueue(),void(game.skip=!1)):void msgBox.alert(Localize.index("FAILED_TO_FETCH_DATA"))});var stopFetchingReplay=!1;socket.on("replayList",function(t){$("replay-list").innerHTML="",t.forEach(function(t){var e=newElement("li"),i=CardInfo[t.selfLrig],n=CardInfo[t.opponentLrig],o=Localize.classes(i)+" vs "+Localize.classes(n);
o=o.replace(/\n/g,""),e.textContent=o,e.onclick=getReplayContent.bind(null,t.id),$("replay-list").appendChild(e)})}),socket.on("replayContent",function(t){if(!stopFetchingReplay){if(!t)return void msgBox.alert(Localize.index("FAILED_TO_FETCH_DATA"));msgBox.close(),playReplayContent(t)}}),socket.on("chat",function(t){var e=["host","host-spectator"],i=["guest","guest-spectator"],n=["host-spectator","guest-spectator"],o=inArr(position,e)&&inArr(t.position,i)||inArr(position,i)&&inArr(t.position,e),s=inArr(t.position,n);chatManager.addMsg(t.nickname,t.content,o,s)}),$("checkbox-bgm").onchange=function(t){audio.disableBgm(!$("checkbox-bgm").checked)},$("checkbox-sound-effect").onchange=function(t){audio.disableSoundEffect(!$("checkbox-sound-effect").checked)};var playingReplay=!1;$("span-play-replay").onclick=function(t){$("input-replay-file").value=null,msgBox.preset("replay"),updateReplayList()},$("button-replay-return").onclick=function(t){msgBox.close()},$("input-replay-file").onchange=function(t){readAndPlayReplayFile()},window.onbeforeunload=function(t){if(game&&"?local=true"!==location.search){var e=Localize.index("CONFIRM_CLOSE");return t.returnValue=e,e}},checkDomain(),/iPhone|Android/i.test(navigator.userAgent)&&($("link-edit-deck").onclick=function(t){window.confirm("Do you like to try our new DeckEditor for mobile phone?")&&(t.preventDefault(),location="/next/")});