var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(x,E,F){x!=Array.prototype&&x!=Object.prototype&&(x[E]=F.value)};$jscomp.getGlobal=function(x){return"undefined"!=typeof window&&window===x?x:"undefined"!=typeof global&&null!=global?global:x};$jscomp.global=$jscomp.getGlobal(this);$jscomp.SYMBOL_PREFIX="jscomp_symbol_";
$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};$jscomp.Symbol=function(){var x=0;return function(E){return $jscomp.SYMBOL_PREFIX+(E||"")+x++}}();
$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var x=$jscomp.global.Symbol.iterator;x||(x=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[x]&&$jscomp.defineProperty(Array.prototype,x,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};$jscomp.arrayIterator=function(x){var E=0;return $jscomp.iteratorPrototype(function(){return E<x.length?{done:!1,value:x[E++]}:{done:!0}})};
$jscomp.iteratorPrototype=function(x){$jscomp.initSymbolIterator();x={next:x};x[$jscomp.global.Symbol.iterator]=function(){return this};return x};$jscomp.makeIterator=function(x){$jscomp.initSymbolIterator();$jscomp.initSymbol();$jscomp.initSymbolIterator();var E=x[Symbol.iterator];return E?E.call(x):$jscomp.arrayIterator(x)};
$jscomp.polyfill=function(x,E,F,B){if(E){F=$jscomp.global;x=x.split(".");for(B=0;B<x.length-1;B++){var r=x[B];r in F||(F[r]={});F=F[r]}x=x[x.length-1];B=F[x];E=E(B);E!=B&&null!=E&&$jscomp.defineProperty(F,x,{configurable:!0,writable:!0,value:E})}};$jscomp.FORCE_POLYFILL_PROMISE=!1;
$jscomp.polyfill("Promise",function(x){function E(){this.batch_=null}function F(n){return n instanceof r?n:new r(function(r,q){r(n)})}if(x&&!$jscomp.FORCE_POLYFILL_PROMISE)return x;E.prototype.asyncExecute=function(n){null==this.batch_&&(this.batch_=[],this.asyncExecuteBatch_());this.batch_.push(n);return this};E.prototype.asyncExecuteBatch_=function(){var n=this;this.asyncExecuteFunction(function(){n.executeBatch_()})};var B=$jscomp.global.setTimeout;E.prototype.asyncExecuteFunction=function(n){B(n,
0)};E.prototype.executeBatch_=function(){for(;this.batch_&&this.batch_.length;){var n=this.batch_;this.batch_=[];for(var r=0;r<n.length;++r){var q=n[r];n[r]=null;try{q()}catch(P){this.asyncThrow_(P)}}}this.batch_=null};E.prototype.asyncThrow_=function(n){this.asyncExecuteFunction(function(){throw n;})};var r=function(n){this.state_=0;this.result_=void 0;this.onSettledCallbacks_=[];var r=this.createResolveAndReject_();try{n(r.resolve,r.reject)}catch(q){r.reject(q)}};r.prototype.createResolveAndReject_=
function(){function n(n){return function(t){q||(q=!0,n.call(r,t))}}var r=this,q=!1;return{resolve:n(this.resolveTo_),reject:n(this.reject_)}};r.prototype.resolveTo_=function(n){if(n===this)this.reject_(new TypeError("A Promise cannot resolve to itself"));else if(n instanceof r)this.settleSameAsPromise_(n);else{a:switch(typeof n){case "object":var x=null!=n;break a;case "function":x=!0;break a;default:x=!1}x?this.resolveToNonPromiseObj_(n):this.fulfill_(n)}};r.prototype.resolveToNonPromiseObj_=function(n){var r=
void 0;try{r=n.then}catch(q){this.reject_(q);return}"function"==typeof r?this.settleSameAsThenable_(r,n):this.fulfill_(n)};r.prototype.reject_=function(n){this.settle_(2,n)};r.prototype.fulfill_=function(n){this.settle_(1,n)};r.prototype.settle_=function(n,r){if(0!=this.state_)throw Error("Cannot settle("+n+", "+r+"): Promise already settled in state"+this.state_);this.state_=n;this.result_=r;this.executeOnSettledCallbacks_()};r.prototype.executeOnSettledCallbacks_=function(){if(null!=this.onSettledCallbacks_){for(var n=
0;n<this.onSettledCallbacks_.length;++n)ya.asyncExecute(this.onSettledCallbacks_[n]);this.onSettledCallbacks_=null}};var ya=new E;r.prototype.settleSameAsPromise_=function(n){var r=this.createResolveAndReject_();n.callWhenSettled_(r.resolve,r.reject)};r.prototype.settleSameAsThenable_=function(n,r){var q=this.createResolveAndReject_();try{n.call(r,q.resolve,q.reject)}catch(P){q.reject(P)}};r.prototype.then=function(n,x){function q(n,q){return"function"==typeof n?function(q){try{B(n(q))}catch(Pb){t(Pb)}}:
q}var B,t,E=new r(function(n,q){B=n;t=q});this.callWhenSettled_(q(n,B),q(x,t));return E};r.prototype.catch=function(n){return this.then(void 0,n)};r.prototype.callWhenSettled_=function(n,r){function q(){switch(x.state_){case 1:n(x.result_);break;case 2:r(x.result_);break;default:throw Error("Unexpected state: "+x.state_);}}var x=this;null==this.onSettledCallbacks_?ya.asyncExecute(q):this.onSettledCallbacks_.push(q)};r.resolve=F;r.reject=function(n){return new r(function(r,q){q(n)})};r.race=function(n){return new r(function(r,
q){for(var x=$jscomp.makeIterator(n),t=x.next();!t.done;t=x.next())F(t.value).callWhenSettled_(r,q)})};r.all=function(n){var x=$jscomp.makeIterator(n),q=x.next();return q.done?F([]):new r(function(n,t){function r(q){return function(t){B[q]=t;u--;0==u&&n(B)}}var B=[],u=0;do B.push(void 0),u++,F(q.value).callWhenSettled_(r(B.length-1),t),q=x.next();while(!q.done)})};return r},"es6","es3");$jscomp.underscoreProtoCanBeSet=function(){var x={a:!0},E={};try{return E.__proto__=x,E.a}catch(F){}return!1};
$jscomp.setPrototypeOf="function"==typeof Object.setPrototypeOf?Object.setPrototypeOf:$jscomp.underscoreProtoCanBeSet()?function(x,E){x.__proto__=E;if(x.__proto__!==E)throw new TypeError(x+" is not extensible");return x}:null;$jscomp.generator={};$jscomp.generator.ensureIteratorResultIsObject_=function(x){if(!(x instanceof Object))throw new TypeError("Iterator result "+x+" is not an object");};
$jscomp.generator.Context=function(){this.isRunning_=!1;this.yieldAllIterator_=null;this.yieldResult=void 0;this.nextAddress=1;this.finallyAddress_=this.catchAddress_=0;this.finallyContexts_=this.abruptCompletion_=null};$jscomp.generator.Context.prototype.start_=function(){if(this.isRunning_)throw new TypeError("Generator is already running");this.isRunning_=!0};$jscomp.generator.Context.prototype.stop_=function(){this.isRunning_=!1};
$jscomp.generator.Context.prototype.jumpToErrorHandler_=function(){this.nextAddress=this.catchAddress_||this.finallyAddress_};$jscomp.generator.Context.prototype.next_=function(x){this.yieldResult=x};$jscomp.generator.Context.prototype.throw_=function(x){this.abruptCompletion_={exception:x,isException:!0};this.jumpToErrorHandler_()};$jscomp.generator.Context.prototype.return=function(x){this.abruptCompletion_={return:x};this.nextAddress=this.finallyAddress_};
$jscomp.generator.Context.prototype.jumpThroughFinallyBlocks=function(x){this.abruptCompletion_={jumpTo:x};this.nextAddress=this.finallyAddress_};$jscomp.generator.Context.prototype.yield=function(x,E){this.nextAddress=E;return{value:x}};$jscomp.generator.Context.prototype.yieldAll=function(x,E){x=$jscomp.makeIterator(x);var F=x.next();$jscomp.generator.ensureIteratorResultIsObject_(F);if(F.done)this.yieldResult=F.value,this.nextAddress=E;else return this.yieldAllIterator_=x,this.yield(F.value,E)};
$jscomp.generator.Context.prototype.jumpTo=function(x){this.nextAddress=x};$jscomp.generator.Context.prototype.jumpToEnd=function(){this.nextAddress=0};$jscomp.generator.Context.prototype.setCatchFinallyBlocks=function(x,E){this.catchAddress_=x;void 0!=E&&(this.finallyAddress_=E)};$jscomp.generator.Context.prototype.setFinallyBlock=function(x){this.catchAddress_=0;this.finallyAddress_=x||0};$jscomp.generator.Context.prototype.leaveTryBlock=function(x,E){this.nextAddress=x;this.catchAddress_=E||0};
$jscomp.generator.Context.prototype.enterCatchBlock=function(x){this.catchAddress_=x||0;x=this.abruptCompletion_.exception;this.abruptCompletion_=null;return x};$jscomp.generator.Context.prototype.enterFinallyBlock=function(x,E,F){F?this.finallyContexts_[F]=this.abruptCompletion_:this.finallyContexts_=[this.abruptCompletion_];this.catchAddress_=x||0;this.finallyAddress_=E||0};
$jscomp.generator.Context.prototype.leaveFinallyBlock=function(x,E){E=this.finallyContexts_.splice(E||0)[0];if(E=this.abruptCompletion_=this.abruptCompletion_||E){if(E.isException)return this.jumpToErrorHandler_();void 0!=E.jumpTo&&this.finallyAddress_<E.jumpTo?(this.nextAddress=E.jumpTo,this.abruptCompletion_=null):this.nextAddress=this.finallyAddress_}else this.nextAddress=x};$jscomp.generator.Context.prototype.forIn=function(x){return new $jscomp.generator.Context.PropertyIterator(x)};
$jscomp.generator.Context.PropertyIterator=function(x){this.object_=x;this.properties_=[];for(var E in x)this.properties_.push(E);this.properties_.reverse()};$jscomp.generator.Context.PropertyIterator.prototype.getNext=function(){for(;0<this.properties_.length;){var x=this.properties_.pop();if(x in this.object_)return x}return null};$jscomp.generator.Engine_=function(x){this.context_=new $jscomp.generator.Context;this.program_=x};
$jscomp.generator.Engine_.prototype.next_=function(x){this.context_.start_();if(this.context_.yieldAllIterator_)return this.yieldAllStep_(this.context_.yieldAllIterator_.next,x,this.context_.next_);this.context_.next_(x);return this.nextStep_()};
$jscomp.generator.Engine_.prototype.return_=function(x){this.context_.start_();var E=this.context_.yieldAllIterator_;if(E)return this.yieldAllStep_("return"in E?E["return"]:function(x){return{value:x,done:!0}},x,this.context_.return);this.context_.return(x);return this.nextStep_()};
$jscomp.generator.Engine_.prototype.throw_=function(x){this.context_.start_();if(this.context_.yieldAllIterator_)return this.yieldAllStep_(this.context_.yieldAllIterator_["throw"],x,this.context_.next_);this.context_.throw_(x);return this.nextStep_()};
$jscomp.generator.Engine_.prototype.yieldAllStep_=function(x,E,F){try{var B=x.call(this.context_.yieldAllIterator_,E);$jscomp.generator.ensureIteratorResultIsObject_(B);if(!B.done)return this.context_.stop_(),B;var r=B.value}catch(ya){return this.context_.yieldAllIterator_=null,this.context_.throw_(ya),this.nextStep_()}this.context_.yieldAllIterator_=null;F.call(this.context_,r);return this.nextStep_()};
$jscomp.generator.Engine_.prototype.nextStep_=function(){for(;this.context_.nextAddress;)try{var x=this.program_(this.context_);if(x)return this.context_.stop_(),{value:x.value,done:!1}}catch(E){this.context_.yieldResult=void 0,this.context_.throw_(E)}this.context_.stop_();if(this.context_.abruptCompletion_){x=this.context_.abruptCompletion_;this.context_.abruptCompletion_=null;if(x.isException)throw x.exception;return{value:x.return,done:!0}}return{value:void 0,done:!0}};
$jscomp.generator.Generator_=function(x){this.next=function(E){return x.next_(E)};this.throw=function(E){return x.throw_(E)};this.return=function(E){return x.return_(E)};$jscomp.initSymbolIterator();$jscomp.initSymbol();$jscomp.initSymbolIterator();this[Symbol.iterator]=function(){return this}};$jscomp.generator.createGenerator=function(x,E){E=new $jscomp.generator.Generator_(new $jscomp.generator.Engine_(E));$jscomp.setPrototypeOf&&$jscomp.setPrototypeOf(E,x.prototype);return E};
$jscomp.asyncExecutePromiseGenerator=function(x){function E(B){return x.next(B)}function F(B){return x.throw(B)}return new Promise(function(B,r){function ya(n){n.done?B(n.value):Promise.resolve(n.value).then(E,F).then(ya,r)}ya(x.next())})};$jscomp.asyncExecutePromiseGeneratorFunction=function(x){return $jscomp.asyncExecutePromiseGenerator(x())};$jscomp.asyncExecutePromiseGeneratorProgram=function(x){return $jscomp.asyncExecutePromiseGenerator(new $jscomp.generator.Generator_(new $jscomp.generator.Engine_(x)))};
$jscomp.objectCreate=$jscomp.ASSUME_ES5||"function"==typeof Object.create?Object.create:function(x){var E=function(){};E.prototype=x;return new E};$jscomp.inherits=function(x,E){x.prototype=$jscomp.objectCreate(E.prototype);x.prototype.constructor=x;if($jscomp.setPrototypeOf){var F=$jscomp.setPrototypeOf;F(x,E)}else for(F in E)if("prototype"!=F)if(Object.defineProperties){var B=Object.getOwnPropertyDescriptor(E,F);B&&Object.defineProperty(x,F,B)}else x[F]=E[F];x.superClass_=E.prototype};
$jscomp.arrayFromIterator=function(x){for(var E,F=[];!(E=x.next()).done;)F.push(E.value);return F};$jscomp.arrayFromIterable=function(x){return x instanceof Array?x:$jscomp.arrayFromIterator($jscomp.makeIterator(x))};$jscomp.findInternal=function(x,E,F){x instanceof String&&(x=String(x));for(var B=x.length,r=0;r<B;r++){var ya=x[r];if(E.call(F,ya,r,x))return{i:r,v:ya}}return{i:-1,v:void 0}};
$jscomp.polyfill("Array.prototype.find",function(x){return x?x:function(x,F){return $jscomp.findInternal(this,x,F).v}},"es6","es3");$jscomp.polyfill("Array.prototype.findIndex",function(x){return x?x:function(x,F){return $jscomp.findInternal(this,x,F).i}},"es6","es3");$jscomp.polyfill("Object.is",function(x){return x?x:function(x,F){return x===F?0!==x||1/x===1/F:x!==x&&F!==F}},"es6","es3");
$jscomp.polyfill("Array.prototype.includes",function(x){return x?x:function(x,F){var B=this;B instanceof String&&(B=String(B));var r=B.length;F=F||0;for(0>F&&(F=Math.max(F+r,0));F<r;F++){var E=B[F];if(E===x||Object.is(E,x))return!0}return!1}},"es7","es3");
$jscomp.checkStringArgs=function(x,E,F){if(null==x)throw new TypeError("The 'this' value for String.prototype."+F+" must not be null or undefined");if(E instanceof RegExp)throw new TypeError("First argument to String.prototype."+F+" must not be a regular expression");return x+""};$jscomp.polyfill("String.prototype.includes",function(x){return x?x:function(x,F){return-1!==$jscomp.checkStringArgs(this,x,"includes").indexOf(x,F||0)}},"es6","es3");
$jscomp.iteratorFromArray=function(x,E){$jscomp.initSymbolIterator();x instanceof String&&(x+="");var F=0,B={next:function(){if(F<x.length){var r=F++;return{value:E(r,x[r]),done:!1}}B.next=function(){return{done:!0,value:void 0}};return B.next()}};B[Symbol.iterator]=function(){return B};return B};$jscomp.polyfill("Array.prototype.keys",function(x){return x?x:function(){return $jscomp.iteratorFromArray(this,function(x){return x})}},"es6","es3");
$jscomp.polyfill("String.prototype.startsWith",function(x){return x?x:function(x,F){var B=$jscomp.checkStringArgs(this,x,"startsWith");x+="";var r=B.length,E=x.length;F=Math.max(0,Math.min(F|0,B.length));for(var n=0;n<E&&F<r;)if(B[F++]!=x[n++])return!1;return n>=E}},"es6","es3");
$jscomp.polyfill("String.prototype.endsWith",function(x){return x?x:function(x,F){var B=$jscomp.checkStringArgs(this,x,"endsWith");x+="";void 0===F&&(F=B.length);F=Math.max(0,Math.min(F|0,B.length));for(var r=x.length;0<r&&0<F;)if(B[--F]!=x[--r])return!1;return 0>=r}},"es6","es3");
$jscomp.polyfill("String.prototype.repeat",function(x){return x?x:function(x){var F=$jscomp.checkStringArgs(this,null,"repeat");if(0>x||1342177279<x)throw new RangeError("Invalid count value");x|=0;for(var B="";x;)if(x&1&&(B+=F),x>>>=1)F+=F;return B}},"es6","es3");$jscomp.owns=function(x,E){return Object.prototype.hasOwnProperty.call(x,E)};$jscomp.polyfill("Object.values",function(x){return x?x:function(x){var F=[],B;for(B in x)$jscomp.owns(x,B)&&F.push(x[B]);return F}},"es8","es3");
$jscomp.stringPadding=function(x,E){x=void 0!==x?String(x):" ";return 0<E&&x?x.repeat(Math.ceil(E/x.length)).substring(0,E):""};$jscomp.polyfill("String.prototype.padEnd",function(x){return x?x:function(x,F){var B=$jscomp.checkStringArgs(this,null,"padStart");return B+$jscomp.stringPadding(F,x-B.length)}},"es8","es3");
$jscomp.polyfill("Array.prototype.fill",function(x){return x?x:function(x,F,B){var r=this.length||0;0>F&&(F=Math.max(0,r+F));if(null==B||B>r)B=r;B=Number(B);0>B&&(B=Math.max(0,r+B));for(F=Number(F||0);F<B;F++)this[F]=x;return this}},"es6","es3");$jscomp.polyfill("Array.prototype.entries",function(x){return x?x:function(){return $jscomp.iteratorFromArray(this,function(x,F){return[x,F]})}},"es6","es3");
$jscomp.polyfill("String.prototype.padStart",function(x){return x?x:function(x,F){var B=$jscomp.checkStringArgs(this,null,"padStart");return $jscomp.stringPadding(F,x-B.length)+B}},"es8","es3");
(function(){var x,E,F=[].indexOf,B=function(a,b){if(!(a instanceof b))throw Error("Bound instance method accessed before binding");},r=function(){};r.info=function(a,b){return this.log(a,"info",b)};r.warn=function(a,b){this.log(a,"warn",b);null==window.logCountWarnings&&(window.logCountWarnings=0);window.logCountWarnings+=1};r.error=function(a,b){this.log(a,"error",b);null==window.logCountErrors&&(window.logCountErrors=0);window.logCountErrors+=1};r.verbose=function(a,b){return this.log(a,"verbose",
b)};r.header=function(a,b){return this.log(a,"header",b)};r.warningCount=function(){return window.logCountWarnings};r.errorCount=function(){return window.logCountErrors};r.clearCount=function(){window.logCountWarnings=0;return window.logCountErrors=0};r.clear=function(){window.logEntries=[];this.clearCount();this.modWarnCounts={};return this.modErrorCounts={}};r.log=function(a,b,c){var d,e,f;var g=null!=a?a:"";if(a instanceof Error){if(null==c||"base"===c)c="ERROR";var h=a;g=a.toString()}g=$jscomp.makeIterator(g.split(";"));
a=g.next().value;g=g.next().value;var k={text:a,extra:g,type:b,mod:c};null==window.logEntries&&(window.logEntries=[]);window.logEntries.push(k);window.logEntries=window.logEntries.slice(0,5E3);"verbose"!==b&&null!=window.logWin&&this.sendMessage("log",k);null==h&&(d=null!=c?"["+c.truncate(20,"middle").padRight(23)+"] ":"");null==h&&(h=""+d+a.padRight(16)+(null!=g?g:""));switch(b){case "warn":console.warn(h);break;case "error":console.error(h);break;default:console.info(h)}window.isClient&&(d=require("fs"),
a=require("path"),null==this.logStream&&(a=a.resolve(window.rootPath,O.baseDir(),"tce-log.txt"),console.log("opening log file at "+a),this.logStream=d.createWriteStream(a)),this.logStream.write(h+"\r\n"));if(null!=c&&"base"!==c&&"ERROR"!==c)switch(b){case "warn":this.modWarnCounts=null!=(e=this.modWarnCounts)?e:{};this.modWarnCounts[c]=null!=this.modWarnCounts[c]?this.modWarnCounts[c]+1:1;break;case "error":this.modErrorCounts=null!=(f=this.modErrorCounts)?f:{},this.modErrorCounts[c]=null!=this.modErrorCounts[c]?
this.modErrorCounts[c]+1:1}};r.sendMessage=function(a,b){a={id:a,data:b};return window.isClient?window.logWin.webContents.send("message",a):window.logWin.postMessage(a,"*")};r.receiveMessage=function(a,b){switch(a){case "clear":return r.clear();case "eventChecks":return debug.eventChecks=b}};r.openWindow=function(){var a=this;if(window.isElectron){if(null==window.logWin){var b=require("electron");window.logWin=new b.remote.BrowserWindow({width:1280,height:720});window.logWin.loadURL("file://"+__dirname+
"/log.html");window.logWin.on("closed",function(){return window.logWin=null});window.logWin.webContents.on("did-finish-load",function(){var b;a.sendMessage("eventChecks",debug.eventChecks);var d=window.logEntries;var e=[];var f=0;for(b=d.length;f<b;f++){var g=d[f];e.push(a.sendMessage("log",g))}return e});return b.ipcRenderer.on("message",function(a,b){return r.receiveMessage(b.id,b.data)})}}else return window.logWin=window.open("log","TCE Log Viewer","width=840,height=640,resizable,scrollbars=yes,status=1"),
window.logWin.addEventListener("load",function(){var a;window.logWin.postMessage({id:"eventChecks",data:debug.eventChecks},"*");var b=window.logEntries;var e=[];var f=0;for(a=b.length;f<a;f++){var g=b[f];e.push(window.logWin.postMessage({id:"log",data:g},"*"))}return e},!0),window.addEventListener("message",function(a){return r.receiveMessage(a.data.id,a.data.data)},!1)};var ya={TCE:0,Demo:1,IO:2,TCEChina:3};("undefined"!==typeof exports&&null!==exports?exports:window).CEGameMode=ya;var n=function(){};
n.canUseLocalStorage=function(){var a;try{return a="undefined"!==typeof localStorage&&null!==localStorage}catch(b){return!1}};n.isTCE=function(){return window.gameMode===ya.TCE||window.gameMode===ya.TCEChina};n.isDemo=function(){return window.gameMode===ya.Demo};n.isIO=function(){return window.gameMode===ya.IO};n.isChina=function(){return window.gameMode===ya.TCEChina};n.getVersionString=function(){return config.footerName};n.assert=function(a,b){if(!a&&(r.error(b),debug.traceAssert)){console.trace();
debugger}};n.assertRef=function(a){if(Object.isString(a)){var b=t.arrify(a);var c=0;for(a=b.length;c<a;c++){var d=b[c];d=t.getEntity(d);if(null==d)return!1}}return!0};n.assertOpts=function(a,b,c,d){var e;var f=function(){var d,e,f;if(Object.isString(b))var l=config.man.find(function(a){return a.keyword===b});else l=b,b=l.keyword;if(0<=F.call(config.staticKeywords,b))return null;if(null==l)return"missing manual for "+b;if(null!=l.$character&&null==c.person)return"need person context for keyword ("+
b+")";if(null!=l.$inline&&!Object.isObject(a)){if(/@id/i.test(l.$inline)&&!n.assertRef(a))return"unknown reference "+a}else if(null==l.$custom)if(null!=l.$flags){if(Object.isString(a)||!Object.isArray(a))return"un-parsed string flags found for ("+b+")"}else{var m=t.arrify(a);var p=0;for(e=m.length;p<e;p++){var w=m[p];if(!Object.isObject(w))return"need object for keyword ("+b+")";if(null==w.bonus){for(d in w)if(null==l[d]&&null==l["_"+d])return"unknown property ("+d+") for keyword ("+b+")";for(d in l)if("keyword"!==
d&&"_"!==(f=d[0])&&"$"!==f&&null==w[d])return"missing mandatory property ("+d+") for keyword ("+b+")"}}}return null};return null!=config.man&&(f=f(),null!=f)?(r.error(f,d),null!=(e=c.main)&&e.doSendError(f),!1):!0};n.num=function(a){return Object.isArray(a)?J.randIntA(a):a};n.isTrue=function(a){return null!=a&&a};n.clone=function(a){return null==a?{}:Object.clone(a)};n.array=function(a,b){var c;var d=[];for(c=0;0<=a?c<a:c>a;0<=a?++c:--c)d.push(b);return d};n.parseVal=function(a){var b;return Object.isString(a)?
null!=(b=config.standardValues[a])?b:0:null!=a?a:0};n.parseRange=function(a){var b,c;var d=function(a){return 0<a.length?parseInt(a):null};if(Object.isString(a)){var e=$jscomp.makeIterator(a.split(".."));var f=e.next().value;e=e.next().value;null==e?f=e=d(f):(f=null!=(b=d(f))?b:-1E4,e=null!=(c=d(e))?c:1E4)}else Object.isArray(a)?2===a.length?(d=$jscomp.makeIterator([a[0],a[1]]),f=d.next().value,e=d.next().value):1===a.length?(d=$jscomp.makeIterator([a[0],a[0]]),f=d.next().value,e=d.next().value):
n.assert(!1,"Invalid int matcher length ("+a.length+")"):e=f=a;f>e&&(d=f,f=e,e=d);return[f,e]};n.match=function(a,b){var c=$jscomp.makeIterator(this.parseRange(a));a=c.next().value;return c.next().value>=b&&b>=a};n.sample=function(a,b){if(Object.isArray(a)){var c=$jscomp.makeIterator(a);a=c.next().value;var d=c.next().value;a>d&&(c=a,a=d,d=c);return b.length<a?[]:b.sample(Math.min(d,b.length))}return b.length<a?[]:b.sample(a)};n.invert=function(a){if(Object.isArray(a)){var b;var c=[];var d=0;for(b=
a.length;d<b;d++){var e=a[d];c.push(-e)}return c}return-a};n.rgbToHex=function(a,b,c){return"#"+(16777216+(a<<16)+(b<<8)+c).toString(16).slice(1)};n.hexToRgb=function(a){a=a.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,function(a,c,d,e){return c+c+d+d+e+e});if(a=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(a))return{r:parseInt(a[1],16),g:parseInt(a[2],16),b:parseInt(a[3],16)}};n.hashCode=function(a){var b,c,d;var e=d=b=0;for(c=a.length;d<c;e=++d)b=a.charCodeAt(e)+((b<<5)-b);return b};n.intToRGB=
function(a){a=(a&16777215).toString(16).toUpperCase();return"00000".substring(0,6-a.length)+a};n.isMac=function(){return navigator.platform.has("Mac")};n.width=function(a,b,c){return a*b+(a-1)*c};n.count=function(a,b,c){var d;null==b&&(b=function(a){return a});null==c&&(c=function(a){return 1});var e={};var f=0;for(d=a.length;f<d;f++){var g=a[f];var h=b(g);null==e[h]&&(e[h]=0);e[h]+=c(g)}return e};n.hasCount=function(a,b){var c,d;for(d in a){var e=a[d];var f=null!=(c=b[d])?c:0;if(!n.match(e,f))return!1}return!0};
n.openLink=function(a,b){return window.isSteam&&(void 0===b||b)&&"undefined"!==typeof greenworks&&null!==greenworks?(greenworks.activateGameOverlayToWebPage(a),setTimeout(function(){if(!window.steamOverlayActive)return require("electron").shell.openExternal(a)},2E3)):window.isNW?(b=require("nw.gui"),b.Shell.openExternal(a)):window.isElectron?(b=require("electron").shell,b.openExternal(a)):window.open(a)};n.openInternalLink=function(a){if(window.isElectron){var b=require("electron");return b.remote.getCurrentWindow().loadURL("file://"+
__dirname+a)}return window.open(a,"_self")};n.parseFaces=function(a){n.assert(null!=a);return n.count(a.split(" "))};n.checkMatch=function(a,b){var c,d;for(c in b){var e=b[c];if((null!=(d=a[c])?d:0)<e)return!1}return!0};var W=function(a,b,c){this.r=a;this.s=a.s;this.sfx=b;this.main=c};W.prototype.show=function(){return this.mouseAction=null};W.prototype.onMouseClick=function(a){return!0};W.prototype.onKeyPress=function(a){return!0};W.prototype.tick=function(a){return!0};W.prototype.hide=function(){return!0};
W.prototype.drawState=function(a,b,c){this.mouseAction=null;return this.draw(a,b,c)};var q=function(){};q.setLang=function(a){var b;r.info("Setting language "+a);0>q.langs.findIndex(function(b){return b.id===a})&&(a="en");q.langId=a;n.canUseLocalStorage()&&window.localStorage.setItem("langId",a);return config.diaryText=null!=(b=config.diaryTextLangs[a])?b:config.diaryTextLangs.latin};q.setNextLang=function(){var a=q.langs.findIndex(function(a){return a.id===q.langId});0>a&&(a=0);return q.setLang(q.langs[(a+
1)%q.langs.length].id)};q.setupLang=function(a){var b;r.header("--== LOADING LANGUAGES ==--");q.readLangs();r.info("Found "+q.langs.length+" languages");n.isChina()&&window.localStorage.setItem("langId","zh-CN");if(n.canUseLocalStorage()&&null!=localStorage.getItem("langId"))q.setLang(localStorage.getItem("langId"));else if(!window.isClient){var c=navigator.languages;var d=0;for(b=c.length;d<b;d++){var e=c[d];var f=0<=q.langs.findIndex(function(a){return a.id===e});f||(e=e.slice(0,2),f=0<=q.langs.findIndex(function(a){return a.id===
e}));if(f){q.setLang(e);break}}}null!=q.langId&&""!==q.langId||q.setLang("en");config.enTexts=config.locTexts=null;if(n.isChina()||"en"===q.langId)return q.loadLang(q.langId,function(b){config.enTexts=config.locTexts=b;return a()});q.loadLang("en",function(b){config.enTexts=b;if(null!=config.locTexts)return a()});return q.loadLang(q.langId,function(b){config.locTexts=b;if(null!=config.enTexts)return a()})};q.readLangs=function(){var a,b;if(n.isChina())q.langs=[],q.langs.push({id:"zh-CN",authors:[]});
else if(window.isClient){q.langs=[];var c=require("fs");var d=require("path");var e=/("?@authors"?),w*"(.+)"/g;var f=c.readdirSync(d.join(window.rootPath,"langs"));try{var g=c.readdirSync("langs");var h=0;for(b=g.length;h<b;h++){var k=g[h];f.includes(k)||f.push(k)}}catch(w){g=w}h=0;for(b=f.length;h<b;h++){k=f[h];r.info("langdir "+k);try{var l="langs/"+k+"/tce_texts.csv";try{var m=c.readFileSync(l)}catch(w){g=w,null!=window.rootPath&&(l=d.join(window.rootPath,l),m=c.readFileSync(l))}m=m.toString();
for(a=[];;){var p=e.exec(m);if(null!=p){a.add(p[2].split(/[,\uff0c]/).map(function(a){return a.trim()}));break}}q.langs.push({id:k,authors:a})}catch(w){g=w,r.error(g)}}}else q.langs=[{id:"en",authors:["Maschinen-Mensch","Dennis Kogel","Luke Openshaw","Tristan Dahl"]},{id:"de",authors:["Iris Sch\u00e4fer","Dennis Kogel","Maschinen-Mensch"]},{id:"fr",authors:["Targus","Baptiste Zapirain","Damn3d","Killpower"]},{id:"it",authors:"MasterOfTheWind;Adam24;Funes;kanoilnano;Fich;JamesShepard;Ace The Brave;Slash111;DioAesir;Bonfi97;RegulusCrowe;Nicox02;EsploratoreCurioso;Nifel17;Doppiad".split(";")},
{id:"es",authors:"V\u00edctor Vicente;Jorge Gisbert;Javier V\u00e1zquez;Rafael Sales Cant\u00f3;Javier Almagro;SJ Otero;Alejandro Johannes;Carlos Rodriguez;NeHoMaR;Franciscogt;juanandreslara98;fucho;luifer_gf;karpacho;Miguel Dos Reis;Santiago Medina;beatriz7;Jonathan C. White;pirluit".split(";")},{id:"pt-BR",authors:["R\u00f4mulo Wehling Magalh\u00e3es","Macalango"]},{id:"pl",authors:"romczek;Haxorek;Micha\u0142 Lisowski;knurson132;Jan Miko\u0142ajczyk;Alex (demostenes);Bart\u0142omiej Mathea;oschlypajac;Average-Guy;Lujka200;Dominik \u0141ukomski;aleks4ndra;Jestemkioskiem;Illeen Avon;Adrian Wajer;Zedarrr;koscian;Ribson;jestemkioskiem;przykrasprawa".split(";")},
{id:"tr",authors:"utopian.io/@kedi;Mustafa Can;Elysion;Mutlu Tayfun K\u00fc\u00e7\u00fck;alialniak;intelligencer;\u00d6mer ATAG\u00dcN;bekoledin;Ugur Gulmen;vitruvianman;arif2k;Furkan Ergen\u00e7;alicangec;emreozturk;Irem Karabulut;madbuddhaabuser;okn;\u0130rem Karag\u00f6z;overmedia;O\u011fuzhan Karabulut;bitcoinfather;ghunwolde;bzkrtoguzhan;okanbaya;curtainwitcher;btknutzier;liquidoo;Fatih K\u00dc\u00c7\u00dcK\u015eEN;hazalg;Erdem \u015eahin;Arda Kaplan;Berkay Tekinsen;baybali;hsyndemir;mustafakavak;alpertr;realinfo;tuganaerdogan;superdoctor;emrenano (Emre Erdo\u011fan);Musa Avc\u0131".split(";")},
{id:"ru",authors:["Levsha Localization Studio"]},{id:"uk",authors:"\u0420\u043e\u0441\u0442\u0438\u0441\u043b\u0430\u0432 \u0421\u0443\u043b\u0456\u043c\u0430;\u042e\u0440\u0456\u0439 \u0411\u0456\u0441\u0438\u043a;\u041c\u0430\u043a\u0441\u0438\u043c \u0414\u0443\u0432\u0430\u043d\u043e\u0432;\u041e\u043b\u0435\u043a\u0441\u0430\u043d\u0434\u0440\u0430 \u041a\u0443\u0446\u0430\u043d;\u041c\u0430\u0440\u0456\u044f \u041f\u043e\u043b\u0456\u0449\u0443\u043a;\u0410\u043d\u043d\u0430 \u0427\u0430\u0439\u043a\u0430;\u041f\u043e\u043b\u0456\u043d\u0430 \u0411\u0443\u0437\u0430\u043d\u043e\u0432\u0430;\u0421\u043e\u0444\u0456\u044f \u0428\u0443\u043b\u044c;\u041c\u0430\u0440\u0438\u043d\u0430 \u041f\u0456\u0449\u0430\u043b\u043a\u043e\u0432\u0441\u044c\u043a\u0430;\u0410\u043d\u0434\u0440\u0456\u0439 \u041f\u0435\u043a\u0430\u0440;\u0410\u043d\u0430\u0441\u0442\u0430\u0441\u0456\u044f \u0420\u0443\u0442\u0438\u043b\u043e;\u041e\u043a\u0441\u0430\u043d\u0430 \u0420\u0438\u0432\u043a\u043e;\u041e\u043b\u0435\u0433 OnaHe;\u042f\u043d\u0456\u0441 \u0412\u0435\u0440\u043c\u0456\u043d\u043a\u043e".split(";")},
{id:"ko",authors:["Lauren Lim (Karma_L)"]},{id:"ja",authors:["Altagram"]},{id:"zh-CN",authors:["Project Gutenberg"]},{id:"zh-TW",authors:["Project Gutenberg"]}]};q.loadLang=function(a,b){var c="langs/"+a+"/tce_texts.csv";r.info("Loading language "+c);return O.readFileAsync(c,function(d){if(null!=d)try{var e=d.toString();var f=q.parseLang(a,e);r.info("Loaded language "+c+": "+Object.keys(f).length+" entries");return b(f)}catch(g){return d=g,r.error(d),b({})}else return r.error("No data returned for file "+
c),b({})})};q.parseLang=function(a,b){var c;var d=function(a){'"'===a[0]&&(a=a.substring(1,a.length-1));return a};var e={};var f=b.match(/[^\r\n]+/g);if(null==f)return e;var g=0;for(c=f.length;g<c;g++){var h=f[g];var k=h.indexOf(",");if(!(0>k)){b=d(h.substring(0,k));for(k=d(h.substring(k+1));k.includes('""');)k=k.replace('""','"');b.startsWith("@authors")||(null!=e[b]&&r.warn("["+a+"] duplicate text key "+b),e[b]=k)}}return e};q.isLocalized=function(a){if(null==a)return!1;a.startsWith("txt-")&&(a=
a.slice(4));return null!=config.locTexts[a]};q.toText=function(a,b){var c;if(null!=a&&a.startsWith("txt-")){a=a.slice(4);var d=config.locTexts[a];null==d&&(d=config.enTexts[a]);null==d&&r.warn("missing text "+a)}return null!=(c=null!=d?d:b)?c:a};q.timeDurationToString=function(a){var b="";var c=Math.floor(a/1E3);a=Math.floor(c/60);var d=Math.floor(a/60);var e=Math.floor(d/24);0<e&&(b+=e,b=1<e?b+(" "+q.toText("txt-io-worldDuration-days")):b+(" "+q.toText("txt-io-worldDuration-day")));var f=d-24*e;
0<f&&(0<b.length&&(b+=", "),b+=f,b=1<f?b+(" "+q.toText("txt-io-worldDuration-hours")):b+(" "+q.toText("txt-io-worldDuration-hour")));0>=e&&(e=a-60*d,0<e?(0<b.length&&(b+=", "),b+=e,b=1<e?b+(" "+q.toText("txt-io-worldDuration-minutes")):b+(" "+q.toText("txt-io-worldDuration-minute"))):(a=c-60*a,0<b.length&&(b+=", "),b+=a,b=1<a?b+(" "+q.toText("txt-io-worldDuration-seconds")):b+(" "+q.toText("txt-io-worldDuration-second"))));return b};q.bonusHelp=function(a){var b;var c=[];for(b in a){var d=a[b];if(null!=
config.helpBonus[b]){var e=config.helpBonus[b];"%"===e[0]?(e=e.slice(1),d=q.fmtInt(100*d)+"%"):d=q.fmtInt(d);c.push(q.toText(e)+": "+d)}}return c};q.getNameGenerator=function(a){var b;a=t.getProto("na-"+a,config.names,!1);return null!=(b=null!=a?a.names:void 0)?b:null};q.getNamePool=function(a){var b;a=t.getProto("np-"+a,config.namePools,!1);return null!=(b=null!=a?a.names:void 0)?b:null};q.createName=function(a,b,c){b=void 0===b?{}:b;c=void 0===c?null:c;var d;var e=this.getNameGenerator(a);if(null==
e)return a;e=t.arrify(e,!1).worldGenSample();var f="butterfly"===a?"$butterflyAdj $butterflySpecies":void 0;null==c&&(c=["male","female"].worldGenSample());e=this.toText(e,f);e=this.parse(e,c);for(d in b)f=b[d],e=e.replace(d,f);for(d=/(\$\w+)/;;){b=d.exec(e);if(null==b)break;f=this.getNamePool(b[1].from(1));null==f&&r.error("Couldn't find name pool '"+b[1].from(1)+"'' for generator '"+a+"'' with name '"+e+"'");f=null!=f?f.worldGenSample():b[1].from(1);f=this.parse(f,c);e=e.replace(b[1],f)}return e};
q.createRandomText=function(a,b){var c=q.toText("txt-name-consonants").split("");var d=q.toText("txt-name-vowels").split("");a=J.randInt(a,b);c=c.sample(Math.ceil(a/2)).map(function(a){return a+d.sample()}).join("");return 1===a%2?c.slice(0,-1):c};q.isTextLatin=function(a){var b,c;var d=c=0;for(b=a.length-1;0<=b?c<=b:c>=b;d=0<=b?++c:--c)if(d=a.charCodeAt(d),64<d&&91>d||96<d&&123>d||47<d&&58>d)return!0;return!1};q.wrap=function(a,b,c){var d=this,e;var f=[];var g="";var h=config.diaryText.separator;
var k=config.diaryTextLangs.latin.separator;if(h!==k&&a.includes(k)){var l=a.split(k);l=l.map(function(a){return d.isTextLatin(a)?a:a.split(h)}).flatten()}else l=a.split(h);var m=e=0;for(a=l.length;e<a;m=++e){var p=l[m];var w=this.isTextLatin(p)||null!=l[m+1]&&this.isTextLatin(l[m+1])?k:h;m=""+g+p+w;if(""!==g&&c.measureText(m).width>=b||"\n"===p||"\\n"===p){if(0<w.length&&g.endsWith(w)&&(g=g.substring(0,g.length-1)),f.push(g),g=p+" ","\n"===p||"\\n"===p)g=""}else g=m}g.compact().isBlank()||(0<h.length&&
g.endsWith(h)&&(g=g.substring(0,g.length-1)),f.push(g));return f};q.sanitiseUser=function(a){var b,c;var d=a.replace("_"," ");a=c=0;for(b=d.length;0<=b?c<b:c>b;a=0<=b?++c:--c)0===a?d=d.slice(0,a)+d[a].toUpperCase()+d.slice(a+1):(" "!==d[a-1]&&/[A-Z]/.test(d[a])&&(d=d.slice(0,a)+" "+d.slice(a))," "===d[a]&&(d=d.slice(0,a+1)+d[a+1].toUpperCase()+d.slice(a+2)));return d};q.parse=function(a,b){var c;a=this.toText(a);if(null==a)return a;if(null!=b){var d=a.match(/\{.*?\}/g);if(null!=d){var e=0;for(c=d.length;e<
c;e++){var f=d[e];var g=f.slice(1,-1);g=g.split("|");g="female"===b?g[1]:g[0];a=a.replace(f,g)}}}d=a.match(/\[.*?\]/g);if(null!=d)for(c=0,b=d.length;c<b;c++)f=d[c],g=f.slice(1,-1),g=g.split("|"),g=1<g.length?g.worldGenSample():.5>ba.rng.random()?g[0]:"",a=a.replace(f,g);return a};q.fmtInt=function(a){return 0>a?""+a:"+"+a};q.rank=function(a){var b=function(){switch(a){case 0:return"txt-outro-first";case 1:return"txt-outro-second";case 2:return"txt-outro-third";case 3:return"txt-outro-fourth";case 4:return"txt-outro-fifth"}}();
return null!=b?q.toText(b):a+1+"."};var P=function(){};P.getGoal=function(a){return this.getProto(a,config.goals)};P.getPocket=function(a){return this.getProto(a,config.pockets)};P.getWorld=function(a){return this.getProto(a,config.worlds)};P.getExpedition=function(a){return this.getProto(a,config.expeditions)};P.getBiome=function(a,b){return this.getProto(a,config.biomes,void 0===b?!0:b)};P.getGroup=function(a){return this.getProto(a,config.groups)};P.getTile=function(a){return this.getProto(a,config.tiles)};
P.getEvent=function(a,b){return this.getProto(a,config.events,void 0===b?!0:b)};P.getAction=function(a){a=this.getProto(a,config.actions);null!=a&&(a.native=!0);return a};P.getLocation=function(a,b){return this.getProto(a,config.locations,void 0===b?!0:b)};P.getZone=function(a,b){return this.getProto(a,config.zones,void 0===b?!0:b)};P.getCharacter=function(a,b){return this.getProto(a,config.characters,void 0===b?!0:b)};P.getParticle=function(a,b){return this.getProto(a,config.particles,void 0===b?
!0:b)};P.getSprawl=function(a){return this.getProto(a,config.sprawls)};P.getTribeGen=function(a){return this.getProto(a,config.tribeGens)};P.getTribeGenLayer=function(a){return this.getProto(a,config.tribeGenLayers)};P.getManual=function(a){return config.man.find(function(b){return b.keyword===a})};P.initSprawl=function(a,b){var c,d,e,f,g;a=null!=(c=P.arrify(a.sprawls).find(function(a){return a.id===b.id}))?c:{};return{active:!1,lifeTime:null!=(d=a.lifeTime)?d:b.defaultLifeTime,chance:null!=(e=a.chance)?
e:b.defaultChance,burnedTile:null!=(f=a.burnedTile)?f:b.defaultBurnedTile,blockZone:null!=(g=b.blockZone)?g:!1}};P.parseLocationPlacing=function(a,b){var c,d;var e=[];var f=P.arrify(a);var g=0;for(a=f.length;g<a;g++){var h=f[g];if(Object.isString(h)){var k=$jscomp.makeIterator([h,1,null]);h=k.next().value;var l=k.next().value;var m=k.next().value}else k=$jscomp.makeIterator([h.ref,null!=(c=h.count)?c:1,h.reqBiomeFlags]),h=k.next().value,l=k.next().value,m=k.next().value;k=null!=(d=null!=b?b.flags:
void 0)?d:{};if(P.checkFlags(null!=m?m:{},k))for(k=0;0<=l?k<l:k>l;0<=l?++k:--k)e.push(h)}return e};P.getItemList=function(a,b){return this.getProto(a,config.itemList,void 0===b?!0:b)};P.getItem=function(a,b){a=this.getProto(a,config.items,void 0===b?!0:b);null!=a&&null==a.known&&(a.known=!(null!=a.isFood||a.isFood));return a};P.getChat=function(a,b){return this.getProto(a,config.chatLines,void 0===b?!0:b)};P.getFont=function(a){return this.getProto(a,config.fonts)};P.getBuildItem=function(a){var b,
c,d,e;return null!=(b=null!=(c=null!=(d=null!=(e=P.getLocation(a,!1))?e:P.getZone(a,!1))?d:P.getBiome(a,!1))?c:P.getGroup(a,!1))?b:{}};P.getStatus=function(a,b){return this.getProto(a,config.statuses,void 0===b?!0:b)};P.getBuff=function(a){return this.getProto(a,config.buffs)};P.getDie=function(a,b){b=void 0===b?!0:b;if("!"===a[a.length-2]){b=this.getProto(a.slice(0,-2),config.dice,b);var c=parseInt(a[a.length-1]);a=b.faces.split(" ").slice(0,c).join(" ");a+=" blank".repeat(6-c);return{sprite:b.sprite,
faces:a}}return this.getProto(a,config.dice,b)};P.getDieFace=function(a){return this.getProto("df-"+a,config.diceFaces)};P.getSlots=function(a){return this.getProto(a,config.slots,!1)};P.getButton=function(a){return this.getProto(a,config.buttons,!1)};P.expandId=function(a,b){return null!=b[a]?this.expand(b[a]):a};P.getPack=function(a,b){return this.getProto(a,config.packs,void 0===b?!0:b)};P.getEntity=function(a){return this.getProto(a,config.entities,!1)};P.getProto=function(a,b,c){c=void 0===c?
!0:c;var d;if(Object.isString(a)){var e=b[a];c&&n.assert(null!=e,"Unknown id: "+a)}else e=a;null!=(null!=e?e["extends"]:void 0)&&(a=null!=(d=e.isAbstract)?d:!1,b=this.getProto(e["extends"],b),Object.merge(e,b,!1,!1),delete e["extends"],e.isAbstract=a);return e};P.parseEntityData=function(a){var b,c;var d=function(a){return Object.isObject(a)&&!Object.isArray(a)};for(b in a){var e=a[b];if("reqTiles"===b)a[b]=P.arrify(e);else if("reqFlags"===b||"flags"===b||"setCharFlags"===b||"reqPartyFlags"===b||
"setLocationFlags"===b||"setBiomeFlags"===b||"setPartyFlags"===b||"reqTileFlags"===b||"setTileFlags"===b||"reqLocationFlags"===b||"reqBiomeFlags"===b||"reqCharFlags"===b||"setTempFlags"===b||"reqTempFlags"===b||"reqWorldFlags"===b||"setWorldFlags"===b||"tileFlags"===b||"reqStatusFlags"===b||"reqAllStatusFlags"===b||"reqItemFlags"===b)a[b]=P.parseFlags(e);else if("reqStatus"===b||"setPartyStatus"===b||"setStatus"===b||"reqPartyStatus"===b)a[b]=P.parseFlags(e,"st-");else if(d(e))P.parseEntityData(e);
else if(Object.isArray(e)){var f=0;for(c=e.length;f<c;f++){var g=e[f];d(g)&&P.parseEntityData(g)}}}};P.arrify=function(a,b){return null==a?[]:(void 0===b||b)&&Object.isString(a)?a.split("|").sample().trim().split(" "):Object.isArray(a)?a:[a]};P.valid=function(a){return null==a?!1:!this.arrify(a).isEmpty()};P.parseFlags=function(a,b){b=void 0===b?"":b;var c,d;if(Object.isString(a)){var e=[];var f=a.split("|");var g=0;for(c=f.length;g<c;g++){var h=f[g];a={};var k=h.split(" ");var l=0;for(d=k.length;l<
d;l++){h=k[l];h=h.trim();var m=1;h.slice(1).startsWith(b)&&(m=1+b.length);0<h.length&&(a[b+h.slice(m)]="+"===h[0])}e.push(a)}return e}return Object.isArray(a)?a:P.arrify(a)};P.setFlags=function(a,b){b=void 0===b?{}:b;a=this.parseFlags(a).sample();return Object.merge(b,a)};P.checkFlags=function(a,b){var c,d,e,f;if(!Object.isArray(a)){if(Object.isBoolean(a))return a;a=Object.isString(a)?this.parseFlags(a):P.arrify(a)}Object.isArray(b)&&(n.assert(1>=b.length),b=0===b.length?{}:b[0]);var g=0;for(d=a.length;g<
d;g++){var h=a[g];var k=e=0;for(c in h){var l=h[c];var m=null!=(f=b[c])?f:!1;k+=1;m===l&&(e+=1)}if(e===k)return!0}return!1};P.createEventCIDs=function(){var a;var b=Object.values(config.events);var c=0;for(a=b.length;c<a;c++){var d=b[c];P.addEventCID(d,d.mod)}a=Object.values(config.sprawls);c=0;for(d=a.length;c<d;c++)b=a[c],P.addEventCID(b,b.mod);b=Object.values(config.zones);d=0;for(a=b.length;d<a;d++)c=b[d],P.addEventCID(c,c.mod);b=Object.values(config.statuses);d=0;for(a=b.length;d<a;d++)c=b[d],
P.addEventCID(c,c.mod);c=Object.values(config.items);a=0;for(b=c.length;a<b;a++)d=c[a],P.addEventCID(d,d.mod);c=Object.values(config.chatLines);a=0;for(b=c.length;a<b;a++)d=c[a],P.addEventCID(d,d.mod);c=Object.values(config.locations);b=0;for(d=c.length;b<d;b++)a=c[b],P.addEventCID(a,a.mod);c=Object.values(config.characters);b=0;for(a=c.length;b<a;b++)d=c[b],P.addEventCID(d,d.mod);b=Object.values(config.tiles);a=0;for(d=b.length;a<d;a++)c=b[a],P.addEventCID(c,c.mod);b=Object.values(config.packs);
c=[];var e=0;for(d=b.length;e<d;e++)a=b[e],c.push(P.addEventCID(a,a.mod));return c};P.addEventCID=function(a,b,c){b=void 0===b?"base":b;var d,e,f;if(!Object.isString(a)&&"internal"!==a.debugCategory){a.cid=null!=(f=a.id)?f:c;n.assert(null!=a.cid);null==a.mod&&(a.mod=b);var g="select actions charEvents partyEvents storeEvents dayEvents tripEvents spawnEvents useEvents lines winEvents failEvents npcEvents events initEvents racetrackEvents".split(" ");f=[];var h=0;for(c=g.length;h<c;h++){var k=g[h];
f.push(function(){var c,f;var g=P.arrify(a[k]);var h=[];e=f=0;for(c=g.length;f<c;e=++f)d=g[e],h.push(P.addEventCID(d,b,a.cid+"."+k+"["+e+"]"));return h}())}return f}};var t=P;var ua=function(a){this.main=a;this.flags={};this.eventTextRefs={};this.checked={};this.eventsChecked=0;this.manKeywords={};var b=config.man;var c=0;for(a=b.length;c<a;c++){var d=b[c];this.manKeywords[d.keyword]=!0}};ua.wordCount=function(a){a=void 0===a?config.events:a;var b;var c=0;var d=t.arrify(a);var e=0;for(b=d.length;e<
b;e++)a=d[e],null!=a.text&&(c+=a.text.split(/[ |]/).length),null!=a.select&&(c+=this.wordCount(a.select)),null!=a.charEvents&&(c+=this.wordCount(a.charEvents)),null!=a.partyEvents&&(c+=this.wordCount(a.partyEvents)),null!=a.storeEvents&&(c+=this.wordCount(a.storeEvents));return c};ua.sanityEventCount=function(){return t.getEvent("evt-sanity-selectZero").select.length+t.getEvent("evt-sanity-selectLow").select.length+t.getEvent("evt-sanity-selectMedium").select.length+t.getEvent("evt-sanity-selectHigh").select.length};
ua.contentPoints=function(){var a=this.stats();return this.wordCount()/10+2*a.eventsNum+10*a.locationsNum+5*a.ailmentsNum+5*a.buffsNum+5*a.medalsNum+5*a.itemsNum+a.chatNum-330+258};ua.stats=function(){var a=config.events.count(function(a){return!a.id.startsWith("evt-test-")});var b=config.statuses.count(function(a){return a.isPerk});var c=config.statuses.count(function(a){return!a.isPerk});var d=config.buffs.length;var e=config.items.length;var f=config.locations.length;var g=config.chatLines.sum(function(a){return t.arrify(a.lines).length});
return{eventsNum:a,medalsNum:b,ailmentsNum:c,buffsNum:d,itemsNum:e,locationsNum:f,chatNum:g}};ua.prototype.checkEventRef=function(a){var b,c,d;var e=t.arrify(a);var f=0;for(b=e.length;f<b;f++){a=e[f];if(Object.isString(a))var g=t.getEvent(a,!1);else if(Object.isObject(a))if(null!=a.ref){g=t.getEvent(a.ref,!1);var h=a.ref;10<(null!=(c=a.slots)?c:1)&&r.warn("Suspicious slot count "+a.slots+" for event "+h,g.mod)}else g=a;null!=g?(null==g.cid&&r.warn("missing cid for event "+JSON.stringify(g).slice(0,
101),g.mod),null==this.checked[g.cid]&&(this.checked[g.cid]=!0,this.checkEventObj(g))):r.warn("unknown event ref '"+(null!=(d=a.ref)?d:a)+"'' referenced by '"+a.cid+"''",a.mod)}};ua.prototype.checkEventObj=function(a){var b,c,d,e;if(null!=a)for(c in null!=a.id&&(this.eventsChecked+=1),a){var f=a[c];"items"===c?this.checkItems(f,a):("loot"===c||"barter"===c)&&this.checkItems(f.items,a);if(null!=this.manKeywords[c]){if(n.assertOpts(f,c,{person:"dummy"},a.mod)||r.info("^^ event "+(null!=(d=null!=(e=
a.cid)?e:a.id)?d:JSON.stringify(a)),a.mod),"reqStatus"!==c&&"setStatus"!==c&&"setPartyStatus"!==c&&"reqPartyStatus"!==c||this.checkStatuses(f,a),c.toLowerCase().endsWith("flags")&&this.addFlags(f),"chat"===c&&null==t.getChat(f,!1)&&r.warn("unknown chat reference "+f+" in "+a.cid,a.mod),"replaceTiles"===c||"removeZones"===c)for(b in f=t.arrify(f),f){var g=f[b];var h=null!=g?g.radius:void 0;null!=h&&(g=h,Object.isObject(h)&&(g=h.base),0<g?r.warn("event "+a.cid+"["+b+"] has deprecated property 'radius' in "+
c+" - replace with 'range' and change value to '.."+g+"'",a.mod):r.warn("event "+a.cid+"["+b+"] has deprecated property 'radius' in "+c+" - replace with 'range'",a.mod))}}else if("actions"===c||"events"===c||"select"===c||"actions"===c||"partyEvents"===c||"charEvents"===c||"npcEvents"===c||"failEvents"===c||"winEvents"===c||"storeEvents"===c||"spawnEvents"===c)this.checkEventRef(f);else if("text"===c||"actionText"===c||"report"===c||"description"===c||"name"===c||"gameOver"===c)this.eventTextRefs[f]=
a;else if("lines"===c||"racetrackEvents"===c){h=t.arrify(f);var k=0;for(f=h.length;k<f;k++)g=h[k],this.checkEventObj(g)}else null!=a.cid&&0>F.call(config.staticKeywords,c)&&r.warn("unknown event property "+c+" in "+a.cid,a.mod)}};ua.prototype.addFlags=function(a){var b,c,d;var e=t.parseFlags(a);var f=0;for(d=e.length;f<d;f++)for(c in a=e[f],a)null==(b=this.flags)[c]&&(b[c]=0),this.flags[c]+=1};ua.prototype.checkStatuses=function(a,b){var c,d;var e=t.parseFlags(a,"st-");var f=0;for(d=e.length;f<d;f++){var g=
e[f];for(c in g)null==t.getStatus(c,!1)&&r.warn("unknown status "+c+" in "+b.cid+" (parsing statusSet: '"+JSON.stringify(a)+"')",b.mod)}};ua.prototype.checkItems=function(a,b){var c;var d=t.arrify(a);var e=0;for(a=d.length;e<a;e++){var f=d[e];for(c in f)if("slots"!==c){f=t.getItemList(c,!1);var g=t.getItem(c,!1);null==g&&null==f?r.warn("Unknown item "+c+" for "+b.cid,b.mod):null!=g&&g.isAbstract&&r.info("Abstract item "+c+" for "+b.cid,b.mod)}}};ua.prototype.checkCharacters=function(){var a,b,c;var d=
Object.values(config.characters);var e=0;for(b=d.length;e<b;e++){var f=d[e];if(null!=f.statuses){var g=f.statuses;var h=0;for(a=g.length;h<a;h++){var k=g[h];null==t.getStatus(k,!1)&&r.warn("Status "+k+" not found. "+f.cid,f.mod)}}null!=f.flags&&this.addFlags(f.flags);if(null!=f.levels)for(h=f.levels,a=0,g=h.length;a<g;a++)if(k=h[a],null!=k.statuses){var l=k.statuses;Object.isString(l)&&(l=k.statuses.split(" "));var m=0;for(c=l.length;m<c;m++)k=l[m],null==t.getStatus(k,!1)&&r.warn("Status "+k+" not found. "+
f.cid,f.mod)}}};ua.prototype.checkDice=function(){var a;var b=Object.values(config.dice);var c=[];var d=0;for(a=b.length;d<a;d++){var e=b[d];6!==t.arrify(e.faces).length?c.push(r.warn("Invalid face count on dice "+e.cid,e.mod)):c.push(void 0)}return c};ua.prototype.checkAllItems=function(){var a,b;var c=Object.values(config.items);var d=0;for(a=c.length;d<a;d++){var e=c[d];null!=e.select&&r.warn("Item "+e.cid+" should use useEvents instead of select",e.mod);null!=e.events&&r.warn("Item "+e.cid+" should use useEvents instead of events",
e.mod);var f=t.arrify(e.addStatus);var g=0;for(b=f.length;g<b;g++){var h=f[g];var k=t.getStatus(h,!1);null==k&&r.warn("Item "+e.cid+" references status with id "+h+", which cannot be found",e.mod)}null==e.name?e.isAbstract||r.warn("Item "+e.cid+" has no 'name' property",e.mod):this.eventTextRefs[e.name]=e;null==e.description?e.isAbstract||r.warn("Item "+e.cid+" has no 'description' property",e.mod):this.eventTextRefs[e.description]=e}};ua.prototype.checkAllPacks=function(){var a,b,c;var d=Object.values(config.packs);
var e=0;for(b=d.length;e<b;e++){var f=d[e];f.debugCategory=null!=(c=f.value)?c:"no value";null!=f.name&&(this.eventTextRefs[f.name]=f);null!=f.items&&this.checkItems(f.items,f);if(null!=f.statuses){var g=t.arrify(f.statuses);var h=0;for(a=g.length;h<a;h++){var k=g[h];var l=t.getStatus(k,!1);null==l&&r.warn("Pack "+f.cid+" references status with id "+k+", which cannot be found",f.mod)}}if(null!=f.characters)for(h=t.arrify(f.characters),k=0,l=h.length;k<l;k++)a=h[k],g=t.getCharacter(a,!1),null==g&&
r.warn("Pack "+f.cid+" references character with id "+a+", which cannot be found",f.mod);null!=f.items&&0!==t.arrify(f.items).length||null!=f.statuses&&0!==t.arrify(f.statuses).length||null!=f.characters&&0!==t.arrify(f.characters).length||r.warn("Pack "+f.cid+" is empty!",f.mod)}};ua.prototype.checkRefs=function(){var a,b,c;var d=Object.values(config.events);var e=0;for(c=d.length;e<c;e++){var f=d[e];null!=(a=f.id)&&a.startsWith("evt-test")||this.checkEventObj(f)}d=Object.values(config.chatLines);
a=0;for(c=d.length;a<c;a++)f=d[a],this.checkEventObj(f);f=[config.helpBonus,config.help];for(g in f)c=f[g],Object.isString(c)&&(this.eventTextRefs[c]=null);d=Object.values(config.characters);f=0;for(c=d.length;f<c;f++){var g=d[f];var h=t.arrify(g.dice);var k=0;for(b=h.length;k<b;k++)a=h[k],e=t.getDie(a,!1),null==e&&r.warn("Unknown die "+a+" for character "+g.cid,g.mod);a=t.arrify(g.items);e=!1;b=0;for(h=a.length;b<h;b++)k=a[b],this.checkItems(k,g),null!=k.slots&&(e=!0);!e&&1<a.length&&r.warn(g.id+
";multiple item sets detected (max 1 supported):\n"+JSON.stringify(g.items))}d=Object.values(config.itemList);f=0;for(c=d.length;f<c;f++)g=d[f],this.checkItems(g.items,g);c=Object.values(config.statuses);f=0;for(g=c.length;f<g;f++)d=c[f],d=t.getStatus(d.id),null!=d.title&&null==d.sprite&&r.warn("missing image for status "+d.cid);a=Object.values(config.items);d=0;for(c=a.length;d<c;d++)g=a[d],f=t.getItem(g.id),f.sprite||f.collectionItem||f.isAbstract||r.warn("missing image for item "+f.cid),this.checkEventRef(g.dayEvents),
this.checkEventRef(g.useEvents);d=Object.values(config.locations);c=0;for(g=d.length;c<g;c++)f=d[c],this.checkEventRef(f.spawnEvents),this.checkEventRef(f.actions),this.checkEventRef(f.dayEvents);f=Object.values(config.tiles);d=0;for(g=f.length;d<g;d++)c=f[d],this.checkEventRef(c.events);f=Object.values(config.zones);c=0;for(g=f.length;c<g;c++)d=f[c],this.checkEventRef(d.events);r.info("Checked "+this.eventsChecked+" events")};ua.prototype.checkLang=function(a,b,c){var d,e,f,g,h,k,l,m,p,w,n,q;var v=
"en"===a;for(h in b){var y=b[h];var t=k=f=e=0;if(!h.includes("store-desc")){var A=q=0;for(l=y.length;q<l;A=++q){var H=y[A];"["===H&&(e+=1);"]"===H&&--e;"{"===H&&(f+=1);"}"===H&&--f;if("]"===H&&0===e){if(0===t)if(v)c.push(h);else{if(!c.includes(h)){r.warn("["+a+"] invalid text format "+h+" (square brackets with no bars at "+A+": last bracket '"+y.slice(k,+(k+20)+1||9E9)+"...')");break}}else{t=y.slice(k+1,+(A-1)+1||9E9);var G=-1;var V=g=0;for(d=t.length;g<d;V=++g){var T=t[V];"{"===T?G=V:"}"===T&&(T=
t.slice(G,+V+1||9E9),t=t.replace(T,T.replace("|","-")))}d=t.split("|");g=0;for(T=d.length;g<T;g++){var u=d[g];1<d.count(function(a){return a===u})&&r.warn("["+a+"] invalid text format "+h+" (Duplicates of '"+u+"' within options: "+t)}}t=0}if(1<e){r.warn("["+a+"] invalid text format "+h+" (nested bracket at "+A+": last bracket '"+y.slice(k,+(k+20)+1||9E9)+"...')");e=0;break}if(0>e){r.warn("["+a+"] invalid text format "+h+" (invalid closing bracket at "+A+": last bracket '"+y.slice(k,+(k+20)+1||9E9)+
"...')");e=0;break}if(1<f){r.warn("["+a+"] invalid text format "+h+" (nested c-bracket at "+A+": last bracket '"+y.slice(G,+(G+20)+1||9E9)+"...')");e=0;break}if(0>f){r.warn("["+a+"] invalid text format "+h+" (invalid closing c-bracket at "+A+": last bracket '"+y.slice(G,+(G+20)+1||9E9)+"...')");e=0;break}"|"===H&&(t+=1,0===f&&0===e&&"@vars"!==h&&"loading-entries"!==h&&r.warn("["+a+"] invalid text format "+h+" (Horziontal Bar not within brackets at "+A+": '..."+y.slice(A-10,+(A+20)+1||9E9)+"...')"));
if("["===H||"]"===H)k=A;if("{"===H||"}"===H)G=A}0!==e&&r.warn("["+a+"] invalid text format "+h+" ("+e+" open brackets: last bracket '"+y.slice(k,+(k+20)+1||9E9)+"...')");0!==f&&r.warn("["+a+"] invalid text format "+h+" ("+e+" open c-brackets: last bracket '"+y.slice(G,+(G+20)+1||9E9)+"...')")}}c=this.eventTextRefs;for(y in c)v=c[y],y.startsWith("txt-")?b[y.slice(4)]||r.warn("["+a+"] missing text key "+y+" referenced by '"+(null!=(w=null!=v?v.cid:void 0)?w:"unknown")+"'",null!=(n=null!=v?v.mod:void 0)?
n:"base"):y.startsWith("!")||r.warn("untranslated text "+y+" referenced by '"+(null!=(m=null!=v?v.cid:void 0)?m:"unknown")+"'",null!=(p=null!=v?v.mod:void 0)?p:"base");r.info("Checked "+Object.size(b)+" language lines and "+Object.keys(this.eventTextRefs).length+" keys for language "+a)};ua.prototype.checkTiles=function(){var a,b,c;var d=Object.values(config.tiles);var e=0;for(b=d.length;e<b;e++){var f=d[e];if(null!=f.sprites){var g=f.sprites;var h=0;for(a=g.length;h<a;h++){var k=g[h];null==this.main.r.img.sprites[k]&&
r.warn("tile sprite "+k+" not found (tile "+f.cid+")",f.mod)}}if(null!=f.borderSprites)for(6!==f.borderSprites.length&&r.warn("unexpected number of bordersprites for tile "+f.cid+" (expecting 6; found "+f.borderSprites.length+")",f.mod),k=t.arrify(f.borderSprites),a=0,g=k.length;a<g;a++){h=k[a];var l=t.arrify(h);var m=0;for(c=l.length;m<c;m++)h=l[m],null==this.main.r.img.sprites[h]&&r.warn("border sprite "+h+" not found (tile "+f.cid+")",f.mod)}else null!=f.borderImgIdx&&r.warn("tile "+f.cid+" has deprecated borderImgIdx: replace with list of borderSprites",
f.mod)}};ua.prototype.checkSounds=function(){var a,b,c,d;if("undefined"!==typeof require&&null!==require){var e=require("fs");var f=config.sounds;for(d in f){var g=f[d];if(g.includes("mods")){for(b=g;b.includes("../");)b=b.replace("../","");var h=[];h.push(b+this.main.r.sfx.audioFormat);var k=!1;var l=0;for(a=h.length;l<a;l++)if(b=h[l],e.existsSync(b)){k=!0;break}k||(k=null!=(c=h[0].split("/")[1])?c:"base",r.warn("sound file not found: "+d+": "+g,k))}}}};ua.dumpUnlockHints=function(){var a,b;var c=
Object.values(config.characters);var d=[];var e=0;for(a=c.length;e<a;e++){var f=c[e];0<(null!=(b=f.unlockHint)?b.length:void 0)&&d.push(f.id+": "+f.unlockHint)}return d};ua.dumpFameItems=function(){var a;var b=Object.values(config.items);var c=[];var d=0;for(a=b.length;d<a;d++){var e=b[d];null!=e.fame?c.push(r.info(e.id.padLeft(30)+"  FAME: "+e.fame.format(0).padLeft(4)+"  FUNDS: "+e.funds.format(0).padLeft(4))):c.push(void 0)}return c};ua.dumpIOUnusedLocations=function(){var a,b;var c=[];var d=config.locations;
for(b in d)if(d=t.getLocation(b),!d.isAbstract&&!d.linked&&"quest"!==d.debugCategory){var e=!1;var f=this.main.worldGenIO.biomes;for(a in f)if(d=f[a],d.locations.any(function(a){return a===b})){e=!0;break}e||c.push(b)}return c};"undefined"!==typeof exports&&null!==exports&&(exports.Core=n,exports.TextHelper=q);var pa=function(a){this.next=this.next.bind(this);this.random=this.random.bind(this);this.randIntA=this.randIntA.bind(this);this.randInt=this.randInt.bind(this);this.randIntMax=this.randIntMax.bind(this);
this.randBool=this.randBool.bind(this);this.rand=this.rand.bind(this);this.randA=this.randA.bind(this);this.randR=this.randR.bind(this);this.numberRand=this.numberRand.bind(this);this.shuffle=this.shuffle.bind(this);this._initialSeed=a;this._seed=a%2147483647;0>=this._seed&&(this._seed+=2147483646)};pa.prototype.next=function(){return this._seed=16807*this._seed%2147483647};pa.prototype.random=function(){return(this.next()-1)/2147483646};pa.prototype.randIntA=function(a,b){Object.isArray(a)&&(b=a[1],
a=a[0]);return this.randInt(a,b)};pa.prototype.randInt=function(a,b){if(null!=b){var c=a;a=b}else c=0;return c>a?a:Math.floor(c)+Math.floor(this.random()*(a-c))};pa.prototype.randIntMax=function(a){return Math.floor(this.random()*a)};pa.prototype.randBool=function(){return.5>this.random()};pa.prototype.rand=function(a,b){return a>b?b:a+this.random()*(b-a)};pa.prototype.randA=function(a){n.assert(null!=a);return this.rand(a[0],a[1])};pa.prototype.randR=function(a){n.assert(null!=a);var b=$jscomp.makeIterator(n.parseRange(a));
a=b.next().value;b=b.next().value;return this.randInt(a,b+1)};pa.prototype.numberRand=function(a,b){1===arguments.length&&(b=a,a=0);var c=Math.min(null!=a?a:0,null!=b?b:1);var d=Math.max(null!=a?a:0,null!=b?b:1)+1;return Math.floor(this.random()*(d-c)+c)};pa.prototype.shuffle=function(a){var b;a=a.concat();for(b=a.length;b;){var c=this.random()*b|0;var d=a[--b];a[b]=a[c];a[c]=d}return a};"undefined"!==typeof exports&&null!==exports&&(exports.Random=pa);var u=function(a,b){n.assert(null!=a);if(1<arguments.length)this.x=
a,this.y=b;else{var c=$jscomp.makeIterator(a);this.x=c.next().value;this.y=c.next().value}};u.fromObj=function(a){n.assert(null!=a);return new u(a.x,a.y)};u.prototype.zero=function(){return this.x=this.y=0};u.prototype.add=function(a){return new u(this.x+a.x,this.y+a.y)};u.prototype.sub=function(a){return new u(this.x-a.x,this.y-a.y)};u.prototype.move=function(a,b){var c=this;var d=0;for(b=void 0===b?1:b;0<=b?d<b:d>b;0<=b?++d:--d)c=c.add(c.getDelta(a));return c};u.prototype.floor=function(){return new u(Math.floor(this.x),
Math.floor(this.y))};u.prototype.getDelta=function(a){var b=0===this.x%2;switch(a.val){case 0:return new qa(0,0);case 1:return new qa(0,-1);case 2:return new qa(1,b?-1:0);case 3:return new qa(1,b?0:1);case 4:return new qa(0,1);case 6:return new qa(-1,b?-1:0);case 5:return new qa(-1,b?0:1);default:return n.assert(!1,"Unknown dir in hex move")}};u.prototype.toHex=function(){return new u(this.x,this.y+Math.ceil(this.x/2))};u.prototype.getDir=function(a){a=a.sub(this);return 0===a.x&&0===a.y?K.here:Math.abs(a.x)<=
.5*Math.abs(a.y)?0<=a.y?K.s:K.n:0<=a.x?0===a.y&&0===this.x%2||0<a.y?K.se:K.ne:0===a.y&&0===this.x%2||0<a.y?K.sw:K.nw};u.prototype.getDirs=function(a){a=a.sub(this);return 0===a.x&&0===a.y?[K.here]:Math.abs(a.x)<=.5*Math.abs(a.y)?0<=a.y?[K.s]:[K.n]:0<a.x?0===a.y&&0===this.x%2?[K.se,K.ne]:0<a.y?[K.se]:[K.ne]:0===a.y&&0===this.x%2?[K.sw,K.nw]:0<a.y?[K.sw]:[K.nw]};u.prototype.dist=function(a){var b=this.toHex();var c=a.toHex();a=c.x-b.x;b=c.y-b.y;return 0<=a===0<=b?Math.max(Math.abs(a),Math.abs(b)):Math.abs(a)+
Math.abs(b)};u.prototype.rectDist=function(a){return Math.max(Math.abs(a.x-this.x),Math.abs(a.y-this.y))};u.prototype.radius=function(a){var b,c,d,e,f,g;var h=[];50<a&&r.warn("restricting max tile radius to 50 (was "+a+")");a=Math.min(a,50);var k=f=b=-a;for(c=a;b<=c?f<=c:f>=c;k=b<=c?++f:--f){var l=g=d=-a;for(e=a;d<=e?g<=e:g>=e;l=d<=e?++g:--g)l=new u(this.x+k,this.y+l),this.dist(l)<=a&&h.push(l)}return h};u.prototype.range=function(a){var b,c,d,e,f,g;var h=$jscomp.makeIterator(n.parseRange(a));a=h.next().value;
h=h.next().value;var k=[];50<h&&r.warn("restricting max tile range to 50 (was "+h+")");h=Math.min(h,50);var l=f=b=-h;for(c=h;b<=c?f<=c:f>=c;l=b<=c?++f:--f){var m=g=d=-h;for(e=h;d<=e?g<=e:g>=e;m=d<=e?++g:--g){var p=new u(this.x+l,this.y+m);m=this.dist(p);a<=m&&m<=h&&k.push(p)}}return k};u.prototype.diff=function(a){return new u(a.x-this.x,a.y-this.y)};u.prototype.max=function(){return Math.max(this.x,this.y)};u.prototype.mul=function(a){if(Object.isNumber(a)){var b=$jscomp.makeIterator(this.lst());
var c=b.next().value;b=b.next().value;return new u(c*a,b*a)}c=$jscomp.makeIterator(a.lst());c.next();c.next();return new u(this.x*a[0],this.y*a[1])};u.prototype.geoDist=function(a){a=this.diff(a);return Math.sqrt(a.x*a.x+a.y*a.y)};u.prototype.eq=function(a){return null!=a&&this.x===a.x&&this.y===a.y};u.prototype.toString=function(){return this.x+","+this.y};u.prototype.lst=function(){return[this.x,this.y]};u.prototype.clone=function(){return new u(this.x,this.y)};u.prototype.isZero=function(){return 0===
this.x&&0===this.y};u.prototype.getNeighbors=function(a,b){b=void 0===b?1:b;var c,d,e,f,g,h;var k=[];if(void 0===a||a)for(a=g=c=-b,d=+b;c<=d?g<=d:g>=d;a=c<=d?++g:--g){var l=h=e=-b;for(f=+b;e<=f?h<=f:h>=f;l=e<=f?++h:--h)0===a&&0===l||k.push(new u(this.x+a,this.y+l))}else for(d=[[-1,0],[1,0],[0,-1],[0,1]],b=0,c=d.length;b<c;b++)l=$jscomp.makeIterator(d[b]),a=l.next().value,l=l.next().value,k.push(new u(this.x+a,this.y+l));return k.compact()};u.prototype.length=function(){return this.dist(new u(0,0))};
u.prototype.normal=function(){var a=this.length();return 0<a?this.mul(1/a):this.clone()};u.prototype.lerp=function(a,b){if(null!=a){var c=a.x-this.x;a=a.y-this.y}else a=c=0;return new u(this.x+b*c,this.y+b*a)};var Na=function(a){return u.apply(this,arguments)||this};$jscomp.inherits(Na,u);Na.prototype.toHex=function(){return new Na(this.x,this.y)};Na.prototype.move=function(a,b){b=void 0===b?1:b;return new Na(this.x+b*a.delta.x,this.y+b*a.delta.y)};Na.prototype.getDir=function(a){a=a.sub(this);return 0===
a.x&&0===a.y?K.here:0===a.x?0<=a.y?K.s:K.n:0<=a.x?0<a.y?K.se:K.ne:0<=a.y?K.sw:K.nw};Na.prototype.radius=function(a){var b,c,d,e,f,g;var h=[];a=Math.floor(a);50<a&&r.warn("restricting max tile radius to 50 (was "+a+")");a=Math.min(a,50);var k=f=b=-a;for(c=a;b<=c?f<=c:f>=c;k=b<=c?++f:--f){var l=g=d=-a;for(e=a;d<=e?g<=e:g>=e;l=d<=e?++g:--g)l=new Na(this.x+k,this.y+l),this.dist(l)<=a&&h.push(l)}return h};Na.prototype.range=function(a){var b,c,d,e,f,g,h;var k=$jscomp.makeIterator(n.parseRange(a));a=k.next().value;
k=k.next().value;var l=[];50<k&&r.warn("restricting max tile range to 50 (was "+k+")");k=Math.min(k,50);var m=g=b=-k;for(c=k;b<=c?g<=c:g>=c;m=b<=c?++g:--g){var p=h=d=-k;for(e=k;d<=e?h<=e:h>=e;p=d<=e?++h:--h)p=new Na(this.x+m,this.y+p),a<=(f=this.dist(p))&&f<=k&&l.push(p)}return l};Na.prototype.dist=function(a){var b=a.x-this.x;a=a.y-this.y;return 0<=b===0<=a?Math.max(Math.abs(b),Math.abs(a)):Math.abs(b)+Math.abs(a)};Na.invDir=function(a){switch(a.val){case 0:return K.here;case 1:return K.s;case 2:return K.sw;
case 3:return K.nw;case 4:return K.n;case 5:return K.ne;case 6:return K.se}};var Pb=function(a,b){var c=u.call(this,a,b)||this;c.x=a;c.y=b;return c};$jscomp.inherits(Pb,u);var qa=Pb;var R=function(a,b){n.assert(null!=a);if(1<arguments.length){var c=u.call(this,a,b)||this;c.w=a;c.h=b}else{c=u.call(this,a)||this;var d=$jscomp.makeIterator(a);c.w=d.next().value;c.h=d.next().value}return c};$jscomp.inherits(R,u);R.prototype.lst=function(){return[this.w,this.h]};var J=function(){var a=function(){};a.bboxIntersect=
function(a,c,d,e,f,g,h,k){return!(f>a+d||f+h<a||g>c+e||g+k<c)};a.clamp=function(a,c,d){return Math.max(Math.min(a,d),c)};a.parseInt=function(a,c){c=void 0===c?0:c;a=parseInt(a);return isNaN(a)?c:a};a.randIntA=function(a,c){return this.rng.randIntA(a,c)};a.randInt=function(a,c){return this.rng.randInt(a,c)};a.randIntMax=function(a){return this.rng.randIntMax(a)};a.rand=function(a,c){return this.rng.rand(a,c)};a.randA=function(a){return this.rng.randA(a)};a.randR=function(a){return this.rng.randR(a)};
a.lerp=function(a,c,d,e){return a+(c-a)*this.clamp(d/(void 0===e?1:e),0,1)};a.smoothStep=function(a){return a*a*(3-2*a)};a.scaleTriangle=function(a,c,d,e){var b=(a.x+c.x+d.x)/3;var g=(a.y+c.y+d.y)/3;var h=(a.z+c.z+d.z)/3;a.x=(a.x-b)*e+b;a.y=(a.y-g)*e+g;a.z=(a.z-h)*e+h;c.x=(c.x-b)*e+b;c.y=(c.y-g)*e+g;c.z=(c.z-h)*e+h;d.x=(d.x-b)*e+b;d.y=(d.y-g)*e+g;return d.z=(d.z-h)*e+h};a.padTriangle=function(b,c,d,e){var f=b.diff(c);var g=c.diff(d);var h=d.diff(b);f=Math.max(f.length(),g.length(),h.length());return a.scaleTriangle(b,
c,d,(f+e)/f)};a.sign=function(a){return 0>a?-1:0<a?1:0};a.addCount=function(a,c){var b;var e={};for(b in a){var f=a[b];null==e[b]&&(e[b]=0);e[b]+=f}for(b in c)f=c[b],null==e[b]&&(e[b]=0),e[b]+=f;return e};a.isInteger=function(a){return 0===a%1};a.rng=new pa(Date.now());return a}.call(this);var Oa=function(a){this.showBiome=this.showBiome.bind(this);this.main=a;this.r=this.main.r;this.s=this.main.r.s;this.info={}};Oa.prototype.hide=function(){};Oa.prototype.showTile=function(a,b){var c,d,e,f;if(null!=
a){var g=[];if(a.biome.generated){(d=null!=(null!=(c=a.location)?c.name:void 0)&&(a.location.known||debug.drawAllLocations))?g.push({text:a.location.name}):(a.known||debug.drawAllTiles)&&g.push({text:a.name});d&&g.push({text:a.name});(a.biome.entered||debug.drawAllTiles||null!=a.biome.claim)&&a.biome.blocking&&g.push({text:" ("+q.toText("txt-tile-impassable")+")"});this.regionDifficulty=0;if(n.isIO()&&!this.main.isWarping()&&!a.biome.blocking&&null==this.main.tutorial){c=this.main.worldGenIO.getBiomeDict(a.biome.pos);
var h=this.main.worldGenIO.worldSegmentList[c.worldSegment];null!=h&&g.push({text:""+h.name});this.regionDifficulty=this.main.worldGenIO.difficultyLvls.indexOf(c.worldLvl)+1}!n.isIO()||a.biome.blocking||this.main.isWarping()||null!=this.main.tutorial||(null!=a.biome.claim&&null!=a.biome.claim.user?g.push({text:q.toText("txt-io-claim")+" "+a.biome.claim.user.displayName,col:config.colors.ioBiomeClaim}):g.push({text:""+q.toText("txt-io-unclaimed"),col:config.colors.ioBiomeClaim}));1<a.elevation&&(g.push(null),
g.push({text:q.toText("txt-tile-elevated")}));0<b.pathCost&&(g.push(null),g.push({text:q.toText("txt-tile-travelcost")+": "+(b.tripCost+b.pathCost)+" ("+b.tripCost+" + "+b.pathCost+")"}),g.push({text:q.toText("txt-tile-traveldays")+": "+b.days}),0<=b.sanityRisk&&(g.push(null),g.push({text:q.toText("txt-bonus-sanityRisk")+": "+100*b.sanityRisk+"%"})));var k=a.zones;var l=c=0;for(h=k.length;c<h;l=++c){var m=k[l];g.push(null);g.push({text:m.name,col:config.colors.zone});if(0<m.inactiveTurns){var p=q.toText("txt-tile-sleeping").replace("$val",
m.inactiveTurns);g.push({text:p,col:config.colors.zone})}m.seeking?0<m.maxSeekTurns&&(p=q.toText("txt-tile-seeking").replace("$val",m.maxSeekTurns-m.seekTurns),g.push({text:p,col:config.colors.zone})):0<=b.aggroChances[l]&&(l=(100*b.aggroChances[l]).format(0),p=q.toText("txt-tile-aggrochance").replace("$val",l),g.push({text:p,col:config.colors.zone}));0<m.lifeTurns&&(p=q.toText("txt-status-days")+": "+m.lifeTurns,g.push({text:p,col:config.colors.zone}))}if("undefined"!==typeof debug&&null!==debug){if(debug.showBorders)for(k=
t.arrify(a.borderSprites),c=0,h=k.length;c<h;c++)m=k[c],g.push({text:"border "+m,col:"DarkOrchid"});if(debug.showLocationInfo)for(k=t.arrify(a.locationScores),c=0,h=k.length;c<h;c++)m=k[c],g.push({text:m.id+" "+m.score,col:"DarkOrchid"});if(debug.showTileCoords&&(g.push({text:a.pos.x+","+a.pos.y+" biome "+a.biome.pos.x+","+a.biome.pos.y+" "+this.main.world.getBiomeIdx(a.biome.pos),col:"DarkOrchid"}),g.push({text:"dist: "+b.centerPos.dist(a.pos),col:"DarkOrchid"}),g.push({text:"outside: "+a.biome.isOutside,
col:"DarkOrchid"}),g.add({text:"reachable: "+a.reachable,col:"DarkOrchid"}),g.add({text:"biome: "+a.biome.id,col:"DarkOrchid"}),null!=a.location&&g.add({text:"location: "+a.location.id,col:"DarkOrchid"}),n.isIO()&&!this.main.isWarping()&&null==this.main.tutorial)){c=this.main.worldGenIO.getBiomeDict(a.biome.pos);g.push({text:"ioBiomeID "+c.biomeIdx+" worldLvl "+c.worldLvl+" worldSegment "+c.worldSegment,col:"DarkOrchid"});if(null!=c.rivers&&0<c.rivers.length){h="river: ";b=null!=(e=c.rivers)?e:[];
e=0;for(k=b.length;e<k;e++)m=b[e],h+=m.from+"-"+m.to+"; ";g.push({text:h,col:"DarkOrchid"})}0<c.locations.length&&g.push({text:"locations:"});c=c.locations;b=0;for(e=c.length;b<e;b++)h=c[b],h=t.getLocation(h),g.push({text:"  "+h.id,col:h.debugColor})}if(debug.showSprawls)for(f in e=a.sprawls,e)b=e[f],b.active&&g.push({text:f+" lt:"+b.lifeTime+" power:"+b.power,col:"DarkOrchid"});debug.showFlagsInfo&&(g.push(null),g.push({text:a.id+" flags: "+this.listFlags(a.flags),col:"DarkOrchid"}),null!=a.location&&
g.push({text:a.location.id+" age "+a.location.dayAge+" flags: "+this.listFlags(a.location.flags),col:"DarkOrchid"}),g.push({text:a.biome.id+" flags: "+this.listFlags(a.biome.flags),col:"DarkOrchid"}));d&&debug.showAgeInfo&&g.push({text:"(Day Age: "+a.location.dayAge+")",col:"DarkOrchid"})}this.setInfo(g,null,null,!0);return a.biome.entered||null!=a.biome.claim?(this.locationCount=a.biome.scoreLocations.length,this.knownLocationCount=a.biome.scoreLocations.count(function(a){return a.known})):this.locationCount=
this.knownLocationCount=0}g.push({text:q.toText("txt-tile-region")+": "+q.toText("txt-tile-generating")});this.setInfo(g,null,null,!0);if(debug.drawAllTiles)for(c=b=d=a.biome.pos.x-1,g=a.biome.pos.x+1;d<=g?b<=g:b>=g;c=d<=g?++b:--b)for(h=k=f=a.biome.pos.y-1,e=a.biome.pos.y+1;f<=e?k<=e:k>=e;h=f<=e?++k:--k)this.main.worldGenIO.generateBiome(new u(c,h))}};Oa.prototype.showBiome=function(a,b){b=void 0===b?!1:b;var c,d;var e=this.main.worldGenIO.getBiomeDict(a,null!=(d=b.drawAllTiles)?d:b);d=[];if(b&&null!=
e){var f=t.getBiome(e.biomeID);var g=t.getPocket(e.pocketID);f=e.biomeIdx+": "+e.pos.x+","+e.pos.y+", "+f.id;d.push({text:f});d.push({text:g.id});d.push({text:""});f=this.main.worldGenIO.perlinMap[e.biomeIdx];g=this.main.worldGenIO.difficultyMap[e.biomeIdx];d.push({text:"PckPerlin: "+f+" WorldPerlin: "+g});e.isBorder?d.push({text:"Blocking Region"}):(null!=e.pckZone&&d.push({text:"PckZone: "+e.pckZone}),null!=e.worldSegment&&d.push({text:"worldSegment: "+e.worldSegment}));g=this.main.worldGenIO.worldSegmentList[e.worldSegment];
null!=g&&d.push({text:""+g.name});n.assert(null!=g||e.isBorder);d.push({text:"WorldLvl "+e.worldLvl});d.push({text:"Region Seed "+e.biomeSeed});null!=e.claim&&null!=e.claim.user&&d.push({text:q.toText("txt-io-claim")+" "+e.claim.user.displayName,col:config.colors.ioBiomeClaim});if(null!=e.rivers&&0<e.rivers.length){f="river: ";g=null!=(c=e.rivers)?c:[];var h=0;for(c=g.length;h<c;h++){var k=g[h];f+=k.from+"-"+k.to+"; "}d.push({text:f,col:"DarkOrchid"})}d.push({text:""});0<e.locations.length&&d.push({text:"locations:"});
g=e.locations;f=0;for(c=g.length;f<c;f++)k=g[f],k=t.getLocation(k),d.push({text:"  "+k.id,col:k.debugColor})}else null!=e&&null!=e.claim&&(e.isBorder?(f=t.getBiome(e.biomeID),c=null!=(g=q.toText(f.name))?g:""):(c=t.getPocket(e.pocketID),c=null!=(f=q.toText(c.name))?f:""),d.push({text:c}),this.regionDifficulty=0,e.isBorder||(c=this.main.worldGenIO.worldSegmentList[e.worldSegment],null!=c&&d.push({text:""+c.name}),this.regionDifficulty=this.main.worldGenIO.difficultyLvls.indexOf(e.worldLvl)+1),e.isBorder?
d.push({text:q.toText("txt-tile-impassable")}):null!=e.claim.user&&d.push({text:q.toText("txt-io-claim")+" "+e.claim.user.displayName,col:config.colors.ioBiomeClaim}));b.showTileCoords&&d.push({text:"biome "+a.x+","+a.y,col:"DarkOrchid"});0<d.length&&this.setInfo(d,null,null,!0);return null!=e};Oa.prototype.clearInfo=function(){this.info={};return this.regionDifficulty=this.knownLocationCount=this.locationCount=0};Oa.prototype.setInfo=function(a,b,c,d){d=void 0===d?!1:d;var e,f,g;var h=$jscomp.makeIterator(this.r.getCanvasSize());
var k=h.next().value;h=h.next().value;var l=$jscomp.makeIterator([180*this.s,14*this.s]);var m=l.next().value;l=l.next().value;this.r.ctx.font=config.fonts.technicalSmall;var p=null!=(e=null!=(f=this.main.party)?null!=(g=f.getExplorer())?g.gender:void 0:void 0)?e:"male";g=t.arrify(a);var w=0;for(e=g.length;w<e;w++)f=g[w],null==f?l+=10*this.s:null!=f.text?(f.txts=q.wrap(q.parse(f.text,p),m-30*this.s,this.r.ctx),l+=10*f.txts.length*this.s):l+=10*this.s;b=null!=b?b-m/2:k-m-45*this.s;null!=c?c-=l+20*
this.s:"game"===this.main.getMainState()?(c=this.main.invBar.getSize(),c=h-l-c.h-6*this.s):c=h-l-35*this.s;return this.info={lines:t.arrify(a),pos:new u(b,c),size:new R(m,l),showTitle:d}};Oa.prototype.setTooltip=function(a){return this.tooltip=q.toText(a)};Oa.prototype.drawTooltip=function(a,b){if(null!=this.tooltip){var c=$jscomp.makeIterator(this.r.getCanvasSize());var d=c.next().value;var e=c.next().value;this.r.ctx.font=config.fonts.technicalSmall;c=3*this.s;var f=this.r.ctx.measureText(this.tooltip).width+
2*c;var g=10*this.s;b+=-c;a=J.clamp(a+f/2,f/2,d-f/2);b=J.clamp(b,g/2,e-g/2);this.r.drawInfoBox(a-f/2,b-g,f,g);this.r.drawText(this.tooltip,a,b-c,{halign:"center",font:config.fonts.technicalSmall,fillColor:config.colors.help,os:0});return this.tooltip=null}};Oa.prototype.drawInfo=function(){var a,b,c;var d=$jscomp.makeIterator(this.r.getCanvasSize());var e=d.next().value;d.next();if(null!=this.info.lines){d=this.r.ctx;this.r.drawInfoBox(this.info.pos.x,this.info.pos.y,this.info.size.w,this.info.size.h);
var f=this.info.pos.y+14*this.s;var g=$jscomp.makeIterator(config.imgSize.dice);var h=g.next().value;g=g.next().value;g=$jscomp.makeIterator([h*this.s*.5,g*this.s*.5]);h=g.next().value;g.next();var k=this.info.lines;var l=c=0;for(b=k.length;c<b;l=++c)if(g=k[l],d.font=0===l&&this.info.showTitle?config.fonts.themedSmall:config.fonts.technicalSmall,null==g)f+=10*this.s;else{if(null!=g.text){var m=g.txts;var p=0;for(l=m.length;p<l;p++){var w=m[p];this.r.drawText(w,this.info.pos.x+10*this.s,f,{fillColor:null!=
(a=g.col)?a:"white"});f+=10*this.s}}if(null!=g.die){l=t.getDie(g.die);p=l.faces.split(" ");g=m=0;for(w=p.length;m<w;g=++m){var da=p[g];da=t.getDieFace(da);this.r.drawSprite(l.sprite,this.info.pos.x+10*this.s+g*(h+3*this.s),f-9*this.s,{scale:.5});null!=da.sprite&&this.r.drawSprite(da.sprite,this.info.pos.x+10*this.s+g*(h+3*this.s),f-9*this.s,{scale:.5})}f+=10*this.s}}if(!n.isIO()&&0<this.locationCount)for(d.lineWidth=this.r.s,d.strokeStyle=config.colors.science,d.fillStyle=config.colors.science,g=
a=0,d=this.locationCount-this.knownLocationCount;0<=d?a<d:a>d;g=0<=d?++a:--a)this.r.drawSprite("res_fxt_questionmark.png",e-70*this.s-12*this.s*g,this.info.pos.y);if(0<this.regionDifficulty&&(f=this.r.img.getSprite(config.io.segmentDifficultySprite),null!=f))for(h=f.dSize.w+2*this.s,g=a=0,d=this.regionDifficulty;0<=d?a<d:a>d;g=0<=d?++a:--a)this.r.drawSprite(f,e-60*this.s-h*g,this.info.pos.y+7*this.s)}};Oa.prototype.listFlags=function(a){var b;var c="";for(b in a){var d=a[b];c+=b+": "+d+" "}return c};
Oa.prototype.showItem=function(a,b,c,d){d=void 0===d?!1:d;var e;if(0!==a.amount){var f=[];0<a.fame?f.push({text:a.name,col:config.colors.fameItem}):f.push({text:a.name});null!=a.description&&f.push({text:a.description});f.push(null);var g=t.getItem(a.id);if(null!=g.bonus){var h=q.bonusHelp(g.bonus);if(0<h.length){var k=0;for(e=h.length;k<e;k++){var l=h[k];f.push({text:l,col:config.colors.bonus})}if(g.noBonusStacking)for(e=0,h=h.length;e<h;e++)f.push({text:"txt-bonus-noStack",col:config.colors.bonus});
f.push(null)}}h="";0<a.subItems.length&&(h="("+q.toText("txt-item-contains").replace("$val",a.subItems.length)+")");f.push({text:q.toText("txt-item-amount")+": "+a.amount+"/"+a.getMaxStack()+" "+h});if("harbor"===c&&!b)f.push({text:q.toText("txt-item-cost")+": "+a.getValue(c,!1)});else if(config.showValueInfobox){h=a.getValue("base",b);e=a.getValue(c,b);c=q.toText("txt-item-value")+": "+e;h!==e&&0<h&&(h=Math.floor(100*(e/h-1)),c+=" ("+q.fmtInt(h)+"%)");if(0<a.subItems.length){var m=k=0;l=a.subItems;
h=0;for(e=l.length;h<e;h++)g=l[h],k+=g.fame,m+=g.funds;0!==k&&(c+="  "+q.toText("txt-highscore-fame")+": "+k);0===m||n.isIO()||(c+="  "+q.toText("txt-item-funds")+": "+m)}else 0!==a.fame&&(c+="  "+q.toText("txt-highscore-fame")+": "+a.fame),0===a.funds||n.isIO()||(c+="  "+q.toText("txt-item-funds")+": "+a.funds);f.push({text:c})}h=Object.clone(t.arrify(a.tempDice)).add(t.arrify(a.dice));null!=a.maxDice&&0<h.length&&f.push({text:q.toText("txt-item-help-maxDice").replace("$val",a.maxDice)});f.push(null);
0===a.fame&&0===a.funds||f.push({text:q.toText("txt-item-help-trade")});a.autoRemove&&!n.isIO()&&f.push({text:q.toText("txt-item-help-autoremove")});a.noWeight&&f.push({text:q.toText("txt-item-help-noweight")});0<h.length&&null!=f.last()&&f.push(null);e=0;for(l=h.length;e<l;e++)c=h[e],f.push({die:c});0<h.length&&f.push(null);if(a.chargeTime<a.maxChargeTime)f.push({text:q.toText("txt-item-help-chargetime").replace("$val",a.maxChargeTime-a.chargeTime)});else if(!b)null!=f.last()&&f.push(null),f.push({text:q.toText("txt-item-help-take"),
col:config.colors.help});else if(b&&null!=a.useEvents&&0<a.useEvents.length&&"ionewgame"!==this.main.getMainState()&&(null!=f.last()&&f.push(null),d))for(f.push({text:q.toText("txt-item-help-use"),col:config.colors.help}),d=a.useEvents,a=0,b=d.length;a<b;a++)if(c=d[a],c=t.getEvent(c),null!=c.tooltip){this.setTooltip(c.tooltip);break}"ranking"!==this.main.getMainState()&&f.push({text:q.toText("txt-item-help-move-not-use"),col:config.colors.help});0<f.length&&null==f.last()&&f.splice(f.length-1,1);
return this.setInfo(f,null,null,!0)}};Oa.prototype.showHelp=function(a,b,c){var d;var e=t.arrify(a,!1);var f=[];var g=0;for(d=e.length;g<d;g++)a=e[g],f.push({text:a});return this.setInfo(f,b,c)};var sa=function(a,b){this.onMouseMove=this.onMouseMove.bind(this);this.onMouseClick=this.onMouseClick.bind(this);this.onKeyPress=this.onKeyPress.bind(this);this.doBarter=this.doBarter.bind(this);this.doLoot=this.doLoot.bind(this);this.checkIOFameDeposit=this.checkIOFameDeposit.bind(this);this.doEscape=this.doEscape.bind(this);
this.main=a;this.r=this.main.r;this.s=this.main.r.s;this.sfx=this.main.sfx;this.party=this.main.party;this.diary=this.main.diary;this.dragCtx=b;this.npcDealInv=new Va(this.main);this.partyDealInv=new Va(this.main);var c=config.inventory.slotCount;this.npcShopGrid=new kb(a,b,{slots:c,fixedRows:2});this.npcDealGrid=new kb(a,b,{slots:c,fixedRows:1,inv:this.npcDealInv});this.partyDealGrid=new kb(a,b,{slots:c,fixedRows:1,inv:this.partyDealInv,owned:!0});this.partyShopGrid=new kb(a,b,{slots:c,fixedRows:3,
inv:this.party.inv,owned:!0});this.mouseDowned=!1};sa.prototype.onMouseMove=function(a,b){this.mousePos=[a,b];return null==this.npcShopGrid.gridOffset?!1:this.npcShopGrid.onMouseMove(a,b,this.priceTable)||this.partyShopGrid.onMouseMove(a,b,this.priceTable)||"barter"===this.type&&(this.npcDealGrid.onMouseMove(a,b,this.priceTable)||!this.hidePartyOffer&&this.partyDealGrid.onMouseMove(a,b,this.priceTable))?!0:!1};sa.prototype.onMouseClick=function(a){var b=this,c;var d=function(c,d){var e=$jscomp.makeIterator(c.mouseToItem(a.x,
a.y));e.next();var f=e.next().value;if(0< !(null!=f&&f.amount))return!1;e=0!==a.button||a.ctrlKey?f.amount:1;d.inv.changeItemCount(f,e);if(d===b.npcShopGrid&&"escape"===b.type&&d.inv.getInvCapacity()<d.inv.items.count(function(a){return null!=a})&&!f.noWeight)return d.inv.changeItemCount(f,-e),!1;f.consume(e);c.inv.clearEmpty();d.inv.clearEmpty();return!0};(c=function(){var a;if(null!=b.main.tutorial&&"barter"===b.type)return d(b.partyShopGrid,b.partyDealGrid);var c="barter"===b.type?b.hidePartyOffer?
[[b.npcShopGrid,b.npcDealGrid]]:[[b.npcShopGrid,b.npcDealGrid],[b.partyShopGrid,b.partyDealGrid]]:[[b.npcShopGrid,b.partyShopGrid]];var g=0;for(a=c.length;g<a;g++){var h=$jscomp.makeIterator(c[g]);var k=h.next().value;h=h.next().value;if(d(k,h)||d(h,k))return!0}return!1}())?this.updateDealState():this.mouseDowned=!0;return c};sa.prototype.onKeyPress=function(a){if(!this.main.showingBarter)return!1;32===a.which&&(this.main.diary.entryTime+=100);switch(this.type){case "barter":49===a.which?this.main.barter.doBarter(!0):
50===a.which&&this.main.barter.doBarter(!1);break;case "loot":49===a.which?this.main.barter.doLoot(!1):50===a.which&&this.main.barter.doLoot(!0)}return!0};sa.prototype.showShop=function(a,b,c){var d,e,f;this.npcShopGrid.inv=a.inv;this.resetGrids();this.baseValue=a.baseValue;this.title=a.title;this.priceTable=null!=(d=a.priceTable)?d:"base";this.hidePartyOffer=null!=(e=a.hidePartyOffer)?e:!1;this.hideNPCInv=null!=(f=a.hideNPCInv)?f:!1;this.events=b;this.partyDealGrid.reqItemFlags=this.partyShopGrid.reqItemFlags=
null!=c?c:[];this.initialItemCounts=a.inv.getItemCount();this.npcDealGrid.inv.clear();this.updateDealState();this.type="barter";this.consumeFameItems=!1;c=a.inv.items.compact();d=[];e=0;for(b=c.length;e<b;e++)a=c[e],d.push(this.party.incStatItemBarter(a.id,a.amount));return d};sa.prototype.showLoot=function(a,b,c,d,e,f){f=void 0===f?!1:f;n.assert(null!=c);this.npcShopGrid.inv=a;this.npcShopGrid.inv.getInvCapacity=function(){return c};this.resetGrids();this.title=b;this.priceTable="base";this.initialItemCounts=
a.getItemCount();this.events=d;this.partyDealGrid.reqItemFlags=this.partyShopGrid.reqItemFlags=null!=e?e:[];this.hideNPCInv=this.hidePartyOffer=!1;this.type="loot";this.consumeFameItems=f;d=a.items.compact();e=[];f=0;for(b=d.length;f<b;f++)a=d[f],e.push(this.party.incStatItemLoot(a.id,a.amount));return e};sa.prototype.resetGrids=function(){this.npcShopGrid.itemOffset=0;this.npcDealGrid.itemOffset=0;this.partyDealGrid.itemOffset=0;return this.partyShopGrid.itemOffset=0};sa.prototype.showEscape=function(a,
b,c){var d=this;var e=new Va(this.main);this.npcShopGrid.inv=e;this.events=c;this.partyDealGrid.reqItemFlags=this.partyShopGrid.reqItemFlags=[];this.resetGrids();e.getInvCapacity=function(){return b+d.npcShopGrid.inv.items.count(function(a){return null!=a&&0<a.amount&&a.noWeight})};this.title=a;this.initialItemCounts=e.getItemCount();this.hideNPCInv=this.hidePartyOffer=!1;return this.type="escape"};sa.prototype.hide=function(){return this.priceTable=this.type=null};sa.prototype.isValidTargetNPC=function(){var a=
this.npcShopGrid.dragCtx;return null==a.inv||a.inv===this.npcShopGrid.inv||a.inv===this.npcDealGrid.inv};sa.prototype.isValidTargetParty=function(){var a=this.npcShopGrid.dragCtx;return null==a.inv||null!=a.inv.party||a.inv===this.partyDealGrid.inv};sa.prototype.updateDealState=function(){var a=function(){switch(this.baseValue){case "funds":return this.party.funds;case "karma":return this.party.karma;default:return-this.baseValue}}.call(this);var b=this.npcDealGrid.inv.totalValue(this.priceTable,
!1);var c=this.partyDealGrid.inv.totalValue(this.priceTable,!0);return this.totalValue=a+c-b};sa.prototype.validLoot=function(){return null!=this.main.tutorial&&0<this.npcShopGrid.inv.items.compact().length?!1:!this.npcShopGrid.inv.isOverburden()};sa.prototype.validDeal=function(){var a=function(a){return null!=a&&!a.metaItem&&0<a.amount};var b=this.npcDealGrid.inv.items.count(a);a=this.partyDealGrid.inv.items.count(a);if(0===b&&0===a)return-1;this.updateDealState();return 0>this.totalValue?-1:Math.floor(this.totalValue/
("village"===this.priceTable?config.nativeBarterStandingSteps:1E3))};sa.prototype.tick=function(a){this.npcShopGrid.tick(a);this.npcDealGrid.tick(a);return this.partyDealGrid.tick(a)};sa.prototype.draw=function(a,b,c){var d=$jscomp.makeIterator(this.r.getCanvasSize());d.next();d.next();this.r.ctx.globalAlpha=1;var e=this.diary.getDiaryOffset();d=e.x+24*this.s;e=e.y+15*this.s;var f=200*this.s;var g={fillColor:"black",font:config.fonts.themedSmall,os:0};this.r.drawText(this.title,d,e,g);e+=5*this.s;
var h=this.validDeal();this.hideNPCInv||(this.npcShopGrid.gridOffset=new R(d,e),this.npcShopGrid.drawBackground(this.isValidTargetNPC(),a,b,c)&&this.mouseDowned&&this.npcShopGrid.tabItems(),e+=this.npcShopGrid.getSize().h+6*this.s);if("barter"===this.type){this.hideNPCInv||(this.npcDealGrid.gridOffset=new R(d,e),this.npcDealGrid.drawBackground(this.isValidTargetNPC(),a,b,c)&&this.mouseDowned&&this.npcDealGrid.tabItems(),e+=this.npcDealGrid.getSize().h+8*this.s);this.r.ctx.font=config.fonts.technicalLarge;
this.r.ctx.globalAlpha=1;if("funds"===this.baseValue)e+=10*this.s,this.r.drawText(q.toText("txt-barter-funds")+": "+this.totalValue,d+f/2,e,{halign:"center",fillColor:"black",font:"18px serif",os:0}),e+=10*this.s;else if("karma"===this.baseValue){var k=10*this.s;this.r.drawPanel(config.panel.inventory,d-2*this.s,e-this.s,f+4*this.s,k+2*this.s);this.r.ctx.fillStyle=config.colors.karmaBarBg;this.r.ctx.fillRect(d-this.s,e,f+2*this.s,k);var l=J.clamp(this.totalValue/config.karmaBarSize,0,1);this.r.ctx.fillStyle=
this.totalValue>=config.karmaBarSize?config.colors.karmaBarFull:config.colors.karmaBar;this.r.ctx.fillRect(d,e+this.s,Math.floor(l*f),k-2*this.s);e+=k*this.s}else{this.r.drawSprite("hud_barter_background.png",d-2.5*this.s,e-3*this.s,{mX:a,mY:b})&&(k=q.toText("txt-help-barter"),this.main.infoBox.setInfo({text:k,col:config.colors.help}));l=J.clamp(this.totalValue/100,-1,1);var m=0<=h?"deal":"noDeal";var p=0<=l?7*this.s:6*this.s;var w=this.r.img.getSprite("hud_barter_"+m+"_body.png");k=Math.round(d+
f/2+p*J.sign(l));var n=Math.round(e-this.s);p=Math.round(l*(f/2-p));l=Math.round(w.dSize.h);this.r.ctx.drawImage(w.img,w.pos.x,w.pos.y,w.size.w,w.size.h,k,n,p,l);this.r.drawSprite("hud_barter_centerBox.png",d+f/2-6*this.s,e-3*this.s);this.r.drawSprite("hud_barter_"+m+"_icon.png",d+f/2-4*this.s,e);e+=16*this.s}this.hidePartyOffer||(this.partyDealGrid.gridOffset=new R(d,e),this.partyDealGrid.drawBackground(this.isValidTargetParty(),a,b,c)&&this.mouseDowned&&this.partyDealGrid.tabItems(),e+=this.partyDealGrid.getSize().h+
6*this.s)}this.partyShopGrid.gridOffset=new R(d,e);this.partyShopGrid.drawBackground(!0,a,b,c)&&this.mouseDowned&&this.partyShopGrid.tabItems();this.r.ctx.globalAlpha=1;e+=this.partyShopGrid.getSize().h+10*this.s;f=q.toText("txt-barter-party");this.r.drawText(f,d,e,g);e+=15*this.s;g=$jscomp.makeIterator([80*this.s,20*this.s]);f=g.next().value;k=g.next().value;this.r.ctx.globalAlpha=1;this.r.ctx.font=config.fonts.themedSmall;switch(this.type){case "barter":"karma"===this.baseValue?(g=q.toText("txt-barter-drop"),
h=0>h?"red":"green"):0>h?(g=q.toText("txt-barter-nodeal"),h="red"):(g=0===h||"funds"===this.baseValue?q.toText("txt-barter-deal"):q.toText("txt-barter-standing").replace("$val",h),h="green");this.dealButtonPos=new u(d,e);h=this.r.drawActionPanel(g,d,e,f,k,h,a,b,c);a=this.r.drawActionPanel(q.toText("txt-barter-cancel"),d+f+10*this.s,e,f,k,"white",a,b,c);this.mouseDowned&&(h&&this.doBarter(!0),a&&this.doBarter(!1));break;case "loot":h=this.validLoot()?"green":"red";h=this.r.drawActionPanel(q.toText("txt-barter-close"),
d,e,f,k,h,a,b,c);a=this.r.drawActionPanel(q.toText("txt-barter-takeall"),d+f+10*this.s,e,f,k,"white",a,b,c);this.mouseDowned&&(h&&this.doLoot(!1),a&&this.doLoot(!0));break;case "escape":h=this.r.drawActionPanel(q.toText("txt-barter-escape"),d,e,f,k,"white",a,b,c),a=this.r.drawActionPanel(q.toText("txt-barter-cancel"),d+f+10*this.s,e,f,k,"white",a,b,c),this.mouseDowned&&(h&&this.doEscape(!0),a&&this.doEscape(!1))}return this.mouseDowned=!1};sa.prototype.doBarter=function(a){var b;this.partyShopGrid.inv.clearEmpty();
var c=this.checkItemEvents();if(a){var d=this.validDeal();if(0>d||null!=this.main.tutorial&&2>d)return;"funds"!==this.baseValue&&"karma"!==this.baseValue&&(d=this.party.changeStanding(d),this.main.notifications.addNotify({standing:d}));if("funds"===this.baseValue){var e=this.partyDealGrid.inv.items.compact();var f=0;for(b=e.length;f<b;f++)d=e[f],this.party.funds+=d.amount*d.getValue(this.priceTable,!0);e=this.npcDealGrid.inv.items.compact();f=0;for(b=e.length;f<b;f++)d=e[f],this.party.funds-=d.amount*
d.getValue(this.priceTable,!1)}else if("karma"===this.baseValue){f=this.partyDealGrid.inv.items.compact();b=0;for(e=f.length;b<e;b++)d=f[b],this.party.karma+=d.amount*d.getValue(this.priceTable,!0);this.partyDealGrid.inv.clear();this.npcDealGrid.inv.clear()}this.npcShopGrid.inv.didEverTransferMeta|=null!=this.npcDealGrid.inv.items.find(function(a){return null!=a?a.metaItem:void 0});this.npcDealGrid.inv.transfer(this.party.inv);this.partyDealGrid.inv.transfer(this.npcShopGrid.inv)}else{if(null!=this.main.tutorial)return;
this.npcDealGrid.inv.transfer(this.npcShopGrid.inv);this.partyDealGrid.inv.transfer(this.party.inv)}null==c&&(c=a?this.events.close:this.events.cancel);this.main.hideBarter(c);return this.partyDealGrid.inv.clear()};sa.prototype.doLoot=function(a){a&&this.npcShopGrid.inv.transfer(this.partyShopGrid.inv);this.partyShopGrid.inv.clearEmpty();if(this.validLoot()){var b=!this.npcShopGrid.inv.hasItemCounts(this.initialItemCounts);var c=this.checkItemEvents();null==c&&(c=b?this.events.close:this.events.cancel);
this.main.hideBarter(c);this.partyDealGrid.inv.clear();if(n.isIO()&&!a)return this.checkIOFameDeposit()}};sa.prototype.checkIOFameDeposit=function(){var a;var b=this.npcShopGrid.inv;if(this.consumeFameItems&&0<b.items.compact().length){var c=0;var d=b.items;var e=0;for(a=d.length;e<a;e++){var f=d[e];if(null!=f){0<f.amount&&0<f.getFame()&&(c+=f.getFame()*f.amount,this.main.party.incStatRankingGift(f.id,f.amount),f.amount=0);var g=f.subItems;var h=0;for(f=g.length;h<f;h++){var k=g[h];0<k.amount&&0<
k.getFame()&&(c+=k.getFame()*k.amount,this.main.party.incStatRankingGift(k.id,k.amount),k.amount=0)}}}if(0<c)return c+=Math.round(c*this.main.party.getBonus("fameScale")),this.main.party.changeFame(c),b.compact()}};sa.prototype.doEscape=function(a){a&&(this.partyShopGrid.inv.clear(),this.npcShopGrid.inv.clearOverburden());this.npcShopGrid.inv.transfer(this.partyShopGrid.inv);return this.main.hideBarter(a?this.events.close:this.events.cancel)};sa.prototype.checkItemEvents=function(){var a,b,c;var d=
{};var e=this.npcShopGrid.inv.items.compact();var f=0;for(b=e.length;f<b;f++){var g=e[f];0<g.amount&&(null==d[c=g.id]&&(d[c]=0),d[g.id]+=g.amount)}c=this.partyDealGrid.inv.items.compact();e=0;for(b=c.length;e<b;e++)g=c[e],0<g.amount&&(null==d[a=g.id]&&(d[a]=0),d[g.id]+=g.amount);c=this.events.itemEvents;g=0;for(b=c.length;g<b;g++)if(a=c[g],n.hasCount(a.items,d))return a.ref;return null};var oa=function(a,b,c){var d=this;this.cacheImages=this.cacheImages.bind(this);this.attachOnAllLoadedHandler=this.attachOnAllLoadedHandler.bind(this);
this.onAllLoaded=this.onAllLoaded.bind(this);this.getLoadState=this.getLoadState.bind(this);this.getImg=this.getImg.bind(this);this.getSpriteAsync=this.getSpriteAsync.bind(this);this.getSprite=this.getSprite.bind(this);this.hasSprite=this.hasSprite.bind(this);this.getSpriteSlots=this.getSpriteSlots.bind(this);this.loadFonts=this.loadFonts.bind(this);this.loadSpriteAtlas=this.loadSpriteAtlas.bind(this);this.restoreOverwrittenSprites=this.restoreOverwrittenSprites.bind(this);this.addFakeSprite=this.addFakeSprite.bind(this);
this.calculateSpriteSlots=this.calculateSpriteSlots.bind(this);this.getColorSlots=this.getColorSlots.bind(this);this.setSlotInfo=this.setSlotInfo.bind(this);this.extractSpriteImages=this.extractSpriteImages.bind(this);this.createSpriteSilhouette=this.createSpriteSilhouette.bind(this);this.main=a;this.onLoadedFn=b;this.langId=c;this.images={};this.sprites={};this.atlases=[];this.overwritten=[];this.modAtlases=[];this.imgLoadingCount=0;this.imgQueue=[];this.prepareImages();O.onAllLoaded=function(){return d.main.wrapSafe(d.onAllLoaded)}};
oa.prototype.scanLocalImages=function(){return require("fs")};oa.prototype.prepareImages=function(){this.addFakeSprite("evt_spec_nightCamp_lighting.png","evt-assets/evt_spec_nightCamp_lighting.png");n.isIO()&&this.addFakeSprite("evt_spec_nightCamp_1.png","evt-assets/evt_spec_nightCamp_1.png");this.loadSpriteAtlas("res_tiles",!0);this.loadSpriteAtlas("hud");this.loadSpriteAtlas("menu");this.loadSpriteAtlas("res_face");this.loadSpriteAtlas("res_emy");this.loadSpriteAtlas("res_items");this.loadSpriteAtlas("res_anm");
this.loadSpriteAtlas("res_npc");n.isIO()||this.loadSpriteAtlas("res_explorer");n.isTCE()&&this.loadSpriteAtlas("res_explorerEdition");this.loadSpriteAtlas("res_fixtures");this.loadSpriteAtlas("res_porter");this.loadSpriteAtlas("res_statusIcons");this.loadSpriteAtlas("res_charPortraits_nativeGen");this.loadSpriteAtlas("res_charSprites_nativeGen");this.loadSpriteAtlas("res_charPortraits_nativeGen_arctic");this.loadSpriteAtlas("res_charSprites_nativeGen_arctic");this.loadSpriteAtlas("res_miniSprites");
this.loadSpriteAtlas("clouds");this.loadSpriteAtlas("menu_achievementIcons");this.loadSpriteAtlas("particles");this.loadSpriteAtlas("menu_landscape");this.loadSpriteAtlas("loca_pictureFonts_ENG");this.cacheImages();switch(this.langId){case "scn":case "tcn":case "zh-CN":case "zh-TW":this.loadSpriteAtlas("loca_pictureFonts_CHN")}this.jungleLayers=[{offset:-1,sprite:"clouds_top.png"},{offset:88,sprite:"bg_layer_5.png"},{offset:55,sprite:"bg_layer_4.png"},{offset:28,sprite:"bg_layer_3.png"},{offset:10,
sprite:"bg_layer_2.png"},{offset:0,sprite:"bg_layer_1.png"}];n.isTCE()&&this.loadSpriteAtlas("menu_title_london");this.loadFonts();this.preloadPanelImages();this.emptyEvent=document.createElement("canvas");this.emptyEvent.width=411;this.emptyEvent.height=260;var a=this.emptyEvent.getContext("2d");a.fillStyle="black";a.globalAlpha=1;a.fillRect(0,0,this.emptyEvent.width,this.emptyEvent.height);if(n.isTCE())return this.addFakeSprite("moddingDefaultImage.png","moddingDefaultImage.png")};oa.prototype.cacheImages=
function(){this.biomeBorder=this.getImg("map_bgTile_border.png");this.borderTiles=this.getImg("map_border.png");this.borderTilesShadow=this.getImg("map_border_shadow.png");this.borderTilesZone=this.getImg("map_border_zone.png");this.partyTileHidden=this.getImg("playerPos_arrow.png");this.compass=this.getImg("hud_compass_needle.png");this.mapMarker=this.getImg("hud_mapMarker.png");this.path=this.getImg("hud_travelRoute.png");this.destination=this.getImg("hud_travelDestination.png");this.campfire=this.getImg("campfireFrames.png");
this.fireplace=this.getImg("fireplaceFrames.png");this.inventoryExtra=this.getImg("hud_inventory_extra.png");this.butterflyBody=this.getImg("tax_butterf_body.png");this.butterflyPattern=this.getImg("tax_butterf_pattern.png");this.butterflyWings=this.getImg("tax_butterf_wings.png");this.cloudsL=this.getImg("cloudCover_left.png");this.cloudsR=this.getImg("cloudCover_right.png");this.biomeBackground=this.getImg("map_bgTile.png");this.nativeMiniSprite=this.getImg("res_miniSprite_nativeGen.png");n.isDemo()&&
(this.logoFB=this.getImg("webdemo_socialIcons_fb.png"),this.logoTwitter=this.getImg("webdemo_socialIcons_tw.png"));this.logoMedienboard=this.getImg("logo_medienboard.png");this.logoMaschinenMensch=this.getImg("mm_logo_desktop_2.png");return this.logoSaftladen=this.getImg("logo_saftladen.png")};oa.prototype.attachOnAllLoadedHandler=function(a){return O.resDoneCount<O.resCount?this.onLoadedFn=a:"function"===typeof a?a():void 0};oa.prototype.onAllLoaded=function(){this.cacheImages();var a=[];var b=this.sprites;
for(d in b){var c=b[d];null==c.img&&a.push(d)}c=0;for(b=a.length;c<b;c++){var d=a[c];delete this.sprites[d]}if(this.areAtlasesDirty)for(this.areAtlasesDirty=!1,b=this.atlases,c=0,a=b.length;c<a;c++)d=b[c],this.extractSpriteImages(d);this.hasInitialLoadFinished||(this.hasInitialLoadFinished=!0,null==this.biomeBackgroundTinted&&(this.biomeBackgroundTinted=this.createSilhouette(this.biomeBackground,config.imgSize.biomeBgTint)),this.createSpriteSilhouette("res_emy",1,config.colors.hitCharacter),this.createSpriteSilhouette("res_porter",
1,config.colors.hitCharacter),n.isIO()||this.createSpriteSilhouette("res_explorer",1,config.colors.hitCharacter),this.createSpriteSilhouette("res_npc",1,config.colors.hitCharacter),this.createSpriteSilhouette("res_anm",1,config.colors.hitCharacter),this.createSpriteSilhouette("res_statusIcons",1,config.colors.medal),this.createSpriteSilhouette("res_items",1,"black"),this.createSpriteSilhouette("res_face",.9,"black"));if("function"===typeof this.onLoadedFn)this.onLoadedFn();return this.onLoadedFn=
null};oa.prototype.getLoadState=function(){return 0<O.resCount?O.resDoneCount/O.resCount:1};oa.prototype.preloadPanelImages=function(){var a;var b=config.panel;var c=[];for(a in b){var d=b[a];c.push(this.getImg(d.img))}return c};oa.prototype.createSilhouette=function(a,b,c){b=void 0===b?0:b;c=void 0===c?"black":c;var d=document.createElement("canvas");d.width=a.width;d.height=a.height;if(0===a.height||0===a.width)debugger;var e=d.getContext("2d");e.drawImage(a,0,0);e.globalCompositeOperation="source-in";
e.fillStyle=c;e.fillRect(0,0,a.width,a.height);e.globalCompositeOperation="source-over";e.globalAlpha=b;e.drawImage(a,0,0);return d};oa.prototype.mergeSpritesASync=function(a){var b;var c=[];var d=0;for(b=a.length;d<b;d++){var e=a[d];c.push(this.getSpriteAsync(e,"evt-assets/"+e))}return Promise.all(c).then(function(a){var b;var c=$jscomp.makeIterator(a.first().size.lst());var d=c.next().value;var f=c.next().value;c=document.createElement("canvas");c.width=d;c.height=f;var m=c.getContext("2d");var p=
0;for(b=a.length;p<b;p++)e=a[p],n.assert(e.size.w===d&&e.size.h===f,"dimensions of images don't match"),m.drawImage(e.img,e.pos.x,e.pos.y,d,f,0,0,d,f);return Promise.resolve(c)})};oa.prototype.getImg=function(a,b,c,d){var e=this;b=void 0===b?null:b;c=void 0===c?!1:c;d=void 0===d?null:d;var f=function(){--e.imgLoadingCount;a=e.imgQueue.shift();if(null!=a)return g(a)};var g=function(a){e.imgLoadingCount+=1;var b=e.images[a];b.onload=function(){var a;if(null!=b.loadCallbacks){var c=b.loadCallbacks;var d=
0;for(a=c.length;d<a;d++){var e=c[d];try{e(b)}catch(v){e=v,r.error(e)}}}b.loadCallbacks=null;O.resDoneCount+=1;O.updateLoadingBar();f()};b.onerror=function(a){O.resDoneCount+=1;b.loadCallbacks=null;r.error("could not load image "+b.src,b.mod);e.main.displayLoadError(b.src,a.type);f()};O.resCount+=1;O.updateLoadingBar();b.src=b.reload?a+("?cache="+Date.now()):a};if(null==a)return null;var h="img/"+a;h.includes("mods")&&(h=""+a);var k=this.images[h];if(null!=k&&(null!=k.loadCallbacks||!c))return null!=
k.loadCallbacks&&null!=b&&k.loadCallbacks.push(b),c&&(k.reload=!0),k;k=new Image;k.mod=d;k.loadCallbacks=[];null!=b&&k.loadCallbacks.push(b);k.reload=c;this.images[h]=k;5<this.imgLoadingCount?this.imgQueue.push(h):g(h);return k};oa.prototype.getSpriteAsync=function(a,b){return null!=this.sprites[a]?null!=this.sprites[a].loadPromise?this.sprites[a].loadPromise:Promise.resolve(this.sprites[a]):this.addFakeSprite(a,b,"img")};oa.prototype.getSprite=function(a){if(Object.isObject(a))return a;var b=this.sprites[a];
n.assert(null!=b,"Unknown sprite "+a);return b};oa.prototype.hasSprite=function(a,b){return null==b?null!=this.sprites[a]:null!=this.sprites[a]&&this.sprites[a].mod===b};oa.prototype.getSpriteSlots=function(a,b){b=void 0===b?1:b;var c,d;a=null!=(d=t.getSlots(a))?d:{};var e={};for(c in a){var f=a[c];if("id"!==c){e[c]=[];var g=0;for(d=f.length;g<d;g++){var h=f[g];e[c].push(new u(h[0]*b,h[1]*b))}}}return e};oa.prototype.loadFonts=function(){var a;var b=config.fonts;var c=0;for(a=b.length;c<a;c++){var d=
b[c];this.getImg(d.imgSrc)}};oa.prototype.loadSpriteAtlas=function(a,b,c,d){var e=this;b=void 0===b?!1:b;c=void 0===c?null:c;d=void 0===d?"img":d;this.getImg(a+".png",function(f){var g;b&&(g=e.getImg(a+"_sil.png"));e.atlases.includes(a)||e.atlases.push(a);e.modAtlases.includes(a)||null==c||e.modAtlases.push(a);var h=null!=c?a+".json":"img/"+a+".json";e.areAtlasesDirty=!0;O.readFileAsync(h,function(b){var h,k;try{b=JSON.parse(b);var p=b.frames;var w=0;for(h=p.length;w<h;w++){var n=p[w];var q=n.frame;
var v={id:n.filename,atlas:a,img:f,imgTinted:g,pos:new u(q.x,q.y),size:new R(q.w,q.h),dSize:new R(2*q.w,2*q.h),scale:2,slots:{},pivot:n.pivot,mod:c,extracted:!1};null==e.sprites[v.id]||null==c||e.overwritten.includes(e.sprites[v.id].atlas)||(c.modWarn("Overwriting sprite '"+v.id+"' in atlas '"+e.sprites[v.id].atlas+"' from '"+(null!=(k=e.sprites[v.id].mod)?k:"base")+"' with '"+a+"'",7),e.overwritten.push(e.sprites[v.id].atlas));"slotted"===d&&e.calculateSpriteSlots(v);e.sprites[v.id]=v}}catch(y){b=
y,r.error("Error parsing json "+a+": "+b)}})})};oa.prototype.restoreOverwrittenSprites=function(){var a;var b=this.overwritten;var c=0;for(a=b.length;c<a;c++){var d=b[c];this.loadSpriteAtlas(d,"res_tiles"===d)}b=this.modAtlases;c=0;for(a=b.length;c<a;c++)d=b[c],this.atlases.remove(d);this.overwritten=[];return this.modAtlases=[]};oa.prototype.addFakeSprite=function(a,b,c,d){var e=this;c=void 0===c?"img":c;d=void 0===d?null:d;var f=null!=d?d.id:null;var g=null!=d;var h="fake_"+b;if(null!=this.sprites[a]){var k=
!this.overwritten.includes(this.sprites[a].atlas)&&!this.sprites[a].atlas.startsWith("fake_");null==d&&r.warn("Overwriting sprite["+a+"]");var l=null!=this.sprites[a].mod?this.sprites[a].mod.id:"base";null==d||this.sprites[a].mod&&this.sprites[a].mod.id===d.id||d.modWarn("Overwriting sprite["+a+"] from "+l,7);null!=d&&k&&this.overwritten.push(this.sprites[a].atlas)}else this.sprites[a]={mod:d,atlas:h};l=new Promise(function(k,l){if("img"===c)return e.getImg(""+b,function(b){var c=e.main.s;var f={id:a,
atlas:h,img:b,imgTinted:b,pos:new u(0,0),size:new R(b.width,b.height),dSize:new R(c*b.width,c*b.height),scale:c,slots:{},extracted:!1,mod:d};e.sprites[f.id]=f;c="img/"+a;null!=e.images[c]&&(e.images[c]=b);return k(f)},g,f);if("tileBorders"===c)return null==d&&r.info("Loading tile border"),null!=d&&d.modLog("Loading tile border: "+b,9),e.getImg(""+b,function(b){var c,f;var g=e.main.s;var l=b.width/3;var m=b.height/2;var p="_n _ne _se _s _sw _nw".split(" ");for(f=c=0;5>=c;f=++c){var w={id:a+p[f],atlas:h,
img:b,imgTinted:b,pos:new u(f%3*l,Math.floor(f/2)*m),size:new R(l,m),dSize:new R(g*l,g*m),scale:g,slots:{},extracted:!1,mod:d};e.sprites[w.id]=w}return k(w)},g,f);if("miniSprite"===c)return e.getImg(""+b,function(b){var c,f;var g=e.main.s;var l=b.width;var m=b.height/8;for(f=c=0;7>=c;f=++c){var p={id:a+"_"+f,atlas:h,img:b,imgTinted:b,pos:new u(0,f*m),size:new R(l,m),dSize:new R(g*l,g*m),scale:g,slots:{},extracted:!1,mod:d};e.sprites[p.id]=p}return k(p)},g,f);if("slotted"===c)return e.getImg(""+b,
function(b){var c=e.main.s;b={id:a,atlas:h,img:b,imgTinted:b,pos:new u(0,0),size:new R(b.width,b.height),dSize:new R(c*b.width,c*b.height),scale:c,slots:{},extracted:!1,mod:d};e.sprites[b.id]=b;e.calculateSpriteSlots(b);return k(b)},g,f)});this.sprites[a].loadPromise=l;this.atlases.push(h);return l};oa.prototype.calculateSpriteSlots=function(a){var b,c;var d=$jscomp.makeIterator(a.size.lst());var e=d.next().value;var f=d.next().value;var g={id:a.id};d=document.createElement("canvas");d.width=e;d.height=
f;var h=d.getContext("2d");h.drawImage(a.img,a.pos.x,a.pos.y,e,f,0,0,e,f);e=h.getImageData(0,0,e,f);var k=c=0;for(b=e.data.length;c<=b;k=c+=4){var l=k/4%e.width;var m=Math.floor(k/4/e.width);var p=this.getColorSlots(e.data.slice(k,+(k+2)+1||9E9));var w=0;for(f=p.length;w<f;w++){var n=p[w];null==g[n]&&(g[n]=[]);g[n].push([l,m])}0<p.length&&4<=k&&(e.data[k]=e.data[k-4],e.data[k+1]=e.data[k-3],e.data[k+2]=e.data[k-2],e.data[k+3]=e.data[k-1])}h.putImageData(e,0,0);a.img=d;a.pos=new u(0,0);a.extracted=
!0;return this.setSlotInfo(g)};oa.prototype.getColorSlots=function(a){var b;var c=[];var d=config.slotColors;for(b in d){var e=d[b];e[0]===a[0]&&e[1]===a[1]&&e[2]===a[2]&&c.add(b)}return c};oa.prototype.setSlotInfo=function(a){return config.slots[a.id]=a};oa.prototype.extractSpriteImages=function(a){var b;var c=this.sprites;var d=[];for(b in c){var e=c[b];if(e.atlas===a){var f=$jscomp.makeIterator(e.pos.lst());var g=f.next().value;f=f.next().value;var h=$jscomp.makeIterator(e.size.lst());var k=h.next().value;
var l=h.next().value;h=document.createElement("canvas");h.width=k;h.height=l;var m=h.getContext("2d");m.drawImage(e.img,g,f,k,l,0,0,k,l);e.img=h;null!=e.imgTinted&&(h=document.createElement("canvas"),h.width=k,h.height=l,m=h.getContext("2d"),m.drawImage(e.imgTinted,g,f,k,l,0,0,k,l),e.imgTinted=h);e.pos=new u(0,0);d.push(e.extracted=!0)}else d.push(void 0)}return d};oa.prototype.createSpriteSilhouette=function(a,b,c){c=void 0===c?"black":c;var d;var e=this.sprites;var f=[];for(d in e){var g=e[d];g.atlas===
a&&(n.assert(g.extracted),null==g.silhouetteImg&&(g.silhouetteImg={}),f.push(g.silhouetteImg[c]=this.createSilhouette(g.img,1-b,c)))}return f};var ab=function(a){var b,c,d,e,f;this.main=a;n.canUseLocalStorage()?(this.musicVolume=J.clamp(parseFloat(null!=(b=null!=(c=window.localStorage)?c.musicVolume:void 0)?b:1),0,1),this.soundVolume=J.clamp(parseFloat(null!=(d=null!=(e=window.localStorage)?e.soundVolume:void 0)?d:1),0,1)):this.musicVolume=this.soundVolume=1;this.audioContext=new (null!=(f=window.AudioContext)?
f:window.webkitAudioContext);a=(new Audio).canPlayType("audio/ogg");this.audioFormat=""!==a?".ogg":".mp4";r.info("Using audio format "+this.audioFormat+" (ogg result was '"+a+"')");this.musicGroup=[];this.soundGroup=[];this.sounds={};n.isDemo()||this.preloadSounds()};ab.prototype.preloadSounds=function(){var a;this.nextCharSound=this.getSound("nextChar");this.diaryAction=this.getSound("diaryAction");this.moveConfirm=this.getSound("moveConfirm");this.triangulation=this.getSound("triangulation");n.isTCE()&&
(this.achievement=this.getSound("achievement"));this.outroBang=this.getSound("outroBang");this.yay=this.getSound("yay");n.isTCE()&&(this.getSound("cheer1"),this.getSound("cheer2"),this.getSound("cheer3"));this.diceRollButton=this.getSound("diceButton");this.diceRollSound=this.getSound("diceRoll");this.diceSelectSound=this.getSound("diceSelect");this.diceDismissSound=this.getSound("diceDismiss");this.diceShieldSound=this.getSound("diceShield");this.mapSounds={};var b=config.mapSounds;var c=0;for(a=
b.length;c<a;c++){var d=b[c];d=d.soundName;this.mapSounds[d]=this.getSound(d)}n.isTCE()&&this.getSound("titleMusic",!0);n.isIO()||this.getSound("clubMusic",!0);n.isIO()||this.getSound("celebrationMusic",!0);if(window.isClient){b="thm_cave_1 thm_cave_2 thm_harbor_1 thm_mission_1 thm_mission_2 thm_nature_1 thm_nature_2 thm_nature_mystic_1 thm_nature_mystic_2 thm_nature_night_campfire thm_nature_night_campfire_dark_2 thm_pyramid thm_shrine_1 thm_shrine_2 thm_temple_1 thm_utility_1 thm_utility_2 thm_village_1 thm_village_2 thm_village_3".split(" ");
c=[];var e=0;for(a=b.length;e<a;e++)d=b[e],c.push(this.getSound(d,!0));return c}};ab.prototype.setMusicVolume=function(a){var b;this.musicVolume=J.clamp(a,0,1);var c=this.musicGroup;var d=0;for(b=c.length;d<b;d++){var e=c[d];e.baseVolume=a;e.setVolume(e.volume)}if(null!=window.localStorage)return window.localStorage.setItem("musicVolume",a)};ab.prototype.setSoundVolume=function(a){var b;this.soundVolume=J.clamp(a,0,1);var c=this.soundGroup;var d=0;for(b=c.length;d<b;d++){var e=c[d];e.baseVolume=a;
e.setVolume(e.volume)}if(null!=window.localStorage)return window.localStorage.setItem("soundVolume",a)};ab.prototype.play=function(a,b){b=void 0===b?!1:b;if(null!=a){Object.isString(a)&&(logs.sound&&r.info("play "+a),a=this.getSound(a,b));if(null!=a)try{a.play(),a.setVolume(100),b&&a.loop()}catch(c){b=c,this.soundWarningFired||(this.soundWarningFired=!0,r.warn(b))}else logs.sound&&r.info(a+" not found");return a}};ab.prototype.fadeIn=function(a,b,c){c=void 0===c?!1:c;if(null!=a)return a=this.play(a),
c?a.loop().fadeIn(b):a.fadeIn(b)};ab.prototype.fadeOut=function(a,b){b=void 0===b?1E3:b;if(null!=a)return Object.isString(a)&&(logs.sound&&r.info("fade-out "+a),a=this.findSound(a)),null!=a&&a.isPlaying()&&a.loop(!1).fadeOut(b,function(){return a.stop()}),this};ab.prototype.stopAll=function(){var a;var b=this.sounds;for(a in b){var c=b[a];c.stop()}};ab.prototype.findSound=function(a){null!=config.sounds[a]&&(a=config.sounds[a]);return null==a?null:this.sounds[a]};ab.prototype.getSound=function(a,
b){b=void 0===b?!1:b;null!=config.sounds[a]&&(a=config.sounds[a]);if(null==a)return null;var c=this.sounds[a];if(null!=c)return c;c="sfx/"+a;c.includes("mods")&&(c=""+a);c=new Oc(c+this.audioFormat,this.audioContext,b?this.musicVolume:this.soundVolume);c.name=a;b?this.musicGroup.push(c):this.soundGroup.push(c);return this.sounds[a]=c};var Pc=function(a,b,c,d){c=void 0===c?!1:c;d=void 0===d?{}:d;this.x=a;this.y=b;this.isTouch=c;this.isMouse=!c;Object.merge(this,d);null==this.ctrlKey&&(this.ctrlKey=
!1);null==this.metaKey&&(this.metaKey=!1)};var Pa=function(a){var b=this;this.addEventListener=this.addEventListener.bind(this);this.onTouchStart=this.onTouchStart.bind(this);this.onTouchMove=this.onTouchMove.bind(this);this.onTouchEnd=this.onTouchEnd.bind(this);this.onMouseOut=this.onMouseOut.bind(this);this.keyDown=this.keyDown.bind(this);this.keyPress=this.keyPress.bind(this);this.onKeyPressGame=this.onKeyPressGame.bind(this);this.onKeyPressDebug=this.onKeyPressDebug.bind(this);this.onMouseDown=
this.onMouseDown.bind(this);this.onMouseUp=this.onMouseUp.bind(this);this.onContextMenu=this.onContextMenu.bind(this);this.onMouseMove=this.onMouseMove.bind(this);this.main=a;this.cam=this.main.r.cam;this.addEventListener("mousemove",this.onMouseMove);this.addEventListener("mousedown",this.onMouseDown);this.addEventListener("mouseup",this.onMouseUp);this.addEventListener("mouseout",this.onMouseOut);this.addEventListener("contextmenu",this.onContextMenu);this.addEventListener("touchstart",this.onTouchStart);
this.addEventListener("touchmove",this.onTouchMove);this.addEventListener("touchend",this.onTouchEnd);$(document).keypress(function(a){return b.main.wrapSafe(function(){return b.keyPress(a)})});$(document).keydown(function(a){return b.main.wrapSafe(function(){return b.keyDown(a)})});window.getDstCanvas().focus()};Pa.prototype.addEventListener=function(a,b){var c=this;return window.getDstCanvas().addEventListener(a,function(a){return c.main.wrapSafe(function(){return b(a)})},!1)};Pa.prototype.onTouchStart=
function(a){return this.onMouseDown(a)};Pa.prototype.onTouchMove=function(a){return this.onMouseMove(a)};Pa.prototype.onTouchEnd=function(a){return this.onMouseUp(a)};Pa.prototype.onMouseOut=function(a){this.main.infoBox.hide();return this.cam.onScrollMouseUp()};Pa.prototype.keyDown=function(a){var b,c,d;if(!this.main.waitingForDemoStart&&!this.main.displayingExplorerWheel){if(null!=(b=this.main.exped)&&null!=(c=b.comboEntity)&&c.active)return this.main.exped.comboEntity.onKeyDown(a);if(this.main.mainMenu.isActive&&
debug.showDebugBar&&this.main.mainMenu.TestGameHit)return this.main.mainMenu.onKeyDown(a);if(38===a.which)return this.cam.addHardScroll(0,config.scrollSpeed);if(39===a.which)return this.cam.addHardScroll(-config.scrollSpeed,0);if(40===a.which)return this.cam.addHardScroll(0,-config.scrollSpeed);if(37===a.which)return this.cam.addHardScroll(config.scrollSpeed,0);if(27===a.which){if("mainMenu"===(d=this.main.getMainState())||"gallery"===d||"worldMap"===d||"harbor"===d||"game"===d||"highscore"===d)return!n.isIO()||
null!=this.main.tutorial||this.main.events.showingEventDialogue||this.main.gameOver?this.main.showSettings(!0):this.main.setMainState("ionewgame");if("settings"===this.main.getMainState())return this.main.showSettings(!1);if("ionewgame"===this.main.getMainState()&&1<this.main.mainStates.length)return this.main.popMainState()}else if(debug.enableDebugKeys&&!this.main.mainMenu.isActive){if(a.shiftKey)return this.main.r.setPureMode(!this.main.r.pureMode);if(81===a.which&&(this.main.r.setViewAllMode(!debug.drawAllTiles),
null!=this.main.worldGenIO))return this.main.worldGenIO.claimCtxDirty=!0}}};Pa.prototype.keyPress=function(a){var b,c;if(0!==this.main.mainStates.length&&(null==(b=this.main.exped)||null==(c=b.comboEntity)||!c.wasHit)){if(null!=(b=this.main.getMainStateObj()))b.onKeyPress(a);if(null!=(b=this.main.modding))b.onKeyPress(a);if("game"===this.main.getMainState())this.onKeyPressGame(a);a.stopPropagation();return a.preventDefault()}};Pa.prototype.onKeyPressGame=function(a){var b,c,d;if(!this.main.waitingForDemoStart&&
!this.main.displayingExplorerWheel){if(this.main.gameOver)32===a.which&&this.main.endGame();else if(this.main.showingOutro)32===a.which&&(this.main.outroTime+=100);else if(!this.main.barter.onKeyPress(a))if(this.main.showingChallenge)32===a.which&&this.main.challenge.isPartyRound&&(0<this.main.challenge.rollsLeft?this.main.challenge.doPartyRoll():this.main.challenge.doEndPartyRound());else if(this.main.events.showingEventDialogue){var e=this.main.events.eventActions.isEmpty();32===a.which?this.main.diary.entryTime+=
100:49===a.which&&e&&this.main.hideEventDialogue();32===a.which||e||(b=!0)}else if(null!=this.main.exped)if(this.main.exped.shipArrived)if(this.main.showingEventAlert)32===a.which&&this.main.hideEventAlert();else if(99===a.which)this.cam.moveToPos(this.main.party.pos);else if(32===a.which)this.main.diary.doAction(0);else if(43===a.which)this.main.exped.zoomIn();else if(45===a.which)this.main.exped.zoomOut();else if(debug.enableDebugKeys)this.onKeyPressDebug(a);else b=!0;else 32===a.which?this.main.exped.shipSpeed=
5:43===a.which?this.main.exped.zoomIn():45===a.which&&this.main.exped.zoomOut();if(b){e=this.main.getActions(this.main.world.getTile(this.main.party.pos));var f=[];b=d=0;for(c=e.length;d<c;b=++d){var g=e[b];g.canDo&&((g=(b+1).toString().charCodeAt(0)===a.which)?this.main.events.showingEventDialogue?f.push(this.main.diary.doAction(b)):f.push(this.main.doAction(b)):f.push(void 0))}return f}}};Pa.prototype.onKeyPressDebug=function(a){if(98===a.which)return this.main.toggleShowBiomes();if(114===a.which){if(this.main.showingBiomes)return this.main.r.showPerlin=
!this.main.r.showPerlin;if(n.isIO()&&!this.main.isWarping()){var b=this.main.world.toBiomePos(this.main.party.pos);a=this.main.worldGenIO.getBiomeDict(b);a.biomeSeed+=1;this.main.world.getBiome(b).generated=!1;return this.main.worldGenIO.generateBiome(b)}if(null!=this.main.worldGen)return debug.testBiome&&(this.main.mouseBiome.id=debug.testBiome),this.main.worldGen.buildPerlin(this.main.mouseBiome)}else if(101===a.which){if(null!=this.main.worldGen){this.main.worldGen.buildRandLocations(this.main.world);
var c=this.main.world.getBiomes();var d=[];var e=0;for(b=c.length;e<b;e++)a=c[e],d.push(a.ctxDirty=!0);return d}switch(this.main.r.showDebugBiomes){case "difficulty":return this.main.r.showDebugBiomes="biomes";case "pockets":return this.main.r.showDebugBiomes="difficulty";default:return this.main.r.showDebugBiomes="pockets"}}else if(115===a.which)switch(this.main.r.showDebugData){case "locationCategory":return this.main.r.showDebugData="locations";case "locations":return this.main.r.showDebugData=
"biomes";default:return this.main.r.showDebugData="locationCategory"}else if(97===a.which)switch(this.main.r.showDebugDataType){case "percent":return this.main.r.showDebugDataType="avg";default:return this.main.r.showDebugDataType="percent"}else{if(119===a.which)return debug.skipStartEvents=!0,this.main.debugRegenWorld();if(116===a.which)return this.main.doRandEvent(t.getEvent("evt-debug-teleport")),this.main.updateActions();if(117===a.which){if(b=new u(this.main.r.ctx.canvas.width/2,this.main.r.ctx.canvas.height/
2),a=t.getParticle(debug.testParticle,!1),null==a&&(a=config.particle[debug.testParticle]),null!=debug.testParticleText&&(a.text=debug.testParticleText),null!=a)return a=Object.clone(a),a.isAbsolute=!0,this.main.r.part.addParticleConf(a,b)}else{if(111===a.which)return this.main.showExpeditionOver(!1,"You pressed O","debug-end");if(105===a.which)return null!=(b=this.main.tutorial)?b.incStep():void 0;if(112===a.which){if(!n.isIO())return this.main.endWorld()}else{if(106===a.which)return this.main.taxonomy.addRandButterfly();
if(120===a.which)return this.main.setTrailerMode(!this.main.r.trailerMode);if(109===a.which)return this.main.party.changeMapScore(10);if(110===a.which)return config.board.showBorders=!config.board.showBorders,this.main.r.biomesDirty=!0;if(107===a.which)return this.main.party.changeSanity(-30);if(100===a.which)return this.main.mainMenu.showDebugBar(!debug.showDebugBar)}}}};Pa.prototype.onMouseDown=function(a){var b;a=this.main.r.mouseToInputEvent(a);this.main.mousePressed=!0;if(!this.main.waitingForDemoStart&&
!this.main.displayingExplorerWheel)switch(window.getDstCanvas().focus(),this.main.getMainState()){case "game":case "harbor":if(this.main.invBar.onMouseDown(a,this.main.showTrash))break;return null!=(b=this.main.exped)?b.onMouseDown(a):void 0;case "modding":return this.main.modding.onMouseDown(a);case "credits":return this.main.credits.onMouseDown(a)}};Pa.prototype.onMouseUp=function(a){var b;if(a.metaKey)this.onContextMenu(a);else if(a=this.main.r.mouseToInputEvent(a),this.cam.onScrollMouseUp(),2!==
a.button){this.main.mousePressed=!1;if(null!=(b=this.main.getMainStateObj()))b.onMouseClick(a);if(!this.main.waitingForDemoStart&&!this.main.displayingExplorerWheel)switch(this.main.getMainState()){case "harbor":this.onMouseClickDiary(a);break;case "game":if(null!=this.main.exped)this.main.exped.onMouseUp(a);break;case "credits":this.main.credits.onMouseUp(a)}}};Pa.prototype.onMouseClickDiary=function(a){this.main.diaryPersonPinned=null;if(this.main.showingBarter)return this.main.barter.onMouseClick(a),
!0;if(this.main.invBar.inInventory(a.x,a.y))return!0;if(this.main.events.showingEventDialogue){var b=this.main.drawDiary(a.x,a.y);null!=b?this.main.diary.doAction(b):a.x<250*this.main.r.s&&(this.main.diary.entryTime+=100);return!0}};Pa.prototype.onContextMenu=function(a){a=this.main.r.mouseToInputEvent(a);switch(this.main.getMainState()){case "harbor":if(this.main.showingBarter&&this.main.barter.onMouseClick(a))return;break;case "game":if(null==this.main.exped)return;if(this.main.exped.showingPunch){this.main.exped.punchCancelable&&
this.main.exped.doPunch(null,!0);return}this.main.events.showingEventDialogue||this.main.exped.clearWayPoints();if(this.main.showingBarter&&this.main.barter.onMouseClick(a))return;break;case "mainMenu":this.main.mainMenu.onContextMenu(a)}if(n.isIO()&&debug.runOffline){var b=$jscomp.makeIterator(this.main.r.getCanvasSize());var c=b.next().value;b=b.next().value;if(a.x>=c-10&&a.y>=b-10){for(;0<this.main.mainStates.length;)this.main.popMainState();this.main.mainMenu.hasEverStartedGame=!1;this.main.initNewIOGame();
return this.main.ioInv.resetInventory()}}};Pa.prototype.onMouseMove=function(a){var b;a=this.main.r.mouseToInputEvent(a);this.main.infoBox.hide();this.main.mousePos=new u(a.x,a.y);this.main.mouseItem=null;if(!this.main.waitingForDemoStart&&!this.main.displayingExplorerWheel){null!=this.main.exped&&(this.main.exped.showTileInfo=null,this.main.exped.mouseTilePos=null);if(!this.cam.mouseScrolling&&("game"===(b=this.main.getMainState())||"harbor"===b)){if(this.main.showingBarter){this.main.barter.onMouseMove(a.x,
a.y);return}if(!this.main.showingOutro&&(this.main.mouseItem=this.main.invBar.onMouseMove(a.x,a.y,this.main.barter.priceTable),null!=this.main.mouseItem||this.main.invBar.inInventory(a.x,a.y)))return}if("game"===this.main.getMainState())return this.main.exped.onMouseMove(a)}};var Ca=function(a,b){this.getCamDetails=this.getCamDetails.bind(this);this.checkScrollMargins=this.checkScrollMargins.bind(this);this.onScrollMove=this.onScrollMove.bind(this);this.doScroll=this.doScroll.bind(this);this.onScrollMouseDown=
this.onScrollMouseDown.bind(this);this.onScrollMouseUp=this.onScrollMouseUp.bind(this);this.addCamShake=this.addCamShake.bind(this);this.tickCamShakes=this.tickCamShakes.bind(this);this.main=a;this.r=b;this.scroll=new qa(0,0);this.camShakes=[];this.shakeY=this.shakeX=0;this.fastScrollTime=100;this.mouseScrolling=this.mousePressed=!1;this.scrollHD=new qa(0,0);this.resetScroll()};Ca.prototype.getCamDetails=function(){var a=["screenCenterPos: "+this.screenCenterPos.toString(),"ScrollHD: "+this.scrollHD.toString(),
"Scroll: "+this.scroll.toString()];null!=this.targetPos&&a.push("targetPos: "+this.targetPos.toString());return a};Ca.prototype.resetScroll=function(){this.autoScroll=new u(0,0);this.hardScroll=new qa(0,0);this.scrollMomentum=this.targetPos=null;return this.updateScreenCenterPos()};Ca.prototype.updateScreenCenterPos=function(){var a=$jscomp.makeIterator(this.r.getCanvasSize());var b=a.next().value;a=a.next().value;return this.screenCenterPos=this.mouseToTilePos(b/2,a/2)};Ca.prototype.centerOnPos=
function(a){var b=$jscomp.makeIterator(this.r.getCanvasSize());var c=b.next().value;b=b.next().value;var d=this.r.getTileScreenPos(a,!1,!1,!0);this.scrollHD.x=-d.x+c/2;this.scrollHD.y=-d.y+b/2;this.scroll.x=Math.round(this.scrollHD.x);this.scroll.y=Math.round(this.scrollHD.y);this.r.biomeBorderDirty=!0;return this.screenCenterPos=a};Ca.prototype.moveToPos=function(a){this.targetPos=a;return this.fastScrollTime=0};Ca.prototype.mouseToTilePos=function(a,b){a-=this.scroll.x-this.r.mapOffset.w;b-=this.scroll.y-
this.r.mapOffset.h;a=Math.floor(a/(this.r.biomeScreenSize.w-this.r.biomeScreenOffset.w));b=Math.floor((b-this.r.hexOffset(a))/this.r.biomeScreenSize.h);return new u(a,b)};Ca.prototype.tickScrolling=function(a,b){this.fastScrollTime+=a;this.mousePressed&&this.resetScroll();var c=1>this.fastScrollTime?3*a:.5*a;if(null!=this.targetPos){this.updateScreenCenterPos();var d=this.r.getTileScreenPos(this.screenCenterPos,!0,!0,!0);var e=this.r.getTileScreenPos(this.targetPos,!0,!0,!0);c=d=e.diff(d).mul(c);
1>d.length()&&this.resetScroll()}else c=this.autoScroll.mul(c),this.autoScroll=this.autoScroll.sub(c);this.scrollHD=this.scrollHD.add(c);d=$jscomp.makeIterator([this.r.biomeScreenSize.w-this.r.biomeScreenOffset.w,this.r.biomeScreenSize.h-this.r.biomeScreenOffset.h]);c=d.next().value;d=d.next().value;d=$jscomp.makeIterator([c*config.board.biomeSize[0],d*config.board.biomeSize[1]]);c=d.next().value;d=d.next().value;b=$jscomp.makeIterator([c*b.w,d*b.h]);b.next();b.next();b=$jscomp.makeIterator(this.r.getCanvasSize());
b.next();b.next();this.r.trailerMode&&(this.scrollHD.x+=config.trailerScrollSpeed[0]*a,this.scrollHD.y+=config.trailerScrollSpeed[1]*a);this.scrollHD.x+=this.hardScroll.x*a;this.scrollHD.y+=this.hardScroll.y*a;this.hardScroll.zero();a=Math.round(this.scrollHD.x);this.scroll.x!==a&&(this.scroll.x=a,this.biomeBorderDirty=!0);a=Math.round(this.scrollHD.y);this.scroll.y!==a&&(this.scroll.y=a,this.biomeBorderDirty=!0);null!=this.oldScrollHD&&(this.scrollMomentum=this.oldScrollHD.sub(this.scrollHD));this.updateScreenCenterPos();
this.checkScrollMargins();return this.oldScrollHD=this.scrollHD.clone()};Ca.prototype.checkScrollMargins=function(){if(null!=this.main.world){var a=$jscomp.makeIterator(this.r.getCanvasSize());var b=a.next().value;var c=a.next().value;a=new u(0,0);a=this.r.getTileScreenPos(a,!1,!1,!0);a=new u(-a.x+b/2,-a.y+c/2);var d=new u(this.main.world.biomeCount.w*config.board.biomeSize[0]-1,this.main.world.biomeCount.h*config.board.biomeSize[1]-1);d=this.r.getTileScreenPos(d,!1,!1,!0);var e=new u(-d.x+b/2,-d.y+
c/2);c=Math.min(a.x,e.x);b=Math.max(a.x,e.x);d=Math.min(a.y,e.y);a=Math.max(a.y,e.y);a=new u(this.scrollHD.x.clamp(c,b),this.scrollHD.y.clamp(d,a));if(!a.eq(this.scrollHD))return this.scrollHD=a,this.scroll.x=Math.round(this.scrollHD.x),this.scroll.y=Math.round(this.scrollHD.y),this.resetScroll()}};Ca.prototype.addHardScroll=function(a,b){return this.hardScroll=new qa(a,b)};Ca.prototype.addAutoScroll=function(a){return this.autoScroll=this.autoScroll.add(a)};Ca.prototype.onScrollMove=function(a,b){if(this.mousePressed){var c=
a-this.mouseDownStart[0];var d=b-this.mouseDownStart[1];if(this.mouseScrolling||!(15>Math.abs(c)+Math.abs(d)))if(0!==c||0!==d)return this.mouseDownStart[0]=a,this.mouseDownStart[1]=b,this.mouseScrolling=!0,this.doScroll(c,d)}};Ca.prototype.doScroll=function(a,b){this.scrollHD.x+=a;this.scrollHD.y+=b;this.autoScroll=new u(0,0);this.targetPos=null;this.r.enableMouseMoveCursor(!0);return this.lastMouseWheelTime=this.timeTotal};Ca.prototype.onScrollMouseDown=function(a){this.mousePressed=!0;return this.mouseDownStart=
[a.x,a.y]};Ca.prototype.onScrollMouseUp=function(a){this.mousePressed=!1;null!=this.scrollMomentum&&(this.addAutoScroll(this.scrollMomentum.mul(-30)),this.scrollMomentum=null);this.mouseScrolling=!1;return this.r.enableMouseMoveCursor(!1)};Ca.prototype.getCamCenter=function(){var a=$jscomp.makeIterator(this.r.getCanvasSize());var b=a.next().value;a=a.next().value;return(new u(b/2,a/2)).sub(this.scroll)};Ca.prototype.addCamShake=function(a,b,c){if(!(this.camShakes.length>config.maxCamShakes))return this.camShakes.push({camX:0,
camY:0,power:a,length:b,time:0,center:c})};Ca.prototype.tickCamShakes=function(a){var b,c;var d=b=0;var e=this.camShakes;var f=0;for(c=e.length;f<c;f++){var g=e[f];g.time+=a;.1<g.time&&(g.camX=Math.round((2*Math.random()-1)*g.power),g.camY=Math.round((2*Math.random()-1)*g.power),g.length-=.1,g.time=0);if(null==g.center||g.center.dist(this.getCamCenter())<config.maxCamShakeDist)b+=g.camX,d+=g.camY}this.camShakes.remove(function(a){return 0>=a.length});this.shakeX=b;return this.shakeY=d};var z=function(a,
b,c){this.introAlpha=this.introAlpha.bind(this);this.hudAlpha=this.hudAlpha.bind(this);this.drawDebugHubs=this.drawDebugHubs.bind(this);this.drawPreviewTriangles=this.drawPreviewTriangles.bind(this);this.drawMapLines=this.drawMapLines.bind(this);this.createMiniMap=this.createMiniMap.bind(this);this.drawMiniMap=this.drawMiniMap.bind(this);this.drawIOMap=this.drawIOMap.bind(this);this.drawLocationSprite=this.drawLocationSprite.bind(this);this.drawNewSegmentBanner=this.drawNewSegmentBanner.bind(this);
this.drawMapRuler=this.drawMapRuler.bind(this);this.updateTileReveal=this.updateTileReveal.bind(this);this.drawSegmentBorders=this.drawSegmentBorders.bind(this);this.drawTileOutline=this.drawTileOutline.bind(this);this.drawTileOutlineShadow=this.drawTileOutlineShadow.bind(this);this.drawTileBackground=this.drawTileBackground.bind(this);this.drawTileZoneIcon=this.drawTileZoneIcon.bind(this);this.drawTileStampPreview=this.drawTileStampPreview.bind(this);this.drawTileZoneName=this.drawTileZoneName.bind(this);
this.drawTileTotalViewCost=this.drawTileTotalViewCost.bind(this);this.drawTileHints=this.drawTileHints.bind(this);this.drawPunch=this.drawPunch.bind(this);this.drawPathFinderDebug=this.drawPathFinderDebug.bind(this);this.drawItem=this.drawItem.bind(this);this.mouseToItemSlot=this.mouseToItemSlot.bind(this);this.charPortraitPos=this.charPortraitPos.bind(this);this.mouseToPortrait=this.mouseToPortrait.bind(this);this.drawMiniParty=this.drawMiniParty.bind(this);this.hasCachedHexFieldRadius=this.hasCachedHexFieldRadius.bind(this);
this.drawHexFieldRadius=this.drawHexFieldRadius.bind(this);this.drawHexFieldHighlight=this.drawHexFieldHighlight.bind(this);this.drawExtraButtons=this.drawExtraButtons.bind(this);this.markActionHighlight=this.markActionHighlight.bind(this);this.drawActionButtons=this.drawActionButtons.bind(this);this.drawPartyPath=this.drawPartyPath.bind(this);this.drawPathCost=this.drawPathCost.bind(this);this.resetZoom=this.resetZoom.bind(this);this.zoomIn=this.zoomIn.bind(this);this.zoomOut=this.zoomOut.bind(this);
this.mouseToTilePos_float=this.mouseToTilePos_float.bind(this);this.adjustZoomTarget=this.adjustZoomTarget.bind(this);this.adjustZoom=this.adjustZoom.bind(this);this.tickZoom=this.tickZoom.bind(this);this.updateBlockSize=this.updateBlockSize.bind(this);this.enableMouseMoveCursor=this.enableMouseMoveCursor.bind(this);this.drawHexOutline=this.drawHexOutline.bind(this);this.moveHexLine=this.moveHexLine.bind(this);this.drawPortrait=this.drawPortrait.bind(this);this.drawWrappedText=this.drawWrappedText.bind(this);
this.drawText=this.drawText.bind(this);this.drawBitmapText=this.drawBitmapText.bind(this);this.drawActionPanel=this.drawActionPanel.bind(this);this.drawChatPanel=this.drawChatPanel.bind(this);this.drawPanel=this.drawPanel.bind(this);this.drawTutorialArrow=this.drawTutorialArrow.bind(this);this.drawLeftSidebar=this.drawLeftSidebar.bind(this);this.drawRaceBar=this.drawRaceBar.bind(this);this.drawRaceTrackIO=this.drawRaceTrackIO.bind(this);this.drawIOFame=this.drawIOFame.bind(this);this.drawIOCalendar=
this.drawIOCalendar.bind(this);this.drawCalendar=this.drawCalendar.bind(this);this.drawSanity=this.drawSanity.bind(this);this.drawStanding=this.drawStanding.bind(this);this.drawXP=this.drawXP.bind(this);this.drawGoalBadge=this.drawGoalBadge.bind(this);this.drawRegionInfo=this.drawRegionInfo.bind(this);this.hitBox=this.hitBox.bind(this);this.drawAchievement=this.drawAchievement.bind(this);this.drawUnlockedChar=this.drawUnlockedChar.bind(this);this.drawGivenPack=this.drawGivenPack.bind(this);this.drawGivenMedals=
this.drawGivenMedals.bind(this);this.drawGivenAlphaKey=this.drawGivenAlphaKey.bind(this);this.drawButton=this.drawButton.bind(this);this.drawWarningBar=this.drawWarningBar.bind(this);this.drawLetterboxMattes=this.drawLetterboxMattes.bind(this);this.drawOutroPacks=this.drawOutroPacks.bind(this);this.drawOutro=this.drawOutro.bind(this);this.drawStats=this.drawStats.bind(this);this.drawInfoBox=this.drawInfoBox.bind(this);this.drawHintBox=this.drawHintBox.bind(this);this.drawCharacterInfo=this.drawCharacterInfo.bind(this);
this.drawCharacterInfoButton=this.drawCharacterInfoButton.bind(this);this.drawCharacterInfoStatusesShort=this.drawCharacterInfoStatusesShort.bind(this);this.drawStatusIcon=this.drawStatusIcon.bind(this);this.drawCharacterInfoStatuses=this.drawCharacterInfoStatuses.bind(this);this.drawStatusInfo=this.drawStatusInfo.bind(this);this.drawBuffInfo=this.drawBuffInfo.bind(this);this.resetClouds=this.resetClouds.bind(this);this.addRandCloud=this.addRandCloud.bind(this);this.drawMapCloud=this.drawMapCloud.bind(this);
this.drawCloudIntro=this.drawCloudIntro.bind(this);this.onStartWorld=this.onStartWorld.bind(this);this.drawFrame=this.drawFrame.bind(this);this.drawBackground=this.drawBackground.bind(this);this.drawLibraryBackground=this.drawLibraryBackground.bind(this);this.drawFameFunds=this.drawFameFunds.bind(this);this.setImageSmoothing=this.setImageSmoothing.bind(this);this.splitText=this.splitText.bind(this);this.drawSprite=this.drawSprite.bind(this);this.drawHealthBar=this.drawHealthBar.bind(this);this.drawHearts=
this.drawHearts.bind(this);this.drawCharacter=this.drawCharacter.bind(this);this.getDebugFont=this.getDebugFont.bind(this);this.getDebugWatchFont=this.getDebugWatchFont.bind(this);this.drawDebugWatches=this.drawDebugWatches.bind(this);this.drawParticles=this.drawParticles.bind(this);this.drawDebugButton=this.drawDebugButton.bind(this);this.drawCheckbox=this.drawCheckbox.bind(this);this.drawImageCheckbox=this.drawImageCheckbox.bind(this);this.main=a;this.ctx=b;this.sfx=c;this.oY=0;this.blockOffset=
new R(config.imgSize.hexOffset);this.blockSize=new R(config.imgSize.blockSize);this.mapOffset=new R(config.imgSize.mapOffset);this.biomeScreenSize=new R(config.imgSize.blockSize);this.biomeScreenOffset=new R(config.imgSize.hexOffset);this.s=2;this.cam=new Ca(this.main,this);this.part=new qb(this,c);this.zoomTarget=this.zoomLevel=0;this.playerColor="#2BBFBD";this.enemyColor="#F22E2E";this.biomesDirty=!1;this.animatedFades=[];this.tileHighlights=[];this.timeDeltas=[];this.outroSoundTime=0;this.sanityBar=
new Qc(config.colors.sanity,"purple");this.porterIconMargin=this.partyOffset=0;this.biomeBorderDirty=this.trailerMode=this.pureMode=!1;this.setImageSmoothing(!1);this.setRandBalloonX();this.introTime=this.hudIntroTime=this.timeTotal=0;this.backgroundImages={};this.debugWatches=[];this.setupStarCanvas()};z.prototype.setupStarCanvas=function(){this.starCtx=this.createCanvas(370,350);var a;var b=[];for(a=0;300>a;++a){var c=Number.random(30);var d=Number.random(this.starCtx.canvas.height);var e=Number.random(5,
30);b.push({pos:new u(c,d),speed:e,color:"rgba(255,255,255,"+J.lerp(.2,1,e-5,25)})}return this.stars=b};z.prototype.tickStars=function(a){var b;var c=this.starCtx.canvas.width;var d=this.starCtx.canvas.height;var e=this.stars;var f=0;for(b=e.length;f<b;f++){var g=e[f];g.pos.x+=a*g.speed;g.pos.x>c&&(g.pos.x=Number.random(100),g.pos.y=Number.random(d))}};z.prototype.drawStarCanvas=function(){var a;this.starCtx.globalAlpha=1;this.starCtx.fillStyle="#09001C";this.starCtx.fillRect(0,0,this.starCtx.canvas.width,
this.starCtx.canvas.height);var b=this.stars;var c=0;for(a=b.length;c<a;c++){var d=b[c];this.starCtx.fillStyle=d.color;this.starCtx.fillRect(d.pos.x,d.pos.y,1,1)}};z.prototype.getCanvasSize=function(){return null!=this.ctx?[this.ctx.canvas.width,this.ctx.canvas.height]:[0,0]};z.prototype.mouseToInputEvent=function(a){var b;a.stopPropagation();a.preventDefault();if(0<(null!=(b=a.touches)?b.length:void 0)){var c=$jscomp.makeIterator([a.touches[0].clientX,a.touches[0].clientY]);var d=c.next().value;
b=c.next().value;c=!0}else b=$jscomp.makeIterator([null!=(d=a.offsetX)?d:a.pageX,null!=(c=a.offsetY)?c:a.pageY]),d=b.next().value,b=b.next().value,c=!1;d=Math.floor(d/this.frameRatio.w);b=Math.floor(b/this.frameRatio.h);return new Pc(d,b,c,{ctrlKey:a.ctrlKey,metaKey:a.metaKey,button:a.button})};z.prototype.layout=function(a,b){var c=$jscomp.makeIterator([Math.max(this.ctx.canvas.width,550*this.s),this.ctx.canvas.height]);var d=c.next().value;c=c.next().value;d=a.has("left")?0:a.has("center")?d/2-
b.w/2:a.has("right")?d-b.w:void 0;a=a.has("top")?0:a.has("middle")?c/2-b.h/2:a.has("bottom")?c-b.h:void 0;return new R(d,a)};z.prototype.setPureMode=function(a){this.pureMode=a;return this.biomesDirty=!0};z.prototype.setViewAllMode=function(a){debug.drawAllLocations=a;debug.drawAllTiles=a;return this.biomesDirty=!0};z.prototype.introAlpha=function(){return 10<this.introTime?1:TWEEN.Easing.Back.Out((.8*(this.introTime-3)).clamp(0,1))};z.prototype.hudAlpha=function(){return 10<this.hudIntroTime?0:1-
TWEEN.Easing.Cubic.Out((1*this.hudIntroTime-.5).clamp(0,1))};z.prototype.getFPS=function(){return 1/this.timeDeltas.average()};z.prototype.tick=function(a){this.timeDelta=a;this.timeDeltas.unshift(a);30<this.timeDeltas.length&&this.timeDeltas.pop();this.timeTotal+=a;if("settings"!==this.main.getMainState())return this.sanityBar.tick(a),this.part.tickParticles(a),this.cam.tickCamShakes(a),n.isMac()&&.1<this.timeTotal&&this.enableMouseMoveCursor(!1),this.tickZoom(a)};z.prototype.clear=function(a,b){a=
void 0===a?!1:a;b=void 0===b?"#222":b;var c=$jscomp.makeIterator(this.getCanvasSize());var d=c.next().value;c=c.next().value;return a?(this.ctx.fillStyle=b,this.ctx.globalAlpha=1,this.ctx.fillRect(0,0,d,c)):this.ctx.clearRect(0,0,d,c)};z.prototype.drawDebugHubs=function(){var a;var b=this.img.getSprite("hud_io_playerPos_zoomMap.png");this.ctx.globalAlpha=1;var c=this.main.worldGenIO.hubBiomes;var d=[];var e=0;for(a=c.length;e<a;e++){var f=c[e];f=this.main.worldGenIO.biomes[f];var g=f.pos;var h=this.main.worldGenIO.world.getBiome(g,
!1);var k=null;if(null!=h&&h.generated){var l=h.locations;var m=0;for(h=l.length;m<h;m++){var p=l[m];if(p.id===config.io.hubLocationID){k=p.pos;break}}}null==k&&(k=new u((g.x+.5)*config.board.biomeSize[0],(g.y+.5)*config.board.biomeSize[1]));g=this.getTileScreenPos(k,!0,!0,!0);this.drawSprite(b,g.x,g.y,{halign:"center",valign:"bottom"});d.push(this.drawText(f.worldLvl,g.x,g.y-b.dSize.h/2,{font:this.getDebugFont(),halign:"center",valign:"center"}))}return d};z.prototype.drawDebugBiomesIO=function(a,
b,c){var d=this,e,f,g,h,k,l,m,p,w,n,q,v,y,r,A,H,G,V,T,x,B,C,z,wb,Ec,xb,rb,F,J;this.ctx.globalAlpha=1;this.ctx.font=this.getDebugWatchFont();a.world.getBiomeCount();this.clear(!0,"black");var Za=3*this.s;var E=this.createCanvas(a.world.biomeCount.w*Za,a.world.biomeCount.h*Za);this.setImageSmoothing(!1,E);E.fillStyle="grey";E.globalAlpha=1;E.fillRect(0,0,E.canvas.width,E.canvas.height);var M=$jscomp.makeIterator(this.getCanvasSize());M.next();M.next();var L=E.canvas.width;var I=20*this.s;var N=40*this.s;
var K=L/a.world.biomeCount.w;var Q=new u(Math.floor((b-I)/K),Math.floor((c-N)/K));this.mouseBiomeDict=a.getBiomeDict(Q,!1);var R=xb=0;for(T=a.world.biomeCount.w;0<=T?xb<T:xb>T;R=0<=T?++xb:--xb){var P=J=0;for(C=a.world.biomeCount.h;0<=C?J<C:J>C;P=0<=C?++J:--J){var S=new u(R,P);var O=a.getBiomeDict(S);var U=!1;if("difficulty"===this.showDebugBiomes)if(U=null!=this.mouseBiomeDict&&null!=this.mouseBiomeDict.worldSegment&&O.worldSegment===this.mouseBiomeDict.worldSegment,this.showPerlin){var X=this.main.worldGenIO.difficultyMap[O.biomeIdx];
E.fillStyle="#000000".replace(/0/g,function(){return(~~(16*X)).toString(16)})}else{if(X=O.worldLvl,E.fillStyle=function(){switch(X){case 0:return"green";case 1:return"blue";case 2:return"cyan";case 3:return"purple";case 4:return"orange";default:return"red"}}(),E.globalAlpha=1,null!=O.worldSegment){var Z=a.worldSegmentList[O.worldSegment];Z.lowestBiome===O.biomeIdx&&(E.globalAlpha=.5)}}else if("pockets"===this.showDebugBiomes){U=null!=this.mouseBiomeDict&&null!=this.mouseBiomeDict.pckZone&&O.pckZone===
this.mouseBiomeDict.pckZone;var ba=t.getPocket(O.pocketID);E.fillStyle=this.showPerlin?"#000000".replace(/0/g,function(){return(~~(16*d.main.worldGenIO.perlinMap[O.biomeIdx])).toString(16)}):ba.debugColor}else{var ca=t.getBiome(O.biomeID);E.fillStyle=this.showPerlin?"#000000".replace(/0/g,function(){return(~~(16*d.main.worldGenIO.perlinMap[O.biomeIdx])).toString(16)}):ca.debugColor}U&&(E.fillStyle="yellow");O===this.mouseBiomeDict&&(E.fillStyle="white");var W=R*Za;var aa=P*Za;E.fillRect(W,aa,Za,Za);
if("difficulty"===this.showDebugBiomes){var fa=[new u(-1,0),new u(0,-1)];var ea=h=0;for(l=fa.length;h<l;ea=++h){var ia=fa[ea];var ka=S.add(ia);if(V=a.getBiomeDict(ka,!1)){if("difficulty"===this.showDebugBiomes){if(V.worldSegment===O.worldSegment)continue}else if(V.pocketID===O.pocketID)continue;E.strokeStyle="grey";E.lineWidth=1*this.s;E.beginPath();switch(ea){case 0:var ha=new u(W,aa);var ja=new u(W,aa+Za);break;case 1:ha=new u(W,aa),ja=new u(W+Za,aa)}E.moveTo(ha.x,ha.y);E.lineTo(ja.x,ja.y);E.stroke()}}}if(null!=
O.rivers){var la=function(a){var b=Math.floor(Za/2);switch(a){case "left":return new u(W,aa+b);case "right":return new u(W+Za,aa+b);case "top":return new u(W+b,aa);case "bottom":return new u(W+b,aa+Za);case "hub":return new u(W+b,aa+b)}};var na=O.rivers;var ma=0;for(p=na.length;ma<p;ma++){var pa=na[ma];ha=la(pa.from);ja=la(pa.to);E.strokeStyle="blue";E.lineWidth=1*this.s;E.beginPath();E.moveTo(ha.x,ha.y);E.lineTo(ja.x,ja.y);E.stroke()}}O.biomeID.includes("outside")}}this.ctx.drawImage(E.canvas,0,
0,E.canvas.width,E.canvas.height,I,N,L,L);I+=.5*K;N+=.5*K;var oa="difficulty"===this.showDebugBiomes?a.worldSegmentList:a.pckZoneList;if(null!=oa&&null!=this.mouseBiomeDict&&null!=this.mouseBiomeDict.worldSegment){var qa=oa[this.mouseBiomeDict.worldSegment];var ra=a.biomes[qa.lowestBiome];this.drawText(""+qa.id,I+ra.pos.x*K,N+ra.pos.y*K,{fillColor:"red",halign:"center",valign:"center",os:0});this.ctx.strokeStyle="black";var ua=null!=(wb=qa.adjZones)?wb:[];var sa=0;for(w=ua.length;sa<w;sa++){var za=
ua[sa];var ya=oa[za];var va=a.biomes[ya.lowestBiome];this.drawText(""+ya.id,I+va.pos.x*K,N+va.pos.y*K,{fillColor:"white",halign:"center",valign:"center",os:0});this.ctx.beginPath();this.ctx.moveTo(I+ra.pos.x*K,N+ra.pos.y*K);this.ctx.lineTo(I+va.pos.x*K,N+va.pos.y*K);this.ctx.stroke()}}var Ca=a.hubBiomes;var Aa=0;for(n=Ca.length;Aa<n;Aa++){var Ga=Ca[Aa];O=a.biomes[Ga];var Ia=a.difficultyLvls.indexOf(O.worldLvl);this.drawText(""+(Ia+1),I+O.pos.x*K,N+(O.pos.y+.5)*K,{fillColor:"white",halign:"center"})}if(null!=
a.goalBiomeID){O=a.biomes[a.goalBiomeID];var Ea=I+O.pos.x*K;var Fa=N+(O.pos.y+.5)*K;this.drawText("G",Ea,Fa,{fillColor:"orange",halign:"center"});var Ja=a.biomes[a.unlockedHubs[0]];var Pa=I+Ja.pos.x*K;var Ra=N+(Ja.pos.y+.5)*K;this.ctx.save();this.ctx.strokeStyle="black";this.ctx.beginPath();this.ctx.moveTo(Pa,Ra);this.ctx.lineTo(Ea,Fa);this.ctx.stroke();this.ctx.restore()}var Ma=a.biomes;for(ea in Ma)if(O=Ma[ea],null!=O.locations){var Na=O.locations;var La=0;for(q=Na.length;La<q;La++){var Ua=Na[La];
if(Ua.includes("goldenSeal")){this.drawText("S",I+O.pos.x*K,N+(O.pos.y+.5)*K,{fillColor:"yellow",halign:"center"});break}}}var Sa=this.main.world.toBiomePos(this.main.party.pos);null==this.youAreHereTime&&(this.youAreHereCol=this.youAreHereTime=0);this.youAreHereTime+=this.timeDelta;this.youAreHereTime>=config.io.youAreHereFlashTime&&(this.youAreHereTime-=config.io.youAreHereFlashTime,this.youAreHereCol=0===this.youAreHereCol?1:0);var Ha=0===this.youAreHereCol?config.io.youAreHereCol1:config.io.youAreHereCol2;
this.ctx.fillStyle=Ha;this.ctx.globalAlpha=.5;this.ctx.fillRect(Sa.x*K+I-K/2,Sa.y*K+N-K/2,K,K);this.ctx.globalAlpha=1;var Qa=null!=(Ec=this.showDebugBiomes)?Ec:"biomes";this.showPerlin&&(Qa+=" (perlin)");var Ka=I+L/2;this.drawText(Qa,Ka,20*this.s,{halign:"center",os:0});this.drawText("E: toggle view; R: toggle perlin; W: regenerate",Ka,30*this.s,{halign:"center",os:0});null!=Q&&this.main.infoBox.showBiome(Q,!0);this.ctx.font=this.getDebugWatchFont();I+=L+5*this.s;null==this.showDebugData&&(this.showDebugData=
"locationCategory");Qa=this.showDebugData;"pockets"===this.showDebugBiomes&&"biomes"===Qa&&(Qa=this.showDebugBiomes);Ka=I+L/2;this.drawText(Qa,Ka,20*this.s,{halign:"center",os:0});Qa="S: toggle view; ";null==(e=this.main.r).showDebugDataType&&(e.showDebugDataType="percent");Qa="percent"===this.main.r.showDebugDataType?Qa+"A: show averages":Qa+"A: show percent";this.drawText(Qa,Ka,30*this.s,{halign:"center",os:0});var xa={};var Da={id:"sum",total:0,diffs:[0,0,0,0,0,0]};var Oa=function(a,b){null==xa[a]&&
(xa[a]={},xa[a].id=a,xa[a].total=0,xa[a].diffs=[0,0,0,0,0,0]);xa[a].total+=1;xa[a].diffs[b]+=1;Da.total+=1;return Da.diffs[b]+=1};switch(this.showDebugData){case "locations":var Wa=a.biomes;for(k in Wa){var wa=Wa[k];var ta=wa.worldLvl;var Xa=wa.locations;var Va=0;for(v=Xa.length;Va<v;Va++){var Ba=Xa[Va];Oa(Ba,ta)}}break;case "locationCategory":var ab=a.biomes;for(k in ab){wa=ab[k];ta=wa.worldLvl;var bb=wa.locations;var $a=0;for(y=bb.length;$a<y;$a++){Ba=bb[$a];var gb=t.getLocation(Ba);var hb=null!=
(x=gb.debugCategory)?x:Ba;Oa(hb,ta)}}break;default:if("pockets"===this.showDebugBiomes){var cb=a.biomes;for(k in cb)wa=cb[k],Ba=wa.pocketID,ta=wa.worldLvl,Oa(Ba,ta)}else{var eb=a.biomes;for(k in eb)wa=eb[k],Ba=wa.biomeID,ta=wa.worldLvl,Oa(Ba,ta)}}var Ya=Object.values(xa);Ya.sort(function(a,b){return a.total>b.total?-1:a.total<b.total?1:0});var db={id:"biomes",total:0,diffs:[0,0,0,0,0,0]};var lb={id:"blockingBiomes",total:0,diffs:[0,0,0,0,0,0]};var jb=this.main.worldGenIO.biomes;for(Ba in jb){var Ta=
jb[Ba];Ta.isBorder?(null==(g=lb.diffs)[G=Ta.worldLvl]&&(g[G]=0),lb.diffs[Ta.worldLvl]+=1,lb.total+=1):(null==(f=db.diffs)[H=Ta.worldLvl]&&(f[H]=0),db.diffs[Ta.worldLvl]+=1,db.total+=1)}db.percent=(db.total/(db.total+lb.total)).toFixed(2)+"%";lb.percent=(lb.total/(db.total+lb.total)).toFixed(2)+"%";var fb=0;for(r=Ya.length;fb<r;fb++){var pb=Ya[fb];if("percent"===this.main.r.showDebugDataType)pb.percent=(pb.total/Da.total*100).toFixed(2)+"%";else{pb.percent=(pb.total/db.total).toFixed(2);var mb=pb.diffs;
ea=rb=0;for(A=mb.length;rb<A;ea=++rb){var nb=mb[ea];0<nb&&(pb.diffs[ea]=(null!=(B=nb/db.diffs[ea])?B:1).toFixed(2))}}}var ob="percent"===this.main.r.showDebugDataType?"%":"avg";P=N;Qa="id".padEnd(35," ")+"total".padEnd(6," ")+ob.padEnd(10," ");ta=F=1;for(z=a.difficultyLvls.length;1<=z?F<=z:F>=z;ta=1<=z?++F:--F)Qa+=ta.toString().padEnd(6," ");this.drawText(Qa,I,P,{halign:"left"});P+=10*this.s;Ha=!0;var ib=function(b,c){var e;var f=null!=(e=b.percent)?e:"";Qa=b.id.padEnd(35," ")+b.total.toString().padEnd(6,
" ")+f.padEnd(10," ");var g=a.difficultyLvls;f=0;for(e=g.length;f<e;f++)ta=g[f],Qa+=b.diffs[ta].toString().padEnd(6," ");d.drawText(Qa,I,c,{halign:"left",os:0,fillColor:Ha?"white":"LightGray"});return Ha=!Ha};var kb=0;for(m=Ya.length;kb<m;kb++)pb=Ya[kb],ib(pb,P),P+=6*this.s;P+=4*this.s;ib(Da,P);P+=10*this.s;ib(db,P);P+=6*this.s;ib(lb,P)};z.prototype.drawDebugBiomes=function(a,b,c){var d,e,f,g,h;if(n.isIO()&&this.main.world===this.main.worldGenIO.world)this.drawDebugBiomesIO(this.main.worldGenIO,b,
c);else{b=$jscomp.makeIterator([270,270]);a=b.next().value;b=b.next().value;this.ctx.globalAlpha=1;this.ctx.font="16px Courier New, Lucida Console, Monaco, monospace";var k=$jscomp.makeIterator(this.cam.scroll.lst());c=k.next().value;var l=k.next().value;var m=this.main.world.getBiomes();var p=0;for(e=m.length;p<e;p++){k=m[p];k.blocking?(this.ctx.fillStyle="#555",this.ctx.fillRect(c+k.pos.x*a,l+k.pos.y*b,a-4,b-4)):(this.ctx.strokeStyle="#593B34",this.ctx.strokeRect(c+k.pos.x*a,l+k.pos.y*b,a-4,b-4));
this.ctx.fillStyle=k.debugColor;this.ctx.fillText("["+k.id+"]",c+k.pos.x*a+10,l+k.pos.y*b+16);var w=k.pos.x*a+10;var da=k.pos.y*b+50;var q=k.locations;var v=g=0;for(d=q.length;g<d;v=++g)v=q[v],0<v.actions.length&&(this.ctx.fillStyle=null!=(f=v.debugColor)?f:"yellow",v=null!=v.tokenIdx?"*"+v.id:v.id,this.ctx.fillText(v,c+w,l+da),da+=16);g=k.locations;v=d=0;for(q=g.length;d<q;v=++d)v=g[v],0===v.actions.length&&v.showHint&&(this.ctx.fillStyle=null!=(h=v.debugColor)?h:"yellow",v="("+v.id+")",this.ctx.fillText(v,
c+w,l+da),da+=16);w=this.main.world.toBiomePos(this.main.party.pos);k.pos.eq(w)&&(this.ctx.fillStyle="blue",this.ctx.fillRect(c+k.pos.x*a+a/2,l+k.pos.y*b+b/2,10,10))}}};z.prototype.drawExitButton=function(a,b,c,d){d=void 0===d?0:d;var e=$jscomp.makeIterator(this.getCanvasSize());var f=e.next().value;e.next();e=new R(110*this.s,25*this.s);f=f-e.w-5*this.s;var g=d+5*this.s;var h=!1;d="white";f<b&&b<f+e.w&&g<c&&c<g+e.h&&(h=!0,d="red");this.drawPanel("backButton",f,g,e.w,e.h);this.drawText(a,f+e.w/2,
g+16*this.s,{fillColor:d,halign:"center",font:config.fonts.technicalLarge});return h};z.prototype.addStatParticle=function(a,b,c){if(0!==a)return c=0<a?"+"+a:a,a=new u(this.ctx.canvas.width-b,80),config.particle.statChange.text=c,config.particle.statChange.queue="stat"+b,this.part.addParticleConf(config.particle.statChange,a)};z.prototype.addStatHighlightParticle=function(a,b){var c=$jscomp.makeIterator(this.getCanvasSize());var d=c.next().value;c=c.next().value;d=new u(d/2,c/2);null!=a&&(b=0<a?b+
" +"+a:b+" "+a);config.particle.statChangeHighlight.text=b;return this.part.addParticleConf(config.particle.statChangeHighlight,d)};z.prototype.drawWayPoints=function(a){var b;if(!debug.hidePath&&!this.pureMode){new R(config.imgSize.location);this.ctx.globalAlpha=1;var c=0;for(b=a.length;c<b;c++){var d=a[c];d=this.getTileScreenPos(d);this.drawSprite("res_fxt_pin.png",d.x,d.y,{scale:this.biomeScaleFactor})}}};z.prototype.drawLegs=function(a){var b,c;new R(config.imgSize.location);this.ctx.globalAlpha=
1;this.ctx.font="32px Curious";var d=b=0;for(c=a.length;d<c;d++){var e=$jscomp.makeIterator(a[d]);var f=e.next().value;e=e.next().value;null!=f&&!f.isBlocking()&&(f=this.getTileScreenPos(f.pos),this.drawSprite("res_fxt_pin.png",f.x,f.y,{scale:this.biomeScaleFactor}),0===e||e>b+5)&&(this.drawText(0===e?q.toText("txt-base-start"):e,f.x+.75*this.biomeScreenSize.w,f.y+.75*this.biomeScreenSize.h,config.colors.path),b=e)}};z.prototype.drawTriangles=function(a,b,c){var d,e;this.ctx.lineWidth=2;this.ctx.globalAlpha=
1;this.ctx.fillStyle=config.triangulation.color;var f=e=0;for(d=a.length;e<d;f=++e){f=a[f];var g=this.getTileScreenPos(f);f=this.img.triSpot;this.ctx.drawImage(f,0,0,f.width,f.height,g.x+this.biomeScreenSize.w/2-f.width/2,g.y+this.biomeScreenSize.h/2-f.height/2,f.width,f.height)}f=e=0;for(a=b.length;e<a;f=++e){var h=$jscomp.makeIterator(b[f]);d=h.next().value;g=h.next().value;var k=h.next().value;h=h.next().value;this.ctx.globalAlpha=Math.max(config.jam.minTriangleAlpha,1-.4*f);g=this.getTileScreenPos(g);
k=this.getTileScreenPos(k);h=this.getTileScreenPos(h);this.ctx.save();d||this.ctx.setLineDash([5,10]);this.ctx.lineWidth=config.triangulation.lineWidth;this.ctx.beginPath();this.ctx.moveTo(g.x+this.biomeScreenSize.w/2,g.y+this.biomeScreenSize.h/2);this.ctx.lineTo(k.x+this.biomeScreenSize.w/2,k.y+this.biomeScreenSize.h/2);this.ctx.lineTo(h.x+this.biomeScreenSize.w/2,h.y+this.biomeScreenSize.h/2);this.ctx.closePath();0===f&&1.2>c&&.15>c%.3&&(this.ctx.fillStyle=d?config.triangulation.color:"red",this.ctx.globalAlpha=
.5,this.ctx.fill());this.ctx.strokeStyle=config.triangulation.color;this.ctx.stroke();this.ctx.restore();0===f&&debug.showTriangulationCapture&&(J.padTriangle(g,k,h,config.triangulation.capturePadding),this.ctx.strokeStyle="red",this.ctx.globalAlpha=.5,this.ctx.beginPath(),this.ctx.moveTo(g.x+this.biomeScreenSize.w/2,g.y+this.biomeScreenSize.h/2),this.ctx.lineTo(k.x+this.biomeScreenSize.w/2,k.y+this.biomeScreenSize.h/2),this.ctx.lineTo(h.x+this.biomeScreenSize.w/2,h.y+this.biomeScreenSize.h/2),this.ctx.closePath(),
this.ctx.stroke())}};z.prototype.drawPreviewTriangles=function(a,b,c){var d;this.ctx.globalAlpha=.8;var e=a.slice(1);var f=0;for(a=e.length;f<a;f++){var g=e[f];var h=this.getTileScreenPos(g);g=this.img.triSpotLarge;this.ctx.drawImage(g,0,0,g.width,g.height,h.x+this.biomeScreenSize.w/2-g.width/2,h.y+this.biomeScreenSize.h/2-g.height/2,g.width,g.height)}if(debug.showTriangulationCapture)for(null!=c&&(d=this.getTileScreenPos(c)),a=0,c=b.length;a<c;a++)e=b[a],e=$jscomp.makeIterator(e),f=e.next().value,
e=e.next().value,f=this.getTileScreenPos(f),e?(this.ctx.strokeStyle="red",this.ctx.lineWidth=2):(this.ctx.strokeStyle="green",this.ctx.lineWidth=4),this.ctx.beginPath(),this.ctx.moveTo(d.x+this.biomeScreenSize.w/2,d.y+this.biomeScreenSize.h/2),this.ctx.lineTo(f.x+this.biomeScreenSize.w/2,f.y+this.biomeScreenSize.h/2),this.ctx.closePath(),this.ctx.stroke()};z.prototype.drawMapLines=function(a,b,c,d,e){var f;c=0;for(b=a.length;c<b;c++){d=a[c];var g=this.getTileScreenPos(d.pos,!0,!0,!0);d=this.img.triSpot;
this.ctx.drawImage(d,0,0,d.width,d.height,g.x-d.width/2,g.y-d.height/2,d.width,d.height)}this.ctx.strokeStyle=config.colors.mapLines;this.ctx.lineWidth=2;if(2<=a.length){b=f=0;for(g=a.length-1;0<=g?f<g:f>g;b=0<=g?++f:--f){d=this.getTileScreenPos(a[b].pos,!0,!0,!0);c=this.getTileScreenPos(a[b+1].pos,!0,!0,!0);d=c.diff(d);var h=a[b].succ;a[b].pos.dist(a[b+1].pos);0===b&&3>e&&.3<e%.5||(this.ctx.lineWidth=0===b?3:2,this.ctx.save(),h||this.ctx.setLineDash([3,15]),this.ctx.beginPath(),this.ctx.moveTo(c.x,
c.y),this.ctx.lineTo(c.x+1*d.x,c.y+1*d.y),this.ctx.stroke(),this.ctx.restore())}this.ctx.globalAlpha=config.mapLines.secondaryAlpha;this.ctx.lineWidth=1;b=e=0;for(g=a.length-2;0<=g?e<g:e>g;b=0<=g?++e:--e)d=this.getTileScreenPos(a[b].pos,!0,!0,!0),c=this.getTileScreenPos(a[b+2].pos,!0,!0,!0),this.ctx.save(),this.ctx.beginPath(),this.ctx.moveTo(d.x,d.y),this.ctx.lineTo(c.x,c.y),this.ctx.closePath(),this.ctx.stroke(),this.ctx.restore()}};z.prototype.createMiniMap=function(a,b,c,d,e){var f,g,h,k,l;var m=
$jscomp.makeIterator(b.lst());b=m.next().value;var p=m.next().value;m=this.createCanvas(b,p);this.setImageSmoothing(!1,m);var w=this.zoomLevel;this.resetZoom();var da=e.getTilesInRadius(a,5,!0,n.isIO());if(n.isIO()){var q=0;for(f=da.length;q<f;q++)(l=da[q])&&!l.biome.generated&&this.main.worldGenIO.generateBiome(l.biome.pos,!0)}f=this.getTileScreenPos(a,!1,!1,!0);q=[];var v=0;for(h=da.length;v<h;v++)if(l=da[v],null!=l){var y=this.getTileScreenPos(l.pos,!1,!1,!1);y=y.sub(f).add(c);Math.random()<d&&
(this.drawSprite(l.sprite,y.x,y.y,{ctx:m}),null!=(null!=(g=l.location)?g.sprite:void 0)&&this.drawSprite(l.location.sprite,y.x,y.y,{ctx:m}),q.push(l));l.pos.eq(a)&&this.drawSprite("res_fxt_treasureLocation.png",y.x,y.y,{ctx:m})}g=0;for(v=da.length;g<v;g++)if(l=da[g],null!=l&&null!=l.borderSprites)for(y=this.getTileScreenPos(l.pos,!1,!1,!0),y=y.sub(f).add(c),h=0,k=Ea.length;h<k;h++)if(d=Ea[h],0!==d.val){var t=e.getTile(l.pos.move(d));this.hasBorder(l,t,!0)&&(q.includes(l)||q.includes(t))&&this.drawSprite(l.borderSprites[d.val-
1],y.x,y.y,{halign:"center",valign:"center",ctx:m})}n.isIO()&&(a=e.toBiomePos(a),c=config.io.topRulerWidth*this.s,m.font=config.fonts.themedSmall,m.globalAlpha=1,m.fillStyle=0===a.x%2?config.io.rulerCol1:config.io.rulerCol2,m.fillRect(0,0,b,c),e=0===a.x%2?config.io.rulerCol2:config.io.rulerCol1,da=b/2,this.drawText(this.main.worldGenIO.getBiomeDisplayTextX(a.x),da,.8*c,{halign:"center",valign:"center",os:0,fillColor:e,ctx:m}),m.fillStyle=config.io.rulerCol2,m.globalAlpha=1,m.fillRect(0,c-1*this.s,
b,1*this.s),c=config.io.sideRulerWidth*this.s,m.fillStyle=0===a.y%2?config.io.rulerCol1:config.io.rulerCol2,m.fillRect(0,0,c,p),m.save(),m.translate(.8*c,p/2),m.rotate(-90*Math.PI/180),e=0===a.y%2?config.io.rulerCol2:config.io.rulerCol1,this.drawText(this.main.worldGenIO.getBiomeDisplayTextY(a.y),0,0,{halign:"center",valign:"center",os:0,fillColor:e,ctx:m}),m.restore(),m.fillStyle=config.io.rulerCol2,m.globalAlpha=1,m.fillRect(c-1*this.s,0,1*this.s,p));this.resetZoom(w);return m.canvas};z.prototype.drawMiniMap=
function(a,b,c){this.ctx.save();this.ctx.globalAlpha=1;this.ctx.fillStyle="#ddd";this.ctx.fillRect(b,c,a.canvas.width,a.canvas.height);this.ctx.drawImage(a.canvas,b,c);this.ctx.lineWidth=2;this.ctx.strokeStyle=config.colors.partyBorder;this.ctx.strokeRect(b,c,a.canvas.width,a.canvas.height);return this.ctx.restore()};z.prototype.drawSubItems=function(a){var b;var c=$jscomp.makeIterator(this.getCanvasSize());var d=c.next().value;c=c.next().value;var e=a.subItems.first();if(null!=(null!=e?e.canvas:
void 0)){var f=$jscomp.makeIterator([.75*e.canvas.width,.75*e.canvas.height]);e=f.next().value;f=f.next().value}else f=$jscomp.makeIterator([config.imgSize.item[0]*this.s,config.imgSize.item[1]*this.s]),e=f.next().value,f=f.next().value;var g=d/2-n.width(a.subItems.length,e,8*this.s)/2;d={halign:"center",valign:"center"};this.ctx.globalAlpha=1;var h=a.subItems;var k=0;for(b=h.length;k<b;k++)a=h[k],null!=a.canvas?this.ctx.drawImage(a.canvas,0,0,a.canvas.width,a.canvas.height,g,c+f/2-100*this.s,e,f):
this.drawSprite(a.sprite,g+e/2,c+f/2-70*this.s,d),g+=e+8*this.s};z.prototype.addGameFade=function(a,b,c){if(!this.trailerMode)return config.particle.travelText.text=a,a=this.part.getParticlePositionForTilePos(config.particle.travelText,b),this.part.addParticleConf(config.particle.travelText,a)};z.prototype.addTxtFade=function(a,b,c,d,e,f){return this.animatedFades.push({ctx:a,pos:c,txt:b,addScroll:d,speed:e,time:-f})};z.prototype.drawFades=function(a){var b;var c=function(a){return 2*(1-a)};var d=
this.animatedFades;var e=0;for(b=d.length;e<b;e++){var f=d[e];if(0<=f.time){f.ctx.font="bold 18px sans-serif";f.ctx.globalAlpha=c(f.time);f.ctx.fillStyle="white";var g=f.ctx.measureText(f.txt);g=f.pos.x-g.width/2;var h=f.pos.y;f.addScroll&&(g+=this.cam.scroll.x,h+=this.cam.scroll.y);f.ctx.fillText(f.txt,g,h);f.pos.y+=a*f.speed}f.time+=a}return this.animatedFades=this.animatedFades.filter(function(a){return 0<c(a.time)})};z.prototype.getMapSize=function(a){var b=$jscomp.makeIterator([this.biomeScreenSize.w-
this.biomeScreenOffset.w,this.biomeScreenSize.h-this.biomeScreenOffset.h]);var c=b.next().value;b=b.next().value;b=$jscomp.makeIterator([c*config.board.biomeSize[0],b*config.board.biomeSize[1]]);c=b.next().value;b=b.next().value;return[c*a.w,b*a.h]};z.prototype.drawMouseBiomeBorder=function(a){if(null!=a.outline)return this.drawHexOutline(this.ctx,a.outline,"#000",.3,!1)};z.prototype.drawUnenteredBiomeBorders=function(a){var b;if(null==this.biomeBorderCtx){var c=document.createElement("canvas");c.width=
this.ctx.canvas.width;c.height=this.ctx.canvas.height;this.biomeBorderCtx=c.getContext("2d");this.biomeBorderCtx.setLineDash([5,10])}if(this.biomeBorderDirty){this.biomeBorderDirty=!1;this.biomeBorderCtx.clearRect(0,0,this.biomeBorderCtx.canvas.width,this.biomeBorderCtx.canvas.height);var d=0;for(b=a.length;d<b;d++)c=a[d],c.entered||null==c.outline||this.drawHexOutline(this.biomeBorderCtx,c.outline,"#DDD",.3,!1)}return this.ctx.drawImage(this.biomeBorderCtx.canvas,0,0)};z.prototype.drawBiomeBackground=
function(a){var b=new R(config.board.biomeSize);b=new R(b.w*(this.blockSize.w-this.blockOffset.w),b.h*(this.blockSize.h-this.blockOffset.h));a.ctx.globalAlpha=1;var c=!a.isOutside&&!this.main.isWarping()&&n.isIO()&&null!=this.main.worldGenIO.getBiomeDict(a.pos).claim;c=!(a.isOutside||a.blocking&&a.entered||c)||n.isDemo()&&null==this.main.tutorial&&0===this.main.worldLvl?this.img.biomeBackground:this.img.biomeBackgroundTinted;var d=c.width/config.imgSize.biomeBgVariations;if(n.isChina())switch(a.imgIdx){case 2:a.imgIdx=
1;break;case 4:a.imgIdx=6;break;case 5:a.imgIdx=3;break;case 7:a.imgIdx=0}a.ctx.drawImage(c,d*a.imgIdx,0,d,c.height,0,0,b.w,b.h)};z.prototype.setRandBalloonX=function(){var a=$jscomp.makeIterator(this.getCanvasSize());var b=a.next().value;a.next();return this.balloonX=Number.random(100,b-100)};z.prototype.drawJungleBackground=function(){var a,b;var c=$jscomp.makeIterator(this.getCanvasSize());var d=c.next().value;c=c.next().value;this.ctx.globalAlpha=1;this.ctx.fillStyle="#00B974";this.ctx.fillRect(0,
50,d,c-100);var e=this.img.jungleLayers;var f=b=0;for(a=e.length;b<a;f=++b){var g=e[f];var h=this.img.getSprite(g.sprite);g=0>g.offset?0:c-h.dSize.h-g.offset*this.s;f=-(this.timeTotal*config.anim.jungleLayers)*(f+2)*config.anim.jungleScrollSpeed;for(f%=h.dSize.w;f<d;)this.drawSprite(h,f,g),f+=h.dSize.w}return this.drawSprite("baloon.png",this.balloonX,30+Math.floor(8*Math.sin(this.timeTotal/2+.3)*this.s))};z.prototype.drawNarratorBackground=function(){var a=$jscomp.makeIterator(this.getCanvasSize());
var b=a.next().value;var c=a.next().value;null==this.fireAlpha&&(this.fireAlpha=1);null==this.fireAlphaTarget&&(this.fireAlphaTarget=1);a=this.fireAlphaTarget-this.fireAlpha;0<a?this.fireAlpha=Math.min(this.fireAlphaTarget,this.fireAlpha+this.timeDelta*config.fireplace.speed):0>a?this.fireAlpha=Math.max(this.fireAlphaTarget,this.fireAlpha-this.timeDelta*config.fireplace.speed):this.fireAlphaTarget=J.randA(config.fireplace.alpha);this.ctx.globalAlpha=1;this.drawFrame("menu_bg_1.png");this.ctx.globalAlpha=
this.fireAlpha;this.drawFrame("menu_bg_2.png");var d=$jscomp.makeIterator([62,34,6]);var e=d.next().value;a=d.next().value;d=d.next().value;c=$jscomp.makeIterator([b/2+config.fireplace.offset[0]*this.s,c/2+config.fireplace.offset[1]*this.s]);b=c.next().value;c=c.next().value;d=Math.floor(this.timeTotal/.12%d);this.ctx.globalAlpha=1;return this.ctx.drawImage(this.img.fireplace,d*e,0,e,a,b,c,e*this.s,a*this.s)};z.prototype.drawCompass=function(a,b,c,d,e,f,g,h,k,l){var m=$jscomp.makeIterator(this.getCanvasSize());
m.next();m.next();if(!this.pureMode&&(this.ctx.globalAlpha=1,this.ctx.lineWidth=2*this.s,this.ctx.strokeStyle="orange",a-=120*this.hudAlpha(),a=new u(a+25*this.s,20*this.s+this.oY),m=1+.1*(1-TWEEN.Easing.Bounce.Out(1.5*f)).clamp(0,1),f=-75*this.s+75*this.s*this.introAlpha(),this.drawSprite("hud_compass_base.png",a.x,a.y+f,{halign:"center",valign:"center",scale:m}),this.ctx.save(),this.ctx.translate(a.x,a.y+f),this.ctx.scale(.5*m*this.s,.5*m*this.s),this.ctx.globalAlpha=1,m=this.img.compass,4.3<this.introTime&&
this.ctx.rotate(-b+Math.sin(this.timeTotal)*c),this.ctx.drawImage(m,-m.width/2,-m.height/2+f),this.ctx.restore(),this.hitBox(a.x-m.width/2,a.y-m.height/2,m.width,m.height,k,l)&&(n.isIO()?h.setInfo([{text:config.help.compass,col:config.colors.help}]):(b=100*d/e,h.setInfo([{text:q.toText("txt-help-compass-info")+": "+b.format(0)+"%"},{text:config.help.compass,col:config.colors.help}]))),n.isIO()&&!this.main.isWarping()&&null==this.main.tutorial&&null!=g)){a.y+=10*this.s;this.drawSprite("hud_compass_distance.png",
a.x-4*this.s,a.y+f,{halign:"center",valign:"center"});h=Math.min(999,g).toString();a.y+=27.5*this.s;a.x+=9.5*this.s;c=[];for(g=d=b=h.length-1;0>=b?0>=d:0<=d;g=0>=b?++d:--d)this.drawText(h[g],a.x,a.y+f,{halign:"center",font:config.fonts.themedSmall,fillColor:"#f0e0c4",os:0}),c.push(a.x-=9*this.s);return c}};z.prototype.selectedMarkerTween=function(a){return this.s*(8*TWEEN.Easing.Bounce.Out(1.2*a%1)-8)};z.prototype.drawLocationMarkers=function(a,b){var c,d;if(!this.pureMode){this.ctx.globalAlpha=1;
var e=this.img.mapMarker;var f=$jscomp.makeIterator([e.width/2,e.height]);var g=f.next().value;f=f.next().value;var h=$jscomp.makeIterator([.5*this.s*g*this.biomeScaleFactor,.5*this.s*f*this.biomeScaleFactor]);f=h.next().value;h=h.next().value;var k=0;for(c=a.length;k<c;k++){var l=a[k];var m=l.tiles;var p=0;for(d=m.length;p<d;p++){var w=m[p];if(null!=w.location){var n=w.location;if(n.hasActions()&&n.known){n.knownTime+=b;var q=TWEEN.Easing.Bounce.Out((1*n.knownTime).clamp(0,1));l=0;this.action_highlight===
n&&(l=this.selectedMarkerTween(this.timeTotal-this.markedTime));n=this.getTileScreenPos(w.pos,!0,!0,!0);this.ctx.drawImage(e,w.location.everUsed?g:0,0,g,e.height,n.x-q*f/2,n.y-10-q*h+l,q*f,q*h)}}}}}};z.prototype.drawVoidTransparentTiles=function(a){var b=a.tiles;var c=0;for(a=b.length;c<a;c++){var d=b[c];"tl-void"===d.id&&(d=this.getTileScreenPos(d.pos),this.ctx.clearRect(d.x,d.y,this.biomeScreenSize.w,this.biomeScreenSize.h))}};z.prototype.drawVoid=function(a){this.ctx.globalAlpha=1;this.ctx.globalCompositeOperation=
"destination-over";var b=!1;var c=a.getBiomes();var d=0;for(a=c.length;d<a;d++){var e=c[d];e.hasVoid&&(b||(this.drawStarCanvas(),b=!0),e=this.getTileScreenPos(e.getFirstTilePos()),this.ctx.drawImage(this.starCtx.canvas,0,0,this.starCtx.canvas.width,this.starCtx.canvas.height,e.x,e.y,this.starCtx.canvas.width*this.s,this.starCtx.canvas.height*this.s))}return this.ctx.globalCompositeOperation="source-over"};z.prototype.createCanvas=function(a,b){var c=document.createElement("canvas");c.width=a;c.height=
b;return c.getContext("2d")};z.prototype.updateBiomeReveals=function(a,b,c){var d=a.tiles;var e=0;for(a=d.length;e<a;e++){var f=d[e];(f.known||debug.drawAllTiles)&&this.updateTileReveal(f,b,c)}};z.prototype.getNeighbourTiles=function(a,b,c){var d,e;var f=a.offset.x-1;var g=a.offset.y-1;var h=a.offset.x+a.size.x;a=a.offset.y+a.size.y;for(e=d=f;f<=h?d<=h:d>=h;e=f<=h?++d:--d){if(e!==h){var k={x:e,y:g};k=b.getTile(k);null!=k&&k.biome.generated&&c.push(k)}e!==f&&(k={x:e,y:a},k=b.getTile(k),null!=k&&k.biome.generated&&
c.push(k))}for(e=d=g;g<=a?d<=a:d>=a;e=g<=a?++d:--d)e!==a&&(k={x:f,y:e},k=b.getTile(k),null!=k&&k.biome.generated&&c.push(k)),e!==g&&(k={x:h,y:e},k=b.getTile(k),null!=k&&k.biome.generated&&c.push(k))};z.prototype.drawIOMap=function(a,b,c,d,e,f,g,h){g=void 0===g?!0:g;h=void 0===h?1:h;var k,l,m,p,w;if(a.claimCtxDirty){a.worldGenCtx=this.createCanvas(a.world.biomeCount.w,a.world.biomeCount.h);var n=p=0;for(l=a.world.biomeCount.w;0<=l?p<l:p>l;n=0<=l?++p:--p){var q=w=0;for(m=a.world.biomeCount.h;0<=m?w<
m:w>m;q=0<=m?++w:--w){var v=a.world.getBiomeIdx(new u(n,q));if(null!=a.biomes[v]){var y=a.biomes[v].claim;if((k=null!=y&&(null==this.claimDateThreshold||y.record.claimDate<this.claimDateThreshold))||!g&&debug.drawAllTiles)a.worldGenCtx.fillStyle=g?a.biomes[v].isBorder?"black":y.user.colour:t.getBiome(a.biomes[v].biomeID).debugColor,a.worldGenCtx.fillRect(n,q,1,1)}}}a.claimCtxDirty=!1}g=$jscomp.makeIterator(this.getCanvasSize());g.next();g.next();this.ctx.globalAlpha=h;this.ctx.drawImage(a.worldGenCtx.canvas,
0,0,a.worldGenCtx.canvas.width,a.worldGenCtx.canvas.height,c,d,b,b);b/=a.worldGenCtx.canvas.width;c=new u(Math.floor((e-c)/b),Math.floor((f-d)/b));return null!=a.world.getBiomeIdx(c)?c:null};z.prototype.drawLocationSprite=function(a,b,c){var d,e,f,g,h,k;a=t.getLocation(a);if(null!=a){null!=a.sprite&&this.drawSprite(a.sprite,b,c,{halign:"center",valign:"center"});var l=/(\d*)(\w+)/;var m=function(a){var b;for(b in K){var c=K[b];if(a===c.abbr)return c}return r.error("Unable to get hexDir for string '"+
a+"'")};var p=function(a){var b=config.imgSize.blockSize[0]-config.imgSize.hexOffset[0];return new u(a.x*b,a.y*(config.imgSize.blockSize[1]-config.imgSize.hexOffset[1])+(1===Math.abs(a.x%2)?config.imgSize.blockSize[1]/2:0))};var w=a.subLocations;var n=[];var q=0;for(a=w.length;q<a;q++){var v=w[q];var y=t.getLocation(v.ref);n.push(function(){var a;var w=v.offsets.split(" ");var n=[];var q=0;for(a=w.length;q<a;q++)d=w[q],g=l.exec(d),e=m(g[2]),f=parseInt(g[1]),null!=e&&0<f?(k=(new u(0,0)).move(e,f),
h=p(k),n.push(this.drawSprite(y.sprite,b+h.x*this.s,c+h.y*this.s,{halign:"center",valign:"center"}))):n.push(void 0);return n}.call(this))}return n}};z.prototype.drawNewSegmentBanner=function(a,b){var c;var d=$jscomp.makeIterator(this.getCanvasSize());var e=d.next().value;d.next();d=50*this.s;var f=125*this.s;this.ctx.globalAlpha=.6*b;this.ctx.fillStyle="black";this.ctx.fillRect(0,f,e,d);this.ctx.globalAlpha=b;b=a.name;var g=q.toText("txt-io-region-article");b.startsWith(g)&&(this.drawText(g,e/2,
f+12*this.s,{halign:"center",valign:"center",font:config.fonts.themedSmall,os:0}),b=b.slice(g.length+1));this.drawText(b,e/2,f+24*this.s,{halign:"center",valign:"center",font:config.fonts.themedLarge,os:0});g=this.main.worldGenIO.difficultyLvls.indexOf(a.value)+1;var h=this.img.getSprite(config.io.segmentDifficultySprite);if(null!=h){var k=4*this.s;var l=h.dSize.w+k;var m=e/2-(l*g-k)/2;for(k=c=0;0<=g?c<g:c>g;k=0<=g?++c:--c)this.drawSprite(h,m+l*k,f+34*this.s);null!=a.hubBiome&&(b=this.ctx.measureText(b),
a=32*this.s,e=Math.round(e/2+b.width/2+26*this.s+a/2),d=Math.round(f+d/2)-12*this.s,this.drawLocationSprite(config.io.hubLocationID,e,d))}};z.prototype.drawMapRuler=function(a,b){var c,d,e;var f=config.io.topRulerWidth*this.s;var g=$jscomp.makeIterator(this.getCanvasSize());var h=g.next().value;g=g.next().value;var k=-60*this.s*this.hudAlpha()+this.oY;this.ctx.font=config.fonts.themedSmall;var l=e=c=a.x;for(d=b.x;c<=d?e<=d:e>=d;l=c<=d?++e:--e){var m=l*config.board.biomeSize[0];var p=this.getTileScreenPos(new u(m,
0)).x;m+=config.board.biomeSize[0];m=this.getTileScreenPos(new u(m,0)).x;m-=p;this.ctx.fillStyle=0===l%2?config.io.rulerCol1:config.io.rulerCol2;this.ctx.globalAlpha=config.io.rulerAlpha;this.ctx.fillRect(p,k,m,f);if(-4<=this.zoomLevel){this.ctx.globalAlpha=1;var w=0===l%2?config.io.rulerCol2:config.io.rulerCol1;this.drawText(this.main.worldGenIO.getBiomeDisplayTextX(l),p+m/2,k+.8*f,{halign:"center",valign:"center",os:0,fillColor:w})}}c=this.main.leftSidebarScrollX+config.io.sideRulerOffset*this.s;
this.ctx.fillStyle=config.io.rulerCol2;this.ctx.globalAlpha=1;this.ctx.fillRect(c+f,k+f-1*this.s,h,1*this.s);f=config.io.sideRulerWidth*this.s;h=d=a=a.y;for(b=b.y;a<=b?d<=b:d>=b;h=a<=b?++d:--d)m=h*config.board.biomeSize[1],w=this.getTileScreenPos(new u(0,m)).y,m+=config.board.biomeSize[1],p=this.getTileScreenPos(new u(0,m)).y,m=p-w,this.ctx.fillStyle=0===h%2?config.io.rulerCol1:config.io.rulerCol2,this.ctx.globalAlpha=config.io.rulerAlpha,this.ctx.fillRect(c,w,f,m),-4<=this.zoomLevel&&(this.ctx.globalAlpha=
1,this.ctx.save(),this.ctx.translate(c+.8*f,p-m/2),this.ctx.rotate(-90*Math.PI/180),w=0===h%2?config.io.rulerCol2:config.io.rulerCol1,this.drawText(this.main.worldGenIO.getBiomeDisplayTextY(h),0,0,{halign:"center",valign:"center",os:0,fillColor:w}),this.ctx.restore());k=k+f-1*this.s;this.ctx.fillStyle=config.io.rulerCol2;this.ctx.globalAlpha=1;this.ctx.fillRect(c+f-1*this.s,k,1*this.s,g)};z.prototype.drawBiomeToScreen=function(a,b,c){var d;this.drawBiomeTiles(a,b,c);if(debug.onlyDrawPlayerBiome&&
b.getTile(this.main.party.pos).biome!==a)b.drawEmptyBiomeBackground(a.pos);else{b=this.getTileScreenPos(a.getFirstTilePos());c=$jscomp.makeIterator(this.getCanvasSize());var e=c.next().value;var f=c.next().value;n.assert(a.ctx.canvas.width===a.zoneCtx.canvas.width);n.assert(a.ctx.canvas.height===a.zoneCtx.canvas.height);c=this.biomeScaleFactor*this.s;n.assert(0<c);var g=a.ctx.canvas.width;var h=a.ctx.canvas.height;var k=g*c;var l=h*c;var m=d=0;g=this.main.showingLeftSidebar()?Math.round(this.main.leftSidebarScrollX-
60*this.s*this.hudAlpha())+27*this.s:0;h=this.main.showingPartySidebar()?32*this.s-Math.round(120*this.hudAlpha()):0;b.x<g&&(m=-b.x+g,k-=m,b.x=g,m/=c);0>b.y&&(d=-b.y,l-=d,b.y=0,d/=c);b.x+k>=e-h&&(e=b.x+k-(e-h),k-=e);b.y+l>=f&&(f=b.y+l-f,l-=f);0<k&&0<l&&(n.assert(J.bboxIntersect(b.x,b.y,k,l,0,0,this.ctx.canvas.width,this.ctx.canvas.height)),g=k/c,h=l/c,this.ctx.drawImage(a.ctx.canvas,m,d,g,h,b.x,b.y,k,l),null!=a.segmentCtx&&this.ctx.drawImage(a.segmentCtx.canvas,m,d,g,h,b.x,b.y,k,l),-1<=this.zoomLevel&&
this.ctx.drawImage(a.zoneCtx.canvas,m,d,g,h,b.x,b.y,k,l),null!=this.main.numSpritesDraw&&(this.main.numSpritesDraw+=2),null!=this.main.numPixDraw&&(this.main.numPixDraw+=k*l));if(debug.logBiomeRenderStats)return this.main.numBiomesDraw+=1}};z.prototype.drawBiomeTiles=function(a,b,c){this.ctx.globalAlpha=1;if(null==a.ctx||a.ctxRedraw){a.ctxRedraw=!0;var d=(this.blockSize.w-this.blockOffset.w)*a.size.w;c=(this.blockSize.h-this.blockOffset.h)*a.size.h;a.ctx=this.createCanvas(d,c);this.setImageSmoothing(!1,
a.ctx);this.drawBiomeBackground(a);a.zoneCtx=this.createCanvas(d,c);this.setImageSmoothing(!1,a.zoneCtx);a.znCtxDirty=!0;n.isIO()&&(a.segmentCtx=this.createCanvas(d,c),this.setImageSmoothing(!1,a.segmentCtx));debug.logBiomeRenderStats&&(this.main.numBiomesRedraw+=1)}if(!this.main.waitingForDemoStart){c=null;if(a.ctxDirty||a.ctxRedraw||a.znCtxDirty)c=a.tiles.slice(),this.getNeighbourTiles(a,b,c);if(a.ctxRedraw){var e=0;for(d=c.length;e<d;e++){var f=c[e];f.ctxDirty=!0}}if(a.ctxDirty||a.ctxRedraw){a.ctxRedraw||
this.setImageSmoothing(!1,a.ctx);e=0;for(f=c.length;e<f;e++)d=c[e],debug.drawAllTiles?this.drawTile(d,a,b):(d.ctxDirty||a.ctxRedraw||1!==d.lastDrawnAlpha)&&d.known&&this.drawTile(d,a,b);debug.drawAllTiles||this.drawBiomeTileOutlines(c,a,b);this.drawBiomeTileBorders(c,a,b);this.drawBiomeLocations(a,c);if(n.isIO()&&null==this.main.tutorial&&!this.main.isWarping())for(a.segmentCtx.clearRect(0,0,a.segmentCtx.canvas.width,a.segmentCtx.canvas.height),f=0,e=c.length;f<e;f++)d=c[f],this.drawSegmentBorders(d,
a,b)}a.znCtxDirty&&(this.drawBiomeZones(a,b,c),a.znCtxDirty=!1)}a.ctxDirty=!1;return a.ctxRedraw=!1};z.prototype.drawBiomeLocations=function(a,b){var c;var d=0;for(c=b.length;d<c;d++){var e=b[d];(e.known||debug.drawAllTiles)&&this.drawLocation(a,e)}};z.hasZoneBorder=function(a,b){return b.showOutline&&b.borderImgIdx===a.borderImgIdx&&!b.seeking};z.prototype.drawBiomeZones=function(a,b,c){var d,e,f;if(!this.pureMode){var g=a.zoneCtx.canvas;a.zoneCtx.clearRect(0,0,g.width,g.height);var h=Ea;var k=0;
for(d=c.length;k<d;k++){var l=c[k];if(l.known||debug.drawAllTiles){var m=l.zones;var p=0;for(e=m.length;p<e;p++){var w=m[p];if(w.showOutline&&!w.seeking){var n=0;for(f=h.length;n<f;n++){g=h[n];var q=b.getTile(l.pos.move(g));null!=q&&0>q.zones.findIndex(function(a){return z.hasZoneBorder(w,a)})&&this.drawInnerBorderTile(l,g,this.img.borderTilesZone,b,a,w.borderImgIdx,a.zoneCtx)}}}}}}};z.prototype.getTileLocalPosInBiome=function(a,b){n.assert(null!=b,"no biome");n.assert(null!=a,"no tile");n.assert(null!=
a.biome,"no tile biome");n.assert(null!=b.offset,"no biome");n.assert(null!=a.biome.offset,"no biome");var c=a.localPos;if(a.biome!==b){var d=a.biome.offset.x-b.offset.x;a=a.biome.offset.y-b.offset.y;c={x:c.x+d,y:c.y+a}}return c};z.prototype.drawTileBorder=function(a,b,c){var d;var e=this.getTileLocalPosInBiome(a,c);var f=this.getTileBiomePos(e,!1,!0);var g=0;for(d=Ea.length;g<d;g++)if(e=Ea[g],0<e.val){var h=b.getTile(a.pos.move(e));this.hasBorder(a,h)&&(h=h.known&&1<=h.alpha||this.trailerMode||debug.drawAllTiles,
this.drawSprite(a.borderSprites[e.val-1],f.x,f.y,{halign:"center",valign:"center",ctx:c.ctx,screenScale:1,useTinted:!h,round:!1}),debug.logBiomeRenderStats&&(this.main.numTileBordersDraw+=1))}};z.prototype.drawBiomeTileBorders=function(a,b,c){var d;if(config.board.showBorders){var e=0;for(d=a.length;e<d;e++){var f=a[e];null!=f.borderSprites&&this.drawTileBorder(f,c,b)}}};z.prototype.hasBorder=function(a,b,c){c=void 0===c?debug.drawAllTiles:c;return null!=b&&a.id!==b.id&&a.borderTag!==b.borderTag&&
(a.borderPrio>b.borderPrio||a.borderPrio===b.borderPrio&&a.borderPrioRand>b.borderPrioRand)&&(b.known||a.known||c)&&(a.known||!a.borderOnlyKnown||c)&&(a.biome.ctxRedraw||a.ctxDirty||b.biome.ctxRedraw||b.ctxDirty||c)};z.prototype.drawLiveTile=function(a){var b,c;var d=$jscomp.makeIterator(config.imgSize.tile);d.next();d.next();var e=$jscomp.makeIterator([this.biomeScreenSize.w/2,this.biomeScreenSize.h/2]);d=e.next().value;var f=e.next().value;e=this.timeDelta*this.main.graphicsSettings.liveTileEmitterTickMultiplier;
var g=a.tiles;var h=0;for(a=g.length;h<a;h++){var k=g[h];if("tl-void"!==k.id&&(this.drawTileHints(k),k.known||debug.drawAllTiles)){var l=k.particle;var m=k.zones;var p=0;for(b=m.length;p<b;p++){var w=m[p];null!=w.particle&&(l=w.particle)}this.tickParticleEmitter(e,l,k,k.pos);b=k.location;null!=b&&(b.known||debug.drawAllLocations)&&this.tickParticleEmitter(e,b.particle,b,k.pos);0<(c=k.alpha)&&1>c&&!debug.drawAllTiles&&(p=this.getTileScreenPos(k.pos),m=Math.floor(k.alpha*d),b=m/d,l=b*f,m=$jscomp.makeIterator([p.x+
d-m,p.y+f-l]),l=m.next().value,m=m.next().value,this.ctx.globalAlpha=k.alpha,this.drawSprite(k.sprite,l,m,{scale:this.biomeScaleFactor*b}))}}};z.prototype.drawInnerBorderTile=function(a,b,c,d,e,f,g){f=void 0===f?0:f;g=void 0===g?e.ctx:g;var h=$jscomp.makeIterator(config.imgSize.tile);d=h.next().value;h=h.next().value;a=this.getTileLocalPosInBiome(a,e);a=this.getTileBiomePos(a,!1);if(J.bboxIntersect(a.x,a.y,this.blockSize.w,this.blockSize.h,0,0,g.canvas.width,g.canvas.height)){if(g.drawImage(c,d*(b.val-
1),f*h,d,h,a.x,a.y,this.blockSize.w,this.blockSize.h),debug.logBiomeRenderStats)return this.main.numMapBordersDraw+=1}else null!=this.main.numSkippedDraws&&(this.main.numSkippedDraws+=1)};z.prototype.updateTileReveal=function(a,b,c){var d;c&&(a.hasVisibleNeighbor=!0);if(1!==a.alpha||a.lastDrawnAlpha!==a.alpha){c=J.clamp(a.visibleTime/config.anim.tileBlendInTime,0,1);if(1!==a.elevation||a.hasVisibleNeighbor)if(a.visible||a.known){if(a.visibleTime<Math.max(config.anim.tileBlendInTime,config.anim.tileBlendInDelay)&&
(a.visibleTime+=this.timeDelta),!a.hasNotifiedNeighbors&&a.visibleTime>config.anim.tileBlendInDelay){var e=b.getTilesInRadius(a.pos,1);var f=0;for(d=e.length;f<d;f++){var g=e[f];g.hasVisibleNeighbor=!0}a.hasNotifiedNeighbors=!0}}else c=0;1===c&&1!==a.alpha&&b.setTileCtxDirtyWithNeighbours(a);a.alpha=c}};z.prototype.drawTile=function(a,b,c){c=this.getTileLocalPosInBiome(a,b);var d=this.getTileBiomePos(c,!1,!0);this.drawTileBackground(a,b,d);d=this.getTileBiomePos(c,!1);return this.drawTileTotalViewCost(a,
b,d)};z.prototype.drawSegmentBorders=function(a,b,c){var d;if(a.known||debug.drawAllTiles){var e=this.getTileLocalPosInBiome(a,b);this.getTileBiomePos(e,!1);e=this.main.worldGenIO.getBiomeDict(a.biome.pos);var f=this.main.worldGenIO.difficultyLvls.indexOf(e.worldLvl);var g=0;for(d=Ea.length;g<d;g++){var h=Ea[g];if(0<h.val){var k=c.getTile(a.pos.move(h));null!=k&&k.biome!==a.biome&&(k.known||debug.drawAllTiles)&&(k=this.main.worldGenIO.getBiomeDict(k.biome.pos,!1),null!=k&&k.worldLvl!==e.worldLvl&&
this.drawInnerBorderTile(a,h,this.img.getSprite("map_border_segment.png").img,c,b,config.board.segmentBorderIndices[f],b.segmentCtx))}}}};z.prototype.drawBiomeTileOutlines=function(a,b,c){var d;var e=0;for(d=a.length;e<d;e++){var f=a[e];f.known&&(f.ctxDirty||b.ctxRedraw||1!==f.lastDrawnAlpha)&&this.drawTileOutlines(f,c,b)}};z.prototype.drawTileOutlines=function(a,b,c){this.drawTileOutline(a,b,c);return this.drawTileOutlineShadow(a,b,c)};z.prototype.drawTileOutline=function(a,b,c){var d;var e=0;for(d=
Ea.length;e<d;e++){var f=Ea[e];if(0<f.val){var g=b.getTile(a.pos.move(f));null==g||g.known||null==g.biome.ctx||(f=Na.invDir(f),this.drawInnerBorderTile(g,f,this.img.borderTiles,b,c))}}};z.prototype.drawTileOutlineShadow=function(a,b,c){var d,e;var f=0;for(d=Ea.length;f<d;f++){var g=Ea[f];if(1===(e=g.val)||2===e||6===e){var h=b.getTile(a.pos.move(g));null==h||h.known||this.drawInnerBorderTile(a,g,this.img.borderTilesShadow,b,c)}}};z.prototype.drawTileBackground=function(a,b,c){var d=$jscomp.makeIterator(config.imgSize.tile);
d.next();d.next();d=this.trailerMode||debug.drawAllTiles?1:a.alpha;b=b.ctx;b.globalAlpha=1;"tl-void"===a.id?(b.globalCompositeOperation="destination-out",this.drawSprite(config.unknownLocationSprite,c.x,c.y,{ctx:b,halign:"center",valign:"center",round:!1,screenScale:1}),b.globalCompositeOperation="source-over"):this.drawSprite(a.sprite,c.x,c.y,{ctx:b,useTinted:1>d,round:!1,halign:"center",valign:"center",screenScale:1});debug.logBiomeRenderStats&&(this.main.numTilesDraw+=1);a.isRiver&&debug.showRivers&&
(b.fillStyle="white",b.fillText("R",c.x,c.y));if("undefined"!==typeof debug&&null!==debug&&(debug.showMapLinesDebug&&a.breakCartography&&(d=this.getTileBiomePos(a.localPos,!0,!0),b.beginPath(),b.strokeStyle="red",b.lineWidth=1,c=config.mapLines.checkScale,b.moveTo(d.x-this.blockSize.w*c+this.blockOffset.w,d.y-this.blockSize.h*c),b.lineTo(d.x-this.blockSize.w*c+this.blockOffset.w,d.y+this.blockSize.h*c),b.moveTo(d.x+this.blockSize.w*c-this.blockOffset.w,d.y-this.blockSize.h*c),b.lineTo(d.x+this.blockSize.w*
c-this.blockOffset.w,d.y+this.blockSize.h*c),b.moveTo(d.x-this.blockSize.w*c,d.y),b.lineTo(d.x+this.blockSize.w*c,d.y),b.closePath(),b.stroke()),debug.showReachable&&a.reachable&&(d=this.getTileBiomePos(a.localPos,!1,!0),b.beginPath(),b.fillStyle="pink",b.arc(d.x,d.y,4,0,2*Math.PI,!1),b.closePath(),b.fill()),debug.showConnected&&a.connected&&(d=this.getTileBiomePos(a.localPos,!1,!0),b.beginPath(),b.fillStyle="pink",b.arc(d.x,d.y,4,0,2*Math.PI,!1),b.closePath(),b.fill()),debug.showSea&&a.sea))return d=
this.getTileBiomePos(a.localPos,!1,!0),this.drawDot(d,b)};z.prototype.drawDot=function(a,b){b=void 0===b?this.ctx:b;b.beginPath();b.fillStyle="blue";b.arc(a.x,a.y,8,0,2*Math.PI,!1);b.closePath();return b.fill()};z.prototype.drawLocation=function(a,b){if(null!=b.location){new R(config.imgSize.location);var c=this.getTileLocalPosInBiome(b,a);c=this.getTileBiomePos(c,!1);var d=b.location;if(b.ctxDirty||1>b.alpha||b.biome.ctxRedraw||debug.drawAllTiles)if(d.known||debug.drawAllLocations){if(null!=d.sprite)return this.drawSprite(d.sprite,
c.x,c.y,{ctx:a.ctx,screenScale:1,round:!1})}else if(d.showHint&&b.known)return a.ctx.globalAlpha=1,b=!n.isIO()||this.main.isWarping()||null!=this.main.tutorial||null!=a.claim?"res_fxt_questionmark.png":"res_fxt_questionmark_undiscovered.png",this.drawSprite(b,c.x,c.y,{ctx:a.ctx,screenScale:1,round:!1})}};z.prototype.drawTileZoneIcon=function(a,b,c){if(!this.pureMode&&null!=b){var d=3*this.timeTotal;if(b.seeking){var e=5.5*Math.sin(3*d);var f=5.5*Math.cos(2*d)}else e=2.5*Math.sin(d),f=2.5*Math.cos(d);
this.ctx.globalAlpha=b.showOutline?config.zone.imgAlpha:.7;d=0;this.action_highlight===b&&(d=this.selectedMarkerTween(this.timeTotal-this.markedTime),f=e=0);if(null!=b.sprite){var g=this.biomeScaleFactor*(1-b.deadTime);this.drawSprite(b.sprite,c.x+e,c.y+f+d,{scale:g,halign:"center",valign:"center"})}if(0<b.inactiveTurns)return this.tickParticleEmitter(a,config.inactiveZoneParticle,b,b.center)}};z.prototype.drawTileStampPreview=function(a){var b;var c=0;for(b=a.length;c<b;c++){var d=a[c];if(d.known){var e=
this.getTileScreenPos(d.pos);d=this.img.tileStampPreview;this.ctx.drawImage(d,0,0,d.width,d.height,e.x,e.y,this.biomeScreenSize.w,this.biomeScreenSize.h)}}};z.prototype.drawTileZoneName=function(a){if(null!=a.center&&null!=a.name){var b=this.getTileScreenPos(a.center,!0,!0,!0);this.ctx.font="20px Curious";this.ctx.globalAlpha=.5;var c=a.name;a=this.ctx.measureText(c);this.ctx.fillStyle="black";this.ctx.fillText(c,b.x-a.width/2+2,b.y+2);this.ctx.fillStyle="white";return this.ctx.fillText(c,b.x-a.width/
2,b.y)}};z.prototype.drawTileTotalViewCost=function(a,b,c){if(debug.showViewCost){b=b.ctx;b.globalAlpha=1;b.fillStyle="white";var d=""+(a.totalViewCost||-1).format(2);b.font="12px sans-serif";var e=b.measureText(d);e=c.x+this.blockSize.w/2-e.width/2;var f=c.y+this.blockSize.h/2;b.fillText(d,e,f);if(1<a.elevation&&null!=a.localTotalViewCost)return d=""+a.localTotalViewCost.format(2),b.font="8px sans-serif",e=b.measureText(d),e=c.x+this.blockSize.w/2-e.width/2,f=c.y+this.blockSize.h/2+10,b.fillText(d,
e,f)}};z.prototype.drawTileHints=function(a){if(debug.showTriangulationCapture&&null!=a.captured&&a.captured){var b=this.getTileScreenPos(a.pos);this.ctx.globalAlpha=1;this.ctx.fillStyle="red";this.ctx.beginPath();this.ctx.arc(b.x+this.biomeScreenSize.w/2,b.y+this.biomeScreenSize.h/2,4,0,2*Math.PI,!1);this.ctx.closePath();this.ctx.fill()}if(null!=a.hintDist&&a.hintDist)return b=this.getTileScreenPos(a.pos),this.ctx.globalAlpha=1,this.ctx.fillStyle="#002BFF",this.ctx.beginPath(),this.ctx.arc(b.x+this.biomeScreenSize.w/
2,b.y+this.biomeScreenSize.h/2,3,0,2*Math.PI,!1),this.ctx.closePath(),this.ctx.fill()};z.prototype.drawPunch=function(a,b,c,d){c=$jscomp.makeIterator(this.getCanvasSize());b=c.next().value;c=c.next().value;var e=$jscomp.makeIterator([200*this.s,60*this.s]);var f=e.next().value;e=e.next().value;this.ctx.globalAlpha=1;this.ctx.fillStyle="white";var g={halign:"center",font:config.fonts.technicalLarge,fillColor:"black",shadowColor:"gray",os:this.s};this.drawPanel(config.panel.infoSimple,b/2-f/2,c-125*
this.s,f,e);this.drawText(a,b/2,c-100*this.s,g);if(!d)return g.font=config.fonts.technicalSmall,this.drawText(q.toText("txt-base-outOfRange"),b/2,c-80*this.s,g)};z.prototype.drawPathFinderDebug=function(a){var b=this,c;var d=function(a,c,d){var e=b.getTileScreenPos(a.pos);a=a.g+"|"+a.h;var f=b.ctx.measureText(a);f=e.x+b.biomeScreenSize.w/2-f.width/2;e=e.y+b.biomeScreenSize.h/2;b.ctx.fillStyle=c;return b.ctx.fillText(a,f+d,e+d)};this.ctx.font="14px sans-serif";var e=a.closedNodes;for(c in e){var f=
e[c];d(f,"white",1)}e=a.openNodes;for(c in e)f=e[c],d(f,"orange",-1);a.openNodeList.isEmpty()||d(a.openNodeList[0],"red",-1);a=a.pos2;if(null!=a)return a=this.getTileScreenPos(a),d=this.ctx.measureText("!!"),d=a.x+this.biomeScreenSize.w/2-d.width/2,a=a.y+this.biomeScreenSize.h/2,this.ctx.fillStyle="red",this.ctx.fillText("!!",d,a)};z.prototype.drawCross=function(a,b,c){c=void 0===c?10:c;this.ctx.save();this.ctx.beginPath();this.ctx.globalAlpha=1;this.ctx.lineWidth=1;this.ctx.strokeStyle="yellow";
this.ctx.moveTo(a-c,b);this.ctx.lineTo(a+c,b);this.ctx.moveTo(a,b-c);this.ctx.lineTo(a,b+c);this.ctx.stroke();return this.ctx.restore()};z.prototype.drawCoordLines=function(){var a=$jscomp.makeIterator(this.getCanvasSize());var b=a.next().value;a=a.next().value;this.ctx.strokeStyle="yellow";this.ctx.globalAlpha=1;this.ctx.beginPath();this.ctx.lineWidth=1;this.ctx.moveTo(b/2,0);this.ctx.lineTo(b/2,a);this.ctx.moveTo(0,a/2);this.ctx.lineTo(b,a/2);return this.ctx.stroke()};z.prototype.drawItem=function(a,
b,c,d){b=void 0===b?0:b;c=void 0===c?0:c;d=void 0===d?{}:d;var e,f,g;var h={amount:a.amount,showDecorator:!0,showCount:!0,scale:1,fillColor:"white",shadowColor:"black",showDowsing:!1,showChange:!1,os:this.s};Object.merge(h,d);if(0===h.amount||0>=h.scale)return!1;var k=h.scale;var l=h.silhouette;var m=$jscomp.makeIterator([config.imgSize.item[0]*this.s,config.imgSize.item[1]*this.s]);d=m.next().value;m=m.next().value;var p=a.maxChargeTime-a.chargeTime;var w=null!=(f=null!=(g=a.sprite)?g:a.sprite)?
f:"it_misc_placeholder.png";f=b;g=c;h.showDowsing&&(f+=Number.random(-a.dowsingPower/2,a.dowsingPower/2),g+=Number.random(-a.dowsingPower/2,a.dowsingPower/2));this.hitBox(b,c,d,m,0,0);this.drawSprite(w,f+d/2,g+m/2,{halign:"center",valign:"center",scale:k,silhouette:l});if(h.showDecorator){if(0<a.fame||0<(null!=(e=a.subItems)?e.length:void 0))e=new R(config.inventory.fameIconOffset),this.drawSprite("hud_fame_small.png",b+e.w*this.s,c+e.h*this.s);a.noWeight&&(e=new R(config.inventory.noWeightIconOffset),
this.drawSprite("hud_weightless.png",b+e.w*this.s,c+e.h*this.s))}h.showChange&&null!=a.changeTime&&(a=2*a.changeTime,0<a&&1>a&&(this.ctx.globalAlpha=1.2-a,this.drawSprite(w,f,g-40*a,{scale:k,silhouette:l}),this.ctx.globalAlpha=1));h.showDecorator&&0<p&&(this.ctx.font="40px sans-serif",a=this.ctx.measureText(p),this.ctx.fillStyle="black",this.ctx.fillText(p,b+d/2-a.width/2+this.s,c+.75*m+this.s),this.ctx.fillStyle="#3DFFE9",this.ctx.fillText(p,b+d/2-a.width/2,c+.75*m));h.showCount&&1<h.amount&&(p=
new u(20*this.s,20*this.s),this.ctx.font=config.fonts.technicalLarge,a=this.ctx.measureText(h.amount),this.ctx.fillStyle=h.shadowColor,this.ctx.fillText(h.amount,b+p.x-a.width,c+p.y),this.ctx.fillStyle=h.fillColor,this.ctx.fillText(h.amount,b+p.x+h.os-a.width,c+p.y+h.os));return null!=h.mX&&null!=h.mY&&this.hitBox(b,c,d*k,m*k,h.mX,h.mY)};z.prototype.mouseToItemSlot=function(a,b,c,d){d=void 0===d?config.inventory.slotCount:d;var e=config.inventory.slotSize*this.s;return Math.floor((c-a.h)/e)*d+Math.floor((b-
a.w)/e)};z.prototype.charPortraitPos=function(a,b,c){var d=$jscomp.makeIterator(this.getCanvasSize());var e=d.next().value;d=d.next().value;var f=this.img.getSprite("hud_unit_background_1.png");var g=$jscomp.makeIterator(f.dSize.lst());f=g.next().value;g=g.next().value;b=Math.max(c,b);b=Math.min(config.uiMaxUnitCount,b);return 0>a||a>=config.uiMaxUnitCount?null:new u(e-f,d/2-g*b/2+12*this.s+g*a)};z.prototype.mouseToPortrait=function(a,b,c){var d,e;var f=$jscomp.makeIterator(this.getCanvasSize());
f.next();f.next();f=this.img.getSprite("hud_unit_background_1.png");var g=$jscomp.makeIterator(f.dSize.lst());f=g.next().value;var h=g.next().value;var k=a.persons.slice(this.partyOffset);var l=e=0;for(d=k.length;e<d;l=++e)if(g=k[l],l=this.charPortraitPos(l,a.persons.length,a.maxUnitCount),null!=l&&this.hitBox(l.x,l.y,f,h,b,c))return g;return null};z.prototype.drawParty=function(a,b,c,d,e,f){var g,h,k;if(!this.pureMode){var l=$jscomp.makeIterator(this.getCanvasSize());var m=l.next().value;l=l.next().value;
var p=this.img.getSprite("hud_unit_background_1.png");var w=$jscomp.makeIterator(p.dSize.lst());var da=w.next().value;var D=w.next().value;w=null;var v=120*this.hudAlpha();this.ctx.globalAlpha=1;var y=J.clamp(b.persons.length-this.partyOffset,b.maxUnitCount-this.partyOffset,config.uiMaxUnitCount);var r=function(){switch(a){case 0:return"hud_border_1_easy.png";case 2:return n.isChina()?"hud_border_1.png":"hud_border_1_hard.png";default:return"hud_border_1.png"}}();for(k=-1;k<l;)this.drawSprite(r,m-
35*this.s+v,k),k+=50*this.s;this.showStatusInfo=null;r={halign:"center",valign:"bottom"};for(g=k=0;0<=y?k<y:k>y;g=0<=y?++k:--k)if(v=b.persons[g+this.partyOffset],g=this.charPortraitPos(g,b.persons.length,b.maxUnitCount),null!=g){var A=$jscomp.makeIterator([g.x+da/2,g.y+D]);g=A.next().value;A=A.next().value;this.drawSprite(p,g,A,r);if(null!=v){var H=null!=c.chatLine&&c.chatLine.person===v;var G=0;H&&1.2>c.chatTime&&.2>c.chatTime%.4&&(G+=1*this.s);0<G&&(this.ctx.save(),this.ctx.beginPath(),this.ctx.rect(g-
15*this.s,A-45*this.s,30*this.s,40*this.s),this.ctx.clip());this.drawPortrait(v,g,A-5*this.s+G,r);0<G&&this.ctx.restore();if(0<v.level){G=v.level;for(h=A-38*this.s;G>config.xp.maxLevelSprite;)this.drawSprite("hud_unit_rank_"+config.xp.maxLevelSprite+".png",g,h,r),G-=config.xp.maxLevelSprite,h-=8*this.s;this.drawSprite("hud_unit_rank_"+G+".png",g,h,r)}null!=v.mounted&&(this.ctx.font=config.fonts.themedSmall,this.drawText(q.toText("txt-base-mounted"),g,A-38*this.s,r));d&&!H&&(H=this.drawCharacterInfoStatusesShort(v,
g-35*this.s,A-25*this.s,e,f),null==this.showStatusInfo&&(this.showStatusInfo=H));b.canLevelUp(v)&&this.drawSprite("hud_levelUp.png",g+13*this.s,A-4*this.s,r);H=0<v.queuedHealthParticles?"pt-healthAdd":0>v.queuedHealthParticles?"pt-healthRemove":void 0;null!=H&&(H=t.getParticle(H),this.part.addParticleConf(H,new u(g,A),{count:Math.abs(v.queuedHealthParticles)}),v.queuedHealthParticles=0)}A+=D}Math.max(b.maxUnitCount,b.persons.length)>config.uiMaxUnitCount&&this.drawSprite("hud_button_unitScroll.png",
m-17*this.s,l-26*this.s,{mX:e,mY:f,halign:"center"})&&(w={id:"partyTab"});null!=this.showStatusInfo&&this.drawStatusInfo(e-50*this.s,f+25*this.s,this.showStatusInfo.status,this.showStatusInfo.owned,this.showStatusInfo.person);return w}};z.prototype.tickParticleEmitter=function(a,b,c,d){var e;if(null!=b&&0!==b.length){if(null==c.particleTime||c.particle!==(null!=(e=c.particleProto)?e.id:void 0))b=t.getParticle(b),c.particleProto=b,c.particleTime=J.rand(0,b.timer[1]);c.particleTime-=a;0>c.particleTime&&
(a=this.part.getParticlePositionForTilePos(c.particleProto,d),c.particleTime=J.randA(c.particleProto.timer),this.part.addParticleConf(c.particleProto,a))}};z.prototype.hexOffsetBiome=function(a){return 1===Math.abs(a%2)?this.blockSize.h/2:0};z.prototype.getTileBiomePos=function(a,b,c){b=void 0===b?!0:b;c=void 0===c?!1:c;var d=this.blockSize.w-this.blockOffset.w;var e=this.blockSize.h-this.blockOffset.h;d*=a.x;a=a.y*e+this.hexOffsetBiome(a.x);b&&(d+=this.mapOffset.w,a+=this.mapOffset.h);c&&(d+=this.blockSize.w/
2,a+=this.blockSize.h/2);return new u(d,a)};z.prototype.hexOffset=function(a){return 1===Math.abs(a%2)?this.biomeScreenSize.h/2:0};z.prototype.getTileScreenPos=function(a,b,c,d){b=void 0===b?!0:b;c=void 0===c?!0:c;d=void 0===d?!1:d;var e=this.biomeScreenSize.w-this.biomeScreenOffset.w;var f=this.biomeScreenSize.h-this.biomeScreenOffset.h;e*=a.x;a=a.y*f+this.hexOffset(a.x);b&&(e+=this.cam.scroll.x,a+=this.cam.scroll.y);c&&(e+=this.mapOffset.w,a+=this.mapOffset.h);d&&(e+=this.biomeScreenSize.w/2,a+=
this.biomeScreenSize.h/2);return new u(e,a)};z.prototype.drawPartyIndicator=function(a,b,c){var d=$jscomp.makeIterator(this.getCanvasSize());var e=d.next().value;d=d.next().value;var f=this.getTileScreenPos(a,!0,!0,!0);a=new u(f.x,f.y);a.x=a.x.clamp(config.board.partyIndicatorZoomSafeZone[0]*this.s,e-config.board.partyIndicatorZoomSafeZone[1]*this.s);a.y=a.y.clamp(this.oY+config.board.partyIndicatorZoomSafeZone[2]*this.s,d-config.board.partyIndicatorZoomSafeZone[3]*this.s);if(this.zoomLevel>config.board.partyIndicatorZoomThreshold&&
f.eq(a))this.currAngle=null;else{e=this.img.getSprite("hud_io_playerPos_zoomMap.png");var g=f.sub(a);var h=a.eq(f)?0:Math.atan2(g.y,g.x)-Math.PI/2;null==this.currAngle&&(this.currAngle=h);h!==this.currAngle&&(d=h-this.currAngle,d<-Math.PI/2&&(h+=2*Math.PI,d=h-this.currAngle),d>Math.PI/2&&(h-=2*Math.PI,d=h-this.currAngle),d=0<d?Math.min(this.timeDelta*config.board.partyIndicatorRotationSpeed,d):Math.max(-this.timeDelta*config.board.partyIndicatorRotationSpeed,d),this.currAngle+=d);h=$jscomp.makeIterator([e.dSize.w/
2,e.dSize.h]);d=h.next().value;var k=h.next().value;null==this.timeUntilAnim&&(this.timeUntilAnim=config.board.partyIndicatorAnimDelay);null==this.currPartyIndicatorOffset&&(this.currPartyIndicatorOffset=0);this.timeUntilAnim-=this.timeDelta;0>=this.timeUntilAnim&&(this.timeUntilAnim=config.board.partyIndicatorAnimDelay,this.currPartyIndicatorOffset=0===this.currPartyIndicatorOffset?1:0);var l=this.currPartyIndicatorOffset*this.s;h=!1;if(!a.eq(f)){f=g.normal().mul(.5*e.dSize.h);g=a.sub(f);var m=new u(.5*
e.dSize.h,.5*e.dSize.h);f=g.sub(m);var p=g.add(m);m=f.x;var w=f.y;g=p.x-f.x;f=p.y-f.y;this.hitBox(m,w,g,f,b,c)&&(l=-2*this.s,h=!0)}k+=l;this.ctx.save();this.ctx.translate(a.x,a.y);this.ctx.rotate(this.currAngle);this.ctx.drawImage(e.img,0,0,e.size.w,e.size.h,-d,-k,e.dSize.w,e.dSize.h);this.ctx.restore();return h}};z.prototype.drawPartyArrow=function(a){var b=this.getTileScreenPos(a,!0,!0,!0);var c=this.img.partyTileHidden;var d=config.anim.partyArrowFrames;a=Math.round(this.timeTotal*config.anim.partyAnimSpeed)%
d;var e=$jscomp.makeIterator([c.width,c.height/d]);d=e.next().value;var f=e.next().value;var g=$jscomp.makeIterator([.5*this.s*d*this.biomeScaleFactor,.5*this.s*f*this.biomeScaleFactor]);e=g.next().value;g=g.next().value;return this.ctx.drawImage(c,0,a*f,d,f,b.x-e/2,b.y-g/2,e,g)};z.prototype.drawMiniParty=function(a,b,c,d,e){var f,g;var h=0;var k=Sa.s.val;this.ctx.globalAlpha=void 0===e?1:e;var l=this.getTileScreenPos(a,!0,!0,!0);var m=$jscomp.makeIterator(d(a));e=m.next().value;var p=m.next().value;
var w=m.next().value;var n=config.anim.partyAnimSpeed;m=config.anim.partyAnimFrames;var q=$jscomp.makeIterator([0,0]);w=q.next().value;var v=q.next().value;var y=g=q=0;for(f=c.length;g<f;y=++g){var t=c[y];p=$jscomp.makeIterator(b.getAnimPos(q));var r=p.next().value;var H=p.next().value;var G=p.next().value;h=p.next().value;q+=.25;if(null!=G){var V=$jscomp.makeIterator(d(H,G,h));e=V.next().value;p=V.next().value;w=V.next().value;V=H.getDir(G).abbr;if(e)continue;p=p?-10*this.s:0;w=w?-10*this.s:0;p+=
(w-p)*h;l=this.getTileScreenPos(H,!0,!0,!0);v=this.getTileScreenPos(G,!0,!0,!0);w=h*(v.x-l.x);v=h*(v.y-l.y);if(0<h){var T=Math.max(Math.abs(w),Math.abs(v));l.x+=w+v/T*Math.sin(32*this.timeTotal+10*y)*this.s;l.y+=v+w/T*Math.sin(32*this.timeTotal+10*y)*this.s}Math.abs(w)>Math.abs(v)?G.x<H.x?k=Sa.w.val:G.x>H.x&&(k=Sa.e.val):G.y<H.y?k=Sa.n.val:G.y>H.y&&(k=Sa.s.val)}else H=$jscomp.makeIterator(d(a)),H.next(),p=H.next().value,w=H.next().value,p=p?-10*this.s:0;if(!e)if(H=function(){switch(k){case Sa.n.val:return 0;
case Sa.e.val:return 1;case Sa.s.val:return 2;case Sa.w.val:return 3}}(),H*=m,H+=Math.floor(this.timeTotal*n)%m,h=null==G?1:0===r?Math.max(1-2*h,0):r===b.path.length-2?Math.min(2*h,1):r===b.path.length-1?1:0,"sledge"===t)null!=V&&this.drawSprite("res_spc_sledge_mini_"+V+".png",l.x,l.y,{scale:this.biomeScaleFactor,halign:"center"});else if(null!=t){var u=Object.isString(t)?this.img.getSprite(t):t;w=r=0;T=u.size.w;v=u.size.h/8;G=this.biomeScaleFactor*u.dSize.w;t=this.biomeScaleFactor*u.dSize.h/8;1<
c.length&&(r=G/2*Math.sin(y/c.length*2*Math.PI)*h,w=t/2*Math.cos(y/c.length*2*Math.PI)*h);this.ctx.drawImage(u.img,u.pos.x,u.pos.y+v*H,T,v,l.x-G/2+r,l.y-t/2+w+p,G,t)}else this.main.doSendError("undefined minisprite")}};z.prototype.hasCachedHexFieldRadius=function(a,b,c,d){var e=this.cachedHexFields;return null!=e&&e.radius===a&&e.zl===b&&e.col===c&&e.stripes===d};z.prototype.drawHexFieldRadius=function(a,b,c){c=void 0===c?{}:c;var d,e,f,g,h;var k=null!=(g=c.drawOnlyOutline)?g:!1;g=null!=(f=c.drawStripes)?
f:!1;f=null!=(d=c.color)?d:this.playerColor;c=null!=(e=c.alpha)?e:.35;if(!this.hasCachedHexFieldRadius(b,this.zoomLevel,f)){var l=1+2*b;var m=0<b?b/Math.floor(b):1;d=(new Na(0,0)).radius(b);e=document.createElement("canvas");e.width=m*(l*(this.biomeScreenSize.w-this.biomeScreenOffset.w)+this.biomeScreenOffset.w);e.height=m*(l*(this.biomeScreenSize.h-this.biomeScreenOffset.h)+this.biomeScreenOffset.h);l=e.getContext("2d");l.save();l.globalAlpha=1;l.translate(e.width/2,e.height/2);l.fillStyle=f;l.scale(m,
m);var p=0;for(h=d.length;p<h;p++)m=d[p],this.drawHexFieldHighlight(l,m,g);if(k){l.scale(.95,.95);l.globalCompositeOperation="destination-out";h=0;for(k=d.length;h<k;h++)m=d[h],this.drawHexFieldHighlight(l,m,g);l.globalCompositeOperation="source-over"}l.restore();this.cachedHexFields={radius:b,canvas:e,zl:this.zoomLevel,col:f,stripes:g}}b=this.getTileScreenPos(a);a=b.x+this.biomeScreenSize.w/2;b=b.y+this.biomeScreenSize.h/2;e=this.cachedHexFields.canvas;this.ctx.globalAlpha=c;this.ctx.drawImage(this.cachedHexFields.canvas,
a-e.width/2,b-e.height/2);return this.ctx.globalAlpha=1};z.prototype.drawHexFieldHighlight=function(a,b,c){if(void 0===c?0:c){c=document.createElement("canvas");c.width=7;c.height=7;var d=c.getContext("2d");d.lineWidth=4;d.strokeStyle="#C4250A";d.beginPath();d.moveTo(3,0);d.lineTo(3,10);d.stroke();c=d.createPattern(c,"repeat");a.fillStyle=c}c=b.x*(this.biomeScreenSize.w-this.biomeScreenOffset.w);b=b.y*(this.biomeScreenSize.h-this.biomeScreenOffset.h)-this.biomeScreenSize.h/2*b.x;a.save();a.beginPath();
a.moveTo(c-this.biomeScreenSize.w/2,b+0);a.lineTo(c-this.biomeScreenSize.w/2+this.biomeScreenOffset.w,b-this.biomeScreenSize.h/2);a.lineTo(c+this.biomeScreenSize.w/2-this.biomeScreenOffset.w+1,b-this.biomeScreenSize.h/2);a.lineTo(c+this.biomeScreenSize.w/2+1,b+0);a.lineTo(c+this.biomeScreenSize.w/2-this.biomeScreenOffset.w+1,b+this.biomeScreenSize.h/2+1);a.lineTo(c-this.biomeScreenSize.w/2+this.biomeScreenOffset.w,b+this.biomeScreenSize.h/2+1);a.closePath();a.rotate(45);a.fill();return a.restore()};
z.prototype.drawExtraButtons=function(a,b,c,d){if(!this.pureMode){var e=$jscomp.makeIterator(this.getCanvasSize());e.next();var f=e.next().value;this.ctx.globalAlpha=1;e=null;c={mX:c,mY:d};a=a-60*this.s*this.hudAlpha()+3;f-=25*this.s;this.drawSprite("hud_button_options.png",a,f,c)&&(e=q.toText(config.help.settings.button),e=[{text:""+e,col:config.colors.help}],d=this.main.modding.activeMods(),0<d.length&&n.isTCE()&&!n.isChina()&&(d="Enabled mods: \n "+d.map("id").join(" \n "),this.main.achievements.canUnlockAchievements()||
e.push({text:" \n Achievements disabled",col:config.colors.infoWarning}),e.push({text:" \n "+d,col:"white"})),b.setInfo(e),e={id:"settings"});f-=27*this.s;n.isDemo()||(this.drawSprite("hud_button_baloon.png",a,f,c)&&(b.setInfo([{text:config.help.balloon,col:config.colors.help}]),e={id:"balloon"}),f-=27*this.s);this.drawSprite("hud_button_wait.png",a,f,c)&&(c=[],0<this.main.party.tripCost&&(a=q.toText("txt-help-wait-sanity").replace("$val",this.main.party.tripCost),c.push({text:a})),c.push({text:config.help.wait,
col:config.colors.help}),b.setInfo(c),e={id:"wait"});return e}};z.prototype.markActionHighlight=function(a){null==a&&(this.action_highlight=null);if(null!=a&&(null!=a.location&&(this.action_highlight!==a.location&&(this.markedTime=this.timeTotal),this.action_highlight=a.location),null!=a.zone))return this.action_highlight!==a.zone&&(this.markedTime=this.timeTotal),this.action_highlight=a.zone};z.prototype.drawActionButtons=function(a,b,c,d,e,f){var g=this,h,k;if(b){b=null;this.ctx.globalAlpha=1;this.ctx.fillStyle=
"black";this.ctx.font=config.fonts.themedLarge;var l=$jscomp.makeIterator(this.getCanvasSize());var m=l.next().value;var p=l.next().value;l=function(){var a;var b=[];var d=0;for(a=c.length;d<a;d++)h=c[d],b.push({name:h,width:this.ctx.measureText(h).width});return b}.call(this);var w=l.sum(function(a){return a.width+20*g.s})+5*(l.length-1)*this.s;p=$jscomp.makeIterator([m/2-w/2,p-100*this.s]);m=p.next().value;var q=p.next().value;this.main.gameOver&&n.isIO()&&(q+=30*this.s);var D=k=0;for(w=l.length;k<
w;D=++k){p=l[D];this.ctx.fillStyle="black";var v=0;this.hitBox(m,q,p.width+20*this.s,30*this.s,d,e)&&(this.ctx.fillStyle="red",b=D,f&&(v=this.s));this.ctx.globalAlpha=(4*a).clamp(0,1);D=(50*(1-4*a)).clamp(0,50);this.drawPanel("mapButton",m,q+D+v,20*this.s+p.width,30*this.s);this.ctx.fillText(p.name,m+10*this.s,q+19*this.s+D+v);m+=p.width+25*this.s}return b}};z.prototype.drawPartyPath=function(a,b,c){c=void 0===c?{}:c;var d;var e={maxDist:0,items:[]};Object.merge(e,c);if(!b.isEmpty()&&!debug.hidePath){this.ctx.globalAlpha=
1;var f=!1;if(null!=a){var g=this.getTileScreenPos(a.pos);var h=a.pos;f=a.isBlocking()}var k=d=0;for(a=b.length;d<a;k=++d){var l=b[k];if(null==l)return;c=l.isBlocking();var m=this.getTileScreenPos(l.pos);var p=e.items[k];if(!c||!f){var w=0;var n=$jscomp.makeIterator(config.imgSize.path);f=n.next().value;n=n.next().value;var q=config.previewPathPulse;k===Math.floor(this.timeTotal/q%b.length)&&(w+=1);null!=g&&(h=h.getDir(l.pos),0<h.val&&(k>=e.maxDist&&(w+=2),k=.5*this.biomeScaleFactor,this.ctx.drawImage(this.img.path,
f*(h.val-1),w*n,f,n,g.x-12*k*this.s,g.y-8*k*this.s,this.s*k*f,this.s*k*n)));null!=p&&(g=function(){switch(p){case "it-machete":return"hud_travelItem_machete.png";case "it-rope":return"hud_travelItem_rope.png";case "it-climbingGear":return"hud_travelItem_climbingGear.png";case "it-water":return"hud_travelItem_water.png";case "it-snowshoe":return"hud_travelItem_snowShoes.png"}}(),null!=g&&this.drawSprite(g,m.x+this.biomeScaleFactor*this.s*8,m.y+this.biomeScaleFactor*this.s*6,{scale:this.biomeScaleFactor}))}h=
l.pos;f=c;g=m}if(null==p)return f=this.img.destination.width,g=f*this.biomeScaleFactor*this.s*.5,b=null==e.maxDist||b.length<=e.maxDist,this.ctx.drawImage(this.img.destination,0,(b?0:1)*f,f,f,m.x+this.biomeScreenSize.w/2-g/2,m.y+this.biomeScreenSize.h/2-g/2,g,g)}};z.prototype.drawPathCost=function(a,b,c){var d,e;a=this.getTileScreenPos(a);this.ctx.font=config.fonts.technicalLarge;c=null!=c?c:[];if(b)var f=config.colors.path;else f=config.colors.warning,a.x+=Number.random(-1,1);b=e=0;for(d=c.length;e<
d;b=++e){var g=c[b];this.drawText(g,a.x+.75*this.biomeScreenSize.w,a.y+.75*this.biomeScreenSize.h-20*c.length+10*b*this.s,{fillColor:f,os:this.s})}};z.prototype.resetZoom=function(a){this.zoomTarget=this.zoomLevel=a=void 0===a?0:a;this.updateBlockSize()};z.prototype.zoomIn=function(){var a,b,c,d,e,f;if(this.main.showingBiomes){if(null!=this.mouseBiomeDict){var g=$jscomp.makeIterator(config.board.biomeSize);var h=g.next().value;g=g.next().value;g=new u(this.mouseBiomeDict.pos.x*h,this.mouseBiomeDict.pos.y*
g);h=this.main.world.toBiomePos(g);var k=e=a=h.x-2;for(b=h.x+2;a<=b?e<b:e>b;k=a<=b?++e:--e){var l=f=c=h.y-2;for(d=h.y+2;c<=d?f<d:f>d;l=c<=d?++f:--f)this.main.worldGenIO.generateBiome(new u(k,l),!0)}this.main.exped.placeParty(g)}this.main.showingBiomes=!1}else this.zoomTarget<config.board.maxZoom[0]&&this.adjustZoomTarget(1)};z.prototype.zoomOut=function(){var a=n.isIO()&&null==this.main.tutorial&&!this.main.isWarping()?config.board.maxZoomIO[1]:config.board.maxZoom[1];this.zoomTarget>a&&this.adjustZoomTarget(-1)};
z.prototype.mouseToTilePos_float=function(a,b){a-=this.cam.scroll.x-this.mapOffset.w;b-=this.cam.scroll.y-this.mapOffset.h;a/=this.biomeScreenSize.w-this.biomeScreenOffset.w;b=(b-this.hexOffset(a))/this.biomeScreenSize.h;return new u(a,b)};z.prototype.adjustZoomTarget=function(a){this.cam.resetScroll();if(this.zoomTarget!==this.zoomLevel){var b=this.zoomTarget-this.prevZoom;this.zoomTarget+=a;a=this.zoomTarget-this.prevZoom;0<a&&(this.zoomBlendTime*=b/a)}else this.prevZoom=this.zoomLevel,this.zoomTarget=
this.zoomLevel+a,this.zoomBlendTime=0,this.zoomMousePos=this.main.mousePos,this.zoomMouseTile=this.mouseToTilePos_float(this.zoomMousePos.x,this.zoomMousePos.y)};z.prototype.adjustZoom=function(a){this.zoomLevel+=a;this.updateBlockSize();this.cam.centerOnPos(this.cam.screenCenterPos);var b=this.mouseToTilePos_float(this.zoomMousePos.x,this.zoomMousePos.y);for(a=0;.01<b.sub(this.zoomMouseTile).length()&&10>a;){a+=1;b=this.zoomMouseTile.sub(b);var c=this.cam.screenCenterPos.add(b);b=this.main.world.biomeCount.w*
config.board.biomeSize[0]-1;var d=this.main.world.biomeCount.h*config.board.biomeSize[1]-1;if(0>c.x){c.x=0;var e=!0}else c.x>b&&(c.x=b,e=!0);0>c.y?(c.y=0,e=!0):c.y>d&&(c.y=d,e=!0);this.cam.centerOnPos(c);if(e)break;b=this.mouseToTilePos_float(this.zoomMousePos.x,this.zoomMousePos.y)}};z.prototype.tickZoom=function(a){if(null!=this.zoomTarget&&this.zoomTarget!==this.zoomLevel){this.zoomBlendTime+=a;a=J.clamp(this.zoomBlendTime/config.board.zoomTime,0,1);a=TWEEN.Easing.Quadratic.InOut(a);var b=J.lerp(this.prevZoom,
this.zoomTarget,Math.min(1,a));b-=this.zoomLevel;this.adjustZoom(b);if(1<=a)return this.zoomTarget=this.zoomLevel}};z.prototype.updateBlockSize=function(){this.biomeScaleFactor=Math.pow(.5,-this.zoomLevel);this.biomeScreenSize.w=this.blockSize.w*this.biomeScaleFactor*this.s;this.biomeScreenSize.h=this.blockSize.h*this.biomeScaleFactor*this.s;this.biomeScreenOffset.w=this.blockOffset.w*this.biomeScaleFactor*this.s;if(0<this.zoomLevel||-1>this.zoomLevel)return this.biomeScreenOffset.w+=2*this.s,this.biomeScreenSize.w+=
2*this.s};z.prototype.enableMouseMoveCursor=function(a){a=this.main.customCursor?n.isIO()&&this.main.ioNewGame.isSelectingHoldCrate?config.cursor.purchase:a?config.cursor.move:config.cursor.standard:"default";return $(window.getDstCanvas()).css("cursor",a)};z.prototype.drawHexOutline=function(a,b,c,d,e,f){d=void 0===d?1:d;e=void 0===e?!0:e;f=void 0===f?1:f;var g;if(!this.pureMode&&null!=c){a.save();a.globalAlpha=d;a.beginPath();a.strokeStyle=c;a.lineWidth=(3+this.zoomLevel)*f;a.lineJoin="round";a.lineCap=
"round";var h=b.tiles;c=g=0;for(f=h.length;g<f;c=++g)d=h[c],(d.known||debug.drawAllTiles)&&this.moveHexLine(a,d.pos,b.edges[c]);a.stroke();if(e)for(f=b.tiles,c=h=0,b=f.length;h<b;c=++h)d=f[c],(d.known||debug.drawAllTiles)&&this.drawHexFieldRadius(d.pos,0,{drawStripes:e,alpha:.15,color:this.playerColor});return a.restore()}};z.prototype.moveHexLine=function(a,b,c,d){d=void 0===d?!1:d;var e;var f=function(b,c,d,e){a.moveTo(b,c);return a.lineTo(d,e)};b=this.getTileScreenPos(b);if(!(0>b.x||b.x>a.canvas.width||
0>b.y||b.y>a.canvas.height)){var g=$jscomp.makeIterator([b.x,b.y]);b=g.next().value;g=g.next().value;b+=this.biomeScreenSize.w/2;g+=this.biomeScreenSize.h/2;var h=d?6:0;c=t.arrify(c);var k=0;for(e=c.length;k<e;k++)d=c[k],d.val===K.n.val?f(b-this.biomeScreenSize.w/2+this.biomeScreenOffset.w,h+g-this.biomeScreenSize.h/2,b+this.biomeScreenSize.w/2-this.biomeScreenOffset.w+1,h+g-this.biomeScreenSize.h/2):d.val===K.ne.val?f(-h/2+b+this.biomeScreenSize.w/2-this.biomeScreenOffset.w+1,h+g-this.biomeScreenSize.h/
2,-h/2+b+this.biomeScreenSize.w/2+1,h/2+g+0):d.val===K.se.val?f(b+this.biomeScreenSize.w/2+1,g+0,b+this.biomeScreenSize.w/2-this.biomeScreenOffset.w+1,g+this.biomeScreenSize.h/2+1):d.val===K.s.val?f(b+this.biomeScreenSize.w/2-this.biomeScreenOffset.w+1,g+this.biomeScreenSize.h/2+1,b-this.biomeScreenSize.w/2+this.biomeScreenOffset.w,g+this.biomeScreenSize.h/2+1):d.val===K.sw.val?f(b-this.biomeScreenSize.w/2+this.biomeScreenOffset.w,g+this.biomeScreenSize.h/2+1,b-this.biomeScreenSize.w/2,g+0):d.val===
K.nw.val&&f(h/2+b-this.biomeScreenSize.w/2,h+g+0,h/2+b-this.biomeScreenSize.w/2+this.biomeScreenOffset.w,h/2+g-this.biomeScreenSize.h/2)}};z.prototype.drawPortrait=function(a,b,c,d){var e,f,g;var h={halign:"center",valign:"bottom",small:!1,statue:!1};Object.merge(h,d);"function"===typeof a.updateSprite&&a.updateSprite(this.tribeGen);d=null!=(e=a.portrait)?e:a.variations[0].portrait;h.statue&&this.img.hasSprite(a.variations[0].portrait.replace(".png","")+"_end.png")?d=a.variations[0].portrait.replace(".png",
"")+"_end.png":h.small&&(null!=(null!=(f=a.portraitSmall)?f.img:void 0)||this.img.hasSprite(a.portraitSmall)?d=a.portraitSmall:null!=(null!=(g=a.variations[0])?g.portrait:void 0)&&this.img.hasSprite(a.variations[0].portrait.replace(".png","")+"_small.png")&&(d=a.variations[0].portrait.replace(".png","")+"_small.png"));return null!=d?this.drawSprite(d,b,c,h):null!=this.drawCharacter(this.ctx,a,b,c,h)};z.prototype.drawWrappedText=function(a,b,c,d,e){e=void 0===e?{}:e;var f={ctx:this.ctx};Object.merge(f,
e);null!=f.font&&(f.ctx.font=f.font);var g=q.wrap(a,d,f.ctx);this.ctx.font.includes("Mallanna");a=Math.round(parseInt(this.ctx.font));d=c;c+=a;var h=0;for(e=g.length;h<e;h++){var k=g[h];this.drawText(k,b,c,f);c+=a}return c-d-a};z.prototype.drawText=function(a,b,c,d){d=void 0===d?{}:d;var e={halign:"",fillColor:"white",shadowColor:"black",os:1,ctx:this.ctx};Object.merge(e,d);null!=e.font&&(e.ctx.font=e.font);"center"===e.halign?(d=e.ctx.measureText(a),b-=d.width/2):"right"===e.halign&&(d=e.ctx.measureText(a),
b-=d.width);b=Math.floor(b);c=Math.floor(c);0<e.os&&(e.ctx.fillStyle=e.shadowColor,e.ctx.fillText(a,b+e.os,c+e.os),null!=this.main.numTextDraw&&(this.main.numTextDraw+=1));e.ctx.fillStyle=e.fillColor;e.ctx.fillText(a,b,c);if(null!=this.main.numTextDraw)return this.main.numTextDraw+=1};z.prototype.drawBitmapText=function(a,b,c,d){d=void 0===d?{}:d;var e,f;var g={font:"curious"};Object.merge(g,d);d=t.getFont(g.font);g=this.img.getImg(d.imgSrc);var h=null!=(f=d.scale)?f:2;var k=$jscomp.makeIterator([0,
0]);f=k.next().value;var l=k.next().value;var m=$jscomp.makeIterator([Math.floor(b),Math.floor(c)]);k=m.next().value;m=m.next().value;var p=$jscomp.makeIterator(d.atlasSize);var w=p.next().value;var n=p.next().value;var q=$jscomp.makeIterator([w*h,n*h]);p=q.next().value;q=q.next().value;var v=0;for(e=a.length;v<e;v++){var y=a[v];if(" "===y)k+=d.spaceWidth,f+=d.spaceWidth;else{var r=d.chars.findIndex(function(a){return a["char"]===y});if(-1<r){var A=d.chars[r];l=r%d.columns;r=Math.floor(r/d.columns);
(0<b||0<c)&&this.ctx.drawImage(g,l*w,r*n,w,n,k,m,p,q);l=A.width*h;k+=l;f+=l}}l=q}return{width:f,height:l}};z.prototype.drawActionPanel=function(a,b,c,d,e,f,g,h,k){k=void 0===k?!1:k;(g=this.hitBox(b,c,d,e,g,h))&&k&&(c+=2);this.drawPanel("action",b,c,d,e);g&&(f=config.colors.diaryActionActive);this.drawText(a,b+d/2,c+.65*e,{halign:"center",fillColor:f});return g};z.prototype.drawChatPanel=function(a,b,c,d){var e=this;d=void 0===d?{}:d;var f,g;var h=$jscomp.makeIterator(this.getCanvasSize());var k=h.next().value;
h.next();var l={width:0,halign:"left",valign:"top",lineCount:null,shrinkWidth:!0};Object.merge(l,d);this.ctx.font=config.fonts.themedSmall;if(0===l.width)l.width=this.ctx.measureText(a).width+20*this.s,h=[a];else{h=[];var m=t.arrify(a,!1);var p=0;for(a=m.length;p<a;p++){var w=m[p];0<h.length&&h.push("");h.add(q.wrap(w,l.width-20*this.s,this.ctx))}l.shrinkWidth&&(l.width=h.map(function(a){return e.ctx.measureText(a).width+20*e.s}).max())}a=(15+10*(null!=(g=l.lineCount)?g:h.length))*this.s;(m="narrator"===
this.main.getMainState())?g=config.panel.chat:(g=config.panel.chatSmall,a-=6*this.s,c-=6*this.s,l.width-=12*this.s);l.width=Math.ceil(l.width);"center"===l.halign&&(b-=l.width/2);"bottom"===l.valign&&(c=c-a-15*this.s);m?(m="hud_chat_bubble_arrow.png",w=c+a-20,p=c+15*this.s):(c+=12*this.s,m="hud_chat_bubble_small_arrow_down.png",w=c+a-2*this.s,p=c+11*this.s);k=J.clamp(b,0,k-l.width);this.drawPanel(g,k,c,l.width,a);this.drawSprite(m,b+l.width/2,w,{halign:"center"});c=p;b=null!=(f=d.halign)?f:"center";
l="center"===b?k+l.width/2:k+10*this.s;k=0;for(f=h.length;k<f;k++)d=h[k],this.drawText(d,l,c,{fillColor:"black",os:0,halign:b}),c+=10*this.s};z.prototype.drawPanel=function(a,b,c,d,e){var f;n.assert(null!=a);Object.isString(a)&&(a=config.panel[a]);if(null!=a.img){var g=this.img.getImg(a.img);var h=$jscomp.makeIterator([0,0]);var k=h.next().value;h=h.next().value;var l=$jscomp.makeIterator([g.width,g.height]);var m=l.next().value;l=l.next().value}else m=this.img.getSprite(a.sprite),g=m.img,h=$jscomp.makeIterator([m.pos.x,
m.pos.y]),k=h.next().value,h=h.next().value,l=$jscomp.makeIterator(m.size.lst()),m=l.next().value,l=l.next().value;var p=null!=(f=a.scale)?f:1;p*=this.s;a=a.offset;f=a*p;b=Math.floor(b);c=Math.floor(c);this.ctx.drawImage(g,k,h,a,a,b,c,f,f);this.ctx.drawImage(g,k+m-a,h,a,a,b+d-f,c,f,f);this.ctx.drawImage(g,k,h+l-a,a,a,b,c+e-f,f,f);this.ctx.drawImage(g,k+m-a,h+l-a,a,a,b+d-f,c+e-f,f,f);this.ctx.drawImage(g,k+a+1,h,m-2*a-2,a,b+f,c,d-2*f,f);this.ctx.drawImage(g,k+a+1,h+l-a,m-2*a-2,a,b+f,c+e-f,d-2*f,f);
if(0<e-2*f)return this.ctx.drawImage(g,k,h+a+1,a,l-2*a-2,b,c+f,f,e-2*f),this.ctx.drawImage(g,k+m-a,h+a+1,a,l-2*a-2,b+d-f,c+f,f,e-2*f),this.ctx.drawImage(g,k+a,h+a,a,a,b+f,c+f,d-2*f,e-2*f)};z.prototype.drawTutorialArrow=function(a,b,c,d,e){var f=this.img.getSprite("hud_io_bigArrow_tip.png");var g=e-f.dSize.w;e=f.dSize.h;this.ctx.font=config.fonts.themedSmall;b=q.wrap(b,g,this.ctx);this.drawPanel(config.panel.tutorialArrow,c,d,g,e);this.drawSprite(f,c+g-1*this.s,d);c+=g/2;d=d+e/2-8*this.s;this.drawText(a,
c,d,{halign:"center",fillColor:config.colors.ioSystemText,shadowColor:config.colors.ioSystemShadow,font:config.fonts.themedLarge});d+=12*this.s;e=[];g=0;for(a=b.length;g<a;g++)f=b[g],this.drawText(f,c,d,{halign:"center",fillColor:config.ioNewGameTitleColor,font:config.fonts.technicalSmall,os:0}),e.push(d+=8*this.s);return e};z.prototype.drawLeftSidebar=function(a,b){if(!this.pureMode){var c=$jscomp.makeIterator(this.getCanvasSize());c.next();c=c.next().value;this.ctx.globalAlpha=1;var d=a-60*this.s*
this.hudAlpha();var e=0;for(a=function(){switch(b){case 0:return"hud_border_2_easy.png";case 2:return n.isChina()?"hud_border_2.png":"hud_border_2_hard.png";default:return"hud_border_2.png"}}();e<c;)this.drawSprite(a,d-6*this.s,e),e+=50*this.s}};z.prototype.drawRaceBar=function(a,b,c,d,e,f){var g;if(this.pureMode)return[!1,null];d=$jscomp.makeIterator(this.getCanvasSize());d.next();d=d.next().value;d=Math.max(d-210*this.s,75*this.s);var h=90*this.s;if(!(d<25*this.s)){this.ctx.globalAlpha=1;a=a-60*
this.s*this.hudAlpha()+14*this.s;this.drawSprite("hud_rivalRaceTrack_line.png",a-4*this.s,h,{dH:d});this.drawSprite("hud_rivalRaceTrack_pyramid.png",a-9*this.s,h-19*this.s);var k={halign:"center",font:config.fonts.themedSmall};var l=b.count(function(a){return a.turn>=c});this.drawText(q.rank(l),a,h-3,k);l=null;var m=b.sortBy(function(a){return a.turn},!0);var p=g=0;for(k=m.length;g<k;p=++g){var w=m[p];w.turn<c&&(0===p||0<w.turn)&&(b=0,0<w.blockedTurns&&(b=Math.sin(15*this.timeTotal+10*p)),p=d*Math.min(w.turn/
c,1),this.drawPortrait(w.character,a+b,h+d-p-10,{small:!0,mX:e,mY:f})&&(l=w))}return[this.hitBox(a-10*this.s,h,20*this.s,d,e,f),l]}};z.prototype.drawRaceTrackIO=function(a,b,c,d){var e,f,g;if(!this.pureMode){var h=$jscomp.makeIterator(this.getCanvasSize());h.next();var k=h.next().value;h=config.racetrackDisplayHeightPixels*this.s;k=k-150*this.s-h;this.ctx.globalAlpha=1;var l=a-60*this.s*this.hudAlpha()+14*this.s;this.drawSprite("hud_rivalRaceTrack_line.png",l-4*this.s,k,{dH:h});var m=config.racetrackDisplayDays;
var p=this.main.exped.raceTrack;var w=0;for(f=p.length;w<f;w++){var n=p[w];if(!(n.inDays>m)){a=h*Math.min(n.inDays/m,1);var D=null!=(g=n.icon)?g:config.io.segmentDifficultySprite;this.drawSprite(D,l+0,k+h-a-10,{mX:c,mY:d,halign:"center"})&&(e=n)}}null!=e&&(c=[{text:q.toText("txt-io-racetrack-days").replace("$inDays",e.inDays),col:config.colors.help}],e.text&&c.push({text:q.toText(e.text)}),debug.showDebugBar&&c.push({text:e.ref,col:"DarkOrchid"}),b.setInfo(c))}};z.prototype.drawIOFame=function(a,
b,c,d,e){if(!this.pureMode){var f=$jscomp.makeIterator(this.getCanvasSize());f.next();f.next();f=210*this.s;this.ctx.globalAlpha=1;a=a-60*this.s*this.hudAlpha()+14*this.s;this.drawSprite("hud_fame.png",a,f,{halign:"center",mX:c,mY:d})&&e.setInfo([{text:q.toText("txt-base-day")+": "+(this.main.exped.turn+1)},{text:q.toText("txt-base-fame")+": "+b.fame}]);return this.drawText(b.fame,a,f+11*this.s,{halign:"center",font:config.fonts.themedSmall,fillColor:"white",os:0})}};z.prototype.drawIOCalendar=function(a,
b,c,d,e){if(!this.pureMode){var f=$jscomp.makeIterator(this.getCanvasSize());f.next();f=f.next().value;if(0!==b.raceTrack.length){b=Math.max(0,b.raceTrack.last().onDay-b.turn);f=Math.max(f-210*this.s,75*this.s);var g=90*this.s;if(!(f<25*this.s))return this.ctx.globalAlpha=1,a=a-60*this.s*this.hudAlpha()+14*this.s,this.drawSprite("hud_day.png",a,g+f+10,{halign:"center",mX:d,mY:e})&&c.setInfo([{text:q.toText("txt-io-help-days-remaining").replace("$days",b)}]),this.drawText(b,a,g+f+22*this.s,{halign:"center",
font:config.fonts.themedSmall,fillColor:"#571607",os:0})}}};z.prototype.drawCalendar=function(a,b,c,d,e,f,g,h,k){if(!this.pureMode){var l=$jscomp.makeIterator(this.getCanvasSize());l.next();l=l.next().value;l=Math.max(l-210*this.s,75*this.s);var m=90*this.s;if(!(l<25*this.s))return this.ctx.globalAlpha=1,a=a-60*this.s*this.hudAlpha()+14*this.s,this.drawSprite("hud_day.png",a,m+l+10,{halign:"center",mX:h,mY:k})&&(f=config.shortDifficultyNames[f],g.setInfo([{text:q.toText("txt-base-day")+": "+(b+1)},
{text:q.toText("txt-base-expedition")+": "+(c+1)},{text:q.toText("txt-base-fame")+": "+d},{text:q.toText("txt-base-funds")+": "+e},{text:q.toText("txt-base-difficulty")+": "+q.toText(f)},{text:config.help.turns,col:config.colors.help}])),this.drawText(b+1,a,m+l+22*this.s,{halign:"center",font:config.fonts.themedSmall,fillColor:"#571607",os:0})}};z.prototype.drawSanity=function(a,b,c,d,e){var f;if(!this.pureMode){var g=$jscomp.makeIterator(this.getCanvasSize());var h=g.next().value;g.next();var k=
-60*this.s*this.hudAlpha();n.isIO()&&!this.main.isWarping()&&null==this.main.tutorial&&(k+=config.io.topRulerWidth*this.s);a=Math.ceil(a);g=200*this.s;var l=$jscomp.makeIterator([h/2-g/2,-2*this.s+this.oY+k]);k=l.next().value;l=l.next().value;this.sanityBar.setValue(a);this.ctx.globalAlpha=1;this.sanityBar.setHighlight(a-c);this.sanityBar.drawBar(this.ctx,b,k,l+5*this.s,g,14*this.s,"#333");0===a&&(this.ctx.globalAlpha=Math.min(.8,Math.abs(Math.sin(3*this.timeTotal))),this.ctx.fillStyle="red",this.ctx.fillRect(k,
l,g,20*this.s));this.ctx.globalAlpha=1;this.ctx.font=config.fonts.technicalSmall;this.drawText(a+" / "+b,h/2,l+15*this.s,{halign:"center"});h=this.img.getSprite("hud_resourceBar_sanity.png");this.drawSprite(h,k-25*this.s,l);c=config.sanity.thresholds;var m=0;for(a=c.length;m<a;m++){var p=c[m];this.drawSprite("hud_resourceBar_sanity_segment.png",k+p/b*g,l+5*this.s)}n.isIO()&&(k-=25*this.s,l+=26*this.s,a=h.dSize.w,b=this.main.iomp.getServerText(),null!=b&&(this.ctx.save(),this.ctx.fillStyle="black",
this.ctx.globalAlpha=.5,this.ctx.fillRect(k,l,a,12*this.s),this.ctx.restore(),this.drawText(b,k+a/2,l+8*this.s,{font:config.fonts.technicalSmall,halign:"center",fillColor:config.colors.ioSystemText,shadowColor:config.colors.ioSystemShadow}),l+=16*this.s),null!=(f=this.main.events)&&f.showingEventDialogue||this.main.iomp.drawNotifications(this.timeDelta,k,l,a,!0));return this.hitBox(k,l,g,19*this.s,d,e)}};z.prototype.drawStanding=function(a,b,c){if(!this.pureMode){var d=$jscomp.makeIterator(this.getCanvasSize());
var e=d.next().value;d.next();d=$jscomp.makeIterator([e/2+118*this.s,-5+this.oY-60*this.s*this.hudAlpha()]);e=d.next().value;var f=d.next().value;n.isIO()&&!this.main.isWarping()&&null==this.main.tutorial&&(f+=config.io.topRulerWidth*this.s);this.ctx.globalAlpha=1;this.ctx.font=config.fonts.technicalSmall;d=function(){switch(!1){case !(-10<=a&&-8>=a):return"hud_standing_neg3.png";case !(-7<=a&&-5>=a):return"hud_standing_neg2.png";case !(-4<=a&&-2>=a):return"hud_standing_neg1.png";case !(-1<=a&&1>=
a):return"hud_standing_0.png";case !(2<=a&&4>=a):return"hud_standing_pos1.png";case !(5<=a&&7>=a):return"hud_standing_pos2.png";case !(8<=a&&10>=a):return"hud_standing_pos3.png"}}();return this.drawSprite(d,e,f,{halign:"center",mX:b,mY:c})}};z.prototype.drawXP=function(a,b,c,d,e,f){if(!this.pureMode){var g=$jscomp.makeIterator(this.getCanvasSize());var h=g.next().value;g.next();g=$jscomp.makeIterator([h-16*this.s+60*this.s*this.hudAlpha(),10*this.s+this.oY]);h=g.next().value;g=g.next().value;if(b<
c||.1<d%.2){c=this.img.getSprite("hud_region_progress.png");var k=b/config.xp.maxMapScore;var l=Math.round(c.pos.x);var m=Math.round(c.pos.y+(1-k)*c.size.h);var p=Math.round(c.size.w);var w=Math.round(c.size.h*k);d=Math.round(h-c.dSize.w/2);var n=Math.round(g+(1-k)*c.dSize.h);b=Math.round(c.dSize.w);k=Math.round(c.dSize.h*k);0<w&&this.ctx.drawImage(c.img,l,m,p,w,d,n,b,k)}this.ctx.font=config.fonts.themedSmall;this.drawText(a,h,g+15*this.s,{os:2,halign:"center"});return this.hitBox(h-10*this.s,g,20*
this.s,20*this.s,e,f)}};z.prototype.drawGoalBadge=function(a,b,c){if(null!=a&&0!==a){var d=a%5;var e=Math.floor(a/5);0===d&&(d=5,--e);var f=Math.floor(e/6);e-=6*f;n.assert(30*f+5*e+d===a);3<e&&0<f&&(c+=2*this.s);a=c;if(0<d){d=this.img.getSprite("hud_io_badge_"+d+".png");this.drawSprite(d,b,c,{halign:"left",valign:"bottom"});c-=d.dSize.h;var g=b+d.dSize.w/2;var h=b+d.dSize.w}0<e&&(d=this.img.getSprite("hud_io_badge_stars_"+e+".png"),null!=d&&this.drawSprite(d,g,c,{halign:"center",valign:"bottom"}));
if(0<f&&(d=this.img.getSprite("hud_io_badge_jewels_"+f+".png"),null!=d))return this.drawSprite(d,h+1*this.s,a,{halign:"left",valign:"bottom"})}};z.prototype.drawRegionInfo=function(a,b,c){var d,e,f;if(!this.pureMode){var g=$jscomp.makeIterator(this.getCanvasSize());var h=g.next().value;g.next();p+=12*this.s;g=!1;var k=$jscomp.makeIterator([0,0,0]);var l=k.next().value;var m=k.next().value;k=k.next().value;var p=null!=(d=null!=(f=config.io)?f.maxRegionInfoLocations:void 0)?d:0;if(!n.isIO()||this.main.isWarping()||
null!=this.main.tutorial)l=0;else if(a.biome.entered||null!=a.biome.claim)l=a.biome.scoreLocations.length,m=a.biome.scoreLocations.count(function(a){return a.known}),k=Math.min(p,l-m);if(0<l){g=config.io.minRegionInfoLocations;l<g&&(g-=l,l+=g,k=Math.min(p,l-(m+g)));l=Math.min(l,p);g=$jscomp.makeIterator([h-101*this.s,this.oY+0]);m=g.next().value;p=g.next().value;this.drawSprite("hud_border_top_base.png",m,p);d=null!=a.biome.claim;g=$jscomp.makeIterator([h-65*this.s-12*this.s*l,this.oY+0]);m=g.next().value;
p=g.next().value;g=this.drawSprite(d?"hud_border_top_overlay_discovered.png":"hud_border_top_overlay_undiscovered.png",m,p,{mX:b,mY:c});if(d&&(m=a.biome.claim.record,f=this.main.iomp.getPortrait(m.explorerTribe,m.explorerSeed,m.explorerGender),null!=f)){var w=$jscomp.makeIterator([h-62*this.s-12*this.s*l,8*this.s,0]);m=w.next().value;p=w.next().value;w=w.next().value;w=p+w*this.s+this.oY+0;this.drawSprite(f,m,w);this.hitBox(m,w,f.size.w*this.s,f.size.h*this.s,b,c)&&(e=!0);null!=a.biome.claim.user&&
0<a.biome.claim.user.goalCount&&this.drawGoalBadge(a.biome.claim.user.goalCount,m-6*this.s,w+f.dSize.h-2*this.s)}if(0<k)for(c=d?"res_fxt_questionmark.png":"res_fxt_questionmark_undiscovered.png",l=$jscomp.makeIterator([h-42*this.s-12*this.s*k,10*this.s+this.oY+0]),b=l.next().value,m=l.next().value,l=p=0;0<=k?p<k:p>k;l=0<=k?++p:--p)this.drawSprite(c,b+12*this.s*l,m)}else k=$jscomp.makeIterator([h-28*this.s,10*this.s+this.oY]),m=k.next().value,p=k.next().value,this.drawSprite("hud_region.png",m,p);
e&&null!=a.biome.claim.user&&(e=150*this.s,this.main.iohighscore.drawUserStats(a.biome.claim.user.userID,h-42*this.s-e,w+34*this.s,e));return g}};z.prototype.hitBox=function(a,b,c,d,e,f){var g=a<e&&e<a+c&&b<f&&f<b+d;n.assert(null!=e,"hitbox: unknown mouse coords");n.assert(null!=f,"hitbox: unknown mouse coords");debug.showHitBoxes&&(this.ctx.save(),this.ctx.strokeStyle=g?"green":"red",this.ctx.lineWidth=1,this.ctx.strokeRect(a,b,c,d),this.ctx.restore());return g};z.prototype.drawAchievement=function(a,
b,c,d,e){var f;var g=e.getDesc();g=q.toText(g);g=g.replace("$val",null!=(f=e.counterTarget)?f:"#ERR#");this.ctx.font=config.fonts.themedSmall;f=q.wrap(g,(c-26-32)*this.s,this.ctx);this.ctx.globalAlpha=1;this.drawPanel(config.panel.infoSimple,a,b,c*this.s,d*this.s);d=e.img;debug.drawAllItems||e.unlocked.some(!0)||(e.secret||(d+="_grey"),e.secret&&(d="achv_img_ID_secret_grey"));this.drawSprite(d+".png",a+12*this.s,b+10*this.s,{scale:.5});d=20;this.ctx.font=config.fonts.themedSmall;this.drawText(q.toText(e.getName()),
a+(c+36)/2*this.s,b+d*this.s,{halign:"center",fillColor:"#973200",os:0});d+=10;this.ctx.font=config.fonts.themedSmall;var h=0;for(g=f.length;h<g;h++){var k=f[h];this.drawText(k,a+(c+36)/2*this.s,b+d*this.s,{halign:"center",fillColor:"black",os:0});d+=8}if(null!=e.counterTarget&&1<e.counterTarget){d-=4;this.ctx.fillStyle="black";this.ctx.fillRect(a+51*this.s,b+d*this.s,(c-36-30)*this.s,6*this.s);h=[0,1,2];var l=0;for(g=h.length;l<g;l++)f=h[l],k=e.counters[f]/e.counterTarget,this.ctx.fillStyle=config.colors.achievements[f],
this.ctx.fillRect(a+52*this.s,b+(d+1)*this.s,k*(c-36-30-2)*this.s,4*this.s)}};z.prototype.drawUnlockedChar=function(a,b,c,d,e){var f;var g=t.getCharacter(e);e=null!=(f=null!=g?g.name:void 0)?f:e;f=q.toText(e);f=q.toText("txt-base-unlockChar").replace("$val",f);this.ctx.font=config.fonts.themedSmall;this.ctx.globalAlpha=1;this.drawPanel(config.panel.infoSimple,a,b,c*this.s,d*this.s);g=g.variations[0].portrait;this.drawSprite("hud_char_frame.png",a+26*this.s,b+d*this.s-13*this.s,{halign:"center",valign:"bottom",
scale:.5});this.drawSprite(g,a+26*this.s,b+d*this.s-16*this.s,{halign:"center",valign:"bottom",scale:.6});this.ctx.font=config.fonts.themedLarge;d=q.wrap(f,(c-26-20)*this.s,this.ctx);e=0;for(g=d.length;e<g;e++)f=d[e],this.drawText(f,a+(c+24)/2*this.s,b+24*this.s,{halign:"center",fillColor:"#973200",os:0}),b+=10*this.s};z.prototype.drawGivenPack=function(a,b,c,d){var e=[config.packImageSize[0]*this.s,config.packImageSize[0]*this.s];var f=16*this.s;var g=e[1]+2*f;if(null!=d){var h=this.main.ioInv.getPackTitle(d);
this.ctx.globalAlpha=1;this.drawPanel(config.panel.infoSimple,a,b,c*this.s,g);this.main.ioInv.drawPack(d,a+16*this.s,b+14*this.s,-1,-1);d=c*this.s-3*f-e[0]+8*this.s;a=a+c*this.s-f-d/2;b+=.75*f;this.ctx.font=config.fonts.themedSmall;c=q.wrap(q.toText("txt-io-pack-new")+":",d,this.ctx);e=0;for(g=c.length;e<g;e++)f=c[e],0!==f.length&&(b+=10*this.s,this.drawText(f,a,b,{halign:"center",fillColor:"#973200",os:0}));this.ctx.font=config.fonts.themedLarge;c=q.wrap(h,d,this.ctx);d=0;for(h=c.length;d<h;d++)f=
c[d],0!==f.length&&(b+=12*this.s,this.drawText(f,a,b,{halign:"center",fillColor:"#973200"}))}};z.prototype.drawGivenMedals=function(a,b,c,d){var e=this.img.getSprite("hud_io_medal.png");var f=16*this.s;var g=e.dSize.h+2*f;if(null!=d){switch(d.type){case "reward":switch(d.sourceData){case eb.worldClaim:var h="txt-io-medals-reason-claim";break;case eb.betaWorld:h="txt-io-medals-reason-beta";break;case eb.keyActivation:h="txt-io-medals-reason-keyActivation";break;case eb.foundPyramid:h="txt-io-medals-reason-foundPyramid";
break;case eb.topScore:h="txt-io-medals-reason-topScore";break;case eb.foundHub:h="txt-io-medals-reason-foundHub"}break;case "xsolla":h="txt-io-medals-reason-xsolla"}n.assert(null!=h&&""!==h);h=q.toText(h).replace("$val",this.main.iomp.getNumClaimsForNextMedal());this.ctx.globalAlpha=1;this.drawPanel(config.panel.infoSimple,a,b,c*this.s,g);g=a+16*this.s;this.drawSprite(e,g,b+14*this.s);e=c*this.s-3*f-e.dSize.x+8*this.s;a=a+c*this.s-f-e/2;b+=.85*f;this.ctx.font=config.fonts.themedLarge;c=1<d.medalsChange?
q.toText("txt-io-medals-new-plural").replace("$val",d.medalsChange):q.toText("txt-io-medals-new");c=q.wrap(c,e,this.ctx);g=0;for(f=c.length;g<f;g++)d=c[g],0!==d.length&&(b+=14*this.s,this.drawText(d,a,b,{halign:"center",fillColor:"#973200"}));this.ctx.font=config.fonts.themedSmall;c=q.wrap(h,e,this.ctx);e=0;for(h=c.length;e<h;e++)d=c[e],0!==d.length&&(b+=10*this.s,this.drawText(d,a,b,{halign:"center",fillColor:"#973200",os:0}))}};z.prototype.drawGivenAlphaKey=function(a,b,c){var d=this.img.getSprite("mr_slippers.png");
var e=16*this.s;var f=60*this.s+2*e;var g=q.toText("txt-io-alpha-notify-title");var h=q.toText("txt-io-alpha-notify-desc");this.ctx.globalAlpha=1;this.drawPanel(config.panel.infoSimple,a,b,c*this.s,f);this.drawSprite(d,a+16*this.s,b+20*this.s,{scale:.1});f=c*this.s-3*e-.1*d.dSize.x+8*this.s;a=a+c*this.s-e-f/2;b+=.7*e;this.ctx.font=config.fonts.themedLarge;this.drawWrappedText(g,a,b,f,{halign:"center",fillColor:"#973200"});b+=25*this.s;this.ctx.font=config.fonts.themedSmall;c=q.wrap(h,f,this.ctx);
g=0;for(e=c.length;g<e;g++)h=c[g],0!==h.length&&(b+=10*this.s,this.drawText(h,a,b,{halign:"center",fillColor:"#973200",os:0}))};z.prototype.drawButton=function(a,b,c,d,e,f,g,h,k){h=void 0===h?!1:h;var l;var m={active:!0,panel:"menuButton",fillColor:"black",shadowColor:"gray",font:config.fonts.themedLarge};Object.merge(m,k);f=this.hitBox(b-d/2,c,d,e,f,g);g=m.active?f?"red":m.fillColor:"gray";this.ctx.globalAlpha=1;this.ctx.font=m.font;f&&h&&(c+=2*this.s);this.drawPanel(m.panel,b-d/2,c,d,e);m.halign=
"center";m.fillColor=g;null==m.os&&(m.os=this.s);h=null!=(l=m.font)?l:this.ctx.font;(l=h.includes("Mallanna"))?(h=parseInt(h),g=.25*h):(h=.6*parseInt(h),g=0);k=config.panel[m.panel];a=q.wrap(a,d-(null!=k?k.offset:0)*this.s*2,this.ctx);d=c+e/2-a.length*h/2+h-g;g=0;for(c=a.length;g<c;g++)e=a[g],this.drawText(e,b,d,m),d+=h,l||(d+=.6*h);return f};z.prototype.drawWarningBar=function(a,b,c,d){c=void 0===c?null:c;d=void 0===d?"center":d;var e=$jscomp.makeIterator(this.getCanvasSize());var f=e.next().value;
e.next();this.ctx.font=config.fonts.themedLarge;null==this.warningBarTime&&(this.warningBarCol=this.warningBarTime=0);this.warningBarTime+=this.timeDelta;this.warningBarTime>=config.colors.warningFlashTime&&(this.warningBarTime-=config.colors.warningFlashTime,this.warningBarCol=0===this.warningBarCol?1:0);e=0===this.warningBarCol?config.colors.warning:config.colors.warningFlash;null==c&&(c=f/2);this.drawText(a,c,b,{fillColor:e,halign:d})};z.prototype.drawLetterboxMattes=function(a){a=void 0===a?100:
a;var b=$jscomp.makeIterator(this.getCanvasSize());var c=b.next().value;b=b.next().value;a=Math.min(80*a,40);this.ctx.globalAlpha=1;this.ctx.fillStyle="black";this.ctx.fillRect(0,0,c,a);return this.ctx.fillRect(0,b-a,c,a)};z.prototype.drawOutroPacks=function(a,b,c){var d,e,f;var g=$jscomp.makeIterator(this.getCanvasSize());var h=g.next().value;g=g.next().value-115*this.s;var k=a.stats.packs;var l=Math.max(k.length,config.maximumPartyPacks);var m=this.img.getSprite("hud_io_crate_closed_dark.png");
a=4*this.s;h=Math.round(h/2-(l*m.dSize.w+(l-1)*a)/2);for(d=f=0;0<=l?f<l:f>l;d=0<=l?++f:--f)d=k[d],null!=d?this.main.ioInv.drawPack(d,h,g,b,c)&&(e=d):this.drawSprite(m,h,g),h+=m.dSize.w+a;return e};z.prototype.drawOutro=function(a,b,c,d,e){var f=$jscomp.makeIterator(this.getCanvasSize());var g=f.next().value;f.next();var h=[];0<c.goalFame&&(h.push([q.toText("txt-outro-pyramid"),c.goalFame]),0<c.newPocketFame&&h.push([q.toText("txt-outro-newWorldFame"),c.newPocketFame]));0<c.butterflies&&(f=c.butterflies*
config.taxonomy.butterflyFame,h.push([c.butterflies+" x "+q.toText("txt-outro-butterflies"),f]));0<c.goalFame?(f=q.rank(c.raceRank),h.push([q.toText("txt-outro-speedbonus")+" ("+f+")",c.timeBonus])):h.push([q.toText("txt-outro-days"),c.turns]);1<c.fameScale&&h.push([q.toText("txt-outro-journalistbonus")+" ("+Math.round(100*c.fameScale-100)+"%)",c.bonus]);var k=c.finalFame;a||--e;var l=TWEEN.Easing.Bounce.Out(e.clamp(0,1));var m=a?140*this.s+20*this.s*h.length:200*this.s;g/=2;f=50*this.s;f=f-(f+m)+
(f+m)*l;l=240*this.s;var p=25*this.s;this.ctx.globalAlpha=1;this.drawPanel(config.panel.info,g-l/2,f,l,m);f+=35*this.s;--e;if(0>e)this.finalBangPlayed=this.titleBangPlayed=!1,this.outroStatsStage=0;else if(this.titleBangPlayed||(this.sfx.play("outroBang"),this.titleBangPlayed=!0),this.ctx.fillStyle="black",this.ctx.font=40*this.s+"px Curious",this.drawSprite(a?0<c.goalFame?"hud_success_title_1.png":"hud_escaped_title_1.png":"hud_gameOver_title_1.png",g,f,{halign:"center"}),f+=50*this.s,--e,!(0>e)){m=
{fillColor:"black",shadowColor:"white"};var w={fillColor:"black",shadowColor:"white",halign:"center"};if(a){d=b=0;for(a=h.length;b<a;d=++b){c=h[d];w=$jscomp.makeIterator(c);c=w.next().value;w=w.next().value;this.ctx.font=config.fonts.themedLarge;this.drawText(c,g-l/2+p,f,m);var da=Math.floor(.5*w*e).clamp(0,w);c=this.ctx.measureText(da);this.drawText(da,g+l/2-p-c.width,f,m);d>this.outroStatsStage&&(this.outroStatsStage+=1,this.outroSoundTime=0);da!==w&&.05<e-this.outroSoundTime&&(this.outroSoundTime=
e,this.sfx.play("outroCount"));e-=3;if(0>e)return;f+=20*this.s}f+=10*this.s;this.ctx.font=config.fonts.themedLarge;this.finalBangPlayed||(this.sfx.play("outroBang"),this.finalBangPlayed=!0);e=q.toText("txt-outro-newfame");c=this.ctx.measureText(e);this.drawText(e,g-c.width/2,f,m);f+=20*this.s;c=this.ctx.measureText(k);return this.drawText(k,g-c.width/2,f,m)}f-=35*this.s;this.ctx.font=config.fonts.technicalSmall;this.ctx.fillStyle="black";this.drawText(b,g,f+50,w);f+=60*this.s;e-=2;if(!(0>e))for(this.ctx.globalAlpha=
e.clamp(0,1),this.ctx.font=config.fonts.themedLarge,this.drawText(q.toText("txt-epilogue-score"),g,f,w),f+=20*this.s,e=n.isIO()?c.fame:c.points,this.drawText(e,g,f,w),f+=10*this.s,this.ctx.fillStyle="#555",this.ctx.font=config.fonts.technicalSmall,k=this.splitText(d,l-40*this.s),l=0,e=k.length;l<e;l++)h=k[l],this.drawText(h,g,f+25*this.s,w),f+=15*this.s}};z.prototype.drawStats=function(a){var b;a=[["txt-base-expedition",a.worldLvl+1],["txt-outro-days",a.turns+1],["txt-outro-legs",a.legs],["txt-outro-avgtravel",
a.avgDist.format(1)],["txt-outro-visited",a.visitedLocations],["txt-outro-worldpct",Math.floor(100*a.discoveredPerc)+"%"],["txt-outro-playtime",q.toText("txt-outro-playtime2").replace("$val",a.playTime)],["txt-base-fame",null!=(b=a.finalFame)?b:a.fame]];b=$jscomp.makeIterator(this.getCanvasSize());b.next();b.next();var c=25*this.s;var d=35*this.s;var e=150*this.s;this.ctx.globalAlpha=1;this.drawInfoBox(c,d,e,14*a.length*this.s+5*this.s);this.ctx.font=config.fonts.technicalSmall;var f=0;for(b=a.length;f<
b;f++){var g=$jscomp.makeIterator(a[f]);var h=g.next().value;g=g.next().value;this.drawText(q.toText(h),c+5*this.s,d+12*this.s);h=this.ctx.measureText(g);this.drawText(g,c+e-5*this.s-h.width,d+12*this.s);d+=14*this.s}};z.prototype.drawInfoBox=function(a,b,c,d){this.ctx.globalAlpha=1;this.ctx.fillStyle="#111";this.ctx.fillRect(a,b,c,d);this.ctx.strokeStyle=config.colors.personInfoBorder;this.ctx.lineWidth=2;return this.ctx.strokeRect(a,b,c,d)};z.prototype.drawHintBox=function(a,b,c){this.ctx.globalAlpha=
1;this.ctx.strokeStyle=config.colors.personInfoBorder;this.ctx.fillStyle=config.colors.personInfoBorder;this.ctx.beginPath();this.ctx.moveTo(b,c);this.ctx.lineTo(b+20,c);this.ctx.stroke();var d=4;.2>this.timeTotal%1&&(d+=4);this.ctx.beginPath();this.ctx.arc(b,c,d,0,2*Math.PI,!1);this.ctx.closePath();this.ctx.fill();this.ctx.fillStyle="#333";this.ctx.fillRect(b+20,c-20,350,40);this.ctx.lineWidth=2;this.ctx.strokeRect(b+20,c-20,350,40);return this.drawText(a,b+30,c+28-20,{font:config.fonts.technicalSmall})};
z.prototype.drawCharacterInfo=function(a,b,c,d,e,f){var g,h,k;var l={halign:"left",valign:"top",maxY:-1,xp:0,showActions:!1,showAttributes:!0,showLevelUp:!1,showDescription:!1,hoverMarginN:0,hoverMarginE:0,hoverMarginS:0,hoverMarginW:0};Object.merge(l,f);var m=!Object.isEmpty(a.statuses);var p=!a.isSpecial&&null==a.mounted&&a.canDismiss;l.showLevelUp&&a.getLevelConf(a.level+1);f=new R(115,20);if(l.showAttributes){this.ctx.font=config.fonts.technicalSmall;a.isNPC||(f.w+=50);var w=l.showDescription?
this.splitText(null!=(g=a.description)?g:"",f.w-5):[];var n=Object.count(a.statuses,function(a,b){return null!=b.title||debug.showFlagsInfo});var D=Math.ceil(n/config.uiMaxStatuses);f.h+=10*w.length;f.h+=0<w.length?15:5;f.h+=16*a.dice.length;a.isNPC||(f.h+=25);0<a.capacity&&(f.h+=18);a.capacity>config.uiMaxCapacity&&(f.h+=18);a.isEnemy||a.isSpecial||a.flags.animal||a.isNPC||(f.h+=18);m&&(f.h+=4+15*D);f.h+=20*Object.size(a.buffs);f.h+=4}l.showLevelUp&&(f.h+=18);l.showActions&&(a.isMountable&&(f.h+=
18),p&&(f.h+=18),f.h+=18*a.buttons.length,debug.showDebugBar&&(f.h+=18),debug.showDebugBar&&!a.isSpecial&&(f.h+=36),null!=l.testStatus&&(f.h+=18));if(l.showLevelUp||l.showActions||0<n)f.h+=8;this.ctx.font=config.fonts.themedLarge;n=this.ctx.measureText(a.name);f.w=Math.max(f.w*this.s,n.width+60*this.s);f.h*=this.s;g=y;"center"===l.halign?b-=f.w/2:"right"===l.halign&&(b-=f.w);-1<l.maxY&&c+f.h>l.maxY&&(c=l.maxY,l.valign="bottom");"bottom"===l.valign&&(c=c-f.h<25*this.s?c+50*this.s:c-f.h);this.drawInfoBox(b,
c+10,f.w,f.h,d,e);this.hitBox(b-l.hoverMarginE,c-l.hoverMarginN+10,f.w+l.hoverMarginE+l.hoverMarginW,f.h+l.hoverMarginN+l.hoverMarginS,d,e)&&(g="hover");c+=20*this.s;var v=$jscomp.makeIterator([b,c]);var y=v.next().value;v=v.next().value;if(debug.showFlagsInfo&&l.showAttributes&&0<Object.size(a.flags)){this.drawInfoBox(b-220,c-30,200,f.h,d,e);this.ctx.font=config.fonts.technicalSmall;var r=a.flags;for(A in r)if(h=r[A])this.drawText("+"+A,y-200,v),v+=20;if(a.isSpecial)for(A in v+=20,this.drawText("PartyFlags:",
y-200,v),v+=20,r=this.main.party.flags,r)h=(h=r[A])?"+":"-",this.drawText(""+h+A,y-200,v),v+=20}this.ctx.fillStyle="white";this.ctx.strokeStyle="white";this.ctx.lineWidth=this.s;this.ctx.fillText(a.name,b+40*this.s,c);var A=function(){switch(a.gender){case "male":return"hud_icon_gender_male.png";case "female":return"hud_icon_gender_female.png";case "hybrid":return"hud_icon_gender_hybrid.png"}}();null!=A&&this.drawSprite(A,b+45*this.s+n.width,c-9*this.s);c+=10*this.s;this.drawPortrait(a,b+10,c,{halign:"left"});
this.ctx.font=config.fonts.technicalSmall;y=a.title;A=t.getCharacter(a.id);if(1<t.arrify(A.levels).length||a.isSpecial)y+=" - "+q.toText("txt-base-level")+" "+(a.level+1);this.ctx.fillText(y,b+40*this.s,c);c+=20*this.s;A=14*this.s;if(l.showAttributes){v=0;for(y=w.length;v<y;v++)n=w[v],this.ctx.fillText(n,b+10*this.s,c),c+=10*this.s;0<w.length&&(c+=10*this.s);w=$jscomp.makeIterator(config.imgSize.dice);y=w.next().value;w=w.next().value;y=$jscomp.makeIterator([y*this.s*.5,w*this.s*.5]);w=y.next().value;
y.next();if(0<a.dice.length){this.ctx.font=config.fonts.technicalSmall;this.ctx.fillStyle="white";this.ctx.fillText(q.toText("txt-ch-dice"),b+10*this.s,c);this.hitBox(b+60*this.s,c-9*this.s,100*this.s,32*a.dice.length,d,e)&&(g="dice");var H=a.dice;var G=0;for(h=H.length;G<h;G++)if(n=H[G],null!=n.faces){var V=n.faces.split(" ");y=v=0;for(r=V.length;v<r;y=++v){var T=V[y];T=t.getDieFace(T);this.drawSprite(n.sprite,b+60*this.s+y*(w+3*this.s),c-9*this.s,{scale:.5});null!=T.sprite&&this.drawSprite(T.sprite,
b+60*this.s+y*(w+3*this.s),c-9*this.s,{scale:.5})}c+=16*this.s}}a.hasHealth()&&(this.ctx.font=config.fonts.technicalSmall,this.ctx.fillStyle="white",this.ctx.fillText(q.toText("txt-ch-toughness"),b+10*this.s,c),this.drawHealthBar(b+60*this.s,c-5*this.s,a.health,a.maxHealth,{showText:!0}),this.hitBox(b+60*this.s,c-5*this.s,100*this.s,7*this.s,d,e)&&(g="health"),c+=16*this.s);if(0<a.capacity){this.ctx.font=config.fonts.technicalSmall;this.ctx.fillStyle="white";this.ctx.fillText(q.toText("txt-ch-capacity"),
b+10*this.s,c);y=n=0;for(v=Math.min(a.capacity,config.uiMaxCapacity);0<=v?n<v:n>v;y=0<=v?++n:--n)this.drawSprite("hud_capacity.png",b+60*this.s+y*(w+6),c-9*this.s);this.hitBox(b+60*this.s,c-9*this.s,100*this.s,12*this.s,d,e)&&(g="capacity");c+=18*this.s}if(a.capacity>config.uiMaxCapacity){y=n=0;for(v=a.capacity-config.uiMaxCapacity;0<=v?n<v:n>v;y=0<=v?++n:--n)this.drawSprite("hud_capacity.png",b+60*this.s+y*(w+6),c-9*this.s);this.hitBox(b+60*this.s,c-9*this.s,100*this.s,12*this.s,d,e)&&(g="capacity");
c+=18*this.s}if(a.hasLoyalty()){this.ctx.font=config.fonts.technicalSmall;this.ctx.fillStyle="white";this.ctx.fillText(q.toText("txt-ch-loyalty"),b+10*this.s,c);for(y=w=0;4>w;y=++w)n=y<a.loyalty?"hud_loyalty_good.png":"hud_loyalty_bad.png",this.drawSprite(n,b+60*this.s+14*y*this.s,c-8*this.s);this.hitBox(b+60*this.s,c-5*this.s,100*this.s,7*this.s,d,e)&&(g="loyalty");c+=18*this.s}if(0<Object.size(a.buffs))for(x in this.drawText(q.toText("txt-ch-buffs"),b+10*this.s,c),w=a.buffs,w)y=w[x],this.drawSprite(y.sprite,
b+60*this.s,c-7*this.s),this.drawText(q.toText(y.title)+" ("+y.duration+")",b+75*this.s,c),this.hitBox(b+60*this.s,c-7*this.s,100*this.s,12*this.s,d,e)&&(k=y),c+=18*this.s;window.isClient||(this.ctx.webkitImageSmoothingEnabled=!1);this.ctx.imageSmoothingEnabled=!1;if(m){var u=this.drawCharacterInfoStatuses(a,l.showActions&&null!=g,b,c,d,e);c+=15*D*this.s}}var x={halign:"center",font:config.fonts.technicalSmall};this.ctx.globalAlpha=1;l.showLevelUp&&(D=a.isSpecial?config.xp.playerLevels[a.level]:config.xp.levels[a.level],
x.fillColor="white",this.hitBox(b+10*this.s,c,f.w-10*this.s,12*this.s,d,e)&&(x.fillColor=config.colors.diaryActionActive,g="levelUp"),this.drawPanel(config.panel.action,b+10*this.s,c,f.w-20*this.s,A),this.drawText(q.toText("txt-ch-promote")+" ("+l.xp+" / "+D+")",b+f.w/2,c+9*this.s,x),c+=18*this.s);if(l.showActions){a.isMountable&&(this.main.party.canMount()||null!=a.mounted?(x.fillColor="white",this.hitBox(b+10*this.s,c,f.w-10*this.s,A,d,e)&&(x.fillColor=config.colors.diaryActionActive,g=null!=a.mounted?
"dismount":"mount")):x.fillColor="grey",this.drawPanel(config.panel.action,b+10*this.s,c,f.w-20*this.s,A),D=null!=a.mounted?"txt-ch-dismount":"txt-ch-mount",D=q.toText(D),this.drawText(D,b+f.w/2,c+9*this.s,x),c+=18*this.s);p&&(this.main.exped.waiting?x.fillColor="grey":(x.fillColor="white",this.hitBox(b+10*this.s,c,f.w-10*this.s,A,d,e)&&(x.fillColor=config.colors.diaryActionActive,g="dismiss")),this.drawPanel(config.panel.action,b+10*this.s,c,f.w-20*this.s,A),D=q.toText("txt-ch-dismiss"),this.drawText(D,
b+f.w/2,c+9*this.s,x),c+=18*this.s);m=a.buttons;D=0;for(x=m.length;D<x;D++)p=m[D],this.drawCharacterInfoButton(p.title,b,c,f.w,d,e)&&(g={id:"customButton",person:a,data:p.events}),c+=18*this.s;debug.showDebugBar&&(p=b+10*this.s+(f.w-20*this.s)/2+5*this.s,this.drawCharacterInfoButton("[Quick Remove]",b,c,f.w,d,e)&&(g="debugRemoveCharacter"),c+=18*this.s,a.isSpecial||(a.hasHealth()&&(this.drawCharacterInfoButton("- Health: "+a.health+" +",b,c,f.w,d,e)&&(g=d>p?"debugIncHealth":"debugDecHealth"),c+=18*
this.s),a.hasLoyalty()&&(this.drawCharacterInfoButton("- Loyalty: "+a.loyalty+" +",b,c,f.w,d,e)&&(g=d>p?"debugIncLoyalty":"debugDecLoyalty"),c+=18*this.s)),null!=l.testStatus&&(this.drawCharacterInfoButton("- Status: "+l.testStatus+" +",b,c,f.w,d,e)&&(g=d>p?"debugAddStatus":"debugRemoveStatus"),c+=18*this.s))}null!=k&&this.drawBuffInfo(d-60*this.s,e+15*this.s,k);null!=u&&this.drawStatusInfo(d-60*this.s,e+15*this.s,u.status,u.owned);return g};z.prototype.drawCharacterInfoButton=function(a,b,c,d,e,
f){var g={halign:"center"};var h=!1;var k=14*this.s;g.fillColor="white";this.hitBox(b+10*this.s,c,d-10*this.s,k,e,f)&&(g.fillColor=config.colors.diaryActionActive,h=!0);this.drawPanel(config.panel.action,b+10*this.s,c,d-20*this.s,k);this.drawText(a,b+d/2,c+9*this.s,g);return h};z.prototype.drawCharacterInfoStatusesShort=function(a,b,c,d,e){var f;var g=0;var h=14*this.s;var k=null;this.ctx.font=config.fonts.themedLarge;var l=a.statuses;for(f in l){var m=l[f];if(null!=m.title&&m.important){var p=Math.floor(g/
2);var w=g%2;p=b+5*this.s-this.s*p*16-6*this.s;var n=c-12*this.s+this.s*w*16;m.revealTime+=this.timeDelta;w=J.clamp(m.revealTime,0,1);var q=-10*this.s*(1-w);this.ctx.globalAlpha=w;this.ctx.fillStyle="black";this.ctx.fillRect(p+q,n,h,h);this.drawStatusIcon(m,p+q,n,h);this.hitBox(p,n,h,h,d,e)&&(k={status:m,owned:!0,person:a});g+=1}}return k};z.prototype.drawStatusIcon=function(a,b,c,d){this.drawSprite(a.sprite,b,c);this.ctx.globalAlpha=1;if(0<a.buffDays||0<a.buffTrips||a.buffDelayDays||0<a.buffDelayTrips){this.ctx.fillStyle=
config.colors.statusBar;this.ctx.fillRect(b,c+d-this.s,d,2*this.s);if(0<a.buffDelayDays){this.ctx.fillStyle=config.colors.statusBarTurnsDelay;var e=a.buffDelayDays/a.buffDelayDaysInit;b+=d*(1-e)}else 0<a.buffDelayTrips?(this.ctx.fillStyle=config.colors.statusBarTripsDelay,e=a.buffDelayTrips/a.buffDelayTripsInit,b+=d*(1-e)):0<a.buffDays?(this.ctx.fillStyle=config.colors.statusBarTurns,e=a.buffDays/a.buffDaysInit):0<a.buffTrips&&(this.ctx.fillStyle=config.colors.statusBarTrips,e=a.buffTrips/a.buffTripsInit);
return this.ctx.fillRect(b,c+d-this.s,d*e,2*this.s)}};z.prototype.drawCharacterInfoStatuses=function(a,b,c,d,e,f){var g=0;var h=null;var k=$jscomp.makeIterator([10*this.s,14*this.s,16*this.s]);var l=k.next().value;var m=k.next().value;k=k.next().value;var p=a.statuses;for(n in p){var w=p[n];if(null!=w.title||debug.showFlagsInfo)this.drawStatusIcon(w,c+l+g*k,d-6*this.s,m),this.hitBox(c+l+g*k,d-6*this.s,m,m,e,f)&&(h={status:w,owned:!0,person:a}),g+=1,g>=config.uiMaxStatuses&&(g=0,d+=30)}if(b){var n=
t.getCharacter(a.id);if(a.canLevelUp()&&null!=n.levels&&(n=t.arrify(n.levels),n=n[a.level+1],null!=n)){p=t.arrify(n.statuses);var q=0;for(b=p.length;q<b;q++)n=p[q],a.hasStatus(n)||(w=t.getStatus(n),null!=w.title&&(this.ctx.globalAlpha=.3,this.drawSprite(w.sprite,c+l+g*k,d-6*this.s),this.ctx.globalAlpha=.9,this.drawSprite("hud_levelUp.png",c+l+g*k+k-m,d+6),this.hitBox(c+l+g*k,d-6*this.s,m,m,e,f)&&(h={status:w,owned:!1,person:a}),g+=1,g>=config.uiMaxStatuses&&(g=0,d+=30)))}}return h};z.prototype.drawStatusInfo=
function(a,b,c,d,e){var f,g,h,k;var l=120*this.s;e=null!=(h=null!=e?e.gender:void 0)?h:"male";h=[{text:null!=(g=q.parse(c.title,e))?g:c.id}];this.ctx.font=config.fonts.technicalSmall;g=q.parse(null!=(f=c.description)?f:"",e);if(0<g.length){e=this.splitText(g,l-10*this.s);var m=0;for(f=e.length;m<f;m++)g=e[m],h.push({text:g})}0<c.buffDelayDays?h.push({text:q.toText("txt-status-in-days")+": "+c.buffDelayDays}):0<c.buffDelayTrips?h.push({text:q.toText("txt-status-in-trips")+": "+c.buffDelayTrips}):0<
c.buffDays?h.push({text:q.toText("txt-status-days")+": "+c.buffDays}):0<c.buffTrips&&h.push({text:q.toText("txt-status-trips")+": "+c.buffTrips});if(null!=c.bonus){f=[];m=q.bonusHelp(c.bonus);var p=0;for(e=m.length;p<e;p++)g=m[p],f.push({text:g});if(0<f.length)for(h.push({text:""}),e=0,m=f.length;e<m;e++){g=f[e];var w=this.splitText(g.text,l-10*this.s);g=0;for(p=w.length;g<p;g++){var n=w[g];h.push({text:n,col:config.colors.bonus})}}c.noBonusStacking&&h.push({text:q.toText("txt-bonus-noStack"),col:config.colors.bonus})}c.blockHealthRegen&&
h.push({text:q.toText("txt-bonus-blocksRegen"),col:config.colors.bonus});c.blockLevelUp&&h.push({text:q.toText("txt-bonus-blocksLevelUp"),col:config.colors.bonus});d||(h.push({text:""}),h.push({text:""+q.toText("txt-base-levelup"),col:config.colors.help}));debug.showAgeInfo&&(h.push({text:""}),h.push({text:"(DayAge: "+c.dayAge+", TripAge: "+c.tripAge+")",col:"DarkOrchid"}));d=new R(l,(5+10*h.length)*this.s);f=$jscomp.makeIterator(this.getCanvasSize());c=f.next().value;f=f.next().value;a=J.clamp(a,
10,c-l-10);b+d.h>f-50*this.s&&(b-=d.h+50);this.ctx.globalAlpha=1;this.ctx.fillStyle="#111";this.ctx.fillRect(a,b,d.w,d.h);this.ctx.strokeStyle=config.colors.personInfoBorder;this.ctx.lineWidth=2;this.ctx.strokeRect(a,b,d.w,d.h);b+=10*this.s;l=0;for(c=h.length;l<c;l++)d=h[l],this.ctx.fillStyle=null!=(k=d.col)?k:"white",this.ctx.fillText(d.text,a+10,b),b+=10*this.s};z.prototype.drawBuffInfo=function(a,b,c){var d,e;var f=120*this.s;var g=[{text:null!=(d=q.toText(c.title))?d:c.id},{text:q.toText("txt-combat-buffDuration")+
": "+c.duration,col:config.colors.bonus}];this.ctx.font=config.fonts.technicalSmall;0<c.damage&&g.push({text:q.toText("txt-combat-dmg")+": "+c.damage,col:config.colors.bonus});0<c.stunDice&&g.push({text:q.toText("txt-combat-stunDice")+": "+c.stunDice,col:config.colors.bonus});d=new R(f,(5+10*g.length)*this.s);var h=$jscomp.makeIterator(this.getCanvasSize());c=h.next().value;h=h.next().value;a=J.clamp(a,10,c-f-10);b+(d.h>h-50*this.s)&&(b-=d.h+50);this.ctx.globalAlpha=1;this.ctx.fillStyle="#111";this.ctx.fillRect(a,
b,d.w,d.h);this.ctx.strokeStyle=config.colors.personInfoBorder;this.ctx.lineWidth=2;this.ctx.strokeRect(a,b,d.w,d.h);b+=10*this.s;d=0;for(f=g.length;d<f;d++)c=g[d],this.ctx.fillStyle=null!=(e=c.col)?e:"white",this.ctx.fillText(c.text,a+10,b),b+=10*this.s};z.prototype.resetClouds=function(){return this.clouds=[]};z.prototype.addRandCloud=function(){var a=$jscomp.makeIterator(this.getCanvasSize());var b=a.next().value;a=a.next().value;b={pos:this.mouseToTilePos_float(Number.random(-10,b),Number.random(-10,
a)),time:0,lifeTime:J.randA(config.clouds.lifeTime),speed:J.randA(config.clouds.speed),sprite:this.img.getSprite("clouds_"+Number.random(1,config.clouds.imgVariations-1)+".png")};return this.clouds.push(b)};z.prototype.drawMapCloud=function(a){var b;if(this.main.graphicsSettings.showCloud){var c=$jscomp.makeIterator(this.getCanvasSize());c.next();c.next();var d=this.clouds;var e=0;for(b=d.length;e<b;e++){c=d[e];var f=1>c.time?J.lerp(0,1,c.time):c.time>c.lifeTime?J.lerp(1,0,c.time-c.lifeTime):1;this.ctx.globalAlpha=
f*config.clouds.alpha;f=this.getTileScreenPos(c.pos);this.drawSprite(c.sprite,f.x,f.y,{scale:this.biomeScaleFactor});c.pos.x+=a*c.speed;c.time+=a}for(this.clouds.remove(function(a){return a.time>a.lifeTime+1});this.clouds.length<config.clouds.count;)this.addRandCloud()}};z.prototype.drawCloudIntro=function(){if(!(10<this.introTime||debug.skipSaveGames&&0<this.introTime)){var a=$jscomp.makeIterator(this.getCanvasSize());var b=a.next().value;a.next();var c=Math.pow((this.introTime-.25)/1.8,5);this.ctx.globalAlpha=
(config.clouds.introFadeDelay-c).clamp(.3,1);a=this.img.cloudsL;this.ctx.drawImage(a,0,0,a.width,a.height,-250*this.s*c,0,.5*a.width*this.s,.5*a.height*this.s);a=this.img.cloudsR;this.ctx.drawImage(a,0,0,a.width,a.height,b-.5*a.width*this.s+250*this.s*c,0,.5*a.width*this.s,.5*a.height*this.s);if(this.main.wasLoadingBeforeGame||"loading"===this.main.getMainState())this.ctx.globalAlpha=J.lerp(1,0,Math.min(1,this.introTime)),this.drawLoadingTitleBox();this.ctx.globalAlpha=1}};z.prototype.onStartWorld=
function(){this.resetZoom();this.resetClouds();this.part.clearParticles();return this.partyOffset=0};z.prototype.drawFrame=function(a,b){b=void 0===b?!1:b;var c;var d=$jscomp.makeIterator(this.getCanvasSize());var e=d.next().value;var f=d.next().value;d=this.img.getSprite(a);null==(c=this.backgroundImages)[a]&&(c[a]=this.img.createSilhouette(d.img,.3));this.ctx.drawImage(this.backgroundImages[a],d.pos.x,d.pos.y,d.size.w,d.size.h,0,0,e,f);if(b){b=640/720;a=window.getDstCanvas();a=$jscomp.makeIterator([Math.max(640*
this.s,a.width),Math.max(360*this.s,a.height)]);c=a.next().value;var g=a.next().value;c/g<b?(a=c,b=c/b):(a=g*b,b=g);e=Math.floor(e/2-a/2);f=Math.floor(f/2-b/2);return this.ctx.drawImage(d.img,d.pos.x,d.pos.y,d.size.w,d.size.h,e,f,a,b)}return this.drawSprite(a,e/2,f/2,{halign:"center",valign:"center"})};z.prototype.drawBackground=function(a){var b;var c=$jscomp.makeIterator(this.getCanvasSize());var d=c.next().value;var e=c.next().value;c=this.img.getSprite(a);null==(b=this.backgroundImages)[a]&&(b[a]=
this.img.createSilhouette(c.img,.3));this.ctx.globalAlpha=1;return this.ctx.drawImage(this.backgroundImages[a],c.pos.x,c.pos.y,c.size.w,c.size.h,0,0,d,e)};z.prototype.drawLibraryBackground=function(){return this.drawBackground("menu_bg_1.png")};z.prototype.drawFameFunds=function(a,b,c){var d=$jscomp.makeIterator(this.getCanvasSize());var e=d.next().value;d.next();var f=70*this.s;d={halign:"center",scale:.75};this.ctx.fillStyle="white";this.ctx.font=config.fonts.technicalLarge;this.ctx.globalAlpha=
1;this.drawSprite("hud_resource_main_expedition.png",e/2-f,0,d);this.drawText(a+1+"/"+(config.maxExpedition+1),e/2-f+10*this.s,12*this.s,d);this.drawSprite("hud_resource_main_fame.png",e/2,0,d);this.drawText(b,e/2+10*this.s,12*this.s,d);this.drawSprite("hud_resource_main_funds.png",e/2+f,0,d);return this.drawText(c,e/2+f+10*this.s,12*this.s,d)};z.prototype.setImageSmoothing=function(a,b){b=void 0===b?this.ctx:b;n.assert(!a);b.mozImageSmoothingEnabled=a;b.webkitImageSmoothingEnabled=a;b.msImageSmoothingEnabled=
a;return b.imageSmoothingEnabled=a};z.prototype.splitText=function(a,b){b=void 0===b?400:b;var c=[];var d="";var e=a.split(config.diaryText.separator);var f=0;for(a=e.length;f<a;f++){var g=e[f];var h=""+d+g+" ";this.ctx.measureText(h).width>=b&&!(0<=F.call(config.diaryText.nonBreaking,g))?(c.push(d),d=g+" "):d=h}d.compact().isBlank()||c.push(d);return c};z.prototype.drawSprite=function(a,b,c,d){d=void 0===d?{}:d;var e,f,g;if(""!==a&&(Object.isString(a)&&(a=this.img.getSprite(a)),n.assert(null!=a),
null!=a)){var h=!1;var k={ctx:this.ctx,scale:1,screenScale:this.s,halign:"left",valign:"top",mirror:!1,damageTime:1E3,rotate:0,useTinted:!1,round:!0,limitHeight:0,limitWidth:0,clipWidth:-1};Object.merge(k,d);this.setImageSmoothing(!1,k.ctx);null!=k.offset&&(b+=k.offset.x,c+=k.offset.y);0<k.limitWidth&&a.size.w*k.scale*k.screenScale>k.limitWidth&&(k.scale=k.limitWidth/(k.screenScale*a.size.w));0<k.limitHeight&&a.size.h*k.scale*k.screenScale>k.limitHeight&&(k.scale=k.limitHeight/(k.screenScale*a.size.w));
null==k.dW&&(k.dW=a.size.w*k.scale*k.screenScale);null==k.dH&&(k.dH=a.size.h*k.scale*k.screenScale);var l=a.size.w;d=a.size.h;0<=k.clipWidth&&(l*=k.clipWidth,k.dW*=k.clipWidth);"l"===k.halign[0]?b+=k.dW/2:"r"===k.halign[0]&&(b-=k.dW/2);"t"===k.valign[0]?c+=k.dH/2:"b"===k.valign[0]&&(c-=k.dH/2);null!=k.mX&&null!=k.mY&&(h=this.hitBox(b-k.dW/2,c-k.dH/2,k.dW,k.dH,k.mX,k.mY));var m=null!=(f=a.pivot)?f:{x:.5,y:.5};f=-k.dW*m.x;m=-k.dH*m.y;k.round&&(b=Math.round(b),c=Math.round(c),f=Math.round(f),m=Math.round(m));
if(k.mirror||0!==k.rotate)k.ctx.save(),k.ctx.translate(b,c),k.mirror&&k.ctx.scale(-1,1),0!==k.rotate&&k.ctx.rotate(k.rotate);else{f+=b;m+=c;if(!J.bboxIntersect(f,m,k.dW,k.dH,0,0,k.ctx.canvas.width,k.ctx.canvas.height)){null!=this.main.numSkippedDraws&&(this.main.numSkippedDraws+=1);return}k.ctx.save()}var p=k.useTinted?a.imgTinted:a.img;if(0===p.height||0===p.width)debugger;null!=k.silhouette&&null!=(null!=(e=a.silhouetteImg)?e[k.silhouette]:void 0)&&(p=a.silhouetteImg[k.silhouette]);if(a.extracted){if(null==
p)debugger;k.ctx.drawImage(p,0,0,l,d,f,m,k.dW,k.dH)}else k.ctx.drawImage(p,a.pos.x,a.pos.y,l,d,f,m,k.dW,k.dH);null!=this.main.numSpritesDraw&&(this.main.numSpritesDraw+=1);null!=this.main.numPixDraw&&(this.main.numPixDraw+=k.dW*k.dH);e=Math.max(0,1-k.damageTime);0<e&&(k.ctx.globalAlpha=e,e=config.colors.hitCharacter,null!=(null!=(g=a.silhouetteImg)?g[e]:void 0)&&k.ctx.drawImage(a.silhouetteImg[e],a.pos.x,a.pos.y,l,d,f,m,k.dW,k.dH));k.ctx.restore();null!=k.health&&this.drawHealthBar(b,c+k.dH/2,k.health,
k.maxHealth,{center:!0});return h}};z.prototype.drawHealthBar=function(a,b,c,d,e){e=void 0===e?{}:e;var f={center:!1,showText:!1};Object.merge(f,e);f.center&&(a-=this.s*(d+2));this.setImageSmoothing(!1);var g=2*(d+1)+1;var h=this.img.getSprite("hud_healthBar_empty.png");this.ctx.drawImage(h.img,0,0,g,h.size.h,a,b,g*this.s,h.size.h*this.s);e=2*(c+1)+1;h=this.img.getSprite("hud_healthBar_full.png");this.ctx.drawImage(h.img,0,0,e,h.size.h,a,b,e*this.s,h.size.h*this.s);this.drawSprite("hud_health_endPiece.png",
a+g*this.s-1,b,{});if(f.showText)return this.drawText(c+" / "+d,a+(g+6)*this.s,b+5*this.s,{font:config.fonts.technicalSmall,center:f.center})};z.prototype.drawHearts=function(a,b,c,d,e,f){e=void 0===e?!1:e;f=void 0===f?{}:f;var g=this.img.getSprite("hud_health_empty.png");var h=this.img.getSprite("hud_health_half.png");var k=this.img.getSprite("hud_health_full.png");var l=this.img.getSprite("hud_health_small.png");var m=this.img.getSprite("hud_health_small_empty.png");var p=g.dSize.w-1;e&&(a-=p*d/
4);for(e=0;0<d;)2<=c?this.drawSprite(k,a+p*e,b,f):1<=c?2<=d?this.drawSprite(h,a+p*e,b,f):this.drawSprite(l,a+p*e,b,f):2<=d?this.drawSprite(g,a+p*e,b,f):this.drawSprite(m,a+p*e,b,f),d-=2,c-=2,e+=1;return p*e};z.prototype.drawCharacter=function(a,b,c,d,e){e=void 0===e?{}:e;var f,g,h,k,l,m,p,w;a=null!=(k=b.sprite)?k:b.variations[0].sprite;null==e.scale&&(e.scale=1);e.showHealth&&(e.health=b.health,e.maxHealth=b.maxHealth);e.highlight&&this.drawSprite("hud_levelUp.png",c-5,d-60);null!=b.nudgeOffset&&
(c+=b.nudgeOffset.x*e.scale,d+=b.nudgeOffset.y*e.scale);null==e.mirror&&(e.mirror=b.mirrored);e.damageTime=b.damageTime;this.drawSprite(a,c,d,e)&&(g=b);a={halign:e.halign,valign:e.valign,mirror:e.mirror,scale:e.scale};b.isMountable&&(null!=b.mounted?(n.assert("No saddle sprite "+b.id,null!=b.extraSprites.saddle),this.drawSprite(b.extraSprites.saddle,c,d,a)):t.checkFlags("+packAnimal",b.flags)&&(n.assert("No crate sprite "+b.id,null!=b.extraSprites.crates),this.drawSprite(b.extraSprites.crates,c,d,
a)));if(null!=e.drawMount){k=this.img.getSprite(b.extraSprites.saddle);k=$jscomp.makeIterator(null!=(l=null!=k?k.dSize.mul(e.scale).lst():void 0)?l:[0,0]);l=k.next().value;k=k.next().value;var q=this.img.getSpriteSlots(b.extraSprites.saddle,this.s);b=null!=(f=null!=q?null!=(m=q.socket)?m.first().mul(e.scale):void 0:void 0)?f:new u(0,0);q=this.img.getSpriteSlots(e.drawMount.mountedSprite,this.s);f=null!=(h=null!=q?null!=(p=q.socket)?p.first().mul(e.scale):void 0:void 0)?h:new u(0,0);a.mirror&&(h=this.img.getSprite(e.drawMount.mountedSprite),
h=$jscomp.makeIterator(null!=(w=null!=h?h.dSize.mul(e.scale).lst():void 0)?w:[0,0]),w=h.next().value,h.next(),b.x=l-b.x,f.x=w-f.x);d=$jscomp.makeIterator([c+b.x-f.x-l/2,d+b.y-f.y-k]);c=d.next().value;d=d.next().value;this.drawSprite(e.drawMount.mountedSprite,c,d,{mirror:e.mirror,mX:e.mX,mY:e.mY,scale:e.scale})&&(g=e.drawMount)}return g};z.prototype.getDebugFont=function(){switch(this.main.pixelScaleSetting){case 1:return"8px Aldrich";case 2:return"12px Aldrich";case 3:return"18px Aldrich";case 6:return"32px Aldrich"}};
z.prototype.getDebugWatchFont=function(){switch(this.main.pixelScaleSetting){case 1:return"8px Courier New";case 2:return"12px Courier New";case 3:return"18px Courier New";case 6:return"38px Courier New"}};z.prototype.drawDebugWatches=function(){var a=$jscomp.makeIterator(this.getCanvasSize());var b=a.next().value;a=a.next().value;this.ctx.font=this.getDebugWatchFont();this.ctx.fillStyle="white";this.ctx.globalAlpha=1;var c=a/2;var d=this.debugWatches;var e=0;for(a=d.length;e<a;e++){var f=d[e];var g=
t.arrify(f());var h=0;for(f=g.length;h<f;h++){var k=g[h];this.drawText(k,b-5*this.s,c,{halign:"right"});c+=8*this.s}}};z.prototype.drawParticles=function(a){if(!(-1>this.zoomLevel))return this.part.drawParticles(a,this.cam.scroll)};z.prototype.drawDebugButton=function(a,b,c,d,e,f){e=void 0===e?60*this.s:e;f=void 0===f?{}:f;var g,h;var k=null!=(g=f.errors)?g:0;f=null!=(h=f.warnings)?h:0;c=this.hitBox(b,this.s,e,15*this.s,c,d);this.ctx.globalAlpha=1;this.ctx.strokeStyle=c?"red":"#aaa";this.ctx.strokeRect(b,
this.s,e,13*this.s);this.ctx.font=this.getDebugFont();this.ctx.fillStyle="white";this.drawText(a,b+e/2,10*this.s,{halign:"center"});0<k&&this.drawText(k,b+e/2+22*this.s,10*this.s,{halign:"center",fillColor:"red",os:0});0<f&&this.drawText(f,b+e/2+30*this.s,10*this.s,{halign:"center",fillColor:"yellow",os:0});return c};z.prototype.drawDebugCheckBox=function(a,b,c,d,e,f){f=void 0===f?138*this.s:f;d=this.hitBox(c,this.s,f,15*this.s,d,e);this.ctx.globalAlpha=1;this.ctx.strokeStyle=d?"red":"#aaa";this.ctx.strokeRect(c,
this.s,f,13*this.s);this.ctx.font=this.getDebugFont();this.ctx.fillStyle="white";this.ctx.fillText(b,c+13*this.s,10*this.s);a?this.ctx.fillRect(c+3*this.s,4*this.s,7*this.s,7*this.s):(this.ctx.strokeStyle="#aaa",this.ctx.strokeRect(c+3*this.s,4*this.s,7*this.s,7*this.s));return d};z.prototype.drawCheckbox=function(a,b,c,d,e){var f={os:0,txt:null,checked:!1,filled:0};Object.merge(f,e);e=$jscomp.makeIterator(this.getCanvasSize());e.next();e.next();this.drawSprite("hud_checkbox_neutral_small.png",a,
b-11*this.s);f.checked&&(f.filled=1);0<f.filled?(e=J.clamp(f.filled,0,1),this.drawSprite("hud_checkbox_enabled_small.png",a,b-11*this.s,{clipWidth:.7*e+.15}),null!=f.txt&&this.drawText(f.txt,a+7*this.s,b+1,{font:config.fonts.technicalLarge,fillColor:"white",halign:"center",os:0})):null!=f.txt&&this.drawText(f.txt,a+7*this.s,b+1,{font:config.fonts.technicalLarge,fillColor:"white",halign:"center"});return this.hitBox(a,b-11*this.s,14*this.s,14*this.s,c,d)};z.prototype.drawImageCheckbox=function(a,b,
c,d,e,f){var g={state:"neutral"};Object.merge(g,f);return this.drawSprite(a+"_"+g.state+".png",b,c,{mX:d,mY:e})};z.prototype.drawLoading=function(a,b){this.drawCloudIntro();return this.drawLoadingBar(a,b)};z.prototype.drawLoadingTitleBox=function(){if(!this.main.isWarping()&&!n.isDemo()&&null==this.main.tutorial){var a=$jscomp.makeIterator(this.getCanvasSize());var b=a.next().value;var c=a.next().value;var d=300*this.s;var e={halign:"center"};if(n.isIO()){var f=this.img.getSprite("title_rivals.png");
a=(f.size.h+52)*this.s;c=c/2-a/2-25*this.s;this.drawPanel(config.panel.info,b/2-d/2,c,d,a);return this.drawSprite(f,b/2,c+30*this.s,e)}c=c/2-75*this.s;this.drawPanel(config.panel.info,b/2-d/2,c,d,125*this.s);this.drawSprite("hud_expeditionStart_expedition.png",b/2,c+30*this.s,e);this.drawSprite("hud_expeditionStart_line.png",b/2,c+85*this.s,e);return this.drawSprite("hud_expeditionStart_"+(this.main.worldLvl+1)+".png",b/2,c+75*this.s,e)}};z.prototype.drawLoadingBar=function(a,b){var c=$jscomp.makeIterator(this.getCanvasSize());
var d=c.next().value;var e=c.next().value-30*this.s;c=100*this.s;this.ctx.lineWidth=this.s;this.ctx.fillStyle="black";this.ctx.fillRect(d/2-c/2,e,c,5*this.s);this.ctx.fillStyle="white";this.ctx.fillRect(d/2-c/2+2,e+2,c*a-4,5*this.s-4);this.ctx.font=config.fonts.technicalLarge;return this.drawText(b,d/2,e+20*this.s,{os:2,halign:"center"})};var qb=function(){var a=function(a){this.getParticlePositionForTilePos=this.getParticlePositionForTilePos.bind(this);this.isShowingExpeditionMap=this.isShowingExpeditionMap.bind(this);
this.r=a;this.emitters=[];this.particlesAbsolute=[];this.particlesRelative=[];this.particleQueue={}};a.prototype.inv=function(a){return Object.isArray(a)?a.map(function(a){return-a}):-a};a.prototype.addEmitter=function(a,b){var c;Object.isString(a)&&(a=t.getParticle(a));this.emitters.push({time:0,particle:a,area:b});if(0<(null!=(c=a.timeJump)?c:0))for(b=0,a=30*a.timeJump;0<=a?b<a:b>a;0<=a?++b:--b)this.tickParticles(1/30)};a.prototype.getParticlePositionForTilePos=function(a,b){var c;if(null!=b)return Object.isString(a)&&
(a=t.getParticle(a)),n.assert(null!=a),(null!=(c=null!=a?a.isAbsolute:void 0)?c:1)?this.r.getTileScreenPos(b,!1,!0,!0):b};a.prototype.isShowingExpeditionMap=function(){return"game"===this.r.main.getMainState()&&!this.r.main.showingEventDialogue()};a.prototype.addParticleConf=function(a,b,e){e=void 0===e?{}:e;var c,d,h,k,l,m,p,w,n,q,v,y,r,A,H,G,V,T,u,x,B,C,wb,z,E,rb,F,I,Za,K,L,M,N,O,P,Q,R,S,U,X,Z,W;Object.isString(a)&&(a=t.getParticle(a));if(null!=b){var aa=null!=(d=e.step)?d:0;d=null!=(h=null!=(l=
e.count)?l:a.count)?h:1;for(h=W=Z=0;0<=d?W<d:W>d;h=0<=d?++W:--W)l={id:null!=(Q=a.id)?Q:null,timer:null!=(R=a.timer)?R:[0,0],velX:null!=(S=a.velX)?S:0,velY:null!=(U=a.velY)?U:0,velScale:null!=(X=a.velScale)?X:0,velRot:null!=(m=a.velRot)?m:0,weight:null!=(p=a.weight)?p:0,isAbsolute:null!=(w=a.isAbsolute)?w:!0,cameraZoom:null!=(n=a.cameraZoom)?n:!0,scale:null!=(q=a.scale)?q:1,rot:null!=(v=a.rot)?v:0,maxTime:null!=(y=a.maxTime)?y:1,timeSteps:null!=(r=a.timeSteps)?r:.1,offsetX:null!=(A=a.offsetX)?A:0,
offsetY:null!=(H=a.offsetY)?H:0,outline:null!=(G=a.outline)?G:1,center:null!=(V=a.center)?V:!0,blinkRate:null!=(T=a.blinkRate)?T:5,interpTargetX:null!=(u=a.interpTargetX)?u:0,interpTargetY:null!=(x=a.interpTargetY)?x:0,velRadius:null!=(B=a.velRadius)?B:0,keys:null!=(C=a.keys)?C:[],color:null!=(wb=a.color)?wb:null,bgColor:null!=(z=a.bgColor)?z:null,font:null!=(E=a.font)?E:null,fadeStart:null!=(rb=a.fadeStart)?rb:null,queue:null!=(F=a.queue)?F:null,count:null!=(I=a.count)?I:null,queueDelay:null!=(Za=
a.queueDelay)?Za:null,mainParticle:null!=(K=a.mainParticle)?K:null,interpSpeed:null!=(L=a.interpSpeed)?L:null,interpStart:null!=(M=a.interpStart)?M:null,imgSrc:null!=(N=a.imgSrc)?N:null,text:null!=(O=a.text)?O:null,sfx:null!=(P=a.sfx)?P:null},Object.merge(l,e),this.explodePartValues(l,l,h),l.startPos=b,l.time=-l.timeSteps*aa-Z,l.pos=b,l.key=0,Z+=J.randA(l.timer),!l.isAbsolute&&1===Math.abs(Math.round(l.pos.x)%2)&&this.isShowingExpeditionMap()&&(l.offset.y+=l.cameraZoom?this.r.blockSize.h*this.r.biomeScaleFactor:
this.r.blockSize.h),null!=l.queue?(null==(c=this.particleQueue)[k=l.queue]&&(c[k]={time:100,list:[]}),this.particleQueue[l.queue].list.push(l)):l.isAbsolute?this.particlesAbsolute.add(l):this.particlesRelative.add(l)}};a.prototype.explodePartValues=function(a,d,e){null==a.vel&&(a.vel=new qa(0,0));null!=d.velX&&(a.vel.x=b(d.velX));null!=d.velY&&(a.vel.y=b(d.velY));null==a.offset&&(a.offset=new qa(0,0));d.offsetX&&(a.offset.x=b(d.offsetX));d.offsetY&&(a.offset.y=b(d.offsetY));!a.isAbsolute&&d.cameraZoom&&
(a.offset.x*=this.r.biomeScaleFactor,a.offset.y*=this.r.biomeScaleFactor);null!=d.scale&&(a.scale=b(d.scale));null!=d.velScale&&(a.velScale=b(d.velScale));null!=d.rot&&(a.rot=b(d.rot));null!=d.velRot&&(a.velRot=b(d.velRot));null!=d.interpSpeed&&(a.interpSpeed=b(d.interpSpeed));null!=d.interpStart&&(a.interpStart=b(d.interpStart));null!=d.fadeStart&&(a.fadeStart=b(d.fadeStart));if(0<a.velRadius){var c=2*Math.PI/d.count;e=e*c+(Math.random()-.5)*c;a.vel.x=Math.sin(e)*d.velRadius;a.vel.y=Math.cos(e)*
d.velRadius}null!=d.weight&&(a.weight=b(d.weight));if(null!=d.imgSrc)return a.sprite=t.arrify(d.imgSrc).sample()};a.prototype.tickParticles=function(a){var b,c;1E3<this.particleQueue.length&&r.warn("long particle queue! "+this.particleQueue.length);var f=this.emitters;var g=0;for(b=f.length;g<b;g++){var h=f[g];h.time-=a;if(0>=h.time){var k=new u(Number.random(h.area.w),Number.random(h.area.h));h.time=J.rand(0,h.particle.timer[1]);this.addParticleConf(h.particle,k)}}b=this.particleQueue;for(c in b)k=
b[c],h=k.list.first(),k.time+=a,k.time>(null!=h?h.queueDelay:void 0)&&(k.time=0,k.list.shift(),h.isAbsolute?this.particlesAbsolute.add(h):this.particlesRelative.add(h));this.particlesRelative=this.tickParticleList(a,this.particlesRelative);return this.particlesAbsolute=this.tickParticleList(a,this.particlesAbsolute)};a.prototype.tickParticleList=function(a,b){var c;var d=0;for(c=b.length;d<c;d++){var g=b[d];g.time+=a;if(0<=g.time){if(null!=g.interpStart&&g.time>=g.interpStart){var h=g.interpTarget;
g.pos.x+=(h.x-g.pos.x)*(a*g.interpSpeed*g.time*g.time).clamp(0,1);g.pos.y+=(h.y-g.pos.y)*(a*g.interpSpeed*g.time*g.time).clamp(0,1)}else g.vel.y+=a*g.weight;h=g.vel.mul(a);!g.isAbsolute&&this.isShowingExpeditionMap()&&(h.x*=1/this.r.biomeScreenSize.w,h.y*=1/this.r.biomeScreenSize.h);g.pos=g.pos.add(h);g.scale=Math.max(g.scale+a*g.velScale,0);g.rot+=a*g.velRot;0<g.keys.length&&g.keys.length>g.key&&(h=g.keys[g.key],g.time>=h.time&&(Object.merge(g,h),this.explodePartValues(g,h),g.key+=1))}}return b.filter(function(a){return a.time<
a.maxTime&&0<a.scale})};a.prototype.clearParticles=function(){var a;this.particlesAbsolute=[];this.particlesRelative=[];this.particleQueue=[];this.emitters=[];for(a=0;10>=a;++a)this.tickParticles(.1)};a.prototype.drawParticles=function(a,b){this.r.ctx.save();this.r.ctx.fillStyle="rgb(255, 0, 0)";var c=a?this.particlesAbsolute:this.particlesRelative;var d=0;for(a=c.length;d<a;d++){var g=c[d];if(!(0>g.time)){var h=1;if(null!=this.r.sfx&&null!=g.sfx){var k=this.r.sfx.getSound(g.sfx);null!=k&&(this.r.sfx.play(k),
g.sfx=null)}null!=g.fadeStart&&g.time>=g.fadeStart&&(h=1-(g.time-g.fadeStart)/(g.maxTime-g.fadeStart));null!=g.blinkStart&&g.time>=g.blinkStart&&(k=1/g.blinkRate,0===Math.floor(g.time/k)%2&&(h=0));this.r.ctx.globalAlpha=h;g.isAbsolute?(h=g.pos.x,k=g.pos.y):this.isShowingExpeditionMap()?(k=this.r.getTileScreenPos(g.pos,!0,!0,!0),h=k.x,k=k.y-this.r.hexOffset(g.pos.x)):(h=g.pos.x,k=g.pos.y,null!=b&&(h+=b.x,k+=b.y));h+=.5*g.offset.x*this.r.s;k+=.5*g.offset.y*this.r.s;var l=!g.isAbsolute&&g.cameraZoom?
this.r.biomeScaleFactor:1;if(null!=g.color)if(this.r.ctx.lineWidth=g.outline,null!=g.text){this.r.ctx.fillStyle=g.color;this.r.ctx.strokeStyle=g.bgColor;this.r.ctx.font=null!=g.font?6*this.r.s*g.scale+"px "+g.font:"bold "+6*this.r.s*g.scale+"px sans-serif";l=0;if(g.center){if(null==g.dim||1!==g.velScale)g.dim=this.r.ctx.measureText(g.text);l=g.dim.width/2}null!=g.bgColor&&this.r.ctx.strokeText(g.text,h-l,k);this.r.ctx.fillText(g.text,h-l,k)}else null!=g.bgColor&&(this.r.ctx.fillStyle=g.bgColor,this.r.ctx.fillRect(h+
1,k+1,2*this.r.s*g.scale*l,2*this.r.s*g.scale*l)),g.center&&(h-=this.r.s*g.scale,k-=this.r.s*g.scale),this.r.ctx.fillStyle=g.color,this.r.ctx.fillRect(h,k,2*this.r.s*g.scale*l,2*this.r.s*g.scale*l);else null!=g.sprite&&this.r.drawSprite(g.sprite,h+this.r.mapOffset.w,k+this.r.mapOffset.h,{halign:"center",valign:"center",scale:g.scale*l,rotate:g.rot});debug.logGeneralRenderStats&&(this.r.main.numParticlesRendered+=1)}}return this.r.ctx.restore()};var b=function(a){return Object.isArray(a)?J.randA(a):
a};return a}.call(this);var Ra=function(a,b,c,d,e){var f;this.r=a;this.onSelect=e;this.options=[];var g=0;for(a=d.length;g<a;g++)e=d[g],Object.isObject(e)?this.options.push(e):this.options.push({id:e});d=this.findOption(c);this.selected=c;this.title=null!=d?null!=(f=d.label)?f:d.id:b;this.mousePressed=!1;this.focus=[];this.active=!1;this.maxOptions=30;this.canQuery=!1;this.fillTitle=!0};Ra.prototype.moveCursor=function(a,b){var c,d;var e=this.getOptions();var f=this.focus.slice(0,-1);var g=0;for(c=
f.length;g<c;g++){var h=f[g];var k=0;for(d=e.length;k<d;k++){var l=e[k];if(l===h){e=l.entries;break}}}l=this.focus.length-1;if(0<=l)if(h=e.indexOf(this.focus[l]),0!==a&&(a=J.clamp(h+a,0,e.length-1),this.focus[l]=e[a]),0<b){if(null!=this.focus[l].entries)return this.focus.push(this.focus[l].entries[0])}else{if(0>b&&0<this.focus.length)return this.focus=this.focus.slice(0,-1)}else return this.focus[0]=e[0]};Ra.prototype.onKeyDown=function(a){if(38===a.which)return this.moveCursor(-1,0);if(39===a.which)return this.moveCursor(0,
1);if(40===a.which)return this.moveCursor(1,0);if(37===a.which)return this.moveCursor(0,-1);if(13===a.which)return this.onSelect(this.focus[this.focus.length-1].id);if(8===a.which)return a.ctrlKey||a.altKey||a.shiftKey||a.metaKey?this.query="":this.query=this.query.slice(0,-1);if(1===a.key.length&&null!=a.key.match(/[\w- ]/i))return null==this.query&&(this.query=""),this.query+=a.key};Ra.prototype.findOption=function(a,b){b=void 0===b?this.options:b;var c;var d=0;for(c=b.length;d<c;d++){var e=b[d];
if(null!=e.entries){var f=this.findOption(a,e.entries);if(null!=f)return f}if(e.id===a)return e}return null};Ra.prototype.draw=function(a,b,c,d,e){var f;var g=90*this.r.s;var h=b;b=this.r.hitBox(a,h,g,15*this.r.s,c,d);!this.mousePressed&&e&&b&&null!=this.selected&&null!=this.onSelect&&(this.onSelect(this.selected),this.mousePressed=!0);e||(this.mousePressed=!1);this.r.ctx.lineWidth=2;this.r.ctx.globalAlpha=1;this.r.ctx.strokeStyle=b?"red":"#aaa";this.r.ctx.strokeRect(a,h,g,13*this.r.s);this.r.ctx.font=
this.r.getDebugFont();this.r.ctx.fillStyle="white";g=null!=this.query?this.query+"_":b&&this.canQuery?"<Type to search>":null!=(f=this.title)?f:"";this.r.ctx.fillText(g,a+8*this.r.s,10*this.r.s);b||this.wasHit||null!=this.focus[0]?(h+=13*this.r.s,f=this.getOptions(),a=this.drawEntries(f,0,a,h,c,d,e),this.wasHit||a||(this.focus=[])):this.query=null;this.active=null!=this.focus[0]||b;this.lastMouse=new u(c,d);return this.wasHit=b};Ra.prototype.getOptions=function(){if(null!=this.query){var a=this.query.split(" ").map(function(a){return new RegExp(a,
"i")});return this.scanOptions(this.options,a)}return this.options};Ra.prototype.scanOptions=function(a,b){var c=[];var d=t.arrify(a);var e=0;for(a=d.length;e<a;e++){var f=d[e];null==f.entries&&b.all(function(a){return a.test(f.id)})&&c.push(f);null!=f.entries&&c.add(this.scanOptions(f.entries,b))}return c};Ra.prototype.drawEntries=function(a,b,c,d,e,f,g){var h,k,l;var m=90*this.r.s;this.r.ctx.fillStyle="black";this.r.ctx.fillRect(c,d,m,10*Math.min(this.maxOptions,a.length)*this.r.s);var p=this.r.hitBox(c-
3*this.r.s,d-3*this.r.s,m,23*this.r.s+10*a.length*this.r.s,e,f);var w=l=0;for(h=a.length;l<h;w=++l){var n=a[w];var q=null!=n.entries;var v=this.r.hitBox(c,d,m,10*this.r.s,e,f);p||(p=v);var t=n.id;var r=null!=(k=n.label)?k:t;!v||e===this.lastMouse.x&&f===this.lastMouse.y||(this.focus[b]=n);this.focus[b]===n&&(this.r.ctx.fillStyle="red",this.r.ctx.fillRect(c,d,m,10*this.r.s));this.r.ctx.fillStyle=this.selected===t?"orange":"white";this.r.ctx.fillText(r,c+9*this.r.s,d+7*this.r.s);q&&(this.r.ctx.fillRect(c+
m-8*this.r.s,d+5*this.r.s,3*this.r.s,1*this.r.s),this.r.ctx.fillRect(c+m-7*this.r.s,d+4*this.r.s,1*this.r.s,3*this.r.s));if(q)this.focus[b]===n&&this.drawEntries(n.entries,b+1,c+m-3*this.r.s,d,e,f,g)&&(p=!0);else if(v&&g&&!this.mousePressed&&(this.selected=t,this.fillTitle&&(this.title=r),null!=this.onSelect))this.onSelect(t);if(w>this.maxOptions)break;d+=10*this.r.s}this.mousePressed=g;return p};Ra.toComboList=function(a){var b;var c=[];a=a.groupBy(function(a){var b;return null!=(b=a.debugCategory)?
b:"etc"});for(b in a){var d=a[b];d=d.filter(function(a){return!a.isAbstract}).map(function(a){return{id:a.id}});c.push({id:b,entries:d})}return c};var yb=function(a,b,c){this.col1=a;this.col2=b;this.targetTime=this.targetValue=this.value=0;this.targetDelay=void 0===c?1.5:c;this.increasing=!1};yb.prototype.setValue=function(a){if(a!==this.targetValue)return this.targetValue=a,this.targetTime=0,this.increasing=this.targetValue>this.value};yb.prototype.setHighlight=function(a){return this.highlightValue=
Math.max(0,a)};yb.prototype.tick=function(a){return this.targetTime>this.targetDelay?(this.value+=a*(this.targetValue-this.value),this.increasing?this.value=Math.min(this.value,this.targetValue):this.value=Math.max(this.value,this.targetValue)):this.targetTime+=a};yb.prototype.drawBar=function(a,b,c,d,e,f,g){.1>this.targetTime&&(d-=2,f+=4);this.value=J.clamp(this.value,0,b);var h=Math.min(this.value,this.targetValue);var k=Math.max(this.value,this.targetValue);null!=g&&(a.fillStyle=g,a.fillRect(c,
d,e,f));h!==k&&(a.fillStyle=this.col2,a.fillRect(c,d,k/b*e,f));a.fillStyle=this.col1;a.fillRect(c,d,h/b*e,f);if(this.highlightValue!==this.value)return g=e*(this.targetValue-this.highlightValue)/b,a.fillStyle=config.colors.sanityHighlight,a.fillRect(c+this.highlightValue/b*e,d,g,f)};var Qc=yb;var ia=function(a){this.checkCompatibility=this.checkCompatibility.bind(this);this.getCompatibilityIssues=this.getCompatibilityIssues.bind(this);this.getCompatibilityString=this.getCompatibilityString.bind(this);
this.packColor=this.packColor.bind(this);this.unpackColor=this.unpackColor.bind(this);this.packColorTable=this.packColorTable.bind(this);this.unpackColorTable=this.unpackColorTable.bind(this);this.packGenLayer=this.packGenLayer.bind(this);this.unpackGenLayer=this.unpackGenLayer.bind(this);this.packGenLayers=this.packGenLayers.bind(this);this.unpackGenLayers=this.unpackGenLayers.bind(this);this.unpackPerson=this.unpackPerson.bind(this);this.main=a;this.saving=this.loading=!1;window.isClient&&!n.isIO()||
n.isDemo()||(this.user=this.main.user);this.saveTime=null;this.loadSaveGame()};ia.prototype.getInfo=function(){return null!=this.sg&&this.checkCompatibility()?{world:this.sg.world,fame:this.sg.fame,funds:this.sg.funds}:null};ia.prototype.checkCompatibility=function(){if(null==this.sg)return!1;try{var a=this.getCompatibilityIssues();return 0===a.missing.length&&0===a.extra.length}catch(b){return!1}};ia.prototype.getCompatibilityIssues=function(){if(null==this.sg||!n.isTCE()||null==this.sg.version)return{missing:[],
extra:[]};var a=$jscomp.makeIterator(this.sg.version.split("."));var b=a.next().value;var c=a.next().value;var d=a.next().value;a=a.next().value;if(1>=parseInt(b)&&3>=parseInt(c)&&11>=parseInt(d)&&8>=parseInt(a))return{missing:[],extra:[]};d=[];b=[];var e=this.main.modding.activeMods();c=function(a){var b;var c=0;for(b=e.length;c<b;c++){var d=e[c];if(d.id===a)return!0}return!1};if(this.main.modding.active){var f=0;for(a=e.length;f<a;f++){var g=e[f];null!=this.sg.enabledMods&&0!==this.sg.enabledMods.filter(function(a){return a.id===
g.id}).length||b.push(g)}}if(null!=this.sg.enabledMods){f=this.sg.enabledMods;var h=0;for(a=f.length;h<a;h++)g=f[h],this.main.modding.active&&c(g.id)||d.push(g)}return{missing:d,extra:b}};ia.prototype.getCompatibilityString=function(a){var b;var c=[];var d=this.getCompatibilityIssues();0<d.missing.length&&c.add(q.toText("txt-mod-missing"));var e=d.missing;var f=0;for(b=e.length;f<b;f++)a=e[f],c.add(a.id+" v"+a.version);0<d.extra.length&&c.add(q.toText("txt-mod-extra"));b=d.extra;e=0;for(d=b.length;e<
d;e++)a=b[e],c.add(""+a.name);return c};ia.prototype.updateSaveGame=function(){var a=this,b,c,d,e,f,g;if(null==this.main.tutorial&&!debug.skipSaveGames){var h=this.main.worldStack;var k=0;for(c=h.length;k<c;k++){var l=h[k];if(!l.generated)return}if(!n.isIO()||!this.main.gameOver&&null==(null!=(d=this.main.party)?null!=(e=d.stats)?e.deathReason:void 0:void 0)){this.saveTime=new Date;null!=this.main.exped&&(this.lastSavedTurn=this.main.exped.turn);c={world:this.main.worldLvl,difficulty:this.main.difficultyLvl,
fame:this.main.party.fame,funds:this.main.party.funds,karma:this.main.party.karma,flags:this.main.party.flags,noCombat:this.main.party.noCombat,xp:this.main.party.xp,mapScore:this.main.party.mapScore,lifetimeMapScore:this.main.party.lifetimeMapScore,version:n.getVersionString(),autoBegin:null!=(b=this.autoBegin)?b:{}};n.isIO()&&(c.worldSeed=this.main.iomp.worldData.worldSeed,c.turnsForStandingBias=this.main.party.turnsForStandingBias);c.enabledMods=[];null!=this.main.modding.activeMods()&&(c.enabledMods=
this.main.modding.activeMods().map(function(a){return{id:a.id,version:a.version}}));this.main.worldDone||null==this.main.exped||(c.exped=this.packExped());null!=(null!=(f=this.main.worldmap)?f.sites:void 0)&&(c.worldMapSeed=this.main.worldmap.worldMapSeed,c.sites=function(){var a;var b=this.main.worldmap.sites;var c=[];var d=0;for(a=b.length;d<a;d++)g=b[d],c.push(this.packSite(g));return c}.call(this),c.rivalSites=function(){var a;var b=this.main.worldmap.rivalSites;var c=[];var d=0;for(a=b.length;d<
a;d++)g=b[d],c.push(this.packSite(g));return c}.call(this));if(null==c.exped&&null==c.sites)throw Error("invalid savegame created");d={};f=this.main.rivals;e=0;for(b=f.length;e<b;e++)h=f[e],d[h.character.id]={fame:h.fame,fameScale:h.fameScale,turn:h.turn,arrivedTurn:h.arrivedTurn,blockedTurns:h.blockedTurns};c.rivals=d;c.items=this.packItems(this.main.party.inv.items);c.persons=this.packPersons(this.main.party.persons);c.store=this.packPersons(this.main.party.store);this.main.party.isInventoryChangedSinceSave=
!1;this.sg=c;if(window.isClient&&!n.isIO()||n.isDemo()||debug.forceLocalSaveGame)b=JSON.stringify(c),r.info("SAVEGAME;updated: size "+b.length),O.writeProfile("sgdata.ls",b,"saveGame");else if(n.isIO()&&!debug.disableIOMP)this.main.iomp.storeSaveData(c);else if(null!=this.user){b={base64:Base64.encode(JSON.stringify(c))};r.info("SAVEGAME;updated: size "+b.base64.length);var m=new Parse.File("savegame.json",b,"application/json");this.saving=!0;m.save().then(function(b){r.info("SAVEGAME;created");a.user.set("saveGameFile",
m);zb.saveUser();return a.saving=!1},function(b){r.info("SAVEGAME;failed creation: "+b);return a.saving=!1})}}}};ia.prototype.loadSaveGame=function(){var a=this;if(window.isClient&&!n.isIO()||debug.forceLocalSaveGame){this.sg=O.loadProfile("sgdata.ls","saveGame");if("function"===typeof this.onSaveGameLoaded)this.onSaveGameLoaded();return this.onSaveGameLoaded=null}if(n.isIO()&&!debug.disableIOMP)return this.loading=!0,this.main.iomp.getSaveData().then(function(b){a.sg=b;a.loading=!1;a.saveTime=new Date;
if("function"===typeof a.onSaveGameLoaded)a.onSaveGameLoaded();return a.onSaveGameLoaded=null},function(b){r.info("SAVEGAME;failed loading: "+b);a.loading=!1;if("function"===typeof a.onSaveGameLoaded)a.onSaveGameLoaded();return a.onSaveGameLoaded=null});if(null!=this.user){var b=this.user.get("saveGameFile");if(null!=b)return this.loading=!0,O.readFileAsync(b.url(),function(b){a.sg=JSON.parse(b);a.loading=!1;a.saveTime=new Date;if("function"===typeof a.onSaveGameLoaded)a.onSaveGameLoaded();return a.onSaveGameLoaded=
null},function(b){r.info("SAVEGAME;failed loading: "+b);a.loading=!1;if("function"===typeof a.onSaveGameLoaded)a.onSaveGameLoaded();return a.onSaveGameLoaded=null},{sync:!1})}};ia.prototype.restoreSaveGame=function(a){a=void 0===a?this.sg:a;var b,c,d,e,f,g,h,k,l,m,p,w,q;r.info("save game: restored");if(null==a)return r.error("save game: not found"),!1;if(!this.checkCompatibility())return r.error("savegame not compatible"),r.error(this.getCompatibilityIssues()),!1;if(n.isIO()){var t=null!=(c=a.worldSeed)?
c:this.main.iomp.worldData.worldSeed;Object.isString(t)&&(t=a.worldSeed=parseInt(t));if(t!==this.main.iomp.worldData.worldSeed)return r.warn("savegame IO seed doesn't match; aborting"),!1}this.main.worldLvl=a.world;this.main.difficultyLvl=null!=(d=a.difficulty)?d:1;this.main.restoredSaveGame=null!=(g=a.version)?g:"-";this.main.party.fame=a.fame;this.main.party.funds=a.funds;this.main.party.karma=a.karma;this.main.party.flags=null!=(h=a.flags)?h:{};this.main.party.xp=null!=(k=null!=(l=a.xp)?l:a.biomePoints)?
k:0;this.main.party.noCombat=a.noCombat;n.isIO()&&(this.main.party.turnsForStandingBias=null!=(m=a.turnsForStandingBias)?m:config.io.turnsForStandingBias);this.main.party.changeMapScore(null!=(p=a.mapScore)?p:0,!1);this.main.party.lifetimeMapScore=null!=(w=a.lifetimeMapScore)?w:this.main.party.mapScore;this.main.rivals=[];d=a.rivals;for(v in d)c=d[v],this.main.rivals.push({character:new Fa(this.main,v),fame:c.fame,fameScale:c.fameScale,turn:c.turn,arrivedTurn:c.arrivedTurn,blockedTurns:null!=(b=c.blockedTurns)?
b:0});this.main.party.inv.items=this.unpackItems(a.items);c=this.unpackPersons(a.persons);d=0;for(b=c.length;d<b;d++){var v=c[d];this.main.party.addCharacter(v);v.mounted&&this.main.party.mount(v,this.main.party.getExplorer())}c=this.unpackPersons(a.store);d=0;for(b=c.length;d<b;d++)v=c[d],this.main.party.store.push(v);null!=a.exped?this.unpackExped(a.exped,a.version):null!=this.main.worldmap&&(this.main.worldmap.worldMapSeed=null!=(e=a.worldMapSeed)?e:0,this.main.worldmap.sites=function(){var b;
var c=a.sites;var d=[];var e=0;for(b=c.length;e<b;e++)q=c[e],d.push(this.unpackSite(q));return d}.call(this),this.main.worldmap.rivalSites=function(){var b;var c=a.rivalSites;var d=[];var e=0;for(b=c.length;e<b;e++)q=c[e],d.push(this.unpackSite(q));return d}.call(this));this.autoBegin=null!=(f=a.autoBegin)?f:null;return this.main.party.getExplorer()?!0:!1};ia.prototype.clearSaveGame=function(){if(!debug.skipSaveGames)return window.isClient&&!n.isIO()||n.isDemo()||debug.forceLocalSaveGame?O.deleteProfile("sgdata.ls",
"saveGame"):n.isIO()&&!debug.disableIOMP?this.main.iomp.storeSaveData(null):null!=this.user&&(this.user.set("saveGameFile",null),zb.saveUser()),this.autoBegin=this.sg=null};ia.prototype.packSite=function(a){var b=a.gen.world.getBiomes().map(function(a){return{id:a.id,isBlocking:a.blocking,locationQueue:a.locationQueue}});return{locationX:a.location.x,locationY:a.location.y,name:a.name,worldId:a.gen.worldId,pocketId:a.gen.pocketId,goalId:a.gen.goalId,biomeStartPos:a.gen.world.biomeStartPos,genBiomes:b}};
ia.prototype.unpackSite=function(a){var b,c;var d=new ba(this.main,a.worldId,a.pocketId,a.goalId);null!=a.biomeStartPos&&(d.world.biomeStartPos=u.fromObj(a.biomeStartPos));var e=a.genBiomes;var f=c=0;for(b=e.length;c<b;f=++c){var g=e[f];f=d.world.getBiomes()[f];f.setup(g.id,g.isBlocking);f.locationQueue=g.locationQueue}return{location:new u(a.locationX,a.locationY),name:a.name,gen:d}};ia.prototype.packItems=function(a){var b;var c=[];var d=a.compact();var e=0;for(b=d.length;e<b;e++){a=d[e];var f=
{id:a.id,amount:a.amount,dayAge:a.dayAge,tripAge:a.tripAge};0<a.chargeTime&&(f.chargeTime=a.chargeTime);null!=a.miniMap&&(f.mapCenter=a.miniMap.center,f.mapOffset=a.miniMap.offset);0<a.subItems.length&&(f.subItems=a.subItems.map(function(a){return{id:a.id,taxSet:a.taxSet}}));c.push(f)}return c};ia.prototype.unpackItems=function(a){var b,c;var d=[];var e=0;for(b=a.length;e<b;e++){var f=a[e];var g=new jb(this.main,f.id);g.amount=f.amount;g.dayAge=f.dayAge;g.tripAge=f.tripAge;g.chargeTime=null!=(c=f.chargeTime)?
c:0;null!=g.miniMap&&null!=f.mapCenter&&(g.miniMap.center=u.fromObj(f.mapCenter),g.miniMap.offset=u.fromObj(f.mapOffset));var h=t.arrify(f.subItems);var k=0;for(f=h.length;k<f;k++){var l=h[k];var m=new jb(this.main,l.id);null!=l.taxSet&&(m.amount=1,m.taxSet=l.taxSet,m.canvas=this.main.taxonomy.createCanvas(l.taxSet));g.subItems.push(m)}d.push(g)}return d};ia.prototype.packPersons=function(a){var b;var c=[];var d=0;for(b=a.length;d<b;d++){var e=a[d];c.push(this.packPerson(e))}return c};ia.prototype.packPerson=
function(a){var b;var c=Object.map(a.statuses,function(a,b){return{dayAge:b.dayAge,tripAge:b.tripAge,isDefault:b.isDefault,buffDelayDays:b.buffDelayDays,buffDelayDaysInit:b.buffDelayDaysInit,buffDelayTrips:b.buffDelayTrips,buffDelayTripsInit:b.buffDelayTripsInit,buffDays:b.buffDays,buffDaysInit:b.buffDaysInit,buffTrips:b.buffTrips,buffTripsInit:b.buffTripsInit}});return{id:a.id,name:a.name,gender:a.gender,level:a.level,variationIdx:a.variationIdx,statuses:c,health:a.health,regenTurn:a.regenTurn,loyalty:a.loyalty,
storeAge:a.storeAge,genLayers:this.packGenLayers(a.genLayers),colorTable:this.packColorTable(a.colorTable),flags:a.flags,mounted:null!=a.mounted,sourceTribeGenId:a.sourceTribeGenId,sourceTribeGenSeed:null!=(b=a.sourceTribeGenSeed)?b:0}};ia.prototype.unpackPersons=function(a){var b;var c=[];var d=0;for(b=a.length;d<b;d++){var e=a[d];e=this.unpackPerson(e);c.push(e)}return c};ia.prototype.packColor=function(a){return{r:a.r,g:a.g,b:a.b}};ia.prototype.unpackColor=function(a){return{r:a.r,g:a.g,b:a.b}};
ia.prototype.packColorTable=function(a){var b=this;return null==a?null:a.map(function(a){return{col1:b.packColor(a.col1),col2:b.packColor(a.col2)}})};ia.prototype.unpackColorTable=function(a){var b=this;return null==a?null:a.map(function(a){return{col1:b.unpackColor(a.col1),col2:b.unpackColor(a.col2)}})};ia.prototype.packGenLayer=function(a){return null==a?null:a.map(function(a){var b;return{alpha:a.alpha,sprite:a.sprite,useInSmall:null!=(b=a.useInSmall)?b:!1}})};ia.prototype.unpackGenLayer=function(a){return null==
a?null:a.map(function(a){var b;return{alpha:a.alpha,sprite:a.sprite,useInSmall:null!=(b=a.useInSmall)?b:!1}})};ia.prototype.packGenLayers=function(a){return null==a?null:{body:this.packGenLayer(a.body),portrait:this.packGenLayer(a.portrait),mounted:this.packGenLayer(a.mounted)}};ia.prototype.unpackGenLayers=function(a){return null==a?null:{body:this.unpackGenLayer(a.body),portrait:this.unpackGenLayer(a.portrait),mounted:this.unpackGenLayer(a.mounted)}};ia.prototype.unpackPerson=function(a){var b,
c,d,e,f,g,h,k,l;var m=new Fa(this.main,a.id);if(null!=m.id){m.isSpecial&&(this.main.party.explorerId=m.id);m.name=a.name;m.setVariation(a.variationIdx);m.setLevel(a.level);m.health=a.health;m.regenTurn=a.regenTurn;m.baseLoyalty=a.loyalty;m.storeAge=a.storeAge;m.genLayers=this.unpackGenLayers(a.genLayers);m.colorTable=this.unpackColorTable(a.colorTable);null!=a.flags&&(m.flags=a.flags);a.mounted&&(m.mounted=!0);null!=a.sourceTribeGenId&&""!==a.sourceTribeGenId&&null==m.genLayers&&null==m.colorTable?
m.initCharGen(a.sourceTribeGenId,a.sourceTribeGenSeed):null!=m.genLayers&&null!=m.colorTable&&(m.sprite="native",m.updateSprite(this.main.tribeGen),null!=a.sourceTribeGenId&&(m.sourceTribeGenId=a.sourceTribeGenId),null!=a.sourceTribeGenSeed&&(m.sourceTribeGenSeed=a.sourceTribeGenSeed));m.statuses={};a=a.statuses;for(l in a){var p=a[l];l.startsWith("pk-")&&(l="st-"+l.slice(3));if(null!=t.getStatus(l,!1)){var w=new kc(l,!1,m.gender);w.dayAge=p.dayAge;w.tripAge=p.tripAge;w.isDefault=p.isDefault;w.buffDelayDays=
null!=(b=p.buffDelayDays)?b:0;w.buffDelayDaysInit=null!=(c=p.buffDelayDaysInit)?c:0;w.buffDelayTrips=null!=(d=p.buffDelayTrips)?d:0;w.buffDelayTripsInit=null!=(e=p.buffDelayTripsInit)?e:0;w.buffDays=null!=(f=p.buffDays)?f:0;w.buffDaysInit=null!=(g=p.buffDaysInit)?g:0;w.buffTrips=null!=(h=p.buffTrips)?h:0;w.buffTripsInit=null!=(k=p.buffTripsInit)?k:0;m.statuses[l]=w}}return m}};ia.prototype.packExped=function(){var a=this,b,c;var d=this.main.party;var e=this.main.exped;var f=this.main.worldStack.map(function(b){return a.packWorld(b)});
n.assert(0<f.length);e={turn:e.turn,compassScore:e.compassScore,colorTable:this.packColorTable(null!=(c=this.main.tribeGen)?c.colorTable:void 0),sanity:d.sanity,standing:d.standing,partyPos:d.pos,butterflies:d.butterflies,itemStatuses:d.itemStatuses,visitedPockets:d.visitedPockets,unlockedPockets:d.unlockedPockets,visitedLocations:d.visitedLocations,playTime:d.playTime,legs:d.legs.map(function(a){return[a[0].x,a[0].y,a[1]]}),moves:d.moves,worlds:f,diaryLogEntries:this.main.diaryLogEntries,raceTrack:e.raceTrack,
globalInv:{}};f=this.main.globalInvs;for(b in f)c=f[b],null!=c&&(e.globalInv[b]=this.packItems(c.items));n.isIO()&&(e.highscoreRow=this.main.iomp.highscoreRow,e.lastPostedHighscore=this.main.iomp.lastPostedHighscore,e.partyStats=d.stats,e.notifiedClaims=d.notifiedClaims);return e};ia.prototype.packBiome=function(a,b,c,d,e,f){f=void 0===f?!1:f;var g,h,k,l;var m=function(a,b){var c;for(c in a){var d=a[c];if(b[c]!==d)return!1}for(c in b)if(d=b[c],a[c]!==d)return!1;return!0};n.assert(null!=a&&a.generated);
var p=t.getBiome(a.id);var w=null!=(k=t.parseFlags(p.flags)[0])?k:{};k={id:a.id,pos:a.pos,isBlocking:a.blocking,hasVoid:a.hasVoid,hasSprawl:a.hasSprawl,conquered:a.conquered,entered:a.entered,worldLvl:a.worldLvl,tiles:[]};m(w,a.flags)||(k.flags=a.flags);var q=a.tiles;var D=0;for(h=q.length;D<h;D++)if(p=q[D],null!=p&&null!=p.id&&(p.changed||f)){var v=t.getTile(p.id);n.assert(null!=v);var y={t:b[p.id],tilePos:p.pos};p.originalId!==p.id&&(y.to=b[p.originalId]);p.known&&(y.k=p.known);p.farKnown&&(y.fk=
p.farKnown);p.particle!==v.particle&&(y.pt=p.particle);w=e[p.id];null==w&&(w=null!=(l=t.parseFlags(v.flags)[0])?l:{},e[p.id]=w);m(w,p.flags)||(y.flags=p.flags);w=d[p.id];null==w&&(w=new Ab,w.setup(p.id),d[p.id]=w);w=this.packSprawls(p,c,w);null!=w&&(y.sprawls=w);if(null!=p.location&&(w=t.getLocation(p.location.id),y.location={id:p.location.id,flags:p.location.flags,known:p.location.known?p.location.known:void 0,everUsed:p.location.everUsed?p.location.everUsed:void 0,pt:p.location.particle!==w.particle?
p.location.particle:void 0,age:p.location.dayAge},0<Object.keys(p.location.invs).length))for(g in y.location.invs={},w=p.location.invs,w)p=w[g],y.location.invs[g]={},y.location.invs[g].items=this.packItems(p.items),y.location.invs[g].meta=p.didEverTransferMeta;k.tiles.push(y)}if(!f&&k.tiles.length!==a.tiles.length)for(k.knownTiles=[],b=a.tiles,c=0,a=b.length;c<a;c++)p=b[c],null!=p&&null!=p.id&&!p.changed&&p.known&&k.knownTiles.push(p.pos);return k};ia.prototype.packWorld=function(a){var b,c,d,e;var f=
{worldId:a.id,pocketId:a.pocketId,goalId:a.goalId,worldFlags:a.flags,startPos:a.startPos,warpPos:a.warpPos,warpStanding:a.warpStanding,worldSeed:a.worldSeed,biomes:[],zones:[],tileTable:Object.keys(config.tiles),sprawlTable:Object.keys(config.sprawls)};n.isIO()&&(f.zoneSpawns=a.zoneSpawns,f.locationSpawns=a.locationSpawns);var g={};var h=f.tileTable;var k=d=0;for(c=h.length;d<c;k=++d){var l=h[k];g[l]=k}c={};l=f.sprawlTable;k=e=0;for(h=l.length;e<h;k=++e)d=l[k],c[d]=k;k={};h={};if(n.isIO()&&a===this.main.worldGenIO.world)for(b in d=
this.main.worldGenIO.biomes,d)l=d[b],null!=l.biome&&l.biome.generated?f.biomes.push(this.packBiome(l.biome,g,c,k,h)):null!=l.sgData&&f.biomes.push(l.sgData);else{d=a.biomes;for(b in d)l=d[b],f.biomes.push(this.packBiome(l,g,c,k,h,!0));n.assert(0<f.biomes.length)}g=a.zones;a=0;for(b=g.length;a<b;a++)c=g[a],k={id:c.id,center:c.center},c.seeking&&(k.seeking=!0),0<c.seekTurns&&(k.seekTurns=c.seekTurns),f.zones.push(k);return f};ia.prototype.packSprawls=function(a,b,c){var d;var e=null;var f=a.sprawls;
for(d in f){var g=f[d];a=c.sprawls[d];if(g.lifeTime!==a.lifeTime||g.active)e=null!=e?e:[],e.push({s:b[d],active:g.active,lt:g.lifeTime,pw:g.power})}return e};ia.prototype.unpackSprawls=function(a,b,c){if(Object.isArray(b)){var d=t.arrify(b);var e=0;for(b=d.length;e<b;e++){var f=d[e];var g=c[f.s];g=a.sprawls[g];null!=g&&(g.active=f.active,g.lifeTime=f.lt,g.power=f.pw)}}else null!=b&&(a.sprawls=null!=b?b:{})};ia.prototype.unpackExped=function(a,b){var c,d,e,f,g,h,k,l,m,p,w,q,t;var v=this.main.party;
v.sanity=a.sanity;v.standing=a.standing;v.butterflies=null!=(c=a.butterflies)?c:0;v.itemStatuses=null!=(m=a.itemStatuses)?m:[];v.visitedPockets=null!=(p=a.visitedPockets)?p:[];v.unlockedPockets=a.unlockedPockets;v.visitedLocations=null!=(w=a.visitedLocations)?w:0;v.playTime=null!=(q=a.playTime)?q:0;c=this.main.resetExped(!1);n.isIO()&&(this.main.iomp.highscoreRow=null!=(t=a.highscoreRow)?t:null,this.main.iomp.lastPostedHighscore=null!=(g=a.lastPostedHighscore)?g:0,null!=a.partyStats&&(this.main.party.stats=
a.partyStats),v.notifiedClaims=null!=(h=a.notifiedClaims)?h:[]);n.isIO()?(g=$jscomp.makeIterator(b.split(".")),b=g.next().value,t=g.next().value,g.next(),m=$jscomp.makeIterator(n.getVersionString().split(".")),g=m.next().value,h=m.next().value,m.next(),b=b===g&&t===h,debug.skipSGWorld&&(b=!1)):b=!0;if(b){if(null!=this.main.worldGenIO){var y=this.main.worldGenIO.world;this.main.worldGenIO.worldGenQueue=[]}t=a.worlds;g=0;for(b=t.length;g<b;g++)h=t[g],null!=y?(this.unpackWorld(h,y),this.main.pushWorld(y),
y=null):(h=this.unpackWorld(h),this.main.pushWorld(h));n.assert(null==y)}else this.main.worldGenIO.startNewGame(this.main.worldGenIO.unlockedHubs.last()),this.main.pushWorld(this.main.worldGenIO.world);c.world.startPos=u.fromObj(a.partyPos);y=c.world.getTile(c.world.startPos);null!=y&&null!=y.biome&&y.biome.generated?c.placeParty(c.world.startPos):(n.assert(n.isIO()),this.main.worldGenIO.playerStartBiome=c.world.toBiomePos(c.world.startPos),this.main.worldGenIO.generateBiome(this.main.worldGenIO.playerStartBiome));
c.turn=a.turn;this.lastSavedTurn=c.turn;c.raceTrack=null!=(f=a.raceTrack)?f:[];y=c.raceTrack;t=0;for(f=y.length;t<f;t++)b=y[t],null!=b.inDays&&(b.onDay=b.inDays+c.turn,delete b.inDays);v.legs=(null!=(k=a.legs)?k:[]).map(function(a){return[new u(a[0],a[1]),a[2]]});v.moves=(null!=(l=a.moves)?l:[]).map(function(a){return qa.fromObj(a)});c.changeCompassScore(a.compassScore);c.shipArrived=!0;null!=(v=this.main.tribeGen)&&(v.colorTable=this.unpackColorTable(a.colorTable));null!=c.world.startPos&&this.main.r.cam.centerOnPos(c.world.startPos);
this.main.diaryLogEntries=a.diaryLogEntries;this.main.globalInvs={};a=null!=(e=a.globalInv)?e:{};for(d in a)e=a[d],this.main.globalInvs[d]=new Va(this.main),this.main.globalInvs[d].items=this.unpackItems(e)};ia.prototype.unpackBiome=function(a,b,c,d,e){var f,g,h,k,l,m,p,w,q,t;a.hasVoid=d.hasVoid;a.hasSprawl=d.hasSprawl;a.conquered=null!=(g=d.conquered)?g:!1;a.entered=null!=(k=d.entered)?k:!1;null!=d.flags&&(a.flags=d.flags);a.worldLvl=null!=(f=d.worldLvl)?f:0;a.generated=!0;k=d.tiles;f=t=0;for(g=
k.length;t<g;f=++t){var v=k[f];f=e.getTile(v.tilePos);var y=null!=f&&null!=f.location?f.location.name:null;n.assert(f.biome===a);null!=v.id?f.setup(v.id):(f.setup(b[v.t]),f.originalId=b[null!=(l=v.to)?l:v.t]);null!=v.flags&&(f.flags=v.flags);this.unpackSprawls(f,v.sprawls,c);f.known=n.isTrue(null!=(m=v.k)?m:v.known);f.farKnown=n.isTrue(null!=(p=v.fk)?p:v.farKnown);var r=null!=(w=v.pt)?w:v.particle;null!=r&&(f.particle=r);if(null!=v.location&&(r=new sb(v.location.id),null!=y&&(r.name=y),f.location=
r,r.setup(f.biome,f.pos),r.known=n.isTrue(v.location.known),r.everUsed=n.isTrue(v.location.everUsed),r.flags=v.location.flags,null!=v.location.pt&&(r.particle=v.location.pt),r.dayAge=null!=(q=v.location.age)?q:0,null!=v.location.barterItems&&(r.invs.barter=new Va(this.main),r.invs.barter.items=this.unpackItems(v.location.barterItems)),null!=v.location.lootItems&&(r.invs.loot=new Va(this.main),r.invs.loot.items=this.unpackItems(v.location.lootItems)),null!=v.location.invs))for(A in y=v.location.invs,
y)f=y[A],r.invs[A]=new Va(this.main),r.invs[A].items=this.unpackItems(f.items),r.invs[A].didEverTransferMeta=null!=(h=f.meta)?h:!1}a.updateLocations();if(null!=d.knownTiles&&0<d.knownTiles.length){c=d.knownTiles;d=0;for(b=c.length;d<b;d++){var A=c[d];f=e.getTile(A);n.assert(null!=f&&f.biome===a);f.known=!0}n.isIO()&&!this.main.isWarping()&&null==this.main.tutorial&&a.getIOMPData(this.main)}};ia.prototype.unpackWorld=function(a,b){b=void 0===b?null:b;var c,d,e,f;null==b&&(b=new ba(this.main,a.worldId,
a.pocketId,a.goalId,!1,a.worldSeed),b=b.world,b.resetBiomes());b.flags=a.worldFlags;null!=a.startPos&&(b.startPos=u.fromObj(a.startPos));null!=a.warpPos&&(b.warpPos=u.fromObj(a.warpPos));null!=a.warpStanding&&(b.warpStanding=a.warpStanding);this.main.tribeGen.setup(b.tribeGen,b.worldSeed);this.main.tribeGen.genColorTable();this.main.tribeGen.genKeyTable();n.assert(0<a.biomes.length);if(null!=a.tiles&&0<a.tiles.length){var g=a.biomes;var h=d=0;for(e=g.length;d<e;h=++d){var k=g[h];k.pos=b.biomes[h].pos;
n.assert(null==k.tiles);k.tiles=[]}g=a.tiles;h=d=0;for(e=g.length;d<e;h=++d){k=g[h];var l=Math.floor(h/b.overallSize.w);h-=l*b.overallSize.w;k.tilePos=new u(h,l);h=b.toBiomePos(k.tilePos);h=b.getBiomeIdx(h);a.biomes[h].tiles.push(k)}}d=a.biomes;h=e=0;for(g=d.length;e<g;h=++e)k=d[h],null!=this.main.worldGenIO&&b===this.main.worldGenIO.world?this.main.worldGenIO.getBiomeDict(k.pos).sgData=k:(h=b.getBiome(k.pos),h.setup(k.id,k.isBlocking),this.unpackBiome(h,a.tileTable,a.sprawlTable,k,b));e=a.zones;
k=0;for(h=e.length;k<h;k++)g=e[k],null!=this.main.worldGenIO&&b===this.main.worldGenIO.world?(d=b.toBiomePos(g.center),d=this.main.worldGenIO.getBiomeDict(d),null==d.sgData&&(d.sgData={}),null==(c=d.sgData).zones&&(c.zones=[]),d.sgData.zones.push(g)):b.addZone(g.id,u.fromObj(g.center),0,n.isTrue(g.seeking),null!=(f=g.seekTurns)?f:0);if(null!=this.main.worldGenIO&&b===this.main.worldGenIO.world){e=b.biomes;c=0;for(f=e.length;c<f;c++)for(h=e[c],d=h.tiles,h=0,g=d.length;h<g;h++)k=d[h],k.reachable=!k.isBlocking();
this.main.worldGenIO.sgTileTable=a.tileTable;this.main.worldGenIO.sgSprawlTable=a.sprawlTable}else b.updateReachability(b.startPos);b.relinkLocations();n.isIO()&&(null!=a.zoneSpawns&&(b.zoneSpawns=a.zoneSpawns),null!=a.locationSpawns&&(b.locationSpawns=a.locationSpawns));b.generated=!0;return b};var Fc=function(){};Fc.saveUser=function(){if(!(window.isClient&&!n.isIO()||debug.runOffline)){var a=Parse.User.current();if(null!=a)try{return a.save().then(function(a){if(logs.parse)return r.log("updated user")},
function(a){return r.error("failed updating user: "+a)})}catch(b){return a=b,r.error("failed updating user: "+a)}}};var zb=Fc;var mb=function(a,b,c){return W.call(this,a,b,c)||this};$jscomp.inherits(mb,W);mb.prototype.show=function(){return this.time=0};mb.prototype.goToNextState=function(){return n.isIO()?null==this.main.events?void 0:this.main.setMainState("iosplash"):this.main.gotoMainMenu()};mb.prototype.tick=function(a){if(debug.skipPreRoll)this.goToNextState();else return n.isChina()&&this.hasShownChinaSplash?
this.time+=.5*a:this.time+=a};mb.prototype.draw=function(a,b,c){b=$jscomp.makeIterator(this.r.getCanvasSize());a=b.next().value;b=b.next().value;this.r.ctx.fillStyle="black";this.r.ctx.fillRect(0,0,a,b);if(n.isChina()&&!this.hasShownChinaSplash)if(5<this.time)this.hasShownChinaSplash=!0,this.time=0;else{b="\u5065\u5eb7\u6e38\u620f\u5fe0\u544a  \u62b5\u5236\u4e0d\u826f\u6e38\u620f\uff0c\u62d2\u7edd\u76d7\u7248\u6e38\u620f\u3002 \u6ce8\u610f\u81ea\u6211\u4fdd\u62a4\uff0c\u8c28\u9632\u53d7\u9a97\u4e0a\u5f53\u3002 \u9002\u5ea6\u6e38\u620f\u76ca\u8111\uff0c\u6c89\u8ff7\u6e38\u620f\u4f24\u8eab\u3002 \u5408\u7406\u5b89\u6392\u65f6\u95f4\uff0c\u4eab\u53d7\u5065\u5eb7\u751f\u6d3b\u3002".split(" ");
var d=90*this.s+this.r.oY;var e=0;for(c=b.length;e<c;e++){var f=b[e];this.r.drawText(f,a/2,d,{halign:"center",font:config.fonts.technicalLarge});d+=30*this.r.s}return}e=(n.isChina()?[{src:this.r.img.getSprite("MM_logo_chinese_greenOutline.png").img,offset:0}]:[{src:this.r.img.logoMaschinenMensch,offset:40},{src:this.r.img.logoSaftladen,offset:0},{src:this.r.img.logoMedienboard,offset:0}])[Math.floor(this.time)];if(null==e)this.goToNextState();else if(f=e.src,n.assert(null!=f),this.r.ctx.drawImage(f,
a/2-f.width/2,b/2-f.height/2+e.offset),c)return this.goToNextState()};mb.prototype.onKeyPress=function(a){if(32===a.which)return this.goToNextState()};var X=function(a,b,c){var d;var e=W.call(this,a,b,c)||this;e.initNews=e.initNews.bind(e);e.createDebugBar=e.createDebugBar.bind(e);e.itemFound=e.itemFound.bind(e);e.onSelectExplorer=e.onSelectExplorer.bind(e);e.onWonCharacter=e.onWonCharacter.bind(e);e.checkAchievements=e.checkAchievements.bind(e);e.getCountOfValidCharsForAchievement=e.getCountOfValidCharsForAchievement.bind(e);
e.onNextWorld=e.onNextWorld.bind(e);e.onShowOutro=e.onShowOutro.bind(e);e.getExplorerSelection=e.getExplorerSelection.bind(e);e.drawSmallNewsBox=e.drawSmallNewsBox.bind(e);e.drawBigNewsBox=e.drawBigNewsBox.bind(e);e.drawNewsBox=e.drawNewsBox.bind(e);e.showNewsDetails=e.showNewsDetails.bind(e);e.hideNewsDetails=e.hideNewsDetails.bind(e);e.saveGame=new ia(c);e.isActive=!1;window.isClient&&!n.isIO()||n.isDemo()||(e.user=Parse.User.current());e.loadPlayerData();e.scores=[];e.initNews();e.cityLayers=Object.clone(config.mainMenuLayers,
!0);var f=e.cityLayers;var g=0;for(d=f.length;g<d;g++)c=f[g],null!=c.particle&&(c.part=new qb(a,b),c.time=0);return e};$jscomp.inherits(X,W);X.prototype.show=function(){var a;debug.showDebugBar&&null==this.comboExplorer&&this.createDebugBar();null==(a=this.playerData).newsSeen&&(a.newsSeen=0);this.playerData.newsSeen+=1;this.newsFade=-2;this.selectedNews=0;this.isActive=!0;this.outTime=this.time=0;this.checkAchievements();return this.main.hasFixedFPS=!1};X.prototype.hide=function(){this.isActive=
!1;return this.outTime=0};X.prototype.initNews=function(){var a=this;B(this,X);this.news=[];this.selectedNews=0;if(n.isTCE()&&!n.isChina())return $.ajax({async:!0,global:!1,url:debug.isDevMode?"conf/tce_news.json":"https://curious-expedition.com/news/tce_news.json",dataType:"text",cache:!1,success:function(b){return a.news=JSON.parse(b)},error:function(a,c,d){return r.error(c)}})};X.prototype.createDebugBar=function(){var a;B(this,X);if(!n.canUseLocalStorage()||n.isChina())debug.showDebugBar=!1;else{this.skipStartEvents=
"true"===window.localStorage.getItem("testSkipStartEvents");this.autoLevel="true"===window.localStorage.getItem("testAutoLevel");var b=window.localStorage.getItem("testExplorer");var c=Object.values(config.characters).filter(function(a){return a.id.startsWith("sp")});c=Ra.toComboList(c);this.comboExplorer=new Ra(this.r,"Explorer",b,c);c=J.parseInt(window.localStorage.getItem("testWorldLevel"),1);b=function(){var b,c;var f=[];a=c=0;for(b=config.maxExpedition;0<=b?c<=b:c>=b;a=0<=b?++c:--c)f.push({id:a,
label:"Expedition "+(a+1)});return f}();this.comboWorld=new Ra(this.r,"World",null!=c?c:0,b);b=J.parseInt(window.localStorage.getItem("testDifficulty"),1);this.comboDifficulty=new Ra(this.r,"Difficulty",b,[{id:0,label:"Easy"},{id:1,label:"Normal"},{id:2,label:"Hard"}]);c=window.localStorage.getItem("testPocket");this.testPocketSeed=window.localStorage.getItem("testPocketSeed");null==this.testPocketSeed&&(this.testPocketSeed="");b=["show map"].include(Object.values(config.pockets).map("id"));return this.comboPocket=
new Ra(this.r,"Pocket",null!=c?c:"show map",b)}};X.prototype.startTestGame=function(){var a,b;if(debug.showDebugBar){debug.testGame=!0;debug.showFlagsInfo=null!=(a=debug.showFlagsInfo)?a:!0;debug.skipSaveGames=null!=(b=debug.skipSaveGame)?b:!1;a=this.comboPocket.selected;"show map"===a&&(a=null);debug.testPocket=a;debug.testPocketSeed=0;if(null!=this.testPocketSeed&&""!==this.testPocketSeed){a=!1;try{debug.testPocketSeed=Number(this.testPocketSeed),a=!isNaN(debug.testPocketSeed)&&0!==debug.testPocketSeed}catch(e){a=
!1}if(!a){debug.testPocketSeed=0;var c=this.testPocketSeed;var d=0;for(b=c.length;d<b;d++)a=c[d],debug.testPocketSeed+=a.charCodeAt(0),(null==debug.testPocketSeed||isNaN(debug.testPocketSeed))&&r.warn("unable to parse test seed: "+this.testPocketSeed)}}ba.rng=new pa(null==debug.testPocketSeed||0===debug.testPocketSeed?Date.now():debug.testPocketSeed);debug.testExplorer=this.comboExplorer.selected;debug.testWorldLevel=this.comboWorld.selected;debug.testDifficulty=this.comboDifficulty.selected;debug.skipStartEvents=
this.skipStartEvents;debug.autoLevel=this.autoLevel;window.localStorage.setItem("testPocket",this.comboPocket.selected);window.localStorage.setItem("testPocketSeed",this.testPocketSeed);window.localStorage.setItem("testExplorer",this.comboExplorer.selected);window.localStorage.setItem("testWorldLevel",this.comboWorld.selected);window.localStorage.setItem("testDifficulty",this.comboDifficulty.selected);window.localStorage.setItem("testSkipStartEvents",this.skipStartEvents);window.localStorage.setItem("testAutoLevel",
this.autoLevel);r.info("TEST-GAME;pck '"+this.comboPocket.selected+"' seed '"+this.testPocketSeed+"' explorer '"+this.comboExplorer.selected+"' world '"+this.comboWorld.selected+"' diff '"+this.comboDifficulty.selected+"' skipStart "+this.skipStartEvents+" autoLevel "+this.autoLevel);this.showDebugBar(!0);return this.main.startGame()}};X.prototype.resetDebug=function(){var a,b;debug.testGame=!1;debug.testExplorer=null;debug.testWorldLevel=null;debug.testDifficulty=null;debug.testPocket=null;debug.testPocketSeed=
0;debug.skipStartEvents=!1;debug.autoLevel=!1;debug.showFlagsInfo=null!=(a=debug.showFlagsInfo)?a:!1;debug.skipSaveGames=null!=(b=debug.skipSaveGame)?b:!1;debug.showLoyalty=!1;return this.showDebugBar(!1)};X.prototype.showDebugBar=function(a){debug.showDebugBar=a;return this.r.oY=a?15*this.s:0};X.prototype.onMouseClick=function(a){var b;switch(null!=(b=this.mouseAction)?b.id:void 0){case "new":return this.resetDebug(),this.main.startGame();case "continue":return this.resetDebug(),this.main.continueGame();
case "tutorial":return this.resetDebug(),this.main.startTutorial();case "mods":return this.main.showModding();case "balloon":return this.totalBalloons+=1,this.main.achievements.incCounter("ach-balloon-click"),a=0<this.totalBalloons&&0===this.totalBalloons%50?"cheer2":"yay",this.main.sfx.play(a),this.r.setRandBalloonX();case "highscore":return this.main.gotoHighScore();case "buy":return n.openLink("https://www.humblebundle.com/store/p/curiousexpedition_storefront");case "quit":return this.main.quit();
case "extraNews":return this.showNewsDetails();case "settings":return this.main.showSettings(!0);case "facebook":return n.openLink("https://www.facebook.com/CuriousExpedition");case "twitter":return n.openLink("https://twitter.com/maschimensch");case "wiki":return n.openLink("http://curious-expedition.wikia.com");case "discord":return n.openLink("https://discordapp.com/invite/maschinen-mensch",!1);case "link":return n.openLink(this.mouseAction.data);case "testGame":return this.startTestGame();case "testSkipStartEvent":return this.skipStartEvents=
!this.skipStartEvents;case "testAutoLevel":return this.autoLevel=!this.autoLevel;case "noNews":return this.hideNewsDetails();case "testTaxonomy":return this.main.gotoTaxonomy();case "rivals":return this.main.gotoRivals();case "ce2wishlist":return this.sfx.play("campClose"),n.openLink("https://store.steampowered.com/app/1040230/Curious_Expedition_2/");case "alphaSignup":return this.sfx.play("campClose"),n.openLink("https://curious-expedition.com/")}};X.prototype.onContextMenu=function(a){var b=$jscomp.makeIterator(this.r.getCanvasSize());
var c=b.next().value;b=b.next().value;if(window.isElectron&&10>c-a.x&&10>b-a.y&&a.ctrlKey)return a=require("electron").remote.getCurrentWindow(),a.webContents.openDevTools()};X.prototype.onKeyDown=function(a){if(debug.showDebugBar&&this.TestGameHit){if(1===a.key.length&&null!=a.key.match(/[\w- ]/i))return null==this.testPocketSeed&&(this.testPocketSeed=""),this.testPocketSeed+=a.key;if(8===a.which)return a.ctrlKey||a.altKey||a.shiftKey||a.metaKey?this.testPocketSeed="":this.testPocketSeed=this.testPocketSeed.slice(0,
-1)}};X.prototype.onKeyPress=function(a){if(!debug.showDebugBar||!this.TestGameHit){if(32===a.which)return this.resetDebug(),this.main.continueGame()||this.main.startGame();if(49===a.which)return this.resetDebug(),this.main.continueGame();if(50===a.which)return this.resetDebug(),this.main.startGame();if(51===a.which)return this.resetDebug(),this.main.startTutorial();if(52===a.which)return this.main.gotoHighScore();if(113===a.which&&debug.showDebugBar)return this.startTestGame()}};X.prototype.unlockCharacter=
function(a){if(this.unlockedChars.any(a))return!1;var b=t.getCharacter(a);n.assert(null!=b);this.unlockedChars.push(a);this.updatePlayerData();null!=this.sfx&&this.sfx.play("achievement");this.checkAchievements();return!0};X.prototype.resetCharacters=function(){this.unlockedChars=[];this.wonChars=[];this.wonHardChars=[];this.itemsFound=[];return this.updatePlayerData()};X.prototype.updatePlayerData=function(){if(null==this.playerData)this.main.doSendError("no playerdata");else{n.isIO()?(this.playerData.lastShownNews=
this.lastShownNews,this.playerData.hasEverStartedGame=this.hasEverStartedGame):(this.playerData.unlockedCharacters=this.unlockedChars,this.playerData.wonCharacters=this.wonChars,this.playerData.wonHardCharacters=this.wonHardChars,this.playerData.playedCharacters=this.playedChars,this.playerData.itemsFound=this.itemsFound,this.playerData.totalGames=this.totalGames,this.playerData.totalBalloons=this.totalBalloons,this.playerData.firstGameDate=this.firstGameDate,this.playerData.visitedWorlds=this.visitedWorlds);
if(n.isIO())return this.user.set("ioPlayerData",this.playerData),zb.saveUser();if(window.isClient){var a=JSON.stringify(this.playerData);O.writeProfile("pldata.ls",a,"playerData");var b=(new Date).format("{yyyy}-{MM}-{dd}");return O.writeProfile("pldata-"+b+".ls.bak",a,"playerData")}if(null!=this.user)return this.user.set("playerData",this.playerData),zb.saveUser()}};X.prototype.loadPlayerData=function(){var a,b,c,d,e,f,g,h,k,l,m,p,w,q;n.isDemo()?this.playerData={}:n.isIO()?this.playerData=null!=
(a=this.user.get("ioPlayerData"))?a:{}:this.playerData=window.isClient?null!=(g=O.loadProfile("pldata.ls","playerData"))?g:{}:null!=this.user?null!=(h=this.user.get("playerData"))?h:{}:{};this.playedChars=null!=(k=this.playerData.playedCharacters)?k:[];this.unlockedChars=null!=(l=this.playerData.unlockedCharacters)?l:[];this.wonChars=null!=(m=this.playerData.wonCharacters)?m:[];this.wonHardChars=null!=(p=this.playerData.wonHardCharacters)?p:[];this.itemsFound=null!=(w=this.playerData.itemsFound)?
w:[];this.totalGames=null!=(q=this.playerData.totalGames)?q:0;this.totalBalloons=null!=(b=this.playerData.totalBalloons)?b:0;this.firstGameDate=null!=(c=this.playerData.firstGameDate)?c:(new Date).format(Date.ISO8601_DATETIME);this.visitedWorlds=null!=(d=this.playerData.visitedWorlds)?d:[];n.isIO()&&(this.lastShownNews=null!=(e=this.playerData.lastShownNews)?e:-1,this.hasEverStartedGame=null!=(f=this.playerData.hasEverStartedGame)?f:!1)};X.prototype.itemFound=function(a){B(this,X);if(this.main.achievements.canUnlockAchievements()){var b=
t.getItem(a);if(null==b.mod||"base"===b.mod)this.main.achievements.setCounter("ach-all-items",this.itemsFound.length),this.itemsFound.any(a)||(this.itemsFound.push(a),this.main.achievements.setCounter("ach-all-items",this.itemsFound.length))}};X.prototype.tick=function(a){var b,c;this.time+=a;this.isActive||(this.outTime+=a);null==this.newsFade&&(this.newsFade=-1.6);this.newsFade+=2*a;var d=this.cityLayers;var e=0;for(b=d.length;e<b;e++){var f=d[e];if(null!=f.part&&(f.part.tickParticles(a),f.time+=
a,f.time>f.interval)){f.time=0;var g=this.r.img.getSpriteSlots(f.sprite,this.s);var h=null!=(c=g.chimney)?c:[];var k=0;for(g=h.length;k<g;k++){var l=h[k];f.part.addParticleConf(f.particle,l)}}}};X.prototype.onSelectExplorer=function(a){B(this,X);if(!this.playedChars.any(a))return this.playedChars.push(a)};X.prototype.onWonCharacter=function(a,b){B(this,X);if(this.main.achievements.canUnlockAchievements())return this.wonChars.any(a)||this.wonChars.push(a),2!==b||this.wonHardChars.any(a)||this.wonHardChars.push(a),
this.checkAchievements(),this.updatePlayerData()};X.prototype.checkAchievements=function(){var a;B(this,X);if(this.main.achievements.canUnlockAchievements()){var b=[];var c=this.itemsFound;var d=0;for(a=c.length;d<a;d++){var e=c[d];var f=t.getItem(e,!1);(null==f||null!=f.mod&&"base"!==f.mod)&&b.push(e)}a=0;for(f=b.length;a<f;a++)e=b[a],this.itemsFound.remove(e);this.main.achievements.setCounter("ach-all-items",this.itemsFound.length);this.main.achievements.setCounter("ach-gol-frames",this.getCountOfValidCharsForAchievement(this.wonChars));
this.main.achievements.setCounter("ach-plat-frames",this.getCountOfValidCharsForAchievement(this.wonHardChars));return this.main.achievements.setCounter("ach-explorer-collect",this.getCountOfValidCharsForAchievement(this.unlockedChars,!1))}};X.prototype.getCountOfValidCharsForAchievement=function(a,b){b=void 0===b?!0:b;B(this,X);return a.filter(function(a){a=t.getCharacter(a);return null!=a&&(b||null==a.unlockPin)&&(null==a.mod||"base"===a.mod)}).length};X.prototype.onNextWorld=function(){B(this,
X);if(!n.isIO())return this.updatePlayerData()};X.prototype.onShowOutro=function(){B(this,X);return this.updatePlayerData()};X.prototype.getExplorerSelection=function(){var a=this;B(this,X);n.isChina()&&(debug.unlockAllExplorers=!0);var b=Object.values(config.characters);var c=b.filter(function(a){return a.id.startsWith("sp")&&null!=a.name&&null==a.unlockPin});c.push.apply(c,$jscomp.arrayFromIterable(b.filter(function(b){var c;return b.id.startsWith("sp")&&null!=b.name&&null!=b.unlockPin&&(c=b.id,
0<=F.call(a.unlockedChars,c))})));c.map(function(a){return t.getCharacter(a.id)}).each(function(b){var c,d;b.available=debug.unlockAllExplorers||b.alwaysUnlocked||null!=b.unlockPin||(c=b.id,0<=F.call(a.unlockedChars,c));b.hintNew=!a.playedChars.any(b.id)&&b.available;b.hintWon=a.wonChars.any(b.id)&&b.available;b.hintWonHard=a.wonHardChars.any(b.id)&&b.available;return b.unlockHint=null!=(d=b.unlockHint)?d:""});b={id:c.filter(function(a){return a.available}).sample().id,available:!0,random:!0,variations:[{portrait:"res_face_random.png"}]};
c.insert(b,0);return c};X.prototype.draw=function(a,b,c){this.drawBackground(a,b);if(this.showNews)return this.drawBigNewsBox(a,b,c);this.drawMainButtons(a,b,c);this.drawExtraButtons(a,b,c);n.isChina()||this.drawSmallNewsBox(a,b,c);this.drawFooter();this.drawDemoNotes(a,b);this.drawDebugBar(a,b,c);if(!n.isChina()){this.drawRivalsButton(a,b,c);var d=35*this.s;debug.showDebugBar&&(d+=15*this.s);a=bb.drawCE2Panel(this.main,5*this.s,d,a,b,c);if(null!=a)return this.mouseAction=a}};X.prototype.drawRivalsButton=
function(a,b,c){var d=$jscomp.makeIterator(this.r.getCanvasSize());var e=d.next().value;d.next();var f=5*this.s;debug.showDebugBar&&(f+=15*this.s);window.isClient&&(f+=30*this.s);d=new R(110*this.s,45*this.s);var g=e-d.w-5*this.s;var h=!1;e="white";this.r.hitBox(g,f,d.w,d.y,a,b)&&(h=!0,e="red",c&&(f+=2*this.s));this.r.drawPanel("backButton",g,f,d.w,d.h);this.r.drawText(q.toText("txt-startup-play"),g+d.w/2,f+16*this.s,{fillColor:e,halign:"center",font:config.fonts.technicalLarge});this.r.drawSprite("title_rivals_single.png",
g+d.w/2,f+22*this.s,{halign:"center",scale:.5});h&&(this.mouseAction={id:"rivals"})};X.prototype.drawBackground=function(a,b){var c=$jscomp.makeIterator(this.r.getCanvasSize());var d=c.next().value;c=c.next().value;this.drawCityBackground(a,b,!1,!0)&&(this.mouseAction={id:"balloon"});this.drawCityBackground(a,b,!0,!1);this.showNews||this.drawTitle();this.r.ctx.fillStyle="white";this.r.ctx.font="62px Curious";return this.r.drawText(config.versionName,d/2,c/2+Math.min(c/2-60*this.s,130*this.s),{halign:"center",
font:config.fonts.themedLarge})};X.prototype.drawTitle=function(){var a=$jscomp.makeIterator(this.r.getCanvasSize());var b=a.next().value;a=a.next().value;var c=300*(1-TWEEN.Easing.Back.Out((.3*this.time).clamp(0,1)));var d=a/2-115*this.s+c+Math.floor(12*Math.sin(this.time));this.r.drawSprite("hud_title.png",b/2,d,{halign:"center",scale:config.imgSize.titleScale});if(n.isChina()){c=["\u5065\u5eb7\u6e38\u620f\u5fe0\u544a","\u62b5\u5236\u4e0d\u826f\u6e38\u620f\uff0c\u62d2\u7edd\u76d7\u7248\u6e38\u620f\u3002\u6ce8\u610f\u81ea\u6211\u4fdd\u62a4\uff0c\u8c28\u9632\u53d7\u9a97\u4e0a\u5f53\u3002",
"\u9002\u5ea6\u6e38\u620f\u76ca\u8111\uff0c\u6c89\u8ff7\u6e38\u620f\u4f24\u8eab\u3002\u5408\u7406\u5b89\u6392\u65f6\u95f4\uff0c\u4eab\u53d7\u5065\u5eb7\u751f\u6d3b\u3002"];d=12*this.s+this.r.oY;var e=[];var f=0;for(a=c.length;f<a;f++){var g=c[f];this.r.drawText(g,b/2,d,{halign:"center",font:config.fonts.technicalSmall});e.push(d+=10*this.r.s)}return e}};X.prototype.drawSmallNewsBox=function(a,b,c){B(this,X);var d=$jscomp.makeIterator(this.r.getCanvasSize());var e=d.next().value;d=d.next().value;var f=
.4*e;a=this.drawNewsBox(e/2-f/2,.575*d,f,1/6*d,a,b,c);if(null!=a)return this.mouseAction=a};X.prototype.drawBigNewsBox=function(a,b,c){B(this,X);var d=$jscomp.makeIterator(this.r.getCanvasSize());var e=d.next().value;var f=d.next().value;d=.2*e;var g=.1*f;e*=.6;var h=4/6*f;f=this.drawNewsBox(d,g,e,h,a,b,c,!1);null!=f&&(this.mouseAction=f);if(this.drawMainButton(q.toText("txt-base-return"),d+e/2,g+h+15*this.s,a,b,c))return this.mouseAction={id:"noNews"}};X.prototype.drawNewsBox=function(a,b,c,d,e,
f,g,h){h=void 0===h?!0:h;B(this,X);var k=null;if(0===this.news.length)return k;null==this.news[this.selectedNews]&&(this.selectedNews=0);var l=J.clamp(this.newsFade,0,1);this.r.ctx.globalAlpha=.7*l;this.r.drawPanel(config.panel.newsFrame,a,b,c,d);this.r.ctx.fillStyle="#603E20";this.r.ctx.globalAlpha=1*l;this.r.ctx.fillRect(a+7*this.s,b+9*this.s,c-14*this.s,9*this.s);var m=this.news[this.selectedNews];if(null!=m){this.r.ctx.font=config.fonts.technicalSmall;this.r.drawText(m.title,a+9*this.s,b+16*this.s,
{fillColor:config.colors.news,os:0});var p=q.wrap(m.text,c-16*this.s,this.r.ctx);var w=h&&(3<p.length||null!=m.links||3===p.length&&this.r.ctx.measureText(p[2]).width>c-77*this.s);var da=p.length;w&&(da=2);l=1;var r=p.slice(0,+(da-1)+1||9E9);var v=0;for(p=r.length;v<p;v++)da=r[v],this.r.drawText(da,a+9*this.s,b+20*this.s+10*l*this.s,{fillColor:config.colors.news,os:0}),l+=1;w&&(w="#DCAC2C",this.r.hitBox(a+c-55*this.s,b+13*this.s+10*l*this.s,50*this.s,10*this.s,e,f)&&(k={id:"extraNews"},w="#f2c857"),
this.r.drawText("Read more...",a+c-10*this.s,b+20*this.s+10*l*this.s,{fillColor:w,halign:"right"}),l+=1);if(!h)for(l+=1,m=t.arrify(m.links),da=0,c=m.length;da<c;da++)if(h=m[da],!n.isTrue(h.onlySteam)||window.isSteam)w="#DCAC2C",p=this.r.ctx.measureText(h.text).width,this.r.hitBox(a+8*this.s,b+13*this.s+10*l*this.s,p+2*this.s,10*this.s,e,f)&&(k={id:"link",data:h.url},w="#f2c857"),this.r.drawText(h.text,a+9*this.s,b+20*this.s+10*l*this.s,{fillColor:w}),l+=1}if(1<this.news.length)for(m=a+7*this.s,a=
l=0,c=Math.min(5,this.news.length-1);0<=c?l<=c:l>=c;a=0<=c?++l:--l)h="hud_news_index_inactive.png",a===this.selectedNews&&(h="hud_news_index_active.png"),this.r.drawSprite(h,m,b+d-14*this.s,{mX:e,mY:f})&&g&&null!=this.news[a]&&(this.selectedNews=a),m+=8*this.s;return k};X.prototype.showNewsDetails=function(){var a;B(this,X);null==(a=this.playerData).newsExpanded&&(a.newsExpanded=0);this.playerData.newsExpanded+=1;return this.showNews=!0};X.prototype.hideNewsDetails=function(){B(this,X);return this.showNews=
!1};X.prototype.drawCityBackground=function(a,b,c,d){c=void 0===c?!0:c;d=void 0===d?!0:d;var e,f,g;var h=$jscomp.makeIterator(this.r.getCanvasSize());var k=h.next().value;var l=h.next().value;d&&(this.r.ctx.globalAlpha=1,this.r.ctx.fillStyle="#00B974",this.r.ctx.fillRect(0,0,k,200*this.s));h=config.anim.cityLayers;var m=config.anim.cityScrollSpeed;var p=this.cityLayers;var w=g=0;for(e=p.length;g<e;w=++g){var n=p[w];if(!(7<w)||c)if(!(7>=w)||d){var q=this.r.img.getSprite(n.sprite);var v=0>n.offset?
0:l-n.offset*this.s-q.dSize.h;var t=-(this.s*this.time*h)*(w+2)*m;w=Math.floor(q.dSize.w);for(t%=w;t<k;)null!=(f=n.part)&&f.drawParticles(!1,new u(t,v)),this.r.drawSprite(q,t,v),t+=w}}return this.r.drawSprite("baloon.png",this.r.balloonX,config.balloonOffsetY*this.s+Math.floor(8*Math.sin(this.time/2+.3)*this.s),{scale:this.s/4,mX:a,mY:b})};X.prototype.drawDemoNotes=function(a,b){if(null==this.user&&!window.isClient&&!n.isIO()){var c=$jscomp.makeIterator(this.r.getCanvasSize());var d=c.next().value;
var e=c.next().value;c=this.r.img.humbleButton;e=$jscomp.makeIterator([d/2-c.width/2,e/2+10]);d=e.next().value;e=e.next().value;this.r.ctx.drawImage(c,d,e);if(this.r.hitBox(d,e,c.width,c.height,a,b))return this.mouseAction={id:"buy"}}};X.prototype.drawMainButtons=function(a,b,c){var d,e;var f=$jscomp.makeIterator(this.r.getCanvasSize());var g=f.next().value;var h=f.next().value;if(null==config.worlds)this.r.ctx.font="24px Aldrich",this.r.drawText("Connecting...",g/2,h-50,{halign:"center"});else{f=
110*this.s;h=h/2+130*this.s;var k=config.showMods?5:4;var l=g/2-(k*f+10*(k-1)*this.s)/2+f/2;this.r.ctx.globalAlpha=1;this.r.ctx.font="24px Aldrich";this.r.ctx.fillStyle="black";this.r.ctx.globalAlpha=1;k=this.saveGame.getInfo();null!=this.saveGame&&(e=this.saveGame.checkCompatibility());this.drawMainButton("txt-mainmenu-continue",l,h,a,b,c,null!=k)&&(null!=k&&(this.mouseAction={id:"continue"}),null==this.saveGame||e||(g=this.saveGame.getCompatibilityString(),0<g.length&&this.main.infoBox.showHelp(g,
Math.max(95*this.s,a),b)));if(this.saveGame.loading){var m=q.toText("txt-loading")+"...";var p="gray"}else null==(null!=(d=this.saveGame)?d.sg:void 0)||e?null!=k&&(m=q.toText("txt-base-expedition")+" "+(k.world+1)+" - "+q.toText("txt-base-fame")+" "+k.fame,p="black"):(m=q.toText("txt-mod-imcompatible"),p="red");null!=m&&(this.r.ctx.font=config.fonts.technicalSmall,this.r.ctx.globalAlpha=1,this.r.drawText(m,l,h+24*this.s,{fillColor:p,shadowColor:"gray",halign:"center"}));l+=f+10*this.s;this.drawMainButton("txt-mainmenu-newgame",
l,h,a,b,c)&&(this.mouseAction={id:"new"});l+=f+10*this.s;this.drawMainButton("txt-mainmenu-tutorial",l,h,a,b,c)&&(this.mouseAction={id:"tutorial"});l+=f+10*this.s;this.drawMainButton("txt-mainmenu-highscore",l,h,a,b,c)&&(this.mouseAction={id:"highscore"});l+=f+10*this.s;config.showMods&&this.drawMainButton("txt-mainmenu-mods",l,h,a,b,c)&&(this.mouseAction={id:"mods"});c=debug.showDebugBar?15*this.s:0;if(window.isClient&&this.r.drawExitButton(q.toText("txt-mainmenu-quit"),a,b,c))return this.mouseAction=
{id:"quit"}}};X.prototype.drawMainButton=function(a,b,c,d,e,f,g){g=void 0===g?!0:g;var h;var k=110*this.s;var l=30*this.s;this.r.ctx.fillStyle="black";this.r.ctx.globalAlpha=1;var m=0;var p=!1;this.r.hitBox(b-k/2,c,k,l,d,e)?(f&&(m=2*this.s),p=!0,g&&(h="#973200")):g&&(h="#dfa814");g||(h="gray");this.r.drawPanel(config.panel.menuButton,b-k/2,c+m,k,l);this.r.drawText(q.toText(a),b,c+16*this.s+m,{fillColor:h,shadowColor:"#7f6317",halign:"center",font:config.fonts.themedLarge});return p};X.prototype.drawFooter=
function(){var a,b;var c=$jscomp.makeIterator(this.r.getCanvasSize());var d=c.next().value;c=c.next().value;this.r.ctx.globalAlpha=1;this.r.ctx.fillStyle="gray";this.r.ctx.font=config.fonts.technicalSmall;var e=window.isClient?"":null!=(a=null!=(b=this.user)?b.get("displayName"):void 0)?a:"Free Play";e=e+"  "+n.getVersionString();return this.r.drawText(e,d-5*this.s,c-5*this.s,{halign:"right",os:0,fillColor:config.colors.news})};X.prototype.drawExtraButtons=function(a,b,c){var d;c=$jscomp.makeIterator(this.r.getCanvasSize());
c.next();c.next();var e=$jscomp.makeIterator([5*this.s,5*this.s]);c=e.next().value;e=e.next().value;var f={mX:a,mY:b};debug.showDebugBar&&(e+=15*this.s);b=n.isChina()?[{sprite:"hud_button_options.png",action:"settings"}]:[{sprite:"hud_button_twitter.png",action:"twitter"},{sprite:"hud_button_discord.png",action:"discord"},{sprite:"hud_button_facebook.png",action:"facebook"},{sprite:"hud_button_wiki.png",action:"wiki"},{sprite:"hud_button_options.png",action:"settings"}];var g=[];var h=0;for(d=b.length;h<
d;h++)a=b[h],this.r.drawSprite(a.sprite,c,e,f)&&(this.mouseAction={id:a.action}),g.push(c+=25*this.s);return g};X.prototype.getTestGameButtonText=function(){return this.TestGameHit?""!==this.testPocketSeed?this.testPocketSeed+"_":"<type seed>":""!==this.testPocketSeed?"Test Game "+this.testPocketSeed:"Test Game"};X.prototype.drawDebugBar=function(a,b,c){var d;if(debug.showDebugBar){null==this.comboExplorer&&(debug.showDebugBar&&this.createDebugBar(),this.showDebugBar(debug.showDebugBar));var e=$jscomp.makeIterator(this.r.getCanvasSize());
var f=e.next().value;e.next();this.r.ctx.globalAlpha=1;this.r.ctx.fillStyle="black";this.r.ctx.fillRect(0,0,f,15*this.s);var g=2*this.s;this.r.drawDebugButton(this.getTestGameButtonText(),g,a,b)?(this.mouseAction={id:"testGame"},this.TestGameHit=!0):this.TestGameHit=!1;g+=60*this.s;var h=[this.comboExplorer,this.comboWorld,this.comboDifficulty,this.comboPocket];var k=0;for(d=h.length;k<d;k++)e=h[k],e.s=this.s,e.draw(g,this.s,a,b,c)&&(this.mouseAction=null),g+=90*this.s;this.r.drawDebugCheckBox(this.skipStartEvents,
1===this.s?"Skip Start":"Skip Start Events",g,a,b,80*this.s)&&(this.mouseAction={id:"testSkipStartEvent"});g+=80*this.s;this.r.drawDebugCheckBox(this.autoLevel,"Auto Level",g,a,b,80*this.s)&&(this.mouseAction={id:"testAutoLevel"});if(this.r.drawDebugButton("Insects",f-50*this.s,a,b,50*this.s))return this.mouseAction={id:"testTaxonomy"}}};var Q=function(a,b,c){var d,e,f,g,h,k,l;c=W.call(this,a,b,c)||this;c.show=c.show.bind(c);c.activeMods=c.activeMods.bind(c);c.orderMods=c.orderMods.bind(c);c.loadMods=
c.loadMods.bind(c);c.onModsLoaded=c.onModsLoaded.bind(c);c.checkAllDependencies=c.checkAllDependencies.bind(c);c.checkDependencies=c.checkDependencies.bind(c);c.checkDependency=c.checkDependency.bind(c);c.tryEnableMod=c.tryEnableMod.bind(c);c.readModFiles=c.readModFiles.bind(c);c.readMod=c.readMod.bind(c);c.drawModInfoTextLines=c.drawModInfoTextLines.bind(c);c.drawModInfoHeader=c.drawModInfoHeader.bind(c);c.drawModLinks=c.drawModLinks.bind(c);c.drawInfoScrollbar=c.drawInfoScrollbar.bind(c);c.drawEnableButton=
c.drawEnableButton.bind(c);c.drawDebugOptions=c.drawDebugOptions.bind(c);c.massEnable=c.massEnable.bind(c);c.startSteamUpload=c.startSteamUpload.bind(c);c.steamUpload=c.steamUpload.bind(c);c.steamPublish=c.steamPublish.bind(c);c.steamFail=c.steamFail.bind(c);c.steamSuccess=c.steamSuccess.bind(c);c.doConfetti=c.doConfetti.bind(c);c.doTears=c.doTears.bind(c);c.steamSync=c.steamSync.bind(c);c.steamSyncFail=c.steamSyncFail.bind(c);c.steamSyncDone=c.steamSyncDone.bind(c);c.steamRemoveMod=c.steamRemoveMod.bind(c);
c.steamUnzipDone=c.steamUnzipDone.bind(c);c.steamUnzipFail=c.steamUnzipFail.bind(c);c.ensureModDirExists=c.ensureModDirExists.bind(c);c.onSteamOverlay=c.onSteamOverlay.bind(c);c.updateEnables=c.updateEnables.bind(c);c.onMouseWheel=c.onMouseWheel.bind(c);c.onKeyDown=c.onKeyDown.bind(c);c.onMouseDown=c.onMouseDown.bind(c);c.enabledMods={};n.canUseLocalStorage()&&!n.isChina()&&(l=window.localStorage.getItem("enabledMods"));null!=l&&(c.enabledMods=JSON.parse(l),Object.isArray(c.enabledMods)&&(c.enabledMods=
{}));n.isChina()?(c.enabledMods["tce-china"]=!0,c.debugOptions={showDebugBar:!1,enableDebugKeys:!1,showFlagsInfo:!1},debug.showDebugBar=!1,debug.enableDebugKeys=!1,debug.showFlagsInfo=!1):c.debugOptions={showDebugBar:null!=(e=debug.showDebugBar)?e:!1,enableDebugKeys:null!=(f=debug.enableDebugKeys)?f:!1,showFlagsInfo:null!=(g=debug.showFlagsInfo)?g:!1};r.modErrorCounts={};r.modWarnCounts={};if(n.isTCE()&&(n.canUseLocalStorage()&&(k=window.localStorage.getItem("debugOptions")),null!=k))for(d in f=JSON.parse(k),
e=c.debugOptions,e)null!=f[d]&&(c.debugOptions[d]=f[d]);c.ps=new qb(a,b);c.scrollOffset=0;c.showDebug=!1;c.steamCache=n.canUseLocalStorage()?JSON.parse(null!=(h=window.localStorage.getItem("steamModCache"))?h:"{}"):{};c.menuOptionsMaxWidth=0;n.isChina()?c.enabled=!0:c.enabled=n.canUseLocalStorage()?"true"===window.localStorage.getItem("modding"):!1;a=c.r.ctx.font;c.r.ctx.font=config.fonts.technicalSmall;c.modsLoaded=!0;c.loadMods();c.menuOptionsMaxWidth=85;c.r.ctx.font=a;if(window.isSteam)greenworks.on("game-overlay-activated",
c.onSteamOverlay);c.backupConfig=null;c.pictureWidth=158;c.textSpacing=9;c.infoScroll=0;c.infoScrollMax=0;c.canUpload=!0;c.hasRefreshedSteam=!1;return c};$jscomp.inherits(Q,W);Q.prototype.show=function(){var a;B(this,Q);this.hasRefreshedSteam||(this.hasRefreshedSteam=!0,this.steamSync());if(null==this.selectedMod){var b=this.mods;var c=0;for(a=b.length;c<a;c++){var d=b[c];if(d.visible){this.selectMod(d);break}}}};Q.prototype.activeMods=function(){var a;B(this,Q);if(!n.isTCE())return this.mods;if(!this.active)return[];
var b=this.mods;var c=[];var d=0;for(a=b.length;d<a;d++){var e=b[d];this.enabledMods[e.id]&&c.push(e)}return c};Q.prototype.orderMods=function(){var a,b,c;B(this,Q);var d=[];for(a=-1;d.length<this.mods.length;){var e=this.mods;var f=0;for(b=e.length;f<b;f++){var g=e[f];if(!d.includes(g))if(null==g.dependencies)d.push(g);else{var h=!0;var k=g.dependencies;var l=0;for(c=k.length;l<c;l++){var m=k[l];d.map(function(a){return a.id}).includes(m.id)||(h=!1)}(h||a===d.length)&&d.push(g)}}a=d.length}return this.mods=
d};Q.prototype.loadMods=function(){var a=this,b,c;B(this,Q);if(this.modsLoaded&&(this.mods=[],config.showMods)){this.modsLoaded=!1;r.header("mod;--== LOADING MODS ==--");r.clearCount();var d=n.isChina()?["tce-china"]:null!=(b=this.readModFiles())?b:[];n.isIO()||d.remove("tce-io");n.isChina()||d.remove("tce-china");n.isDemo()||d.remove("tce-demo");var e=c=0;for(b=d.length;e<b;e++){var f=d[e];this.readMod(f,function(){c+=1;if(c===d.length)return a.onModsLoaded()})}if(0===d.length)return this.onModsLoaded()}};
Q.prototype.onModsLoaded=function(){var a=this,b;B(this,Q);this.checkAllDependencies();this.orderMods();var c=this.mods;var d=0;for(b=c.length;d<b;d++){var e=c[d];e.enable=!0===this.enabledMods[e.id]}this.updateEnables();null!=this.selectedMod&&(b=this.mods.find(function(b){return b.id===a.selectedMod.id}),null!=b&&this.selectMod(b));this.modsLoaded=!0;if("function"===typeof this.onLoadedFn)this.onLoadedFn();return this.onLoadedFn=null};Q.prototype.checkAllDependencies=function(){var a;B(this,Q);
var b=this.mods;var c=[];var d=0;for(a=b.length;d<a;d++){var e=b[d];var f=this.checkDependencies(e);"okay"!==f&&(this.enabledMods[e.id]=!1);"okay"===f&&(e.invalid=!1);"missing"===f||"disabled"===f?(e.invalid=!0,"missing"===f?c.push(e.modError("A dependency could not be found")):c.push(void 0)):c.push(void 0)}return c};Q.prototype.checkDependencies=function(a){B(this,Q);if(null==a.dependencies)return"okay";var b="okay";var c=a.dependencies;var d=0;for(a=c.length;d<a;d++){var e=c[d];e=this.checkDependency(e);
if("missing"===e)return"missing";"disabled"===e&&(b="disabled")}return b};Q.prototype.checkDependency=function(a){var b;B(this,Q);var c=this.mods;var d=0;for(b=c.length;d<b;d++){var e=c[d];if(e.id===a.id&&(null==a.version||e.matchesVersionRange(a.version)))return this.enabledMods[e.id]?"okay":"disabled"}return"missing"};Q.prototype.tryEnableMod=function(a,b){B(this,Q);this.checkDependencies(a)&&!a.invalid?this.enabledMods[a.id]=b:this.enabledMods[a.id]=!1;this.checkAllDependencies();return this.updateEnables()};
Q.prototype.readModFiles=function(){B(this,Q);if(window.isElectron)try{return n.isIO()?["tce-io"]:O.scanDir(O.modDir()).filter(function(a){return O.isDir(O.modDir()+"/"+a)})}catch(b){var a=b;r.error("mod;readModFiles error "+a);return[]}else return window.modFiles};Q.prototype.readMod=function(a,b){var c=this;B(this,Q);var d=O.modDir()+"/"+a+"/mod.hjson";return O.readFileAsync(d,function(e){var f,g,h,k,l;var m=!1;try{if(null==e){r.error("mod;mod "+d+" not found",a);b();return}Object.isString(e)&&
(e=Hjson.parse(e));var p=new Rc(c.main,e,d);null!=p&&(null!=e.modInfo.steamId&&(l=""+e.modInfo.steamId),null!=l&&null==(null!=(h=c.steamCache)?null!=(k=h[p.id])?k.steamId:void 0:void 0)&&(null==c.steamCache&&(c.steamCache={}),null==c.steamCache[p.id]&&null==(f=c.steamCache)[g=p.id]&&(f[g]={}),c.steamCache[p.id].steamId=l,r.info("mod;found steam ID "+l+" for mod "+p.id)));a.endsWith(p.id)?p.ignore?p.modLog("mod;not enabled"):(c.mods.push(p),m=!0):p.modError("mod;doesn't match mod directory "+a)}catch(w){e=
w,r.error("mod;Couldn't load mod from "+d),r.error("mod;error: "+e.message),r.error("mod;exception: "+e)}return m?p.loadLangs(function(){c.enabledMods[p.id]?p.modLog("active"):p.modLog("loaded");return b()}):b()})};Q.prototype.draw=function(a,b,c){var d,e,f;this.r.drawFrame("menu_bg_1.png");var g=40*this.s;var h=40*this.s;var k=143*this.s;var l=300*this.s;this.r.ctx.font=config.fonts.technicalSmall;this.r.drawPanel(config.panel.info,g,h,k,l);g+=39*this.s;h+=42*this.s;this.canScrollUp=this.canScrollDown=
!1;k=null!=(e=this.extractingMods)?e:0;e=this.isSteamSyncRunning||!this.modsLoaded||0<k;k+=O.resCount-O.resDoneCount;if(!e){var m=this.mods.slice(this.scrollOffset);var p=0;for(d=m.length;p<d;p++){var n=m[p];if(null==(f=n.visible)||f){if(h>l+20*this.s){this.canScrollDown=!0;break}this.drawModSelectButton(n,g,h,a,b);h+=22*this.s}}}this.canScrollUp=0<this.scrollOffset&&!e;g+=8*this.s;h=l+10*this.s;this.canScrollUp?(this.r.drawSprite("hud_scrollButton_up.png",g,h,20*this.s,20*this.s,a,b),this.r.hitBox(g,
h,20*this.s,20*this.s,a,b)&&(this.mouseAction={id:"scrollUp"})):this.r.drawSprite("hud_scrollButton_up_inactive.png",g,h,20*this.s,20*this.s,a,b);this.canScrollDown?(this.r.drawSprite("hud_scrollButton_down.png",g+35*this.s,h,20*this.s,20*this.s,a,b),this.r.hitBox(g+35*this.s,h,20*this.s,20*this.s,a,b)&&(this.mouseAction={id:"scrollDown"})):this.r.drawSprite("hud_scrollButton_down_inactive.png",g+35*this.s,h,20*this.s,20*this.s,a,b);this.drawModInfo(a,b,e);this.drawDebugOptions(a,b,c);c=q.toText(e?
"txt-loading":"txt-base-return");0<k&&e&&(c+=" ("+k+")");this.r.drawExitButton(c,a,b)&&(this.mouseAction=e?null:{id:"return"});null!=this.tearCountdown&&0<this.tearCountdown&&(b=$jscomp.makeIterator(this.r.getCanvasSize()),a=b.next().value,b=b.next().value,this.r.ctx.globalAlpha=Math.min(1,this.tearCountdown),this.r.drawSprite("res_face_darwin.png",a/2,b/2,{valign:"c",halign:"c",scale:4}),this.r.ctx.globalAlpha=1,this.tearCountdown-=.016);this.ps.tickParticles(.016);return this.ps.drawParticles(!0,
new u(0,0))};Q.prototype.drawModSelectButton=function(a,b,c,d,e){var f="#dfa814";a===this.selectedMod&&(f="white");this.r.hitBox(b-6*this.s,c-11*this.s,90*this.s,17*this.s,d,e)&&(this.mouseAction={id:"select",data:a},f="white");this.r.drawPanel("action",b-20*this.s,c-11*this.s,110*this.s,17*this.s);this.r.ctx.font=config.fonts.technicalSmall;a.invalid&&(f="red");var g=a.name;20<g.length&&(g=g.slice(0,20)+"...");this.r.drawText(g,b+35*this.s,c,{fillColor:f,os:0,halign:"center"});return this.drawEnableButton(a,
b-30*this.s,c-16*this.s,d,e)};Q.prototype.drawModInfo=function(a,b,c){var d,e=this,f,g,h;var k=197*this.s;var l=45*this.s;var m=325*this.s;var p=300*this.s;this.r.drawPanel(config.panel.info,k-7*this.s,l-5*this.s,m,p);if(null!=this.selectedMod&&!c){l+=3*this.s;this.r.drawText(this.selectedMod.name,k+m/2,l+19*this.s,{font:config.fonts.themedLarge,fillColor:"#973200",halign:"center"});this.r.drawSprite("hud_line.png",k+m/2,l+27*this.s,{valign:"c",halign:"c"});this.r.ctx.save();this.r.ctx.rect(200*this.s,
90*this.s,m,p-70*this.s);this.r.ctx.clip();l+=this.infoScroll;this.limitedWidthLines=23;this.currLine=6;if(null!=this.selectedMod.score){c=5*this.selectedMod.score;this.drawModInfoTextLines(k,l,"                         "+this.selectedMod.votes,this.currLine);for(d=f=0;4>=f;d=++f)this.r.drawSprite("hud_unit_rank_blank.png",k+14*this.s+8*d*this.s,l+48*this.s);for(d=h=0;0<=c?h<=c:h>=c;d=0<=c?++h:--h)f={},d+1>c&&(f={clipWidth:c-Math.floor(c)}),this.r.drawSprite("hud_unit_rank_1.png",k+14*this.s+8*d*
this.s,l+48*this.s,f)}else this.currLine=4;c=k+216*this.s;d=l+117*this.s;this.r.drawSprite("hud_frame_mod.png",c,d,{valign:"c",halign:"c"});f=!1;if(null!=this.selectedMod.preview&&1<=this.r.img.getLoadState())if(this.r.img.hasSprite(this.selectedMod.preview,this.selectedMod))try{this.r.drawSprite(this.selectedMod.preview,c,d,{limitHeight:134*this.s,limitWidth:134*this.s,valign:"c",halign:"c"}),f=!0}catch(w){}else this.selectedMod.loadPreview();f||this.r.drawSprite("moddingDefaultImage.png",c,d,{limitHeight:134*
this.s,limitWidth:134*this.s,valign:"c",halign:"c"});this.currLine=this.drawModInfoHeader(k,l,q.toText("txt-mod-info"),this.currLine);c=[q.toText("txt-base-authors")+": "+this.selectedMod.authors.join(", "),q.toText("txt-highscore-version")+": "+this.selectedMod.getFullVersion(this.selectedMod.version),q.toText("txt-base-languages")+": "+this.selectedMod.defaultLang];this.currLine=this.drawModInfoTextLines(k,l,c.join(" \n "),this.currLine);null!=this.selectedMod.dependencies&&(this.currLine=this.drawModInfoHeader(k,
l,q.toText("txt-mod-dependencies"),this.currLine),c=this.selectedMod.dependencies.map(function(a){return a.id}).join(", "),this.currLine=this.drawModInfoTextLines(k,l,c,this.currLine));null!=this.selectedMod.featureList.special&&(this.currLine=this.drawModInfoHeader(k,l,q.toText("txt-mod-affects"),this.currLine),c=Object.keys(this.selectedMod.featureList.special).map(function(a){return""+a}).join(" | "),this.currLine=this.drawModInfoTextLines(k,l,c,this.currLine));null!=this.selectedMod.featureList.adds&&
(this.currLine=this.drawModInfoHeader(k,l,q.toText("txt-mod-adds"),this.currLine),c=Object.keys(this.selectedMod.featureList.adds).map(function(a){return a+":"+e.selectedMod.featureList.adds[a].count}).join(" | "),this.currLine=this.drawModInfoTextLines(k,l,c,this.currLine));this.currLine=this.drawModInfoHeader(k,l,q.toText("txt-base-description"),this.currLine);c=q.toText(null!=(g=this.selectedMod.description)?g:"-");this.currLine=this.drawModInfoTextLines(k,l,c,this.currLine);this.infoScrollMax=
(this.currLine*this.textSpacing+50)*this.s-p;0>this.infoScrollMax&&(this.infoScrollMax=0);this.r.ctx.restore();l-=this.infoScroll;this.drawModLinks(k+m-28*this.s,l+p-47*this.s,a,b);return this.drawInfoScrollbar(505*this.s,66*this.s,136*this.s,a,b)}};Q.prototype.drawModInfoTextLines=function(a,b,c,d){var e;B(this,Q);var f=120*this.s;var g=275*this.s;this.r.ctx.font=config.fonts.technicalSmall;var h=0;if(d<this.limitedWidthLines){var k=q.wrap(c,f,this.r.ctx);var l=0;for(e=k.length;l<e;l++){f=k[l];if(d+
h<this.limitedWidthLines)this.r.drawText(f,a+15*this.s,b+(h+d)*this.textSpacing*this.s,{fillColor:"black",os:0});else{c=k.slice(h).join(config.diaryText.separator);d+=h;h=0;break}h+=1}}if(Object.isString(c)&&0===h)for(k=q.wrap(c,g,this.r.ctx),g=0,c=k.length;g<c;g++)f=k[g],this.r.drawText(f,a+15*this.s,b+(h+d)*this.textSpacing*this.s,{fillColor:"black",os:0}),h+=1;return d+h};Q.prototype.drawModInfoHeader=function(a,b,c,d){B(this,Q);this.r.drawText(c,a+15*this.s,b+(d+1.9)*this.textSpacing*this.s,{font:config.fonts.technicalLarge,
fillColor:"#973200",halign:"left"});return d+3};Q.prototype.drawModLinks=function(a,b,c,d){var e;B(this,Q);var f=["twitter","mail","steam","weblink"];var g=[];var h=0;for(e=f.length;h<e;h++){var k=f[h];null!=this.selectedMod[k]&&(this.r.drawSprite("hud_button_"+k+".png",a,b,{mX:c,mY:d})&&(this.mouseAction={id:"link",data:this.selectedMod[k]}),g.push(b-=28*this.s))}return g};Q.prototype.drawInfoScrollbar=function(a,b,c,d,e){B(this,Q);if(0!==this.infoScrollMax){this.r.ctx.save();this.r.ctx.beginPath();
this.r.ctx.moveTo(a,b-1);this.r.ctx.lineTo(a,b+c+1);this.r.ctx.lineWidth=6*this.s;this.r.ctx.strokeStyle="black";this.r.ctx.stroke();this.r.ctx.restore();var f=100/this.infoScrollMax;f=J.clamp(f,.1,.8);f*=c;var g=(c-f)*this.infoScroll/this.infoScrollMax;this.r.ctx.save();this.r.ctx.beginPath();this.r.ctx.moveTo(a+1,b-g);this.r.ctx.lineTo(a+1,b+f-g);this.r.ctx.lineWidth=4*this.s;this.r.ctx.strokeStyle="white";this.r.ctx.stroke();this.r.ctx.restore();if(this.r.hitBox(a-2*this.s,b,6*this.s,c*this.s,
d,e))return a=J.clamp((e-f/2-b)/(c-f),0,1),a*=c,a>this.infoScrollMax&&(a=this.infoScrollMax),this.mouseAction={id:"setInfoScroll",data:-a}}};Q.prototype.drawEnableButton=function(a,b,c,d,e){B(this,Q);if(this.r.drawImageCheckbox("hud_checkbox",b+5*this.s,c+5*this.s,d,e,{state:a.invalid||!this.enabled?"disabled":this.enabledMods[a.id]?"enabled":"neutral"}))return this.mouseAction={id:"toggle",data:a}};Q.prototype.drawOptionButton=function(a,b,c,d,e,f,g,h,k,l){l=void 0===l?!0:l;var m="black";b=q.toText(b);
l?this.r.hitBox(c,d,e,f,g,h)&&(this.mouseAction={id:a},m="#973200",k&&(d+=this.s)):m="gray";this.r.drawPanel("menuButton",c,d,e,f);return this.r.drawText(b,c+20*this.s,d+13*this.s,{font:config.fonts.technicalSmall,fillColor:m,os:0})};Q.prototype.drawDebugOptions=function(a,b,c){var d,e,f;B(this,Q);var g=$jscomp.makeIterator(this.r.getCanvasSize());var h=g.next().value;g.next();var k=Object.keys(this.debugOptions);var l=(this.menuOptionsMaxWidth+3+18)*this.r.s;h=h-l-5*this.s;g=40*this.r.s;var m="white";
this.r.drawImageCheckbox("hud_checkbox",h+6*this.s,g+3*this.s,a,b,{state:this.enabled?this.active?"enabled":"neutral":"disabled"})&&(this.mouseAction={id:"toggleModding"});this.r.drawText(q.toText("txt-mainmenu-mods"),h+28*this.s,g+13*this.s,{font:config.fonts.technicalSmall,fillColor:m,os:1});g+=28*this.s;this.drawOptionButton("refresh","txt-mod-refresh",h,g,l,23*this.r.s,a,b,c,!this.isSteamSyncRunning&&this.canUpload&&this.modsLoaded);g+=28*this.s;this.drawOptionButton("toggleLog","txt-mod-log",
h,g,l,23*this.r.s,a,b,c);g+=28*this.s;window.isSteam&&(this.drawOptionButton("workshop","txt-mod-workshop",h,g,l,23*this.r.s,a,b,c),g+=28*this.s);this.drawOptionButton("toggleDebug","txt-mod-tools",h,g,l,23*this.r.s,a,b,c);g+=23*this.s;if(this.showDebug){this.r.ctx.globalAlpha=1;this.r.ctx.strokeStyle="white";this.r.ctx.lineWidth=2;this.r.ctx.font=config.fonts.technicalSmall;this.r.drawInfoBox(h+5*this.s,g,l-10*this.s,(16*k.length+10)*this.r.s);h+=10*this.r.s;g+=15*this.r.s;var p=0;for(d=k.length;p<
d;p++){var n=k[p];m="white";this.r.drawCheckbox(h,g+2*this.r.s,a,b,{checked:this.debugOptions[n]})&&(this.mouseAction={id:"toggleOption",data:n},m="#973200","showDebugBar"===n&&this.main.infoBox.setInfo([{text:q.toText("txt-mod-achievementWarning"),col:"red"}],a,b+65*this.s));n=n.spacify().capitalize(!0,!0);this.r.drawText(n,h+21*this.s,g,{fillColor:m,os:0});g+=16*this.r.s}}this.showDebug?(g+=12*this.s,h-=10*this.r.s):g+=5*this.s;if(window.isSteam&&null!=this.selectedMod&&this.selectedMod.mine)return m=
this.canUpload?"txt-mod-upload":"txt-mod-uploading",m=this.isSteamSyncRunning?"txt-loading":m,this.drawOptionButton("workshopUpload",m,h,g,l,23*this.r.s,a,b,c,this.canUpload&&!this.isSteamSyncRunning),g+=33*this.s,a=null!=(e=r.modErrorCounts[this.selectedMod.id])?e:0,e=null!=(f=r.modWarnCounts[this.selectedMod.id])?f:0,this.r.drawInfoBox(h,g,110*this.s,30*this.s),this.r.ctx.font=this.r.getDebugFont(),h+=3*this.s,g+=8*this.s,f=q.toText("txt-mod-logReport").replace("$modID",this.selectedMod.id),this.r.drawText(f,
h,g,{fillColor:"white",os:0}),g+=this.textSpacing*this.s,m=0<a?"red":"green",f=q.toText("txt-mod-errorCount").replace("$count",a),this.r.drawText(f,h,g,{fillColor:m,os:0}),g+=this.textSpacing*this.s,m=0<e?"yellow":"green",f=q.toText("txt-mod-warnCount").replace("$count",e),this.r.drawText(f,h,g,{fillColor:m,os:0})};Q.prototype.massEnable=function(a){a=void 0===a?!0:a;var b;B(this,Q);var c=this.mods;var d=0;for(b=c.length;d<b;d++){var e=c[d];this.tryEnableMod(e,a)}return this.massState=a};Q.prototype.startSteamUpload=
function(){var a=this;B(this,Q);if(window.isSteam){var b=require("os");var c=require("path");r.info("mod;Checking mod and code dependencies");if(this.selectedMod.mine&&window.isSteam&&null!=b&&null!=c&&this.canUpload)return this.targetPath=c.resolve(b.tmpdir(),this.selectedMod.id+".zip"),b=c.resolve(window.rootPath,O.modDir(),this.selectedMod.id),greenworks.enableCloud(!0),this.uploadMod=this.selectedMod,this.canUpload=!1,this.uploadMod.modLog("Packing archive: "+b+" -> "+this.targetPath),greenworks.Utils.createArchive(this.targetPath,
b,"",5,function(){return a.steamUpload(a.targetPath)},this.steamFail);r.error("mod;Can not upload mod ")}};Q.prototype.steamUpload=function(a){var b=this;B(this,Q);var c=[a];null!=this.uploadMod.preview&&c.push(this.uploadMod.getPreviewPath());r.info("STEAM;Uploading mod:\n"+c.join("\n"));greenworks.saveFilesToCloud(c,function(){r.info("mod;saveFilesToCloud SUCCESS");return greenworks.fileShare(a,b.steamPublish,b.steamFail)},this.steamFail)};Q.prototype.steamPublish=function(){var a,b;B(this,Q);var c=
null;null!=this.steamCache[this.uploadMod.id]&&(c=this.steamCache[this.uploadMod.id].steamId);null!=c&&r.info("mod;found steam ID "+c);var d=null!=(a=this.uploadMod.getPreviewPath())?a:"";a=null!=(b=this.uploadMod.description)?b:"";if(null==c)return r.info("mod;publish as new"),greenworks.publishWorkshopFile(this.targetPath,d,this.uploadMod.name,a,this.steamSuccess,this.steamFail);r.info("mod;publish as update");return greenworks.updatePublishedWorkshopFile(c,this.targetPath,d,this.uploadMod.name,
a,this.steamSuccess,this.steamFail)};Q.prototype.steamFail=function(a){B(this,Q);this.canUpload=!0;this.doTears();return r.error("mod;SteamFail: "+a)};Q.prototype.steamSuccess=function(a){var b,c;B(this,Q);this.uploadMod.modLog("mod;Successfully uploaded!");this.doConfetti();null!=a&&(null==(b=this.steamCache)[c=this.uploadMod.id]&&(b[c]={}),this.steamCache[this.uploadMod.id].steamId=a,n.canUseLocalStorage()&&localStorage.setItem("steamModCache",JSON.stringify(this.steamCache)));return this.canUpload=
!0};Q.prototype.doConfetti=function(){var a,b,c;B(this,Q);var d=$jscomp.makeIterator(this.r.getCanvasSize());var e=d.next().value;d=d.next().value;this.sfx.play("cheer3",!1);for(a=b=1;8>=b;a=++b)this.ps.addParticleConf("pt-confetti-2",new u(a/10*e,d/2),{isAbsolute:!0});b=[];for(a=c=1;8>=c;a=++c)b.push(this.ps.addParticleConf("pt-fireworks",new u(a/10*e,d/2),{isAbsolute:!0}));return b};Q.prototype.doTears=function(){B(this,Q);var a=$jscomp.makeIterator(this.r.getCanvasSize());var b=a.next().value;
a=a.next().value;this.sfx.play("sfx_campClose",!1);this.tearCountdown=5;this.ps.addParticleConf("pt-tears",new u(b/2-10*this.s,a/2-16*this.s),{isAbsolute:!0});return this.ps.addParticleConf("pt-tears",new u(b/2+10*this.s,a/2-16*this.s),{isAbsolute:!0})};Q.prototype.steamSync=function(){B(this,Q);if(window.isSteam&&!this.isSteamSyncRunning&&this.modsLoaded&&!(0<this.extractingMods)){var a=require("path").resolve(window.rootPath,O.modDir());this.isSteamSyncRunning=!0;r.info("mod;calling ugcSynchronizeItems with dir "+
a);return greenworks.ugcSynchronizeItems(a,this.steamSyncDone,this.steamSyncFail)}};Q.prototype.steamSyncFail=function(a){B(this,Q);this.isSteamSyncRunning=!1;r.error("mod;steamSyncFail: "+a);return this.steamFail(a)};Q.prototype.steamSyncDone=function(a){var b,c,d;B(this,Q);try{var e=O.scanDir(O.modDir()).filter(function(a){return a.endsWith(".zip")});this.ensureModDirExists();var f=0;for(b=e.length;f<b;f++){var g=e[f];r.info("mod;found archive "+g)}var h=require("path");null==this.extractingMods&&
(this.extractingMods=0);var k=h.resolve(window.rootPath,O.modDir());var l=0;for(c=a.length;l<c;l++){var m=a[l];if(null!=m.publishedFileId){var p=m.fileName.slice(0,-4);this.steamCache[p]={steamId:m.publishedFileId,score:m.score,votes:m.votesDown+m.votesUp,updated:m.isUpdated};r.info("mod;received id "+m.publishedFileId+" for mod "+p)}var w=h.resolve(window.rootPath,O.modDir(),m.fileName);this.extractingMods+=1;r.info("mod;Extracting "+w+" to "+k);greenworks.Utils.extractArchive(w,k,"",this.steamUnzipDone,
this.steamUnzipFail);e.remove(m.fileName)}var q=0;for(d=e.length;q<d;q++)g=e[q],this.steamRemoveMod(g.slice(0,-4));n.canUseLocalStorage()&&window.localStorage.setItem("steamModCache",JSON.stringify(this.steamCache));this.isSteamSyncRunning=!1;if(0===this.extractingMods)return this.loadMods()}catch(D){return a=D,r.error("mod; error in steamSyncDone: '"+a.message+"' _ "+a.stack)}};Q.prototype.steamRemoveMod=function(a){B(this,Q);var b=require("path");require("fs");try{var c=b.join(O.modDir(),a+".zip");
O.removeFile(c)}catch(f){var d=f;r.error("mod;failed deleting "+c+" "+d)}try{var e=b.join(O.modDir(),a);return O.removeFolder(e)}catch(f){return d=f,r.error("mod;failed deleting  "+b.resolve(window.rootPath,e)+" "+d)}};Q.prototype.steamUnzipDone=function(){B(this,Q);--this.extractingMods;if(0===this.extractingMods)return this.loadMods()};Q.prototype.steamUnzipFail=function(a){B(this,Q);--this.extractingMods;r.error("mod;failed to unzip mod file: "+a);return this.steamUnzipDone()};Q.prototype.ensureModDirExists=
function(){B(this,Q);var a=require("fs");var b=Ga.resolve(window.rootPath,O.modDir());if(!a.existsSync(b))return a.mkdirSync(b)};Q.prototype.onSteamOverlay=function(a){B(this,Q);if(!a&&this.main.mainStates.some(function(a){return"modding"===a.id}))return this.steamSync()};Q.prototype.updateEnables=function(){B(this,Q);this.active=this.enabled&&Object.values(this.enabledMods).any(!0);n.canUseLocalStorage()&&(window.localStorage.setItem("enabledMods",JSON.stringify(this.enabledMods)),window.localStorage.setItem("modding",
this.enabled));return this.main.entitiesDirty=!0};Q.prototype.onMouseWheel=function(a){B(this,Q);var b=$jscomp.makeIterator(this.main.mousePos.lst());var c=b.next().value;b.next();c<175*this.s?0>a&&this.canScrollDown?this.scrollOffset+=1:0<a&&this.canScrollUp&&--this.scrollOffset:(this.infoScroll+=a,this.infoScroll=J.clamp(this.infoScroll,-this.infoScrollMax,0))};Q.prototype.onKeyDown=function(a){B(this,Q)};Q.prototype.onMouseDown=function(a){B(this,Q);if(null!=this.mouseAction&&"setInfoScroll"===
this.mouseAction.id)return this.infoScroll=this.mouseAction.data};Q.prototype.selectMod=function(a){this.selectedMod=a;this.selectedMod.updateMetaData(this.steamCache[a.id]);this.selectedMod.applyLangs();return this.infoScroll=0};Q.prototype.onMouseClick=function(a){var b;if(null!=this.mouseAction)switch(this.mouseAction.id){case "return":if(this.isSteamSyncRunning)break;this.main.prepareEntities();this.main.gotoMainMenu();break;case "toggle":this.enabled?this.tryEnableMod(this.mouseAction.data,!this.enabledMods[this.mouseAction.data.id]):
(this.enabled=!0,this.tryEnableMod(this.mouseAction.data,!0));this.updateEnables();break;case "select":this.selectMod(this.mouseAction.data);break;case "workshop":window.isSteam&&(greenworks.ugcShowOverlay(),n.isMac()&&n.openLink("http://steamcommunity.com/app/358130/workshop/"));break;case "workshopUpload":this.startSteamUpload();break;case "toggleOption":this.debugOptions[this.mouseAction.data]=!this.debugOptions[this.mouseAction.data];n.canUseLocalStorage()&&window.localStorage.setItem("debugOptions",
JSON.stringify(this.debugOptions));break;case "toggleModding":this.enabled=!this.enabled;this.updateEnables();break;case "scrollDown":this.scrollOffset+=1;break;case "scrollUp":--this.scrollOffset;break;case "toggleDebug":this.showDebug=!this.showDebug;break;case "toggleLog":r.openWindow();break;case "refresh":window.isSteam?this.steamSync():this.loadMods();break;case "link":null!=(b=this.mouseAction.data)&&b.startsWith("steam:")&&window.isSteam?greenworks.ugcShowOverlay(this.mouseAction.data.slice(6)):
n.openLink(this.mouseAction.data)}};var nb=function(a,b,c){a=W.call(this,a,b,c)||this;a.quickScroll=!1;return a};$jscomp.inherits(nb,W);nb.prototype.onMouseDown=function(a){return this.quickScroll=!0};nb.prototype.onMouseUp=function(a){this.quickScroll=!1;if("exit"===this.mouseAction)return this.sfx.fadeOut("clubMusic"),this.main.showCredits(!1)};nb.prototype.show=function(){var a,b;this.time=0;this.lines=[];var c=config.credits;var d=0;for(a=c.length;d<a;d++){var e=c[d];if("TRANSLATION"===e){var f=
q.langs;var g=0;for(e=f.length;g<e;g++){var h=f[g];this.lines.push("["+window.getLanguageName(h.id)+"]");var k=h.authors;var l=0;for(b=k.length;l<b;l++)h=k[l],this.lines.push(h);this.lines.push("")}}else this.lines.add(t.arrify(e,!1).randomize())}};nb.prototype.tick=function(a){this.quickScroll&&(a*=12);return this.time+=a};nb.prototype.draw=function(a,b,c){var d;var e=$jscomp.makeIterator(this.r.getCanvasSize());c=e.next().value;e=e.next().value;this.r.drawJungleBackground();this.mouseAction=null;
this.r.drawExitButton(q.toText("txt-base-return"),a,b)&&(this.mouseAction="exit");var f=12<this.time?20*(this.time-12)*this.s:0;b=e/2-160*this.s;this.r.ctx.fillStyle="white";this.r.ctx.font=config.fonts.technicalLarge;if(n.isChina())a=this.r.img.getSprite("MM_logo_chinese_greenOutline.png").img,this.r.ctx.drawImage(a,c/2-a.width/2,e/3-a.height/2);else{var g=this.lines;var h=d=0;for(a=g.length;d<a;h=++d){var k=g[h];"BREAK"===k?b=e:(b+=20*this.s,this.r.ctx.globalAlpha=J.clamp(this.time-.75*h,0,1),h=
b-f,0<h&&h<e+20*this.s&&this.r.drawText(k,c/2,h,{halign:"center"}))}}};var La=function(a,b,c){a=W.call(this,a,b,c)||this;a.drawCharacterInfo=a.drawCharacterInfo.bind(a);a.currentOffset=0;a.rows=2;a.maxCols=11;a.hasPlayedMusic=!1;a.explorerSelection=a.main.mainMenu.getExplorerSelection();a.didFinishBlendIn=!1;return a};$jscomp.inherits(La,W);La.prototype.show=function(){var a,b;this.chars=this.explorerSelection.slice(this.currentOffset,+(this.currentOffset+this.rows*this.maxCols-1)+1||9E9);this.time=
0;var c=this.chars;var d=b=0;for(a=c.length;b<a;d=++b){var e=c[d];this.resetFrame(e,.02*d)}this.tidy=!1;this.showExplorer=null;this.hasPlayedMusic||(this.sfx.fadeOut("titleMusic").play("clubMusic",!0),this.hasPlayedMusic=!0);if(debug.testExplorer&&null!=t.getCharacter(debug.testExplorer,!1))return this.main.selectExplorer(debug.testExplorer,this.createTrek(debug.testExplorer))};La.prototype.resetFrame=function(a,b){b=void 0===b?0:b;a.rotation=0;a.targetRotation=this.tidy?0:J.rand(-.05,.05);return a.time=
-b};La.prototype.tick=function(a){var b;if(!(1>this.r.img.getLoadState())){this.time+=a;1<=this.time&&(this.didFinishBlendIn=!0);var c=!0;var d=this.chars;var e=0;for(b=d.length;e<b;e++){var f=d[e];f.time+=a;f.rotation+=(f.targetRotation-f.rotation)*a*10;.015<Math.abs(f.targetRotation)&&(c=!1)}if(c&&!this.tidy)return this.sfx.play("cheer2"),this.tidy=!0}};La.prototype.doSelectExplorer=function(){if(null!=this.showExplorer&&this.showExplorer.available)return this.main.selectExplorer(this.showExplorer.id,
this.showTrek)};La.prototype.doShowExplorer=function(a){a===this.showExplorer?this.doSelectExplorer():(this.showExplorer=a,this.showTrek=[],this.sfx.play("nextChar"),a.available&&(this.showTrek=this.createTrek(a.id)))};La.prototype.createTrek=function(a){var b=t.getCharacter(a);a=[];var c=t.arrify(b.characters);var d=0;for(b=c.length;d<b;d++){var e=c[d];e=new Fa(this.main,e);null!=e.id&&(this.main.doRandEvent(e.spawnEvents,{person:e,silent:!0}),a.push(e))}return a};La.prototype.onMouseClick=function(a){if(null!=
this.mouseAction)switch(this.mouseAction.id){case "select":return this.doShowExplorer(this.mouseAction.data);case "continue":return this.doSelectExplorer();case "prevPage":return this.currentOffset=Math.max(0,this.currentOffset-this.rows*this.maxCols),this.show();case "nextPage":return this.currentOffset+=this.rows*this.maxCols,this.show();case "exit":return this.main.gotoMainMenu()}};La.prototype.onKeyPress=function(a){var b,c,d;if(32===a.which)return null==this.showExplorer?this.doShowExplorer(this.chars.filter(function(a){return a.available}).sample()):
this.doSelectExplorer();var e=[];var f=d=0;for(c=this.chars.length;0<=c?d<c:d>c;f=0<=c?++d:--d)if(b=(f+1).toString().charCodeAt(0)===a.which){this.doShowExplorer(this.chars[f]);break}else e.push(void 0);return e};La.prototype.draw=function(a,b,c){var d,e,f,g,h;var k=$jscomp.makeIterator(this.r.getCanvasSize());var l=k.next().value;var m=k.next().value;this.r.drawFrame("menu_bg_explorerSelection.png");if(1>this.r.img.getLoadState())null==this.loadCounter&&(this.loadCounter=0),this.loadCounter+=1,this.loadCounter%=
3,this.r.drawText("Loading "+".".repeat(this.loadCounter+1),l/2,m/2+50*this.r.s,{halign:"center",font:config.fonts.themedLarge});else if(1>this.r.img.getLoadState())null==this.loadCounter&&(this.loadCounter=0),this.loadCounter+=1,this.loadCounter%=3,this.r.drawText("Loading "+".".repeat(this.loadCounter+1),l/2,m/2+50*this.r.s,{halign:"center",font:config.fonts.themedLarge});else{var p=this.chars.length;var n=0;var t=null;var r=Math.min(p,Math.ceil(this.chars.length/2));var v=g=0;for(d=this.rows;0<=
d?g<d:g>d;v=0<=d?++g:--g)for(p-=r,k=h=0,e=r;(0<=e?h<e:h>e)&&!(n>=this.chars.length);k=0<=e?++h:--h){var y=this.chars[n];this.drawCharFrame(y,k,v,a,b)&&(t=y,t.rotation=0);n+=1}c&&null!=t&&(this.mouseAction={id:"select",data:t});null!=this.showExplorer?(this.drawCharacterInfo(this.showExplorer,a,b),null!=(f=this.showExplorer)&&f.available&&this.r.drawButton(q.toText("txt-base-continue"),l/2,m/2+135*this.s,130*this.s,25*this.s,a,b,c)&&(this.mouseAction={id:"continue"})):(this.r.ctx.globalAlpha=this.didFinishBlendIn?
1:Math.min(2*this.time,1),this.r.ctx.fillStyle="white",this.r.drawText(q.toText("txt-gallery-choose"),l/2,m/2+100*this.s,{halign:"center",font:config.fonts.themedLarge}));this.chars.length<this.explorerSelection.length&&(0<this.currentOffset&&(c=$jscomp.makeIterator([18*this.s,m/2+14*this.s]),k=c.next().value,v=c.next().value,this.r.hitBox(k,v,20*this.s,20*this.s,a,b)&&(this.mouseAction={id:"prevPage"},k-=2*this.s),this.r.drawSprite("hud_scrollButton_charSelect_left.png",k,v,20*this.s,20*this.s,a,
b)),this.currentOffset+this.rows*this.maxCols<this.explorerSelection.length&&(l=$jscomp.makeIterator([l-32*this.s,m/2+14*this.s]),k=l.next().value,v=l.next().value,this.r.hitBox(k,v,20*this.s,20*this.s,a,b)&&(this.mouseAction={id:"nextPage"},k+=2*this.s),this.r.drawSprite("hud_scrollButton_charSelect_right.png",k,v,20*this.s,20*this.s,a,b)));if(this.r.drawExitButton(q.toText("txt-base-return"),a,b))return this.mouseAction={id:"exit"}}};La.prototype.drawCharFrame=function(a,b,c,d,e){var f=$jscomp.makeIterator(this.r.getCanvasSize());
var g=f.next().value;var h=f.next().value;var k=$jscomp.makeIterator([32*this.s,32*this.s]);f=k.next().value;var l=k.next().value;var m=25*this.s;k=!1;var p=Math.min(this.chars.length,Math.ceil(this.chars.length/2));var n=.1>a.time?J.lerp(0,1,a.time,.1):1-TWEEN.Easing.Bounce.Out((1.2*a.time).clamp(0,1));b=(new u(g/2-p/2*(f+m)+(f+m)*b+20,Math.max(25*this.s,h/2-100*this.s)+c*(l+36*this.s))).floor();c=-5*this.s*Math.max(n,0);g=a.rotation;this.r.hitBox(b.x-5*this.s,b.y-20*this.s,45*this.s,60*this.s,d,
e)&&(k=!0,c-=5*this.s);k||a!==this.showExplorer||(g=0);a.hintNew&&(this.r.ctx.font=config.fonts.technicalSmall,this.r.drawText(q.toText("txt-base-new"),b.x+f/2,b.y-5*this.s+c,{halign:"center"}));this.r.drawSprite(a.hintWonHard?"hud_char_frame_silver.png":a.hintWon?"hud_char_frame_golden.png":"hud_char_frame.png",b.x-5*this.s,b.y-15*this.s+c,{rotate:g});this.r.drawSprite(a.variations[0].portrait,b.x+19*this.s,b.y+35.5*this.s+c,{halign:"center",valign:"bottom",silhouette:a.available?null:"black"});
return k};La.prototype.drawCharacterInfo=function(a,b,c){var d,e,f,g,h,k,l,m,p,w;B(this,La);var r=$jscomp.makeIterator(this.r.getCanvasSize());var D=r.next().value;r=r.next().value/2-50*this.s;var v=460*this.s;this.r.drawPanel(config.panel.info,D/2-v/2,r+70*this.s,v,110*this.s);this.r.ctx.font=config.fonts.themedLarge;if(a.random)a=q.toText("txt-gallery-random"),this.r.drawText(a,D/2,r+120*this.s,{halign:"center",fillColor:config.colors.partyBorder,os:0});else{a.available&&this.r.drawText(q.toText(a.name),
D/2,r+100*this.s,{halign:"center",fillColor:"black",os:0});var y=a.available?[a.description]:["???","",a.unlockHint];v={font:config.fonts.themedSmall,halign:"center",fillColor:config.colors.partyBorder,os:0};var Y=null!=(e=null!=(p=a.gender)?p:null!=(d=a.variations)?null!=(g=d[0])?g.gender:void 0:void 0)?e:"male";e=g=0;for(d=y.length;g<d;e=++g)p=y[e],this.r.drawText(q.parse(p,Y),D/2,r+115*this.s+10*e*this.s,v);if(a.available){this.r.ctx.fillStyle=config.colors.mapLines;Y=t.arrify(a.characters);e=
null!=(h=a.items)?h:{};v.fillColor="#222";this.r.ctx.font=config.fonts.themedSmall;p=$jscomp.makeIterator([32*this.s,32*this.s]);h=p.next().value;p=p.next().value;Y=D/2-n.width(Y.length,h,10*this.s)/2-100*this.s;y=r+171*this.s;var A=this.showTrek;var H=0;for(g=A.length;H<g;H++)d=A[H],this.r.drawPortrait(d,Y+h/2,y,{halign:"center"}),this.r.hitBox(Y,y-p,h,p,b,c)&&this.main.infoBox.setInfo([{text:d.title},{text:d.description}],b,c),Y+=h+10*this.s;h=15*this.s;Y=D/2-n.width(Object.size(e),h,10*this.s)/
2+100*this.s;y=r+145*this.s;for(G in e)d=e[G],d=new jb(this.main,G,d),this.r.drawItem(d,Y,y,{showDecorator:!1}),this.r.hitBox(Y,y,h+5*this.s,p,b,c)&&this.main.infoBox.setInfo([{text:d.name},{text:d.description}],b,c),Y+=h+10*this.s;v.fillColor="#222";v.font=config.fonts.technicalSmall;b=t.arrify(null!=(f=a.levels)?f[0].statuses:void 0);e=f=0;for(c=b.length;f<c;e=++f){var G=b[e];G=t.getStatus(G);p=q.parse(G.title,null!=(w=null!=(k=null!=(l=a.variations)?null!=(m=l[0])?m.gender:void 0:void 0)?k:a.gender)?
w:"male");if(null!=G.description)p+=" - "+q.toText(G.description);else if(null!=G.bonus)for(y=q.bonusHelp(G.bonus),G=0,h=y.length;G<h;G++)Y=y[G],p+=" - "+Y;this.r.drawText(p,D/2,r+130*this.s+10*e*this.s,v)}}}};var za=function(a,b,c){var d,e;a=W.call(this,a,b,c)||this;a.drawAchievements=a.drawAchievements.bind(a);a.drawAchievement=a.drawAchievement.bind(a);a.onKeyPress=a.onKeyPress.bind(a);b=a.main.mainMenu;a.topScores=null!=(d=b.playerData.topScores)?d:[];a.explorerScores=Object.clone(null!=(e=b.playerData.explorerScores)?
e:{});return a};$jscomp.inherits(za,W);za.prototype.show=function(){var a,b;this.topScores.remove(function(a){return null==a.id});var c=this.topScores;var d=0;for(b=c.length;d<b;d++){var e=c[d];e.points=this.calcPoints(e.difficulty,e.fame)}b=this.explorerScores;for(a in b)e=b[a],e.points=this.calcPoints(e.difficulty,e.fame);this.topScores=this.topScores.sortBy(function(a){return a.points},!0);this.showScores();if(n.isChina())return debug.drawAllItems=!0};za.prototype.showScores=function(){this.showingAchievements=
!1;this.showingScores=!0;return this.showingItems=!1};za.prototype.showItems=function(){this.showingScores=this.showingAchievements=!1;return this.showingItems=!0};za.prototype.showAchievements=function(){this.showingAchievements=!0;return this.showingItems=this.showingScores=!1};za.prototype.resetScores=function(){var a=this.main.mainMenu;this.topScores=a.playerData.topScores=[];a.playerData.explorerScores={};return this.explorerScores={}};za.prototype.calcPoints=function(a,b){return Math.round(b*
(0===a?config.score.easyModifier:2===a?config.score.hardModifier:config.score.mediumModifier))};za.prototype.addScore=function(a,b,c,d,e,f){var g;n.assert(null!=a);var h={points:this.calcPoints(d,b),id:a,fame:b,worldLvl:c,difficulty:d,rank:e,version:f};b=this.topScores.findIndex(function(a){return a.points<h.points});0>b&&(b=this.topScores.length);this.topScores.splice(b,0,h);this.topScores=this.topScores.slice(0,50);b=this.explorerScores[a];if(null==b||h.points>=b.points)this.explorerScores[a]=h;
c=this.topScores;d=0;for(b=c.length;d<b;d++)a=c[d],a.isNew=!1;b=this.explorerScores;for(g in b)a=b[g],a.isNew=!1;h.isNew=!0;this.main.mainMenu.playerData.topScores=this.topScores;this.main.mainMenu.playerData.explorerScores=this.explorerScores;return this.main.mainMenu.updatePlayerData()};za.prototype.draw=function(a,b,c){this.r.drawFrame("menu_bg_1.png");this.showingScores?this.drawScores(a,b,c):this.showingItems?this.drawItems(a,b,c):this.showingAchievements&&this.drawAchievements(a,b,c);var d=
q.toText("txt-highscore-scores");this.r.drawButton(d,60*this.s,5*this.s,100*this.s,25*this.s,a,b,c)&&(this.mouseAction="scores");d=q.toText("txt-highscore-items");this.r.drawButton(d,165*this.s,5*this.s,100*this.s,25*this.s,a,b,c)&&(this.mouseAction="items");d=q.toText("txt-highscore-achievements");this.r.drawButton(d,270*this.s,5*this.s,100*this.s,25*this.s,a,b,c)&&(this.mouseAction="achievements");if(this.r.drawExitButton(q.toText("txt-base-return"),a,b))return this.mouseAction="return"};za.prototype.drawScores=
function(a,b,c){var d,e,f;var g=$jscomp.makeIterator(this.r.getCanvasSize());c=g.next().value;g=g.next().value;this.r.ctx.globalAlpha=1;this.r.ctx.fillStyle="black";this.r.drawPanel(config.panel.info,c/2-310*this.s,g/2-140*this.s,190*this.s,310*this.s);this.r.drawPanel(config.panel.info,c/2-95*this.s,g/2-140*this.s,380*this.s,310*this.s);var h={font:config.fonts.themedLarge,halign:"center"};this.r.ctx.globalAlpha=1;this.r.drawText(q.toText("txt-highscore-topscores"),c/2-315*this.s+95*this.s,g/2-110*
this.s,h);this.r.drawText(q.toText("txt-highscore-explorerscores"),c/2-95*this.s+190*this.s,g/2-110*this.s,h);var k=this.topScores.slice(0,8);var l=e=0;for(d=k.length;e<d;l=++e){h=k[l];var m=c/2-285*this.s;var p=g/2-100*this.s+32*l*this.s;this.r.drawText(l+1+".",m-5*this.s,p+15*this.s,{font:config.fonts.technicalLarge,fillColor:"black",os:0});l=t.getCharacter(h.id,!1);null!=l&&(this.r.drawPortrait(l,m+18*this.s,p+10*this.s,{small:!0,halign:"center",valign:"center"}),this.drawScore(h,m,p-2*this.s,
a,b))}k=Object.values(this.explorerScores).sortBy(function(a){return a.points},!0).slice(0,16);e=[];l=f=0;for(d=k.length;f<d;l=++f)h=k[l],m=c/2-80*this.s+200*Math.floor(l/8)*this.s,p=g/2-100*this.s+l%8*32*this.s,l=t.getCharacter(h.id,!1),null!=l&&(this.r.drawPortrait(l,m+18*this.s,p+10*this.s,{small:!0,halign:"center",valign:"center"}),e.push(this.drawScore(h,m,p-2*this.s,a,b)));return e};za.prototype.drawScore=function(a,b,c,d,e){var f;if(null!=a){var g=a.isNew?config.colors.science:"white";this.r.drawText(a.points,
b+35*this.s,c+12*this.s,{font:config.fonts.technicalLarge,fillColor:g,os:1});var h=null!=(f=a.difficulty)?f:1;g=function(){switch(h){case 0:return"txt-difficulty-easy";case 1:return"txt-difficulty-medium";case 2:return"txt-difficulty-hard"}}();g=q.toText(g);this.r.drawText(q.toText("txt-highscore-expedition")+" "+(a.worldLvl+1)+" ("+g+")",b+35*this.s,c+22*this.s,{font:config.fonts.technicalSmall,fillColor:"black",os:0});if(this.r.hitBox(b+5*this.s,c,140*this.s,25*this.s,d,e)&&(b=t.getCharacter(a.id,
!1),null!=b.id))return this.main.infoBox.setInfo([{text:b.name},{text:q.toText("txt-highscore-score")+": "+a.points},{text:q.toText("txt-highscore-fame")+": "+a.fame},{text:q.toText("txt-highscore-expedition")+": "+(a.worldLvl+1)},{text:q.toText("txt-highscore-difficulty")+": "+g},{text:q.toText("txt-highscore-version")+": "+a.version}])}else return this.r.drawText("-",b+35*this.s,c+15*this.s,{font:"18px Aldrich",fillColor:"black",os:0})};za.prototype.drawItems=function(a,b,c){var d=$jscomp.makeIterator(this.r.getCanvasSize());
c=d.next().value;d=d.next().value;this.r.ctx.globalAlpha=1;this.r.ctx.fillStyle="black";this.r.drawPanel(config.panel.info,c/2-310*this.s,d/2-140*this.s,620*this.s,310*this.s);var e=$jscomp.makeIterator([c/2-310*this.s,d/2-125*this.s,0]);d=e.next().value;var f=e.next().value;e=e.next().value;var g={mX:a,mY:b,showCount:!1,showDecorator:!1};var h={mX:a,mY:b,showCount:!1,showDecorator:!1,silhouette:"black"};b=Object.values(config.items);var k=0;for(a=b.length;k<a;k++){var l=b[k];var m=t.getItem(l);if(!m.isAbstract&&
!0!==m.metaItem&&!1!==m.showInHallOfFame&&null!=m.sprite&&(null==m.mod||"base"===m.mod)){0===e%22&&(d=c/2-300*this.s,f+=30*this.s);d+=25*this.s;e+=1;var p=(l=debug.drawAllItems||this.main.mainMenu.itemsFound.any(m.id))?g:h;this.r.drawItem(m,d,f,p)&&(l?this.main.infoBox.setInfo([{text:m.name},{text:m.description}]):this.main.infoBox.setInfo([{text:"???"}]))}}};za.prototype.drawAchievements=function(a,b,c){var d;B(this,za);var e=$jscomp.makeIterator(this.r.getCanvasSize());c=e.next().value;e=e.next().value;
this.r.ctx.globalAlpha=1;this.r.ctx.fillStyle="black";this.r.drawPanel(config.panel.info,c/2-310*this.s,e/2-140*this.s,620*this.s,310*this.s);var f=d=0;this.hoverAchievement=null;e=Object.keys(this.main.achievements.achievements);var g=0;for(c=e.length;g<c;g++){var h=e[g];h=this.main.achievements.achievements[h];this.r.ctx.lineWidth=Math.floor(this.s);var k=h.unlocked.lastIndexOf(!0);this.r.ctx.strokeStyle=-1<k?config.colors.achievements[k]:"#422406";this.r.ctx.strokeRect((53+50*d)*this.s,(57+48*
f)*this.s,34*this.s,34*this.s);this.drawAchievement(h,(54+50*d)*this.s,(58+48*f)*this.s,a,b);d+=1;10<d&&(d=0,f+=1)}if(null!=this.hoverAchievement)return this.r.drawAchievement(395*this.s,285*this.s,200,52,this.hoverAchievement)};za.prototype.drawAchievement=function(a,b,c,d,e){B(this,za);var f=""+a.img;debug.drawAllItems||a.unlocked.some(!0)||(a.secret||(f+="_grey"),a.secret&&(f="achv_img_ID_secret_grey"));f+=".png";null==f&&(f="achv_img_ID_secret_grey.png");if(this.r.drawSprite(f,b,c,{mX:d,mY:e,
scale:.5}))return this.hoverAchievement=a};za.prototype.onMouseClick=function(a){switch(this.mouseAction){case "return":return this.main.gotoMainMenu();case "items":return this.showItems();case "scores":return this.showScores();case "achievements":return this.showAchievements()}};za.prototype.onKeyPress=function(a){B(this,za);if(n.isChina())return a=String.fromCharCode(a.which),null==this.unlockBuffer&&(this.unlockBuffer=""),7<=this.unlockBuffer.length&&(this.unlockBuffer=this.unlockBuffer.substr(1,
7)),this.unlockBuffer+=a,r.info(this.unlockBuffer),"159753a"===this.unlockBuffer&&(debug.drawAllItems=!debug.drawAllItems),!0};var Ha=function(a,b,c){c=void 0===c?0:c;var d,e,f,g,h,k,l,m,p,w,r;this.main=a;n.assert(null!=this.main);this.id=b;this.amount=c;var D=t.getItem(b);n.assert(!D.isAbstract,"Can't create abstract item");this.name=q.toText(null!=(d=D.name)?d:"Unnamed item");this.description=q.toText(D.description);this.debugCategory=D.debugCategory;this.value=null!=(g=D.value)?g:1;this.maxStack=
null!=(h=D.maxStack)?h:10;this.maxChargeTime=null!=(k=D.maxChargeTime)?k:0;this.sprite=null!=(l=D.sprite)?l:"it_misc_placeholder.png";this.flags=t.setFlags(D.flags);this.metaItem=null!=(m=D.metaItem)?m:!1;this.noWeight=null!=(p=D.noWeight)?p:!1;this.losable=null!=(w=D.losable)?w:!0;this.autoRemove=null!=(r=D.autoRemove)?r:!1;this.fame=n.parseVal(D.fame);this.funds=n.parseVal(D.funds);this.resellFactor=null!=(e=D.resellFactor)?e:config.defaultResellFactor;this.useEvents=t.arrify(D.useEvents);this.usable=
0<this.useEvents.length;this.dropEvents=t.arrify(D.dropEvents);this.dayEvents=t.arrify(D.dayEvents);this.tripEvents=t.arrify(D.tripEvents);this.maxDice=D.maxDice;this.tempDice=function(){var a;var c=t.arrify(D.tempDice);var d=[];var e=0;for(a=c.length;e<a;e++)b=c[e],d.push(t.getDie(b));return d}();this.dice=function(){var a;var c=t.arrify(D.dice);var d=[];var e=0;for(a=c.length;e<a;e++)b=c[e],d.push(t.getDie(b));return d}();this.isWeapon=D.isWeapon;this.changeAmount=0;this.changeTime=1E3;this.owned=
!1;this.miniMap=null!=D.miniMap?{width:D.miniMap.width,height:D.miniMap.height,coverage:D.miniMap.coverage,initEvents:D.miniMap.initEvents}:null;this.chargeTime=null!=(f=D.chargeTime)?f:this.maxChargeTime;this.collectionItem=D.collectionItem;this.subItems=[];this.addStatus=D.addStatus;this.dowsing=D.dowsing;this.dowsingPower=0};Ha.prototype.clone=function(){var a=new Ha(this.main,this.id);a.miniMap=Object.clone(this.miniMap);a.chargeTime=this.chargeTime;a.subItems=Object.clone(this.subItems);a.owned=
this.owned;return a};Ha.prototype.getMaxStack=function(){var a;return this.main.party.parseBonus(null!=(a=this.maxStack)?a:10)};Ha.prototype.getFame=function(){return 0<this.subItems.length?this.subItems.sum(function(a){return a.fame}):this.fame};Ha.prototype.getFunds=function(){return 0<this.subItems.length?this.subItems.sum(function(a){return a.funds}):this.funds};Ha.prototype.getValue=function(a,b){a=void 0===a?"base":a;b=void 0===b?!1:b;var c;if(0<this.subItems.length)return this.subItems.sum(function(c){return c.getValue(a,
b)});var d=Object.isObject(this.value)?null!=(c=this.value[a])?c:this.value.base:this.value;d=n.parseVal(d);return 0<d?(b&&(d*=this.resellFactor),Math.max(0,Math.floor(d))):d};Ha.prototype.change=function(a){return 0<a?this.increase(a):this.consume(-a)};Ha.prototype.increase=function(a){return this.amount+=void 0===a?1:a};Ha.prototype.consume=function(a){var b=this.amount;this.amount=Math.max(this.amount-(void 0===a?1:a),0);this.changeAmount=this.amount-b;if(0!==this.changeAmount)return this.changeTime=
0};Ha.prototype.isEmpty=function(){return 0===this.amount};Ha.prototype.clearAge=function(){this.tripAge=this.dayAge=0;return this.chargeTime=this.maxChargeTime};Ha.prototype.tick=function(a){return this.changeTime+=a};var jb=Ha;var ja=function(a,b,c,d){this.updateUsability=this.updateUsability.bind(this);this.main=a;n.assert(null!=this.main);this.items=[];this.getInvCapacity=null!=c?c:function(){return-1};this.onAddedItem=d;if(null!=b)for(n.assert(Object.isArray(b)),d=0,c=b.length;d<c;d++)a=b[d],
this.changeItemCount(a.id,a.amount)};ja.prototype.clear=function(){return this.items=[]};ja.prototype.isOverburden=function(){var a;return this.items.length>(a=this.getInvCapacity())&&-1<a};ja.prototype.updateUsability=function(){var a,b,c;var d=this.items;var e=0;for(a=d.length;e<a;e++){var f=d[e];if(null!=f){f.usable=!1;var g=null!=(c=f.useEvents)?c:[];var h=0;for(b=g.length;h<b;h++){var k=g[h];var l=this.main.fillEventCtx({item:f});if(this.main.events.hasRequirements(k,l)){f.usable=!0;break}}}}};
ja.prototype.onChanged=function(){this.isOverburden()?this.compact():this.clearEmpty();if(null!=this.onItemsChanged)return this.onItemsChanged()};ja.prototype.compact=function(){this.clearEmpty();return this.items=this.items.compact()};ja.prototype.compactAndStackAll=function(){var a;var b=[];var c=this.items;var d=0;for(a=c.length;d<a;d++){var e=c[d];null!=e&&(b.includes(e.id)||b.push(e.id))}c=0;for(a=b.length;c<a;c++)e=b[c],this.compactAndStack(e);return this.compact()};ja.prototype.compactAndStack=
function(a){var b,c;var d=b=0;var e=this.items;var f=0;for(c=e.length;f<c;f++){var g=e[f];null!=g&&g.id===a&&(d=g.getMaxStack(),b+=g.amount,g.amount=0)}if(0!==b){this.compact();for(c=[];0<b;)g=Math.min(b,d),this.changeItemCount(a,g),c.push(b-=g);return c}};ja.prototype.clearOverburden=function(){this.compact();return this.items=this.items.slice(0,this.getInvCapacity())};ja.prototype.clearEmpty=function(){var a,b;this.items=this.items.map(function(a){return 0!==(null!=a?a.amount:void 0)?a:null});var c=
0;var d=this.items;var e=b=0;for(a=d.length;b<a;e=++b){var f=d[e];null!=f&&0!==f.amount&&(c=e)}return this.items=this.items.slice(0,+c+1||9E9)};ja.prototype.transfer=function(a){var b;var c=this.items.compact();var d=0;for(b=c.length;d<b;d++){var e=c[d];a.changeItemCount(e,e.amount)}return this.clear()};ja.prototype.getCount=function(){return this.items.compact().length};ja.prototype.clone=function(){return Object.clone(this.items)};ja.prototype.totalValue=function(a,b){b=void 0===b?!1:b;return this.items.compact().sum(function(c){return c.getValue(a,
b)*c.amount})};ja.prototype.getItemById=function(a){return this.items.compact().findAll(function(b){return b.id===a}).min(function(a){return a.amount})};ja.prototype.getItemsById=function(a){return this.items.compact().findAll(function(b){return b.id===a})};ja.prototype.getItemByIdx=function(a,b){b=void 0===b?[]:b;var c,d;if(0===b.length)return this.items[a];var e=0;var f=this.items;var g=0;for(c=f.length;g<c;g++){var h=f[g];var k=null!=h&&t.checkFlags(b,h.flags);if(!k&&null!=(null!=h?h.subItems:
void 0)){var l=h.subItems;var m=0;for(d=l.length;m<d;m++){var p=l[m];if(t.checkFlags(b,p.flags)){k=!0;break}}}if(null==h||k){if(e===a)return h;e+=1}}return null};ja.prototype.hasItemCounts=function(a){var b,c;var d=this.getItemCount();for(b in a){var e=a[b];var f=null!=(c=d[b])?c:0;if(!n.match(e,f))return!1}return!0};ja.prototype.getItemCount=function(){var a,b;var c={};var d=this.items.compact();var e=0;for(a=d.length;e<a;e++){var f=d[e];0<f.amount&&(null==c[b=f.id]&&(c[b]=0),c[f.id]+=f.amount)}return c};
ja.prototype.getTotalItems=function(){var a,b;var c={};var d=this.items.compact();var e=0;for(a=d.length;e<a;e++){var f=d[e];null==c[b=f.id]&&(c[b]=new jb(this.main,f.id));c[f.id].amount+=f.amount}return Object.values(c)};ja.prototype.getSingleItems=function(){return this.items.compact().map(function(a){var b;var c=[];var d=0;for(b=a.amount;0<=b?d<b:d>b;0<=b?++d:--d)c.push(a);return c}).flatten()};ja.prototype.setItem=function(a,b){this.items[b]=a;if(null!=this.onItemsChanged)return this.onItemsChanged()};
ja.prototype.changeItemCount=function(a,b){b=void 0===b?1:b;var c,d;var e=Object.isString(a)?new jb(this.main,a):a;if(-1<this.getInvCapacity()){if(e.metaItem)return;!e.owned&&e.id.startsWith("it-treasure")&&0<b&&this.main.achievements.incCounter("ach-treasure-collect",b);e.owned=!0}if(null!=this.onAddedItem&&0<b)this.onAddedItem(e.id);if(null!=e.collectionItem){if(b=this.getItemsById(e.collectionItem).first(),null==b&&(this.changeItemCount(e.collectionItem,1),b=this.getItemsById(e.collectionItem).first()),
b.subItems.push(new jb(this.main,a)),null!=this.onItemsChanged)this.onItemsChanged()}else{var f=this.getItemsById(e.id);var g=0;for(c=f.length;g<c;g++){var h=f[g];0<b?(a=Math.min(h.getMaxStack()-h.amount,b),h.increase(a),b-=a):0>b&&(a=Math.min(h.amount,-b),h.consume(a),b+=a)}if(0>=b){if(null!=this.onItemsChanged)this.onItemsChanged()}else{g=this.items;c=d=0;for(f=g.length;d<f;c=++d)if(h=g[c],null==h||0===h.amount)h=e.clone(),a=Math.min(h.getMaxStack(),b),h.amount=a,b-=a,this.items[c]=h;for(;0<b;)h=
e.clone(),a=Math.min(h.getMaxStack(),b),h.amount=a,b-=a,this.items.push(h);this.clearEmpty();if(null!=this.onItemsChanged)this.onItemsChanged();return b}}};ja.prototype.getTotalAmount=function(a){return this.items.compact().sum(function(b){return b.id===a?b.amount:0})};ja.prototype.getTotalValue=function(a){return this.items.compact().filter(function(a){return a.losable}).sum(function(a){return a.amount*a.getValue("base",!1)})};ja.prototype.incInvTurn=function(){var a,b;var c=this.items.compact();
var d=[];var e=0;for(a=c.length;e<a;e++){var f=c[e];if(0<f.maxChargeTime&&!(b=f.id,0<=F.call(d,b))){var g=c.filter(function(a){return a.id===f.id&&a.chargeTime<a.maxChargeTime}).max(function(a){return a.chargeTime});d.push(f.id);null!=g&&(g.chargeTime=Math.min(g.maxChargeTime,g.chargeTime+1))}}};ja.prototype.dropRandItems=function(a){var b,c;var d=a;var e={};for(a=!1;0<d;){var f=d;var g=this.items.compact().randomize();var h=0;for(b=g.length;h<b;h++){var k=g[h];if(0<k.amount&&k.losable){var l=k.getValue("base",
!1);if(l<=d||a){d-=l;k.consume(1);null==e[c=k.id]&&(e[c]=0);--e[k.id];break}}}if(f===d){if(a)break;a=!0}}this.isOverburden()&&this.compact();return e};ja.prototype.tick=function(a){var b;var c=this.items.compact();var d=0;for(b=c.length;d<b;d++){var e=c[d];e.tick(a)}};var Va=ja;var Ia=function(a,b,c){c=void 0===c?{}:c;var d,e;this.getOffset=this.getOffset.bind(this);this.getSlotCount=this.getSlotCount.bind(this);this.setSlotLimit=this.setSlotLimit.bind(this);this.getSize=this.getSize.bind(this);this.clearDraggedItem=
this.clearDraggedItem.bind(this);this.mouseToItem=this.mouseToItem.bind(this);this.inInventory=this.inInventory.bind(this);this.pickupItem=this.pickupItem.bind(this);this.onMouseDown=this.onMouseDown.bind(this);this.onMouseMove=this.onMouseMove.bind(this);this.tabItems=this.tabItems.bind(this);this.drawTrash=this.drawTrash.bind(this);this.main=a;this.r=this.main.r;this.sfx=this.main.sfx;this.dragCtx=b;this.itemOffset=0;a={inv:null,slots:0,offset:0,onCheckItem:null,onTrashItem:null,canUseItemFn:null,
owned:!1};Object.merge(a,c);this.inv=a.inv;this.slotCount=null!=(d=a.slots)?d:0;this.gridOffset=a.offset;this.onCheckItem=a.onCheckItem;this.onTrashItem=a.onTrashItem;this.canUseItemFn=a.canUseItemFn;this.owned=a.owned;this.fixedRows=null!=(e=a.fixedRows)?e:0;this.slotLimit=config.inventory.maxPartySlots;this.actionTrash=!1;this.invTime=0;this.reqItemFlags=[]};Ia.prototype.getOffset=function(){return Object.isFunction(this.gridOffset)?this.gridOffset(this):this.gridOffset};Ia.prototype.getSlotCount=
function(a){var b=Math.max(this.inv.items.length,this.inv.getInvCapacity());0<this.slotCount?(a=Math.max(1,Math.ceil(b/this.slotCount)),b=config.inventory.slotCount):b>this.slotLimit?(b=Math.min(this.getMaxSlots(),b),a=2,b=Math.ceil(b/2)):a=1;0<this.fixedRows&&(a=this.fixedRows);return new R(b,a)};Ia.prototype.setSlotLimit=function(a){return this.slotLimit=a};Ia.prototype.getSize=function(){var a=this.getSlotCount();var b=config.inventory.slotSize*this.r.s;return new R(b*a.w,b*a.h)};Ia.prototype.clearDraggedItem=
function(a,b){b=void 0===b?!0:b;var c;if(null!=this.dragCtx.item)if(a)this.onTrashItem(this.dragCtx.item);else if(this.dragCtx.item.increase(this.dragCtx.amount),b&&null!=(c=this.inv)&&c.clearEmpty(),null!=this.inv&&null!=this.inv.onItemsChanged)this.inv.onItemsChanged();this.dragCtx.inv=null;return this.dragCtx.item=null};Ia.prototype.mouseToItem=function(a,b){if(!this.inInventory(a,b))return[null,null];a=this.r.mouseToItemSlot(this.getOffset(),a,b,this.getSlotCount().w);a+=this.itemOffset*this.getMaxSlots();
return[a,this.inv.getItemByIdx(a,this.reqItemFlags)]};Ia.prototype.inInventory=function(a,b){var c=this.getOffset();if(null!=c){var d=this.getSize();return c.w<a&&a<c.w+d.w&&c.h<b&&b<c.h+d.h}};Ia.prototype.pickupItem=function(a,b,c){c=(void 0===c?0:c)?1:a.amount;this.dragCtx.inv=this.inv;this.dragCtx.item=a;this.dragCtx.invIdx=b;this.dragCtx.amount=c;return a.amount-=c};Ia.prototype.onMouseDown=function(a,b){var c=this,d;var e=function(a,b,d,e){d=void 0===d?!1:d;e=void 0===e?!0:e;var f;if(f=null==
a)a=new jb(c.main,c.dragCtx.item.id),a.chargeTime=c.dragCtx.item.chargeTime,a.miniMap=c.dragCtx.item.miniMap,a.subItems=c.dragCtx.item.subItems;d=Math.min(d?1:c.dragCtx.amount,a.getMaxStack()-a.amount);a.amount+=d;c.dragCtx.amount-=d;f&&c.inv.setItem(a,b);0===c.dragCtx.amount&&c.clearDraggedItem(!1,e);if(e&&(null==c.dragCtx.item||0===c.dragCtx.amount))return c.inv.compact()};this.mouseMoveItem=null;var f=$jscomp.makeIterator(this.mouseToItem(a.x,a.y));var g=f.next().value;f=f.next().value;if(null!=
this.dragCtx.item&&this.actionTrash&&b)return this.clearDraggedItem(!0),!0;if(null!=this.main.tutorial&&null!=f&&!this.main.tutorial.onUseItem(f))return!1;if(0===a.button&&!a.metaKey&&null==this.dragCtx.item&&0<(null!=f?f.amount:void 0))return this.mouseMoveItem={item:f,invIdx:g,mX:a.x,mY:a.x},!0;if(null==this.dragCtx.item){if(0<(null!=f?f.amount:void 0))return this.pickupItem(f,g,a.ctrlKey),!0}else{if(null==g||null!=this.main.tutorial&&"it-torch"===(null!=(d=this.dragCtx.item)?d.id:void 0))return!1;
if(null!=f&&0<f.amount)return f.id===this.dragCtx.item.id?e(f,g,a.ctrlKey):(e(null,g,!1,!1),this.pickupItem(f,g,!1)),!0;if(null!=g)return e(null,g,a.ctrlKey),!0}return!1};Ia.prototype.onMouseMove=function(a,b,c){if(null!=this.inv)return this.mousePos=new u(a,b),b=$jscomp.makeIterator(this.mouseToItem(a,b)),a=b.next().value,b.next(),this.main.showItemInfo=null,null!=a&&(a=this.inv.getItemByIdx(a,this.reqItemFlags),0<(null!=a?a.amount:void 0))?(this.main.showItemInfo={item:a,owned:this.owned,priceTable:c,
usable:"function"===typeof this.canUseItemFn?this.canUseItemFn(a):void 0},a):null};Ia.prototype.tick=function(a){return this.invTime+=a};Ia.prototype.tabItems=function(){this.itemOffset+=1;if(this.itemOffset*this.getMaxSlots()>=this.inv.items.length)return this.itemOffset=0};Ia.prototype.getMaxSlots=function(){return 0<this.fixedRows?config.inventory.slotCount*this.fixedRows:2*this.slotLimit};Ia.prototype.drawBackground=function(a,b,c,d){a=void 0===a?!0:a;d=$jscomp.makeIterator(this.r.getCanvasSize());
d.next();d.next();var e=$jscomp.makeIterator(this.getOffset().lst());d=e.next().value;var f=e.next().value;var g=config.inventory.slotSize*this.r.s;var h=this.inv.getInvCapacity();var k=this.getSlotCount();var l=!1;var m=this.itemOffset*this.getMaxSlots();var p=null!=this.canUseItemFn&&this.inv.items.length>h&&-1<h;e=this.r.ctx;e.globalAlpha=1;var n=2*this.r.s;if(0<this.itemOffset||this.inv.items.length>this.getMaxSlots()){var q=d-n+k.w*g+2*n;var t=f-n+4*this.r.s;var v=this.r.img.inventoryExtra;var r=
$jscomp.makeIterator([v.width,v.height]);var Y=r.next().value;r=r.next().value;e.drawImage(v,0,0,Y,r,q,t,this.r.s*Y,this.r.s*r);this.r.hitBox(q,t,this.r.s*Y,this.r.s*r,b,c)&&(l=!0)}this.r.drawPanel(config.panel.inventory,d-n,f-n,k.w*g+2*n,k.h*g+2*n);e.fillStyle=config.inventory.backgroundColor;e.fillRect(d,f,k.w*g,k.h*g);p&&(e.lineWidth=this.r.s,e.strokeStyle=config.colors.invSlotInvalid,e.strokeRect(d-this.r.s,f-this.r.s,2*this.r.s+k.w*g,2*this.r.s+k.h*g));q=t=0;for(b=k.h;0<=b?t<b:t>b;q=0<=b?++t:
--t)for(n=v=0,c=k.w;0<=c?v<c:v>c;n=0<=c?++v:--v)Y=Math.floor(d+n*g),r=Math.floor(f+q*g),n=this.inv.getItemByIdx(m,this.reqItemFlags),e.globalAlpha=1,e.lineWidth=config.inventory.margin*this.r.s,e.strokeStyle=config.inventory.gridColor,e.strokeRect(Y,r,g,g),null==this.canUseItemFn&&m>=h&&-1<h?(e.fillStyle="#111",e.globalAlpha=.8,e.fillRect(Y+1,r,g-1,g)):(e.strokeStyle="#222",e.globalAlpha=.2,e.beginPath(),e.moveTo(Y,r),e.lineTo(Y+g,r+g),e.moveTo(Y,r+g),e.lineTo(Y+g,r),e.stroke()),0<(null!=n?n.amount:
void 0)&&(p&&!n.noWeight&&(e.globalAlpha=.25,e.fillStyle=config.colors.invSlotInvalid,e.fillRect(Y+2,r+12*this.r.s,g-4,5)),"function"===typeof this.canUseItemFn&&this.canUseItemFn(n)&&(e.globalAlpha=.8,e.strokeStyle=config.colors.invSlotUsable,e.strokeRect(Y+this.r.s,r+this.r.s,g-3*this.r.s,g-3*this.r.s)),e.globalAlpha=a?1:.6,this.r.drawItem(n,Y+2*this.r.s,r+2*this.r.s,{showDowsing:!0,showChange:null!=this.canUseItemFn})),m+=1;return l};Ia.prototype.drawTrash=function(a,b){var c=$jscomp.makeIterator(this.r.getCanvasSize());
c.next();c=c.next().value;var d=this.getOffset();var e=this.getSize();d=d.w+4*this.r.s+e.w;c-=28*this.r.s;this.r.ctx.globalAlpha=1;return this.r.drawSprite("hud_inventory_discard.png",d,c,{mX:a,mY:b})};Ia.prototype.drawDragged=function(a){this.actionTrash=!1;if(null!=this.dragCtx.item){var b=this.mousePos.x;var c=this.mousePos.y;a&&this.drawTrash(b,c)&&(this.actionTrash=!0,this.main.infoBox.setInfo([{text:config.help.trash}],b,c));this.r.ctx.globalAlpha=1;var d=$jscomp.makeIterator(config.imgSize.item);
a=d.next().value;d=d.next().value;return this.r.drawItem(this.dragCtx.item,b-a/2,c-d,{amount:this.dragCtx.amount,showDecorator:!1})}};var kb=Ia;var N=function(a,b,c,d){var e=this;this.setPersonStatus=this.setPersonStatus.bind(this);this.mount=this.mount.bind(this);this.dismount=this.dismount.bind(this);this.getCapacity=this.getCapacity.bind(this);this.onStatusChanged=this.onStatusChanged.bind(this);this.updateCapacity=this.updateCapacity.bind(this);this.updateItemStatuses=this.updateItemStatuses.bind(this);
this.updatePersonButtons=this.updatePersonButtons.bind(this);this.onBonusChanged=this.onBonusChanged.bind(this);this.changeMaxSanity=this.changeMaxSanity.bind(this);this.updateTripCost=this.updateTripCost.bind(this);this.updateDice=this.updateDice.bind(this);this.updateOverburden=this.updateOverburden.bind(this);this.clearDowsing=this.clearDowsing.bind(this);this.updateDowsing=this.updateDowsing.bind(this);this.updateUnitCount=this.updateUnitCount.bind(this);this.updateMaxSanity=this.updateMaxSanity.bind(this);
this.getZoneAggroChance=this.getZoneAggroChance.bind(this);this.getMoveCost=this.getMoveCost.bind(this);this.getBonusArr=this.getBonusArr.bind(this);this.evaluateBonus=this.evaluateBonus.bind(this);this.getBonus=this.getBonus.bind(this);this.getBonusMapHintXP=this.getBonusMapHintXP.bind(this);this.getBonusMapHintSanity=this.getBonusMapHintSanity.bind(this);this.getBonusMapHintPunchRadius=this.getBonusMapHintPunchRadius.bind(this);this.getBonusMapHintCompassScore=this.getBonusMapHintCompassScore.bind(this);
this.getBonusMapStampTileScore=this.getBonusMapStampTileScore.bind(this);this.getBonusMapLineScore=this.getBonusMapLineScore.bind(this);this.getBonusMapLineMaxAngle=this.getBonusMapLineMaxAngle.bind(this);this.getBonusTravelScoreMod=this.getBonusTravelScoreMod.bind(this);this.getBonusMoveCost=this.getBonusMoveCost.bind(this);this.getBonusTileEventChance=this.getBonusTileEventChance.bind(this);this.main=a;this.events=b;this.r=c;this.chat=d;this.mapScoreInterp=this.lifetimeMapScore=this.mapScore=this.xp=
0;this.fame=config.baseFame;this.karma=0;this.maxSanity=this.baseMaxSanity=config.sanity.maxSanity;this.persons=[];this.flags={};this.store=[];this.noCombat=!0;this.visitedPockets=[];this.unlockedPockets=[];this.notifiedClaims=[];this.autoUseMapStamps=this.autoUseMapLines=!1;this.mapScoreTime=0;this.inv=new Va(this.main,[],this.getCapacity,this.main.mainMenu.itemFound);this.inv.onItemsChanged=function(){e.updateItemStatuses();e.inv.updateUsability();return e.isInventoryChangedSinceSave=!0};this.itemStatuses=
[];this.reset();this.resetStats()};N.prototype.unlockPocket=function(a){return this.unlockedPockets.push(a)};N.prototype.isOverburden=function(){return this.inv.items.length>this.getCapacity()};N.prototype.isOverfilled=function(){return this.unitCount>this.maxUnitCount};N.prototype.checkTrackedEvent=function(a,b){var c;null==(c=this.trackedEvents)[a]&&(c[a]=0);return this.trackedEvents[a]<b};N.prototype.incTrackedEvent=function(a){var b;null==(b=this.trackedEvents)[a]&&(b[a]=0);return this.trackedEvents[a]+=
1};N.prototype.reset=function(){var a=this,b,c;this.pos=null;this.trackedEvents={};this.sanity=this.maxSanity;this.butterflies=this.standing=0;this.isSuperMove=!1;this.unlockedPockets=[];this.playTime=this.visitedLocations=0;n.isIO()&&(this.turnsForStandingBias=config.io.turnsForStandingBias);this.legs=[];this.moves=[];this.resetStats();var d=this.persons;var e=0;for(c=d.length;e<c;e++){var f=d[e];f.health=f.maxHealth;f.updateHealth();var g=f.statuses;for(b in g){var h=g[b];h.autoRemove&&(f.setStatus(b,
!1),h=this.itemStatuses.findIndex(function(a){return a===b}),-1!==h&&this.itemStatuses.removeAt(h))}this.inv.items.remove(function(b){return null==b||b.autoRemove&&0<a.main.worldLvl})}this.inv.compact();d=this.inv.items;g=0;for(f=d.length;g<f;g++)c=d[g],c.chargeTime=c.maxChargeTime;this.updateItemStatuses();return this.clearDowsing()};N.prototype.incStatLocationVisit=function(a){var b;n.assert(null!=a);null==(b=this.stats.locationVisit)[a]&&(b[a]=0);return this.stats.locationVisit[a]+=1};N.prototype.incStatItemUsage=
function(a){var b;n.assert(null!=a);null==(b=this.stats.itemUsage)[a]&&(b[a]=0);return this.stats.itemUsage[a]+=1};N.prototype.incStatItemLoot=function(a,b){b=void 0===b?1:b;var c;n.assert(null!=a);null==(c=this.stats.itemLoot)[a]&&(c[a]=0);return this.stats.itemLoot[a]+=b};N.prototype.incStatItemBarter=function(a,b){b=void 0===b?1:b;var c;n.assert(null!=a);null==(c=this.stats.itemBarter)[a]&&(c[a]=0);return this.stats.itemBarter[a]+=b};N.prototype.incStatItemEvent=function(a,b){b=void 0===b?1:b;
var c,d;n.assert(null!=a);null==(c=this.stats).itemEvent&&(c.itemEvent={});null==(d=this.stats.itemEvent)[a]&&(d[a]=0);return this.stats.itemEvent[a]+=b};N.prototype.incStatEventEncounter=function(a){var b,c;if(null!=a.id)return null==(b=this.stats.eventEncounters)[c=a.id]&&(b[c]=0),this.stats.eventEncounters[a.id]+=1};N.prototype.incStatRankingSell=function(a){var b;n.assert(null!=a);null==(b=this.stats.rankingSell)[a]&&(b[a]=0);return this.stats.rankingSell[a]+=1};N.prototype.incStatRankingGift=
function(a,b){b=void 0===b?1:b;var c;n.assert(null!=a);null==(c=this.stats.rankingGift)[a]&&(c[a]=0);return this.stats.rankingGift[a]+=b};N.prototype.incStatRankingKeep=function(a){var b;n.assert(null!=a);null==(b=this.stats.rankingKeep)[a]&&(b[a]=0);return this.stats.rankingKeep[a]+=1};N.prototype.incStatCombatZone=function(a){var b,c;n.assert(null!=a);null==(b=this.stats).combatZones&&(b.combatZones={});null==(c=this.stats.combatZones)[a]&&(c[a]=0);return this.stats.combatZones[a]+=1};N.prototype.incStatCombatEnemy=
function(a){var b,c;n.assert(null!=a);null==(b=this.stats).combatEnemies&&(b.combatEnemies={});null==(c=this.stats.combatEnemies)[a]&&(c[a]=0);return this.stats.combatEnemies[a]+=1};N.prototype.resetStats=function(){return this.stats={itemUsage:{},locationVisit:{},eventEncounters:{},attackUsage:{},turns:0,fame:0,worldLvl:0,mapScore:0,rankingSell:{},rankingGift:{},rankingKeep:{},itemLoot:{},itemBarter:{},itemEvent:{},combatZones:{},combatEnemies:{},marks:[]}};N.prototype.addStatsLeg=function(a){return this.legs.push([this.pos,
a])};N.prototype.hasPartyStatus=function(a){return this.persons.any(function(b){return b.hasStatus(a)})};N.prototype.setFlags=function(a){return t.setFlags(a,this.flags)};N.prototype.hasPersonStatuses=function(a,b,c){return t.parseFlags(b,void 0===c?"st-":c).any(function(b){return Object.all(b,function(b,c){return null!=a.statuses[b]===c})})};N.prototype.setPersonStatuses=function(a,b,c,d){c=void 0===c?!1:c;var e;var f=[];d=t.parseFlags(b,void 0===d?"st-":d).sample();for(e in d)b=d[e],this.setPersonStatus(a,
e,b,c)&&f.push({character:a,status:e,enabled:b});return f};N.prototype.setPersonStatus=function(a,b,c,d){return a.setStatus(b,c,void 0===d?!1:d)};N.prototype.canMount=function(){return null==this.getExplorer().riding};N.prototype.mount=function(a,b){if(null==b.riding){a.mounted=b;b.riding=a;var c=a.mountedStatuses;var d=0;for(b=c.length;d<b;d++){var e=c[d];this.setPersonStatus(a,e,!0)}return this.onBonusChanged()}};N.prototype.dismount=function(a){var b;var c=a.mountedStatuses;var d=0;for(b=c.length;d<
b;d++){var e=c[d];this.setPersonStatus(a,e,!1)}a.mounted.riding=null;a.mounted=null;return this.onBonusChanged()};N.prototype.hasTranslator=function(){return this.persons.any(function(a){return a.flags.translator})};N.prototype.getStatusCounts=function(a){a=void 0===a?this.persons:a;var b,c;var d={};var e=0;for(c=a.length;e<c;e++){var f=a[e];f=f.statuses;for(b in f){var g=f[b];0>=g.buffDelayTrips&&0>=g.buffDelayDays&&(null==d[b]&&(d[b]=0),d[b]+=1)}}return d};N.prototype.setExplorer=function(a,b){var c;
this.addCharacter(a);var d=0;for(c=b.length;d<c;d++){var e=b[d];this.addCharacter(e)}return this.explorerId=a};N.prototype.levelUp=function(a,b){b=void 0===b?!0:b;var c=a.isSpecial?config.xp.playerLevels[a.level]:config.xp.levels[a.level];return this.canLevelUp(a)&&this.xp>=c?(a.setLevel(a.level+1),a.hasHealth()&&a.updateHealth(),a.hasLoyalty()&&Math.random()<this.loyaltyBoost&&a.changeLoyalty(1),this.xp-=c,b&&this.r.addStatHighlightParticle(1,q.toText("txt-base-level")),this.main.doChat("cl-levelUp",
{person:a}),this.onBonusChanged(),null!=config.specialEvents.promotion&&this.main.hasMainState("game")&&this.main.doRandEvent(config.specialEvents.promotion,{person:a}),!0):!1};N.prototype.canLevelUpAny=function(){var a=this;return this.persons.any(function(b){return a.canLevelUp(b)})};N.prototype.canLevelUp=function(a,b){b=void 0===b?!1:b;var c;if(!this.main.exped.canHaveEvent()||this.main.exped.isTraveling()||!a.canLevelUp())return!1;var d=null!=(c=this.getExplorer())?c.hasStatus(config.specialStatuses.animalWhisperer):
void 0;if(!a.isSpecial&&!t.checkFlags({animal:d},a.flags))return!1;if(b)return!0;b=a.isSpecial?config.xp.playerLevels:config.xp.levels;return null!=b[a.level]&&this.xp>=b[a.level]};N.prototype.move=function(a){this.pos=this.pos.move(a);this.main.isWarping()||this.moves.push(this.pos);return this.main.updateForNewPartyPos()};N.prototype.incPartyTurn=function(){var a;this.inv.incInvTurn();var b=this.persons;var c=0;for(a=b.length;c<a;c++){var d=b[c];d.incHealthRegen();d.updateHealth()}n.isIO()&&(--this.turnsForStandingBias,
0>=this.turnsForStandingBias&&(this.turnsForStandingBias=config.io.turnsForStandingBias+this.getBonus("turnsForStandingBias"),d=this.getBonus("standingBias"),this.standing<d&&(d=this.changeStanding(1),this.main.notifications.addNotify({standing:d}))))};N.prototype.tick=function(a){this.mapScoreTime+=a;if(1.7<this.mapScoreTime){var b=this.mapScoreInterp<=this.mapScore?this.mapScore:config.xp.maxMapScore;this.mapScoreInterp+=a;this.mapScoreInterp=Math.min(b,this.mapScoreInterp);4<this.mapScoreTime&&
this.mapScore<this.mapScoreInterp&&(this.mapScoreInterp=this.mapScore)}var c=this.persons;var d=0;for(b=c.length;d<b;d++){var e=c[d];e.tick(a)}return this.inv.tick(a)};N.prototype.getCapacity=function(){return this.persons.sum(function(a){return a.capacity})+this.inv.items.count(function(a){return null!=a&&0<a.amount&&a.noWeight})};N.prototype.changeKarma=function(a){this.karma=Math.max(this.karma+this.parseBonus(a),0)};N.prototype.changeFame=function(a,b){b=void 0===b?!0:b;0!==a&&(this.fame=Math.max(this.fame+
a,0),n.isIO()&&null==this.main.tutorial&&(b&&this.main.notifications.addNotify({fame:a}),a=this.fame-this.main.iomp.lastPostedHighscore,100<a&&this.main.iomp.queueSave()))};N.prototype.onStatusChanged=function(){this.onBonusChanged()};N.prototype.updateCapacity=function(){var a;var b=this.getBonus("animalCapacity");var c=this.persons;var d=0;for(a=c.length;d<a;d++){var e=c[d];e.capacity=e.baseCapacity+this.getBonus("capacity",{person:e});t.checkFlags("+packAnimal",e.flags)&&null==e.mounted&&(e.capacity+=
b)}};N.prototype.updateItemStatuses=function(){var a,b;var c=[];var d=this.inv.items;var e=0;for(a=d.length;e<a;e++){var f=d[e];if(null!=f&&0<f.amount&&null!=f.addStatus){var g=t.arrify(f.addStatus);var h=0;for(b=g.length;h<b;h++)f=g[h],c.includes(f)||c.push(f)}}a=this.getExplorer();for(d=e=this.itemStatuses.length-1;0<=e;d=e+=-1)f=this.itemStatuses[d],c.includes(f)||(r.info("ITEM-STATUS;Removing "+f+" from "+a.id),this.itemStatuses.removeAt(d),this.setPersonStatuses(a,"-"+f));d=0;for(e=c.length;d<
e;d++)f=c[d],this.hasPersonStatuses(a,"+"+f)||(r.info("ITEM-STATUS;Adding "+f+" to "+a.id),this.itemStatuses.includes(f)||this.itemStatuses.push(f),this.setPersonStatuses(a,"+"+f))};N.prototype.updatePersonButtons=function(){var a,b,c;var d=null!=(a=this.persons)?a:[];var e=0;for(b=d.length;e<b;e++){var f=d[e];a=this.main.fillEventCtx({person:f});f.buttons=[];var g=Object.values(config.buttons);var h=0;for(c=g.length;h<c;h++){var k=g[h];this.main.events.hasRequirements(k,a)&&(k=new Sc(k.id),null!=
k.id&&f.buttons.push(k))}}};N.prototype.onBonusChanged=function(){var a,b;this.updatePersonButtons();this.updateMaxSanity();this.updateDice();this.updateTripCost();this.updateDowsing();this.updateViewDist();this.updateCapacity();null!=(a=this.inv)&&a.updateUsability();this.loyaltyBoost=config.loyalty.levelUpChance+this.getBonus("loyaltyBoost");var c=this.persons;var d=0;for(b=c.length;d<b;d++)a=c[d],a.updateUnitCount(),a.updateHealth(),a.updateLoyalty();this.updateOverburden();this.updateUnitCount();
this.mapScoreBonus=this.getBonus("mapScore");a=this.main.exped;null!=a&&(0<this.sanity&&a.resetSanityTurns(),a.updateVisibility())};N.prototype.addCharacter=function(a,b){b=void 0===b?null:b;if(Object.isString(a)){b=new Fa(this.main,a,b);var c=!0}else b=a,c=!1;if(null==b.id)return null;b.isMember=!0;this.persons.add(b);this.persons=this.persons.sortBy(function(a){return a.flags.animal?-1:a.flags.special?1:0},!0);this.onBonusChanged();b.onStatusChanged=this.onStatusChanged;"native"===b.sprite&&b.updateSprite(this.main.getTribeGenAtPartyPos());
if(c){if(null!=b.items&&null==this.main.tutorial){var d=b.items;for(a in d)c=d[a],this.inv.changeItemCount(a,c)}null!=b.spawnEvents&&this.main.doRandEvent(b.spawnEvents,{person:b,silent:!0})}return b};N.prototype.getExplorer=function(){return this.persons.find(function(a){return a.isSpecial})};N.prototype.removeCharacter=function(a){var b;n.isIO()&&!this.main.isWarping()&&null!=this.main.exped&&this.main.exped.sendLegCache();a=t.arrify(a);var c=0;for(b=a.length;c<b;c++){var d=a[c];null!=d.mounted&&
this.dismount(d);d.isMember=!1}this.persons=this.persons.subtract(a);this.onBonusChanged();this.persons.length<=config.uiMaxUnitCount&&(this.main.r.partyOffset=0);if(this.isOverburden())return this.inv.compact()};N.prototype.storePerson=function(a){a.storeAge=0;return this.store.push(a)};N.prototype.hasBiomeInfo=function(){return this.hasPartyStatus(config.specialStatuses.biomeInfo)||this.inv.hasItemCounts({"it-wadjetEye":1})};N.prototype.isCartographer=function(){return this.hasPartyStatus(config.specialStatuses.cartographer)};
N.prototype.isPacifist=function(){var a;return null!=(a=this.getExplorer())?a.hasStatus(config.specialStatuses.pacifist):void 0};N.prototype.isOtherworldly=function(){var a;return null!=(a=this.getExplorer())?a.hasStatus(config.specialStatuses.otherworldly):void 0};N.prototype.changeMaxSanity=function(a){this.baseMaxSanity+=a;return this.updateMaxSanity()};N.prototype.updateTripCost=function(){var a;return this.tripCost=this.isSuperMove?0:(a=Math.floor(config.sanity.tripCost[this.main.difficultyLvl]*
(1+this.getBonus("tripCost"))),Math.max(a,0))};N.prototype.updateDice=function(){var a;var b=null!=(a=this.persons)?a:[];var c=[];var d=0;for(a=b.length;d<a;d++){var e=b[d];c.push(e.updateDice(this.isOverburden()))}return c};N.prototype.getDice=function(a){var b,c;var d=[];var e=0;for(b=a.length;e<b;e++){var f=a[e];var g=f.dice;var h=0;for(c=g.length;h<c;h++)f=g[h],d.push(f)}return d};N.prototype.updateOverburden=function(){var a;var b=this.getExplorer();this.inv.onChanged();if(null!=b){var c=this.isOverburden();
this.setPersonStatus(b,config.specialStatuses.overburden,c);if(c!==this.overburden)return this.overburden=c,null!=(a=this.main.exped)?a.resetPath():void 0}};N.prototype.updateViewDist=function(){this.viewDistBonus=this.getBonus("viewDist");return this.revealDist=config.simpleLocationRevealDist+this.getBonus("revealDist")};N.prototype.clearDowsing=function(){var a;var b=this.inv.items;var c=[];var d=0;for(a=b.length;d<a;d++){var e=b[d];null!=e?c.push(e.dowsingPower=0):c.push(void 0)}return c};N.prototype.updateDowsing=
function(){var a;if(null!=this.main.world&&null!=this.pos){var b=this.inv.items.compact();var c=[];var d=0;for(a=b.length;d<a;d++){var e=b[d];if(null!=e.dowsing){var f=this.main.world.getDowsingLocation(this.pos,e.dowsing);e.dowsingPower=0;null!=f?(f=f.pos.dist(this.pos),12<=f?c.push(e.dowsingPower=0):10<=f?c.push(e.dowsingPower=1):8<=f?c.push(e.dowsingPower=2):6<=f?c.push(e.dowsingPower=3):4<=f?c.push(e.dowsingPower=4):2<=f?c.push(e.dowsingPower=6):c.push(e.dowsingPower=8)):c.push(void 0)}}return c}};
N.prototype.updateUnitCount=function(){this.unitCount=this.persons.sum(function(a){return a.unitCount});return this.maxUnitCount=Math.max(1,config.maxUnitCount+this.getBonus("maxUnitCount"))};N.prototype.getFreeUnitCount=function(){return this.maxUnitCount-this.unitCount};N.prototype.getFreeItemSlots=function(){return Math.max(0,this.getCapacity()-this.inv.items.count(function(a){return null!=a&&0<a.amount}))};N.prototype.updateMaxSanity=function(){var a=this.maxSanity;this.maxSanity=this.baseMaxSanity+
this.getBonus("maxSanity");if(this.sanity>this.maxSanity)return this.changeSanity(this.sanity-this.maxSanity);if(this.maxSanity>a)return this.changeSanity(this.maxSanity-a)};N.prototype.changeSanity=function(a,b){var c;b=this.sanity;this.sanity=(this.sanity+a).clamp(0,this.maxSanity);a=this.sanity-b;0<this.sanity&&null!=(c=this.main.exped)&&c.resetSanityTurns();if(0!==a)this.onBonusChanged();return a};N.prototype.changeXP=function(a){return this.xp=(this.xp+this.parseBonus(a)).clamp(0,50)};N.prototype.changeMapScore=
function(a,b){b=void 0===b?!0:b;var c;this.mapScore=(this.mapScore+a).clamp(0,50);1>=this.mapScore-this.mapScoreInterp&&(this.mapScoreTime=0);for(;this.mapScore>=config.xp.maxMapScore;)this.mapScore-=config.xp.maxMapScore,this.changeXP(1);if(b&&null!=config.lifetimeMapScoreEvents)for(c=0;0<=a?c<a:c>a;0<=a?++c:--c){this.lifetimeMapScore+=1;b=parseInt(Object.keys(config.lifetimeMapScoreEvents).max(function(a){return parseInt(a)}));var d=this.lifetimeMapScore%b;0!==this.lifetimeMapScore&&0===d&&(d+=
b);config.lifetimeMapScoreEvents[d]&&this.main.doEvent(t.getEvent(config.lifetimeMapScoreEvents[d]),{silent:!0})}};N.prototype.changeStanding=function(a,b){b=this.standing;this.standing=(this.standing+a).clamp(-10,10);a=this.standing-b;0>this.standing&&this.setFlags("+hadBadStanding");n.isIO()&&(this.turnsForStandingBias=config.io.turnsForStandingBias+this.getBonus("turnsForStandingBias"));return a};N.prototype.getZoneAggroChance=function(a){return null==a||0>a.aggroChance?-1:J.clamp(a.aggroChance+
this.getBonus("zoneEventChance"),0,1)};N.prototype.getMoveCost=function(a,b,c){c=void 0===c?{}:c;var d,e,f,g;if(this.isSuperMove)return[0,null];if(null!=this.main.exped.sledgeTarget)return[(null!=(d=b.moveCost.sledge)?d:b.moveCost.default)/4,null];var h=b.moveCost.default;var k=null;var l=b.moveCost;for(e in l)if(d=l[e],"default"!==e&&0<this.inv.getTotalAmount(e)-(null!=(f=c[e])?f:0)){k=e;h=d;break}if(null!=b.passCost&&a.id!==b.id){a=b.passCost.default;n.assert(null==k,"Can't use two items on same tile");
f=b.passCost;for(e in f)if(d=f[e],"default"!==e&&0<this.inv.getTotalAmount(e)-(null!=(g=c[e])?g:0)){k=e;a=d;break}h+=a}h=Math.max(1,h+this.getBonusMoveCost(b.pos));return[h,k]};N.prototype.getBonusArr=function(a,b){if(null!=a)return Object.isArray(a)?0===a.length?null:a:null==a[b]?null:t.arrify(a)};N.prototype.evaluateBonus=function(a,b,c,d,e){var f,g,h;var k=this.getBonusArr(c,d);if(null==k)return 0;var l=f=0;for(g=k.length;l<g;l++)c=k[l],e.person=b,null!=c&&null!=c[d]&&this.events.hasRequirements(c,
e)&&(a=Math.min(null!=(h=c.maxAmount)?h:100,a),f+=c[d]*a);return f};N.prototype.getBonus=function(a,b){b=void 0===b?{}:b;var c;var d={world:this.main.world,party:this,pos:this.pos};Object.merge(d,b);var e=null!=d.person?[d.person]:this.persons;var f=b=0;for(c=e.length;f<c;f++){var g=e[f];b+=this.evaluateBonus(1,g,g.bonus,a,d);b+=this.evaluateBonus(1,g,g.levelBonus,a,d)}c=this.getStatusCounts(e);var h=[];e=Object.keys(c);f=0;for(g=e.length;f<g;f++){var k=e[f];var l=t.getStatus(k,!1);l.noBonusStacking&&
!h.includes(k)&&(h.push(k),delete c[k])}var m=function(a){var b=h.indexOf(a);0<=b&&h.splice(b,1);l=t.getStatus(a,!1);if(null!=l&&null!=l.improves)return m(l.improves)};g=0;for(e=h.length;g<e;g++)k=h[g],l=t.getStatus(k,!1),null!=l&&null!=l.improves&&m(l.improves);g=0;for(e=h.length;g<e;g++)k=h[g],c[k]=1;for(k in c)g=c[k],l=t.getStatus(k,!1),null!=l&&(b+=this.evaluateBonus(g,null,l.bonus,a,d));c=[];f=this.inv.getItemCount();for(k in f)if(g=f[k],e=t.getItem(k,!1),null!=e){if(e.noBonusStacking){if(c.includes(k))continue;
g=Math.min(g,1)}b+=this.evaluateBonus(g,null,e.bonus,a,d);c.push(k)}return b};N.prototype.getBonusMapHintXP=function(){return this.getBonus("mapHintXP")};N.prototype.getBonusMapHintSanity=function(){return this.getBonus("mapHintSanity")};N.prototype.getBonusMapHintPunchRadius=function(){return this.getBonus("mapHintPunchRadius")};N.prototype.getBonusMapHintCompassScore=function(){return this.getBonus("mapHintCompassScore")};N.prototype.getBonusMapStampTileScore=function(){return this.getBonus("mapStampTileScore")};
N.prototype.getBonusMapLineScore=function(){return this.getBonus("mapLineScore")};N.prototype.getBonusMapLineMaxAngle=function(){return this.getBonus("mapLineMaxAngle")};N.prototype.getBonusTravelScoreMod=function(){return this.getBonus("travelScoreMod")};N.prototype.getBonusMoveCost=function(a){return this.getBonus("moveCost",{pos:a})};N.prototype.getBonusTileEventChance=function(a){return this.getBonus("eventChance",{pos:a})};N.prototype.parseRangeBonus=function(a){var b;if(Object.isObject(a)){var c=
n.parseRange(null!=(b=a.base)?b:"");a={base:c[1],bonus:a.bonus};c[1]=this.parseBonus(a);return c}return n.parseRange(a)};N.prototype.parseBonus=function(a){var b,c,d;return null==a?null:Object.isNumber(a)?a:Object.isString(a)?"-"===a[0]?null!=(b=-config.standardValues[a.slice(1)])?b:0:null!=(c=config.standardValues[a])?c:0:(null!=(d=this.parseBonus(a.base))?d:0)+this.getBonus(a.bonus)};var Gc=0;var Sc=function(a){var b=t.getButton(a);null!=b&&(this.id=a,this.title=q.parse(b.title),this.events=t.arrify(b.useEvents))};
var tb=function(){this.pos=new u(0,0)};tb.prototype.setPos=function(a){return this.pos=a.clone()};tb.prototype.interpTo=function(a,b,c){b=void 0===b?1:b;c=void 0===c?0:c;null==this.pos&&(this.pos=a.clone());this.interpStartPos=this.pos.clone();this.interpTargetPos=a;this.interpBlendTime=-c;return this.interpTotalBlendTime=b};tb.prototype.tick=function(a){return this.tickInterp(a)};tb.prototype.tickInterp=function(a){if(!(0>this.interpTotalBlendTime||null==this.interpTargetPos)){this.interpBlendTime+=
a;a=J.clamp(this.interpBlendTime/this.interpTotalBlendTime,0,1);a=TWEEN.Easing.Quartic.Out(a);var b=this.interpTargetPos.x-this.interpStartPos.x;this.pos=new u(this.interpStartPos.x+b*a,this.interpStartPos.y+(this.interpTargetPos.y-this.interpStartPos.y)*a);if(1<=a)return this.interpTotalBlendTime=-1}};var $a=function(a,b){b=void 0===b?"npc":b;this.initCharGen=this.initCharGen.bind(this);this.main=a;n.assert(null!=this.main);this.nudgeOffset=new qa(0,0);this.nudgeVel=new qa(0,0);this.damageTime=1E3;
this.imgSlot=b;this.rightFacingSprite=!1};$a.prototype.initCharGen=function(a,b){b=void 0===b?0:b;0===b&&(b=J.rng.next());if(this.sourceTribeGenId!==a||this.sourceTribeGenSeed!==b||"native"!==this.sprite){this.colorTable=this.genLayers=null;this.sprite="native";var c=new Ta(this.main.r,this.main.r.sfx,this.main);c.setup(a,b);this.updateSprite(c);this.variations[0].portrait=null}};$a.prototype.updateSprite=function(a){if("native"===this.sprite)return this.sourceTribeGenId=a.id,this.sourceTribeGenSeed=
a.rng._seed,null==this.genLayers&&(this.genLayers=a.genSpriteLayers(this.gender)),null==this.colorTable&&(this.colorTable=a.colorTable),a=a.genSprite(this.genLayers,this.colorTable),this.sprite=a.body,null!=a.mounted&&(this.mountedSprite=a.mounted),this.portraitSmall=a.portraitSmall,this.portrait=a.portrait,null!=a.mini&&(this.miniSprite=a.mini),this.rightFacingSprite=!0};$a.prototype.nudge=function(a){return this.nudgeVel=a};$a.prototype.tick=function(a){this.damageTime+=a;if(!this.nudgeOffset.isZero()||
!this.nudgeVel.isZero()){var b=this.nudgeOffset.clone();b.x+=10*a*this.nudgeVel.x;b.y+=10*a*this.nudgeVel.y;this.nudgeVel.x-=10*a*b.x;this.nudgeVel.y-=10*a*b.y;return 0>b.x*this.nudgeOffset.x||0>b.y*this.nudgeOffset.y?(this.nudgeOffset=new qa(0,0),this.nudgeVel=new qa(0,0)):this.nudgeOffset=b}};$a.prototype.getImgSlot=function(){return this.imgSlot};var fa=function(a,b,c){c=void 0===c?null:c;var d,e,f,g,h,k,l,m,p,n,r;a=$a.call(this,a)||this;a.setVariationWithGender=a.setVariationWithGender.bind(a);
a.setVariation=a.setVariation.bind(a);a.hasHealth=a.hasHealth.bind(a);a.changeHealth=a.changeHealth.bind(a);a.hasLoyalty=a.hasLoyalty.bind(a);a.changeLoyalty=a.changeLoyalty.bind(a);a.updateDice=a.updateDice.bind(a);a.updateUnitCount=a.updateUnitCount.bind(a);a.updateHealth=a.updateHealth.bind(a);a.incHealthRegen=a.incHealthRegen.bind(a);var D=t.getCharacter(b,!1);if(null==D)return a;a.cid="ch-"+Gc;a.mod=D.mod;a.debugCategory=D.debugCategory;Gc+=1;a.bonus=D.bonus;a.capacity=D.capacity;a.items=D.items;
a.id=b;a.size=null!=(d=D.size)?d:1;a.baseHealth=a.maxHealth=a.health=null!=(g=D.health)?g:1;a.healthBonus=null!=(h=D.healthBonus)?h:config.xp.healthBonus;a.regenTurn=0;a.queuedHealthParticles=0;a.flags=t.setFlags(D.flags);a.isSpecial=a.flags.special;a.isEnemy=!1;a.isMember=!1;a.isMountable=null!=(k=D.isMountable)?k:!1;a.canDismiss=null!=(l=D.canDismiss)?l:!0;a.mountedDice=t.arrify(D.mountedDice);a.mountedStatuses=t.arrify(D.mountedStatuses);a.spawnEvents=t.arrify(D.spawnEvents);a.miniSprite=D.miniSprite;
a.baseCapacity=null!=(m=D.capacity)?m:0;a.variations=t.arrify(D.variations);null==a.bonus&&(a.bonus={});null!=D.variations?a.setVariationWithGender(c):(a.sprite=D.sprite,a.portrait=null!=(p=D.portrait)?p:a.sprite,a.title=q.parse(null!=(n=D.title)?n:"",c),a.description=q.parse(null!=(r=D.description)?r:"",c));a.dice=[];if(null!=D.dice){d=t.arrify(D.dice);g=[];h=0;for(c=d.length;h<c;h++)b=d[h],g.push(t.getDie(b));a.dice=g}a.mirrored=!1;a.mirrorTime=J.randInt(2,8);a.baseLoyalty=a.loyalty=null!=(e=D.loyalty)?
e:config.loyalty.defaultValue;null==a.name&&(a.name=D.name);a.name=q.toText(a.name);a.shortName=null!=(f=q.toText(D.shortName))?f:a.name;a.imgSlot=D.imgSlot;a.extraSprites=D.extraSprites;a.rightFacingSprite=!D.isLeftFacingSprite;a.screenPos=new u(config.imgSize.partyOffset);a.moveTotalBlendTime=-1;a.statuses={};a.buffs=[];a.level=0;a.setLevel(0);a.time=0;return a};$jscomp.inherits(fa,$a);fa.prototype.setVariationWithGender=function(a){var b,c;B(this,fa);var d=t.getCharacter(this.id);var e=[];var f=
t.arrify(d.variations);d=c=0;for(b=f.length;c<b;d=++c){var g=f[d];null!=a&&a!==g.gender||e.push(d)}return 0===e.length?this.setVariation(J.randInt(f.length)):this.setVariation(e.sample())};fa.prototype.setVariation=function(a){var b,c,d;B(this,fa);this.variationIdx=a;var e=t.getCharacter(this.id);a=t.arrify(e.variations)[a];n.assert(null!=a);this.gender=a.gender;this.sprite=a.sprite;this.portrait=a.portrait;null!=a.miniSprite&&(this.miniSprite=a.miniSprite);this.title=q.parse(null!=(b=e.title)?b:
"",this.gender);this.description=q.parse(null!=(c=e.description)?c:"",this.gender);null!=this.portrait&&(b=this.portrait.split("."),this.portraitSmall=b[0]+"_small",null!=b[1]&&(this.portraitSmall=this.portraitSmall+"."+b[1]));null!=a.sprite&&(this.mountedSprite=null!=(d=a.mountedSprite)?d:a.sprite.replace(".png","")+"_mounted.png");if(null==this.name)return this.name=null!=e.name?e.name:this.createRandomName(a.name)};fa.prototype.getImgSlot=function(a){var b;return this.isMember?null!=this.imgSlot?
this.imgSlot:this.flags.special?config.imgSlot.explorer:this.flags.animal||this.flags.vehicle?config.imgSlot.animal:config.imgSlot.unit:null!=(b=this.imgSlot)?b:config.imgSlot.npc};fa.prototype.getImg=function(){return this.sprite};fa.prototype.setStatus=function(a,b,c,d){c=void 0===c?!1:c;d=void 0===d?!1:d;var e=this.statuses[a];var f=!1;if(void 0===b||b)if(null==e){e=new kc(a,d,this.gender);if(null==e.id)return;f=!0;this.statuses[a]=e;if(null!=this.onStatusChanged)this.onStatusChanged()}else c&&
(e.dayAge=0,e.tripAge=0);else if(null!=e&&(f=!0,delete this.statuses[a],null!=this.onStatusChanged))this.onStatusChanged();return f};fa.prototype.addBuff=function(a){var b;var c=null!=(b=t.getBuff(a).maxStack)?b:3;if(this.buffs.count(function(b){return b.id===a})<c&&(c=new Tc(a),this.buffs.push(c),c.isTaunting))return this.isTaunting=!0};fa.prototype.hasStatus=function(a){return!0===(null!=this.statuses[a])};fa.prototype.canRegenHealth=function(){var a;if(!this.hasHealth())return!1;var b=this.statuses;
for(a in b){var c=b[a];if(c.blockHealthRegen)return!1}return!0};fa.prototype.hasInfection=function(){return null!=this.statuses[config.specialStatuses.infected]};fa.prototype.moveTo=function(a,b){this.moveStartPos=this.screenPos.clone();this.moveTargetPos=a;this.moveBlendTime=0<b?J.rand(-.5,0):0;return this.moveTotalBlendTime=b};fa.prototype.tick=function(a){$a.prototype.tick.call(this,a);this.tickAnim(a);this.tickInterp(a);return this.tickMirror(a)};fa.prototype.tickAnim=function(a){};fa.prototype.tickMirror=
function(a){var b=this.flags.animal||this.flags.vehicle||this.flags.noMirror;if(0>this.moveTotalBlendTime)return b?this.mirrored=!1:0>this.mirrorTime?(this.mirrorTime=J.randInt(5,15),this.mirrored=!this.mirrored):this.mirrorTime-=a;if(null!=this.moveTargetPos)return this.mirrored=this.moveTargetPos.x<this.screenPos};fa.prototype.tickInterp=function(a){if(!(0>this.moveTotalBlendTime||null==this.moveTargetPos)){this.moveBlendTime+=a;a=J.clamp(this.moveBlendTime/this.moveTotalBlendTime,0,1);a=J.smoothStep(a);
var b=this.moveTargetPos.x-this.moveStartPos.x;this.screenPos=new u(this.moveStartPos.x+b*a,this.moveStartPos.y+(this.moveTargetPos.y-this.moveStartPos.y)*a);if(1<=a)return this.moveTotalBlendTime=-1}};fa.prototype.hasHealth=function(){B(this,fa);return!(this.isNPC||this.flags.vehicle||this.flags.noHealth)};fa.prototype.changeHealth=function(a){B(this,fa);if(0!==a&&this.hasHealth()){var b=this.health;this.health=J.clamp(this.health+a,0,this.maxHealth);this.queuedHealthParticles+=this.health-b;this.regenTurn=
0;return this.updateHealth()}};fa.prototype.hasLoyalty=function(){B(this,fa);return!(this.isEnemy||this.isSpecial||this.flags.animal||this.isNPC||this.flags.vehicle||this.flags.noLoyalty)};fa.prototype.changeLoyalty=function(a){B(this,fa);if(this.hasLoyalty()&&0!==a)return this.hasStatus(config.specialStatuses.bipolar)&&(a*=2),this.baseLoyalty=J.clamp(this.baseLoyalty+a,0,4),this.oldLoyalty=this.loyalty,this.updateLoyalty(),this.loyalty-this.oldLoyalty};fa.prototype.updateLoyalty=function(){if(this.hasLoyalty())return this.loyalty=
this.baseLoyalty+this.getCharBonus("loyalty"),this.setStatus(config.specialStatuses.angry,0===this.loyalty)};fa.prototype.createRandomName=function(a){return null==a?"":"native"===a?n.isChina()?q.parse("txt-native-name-china",this.gender):q.createRandomText(4,10).capitalize():q.createName(a,{},this.gender)};fa.prototype.setLevel=function(a){var b=t.getCharacter(this.id);if(!(null==b.levels||!this.isSpecial&&a>=t.arrify(b.levels).length)&&(this.level=a,this.updateHealth(),a=b.levels[this.level],null!=
a)){b=this.statuses;for(e in b){var c=b[e];c.isDefault&&this.setStatus(e,!1)}c=t.arrify(a.statuses);var d=0;for(b=c.length;d<b;d++){var e=c[d];this.setStatus(e,!0,!0,!0)}this.levelBonus=t.arrify(a.bonus);return this.updateDice()}};fa.prototype.getLastName=function(){return this.name.split(" ").last()};fa.prototype.getLevelConf=function(a){var b=t.getCharacter(this.id);if(null==b.levels)return null;a=Math.min(t.arrify(b.levels).length-1,a);var c=Object.clone(b.levels[a]);c.health=b.health+a*this.healthBonus;
return c};fa.prototype.canLevelUp=function(){var a;var b=t.getCharacter(this.id);b=t.arrify(b.levels);var c=this.statuses;for(a in c){var d=c[a];if(d.blockLevelUp)return!1}return this.isSpecial?n.isIO()&&this.level<config.xp.playerLevels.length-1:this.level<b.length-1};fa.prototype.updateDice=function(a){a=void 0===a?!1:a;var b;B(this,fa);var c=[];this.isSpecial&&c.add(t.arrify(config.challenge.defaultExplorerDice));var d=this.getLevelConf(this.level);null!=d&&c.add(t.arrify(d.dice));null==this.mounted||
a||c.add(t.arrify(this.mountedDice));a=this.statuses;for(b in a)d=a[b],c.add(t.arrify(d.bonus.dice));return this.dice=c.flatten().map(function(a){return t.getDie(a)})};fa.prototype.updateUnitCount=function(){B(this,fa);return this.unitCount=1+this.getCharBonus("unitCount")};fa.prototype.updateHealth=function(){B(this,fa);var a=this.maxHealth;this.maxHealth=Math.max(1,this.baseHealth+this.level*config.xp.healthBonus+this.getCharBonus("health"));this.health=Math.max(0,this.health+(this.maxHealth-a));
this.healthRegenBonus=this.getCharBonus("healthRegen");this.healthRegenTurn=config.healthRegenTurn*(1-this.healthRegenBonus);this.infectionChance=this.getCharBonus("infection");this.deathChance=this.getCharBonus("death");if(this.hasInfection())return this.setStatus(config.specialStatuses.injured,!1);if(this.health<this.maxHealth)return this.setStatus(config.specialStatuses.injured,!0);if(this.health>=this.maxHealth)return this.health=this.maxHealth,this.setStatus(config.specialStatuses.injured,!1)};
fa.prototype.incHealthRegen=function(){B(this,fa);if(this.canRegenHealth()&&(this.regenTurn+=1,this.regenTurn>=this.healthRegenTurn))return this.changeHealth(1)};fa.prototype.getCharBonus=function(a){var b,c,d;var e=null!=(b=this.bonus[a])?b:0;b=this.statuses;for(d in b){var f=b[d];0>=f.buffDelayDays&&0>=f.buffDelayTrips&&(e+=null!=(c=f.bonus[a])?c:0)}return e};var Fa=fa;var Hc=function(a,b,c){b=void 0===b?!1:b;c=void 0===c?"male":c;var d,e,f,g,h,k,l,m,p,n,r,D;var v=t.getStatus(a,!1);null!=v&&(this.id=
a,this.isDefault=b,this.title=q.parse(v.title,c),this.description=q.parse(v.description,c),this.warnHealth=null!=(d=v.warnHealth)?d:!1,this.sprite=null!=(h=v.sprite)?h:"res_status_placeholder.png",this.autoRemove=null!=(k=v.autoRemove)?k:!1,this.important=null!=(l=v.important)?l:!1,this.noBonusStacking=null!=(m=v.noBonusStacking)?m:!1,this.dayEvents=t.arrify(v.dayEvents),this.tripEvents=t.arrify(v.tripEvents),this.buffEndEvents=t.arrify(v.buffEndEvents),this.showAge=null!=v?v:!1,this.bonus=null!=
(p=v.bonus)?p:{},this.flags=t.setFlags(v.flags),this.revealTime=0,this.blockHealthRegen=null!=(n=v.blockHealthRegen)?n:!1,this.blockLevelUp=null!=(r=v.blockLevelUp)?r:!1,this.buffDelayDaysInit=this.buffDelayDays=J.randR(null!=(D=v.buffDelayDays)?D:"0"),this.buffDelayTripsInit=this.buffDelayTrips=J.randR(null!=(e=v.buffDelayTrips)?e:"0"),this.buffDaysInit=this.buffDays=J.randR(null!=(f=v.buffDays)?f:"0"),this.buffTripsInit=this.buffTrips=J.randR(null!=(g=v.buffTrips)?g:"0"),this.tripAge=this.dayAge=
0)};Hc.prototype.clearAge=function(){return this.dayAge=0};var kc=Hc;var Tc=function(a){var b,c;this.id=a;a=t.getBuff(a);this.title=q.toText(a.title);this.description=q.toText(a.description);this.damage=a.damage;this.duration=a.duration;this.particle=a.particle;this.sprite=a.sprite;this.maxStack=null!=(b=a.maxStack)?b:3;this.isTaunting=a.isTaunting;this.stunDice=null!=(c=a.stunDice)?c:0};var Wa=function(a,b){b=void 0===b?{}:b;var c,d;var e=Object.isString(a)?t.getDie(a):a;n.assert(null!=e.sprite,
"Missing sprite for "+a);this.id=e.id;this.sprite=null!=(c=e.sprite)?c:"hud_dice_symbol_blink_1.png";this.item=e.item;this.addFaces(e.faces);this.character=b.character;this.item=b.item;this.isTemp=null!=(d=b.temp)?d:!1;null!=this.character&&(this.isEnemy=this.character.isEnemy);this.anim=new tb;this.targetRot=0;this.destroyed=!1;this.faceIdx=this.faces.length-1;this.reset()};Wa.prototype.addFaces=function(a){var b=this,c;this.faces=[];var d=n.parseFaces(a);for(c in d)a=d[c],a.times(function(){return b.faces.push(t.getDieFace(c))});
for(a=[];this.faces.length<config.challenge.faceCount;)a.push(this.faces.push(t.getDieFace("blank")));return a};Wa.prototype.getFace=function(){return this.faces[this.faceIdx]};Wa.prototype.setRolledFace=function(a){return this.faceIdx=this.faces.findIndex(function(b){return b.id.slice(3)===a})};Wa.prototype.tick=function(a){var b;this.rollTime+=a;this.anim.tick(a);var c=this.targetRot-this.rot;this.rot=.1<Math.abs(c)?this.rot+5*a*c:this.targetRot;0>=(null!=(b=this.character)?b.health:void 0)&&this.destroy();
this.destroyed&&(this.destroyTime+=a);if(this.rollTime>config.challenge.rollTime)return this.rolling=!1};Wa.prototype.destroy=function(){if(!this.destroyed)return this.destroyTime=0,this.destroyed=!0};Wa.prototype.roll=function(a,b){this.rollTime=void 0===b?0:b;this.rolling=!0;this.selected=this.pinned=!1;this.faceIdx=this.randFace();this.targetRot=this.rollRot=Number.random(-config.challenge.maxDiceRotation,config.challenge.maxDiceRotation);this.anim.interpTo(a,config.challenge.rollTime);return this.oldTarget=
a};Wa.prototype.randFace=function(){return Number.random(0,this.faces.length-1)};Wa.prototype.reset=function(){this.rollTime=0;return this.consumed=this.pinned=this.rolling=!1};var Z=function(a,b,c){this.onMouseClick=this.onMouseClick.bind(this);this.selectRandomTarget=this.selectRandomTarget.bind(this);this.doKillAchievements=this.doKillAchievements.bind(this);this.r=a;this.s=a.s;this.sfx=b;this.main=c;this.diary=this.main.diary;this.infoBox=this.main.infoBox;this.part=new qb(a,b);this.setHints(this.main.firstCombat);
this.main.firstCombat=!1;this.enableRoundAction=this.enableRoll=!0;this.debugIsGodMode=!1};Z.prototype.setHints=function(a){return this.hintRound=this.hintAttack=this.hintRoll=this.hintPin=a};Z.prototype.onMouseClick=function(a){if(null!=this.mouseAction){if("die"===this.mouseAction.id)return this.doSelectDie(this.mouseAction.data);if("pattern"===this.mouseAction.id)return this.commitPattern(this.mouseAction.data),this.mouseAction=null;if("roll"===this.mouseAction.id)return this.doPartyRoll();if("accept"===
this.mouseAction.id)return this.doEndPartyRound();if("target"===this.mouseAction.id)return this.target=this.mouseAction.data;if("continue"===this.mouseAction.id||"cancel"===this.mouseAction.id)return this.endCombat();if("nextPattern"===this.mouseAction.id)return this.partyPatternIdx=this.partyPatternIdx>=this.partyPatterns.length-1?0:this.partyPatternIdx+1,this.autoSelectDice();if("prevPattern"===this.mouseAction.id)return this.partyPatternIdx=0>=this.partyPatternIdx?this.partyPatterns.length-1:this.partyPatternIdx-
1,this.autoSelectDice()}};Z.prototype.autoSelectDice=function(){var a,b,c;if(this.main.combatAutoSelect&&(this.partyPattern=this.isPartyRound?this.partyPatterns[this.partyPatternIdx]:null,null!=this.partyPattern)){var d=this.partyDice.filter(function(a){return!a.consumed&&!a.isStunned});var e=0;for(a=d.length;e<a;e++){var f=d[e];f.wasSelected=f.selected;f.selected=!1}a=[];var g=t.arrify(this.partyPattern.faces);var h=0;for(b=g.length;h<b;h++){e=g[h];var k=0;for(c=d.length;k<c;k++)if(f=d[k],f.getFace().id.slice(3)===
e){a.push(f);d.remove(f);f.selected=!0;break}}e=0;for(k=d.length;e<k;e++)f=d[e],!f.wasSelected||f.selected||f.consumed||(f.anim.interpTo(f.oldTarget,.25),f.targetRot=f.rollRot);return this.updateSockets(a)}};Z.prototype.showCombat=function(a,b,c,d){d=void 0===d?{}:d;var e,f,g,h;this.party=a;null!=c&&this.party.incStatCombatZone(c.id);var k=this.party.persons;var l=0;for(g=k.length;l<g;l++)a=k[l],0>=a.health&&null!=a.mounted&&this.party.dismount(a);this.zone=c;this.round=this.challengeTime=0;this.target=
this.onSuccess=null;c=null!=(f=d.isSurpriseAttack)?f:!1;this.winEvent=null!=(e=d.win)?e:this.main.challengeEvts.win;this.fleeEvent=null!=(h=d.flee)?h:this.main.challengeEvts.cancel;null!=this.main.invBar&&this.main.invBar.setSlotLimit(config.inventory.maxCombatSlots);this.preRoll=this.isPartyRound=!0;this.shields={party:{value:0,time:100,hits:0},enemy:{value:0,time:100,hits:0}};this.isSurpriseAttack=c;this.lootSets=[];this.fame=0;this.part.clearParticles();this.enemies=[];d=0;for(m in b)if(e=b[m],
"slots"!==m)for(f=0,h=e;0<=h?f<h:f>h;0<=h?++f:--f)e=new Fa(this.main,m),null!=e.id&&(e.title=q.toText("txt-combat-targetbuff"),e.isEnemy=!0,e.updateSprite(this.main.getTribeGenAtPartyPos()),e.slot=d,this.enemies.push(e),d+=1,this.party.incStatCombatEnemy(e.id));this.partyDice=this.getDice(this.party.persons);this.enemyDice=this.getDice(this.enemies);d=this.party.isPacifist();g=this.party.inv.items.compact();var m=0;for(h=g.length;m<h;m++)if(f=g[m],!f.isWeapon||!d)for(k=t.arrify(f.dice),e=0,a=k.length;e<
a;e++)b=k[e],this.partyDice.push(new Wa(b,{item:f}));this.updateSockets(this.partyDice);this.updateTarget();return c?this.startEnemyRound():this.startPartyRound()};Z.prototype.endCombat=function(){var a,b;this.main.showingChallenge=!1;null!=(a=this.main.invBar)&&a.setSlotLimit(config.inventory.maxPartySlots);var c=this.party.persons;var d=0;for(b=c.length;d<b;d++)a=c[d],a.updateHealth(),a.buffs=[];0<this.enemies.length?a=this.fleeEvent:(a=this.winEvent,null!=this.zone&&this.main.world.removeZone(this.zone));
this.main.challengeEvts=null;this.diary.setCombat(!1);if(null!=a){b=[];var e=this.lootSets;var f=0;for(c=e.length;f<c;f++)d=e[f],b.add(this.main.randItemSet(d));b=new Va(this.main,b);return this.main.doRandEvent(a,{inv:b,zone:this.zone})}return this.main.hideEventDialogue()};Z.prototype.getDice=function(a,b){b=void 0===b?"":b;var c,d;var e=[];var f=0;for(c=a.length;f<c;f++){var g=a[f];g.myDice=[];if(t.checkFlags(b,g.flags)&&!(0>=g.health)){var h=g.dice;var k=0;for(d=h.length;k<d;k++){var l=h[k];l=
new Wa(l,{character:g});e.push(l);g.myDice.push(l)}}}return e};Z.prototype.canUseItem=function(a,b){return 0===a.tempDice.length||this.partyDice.count(function(b){var c;return(null!=(c=b.item)?c.id:void 0)===a.id})>=a.maxDice||this.party.isPacifist()&&a.isWeapon?!1:!0};Z.prototype.useItem=function(a,b){if(this.canUseItem(a,b)){var c=a.tempDice;var d=0;for(b=c.length;d<b;d++){var e=c[d];e=new Wa(e.id,{item:a,temp:!0});if(!this.preRoll){var f=this.partyDice.map(function(a){return a.anim.pos});e.roll(this.randDiePos(f),
0)}this.partyDice.push(e)}this.preRoll&&this.updateSockets(this.partyDice);this.updatePattern();return!0}};Z.prototype.canTarget=function(a){var b=this.enemies.any(function(a){return a.isTaunting&&0<a.health});return 0<a.health&&(!b||a.isTaunting)};Z.prototype.updateTarget=function(){var a=this.enemies.any(function(a){return a.isTaunting&&0<a.health});if(null===this.target||0>=this.target.health||a&&!this.target.isTaunting){var b=this.enemies.filter(function(b){return 0<b.health&&!a||b.isTaunting}).sample();
if(null!=b)return this.target=b}};Z.prototype.hide=function(){if(null!=this.main.invBar)return this.main.invBar.setSlotLimit(config.inventory.maxPartySlots)};Z.prototype.startPartyRound=function(){var a,b;this.isPartyRound=this.preRoll=!0;this.incBuffTurn();this.rollsLeft=Math.max(1,config.challenge.defaultRolls+this.party.getBonus("combatRoll"));config.challenge.resetShields&&(this.shields.party={value:0,hits:0,time:100});var c=this.partyDice;var d=b=0;for(a=c.length;b<a;d=++b)d=c[d],d.reset();this.updatePattern();
return this.updateSockets(this.partyDice)};Z.prototype.startEnemyRound=function(){var a,b;this.preRoll=!0;this.isPartyRound=!1;this.incBuffTurn();this.enemyTime=0;this.enemyRolled=!1;config.challenge.resetShields&&(this.shields.enemy={value:0,hits:0,time:100});var c=this.enemyDice;var d=b=0;for(a=c.length;b<a;d=++b)d=c[d],d.tick(0),d.reset();this.updatePattern();return this.updateSockets(this.enemyDice)};Z.prototype.incBuffTurn=function(){var a,b,c;var d=this.isPartyRound?this.party.persons:this.enemies;
var e=[];var f=0;for(b=d.length;f<b;f++){var g=d[f];var h=0;g.isTaunting=!1;var k=g.buffs;var l=c=0;for(a=k.length;c<a;l=++c)l=k[l],null!=l&&(null!=l.damage&&this.doDamage([g],l.damage),0<l.stunDice&&(h+=l.stunDice),l.isTaunting&&1<l.duration&&(g.isTaunting=!0),--l.duration);g.buffs.remove(function(a){return null==a||0>=a.duration});c=t.arrify(g.myDice);a=0;for(k=c.length;a<k;a++){var m=c[a];m.isStunned=!1}e.push(function(){var a;var b=t.arrify(g.myDice).sample(h);var c=[];var d=0;for(a=b.length;d<
a;d++)m=b[d],c.push(m.isStunned=!0);return c}())}return e};Z.prototype.randDiePos=function(a){var b;this.getRollAreaCenter();var c=this.getRollAreaSize();var d=$jscomp.makeIterator(config.imgSize.dice);var e=d.next().value;var f=d.next().value;for(b=0;1E3>b;++b){var g=$jscomp.makeIterator([Number.random(-c.w/2+e/2,c.w/2-e/2),Number.random(-c.h/2+f/2,c.h/2-f/2)]);d=g.next().value;g=g.next().value;var h=new u(d,g);if(!(11236>d+d+g*g)&&a.all(function(a){return 72<a.dist(h)}))break}return h};Z.prototype.doPartyRoll=
function(){if(this.isPartyRound&&!(0< !this.rollsLeft))return this.preRoll=this.hintRoll=!1,--this.rollsLeft,this.sfx.play("diceButton"),this.sfx.play("diceRoll"),this.rollDice(this.partyDice.filter(function(a){return!a.pinned&&!a.consumed})),this.updatePattern()};Z.prototype.doEnemyRoll=function(){this.preRoll=!1;this.enemyRolled=!0;this.sfx.play("diceButton");this.sfx.play("diceRoll");this.rollDice(this.enemyDice);return this.enemyPattern=this.findEnemyPatterns()};Z.prototype.rollDice=function(a){var b,
c;var d=[];var e=c=0;for(b=a.length;c<b;e=++c){var f=a[e];var g=this.randDiePos(d);f.roll(g,e*-config.challenge.rollDelay);d.push(g)}if(null!=this.main.tutorial){f=[{"dc-support-2":"mind","dc-defend-1":"stability","dc-attack-1":"blank"},{"dc-defend-1":"shield","dc-attack-1":"sword"}];e=f[3*this.round+(2-this.rollsLeft)];g=[];d=0;for(b=a.length;d<b;d++)f=a[d],null!=e[f.id]?g.push(f.setRolledFace(e[f.id])):g.push(void 0);return g}};Z.prototype.updateSockets=function(a){var b=this,c,d;var e=function(a,
c){var d,e;var f=b.getRollAreaCenter();var g=b.diary.getImageCenter();var h=g.x-f.x;f=g.y-f.y+c;c=b.preRoll?0:1;var k=$jscomp.makeIterator(config.imgSize.dice);g=k.next().value;k.next();g*=b.s;var l=10*b.s;h-=n.width(a.length,g,l)/2-g/2;var m=e=0;for(d=a.length;e<d;m=++e)k=a[m],m=new u(h+m*(g+l),f),k.anim.interpTo(m,c),k.rot=k.targetRot=0};var f=$jscomp.makeIterator(config.imgSize.dice);f.next();f.next();if(this.preRoll){this.getRollAreaCenter();e=0===this.round?0:1;var g=[];var h=d=0;for(c=a.length;d<
c;h=++d){f=a[h];var k=h/a.length*Math.PI*2;h=75*Math.sin(k)*this.s;k=-75*Math.cos(k)*this.s;f.anim.interpTo(new u(h,k),e);g.push(f.rot=f.targetRot=Number.random(-config.challenge.maxDiceRotation,config.challenge.maxDiceRotation))}return g}e(a.filter(function(a){return a.consumed}),-130*this.s);return e(a.filter(function(a){return a.selected&&!a.consumed}),-100*this.s)};Z.prototype.doSelectDie=function(a){if(!this.preRoll){if(null!=this.main.tutorial){var b=["mind","shield","sword"];var c=this.partyDice.count(function(a){return a.pinned});
b=b[c];if(a.pinned||b!==a.getFace().id.slice(3)||1<c&&0===this.partyDice.count(function(a){return a.consumed}))return}if(!(a.consumed||a.isEnemy||a.rolling||a.isStunned))return this.main.combatAutoSelect?a.pinned=!a.pinned:(a.pinned?(a.selected=a.pinned=!1,a.anim.interpTo(a.oldTarget,.25),a.targetRot=a.rollRot,this.sfx.play("diceDismiss")):(a.selected=a.pinned=!0,this.sfx.play("diceSelect")),this.updatePattern()),this.updateSockets(this.partyDice)}};Z.prototype.consumeDice=function(a,b){var c,d;var e=
[];a=n.parseFaces(a.faces);for(c in a){var f=a[c];var g=0;for(d=f;0<=d?g<d:g>d;0<=d?++g:--g){var h=b.filter(function(a){return!a.consumed}).find(function(a){return a.getFace().id.slice(3)===c});null!=h&&(f=h.character,null==f||e.any(f)||e.push(f),h.consumed=!0)}}g=0;for(a=e.length;g<a;g++)b=e[g],b.nudge(new qa(0,-30));return e};Z.prototype.commitPattern=function(a,b){b=void 0===b?!1:b;var c,d,e,f,g,h,k,l,m,p,w;var t=b?this.enemyDice:this.partyDice;var r=n.parseFaces(a.faces);var v=this.getFaceCount(t);
if(n.checkMatch(v,r)){v=t.map(function(a){return a.character}).compact().unique();t=this.consumeDice(a,t.filter(function(a){return a.selected||b}));r=null!=(g=a.damage)?g:0;g=null!=(k=a.shield)?k:0;k=null!=(e=a.shieldDamage)?e:0;e=null!=(l=a.multiHeal)?l:0;l=null!=(d=a.selfDamage)?d:0;d=null!=(m=a.groupDamage)?m:0;m=null!=(p=a.targetBuff)?p:null;p=null!=(w=a.selfBuff)?w:null;b||null==a.id||(null==(c=this.party.stats.attackUsage)[f=a.id]&&(c[f]=0),this.party.stats.attackUsage[a.id]+=1);0<e&&this.doHeal(v,
e);c=b?this.shields.enemy:this.shields.party;c.value=Math.min(c.value+g,config.challenge.maxShield);c=b?this.shields.party:this.shields.enemy;k=Math.min(k,c.value);c.value-=k;f=Math.min(r,c.value);r-=f;c.value-=f;if(0<f||0<k)this.sfx.play("diceShield"),c.time=0,c.hits=f+k;c=this.getAttackTargets(a,b);this.doDamage(c,r,a.particle);"dp-attack7"===a.id&&c.some(function(a){return a.id.includes("raptor")})&&this.main.achievements.incCounter("ach-headbutt-raptor");0<l&&this.doDamage(t,l,a.particle);0<d&&
this.doDamage(v,d,a.particle);if(null!=m)for(f=0,r=c.length;f<r;f++)v=c[f],this.debugIsGodMode&&!v.isEnemy||v.addBuff(m);if(null!=p)for(r=0,c=t.length;r<c;r++)v=t[r],v.addBuff(p);this.updateTarget();this.updatePattern();this.updateSockets(this.partyDice);this.updateSockets(this.enemyDice);this.hintAttack=!1;this.showPatternName(q.toText(a.name),b);null!=a.sound&&this.sfx.play(a.sound);b||this.party.changeFame(null!=(h=a.fame)?h:0);if(debug.outputDiaryLog&&null==this.timeToShot||0>=this.timeToShot)return this.timeToShot=
.15}};Z.prototype.showPatternName=function(a,b){var c=this.diary.getImageCenter().sub(this.diary.getImageOffset());var d=config.particle.attackNames;return this.part.addParticleConf(d,c,{text:a,velX:b?this.part.inv(d.velX):d.velX,offsetX:b?this.part.inv(d.offsetX):d.offsetX})};Z.prototype.getAttackTargets=function(a,b){if(a.multiAttack)return a=b?this.partyDice:this.enemyDice,a.map(function(a){return a.character}).compact().unique();if(b){a=this.partyDice.filter(function(a){return null!=a.character});
b=a.filter(function(a){return a.pinned});var c=a.filter(function(a){return a.character.isTaunting});if(0<c.length)return[c.sample().character];a=0<b.length?b:a;return[a.sample().character]}return[this.target]};Z.prototype.doHeal=function(a,b){var c;n.assert(0<b);var d=t.arrify(a);var e=[];var f=0;for(c=d.length;f<c;f++)if(a=d[f],null==a.riding&&!(0>=a.health)){var g=Math.min(a.health+b,a.maxHealth);g>a.health&&(a.health=g,a.nudge(new qa(0,-30)));g=config.particle.heal;e.push(this.part.addParticleConf(g,
this.particlePos(a)))}return e};Z.prototype.doDamage=function(a,b,c){var d;var e=0;for(d=a.length;e<d;e++){var f=a[e];if(!this.debugIsGodMode||f.isEnemy){null!=f.riding&&(f=this.main.party.persons.find(function(a){return a.mounted===f}));var g=Math.min(b,f.health);if(0<g){f.health-=g;f.damageTime=0;f.isEnemy&&(this.main.party.noCombat=!1);g=f.isEnemy?50:-50;f.nudge(new qa(g,0));g=this.particlePos(f);var h=null!=c?c:config.particle.blood;Object.isString(h)&&(h=t.getParticle(h));this.part.addParticleConf(h,
g,{velX:f.isEnemy?h.velX:this.part.inv(h.velX),count:b*h.count});this.part.addParticleConf(config.particle.damageNumber,g,{text:"-"+b});if(0>=f.health)if(f.isEnemy){if(f===this.target&&(this.target=this.selectRandomTarget()),this.doKillAchievements(f),this.lootSets.push(f.items),null!=this.onSuccess)this.onSuccess()}else null!=f.mounted&&this.main.party.dismount(f)}}}};Z.prototype.selectRandomTarget=function(){return this.enemies.sample()};Z.prototype.doKillAchievements=function(a){switch(a.id){case "emy-giantSpider":return this.main.achievements.incCounter("ach-giantSpider-kills");
case "emy-giantCrab":return this.main.achievements.incCounter("ach-giantCrab-kill");case "emy-giantScorpion":return this.main.achievements.incCounter("ach-giantScorpion-kills");case "emy-walrus":return this.main.achievements.incCounter("ach-giantWalrus-kills");case "emy-giantBird":return this.main.achievements.incCounter("ach-giantBird-kills");case "emy-crocodile":return this.main.achievements.incCounter("ach-crocodile-kills");case "emy-hyena":case "emy-hyena-black":return this.main.achievements.incCounter("ach-hyena-kills")}};
Z.prototype.doEndPartyRound=function(){if(null==this.partyPattern||this.main.combatAutoSelect)return this.partyDice.remove(function(a){return a.isTemp}),this.hintRound=!1,this.startEnemyRound();this.hintAttack=!0};Z.prototype.endEnemyRound=function(){this.round+=1;return this.startPartyRound()};Z.prototype.checkExpeditionOver=function(){return 0===this.partyDice.count(function(a){return null!=a.character})};Z.prototype.getFaceCount=function(a){if(this.preRoll)return[];a=a.filter(function(a){return!a.isStunned});
return n.count(a,function(a){return a.getFace().id.slice(3)})};Z.prototype.parseEnemyBonus=function(a){var b,c,d;return null==a?null:Object.isNumber(a)?a:Object.isString(a)?"-"===a[0]?null!=(b=-config.standardValues[a.slice(1)])?b:0:null!=(c=config.standardValues[a])?c:0:null!=(d=this.parseEnemyBonus(a.base))?d:0};Z.prototype.findEnemyPatterns=function(){var a,b,c,d,e,f,g,h,k;var l=this.enemyDice.filter(function(a){return!a.isStunned&&!a.destroyed});var m=this.getFaceCount(l);l=[];for(a=!0;a;){a=
!1;var p=config.dicePattern;for(k=p.length-1;0<=k;k+=-1){var w=p[k];var q=n.parseFaces(w.faces);if(n.checkMatch(m,q)){for(b in q)a=q[b],m[b]-=a;w={id:w.id,name:w.name,faces:w.faces,sound:w.sound,multiAttack:w.multiAttack,targetBuff:w.targetBuff,selfBuff:w.selfBuff,damage:null!=(c=this.parseEnemyBonus(w.damage))?c:0,groupDamage:null!=(d=this.parseEnemyBonus(w.groupDamage))?d:0,selfDamage:null!=(e=this.parseEnemyBonus(w.selfDamage))?e:0,shield:null!=(f=this.parseEnemyBonus(w.shield))?f:0,shieldDamage:null!=
(g=this.parseEnemyBonus(w.shieldDamage))?g:0,multiHeal:null!=(h=this.parseEnemyBonus(w.multiHeal))?h:0};l.push(w);a=!0}}}return l};Z.prototype.findPattern=function(a){var b;a=this.getFaceCount(a);var c=config.dicePattern;var d=0;for(b=c.length;d<b;d++){var e=c[d];var f=n.parseFaces(e.faces);if(n.checkMatch(a,f))return e}return null};Z.prototype.getSanityRollCost=function(){return 0};Z.prototype.tick=function(a){var b,c;this.challengeTime+=a;this.part.tickParticles(a);this.shields.party.time+=a;this.shields.enemy.time+=
a;if(!this.isPartyRound){if(this.isSurpriseAttack&&0===this.enemyTime){var d=this.diary.getImageSize();this.part.addParticleConf(config.particle.attackNames,new u(d.w/2,d.h/2),{text:q.toText("txt-combat-surprise")})}this.enemyTime+=a;this.isSurpriseAttack?this.enemyTime>config.challenge.surpriseDelay&&(this.enemyTime=0,this.isSurpriseAttack=!1):this.enemyRolled?this.enemyDice.none(function(a){return a.rolling})&&1<this.enemyTime&&(0===this.enemyPattern.length?this.endEnemyRound():(this.commitPattern(this.enemyPattern.shift(),
!0),this.enemyTime=0)):1<this.enemyTime&&this.doEnemyRoll()}var e=[this.partyDice,this.enemyDice];var f=0;for(b=e.length;f<b;f++){var g=e[f];var h=0;for(c=g.length;h<c;h++){var k=g[h];k.tick(a);if(null!=k.character){var l=k.character.buffs;for(p in l)if(d=l[p],null!=d.particle){if(null==d.particleTime){var m=t.getParticle(d.particle);d.particleProto=m;d.particleTime=J.rand(0,m.timer[1])}d.particleTime-=a;0>d.particleTime&&0<k.character.health&&(d.particleTime=J.randA(d.particleProto.timer),m=this.particlePos(k.character),
this.part.addParticleConf(d.particleProto,m))}}}}this.partyDice.remove(function(a){return 1<a.destroyTime});this.enemyDice.remove(function(a){return 1<a.destroyTime});k=this.enemies;d=0;for(g=k.length;d<g;d++){var p=k[d];p.tick(a)}this.enemies.remove(function(a){return 0>=a.health});0===this.enemyDice.length&&this.endCombat();if(null!=this.timeToShot&&0<this.timeToShot&&(this.timeToShot-=a,0>this.timeToShot))return this.main.outputDiaryLog=!0};Z.prototype.hasChallenge=function(){return 0<this.enemies.length};
Z.prototype.canRoll=function(){var a=0<this.partyDice.count(function(a){return!a.pinned});return this.enableRoll&&a&&0<this.rollsLeft&&this.isPartyRound};Z.prototype.updatePattern=function(){var a,b,c,d,e,f,g,h,k,l,m;this.partyPattern=null;this.partyPatterns=[];this.partyPatternIdx=-1;var p=this.partyDice.filter(function(a){return!a.consumed&&!a.isStunned});var w=p.filter(function(a){return a.pinned});var q=config.dicePattern;var t=0;for(a=q.length;t<a;t++){var v=q[t];if(!v.hide){var r=this.getFaceCount(this.main.combatAutoSelect?
p:w);var Y=n.parseFaces(v.faces);var A=!0;for(T in Y){var H=Y[T];if(this.main.combatAutoSelect){if((null!=(b=r[T])?b:0)<H){A=!1;break}}else if(!Object.equal(Y,r)){A=!1;break}}A&&(this.partyPatterns.push({id:v.id,name:v.name,faces:v.faces,sound:v.sound,multiAttack:v.multiAttack,targetBuff:v.targetBuff,selfBuff:v.selfBuff,damage:null!=(e=this.party.parseBonus(v.damage))?e:0,groupDamage:null!=(f=this.party.parseBonus(v.groupDamage))?f:0,selfDamage:null!=(g=this.party.parseBonus(v.selfDamage))?g:0,shield:null!=
(h=this.party.parseBonus(v.shield))?h:0,shieldDamage:null!=(k=this.party.parseBonus(v.shieldDamage))?k:0,multiHeal:null!=(l=this.party.parseBonus(v.multiHeal))?l:0}),this.partyPatternIdx=0,this.partyPattern=this.partyPatterns[0])}}this.autoSelectDice();"die"===(null!=(m=this.mouseAction)?m.id:void 0)&&w.push(this.mouseAction.data);var G=this.getFaceCount(p);var u=this.getFaceCount(w);this.openPatterns=config.dicePattern.filter(function(a){var b,c,d;var e=n.parseFaces(a.faces);for(b in u)if(a=u[b],
(null!=(c=e[b])?c:0)<a)return!1;for(b in e)if(a=e[b],(null!=(d=G[b])?d:0)<a)return!1;return!0});if(!this.main.combatAutoSelect){e=[];f=0;for(w=p.length;f<w;f++){r=p[f];var T=r.getFace().id.slice(3);a=!1;if(!r.pinned&&!r.consumed&&!r.isStunned)for(b=this.openPatterns,H=0,q=b.length;H<q;H++)if(v=b[H],v=n.parseFaces(v.faces),0<(null!=(c=v[T])?c:0)-(null!=(d=u[T])?d:0)){a=!0;break}e.push(r.hint=a)}return e}};Z.prototype.drawRollButton=function(a,b,c){var d=30*this.s;var e=this.getRollAreaCenter();a=this.isPartyRound&&
this.r.hitBox(e.x-d,e.y-d/2,2*d,d,a,b);c=!this.canRoll()||a&&c?"hud_button_dice_roll_2.png":"hud_button_dice_roll_1.png";this.r.ctx.globalAlpha=1;this.r.drawSprite(c,e.x,e.y,{halign:"center",valign:"center"});return a};Z.prototype.drawPreviewButton=function(a,b){var c,d,e,f;if(null==this.partyPattern)return null;var g=null;var h=this.diary.getImageCenter();this.r.ctx.font=config.fonts.technicalLarge;var k=q.toText(this.partyPattern.name).capitalize(!0)+"!";var l=$jscomp.makeIterator([150*this.s,20*
this.s]);var m=l.next().value;var p=l.next().value;var n=h.x-m/2;l=h.y-75*this.s;this.r.drawActionPanel(k,n,l,m,p,"white",a,b)&&(g=this.partyPattern);n={mX:a,mY:b,halign:"center"};1<this.partyPatterns.length&&(this.r.drawSprite("hud_scrollButton_charSelect_left.png",h.x+90*this.s,l,n)&&(this.mouseAction={id:"prevPattern"}),this.r.drawSprite("hud_scrollButton_charSelect_right.png",h.x+110*this.s,l,n)&&(this.mouseAction={id:"nextPattern"}));n=h.x;l+=35*this.s;this.r.ctx.font=config.fonts.technicalSmall;
a={halign:"center"};0<this.partyPattern.damage&&(h=q.toText("txt-combat-dmg"),this.r.drawText(h+": "+this.partyPattern.damage,n,l,a),l+=15*this.s);0<this.partyPattern.selfDamage&&(h=q.toText("txt-combat-selfdmg"),this.r.drawText(h+": "+this.partyPattern.selfDamage,n,l,a),l+=15*this.s);0<this.partyPattern.groupDamage&&(h=q.toText("txt-combat-groupdmg"),this.r.drawText(h+": "+this.partyPattern.groupDamage,n,l,a),l+=15*this.s);0<this.partyPattern.shield&&(h=q.toText("txt-combat-shield"),this.r.drawText(h+
": "+this.partyPattern.shield,n,l,a),l+=15*this.s);0<this.partyPattern.shieldDamage&&(h=q.toText("txt-combat-shielddmg"),this.r.drawText(h+": "+this.partyPattern.shieldDamage,n,l,a),l+=15*this.s);this.partyPattern.multiAttack&&(h=q.toText("txt-combat-multiattack"),this.r.drawText(h,n,l,a),l+=15*this.s);0<this.partyPattern.multiHeal&&(h=q.toText("txt-combat-multiheal"),this.r.drawText(h+": "+this.partyPattern.multiHeal,n,l,a),l+=15*this.s);0<this.partyPattern.fame&&(h=q.toText("txt-combat-fame"),this.r.drawText(h+
": "+this.partyPattern.fame,n,l,a),l+=15*this.s);null!=this.partyPattern.selfBuff&&(b=t.getBuff(this.partyPattern.selfBuff),h=q.toText("txt-combat-selfbuff"),b=q.parse(b.title,null!=(c=null!=(d=this.target)?d.gender:void 0)?c:"male"),this.r.drawText(h+": "+b,n,l,a),l+=15*this.s);null!=this.partyPattern.targetBuff&&(b=t.getBuff(this.partyPattern.targetBuff),h=q.toText("txt-combat-targetbuff"),b=q.parse(b.title,null!=(e=null!=(f=this.target)?f.gender:void 0)?e:"male"),this.r.drawText(h+": "+b,n,l,a));
return g};Z.prototype.drawOpenPatterns=function(){var a,b;if(config.challenge.showOverview){var c=this.diary.getImageCenter();var d=$jscomp.makeIterator(this.r.getCanvasSize());d.next();d.next();var e=c.y-200;var f=this.openPatterns;var g=[];var h=0;for(d=f.length;h<d;h++){var k=f[h];var l={scale:1};this.r.ctx.globalAlpha=.75;var m=t.arrify(k.faces);var p=b=0;for(a=m.length;b<a;p=++b){var n=m[p];p=c.x-30*p;n=t.getDieFace(n);this.r.drawSprite("hud_dice_bg_attack_1.png",p,e,l);null!=n.sprite&&this.r.drawSprite(n.sprite,
p,e,l)}this.r.ctx.globalAlpha=1;this.r.drawText(k.name,c.x+40,e+20,{halign:"left"});g.push(e+=30)}return g}};Z.prototype.getRollAreaCenter=function(){return this.diary.getDiaryCenter()};Z.prototype.getRollAreaSize=function(){var a=this.diary.getDiarySize();a.w-=50*this.s;a.h-=80*this.s;return a};Z.prototype.draw=function(a,b,c){var d,e;this.mouseAction=null;var f=this.r.ctx;var g=this.getRollAreaCenter();this.getRollAreaSize();f.globalAlpha=1;var h=this.isPartyRound?this.partyDice:this.enemyDice;
f=null;var k=e=0;for(d=h.length;e<d;k=++e){k=h[k];var l=g.x+k.anim.pos.x;var m=g.y+k.anim.pos.y;var p=$jscomp.makeIterator(config.imgSize.dice);var n=p.next().value;p=p.next().value;p=$jscomp.makeIterator([n*this.s,p*this.s]);n=p.next().value;p=p.next().value;this.r.hitBox(l-n/2,m-p/2,n,p,a,b)&&(this.mouseAction={id:"die",data:k},f={die:k,x:l,y:m})}this.main.combatAutoSelect||f===this.oldHoverDie||this.updatePattern();this.oldHoverDie=f;this.drawShields(a,b);this.drawTitle();c=c&&null==this.mouseAction;
this.drawRollButton(a,b,c)&&null==this.mouseAction&&(this.canRoll()?(this.mouseAction={id:"roll"},this.preRoll?this.infoBox.showHelp(config.help.combat.roll):this.infoBox.showHelp(config.help.combat.reroll)):this.infoBox.showHelp(q.toText("txt-combat-rolls0")));d=this.drawEnemies(a,b);k=n=0;for(e=h.length;n<e;k=++n)k=h[k],l=g.x+k.anim.pos.x,m=g.y+k.anim.pos.y,this.drawDie(k,l,m,a,b);g=this.drawButtons(a,b);null!=g&&(this.mouseAction=g);null!=f&&this.drawDieInfo(f.die,f.x,f.y-25*this.s);this.drawOpenPatterns();
a=this.drawPreviewButton(a,b,c);!this.preRoll&&config.challenge.manualPattern&&null!=a&&(this.mouseAction={id:"pattern",data:a});this.part.drawParticles(!1,this.diary.getImageOffset());return d};Z.prototype.drawDieInfo=function(a,b,c){var d=$jscomp.makeIterator(config.imgSize.dice);var e=d.next().value;d=d.next().value;d=$jscomp.makeIterator([e/2*this.s,d/2*this.s]);e=d.next().value;d=d.next().value;var f=n.width(a.faces.length,e,5*this.s);b-=(f+10*this.s)/2-e;this.r.drawInfoBox(b-5*this.s,c-5*this.s,
f+10*this.s,d+10*this.s);a.isEnemy&&this.infoBox.showHelp(config.help.combat.enemyDie);var g=a.faces;var h=0;for(f=g.length;h<f;h++)d=g[h],this.r.drawSprite(a.sprite,b,c,{scale:.5}),null!=d.sprite&&this.r.drawSprite(d.sprite,b,c,{scale:.5}),b+=e+5*this.s};Z.prototype.charPos=function(a){return this.diary.transformSlotToScreen(a.eventPos)};Z.prototype.particlePos=function(a){null!=a.mounted&&(a=a.mounted);var b=this.diary.getImageScale();return new u(a.eventPos.x*b,a.eventPos.y*b)};Z.prototype.drawEnemies=
function(a,b){var c,d;this.r.ctx.globalAlpha=1;var e=null;var f=-1;var g=this.enemyDice;var h=d=0;for(c=g.length;d<c;h=++d)if(h=g[h],h=h.character,h.slot!==f){f=h.slot;null==h.eventPos&&(h.eventPos=this.diary.popEnemyImgSlot(config.imgSlot.enemy));var k=this.charPos(h);var l=this.r.img.getSprite(h.sprite);var m=$jscomp.makeIterator([l.dSize.w,l.dSize.h]);l=m.next().value;m=m.next().value;this.r.hitBox(k.x-l/2,k.y-m,l,m,a,b)&&this.canTarget(h)&&(this.mouseAction={id:"target",data:h},e=h);this.target===
h&&this.r.drawSprite("hud_cursor_target_1.png",k.x,k.y,{halign:"center",valign:"center"});l={halign:"center",valign:"bottom",health:h.health,maxHealth:h.maxHealth,offset:h.nudgeOffset,damageTime:h.damageTime,mirror:h.rightFacingSprite};this.r.drawCharacter(this.r.ctx,h,k.x,k.y,l)}return e};Z.prototype.drawShields=function(a,b){var c=this.diary.getImageCenter();var d=this.diary.getImageSize();var e=null;var f=$jscomp.makeIterator([c.x-d.w/3,c.y]);var g=f.next().value;f=f.next().value;this.drawShield(g,
f,this.shields.party,a,b)&&(e=this.shields.party);c=$jscomp.makeIterator([c.x+d.w/3,c.y]);g=c.next().value;f=c.next().value;this.drawShield(g,f,this.shields.enemy,a,b)&&(e=this.shields.enemy);if(null!=e)return this.infoBox.setInfo([{text:q.toText("txt-combat-shield")+": "+e.value+"/"+config.challenge.maxShield},{text:config.help.combat.shield,col:config.colors.help}])};Z.prototype.drawShield=function(a,b,c,d,e){var f=!1;0<c.hits&&(this.part.addParticleConf(config.particle.shieldDamage,(new u(a,b)).sub(this.diary.getImageOffset()),
{count:c.hits}),c.hits=0);.1>c.time&&(a+=Number.random(-3,3),b+=Number.random(-3,3));if(0<c.value||.5>c.time){0===c.value&&(this.r.ctx.globalAlpha=1-J.clamp(c.time/.5,0,1));var g={halign:"center",font:config.fonts.technicalLarge};d={halign:"center",valign:"center",mX:d,mY:e};f=this.r.drawSprite("hud_dice_shield.png",a,b,d);this.r.drawText(c.value,a,b,g)}return f};Z.prototype.drawHints=function(){if(this.isPartyRound){var a=this.getRollAreaCenter();if(this.hintPin&&!this.preRoll){var b=this.partyDice.filter(function(a){return a.hint});
if(0<b.length){var c=b.max(function(a){return a.anim.pos.x});if(null!=c&&!c.rolling)return b=a.x+c.anim.pos.x+10,a=a.y+c.anim.pos.y,this.r.drawHintBox(config.help.challengePin,b,a)}else if(null!=this.partyPattern)return this.hintPin=!1}else{if(this.hintAttack&&null!=this.partyPattern)return a=this.diary.getImageCenter(),this.r.drawHintBox(config.help.challengeAttack,a.x+50,a.y-120);if(this.hintRound&&0===this.rollsLeft&&null==this.partyPattern&&!this.partyDice.any(function(a){return a.rolling}))return this.r.drawHintBox(config.help.challengeRound,
a.x+50,a.y+260)}}};Z.prototype.drawButtons=function(a,b){var c;if(this.isPartyRound){var d=this.getRollAreaCenter();var e=null;this.r.ctx.font=config.fonts.technicalSmall;this.r.ctx.strokeStyle="white";this.r.ctx.fillStyle="white";var f=[];this.partyDice.any(function(a){return a.rolling})||(this.preRoll||f.push("accept"),this.preRoll&&f.push("cancel"));var g=80*this.s;var h=d.x-n.width(f.length,g,10)/2;var k=d.y+125*this.s;var l=this.enableRoundAction;var m=0;for(c=f.length;m<c;m++){d=f[m];a:{switch(d){case "accept":var p=
"txt-combat-endround";break a;case "cancel":p="txt-combat-flee";break a}p=void 0}var w=l?"white":"gray";this.r.drawActionPanel(q.toText(p),h,k-5,g,18*this.s,w,a,b)&&(l&&(e={id:d}),"cancel"===d&&this.infoBox.showHelp(config.help.combat.flee));h+=g+10}return e}};Z.prototype.drawTitle=function(){var a=this.getRollAreaCenter();var b=this.isPartyRound?1<this.rollsLeft?q.toText("txt-combat-rolls").replace("$val",this.rollsLeft):1===this.rollsLeft?q.toText("txt-combat-rolls1"):q.toText("txt-combat-rolls0"):
q.toText("txt-combat-enemyround");this.r.ctx.font=config.fonts.technicalLarge;return this.r.drawText(b,a.x,a.y-125*this.s,{halign:"center",os:0,fillColor:"#333"})};Z.prototype.drawDie=function(a,b,c,d,e){var f;var g=a.faceIdx;var h=$jscomp.makeIterator(config.imgSize.dice);var k=h.next().value;h=h.next().value;h=$jscomp.makeIterator([k*this.s,h*this.s]);k=h.next().value;h=h.next().value;this.r.ctx.font=config.fonts.technicalLarge;var l=!1;a.rolling?config.challenge.shakeTime[0]<=(f=a.rollTime)&&f<=
config.challenge.shakeTime[1]&&(g=a.randFace(),b+=Number.random(-6,6),c+=Number.random(-6,6)):a.hint&&!a.consumed&&(b+=Number.random(-1,1),c+=Number.random(-1,1));this.r.ctx.save();this.r.ctx.translate(Math.floor(b),Math.floor(c));this.r.ctx.globalAlpha=1;var m=a.destroyed?J.clamp(1-4*a.destroyTime,0,1):a.rolling?a.rollTime<=config.challenge.flyTime?1+Math.sin(Math.PI*a.rollTime/config.challenge.flyTime):1:a.consumed?.65:1;f={halign:"center",valign:"center"};this.r.ctx.scale(m,m);this.r.ctx.rotate(a.rot*
Math.PI/180);this.r.drawSprite(a.sprite,0,0,f);a.isStunned&&this.r.drawText(q.toText("txt-combat-stunned"),0,10*this.s,{font:config.fonts.technicalSmall,halign:"center"});a.pinned&&this.main.combatAutoSelect&&this.r.drawText(q.toText("txt-combat-keep"),0,20*this.s,{font:config.fonts.technicalLarge,halign:"center"});if(a.isEnemy||!this.preRoll)this.r.ctx.globalAlpha=a.consumed?.1:a.isStunned?.2:1,g=a.faces[g].sprite,0<(null!=g?g.length:void 0)&&this.r.drawSprite(g,0,0,f);this.r.ctx.restore();this.r.hitBox(b-
k/2,c-h/2,k,h,d,e)&&(l=!0);if(l||this.preRoll&&!a.isEnemy&&!a.rolling)null!=a.character?this.r.drawPortrait(a.character,b,c,{small:!0,scale:m,halign:"left",valign:"top"}):null!=a.item&&this.r.drawItem(a.item,b,c,{scale:1.25,showCount:!1});return l};Z.prototype.doQuickCheck=function(a){var b,c;var d=this.main.party.persons;var e=[];var f=0;for(a=d.length;f<a;f++){var g=d[f];e.push(function(){var a;var d=g.dice;var e=[];var f=0;for(a=d.length;f<a;f++)b=d[f],c=new Wa(b),e.push(c.roll(this.randDiePos([]),
0));return e}.call(this))}return e};var ha=function(a,b,c){this.drawDiary=this.drawDiary.bind(this);this.transformSlotToScreen=this.transformSlotToScreen.bind(this);this.drawHighlightPerson=this.drawHighlightPerson.bind(this);this.drawDiaryEventTexts=this.drawDiaryEventTexts.bind(this);this.drawDiaryEventActions=this.drawDiaryEventActions.bind(this);this.drawDiaryEventImage=this.drawDiaryEventImage.bind(this);this.fillDiaryAction=this.fillDiaryAction.bind(this);this.r=a;this.s=a.s;this.sfx=b;this.main=
c;this.party=this.main.party;this.showImage=null;this.imageAlpha=0;this.pages=[];this.storyDone=!0;this.isChatAllowed=!1;this.part=new qb(this.r,this.sfx);this.highlightPerson=null;this.idleAnim="";this.actions=[];this.campfireAlphaTarget=this.campfireAlpha=1;this.imageScale=new u(1,1);this.drawMapUnderDiary=!0;this.clearChatQueue()};ha.prototype.clearChatQueue=function(){this.chatQueue=[];return this.chatTime=0};ha.prototype.doAction=function(a){var b;if(!(a>this.actions.length-1)&&null==this.pendingActionIdx){if(null!=
this.main.tutorial){var c=this.main.tutorial.getFocusAction();if(null!=c&&c.none(a))return}var d=this.actions[a];if(0<(null!=d?d.reqDice.length:void 0)){c=this.getDicePersons(d);this.eventDice=this.main.challenge.getDice(c);this.main.challenge.preRoll=!1;this.main.challenge.rollDice(this.eventDice);c=this.main.challenge.getFaceCount(this.eventDice);var e=n.count(t.arrify(d.reqDice));var f=this.eventDice;var g=0;for(b=f.length;g<b;g++)d=f[g],d.success=0<e[d.getFace().id];this.pendingActionIdx=a;this.pendingActionTime=
0;return this.pendingActionWin=n.checkMatch(c,e)}return this.main.doAction(a)}};ha.prototype.setCombat=function(a){return this.isInCombat=a};ha.prototype.setBarter=function(a){return this.isInBarter=a};ha.prototype.addDiff=function(a){this.storyDone?(this.newPage(!0,a),this.storyDone=!1):this.pages.last().diffs.push(a);this.actions=t.arrify(a.actions);this.pendingActionIdx=null;return this.pendingActionTime=0};ha.prototype.newPage=function(a,b){a={diffs:[],day:b.day,newStory:void 0===a?!1:a};null!=
b&&a.diffs.push(b);this.pages.push(a);return this.thisPageDrawn=!1};ha.prototype.breakPage=function(){return this.storyDone=!0};ha.prototype.showChat=function(a,b,c,d){c=void 0===c?0:c;if(null!=a&&0!==a.length)return 0===this.chatQueue.length&&0===c&&(c=config.chat.eventChatDelay),this.chatQueue.push({person:b,text:a,delay:c,duration:void 0===d?null:d})};ha.prototype.tickDiary=function(a){var b;this.entryTime+=a;this.changeTime+=a;if(null!=this.pendingActionIdx){this.pendingActionTime+=a;if(1.5<this.pendingActionTime){var c=
this.eventDice;var d=0;for(b=c.length;d<b;d++){var e=c[d];e.success||e.destroy()}}4<this.pendingActionTime&&(this.main.doAction(this.pendingActionIdx,this.pendingActionWin),this.pendingActionIdx=null);c=this.eventDice;d=0;for(b=c.length;d<b;d++)e=c[d],e.tick(a)}if(null!=this.showImage){b=this.getImageSize();var f=this.showImage.particles;e=0;for(c=f.length;e<c;e++)d=f[e],this.part.addEmitter(d,new R(b.w,b.h/2));this.showImage.particles=[];c=this.showImage.characters;d=e=0;for(b=c.length;e<b;d=++e)d=
c[d],d.animTime+=a,d.isMember||d.tick(a);this.part.tickParticles(a);this.showImage.showCampfire&&(e=this.campfireAlphaTarget-this.campfireAlpha,0<e?this.campfireAlpha=Math.min(this.campfireAlphaTarget,this.campfireAlpha+a*config.campfire.speed):0>e?this.campfireAlpha=Math.max(this.campfireAlphaTarget,this.campfireAlpha-a*config.campfire.speed):this.campfireAlphaTarget=J.randA(config.campfire.alpha))}if(this.isChatAllowed&&(0<this.chatQueue.length&&0<this.chatQueue[0].delay&&(e=Math.min(a,this.chatQueue[0].delay),
this.chatQueue[0].delay-=e,a-=e),this.chatTime+=a,a="celebration"===this.main.getMainState()?4:0<this.chatQueue.length&&null!=this.chatQueue[0].duration?this.chatQueue[0].duration:config.chat.eventChatDuration,this.chatTime>a))return this.chatQueue.shift(),this.chatTime=0};ha.prototype.drawDiary=function(a,b,c,d,e,f,g,h,k){e=void 0===e?!1:e;g=void 0===g?0:g;h=void 0===h?0:h;k=void 0===k?!1:k;if(null!=this.r){var l=null;this.focusActionPosis=[];this.diaryScrollX=a;var m=this.getDiaryOffset().y;b&&
1>this.r.timeTotal%4&&(m-=10*Math.sin(4*Math.PI*this.r.timeTotal%4));1>J.clamp(4*d,0,1)&&(d=d*Math.PI*2/.5,0>d&&(d/=2),a+=25*Math.sin(d)*this.s);var p=m+25*this.s;d=this.drawDiaryEventImage(c,p,g,h);this.main.notifications.draw(g,h);this.r.ctx.globalAlpha=1;(this.isCelebration=f)?this.isChatAllowed=!0:(f=this.isInCombat?"hud_dice_bg.png":"hud_journal_bg.png",this.r.drawSprite(f,a,m),b||!c||this.isInCombat||this.isInBarter||(p=this.drawDiaryEventTexts(a,p,g,h),l=this.drawDiaryEventActions(e,a,p,g,
h,k),1<=this.r.ctx.globalAlpha&&(this.isChatAllowed=!0),this.showPartyCount&&(a=this.getDiaryCenter(),b=q.toText("txt-base-trekcount")+": "+this.party.unitCount+" / "+this.party.maxUnitCount,this.r.drawText(b,a.x,a.y+130*this.s,{halign:"center",fillColor:"black",os:0}))));this.drawActionInfo();this.drawDice(g,h);this.drawChat();return[l,d]}};ha.prototype.drawActionInfo=function(){var a;if(null!=this.actionInfo){var b=(config.diary.textWidth+5)*this.s;var c=$jscomp.makeIterator([110*this.s,16*this.s*
this.actionInfo.dice.length+16*this.s]);var d=c.next().value;var e=c.next().value;var f=$jscomp.makeIterator([this.actionInfo.x,this.actionInfo.y+24*this.s]);c=f.next().value;f=f.next().value;var g=$jscomp.makeIterator(config.imgSize.dice);var h=g.next().value;g=g.next().value;g=$jscomp.makeIterator([h*this.s*.5,g*this.s*.5]);h=g.next().value;g.next();g={halign:"center",fillColor:"white",os:0};if(0<this.actionInfo.dice.length){this.r.drawInfoBox(this.actionInfo.x+b/2-d/2,this.actionInfo.y+10*this.s,
d,e);this.r.drawText(q.toText("txt-base-yourdice"),this.actionInfo.x+b/2,this.actionInfo.y+20*this.s,g);var k=this.actionInfo.dice;var l=[];var m=0;for(e=k.length;m<e;m++){b=k[m];var p=b.faces.split(" ");d=a=0;for(g=p.length;a<g;d=++a){var n=p[d];n=t.getDieFace(n);this.r.drawSprite(b.sprite,c+53*this.s+d*(h+3*this.s),f,{scale:.5});null!=n.sprite&&this.r.drawSprite(n.sprite,c+53*this.s+d*(h+3*this.s),f,{scale:.5})}l.push(f+=16*this.s)}return l}this.r.drawInfoBox(this.actionInfo.x+b/2-d/2,this.actionInfo.y+
10*this.s,d,16*this.s);c=q.toText("txt-base-nodice");return this.r.drawText(c,this.actionInfo.x+b/2,this.actionInfo.y+20*this.s,g)}};ha.prototype.drawDice=function(a,b){var c;if(null!=this.pendingActionIdx){var d=this.main.challenge.getRollAreaCenter();var e=this.eventDice;var f=0;for(c=e.length;f<c;f++){var g=e[f];var h=d.x+g.anim.pos.x;var k=d.y+g.anim.pos.y;this.main.challenge.drawDie(g,h,k,a,b)}}};ha.prototype.getDiaryOffset=function(){var a;if("iosplash"===(a=this.main.getMainState())||"ionewgame"===
a||"iopromote"===a)return new u(0,0);a=$jscomp.makeIterator(this.r.getCanvasSize());a.next();a=a.next().value;a=Math.max(a/2-this.r.img.getSprite("hud_journal_bg.png").dSize.h/2,0);return new u(Math.floor(this.diaryScrollX),Math.floor(a))};ha.prototype.getDiarySize=function(){var a;return"iosplash"===(a=this.main.getMainState())||"ionewgame"===a||"iopromote"===a?new R(0,0):new R(this.r.img.getSprite("hud_journal_bg.png").dSize.lst())};ha.prototype.getDiaryCenter=function(){var a=this.getDiaryOffset();
var b=this.getDiarySize();return new u(a.x+b.w/2,a.y+b.h/2)};ha.prototype.getImageOffset=function(){var a;var b=$jscomp.makeIterator(this.r.getCanvasSize());var c=b.next().value;b=b.next().value;var d=$jscomp.makeIterator([this.showImage.img.width,this.showImage.img.height]);var e=d.next().value;d=d.next().value;if("iosplash"===(a=this.main.getMainState())||"ionewgame"===a||"iopromote"===a)return a=this.getImageScale(),e=$jscomp.makeIterator([e*a,d*a]),a=e.next().value,e=e.next().value,new u(c/2-
a/2,b/2-e/2);b=$jscomp.makeIterator([e*this.s,d*this.s]);a=b.next().value;b.next();c=this.isCelebration?c/2-a/2:c/2-a*config.diary.imageOffsetX;b=this.getDiaryOffset().y+25*this.s;return new u(c,b)};ha.prototype.getImageScale=function(){var a;var b=$jscomp.makeIterator([this.showImage.img.width,this.showImage.img.height]);var c=b.next().value;b=b.next().value;if("iosplash"===(a=this.main.getMainState())||"ionewgame"===a||"iopromote"===a)return a=$jscomp.makeIterator(this.r.getCanvasSize()),a.next(),
a=a.next().value,a/b;a=$jscomp.makeIterator([c*this.s,b*this.s]);a.next();return a.next().value/b};ha.prototype.getImageSize=function(){return new R(this.showImage.img.width*this.s,this.showImage.img.height*this.s)};ha.prototype.transformSlotToScreen=function(a){n.assert(null!=a);var b=this.getImageScale();var c=this.getImageOffset();return(new u(a.x*b,a.y*b)).add(c)};ha.prototype.getImageCenter=function(){var a=this.getImageOffset();var b=this.getImageSize();return new u(a.x+b.w/2,a.y+b.h/2)};ha.prototype.drawChat=
function(a){var b,c;if(null!=this.showImage&&null!=this.r&&this.isChatAllowed&&0!==this.chatQueue.length&&!(0>this.chatTime)){var d=this.chatQueue.first();if(!(0<d.delay)&&null!=d.person){var e=d.person;if(this.showImage.characters.any(e)){a=this.transformSlotToScreen(e.eventPos);var f=this.getImageScale();var g=a.x+config.chat.eventChatOffset[0]*f;a=a.y+config.chat.eventChatOffset[1]*f;this.showImage.showMounted&&null!=e.riding&&(a-=8*f);this.r.ctx.globalAlpha=1;this.r.ctx.font=config.fonts.themedSmall;
if(d.text.includes("$")||d.text.includes("_")){var h=this.main.events.prepareWords(d.text,[[d.person]],0);d.text="";e=c=0;for(f=h.length;c<f;e=++c){var k=h[e];d.text+=k.text;e<h.length-1&&"."!==(b=h[e+1].text)&&"!"!==b&&":"!==b&&";"!==b&&"'"!==b&&","!==b&&(d.text+=config.diaryText.separator);k.forceSpace&&(d.text+=" ")}}return this.r.drawChatPanel(d.text,g,a,{width:250*this.s,halign:"center",valign:"bottom"})}}}};ha.prototype.drawHighlightPerson=function(a,b){if(null!=this.highlightPerson){var c=
{xp:this.party.xp,showActions:!1,hoverMarginN:20*this.s,hoverMarginW:70*this.s};a=this.r.drawCharacterInfo(this.highlightPerson.person,this.highlightPerson.lineX,this.highlightPerson.lineY+10*this.s,a,b,c);if(null==a)return this.highlightPerson=null}};ha.prototype.drawDiaryEventTexts=function(a,b,c,d){var e,f,g,h,k,l;var m=a+=config.diary.offsetX*this.s;var p=!0;var n=b;var t=this.pages.last();var r=new R(config.diaryText.margin);var v=t.diffs.last();var y=null;this.r.ctx.font=config.fonts.themedSmall;
t.newStory&&0<t.day&&(this.r.ctx.fillStyle=config.colors.diaryTextDefault,this.r.ctx.fillText(q.toText("txt-base-day")+" "+t.day,m+204*this.s,n,{halign:"right"}),n+=15*this.s);this.textDelay=0;var Y=t.diffs;var A=l=0;for(e=Y.length;l<e;A=++l){b=Y[A];var H=b.lines;var G=0;for(f=H.length;G<f;G++){var u=H[G];m=p?0:config.diary.indentationOffsetX;this.main.getLangId().startsWith("zh")&&(m*=2);p=!1;var T=0;for(g=u.length;T<g;T++){var x=u[T];var B=-1<config.diaryText.nonBreaking.indexOf(x.text[0]);!B&&
m+x.width>config.diary.textWidth*this.s&&(m=0,n+=r.h*this.s);if(b===v){var C=((this.entryTime-this.textDelay)/.5).clamp(0,1);A===t.diffs.length-1&&(this.textDelay=B?this.textDelay+.25:this.textDelay+.1)}B=a+m<c&&c<a+m+x.width&&n-15*this.s<d&&d<n+5*this.s;0<C&&null!=x.person&&B&&(y={person:x.person,text:!0,lineX:Math.max(10,a+m+x.width/2-100*this.s),lineY:n});this.r.ctx.fillStyle=x.highlight?config.colors.diaryTextHighlight:null==x.person?config.colors.diaryTextDefault:x.person===(null!=(h=this.highlightPerson)?
h.person:void 0)?config.colors.diaryTextPersonActive:config.colors.diaryTextPerson;!(k=x.text[0],0<=F.call("!?.,:'",k))&&0<m&&(m=x.forceSpace?m+config.diaryTextLangs.latin.margin[0]*this.s:m+r.w*this.s);this.r.ctx.globalAlpha=C;this.r.ctx.fillText(x.text,m+a,n);m+=x.width}n+=r.h*this.s;A===t.diffs.length-1&&(this.textDelay+=1.2)}}null!=y&&(null==this.highlightPerson||d<this.highlightPerson.lineY)&&(this.highlightPerson=y);return n};ha.prototype.drawDiaryEventActions=function(a,b,c,d,e,f){var g,h,
k,l;var m=config.diary.offsetX*this.s;var p=null;var n=this.pages.last();n.diffs.last().lines.sum(function(a){return a.length});n=n.diffs.last();this.actionInfo=null;0!==this.actions.length||a||this.actions.push({name:q.toText("txt-base-continue"),canDo:!0,actionIdx:-1,reqDice:[]});a=!0;var t=this.actions;var r=l=0;for(g=t.length;l<g;r=++l){var v=t[r];var y=$jscomp.makeIterator([b+m,c+20]);var Y=y.next().value;y=y.next().value;var A=((this.entryTime-.2*r-this.textDelay)/.5).clamp(0,1);if(1>A||1>this.r.ctx.globalAlpha)a=
!1;this.r.ctx.globalAlpha=A;this.r.ctx.font=config.fonts.themedSmall;if(0===this.r.ctx.globalAlpha||null!=this.highlightPerson)e=$jscomp.makeIterator([0,0]),d=e.next().value,e=e.next().value;if(A=this.fillDiaryAction(r,v,Y,y,d,e,f))p=null!=(h=v.actionIdx)?h:r,v.showPersonInfo&&(this.highlightPerson={person:v.person,text:!1,lineX:Y+190*this.s,lineY:y-75*this.s});r=null!=(k=0<Object.size(v.reqItems)&&v.showReqItems)?k:!0;v=0<v.reqDice.length||r;c+=v?26*this.s:23*this.s}!this.thisPageDrawn&&a&&(this.thisPageDrawn=
!0,this.main.outputDiaryLog=!0);725<c&&this.newPage(!1,n);return p};ha.prototype.drawDiaryEventImage=function(a,b,c,d){var e,f;var g=$jscomp.makeIterator(this.r.getCanvasSize());b=g.next().value;g=g.next().value;var h=(3*this.changeTime).clamp(0,1);a||(h=1-h);this.imageAlpha=h;1<=this.imageAlpha&&(this.drawMapUnderDiary=!0);if(!(0>=h))if(this.r.ctx.globalAlpha=h,null==this.showImage)this.r.ctx.save(),this.r.ctx.fillStyle="black",this.r.ctx.fillRect(0,0,b,g),this.r.ctx.restore();else{h=$jscomp.makeIterator([this.showImage.img.width,
this.showImage.img.height]);a=h.next().value;var k=h.next().value;h=$jscomp.makeIterator([a*this.s,k*this.s]);var l=h.next().value;var m=h.next().value;var p=$jscomp.makeIterator(this.getImageOffset().lst());h=p.next().value;p=p.next().value;this.r.setImageSmoothing(!1);"iosplash"===(f=this.main.getMainState())||"ionewgame"===f||"iopromote"===f?(b=this.getImageScale(),f=this.getImageOffset(),this.r.ctx.drawImage(this.showImage.img,0,0,a,k,f.x,f.y,a*b,k*b)):(this.r.ctx.drawImage(this.showImage.bgImg,
0,0,a,k,0,0,b,g),this.r.ctx.save(),this.r.ctx.beginPath(),this.r.ctx.rect(h,p,l,m),this.r.ctx.clip(),this.r.ctx.drawImage(this.showImage.img,0,0,a,k,h,p,l,m));c=this.drawCharacters(c,d);this.part.drawParticles(!1,new u(h,p));this.r.ctx.restore();if(debug.debugImageSlots)for(e in f=this.showImage.img.slots,f)for(b=f[e],g=0,d=b.length;g<d;g++)a=b[g],a=this.transformSlotToScreen(a),this.r.drawText(e[0],a.x,a.y);return c}};ha.prototype.drawCharacters=function(a,b){var c;var d=this.getImageScale()/this.s;
if(this.showImage.showCampfire&&null!=this.showImage.slots.campfire){var e=this.transformSlotToScreen(t.arrify(this.showImage.slots.campfire)[0]);if(null!=e){this.r.ctx.globalAlpha=this.campfireAlpha;var f=$jscomp.makeIterator([e.x,e.y]);var g=f.next().value;f=f.next().value;this.r.drawSprite("evt_spec_nightCamp_lighting.png",g+3*this.s,f+4*this.s,{halign:"center",valign:"center",scale:d});this.r.ctx.globalAlpha=1}}g=null;var h=this.showImage.characters;var k=0;for(f=h.length;k<f;k++){var l=h[k];
if(!this.showImage.showMounted||null==l.mounted){var m=this.transformSlotToScreen(l.eventPos);null!=e&&e.y<m.y&&(this.drawCampfireAnim(e),e=null);if(!l.isMember)switch(this.idleAnim){case "happy":l.animTime>l.jumpTime&&(l.nudge(new u(0,-10)),l.animTime=0,l.jumpTime=J.randA(config.celebration.happyJumpDelay));break;case "veryHappy":l.animTime>l.jumpTime&&(l.nudge(new u(0,-20)),l.animTime=0,l.jumpTime=J.randA(config.celebration.veryHappyJumpDelay));break;case "nervous":m.x+=Math.sin(5*l.animTime+m.x),
m.y+=Math.cos(3*l.animTime+m.x)}var p=this.main.diaryPersonHover;p=l===p||l.riding===p?2:0;this.isInCombat&&(l.mirrored=!1);l=this.showImage.showMounted?null!=(c=l.riding)?c:l:l;m=this.r.drawCharacter(this.r.ctx,l,m.x,m.y+p,{mX:a,mY:b,showHealth:this.isInCombat&&l.hasHealth(),valign:"bottom",halign:"center",offset:l.nudgeOffset,drawMount:this.showImage.showMounted?l.mounted:null,scale:d});null==g&&(g=m)}}null!=e&&this.drawCampfireAnim(e);return g};ha.prototype.drawCampfireAnim=function(a){var b=this.getImageScale();
var c=$jscomp.makeIterator([a.x,a.y]);a=c.next().value;var d=c.next().value;c=Math.floor(this.entryTime/config.campfire.frameDelay%17);var e=this.r.img.campfire;var f=$jscomp.makeIterator([e.width/17,e.height]);var g=f.next().value;f=f.next().value;this.r.ctx.globalAlpha=1;n.assert(null!=e);return this.r.ctx.drawImage(e,c*g,0,g,f,a-g*b/2,d-f*b/2-52*b,g*b,f*b)};ha.prototype.popEnemyImgSlot=function(a){n.assert(null!=this.showImage,"Unknown event image");var b=this.showImage.slots[a];if(null==b)return new u(0,
0);a=b.min(function(a){return a.x});if(null==a)return new u(0,0);b.remove(a);return a};ha.prototype.setIdleAnim=function(a){var b;this.idleAnim=a;var c=this.showImage.characters;var d=0;for(b=c.length;d<b;d++){var e=c[d];switch(a){case "happy":e.animTime=0;e.jumpTime=.1*J.randA(config.celebration.happyJumpDelay);break;case "veryHappy":e.animTime=0,e.jumpTime=.1*J.randA(config.celebration.veryHappyJumpDelay)}}};ha.prototype.getDicePersons=function(a){return this.party.persons};ha.prototype.fillDiaryAction=
function(a,b,c,d,e,f,g){var h,k,l,m;var p=!1;var w=a+1+". "+b.name;var q=b.canDo;if(null!=this.main.tutorial){var r=this.main.tutorial.getFocusAction();null!=r&&(r.any(a)&&0<this.r.ctx.globalAlpha?this.focusActionPosis.push(new u(c+100*this.s,d-3*this.s)):q=!1)}if(null!=this.pendingActionIdx)a=a===this.pendingActionIdx?.6<this.pendingActionTime?this.pendingActionWin?"green":"red":config.colors.diaryActionActive:"gray";else if(q){if(a=config.colors.diaryAction,(null==(m=this.highlightPerson)||!m.text)&&
this.r.hitBox(c,d-12*this.s,200*this.s,18*this.s,e,f)&&(p=!0,a=config.colors.diaryActionActive,0<b.reqDice.length)){f=this.getDicePersons(b);e=[];r=this.party.getDice(f);var v=0;for(m=r.length;v<m;v++){f=r[v];var y=b.reqDice;var Y=0;for(q=y.length;Y<q;Y++){var A=y[Y];if(f.faces.split(" ").any(A)){e.push(f);break}}}this.actionInfo={x:c,y:d,action:b,dice:e}}}else a=config.colors.diaryActionInvalid;this.r.ctx.fillStyle=a;f=d-12*this.s;e=(config.diary.textWidth+5)*this.s;a=17*this.s;p&&g&&(d+=2,f+=2);
this.r.drawPanel(config.panel.action,c,f,e,a);this.r.ctx.fillText(w,c+14*this.s,d);g=null!=(h=b.reqItems)?h:{};if(null!=(l=b.showReqItems)?l:1)for(k in g)w=g[k],l=t.getItem(k),n.assert(null!=l,"Unknown item "+k),h=15*this.s,this.r.ctx.fillStyle="#422406",this.r.ctx.fillRect(c+160*this.s-4,d-h-2,24*this.s,24*this.s),this.r.ctx.fillStyle="#111",this.r.ctx.fillRect(c+160*this.s-2,d-h,22*this.s,23*this.s),a=$jscomp.makeIterator(n.parseRange(w)),w=a.next().value,a.next(),this.r.drawItem(l,c+160*this.s,
d-h,{amount:w,showDecorator:!1}),c-=25*this.s;g=b.reqDice;b=0;for(k=g.length;b<k;b++)w=g[b],l={scale:.75},h=15*this.s,this.r.ctx.fillStyle="#422406",this.r.ctx.fillRect(c+158*this.s,d-h-2,24*this.s,24*this.s),this.r.ctx.fillStyle="#111",this.r.ctx.fillRect(c+160*this.s,d-h,22*this.s,23*this.s),w=t.getDieFace(w),this.r.drawSprite(w.bgSprite,c+160*this.s,d-h+2,l),null!=w.sprite&&this.r.drawSprite(w.sprite,c+160*this.s,d-h+2,l),c-=25*this.s;return p};var va=function(a,b,c){c=W.call(this,a,b,c)||this;
c.drawPersonRank=c.drawPersonRank.bind(c);c.party=c.main.party;c.part=new qb(a,b);c.speedup=!1;return c};$jscomp.inherits(va,W);va.prototype.addRivalFame=function(){var a,b;var c=this.main.rivals.map(function(a){return a.arrivedTurn}).add(this.party.stats.turns).sortBy();var d=this.main.rivals;var e=[];var f=0;for(b=d.length;f<b;f++){var g=d[f];var h=a=g.fameScale*J.randIntA(config.rivals.fame);h+=this.main.worldLvl*config.rivals.worldBonus;h+=config.rivals.rewards[c.findIndex(g.arrivedTurn)];h=Math.round(h);
g.itemFame=Math.round(a);g.newFame=h;e.push(g.fame+=g.newFame)}return e};va.prototype.show=function(){var a,b,c,d,e,f,g;var h=$jscomp.makeIterator(this.r.getCanvasSize());var k=h.next().value;h=h.next().value;this.addRivalFame();this.spotlightIdx=-1;this.speedup=!1;this.persons=function(){var a;var c=this.main.rivals;var e=[];var h=0;for(a=c.length;h<a;h++){f=c[h];d=t.getItemList("il-rival-items");b=this.main.randItemSet(d.items.sample());b=b.remove(function(a){return 0===a.fame});for(g=b.sum(function(a){return a.getValue("base",
!1)});g>f.itemFame;)b=b.remove(b.sample()).compact(),g=b.sum(function(a){return a.getValue("base",!1)});r.info("RIVAL;"+f.character.name+" - itemFame: "+f.itemFame+", items: "+g+", diff: "+(f.itemFame-g));e.push({rival:!0,pers:f.character,fame:f.fame-f.newFame,queuedFame:f.newFame,queuedFunds:0,items:b,done:!1})}return e}.call(this);this.persons=this.persons.sortBy(function(a){return a.queuedFame},!0);var l=null!=(a=this.party.newFame)?a:0;this.specialist={rival:!1,pers:this.party.getExplorer(),fame:this.party.fame-
l,queuedFame:l,queuedFunds:0,done:!0,items:[]};this.persons.push(this.specialist);this.sortPersons();this.items=[];var m=this.main.outroItems;var p=0;for(c=m.length;p<c;p++){l=m[p];var n=0;for(e=l.amount;0<=e?n<e:n>e;0<=e?++n:--n)a=new tb,a.pos=new u(k/2,h/2),this.items.push({item:l,anim:a})}this.updateItemSockets();this.time=0;this.houses={gift:{time:0,chat:null,chats:"txt-museum",particle:config.particle.rankingFame,pos:new u(-250*this.s,30*this.s),sprite:"hud_char_museum.png"},sell:{time:0,chat:null,
chats:"txt-auction",particle:config.particle.rankingMoney,pos:new u(250*this.s,30*this.s),sprite:"hud_char_auction.png"}};this.updateSpotlight();this.main.stopMusic(!0);this.sfx.fadeOut("celebrationMusic");return this.sfx.play("clubMusic",!0)};va.prototype.playHouse=function(a){var b=$jscomp.makeIterator(this.r.getCanvasSize());var c=b.next().value;b=b.next().value;a=this.houses[a];if(null!=a)return a.time=0,a.chat=q.parse(a.chats),c=new u(a.pos.x+c/2,a.pos.y+b/2),this.part.addParticleConf(a.particle,
c)};va.prototype.drawHouse=function(a){var b=$jscomp.makeIterator(this.r.getCanvasSize());var c=b.next().value;b=b.next().value;a=this.houses[a];var d=.2<a.time?1:1.1;c=a.pos.x+c/2;b=a.pos.y+b/2;this.r.drawSprite(a.sprite,c,b,{halign:"center",scale:d});if(null!=a.chat&&2>a.time)return this.r.drawChatPanel(a.chat,c,b-5*this.s,{width:120*this.s,halign:"center",valign:"bottom"})};va.prototype.sortPersons=function(){var a,b;var c=$jscomp.makeIterator(this.r.getCanvasSize());c.next();c=c.next().value;
var d=this.persons.sortBy(function(a){return a.fame},!0);var e=[];var f=b=0;for(a=d.length;b<a;f=++b){var g=d[f];g.targetY=c/2-130*this.s+35*this.s+20*f*this.s;e.push(null!=g.y?g.y:g.y=g.targetY)}return e};va.prototype.updateSpotlight=function(){this.spotlightTime=0;this.spotlightIdx+=1;this.persons[this.spotlightIdx]===this.specialist&&(this.spotlightIdx+=1);if(this.spotlightIdx>=this.persons.length)return this.sortPersons()};va.prototype.updateItemSockets=function(){var a,b;var c=$jscomp.makeIterator(this.r.getCanvasSize());
c.next();c.next();var d=this.items.exclude(function(a){return null!=a.action});var e=[];var f=b=0;for(a=d.length;b<a;f=++b)c=d[f],f=0===f?(new u(-10,45)).mul(this.s):(new u(30*f,100)).mul(this.s),e.push(c.anim.interpTo(f,1));return e};va.prototype.shiftOutroItem=function(){return this.items.shift()};va.prototype.sellOutroItem=function(){var a=$jscomp.makeIterator(this.r.getCanvasSize());a.next();a.next();a=this.items.exclude(function(a){return null!=a.action}).first();if(null!=a)return a.anim.interpTo(this.houses.sell.pos.add(new u(0,
30)),1),a.queuedFame=0,a.queuedFunds=a.item.getFunds(),this.main.achievements.incCounter("ach-sell-funds",a.item.getFunds()),a.action="sell",a.actionTime=0,this.party.incStatRankingSell(a.item.id),this.party.setFlags("+soldItem"),this.updateItemSockets()};va.prototype.giftOutroItem=function(){var a=$jscomp.makeIterator(this.r.getCanvasSize());a.next();a.next();a=this.items.exclude(function(a){return null!=a.action}).first();if(null!=a)return a.anim.interpTo(this.houses.gift.pos.add(new u(0,30)),1),
a.queuedFame=a.item.getFame(),a.queuedFunds=0,this.main.achievements.incCounter("ach-sell-fame",a.item.getFame()),a.action="gift",a.actionTime=0,this.party.incStatRankingGift(a.item.id),this.updateItemSockets()};va.prototype.keepOutroItem=function(){var a=$jscomp.makeIterator(this.r.getCanvasSize());var b=a.next().value;a=a.next().value;var c=this.items.exclude(function(a){return null!=a.action}).first();if(null!=c)return c.anim.interpTo(new u(b/2,a),1),c.queuedFame=0,c.queuedFunds=0,c.action="keep",
c.actionTime=0,this.party.inv.changeItemCount(c.item,1),this.party.incStatRankingKeep(c.item.id),this.updateItemSockets()};va.prototype.tick=function(a){var b,c,d;this.speedup&&(a*=5);this.time+=a;this.part.tickParticles(a);this.spotlightTime+=a;var e=this.persons;var f=d=0;for(b=e.length;d<b;f=++d){var g=e[f];g.y+=(g.targetY-g.y)*a*5;f<=this.spotlightIdx&&(0<g.queuedFame&&(f=g.queuedFame*a,g.queuedFame-=f,g.fame+=f),0<g.queuedFunds&&(f=g.queuedFunds*a,g.queuedFunds-=f,g.funds+=f))}2.5<this.spotlightTime&&
this.updateSpotlight();e=this.items;d=0;for(g=e.length;d<g;d++)b=e[d],b.anim.tick(a),null!=b.action&&(b.actionTime+=a,.5<b.actionTime&&(this.playHouse(b.action),b.action="done",this.specialist.queuedFame+=b.queuedFame,this.specialist.queuedFunds+=b.queuedFunds,this.party.fame+=b.queuedFame,this.party.funds+=b.queuedFunds));g=this.houses;for(c in g)b=g[c],b.time+=a;this.items.remove(function(a){return"done"===a.action});if(n.isDemo()&&null==this.persons[this.spotlightIdx]&&0<this.items.count(function(a){return null==
a.action})&&1<this.spotlightTime)return this.spotlightTime=0,this.giftOutroItem()};va.prototype.drawPanel=function(a,b,c){var d;var e=$jscomp.makeIterator(this.r.getCanvasSize());var f=e.next().value;e=e.next().value/2-140*this.s;this.r.drawPanel(config.panel.info,f/2-a/2,e,a,150*this.s);f=f/2-(a-80*this.s)/2;var g=a-130*this.s;this.r.ctx.fillStyle=config.colors.personInfoBorder;this.r.ctx.fillRect(f,e+20*this.s,g,5*this.s);for(d=b+10-b%10;d<=c;)a=(d-b)/(c-b),0===d%50?(this.r.drawText(d,f+g*a+2,e+
16*this.s,{halign:"center",font:config.fonts.technicalSmall,fillColor:"black",shadowColor:"white"}),this.r.ctx.fillStyle="red"):this.r.ctx.fillStyle="black",this.r.ctx.fillRect(f+g*a,e+20*this.s,2*this.s,8*this.s),d+=10};va.prototype.draw=function(a,b,c){var d,e;var f=$jscomp.makeIterator(this.r.getCanvasSize());var g=f.next().value;f=f.next().value;1<this.time&&c&&(this.speedup=!0);this.r.setImageSmoothing(!1);this.r.drawNarratorBackground();var h=this.persons.max(function(a){return a.fame}).fame;
var k=this.persons.min(function(a){return a.fame}).fame;var l=Math.min(600*this.s,g-50*this.s);this.drawPanel(l,k,h);var m=this.persons;var p=e=0;for(d=m.length;e<d;p=++e){var w=m[p];this.drawPersonRank(w,p,k,h,l,a,b)}p=this.persons[this.spotlightIdx];if(null!=p)for(this.r.ctx.font=config.fonts.themedLarge,this.r.drawText(p.pers.name,g/2,f/2+50*this.s,{halign:"center"}),a=q.toText("txt-ranking-home"),this.r.drawText(a,g/2,f/2+70*this.s,{halign:"center"}),a=32*this.s,g=g/2-p.items.length/2*a,f-=f/
4,d=p.items,p=h=0,c=d.length;h<c;p=++h)b=d[p],this.r.drawItem(b,g+p*(a+10*this.s),f,{showDecorator:!1,showCount:!1,scale:Math.min(1,2*this.spotlightTime-.2*p)});else{this.speedup=!1;this.r.drawSprite("hud_pillow.png",g/2,f/2+60*this.s,{halign:"center"});l=this.items;p=d=0;for(k=l.length;d<k;p=++d)h=l[p],p=null==h.action?0===p?1+.5*h.anim.interpBlendTime:1:1.5-2*h.anim.interpBlendTime,w=g/2+h.anim.pos.x,m=f/2+h.anim.pos.y,(p=this.r.drawItem(h.item,w,m,{showDecorator:!1,showCount:!1,scale:p,mX:a,mY:b}))&&
this.main.infoBox.showItem(h.item,!0);k=["sell","gift"];d=0;for(h=k.length;d<h;d++)p=k[d],this.drawHouse(p);p=this.items.first();null!=p&&(this.r.ctx.font=config.fonts.technicalLarge,d=q.toText("txt-base-fame"),this.r.drawText(d+": +"+p.item.getFame(),g/2+this.houses.gift.pos.x,75*this.s+f/2+this.houses.gift.pos.y,{halign:"center"}),d=q.toText("txt-base-funds"),this.r.drawText(d+": +"+p.item.getFunds(),g/2+this.houses.sell.pos.x,75*this.s+f/2+this.houses.gift.pos.y,{halign:"center"}));this.part.drawParticles(!0);
l=0<this.items.count(function(a){return null==a.action})?n.isDemo()?[]:[{id:"gift",txt:"txt-ranking-gift"},{id:"keep",txt:"txt-ranking-keep"},{id:"sell",txt:"txt-ranking-sell"}]:[{id:"continue",txt:"txt-base-continue"}];this.r.ctx.strokeStyle="yellow";h=n.width(l.length,60,70)*this.s;p=w=0;for(m=l.length;w<m;p=++w)k=l[p],d=q.toText(k.txt),this.r.drawButton(d,g/2-h/2+140*p*this.s+25*this.s,f/2+140*this.s,100*this.s,30*this.s,a,b,c)&&(this.mouseAction=k.id)}return this.r.drawFameFunds(this.main.worldLvl,
this.party.fame,this.party.funds)};va.prototype.drawPersonRank=function(a,b,c,d,e,f,g){B(this,va);var h=$jscomp.makeIterator(this.r.getCanvasSize());var k=h.next().value;h.next();q.rank(b);b=a.fame;e-=130*this.s;c=e*Math.max(.02,(b-c)/(d-c));d=k/2-e/2+c-25*this.s;h=a.y;this.r.ctx.fillStyle="brown";this.r.ctx.fillRect(k/2-e/2-25*this.s,h,c,4*this.s);this.r.ctx.fillStyle="white";this.r.ctx.fillRect(k/2-e/2-25*this.s,h+2,c,2*this.s);this.r.drawPortrait(a.pers,d,h,{valign:"center",small:!0,mX:f,mY:g})&&
this.main.infoBox.showHelp([a.pers.name,a.pers.description]);return this.r.drawText(Math.round(b),d+17*this.s,h+4*this.s,{font:config.fonts.technicalLarge,fillColor:a.rival?"white":"orange"})};va.prototype.onMouseClick=function(a){switch(this.mouseAction){case "gift":return this.giftOutroItem();case "sell":return this.sellOutroItem();case "keep":return this.keepOutroItem();case "continue":this.main.doEvent(t.getEvent(config.specialEvents.expeditionUnlocks),{silent:!0});if(n.isDemo())return this.main.gotoCelebration();
if(this.main.hasCampaign())return this.main.doSendStats(),this.main.gotoNextWorld();this.main.hasExtraCampaign();this.main.gotoEpilogue();return this.main.doSendStats()}};var wa=function(a,b,c){a=W.call(this,a,b,c)||this;a.usedLocations=[];a.worldMapSeed=0;return a};$jscomp.inherits(wa,W);wa.prototype.show=function(){var a,b;this.party=this.main.party;this.time=0;this.usedLocations=[];null==this.sites&&(this.worldMapSeed=null==debug.testPocketSeed||0===debug.testPocketSeed?Date.now():debug.testPocketSeed,
ba.rng=new pa(this.worldMapSeed),this.createSites(),this.createRivalSites());r.info("WORLDMAP;seed:"+this.worldMapSeed+" worldLvl:"+this.main.worldLvl+" difficulty:"+this.main.difficultyLvl);var c=this.sites;var d=0;for(a=c.length;d<a;d++){var e=c[d];var f=t.getPocket(e.gen.pocketId);var g=t.getGoal(e.gen.goalId);e.description=[q.parse(null!=(b=g.description)?b:"")];e.slotMarker=f.slotMarker;e.locations=e.gen.getQueuedLocations().groupBy("worldMap")}this.worldSelection=this.sites[0];if(null!=debug.testPocket&&
null!=this.worldSelection)return this.prepareWorld()};wa.prototype.tick=function(a){return this.time+=a};wa.prototype.createSite=function(a,b,c){var d=this,e,f,g;var h=t.getPocket(c);if(null!=h){var k=this.r.img.getSpriteSlots("hud_worldmap.png");var l=k[h.id];if(null==l||0===l.length)l=k["pck-grass"];k=l.filter(function(a){return d.usedLocations.none(function(b){return 30>b.dist(a)})});l=0<k.length?k.worldGenSample():null!=(e=l.worldGenSample())?e:new u(0,0);this.usedLocations.push(l);if(null!=debug.testGoal)var m=
t.getGoal(debug.testGoal);else{k=t.arrify(h.goals).worldGenRandomize();var p=0;for(e=k.length;p<e&&(m=k[p],m=t.getGoal(m),null==m||!n.match(null!=(f=m.reqDifficulty)?f:"..",this.main.difficultyLvl)||!n.match(null!=(g=m.reqWorld)?g:"..",this.main.worldLvl));p++);}n.assert(null!=m||null!=debug.testPocket,"No valid goal found!");if(null==m)if(m=config.goals[0],null!=m)r.warn("No valid goal found for site with seed "+a+" and pocket "+c+"; falling back to "+m.id);else return r.warn("No valid goal found for site with seed "+
a+" and pocket "+c+"; cancelling"),null;return{location:l,name:q.parse("txt-world-adjective")+" "+q.toText(h.name),gen:new ba(this.main,b.id,h.id,m.id,!1,a)}}};wa.prototype.createRivalSites=function(){var a=t.getWorld(this.main.getExpeditionWorld(this.main.worldLvl));var b=this.main.rivals;var c=[];var d=0;for(b=b.length;d<b;d++)c.push(this.createSite(ba.rng.next(),a,t.arrify(a.pockets).worldGenSample(),0<this.main.worldLvl&&.2>ba.rng.random()));this.rivalSites=c;return this.rivalSites=this.rivalSites.compact()};
wa.prototype.createSites=function(){var a=this,b,c,d;var e=t.getWorld(this.main.getExpeditionWorld(this.main.worldLvl));var f=[];if(null!=debug.testPocket)f.push(debug.testPocket),this.sites=[this.createSite(this.worldMapSeed,e,debug.testPocket)],this.sites=this.sites.compact();else{this.party.getExplorer().hasStatus(config.specialStatuses.desertExpert)&&f.push("pck-desert");var g=t.arrify(e.pockets).worldGenRandomize();n.isDemo()||g.remove(function(b){return 0<=F.call(a.party.visitedPockets,b)});
g.add(t.arrify(e.pockets).worldGenRandomize());var h=d=0;for(c=e.numSites;0<=c?d<c:d>c;h=0<=c?++d:--d)h=g[h%g.length],f.push(h);c=this.party.unlockedPockets;d=0;for(g=c.length;d<g;d++)h=c[d],f.push(h);this.sites=function(){var a;var c=[];var d=0;for(a=f.length;d<a;d++)b=f[d],c.push(this.createSite(ba.rng.next(),e,b));return c}.call(this);return this.sites=this.sites.compact()}};wa.prototype.prepareWorld=function(){if(null!=this.worldSelection)return n.isDemo()&&this.sfx.fadeOut("celebrationMusic"),
this.sfx.play("campClose"),this.sites=null,this.party.reset(),this.main.mainMenu.visitedWorlds.includes(this.worldSelection.gen.world.pocketId)||this.main.mainMenu.visitedWorlds.add(this.worldSelection.gen.world.pocketId),this.main.prepareWorld(this.worldSelection.gen)};wa.prototype.onMouseClick=function(a){if(null!=this.mouseAction)switch(this.mouseAction.id){case "select":if(this.mouseAction.data===this.worldSelection)return this.prepareWorld();this.worldSelection=this.mouseAction.data;return this.sfx.play("nextChar");
case "play":return this.prepareWorld();case "save":return this.main.mainMenu.saveGame.updateSaveGame(),this.main.gotoMainMenu()}};wa.prototype.onKeyPress=function(a){if(32===a.which)return this.prepareWorld()};wa.prototype.draw=function(a,b,c){var d,e,f,g;var h=$jscomp.makeIterator(this.r.getCanvasSize());var k=h.next().value;h=h.next().value;var l=this.r.img.getSprite("hud_worldmap.png").dSize;var m=k/2-l.w/2;l=h/2-l.h/2;this.mouseHover=this.mouseRival=this.mouseAction=null;this.r.drawSprite("hud_worldmap.png",
m,l);new u(a,b);var p=config.homeLocation[0]*this.s;var w=config.homeLocation[1]*this.s;var t=this.sites;var r=f=0;for(e=t.length;f<e;r=++f){var v=t[r];var y=m+v.location.x*this.s;var Y=l+v.location.y*this.s;v===this.worldSelection?(this.r.ctx.globalAlpha=1,this.r.ctx.strokeStyle="red"):(this.r.ctx.globalAlpha=.5,this.r.ctx.strokeStyle="white");this.r.ctx.lineWidth=2*this.s;this.r.ctx.setLineDash([5*this.s,2.5*this.s]);this.r.ctx.lineDashOffset=10*-this.r.timeTotal%7.5*this.s;this.r.ctx.beginPath();
this.r.ctx.moveTo(m+p,l+w-5*this.s);this.r.ctx.lineTo(y,Y-5*this.s);this.r.ctx.stroke();this.r.ctx.setLineDash([])}this.r.ctx.globalAlpha=1;this.r.drawSprite("hud_mapMarker_home.png",m+p,l+w,{halign:"center",valign:"bottom"});f=this.sites;r=g=0;for(t=f.length;g<t;r=++g)v=f[r],e=v.slotMarker,Y=l+v.location.y*this.s,y=m+v.location.x*this.s,null!=e&&this.r.drawSprite(e,y,Y,{halign:"center",valign:"bottom",mX:a,mY:b})&&(this.mouseAction={id:"select",data:v},this.mouseHover=v,this.mouseWorldSiteX=y,this.mouseWorldSiteY=
l+v.location.y*this.s),(d=v.gen.world.pocketId,0<=F.call(this.party.visitedPockets,d))||this.r.drawSprite("hud_mapMarker_bonus.png",y,Y,{halign:"center",valign:"bottom"});f=this.rivalSites;r=d=0;for(t=f.length;d<t;r=++d)v=f[r],e="hud_mapMarker_rival.png",Y=Math.min(1,TWEEN.Easing.Back.Out(.5*this.time)),y=m+p+(v.location.x*this.s-p)*Y,Y=l+w+(v.location.y*this.s-w)*Y,this.r.drawSprite(e,y,Y,{halign:"center",valign:"bottom"}),r=this.main.rivals[r],this.r.drawPortrait(r.character,y-2*this.s,Y-19*this.s,
{small:!0}),this.r.hitBox(y-10*this.s,Y-35*this.s,20*this.s,35*this.s,a,b)&&(this.mouseHover=v,this.mouseWorldSiteX=y,this.mouseWorldSiteY=l+v.location.y*this.s,this.mouseRival=r);this.r.ctx.globalAlpha=1;this.r.ctx.font=config.fonts.themedLarge;this.r.drawText(q.toText("txt-worldmap-choose"),k/2,300*this.s,{halign:"center"});m=new R(130*this.s,25*this.s);this.r.ctx.globalAlpha=1;null!=this.worldSelection&&this.r.drawButton(q.toText("txt-worldmap-start"),k/2,h/2+130*this.s,m.w,m.h,a,b,c)&&(this.mouseAction=
{id:"play"});!n.isDemo()&&this.r.drawExitButton(q.toText("txt-base-saveexit"),a,b)&&(this.mouseAction={id:"save"});this.r.drawFameFunds(this.main.worldLvl,this.party.fame,this.party.funds);return this.drawInfoBox(c)};wa.prototype.drawInfoBox=function(a){var b,c,d,e,f;a=$jscomp.makeIterator(this.r.getCanvasSize());var g=a.next().value;a=a.next().value;if(null!=(null!=(b=this.mouseHover)?b.name:void 0)){b=null!=this.mouseRival?new R(275*this.s,110*this.s):new R(275*this.s,130*this.s);var h=J.clamp(this.mouseWorldSiteX,
b.w/2+10*this.s,g-10*this.s-b.w/2);g=this.mouseWorldSiteY>a/2?this.mouseWorldSiteY-25*this.s-b.h:this.mouseWorldSiteY+25*this.s;this.r.drawPanel(config.panel.infoSimple,h-b.w/2,g,b.w,b.h);a=g+=7*this.s;this.r.ctx.globalAlpha=1;this.r.ctx.fillStyle="#222";this.r.ctx.font=config.fonts.themedLarge;this.r.drawSprite(this.mouseHover.gen.previewSprite,Math.floor(h-b.w/2+9*this.s)+(2!==this.s?-1:0),a);var k=!(f=this.mouseHover.gen.world.pocketId,0<=F.call(this.party.visitedPockets,f));f=(c=this.mouseHover.gen.world.pocketId,
0<=F.call(this.party.unlockedPockets,c));k&&(d=this.mouseHover,0<=F.call(this.sites,d))&&this.r.drawSprite("hud_fame.png",h+b.w/3,g-10*this.s);this.r.drawText("- "+this.mouseHover.name+" -",h,a+27*this.s,{halign:"center",fillColor:f?"orange":"white",shadowColor:"black",os:this.s});a+=70*this.s;this.r.ctx.font=config.fonts.themedSmall;null!=this.mouseRival?(c=this.mouseRival.character.getLastName(),f=[q.toText(config.help.worldmap.rival).replace("$name",c),q.toText("txt-highscore-fame")+": "+this.mouseRival.fame]):
f=this.mouseHover.description;k=0;for(c=f.length;k<c;k++)d=f[k],this.r.drawText(d,h,a,{halign:"center",fillColor:"#222",os:0}),a+=10*this.s;if(null==this.mouseRival)for(e in c=new R(config.imgSize.tile),c=new R(.5*c.w*this.s,.5*c.h*this.s),d=new R(.5*c.w,.5*c.h),h-=c.w*Object.keys(this.mouseHover.locations).length/2,k=this.mouseHover.locations,k){f=k[e];var l=h+d.w;var m=a+d.h;var p=t.parseLocationPlacing(f[0].sprite).sample();this.r.drawSprite(config.unknownLocationSprite,l,m,{halign:"center",valign:"center"});
this.r.drawSprite(p,l,m,{halign:"center",valign:"center"});this.r.drawText(f.length,h+d.w,a+c.h+4*this.s,{font:config.fonts.technicalLarge,os:this.s,halign:"center"});h+=c.w}return g+b.h}};var ta=function(a,b,c){return W.call(this,a,b,c)||this};$jscomp.inherits(ta,W);ta.prototype.show=function(){this.time=0;this.rivalTime=-1;this.chatTime=this.chatStep=0;this.updateChatText();if(debug.testGame)return this.main.selectDifficulty(debug.testDifficulty)};ta.prototype.tick=function(a){this.time+=a;this.chatTime+=
a;8<this.chatTime&&this.incChatStep();2<=this.chatStep&&0>this.rivalTime&&(this.time+=100,this.rivalTime=0);if(0<=this.rivalTime)return this.rivalTime+=a};ta.prototype.draw=function(a,b,c){var d=$jscomp.makeIterator(this.r.getCanvasSize());var e=d.next().value;var f=d.next().value;this.r.drawNarratorBackground();this.drawGentleman();this.drawRivals();var g=130*this.s;d=25*this.s;if(this.chatStep===config.narrator.length-1){var h=$jscomp.makeIterator([e/2-g-10,f/2+130*this.s]);f=h.next().value;var k=
h.next().value;h=q.toText(config.difficultyNames[0]);this.r.drawButton(h,f,k,g,d,a,b,c)&&(this.main.infoBox.setInfo([{text:config.help.easyDifficulty}],a,b),this.mouseAction="easy");f=e/2;h=q.toText(config.difficultyNames[1]);this.r.drawButton(h,f,k,g,d,a,b,c)&&(this.main.infoBox.setInfo([{text:config.help.mediumDifficulty}],a,b),this.mouseAction="normal");f=e/2+g+10;h=q.toText(config.difficultyNames[2]);if(this.r.drawButton(h,f,k,g,d,a,b,c))return this.main.infoBox.setInfo([{text:config.help.hardDifficulty}],
a,b),this.mouseAction="hard"}};ta.prototype.drawGentleman=function(){var a=$jscomp.makeIterator(this.r.getCanvasSize());var b=a.next().value;a=a.next().value;var c=this.chatText.slice(0,+Math.floor(50*this.chatTime)+1||9E9);return this.r.drawChatPanel(c,b/2-200*this.s,a/2-25*this.s,{width:225*this.s,shrinkWidth:!1,lineCount:3,halign:"left"})};ta.prototype.drawRivals=function(){var a;var b=$jscomp.makeIterator(this.r.getCanvasSize());var c=b.next().value;b=b.next().value;var d=TWEEN.Easing.Bounce.Out(this.rivalTime.clamp(0,
1));var e=c-100*this.s+100*this.s-100*d*this.s;this.r.drawPanel(config.panel.info,e,-100,200*this.s,b+100*this.s);var f=this.main.rivals;var g=[];c=a=0;for(d=f.length;a<d;c=++a){var h=f[c];g.push(this.drawCharFrame(h.character,e+35*this.s,b/2-150*this.s+80*c*this.s,1,1))}return g};ta.prototype.drawCharFrame=function(a,b,c,d,e){var f=$jscomp.makeIterator(this.r.getCanvasSize());f.next();f.next();f=!1;var g=.1>a.time?J.lerp(0,1,a.time,.1):1-TWEEN.Easing.Bounce.Out((1.2*a.time).clamp(0,1));b=(new u(b,
c)).floor();c=-5*this.s*Math.max(g,0);g=a.rotation;this.r.hitBox(b.x-5*this.s,b.y-20*this.s,45*this.s,60*this.s,d,e)&&(f=!0,c-=5*this.s);d={halign:"center",fillColor:"black",shadowColor:"white",font:config.fonts.themedSmall};this.r.ctx.font=config.fonts.technicalSmall;this.r.drawText(a.shortName,b.x+20*this.s,b.y+52*this.s+c,d);this.r.drawSprite("hud_char_frame.png",b.x-5*this.s,b.y-15*this.s+c,{rotate:g});this.r.drawSprite(a.variations[0].portrait,b.x+19*this.s,b.y+35.5*this.s+c,{halign:"center",
valign:"bottom"});return f};ta.prototype.incChatStep=function(){if(this.chatStep<config.narrator.length-1)return this.chatStep+=1,this.chatTime=0,this.updateChatText()};ta.prototype.updateChatText=function(){return this.chatText=q.parse(config.narrator[this.chatStep],this.main.party.getExplorer().gender)};ta.prototype.onMouseClick=function(a){switch(this.mouseAction){case "easy":return this.main.selectDifficulty(0);case "normal":return this.main.selectDifficulty(1);case "hard":return this.main.selectDifficulty(2);
default:return this.incChatStep()}};ta.prototype.onKeyPress=function(a){switch(a.which){case 32:return this.incChatStep();case 49:return this.main.selectDifficulty(0);case 50:return this.main.selectDifficulty(1);case 51:return this.main.selectDifficulty(2)}};var Ja=function(a,b,c){a=W.call(this,a,b,c)||this;a.advanceCelebration=a.advanceCelebration.bind(a);a.drawFinalDemoScreen=a.drawFinalDemoScreen.bind(a);return a};$jscomp.inherits(Ja,W);Ja.prototype.show=function(){var a;this.time=0;this.chatLine=
null;this.chatTime=4;this.doneTime=-1;this.perks=[];this.audience=[];this.main.party.getExplorer();this.perkCount=1;this.showPerks=this.main.hasCampaign()||this.main.hasExtraCampaign();this.main.doEvent(t.getEvent(config.specialEvents.celebration));var b=Math.floor(J.lerp(config.celebration.audienceCount[0],config.celebration.audienceCount[1],(this.main.party.fame/config.celebration.maxFame).clamp(0,1)));for(a=0;0<=b?a<b:a>b;0<=b?++a:--a){var c=new $a(this.main);c.sprite=config.celebration.npc.sample();
this.main.events.addCharacter(c);this.audience.push(c)}n.isDemo()&&(this.sfx.fadeOut("clubMusic"),this.main.hasCampaign()||(this.main.demoCompleted=!0,this.main.doSendStats()));this.sfx.play("celebrationMusic",!0);this.main.diary.setIdleAnim("happy");return this.sfx.play(this.showPerks?"cheer1":"cheer3",!0)};Ja.prototype.getShareMessageText=function(){var a=this.main.party.fame;var b=this.main.party.getExplorer().name;return q.toText("txt-demo-share-message").replace("$explorerName",b).replace("$points",
a)+" %23CuriousDemo"};Ja.prototype.onMouseClick=function(a){var b,c;if(this.showPerks)return null!=this.mouseAction&&0>this.doneTime?this.selectCelebrationPerk(this.mouseAction.id):this.advanceCelebration();if(n.isDemo()&&!this.main.hasCampaign())if(null!=this.demoMouseAction){if("restart"===this.demoMouseAction.id)return this.sfx.fadeOut("cheer1").fadeOut("cheer3").fadeOut("cheer2"),this.main.shareMessageText=this.getShareMessageText(),this.finishCelebration(),this.main.doSendStats();if("actionScreen"===
this.demoMouseAction.id)return n.openLink("https://curious-expedition.com/buy"),this.main.goneToAction=!0,this.main.doSendStats(),this.sfx.fadeOut("cheer2").play("cheer3");if("shareTwitter"===(null!=(b=this.demoMouseAction)?b.id:void 0))return n.openLink("https://twitter.com/intent/tweet?text="+this.getShareMessageText()+"%0A"+this.main.getShareMessageURL()),this.main.sharedTwitter=!0,this.main.doSendStats();if("shareFB"===(null!=(c=this.demoMouseAction)?c.id:void 0))return n.openLink("https://www.facebook.com/sharer/sharer.php?u="+
this.main.getShareMessageURL()+"&quote="+this.getShareMessageText()),this.main.sharedFB=!0,this.main.doSendStats()}else return this.advanceCelebration();else return this.sfx.fadeOut("cheer1").fadeOut("cheer3"),this.finishCelebration()};Ja.prototype.finishCelebration=function(){if(n.isDemo()){this.main.stopMusic(!0);if(this.main.hasCampaign())return this.main.gotoNextWorld();this.sfx.fadeOut("celebrationMusic");return this.main.startNewDemoGame()}return this.main.gotoRanking()};Ja.prototype.onKeyPress=
function(a){if(32===a.which)return this.advanceCelebration()};Ja.prototype.randChatLine=function(){var a;var b={main:this.main,party:this.main.party,isDefaultPerson:!0};var c=(a=n.isDemo()&&!this.main.hasCampaign())?"cl-celebration-audience-demo":"cl-celebration-audience";.5>Math.random()&&!a&&this.main.doChat("cl-celebration-party",b);b.person=this.main.party.getExplorer();b.fakePartyHasTranslator=!0;c=this.main.randChatLine(c,b).first();if(null!=c){b=this.audience.sample();var d=this.main.diary.transformSlotToScreen(b.eventPos);
a=this.main.diary.getImageScale();b=d.x+config.chat.eventChatOffset[0]*a;a=d.y+config.chat.eventChatOffset[1]*a;return{text:q.parse(c.text),pos:new u(b,a)}}};Ja.prototype.showCelebrationMedals=function(){var a=this,b,c,d,e,f,g;if(!n.isDemo()||this.main.hasCampaign()){this.doneTime=-1;var h=this.main.party.getExplorer();var k=h.hasStatus(config.specialStatuses.polymath)?config.celebration.perkCountPolymath:config.celebration.perkCount;var l=this.main.fillEventCtx();var m=Object.values(config.statuses).filter(function(b){var c=
t.getStatus(b.id,!1);return null==c||c.isAbstract||!c.isPerk||h.hasStatus(b.id)?!1:a.main.events.hasRequirements(c,l)}).sample(k);0===m.length&&(this.showPerks=!1);var p=0;for(k=m.length;p<k;p++){var q=m[p];var r=this.r.img.getSprite(q.sprite);null!=r&&(null==r.silhouetteImg&&(r.silhouetteImg=[]),null==r.silhouetteImg[config.colors.medal]&&(r.silhouetteImg[config.colors.medal]=this.r.img.createSilhouette(r.img,0,config.colors.medal)))}this.perks=function(){var a,h;var k=[];e=h=0;for(a=m.length;h<
a;e=++h)q=m[e],b=function(){var a;var b=[];for(f=a=0;6>a;f=++a)d=.5>Math.random()?1:-1,g=new u(-2*(6-f)+d*f*10,3*f),b.push({pinned:0===f,pos:g,lastPos:g.clone()});return b}(),c=function(){var a;var b=[];for(f=a=0;5>a;f=++a)g=new u(2*(6-f)+d*f*10,3*f),b.push({pinned:0===f,pos:g,lastPos:g.clone()});return b}(),c.push(b.last()),k.push({conf:q,chains:[b,c]});return k}();return this.main.diary.setIdleAnim("nervous")}};Ja.prototype.selectCelebrationPerk=function(a){var b,c;var d=this.main.party.getExplorer();
d.setStatus(a);var e=this.perks;var f=0;for(b=e.length;f<b;f++){var g=e[f];if(g.conf.id!==a){var h=g.chains;var k=0;for(c=h.length;k<c;k++)g=h[k],g.first().pinned=!1}}--this.perkCount;0===this.perkCount&&(d.setLevel(d.level+1),this.sfx.fadeOut("cheer2").play("cheer3"),this.main.diary.setIdleAnim("veryHappy"));return this.doneTime=0};Ja.prototype.tick=function(a){var b=this,c,d,e,f,g;var h=function(b){if(!b.pinned){var c=b.pos.x-b.lastPos.x;var d=b.pos.y-b.lastPos.y;c=b.pos.x+c;d=b.pos.y+d+1E3*Math.min(.001,
a);b.lastPos.x=b.pos.x;b.lastPos.y=b.pos.y;b.pos.x=c;return b.pos.y=d}};var k=function(a,c){var d=a.pos.x-c.pos.x;var e=a.pos.y-c.pos.y;var f=Math.sqrt(d*d+e*e);var g=5*b.s;if(0<f&&f>g&&(f=(g-f)/f,d=.5*d*f,e=.5*e*f,a.pinned||(a.pos.x+=d,a.pos.y+=e),!c.pinned))return c.pos.x-=d,c.pos.y-=e};this.main.tickDiary(a);this.time+=a;this.chatTime+=a;this.chatTime>config.celebration.chatDelay&&(this.chatLine=this.randChatLine(),this.chatTime=0);this.showPerks&&this.time>config.celebration.medalDelay&&0===this.perks.length&&
(this.sfx.fadeOut("cheer1").play("cheer2",!0),this.showCelebrationMedals());var l=this.perks;var m=0;for(d=l.length;m<d;m++){var p=l[m];for(g=0;3>g;++g){var n=p.chains;var q=0;for(e=n.length;q<e;q++){var r=n[q];var t=c=1;for(f=r.length;1<=f?c<f:c>f;t=1<=f?++c:--c)k(r[t],r[t-1]);c=0;for(f=r.length;c<f;c++)t=r[c],h(t)}}}if(0<=this.doneTime){this.doneTime+=a;if(.5<this.doneTime&&0<this.perkCount)return this.showCelebrationMedals();if(this.doneTime>config.celebration.outFade+1)return this.sfx.fadeOut("cheer3"),
this.main.diary.part.clearParticles(),this.main.worldLvl<config.maxExpedition?this.finishCelebration():this.main.gotoEpilogue()}};Ja.prototype.advanceCelebration=function(){B(this,Ja);return 0<this.doneTime?this.doneTime+=50:this.time+=50};Ja.prototype.drawFinalDemoScreen=function(a,b,c){B(this,Ja);if(!(this.time<config.celebration.bannerDelay)){c=$jscomp.makeIterator(this.r.getCanvasSize());var d=c.next().value;c.next();this.demoMouseAction=null;var e=140*this.s;c=d/2;var f=q.toText("txt-demo-buy-now");
var g={fillColor:"#eab600",shadowColor:"black",font:config.fonts.themedLarge};this.r.ctx.font=g.font;var h=this.r.ctx.measureText(f).width+30*this.s;var k=45*this.s;null==this.wasHoveringActionButton&&(this.wasHoveringActionButton=!1);this.r.drawButton(f,c,e,h,k,a,b,!1,g)?(this.demoMouseAction={id:"actionScreen"},this.wasHoveringActionButton||(this.wasHoveringActionButton=!0,this.sfx.fadeOut("cheer1").play("cheer2"),this.main.diary.setIdleAnim("veryHappy"))):!this.main.goneToAction&&this.wasHoveringActionButton&&
(this.sfx.fadeOut("cheer2").play("cheer1"),this.main.diary.setIdleAnim("happy"),this.wasHoveringActionButton=!1);e+=k/2;g=h/2-5*this.s;g+=6*TWEEN.Easing.Sinusoidal.InOut(this.time)*this.s;this.r.drawSprite("hud_redArrow_left.png",c+g,e,{halign:"center",valign:"center"});this.r.drawSprite("hud_redArrow_right.png",c-g,e,{halign:"center",valign:"center"});g={shadowColor:"transparent"};f=q.toText("txt-demo-restart");h=this.r.ctx.measureText(f).width+15*this.s;k=28*this.s;e=285*this.s;this.r.drawButton(f,
c,e,h,k,a,b,!1,g)&&(this.demoMouseAction={id:"restart"});this.main.getPartyRank();k=this.main.party.fame;c=d/2;e=335*this.s;this.r.ctx.font=15*this.s+"px Averia";d=q.toText("txt-demo-score");g={fillColor:"white",shadowColor:"transparent",halign:"center"};this.r.drawText(d,c,e,g);e+=20*this.s;d=this.r.ctx.measureText(d).width/2+10*this.s;this.r.ctx.font=20*this.s+"px Averia";this.r.drawText(""+k,c,e,g);g=4*this.s;e-=25*this.s;k=c-d-this.r.img.logoFB.width/2;h=e;this.r.hitBox(k-g,h-g,this.r.img.logoFB.width/
2+2*g,this.r.img.logoFB.height/2+2*g,a,b)&&(this.demoMouseAction={id:"shareFB"},h-=2*this.s);this.r.ctx.drawImage(this.r.img.logoFB,k,h,this.r.img.logoFB.width/2,this.r.img.logoFB.height/2);k=c+d;h=e;this.r.hitBox(k-g,h-g,this.r.img.logoTwitter.width+2*g,this.r.img.logoTwitter.height+2*g,a,b)&&(this.demoMouseAction={id:"shareTwitter"},h-=2*this.s);return this.r.ctx.drawImage(this.r.img.logoTwitter,k,h,this.r.img.logoTwitter.width/2,this.r.img.logoTwitter.height/2)}};Ja.prototype.draw=function(a,b,
c){var d,e,f,g,h;var k=$jscomp.makeIterator(this.r.getCanvasSize());var l=k.next().value;var m=k.next().value;var p=this.main.diary.getImageCenter();this.main.drawDiary(a,b);var w=30*this.s;var r=30*this.s;var t=p.x-((this.perks.length-1)*w+(this.perks.length-1)*r)/2;var v=p.y-85*this.s;var y=this.perks;var u=h=0;for(e=y.length;h<e;u=++h){k=y[u];var A=k.chains;var H=0;for(f=A.length;H<f;H++){var G=A[H];var V=d=0;for(g=G.length;d<g;V=++d){var T=G[V];var x=Math.floor(t+T.pos.x);var B=Math.floor(20*
this.s*Math.abs(u-(this.perks.length-1)/2)+v+T.pos.y);0===V?(this.r.ctx.beginPath(),this.r.ctx.moveTo(x,B)):this.r.ctx.lineTo(x,B)}this.r.ctx.lineWidth=8;this.r.ctx.strokeStyle=config.colors.ribbonOut;this.r.ctx.stroke();this.r.ctx.lineWidth=4;this.r.ctx.strokeStyle=config.colors.ribbonIn;this.r.ctx.stroke()}this.r.ctx.save();this.r.ctx.translate(x,B-5*this.s);this.r.ctx.rotate(-T.pos.x/100);this.r.drawSprite("hud_medal.png",0,0,{halign:"center",valign:"top"});this.r.drawSprite(k.conf.sprite,-7*this.s,
10*this.s,{silhouette:config.colors.medal});this.r.ctx.restore();this.r.hitBox(x-w/2,v,w,3*w,a,b)&&(this.mouseAction=k.conf,k.chains[0].last().pos.y+=5*this.s);t+=w+r}this.r.drawSprite("hud_celebration_title_1.png",p.x,p.y-80*this.s,{halign:"center",valign:"center",scale:TWEEN.Easing.Back.Out(J.lerp(0,1,2*(this.time-config.celebration.bannerDelay),1))});this.showPerks&&this.r.drawSprite("hud_celebration_title_2.png",p.x+1,p.y-76*this.s,{halign:"center",valign:"center",scale:TWEEN.Easing.Back.Out(J.lerp(0,
1,2*(this.time-config.celebration.bannerDelay-3),1))});4>this.time&&(this.r.ctx.fillStyle="black",this.r.ctx.globalAlpha=J.lerp(1,0,this.time-.5,3),this.r.ctx.fillRect(0,0,l,m));1<this.doneTime&&(this.r.ctx.fillStyle="black",this.r.ctx.globalAlpha=J.lerp(0,1,this.doneTime-1,config.celebration.outFade),this.r.ctx.fillRect(0,0,l,m));0>this.doneTime&&2>this.chatTime&&null!=this.chatLine&&(this.r.ctx.fillStyle="blue",this.r.ctx.fillRect(this.chatLine.pos.x,this.chatLine.pos.y,2,2),this.r.ctx.globalAlpha=
1,this.main.r.drawChatPanel(this.chatLine.text,this.chatLine.pos.x,this.chatLine.pos.y,{halign:"center",valign:"bottom"}));n.isDemo()&&!this.main.hasCampaign()&&this.drawFinalDemoScreen(a,b,c);this.r.drawParticles(!0);if(null!=this.mouseAction){k=this.mouseAction;a=[{text:k.title},{text:k.description}];T=q.bonusHelp(k.bonus);b=0;for(c=T.length;b<c;b++)l=T[b],a.push({text:l,col:config.colors.bonus});return this.main.infoBox.setInfo(a)}};var fb=function(a,b,c){var d=W.call(this,a,b,c)||this;d.steps=
[Uc,Vc,Wc,Xc,Yc,Zc,$c,ad,bd,cd,dd,ed,fd,gd,hd,id,jd,kd,ld,md,nd,od,pd,qd,rd,sd,td,ud,vd,wd,xd,yd,zd,Ad,Bd,Cd,Dd,Ed,Fd,Gd,Hd,Id,Jd,Kd].map(function(d){return new d(a,b,c)});d.firstTick=!0;return d};$jscomp.inherits(fb,W);fb.prototype.tick=function(a){var b;this.firstTick&&(this.steps.first().activate(),this.firstTick=!1);null!=(b=this.steps.first())&&b.done()&&this.incStep();return this.steps.first().time+=a};fb.prototype.incStep=function(){this.steps.shift();var a=this.steps.first();if(null!=a)return this.main.log("tutorial "+
a.constructor.name),a.activate()};fb.prototype.draw=function(a,b,c){var d;null!=(d=this.steps.first())&&d.draw();if(debug.showTutorial&&null!=this.steps.first().textId)return b=$jscomp.makeIterator(this.r.getCanvasSize()),a=b.next().value,b.next(),this.r.drawText(this.steps.first().constructor.name,a/2,70,{font:config.fonts.technicalSmall,halign:"center"})};fb.prototype.onEvent=function(a,b){if(0<this.steps.length)return this.steps.first().onEvent(a,b)};fb.prototype.onUseItem=function(a){if(0<this.steps.length)return this.steps.first().onUseItem(a)};
fb.prototype.getFocusAction=function(){var a;return 0===this.steps.length?null:null!=(a=this.steps.first())?a.diaryActionIdx:void 0};var L=function(a,b,c){this.r=a;this.sfx=b;this.main=c;this.tutorialBoxOffsetY=this.time=0;this.diaryActionIdx=null;this.doneOnEvent="";this.eventTriggered=!1};L.prototype.activate=function(){return!1};L.prototype.onEvent=function(a){if(a===this.doneOnEvent)return this.eventTriggered=!0};L.prototype.onUseItem=function(a,b){return!0};L.prototype.done=function(){return this.eventTriggered};
L.prototype.draw=function(){return this.drawTutorialBox(this.text)};L.prototype.doEvent=function(a){return this.main.doRandEvent(t.getEvent(a))};L.prototype.addLocation=function(a,b){var c=this;var d={visible:!1,farVisible:!0,range:"4..10",centerCam:!0};Object.merge(d,b);b=this.main.world.getArea(this.main.party.pos,d.range).filter(function(a){return a.reachable}).sortBy(function(a){var b=a.pos.dist(c.main.party.pos);a.known&&(b+=10);return b});a=this.main.world.addLocation(a,b);this.main.exped.revealTileRadius(a.pos,
1,{centerCam:d.centerCam,farVisible:d.farVisible,visible:d.visible});return a};L.prototype.findLocation=function(a){return this.main.world.getLocations().find(function(b){return b.id===a})};L.prototype.setLocation=function(a,b){b=void 0===b?null:b;this.location=this.findLocation(a);if(null!=b)return this.main.exped.revealTileRadius(this.location.pos,1,{centerCam:!0,farVisible:!0,visible:b})};L.prototype.setItem=function(a){return this.item=a};L.prototype.getHintPos=function(){var a=this;if(null!=
this.location)return this.main.events.showingEventDialogue?[]:this.r.getTileScreenPos(this.location.pos,!0,!0,!0);if(null!=this.item){var b=config.inventory.slotSize*this.main.r.s;var c=this.main.invBar.getOffset();var d=this.main.invBar.inv.items.findIndex(function(b){return(null!=b?b.id:void 0)===a.item});return new u(c.w+b*d+b/2,c.h+b/2)}return this.main.diary.focusActionPosis};L.prototype.drawTutorialBox=function(a){var b;var c=Math.min(3*this.time,1);var d=$jscomp.makeIterator(this.r.getCanvasSize());
a=d.next().value;d.next();d=$jscomp.makeIterator([a-200*this.r.s,50*this.r.s+this.tutorialBoxOffsetY]);a=d.next().value;d=d.next().value;this.r.ctx.globalAlpha=1;if(1<=c){var e=t.arrify(this.getHintPos());var f=0;for(b=e.length;f<b;f++){var g=e[f];var h=15*this.r.s-this.r.timeTotal%1*15*this.r.s;this.r.ctx.strokeStyle=config.colors.personInfoBorder;this.r.ctx.lineWidth=2*this.r.s;this.r.ctx.beginPath();this.r.ctx.arc(g.x,g.y,h,0,2*Math.PI,!1);this.r.ctx.closePath();this.r.ctx.stroke()}}if(null!=this.textId&&
(this.r.ctx.font=config.fonts.technicalSmall,null==this.lines&&(this.lines=q.wrap(q.parse(this.textId),240*this.r.s,this.r.ctx)),b=250*c*this.r.s,h=c*(10*this.lines.length*this.r.s+9*this.r.s),this.r.drawInfoBox(a-b/2,d,b,h),d+=12*this.r.s,1<=c)){g=this.lines;e=[];f=0;for(c=g.length;f<c;f++)h=g[f],this.r.drawText(h,a+5*this.r.s-b/2,d),e.push(d+=10*this.r.s);return e}};var lc=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(lc,L);lc.prototype.activate=function(){this.diaryActionIdx=
[0];this.doneOnEvent=config.tutorial.start;return this.main.showActions=!0};var Uc=lc;var Qb=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(Qb,L);Qb.prototype.activate=function(){this.textId="txt-tu-cameraMove";this.cameraPosX=this.r.cam.scroll.x;return this.cameraPosY=this.r.cam.scroll.y};Qb.prototype.done=function(){return 200<Math.abs(this.cameraPosX-this.r.cam.scroll.x)+Math.abs(this.cameraPosY-this.r.cam.scroll.y)};var Vc=Qb;var Rb=function(a){return L.apply(this,arguments)||
this};$jscomp.inherits(Rb,L);Rb.prototype.activate=function(){this.textId="txt-tu-cameraZoom";this.startZoom=this.r.zoomTarget;return this.changedZoom=!1};Rb.prototype.done=function(){this.changedZoom||(this.changedZoom=this.r.zoomTarget!==this.startZoom);return this.changedZoom&&this.r.zoomTarget===this.startZoom};var Wc=Rb;var Sb=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(Sb,L);Sb.prototype.activate=function(){this.textId="txt-tu-movement";this.wasTraveling=!1;this.main.showPath=
!0;return this.startPos=this.main.party.pos};Sb.prototype.done=function(){return 2<this.main.party.pos.dist(this.startPos)};var Xc=Sb;var Tb=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(Tb,L);Tb.prototype.activate=function(){this.textId="txt-tu-sanity";this.main.showSanity=!0;this.main.showTileInfo=!0;this.startPos=this.main.party.pos;this.main.party.sanity=60;return this.main.exped.endTravel()};Tb.prototype.done=function(){return 2<this.main.party.pos.dist(this.startPos)};var Yc=
Tb;var Ub=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(Ub,L);Ub.prototype.activate=function(){this.textId="txt-tu-questionMark";this.location=this.addLocation(config.tutorial.oldCamp);return this.main.exped.endTravel()};Ub.prototype.done=function(){return 2>=this.main.party.pos.dist(this.location.pos)};var Zc=Ub;var mc=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(mc,L);mc.prototype.activate=function(){this.textId="txt-tu-oldCamp";this.doneOnEvent=config.tutorial.enterCamp;
this.main.showActions=!0;return this.main.exped.endTravel()};var $c=mc;var nc=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(nc,L);nc.prototype.activate=function(){this.textId="txt-tu-oldCampSearch";this.doneOnEvent=config.tutorial.leaveCamp;return this.diaryActionIdx=[0]};var ad=nc;var oc=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(oc,L);oc.prototype.activate=function(){this.textId="txt-tu-noSanity";this.noSanityPos=null;return this.main.party.sanity=10};
oc.prototype.done=function(){0<this.main.party.sanity&&(this.noSanityPos=this.main.party.pos);return 5<this.main.party.pos.dist(this.noSanityPos)};var Bb=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(Bb,L);Bb.prototype.activate=function(){this.textId="txt-tu-itemUsage";this.main.showInventory=!0;this.startSanity=this.main.party.sanity;this.itemUsed=0;this.main.showPath=!1;return this.setItem("it-chocolate")};Bb.prototype.onUseItem=function(a){this.itemUsed+=1;return!0};Bb.prototype.done=
function(){return 3<=this.itemUsed};var bd=Bb;var pc=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(pc,L);pc.prototype.activate=function(){this.textId="txt-tu-villageReach";this.doneOnEvent=config.tutorial.villageEnter;this.location=this.addLocation(config.tutorial.village,{visible:!0});return this.main.showPath=!0};var cd=pc;var qc=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(qc,L);qc.prototype.activate=function(){this.textId="txt-tu-villageRest";this.doneOnEvent=
config.tutorial.villageRest;return this.diaryActionIdx=[0]};var dd=qc;var rc=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(rc,L);rc.prototype.activate=function(){this.textId="txt-tu-standing";this.doneOnEvent=config.tutorial.villageTrade;this.main.party.standing=0;this.main.showStanding=!0;return this.diaryActionIdx=[2]};var ed=rc;var Vb=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(Vb,L);Vb.prototype.activate=function(){this.textId="txt-tu-tradingBasic";
return this.traded=!1};Vb.prototype.done=function(){return 2<=this.main.barter.validDeal()};var fd=Vb;var Cb=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(Cb,L);Cb.prototype.activate=function(){this.textId="txt-tu-tradingStanding";return this.traded=!1};Cb.prototype.getHintPos=function(){var a=this.main.barter.dealButtonPos;if(null!=a)return a.x+=50*this.r.s,a.y+=10*this.r.s,a};Cb.prototype.done=function(){return 2<=this.main.party.standing};var gd=Cb;var sc=function(a){return L.apply(this,
arguments)||this};$jscomp.inherits(sc,L);sc.prototype.activate=function(){this.textId="txt-tu-recruiting";this.doneOnEvent=config.tutorial.villageRecruit;this.diaryActionIdx=[1];return this.main.showPartySidebar=!0};var hd=sc;var Wb=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(Wb,L);Wb.prototype.activate=function(){this.textId="txt-tu-recruitingSelect";return this.diaryActionIdx=[0,1,2]};Wb.prototype.done=function(){return 1<this.main.party.persons.length};var id=Wb;var tc=function(a){return L.apply(this,
arguments)||this};$jscomp.inherits(tc,L);tc.prototype.activate=function(){this.textId="txt-tu-villageLeave";this.diaryActionIdx=[3];return this.doneOnEvent=config.tutorial.villageLeave};var jd=tc;var Xb=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(Xb,L);Xb.prototype.activate=function(){};Xb.prototype.done=function(){return!this.main.exped.events.showingEventDialogue};var kd=Xb;var Yb=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(Yb,L);Yb.prototype.activate=
function(){this.textId="txt-tu-shipSpawn";this.doneOnEvent=config.tutorial.hyenaAttack;this.diaryActionIdx=[0];this.findLocation(config.tutorial.village).actions=[];this.main.updateActions();var a=this.main.world.findPartyPos(!0);null==a&&(a=this.main.world.findPartyPos(!0,!1));a=this.main.world.getArea(a,"0");this.location=this.main.world.addLocation(config.ship.location,a);this.main.world.replaceTile(a.first(),"tl-river-shallow",{checkReachability:!1});this.main.exped.revealTileRadius(this.location.pos,
1,{centerCam:!0,farVisible:!0,visible:!1});this.startPos=this.main.party.pos;this.main.showPath=!0;this.main.showSanity=!0;this.main.showTileInfo=!0;return this.main.showActions=!0};Yb.prototype.done=function(){return 2<=this.main.party.pos.dist(this.startPos)};var ld=Yb;var Zb=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(Zb,L);Zb.prototype.activate=function(){this.main.exped.endTravel();this.doEvent(config.tutorial.overburden);return this.diaryActionIdx=[0]};Zb.prototype.done=
function(){return!this.main.exped.events.showingEventDialogue};var md=Zb;var Db=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(Db,L);Db.prototype.activate=function(){this.textId="txt-tu-overburden-1";this.main.showInventory=!0;this.main.showTrash=!0;this.main.showPath=!1;return this.setItem("it-torch")};Db.prototype.onUseItem=function(a){return"it-torch"===a.id};Db.prototype.done=function(){var a;return null!=(a=this.main.invBar.dragCtx.item)?a.id:void 0};var nd=Db;var Eb=function(a){return L.apply(this,
arguments)||this};$jscomp.inherits(Eb,L);Eb.prototype.activate=function(){this.textId="txt-tu-overburden-2";return this.startInvCount=this.main.party.inv.items.length};Eb.prototype.onUseItem=function(a){return"it-torch"===a.id};Eb.prototype.done=function(){return this.main.party.inv.items.length<this.startInvCount};var od=Eb;var $b=function(a){return L.apply(this,arguments)||this};$jscomp.inherits($b,L);$b.prototype.activate=function(){this.textId="txt-tu-overburden-3";this.main.showPath=!0;this.location=
this.findLocation(config.tutorial.ship);return this.main.world.addZone("zn-tiger-tutorial",this.location.pos,1,!0,5)};$b.prototype.done=function(){return this.main.showingChallenge};var pd=$b;var Fb=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(Fb,L);Fb.prototype.activate=function(){this.textId="txt-tu-combatRoll";this.tutorialBoxOffsetY=-15*this.r.s;return this.main.challenge.enableRoundAction=!1};Fb.prototype.getHintPos=function(){return this.main.challenge.getRollAreaCenter()};
Fb.prototype.done=function(){return 3>this.main.challenge.rollsLeft};var qd=Fb;var Gb=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(Gb,L);Gb.prototype.activate=function(){this.textId="txt-tu-combatPinFirst";this.tutorialBoxOffsetY=-15*this.r.s;return this.main.challenge.enableRoll=!1};Gb.prototype.getHintPos=function(){this.die=this.main.challenge.partyDice.find(function(a){return"mind"===a.getFace().id.slice(3)});if(null!=this.die){var a=this.main.challenge.getRollAreaCenter();
return this.die.anim.pos.add(a)}};Gb.prototype.done=function(){var a;return null!=(a=this.die)?a.pinned:void 0};var rd=Gb;var Hb=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(Hb,L);Hb.prototype.activate=function(){this.textId="txt-tu-combatReroll";this.tutorialBoxOffsetY=-15*this.r.s;return this.main.challenge.enableRoll=!0};Hb.prototype.getHintPos=function(){return this.main.challenge.getRollAreaCenter()};Hb.prototype.done=function(){return 2>this.main.challenge.rollsLeft};var sd=
Hb;var Ib=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(Ib,L);Ib.prototype.activate=function(){this.textId="txt-tu-combatPinSecond";this.tutorialBoxOffsetY=-15*this.r.s;return this.main.challenge.enableRoll=!1};Ib.prototype.getHintPos=function(){this.die=this.main.challenge.partyDice.find(function(a){return"shield"===a.getFace().id.slice(3)});if(null!=this.die){var a=this.main.challenge.getRollAreaCenter();return this.die.anim.pos.add(a)}};Ib.prototype.done=function(){var a;return null!=
(a=this.die)?a.pinned:void 0};var td=Ib;var Jb=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(Jb,L);Jb.prototype.activate=function(){this.textId="txt-tu-combatBlock";return this.tutorialBoxOffsetY=-15*this.r.s};Jb.prototype.getHintPos=function(){var a=this.main.diary.getImageCenter();a.x+=25*this.r.s;a.y-=60*this.r.s;return a};Jb.prototype.done=function(){return this.main.challenge.partyDice.any(function(a){return a.consumed})};var ud=Jb;var Kb=function(a){return L.apply(this,
arguments)||this};$jscomp.inherits(Kb,L);Kb.prototype.activate=function(){this.textId="txt-tu-combatPinThird";this.tutorialBoxOffsetY=-15*this.r.s;return this.main.challenge.enableRoll=!1};Kb.prototype.getHintPos=function(){this.die=this.main.challenge.partyDice.find(function(a){return"sword"===a.getFace().id.slice(3)});if(null!=this.die){var a=this.main.challenge.getRollAreaCenter();return this.die.anim.pos.add(a)}};Kb.prototype.done=function(){var a;return null!=(a=this.die)?a.pinned:void 0};var vd=
Kb;var Lb=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(Lb,L);Lb.prototype.activate=function(){this.textId="txt-tu-combatAttack";return this.tutorialBoxOffsetY=-30};Lb.prototype.getHintPos=function(){var a=this.main.diary.getImageCenter();a.x+=25*this.r.s;a.y-=60*this.r.s;return a};Lb.prototype.done=function(){return 2<this.main.challenge.partyDice.count(function(a){return a.consumed})};var wd=Lb;var Mb=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(Mb,L);
Mb.prototype.activate=function(){this.textId="txt-tu-combatEndRound";this.tutorialBoxOffsetY=-30;return this.main.challenge.enableRoundAction=!0};Mb.prototype.getHintPos=function(){var a=this.main.challenge.getRollAreaCenter();a.x+=25*this.r.s;a.y+=130*this.r.s;return a};Mb.prototype.done=function(){return!this.main.challenge.isPartyRound};var xd=Mb;var ac=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(ac,L);ac.prototype.activate=function(){this.textId="txt-tu-combatAttackEnemy";
return this.tutorialBoxOffsetY=-30};ac.prototype.done=function(){return 0<this.main.challenge.round};var yd=ac;var bc=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(bc,L);bc.prototype.activate=function(){this.textId="txt-tu-combatFlee";this.doneOnEvent=config.tutorial.hyenaFlee;this.tutorialBoxOffsetY=-30;this.diaryActionIdx=[0];return this.main.challenge.enableRoundAction=!0};bc.prototype.getHintPos=function(){var a=this.main.challenge.getRollAreaCenter();a.x+=25*this.r.s;a.y+=
130*this.r.s;return a};var zd=bc;var cc=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(cc,L);cc.prototype.activate=function(){this.textId="txt-tu-combatDone";this.startPos=this.main.party.pos;return this.location=this.main.world.getLocations().find(function(a){return a.id===config.tutorial.ship})};cc.prototype.done=function(){return 1>=this.main.party.pos.dist(this.location.pos)};var Ad=cc;var uc=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(uc,L);uc.prototype.activate=
function(){this.textId="txt-tu-ship-1";this.setLocation(config.tutorial.ship,!0);this.main.exped.endTravel();this.doneOnEvent=config.tutorial.shipReturn;return this.diaryActionIdx=[-1,0]};var Bd=uc;var dc=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(dc,L);dc.prototype.activate=function(){var a;this.textId="txt-tu-ship-2";this.diaryActionIdx=[-1,0];var b=this.main.world.zones;var c=[];var d=0;for(a=b.length;d<a;d++){var e=b[d];c.push(this.main.world.removeZone(e))}return c};dc.prototype.done=
function(){return!this.main.exped.events.showingEventDialogue};var Cd=dc;var ec=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(ec,L);ec.prototype.activate=function(){this.textId="txt-tu-compass";this.addLocation(config.tutorial.goldenTemple,{farVisible:!1,centerCam:!1,range:"20..30"});this.main.exped.changeCompassScore(0);this.location=this.addLocation(config.tutorial.shrine);return this.main.showLeftSidebar=!0};ec.prototype.done=function(){return 2>=this.main.party.pos.dist(this.location.pos)};
var Dd=ec;var fc=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(fc,L);fc.prototype.activate=function(){this.textId="txt-tu-promote-1";this.main.showXP=!0;this.main.showPartySidebar=!0;this.main.showActions=!1;return this.main.exped.checkMapScores()};fc.prototype.done=function(){return this.main.party.persons.any(function(a){return 0<a.level})};var Ed=fc;var vc=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(vc,L);vc.prototype.activate=function(){this.textId=
"txt-tu-promote-2";this.main.showActions=!0;return this.doneOnEvent=config.tutorial.shrineEnter};var Fd=vc;var wc=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(wc,L);wc.prototype.activate=function(){this.textId="txt-tu-shrine-1";this.doneOnEvent=config.tutorial.shrineExplore;return this.diaryActionIdx=[0]};var Gd=wc;var xc=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(xc,L);xc.prototype.activate=function(){this.textId="txt-tu-shrine-2";this.doneOnEvent=config.tutorial.shrineLoot;
return this.diaryActionIdx=[0]};var Hd=xc;var gc=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(gc,L);gc.prototype.activate=function(){this.textId="txt-tu-shrine-3";return this.diaryActionIdx=[-1,0]};gc.prototype.done=function(){return!this.main.events.showingEventDialogue};var Id=gc;var yc=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(yc,L);yc.prototype.activate=function(){this.textId="txt-tu-volcanoFlee";return this.doneOnEvent=config.tutorial.goalEnter};
var Jd=yc;var zc=function(a){return L.apply(this,arguments)||this};$jscomp.inherits(zc,L);zc.prototype.activate=function(){this.textId="txt-evt-tutorial-finish";return this.main.achievements.incCounter("ach-beat-tutorial")};var Kd=zc;var Nb=function(a,b,c){return W.call(this,a,b,c)||this};$jscomp.inherits(Nb,W);Nb.prototype.draw=function(a,b,c){this.main.events.showingEventDialogue||this.r.drawCloudIntro();this.main.drawDiary(a,b);if(this.main.events.showingEventDialogue)return this.main.drawInventoryBar(),
this.main.drawWarningBar(),this.main.drawItemInfo(),this.r.drawFameFunds(this.main.worldLvl,this.main.party.fame,this.main.party.funds)};Nb.prototype.tick=function(a){return this.main.tickDiary(a)};Nb.prototype.onKeyPress=function(a){var b,c;if(this.main.events.showingEventDialogue){var d=this.main.events.eventActions.isEmpty();if(!this.main.barter.onKeyPress(a)){if(32===a.which)return this.main.diary.entryTime+=100;if(49===a.which&&d)return this.main.hideEventDialogue();d=this.main.getActions();
var e=[];var f=c=0;for(b=d.length;c<b;f=++c){var g=d[f];g.canDo&&((g=(f+1).toString().charCodeAt(0)===a.which)?e.push(this.main.doAction(f)):e.push(void 0))}return e}}};var ob=function(a,b,c){return W.call(this,a,b,c)||this};$jscomp.inherits(ob,W);ob.prototype.show=function(){var a,b,c,d;var e=this.main.hasExtraCampaign()?config.specialEvents.extraNarrative:config.specialEvents.postNarrative;var f=this.main.fillEventCtx();var g=f.party.persons;var h=this.main.events.doEvent(t.getEvent(e),f);this.winner=
this.main.getBestExplorer();this.bios=function(){var e=h.texts.groupBy(function(a){return g.indexOf(a.persons[0])});var f=[];for(a in e)b=e[a],c=b[0].persons[0],d=b.map(function(a){return a.text}).join(" "),f.push({person:c,lines:q.wrap(this.parse(d,c),250*this.s,this.r.ctx)});return f}.call(this);return this.currentPage=this.textTime=this.time=0};ob.prototype.parse=function(a,b){var c;a=q.parse(a);var d=this.main.events.prepareWords(a,[[b]],0);d=d.map(function(a){return a.text});var e="";a=c=0;for(b=
d.length;c<b;a=++c){var f=d[a];0!==a&&(e+=q.isTextLatin(f)||q.isTextLatin(d[a-1])?config.diaryTextLangs.latin.separator:config.diaryText.separator);e+=f}return e};ob.prototype.tick=function(a){this.time+=a;return this.textTime+=a};ob.prototype.onMouseClick=function(a){if(!(.1>this.time))switch(this.mouseAction.id){case "next":return this.currentPage<this.bios.length?(this.currentPage+=1,this.textTime=0):this.main.hasExtraCampaign()?this.main.gotoNextWorld():this.main.showCredits(!0);case "goto":return this.currentPage=
this.mouseAction.val,this.textTime=0}};ob.prototype.draw=function(a,b,c){var d,e,f,g;c=$jscomp.makeIterator(this.r.getCanvasSize());var h=c.next().value;c=c.next().value;this.r.clear(!0);this.mouseAction={id:"next"};this.r.drawSprite("menu_endscreen_sky.png",h/2,0,{halign:"center"});this.r.drawSprite("menu_endscreen_building.png",h/2,c,{halign:"center",valign:"bottom"});for(d=g=1;3>=g;d=++g){var k=this.r.img.getSprite("menu_endscreen_clouds_"+d+".png");var l=-(this.s*this.r.timeTotal/d*15);for(l%=
k.dSize.w;l<h;)this.r.drawSprite(k,l,h/2-350*this.s+50*d*this.s),l+=k.dSize.w}d=500*this.s-500*this.s*TWEEN.Easing.Quartic.Out((.2*this.time).clamp(0,1));this.r.drawSprite("menu_endscreen_statue_base.png",h/2-200*this.s,c/2+180*this.s+d,{halign:"center",valign:"bottom"});g=this.winner.variations[0].portrait.replace(".png","")+"_end.png";k=$jscomp.makeIterator(this.r.img.getSprite(g).dSize.lst());l=k.next().value;k=k.next().value;g=this.r.img.getSpriteSlots(g,2);g=null!=(e=null!=g?null!=(f=g.socket)?
f.first():void 0:void 0)?e:new u(0,0);this.r.drawPortrait(this.winner,h/2-197*this.s-(l/2-g.x),c/2-83*this.s+(k-g.y)+d,{halign:"center",valign:"bottom",statue:!0,scale:2});l=h/2+90*this.s;e=c/2-100*this.s;this.r.ctx.font=config.fonts.themedLarge;if(0===this.currentPage)this.r.ctx.font=32*this.s+"px Averia",d=q.toText("txt-epilogue-congratulations"),this.r.drawText(d,l,e,{halign:"center"}),e+=50*this.s,h=this.main.getPartyRank(),f=this.main.getPoints(),this.r.ctx.font=20*this.s+"px Averia",d=q.toText("txt-epilogue-rank"),
this.r.drawText(d+": "+q.rank(h)+"!",l,e,{halign:"center"}),e+=30*this.s,d=q.toText("txt-epilogue-score"),this.r.drawText(d+": "+f,l,e,{halign:"center"});else for(f=0,h=this.bios[this.currentPage-1],this.r.drawPortrait(h.person,l,e,{halign:"center"}),e+=35*this.s,k=h.lines,g=0,h=k.length;g<h;g++)d=k[g],this.r.ctx.globalAlpha=J.clamp(this.textTime-f,0,1),this.r.drawText(d,l,e,{halign:"center"}),f+=1,e+=15*this.s;this.r.ctx.globalAlpha=1;this.r.ctx.strokeStyle="black";this.r.ctx.fillStyle="white";this.r.ctx.lineWidth=
this.s;f=this.bios.length+1;for(d=e=0;0<=f?e<f:e>f;d=0<=f?++e:--e)h=this.currentPage===d?10*this.s:6*this.s,k=30*this.s,k=l-(f-1)/2*k+d*k-h/2,g=c/2+50*this.s-h/2,this.r.ctx.fillRect(k,g,h,h),this.r.hitBox(k,g,h,h,a,b)&&(this.mouseAction={id:"goto",val:d},this.r.ctx.strokeRect(k,g,h,h))};var Aa=function(a,b,c){a=W.call(this,a,b,c)||this;a.draw=a.draw.bind(a);a.toggleFullscreen=a.toggleFullscreen.bind(a);a.toggleLowGraphics=a.toggleLowGraphics.bind(a);a.tick=a.tick.bind(a);a.onMouseClick=a.onMouseClick.bind(a);
a.onKeyPress=a.onKeyPress.bind(a);return a};$jscomp.inherits(Aa,W);Aa.prototype.show=function(){var a,b;this.waitForSave=!1;this.resetCheckTime=-1;this.unlockBuffer="XXXX";this.confirmTime=100;this.confirmText="";return this.isFullScreen=window.isNW?(a=require("nw.gui"),b=a.Window.get(),b.isFullscreen):window.isElectron?(b=require("electron").remote.getCurrentWindow(),b.isFullScreen()):screenfull.isFullscreen};Aa.prototype.draw=function(a,b,c){var d,e,f,g,h;B(this,Aa);var k=$jscomp.makeIterator(this.r.getCanvasSize());
var l=k.next().value;k=k.next().value;var m=145*this.s;var p=115*this.s;var w=$jscomp.makeIterator([280*this.s,260*this.s]);var r=w.next().value;var t=w.next().value;n.isChina()&&(t-=50*this.s);k=$jscomp.makeIterator([l/2-r/2,Math.max(15*this.s,k/2-170*this.s)]);w=k.next().value;k=k.next().value;var v={fillColor:"black",shadowColor:"gray",font:config.fonts.technicalLarge};this.waitForSave&&(b=a=0,c=!1);this.r.clear(!0);this.r.ctx.globalAlpha=1;if(this.isAlphaActivateMode)this.mouseAction=null!=(h=
bb.drawAlphaAccessPanel(this.main,a,b,c))?h.id:void 0;else{this.r.drawPanel(config.panel.info,w,k,r,t);k+=50*this.s;this.r.ctx.font=config.fonts.technicalLarge;this.r.drawText(q.toText("txt-settings-musicvolume"),w+20*this.s,k,v);this.r.ctx.fillStyle="#C4B190";this.r.ctx.fillRect(w+p,k-4*this.s,m,4*this.s);this.r.drawPanel(config.panel.scrollBar,w+p+this.r.sfx.musicVolume*m,k-10*this.s,6*this.s,15*this.s);this.r.hitBox(w+95*this.s,k-10*this.s,m+15*this.s,20*this.s,a,b)&&c&&this.r.sfx.setMusicVolume(J.clamp((a-
w-p)/m,0,1));k+=25*this.s;this.r.drawText(q.toText("txt-settings-soundvolume"),w+20*this.s,k,v);this.r.ctx.fillStyle="#C4B190";this.r.ctx.fillRect(w+p,k-4*this.s,m,4*this.s);this.r.drawPanel(config.panel.scrollBar,w+p+this.r.sfx.soundVolume*m,k-10*this.s,6*this.s,15*this.s);this.r.hitBox(w+95*this.s,k-10*this.s,m+15*this.s,20*this.s,a,b)&&c&&this.r.sfx.setSoundVolume(J.clamp((a-w-p)/m,0,1));k+=25*this.s;this.r.drawText(q.toText("txt-settings-low-graphics"),w+140*this.s,k,v);this.r.drawCheckbox(w+
240*this.s,k,a,b,{checked:this.main.lowGraphics})&&(this.main.infoBox.showHelp(config.help.settings.lowGraphics,a,b),this.mouseAction="lowGraphics");if(!n.isDemo()){this.r.drawText(q.toText("txt-settings-fullscreen"),w+20*this.s,k,v);this.r.drawCheckbox(w+110*this.s,k,a,b,{checked:this.isFullScreen})&&(this.mouseAction="fullscreen");k+=25*this.s;this.r.drawText(q.toText("txt-settings-scaling"),w+20*this.s,k,v);m=(null!=(e=this.main.events)?e.showingEventDialogue:void 0)&&!this.main.diary.isCelebration;
var y=window.localStorage.getItem("pixelScale");this.r.drawCheckbox(w+110*this.s,k,a,b,{txt:"1",checked:"1"===y})&&(m||(this.mouseAction="scale1"),this.main.infoBox.showHelp(config.help.settings.scale1,a,b));this.r.drawCheckbox(w+130*this.s,k,a,b,{txt:"2",checked:"2"===y})&&(m||(this.mouseAction="scale2"),this.main.infoBox.showHelp(config.help.settings.scale2,a,b));this.r.drawCheckbox(w+150*this.s,k,a,b,{txt:"3",checked:"3"===y})&&(m||(this.mouseAction="scale3"),this.main.infoBox.showHelp(config.help.settings.scale3,
a,b));this.r.drawCheckbox(w+170*this.s,k,a,b,{txt:"6",checked:"6"===y})&&(m||(this.mouseAction="scale6"),this.main.infoBox.showHelp(config.help.settings.scale6,a,b));!n.isChina()&&this.r.drawCheckbox(w+190*this.s,k,a,b,{txt:"s",checked:this.main.stretching})&&(m||(this.mouseAction="scaleStrech"),this.main.infoBox.showHelp(config.help.settings.scaleStrech,a,b))}k+=25*this.s;this.r.drawText(q.toText("txt-settings-quicktext"),w+20*this.s,k,v);this.r.drawCheckbox(w+110*this.s,k,a,b,{checked:this.main.quickText})&&
(this.mouseAction="quickText",this.main.infoBox.showHelp(config.help.settings.quickText,a,b));this.r.drawText(q.toText("txt-settings-customcursor"),w+140*this.s,k,v);this.r.drawCheckbox(w+240*this.s,k,a,b,{checked:this.main.customCursor})&&(this.mouseAction="customCursor",this.main.infoBox.showHelp(config.help.settings.customCursor,a,b));k+=25*this.s;m=!1;this.main.showingChallenge||null!=this.main.tutorial||(m=!0,this.r.drawText(q.toText("txt-settings-combat-autoselect"),w+20*this.s,k,v),this.r.drawCheckbox(w+
110*this.s,k,a,b,{checked:this.main.combatAutoSelect})&&(this.mouseAction="combat-autoselect",this.main.infoBox.showHelp(config.help.settings.combatAutoSelect,a,b)));n.isTCE()&&(e=!1,m=!0,this.r.drawText(q.toText("txt-settings-resetprofile"),w+140*this.s,k,v),this.r.drawCheckbox(w+240*this.s,k,a,b,{filled:this.resetCheckTime})&&(this.main.infoBox.showHelp(config.help.settings.resetProfile,a,b),e=c,this.wasPressed||(this.resetCheckTime=Math.max(0,this.resetCheckTime))),e||(this.resetCheckTime=-1,this.resetConfirmed=
!1),this.wasPressed=c);m&&(k+=25*this.s);n.isChina()||(this.r.drawText(q.toText("txt-settings-language"),w+20*this.s,k,v),this.r.drawPanel("backButton",w+110*this.s,k-13*this.s,144*this.s,18*this.s),m=getLanguageName(q.langId),e=getLanguageNativeName(q.langId),this.r.drawText(e,w+182*this.s,k+1,{font:config.fonts.technicalLarge,fillColor:"white",halign:"center"}),this.r.hitBox(w+110*this.s,k-11*this.s,112*this.s,14*this.s,a,b)&&(this.mouseAction="nextLang",e=q.langs.find(function(a){return a.id===
q.langId}),e=null!=(g=null!=e?e.authors:void 0)?g:[],g=Math.floor(this.main.r.timeTotal%e.length),g=[m,e[g],"txt-help-settings-restart"],this.main.infoBox.showHelp(g,a,b)));k+=25*this.s;n.isChina()?(this.r.drawText(q.toText("txt-settings-credits"),w+20*this.s,k-50*this.s,v),this.r.drawCheckbox(w+110*this.s,k-50*this.s,a,b)&&(this.mouseAction="credits")):(this.r.drawText(q.toText("txt-settings-credits"),w+20*this.s,k,v),this.r.drawCheckbox(w+110*this.s,k,a,b)&&(this.mouseAction="credits"),this.r.drawText(q.toText("txt-settings-privacy-policy"),
w+140*this.s,k,v),this.r.drawCheckbox(w+240*this.s,k,a,b,{checked:!1})&&(this.mouseAction="privacyPolicy"));k+=50*this.s;g=0;(null!=(f=null!=(d=this.iomp)?d.isSaving:void 0)?f:this.main.mainMenu.saveGame.saving)&&this.r.drawText("Saving...",l/2,25*this.s,{halign:"center"});m=120;n.isDemo()?(k+=30*this.s,g=65*this.s,null==this.main.tutorial?this.r.drawButton(q.toText("txt-demo-restart"),l/2-g,k,m*this.s,30*this.s,a,b,c)&&(this.main.infoBox.showHelp(config.help.settings.restartDemo,a,b),this.mouseAction=
"quit"):this.r.drawButton(q.toText("txt-demo-skip-tutorial"),l/2-g,k,m*this.s,30*this.s,a,b,c)&&(this.mouseAction="skipTutorial"),this.r.drawButton(q.toText("txt-base-return"),l/2+g,k,m*this.s,30*this.s,a,b,c)&&(this.mouseAction="return")):n.isTCE()?(this.main.mainMenu.isActive||(g=65*this.s,f=this.main.canSave(),this.r.drawButton(q.toText("txt-base-saveexit"),l/2,k,m*this.s,30*this.s,a,b,c,{active:f})&&(this.main.infoBox.showHelp(config.help.settings.saving,a,b),f&&(this.mouseAction="save"))),this.r.drawButton(q.toText("txt-mainmenu-quit"),
l/2-65*this.s-g,k,m*this.s,30*this.s,a,b,c)&&(this.main.infoBox.showHelp(config.help.settings.quit,a,b),this.mouseAction="quit"),this.r.drawButton(q.toText("txt-base-return"),l/2+65*this.s+g,k,m*this.s,30*this.s,a,b,c)&&(this.mouseAction="return")):n.isIO()&&(f=w+r/2,this.r.drawButton(q.toText("txt-base-return"),f-75*this.s,k,m*this.s,30*this.s,a,b,c)&&(this.mouseAction="return"),null==this.main.user||debug.runOffline||(d=(d=!window.isSteam&&(""===this.main.user.get("email")||null==this.main.user.get("email")))?
q.toText("txt-io-claim-account"):q.toText("txt-io-manage-account"),this.r.drawButton(d,f+75*this.s,k,m*this.s,30*this.s,a,b,c)&&(this.mouseAction="account")));this.r.ctx.globalAlpha=J.clamp((3-this.confirmTime)/3,0,1);this.r.drawText(this.confirmText,l-10*this.s,20*this.s,{halign:"right",font:config.fonts.technicalLarge});n.isDemo()&&this.drawFooter();"6"===y&&!this.main.stretching&&this.r.drawButton(q.toText("txt-settings-reset"),50*this.s,10*this.s,40*this.s,20*this.s,a,b,c,{os:0,font:config.fonts.technicalSmall})&&
(this.mouseAction="scaleStrech");if(n.isIO())return this.drawIO(a,b,c)}};Aa.prototype.drawIO=function(a,b,c){this.r.ctx.globalAlpha=1;var d=$jscomp.makeIterator(this.r.getCanvasSize());var e=d.next().value;d.next();d=bb.drawPyramidPanel(this.main,e-130*this.s,50*this.s,a,b,c);null!=d&&(this.mouseAction=d.id);c=bb.drawCE2Panel(this.main,e-130*this.s,215*this.s,a,b,c);null!=c&&(this.mouseAction=c.id);c=debug.showDebugBar?15*this.s:0;if(window.isClient&&this.r.drawExitButton(q.toText("txt-mainmenu-quit"),
a,b,c))return this.mouseAction="quitClient"};Aa.prototype.drawFooter=function(){var a=$jscomp.makeIterator(this.r.getCanvasSize());var b=a.next().value;a=a.next().value;this.r.ctx.globalAlpha=1;this.r.ctx.fillStyle="gray";this.r.ctx.font=config.fonts.technicalSmall;return this.r.drawText("Demo  V"+config.footerName,b-5*this.s,a-5*this.s,{halign:"right",os:0,fillColor:config.colors.news})};Aa.prototype.toggleFullscreen=function(){B(this,Aa);this.isFullScreen=!this.isFullScreen;if(window.isNW){var a=
require("nw.gui");a=a.Window.get();this.isFullScreen?a.enterFullscreen():a.leaveFullscreen();return window.localStorage.setItem("fullscreen",this.isFullScreen)}return window.isElectron?(a=require("electron").remote.getCurrentWindow(),a.setFullScreen(this.isFullScreen),window.localStorage.setItem("fullscreen",this.isFullScreen)):screenfull.toggle()};Aa.prototype.toggleLowGraphics=function(){B(this,Aa);return this.main.setLowGraphicsMode(!this.main.lowGraphics)};Aa.prototype.showConfirm=function(a){this.confirmText=
a;return this.confirmTime=0};Aa.prototype.tick=function(a){B(this,Aa);0<=this.resetCheckTime&&(this.resetCheckTime+=a,1<this.resetCheckTime&&!this.resetConfirmed&&(this.showConfirm("Profile reset!"),this.resetConfirmed=!0,this.main.mainMenu.resetCharacters(),this.main.highscore.resetScores(),this.main.achievements.resetAchievements()));this.confirmTime+=a;if(this.waitForSave&&!this.main.mainMenu.saveGame.saving)return this.main.gotoMainMenu()};Aa.prototype.onMouseClick=function(){B(this,Aa);switch(this.mouseAction){case "return":return this.main.showSettings(!1);
case "credits":return this.main.showCredits(!0);case "quickText":return this.main.setQuickText(!this.main.quickText);case "fullscreen":return this.toggleFullscreen();case "lowGraphics":return this.toggleLowGraphics();case "scale1":return this.main.setPixelScale(1,this.main.stretching);case "scale2":return this.main.setPixelScale(2,this.main.stretching);case "scale3":return this.main.setPixelScale(3,this.main.stretching);case "scale6":return this.main.setPixelScale(6,this.main.stretching);case "scaleStrech":return this.main.setPixelScale(this.s,
!this.main.stretching);case "customCursor":return this.main.setCustomCursor(!this.main.customCursor);case "sendStats":return this.main.setSendStats(!this.main.sendStats);case "nextLang":return q.setNextLang();case "account":return this.main.gotoRivalsAccount();case "combat-autoselect":return this.main.toggleCombatAutoselect(!this.main.combatAutoSelect);case "privacyPolicy":return n.isIO()?n.openLink("http://curious-expedition.io/imprint_p",!1):n.openLink("https://curious-expedition.com/imprint",!1);
case "save":return this.main.hasMainState("game")?(this.waitForSave=!0,this.main.mainMenu.saveGame.updateSaveGame()):this.main.popMainState();case "quit":this.main.popMainState();if("game"===this.main.getMainState())return this.main.showExpeditionOver();if("mainMenu"===this.main.getMainState()&&window.isClient)return this.main.quit();this.main.stopMusic(!0);return this.main.gotoMainMenu();case "skipTutorial":return this.main.endWorld();case "alphaActivate":return this.sfx.play("campClose"),navigator.clipboard.writeText(this.main.ioInv.userSecure.alphaKey),
this.isAlphaActivateMode=!0;case "alphaPanelBack":return this.sfx.play("campClose"),this.isAlphaActivateMode=!1;case "ce2wishlist":return this.sfx.play("campClose"),n.openLink("https://store.steampowered.com/app/1040230/Curious_Expedition_2/");case "alphaSignup":return this.sfx.play("campClose"),n.openLink("https://curious-expedition.com/");case "discord":return this.sfx.play("campClose"),n.openLink("https://discordapp.com/invite/maschinen-mensch",!1);case "quitClient":return this.main.quit()}};Aa.prototype.onKeyPress=
function(a){var b=this;B(this,Aa);if(n.isTCE()&&!n.isChina())return a=String.fromCharCode(a.which),this.unlockBuffer=this.unlockBuffer.substr(1,3)+a,a=Object.values(config.characters).find(function(a){var c;return(null!=(c=a.unlockPin)?c.toString():void 0)===b.unlockBuffer}),null!=a&&(this.main.mainMenu.unlockedChars.includes(a.id)?(this.main.mainMenu.unlockedChars.remove(a.id),a=q.toText("txt-base-lockChar").replace("$val",a.name),this.showConfirm(a)):(this.main.mainMenu.unlockCharacter(a.id),this.main.achievementBox.queueUnlockedChar(a.id))),
!0};var gb=function(a,b,c){a=W.call(this,a,b,c)||this;a.randTaxSet=a.randTaxSet.bind(a);a.addRandButterfly=a.addRandButterfly.bind(a);return a};$jscomp.inherits(gb,W);gb.prototype.randTaxSet=function(a){a=void 0===a?[]:a;B(this,gb);return{name:q.createName("butterfly",{$name:a.sample()}),body:Number.random(config.taxonomy.butterflyBody-1),pattern:Number.random(config.taxonomy.butterflyPattern-1),wingsTop:Number.random(config.taxonomy.butterflyWings-1),wingsBottom:Number.random(config.taxonomy.butterflyWings-
1)}};gb.prototype.addRandButterfly=function(){B(this,gb);var a=this.main.party.persons.filter(function(a){return!a.flags.animal}).map(function(a){return a.name.split(" ")}).flatten().compact();var b=this.randTaxSet(a);a=this.createCanvas(b);this.main.notifications.addLine("statusPos",b.name,{showButterfly:a});var c=this.main.party.getBonus("taxonomySanity");0!==c&&this.main.party.changeSanity(c);this.main.party.inv.changeItemCount("it-butterfly-random",1);var d=this.main.party.inv.getItemById("it-butterfly-collection").subItems;
var e=[];var f=0;for(c=d.length;f<c;f++){var g=d[f];null==g.canvas&&(g.taxSet=b,e.push(g.canvas=a))}return e};gb.prototype.createCanvas=function(a){var b=this.r.createCanvas(48*this.s,48*this.s);var c=b.canvas;var d=this.r.img.butterflyWings;var e=$jscomp.makeIterator([d.width/config.taxonomy.butterflyWings,d.height/2]);var f=e.next().value;e=e.next().value;var g=$jscomp.makeIterator([.5*f*this.s,.5*e*this.s]);var h=g.next().value;g=g.next().value;b.drawImage(d,f*a.wingsBottom,e,f,e,0,0,h,g);b.drawImage(d,
f*a.wingsTop,0,f,e,0,0,h,g);b=this.r.createCanvas(48*this.s,48*this.s);var k=b.canvas;b.drawImage(c,0,0);b.globalCompositeOperation="source-in";d=this.r.img.butterflyPattern;b.drawImage(d,f*a.pattern,0,f,e,0,0,h,g);b.globalCompositeOperation="multiply";"multiply"===b.globalCompositeOperation&&b.drawImage(c,0,0);d=this.r.img.butterflyBody;b.globalCompositeOperation="source-over";c=d.width/config.taxonomy.butterflyBody;f=.5*c*this.s;b.drawImage(d,c*a.body,0,c,e,k.width/2-f/2,0,f,g);return k};gb.prototype.show=
function(){var a;this.debugGallery=[];var b=[];for(a=0;50>=a;++a){var c=this.randTaxSet(["Johannes","Riad"]);c.canvas=this.createCanvas(c);b.push(this.debugGallery.push(c))}return b};gb.prototype.onMouseClick=function(a){switch(this.mouseAction){case "exit":return this.main.popMainState();default:return this.show()}};gb.prototype.draw=function(a,b,c){var d;c=$jscomp.makeIterator(this.r.getCanvasSize());c.next();c.next();this.r.clear(!0);this.r.ctx.globalAlpha=1;this.r.ctx.fillStyle="white";this.r.ctx.font=
"22px Curious";var e=new R(25*this.r.s,25*this.r.s);var f=new u(40*this.r.s,40*this.r.s);var g=this.debugGallery;var h=d=0;for(c=g.length;d<c;h=++d){var k=g[h];var l=$jscomp.makeIterator([k.canvas.width,k.canvas.height]);h=l.next().value;l=l.next().value;this.r.ctx.drawImage(k.canvas,f.x-h/2,f.y);f.x+=h+e.w;if(f.x+h>this.r.ctx.canvas.width&&(f.x=80,f.y+=l+e.h,f.y+l>this.r.ctx.canvas.height))break}if(this.r.drawExitButton("Return",a,b))return this.mouseAction="exit"};var Ba=function(a,b,c){a=W.call(this,
a,b,c)||this;a.rng=new pa(Date.now());a.colorCanvas=document.createElement("canvas");a.colorCanvas.width=config.imgSize.portrait[0];a.colorCanvas.height=config.imgSize.portrait[1];b=a.colorCanvas.getContext("2d");a.r.setImageSmoothing(!1,b);return a};$jscomp.inherits(Ba,W);Ba.prototype.setup=function(a,b){b=void 0===b?0:b;0===b&&(b=this.rng._seed);this.rng=new pa(b);this.id=a;return this.layers=t.getTribeGen(this.id).layers.map(function(a){return t.getTribeGenLayer(a)})};Ba.prototype.show=function(){return this.createGallery()};
Ba.prototype.createGallery=function(a){var b;this.setup(debug.testTribe,void 0===a?0:a);this.genColorTable();this.genKeyTable();var c;a=[];for(b=c=0;98>c;b=++c)b=14>b%28?"male":"female",a.push(this.genSpriteLayers(b));return this.gallery=a};Ba.prototype.draw=function(a,b,c){var d,e;this.r.clear(!0,debug.tribeBackground);this.r.ctx.globalAlpha=1;this.r.ctx.fillStyle="white";this.r.ctx.font="22px Curious";var f=$jscomp.makeIterator(this.r.getCanvasSize());c=f.next().value;f.next();var g=$jscomp.makeIterator([c/
2-700,30]);f=g.next().value;var h=g.next().value;this.r.setImageSmoothing(!1);var k=this.gallery;var l=e=0;for(d=k.length;e<d;l=++e)g=k[l],0===l%14&&(f=c/2-700,h+=100),null==g.portraitSprite&&(l=this.genSprite(g,this.colorTable),g.portraitSprite=l.portrait,null==g.bodySprite&&(g.bodySprite=l.body)),this.r.drawSprite(g.portraitSprite,f,h,{mX:a,mY:b})&&(l=["BODY"],l.add(g.body.map(function(a){return"  "+a.sprite.slice(5)})),l.push("PORTRAIT"),l.add(g.portrait.map(function(a){return"  "+a.sprite.slice(5)})),
this.main.infoBox.showHelp(l)),this.r.drawSprite(g.bodySprite,f+70,h),f+=100;if(this.r.drawExitButton("Return",a,b))return this.mouseAction="exit"};Ba.prototype.onMouseClick=function(a){return"exit"===this.mouseAction?this.main.popMainState():this.createGallery()};Ba.prototype.genColorTable=function(){var a,b,c;var d=function(a,b){var c,d;var e=[];var f=d=0;for(c=a.height;0<=c?d<c:d>c;f=0<=c?++d:--d)f=f*a.width*4+4*b,e.push({r:a.data[f+0],g:a.data[f+1],b:a.data[f+2]});return e};this.colorTable=[];
var e=this.layers;var f=0;for(a=e.length;f<a;f++){var g=e[f];if(null!=g.colors){var h=this.r.img.getSprite(g.colors);g=this.colorCanvas.getContext("2d");var k=$jscomp.makeIterator(h.size.lst());var l=k.next().value;k=k.next().value;g.drawImage(h.img,h.pos.x,h.pos.y,l,k,0,0,l,k);l=g.getImageData(0,0,l,k);g=d(l,0);l=d(l,this.rng.randInt(1,h.size.w));k=c=0;for(b=g.length;c<b;k=++c)h=g[k],this.colorTable.push({col1:h,col2:l[k]})}}};Ba.prototype.genKeyTable=function(){var a=this;var b=function(b,c){var d,
e;var h={};var k=0;for(d=c.length;k<d;k++){var l=c[k];var m="male"===b?l.male:l.female;h[null!=(e=l.key)?e:l.id]=a.rng.randInt(m.length)}return h};var c=this.layers.filter(function(a){return a.tribal}).sample(config.tribeGen.tribalLayers);this.keyTableMale=b("male",c);return this.keyTableFemale=b("female",c)};Ba.prototype.genSpriteLayers=function(a){a=void 0===a?"male":a;var b,c,d,e,f,g,h,k,l,m;null==this.colorTable&&this.genColorTable();null==this.keyTableMale&&this.genKeyTable();var p=[];var q=
[];var t=null;var D=this.layers;var v=0;for(b=D.length;v<b;v++){var y=D[v];var u=y.male;var A=0;for(y=u.length;A<y;A++){var H=u[A];if(null!=H.mounted){t=[];break}}if(null!=t)break}D=Object.clone("male"===a?this.keyTableMale:this.keyTableFemale);logs.tribeGen&&r.log("TribeGen;Choosing layers for "+this.id+": "+a);u=this.layers;b=0;for(v=u.length;b<v;b++)if(y=u[b],H=null!=(f=y.chance)?f:1,!(1>H&&this.rng.random()>H)&&(H="male"===a?y.male:y.female,null!=H)){var G=null!=(g=y.key)?g:y.id;A=null!=D[G]?
D[G]:D[G]=this.rng.randInt(H.length);H=H[A];null==H&&logs.tribeGen&&r.log("TribeGen;Layer "+G+" : "+A+" (no sprite))");null!=H&&(logs.tribeGen&&r.log("TribeGen;Layer "+G+" : "+A+" ("+(null!=(h=null!=(k=H.portrait)?k:H.body)?h:"???")+")"),null!=H.portrait&&q.push({alpha:null!=(l=y.alpha)?l:1,sprite:H.portrait,useInSmall:null!=(m=y.useInSmall)?m:!0}),null!=H.body&&p.push({alpha:null!=(c=y.alpha)?c:1,sprite:H.body}),null!=H.mounted?(n.assert(null!=t),t.push({alpha:null!=(d=y.alpha)?d:1,sprite:H.mounted})):
null!=H.body&&null!=t&&t.push({alpha:null!=(e=y.alpha)?e:1,sprite:H.body}))}a={portrait:q,body:p};null!=t&&(a.mounted=t);return a};Ba.prototype.genSprite=function(a,b){var c=this,d,e;var f=function(a){var b=document.createElement("canvas");b.width=a[0];b.height=a[1];a=b.getContext("2d");c.main.r.setImageSmoothing(!1,a);return a};var g=function(a){var c,d,e;var f=a.getImageData(0,0,a.canvas.width,a.canvas.height);var g=e=0;for(d=f.data.length;e<=d;g=e+=4){var h=0;for(c=b.length;h<c;h++){var k=b[h];
if(f.data[g+0]===k.col1.r&&f.data[g+1]===k.col1.g&&f.data[g+2]===k.col1.b){f.data[g+0]=k.col2.r;f.data[g+1]=k.col2.g;f.data[g+2]=k.col2.b;f.data[g+3]=255;break}}}return a.putImageData(f,0,0)};var h=function(a,b,d,e){e=void 0===e?0:e;var f,g;b.globalAlpha=null!=d?d:1;var h=c.r.img.getSprite(a);if(null!=h){b.drawImage(h.img,h.pos.x+2-e,h.pos.y,h.size.w-4,h.size.h,2,0,h.size.w-4,h.size.h);var k=b.getImageData(2+e,0,h.size.w-4,h.size.h);var l=k.data;d=!1;var m=g=0;for(f=l.length;g<f;m=g+=4){var p=l[m];
var q=l[m+1];var w=l[m+2];a=l[m+3];w=n.rgbToHex(p,q,w);w===config.tribeGen.maskOutColor&&0!==a&&(l[m+3]=0,d=!0)}if(d)return b.putImageData(k,2+e,0,0,0,h.size.w-4,h.size.h)}};var k=f(config.imgSize.portrait);var l=f(config.imgSize.portraitSmall);var m=f(config.imgSize.body);var p=a.portrait;var q=0;for(d=p.length;q<d;q++){var r=p[q];h(r.sprite,k,r.alpha)}q=-(config.imgSize.portrait[0]-config.imgSize.portraitSmall[0])/2;p=a.portrait;var D=0;for(d=p.length;D<d;D++)r=p[D],r.useInSmall&&h(r.sprite,l,r.alpha,
q);q=a.body;d=0;for(p=q.length;d<p;d++)r=q[d],h(r.sprite,m,r.alpha);g(k);g(l);g(m);m={portrait:{id:"tribeGen",img:k.canvas,pos:new u(0,0),scale:2,size:new R(k.canvas.width,k.canvas.height),dSize:new R(2*k.canvas.width,2*k.canvas.height)},portraitSmall:{id:"tribeGen",img:l.canvas,pos:new u(0,0),scale:2,size:new R(l.canvas.width,l.canvas.height),dSize:new R(2*l.canvas.width,2*l.canvas.height)},body:{id:"tribeGen",img:m.canvas,pos:new u(0,0),scale:2,size:new R(m.canvas.width,m.canvas.height),dSize:new R(2*
m.canvas.width,2*m.canvas.height)}};if(null!=a.mounted&&0<a.mounted.length){l=function(a){var b,c,d,e;var f=a.getImageData(0,0,a.canvas.width,a.canvas.height);var g=f.data;var h=b=0;for(d=a.canvas.width;0<=d?b<d:b>d;h=0<=d?++b:--b){var k=c=0;for(e=a.canvas.height;0<=e?c<e:c>e;k=0<=e?++c:--c){var l=4*h+k*a.canvas.width*4;var m=g[l];var p=g[l+1];var q=g[l+2];if(0!==m||0!==p||0!==q)if(q=n.rgbToHex(m,p,q),q===config.tribeGen.mountedColor)return 0<l&&(g[l]=g[l-4],g[l+1]=g[l-3],g[l+2]=g[l-2],g[l+3]=g[l-
1],a.putImageData(f,0,0)),[h,k]}}return null};k=f(config.imgSize.body);p=a.mounted;a=0;for(d=p.length;a<d;a++)r=p[a],h(r.sprite,k,r.alpha);h=l(k);null==h&&(h=[4,14]);g(k);m.mounted={id:"tribeGen",img:k.canvas,pos:new u(0,0),scale:2,size:new R(k.canvas.width,k.canvas.height),dSize:new R(2*k.canvas.width,2*k.canvas.height),socket:[h]}}null!=this.id&&(e=t.getTribeGen(this.id));null!=e&&e.createMiniSprite&&(e=this.r.img.nativeMiniSprite,0<e.width&&0<e.height&&(f=f([e.width,e.height]),f.drawImage(e,0,
0),g(f),m.mini={id:"tribeGen",img:f.canvas,pos:new u(0,0),scale:this.r.s,size:new R(f.canvas.width,f.canvas.height),dSize:new R(f.canvas.width*this.r.s,f.canvas.height*this.r.s)}));return m};var Ta=Ba;var Ka=function(a,b){a=void 0===a?[]:a;b=void 0===b?[]:b;this.path=a;this.pathCost=b;var c;var d=[];var e=0;for(c=b.length;e<c;e++)a=b[e],d.push(Math.min(config.anim.travelTime+config.anim.travelTime*a*.3,config.anim.maxTravelTime));this.travelTimes=d;this.moveTime=this.move=0};Ka.prototype.tick=function(a){return this.moveTime+=
a};Ka.prototype.getAnimPos=function(a){var b=this.move;for(a=this.moveTime-(void 0===a?0:a);0>a;)0<b?(--b,a=this.travelTimes[b]+a):a=0;return[b,this.path[b],this.path[b+1],b<this.travelTimes.length?a/this.travelTimes[b]:0]};Ka.prototype.getTravelSpeed=function(){return 1-this.travelTimes[this.move]/config.anim.maxTravelTime};Ka.prototype.getPos=function(){return this.path[this.move]};Ka.prototype.getNextPos=function(){return this.move+1<this.path.length?this.path[this.move+1]:null};Ka.prototype.getAlpha=
function(){return this.travelTimes.length<=this.move?0:this.moveTime/this.travelTimes[this.move]};Ka.prototype.incMove=function(){this.move+=1;this.moveTime=0;return this.path[this.move]};Ka.prototype.cancel=function(){return this.path.removeAt(this.move+(0===this.moveTime?1:2),this.path.length)};Ka.prototype.isDone=function(){return this.move>=this.path.length-1};var Ma=function(a,b,c,d,e){d=void 0===d?{}:d;e=void 0===e?{}:e;this.find=this.find.bind(this);this.doStep=this.doStep.bind(this);this.tick=
this.tick.bind(this);this.wait=this.wait.bind(this);this.calcCost=this.calcCost.bind(this);this.world=a;this.party=b;this.opts={ignoreUnknown:!0,searchRiver:!1,ignoreTileCost:!1,maxCost:-1};Object.merge(this.opts,e);this.ignoreUnknown=this.opts.ignoreUnknown;this.searchRiver=this.opts.searchRiver;this.moveFlags=this.opts.moveFlags;this.pos1=c;a={pos:c,g:0,h:0,usedItems:d};this.openNodes={};this.openNodes[this.hash(c)]=a;this.openNodeList=[a];this.closedNodes={};this.closedNodesNum=0;this.clear()};
Ma.prototype.clear=function(){this.path=this.pos2=null;return this.done=!0};Ma.prototype.find=function(a){var b;this.pos2=a;this.path=null;this.done=!1;if(null==this.pos2)return this.done=!0,this;a=this.world.getTile(this.pos2);if(null==a||this.ignoreUnknown&&!(null!=a&&a.known||null!=a&&a.farVisible))return this.done=!0,this;if(!(0<this.pos1.dist(this.pos2)))return this.path=[],this.pathCost=0,this.pathItems=[],this.done=!0,this;a=this.closedNodes[this.hash(this.pos2)];if(null!=a&&(0>this.opts.maxCost||
this.opts.maxCost>=a.g)){var c=$jscomp.makeIterator(this.buildPath(a));this.path=c.next().value;this.pathCost=c.next().value;this.pathItems=c.next().value;this.done=!0;return this}var d=this.openNodeList;var e=0;for(b=d.length;e<b;e++)a=d[e],a.h=this.estimateCost(a.pos,this.pos2);this.openNodeList=this.openNodeList.sortBy(function(a){return a.g+a.h});if(debug.showPathFinder)for(c in b=this.closedNodes,b)a=b[c],a.h=this.estimateCost(a.pos,this.pos2);return this};Ma.prototype.buildPath=function(a){var b;
var c=[];var d=[];for(b=[];null!=a.prev;)c.unshift(a.pos),d.unshift(a.g-a.prev.g),b.unshift(a.itemId),a=a.prev;return[c,d,b]};Ma.prototype.doStep=function(){var a;if(this.openNodeList.isEmpty())this.done=!0;else{var b=this.openNodeList.shift();delete this.openNodes[this.hash(b.pos)];this.closedNodes[this.hash(b.pos)]=b;this.closedNodesNum+=1;if(!(0<=this.opts.maxCost&&b.g>this.opts.maxCost)){if(b.pos.eq(this.pos2)){var c=$jscomp.makeIterator(this.buildPath(b));this.path=c.next().value;this.pathCost=
c.next().value;this.pathItems=c.next().value;this.done=!0}c=[];for(a in K){var d=K[a];if(0!==d.val){var e=b.pos.move(d);var f=this.world.getTile(e);if(null!=f&&null==this.closedNodes[this.hash(e)]){if(this.searchRiver){if(t.checkFlags("-river",f.flags))continue}else{if(this.ignoreUnknown&&!f.known)continue;if(null!=this.moveFlags&&!t.checkFlags(this.moveFlags,f.flags))continue;if(f.isBlocking())continue}f=$jscomp.makeIterator(this.calcCost(b.pos,e,b.usedItems));var g=f.next().value;f=f.next().value;
g=b.g+g;var h=this.openNodes[this.hash(e)];var k=null!=h;var l=!1;var m=Object.clone(b.usedItems);null!=f&&(null==m[f]&&(m[f]=0),m[f]+=1);k?h.g>g&&(h.g=g,h.dir=d,h.prev=b,h.itemId=f,h.usedItems=m,this.openNodeList.remove(h),l=!0):(k=this.estimateCost(e,this.pos2),h={pos:e,dir:d,prev:b,g:g,h:k,itemId:f,usedItems:m},this.openNodes[this.hash(h.pos)]=h,l=!0);l?(d=this.openNodeList.findIndex(function(a){return a.g+a.h>h.g+h.h}),-1<d?c.push(this.openNodeList.splice(d,0,h)):c.push(this.openNodeList.push(h))):
c.push(void 0)}}}return c}}};Ma.prototype.tick=function(a){for(a=0;25>a&&!this.done;++a)this.doStep()};Ma.prototype.wait=function(){for(;;){if(this.done)return this.path;this.doStep()}};Ma.prototype.estimateCost=function(a,b){return a.dist(b)};Ma.prototype.hash=function(a){return 1E4*a.y+a.x};Ma.prototype.calcCost=function(a,b,c){if(null==this.party)return[1,null];b=this.world.getTile(b);if(b.isBlocking())return[1E3,null];if(this.opts.ignoreTileCost)return[1,null];a=this.world.getTile(a);a=$jscomp.makeIterator(this.party.getMoveCost(a,
b,c));c=a.next().value;a=a.next().value;null!=a&&(c+=.2);c+=.1*b.zones.length;return[c,a]};var Ob=function(){this.markChanged=this.markChanged.bind(this);this.visible=this.farVisible=this.known=this.farKnown=!1;this.visibleTime=0;this.alpha=-1;this.flags={};this.hasVisibleNeighbor=this.hasNotifiedNeighbors=!1;this.zones=[];this.created=!1;this.viewTurn=-1;this.changed=!1};Ob.prototype.markChanged=function(){if(null!=this.biome&&this.biome.generated)return this.changed=!0};Ob.prototype.setup=function(a){var b,
c,d,e,f,g,h,k,l,m;var p=t.getTile(a);n.assert(null!=p);this.id=this.originalId=p.id;this.name=p.name;this.flags=t.setFlags(p.flags);this.sprite=p.sprites.worldGenSample();this.borderPrio=null!=(b=p.borderPrio)?b:0;this.borderPrioRand=ba.rng.numberRand(100);this.borderTag=null!=(c=p.borderTag)?c:p.id;this.borderOnlyKnown=null!=(d=p.borderOnlyKnown)?d:!1;this.borderSprites=null!=p.borderSprites?p.borderSprites.map(function(a){return t.arrify(a).worldGenSample()}):null;this.imgVariation=ba.rng.randIntMax(config.imgSize.tileVariations);
this.eventImg=p.eventImg;this.events=t.arrify(p.events);this.eventChance=null!=(f=p.eventChance)?f:0<this.events.length?1:0;this.actions=t.arrify(p.actions);this.viewCost=null!=(g=p.viewCost)?g:0;this.travelParticle=null!=(h=p.travelParticle)?h:"pt-travel-default";this.moveSounds=null!=(k=t.arrify(p.moveSounds))?k:["sfx_move_01"];this.hideParty=null!=(l=p.hideParty)?l:!1;null!=p.crumble&&(this.crumble=p.crumble);this.moveCost=Object.isNumber(p.moveCost)?{default:p.moveCost}:p.moveCost;this.passCost=
p.passCost;this.elevation=null!=(m=p.elevation)?m:1;this.particle=p.particle;this.zoneId=this.location=null;d=t.arrify(p.zones);f=0;for(b=d.length;f<b;f++)c=d[f],ba.rng.random()<(null!=(e=c.chance)?e:1)&&(this.zoneId=c.ref);this.sprawls={};e=config.sprawls;for(a in e)if(c=e[a],b=t.initSprawl(p,c),0<b.lifeTime||0<b.chance)this.sprawls[c.id]=b;null!=this.biome&&"tl-void"===this.id&&(this.biome.hasVoid=!0);this.created=!0;return this.markChanged()};Ob.prototype.canStartSprawl=function(a){if(null==this.sprawls)return!1;
a=this.sprawls[a];return null!=a&&!a.active&&0<a.lifeTime};Ob.prototype.isBlocking=function(){return null==this.moveCost?!0:1>this.moveCost.default};var Ab=Ob;var hc=function(a,b){var c,d,e,f,g,h,k,l,m,p,n,r,D,v;this.id=a;this.center=b;this.turnsSinceLastMove=0;this.moveQueue=[];this.dead=this.captured=!1;this.deadTime=0;this.seeking=!1;this.seekTurns=0;a=t.getZone(a);this.name=q.toText(a.name);this.maxSize=ba.rng.randIntA(null!=(c=a.size)?c:[1,1]);this.showOutline=null!=(k=a.showOutline)?k:!0;this.maxSeekTurns=
null!=(l=a.maxSeekTurns)?l:config.zone.defaultSeekTurns;this.alwaysSeeking=null!=(m=a.alwaysSeeking)?m:!1;this.inactiveTurns=null!=(p=a.inactiveTurns)?p:0;this.lifeTurns=ba.rng.randR(null!=(n=a.lifeTurns)?n:"0");this.aggroChance=null!=(r=a.aggroChance)?r:-1;this.eventChance=null!=(D=a.eventChance)?D:0;this.events=a.events;this.moveSpeed=null!=(v=a.moveSpeed)?v:0;this.actions=null!=(d=a.actions)?d:[];this.stopTravel=null!=(e=a.stopTravel)?e:!0;this.flags=t.setFlags(a.flags);this.moveFlags=t.setFlags(null!=
(f=a.moveFlags)?f:"-hill");this.canAttack=null!=(g=a.canAttack)?g:!0;this.sprite=t.arrify(a.sprite).worldGenSample();this.borderImgIdx=null!=(h=a.borderImgIdx)?h:0;this.particle=a.particle};hc.prototype.getSize=function(){return this.outline.tiles.length};hc.prototype.hasPos=function(a){return this.outline.tiles.any(function(b){return b.pos.eq(a)})};hc.prototype.startSeeking=function(){this.seeking=!0;return this.seekTurns=0};var ic=function(a){var b,c,d,e,f,g,h,k,l,m,p,n,q,r,v,y,u,A,H;this.id=a;
this.dayAge=0;this.everUsed=!1;this.knownTime=0;a=t.getLocation(a);this.name=a.name;this.checkReachability=null!=(b=a.checkReachability)?b:!0;this.showHint=null!=(n=a.showHint)?n:!0;this.known=null!=(q=a.showAlways)?q:!this.showHint;this.mapScore=null!=(r=a.mapScore)?r:this.showHint?config.mapScore.locationDiscoveryDefault:0;this.isRemovable=null!=(v=a.isRemovable)?v:!0;this.keepReachable=null!=(y=a.keepReachable)?y:!1;this.hintCompass=null!=(u=a.hintCompass)?u:!1;this.hintBiome=null!=(A=a.hintBiome)?
A:0<this.mapScore;this.worldMap=a.worldMap;this.sprite=a.sprite;this.actions=null!=(H=a.actions)?H:[];this.debugColor=a.debugColor;this.eventImg=a.eventImg;this.maximizeDistance=null!=(c=a.maximizeDistance)?c:!1;this.setTile=null!=(d=t.arrify(a.setTile))?d:[];this.setNeighbors=null!=(e=t.arrify(a.setNeighbors))?e:[];this.initItems=a.initItems;this.priceTable=a.priceTable;this.flags=t.setFlags(a.flags);this.hideParty=null!=(f=a.hideParty)?f:!0;this.subLocations=a.subLocations;this.linked=null!=(g=
a.linked)?g:!1;this.links=[];this.dist=null!=(h=a.dist)?h:config.board.defaultLocationMinDist;this.particle=a.particle;this.mobility=a.mobility;this.spawns=a.spawns;this.events=null!=(k=a.events)?k:[];this.spawnEvents=a.spawnEvents;this.revealEvents=a.revealEvents;this.dayEvents=null!=(l=a.dayEvents)?l:[];this.sprawlEvents=null!=(m=t.arrify(a.sprawlEvents))?m:[];this.hasStash=null!=(p=a.hasStash)?p:!1;this.invs={}};ic.prototype.clearAge=function(){return this.dayAge=0};ic.prototype.setup=function(a,
b){this.biome=a;this.spawnPos=this.pos=b;this.sprite=t.parseLocationPlacing(this.sprite,a).worldGenSample();return this.biome.updateLocations()};ic.prototype.hasActions=function(){return 0<this.actions.length};var sb=ic;var xa=function(a,b){this.getIOMPData=this.getIOMPData.bind(this);this.id="bio-outside-sea";this.pos=a;this.isOutside=b;var c=$jscomp.makeIterator(config.board.biomeSize);b=c.next().value;c=c.next().value;this.offset=new u(a.x*b,a.y*c);this.entered=this.created=!1;this.tiles=[];this.locationQueue=
[];this.locations=[];this.scoreLocations=[];this.hasSprawl={};this.size=new R(config.board.biomeSize);this.imgIdx=1;this.conquered=!1};xa.prototype.setup=function(a,b){var c,d,e;this.id=a;this.blocking=null!=b?b:!1;a=t.getBiome(a);this.name=null!=(c=q.toText(a.name))?c:"";this.debugColor=null!=(d=a.debugColor)?d:"yellow";this.events=null!=(e=a.events)?e:[];this.isOutside||(this.tokenIdx=a.tokenIdx);this.eventImg=a.eventImg;this.spawnEvents=a.spawnEvents;this.flags=t.setFlags(a.flags);return this.clearUnconnected=
a.clearUnconnected};xa.prototype.resetTiles=function(){var a,b,c;var d=$jscomp.makeIterator(config.board.biomeSize);var e=d.next().value;var f=d.next().value;d=[];for(b=a=0;0<=e?a<e:a>e;b=0<=e?++a:--a)d.push(function(){var a;var d=[];for(c=a=0;0<=f?a<f:a>f;c=0<=f?++a:--a)d.push(this.setTile(new u(b,c),new Ab));return d}.call(this));return d};xa.prototype.updateLocations=function(){this.locations=this.tiles.filter(function(a){return null!=a.location}).map(function(a){return a.location});return this.scoreLocations=
this.locations.filter(function(a){var b;return 0<(null!=(b=a.mapScore)?b:0)})};xa.prototype.getCenter=function(a){a=void 0===a?!1:a;var b=new u(Math.round(this.size.w/2-1),Math.round(this.size.h/2));a&&(b=b.add(this.offset));return b};xa.prototype.getFirstTilePos=function(){return new u(this.pos.x*this.size.w,this.pos.y*this.size.h)};xa.prototype.isValid=function(a){var b,c;return 0<=(b=a.x)&&b<this.size.w&&0<=(c=a.y)&&c<this.size.h};xa.prototype.setTile=function(a,b){this.tiles[a.y*this.size.w+a.x]=
b;b.pos=a.add(this.offset);b.localPos=a;b.biome=this;return b.markChanged()};xa.prototype.getTile=function(a){return null!==a&&this.isValid(a)?this.tiles[a.y*this.size.w+a.x]:null};xa.prototype.getCompassLocations=function(){return this.locations.filter(function(a){return a.hintCompass})};xa.prototype.close=function(){this.created=!0;return this.outline=new Ld(this.tiles)};xa.prototype.setClaim=function(a,b){this.claim=a;if(null!=this.claim){var c=this.tiles;var d=0;for(a=c.length;d<a;d++){var e=
c[d];e.known=!0;e.visible=!0;b.setTileCtxDirtyWithNeighbours(e)}this.znCtxDirty=this.ctxDirty=!0;return t.setFlags("+claimed",this.flags)}};xa.prototype.getIOMPData=function(a){var b=this;if(!this.iompDataRequested){this.iompDataRequested=!0;logs.iomp&&r.info("IOMP;Requesting iomp data for biome "+this.pos.toString());var c=a.worldGenIO.world;var d=c.getBiomeIdx(this.pos);a.iomp.getBiomeRecord(d,function(e){var f,g,h;if(null==e){var k=a.worldGenIO.biomes[d].claim;null!=k&&b.setClaim(k,c)}else{var l=
e.claim;if(null!=l){var m=l.userID;k=function(d){d={record:{explorerTribe:l.explorerTribe,explorerSeed:l.explorerSeed,explorerGender:l.explorerGender,claimDate:l.claimDate,userID:l.userID},user:d};a.worldGenIO.getBiomeDict(b.pos).claim=d;return b.setClaim(d,c)};a.iomp.getUser(m,k)}else k=a.worldGenIO.biomes[d].claim,null!=k&&b.setClaim(k,c);m=null!=(h=e.deathRecords)?h:[];var p=b.locations.count(function(a){return a.id===config.io.deathLocation});var n=0;for(f=m.length;n<f;n++){h=m[n];if(p>=config.io.maxDeathLocationsPerBiome)break;
k=b.getTile(h.localPos);if(null!=k&&(null==k.location||k.location.id===config.io.deathLocation)){var q=k.location;if(null==q&&(q=c.addLocation(config.io.deathLocation,[k]),null==q))continue;q.flags=t.setFlags("+userID",q.flags);k=function(a){return q.user=a};a.iomp.getUser(h.userID,k);p+=1}}e=null!=(g=e.locationFlags)?g:[];m=0;for(g=e.length;m<g;m++)h=e[m],k=b.getTile(h.localPos),null!=k&&null!=k.location&&(k.location.flags=t.setFlags(h.flags,k.location.flags),k.location.everUsed=!0)}})}};var S=function(a,
b,c,d,e){e=void 0===e?0:e;var f,g,h;this.getTilesInRadius=this.getTilesInRadius.bind(this);this.getTilesInRange=this.getTilesInRange.bind(this);this.allocateBiome=this.allocateBiome.bind(this);this.getBiomes=this.getBiomes.bind(this);this.getCompassLocations=this.getCompassLocations.bind(this);this.getBiomePosFromIdx=this.getBiomePosFromIdx.bind(this);this.setTile=this.setTile.bind(this);this.scoreLocationPos=this.scoreLocationPos.bind(this);this.parseLocationTiles=this.parseLocationTiles.bind(this);
this.parseLocationNeighbors=this.parseLocationNeighbors.bind(this);this.updateReachability=this.updateReachability.bind(this);this.updateConnectivity=this.updateConnectivity.bind(this);this.updateSea=this.updateSea.bind(this);this.setLocation=this.setLocation.bind(this);this.relinkLocations=this.relinkLocations.bind(this);this.addZone=this.addZone.bind(this);this.removeZonesInRadius=this.removeZonesInRadius.bind(this);this.removeZonesFromTiles=this.removeZonesFromTiles.bind(this);this.deactivateZonesInRadius=
this.deactivateZonesInRadius.bind(this);this.updateZoneArea=this.updateZoneArea.bind(this);this.incLocationsTurn=this.incLocationsTurn.bind(this);this.main=a;this.id=b;this.pocketId=c;this.goalId=d;this.worldSeed=0!==e?e:Date.now();this.r=this.main.r;this.events=this.main.events;this.locationSpawns={};this.zoneSpawns={};this.generated=!1;a=t.getWorld(b);e=$jscomp.makeIterator(a.biomeCount);b=e.next().value;var k=e.next().value;this.biomeCount=new R(b+2,k+2);if(null!=a.startPos){b=$jscomp.makeIterator(a.startPos);
e=b.next().value;var l=b.next().value}else for(;l=$jscomp.makeIterator([ba.rng.numberRand(b-1),ba.rng.numberRand(k-1)]),e=l.next().value,l=l.next().value,0!==e&&e!==b-1||0!==l&&l!==k-1;);this.biomeStartPos=new u(e+1,l+1);this.maxCompassScore=0;null!=a.maxCompassScore&&(this.maxCompassScore=a.maxCompassScore[this.main.difficultyLvl]);this.rivalTurns=n.isIO()?null:a.rivalTurns;this.goalFame=a.goalFame;null!=d&&(d=t.getGoal(d),this.goalFame+=null!=(f=d.extraFame)?f:0);f=t.getPocket(c);null!=f?(this.flags=
t.setFlags(f.flags),this.tribeGen=null!=(g=f.tribeGen)?g:"tg-jungle",this.shipTile=null!=(h=f.shipTile)?h:config.ship.defaultTile):(this.flags=[],this.tribeGen="tg-jungle",this.shipTile=config.ship.defaultTile);this.startPos=null;h=$jscomp.makeIterator(config.board.biomeSize);g=h.next().value;h=h.next().value;this.overallSize=new R(g*this.biomeCount.w,h*this.biomeCount.h);this.resetBiomes(null!=c)};S.prototype.tick=function(a){var b;var c=this.zones;var d=0;for(b=c.length;d<b;d++){var e=c[d];e.dead&&
(e.deadTime+=a)}return this.zones.remove(function(a){return 1<a.deadTime})};S.prototype.lineSign=function(a,b,c){return(a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y)};S.prototype.lineCheck=function(a,b,c,d){if(a.eq(b)||a.eq(c)||a.eq(d)||b.eq(c)||b.eq(d)||c.eq(d))return!1;var e=this.lineSign(a,b,d);b=this.lineSign(a,b,c);return 0>e*b?(a=this.lineSign(c,d,a),0>a*(a+b-e)):!1};S.prototype.getBiomeCount=function(){return this.biomeCount};S.prototype.getArea=function(a,b,c){c=void 0===c?!1:c;if(Object.isString(b)){b=
$jscomp.makeIterator(n.parseRange(b));var d=b.next().value;b=b.next().value;return this.getTilesInRadius(a,b,!0,c).filter(function(b){return b.pos.dist(a)>=d})}if(Object.isNumber(b))return this.getTilesInRadius(a,b,!0,c);if("biome"===b)return this.getTile(a,c).biome.tiles};S.prototype.getTilesInRadius=function(a,b,c,d){var e=this;c=void 0===c?!0:c;d=void 0===d?!1:d;n.assert(null!=a);n.assert(null!=b);if(1===b){b=[];if(c){var f=this.getTile(a,d);c&&null!=f&&b.push(f)}f=0;for(c=Ic.length;f<c;f++){var g=
Ic[f];g=this.getTile(a.move(g),d);null!=g&&b.push(g)}return b}return a.radius(b).map(function(a){return e.getTile(a,d)}).compact()};S.prototype.getTilesInRange=function(a,b,c,d){var e=this;d=void 0===d?!1:d;n.assert(null!=a);n.assert(null!=b);return a.range(b).map(function(a){return e.getTile(a,d)}).compact()};S.prototype.getLocationsArea=function(a,b,c){var d=this;c=void 0===c?0:c;var e=this.getLocationPositions().map(function(a){return d.getTile(a)});if("biome"===c){var f=this.getTile(a);e=e.filter(function(a){return a.biome.pos.eq(f.biome.pos)})}else if("closest"===
c)e=e.min(function(b){return b.pos.dist(a)});else{b=$jscomp.makeIterator(null!=b?b.parseRangeBonus(c):n.parseRange(c));var g=b.next().value;var h=b.next().value;e=e.filter(function(b){var c;return g<=(c=b.pos.dist(a))&&c<=h})}return e};S.prototype.getZonesInRadius=function(a,b){return this.getTilesInRadius(a,b).map(function(a){return a.zones}).flatten().compact().unique(function(a){return a.center})};S.prototype.resetBiomes=function(a){var b,c,d,e;this.biomes={};this.biomeArray=[];this.zones=[];if(void 0===
a||a){var f=$jscomp.makeIterator(this.getBiomeCount().lst());a=f.next().value;f=f.next().value;for(b=d=0;0<=a?d<a:d>a;b=0<=a?++d:--d){var g=e=0;for(c=f;0<=c?e<c:e>c;g=0<=c?++e:--e)this.allocateBiome(b,g)}}c=this.getBiomes().worldGenRandomize();f=b=0;for(g=c.length;b<g;f=++b){a=c[f];if(f+2>=config.imgSize.biomeBgVariations)break;a.imgIdx=f+2}};S.prototype.allocateBiome=function(a,b){var c=$jscomp.makeIterator(this.getBiomeCount().lst());var d=c.next().value;c=c.next().value;d=0===a||0===b||a===d-1||
b===c-1;a=new xa(new u(a,b),d);b=this.getBiomeIdx(a.pos);n.assert(null!=b);n.assert(null==this.biomes[b],"Biome index already in use!");this.biomes[b]=a;n.assert(this.getBiome(a.pos)===a);a.resetTiles();this.biomeArray=Object.values(this.biomes);n.isIO()&&(b=this.main.worldGenIO.getBiomeDict(a.pos),a.imgIdx=b.bgImgIdx);return a};S.prototype.getBiomes=function(){return this.biomeArray};S.prototype.getCompassLocations=function(){return this.getBiomes().map(function(a){return a.getCompassLocations()}).flatten()};
S.prototype.toBiomePos=function(a){var b=$jscomp.makeIterator(config.board.biomeSize);var c=b.next().value;b=b.next().value;return new u(Math.floor(a.x/c),Math.floor(a.y/b))};S.prototype.toLocalPos=function(a){var b=$jscomp.makeIterator(config.board.biomeSize);var c=b.next().value;b=b.next().value;var d=new u(Math.floor(a.x/c),Math.floor(a.y/b));return[this.getBiome(d,!1),new u(a.x-d.x*c,a.y-d.y*b)]};S.prototype.toLocalPos_fast=function(a,b,c){c=void 0===c?!1:c;var d=config.board.biomeSize[0];var e=
config.board.biomeSize[1];null==this.toLocalPos_fast_bP&&(this.toLocalPos_fast_bP=new u(0,0));this.toLocalPos_fast_bP.x=Math.floor(a.x/d);this.toLocalPos_fast_bP.y=Math.floor(a.y/e);b.biome=this.getBiome(this.toLocalPos_fast_bP,c);b.lp.x=a.x-this.toLocalPos_fast_bP.x*d;return b.lp.y=a.y-this.toLocalPos_fast_bP.y*e};S.prototype.isValidBiomePos=function(a){var b,c;var d=this.getBiomeCount();return 0<=(b=a.x)&&b<d.w&&0<=(c=a.y)&&c<d.h};S.prototype.getBiomeIdx=function(a){return 0>a.x||0>a.y||a.x>=this.biomeCount.x||
a.y>=this.biomeCount.h?null:this.biomeCount.w*a.y+a.x};S.prototype.getBiomePosFromIdx=function(a){var b=a%this.biomeCount.w;return new u(b,(a-b)/this.biomeCount.w)};S.prototype.getBiome=function(a,b){b=void 0===b?!0:b;var c;var d=this.getBiomeIdx(a);var e=null!=(c=this.biomes[d])?c:null;b&&null==e&&null!=d&&(e=this.allocateBiome(a.x,a.y));n.assert(null==e||e.pos.eq(a),"getBiome got wrong biome!");return e};S.prototype.getCenterBiomePos=function(){var a=this.getBiomeCount();return new u((a.w-1)/2,
(a.h-1)/2)};S.prototype.getCenter=function(){return new u(Math.floor(this.overallSize.w/2),Math.floor(this.overallSize.h/2))};S.prototype.setTile=function(a,b){var c,d;var e=this.getTile(a);var f=$jscomp.makeIterator(this.toLocalPos(a));var g=f.next().value;f=f.next().value;g.setTile(f,b);if(null!=e){b.visible=e.visible;b.farVisible=e.farVisible;b.known=e.known;b.farKnown=e.farKnown;b.hasVisibleNeighbor=e.hasVisibleNeighbor;b.zones=e.zones;b.locationScores=e.locationScores;f=t.getTile(e.id);n.assert(null!=
f);f=t.setFlags(f.flags);for(h in f)(d=f[h])&&e.flags[h]&&delete e.flags[h];Object.merge(b.flags,e.flags);var h=e.sprawls;for(c in h)f=h[c],f.active&&this.startSprawl(c,a,0,f.power);if(null!=e.location){if(this.matchTile(b,e.location)||!e.location.isRemovable)b.location=e.location;else this.onLocationRemoved(e.location);return g.updateLocations()}}};S.prototype.onLocationRemoved=function(a){var b;if(a.hasStash&&0<(null!=(b=a.invs.stash)?b.items.compact().length:void 0))return this.main.exped.lostStashTime=
0};S.prototype.isValid=function(a){return null!=this.toBiomePos(a)[0]};S.prototype.getTile=function(a,b){b=void 0===b?!1:b;if(null===a)return null;null==this.getTileRes&&(this.getTileRes={biome:null,lp:new u(0,0)});this.toLocalPos_fast(a,this.getTileRes,b);if(null==this.getTileRes.biome)return null;a=this.getTileRes.biome.getTile(this.getTileRes.lp);if(null!=a)return a};S.prototype.validSpawnTile=function(a){return a.biome.generated&&this.validSpawnPos(a.pos)&&!a.isBlocking()};S.prototype.validSpawnPos=
function(a){var b,c;return 0<(b=a.x)&&b<this.overallSize.w-1&&0<(c=a.y)&&c<this.overallSize.h-1};S.prototype.findPartyPos=function(a,b){var c=this;a=void 0===a?!0:a;b=void 0===b?!0:b;var d=this.getBiome(this.biomeStartPos);var e=d.getCenter(!0);var f=this.getCenter();d=d.tiles.filter(function(d){return d.isBlocking()?!1:a?d.known&&b?!1:c.getTilesInRadius(d.pos,1).any(function(a){return a.sea}):!0}).max(function(a){return 3*f.dist(a.pos)-e.dist(a.pos)});return null!=d?d.pos:null};S.prototype.hasReachableNeighbor=
function(a){return this.getTilesInRadius(a.pos,1).any(function(b){return b.reachable&&(!n.isIO()||b.biome===a.biome)})};S.prototype.matchTile=function(a,b){return null!=b.setTile&&t.arrify(b.setTile).map(function(a){return Object.isString(a)?a:a.ref}).any(a.id)?!0:!a.isBlocking()};S.prototype.distNextFixt=function(a,b){return((void 0===b?0:b)?a.biome.locations.filter(function(a){return 0<a.actions.length}):a.biome.locations).map(function(b){return b.pos.dist(a.pos)}).min()};S.prototype.scoreLocationPos=
function(a,b,c){c=void 0===c?!0:c;var d,e,f,g,h,k;var l=1E4;if(null!=a.location||!this.validSpawnPos(a.pos)||!this.hasReachableNeighbor(a))return 0;var m=config.board.biomeSafeZone;m=new u(m,m);if(a.biome!==(null!=(d=this.getTile(a.pos.add(m)))?d.biome:void 0)){if(b.id===config.specialLocations.treasure&&n.isIO())return 0;l-=3E3}if(a.biome!==(null!=(f=this.getTile(a.pos.sub(m)))?f.biome:void 0)){if(b.id===config.specialLocations.treasure&&n.isIO())return 0;l-=3E3}null==this.startPos||null!=this.main.worldGenIO&&
this.main.worldGenIO.world===this||(b.maximizeDistance&&(l+=15*a.pos.dist(this.startPos)),6>a.pos.dist(this.startPos)&&(l-=1E3));f=(d=b.id===config.specialLocations.treasure&&n.isIO())?null!=(e=a.biome.locations.filter(function(a){return a.id===config.specialLocations.treasure}).map(function(b){return b.pos.dist(a.pos)}).min())?e:0:null!=(g=this.distNextFixt(a,!0))?g:0;3>=f?l-=3E3:(d||(f=null!=(h=this.distNextFixt(a,!1))?h:0),l=2>=f?l-1E3:l+200*f);g=this.parseLocationTiles(b,a.biome);d=0;for(e=g.length;d<
e;d++)h=g[d],a.id===h&&(l+=1E3);h=this.parseLocationNeighbors(b,a.biome);g=this.getTilesInRadius(a.pos,1,!1);d=0;for(b=g.length;d<b;d++)if(e=g[d],k=e.id,0<=F.call(h,k))l+=100,h.remove(e.id);c&&(l+=ba.rng.numberRand(1,100));return l};S.prototype.addLocation=function(a,b,c){var d=this;c=void 0===c?!0:c;var e,f;var g=Object.isString(a)?new sb(a):a;if(null!=g.pos)return g;var h=new sb(a);b=b.map(function(b){b.tempScore=d.scoreLocationPos(b,h);null==b.locationScores&&(b.locationScores=[]);b.locationScores.push({score:b.tempScore,
id:a});return b}).sortBy(function(a){return a.tempScore},!0);var k=b.filter(function(a){return 0<a.tempScore}).first(3);var l=0;for(b=k.length;l<b;l++){var m=k[l];if(this.setLocation(m,g,c)){m.biome.updateLocations();m.ctxDirty=!0;m.biome.ctxDirty=!0;c=this.getTilesInRadius(m.pos,1);m=0;for(b=c.length;m<b;m++)k=c[m],k.biome.ctxDirty=!0;null==(e=this.locationSpawns)[f=g.id]&&(e[f]=0);this.locationSpawns[g.id]+=1;return g}}return null};S.prototype.parseLocationTiles=function(a,b){return t.parseLocationPlacing(a.setTile,
b)};S.prototype.parseLocationNeighbors=function(a,b){return t.parseLocationPlacing(a.setNeighbors,b)};S.prototype.updateReachability=function(a,b){b=void 0===b?null:b;var c,d;var e=this.getBiomes();var f=0;for(d=e.length;f<d;f++){var g=e[f];var h=g.tiles;var k=0;for(g=h.length;k<g;k++){var l=h[k];l.reachable=!1}}for(d=[this.getTile(a)];0<d.length;)if(a=d.shift(),!(a.reachable||null!=b&&a.pos.eq(b)))for(c in a.reachable=!0,K)e=K[c],0!==e.val&&(e=a.pos.move(e),e=this.getTile(e),null==e||e.reachable||
e.isBlocking()||d.push(e))};S.prototype.updateConnectivity=function(a){var b,c;var d=this.getBiomes();var e=0;for(c=d.length;e<c;e++){var f=d[e];var g=f.tiles;var h=0;for(f=g.length;h<f;h++){var k=g[h];k.connected=!1}}d=[this.getTile(a)];for(a=t.parseFlags("+pit | +void | +river");0<d.length;)if(c=d.shift(),null!=c&&!c.connected&&!t.checkFlags(a,c.flags))for(b in c.connected=!0,K)e=K[b],0!==e.val&&(e=c.pos.move(e),e=this.getTile(e),null==e||e.connected||d.push(e))};S.prototype.updateSea=function(){var a,
b;var c=[];var d=this.getBiomes();var e=0;for(b=d.length;e<b;e++){var f=d[e];var g=f.tiles;var h=0;for(f=g.length;h<f;h++){var k=g[h];k.sea=!1;(t.checkFlags("+river",k.flags)&&0===k.pos.x||0===k.pos.y)&&c.push(k)}}for(;0<c.length;)if(b=c.shift(),!b.sea&&!t.checkFlags("-river",b.flags))for(a in b.sea=!0,K)d=K[a],0!==d.val&&(d=b.pos.move(d),d=this.getTile(d),null==d||d.sea||c.push(d))};S.prototype.setLocation=function(a,b,c){c=void 0===c?!0:c;var d,e,f,g,h;var k=function(a){var b;for(b in K){var c=
K[b];if(a===c.abbr)return c}return r.error("Unable to get hexDir for string '"+a+"'")};if(null!=b.setTile){var l=this.parseLocationTiles(b,a.biome).first();if(null!=l&&(a=this.replaceTile(a,l,{ignoreOriginalId:!0,checkReachability:b.checkReachability&&this!==(null!=(d=this.main.worldGenIO)?d.world:void 0),animate:c}),null==a))return!1}a.location=b;a.zone=null;a.markChanged();b.setup(a.biome,a.pos);n.assert(null!=a.location);var m=this.parseLocationNeighbors(b,a.biome);if(0<m.length){d=this.getTilesInRadius(b.pos,
1,!1).worldGenRandomize();if(n.isIO())for(g=f=e=m.length-1;0>=e?0>f:0<f;g=0>=e?++f:--f)l=d.find(function(a){return a.id===m[g]}),null!=l&&(m.splice(g),d.remove(l));var p=0;for(l=m.length;p<l;p++){e=m[p];f=d.shift();if(null==f)break;(f.biome.generated||f.biome===a.biome)&&this.replaceTile(f,e,{ignoreOriginalId:!0,animate:c})}}null!=b.spawnEvents&&this.main.doRandEvent(b.spawnEvents,{world:this,pos:b.pos,location:b,silent:!0});d=[];if(null!=b.subLocations){var q=/(\d*)(\w+)/;var da=t.arrify(b.subLocations);
l=0;for(f=da.length;l<f;l++){var D=da[l];var v=D.offsets.split(" ");e=0;for(p=v.length;e<p;e++){var y=v[e];var u=q.exec(y);y=null!=(h=D.chance)?h:1;ba.rng.random()<y&&(y=[t.arrify(D.ref).worldGenSample(),parseInt(u[1]),k(u[2]),1>y],null!=y[2]&&d.push(y))}}h=0;for(l=d.length;h<l;h++)(p=$jscomp.makeIterator(d[h]),k=p.next().value,f=p.next().value,e=p.next().value,p=p.next().value,e=this.getTile(a.pos.move(e,f)),null==e||!e.biome.generated&&e.biome!==a.biome||p&&e.isBlocking()||(f=e.location,null!=f&&
(!f.isRemovable||f.showHint)))||(f=new sb(k),this.setLocation(e,f,c)?(e=this.getTile(e.pos),f.linked&&b.links.push(e)):r.warn("could not place sub loc "+k))}return!0};S.prototype.getDowsingLocation=function(a,b){return this.getLocations().filter(function(a){return t.checkFlags(b,a.flags)}).min(function(b){return a.dist(b.pos)})};S.prototype.relinkLocations=function(){var a,b,c;var d=function(a){var b;for(b in K){var c=K[b];if(a===c.abbr)return c}return r.error("Unable to get hexDir for string '"+
a+"'")};var e=this.getLocations();var f=0;for(b=e.length;f<b;f++){var g=e[f];g.links=[];if(null!=g.subLocations){var h=[];var k=/(\d*)(\w+)/;var l=t.arrify(g.subLocations);var m=0;for(a=l.length;m<a;m++){var p=l[m];var n=p.offsets.split(" ");var q=0;for(c=n.length;q<c;q++){var D=n[q];D=k.exec(D);h.push([t.arrify(p.ref),parseInt(D[1]),d(D[2])])}}a=0;for(c=h.length;a<c;a++)l=$jscomp.makeIterator(h[a]),q=l.next().value,p=l.next().value,l=l.next().value,p=this.getTile(g.pos.move(l,p)),null!=p&&null!=
p.location&&q.includes(p.location.id)&&p.location.linked&&(g.links.push(p),p.location.known=g.known)}}};S.prototype.getLocations=function(){return this.getBiomes().map(function(a){return a.locations}).flatten()};S.prototype.getLocationPositions=function(){return this.getBiomes().map(function(a){return a.locations.map(function(a){return a.pos})}).flatten()};S.prototype.replaceTile=function(a,b,c){c=void 0===c?{}:c;var d,e;var f={checkReachability:this!==(null!=(e=this.main.worldGenIO)?e.world:void 0),
ignoreOriginalId:!1,animate:!0};Object.merge(f,c);c=new Ab;c.biome=a.biome;c.setup(b);f.animate||(c.alpha=a.alpha,c.visibleTime=a.visibleTime);if(f.checkReachability&&c.isBlocking()){b=null!=(d=this.main.party.pos)?d:this.startPos;this.updateReachability(b,a.pos);var g=this.getLocations();var h=0;for(b=g.length;h<b;h++)if(e=g[h],((d=null!=this.main.tutorial||e.keepReachable)||!this.generated&&0<e.mapScore)&&!this.hasReachableNeighbor(this.getTile(e.pos)))return null}if(null!=a.location&&!a.location.isRemovable&&
c.isBlocking())return null;c.reachable=!c.isBlocking();c.zones=a.zones;f.ignoreOriginalId||(c.originalId=a.originalId);this.setTile(a.pos,c);this.setTileCtxDirtyWithNeighbours(c);return c};S.prototype.setTileCtxDirtyWithNeighbours=function(a,b){a.ctxDirty=!0;a.biome.ctxDirty=!0;a=this.getTilesInRadius(a.pos,void 0===b?1:b,!1);var c=0;for(b=a.length;c<b;c++){var d=a[c];d.ctxDirty=!0;d.biome.ctxDirty=!0}};S.prototype.setZoneCtxDirtyWithNeighbours=function(a,b){a.biome.znCtxDirty=!0;a=this.getTilesInRadius(a.pos,
void 0===b?1:b,!1);var c=0;for(b=a.length;c<b;c++){var d=a[c];d.biome.znCtxDirty=!0}};S.prototype.replaceLocation=function(a,b){var c=a.location;b=new sb(b);b.known=a.location.known;this.setTileCtxDirtyWithNeighbours(a);this.setLocation(a,b);return this.onLocationRemoved(c)};S.prototype.removeLocation=function(a){if(null==a.location||a.location.isRemovable){var b=a.location;a.location=null;a.ctxDirty=!0;a.biome.ctxDirty=!0;a.markChanged();a.biome.updateLocations();return this.onLocationRemoved(b)}};
S.prototype.isValidZonePos=function(a,b){var c,d;var e=this.getTile(a);if(null==e||e.isBlocking()||!t.checkFlags(b.moveFlags,e.flags))return!1;var f=e.zones;var g=0;for(d=f.length;g<d;g++){var h=f[g];if(h!==b&&a.eq(h.center))return!1}a=e.sprawls;for(c in a)if(b=a[c],b.active&&b.blockZone)return!1;return!0};S.prototype.addZone=function(a,b,c,d,e,f){d=void 0===d?!1:d;e=void 0===e?0:e;f=void 0===f?!1:f;var g;var h=this.getTilesInRange(b,c);c=new hc(a);f&&this.updateReachability(b);h=h.worldGenRandomize();
var k=0;for(b=h.length;k<b;k++){var l=h[k];if((!f||l.reachable)&&this.isValidZonePos(l.pos,c))return c.center=l.pos,this.updateZoneArea(c),this.zones.push(c),c.seeking=d,c.seekTurns=e,null==(g=this.zoneSpawns)[a]&&(g[a]=0),this.zoneSpawns[a]+=1,!0}return!1};S.prototype.getZoneTiles=function(a){return this.getTilesInRadius(a.center,a.maxSize).filter(function(b){return 0<=F.call(b.zones,a)})};S.prototype.removeZone=function(a){var b;if(!a.dead){var c=this.getZoneTiles(a);var d=0;for(b=c.length;d<b;d++){var e=
c[d];e.zones.remove(a);e.biome.znCtxDirty=!0}return a.dead=!0}};S.prototype.removeZonesInRadius=function(a,b,c){a=this.getTilesInRadius(a,b);this.removeZonesFromTiles(a,c)};S.prototype.removeZonesFromTiles=function(a,b){var c;var d=0;for(c=a.length;d<c;d++){var e=a[d];var f=e.zones;var g=0;for(e=f.length;g<e;g++){var h=f[g];null!=h&&t.checkFlags(b,h.flags)&&this.removeZone(h)}}};S.prototype.deactivateZonesInRadius=function(a,b,c){var d=this.getZonesInRadius(a,b);b=0;for(a=d.length;b<a;b++){var e=
d[b];e.seeking=!1;e.inactiveTurns=c;e.moveQueue=[];var f=this.getZoneTiles(e);var g=0;for(e=f.length;g<e;g++){var h=f[g];h.biome.znCtxDirty=!0}}};S.prototype.moveZoneRand=function(a,b,c){var d;var e=null!=(d=a.moveQueue.last())?d:a.center;if(a.seeking){c=new Ma(this,null,e,{},{ignoreUnknown:!1,moveFlags:a.moveFlags});c.find(this.main.party.pos);c=c.wait();if(null==c)return;c=c.first(b)}else c=Ea.worldGenRandomize().map(function(a){return e.move(a)});var f=0;for(b=c.length;f<b;f++)if(d=c[f],this.isValidZonePos(d,
a)){a.moveQueue.push(d);break}};S.prototype.canStartSprawl=function(a,b,c){return this.getTilesInRadius(b,void 0===c?0:c).any(function(b){return null!=b&&b.canStartSprawl(a)})};S.prototype.startSprawl=function(a,b,c,d,e){d=void 0===d?100:d;e=void 0===e?1:e;var f,g,h;b=this.getTilesInRadius(b,void 0===c?0:c);b=b.filter(function(b){return null!=b&&b.canStartSprawl(a)}).worldGenSample(e);var k=0;for(e=b.length;k<e;k++){c=b[k];c.biome.hasSprawl[a]=!0;c.sprawls[a].active=!0;c.sprawls[a].power=d;var l=
t.getSprawl(a);c.particle=l.particle;null!=l.camShake&&this.r.cam.addCamShake(null!=(f=l.camShake.power)?f:1,null!=(g=l.camShake.length)?g:.2);l=t.arrify(null!=(h=c.location)?h.sprawlEvents.find(function(b){return b.id===a}):void 0);null!=l&&this.main.doRandEvent(l,{world:this,pos:c.pos,loc:c.location})}};S.prototype.incSprawlTurn=function(a){var b,c,d;var e=Object.values(config.sprawls);var f=0;for(b=e.length;f<b;f++){var g=e[f];var h=g.id;var k=[];var l=0;for(c=a.length;l<c;l++){var m=a[l];if(m.generated&&
m.hasSprawl[h]){var p=!1;var n=m.tiles;var q=0;for(d=n.length;q<d;q++){var r=n[q];g=r.sprawls[h];null!=g&&g.active&&(k.add(this.incSprawlTileTurn(r,h)),p||(p=g.active))}m.hasSprawl[h]=p;"spr-void"===h&&(m.hasVoid=!0)}}m=0;for(p=k.length;m<p;m++)c=$jscomp.makeIterator(k[m]),q=c.next().value,c=c.next().value,this.startSprawl(h,q,0,c)}};S.prototype.incSprawlTileTurn=function(a,b){var c;var d=t.getSprawl(b);var e=a.sprawls[b];var f=[];if(0<e.lifeTime){--e.lifeTime;var g=!1;if(0<e.power){var h=this.getTilesInRadius(a.pos,
1,!1);var k=0;for(c=h.length;k<c;k++){var l=h[k];null!=l.biome&&l.biome.generated&&l.canStartSprawl(b)&&(g=!0,ba.rng.random()>l.sprawls[b].chance||f.push([l.pos,e.power-1]))}}!g&&d.forceOuter&&(e.lifeTime=0)}if(0>=e.lifeTime&&(e.active=!1,a.particle=null,null!=e.burnedTile&&(g=e.burnedTile,"regen"===g&&(g=a.originalId),a=this.replaceTile(a,g,{checkReachability:!1})),null!=a)){null!=a.location&&t.checkFlags(d.removeLocation,a.location.flags)&&this.removeLocation(a);g=Object.clone(a.zones);c=0;for(d=
g.length;c<d;c++)l=g[c],this.updateZoneArea(l);delete a.sprawls[b]}return f};S.prototype.incZonesTurn=function(a,b){var c=this,d,e;a=a.map(function(a){return c.getBiomeIdx(a.pos)});var f=Object.clone(this.zones);var g=0;for(d=f.length;g<d;g++){var h=f[g];var k=this.getBiomeIdx(this.toBiomePos(h.center));if(a.includes(k)&&!h.dead){0<h.moveQueue.length&&(this.updateZoneArea(h,h.moveQueue.last()),h.moveQueue=[]);if(0<h.lifeTurns&&(--h.lifeTurns,0>=h.lifeTurns)){this.removeZone(h);break}if(0<h.inactiveTurns)--h.inactiveTurns;
else{if(h.seeking){h.seekTurns+=1;if(h.seekTurns<config.zone.aggroDelay)continue;h.seekTurns>(e=h.maxSeekTurns)&&0<e&&(h.seeking=!1)}else h.alwaysSeeking&&h.startSeeking();h.turnsSinceLastMove+=h.moveSpeed;k=h.turnsSinceLastMove.floor();0<k&&(h.turnsSinceLastMove-=k,this.moveZoneRand(h,k,b))}}}};S.prototype.updateZoneArea=function(a,b){var c=this;b=void 0===b?null:b;var d;var e=function(b){var d;var f=c.getTile(b);if(null!=f&&f.checkZone&&c.isValidZonePos(b,a)){0<=F.call(f.zones,a)||f.zones.push(a);
f.checkZone=!1;f.biome.znCtxDirty=!0;var g=0;for(d=Ea.length;g<d;g++)f=Ea[g],0<f.val&&e(b.move(f))}};var f=this.getTile(a.center);if(f.isBlocking())this.removeZone(a);else{f=f.sprawls;for(d in f){var g=f[d];if(g.active&&g.blockZone){this.removeZone(a);return}}if(null==b||this.isValidZonePos(b,a)){f=this.getTilesInRadius(a.center,a.maxSize);var h=0;for(d=f.length;h<d;h++)g=f[h],g.zones.remove(a),g.biome.znCtxDirty=!0;null!=b&&(a.center=b);b=this.getTilesInRadius(a.center,a.maxSize);g=0;for(f=b.length;g<
f;g++)d=b[g],d.checkZone=!0;e(a.center);f=0;for(g=b.length;f<g;f++)d=b[f],d.checkZone=!1}}};S.prototype.incLocationsTurn=function(a){var b=a.map(function(a){return a.locations}).flatten();var c=0;for(a=b.length;c<a;c++){var d=b[c];d.dayAge+=1;this.events.doRandEvent(d.dayEvents,{world:this,pos:d.pos,location:d,silent:!0,age:d.dayAge})}};S.prototype.drawEmptyBiomeBackground=function(a){var b=new R(config.board.biomeSize);var c=new R(b.w*(this.r.biomeScreenSize.w-this.r.biomeScreenOffset.w),b.h*(this.r.biomeScreenSize.h-
this.r.biomeScreenOffset.h));this.r.ctx.globalAlpha=1;var d=0>=a.x||0>=a.y||a.x>=this.getBiomeCount().w-1||a.y>=this.getBiomeCount().h-1;var e=!d&&!this.main.isWarping()&&n.isIO()&&null!=this.main.worldGenIO.getBiomeDict(a).claim;e=d||e?this.r.img.biomeBackgroundTinted:this.r.img.biomeBackground;var f=e.width/config.imgSize.biomeBgVariations;d=Math.abs(a.x+a.y)%config.imgSize.biomeBgVariations;if(n.isIO()&&this===this.main.worldGenIO.world){var g=this.main.worldGenIO.getBiomeDict(a);null!=g&&(d=g.bgImgIdx)}if(n.isChina())switch(d){case 2:d=
1;break;case 4:d=6;break;case 5:d=3;break;case 7:d=0}a=new u(a.x*b.w,a.y*b.h);a=this.r.getTileScreenPos(a);return this.r.ctx.drawImage(e,f*d,0,f,e.height,a.x,a.y,c.w,c.h)};S.prototype.drawBiome=function(a,b){var c=this.getBiome(a,!1);n.isIO()&&(null!=c&&c.generated||0!==this.main.worldGenIO.worldGenQueue.length||this.main.worldGenIO.shouldGenerateOnScreenBiome(a)&&this.main.worldGenIO.generateBiome(a),c&&c.generated&&this.main.worldGenIO.shouldGenerateOnScreenBiome(a)&&!c.iompDataRequested&&c.getIOMPData(this.main));
if(null!=c&&c.generated)return this.r.drawBiomeToScreen(c,this,b),c;this.drawEmptyBiomeBackground(a);return null};var ub=function(a){a=void 0===a?[]:a;this.hasPos=this.hasPos.bind(this);this.removeRadius=this.removeRadius.bind(this);this.tiles=a;this.updateEdges()};ub.prototype.hasPos=function(a,b){return null!=b?b.any(function(b){return b.eq(a)}):this.tiles.any(function(b){return b.pos.eq(a)})};ub.prototype.removeRadius=function(a,b){this.tiles.remove(function(c){return c.pos.dist(a)<=b});return this.updateEdges()};
ub.prototype.addTile=function(a){this.tiles.push(a);return this.updateEdges()};ub.prototype.removeTile=function(a){this.tiles.remove(a);return this.updateEdges()};ub.prototype.updateEdges=function(){var a;this.edges=[];var b=this.tiles.map(function(a){return a.pos});var c=this.tiles;var d=0;for(a=c.length;d<a;d++){var e=c[d];var f=[];this.hasPos(e.pos.move(K.n),b)||f.push(K.n);this.hasPos(e.pos.move(K.ne),b)||f.push(K.ne);this.hasPos(e.pos.move(K.se),b)||f.push(K.se);this.hasPos(e.pos.move(K.s),b)||
f.push(K.s);this.hasPos(e.pos.move(K.sw),b)||f.push(K.sw);this.hasPos(e.pos.move(K.nw),b)||f.push(K.nw);this.edges.push(f)}};var Ld=ub;var ba=function(){var a=function(a,c,d,e,f,g){f=void 0===f?!1:f;g=void 0===g?0:g;this.randBorderBiome=this.randBorderBiome.bind(this);this.initBiome=this.initBiome.bind(this);this.buildBiomes=this.buildBiomes.bind(this);this.buildPerlin=this.buildPerlin.bind(this);this.getBiomeRiverWorldPos=this.getBiomeRiverWorldPos.bind(this);this.smoothBiomeWithNeighbour=this.smoothBiomeWithNeighbour.bind(this);
this.buildSmoothingIO=this.buildSmoothingIO.bind(this);this.buildSmoothing=this.buildSmoothing.bind(this);this.buildRandZones=this.buildRandZones.bind(this);this.updateReachabilityIO=this.updateReachabilityIO.bind(this);this.randGroupBuildList=this.randGroupBuildList.bind(this);this.main=a;this.r=this.main.r;this.s=this.main.r.s;this.worldId=c;this.pocketId=d;this.goalId=e;this.isWarping=f;this.worldSeed=g;0===this.worldSeed&&(this.worldSeed=Date.now());null!=c&&this.initWorld();this.logDetail="";
this.logTime=100;this.loadingTexts=[];this.allLoadingTexts=q.toText("txt-loading-entries").split("|");null!=this.world&&this.clear()};a.prototype.clear=function(){this.created=!1;for(this.resetCount=0;!this.buildBiomes(););this.buildLocationQueue();return this.resetBuildSteps()};a.prototype.initWorld=function(){var a;this.initRNG();null==this.world?this.world=new S(this.main,this.worldId,this.pocketId,this.goalId,this.worldSeed):this.world.resetBiomes(this.pocketId);this.previewSprite=t.getPocket(this.pocketId).previewSprite;
return this.blockedBiomes=null!=(a=t.getWorld(this.worldId).blockedBiomes)?a:0};a.prototype.initForBiome=function(a,c){this.biomeToGenerate=a;this.blockedBiomes=0;this.created=!1;this.resetCount=0;this.biomeIsBlocking=c;this.resetBuildSteps()};a.prototype.resetBuildSteps=function(){var a,c;this.buildSteps=[];if(null!=this.biomeToGenerate){var d=["initRNG","initBiome","buildPerlin","buildSmoothingIO","updateReachabilityIO"];var e=this.main.worldGenIO.getBiomeDict(this.biomeToGenerate.pos);this.biomeLocations=
Object.clone(e.locations);var f=0;for(e=this.biomeLocations.length;0<=e?f<e:f>e;0<=e?++f:--f)d.push("buildSingleLocation");d.push("buildRivers");d.push("buildRandZones");d.push("updateFromSaveData");var g=0;for(f=d.length;g<f;g++)e=d[g],this.buildSteps.push(e),this.buildSteps.push(this[e].bind(this,this.biomeToGenerate))}else for(d="initRNG buildPerlin buildConnectivity buildSmoothing buildReachability buildLocations buildRandZones".split(" "),g=0,a=d.length;g<a;g++)if(e=d[g],this.buildSteps.push(e),
"buildPerlin"!==e&&"buildSmoothing"!==e&&"buildLocations"!==e&&"buildRandZones"!==e&&this.buildSteps.push(this[e].bind(this,null)),"initRNG"!==e){var h=this.world.getBiomes();var k=0;for(c=h.length;k<c;k++)f=h[k],this.buildSteps.push(this[e].bind(this,f))}this.maxBuildSteps=this.buildSteps.length;this.resetCount+=1;if(10<this.resetCount)return this.main.doSendError("worldgen reset after "+this.lastBuildStep),this.clear()};a.prototype.initRNG=function(){return a.rng=new pa(this.worldSeed)};a.prototype.tickGen=
function(a){this.logTime+=a;.25<this.logTime&&(0===this.loadingTexts.length&&(this.loadingTexts=this.allLoadingTexts.randomize()),this.logDetail=q.toText("txt-loading-gen")+" "+this.loadingTexts.shift()+"...",this.logTime=0);if(0<this.buildSteps.length){var b=this.buildSteps.shift();Object.isString(b)&&(logs.worldgen&&r.info(b),this.lastBuildStep=b,b=this.buildSteps.shift());if(null!=b&&!b())return this.worldSeed+=1,null!=this.biomeToGenerate?this.initForBiome(this.biomeToGenerate):(this.initWorld(),
this.clear()),logs.worldgen&&r.info("resetting world gen: seed now "+this.worldSeed),this.resetBuildSteps()}else{this.created=!0;if(null!=this.biomeToGenerate)this.biomeToGenerate.generated=!0,this.main.worldGenIO.markBiomeCtxDirty(this.biomeToGenerate.pos.x+1,this.biomeToGenerate.pos.y),this.main.worldGenIO.markBiomeCtxDirty(this.biomeToGenerate.pos.x,this.biomeToGenerate.pos.y+1),this.main.worldGenIO.markBiomeCtxDirty(this.biomeToGenerate.pos.x+1,this.biomeToGenerate.pos.y+1);else if(null!=this.world){this.world.generated=
!0;var d=this.world.biomes;for(b in d)a=d[b],a.generated=!0}if(logs.worldgen)return console.groupEnd()}};a.prototype.waitGen=function(){var a;for(a=[];!this.created;)a.push(this.tickGen(0));return a};a.prototype.getQueuedLocations=function(){var a;var c=[];var d=null!=this.biomeToGenerate?[this.biomeToGenerate]:this.world.getBiomes();var e=0;for(a=d.length;e<a;e++){var f=d[e];var g=f.locationQueue;var h=0;for(f=g.length;h<f;h++){var k=g[h];k=t.getLocation(k);null!=k.worldMap&&c.push(k)}}return c};
a.prototype.setupPerlin=function(){var a=new Perlin;a.octaves=config.terrain.octaves;a.persistence=config.terrain.persistence;a.frequency=config.terrain.frequency;return a};a.prototype.randBorderBiome=function(b){var c,d,e;b=t.arrify(b);var f=b.sum(function(a){var b;return null!=(b=a.slots)?b:1});var g=a.rng.random()*f;var h=0;for(c=b.length;h<c;h++){var k=b[h];g-=null!=(d=k.slots)?d:1;if(0>=g||0===f)return null!=(e=k.ref)?e:k}return null};a.prototype.initBiome=function(a){if(null==a)return!0;a.setup(a.id,
this.biomeIsBlocking);a=t.getPocket(this.pocketId);n.assert(null!=a);return!0};a.prototype.buildBiomes=function(){var a=this,c,d,e,f;var g=t.getPocket(this.pocketId);var h=null!=this.biomeToGenerate?[this.biomeToGenerate]:this.world.getBiomes();var k=null!=this.biomeToGenerate?this.biomeToGenerate.pos:this.world.biomeStartPos;var l=h.filter(function(a){return!a.isOutside}).worldGenRandomize();var m=this.maxReachableBiomeCount();var p=this.countReachableBiomes(k);var q=this.maxBiomeExtent();this.blockedBiomes.times(function(){var b,
c;var d=0;for(b=l.length;d<b;d++){var e=l[d];if(!e.pos.eq(k)){e.blocking=!0;var f=a.maxReachableBiomeCount();var h=a.countReachableBiomes(k);var n=a.maxBiomeExtent();e.blocking=!1;if(!(f<m-1||h<p-1||n<q)){b=null!=(c=a.randBorderBiome(g.borderBiome))?c:"bio-outside-mountains";e.setup(b,!0);l.remove(e);--m;--p;break}}}return[]});var r=[];var D=3*l.length;for(d=!1;!l.isEmpty();){if(r.isEmpty()){r=this.randBuildList(g.biomes);var v=t.arrify(g.specialBiomes);var y=0;for(c=v.length;y<c;y++){var u=v[y];
r.add(u,1)}}c=r.shift();y=d?"1..":"0";--D;if(0>=D)return!1;var A=0;for(v=l.length;A<v;A++)if(u=l[A],n.match(y,u.pos.dist(k))){u.setup(c);l.remove(u);d=!0;break}}r=0;for(d=h.length;r<d;r++)u=h[r],u.isOutside&&(c=1>=u.pos.rectDist(k)&&!this.isWarping?null!=(e=this.randBorderBiome(g.seaBorderBiome))?e:"bio-outside-sea":null!=(f=this.randBorderBiome(g.borderBiome))?f:"bio-outside-mountains",u.setup(c,!0));return!0};a.prototype.buildPerlin=function(b){var c=this;if(null==b)return!0;var d=$jscomp.makeIterator(config.board.biomeSize);
var e=d.next().value;d=d.next().value;b.size=new R(e,d);var f=this.world.getBiomeCount();var g=f.w*e;var h=f.h*d;var k=new u(b.pos.x*e,b.pos.y*d);var l=t.getBiome(b.id);this.setupPerlin().generate(k.lst(),b.size.lst(),function(b,d){var e=$jscomp.makeIterator(b);b=e.next().value;e=e.next().value;b=new u(b,e);b.sub(k);c.isWarping||n.isIO()?e=l.terrain.find(function(a){return d>a.perlin}).tile:(e=Math.min(b.x,g-1-b.x,b.y,h-1-b.y),e=0===e?1:1===e?.5:2===e?.1:0,e=a.rng.random()<e?"tl-river":e=l.terrain.find(function(a){return d>
a.perlin}).tile);return c.world.getTile(b).setup(e)});b.close();return b.ctxDirty=!0};a.prototype.getBiomeRiverWorldPos=function(a,c){var b=this.main.worldGenIO.getBiomeDict(a.pos);switch(c){case "left":return b.riverPoints.left;case "right":return a=b.pos.add(new u(1,0)),this.main.worldGenIO.getBiomeDict(a).riverPoints.left;case "top":return b.riverPoints.top;case "bottom":return a=b.pos.add(new u(0,1)),this.main.worldGenIO.getBiomeDict(a).riverPoints.top;case "hub":b=a.locations;var e=0;for(a=b.length;e<
a;e++)if(c=b[e],c.id===config.io.hubLocationID)return c.pos;return n.assert(!1)}};a.prototype.buildRivers=function(b){var c,d,e,f;if(null==b)return!0;var g=this.main.worldGenIO.getBiomeDict(b.pos);if(null==g||null==g.rivers)return!0;var h=g.rivers;var k=0;for(d=h.length;k<d;k++){var l=h[k];g=this.getBiomeRiverWorldPos(b,l.from);var m=this.getBiomeRiverWorldPos(b,l.to);var p=0;var q=config.io.riverShallowChanceBase;for(l=0;;){l+=1;if(100<l)break;var r=this.world.getTile(g);if(null!=r&&r.biome===b&&
!r.isRiver)if(r.id!==config.io.riverTile&&r.id!==config.io.riverShallowTile){--p;0>p&&((r=a.rng.random()<=q)?(p=a.rng.randA(config.io.riverShallowConsecutiveTiles),q=config.io.riverShallowChanceBase):q+=config.io.riverShallowChanceIncrease);var t=0<=p?config.io.riverShallowTile:config.io.riverTile;r=new Ab;r.setup(t);this.world.setTile(g,r);r.isRiver=!0;r.reachable=!r.isBlocking();n.assert(this.world.getTile(g).id===t)}else r.isRiver=!0;if(g.eq(m))break;t=[];var v=0;for(c=Ea.length;v<c;v++){var y=
Ea[v];if(0!==y.val){r=g.move(y);var u=this.world.getTile(r);null!=u&&u.biome===b&&null==u.location?t.push(y):r.eq(m)&&t.push(y)}}n.assert(0<t.length);y=g.getDirs(m);c=[];u=0;for(v=y.length;u<v;u++)r=y[u],t.includes(r)&&c.push(r);if(0===c.length||a.rng.random()<config.io.riverWalkRandomChance)for(c=[],u=0,e=y.length;u<e;u++){r=y[u];switch(r.abbr){case "n":var A=[K.ne,K.nw];break;case "ne":A=[K.n,K.se];break;case "se":A=[K.ne,K.s];break;case "s":A=[K.se,K.sw];break;case "sw":A=[K.s,K.nw];break;case "nw":A=
[K.sw,K.n]}v=0;for(f=A.length;v<f;v++)r=A[v],t.includes(r)&&!c.includes(r)&&c.push(r)}r=0<c.length?c.worldGenSample():y.worldGenSample();g=g.move(r)}}return!0};a.prototype.checkSwapTiles=function(a,c){a=this.world.getTile(a);c=this.world.getTile(c);return null==a||null==c?!1:a.setup(c.id)};a.prototype.smoothBiomeWithNeighbour=function(b,c){var d,e;var f=b.pos.add(c);var g=this.main.worldGenIO.getBiomeDict(f);if(null!=g&&g.biomeID!==b.id){var h=0===c.x?config.board.biomeSize[0]:config.board.biomeSize[1];
var k=0===c.x?new u(1,0):new u(0,1);f=t.getBiome(g.biomeID);n.assert(null!=f);var l=this.main.worldGenIO.getBiomeDict(b.pos);var m=g.pocketID!==l.pocketID||g.isBorder!==l.isBorder;var p=0;p=l.isBorder!==g.isBorder?l.isBorder?config.io.worldGenSmoothingDepthBlockingBiome:config.io.worldGenSmoothingDepthNonBlockingBiome:m?config.io.worldGenSmoothingDepthDiffPocket:config.io.worldGenSmoothingDepthSamePocket;m=config.io.worldGenSmoothingBaseChance;l=config.io.worldGenSmoothingChanceIncrease;g=[];var q=
e=0;for(d=p;0<=d?e<d:e>d;q=0<=d?++e:--e){p=b.getFirstTilePos();1===c.x?p.x+=config.board.biomeSize[0]-1-q:-1===c.x&&(p.x+=q);1===c.y?p.y+=config.board.biomeSize[1]-1-q:-1===c.y&&(p.y+=q);var r=m;var D=0;for(q=h;0<=q?D<q:D>q;0<=q?++D:--D){var v=this.world.getTile(p);if(null!=v&&v.biome===b)if(p=p.add(k),a.rng.random()>r)r+=l;else{var y=a.rng.random();r=f.terrain.find(function(a){return y>a.perlin}).tile;v.id!==r&&v.setup(r);r=m}}m*=config.io.worldGenSmoothingChanceMultiplierPerDepth;g.push(l*=config.io.worldGenSmoothingChanceMultiplierPerDepth)}return g}};
a.prototype.buildSmoothingIO=function(a){var b;if(null==a)return!0;var d=[new u(-1,0),new u(1,0),new u(0,-1),new u(0,1)];var e=[];var f=0;for(b=d.length;f<b;f++){var g=d[f];e.push(this.smoothBiomeWithNeighbour(a,g))}return e};a.prototype.buildSmoothing=function(b){var c,d,e;if(null==b)return!0;var f=$jscomp.makeIterator(config.board.biomeSize);var g=f.next().value;f=f.next().value;b=b.getFirstTilePos();for(e=c=d=0;0<=g?c<g:c>g;e=0<=g?++c:--c)if(a.rng.random()>d)d+=.5;else{var h=this.world.getTile(new u(b.x+
e,b.y+f-1));e=this.world.getTile(new u(b.x+e,b.y+f));null!=e&&null!=e.id&&(.5>a.rng.random()&&(e=$jscomp.makeIterator([e,h]),h=e.next().value,e=e.next().value),h.setup(e.id),d=.25)}for(e=d=c=0;0<=f?d<f:d>f;e=0<=f?++d:--d)c=0<c?c-1:0>c?c+1:.5<a.rng.random()?c+1:c-1,0!==c&&(h=this.world.getTile(new u(b.x+g-1,b.y+e)),e=this.world.getTile(new u(b.x+g,b.y+e)),null!=e&&null!=e.id&&(1===c&&(e=$jscomp.makeIterator([e,h]),h=e.next().value,e=e.next().value),h.setup(e.id)));return!0};a.prototype.buildRandZones=
function(a){var b,d,e;if(null==a||a.isOutside)return!0;if(null!=this.biomeToGenerate){var f=this.main.worldGenIO.getBiomeDict(this.biomeToGenerate.pos);if(null!=f.sgData){a=null!=(d=f.sgData.zones)?d:[];var g=0;for(d=a.length;g<d;g++)f=a[g],this.world.addZone(f.id,u.fromObj(f.center),0,n.isTrue(f.seeking),null!=(b=f.seekTurns)?b:0);return!0}}b=this.world.getBiome(this.world.biomeStartPos);if(!this.isWarping&&b.pos.eq(a.pos))return!0;b=t.getBiome(a.id);d=this.randBuildList(b.zones,a);f=0;for(b=d.length;f<
b;f++){var h=d[f];var k=t.getZone(h);var l=a.tiles.filter(function(a){var b;return null!=a.location&&0<a.location.mapScore?!1:a.reachable&&t.checkFlags(null!=(b=k.tileFlags)?b:{},a.flags)});g=!1;var m=l.worldGenRandomize();l=0;for(e=m.length;l<e;l++){var p=m[l];if((null==this.biomeToGenerate||p.biome===this.biomeToGenerate)&&this.world.addZone(h,p.pos,0)){g=!0;break}}g||r.error("could not spawn zone "+h)}return!0};a.prototype.updateReachabilityIO=function(a){if(null==a)return!0;var b=a.tiles;var d=
0;for(a=b.length;d<a;d++){var e=b[d];e.reachable=!e.isBlocking()}return!0};a.prototype.buildReachability=function(a){if(null!=a){if(a.isOutside||a.blocking)return!0;var b=a.tiles.count(function(a){return a.reachable});a=a.tiles.length;b/=a;if(.3<b)return!0;this.main.log("reachabilty ("+b+") too low");return!1}this.world.updateSea();b=this.world.findPartyPos(!this.isWarping&&8>this.resetCount);if(null!=b)return this.world.updateReachability(b),this.world.startPos=b,this.isWarping||this.world.replaceTile(this.world.getTile(b),
this.world.shipTile,!1),!0;r.error("no start position found");return!1};a.prototype.buildConnectivity=function(a){var b;if(null!=(null!=a?a.clearUnconnected:void 0)){var d=a.tiles;var e=0;for(b=d.length;e<b;e++){var f=d[e];f.connected||this.world.replaceTile(f,a.clearUnconnected,{checkReachability:!1,ignoreOriginalId:!0})}return!0}if(null==a){a=$jscomp.makeIterator(config.board.biomeSize);f=a.next().value;a=a.next().value;a=new u(this.world.biomeCount.w/2*f,this.world.biomeCount.h/2*a);for(f=this.world.getTile(a);null!=
f&&f.isBlocking();)a.x+=1,f=this.world.getTile(a);this.world.updateConnectivity(a)}return!0};a.prototype.buildLocationQueue=function(){var b=this,c,d;var e=function(a){return Math.max(Math.abs(g.pos.x-a.pos.x),Math.abs(g.pos.y-a.pos.y))};var f=t.getPocket(this.pocketId);var g=this.world.getBiome(this.world.biomeStartPos);var h=this.world.getBiomes().filter(function(a){return!a.isOutside&&!a.blocking});var k=0;for(c=h.length;k<c;k++){var l=h[k];this.clearLocations(l)}c=[];var m=this.world.getBiomes();
var p=0;for(k=m.length;p<k;p++)l=m[p],l.locationQueue=[];null!=this.goalId?(k=t.getGoal(this.goalId),null!=k.locations?c.push(this.randBuildList(k.locations)):r.error("Couldn't find goal")):null!=this.biomeToGenerate||this.isWarping||null!=this.main.tutorial||r.error("Couldn't find goal");p=t.arrify(f.locations);f=0;for(k=p.length;f<k;f++)m=p[f],c.push(this.randBuildList(m));p=f=0;for(k=c.length;f<k;p=++f){m=c[p];p=0===p?h.sortBy(function(b){return 100*e(b)+a.rng.numberRand(10)},!0):h.sortBy(function(b){return 100*
b.locationQueue.length+a.rng.numberRand(10)},!1);var n=0;for(d=m.length;n<d;n++){var q=m[n];if(null==q)p.pop();else{l=p.shift();if(null==l)break;l.locationQueue.add(this.randBuildList(q,l))}}}k=h.worldGenRandomize();c=0;for(f=k.length;c<f;c++)for(l=k[c],m=t.getBiome(l.id),n=this.randBuildList(m.locations,l),q=0,m=n.length;q<m;q++)p=n[q],l.locationQueue.push(p);f=0;for(c=h.length;f<c;f++)l=h[f],l.locationQueue=l.locationQueue.map(function(a){return a.startsWith("grp-")?b.randBuildList({group:a},l):
a}),l.locationQueue=l.locationQueue.flatten().worldGenRandomize();return!0};a.prototype.buildLocations=function(a){var b,d;if(null==a)return!0;var e=a.locationQueue;var f=0;for(b=e.length;f<b;f++){var g=e[f];if(""!==g&&!this.world.addLocation(g,a.tiles)){var h=t.getLocation(g);h=null!=(d=h.isRemovable)?d:!0;r.warn("could not spawn "+g+" (removable: "+h+")");if(!h)return!1}}return!0};a.prototype.buildSingleLocation=function(b){var c;if(null==b)return!0;for(this.main.worldGenIO.getBiomeDict(this.biomeToGenerate.pos);0<
this.biomeLocations.length;){var d=this.biomeLocations.shift();if(null==d||""===d)break;var e=a.rng._seed;var f=this.world.addLocation(d,b.tiles);a.rng._seed=e+1;if(f)break;else if(f=t.getLocation(d),f=null!=(c=f.isRemovable)?c:!0,r.warn("could not spawn "+d+" (removable: "+f+")"),!f)return!1}return!0};a.prototype.checkWorldReqs=function(a){var b=this.biomeToGenerate?this.biomeToGenerate.worldLvl:this.main.worldLvl;return null!=a.reqWorld&&!n.match(a.reqWorld,b)||null!=a.reqDifficulty&&!n.match(a.reqDifficulty,
this.main.difficultyLvl)||null!=a.ref&&!this.checkWorldReqs(t.getBuildItem(a.ref))?!1:!0};a.prototype.checkBiomeFlags=function(a,c){return null!=a.reqBiomeFlags&&!t.checkFlags(a.reqBiomeFlags,c.flags)||null!=a.ref&&!this.checkBiomeFlags(t.getBuildItem(a.ref),c)?!1:!0};a.prototype.clearLocations=function(a){a.locations=[];var b=a.tiles;var d=[];var e=0;for(a=b.length;e<a;e++){var f=b[e];d.push(f.location=null)}return d};a.prototype.maxBiomeExtent=function(){var a;var c=$jscomp.makeIterator([10,0]);
var d=c.next().value;c=c.next().value;var e=$jscomp.makeIterator([10,0]);var f=e.next().value;var g=e.next().value;var h=this.world.getBiomes().filter(function(a){return!(a.isOutside||a.blocking)});var k=0;for(a=h.length;k<a;k++)e=h[k],d=Math.min(d,e.pos.x),c=Math.max(c,e.pos.x),f=Math.min(f,e.pos.y),g=Math.max(g,e.pos.y);return c-d+(g-f)};a.prototype.maxReachableBiomeCount=function(){var a=this;return this.world.getBiomes().filter(function(a){return!(a.isOutside||a.blocking)}).map(function(b){return a.countReachableBiomes(b.pos)}).max()};
a.prototype.countReachableBiomes=function(a){var b;var d=this.world.getBiome(a);a=[d];for(d=[d];0<a.length;){var e=a.shift();var f=[Sa.n,Sa.e,Sa.s,Sa.w];var g=0;for(b=f.length;g<b;g++){var h=f[g];var k=e.pos.add(h.delta);h=this.world.getBiome(k);null==h||h.isOutside||h.blocking||d.any(function(a){return a.pos.eq(k)})||(a.push(h),d.push(h))}}return d.length};a.prototype.updateFromSaveData=function(a){if(null==a)return!0;var b=this.main.worldGenIO.getBiomeDict(a.pos).sgData;if(null==b)return!0;this.main.mainMenu.saveGame.unpackBiome(a,
this.main.worldGenIO.sgTileTable,this.main.worldGenIO.sgSprawlTable,b,this.main.worldGenIO.world);return!0};a.prototype.randBuildList=function(b,c){var d,e,f,g;var h=[];var k=t.arrify(b);var l=0;for(e=k.length;l<e;l++)if(b=k[l],!(a.rng.random()>(null!=(f=b.chance)?f:1))&&this.checkWorldReqs(b)&&(null==c||this.checkBiomeFlags(b,c))){var m=null!=(g=b.select)?g:1;if(null!=b.group)h.add(this.randGroupBuildList(b.group,m,c,b.fallback));else if(null!=b.ref)for(d=0;0<=m?d<m:d>m;0<=m?++d:--d)h.push(b.ref);
else if(Object.isString(b))for(d=0;0<=m?d<m:d>m;0<=m?++d:--d)h.push(b)}return h};a.prototype.randGroupBuildList=function(b,c,d,e){var f=this;c=void 0===c?1:c;Object.isString(b)&&(e=t.getGroup(b),b=e.group,e=e.fallback);b=b.filter(function(a){return f.checkWorldReqs(a)&&(null==d||f.checkBiomeFlags(a,d))});0===b.length&&null!=e&&(b=[e]);var g=[];c.times(function(){var c,e,l,m,p;var n=b.sum(function(a){var b;return null!=(b=a.slots)?b:1});var q=a.rng.random()*n;var r=[];var t=p=0;for(c=b.length;p<c;t=
++p){var y=b[t];q-=null!=(e=y.slots)?e:1;if(0>=q||0===n){c=null!=(l=y.select)?l:1;if(null!=y.group)g.add(f.randGroupBuildList(y.group,c,d,y.fallback));else if(null!=y.ref)for(l=0;0<=c?l<c:l>c;0<=c?++l:--l)g.push(y.ref);(null!=(m=y.consume)?m:1)&&b.removeAt(t);break}else r.push(void 0)}return r});return g};a.prototype.getProgress=function(){return 1-this.buildSteps.length/this.maxBuildSteps};a.prototype.draw=function(){this.drawTitleBox();return this.drawLoadingBar()};a.prototype.drawTitleBox=function(){if(!this.isWarping){var a=
$jscomp.makeIterator(this.r.getCanvasSize());var c=a.next().value;var d=a.next().value;a=300*this.r.s;var e=d/2-75*this.r.s;d={halign:"center"};this.r.drawPanel(config.panel.info,c/2-a/2,e,a,125*this.r.s);this.r.drawSprite("hud_expeditionStart_expedition.png",c/2,e+30*this.r.s,d);this.r.drawSprite("hud_expeditionStart_line.png",c/2,e+85*this.r.s,d);return this.r.drawSprite("hud_expeditionStart_"+(this.main.worldLvl+1)+".png",c/2,e+75*this.r.s,d)}};a.prototype.drawLoadingBar=function(){var a=$jscomp.makeIterator(this.r.getCanvasSize());
var c=a.next().value;var d=a.next().value-30*this.s;a=100*this.s;this.r.ctx.lineWidth=this.s;this.r.ctx.fillStyle="black";this.r.ctx.fillRect(c/2-a/2,d,a,5*this.s);this.r.ctx.fillStyle="white";this.r.ctx.fillRect(c/2-a/2+2,d+2,a*this.getProgress()-4,5*this.s-4);this.r.ctx.font=config.fonts.technicalLarge;return this.r.drawText(this.logDetail,c/2,d+20*this.s,{os:2,halign:"center"})};a.rng=new pa(Date.now());return a}.call(this);window.worldGenShuffle=function(a){return ba.rng.shuffle(a)};window.worldGenRandom=
function(a){return ba.rng.random()};var hb=function(a){this.setEnabled=this.setEnabled.bind(this);this.main=a;this.r=this.main.r;this.s=this.main.r.s;this.enabled=!1;this.clearChatQueue();this.clearUnlockQueue();this.startY=config.chat.offsetY;this.lineHeight=70};hb.prototype.setEnabled=function(a){return this.enabled=a};hb.prototype.showStat=function(a,b){if(0<b)return this.showText(a+": +"+b);if(0>b)return this.showText(a+": "+b)};hb.prototype.clearChatQueue=function(){this.chatQueue=[];this.chatTime=
this.lastTime=0;return this.chatLine=null};hb.prototype.clearUnlockQueue=function(){this.unlockQueue=[];this.unlockTime=this.lastTime=0;return this.unlockLine=null};hb.prototype.showText=function(a,b,c){c=void 0===c?0:c;if(this.enabled)return a=q.parse(a),this.chatQueue.push({person:b,text:a,fadeAge:-c,posY:this.startY,statuses:[]})};hb.prototype.showUnlock=function(a){return this.unlockQueue.push(a)};hb.prototype.showTaxonomy=function(a,b){if(this.enabled)return a={person:this.main.party.getExplorer(),
text:a.name,canvas:b,fadeAge:0,posY:this.startY,statuses:[]},this.chatQueue.push(a)};hb.prototype.tick=function(a){this.chatTime+=a;var b=config.chat.maxTime;0<this.chatQueue.length&&(b/=5);if(this.chatTime>b||null===this.chatLine)this.chatLine=0<this.chatQueue.length?this.chatQueue.shift():null,this.chatTime=0;if(!this.main.showingDiary()&&(this.unlockTime+=a,this.unlockTime>config.chat.maxTime||null===this.unlockLine))return this.unlockLine=0<this.unlockQueue.length?this.unlockQueue.shift():null,
this.unlockTime=0};hb.prototype.drawChat=function(){if(!this.r.pureMode){var a=$jscomp.makeIterator(this.r.getCanvasSize());var b=a.next().value;a.next();this.r.ctx.fillStyle="white";this.r.ctx.strokeStyle="#222";this.r.ctx.lineWidth=this.s;if(null!=this.chatLine){if(null!=this.chatLine.person){var c=this.main.party.persons.findIndex(this.chatLine.person)-this.r.partyOffset;var d=this.r.charPortraitPos(c,this.main.party.persons.length,this.main.party.maxUnitCount);if(null==d)return;this.r.ctx.font=
config.fonts.themedSmall;c=this.r.ctx.measureText(this.chatLine.text);this.r.drawPanel(config.panel.chatSmall,d.x-15*this.s-c.width,d.y+12*this.s,c.width+12*this.s,25*this.s);this.r.drawSprite("hud_chat_bubble_small_arrow_right.png",d.x-5*this.s,d.y+20*this.s);this.r.drawText(this.chatLine.text,d.x-9*this.s-c.width,d.y+27*this.s,{fillColor:"black",os:0})}null!=this.chatLine.canvas&&(this.r.ctx.save(),this.r.ctx.translate(d.x-c.width-55*this.s+this.chatLine.canvas.width/2,d.y+this.chatLine.canvas.height/
2),this.r.ctx.drawImage(this.chatLine.canvas,-this.chatLine.canvas.width/2,-this.chatLine.canvas.height/2),this.r.ctx.restore())}if(!this.main.showingDiary()&&null!=this.unlockLine)return d=new u(b/2,50*this.s),this.r.drawPanel(config.panel.infoSimple,d.x-100*this.s,d.y,200*this.s,50*this.s),this.r.drawText(this.unlockLine,d.x,d.y+30*this.s,{halign:"center",fillColor:"black",os:0})}};var ka=function(a){this.doRandEvent=this.doRandEvent.bind(this);this.doCharEvents=this.doCharEvents.bind(this);this.doPartyEvents=
this.doPartyEvents.bind(this);this.doSubEvent=this.doSubEvent.bind(this);this.mergeDiff=this.mergeDiff.bind(this);this.checkEventDiff=this.checkEventDiff.bind(this);this.clearActions=this.clearActions.bind(this);this.prepareWords=this.prepareWords.bind(this);this.main=a;this.infoBox=this.main.infoBox;this.sfx=this.main.sfx;this.r=this.main.r;this.clearActions();this.updateEventKeywords();this.setupPronouns();this.showingEventDialogue=!1};ka.prototype.setupPronouns=function(){var a,b;this.pronouns=
[];var c=[config.enTexts,config.locTexts];var d=0;for(b=c.length;d<b;d++){var e=c[d];for(a in e){var f=e[a];if("@vars"===a){var g=f.split(",");var h=0;for(f=g.length;h<f;h++){var k=g[h];try{var l=$jscomp.makeIterator(k.trim().split("="));var m=l.next().value;var p=l.next().value;p=p.split("|");this.pronouns.remove(function(a){return a.old===m});this.pronouns.push({old:m,male:p[0],female:p[1]})}catch(w){r.error("Error in formatting of @vars in language file")}}}}}return this.pronouns=this.pronouns.sortBy(function(a){return a.old.length},
!0)};ka.prototype.getEvent=function(a){return null!=a.ref?t.getEvent(a.ref):Object.isObject(a)?a:t.getEvent(a)};ka.prototype.randEvent=function(a,b){var c=this,d;a=t.arrify(a).groupBy(function(a){var b;return null!=(b=a.prio)?b:0});var e=Object.keys(a).sortBy(function(a){return a});var f=0;for(d=e.length;f<d;f++){var g=e[f];g=a[g];g=t.arrify(g).map(function(a){var d;var e=c.getEvent(a);return{evt:e,canDo:c.hasRequirements(e,b),slots:null!=(d=a.slots)?d:1}});g.remove(function(a){return!a.canDo});if(!g.isEmpty())break}return null!=
g&&(a=ka.randEntry(g),null!=a)?a.evt:null};ka.randEntry=function(a){var b,c;var d=a.sum(function(a){var b;return null!=(b=a.slots)?b:1});var e=ba.rng.random()*d;var f=0;for(b=a.length;f<b;f++){var g=a[f];e-=null!=(c=g.slots)?c:1;if(0>=e||0===d)return g}return null};ka.prototype.hasRequirements=function(a,b,c){b=void 0===b?{}:b;c=void 0===c?0:c;var d,e;if(null==a)return!0;if(e=debug.eventChecks&&null==b.trigger&&null!=a.cid){var f=function(){var a;var b=[];var d=0;for(a=c;0<=a?d<=a:d>=a;0<=a?++d:--d)b.push("  ");
return b}().join("");var g=null!=b.person?" ("+b.person.id+")":"";g=""+a.cid+g}for(d in a){var h=this.eventRequirements[d];if(null!=h&&!1===h(a,b))return e&&r.warn("EVENT-CHECK;"+f+g+" FAILED "+d,a.mod),!1}if(!this.doPartyEvents(a,b,{},!0,c+1)||!this.doCharEvents(a.charEvents,function(){return b.party.persons},b,{},!0,c+1)||!this.doCharEvents(a.storeEvents,function(){return b.party.store},b,{},!0,c+1))return!1;e&&r.info("EVENT-CHECK;"+f+g+" OK",a.mod);return!0};ka.prototype.updateEventKeywords=function(){var a;
this.eventEffects={};var b=Object.getOwnPropertyNames(Jc.prototype);var c=0;for(a=b.length;c<a;c++){var d=b[c];if(d.startsWith("apply")){var e=d.remove("apply");e=e[0].toLowerCase()+e.slice(1);this.eventEffects[e]=Jc.prototype[d]}}this.eventRequirements={};e=Object.getOwnPropertyNames(Kc.prototype);b=[];c=0;for(a=e.length;c<a;c++)d=e[c],d.startsWith("req")&&b.push(this.eventRequirements[d]=Kc.prototype[d]);return b};ka.prototype.doRandEvent=function(a,b){b=void 0===b?{}:b;b.main=this.main;b.party=
this.main.party;a=this.randEvent(a,b);if(null!=a)return this.doEvent(a,b)};ka.prototype.posTile=function(a,b){var c;if(null!=a.posTile){var d=a.posTile;n.assertOpts(d,"posTile",b,a.mod);var e=t.arrify(d.tiles);var f=d.tileFlags;var g=t.arrify(d.locations);var h=d.locationFlags;var k=d.biomeFlags;var l=null!=d.range&&"world"!==d.range?n.parseRange(d.range):"world";var m=d.tileKnown;var p=d.locationKnown;var q=d.traversable;var r=d.reachable;a=n.isTrue(d.closest);var D=d.showHint;null!=r&&(d=null!=
(c=b.party.pos)?c:b.world.startPos,b.world.updateReachability(d));"world"===l?(d=0,c=Math.max(b.world.biomeCount.w,b.world.biomeCount.h)):(d=Math.floor(Math.min(l[0]/config.board.biomeSize[0],l[0]/config.board.biomeSize[1])),c=Math.ceil(Math.max(l[1]/config.board.biomeSize[0],l[1]/config.board.biomeSize[1])));var v=[d,c];var y=b.world.toBiomePos(b.pos);c=b.world.getBiomes().map(function(a){return null!=a&&a.generated&&n.match(v,a.pos.sub(y).length())?a.tiles:[]}).flatten();c=c.filter(function(a){return!a.biome.generated||
n.isIO()&&a.biome.blocking||"world"!==l&&!n.match(l,a.pos.dist(b.pos))||0<e.length&&e.none(a.id)||null!=f&&!t.checkFlags(f,a.flags)||null!=r&&a.reachable!==r||0<g.length&&(null==a.location||g.none(a.location.id))||null!=h&&(null==a.location||!t.checkFlags(h,a.location.flags))||null!=k&&!t.checkFlags(k,a.biome.flags)||null!=a.location&&(null!=D&&a.location.showHint!==D||null!=p&&a.location.known!==p)||null!=m&&a.known!==m||null!=q&&!a.isBlocking()!==q?!1:!0});a=a?c.min(function(a){return a.pos.dist(b.pos)}):
c.worldGenSample();if(null!=a)return b.pos=a.pos,b.location=a.location}};ka.prototype.newDiff=function(){return{sanity:0,standing:0,fame:0,funds:0,texts:[],npc:[],actions:[],events:[],chats:[],reveals:[],delayedEvent:null,addedCharacters:[],removedCharacters:[],turns:0,rivalTurns:0,trackDistBonus:0,endWorld:null,gameOver:!1,breakPage:!0,showEvent:!1,showPartyCount:!1,pendingEvent:!1,statuses:[],loyalties:{},items:{}}};ka.prototype.doEvent=function(a,b,c){c=void 0===c?!0:c;var d,e,f,g;if(null!=a.cid){var h=
function(){var b;var c=[];var d=0;for(b=a.cid.split(".").length-1;0<=b?d<b:d>b;0<=b?++d:--d)c.push("  ");return c}().join("");logs.events&&r.info("EVENT;"+h+a.cid,a.mod);""!==h||a.cid.includes("return")||(this.lastEventCID=a.cid)}this.main.party.incStatEventEncounter(a);if(null!=a.id&&null!=(f=this.main.tutorial))f.onEvent(a.id,b);null!=a.reqMaxPerWorld&&this.main.party.incTrackedEvent(a.cid);h=this.newDiff();h.breakPage=null!=(e=a.breakPage)?e:!0;null!=b.main&&(h.day=b.main.getDay());if(null==a)return h;
null!=b.item&&(b.item.chargeTime=0);c&&this.addDiffText(h,a.text,a.report,b.person);null==b.tempFlags&&(b.tempFlags={});null==b.targetChar&&(b.targetChar=b.person);this.posTile(a,b);for(d in a)if(e=a[d],c=this.eventEffects[d],null!=c){if(config.sanityCheckEvents&&!n.assertOpts(e,d,b,a.mod))debugger;c(a,b,h)}else config.sanityCheckEvents&&null==this.eventRequirements[d]&&0>F.call(config.staticKeywords,d)&&r.warn("unknown key word "+d+" in "+(null!=(g=a.cid)?g:JSON.stringify(a)));this.mergeDiff(this.eventDiff,
h);this.doCharEvents(a.charEvents,function(){return b.party.persons},b,h,!1);this.doCharEvents(a.storeEvents,function(){return b.party.store},b,h,!1);0<t.arrify(b.npc).length&&this.doCharEvents(a.npcEvents,function(){return b.npc},b,h,!1);this.doPartyEvents(a,b,h,!1);this.doFollowUpEvents(a,b,h);this.doFollowUpActions(a,b,h);return h};ka.prototype.addDiffText=function(a,b,c,d){if(null==b)return null;d=t.arrify(d);0===d.length&&(d=[this.main.party.getExplorer()]);var e=d[0].gender;b={text:q.parse(b,
e),persons:d};null!=c&&(b.report=q.parse(c,e));a.texts.push(b);a.showEvent=!0;a.hasText=!0;return b.text};ka.prototype.doCharEvents=function(a,b,c,d,e,f){var g=this;f=void 0===f?0:f;var h,k;if(null==a)return!0;var l=[];var m=Object.clone(c);m.trigger=null;var p=t.arrify(a);var q=0;for(c=p.length;q<c;q++){a=p[q];var r=null!=(h=a.optional)?h:!1;if(!r||!e){var D=this.getEvent(a);var v=b();var y=v.filter(function(a){if(0<=F.call(l,a))return!1;m.person=a;m.age=a.storeAge;return g.hasRequirements(D,m,f)});
var u=null!=(k=D.count)?k:1;if("all"===u){if(y.length<v.length)if(r)continue;else return!1}else if("any"!==u)if(Object.isString(u)){u=$jscomp.makeIterator(n.parseRange(u));v=u.next().value;u=u.next().value;if(y.length<Math.max(1,v))if(r)continue;else return!1;y=y.sample(u)}else{if(y.length<u)if(r)continue;else return!1;y=n.sample(u,y)}if(y.isEmpty())if(r)continue;else return!1;if(!(e||null!=D.chance&&ba.rng.random()>D.chance))for(this.addDiffText(d,D.text,D.report,y),v=y.worldGenRandomize(),u=0,y=
v.length;u<y;u++)r=v[u],m.person=r,this.doSubEvent(D,m,d,!1),a.consume&&l.push(r)}}return!0};ka.prototype.doPartyEvents=function(a,b,c,d,e){e=void 0===e?0:e;var f,g;var h=t.arrify(a.partyEvents);var k=0;for(f=h.length;k<f;k++){a=h[k];var l=null!=(g=a.optional)?g:!1;if(!l||!d){var m=this.getEvent(a);var p=Object.clone(b);this.posTile(m,p);if(this.hasRequirements(m,p,e))d||null!=a.chance&&ba.rng.random()>a.chance||this.doSubEvent(m,p,c);else if(!l)return!1}}return!0};ka.prototype.doFollowUpActions=
function(a,b,c){var d=this,e;var f=[];null!=a.loot&&f.add(this.addAction("act-loot",!0,b));null!=a.barter&&f.add(this.addAction("act-barter",!0,b));if(null!=a.actions){var g=t.arrify(a.actions).map(function(a){return d.addAction(a,!1,b)}).filter(function(a){a.canDo=d.canDoAction(a,b.main);return a.canDo||a.alwaysShown});f.add(g)}c.actions.add(f);0<c.actions.length&&(c.showEvent=!0);if(logs.events){var h=[];var k=0;for(g=f.length;k<g;k++)c=f[k],h.push(r.info("SHOW-ACTION;"+(null!=(e=c.cid)?e:c.id),
a.mod));return h}};ka.prototype.doFollowUpEvents=function(a,b,c){var d;var e=null!=(d=a.select)?d:a.events;null!=e&&(e=this.randEvent(e,b),null!=e&&this.doSubEvent(e,b,c));null!=a.delayedEvent&&(c.delayedEvent={event:a.delayedEvent,ctx:b});if(null!=b.diceSuccess&&(e=b.diceSuccess?a.winEvents:a.failEvents,e=this.randEvent(e,b),null!=e))return this.doSubEvent(e,b,c)};ka.prototype.doSubEvent=function(a,b,c,d){a=this.doEvent(a,b,void 0===d?!0:d);if(null!=a)return this.mergeDiff(c,a)};ka.prototype.mergeDiff=
function(a,b){a.sanity+=b.sanity;a.standing+=b.standing;a.fame+=b.fame;a.funds+=b.funds;null!=b.actionText&&(a.actionText=b.actionText);0<b.texts.length&&a.texts.add(b.texts);0<b.chats.length&&a.chats.add(b.chats);0<b.actions.length&&a.actions.add(b.actions);0<b.npc.length&&a.npc.add(b.npc);null!=b.delayedEvent&&(a.delayedEvent=b.delayedEvent);a.turns+=b.turns;a.rivalTurns+=b.rivalTurns;a.showPartyCount||(a.showPartyCount=b.showPartyCount);null!=b.teleport&&(a.teleport=b.teleport);null!=b.showImage&&
(a.showImage=b.showImage);null!=b.playSound&&(a.playSound=b.playSound);null!=b.playMusic&&(a.playMusic=b.playMusic);a.showEvent||(a.showEvent=b.showEvent);a.hasText||(a.hasText=b.hasText);a.pendingEvent||(a.pendingEvent=b.pendingEvent);a.startWorld||(a.startWorld=b.startWorld);a.endWorld||(a.endWorld=b.endWorld);a.triangulation||(a.triangulation=b.triangulation);a.gameOver||(a.gameOver=b.gameOver);a.breakPage||(a.breakPage=b.breakPage);a.challenge||(a.challenge=b.challenge);null!=b.loot&&(a.loot=
b.loot);null!=b.barter&&(a.barter=b.barter);null!=b.escape&&(a.escape=b.escape);0<b.reveals.length&&a.reveals.add(b.reveals);null!=b.day&&(a.day=b.day);a.statuses.add(b.statuses);a.items=J.addCount(a.items,b.items);a.loyalties=J.addCount(a.loyalties,b.loyalties);a.addedCharacters.add(b.addedCharacters);return a.removedCharacters.add(b.removedCharacters)};ka.prototype.canDoAction=function(a,b){var c=this;return a.native?!0:t.arrify(a.events).any(function(d){return c.hasRequirements(d,{main:b,world:c.main.world,
party:c.main.party,person:a.person,location:a.location,pos:null!=a.location?a.location.pos:c.main.party.pos,tempFlags:{}})})};ka.prototype.addAction=function(a,b,c){b=void 0===b?!1:b;c=void 0===c?{}:c;var d,e,f,g,h,k,l,m,p,r,u;if(Object.isObject(a)){if(null!=a.isAction)return a;null!=a.ref?a=d=t.getEvent(a.ref):d=a}else a.startsWith("evt")?a=d=t.getEvent(a):(d=t.getAction(a),a=null!=(e=d.events)?e:[]);e=null!=(g=d.actionText)?g:"txt-base-continue";e=q.parse(e,null!=(h=c.person)?h.gender:void 0);null!=
c.zone&&(e=e.replace("$zone",c.zone.name));g=null!=(k=d.showPersonInfo)?k:!1;if(e.has("$name")||e.has("$Name"))n.assert(c.person,"No person context for action ("+d.id+")"),e=e.replace("$name",c.person.name),e=e.replace("$Name",c.person.name),g=!0;return{isAction:!0,id:d.id,cid:d.cid,name:e,actionText:e,showPersonInfo:g,description:d.description,alwaysShown:null!=(l=d.alwaysShown)?l:!1,canDo:b,events:a,items:null!=(m=d.actionItems)?m:{},reqItems:null!=(p=d.reqItems)?p:{},showReqItems:null!=(r=d.showReqItems)?
r:!0,reqDice:t.arrify(d.reqDice),reqDiceCharFlags:d.reqDiceCharFlags,highlight:null!=(u=d.highlight)?u:!1,native:null!=(f=d.native)?f:!1,person:c.person,pos:c.pos,location:c.location,srclocation:c.location}};ka.prototype.checkEventDiff=function(a,b){b=void 0===b?{}:b;if(null!=a&&(this.eventReveals.add(a.reveals),a.breakPage&&this.diary.breakPage(),b.silent?this.showReveals():(this.eventloc=b.location,this.eventActions=a.actions,a.showEvent?this.showEventDialogue(a):(this.showingEventDialogue&&!b.fromAction&&
this.main.doSendError("non-action closed diary (last event "+this.lastEventCID+")"),this.main.showingChallenge||this.hideEventDialogue(a.pendingEvent))),this.main.showChatMsg(a.chats),0<a.turns&&this.main.exped.wait(a.turns),null!=a.teleport&&this.main.exped.placeParty(a.teleport),null!=a.endWorld&&this.main.endWorld(a.endWorld.goalFame),a.startWorld&&this.main.gotoNextWorld(),a.gameOver&&this.main.showExpeditionOver(!1,a.gameOver,this.lastEventCID),null!=a.loot&&(a.hasText?this.eventLoot=a.loot:
this.main.showLoot(a.loot)),null!=a.barter&&(a.hasText?this.eventBarter=a.barter:this.main.showBarter(a.barter)),null!=a.escape))return a.hasText?this.eventEscape=a.escape:this.main.showEscape(a.escape)};ka.prototype.clearActions=function(){this.eventloc=null;this.eventActions=[];this.eventDiff=this.newDiff();this.eventEscape=this.eventBarter=this.eventLoot=null;return this.eventReveals=[]};ka.prototype.prepareWords=function(a,b,c){var d,e,f,g,h,k,l,m,p;var r=[];var t=!1;var u=p="";var v=0;for(e=
a.length;v<e;v++){var y=a[v];if(x)if(" "===y||"$"===y||"_"===y||"."===y||"!"===y||":"===y||";"===y||"'"===y||","===y||"\u3002"===y||"\uff01"===y||"\uff0c"===y){var x=!1;var A=u.toLowerCase();var H=parseInt(A.slice(-1));isNaN(H)&&(H=c);var G=b[H];if("."===y||"!"===y||":"===y||";"===y||"'"===y||","===y)p=y;if(A.startsWith("$playername")){A=null!=(null!=(h=this.eventloc)?h.user:void 0)?this.eventloc.user.displayName:"unknown player";var V=A.split(" ");H=0;for(G=V.length;H<G;H++)A=V[H],r.push({text:A,
highlight:!0,forceSpace:1<V.length})}else if(A.startsWith("$name"))for(H=d=0,f=G.length;d<f;H=++d){var T=G[H];1<G.length&&H===G.length-1&&(A=q.isLocalized("txt-evt-name-list-seperator")?q.toText("txt-evt-name-list-seperator"):",",r.push({text:A,highlight:!1}));V=T.name.split(" ");var B=0;for(g=V.length;B<g;B++)A=V[B],r.push({text:A,person:T,highlight:!1,forceSpace:1<V.length});H<G.length-2&&r.push({text:",",highlight:!1})}else if(A.startsWith("$pyramiddir"))G=q.toText(this.main.worldGenIO.getPyramidDirText(this.main.party.pos)),
G=A.replace("$pyramiddir",G),r.push({text:G,highlight:!0});else if(A.startsWith("$worldnumber"))G=A.replace("$worldnumber",this.main.iomp.worldData.worldID.toString()),r.push({text:G});else if(A.startsWith("$worldduration"))H=new Date(this.main.iomp.worldData.worldStart),G=new Date(Date.now()),G-=H,H=Math.floor(G/36E5),G=Math.floor(H/24),0<G&&(r.push({text:G.toString()}),1<G?r.push({text:q.toText("txt-io-worldDuration-days")+","}):r.push({text:q.toText("txt-io-worldDuration-day")+","})),G=H-24*G,
r.push({text:G.toString()}),1===G?r.push({text:q.toText("txt-io-worldDuration-hour")}):r.push({text:q.toText("txt-io-worldDuration-hours")}),G=A.replace("$worldduration",""),0<G.length&&r.push({text:G});else if(A.startsWith("$playerbestname"))null!=this.main.iomp.currentTopScore?(G=this.main.iomp.currentTopScore.userID,G=null!=this.main.iomp.userDB[G]?this.main.iomp.userDB[G].displayName:"unknown",r.push({text:G})):r.push({text:"unknown"}),G=A.replace("$playerbestname",""),0<G.length&&r.push({text:G});
else if(A.startsWith("$playerbestscore"))null!=this.main.iomp.currentTopScore?r.push({text:this.main.iomp.currentTopScore.points.toString()}):r.push({text:"unknown"}),G=A.replace("$playerbestscore",""),0<G.length&&r.push({text:G});else if(A.startsWith("$playercount"))G=null!=(k=this.main.ioSplash.worldScoreStats.totalUsers)?k:0,r.push({text:G.toString()}),G=A.replace("$playercount",""),0<G.length&&r.push({text:G});else if(A.startsWith("$playedsessions"))G=null!=(l=this.main.ioSplash.worldScoreStats.totalScores)?
l:0,r.push({text:G.toString()}),G=A.replace("$playedsessions",""),0<G.length&&r.push({text:G});else if(A.startsWith("$worldexplored"))G=100*this.main.worldGenIO.getExploredStat(),r.push({text:G.toFixed(1)+"%"}),G=A.replace("$worldexplored",""),0<G.length&&r.push({text:G});else if(A.startsWith("$unlockedhubs"))G=this.main.worldGenIO.unlockedHubs.length,r.push({text:G.toString()}),G=A.replace("$unlockedhubs",""),0<G.length&&r.push({text:G});else if(A.startsWith("$numgamesthisuser"))G=(null!=(m=this.main.ioSplash.worldScoreStats.thisUserScores)?
m:0).toString(),r.push({text:G}),G=A.replace("$numgamesthisuser",""),0<G.length&&r.push({text:G});else if(A.startsWith("$segmentname"))G=this.main.world.toBiomePos(this.main.exped.party.pos),A=this.main.worldGenIO.world.getBiomeIdx(G),A=this.main.worldGenIO.biomes[A],n.assert(null!=A),A=this.main.worldGenIO.worldSegmentList[A.worldSegment],n.assert(null!=A),r.push({text:A.name,highlight:!0});else if(A.startsWith("$currentregion"))G=this.main.world.toBiomePos(this.main.exped.party.pos),A=this.main.worldGenIO.getBiomeDisplayTextX(G.x),
G=this.main.worldGenIO.getBiomeDisplayTextY(G.y),r.push({text:A+", "+G,highlight:!0});else for(d=this.pronouns,H=0,V=d.length;H<V;H++)if(f=d[H],A.startsWith(f.old)){if(0===G.length){this.main.doSendError("unknown gender in text ("+a+")");break}A="male"===G.first().gender?f.male:f.female;A=null!=u[1]&&u[1]===u[1].toLowerCase()?A:A.capitalize();r.push({text:A,highlight:t});break}"_"===y&&(t=!1)}else u+=y;else{if("$"===y)x=!0,u="$";else if(!t&&"_"===y)t=!0;else if(" "!==y&&"_"!==y&&(p+=y," "===config.diaryText.separator||
q.isTextLatin(p))){"_"===y&&(t=!1);continue}0<p.length&&(A=" "!==config.diaryText.separator&&q.isTextLatin(p),r.push({text:p,highlight:t,forceSpace:A}),p="","_"===y&&(t=!1))}}0<p.length&&(A=" "!==config.diaryText.separator&&q.isTextLatin(p),r.push({text:p,highlight:t,forceSpace:A}));this.r.ctx.font=config.fonts.themedSmall;a=0;for(b=r.length;a<b;a++)p=r[a],n.assert(Object.isString(p.text)),p.width=this.r.ctx.measureText(p.text).width;return r};ka.prototype.showEventDialogue=function(a){var b=this,
c,d;this.infoBox.hide();!this.showingEventDialogue&&logs.events&&r.info("DIARY;open");this.showingEventDialogue=!0;this.diary.clearChatQueue();this.main.chat.clearChatQueue();if(null!=a.showImage){var e={};var f=a.showImage.layers;var g=0;for(d=f.length;g<d;g++){var h=f[g];var k=this.r.img.getSpriteSlots(h);for(c in k)h=k[c],e[c]=h.randomize()}if(null!=this.diary.showImage){var l=this.diary.showImage.img;var m=this.diary.showImage.bgImg}this.diary.showImage={img:null!=l?l:this.r.img.emptyEvent,bgImg:null!=
m?m:this.r.img.emptyEvent,slots:e,characters:[],showMounted:a.showImage.showMounted,showCampfire:a.showImage.showCampfire,particles:a.showImage.particles};this.r.img.mergeSpritesASync(a.showImage.layers).then(function(a){if(null!=b.diary.showImage&&(b.diary.showImage.img=a,b.diary.showImage.bgImg=b.r.img.createSilhouette(a,config.diary.bgAlpha),0!==b.diary.imageAlpha))return b.diary.changeTime=0,b.diary.drawMapUnderDiary=!1},function(a){return r.error("mergesprites error: "+a)});this.diary.part.clearParticles();
l=this.main.party.persons;d=0;for(c=l.length;d<c;d++)m=l[d],this.addCharacter(m,a.showImage.showMounted);d=a.npc;c=0;for(l=d.length;c<l;c++)m=d[c],this.addCharacter(m)}else if(null!=this.diary.showImage){d=a.npc;c=0;for(l=d.length;c<l;c++)m=d[c],this.addCharacter(m);d=a.addedCharacters;c=0;for(l=d.length;c<l;c++)m=d[c],this.addCharacter(m);d=a.removedCharacters;c=0;for(l=d.length;c<l;c++)m=d[c],this.removeCharacter(m)}this.diary.showPartyCount=a.showPartyCount;e=a.texts.map(function(a){return a.persons});
a.lines=[];f=a.texts;c=d=0;for(l=f.length;d<l;c=++d)m=f[c],null!=m.text&&a.lines.push(this.prepareWords(m.text,e,c));return this.diary.addDiff(a)};ka.prototype.addCharacter=function(a,b){b=void 0===b?!0:b;var c,d;var e=null!=(d=this.diary.showImage)?d.slots:void 0;a.updateSprite(this.main.getTribeGenAtPartyPos());d=this.r.img.getSprite(a.sprite);if(null==d)r.warn("unknown sprite "+d);else{b=a.getImgSlot(b);null!=e&&(c=e[b]);if(null==c&&(r.warn("no slot ["+b+"] found for "+d.id),b=config.imgSlot.unit,
null!=e&&(c=e[b]),null==c)){r.warn("no slot fallback "+b+" found for "+d.id);return}c=c.sample();null!=e&&null!=c&&e[b].remove(c);a.mirrorTime=0;a.mirrored=.5<Math.random();a.animTime=0;a.sprite=d;null!=c&&(a.eventPos=c);this.diary.showImage.characters.push(a);return this.diary.showImage.characters=this.diary.showImage.characters.exclude(function(a){return null==a.eventPos}).sortBy(function(a){return a.eventPos.y})}};ka.prototype.removeCharacter=function(a){if(null!=this.diary.showImage)return this.diary.showImage.characters.remove(a)};
ka.prototype.hideEventDialogue=function(a){var b,c,d;(d=this.showingEventDialogue)&&logs.events&&r.info("DIARY;close");this.showingEventDialogue=!1;this.diary.breakPage();this.diary.chatQueue=[];this.diary.isChatAllowed=!1;this.diary.highlightPerson=null;this.diary.showImage=null;this.diary.part.clearParticles();var e=this.main.party.persons;var f=0;for(c=e.length;f<c;f++){var g=e[f];var h=g.flags;for(b in h)b.startsWith("temp")&&delete g.flags[b];d&&(g.queuedHealthParticles=0)}this.showReveals();
a||(this.clearActions(),this.main.onActionsChanged());if(n.isIO()&&this.main.canSave()&&d)return this.main.mainMenu.saveGame.updateSaveGame()};ka.prototype.showReveals=function(){var a;null!=(a=this.main.exped)&&a.showReveals(this.eventReveals);return this.eventReveals=[]};ka.prototype.highlightDiff=function(a){0!==a.turns&&this.r.addStatHighlightParticle(a.turns,"Days");0!==a.sanity&&this.r.addStatHighlightParticle(a.sanity,"Sanity");if(0!==a.standing)return this.r.addStatHighlightParticle(a.standing,
"Standing")};var ib=function(a){this.main=a;this.r=this.main.r;this.s=this.main.r.s;this.history=[]};ib.prototype.clear=function(){return this.history=[]};ib.prototype.tick=function(a){var b;var c=this.history;var d=0;for(b=c.length;d<b;d++){var e=c[d];e.time+=e.old?5*a:a;e.dY=Math.min(e.dY+75*a*this.s,e.targetY)}return this.history.remove(function(a){return a.time>=config.notifications.delay})};ib.prototype.addNotify=function(a){var b,c,d,e,f;var g=this.history.length;this.addDiff("turns",a.turns,
q.toText("txt-outro-days"));this.addDiff("sanity",a.sanity,q.toText("txt-base-sanity"));this.addDiff("standing",a.standing,q.toText("txt-base-standing"));null!=a.fame&&0!==a.fame&&this.addLine("standing",q.fmtInt(a.fame)+" "+q.toText("txt-base-fame"));null!=a.funds&&0!==a.funds&&this.addLine("standing",q.fmtInt(a.funds)+" "+q.toText("txt-base-funds"));var h=t.arrify(a.addedCharacters);var k=t.arrify(a.removedCharacters);var l=0;for(e=h.length;l<e;l++){var m=h[l];this.addLine("unit","+ "+m.title,{character:m})}l=
0;for(e=k.length;l<e;l++)m=k[l],this.addLine("unit","- "+m.title,{character:m});l=a.loyalties;for(c in l)e=l[c],m=this.main.party.persons.find(function(a){return a.cid===c}),e=0<e?"txt-outro-loyaltyup":"txt-outro-loyaltydown",this.addLine("unit",q.toText(e),{character:m});m=null!=(b=a.statuses)?b:{};var p=0;for(f=m.length;p<f;p++)l=m[p],e=t.getStatus(l.status),null==e.title||h.find(l.character)||k.find(l.character)||(b=l.enabled?"+":"-",e=b+" "+q.parse(e.title,l.character.gender),this.addLine("statusPos",
e,{character:l.character}));a=null!=(d=a.items)?d:{};for(r in a)h=a[r],d=t.getItem(r),n.assert(null!=h&&!isNaN(h)),0!==h&&(b=0<h?"+":"-",e=q.fmtInt(h)+" "+q.toText(d.name),this.addLine("item",e,{item:d}));d=this.history.length-g;if(0<d){var r=g=d;for(a=this.history.length;d<=a?g<a:g>a;r=d<=a?++g:--g)this.history[r].old=!0}};ib.prototype.addDiff=function(a,b,c){if(null!=b&&0!==b){var d={showSanity:"sanity"===a};this.addLine(a,q.fmtInt(b)+" "+c,d);return!0}return!1};ib.prototype.addLine=function(a,
b,c){c=void 0===c?{}:c;this.history.unshift({time:0,targetY:0,dY:0,type:a,text:b,old:!1,character:c.character,showSanity:c.showSanity,showButterfly:c.showButterfly,item:c.item,claim:c.claim})};ib.prototype.draw=function(a,b){var c,d,e;if(!this.main.showingOutro&&"celebration"!==(c=this.main.getMainState())&&"ionewgame"!==c&&"iosplash"!==c&&!this.r.trailerMode){a=this.main.showingLeftSidebar()?-210:-240;var f=235*this.s+Math.max(a*this.s,this.main.diaryScrollX);var g=90*this.s;this.r.ctx.font=config.fonts.themedSmall;
c=this.history;var h=e=0;for(a=c.length;e<a;h=++e){b=c[h];b.targetY=25*this.s*h;h=config.notifications.sprites[b.type];var k=this.r.img.getSprite(h+".png");var l=J.clamp(b.time,0,1);l=150*TWEEN.Easing.Bounce.Out(l)*this.s-150*this.s;this.r.ctx.globalAlpha=J.clamp(config.notifications.delay-1-b.time,0,1);var m=0;null!=b.showButterfly&&(m+=30*this.s);var p=this.r.ctx.measureText(b.text);p=Math.max(50*this.s,p.width+34*this.s)+m;this.r.ctx.drawImage(k.img,k.pos.x,k.pos.y,k.size.w,k.size.h,f+l,g+b.dY,
p,k.dSize.h);this.r.drawSprite(h+"_end.png",f+l+p-2*this.s,g+b.dY);this.r.drawText(b.text,f+32*this.s+l+m,g+b.dY+14*this.s);null!=b.character?this.r.drawPortrait(b.character,f+18*this.s+l,g+b.dY+20*this.s,{small:!0}):null!=b.item?this.r.drawItem(b.item,f+8*this.s+l,g+b.dY,{showCount:!1,showDecorator:!1}):b.showSanity?this.r.drawSprite("hud_icon_sanity.png",f+8*this.s+l,g+b.dY+2*this.s):null!=b.showButterfly?this.r.ctx.drawImage(b.showButterfly,f+8*this.s+l,g+b.dY-18*this.s):null!=(null!=(d=b.claim)?
d.record:void 0)&&(h=this.main.iomp.getPortrait(b.claim.record.explorerTribe,b.claim.record.explorerSeed,b.claim.record.explorerGender),this.r.drawSprite(h,f+8*this.s+l,g+b.dY-2*this.s))}}};var Kc=function(){var a=function(){};a.prototype.reqTargetChar=function(a,b){return b.targetChar===b.person===a.reqTargetChar};a.prototype.reqLocation=function(a,b){var c,d,g,h,k;var l=a.reqLocation;var m=l.tileKnown;var p=l.locationKnown;a=null!=(g=l.count)?g:"1..";var q=null!=(c=l.range)?c:0;var r=l.reachable;
if("world"!==q&&null==b.pos)return!1;if(n.isIO()&&!b.main.isWarping()&&!m&&!p){g=[];var D=config.locations;for(H in D){var v=D[H];if(null!=v.flags&&t.checkFlags(l.flags,v.flags))g.push(v.id);else{var y=t.arrify(v.spawnEvents);var x=0;for(c=y.length;x<c;x++){var A=y[x];if(null!=A.setLocationFlags&&t.checkFlags(l.flags,A.setLocationFlags)){g.push(v.id);break}}}}if(0<g.length){var H=b.world.toBiomePos(b.pos);"world"===q?(A=b.world.biomeCount.w,c=b.world.biomeCount.h):(c=n.parseRange(q),A=Math.ceil(c[1]/
config.board.biomeSize[0]),c=Math.ceil(c[1]/config.board.biomeSize[1]));D=y=v=H.x-A;for(x=H.x+A;v<=x?y<=x:y>=x;D=v<=x?++y:--y){var G=A=h=H.y-c;for(k=H.y+c;h<=k?A<=k:A>=k;G=h<=k?++A:--A){var V=new u(D,G);G=b.main.worldGenIO.getBiomeDict(V);if(null!=G&&null!=G.locations){var T=0;for(d=g.length;T<d;T++){var B=g[T];if(G.locations.includes(B)){b.main.worldGenIO.generateBiome(V,!0);break}}}}}}}g=b.world.getLocations().count(function(a){var c=b.world.getTile(a.pos);return null!=m&&c.known!==m||null!=p&&
a.known!==p||!t.checkFlags(l.flags,c.location.flags)||null!=r&&r!==c.reachable?!1:"world"===q||n.match(q,b.pos.dist(c.pos))});return n.match(a,g)};a.prototype.reqZone=function(a,b){var c,d;var g=a.reqZone;var h=null!=(d=g.range)?d:"world";a=null!=(c=g.count)?c:"1..";c=b.world.zones.count(function(a){return t.checkFlags(g.flags,a.flags)?"world"===h?!0:n.match(h,b.pos.dist(a.center)):!1});return n.match(a,c)};a.prototype.reqMapScore=function(a,b){return n.match(a.reqMapScore,b.party.mapScore)};a.prototype.reqXP=
function(a,b){return n.match(a.reqXP,b.party.xp)};a.prototype.reqLevel=function(a,b){return n.match(a.reqLevel,b.person.level)};a.prototype.reqGender=function(a,b){return a.reqGender===b.person.gender};a.prototype.reqItems=function(a,b){return t.arrify(a.reqItems).any(function(a){return b.party.inv.hasItemCounts(a)})};a.prototype.reqItemsValue=function(a,b){return n.match(a.reqItemsValue,b.party.inv.getTotalValue())};a.prototype.reqCharacter=function(a,b){var c;return c=b.person.id,0<=F.call(t.arrify(a.reqCharacter),
c)};a.prototype.reqExplorer=function(a,b){return b.party.getExplorer().id===a.reqExplorer};a.prototype.reqSanity=function(a,b){return n.match(a.reqSanity,b.party.sanity)};a.prototype.reqStanding=function(a,b){return n.match(a.reqStanding,b.party.standing)};a.prototype.reqTiles=function(a,b){if(null!=a.reqTiles&&null!=b.pos)return b=b.world.getTile(b.pos),n.assert(Object.isArray(a.reqTiles)),a.reqTiles.includes(b.id)};a.prototype.reqTileFlags=function(a,b){b=b.world.getTile(b.pos);return t.checkFlags(a.reqTileFlags,
b.flags)};a.prototype.reqLocationFlags=function(a,b){return null!=b.location&&t.checkFlags(a.reqLocationFlags,b.location.flags)};a.prototype.reqItemFlags=function(a,b){var c;var d=b.party.inv.items.compact();var g=0;for(b=d.length;g<b;g++){var h=d[g];if(t.checkFlags(a.reqItemFlags,h.flags))return!0;var k=null!=(c=h.subItems)?c:[];var l=0;for(h=k.length;l<h;l++){var m=k[l];if(t.checkFlags(a.reqItemFlags,m.flags))return!0}}return!1};a.prototype.reqTempFlags=function(a,b){return t.checkFlags(a.reqTempFlags,
b.tempFlags)};a.prototype.reqPartyFlags=function(a,b){return t.checkFlags(a.reqPartyFlags,b.party.flags)};a.prototype.reqBiomeFlags=function(a,b){if(null==b.pos)return!0;b=b.world.getTile(b.pos);return null==b?!1:t.checkFlags(a.reqBiomeFlags,b.biome.flags)};a.prototype.reqAge=function(a,b){return n.match(a.reqAge,b.age)};a.prototype.reqDayAge=function(a,b){return n.match(a.reqDayAge,b.dayAge)};a.prototype.reqTripAge=function(a,b){return n.match(a.reqTripAge,b.tripAge)};a.prototype.reqStatusDayAge=
function(a,b){a=a.reqStatusDayAge;b=b.person.statuses[a.ref];return n.match(a.age,null!=b?b.dayAge:-1)};a.prototype.reqTutorial=function(a,b){return null!=b.main.tutorial===a.reqTutorial};a.prototype.reqWorld=function(a,b){if(n.isIO()){if(b.main.isWarping())var c=b.main.worldStack[0].toBiomePos(b.main.worldStack[0].warpPos);else{if(null==b.world||null==b.pos)return!1;c=b.world.toBiomePos(b.pos)}b=b.main.worldGenIO.getBiomeDict(c).worldLvl;return n.match(a.reqWorld,b)}return n.match(a.reqWorld,b.main.worldLvl)};
a.prototype.reqWarpWorld=function(a,b){return b.main.isWarping()===a.reqWarpWorld};a.prototype.reqDifficulty=function(a,b){return n.match(a.reqDifficulty,b.main.difficultyLvl)};a.prototype.reqWorldFlags=function(a,b){return t.checkFlags(a.reqWorldFlags,b.world.flags)};a.prototype.reqPartyCount=function(a,b){return n.match(a.reqPartyCount,b.main.party.unitCount)};a.prototype.reqFreePartyCount=function(a,b){return n.match(a.reqFreePartyCount,b.main.party.getFreeUnitCount())};a.prototype.reqPartyBonus=
function(a,b){a=a.reqPartyBonus;n.assert(Object.isString(a.bonus));n.assert(null!=a.bonus,"No bonus specified for reqPartyBonus");n.assert(null!=a.range,"No range specified for reqPartyBonus");return n.match(a.range,b.main.party.getBonus(a.bonus))};a.prototype.reqStatus=function(a,b){return b.party.hasPersonStatuses(b.person,a.reqStatus)};a.prototype.reqStatusFlags=function(a,b){var c;if(null!=a.reqStatusFlags){b=b.person.statuses;for(c in b){var d=b[c];if(t.checkFlags(a.reqStatusFlags,d.flags))return!0}return!1}};
a.prototype.reqAllStatusFlags=function(a,b){var c;if(null!=a.reqAllStatusFlags){b=b.person.statuses;for(c in b){var d=b[c];if(!t.checkFlags(a.reqAllStatusFlags,d.flags))return!1}return!0}};a.prototype.reqPartyStatus=function(a,b){var c=b.party.getExplorer();return b.party.hasPersonStatuses(c,a.reqPartyStatus)};a.prototype.reqCanDismiss=function(a,d){return b(a,d)?d.person.canDismiss===a.reqCanDismiss:!1};a.prototype.reqCharFlags=function(a,d){return b(a,d)?t.checkFlags(a.reqCharFlags,d.person.flags):
!1};a.prototype.reqMounted=function(a,b){return(null!=b.person.mounted||null!=b.person.riding)===a.reqMounted};a.prototype.reqCanStartSprawl=function(a,b){var c;a=a.reqCanStartSprawl;return b.world.canStartSprawl(a.ref,b.pos,null!=(c=a.radius)?c:0)};a.prototype.reqTurns=function(a,b){return n.match(a.reqTurns,b.main.exped.turn)};a.prototype.reqFame=function(a,b){return n.match(a.reqFame,b.party.fame)};a.prototype.reqFunds=function(a,b){return n.match(a.reqFunds,b.party.funds)};a.prototype.reqRanking=
function(a,b){return n.match(a.reqRanking,b.main.getPartyRank())};a.prototype.reqHealth=function(a,b){return b.person.hasHealth()?n.match(a.reqHealth,b.person.health):!1};a.prototype.reqLoyalty=function(a,b){return b.person.hasLoyalty()?n.match(a.reqLoyalty,b.person.loyalty):!1};a.prototype.reqNoCombat=function(a,b){return a.reqNoCombat===b.party.noCombat};a.prototype.reqMaxPerWorld=function(a,b){return b.party.checkTrackedEvent(a.cid,a.reqMaxPerWorld)};a.prototype.reqKarma=function(a,b){return n.match(a.reqKarma,
b.party.karma)};a.prototype.reqWaiting=function(a,b){return null!=b.main.exped.waiting===a.reqWaiting};a.prototype.reqioNewPlayer=function(a,b,e){return b.main.mainMenu.hasEverStartedGame!==a.reqioNewPlayer};var b=function(a,b){var c;return null!=b.person?!0:r.warn((null!=(c=a.id)?c:"inline-event")+": used requirement without person context")};return a}.call(this);var I=function(){this.applySetupHub=this.applySetupHub.bind(this);this.applyUnlockGoal=this.applyUnlockGoal.bind(this)};I.prototype.applySanity=
function(a,b,c){return c.sanity+=b.party.changeSanity(b.party.parseBonus(a.sanity))};I.prototype.applyMaxSanity=function(a,b,c){return b.party.changeMaxSanity(b.party.parseBonus(a.maxSanity))};I.prototype.applyStanding=function(a,b,c){return c.standing+=b.party.changeStanding(b.party.parseBonus(a.standing))};I.prototype.applyMapScore=function(a,b,c){return b.main.party.changeMapScore(b.party.parseBonus(a.mapScore))};I.prototype.applyFame=function(a,b,c){var d=b.party.fame;a=Math.max(b.party.fame+
b.party.parseBonus(a.fame),0)-d;b.party.changeFame(a,!1);return c.fame+=a};I.prototype.applyFunds=function(a,b,c){var d=b.party.funds;a=Math.max(b.party.funds+b.party.parseBonus(a.funds),0);b.party.funds=a;return c.funds+=a-d};I.prototype.applyGameOver=function(a,b,c){return c.gameOver=q.toText(a.gameOver)};I.prototype.applyAddLocation=function(a,b,c){var d,e,f,g,h,k,l,m,p,q,x,D,v;var y=a.addLocation;var B=null!=(m=y.range)?m:"biome";a=function(){if("biome"===B)return d=b.world.getTile(b.pos).biome,
d.tiles;if("world"===B)return b.world.getBiomes().map(function(a){return a.tiles}).flatten();if(n.isIO()&&b.world===b.main.worldGenIO.world){l=n.parseRange(B);e=null;for(v=0;(null==e||e.isBorder)&&100>v;)v+=1,g=ba.rng.randInt(Math.max(0,l[0]),l[1]+1),h=(new u(ba.rng.rand(-1,1),ba.rng.rand(-1,1))).normal(),k=h.mul(g),k.x=Math.round(k.x),k.y=Math.round(k.y),D=b.pos.add(k),f=b.world.toBiomePos(D),e=b.main.worldGenIO.getBiomeDict(f,!1);if(null!=e&&!e.isBorder)return d=b.world.getBiome(e.pos),d.generated||
d.pos.eq(b.world.toBiomePos(b.pos))||b.main.worldGenIO.generateBiome(e.pos,!0),d.tiles.filter(function(a){return a.pos.sub(b.pos).length()<=l[1]})}else return b.world.getTilesInRange(b.pos,B)}.call(this);null!=y.reqBiomeFlags&&(a=a.filter(function(a){return t.checkFlags(y.reqBiomeFlags,a.biome.flags)}));if(0===a.length)r.warn("effect: failed to find a tile for location "+y.ref);else if(a=b.world.addLocation(y.ref,a,null!=(p=y.animate)?p:!0),null!=a){if(null!=(q=y.setPos)?q:1)b.pos=a.pos;null!=(x=
b.main.exped)&&x.updateVisibility()}else r.warn("effect: failed add location "+y.ref)};I.prototype.applyAddCharacter=function(a,b,c){var d;var e=t.arrify(a.addCharacter);var f=0;for(d=e.length;f<d;f++){a=e[f];if(Object.isString(a))var g=b.party.addCharacter(a);else g=b.party.addCharacter(a.id,a.gender),b.main.doEvent(a,{person:g,silent:!0});null!=g&&(b.main.events.showingEventDialogue&&b.main.events.addCharacter(g),c.addedCharacters.push(g))}};I.prototype.applyNpc=function(a,b,c){b.npc=[];var d=t.arrify(a.npc);
var e=0;for(a=d.length;e<a;e++){var f=d[e];f=new Fa(b.main,f);null!=f.id&&(Math.random()<config.loyalty.randomExtraLoyalty&&(f.loyalty+=1),b.main.doRandEvent(f.spawnEvents,{person:f,silent:!0}),b.npc.push(f),c.npc.push(f))}};I.prototype.applyAddNPC=function(a,b,c){if(n.isTrue(a.addNPC))return n.assert(null!=b.person,"Need person for addNPC effect"),b.party.addCharacter(b.person),c.addedCharacters.push(b.person)};I.prototype.applyShowNPC=function(a,b,c){var d;if(n.isTrue(a.showNPC)){b.npc=[];var e=
t.arrify(b.person);var f=[];var g=0;for(d=e.length;g<d;g++)a=e[g],b.npc.push(a),f.push(c.npc.push(a));return f}};I.prototype.applyRemoveCharacter=function(a,b,c){if(null!=a.removeCharacter&&a.removeCharacter)return n.assert(null!=b.person,"Need person for remove character effect"),b.party.removeCharacter(b.person),b.main.events.removeCharacter(b.person),c.removedCharacters.push(b.person)};I.prototype.applyStoreCharacter=function(a,b,c){if(n.isTrue(a.storeCharacter))return b.person.isMember&&(b.party.removeCharacter(b.person),
c.removedCharacters.push(b.person)),b.party.storePerson(b.person),b.main.events.removeCharacter(b.person)};I.prototype.applyUnstoreCharacter=function(a,b,c){if(n.isTrue(a.unstoreCharacter))return b.party.store.remove(b.person)};I.prototype.applyRestoreCharacter=function(a,b,c){if(n.isTrue(a.restoreCharacter))return n.assert(null!=b.person,"Restore character (ctx) needs person context"),b.party.addCharacter(b.person),b.party.store.remove(b.person),c.addedCharacters.push(b.person)};I.prototype.applyRevealTiles=
function(a,b,c){var d,e,f,g;a=a.revealTiles;return c.reveals.push({pos:b.pos,visible:null!=(d=a.visible)?d:!0,location:null!=(e=a.location)?e:!1,radius:b.party.parseBonus(null!=(f=a.radius)?f:0),centerCam:null!=(g=a.centerCam)?g:!1,particle:a.particle})};I.prototype.applyRevealBiome=function(a,b,c){var d,e;if(null!=a.revealBiome){a=a.revealBiome;c=null!=(d=a.locationKnown)?d:!0;d=b.world.getTile(b.pos).biome;if(null!=a.particle){var f=d.tiles;var g=0;for(e=f.length;g<e;g++){var h=f[g];if(!h.known){var k=
t.getParticle(a.particle);var l=b.main.r.part.getParticlePositionForTilePos(k,h.pos);h=.5*h.pos.dist(b.pos);b.main.r.part.addParticleConf(k,l,{step:h})}}}return b.main.exped.revealBiome(d,c)}};I.prototype.applyReplaceTiles=function(a,b,c){var d,e,f,g,h;var k=!1;var l=t.arrify(a.replaceTiles);var m=0;for(c=l.length;m<c;m++){var p=l[m];n.assertOpts(p,"replaceTiles",b,a.mod);var q=null!=p.range?b.world.getTilesInRange(b.pos,b.party.parseRangeBonus(p.range)):b.world.getTilesInRadius(b.pos,b.party.parseBonus(null!=
(f=p.radius)?f:0));var r=p["new"];n.assert(null!=r,"Need to specify new property for replaceTiles");var u=b.world.getTile(b.pos);var v="any"===p.old?q:(e=t.arrify(null!=(g=p.old)?g:u.id),q.filter(function(a){return e.any(function(b){return b===a.id})}));var y=0;for(q=v.length;y<q;y++)if(u=v[y],null!=u.id&&!(null!=p.chance&&ba.rng.random()>p.chance)){var x=null!=(h=p.animate)?h:!0;x=b.world.replaceTile(u,r,{animate:x});k||(k=null!=x);if(u.known){var A=t.arrify(p.particle);x=0;for(d=A.length;x<d;x++){var H=
A[x];H=t.getParticle(H);var G=b.main.r.part.getParticlePositionForTilePos(H,u.pos);b.main.r.part.addParticleConf(H,G)}}}}if(null!=b.party.pos&&k)return b.main.exped.updateVisibility()};I.prototype.applyReplaceLocations=function(a,b,c){var d,e,f;if(null!=a.replaceLocations){var g=t.arrify(a.replaceLocations);var h=[];var k=0;for(a=g.length;k<a;k++){var l=g[k];var m=b.world.getLocationsArea(b.pos,b.party,null!=(d=l.range)?d:0);c=l["new"];var p=b.world.getTile(b.pos);var n=null!=(e=l.oldFlags)?e:"";
var q=t.arrify(l.old);m=m.filter(function(a){return t.checkFlags(n,a.location.flags)&&0===q.length||q.any(a.location.id)});var r=0;for(l=m.length;r<l;r++)p=m[r],null!=c?b.world.replaceLocation(p,c):b.world.removeLocation(p),b.main.party.changeMapScore(0);h.push(null!=(f=b.main.exped)?f.changeCompassScore():void 0)}return h}};I.prototype.applyCompassScore=function(a,b,c){return b.main.exped.changeCompassScore(b.party.parseBonus(a.compassScore))};I.prototype.applySetCharFlags=function(a,b,c){return t.setFlags(a.setCharFlags,
b.person.flags)};I.prototype.applySetTempFlags=function(a,b,c){return t.setFlags(a.setTempFlags,b.tempFlags)};I.prototype.applySetPartyFlags=function(a,b,c){n.assert(null!=b.party,"Need party context for setting party flags");return b.party.setFlags(a.setPartyFlags)};I.prototype.applySetTileFlags=function(a,b,c){var d;if(null!=a.setTileFlags){n.assert(null!=b.main,"Need to be in travel mode for map effect");b=b.world.getArea(b.pos,null!=(d=a.setTileFlags.range)?d:0);c=[];var e=0;for(d=b.length;e<
d;e++){var f=b[e];t.setFlags(a.setTileFlags,f.flags);c.push(f.markChanged())}return c}};I.prototype.applySetLocationFlags=function(a,b,c){if(null!=b.location&&(t.setFlags(a.setLocationFlags,b.location.flags),a=b.world.getTile(b.location.pos),null!=a))return a.markChanged()};I.prototype.applySetLocationParticle=function(a,b,c){b=b.world.getTile(b.pos);if(null!=b)return b.location.particle=a.setLocationParticle,b.markChanged()};I.prototype.applyResetLocationAge=function(a,b,c){if(n.isTrue(a.resetLocationAge)&&
(n.assertOpts(a.resetLocationAge,"resetLocationAge",b,a.mod),a=b.world.getTile(b.pos),null!=a))return a.location.clearAge(),a.markChanged()};I.prototype.applySetWorldFlags=function(a,b,c){return t.setFlags(a.setWorldFlags,b.world.flags)};I.prototype.applySetBiomeFlags=function(a,b){b=b.world.getTile(b.pos);return t.setFlags(a.setBiomeFlags,b.biome.flags)};I.addStatusChangesToDiff=function(a,b){var c;var d=[];var e=0;for(c=a.length;e<c;e++){var f=a[e];var g=t.getStatus(f.status);n.assert(null!=g,"No status inside of statusChange");
g.hideNotifications?d.push(void 0):d.push(b.statuses.add(f))}return d};I.prototype.applyRemoveStatus=function(a,b,c){if(n.isTrue(a.removeStatus))return n.assert(null!=b.person,"Need person for removeStatus"),a={},a[b.status.id]=!1,b=b.party.setPersonStatuses(b.person,a,!1),I.addStatusChangesToDiff(b,c)};I.prototype.applySetStatus=function(a,b,c){a=b.party.setPersonStatuses(b.person,a.setStatus);if(b.person.isMember)return I.addStatusChangesToDiff(a,c)};I.prototype.applyRemoveStatusWithFlags=function(a,
b,c){var d;var e=[];var f=b.person;var g=f.statuses;for(d in g){var h=g[d];t.checkFlags(a.removeStatusWithFlags,h.flags)&&f.setStatus(d,!1)&&e.push({character:f,status:d,enabled:!1})}if(b.person.isMember)return I.addStatusChangesToDiff(e,c)};I.prototype.applySetPartyStatus=function(a,b,c){a=b.party.setPersonStatuses(b.party.getExplorer(),a.setPartyStatus);return I.addStatusChangesToDiff(a,c)};I.prototype.applyResetPartyStatus=function(a,b,c){a=b.party.setPersonStatuses(b.party.getExplorer(),a.resetPartyStatus,
!0);return I.addStatusChangesToDiff(a,c)};I.prototype.applyResetStatus=function(a,b,c){var d;c=a.resetStatus;var e=[];for(d in c)a=c[d],e.push(b.person.setStatus(d,a,!0));return e};I.prototype.applyResetStatusAge=function(a,b,c){n.assert(null!=b.status,"Need status for resetStatusAge");return b.status.clearAge()};I.prototype.applyTurns=function(a,b,c){return c.turns+=a.turns};I.prototype.applyAddZone=function(a,b,c){var d,e,f;c=a.addZone.ref;var g=null!=(d=a.addZone.range)?d:"..1";d=null!=(e=a.addZone.seeking)?
e:!1;a=null!=(f=a.addZone.reachable)?f:!1;return b.world.addZone(c,b.pos,g,d,0,a)};I.prototype.applyRemoveZone=function(a,b,c){if(n.isTrue(a.removeZone))return b.world.removeZone(b.zone)};I.prototype.applyRemoveZones=function(a,b,c){var d,e,f;return null!=a.removeZones.range?(c=b.world.getTilesInRange(b.pos,b.party.parseRangeBonus(a.removeZones.range)),b.world.removeZonesFromTiles(c,null!=(d=a.removeZones.flags)?d:"")):b.world.removeZonesInRadius(b.pos,b.party.parseBonus(null!=(e=a.removeZones.radius)?
e:0),null!=(f=a.removeZones.flags)?f:"")};I.prototype.applyDeactivateZones=function(a,b,c){var d,e;return b.world.deactivateZonesInRadius(b.pos,b.party.parseBonus(null!=(d=a.deactivateZones.radius)?d:0),b.party.parseBonus(null!=(e=a.deactivateZones.turns)?e:2))};I.prototype.applyStartWorld=function(a,b,c){if(n.isTrue(a.startWorld))return c.startWorld=!0};I.prototype.applyEndWorld=function(a,b,c){var d;if(n.isTrue(a.endWorld)){n.assertOpts(a.endWorld,"endWorld",b,a.mod);if(n.isIO()){a=0;var e=b.party.inv.items;
var f=0;for(d=e.length;f<d;f++){var g=e[f];if(null!=g){0<g.amount&&0<g.getFame()&&(a+=g.getFame()*g.amount,b.party.incStatRankingGift(g.id,g.amount));var h=g.subItems;var k=0;for(g=h.length;k<g;k++){var l=h[k];0<l.amount&&0<l.getFame()&&(a+=l.getFame()*l.amount,b.party.incStatRankingGift(l.id,l.amount))}}}0<a&&(a+=Math.round(a*b.party.getBonus("fameScale")),b.party.changeFame(a,!1),c.fame+=a);return c.gameOver=q.toText("txt-io-gameover-success")}return c.endWorld={goalFame:null!=(d=a.endWorld.goalFame)?
d:!0}}};I.prototype.applyPlayTutorial=function(a,b,c){b.main.mainMenu.saveGame.clearSaveGame();debug.skipStartEvents=!1;return b.main.startTutorial()};I.prototype.applyTeleport=function(a,b,c){if(n.isTrue(a.teleport))return a=b.pos,b.world.validSpawnTile(b.world.getTile(a))||(a=b.world.getTilesInRadius(b.pos,1,!1).filter(function(a){return b.world.validSpawnTile(a)}),a=0<a.length?a.sample().pos:null),c.teleport=a};I.prototype.applyResetGlobalInv=function(a,b,c){return b.main.globalInvs[a.resetGlobalInv]=
null};I.prototype.applyBarter=function(a,b,c){var d,e,f,g,h,k,l,m;a=a.barter;var p=e=null;var r={};var u=null!=(d=a.invName)?d:"barter";d=null;null!=a.globalInv?(d=a.globalInv,e=b.main.globalInvs[d]):null!=b.location?(e=b.location.invs[u],p=b.location.priceTable,r=b.location.initItems):"barter"!==u&&(d=u,e=b.main.globalInvs[d]);r=null!=(f=a.items)?f:r;if(null==e)r=b.main.randItemSet(r),e=new Va(b.main,r),null!=d?b.main.globalInvs[d]=e:null!=b.location&&(b.location.invs[u]=e);else if(!e.didEverTransferMeta){d=
e.items;var D=0;for(f=d.length;D<f;D++)u=d[D],null!=u&&u.metaItem&&e.changeItemCount(u,-u.amount);r=b.main.randItemSet(r);d=0;for(f=r.length;d<f;d++)u=r[d],u.metaItem&&e.changeItemCount(u,u.amount)}u=Object.isString(a.baseValue)?a.baseValue:b.party.parseBonus(null!=(g=a.baseValue)?g:0);c.showEvent=!0;return c.barter={inv:e,close:a.closeEvents,cancel:null!=(h=a.cancelEvents)?h:a.closeEvents,baseValue:u,title:q.toText(null!=(k=a.title)?k:"txt-barter-their"),priceTable:null!=(l=a.priceTable)?l:p,hideNPCInv:n.isTrue(a.hideNPCInv),
hidePartyOffer:n.isTrue(a.hidePartyOffer),itemEvents:t.arrify(a.itemEvents),person:b.person,reqItemFlags:null!=(m=a.reqItemFlags)?m:[]}};I.prototype.applyLoot=function(a,b,c){var d,e,f,g,h,k,l,m,p;a=a.loot;var n=null!=(d=a.invName)?d:null!=(f=b.location)&&f.hasStash?"stash":"loot";d=null!=(e=b.inv)?e:null!=(g=b.location)?g.invs[n]:void 0;null==d&&(e=b.main.randItemSet(a.items),d=new Va(b.main,e),null!=b.location&&(b.location.invs[n]=d,b.world.getTile(b.location.pos).markChanged()));c.showEvent=!0;
return c.loot={inv:d,close:a.closeEvents,cancel:null!=(h=a.cancelEvents)?h:a.closeEvents,itemEvents:t.arrify(a.itemEvents),person:b.person,title:q.toText(null!=(k=a.title)?k:"txt-barter-loot"),slots:null!=(l=a.slots)?l:-1,reqItemFlags:null!=(m=a.reqItemFlags)?m:[],consumeFameItems:null!=(p=a.consumeFameItems)?p:!1}};I.prototype.applyEscape=function(a,b,c){var d;a=a.escape;c.showEvent=!0;return c.escape={close:a.closeEvents,cancel:null!=(d=a.cancelEvents)?d:a.closeEvents,title:q.toText(a.title),slots:a.slots}};
I.prototype.applyItems=function(a,b,c){var d,e,f;var g=b.main.randItemSet(a.items);var h=0;for(e=g.length;h<e;h++){var k=g[h];b.party.inv.changeItemCount(k.id,k.amount);0<k.amount&&b.party.incStatItemEvent(k.id,k.amount);a.items.hideNotifications||(null==(d=c.items)[f=k.id]&&(d[f]=0),c.items[k.id]+=k.amount)}return b.main.onBonusChanged()};I.prototype.applyRemoveItem=function(a,b,c){var d,e;if(n.isTrue(a.removeItem))return n.assertOpts(a.removeItem,"removeItem",b,a.mod),b.item.consume(),null==(d=
c.items)[e=b.item.id]&&(d[e]=0),--c.items[b.item.id],b.main.onBonusChanged()};I.prototype.applyDropItems=function(a,b,c){return c.items=b.party.inv.dropRandItems(a.dropItems)};I.prototype.applyChallenge=function(a,b,c){var d,e,f;a=a.challenge;n.assert(null!=a.goals,"Need goals for challenge");b.main.showChallenge(Object.clone(a.goals,!0),null!=(d=a.type)?d:"survival",null!=(e=a.sanityCost)?e:0,null!=(f=a.maxTries)?f:0,a.success,a.win,a.cancel);return c.showEvent=!0};I.prototype.applyCombat=function(a,
b,c){var d,e;if(Object.isObject(a.combat)){var f=null!=(d=a.combat.surprise)?d:!1;var g=a.combat.winEvents;var h=a.combat.fleeEvents;d=t.arrify(a.combat.refs);var k=null!=(e=a.combat.combatMusic)?e:null}else f=!1,d=t.arrify(a.combat);null==k&&null!=b.zone&&(a=t.getZone(b.zone.id),null!=a&&null!=a.combatMusic&&(k=a.combatMusic));b.main.showCombat(d,b.zone,f||b.enemyAttacks,g,h,k);return c.showEvent=!0};I.prototype.applyChat=function(a,b,c){var d;if(Object.isObject(a.chat)){if(null!=(d=Math.random()>
a.chat.chance)?d:1)return;a=a.chat.id}else a=a.chat;return c.chats.add(b.main.randChatLine(a,b))};I.prototype.applyShowPartyCount=function(a,b,c){if(n.isTrue(a.showPartyCount))return c.showPartyCount=!0};I.prototype.applyShowImage=function(a,b,c){var d,e,f,g,h,k,l;var m=function(a,b){return null==a||null==a.eventImg?null:Object.isString(a.eventImg)?a.eventImg:a.eventImg[b]};if(null!=a.showImage){var p=[];var n=null!=(e=null!=(f=b.location)?f.pos:void 0)?e:b.pos;null!=n&&(n=b.world.getTile(n),b=n.biome,
e=null!=(g=a.showImage.type)?g:"default",p.add([m(b,e),m(n,e),m(n.location,e)].compact()));Object.isString(a.showImage)?p.push(a.showImage):null!=a.showImage.src&&p.push(a.showImage.src);m=null!=(d=a.showImage.particlesChance)?d:1;d=[];ba.rng.random()<m&&(d=t.arrify(a.showImage.particles));return c.showImage={layers:p,npcSprites:t.arrify(a.showImage.npc),npcMovement:null!=(h=a.showImage.npcMovement)?h:!1,showMounted:null!=(k=a.showImage.showMounted)?k:!0,showCampfire:null!=(l=a.showImage.showCampfire)?
l:!0,particles:d}}};I.prototype.applyCompactAndStack=function(a,b,c){var d;c=t.arrify(a.compactAndStack);var e=[];var f=0;for(d=c.length;f<d;f++)a=c[f],e.push(b.party.inv.compactAndStack(a));return e};I.prototype.applyIoRemovePlayerDeath=function(a,b,c){var d;if(null!=(null!=(d=b.location)?d.user:void 0))return c=$jscomp.makeIterator(b.world.toLocalPos(b.pos)),a=c.next().value,c=c.next().value,b.main.iomp.clearDeathRecord(b.world.getBiomeIdx(a.pos),c,b.location.user.userID)};I.prototype.applyioSetLocationFlags=
function(a,b,c){if(!b.main.isWarping()){var d=$jscomp.makeIterator(b.world.toLocalPos(b.pos));c=d.next().value;d=d.next().value;return b.main.iomp.setLocationFlags(b.world.getBiomeIdx(c.pos),d,a.ioSetLocationFlags)}};I.prototype.applyioAddLiveLog=function(a,b,c){var d,e;var f=$jscomp.makeIterator(b.world.toLocalPos(b.pos));c=f.next().value;f.next();var g=Ac[a.ioAddLiveLog.logType];f={};a=null!=(d=a.ioAddLiveLog.keys)?d:[];var h=0;for(e=a.length;h<e;h++){d=a[h];var k=null;switch(d){case "pyramidDir":k=
b.main.worldGenIO.getPyramidDirText(b.pos)}null!=k&&(f[d]=k)}return b.main.iomp.addLiveLog(b.world.getBiomeIdx(c.pos),g,f)};I.prototype.applyPlayMusic=function(a,b,c){a=t.arrify(a.playMusic).sample();return c.playMusic=a};I.prototype.applyPlaySound=function(a,b,c){a=t.arrify(a.playSound).sample();return c.playSound=a};I.prototype.applyCamShake=function(a,b,c){var d,e;c=null;null!=b.pos&&(c=b.main.r.getTileScreenPos(b.pos,!1,!0,!0));return b.main.r.cam.addCamShake(null!=(d=a.camShake.power)?d:1,null!=
(e=a.camShake.length)?e:.2,c)};I.prototype.applyParticle=function(a,b,c){c=t.arrify(a.particle);var d=[];var e=0;for(a=c.length;e<a;e++){var f=c[e];f=t.getParticle(f);var g=b.main.r.part.getParticlePositionForTilePos(f,b.pos);d.push(b.main.r.part.addParticleConf(f,g))}return d};I.prototype.applyRest=function(a,b,c){a=a.rest;var d=b.party.parseBonus(a.sanity);b.main.exped.rest(d,a.events);return c.pendingEvent=!0};I.prototype.applyWait=function(a,b,c){a=a.wait;b.main.exped.wait(a.turns,0,a.events,
!1,a.waitLabel);return c.pendingEvent=!0};I.prototype.applyStartSprawl=function(a,b,c){var d,e,f,g;a=a.startSprawl;c=null!=(d=a.radius)?d:0;d=null!=(e=a.count)?e:1;e=null!=(f=a.power)?f:100;f=null!=(g=a.worldPower)?g:0;e+=b.main.worldLvl*f;return b.main.world.startSprawl(a.ref,b.pos,c,e,d)};I.prototype.applyUnlockCharacter=function(a,b,c){if(!n.isIO()&&"base"===a.mod&&(n.assert(Object.values(config.characters).any(function(b){return b.id===a.unlockCharacter})),b.main.mainMenu.unlockCharacter(a.unlockCharacter)))return b.main.achievementBox.queueUnlockedChar(a.unlockCharacter,
7)};I.prototype.applyUnlockPocket=function(a,b,c){b.party.unlockPocket(a.unlockPocket);return b.main.chat.showUnlock(q.toText("txt-base-unlockSite"))};I.prototype.applyIncAchievement=function(a,b,c){if("base"===a.mod)return b.main.achievements.incCounter(a.incAchievement)};I.prototype.applyAddButterfly=function(a,b,c){var d;a=null!=(d=a.addButterfly.count)?d:1;a.times(function(){return b.main.taxonomy.addRandButterfly()});return b.main.achievements.incCounter("ach-butterfly-collect",a)};I.prototype.applyRegenBiome=
function(a,b,c){var d=b.world.getTile(b.pos);c=d.id;null!=a.regenBiome.biomeId&&(d.biome.id=a.regenBiome.biomeId);b.main.worldGen.buildPerlin(d.biome);b.main.worldGen.clearLocations(d.biome);b.main.worldGen.buildLocations(d.biome);return b.world.replaceTile(d,c)};I.prototype.applyHealth=function(a,b,c){return b.person.changeHealth(a.health)};I.prototype.applyLoyalty=function(a,b,c){var d,e;a=b.person.changeLoyalty(a.loyalty);if(0!==a)return null==(d=c.loyalties)[e=b.person.cid]&&(d[e]=0),c.loyalties[b.person.cid]+=
a};I.prototype.applySuperMove=function(a,b,c){return b.party.isSuperMove=!0};I.prototype.applyResetVisibility=function(a,b,c){return b.main.exped.resetVisibility()};I.prototype.applyWarpWorld=function(a,b,c){return b.main.warpWorld(a.warpWorld)};I.prototype.applyUnwarpWorld=function(a,b,c){return b.main.unwarpWorld(a.unwarpWorld)};I.prototype.applyKarma=function(a,b,c){return b.party.changeKarma(a.karma)};I.prototype.applyBlockRivals=function(a,b,c){c=b.main.rivals;var d=[];var e=0;for(b=c.length;e<
b;e++){var f=c[e];d.push(f.blockedTurns=a.blockRivals)}return d};I.prototype.applyCloneCharacter=function(a,b,c){var d;a=new Fa(b.main,b.person.id);a.name=b.person.name;a.setVariation(b.person.variationIdx);a.setLevel(b.person.level);a.health=b.person.health;a.loyalty=b.person.loyalty;a.storeAge=b.person.storeAge;a.genLayers=b.person.genLayers;a.colorTable=b.person.colorTable;a.flags=Object.clone(b.person.flags);a.statuses={};c=b.person.statuses;for(d in c){var e=c[d];var f=new kc(d,!1,b.person.gender);
f.dayAge=e.dayAge;f.tripAge=e.tripAge;f.isDefault=e.isDefault;a.statuses[d]=f}return b.party.addCharacter(a)};I.prototype.applyForceTravel=function(a,b,c){if(n.isTrue(a.forceTravel))return b.main.exped.sledgeTravel(b.pos)};I.prototype.applySetupHub=function(a,b,c){n.assert(null!=b.location);a=b.main.worldGenIO.world.toBiomePos(b.location.pos);a=b.main.worldGenIO.getBiomeDict(a);n.assert(null!=a);c=b.main.worldGenIO.worldSegmentList[a.worldSegment];n.assert(null!=c);b.location.name=c.name+" "+q.toText(b.location.name);
b.main.worldGenIO.unlockedHubs.includes(a.biomeIdx)&&t.setFlags("+explored",b.location.flags)};I.prototype.applyUnlockHub=function(a,b,c){a=b.main.worldGenIO.world.toBiomePos(b.pos);a=b.main.worldGenIO.getBiomeDict(a);b.main.worldGenIO.unlockedHubs.includes(a.biomeIdx)||b.main.iomp.unlockHub(a.biomeIdx)};I.prototype.applyUnlockGoal=function(a,b,c){return b.main.iomp.unlockGoal()};I.prototype.applyGivePack=function(a,b,c){c=parseInt(a.givePack);var d=function(c){var e=Object.values(config.packs).filter(function(a){var d;
return c===(null!=(d=a.value)?d:0)&&b.main.ioInv.canGivePack(a.id)});var g=e.filter(function(a){return!b.main.ioInv.isPackInInventory(a.id)});g=10<g.length?g:e;if(0===g.length)1<c?d(c-1):r.warn("applyGivePack: no packs found with value in range "+a.givePack+", "+a.cid);else return g=g.sample(),b.main.ioInv.addPack(g.id)};d(c)};I.prototype.applyracetrackEvents=function(a,b,c){var d=t.arrify(a.racetrackEvents);var e=0;for(c=d.length;e<c;e++){var f=d[e];if(null!=f.select){var g=ka.randEntry(f.select);
if(null!=g){var h=g.ref;var k=g.text}}else h=f.ref,k=f.text;null==h?r.info("no event for racetrack in "+a.cid):(g={ref:h,onDay:f.inDays+b.main.exped.turn,icon:f.icon,text:k},b.main.exped.raceTrack.push(g))}};var Jc=I;var Md=function(){var a=function(a,c,d,e){this.getName=this.getName.bind(this);this.getDesc=this.getDesc.bind(this);this.id=a;this.name=c;this.desc=d;this.img=e;this.counters=[0,0,0];this.unlocked=[!1,!1,!1]};a.prototype.getName=function(){return this.name};a.prototype.getDesc=function(){return!this.secret||
this.unlocked.some(!0)||debug.drawAllItems?this.desc:"???"};a.prototype.counterTarget=1;a.prototype.secret=!1;a.prototype.updateInterval=5;return a}.call(this);var Nd=function(){var a=function(a){this.tick=this.tick.bind(this);this.elementsMatch=this.elementsMatch.bind(this);this.queueElement=this.queueElement.bind(this);this.queueAchievement=this.queueAchievement.bind(this);this.queueUnlockedChar=this.queueUnlockedChar.bind(this);this.queuePack=this.queuePack.bind(this);this.queueMedals=this.queueMedals.bind(this);
this.queueAlphaKey=this.queueAlphaKey.bind(this);this.setDisplayElement=this.setDisplayElement.bind(this);this.draw=this.draw.bind(this);this.main=a;this.r=this.main.r;this.s=this.main.r.s};a.prototype.tick=function(a){"loading"===this.main.getMainState()||null!=this.main.iomp&&this.main.iomp.isStoreOpen()||(this.timeout-=a,0>this.timeout&&(null!=this.element&&null!=this.element.medals&&this.main.iomp.setTransactionNotified(this.element.medals.tid),0<this.queue.length?(a=this.queue.shift(),this.setDisplayElement(a),
this.main.sfx.play("achievement")):this.element=null))};a.prototype.elementsMatch=function(a,c){return null==a||null==c?!1:null!=a.achieve&&null!=c.achieve?a.achieve.id===c.achieve.id:null!=a.char&&null!=c.char?a.char===c.char:!1};a.prototype.queueElement=function(a){var b;if(!this.elementsMatch(a,this.element)){var d=this.queue;var e=0;for(b=d.length;e<b;e++){var f=d[e];if(this.elementsMatch(f,a))return}return this.queue.add(a)}};a.prototype.queueAchievement=function(a,c){return this.queueElement({achieve:a,
time:void 0===c?7:c})};a.prototype.queueUnlockedChar=function(a,c){return this.queueElement({char:a,time:void 0===c?7:c})};a.prototype.queuePack=function(a,c){return this.queueElement({pack:a,time:void 0===c?7:c})};a.prototype.queueMedals=function(a,c){c=void 0===c?7:c;n.assert(null!=a.type);return this.queueElement({medals:a,time:c})};a.prototype.queueAlphaKey=function(a,c){return this.queueElement({alphaKey:a,time:void 0===c?15:c})};a.prototype.setDisplayElement=function(a){this.element=a;return this.timeoutStart=
this.timeout=a.time};a.prototype.draw=function(){var a;if(null!=this.element){var c=$jscomp.makeIterator(this.r.getCanvasSize());var d=c.next().value;c.next();c=Math.min(this.timeoutStart-this.timeout,1);var e=Math.max(1-this.timeout,0);this.timeout>this.fadeOutTime&&(a=TWEEN.Easing.Bounce.Out(c));this.timeout<=this.fadeOutTime&&(a=1-TWEEN.Easing.Circular.Out(e));d=new u(d-this.width*this.s*a,50*this.s);return null!=this.element.achieve?this.r.drawAchievement(d.x,d.y,this.width,this.height,this.element.achieve):
null!=this.element.char?this.r.drawUnlockedChar(d.x,d.y,this.width,this.height,this.element.char):null!=this.element.pack?this.r.drawGivenPack(d.x,d.y,this.width,this.element.pack):null!=this.element.medals?this.r.drawGivenMedals(d.x,d.y,this.width,this.element.medals):null!=this.element.alphaKey?this.r.drawGivenAlphaKey(d.x,d.y,this.width):r.warn("achievement box without known element")}};a.prototype.element=null;a.prototype.timeout=0;a.prototype.timeoutStart=0;a.prototype.width=200;a.prototype.height=
52;a.prototype.fadeOutTime=1;a.prototype.queue=[];return a}.call(this);var Xa=function(a,b){var c,d,e,f,g,h;this.getUnlockedAchievements=this.getUnlockedAchievements.bind(this);this.resetAchievements=this.resetAchievements.bind(this);this.tick=this.tick.bind(this);this.updateTracker=this.updateTracker.bind(this);this.unlockSteamAchievementIfNecessary=this.unlockSteamAchievementIfNecessary.bind(this);this.syncWithSteam=this.syncWithSteam.bind(this);this.incCounter=this.incCounter.bind(this);this.setCounter=
this.setCounter.bind(this);this.showAchievement=this.showAchievement.bind(this);this.main=a;this.trackingData=null!=(d=this.main.mainMenu.playerData.achievements)?d:{};this.lastShowTime=-1E8;this.achievements={};var k=0;for(d=b.length;k<d;k++){var l=b[k];a=new Md(l.id,l.name,l.desc,l.img);a.counterTarget=null!=(f=l.counterTarget)?f:1;a.secret=null!=(g=l.secret)?g:!1;a.updateInterval=null!=(h=l.updateInterval)?h:5;this.achievements[a.id]=a;if(null!=this.trackingData[a.id])try{var m=[0,1,2];var p=0;
for(e=m.length;p<e;p++){var q=m[p];a.unlocked[q]=this.trackingData[a.id].unlocked[q];a.counters[q]=this.trackingData[a.id].counters[q]}}catch(da){l=da,this.main.doSendError("could not restore achievement "+a.id+": "+l.message),null!=a.counters&&(a.counters=[0,0,0]),a.unlocked=[!1,!1,!1]}}this.syncWithSteam();if(n.isTCE())for(b=JSON.parse(null!=(c=localStorage.getItem("io-achieves"))?c:"[]"),c=0,e=b.length;c<e;c++)q=b[c],this.incCounter(q)};Xa.prototype.getUnlockedAchievements=function(a){a=void 0===
a?1:a;var b;var c=[];var d=this.trackingData;for(b in d){var e=d[b];e.unlocked[a]&&c.push(b)}return c};Xa.prototype.resetAchievements=function(){var a;this.trackingData={};this.main.mainMenu.playerData.achievements=this.trackingData;var b=this.achievements;for(a in b){var c=b[a];null!=c.counters&&(c.counters=[0,0,0]);c.unlocked=[!1,!1,!1]}b=this.trackingData;for(a in b)c=b[a],c.unlocked=[!1,!1,!1],c.counters=[0,0,0];this.main.achievementBox.element=null;this.main.achievementBox.queue=[]};Xa.prototype.tick=
function(){if(this.achievementsTrackingDirty)return this.main.mainMenu.playerData.achievements=this.trackingData,this.main.mainMenu.updatePlayerData(),this.achievementsTrackingDirty=!1};Xa.prototype.updateTracker=function(a){var b;this.trackingData[a]||(this.trackingData[a]={});var c=this.achievements[a];var d=this.trackingData[a];null==d.unlocked&&(d.unlocked=[!1,!1,!1]);var e=!1;if(null!=c.counterTarget){d.counters=[0,0,0];c.unlocked=[!1,!1,!1];var f=[0,1,2];var g=0;for(b=f.length;g<b;g++){var h=
f[g];d.counters[h]=Math.min(c.counters[h],c.counterTarget);c.unlocked[h]=d.counters[h]>=c.counterTarget;c.unlocked[h]&&!d.unlocked[h]&&(e=!0,d.unlocked[h]=!0)}}e&&this.showAchievement(a);this.syncWithSteam(a);this.achievementsTrackingDirty=!0};Xa.prototype.unlockSteamAchievementIfNecessary=function(a){greenworks.getAchievement(a,function(b){if(!b)return greenworks.activateAchievement(a,function(){return r.log(a+" unlocked")},function(a){return r.error(a)})},function(a){return r.error(a)})};Xa.prototype.syncWithSteam=
function(a){var b;if(window.isSteam){var c=!1;var d=this.achievements;for(b in d){var e=d[b];if(null==a||b===a)if(e.unlocked.some(!0)&&this.unlockSteamAchievementIfNecessary(b),1<e.counterTarget){var f=e.counters.max();var g=b+"-count";e=greenworks.getStatInt(g);e<f&&(greenworks.setStat(g,f)?c=!0:r.error("Error setting stat "+g+" to "+f))}}c&&(r.info("GREENWORKS;sync stats"),greenworks.storeStats(function(a){return r.log("steam achievements synched")},function(a){return r.error(a)}))}};Xa.prototype.canUnlockAchievements=
function(){return(!debug.showDebugBar||debug.isDevMode)&&n.isTCE()};Xa.prototype.incCounter=function(a,b){b=void 0===b?1:b;var c,d,e;var f=null!=(c=this.main.difficultyLvl)?c:1;c=this.achievements[a];if(null==c)r.error("Unknown achievement "+a);else for(d=e=0;0<=f?e<=f:e>=f;d=0<=f?++e:--e)this.setCounter(a,c.counters[d]+b,d,!1)};Xa.prototype.setCounter=function(a,b,c,d){c=void 0===c?null:c;d=void 0===d?!0:d;var e,f,g,h;var k=this.achievements[a];if(null==k)r.error("Unknown achievement "+a);else if(this.canUnlockAchievements()){null==
c&&(c=null!=(e=this.main.difficultyLvl)?e:1);e=h=!1;for(d=g=f=d?0:c;f<=c?g<=c:g>=c;d=f<=c?++g:--g){var l=k.counters[d];l>=k.counterTarget||l>=b||(h=!0,l=k.updateInterval+l-l%k.updateInterval,k.counters[d]=b,r.info("ACHIEVEMENT;"+a+":d"+d+" (new value: "+b+")"),k.counters[d]>=l&&(e=!0))}h&&!e&&this.main.r.timeTotal-this.lastShowTime>config.achievementTimer&&(e=!0);e&&this.showAchievement(a);this.updateTracker(a)}};Xa.prototype.unlockIOAchievement=function(a){var b;if(n.canUseLocalStorage())if(null==
this.achievements[a])console.error("No such IO achievement "+a);else{var c=JSON.parse(null!=(b=localStorage.getItem("io-achieves"))?b:"[]");if(!c.includes(a)&&(c.push(a),localStorage.setItem("io-achieves",JSON.stringify(c)),this.achievements[a].counters=[1,1,1],this.achievements[a].unlocked=[!0,!0,!0],this.showAchievement(a),window.isSteam))return this.unlockSteamAchievementIfNecessary(a)}else console.error("unable to unlock "+a+" as can't use local storage")};Xa.prototype.showAchievement=function(a){null==
this.achievements[a]?r.error("Unknown achievement "+a):(this.main.achievementBox.queueAchievement(this.achievements[a],7),this.lastShowTime=this.main.r.timeTotal)};var M=function(a,b,c,d,e,f){this.playTileSound=this.playTileSound.bind(this);this.resetVisibility=this.resetVisibility.bind(this);this.revealTileRadius=this.revealTileRadius.bind(this);this.revealBiome=this.revealBiome.bind(this);this.sendLegCache=this.sendLegCache.bind(this);this.cancelTravel=this.cancelTravel.bind(this);this.getEnvBiomesToTick=
this.getEnvBiomesToTick.bind(this);this.incTurn=this.incTurn.bind(this);this.checkRacetrackEvent=this.checkRacetrackEvent.bind(this);this.wait=this.wait.bind(this);this.rest=this.rest.bind(this);this.updateStats=this.updateStats.bind(this);this.tickDayAge=this.tickDayAge.bind(this);this.doDayAgeEvents=this.doDayAgeEvents.bind(this);this.doTripEvents=this.doTripEvents.bind(this);this.resetSanityTurns=this.resetSanityTurns.bind(this);this.checkSanityEvent=this.checkSanityEvent.bind(this);this.doZoneEvent=
this.doZoneEvent.bind(this);this.tickWait=this.tickWait.bind(this);this.stopWait=this.stopWait.bind(this);this.resetPath=this.resetPath.bind(this);this.tickPath=this.tickPath.bind(this);this.changeCompassScore=this.changeCompassScore.bind(this);this.setCompass=this.setCompass.bind(this);this.tickTracks=this.tickTracks.bind(this);this.setTravelPath=this.setTravelPath.bind(this);this.doPartyTravel=this.doPartyTravel.bind(this);this.highlightMapScore=this.highlightMapScore.bind(this);this.tickAutoTravel=
this.tickAutoTravel.bind(this);this.endTravel=this.endTravel.bind(this);this.checkAutoSave=this.checkAutoSave.bind(this);this.endSledgeTravel=this.endSledgeTravel.bind(this);this.checkNextTileTravel=this.checkNextTileTravel.bind(this);this.getLastWayPoint=this.getLastWayPoint.bind(this);this.sledgeTravel=this.sledgeTravel.bind(this);this.addMouseWayPoint=this.addMouseWayPoint.bind(this);this.addWayPoint=this.addWayPoint.bind(this);this.validWayPoint=this.validWayPoint.bind(this);this.removeWayPoint=
this.removeWayPoint.bind(this);this.updateWayPoint=this.updateWayPoint.bind(this);this.clearWayPoints=this.clearWayPoints.bind(this);this.drawTileInfo=this.drawTileInfo.bind(this);this.updateBiomes=this.updateBiomes.bind(this);this.clearDirtyFlags=this.clearDirtyFlags.bind(this);this.displayNewSegment=this.displayNewSegment.bind(this);this.drawNewSegmentBanner=this.drawNewSegmentBanner.bind(this);this.drawMap=this.drawMap.bind(this);this.checkGenerateMiniMap=this.checkGenerateMiniMap.bind(this);this.drawMiniMap=
this.drawMiniMap.bind(this);this.isPartyHidden=this.isPartyHidden.bind(this);this.drawShip=this.drawShip.bind(this);this.drawPunch=this.drawPunch.bind(this);this.drawPaths=this.drawPaths.bind(this);this.drawPathCost=this.drawPathCost.bind(this);this.drawCompass=this.drawCompass.bind(this);this.drawZones=this.drawZones.bind(this);this.debugEntity=this.debugEntity.bind(this);this.onMouseMove=this.onMouseMove.bind(this);this.onScroll=this.onScroll.bind(this);this.onMousePan=this.onMousePan.bind(this);
this.onMouseWheel=this.onMouseWheel.bind(this);this.zoomIn=this.zoomIn.bind(this);this.zoomOut=this.zoomOut.bind(this);this.onMouseDown=this.onMouseDown.bind(this);this.onMouseUp=this.onMouseUp.bind(this);this.main=a;this.world=b;this.party=c;this.events=d;this.r=e;this.s=e.s;this.sfx=f;this.viewCostTime=this.compassTime=this.compassScore=this.turn=0;this.travelPath=new Ka;this.soundTime=0;this.previewPath=[];this.wayPoints=[];this.wayPointPath=[];this.wayPointCost=[];this.previewTracks=[];this.shipPath=
[];this.shipArrived=!0;this.waiting=null;this.sanityTurn=this.resetSanityTurns();this.lostStashTime=1E3;this.raceTrack=[];this.moveSoundPlayed=!1;debug.showDebugBar&&this.createDebugBar();this.clearWayPoints();n.isIO()&&null==this.main.tutorial&&(this.ioPartyGhosts=new Od(this.main));this.ioLegCache=[]};M.prototype.onStartWorld=function(){this.viewQueue=[];null!=this.world.startPos&&(this.placeParty(this.world.startPos),this.changeCompassScore(0),n.isIO()&&this.r.cam.centerOnPos(this.world.startPos));
if(!this.main.isWarping()&&null==this.main.tutorial)return this.initShip()};M.prototype.resetRivals=function(){var a;var b=this.main.rivals;var c=0;for(a=b.length;c<a;c++){var d=b[c];d.turn=0;d.arrivedTurn=null;d.blockedTurns=0}};M.prototype.setBiomeEntered=function(a,b){b=void 0===b?!0:b;a=this.world.getBiome(a);a.entered=!0;if(null==this.main.tutorial&&(b&&(b=a.blocking?"txt-tile-impassableregion":"txt-tile-newregion",b=q.toText(b),this.r.addGameFade(b,this.party.pos,0)),this.party.hasBiomeInfo())){var c=
a.locations;var d=0;for(a=c.length;d<a;d++)b=c[d],b.hintBiome&&this.revealTileRadius(b.pos,1)}};M.prototype.playTileSound=function(a){if(!this.moveSoundPlayed)return a=this.sfx.getSound(a.moveSounds.sample()),null!=a&&this.sfx.play(a),this.moveSoundPlayed=!0};M.prototype.tickMapSounds=function(a){var b;this.soundTime+=a;if(1<this.soundTime){this.soundTime=0;var c=this.r.cam.updateScreenCenterPos();a=this.world.getTilesInRadius(c,10);var d=config.mapSounds;var e=0;for(b=d.length;e<b;e++){var f=d[e];
this.checkNearSound(a,c,this.r.sfx.mapSounds[f.soundName],f.options)}}};M.prototype.clearMapSounds=function(){var a;var b=config.mapSounds;var c=0;for(a=b.length;c<a;c++){var d=b[c];this.r.sfx.mapSounds[d.soundName].fadeOut(50)}};M.prototype.checkNearSound=function(a,b,c,d){d=void 0===d?[]:d;n.assert(null!=c);this.main.showingDiary()?a=0:(a=a.min(function(a){var c,e;if(!a.biome.generated)return 100;var h=0;for(c=d.length;h<c;h++){var k=d[h];if(null==k.tile||a.id===k.tile)if(null==k.location||null!=
a.location&&a.location.id===k.location)if(null==k.sprawl||null!=(e=a.sprawls[k.sprawl])&&e.active)return a.pos.dist(b)}return 100}),a=null!=a?a.pos.dist(b):100,a=.5*Math.max(100-10*a,0));!c.isPlaying()&&0<a&&(this.r.sfx.play(c,!0),c.setVolume(0));if(c.isPlaying())return c.fadeTo(a,1E3)};M.prototype.showReveals=function(a){var b=this,c,d;var e=function(a){var c,d;var e=0;for(c=a.length;e<c;e++){var f=a[e];b.revealTileRadius(f.pos,f.radius,{visible:f.visible,centerCam:f.centerCam,location:f.location});
if(null!=f.particle){var g=b.world.getTilesInRadius(f.pos,f.radius);var h=0;for(d=g.length;h<d;h++){var n=g[h];var q=t.getParticle(f.particle);var r=b.r.part.getParticlePositionForTilePos(q,n.pos);n=4*n.pos.dist(f.pos);b.r.part.addParticleConf(q,r,{step:n})}}}};if(0!==a.length)if(a.any(function(a){return a.centerCam})){var f=d=0;for(c=a.length;d<c;f=++d){var g=a[f];e.delay(650*f,[g])}}else e(a)};M.prototype.resetVisibility=function(){var a;var b=this.world.getBiomes();var c=0;for(a=b.length;c<a;c++){var d=
b[c];var e=d.tiles;var f=0;for(d=e.length;f<d;f++){var g=e[f];g.visible=g.farVisible=g.known=g.farKnown=!1;null!=g.location&&(g.location.visible=g.location.known=!1)}}return this.updateVisibility()};M.prototype.revealTileRadius=function(a,b,c){var d={location:!1,centerCam:!1,noPoints:!1};Object.merge(d,c);b=this.world.getTilesInRadius(a,b,!0,!0);var e=0;for(c=b.length;e<c;e++){var f=b[e];f.biome.generated||this.main.worldGenIO.generateBiome(f.biome.pos);this.setTileVisible(f,!0,d.noPoints,d.location)}if(d.visible||
d.location)this.world.getTile(a).hasVisibleNeighbor=!0;if(d.centerCam)return this.r.cam.moveToPos(a)};M.prototype.revealBiome=function(a,b){b=void 0===b?!1:b;a.generated||this.main.worldGenIO.generateBiome(a.pos);var c=a.tiles;var d=0;for(a=c.length;d<a;d++){var e=c[d];this.setTileVisible(e,b)}};M.prototype.setTileVisible=function(a,b,c,d){c=void 0===c?!1:c;d=void 0===d?!1:d;a.visible=b;a.visible&&!a.known&&(a.known=!0,this.main.world.setTileCtxDirtyWithNeighbours(a),this.main.world.setZoneCtxDirtyWithNeighbours(a),
this.resetPath());if(a.known&&(this.updateLocationVisibility(a,c||this.main.gameOver,d)&&this.checkMapScores(),n.isIO()&&!this.main.isWarping()))return a.biome.getIOMPData(this.main)};M.prototype.updateVisibility=function(){if(null!=this.world&&null!=this.party.pos){var a=this.world.getTile(this.party.pos);this.party.maxViewCost=config.baseViewDist*(1+this.party.viewDistBonus);1<a.elevation&&(this.party.maxViewCost+=config.extendedViewDist);null==this.viewTurn&&(this.viewTurn=0);this.viewTurn+=1;
return this.viewQueue=[this.world.getTile(this.party.pos)]}};M.prototype.placeParty=function(a){n.assert(null!=a,"Party can't have null position");var b=this.world.getTile(a);this.setBiomeEntered(b.biome.pos,!1);this.party.pos=b.pos;this.main.isWarping()||(this.party.moves.push(b.pos),this.party.addStatsLeg(this.turn));this.changeCompassScore();this.shipArrived&&(this.r.cam.centerOnPos(a),this.updateVisibility());this.resetPath();this.checkTileEvent();this.main.updateForNewPartyPos();this.party.onBonusChanged();
n.isIO()&&(this.sendLegCache(),this.main.isWarping()||this.ioLegCache.push(a))};M.prototype.sendLegCache=function(){if(0!==this.ioLegCache.length)return 1<this.ioLegCache.length&&this.main.iomp.addLeg(this.ioLegCache),this.ioLegCache=[]};M.prototype.cancelTravel=function(){this.travelPath.cancel();return this.main.updateActions()};M.prototype.checkExpeditionOver=function(){return null==this.party.getExplorer()};M.prototype.doTurn=function(a){null==this.sledgeTarget&&this.party.changeSanity(-a,!1);
a=this.incTurn();if(!a){var b=config.compass.turnDiff+1*this.party.getBonus("compass");this.changeCompassScore(b);b=this.world.getTile(this.party.pos);b.biome.entered||this.setBiomeEntered(b.biome.pos)}this.updateVisibility();return a};M.prototype.getEnvBiomesToTick=function(){if(!n.isIO()||this.main.isWarping()||null==this.party)return Object.values(this.world.biomes);var a=this.world.toBiomePos(this.party.pos);return Object.values(this.world.biomes).filter(function(b){return b.generated?a.sub(b.pos).length()<=
config.io.biomeDistForWorldTick:!1})};M.prototype.incTurn=function(){this.turn+=1;this.party.incPartyTurn();var a=this.getEnvBiomesToTick();this.world.incLocationsTurn(a);this.world.incZonesTurn(a,this.party.pos);this.checkMapScores();this.incRivalTurn();if(!this.canHaveEvent())return this.tickDayAge(),!1;this.world.incSprawlTurn(a);return this.checkTileEvent()||this.checkSprawlEvent()||this.doDayAgeEvents()||this.checkZoneEvent()||this.checkSanityEvent()||this.checkRacetrackEvent()?!0:!1};M.prototype.checkRacetrackEvent=
function(){var a,b;var c=this.raceTrack;var d=b=0;for(a=c.length;b<a;d=++b){var e=c[d];if(e.onDay<=this.turn)return this.raceTrack.splice(d,1),d=t.getEvent(e.ref),null!=d&&this.main.doEvent(d),!0}return!1};M.prototype.canHaveEvent=function(){return this.main.showingDiary()||null!=this.sledgeTarget||this.waiting&&(0<this.waiting.sanityGain||0===this.waiting.turnsDone||!this.waiting.resting)?!1:!0};M.prototype.incRivalTurn=function(){var a,b;if(!this.main.isWarping()){var c=this.main.rivals;var d=b=
0;for(a=c.length;b<a;d=++b){var e=c[d];0<e.blockedTurns?--e.blockedTurns:this.turn>=20*d&&(e.turn+=1,e.turn>=this.world.rivalTurns&&(e.arrivedTurn=this.turn))}}};M.prototype.checkMapScores=function(){};M.prototype.wait=function(a,b,c,d,e){c=void 0===c?[]:c;this.waiting={time:0,sanityGain:void 0===b?0:b,turnsLeft:a,turnsDone:0,resting:void 0===d?!1:d,events:c,waitLabel:void 0===e?"txt-base-waiting":e};return this.main.updateActions()};M.prototype.rest=function(a,b){return this.wait(config.maxRestTime,
a,b,!0,"txt-base-resting")};M.prototype.updateStats=function(){var a=this,b;var c=this.party.stats;var d=this.party.getExplorer();null!=d&&(c.perks=Object.keys(d.statuses).filter(function(a){return t.getStatus(a).isPerk}));c.fame=this.party.fame;c.funds=this.party.funds;c.karma=this.party.karma;c.visitedLocations=this.party.visitedLocations;c.playTime=Math.floor(this.party.playTime/60);c.legs=this.party.legs.length;c.avgDist=0<this.party.legs.length?this.party.moves.length/this.party.legs.length:
0;c.gameOver=this.main.gameOver;c.worldLvl=this.main.worldLvl;c.turns=this.turn;c.butterflies=this.party.butterflies;c.fameScale=Math.max(1,1+this.party.getBonus("fameScale"));d=0<this.world.goalFame?this.main.rivals.count(function(b){return b.turn>=a.main.world.rivalTurns}):this.main.rivals.length;c.raceRank=d;c.timeBonus=config.rivals.rewards[d];c.goalFame=this.world.goalFame;c.points=this.main.getPoints();d=!(b=this.world.pocketId,0<=F.call(this.party.visitedPockets,b));c.newPocketFame=d?config.newPocketFameBonus:
0;d=this.world.getBiomes().filter(function(a){return!a.isOutside});b=d.sum(function(a){return a.tiles.count(function(a){return a.known})});d=d.sum(function(a){return a.tiles.length});c.discoveredPerc=b/d};M.prototype.tickDayAge=function(){var a,b;var c=this.party.store;var d=0;for(b=c.length;d<b;d++){var e=c[d];e.storeAge+=1}c=this.party.persons;d=0;for(b=c.length;d<b;d++)for(a in e=c[d],e=e.statuses,e){var f=e[a];f.dayAge+=1;0<f.buffDelayDays?--f.buffDelayDays:1<f.buffDays&&--f.buffDays}};M.prototype.doDayAgeEvents=
function(){var a,b;var c=this.party.store;var d=0;for(b=c.length;d<b;d++){var e=c[d];e.storeAge+=1}if(this.main.showingDiary()||null!=this.waiting&&0<this.waiting.sanityGain)return!1;var f=this.party.persons;var g=0;for(d=f.length;g<d;g++){e=f[g];var h=e.statuses;for(a in h)if(b=h[a],c={age:b.dayAge,status:b,person:e},this.main.doRandEvent(b.dayEvents,c),this.main.showingDiary())return!0}e=this.party.inv.getItemCount();for(a in e)if(e=t.getItem(a),null!=e.dayEvents&&(c={item:this.party.inv.getItemById(a)},
this.main.doRandEvent(e.dayEvents,c),this.main.showingDiary()))return!0;f=this.party.persons;c=0;for(d=f.length;c<d;c++)for(a in e=f[c],h=e.statuses,h)if(b=h[a],b.dayAge+=1,0<b.buffDelayDays)--b.buffDelayDays;else if(0<b.buffDays&&(--b.buffDays,0>=b.buffDays&&(e.setStatus(b.id,!1),null!=b.buffEndEvents&&(this.main.doRandEvent(b.buffEndEvents,{person:e,status:b}),this.main.showingDiary()))))return!0;return!1};M.prototype.doTripEvents=function(){var a,b;if(!this.main.showingDiary()){var c=this.party.persons;
var d=0;for(b=c.length;d<b;d++){var e=c[d];if(Math.random()<e.deathChance){if(this.main.doRandEvent(config.specialEvents.death,{person:e}),this.main.showingDiary())return!0}else if(e.health<e.maxHealth&&Math.random()<e.infectionChance&&!e.hasInfection()&&(this.main.doRandEvent(config.specialEvents.infected,{person:e}),this.main.showingDiary()))return!0}d=this.party.persons;var f=0;for(c=d.length;f<c;f++){e=d[f];var g=e.statuses;for(a in g)b=g[a],0<b.buffDelayTrips?--b.buffDelayTrips:0<b.buffTrips&&
(--b.buffTrips,0>=b.buffTrips&&e.setStatus(b.id,!1))}f=this.party.persons;d=0;for(g=f.length;d<g;d++){e=f[d];var h=e.statuses;for(a in h)if(b=h[a],b.tripAge+=1,c={age:b.tripAge,person:e,status:b},this.main.doRandEvent(b.tripEvents,c),this.main.showingDiary())return!0}b=this.party.inv.items;for(a in b)if(e=b[a],null!=(null!=e?e.tripEvents:void 0)&&(e.tripAge+=1,c={item:e,age:e.tripAge,tripAge:e.tripAge,dayAge:e.dayAge},this.main.doRandEvent(e.tripEvents,c),this.main.showingDiary()))return!0}};M.prototype.resetSanityTurns=
function(){this.sanityTurn=0;0===this.party.sanity&&(this.sanityTurn-=config.sanity.bonusInterval);return this.sanityTurnMax=J.randInt(config.sanity.maxExtraMoves)};M.prototype.checkSanityEvent=function(){if(this.main.showingDiary()||null!=this.main.tutorial||this.waiting)return!1;if(0<this.party.sanity)return this.resetSanityTurns(),!1;if(this.sanityTurn>=this.sanityTurnMax)return this.resetSanityTurns(),this.main.showRandEventAlert("Your trek needs attention!",config.specialEvents.noSanity),!0;
this.sanityTurn+=1;return!1};M.prototype.checkDayStartEvents=function(){var a=this;var b=function(){return a.events.showingEventDialogue};if(!b())for(;!this.checkDayStartFns.isEmpty();){var c=this.checkDayStartFns.shift();c();if(b())break}};M.prototype.checkTileEvent=function(){var a=this.world.getTile(this.party.pos);return 0<a.events.length&&Math.random()<=a.eventChance?(this.main.doRandEvent(a.events),this.events.showingEventDialogue):!1};M.prototype.checkZoneEvent=function(){var a=this;if(this.r.trailerMode||
this.events.showingEventDialogue)return!1;var b=this.world.getTile(this.party.pos);var c=Object.clone(b.zones);var d=0;for(b=c.length;d<b;d++){var e=c[d];if(!(0<e.inactiveTurns||this.waiting||null!=this.sledgeTarget)){!e.seeking&&Math.random()<this.party.getZoneAggroChance(e)&&e.startSeeking();var f=Math.random()<=e.eventChance;f||(f=e.seeking&&e.seekTurns>=config.zone.aggroDelay,f=1>=e.center.dist(this.party.pos)&&f);if(f){if(e.stopTravel)return e.moveQueue=[],this.main.showEventAlert("Crossing dangerous territory!",
function(){return a.doZoneEvent(e)}),this.main.r.cam.addCamShake(config.zone.camShake.power,config.zone.camShake.length),this.main.playSound("zoneAttacked"),this.punchHandler=null,!0;this.doZoneEvent(e)}}}return!1};M.prototype.checkSprawlEvent=function(){var a;var b=this.world.getTile(this.party.pos).sprawls;for(a in b){var c=b[a];if(c.active&&(c=t.getSprawl(a),null!=c.partyEvents&&this.main.doRandEvent(c.partyEvents),this.events.showingEventDialogue))return!0}return!1};M.prototype.doZoneEvent=function(a,
b){b=void 0===b?!0:b;return null!=a.events?(this.main.mainMenu.saveGame.autoBegin={zone:this.main.world.zones.findIndex(a),enemyAttacks:b},this.main.mainMenu.saveGame.updateSaveGame(),this.main.mainMenu.saveGame.autoBegin=null,this.main.doRandEvent(a.events,{zone:a,enemyAttacks:b})):r.warn("doZoneEvent;no zone events for zone "+a.id,t.getZone(a.id).mod)};M.prototype.showPunchDialogue=function(a,b,c,d,e,f,g,h){this.showingPunch=!0;this.punchText=a;this.punchRadius=b;this.punchRange=c;this.punchPathable=
d;this.punchKnown=e;this.punchCancelable=f;this.punchHandler=g;this.punchDraw=null!=h?h:this.r.drawHexFieldRadius;return this.main.hideEventDialogue()};M.prototype.validPunch=function(a){if(this.punchKnown){var b=null!=a?this.world.getTile(a):null;if(null==b||!b.known)return!1}return null!=a&&(null==this.punchRange||this.party.pos.dist(a)<=this.punchRange)};M.prototype.doPunch=function(a,b){(void 0===b?0:b)?this.punchHandler=null:this.punchPathable&&0<a.dist(this.party.pos)?this.doPartyTravel():null!=
this.punchHandler?(b=this.punchHandler,this.punchHandler=null,b(a)):r.warn("Unknown punch event ignored.");this.showingPunch=!1;return this.main.onActionsChanged()};M.prototype.tickWait=function(a){if(this.waiting&&(this.waiting.time+=a,this.waiting.time>config.waitTime)){this.waiting.time=0;this.waiting.turnsDone+=1;var b="";this.waiting.waitLabel&&(a=this.waiting.waitLabel,b+=q.toText(a));b+=" "+this.waiting.turnsDone+" "+q.toText("txt-outro-days");this.r.addGameFade(b,this.party.pos);if(this.incTurn())this.stopWait(!0);
else{0<this.waiting.sanityGain&&this.party.changeSanity(this.waiting.sanityGain);if(0<this.waiting.turnsLeft&&(--this.waiting.turnsLeft,0===this.waiting.turnsLeft)){this.stopWait();return}this.updateVisibility();return this.main.updateActions()}}};M.prototype.stopWait=function(a){var b=this.waiting.events;this.waiting=null;(void 0===a?0:a)||null==b||this.main.showRandEventAlert("",b);return this.main.updateActions()};M.prototype.resetPath=function(){return this.pathFinders=[]};M.prototype.tickPath=
function(a){var b,c;if(!this.waiting&&!this.main.showingOutro&&!this.isTraveling()){var d=[this.party.pos];d.add(this.wayPoints);if(null!=this.sledgeTarget)d.push(this.sledgeTarget);else if(!this.hoverActionButton){var e=this.mouseTilePos;null!=e&&this.previewPath.slice(0,-1).none(function(a){return a.eq(e)})&&(0!==this.wayPoints.length&&this.party.isSuperMove||d.push(e))}var f={};this.previewPath=[];this.previewCost=[];this.previewItems=[];this.previewPathCost=this.previewPathMaxDist=0;var g=d.slice(0,
-1);var h=c=0;for(b=g.length;c<b;h=++c){var k=g[h];var l=d[h+1];var m=this.pathFinders[h];null!=m&&m.pos1.eq(k)||(m=!(this.r.trailerMode||debug.freePath||null!=this.sledgeTarget),m=this.pathFinders[h]=new Ma(this.world,this.party,k,f,{ignoreUnknown:m}));l.eq(m.pos2)||m.find(l).wait();if(m.done&&null!=m.path){this.previewPath.add(m.path);this.previewCost.add(m.pathCost);this.previewItems.add(m.pathItems);l=m.pathItems;var p=0;for(k=l.length;p<k;p++)h=l[p],null==f[h]&&(f[h]=0),f[h]+=1}else{m.tick(a);
break}}this.previewPathCost=this.party.tripCost;c=this.previewCost;b=0;for(g=c.length;b<g;b++)a=c[b],this.previewPathCost+=a,this.previewPathCost<this.party.sanity&&(this.previewPathMaxDist+=1),this.previewPathCost=Math.floor(this.previewPathCost);null!=this.sledgeTarget&&null!=m.path&&(this.isTraveling()||(this.addWayPoint(this.sledgeTarget),this.doPartyTravel()),0===m.path.length&&this.endSledgeTravel())}};M.prototype.changeCompassScore=function(a){var b=this;a=void 0===a?0:a;var c=this.compassScore;
0<this.world.maxCompassScore&&(this.compassScore=(this.compassScore+a).clamp(0,this.world.maxCompassScore));a=this.compassScore-c;if(null!=this.party.pos){c=$jscomp.makeIterator(config.compass.hintAngleError);var d=c.next().value;c=c.next().value;d=(c-d)/this.world.maxCompassScore;c=Math.min(Math.PI,c-this.compassScore*d);d=this.world.getCompassLocations().min(function(a){var c=b.party.pos.dist(a.pos);return"loc-magneticMountain"===a.id&&c>config.magneticMountain.radius?100*c:c});if(null!=d&&"loc-magneticMountain"===
d.id){var e=this.party.pos.dist(d.pos);e>config.magneticMountain.radius&&(d=null)}e=null!=d?d.pos:n.isIO()&&!this.main.isWarping()&&null==this.main.tutorial?this.main.worldGenIO.getNextHubPos():null;null!=d&&"loc-magneticMountain"===d.id&&(c=config.magneticMountain.error);null!=e&&this.setCompass(this.party.pos,e,c)}return a};M.prototype.setCompass=function(a,b,c){c=void 0===c?Math.PI/4:c;this.compassDist=a.sub(b).length();var d=this.r.getTileScreenPos(a,!1,!1);b=this.r.getTileScreenPos(b,!1,!1).diff(d);
b=b.mul(1/b.length());b=Math.atan2(b.x,b.y);b+=2*Math.random()*c-c;n.isIO()||(this.compassTime=0);return this.compass={pos:a,angle:b,maxError:c}};M.prototype.tickExped=function(a){if(this.tickShip(a)&&(this.compassTime+=a,this.lostStashTime+=a,this.world.tick(a),this.travelPath.tick(a),this.tickAutoTravel(a),this.tickTileViewCosts(a),this.tickWait(a),this.tickPath(a),this.tickMapSounds(a),null!=this.ioPartyGhosts))return this.ioPartyGhosts.tick(a)};M.prototype.track=function(a,b){this.previewTracks=
[];if(null!=b)return this.trackFinder=new Ma(this.world,this.party,a,{},{ignoreUnknown:!1}),this.trackPosis=b};M.prototype.tickTracks=function(a){var b=this;if(null!=this.trackFinder){if(this.trackFinder.done){null!=this.trackFinder.path&&(a=this.trackFinder.path.map(function(a){return b.world.getTile(a)}).filter(function(a){return a.known}),this.previewTracks.push({path:a,location:this.world.getTile(this.trackFinder.pos2).location}));if(this.trackPosis.isEmpty())return this.trackFinder=null;a=this.trackPosis.shift();
return this.trackFinder.find(a)}return this.trackFinder.tick(a)}};M.prototype.setTravelPath=function(a,b){a.unshift(this.party.pos);return this.travelPath=new Ka(a,b)};M.prototype.doPartyTravel=function(){var a;if(null==(a=this.previewPath)||!a.isEmpty()){a=this.previewPath;var b=this.wayPoints.last();var c=null!=b?a.findIndex(function(a){return b.eq(a)}):-1;a=this.previewPath.slice(0,+c+1||9E9);c=this.previewCost.slice(0,+c+1||9E9);this.previewPath=[];this.clearWayPoints();if(!this.events.showingEventDialogue)if(this.party.isOverfilled())this.main.chat.showText(config.help.overfilled);
else if(!a.isEmpty())return this.setTravelPath(a,c),this.checkNextTileTravel(),this.party.changeSanity(-this.party.tripCost,!1),this.sfx.play("moveConfirm"),this.main.updateActions(),this.main.infoBox.hide()}};M.prototype.highlightMapScore=function(a,b,c){if(!(0>=c.maxMapScore)){var d=$jscomp.makeIterator(this.r.getCanvasSize());var e=d.next().value;d.next();d=c.mapScore+b>=c.maxMapScore?config.particle.travelScoreFull:config.particle.travelScore;((c.mapScore+.75*b)/c.maxMapScore).clamp(0,1);b={interpTarget:new u(e-
590,20)};return this.r.part.addParticleConf(d,a,b)}};M.prototype.addTravelParticle=function(){var a=$jscomp.makeIterator(this.travelPath.getAnimPos());a.next();var b=a.next().value;var c=a.next().value;a=a.next().value;var d=this.world.getTile(.5>a?b:c);d=t.getParticle(d.travelParticle);var e=t.getParticle(config.superMoveParticle);b=this.r.part.getParticlePositionForTilePos(null!=d?d:e,b);c=this.r.part.getParticlePositionForTilePos(null!=d?d:e,c);a=new u(b.x+a*(c.x-b.x),b.y+a*(c.y-b.y));this.r.part.addParticleConf(d,
a);if(this.party.isSuperMove)return this.r.part.addParticleConf(e,a)};M.prototype.tickAutoTravel=function(a){if(!this.travelPath.isDone()){a=this.travelPath.getAlpha();var b=this.travelPath.getPos();b=this.world.getTile(b);Math.floor(this.travelPath.moveTime/.15)>this.tileParticlesDrawn&&(this.addTravelParticle(),this.tileParticlesDrawn+=1);this.playTileSound(b);if(!(1>a)){this.tileParticlesDrawn=0;var c=this.travelPath.incMove();var d=this.world.getTile(c);a=this.party.pos.getDir(c);d=$jscomp.makeIterator(null!=
this.sledgeTarget?[0,null]:this.party.getMoveCost(b,d));b=d.next().value;d=d.next().value;this.moveSoundPlayed=!1;if(config.board.autoScroll){var e=this.r.getTileScreenPos(this.party.pos,!0,!0,!0);c=this.r.getTileScreenPos(c,!0,!0,!0);c=c.diff(e);this.r.cam.addAutoScroll(new qa(c.x,c.y))}c=this.world.getTile(this.party.pos);this.party.move(a);null==this.sledgeTarget&&null!=c.crumble&&null==c.location&&this.world.replaceTile(c,c.crumble);this.main.events.clearActions();null!=d&&(this.party.inv.changeItemCount(d,
-1),a=t.getItem(d),null!=a.travelEvent&&this.main.doEvent(a.travelEvent,{silent:!0}));this.doTurn(b)?this.endTravel():this.checkNextTileTravel();if(this.travelPath.isDone())return this.main.onActionsChanged()}}};M.prototype.endTravel=function(){if(!this.main.showingOutro&&(this.cancelTravel(),this.doTripEvents(),this.party.updateDowsing(),this.party.sanity=Math.ceil(this.party.sanity),this.party.addStatsLeg(this.turn),this.party.isSuperMove=!1,null!=this.sledgeTarget&&this.endSledgeTravel(),null!=
this.punchHandler&&(this.punchHandler(this.party.pos),this.punchHandler=null),this.checkAutoSave(),n.isIO()&&!this.main.isWarping()&&null==this.main.tutorial&&(this.ioLegCache.push(this.party.pos),this.ioLegCache.length>config.io.iompGhostLegMaxLength)))return this.sendLegCache()};M.prototype.checkAutoSave=function(){var a;if((!n.isIO()||null==this.main.iomp.saveTimer)&&this.canHaveEvent()&&this.main.canSave()){var b=this.main.mainMenu.saveGame;var c=null!=(a=b.saveTime)?a:0;c=(new Date-c)/1E3;if(c>
config.autosaveDelay)return b.updateSaveGame()}};M.prototype.endSledgeTravel=function(){this.sledgeTarget=null;this.sfx.fadeOut("sledgeLoop",50);return this.party.getExplorer().setStatus(config.specialStatuses.sledding,!1)};M.prototype.isTraveling=function(){return null!=this.travelPath&&!this.travelPath.isDone()};M.prototype.checkNextTileTravel=function(){if(this.travelPath.isDone())this.endTravel();else{var a=this.travelPath.getNextPos();this.world.getTile(a).isBlocking()&&this.endTravel()}};M.prototype.getLastWayPoint=
function(){return this.wayPoints.last()};M.prototype.sledgeTravel=function(a){n.assert(null!=a);this.clearWayPoints();this.sledgeTarget=a;this.party.getExplorer().setStatus(config.specialStatuses.sledding,!0);return this.sfx.fadeIn("sledgeLoop",150,!0)};M.prototype.addMouseWayPoint=function(){return this.addWayPoint(this.mouseTilePos)};M.prototype.addWayPoint=function(a){var b;if(null!=a&&!(this.party.isSuperMove&&0<this.wayPoints.length)&&this.validWayPoint(a)&&!this.isTraveling()){var c=0;var d=
this.previewPath;var e=0;for(b=d.length;e<b;e++){var f=d[e];var g=this.wayPoints[c];if(f.eq(g))c+=1;else if(f.eq(a)){this.wayPoints.splice(c,0,f);break}}return this.main.updateActions()}};M.prototype.validWayPoint=function(a){var b=this.world.getTile(a);return b.isBlocking()||!b.known&&!this.r.trailerMode&&!debug.freePath||this.wayPoints.any(function(b){return b.eq(a)})?!1:this.previewPath.any(function(b){return b.eq(a)})};M.prototype.removeWayPoint=function(){this.wayPoints.pop();return this.main.updateActions()};
M.prototype.updateWayPoint=function(a,b){if(!(a>=this.wayPoints.length||this.wayPoints[a].eq(b))&&this.validWayPoint(b))return this.wayPoints[a]=b};M.prototype.clearWayPoints=function(){this.wayPoints=[];this.resetPath();return this.main.updateActions()};M.prototype.tickTileViewCosts=function(a){var b=this,c,d,e;this.viewCostTime+=a;if(!(.05>this.viewCostTime))if(this.viewCostTime=0,0===this.viewQueue.length)this.dirtyView&&(this.resetPath(),this.dirtyView=!1);else{this.dirtyView=!0;var f=[];var g=
this.viewQueue;var h=0;for(a=g.length;h<a;h++){var k=g[h];if(!k.biome.generated)k.pos.dist(this.party.pos)<=config.io.maxDistForVisibilityGeneration&&this.main.worldGenIO.generateBiome(k.biome.pos);else if(!(k.viewTurn>=this.viewTurn)){if(k.pos.eq(this.party.pos))k.totalViewCost=k.localTotalViewCost=0,k.viewTurn=this.viewTurn;else{var l=k.pos.getDirs(this.party.pos);var m=0;for(d=l.length;m<d;m++){var p=l[m];p=k.pos.move(p);p=this.world.getTile(p);if(null!=p){var n=p.totalViewCost+k.viewCost;p=k.sprawls;
for(c in p){var q=p[c];q.active&&(n+=null!=(e=t.getSprawl(c).viewCost)?e:0)}if(k.viewTurn<this.viewTurn||k.totalViewCost>n)k.totalViewCost=n,k.viewTurn=this.viewTurn}}k.localTotalViewCost=k.totalViewCost-(k.elevation-1)}l=k.localTotalViewCost<=this.party.maxViewCost||1>=k.pos.dist(this.party.pos);this.setTileVisible(k,l);l=this.world.getTilesInRadius(k.pos,1,!0,!0);f.add(l.filter(function(a){return a.viewTurn<b.viewTurn}))}}return this.viewQueue=20>=k.pos.dist(this.party.pos)?f:[]}};M.prototype.updateLocationVisibility=
function(a,b,c){var d=a.location;return null!=d&&!d.known&&(c=d.linked||null!=this.sledgeTarget?!1:(void 0===c?0:c)?!0:null!=this.party.pos?a.pos.dist(this.party.pos)<=this.party.revealDist:!1)?(this.setLocationVisible(a,b),!0):!1};M.prototype.setLocationVisible=function(a,b){var c,d;var e=a.location;if(null!=e&&!e.known){e.known=!0;a.markChanged();e.biome.ctxDirty=!0;a.ctxDirty=!0;var f=this.world.getTilesInRadius(a.pos,1);var g=0;for(d=f.length;g<d;g++){var h=f[g];h.biome.ctxDirty=!0}b|=this.main.showingOutro;
if(!b&&0<e.mapScore&&(b=e.mapScore,Math.random()<this.party.mapScoreBonus&&(b+=1),n.isIO()&&(this.main.isWarping()||null!=this.main.tutorial||(c=this.main.iomp.checkClaimBiome(a.biome)),c&&(this.main.r.addStatHighlightParticle(null,q.toText("txt-io-discovered")),b+=config.io.regionMapScore),0<config.io.famePerLocationDiscovery&&this.party.changeFame(config.io.famePerLocationDiscovery,!1)),this.party.changeMapScore(b),this.main.showXP)){f=$jscomp.makeIterator(this.r.getCanvasSize());c=f.next().value;
f.next();a=this.r.getTileScreenPos(a.pos,!0,!0,!0);f=1;for(h=b;1<=h?f<=h:f>=h;1<=h?++f:--f)d=t.getParticle(config.particle.travelScore),b={interpTarget:new u(c-16*this.s,20*this.s+this.r.oY)},this.r.part.addParticleConf(d,a,b);this.sfx.play("triangulation")}null!=e.revealEvents&&this.main.doRandEvent(e.revealEvents,{location:e});c=e.links;e=0;for(a=c.length;e<a;e++)b=c[e],this.setLocationVisible(b)}};M.prototype.createMapShot=function(){var a=this;var b=document.getElementById("shareBoard");var c=
b.getContext("2d");var d=new z(c,this.sfx);d.img=this.r.img;var e=$jscomp.makeIterator(d.getMapSize(this.world.getBiomeCount().lst()));var f=e.next().value;e=e.next().value;b.width=f;b.height=e;d.scroll.y=-15;d.drawBiomeBackground(this.world.getBiomes());d.drawTiles(this.world,!0);var g=this.party.moves.map(function(b){return a.world.getTile(b)});d.drawPartyPath(null,g);d.drawLegs(this.party.stats.legs.map(function(b){return[a.world.getTile(b[0]),b[1]]}));d.drawParticles(!1);d.clouds=this.r.clouds;
d.drawMapCloud(0);c.globalAlpha=1;d.drawPortrait(this.party.getExplorer(),f/2-config.imgSize.unitFaceSmall[0]/2,e-100,{small:!0});if(null!=this.main.user){c.font="20px Aldrich";g=this.main.user.get("displayName");var h=g+"'s Travel Report - Expedition "+this.main.worldLvl+" - Fame "+this.party.fame+" - Days "+this.turn;g=c.measureText(h);d.drawText(h,f/2-g.width/2,e-30)}c.fillStyle=config.colors.tileBorder;c.fillRect(0,0,f,15);c.fillRect(0,e-15,f,15);c.fillRect(0,0,15,e);c.fillRect(f-15,0,15,e);c=
b.toDataURL("image/png");window.open(c);b.width=1;return b.height=1};M.prototype.drawTileInfo=function(){if(null!=this.showTileInfo){var a;var b=this.showTileInfo.zones;var c=[];var d=0;for(a=b.length;d<a;d++){var e=b[d];c.push(this.party.getZoneAggroChance(e))}return this.main.infoBox.showTile(this.showTileInfo,{aggroChances:c,centerPos:this.world.getCenter(),tripCost:this.party.tripCost,pathCost:this.previewPathCost-this.party.tripCost,sanityRisk:this.sanityRisk,days:this.previewPath.length})}};
M.prototype.tickShip=function(a){this.shipTime+=a*this.shipSpeed;this.shipParticleTime+=a*this.shipSpeed;if(!this.shipArrived&&(1<=this.shipTime||n.isIO())){var b=this.shipPath[this.shipIdx];this.shipIdx<this.shipPath.length-1&&(this.shipTime=0,this.shipIdx+=1);a=this.shipPath[this.shipIdx];this.revealTileRadius(a,3,{visible:!0,farVisible:!0,noPoints:!0});b=this.r.getTileScreenPos(b,!0,!0,!0);a=this.r.getTileScreenPos(a,!0,!0,!0);a=a.diff(b);this.r.cam.addAutoScroll(new qa(a.x,a.y));if(this.shipIdx>=
this.shipPath.length-1)this.onShipArrive()}return this.shipArrived};M.prototype.initShip=function(){var a;this.shipArrived=!1;this.shipParticleTime=this.shipTime=0;this.shipSpeed=.75;if(n.isIO())this.shipPath=[this.world.startPos];else{this.world.getCenter();var b=this.world.startPos;var c=[new u(0,0),new u(this.world.overallSize.w/2,0),new u(this.world.overallSize.w-1,0),new u(0,this.world.overallSize.h-1),new u(0,this.world.overallSize.h/2),new u(this.world.overallSize.w-1,this.world.overallSize.h/
2),new u(this.world.overallSize.w/2,this.world.overallSize.h-1),new u(this.world.overallSize.w-1,this.world.overallSize.h-1)].sortBy(function(a){return a.dist(b)});var d=0;for(a=c.length;d<a;d++){var e=c[d];var f=new Ma(this.world,null,b,{},{ignoreUnknown:!1,searchRiver:!0});e=f.find(e).wait();if(null!=e){this.shipPath=e.reverse();break}}this.shipPath.push(b)}this.shipIdx=n.isIO()||debug.skipStartEvents?this.shipPath.length-1:Math.max(this.shipPath.length-8,0);a=this.shipPath.slice(0,+this.shipIdx+
1||9E9);d=0;for(c=a.length;d<c;d++)b=a[d],this.revealTileRadius(b,3,{noPoints:!0,visible:!0,farVisible:!0});return this.r.cam.centerOnPos(b)};M.prototype.updateBiomes=function(a){var b;if(!this.main.waitingForDemoStart&&null!=this.lastOnScreenBiomes){var c=this.lastOnScreenBiomes;var d=0;for(b=c.length;d<b;d++){var e=c[d];e.generated&&this.r.updateBiomeReveals(e,this.world,a)}}};M.prototype.clearDirtyFlags=function(a){var b;var c=0;for(b=a.length;c<b;c++){var d=a[c];var e=d.tiles;var f=0;for(d=e.length;f<
d;f++){var g=e[f];g.ctxDirty=!1;g.lastDrawnAlpha=g.alpha}}};M.prototype.displayNewSegment=function(a){this.lastSegmentID=a;this.segmentDisplayTime=0};M.prototype.drawNewSegmentBanner=function(a){if(this.lastSegmentID&&this.segmentDisplayTime<2*config.io.segmentDisplayFadeTime+config.io.segmentDisplayDuration){var b=this.main.worldGenIO.worldSegmentList[this.lastSegmentID];n.assert(null!=b);var c=1;this.segmentDisplayTime<config.io.segmentDisplayFadeTime?c=this.segmentDisplayTime/config.io.segmentDisplayFadeTime:
this.segmentDisplayTime>config.io.segmentDisplayFadeTime+config.io.segmentDisplayDuration&&(c=1-(this.segmentDisplayTime-config.io.segmentDisplayFadeTime-config.io.segmentDisplayDuration)/config.io.segmentDisplayFadeTime);this.r.drawNewSegmentBanner(b,c)}this.segmentDisplayTime+=a};M.prototype.drawMap=function(a,b,c){var d=this,e,f,g,h;var k=this.main.showingOutro;k|=null!=(f=debug.drawAllTiles)?f:0;f=$jscomp.makeIterator(this.r.getCanvasSize());var l=f.next().value;var m=f.next().value;f=this.world.toBiomePos(this.r.cam.mouseToTilePos(0,
-12*this.s));l=this.world.toBiomePos(this.r.cam.mouseToTilePos(l,m+12*this.s));if(this.r.biomesDirty){var p=this.world.getBiomes();var q=0;for(m=p.length;q<m;q++){var t=p[q];t.ctxRedraw=!0;t.znCtxDirty=!0}}this.r.biomesDirty=!1;if(debug.logBiomeRenderStats){this.main.numBiomesRedraw=0;this.main.numBiomesDraw=0;this.main.numTilesDraw=0;this.main.numTileBordersDraw=0;var D=this.main.numMapBordersDraw=0}this.updateBiomes(k);p=g=l.y;for(q=f.y;g>=q;p=g+=-1)for(t=m=l.x,e=f.x;m>=e;t=m+=-1)t=this.world.getBiome(new u(t,
p),!1),null!=t&&t.hasVoid&&this.r.drawVoidTransparentTiles(t);m=[];p=q=l.y;for(h=f.y;q>=h;p=q+=-1)for(t=e=l.x,g=f.x;e>=g;t=e+=-1)t=this.world.drawBiome(new u(t,p),k),null!=t&&m.push(t);this.lastOnScreenBiomes=Object.clone(m);p=0;for(q=m.length;p<q;p++)t=m[p],this.r.drawLiveTile(t);e=this.world.getBiomes();q=0;for(p=e.length;q<p;q++)t=e[q],!m.includes(t)&&(t.ctxDirty||t.ctxRedraw)&&t.generated&&(this.r.drawBiomeTiles(t,this.world,k),m.push(t));if(debug.logBiomeRenderStats)for(p=0,k=m.length;p<k;p++)for(t=
m[p],e=t.tiles,q=0,t=e.length;q<t;q++)g=e[q],g.ctxDirty&&(D+=1);this.clearDirtyFlags(m);debug.logBiomeRenderStats&&(0<this.main.numTilesDraw||0<this.main.numTileBordersDraw||0<this.main.numMapBordersDraw)&&(r.info("=== DRAW STATS ==="),r.info("numBiomesRedraw:    "+this.main.numBiomesRedraw),r.info("numBiomesDraw:      "+this.main.numBiomesDraw),r.info("numTilesDraw:       "+this.main.numTilesDraw),r.info("numTileBordersDraw: "+this.main.numTileBordersDraw),r.info("numMapBordersDraw:  "+this.main.numMapBordersDraw),
r.info("numDirtyTiles:      "+D),null==(D=this.main).peakSprites&&(D.peakSprites=0),null==(D=this.main).peakBorders&&(D.peakBorders=0),this.main.peakSprites=Math.max(this.main.peakSprites,this.main.numSpritesDraw),this.main.peakBorders=Math.max(this.main.peakBorders,this.main.numMapBordersDraw),r.info("peakSprites:        "+this.main.peakSprites),r.info("peakBorders:        "+this.main.peakBorders));this.r.drawVoid(this.world);this.drawZones(a);this.drawPaths();this.r.drawParticles(!1);t=this.travelPath;
!this.main.showingOutro&&this.shipArrived&&(D=null!=this.sledgeTarget?["res_anm_husky_4_mini.png","res_anm_husky_3_mini.png","res_anm_husky_2_mini.png","res_anm_husky_1_mini.png","sledge"]:this.party.persons.filter(function(a){return null==a.riding}).map(function(a){return a.miniSprite}),k=this.isPartyHidden.bind(this),this.r.drawMiniParty(this.party.pos,t,D,k));null!=this.ioPartyGhosts&&this.ioPartyGhosts.draw();this.r.drawWayPoints(this.wayPoints);this.r.drawLocationMarkers(m,a);t.isDone()&&this.isPartyHidden(this.party.pos)[0]&&
this.shipArrived&&this.r.drawPartyArrow(this.party.pos);this.drawPathCost();this.main.showingOutro&&(D=this.party.legs.map(function(a){return[d.world.getTile(a[0]),a[1]]}),this.r.drawLegs(D));n.isIO()&&this.r.drawPartyIndicator(this.party.pos,b,c)&&(this.mouseAction={id:"centerOnParty"});!this.main.isWarping()&&debug.drawHubArrows&&this.r.drawDebugHubs();n.isIO()&&null==this.main.tutorial&&!this.main.isWarping()&&this.r.drawMapRuler(f,l);b=this.isTraveling()||null!=this.waiting?3:1;this.r.drawMapCloud(a*
b);f=this.party.inv.items;l=0;for(c=f.length;l<c;l++)b=f[l],null!=b&&null!=b.miniMap&&this.checkGenerateMiniMap(b.miniMap);n.isIO()&&null==this.main.tutorial&&this.drawNewSegmentBanner(a)};M.prototype.checkGenerateMiniMap=function(a){var b,c,d,e,f;var g=new R(null!=(b=.5*a.width*this.s)?b:50*this.s,null!=(c=.5*a.height*this.s)?c:50*this.s);if(null==a.center){var h=this.main.fillEventCtx(h);this.events.doEvent(a.initEvents,h);a.center=h.pos;b=null!=(null!=(d=a.initEvents)?null!=(e=d.addLocation)?e.ref:
void 0:void 0)?a.initEvents.addLocation.ref:config.specialLocations.treasure;h=h.world.getTile(h.pos).location;if(null==h||h.id!==b){a.center=null;return}n.isIO()?a.offset=new u(g.w/2,g.h/2):a.offset=new u(g.w/2+J.rand(.4*-g.w,.4*g.w),g.h/2+J.rand(.4*-g.h,.4*g.h))}if(null==a.canvas||a.scale!==this.s)return h=null!=(f=a.coverage)?f:1,a.scale=this.s,n.isIO()&&(a.offset=new u(g.w/2,g.h/2)),a.canvas=this.r.createMiniMap(a.center,g,a.offset,h,this.main.worldStack[0])};M.prototype.drawMiniMap=function(){if(!this.events.showingEventDialogue&&
null!=this.main.mouseItem){var a=this.main.mouseItem.miniMap;if(null!=a){this.checkGenerateMiniMap(a);var b=$jscomp.makeIterator(this.r.getCanvasSize());var c=b.next().value;b=b.next().value;var d=this.main.invBar.getSize();c=c/2-a.canvas.width/2;return this.r.drawMiniMap(a,c,b-a.canvas.height-25*this.s-d.h)}}};M.prototype.isPartyHidden=function(a,b,c){b=void 0===b?null:b;c=void 0===c?0:c;var d,e,f;a=this.world.getTile(a);b=this.world.getTile(b);c=null!=b&&.5<c?b:a;return null==c?!1:[(null!=(d=c.hideParty)?
d:!1)||(null!=(e=null!=(f=c.location)?f.hideParty:void 0)?e:!1),1<(null!=a?a.elevation:void 0),1<(null!=b?b.elevation:void 0)]};M.prototype.drawShip=function(){if(!this.shipArrived&&!this.main.waitingForDemoStart){this.r.ctx.globalAlpha=1;var a=this.shipPath[this.shipIdx];var b=this.r.getTileScreenPos(a,!0,!0,!1);if(this.shipIdx>=this.shipPath.length-1){var c=b;var d=a;var e="idle"}else d=this.shipPath[this.shipIdx+1],c=this.r.getTileScreenPos(d,!0,!0,!1),e=a.getDir(d).abbr;b=new u(b.x+this.shipTime*
(c.x-b.x),b.y+this.shipTime*(c.y-b.y));this.r.drawSprite("res_fxt_ship_"+e+".png",b.x,b.y,{scale:this.r.biomeScaleFactor});if(this.shipParticleTime>config.ship.particleDelay)return e=new u(a.x+this.shipTime*(d.x-a.x),a.y+this.shipTime*(d.y-a.y)),this.r.part.addParticleConf(t.getParticle(config.ship.particle),e),this.shipParticleTime=0}};M.prototype.onShipArrive=function(){if(!this.shipArrived){if(!n.isIO()){var a=this.world.getTile(this.world.startPos);this.world.addLocation(config.ship.location,
[a]);this.setLocationVisible(a,!0)}this.main.playMusic("sfx_startExpedition_1");r.info("SHIP;arrived");debug.logBiomeRenderStats&&(this.main.peakSprites=0,this.main.peakBorders=0);this.updateVisibility();this.main.onBonusChanged();this.shipArrived=!0;this.main.updateActions();n.isIO()&&!t.checkFlags("+visitedOutpost",this.party.flags)&&this.main.doAction(0)}};M.prototype.drawPunch=function(){if(this.showingPunch)return null!=this.mouseTilePos&&(null==this.punchRange||this.mouseTilePos.dist(this.party.pos)<=
this.punchRange)&&this.punchDraw(this.mouseTilePos,this.punchRadius),this.r.drawPunch(this.punchText,this.mouseTilePos,this.punchRadius,this.validPunch(this.mouseTilePos))};M.prototype.drawPaths=function(){var a=this;if(this.main.showingOutro){var b=this.party.moves.map(function(b){return a.world.getTile(b)});this.r.drawPartyPath(null,b)}else{this.showingPunch&&!this.punchPathable||null==this.previewPath||(b=this.previewPath.map(function(b){return a.world.getTile(b)}),this.r.drawPartyPath(this.world.getTile(this.party.pos),
b,{maxDist:this.previewPathMaxDist,items:this.previewItems}));var c=this.previewTracks;var d=0;for(b=c.length;d<b;d++){var e=c[d];this.r.drawPartyPath(null,e.path)}}};M.prototype.drawPathCost=function(){if(!(this.main.showingOutro||this.showingPunch&&!this.punchPathable||null==this.previewPath||0===this.previewPath.length||this.r.pureMode)){this.sanityRisk=-1;var a=[""+this.previewPathCost];var b=this.previewPath.length-this.previewPathMaxDist;var c=this.previewPath.length<=this.previewPathMaxDist;
c||(a=["0%"],b=this.sanityTurn+b,this.sanityRisk=0,0<b&&(this.sanityRisk=Math.min(1,b/config.sanity.maxExtraMoves),a=[Math.round(100*this.sanityRisk)+"%"]));return this.r.drawPathCost(this.previewPath.last(),c,a)}};M.prototype.drawCompass=function(a,b,c){if(!this.party.isOtherworldly()&&null!=this.compass)return this.r.drawCompass(a,this.compass.angle,this.compass.maxError,this.compassScore,this.world.maxCompassScore,this.compassTime,this.compassDist,this.main.infoBox,b,c)};M.prototype.drawZones=
function(a){var b;if(!(-1>this.r.zoomLevel)){var c=J.clamp(null!=(b=this.travelPath.getAlpha())?b:0,0,1);var d=this.world.zones;var e=0;for(b=d.length;e<b;e++){var f=d[e];if(null!=f.center)if(0<f.moveQueue.length&&1>c&&0<c){var g=[f.center,f.moveQueue].flatten();var h=1/(g.length-1);var k=Math.min(g.length-2,Math.floor(c/h));h=c/h-k;var l=this.world.getTile(g[k]);g=this.world.getTile(g[k+1]);null!=l&&(l.known||debug.drawAllTiles)&&(g.known||debug.drawAllTiles)&&(k=this.r.getTileScreenPos(l.pos,!0,
!0,!0),g=this.r.getTileScreenPos(g.pos,!0,!0,!0),h=new u(k.x+h*(g.x-k.x),k.y+h*(g.y-k.y)),this.r.drawTileZoneIcon(a,f,h,!1))}else if(h=this.world.getTile(f.center),h.known||debug.drawAllTiles)h=this.r.getTileScreenPos(f.center,!0,!0,!0),this.r.drawTileZoneIcon(a,f,h)}}};M.prototype.toComboList=function(a){var b;var c=[];a=a.groupBy(function(a){var b;return null!=(b=a.debugCategory)?b:"etc"});for(b in a){var d=a[b];d=d.filter(function(a){return!a.isAbstract}).map(function(a){return{id:a.id}});c.push({id:b,
entries:d})}return c};M.prototype.createDebugBar=function(){var a,b;var c=[{id:"Items",entries:Object.values(config.items)},{id:"Statuses",entries:Object.values(config.statuses)},{id:"Characters",entries:Object.values(config.characters)},{id:"Locations",entries:Object.values(config.locations)},{id:"Zones",entries:Object.values(config.zones)},{id:"Sprawls",entries:Object.values(config.sprawls)},{id:"Tiles",entries:Object.values(config.tiles)},{id:"Biomes",entries:Object.values(config.biomes)},{id:"Chat Lines",
entries:Object.values(config.chatLines)},{id:"Events",entries:Object.values(config.events)},{id:"Tribes",entries:Object.values(config.tribeGens)},{id:"Particles",entries:Object.values(config.particles)}];n.isIO()&&c.push({id:"Packs",entries:Object.values(config.packs)});var d=0;for(a=c.length;d<a;d++){var e=c[d];var f=Object.values(e.entries);f.any(function(a){return null!=a.debugCategory})&&(e.entries=this.toComboList(f))}this.comboEntity=new Ra(this.r,"Entities",null,c,this.debugEntity);this.comboEntity.canQuery=
!0;this.comboEntity.fillTitle=!1;this.comboHistory=new Ra(this.r,"History",null,[],this.debugEntity);this.comboHistory.fillTitle=!1;if("undefined"!==typeof localStorage&&null!==localStorage)return this.comboHistory.options=JSON.parse(null!=(b=localStorage.getItem("debugHistory"))?b:"[]")};M.prototype.debugEntity=function(a){var b=t.getEntity(a);if(null!=b){r.info("ENTITY '"+a+"':\n"+JSON.stringify(b,null,"\t"),b.mod);switch(a.slice(0,3)){case "evt":this.main.doEvent(t.getEvent(a));break;case "loc":var c=
new sb(a);b=this.main.world.getArea(this.party.pos,1);this.main.world.addLocation(c,b);this.updateVisibility();this.main.updateActions();break;case "it-":this.party.inv.changeItemCount(a,1);break;case "zn-":this.main.world.addZone(a,this.party.pos,"..1");break;case "ch-":case "sp-":case "anm":case "npc":case "pl-":case "emy":this.party.addCharacter(a);break;case "st-":debug.testStatus=a;break;case "spr":this.main.world.startSprawl(a,this.party.pos);break;case "tl-":b=new Ab;b.setup(a);c=this.main.world.getTile(this.party.pos);
b.isBlocking()&&(c=this.main.world.getTile(this.party.pos.move(K.n)));this.main.world.replaceTile(c,a);break;case "bio":var d=this.world.getTile(this.party.pos);null!=d&&(this.world===this.main.worldGenIO.world?(c=this.world.toBiomePos(this.party.pos),b=this.main.worldGenIO.getBiomeDict(c),b.biomeID=a,b.biomeSeed+=1,d.biome.generated=!1,this.main.worldGenIO.generateBiome(c)):(d.biome.id=a,this.main.worldGen.buildPerlin(d.biome),d.biome.ctxRedraw=!0));break;case "cl-":b=this.main.fillEventCtx();b.person=
null;b=this.main.randChatLine(a,b);this.main.showChatMsg(b);break;case "tg-":debug.testTribe=a;this.main.gotoTribeGen();break;case "pac":this.main.ioInv.addPack(a);break;case "pt-":b=t.getParticle(a),c=this.main.r.part.getParticlePositionForTilePos(b,this.party.pos.move(K.n)),this.main.r.part.addParticleConf(b,c)}this.comboHistory.options.none(function(b){return b.id===a})&&(this.comboHistory.options.unshift({id:a}),this.comboHistory.options=this.comboHistory.options.slice(0,20),"undefined"!==typeof localStorage&&
null!==localStorage&&localStorage.setItem("debugHistory",JSON.stringify(this.comboHistory.options)));return this.main.onBonusChanged()}r.info("ENTITY '"+a+"' not found")};M.prototype.drawDebugBar=function(a,b,c){var d;if(debug.showDebugBar){null==this.comboEntity&&this.createDebugBar();var e=$jscomp.makeIterator(this.r.getCanvasSize());var f=e.next().value;e.next();this.r.ctx.globalAlpha=1;this.r.ctx.fillStyle="black";this.r.ctx.fillRect(0,0,f,15*this.s);e=$jscomp.makeIterator([2,90*this.s]);f=e.next().value;
e=e.next().value;var g=[this.comboEntity,this.comboHistory];var h=0;for(d=g.length;h<d;h++){var k=g[h];k.draw(f,2,a,b,c)&&(this.mouseAction=null);f+=e+2*this.s}e=70*this.s;this.r.drawDebugButton("- Sanity: "+this.party.sanity+" +",f,a,b,e)&&(this.mouseAction=a>f+e/2?{id:"debugIncSanity"}:{id:"debugDecSanity"});f+=e+4;this.r.drawDebugButton("- Standing: "+this.party.standing+" +",f,a,b,e)&&(this.mouseAction=a>f+e/2?{id:"debugIncStanding"}:{id:"debugDecStanding"});f+=e+4;this.r.drawDebugButton("- XP: "+
this.party.xp+" +",f,a,b,e)&&(this.mouseAction=a>f+e/2?{id:"debugIncBiomePoint"}:{id:"debugDecBiomePoint"});f+=e+4;this.main.diary.isInCombat?(c=(e-4)/2,this.r.drawDebugCheckBox(this.main.challenge.debugIsGodMode,"God",f,a,b,c)&&(this.mouseAction={id:"debugFightGodMode"}),f+=c+4,this.r.drawDebugButton("Win",f,a,b,c)&&(this.mouseAction={id:"debugFightWin"}),f+=c+4):n.isIO()||(this.r.drawDebugButton("Success!",f,a,b,e)&&(this.mouseAction={id:"debugEndWorld"}),f+=e+4);this.r.drawDebugButton("Reload Mods",
f,a,b,e)&&(this.mouseAction={id:"debugRefresh"});f+=e+4;this.r.drawDebugButton("Show Log",f,a,b,e,{errors:r.errorCount(),warnings:r.warningCount()})&&(this.mouseAction={id:"debugShowLog"});return f+(e+4)}};M.prototype.showCharacterInfo=function(a){var b=this.main.party.persons.findIndex(a)-this.r.partyOffset;b=this.r.charPortraitPos(b,this.party.persons.length,this.party.maxUnitCount);return this.main.showPersonInfo={person:a,pos:b}};M.prototype.onMouseMove=function(a){var b=!(null!=this.oldMousePos&&
this.oldMousePos.x===a.x&&this.oldMousePos.y===a.y);var c=$jscomp.makeIterator(this.r.getCanvasSize());var d=c.next().value;c.next();if(!this.main.events.showingEventDialogue&&null==this.mouseWayPoint&&(this.r.cam.onScrollMove(a.x,a.y),this.r.cam.mouseScrolling))return;if(!(this.main.r.introTime<config.anim.introTime||null!=this.main.r.showStatusInfo||null!=this.mouseAction||this.main.showingOutro)){if(this.main.showPartySidebar&&!this.main.events.showingEventDialogue&&(c=this.main.r.mouseToPortrait(this.main.party,
a.x,a.y),null!=c&&this.main.showPartySidebar)){this.showCharacterInfo(c);return}if(null!=this.main.showPersonInfo)null==this.main.handleCharacterInfo(a.x,a.y)&&(this.main.showPersonInfo=null);else if(!this.main.events.showingEventDialogue&&!this.main.showingBiomes)if(this.main.r.cam.mouseScrolling)this.main.infoBox.hide();else if(null==this.main.invBar.dragCtx.item&&!(a.y<30*this.s||a.x<20*this.s||a.x>d-23*this.s||n.isIO()&&(a.y<40*this.s+this.r.oY||a.x>d-100*this.s))){d=this.main.r.cam.mouseToTilePos(a.x,
a.y);c=!1;this.main.mouseBiome=null;if(null!=d){var e=this.main.world.getTile(d,debug.drawAllTiles);if(null==e)return;this.main.mouseBiome=e.biome;if(!this.travelPath.isDone())return;this.main.showPath&&(this.mouseTilePos=d);null!=this.mouseWayPoint&&b&&(this.updateWayPoint(this.mouseWayPoint,d),this.checkMouseTravel=!1);if(null!=e&&e.known||debug.drawAllTiles)c=!0,this.showTileInfo=e}c||this.main.infoBox.hide();return this.oldMousePos={x:a.x,y:a.y}}}};M.prototype.onScroll=function(a){};M.prototype.onMousePan=
function(a,b){a=-a;b=-b;if(0!==a||0!==b)return this.r.cam.doScroll(a,b)};M.prototype.onMouseWheel=function(a){if("game"===this.main.getMainState())return 0<a?this.zoomIn():this.zoomOut()};M.prototype.zoomIn=function(){if(null!=this.party)return this.r.zoomIn()};M.prototype.zoomOut=function(){return this.r.zoomOut()};M.prototype.onMouseDown=function(a){var b=this;if(this.shipArrived){if(this.main.r.cam.onScrollMouseDown(a),null!=this.mouseTilePos&&(this.checkMouseTravel=!0,a=this.wayPoints.findIndex(function(a){return a.eq(b.mouseTilePos)}),
0<=a&&a<this.wayPoints.length))return this.mouseWayPoint=a}else this.shipSpeed=5};M.prototype.onMouseUp=function(a){var b;var c=this.mouseTilePos;this.mouseWayPoint=null;if(!this.main.showingBarter&&null==this.main.showPersonInfo){var d=null!=(b=this.main.invBar.mouseMoveItem)?b.item:void 0;if(0<(null!=d?d.amount:void 0)){this.main.useItem(d);this.main.invBar.mouseMoveItem=null;return}if(this.main.invBar.actionTrash)return}null!=this.mouseAction&&("itemTab"===this.mouseAction.id&&this.main.invBar.tabItems(),
"centerOnParty"===this.mouseAction.id&&this.r.cam.moveToPos(this.party.pos));if(null==this.main.invBar.dragCtx.item)if(this.showingPunch)this.validPunch(c)&&this.doPunch(c);else if(this.main.showingChallenge){if(this.main.challenge.onMouseClick(a),null!=this.mouseAction)if("debugFightGodMode"===this.mouseAction.id)this.main.challenge.debugIsGodMode=!this.main.challenge.debugIsGodMode;else if("debugFightWin"===this.mouseAction.id){b=this.main.challenge.enemies;var e=0;for(d=b.length;e<d;e++)a=b[e],
this.main.challenge.doDamage([a],a.health)}}else if(this.main.showingEventAlert&&a.x<config.diary.alertWidth*this.s&&this.travelPath.isDone())this.main.hideEventAlert();else{if(null!=this.main.showPersonInfo){d=this.main.r.mouseToPortrait(this.main.party,a.x,a.y);e=b=this.main.handleCharacterInfo(a.x,a.y);Object.isObject(b)&&(e=e.id);if(null!=e)switch(e){case "close":this.main.showPersonInfo=null;break;case "dismiss":this.main.checkDismissCharacter(this.main.showPersonInfo.person);this.main.showPersonInfo=
null;break;case "mount":this.main.party.mount(this.main.showPersonInfo.person,this.main.party.getExplorer());this.main.showPersonInfo=null;break;case "dismount":this.main.party.dismount(this.main.showPersonInfo.person);this.main.showPersonInfo=null;break;case "levelUp":d=this.main.showPersonInfo.person;break;case "customButton":this.main.doRandEvent(b.data,{person:b.person});break;case "debugRemoveCharacter":this.main.party.removeCharacter(this.main.showPersonInfo.person);this.main.party.storePerson(this.main.showPersonInfo.person);
break;case "debugIncLoyalty":this.main.showPersonInfo.person.changeLoyalty(1);break;case "debugDecLoyalty":this.main.showPersonInfo.person.changeLoyalty(-1);break;case "debugIncHealth":this.main.showPersonInfo.person.changeHealth(1);break;case "debugDecHealth":this.main.showPersonInfo.person.changeHealth(-1);break;case "debugAddStatus":this.main.showPersonInfo.person.setStatus(debug.testStatus,!0);break;case "debugRemoveStatus":this.main.showPersonInfo.person.setStatus(debug.testStatus,!1)}if(null!=
d){if(a=this.main.party.levelUp(d))this.main.onBonusChanged(),d.isSpecial?this.main.gotoIOPromote():this.main.mainMenu.saveGame.updateSaveGame();return}}if(!this.main.io.onMouseClickDiary(a))if(null!=this.mouseAction){switch(this.mouseAction.id){case "action":this.main.doAction(this.mouseAction.data);break;case "wait":this.party.changeSanity(-this.party.tripCost);this.wait(4,0,[config.specialEvents.waitNoSanity],!0);break;case "balloon":this.main.doEvent(t.getEvent(config.specialEvents.balloon));
break;case "highscores":this.main.gotoHighScore();break;case "debugIncBiomePoint":this.party.changeXP(1);break;case "debugDecBiomePoint":this.party.changeXP(-1);break;case "debugIncStanding":this.party.changeStanding(1);break;case "debugDecStanding":this.party.changeStanding(-1);break;case "debugIncSanity":this.party.changeSanity(25);break;case "debugDecSanity":this.party.changeSanity(-25);break;case "debugEndWorld":this.main.endWorld();break;case "debugShowLog":r.openWindow();break;case "debugRefresh":this.main.modding.loadMods();
this.main.entitiesDirty=!0;this.main.prepareEntities();this.createDebugBar();break;case "settings":n.isIO()&&null==this.main.tutorial?this.main.setMainState("ionewgame"):this.main.showSettings(!0);break;case "tutorial":this.canHaveEvent()&&(this.main.mainMenu.saveGame.updateSaveGame(),debug.skipStartEvents=!1,this.main.startTutorial());break;case "skipTutorial":n.assert(null!=this.main.tutorial);this.main.endWorld();break;case "partyTab":this.r.partyOffset+=config.uiMaxUnitCount,this.r.partyOffset>
Math.max(this.party.maxUnitCount,this.party.persons.length)&&(this.r.partyOffset=0)}this.mouseAction=null}else if(this.main.showingOutro&&(this.main.outroTime+=100),this.travelPath.isDone())if(this.main.showingEventAlert)this.main.diaryBumpTime=0;else if(this.main.party.pos.eq(c)&&this.main.doAction(0),!this.main.events.showingEventDialogue&&this.checkMouseTravel){a=this.wayPoints.findIndex(function(a){return a.eq(c)});if(0>a)return this.addMouseWayPoint();if(a===this.wayPoints.length-1)return this.doPartyTravel()}}};
var K={here:{val:0,delta:new u(0,0),name:"here",abbr:"h"},n:{val:1,delta:new u(0,-1),name:"north",abbr:"n",rval:0},ne:{val:2,delta:new u(1,0),name:"north east",abbr:"ne",rval:1},se:{val:3,delta:new u(1,1),name:"south east",abbr:"se",rval:2},s:{val:4,delta:new u(0,1),name:"south",abbr:"s",rval:3},sw:{val:5,delta:new u(-1,0),name:"south west",abbr:"sw",rval:4},nw:{val:6,delta:new u(-1,-1),name:"north west",abbr:"nw",rval:5}};var Ea=Object.values(K);var Ic=[K.n,K.ne,K.se,K.s,K.sw,K.nw];var Sa={here:{val:0,
delta:new u(0,0),name:"here"},n:{val:1,delta:new u(0,-1),name:"north"},ne:{val:2,delta:new u(1,-1),name:"north east"},e:{val:3,delta:new u(1,0),name:"east"},se:{val:4,delta:new u(1,1),name:"south east"},s:{val:5,delta:new u(0,1),name:"south"},sw:{val:6,delta:new u(-1,1),name:"south west"},w:{val:7,delta:new u(-1,0),name:"west"},nw:{val:8,delta:new u(-1,-1),name:"north west"}};var C=function(){var a=this,b,c,d;this.setupRenderer=this.setupRenderer.bind(this);this.setupMouseWheel=this.setupMouseWheel.bind(this);
this.setCustomCursor=this.setCustomCursor.bind(this);this.setQuickText=this.setQuickText.bind(this);this.toggleCombatAutoselect=this.toggleCombatAutoselect.bind(this);this.handleScale=this.handleScale.bind(this);this.setupFonts=this.setupFonts.bind(this);this.setSendStats=this.setSendStats.bind(this);this.setCanvasStyleSize=this.setCanvasStyleSize.bind(this);this.onWindowResize=this.onWindowResize.bind(this);this.initMainState=this.initMainState.bind(this);this.setMainState=this.setMainState.bind(this);
this.popMainState=this.popMainState.bind(this);this.getMainState=this.getMainState.bind(this);this.getMainStateObj=this.getMainStateObj.bind(this);this.hasMainState=this.hasMainState.bind(this);this.prepareGame=this.prepareGame.bind(this);this.checkData=this.checkData.bind(this);this.convertSlotColors=this.convertSlotColors.bind(this);this.restoreBackupConfig=this.restoreBackupConfig.bind(this);this.startGame=this.startGame.bind(this);this.startIO=this.startIO.bind(this);this.loadOrStartIOGame=this.loadOrStartIOGame.bind(this);
this.initNewIOGame=this.initNewIOGame.bind(this);this.startNewIOGame=this.startNewIOGame.bind(this);this.startDemo=this.startDemo.bind(this);this.startNewDemoGame=this.startNewDemoGame.bind(this);this.startExplorerWheel=this.startExplorerWheel.bind(this);this.drawExplorerWheel=this.drawExplorerWheel.bind(this);this.startTutorial=this.startTutorial.bind(this);this.prepareTutorialWorld=this.prepareTutorialWorld.bind(this);this.continueGame=this.continueGame.bind(this);this.debugContinueGame=this.debugContinueGame.bind(this);
this.selectExplorer=this.selectExplorer.bind(this);this.getTribeGenAtPartyPos=this.getTribeGenAtPartyPos.bind(this);this.updateForNewPartyPos=this.updateForNewPartyPos.bind(this);this.displayClaimNotification=this.displayClaimNotification.bind(this);this.updateAmbientSound=this.updateAmbientSound.bind(this);this.prepareWorld=this.prepareWorld.bind(this);this.resetExped=this.resetExped.bind(this);this.getMouseTile=this.getMouseTile.bind(this);this.addDebugWatch=this.addDebugWatch.bind(this);this.clearDebugWatch=
this.clearDebugWatch.bind(this);this.onMouseWheel=this.onMouseWheel.bind(this);this.handleScrollWheelEvent=this.handleScrollWheelEvent.bind(this);this.handlePanEvent=this.handlePanEvent.bind(this);this.onScroll=this.onScroll.bind(this);this.getDefaultScalingFactor=this.getDefaultScalingFactor.bind(this);this.setLowGraphicsMode=this.setLowGraphicsMode.bind(this);this.onLoadedImgs=this.onLoadedImgs.bind(this);this.getRenderStats=this.getRenderStats.bind(this);this.showEventAlert=this.showEventAlert.bind(this);
this.hideEventAlert=this.hideEventAlert.bind(this);this.tickLeftSidebar=this.tickLeftSidebar.bind(this);this.tickDiary=this.tickDiary.bind(this);this.randChatLine=this.randChatLine.bind(this);this.showChatMsg=this.showChatMsg.bind(this);this.randItemSet=this.randItemSet.bind(this);this.trashItem=this.trashItem.bind(this);this.isUsableItem=this.isUsableItem.bind(this);this.useItem=this.useItem.bind(this);this.doPreEvent=this.doPreEvent.bind(this);this.fillEventCtx=this.fillEventCtx.bind(this);this.doDelayedEvent=
this.doDelayedEvent.bind(this);this.doRandEvent=this.doRandEvent.bind(this);this.showRandEventAlert=this.showRandEventAlert.bind(this);this.checkEventDiff=this.checkEventDiff.bind(this);this.playSound=this.playSound.bind(this);this.stopMusic=this.stopMusic.bind(this);this.tickSound=this.tickSound.bind(this);this.hideBarter=this.hideBarter.bind(this);this.showCombat=this.showCombat.bind(this);this.doChallengeSuccess=this.doChallengeSuccess.bind(this);this.doAction=this.doAction.bind(this);this.endGame=
this.endGame.bind(this);this.tick=this.tick.bind(this);this.tickDemo=this.tickDemo.bind(this);this.checkExpeditionOver=this.checkExpeditionOver.bind(this);this.tickChat=this.tickChat.bind(this);this.draw=this.draw.bind(this);this.wrapSafe=this.wrapSafe.bind(this);this.drawMain=this.drawMain.bind(this);this.drawGameState=this.drawGameState.bind(this);this.drawSubItems=this.drawSubItems.bind(this);this.handleCharacterInfo=this.handleCharacterInfo.bind(this);this.drawActionButtons=this.drawActionButtons.bind(this);
this.drawWarningBar=this.drawWarningBar.bind(this);this.drawInventoryBar=this.drawInventoryBar.bind(this);this.drawHUD=this.drawHUD.bind(this);this.drawPartySideBar=this.drawPartySideBar.bind(this);this.onActionsChanged=this.onActionsChanged.bind(this);this.appendLangTexts=this.appendLangTexts.bind(this);this.getLangId=this.getLangId.bind(this);this.displayLoadError=this.displayLoadError.bind(this);if("undefined"===typeof isMobileDevice||null===isMobileDevice||!isMobileDevice()){O.resDoneCount=0;
O.resCount=0;O.displayLoadError=this.displayLoadError;debug.isDemo&&(window.gameMode=ya.Demo);null!=(null!=(b=window.iomp)?b.parseUser:void 0)?this.user=window.iomp.parseUser:this.user="undefined"!==typeof Parse&&null!==Parse?Parse.User.current():void 0;if(!window.isClient&&!n.isDemo()){if(null==this.user){r.error("No user: mode "+this.getClient());displayNoUser();return}b=this.user.get("gameKey");if(null==b||"rivals"===b){r.error("User with bad key: mode "+this.getClient());displayNoUser("<br>Your account '"+
this.user.get("username")+"' does not have a valid web key!");return}}null!=window.iomp&&(this.iomp=window.iomp);this.logs=[];null==this.debug&&(this.debug={});window.onresize=this.onWindowResize;this.ctx=window.getDstCanvas().getContext("2d");this.r=this.setupRenderer(this.ctx);this.s=this.r.s;null!=this.ctx&&(this.r.sfx=this.sfx=new ab(this));this.r.img.attachOnAllLoadedHandler(this.onLoadedImgs);this.allStates=[{id:"preRoll",clear:!0},{id:"mainMenu",clear:!0},{id:"gallery",clear:!0},{id:"narrator",
clear:!0},{id:"worldMap",clear:!0},{id:"harbor",clear:!0},{id:"loading",clear:!0},{id:"game",clear:!0},{id:"ranking",clear:!0},{id:"celebration",clear:!0},{id:"epilogue",clear:!0},{id:"highscore",clear:!0},{id:"taxonomy",clear:!1},{id:"tribeGen",clear:!1},{id:"settings",clear:!1},{id:"credits",clear:!1},{id:"modding",clear:!1}];n.isIO()&&(this.allStates.push({id:"iosplash",clear:!0}),this.allStates.push({id:"ionewgame",clear:!1}),this.allStates.push({id:"iohighscore",clear:!1}),this.allStates.push({id:"iopromote",
clear:!1}),this.allStates.push({id:"iotransact",clear:!1}));n.canUseLocalStorage()&&window.localStorage.setItem("isIO",n.isIO());this.onWindowResize();this.loadConfig(function(){a.contentDirty=!1;a.dataDirty=!1;a.mainStates=[];a.mainMenu=a.initMainState("mainMenu",X);a.settings=a.initMainState("settings",Aa);a.credits=a.initMainState("credits",nb);a.tribeGen=a.initMainState("tribeGen",Ta);a.taxonomy=a.initMainState("taxonomy",gb);a.modding=a.initMainState("modding",Q);a.preRoll=a.initMainState("preRoll",
mb);n.isIO()?(a.ioSplash=a.initMainState("iosplash",Pd),a.ioNewGame=a.initMainState("ionewgame",Qd),a.iohighscore=a.initMainState("iohighscore",Rd),a.iopromote=a.initMainState("iopromote",Sd),a.ioTransact=a.initMainState("iotransact",jc)):a.highscore=a.initMainState("highscore",za);a.io=new Pa(a);a.infoBox=new Oa(a);a.achievementBox=new Nd(a);a.chat=new hb(a);a.achievements=new Xa(a,achievements);a.entitiesDirty=!0;a.prepareEntities();a.r.tribeGen=a.tribeGen;n.canUseLocalStorage()&&(a.quickText="true"===
window.localStorage.getItem("quickText"),a.setCustomCursor("false"!==window.localStorage.getItem("customCursor")),a.combatAutoSelect="true"===window.localStorage.getItem("combatAutoSelect"),window.localStorage.getItem("sendStats"));var b=n.isIO();a.setSendStats(b);a.firstCombat=!0;a.showingChallenge=!1;window.isClient&&"false"!==window.localStorage.getItem("fullscreen")&&a.settings.toggleFullscreen();a.worldLvl=0;a.worldStack=[];a.gameCount=0;a.outroItems=[];a.restoredSaveGame=null;a.trailerMode=
!1;a.mousePos=new u(0,0);a.lastTick=new Date});var e=new pa(1337);var f=function(){for(var a=[],b=0;100>b;b++)a.push(b);return a}.apply(this).map(function(){return e.randInt(-1E3,1E4)});b=[-885,8526,1687,1367,2407,7232,8885,6063,1412,6528,7165,4056,-993,1452,4260,1300,2593,2217,5893,3048,966,1366,4079,9929,2576,4541,9527,2186,1102,4410,88,-354,8896,4060,556,8340,8215,2529,-814,4035,2200,6367,1166,1604,-117,991,4451,8387,5745,4302,7838,7001,8948,5054,2710,5821,4211,831,5723,9719,4733,5018,2105,5017,
545,3915,8187,2408,768,5627,3899,5578,4042,7513,1994,9604,-8,9585,590,7398,7709,5748,1366,4112,8310,6695,2653,8634,2027,-769,7597,5075,2381,1716,2507,-150,9471,96,-151,3208];for(c=d=0;100>d;c=++d)if(f[c]!==b[c]){this.doSendError("RNG determinism failed: "+c+" expected "+b[c]+" got "+f[c]+" browser '"+navigator.userAgent+"' platform '"+navigator.platform+"' lang "+this.getLangId());break}}};C.prototype.log=function(a){a="("+this.getMainState()+") "+a;r.info(a);for(this.logs.push(a);50<this.logs.length;)this.logs.shift()};
C.prototype.setupRenderer=function(a){a=new z(this,a,this.sfx);a.img=new oa(this,null,this.getLangId());this.setupMouseWheel(window.getDstCanvas());a.cam.resetScroll();a.enableMouseMoveCursor(!1);return a};C.prototype.setupMouseWheel=function(a){if(a.attachEvent)return a.attachEvent("onwheel",this.onMouseWheel);if(a.addEventListener)return a.addEventListener("wheel",this.onMouseWheel)};C.prototype.setCustomCursor=function(a){this.customCursor=a;if(n.canUseLocalStorage())return window.localStorage.setItem("customCursor",
a)};C.prototype.setQuickText=function(a){this.quickText=a;if(n.canUseLocalStorage())return window.localStorage.setItem("quickText",this.quickText)};C.prototype.toggleCombatAutoselect=function(a){this.combatAutoSelect=a;if(n.canUseLocalStorage())return window.localStorage.setItem("combatAutoSelect",this.combatAutoSelect)};C.prototype.handleScale=function(a){if(window.isNW){var b=require("nw.gui");return b.Window.get()}if(window.isElectron){b=require("electron").remote.getCurrentWindow();var c=b.getBounds();
var d=b.getContentSize();var e=c.width-d[0];d=c.height-d[1];if(a)return b.setMinimumSize(0,0);a=Math.round(640*this.s+e);e=Math.round(360*this.s+d);b.setMinimumSize(a,e);return b.setSize(a,e)}};C.prototype.setPixelScale=function(a,b){var c;1!==a&&2!==a&&3!==a&&6!==a&&(a=2);n.canUseLocalStorage()&&(window.localStorage.setItem("scaling",b),window.localStorage.setItem("pixelScale",a));this.stretching=b;this.pixelScaleSetting=a;0<(null!=window.devicePixelRatio)&&!b&&(a/=window.devicePixelRatio);var d=
window.getDstCanvas();this.r.ctx=this.ctx=d.getContext("2d");this.s=a;this.r.setImageSmoothing(!1,this.ctx);this.handleScale(b);this.r.s=a;this.r.updateBlockSize();this.infoBox.s=a;this.achievementBox.s=a;null!=(b=this.diary)&&(b.s=a);null!=(b=this.challenge)&&(b.s=a);null!=(b=this.barter)&&(b.s=a);null!=(b=this.notifications)&&(b.s=a);null!=(b=this.chat)&&(b.s=a);null!=(b=this.exped)&&(b.s=a);null!=(b=this.ioInv)&&(b.s=a);b=this.allStates;for(e in b)d=b[e],null!=(d=d.obj)&&(d.s=a);this.mainMenu.showDebugBar(debug.showDebugBar);
var e=this.r.img.sprites;for(c in e)b=e[c],b.scale=a,b.dSize=new R(a*b.size.w,a*b.size.h);e=this.allStates;d=0;for(c=e.length;d<c;d++)b=e[d],null!=b.obj&&(b.obj.s=a);this.setupFonts();this.onWindowResize();if(null!=this.r.cam)return this.r.cam.centerOnPos(this.r.cam.screenCenterPos)};C.prototype.setupFonts=function(){config.fonts=config.scaledFonts[6===this.pixelScaleSetting?3:this.pixelScaleSetting-1];if(null==config.fonts)throw"no fonts for scale "+this.pixelScaleSetting;};C.prototype.setSendStats=
function(a){n.canUseLocalStorage()&&window.localStorage.setItem("sendStats",a);return this.sendStats=a};C.prototype.setCanvasStyleSize=function(a,b){var c=window.getDstCanvas().style;c.width=a+"px";c.height=b+"px"};C.prototype.onWindowResize=function(){if(n.isDemo()){var a=$jscomp.makeIterator(setupDemoWindow(this));var b=a.next().value;var c=a.next().value;var d=a.next().value;a=a.next().value;this.r.frameRatio=new R(b/d,c/a);this.r.frameSize=new R(d,a)}else c=window.getDstCanvas(),c.width=640*this.s,
c.height=360*this.s,this.stretching?(a=c.width/c.height,d=window.innerWidth/window.innerHeight,d<a?(d=window.innerWidth,a=window.innerWidth/a):(d=window.innerHeight*a,a=window.innerHeight),this.setCanvasStyleSize(d,a),this.r.frameRatio=new R(d/c.width,a/c.height),this.r.frameSize=new R(c.width,c.height),c=(window.innerHeight-Math.max(1,a))/2):(this.setCanvasStyleSize(c.width,c.height),c=Math.max(0,window.innerHeight/2-c.height/2),a=$jscomp.makeIterator(this.r.getCanvasSize()),d=a.next().value,a=a.next().value,
this.r.frameRatio=new R(1,1),this.r.frameSize=[d,a]),$("#gameContent")[0].style.marginTop=c+"px",this.hasFixedFPS=!1};C.prototype.setTrailerMode=function(a){this.r.trailerMode=a;this.exped.resetPath();this.r.setViewAllMode(a);return this.r.setPureMode(a)};C.prototype.initMainState=function(a,b){var c=this.allStates.find(function(b){return b.id===a});n.assert(null!=c,"Unknown main state: "+a);c.obj=new b(this.r,this.sfx,this);return c.obj};C.prototype.setMainState=function(a){var b,c;var d=this.allStates.find(function(b){return b.id===
a});n.assert(null!=d,"Unknown main state: "+a);r.info("NEW-STATE;"+a);if(d.clear){var e=this.mainStates;var f=0;for(b=e.length;f<b;f++)a=e[f],null!=(null!=a?a.obj:void 0)&&a.obj.hide();this.mainStates=[]}this.mainStates.push(d);return null!=(c=d.obj)?c.show():void 0};C.prototype.popMainState=function(){this.wasLoadingBeforeGame="loading"===this.getMainState();var a=this.mainStates.last();null!=(null!=a?a.obj:void 0)&&a.obj.hide();return this.mainStates.pop()};C.prototype.getMainState=function(){if(null!=
this.mainStates.last())return this.mainStates.last().id};C.prototype.getMainStateObj=function(){if(null!=this.mainStates.last())return this.mainStates.last().obj};C.prototype.hasMainState=function(a){return this.mainStates.any(function(b){return b.id===a})};C.prototype.canSave=function(){var a,b,c,d;if(n.isDemo())return!1;var e=null!=(a=null!=(b=this.iomp)?b.isSaving:void 0)?a:this.mainMenu.saveGame.saving;return null!=this.tutorial||e||this.showingChallenge||null==this.events||this.events.showingEventDialogue&&
!this.hasMainState("iosplash")&&!this.hasMainState("ionewgame")||this.showingEventAlert||null!=(null!=(c=this.exped)?c.waiting:void 0)||null==(d=this.exped)||!d.shipArrived||this.worldDone?!1:!0};C.prototype.prepareGame=function(a){var b=this;a=void 0===a?!0:a;var c,d;this.gameOver=!1;this.leftSidebarScrollX=this.diaryScrollX=0;this.worldLvl=null!=(c=debug.testWorldLevel)?c:0;this.worldStack=[];this.restoredSaveGame=null;this.events=new ka(this);this.notifications=new ib(this);this.party=new N(this,
this.events,this.r,this.chat);this.globalInvs={};c={inv:null,item:null,amount:-1,invIdx:-1};this.prepareEntities();this.invBar=new kb(this,c,{inv:this.party.inv,offset:function(a){return b.r.layout("center bottom",a.getSize())},onCheckItem:this.useItem,onTrashItem:this.trashItem,canUseItemFn:this.isUsableItem.bind(this),owned:!0});this.diary=new ha(this.r,this.sfx,this);this.events.diary=this.diary;this.barter=new sa(this,c);n.isIO()||(this.gallery=this.initMainState("gallery",La),this.celebration=
this.initMainState("celebration",Ja),this.worldmap=this.initMainState("worldMap",wa),this.ranking=this.initMainState("ranking",va),this.harbor=this.initMainState("harbor",Nb),this.narrator=this.initMainState("narrator",ta),this.epilogue=this.initMainState("epilogue",ob));this.challenge=new Z(this.r,this.sfx,this);this.showingStats=this.showingOutro=this.showingBarter=this.showingBiomes=!1;this.hideEventAlert(!1);this.gameStartDate=Date.create();null!=(null!=(d=this.sfx)?d.bgMusic:void 0)&&this.sfx.bgMusic.loop().play();
this.mainMenu.hide();this.gameCount+=1;if(n.isIO())return r.info("IO;Initting new ce.io world with seed "+this.iomp.worldData.worldSeed),a=t.getWorld(config.io.worldID),null==this.worldGenIO?this.worldGenIO=new Td(this,a,this.iomp.worldData.worldSeed):this.worldGenIO.reset(a,this.iomp.worldData.worldSeed);if(a)return this.sfx.play("campClose")};C.prototype.prepareEntities=function(){var a=this,b;if(this.entitiesDirty)if(config.showMods&&!this.modding.modsLoaded)this.modding.onLoadedFn=function(){return a.prepareEntities()};
else{r.header("--== PREPARING ENTITIES ==--");this.entitiesDirty=!1;var c=function(a){t.parseEntityData(a);var b=function(){switch(a.id.slice(0,3)){case "ex-":return config.expeditions;case "tl-":return config.tiles;case "evt":return config.events;case "loc":return config.locations;case "act":return config.actions;case "gol":return config.goals;case "grp":return config.groups;case "pck":return config.pockets;case "bio":return config.biomes;case "it-":return config.items;case "zn-":return config.zones;
case "cl-":return config.chatLines;case "tg-":return config.tribeGens;case "tgl":return config.tribeGenLayers;case "il-":return config.itemList;case "spr":return config.sprawls;case "df-":return config.diceFaces;case "dp-":return config.dicePattern;case "pt-":return config.particles;case "dc-":return config.dice;case "buf":return config.buffs;case "wd-":return config.worlds;case "na-":return config.names;case "np-":return config.namePools;case "st-":return config.statuses;case "btn":return config.buttons;
case "ch-":case "sp-":case "anm":case "npc":case "pl-":case "emy":return config.characters;case "pac":return config.packs;default:return r.error("Entity with unknown type identifier '"+a.id.slice(0,3)+"': "+a.id,a.mod)}}();null!=b&&(Object.isArray(b)?(b.find(function(b){return b.id===a.id})&&r.error("Found duplicate ID "+a.id+"!",a.mod),b.push(a)):(null!=b[a.id]&&r.error("Found duplicate ID "+a.id+"!",a.mod),b[a.id]=a));if(b===config.particles&&null!=a.mainParticle&&a.mainParticle)return config.particle[a.id.slice(3)]=
a};this.sfx.stopAll();this.r.img.restoreOverwrittenSprites();var d={};var e=config.slots;var f=0;for(b=e.length;f<b;f++){var g=e[f];n.assert(null==d[g.id]);d[g.id]=g}config.slots=d;config.expeditions={};config.tiles={};config.events={};config.locations={};config.actions={};config.goals={};config.groups={};config.pockets={};config.biomes={};config.items={};config.statuses={};config.zones={};config.chatLines={};config.tribeGens={};config.tribeGenLayers={};config.items={};config.itemList={};config.sprawls=
{};config.particles={};config.particle={};config.dice={};config.buffs={};config.characters={};config.statuses={};config.worlds={};config.diceFaces={};config.dicePattern=[];config.names={};config.namePools={};config.buttons={};config.packs={};Object.merge(window.config,this.restoreBackupConfig());"en"===this.getLangId()&&(config.locTexts=config.enTexts);this.r.img.restoreOverwrittenSprites();b=[];d=this.modding.activeMods();f=0;for(e=d.length;f<e;f++)g=d[f],g.modLog("Applying mod"),b.push(g.id),g.applyImages(!0),
g.applyEntries(),g.applyLangs(),Object.merge(config,g.configSettings,{deep:!0}),this.contentDirty=!0;e=[];g=this.r.img.sprites;for(h in g)d=g[h],null==d.mod||b.includes(d.mod.id)||e.push(h);b=0;for(g=e.length;b<g;b++){var h=e[b];delete this.r.img.sprites[h]}b=config.entities;for(k in b)h=b[k],c(h);if(null!=config.testEvents){e=config.testEvents;var k=0;for(b=e.length;k<b;k++)h=e[k],c(h)}t.createEventCIDs();Object.merge(config,staticConfig);this.convertSlotColors();null!=this.pixelScaleSetting&&this.setupFonts();
this.contentDirty&&debug.showDebugBar&&null!=this.mainMenu&&this.mainMenu.createDebugBar();this.dataDirty=!0;return this.checkData()}};C.prototype.checkData=function(){if("undefined"===typeof debug||null===debug||!debug.isDevMode)if(!n.isTCE()||0===this.modding.activeMods())return;if(config.sanityCheckEvents&&this.dataDirty)if(1<=this.r.img.getLoadState()){r.header("--== CHECKING DATA ==--");this.dataDirty=!1;var a=new ua(this);a.checkRefs();a.checkAllItems();a.checkCharacters();a.checkDice();a.checkTiles();
n.isIO()&&a.checkAllPacks();var b=[];a.checkLang("en",config.enTexts,b);config.locTexts!==config.enTexts&&a.checkLang(this.getLangId(),config.locTexts,b);a.checkSounds();if(this.didShowLoadingBar)return $("#boot").hide(),$("#gameContent").show(),this.didShowLoadingBar=!1}else if(null==this.r.img.onLoadedFn)return this.r.img.attachOnAllLoadedHandler(this.checkData),O.updateLoadingBar(),$("#boot").show(),$("#gameContent").hide(),this.didShowLoadingBar=!0};C.prototype.createRivals=function(){var a=this;
var b=this.party.getExplorer();var c=Object.values(config.characters).filter(function(c){var d;return c.id.startsWith("sp")&&null!=c.name&&c.id!==b.id&&(null==c.unlockPin||(d=c.id,0<=F.call(a.mainMenu.unlockedChars,d)))});var d=config.rivals.scoring.slice(0,config.rivals.count).randomize();var e=c.sample(config.rivals.count);var f=[];var g=0;for(c=e.length;g<c;g++){var h=e[g];f.push({character:new Fa(this,h.id),fame:10,newFame:0,fameScale:d.shift()})}return f};C.prototype.convertSlotColors=function(){var a;
var b=function(a){var b=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(a);return null!=b?[parseInt(b[1],16),parseInt(b[2],16),parseInt(b[3],16)]:a};var c=config.slotColors;for(a in c){var d=c[a];config.slotColors[a]=b(d)}};C.prototype.restoreBackupConfig=function(){if(null!=this.configBackup)return Object.clone(this.configBackup,!0);if("undefined"!==typeof config&&null!==config)return this.configBackup=Object.clone(config,!0),config};C.prototype.getPartyRank=function(){var a=this;return this.rivals.include(this.party).sortBy(function(a){return a.fame},
!0).findIndex(function(b){return a.party.fame>=b.fame})};C.prototype.getBestExplorer=function(){var a;var b=this.rivals.include(this.party).max(function(a){return a.fame});return null!=(a=b.character)?a:b.persons[0]};C.prototype.startGame=function(){r.info("GAME;started");this.prepareGame();this.setAllHUD(!0);this.mainMenu.totalGames+=1;this.debugLocationCounts=[];this.diaryLogEntries=debug.outputDiaryLog?[]:null;return this.gotoGallery()};C.prototype.startIO=function(){var a=this;"undefined"!==typeof debug&&
null!==debug||this.mainMenu.resetDebug();this.iomp.main=this;this.ioInv=new Ud(this);this.r.sfx.preloadSounds();this.r.setImageSmoothing(!1);if(null!=this.user&&null==this.user.get("displayName")){var b=.5>J.rng.random()?"beastMale":"beastFemale";this.user.set("displayName",q.createName(b));this.user.save().then(function(b){a.user=b;a.iomp.parseUser=b;a.iomp.addParseUserToDB(a.user);return a.iomp.refreshLocalUserOnServer()})}this.difficultyLvl=1;this.worldLvl=0;return this.mainMenu.saveGame.loading?
this.mainMenu.saveGame.onSaveGameLoaded=this.loadOrStartIOGame:this.loadOrStartIOGame()};C.prototype.loadOrStartIOGame=function(){if(null==this.mainMenu.saveGame.sg||debug.startNewIOGame)return this.initNewIOGame();if(!this.continueGame())return r.error("ContinueGame failed; starting new game"),this.initNewIOGame()};C.prototype.initNewIOGame=function(){var a=this;this.difficultyLvl=1;this.prepareGame(!1);this.pushWorld(this.worldGenIO.world);this.tutorial=null;this.setAllHUD(!0);this.party.funds=
config.funds[this.difficultyLvl];Object.values(config.characters).filter(function(a){return a.id.startsWith("sp")&&null!=a.name&&null==a.unlockPin});var b=t.getCharacter(config.io.explorerID);this.exped=null;var c=function(c){b=t.getCharacter(c);var d=[];var e=t.arrify(b.characters);var h=0;for(c=e.length;h<c;h++){var k=e[h];k=new Fa(a,k);null!=k.id&&(a.doRandEvent(k.spawnEvents,{person:k,silent:!0}),d.push(k))}return d}(b.id);this.party.setExplorer(b.id,c);c=this.party.getExplorer();if(null!=this.user)c.name=
this.user.get("displayName");else{var d=.5>J.rng.random()?"beastMale":"beastFemale";c.name=q.createName(d)}d=this.ioInv.getAllStoredExplorers();null!=d&&0<d.length?(d=d.sample(),c.setVariationWithGender(d.explorerGender),c.initCharGen(d.explorerTribe,d.explorerSeed)):(c.initCharGen(config.io.explorerGen.sample()),r.info("IO;Chosen explorer tg "+c.sourceTribeGenId));this.rivals=[];this.iomp.resetForNewGame();this.mainMenu.saveGame.clearSaveGame();this.gameOver=!1;this.hasMainState("preRoll")||(0===
this.mainStates.length?this.setMainState("iosplash"):(this.setMainState("ionewgame"),this.ioNewGame.initNewParty()))};C.prototype.startNewIOGame=function(a){a=void 0===a?0:a;r.info("Starting new IO game at hub "+a);this.worldGenIO.startNewGame(a);this.iomp.resetForNewGame();this.party.stats.IOStart=a;this.isNewGameLoading=!0;return this.gotoLoading()};C.prototype.startDemo=function(){var a;"undefined"!==typeof debug&&null!==debug||this.mainMenu.resetDebug();this.r.sfx.preloadSounds();this.setAllHUD(!0);
this.setPixelScale(2,!0);return this.startNewDemoGame(null!=(a=debug.demoSeed)?a:0)};C.prototype.startNewDemoGame=function(a){this.setAllHUD(!0);this.prepareGame(!1);if(null==a||0===a)a=Date.now();ba.rng=new pa(a);r.info("DEMO;Initting demo with seed "+ba.rng._initialSeed);var b=Object.values(config.characters).filter(function(a){return a.id.startsWith("sp")&&null!=a.name&&null==a.unlockPin&&a.alwaysUnlocked}).worldGenSample();r.info("DEMO;Chosen explorer "+b.id);var c=this.gallery.createTrek(b.id);
this.party.setExplorer(b.id,c);this.rivals=this.createRivals();this.worldLvl=this.difficultyLvl=0;this.party.funds=config.funds[this.difficultyLvl];c=t.getWorld(this.getExpeditionWorld(this.worldLvl));b=c.pockets.worldGenSample();r.info("DEMO;Chosen pocket "+b);this.worldmap.sites=[this.worldmap.createSite(a,c,b)];this.worldmap.rivalSites=this.worldmap.createRivalSites();this.worldmap.worldSelection=this.worldmap.sites[0];this.worldGen=this.worldmap.worldSelection.gen;this.pushWorld(this.worldGen.world);
this.worldmap.sites=null;this.tribeGen.setup(this.worldGen.world.tribeGen);this.tribeGen.genColorTable();this.tribeGen.genKeyTable();return this.gotoLoading()};C.prototype.startExplorerWheel=function(){var a=this;this.displayingExplorerWheel=!0;this.explorerWheelChars=Object.values(config.characters).filter(function(b){return b.id.startsWith("sp")&&null!=b.name&&null==b.unlockPin&&b.alwaysUnlocked&&b.id!==a.party.getExplorer().id}).randomize().slice(0,4);var b=t.getCharacter(this.party.getExplorer().id);
this.explorerWheelChars.push(b);this.explorerWheelIdx=1;this.explorerWheelTime=0;this.explorerTargetIndex=this.explorerWheelChars.indexOf(b);return this.remainingSpins=this.explorerWheelChars.length};C.prototype.drawExplorerWheel=function(){var a,b,c;var d=42*this.s;var e=Math.min(this.explorerWheelTime,1);0===this.remainingSpins&&this.explorerWheelIdx%this.explorerWheelChars.length===this.explorerTargetIndex&&(e=Math.min(this.explorerWheelTime,.5));var f=this.r.createCanvas(32*this.s,42*this.s);
var g=f.canvas.width/2;var h=f.canvas.height-1.5*d;h+=Math.floor(e*d);var k=c=a=this.explorerWheelIdx+1;for(b=this.explorerWheelIdx-1;a<=b?c<=b:c>=b;k=a<=b?++c:--c){var l=k%this.explorerWheelChars.length;var m=this.explorerWheelChars[l];l=1;k===this.explorerWheelIdx+1?l=e:k===this.explorerWheelIdx-1&&(l=1-e);f.globalAlpha=l;this.r.drawSprite(m.variations[0].portrait,g,h,{halign:"center",valign:"bottom",ctx:f});h+=d}d=$jscomp.makeIterator(this.r.getCanvasSize());g=d.next().value;d=d.next().value;g/=
2;h=d/2+100*this.s;this.r.ctx.globalAlpha=1;this.r.drawSprite("hud_char_frame.png",g,h,{halign:"center",valign:"center"});this.r.ctx.drawImage(f.canvas,g-f.canvas.width/2,h-f.canvas.height/2-1);l=this.explorerWheelIdx%this.explorerWheelChars.length;return this.r.drawText(q.toText(this.explorerWheelChars[l].name),g,h+45*this.s,{halign:"center",font:config.fonts.themedLarge})};C.prototype.startTutorial=function(){this.rivals=[];this.difficultyLvl=0;this.toggleCombatAutoselect(!1);this.prepareGame();
this.setAllHUD(!1);this.tutorial=new fb(this.r,this.sfx,this);this.isNewGameLoading=!0;this.sfx.play("campClose");this.party.addCharacter(config.tutorial.character);return this.prepareTutorialWorld()};C.prototype.prepareTutorialWorld=function(){this.sfx.fadeOut("titleMusic").fadeOut("clubMusic");this.party.reset();var a=config.tutorial.worlds[this.worldLvl];var b=t.arrify(t.getWorld(a).pockets).sample();var c=t.arrify(t.getPocket(b).goals).sample();return this.prepareWorld(new ba(this,a,b,c,!1))};
C.prototype.continueGame=function(){if(null==this.mainMenu.saveGame.getInfo())return!1;this.sfx.fadeOut("titleMusic");this.setAllHUD(!0);this.prepareGame();this.tutorial=null;try{var a=this.mainMenu.saveGame.restoreSaveGame();if(!a)return!1}catch(b){return a=b,this.doSendError(a.message+" _ "+a.stack,this.mainMenu.saveGame.sg),!1}n.isIO()?this.hasMainState("preRoll")||this.setMainState("iosplash"):null!=this.exped?this.gotoGame():this.gotoWorldMap();this.updateActions();this.r.introTime=0;r.info("Continue game OK");
n.isIO()||this.playMusic("sfx_startExpedition_1");return!0};C.prototype.debugContinueGame=function(){this.setAllHUD(!0);this.prepareGame();this.tutorial=null;var a=JSON.parse(atob(decodeURIComponent(debug.saveGame)));this.mainMenu.saveGame.restoreSaveGame(a);null!=this.exped?this.gotoGame():this.gotoWorldMap();this.updateActions();return!0};C.prototype.gotoGame=function(){var a;this.wasLoadingBeforeGame="loading"===this.getMainState();this.setMainState("game");this.updateActions();if(null!=this.mainMenu.saveGame.autoBegin){if(null!=
this.mainMenu.saveGame.autoBegin.action)this.doAction(this.mainMenu.saveGame.autoBegin.action);else if(null!=this.mainMenu.saveGame.autoBegin.event){var b={};null!=this.mainMenu.saveGame.autoBegin.zone&&null!=(null!=(a=this.world)?a.zones:void 0)&&(b.zone=this.world.zones[this.mainMenu.saveGame.autoBegin.zone]);this.doEvent(t.getEvent(this.mainMenu.saveGame.autoBegin.event),b)}else null!=this.mainMenu.saveGame.autoBegin.zone&&(b=this.world.zones[this.mainMenu.saveGame.autoBegin.zone],null!=b&&this.exped.doZoneEvent(b,
this.mainMenu.saveGame.autoBegin.enemyAttacks));return this.mainMenu.saveGame.autoBegin=null}};C.prototype.selectExplorer=function(a,b){this.sfx.play("campClose");this.party.setExplorer(a,b);this.rivals=this.createRivals();this.mainMenu.onSelectExplorer(a);this.mainMenu.saveGame.clearSaveGame();return this.gotoNarrator()};C.prototype.gotoGallery=function(){return this.setMainState("gallery")};C.prototype.gotoPreRoll=function(){return this.setMainState("preRoll")};C.prototype.gotoMainMenu=function(){this.setMainState("mainMenu");
null==this.debugRestore&&(this.debugRestore=Object.clone(debug));window.debug=Object.clone(this.debugRestore);"undefined"!==typeof debug&&null!==debug&&this.modding.active&&Object.merge(debug,this.modding.debugOptions);this.difficultyLvl=this.tutorial=this.exped=null;var a=this.sfx.getSound("titleMusic");if(null==a||!a.isPlaying())return a=this.sfx.getSound("clubMusic"),(a=null!=a&&a.isPlaying())?this.sfx.fadeOut("clubMusic"):this.sfx.stopAll(),this.sfx.play("titleMusic",!0)};C.prototype.selectDifficulty=
function(a){this.sfx.play("campClose");this.difficultyLvl=null!=a?a:1;this.party.funds=config.funds[this.difficultyLvl];return this.gotoWorldMap()};C.prototype.gotoWorldMap=function(){"mainMenu"===this.getMainState()&&this.sfx.fadeOut("titleMusic").play("clubMusic",!0);return this.setMainState("worldMap")};C.prototype.gotoTaxonomy=function(){return this.setMainState("taxonomy")};C.prototype.gotoTribeGen=function(){return this.setMainState("tribeGen")};C.prototype.gotoRivals=function(){return window.isElectron?
n.openInternalLink("/play-electron-io.html"):n.openInternalLink("/io")};C.prototype.refreshWindow=function(){return window.refreshWindow()};C.prototype.gotoTCE=function(){var a;this.canSave()&&null!=(a=this.party)&&a.isInventoryChangedSinceSave&&this.mainMenu.saveGame.updateSaveGame();return this.queuedReturnToTCE=!0};C.prototype.beginQuit=function(){var a;this.canSave()&&null!=(a=this.party)&&a.isInventoryChangedSinceSave&&this.mainMenu.saveGame.updateSaveGame();return this.queuedQuitToDesktop=!0};
C.prototype.gotoRivalsAccount=function(){return window.isSteam?n.openInternalLink("/io_account_steam.html"):n.openInternalLink("/io_account.html")};C.prototype.getTribeGenAtPartyPos=function(){var a,b;return n.isIO()&&0<this.mainStates.length&&("ionewgame"===(a=this.getMainState())||"iosplash"===a)?(a=this.worldGenIO.unlockedHubs[this.ioNewGame.startUnlockedHubIdx],this.worldGenIO.getBiomeTribeGen(this.worldGenIO.biomes[a].pos)):n.isIO()&&this.world===this.worldGenIO.world?(n.assert(null!=(null!=
(b=this.party)?b.pos:void 0)),a=this.world.toBiomePos(this.party.pos),this.worldGenIO.getBiomeTribeGen(a)):this.tribeGen};C.prototype.updateForNewPartyPos=function(){var a,b;this.updateAmbientSound();if(n.isIO()&&!this.isWarping()&&null!=this.exped&&null!=this.world&&null!=this.party&&null!=this.party.pos){var c=this.world.toBiomePos(this.party.pos);c=this.worldGenIO.getBiomeDict(c);var d=c.worldSegment;d!==this.exped.lastSegmentID&&this.exped.displayNewSegment(d);null!=(null!=(a=c.claim)?null!=(b=
a.user)?b.displayName:void 0:void 0)&&this.displayClaimNotification(c.biomeIdx);this.iomp.setupGhostsQuery(c.biomeIdx)}};C.prototype.displayClaimNotification=function(a){var b;if(!this.party.notifiedClaims.includes(a)){var c=this.worldGenIO.biomes[a];if(null!=(null!=(b=c.claim)?b.user:void 0))return this.party.notifiedClaims.push(a),a=q.toText("txt-io-claim")+" "+c.claim.user.displayName,this.notifications.addLine("claim",a,{claim:c.claim})}};C.prototype.updateAmbientSound=function(){var a;var b=
t.getPocket(this.world.pocketId);null==b&&null!=(null!=(a=this.party)?a.pos:void 0)&&(b=this.world.toLocalPos(this.party.pos)[0],n.assert(null!=b),b=this.worldGenIO.getBiomeDict(b.pos),n.assert(null!=b),b=t.getPocket(b.pocketID));this.ambientSound=null!=b?this.sfx.getSound(b.ambientSound,!0):null};C.prototype.pushWorld=function(a){var b;null!=this.world&&(null==(b=this.world).warpPos&&(b.warpPos=this.party.pos),null==(b=this.world).warpStanding&&(b.warpStanding=this.party.standing));this.worldStack.push(a);
this.world=a;null!=(b=this.exped)&&(b.world=a);this.updateForNewPartyPos();return r.header("--== PUSHING WORLD: seed:"+a.worldSeed+" difficulty:"+this.difficultyLvl+" pocketId:"+a.pocketId+" worldId:"+a.id+"  ==--")};C.prototype.warpWorld=function(a){n.isIO()&&null!=this.exped&&this.exped.sendLegCache();var b=t.getWorld(a);b=t.arrify(b.pockets).sample();a=new ba(this,a,b,null,!0);this.prepareWorld(a);this.party.pos=null;this.party.standing=0;return this.wasLoadingBeforeGame=!1};C.prototype.unwarpWorld=
function(){var a;if(1>=this.worldStack.length)this.doSendError("invalid unwarp");else{this.worldStack.pop();this.world=this.worldStack.last();this.worldGen=this.world.gen;this.exped.world=this.world;var b=t.getPocket(this.world.pocketId);this.ambientSound=null!=b?this.sfx.getSound(b.ambientSound,!0):null;n.assert(null!=this.world.warpPos);n.isIO()&&this.world===this.worldGenIO.world&&this.worldGenIO.generateBiome(this.worldGenIO.world.toBiomePos(this.world.warpPos));this.party.pos=this.world.warpPos;
this.party.standing=null!=(a=this.world.warpStanding)?a:0;this.world.warpPos=null;this.world.warpStanding=null;this.r.cam.centerOnPos(this.party.pos);this.r.introTime=0;return this.wasLoadingBeforeGame=!1}};C.prototype.prepareWorld=function(a){this.sfx.play("campClose");this.infoBox.hide();debug.testPocket=null;this.worldGen=a;this.pushWorld(a.world);this.tribeGen.setup(a.world.tribeGen,a.worldSeed);this.tribeGen.genColorTable();this.tribeGen.genKeyTable();debug.autoLevel&&!this.isWarping()&&this.autoLevelParty();
return n.isIO()||this.isWarping()||debug.skipStartEvents||0<debug.testLocationCount||null!=this.tutorial?this.gotoLoading():this.gotoHarbor()};C.prototype.autoLevelParty=function(){var a,b,c;this.party.getExplorer().setLevel(this.worldLvl);var d=c=0;for(a=this.worldLvl;0<=a?c<a:c>a;d=0<=a?++c:--c)if(d="wd-world-"+(d+1),d=config.worlds[d]){this.party.changeXP(d.debugXP);d=this.party.persons.filter(function(a){return!a.isSpecial&&!a.flags.animal}).sample();null!=d&&.2>Math.random()&&this.party.removeCharacter(d);
if(null==d||.4>Math.random()&&0<this.party.getFreeUnitCount())d=Object.values(config.characters).filter(function(a){return a.id.startsWith("pl-")}),this.party.addCharacter(d.sample().id);var e=this.party.persons;var f=0;for(d=e.length;f<d;f++){var g=e[f];this.party.levelUp(g)}d=["il-common","il-magic","il-tomePages"].sample();d=t.getItemList(d);g=this.randItemSet(d.items.sample());d=0;for(f=g.length;d<f;d++)e=g[d],this.party.inv.changeItemCount(e.id,1);var h=this.party.getExplorer();d=Object.values(config.statuses).filter(function(a){return a.isPerk&&
!h.hasStatus(a.id)}).sample().id;h.setStatus(d)}a=t.getPocket(this.world.pocketId);if(null!=a.debugItems){c=a.debugItems;d=[];for(b in c)a=c[b],d.push(this.party.inv.changeItemCount(b,a));return d}};C.prototype.gotoHarbor=function(){this.r.introTime=0;this.r.hudIntroTime=0;this.stopMusic(!0);this.sfx.fadeOut("clubMusic");this.setMainState("harbor");return this.doEvent(t.getEvent(config.specialEvents.harbor))};C.prototype.gotoCelebration=function(){this.r.introTime=0;this.r.hudIntroTime=0;this.r.setPureMode(!1);
this.stopMusic(!0);return this.setMainState("celebration")};C.prototype.gotoIOPromote=function(){this.r.introTime=0;this.r.hudIntroTime=0;this.r.setPureMode(!1);this.stopMusic(!0);return this.setMainState("iopromote")};C.prototype.gotoRanking=function(){this.setMainState("ranking");return this.outroItems=[]};C.prototype.gotoHighScore=function(){return n.isIO()?this.setMainState("iohighscore"):this.setMainState("highscore")};C.prototype.gotoLoading=function(){logs.worldgen&&r.header("--== BUILDING WORLD ==--");
this.r.introTime=0;this.r.hudIntroTime=0;this.stopMusic(!0);this.sfx.fadeOut("clubMusic").fadeOut("titleMusic");return this.setMainState("loading")};C.prototype.gotoNarrator=function(){return this.setMainState("narrator")};C.prototype.resetExped=function(a){a=void 0===a?!0:a;this.r.setPureMode(!1);this.worldDone=this.showingStats=this.showingOutro=!1;this.lastMusic=null;this.exped=new M(this,this.world,this.party,this.events,this.r,this.sfx);a&&this.exped.resetRivals();this.diary.changeTime=0;this.r.onStartWorld();
return this.exped};C.prototype.isWarping=function(){return 1<this.worldStack.length};C.prototype.checkDebugLocationCount=function(){var a,b;if(0>=(null!=(a=debug.testLocationCount)?a:0))return!1;a=this.world.getBiomes().map(function(a){return a.locations.filter(function(a){return a.hintBiome}).map(function(a){return t.getLocation(a.id).debugCategory})}).compact().flatten();this.debugLocationCounts.push(n.count(a));if(this.debugLocationCounts.length>=debug.testLocationCount){r.info("==== Location STATS ====");
r.info("iterations: "+this.debugLocationCounts.length+", world: "+this.worldLvl+", pocket: "+this.world.pocketId+", difficulty: "+this.difficultyLvl);var c=this.debugLocationCounts.map(function(a){return Object.keys(a)}).flatten().unique().sortBy();var d=0;for(b=c.length;d<b;d++){var e=c[d];var f=this.debugLocationCounts.sum(function(a){var b;return null!=(b=a[e])?b:0});a=f/this.debugLocationCounts.length;var g=this.debugLocationCounts.map(function(a){var b;return null!=(b=a[e])?b:0}).min();var h=
this.debugLocationCounts.map(function(a){var b;return null!=(b=a[e])?b:0}).max();var k=this.debugLocationCounts.map(function(a){var b;return null!=(b=a[e])?b:0}).sortBy()[Math.round(this.debugLocationCounts.length/2)];var l=e.padLeft(30)+" |";l+=" total: "+f.format(0).padLeft(4)+" |";l+=" min: "+g.format(0).padLeft(4)+" |";l+=" max: "+h.format(0).padLeft(4)+" |";l+=" avg: "+a.format(1).padLeft(4)+" |";l+=" median: "+k.format(0).padLeft(4)+" |";r.info(l)}}this.debugRegenWorld();return!0};C.prototype.debugRegenWorld=
function(){if(n.isIO()){this.iomp.worldData.worldSeed+=1337;this.world=null;this.worldStack=[];var a=t.getWorld(config.io.worldID);this.worldGenIO.reset(a,this.iomp.worldData.worldSeed);this.worldGenIO.generateBiome(this.worldGenIO.world.toBiomePos(this.party.pos));this.pushWorld(this.worldGenIO.world);n.assert(null!=this.world);return this.exped.updateVisibility()}this.party.reset();this.worldStack=[];a=new ba(this,this.world.id,this.world.pocketId,this.world.goalId);return this.prepareWorld(a)};
C.prototype.startWorld=function(){var a;if(!this.checkDebugLocationCount()){if(null!=debug.testWorldValidation){var b=this.fillEventCtx({pos:this.world.startPos});var c=t.getEvent(debug.testWorldValidation);if(this.events.hasRequirements(c,b)){this.debugRegenWorld();return}r.info("world validation failed");debugger}r.info("START-WORLD;"+this.worldLvl);c=this.isWarping();c||(this.resetExped(),this.mainMenu.onNextWorld());var d=this.world.getBiomes();var e=0;for(a=d.length;e<a;e++)b=d[e],null!=b.spawnEvents&&
this.doRandEvent(b.spawnEvents,{pos:b.getCenter(),silent:!0});this.notifications.clear();this.exped.onStartWorld();this.gotoGame();if(c){a=this.world.getBiomes();d=0;for(c=a.length;d<c;d++){b=a[d];var f=b.tiles;b=0;for(e=f.length;b<e;b++){var g=f[b];g.known=!0;g.visibleTime=100}}this.doEvent(t.getEvent(config.specialEvents.worldStartWarped),{silent:!0})}else this.doEvent(t.getEvent(config.specialEvents.worldInit),{silent:!0}),this.party.changeStanding(this.party.getBonus("startStanding")),n.isIO()&&
null==this.tutorial?this.chat.setEnabled(!0):debug.skipStartEvents?this.chat.setEnabled(!0):this.doDelayedEvent(t.getEvent(config.specialEvents.worldStart),{},q.toText("txt-base-alert"));if(n.isIO()&&null==this.tutorial)return this.saveGameOnStart&&this.mainMenu.saveGame.updateSaveGame(),this.saveGameOnStart=!1}};C.prototype.endWorld=function(a){a=void 0===a?!0:a;var b;if(n.isDemo()&&null!=this.tutorial)this.tutorial=null,null!=this.mainMenu.saveGame.sg?this.continueGame():this.startNewDemoGame();
else{this.worldDone=!0;a||(this.world.goalFame=0);this.exped.updateStats();this.transferStashes();var c=this.rivals;var d=0;for(b=c.length;d<b;d++){var e=c[d];null==e.arrivedTurn&&(e.arrivedTurn=this.exped.turn+(this.world.rivalTurns-e.turn))}return this.showOutro(!0,a?"Success":"Escaped")}};C.prototype.transferStashes=function(){var a,b;var c=this.world.getLocations();var d=[];var e=0;for(a=c.length;e<a;e++){var f=c[e];f.hasStash&&d.push(null!=(b=f.invs.stash)?b.transfer(this.party.inv):void 0)}return d};
C.prototype.getExpeditionWorld=function(a){var b;var c=[];var d=Object.values(config.expeditions);var e=0;for(b=d.length;e<b;e++){var f=d[e];n.match(f.range,a)&&c.push(f)}return t.arrify(c.sample().worlds).worldGenSample()};C.prototype.hasCampaign=function(){return this.worldLvl<config.maxExpedition};C.prototype.hasExtraCampaign=function(){return!1};C.prototype.gotoNextWorld=function(){this.worldLvl+=1;this.restoredSaveGame=null;this.exped.updateStats();this.worldStack=[];return null!=this.tutorial?
this.prepareTutorialWorld():this.gotoWorldMap()};C.prototype.getMouseTile=function(){if(null!=this.exped.mouseTilePos)return this.world.getTile(this.exped.mouseTilePos)};C.prototype.addDebugWatch=function(a){return this.r.debugWatches.push(a)};C.prototype.clearDebugWatch=function(){return this.r.debugWatches=[]};C.prototype.onMouseWheel=function(a){var b,c;a.stopPropagation();a.preventDefault();if(!this.waitingForDemoStart&&!this.displayingExplorerWheel)if(navigator.userAgent.includes("Safari")&&
!navigator.userAgent.includes("Chrome"))(b=0!==a.deltaX||J.isInteger(a.deltaY))?this.handlePanEvent(a.deltaX,a.deltaY):this.handleScrollWheelEvent(null!=(c=a.wheelDelta)?c:a.deltaY);else return c=null!=(b=a.wheelDelta)?b:a.deltaY,a.ctrlKey?(this.handleScrollWheelEvent(c),this.didEverUseTrackpad=!0):0!==a.deltaX?(this.handlePanEvent(a.deltaX,a.deltaY),this.didEverUseTrackpad=!0):this.didEverUseTrackpad?this.handlePanEvent(a.deltaX,a.deltaY):this.handleScrollWheelEvent(c)};C.prototype.handleScrollWheelEvent=
function(a){var b;if(null!=(b=this.exped))b.onMouseWheel(a);this.modding.onMouseWheel(a);if("ionewgame"===this.getMainState())return this.ioNewGame.onMouseWheel(a)};C.prototype.handlePanEvent=function(a,b){var c;return null!=(c=this.exped)?c.onMousePan(a,b):void 0};C.prototype.onScroll=function(a){var b;if(!this.waitingForDemoStart&&!this.displayingExplorerWheel)return null!=(b=this.exped)?b.onScroll(a):void 0};C.prototype.getDefaultScalingFactor=function(a){var b=1;a?(640<window.innerWidth&&360<
window.innerHeight&&(b=2),1280<window.innerWidth&&720<window.innerHeight&&(b=3),1920<window.innerWidth&&1080<window.innerHeight&&(b=6)):(1280<=window.innerWidth&&720<=window.innerHeight&&(b=2),1920<=window.innerWidth&&1080<=window.innerHeight&&(b=3),3840<=window.innerWidth&&2160<=window.innerHeight&&(b=4));return b};C.prototype.setLowGraphicsMode=function(a){this.lowGraphics=a;n.canUseLocalStorage()&&window.localStorage.setItem("lowGraphics",this.lowGraphics);return this.graphicsSettings=this.lowGraphics?
config.lowGraphicsSettings:config.normalGraphicsSettings};C.prototype.onLoadedImgs=function(){var a;this.checkData();var b=!0;var c=this.getDefaultScalingFactor(b);var d=!window.GPUCanvas;n.canUseLocalStorage()&&(null==window.localStorage.getItem("pixelScale")||isNaN(window.localStorage.getItem("pixelScale"))||(c=null!=(a=parseInt(window.localStorage.getItem("pixelScale")))?a:c),null!=window.localStorage.getItem("scaling")&&(b="true"===window.localStorage.getItem("scaling")),null!=window.localStorage.getItem("lowGraphics")&&
(d="true"===window.localStorage.getItem("lowGraphics")),null==window.localStorage.getItem("doneGPUCheck")&&(window.localStorage.setItem("doneGPUCheck",!0),window.GPUCanvas||(c=this.getDefaultScalingFactor(!1),d=!0)));if(window.isClient)try{var e=require("electron").remote;var f=e.process.argv;f.includes("-stretch")&&(b=!0)}catch(g){}this.setPixelScale(c,b);this.setLowGraphicsMode(d);n.isDemo()?this.startDemo():this.gotoPreRoll();n.isIO()&&this.startIO();this.draw();$("#boot").hide();$("#gameContent").show();
if(debug.logGeneralRenderStats)return this.numSkippedDraws=0,this.addDebugWatch(this.getRenderStats)};C.prototype.getRenderStats=function(){if(null==this.r)return[];null==this.numSpritesDraw&&(this.numSpritesDraw=0);null==this.numSkippedDraws&&(this.numSkippedDraws=0);null==this.numParticlesRendered&&(this.numParticlesRendered=0);null==this.numTextDraw&&(this.numTextDraw=0);null==this.numPixDraw&&(this.numPixDraw=0);return["fps "+Math.round(1/this.r.timeDelta),"sprites: "+this.numSpritesDraw,"Pixels "+
this.numPixDraw.toLocaleString(),"culled: "+this.numSkippedDraws,"particles: "+this.numParticlesRendered,"texts "+this.numTextDraw]};C.prototype.drawItemInfo=function(){if(null!=this.showItemInfo){var a=this.showItemInfo;return this.infoBox.showItem(a.item,a.owned,a.priceTable,a.usable)}};C.prototype.drawDiary=function(a,b,c){var d,e,f;var g="celebration"===(e=this.getMainState())||"iosplash"===e||"ionewgame"===e||"iotransact"===e||"iopromote"===e;e=$jscomp.makeIterator(this.diary.drawDiary(this.diaryScrollX,
this.showingEventAlert&&!(null!=(d=this.exped)&&d.isTraveling()),this.events.showingEventDialogue,this.diaryBumpTime,this.showingChallenge||this.showingBarter,g,a,b,c));d=e.next().value;e=e.next().value;if(!g)return g=!1,this.showingBarter&&this.barter.draw(a,b,c),this.events.showingEventDialogue||(this.diaryPersonPinned=null),this.showingChallenge&&(c=this.challenge.draw(a,b,c),null==e&&(e=c)),null!=this.diaryPersonPinned&&(c=this.diary.showImage.showMounted?null!=(f=this.diaryPersonPinned.mounted)?
f:this.diaryPersonPinned:this.diaryPersonPinned,c=$jscomp.makeIterator(this.diary.transformSlotToScreen(c.eventPos).lst()),f=c.next().value,c=c.next().value,null!=this.diaryPersonPinned.id&&(c=$jscomp.makeIterator([f,c-40*this.s]),f=c.next().value,c=c.next().value,this.r.hitBox(f-100,c,100*this.s,40*this.s,a,b)&&(g=!0),this.r.drawCharacterInfo(this.diaryPersonPinned,f,c,a,b,{showActions:!1,showAttributes:!0,valign:"bottom",halign:"center"})&&(g=!0))),null==e?(this.diaryPersonHover=null,this.diaryPersonHoverTime=
-1):e!==this.diaryPersonHover&&(this.diaryPersonHover=e,this.diaryPersonHoverTime=0),null!=this.diaryPersonHover&&this.diaryPersonHoverTime>=config.diary.pinDelay&&(this.diaryPersonPinned=this.diaryPersonHover,g=!0),this.diary.drawHighlightPerson(a,b),g||(this.diaryPersonPinned=null),d};C.prototype.checkDismissCharacter=function(a){this.doEvent(t.getEvent(config.specialEvents.dismiss),{person:a});return this.showPersonInfo=null};C.prototype.showEventAlert=function(a,b){this.showingEventAlert=!0;this.alertText=
a;this.alertHandler=b;return this.diaryBumpTime=0};C.prototype.hideEventAlert=function(a){this.showingEventAlert=!1;if(void 0===a||a)return this.alertHandler()};C.prototype.tickLeftSidebar=function(a){var b=this.showingLeftSidebar()?0:-60*this.s;return this.leftSidebarScrollX+=10*a*(b-this.leftSidebarScrollX)};C.prototype.tickDiary=function(a){if(this.showingEventAlert)var b=-200*this.r.s;else if(this.events.showingEventDialogue){b=this.diary.showImage;var c=null!=b?(1-config.diary.imageOffsetX)*
b.img.width*this.s:this.showingChallenge?this.diary.getDiarySize().w+155*this.r.s:this.diary.getDiarySize().w/2;b=this.ctx.canvas.width;b=Math.max(0,b/2-c)}else b=-300*this.r.s;this.diaryScrollX+=10*a*(b-this.diaryScrollX);this.events.showingEventDialogue&&(this.diaryScrollX=Math.min(this.diaryScrollX,b));this.diaryBumpTime+=a;b=config.diary.delay;null!=this.exped&&0===this.exped.turn&&(b+=10);this.showingEventAlert&&this.diaryBumpTime>b&&this.hideEventAlert();this.diary.tickDiary(a);this.notifications.tick(a);
null!=this.diaryPersonHover&&(this.diaryPersonHoverTime+=a);if("harbor"===this.getMainState()&&!this.events.showingEventDialogue&&(this.notifications.clear(),2<this.diary.changeTime))return this.gotoLoading()};C.prototype.showExpeditionOver=function(a,b,c){a=void 0===a?!1:a;b=void 0===b?"":b;c=void 0===c?"":c;if(!this.gameOver){this.gameOver=!0;if(n.isIO()){var d=this.isWarping()?this.worldStack[0].warpPos:this.party.pos;var e=$jscomp.makeIterator(this.worldGenIO.world.toLocalPos(d));d=e.next().value;
e.next();null!=d&&null==this.party.stats.IOEnd&&(this.party.stats.IOEnd=this.worldGenIO.world.getBiomeIdx(d.pos));null==this.party.stats.deathReason&&(this.party.stats.deathReason=c);this.isWarping()||"evt-timedEvent-endGame"===c||(e=$jscomp.makeIterator(this.world.toLocalPos(this.party.pos)),d=e.next().value,e=e.next().value,this.iomp.addDeathRecord(this.world.getBiomeIdx(d.pos),e,c,this.exped.turn));this.exped.sendLegCache();this.iomp.postCurrHighscore()}else{e=this.world.getCompassLocations();
var f=0;for(c=e.length;f<c;f++)d=e[f],t.checkFlags("+goldenTemple",d.flags)&&(this.r.cam.centerOnPos(d.pos),this.exped.revealTileRadius(d.pos,1))}this.stopMusic(!0);this.exped.updateStats();this.showOutro(a,b);null==this.tutorial&&this.mainMenu.saveGame.clearSaveGame()}};C.prototype.showModding=function(){return this.setMainState("modding")};C.prototype.showOutro=function(a,b){var c,d;this.showingOutro=!0;this.outroSuccess=a;this.outroReason=q.toText(b);b=config.tips.filter(function(a){return q.isLocalized(a)});
this.outroTip=q.parse(b.sample());this.outroTime=0;this.outroItems=[];this.notifications.clear();if(a){var e=this.party.inv.items;a=d=0;for(c=e.length;d<c;a=++d)b=e[a],null==b||0===b.getFame()&&0===b.getFunds()||(this.party.inv.items[a]=null,this.outroItems.push(b));a=this.party.butterflies*config.taxonomy.butterflyFame;0<this.party.stats.goalFame&&(a+=this.party.stats.timeBonus,a+=this.party.stats.goalFame,a+=this.party.stats.newPocketFame);b=Math.round(a*this.party.stats.fameScale-a);this.party.stats.bonus=
b;a=Math.floor(a+b);b=this.party.fame;this.party.changeFame(a);this.party.newFame=this.party.fame-b;this.party.stats.finalFame=this.party.fame}this.r.lastOutroStage=0;this.r.setPureMode(!0);this.showPersonInfo=null;this.mainMenu.onShowOutro();this.gameOver&&this.doSendStats();this.exped.cancelTravel();this.exped.clearWayPoints();this.showingChallenge=!1;this.hideEventDialogue();this.hideEventAlert(!1);return this.updateActions()};C.prototype.getClient=function(){return window.isSteam?"steam":window.isClient?
"drmfree":n.isDemo()?"demo":n.isIO()?"io":"tce-web"};C.prototype.getStatsData=function(){var a,b,c;var d=null!=this.r?Math.floor(this.r.getFPS()):0;d={version:n.getVersionString(),platform:navigator.platform,client:this.getClient(),lang:this.getLangId(),log:this.logs,newsSeen:null!=(a=this.mainMenu.playerData.newsSeen)?a:0,newsExpanded:null!=(b=this.mainMenu.playerData.newsExpanded)?b:0,achievementsEasy:this.achievements.getUnlockedAchievements(0),achievementsNormal:this.achievements.getUnlockedAchievements(1),
achievementsHard:this.achievements.getUnlockedAchievements(2),states:this.mainStates.map(function(a){return a.id}),totalGames:this.mainMenu.totalGames,totalBalloons:this.mainMenu.totalBalloons,firstGameDate:this.mainMenu.firstGameDate,mods:this.modding.activeMods().map("id"),scale:this.r.s,fps:d,lastEventCID:this.events.lastEventCID};null!=this.world&&Object.merge(d,{worldId:this.world.id,pocketId:this.world.pocketId,goalId:this.world.goalId,worldSeed:this.world.worldSeed,locationSpawns:this.world.locationSpawns,
zoneSpawns:this.world.zoneSpawns});null!=(null!=(c=this.worldmap)?c.sites:void 0)&&Object.merge(d,{worldMapSeed:this.worldmap.worldMapSeed});null!=this.party&&(Object.merge(d,{explorer:this.party.explorerId,fame:this.party.fame,funds:this.party.funds,karma:this.party.karma,lifetimeMapScore:this.party.lifetimeMapScore,capacity:this.party.getCapacity(),playTime:this.party.playTime,xp:this.party.xp,perks:this.party.stats.perks,worldLvl:this.party.stats.worldLvl,turns:this.party.stats.turns,raceRank:this.party.stats.raceRank,
locationVisit:this.party.stats.locationVisit,eventEncounters:this.party.stats.eventEncounters,attackUsage:this.party.stats.attackUsage,combatZones:this.party.stats.combatZones,combatEnemies:this.party.stats.combatEnemies,gameOver:this.gameOver,difficulty:this.difficultyLvl,restoredSaveGame:this.restoredSaveGame,itemUsage:this.party.stats.itemUsage,itemLoot:this.party.stats.itemLoot,itemBarter:this.party.stats.itemBarter,itemEvent:this.party.stats.itemEvent,rankingSell:this.party.stats.rankingSell,
rankingGift:this.party.stats.rankingGift,rankingKeep:this.party.stats.rankingKeep,characters:this.party.persons.map(function(a){return{id:a.id,level:a.level,loyalty:a.loyalty,health:a.health}}),items:n.count(this.party.inv.items.compact(),function(a){return a.id},function(a){return a.amount}),deathReason:this.party.stats.deathReason}),n.isIO()&&Object.merge(d,{packs:this.party.stats.packs,givenPacks:this.party.stats.givenPacks}));return d};C.prototype.doSendStats=function(){var a,b;if(n.isIO()&&!debug.skipMetrics){var c=
new (Parse.Object.extend("IOStats"));var d=this.getStatsData();c.set("data",d);c.set("userID",this.iomp.parseUser.id);c.set("highscoreRow",this.iomp.highscoreRow);var e=null!=(b=this.party.stats.marks)?b:[];var f=function(a,b,c){var f,g,h,k,l,n,q,r,u;if(!(a.includes("meat")||a.includes("bongos")||a.includes("jewels")||a.includes("necronomicon")||a.includes("markedAmmo")||a.includes("water")||a.includes("region")||a.includes("hub")||a.includes("crystalBall")||a.includes("polarStation"))){var H=null!=
(f=null!=(k=d.itemLoot)?k[a]:void 0)?f:0;f=null!=(g=null!=(q=d.itemBarter)?q[a]:void 0)?g:0;g=null!=(r=null!=(u=d.itemEvent)?u[a]:void 0)?r:0;u=0;r=null!=(h=d.packs)?h:[];q=0;for(h=r.length;q<h;q++){k=r[q];k=t.getPack(k);var G=null!=(n=k.items)?n:{};for(l in G)k=G[l],l===a&&(u+=k)}H=H+f+u+g;10<b-H&&e.push(c+"-"+a+"x"+b+">found"+H)}};if(null!=d.itemUsage){var g=d.itemUsage;for(a in g)b=g[a],f(a,b,"use")}if(null!=d.rankingGift)for(a in g=d.rankingGift,g)b=g[a],f(a,b,"gift");if(null!=d.items)for(a in g=
d.items,g)b=g[a],f(a,b,"item");0<e.length&&c.set("marks",e);return c.save().then(function(a){return r.info("STATS;updated")},function(a){return r.warn("STATS;failed updating: "+a.message)})}};C.prototype.doSendError=function(a,b){null==this.sentError&&(this.sentError=!1);if(!this.sentError&&(this.sentError=!0,r.error("SendError: "+a),n.isIO()&&!debug.skipMetrics&&"undefined"!==typeof Parse&&null!==Parse)){var c=this.getStatsData();var d=new (Parse.Object.extend("IOErrors"));d.set("data",c);null!=
b&&d.set("debugdata",b);d.set("version",n.getVersionString());d.set("error",a);null!=Parse.User.current()&&d.set("userID",Parse.User.current().id);return d.save().then(function(a){return r.info("errors OK")},function(a){return r.warn("errors NOK: "+a)})}};C.prototype.showStats=function(){this.showingStats=!0;return this.updateActions()};C.prototype.showSettings=function(a){return a?this.setMainState("settings"):this.popMainState()};C.prototype.showCredits=function(a){if(a)return this.setMainState("credits");
this.popMainState();if("epilogue"===this.getMainState())return this.gotoMainMenu()};C.prototype.randChatLine=function(a,b,c){a=void 0===a?"cl-idle":a;b=void 0===b?{}:b;c=void 0===c?!1:c;var d;b=Object.clone(b);var e=t.getChat(a,!1);if(null==e)return[];var f=this.party.persons.randomize();b.isDefaultPerson||(c?f.remove(b.person):f=[b.person]);a=null;var g=0;for(d=f.length;g<d&&(a=f[g],b.person=a,a=this.events.randEvent(t.arrify(e.lines),b),null==a);g++);d=null!=a&&Object.isArray(a.text)?a.text.sample():
null!=a?a.text:void 0;e=[];null!=b.person&&null!=d&&(d=q.parse(d,b.person.gender),!b.person.flags["native"]||this.party.hasTranslator()||b.fakePartyHasTranslator||(d=d.replace(/\w+/g,function(a){var b=q.createRandomText(a.length,a.length);return a[0].toUpperCase()===a[0]?b.capitalize():b})),c=c?config.chat.answerDelay:0,null!=a.delay&&(c+=a.delay),e.push({text:d,person:b.person,delay:c,duration:a.duration}),null!=a.chat&&e.add(this.randChatLine(a.chat,b,!0)));return e};C.prototype.showChatMsg=function(a){var b;
var c=t.arrify(a);var d=[];var e=0;for(b=c.length;e<b;e++)a=c[e],this.events.showingEventDialogue?d.push(this.diary.showChat(a.text,a.person,a.delay,a.duration)):d.push(this.chat.showText(a.text,a.person,a.delay));return d};C.prototype.doChat=function(a,b){b=void 0===b?{}:b;return this.showChatMsg(this.randChatLine(void 0===a?"cl-idle":a,b))};C.prototype.randItemSet=function(a,b,c){var d=this;b=void 0===b?1:b;c=void 0===c?debug.showAllItems:c;var e,f,g;var h=t.arrify(Object.clone(a));var k=[];for(e=
this.fillEventCtx();0<b;){var l=ka.randEntry(h);if(null==l)break;h.removeAt(h.findIndex(l));a=!1;for(f in l){var m=l[f];if("it-"===(g=f.slice(0,3))||"il-"===g){var n=t.getItemList(f,!1);if(null!=n)m=this.randItemSet(n.items,m,c),0<m.length&&(k.add(m),a=!0);else{var q=e.item=t.getItem(f);!c&&0<m&&this.party.persons.none(function(a){e.person=a;return d.events.hasRequirements(q,e)})||(k.push(new jb(this,f,m)),a=!0)}}}a&&--b}return k};C.prototype.trashItem=function(a){if(this.showTrash)return this.doRandEvent(a.dropEvents),
this.party.inv.isOverburden()&&this.party.inv.compact(),this.onBonusChanged()};C.prototype.isUsableItem=function(a){return this.showingChallenge&&this.challenge.isPartyRound?this.challenge.canUseItem(a,this.party):!a.usable||null==this.exped||this.exped.waiting||this.exped.showingPunch||!this.exped.travelPath.isDone()||this.showingDiary()||a.useEvents.isEmpty()||a.chargeTime<a.maxChargeTime?!1:!0};C.prototype.useItem=function(a){if(!this.isUsableItem(a))return null;r.info("ITEM-USE;"+a.id,a.mod);
if(this.showingChallenge){if(this.challenge.useItem(a,this.party)){a.consume();this.party.incStatItemUsage(a.id);var b=null}}else if(!this.events.showingEventDialogue){var c=this.fillEventCtx({item:a});var d=this.events.randEvent(a.useEvents,c);null!=d&&(this.party.incStatItemUsage(a.id),b=this.doEvent(d,c),t.getItem(a.id))}0===a.amount&&this.invBar.inv.isOverburden()?this.invBar.inv.compact():this.invBar.inv.clearEmpty();this.onBonusChanged();this.updateActions();return b};C.prototype.onBonusChanged=
function(){return this.party.onBonusChanged()};C.prototype.doPreEvent=function(a,b){var c=this;b=void 0===b?{}:b;var d,e;n.assert(null!=a);var f=function(a,b,d){b.pos=d;return c.doDelayedEvent(a,b,"")};var g=a.posPunch;if(null!=g){n.assertOpts(g,"posPunch",b,a.mod);var h=q.toText("txt-base-posPunch");this.exped.showPunchDialogue(h,this.party.parseBonus(null!=(d=g.radius)?d:1),this.party.parseBonus(null!=(e=g.maxRange)?e:2),!1,g.tileKnown,null!=b.item,f.bind(this,a,b));return!0}return!1};C.prototype.fillEventCtx=
function(a){a=void 0===a?{}:a;var b,c;a.main=this;a.world=this.world;a.party=this.party;null==a.location&&(a.location=this.events.eventloc);a.isDefaultPerson||(a.isDefaultPerson=null==a.person);null==a.person&&(a.person=this.party.getExplorer());null==a.pos&&(a.pos=null!=a.location?a.location.pos:this.party.pos);null==a.tempFlags&&(a.tempFlags={});null==a.npc&&(a.npc=[]);if(null!=this.diary.showImage){var d=null!=(b=this.diary.showImage.characters)?b:[];var e=0;for(c=d.length;e<c;e++)b=d[e],a.npc.includes(b)||
this.party.persons.includes(b)||a.npc.push(b)}return a};C.prototype.doDelayedEvent=function(a,b,c){b=void 0===b?{}:b;c=void 0===c?"":c;b=this.fillEventCtx(b);a=this.events.doEvent(a,b);if(null!=a)return a.showEvent?this.showEventAlert(c,this.checkEventDiff.bind(this,a,b)):this.checkEventDiff(a,b)};C.prototype.doRandEvent=function(a,b){b=void 0===b?{}:b;b=this.fillEventCtx(b);a=this.events.randEvent(a,b);return null!=a?(this.doEvent(a,b),!0):!1};C.prototype.doEvent=function(a,b){b=void 0===b?{}:b;
var c;null!=this.mainMenu.saveGame.autoBegin||!this.canSave()||"game"!==this.getMainState()||b.silent||n.isIO()&&this.worldGenIO.isGenerating||(Object.isString(a)&&(a=t.getEvent(a)),null==a.id||null==a.text&&null==a.showImage&&null==a.select&&null==a.charEvents||(this.mainMenu.saveGame.autoBegin={event:a.id},null!=b.zone&&null!=(null!=(c=b.world)?c.zones:void 0)&&(this.mainMenu.saveGame.autoBegin.zone=b.world.zones.findIndex(b.zone)),this.mainMenu.saveGame.updateSaveGame(),this.mainMenu.saveGame.autoBegin=
null));b=this.fillEventCtx(b);if(!this.doPreEvent(a,b))return a=this.events.doEvent(a,b),this.checkEventDiff(a,b)};C.prototype.showRandEventAlert=function(a,b,c){var d=this;c=void 0===c?{}:c;c=this.fillEventCtx(c);var e=this.events.randEvent(b,c);if(null!=e)return this.showEventAlert(a,function(){return d.doEvent(e,c)})};C.prototype.checkEventDiff=function(a,b){var c;null!=this.worldGenIO&&this.worldGenIO.isGenerating||null!=(c=this.exped)&&c.clearWayPoints();this.diary.entryTime=this.quickText?100:
0;c=this.events.showingEventDialogue;this.events.checkEventDiff(a,b);b=this.events.showingEventDialogue;c!==b&&(this.diary.changeTime=0);null!=a.delayedEvent&&(b&&r.warn("Delayed event and diary text should not be used at once",a.delayedEvent.event.mod),this.showRandEventAlert("",a.delayedEvent.event,a.delayedEvent.ctx));null!=a.playSound&&this.playSound(a.playSound);null!=a.playMusic&&this.playMusic(a.playMusic);null!=this.party.explorerId&&this.notifications.addNotify(a);if(b)return this.mouseBiome=
this.showPersonInfo=null;this.chat.setEnabled(!0);if(c&&null==a.playMusic)return this.stopMusic()};C.prototype.playSound=function(a){return this.sfx.play(a)};C.prototype.isLastMusicPlaying=function(){return null!=this.lastMusic&&this.lastMusic.isPlaying()&&0<this.lastMusic.currentFadeTarget};C.prototype.playMusic=function(a,b){b=void 0===b?!1:b;if(null==this.lastMusic||this.lastMusic.name!==a||!this.isLastMusicPlaying())return this.stopMusic(!0),logs.sound&&r.info("play music "+a),a="ambient"===a?
this.ambientSound:this.sfx.getSound(a,!0),this.sfx.fadeIn(a,1E3*config.sfx.diaryFadeDuration,b),this.lastMusic=a};C.prototype.stopMusic=function(a){a=void 0===a?!1:a;if(null!=this.lastMusic)return logs.sound&&r.info("sound: stop "+this.lastMusic.name),a=a?1:config.sfx.diaryFadeDuration,this.sfx.fadeOut(this.lastMusic,1E3*a),this.ambientDelay=a+5,this.lastMusic=null};C.prototype.tickSound=function(a){if(!(null!=this.lastMusic&&this.lastMusic.isPlaying()&&0<this.lastMusic.getVolume()||(null==this.ambientDelay&&
(this.ambientDelay=1),this.ambientDelay-=a,0<this.ambientDelay)))return this.playMusic("ambient"),this.ambientDelay=J.randIntA(config.sfx.ambientDelay)};C.prototype.showBarter=function(a){var b;this.barterPerson=a.person;var c={close:a.close,cancel:null!=(b=a.cancel)?b:a.close,itemEvents:a.itemEvents};this.barter.showShop(a,c,a.reqItemFlags);this.showingBarter=!0;return this.diary.setBarter(!0)};C.prototype.showLoot=function(a){this.barterPerson=a.person;this.barter.showLoot(a.inv,a.title,a.slots,
{close:a.close,cancel:a.cancel,itemEvents:a.itemEvents},a.reqItemFlags,a.consumeFameItems);this.showingBarter=!0;return this.diary.setBarter(!0)};C.prototype.showEscape=function(a){this.barterPerson=a.person;this.barter.showEscape(a.title,a.slots,{close:a.close,cancel:a.cancel});this.showingBarter=!0;return this.diary.setBarter(!0)};C.prototype.hideBarter=function(a){this.sfx.play("diaryAction");this.showingBarter=!1;this.barter.hide();this.diary.setBarter(!1);this.onBonusChanged();var b={person:this.barterPerson,
fromAction:!0};this.barterPerson=null;if(null==a||!this.doRandEvent(t.getEvent(a),b))return this.hideEventDialogue()};C.prototype.showCombat=function(a,b,c,d,e,f){c=void 0===c?!1:c;d=void 0===d?null:d;e=void 0===e?null:e;f=void 0===f?"combatMusic":f;this.challengeEvts={win:config.specialEvents.combatLoot,cancel:config.specialEvents.combatFlee};this.challenge.showCombat(this.party,ka.randEntry(a),b,{isSurpriseAttack:c&&null==this.tutorial,win:d,flee:e});this.showingChallenge=!0;this.diary.setCombat(!0);
r.info("COMBAT;start");return this.playMusic(f,!0)};C.prototype.doChallengeSuccess=function(){if(null!=this.challengeEvts.success)return this.doEvent(t.getEvent(this.challengeEvts.success))};C.prototype.doAction=function(a,b){b=void 0===b?null:b;var c,d;if(null==(null!=(c=this.exped)?c.sledgeTarget:void 0)){if(null!=a&&-1<a){null!=this.party.pos&&(d=this.world.getTile(this.party.pos));c=this.getActions(d);c=c[a];if(null==c)return;null!=this.mainMenu.saveGame.autoBegin||!this.canSave()||"game"!==this.getMainState()||
n.isIO()&&this.worldGenIO.isGenerating||(this.mainMenu.saveGame.autoBegin={action:a},this.mainMenu.saveGame.updateSaveGame());r.info("DO-ACTION;"+a+": "+c.id);null!=c.srcLocation&&(this.events.showingEventDialogue||r.header("LOCATION;"+c.srcLocation.id),c.srcLocation.everUsed||(c.srcLocation.everUsed=!0,this.party.visitedLocations+=1,this.party.incStatLocationVisit(c.srcLocation.id)));c.native?this.doNativeAction(c):(a={person:c.person,location:c.location,diceSuccess:b,fromAction:!0,pos:null!=c.location?
c.location.pos:this.party.pos},this.doRandEvent(c.events,a));this.mainMenu.saveGame.autoBegin=null}else r.info("DO-ACTION;"+a+": none"),this.hideEventDialogue(),this.stopMusic();return this.sfx.play("diaryAction")}};C.prototype.gotoHome=function(){var a;this.showingOutro=!1;this.party.visitedPockets.push(this.world.pocketId);null!=(a=this.exped)&&a.clearMapSounds();return null!=this.tutorial?this.worldLvl<config.tutorial.worlds.length-1?this.gotoNextWorld():this.endGame():n.isDemo()?this.gotoRanking():
this.gotoCelebration()};C.prototype.doNativeAction=function(a){switch(a.id){case "act-travel":return this.exped.doPartyTravel();case "act-cancelTravel":return this.exped.cancelTravel();case "act-endgame":case "act-restartGame":return this.endGame();case "act-returnhome":return this.gotoHome();case "act-showStats":return this.showStats();case "act-stopRest":case "act-stopWait":return this.exped.stopWait();case "act-mapShot":return this.exped.createMapShot();case "act-attackZone":return this.exped.doZoneEvent(a.zone,
!1);case "act-loot":return this.showLoot(this.events.eventLoot);case "act-barter":return this.showBarter(this.events.eventBarter)}};C.prototype.gotoEpilogue=function(){if(0===this.getPartyRank())this.mainMenu.onWonCharacter(this.party.getExplorer().id,this.difficultyLvl);this.mainMenu.saveGame.clearSaveGame();this.addScore();return this.setMainState("epilogue")};C.prototype.getDay=function(){return null==this.exped||"harbor"===this.getMainState()?-1:this.exped.turn+1};C.prototype.endGame=function(){var a;
this.hideEventDialogue();null!=(null!=(a=this.sfx)?a.bgMusic:void 0)&&this.sfx.bgMusic.stop();this.gameOver&&!n.isDemo()&&null==this.tutorial&&this.mainMenu.saveGame.clearSaveGame();this.showingOutro=!1;if(n.isDemo())return this.shareMessageText=this.celebration.getShareMessageText(),this.startNewDemoGame();if(n.isIO())return this.initNewIOGame();this.addScore();return this.gotoMainMenu()};C.prototype.getPoints=function(){return n.isIO()?this.party.fame:this.highscore.calcPoints(this.difficultyLvl,
this.party.fame)};C.prototype.addScore=function(){if(null==this.tutorial)return this.highscore.addScore(this.party.explorerId,this.party.fame,this.worldLvl,this.difficultyLvl,this.getPartyRank(),n.getVersionString())};C.prototype.hideEventDialogue=function(){this.events.showingEventDialogue&&(this.diary.changeTime=0);this.events.hideEventDialogue();if("harbor"===this.getMainState())return this.setMainState("loading")};C.prototype.toggleShowBiomes=function(){return(this.showingBiomes=!this.showingBiomes)?
(this.r.cam.resetScroll(),this.r.cam.scrollHD.x=100,this.r.cam.scrollHD.y=100):this.r.cam.centerOnPos(this.party.pos)};C.prototype.getShareMessageURL=function(){return"http://demo.curious-expedition.com/"};C.prototype.tick=function(){var a,b,c,d,e,f,g;if(this.queuedReturnToTCE||this.queuedQuitToDesktop)(a=null!=(c=null!=(d=this.iomp)?d.isSaving:void 0)?c:this.mainMenu.saveGame.saving)||(this.queuedReturnToTCE?returnToTCE():this.queuedQuitToDesktop&&this.quit());else{if(n.isIO()&&null!=this.party&&
null!=(null!=(e=this.party)?null!=(f=e.inv)?f.items:void 0:void 0))for(e=this.party.inv.items,f=0,d=e.length;f<d;f++)if(c=e[f],null!=(null!=c?c.id:void 0)){var h=t.getItem(c.id);var k=null!=(b=h.maxStack)?b:10;c.amount>k&&(null==(h=this.party.stats).marks&&(h.marks=[]),this.party.stats.marks.push("has-"+c.id+"x"+c.amount),c.amount=k)}b=(new Date-this.lastTick)/1E3;b=Math.min(b,.1);b*=null!=(a=debug.timeDilation)?a:1;this.lastTick=new Date;null!=(g=this.getMainStateObj())&&g.tick(b);a=this.getMainState();
null!=this.worldGenIO&&"ionewgame"!==a&&this.worldGenIO.tick(b);null!=this.iomp&&this.iomp.tick(b);switch(a){case "loading":null!=this.worldGen&&this.worldGen.tickGen(b);if(a=this.worldGen?this.worldGen.created:0===this.worldGenIO.worldGenQueue.length)!n.isIO()||this.isNewGameLoading||this.isWarping()||null!=this.tutorial?(this.startWorld(),this.isNewGameLoading=!1):(this.r.setPureMode(!1),this.worldDone=this.showingStats=this.showingOutro=!1,this.lastMusic=null,this.diary.changeTime=0,this.r.onStartWorld(),
this.exped.onStartWorld(),this.gotoGame()),this.waitingForDemoStart=n.isDemo()&&null==this.tutorial&&0===this.worldLvl,"suspended"===this.r.sfx.audioContext.state&&this.r.sfx.audioContext.resume();break;case "game":this.outroTime+=b,this.r.introTime+=b,this.r.cam.tickScrolling(b,this.world.getBiomeCount()),null==this.exped||this.waitingForDemoStart||(this.exped.shipArrived&&(this.r.hudIntroTime+=b),this.r.tickStars(b),this.exped.tickExped(b),this.showingChallenge&&this.challenge.tick(b),this.invBar.tick(b),
this.tickDiary(b),this.tickLeftSidebar(b),this.tickSound(b),this.tickChat(b),this.tickGameBar(b),this.party.tick(b),this.showingOutro||(this.party.playTime+=b),null!=this.tutorial&&this.tutorial.tick(b),this.checkExpeditionOver())}n.isDemo()&&this.tickDemo(b);this.achievementBox.tick(b);this.achievements.tick();this.r.tick(b);this.hasFixedFPS||(null==this.timeToFixFPS&&(this.timeToFixFPS=0),this.timeToFixFPS+=b,.1<this.timeToFixFPS&&(this.hasFixedFPS=!0,this.r.ctx.drawImage(this.r.img.biomeBackgroundTinted,
-1E3,-1E3)));return b}};C.prototype.tickDemo=function(a){this.waitingForDemoStart&&this.mousePressed&&null==this.demoMouseAction&&(this.waitingForDemoStart=this.mousePressed=!1,debug.skipStartEvents||this.startExplorerWheel());if(this.displayingExplorerWheel){var b=Math.floor(this.remainingSpins/this.explorerWheelChars.length);var c=0===this.remainingSpins?1:b+2;null==this.wheelSpeed?this.wheelSpeed=c:this.wheelSpeed!==c&&(b=TWEEN.Easing.Quadratic.InOut(Math.min(1,this.explorerWheelTime)),this.wheelSpeed=
J.lerp(c+1,c,b));this.explorerWheelTime+=a*this.wheelSpeed*1.2;1<this.explorerWheelTime&&(0<this.remainingSpins||this.explorerWheelIdx%this.explorerWheelChars.length!==this.explorerTargetIndex?(--this.explorerWheelTime,this.explorerWheelIdx++,0<this.remainingSpins&&this.remainingSpins--,this.wheelSpeed=c):this.exped.shipArrived&&(this.displayingExplorerWheel=!1))}if(this.mousePressed&&null!=this.demoMouseAction){this.mousePressed=!1;if("shareTwitter"===this.demoMouseAction.id)return n.openLink("https://twitter.com/intent/tweet?text="+
this.shareMessageText+"%0A"+this.getShareMessageURL()),this.sharedTwitter=!0,this.doSendStats();if("shareFB"===this.demoMouseAction.id)return n.openLink("https://www.facebook.com/sharer/sharer.php?u="+this.getShareMessageURL()+"&quote="+this.shareMessageText),this.sharedFB=!0,this.doSendStats()}};C.prototype.checkExpeditionOver=function(a){a=void 0===a?!1:a;if(this.showingChallenge){if(this.challenge.checkExpeditionOver()){var b=config.gameOver.combat;var c=null!=this.challenge.zone?this.challenge.zone.id:
this.events.lastEventCID}}else!this.events.showingEventDialogue&&null!=this.exped&&this.exped.checkExpeditionOver()&&(b=config.gameOver.noSanity,c=this.events.lastEventCID);null==b||a||this.showExpeditionOver(!1,b,c);return null!=b};C.prototype.tickChat=function(a){return this.chat.tick(a)};C.prototype.draw=function(){var a=this;this.wrapSafe(function(){return a.drawMain()});return requestAnimationFrame(this.draw)};C.prototype.wrapSafe=function(a){if(debug.traceAssert)return a();try{return a()}catch(b){return a=
b,r.error(a),this.doSendError(a.message+" _ "+a.stack)}};C.prototype.drawMain=function(){var a;debug.logGeneralRenderStats&&(this.numParticlesRendered=this.numTextDraw=this.numPixDraw=this.numSpritesDraw=this.numSkippedDraws=0);this.infoBox.clearInfo();var b=this.tick();var c=$jscomp.makeIterator(this.mousePos.lst());var d=c.next().value;c=c.next().value;var e=this.mousePressed;null!=(a=this.getMainStateObj())&&a.drawState(d,c,e);switch(this.getMainState()){case "loading":n.isDemo()&&null==this.tutorial&&
0===this.worldLvl?this.drawDemoSplash(b,d,c,e):null!=this.worldGen?this.r.drawLoading(this.worldGen.getProgress(),this.worldGen.logDetail):null!=this.worldGenIO&&this.r.drawLoading(this.worldGenIO.getProgress(),this.worldGenIO.getLogDetail());break;case "game":this.drawGameState(b,d,c,e),this.waitingForDemoStart&&this.drawDemoSplash(b,d,c,e),this.displayingExplorerWheel&&(this.drawDemoSplash(b,d,c,e),this.drawExplorerWheel())}this.infoBox.drawInfo();this.infoBox.drawTooltip(d,c);this.achievementBox.draw();
debug.showCoordLines&&this.r.drawCoordLines();this.r.drawDebugWatches();if(this.outputDiaryLog&&debug.outputDiaryLog){try{this.outputDiaryLogEntry()}catch(f){b=f,r.error(b)}return this.outputDiaryLog=!1}};C.prototype.outputDiaryLogEntry=function(){var a,b,c;this.diaryLogEntries=null!=(a=this.diaryLogEntries)?a:[];var d=this.worldLvl+1;var e=this.getDay()+1;var f=""+this.diaryLogEntries.length;f=f.padStart(4,"0");a=f+"_e"+d+"_d"+e+".png";var g=this.diary.pages.last();var h="";var k=g.diffs;var l=0;
for(g=k.length;l<g;l++){var m=k[l];var n=m.lines;var t=0;for(b=n.length;t<b;t++){var u=n[t];m=0;for(c=u.length;m<c;m++){var D=u[m];h+=D.text+" "}}}""===h&&null!=this.challenge.zone&&(h=q.parse(this.challenge.zone.name)+"!");g={exped:d,day:e,text:h,img:a,idx:f};this.diaryLogEntries.push(g);e="idx,exped,day,img,text\r\n";h=this.diaryLogEntries;d=0;for(f=h.length;d<f;d++)g=h[d],g=g.idx+","+g.exped+","+g.day+","+g.img+',"'+g.text+'"',e+=g+"\r\n";window.isClient&&"undefined"!==typeof require&&null!==require&&
(h=require("electron").nativeImage,d=require("fs"),f=require("path"),g=f.resolve(window.rootPath,O.baseDir(),"diaryLog"),d.existsSync(g)||d.mkdirSync(g),a=f.resolve(window.rootPath,O.baseDir(),"diaryLog/"+a),r.log("writing "+a),g=this.ctx.canvas.toDataURL("image/png"),h=h.createFromDataURL(g),d.writeFile(a,h.toPNG(),function(a){if(null!=a)return r.warn(a)}),a=f.resolve(window.rootPath,O.baseDir(),"diaryLog/log.csv"),r.log("writing "+a),d.writeFile(a,e,function(a){if(null!=a)return r.warn(a)}))};C.prototype.drawDemoSplash=
function(a,b,c,d){this.r.ctx.globalAlpha=1;this.r.drawCloudIntro();null==this.demoTitleTime&&(this.demoTitleTime=0);this.demoTitleTime+=a;var e=$jscomp.makeIterator(this.r.getCanvasSize());d=e.next().value;e=e.next().value;this.demoMouseAction=null;var f=300*(1-TWEEN.Easing.Back.Out((.3*this.demoTitleTime).clamp(0,1)));e=e/2-115*this.s+f+Math.floor(12*Math.sin(this.demoTitleTime));this.displayingExplorerWheel&&(null==this.demoOutOffset&&(this.demoOutOffset=0),this.demoOutOffset-=500*a,e+=this.demoOutOffset);
a=d/2;if(null==this.shareMessageText)this.r.drawSprite("hud_title.png",a,e,{halign:"center",scale:config.imgSize.titleScale}),e+=112.5*this.s,this.r.drawSprite("hud_subtitle_demo.png",a,e,{halign:"center",scale:.5});else if(!this.displayingExplorerWheel){e=100*this.s;var g=250*this.s;f=100*this.s;this.r.drawPanel(config.panel.infoSimple,a-g/2,e,g,f);f=q.toText("txt-demo-share-prompt-1");e+=25*this.s;this.r.drawText(f,a,e,{halign:"center",fillColor:"black",shadowColor:"transparent",font:config.fonts.themedSmall});
e+=15*this.s;f=q.toText("txt-demo-share-prompt-2");this.r.drawText(f,a,e,{halign:"center",fillColor:"black",shadowColor:"transparent",font:config.fonts.themedSmall});e+=10*this.s;f=4*this.s;g=a-10*this.s-this.r.img.logoFB.width;var h=e;this.r.hitBox(g-f,h-f,this.r.img.logoFB.width+2*f,this.r.img.logoFB.height+2*f,b,c)&&(this.demoMouseAction={id:"shareFB"},h-=2*this.s);this.r.ctx.drawImage(this.r.img.logoFB,g,h);g=a+10*this.s;h=e;this.r.hitBox(g-f,h-f,this.r.img.logoTwitter.width+2*f,this.r.img.logoTwitter.height+
2*f,b,c)&&(this.demoMouseAction={id:"shareTwitter"},h-=2*this.s);this.r.ctx.drawImage(this.r.img.logoTwitter,g,h);e+=20*this.s}if("loading"===this.getMainState())return this.worldGen.drawLoadingBar();if(!this.displayingExplorerWheel)return a=d/2,f=q.toText("txt-demo-click-start"),e+=50*this.s,h={fillColor:"#f4aa00",shadowColor:"#bc2d00",font:config.fonts.themedLarge},this.ctx.font=h.font,g=this.ctx.measureText(f).width+54*this.s,d=g/2-14*this.s,this.r.drawButton(f,a,e,g,28*this.s,b,c,!1,h)&&(d-=4*
this.s),e+=14*this.s,this.r.drawSprite("hud_redArrow_left.png",a+d,e,{halign:"center",valign:"center"}),this.r.drawSprite("hud_redArrow_right.png",a-d,e,{halign:"center",valign:"center"})};C.prototype.drawGameState=function(a,b,c,d){if(this.showingBiomes)this.r.clear(),this.r.drawDebugBiomes(this,b,c);else{this.exped.mouseAction=null;if(!this.exped.shipArrived||1>this.diary.imageAlpha&&this.diary.drawMapUnderDiary||0===this.diary.imageAlpha)this.ctx.translate(this.r.cam.shakeX,this.r.cam.shakeY),
this.exped.drawMap(a,b,c),this.ctx.translate(-this.r.cam.shakeX,-this.r.cam.shakeY),this.r.drawFades(a);this.r.trailerMode||this.drawActionButtons(b,c,d);this.exped.shipArrived&&(this.drawDiary(b,c,d),this.showingOutro||this.drawHUD(a,b,c));this.showPartySidebar&&this.chat.drawChat();this.r.trailerMode||(this.showTileInfo&&this.exped.drawTileInfo(),this.drawItemInfo());this.exped.drawPunch();this.exped.drawMiniMap();this.drawSubItems();n.isIO()||this.exped.drawShip();this.showingOutro||(this.exped.shipArrived&&
(this.drawWarningBar(),this.drawInventoryBar(b,c,d)),null!=this.tutorial&&this.tutorial.draw(b,c,d),this.handleCharacterInfo(b,c));this.r.drawParticles(!0);this.exped.drawDebugBar(b,c,d);a=null;this.showingStats?(n.isIO()&&null!=this.iomp.lastPostedScore?(a=this.iohighscore.drawPartyInfo(this.iomp.lastPostedScore,10*this.s,20*this.s,222*this.s,b,c),b=this.iomp.lastPostedScore.partyData.playTime,null!=b&&(b=q.toText("txt-outro-playtime")+": "+q.toText("txt-outro-playtime2").replace("$val",b),this.r.drawText(b,
13*this.s,230*this.s,{font:config.fonts.technicalSmall,halign:"left",fillColor:config.colors.help}))):this.r.drawStats(this.party.stats),this.r.drawLetterboxMattes()):this.showingOutro&&(this.r.drawOutro(this.outroSuccess,this.outroReason,this.party.stats,this.outroTip,this.outroTime),n.isIO()&&(a=this.r.drawOutroPacks(this.party,b,c)),this.r.drawLetterboxMattes(this.outroTime));null!=a&&d&&jc.beginTransaction(this,{item:a,type:cb.crateHold});return this.r.drawCloudIntro()}};C.prototype.drawSubItems=
function(){var a;if(!this.events.showingEventDialogue&&null!=this.mouseItem&&!Object.isEmpty(this.mouseItem.subItems)){var b=this.mouseItem.subItems;var c=0;for(a=b.length;c<a;c++){var d=b[c];if(d.id===config.specialItems.anthropologicalStudies&&!d.genTribe){var e=.5<Math.random()?"male":"female";var f=this.getTribeGenAtPartyPos();n.assert(null!=f);e=f.genSpriteLayers(e);d.sprite=f.genSprite(e,f.colorTable).portrait;d.genTribe=!0}}return this.r.drawSubItems(this.mouseItem)}};C.prototype.handleCharacterInfo=
function(a,b){var c;var d=$jscomp.makeIterator(this.r.getCanvasSize());var e=d.next().value;d=d.next().value;if(null!=this.showPersonInfo){var f={xp:this.party.xp,showActions:null==this.tutorial&&!this.events.showingEventDialogue&&!this.exped.isTraveling(),showLevelUp:this.party.canLevelUp(this.showPersonInfo.person,!0),maxY:d-35*this.r.s,hoverMarginW:35*this.r.s,halign:"right"};debug.showDebugBar&&(f.testStatus=debug.testStatus);f=this.r.drawCharacterInfo(this.showPersonInfo.person,e-45*this.r.s,
this.showPersonInfo.pos.y-5*this.r.s,a,b,f);switch(f){case "levelUp":this.showPersonInfo.person.hasLoyalty()&&(c=q.toText("txt-bonus-loyaltyBoost")+": "+100*this.party.loyaltyBoost+"%");this.infoBox.setInfo([{text:c,col:config.colors.bonus},{text:config.help.levelUp}],e-308*this.s);break;case "health":a=this.showPersonInfo.person;b=1+a.healthRegenBonus;c=q.toText(config.helpBonus.healthRegen.slice(1));if(a.health<a.maxHealth){var g=(a.maxHealth-a.health)*a.healthRegenTurn-a.regenTurn;g="("+g+" "+
q.toText("txt-status-days")+")"}g=c+": "+100*b+"% "+(null!=g?g:"");b=q.toText(config.helpBonus.infection.slice(1));b=b+": "+100*a.infectionChance+"% ("+q.toText("txt-bonus-perTrip")+")";c=q.toText(config.helpBonus.death.slice(1));a=c+": "+100*a.deathChance+"% ("+q.toText("txt-bonus-perTrip")+")";this.infoBox.setInfo([{text:config.help.health},null,{text:g,col:config.colors.bonus},{text:b,col:config.colors.bonus},{text:a,col:config.colors.bonus}]);break;case "loyalty":this.infoBox.setInfo([{text:config.help.loyalty}]);
break;case "dice":this.infoBox.setInfo([{text:config.help.dice}]);break;case "capacity":this.infoBox.setInfo([{text:config.help.capacity}])}}return f};C.prototype.drawActionButtons=function(a,b,c){var d=$jscomp.makeIterator(this.r.getCanvasSize());d.next();d.next();this.r.cam.mouseScrolling&&(c=!1);this.exped.hoverActionButton=!1;if(this.showActions&&!(null!=this.mouseItem&&(null!=this.mouseItem.miniMap||0<this.mouseItem.subItems.length)||debug.hideActionButtons&&!this.showingOutro||null==this.actionButtons))return d=
this.shouldShowGameBar(),a=this.r.drawActionButtons(this.buttonsTime,d,this.actionButtons,a,b,c),null!=a?(this.exped.hoverActionButton=!0,c&&(this.exped.mouseAction={id:"action",data:a}),c=this.actions[a],null!=c?this.r.markActionHighlight(c):this.r.markActionHighlight(null)):this.r.markActionHighlight(null)};C.prototype.drawWarningBar=function(a){var b,c;if(!(this.events.showingEventDialogue||null!=(c=this.exped)&&c.checkExpeditionOver(!0))&&(a=this.exped.lostStashTime<config.lostStashWarningTime?
q.toText(config.help.lostStash):this.party.isOverfilled()?q.toText(config.help.overfilled):this.party.isOverburden()?(b=this.party.inv.items.length-this.party.getCapacity(),q.toText(config.help.overburden).replace("$val",b)):void 0,b=$jscomp.makeIterator(this.r.getCanvasSize()),b.next(),b=b.next().value,c=this.invBar.getSize(),null!=a))return this.r.drawWarningBar(a,b-c.h-8*this.s)};C.prototype.drawInventoryBar=function(a,b,c){if(this.showInventory&&!this.r.pureMode&&!this.showingBarter){var d=!this.showingBarter||
this.barter.isValidTargetParty();this.invBar.drawBackground(d,a,b,c)&&(this.exped.mouseAction={id:"itemTab"});return this.invBar.drawDragged(this.showTrash)}};C.prototype.setAllHUD=function(a){return this.showTrash=this.showTileInfo=this.showInventory=this.showXP=this.showLeftSidebar=this.showPartySidebar=this.showActions=this.showStanding=this.showPath=this.showSanity=a};C.prototype.drawHUD=function(a,b,c){var d,e,f;var g=$jscomp.makeIterator(this.r.getCanvasSize());var h=g.next().value;g.next();
this.showingPartySidebar()&&(a=this.drawPartySideBar(a,b,c),null!=a&&(this.exped.mouseAction=a),this.showXP&&(a=this.world.getTile(this.party.pos),null!=a&&this.r.drawRegionInfo(a,b,c)&&(e="region"),this.r.drawXP(this.party.xp,this.party.mapScoreInterp,config.xp.maxMapScore,this.party.mapScoreTime,b,c)&&(e="xp")));this.showStanding&&!this.showingChallenge&&this.r.drawStanding(this.party.standing,b,c)&&(e="standing");if(!(this.events.showingEventDialogue||this.showingEventAlert||null!=(d=this.exped)&&
d.waiting))if(n.isDemo()){d=25*this.s;a=$jscomp.makeIterator([h/2,15*this.s+this.r.oY]);h=a.next().value;var k=a.next().value;g={panel:"demoTutorial",fillColor:"#644900",shadowColor:"transparent"};this.ctx.font=config.fonts.themedLarge;if(null==this.tutorial&&this.showSanity){var l=q.toText("txt-demo-play-tutorial");a=this.r.ctx.measureText(l).width+18*this.s;this.r.drawButton(l,h,k,a,d,b,c,!1,g)&&(this.exped.mouseAction={id:"tutorial"})}else null!=this.tutorial&&(l=q.toText("txt-demo-skip-tutorial"),
a=this.r.ctx.measureText(l).width+18*this.s,this.r.drawButton(l,h,k,a,d,b,c,!1,g)&&(this.exped.mouseAction={id:"skipTutorial"}))}else n.isIO()&&null!=this.tutorial&&(d=25*this.s,a=$jscomp.makeIterator([h/2,13*this.s+this.r.oY]),h=a.next().value,k=a.next().value,g={panel:"demoTutorial",fillColor:"#644900",shadowColor:"transparent"},this.ctx.font=config.fonts.themedLarge,l=q.toText("txt-demo-skip-tutorial"),a=this.r.ctx.measureText(l).width+18*this.s,this.r.drawButton(l,h,k,a,d,b,c,!1,g)&&(this.exped.mouseAction=
{id:"skipTutorial"}));this.showSanity&&(d=0<(null!=(f=this.exped.previewPath)?f.length:void 0)?this.exped.previewPathCost:void 0,this.r.drawSanity(this.party.sanity,this.party.maxSanity,d,b,c)&&(e="sanity"));switch(e){case "sanity":l=function(){switch(!1){case 0!==this.party.sanity:return"txt-help-eventtypes-zero";case !(this.party.sanity<config.sanity.thresholds[0]):return"txt-help-eventtypes-bad";case !(this.party.sanity<config.sanity.thresholds[1]):return"txt-help-eventtypes-neutral";default:return"txt-help-eventtypes-good"}}.call(this);
this.infoBox.setInfo([{text:q.toText("txt-base-sanity")+": "+this.party.sanity+"/"+this.party.maxSanity},{text:q.toText("txt-help-eventtypes")+": "+q.toText(l)},{text:config.help.sanity,col:config.colors.help}]);break;case "standing":this.infoBox.setInfo([{text:q.toText("txt-base-standing")+": "+this.party.standing},{text:config.help.standing,col:config.colors.help},{text:config.help.standingio,col:config.colors.help},{text:config.help.standing2,col:config.colors.help}]);break;case "xp":this.infoBox.setInfo([{text:q.toText("txt-base-xp")+
": "+this.party.xp+" ("+this.party.mapScore+" / "+config.xp.maxMapScore+")"},{text:q.toText("txt-help-xp"),col:config.colors.help}]);break;case "region":h=this.world.getTile(this.party.pos),d=e=0,null!=h&&h.biome.entered&&(d=h.biome.scoreLocations.length,e=h.biome.scoreLocations.count(function(a){return a.known})),f=[],n.isIO()&&!this.isWarping()&&null==this.tutorial&&(null!=h.biome.claim?f.push({text:q.toText("txt-io-claim")+" "+h.biome.claim.user.displayName,col:config.colors.ioBiomeClaim}):f.push({text:""+
q.toText("txt-io-unclaimed"),col:config.colors.ioBiomeClaim})),f.push({text:q.toText("txt-bonus-revealDist")+": "+this.party.revealDist}),f.push({text:q.toText("txt-help-locations")+": "+e+" / "+d}),f.push({text:q.toText("txt-help-region"),col:config.colors.help}),this.infoBox.setInfo(f)}return this.drawLeftSidebar(b,c)};C.prototype.drawLeftSidebar=function(a,b){this.r.drawLeftSidebar(this.leftSidebarScrollX,this.difficultyLvl);n.isIO()?this.r.drawIOCalendar(this.leftSidebarScrollX,this.exped,this.infoBox,
a,b):this.r.drawCalendar(this.leftSidebarScrollX,this.exped.turn,this.worldLvl,this.party.fame,this.party.funds,this.difficultyLvl,this.infoBox,a,b);this.exped.drawCompass(this.leftSidebarScrollX,a,b);if(null!=this.world.rivalTurns){var c=$jscomp.makeIterator(this.r.drawRaceBar(this.leftSidebarScrollX,this.rivals,this.world.rivalTurns,this.infoBox,a,b));var d=c.next().value;c=c.next().value;d&&(c=null!=c?c:this.rivals.exclude(function(a){return null!=a.arrivedTurn}).max(function(a){return a.turn}),
d=[],null!=c&&d.push({text:""+c.character.name}),null!=c&&d.push({text:q.toText("txt-help-racebar-info")+": "+(this.world.rivalTurns-c.turn)}),d.push({text:config.help.raceBar,col:config.colors.help}),this.infoBox.setInfo(d))}else n.isIO()&&null==this.tutorial&&this.r.drawIOFame(this.leftSidebarScrollX,this.party,a,b,this.infoBox);a=this.r.drawExtraButtons(this.leftSidebarScrollX,this.infoBox,a,b);if(null!=a)return this.exped.mouseAction=a};C.prototype.showingLeftSidebar=function(){var a,b;return this.showLeftSidebar&&
!(this.events.showingEventDialogue||this.showingEventAlert||null!=(a=this.exped)&&a.waiting)&&(null!=(b=this.exped)?b.shipArrived:void 0)&&!this.showingOutro&&!this.r.trailerMode&&!this.r.pureMode};C.prototype.showingPartySidebar=function(){var a;return this.showPartySidebar&&!this.events.showingEventDialogue&&(null!=(a=this.exped)?a.shipArrived:void 0)&&!this.showingOutro&&!this.r.trailerMode&&!this.r.pureMode};C.prototype.showingEventDialogue=function(){return null!=this.events&&this.events.showingEventDialogue};
C.prototype.showingDiary=function(){return null!=this.exped&&(this.showingEventAlert||this.events.showingEventDialogue)};C.prototype.drawPartySideBar=function(a,b,c){return this.r.drawParty(this.difficultyLvl,this.party,this.chat,null==this.showPersonInfo&&!this.events.showingEventDialogue&&1.5<this.r.hudIntroTime,b,c)};C.prototype.add=function(a,b){b=a.add(b);return this.world.isValid(b)?b:a};C.prototype.getActions=function(a){var b=this,c,d;var e=function(a,c){c=void 0===c?{}:c;var d={zone:c.zone,
location:c.location};var e=t.arrify(a);var g=0;for(a=e.length;g<a;g++){var h=e[g];h=b.events.addAction(h,!0,d);h.location=c.location;h.srcLocation=c.location;h.zone=c.zone;h.canDo=b.events.canDoAction(h,b);f.push(h)}};var f=[];switch(this.getMainState()){case "harbor":e(this.events.eventActions,{location:this.events.eventloc});break;case "game":if(!this.exped.showingPunch)if(this.showingOutro)if(this.gameOver){var g=n.isDemo()?"act-restartGame":"act-endgame";this.showingStats?e(g):e([g,"act-showStats"]);
config.enableScreenshots&&e("act-mapShot")}else this.worldDone&&(e("act-returnhome"),this.showingStats||e("act-showStats"),config.enableScreenshots&&e("act-mapShot"));else if(this.exped.waiting)this.exped.canHaveEvent()&&e("act-stopWait");else if(this.exped.isTraveling())e("act-cancelTravel");else if(0<this.exped.wayPoints.length)e("act-travel");else if(!this.events.eventActions.isEmpty())e(this.events.eventActions,{location:this.events.eventloc});else if(null!=a){null!=a.location&&e(a.location.actions,
{location:a.location});g=this.world.getTilesInRadius(a.pos,1);var h=0;for(c=g.length;h<c;h++){var k=g[h];k!==a&&null!=k.location&&null!=k.location.actions&&e(k.location.actions,{location:k.location})}if(null==this.tutorial){g=this.world.getTilesInRadius(a.pos,2);var l=[];c=new Ma(this.world,this.party,this.party.pos,{},{ignoreTileCost:!0,ignoreUnknown:!1,maxCost:2});h=0;for(a=g.length;h<a;h++)if(k=g[h],null!=k.zones){var m=k.zones;k=0;for(d=m.length;k<d;k++){var p=m[k];null!=p&&-1===l.indexOf(p)&&
(l.push(p),c.find(p.center),c.wait(),null!=c.path&&(p.canAttack&&e("act-attackZone",{zone:p}),e(p.actions)))}}}}break;case "celebration":e(this.events.eventActions,{location:this.events.eventloc})}return f.filter(function(a){return a.alwaysShown||a.canDo})};C.prototype.onActionsChanged=function(){return this.updateActions()};C.prototype.shouldShowGameBar=function(){var a;var b=this.getMainState();return this.showingOutro||"celebration"===b||!this.events.showingEventDialogue&&!this.showingBiomes&&
"intro"!==b&&!this.showingEventAlert&&!(null!=(a=this.exped)&&a.sledgeTarget)};C.prototype.tickGameBar=function(a){return this.buttonsTime+=a};C.prototype.updateActions=function(){if(null!=this.world&&null!=this.party.pos){var a=this.world.getTile(this.party.pos);this.actions=this.getActions(a);a=this.actions.map(function(a){return a.name});if(!Object.equal(this.actionButtons,a))return this.actionButtons=a,this.buttonsTime=0}};C.prototype.onMouseOutAction=function(a){return this.infoBox.hide()};C.prototype.loadConfig=
function(a){var b;if(!config.campaign){var c=0;null==config.entities&&(config.entities={});var d=0;for(b=hjsonConfs.length;d<b;d++){var e=hjsonConfs[d];O.readFileAsync("conf/"+e,function(b){var d;c+=1;try{var f=Hjson.parse(b);var k=0;for(d=f.length;k<d;k++){var l=f[k];null!=config.entities[l.id]&&r.error("Found duplicate ID "+l.id+"!",l.mod);config.entities[l.id]=l}}catch(m){b=m,r.error("invalid syntax in file "+e+": "+b)}if(c===hjsonConfs.length)return a()})}}};C.prototype.quit=function(){if(window.isNW)return process.exit();
if(window.isElectron)return require("electron").remote.app.quit()};C.prototype.appendLangTexts=function(a,b,c){a=q.parseLang(a,b);c===this.getLangId()&&Object.merge(config.locTexts,a);if("en"===c&&config.enTexts!==config.locTexts)return Object.merge(config.enTexts,a)};C.prototype.getLangId=function(){return q.langId};C.prototype.debugGetPos=function(){return this.world.getTile(this.party.pos)};C.prototype.displayLoadError=function(a,b){if(!(a.includes("mods")&&n.isTCE()||this.isDisplayingLoadError)){this.isDisplayingLoadError=
!0;var c="<h1>"+q.toText("txt-startup-server-download-error")+"</h1>";c=c+("<p>"+a+"</p>")+("<p>"+b+"</p>");return $("#loading").html(c)}};"undefined"!==typeof window&&null!==window&&(window.privacyOpen=function(){return n.openLink("http://curious-expedition.io/imprint_p",!1)},window.privacyAccept=function(){$("#loading").html(q.toText("txt-startup-connecting")+"...");var a=Parse.User.current();if(null!=a)return a.set("privacyPolicyAccepted",new Date(Date.now())),a.save().then(function(a){return window.refreshWindow()});
if(window.isSteam&&!debug.disableIOMP)return greenworks.getAuthSessionTicket(function(a){var b,c,f,g,h,k,l,m,n,q;return $jscomp.asyncExecutePromiseGeneratorProgram(function(d){switch(d.nextAddress){case 1:l={id:greenworks.getSteamId().steamId,sessionTicket:""};k=a.ticket;m=0;for(h=k.length;m<h;m++)g=k[m],l.sessionTicket+=("0"+g.toString(16)).slice(-2);new Parse.User;d.setCatchFinallyBlocks(2);return d.yield(Parse.User.logInWith("steam",{authData:l}),4);case 4:n=d.yieldResult;greenworks.cancelAuthTicket(a.handle);
if(null==n)return f="IOMP; parse steam login failed: no userResult",r.error(f),$("#loading").html(f),d.return();b="#000000".replace(/0/g,function(){return(~~(16*Math.random())).toString(16)});n.set("colour",b);n.set("privacyPolicyAccepted",new Date(Date.now()));n.set("gameKey","steam");n.set("displayName",greenworks.getSteamId().getPersonaName());return d.yield(n.save(),5);case 5:window.refreshWindow();d.leaveTryBlock(0);break;case 2:c=q=d.enterCatchBlock(),greenworks.cancelAuthTicket(a.handle),f=
"IOMP; failed Parse.User.logInWith: "+c.message,r.error(f),$("#loading").html(f),d.jumpToEnd()}})},function(a){a="IOMP; failed getAuthSessionTicket: "+a.message;r.error(a);$("#loading").html(a)});a=new Parse.User;a.set("username","ceio_"+J.randInt(100,9999999));a.set("password","password");var b="#000000".replace(/0/g,function(){return(~~(16*Math.random())).toString(16)});a.set("colour",b);a.set("privacyPolicyAccepted",new Date(Date.now()));window.isElectron&&a.set("gameKey","rivals");return a.signUp({}).then(function(a){window.refreshWindow()},
function(a){r.error("IOMP;failed creating user: "+a.message)})},window.privacyReject=function(){return $("#loading").html(q.toText("txt-startup-privacy-decline")+getRefreshOrQuitHtml())},window.emailSignup=function(){var a=Parse.User.current();if(null!=a)return a.set("emails",!0),a.save().then(function(a){return window.refreshWindow()})},window.displayNoUser=function(a){a=void 0===a?"":a;var b=n.isIO()&&window.isClient?"/io_account.html":"/";return $("#loading").html('<a href="'+b+'">'+q.toText("txt-startup-login")+
"</a>"+a)},window.returnToTCE=function(){return window.isElectron?n.openInternalLink("/play-electron.html"):n.openInternalLink("/play")},window.refreshWindow=function(){n.canUseLocalStorage()&&window.localStorage.setItem("refreshing",!0);return location.reload()},window.getRefreshOrQuitHtml=function(){var a=q.toText("txt-startup-retry");var b=q.toText("txt-startup-return-tce");return'<h2><a href="#" onclick="window.refreshWindow()">'+a+'</h2><h2><a href="#" onclick="returnToTCE()">'+b+"</a></h2>"},
null==window.isNW&&(window.isNW=!1),null==window.isElectron&&(window.isElectron=!1),null==window.gameMode&&(window.gameMode=ya.TCE),window.isClient=window.isNW||window.isElectron,window.getDstCanvas=function(){return document.getElementById("gameBoard")},window.onload=function(){var a=this,b;if(!window.isTest){window.isSteam=!1;debug.isDevMode?r.info("game version: "+n.getVersionString()+" (devMode)"):r.info("game version: "+n.getVersionString());if(window.isClient&&!n.isChina())try{if(window.greenworks=
require("./greenworks"),null!=window.greenworks&&(process.activateUvLoop(),window.isSteam=greenworks.init(),r.info("GREENWORKS;initted: logged in: "+window.isSteam),window.isSteam))greenworks.on("game-overlay-activated",function(a){return window.steamOverlayActive=a})}catch(D){var c=D;r.warn("GREENWORKS;failed init\n"+c)}staticConfig.showMods=n.isTCE()&&("undefined"!==typeof debug&&null!==debug&&debug.isDevMode||window.isClient)&&!n.isChina();window.GPUCanvas=!0;if(window.isElectron){c=require("electron").remote.app.getGPUFeatureStatus();
for(e in c){var d=c[e];r.info("GPU-STATUS;"+e+": "+d)}window.GPUCanvas=null!=(b=c["2d_canvas"])?b.includes("enabled"):void 0}if(window.isClient&&("undefined"===typeof hjsonConfs||null===hjsonConfs)){var e=require("fs");b=require("path");window.hjsonConfs=e.readdirSync(b.join(window.rootPath,"conf")).filter(function(a){return a.endsWith(".hjson")})}var f=function(a,b){a=void 0===a?"":a;b=void 0===b?"":b;var c=q.toText("txt-startup-server-error");c+="<p>error: "+b+"</p>";debug.isDevMode&&(c+="<p>DevMode: You need to run the io helper server at tools/io_helper_server/dev_server.bat (do npm install first!) or turn on debug.disableIOMP<p>Server url: "+
a);c+=getRefreshOrQuitHtml();return $("#loading").html(c)};var g=function(){return $("#loading").html(q.toText("txt-startup-game-offline")+getRefreshOrQuitHtml())};var h=function(a){var b=q.toText("txt-startup-version-mismatch");b+="<p>Game: "+n.getVersionString()+" Server: "+a;return $("#loading").html(b+getRefreshOrQuitHtml())};var k=function(){return $("#loading").html(q.toText("txt-startup-game-booting")+getRefreshOrQuitHtml())};var l=function(){return $("#loading").html(q.toText("txt-startup-banned")+
getRefreshOrQuitHtml())};var m=function(a){var b='<a onclick="privacyOpen()" href="#">'+q.toText("txt-startup-privacy-policy")+"</a>";var c=q.toText("txt-startup-privacy-question").replace("$privacy",b);null!=a&&(c+="<br>"+q.toText("txt-startup-privacy-lastUpdated").replace("$date",a.toLocaleDateString()));var d=q.toText("txt-startup-privacy-yes");b=q.toText("txt-startup-privacy-no");if(null!=a||window.isSteam)a="";else{a=q.toText("txt-startup-privacy-login");var e="/io_account.html#dologin";window.isElectron&&
(e="file://"+__dirname+e);a='<br><br><p><a href="'+e+'">'+a+"</a></p>"}return $("#loading").html("<h1>"+c+'</h1><h2><a onclick="privacyAccept()" href="#">'+d+'</a> <a onclick="privacyReject()" href="#">'+b+"</a></h2>"+a)};var p=function(){$("#loadingText").html(q.toText("txt-loading")+"...");return setTimeout(function(){var a=new C;debug.isDevMode&&(window.devMain=a);return window.HandleElectronClose=function(){return a.beginQuit()}})};n.canUseLocalStorage()&&(e=window.localStorage.getItem("useProxy"),
null!=e&&"true"===e&&(Parse.serverURL=window.parseProxyURL));var t=function(a){r.log("IO;Connected to iomp server, error "+a);return"notready"===a?k():a.includes("banned")?l():"noworld"===a?g():f(ea.helperURL,a)};var u=function(){var a,b;var c=Parse.User.current();if(null!=c&&window.isClient&&!debug.disableIOMP){var d=c.get("gameKey");d=window.isSteam===("steam"===d);if(!d){Parse.User.logOut();return}window.isSteam&&(d=null!=(a=c.get("authData"))?null!=(b=a.steam)?b.id:void 0:void 0,d!==greenworks.getSteamId().steamId&&
Parse.User.logOut())}return null!=c?(r.header("IO;Fetching current user "+Parse.User.current().id),debug.isDevMode&&debug.disableIOMP?c=Promise.resolve(Parse.User.current()):(a=!0,n.canUseLocalStorage()&&(c=window.localStorage.getItem("refreshing"),null!=c&&"true"===c&&(a=!1,window.localStorage.setItem("refreshing",!1))),c=a?Parse.User.current().fetch():Promise.resolve(Parse.User.current())),c.then(function(a){var b,c,d,e,g,k,l;return $jscomp.asyncExecutePromiseGeneratorProgram(function(q){switch(q.nextAddress){case 1:if(null==
a)return r.header("IO;No user"),q.return(f("","no user"));n.canUseLocalStorage()&&window.localStorage.setItem("useProxy",Parse.serverURL===window.parseProxyURL);r.header("IO;Fetched user "+a.id);window.iomp=new Lc(a);e=a.get("privacyPolicyAccepted");d=!0;if(null==e){d=!1;q.jumpTo(3);break}q.setCatchFinallyBlocks(4);return q.yield(window.iomp.getConfig(),6);case 6:b=q.yieldResult;q.leaveTryBlock(5);break;case 4:return c=l=q.enterCatchBlock(),t(c),q.return();case 5:g=new Date(b.privacyPolicyUpdated),
bb.disableIOUI=null!=(k=b.disableIOUI)?k:!0,null!=g&&g>e&&(d=!1);case 3:return d?q.return(window.iomp.helperServerConnect().then(function(a){if(null!=a.error)t(a.error);else return r.log("IO;Connected to iomp server, version "+a.version),iomp.isServerVersionIncompatible(a.version)?h(a.version):p()},function(a){r.log("IO;Connection to iomp server failed, error "+a);return f(response.serverURL,a)})):q.return(m(g))}})},function(a){r.header("IO;Login error: "+a);if(100===a.code&&Parse.serverURL!==window.parseProxyURL)r.info("Switching to proxy server"),
Parse.serverURL=window.parseProxyURL,u();else return n.canUseLocalStorage()&&window.localStorage.setItem("useProxy",!1),a.code===Parse.Error.INVALID_SESSION_TOKEN?(Parse.User.logOut(),window.refreshWindow()):f("",a)})):window.isClient?(r.header("IO;New user must accept privacy"),m()):n.openInternalLink("/")};n.isIO()&&window.isElectron&&!debug.isDevMode&&(e=require("electron"),e.remote.getCurrentWindow().webContents.closeDevTools());return q.setupLang(function(){$("#loadingText").html(q.toText("txt-startup-connecting")+
'...<br><a href="#" onclick="returnToTCE()">'+q.toText("txt-barter-cancel")+"</a>");if("undefined"!==typeof debugEvents&&null!==debugEvents)a.eventsTestGround=new EventsTestGround;else if(!window.isClient&&n.isTCE()&&null==Parse.User.current())displayNoUser();else if(n.isIO()){if(window.isSteam){var b={authenticate:function(a){return a.error("steam",Error("no steam auth data"))},restoreAuthentication:function(){return!0},getAuthType:function(){return"steam"}};Parse.User._registerAuthenticationProvider(b)}debug.runOffline?
(b=new Parse.User,b.id="fake",b.set("username","egx"),b.set("displayName","EGX Player"),b.set("email","egx_offline_io@dummy.com"),b.set("colour","#FF0000"),b.set("privacyPolicyAccepted",new Date(Date.now())),window.iomp=new Lc(b),window.iomp.helperServerConnect(),p()):u()}else p()})}},window.onbeforeunload=function(a){var b;a=null!=a?a:window.event;if(!window.isTest){var c=window.main;if(window.isElectron){if(this.canSave())return this.mainMenu.saveGame.updateSaveGame()}else if(null!=c&&("game"===
(b=this.getMainState())||"worldMap"===b||"celebration"===b||"ionewgame"===b)&&!debug.skipExitWarning&&null!=this.exped&&null!=this.party&&this.exped.turn!==this.mainMenu.saveGame.lastSavedTurn)return n.isIO()&&this.canSave()&&this.mainMenu.saveGame.updateSaveGame(),a&&(a.returnValue="Are you sure?"),"Are you sure?"}});var Rc=function(){var a=function(a,c,d){var b,f,g,h,k,l,m,n;this.getFullVersion=this.getFullVersion.bind(this);this.updateMetaData=this.updateMetaData.bind(this);this.matchesVersionRange=
this.matchesVersionRange.bind(this);this.generateHash=this.generateHash.bind(this);this.loadHjsonData=this.loadHjsonData.bind(this);this.getPreviewPath=this.getPreviewPath.bind(this);this.importData=this.importData.bind(this);this.addFeature=this.addFeature.bind(this);this.sanityCheckData=this.sanityCheckData.bind(this);this.applyEntries=this.applyEntries.bind(this);this.applyEntry=this.applyEntry.bind(this);this.applyEntryOld=this.applyEntryOld.bind(this);this.getEntityProperty=this.getEntityProperty.bind(this);
this.getEntryInfo=this.getEntryInfo.bind(this);this.addEntry=this.addEntry.bind(this);this.replaceEntry=this.replaceEntry.bind(this);this.mergeEntry=this.mergeEntry.bind(this);this.removeEntry=this.removeEntry.bind(this);this.loadPreview=this.loadPreview.bind(this);this.loadLangs=this.loadLangs.bind(this);this.loadLanguageFile=this.loadLanguageFile.bind(this);this.applyLangs=this.applyLangs.bind(this);this.appendLanguageFile=this.appendLanguageFile.bind(this);this.main=a;this.hash=this.generateHash(c);
this.srcPath=d;Object.isString(c)&&(c=Hjson.parse(c));if(null==c.modInfo)throw this.modError("No ModInfo passed!",0),Error("Not a mod");if(null==c.modInfo.id)throw this.modError("No id in ModInfo passed!",0),Error("Not a mod");this.id=c.modInfo.id;this.name=null!=(b=c.modInfo.name)?b:"-";this.description=c.modInfo.description;this.preview=c.modInfo.preview;this.twitter=c.modInfo.twitter;this.weblink=c.modInfo.weblink;null!=c.modInfo.mail&&(this.mail="mailto:"+c.modInfo.mail);this.authors=null!=(f=
t.arrify(c.modInfo.authors,!1))?f:["-"];this.ignore=null!=(g=!1===c.modInfo.enabled)?g:!1;this.logLevel=null!=(h=c.modInfo.logLevel)?h:10;this.defaultLang=null!=(k=c.modInfo.defaultLang)?k:"en";this.version=this.getFullVersion(null!=(l=""+c.modInfo.version)?l:"0");this.dependencies=c.modInfo.dependencies;this.visible=null!=(m=c.modInfo.visible)?m:!0;this.mine=!1;if("undefined"!==typeof greenworks&&null!==greenworks&&isSteam){if(a=greenworks.getSteamId(),n=a.screenName,0<=F.call(this.authors,n))this.mine=
!0}else this.steam=null;this.hash=this.version;this.imageData=t.arrify(c.imageData);this.spriteSheets=t.arrify(c.spriteSheets);this.importData(c);this.sanityCheckData("","",c);this.modifications=t.arrify(c.modEntries);this.configSettings=c.configSettings;this.updateMetaData();this.featureCheck()};a.prototype.getFullVersion=function(a){for(a=a.split(".").slice(0,2);2>a.length;)a.push(0);return a.map(function(a){return J.parseInt(a)||0}).join(".")};a.prototype.updateMetaData=function(a){this.steam=
null;null!=a&&(this.steam="steam:"+a.steamId,this.score=a.score,this.votes=a.votes)};a.prototype.matchesVersionRange=function(a){var b;var d=null;var e=this.version.split(".");if(a.includes("..")){var f=a.split("..");a=this.getFullVersion(f[0]).split(".");0<f[1].length&&(d=this.getFullVersion(f[1]).split("."))}else d=a=this.getFullVersion(a).split(".");if(d)for(f=b=0;2>b;f=++b){if(e[f]<a[f]||e[f]>d[f])return!1}else for(f=d=0;2>d;f=++d)if(e[f]<a[f])return!1;return!0};a.prototype.generateHash=function(a){var b,
d;var e=JSON.stringify(a);a=0;if(0===e.length)return a;var f=d=0;for(b=e.length-1;0<=b?d<=b:d>=b;f=0<=b?++d:--d)f=e.charCodeAt(f),a=(a<<5)-a+f,a|=0;return a};a.prototype.loadHjsonData=function(a){a=O.readFile(O.modDir()+"/"+a);return Hjson.parse(a)};a.prototype.getPreviewPath=function(){var a=this;if(null!=this.preview&&window.isClient){var c=require("path");var d=this.imageData.find(function(b){return b.id===a.preview}).file;return c.resolve(window.rootPath,O.modDir(),d)}};a.prototype.importData=
function(a){var b;if(null!=a)if(Object.isArray(a))for(b=0;b<a.length;){var d=a[b];if(null!=d&&(this.importData(d),null!=d.import)){d=this.loadHjsonData(d.import);a.splice(b,1);var e=t.arrify(d);var f=0;for(d=e.length;f<d;f++){var g=e[f];a.splice(b,0,g);b+=1}--b}b+=1}else if(Object.isObject(a))for(b in a)d=a[b],null!=d&&this.importData(d)};a.prototype.featureCheck=function(){var a;this.featureList={};var c=this.modifications;var d=0;for(a=c.length;d<a;d++){var e=c[d];if(null!=e.targetId){var f=$jscomp.makeIterator(this.getEntryInfo(e,
!1));e=f.next().value;f.next();f=this.getSpecialFeatureName(e);null!=f&&this.addFeature(f,"special");e=this.getFeatureName(e);null!=e&&this.addFeature(e,"special")}else null!=e.id&&(e=this.getFeatureName(e.id),null!=e&&this.addFeature(e,"adds"))}};a.prototype.getSpecialFeatureName=function(a){if(a.includes("evt-harbor"))return"Harbor";if(a.includes("evt-village"))return"Village"};a.prototype.getFeatureName=function(a){switch(a.slice(0,3)){case "ex-":return"Expeditions";case "tl-":return"Tiles";case "evt":return"Events";
case "loc":return"Locations";case "act":return"Actions";case "gol":return"Goals";case "grp":return"Groups";case "pck":return"Pockets";case "bio":return"Biomes";case "it-":return"Items";case "zn-":return"Zones";case "cl-":return"Chat Lines";case "tg-":return"Tribe Gens";case "tgl":return"Tribe Gen Layers";case "il-":return"Item Lists";case "spr":return"Sprawls";case "df-":return"Dice Faces";case "dp-":return"Dice Patterns";case "pt-":return"Particles";case "dc-":return"Dice";case "buf":return"Buffs";
case "wd-":return"Worlds";case "na-":return"Names";case "np-":return"Name Pools";case "ch-":case "sp-":case "anm":case "npc":case "pl-":case "emy":return"Characters";case "st-":return"Status Effects";default:return null}};a.prototype.addFeature=function(a,c){c=void 0===c?"changes":c;var b;null==(b=this.featureList)[c]&&(b[c]={});null==this.featureList[c][a]?(this.featureList[c][a]={},this.featureList[c][a].count=1):this.featureList[c][a].count+=1};a.prototype.sanityCheckData=function(a,c,d){var b;
if(null!=d){var f=Object.keys(d);var g=0;for(b=f.length;g<b;g++){var h=f[g];var k=d[h];if(Object.isString(k)){(k.startsWith("'")||k.endsWith("'"))&&this.modWarn(c+" String "+k+" ("+(a+h)+") contains leading or trailing '. This is probably wrong.",5);"id"===h&&""===c&&(c=k);null!=c&&c.startsWith("cfg")&&this.modWarn(c+" cfg entities are deprecated, please use configSettings instead (http://curious-expedition.wikia.com/wiki/Modding:Config)");var l=h.toLowerCase();if(l.includes("music")||l.includes("sound")||
l.includes("sfx")||c.includes("sounds"))if(k.startsWith("mods/")&&this.modWarn(c+" Sound reference ("+(a+h)+") starts with mods, that is probably a mistake.",5),k.includes("/")||k.includes("\\"))d[h]="/"===k[0]||"\\"===k[0]?O.modDir()+k:O.modDir()+"/"+k}if(h.includes("flag")||h.includes("Flag"))Object.isString(k)||this.modWarn(c+" Flags ("+(a+h)+") aren't a string. This is probably wrong.",5);"object"===typeof k&&this.sanityCheckData(a+h+".",c,k)}}};a.prototype.applyEntries=function(){var a;this.modLog("Applying modifications",
11);null!=this.langData&&this.applyLangs();this.applyImages();var c=this.modifications;var d=0;for(a=c.length;d<a;d++){var e=c[d];this.applyEntry(e)}};a.prototype.applyEntry=function(a){var b;this.modLog("Processing "+(null!=(b=a.id)?b:a.targetId),11);if(null!=a.mode)this.applyEntryOld(a);else if(null!=a.targetId)switch(a.targetId[0]){case "+":this.addEntry(a,!1);break;case "-":this.removeEntry(a,!1);break;case "*":this.mergeEntry(a,!1);break;case "/":this.replaceEntry(a,!1);break;default:this.addEntry(a,
!1)}else this.addEntry(a)};a.prototype.applyEntryOld=function(a){try{var b=-1!==a.mode.indexOf("!");var d=a.mode.replace("!","");d=null!=d?d:"add";switch(d){case "add":this.addEntry(a,b);break;case "replace":this.replaceEntry(a,b);break;case "merge":this.mergeEntry(a,b);break;case "remove":this.removeEntry(a,b);break;default:this.modWarn("Invalid mode in entry("+a.id+"): "+d)}}catch(e){a=e,this.modError(a)}};a.prototype.getEntityObjs=function(a,c){c=void 0===c?null:c;var b;var e=[];null!=c&&(b=c.split("."));
c=this.findEntitiesById(a);var f=0;for(a=c.length;f<a;f++){var g=c[f];g={container:g.container,index:g.index};if(null!=b)try{e.add(this.getEntityProperty(g.container[g.index],b))}catch(h){}else g.container=config.entities,e.add(g)}return e};a.prototype.findEntitiesById=function(a){var b;var d=[];Object.isRegExp(a)||(a=new RegExp("^"+a+"$"));var e=config.entities;for(b in e){var f=e[b];a.test(f.id)&&(f={container:config.entities,index:b},d.add(f))}return d};a.prototype.getEntityProperty=function(a,
c){if(null!=a)return 1===c.length?{container:a,index:c[0]}:this.getEntityProperty(a[c[0]],c.slice(1))};a.prototype.getEntryInfo=function(a,c){c=void 0===c?!0:c;var b,e;var f=a.targetId;if(null!=f){["+","-","*","/"].includes(f[0])&&(f=f.slice(1));var g=a.targetSubId;if(f.includes("::")){var h=f.split("::");f=h[0];g=h[1];2!==h.length&&this.modWarn("Too many double colons in targetId "+a.targetId,3)}}c?(a=Object.clone(null!=(b=a.data)?b:a),null!=a.id&&(a.mod=this.id),Object.isObject(a)&&(null!=a.targetId&&
delete a.targetId,null!=a.targetSubId&&delete a.targetSubId)):a=null!=(e=a.data)?e:a;null!=f&&this.modLog("id:"+f+" sub:"+g,12);return[f,g,a]};a.prototype.addEntry=function(a,c){var b=$jscomp.makeIterator(this.getEntryInfo(a));var e=b.next().value;var f=b.next().value;b=b.next().value;var g=!1;if(null!=e){c=this.getEntityObjs(e,f);var h=0;for(a=c.length;h<a;h++){var k=c[h];try{var l=t.arrify(k.container[k.index]);l.push(b);k.container[k.index]=l;g=!0;this.modLog("Added data  to "+e+"::"+f+": "+JSON.stringify(b,
null,"\t"),11);this.modLog("Now: "+JSON.stringify(k.container[k.index],null,"\t"),11)}catch(m){k=m,this.modError(k)}}g||this.modError("Couldn't add data to "+e+"::"+f+": Not found",1)}else null==b.id?this.modError("Can not add new entity without an id (entry: '"+JSON.stringify(a,null,"\t")+"')",1):(e=this.getEntityObjs(b.id),0<e.length?c?this.modError("Couldn't add entity("+b.id+"): Already exists",1):(this.modWarn("Couldn't add entity("+b.id+"): Already exists, trying to merge instead",2),this.mergeEntry(a)):
(b.mod=this.id,config.entities[b.id]=b,this.modLog("Added data to config.entities: "+JSON.stringify(b,null,"\t"),11)))};a.prototype.replaceEntry=function(a,c){var b,e,f;var g=$jscomp.makeIterator(this.getEntryInfo(a));var h=g.next().value;var k=g.next().value;g=g.next().value;if(null==h)this.modError("Replace entry needs a targetId",1);else{var l=!1;var m=this.getEntityObjs(h,k);var n=0;for(b=m.length;n<b;n++){var q=m[n];null!=(null!=(e=q.container[q.index])?e.id:void 0)&&(g.id=q.container[q.index].id);
q.container[q.index]=g;l=!0;this.modLog("Replaced "+(null!=(f=q.container.id)?f:"entities")+"::"+q.index,11);this.modLog("Now: "+JSON.stringify(q.container[q.index],null,"\t"),11)}l||(c?this.modError("Couldn't replace entity("+h+"::"+k+"): Not found",1):(this.modWarn("Couldn't replace entity("+h+"::"+k+"): Not Found, adding instead",2),this.addEntry(a,!0)))}};a.prototype.mergeEntry=function(a,c){var b;var e=$jscomp.makeIterator(this.getEntryInfo(a));var f=e.next().value;var g=e.next().value;e=e.next().value;
var h=!1;if(null==f)this.modError("Merge entry needs a targetId",1);else{var k=this.getEntityObjs(f,g);var l=0;for(b=k.length;l<b;l++){var m=k[l];try{Object.merge(m.container[m.index],e),this.modLog("Merged in data to "+f+"::"+g+": "+JSON.stringify(e,null,"\t"),11),this.modLog("Now: "+JSON.stringify(m.container[m.index],null,"\t"),11),h=!0}catch(p){}}h||(c?this.modError("Couldn't merge entity("+a.targetId+"): Not found",1):(this.modWarn("Couldn't merge entity("+a.targetId+"): Not Found, adding instead",
2),this.addEntry(a,!0)))}};a.prototype.removeEntry=function(a,c){var b=$jscomp.makeIterator(this.getEntryInfo(a,!1));var e=b.next().value;var f=b.next().value;b=!1;if(null==e)this.modError("Remove entry needs a targetId",1);else{e=this.getEntityObjs(e,f);var g=0;for(f=e.length;g<f;g++)b=e[g],"function"===typeof b.container.splice?b.container.splice(b.index,1):delete b.container[b.index],b=!0;b?this.modLog("Removed "+a.targetId,11):c?this.modError("Couldn't remove entity("+a.targetId+"): Not found",
1):this.modWarn("Couldn't remove entity("+a.targetId+"): Not Found",2)}};a.prototype.applyImages=function(a){a=void 0===a?!1:a;var b,d;var e=this.main.r.img;var f=this.imageData;var g=0;for(b=f.length;g<b;g++){var h=f[g];if((!a||null!=h.preload&&h.preload)&&null!=h.file&&null!=h.id){null==h.type&&(h.type="img");var k=O.modDir()+"/"+h.file;h.file.includes("/")||h.file.includes("\\")||(k=""+h.file);e.addFakeSprite(h.id,k,h.type,this)}}b=this.spriteSheets;g=0;for(h=b.length;g<h;g++)f=b[g],(!a||null!=
f.preload&&f.preload)&&null!=f.file&&(k=O.modDir()+"/"+f.file,f.file.includes("/")||f.file.includes("\\")||(k=""+f.file),k=k.replace(".json",""),k=k.replace(".png",""),e.loadSpriteAtlas(k,f.hasTinted,this,null!=(d=f.type)?d:"img"))};a.prototype.loadPreview=function(){var a;var c=this.imageData;var d=0;for(a=c.length;d<a;d++){var e=c[d];if(e.id===this.preview){var f=O.modDir()+"/"+e.file;e.file.includes("/")||e.file.includes("\\")||(f=""+e.file);this.main.r.img.addFakeSprite(e.id,f,"img",this)}}};
a.prototype.loadLangs=function(a){this.defaultTexts=this.locTexts=null;var b=0;null!=this.defaultLang&&(b+=1,this.loadLanguageFile(this.defaultLang,function(){--b;if(0===b)return"function"===typeof a?a():void 0}));var d=this.main.getLangId();d!==this.defaultLang&&(b+=1,this.loadLanguageFile(d,function(){--b;if(0===b)return"function"===typeof a?a():void 0}))};a.prototype.loadLanguageFile=function(a,c){var b=this;var e=O.modDir()+"/"+this.id+"/langs/lang_"+a+".csv";this.modLog("Loading language file "+
e,11);O.readFileAsync(e,function(d){null!=d?a===b.defaultLang?b.defaultTexts=d:b.locTexts=d:a===b.defaultLang?b.modError("Couldn't load default language file "+e,0):b.modLog("Language file "+e+" for "+a+" not found.",5);return"function"===typeof c?c():void 0})};a.prototype.applyLangs=function(){this.modLog("Applying languages",11);null!=this.defaultLang&&this.appendLanguageFile(this.defaultLang);var a=this.main.getLangId();a!==this.defaultLang&&this.appendLanguageFile(a)};a.prototype.appendLanguageFile=
function(a){var b=a===this.defaultLang?this.defaultTexts:this.locTexts;null!=b?(this.modLog("Applying language "+a,8),this.main.appendLangTexts("Mod("+this.id+")",b,a)):this.modWarn("No language data for "+a)};a.prototype.modError=function(a,c){var b;(void 0===c?0:c)<=this.logLevel&&r.error(a,null!=(b=this.id)?b:this.srcPath)};a.prototype.modWarn=function(a,c){var b;(void 0===c?3:c)<=this.logLevel&&r.warn(a,null!=(b=this.id)?b:this.srcPath)};a.prototype.modLog=function(a,c){var b;(void 0===c?5:c)<=
this.logLevel&&r.info(a,null!=(b=this.id)?b:this.srcPath)};a.prototype.modifications=[];a.prototype.configSettings=[];a.prototype.dependencies=[];a.prototype.featureList=[];a.prototype.applied=!1;a.prototype.hash=null;return a}.call(this);if(window.isElectron){var Ga=require("path");var la=require("fs")}var aa=function(){};aa.baseDir=function(){return window.isClient?n.isMac()?"..":"../..":""};aa.modDir=function(){return window.isClient?n.isIO()?"mods":n.isMac()?"../mods":"../../mods":"mods"};aa.resolve=
function(a){null==window.rootPath||Ga.isAbsolute(a)||(a=Ga.join(window.rootPath,a));return a};aa.isDir=function(a){return window.isClient?(a=aa.resolve(a),la.lstatSync(a).isDirectory()):!0};aa.loadProfile=function(a,b){var c,d;if(n.isDemo())return null;var e=function(a){return JSON.parse(Base64.decode(a))};if("undefined"!==typeof require&&null!==require&&(la=require("fs"),Ga=require("path"),null!=la)){var f=aa.homeDirs(!0);var g=0;for(c=f.length;g<c;g++){var h=f[g];h=Ga.join(h,"TheCuriousExpedition",
a);try{var k=la.readFileSync(h,"utf8");r.info("loaded "+h);return e(k)}catch(l){r.info(h+" not found or not working")}}}if(n.canUseLocalStorage()){if(null!=window.localStorage[b])return e(window.localStorage[b])}else if(null!=(null!=(d=this.tempLocalStorage)?d[b]:void 0))return e(this.tempLocalStorage[b]);return null};aa.writeProfile=function(a,b,c){var d;if(!n.isDemo()){b=Base64.encode(b);if(window.isClient&&(la=require("fs"),Ga=require("path"),null!=la)){var e=aa.homeDirs();var f=0;for(d=e.length;f<
d;f++){var g=e[f];try{var h=la.statSync(g);if(!h.isDirectory())continue}catch(l){var k=l;continue}g=Ga.join(g,"TheCuriousExpedition/");try{la.mkdirSync(g)}catch(l){}g=Ga.join(g,a);try{la.writeFileSync(g+".tmp",b,"utf8"),la.renameSync(g+".tmp",g)}catch(l){k=l,r.error("failed to save file "+g+": error "+k)}return}}try{if(n.canUseLocalStorage())return window.localStorage[c]=b;this.tempLocalStorage||(this.tempLocalStorage={});return this.tempLocalStorage[c]=b}catch(l){return r.error("failed to save file "+
c+" to local storage: error "+k)}}};aa.deleteProfile=function(a,b){var c;n.canUseLocalStorage()&&null!=window.localStorage[b]&&delete window.localStorage[b];null!=(null!=(c=this.tempSaveObject)?c[b]:void 0)&&delete this.tempSaveObject[b];if("undefined"!==typeof require&&null!==require){la=require("fs");Ga=require("path");var d=aa.homeDirs(!0);var e=[];var f=0;for(c=d.length;f<c;f++){b=d[f];b=Ga.join(b,"TheCuriousExpedition");b=Ga.join(b,a);try{null!=la?e.push(la.unlinkSync(b)):e.push(void 0)}catch(g){e.push(r.log(b+
" does not exist"))}}return e}};aa.updateLoadingBar=function(){var a=100*(0<aa.resCount?aa.resDoneCount/aa.resCount:0);$("#progress div").css("width",a+"%");if(aa.resDoneCount>=aa.resCount&&null!=aa.onAllLoaded)return r.info("Loaded "+aa.resDoneCount+" resources"),aa.resCount=aa.resDoneCount=0,aa.onAllLoaded()};aa.onReadFileAsyncCompleted=function(){aa.resDoneCount+=1;return aa.updateLoadingBar()};aa.readFileAsync=function(a,b,c){c=void 0===c?"utf-8":c;if(window.isClient)try{var d=aa.resolve(a);if(la.existsSync(d))a=
d;else if(!la.existsSync(a)){r.error("readFileAsync: file "+a+" or resolved file "+d+" not found");b(null);return}aa.resCount+=1;return la.readFile(a,{encoding:c},function(a,c){a&&r.error(a);b(c);return aa.onReadFileAsyncCompleted()})}catch(e){return c=e,r.error(c),b(null),aa.onReadFileAsyncCompleted(),aa.displayLoadError(a,c)}else return aa.resCount+=1,$.ajax({async:!0,global:!1,url:a,dataType:"text",error:function(c,d,g){r.error(d+": "+g);b(null);aa.onReadFileAsyncCompleted();return aa.displayLoadError(a,
d+": "+g)},success:function(a){b(a);return aa.onReadFileAsyncCompleted()}})};aa.readFile=function(a,b){b=void 0===b?"utf-8":b;if(window.isClient)try{return a=aa.resolve(a),la.readFileSync(a,{encoding:b})}catch(c){return b=c,r.error(b),null}else return $.ajax({async:!1,global:!1,url:a,dataType:"text",error:function(b,d,e){r.error(d+": "+e);return aa.displayLoadError(a,d+": "+e)}}).responseText};aa.scanDir=function(a){return window.isClient?(a=aa.resolve(a),la.readdirSync(a)):[]};aa.removeFolder=function(a){var b;
if(window.isClient&&(a=this.resolve(a),la.existsSync(a))){var c=la.readdirSync(a);var d=0;for(b=c.length;d<b;d++){var e=c[d];e=Ga.join(a,e);la.lstatSync(e).isDirectory()?this.removeFolder(e):la.unlinkSync(e)}return la.rmdirSync(a)}};aa.removeFile=function(a){a=this.resolve(a);return la.unlinkSync(a)};aa.homeDirs=function(a){if("undefined"===typeof process||null===process)return[];a=[];var b=process.env;var c=b.HOME;var d=b.LOGNAME||b.USER||b.LNAME||b.USERNAME;"win32"===process.platform?(c=b.USERPROFILE||
b.HOMEDRIVE+b.HOMEPATH||c||"",this.checkAppDataDir()&&a.push(b.APPDATA+"/Maschinen-Mensch/"),a.push(c+"/Documents/")):"darwin"===process.platform?a.push((c||(d?"/Users/"+d:""))+"/Documents/"):"linux"===process.platform?(b=c||(0===process.getuid()?"/root":d?"/home/"+d:""),a.push(b+"/.config"),a.push(b)):a.push(c||"");a.push(".");return a};aa.checkAppDataDir=function(){la=require("fs");var a=process.env.APPDATA+"/Maschinen-Mensch/";var b=!1;try{var c=la.statSync(a);b=c.isDirectory()}catch(d){}if(b)return!0;
if(null!=la)try{return la.mkdirSync(a),!0}catch(d){return!1}};var O=aa;var Ua=function(a,b,c){var d=this;c=void 0===c?1:c;var e;this.onBufferLoaded=this.onBufferLoaded.bind(this);this.onDecodeSuccess=this.onDecodeSuccess.bind(this);this.onDecodeFailure=this.onDecodeFailure.bind(this);this.createSource=this.createSource.bind(this);this.isPlaying=this.isPlaying.bind(this);this.play=this.play.bind(this);this.stop=this.stop.bind(this);this.loop=this.loop.bind(this);this.getVolume=this.getVolume.bind(this);
this.setVolume=this.setVolume.bind(this);this.fadeTo=this.fadeTo.bind(this);this.fadeIn=this.fadeIn.bind(this);this.fadeOut=this.fadeOut.bind(this);n.assert(null!=a&&""!==a);n.assert(null!=b);this.context=b;this.sourceFile=a;this.looping=this.playing=!1;this.baseVolume=null!=c?c:1;this.gainNode=this.context.createGain();n.assert(null!=this.gainNode);this.gainNode.connect(this.context.destination);this.setVolume(100);var f=new XMLHttpRequest;f.open("GET",a,!0);f.responseType="arraybuffer";if(e=0<O.resCount)O.resCount+=
1;f.onload=function(){if(e)O.onReadFileAsyncCompleted();return d.onBufferLoaded(f.response)};f.send()};Ua.prototype.onBufferLoaded=function(a){n.assert(null!=this.context);null!=a?this.context.decodeAudioData(a,this.onDecodeSuccess,this.onDecodeFailure):r.error("Sound file loading failed for "+this.sourceFile)};Ua.prototype.onDecodeSuccess=function(a){n.assert(null!=this.context);this.audioBuffer=a;n.assert(null==this.source);this.playing&&this.play(this.playing,this.looping)};Ua.prototype.onDecodeFailure=
function(){r.error("Sound file decoding failed for "+this.sourceFile)};Ua.prototype.createSource=function(){var a=this;n.assert(null!=this.audioBuffer);n.assert(null!=this.gainNode);this.source=this.context.createBufferSource();this.source.connect(this.gainNode);this.source.buffer=this.audioBuffer;this.source.loop=this.looping;this.source.onended=function(){a.source=null;return a.playing=!1};if("function"===typeof this.onSourceCreated)this.onSourceCreated()};Ua.prototype.isPlaying=function(){return this.playing};
Ua.prototype.play=function(a,b){a=void 0===a?!0:a;n.assert(null!=this.context);"suspended"===this.context.state&&this.context.resume();this.playing&&null!=this.source&&(this.source.onended=null,this.source.stop(),this.source=null);this.playing=a;this.audioBuffer&&this.playing&&(this.createSource(),n.assert(this.source),this.source.start(0));return this};Ua.prototype.stop=function(){return this.play(!1)};Ua.prototype.loop=function(a){a=void 0===a?!0:a;if(this.looping===a)return this;this.looping=a;
null!=this.source&&(this.source.loop=this.looping);return this};Ua.prototype.getVolume=function(){return this.volume};Ua.prototype.setVolume=function(a){n.assert(null!=this.gainNode);n.assert(null!=this.baseVolume);this.volume=J.clamp(a,0,100);this.gainNode.gain.value=this.volume/100*this.baseVolume;return this};Ua.prototype.fadeTo=function(a,b,c){var d=this;if(null!=this.timerID){if(this.currentFadeTarget===a)return this;clearTimeout(this.timerID);this.timerID=null}this.currentFadeTarget=a;if(this.volume!==
a){var e=this.volume;var f=b/Math.abs(e-this.currentFadeTarget);var g=function(){return d.timerID=setTimeout(function(){if(e<d.currentFadeTarget&&d.volume<d.currentFadeTarget)return d.setVolume(d.volume+1),g();if(e>d.currentFadeTarget&&d.volume>d.currentFadeTarget)return d.setVolume(d.volume-1),g();d.timerID=null;return"function"===typeof c?c():void 0},f)};null!=this.source?(this.playing||this.play(!0),g()):this.onSourceCreated=g;return this}};Ua.prototype.fadeIn=function(a,b){a=void 0===a?1E3:a;
this.playing&&null!=this.source||this.setVolume(0);this.fadeTo(100,a,b);return this};Ua.prototype.fadeOut=function(a,b){this.fadeTo(0,void 0===a?1E3:a,b);return this};var Oc=Ua;var bb=function(){var a=function(){};a.drawPyramidPanel=function(b,c,d,e,f,g){if(a.disableIOUI)return null;var h=null;var k=b.r.s;var l=null!=b.ioInv.userSecure.alphaKey;var m=0<b.iohighscore.goalScores.length;var n=125*k;b.r.drawPanel(config.panel.newsFrame,c,d,n,l?130*k:100*k);b.r.drawSprite("pyramid_panel.png",c+n/2,d+4*
k,{halign:"center",scale:1/3});d+=60*k;m=l?q.toText("txt-io-pyramid-found"):m?q.toText("txt-io-pyramid-found-other").replace("$user",b.iohighscore.goalScores[0].displayname):q.toText("txt-io-pyramid-not-found");b.r.drawWrappedText(m,c+n/2,d,n-10*k,{halign:"center",fillColor:"white",font:config.fonts.technicalSmall});l&&(d+=35*k,l=n-25*k,k*=25,b.r.drawButton(q.toText("txt-io-pyramid-activate"),c+n/2,d,l,k,e,f,g,{font:config.fonts.themedSmall,os:0})&&(h={id:"alphaActivate"}));return h};a.drawCE2Panel=
function(a,c,d,e,f,g){var b=null;var k=a.r.s;var l=window.isSteam||!window.isClient;var m=125*k;var n=130*k;var r=m-25*k;var t=30*k;l||(n-=t+5*k);a.r.drawPanel(config.panel.newsFrame,c,d,m,n);a.r.drawSprite("title_ce2.png",c+m/2,d+4*k,{halign:"center",valign:"top",scale:1/3});d+=58*k;l&&(n=q.toText("txt-ce2-wishlist"),a.r.drawButton(n,c+m/2,d,r,t,e,f,g,{font:config.fonts.themedSmall,os:0})&&(b={id:"ce2wishlist"}),d+=t+5*k);n=q.toText("txt-ce2-alpha-signup");a.r.drawButton(n,c+m/2,d,r,t,e,f,g,{font:config.fonts.themedSmall,
os:0})&&(b={id:"alphaSignup"});return b};a.drawAlphaAccessPanel=function(b,c,d,e){var f;if(a.disableIOUI)return null;var g=$jscomp.makeIterator(b.r.getCanvasSize());var h=g.next().value;var k=g.next().value;var l=null;var m=b.r.s;var n=25*m+Math.floor(12*Math.sin(b.r.timeTotal));b.r.drawSprite("ce2_logo.png",h/2,n,{halign:"center",valign:"top",scale:1/3});var r=400*m;g=175*m;h=h/2-r/2;n=125*m;b.r.drawPanel(config.panel.newsFrame,h,n,r,g);var t=h+90*m;var u=n+15*m;b.r.drawSprite("mr_slippers.png",
t,u,{halign:"center",valign:"top",scale:.2});u+=125*m;b.r.drawText(q.toText("txt-io-alpha-yourkey"),t,u,{font:config.fonts.themedLarge,halign:"center"});b.r.drawText(b.ioInv.userSecure.alphaKey,t,u+20*m,{font:config.fonts.themedLarge,halign:"center"});t=h+r-240*m;u=n+10*m;b.r.drawWrappedText(q.toText("txt-io-alpha-instructions-header"),t,u,220*m,{font:config.fonts.technicalLarge,halign:"left"});var v=["txt-io-alpha-instructions-1","txt-io-alpha-instructions-2","txt-io-alpha-instructions-3","txt-io-alpha-instructions-4"];
u+=30*m;var y=0;for(f=v.length;y<f;y++){var x=v[y];b.r.drawWrappedText(q.toText(x),t+10*m,u,220*m,{font:config.fonts.technicalSmall,halign:"left"});u+=15*m}v=125*m;x=40*m;u=n+g-60*m;b.r.drawButton(q.toText("txt-io-alpha-join"),t+120*m,u,v,x,c,d,e,{font:config.fonts.themedLarge,os:0})&&(l={id:"discord"});v=100*m;x=25*m;b.r.drawButton(q.toText("txt-generic-back"),h+r/2,k-x-20*m,v,x,c,d,e,{font:config.fonts.themedLarge,os:0})&&(l={id:"alphaPanelBack"});return l};a.disableIOUI=!0;return a}.call(this);
var Mc=["getMostGoals","getFastestGoals"];var Nc="getHighscorePage getHighscorePageForUser getWorldData getUsers getBiomeData getClaimData postHighscore claimBiome setLocationFlags addDeathRecord clearDeathRecord addPartyLeg unlockHub unlockGoal getUnlockedHubs getGoalScores getSaveGame setSaveGame addLiveLog refreshUserCache getWorldForSeed setTransactionNotified performPurchase resetShowUser getStatsForUser getConfig".split(" ");var eb={worldClaim:0,betaWorld:1,keyActivation:2,foundPyramid:3,topScore:4,
foundHub:5};var ea=function(){var a=function(){};a.addCloudFunction=function(b){return a[b]=function(a,d){Parse.Cloud.run(b,a).then(function(a){return d(a)},function(a){return d({error:a})})}};a.addHelperFunction=function(b){a[b]=function(c,d){c.userID=window.iomp.parseUser.id;c.sessionToken=window.iomp.parseUser.getSessionToken();$.ajax({url:a.helperURL+"/"+b,type:"POST",data:JSON.stringify(c),contentType:"application/json"}).done(function(a,b){try{d(a)}catch(g){a=g,r.error(a)}}).fail(function(a,
b,c){try{d({error:c})}catch(h){a=h,r.error(a)}})}};a.helperURL="undefined"!==typeof debug&&null!==debug&&debug.isDevMode?"http://localhost:3456":"https://ce-rivals-server.j.layershift.co.uk";return a}.call(this);var Bc=0;for(x=Mc.length;Bc<x;Bc++){var Cc=Mc[Bc];ea.addCloudFunction(Cc)}var Dc=0;for(E=Nc.length;Dc<E;Dc++)Cc=Nc[Dc],ea.addHelperFunction(Cc);var Ac={newTrek:0,foundSeal:1};var U=function(a){var b=this;this.getWorldForSeed=this.getWorldForSeed.bind(this);this.initWorldSeed=this.initWorldSeed.bind(this);
this.getConfig=this.getConfig.bind(this);this.helperServerConnect=this.helperServerConnect.bind(this);this.refreshLocalUserOnServer=this.refreshLocalUserOnServer.bind(this);this.getPortrait=this.getPortrait.bind(this);this.addParseUserToDB=this.addParseUserToDB.bind(this);this.fireBiomeCallbacks=this.fireBiomeCallbacks.bind(this);this.getBiomeRecord=this.getBiomeRecord.bind(this);this.addPlayerLeg=this.addPlayerLeg.bind(this);this.getLegForBiome=this.getLegForBiome.bind(this);this.parseLocationFlags=
this.parseLocationFlags.bind(this);this.setLocationFlags=this.setLocationFlags.bind(this);this.parseDeathRecord=this.parseDeathRecord.bind(this);this.addDeathRecord=this.addDeathRecord.bind(this);this.clearDeathRecord=this.clearDeathRecord.bind(this);this.checkClaimBiome=this.checkClaimBiome.bind(this);this.parseClaimRecord=this.parseClaimRecord.bind(this);this.displayClaim=this.displayClaim.bind(this);this.getNumClaimsForNextMedal=this.getNumClaimsForNextMedal.bind(this);this.claimBiome=this.claimBiome.bind(this);
this.handleNewHubUnlockedByPlayer=this.handleNewHubUnlockedByPlayer.bind(this);this.getGoalScores=this.getGoalScores.bind(this);this.requestHubInfo=this.requestHubInfo.bind(this);this.unlockHub=this.unlockHub.bind(this);this.unlockGoal=this.unlockGoal.bind(this);this.handleClaimInfo=this.handleClaimInfo.bind(this);this.requestClaimInfo=this.requestClaimInfo.bind(this);this.addLiveLog=this.addLiveLog.bind(this);this.clearLQForScores=this.clearLQForScores.bind(this);this.setLQForScores=this.setLQForScores.bind(this);
this.setupGhostsQuery=this.setupGhostsQuery.bind(this);this.initWebsocketClient=this.initWebsocketClient.bind(this);this.handleUserStatUpdate=this.handleUserStatUpdate.bind(this);this.initLiveQuery=this.initLiveQuery.bind(this);this.getUser=this.getUser.bind(this);this.flushPendingUserQueries=this.flushPendingUserQueries.bind(this);this.resetForNewGame=this.resetForNewGame.bind(this);this.setTransactionNotified=this.setTransactionNotified.bind(this);this.performPurchase=this.performPurchase.bind(this);
this.addLeg=this.addLeg.bind(this);this.getIsPostingHighscore=this.getIsPostingHighscore.bind(this);this.postCurrHighscore=this.postCurrHighscore.bind(this);this.postHighscore=this.postHighscore.bind(this);this.getHighscorePage=this.getHighscorePage.bind(this);this.getHighscorePageForUser=this.getHighscorePageForUser.bind(this);this.getStatsForUser=this.getStatsForUser.bind(this);this.storeSaveData=this.storeSaveData.bind(this);this.getSaveData=this.getSaveData.bind(this);this.addNotification=this.addNotification.bind(this);
this.isServerOK=this.isServerOK.bind(this);this.isServerVersionIncompatible=this.isServerVersionIncompatible.bind(this);this.getServerText=this.getServerText.bind(this);this.refreshUserData=this.refreshUserData.bind(this);this.drawShopButton=this.drawShopButton.bind(this);this.isStoreOpen=this.isStoreOpen.bind(this);this.openStore=this.openStore.bind(this);this.queueSave=this.queueSave.bind(this);this.tick=this.tick.bind(this);this.drawNotifications=this.drawNotifications.bind(this);this.parseUser=
a;this.userDB={};this.pendingUserCallbacks={};this.pendingUserQueries=[];this.biomeRecords={};this.pendingBiomeCallbacks={};this.portraitCache={};this.notifications=[];this.worldSeedCache={};this.scoreLQCallback={};this.storeOpenState=0;null!=this.parseUser&&(debug.disableIOMP?this.addParseUserToDB(this.parseUser):(this.getUser(this.parseUser.id,function(a){}),Promise.resolve().then(function(){return b.flushPendingUserQueries()})))};U.prototype.getWorldForSeed=function(a){var b=this;if(debug.disableIOMP)return Promise.resolve(1);
if(a===this.worldData.worldSeed)return Promise.resolve(this.worldData.worldID);if(null!=this.worldSeedCache[a])return Promise.resolve(this.worldSeedCache[a]);null==this.worldSeedLookups&&(this.worldSeedLookups={});if(null!=this.worldSeedLookups[a])return this.worldSeedLookups[a];var c=new Promise(function(c,e){return ea.getWorldForSeed({seed:a},function(d){if(d.error)return e(d.error);b.worldSeedCache[a]=d;c(d);return delete b.worldSeedLookups[a]})});return this.worldSeedLookups[a]=c};U.prototype.initWorldSeed=
function(a){this.worldData={worldSeed:a.worldSeed,worldID:a.worldID,worldStart:a.worldStart,worldEnd:a.worldEnd};return this.ioSeed=null!=this.worldData.worldSeed?parseInt(this.worldData.worldSeed):0};U.prototype.getConfig=function(){var a;return $jscomp.asyncExecutePromiseGeneratorProgram(function(b){if(1==b.nextAddress)return debug.disableIOMP?b.yield(Parse.Config.get(),3):b.return(new Promise(function(a,b){return ea.getConfig({},function(c){return null!=c.error?b(c.error):a(c)})}));a=b.yieldResult;
return b.return({privacyPolicyUpdated:a.get("privacyPolicyUpdated").getTime(),disableIOUI:a.get("disableIOUI")})})};U.prototype.helperServerConnect=function(){var a=this,b,c,d,e;if(debug.disableIOMP||debug.iompServerOnClient){r.log("IO;IOMP is disabled; creating fake world");var f={world:{worldSeed:null!=(b=window.worldSeed)?b:1337,worldID:null!=(c=window.worldID)?c:1,worldStart:null!=(d=window.worldStart)?d:(new Date).getTime(),worldEnd:null!=(e=window.worldEnd)?e:null},version:n.getVersionString()};
this.initWorldSeed(f.world);return Promise.resolve(f)}r.log("IO;Connecting to iomp server at "+ea.helperURL);return new Promise(function(b,c){ea.getWorldData({},function(d){var e;if(null!=d.error)d.serverURL=ea.helperURL,r.info("IOMP;getWorldData response error: "+d.error),null==window.debug&&(window.debug={}),window.debug.disableIOMP=!0,d.error.includes("Invalid token")?(Parse.User.logOut(),location.reload()):b(d);else if(null!=d.world){logs.iomp&&r.info("IOMP;getWorldData OK");a.initWorldSeed(d.world);
var f={medals:d.userSecure.medals,items:d.userSecure.items};bb.disableIOUI||(f.alphaKey=d.userSecure.alphaKey);null!=(null!=(e=a.main)?e.ioInv:void 0)?a.main.ioInv.initUserData(f):a.userSecureData=f;b(d)}else c({serverURL:ea.helperURL})})})};U.prototype.refreshLocalUserOnServer=function(){return ea.refreshUserCache({},function(){})};U.prototype.getPortrait=function(a,b,c){if(null==a||""===a||null==b||""===b||0===b||null==c||""===c)return null;var d=""+a+b+c;if(null!=this.portraitCache[d])return this.portraitCache[d];
var e=new Ta(this.main.r,this.main.r.sfx,this.main);e.setup(a,b);a=e.genSpriteLayers(c);e=e.genSprite(a,e.colorTable);return this.portraitCache[d]=e.portraitSmall};U.prototype.addParseUserToDB=function(a){var b,c;a={userID:a.id,displayName:null!=(b=a.get("displayName"))?b:a.get("username"),colour:null!=(c=a.get("colour"))?c:"#000000"};return this.userDB[a.userID]=a};U.prototype.fireBiomeCallbacks=function(a){var b;if(null!=this.pendingBiomeCallbacks[a]){var c=this.pendingBiomeCallbacks[a];var d=0;
for(b=c.length;d<b;d++){var e=c[d];try{e(this.biomeRecords[a])}catch(f){e=f,r.error(e)}}return delete this.pendingBiomeCallbacks[a]}};U.prototype.getBiomeRecord=function(a,b){var c=this,d,e,f,g,h;if(debug.disableIOMP||debug.drawAllTiles)b(null);else if(a in this.biomeRecords)try{b(this.biomeRecords[a])}catch(w){b=w,r.error(b)}else if(null!=this.pendingBiomeCallbacks[a])this.pendingBiomeCallbacks[a].push(b);else{this.pendingBiomeCallbacks[a]=[b];b=this.main.worldGenIO.world.getBiomePosFromIdx(a);var k=
Math.floor(b.x/config.io.iompBiomeRequestGridSize);var l=Math.floor(b.y/config.io.iompBiomeRequestGridSize);b=[];var m=d=e=k*config.io.iompBiomeRequestGridSize;for(f=(k+1)*config.io.iompBiomeRequestGridSize;e<=f?d<f:d>f;m=e<=f?++d:--d){var p=k=g=l*config.io.iompBiomeRequestGridSize;for(h=(l+1)*config.io.iompBiomeRequestGridSize;g<=h?k<h:k>h;p=g<=h?++k:--k)p=this.main.worldGenIO.world.getBiomeIdx(new u(m,p)),b.push(p),p!==a&&null==this.pendingBiomeCallbacks[p]&&(this.pendingBiomeCallbacks[p]=[])}b=
{seed:this.ioSeed,biomeIDs:b};logs.iomp&&r.info("IOMP;Requesting iomp data for "+b.biomeIDs.length+" biomes");ea.getBiomeData(b,function(b){var d,e,f,g;if(null!=b.error)r.error("Get biome dict failed: "+b.error);else{var h=b.biomes;var k=0;for(d=h.length;k<d;k++){var l=h[k];a=l.biomeID;logs.iomp&&r.info("IOMP;Received iomp data biome "+a);if(null!=l.legs){var m=l.legs;var p=0;for(e=m.length;p<e;p++){var q=m[p];q=b.legs[q];n.assert(null!=q);c.addPlayerLeg(q)}delete l.legs}c.biomeRecords[a]={biomeID:a,
claim:c.parseClaimRecord(l.claim),deathRecords:(null!=(f=l.deathRecords)?f:[]).map(function(a){return c.parseDeathRecord(a)}),locationFlags:(null!=(g=l.locationFlags)?g:[]).map(function(a){return c.parseLocationFlags(a)})};c.fireBiomeCallbacks(a);n.assert(null==c.pendingBiomeCallbacks[a])}}})}};U.prototype.addPlayerLeg=function(a){null==this.unplayedPartyLegs&&(this.unplayedPartyLegs=[]);null==this.addedLegs&&(this.addedLegs=[]);var b=a.id;if(!this.addedLegs.includes(b)){this.addedLegs.push(b);var c=
a.et;var d=a.es;b=a.eg;var e=a.ui;n.assert(null!=c&&null!=d&&null!=b&&null!=e);var f=""+e+c+d+b;var g=this.main.party.getExplorer();if(null!=g&&(g=""+this.parseUser.id+g.sourceTribeGenId+g.sourceTribeGenSeed+g.gender,g===f))return;d={userID:e,explorerTribe:c,explorerGender:b,explorerSeed:d,partyMembers:a.pm,path:[]};b=a.bs;f=a.ps;n.assert(0<b.length&&f.length===b.length);a=c=0;for(e=b.length;0<=e?c<e:c>e;a=0<=e?++c:--c)d.path.push({biome:b[a],lp:f[a]});return this.unplayedPartyLegs.push(d)}};U.prototype.getLegForBiome=
function(a){var b,c,d,e;var f=[];var g=null!=(b=this.unplayedPartyLegs)?b:[];b=c=0;for(d=g.length;c<d;b=++c){var h=g[b];var k=h.path;var l=0;for(e=k.length;l<e;l++){var m=k[l];if(m.biome===a){l=!0;k=h.path;h=0;for(e=k.length;h<e;h++)if(m=k[h],m=this.main.worldGenIO.world.biomes[m.biome],null==m||!m.generated){l=!1;break}l&&f.push(b);break}}}if(0===f.length)return null;a=f.sample();h=this.unplayedPartyLegs[a];this.unplayedPartyLegs.splice(a,1);return h};U.prototype.parseLocationFlags=function(a){return null==
a?null:{flags:a.flags,localPos:a.localPos}};U.prototype.setLocationFlags=function(a,b,c){var d=this;debug.disableIOMP||(c={seed:this.ioSeed,flags:t.parseFlags(c),localPos:b,biomeID:a},ea.setLocationFlags(c,function(c){var e;if(null!=c.error)r.info("IOMP;setLocationFlags response error: "+c.error);else if(logs.iomp&&r.info("IOMP;setLocationFlags OK, row "+c),a in d.biomeRecords){var g=!1;c=d.parseLocationFlags(c);var h=d.biomeRecords[a].locationFlags;var k=0;for(e=h.length;k<e;k++){var l=h[k];if(b.eq(l.localPos)){g=
!0;l.flags=c.flags;break}}g||d.biomeRecords[a].locationFlags.push(c)}}))};U.prototype.parseDeathRecord=function(a){return null==a?null:{userID:a.userID,localPos:a.localPos,rowID:a.rowID}};U.prototype.addDeathRecord=function(a,b,c,d){var e=this;debug.disableIOMP||ea.addDeathRecord({seed:this.ioSeed,localPos:b,biomeID:a,reason:c,turns:d,score:this.main.party.fame,highscoreRow:this.highscoreRow},function(b){null!=b.error?r.warn("IOMP;addDeathRecord response error: "+b.error):(logs.iomp&&r.info("IOMP;addDeathRecord OK"),
null!=e.biomeRecords[a]&&e.biomeRecords[a].deathRecords.push(e.parseDeathRecord(b)))})};U.prototype.clearDeathRecord=function(a,b,c){var d=this;debug.disableIOMP||ea.clearDeathRecord({seed:this.ioSeed,deathRecordUserID:c,localPos:b,biomeID:a},function(b){var c,e;if(null!=b.error)r.warn("IOMP;clearDeathRecord response error: "+b.error);else if(logs.iomp&&r.info("IOMP;clearDeathRecord OK, row "+b),a in d.biomeRecords){var h=d.biomeRecords[a].deathRecords;var k=c=0;for(e=h.length;c<e;k=++c){var l=h[k];
if(l.rowID===b){d.biomeRecords[a].deathRecords.splice(k,1);break}}}})};U.prototype.checkClaimBiome=function(a){if(!a.blocking){var b=a.scoreLocations.length;var c=a.scoreLocations.count(function(a){return a.known});if(b===c&&0<b){if(null!=a.claim)return!0;a=this.main.world.getBiomeIdx(a.pos);this.claimBiome(a);return!0}return!1}};U.prototype.parseClaimRecord=function(a){return null==a?null:{explorerTribe:a.explorerTribe,explorerSeed:a.explorerSeed,explorerGender:a.explorerGender,claimDate:a.claimDate,
userID:a.userID}};U.prototype.displayClaim=function(a,b){var c=this;return new Promise(function(d,e){return c.getUser(b.userID,function(f){return null!=f?(f={user:f,record:b},c.main.worldGenIO.receiveClaimInfo(a,f),d()):e()})})};U.prototype.getNumClaimsForNextMedal=function(){var a=this,b,c;var d=null!=(b=null!=(c=this.main.worldGenIO.topClaimScores.find(function(b){return b.userID===a.main.user.id}))?c.points:void 0)?b:0;b=1;b<=d&&(b=6);for(b<=d&&(b=11);b<=d;)b+=10;return b-d};U.prototype.claimBiome=
function(a){var b=this,c;var d=function(c){c=b.parseClaimRecord(c);null!=b.biomeRecords[a]&&(b.biomeRecords[a].claim=c);return b.displayClaim(a,c).then(function(){if(c.userID===b.parseUser.id&&null!=b.main.party){logs.iomp&&r.log("IOMP;Claimed biome "+a);var d=b.main.worldGenIO.difficultyLvls.indexOf(f);b.main.party.incStatRankingGift("region-"+d);b.main.party.changeFame(config.io.famePerBiomeDiscovery[d]);return b.main.displayClaimNotification(a)}})};var e=this.main.worldGenIO.biomes[a];var f=e.worldLvl;
var g=e.worldSegment;this.main.worldGenIO.difficultyLvls.indexOf(f);e=this.main.party.getExplorer();debug.disableIOMP?(e={userID:this.parseUser.id,explorerTribe:e.sourceTribeGenId,explorerSeed:e.sourceTribeGenSeed,explorerGender:e.gender,claimDate:Date.now()},null==(c=this.biomeRecords)[a]&&(c[a]={}),d(e)):ea.claimBiome({ioSeed:this.ioSeed,biomeID:a,segmentID:g,explorerTribe:e.sourceTribeGenId,explorerSeed:e.sourceTribeGenSeed,explorerGender:e.gender},function(a){null!=a.error?r.error("IOMP;failed adding claim record: "+
a.error):null!=a&&d(a)})};U.prototype.handleNewHubUnlockedByPlayer=function(a){var b=this.main.worldGenIO.difficultyLvls.indexOf(this.main.worldGenIO.biomes[a].worldLvl);this.main.worldGenIO.handleHubUnlock(a,this.parseUser.id,Date.now(),!1);this.main.party.incStatRankingGift("hub-"+b);this.main.party.changeFame(config.io.famePerHubUnlock[b]);if(null!=this.main.exped)return this.main.exped.changeCompassScore(this.main.exped.compassScore)};U.prototype.getGoalScores=function(a,b){if(debug.disableIOMP)b([]);
else{var c={seed:this.ioSeed,numScores:a};logs.iomp&&r.log("IOMP;querying "+a+" goalscores");ea.getGoalScores(c,function(a){null!=a.error?(r.warn("getGoalScores failed: "+a.error),b([])):b(a)})}};U.prototype.requestHubInfo=function(a){debug.disableIOMP?a([]):ea.getUnlockedHubs({seed:this.ioSeed},function(b){null!=b.error?(r.warn("requestHubInfo failed: "+b.error),a([])):a(b)})};U.prototype.unlockHub=function(a){var b=this;if(debug.disableIOMP)this.handleNewHubUnlockedByPlayer(a);else{var c=this.main.worldGenIO.biomes[a].worldSegment;
ea.unlockHub({seed:this.ioSeed,biomeID:a,segmentID:c},function(c){null!=c.error?r.error("IOMP;failed unlocking hub record: "+c.error):b.handleNewHubUnlockedByPlayer(a)})}};U.prototype.unlockGoal=function(){var a=this;if(!debug.disableIOMP){var b=this.main.party.getExplorer();ea.unlockGoal({seed:this.ioSeed,explorerTribe:b.sourceTribeGenId,explorerSeed:b.sourceTribeGenSeed,explorerGender:b.gender},function(b){null!=b.error?r.error("IOMP;failed unlocking goal: "+b.error):(a.main.party.incStatRankingGift("goal"),
a.main.party.changeFame(config.io.fameForGoalUnlock))})}};U.prototype.handleClaimInfo=function(a,b,c){var d=this;return function(a,c){var e=a.biomeID;var f=a.claim;return d.getUser(f.userID,function(a){try{var g={user:a,record:d.parseClaimRecord(f)};return b(e,g,c)}catch(m){return a=m,r.error(a)}})}(a,void 0===c?!1:c)};U.prototype.requestClaimInfo=function(a){var b=this;debug.disableIOMP?a(null):ea.getClaimData({seed:this.ioSeed},function(c){var d;if(null!=c.error){r.error("IOMP;failed getting claim info: "+
c.error);try{a([])}catch(g){c=g,r.error(c)}}else{logs.iomp&&r.log("IOMP;requestClaimInfo returned "+c.length+" claimed biomes");var e=0;for(d=c.length;e<d;e++){var f=c[e];b.handleClaimInfo(f,a)}}})};U.prototype.addLiveLog=function(a,b,c){if(!debug.disableIOMP){var d=this.main.worldGenIO.biomes[a].worldSegment;ea.addLiveLog({seed:this.ioSeed,logType:b,biomeID:a,keysDict:c,segmentID:d},function(a){null!=a&&null!=a.error?r.info("IOMP;addLiveLog response error: "+a.error):logs.iomp&&r.info("IOMP;addLiveLog OK")})}};
U.prototype.clearLQForScores=function(a){if(null!=this.wsClient&&null!=this.scoreLQCallback[a]&&(delete this.scoreLQCallback[a],null!=this.wsClient))return this.wsClient.emit("scoreLQClear",a)};U.prototype.setLQForScores=function(a,b,c,d){if(null!=this.wsClient)return this.scoreLQCallback[d]=a,this.wsClient.emit("scoreLQ",{min:b,max:c,id:d})};U.prototype.setupGhostsQuery=function(a){var b,c,d,e,f,g;if(!debug.disableIOMP&&a!==this.lastGhostsQueryBiome){this.lastGhostsQueryBiome=a;a=this.main.worldGenIO.world.getBiomePosFromIdx(a);
var h=[];var k=b=d=a.x-1;for(e=a.x+1;d<=e?b<=e:b>=e;k=d<=e?++b:--b){var l=c=f=a.y-1;for(g=a.y+1;f<=g?c<=g:c>=g;l=f<=g?++c:--c)l=this.main.worldGenIO.world.getBiomeIdx(new u(k,l)),h.push(l)}this.wsClient.emit("ghosts",h)}};U.prototype.initWebsocketClient=function(){var a=this;this.wsClient=io(ea.helperURL,{query:"userID="+this.parseUser.id+"&token="+this.parseUser.getSessionToken()});this.wsConnected=!0;this.wsClient.on("connect",function(){a.wsConnected=!0;return r.log("IOMP;wsClient connect")});
this.wsClient.on("disconnect",function(){a.wsConnected=!1;return r.log("IOMP;wsClient disconnect")});this.wsClient.on("connect_failed",function(){a.wsConnected=!1;return r.log("IOMP;wsClient connect_failed")});this.wsClient.on("connect_error",function(){a.wsConnected=!1;return r.log("IOMP;wsClient connect_error")});this.wsClient.on("connect_timeout",function(){a.wsConnected=!1;return r.log("IOMP;wsClient connect_timeout")});this.wsClient.on("reconnect_failed",function(){a.wsConnected=!1;return r.log("IOMP;wsClient connect_failed")});
this.wsClient.on("io_handshake",function(b){a.wsConnected=!0;a.wsData=b;if(a.wsData.worldData.worldID===a.worldData.worldID&&a.worldData.worldSeed===a.wsData.worldData.worldSeed)return a.initWorldSeed(a.wsData.worldData);null==window.debug&&(window.debug={});return window.debug.disableIOMP=!0});return this.wsClient};U.prototype.handleUserStatUpdate=function(a){var b;if(null!=this.userDB[a.userID])return null==(b=this.userDB[a.userID]).stats&&(b.stats={}),this.userDB[a.userID].stats[a.stat]=a.value};
U.prototype.initLiveQuery=function(a){var b=this;if(!debug.disableIOMP&&(null==this.wsClient&&this.initWebsocketClient(),null!=this.wsClient)){this.wsClient.on("medalsChange",this.main.ioInv.handleMedalsChange);this.wsClient.on("itemAdded",this.main.ioInv.handleItemAdded);this.wsClient.on("itemRemoved",this.main.ioInv.handleItemRemoved);this.wsClient.on("userStatUpdate",this.handleUserStatUpdate);if(!bb.disableIOUI)this.wsClient.on("alphaKeyGiven",this.main.ioInv.handleAlphaKeyGiven);this.wsClient.on("newLeg",
function(a){logs.iomp&&r.info("IOMP;new leg receieved");b.addPlayerLeg(a)});this.wsClient.on("scoreLQUpdate",function(a){logs.iomp&&r.info("IOMP;new score LQ update");var c=a.id;if(b.scoreLQCallback[c])b.scoreLQCallback[c](a.record)});this.wsClient.on("claim",function(c){logs.iomp&&r.info("IOMP;new claim receieved");b.handleClaimInfo(c,a,!0)});this.wsClient.on("death",function(a){var c;logs.iomp&&r.info("IOMP;death sub received");var e=a.userID;if(e!==b.parseUser.id){var f=a.biomeID;var g=a.score;
var h=(null!=(c=a.turns)?c:0)+1;b.getUser(e,function(a){var c=b.main.worldGenIO.biomes[f];null!=a&&null!=c&&(c=b.main.worldGenIO.worldSegmentList[c.worldSegment],a=q.parse("txt-io-livelog-death").replace("$user",a.displayName).replace("$segment",c.name).replace("$fame",g).replace("$days",h),b.addNotification(a))})}});this.wsClient.on("hubUnlock",function(a){logs.iomp&&r.info("IOMP;Hub sub received");b.main.worldGenIO.handleHubUnlock(a.biomeID,a.userID,a.unlockDate)});this.wsClient.on("goalUnlock",
function(a){var c;logs.iomp&&r.info("IOMP;Goal sub: record created");var e=a.userID;if(null!=b.userDB[e]){var f=null!=(c=b.userDB[e].goalCount)?c:0;b.userDB[e].goalCount=f+1}b.main.iohighscore.processGoalRecord(a,!0)});this.getHighscorePage(1).then(function(a){null!=a&&0<a.length&&(b.currentTopScore=b.main.iohighscore.createScoreFromHSRecord(a[0]))});this.wsClient.on("newTopScore",function(a){b.currentTopScore=b.main.iohighscore.createScoreFromHSRecord(a);b.getUser(a.userID,function(c){c=q.parse("txt-io-livelog-newTopScore").replace("$user",
c.displayName).replace("$fame",a.points.toString());b.addNotification(c)})});this.wsClient.on("liveLog",function(a){logs.iomp&&r.info("IOMP;LiveLog sub: receievd");var c=a.biomeID;var e=a.userID;e!==b.parseUser.id&&b.getUser(e,function(d){var e;var f=b.main.worldGenIO.biomes[c];if(null!=d&&null!=f){var k=b.main.worldGenIO.worldSegmentList[f.worldSegment];a:{switch(a.logType){case Ac.newTrek:var l="txt-io-livelog-newTrek";break a;case Ac.foundSeal:l="txt-io-livelog-foundSeal";break a}l=void 0}l=q.parse(l).replace("$user",
d.displayName).replace("$segment",k.name).replace("$xCoord",b.main.worldGenIO.getBiomeDisplayTextX(f.pos.x)).replace("$yCoord",b.main.worldGenIO.getBiomeDisplayTextY(f.pos.y));d=a.keys;for(e in d)f=d[e],l=l.replace("$"+e,q.parse(f));b.addNotification(l)}})})}};U.prototype.getUser=function(a,b){debug.disableIOMP&&b(this.userDB[this.parseUser.id]);if(null!=this.userDB[a])try{return b(this.userDB[a])}catch(c){return a=c,r.error(a)}else debug.disableIOMP?b(null):null!=this.pendingUserCallbacks[a]?this.pendingUserCallbacks[a].push(b):
(this.pendingUserCallbacks[a]=[b],logs.iomp&&r.log("IOMP;querying user "+a),n.assert(!this.pendingUserQueries.includes(a)),this.pendingUserQueries.push(a),this.userFlushCountdown=.5)};U.prototype.flushPendingUserQueries=function(){var a=this;0!==this.pendingUserQueries.length&&(logs.iomp&&r.log("IOMP;querying "+this.pendingUserQueries.length+" users"),ea.getUsers({users:this.pendingUserQueries},function(b){var c,d,e,f;if(null!=b.error)r.info("IOMP;flushPendingUserQueries response error: "+b.error);
else{var g=0;for(c=b.length;g<c;g++){var h=b[g];var k=h.userID;a.userDB[k]={userID:k,displayName:h.displayName,colour:h.colour,goalCount:h.goalCount,stats:null!=(e=h.stats)?e:{}};var l=null!=(f=a.pendingUserCallbacks[k])?f:[];h=0;for(d=l.length;h<d;h++){var m=l[h];try{m(a.userDB[k])}catch(p){m=p,r.error(m)}}delete a.pendingUserCallbacks[k]}}}),this.pendingUserQueries.length=0)};U.prototype.resetForNewGame=function(){this.lastPostedHighscore=0;this.highscoreRow=null;this.lastHighscorePostTime=0;this.postHighscoreAgainAfterThisPost=
!1};U.prototype.setTransactionNotified=function(a){ea.setTransactionNotified({tid:a},function(a){if(null!=(null!=a?a.error:void 0))return r.info("IOMP;setTransactionNotified response error: "+a.error);if(logs.iomp)return r.info("IOMP;setTransactionNotified OK")})};U.prototype.performPurchase=function(a){if(debug.disableIOMP)return Promise.resolve(!0);var b={transactionParams:{item:a.item,type:a.type,cost:a.cost}};return new Promise(function(a,d){ea.performPurchase(b,function(b){if(null!=(null!=b?
b.error:void 0))return r.info("IOMP;performPurchase response error: "+b.error),d(b.error);logs.iomp&&r.info("IOMP;performPurchase OK");return a(b)})})};U.prototype.addLeg=function(a){var b;if(!debug.disableIOMP&&(n.assert(null!=this.main.party),n.assert(null!=a),n.assert(0<a.length),this.main.world===this.main.worldGenIO.world)){var c=[];var d=[];var e=0;for(b=a.length;e<b;e++){var f=a[e];var g=$jscomp.makeIterator(this.main.world.toLocalPos(f));f=g.next().value;g=g.next().value;if(null==f)return;
f=this.main.world.getBiomeIdx(f.pos);c.push(f);d.push(g)}a=this.main.party.getExplorer();null!=a&&(c={seed:this.ioSeed,explorerTribe:a.sourceTribeGenId,explorerSeed:a.sourceTribeGenSeed,explorerGender:a.gender,biomes:c,positions:d,partyMembers:this.main.party.persons.filter(function(a){return!a.isSpecial}).map(function(a){return a.id})},ea.addPartyLeg(c,function(a){if(null!=a.error)return r.info("IOMP;addPartyLeg response error: "+a.error);if(logs.iomp)return r.info("IOMP;addPartyLeg OK, row "+a)}))}};
U.prototype.getIsPostingHighscore=function(){if(0<this.lastHighscorePostTime){var a=Date.now()-this.lastHighscorePostTime;return 1E4>a}return!1};U.prototype.postCurrHighscore=function(){var a;if(null!=this.main.party){var b=this.main.party.getExplorer();if(null!=b&&!(0>=this.main.party.fame||this.main.party.fame===this.lastPostedHighscore&&null==this.main.party.stats.deathReason))if(this.getIsPostingHighscore())this.postHighscoreAgainAfterThisPost=!0;else{var c=this.main.party.persons.map(function(a){var b;
if(a.isSpecial)return null;var c={id:a.id,"in":!0,dead:null!=(b=a.flags.dead)?b:!1,gender:a.gender,"var":a.variationIdx};null!=a.sourceTribeGenId&&(c.sourceTribeGenId=a.sourceTribeGenId,c.sourceTribeGenSeed=a.sourceTribeGenSeed);return c});c.add(this.main.party.store.map(function(a){var b;var c={id:a.id,"in":!1,dead:null!=(b=a.flags.dead)?b:!1,gender:a.gender,"var":a.variationIdx};null!=a.sourceTribeGenId&&(c.sourceTribeGenId=a.sourceTribeGenId,c.sourceTribeGenSeed=a.sourceTribeGenSeed);return c}));
c=c.compact();c={days:this.main.exped.turn,packs:this.main.party.stats.packs,explorerLevel:b.level,partyMembers:c,fame:this.main.party.stats.rankingGift,startBiome:null!=(a=this.main.party.stats.IOStart)?a:-1,playTime:Math.floor(this.main.party.playTime/60)};null!=this.main.party.stats.IOEnd&&(c.endBiome=this.main.party.stats.IOEnd);null!=this.main.party.stats.deathReason&&(c.deathReason=this.main.party.stats.deathReason);this.postHighscore(b.sourceTribeGenId,b.sourceTribeGenSeed,b.gender,this.main.party.fame,
this.highscoreRow,c)}}};U.prototype.postHighscore=function(a,b,c,d,e,f){var g=this;e=void 0===e?null:e;f=void 0===f?null:f;if(!this.getIsPostingHighscore()){var h={seed:this.ioSeed,explorerTribe:a,explorerSeed:b,explorerGender:c,score:d,existingRow:e,partyData:f};debug.disableIOMP?this.lastPostedScore=this.main.iohighscore.createScoreFromHSRecord(h):(this.lastHighscorePostTime=Date.now(),ea.postHighscore(h,function(a){null!=a.error?(r.info("IOMP;post highscore response error: "+a.error),a.error.includes("Invalid token")&&
(g.wsConnected=!1,g.wsClient.close())):(logs.iomp&&r.info("IOMP;posted highscore "+d+" OK, row "+a),g.lastPostedScore=g.main.iohighscore.createScoreFromHSRecord(h),null!=f.endBiome?g.resetForNewGame():(g.lastPostedHighscore=d,null==g.highscoreRow&&(g.highscoreRow=a,g.main.gameOver||g.main.mainMenu.saveGame.updateSaveGame())),g.main.iohighscore.playerScores=[]);g.lastHighscorePostTime=0;g.postHighscoreAgainAfterThisPost&&(g.postHighscoreAgainAfterThisPost=!1,null!=g.highscoreRow&&g.postCurrHighscore())}))}};
U.prototype.getHighscorePage=function(a,b){b=void 0===b?0:b;if(debug.disableIOMP)return Promise.resolve([]);var c={seed:this.ioSeed,pageSize:a,page:b};return new Promise(function(a,b){return ea.getHighscorePage(c,function(c){if(null!=c.error)return r.info("IOMP;getHighscorePage response error: "+c.error),b(c.error);logs.iomp&&r.info("IOMP;getHighscorePage OK");return a(c)})})};U.prototype.getHighscorePageForUser=function(a){if(debug.disableIOMP)return Promise.resolve(0);var b={seed:this.ioSeed,pageSize:a};
return new Promise(function(a,d){return ea.getHighscorePageForUser(b,function(b){if(null!=b.error)return r.info("IOMP;getHighscorePageForUser response error: "+b.error),d(b.error);logs.iomp&&r.info("IOMP;getHighscorePageForUser OK");return a(b)})})};U.prototype.getStatsForUser=function(){if(debug.disableIOMP)return Promise.resolve(0);var a={seed:this.ioSeed};return new Promise(function(b,c){return ea.getStatsForUser(a,function(a){if(null!=a.error)return r.info("IOMP;getStatsForUser response error: "+
a.error),c(a.error);logs.iomp&&r.info("IOMP;getStatsForUser OK");return b(a)})})};U.prototype.storeSaveData=function(a){var b=this;if(this.isSaving)this.queueSave();else return null!=a?(a=JSON.stringify(a),a=pako.deflate(a,{to:"string"}),a=btoa(a)):a=null,a={data:a},this.isSaving=!0,this.saveTimer=null,this.main.ioInv.flushInvData(),ea.setSaveGame(a,function(a){var c;(c=null!=a&&null!=a.error)?(a.error.includes("Invalid token")&&(b.wsConnected=!1,b.wsClient.close()),r.error("IOMP;storeSaveData error "+
a.error)):logs.iomp&&r.info("IOMP;storeSaveData stored, length "+a);b.isSaving=!1;if(!c&&null==b.saveTimer)return b.postCurrHighscore()})};U.prototype.getSaveData=function(){return(new Promise(function(a,b){return ea.getSaveGame({},function(c){return null==c?a(null):null!=c.error?b(c.error):a(c)})})).then(function(a){return null!=a?(a=atob(a),a=pako.inflate(a,{to:"string"}),a=JSON.parse(a),Promise.resolve(a)):Promise.resolve(null)})};U.prototype.addNotification=function(a,b){this.notifications.push({text:a,
y:0,time:0,system:void 0===b?!1:b})};U.prototype.isServerOK=function(){if(debug.disableIOMP&&!this.wsConnected)return!0;if(!this.wsConnected||null!=this.wsData&&(this.isServerVersionIncompatible(this.wsData.version)||this.wsData.worldData.worldID!==this.worldData.worldID))return!1;if(null!=this.worldData.worldEnd&&0<this.worldData.worldEnd){var a=new Date(this.worldData.worldEnd);var b=new Date(Date.now());return 0<a-b}return!0};U.prototype.isServerVersionIncompatible=function(a){var b=$jscomp.makeIterator(a.split("."));
a=b.next().value;var c=b.next().value;var d=b.next().value;b.next();var e=$jscomp.makeIterator(n.getVersionString().split("."));b=e.next().value;var f=e.next().value;var g=e.next().value;e.next();return a!==b||c!==f||d!==g};U.prototype.getServerText=function(){if(!debug.disableIOMP){if(!this.wsConnected)return q.toText("txt-io-connection-lost");if(null!=this.wsData&&this.isServerVersionIncompatible(this.wsData.version))return q.toText("txt-io-connection-newVersion")}if(null!=this.wsData&&this.wsData.worldData.worldID!==
this.worldData.worldID)return q.toText("txt-io-connection-newWorld");if(null==this.main.iomp.worldData.worldEnd||0===this.main.iomp.worldData.worldEnd)return null;var a=new Date(this.main.iomp.worldData.worldEnd);var b=new Date(Date.now());a-=b;if(0>a)return q.toText("txt-io-worldDuration-new");a=q.timeDurationToString(a);0<a.length&&(a=q.toText("txt-io-worldDuration-end")+" "+a);return a};U.prototype.refreshUserData=function(){var a=this;return this.parseUser.fetch().then(function(b){a.parseUser=
b;return a.waitingForRefresh=!1},function(b){console.error(b);return a.waitingForRefresh=!1})};U.prototype.drawShopButton=function(a,b,c,d,e,f,g){if(debug.runOffline)return null;if(this.waitingForRefresh){if(this.main.r.drawButton(q.toText("txt-io-shop-refresh"),a,b,c,d,e,f,g,{font:config.fonts.technicalLarge,os:0}))return"refreshUser"}else{var h=this.parseUser.get("email");if(null==h||""===h){if(this.main.r.drawButton(q.toText("txt-io-shop-unclaimed"),a,b,c,d,e,f,g,{font:config.fonts.technicalSmall,
os:0}))return"account"}else if(debug.disableIOMP)this.main.r.drawButton("no shop: iomp disabled",a,b,c,d,e,f,g,{panel:config.panel.jewelButton,font:config.fonts.technicalSmall,os:0,fillColor:"#ffcb12",shadowColor:"#bc2d00"});else{if(this.parseUser.get("emailVerified")){switch(this.storeOpenState){case 0:h=q.toText("txt-io-medals-buy");if(this.main.r.drawButton(h,a,b,c,d,e,f,g,{panel:config.panel.jewelButton,fillColor:"#ffcb12",shadowColor:"#bc2d00"}))return"openStore";break;case 1:this.main.r.drawText(q.toText("txt-io-shop-open")+
"...",a,b+d/2,{halign:"center",fillColor:config.ioNewGameTitleColor,font:config.fonts.themedLarge,os:0});break;case 2:this.main.r.drawText(q.toText("txt-loading")+"...",a,b+d/2,{halign:"center",fillColor:config.ioNewGameTitleColor,font:config.fonts.themedLarge,os:0})}return null}if(this.main.r.drawButton(q.toText("txt-io-shop-unverified"),a,b,c,d,e,f,g,{font:config.fonts.technicalSmall,os:0}))return"verifyEmail"}}};U.prototype.isStoreOpen=function(){return 0!==this.storeOpenState};U.prototype.openStore=
function(){var a=this;if(debug.disableIOMP)return Promise.reject("iomp disabled");if(0!==this.storeOpenState)return Promise.reject("already open/opening");var b=new Promise(function(b,c){null!=a.xsToken&&b(a.xsToken);var d={userName:a.parseUser.get("username"),userEmail:a.parseUser.get("email")};return ea.getXsollaStoreToken(d,function(d){if(null==d)return c(null);if(null!=d.error)return c(d.error);a.xsToken=d;return b(d)})});var c=new Promise(function(b,c){"undefined"!==typeof XPayStationWidget&&
null!==XPayStationWidget&&b(XPayStationWidget);c=document.createElement("script");c.type="text/javascript";c.async=!0;c.src="//static.xsolla.com/embed/paystation/1.0.7/widget.min.js";c.addEventListener("load",function(c){XPayStationWidget.on("open",function(){return a.storeOpenState=1});XPayStationWidget.on("close",function(){return a.storeOpenState=0});return b(XPayStationWidget)},!1);return document.getElementsByTagName("head")[0].appendChild(c)});this.storeOpenState=2;return Promise.all([b,c]).then(function(a){var b=
$jscomp.makeIterator(a);a=b.next().value;b=b.next().value;var c=debug.isDevMode;b.init({access_token:a,host:c?"sandbox-secure.xsolla.com":"secure.xsolla.com",sandbox:c,lightbox:{spinner:"round",contentMargin:"50px",height:"75%"}});b.open();return Promise.resolve(!0)},function(b){var c;console.log("IOMP; store open error: "+(null!=(c=b.message)?c:b));a.storeOpenState=0})};U.prototype.queueSave=function(){return this.saveTimer=5};U.prototype.tick=function(a){0<this.userFlushCountdown&&(this.userFlushCountdown-=
a,0>=this.userFlushCountdown&&this.flushPendingUserQueries());if(null!=this.saveTimer&&(this.saveTimer-=a,0>=this.saveTimer&&this.main.canSave()))return this.main.mainMenu.saveGame.updateSaveGame(),this.saveTimer=null};U.prototype.drawNotifications=function(a,b,c,d,e){e=void 0===e?!0:e;var f=this.main.r;var g=$jscomp.makeIterator(f.getCanvasSize());g.next();g.next();var h=10*f.s;var k=12*f.s;var l=config.io.iompNotificationFadeTime+config.io.iompNotificationShowTime;this.toRemove=[];if(0!==this.notifications.length){var m=
this.notifications[0];g=0;m.time+=a;h*=g;m.y<h&&(m.y=Math.min(h,m.y+a*k));l=m.time<config.io.iompNotificationFadeTime?J.lerp(0,1,m.time/config.io.iompNotificationFadeTime):m.time>l?J.lerp(1,0,(m.time-l)/config.io.iompNotificationFadeTime):1;f.ctx.save();if(0>=l)this.toRemove.push(g);else for(f.ctx.font=config.fonts.technicalSmall,g=q.wrap(m.text,d,f.ctx),c-=m.y,m=m.system?config.colors.help:config.ioNewGameTitleColor,a=8*f.s,e&&(f.ctx.fillStyle="black",f.ctx.globalAlpha=.5*l,f.ctx.fillRect(b,c,d,
g.length*a),b+=2*f.s),f.ctx.globalAlpha=l,c+=a-2*f.s,d=e=0,l=g.length;0<=l?e<l:e>l;d=0<=l?++e:--e)this.main.r.drawText(g[d],b,c,{font:config.fonts.technicalSmall,fillColor:m,halign:"left"}),c+=a;for(g=b=this.toRemove.length-1;0<=b;g=b+=-1)this.notifications.splice(this.toRemove[g],1);f.ctx.restore()}};var Lc=U;var Ya=function(a,b,c){a=W.call(this,a,b,c)||this;a.startFirstExpedition=a.startFirstExpedition.bind(a);a.time=0;return a};$jscomp.inherits(Ya,W);Ya.prototype.show=function(){var a=this,b,c,
d,e;this.time=0;null==this.worldScoreStats&&(this.worldScoreStats={thisUserScores:0,totalScores:0,totalUsers:0});debug.disableIOMP||(this.main.iohighscore.updateGoalScores(),this.main.iomp.getStatsForUser().then(function(b){return a.worldScoreStats=b}));this.main.mainMenu.hasEverStartedGame?null!=(null!=(e=this.main.world)?e.startPos:void 0)?this.splashType=1:this.splashType=2:(this.splashType=0,n.assert(0<this.main.worldGenIO.unlockedHubs.length),this.main.ioNewGame.startUnlockedHubIdx=0);if(1!==
this.splashType&&1===(null!=(c=this.main.party)?c.persons.length:void 0))for(e=null!=(b=config.autoPacks)?b:[],c=0,d=e.length;c<d;c++)b=e[c],this.main.ioNewGame.addPackToParty(b);this.main.doEvent(t.getEvent(config.specialEvents.ioSplash));if(!this.main.isLastMusicPlaying())return this.main.playMusic(t.arrify(config.io.splashAudio).sample())};Ya.prototype.draw=function(a,b,c){var d=$jscomp.makeIterator(this.r.getCanvasSize());var e=d.next().value;d=d.next().value;this.mouseAction=null;this.r.clear(!0,
"#0a0312");this.main.drawDiary(a,b);if(this.isAlphaActivateMode)this.mouseAction=bb.drawAlphaAccessPanel(this.main,a,b,c);else{var f=25*this.s+Math.floor(12*Math.sin(this.time));this.r.drawSprite("title_rivals.png",e/2,f,{halign:"center",valign:"top"});var g=50*this.s;f=d-90*this.s;if(1!==this.splashType){var h=this.main.party.getExplorer();var k={valign:"bottom",halign:"left"};var l=this.r.img.getSprite("hud_char_frame_io.png");this.r.drawSprite(l,g,f,k);k.scale=1.5;l=g+3.5*this.s*k.scale;var m=
f-5*this.s*k.scale;this.r.drawPortrait(h,l,m,k);h={sprite:"hud_io_randomize.png",event:{id:"regenExplorer"}};f=this.main.ioNewGame.drawTinyButton(h,null,g+14*this.s,f-14*this.s,a,b,c);null!=f&&(this.mouseAction=f)}f=new R(20*this.s,35*this.s);this.main.iomp.isServerOK()?(h=1===this.splashType?"txt-io-splash-continue":"txt-io-splash-new",this.r.ctx.font=config.fonts.themedLarge,k=this.r.ctx.measureText(h),f.w+=Math.ceil(k.width),this.r.drawButton(q.toText(h),g+f.w/2,d-50*this.s-f.h,f.w,f.h,a,b,c)&&
(this.mouseAction={id:"start"})):(h=this.main.iomp.getServerText(),g+=f.w/2,d=d-30*this.s-f.h,this.r.drawWarningBar(h,d,g,"left"),f=100*this.s,this.r.drawButton(q.toText("txt-mod-refresh"),g+f/2,d-35*this.s,f,25*this.s,a,b,c)&&(this.mouseAction={id:"refreshWindow"}));d=this.main.ioNewGame.drawHeader(a,b,c);null!=d&&(this.mouseAction=d);d=bb.drawPyramidPanel(this.main,e-130*this.s,50*this.s,a,b,c);null!=d&&(this.mouseAction=d);a=bb.drawCE2Panel(this.main,e-130*this.s,215*this.s,a,b,c);if(null!=a)return this.mouseAction=
a}};Ya.prototype.startFirstExpedition=function(){B(this,Ya);var a=this.main.worldGenIO.getDefaultPlayerHub();this.main.ioNewGame.startUnlockedHubIdx=this.main.worldGenIO.unlockedHubs.indexOf(a);this.main.startNewIOGame(a);this.main.party.stats.packs=Object.clone(config.autoPacks);this.main.mainMenu.hasEverStartedGame=!0;return this.main.mainMenu.updatePlayerData()};Ya.prototype.hide=function(){this.main.events.showingEventDialogue=!1;this.main.diary.chatQueue=[];this.main.diaryScrollX=-200*this.s;
this.main.diary.imageAlpha=0;this.main.diary.changeTime=1};Ya.prototype.onMouseClick=function(a){if(null!=this.mouseAction)switch(this.mouseAction.id){case "start":this.sfx.play("campClose");switch(this.splashType){case 0:return this.startFirstExpedition();case 1:this.main.isNewGameLoading=!1;this.main.tutorial=null;this.main.gotoLoading();if(this.main.isWarping())return this.main.gotoGame();break;case 2:return this.main.popMainState(),this.main.setMainState("ionewgame"),this.main.ioNewGame.initNewParty()}break;
case "settings":return this.sfx.play("campClose"),this.main.showSettings(!0);case "account":return this.sfx.play("campClose"),this.main.gotoRivalsAccount();case "discord":return this.sfx.play("campClose"),n.openLink("https://discordapp.com/invite/maschinen-mensch",!1);case "tce":return this.main.gotoTCE();case "regenExplorer":this.sfx.play("outroCount");a=this.main.party.getExplorer();var b=t.arrify(t.getCharacter(a.id).variations);a.setVariation(J.randInt(b.length));return a.initCharGen(config.io.explorerGen.sample());
case "refreshWindow":return this.main.refreshWindow();case "alphaActivate":return this.sfx.play("campClose"),navigator.clipboard.writeText(this.main.ioInv.userSecure.alphaKey),this.isAlphaActivateMode=!0;case "alphaPanelBack":return this.sfx.play("campClose"),this.isAlphaActivateMode=!1;case "ce2wishlist":return this.sfx.play("campClose"),n.openLink("https://store.steampowered.com/app/1040230/Curious_Expedition_2/");case "alphaSignup":return this.sfx.play("campClose"),n.openLink("https://curious-expedition.com/")}};
Ya.prototype.tick=function(a){this.main.tickDiary(a);this.time+=a;if(null!=this.main.diary.showImage&&0===this.main.diary.chatQueue.length)return this.main.doEvent(t.getEvent(config.specialEvents.ioSplashChat),{silent:!0})};var Pd=Ya;var Qd=function(){var a=function(a,c,d){var f=W.call(this,a,c,d)||this;f.updateTopScores=f.updateTopScores.bind(f);f.startNewGame=f.startNewGame.bind(f);f.calculateTimelineStart=f.calculateTimelineStart.bind(f);f.addPackToParty=f.addPackToParty.bind(f);f.setupParty=f.setupParty.bind(f);
f.handlePackSelection=f.handlePackSelection.bind(f);f.drawTinyButton=f.drawTinyButton.bind(f);f.drawTinyButtonSet=f.drawTinyButtonSet.bind(f);f.drawMap=f.drawMap.bind(f);f.drawTitle=f.drawTitle.bind(f);f.drawBiomeInfo=f.drawBiomeInfo.bind(f);f.drawNews=f.drawNews.bind(f);f.updatePackLists=f.updatePackLists.bind(f);f.drawPacks=f.drawPacks.bind(f);f.setSelectingHoldCrate=f.setSelectingHoldCrate.bind(f);f.displayPack=f.displayPack.bind(f);f.drawPackSet=f.drawPackSet.bind(f);f.drawStoredExplorer=f.drawStoredExplorer.bind(f);
f.updateCharDragCtx=f.updateCharDragCtx.bind(f);f.handleDrag=f.handleDrag.bind(f);f.drawDrag=f.drawDrag.bind(f);f.drawExpedition=f.drawExpedition.bind(f);f.onMouseWheel=f.onMouseWheel.bind(f);f.adjustPackScroll=f.adjustPackScroll.bind(f);f.time=0;f.addedPacks=[];f.invalidPacks={};f.packOffset=0;f.viewState=b.packs;f.mapViewState=e.pockets;f.packViewState=l.recent;f.scoreViewState=x.score;f.newGameState=C.resume;f.startUnlockedHubIdx=0;f.topScores=[];f.hubsDisplayed=!1;$.ajax({async:!0,global:!1,url:debug.isDevMode||
debug.runOffline?"conf/io_news_p.json":"https://curious-expedition.com/news/io_news_p.json",dataType:"text",cache:!1,success:function(a){f.main.mainMenu.news=JSON.parse(a);if(0<f.main.mainMenu.news.length&&f.main.mainMenu.news[0].id>f.main.mainMenu.lastShownNews&&(f.viewState=b.news,0>f.main.mainMenu.lastShownNews))return f.main.mainMenu.selectedNews=f.main.mainMenu.news.length-1},error:function(a,b,c){return r.error(b)}});return f};$jscomp.inherits(a,W);a.prototype.initNewParty=function(){var a,
c,d,f;n.assert(0<this.main.worldGenIO.unlockedHubs.length);var g=this.main.worldGenIO.getDefaultPlayerHub();this.startUnlockedHubIdx=this.main.worldGenIO.unlockedHubs.indexOf(g);g=null!=(c=config.freePacks)?c:[];var h=0;for(d=g.length;h<d;h++){var k=g[h];c=null!=(f=this.main.ioInv.packs[k])?f:0;0===c&&this.main.ioInv.addPack(k,!1)}this.addedPacks=[];f=null!=(a=config.autoPacks)?a:[];g=0;for(c=f.length;g<c;g++)a=f[g],this.handlePackSelection(a);this.viewState=b.map;this.packOffset=0;this.packViewState=
l.recent;this.mapViewState=e.pockets;this.updatePackLists();this.newGameState=C.new;this.timelineActive=!1;return this.main.worldGenIO.claimCtxDirty=!0};a.prototype.updateTopScores=function(){var b=this;B(this,a);this.loadingTopScores=!0;this.main.iomp.getHighscorePage(10).then(function(a){var c;b.topScores=[];var d=0;for(c=a.length;d<c;d++){var e=a[d];b.topScores.push(b.main.iohighscore.createScoreFromHSRecord(e))}0<b.topScores.length&&b.topScores.last();b.main.iomp.setLQForScores(b.updateTopScores,
0,9,"ionewgame");b.loadingTopScores=!1})};a.prototype.hide=function(){this.main.events.showingEventDialogue=!1;this.main.diary.chatQueue=[];this.main.diaryScrollX=-200*this.s;this.main.diary.imageAlpha=0;this.main.diary.changeTime=1;this.main.iomp.clearLQForScores("ionewgame")};a.prototype.show=function(){var a;null!=this.main.exped&&this.main.exped.showingPunch&&this.main.exped.doPunch(null,!0);this.time=0;this.addedPacks=[];this.invalidPacks={};this.dismissedPacksTutorial=this.dismissedHubTutorial=
!1;this.main.iomp.postCurrHighscore();this.updateTopScores();this.main.iohighscore.updateGoalScores();this.invBar=new kb(this.main,{inv:null,item:null,amount:-1,invIdx:-1},{inv:this.main.party.inv,owned:!0});this.invBar.slotLimit=config.ioNewGameInventorySlotsWidth;this.newGameState=null!=this.main.world.startPos?C.resume:C.none;this.viewState!==b.news&&(this.viewState=b.map);this.mapViewState=e.pockets;this.main.worldGenIO.claimCtxDirty=!0;this.updatePackLists();if(this.newGameState!==C.resume){n.assert(0<
this.main.worldGenIO.unlockedHubs.length);var c=this.main.worldGenIO.getDefaultPlayerHub();this.startUnlockedHubIdx=this.main.worldGenIO.unlockedHubs.indexOf(c)}this.main.doEvent(t.getEvent(config.specialEvents.ioNewGame));this.newGameState===C.resume||this.main.isLastMusicPlaying()||this.main.playMusic(t.arrify(config.io.splashAudio).sample());window.isClient?this.main.ioInv.flushInvData():this.main.canSave()&&null!=(a=this.main.party)&&a.isInventoryChangedSinceSave?this.main.mainMenu.saveGame.updateSaveGame():
this.main.ioInv.flushInvData()};a.prototype.startNewGame=function(){var b;B(this,a);if(0<this.addedPacks.length){this.addedPacks=this.addedPacks.sortBy(function(a){return a});var c=(new Date).getTime();var d=this.addedPacks;var e=0;for(b=d.length;e<b;e++){var f=d[e];this.main.ioInv.packsLastUsed[f]=c;if(!this.main.ioInv.isPackHeld(f)){n.assert(0<this.main.ioInv.packs[f]);if(0===this.main.ioInv.packs[f])return;--this.main.ioInv.packs[f]}}this.main.ioInv.saveInventory()}this.main.party.stats.packs=
Object.clone(this.addedPacks);f=this.main.party.persons;c=0;for(e=f.length;c<e;c++)b=f[c],null!=b.spawnEvents&&this.main.doRandEvent(b.spawnEvents,{person:b,silent:!0});this.main.startNewIOGame(this.main.worldGenIO.unlockedHubs[this.startUnlockedHubIdx]);this.main.ioSplash.numScoresThisUser+=1};a.prototype.calculateTimelineStart=function(){B(this,a);this.timelinePoint=this.main.iomp.worldData.worldStart};a.prototype.onMouseClick=function(a){if(null!=this.mouseAction)switch(this.mouseAction.id){case "start":this.sfx.play("campClose");
this.initNewParty();this.setSelectingHoldCrate(!1);break;case "regenExplorer":this.sfx.play("outroCount");a=this.main.party.getExplorer();var c=t.arrify(t.getCharacter(a.id).variations);a.setVariation(J.randInt(c.length));a.initCharGen(config.io.explorerGen.sample());this.setSelectingHoldCrate(!1);break;case "continue":this.sfx.play("campClose");1===this.main.mainStates.length?(this.main.isNewGameLoading=!1,this.main.tutorial=null,this.main.gotoLoading(),this.main.isWarping()&&this.main.gotoGame()):
this.main.popMainState();this.setSelectingHoldCrate(!1);break;case "abort":1===this.main.mainStates.length?this.main.initNewIOGame():(this.main.popMainState(),this.main.showExpeditionOver(!1,q.toText("txt-io-exped-aborted"),"io-aborted"));this.setSelectingHoldCrate(!1);break;case "tutorial":n.openLink("http://demo.curious-expedition.com/");break;case "advanceNewState":this.sfx.play("campClose");this.viewState===b.map?this.viewState=b.packs:this.startNewGame();this.setSelectingHoldCrate(!1);break;
case "backNewState":this.sfx.play("campClose");this.viewState===b.packs?this.viewState=b.map:(this.main.popMainState(),this.main.setMainState("iosplash"));this.setSelectingHoldCrate(!1);break;case "toggleState":this.sfx.play("outroCount");this.viewState=this.viewState===b.packs?b.map:b.packs;this.setSelectingHoldCrate(!1);break;case "addPack":this.sfx.play("outroCount");this.handlePackSelection(this.mouseAction.pack,!0);break;case "removePack":this.sfx.play("outroCount");this.handlePackSelection(this.mouseAction.pack,
!1);break;case "changePackState":this.sfx.play("outroCount");this.packViewState=this.mouseAction.state;this.updatePackLists();break;case "nextPackPage":this.sfx.play("outroCount");this.adjustPackScroll(1);break;case "prevPackPage":this.sfx.play("outroCount");this.adjustPackScroll(-1);break;case "toggleHoldCrate":this.sfx.play("outroCount");this.setSelectingHoldCrate(!this.isSelectingHoldCrate);break;case "holdCrate":this.sfx.play("campClose");jc.beginTransaction(this.main,{item:this.mouseAction.pack,
type:cb.crateHold});this.setSelectingHoldCrate(!1);break;case "link":n.openLink(this.mouseAction.data);break;case "dismissNews":a=this.main.mainMenu.selectedNews;this.main.mainMenu.lastShownNews<this.main.mainMenu.news[a].id&&(this.main.mainMenu.lastShownNews=this.main.mainMenu.news[a].id,this.main.mainMenu.updatePlayerData());this.viewState=b.map;break;case "news":this.viewState=b.news;break;case "changeMapState":this.sfx.play("outroCount");this.mapViewState=this.mouseAction.state;this.main.worldGenIO.claimCtxDirty=
!0;break;case "nextHub":this.sfx.play("outroCount");this.startUnlockedHubIdx+=1;this.startUnlockedHubIdx>=this.main.worldGenIO.unlockedHubs.length&&(this.startUnlockedHubIdx=0);break;case "prevHub":this.sfx.play("outroCount");--this.startUnlockedHubIdx;0>this.startUnlockedHubIdx&&(this.startUnlockedHubIdx=this.main.worldGenIO.unlockedHubs.length-1);break;case "hubSelect":this.sfx.play("outroCount");this.startUnlockedHubIdx=this.main.worldGenIO.unlockedHubs.indexOf(this.mouseAction.hub);break;case "timelineToggle":this.sfx.play("outroCount");
null==this.timelineActive&&(this.timelineActive=!1);this.timelineActive=!this.timelineActive;this.main.worldGenIO.claimCtxDirty=!0;this.timelineActive&&this.calculateTimelineStart();break;case "toggleHubs":this.hubsDisplayed=!this.hubsDisplayed;break;case "changeScoreState":this.sfx.play("outroCount");this.scoreViewState=this.mouseAction.state;break;case "moreScores":this.sfx.play("outroCount");this.main.gotoHighScore();this.setSelectingHoldCrate(!1);break;case "settings":this.main.showSettings(!0);
this.setSelectingHoldCrate(!1);break;case "account":this.main.gotoRivalsAccount();this.setSelectingHoldCrate(!1);break;case "discord":n.openLink("https://discordapp.com/invite/maschinen-mensch",!1);break;case "tce":this.main.gotoTCE();break;case "tabInventory":this.sfx.play("outroCount");this.invBar.tabItems();this.setSelectingHoldCrate(!1);break;case "openStore":this.main.iomp.openStore();break;case "verifyEmail":Parse.User.current().set("email",Parse.User.current().get("email"));Parse.User.current().save();
this.main.iomp.waitingForRefresh=!0;break;case "refreshUser":this.main.iomp.refreshUserData();break;case "refreshWindow":this.main.refreshWindow()}return!0};a.prototype.onKeyPress=function(a){return!0};a.prototype.tick=function(a){this.main.tickDiary(a);this.time+=a;this.timelineActive&&(this.timelinePoint+=3600*Math.round(1E3*a),this.main.worldGenIO.claimCtxDirty=!0,this.timelinePoint>Date.now()+108E5&&this.calculateTimelineStart());this.newGameState!==C.new&&this.main.tickSound();return!0};a.prototype.addPackToParty=
function(b,c){c=void 0===c?[]:c;var d,e,f,g;B(this,a);b=t.getPack(b);n.assert(null!=b);var h=null!=(d=b.items)?d:[];for(m in h)d=h[m],this.main.party.inv.changeItemCount(m,d);var k=t.arrify(b.characters);var l=0;for(f=k.length;l<f;l++){var m=k[l];var p=null;h=e=0;for(g=c.length;e<g;h=++e)if(d=c[h],d.id===m){p=d;c.splice(h,1);break}null==p&&(p=new Fa(this.main,m),p.updateSprite(this.main.getTribeGenAtPartyPos()));this.main.party.addCharacter(p)}m=t.arrify(b.statuses);c=0;for(b=m.length;c<b;c++)d=m[c],
this.main.party.getExplorer().setStatus(d,!0)};a.prototype.setupParty=function(){var b;B(this,a);var c=Object.clone(this.main.party.persons);this.main.party.inv.items=[];this.main.party.persons=[this.main.party.getExplorer()];this.main.party.getExplorer().statuses={};var d=this.addedPacks;var e=0;for(b=d.length;e<b;e++){var f=d[e];this.addPackToParty(f,c)}this.main.party.inv.compactAndStackAll();return this.main.doEvent(t.getEvent(config.specialEvents.ioNewGame))};a.prototype.handlePackSelection=
function(b,c){c=void 0===c?!0:c;var d;B(this,a);n.assert(this.main.ioInv);n.assert(0<this.main.ioInv.packs[b]);if(c){if(this.addedPacks.includes(b)||this.addedPacks.length>=config.maximumPartyPacks||null!=this.getPackTimer(b))return;this.addedPacks.push(b)}else this.addedPacks.splice(this.addedPacks.indexOf(b),1);this.setupParty();this.updatePackLists();this.invalidPacks={};var e=this.availPacksList;c=0;for(d=e.length;c<d;c++){b=e[c];var f={};this.testIsPackValid(b,f)||(this.invalidPacks[b]=f)}this.main.party.inv.compactAndStackAll()};
a.prototype.testIsPackValid=function(a,b){var c,d,e;if(this.addedPacks.includes(a))return b.alreadyAdded=!0,!1;a=t.getPack(a);n.assert(null!=a);var f=null!=(c=a.items)?c:[];for(k in f){var g=f[k];this.main.party.inv.changeItemCount(k,g)}c=[];var h=t.arrify(a.characters);f=0;for(d=h.length;f<d;f++)g=h[f],g=new Fa(this.main,g),this.main.party.addCharacter(g),c.push(g);this.main.party.inv.compactAndStackAll();b.overBurden=this.main.party.inv.isOverburden();b.overFilled=this.main.party.isOverfilled();
a=null!=(e=a.items)?e:[];for(k in a)g=a[k],this.main.party.inv.changeItemCount(k,-g);var k=0;for(e=c.length;k<e;k++)g=c[k],this.main.party.removeCharacter(g);this.main.party.inv.compactAndStackAll();return!b.overBurden&&!b.overFilled};a.prototype.drawTinyButton=function(b,c,d,e,f,g,h,k){B(this,a);n.assert(null!=b&&null!=b.sprite);var l=c&&null!=b.spritePressed?b.spritePressed:b.sprite;l=this.r.img.getSprite(l);d-=l.dSize.w;if(this.r.hitBox(d,e,l.dSize.w,l.dSize.h,f,g)){var m=!0;c||(e+=h?1*this.s:
-1*this.s)}c&&null==b.spritePressed&&(e+=1*this.s);this.r.drawSprite(l,d,e,k);this.lastTinyButtonWidth=l.dSize.w;m&&null!=b.tooltip&&this.main.infoBox.setTooltip(b.tooltip);return m?b.event:null};a.prototype.drawTinyButtonSet=function(b,c,d,e,f,g,h){var k;B(this,a);var l=[];var m=0;for(k=b.length;m<k;m++){var n=b[m];if(n=this.drawTinyButton(n,0<=F.call(c,n),d,e,f,g,h))this.mouseAction=n;l.push(d-=this.lastTinyButtonWidth+2*this.s)}return l};a.prototype.draw=function(a,c,d){this.main.drawDiary(a,c);
var e=$jscomp.makeIterator(this.r.getCanvasSize());var f=e.next().value;var g=e.next().value;A=4*this.s;this.highlightedStats=this.highlightedScore=this.mouseAction=null;e=245*this.s;var h=this.r.img.getSprite("maxmap_bg.png");h=null!=h?h.dSize.w:Math.round(.64*g);var k=40*this.s;var l=g-k-A;var m=f-h-e-3*A;var n=5*this.s;this.r.drawSprite("title_rivals.png",e/2,n,{halign:"center",valign:"top"});n=k;var p=e+h+2*A;this.viewState!==b.news&&this.drawScores(p,n,m,l,a,c,d);p=e+A;switch(this.viewState){case b.map:this.drawMap(p,
n,h,l,a,c,d);break;case b.packs:this.drawPacks(p,n,h,l,a,c,d);break;case b.news:this.drawNews(p,n,h+m/2+A,l,a,c,d)}l=this.viewState===b.map?h+20*this.s:l;this.newGameState===C.new&&this.r.hitBox(p,n,h,l,a,c)&&(this.viewState!==b.map||this.dismissedHubTutorial?this.viewState!==b.packs||this.dismissedPacksTutorial||(this.dismissedPacksTutorial=!0):this.dismissedHubTutorial=!0);l=this.main.iomp.getServerText();null!=l&&this.r.drawText(l,p,33*this.s,{font:config.fonts.technicalSmall,halign:"left",fillColor:config.colors.ioSystemText,
shadowColor:config.colors.ioSystemShadow});this.main.iomp.drawNotifications(this.r.timeDelta,p,2*A,h,!1);this.viewState!==b.news&&this.newGameState!==C.new&&(l=this.viewState===b.map?"hud_io_button_crates.png":"hud_io_button_maxmap.png",l=this.r.img.getSprite(l),n-=1*this.s,this.r.hitBox(p,n,l.dSize.w,l.dSize.h,a,c)&&(n=d?n+1*this.s:n-1*this.s,this.mouseAction={id:"toggleState"}),this.r.drawSprite(l,p,n));this.newGameState===C.none?(p=new R(130*this.s,50*this.s),n=g/2,this.r.drawButton(q.toText("txt-io-newgame-start"),
e/2,n,p.w,p.h,a,c,d)&&(this.mouseAction={id:"start"})):this.drawExpedition(e,a,c,d);this.charToDraw&&(n=this.r.drawCharacterInfo(this.charToDraw,this.chInfoBoxPos.x,this.chInfoBoxPos.y,a,c),n||(this.charToDraw=null));this.statusToDraw&&!this.charToDraw&&this.r.drawStatusInfo(f-130*this.s,g,this.statusToDraw,!0);f=this.drawHeader(a,c,d);null!=f&&(this.mouseAction=f);null!=this.highlightedScore?this.main.iohighscore.drawPartyInfo(this.highlightedScore,e+A,k+20*this.s,h):this.highlightedStats&&(f=150*
this.s,this.main.iohighscore.drawUserStats(this.highlightedStats,e+h-f,k+20*this.s,f));return this.drawDrag(a,c,d)};a.prototype.drawMap=function(b,d,l,m,n,p,r){var t=this,w,v,y,x;B(this,a);var G=A;var H=20*this.s;this.newGameState===C.none&&(m=l-G+H);switch(this.mapViewState){case e.claims:var D=f;break;case e.pockets:D=k}var V=[f,k];D=[D];this.newGameState!==C.new&&(V.push(h),V.push(g),V.push(c),this.timelineActive&&D.push(g));this.hubsDisplayed&&D.push(h);this.drawTinyButtonSet(V,D,b+l,d+3*this.s,
n,p,r);if(this.newGameState===C.new){var T=this.main.worldGenIO.unlockedHubs[this.startUnlockedHubIdx];var z=null!=T?this.main.worldGenIO.biomes[T].pos:null}else this.newGameState===C.resume&&(this.main.isWarping()?z=this.main.world.toBiomePos(this.main.worldStack[0].warpPos):null!=(null!=(v=this.main.exped)?null!=(y=v.party)?y.pos:void 0:void 0)?z=this.main.world.toBiomePos(this.main.exped.party.pos):null!=this.main.world.startPos&&(z=this.main.world.toBiomePos(this.main.world.startPos)),null!=z&&
(T=this.main.worldGenIO.world.getBiomeIdx(z)));r=d+H;V=this.r.img.getSprite("maxmap_bg.png");if(null!=V){y=V.dSize.w;var E=Math.round(b+(l/2-y/2));this.r.drawSprite(V,E,r)}y=l;this.r.claimDateThreshold=this.timelineActive?new Date(this.timelinePoint):null;this.mouseOverBiome=this.r.drawIOMap(this.main.worldGenIO,y,E,r,n,p,this.mapViewState===e.claims);null!=this.mouseOverBiome&&this.main.infoBox.showBiome(this.mouseOverBiome,debug.drawAllTiles);V=y/this.main.worldGenIO.worldGenCtx.canvas.width;null==
this.youAreHereTime&&(this.youAreHereCol=this.youAreHereTime=0);this.youAreHereTime+=this.r.timeDelta;this.youAreHereTime>=config.io.youAreHereFlashTime&&(this.youAreHereTime-=config.io.youAreHereFlashTime,this.youAreHereCol=0===this.youAreHereCol?1:0);v=this.hubsDisplayed||this.newGameState===C.new;if(null==this.mouseOverBiome||v)null!=this.highlightedScore&&(da=this.highlightedScore.userID);else if(D=this.main.worldGenIO.getBiomeDict(this.mouseOverBiome).claim,null!=D)var da=D.user.userID;if(null!=
da){D=[];var Y=this.main.worldGenIO.biomes;for(I in Y){var F=Y[I];null!=F.claim&&F.claim.user.userID===da&&D.push(F.pos)}if(0<D.length){this.r.ctx.save();this.r.ctx.fillStyle=0===this.youAreHereCol?config.io.youAreHereCol1:config.io.youAreHereCol2;this.r.ctx.globalAlpha=1;var J=Math.ceil(V);F=0;for(Y=D.length;F<Y;F++){var I=D[F];this.r.ctx.fillRect(Math.floor(I.x*V+E),Math.floor(I.y*V+r),J,J)}this.r.ctx.restore()}}if(null!=z){if(!this.timelineActive){D=this.r.img.partyTileHidden;F=config.anim.partyArrowFrames;
I=Math.round(this.r.timeTotal*config.anim.partyAnimSpeed)%F;Y=$jscomp.makeIterator([D.width,D.height/F]);F=Y.next().value;J=Y.next().value;var K=$jscomp.makeIterator([.5*this.s*F,.5*this.s*J]);Y=K.next().value;K=K.next().value;var L=new u((z.x+.5)*V+E,(z.y+2.5)*V+r);this.r.ctx.drawImage(D,0,I*J,F,J,L.x-Y/2,L.y-K/2,Y,K);this.newGameState!==C.new&&null==da&&(da=0===this.youAreHereCol?config.io.youAreHereCol1:config.io.youAreHereCol2,this.r.ctx.fillStyle=da,this.r.ctx.globalAlpha=.5,this.r.ctx.fillRect(z.x*
V+E,z.y*V+r,V,V))}z=d+H+y;null!=T&&this.drawBiomeInfo(T,b,z,l,d+m-z-G,n,p)}if(v){n=debug.drawAllTiles?this.main.worldGenIO.hubBiomes:this.main.worldGenIO.unlockedHubs;null!=this.mouseOverBiome&&(w=n.min(function(a){return t.main.worldGenIO.world.getBiomePosFromIdx(a).sub(t.mouseOverBiome).length()}));p=0;for(G=n.length;p<G;p++){H=n[p];if(this.timelineActive&&null!=(null!=(x=this.main.worldGenIO.unlockedHubDates)?x[H]:void 0)&&(m=this.main.worldGenIO.unlockedHubDates[H],m>this.r.claimDateThreshold))continue;
m=this.main.worldGenIO.world.getBiomePosFromIdx(H);z=m.x*V+E+.5*V;m=m.y*V+r+.5*V;H=(H=H===w||this.newGameState===C.new&&T===H)?"hud_icon_outpost_selected.png":"hud_icon_outpost.png";this.r.drawSprite(H,z,m,{halign:"center",valign:"center"})}null!=w&&(x=this.main.worldGenIO.worldSegmentList[this.main.worldGenIO.biomes[w].worldSegment],this.r.ctx.font=config.fonts.technicalSmall,n=3*this.s,p=this.r.ctx.measureText(x.name).width+2*n,T=10*this.s,m=this.main.worldGenIO.world.getBiomePosFromIdx(w),E=m.x*
V+E,r=m.y*V+r-n,this.r.drawInfoBox(E-p/2,r-T,p,T),this.r.drawText(x.name,E,r-n,{halign:"center",font:config.fonts.technicalSmall,fillColor:config.colors.help,os:0}),this.newGameState===C.new&&(this.mouseAction={id:"hubSelect",hub:w}))}this.timelineActive?(w=Object.values(this.main.worldGenIO.biomes),E=w.sum(function(a){var b;return null!=(null!=(b=a.claim)?b.record:void 0)&&a.claim.record.claimDate<t.r.claimDateThreshold?1:0}),E/=w.length):E=this.main.worldGenIO.getExploredStat();w=100*E;w=q.toText("txt-io-explored").replace("$val",
w.toFixed(1));return this.drawTitle(w,b+l/2,d,.2*l)};a.prototype.drawTitle=function(b,c,d,e){B(this,a);this.r.ctx.font=config.fonts.themedSmall;var f=q.wrap(b,e,this.r.ctx);this.r.ctx.globalAlpha=1;d+=8*this.s;var g=[];b=0;for(e=f.length;b<e;b++){var h=f[b];this.r.drawText(h,c,d,{os:0,font:config.fonts.themedSmall,halign:"center",fillColor:config.ioNewGameTitleColor});g.push(d+=8*this.s)}return g};a.prototype.drawBiomeInfo=function(b,c,d,e,f,g,h){B(this,a);this.r.ctx.globalAlpha=1;var k=this.main.worldGenIO.biomes[b];
n.assert(null!=k);var l=this.main.worldGenIO.worldSegmentList[k.worldSegment];n.assert(null!=l);b=t.getPocket(k.pocketID);c+=e/2;var m=d;d+=10*this.s;if(this.timelineActive){var p=Math.min(Date.now(),this.timelinePoint);p-=this.main.iomp.worldData.worldStart;p=q.timeDurationToString(p)}else p=this.newGameState===C.new?"txt-io-hub-start":"txt-io-player-location",p=q.toText(p)+":";this.r.drawText(p,c,d,{halign:"center",valign:"top",font:config.fonts.themedSmall,fillColor:config.ioNewGameTitleColor});
d+=4*this.s;if(null!=b.previewSprite&&(p=this.r.img.getSprite(b.previewSprite),n.assert(null!=p),null!=p)){e=Math.min(1,e/p.dSize.w);var r=Math.min(1,(f-(d-m))/p.dSize.h);m=Math.round(e*p.size.w);f=Math.round(r*p.size.h);e=m/p.size.w;r=f/p.size.h;e*=p.dSize.w;r*=p.dSize.h;this.r.ctx.drawImage(p.img,(p.size.w-m)/2,(p.size.h-f)/2,m,f,c-e/2,d,e,r)}d+=15*this.s;this.r.drawText(l.name,c,d,{halign:"center",font:config.fonts.themedLarge});d+=A;k=this.main.worldGenIO.difficultyLvls.indexOf(k.worldLvl)+1;
p=this.r.img.getSprite(config.io.segmentDifficultySprite);if(null!=p)for(l=4*this.s,e=p.dSize.w+l,m=c-(e*k-l)/2,l=f=0;0<=k?f<k:f>k;l=0<=k?++f:--f)this.r.drawSprite(p,m+e*l,d);d+=20*this.s;this.r.drawText(q.toText(b.name),c,d,{halign:"center",font:config.fonts.themedSmall});if(this.newGameState===C.new&&1<this.main.worldGenIO.unlockedHubs.length)return b=this.r.img.getSprite("hud_scrollButton_charSelect_left.png"),p=this.r.img.getSprite("hud_scrollButton_charSelect_right.png"),d-=b.dSize.h,d+=8*this.s,
e=c-100*this.s,this.r.hitBox(e,d-b.dSize.h/2,b.dSize.w,b.dSize.h,g,h)&&(this.mouseAction={id:"prevHub"},e-=2*this.s),this.r.drawSprite(b,e,d,{valign:"center",halign:"left"}),c+=100*this.s,this.r.hitBox(c-p.dSize.w,d-b.dSize.h/2,p.dSize.w,p.dSize.h,g,h)&&(this.mouseAction={id:"nextHub"},c+=2*this.s),this.r.drawSprite(p,c,d,{valign:"center",halign:"right"})};a.prototype.drawNews=function(b,c,d,e,f,g,h){B(this,a);var k=this.main.mainMenu.drawNewsBox(b,c,d,e,f,g,h,!1);null!=k&&(this.mouseAction=k);var l=
60*this.s;k=25*this.s;b+=d/2;c=c+e-k-6*this.s;if(this.r.drawButton(q.toText("txt-base-ok"),b,c,l,k,f,g,h))return this.mouseAction={id:"dismissNews"}};a.prototype.updatePackLists=function(){var b=this,c;B(this,a);this.availPacksToDisplay={};var d=this.main.ioInv.packs;for(c in d){var e=d[c];var f=this.addedPacks.count(function(a){return a===c});f=e-f;this.main.ioInv.isPackHeld(c)&&(f=1);0<f&&(this.availPacksToDisplay[c]=f)}var g=function(a,b){var c=t.getPack(a);var d=t.getPack(b);var e=t.arrify(c.characters).length;
var f=t.arrify(d.characters).length;var g=t.arrify(c.statuses).length;var h=t.arrify(d.statuses).length;c=t.arrify(c.items).length;d=t.arrify(d.items).length;return 0<e&&0===f?-1:0<f&&0===e?1:0<g&&0===h?-1:0<h&&0===g?1:0<c&&0===d||0<d&&0===c||e>f?-1:e<f?1:g>h?-1:g<h?1:c>d?-1:c<d?1:a.localeCompare(b)};d=function(a,c){var d=b.main.ioInv.isPackHeld(a);var e=b.main.ioInv.isPackHeld(c);if(d!==e)return d?-1:1;d=t.getPack(a);e=t.getPack(c);return e.value<d.value?-1:e.value>d.value?1:g(a,c)};this.availPacksList=
Object.keys(this.availPacksToDisplay);this.packViewState===l.rarity?this.availPacksList.sort(d):this.packViewState===l.type?this.availPacksList.sort(g):this.availPacksList=this.main.ioInv.packAddOrder.filter(function(a){return null!=b.availPacksToDisplay[a]});return this.packOffset=J.clamp(this.packOffset,0,Math.ceil(this.availPacksList.length/5)-1)};a.prototype.drawPacks=function(b,d,e,f,g,h,k){var n;B(this,a);var r=d;var t=A;var v=20*this.s;var u=20*this.s;var y=config.packImageSize[1]*this.s+t;
var x=b+e/2;var D=.35*e;var H=u+1*(y+t)+2*this.s;this.drawTitle(q.toText(this.newGameState===C.resume?"txt-io-packs-running":"txt-io-packs-selected")+":",x,d,D);var G=this.newGameState===C.new?this.addedPacks:null!=(n=this.main.party.stats.packs)?n:[];d=this.drawPackSet(G,0,b,d+u,e,1*y+0*t,g,h,k,!1);null!=d&&(this.displayPack(d,!0),this.isSelectingHoldCrate?this.mouseAction={id:"holdCrate",pack:d}:this.newGameState===C.new&&(this.mouseAction={id:"removePack",pack:d}));H=f-(r+H+t-r);d=r+f-H+v/3;H-=
v;this.drawTitle(q.toText("txt-io-packs-available")+":",x,d,D);if(null!=this.scrollPacksX&&null!=this.scrollPacksY){D=Math.ceil(this.availPacksList.length/this.scrollPacksY);D-=this.scrollPacksX;var z=0<this.packOffset;var V=this.packOffset<D}if(z||V)v=this.r.img.getSprite("hud_scrollButton_charSelect_left.png"),y=this.r.img.getSprite("hud_scrollButton_charSelect_right.png"),D=d+8*this.s,G=55*this.s,z&&(z=x-G,this.r.hitBox(z,D-v.dSize.h/2,v.dSize.w,v.dSize.h,g,h)&&(this.mouseAction={id:"prevPackPage"},
z-=2*this.s),this.r.drawSprite(v,z,D,{valign:"center",halign:"left"})),V&&(z=x+G,this.r.hitBox(z-y.dSize.w,D-v.dSize.h/2,y.dSize.w,y.dSize.h,g,h)&&(this.mouseAction={id:"nextPackPage"},z+=2*this.s),this.r.drawSprite(y,z,D,{valign:"center",halign:"right"}));switch(this.packViewState){case l.type:var T=w;break;case l.rarity:T=p;break;case l.recent:T=m}D=[w,p,m];this.newGameState!==C.new&&D.push(c);this.drawTinyButtonSet(D,[T],b+e,d+3*this.s,g,h,k);T=26*this.s;d=this.drawPackSet(this.availPacksList,
this.packOffset,b,d+u,e,H-(T+A)-u-t,g,h,k);null!=d&&(b=this.invalidPacks[d],this.displayPack(d,!1,b),this.isSelectingHoldCrate?this.mouseAction={id:"holdCrate",pack:d}:this.newGameState===C.new&&null==b&&this.addedPacks.length<config.maximumPartyPacks&&(this.mouseAction={id:"addPack",pack:d}));u=q.toText("txt-io-pack-hold");this.r.ctx.font=config.fonts.themedLarge;t=Math.ceil(this.r.ctx.measureText(u).width+32*this.s);d=r+f-T;b=x-28*this.s;f=this.r.img.getSprite("hud_io_medal.png");r=Math.min(Math.round(b+
t/2),418*this.s);this.r.drawSprite(f,r,d,{halign:"left",valign:"center"});this.r.hitBox(r,d-f.dSize.h/2,f.dSize.w,f.dSize.h,g,h)&&(D=this.main.iomp.getNumClaimsForNextMedal(),this.main.infoBox.setTooltip(q.toText(1===D?"txt-io-premium-medals-help-singular":"txt-io-premium-medals-help").replace("$val",D)));D=d+3*this.s;f=r+f.dSize.w+2*this.s;H=this.main.ioInv.getNumMedals();this.r.drawText("x "+H,f,d+2*this.s,{font:config.fonts.technicalLarge,os:0});d-=T/2+A/2;f=q.toText("txt-io-medals-use");r=q.toText("txt-io-medals-buyHelp");
this.isSelectingHoldCrate&&(u=q.toText("txt-barter-cancel"));this.r.drawButton(u,b,d,t-16*this.s,T,g,h,k,{panel:config.panel.demoTutorial,fillColor:"#2e2c28",shadowColor:"#ffdf5e"})&&(this.mouseAction={id:"toggleHoldCrate"},k=f+config.diaryText.separator+r,this.main.infoBox.setTooltip(k));if(0<H&&!this.medalTutorialDismissed&&this.newGameState===C.new&&this.dismissedPacksTutorial&&(b=140*this.s,k=this.r.img.getSprite("hud_io_bigArrow_tip.png"),x=x-t/4-b,D-=k.dSize.h/2,this.r.drawTutorialArrow(f,r,
x,D,b),this.r.hitBox(x,D,e,k.dSize.h,g,h)))return this.medalTutorialDismissed=!0};a.prototype.setSelectingHoldCrate=function(b){B(this,a);this.isSelectingHoldCrate=b;return this.r.enableMouseMoveCursor(!1)};a.prototype.displayPack=function(b,c,d){var e,f,g,h,k,l,m;B(this,a);var p=t.getPack(b);var r=[{text:this.main.ioInv.getPackTitle(b),col:"orange"}];b=this.getPackTimer(b);null!=b&&r.push({text:q.toText("txt-io-pack-timer").replace("$val",b),col:"yellow"});var w=t.arrify(p.statuses);0<w.length&&
r.push({text:q.toText("txt-io-packs-perks")+":"});b=0;for(l=w.length;b<l;b++){var v=w[b];r.push({text:"  "+q.parse(t.getStatus(v).title,null!=(e=null!=(f=this.main.party)?null!=(g=f.getExplorer())?g.gender:void 0:void 0)?e:"male")})}f=t.arrify(p.characters);0<f.length&&r.push({text:q.toText("txt-io-packs-chars")+":"});b=0;for(l=f.length;b<l;b++)e=f[b],g=null!=e.variations&&0<e.variations.length?e.variations[0].gender:"male",r.push({text:"  "+q.parse(t.getCharacter(e).title,g)});0<Object.keys(null!=
(h=p.items)?h:{}).length&&r.push({text:q.toText("txt-io-packs-items")+":"});p=null!=(m=p.items)?m:{};for(k in p)m=p[k],h=t.getItem(k),h=q.toText(h.name),1===m?r.push({text:"  "+h}):r.push({text:"  "+m+" x "+h});null!=d&&(n.assert(d.overBurden||d.overFilled||d.alreadyAdded),d.overBurden&&r.push({text:q.toText("txt-io-packs-overburden"),col:"orange"}),d.overFilled&&r.push({text:q.toText("txt-io-packs-overFilled"),col:"orange"}),d.alreadyAdded&&r.push({text:q.toText("txt-io-packs-alreadyAdded"),col:"orange"}));
!c&&this.addedPacks.length>=config.maximumPartyPacks&&r.push({text:q.toText("txt-io-packs-maximum"),col:"orange"});if(null==this.charToDraw)return this.main.infoBox.setInfo(r)};a.prototype.getPackTimer=function(a){var b=t.getPack(a);if(null==b||0===b.value)return null;b=this.main.ioInv.packsLastUsed[a];if(null==b)return null;a=(new Date).getTime();a=6E4*config.io.packTimerMins-(a-b);return 0>a?null:q.timeDurationToString(a)};a.prototype.drawPackSet=function(b,c,d,e,f,g,h,k,l,m){m=void 0===m?!0:m;
var p,q;B(this,a);n.assert(null!=b);var r=A;var t=this.r.img.getSprite("hud_io_crate_bg_rank1.png");r=new R(t.dSize.w+r,t.dSize.h+r);var w=Math.max(1,Math.floor(f/r.w));g=Math.max(1,Math.floor(g/r.h));t=r.x;r.x=Math.ceil(f/w)+1*this.s;r.y+=r.x-t;w*g<b.length&&(this.scrollPacksX=w,this.scrollPacksY=g);f=e;var v=c*g;this.r.ctx.globalAlpha=1;for(c=0;0<=w?c<w:c>w;0<=w?++c:--c){e=f;var u=0;for(q=g;0<=q?u<q:u>q;0<=q?++u:--u){t=b[v];if(null!=t){var y=m?this.availPacksToDisplay[t]:1;(y=this.main.ioInv.drawPack(t,
d,e,h,k,l,y))&&(p=t);m&&null!=this.getPackTimer(t)&&!this.isSelectingHoldCrate&&(t=this.r.img.getSprite("hud_io_crate_bg_rank1.png"),this.r.drawSprite("res_fxt_treasureLocation.png",d+t.dSize.w/2,e+t.dSize.h/2,{scale:2,halign:"center",valign:"center"}))}else this.r.drawSprite("hud_io_crate_closed_dark.png",d,e);e+=r.y;v+=1}d+=r.x}return p};a.prototype.drawStoredExplorer=function(b,c,d,e,f){B(this,a);var g=this.main.ioInv.hasExplorerSlotUnlocked(b);var h=this.main.ioInv.getStoredExplorer(b);var k=
g&&null!=h?this.r.img.getSprite("hud_charFrame_empty.png"):this.r.img.getSprite("hud_charFrame_silhouette.png");var l=d+k.dSize.h;this.r.drawSprite(k,c,l,{valign:"bottom",halign:"left"});g?null!=h&&(b=c+k.dSize.w/2,l-=4*this.s,this.r.drawSprite(h.portrait,b,l,{valign:"bottom",halign:"center"})):(this.r.ctx.fillStyle="black",this.r.ctx.globalAlpha=.5,this.r.ctx.fillRect(c,d,k.dSize.w,k.dSize.h),this.r.ctx.globalAlpha=1,h=c+k.dSize.x/2,l=d+k.dSize.y/2,g=this.r.img.getSprite("hud_medal.png"),this.r.drawSprite(g,
h,l,{halign:"center",valign:"center",scale:.5}),b=config.io.storedExplorerSlotCost[b],this.r.drawText(b,h+.5*this.s,l+2*this.s,{font:config.fonts.technicalSmall,halign:"center",fillColor:"black",shadowColor:"white"}));return this.r.hitBox(c,d,k.dSize.w,k.dSize.h,e,f)};a.prototype.updateCharDragCtx=function(c,d){B(this,a);if(this.newGameState===C.new&&this.viewState===b.map)if(this.main.ioInv.hasExplorerSlotUnlocked(c)){if(d&&null==this.dragCtx)return this.dragCtx=c;if(!d&&null!=this.dragCtx)return this.handleDrag(this.dragCtx,
c),this.dragCtx=null}else(d&&null==this.dragCtx||null!=this.dragCtx&&!d)&&jc.beginTransaction(this.main,{item:c.toString(),type:cb.explorerSlot})};a.prototype.handleDrag=function(b,c){var d;B(this,a);if(b!==c&&(-1===b||-1===c)&&(-1===b?(b=this.main.party.getExplorer(),null!=b&&(d={explorerTribe:b.sourceTribeGenId,explorerSeed:b.sourceTribeGenSeed,explorerGender:b.gender})):d=this.main.ioInv.getStoredExplorer(b),null!=d))return-1===c?(c=this.main.party.getExplorer(),c.setVariationWithGender(d.explorerGender),
c.initCharGen(d.explorerTribe,d.explorerSeed)):this.main.ioInv.setStoredExplorer(d,c)};a.prototype.drawDrag=function(b,c,d){var e;B(this,a);d||(this.dragCtx=null);if(null!=this.dragCtx&&(d=0<=this.dragCtx?(e=this.main.ioInv.getStoredExplorer(this.dragCtx),null!=e?e.portrait:void 0):(e=this.main.party.getExplorer(),null!=e?e.portrait:void 0),null!=d))return this.r.ctx.globalAlpha=.8,this.r.drawSprite(d,b,c,{halign:"center",valign:"center"}),this.r.ctx.globalAlpha=1};a.prototype.drawExpedition=function(c,
e,f,g){var h,k,l;B(this,a);var m=$jscomp.makeIterator(this.r.getCanvasSize());m.next();m=m.next().value;this.r.ctx.save();var n=185*this.s;var p=3*this.s;var r=this.main.party.getExplorer();var t={valign:"bottom",halign:"left"};var w=this.r.img.getSprite("hud_char_frame_io.png");this.r.drawSprite(w,p,n,t);t.scale=1.5;var v=p+3.5*this.s*t.scale;var y=n-5*this.s*t.scale;this.r.drawPortrait(r,v,y,t);null==this.charToDraw&&this.r.hitBox(p,n-w.dSize.h,w.dSize.w,w.dSize.h,e,f)&&(this.charToDraw=r,m=$jscomp.makeIterator(this.r.getCanvasSize()),
y=m.next().value,m=m.next().value,this.chInfoBoxPos=new u(y-200*this.s,m-150*this.s));this.newGameState===C.new&&(y=this.drawTinyButton(d,null,p+14*this.s,n-14*this.s,e,f,g),null!=y?this.mouseAction=y:this.r.hitBox(p,n-w.dSize.h,w.dSize.w,w.dSize.h,e,f)&&this.updateCharDragCtx(-1,g));this.newGameState===C.new?(y=this.viewState===b.packs&&this.dismissedPacksTutorial,v=n-w.dSize.h+4*this.s,this.viewState!==b.packs||this.dismissedPacksTutorial?this.viewState!==b.map||this.dismissedHubTutorial||this.r.drawTutorialArrow(q.toText("txt-io-newgame-outpost-title"),
q.toText("txt-io-newgame-outpost-help"),p+68*this.s,v,c):this.r.drawTutorialArrow(q.toText("txt-io-newgame-packs-title"),q.toText("txt-io-newgame-packs-help"),p+68*this.s,v,c)):y=!0;if(y){v=p+68*this.s;y=n-4*this.s;t=$jscomp.makeIterator([32*this.s,32*this.s]);w=t.next().value;var x=t.next().value;t=this.r.img.getSprite("hud_unit_background_1.png");var D=t.dSize.w-3*this.s;var G=Math.max(this.main.party.maxUnitCount-1,this.main.party.persons.length-1+Math.max(0,this.main.party.getFreeUnitCount()));
for(h=k=G-1;0<=k;h=k+=-1)this.r.drawSprite(t,v+D*h-4*this.s,y+4*this.s,{scale:1,valign:"bottom",mirror:h===G-1});v-=3*this.s;var H=this.main.party.persons;G=0;for(l=H.length;G<l;G++)h=H[G],h.isSpecial||(k=v+t.dSize.w/2,this.r.drawPortrait(h,k,y-1*this.s,{halign:"center",scale:1}),null==this.charToDraw&&this.r.hitBox(k-w/2,y-x,w,x,e,f)&&(this.charToDraw=h,this.chInfoBoxPos=new u(v+w-3*this.s,y-x)),v+=D);v=p+66*this.s;y=y-t.dSize.h-12*this.s;w=14*this.s;this.statusToDraw=null;r=r.statuses;for(z in r)t=
r[z],null!=t.title&&(this.r.drawStatusIcon(t,v,y,w),this.r.hitBox(v,y,w,w,e,f)&&(this.statusToDraw=t),v+=w+2*this.s);p+=A;n+=10*this.s;this.invBar.gridOffset=new R(p,n,100*this.s,20*this.s);if(null!=this.invBar)this.invBar.onMouseMove(e,f);n=this.invBar.drawBackground(!0,e,f,g);this.main.drawItemInfo();n&&(this.mouseAction={id:"tabInventory"})}else if(this.dismissedHubTutorial&&this.viewState===b.map&&this.newGameState===C.new){var z=this.r.img.getSprite("hud_charFrame_empty.png");p=c/2-z.dSize.w/
2;y=n-w.dSize.h+20*this.s;this.r.drawText(q.toText("txt-io-newgame-slots"),p+2*this.s,y-4*this.s,{font:config.fonts.themedSmall,fillColor:config.ioNewGameTitleColor});h=r=0;for(w=config.io.storedExplorerSlotCost.length;0<=w?r<w:r>w;h=0<=w?++r:--r)(n=this.drawStoredExplorer(h,p,y,e,f))&&this.updateCharDragCtx(h,g),p+=z.dSize.w+A;this.r.drawWrappedText(q.toText("txt-io-newgame-slots-desc"),.7*c,y+z.dSize.h+A,.5*c,{font:config.fonts.technicalSmall,fillColor:config.ioNewGameTitleColor,halign:"center"})}this.r.ctx.restore();
z=new R(130*this.s,40*this.s);if(this.main.iomp.isServerOK())if(this.newGameState===C.new){if(n=this.viewState===b.packs?"txt-worldmap-start":"txt-io-newgame-outpost-confirm",this.main.party.inv.isOverburden()?(n=this.main.party.inv.items.length-this.main.party.getCapacity(),n=q.toText(config.help.overburden).replace("$val",n),this.r.drawWarningBar(n,m-A-z.h/2,c/2)):this.main.party.isOverfilled()?(n=q.toText(config.help.overfilled),this.r.drawWarningBar(n,m-A-z.h/2,c/2)):(p=q.toText("txt-base-next")+
":",r=m-A-.7*z.h,this.r.drawButton(q.toText(n),c/2,m-A-z.h,z.w,z.h,e,f,g)&&(this.mouseAction={id:"advanceNewState"},g&&(r+=2*this.s)),this.r.drawText(p,c/2,r,{font:config.fonts.technicalSmall,os:0,fillColor:"black",halign:"center"})),z=new R(40*this.s,20*this.s),c=$jscomp.makeIterator(this.r.getCanvasSize()),c.next(),m=c.next().value,this.r.drawButton(q.toText("txt-generic-back"),A+z.w/2,m-A-z.h,z.w,z.h,e,f,g,{font:config.fonts.technicalSmall,os:0}))return this.mouseAction={id:"backNewState"}}else return z=
new R(80*this.s,28*this.s),n=m-A-z.h,this.r.drawButton(q.toText("txt-base-continue"),c/2+z.w/2+A,n,z.w,z.h,e,f,g)&&(this.mouseAction={id:"continue"}),this.r.drawButton(q.toText("txt-generic-abort"),c/2-z.w/2-A,n,z.w,z.h,e,f,g)&&(this.mouseAction={id:"abort"}),n-=8*this.s,this.r.drawText(q.toText("txt-io-currExped"),c/2,n,{os:0,font:config.fonts.themedSmall,halign:"center",fillColor:config.ioNewGameTitleColor});else if(n=this.main.iomp.getServerText(),c=10*this.s,m=m-A-z.h/2,this.r.drawWarningBar(n,
m,c,"left"),n=100*this.s,this.r.drawButton(q.toText("txt-mod-refresh"),c+n/2,m-35*this.s,n,25*this.s,e,f,g))return this.mouseAction={id:"refreshWindow"}};a.prototype.drawScores=function(a,b,c,d,e,f,g){var h,k;var l=a;var m=b;var n=A;var p=20*this.s;var r=d-n-p;switch(this.scoreViewState){case x.claims:var t=v;break;case x.score:t=D;break;case x.goals:t=y}this.drawTinyButtonSet([y,v,D],[t],a+c,b+3*this.s,e,f,g);b+=p;t=function(){switch(this.scoreViewState){case x.score:return"txt-io-highscores-top";
case x.claims:return"txt-io-highscores-claims";case x.goals:return"txt-io-highscores-goals"}}.call(this);this.r.drawText(q.toText(t),a,b-n,{font:config.fonts.themedSmall,fillColor:config.ioNewGameTitleColor});if(this.loadingTopScores&&0===this.topScores.length&&this.scoreViewState===x.score)b+=30*this.s,this.r.drawText(q.toText("txt-loading"),a+c/2,b,{font:config.fonts.technicalLarge,halign:"center",fillColor:"white",os:0});else{if(this.scoreViewState===x.score)var w=null!=(h=this.topScores)?h:[];
else this.scoreViewState===x.claims?w=this.main.worldGenIO.topClaimScores:this.scoreViewState===x.goals&&(w=this.main.iohighscore.goalScores);p=Math.round(r/10);var u=Math.round(c/1);var z=b;for(r=h=0;1>h;r=++h){b=z;for(k=t=0;10>t;k=++t){var G=k+10*r;k=w[G];if(null==k)break;G=this.main.iohighscore.drawScore(k,G,a,b,u,e,f);"hitScore"===G?this.highlightedScore=k:"hitUser"===G&&(this.highlightedStats=k.userID);b+=p}a+=u}this.scoreViewState===x.goals&&10>w.length&&this.r.drawWrappedText(q.toText("txt-io-pyramid-unclaimed"),
a-u,b,u,{font:config.fonts.technicalSmall,halign:"left",os:0,fillColor:config.ioNewGameTitleColor})}b=40*this.s;a=20*this.s;c=l+c-b/2;d=m+d-a+n;if(this.r.drawButton(q.toText("txt-base-more")+"...",c,d,b,a,e,f,g,{font:config.fonts.technicalSmall,os:0}))return this.mouseAction={id:"moreScores"}};a.prototype.onMouseWheel=function(c){var d;B(this,a);if("ionewgame"===this.main.getMainState())switch(this.viewState){case b.map:if(1===this.main.mainStates.length||this.newGameState===C.new)break;if(this.mouseOverBiome&&
0<c){c=new u((this.mouseOverBiome.x+.5)*config.board.biomeSize[0],(this.mouseOverBiome.y+.5)*config.board.biomeSize[1]);for(this.r.zoomLevel=Math.floor(this.r.zoomLevel);this.r.zoomLevel>config.board.maxZoom[1];)this.r.zoomTarget=this.r.zoomLevel,this.r.adjustZoomTarget(-1),this.r.adjustZoom(-1),this.r.zoomTarget=this.r.zoomLevel;this.r.cam.resetScroll();var e=this.r.cam.mouseToTilePos(this.main.mousePos.x,this.main.mousePos.y);for(d=0;!e.eq(c)&&10>d;)d+=1,e=c.sub(e),this.r.cam.centerOnPos(this.r.cam.screenCenterPos.add(e)),
e=this.r.cam.mouseToTilePos(this.main.mousePos.x,this.main.mousePos.y);this.main.popMainState()}break;case b.packs:this.adjustPackScroll(0<c?-1:1)}};a.prototype.adjustPackScroll=function(b){B(this,a);this.packOffset+=b;null!=this.scrollPacksX&&null!=this.scrollPacksY&&(b=Math.ceil(this.availPacksList.length/this.scrollPacksY),b-=this.scrollPacksX,this.packOffset=J.clamp(this.packOffset,0,b))};a.prototype.drawHeader=function(a,b,c){var d=$jscomp.makeIterator(this.r.getCanvasSize());var e=d.next().value;
d.next();A=4*this.s;d=null;var f=this.r.img.getSprite("hud_button_options.png");var g=q.toText("txt-io-return-tce");this.r.ctx.font=config.fonts.technicalLarge;var h=this.r.ctx.measureText(g).width;var k=new R(h+80*this.s,f.dSize.h);h=e-A-k.w;var l=A;var m="white";var p=l;this.r.hitBox(h,l,k.w,k.y,a,b)&&(m="red",this.main.infoBox.setInfo([{text:q.toText("txt-io-return-tce-tooltip"),col:config.colors.help}]),d={id:"tce"},c&&(p+=2*this.s));this.r.drawPanel("backButton",h,p,k.w,k.h);this.r.drawText(g,
h+k.w-74*this.s,p+16*this.s,{fillColor:m,halign:"right",font:config.fonts.technicalLarge});this.r.drawSprite("title_rivals_single.png",h+k.w-38*this.s,p+k.h/2+1*this.s,{halign:"center",valign:"center",scale:.5});h-=A+f.dSize.w;l=A;this.r.drawSprite(f,h,l,{mX:a,mY:b})&&(this.main.infoBox.setInfo([{text:q.toText(config.help.settings.button),col:config.colors.help}]),d={id:"settings"});if(debug.runOffline)return d;f=this.r.img.getSprite("hud_button_discord.png");h-=A+f.dSize.w;this.r.drawSprite(f,h,
l,{mX:a,mY:b})&&(this.main.infoBox.setInfo([{text:q.toText("txt-io-discord"),col:config.colors.help}]),d={id:"discord"});null!=this.main.user&&((g=!window.isSteam&&(""===this.main.user.get("email")||void 0===this.main.user.get("email")))?(e=g?q.toText("txt-io-claim-account"):q.toText("txt-io-manage-account"),g=45*this.s,this.r.drawButton(e,h-A-g/2,l,g,f.dSize.h,a,b,c,{font:config.fonts.technicalSmall,os:0})&&(d={id:"account"})):(this.r.ctx.globalAlpha=1,this.r.ctx.fillStyle="gray",this.r.ctx.font=
config.fonts.technicalSmall,l+=34*this.s,h=e-A,b=q.toText("txt-io-state-world")+" "+this.main.iomp.worldData.worldID,b+=" | rivals v"+n.getVersionString(),debug.isDevMode&&(b+=" | dev"),this.r.drawText(b,h,l,{halign:"right",os:0,fillColor:config.ioNewGameTitleColor}),h-=this.r.ctx.measureText(b).width+A/2,null!=this.main.user&&(b=window.isSteam?""+this.main.user.get("displayName"):this.main.user.get("username")+" | "+this.main.user.get("displayName"),a=A+1*this.s,this.r.drawText(b,h-a-2*this.s,l,
{halign:"right",os:0,fillColor:config.ioNewGameTitleColor}),this.r.ctx.fillStyle=this.main.user.get("colour"),this.r.ctx.fillRect(h-a,l-a+1*this.s,a,a))));return d};var b={packs:0,map:1,news:2};var c={sprite:"hud_io_smallButton_news.png",event:{id:"news"},tooltip:"txt-tooltip-io-news"};var d={sprite:"hud_io_randomize.png",event:{id:"regenExplorer"}};var e={claims:0,pockets:1};var f={sprite:"hud_io_smallButton_player.png",spritePressed:"hud_io_smallButton_player_selected.png",event:{id:"changeMapState",
state:e.claims},tooltip:"txt-tooltip-map-claims"};var g={sprite:"hud_io_smallButton_time.png",spritePressed:"hud_io_smallButton_time_selected.png",event:{id:"timelineToggle"},tooltip:"txt-tooltip-map-timeline"};var h={sprite:"hud_io_smallButton_outpost.png",spritePressed:"hud_io_smallButton_outpost_selected.png",event:{id:"toggleHubs"},tooltip:"txt-tooltip-map-hubs"};var k={sprite:"hud_io_smallButton_world.png",spritePressed:"hud_io_smallButton_world_selected.png",event:{id:"changeMapState",state:e.pockets},
tooltip:"txt-tooltip-map-pockets"};var l={recent:0,rarity:1,type:2};var m={sprite:"hud_io_smallButton_time.png",spritePressed:"hud_io_smallButton_time_selected.png",event:{id:"changePackState",state:l.recent},tooltip:"txt-tooltip-packs-recent"};var p={sprite:"hud_io_smallButton_rarity.png",spritePressed:"hud_io_smallButton_rarity_selected.png",event:{id:"changePackState",state:l.rarity},tooltip:"txt-tooltip-packs-rarity"};var w={sprite:"hud_io_smallButton_type.png",spritePressed:"hud_io_smallButton_type_selected.png",
event:{id:"changePackState",state:l.type},tooltip:"txt-tooltip-packs-type"};var x={score:0,claims:1,goals:2};var D={sprite:"hud_io_smallButton_world.png",spritePressed:"hud_io_smallButton_world_selected.png",event:{id:"changeScoreState",state:x.score},tooltip:"txt-base-fame"};var v={sprite:"hud_io_smallButton_player.png",spritePressed:"hud_io_smallButton_player_selected.png",event:{id:"changeScoreState",state:x.claims},tooltip:"txt-tooltip-score-claims"};var y={sprite:"hud_io_smallButton_pyramid.png",
spritePressed:"hud_io_smallButton_pyramid_selected.png",event:{id:"changeScoreState",state:x.goals},tooltip:"txt-tooltip-score-goals"};var C={none:0,new:1,resume:2};var A=4;return a}.call(this);var ma=function(a){this.handleMedalsChange=this.handleMedalsChange.bind(this);this.handleItemAdded=this.handleItemAdded.bind(this);this.handleItemRemoved=this.handleItemRemoved.bind(this);this.handleAlphaKeyGiven=this.handleAlphaKeyGiven.bind(this);this.canGivePack=this.canGivePack.bind(this);this.isItemOwned=
this.isItemOwned.bind(this);this.isPackHeld=this.isPackHeld.bind(this);this.isPackInInventory=this.isPackInInventory.bind(this);this.getNumMedals=this.getNumMedals.bind(this);this.resetInventory=this.resetInventory.bind(this);this.flushInvData=this.flushInvData.bind(this);this.cacheStoredExplorerPortrait=this.cacheStoredExplorerPortrait.bind(this);this.setStoredExplorer=this.setStoredExplorer.bind(this);this.getStoredExplorer=this.getStoredExplorer.bind(this);this.getAllStoredExplorers=this.getAllStoredExplorers.bind(this);
this.hasExplorerSlotUnlocked=this.hasExplorerSlotUnlocked.bind(this);this.createPackIcon=this.createPackIcon.bind(this);this.getPackTitle=this.getPackTitle.bind(this);this.drawPack=this.drawPack.bind(this);this.main=a;this.packStartDisplay=0;this.s=this.main.s;this.r=this.main.r;this.storedExplorerPortraits=[];this.loadInventory();this.initUserData(this.main.iomp.userSecureData);delete this.main.iomp.userSecureData};ma.prototype.handleMedalsChange=function(a){var b=a.medalsChange;a.oninit||(this.userSecure.medals=
null!=this.userSecure.medals?this.userSecure.medals+b:b);if(0<b&&"purchase"!==a.type&&(this.main.achievementBox.queueMedals(a),"reward"===a.type))switch(a.sourceData){case eb.worldClaim:this.main.achievements.unlockIOAchievement("ach-claim-region");break;case eb.foundPyramid:this.main.achievements.unlockIOAchievement("ach-find-pyramid");break;case eb.foundHub:this.main.achievements.unlockIOAchievement("ach-claim-hub")}};ma.prototype.handleItemAdded=function(a){var b=a.item;if(null!=b)return null==
this.userSecure&&(this.userSecure={}),null==(a=this.userSecure).items&&(a.items=[]),this.userSecure.items.push(b)};ma.prototype.handleItemRemoved=function(a){var b=a.item;if(null!=b)return null==this.userSecure&&(this.userSecure={}),null==(a=this.userSecure).items&&(a.items=[]),a=this.userSecure.items.indexOf(b),this.userSecure.items.splice(a,1)};ma.prototype.handleAlphaKeyGiven=function(a){null==this.userSecure&&(this.userSecure={});this.userSecure.alphaKey=a.alphaKey;return this.main.achievementBox.queueAlphaKey(a.alphaKey)};
ma.prototype.canGivePack=function(a){return null!=this.packs[a]&&this.packs[a]>=config.maximumPackCount||this.isPackHeld(a)?!1:!0};ma.prototype.isItemOwned=function(a){var b;return null==this.userSecure?!1:(null!=(b=this.userSecure.items)?b:[]).includes(a)};ma.prototype.isPackHeld=function(a){return this.isItemOwned(a)};ma.prototype.isPackInInventory=function(a){return this.isPackHeld(a)||0<this.packs[a]};ma.prototype.giveAllPacks=function(){var a;if(debug.isDevMode){var b=config.packs;var c=[];for(a in b)c.push(this.addPack(a,
!1));return c}};ma.prototype.initUserData=function(a){var b,c;if(this.userSecure=null!=a?a:{})for(a=null!=(b=this.userSecure.items)?b:[],b=0,c=a.length;b<c;b++){var d=a[b];null!=this.packs[d]&&0!==this.packs[d]||this.addPack(d,!1)}};ma.prototype.getNumMedals=function(){var a;return null==this.userSecure?0:null!=(a=this.userSecure.medals)?a:0};ma.prototype.resetInventory=function(){var a=this;return $jscomp.asyncExecutePromiseGeneratorProgram(function(b){return 1==b.nextAddress?(a.main.user.set("ioData",
{}),b.yield(a.main.user.save(),2)):b.return(a.loadInventory())})};ma.prototype.loadInventory=function(){var a,b,c,d;var e=null!=this.main.user?null!=(a=this.main.user.get("ioData"))?a:{}:{};this.packs=null!=e.packs?jQuery.extend(!0,{},e.packs):{};this.packsLastUsed=null!=e.packsLastUsed?jQuery.extend(!0,{},e.packsLastUsed):{};this.packAddOrder=null!=e.packAddOrder?jQuery.extend(!0,[],e.packAddOrder):Object.keys(this.packs);var f=Object.keys(this.packs);a=0;for(c=f.length;a<c;a++){var g=f[a];var h=
t.getPack(g,!1);null==h&&delete this.packs[g]}this.packIcons={};for(k in this.packs)this.packIcons[k]=this.createPackIcon(k),this.packAddOrder.includes(k)||this.packAddOrder.push(k);a=this.packs;for(b in a){var k=a[b];k>config.maximumPackCount&&(this.packs[b]=config.maximumPackCount)}r.info("IOInventory;Loaded IO inventory: "+Object.keys(this.packs).length+" packs");this.storedExplorers=null!=(d=e.storedExplorers)?d:[];e=b=0;for(d=this.storedExplorers.length;0<=d?b<d:b>d;e=0<=d?++b:--b)this.cacheStoredExplorerPortrait(e)};
ma.prototype.saveInventory=function(){var a={packs:this.packs,packAddOrder:this.packAddOrder,storedExplorers:this.storedExplorers,packsLastUsed:this.packsLastUsed};null!=this.main.user&&(JSON.stringify(a),this.main.user.set("ioData",a),this.invDirty=!0)};ma.prototype.flushInvData=function(){if(this.invDirty)return this.invDirty=!1,zb.saveUser()};ma.prototype.cacheStoredExplorerPortrait=function(a){var b=this.getStoredExplorer(a);if(null!=b){var c=new Fa(this.main,config.io.explorerID,b.explorerGender);
var d=new Ta(this.main.r,this.main.r.sfx,this.main);c.initCharGen(b.explorerTribe,b.explorerSeed);c.updateSprite(d);return this.storedExplorerPortraits[a]=c.portrait}};ma.prototype.setStoredExplorer=function(a,b){if(null!=a)return this.storedExplorers[b]={gender:a.explorerGender,tribe:a.explorerTribe,seed:a.explorerSeed},this.saveInventory(),this.cacheStoredExplorerPortrait(b)};ma.prototype.getStoredExplorer=function(a){var b;var c=this.storedExplorers[a];return null==c?null:{explorerGender:c.gender,
explorerTribe:c.tribe,explorerSeed:c.seed,portrait:null!=(b=this.storedExplorerPortraits[a])?b:[]}};ma.prototype.getAllStoredExplorers=function(){var a,b;var c=[];var d=a=0;for(b=config.io.storedExplorerSlotCost.length;0<=b?a<=b:a>=b;d=0<=b?++a:--a)this.hasExplorerSlotUnlocked(d)&&(d=this.getStoredExplorer(d),null!=d&&c.push(d));return c};ma.prototype.hasExplorerSlotUnlocked=function(a){return 0>a||0>=config.io.storedExplorerSlotCost[a]||this.isItemOwned("explorerSlot_"+a)};ma.prototype.createPackIcon=
function(a){var b;var c=[];var d=t.getPack(a);if(null==d)return null;if(null!=d.icon){var e=this.r.img.getSprite(d.icon);if(null!=e)return e.img.getContext("2d")}for(b in d.items)e=t.getItem(b),n.assert(null!=e),null!=e.sprite&&c.push(e.sprite);var f=t.arrify(d.statuses);e=0;for(b=f.length;e<b;e++){var g=f[e];g=t.getStatus(g);n.assert(null!=g);null!=g.sprite&&c.push(g.sprite)}f=t.arrify(d.characters);e=0;for(b=f.length;e<b;e++){g=f[e];var h=null!=g.variations&&0<g.variations.length?g.variations[0].gender:
"male";g=new Fa(this.main,g,h);if(null==g.portraitSmall){if("undefined"===typeof k||null===k){var k=new Ta(this.main.r,this.main.r.sfx,this.main);k.setup("tg-jungle");k.genColorTable();k.genKeyTable()}g.updateSprite(k)}null!=g.portraitSmall&&c.push(g.portraitSmall)}k=this.r.createCanvas(config.packImageSize[0],config.packImageSize[1]);this.r.setImageSmoothing(!1,k);0===c.length&&r.warn("No sprites found for pack: "+d.id);d=b=0;for(f=c.length;b<f;d=++b)g=c[d],e=Object.isString(g)?this.r.img.getSprite(g):
g,null==e?r.warn("No sprite found for pack icon: "+g+" for pack "+a):(h=g=0,1<c.length&&(g=.25*-Math.cos(d/c.length*2*Math.PI)*config.packImageSize[0],h=.25*Math.sin(d/c.length*2*Math.PI)*config.packImageSize[1]),g+=config.packImageSize[0]/2,h+=config.packImageSize[1]/2,this.r.drawSprite(e,g,h,{ctx:k,halign:"center",valign:"center",scale:1/this.s}));return k};ma.prototype.addPack=function(a,b){b=void 0===b?!0:b;var c,d;if(t.getPack(a,!1)){if(null==(c=this.packs)[a]&&(c[a]=0),this.packs[a]+=1,this.packIcons[a]||
(this.packIcons[a]=this.createPackIcon(a)),c=this.packAddOrder.indexOf(a),null!=c&&0<=c&&this.packAddOrder.splice(c,1),this.packAddOrder.unshift(a),this.saveInventory(),r.log("IOInventory;Pack added: '"+a+"'"),b&&this.main.achievementBox.queuePack(a,7),null!=this.main.party)return null==(d=this.main.party.stats).givenPacks&&(d.givenPacks=[]),this.main.party.stats.givenPacks.push(a)}else r.error("IOInventory;Pack not found '"+a+"'")};ma.prototype.getPackTitle=function(a){var b,c,d;n.assert(null!=a);
if(null==a)return"";var e=t.getPack(a);if(null!=e&&null!=e.name)return q.toText(e.name);var f=t.arrify(e.characters);if(0<f.length){a=t.getCharacter(f[0]);var g=null!=a.variations&&0<a.variations.length?a.variations[0].gender:"male";return q.toText("txt-pack-automatic").replace("$item",q.parse(a.title,g))}f=t.arrify(e.statuses);if(0<f.length)return a=t.getStatus(f[0]),q.toText("txt-pack-automatic").replace("$item",q.parse(a.title,null!=(g=null!=(b=this.main.party)?null!=(c=b.getExplorer())?c.gender:
void 0:void 0)?g:"male"));g=Object.keys(null!=(d=e.items)?d:{});return 0<g.length?(a=t.getItem(g[0]),q.toText("txt-pack-automatic").replace("$item",q.parse(a.name))):a};ma.prototype.drawPack=function(a,b,c,d,e,f,g,h){g=void 0===g?1:g;h=void 0===h?!0:h;n.assert(null!=a);var k=t.getPack(a);if(null!=k){f=b;switch(k.value){case 0:var l="hud_io_crate_bg_rank1.png";break;case 1:l="hud_io_crate_bg_rank1.png";break;case 2:l="hud_io_crate_bg_rank2.png";break;case 3:l="hud_io_crate_bg_rank3.png";break;case 4:l=
"hud_io_crate_bg_rank4.png"}l=this.r.img.getSprite(l);this.r.drawSprite(l,b,c);this.packIcons[a]||(this.packIcons[a]=this.createPackIcon(a));var m=this.packIcons[a];null!=m&&(b=f+l.dSize.w/2-m.canvas.width*this.s/2,null!=m&&this.r.ctx.drawImage(m.canvas,0,0,m.canvas.width,m.canvas.height,b,c,m.canvas.width*this.s,m.canvas.height*this.s));b=f+l.dSize.x-3*this.s;m=c+l.dSize.y-1*this.s;h&&(this.main.ioNewGame.isSelectingHoldCrate||this.main.gameOver)?this.isPackHeld(a)||0===k.value?(this.r.ctx.fillStyle=
"black",this.r.ctx.globalAlpha=.5,this.r.ctx.fillRect(f,c,l.dSize.w,l.dSize.h),this.r.ctx.globalAlpha=1):(m-=4*this.s,b-=2*this.s,a=this.r.img.getSprite("hud_medal.png"),this.r.drawSprite(a,b,m,{halign:"center",valign:"center",scale:.5}),a=config.io.packCosts[k.value],this.r.drawText(a,b+.5*this.s,m+2*this.s,{font:config.fonts.technicalSmall,halign:"center",fillColor:"black",shadowColor:"white"})):h&&this.isPackHeld(a)?this.r.drawSprite("hud_io_medal_hold.png",f+l.dSize.w/2,c,{halign:"center",valign:"top",
scale:.5}):1<g&&(a=g.toString(),this.r.drawText(a,b,m,{font:config.fonts.technicalSmall,halign:"right"}));return this.r.hitBox(f,c,l.dSize.w,l.dSize.h,null!=d?d:-1,null!=e?e:-1)}};var Ud=ma;var ca=function(a,b,c){var d=this;c=void 0===c?0:c;this.reset=this.reset.bind(this);this.getDebugInfo=this.getDebugInfo.bind(this);this.startNewGame=this.startNewGame.bind(this);this.addClaimScore=this.addClaimScore.bind(this);this.receiveClaimInfo=this.receiveClaimInfo.bind(this);this.getExploredStat=this.getExploredStat.bind(this);
this.generateBiomesIO=this.generateBiomesIO.bind(this);this.getPyramidDirText=this.getPyramidDirText.bind(this);this.getPyramidDirText_biome=this.getPyramidDirText_biome.bind(this);this.setupGoal=this.setupGoal.bind(this);this.createRivers=this.createRivers.bind(this);this.getNumBlockingBiomesInRiverPath=this.getNumBlockingBiomesInRiverPath.bind(this);this.addRiverPath=this.addRiverPath.bind(this);this.addOptionToSetIfNotBackwards=this.addOptionToSetIfNotBackwards.bind(this);this.buildRiverPath=this.buildRiverPath.bind(this);
this.getNumRivers=this.getNumRivers.bind(this);this.createRiverPoints=this.createRiverPoints.bind(this);this.addRiverToBiome=this.addRiverToBiome.bind(this);this.gatherUnlockedHubs=this.gatherUnlockedHubs.bind(this);this.handleHubUnlock=this.handleHubUnlock.bind(this);this.getDefaultPlayerHub=this.getDefaultPlayerHub.bind(this);this.unlockInitialHub=this.unlockInitialHub.bind(this);this.addBiomeToSegmentList=this.addBiomeToSegmentList.bind(this);this.createSegments=this.createSegments.bind(this);
this.expandSegmentsIntoBlockingBiomes=this.expandSegmentsIntoBlockingBiomes.bind(this);this.generatePerlinMap=this.generatePerlinMap.bind(this);this.generateBiomeDict=this.generateBiomeDict.bind(this);this.getBiomeDisplayTextX=this.getBiomeDisplayTextX.bind(this);this.getBiomeDisplayTextY=this.getBiomeDisplayTextY.bind(this);this.generateBiomeLocations=this.generateBiomeLocations.bind(this);this.shouldGenerateOnScreenBiome=this.shouldGenerateOnScreenBiome.bind(this);this.getBiomeTribeGen=this.getBiomeTribeGen.bind(this);
this.findBadCave=this.findBadCave.bind(this);this.isValidPlayerStartTile=this.isValidPlayerStartTile.bind(this);this.choosePlayerStartBiome=this.choosePlayerStartBiome.bind(this);this.choosePlayerStartPos=this.choosePlayerStartPos.bind(this);this.getNextHubPos=this.getNextHubPos.bind(this);this.markBiomeCtxDirty=this.markBiomeCtxDirty.bind(this);this.tickGeneration=this.tickGeneration.bind(this);this.tick=this.tick.bind(this);this.randBorderBiome=this.randBorderBiome.bind(this);this.createLocationBuildList=
this.createLocationBuildList.bind(this);this.getLocationBuildList=this.getLocationBuildList.bind(this);this.getBiomeBuildList=this.getBiomeBuildList.bind(this);this.randGroupBuildListIO=this.randGroupBuildListIO.bind(this);this.checkAllReqsIO=this.checkAllReqsIO.bind(this);this.main=a;this.unlockedHubs=[];debug.debugIOGen&&this.main.addDebugWatch(function(){return d.getDebugInfo()});this.reset(b,c);this.main.iomp.initLiveQuery(this.receiveClaimInfo)};ca.prototype.reset=function(a,b){b=void 0===b?
0:b;var c;if(this.worldProto===a&&this.worldSeed===b){this.world=new S(this.main,a.id,null,null,b);this.world.generated=!0;this.worldGenQueue=[];this.maxWorldGenQueue=0;var d=this.biomes;for(c in d){var e=d[c];null!=e.sgData&&delete e.sgData;null!=e.biome&&delete e.biome}r.info("IO;Resetting IO world from "+a.id+" size "+this.world.biomeCount.x+" "+this.world.biomeCount.y+" with seed "+b)}else this.worldProto=a,n.assert(null!=this.worldProto),this.worldSeed=b,this.world=new S(this.main,a.id,null,
null,b),this.world.generated=!0,r.info("IO;Initializing IO world from "+a.id+" size "+this.world.biomeCount.x+" "+this.world.biomeCount.y+" with seed "+b),this.biomeBuildLists={},this.locationBuildLists={},this.claimedBiomes=0,this.biomes={},this.claimsByUser={},this.claimScoresByUser={},this.topClaimScores=[],this.worldGenQueue=[],this.maxWorldGenQueue=0,this.generateBiomesIO(),this.claimCtxDirty=!0,this.main.iomp.requestClaimInfo(this.receiveClaimInfo)};ca.prototype.getDebugInfo=function(){var a=
[];a.push("io biomes: "+Object.keys(this.biomes).length);a.push("world biomes: "+this.world.getBiomes().length);a.push("generated biomes: "+this.world.getBiomes().map(function(a){return a.generated?1:0}).sum());a.push("gen queue: "+this.worldGenQueue.length);return a};ca.prototype.startNewGame=function(a){this.world.biomes={};this.worldGenQueue=[];this.startBiomeIdx=void 0===a?0:a;return null!=debug.startBiome?(this.playerStartBiome=new u(debug.startBiome),this.generateBiome(this.playerStartBiome)):
this.choosePlayerStartBiome()};ca.prototype.addClaimScore=function(a,b){var c=this,d,e,f,g,h;var k=this.topClaimScores[0];var l=a.user;null==(d=this.claimsByUser)[g=l.userID]&&(d[g]={claimsPerExplorer:{}});d=""+a.record.explorerTribe+a.record.explorerSeed+a.record.explorerGender;null==(e=this.claimsByUser[l.userID].claimsPerExplorer)[d]&&(e[d]={score:0,explorer:a.record});this.claimsByUser[l.userID].claimsPerExplorer[d].score+=1;null==(f=this.claimScoresByUser)[h=l.userID]&&(f[h]={points:0,displayname:l.displayName,
goalCount:l.goalCount,userID:l.userID});this.claimScoresByUser[l.userID].points+=1;a=Object.values(this.claimsByUser[l.userID].claimsPerExplorer).max(function(a){return a.score}).explorer;this.claimScoresByUser[l.userID].explorer=a;this.topClaimScores=Object.values(this.claimScoresByUser).sortBy(function(a){return a.points},!0);var m=this.topClaimScores[0];if(b&&null!=k&&null!=m&&k.userID!==m.userID&&m.points>k.points)return this.main.iomp.getUser(m.userID,function(a){a=q.parse("txt-io-livelog-newTopClaims").replace("$user",
a.displayName).replace("$claims",m.points.toString());return c.main.iomp.addNotification(a)})};ca.prototype.receiveClaimInfo=function(a,b,c){c=void 0===c?!1:c;var d;if(null!=b&&(a=this.biomes[a],null!=a&&null==a.claim)){var e=b.user;if(null!=e){n.assert(null!=e.displayName);a.claim=b;var f=this.world.getBiome(a.pos,!1);null!=f&&f.setClaim(b,this.world);this.addClaimScore(b,c);this.claimedBiomes+=1;f=[new u(1,0),new u(-1,0),new u(0,1),new u(0,-1),new u(1,1),new u(-1,-1),new u(-1,1),new u(1,-1)];b=
{user:"dummy",record:{claimDate:b.record.claimDate}};var g=0;for(d=f.length;g<d;g++){var h=f[g];h=a.pos.add(h);h=this.getBiomeDict(h,!1);null!=h&&h.isBorder&&null==h.claim&&(h.claim=b,h=this.world.getBiome(h.pos,!1),null!=h&&h.setClaim(b,this.world),this.claimedBiomes+=1)}this.claimCtxDirty=!0;e.userID!==this.main.user.id&&c&&(c=this.worldSegmentList[a.worldSegment],c=q.toText("txt-io-livelog-claim").replace("$segment",c.name).replace("$user",e.displayName).replace("$xCoord",this.getBiomeDisplayTextX(a.pos.x)).replace("$yCoord",
this.getBiomeDisplayTextY(a.pos.y)),this.main.iomp.addNotification(c))}}};ca.prototype.getExploredStat=function(){return this.claimedBiomes/(this.world.biomeCount.x*this.world.biomeCount.y)};ca.prototype.generateBiomesIO=function(){var a,b,c,d;r.info("IO;Generating world perlin");this.generatePerlinMap();r.info("IO;Generating biome dict");this.difficultyLvls=[];var e=a=0;for(c=this.world.biomeCount.w;0<=c?a<c:a>c;e=0<=c?++a:--a){var f=b=0;for(d=this.world.biomeCount.h;0<=d?b<d:b>d;f=0<=d?++b:--b)f=
this.getBiomeDict(new u(e,f)),this.difficultyLvls.includes(f.worldLvl)||this.difficultyLvls.push(f.worldLvl)}this.difficultyLvls.sort();r.info("IO;Generating world segments");this.createSegments();r.info("IO;Generating rivers");this.createRivers();r.info("IO;Initial Hub");this.unlockInitialHub();r.info("IO;Generating goal");this.setupGoal();r.info("IO;Generating locations");this.generateBiomeLocations();r.info("IO;Gathering unlocked hubs");this.gatherUnlockedHubs();r.info("IO;IO gen finished")};ca.prototype.getPyramidDirText=
function(a){a=this.world.getBiomeIdx(this.world.toBiomePos(a));return this.getPyramidDirText_biome(a)};ca.prototype.getPyramidDirText_biome=function(a){a=this.biomes[this.goalBiomeID].pos.sub(this.biomes[a].pos).normal();var b=Math.round(4*Math.atan2(-a.y,a.x)/(2*Math.PI)+4)%4;return function(){switch(b){case 0:return"txt-compass-e";case 1:return"txt-compass-n";case 2:return"txt-compass-w";case 3:return"txt-compass-s"}}()};ca.prototype.setupGoal=function(){var a=this,b,c;n.assert(0<this.hubBiomes.length);
n.assert(0<this.hubBiomes.length&&0<this.difficultyLvls.length);var d=this.biomes[this.unlockedHubs[0]].pos;var e=Object.keys(this.biomes).filter(function(b){var c,e,f,g,h,k;b=a.biomes[b];if(b.isBorder||b.worldLvl!==a.difficultyLvls.last()||d.sub(b.pos).length()<config.io.minGoalStartDist||Math.min(Math.min(b.pos.x,a.world.biomeCount.x-b.pos.x-1),Math.min(b.pos.y,a.world.biomeCount.y-b.pos.y-1))<config.io.minGoalEdgeDist)return!1;var l=c=f=b.pos.x-1;for(g=b.pos.x+1;f<=g?c<=g:c>=g;l=f<=g?++c:--c){var n=
e=h=b.pos.y-1;for(k=b.pos.y+1;h<=k?e<=k:e>=k;n=h<=k?++e:--e)if(n=a.getBiomeDict(new u(l,n),!1),null==n||!n.isBorder&&n.worldLvl!==b.worldLvl)return!1}return!0});0===e.length&&(e=Object.keys(this.biomes).filter(function(b){b=a.biomes[b];return b.isBorder||d.sub(b.pos).length()<config.io.minGoalStartDist?!1:b.worldLvl===a.difficultyLvls.last()}));n.assert(0<e.length);var f={};var g=b=0;for(c=e.length;g<c;g++){var h=e[g];var k=this.hubBiomes.min(function(b){return a.biomes[b].pos.sub(a.biomes[h].pos).length()});
k=this.biomes[k].pos.sub(this.biomes[h].pos).length();null==f[k]&&(f[k]=[]);f[k].push(h);b=Math.max(b,k)}h=f[b].worldGenSample();h=this.biomes[h];e=this.createLocationBuildList(t.getGroup(config.io.goalLocationGroup).group,t.getBiome(h.biomeID),h.worldLvl);n.assert(null!=e&&0<e.length);null==h.locations&&(h.locations=[]);h.locations.unshift(e.worldGenSample().worldGenSample());this.goalBiomeID=h.biomeIdx;d.sub(h.pos).length();g=h.worldSegment;f=[];k=this.worldSegmentList;c=0;for(e=k.length;c<e;c++)b=
k[c],b.value===this.difficultyLvls.last()&&b.id!==g&&(b=b.biomes.filter(function(b){return a.biomes[b].isBorder?!1:!0}),1>=b.length||(b=this.biomes[b.worldGenSample()],f.push(b)));f=f.worldGenRandomize();b=Math.max(0,f.length-config.io.maxSeals);0<b&&f.splice(config.io.maxSeals,b);g=0;for(c=f.length;g<c;g++)b=f[g],e=this.createLocationBuildList(t.getGroup(config.io.sealLocationGroup).group,t.getBiome(b.biomeID),b.worldLvl),n.assert(null!=e&&0<e.length),b.locations.unshift(e.worldGenSample().worldGenSample())};
ca.prototype.createRivers=function(){var a=this,b,c,d,e,f,g,h,k,l,m;var p={};var q=this.hubBiomes;var r=0;for(f=q.length;r<f;r++){var t=q[r];var v=this.biomes[t];null==p[t]&&(p[t]=[]);var u=v.pos;for(b=this.difficultyLvls.indexOf(v.worldLvl);p[t].length<config.io.maxRiversPerHub;){v=this.hubBiomes.filter(function(c){if(c===t||p[t].includes(c)||null!=p[c]&&(p[c].length>=config.io.maxRiversPerHub||p[c].includes(t)))return!1;c=a.biomes[c];var d=a.difficultyLvls.indexOf(c.worldLvl);return 1<Math.abs(d-
b)?!1:c.pos.sub(u).length()<=config.io.maxDistanceBetweenConnectedHubs});0===v.length&&0===p[t].length&&(v=this.hubBiomes.filter(function(b){return b===t||p[t].includes(b)||null!=p[b]&&p[b].includes(t)?!1:a.biomes[b].pos.sub(u).length()<=config.io.maxDistanceBetweenConnectedHubs}));if(0===v.length)break;v=v.min(function(b){return a.biomes[b].pos.sub(u).length()});n.assert(!p[t].includes(v));n.assert(null==p[v]||!p[v].includes(t));p[t].push(v);null==p[v]&&(p[v]=[]);p[v].push(t)}}for(d in p)for(v=p[d],
r=0,f=v.length;r<f;r++){q=v[r];var x=p[q];x.splice(x.indexOf(d),1);var A=c=1E4;var z=0;var C=-1;x=null;for(e=l=0;100>e;++e){var B=this.buildRiverPath(d,q);if(null!=B){var E=this.getNumBlockingBiomesInRiverPath(B);E<c?(c=E,x=B,A=B.length):E===c&&B.length<A&&(A=B.length,x=B);if(E===c&&A===B.length){var F=k=0;for(g=B.length;F<g;F++){var J=B[F];var I=this.getBiomeDict(J.currPos);var K=null!=(m=I.rivers)?m:[];var L=0;for(h=K.length;L<h;L++)if(I=K[L],I.from===J.fromType&&I.to===J.toType||I.to===J.fromType&&
I.from===J.toType)k+=1}k>z&&(z=k,x=B)}E>C&&(C=E);0===c&&(l+=1);if(15===l)break}}n.assert(null!=x);this.addRiverPath(d,q,x)}};ca.prototype.getNumBlockingBiomesInRiverPath=function(a){var b,c;var d=c=0;for(b=a.length;d<b;d++){var e=a[d];this.getBiomeDict(e.currPos).isBorder&&(c+=1)}return c};ca.prototype.addRiverPath=function(a,b,c){var d;a=[parseInt(a),b];b=0;for(d=c.length;b<d;b++){var e=c[b];e=this.addRiverToBiome(e.currPos,e.fromType,e.toType,a);if(!e)break}};ca.prototype.addOptionToSetIfNotBackwards=
function(a,b,c,d){var e;if(b.from!==b.to){var f=a.add(new u(b.x,b.y));if(this.getBiomeDict(f,!1)){a=0;for(e=c.length;a<e;a++){var g=c[a];if(f.eq(g.currPos))return}return d.push(b)}}};ca.prototype.buildRiverPath=function(a,b){var c=this,d,e,f;a=this.biomes[a].pos;b=this.biomes[b].pos;var g=u.fromObj(a);var h="hub";for(a=[];!g.eq(b);){var k=b.sub(g);var l=0===k.x?0:0>k.x?-1:0<k.x?1:void 0;var m=0===k.y?0:0>k.y?-1:0<k.y?1:void 0;k=[];1===l?this.addOptionToSetIfNotBackwards(g,{from:h,to:"right",x:1,y:0},
a,k):-1===l&&this.addOptionToSetIfNotBackwards(g,{from:h,to:"left",x:-1,y:0},a,k);-1===m?this.addOptionToSetIfNotBackwards(g,{from:h,to:"top",y:-1,x:0},a,k):1===m&&this.addOptionToSetIfNotBackwards(g,{from:h,to:"bottom",y:1,x:0},a,k);if(0===k.length||1===k.length&&.2>ba.rng.random())0===l?(this.addOptionToSetIfNotBackwards(g,{from:h,to:"right",x:1,y:0},a,k),this.addOptionToSetIfNotBackwards(g,{from:h,to:"left",x:-1,y:0},a,k)):(this.addOptionToSetIfNotBackwards(g,{from:h,to:"top",y:-1,x:0},a,k),this.addOptionToSetIfNotBackwards(g,
{from:h,to:"bottom",y:1,x:0},a,k));if(0===k.length)return null;var p=null;if(1<k.length){if(.9>ba.rng.random())for(l=this.getBiomeDict(g),m=0,d=k.length;m<d;m++){var q=k[m];var r=null!=(f=l.rivers)?f:[];var t=0;for(e=r.length;t<e;t++)if(h=r[t],h.from===q.from&&h.to===q.to||h.to===q.from&&h.from===q.to){var v=(new u(q.x,q.y)).add(g);var y=this.getBiomeDict(v);if(null!=y&&!y.isBorder){p=q;break}}if(null!=p)break}null==p&&(l=k.filter(function(a){v=(new u(a.x,a.y)).add(g);y=c.getBiomeDict(v);return null!=
y&&!y.isBorder}),0<l.length&&(k=l),p=k.worldGenSample())}else p=k[0];n.assert(null!=p);a.push({currPos:u.fromObj(g),fromType:p.from,toType:p.to});h=function(){switch(p.to){case "right":return"left";case "left":return"right";case "top":return"bottom";case "bottom":return"top"}}();g.x+=p.x;g.y+=p.y}a.push({currPos:g,fromType:h,toType:"hub"});return a};ca.prototype.getNumRivers=function(){var a;var b=0;var c=this.biomes;for(a in c){var d=c[a];null!=d.rivers&&(b+=d.rivers.length)}return b};ca.prototype.createRiverPoints=
function(a){var b=this.getBiomeDict(a);null==b.riverPoints&&(a=new u(a.x*config.board.biomeSize[0],a.y*config.board.biomeSize[1]),b.riverPoints={left:(new u(0,ba.rng.randInt(0,config.board.biomeSize[1]-1))).add(a),top:(new u(ba.rng.randInt(0,config.board.biomeSize[0]-1),0)).add(a)})};ca.prototype.addRiverToBiome=function(a,b,c,d){var e;var f=this.getBiomeDict(a);null==f.rivers&&(f.rivers=[],this.createRiverPoints(a),this.createRiverPoints(a.add(new u(1,0))),this.createRiverPoints(a.add(new u(0,1))));
null!=d&&(null==f.riverConnections&&(f.riverConnections=[]),f.riverConnections.includes(d[0])||f.riverConnections.push(d[0]));var g=f.rivers;var h=0;for(e=g.length;h<e;h++)if(a=g[h],a.from===b&&a.to===c||a.to===b&&a.from===c)return null!=d&&f.riverConnections.includes(d[1])?!1:!0;f.rivers.push({from:b,to:c});null!=d&&f.riverConnections.push(d[1]);return!0};ca.prototype.gatherUnlockedHubs=function(){var a=this;this.main.iomp.requestHubInfo(function(b){var c;var d=[];var e=0;for(c=b.length;e<c;e++){var f=
b[e];d.push(a.handleHubUnlock(f.biomeID,f.userID,f.unlockDate,!1))}return d})};ca.prototype.handleHubUnlock=function(a,b,c,d){var e=this;d=void 0===d?!0:d;this.hubBiomes.includes(a)&&(this.unlockedHubs.includes(a)||this.unlockedHubs.push(a),null==this.unlockedHubDates&&(this.unlockedHubDates={}),this.unlockedHubDates[a]=c,this.main.iomp.getUser(b,function(b){var c,f,k,l;var m=e.main.worldGenIO.biomes[a];if(null!=b&&null!=m){m=e.main.worldGenIO.worldSegmentList[m.worldSegment];ba.rng=new pa(m.seed);
var n=b.displayName;n=q.createName(config.io.worldNameGenUnlockedHub).replace("\u00a3name",n);var r=m.name;m.name=n;d&&(b=q.parse("txt-io-livelog-unlockedOutpost").replace("$user",b.displayName).replace("$newname",m.name).replace("$oldname",r),e.main.iomp.addNotification(b));null!=(f=e.main.exped)&&f.changeCompassScore();null!=(null!=(k=e.main.party)?k.pos:void 0)&&(f=null!=(c=e.world.getTile(e.main.party.pos))?null!=(l=c.biome)?l.pos:void 0:void 0,null!=f&&(c=e.world.getBiomeIdx(f),c=e.main.worldGenIO.biomes[c],
(null!=c?c.worldSegment:void 0)===m.id&&e.main.exped.displayNewSegment(m.id)))}}))};ca.prototype.getDefaultPlayerHub=function(){var a=this;var b=this.main.worldGenIO.unlockedHubs.filter(function(b){if(a.main.worldGenIO.biomes[b].worldLvl===a.main.worldGenIO.difficultyLvls[0])return!0});n.assert(0<b.length);var c=function(b,c){c=void 0===c?1:c;var d,e,f,l,m,p;n.assert(null!=b);var q=0;var r=d=f=b.pos.x-c;for(l=b.pos.x+c;f<=l?d<=l:d>=l;r=f<=l?++d:--d){var t=e=m=b.pos.y-c;for(p=b.pos.y+c;m<=p?e<=p:e>=
p;t=m<=p?++e:--e)t=a.getBiomeDict(new u(r,t),!1),null==t||null!=t.claim||t.isBorder||(q+=1)}return q};b.sort(function(b,d){b=a.main.worldGenIO.biomes[b];d=a.main.worldGenIO.biomes[d];var e=c(b);var f=c(d);e===f&&(e=c(b,2),f=c(d,2));return e===f?0:e<f?1:-1});var d=Math.ceil(.1*b.length);b.splice(d,Math.max(0,b.length-d));return b.sample()};ca.prototype.unlockInitialHub=function(){var a=this;n.assert(0<this.hubBiomes.length);this.unlockedHubs=[];n.assert(0<this.hubBiomes.length&&0<this.difficultyLvls.length);
var b=this.hubBiomes.filter(function(b){b=a.biomes[b];if(b.isBorder||b.worldLvl!==a.difficultyLvls[0])return!1;b=Math.min(Math.min(b.pos.x,a.world.biomeCount.x-b.pos.x-1),Math.min(b.pos.y,a.world.biomeCount.y-b.pos.y-1));return b<config.io.minHubEdgeDist||b>config.io.maxHubEdgeDist?!1:!0});if(0===b.length)b=this.hubBiomes.filter(function(b){return a.biomes[b].worldLvl===a.difficultyLvls[0]});else{var c=b.filter(function(b){var c,d,e,k,l,m;b=a.biomes[b];var n=c=e=b.pos.x-1;for(k=b.pos.x+1;e<=k?c<=
k:c>=k;n=e<=k?++c:--c){var q=d=l=b.pos.y-1;for(m=b.pos.y+1;l<=m?d<=m:d>=m;q=l<=m?++d:--d)if(q=a.getBiomeDict(new u(n,q),!1),null==q||q.isBorder||q.worldLvl!==b.worldLvl)return!1}return!0});0<c.length&&(b=c)}n.assert(0<b.length);b.sort(function(b,c){return a.worldSegmentList[a.biomes[c].worldSegment].biomes.length>a.worldSegmentList[a.biomes[b].worldSegment].biomes.length?1:-1});c=Math.round(.2*this.worldProto.hubsPerDifficulty[0]);b.splice(c,Math.max(0,b.length-c));var d=new u(this.world.biomeCount.x/
2,this.world.biomeCount.y/2);b.sort(function(b,c){b=a.biomes[b];c=a.biomes[c];b=b.pos.sub(d).length();c=c.pos.sub(d).length();return b!==c?c<b?1:-1:0});b=b[0];n.assert(null!=b);this.unlockedHubs.push(b)};ca.prototype.addBiomeToSegmentList=function(a,b,c,d){c=void 0===c?!0:c;d=void 0===d?-1:d;if(!(b.isBorder||c&&null!=b.worldSegment||!c&&null!=b.pckSegment)){if(-1===d){d=a.length;var e=c?b.worldLvl:b.pocketID;var f=this.worldSeed+1337*d;ba.rng=new pa(f);var g=q.createName(config.io.worldNameGen);a.push({biomes:[],
adj:[],lowestBiome:null,lowestPerlin:1,value:e,id:d,name:g,seed:f});n.assert(null!=a[d].name);n.assert(""!==a[d].name)}f=a[d];e=f.biomes;g=f.adj;c?b.worldSegment=d:b.pckSegment=d;e.push(b.biomeIdx);e=c?this.difficultyMap[b.biomeIdx]:this.perlinMap[b.biomeIdx];e<f.lowestPerlin&&(f.lowestPerlin=e,f.lowestBiome=b.biomeIdx);var h=[new u(1,0),new u(-1,0),new u(0,1),new u(0,-1),new u(1,1),new u(-1,-1)];f=0;for(e=h.length;f<e;f++){var k=h[f];var l=b.pos.add(k);k=this.getBiomeDict(l,!1);n.assert(k.pos.eq(l));
null==k||k.isBorder||((l=c?k.worldLvl===b.worldLvl:k.pocketID===b.pocketID)?this.addBiomeToSegmentList(a,k,c,d):g.includes(k.biomeIdx)||g.push(k.biomeIdx))}}};ca.prototype.createSegments=function(){var a=this,b,c,d,e,f,g,h,k;this.worldSegmentList=[];var l=this.biomes;for(q in l){var m=l[q];m.isBorder||this.addBiomeToSegmentList(this.worldSegmentList,m,!0)}m={};var p=this.worldSegmentList;var q=0;for(l=p.length;q<l;q++){var t=p[q];delete t.adj;m[t.value]||(m[t.value]=[]);m[t.value].push(t)}l=function(a,
b){return a.biomes.length>b.biomes.length?-1:a.biomes.length<b.biomes.length?1:a.id-b.id};var x=function(a,b){return a-b};this.hubBiomes=[];for(d in m){var v=m[d];v.sort(l);p=this.difficultyLvls.indexOf(parseInt(d));var y=Math.min(this.worldProto.hubsPerDifficulty[p],v.length);q=0;for(e=12;q<y&&3<e;){var z=0;for(c=v.length;z<c;z++)if(t=v[z],null==t.hubBiome){var A=function(b){var c,d,f,g,h,k;var l=c=f=b.x-e;for(g=b.x+e;f<=g?c<=g:c>=g;l=f<=g?++c:--c){var m=d=h=b.y-e;for(k=b.y+e;h<=k?d<=k:d>=k;m=h<=
k?++d:--d){m=new u(l,m);var n=m.geoDist(b);if(n<=e&&(m=a.world.getBiomeIdx(m),a.hubBiomes.includes(m)))return!0}}return!1};var B=t.biomes.filter(function(b){return!A(a.biomes[b].pos)});if(0!==B.length){var C={};var E={};var F=t.biomes;var J=0;for(b=F.length;J<b;J++){var I=F[J];var K=this.biomes[I].pos;null==C[f=K.x]&&(C[f]=0);null==E[g=K.y]&&(E[g]=0);C[K.x]+=1;E[K.y]+=1}var L=Object.keys(C).map(function(a){return parseInt(a)});L=L.sort(x);J=Math.floor(t.biomes.length/2);b=I=0;for(F=L.length;b<F;b++){var M=
L[b];I+=null!=(h=C[M])?h:0;if(I>=J)break}I=0;F=Object.keys(E).map(function(a){return parseInt(a)});F=F.sort(x);b=0;for(C=F.length;b<C;b++){var N=F[b];I+=null!=(k=E[N])?k:0;if(I>=J)break}E=function(b){var c,d,e,f,g,h,k;var l=a.world.getBiomeIdx(b);if(t.biomes.includes(l))return b;for(e=1;!t.biomes.includes(l)&&e<=a.world.biomeCount.x;){var m=c=f=b.x-e;for(g=b.x+e;f<=g?c<=g:c>=g;m=f<=g?++c:--c){var n=d=h=b.y-e;for(k=b.y+e;h<=k?d<=k:d>=k;n=h<=k?++d:--d)if(K=new u(m,n),l=a.world.getBiomeIdx(K),t.biomes.includes(l))return K}e+=
1}return null};var O=E(new u(M,N));if(null!=O&&(B=B.min(function(b){return a.biomes[b].pos.geoDist(O)}),n.assert(t.biomes.includes(B)),this.hubBiomes.push(B),t.hubBiome=B,q+=1,q===y))break}}--e}q!==y&&r.warn("Unable to allocate "+y+" segments for level "+p+": only allocated "+q)}for(M=!0;M;)M=this.expandSegmentsIntoBlockingBiomes();M=Object.values(this.biomes).filter(function(a){return null==a.worldSegment});n.assert(0===M.length)};ca.prototype.expandSegmentsIntoBlockingBiomes=function(){var a,b,
c;var d=!1;var e=Object.clone(this.worldSegmentList);e.sort(function(a,b){return a.biomes.length>b.biomes.length?-1:a.biomes.length<b.biomes.length?1:a.id-b.id});var f=0;for(a=e.length;f<a;f++){var g=e[f];var h=[];var k=g.biomes;var l=0;for(b=k.length;l<b;l++){var m=k[l];var n=[new u(1,0),new u(-1,0),new u(0,1),new u(0,-1),new u(1,1),new u(-1,-1)];var q=0;for(c=n.length;q<c;q++){var r=n[q];r=this.biomes[m].pos.add(r);r=this.getBiomeDict(r,!1);null!=r&&r.isBorder&&null==r.worldSegment&&r.worldSegment!==
g.id&&h.push(r.biomeIdx)}}l=0;for(q=h.length;l<q;l++)m=h[l],d=!0,r=this.biomes[m],g.biomes.push(m),r.worldSegment=g.id,r.worldLvl=g.value}return d};ca.prototype.generatePerlinMap=function(){var a=this;ba.rng=new pa(this.worldSeed);var b=new Perlin;b.octaves=config.io.biomeMap.octaves;b.persistence=config.io.biomeMap.persistence;b.frequency=config.io.biomeMap.frequency;this.perlinMap={};var c=function(b,c){return a.perlinMap[a.world.getBiomeIdx(new u(b))]=c};b.generate([0,0],this.world.getBiomeCount().lst(),
c);for(b=0;100>=b;++b)ba.rng.next();b=new Perlin;b.octaves=config.io.difficultyMap.octaves;b.persistence=config.io.difficultyMap.persistence;b.frequency=config.io.difficultyMap.frequency;this.difficultyMap={};c=function(b,c){return a.difficultyMap[a.world.getBiomeIdx(new u(b))]=c};b.generate([0,0],this.world.getBiomeCount().lst(),c)};ca.prototype.generateBiomeDict=function(a){var b;var c=this.world.getBiomeIdx(a);var d=ba.rng.next();var e=this.perlinMap[c];n.assert(null!=e);var f=this.worldProto.pockets.find(function(a){return e>
a.perlin});n.assert(null!=f);f=f.pocket;var g=t.getPocket(f);n.assert(null!=g);var h=this.difficultyMap[c];var k=this.worldProto.difficulty.find(function(a){return h>a.perlin}).world;var l="";var m=0===a.x||0===a.y||a.x===this.world.getBiomeCount().w-1||a.y===this.world.getBiomeCount().h-1;m||(m=ba.rng.random(),m=m<config.io.blockingBiomeChance);m?l=null!=(b=this.randBorderBiome(g.borderBiome))?b:"bio-outside-mountains":(l=this.getBiomeBuildList(f,k),l=l.shift(),n.assert(null!=l&&""!==l));b=t.getBiome(l);
n.assert(null!=b);m||(m=t.checkFlags("+blocking",b.flags));b=ba.rng.random()<config.io.specialBiomeBGChance;return{pos:a,biomeIdx:c,biomeSeed:d,pocketID:f,biomeID:l,isBorder:m,worldLvl:k,bgImgIdx:b?ba.rng.randInt(2,config.imgSize.biomeBgVariations-1):ba.rng.randInt(0,1),locations:[]}};ca.prototype.getBiomeDisplayTextX=function(a){a=a+1-this.world.biomeCount.w/2;if(0>=a){var b=q.toText("txt-io-ruler-west");a=Math.abs(a)+1}else b=q.toText("txt-io-ruler-east");return a+"\u00b0 "+b};ca.prototype.getBiomeDisplayTextY=
function(a){a=a+1-this.world.biomeCount.h/2;if(0>=a){var b=q.toText("txt-io-ruler-north");a=Math.abs(a)+1}else b=q.toText("txt-io-ruler-south");return a+"\u00b0 "+b};ca.prototype.generateBiomeLocations=function(){var a;var b=Object.keys(this.biomes).worldGenRandomize();var c=0;for(a=b.length;c<a;c++){var d=b[c];d=this.biomes[d];if(!d.isBorder){null==d.locations&&(d.locations=[]);this.hubBiomes.includes(d.biomeIdx)&&d.locations.push(config.io.hubLocationID);var e=t.getBiome(d.biomeID);null!=e.locations&&
0<e.locations.length&&(e=this.createLocationBuildList(e.locations,e,d.worldLvl),0<e.length&&d.locations.add(e[0]));e=this.getLocationBuildList(config.io.locationBuildList,d.biomeID,d.worldLvl);d.locations.add(e);d.locations.compact().worldGenRandomize()}}};ca.prototype.getBiomeDict=function(a,b){b=void 0===b?!0:b;var c;var d=this.world.getBiomeIdx(a);if(null==d||0>d)return null;var e=null!=(c=this.biomes[d])?c:null;null==e&&b&&(e=this.generateBiomeDict(a),this.biomes[d]=e);n.assert(null==e||e.pos.x===
a.x&&e.pos.y===a.y,"getBiome got wrong biome!");return e};ca.prototype.shouldGenerateOnScreenBiome=function(a){var b;a=this.getBiomeDict(a,!1);return null!=a&&(null!=a.claim||null!=(null!=(b=a.sgData)?b.knownTiles:void 0)||null!=a.sgData&&0<a.sgData.tiles.length)};ca.prototype.getBiomeTribeGen=function(a){var b;a=this.getBiomeDict(a);if(null==a.tribeGen){var c=t.getPocket(a.pocketID);var d=this.worldSegmentList[a.worldSegment];d=d.seed;a.tribeGen=new Ta(this.main.r,this.main.r.sfx,this.main);a.tribeGen.setup(null!=
(b=c.tribeGen)?b:"tg-jungle",d);a.tribeGen.genColorTable();a.tribeGen.genKeyTable()}return a.tribeGen};ca.prototype.findBadCave=function(){var a,b,c;var d=this.biomes;for(a in d){var e=d[a];if(e.locations.includes("loc-cave")){this.generateBiome(e.pos,!0);var f=this.world.getBiome(e.pos);var g=f.locations;f=0;for(b=g.length;f<b;f++){var h=g[f];if("loc-cave"===h.id){var k=this.world.getTilesInRadius(h.pos,1);h=!0;var l=0;for(c=k.length;l<c;l++){var m=k[l];if(!m.isBlocking()){h=!1;break}}if(h){r.info("Found at "+
e.pos.x+", "+e.pos.y);return}}}}}};ca.prototype.generateBiome=function(a,b){b=void 0===b?!1:b;n.assert(null!=this.world);var c=this.world.getBiome(a);if(null!=c){var d=this.worldGenQueue.find(function(a){return a.biomeToGenerate===c});if(null!=d&&b){for(;!d.created;)d.tickGen(0);return c}if(!c.generated&&null==d)if(a=this.getBiomeDict(a),n.assert(null!=a),d=new ba(this.main,null,a.pocketID,null,!1,a.biomeSeed),d.world=this.world,c.id=a.biomeID,c.worldLvl=a.worldLvl,c.blocking=a.isBorder,d.initForBiome(c,
a.isBorder),a.biome=c,logs.worldgen&&r.info("biome generation queued: "+c.pos.x+" "+c.pos.y+": "+c.id+" "+a.biomeIdx+" "+a.biomeSeed),b)for(;!d.created;)d.tickGen(0);else this.worldGenQueue.push(d),this.maxWorldGenQueue=Math.max(this.maxWorldGenQueue,this.worldGenQueue.length*d.maxBuildSteps);return c}};ca.prototype.isValidPlayerStartTile=function(a){var b,c;if(a.isBlocking()||null!=a.location)return!1;var d=config.board.biomeSafeSegment;d=new u(d,d);return a.biome!==(null!=(b=this.world.getTile(a.pos.add(d)))?
b.biome:void 0)||a.biome!==(null!=(c=this.world.getTile(a.pos.sub(d)))?c.biome:void 0)||2>=a.biome.locations.map(function(b){var c;return 0<(null!=(c=b.actions)?c.length:void 0)?b.pos.dist(a.pos):100}).min()?!1:!0};ca.prototype.choosePlayerStartBiome=function(){0>this.startBiomeIdx&&(this.startBiomeIdx=this.hubBiomes[0],n.assert(null!=this.startBiomeIdx&&0<=this.startBiomeIdx));this.playerStartBiome=this.biomes[this.startBiomeIdx].pos;return this.generateBiome(this.playerStartBiome)};ca.prototype.choosePlayerStartPos=
function(){var a;if(null!=this.world.startPos)return!0;var b=this.world.getBiome(this.playerStartBiome);n.assert(null!=b);var c=b.locations;var d=0;for(a=c.length;d<a;d++){var e=c[d];if(e.id===config.io.hubLocationID)return this.world.startPos=e.pos,this.main.saveGameOnStart=!0}d=b.tiles.filter(this.isValidPlayerStartTile).sample();if(null==d)return!1;n.assert(null!=d);this.world.startPos=d.pos;return this.main.saveGameOnStart=!0};ca.prototype.getNextHubPos=function(){var a=this,b,c,d;var e=null!=
(c=this.unlockedHubs)?c:[];if(null!=this.hubBiomes&&null!=(null!=(b=this.main.party)?b.pos:void 0)&&(c=this.hubBiomes.filter(function(a){return!e.includes(a)}),0!==c.length)){var f=this.world.toBiomePos(this.main.party.pos);c=c.min(function(b){return a.biomes[b].pos.sub(f).length()});n.assert(null!=this.biomes[c]);c=this.biomes[c].pos;b=this.world.getBiome(c,!1);if(null!=b&&b.generated){var g=b.locations;b=0;for(d=g.length;b<d;b++){var h=g[b];if(h.id===config.io.hubLocationID)return h.pos}}return new u((c.x+
.5)*config.board.biomeSize[0],(c.y+.5)*config.board.biomeSize[1])}};ca.prototype.markBiomeCtxDirty=function(a,b){a=this.world.getBiome(new u(a,b),!1);if(null!=a)return a.ctxDirty=!0,a.znCtxDirty=!0};ca.prototype.tickGeneration=function(a){if(0<this.worldGenQueue.length&&(null!=this.lastRNGSeed&&(ba.rng._seed=this.lastRNGSeed),this.isGenerating=!0,this.worldGenQueue[0].tickGen(a),this.isGenerating=!1,this.lastRNGSeed=ba.rng._seed,this.worldGenQueue[0].created))if(a=this.worldGenQueue.shift(),logs.worldgen&&
r.info("biome generation finished: "+a.biomeToGenerate.pos.x+" "+a.biomeToGenerate.pos.y+": "+a.biomeToGenerate.id),0===this.worldGenQueue.length?this.maxWorldGenQueue=0:(this.worldGenQueue[0].loadingTexts=a.loadingTexts,this.worldGenQueue[0].logDetail=a.logDetail,this.worldGenQueue[0].logTime=a.logTime),"loading"===this.main.getMainState()){if(0===this.worldGenQueue.length){var b=this.choosePlayerStartPos();if(!b)return this.choosePlayerStartBiome()}}else if(null!=(null!=(b=this.main.exped)?b.viewQueue:
void 0)&&0===this.main.exped.viewQueue.length)return this.main.exped.updateVisibility()};ca.prototype.tick=function(a){var b;if(!this.main.showingDiary()&&0<this.worldGenQueue.length){var c=0;for(b=config.io.worldGenIOBudgetMS;(c<b||debug.genInstant)&&0<this.worldGenQueue.length;){var d=Date.now();this.tickGeneration(a);d=Date.now()-d;c+=d}}};ca.prototype.randBorderBiome=function(a){var b,c,d;a=t.arrify(a);var e=a.sum(function(a){var b;return null!=(b=a.slots)?b:1});var f=ba.rng.random()*e;var g=
0;for(b=a.length;g<b;g++){var h=a[g];f-=null!=(c=h.slots)?c:1;if(0>=f||0===e)return null!=(d=h.ref)?d:h}return null};ca.prototype.createLocationBuildList=function(a,b,c){var d,e,f;var g=[];var h=t.arrify(a);a=0;for(e=h.length;a<e;a++){var k=h[a];g.push(this.randBuildListIO(k,b,c))}a=[];k=0;for(h=g.length;k<h;k++){e=g[k];var l=d=0;for(f=e.length;d<f;l=++d){var m=e[l];null!=m&&this.checkAllReqsIO(m,c)&&(null==a[l]&&(a[l]=[]),a[l].add(this.randBuildListIO(m,b,c)))}}b=[];c=0;for(g=a.length;c<g;c++)e=
a[c],e=e.compact(),0<e.length&&b.push(e);return b};ca.prototype.getLocationBuildList=function(a,b,c){null==this.locationBuildLists[b]&&(this.locationBuildLists[b]={});var d=this.locationBuildLists[b][c];if(null==d||0===d.length)d=t.getBiome(b),a=t.getGroup(a),d=this.createLocationBuildList(a.group,d,c),this.locationBuildLists[b][c]=d;return d.shift()};ca.prototype.getBiomeBuildList=function(a,b){var c;n.assert(null!=a);n.assert(null!=b);null==this.biomeBuildLists[a]&&(this.biomeBuildLists[a]={});
var d=this.biomeBuildLists[a][b];if(null==d||0===d.length){var e=t.getPocket(a);d=this.randBuildListIO(e.biomes,null,b);var f=t.arrify(e.specialBiomes);e=0;for(c=f.length;e<c;e++){var g=f[e];d.add(g)}this.biomeBuildLists[a][b]=d.worldGenRandomize().compact()}return d};ca.prototype.randBuildListIO=function(a,b,c){var d,e,f,g;n.assert(null!=a);n.assert(null!=c);var h=[];Object.isArray(a)||(a=[a]);var k=0;for(e=a.length;k<e;k++){var l=a[k];if(!(ba.rng.random()>(null!=(f=l.chance)?f:1))&&this.checkAllReqsIO(l,
c,b)){var m=null!=(g=l.select)?g:1;if(null!=l.group)h.add(this.randGroupBuildListIO(l.group,m,b,l.fallback,c));else if(null!=l.ref)if(l.ref.includes("grp-"))h.add(this.randGroupBuildListIO(l.ref,m,b,l.fallback,c));else for(d=0;0<=m?d<m:d>m;0<=m?++d:--d)h.push(l.ref);else if(Object.isString(l))for(d=0;0<=m?d<m:d>m;0<=m?++d:--d)h.push(l)}}return h};ca.prototype.randGroupBuildListIO=function(a,b,c,d,e){var f,g,h,k,l;n.assert(null!=a);n.assert(null!=b);n.assert(null!=e);if(Object.isString(a)){var m=t.getGroup(a);
a=m.group;d=m.fallback}m=[];var p=0;for(g=a.length;p<g;p++){var q=a[p];this.checkAllReqsIO(q,e,c)&&m.push(q)}0===m.length&&null!=d&&(m=[d]);a=[];for(d=q=0;0<=b?q<b:q>b;d=0<=b?++q:--q){var r=m.sum(function(a){var b;return null!=(b=a.slots)?b:1});var u=ba.rng.random()*r;d=g=0;for(f=m.length;g<f;d=++g)if(p=m[d],u-=null!=(h=p.slots)?h:1,0>=u||0===r){f=null!=(k=p.select)?k:1;if(null!=p.group)a.add(this.randGroupBuildListIO(p.group,f,c,p.fallback,e));else if(null!=p.ref)if(p.ref.includes("grp-"))a.add(this.randGroupBuildListIO(p.ref,
f,c,p.fallback,e));else for(g=0;0<=f?g<f:g>f;0<=f?++g:--g)a.push(p.ref);(null!=(l=p.consume)?l:1)&&m.removeAt(d);break}}return a};ca.prototype.checkAllReqsIO=function(a,b,c){c=void 0===c?null:c;var d;n.assert(null!=a);n.assert(null!=b);if(null!=a.reqWorld&&!n.match(a.reqWorld,b)||null!=a.reqDifficulty&&!n.match(a.reqDifficulty,this.main.difficultyLvl)||null!=c&&null!=a.reqBiomeFlags&&!t.checkFlags(a.reqBiomeFlags,c.flags))return!1;if(null!=a.ref){if(!this.checkAllReqsIO(t.getBuildItem(a.ref),b,c))return!1}else if(Object.isString(a)){if(!this.checkAllReqsIO(t.getBuildItem(a),
b,c))return!1}else if(null!=a.group){if(Object.isString(a.group))return this.checkAllReqsIO(a.group,b,c);var e=a.group;a=0;for(d=e.length;a<d;a++){var f=e[a];if(this.checkAllReqsIO(f,b,c))return!0}return!1}return!0};ca.prototype.getProgress=function(){return 0===this.maxWorldGenQueue?1:1-this.worldGenQueue.sum(function(a){return a.buildSteps.length})/this.maxWorldGenQueue};ca.prototype.getLogDetail=function(){return null!=this.worldGenQueue[0]?this.worldGenQueue[0].logDetail:""};var Td=ca;var na=
function(a,b,c){a=W.call(this,a,b,c)||this;a.createScoreFromDBRecord=a.createScoreFromDBRecord.bind(a);a.createScoreFromHSRecord=a.createScoreFromHSRecord.bind(a);a.processGoalRecord=a.processGoalRecord.bind(a);a.updateTopScores=a.updateTopScores.bind(a);a.setGlobalType=a.setGlobalType.bind(a);a.getBestGoalScores=a.getBestGoalScores.bind(a);a.drawPartyInfo=a.drawPartyInfo.bind(a);a.globalScoreType=0;a.topScores={};a.goalScores=[];a.scoresPerColumn=10;a.topScoreColumns=4;a.topScoresPerPage=a.scoresPerColumn*
a.topScoreColumns;return a};$jscomp.inherits(na,W);na.prototype.show=function(){var a=this;this.loadingTopScores=!0;this.main.iomp.getHighscorePageForUser(this.topScoresPerPage).then(function(b){a.loadingTopScores=!1;return a.updateTopScores(b)});this.fastestGoalScores=this.mostGoalScores=this.bestGlobalScores=this.bestPlayerScores=null;return this.setGlobalType(0)};na.prototype.hide=function(){this.main.iomp.clearLQForScores("iohighscore");this.topScores={}};na.prototype.createScoreFromDBRecord=
function(a){B(this,na);a={points:a.get("score"),userID:a.get("userid"),explorerSeed:a.get("explorerSeed"),explorerTribe:a.get("explorerTribe"),explorerGender:a.get("explorerGender"),id:a.id,partyData:a.get("partyData")};return this.createScoreFromHSRecord(a)};na.prototype.createScoreFromHSRecord=function(a){var b,c;B(this,na);var d={points:null!=(b=a.points)?b:a.score,userID:a.userID,currentRun:a.id===this.main.iomp.highscoreRow,partyData:null!=(c=a.partyData)?c:{}};null!=a.world&&(d.world=a.world);
null!=a.explorerSeed&&0!==a.explorerSeed&&(d.explorer={explorerSeed:a.explorerSeed,explorerTribe:a.explorerTribe,explorerGender:a.explorerGender});this.main.iomp.getUser(d.userID,function(a){return null!=a?(d.displayname=a.displayName,d.goalCount=a.goalCount):d.displayname="no user!"});return d};na.prototype.updateGoalScores=function(a){var b=this;a=void 0===a?10:a;this.loadingGoalScores||(Parse.Object.extend("Goal"),this.loadingGoalScores=!0,this.main.iomp.getGoalScores(a,function(a){var c;b.goalScores=
[];var e=0;for(c=a.length;e<c;e++){var f=a[e];b.processGoalRecord(f)}b.loadingGoalScores=!1},function(a){return r.error("failed to get top scores: "+a.message)}))};na.prototype.processGoalRecord=function(a,b){var c=this;b=void 0===b?!1:b;B(this,na);var d={userID:a.userID,explorer:{explorerTribe:a.explorer.explorerTribe,explorerSeed:a.explorer.explorerSeed,explorerGender:a.explorer.explorerGender},time:a.time};this.goalScores.push(d);return this.main.iomp.getUser(d.userID,function(a){d.displayname=
a.displayName;d.goalCount=a.goalCount;if(b)return a=q.parse("txt-io-livelog-goal-unlock").replace("$user",a.displayName),c.main.iomp.addNotification(a)})};na.prototype.updateTopScores=function(a,b){var c=this;b=void 0===b?!1:b;B(this,na);!this.loadingTopScores&&(this.currentPage=a,b||null==this.topScores[this.currentPage])&&(this.loadingTopScores=!0,this.main.iomp.getHighscorePage(this.topScoresPerPage,this.currentPage).then(function(b){var d;c.loadingTopScores=!1;var f=[];var g=0;for(d=b.length;g<
d;g++){var h=b[g];f.push(c.createScoreFromHSRecord(h))}c.topScores[a]=f;b=c.currentPage*c.topScoresPerPage;c.main.iomp.setLQForScores(function(a){return c.updateTopScores(c.currentPage,!0)},b,b+c.topScoresPerPage-1,"iohighscore")}))};na.prototype.setGlobalType=function(a){var b=this,c,d,e,f,g,h;return $jscomp.asyncExecutePromiseGeneratorProgram(function(k){switch(k.nextAddress){case 1:B(b,na);3<a?a=0:0>a&&(a=3);b.globalScoreType=a;b.loadingGlobalScores=!0;k.setCatchFinallyBlocks(2);switch(b.globalScoreType){case 1:return k.jumpTo(4);
case 0:return k.jumpTo(5);case 2:return k.jumpTo(6);case 3:return k.jumpTo(7)}k.jumpTo(8);break;case 4:if(null!=b.bestPlayerScores){k.jumpTo(9);break}d=b;return k.yield(b.getBestScores(!0),10);case 10:d.bestPlayerScores=k.yieldResult;case 9:k.jumpTo(8);break;case 5:if(null!=b.bestGlobalScores){k.jumpTo(11);break}e=b;return k.yield(b.getBestScores(!1),12);case 12:e.bestGlobalScores=k.yieldResult;case 11:k.jumpTo(8);break;case 6:if(b.mostGoalScores){k.jumpTo(13);break}f=b;return k.yield(b.getBestGoalScores("getMostGoals"),
14);case 14:f.mostGoalScores=k.yieldResult;case 13:k.jumpTo(8);break;case 7:if(b.fastestGoalScores){k.jumpTo(8);break}g=b;return k.yield(b.getBestGoalScores("getFastestGoals"),16);case 16:g.fastestGoalScores=k.yieldResult;case 8:k.leaveTryBlock(3);break;case 2:c=h=k.enterCatchBlock(),r.error("Setting global score type to "+b.globalScoreType+" failed: "+c);case 3:return k.return(b.loadingGlobalScores=!1)}})};na.prototype.getUserForScore=function(a){return this.main.iomp.getUser(a.userID,function(b){null!=
b?(a.displayname=b.displayName,a.goalCount=b.goalCount):a.displayname="no user!"})};na.prototype.getBestGoalScores=function(a,b){b=void 0===b?20:b;var c=this,d,e,f,g;return $jscomp.asyncExecutePromiseGeneratorProgram(function(h){if(1==h.nextAddress)return B(c,na),debug.disableIOMP||0>=b?h.return([]):h.yield(new Promise(function(c,d){return ea[a]({count:b},function(a){return null!=a.error?d(a.error):c(a)})}),2);g=h.yieldResult;d=0;for(e=g.length;d<e;d++)f=g[d],c.getUserForScore(f);return h.return(g)})};
na.prototype.getBestScores=function(a,b){b=void 0===b?20:b;var c=this,d,e,f,g,h,k,l,m,n;return $jscomp.asyncExecutePromiseGeneratorProgram(function(p){if(1==p.nextAddress){if(debug.disableIOMP||0>=b)return p.return([]);d=Parse.Object.extend("Highscore");m=new Parse.Query(d);a&&m.equalTo("userid",c.main.user.id);m.limit(b);m.descending("score");logs.iomp&&r.log("IOMP;querying "+b+" player scores");return p.yield(m.find(),2)}h=p.yieldResult;l=[];e=0;for(f=h.length;e<f;e++)g=h[e],k=c.createScoreFromDBRecord(g),
l.push(k),n=function(a,b){return c.main.iomp.getWorldForSeed(a).then(function(a){return b.world=a})},n(g.get("seed"),k);return p.return(l)})};na.prototype.draw=function(a,b,c){this.r.drawFrame("menu_bg_1.png");this.drawScores(a,b,c);if(this.r.drawExitButton(q.toText("txt-base-return"),a,b))return this.mouseAction="return"};na.prototype.drawScores=function(a,b,c){var d,e,f;c=$jscomp.makeIterator(this.r.getCanvasSize());var g=c.next().value;var h=c.next().value;var k=this.highlightedScore=null;c=this.r.img.getSprite("hud_scrollButton_charSelect_left.png");
var l=this.r.img.getSprite("hud_scrollButton_charSelect_right.png");this.r.ctx.globalAlpha=1;this.r.ctx.fillStyle="black";var m=2*this.s;var n=200*this.s;var r=h-2*m;this.r.drawPanel(config.panel.infoSimple,m,m,n,r);var t=m+n+m;var u=g-n-3*m;this.r.drawPanel(config.panel.infoSimple,t,m,u,r);r={font:config.fonts.themedLarge,halign:"center"};switch(this.globalScoreType){case 1:var v="txt-io-highscores-mine";var y=this.bestPlayerScores;break;case 0:v="txt-io-highscores-lifetime-score";y=this.bestGlobalScores;
break;case 2:v="txt-io-highscores-lifetime-goals";y=this.mostGoalScores;break;case 3:v="txt-io-highscores-lifetime-goalspeed",y=this.fastestGoalScores}this.r.ctx.globalAlpha=1;g=26*this.s;this.r.drawText(q.toText(v),m+n/2,g,r);this.r.drawText(q.toText("txt-io-highscores-top")+(": "+q.toText("txt-io-state-world")+" "+this.main.iomp.worldData.worldID),t+u/2,g,r);v=12*this.s;var x=2*this.s;if(this.loadingGlobalScores)this.r.drawText(q.toText("txt-loading"),m+n/2,h/2-80*this.s,r);else{var A=m+n/2;var z=
g-4*this.s;var B=A-80*this.s;this.r.hitBox(B,z-c.dSize.h/2,c.dSize.w,c.dSize.h,a,b)&&(this.mouseAction="prevGlobalPage",B-=2*this.s);this.r.drawSprite(c,B,z,{valign:"center",halign:"left"});A+=80*this.s;this.r.hitBox(A-l.dSize.w,z-c.dSize.h/2,l.dSize.w,l.dSize.h,a,b)&&(this.mouseAction="nextGlobalPage",A+=2*this.s);this.r.drawSprite(l,A,z,{valign:"center",halign:"right"});var C=m+v+1*this.s;z=(n-2*v)/2;if(null!=y){var E=y.slice(0,2*this.scoresPerColumn);B=d=0;for(e=E.length;d<e;B=++d){n=E[B];A=C+
Math.floor(B/this.scoresPerColumn)*z;var J=g+8*this.s+B%this.scoresPerColumn*32*this.s;A=this.drawScore(n,B,A,J,z-x,a,b,1!==this.globalScoreType);null!=A&&(k=A,this.highlightedScore=n)}}}C=this.topScores[this.currentPage];if(null==C||this.loadingTopScores&&0===C.length)this.r.drawText(q.toText("txt-loading"),t+u/2,h/2-80*this.s,r);else for(h=t+v+1*this.s,z=(u-2*v)/4,B=u=0,d=C.length;u<d;B=++u)n=C[B],A=h+Math.floor(B/this.scoresPerColumn)*z,J=g+8*this.s+B%this.scoresPerColumn*32*this.s,A=this.drawScore(n,
B+this.currentPage*this.topScoresPerPage,A,J,z-x,a,b),null!=A&&(k=A,this.highlightedScore=n);h=q.toText("txt-io-highscores-page").replace("$page",this.currentPage+1);r.font=config.fonts.themedSmall;A=t+4*v;this.r.drawText(h,A,g,r);this.loadingTopScores||(z=J=g-4*this.s,0<this.currentPage&&(B=A-30*this.s,this.r.hitBox(B,z-c.dSize.h/2,c.dSize.w,c.dSize.h,a,b)&&(this.mouseAction="prevPage",B-=2*this.s),this.r.drawSprite(c,B,z,{valign:"center",halign:"left"})),null!=C&&C.length===this.topScoresPerPage&&
(A+=30*this.s,this.r.hitBox(A-l.dSize.w,z-c.dSize.h/2,l.dSize.w,l.dSize.h,a,b)&&(this.mouseAction="nextPage",A+=2*this.s),this.r.drawSprite(l,A,z,{valign:"center",halign:"right"})));if(null!=this.highlightedScore){A=null!=y&&(f=this.highlightedScore,0<=F.call(y,f))?t:m;if("hitScore"===k&&this.highlightedScore.partyData)return this.drawPartyInfo(this.highlightedScore,A,80*this.s,222*this.s);a=150*this.s;return this.drawUserStats(this.highlightedScore.userID,A,80*this.s,a)}};na.prototype.drawScore=
function(a,b,c,d,e,f,g,h){h=void 0===h?!0:h;var k,l;var m=function(a,b){};var n=c;var r=this.r.img.getSprite(config.panel.scorePanel.sprite).dSize.h;this.r.drawPanel(config.panel.scorePanel,c,d,e,r);m(c,d);m(c+e,d);if(null!=b){c+=12*this.s;m(c,d);m=config.fonts.technicalSmall;var t=d+16*this.s;this.r.drawText(b+1+".",c,t,{font:m,fillColor:"#442406",shadowColor:"white",halign:"right"})}if(null!=a){null==a.portrait&&null!=a.explorer&&(a.portrait=this.main.iomp.getPortrait(a.explorer.explorerTribe,a.explorer.explorerSeed,
a.explorer.explorerGender));null!=a.portrait&&(this.r.drawSprite(a.portrait,c,d+1*this.s,{small:!0,halign:"left",valign:"top"}),this.r.hitBox(c,d-2*this.s,a.portrait.size.w*this.s,a.portrait.size.h*this.s+5*this.s,f,g)&&(k=!0));c+=22*this.s;e>80*this.s&&(this.r.drawGoalBadge(a.goalCount,c,d+23*this.s),c+=13*this.s);b=a.currentRun?config.colors.science:"white";null==this.main.user||a.currentRun||a.userID!==this.main.user.id||(b="yellow");if(null!=a.points){var u=a.points;var v=config.fonts.technicalLarge;
var y=d+13*this.s}else if(a.time){u=this.main.hasMainState("iohighscore")?a.time:a.time-this.main.iomp.worldData.worldStart;u=q.timeDurationToString(u);for(v=this.r.ctx.measureText(u).width;c+v>n+e-4*this.s;)u=u.slice(0,u.length-1),u=u.slice(0,u.length-3)+"...",v=this.r.ctx.measureText(u).width;v=config.fonts.technicalSmall;y=d+11*this.s}this.r.drawText(u,c,y,{font:v,fillColor:b,shadowcolor:"#422406",os:1});u=null;h?u=null!=(l=a.displayname)?l:"...":null!=a.world&&(u=q.toText("txt-io-state-world")+
" "+a.world);if(null!=u){this.r.ctx.font=config.fonts.technicalSmall;for(v=this.r.ctx.measureText(u).width;c+v>n+e-4*this.s;)u=u.slice(0,u.length-1),u=u.slice(0,u.length-3)+"...",v=this.r.ctx.measureText(u).width;this.r.drawText(u,c,d+21*this.s,{font:config.fonts.technicalSmall,fillColor:"black",os:0})}}else this.r.drawText("-",c+25*this.s,d+15*this.s,{font:"18px Aldrich",fillColor:"black",os:0});return k?"hitUser":this.r.hitBox(n,d,e,r,f,g)?"hitScore":null};na.prototype.drawPartyInfo=function(a,
b,c,d,e,f){var g=this,h,k;B(this,na);if(null!=a){var l=a.partyData;if(null!=l&&null!=l.fame){var m=260*this.s;var n=5*this.s;this.r.img.getSprite(config.panel.scorePanel.sprite);this.r.drawInfoBox(b,c,d,m);var r=c;c+=12*this.s;var u=a.displayname+" - "+a.points+" "+q.toText("txt-base-fame")+" - "+l.days+" "+q.toText("txt-outro-days");null!=a.world&&(u+=" - "+q.toText("txt-io-state-world")+" "+a.world);this.r.drawText(u,b+d/2,c,{font:config.fonts.themedSmall,halign:"center",fillColor:config.ioNewGameTitleColor});
var x=b;u=c;if(null==l.createdParty){l.createdParty=[];var v=l.partyMembers;var y=0;for(h=v.length;y<h;y++){var z=v[y];var A=new Fa(this.main,z.id,z.gender);null!=z["var"]&&A.setVariation(z["var"]);A.isDead=z.dead;l.createdParty.push(A);if(null!=z.sourceTribeGenId){var C=new Ta(this.main.r,this.main.r.sfx,this.main);A.initCharGen(z.sourceTribeGenId,z.sourceTribeGenSeed)}}l.explorer=new Fa(this.main,config.io.explorerID,a.explorer.explorerGender);C=new Ta(this.main.r,this.main.r.sfx,this.main);l.explorer.initCharGen(a.explorer.explorerTribe,
a.explorer.explorerSeed);l.explorer.updateSprite(C)}var G=this.r.img.getSprite("res_fxt_treasureLocation.png");v={valign:"bottom",halign:"left"};a=this.r.img.getSprite("hud_char_frame_io.png");y=b+n;z=c+n+a.dSize.h;this.r.drawSprite(a,y,z,v);v.scale=1.5;h=y+3.5*this.s*v.scale;A=z-5*this.s*v.scale;this.r.drawPortrait(l.explorer,h,A,v);if(null!=l.endBiome){var E=y+a.dSize.w/2;var F=z-.6*a.dSize.h}this.r.ctx.globalAlpha=.8;this.r.drawSprite(G,E,F,{halign:"center",valign:"center",scale:2});this.r.ctx.globalAlpha=
1;E=l.explorerLevel;F=A;A=y+a.dSize.w/2;if(0<E){for(;E>config.xp.maxLevelSprite;)this.r.drawSprite("hud_unit_rank_"+config.xp.maxLevelSprite+".png",A,F,{halign:"center",valign:"bottom"}),E-=config.xp.maxLevelSprite,F-=8*this.s;this.r.drawSprite("hud_unit_rank_"+E+".png",A,F,{halign:"center",valign:"bottom"})}F=[];v=l.createdParty;h=0;for(z=v.length;h<z;h++)A=v[h],E=A.flags.animal?this.r.img.getSprite(A.portrait):this.r.img.getSprite(A.portraitSmall),null!=E&&(E=[E],A.isDead&&E.push(G),F.push(E));
E=y+a.dSize.w;E=function(a,b,c,d){var e,f,h,k,l;var m=e=k=0;for(f=a.length;m<f;m++){var p=a[m];var q=0;for(h=p.length;q<h;q++){var r=p[q];k=Math.max(k,.8*r.dSize.h);e=Math.max(e,.8*r.dSize.w)}}m=Math.ceil(a.length/Math.ceil(e*a.length/(d-2*n)));q=Math.ceil((d-2*n-e)/Math.max(1,m-1));q=Math.min(q,2*e);d=0;b=l=b+e/2;c=c+n+k/2;e=0;for(f=a.length;e<f;e++){p=a[e];var t=0;for(h=p.length;t<h;t++)r=p[t],r===G&&(g.r.ctx.globalAlpha=.8),g.r.drawSprite(r,b,c,{halign:"center",valign:"center"}),g.r.ctx.globalAlpha=
1;d+=1;d>=m?(d=0,b=l,c+=k):b+=q}return c+k/2}(F,E,u+n,x+d-E);c+=a.dSize.h+n;b=k=x+n;u=4*this.s;var I=20*this.s;c+=I/2;c=Math.max(E,c);a=l.fame;for(L in a){y=a[L];A=function(a){if(b+a>x+d)return b=k,c+=I};if(L.includes("it-")){E=t.getItem(L);if(null==E||null==E.sprite)continue;E=this.r.img.getSprite(E.sprite);F=E.dSize.w+(y-1)*u;A(F);A=Math.PI/40;v=Math.min(Math.PI/4,A*y);F=Math.min(7,y);h=b;A=z=0;for(C=F;0<=C?z<C:z>C;A=0<=C?++z:--z)A=1===F?0:J.lerp(-v,0,A/(F-1)),this.r.drawSprite(E,b,c,{halign:"left",
valign:"center",rotate:A}),b+=u;F<y&&(A=b+E.dSize.x,this.r.drawText("x "+y,(h+A)/2,c+2*this.s,{font:config.fonts.themedSmall,halign:"center",shadowColor:"black",fillColor:config.colors.help}));b+=E.dSize.w}else if(L.includes("hub")){F=E=60*this.s;A(F);h=parseInt(L.last());E=this.r.img.getSprite(config.io.segmentDifficultySprite);A=b+.55*F;z=A-u;2===h?z-=u/2:3===h&&(z-=u);this.r.drawLocationSprite(config.io.hubLocationID,A,c-10*this.s);this.r.ctx.globalAlpha=.65;for(A=v=0;0<=h?v<=h:v>=h;A=0<=h?++v:
--v)this.r.drawSprite(E,z,c,{halign:"center",valign:"center"}),z+=u;this.r.ctx.globalAlpha=1;1<y&&this.r.drawText("x "+y,z+2*this.s,c+2*this.s,{font:config.fonts.themedSmall,halign:"left",shadowColor:"black",fillColor:config.colors.help});b+=F}else if(L.includes("goal"))E=50*this.s,F=E+y*u,A(F),b+=E/2,this.r.drawLocationSprite("loc-goldenTemple-dry",b,c+5*this.s),b+=E/2;else if(L.includes("region")){b+=u;E=this.r.img.getSprite(config.io.segmentDifficultySprite);z=this.r.img.getSprite("res_fxt_questionmark_undiscovered.png");
v=z.dSize.w/2;F=v+(y-1)*u;A(F);h=parseInt(L.last());var K=b;for(A=C=0;0<=y?C<y:C>y;A=0<=y?++C:--C)this.r.drawSprite(z,b-v/2,c,{halign:"left",valign:"center"}),b+=u;b+=v;z=K+F/2;2===h?z-=u:3===h&&(z-=1.5*u);this.r.ctx.globalAlpha=.65;A=y=0;for(F=h;0<=F?y<=F:y>=F;A=0<=F?++y:--y)this.r.drawSprite(E,z,c+2*this.s,{halign:"center",valign:"center",alpha:.5}),z+=u;this.r.ctx.globalAlpha=1}b+=n}c=r+m-41*this.s-n;b=k-2*this.s;F=Math.max(l.packs.length,config.maximumPartyPacks);var L=this.r.img.getSprite("hud_io_crate_closed_dark.png");
r=null;A=m=0;for(u=F;0<=u?m<u:m>u;A=0<=u?++m:--m)a=l.packs[A],null!=a?this.main.ioInv.drawPack(a,b,c,e,f,!1,1,this.main.gameOver)&&(r=a):this.r.drawSprite(L,b,c),b+=L.dSize.w+n;return r}}};na.prototype.onMouseClick=function(a){switch(this.mouseAction){case "return":this.main.popMainState();break;case "nextPage":this.updateTopScores(this.currentPage+1);break;case "prevPage":this.updateTopScores(this.currentPage-1);break;case "nextGlobalPage":this.setGlobalType(this.globalScoreType+1);break;case "prevGlobalPage":this.setGlobalType(this.globalScoreType-
1)}};na.prototype.drawUserStats=function(a,b,c,d){d=void 0===d?150*this.s:d;a=this.main.iomp.userDB[a];if(null!=a){var e=145*this.s;var f=$jscomp.makeIterator(this.r.getCanvasSize());var g=f.next().value;f=f.next().value;b+d>g&&(b=g-d-5*this.s);c+e>f&&(c=f-e-5*this.s);this.r.drawInfoBox(b,c,d,e);b+=4*this.s;c+=12*this.s;g=config.ioNewGameTitleColor;this.r.drawText(a.displayName,b,c,{font:config.fonts.themedLarge,halign:"left",fillColor:g});f=this.r.ctx.measureText(a.displayName).width;e=8*this.s;
this.r.ctx.fillStyle=a.colour;this.r.ctx.fillRect(b+f+2*this.s,c-e,e,e);c+=15*this.s;f=a.stats;null==f?this.r.drawText("No stats for user!",b,c,{font:config.fonts.technicalSmall,fillColor:g}):(null!=f.bestScore&&(null==f.bestScore.explorer&&(f.bestScore=this.createScoreFromHSRecord(f.bestScore)),this.r.drawText(q.toText("txt-io-user-best-score")+":",b,c,{font:config.fonts.technicalSmall,fillColor:g}),c+=4*this.s,this.drawScore(f.bestScore,null,b,c,d-8*this.s,0,0,!1),c+=30*this.s),null!=f.bestPyramidRank&&
(e=q.toText("txt-io-user-best-pyramid-rank")+": "+(f.bestPyramidRank+1),c+=this.r.drawWrappedText(e,b,c,d,{font:config.fonts.technicalSmall,fillColor:g}),c+=2*this.s),null!=f.bestPyramidTime&&(e=q.toText("txt-io-user-best-pyramid-time")+": "+q.timeDurationToString(f.bestPyramidTime),c+=this.r.drawWrappedText(e,b,c,d,{font:config.fonts.technicalSmall,fillColor:g}),c+=2*this.s),null!=a.goalCount&&(e=q.toText("txt-io-user-best-pyramid-count")+": "+a.goalCount,c+=this.r.drawWrappedText(e,b,c,d,{font:config.fonts.technicalSmall,
fillColor:g}),c+=2*this.s),null!=f.mostClaims&&(e=q.toText("txt-io-user-best-claims")+": "+f.mostClaims,c+=this.r.drawWrappedText(e,b,c,d,{font:config.fonts.technicalSmall,fillColor:g}),c+=2*this.s),null!=f.totalClaims&&(e=q.toText("txt-io-user-best-num-claims")+": "+f.totalClaims,c+=this.r.drawWrappedText(e,b,c,d,{font:config.fonts.technicalSmall,fillColor:g}),c+=2*this.s),null!=f.totalHubs&&(e=q.toText("txt-io-user-best-num-hubs")+": "+f.totalHubs,c+=this.r.drawWrappedText(e,b,c,d,{font:config.fonts.technicalSmall,
fillColor:g}),c+=2*this.s),null!=f.numWorldsPlayed&&(e=q.toText("txt-io-user-best-num-worlds")+": "+f.numWorldsPlayed,c+=this.r.drawWrappedText(e,b,c,d,{font:config.fonts.technicalSmall,fillColor:g}),c+=2*this.s),null!=f.totalExpeditions&&(e=q.toText("txt-io-user-best-num-expeditions")+": "+f.totalExpeditions,this.r.drawWrappedText(e,b,c,d,{font:config.fonts.technicalSmall,fillColor:g})))}};var Rd=na;var Da=function(a,b,c){a=W.call(this,a,b,c)||this;a.advanceCelebration=a.advanceCelebration.bind(a);
return a};$jscomp.inherits(Da,W);Da.prototype.show=function(){var a;this.time=0;this.chatPos=this.chatLine=null;this.chatTime=4;this.doneTime=-1;this.perks=[];this.audience=[];this.main.party.getExplorer();this.perkCount=1;this.showPerks=this.main.hasCampaign()||this.main.hasExtraCampaign();this.main.doEvent(t.getEvent(config.specialEvents.ioPromote));for(a=0;0>a;++a){var b=new $a(this.main);b.sprite=config.celebration.npc.sample();this.main.events.addCharacter(b);this.audience.push(b)}return this.main.playMusic("celebrationMusic",
!0)};Da.prototype.onMouseClick=function(a){return this.showPerks?null!=this.mouseAction&&0>this.doneTime&&4<this.time?this.selectCelebrationPerk(this.mouseAction.id):this.advanceCelebration():this.finishCelebration()};Da.prototype.finishCelebration=function(){this.sfx.fadeOut("celebrationMusic");this.main.popMainState();this.main.hideEventDialogue();return this.main.mainMenu.saveGame.updateSaveGame()};Da.prototype.onKeyPress=function(a){if(32===a.which)return this.advanceCelebration()};Da.prototype.randChatLine=
function(){var a;var b={main:this.main,party:this.main.party,isDefaultPerson:!0};var c=(a=n.isDemo()&&!this.main.hasCampaign())?"cl-celebration-audience-demo":"cl-celebration-audience";.5>Math.random()&&!a&&this.main.doChat("cl-celebration-party",b);b.person=this.main.party.getExplorer();b.fakePartyHasTranslator=!0;c=this.main.randChatLine(c,b).first();if(null!=c){a=this.audience.sample().eventPos;var d=this.main.diary.getImageOffset();b=a.x+d.x+config.chat.eventChatOffset[0]*this.s;a=a.y+d.y+config.chat.eventChatOffset[1]*
this.s;return{text:q.parse(c.text),pos:new u(b,a)}}};Da.prototype.showCelebrationMedals=function(){var a=this,b,c,d,e,f,g,h;this.doneTime=-1;var k=this.main.party.getExplorer();var l=k.hasStatus(config.specialStatuses.polymath)?config.celebration.perkCountPolymath:config.celebration.perkCount;var m=this.main.fillEventCtx();var n=Object.values(config.statuses).filter(function(b){var c=t.getStatus(b.id,!1);return null==c||c.isAbstract||!c.isPerk||k.hasStatus(b.id)?!1:a.main.events.hasRequirements(c,
m)}).worldGenSample(l);0===n.length&&(this.showPerks=!1);l=0;for(g=n.length;l<g;l++){var q=n[l];var r=this.r.img.getSprite(q.sprite);null!=r&&(null==r.silhouetteImg&&(r.silhouetteImg=[]),null==r.silhouetteImg[config.colors.medal]&&(r.silhouetteImg[config.colors.medal]=this.r.img.createSilhouette(r.img,0,config.colors.medal)))}return this.perks=function(){var a,g;var k=[];e=a=0;for(g=n.length;a<g;e=++a)q=n[e],b=function(){var a;var b=[];for(f=a=0;6>a;f=++a)d=.5>Math.random()?1:-1,h=new u(-2*(6-f)+
d*f*10,3*f),b.push({pinned:0===f,pos:h,lastPos:h.clone()});return b}(),c=function(){var a;var b=[];for(f=a=0;5>a;f=++a)h=new u(2*(6-f)+d*f*10,3*f),b.push({pinned:0===f,pos:h,lastPos:h.clone()});return b}(),c.push(b.last()),k.push({conf:q,chains:[b,c]});return k}()};Da.prototype.selectCelebrationPerk=function(a){var b,c;this.main.party.getExplorer().setStatus(a);var d=this.perks;var e=0;for(b=d.length;e<b;e++){var f=d[e];if(f.conf.id!==a){var g=f.chains;var h=0;for(c=g.length;h<c;h++)f=g[h],f.first().pinned=
!1}}--this.perkCount;return this.doneTime=0};Da.prototype.tick=function(a){var b=this,c,d,e,f,g;var h=function(b){if(!b.pinned){var c=b.pos.x-b.lastPos.x;var d=b.pos.y-b.lastPos.y;c=b.pos.x+c;d=b.pos.y+d+1E3*Math.min(.001,a);b.lastPos.x=b.pos.x;b.lastPos.y=b.pos.y;b.pos.x=c;return b.pos.y=d}};var k=function(a,c){var d=a.pos.x-c.pos.x;var e=a.pos.y-c.pos.y;var f=Math.sqrt(d*d+e*e);var g=5*b.s;if(0<f&&f>g&&(f=(g-f)/f,d=.5*d*f,e=.5*e*f,a.pinned||(a.pos.x+=d,a.pos.y+=e),!c.pinned))return c.pos.x-=d,c.pos.y-=
e};this.main.tickDiary(a);this.time+=a;this.chatTime+=a;this.showPerks&&this.time>config.celebration.medalDelay&&0===this.perks.length&&this.showCelebrationMedals();var l=this.perks;var m=0;for(e=l.length;m<e;m++){var n=l[m];for(c=0;3>c;++c){var q=n.chains;var r=0;for(f=q.length;r<f;r++){var t=q[r];var u=d=1;for(g=t.length;1<=g?d<g:d>g;u=1<=g?++d:--d)k(t[u],t[u-1]);g=0;for(d=t.length;g<d;g++)u=t[g],h(u)}}}if(0<=this.doneTime){this.doneTime+=a;if(.5<this.doneTime&&0<this.perkCount)return this.showCelebrationMedals();
if(this.doneTime>config.celebration.outFade+1)return this.main.diary.part.clearParticles(),this.finishCelebration()}};Da.prototype.advanceCelebration=function(){B(this,Da);return 0<this.doneTime?this.doneTime+=50:this.time+=50};Da.prototype.draw=function(a,b,c){var d,e,f,g,h;var k=$jscomp.makeIterator(this.r.getCanvasSize());c=k.next().value;var l=k.next().value;var m=new u(c/2,l/2);this.main.drawDiary(a,b);var n=50*this.s;var r=0*this.s;var t=m.x-((this.perks.length-1)*n+(this.perks.length-1)*r)/
2;var x=m.y-115*this.s;var v=this.perks;var y=d=0;for(f=v.length;d<f;y=++d){k=v[y];var z=k.chains;var A=0;for(g=z.length;A<g;A++){var C=z[A];var B=e=0;for(h=C.length;e<h;B=++e){var E=C[B];var F=Math.floor(t+E.pos.x);var I=Math.floor(5*this.s*Math.abs(y-(this.perks.length-1)/2)+x+E.pos.y);0===B?(this.r.ctx.beginPath(),this.r.ctx.moveTo(F,I)):this.r.ctx.lineTo(F,I)}this.r.ctx.lineWidth=8;this.r.ctx.strokeStyle=config.colors.ribbonOut;this.r.ctx.stroke();this.r.ctx.lineWidth=4;this.r.ctx.strokeStyle=
config.colors.ribbonIn;this.r.ctx.stroke()}this.r.ctx.save();this.r.ctx.translate(F,I-5*this.s);this.r.ctx.rotate(-E.pos.x/100);this.r.drawSprite("hud_medal.png",0,0,{halign:"center",valign:"top"});this.r.drawSprite(k.conf.sprite,-7*this.s,10*this.s,{silhouette:config.colors.medal});this.r.ctx.restore();this.r.hitBox(F-n/2,x,n,3*n,a,b)&&(this.mouseAction=k.conf,k.chains[0].last().pos.y+=5*this.s);t+=n+r}this.showPerks&&this.r.drawSprite("hud_celebration_title_2.png",m.x+1,m.y-110*this.s,{halign:"center",
valign:"center",scale:TWEEN.Easing.Back.Out(J.lerp(0,1,2*this.time,1))});4>this.time&&(this.r.ctx.fillStyle="black",this.r.ctx.globalAlpha=J.lerp(1,0,this.time-.5,3),this.r.ctx.fillRect(0,0,c,l));1<this.doneTime&&(this.r.ctx.fillStyle="black",this.r.ctx.globalAlpha=J.lerp(0,1,this.doneTime-1,config.celebration.outFade),this.r.ctx.fillRect(0,0,c,l));0>this.doneTime&&2>this.chatTime&&null!=this.chatLine&&(this.r.ctx.fillStyle="blue",this.r.ctx.fillRect(this.chatLine.pos.x,this.chatLine.pos.y,2,2),this.r.ctx.globalAlpha=
1,this.main.r.drawChatPanel(this.chatLine.text,this.chatLine.pos.x,this.chatLine.pos.y,{halign:"center",valign:"bottom"}));this.r.drawParticles(!0);if(null!=this.mouseAction){k=this.mouseAction;a=[{text:k.title},{text:k.description}];I=q.bonusHelp(k.bonus);b=0;for(E=I.length;b<E;b++)F=I[b],a.push({text:F,col:config.colors.bonus});return this.main.infoBox.setInfo(a)}};var Sd=Da;var vb=function(a){this.tick=this.tick.bind(this);this.draw=this.draw.bind(this);this.tickCurrentPath=this.tickCurrentPath.bind(this);
this.startNewPath=this.startNewPath.bind(this);this.startNextLeg=this.startNextLeg.bind(this);this.main=a;this.timeUntilNewPathStart=J.randInt(config.io.iompGhostMinIntervalTime,config.io.iompGhostMaxIntervalTime);this.timeUntilNextLeg=0;this.travelPath=this.pathFinder=null;this.currentPathIdx=this.fadeTime=0;this.currentPath=null;this.miniSprites=[];this.currPathUsername="";this.lastPosKnown=!1;this.currentPathPos=null};vb.prototype.tick=function(a){var b;"game"!==this.main.getMainState()||null==
(null!=(b=this.main.party)?b.pos:void 0)||null==this.main.world||this.main.isWarping()||null!=this.main.tutorial||this.main.events.showingEventDialogue?this.travelPath=this.pathFinder=this.currentPath=null:null!=this.currentPath?this.tickCurrentPath(a):(this.timeUntilNewPathStart-=a,0>=this.timeUntilNewPathStart&&(this.startNewPath(),this.timeUntilNewPathStart=J.randInt(config.io.iompGhostMinIntervalTime,config.io.iompGhostMaxIntervalTime)))};vb.prototype.draw=function(){var a;if(null!=this.currentPath){var b=
this.fadeTime<config.io.iompGhostFadeTime?0===this.currentPathIdx?J.lerp(0,1,this.fadeTime/config.io.iompGhostFadeTime):J.lerp(1,0,this.fadeTime/config.io.iompGhostFadeTime):1;Ga=null!=this.travelPath?this.travelPath:new Ka;var c=null!=(a=Ga.getNextPos())?a:this.currentPathPos;c=this.main.world.getTile(c).known;c!==this.lastPosKnown?(c=Ga.getAlpha(),this.lastPosKnown&&(c=1-c),b*=c):c||(b=0);this.main.r.drawMiniParty(this.currentPathPos,Ga,this.miniSprites,this.main.exped.isPartyHidden.bind(this.main.exped),
b*config.io.iompGhostAlpha);b=$jscomp.makeIterator(Ga.getAnimPos(0));b.next();c=b.next().value;a=b.next().value;b=b.next().value;if(null!=c&&null!=a&&null!=b){c=this.main.r.getTileScreenPos(c,!0,!0,!0);var d=this.main.r.getTileScreenPos(a,!0,!0,!0);a=b*(d.x-c.x);b*=d.y-c.y;b=new u(c.x+a,c.y+b)}else b=this.main.r.getTileScreenPos(this.currentPathPos,!0,!0,!0);b.y-=10*this.main.r.s;this.main.r.drawText(this.currPathUsername,b.x,b.y,{font:config.fonts.themedSmall,halign:"center"})}};vb.prototype.tickCurrentPath=
function(a){var b;if(this.fadeTime<config.io.iompGhostFadeTime&&(this.fadeTime+=a,this.fadeTime>=config.io.iompGhostFadeTime))if(logs.ioGhosts&&r.log("GHOSTS;Fade Finished"),this.fadeTime=config.io.iompGhostFadeTime,0===this.currentPathIdx)this.startNextLeg();else{this.currentPath=null;return}if(null!=this.pathFinder){this.pathFinder.tick(a);if(!this.pathFinder.done)return;if(null==this.pathFinder.path){this.fadeTime=0;this.currentPathIdx+=1;this.travelPath=this.pathFinder=null;return}this.pathFinder.path.unshift(this.currentPathPos);
this.travelPath=new Ka(this.pathFinder.path,this.pathFinder.pathCost);this.pathFinder=null}if(null!=this.travelPath){this.travelPath.tick(a*config.io.iompGhostTimeDilation);var c=this.travelPath.getAlpha();1<=c&&(c=null!=(b=this.travelPath.getNextPos())?b:this.currentPathPos,this.travelPath.incMove(),b=this.travelPath.getPos(),b.eq(this.currentPathPos)||(c=this.main.world.getTile(c),this.lastPosKnown=null!=c&&c.known,this.currentPathPos=b));this.travelPath.isDone()&&(this.timeUntilNextLeg-=a,0>=this.timeUntilNextLeg&&
this.fadeTime>=config.io.iompGhostFadeTime&&this.startNextLeg())}};vb.prototype.startNewPath=function(){var a=this,b,c;var d=this.main.world.toBiomePos(this.main.party.pos);d=this.main.world.getBiomeIdx(d);this.currentPath=this.main.iomp.getLegForBiome(d);if(null!=this.currentPath){logs.ioGhosts&&r.log("GHOSTS;Started new path with length "+this.currentPath.path.length+" and user "+this.currentPath.userID+" in biome "+d);n.assert(0<this.currentPath.path.length);this.fadeTime=this.currentPathIdx=0;
var e=this.currentPath.path;d=b=0;for(c=e.length;b<c;d=++b){var f=e[d];this.currentPath.path[d]=this.main.world.biomes[f.biome].getFirstTilePos().add(f.lp)}this.currentPathPos=this.currentPath.path[this.currentPathIdx];this.lastPosKnown=this.main.world.getTile(this.currentPathPos).known;this.pathFinder=this.travelPath=null;this.currPathUsername="";this.main.iomp.getUser(this.currentPath.userID,function(b){return a.currPathUsername=b.displayName});n.assert(null!=this.currentPath.explorerGender);d=
new Fa(this.main,config.io.explorerID,this.currentPath.explorerGender);d.initCharGen(this.currentPath.explorerTribe,this.currentPath.explorerSeed);n.assert(null!=d.miniSprite);this.miniSprites=[d.miniSprite];c=this.currentPath.partyMembers;d=0;for(b=c.length;d<b;d++)f=c[d],f=t.getCharacter(f),null!=(null!=f?f.miniSprite:void 0)&&this.miniSprites.push(f.miniSprite)}};vb.prototype.startNextLeg=function(){n.assert(this.currentPath&&0<this.currentPath.path.length);var a=this.currentPath.path[this.currentPathIdx];
this.currentPathIdx+=1;logs.ioGhosts&&r.log("GHOSTS;Starting leg "+this.currentPathIdx);null==this.currentPath.path[this.currentPathIdx]?(logs.ioGhosts&&r.log("GHOSTS;Path finished"),this.fadeTime=0):(this.travelPath=null,this.pathFinder=new Ma(this.main.world,null,a,{},{ignoreUnknown:!1}),this.pathFinder.find(this.currentPath.path[this.currentPathIdx]),this.timeUntilNextLeg=config.io.iompGhostLegDelayTime)};var Od=vb;var cb={crateHold:0,explorerSlot:1};var ra=function(a,b,c){a=W.call(this,a,b,c)||
this;a.onMouseClick=a.onMouseClick.bind(a);a.onKeyPress=a.onKeyPress.bind(a);a.tick=a.tick.bind(a);a.hide=a.hide.bind(a);a.draw=a.draw.bind(a);a.drawProcessingDialogue=a.drawProcessingDialogue.bind(a);a.drawCompletedDialogue=a.drawCompletedDialogue.bind(a);a.drawFailedDialogue=a.drawFailedDialogue.bind(a);a.drawConfirmationDialogue=a.drawConfirmationDialogue.bind(a);return a};$jscomp.inherits(ra,W);ra.beginTransaction=function(a,b){Object.isString(b.type)&&(b.type=cb[b.type]);switch(b.type){case cb.crateHold:var c=
t.getPack(b.item);if(null==c)return;b.cost=config.io.packCosts[c.value];if(0===b.cost||a.ioInv.isPackHeld(c.id))return;break;case cb.explorerSlot:b.cost=config.io.storedExplorerSlotCost[parseInt(b.item)];b.item="explorerSlot_"+b.item;break;default:r.error("IOTransactionState:beginTransaction: unknown transaction type "+b.type);return}a.ioTransact.transactionParams=b;a.ioTransact.state=0;return a.setMainState("iotransact")};ra.prototype.show=function(){return this.shownTime=0};ra.prototype.onMouseClick=
function(a){var b=this;B(this,ra);if(!(.25>this.shownTime))if(!this.isInBox&&0===this.state)this.main.popMainState();else if(null!=this.mouseAction)switch(this.mouseAction.id){case "dismiss":return this.main.popMainState();case "confirmTransaction":return this.state=1,this.main.iomp.performPurchase(this.transactionParams).then(function(a){if(a)return b.state=2;console.error("IOMP;Transaction failed: result "+a);return b.state=3},function(a){console.error("IOMP;Transaction failed: error "+a);return b.state=
3});case "openStore":return this.main.iomp.openStore();case "account":return this.main.gotoRivalsAccount();case "verifyEmail":return Parse.User.current().set("email",Parse.User.current().get("email")),Parse.User.current().save(),this.main.iomp.waitingForRefresh=!0;case "refreshUser":return this.main.iomp.refreshUserData()}};ra.prototype.onKeyPress=function(a){B(this,ra)};ra.prototype.tick=function(a){B(this,ra);return this.shownTime+=a};ra.prototype.hide=function(){B(this,ra)};ra.prototype.draw=function(a,
b,c){B(this,ra);if(1<this.main.mainStates.length){var d=this.main.mainStates[this.main.mainStates.length-2];null!=d.obj?d.obj.draw(-1,-1,!1):this.main.drawGameState(0,-1,-1,!1)}d=$jscomp.makeIterator(this.r.getCanvasSize());var e=d.next().value;var f=d.next().value;this.r.ctx.fillStyle="black";this.r.ctx.globalAlpha=.5;this.r.ctx.fillRect(0,0,e,f);this.r.ctx.globalAlpha=1;d=220*this.s;var g=170*this.s;e=e/2-d/2;f=f/2-g/2;this.isInBox=this.r.hitBox(e,f,d,g,a,b);this.r.drawPanel(config.panel.confirmWindow,
e,f,d,g);switch(this.state){case 0:return this.drawConfirmationDialogue(d,g,a,b,c);case 1:return this.drawProcessingDialogue(d,g,a,b,c);case 2:return this.drawCompletedDialogue(d,g,a,b,c);case 3:return this.drawFailedDialogue(d,g,a,b,c)}};ra.prototype.drawProcessingDialogue=function(a,b,c,d,e){B(this,ra);a=$jscomp.makeIterator(this.r.getCanvasSize());b=a.next().value;a=a.next().value;b/=2;a/=2;return this.r.drawText(q.toText("txt-io-transact-processing")+"...",b,a,{font:config.fonts.themedLarge,halign:"center",
os:0,fillColor:config.colors.ioSystemText})};ra.prototype.drawCompletedDialogue=function(a,b,c,d,e){B(this,ra);b=$jscomp.makeIterator(this.r.getCanvasSize());a=b.next().value;b=b.next().value;a/=2;var f=b/2;this.r.drawText(q.toText("txt-io-transact-success"),a,f,{font:config.fonts.themedLarge,halign:"center",os:0,fillColor:config.colors.ioSystemText});var g=q.toText("txt-base-ok");b=this.r.ctx.measureText(g).width+32*this.s;if(this.r.drawButton(g,a,f+32*this.s,b,32*this.s,c,d,e))return this.mouseAction=
{id:"dismiss"}};ra.prototype.drawFailedDialogue=function(a,b,c,d,e){B(this,ra);b=$jscomp.makeIterator(this.r.getCanvasSize());a=b.next().value;b=b.next().value;a/=2;var f=b/2;this.r.drawText(q.toText("txt-io-transact-failure"),a,f,{font:config.fonts.themedLarge,halign:"center",os:0,fillColor:config.colors.ioSystemText});var g=q.toText("txt-base-ok");b=this.r.ctx.measureText(g).width+32*this.s;if(this.r.drawButton(g,a,f+32*this.s,b,32*this.s,c,d,e))return this.mouseAction={id:"dismiss"}};ra.prototype.drawConfirmationDialogue=
function(a,b,c,d,e){B(this,ra);var f=$jscomp.makeIterator(this.r.getCanvasSize());var g=f.next().value;f=f.next().value;g/=2;var h=f/2;f=this.transactionParams.cost<=this.main.ioInv.getNumMedals();var k=Math.round(a/3);var l=Math.round(.2*a);var m=g-l;l=g+l;b=h-b/2+8*this.s;this.r.drawWrappedText(q.toText("txt-io-transact-selection")+":",m,b,k,{font:config.fonts.themedLarge,halign:"center",os:0,fillColor:config.colors.ioSystemText});h=f?config.colors.ioSystemText:"red";this.r.drawWrappedText(q.toText("txt-io-transact-cost")+
":",l,b,k,{font:config.fonts.themedLarge,halign:"center",os:0,fillColor:h});b+=32*this.s;switch(this.transactionParams.type){case cb.crateHold:k=this.r.img.getSprite("hud_io_crate_bg_rank1.png");m-=k.dSize.w/2;this.main.ioInv.drawPack(this.transactionParams.item,m,b,c,d,!1)&&this.main.ioNewGame.displayPack(this.transactionParams.item,!1,null);break;case cb.explorerSlot:k=this.r.img.getSprite("hud_charFrame_silhouette.png"),m-=k.dSize.w/2,this.r.drawSprite(k,m,b)}m=this.r.img.getSprite("hud_io_medal.png");
k=b+m.dSize.h/2;this.r.drawSprite(m,l,k,{halign:"center",valign:"center"});l=l+m.dSize.w/2+4*this.s;h="x "+this.transactionParams.cost;this.r.drawText(h,l,k+2*this.s,{font:config.fonts.technicalLarge,os:0,fillColor:f?"white":"red"});h=this.r.ctx.measureText(h).width;var n="/ "+this.main.ioInv.getNumMedals();this.r.drawText(n,l+h+2*this.s,k+2*this.s,{font:config.fonts.technicalSmall,os:0,fillColor:"gray"});b+=m.dSize.h+8*this.s;switch(this.transactionParams.type){case cb.crateHold:var r=q.toText("txt-io-transact-crate-desc");
break;case cb.explorerSlot:r=q.toText("txt-io-transact-explorerSlot-desc")}null!=r&&this.r.drawWrappedText(r,g,b,.7*a,{font:config.fonts.technicalSmall,os:0,fillColor:config.ioNewGameTitleColor,halign:"center"});b+=32*this.s;a=32*this.s;this.r.ctx.font=config.fonts.themedLarge;r=this.r.ctx.measureText(t).width+32*this.s;if(f){var t=q.toText("txt-generic-accept");if(this.r.drawButton(t,g,b,r,a,c,d,e))return this.mouseAction={id:"confirmTransaction"}}else return t=q.toText("txt-generic-back"),this.r.drawButton(t,
g,b,r,a,c,d,e)&&(this.mouseAction={id:"dismiss"}),b-=8*this.s,this.r.drawText(q.toText("txt-io-transact-noFunds"),g,b,{font:config.fonts.technicalSmall,fillColor:"red",os:0,halign:"center"})};var jc=ra}).call(this);
