-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathkongregate_api.js
1 lines (1 loc) · 63.5 KB
/
kongregate_api.js
1
var Kongregate=Kongregate||{};function KongregateAPI(){this._initialize()}Kongregate.Utils=Kongregate.Utils||{},Kongregate.Utils.catchErrors=function(e,t,n){return function(){try{return e.apply(t,arguments)}catch(e){return Kongregate.Log.error("catchErrors caught unhandled exception",e),n}}},function(){function e(e,t,n){Kongregate.Log[e]=function(){try{"undefined"!=typeof active_user&&void 0===Kongregate.Log.debugLevel&&(Kongregate.Log.debugLevel=active_user.debugLevel()),Kongregate.Log.debugLevel>=t&&(console[n]?Function.prototype.apply.call(console[n],console,arguments):console.log(arguments))}catch(e){}}}Kongregate.Log={},e("spam",5,"log"),e("debug",4,"log"),e("info",3,"info"),e("warn",2,"warn"),e("error",1,"error")}(),KonduitEvent={INIT:"init",CONNECT:"connect",CONNECTED:"connected",DISCONNECT:"disconnect",LOGIN:"login",SWITCH_USER:"switch_user",JOIN_ROOM:"join_room",LEAVE_ROOM:"leave_room",USER_JOIN:"user_join",USER_DEPARTURE:"user_departure",USER_CHANGED:"user_changed",ROOM_MESSAGE:"room_message",SYSTEM_MESSAGE:"system_message",PRIVATE_MESSAGE:"private_message",ADMIN_MESSAGE:"admin_message",MESSAGE_ERROR:"message_error",SET_PRESENCE:"set_presence",GUEST_COUNT:"guest_count",ROOM_NOT_FOUND:"room_not_found",ROOM_FULL:"room_full",REQUEST_CHAT_ROOM:"request_chat_room",CREATE_PRIVATE_ROOM:"create_private_room",DESTROY_PRIVATE_ROOM:"destroy_private_room",PRIVATE_ROOM_INVITATION:"private_room_invitation",PRIVATE_ROOM_KICK:"private_room_kick",PRIVATE_ROOM_INVITATION_SENT:"private_room_invitation_sent",JOIN_GUILD_ROOM:"join_guild_room",SILENCED:"silenced",PARTICIPATE:"participate",AMNESTY:"amnesty",API_INITIALIZED:"api_initialized",ADD_STATISTICS:"add_statistics",STATISTIC_UPDATED:"statistic_updated",STATISTIC_SUBMISSION:"statistic_submission",STATISTICS_FLUSH:"statistics_flush",SET_ACCOMPLISHMENT_PROGRESS:"set_accomplishment_progress",NEW_HIGH_SCORE:"new_high_score",DISPLAY_SHOUT_BOX:"display_shout_box",DISPLAY_INVITATION_BOX:"display_invitation_box",SEND_PRIVATE_MESSAGE:"send_private_message",DISPLAY_FEED_POST_BOX:"display_feed_post_box",DISPLAY_SIGN_IN_LIGHTBOX:"display_sign_in_lightbox",DISPLAY_REGISTRATION_LIGHTBOX:"display_registration_lightbox",RESIZE_GAME:"resize_game",HANDLE_ITEM_CHECKOUT_REQUEST:"handle_item_checkout_request",KONDUIT_MESSAGE:"konduit_message",ANALYTICS_PAYLOAD:"analytics_payload",OP_EXTERNAL_MESSAGE:"ext.msg",OP_CONNECTED:"connected",OP_HELLO:"hello",OP_USER_INFO:"user.info",OP_SIGN_IN:"sign_in",PARAM_USER:"user",PARAM_USER_ID:"user_id",PARAM_GAME_AUTH_TOKEN:"auth_token",PURCHASE_RESULT:"purchase_result",PARAM_LOCALCONNECTION_ONLY:"localconnection_only",CUSTOM_TAB_MESSAGE:"custom_tab_message",CUSTOM_TAB_SHOW:"custom_tab_show",CUSTOM_TAB_CLOSE:"custom_tab_close",CUSTOM_TAB_SHOWN:"custom_tab_shown",CUSTOM_TAB_CLEAR_MESSAGES:"custom_tab_clear_messages",OP_CHAT_TAB:"chat.tab",OP_CHAT_CLEAR_DIALOG:"chat.dlg.clear",OP_CHAT_DISPLAY:"chat.disp",OP_CHAT_MSG:"chat.msg",OP_CHAT_CANVAS_ELEMENT:"chat.elm",OP_CHAT_PRIVATE_MESSAGE:"chat.privateMessage",OP_CHAT_RESIZE_GAME:"chat.resizeGame",OP_CHAT_DISPLAY_INVITATION_BOX:"chat.invite",OP_CHAT_DISPLAY_FEED_POST_BOX:"chat.feedpost",OP_CHAT_DISPLAY_REGISTRATION:"chat.registration",OP_CHAT_DISPLAY_SHOUT_BOX:"chat.shoutbox",PARAM_SHOUT_MESSAGE:"shout_message",PARAM_CANVAS_SIZE:"chat.canvas.size",PARAM_RESIZE_GAME_WIDTH:"chat.resizeGame.width",PARAM_RESIZE_GAME_HEIGHT:"chat.resizeGame.height",PARAM_INVITATION_MESSAGE:"invitation_message",PARAM_FRIEND_FILTER:"filter",PARAM_IMAGE_URI:"image_uri",PARAM_KV_PARAMS:"kv_params",PARAM_NAME:"name",PARAM_DESCRIPTION:"desc",PARAM_DATA:"data",OP_SHOUT_CALLBACK:"ext.shout_callback",PARAM_MESSAGE_TYPE:"ext.message_type",PARAM_MESSAGE_RECIPIENTS:"ext.message_recipients",PARAM_ERROR:"error",PARAM_SUCCESS:"success",PARAM_REQUEST_ID:"req.id",OP_STATS_SUBMIT:"stat.submit",ITEM_LIST:"mtx.item_list",ITEM_CHECKOUT:"mtx.checkout",PURCHASE_KREDS:"mtx.kred_purchase",ITEM_INSTANCES:"mtx.item_instances",USE_ITEM_INSTANCE:"mtx.use_item_instance",PARAM_PURCHASE_METHOD:"purchase_method",PARAM_ITEM_TAGS:"item_tags",PARAM_ITEMS:"items",PARAM_ORDER_INFO:"order_info",PARAM_ID:"id",ADS_INITIALIZE:"ads.initialize",ADS_AVAILABLE:"ads.available",ADS_UNAVAILABLE:"ads.unavailable",ADS_SHOW_INCENTIVIZED:"ads.show_incentivized",AD_OPENED:"ads.ad_opened",AD_COMPLETED:"ads.ad_completed",AD_ABANDONED:"ads.ad_abandoned",PROCESSING_SAVE_SHARED_CONTENT:"processing_save_shared_content",SAVE_SHARED_CONTENT:"save_shared_content",SAVE_SHARED_CONTENT_COMPLETE:"shared_content_save_complete",LOAD_SHARED_CONTENT:"load_shared_content",BROWSE_SHARED_CONTENT:"browse_shared_content",OP_SAVE_SHARED_CONTENT:"save_shared_content",OP_BROWSE_SHARED_CONTENT:"browse_shared_content",OP_LOAD_SHARED_CONTENT:"load_shared_content",OP_SHARED_CONTENT_SAVE_COMPLETE:"shared_content_save_complete",PARAM_CONTENT_TYPE:"content_type",PARAM_LABEL:"label",PARAM_IMAGE:"image",OP_IMAGE_AVATAR_SUBMIT:"avatar.submit",OP_IMAGE_AVATAR_FINISHED:"avatar.finished",IMAGE_AVATAR_SUBMIT:"image_avatar_submit",IMAGE_AVATAR_COMPLETE:"image_avatar_complete",OP_ANALYTICS_PAYLOAD:"analytics.payload",HOLODECK_DATA:"holodeck_data",PARAM_HOLODECK_TYPE:"holodeck_type",FETCH_HISTORY:"fetch_history",HISTORY_RECEIVED:"history_received",FAYE_DISCONNECT:"faye_disconnect"},KonduitChatErrorMessage={MESSAGE_TOO_LONG:"error_msg_too_long",RATE_LIMITED:"error_msg_rate_limit"},KonduitPresenceType={CHAT:"chat",AWAY:"away"},Kongregate.polyfillJSON=function(){var a,b,c,d,e;window.JSON||(window.JSON={parse:function(a){return eval("("+a+")")},stringify:(a=Object.prototype.toString,b=Array.isArray||function(e){return"[object Array]"===a.call(e)},c={'"':'\\"',"\\":"\\\\","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t"},d=function(e){return c[e]||"\\u"+(e.charCodeAt(0)+65536).toString(16).substr(1)},e=/[\\"\u0000-\u001F\u2028\u2029]/g,function t(n){if(null==n)return"null";if("number"==typeof n)return isFinite(n)?n.toString():"null";if("boolean"==typeof n)return n.toString();if("object"==typeof n){if("function"==typeof n.toJSON)return t(n.toJSON());if(b(n)){for(var s="[",i=0;i<n.length;i++)s+=(i?", ":"")+t(n[i]);return s+"]"}if("[object Object]"===a.call(n)){for(i in s=[],n)Object.prototype.hasOwnProperty.call(n,i)&&s.push(t(i)+": "+t(n[i]));return"{"+s.join(", ")+"}"}}return'"'+n.toString().replace(e,d)+'"'})})},Kongregate.contentLoaded=function(e){var t=window,n=!1,s=!0,i=t.document,a=i.documentElement,r=i.addEventListener,o=r?"addEventListener":"attachEvent",_=r?"removeEventListener":"detachEvent",c=r?"":"on",g=function(s){"readystatechange"==s.type&&"complete"!=i.readyState||(("load"==s.type?t:i)[_](c+s.type,g,!1),n||!(n=!0))||e.call(t,s.type||s)},u=function(){try{a.doScroll("left")}catch(e){return void setTimeout(u,50)}g("poll")};if("complete"==i.readyState)e.call(t,"lazy");else{if(!r&&a.doScroll){try{s=!t.frameElement}catch(e){}s&&u()}i[o](c+"DOMContentLoaded",g,!1),i[o](c+"readystatechange",g,!1),t[o](c+"load",g,!1)}},function(){var e;Kongregate.MessageConnection=function(e){this.initialize(e)},Kongregate.MessageConnection.MESSAGE_EVENT="kongregate:api:message",Kongregate.MessageConnection.prototype={initialize:function(t){e=t.channel_id,this._window=t.window||window,this._targetOrigin=t.target_origin,this._targetWindows=t.target_window?[t.target_window]:[],this._retryConnection=t.retry_connection||!1,this._messageListeners=[],this._supportsObjects=Kongregate.PostMessage.supportsObjects(),this._client="string"==typeof this._targetOrigin,this._connected=this._handleMessages=!1},addMessageListener:function(e){this._messageListeners.push(e)},isSupported:function(){return!(!this.supportsObjects()&&void 0===this._window.JSON)&&void 0!==(this._targetWindows[0]||window).postMessage},connected:function(){return this._connected},isClient:function(){return this._client},supportsObjects:function(){return this._supportsObjects},logPrefix:function(){return this._client?"[Game:JS]":"[Konduit]"},listen:function(){if(this.isSupported()&&!this._listening){this._listening=!0;var e=this;Kongregate.PostMessage.addMessageListener(this._window,(function(t){e.onMessageReceived.call(e,t)}))}},parseMessage:function(e){try{var t=Kongregate.PostMessage.parseMessage(e);if(t&&t.kongregate_type===Kongregate.MessageConnection.MESSAGE_EVENT)return{opcode:t.opcode,params:t.params}}catch(t){Kongregate.Log.warn(this.logPrefix(),"Error parsing message",e,t)}return null},onMessageReceived:function(e){var t=e.origin||e.originalEvent.origin;this._targetOrigin&&t!==this._targetOrigin?Kongregate.Log.debug(this.logPrefix(),"Ignoring message from "+t):(t=this.parseMessage(e.data))&&this.processMessage(t,e)},processMessage:function(e,t){switch(Kongregate.Log.debug(this.logPrefix(),"Message received:",e),e.opcode){case KonduitEvent.CONNECT:this.onClientConnected(e.params,t.source);break;case KonduitEvent.CONNECTED:this.onConnectedToServer()}for(var n=0;n<this._messageListeners.length;n++)this._messageListeners[n](e.opcode,e.params)},sendMessage:function(e,t){if(this.removeMissingWindows(),this.connected()||e===KonduitEvent.CONNECT||e===KonduitEvent.CONNECTED){var n={kongregate_type:Kongregate.MessageConnection.MESSAGE_EVENT,opcode:e,params:"string"==typeof t?JSON.parse(t):t};this.supportsObjects()||(n=JSON.stringify(n))}else Kongregate.Log.debug(this.logPrefix(),"Not sending "+e+", not connected")},connect:function(){this.connected()||(this.listen(),Kongregate.Log.debug("Attempting to connect to Kongregate API"),this.sendMessage(KonduitEvent.CONNECT,{chnl:e}),this._retryConnection&&this.retryConnection())},retryConnection:function(){var e=this;setTimeout((function(){e.connect()}),5e3)},onClientConnected:function(t,n){t.chnl!==e?Kongregate.Log.warn(this.logPrefix(),"Channel ID mismatch, ignoring connect"):(Kongregate.Log.debug(this.logPrefix(),"API connection established!"),this.acceptClientConnection(n))},onConnectedToServer:function(){this.connected()||(Kongregate.Log.debug(this.logPrefix(),"API connection established!"),this._connected=!0)},acceptClientConnection:function(e){for(var t=!1,n=this._targetWindows,s=0;s<this._targetWindows.length;s++)if(this._targetWindows[s]===e){Kongregate.Log.warn("Re-initializing duplicate connection"),t=!0;break}this._targetWindows=[e],this.sendMessage(KonduitEvent.CONNECTED,{}),this._targetWindows=n,t||this._targetWindows.push(e),this.removeMissingWindows()},removeMissingWindows:function(e){if(!this._client){for(i=this._targetWindows.length-1;0<=i;i--)this._targetWindows[i].top||this._targetWindows.splice(i,1);this._connected=0<this._targetWindows.length}}}}(),Kongregate.PostMessage={addMessageListener:function(e,t){if(e.document.addEventListener)try{e.document.addEventListener.call(e,"message",t,!1)}catch(n){Kongregate.Log.debug("addEventListener failed, using iframe addEventListener: "+n),Kongregate.PostMessage.createIframeEventListener(e,t)}else e.attachEvent?e.attachEvent("onmessage",t):Kongregate.Log.error("Could not add event listener, neither addEventListener or attachEvent found!")},supportsObjects:function(){var e=document.createElement("iframe"),t=!0;e.src="about:blank",document.body.appendChild(e);try{e.contentWindow.postMessage({toString:function(){return t=!1,""}},"*")}catch(e){}return document.body.removeChild(e),t},parseMessage:function(e){return"string"==typeof e&&"{"===e.charAt(0)?JSON.parse(e):"object"==typeof e?e:null},createIframeEventListener:function(e,t){var n=document.createElement("iframe");n.src="about:blank",document.head.appendChild(n),n.contentWindow.addEventListener.call(e,"message",t,!1),document.head.removeChild(n)}},function(){Kongregate.AnalyticsServices=function(e){this.initialize(e)},Kongregate.AnalyticsServices.prototype={initialize:function(e){var t=this;this._heartbeatInterval=e.heartbeat_interval||15e3,this._services=e.services,this._swrveClient=e.swrve_client,this._mtx=e.mtx,this._kongVars=e.kongregate_variables,this._staticVars={},this._persistentStore={},this._heartbeatCount=0,this._enablePersistence=e.enable_persistence,this._services.addEventListener(KonduitEvent.KONDUIT_MESSAGE,(function(e){t._onIncomingMessage(e.opcode,e.params)})),e.start&&this._setup()},addEvent:function(e,t){this._enabled&&(!this._autoAnalyticsDisabled()&&0<=Kongregate.Utils.indexOf(Re,e)?Kongregate.Log.warn("Ignoring analytics event: "+e+" since it is a kong-automatic event."):this._addEventInternal(e,this._objectify(t)))},addFilterType:function(e){if(this._enabled&&e){var t=/^[a-zA-Z0-9_]+$/;e&&t.test(e)?(t=(t=this._savedData[S])?t.split(","):[],0>Kongregate.Utils.indexOf(t,e)&&(t.push(e),t.sort(),this._savedData[S]=t.join(","),this._flushPersistentStore(),Kongregate.Log.info("Filter type added: "+e))):Kongregate.Log.warn("Invalid filterType: "+e+", must be alpha_numeric")}},setCommonPropsCallback:function(e){this._enabled&&(this._commonPropsCallback=e,this.updateCommonProperties())},setCommonProperties:function(e){e=this._objectify(e),this.setCommonPropsCallback((function(){return e}))},updateCommonProperties:function(){try{"function"==typeof this._commonPropsCallback&&(this._commonProperties=this._objectify(this._commonPropsCallback()),this._savedData[ke]=this._commonProperties,this._commonProperties[q]&&!this._savedData[P]&&(this._savedData[P]=this._commonProperties[q]))}catch(e){Kongregate.Log.error("Error updating common properties: "+e)}},getAutoLongProperty:function(e){return this.getAutoIntProperty(e)},getAutoLongLongProperty:function(e){return this.getAutoLongProperty(e)},getAutoStringProperty:function(e){if(!this._enabled)return null;var t=this._getKongAutomaticVariables();return"string"==typeof t[e]?t[e]:(Kongregate.Log.warn("Property is not a string: "+e),null)},getAutoBoolProperty:function(e){return!!this._enabled&&!!this._getKongAutomaticVariables()[e]},getAutoDoubleProperty:function(e){if(!this._enabled)return NaN;var t=this._getKongAutomaticVariables();return Number(t[e])},getAutoIntProperty:function(e){return this._enabled?Math.floor(this.getAutoDoubleProperty(e)):NaN},getAutoUTCProperty:function(e){return this.getAutoStringProperty(e)},getAutoPropertiesJSON:function(){return this._enabled?(this._buildKongAutomaticVariables(),"function"==typeof JSON.stringify?JSON.stringify(this._automaticVars):"{}"):"{}"},startPurchase:function(e,t){if(!this._autoAnalyticsDisabled()){var n=this._getProductId(e);n?(this._priceUSD=this._getUSDPrice(n,t),this._iapID&&Kongregate.Log.warn("startPurchase: invoked before active transaction finished. iap_ids may mismatch."),Kongregate.Log.debug("IAP FLOW STEP: startPurchase(): "+n),this._iapID=this._uuid(),this._productId=n,this._addIAPEvent(null,this._objectify(t),Ee)):Kongregate.Log.warn("startPurchase: Can't start purchase with null productId, param was: "+e)}},finishPurchase:function(e,t,n){this._autoAnalyticsDisabled()||(Kongregate.Log.debug("IAP FLOW STEP: finishPurchase(): "+this._productId+", transactionId: "+t+", resultCode: "+e),Pe===e?(this._numPurchases++,this._totalSpentUSD+=this._priceUSD,this._addIAPEvent(t,this._objectify(n),fe)):this._addIAPFailEvent(t,this._objectify(n)))},setAutomaticVariablesListener:function(e){this._enabled&&(this._automaticVarsListener=e,this._getKongAutomaticVariables())},start:function(){},_setup:function(){if(!this._savedData){var t=this._services.isKongregate();if(this._mode=t?this._kongVars.kongregate_analytics_mode:null,this._enabled=null!==this._mode&&void 0!==this._mode&&this._checkBrowserSupport(),Kongregate.Log.debug("Initializing Analytics API, mode: "+this._mode),this._enabled){this._enablePersistence&&this._hasLocalStorage()&&this._loadPersistentStore(),this._clientVersion=t?this._kongVars.kongregate_game_version:"1",this._pendingEvents=this._persistentStore.pending_events=this._persistentStore.pending_events||[],this._persistentStore.event_queues=this._persistentStore.event_queues||{swrve:[]},this._eventQueue=this._persistentStore.event_queues.swrve=this._persistentStore.event_queues.swrve||[],this._savedData=this._persistentStore.saved_data=this._persistentStore.saved_data||{},this._items=this._persistentStore.items=this._persistentStore.items||[],this._commonProperties=this._savedData.common_properties=this._savedData.common_properties||{},this._bundleId=this._savedData[r],this._autoAnalyticsDisabled()?Kongregate.Log.debug("Auto analytics disabled"):this._autoAnalyticsExcludesServer()?Kongregate.Log.debug("Game has a server, only tracking a subset of analytics automatically"):Kongregate.Log.debug("Automatic analytics enabled"),t&&this._requestItems();t=this._getDate();var n=!this._savedData[y];this._setInitialSavedData(y,this._toW3CDTF(t)),this._setInitialSavedData(b,e),this._setInitialSavedData(I,this._clientVersion),this._setInitialSavedData(T,this._timeZoneOffset()),n&&(Kongregate.Log.debug("Analytics: First play"),this._installEvent()),this._startSession(),this._buildKongStaticVars()}else Kongregate.Log.debug("Analytics API not enabled")}},_enqueueEvent:function(e,t){return!this._initialized&&(this._autoAnalyticsDisabled()&&t[ne]||(Kongregate.Log.debug("Queueing pending event: "+e),this._pendingEvents.push({name:e,event:t})),!0)},_addEventInternal:function(e,t,n){var s=0===e.indexOf("swrve.");if(!s&&!t[te]&&(t=this._merge(this._buildEventSpecificVariables(),t)),!this._enqueueEvent(e,t)&&this._enabled){Ke===e&&this._refreshPlayerInfoFields(t);var i=this._getKongAutomaticVariables(),a={};s?a=t:(this._merge(a,this._objectify(this._commonProperties)),t[ne]?(this._merge(a,i),this._merge(a,t)):(this._merge(a,t),this._merge(a,i))),Kongregate.SwrveClient.SWRVE_SESSION_START_IDENTIFIER===e&&(n=!0),Kongregate.Log.debug("Adding event: "+e+", flush="+n),this._eventQueue.push({name:e,event:a}),this._flushQueue(),n&&this._flushPersistentStore()}},_flushQueue:function(){if(this._swrveClient){var e=this;this._eventQueue.length&&!this._submitLock&&(Kongregate.Log.debug("Flushing swrve event queue"),this._submitLock=!0,this._swrveClient.sendEvents(this._eventQueue,(function(t){e._submitLock=!1,e._flushPersistentStore(),e._flushQueueDelayed(t.success?1e3:1e4)})))}},_flushQueueDelayed:function(e){var t=this;setTimeout((function(){t._flushQueue()}),e)},_persistentStoreName:function(){return Kongregate.AnalyticsServices.persistentStoreName(this._kongVars.kongregate_game_id)},_loadPersistentStore:function(){var e;try{var t=localStorage.getItem(this._persistentStoreName())||"{}";e=JSON.parse(t)}catch(e){Kongregate.Log.warn("Error loading persistent store: "+e)}this._persistentStore=e||{}},_flushPersistentStore:function(){try{var e=JSON.stringify(this._persistentStore);localStorage.setItem(this._persistentStoreName(),e)}catch(e){Kongregate.Log.warn("Error flushing persistent store: "+e)}},_destroyPersistentStore:function(){localStorage.removeItem(this._persistentStoreName())},_buildEventSpecificVariables:function(){var e={};return e[te]=0,this._autoAnalyticsDisabled()||(e[f]=this._uuid(),e[m]=this._toW3CDTF(this._getDate()),e[Q]=this._timeZoneOffset()),e},_refreshPlayerInfoFields:function(e){e[Me]=this._savedData[Me],e[Oe]=this._savedData[Oe];for(var t=0;t<Le.length;t++){var n=Le[t];e[n]?this._savedData[n]=e[n]:e[n]=this._savedData[n]?this._savedData[n]:null}},_addAutoEvent:function(e,t){this._autoAnalyticsDisabled()||((t=this._objectify(t))[ne]=!0,this._addEventInternal(e,t))},_addIAPEvent:function(e,t,n){var s={};this._merge(s,this._objectify(t)),s[me]=this._priceUSD,s[Ae]=this._productId,s[Se]=this._iapID,Ee!=n&&(s[Te]=e||Ce),this._services.isKongregate()?(s[be]=this._getKredPrice(this._productId),s[ye]="KRED"):(s[be]=t[be]||this._priceUSD,s[ye]=t[ye]||"USD"),fe===n&&(this._sendSwrveIAPEvent(this._productId,this._priceUSD,t),this._productId=this._iapID=null,this._priceUSD=0),this._addEventInternal(n,s)},_addIAPFailEvent:function(e,t){var n={};this._merge(n,this._objectify(t)),n[Ie]="SKErrorPaymentCancelled",n[Te]=e||Ce,n[Se]=this._iapID,this._productId=this._iapID=null,this._priceUSD=0,this._addEventInternal(pe,n)},_sendSwrveUserEvent:function(){if(!this._autoAnalyticsDisabled()){for(var e=this._getKongAutomaticVariables(),t={},n=0;n<De.length;n++){var s=De[n];t["kong."+s]=e[s]}this._addAutoEvent(Kongregate.SwrveClient.SWRVE_USER_IDENTIFIER,t)}},_sendSwrveIAPEvent:function(e,t,n){t={product_id:e,quantity:1,local_cost:t,local_currency:"USD",app_store:"unknown_store"};var s={};s[e]={type:"item",amount:1},n.soft_currency_change&&(s.soft_currency_change={type:"currency",amount:n.soft_currency_change}),n.hard_currency_change&&(s.hard_currency_change={type:"currency",amount:n.hard_currency_change}),n.type&&(s[n.type]={type:"item",amount:1}),t.rewards=s,this.addEvent(Kongregate.SwrveClient.SWRVE_IAP_IDENTIFIER,t)},_onIncomingMessage:function(e,t){e===KonduitEvent.OP_ANALYTICS_PAYLOAD&&this._processAnalyticsPayload(t.data.info,t.data.payload)},_setInitialSavedData:function(e,t){this._savedData[e]||(this._savedData[e]=t)},_autoAnalyticsDisabled:function(){return!this._enabled||this._mode===n},_autoAnalyticsAllEnabled:function(){return this._enabled&&this._mode===s},_autoAnalyticsExcludesServer:function(){return this._enabled&&this._mode===i},_getProductId:function(e){try{if("string"==typeof e)return e;if(Number(parseFloat(e))==e)return e.toString();if("[object Array]"===Object.prototype.toString.call(e)){if(0<e.length)return this._getProductId(e[0])}else if("string"==typeof e.identifier)return e.identifier}catch(e){Kongregate.Log.error("Error calculating product ID:",e)}return Kongregate.Log.warn("Couldn't get product ID from: "+e+", type="+typeof e),null},_getUSDPrice:function(e,t){if(this._services.isKongregate()){var n=this._getKredPrice(e);if(0!==n)return Math.floor(100*n*this._kredExchangeRate)/100}else if(t&&t[me])return t[me];return(n=e.match(/^.*t([0-9][0-9])_.*$/))&&2===n.length&&(0<(n=parseInt(n[1],10))&&n<=we.length)?we[n-1]:(Kongregate.Log.warn("Couldn't calculate USD price for identifier: "+e),0)},_getKredPrice:function(e){for(var t=0;t<this._items.length;t++){var n=this._items[t];if(e===n.identifier)return n.price}return Kongregate.Log.warn("Couldn't get kred price for identifier: "+e),0},_requestItems:function(e){if(5<(e=e||0))Kongregate.Log.error("Giving up on retrieving item list");else{var t=this;this._mtx.requestItemList(null,(function(n){n.success?t._items=t._persistentStore.items=n.data:t._retryRequestItems(e+1)}))}},_retryRequestItems:function(e){var t=this;Kongregate.Log.warn("Retrying item list request, retry #"+e),setTimeout((function(){t.requestItems(e)}),15e3*e)},_processAnalyticsPayload:function(e,t){if(Kongregate.Log.info("Analytics payload received"),this._enabled)if(this._checkBrowserSupport(t)){this._config=e;var n=this._config.swrve;this._svid=t.site_visitor_uid,t.kger&&(this._kredExchangeRate=t.kger),this._updateKongStaticVars(t),this._initialized||(this._initialized=!0,!this._swrveClient&&n&&n.application_id&&n.key&&(Kongregate.Log.debug("Swrve initialized"),this._swrveClient=new Kongregate.SwrveClient({application_id:n.application_id,api_key:n.key,player_id:this._services.isKongregate()?this._svid:this._savedData[j],client_version:this._clientVersion})),this._swrveClient?(this._submitLock=!1,this._startHeartbeatTimer(),this._flushPendingEvents(),this._sendSwrveUserEvent(),this.addEvent(Ke,{}),this._flushQueue()):(Kongregate.Log.debug("Analytics not initialized, no services configured"),this._enabled=!1))}else this._enabled=!1},_checkBrowserSupport:function(e){try{if(e&&"safari"===e.browser.browser.toLowerCase())Kongregate.Log.warn("Analytics disabled on Safari");else{if(window.XMLHttpRequest&&"withCredentials"in new XMLHttpRequest)return!0;Kongregate.Log.warn("Analytics disabled due to lack of XHR/CORS support")}}catch(e){Kongregate.Log.warn("Error while checking browser support: "+e)}return!1},_hasLocalStorage:function(){try{var e="kong-"+this._getDate().getTime();return localStorage.setItem(e,e),localStorage.removeItem(e),!0}catch(e){return!1}},_startHeartbeatTimer:function(){if(this._heartbeatInterval){var e=this;setInterval((function(){e._onHeartbeatInterval()}),this._heartbeatInterval)}},_onHeartbeatInterval:function(){this._heartbeatCount+=1,this._session.active=this._getDate().getTime(),4==this._heartbeatCount&&(this._heartbeatCount=0,this.addEvent(Ne,{}))},_flushPendingEvents:function(){if(0<this._pendingEvents.length){Kongregate.Log.debug("Flushing "+this._pendingEvents.length+" pending event(s)");for(var e=0;e<this._pendingEvents.length;e++){var t=this._pendingEvents[e];this._addEventInternal(t.name,t.event,!1)}this._pendingEvents.length=0}},_buildKongStaticVars:function(){if(!this._autoAnalyticsDisabled()){var t=this._services.isKongregate();this._staticVars[r]=this._bundleId,this._staticVars[V]=this._services.getUsername(),this._staticVars[k]=this._services.getUserId(),this._staticVars[Z]=t?this._svid:"",this._staticVars[z]=this._session.id,this._staticVars[W]=e,this._staticVars[F]=this._numSessions(),this._staticVars[h]=this._clientVersion,this._staticVars[E]=this._clientVersion,this._staticVars[I]=this._savedData[I],this._staticVars[P]=this._savedData[P]||null,this._staticVars[X]="kongregate_web",this._autoAnalyticsExcludesServer()||(this._staticVars[j]=t?this._svid:this._savedData[j]),this._staticVars[p]="browser",this._staticVars[B]=null,this._staticVars[y]=this._savedData[y],this._staticVars[b]=this._savedData[b],this._staticVars[T]=this._savedData[T],this._staticVars[H]=this._kongVars.kongregate_language||(window.navigator.userLanguage||window.navigator.language).split("-")[0],this._staticVars[M]=null,this._staticVars[R]=null,this._staticVars[D]=null,this._staticVars[L]=null,this._staticVars[a]=!1,this._staticVars[l]="wifi",this._staticVars[c]=null,this._staticVars[C]=null,this._staticVars[K]=null,this._staticVars[w]=!0,this._staticVars[ee]="web"}},_buildKongAutomaticVariables:function(){if(this._autoAnalyticsDisabled())this._automaticVars={};else{var e={};e[S]=this._savedData[S]||"",e[G]=this._numPurchases,e[v]=this._daysRetained(),this._autoAnalyticsExcludesServer()||(e[J]=this._totalSpentUSD),this._automaticVars=this._merge(e,this._staticVars)}},_updateKongStaticVars:function(e){if(!this._autoAnalyticsDisabled()){this._bundleId="com.kongregate.web."+e.game_permalink,this._services.isExternal()&&(this._bundleId+=".external"),this._savedData[r]=this._bundleId,this._buildKongStaticVars();var t=this._parseOS(e.browser.os);this._staticVars[g]=t.type,this._staticVars[u]=t.version,this._staticVars[U]=e.premium,this._staticVars[O]=e.powerup_rewards_tier,this._savedData[Me]=e.pur_link_date||null,this._savedData[Oe]=e.join_date||null,this._staticVars[$]=Number(e.spent_on_kreds),this._totalSpentUSD=e.spent_usd,this._numPurchases=e.num_purchases,this._staticVars[o]=e.browser.browser,this._staticVars[_]=e.browser.version,this._staticVars[N]=e.ip_address,this._staticVars[A]=e.ip_address,t=this._getDate(),t=Math.abs(t.getTime()-this._parseW3CDTF(e.server_time,t).getTime())/1e3,this._staticVars[Y]=Math.floor(t),this._savedData[x]=e.server_time,this._staticVars[d]=e.country_code,this._getKongAutomaticVariables()}},_getKongAutomaticVariables:function(){return this._enabled?(this.updateCommonProperties(),this._buildKongAutomaticVariables(),this._automaticVarsListener&&this._automaticVarsListener(this._automaticVars),this._automaticVars):{}},_startSession:function(){var e=this._getDate(),n=(this._previousSession=this._savedData.current_session)?(e.getTime()-this._previousSession.active)/1e3:0,s=this._previousSession?(e.getTime()-this._previousSession.start)/1e3:0;n>t?(Kongregate.Log.debug("Terminating previous session ("+this._previousSession.id+"), inactiveFor="+n+", length="+s),(n={})[z]=this._previousSession.id,n[F]=this._numSessions(),n[oe]=this._toW3CDTF(this._previousSession.active),n[re]=s,n[_e]=!1,this._addAutoEvent(ae,n)):this._previousSession&&(this._session=this._previousSession,Kongregate.Log.debug("Reopening previous session ("+this._previousSession.id+"), inactiveFor="+n+", length="+s)),this._session||(this._session={id:this._uuid(),start:e.getTime(),active:e.getTime()},this._savedData.current_session=this._session,e=this._savedData[F]?this._numSessions()+1:1,this._savedData[F]=e,Kongregate.Log.debug("Created new session: "+this._session.id)),this._session!=this._previousSession&&(this.addEvent(Kongregate.SwrveClient.SWRVE_SESSION_START_IDENTIFIER,{}),(e={})[ie]=!1,this._addAutoEvent(se,e))},_installEvent:function(){if(this._autoAnalyticsAllEnabled()){var e={};e[ge]=null,e[ue]=null,e[he]=null,e[de]=null,e[le]=null,e[ve]=null,this._addAutoEvent(ce,e)}else Kongregate.Log.debug("Not firing installs event since analytics mode is not all")},_parseOS:function(e){var t="Unknown",n="Unknown";try{var s=e.split(" ");if(2>s.length)throw Error("Not enough segments in OS string");"OS"===(t=s.shift())&&(t="MacOS",s.shift()),n=s.join(" ")}catch(t){Kongregate.Log.error("Error parsing OS version ("+e+"): "+t.toString())}return{type:t,version:n}},_numSessions:function(){return this._savedData[F]||1},_timeZoneOffset:function(){return this._getDate().getTimezoneOffset()/-60},_daysRetained:function(){var e=this._getDate(),t=this._timeZoneOffset(),n=this._staticVars[y];return n&&(null===(e=this._parseW3CDTF(n,null))&&(Kongregate.Log.warn("Failed to parse first play date: "+n+", resetting"),e=this._getDate(),this._savedData[y]=this._toW3CDTF(e),this._flushPersistentStore())),this._staticVars[T]&&(t=this._staticVars[T]),this._daysSince(e,t)},_dayOfEra:function(e,t){return Math.floor((e+3600*t)/86400)},_daysSince:function(e,t){var n=Math.floor(this._getDate()/1e3),s=Math.floor(e.getTime()/1e3);return this._dayOfEra(n,this._timeZoneOffset())-this._dayOfEra(s,t)},_objectify:function(e){if("string"==typeof e){if(0===e.length||"function"!=typeof JSON.parse)return{};try{return JSON.parse(e)||{}}catch(t){return Kongregate.Log.warn("Failed to parse JSON: "+e+", error: "+t),{}}}return e},_toW3CDTF:function(e){return Kongregate.Utils.toW3CDTF(e)},_parseW3CDTF:function(e,t){return Kongregate.Utils.parseW3CDTF(e,t)},_uuid:function(){var e=this._getDate().getTime();return window.performance&&"function"==typeof window.performance.now&&(e+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){var n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?n:3&n|8).toString(16)}))},_merge:function(e,t){return Kongregate.Utils.merge(e,t)},_getDate:function(){return new Date}};var e="2.0.0",t=300,n="none",s="all",i="cloud",a="ad_tracking",r="bundle_id",o="browser",_="browser_version",c="carrier",g="client_os_type",u="client_os_version",h="client_version",d="country_code",l="data_connection_type",v="days_retained",E="dev_client_version",f="device_event_id",p="device_type",m="event_time",A="external_ip_address",S="filter_type",I="first_client_version",T="first_play_time_offset",y="first_play_time",b="first_sdk_version",P="first_server_version",C="gamecenter_id",K="gamecenter_alias",O="pur_tier",M="idfa",R="idfv",L="imei",D="android_id",N="ip_address",w="is_valid",k="kong_user_id",V="kong_username",U="kong_plus",H="lang_code",x="last_skew_refresh_time",G="num_purchases",F="num_sessions",B="mac_address",j="player_id",W="sdk_version",q="server_version",z="session_id",Y="time_skew",J="total_spent_in_usd",Q="event_time_offset",Z="site_visitor_id",$="usd_spent_on_kreds",X="platform",ee="pkg_src",te="retry_count",ne="auto_event",se="session_starts",ie="is_from_background",ae="session_ends",re="session_length_seconds",oe="session_end_time",_e="did_crash",ce="installs",ge="stub_field",ue="utm_source",he="utm_medium",de="utm_term",le="utm_content",ve="utm_campaign",Ee="iap_attempts",fe="iap_transactions",pe="iap_fails",me="usd_cost",Ae="product_id",Se="iap_id",Ie="fail_reason",Te="receipt_id",ye="local_currency_type",be="local_currency_cost",Pe="SUCCESS",Ce="none",Ke="player_info",Oe="kong_join_date",Me="pur_link_date",Re=[ce,se,ae,"foreground_visits","background_visits",Ee,pe,fe,"invalid_states"],Le=["twitter_id","fb_user_id","fb_username","fb_email","email"],De=[J,y,F,v,p,g,u,d,V,z,M,R,h],Ne="swrve.heartbeat",we=[.99,1.99,2.99,3.99,4.99,5.99,6.99,7.99,8.99,9.99,10.99,11.99,12.99,13.99,14.99,15.99,16.99,17.99,18.99,19.99,20.99,21.99,22.99,23.99,24.99,25.99,26.99,27.99,28.99,29.99,30.99,31.99,32.99,33.99,34.99,35.99,36.99,37.99,38.99,39.99,40.99,41.99,42.99,43.99,44.99,45.99,46.99,47.99,48.99,49.99,54.99,59.99,64.99,69.99,74.99,79.99,84.99,89.99,94.99,99.99,109.99,119.99,124.99,129.99,139.99,149.99,159.99,169.99,174.99,179.99,189.99,199.99,209.99,219.99,229.99,239.99,249.99,299.99,349.99,399.99,449.99,499.99,599.99,699.99,799.99,899.99,999.99],ke="common_properties";Kongregate.AnalyticsServices.KONG_ANALYTICS_EVENT_TIME=m,Kongregate.AnalyticsServices.persistentStoreName=function(e){return"kong-game-analytics-"+e}}(),Kongregate.ApiServices=function(e){this.initialize(e)},Kongregate.ApiServices.prototype={initialize:function(e){this._kongVars=e.kongregate_variables||{},this._messageConnection=e.message_connection,this._eventListeners={},this._requestHandlers={},this._messageQueue=[],this._requestId=0,this._initializeKongVars(this._kongVars),this.initializeEventListeners()},initializeEventListeners:function(){var e=this;this._messageConnection.addMessageListener((function(t,n){e._onIncomingMessage(t,n)}))},_initializeKongVars:function(e){e=e||{},this._kongregate="true"===String(e.kongregate),this._username=e.kongregate_username||"Guest",this._authToken=e.kongregate_game_auth_token,this._userId=parseInt(e.kongregate_user_id,10)||0,this._gameId=parseInt(e.kongregate_game_id,10)||0},addEventListener:function(e,t){this._eventListeners[e]||(this._eventListeners[e]=[]),this._eventListeners[e].push(t)},_dispatchEvent:function(e,t){for(var n=this._eventListeners[e]||[],s=0;s<n.length;s++)n[s](t||{})},connect:function(){},connectExternal:function(){Kongregate.Log.warn("The Kongregate externally hosted API is not available")},isExternal:function(){return!this.isKongregate()},isKongregate:function(){return this._kongregate},getUsername:function(){return this._username},getGameAuthToken:function(){return this._authToken},getUserId:function(){return this._userId},getUserID:function(){return this.getUserId()},getGameId:function(){return this._gameId},getGameID:function(){return this.getGameId()},isGuest:function(){return 0===this.getUserId()},isConnected:function(){return this._messageConnection.connected()&&!this._messageQueue},sendMessage:function(e){this.isConnected()?this._messageConnection.sendMessage(e.opcode,e.params):(Kongregate.Log.debug("Queueing message "+e.opcode+" since API is not yet connected!"),this._messageQueue.push(e))},_flushMessageQueue:function(){if(this._messageQueue){var e=this._messageQueue;this._messageQueue=null,Kongregate.Log.debug("Flushing message queue",e);for(var t=0;t<e.length;t++)this.sendMessage(e[t])}},_onIncomingMessage:function(e,t){switch(e){case KonduitEvent.OP_CONNECTED:this.sendMessage({opcode:KonduitEvent.OP_HELLO,params:{}}),this._flushMessageQueue();break;case KonduitEvent.OP_EXTERNAL_MESSAGE:this._onIncomingMessage(t.opcode,t.data);break;case KonduitEvent.OP_SHOUT_CALLBACK:this._onShoutResponse(t);break;case KonduitEvent.OP_USER_INFO:this._onUserInfo(t)}this._dispatchEvent(KonduitEvent.KONDUIT_MESSAGE,{opcode:e,params:t})},_onShoutResponse:function(e){this._completeRequest(e,{type:e[KonduitEvent.PARAM_MESSAGE_TYPE],recipients:e[KonduitEvent.PARAM_MESSAGE_RECIPIENTS],success:e.success,error:e.error})},_onUserInfo:function(e){var t=e[KonduitEvent.PARAM_USER_ID];if(0!==t){var n=this.isGuest();this._username=e[KonduitEvent.PARAM_USER],this._authToken=e[KonduitEvent.PARAM_GAME_AUTH_TOKEN],this._userId=t,n&&this._dispatchEvent(KonduitEvent.LOGIN)}},privateMessage:function(e,t){if(this._ensureKongregate(t)){var n={shout_message:("string"==typeof e?e:e.content)||""};this._enqueueRequest(n,t),this.sendMessage({opcode:KonduitEvent.OP_CHAT_PRIVATE_MESSAGE,params:n})}},resizeGame:function(e,t){if(this._ensureKongregate()){var n={};n[KonduitEvent.PARAM_RESIZE_GAME_WIDTH]=e,n[KonduitEvent.PARAM_RESIZE_GAME_HEIGHT]=t,this.sendMessage({opcode:KonduitEvent.OP_CHAT_RESIZE_GAME,params:n})}},showInvitationBox:function(e,t){if(this._ensureKongregate()){var n={};e="string"==typeof e?{content:e}:e,n[KonduitEvent.PARAM_INVITATION_MESSAGE]=e.content||"",n[KonduitEvent.PARAM_FRIEND_FILTER]=e.filter||"",n[KonduitEvent.PARAM_KV_PARAMS]=e.kv_params||{},this._enqueueRequest(n,t),this.sendMessage({opcode:KonduitEvent.OP_CHAT_DISPLAY_INVITATION_BOX,params:n})}},showFeedPostBox:function(e,t){if(this._ensureKongregate()){var n={};e="string"==typeof e?{content:e}:e,n[KonduitEvent.PARAM_SHOUT_MESSAGE]=e.content||"",n[KonduitEvent.PARAM_KV_PARAMS]=e.kv_params||{},e.image_uri&&(n[KonduitEvent.PARAM_IMAGE_URI]=e.image_uri),this._enqueueRequest(n,t),this.sendMessage({opcode:KonduitEvent.OP_CHAT_DISPLAY_FEED_POST_BOX,params:n})}},showSignInBox:function(){this.showRegistrationBox()},showRegistrationBox:function(){this._ensureKongregate()&&this.isGuest()&&this.sendMessage({opcode:KonduitEvent.OP_CHAT_DISPLAY_REGISTRATION,params:{}})},showShoutBox:function(e,t){if(this._ensureKongregate()){var n={};n[KonduitEvent.PARAM_SHOUT_MESSAGE]=("string"==typeof e?e:e.content)||"",this._enqueueRequest(n,t),this.sendMessage({opcode:KonduitEvent.OP_CHAT_DISPLAY_SHOUT_BOX,params:n})}},_ensureKongregate:function(e){return!!this.isKongregate()||(e&&e({success:!1}),!1)},_enqueueRequest:function(e,t){var n=this._nextRequestId();e[KonduitEvent.PARAM_REQUEST_ID]=n,"function"==typeof t&&(this._requestHandlers[n]=t)},_completeRequest:function(e,t){var n=e[KonduitEvent.PARAM_REQUEST_ID],s=this._requestHandlers[n];"function"==typeof s&&(s(t||e),delete this._requestHandlers[n])},_nextRequestId:function(){return this._requestId+=1}},Kongregate.ChatServices=function(e){this.initialize(e)},Kongregate.ChatServices.DEFAULT_TAB="Default",Kongregate.ChatServices.prototype={initialize:function(e){var t=this;this._services=e.services,this._eventCallbacks=[],this._services.addEventListener(KonduitEvent.KONDUIT_MESSAGE,(function(e){t._onIncomingMessage(e.opcode,e.params)}))},showTab:function(e,t,n){var s={};s[KonduitEvent.PARAM_NAME]=e,s[KonduitEvent.PARAM_DESCRIPTION]=t,n&&n.size&&(s[KonduitEvent.PARAM_CANVAS_SIZE]=n.size),this._services.sendMessage({opcode:KonduitEvent.OP_CHAT_TAB,params:s})},closeTab:function(){this.showTab(Kongregate.ChatServices.DEFAULT_TAB)},displayMessage:function(e,t){var n={};n[KonduitEvent.PARAM_DATA]=e,n[KonduitEvent.PARAM_USER]=t,this._services.sendMessage({opcode:KonduitEvent.OP_CHAT_DISPLAY,params:n})},clearMessages:function(){this._services.sendMessage({opcode:KonduitEvent.OP_CHAT_CLEAR_DIALOG})},displayCanvasImage:function(e,t,n){var s={};s[KonduitEvent.PARAM_DATA]={type:"image",name:e,url:t,position:n},this._services.sendMessage({opcode:KonduitEvent.OP_CHAT_CANVAS_ELEMENT,params:s})},displayCanvasText:function(e,t,n,s){var i={};i[KonduitEvent.PARAM_DATA]={type:"text",name:e,text:t,position:n,options:s},this._services.sendMessage({opcode:KonduitEvent.OP_CHAT_CANVAS_ELEMENT,params:i})},drawCanvasObject:function(e,t){var n={};n[KonduitEvent.PARAM_DATA]={type:"draw",name:e,commands:t},this._services.sendMessage({opcode:KonduitEvent.OP_CHAT_CANVAS_ELEMENT,params:n})},removeCanvasObject:function(e){var t={};t[KonduitEvent.PARAM_DATA]={type:"remove",name:e},this._services.sendMessage({opcode:KonduitEvent.OP_CHAT_CANVAS_ELEMENT,params:t})},_onIncomingMessage:function(e,t){switch(e){case KonduitEvent.OP_CHAT_MSG:this._handleChatEvent("message",t);break;case KonduitEvent.OP_CHAT_ROOM_MESSAGE:this._handleChatEvent("room.message",t);break;case KonduitEvent.OP_CHAT_TAB:this._handleChatEvent("tab_visible",t)}},addEventListener:function(e,t){"function"!=typeof t?Kongregate.Log.error("addEventListener requires a callback function"):(this._eventCallbacks[e]||(this._eventCallbacks[e]=[]),this._eventCallbacks[e].push(t))},_handleChatEvent:function(e,t){var n=this._eventCallbacks[e];if(n)for(var s=0;s<n.length;s++)n[s](t)}},Kongregate.ImageServices=function(e){this.initialize(e)},Kongregate.ImageServices.prototype={initialize:function(e){var t=this;this._services=e.services,this._submitting=!1,this._callback=null,this._services.addEventListener(KonduitEvent.KONDUIT_MESSAGE,(function(e){t._onIncomingMessage(e.opcode,e.params)}))},submitAvatar:function(e,t){this._submitting?(Kongregate.Log.warn("Another avatar submission is active, ignoring"),t&&t({success:!1})):(this._submitting=!0,this._callback=t,this._services.sendMessage({opcode:KonduitEvent.OP_IMAGE_AVATAR_SUBMIT,params:{image:e}}))},_onIncomingMessage:function(e,t){KonduitEvent.OP_IMAGE_AVATAR_FINISHED===e&&(this._submitting=!1,this._callback&&this._callback(t.success))}},KongregateAPI.prototype={unityElementId:null,_initialize:function(){if(this._flashVarsString="",this._flashVarsObject={},this._services={},this._postMessageParams=void 0,this._loaded=this._paramsReceived=!1,this._queuedMessages=[],this._loadCallbacks=[],this._processParentKongregateParams(),this._processParams(location.search.split("?")[1]),this._updateDebugLevel(),this._postMessageParams=!this.flashVarsObject().kongregate_username&&top!=window){var e=this;Kongregate.polyfillJSON(),Kongregate.PostMessage.addMessageListener(window,(function(t){e._messageOriginIsKongregate(t)&&(t=Kongregate.PostMessage.parseMessage(t.data))&&"params"===t.type&&e._handleParamsMessage(t.data)})),top.postMessage("kongregate_request_params","*")}else this._paramsReceived=!0;setTimeout(this._hijackUnityErrorHandler,0)},flashVarsString:function(){return this._flashVarsString},flashVarsObject:function(){return this._flashVarsObject},getVariable:function(e){return this._flashVarsObject[e]},loadAPI:function(e){!this._postMessageParams||this._paramsReceived?this._doLoadAPI(e):this._loadCallbacks.push(e)},getAPI:function(){return this._services},embedFrame:function(e,t){try{console.warn("KONGREGATE WARNING: The Kongregate Shell and embedFrame method are deprecated, and it is very unlikely that this functionality is really needed. See the note on the documentation page: https://docs.kongregate.com/v1.0/docs/concepts-kongregate-shell")}catch(e){}var n,s=document.getElementById(t||"contentdiv");n="<iframe id='content' frameborder='0' style='position:relative;top:0px;left:0px;border:0px none;padding:0px;width:"+s.offsetWidth+"px;height:"+s.offsetHeight+"px;'",n+="src='"+e+"'></iframe>",s.innerHTML=n},_setGameSwf:function(e){var t=this.flashVarsObject(),n=this,s=this._findSwf(e);s?(this._gameSwf=s,this.messageConnection=this.messageConnection||this._createMessageConnection(t),this.messageConnection.isSupported()?setTimeout((function(){n._gameSwf.setConnectionObject("kongregateAPI.messageConnection")?n.messageConnection.connect():Kongregate.Log.warn("setConnectionObject returned false, not connecting")}),1):(Kongregate.Log.debug("MessageConnection isSupported was false"),setTimeout((function(){n._gameSwf.setConnectionObject(null)}),1))):Kongregate.Log.debug("Kongregate game SWF element does not appear to be a swf: "+e)},_isSwf:function(e){return e&&void 0!==e.Play&&void 0!==e.setConnectionObject},_findSwf:function(e){var t=document.getElementById(e),n=this,s=function(e){for(var s=0;s<e.length;s++)if(t=e[s],n._isSwf(t))return t};return this._isSwf(t)?t:t=s(document.getElementsByName(e))||s(document.querySelectorAll("[id='"+e+"']"))||s(document.getElementsByTagName("object"))||s(document.getElementsByTagName("embed"))},_updateDebugLevel:function(){Kongregate.Log.debugLevel=this._flashVarsObject.kongregate_debug_level||2},_processParentKongregateParams:function(e){try{for(var t=window.parent;t!==top;){try{t.kongregateAPI&&this._processParams(t.kongregateAPI.flashVarsString())}catch(e){}t=t.parent}}catch(e){}},_handleParamsMessage:function(e){if(!this._paramsReceived){for(var t in e)this._processParam(t,e[t]);this._paramsReceived=!0,this._updateDebugLevel(),this._hijackUnityErrorHandler(),0<this._loadCallbacks.length&&this._doLoadAPI()}},_fireLoadCallbacks:function(){var e=this._loadCallbacks.length;Kongregate.Log.debug("Kongregate API: Firing "+e+" load callback(s)");for(var t=0;t<e;t++){var n=this._loadCallbacks[t];"function"==typeof n&&setTimeout(n,0)}this._loadCallbacks=[]},_checkAlreadyLoaded:function(){return this._loaded&&this._fireLoadCallbacks(),this._loaded},_doLoadAPI:function(e){var t=this;Kongregate.contentLoaded((function(){t._loadCallbacks.push(e),t._checkAlreadyLoaded()||(t._loaded=!0,Kongregate.polyfillJSON(),t._hijackUnityErrorHandler(),t.messageConnection=t._createMessageConnection(),t._createJavascriptApi(),t._fireLoadCallbacks())}))},_processParams:function(e){if(e){e=e.split("&");for(var t=0;t<e.length;t++){var n=e[t].split("=");n&&2==n.length&&this._processParam(n[0],n[1])}}},_processParam:function(e,t){0===e.indexOf("kongregate")&&(this._flashVarsObject[e]=t,this._flashVarsString+=e+"="+t+"&")},_messageOriginIsKongregate:function(e){var t=decodeURIComponent(this._flashVarsObject.kongregate_host||"");return e=e.origin,t&&(e===t||e=="http://"+t||e=="https://"+t)},_createJavascriptApi:function(){var e=this;this._services.services=new Kongregate.ApiServices({kongregate_variables:this.flashVarsObject(),message_connection:this.messageConnection}),this._services.stats=new Kongregate.StatisticServices({services:this._services.services}),this._services.sharedContent=new Kongregate.SharedContentServices({services:this._services.services}),this._services.images=new Kongregate.ImageServices({services:this._services.services}),this._services.mtx=new Kongregate.MicrotransactionServices({services:this._services.services}),this._services.chat=new Kongregate.ChatServices({services:this._services.services}),this._services.analytics=new Kongregate.AnalyticsServices({services:this._services.services,mtx:this._services.mtx,kongregate_variables:this.flashVarsObject(),enable_persistence:!0,start:!0}),setTimeout((function(){e.messageConnection.connect()}),0)},_createMessageConnection:function(){var e=this,t=this.flashVarsObject();return(t=new Kongregate.MessageConnection({target_window:top,target_origin:decodeURIComponent(t.kongregate_host),channel_id:t.kongregate_channel_id,retry_connection:!0})).isSupported()&&t.addMessageListener((function(t,n){var s=e._gameSwf;s&&"function"==typeof s.handleMessageConnectionEvent&&s.handleMessageConnectionEvent(JSON.stringify({opcode:t,params:n}))})),t},_hijackUnityErrorHandler:function(){try{kongregateUnitySupport.hijackUnityErrorHandler()}catch(e){}}},kongregateAPI=new KongregateAPI,function(e){function t(e){for(var t=16;t--;){var n=t<<2;_[t]=e.charCodeAt(n)+(e.charCodeAt(n+1)<<8)+(e.charCodeAt(n+2)<<16)+(e.charCodeAt(n+3)<<24)}}function n(e,t,n,s,i,a,r){return((t+=e+s+r)<<i|t>>>a)+n<<0}function s(e){a(0,0,0,0,e),h[0]=E[0]+1732584193<<0,h[1]=E[1]-271733879<<0,h[2]=E[2]-1732584194<<0,h[3]=E[3]+271733878<<0}function i(e){a(h[0],h[1],h[2],h[3],e),h[0]=E[0]+h[0]<<0,h[1]=E[1]+h[1]<<0,h[2]=E[2]+h[2]<<0,h[3]=E[3]+h[3]<<0}function a(e,t,s,i,a){var r;d?(e=n((s^i)&t^i,e,t,a[0],7,25,-680876936),i=n((t^s)&e^s,i,e,a[1],12,20,-389564586),s=n((e^t)&i^t,s,i,a[2],17,15,606105819),t=n((i^e)&s^e,t,s,a[3],22,10,-1044525330)):(e=((e=a[0]-680876937)<<7|e>>>25)-271733879<<0,i=((i=a[1]-117830708+(2004318071&e^-1732584194))<<12|i>>>20)+e<<0,s=((s=a[2]-1126478375+((-271733879^e)&i^-271733879))<<17|s>>>15)+i<<0,t=((t=a[3]-1316259209+((i^e)&s^e))<<22|t>>>10)+s<<0),e=n((s^i)&t^i,e,t,a[4],7,25,-176418897),i=n((t^s)&e^s,i,e,a[5],12,20,1200080426),s=n((e^t)&i^t,s,i,a[6],17,15,-1473231341),t=n((i^e)&s^e,t,s,a[7],22,10,-45705983),e=n((s^i)&t^i,e,t,a[8],7,25,1770035416),i=n((t^s)&e^s,i,e,a[9],12,20,-1958414417),s=n((e^t)&i^t,s,i,a[10],17,15,-42063),t=n((i^e)&s^e,t,s,a[11],22,10,-1990404162),e=n((s^i)&t^i,e,t,a[12],7,25,1804603682),i=n((t^s)&e^s,i,e,a[13],12,20,-40341101),s=n((e^t)&i^t,s,i,a[14],17,15,-1502002290),t=n((i^e)&s^e,t,s,a[15],22,10,1236535329),e=n((t^s)&i^s,e,t,a[1],5,27,-165796510),i=n((e^t)&s^t,i,e,a[6],9,23,-1069501632),s=n((i^e)&t^e,s,i,a[11],14,18,643717713),t=n((s^i)&e^i,t,s,a[0],20,12,-373897302),e=n((t^s)&i^s,e,t,a[5],5,27,-701558691),i=n((e^t)&s^t,i,e,a[10],9,23,38016083),s=n((i^e)&t^e,s,i,a[15],14,18,-660478335),t=n((s^i)&e^i,t,s,a[4],20,12,-405537848),e=n((t^s)&i^s,e,t,a[9],5,27,568446438),i=n((e^t)&s^t,i,e,a[14],9,23,-1019803690),s=n((i^e)&t^e,s,i,a[3],14,18,-187363961),t=n((s^i)&e^i,t,s,a[8],20,12,1163531501),e=n((t^s)&i^s,e,t,a[13],5,27,-1444681467),i=n((e^t)&s^t,i,e,a[2],9,23,-51403784),s=n((i^e)&t^e,s,i,a[7],14,18,1735328473),t=n((s^i)&e^i,t,s,a[12],20,12,-1926607734),e=n((r=t^s)^i,e,t,a[5],4,28,-378558),i=n(r^e,i,e,a[8],11,21,-2022574463),s=n((r=i^e)^t,s,i,a[11],16,16,1839030562),t=n(r^s,t,s,a[14],23,9,-35309556),e=n((r=t^s)^i,e,t,a[1],4,28,-1530992060),i=n(r^e,i,e,a[4],11,21,1272893353),s=n((r=i^e)^t,s,i,a[7],16,16,-155497632),t=n(r^s,t,s,a[10],23,9,-1094730640),e=n((r=t^s)^i,e,t,a[13],4,28,681279174),i=n(r^e,i,e,a[0],11,21,-358537222),s=n((r=i^e)^t,s,i,a[3],16,16,-722521979),t=n(r^s,t,s,a[6],23,9,76029189),e=n((r=t^s)^i,e,t,a[9],4,28,-640364487),i=n(r^e,i,e,a[12],11,21,-421815835),s=n((r=i^e)^t,s,i,a[15],16,16,530742520),t=n(r^s,t,s,a[2],23,9,-995338651),e=n(s^(t|~i),e,t,a[0],6,26,-198630844),i=n(t^(e|~s),i,e,a[7],10,22,1126891415),s=n(e^(i|~t),s,i,a[14],15,17,-1416354905),t=n(i^(s|~e),t,s,a[5],21,11,-57434055),e=n(s^(t|~i),e,t,a[12],6,26,1700485571),i=n(t^(e|~s),i,e,a[3],10,22,-1894986606),s=n(e^(i|~t),s,i,a[10],15,17,-1051523),t=n(i^(s|~e),t,s,a[1],21,11,-2054922799),e=n(s^(t|~i),e,t,a[8],6,26,1873313359),i=n(t^(e|~s),i,e,a[15],10,22,-30611744),s=n(e^(i|~t),s,i,a[6],15,17,-1560198380),t=n(i^(s|~e),t,s,a[13],21,11,1309151649),e=n(s^(t|~i),e,t,a[4],6,26,-145523070),i=n(t^(e|~s),i,e,a[11],10,22,-1120210379),s=n(e^(i|~t),s,i,a[2],15,17,718787259),t=n(i^(s|~e),t,s,a[9],21,11,-343485551),E[0]=e,E[1]=t,E[2]=s,E[3]=i}var r=[],o=[],_=[],c=[],g="0123456789abcdef".split(""),u=[],h=[],d=!1,l=0,v=0,E=[];if(e.Int32Array)o=new Int32Array(16),_=new Int32Array(16),c=new Int32Array(4),u=new Int32Array(4),h=new Int32Array(4),E=new Int32Array(4);else{for(e=0;16>e;e++)o[e]=_[e]=0;for(e=0;4>e;e++)c[e]=u[e]=h[e]=E[e]=0}c[0]=128,c[1]=32768,c[2]=8388608,c[3]=-2147483648,u[0]=0,u[1]=8,u[2]=16,u[3]=24,Kongregate.Utils.md5=function(e,n,a){if(!n){for(var E=n="",f=0,p=0,m=0,A=e.length;m<A;m++)128>(E=e.charCodeAt(m))?p++:(E=2048>E?String.fromCharCode(E>>6|192,63&E|128):String.fromCharCode(E>>12|224,E>>6&63|128,63&E|128),p>f&&(n+=e.slice(f,p)),n+=E,f=p=m+1);p>f&&(n+=e.slice(f,A)),e=n}if(d=!1,l=v=(e+="").length,63<v){for(t(e.substring(0,64)),s(_),d=!0,n=128;n<=v;n+=64)t(e.substring(n-64,n)),i(_);e=e.substring(n-64),v=e.length}for(n=o[0]=o[1]=o[2]=o[3]=o[4]=o[5]=o[6]=o[7]=o[8]=o[9]=o[10]=o[11]=o[12]=o[13]=o[14]=o[15]=0;n<v;n++)f=3&n,o[n>>2]=0===f?e.charCodeAt(n):o[n>>2]|e.charCodeAt(n)<<u[f];return o[n>>2]|=c[3&n],55<n?(d?i(o):(s(o),d=!0),i([0,0,0,0,0,0,0,0,0,0,0,0,0,0,l<<3,0])):(o[14]=l<<3,d?i(o):s(o)),e=h[0],r[1]=g[15&e],r[0]=g[15&(e>>=4)],r[3]=g[15&(e>>=4)],r[2]=g[15&(e>>=4)],r[5]=g[15&(e>>=4)],r[4]=g[15&(e>>=4)],r[7]=g[15&(e>>=4)],r[6]=g[e>>4&15],e=h[1],r[9]=g[15&e],r[8]=g[15&(e>>=4)],r[11]=g[15&(e>>=4)],r[10]=g[15&(e>>=4)],r[13]=g[15&(e>>=4)],r[12]=g[15&(e>>=4)],r[15]=g[15&(e>>=4)],r[14]=g[e>>4&15],e=h[2],r[17]=g[15&e],r[16]=g[15&(e>>=4)],r[19]=g[15&(e>>=4)],r[18]=g[15&(e>>=4)],r[21]=g[15&(e>>=4)],r[20]=g[15&(e>>=4)],r[23]=g[15&(e>>=4)],r[22]=g[e>>4&15],e=h[3],r[25]=g[15&e],r[24]=g[15&(e>>=4)],r[27]=g[15&(e>>=4)],r[26]=g[15&(e>>=4)],r[29]=g[15&(e>>=4)],r[28]=g[15&(e>>=4)],r[31]=g[15&(e>>=4)],r[30]=g[e>>4&15],a?r:r.join("")}}("undefined"==typeof global?window:global),Kongregate.MicrotransactionServices=function(e){this.initialize(e)},Kongregate.MicrotransactionServices.prototype={initialize:function(e){var t=this;this._services=e.services,this._services.addEventListener(KonduitEvent.KONDUIT_MESSAGE,(function(e){t._onIncomingMessage(e.opcode,e.params)})),this._adCallbacks=[]},requestItemList:function(e,t){Kongregate.Log.info("MicrotransactionServices.requestItemList("+e+")");var n={};e&&0<e.length&&(n[KonduitEvent.PARAM_ITEM_TAGS]=e),this._services._enqueueRequest(n,t),this._services.sendMessage({opcode:KonduitEvent.ITEM_LIST,params:n})},requestUserItemList:function(e,t){Kongregate.Log.info("MicrotransactionServices.requestUserItemList("+e+")");var n={};n[KonduitEvent.PARAM_USER]=e||this._services.getUsername(),this._services._enqueueRequest(n,t),this._services.sendMessage({opcode:KonduitEvent.ITEM_INSTANCES,params:n})},purchaseItems:function(e,t){Kongregate.Log.info("MicrotransactionServices.purchaseItems("+e+")");var n={};e&&0<e.length?(this._purchaseItemsCallback=t,n[KonduitEvent.PARAM_ITEMS]=e,this._services.sendMessage({opcode:KonduitEvent.ITEM_CHECKOUT,params:n})):(Kongregate.Log.error("purchaseItems requires a non-empty item identifier array"),t&&t({success:!1}))},purchaseItemsRemote:function(e,t){Kongregate.Log.info("MicrotransactionServices.purchaseItemsRemote("+e+")");var n={};e&&0<String(e).length?(this._purchaseItemsCallback=t,n[KonduitEvent.PARAM_ORDER_INFO]=String(e),this._services.sendMessage({opcode:KonduitEvent.ITEM_CHECKOUT,params:n})):(Kongregate.Log.error("purchaseItemsRemote requires an orderInformation string"),t&&t({success:!1}))},useItemInstance:function(e,t){Kongregate.Log.info("MicrotransactionServices.useItemInstance("+e+")");var n={};e?(n[KonduitEvent.PARAM_ID]=e,this._services._enqueueRequest(n,t),this._services.sendMessage({opcode:KonduitEvent.USE_ITEM_INSTANCE,params:n})):(Kongregate.Log.error("useItemInstance requires an itemInstanceId"),t&&t({success:!1}))},showKredPurchaseDialog:function(e){var t={};t[KonduitEvent.PARAM_PURCHASE_METHOD]=e,this._services.sendMessage({opcode:KonduitEvent.PURCHASE_KREDS,params:t})},initializeIncentivizedAds:function(){this._services.sendMessage({opcode:KonduitEvent.ADS_INITIALIZE})},showIncentivizedAd:function(){this._services.sendMessage({opcode:KonduitEvent.ADS_SHOW_INCENTIVIZED})},addEventListener:function(e,t){"function"!=typeof t?Kongregate.Log.error("addEventListener requires a callback function"):(this._adCallbacks[e]||(this._adCallbacks[e]=[]),this._adCallbacks[e].push(t))},_onIncomingMessage:function(e,t){switch(e){case KonduitEvent.ITEM_INSTANCES:case KonduitEvent.ITEM_LIST:case KonduitEvent.USE_ITEM_INSTANCE:this._services._completeRequest(t);break;case KonduitEvent.PURCHASE_RESULT:this._onPurchaseResultResponse(t);break;case KonduitEvent.ADS_AVAILABLE:this._handleAdEvent("adsAvailable",t);break;case KonduitEvent.ADS_UNAVAILABLE:this._handleAdEvent("adsUnavailable",t);break;case KonduitEvent.AD_OPENED:this._handleAdEvent("adOpened",t);break;case KonduitEvent.AD_COMPLETED:this._handleAdEvent("adCompleted",t);break;case KonduitEvent.AD_ABANDONED:this._handleAdEvent("adAbandoned",t)}},_onPurchaseResultResponse:function(e){this._purchaseItemsCallback&&(this._purchaseItemsCallback(e),this._purchaseItemsCallback=null)},_handleAdEvent:function(e,t){var n=this._adCallbacks[e];if(n)for(var s=0;s<n.length;s++)n[s](t)}},Kongregate.SharedContentServices=function(e){this.initialize(e)},Kongregate.SharedContentServices.CONTENT_TYPE_LIMIT=12,Kongregate.SharedContentServices.prototype={initialize:function(e){var t=this;this._services=e.services,this._loadListeners={},this._services.addEventListener(KonduitEvent.KONDUIT_MESSAGE,(function(e){t._onIncomingMessage(e.opcode,e.params)}))},browse:function(e,t,n){var s={};s[KonduitEvent.PARAM_CONTENT_TYPE]=e,n&&(s[KonduitEvent.PARAM_LABEL]=n),t&&(s[KonduitEvent.PARAM_SORT]=t),this._services.sendMessage({opcode:KonduitEvent.OP_BROWSE_SHARED_CONTENT,params:s})},save:function(e,t,n,s,i){if(this._saving||e.length>Kongregate.SharedContentServices.CONTENT_TYPE_LIMIT)n&&n({success:!1});else{var a={};a[KonduitEvent.PARAM_CONTENT_TYPE]=e,a[KonduitEvent.PARAM_LABEL]=i,a[KonduitEvent.PARAM_DATA]=t,a[KonduitEvent.PARAM_IMAGE]=s,this._services.sendMessage({opcode:KonduitEvent.OP_SAVE_SHARED_CONTENT,params:a}),this._saving=!0,this._saveCallback=n}},addLoadListener:function(e,t){this._loadListeners[e]||(this._loadListeners[e]=[]),this._loadListeners[e].push(t)},_onIncomingMessage:function(e,t){switch(e){case KonduitEvent.OP_SHARED_CONTENT_SAVE_COMPLETE:this._onSaveContentComplete(t);break;case KonduitEvent.OP_LOAD_SHARED_CONTENT:this._onLoadSharedContent(t)}},_onSaveContentComplete:function(e){this._saving=!1,this._saveCallback&&(this._saveCallback(e),this._saveCallback=null)},_onLoadSharedContent:function(e){var t=e.contentType;e={id:e.id,name:e.name,permalink:e.permalink,content:e.content,label:e.label},Kongregate.Log.info({loadContent:e});t=this._loadListeners[t]||[];for(var n=0;n<t.length;n++)t[n](e)}},Kongregate.StatisticServices=function(e){this.initialize(e)},Kongregate.StatisticServices.prototype={initialize:function(e){this._services=e.services},submit:function(e,t){Kongregate.Log.info("StatServices.submit("+e+","+t+")"),!e||null==t||isNaN(t)?Kongregate.Log.warn("Invalid stat name or value:",e,t):this._services.sendMessage({opcode:KonduitEvent.OP_STATS_SUBMIT,params:{stats:[{name:e,value:t}]}})},submitArray:function(e){if(e&&e.length)for(var t=0;t<e.length;t++)this.submit(e[t].name,e[t].value)}},function(){Kongregate.SwrveClient=function(e){this.initialize(e)};var e=Kongregate.SwrveClient;Kongregate.SwrveClient.prototype={initialize:function(e){this._applicationId=e.application_id,this._apiKey=e.api_key,this._playerId=e.player_id,this._clientVersion=e.client_version},sendEvents:function(e,t){var n=new XMLHttpRequest,s=e.length,i=this,a=function(n){i._onError(e,s,n,t)};n.open("POST","//"+this._applicationId+".api.swrve.com/1/batch"),n.setRequestHeader("Content-Type","application/json; charset=utf-8"),n.onerror=n.onabort=a,n.onload=function(){i._onBatchResponse(n,e,s,t,a)},void 0!==n.timeout&&(n.timeout=3e4,n.ontimeout=a),n.send(JSON.stringify(this._createPayload(e)))},_onBatchResponse:function(e,t,n,s,i){var a=!1;if(200===e.status){var r=e.responseText;(a=0===r.length)||(a=200===JSON.parse(r).code)}a?(Kongregate.Log.debug("SWRVE submission complete, "+n+" event(s)"),t.splice(0,n),s&&s({success:!0})):(Kongregate.Log.error("Error while parsing swrve result: "+e.status+", removing "+n+" event(s)"),i(!0))},_onError:function(e,t,n,s){for(var i=0;i<t&&i<e.length;i++){var a=e[i];if(a){var r=(a.event.retry_count||0)+(n?this._maxRetries()+1:1);a.event.retry_count=r}}this._pruneEvents(e),s&&s({success:!1})},_createPayload:function(t){for(var n={app_version:this._clientVersion,session_token:this._createSessionToken(),user:this._playerId},s=[],i=0;i<t.length;i++){var a=(o=t[i]).name,r=this._getTime(o),o=Kongregate.Utils.merge({},o.event);this._removeTransientProperties(o),e.SWRVE_SESSION_START_IDENTIFIER===a?s.push({type:"session_start",time:r}):e.SWRVE_USER_IDENTIFIER===a?s.push({type:"user",time:r,attributes:o}):e.SWRVE_IAP_IDENTIFIER===a?s.push(Kongregate.Utils.merge({type:"iap",time:r},o)):0===a.indexOf("swrve.")?(a=a.replace("swrve.","Kongregate."),s.push({type:"event",name:a,time:r,payload:o})):(a="Kongregate.RawData."+a,s.push({type:"event",name:a,time:r,payload:{data:JSON.stringify(o)}}))}return n.data=s,n},_pruneEvents:function(e){for(var t=e.length-1;0<=t;t--)e[t].event&&e[t].event.retry_count>this._maxRetries()&&(Kongregate.Log.debug("Event "+e[t].name+" is over max retry count, deleting it"),e.splice(t,1));t=this._maxBacklogSize(),e&&e.length>t&&e.splice(0,e.length-t)},_removeTransientProperties:function(e){for(var n=0;n<t.length;n++){var s=t[n];void 0!==e[s]&&delete e[s]}},_createSessionToken:function(){var e=Math.floor(this._getDate().getTime()/1e3);return this._applicationId+"="+this._playerId+"="+String(e)+"="+Kongregate.Utils.md5(this._playerId+String(e)+this._apiKey)},_maxRetries:function(){return 2},_maxBacklogSize:function(){return 100},_getDate:function(){return new Date},_getTime:function(e){var t=this._getDate();return e.event&&e.event[Kongregate.AnalyticsServices.KONG_ANALYTICS_EVENT_TIME]&&(t=Kongregate.Utils.parseW3CDTF(e.event[Kongregate.AnalyticsServices.KONG_ANALYTICS_EVENT_TIME],this._getDate())),Math.floor(t.getTime()/1e3)}},e.SWRVE_EVENT_IDENTIFIER="swrve.",e.SWRVE_BARE_EVENT_IDENTIFIER=e.SWRVE_EVENT_IDENTIFIER+"__bare_",e.SWRVE_SESSION_START_IDENTIFIER=e.SWRVE_BARE_EVENT_IDENTIFIER+"session_start",e.SWRVE_USER_IDENTIFIER=e.SWRVE_BARE_EVENT_IDENTIFIER+"user",e.SWRVE_IAP_IDENTIFIER=e.SWRVE_BARE_EVENT_IDENTIFIER+"iap";var t=["auto_event","retry_count"]}(),function(){Kongregate.Utils.merge=function(e,t){if(!e||!t)return e;for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e},Kongregate.Utils.toW3CDTF=function(e){function t(e){return 10>e?"0"+e:e}return e instanceof Date?e.getUTCFullYear()+"-"+t(e.getUTCMonth()+1)+"-"+t(e.getUTCDate())+"T"+t(e.getUTCHours())+":"+t(e.getUTCMinutes())+":"+t(e.getUTCSeconds())+"."+(e.getUTCMilliseconds()/1e3).toFixed(3).slice(2,5)+"-00:00":""},Kongregate.Utils.parseW3CDTF=function(t,n){var s;try{var i,a=0,r=[1,4,5,6,7,10,11];if(i=e.exec(t)){for(var o,_=0;o=r[_];++_)i[o]=+i[o]||0;i[2]=(+i[2]||1)-1,i[3]=+i[3]||1,"Z"!==i[8]&&void 0!==i[9]&&(a=60*i[10]+i[11],"+"===i[9]&&(a=0-a)),s=new Date(Date.UTC(i[1],i[2],i[3],i[4],i[5]+a,i[6],i[7]))}if(!s||"Invalid Date"===s.toString())throw Error("This date does not conform to W3CDTF.")}catch(e){return s="Unable to parse the string ["+t+"] into a date. The internal error was: "+e.toString(),Kongregate.Log.error(s),n}return s},Kongregate.Utils.indexOf=function(e,t){if(!e)return-1;if("function"==typeof e.indexOf)return e.indexOf(t);for(var n=0;n<e.length;n++)if(e[n]===t)return n;return-1};var e=/^(\d{4}|[+\-]\d{6})(?:-(\d{2})(?:-(\d{2}))?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2})(?::(\d{2}))?)?)?$/}(),"undefined"==typeof kongregateUnitySupport&&(kongregateUnitySupport=function(){function e(e){return(e=r.getElementById(e))?(u.win&&u.ie?(e=e.getElementsByTagName("object")[0])&&"OBJECT"==e.nodeName&&(t=e):(e=e.getElementsByTagName("embed")[0])&&"EMBED"==e.nodeName&&(t=e),t&&typeof t.GetPluginVersion==i?null:t):null;var t}function t(){var t=typeof kongregateAPI!=i&&kongregateAPI.unityGameInstance?kongregateAPI.unityGameInstance:"function"==typeof window.SendMessage?window:window.gameInstance&&"function"==typeof window.gameInstance.SendMessage?window.gameInstance:null;return t||(t="kongregateUnityDiv",typeof kongregateAPI!=i&&kongregateAPI.unityElementId&&(t=kongregateAPI.unityElementId),e(t)||e("unityPlayer"))}function n(){return[kongregate.services.getUserId(),kongregate.services.getUsername(),kongregate.services.getGameAuthToken()].join("|")}var s=[],i="undefined",a=navigator,r=document,o=a.userAgent,_=(a=a.platform,!1),c=/chrome/i.test(o),g={};/msie/i.test(o)?_=parseFloat(o.replace(/^.*msie ([0-9]+(\.[0-9]+)?).*$/i,"$1")):/Trident/i.test(o)&&(_=parseFloat(o.replace(/^.*rv:([0-9]+(\.[0-9]+)?).*$/i,"$1")));var u={w3:typeof r.getElementById!=i&&typeof r.getElementsByTagName!=i&&typeof r.createElement!=i,win:/win/i.test(a||o),mac:/mac/i.test(a||o),ie:_,ff:/firefox/i.test(o),op:/opera/i.test(o),ch:c,ch_v:!!/chrome/i.test(o)&&parseFloat(o.replace(/^.*chrome\/(\d+(\.\d+)?).*$/i,"$1")),sf:/safari/i.test(o)&&!c,wk:!!/webkit/i.test(o)&&parseFloat(o.replace(/^.*webkit\/(\d+(\.\d+)?).*$/i,"$1")),x64:/win64/i.test(o)&&/x64/i.test(o),moz:/mozilla/i.test(o)?parseFloat(o.replace(/^.*mozilla\/([0-9]+(\.[0-9]+)?).*$/i,"$1")):0,mobile:/ipad/i.test(a)||/iphone/i.test(a)||/ipod/i.test(a)||/android/i.test(o)||/windows phone/i.test(o)};return u.clientBrand=u.ch?"ch":u.ff?"ff":u.sf?"sf":u.ie?"ie":u.op?"op":"??",u.clientPlatform=u.win?"win":u.mac?"mac":"???",{onUnityEmbed:function(e){$("unity_missing")&&(e.success?"missingUnityObject"==e.id?($("missingUnityObject").update(""),$("kongregateUnityDiv").update(""),top.location.replace(decodeURIComponent(kongregateAPI.getVariable("kongregate_game_url")))):$("unity_missing").remove():$("unity_missing").show())},initAPI:function(e,i){s.push({object:e||"KongregateAPI",callback:i||"OnKongregateAPILoaded"}),kongregateAPI.loadAPI((function(){"undefined"==typeof kongregate&&(kongregate=kongregateAPI.getAPI());for(var e=0;e<s.length;e++){var i=s[e];t().SendMessage(i.object,i.callback,n())}s=[]}))},getUnityObject:function(){return t()},getUserInfoString:function(){return n()},hijackUnityErrorHandler:function(){if(!kongregateAPI.disableUnityErrorHandler&&!this.unityErrorHandlerInstalled){var e=function(e){if(e.match(/Permission denied to access property/)){try{console.error("Caught error: "+e)}catch(e){}return!0}try{var t;e:{if("string"==typeof e){if(-1!==e.indexOf("Cannot enlarge memory arrays")){t="UnityWebGL:Memory:WebGL";break e}if(-1!==e.indexOf("out of memory")){t="UnityWebGL:Memory:Browser";break e}}t=void 0}if(t&&!g[t]){var n=decodeURIComponent(kongregateAPI.flashVarsObject().kongregate_host||"*");g[t]=!0,top.postMessage({kongregateGameError:{type:t}},n)}}catch(e){}};if("undefined"!=typeof UnityLoader&&UnityLoader.Error&&UnityLoader.Error.handler){var t=UnityLoader.Error.handler;UnityLoader.Error.handler=function(n){return!!e(n.message)||"function"==typeof t&&t.apply(UnityLoader.Error,arguments)},this.unityErrorHandlerInstalled=!0}var n=window.Module;if(n&&n.TOTAL_MEMORY&&n.codeUrl){var s=n.errorhandler;n.errorhandler=function(t,n,i){return!!e(t)||"function"==typeof s&&s(t,n,i)},this.unityErrorHandlerInstalled=!0}}}}}());