@idosgames/game-kit 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +197 -6
- package/dist/index.d.ts +197 -6
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';function
|
|
2
|
-
`||s==="\r"){r++;continue}if(s>="0"&&s<="9"||s==="."&&/[0-9]/.test(e[r+1]??"")){let o=/^(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/.exec(e.slice(r));if(!o)throw new or("bad number",e,r);t.push({t:"num",v:Number(o[0]),at:r}),r+=o[0].length;continue}if(s==="'"||s==='"'){let o=e.indexOf(s,r+1);if(o<0)throw new or("unclosed string",e,r);t.push({t:"str",v:e.slice(r+1,o),at:r}),r=o+1;continue}if(/[A-Za-z_$]/.test(s)){let o=/^[A-Za-z_$][A-Za-z0-9_$]*(?:\.[A-Za-z_$][A-Za-z0-9_$]*)*/.exec(e.slice(r));if(!o)throw new or("bad name",e,r);t.push({t:"id",v:o[0],at:r}),r+=o[0].length;continue}let n=pf.find(o=>e.startsWith(o,r));if(!n)throw new or(`unexpected "${s}"`,e,r);t.push({t:"op",v:n,at:r}),r+=n.length;}return t.push({t:"end",at:e.length}),t}var oc={"||":1,"&&":2,"==":3,"!=":3,"<":4,"<=":4,">":4,">=":4,"+":5,"-":5,"*":6,"/":6,"%":6,"^":8};function uf(e){let t=hf(e),r=0,s=()=>t[r],n=()=>t[r++],o=C=>{let I=s();return I.t==="op"&&I.v===C},a=C=>{let I=n();if(I.t!=="op"||I.v!==C)throw new or(`expected "${C}"`,e,I.at)},c=C=>{if(C>Qi)throw new or("formula is nested too deep",e,s().at);let I=p(0,C+1);if(!o("?"))return I;n();let K=c(C+1);a(":");let ne=c(C+1);return {k:"cond",c:I,a:K,b:ne}},p=(C,I)=>{if(I>Qi)throw new or("formula is nested too deep",e,s().at);let K=x(I+1);for(;;){let ne=s();if(ne.t!=="op")break;let V=oc[ne.v];if(V===void 0||V<C)break;n();let ce=ne.v==="^"?p(V,I+1):p(V+1,I+1);K={k:"bin",op:ne.v,a:K,b:ce};}return K},x=C=>{if(C>Qi)throw new or("formula is nested too deep",e,s().at);return o("-")||o("!")?{k:"un",op:n().v,a:p(oc["^"],C+1)}:E(C+1)},E=C=>{let I=n();if(I.t==="num")return {k:"num",v:I.v};if(I.t==="str")return {k:"str",v:I.v};if(I.t==="op"&&I.v==="("){let K=c(C+1);return a(")"),K}if(I.t==="id"){if(I.v==="true")return {k:"bool",v:true};if(I.v==="false")return {k:"bool",v:false};if(o("(")){if(!Object.prototype.hasOwnProperty.call(Yi,I.v))throw new or(`unknown function "${I.v}"`,e,I.at);n();let K=[];if(!o(")"))for(;;){if(K.push(c(C+1)),o(",")){n();continue}break}return a(")"),{k:"call",fn:I.v,args:K}}return {k:"var",path:I.v.split(".")}}throw new or(I.t==="end"?"unexpected end":"unexpected token",e,I.at)},L=c(0),O=s();if(O.t!=="end")throw new or("unexpected token",e,O.at);return L}function mf(e,t){let r=e;for(let s of t){if(r===null||typeof r!="object"||!Object.prototype.hasOwnProperty.call(r,s))return 0;r=r[s];}return typeof r=="number"||typeof r=="string"||typeof r=="boolean"?r:0}function nr(e,t){switch(e.k){case "num":case "str":case "bool":return e.v;case "var":return mf(t,e.path);case "un":return e.op==="-"?-it(nr(e.a,t)):!pn(nr(e.a,t));case "cond":return pn(nr(e.c,t))?nr(e.a,t):nr(e.b,t);case "call":return it(Yi[e.fn](...e.args.map(r=>it(nr(r,t)))));case "bin":{if(e.op==="&&")return pn(nr(e.a,t))&&pn(nr(e.b,t));if(e.op==="||")return pn(nr(e.a,t))||pn(nr(e.b,t));let r=nr(e.a,t),s=nr(e.b,t);switch(e.op){case "==":return typeof r=="string"||typeof s=="string"?String(r)===String(s):it(r)===it(s);case "!=":return typeof r=="string"||typeof s=="string"?String(r)!==String(s):it(r)!==it(s);case "<":return it(r)<it(s);case "<=":return it(r)<=it(s);case ">":return it(r)>it(s);case ">=":return it(r)>=it(s);case "+":return typeof r=="string"||typeof s=="string"?`${r}${s}`:it(r)+it(s);case "-":return it(r)-it(s);case "*":return it(r)*it(s);case "/":{let n=it(s);return n===0?0:it(r)/n}case "%":{let n=it(s);return n===0?0:it(r)%n}case "^":return it(Math.pow(it(r),it(s)))}return 0}}}function Qr(e,t){switch(e.k){case "var":t.add(e.path.join("."));return;case "un":Qr(e.a,t);return;case "bin":Qr(e.a,t),Qr(e.b,t);return;case "cond":Qr(e.c,t),Qr(e.a,t),Qr(e.b,t);return;case "call":for(let r of e.args)Qr(r,t);return;default:return}}var ps=new Map;function br(e){let t=ps.get(e);if(t)return t;if(e.length>nc)throw new or("formula is too long",e,nc);let r=uf(e),s=new Set;Qr(r,s);let n={source:e,reads:[...s],eval:o=>nr(r,o),num:o=>it(nr(r,o)),bool:o=>pn(nr(r,o))};return ps.size>5e3&&ps.clear(),ps.set(e,n),n}function Ji(e){try{return br(e),null}catch(t){return t instanceof Error?t.message:String(t)}}function ea(e,t,r=0){return e===void 0?r:typeof e=="number"?Number.isFinite(e)?e:r:br(e).num(t)}var yf=/^[a-z][a-z0-9-]*(?:\.[a-z0-9-]+)*$/;function $e(e){if(!yf.test(e))throw new Error(`world: bad component name "${e}"`);return Object.freeze({name:e})}var $o=class{rng;vars;tick=0;time=0;nextId=1;alive=new Set;stores=new Map;doomed=new Set;systems=[];systemSeq=0;handlers=new Map;queue=[];maxEventRounds;stepping=false;constructor(t={}){this.rng=fs(t.seed??"world"),this.vars={...t.vars??{}},this.maxEventRounds=t.maxEventRounds??16;}create(){let t=this.nextId++;return this.alive.add(t),t}destroy(t){this.alive.has(t)&&(this.stepping?this.doomed.add(t):this.purge(t));}isAlive(t){return this.alive.has(t)&&!this.doomed.has(t)}get entityCount(){return this.alive.size-this.doomed.size}set(t,r,s){if(!this.alive.has(t))throw new Error(`world: entity ${t} does not exist`);let n=this.stores.get(r.name);return n||(n=new Map,this.stores.set(r.name,n)),n.set(t,s),t}get(t,r){return this.stores.get(r.name)?.get(t)}need(t,r){let s=this.get(t,r);if(s===void 0)throw new Error(`world: entity ${t} has no ${r.name}`);return s}has(t,r){return this.stores.get(r.name)?.has(t)??false}remove(t,r){this.stores.get(r.name)?.delete(t);}query(...t){if(t.length===0)return [...this.alive].filter(a=>!this.doomed.has(a)).sort((a,c)=>a-c);let r=t.map(a=>this.stores.get(a.name));if(r.some(a=>!a||a.size===0))return [];let s=r,n=s.reduce((a,c)=>c.size<a.size?c:a),o=[];for(let a of n.keys())this.doomed.has(a)||s.every(c=>c.has(a))&&o.push(a);return o.sort((a,c)=>a-c)}addSystem(t){if(this.systems.some(r=>r.system.id===t.id))throw new Error(`world: system "${t.id}" is already added`);this.systems.push({system:t,seq:this.systemSeq++}),this.systems.sort((r,s)=>(r.system.order??0)-(s.system.order??0)||r.seq-s.seq);}removeSystem(t){this.systems=this.systems.filter(r=>r.system.id!==t);}get systemIds(){return this.systems.map(t=>t.system.id)}on(t,r){let s=this.handlers.get(t)??[];return s.push(r),this.handlers.set(t,s),()=>{let n=this.handlers.get(t);if(!n)return;let o=n.indexOf(r);o>=0&&n.splice(o,1);}}emit(t,r={}){this.queue.push({topic:t,payload:r});}flushEvents(){for(let t=0;t<this.maxEventRounds&&this.queue.length>0;t++){let r=this.queue;this.queue=[];for(let{topic:s,payload:n}of r){let o=this.handlers.get(s);if(!o)continue;for(let c of o.slice())c(n,this);let a=this.handlers.get("*");if(a)for(let c of a.slice())c({...n,topic:s},this);}}this.queue.length>0&&(this.queue=[],this.overflowed++);}overflowed=0;step(t){if(!(t>=0)||!Number.isFinite(t))throw new RangeError("world: dt must be a finite number \u2265 0");this.stepping=true;try{this.tick++,this.time+=t;for(let{system:r}of this.systems.slice())r.run(this,t);this.flushEvents();}finally{this.stepping=false;for(let r of this.doomed)this.purge(r);this.doomed.clear();}}purge(t){this.alive.delete(t);for(let r of this.stores.values())r.delete(t);}};function gf(e,t={}){let r=t.step??.016666666666666666,s=t.maxSteps??5,n=0;return {step:r,advance(o){if(!(o>0)||!Number.isFinite(o))return 0;n+=o;let a=0;for(;n>=r&&a<s;)e.step(r),n-=r,a++;return a===s&&(n=0),a},get alpha(){return n/r}}}var Mo=Cr("effect"),bf=/^[a-z][a-z0-9_]*$/,sc=e=>{let t=e.name;if(typeof t!="string"||!bf.test(t))throw new Error(`effect ${e.type}: bad var name`);return t},ic=[{id:"set-var",version:1,required:["name","value"],formulas:["value"],run(e,t){let r=t.value,s=typeof r=="string"?br(r).eval(e.scope):typeof r=="number"||typeof r=="boolean"?r:0;e.world.vars[sc(t)]=s;}},{id:"add-var",version:1,required:["name","amount"],formulas:["amount","min","max"],run(e,t){let r=sc(t),s=e.world.vars[r],n=(typeof s=="number"?s:0)+e.num(t.amount);t.min!==void 0&&(n=Math.max(n,e.num(t.min))),t.max!==void 0&&(n=Math.min(n,e.num(t.max))),e.world.vars[r]=n;}},{id:"emit",version:1,required:["topic"],run(e,t){let r=t.topic;if(typeof r!="string"||r.length===0)throw new Error("effect emit: topic required");let s=t.payload,n={};if(s&&typeof s=="object")for(let[o,a]of Object.entries(s))n[o]=typeof a=="string"?br(a).eval(e.scope):a;e.world.emit(r,n);}}];function Eo(e){for(let t of ic)e.has(Mo,t.id)||e.define(Mo,t);}function hs(e,t,r,s){let n=new Set;e.forEach((o,a)=>{let c=`${r}.${a}`;if(!o||typeof o!="object"){s.push({level:"error",path:c,code:"RULE_SHAPE",message:"a rule must be an object"});return}if(typeof o.id!="string"||o.id.length===0?s.push({level:"error",path:`${c}.id`,code:"RULE_ID",message:"a rule needs an id"}):n.has(o.id)?s.push({level:"error",path:`${c}.id`,code:"RULE_DUPLICATE",message:`rule "${o.id}" is defined twice`}):n.add(o.id),(typeof o.on!="string"||o.on.length===0)&&s.push({level:"error",path:`${c}.on`,code:"RULE_TRIGGER",message:"a rule needs an event topic in `on`"}),o.when!==void 0)try{br(String(o.when));}catch(p){s.push({level:"error",path:`${c}.when`,code:"RULE_FORMULA",message:p.message});}if(!Array.isArray(o.do)||o.do.length===0){s.push({level:"error",path:`${c}.do`,code:"RULE_EFFECTS",message:"a rule needs at least one effect"});return}o.do.forEach((p,x)=>{let E=`${c}.do.${x}`,L=typeof p?.type=="string"?t.get(Mo,p.type):void 0;if(!L){s.push({level:"error",path:`${E}.type`,code:"EFFECT_UNKNOWN",message:`unknown effect "${String(p?.type)}"`});return}for(let O of L.required??[])p[O]===void 0&&s.push({level:"error",path:`${E}.${O}`,code:"EFFECT_PARAM",message:`effect "${L.id}" needs "${O}"`});for(let O of L.formulas??[]){let C=p[O];if(typeof C=="string")try{br(C);}catch(I){s.push({level:"error",path:`${E}.${O}`,code:"RULE_FORMULA",message:I.message});}}});});}function ta(e,t,r,s={}){let n=t.map(c=>({def:c,...c.when!==void 0?{when:br(c.when)}:{},effects:c.do.map(p=>({spec:p,def:r.require(Mo,p.type)})),hits:0,runs:0,lastRunAt:Number.NEGATIVE_INFINITY})),o=new Map;for(let c of n){let p=o.get(c.def.on)??[];p.push(c),o.set(c.def.on,p);}let a=[...o.entries()].map(([c,p])=>e.on(c,x=>{for(let E of p){if(E.def.once&&E.runs>0)continue;let L={event:x,vars:e.vars,tick:e.tick,time:e.time};if(E.when&&!E.when.bool(L)||(E.hits++,E.def.every!==void 0&&E.def.every>1&&E.hits%E.def.every!==0)||E.def.cooldown!==void 0&&e.time-E.lastRunAt<E.def.cooldown)continue;E.runs++,E.lastRunAt=e.time;let O={world:e,rule:E.def,event:x,scope:L,num:(C,I=0)=>typeof C=="number"||typeof C=="string"?ea(C,L,I):I};for(let C of E.effects)try{C.def.run(O,C.spec);}catch(I){s.onError?.(E.def,I);}}}));return ()=>a.forEach(c=>c())}var ra=e=>e.some(t=>t.level==="error");function us(e,t,r,s){let n={};for(let[o,a]of Object.entries(e))n[o]=a.default;if(!t)return n;for(let[o,a]of Object.entries(t)){let c=e[o],p=`${r}.${o}`;if(!c){s.push({level:"warning",path:p,code:"PARAM_UNKNOWN",message:`unknown parameter "${o}"`});continue}switch(c.type){case "number":{if(typeof a!="number"||!Number.isFinite(a)){s.push({level:"warning",path:p,code:"PARAM_TYPE",message:"expected a number, default used"});break}let x=c.integer?Math.round(a):a;c.min!==void 0&&x<c.min&&(x=c.min),c.max!==void 0&&x>c.max&&(x=c.max),x!==a&&s.push({level:"warning",path:p,code:"PARAM_CLAMPED",message:`${a} \u2192 ${x}`}),n[o]=x;break}case "enum":typeof a=="string"&&c.values.includes(a)?n[o]=a:s.push({level:"warning",path:p,code:"PARAM_ENUM",message:`not one of ${c.values.join(", ")}, default used`});break;case "boolean":typeof a=="boolean"?n[o]=a:s.push({level:"warning",path:p,code:"PARAM_TYPE",message:"expected true/false, default used"});break;case "string":if(typeof a=="string"){let x=c.maxLength??500;n[o]=a.length>x?a.slice(0,x):a,a.length>x&&s.push({level:"warning",path:p,code:"PARAM_CLAMPED",message:`cut to ${x} characters`});}else s.push({level:"warning",path:p,code:"PARAM_TYPE",message:"expected text, default used"});break}}return n}var ms=["phaser","three","dom"],Yr=Cr("block"),Jr=Cr("preset");var ac=["store","premium","character","inventory","lootboxes","boosts","leaderboard","rewards","quests","collections","craft","marketplace","deals","events","coop-events","season","pvp","mailbox","reward-window","idle"],xf=/^system:([a-z][a-z0-9-]*)$/,kf=new Set(["currency","item"]);function na(e,t,r,s){let n=new Set(e.map(p=>p.id)),o=new Set(t.map(p=>p.id)),a=new Map,c=new Map;r.forEach((p,x)=>{let E=`flows.${x}`;o.has(p.resource)||s.push({level:"error",path:`${E}.resource`,code:"FLOW_RESOURCE_UNKNOWN",message:`no resource "${p.resource}"`});let L=xf.exec(p.by);L?ac.includes(L[1])||s.push({level:"warning",path:`${E}.by`,code:"FLOW_SYSTEM_UNKNOWN",message:`"${p.by}" is not a platform system`}):n.has(p.by)||s.push({level:"error",path:`${E}.by`,code:"FLOW_BY_UNKNOWN",message:`"${p.by}" is neither a mode of the spec nor "system:<id>"`}),p.kind!=="source"&&p.kind!=="sink"&&s.push({level:"error",path:`${E}.kind`,code:"FLOW_KIND",message:'kind is "source" or "sink"'});let O=p.kind==="source"?a:c;O.set(p.resource,(O.get(p.resource)??0)+1);}),t.forEach((p,x)=>{let E=`resources.${x}`,L=a.get(p.id)??0,O=c.get(p.id)??0;L===0&&s.push({level:"error",path:E,code:"RESOURCE_NO_SOURCE",message:`nothing produces "${p.id}"`}),kf.has(p.kind)&&O===0&&s.push({level:"error",path:E,code:"RESOURCE_NO_SINK",message:`nothing spends "${p.id}"`});});}var G=$e("transform"),te=$e("visual"),sa=Object.freeze({background:"#1b2133",ground:"#273047",lane:"#313b56",primary:"#4fc3f7",secondary:"#ba68c8",danger:"#ef5350",coin:"#ffd54f",accent:"#66bb6a",text:"#ffffff",muted:"#9aa3b8",piece1:"#ef5350",piece2:"#42a5f5",piece3:"#66bb6a",piece4:"#ffd54f",piece5:"#ab47bc",piece6:"#ff8a3d",panel:"#2b3550"}),oa=/^#[0-9a-fA-F]{6}(?:[0-9a-fA-F]{2})?$/;function ia(e,t){let r=oa.test(e)?e:t[e]??sa[e]??t.text??"#ffffff";return oa.test(r)?r.slice(0,7):"#ffffff"}function aa(e){let t={...sa};for(let[r,s]of Object.entries(e??{}))typeof s=="string"&&oa.test(s)&&(t[r]=s);return t}var Tt="input",jt="view-resized",ys=Object.freeze({hero:{preset:"knight",races:["human"]},foe:{preset:"berserker",parts:{Hat:null,Offhand:null,Weapon:"weapon/battle_axe"},races:["orc"]},foe2:{preset:"crossbowman",parts:{Weapon:"weapon/broadsword"},races:["undead"]},boss:{preset:"dark_knight",races:["orc"]},helper:{preset:"camper",parts:{Weapon:null,Back:null,Glasses:null},races:["human","elf","dwarf"]},foe3:{preset:"crossbowman",races:["undead"]},foe4:{preset:"viking",parts:{Weapon:"weapon/warhammer"},races:["orc"]},foe5:{preset:"hunter",parts:{Hat:null,Back:null,Weapon:"weapon/dagger"},races:["undead"]},hero2:{preset:"crusader",races:["human"]},hero3:{preset:"archmage",races:["elf"]}}),la=Object.freeze({style:"default",cast:ys}),ca="fx";var Tn=Cr("asset-pack"),So=Cr("link"),vf=(e,t="en")=>e.names[t]??e.names.en??e.id;function $f(e,t,r){let s=[],n=r.get(So,t);if(!n)return s.push({level:"error",path:"link",code:"LINK_UNKNOWN",message:`no link "${t}"`}),{spec:e,systems:[],issues:s};let o=e.modes.find(c=>c.role==="core")??e.modes[0],a=o?r.get(Jr,o.preset)?.genre:void 0;return !a||!n.core.includes(a)?(s.push({level:"error",path:"link",code:"LINK_GENRE",message:`link "${t}" fits ${n.core.join(", ")}, not "${a??"?"}"`}),{spec:e,systems:[],issues:s}):{spec:n.apply(e),systems:n.systems,issues:s}}var Lo=1,cc=Object.freeze({window:"round",adMultiplier:3,vipMultiplier:5}),Mf={};function dc(e,t){let r={...e},s=r.v===void 0?1:r.v;if(typeof s!="number"||!Number.isInteger(s)||s<1)return t.push({level:"error",path:"v",code:"SPEC_VERSION",message:"v must be an integer \u2265 1"}),null;if(s>Lo)return t.push({level:"error",path:"v",code:"SPEC_TOO_NEW",message:`spec v${s} is newer than this kit (v${Lo})`}),null;for(;s<Lo;){let n=Mf[s];if(!n)return t.push({level:"error",path:"v",code:"SPEC_NO_MIGRATION",message:`no migration from v${s}`}),null;r=n(r),s++;}return r.v=Lo,r}var da=/^[a-z][a-z0-9_]*$/,Ef=/^#[0-9a-fA-F]{6}(?:[0-9a-fA-F]{2})?$/,Sf=/^[a-z]{2}(?:-[A-Z]{2})?$/,wf=/^[a-z][a-z0-9_.-]*$/,lc=["none","async","coop","pvp"],It=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),wo=e=>Array.isArray(e)?e:[];function Lf(e,t){let r=[];if(!It(e))return r.push({level:"error",path:"",code:"SPEC_SHAPE",message:"a spec must be an object"}),{ok:false,issues:r};let s=dc(e,r);if(!s)return {ok:false,issues:r};let n=s;ms.includes(n.engine)||r.push({level:"error",path:"engine",code:"SPEC_ENGINE",message:`engine is one of ${ms.join(", ")}`});let o=wo(n.modes);o.length===0&&r.push({level:"error",path:"modes",code:"SPEC_NO_MODES",message:"a game needs at least one mode"});let a=new Set,c=[];o.forEach((V,ce)=>{let oe=`modes.${ce}`;if(!It(V)){r.push({level:"error",path:oe,code:"MODE_SHAPE",message:"a mode must be an object"});return}typeof V.id!="string"||!da.test(V.id)?r.push({level:"error",path:`${oe}.id`,code:"MODE_ID",message:"mode id: snake_case, starts with a letter"}):a.has(V.id)?r.push({level:"error",path:`${oe}.id`,code:"MODE_DUPLICATE",message:`mode "${V.id}" is defined twice`}):a.add(V.id);let le=typeof V.preset=="string"?t.get(Jr,V.preset):void 0;if(!le){r.push({level:"error",path:`${oe}.preset`,code:"MODE_PRESET_UNKNOWN",message:`no preset "${String(V.preset)}"`});return}le.engine!==n.engine&&r.push({level:"error",path:`${oe}.preset`,code:"MODE_ENGINE",message:`preset "${le.id}" runs on ${le.engine}, the spec on ${String(n.engine)}`}),V.role!==void 0&&!["core","meta","embedded"].includes(V.role)&&r.push({level:"error",path:`${oe}.role`,code:"MODE_ROLE",message:"role is core, meta or embedded"});let Ae=us(le.params??{},It(V.params)?V.params:void 0,`${oe}.params`,r),xe={},we=new Set(le.blocks);for(let ke of le.blocks){let pe=t.get(Yr,ke);if(!pe){r.push({level:"error",path:`${oe}.preset`,code:"PRESET_BLOCK_UNKNOWN",message:`preset "${le.id}" uses unknown block "${ke}"`});continue}pe.engines&&!pe.engines.includes(le.engine)&&r.push({level:"error",path:`${oe}.preset`,code:"BLOCK_ENGINE",message:`block "${ke}" is not drawn by ${le.engine}`});for(let ze of pe.requires??[])we.has(ze)||r.push({level:"error",path:`${oe}.preset`,code:"BLOCK_REQUIRES",message:`block "${ke}" needs "${ze}" in the same preset`});let Te={};for(let[ze,Y]of Object.entries(le.blockParams?.[ke]??{})){let Le=pe.params?.[ze];if(typeof Y=="string"&&(Le?.type==="number"||Le?.type==="boolean"))try{let J=br(Y).eval({params:Ae});Te[ze]=Le.type==="number"?Number(J):!!J;}catch(J){r.push({level:"error",path:`${oe}.preset`,code:"PRESET_FORMULA",message:`preset "${le.id}", ${ke}.${ze}: ${J.message}`});}else Te[ze]=Y;}let Be={...Te,...It(V.blockParams)&&It(V.blockParams[ke])?V.blockParams[ke]:{}};xe[ke]=us(pe.params??{},Be,`${oe}.blockParams.${ke}`,r);}if(It(V.blockParams))for(let ke of Object.keys(V.blockParams))we.has(ke)||r.push({level:"warning",path:`${oe}.blockParams.${ke}`,code:"BLOCK_NOT_IN_PRESET",message:`preset "${le.id}" has no block "${ke}"`});let ge=[...le.rules??[],...wo(V.rules)];hs(ge,t,`${oe}.rules`,r),c.push({id:V.id,role:V.role??(ce===0?"core":"meta"),preset:le,params:Ae,blockParams:xe,rules:ge});}),o.length>0&&!o.some((V,ce)=>It(V)?(V.role??(ce===0?"core":"meta"))==="core":false)&&r.push({level:"error",path:"modes",code:"SPEC_NO_CORE",message:"one mode must be the core (what the player plays)"});let p=wo(n.resources),x=new Set;p.forEach((V,ce)=>{let oe=`resources.${ce}`;if(!It(V)||typeof V.id!="string"||!da.test(V.id)){r.push({level:"error",path:oe,code:"RESOURCE_ID",message:"resource id: snake_case, starts with a letter"});return}x.has(V.id)&&r.push({level:"error",path:`${oe}.id`,code:"RESOURCE_DUPLICATE",message:`resource "${V.id}" is defined twice`}),x.add(V.id),["currency","item","score","local"].includes(V.kind)||r.push({level:"error",path:`${oe}.kind`,code:"RESOURCE_KIND",message:"kind is currency, item, score or local"}),(V.kind==="currency"||V.kind==="item")&&V.ref!==void 0&&(typeof V.ref!="string"||V.ref.length===0)&&r.push({level:"error",path:`${oe}.ref`,code:"RESOURCE_REF",message:"ref is the engine currency or item id"});});let E=wo(n.flows);E.forEach((V,ce)=>{if(typeof V?.amount=="string"){let oe=Ji(V.amount);oe&&r.push({level:"error",path:`flows.${ce}.amount`,code:"FLOW_FORMULA",message:oe});}}),na(o.filter(It),p.filter(V=>It(V)&&typeof V.id=="string"),E.filter(It),r);let L=wo(n.rules);hs(L,t,"rules",r);let O={};if(n.vars!==void 0)if(!It(n.vars))r.push({level:"error",path:"vars",code:"VARS_SHAPE",message:"vars must be an object"});else for(let[V,ce]of Object.entries(n.vars))da.test(V)?typeof ce=="number"||typeof ce=="string"||typeof ce=="boolean"?O[V]=ce:r.push({level:"error",path:`vars.${V}`,code:"VAR_TYPE",message:"a var is a number, text or true/false"}):r.push({level:"error",path:`vars.${V}`,code:"VAR_NAME",message:"var name: snake_case"});let C=typeof n.assets=="string"&&n.assets?t.get(Tn,n.assets):void 0;if(n.assets!==void 0&&!C&&r.push({level:"warning",path:"assets",code:"ASSETS_UNKNOWN",message:`no asset pack "${String(n.assets)}"; the default look is used`}),n.palette!==void 0)if(!It(n.palette))r.push({level:"error",path:"palette",code:"PALETTE_SHAPE",message:"palette must be an object"});else for(let[V,ce]of Object.entries(n.palette))(typeof ce!="string"||!Ef.test(ce))&&r.push({level:"warning",path:`palette.${V}`,code:"PALETTE_COLOR",message:"a colour is #rrggbb or #rrggbbaa; ignored"});if(n.texts!==void 0)if(!It(n.texts))r.push({level:"error",path:"texts",code:"TEXTS_SHAPE",message:"texts must be an object"});else for(let[V,ce]of Object.entries(n.texts)){if(wf.test(V)||r.push({level:"error",path:`texts.${V}`,code:"TEXT_KEY",message:"text key: lower case, digits, _ . -"}),!It(ce)){r.push({level:"error",path:`texts.${V}`,code:"TEXT_SHAPE",message:"a text is { lang: text }"});continue}for(let[oe,le]of Object.entries(ce))(!Sf.test(oe)||typeof le!="string")&&r.push({level:"error",path:`texts.${V}.${oe}`,code:"TEXT_LANG",message:"language code like en or pt-BR, value text"});ce.en===void 0&&r.push({level:"warning",path:`texts.${V}`,code:"TEXT_NO_EN",message:"no English text: other languages fall back to it"});}let I={...cc};if(n.rewards!==void 0)if(!It(n.rewards))r.push({level:"error",path:"rewards",code:"REWARDS_SHAPE",message:"rewards must be an object"});else {let V=(oe,le,Ae)=>{let xe=n.rewards[oe];if(xe===void 0)return;if(typeof xe!="number"||!Number.isFinite(xe)){r.push({level:"warning",path:`rewards.${oe}`,code:"PARAM_TYPE",message:"expected a number, default used"});return}let we=Math.min(Math.max(xe,le),Ae);we!==xe&&r.push({level:"warning",path:`rewards.${oe}`,code:"PARAM_CLAMPED",message:`${xe} \u2192 ${we}`}),I[oe]=we;};V("adMultiplier",1,10),V("vipMultiplier",1,20);let ce=n.rewards.window;ce!==void 0&&(typeof ce=="string"&&/^[A-Za-z0-9_-]{1,64}$/.test(ce)?I.window=ce:r.push({level:"warning",path:"rewards.window",code:"PARAM_TYPE",message:"expected a window id, default used"}));}let K=n.multiplayer??"none";lc.includes(K)||r.push({level:"error",path:"multiplayer",code:"SPEC_MULTIPLAYER",message:`multiplayer is one of ${lc.join(", ")}`});let ne=!ra(r);return {ok:ne,issues:r,spec:n,...ne?{resolved:{spec:n,engine:n.engine,seed:typeof n.seed=="string"&&n.seed.length>0?n.seed:"game",modes:c,resources:p,flows:E,rules:L,vars:O,rewards:I,multiplayer:K,palette:aa({...C?.palette,...It(n.palette)?n.palette:{}}),texts:_f(C?.texts,It(n.texts)?n.texts:void 0),look:{style:C?C.style??C.id:la.style,cast:{...ys,...C?.cast}}}}:{}}}function _f(e,t){let r={};for(let s of [e,t])for(let[n,o]of Object.entries(s??{}))if(o&&typeof o=="object")for(let[a,c]of Object.entries(o))typeof c=="string"&&((r[n]??={})[a]=c);return r}function Rf(){let e=ds();return Eo(e),e}function Af(e,t,r,s={}){let n=e.modes.find(c=>c.id===t);if(!n)throw new Error(`game: no mode "${t}"`);let o=new $o({seed:`${e.seed}/${n.id}${s.salt!==void 0?`/${s.salt}`:""}`,vars:e.vars});for(let c of n.preset.blocks)r.require(Yr,c).setup?.({world:o,spec:e,mode:n,params:n.blockParams[c]??{},registry:r});let a=ta(o,[...n.rules,...e.rules],r,{...s.onRuleError?{onError:s.onRuleError}:{}});return o.emit("mode-started",{mode:n.id}),o.flushEvents(),{world:o,mode:n,stop:a}}var Df=(e,t=0,r=255)=>Math.min(r,Math.max(t,e)),fa=e=>{let t=/^#[0-9a-fA-F]{6}/.test(e)?e.slice(1,7):"ffffff";return [Number.parseInt(t.slice(0,2),16),Number.parseInt(t.slice(2,4),16),Number.parseInt(t.slice(4,6),16)]},Tf=(e,t,r)=>`#${[e,t,r].map(s=>Math.round(Df(s)).toString(16).padStart(2,"0")).join("")}`;function On(e,t,r){let s=fa(e),n=fa(t);return Tf(s[0]+(n[0]-s[0])*r,s[1]+(n[1]-s[1])*r,s[2]+(n[2]-s[2])*r)}var W=(e,t)=>On(e,"#000000",t),X=(e,t)=>On(e,"#ffffff",t),gs=e=>{let[t,r,s]=fa(e);return (t*.299+r*.587+s*.114)/255},fe=(e,t,r=false)=>`<linearGradient id="${e}" x1="0" y1="0" x2="${r?1:0}" y2="${r?0:1}">${t.map(([s,n,o])=>`<stop offset="${s}" stop-color="${n}"${o===void 0?"":` stop-opacity="${o}"`}/>`).join("")}</linearGradient>`,Fe=(e,t,r=.5,s=.5,n=.5)=>`<radialGradient id="${e}" cx="${r}" cy="${s}" r="${n}">${t.map(([o,a,c])=>`<stop offset="${o}" stop-color="${a}"${c===void 0?"":` stop-opacity="${c}"`}/>`).join("")}</radialGradient>`,ee=(...e)=>`<defs>${e.join("")}</defs>`,hn=e=>(Math.round(e*10)/10).toString(),Qe=(e,t,r,s,n=5,o=-Math.PI/2)=>{let a=[];for(let c=0;c<n*2;c++){let p=c%2===0?r:s,x=o+c*Math.PI/n;a.push(`${hn(e+Math.cos(x)*p)},${hn(t+Math.sin(x)*p)}`);}return a.join(" ")},Lt=(e,t,r,s,n=-Math.PI/2)=>{let o=[];for(let a=0;a<s;a++){let c=n+a*2*Math.PI/s;o.push(`${hn(e+Math.cos(c)*r)},${hn(t+Math.sin(c)*r)}`);}return o.join(" ")},_o=(e,t,r,s,n)=>{let o=[],a=s*4;for(let c=0;c<a;c++){let p=c/a*Math.PI*2,x=c%4<2?r:r-n;o.push(`${hn(e+Math.cos(p)*x)},${hn(t+Math.sin(p)*x)}`);}return `M${o.join("L")}Z`};function yr(e){let t=e>>>0||1;return ()=>(t=t*1664525+1013904223>>>0,t/4294967296)}var fc=e=>e==="cozy"?"#5b3b33":e==="sci-fi"?"#05070f":e==="post-apocalypse"?"#1a120c":"#1c1622",U=hn;var _t=(e,t,r,s,n=.28)=>`<ellipse cx="${e}" cy="${t}" rx="${r}" ry="${s}" fill="#000" opacity="${n}"/>`,Pr=(e,t=4,r=.55)=>`<path d="${e}" fill="none" stroke="#fff" stroke-width="${t}" stroke-linecap="round" opacity="${r}"/>`,Of={w:64,h:64,main:"coin",draw({main:e,ink:t,style:r}){let s=W(e,.25),n;return r==="sci-fi"?n=`<polygon points="${Lt(32,31,11,6)}" fill="none" stroke="${W(e,.45)}" stroke-width="3.5"/><circle cx="32" cy="31" r="3.5" fill="${W(e,.45)}"/>`:r==="cozy"?n=`<path d="M32 41 C22 34 19 29 22 25 C25 21 30 22 32 26 C34 22 39 21 42 25 C45 29 42 34 32 41Z" fill="${W(e,.35)}"/>`:r==="post-apocalypse"?n=`<path d="${_o(32,31,13,10,3)}" fill="${W(e,.4)}"/><circle cx="32" cy="31" r="5" fill="${e}"/>`:n=`<polygon points="${Qe(32,31,12,5.5)}" fill="${W(e,.35)}"/>`,ee(fe("g",[[0,X(e,.45)],[.55,e],[1,W(e,.2)]]))+`<circle cx="32" cy="35" r="26" fill="${W(e,.5)}" stroke="${t}" stroke-width="3"/><circle cx="32" cy="31" r="26" fill="url(#g)" stroke="${t}" stroke-width="3"/><circle cx="32" cy="31" r="19" fill="none" stroke="${s}" stroke-width="2.5"/>`+n+Pr("M15 24 A19 19 0 0 1 28 12")}},Cf={w:64,h:64,main:"accent",draw({main:e,ink:t}){return _t(32,59,14,3.5)+`<polygon points="32,4 52,22 44,57 20,57 12,22" fill="${e}" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><polygon points="32,4 12,22 26,24" fill="${X(e,.5)}"/><polygon points="32,4 26,24 38,24" fill="${X(e,.3)}"/><polygon points="32,4 38,24 52,22" fill="${W(e,.1)}"/><polygon points="12,22 26,24 20,57" fill="${X(e,.15)}"/><polygon points="52,22 38,24 44,57" fill="${W(e,.3)}"/><polygon points="26,24 38,24 44,57 20,57" fill="${e}"/>`+Pr("M22 18 L28 10",3,.8)}},Pf={w:64,h:64,main:"danger",draw({main:e,ink:t}){return ee(fe("g",[[0,X(e,.3)],[1,W(e,.25)]]))+`<path d="M32 56 C12 42 5 32 8 21 C11 10 25 8 32 19 C39 8 53 10 56 21 C59 32 52 42 32 56Z" fill="url(#g)" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/>`+Pr("M16 22 C17 16 22 14 26 17",4,.7)}},If={w:100,h:100,draw({style:e,ink:t,c:r}){if(e==="sci-fi"){let n=r("primary");return ee(fe("m",[[0,"#5d6f96"],[1,"#2a3452"]]),Fe("o",[[0,X(n,.6)],[.5,n,.9],[1,n,0]]))+_t(50,95,40,5)+`<rect x="12" y="18" width="76" height="74" rx="10" fill="url(#m)" stroke="${t}" stroke-width="4"/><rect x="20" y="26" width="60" height="10" rx="3" fill="#1a2238"/><rect x="22" y="28" width="56" height="6" rx="2" fill="${n}" opacity="0.85"/><circle cx="50" cy="62" r="20" fill="url(#o)"/><circle cx="50" cy="62" r="11" fill="${X(n,.3)}" stroke="${t}" stroke-width="3"/><circle cx="22" cy="84" r="3" fill="#9fb2d8"/><circle cx="78" cy="84" r="3" fill="#9fb2d8"/>`}if(e==="cozy"){let n="#f2c862";return ee(fe("h",[[0,X(n,.25)],[1,W(n,.2)]]))+_t(50,94,42,5)+`<rect x="8" y="26" width="84" height="66" rx="22" fill="url(#h)" stroke="${t}" stroke-width="4"/>`+[36,50,64,78].map(o=>`<path d="M18 ${o} Q50 ${o-5} 82 ${o}" stroke="${W(n,.25)}" stroke-width="2.5" fill="none"/>`).join("")+`<rect x="30" y="24" width="7" height="70" fill="#c0563d" stroke="${t}" stroke-width="2"/><rect x="63" y="24" width="7" height="70" fill="#c0563d" stroke="${t}" stroke-width="2"/>`+Pr("M20 38 Q30 32 44 33",4,.5)}if(e==="post-apocalypse"){let n="#9a4a26";return ee(fe("r",[[0,"#6a2e18"],[.35,X(n,.15)],[.7,n],[1,"#4a2010"]],true))+_t(50,95,34,5)+`<rect x="18" y="10" width="64" height="84" rx="8" fill="url(#r)" stroke="${t}" stroke-width="4"/><rect x="16" y="28" width="68" height="6" fill="#5a2814" stroke="${t}" stroke-width="2"/><rect x="16" y="68" width="68" height="6" fill="#5a2814" stroke="${t}" stroke-width="2"/><polygon points="50,40 62,60 38,60" fill="#e8c23a" stroke="${t}" stroke-width="2.5" stroke-linejoin="round"/><rect x="48.5" y="45" width="3" height="8" fill="${t}"/><circle cx="50" cy="56.5" r="1.8" fill="${t}"/><path d="M24 82 q6 -6 10 2 q4 6 9 0" stroke="#3a1608" stroke-width="3" fill="none" opacity="0.6"/>`}if(e==="fantasy"){let n="#9a6234";return ee(fe("w",[[0,"#5a3418"],[.3,X(n,.15)],[.7,n],[1,"#4a2a12"]],true))+_t(50,95,36,5)+`<path d="M24 10 Q14 52 24 94 L76 94 Q86 52 76 10Z" fill="url(#w)" stroke="${t}" stroke-width="4" stroke-linejoin="round"/>`+[38,50,62].map(o=>`<path d="M${o} 12 Q${o+(o-50)*.25} 52 ${o} 92" stroke="${W(n,.35)}" stroke-width="2" fill="none"/>`).join("")+[24,76].map(o=>`<path d="M19 ${o} Q50 ${o+4} 81 ${o}" stroke="#4d525c" stroke-width="7" fill="none"/><path d="M19 ${o-2} Q50 ${o+2} 81 ${o-2}" stroke="#8d939e" stroke-width="2" fill="none"/>`).join("")+Pr("M28 30 Q26 50 28 66",4,.35)}let s="#b07a44";return _t(50,95,42,5)+`<rect x="10" y="14" width="80" height="80" rx="6" fill="${s}" stroke="${t}" stroke-width="4"/><rect x="18" y="22" width="64" height="64" fill="${W(s,.12)}" stroke="${W(s,.4)}" stroke-width="3"/><path d="M20 24 L80 84 M80 24 L20 84" stroke="${X(s,.15)}" stroke-width="9"/><path d="M20 24 L80 84 M80 24 L20 84" stroke="${W(s,.4)}" stroke-width="2" fill="none" opacity="0.5"/>`+[18,82].flatMap(n=>[22,86].map(o=>`<circle cx="${n}" cy="${o}" r="3" fill="#6b6f78"/>`)).join("")}},zf={w:100,h:60,draw({style:e,ink:t,c:r}){let s=[18,50,82];if(e==="sci-fi"){let o=r("danger");return ee(fe("l",[[0,X(o,.6),.95],[1,o,.2]]))+s.map(a=>`<polygon points="${a-9},52 ${a},6 ${a+9},52" fill="url(#l)"/>`).join("")+s.map(a=>`<line x1="${a}" y1="10" x2="${a}" y2="50" stroke="#fff" stroke-width="2" opacity="0.8"/>`).join("")+`<rect x="2" y="48" width="96" height="11" rx="3" fill="#2a3452" stroke="${t}" stroke-width="3"/>`+s.map(a=>`<circle cx="${a}" cy="53" r="3" fill="${o}"/>`).join("")}if(e==="cozy")return `<path d="M6 58 C2 40 14 26 26 30 C30 14 48 10 54 24 C64 12 86 18 84 34 C98 36 100 52 94 58Z" fill="#6cbf5c" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/>`+[[18,36],[36,24],[56,22],[74,30],[88,44],[28,48],[62,44]].map(([a,c])=>`<polygon points="${a-3},${c+2} ${a},${c-7} ${a+3},${c+2}" fill="#fff4e6" stroke="${t}" stroke-width="1.5"/>`).join("")+'<circle cx="44" cy="40" r="4" fill="#ff8fab"/><circle cx="72" cy="46" r="3.5" fill="#ff8fab"/>';let n=e==="post-apocalypse"?"#8a6a52":"#b9c1cd";return ee(fe("s",[[0,X(n,.4)],[.5,n],[1,W(n,.45)]],true))+s.map(o=>`<polygon points="${o-14},50 ${o},4 ${o+14},50" fill="url(#s)" stroke="${t}" stroke-width="3" stroke-linejoin="round"/>`).join("")+(e==="post-apocalypse"?'<path d="M2 40 q8 -10 16 0 q8 10 16 0 q8 -10 16 0 q8 10 16 0 q8 -10 16 0 q8 10 16 0" stroke="#5a4a3a" stroke-width="3" fill="none"/>':"")+`<rect x="2" y="47" width="96" height="12" rx="3" fill="${e==="post-apocalypse"?"#4a3a2a":"#5a4636"}" stroke="${t}" stroke-width="3"/>`}},Nf={w:60,h:180,main:"accent",draw({style:e,ink:t,main:r,c:s}){if(e==="sci-fi"){let a=s("primary");return ee(Fe("b",[[0,"#fff"],[.4,a],[1,a,0]]))+`<rect x="24" y="30" width="10" height="146" rx="3" fill="#4a5a80" stroke="${t}" stroke-width="3"/><circle cx="29" cy="24" r="22" fill="url(#b)"/><circle cx="29" cy="24" r="8" fill="#fff" stroke="${t}" stroke-width="2"/><rect x="34" y="50" width="24" height="34" rx="3" fill="${r}" opacity="0.75" stroke="${X(r,.5)}" stroke-width="2"/><rect x="14" y="166" width="30" height="12" rx="3" fill="#2a3452" stroke="${t}" stroke-width="3"/>`}let n=e==="post-apocalypse"?"#7a6a5a":e==="cozy"?"#e8d8c8":"#c8a060",o=e==="post-apocalypse"?`<path d="M30 22 L58 28 L52 40 L58 52 L40 50 L44 60 L30 58Z" fill="${r}" stroke="${t}" stroke-width="3" stroke-linejoin="round"/>`:e==="cozy"?`<path d="M30 22 Q46 16 58 26 Q50 40 58 54 Q44 46 30 56Z" fill="${r}" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><path d="M44 44 C38 40 37 37 39 35 C41 33 43 34 44 36 C45 34 47 33 49 35 C51 37 50 40 44 44Z" fill="#fff"/>`:`<path d="M30 22 L58 22 L58 62 L44 54 L30 62Z" fill="${r}" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><polygon points="${Qe(44,38,8,3.5)}" fill="${s("coin")}"/>`;return _t(30,176,18,3.5)+`<rect x="25" y="14" width="8" height="162" rx="3" fill="${n}" stroke="${t}" stroke-width="3"/>`+o+`<circle cx="29" cy="12" r="7" fill="${s("coin")}" stroke="${t}" stroke-width="3"/>`}},pc={w:64,h:32,main:"primary",draw({style:e,main:t,c:r}){return e==="sci-fi"?ee(fe("t",[[0,t,0],[1,t,.9]],true))+`<rect x="2" y="11" width="44" height="10" rx="5" fill="url(#t)"/><rect x="22" y="9" width="40" height="14" rx="7" fill="${t}"/><rect x="28" y="13" width="30" height="6" rx="3" fill="#fff"/>`:e==="post-apocalypse"?ee(fe("t",[[0,r("coin"),0],[1,r("coin"),.8]],true))+'<rect x="0" y="13" width="44" height="6" rx="3" fill="url(#t)"/><path d="M40 10 L54 10 Q62 16 54 22 L40 22Z" fill="#c9a24a" stroke="#3a2a12" stroke-width="2"/>':e==="cozy"?ee(fe("t",[[0,t,0],[1,t,.7]],true))+`<rect x="0" y="12" width="40" height="8" rx="4" fill="url(#t)"/><polygon points="${Qe(46,16,14,6)}" fill="${r("coin")}" stroke="#5b3b33" stroke-width="2" stroke-linejoin="round"/>`:ee(fe("t",[[0,t,0],[1,t,.85]],true),Fe("o",[[0,"#fff"],[.45,X(t,.4)],[1,t,0]]))+'<path d="M2 16 Q20 8 40 10 L40 22 Q20 24 2 16Z" fill="url(#t)"/><circle cx="46" cy="16" r="15" fill="url(#o)"/><circle cx="46" cy="16" r="6" fill="#fff"/>'}},Wf=e=>({w:100,h:100,main:`piece${e}`,draw({main:t,ink:r}){let s=X(t,.55),n=X(t,.2),o=W(t,.32),a=ee(fe("g",[[0,X(t,.35)],[1,W(t,.25)]])),c=`stroke="${r}" stroke-width="4" stroke-linejoin="round"`,p;switch(e){case 1:p=`<circle cx="50" cy="52" r="40" fill="url(#g)" ${c}/><polygon points="${Lt(50,52,22,8,-Math.PI/8)}" fill="${n}"/><polygon points="${Lt(50,52,22,8,-Math.PI/8).split(" ").slice(5,8).join(" ")} 50,52" fill="${s}"/><polygon points="${Lt(50,52,22,8,-Math.PI/8).split(" ").slice(1,4).join(" ")} 50,52" fill="${o}"/>`;break;case 2:p=`<path d="M50 8 C66 30 84 46 84 64 C84 82 68 92 50 92 C32 92 16 82 16 64 C16 46 34 30 50 8Z" fill="url(#g)" ${c}/><path d="M50 24 C60 40 70 50 70 64 C70 76 60 82 50 82Z" fill="${o}" opacity="0.6"/><path d="M50 24 C40 40 30 50 30 64 C30 76 40 82 50 82Z" fill="${n}" opacity="0.7"/>`;break;case 3:p=`<polygon points="28,10 72,10 90,28 90,72 72,90 28,90 10,72 10,28" fill="url(#g)" ${c}/><polygon points="32,24 68,24 76,32 76,68 68,76 32,76 24,68 24,32" fill="${n}"/><polygon points="28,10 72,10 68,24 32,24" fill="${s}"/><polygon points="90,28 90,72 76,68 76,32" fill="${o}"/><polygon points="36,34 64,34 64,66 36,66" fill="${t}"/>`;break;case 4:p=`<polygon points="${Qe(50,54,44,20)}" fill="url(#g)" ${c}/><polygon points="${Qe(50,54,22,10)}" fill="${n}"/><polygon points="50,10 50,54 30,44" fill="${s}" opacity="0.7"/>`;break;case 5:p=`<polygon points="50,6 90,50 50,94 10,50" fill="url(#g)" ${c}/><polygon points="50,6 10,50 50,50" fill="${s}"/><polygon points="50,6 90,50 50,50" fill="${n}"/><polygon points="10,50 50,94 50,50" fill="${t}"/><polygon points="90,50 50,94 50,50" fill="${o}"/><polygon points="50,30 64,50 50,70 36,50" fill="${X(t,.35)}"/>`;break;default:p=`<polygon points="${Lt(50,50,42,6)}" fill="url(#g)" ${c}/><polygon points="${Lt(50,50,24,6)}" fill="${n}"/><polygon points="${Lt(50,50,42,6).split(" ").slice(4,6).join(" ")} ${Lt(50,50,42,6).split(" ")[0]} 50,50" fill="${s}" opacity="0.6"/><polygon points="${Lt(50,50,42,6).split(" ").slice(1,4).join(" ")} 50,50" fill="${o}" opacity="0.55"/>`;}return a+_t(50,94,30,4,.22)+p+Pr("M28 30 Q32 22 40 20",5,.75)}}),bs=e=>`<path d="M24 86 Q50 72 76 86 Q76 94 50 94 Q24 94 24 86Z" fill="#7a5032" stroke="${e}" stroke-width="3"/>`,Cn=(e,t,r,s,n,o)=>`<path transform="translate(${e} ${t}) rotate(${r}) scale(${s})" d="M0 0 C6 -10 18 -10 22 0 C18 8 6 8 0 0Z" fill="${n}" stroke="${o}" stroke-width="${U(2.4/s)}"/>`,Ro=(e,t,r,s,n)=>`<circle cx="${e-r*.55}" cy="${t+r*.2}" r="${r*.7}" fill="${W(s,.1)}" stroke="${n}" stroke-width="3"/><circle cx="${e+r*.55}" cy="${t+r*.2}" r="${r*.7}" fill="${W(s,.1)}" stroke="${n}" stroke-width="3"/><circle cx="${e}" cy="${t-r*.15}" r="${r*.85}" fill="${s}" stroke="${n}" stroke-width="3"/><circle cx="${e-r*.3}" cy="${t-r*.4}" r="${r*.3}" fill="${X(s,.3)}"/>`,pa=(e,t=50)=>`<path d="M45 92 L47 ${t} L53 ${t} L55 92Z" fill="#8a5a32" stroke="${e}" stroke-width="3" stroke-linejoin="round"/>`;function jf(e,t){let{ink:r}=t,s=t.style==="cozy"?"#7fd36e":"#58b04a",n=t.c("primary");switch(e){case 1:return _t(50,84,18,4)+`<ellipse cx="50" cy="64" rx="15" ry="20" fill="#b07a44" stroke="${r}" stroke-width="3.5"/>`+Pr("M44 54 Q46 48 50 47",3.5,.6);case 2:return bs(r)+`<path d="M50 84 Q48 66 50 56" stroke="${W(s,.2)}" stroke-width="5" fill="none" stroke-linecap="round"/>`+Cn(50,60,-150,1,s,r)+Cn(50,60,-30,1,s,r);case 3:return bs(r)+`<path d="M50 84 Q47 60 50 38" stroke="${W(s,.2)}" stroke-width="5" fill="none" stroke-linecap="round"/>`+Cn(50,66,-160,1.1,s,r)+Cn(50,62,-20,1.1,s,r)+Cn(50,44,-130,.9,X(s,.15),r)+Cn(50,42,-50,.9,X(s,.15),r);case 4:return bs(r)+Ro(50,62,26,s,r);case 5:return bs(r)+Ro(50,62,28,s,r)+[[34,56],[56,44],[66,64],[46,70]].map(([o,a])=>`<polygon points="${Qe(o,a,7,3.5,5)}" fill="${n}" stroke="${r}" stroke-width="1.5"/><circle cx="${o}" cy="${a}" r="2" fill="#fff6c0"/>`).join("");case 6:return _t(50,93,26,4)+pa(r,52)+Ro(50,40,32,s,r);case 7:return _t(50,93,28,4)+pa(r,54)+Ro(50,40,34,W(s,.05),r)+[[34,36],[58,26],[66,46],[44,52],[52,38]].map(([o,a])=>`<circle cx="${o}" cy="${a}" r="5.5" fill="${t.c("danger")}" stroke="${r}" stroke-width="2"/><circle cx="${o-1.5}" cy="${a-1.5}" r="1.6" fill="#fff" opacity="0.8"/>`).join("");default:{let o=t.c("coin");return _t(50,93,30,4)+pa(r,54)+Ro(50,38,36,o,r)+[[22,18],[80,22],[74,64],[24,60],[50,6]].map(([a,c])=>`<polygon points="${Qe(a,c,6,2,4)}" fill="#fff"/>`).join("")}}}function Hf(e,t){let{ink:r}=t,s=t.style==="post-apocalypse"?"#9a8a72":"#a9b8d6",n=t.style==="post-apocalypse"?t.c("coin"):t.c("primary"),o=ee(fe("m",[[0,X(s,.35)],[1,W(s,.35)]]));switch(e){case 1:return o+_t(50,88,16,4)+`<rect x="44" y="34" width="12" height="50" rx="2" fill="url(#m)" stroke="${r}" stroke-width="3"/>`+[44,54,64,74].map(a=>`<line x1="44" y1="${a}" x2="56" y2="${a-4}" stroke="${W(s,.45)}" stroke-width="2"/>`).join("")+`<rect x="32" y="22" width="36" height="14" rx="5" fill="url(#m)" stroke="${r}" stroke-width="3"/><line x1="42" y1="29" x2="58" y2="29" stroke="${r}" stroke-width="3"/>`;case 2:return o+_t(50,86,26,4)+`<polygon points="${Lt(50,54,30,6)}" fill="url(#m)" stroke="${r}" stroke-width="3.5"/><circle cx="50" cy="54" r="12" fill="${W(s,.5)}" stroke="${r}" stroke-width="3"/>`+Pr("M30 42 L42 34",3.5,.6);case 3:return o+_t(50,90,30,4)+`<path d="${_o(50,52,36,10,8)}" fill="url(#m)" stroke="${r}" stroke-width="3"/><circle cx="50" cy="52" r="12" fill="${W(s,.5)}" stroke="${r}" stroke-width="3"/>`;case 4:return o+_t(50,90,34,4)+`<path d="${_o(36,60,26,9,6)}" fill="url(#m)" stroke="${r}" stroke-width="3"/><path d="${_o(66,38,22,8,6)}" fill="${X(s,.1)}" stroke="${r}" stroke-width="3"/><circle cx="36" cy="60" r="8" fill="${n}" stroke="${r}" stroke-width="2.5"/><circle cx="66" cy="38" r="7" fill="${W(s,.5)}" stroke="${r}" stroke-width="2.5"/>`;case 5:return o+_t(50,90,34,4)+[26,38,50,62,74].map(a=>`<rect x="${a-2}" y="12" width="4" height="12" fill="#c9a24a"/><rect x="${a-2}" y="76" width="4" height="12" fill="#c9a24a"/>`).join("")+`<rect x="18" y="22" width="64" height="56" rx="6" fill="#2a3040" stroke="${r}" stroke-width="3.5"/><rect x="32" y="36" width="36" height="28" rx="3" fill="${n}" opacity="0.85"/><path d="M36 50 H46 V42 H54 V58 H64" stroke="#fff" stroke-width="2.5" fill="none"/>`;case 6:return o+_t(50,92,22,4)+`<rect x="28" y="20" width="44" height="70" rx="8" fill="url(#m)" stroke="${r}" stroke-width="3.5"/><rect x="40" y="10" width="20" height="12" rx="3" fill="${W(s,.3)}" stroke="${r}" stroke-width="3"/><rect x="34" y="30" width="32" height="52" rx="4" fill="#1d2230"/>`+[0,1,2].map(a=>`<rect x="38" y="${66-a*15}" width="24" height="11" rx="2" fill="${n}" opacity="${.95-a*.25}"/>`).join("");case 7:return o+_t(50,94,32,4)+`<line x1="50" y1="6" x2="50" y2="20" stroke="${r}" stroke-width="3"/><circle cx="50" cy="6" r="5" fill="${t.c("danger")}" stroke="${r}" stroke-width="2"/><rect x="16" y="20" width="68" height="60" rx="16" fill="url(#m)" stroke="${r}" stroke-width="3.5"/><rect x="26" y="34" width="48" height="24" rx="10" fill="#1d2230"/><circle cx="40" cy="46" r="7" fill="${n}"/><circle cx="60" cy="46" r="7" fill="${n}"/><rect x="38" y="64" width="24" height="6" rx="3" fill="${W(s,.5)}"/><rect x="6" y="38" width="10" height="22" rx="4" fill="${W(s,.2)}" stroke="${r}" stroke-width="3"/><rect x="84" y="38" width="10" height="22" rx="4" fill="${W(s,.2)}" stroke="${r}" stroke-width="3"/>`;default:return o+ee(Fe("f",[[0,"#fff"],[.4,t.c("coin")],[1,t.c("danger"),0]]))+`<ellipse cx="50" cy="88" rx="16" ry="12" fill="url(#f)"/><path d="M50 4 C66 18 70 40 66 70 L34 70 C30 40 34 18 50 4Z" fill="url(#m)" stroke="${r}" stroke-width="3.5"/><circle cx="50" cy="34" r="9" fill="${n}" stroke="${r}" stroke-width="3"/><path d="M34 54 L20 76 L34 72Z M66 54 L80 76 L66 72Z" fill="${t.c("danger")}" stroke="${r}" stroke-width="3" stroke-linejoin="round"/>`}}var Bf=e=>({w:100,h:100,draw(t){return t.style==="sci-fi"||t.style==="post-apocalypse"?Hf(e,t):jf(e,t)}}),Vf={w:100,h:100,main:"accent",draw({style:e,ink:t,c:r}){let s=e==="sci-fi"?"#4a5a80":e==="post-apocalypse"?"#5e6a3a":e==="cozy"?"#e09a5a":"#9a5a2c",n=e==="sci-fi"?r("primary"):e==="post-apocalypse"?"#8a8a7a":r("coin");return ee(fe("b",[[0,X(s,.2)],[1,W(s,.3)]]),fe("l",[[0,X(s,.35)],[1,s]]))+_t(50,92,40,5)+`<rect x="10" y="44" width="80" height="46" rx="6" fill="url(#b)" stroke="${t}" stroke-width="4"/><path d="M10 46 L10 34 Q50 4 90 34 L90 46Z" fill="url(#l)" stroke="${t}" stroke-width="4" stroke-linejoin="round"/><rect x="10" y="42" width="80" height="8" fill="${n}" stroke="${t}" stroke-width="3"/><rect x="20" y="18" width="8" height="72" fill="${n}" opacity="0.9"/><rect x="72" y="18" width="8" height="72" fill="${n}" opacity="0.9"/><rect x="40" y="44" width="20" height="22" rx="4" fill="${n}" stroke="${t}" stroke-width="3"/><circle cx="50" cy="54" r="3.5" fill="${t}"/>`+Pr("M18 32 Q34 18 48 16",4,.45)}},hc={coin:Of,crystal:Cf,heart:Pf,obstacle:If,spike:zf,flag:Nf,shot:pc,bolt:pc,chest:Vf,...Object.fromEntries([1,2,3,4,5,6].map(e=>[`gem${e}`,Wf(e)])),...Object.fromEntries([1,2,3,4,5,6,7,8].map(e=>[`item${e}`,Bf(e)]))};var en=(e,t,r)=>U(Math.min(e,t)*r),Gf={w:0,h:0,exact:true,main:"panel",draw({w:e,h:t,main:r,ink:s}){let n=Math.max(2,Math.min(Math.min(e,t)*.035,7)),o=U(Math.min(Math.min(e,t)*.14,24)),a=gs(r)>.6;return ee(fe("p",[[0,X(r,a?.3:.12)],[1,W(r,a?.06:.25)]]))+`<rect x="${U(n/2)}" y="${U(n*1.5)}" width="${U(e-n)}" height="${U(t-n*2)}" rx="${o}" fill="#000" opacity="0.25"/><rect x="${U(n/2)}" y="${U(n/2)}" width="${U(e-n)}" height="${U(t-n*2)}" rx="${o}" fill="url(#p)" stroke="${a?W(r,.3):s}" stroke-width="${U(n)}"/><rect x="${U(n*2)}" y="${U(n*2)}" width="${U(e-n*4)}" height="${U(Math.max(1,t*.12))}" rx="${en(e,t,.06)}" fill="#fff" opacity="0.1"/>`}},Ff={w:0,h:0,exact:true,main:"panel",draw({w:e,h:t,main:r,ink:s,c:n}){let o=Math.max(3,e*.03),a=n("coin");return ee(fe("p",[[0,X(r,.18)],[1,W(r,.3)]]),fe("g",[[0,X(a,.35)],[1,W(a,.25)]]))+`<rect x="${U(o)}" y="${U(o*2)}" width="${U(e-o*2)}" height="${U(t-o*2.5)}" rx="${en(e,t,.1)}" fill="#000" opacity="0.35"/><rect x="${U(o)}" y="${U(o)}" width="${U(e-o*2)}" height="${U(t-o*2.5)}" rx="${en(e,t,.1)}" fill="url(#g)" stroke="${s}" stroke-width="${U(o*.8)}"/><rect x="${U(o*2.4)}" y="${U(o*2.4)}" width="${U(e-o*4.8)}" height="${U(t-o*5.3)}" rx="${en(e,t,.07)}" fill="url(#p)"/><circle cx="${U(e/2)}" cy="${U(t*.3)}" r="${U(e*.2)}" fill="${a}" opacity="0.18"/>`}},Uf={w:0,h:0,exact:true,main:"accent",draw({w:e,h:t,main:r,ink:s}){let n=Math.max(2,Math.min(e,t)*.06),o=t*.12;return ee(fe("b",[[0,X(r,.3)],[1,W(r,.1)]]))+`<rect x="${U(n/2)}" y="${U(o)}" width="${U(e-n)}" height="${U(t-o-n/2)}" rx="${en(e,t,.3)}" fill="${W(r,.45)}" stroke="${s}" stroke-width="${U(n)}"/><rect x="${U(n/2)}" y="${U(n/2)}" width="${U(e-n)}" height="${U(t-o-n/2)}" rx="${en(e,t,.3)}" fill="url(#b)" stroke="${s}" stroke-width="${U(n)}"/><rect x="${U(e*.12)}" y="${U(t*.12)}" width="${U(e*.76)}" height="${U(t*.16)}" rx="${U(t*.08)}" fill="#fff" opacity="0.35"/>`}},Xf={w:0,h:0,exact:true,main:"ground",draw({w:e,h:t,main:r}){let s=gs(r)>.55;return ee(fe("c",[[0,W(r,s?.12:.3)],[1,X(r,s?.1:.06)]]))+`<rect x="1.5" y="1.5" width="${U(e-3)}" height="${U(t-3)}" rx="${en(e,t,.16)}" fill="url(#c)"/><rect x="1.5" y="1.5" width="${U(e-3)}" height="${U(t-3)}" rx="${en(e,t,.16)}" fill="none" stroke="#000" stroke-opacity="0.18" stroke-width="2"/>`}},qf={w:0,h:0,exact:true,main:"panel",draw({w:e,h:t,main:r,ink:s}){let n=t*.16,o=Math.max(2,Math.min(e,t)*.05),c=gs(r)>.6?X(r,.4):X(r,.85);return `<path d="M${U(o)} ${U(o)} H${U(e-o)} V${U(t-n-o)} H${U(e*.58)} L${U(e*.5)} ${U(t-o)} L${U(e*.42)} ${U(t-n-o)} H${U(o)}Z" fill="${c}" stroke="${s}" stroke-width="${U(o)}" stroke-linejoin="round"/>`}},Kf={w:100,h:100,draw(){let e="#1c1622",t="#ffffff",r="#d9dde8";return `<ellipse cx="60" cy="96" rx="26" ry="4" fill="#000" opacity="0.18"/><path d="M30 52 L30 14 Q30 5 39 5 Q48 5 48 14 L48 44 Q50 38 57 38 Q64 38 65 45 Q67 40 73 40 Q80 41 80 49 Q82 45 86 46 Q92 48 91 56 L89 76 Q86 92 70 94 L48 94 Q36 93 31 82 L17 64 Q13 58 18 54 Q23 50 28 55 Z" fill="${t}" stroke="${e}" stroke-width="4" stroke-linejoin="round"/><path d="M48 44 L48 58 M65 45 L65 58 M80 49 L80 60" stroke="${e}" stroke-width="3" stroke-linecap="round"/><path d="M34 86 Q44 92 58 91" stroke="${r}" stroke-width="5" fill="none" stroke-linecap="round"/><path d="M35 14 Q36 9 40 9" stroke="${r}" stroke-width="3" fill="none" stroke-linecap="round"/>`}},Zf={w:100,h:100,main:"accent",draw({main:e,ink:t}){return ee(fe("p",[[0,X(e,.35)],[1,W(e,.15)]]))+`<circle cx="50" cy="54" r="44" fill="${W(e,.45)}"/><circle cx="50" cy="50" r="44" fill="url(#p)" stroke="${t}" stroke-width="4"/><circle cx="50" cy="50" r="36" fill="none" stroke="#fff" stroke-opacity="0.35" stroke-width="3"/><path d="M41 30 L72 50 L41 70 Z" fill="#fff" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/><path d="M22 38 Q28 22 44 16" stroke="#fff" stroke-width="5" fill="none" stroke-linecap="round" opacity="0.55"/>`}},uc={panel:Gf,card:Ff,button:Uf,cell:Xf,ticket:qf,hand:Kf,play:Zf};var xr=(e,t=4,r=.55)=>`<path d="${e}" fill="none" stroke="#fff" stroke-width="${t}" stroke-linecap="round" opacity="${r}"/>`,lr=(e,t)=>({w:64,h:64,main:e,draw:({main:r,ink:s})=>t(r,s)}),Qf=lr("primary",(e,t)=>ee(fe("b",[[0,X(e,.55)],[1,W(e,.15)]]))+`<path d="M32 4 C50 10 58 28 52 46 C48 34 40 26 30 24 C28 16 29 9 32 4Z" fill="url(#b)" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><path d="M32 60 C14 54 6 36 12 18 C16 30 24 38 34 40 C36 48 35 55 32 60Z" fill="url(#b)" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><circle cx="32" cy="32" r="8" fill="${W(e,.35)}" stroke="${t}" stroke-width="3"/><circle cx="32" cy="32" r="3" fill="${X(e,.6)}"/>`+xr("M36 9 C44 13 49 20 51 28",3,.7)),Yf=lr("secondary",(e,t)=>ee(Fe("a",[[0,X(e,.7),.95],[.55,e,.55],[1,e,0]]))+`<circle cx="32" cy="32" r="29" fill="url(#a)"/><circle cx="32" cy="32" r="20" fill="none" stroke="${X(e,.4)}" stroke-width="3" stroke-dasharray="7 5"/><circle cx="32" cy="32" r="10" fill="${X(e,.5)}" stroke="${t}" stroke-width="2.5"/>`),Jf={w:100,h:100,main:"secondary",draw:({main:e})=>ee(Fe("a",[[0,e,.05],[.7,e,.18],[.94,X(e,.3),.5],[1,X(e,.4),0]]))+`<circle cx="50" cy="50" r="50" fill="url(#a)"/><circle cx="50" cy="50" r="46" fill="none" stroke="${X(e,.5)}" stroke-width="1.5" stroke-dasharray="6 6" opacity="0.7"/>`},e0=lr("accent",(e,t)=>ee(fe("g",[[0,X(e,.4)],[1,W(e,.25)]]))+`<path d="M8 14 C22 10 34 18 38 30 C46 32 54 42 56 54 C48 50 40 46 32 44 C28 32 20 24 8 14Z" fill="url(#g)" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/><path d="M14 16 C24 16 31 22 34 32" fill="none" stroke="${W(e,.35)}" stroke-width="2.5"/>`+xr("M14 15 C22 14 28 18 31 24",3,.7)),t0=lr("primary",(e,t)=>ee(fe("l",[[0,X(e,.7)],[1,e]]))+`<polygon points="36,3 12,36 28,36 22,61 52,24 35,24 44,3" fill="url(#l)" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/>`+xr("M33 9 L20 30",3,.75)),r0={w:100,h:20,main:"primary",draw:({main:e})=>`<polyline points="0,10 14,4 26,15 40,5 54,14 66,4 80,15 92,6 100,10" fill="none" stroke="${X(e,.4)}" stroke-width="7" stroke-linejoin="round" opacity="0.55"/><polyline points="0,10 14,4 26,15 40,5 54,14 66,4 80,15 92,6 100,10" fill="none" stroke="#fff" stroke-width="2.5" stroke-linejoin="round"/>`},n0=lr("piece6",(e,t)=>ee(fe("d",[[0,X(e,.45)],[1,W(e,.2)]]))+`<rect x="4" y="18" width="20" height="5" rx="2.5" fill="${W(e,.4)}" stroke="${t}" stroke-width="2"/><rect x="40" y="18" width="20" height="5" rx="2.5" fill="${W(e,.4)}" stroke="${t}" stroke-width="2"/><path d="M14 23 L22 32 M50 23 L42 32" stroke="${t}" stroke-width="3"/><ellipse cx="32" cy="38" rx="17" ry="13" fill="url(#d)" stroke="${t}" stroke-width="3"/><circle cx="32" cy="38" r="6" fill="#16223a" stroke="${t}" stroke-width="2"/><circle cx="33.5" cy="36.5" r="2" fill="#7fe7ff"/>`+xr("M21 32 C24 28 28 27 31 27",3,.6)),o0=lr("danger",(e,t)=>ee(fe("f",[[0,X(e,.35)],[1,W(e,.2)]]))+`<path d="M14 26 C14 18 20 14 26 15 L46 15 C52 15 54 20 54 25 L54 40 C54 50 46 58 36 58 L28 58 C20 58 14 52 14 44Z" fill="url(#f)" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/>`+[24,34,44].map(r=>`<path d="M${r} 16 L${r} 30" stroke="${W(e,.4)}" stroke-width="2.5"/>`).join("")+`<path d="M14 34 C22 30 30 32 32 38" fill="none" stroke="${t}" stroke-width="3"/>`+xr("M20 20 C22 18 26 18 30 18",3,.6)),s0=lr("primary",(e,t)=>`<rect x="12" y="5" width="40" height="7" rx="3" fill="${W(e,.3)}" stroke="${t}" stroke-width="3"/><rect x="12" y="52" width="40" height="7" rx="3" fill="${W(e,.3)}" stroke="${t}" stroke-width="3"/><path d="M17 12 C17 26 30 28 30 32 C30 36 17 38 17 52 L47 52 C47 38 34 36 34 32 C34 28 47 26 47 12Z" fill="${X(e,.75)}" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><path d="M22 49 C24 42 30 40 32 40 C34 40 40 42 42 49Z" fill="${e}"/><path d="M24 16 L40 16 C38 22 34 24 32 26 C30 24 26 22 24 16Z" fill="${e}"/>`),i0=lr("accent",(e,t)=>ee(fe("b",[[0,X(e,.35)],[1,W(e,.25)]]))+`<path d="M18 6 L38 6 L38 34 L54 40 C58 42 58 50 54 52 L14 52 C12 52 11 50 12 48 L18 34Z" fill="url(#b)" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/><rect x="12" y="52" width="46" height="6" rx="3" fill="${W(e,.45)}" stroke="${t}" stroke-width="3"/><path d="M6 22 L14 22 M3 30 L13 30 M7 38 L13 38" stroke="${X(e,.5)}" stroke-width="3" stroke-linecap="round"/>`+xr("M23 11 L23 30",3,.6)),a0=lr("muted",(e,t)=>ee(fe("s",[[0,X(e,.45)],[1,W(e,.3)]]))+`<path d="M32 4 L54 12 C54 34 46 50 32 60 C18 50 10 34 10 12Z" fill="url(#s)" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/><path d="M32 12 L46 17 C46 32 41 43 32 51Z" fill="${X(e,.25)}" opacity="0.6"/>`+xr("M17 16 C17 26 19 34 23 40",3,.55)),l0=lr("danger",(e,t)=>`<path d="M10 8 L24 8 L24 34 C24 40 28 44 32 44 C36 44 40 40 40 34 L40 8 L54 8 L54 34 C54 48 44 58 32 58 C20 58 10 48 10 34Z" fill="${e}" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/><rect x="10" y="8" width="14" height="10" fill="#e8edf5" stroke="${t}" stroke-width="3"/><rect x="40" y="8" width="14" height="10" fill="#e8edf5" stroke="${t}" stroke-width="3"/>`+xr("M15 26 C15 38 20 46 26 50",3,.55)),c0=lr("accent",(e,t)=>[[32,18],[46,32],[32,46],[18,32]].map(([r,s])=>`<circle cx="${r}" cy="${s}" r="12" fill="${e}" stroke="${t}" stroke-width="3"/>`).join("")+`<circle cx="32" cy="32" r="7" fill="${X(e,.3)}"/><path d="M36 40 C40 50 44 56 50 60" fill="none" stroke="${t}" stroke-width="3.5" stroke-linecap="round"/>`+xr("M26 12 C28 9 32 8 35 9",3,.6)),d0=lr("accent",(e,t)=>ee(fe("p",[[0,X(e,.4)],[1,W(e,.2)]]))+`<rect x="25" y="4" width="14" height="8" rx="2" fill="#b07a44" stroke="${t}" stroke-width="3"/><path d="M26 12 L38 12 L38 22 C48 26 54 34 54 42 C54 52 44 60 32 60 C20 60 10 52 10 42 C10 34 16 26 26 22Z" fill="#e8f2ff" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/><path d="M13 40 C20 36 44 36 51 40 C51 50 43 57 32 57 C21 57 13 50 13 40Z" fill="url(#p)"/>`+xr("M18 32 C20 28 24 26 27 25",3,.7)),f0=lr("muted",(e,t)=>ee(Fe("b",[[0,"#6a7080"],[1,"#1c1f28"]],.35,.35,.7))+`<circle cx="30" cy="38" r="22" fill="url(#b)" stroke="${t}" stroke-width="3.5"/><rect x="34" y="12" width="12" height="10" rx="2" transform="rotate(35 40 17)" fill="#4a4f5c" stroke="${t}" stroke-width="3"/><path d="M44 12 C48 6 54 6 56 10" fill="none" stroke="#b07a44" stroke-width="3"/><polygon points="${Qe(57,9,7,3,6)}" fill="#ffd54f" stroke="${t}" stroke-width="1.5"/>`+xr("M18 30 C20 25 24 22 28 21",4,.5)+`<circle cx="30" cy="38" r="22" fill="${e}" opacity="0.08"/>`),p0={w:40,h:40,main:"danger",draw:({main:e,ink:t})=>ee(Fe("o",[[0,"#fff"],[.45,X(e,.3)],[1,e]]))+`<circle cx="20" cy="20" r="17" fill="${e}" opacity="0.35"/><circle cx="20" cy="20" r="11" fill="url(#o)" stroke="${t}" stroke-width="2.5"/>`},h0=lr("text",(e,t)=>`<path d="M32 6 C18 6 9 16 9 28 C9 36 13 41 18 44 L18 54 C18 57 20 58 22 58 L42 58 C44 58 46 57 46 54 L46 44 C51 41 55 36 55 28 C55 16 46 6 32 6Z" fill="${X(e,.1)}" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/><circle cx="22" cy="30" r="7" fill="${t}"/><circle cx="42" cy="30" r="7" fill="${t}"/><path d="M32 38 L28 45 L36 45Z" fill="${t}"/>`+[26,32,38].map(r=>`<path d="M${r} 50 L${r} 58" stroke="${t}" stroke-width="2.5"/>`).join("")),u0={w:64,h:64,main:"coin",draw:({main:e,ink:t})=>`<polygon points="${Qe(32,32,29,17,10)}" fill="${X(e,.25)}" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><polygon points="${Lt(32,32,12,6)}" fill="${e}"/>`},mc={blade:Qf,aura:Yf,aura_field:Jf,boomerang:e0,lightning:t0,zap:r0,drone:n0,fist:o0,hourglass:s0,boot:i0,shield:a0,magnet:l0,clover:c0,potion:d0,bomb:f0,orb:p0,skull:h0,burst:u0};var ha=(e,t=4,r=.5)=>`<path d="${e}" fill="none" stroke="#fff" stroke-width="${t}" stroke-linecap="round" opacity="${r}"/>`,xs=(e,t)=>e==="sci-fi"?{body:"#4f5f86",trim:t("primary"),dark:"#232c47"}:e==="cozy"?{body:"#d9935a",trim:"#f6d38a",dark:"#7a4a2e"}:e==="post-apocalypse"?{body:"#8a6a52",trim:"#c9a14a",dark:"#3d2f24"}:{body:"#9a6b43",trim:t("accent"),dark:"#4a3322"},m0={w:100,h:60,draw({style:e,ink:t,c:r}){let s=xs(e,r),n=r("danger");return ee(fe("b",[[0,X(s.trim,.4)],[1,W(s.trim,.15)]]))+`<ellipse cx="50" cy="57" rx="44" ry="3" fill="#000" opacity="0.25"/><rect x="10" y="14" width="9" height="44" rx="3" fill="${s.body}" stroke="${t}" stroke-width="3"/><rect x="81" y="14" width="9" height="44" rx="3" fill="${s.body}" stroke="${t}" stroke-width="3"/><rect x="4" y="10" width="92" height="17" rx="5" fill="url(#b)" stroke="${t}" stroke-width="3.5"/>`+[16,38,60,82].map(o=>`<path d="M${o} 11 L${o+10} 11 L${o+2} 26 L${o-8} 26Z" fill="${n}" opacity="0.9"/>`).join("")+`<rect x="4" y="10" width="92" height="17" rx="5" fill="none" stroke="${t}" stroke-width="3.5"/><rect x="14" y="32" width="72" height="8" rx="3" fill="${W(s.trim,.1)}" stroke="${t}" stroke-width="2.5"/>`+ha("M12 15 L88 15",2.5,.55)}},y0={w:120,h:40,draw({style:e,ink:t,c:r}){let s=xs(e,r);return ee(Fe("p",[[0,"#000000",1],[.7,"#0b0d14",.95],[1,W(s.dark,.2),.9]]))+`<path d="M8 20 C10 6 32 3 60 4 C90 3 112 7 112 20 C112 33 90 37 60 36 C30 37 8 34 8 20Z" fill="${s.dark}" stroke="${t}" stroke-width="3"/><path d="M16 21 C18 11 36 9 60 9 C86 9 104 12 104 21 C104 30 86 32 60 32 C34 32 16 30 16 21Z" fill="url(#p)"/><path d="M20 12 L28 16 L34 10 L44 15 L52 9 L62 14 L72 9 L82 14 L92 10 L100 15" fill="none" stroke="${X(s.dark,.25)}" stroke-width="2.5" stroke-linejoin="round"/>`}},g0={w:300,h:100,draw({style:e,ink:t,c:r}){let s=xs(e,r),n=r("secondary");return ee(fe("w",[[0,X(n,.35)],[1,W(n,.3)]]))+`<rect x="4" y="8" width="292" height="72" rx="10" fill="url(#w)" stroke="${t}" stroke-width="4"/><rect x="4" y="8" width="292" height="12" rx="6" fill="${X(n,.45)}" stroke="${t}" stroke-width="3"/>`+[30,100,170,240].map(o=>`<rect x="${o}" y="30" width="40" height="24" rx="4" fill="${X(s.trim,.55)}" stroke="${t}" stroke-width="3"/>`).join("")+`<rect x="4" y="64" width="292" height="10" fill="${W(n,.4)}"/>`+[40,90,210,260].map(o=>`<circle cx="${o}" cy="84" r="12" fill="${s.dark}" stroke="${t}" stroke-width="3.5"/><circle cx="${o}" cy="84" r="4" fill="${s.trim}"/>`).join("")+ha("M14 26 L120 26",3,.4)}},b0={w:140,h:100,draw({style:e,ink:t,c:r}){let s=xs(e,r);return ee(fe("r",[[0,X(s.trim,.3)],[1,W(s.trim,.25)]]))+`<path d="M4 96 L136 8 L136 96Z" fill="${s.body}" stroke="${t}" stroke-width="4" stroke-linejoin="round"/><path d="M4 96 L136 8 L136 20 L22 96Z" fill="url(#r)" stroke="${t}" stroke-width="3" stroke-linejoin="round"/>`+[0,1,2].map(n=>{let o=60+n*22,a=70-n*15;return `<path d="M${o-8} ${a+6} L${o} ${a-4} L${o+8} ${a+6}" fill="none" stroke="#fff" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" opacity="0.8"/>`}).join("")}},x0={w:100,h:100,draw({style:e,ink:t,c:r}){let s=e==="sci-fi"?"#7c86a8":e==="cozy"?"#b8a99a":"#8f8a82",n=e==="cozy"?"#7ccf6a":e==="sci-fi"?r("primary"):"#6b8f4a";return ee(fe("s",[[0,X(s,.35)],[1,W(s,.35)]]))+`<ellipse cx="50" cy="95" rx="42" ry="5" fill="#000" opacity="0.28"/><path d="M10 92 C4 70 14 44 30 32 C40 14 66 10 80 26 C96 40 98 70 90 92Z" fill="url(#s)" stroke="${t}" stroke-width="4" stroke-linejoin="round"/><path d="M34 50 L46 62 M62 40 L70 54 M28 74 L40 70" stroke="${W(s,.45)}" stroke-width="3" stroke-linecap="round"/><path d="M30 34 C40 26 52 24 62 28" fill="none" stroke="${n}" stroke-width="6" stroke-linecap="round" opacity="0.85"/>`+ha("M24 48 C28 38 36 32 44 30",4,.45)}},k0={w:100,h:30,draw:()=>ee(Fe("d",[[0,"#000000",.8],[.7,"#000000",.5],[1,"#000000",0]]))+'<ellipse cx="50" cy="15" rx="50" ry="15" fill="url(#d)"/>'},v0={w:60,h:300,draw({ink:e,c:t}){let r="#ffffff",s="#1b1d24",n=[];for(let o=0;o<14;o++)for(let a=0;a<2;a++)n.push(`<rect x="${16+a*14}" y="${18+o*18}" width="14" height="18" fill="${(o+a)%2===0?r:s}"/>`);return `<rect x="10" y="10" width="40" height="270" rx="4" fill="${s}" stroke="${e}" stroke-width="4"/>`+n.join("")+`<rect x="10" y="10" width="40" height="270" rx="4" fill="none" stroke="${e}" stroke-width="4"/><rect x="4" y="276" width="52" height="20" rx="5" fill="${t("accent")}" stroke="${e}" stroke-width="3.5"/><circle cx="30" cy="8" r="7" fill="${t("coin")}" stroke="${e}" stroke-width="3"/>`}},$0={w:64,h:64,main:"coin",draw:({main:e,ink:t})=>ee(Fe("c",[[0,X(e,.5)],[.7,e],[1,W(e,.2)]]))+`<circle cx="24" cy="36" r="18" fill="url(#c)" stroke="${t}" stroke-width="3.5"/><circle cx="40" cy="26" r="18" fill="url(#c)" stroke="${t}" stroke-width="3.5"/><circle cx="40" cy="26" r="11" fill="none" stroke="${W(e,.25)}" stroke-width="2.5"/><rect x="30" y="40" width="30" height="20" rx="7" fill="${W(e,.55)}" stroke="${t}" stroke-width="3"/><path d="M36 45 L43 55 M43 45 L36 55" stroke="#fff" stroke-width="3.2" stroke-linecap="round"/><path d="M47 47 C48 43 55 43 55 47 C55 50 47 53 47 55 L55 55" fill="none" stroke="#fff" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>`},M0={w:64,h:64,main:"secondary",draw:({main:e,ink:t})=>ee(fe("g",[[0,X(e,.6)],[1,W(e,.15)]]))+`<path d="M32 40 C22 22 10 14 4 14 C6 26 10 40 20 48 C10 48 8 52 6 56 C18 58 28 54 32 48Z" fill="url(#g)" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><path d="M32 40 C42 22 54 14 60 14 C58 26 54 40 44 48 C54 48 56 52 58 56 C46 58 36 54 32 48Z" fill="url(#g)" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><path d="M12 22 C16 30 20 36 26 40 M52 22 C48 30 44 36 38 40" fill="none" stroke="${X(e,.7)}" stroke-width="2.5" stroke-linecap="round"/><circle cx="32" cy="44" r="5" fill="${X(e,.4)}" stroke="${t}" stroke-width="2.5"/>`},yc={hurdle:m0,pit:y0,wagon:g0,ramp:b0,rock:x0,shadow:k0,finish:v0,coin2x:$0,wing:M0};var ua=(e,t=4,r=.55)=>`<path d="${e}" fill="none" stroke="#fff" stroke-width="${t}" stroke-linecap="round" opacity="${r}"/>`,E0={w:100,h:100,main:"coin",draw:({main:e,ink:t})=>ee(Fe("g",[[0,X(e,.6),.75],[.6,e,.25],[1,e,0]]),fe("s",[[0,X(e,.55)],[1,W(e,.25)]]))+`<circle cx="50" cy="52" r="48" fill="url(#g)"/><polygon points="${Qe(50,54,40,18)}" fill="url(#s)" stroke="${t}" stroke-width="4.5" stroke-linejoin="round"/><polygon points="${Qe(50,54,22,10)}" fill="${X(e,.45)}" opacity="0.7"/>`+ua("M38 32 L46 22",4,.75)},S0={w:64,h:64,main:"coin",draw:({main:e,ink:t})=>ee(fe("k",[[0,X(e,.45)],[1,W(e,.25)]]))+`<circle cx="20" cy="22" r="14" fill="url(#k)" stroke="${t}" stroke-width="3.5"/><circle cx="20" cy="22" r="5.5" fill="${W(e,.5)}"/><path d="M29 31 L54 56 M44 46 L50 40 M50 52 L56 46" stroke="${t}" stroke-width="9" stroke-linecap="round"/><path d="M29 31 L54 56 M44 46 L50 40 M50 52 L56 46" stroke="url(#k)" stroke-width="4.5" stroke-linecap="round"/>`+ua("M12 18 C13 13 16 11 20 10",3,.7)},w0={w:80,h:60,main:"accent",draw:({main:e,ink:t})=>ee(fe("p",[[0,X(e,.4)],[1,W(e,.2)]]))+`<rect x="14" y="50" width="52" height="8" rx="3" fill="#5a6070" stroke="${t}" stroke-width="3"/><path d="M24 50 L56 44 L24 38 L56 32 L24 26 L56 20" fill="none" stroke="${t}" stroke-width="7" stroke-linejoin="round"/><path d="M24 50 L56 44 L24 38 L56 32 L24 26 L56 20" fill="none" stroke="#c9d1dc" stroke-width="3.5" stroke-linejoin="round"/><rect x="6" y="6" width="68" height="14" rx="6" fill="url(#p)" stroke="${t}" stroke-width="3.5"/>`+ua("M14 10 L60 10",2.5,.6)},gc={bigstar:E0,key:S0,spring:w0};var ks=(e,t=4,r=.5)=>`<path d="${e}" fill="none" stroke="#fff" stroke-width="${t}" stroke-linecap="round" opacity="${r}"/>`,Ir=e=>e==="sci-fi"?{stone:"#5d6f96",wood:"#2f3a5c",metal:"#8fa3c8"}:e==="cozy"?{stone:"#f1e2cf",wood:"#c98b5a",metal:"#9aa3b0"}:e==="post-apocalypse"?{stone:"#8a7a62",wood:"#5e4a36",metal:"#7d7466"}:{stone:"#aeb0b8",wood:"#8a5a34",metal:"#6a7080"},ma=e=>78-e*12,vs='<ellipse cx="50" cy="123" rx="38" ry="7" fill="#000" opacity="0.28"/>';function bc(e,t,r,s,n){let o="";for(let a=r+10;a<116;a+=11){o+=`<line x1="${e+2}" y1="${a}" x2="${e+t-2}" y2="${a}" stroke="${W(s,.25)}" stroke-width="2"/>`;for(let c=1;c<3;c++){let p=e+t*c/3+((a-r)/11%2?6:0);o+=`<line x1="${p}" y1="${a}" x2="${p}" y2="${a+11}" stroke="${W(s,.25)}" stroke-width="2"/>`;}}return ee(fe("s",[[0,X(s,.25)],[1,W(s,.22)]],true))+`<rect x="${e}" y="${r}" width="${t}" height="${118-r}" fill="url(#s)" stroke="${n}" stroke-width="3.5"/>`+o+`<path d="M43 118 L43 105 A7 7 0 0 1 57 105 L57 118Z" fill="#3a2a1e" stroke="${n}" stroke-width="2.5"/>`}function L0(e,t,r){let{style:s,ink:n,c:o}=e,a=Ir(s),c=ma(t)-(r?8:0),p=o(r==="sniper"?"danger":r==="ranger"?"coin":"accent"),x=bc(28,44,c+18,a.stone,n),E=`<rect x="20" y="${c+8}" width="60" height="12" rx="2" fill="${a.wood}" stroke="${n}" stroke-width="3"/>`+[26,38,50,62,74].map(K=>`<rect x="${K-2}" y="${c-6}" width="4" height="15" fill="${X(a.wood,.15)}" stroke="${n}" stroke-width="1.5"/>`).join("")+`<rect x="20" y="${c-8}" width="60" height="5" rx="2" fill="${X(a.wood,.2)}" stroke="${n}" stroke-width="2.5"/>`,L=t>=2?`<polygon points="14,${c-8} 50,${c-36} 86,${c-8}" fill="${p}" stroke="${n}" stroke-width="3.5" stroke-linejoin="round"/><polygon points="14,${c-8} 50,${c-36} 38,${c-8}" fill="${X(p,.25)}"/>`:"",O=t>=3?`<line x1="50" y1="${c-36}" x2="50" y2="${c-54}" stroke="${n}" stroke-width="3"/><path d="M50 ${c-54} L70 ${c-48} L50 ${c-42}Z" fill="${o("coin")}" stroke="${n}" stroke-width="2"/>`:"",C=(K,ne,V=1)=>`<path d="M${K} ${ne-12*V} Q${K+9*V} ${ne} ${K} ${ne+12*V}" fill="none" stroke="${a.wood}" stroke-width="${3.5*V}" stroke-linecap="round"/><line x1="${K}" y1="${ne-12*V}" x2="${K}" y2="${ne+12*V}" stroke="#eee" stroke-width="1.5"/>`,I=C(66,c-2);return r==="ranger"&&(I=C(30,c-2)+C(68,c-2)),r==="sniper"&&(I=`<rect x="44" y="${c-6}" width="44" height="6" rx="2" fill="${a.metal}" stroke="${n}" stroke-width="2.5"/><rect x="56" y="${c-13}" width="14" height="6" rx="2" fill="${W(a.metal,.3)}" stroke="${n}" stroke-width="2"/>`),vs+x+E+I+L+O+ks(`M24 ${c+11} L44 ${c+11}`,2.5,.45)}function _0(e,t,r){let{style:s,ink:n,c:o}=e,a=Ir(s),c=ma(t)+14-(r?6:0),p=ee(fe("b",[[0,X(a.stone,.3)],[1,W(a.stone,.25)]],true),fe("m",[[0,X(a.metal,.35)],[1,W(a.metal,.35)]]))+`<path d="M20 118 L24 ${c} L76 ${c} L80 118Z" fill="url(#b)" stroke="${n}" stroke-width="3.5" stroke-linejoin="round"/>`+[0,1,2].map(ne=>`<rect x="${22+ne*20}" y="${c-9}" width="14" height="11" fill="${a.stone}" stroke="${n}" stroke-width="2.5"/>`).join("")+(t>=2?`<rect x="22" y="${c+14}" width="56" height="7" fill="${W(a.stone,.2)}" stroke="${n}" stroke-width="2"/>`:"")+(t>=3?`<rect x="22" y="${c+30}" width="56" height="7" fill="${o("coin")}" stroke="${n}" stroke-width="2"/>`:""),x=r==="bombard"?1.45:1+t*.08,E=34*x,L=13*x,O=`<g transform="rotate(-28 50 ${c-4})"><rect x="46" y="${c-4-L/2}" width="${E}" height="${L}" rx="${L/3}" fill="url(#m)" stroke="${n}" stroke-width="3"/><rect x="${46+E-7}" y="${c-4-L/2-2}" width="8" height="${L+4}" rx="2" fill="${W(a.metal,.3)}" stroke="${n}" stroke-width="2.5"/></g><circle cx="50" cy="${c-4}" r="${9*x}" fill="${W(a.metal,.2)}" stroke="${n}" stroke-width="3"/>`,C=44+E,I=r==="flamer"?`<g transform="rotate(-28 50 ${c-4})"><path d="M${C} ${c-16} C${C+14} ${c-22} ${C+30} ${c-10} ${C+22} ${c-4} C${C+30} ${c+2} ${C+14} ${c+14} ${C} ${c+8}Z" fill="#ff7a1a" stroke="${n}" stroke-width="2.5" stroke-linejoin="round"/><path d="M${C+2} ${c-9} C${C+12} ${c-12} ${C+18} ${c-6} ${C+13} ${c-3} C${C+18} ${c} ${C+10} ${c+6} ${C+2} ${c+2}Z" fill="#ffd34a"/></g>`:"",K=r==="bombard"?`<polygon points="${Qe(50,c+24,8,3.5)}" fill="${o("danger")}" stroke="${n}" stroke-width="2"/>`:"";return vs+p+O+I+K+ks(`M28 ${c+4} L28 ${c+40}`,3,.4)}function R0(e,t,r){let{style:s,ink:n,c:o}=e,a=Ir(s),c=64-t*6-(r?4:0),p=r==="storm"?o("coin"):r==="arcane"?X(o("secondary"),.2):o("secondary"),x=bc(32,36,c,a.stone,n)+`<rect x="44" y="${c+16}" width="12" height="16" rx="6" fill="${p}" stroke="${n}" stroke-width="2.5" opacity="0.9"/>`,E=c-28,L=`<polygon points="26,${c+2} 50,${E} 74,${c+2}" fill="${o("secondary")}" stroke="${n}" stroke-width="3.5" stroke-linejoin="round"/><polygon points="26,${c+2} 50,${E} 42,${c+2}" fill="${X(o("secondary"),.25)}"/>`,O=7+t*1.3+(r==="arcane"?3:0),C=Math.max(O+6+(r==="arcane"?8:0),E-O*.5),I=ee(Fe("o",[[0,"#ffffff",1],[.45,p,.95],[1,p,.3]]))+`<circle cx="50" cy="${C}" r="${O+7}" fill="${p}" opacity="0.25"/><circle cx="50" cy="${C}" r="${O}" fill="url(#o)" stroke="${n}" stroke-width="2.5"/>`,K=r==="storm"?[-1,1].map(ne=>`<path d="M${50+ne*(O+3)} ${C-6} L${50+ne*(O+10)} ${C} L${50+ne*(O+5)} ${C+2} L${50+ne*(O+13)} ${C+10}" fill="none" stroke="${o("coin")}" stroke-width="3" stroke-linejoin="round"/>`).join(""):r==="arcane"?`<circle cx="50" cy="${C}" r="${O+11}" fill="none" stroke="${p}" stroke-width="2.5" stroke-dasharray="5 4"/>`:"";return vs+x+L+I+K}function A0(e,t,r){let{style:s,ink:n,c:o}=e,a=Ir(s),c=ma(t)+10-(r?6:0),p=r==="glacier"?W(o("primary"),.15):X(o("primary"),.35),x=ee(fe("p",[[0,X(a.stone,.25)],[1,W(a.stone,.25)]],true),fe("i",[[0,"#ffffff"],[.5,p],[1,W(p,.25)]]))+`<path d="M24 118 L28 ${c+18} L72 ${c+18} L76 118Z" fill="url(#p)" stroke="${n}" stroke-width="3.5" stroke-linejoin="round"/>`,E=(C,I,K,ne)=>`<g transform="rotate(${ne} ${C} ${c+20})"><polygon points="${C-K},${c+20} ${C-K*.8},${c+20-I*.75} ${C},${c+20-I} ${C+K*.8},${c+20-I*.75} ${C+K},${c+20}" fill="url(#i)" stroke="${n}" stroke-width="2.5" stroke-linejoin="round"/><line x1="${C}" y1="${c+20-I}" x2="${C}" y2="${c+18}" stroke="#fff" stroke-width="1.5" opacity="0.6"/></g>`,L=E(50,38+t*6,10,0);t>=2&&(L=E(36,26+t*3,7,-14)+E(64,26+t*3,7,14)+L),t>=3&&(L=E(28,20,5,-26)+E(72,20,5,26)+L),r==="glacier"&&(L+=E(50,70,15,0));let O=r==="blizzard"?[0,1,2,3,4].map(C=>`<polygon points="${Qe(22+C*14,c-30+C%2*12,5,2,6)}" fill="#fff" stroke="${n}" stroke-width="1.2"/>`).join(""):"";return vs+x+L+O}var D0={archer:L0,cannon:_0,mage:R0,frost:A0},Rt=(e,t,r="")=>({w:100,h:130,draw:s=>D0[e](s,t,r)}),T0={w:100,h:64,draw({style:e,ink:t,c:r}){let s=Ir(e),n=Array.from({length:10},(o,a)=>{let c=a/10*Math.PI*2;return `<ellipse cx="${(50+Math.cos(c)*38).toFixed(1)}" cy="${(34+Math.sin(c)*20).toFixed(1)}" rx="9" ry="6" fill="${a%2?s.stone:X(s.stone,.15)}" stroke="${t}" stroke-width="2.5"/>`}).join("");return `<ellipse cx="50" cy="34" rx="40" ry="22" fill="${W(s.stone,.45)}" opacity="0.55"/>`+n+`<line x1="78" y1="30" x2="78" y2="6" stroke="${t}" stroke-width="2.5"/><path d="M78 6 L92 10 L78 15Z" fill="${r("coin")}" stroke="${t}" stroke-width="1.5"/>`}},O0={w:100,h:100,draw({style:e,ink:t,c:r}){let s=Ir(e),n=a=>`<rect x="${a}" y="22" width="22" height="72" fill="${s.stone}" stroke="${t}" stroke-width="3"/>`+[0,1].map(c=>`<rect x="${a+c*13}" y="13" width="9" height="11" fill="${s.stone}" stroke="${t}" stroke-width="2.5"/>`).join("")+`<polygon points="${a-3},22 ${a+11},2 ${a+25},22" fill="${r("danger")}" stroke="${t}" stroke-width="3" stroke-linejoin="round"/>`,o="";for(let a=38;a<=62;a+=6)o+=`<line x1="${a}" y1="52" x2="${a}" y2="94" stroke="${W(s.metal,.3)}" stroke-width="3"/>`;return `<ellipse cx="50" cy="95" rx="46" ry="5" fill="#000" opacity="0.28"/><rect x="22" y="36" width="56" height="58" fill="${X(s.stone,.1)}" stroke="${t}" stroke-width="3.5"/><path d="M34 94 L34 60 A16 16 0 0 1 66 60 L66 94Z" fill="#241a14" stroke="${t}" stroke-width="3"/>`+o+n(8)+n(70)+`<rect x="44" y="40" width="12" height="9" fill="${r("coin")}" stroke="${t}" stroke-width="2"/>`}},C0={w:100,h:90,draw({style:e,ink:t}){let r=Ir(e);return `<path d="M6 86 C6 40 26 10 50 10 C74 10 94 40 94 86Z" fill="${W(r.stone,.15)}" stroke="${t}" stroke-width="4" stroke-linejoin="round"/><path d="M24 86 C24 52 36 30 50 30 C64 30 76 52 76 86Z" fill="#120c10" stroke="${t}" stroke-width="3"/><circle cx="42" cy="58" r="3" fill="#ff5a3a"/><circle cx="56" cy="58" r="3" fill="#ff5a3a"/>`}},P0={w:100,h:130,draw({style:e,ink:t,c:r}){let s=Ir(e),n=e==="post-apocalypse"?"#6b6a3a":e==="sci-fi"?r("secondary"):e==="cozy"?"#6fcf6a":"#3f8f3a";return e==="post-apocalypse"?`<ellipse cx="50" cy="124" rx="26" ry="5" fill="#000" opacity="0.28"/><path d="M46 124 L48 60 L30 40 M48 70 L68 46 M48 84 L32 74" fill="none" stroke="${s.wood}" stroke-width="8" stroke-linecap="round"/><path d="M46 124 L48 60" stroke="${t}" stroke-width="2" opacity="0.4"/>`:ee(Fe("l",[[0,X(n,.35),1],[1,W(n,.2),1]],.4,.35,.65))+`<ellipse cx="50" cy="124" rx="30" ry="6" fill="#000" opacity="0.28"/><rect x="42" y="78" width="16" height="46" rx="4" fill="${s.wood}" stroke="${t}" stroke-width="3"/>`+(e==="sci-fi"?`<polygon points="${Lt(50,50,36,6)}" fill="url(#l)" stroke="${t}" stroke-width="3.5"/>`:`<circle cx="34" cy="62" r="24" fill="url(#l)" stroke="${t}" stroke-width="3.5"/><circle cx="66" cy="62" r="24" fill="url(#l)" stroke="${t}" stroke-width="3.5"/><circle cx="50" cy="38" r="28" fill="url(#l)" stroke="${t}" stroke-width="3.5"/>`)+ks("M36 26 C42 20 50 18 56 20",4,.4)}},I0={w:100,h:70,draw({style:e,ink:t,c:r}){let s=e==="post-apocalypse"?"#7a6a3a":e==="sci-fi"?r("secondary"):e==="cozy"?"#7fd87a":"#4a9a3e";return `<ellipse cx="50" cy="64" rx="40" ry="5" fill="#000" opacity="0.25"/><circle cx="30" cy="44" r="20" fill="${s}" stroke="${t}" stroke-width="3"/><circle cx="70" cy="44" r="20" fill="${s}" stroke="${t}" stroke-width="3"/><circle cx="50" cy="32" r="24" fill="${X(s,.12)}" stroke="${t}" stroke-width="3"/>`+[30,54,70].map((n,o)=>`<circle cx="${n}" cy="${36+o%2*10}" r="4" fill="${r(o===1?"coin":"danger")}"/>`).join("")}},z0={w:100,h:30,draw:({ink:e})=>`<line x1="10" y1="15" x2="80" y2="15" stroke="#8a5a34" stroke-width="5" stroke-linecap="round"/><polygon points="78,6 98,15 78,24" fill="#d8dde6" stroke="${e}" stroke-width="2.5" stroke-linejoin="round"/><path d="M4 7 L20 15 L4 23 M12 7 L26 15 L12 23" fill="none" stroke="#e8e0d0" stroke-width="3"/>`},N0={w:100,h:100,main:"danger",draw:({main:e,ink:t})=>ee(Fe("f",[[0,"#fff6c0",1],[.4,"#ffb23a",1],[1,e,.9]]))+`<path d="M62 10 C82 18 96 30 98 40 L70 62 Z" fill="#ff8a2a" opacity="0.75"/><path d="M50 16 C70 26 84 40 86 52 L60 66 Z" fill="#ffd34a" opacity="0.6"/><circle cx="40" cy="62" r="26" fill="url(#f)" stroke="${t}" stroke-width="3.5"/><circle cx="32" cy="56" r="5" fill="${W(e,.35)}"/><circle cx="48" cy="70" r="4" fill="${W(e,.35)}"/>`},W0={w:100,h:80,main:"coin",draw:({main:e,ink:t})=>{let r=(s,n)=>`<polygon points="${s},${n+18} ${s+6},${n} ${s+34},${n} ${s+40},${n+18}" fill="url(#g)" stroke="${t}" stroke-width="3" stroke-linejoin="round"/>`+ks(`M${s+10} ${n+5} L${s+24} ${n+5}`,2.5,.7);return ee(fe("g",[[0,X(e,.5)],[1,W(e,.25)]]))+'<ellipse cx="50" cy="74" rx="44" ry="5" fill="#000" opacity="0.25"/>'+r(8,52)+r(52,52)+r(30,32)+r(30,12)}},j0={w:100,h:100,draw:({ink:e})=>`<path d="M14 86 L86 14 M14 14 L86 86" stroke="#d8dde6" stroke-width="9" stroke-linecap="round"/><path d="M14 86 L86 14 M14 14 L86 86" stroke="${e}" stroke-width="2.5" stroke-linecap="round" opacity="0.6"/><path d="M26 46 C26 24 38 14 50 14 C62 14 74 24 74 46 C74 58 68 62 64 64 L64 76 L36 76 L36 64 C32 62 26 58 26 46Z" fill="#f4efe4" stroke="${e}" stroke-width="4" stroke-linejoin="round"/><circle cx="40" cy="46" r="8" fill="#2a1e1e"/><circle cx="60" cy="46" r="8" fill="#2a1e1e"/><path d="M50 54 L46 62 L54 62Z" fill="#2a1e1e"/><path d="M42 76 L42 68 M50 76 L50 68 M58 76 L58 68" stroke="${e}" stroke-width="2.5"/>`},H0={w:100,h:100,draw({style:e,ink:t,c:r}){let s=Ir(e),n=r("danger");return `<rect x="30" y="30" width="34" height="56" fill="${s.stone}" stroke="${t}" stroke-width="3.5"/>`+[30,41,52].map(o=>`<rect x="${o+1}" y="20" width="8" height="11" fill="${s.stone}" stroke="${t}" stroke-width="2.5"/>`).join("")+`<path d="M41 86 L41 74 A6 6 0 0 1 53 74 L53 86Z" fill="#3a2a1e" stroke="${t}" stroke-width="2.5"/><circle cx="47" cy="52" r="38" fill="none" stroke="${t}" stroke-width="13"/><circle cx="47" cy="52" r="38" fill="none" stroke="${n}" stroke-width="8"/><line x1="20" y1="79" x2="74" y2="25" stroke="${t}" stroke-width="13" stroke-linecap="round"/><line x1="20" y1="79" x2="74" y2="25" stroke="${n}" stroke-width="8" stroke-linecap="round"/>`+ee(fe("g",[[0,X(r("coin"),.45)],[1,W(r("coin"),.2)]]))+`<circle cx="78" cy="80" r="17" fill="url(#g)" stroke="${t}" stroke-width="3.5"/><path d="M78 71 L78 89 M69 80 L87 80" stroke="${W(r("coin"),.45)}" stroke-width="4" stroke-linecap="round"/>`}},xc={td_sell:H0,td_archer1:Rt("archer",1),td_archer2:Rt("archer",2),td_archer3:Rt("archer",3),td_archer_ranger:Rt("archer",3,"ranger"),td_archer_sniper:Rt("archer",3,"sniper"),td_cannon1:Rt("cannon",1),td_cannon2:Rt("cannon",2),td_cannon3:Rt("cannon",3),td_cannon_bombard:Rt("cannon",3,"bombard"),td_cannon_flamer:Rt("cannon",3,"flamer"),td_mage1:Rt("mage",1),td_mage2:Rt("mage",2),td_mage3:Rt("mage",3),td_mage_arcane:Rt("mage",3,"arcane"),td_mage_storm:Rt("mage",3,"storm"),td_frost1:Rt("frost",1),td_frost2:Rt("frost",2),td_frost3:Rt("frost",3),td_frost_glacier:Rt("frost",3,"glacier"),td_frost_blizzard:Rt("frost",3,"blizzard"),td_spot:T0,td_gate:O0,td_portal:C0,td_tree:P0,td_bush:I0,td_arrow:z0,td_meteor:N0,td_gold:W0,td_call:j0};var Ao=(e,t=4,r=.5)=>`<path d="${e}" fill="none" stroke="#fff" stroke-width="${t}" stroke-linecap="round" opacity="${r}"/>`,B0={w:100,h:100,draw:({ink:e})=>{let r=["#ff5a5a","#ffb03a","#ffe14a","#5ad35a","#4aa8ff","#a26bff"].map((s,n)=>{let o=n/6*Math.PI*2,a=(n+1)/6*Math.PI*2,c=p=>`${(50+Math.cos(p)*38).toFixed(1)} ${(50+Math.sin(p)*38).toFixed(1)}`;return `<path d="M50 50 L${c(o)} A38 38 0 0 1 ${c(a)}Z" fill="${s}"/>`});return ee(Fe("g",[[0,"#ffffff",.95],[.5,"#ffffff",.2],[1,"#ffffff",0]],.38,.35,.5))+'<circle cx="50" cy="50" r="46" fill="#ffffff" opacity="0.25"/>'+r.join("")+`<circle cx="50" cy="50" r="38" fill="url(#g)" stroke="${e}" stroke-width="4"/><polygon points="${Qe(50,50,13,6)}" fill="#fff" opacity="0.9"/>`}},kc=e=>({w:100,h:100,draw:({ink:t})=>{let r=`<path d="M8 50 L24 38 L24 45 L76 45 L76 38 L92 50 L76 62 L76 55 L24 55 L24 62Z" fill="#fff" stroke="${t}" stroke-width="3" stroke-linejoin="round"/>`;return `<g ${e?'transform="rotate(90 50 50)"':""} opacity="0.95">${r}</g>`}}),V0={w:100,h:100,draw:({ink:e})=>`<circle cx="50" cy="50" r="40" fill="none" stroke="#fff" stroke-width="7" opacity="0.9"/><circle cx="50" cy="50" r="40" fill="none" stroke="${e}" stroke-width="2" opacity="0.6"/><polygon points="${Qe(78,20,13,5,8)}" fill="#ffd34a" stroke="${e}" stroke-width="2"/>`},vc=e=>({w:100,h:100,draw:({ink:t})=>ee(fe("i",[[0,"#e6f6ff",.75],[1,"#7cc4ff",e>1?.85:.6]]))+`<rect x="3" y="3" width="94" height="94" rx="12" fill="url(#i)" stroke="${t}" stroke-width="3" opacity="0.95"/>`+(e>1?'<rect x="12" y="12" width="76" height="76" rx="8" fill="none" stroke="#fff" stroke-width="4" opacity="0.8"/>':"")+Ao("M14 30 L30 14",5,.8)+Ao("M70 88 L86 72",4,.5)}),G0={w:100,h:100,draw:({ink:e})=>`<path d="M4 20 C4 8 14 4 24 6 C36 0 56 10 64 4 C78 0 96 8 96 22 L96 80 C96 94 84 98 72 94 C60 100 44 90 30 96 C16 100 4 92 4 80Z" fill="#8edc4a" opacity="0.6" stroke="${e}" stroke-width="3"/><circle cx="28" cy="70" r="6" fill="#c6f58a" opacity="0.9"/><circle cx="72" cy="30" r="5" fill="#c6f58a" opacity="0.9"/>`},F0={w:100,h:100,draw:({ink:e})=>{let t=(r,s,n)=>`<rect x="${r-14}" y="${s-8}" width="28" height="16" rx="8" fill="none" stroke="#9aa3b0" stroke-width="7" transform="rotate(${n} ${r} ${s})"/><rect x="${r-14}" y="${s-8}" width="28" height="16" rx="8" fill="none" stroke="${e}" stroke-width="1.5" transform="rotate(${n} ${r} ${s})"/>`;return [t(18,18,45),t(36,36,45),t(64,64,45),t(82,82,45),t(82,18,-45),t(64,36,-45),t(36,64,-45),t(18,82,-45)].join("")+`<circle cx="50" cy="50" r="12" fill="#c9a14a" stroke="${e}" stroke-width="3"/><rect x="46" y="48" width="8" height="10" fill="${e}"/>`}},$c=e=>({w:100,h:100,draw:({style:t,ink:r})=>{let s=t==="sci-fi"?"#7c86a8":t==="cozy"?"#b8a99a":"#8f8a82";return ee(fe("s",[[0,X(s,.35)],[1,W(s,.35)]]))+`<path d="M10 30 L28 8 L72 6 L92 26 L94 72 L74 94 L26 94 L6 72Z" fill="url(#s)" stroke="${r}" stroke-width="4" stroke-linejoin="round"/>`+(e?"":`<path d="M30 30 L44 50 L36 70 M60 24 L66 44 L80 54" fill="none" stroke="${W(s,.5)}" stroke-width="3.5" stroke-linecap="round"/>`)+(e?`<path d="M30 40 L70 40 M30 60 L70 60" stroke="${W(s,.4)}" stroke-width="4"/>`:"")+Ao("M20 30 L34 14",4,.45)}}),U0={w:100,h:100,draw:({ink:e,c:t})=>{let r="";for(let s=18;s<=82;s+=16)r+=`<line x1="${s}" y1="18" x2="${s}" y2="88" stroke="#b07a3a" stroke-width="5"/>`;return `<circle cx="50" cy="58" r="22" fill="${t("coin")}" stroke="${e}" stroke-width="3"/><circle cx="42" cy="54" r="4" fill="${e}"/><circle cx="58" cy="54" r="4" fill="${e}"/><path d="M44 66 Q50 71 56 66" fill="none" stroke="${e}" stroke-width="3" stroke-linecap="round"/><path d="M34 40 L30 28 L42 36Z M66 40 L70 28 L58 36Z" fill="${t("coin")}" stroke="${e}" stroke-width="2.5"/>`+r+`<rect x="10" y="10" width="80" height="10" rx="4" fill="#8a5a2a" stroke="${e}" stroke-width="3"/><rect x="10" y="86" width="80" height="10" rx="4" fill="#8a5a2a" stroke="${e}" stroke-width="3"/>`}},X0={w:100,h:100,draw:({ink:e})=>ee(fe("w",[[0,"#d9a066"],[1,"#9a6236"]]))+`<rect x="8" y="8" width="84" height="84" rx="6" fill="url(#w)" stroke="${e}" stroke-width="4"/><rect x="16" y="16" width="68" height="68" fill="none" stroke="#7a4a26" stroke-width="4"/><path d="M18 18 L82 82 M82 18 L18 82" stroke="#7a4a26" stroke-width="6"/><path d="M50 30 L50 64 M38 54 L50 66 L62 54" fill="none" stroke="#fff4d0" stroke-width="7" stroke-linecap="round" stroke-linejoin="round"/>`},q0={w:100,h:100,main:"danger",draw:({main:e,ink:t})=>ee(fe("h",[[0,X(e,.45)],[1,W(e,.2)]]))+`<path d="M50 88 C20 66 8 50 8 32 C8 18 20 8 32 8 C40 8 46 12 50 20 C54 12 60 8 68 8 C80 8 92 18 92 32 C92 50 80 66 50 88Z" fill="url(#h)" stroke="${t}" stroke-width="4.5" stroke-linejoin="round"/>`+Ao("M22 30 C22 22 28 18 34 18",5,.7)},K0={w:100,h:100,main:"primary",draw:({main:e,ink:t})=>ee(fe("s",[[0,X(e,.45)],[1,W(e,.25)]]))+`<path d="M50 6 L88 18 L86 52 C84 74 68 88 50 96 C32 88 16 74 14 52 L12 18Z" fill="url(#s)" stroke="${t}" stroke-width="4.5" stroke-linejoin="round"/><path d="M50 20 L74 28 L72 52 C70 66 60 76 50 82Z" fill="${X(e,.3)}" opacity="0.7"/>`+Ao("M24 26 L36 22",4,.7)},Z0={w:100,h:100,draw:({ink:e})=>ee(Fe("f",[[0,"#fff6c0",1],[.45,"#ffb23a",1],[1,"#e0442e",1]]))+`<polygon points="${Qe(50,50,46,22,10)}" fill="url(#f)" stroke="${e}" stroke-width="4" stroke-linejoin="round"/><circle cx="50" cy="50" r="12" fill="#fff6c0"/>`},Q0={w:100,h:100,draw:({ink:e,c:t})=>`<path d="M40 6 L60 6 L60 40 L94 40 L94 60 L60 60 L60 94 L40 94 L40 60 L6 60 L6 40 L40 40Z" fill="${t("coin")}" stroke="${e}" stroke-width="4" stroke-linejoin="round"/><circle cx="50" cy="50" r="13" fill="#fffbe0" stroke="${e}" stroke-width="3"/>`},Y0={w:100,h:100,draw:({ink:e,c:t})=>`<path d="M20 44 C10 44 6 34 12 26 C16 18 26 18 30 22 C34 10 52 8 60 18 C70 12 86 18 86 30 C96 32 96 46 84 48Z" fill="#d8e2f0" stroke="${e}" stroke-width="4" stroke-linejoin="round"/><path d="M48 48 L36 72 L50 72 L42 96 L68 62 L54 62 L62 48Z" fill="${t("coin")}" stroke="${e}" stroke-width="3.5" stroke-linejoin="round"/>`},Mc={m3_rainbow:B0,m3_row:kc(false),m3_col:kc(true),m3_bomb:V0,m3_ice:vc(1),m3_ice2:vc(2),m3_slime:G0,m3_chain:F0,m3_stone:$c(false),m3_stone2:$c(true),m3_cage:U0,m3_crate:X0,m3_heart:q0,m3_shield:K0,m3_skill_blast:Z0,m3_skill_cross:Q0,m3_skill_storm:Y0};var vt=(e,t,r,s,n=.28)=>`<ellipse cx="${e}" cy="${t}" rx="${r}" ry="${s}" fill="#000" opacity="${n}"/>`,fr=(e,t=4,r=.55)=>`<path d="${e}" fill="none" stroke="#fff" stroke-width="${t}" stroke-linecap="round" opacity="${r}"/>`,Xt=e=>({w:100,h:100,draw:({ink:t})=>e(t)}),Do="#e8b84a",un="#c9803a",J0=e=>Xt(t=>{switch(e){case 1:{let r=[0,1,2,3].map(s=>`<ellipse cx="${44-s%2*0}" cy="${30+s*11}" rx="7" ry="5" fill="${Do}" stroke="${t}" stroke-width="2.5" transform="rotate(-30 44 ${30+s*11})"/><ellipse cx="57" cy="${30+s*11}" rx="7" ry="5" fill="${X(Do,.1)}" stroke="${t}" stroke-width="2.5" transform="rotate(30 57 ${30+s*11})"/>`);return vt(50,90,14,3)+`<path d="M50 90 L50 22" stroke="${W(Do,.3)}" stroke-width="4" stroke-linecap="round"/>`+r.join("")+`<ellipse cx="50" cy="20" rx="5" ry="8" fill="${Do}" stroke="${t}" stroke-width="2.5"/>`}case 2:return ee(fe("s",[[0,"#f6ecd6"],[1,"#d6c29a"]]))+vt(50,90,28,5)+`<path d="M24 40 Q22 86 30 88 L70 88 Q78 86 76 40 Q50 30 24 40Z" fill="url(#s)" stroke="${t}" stroke-width="3.5"/><path d="M28 40 Q38 22 50 30 Q62 22 72 40" fill="#f6ecd6" stroke="${t}" stroke-width="3"/><path d="M36 38 L64 38" stroke="${un}" stroke-width="5"/><path d="M50 52 L56 62 L50 72 L44 62Z" fill="${Do}" stroke="${t}" stroke-width="2"/><circle cx="50" cy="20" r="6" fill="#fff" opacity="0.9"/><circle cx="58" cy="16" r="4" fill="#fff" opacity="0.8"/>`;case 3:return ee(Fe("d",[[0,"#fff6e6"],[1,"#e8cfa2"]],.4,.35))+vt(50,86,30,5)+`<path d="M18 70 Q14 44 36 38 Q50 30 64 38 Q86 44 82 70 Q78 84 50 84 Q22 84 18 70Z" fill="url(#d)" stroke="${t}" stroke-width="3.5"/>`+fr("M30 52 Q36 44 46 42",4,.7);case 4:return ee(fe("b",[[0,"#f0b25a"],[1,un]]))+vt(50,86,32,5)+`<path d="M16 72 Q14 40 50 34 Q86 40 84 72 Q80 84 50 84 Q20 84 16 72Z" fill="url(#b)" stroke="${t}" stroke-width="3.5"/>`+[[36,50],[50,46],[64,50],[44,60],[58,60]].map(([r,s])=>`<ellipse cx="${r}" cy="${s}" rx="3" ry="1.8" fill="#fff6d6" stroke="${t}" stroke-width="1"/>`).join("")+fr("M26 56 Q30 46 40 42",4,.5);case 5:return ee(fe("l",[[0,"#f2bb66"],[1,W(un,.1)]]))+vt(50,84,40,5)+`<path d="M8 66 Q8 36 50 32 Q92 36 92 66 Q92 80 50 80 Q8 80 8 66Z" fill="url(#l)" stroke="${t}" stroke-width="3.5"/>`+[26,42,58,74].map(r=>`<path d="M${r-6} 52 Q${r} 42 ${r+6} 40" stroke="${W(un,.35)}" stroke-width="4" fill="none" stroke-linecap="round"/>`).join("")+fr("M16 60 Q18 46 30 40",4,.45);case 6:return ee(fe("p",[[0,"#f4c070"],[1,un]]))+vt(50,86,42,5)+`<path d="M8 60 L14 80 L86 80 L92 60Z" fill="#b8b8c8" stroke="${t}" stroke-width="3.5"/><ellipse cx="50" cy="58" rx="42" ry="16" fill="url(#p)" stroke="${t}" stroke-width="3.5"/><ellipse cx="50" cy="56" rx="32" ry="10" fill="#c43a5a"/>`+[-20,-7,6,19].map(r=>`<line x1="${50+r}" y1="46" x2="${50+r+6}" y2="67" stroke="${X(un,.2)}" stroke-width="4"/>`).join("")+[-20,0,20].map(r=>`<line x1="20" y1="${56+r*.3}" x2="80" y2="${56+r*.3}" stroke="${X(un,.2)}" stroke-width="4" opacity="0.9"/>`).join("")+`<ellipse cx="50" cy="58" rx="42" ry="16" fill="none" stroke="${t}" stroke-width="3.5"/>`;default:return ee(fe("c",[[0,"#fff4f6"],[1,"#f2c6d2"]]),fe("t",[[0,"#ffd6e0"],[1,"#e89ab0"]]))+vt(50,94,40,4)+`<rect x="12" y="62" width="76" height="28" rx="6" fill="url(#c)" stroke="${t}" stroke-width="3.5"/><rect x="24" y="38" width="52" height="26" rx="6" fill="url(#t)" stroke="${t}" stroke-width="3.5"/><path d="M12 70 Q20 78 28 70 Q36 78 44 70 Q52 78 60 70 Q68 78 76 70 Q84 78 88 70" fill="none" stroke="#fff" stroke-width="4"/><path d="M24 46 Q32 52 40 46 Q48 52 56 46 Q64 52 76 46" fill="none" stroke="#fff" stroke-width="4"/>`+[36,50,64].map(r=>`<rect x="${r-2.5}" y="22" width="5" height="16" rx="2" fill="#7cc4ff" stroke="${t}" stroke-width="1.5"/><path d="M${r} 12 Q${r+4} 18 ${r} 21 Q${r-4} 18 ${r} 12Z" fill="#ffc83a"/>`).join("")+`<circle cx="50" cy="40" r="5" fill="#d62a3a" stroke="${t}" stroke-width="2"/>`}}),Sr="#4ac8ff",To="#ffc83a",Pn=(e,t,r,s,n,o)=>`<path d="M${e} ${t-r} L${e+s} ${t-r*.6} L${e+s*.8} ${t} L${e-s*.8} ${t} L${e-s} ${t-r*.6}Z" fill="${n}" stroke="${o}" stroke-width="3" stroke-linejoin="round"/><path d="M${e} ${t-r} L${e} ${t}" stroke="#fff" stroke-width="2" opacity="0.6"/>`,ep=e=>Xt(t=>{switch(e){case 1:return ee(Fe("r",[[0,"#c8ccd6"],[1,"#7a8090"]],.4,.35))+vt(50,84,28,5)+`<path d="M20 70 Q16 48 34 40 Q52 30 70 42 Q86 54 78 72 Q66 84 44 82 Q24 80 20 70Z" fill="url(#r)" stroke="${t}" stroke-width="3.5"/><path d="M58 52 L66 58 L60 64Z" fill="${Sr}" stroke="${t}" stroke-width="1.5"/>`+fr("M30 52 Q36 44 46 42",4,.5);case 2:return vt(50,88,22,4)+Pn(50,86,66,18,Sr,t)+fr("M44 40 L46 30",3,.7);case 3:return vt(50,90,34,5)+Pn(30,88,44,13,W(Sr,.15),t)+Pn(70,88,48,13,"#a88aff",t)+Pn(50,88,70,16,Sr,t);case 4:return ee(fe("g",[[0,X(Sr,.4)],[1,W(Sr,.3)]]))+vt(50,90,30,5)+`<path d="M20 38 L34 20 L66 20 L80 38 L50 86Z" fill="url(#g)" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/><path d="M20 38 L80 38 M34 20 L42 38 L50 86 L58 38 L66 20 M42 38 L50 20 L58 38" fill="none" stroke="${t}" stroke-width="2" opacity="0.7"/><path d="M28 34 L36 24" stroke="#fff" stroke-width="4" stroke-linecap="round" opacity="0.8"/>`;case 5:return vt(50,90,26,4)+`<circle cx="50" cy="62" r="24" fill="none" stroke="${t}" stroke-width="13"/><circle cx="50" cy="62" r="24" fill="none" stroke="${To}" stroke-width="8"/><path d="M50 62 m-16 -20" stroke="#fff" stroke-width="3" opacity="0.5"/><path d="M36 32 L42 22 L58 22 L64 32 L50 48Z" fill="#ff4a8a" stroke="${t}" stroke-width="3" stroke-linejoin="round"/>`+fr("M30 70 Q30 54 40 46",3,.6);case 6:return vt(50,92,24,4)+`<path d="M18 16 Q20 58 50 66 Q80 58 82 16" fill="none" stroke="${t}" stroke-width="7"/><path d="M18 16 Q20 58 50 66 Q80 58 82 16" fill="none" stroke="${To}" stroke-width="4" stroke-dasharray="5 3"/><path d="M50 62 L64 74 L50 92 L36 74Z" fill="${Sr}" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><circle cx="34" cy="52" r="4" fill="#ff4a8a" stroke="${t}" stroke-width="1.5"/><circle cx="66" cy="52" r="4" fill="#ff4a8a" stroke="${t}" stroke-width="1.5"/>`+fr("M44 72 L50 66",3,.7);default:return ee(fe("k",[[0,X(To,.3)],[1,W(To,.25)]]))+vt(50,90,38,5)+`<path d="M12 80 L8 30 L30 50 L50 18 L70 50 L92 30 L88 80Z" fill="url(#k)" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/><rect x="12" y="72" width="76" height="12" rx="3" fill="${W(To,.15)}" stroke="${t}" stroke-width="3"/><circle cx="50" cy="60" r="7" fill="#ff4a8a" stroke="${t}" stroke-width="2.5"/><circle cx="30" cy="64" r="5" fill="${Sr}" stroke="${t}" stroke-width="2"/><circle cx="70" cy="64" r="5" fill="${Sr}" stroke="${t}" stroke-width="2"/>`+[[8,30],[50,18],[92,30]].map(([r,s])=>`<circle cx="${r}" cy="${s}" r="5" fill="#fff6c0" stroke="${t}" stroke-width="2"/>`).join("")}}),zr="#a26bff",Ec="#dff2ff",tp=e=>Xt(t=>{switch(e){case 1:return vt(50,90,18,4)+'<path d="M50 90 Q46 60 52 30" stroke="#3f8a3a" stroke-width="4" fill="none" stroke-linecap="round"/>'+[[52,34,-40],[49,50,210],[51,64,-30],[48,76,200]].map(([r,s,n])=>`<ellipse cx="${r+12*Math.cos(n*Math.PI/180)}" cy="${s+12*Math.sin(n*Math.PI/180)}" rx="13" ry="6" fill="#5ad35a" stroke="${t}" stroke-width="2.5" transform="rotate(${n} ${r+12*Math.cos(n*Math.PI/180)} ${s+12*Math.sin(n*Math.PI/180)})"/>`).join("");case 2:return ee(Fe("d",[[0,X(zr,.5)],[1,W(zr,.2)]],.4,.55))+vt(50,90,18,4)+`<path d="M50 12 Q74 46 74 62 A24 24 0 0 1 26 62 Q26 46 50 12Z" fill="url(#d)" stroke="${t}" stroke-width="3.5"/>`+fr("M38 58 Q38 48 44 40",4,.7);case 3:return vt(50,92,14,3)+`<rect x="38" y="12" width="24" height="8" rx="2" fill="#a8774a" stroke="${t}" stroke-width="2.5"/><path d="M40 20 L40 78 A10 10 0 0 0 60 78 L60 20Z" fill="${Ec}" stroke="${t}" stroke-width="3" opacity="0.95"/><path d="M41 52 L41 78 A9 9 0 0 0 59 78 L59 52Z" fill="#4ad3a0"/>`+fr("M45 26 L45 72",3,.7);case 4:return vt(50,92,26,4)+`<rect x="42" y="10" width="16" height="10" rx="2" fill="#a8774a" stroke="${t}" stroke-width="2.5"/><path d="M44 20 L44 40 A26 26 0 1 0 56 40 L56 20Z" fill="${Ec}" stroke="${t}" stroke-width="3"/><path d="M27 62 A23 23 0 0 0 73 62Z" fill="#ff6a5a"/><circle cx="44" cy="70" r="3" fill="#fff" opacity="0.7"/><circle cx="56" cy="74" r="2" fill="#fff" opacity="0.7"/>`+fr("M34 52 Q32 62 36 70",3.5,.7);case 5:return ee(fe("b",[[0,X(zr,.3)],[1,W(zr,.3)]]))+vt(50,94,26,4)+`<rect x="40" y="6" width="20" height="12" rx="3" fill="#a8774a" stroke="${t}" stroke-width="2.5"/><path d="M42 18 L42 30 Q22 38 22 60 L22 82 Q22 90 30 90 L70 90 Q78 90 78 82 L78 60 Q78 38 58 30 L58 18Z" fill="url(#b)" stroke="${t}" stroke-width="3.5"/><rect x="30" y="56" width="40" height="22" rx="4" fill="#fff6e6" stroke="${t}" stroke-width="2"/><path d="M50 74 L40 64 A5 5 0 0 1 50 60 A5 5 0 0 1 60 64Z" fill="#e8384a"/>`+fr("M30 44 Q28 52 28 60",4,.6);case 6:return ee(fe("k",[[0,"#5a5a6a"],[1,"#22222c"]]))+vt(50,94,36,4)+[[30,30,6],[46,20,8],[62,28,5]].map(([r,s,n])=>`<circle cx="${r}" cy="${s}" r="${n}" fill="${X("#4ad3a0",.2)}" stroke="${t}" stroke-width="2"/>`).join("")+`<ellipse cx="50" cy="44" rx="38" ry="10" fill="#4ad3a0" stroke="${t}" stroke-width="3"/><path d="M12 44 Q12 86 50 86 Q88 86 88 44Z" fill="url(#k)" stroke="${t}" stroke-width="3.5"/><path d="M26 86 L22 94 M74 86 L78 94" stroke="${t}" stroke-width="5" stroke-linecap="round"/>`+fr("M20 54 Q22 68 30 76",4,.35);default:return ee(Fe("o",[[0,"#ffffff"],[.35,X(zr,.4)],[1,W(zr,.35)]],.4,.35))+vt(50,94,26,4)+`<path d="M28 94 L34 76 L66 76 L72 94Z" fill="#a8774a" stroke="${t}" stroke-width="3"/><circle cx="50" cy="44" r="34" fill="${zr}" opacity="0.25"/><circle cx="50" cy="46" r="28" fill="url(#o)" stroke="${t}" stroke-width="3.5"/><polygon points="${Qe(50,46,12,5,4)}" fill="#fff" opacity="0.85"/>`+[[18,20],[84,26],[80,70],[16,66]].map(([r,s])=>`<polygon points="${Qe(r,s,5,2,4)}" fill="#fff6c0"/>`).join("")}}),$s=(e,t)=>ee(fe("pad",[[0,X(e,.25)],[1,W(e,.25)]]))+`<rect x="6" y="6" width="88" height="88" rx="20" fill="url(#pad)" stroke="${t}" stroke-width="4"/><rect x="12" y="12" width="76" height="40" rx="14" fill="#fff" opacity="0.18"/>`,rp=Xt(e=>$s("#5ab04a",e)+`<path d="M26 44 Q24 84 32 84 L68 84 Q76 84 74 44 Q50 36 26 44Z" fill="#d8b884" stroke="${e}" stroke-width="3.5"/><path d="M30 46 Q40 32 50 40 Q60 32 70 46" fill="#e8cc9a" stroke="${e}" stroke-width="3"/><path d="M50 40 Q48 26 50 18" stroke="#3f8a3a" stroke-width="4" fill="none" stroke-linecap="round"/><ellipse cx="41" cy="22" rx="9" ry="5" fill="#7fd36e" stroke="${e}" stroke-width="2.5" transform="rotate(-25 41 22)"/><ellipse cx="59" cy="20" rx="9" ry="5" fill="#7fd36e" stroke="${e}" stroke-width="2.5" transform="rotate(25 59 20)"/>`+[[42,64],[52,70],[58,60]].map(([t,r])=>`<ellipse cx="${t}" cy="${r}" rx="3" ry="4" fill="#8a5a32"/>`).join("")),np=Xt(e=>$s("#e09a3a",e)+`<path d="M16 84 L16 50 Q16 20 50 20 Q84 20 84 50 L84 84Z" fill="#c8634a" stroke="${e}" stroke-width="3.5"/>`+[30,44,58].map(t=>`<path d="M18 ${t} L82 ${t}" stroke="${W("#c8634a",.3)}" stroke-width="2"/>`).join("")+`<path d="M30 84 L30 60 Q30 46 50 46 Q70 46 70 84Z" fill="#2a1a14" stroke="${e}" stroke-width="3"/><path d="M38 84 Q36 70 44 64 Q44 72 50 70 Q50 60 58 58 Q66 70 62 84Z" fill="#ffb03a"/><path d="M44 84 Q44 76 50 74 Q56 76 56 84Z" fill="#ffe66a"/>`),op=Xt(e=>$s("#4a7ad3",e)+`<path d="M14 84 L22 46 L42 28 L66 32 L84 54 L86 84Z" fill="#8a8a9a" stroke="${e}" stroke-width="3.5" stroke-linejoin="round"/><path d="M22 46 L40 56 L42 28 M40 56 L66 32 M40 56 L60 84 M66 32 L68 60 L84 54 M68 60 L60 84" fill="none" stroke="${W("#8a8a9a",.3)}" stroke-width="2"/>`+Pn(36,76,18,6,Sr,e)+Pn(70,78,14,5,"#ff4a8a",e)+`<path d="M58 14 L84 26" stroke="#8a5a32" stroke-width="5" stroke-linecap="round"/><path d="M76 12 Q86 20 90 34 L82 30 Q80 22 72 18Z" fill="#c8ccd6" stroke="${e}" stroke-width="2.5"/>`),sp=Xt(e=>$s("#8a4ad3",e)+`<rect x="16" y="20" width="68" height="66" rx="6" fill="#8a5a32" stroke="${e}" stroke-width="3.5"/><path d="M16 52 L84 52" stroke="${e}" stroke-width="3"/>`+[[30,44,"#4ad3a0"],[50,44,"#ff6a5a"],[70,44,zr],[30,78,zr],[50,78,"#ffc83a"],[70,78,"#4ad3a0"]].map(([t,r,s])=>`<rect x="${Number(t)-4}" y="${Number(r)-20}" width="8" height="6" fill="#d8b884"/><path d="M${Number(t)-6} ${Number(r)-14} L${Number(t)+6} ${Number(r)-14} L${Number(t)+7} ${r} L${Number(t)-7} ${r}Z" fill="${s}" stroke="${e}" stroke-width="2"/>`).join("")),Sc=e=>Xt(t=>{let r="#c08a4a";return ee(fe("w",[[0,X(r,.15)],[1,W(r,.2)]]))+`<rect x="6" y="6" width="88" height="88" rx="8" fill="url(#w)" stroke="${t}" stroke-width="4"/>`+[30,50,70].map(s=>`<line x1="8" y1="${s}" x2="92" y2="${s}" stroke="${W(r,.35)}" stroke-width="2"/>`).join("")+`<path d="M14 14 L86 86 M86 14 L14 86" stroke="${W(r,.3)}" stroke-width="7"/><rect x="6" y="6" width="88" height="88" rx="8" fill="none" stroke="${t}" stroke-width="4"/>`+(e?`<rect x="6" y="22" width="88" height="10" fill="#8a96aa" stroke="${t}" stroke-width="2.5"/><rect x="6" y="68" width="88" height="10" fill="#8a96aa" stroke="${t}" stroke-width="2.5"/>`+[16,50,84].map(s=>`<circle cx="${s}" cy="27" r="2.5" fill="${t}"/><circle cx="${s}" cy="73" r="2.5" fill="${t}"/>`).join(""):"")}),ip={w:100,h:100,draw:()=>ee(Fe("f",[[0,"#ffffff"],[1,"#c8d2e0"]],.45,.4,.6))+'<rect x="2" y="2" width="96" height="96" rx="14" fill="url(#f)" opacity="0.97"/>'+[[28,34,18],[62,30,20],[44,58,22],[76,64,16],[22,70,14]].map(([e,t,r])=>`<circle cx="${e}" cy="${t}" r="${r}" fill="#ffffff" opacity="0.75"/>`).join("")+'<text x="50" y="62" font-size="30" font-family="sans-serif" font-weight="900" text-anchor="middle" fill="#8a96aa" opacity="0.8">?</text>'},ap=Xt(e=>'<g stroke="#ffffff" stroke-width="2.5" fill="none" opacity="0.9">'+[0,45,90,135].map(t=>`<line x1="${50-46*Math.cos(t*Math.PI/180)}" y1="${50-46*Math.sin(t*Math.PI/180)}" x2="${50+46*Math.cos(t*Math.PI/180)}" y2="${50+46*Math.sin(t*Math.PI/180)}"/>`).join("")+[14,28,42].map(t=>`<polygon points="${Lt(50,50,t,8,0)}"/>`).join("")+`</g><g stroke="${e}" stroke-width="1" fill="none" opacity="0.35">`+[14,28,42].map(t=>`<polygon points="${Lt(50,50,t,8,0)}"/>`).join("")+"</g>"),lp={w:100,h:100,draw:()=>ee(Fe("u",[[0,"#ffffff",0],[.75,"#9ad8ff",.25],[1,"#4ab0ff",.7]]))+'<circle cx="50" cy="50" r="46" fill="url(#u)" stroke="#ffffff" stroke-width="3" opacity="0.95"/>'+fr("M24 38 Q28 24 42 18",6,.85)+'<circle cx="72" cy="72" r="4" fill="#fff" opacity="0.7"/>'},cp=Xt(e=>ee(fe("j",[[0,"#ff6a8a"],[.35,"#ffc83a"],[.7,"#5ad35a"],[1,"#4aa8ff"]]))+vt(50,90,26,4)+`<circle cx="50" cy="50" r="40" fill="#fff" opacity="0.25"/><polygon points="${Qe(50,50,40,18,5)}" fill="url(#j)" stroke="${e}" stroke-width="3.5" stroke-linejoin="round"/><circle cx="42" cy="46" r="4" fill="${e}"/><circle cx="58" cy="46" r="4" fill="${e}"/><path d="M42 58 Q50 64 58 58" stroke="${e}" stroke-width="3" fill="none" stroke-linecap="round"/>`),dp=Xt(e=>vt(50,92,22,4)+`<path d="M50 54 L26 12 L34 10 L54 48Z" fill="#d8dee8" stroke="${e}" stroke-width="3" stroke-linejoin="round"/><path d="M50 54 L74 12 L66 10 L46 48Z" fill="#eef2f8" stroke="${e}" stroke-width="3" stroke-linejoin="round"/><circle cx="34" cy="74" r="14" fill="none" stroke="${e}" stroke-width="10"/><circle cx="34" cy="74" r="14" fill="none" stroke="#e8384a" stroke-width="6"/><circle cx="66" cy="74" r="14" fill="none" stroke="${e}" stroke-width="10"/><circle cx="66" cy="74" r="14" fill="none" stroke="#e8384a" stroke-width="6"/><circle cx="50" cy="54" r="5" fill="#ffc83a" stroke="${e}" stroke-width="2"/>`),fp=Xt(e=>ee(Fe("e",[[0,"#fff6a0"],[1,"#ffb000"]],.4,.35))+`<circle cx="50" cy="50" r="44" fill="url(#e)" stroke="${e}" stroke-width="4"/><path d="M56 12 L26 56 L46 56 L40 88 L74 40 L54 40Z" fill="#fff" stroke="${e}" stroke-width="3.5" stroke-linejoin="round"/>`),pp=Xt(e=>ee(fe("t",[[0,"#9aa6ba"],[1,"#5a6478"]],true))+`<rect x="36" y="8" width="28" height="10" rx="4" fill="#5a6478" stroke="${e}" stroke-width="3"/><rect x="14" y="16" width="72" height="12" rx="4" fill="#7a869a" stroke="${e}" stroke-width="3.5"/><path d="M20 30 L26 90 L74 90 L80 30Z" fill="url(#t)" stroke="${e}" stroke-width="3.5" stroke-linejoin="round"/>`+[36,50,64].map(t=>`<line x1="${t}" y1="40" x2="${t}" y2="80" stroke="${e}" stroke-width="3" stroke-linecap="round" opacity="0.6"/>`).join("")),hp=Xt(e=>`<path d="M50 10 L80 44 L62 44 L62 84 L38 84 L38 44 L20 44Z" fill="#7cf0a0" stroke="${e}" stroke-width="4" stroke-linejoin="round"/>`+[[18,20],[84,66],[16,74]].map(([t,r])=>`<polygon points="${Qe(t,r,9,3.5,4)}" fill="#fff6a0" stroke="${e}" stroke-width="1.5"/>`).join("")),up=Xt(e=>`<path d="M40 8 L16 50 L32 50 L26 90 L56 40 L40 40Z" fill="#ffd34a" stroke="${e}" stroke-width="3.5" stroke-linejoin="round"/><path d="M70 18 L52 50 L64 50 L60 82 L84 44 L72 44Z" fill="#fff6a0" stroke="${e}" stroke-width="3" stroke-linejoin="round"/>`),mp=Xt(e=>`<path d="M22 84 L64 42" stroke="${e}" stroke-width="12" stroke-linecap="round"/><path d="M22 84 L64 42" stroke="#8a5a32" stroke-width="7" stroke-linecap="round"/><polygon points="${Qe(70,34,24,10,5)}" fill="#ffc83a" stroke="${e}" stroke-width="3.5" stroke-linejoin="round"/>`+[[30,22],[88,70],[52,82]].map(([t,r])=>`<polygon points="${Qe(t,r,7,2.5,4)}" fill="#fff"/>`).join("")),wc={...Object.fromEntries([1,2,3,4,5,6,7].map(e=>[`mg_bake${e}`,J0(e)])),...Object.fromEntries([1,2,3,4,5,6,7].map(e=>[`mg_jewel${e}`,ep(e)])),...Object.fromEntries([1,2,3,4,5,6,7].map(e=>[`mg_potion${e}`,tp(e)])),mg_gen_garden:rp,mg_gen_bake:np,mg_gen_jewel:op,mg_gen_potion:sp,mg_box:Sc(false),mg_box2:Sc(true),mg_fog:ip,mg_web:ap,mg_bubble:lp,mg_joker:cp,mg_scissors:dp,mg_energy:fp,mg_bin:pp,mg_sk_merge:hp,mg_sk_free:up,mg_sk_joker:mp};var Lc={fantasy:{skyTop:"#3f6aa8",skyBottom:"#f4c98e",far1:"#7b8fb8",far2:"#566f94",near:"#2c5638",crust:"#6dbb45",soil:"#7a5232",deep:"#4e331e",floor:"#5f9a3e",detail:"#7ab552",road:"#a57d4f",edge:"#7a5a36",wall:"#e8d9b8",roof:"#b8483a"},"sci-fi":{skyTop:"#050816",skyBottom:"#3b1f63",far1:"#232b5c",far2:"#161c40",near:"#0e1430",crust:"#36e3ff",soil:"#2a3452",deep:"#151b30",floor:"#1b2340",detail:"#2a3762",road:"#2b3868",edge:"#36e3ff",wall:"#3a4a72",roof:"#232c4a"},cozy:{skyTop:"#8fd3ff",skyBottom:"#fff3d6",far1:"#b6e2a2",far2:"#8fcc7e",near:"#5fae5a",crust:"#8ed46f",soil:"#c98b5a",deep:"#9e6a42",floor:"#a8dc8a",detail:"#c6ecab",road:"#efc89a",edge:"#d9a676",wall:"#fff1e0",roof:"#ff8f8f"},"post-apocalypse":{skyTop:"#3b2a26",skyBottom:"#d0803e",far1:"#7a5442",far2:"#4e3a2e",near:"#2a201a",crust:"#5a5248",soil:"#6b6358",deep:"#3e3832",floor:"#5e5648",detail:"#4a4438",road:"#46423c",edge:"#2e2a26",wall:"#8a7a62",roof:"#5a3a2a"},default:{skyTop:"#25365e",skyBottom:"#7d9fd6",far1:"#4f6494",far2:"#3a4b72",near:"#283958",crust:"#5fae5a",soil:"#6b4a2e",deep:"#45301c",floor:"#3e5a46",detail:"#4b6a52",road:"#5a5f78",edge:"#454a60",wall:"#e6dccb",roof:"#5a6fae"}},sr=e=>Lc[e]??Lc.default,yp={w:100,h:200,draw({style:e}){let t=sr(e),r="";if(e==="sci-fi"){let s=yr(7);r=Array.from({length:60},()=>`<circle cx="${U(s()*100)}" cy="${U(s()*150)}" r="${U(.3+s()*.6)}" fill="#fff" opacity="${U(.3+s()*.7)}"/>`).join("");}return ee(fe("s",[[0,t.skyTop],[.75,On(t.skyTop,t.skyBottom,.7)],[1,t.skyBottom]]))+'<rect width="100" height="200" fill="url(#s)"/>'+r}},gp={w:100,h:100,draw({style:e}){if(e==="sci-fi")return ee(fe("p",[[0,"#ff9ad5"],[1,"#6a3cc8"]]),Fe("h",[[0,"#ff9ad5",.5],[1,"#ff9ad5",0]]))+'<circle cx="50" cy="50" r="48" fill="url(#h)"/><circle cx="50" cy="50" r="26" fill="url(#p)"/><ellipse cx="50" cy="52" rx="44" ry="9" fill="none" stroke="#ffd0f0" stroke-width="3" opacity="0.8" transform="rotate(-14 50 52)"/>';let t=e==="post-apocalypse"?"#ff7a3a":e==="cozy"?"#fff2a8":"#fff0c0",r=e==="post-apocalypse"?"#ff5a2a":"#fff6d0";return ee(Fe("h",[[0,r,.85],[.45,r,.35],[1,r,0]]))+`<circle cx="50" cy="50" r="50" fill="url(#h)"/><circle cx="50" cy="50" r="20" fill="${t}"/>`}},Ms=(e,t,r,s,n,o)=>{let a=yr(e),c=Array.from({length:o},()=>s-a()*n);c.push(c[0]);let p=c.map((x,E)=>`${U(E/o*t)},${U(x)}`);return `M0 ${r} L${p.join(" L")} L${t} ${r}Z`},bp={w:512,h:200,band:true,draw({style:e}){let t=sr(e),r=On(t.far1,t.skyBottom,.35);if(e==="sci-fi"){let p=yr(11),x=0,E="",L="";for(;x<500;){let O=26+Math.floor(p()*40),C=50+Math.floor(p()*130),I=Math.min(O,512-x);E+=`<rect x="${x}" y="${200-C}" width="${I}" height="${C}" fill="${p()<.5?t.far1:t.far2}"/>`,p()<.3&&(E+=`<rect x="${x+I/2-1}" y="${200-C-18}" width="2" height="18" fill="${t.far1}"/><circle cx="${x+I/2}" cy="${200-C-18}" r="2" fill="#ff3d6e"/>`);for(let K=200-C+8;K<196;K+=10)for(let ne=x+4;ne<x+I-4;ne+=7)p()<.35&&(L+=`<rect x="${ne}" y="${K}" width="3" height="4" fill="${p()<.5?"#36e3ff":"#ffd36e"}" opacity="0.8"/>`);x+=I+2;}return E+L}if(e==="post-apocalypse"){let p=yr(13),x=6,E=`<path d="${Ms(3,512,200,170,22,8)}" fill="${r}"/>`;for(;x<490;){let L=30+Math.floor(p()*36),C=200-(60+Math.floor(p()*110)),I=p()*20;E+=`<path d="M${x} 200 L${x} ${C+I} L${x+L*.3} ${C} L${x+L*.55} ${C+14+I} L${x+L} ${C+6} L${x+L} 200Z" fill="${p()<.5?t.far1:t.far2}"/>`;for(let K=C+20;K<190;K+=14)for(let ne=x+5;ne<x+L-6;ne+=10)p()<.5&&(E+=`<rect x="${ne}" y="${K}" width="4" height="6" fill="${t.near}" opacity="0.7"/>`);x+=L+8+Math.floor(p()*20);}return E+'<ellipse cx="380" cy="60" rx="60" ry="14" fill="#2a1a14" opacity="0.25"/>'}if(e==="cozy"){let p=[80,230,400].map((x,E)=>`<rect x="${x}" y="${132-E*6}" width="22" height="18" fill="#fff4e8"/><polygon points="${x-3},${133-E*6} ${x+11},${120-E*6} ${x+25},${133-E*6}" fill="${["#ff8f8f","#8fb8ff","#ffb86b"][E]}"/><rect x="${x+8}" y="${140-E*6}" width="6" height="10" fill="#c98b5a"/>`).join("");return `<path d="${Ms(5,512,200,140,30,6)}" fill="${t.far1}"/>`+p+`<path d="${Ms(9,512,200,168,22,5)}" fill="${t.far2}"/>`+[40,170,300,460].map(x=>`<circle cx="${x}" cy="158" r="12" fill="${W(t.far2,.12)}"/>`).join("")}let s=yr(17),n=[],o=[],a=(p,x)=>{n.push(`M${U(p-110)} 200 L${U(p)} ${U(x)} L${U(p+110)} 200Z`),o.push(`M${U(p-24)} ${U(x+26)} L${U(p)} ${U(x)} L${U(p+24)} ${U(x+26)} L${U(p+10)} ${U(x+20)} L${U(p)} ${U(x+28)} L${U(p-10)} ${U(x+20)}Z`);};for(let p=0;p<4;p++){let x=64+p*128+(s()-.5)*30,E=30+s()*40;a(x,E),x-110<0&&a(x+512,E),x+110>512&&a(x-512,E);}let c=e==="fantasy"?`<g fill="${W(t.far2,.15)}"><rect x="300" y="120" width="40" height="80"/><rect x="292" y="104" width="14" height="96"/><rect x="334" y="100" width="14" height="100"/><polygon points="290,104 299,84 308,104"/><polygon points="332,100 341,78 350,100"/>${[300,310,320,330].map(p=>`<rect x="${p}" y="114" width="6" height="8"/>`).join("")}</g><rect x="340" y="82" width="10" height="6" fill="#d0483b"/>`:"";return `<path d="${n.join(" ")}" fill="${r}"/><path d="${o.join(" ")}" fill="#f4f6ff" opacity="0.85"/><path d="${Ms(21,512,200,160,40,9)}" fill="${t.far2}"/>`+c}},xp={w:512,h:160,band:true,draw({style:e}){let t=sr(e),r=yr(29),s=`<rect x="0" y="146" width="512" height="14" fill="${t.near}"/>`;if(e==="sci-fi"){let o=s;for(let a=30;a<500;a+=90+Math.floor(r()*40)){let c=60+r()*70;o+=`<rect x="${a}" y="${150-c}" width="8" height="${c}" fill="${t.near}"/><rect x="${a-14}" y="${150-c}" width="36" height="5" fill="${t.near}"/><circle cx="${a+4}" cy="${146-c}" r="3" fill="#36e3ff"/>`;}return o+=`<path d="M180 150 A40 40 0 0 1 260 150Z" fill="${t.near}"/><path d="M200 140 A22 22 0 0 1 240 140" stroke="#36e3ff" stroke-width="2" fill="none" opacity="0.7"/>`,o}if(e==="post-apocalypse"){let o=s,a=(c,p)=>`<path d="M${c} 150 L${c+3} ${150-p} M${c+2} ${150-p*.6} L${c-14} ${150-p*.85} M${c+2} ${150-p*.45} L${c+18} ${150-p*.7} M${c+3} ${150-p*.8} L${c+12} ${150-p}" stroke="${t.near}" stroke-width="5" stroke-linecap="round" fill="none"/>`;return o+=a(40,90)+a(300,110)+a(460,70),o+=`<rect x="150" y="18" width="5" height="132" fill="${t.near}"/><rect x="138" y="28" width="30" height="4" fill="${t.near}"/><path d="M0 34 Q75 54 152 30 Q260 58 360 34 Q440 50 512 34" stroke="${t.near}" stroke-width="1.5" fill="none"/>`,o+=`<path d="M180 150 L188 128 L232 124 L246 136 L262 138 L262 150Z" fill="${t.near}"/><circle cx="198" cy="150" r="8" fill="#1a120c"/><circle cx="246" cy="150" r="8" fill="#1a120c"/>`,o}if(e==="cozy"){let o=s;for(let a=20;a<500;a+=100+Math.floor(r()*30)){let c=50+r()*30;o+=`<rect x="${a+16}" y="${150-c*.5}" width="8" height="${c*.5}" fill="#9e6a42"/><circle cx="${a+20}" cy="${150-c*.6}" r="${c*.36}" fill="${t.near}"/><circle cx="${a+12}" cy="${150-c*.7}" r="${c*.12}" fill="${X(t.near,.25)}"/>`;}for(let a=4;a<512;a+=16)o+=`<rect x="${a}" y="128" width="8" height="22" rx="3" fill="#fff8f0"/>`;return o+='<rect x="0" y="134" width="512" height="4" fill="#fff8f0"/>',o}let n=s;for(let o=14;o<500;o+=44+Math.floor(r()*50)){let a=70+r()*60,c=a*.36;n+=`<rect x="${o-3}" y="${150-a*.18}" width="6" height="${a*.18}" fill="${W(t.near,.3)}"/>`;for(let p=0;p<3;p++){let x=150-a*.15-p*a*.26,E=c*(1-p*.25);n+=`<polygon points="${U(o-E)},${U(x)} ${U(o)},${U(x-a*.42)} ${U(o+E)},${U(x)}" fill="${p===2?X(t.near,.08):t.near}"/>`;}}return n}};function _c(e,t){let r=sr(e.style);if(e.style==="sci-fi")return `<rect x="0" y="0" width="${t}" height="16" fill="#3a4a72"/><rect x="0" y="0" width="${t}" height="4" fill="${e.c("primary")}"/><rect x="0" y="14" width="${t}" height="3" fill="#11172a"/>`+[16,48,80,112].filter(n=>n<t).map(n=>`<rect x="${n}" y="6" width="14" height="4" rx="2" fill="${e.c("primary")}" opacity="0.5"/>`).join("");if(e.style==="post-apocalypse")return `<path d="M0 0 L${t} 0 L${t} 14 L${t*.8} 18 L${t*.62} 12 L${t*.4} 20 L${t*.2} 13 L0 16Z" fill="#3a3530"/><path d="M${t*.15} 4 L${t*.3} 8 M${t*.6} 3 L${t*.75} 9" stroke="#24201c" stroke-width="2"/>`;if(e.style==="cozy"){let n="";for(let o=0;o<t;o+=32)n+=`<circle cx="${o+16}" cy="14" r="16" fill="${r.crust}"/>`;return `<rect x="0" y="0" width="${t}" height="14" fill="${r.crust}"/>${n}<circle cx="${t*.3}" cy="8" r="3" fill="#fff"/><circle cx="${t*.75}" cy="10" r="3" fill="#ff8fab"/>`}let s="";for(let n=2;n<t;n+=8)s+=`<polygon points="${n},12 ${n+3},${2+n*7%5} ${n+6},12" fill="${X(r.crust,.15)}"/>`;return `<rect x="0" y="6" width="${t}" height="16" fill="${r.crust}"/>${s}<rect x="0" y="20" width="${t}" height="4" fill="${W(r.crust,.3)}"/>`}var kp={w:128,h:512,draw(e){let t=sr(e.style),r=yr(41),s="";for(let n=0;n<14;n++)s+=`<ellipse cx="${U(8+r()*112)}" cy="${U(40+r()*460)}" rx="${U(4+r()*7)}" ry="${U(3+r()*4)}" fill="${W(t.soil,.2+r()*.15)}"/>`;return e.style==="sci-fi"&&(s=[80,180,280,380].map(n=>`<rect x="0" y="${n}" width="128" height="2" fill="#11172a"/>`).join("")+'<rect x="62" y="20" width="2" height="492" fill="#11172a"/>'+[100,300].map(n=>`<circle cx="20" cy="${n}" r="3" fill="#4a5a88"/><circle cx="108" cy="${n}" r="3" fill="#4a5a88"/>`).join("")),ee(fe("d",[[0,t.soil],[1,t.deep]]))+'<rect width="128" height="512" fill="url(#d)"/>'+s+_c(e,128)}},vp={w:128,h:40,draw(e){let t=sr(e.style);return ee(fe("d",[[0,t.soil],[1,t.deep]]))+'<path d="M0 10 L128 10 L128 26 Q96 40 64 36 Q32 40 0 26Z" fill="url(#d)"/>'+_c(e,128)+`<path d="M0 26 Q32 40 64 36 Q96 40 128 26" stroke="${e.ink}" stroke-width="2.5" fill="none" opacity="0.5"/>`}},$p={w:128,h:100,draw(e){let t=sr(e.style);if(e.style==="sci-fi")return `<rect width="128" height="100" fill="${t.road}"/><rect y="0" width="128" height="5" fill="${e.c("primary")}" opacity="0.8"/><rect y="95" width="128" height="5" fill="${e.c("primary")}" opacity="0.8"/><path d="M40 38 L58 50 L40 62 M74 38 L92 50 L74 62" stroke="${e.c("primary")}" stroke-width="5" fill="none" opacity="0.35"/>`;if(e.style==="cozy"){let o="";for(let a=0;a<5;a++)for(let c=a%2*-16;c<128;c+=32)o+=`<rect x="${c+1}" y="${a*20+1}" width="30" height="18" rx="4" fill="${a%2?t.road:X(t.road,.08)}" stroke="${t.edge}" stroke-width="2"/>`;return `<rect width="128" height="100" fill="${t.edge}"/>${o}`}let r=yr(53),s="";for(let o=0;o<12;o++)s+=`<ellipse cx="${U(r()*128)}" cy="${U(10+r()*80)}" rx="${U(2+r()*3)}" ry="${U(1.5+r()*2)}" fill="${W(t.road,.25)}"/>`;let n=e.style==="post-apocalypse"?'<rect x="20" y="47" width="40" height="6" fill="#c9a43a" opacity="0.75"/><path d="M80 20 L96 36 L90 52" stroke="#2a2622" stroke-width="2" fill="none"/>':"";return `<rect width="128" height="100" fill="${t.road}"/><rect width="128" height="6" fill="${t.edge}"/><rect y="94" width="128" height="6" fill="${t.edge}"/>${s}${n}`}},Mp={w:128,h:128,draw({style:e}){let t=sr(e),r=yr(61),s="";if(e==="sci-fi")s=`<rect x="2" y="2" width="60" height="60" rx="4" fill="${t.detail}"/><rect x="66" y="66" width="60" height="60" rx="4" fill="${t.detail}"/><rect x="66" y="2" width="60" height="60" rx="4" fill="${X(t.floor,.05)}"/><rect x="2" y="66" width="60" height="60" rx="4" fill="${X(t.floor,.05)}"/><rect x="62" y="0" width="4" height="128" fill="#36e3ff" opacity="0.18"/><rect x="0" y="62" width="128" height="4" fill="#36e3ff" opacity="0.18"/>`;else if(e==="post-apocalypse")s=`<path d="M10 20 L40 44 L36 70 L60 96 M80 10 L92 40 L120 52 M70 80 L100 110" stroke="${t.detail}" stroke-width="2.5" fill="none"/>`;else for(let n=0;n<18;n++){let o=6+r()*116,a=6+r()*116;s+=`<path d="M${U(o)} ${U(a)} l-3 -6 M${U(o)} ${U(a)} l0 -7 M${U(o)} ${U(a)} l3 -6" stroke="${t.detail}" stroke-width="2" stroke-linecap="round"/>`,e==="cozy"&&n%5===0&&(s+=`<circle cx="${U(o+6)}" cy="${U(a)}" r="2.5" fill="${["#fff","#ff8fab","#ffd166"][n%3]}"/>`);}return `<rect width="128" height="128" fill="${t.floor}"/>${s}`}},Ep=e=>({w:64,h:64,draw({style:t,ink:r}){let s=sr(t),n='<ellipse cx="32" cy="50" rx="20" ry="6" fill="#000" opacity="0.22"/>';if(t==="sci-fi"){let c=[`<rect x="14" y="16" width="36" height="32" rx="4" fill="#4a5a80" stroke="${r}" stroke-width="3"/><rect x="20" y="24" width="24" height="5" fill="#36e3ff"/>`,`<circle cx="32" cy="32" r="16" fill="#2a3452" stroke="${r}" stroke-width="3"/>${[0,1,2,3].map(p=>`<rect x="22" y="${23+p*5}" width="20" height="2" fill="#11172a"/>`).join("")}`,`<rect x="6" y="28" width="52" height="10" rx="5" fill="#5d6f96" stroke="${r}" stroke-width="3"/><circle cx="18" cy="33" r="3" fill="#ff3d6e"/>`,'<circle cx="32" cy="32" r="8" fill="#b45cff"/><circle cx="32" cy="32" r="14" fill="none" stroke="#b45cff" stroke-width="2" opacity="0.5"/>'];return n+c[(e-1)%4]}if(t==="post-apocalypse"){let c=[`<circle cx="32" cy="32" r="18" fill="#1e1a16" stroke="${r}" stroke-width="3"/><circle cx="32" cy="32" r="8" fill="${s.floor}"/>`,`<circle cx="32" cy="32" r="16" fill="#8a3d24" stroke="${r}" stroke-width="3"/><circle cx="32" cy="32" r="10" fill="none" stroke="#5a2814" stroke-width="2"/>`,`<polygon points="10,40 22,22 38,30 52,18 54,44 30,48" fill="#6b6358" stroke="${r}" stroke-width="3" stroke-linejoin="round"/>`,'<path d="M20 44 L24 20 M32 46 L32 16 M42 44 L38 22" stroke="#7a6a3a" stroke-width="3" stroke-linecap="round"/>'];return n+c[(e-1)%4]}let o=t==="cozy"?"#6fc46a":"#3f7f3a",a=[`<circle cx="22" cy="34" r="12" fill="${o}" stroke="${r}" stroke-width="3"/><circle cx="42" cy="34" r="12" fill="${o}" stroke="${r}" stroke-width="3"/><circle cx="32" cy="24" r="13" fill="${X(o,.1)}" stroke="${r}" stroke-width="3"/>`,`<path d="M12 44 Q14 22 32 20 Q50 22 52 44Z" fill="#9aa0a8" stroke="${r}" stroke-width="3"/><path d="M22 28 Q30 24 36 26" stroke="#fff" stroke-width="3" opacity="0.5" fill="none"/>`,[[22,28],[40,24],[32,40],[46,40]].map(([c,p],x)=>`<polygon points="${Qe(c,p,7,3,5)}" fill="${["#ff8fab","#ffd166","#fff","#c39bff"][x]}" stroke="${r}" stroke-width="1.5"/>`).join(""),t==="cozy"?`<rect x="28" y="30" width="8" height="16" fill="#fff4e6" stroke="${r}" stroke-width="2.5"/><path d="M14 32 Q32 8 50 32Z" fill="#ff6b6b" stroke="${r}" stroke-width="3"/><circle cx="26" cy="24" r="3" fill="#fff"/><circle cx="38" cy="26" r="2.5" fill="#fff"/>`:`<ellipse cx="32" cy="38" rx="16" ry="9" fill="#8a5a32" stroke="${r}" stroke-width="3"/><ellipse cx="32" cy="34" rx="16" ry="9" fill="#c49a6a" stroke="${r}" stroke-width="3"/><ellipse cx="32" cy="34" rx="8" ry="4" fill="none" stroke="#8a5a32" stroke-width="2"/>`];return n+a[(e-1)%4]}}),Sp={w:0,h:0,exact:true,main:"ground",draw({style:e,w:t,h:r}){let s=sr(e),n=yr(Math.round(t*13+r)),o="";for(let a=0;a<4;a++){let c=t*(.15+n()*.7),p=r*(.2+n()*.65);o+=e==="sci-fi"?`<circle cx="${U(c)}" cy="${U(p)}" r="${U(t*.02)}" fill="#4a5a88"/>`:`<path d="M${U(c)} ${U(p)} l${U(-t*.04)} ${U(-r*.08)} M${U(c)} ${U(p)} l0 ${U(-r*.1)} M${U(c)} ${U(p)} l${U(t*.04)} ${U(-r*.08)}" stroke="${s.detail}" stroke-width="${U(t*.025)}" stroke-linecap="round"/>`;}return `<rect width="${t}" height="${r}" fill="${s.floor}"/><rect x="0.5" y="0.5" width="${t-1}" height="${r-1}" fill="none" stroke="${W(s.floor,.25)}" stroke-opacity="0.35" stroke-width="1"/>${o}`}},wp={w:0,h:0,exact:true,main:"lane",draw({style:e,w:t,h:r,c:s}){let n=sr(e),o=yr(Math.round(t*7+r*3)),a="";for(let p=0;p<5;p++)a+=`<ellipse cx="${U(t*(.15+o()*.7))}" cy="${U(r*(.15+o()*.7))}" rx="${U(t*(.04+o()*.05))}" ry="${U(r*.035)}" fill="${W(n.road,.18)}"/>`;let c=e==="sci-fi"?`<rect x="${U(t*.42)}" y="${U(r*.42)}" width="${U(t*.16)}" height="${U(r*.16)}" rx="2" fill="${s("primary")}" opacity="0.45"/>`:"";return `<rect width="${t}" height="${r}" fill="${n.road}"/>${a}${c}`}},Lp=e=>({w:100,h:130,main:"primary",draw({style:t,ink:r,main:s,c:n}){let o='<ellipse cx="50" cy="122" rx="38" ry="8" fill="#000" opacity="0.28"/>';if(t==="sci-fi"||t==="post-apocalypse"){let C=t==="sci-fi"?"#5d6f96":"#7a6a52",I=t==="sci-fi"?s:n("coin"),K=Array.from({length:e},(V,ce)=>`<rect x="50" y="${52-(e-1)*5+ce*10}" width="${36+e*2}" height="8" rx="3" fill="${W(C,.25)}" stroke="${r}" stroke-width="2.5"/>`).join(""),ne=t==="post-apocalypse"?[0,1,2].map(V=>`<ellipse cx="${26+V*24}" cy="106" rx="14" ry="9" fill="#a89070" stroke="${r}" stroke-width="2.5"/>`).join("")+[0,1].map(V=>`<ellipse cx="${38+V*24}" cy="94" rx="14" ry="9" fill="#b8a080" stroke="${r}" stroke-width="2.5"/>`).join(""):`<polygon points="${Lt(50,100,34,6,0)}" fill="#2a3452" stroke="${r}" stroke-width="3.5"/><polygon points="${Lt(50,100,22,6,0)}" fill="${I}" opacity="0.4"/>`;return o+ne+`<rect x="38" y="64" width="24" height="30" fill="${C}" stroke="${r}" stroke-width="3"/>`+K+`<path d="M24 68 A26 26 0 0 1 76 68Z" fill="${X(C,.15)}" stroke="${r}" stroke-width="3.5"/><circle cx="50" cy="56" r="${5+e}" fill="${I}" stroke="${r}" stroke-width="2.5"/>`}let a=t==="cozy"?"#f4e6d4":"#a7a9b2",c=t==="cozy"?n("primary"):s,p=70-e*14,x="";for(let C=p+10;C<112;C+=12)x+=`<line x1="26" y1="${C}" x2="74" y2="${C}" stroke="${W(a,.25)}" stroke-width="2"/>`+[0,1].map(I=>`<line x1="${36+I*16+C/12%2*8}" y1="${C}" x2="${36+I*16+C/12%2*8}" y2="${C+12}" stroke="${W(a,.25)}" stroke-width="2"/>`).join("");let E=[26,40,54,68].map(C=>`<rect x="${C}" y="${p-10}" width="8" height="12" fill="${a}" stroke="${r}" stroke-width="2.5"/>`).join(""),L=e>=2?`<polygon points="20,${p-2} 50,${p-44} 80,${p-2}" fill="${c}" stroke="${r}" stroke-width="3.5" stroke-linejoin="round"/><polygon points="20,${p-2} 50,${p-44} 40,${p-2}" fill="${X(c,.2)}"/>`:E,O=e>=3?`<line x1="50" y1="${p-44}" x2="50" y2="${p-64}" stroke="${r}" stroke-width="3"/><path d="M50 ${p-64} L70 ${p-58} L50 ${p-52}Z" fill="${n("coin")}" stroke="${r}" stroke-width="2"/>`:"";return o+ee(fe("s",[[0,X(a,.2)],[1,W(a,.2)]],true))+`<rect x="24" y="${p}" width="52" height="${116-p}" fill="url(#s)" stroke="${r}" stroke-width="3.5"/>`+x+`<rect x="44" y="${p+16}" width="12" height="18" rx="6" fill="#2a2030" stroke="${r}" stroke-width="2.5"/><path d="M42 116 L42 100 A8 8 0 0 1 58 100 L58 116Z" fill="#6a4628" stroke="${r}" stroke-width="2.5"/>`+L+O}}),_p=e=>({w:120,h:120,main:`piece${e}`,draw({style:t,ink:r,main:s,c:n}){let o=sr(t),a=t==="cozy"?X(s,.6):o.wall,c=t==="sci-fi"?n("primary"):t==="post-apocalypse"?"#3a3530":"#9fd2f0",p=(L,O,C=12,I=14)=>`<rect x="${L}" y="${O}" width="${C}" height="${I}" rx="2" fill="${c}" stroke="${r}" stroke-width="2"/>`+(t==="post-apocalypse"?`<path d="M${L} ${O+3} L${L+C} ${O+I-3}" stroke="#8a6a3a" stroke-width="3"/>`:`<rect x="${L+2}" y="${O+2}" width="${C*.3}" height="${I*.4}" fill="#fff" opacity="0.5"/>`),x='<ellipse cx="60" cy="114" rx="50" ry="6" fill="#000" opacity="0.25"/>',E=(L,O,C)=>{let I="";for(let K=0;K<C;K+=12)I+=`<path d="M${L+K} ${O} h12 v10 q-6 6 -12 0Z" fill="${K/12%2?"#fff":s}" stroke="${r}" stroke-width="2"/>`;return I};switch(e){case 1:return x+`<rect x="22" y="64" width="76" height="46" fill="${a}" stroke="${r}" stroke-width="3"/><rect x="16" y="60" width="88" height="8" fill="${W(a,.2)}" stroke="${r}" stroke-width="3"/><rect x="28" y="30" width="4" height="34" fill="${r}"/><rect x="88" y="30" width="4" height="34" fill="${r}"/>`+E(22,24,76)+`<circle cx="44" cy="56" r="6" fill="${n("coin")}" stroke="${r}" stroke-width="2"/><circle cx="60" cy="54" r="7" fill="${s}" stroke="${r}" stroke-width="2"/><circle cx="76" cy="56" r="6" fill="${n("accent")}" stroke="${r}" stroke-width="2"/>`;case 2:return x+`<rect x="18" y="40" width="84" height="70" fill="${a}" stroke="${r}" stroke-width="3"/><polygon points="12,42 60,14 108,42" fill="${o.roof}" stroke="${r}" stroke-width="3" stroke-linejoin="round"/>`+E(22,54,76)+p(28,72,28,24)+`<rect x="68" y="72" width="22" height="38" fill="${W(s,.2)}" stroke="${r}" stroke-width="3"/>`;case 3:return x+`<rect x="20" y="26" width="80" height="84" fill="${a}" stroke="${r}" stroke-width="3"/><rect x="14" y="18" width="92" height="10" fill="${o.roof}" stroke="${r}" stroke-width="3"/>`+p(30,36)+p(54,36)+p(78,36)+E(20,62,80)+p(30,78,26,22)+`<rect x="66" y="78" width="22" height="32" fill="${W(s,.25)}" stroke="${r}" stroke-width="3"/><rect x="42" y="4" width="36" height="16" rx="4" fill="${s}" stroke="${r}" stroke-width="2.5"/><path d="M54 8 h10 v6 a4 4 0 0 1 -10 0Z" fill="#fff"/>`;case 4:return x+`<rect x="80" y="14" width="12" height="40" fill="${W(o.wall,.35)}" stroke="${r}" stroke-width="3"/><circle cx="90" cy="8" r="7" fill="#cfcfd8" opacity="0.75"/><circle cx="100" cy="2" r="5" fill="#cfcfd8" opacity="0.5"/><path d="M12 110 L12 50 L36 36 L36 50 L60 36 L60 50 L84 36 L84 50 L108 50 L108 110Z" fill="${W(a,.08)}" stroke="${r}" stroke-width="3" stroke-linejoin="round"/>`+p(22,62)+p(46,62)+p(70,62)+`<rect x="40" y="84" width="40" height="26" fill="${s}" stroke="${r}" stroke-width="3"/>`+[0,1,2].map(L=>`<line x1="40" y1="${90+L*7}" x2="80" y2="${90+L*7}" stroke="${W(s,.35)}" stroke-width="2"/>`).join("");case 5:return x+`<polygon points="8,42 60,12 112,42" fill="${X(o.wall,.15)}" stroke="${r}" stroke-width="3" stroke-linejoin="round"/><circle cx="60" cy="32" r="8" fill="${n("coin")}" stroke="${r}" stroke-width="2.5"/><rect x="14" y="42" width="92" height="8" fill="${W(o.wall,.1)}" stroke="${r}" stroke-width="3"/>`+[20,40,72,92].map(L=>`<rect x="${L}" y="50" width="8" height="52" fill="${X(o.wall,.2)}" stroke="${r}" stroke-width="2.5"/>`).join("")+`<rect x="50" y="62" width="20" height="40" fill="${s}" stroke="${r}" stroke-width="3"/><rect x="10" y="102" width="100" height="8" fill="${W(o.wall,.15)}" stroke="${r}" stroke-width="3"/>`;default:{let L="";for(let O=22;O<92;O+=18)L+=p(40,O,12,12)+p(62,O,12,12);return x+`<rect x="58" y="2" width="3" height="14" fill="${r}"/><circle cx="59.5" cy="2" r="3" fill="${n("danger")}"/><rect x="32" y="14" width="56" height="96" fill="${t==="cozy"?a:On(o.wall,s,.25)}" stroke="${r}" stroke-width="3"/>`+L+`<rect x="50" y="94" width="20" height="16" fill="${W(s,.25)}" stroke="${r}" stroke-width="2.5"/>`}}}}),Rc={sky:yp,sun:gp,far:bp,near:xp,ground:kp,platform:vp,road:$p,floor:Mp,tile_grass:Sp,tile_road:wp,...Object.fromEntries([1,2,3,4].map(e=>[`decor${e}`,Ep(e)])),...Object.fromEntries([1,2,3].map(e=>[`tower${e}`,Lp(e)])),...Object.fromEntries([1,2,3,4,5,6].map(e=>[`biz${e}`,_p(e)]))};var Oo=(e,t,r,s,n=.28)=>`<ellipse cx="${e}" cy="${t}" rx="${r}" ry="${s}" fill="#000" opacity="${n}"/>`,ya=(e,t=4,r=.55)=>`<path d="${e}" fill="none" stroke="#fff" stroke-width="${t}" stroke-linecap="round" opacity="${r}"/>`,Nr=e=>({w:100,h:100,draw:({ink:t})=>e(t)}),Rp={w:120,h:120,main:"danger",draw({style:e,ink:t,main:r,c:s}){let n=sr(e),o=Array.from({length:9},(a,c)=>`<circle cx="${24+c*9}" cy="30" r="2.6" fill="${s("coin")}" stroke="${t}" stroke-width="1"/>`).join("");return Oo(60,114,50,6,.25)+`<rect x="14" y="40" width="92" height="70" fill="${n.wall}" stroke="${t}" stroke-width="3"/><rect x="10" y="18" width="100" height="24" rx="4" fill="${r}" stroke="${t}" stroke-width="3"/>`+o+`<rect x="34" y="46" width="52" height="22" rx="3" fill="${W(n.wall,.6)}" stroke="${t}" stroke-width="2.5"/><polygon points="54,51 54,63 66,57" fill="${s("coin")}"/><rect x="24" y="76" width="30" height="34" fill="${W(r,.25)}" stroke="${t}" stroke-width="3"/><rect x="66" y="76" width="30" height="34" fill="${W(r,.25)}" stroke="${t}" stroke-width="3"/><line x1="39" y1="76" x2="39" y2="110" stroke="${t}" stroke-width="2"/><line x1="81" y1="76" x2="81" y2="110" stroke="${t}" stroke-width="2"/><polygon points="${Qe(60,9,8,3.5)}" fill="${s("coin")}" stroke="${t}" stroke-width="2"/>`}},Ap={w:120,h:120,main:"primary",draw({style:e,ink:t,main:r,c:s}){let n=sr(e);return Oo(60,114,52,6,.25)+`<path d="M8 110 L8 84 Q60 62 112 84 L112 110Z" fill="${n.wall}" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><rect x="16" y="90" width="14" height="10" rx="2" fill="#9fd2f0" stroke="${t}" stroke-width="2"/><rect x="90" y="90" width="14" height="10" rx="2" fill="#9fd2f0" stroke="${t}" stroke-width="2"/><rect x="78" y="22" width="6" height="66" fill="${W(n.wall,.35)}" stroke="${t}" stroke-width="2.5"/>`+[34,50,66].map(o=>`<line x1="84" y1="${o}" x2="70" y2="${o}" stroke="${t}" stroke-width="2.5"/>`).join("")+`<path d="M60 6 Q72 22 70 64 L50 64 Q48 22 60 6Z" fill="${X(r,.75)}" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><circle cx="60" cy="34" r="6" fill="#9fd2f0" stroke="${t}" stroke-width="2.5"/><path d="M50 52 L40 70 L50 66Z M70 52 L80 70 L70 66Z" fill="${r}" stroke="${t}" stroke-width="2.5" stroke-linejoin="round"/><path d="M54 64 L60 82 L66 64Z" fill="${s("coin")}" stroke="${t}" stroke-width="2"/><path d="M57 64 L60 74 L63 64Z" fill="#fff"/>`}},Ac=(e,t)=>Nr(r=>`<circle cx="50" cy="50" r="44" fill="${X(e,.7)}" stroke="${r}" stroke-width="4"/><path d="M50 12 L76 40 L60 40 L60 62 L40 62 L40 40 L24 40Z" fill="${e}" stroke="${r}" stroke-width="3.5" stroke-linejoin="round"/><text x="50" y="88" text-anchor="middle" font-family="Arial, sans-serif" font-weight="900" font-size="24" fill="${r}">${t}</text>`),Dp=Nr(e=>`<circle cx="50" cy="50" r="44" fill="#ffe8a8" stroke="${e}" stroke-width="4"/>`+[30,50,70].map((t,r)=>`<path d="M${t} ${16+(r===1?0:8)} L${t+13} ${32+(r===1?0:8)} L${t+6} ${32+(r===1?0:8)} L${t+6} 56 L${t-6} 56 L${t-6} ${32+(r===1?0:8)} L${t-13} ${32+(r===1?0:8)}Z" fill="#ffb21a" stroke="${e}" stroke-width="2.5" stroke-linejoin="round"/>`).join("")+`<text x="50" y="88" text-anchor="middle" font-family="Arial, sans-serif" font-weight="900" font-size="24" fill="${e}">\xD72</text>`),Tp=Nr(e=>ee(Fe("r",[[0,"#fff6a0"],[1,"#ff7a1a"]],.5,.6))+`<path d="M50 8 Q70 30 66 46 Q78 40 76 26 Q92 46 86 66 Q80 90 50 92 Q20 90 14 66 Q10 46 26 30 Q28 46 38 48 Q30 26 50 8Z" fill="url(#r)" stroke="${e}" stroke-width="3.5" stroke-linejoin="round"/><text x="50" y="76" text-anchor="middle" font-family="Arial, sans-serif" font-weight="900" font-size="30" fill="#fff" stroke="${e}" stroke-width="2">\xD73</text>`),Op=Nr(e=>Oo(50,92,24,4)+`<path d="M30 80 L62 46" stroke="${e}" stroke-width="16" stroke-linecap="round"/><path d="M30 80 L62 46" stroke="#a8b2c2" stroke-width="10" stroke-linecap="round"/><path d="M58 24 A20 20 0 1 0 80 50 L70 50 L62 42 L62 30Z" fill="#c8d0dc" stroke="${e}" stroke-width="3.5" stroke-linejoin="round"/>`+ya("M66 22 Q76 24 80 32",3,.7)+`<circle cx="26" cy="22" r="10" fill="#e8384a" stroke="${e}" stroke-width="3"/><path d="M26 15 L26 23 M26 27 L26 28" stroke="#fff" stroke-width="3.5" stroke-linecap="round"/>`),Cp=Nr(e=>ee(fe("c",[[0,"#8a5a32"],[1,"#5a381c"]]))+Oo(50,90,34,5)+`<path d="M38 26 L38 18 Q38 14 42 14 L58 14 Q62 14 62 18 L62 26" fill="none" stroke="${e}" stroke-width="5"/><rect x="12" y="26" width="76" height="56" rx="8" fill="url(#c)" stroke="${e}" stroke-width="4"/><line x1="12" y1="46" x2="88" y2="46" stroke="${e}" stroke-width="3"/><rect x="44" y="40" width="12" height="12" rx="2" fill="#ffc83a" stroke="${e}" stroke-width="2.5"/><text x="50" y="74" text-anchor="middle" font-family="Arial, sans-serif" font-weight="900" font-size="20" fill="#ffd34a">$</text>`+ya("M20 32 L40 32",3,.5)),Pp=Nr(e=>`<circle cx="50" cy="50" r="44" fill="#d8ecff" stroke="${e}" stroke-width="4"/><circle cx="50" cy="36" r="14" fill="#f4c9a0" stroke="${e}" stroke-width="3"/><path d="M36 30 Q50 14 64 30 Q60 22 50 22 Q40 22 36 30Z" fill="#5a381c" stroke="${e}" stroke-width="2"/><path d="M22 86 Q22 56 50 54 Q78 56 78 86Z" fill="#3a4a72" stroke="${e}" stroke-width="3" stroke-linejoin="round"/><path d="M46 56 L54 56 L56 76 L50 82 L44 76Z" fill="#e8384a" stroke="${e}" stroke-width="2" stroke-linejoin="round"/>`),Ip=Nr(e=>`<circle cx="48" cy="54" r="34" fill="#fff" stroke="${e}" stroke-width="4"/><path d="M48 54 L48 32 M48 54 L64 62" stroke="${e}" stroke-width="5" stroke-linecap="round"/><path d="M74 10 Q86 22 82 34 Q92 30 90 20 Q100 34 92 46 Q84 56 72 50 Q62 42 68 30 Q72 36 76 34 Q70 22 74 10Z" fill="#ff7a1a" stroke="${e}" stroke-width="2.5" stroke-linejoin="round"/><rect x="40" y="12" width="16" height="8" rx="3" fill="#8a96aa" stroke="${e}" stroke-width="2.5"/>`),zp=Nr(e=>ee(Fe("i",[[0,"#fff6a0"],[1,"#ffb000"]],.45,.4))+`<circle cx="50" cy="50" r="42" fill="url(#i)" stroke="${e}" stroke-width="4"/><path d="M58 10 L28 54 L48 54 L40 90 L74 42 L54 42Z" fill="#fff" stroke="${e}" stroke-width="3.5" stroke-linejoin="round"/>`+[[18,24],[82,74],[20,78]].map(([t,r])=>`<polygon points="${Qe(t,r,7,2.5,4)}" fill="#fff" stroke="${e}" stroke-width="1.5"/>`).join("")),Np=Nr(e=>Oo(50,92,24,4)+`<path d="M14 46 L46 12 L86 12 L86 52 L52 86Z" fill="#ff5a7a" stroke="${e}" stroke-width="4" stroke-linejoin="round"/><circle cx="72" cy="26" r="7" fill="#fff" stroke="${e}" stroke-width="3"/><text x="54" y="62" text-anchor="middle" font-family="Arial, sans-serif" font-weight="900" font-size="24" fill="#fff" stroke="${e}" stroke-width="1.5" transform="rotate(-45 54 54)">%</text>`+ya("M48 18 L24 44",3,.6)),Dc={ty_cinema:Rp,ty_port:Ap,ty_up:Ac("#5ad35a","\xD72"),ty_up3:Ac("#4aa8ff","\xD73"),ty_upall:Dp,ty_rush:Tp,ty_wrench:Op,ty_investor:Cp,ty_manager:Pp,ty_sk_rush:Ip,ty_sk_instant:zp,ty_sk_sale:Np};var Es=Object.freeze({...hc,...mc,...yc,...gc,...xc,...Mc,...wc,...Dc,...Rc,...uc}),Wp=e=>Object.prototype.hasOwnProperty.call(Es,e);function jp(e,t){let r=Es[e];return r?r.exact?t.w/Math.max(1,t.h):r.w/r.h:1}function Hp(e,t){let r=Es[e];if(!r)return null;let{palette:s,style:n,box:o,px:a}=t,c=I=>ia(I,s),p=r.exact?o.w:r.w,x=r.exact?o.h:r.h,E=r.draw({style:n,c,main:c(t.color??r.main??"primary"),ink:fc(n),w:p,h:x}),L=Math.max(1,Math.round(a.h)),O=Math.max(0,Math.round(t.padBottom??0)),C=O>0?x*(L+O)/L:x;return `<svg xmlns="http://www.w3.org/2000/svg" width="${Math.max(1,Math.round(a.w))}" height="${L+O}" viewBox="0 0 ${p} ${C}" preserveAspectRatio="none">${E}</svg>`}var Ne=e=>({w:Number(e.vars.view_w??720),h:Number(e.vars.view_h??1280)}),rt=e=>e.vars.state==="playing",tn=e=>e.vars.started_tick===e.tick,Ke=(e,t,r)=>{let s=Number(e.vars[t]??0)+r;return e.vars[t]=s,s},cr=(e,t)=>Number(e[t]);function At(e,t,r,s,n){let o=e.create();return e.set(o,G,{x:t,y:r}),e.set(o,te,s),n&&e.set(o,n.type,n.data),o}var at=(e,t)=>{for(let r of e.query(t))e.destroy(r);};function Wn(e){let t=new Set,r={down:false,x:0,y:0};return e.on(Tt,s=>{let n=s;n.type==="key"?t.add(n.key):n.type==="key-up"?t.delete(n.key):n.type==="press"||n.type==="move"?(r.down=true,r.x=n.x,r.y=n.y):n.type==="release"&&(r.down=false);}),{keys:t,pointer:r,axis(){return {x:(t.has("right")?1:0)-(t.has("left")?1:0),y:(t.has("down")?1:0)-(t.has("up")?1:0)}}}}function rn(e,t,r,s){let n=e.h*(s.bottom-s.top),o=Math.floor(Math.min(e.w*(s.widthShare??.94)/t,n/r)),a=(e.w-o*t)/2,c=e.h*s.top+(n-o*r)/2;return {cols:t,rows:r,cell:o,left:a,top:c}}var nt=(e,t,r)=>({x:e.left+e.cell*(t+.5),y:e.top+e.cell*(r+.5)});function Wr(e,t,r){let s=Math.floor((t-e.left)/e.cell),n=Math.floor((r-e.top)/e.cell);return s>=0&&s<e.cols&&n>=0&&n<e.rows?{col:s,row:n}:null}var Cc=["piece1","piece2","piece3","piece4","piece5","piece6"];$e("kit.status");var ws=e=>{let t=Math.max(0,Math.ceil(e));return `${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`},H=(e,t)=>e.emit(ca,t),Nn=$e("kit.backdrop");function Ot(e,t,r,s={}){for(let E of e.query(Nn))e.destroy(E);let n=Ne(e),o=(E,L,O,C)=>At(e,L,O,C,{type:Nn,data:{speed:E}});if(t==="top"){let E=s.pan?1:0;o(E,n.w/2,n.h/2,{shape:"tile",art:"floor",w:n.w,h:n.h,unit:Math.min(n.w,n.h)*.24,depth:-100});let L=e.rng.stream("backdrop"),O=Math.round(n.w*n.h/52e3),C=Math.min(n.w,n.h);for(let I=0;I<O;I++){let K=C*L.range(.06,.1);o(E,L.range(0,n.w),L.range(0,n.h),{shape:"sprite",art:`decor${L.int(1,4)}`,w:K,h:K,depth:-95});}return}let a=r??n.h*.62;o(0,n.w/2,n.h/2,{shape:"sprite",art:"sky",w:n.w,h:n.h,depth:-100});let c=Math.min(n.w,n.h)*.34;o(.02,n.w*.74,a*.3,{shape:"sprite",art:"sun",w:c,h:c,depth:-99});let p=Math.min(n.h*.32,n.w*.55);o(.12,n.w/2,a-p/2,{shape:"tile",art:"far",w:n.w,h:p,depth:-90});let x=p*.62;o(.4,n.w/2,a-x/2+2,{shape:"tile",art:"near",w:n.w,h:x,depth:-80}),t==="board"?o(0,n.w/2,(n.h+a)/2,{shape:"tile",art:"ground",w:n.w,h:n.h-a+4,unit:p*.7,depth:-79}):o(0,n.w/2,(n.h+a)/2,{shape:"rect",w:n.w,h:n.h-a,color:"#140f0c",alpha:.92,depth:-79});}function Co(e,t){for(let r of e.query(Nn)){let s=e.need(r,Nn).speed;if(s<=0)continue;let n=e.need(r,te);n.shape==="tile"&&(n.scrollX=(n.scrollX??0)+t*s);}}function Pc(e,t,r){let s=Ne(e),n=Math.min(s.w,s.h)*.1;for(let o of e.query(Nn)){if(e.need(o,Nn).speed<=0)continue;let a=e.need(o,te);if(a.shape==="tile"){a.scrollX=(a.scrollX??0)+t,a.scrollY=(a.scrollY??0)+r;continue}let c=e.need(o,G);c.x-=t,c.y-=r,c.x<-n?c.x+=s.w+2*n:c.x>s.w+n&&(c.x-=s.w+2*n),c.y<-n?c.y+=s.h+2*n:c.y>s.h+n&&(c.y-=s.h+2*n);}}function ot(e,t,r){let s=e.get(t,te);s?.shape==="actor"&&(s.pose=r);}function Ge(e,t,r){let s=e.get(t,te);s?.shape==="actor"&&(s.act=r,s.actN=(s.actN??0)+1);}var zn=$e("kit.fading"),Tc=new WeakSet;function mn(e,t,r){e.set(t,zn,{left:r,total:r}),!Tc.has(e)&&(Tc.add(e),e.addSystem({id:"kit.fading",order:90,run(s,n){for(let o of s.query(zn)){let a=s.need(o,zn);a.left-=n;let c=s.get(o,te);c&&(c.alpha=Math.max(0,Math.min(1,a.left/a.total*2))),a.left<=0&&s.destroy(o);}}}));}var qt=(e,t,r=5)=>r+t/Math.max(1,Ne(e).h),In=$e("kit.hint"),Oc=new WeakSet,Ss=(e,t,r)=>({x:e+r*.11,y:t+r*.42});function bt(e,t,r,s=r,n){Ct(e);let o=n??Math.min(Ne(e).w,Ne(e).h)*.13,a={kind:t,ax:r.x,ay:r.y,bx:s.x,by:s.y,size:o,t:0},c=Ss(r.x,r.y,o);At(e,r.x,r.y,{shape:"circle",r:o*.22,color:"#ffffff",alpha:0,depth:89},{type:In,data:{...a,part:"ring"}}),At(e,c.x,c.y,{shape:"sprite",art:"hand",w:o,h:o,alpha:0,depth:90},{type:In,data:{...a,part:"hand"}}),!Oc.has(e)&&(Oc.add(e),e.addSystem({id:"kit.hints",order:95,run(p,x){for(let E of p.query(In)){let L=p.need(E,In);L.t+=x;let O=p.need(E,G),C=p.need(E,te);if(L.kind==="tap"){let I=L.t%1.2/1.2,K=I>.35&&I<.55;if(L.part==="hand"){let ne=Ss(L.ax,L.ay+(K?L.size*.06:0),L.size);O.x=ne.x,O.y=ne.y,O.scale=K?.9:1,C.alpha=Math.min(1,L.t*4);}else {let ne=I<.4?0:(I-.4)/.6;O.scale=1+ne*2.2,C.alpha=I<.4?0:.55*(1-ne);}}else if(L.kind==="swipe"){let I=L.t%1.6/1.6,K=I<.15?0:I>.75?1:(I-.15)/.6,ne=K*K*(3-2*K),V=L.ax+(L.bx-L.ax)*ne,ce=L.ay+(L.by-L.ay)*ne;if(L.part==="hand"){let oe=Ss(V,ce,L.size);O.x=oe.x,O.y=oe.y,C.alpha=I<.1?I*10:I>.85?Math.max(0,(1-I)/.15):1;}else O.x=V,O.y=ce,C.alpha=I>.15&&I<.8?.35:0;}else {let I=L.t*3,K=L.ax+Math.cos(I)*L.bx,ne=L.ay+Math.sin(I)*L.bx;if(L.part==="hand"){let V=Ss(K,ne,L.size);O.x=V.x,O.y=V.y,C.alpha=Math.min(1,L.t*3);}else O.x=K,O.y=ne,C.alpha=.3;}}}}));}function Ct(e){for(let t of e.query(In))e.destroy(t);}var kr=e=>e.query(In).length>0,xt=(e,t)=>e.vars[`learned:${t}`]===true;function $t(e,t){xt(e,t)||(e.vars[`learned:${t}`]=true,Ct(e));}var jn=$e("round.start"),Ht="round-started",Bt="round-over",Vt="round-ended",ga="start-round",Gt="show-start",Kt="revive-offer",Zt="revive",Qt="give-up",Ls={id:"round",version:1,setup({world:e}){e.vars.state="ready",e.vars.score=0,e.vars.coins=0,e.vars.best=typeof e.vars.best=="number"?e.vars.best:0,e.vars.round=0;let t=s=>{for(let c of s.query(jn))s.destroy(c);if(s.vars.state!=="ready")return;let n=Ne(s),o=Math.min(n.w,n.h)*.26,a={x:n.w/2,y:n.h*.55};At(s,n.w/2,n.h/2,{shape:"rect",w:n.w,h:n.h,color:"#05040a",alpha:.4,depth:84},{type:jn,data:{t:-1}}),At(s,a.x,a.y,{shape:"sprite",art:"play",w:o,h:o,color:"accent",depth:85},{type:jn,data:{t:0}}),bt(s,"tap",{x:a.x+o*.12,y:a.y+o*.1});},r=()=>{for(let s of e.query(jn))e.destroy(s);Ct(e),e.vars.state="playing",e.vars.score=0,e.vars.coins=0,e.vars.round=Number(e.vars.round??0)+1,e.vars.started_tick=e.tick,e.emit(Ht,{round:e.vars.round});};e.on(Tt,s=>{let n=s;e.vars.state==="ready"&&(n.type==="tap"||n.type==="key"&&n.key==="action")&&r();}),e.on(ga,()=>{e.vars.state!=="playing"&&r();}),e.on(Gt,()=>{e.vars.state==="ended"&&(e.vars.state="ready",t(e));}),e.on(jt,()=>t(e)),e.addSystem({id:"round.start",order:96,run(s,n){for(let o of s.query(jn)){let a=s.need(o,jn);a.t<0||(a.t+=n,s.need(o,G).scale=1+.06*Math.sin(a.t*5));}}}),t(e),e.on(Bt,s=>{if(e.vars.state!=="playing")return;e.vars.state="ended",Ct(e);let n=Number(e.vars.score??0),o=Math.max(Number(e.vars.best??0),n);e.vars.best=o,e.emit(Vt,{score:n,coins:Number(e.vars.coins??0),best:o,reason:typeof s.reason=="string"?s.reason:"over",...s.stats&&typeof s.stats=="object"?{stats:s.stats}:{}});});}};var _s=["wall","barrier","pit","mover","train","rock"];var Io=["magnet","shield","double","dash","flight"],vr={magnet:{art:"magnet",color:"danger",seconds:6,var:"meta:magnet_t",weight:3},shield:{art:"shield",color:"muted",seconds:8,var:"meta:shield_t",weight:2.5},double:{art:"coin2x",color:"coin",seconds:8,var:"meta:double_t",weight:2.5},dash:{art:"boot",color:"accent",seconds:2.5,var:"meta:dash_t",weight:1.5},flight:{art:"wing",color:"secondary",seconds:4,var:"meta:flight_t",weight:1}},Po=20,Ic={wall:1,barrier:2,pit:3,mover:4,train:5,rock:6};function Hn(e,t=.5){let r=Math.max(1,Math.min(Po,Math.floor(e))),s=(r-1)/(Po-1),n=_s.filter(c=>Ic[c]<=r),o=_s.find(c=>Ic[c]===r)??null,a=330+t*120+s*220;return {level:r,length:Math.round(16e3+(r-1)*3e3),speed:a,topSpeed:a*(1.25+s*.1),density:Math.min(.72,.3+t*.12+s*.3),kinds:n,fresh:o,coinStar:.6,firstClearGold:60+(r-1)*25}}var Bn=e=>Math.floor(e/30),Vn=[{id:"hero",cast:"hero",gems:0,perk:"none"},{id:"hero2",cast:"hero2",gems:150,perk:"heart"},{id:"hero3",cast:"hero3",gems:300,perk:"power"}],ba="kit-runner",xa=[{id:"MagnetTime",var:"meta:magnet_t",art:"magnet",color:"danger",perLevel:.6,unit:"s",maxLevel:15,price:20,growth:.12},{id:"ShieldTime",var:"meta:shield_t",art:"shield",color:"muted",perLevel:.8,unit:"s",maxLevel:15,price:25,growth:.12},{id:"DoubleTime",var:"meta:double_t",art:"coin2x",color:"coin",perLevel:.8,unit:"s",maxLevel:15,price:25,growth:.12},{id:"DashTime",var:"meta:dash_t",art:"boot",color:"accent",perLevel:.3,unit:"s",maxLevel:15,price:30,growth:.12},{id:"FlightTime",var:"meta:flight_t",art:"wing",color:"secondary",perLevel:.4,unit:"s",maxLevel:15,price:35,growth:.12},{id:"Luck",var:"meta:luck",art:"clover",color:"accent",perLevel:5,unit:"%",maxLevel:20,price:30,growth:.1},{id:"HeadStart",var:"meta:head_start",art:"lightning",color:"primary",perLevel:.4,unit:"s",maxLevel:10,price:50,growth:.15},{id:"Greed",var:"meta:greed",art:"coin",color:"coin",perLevel:2,unit:"%",maxLevel:25,price:40,growth:.1}],zc={game:"runner",character:ba,stats:xa,heroes:Vn,levels:Po,firstClearGold:e=>Hn(e).firstClearGold,stars:3};var Mt=$e("runner.item"),jr=$e("runner.player"),Rs=$e("runner.stripe"),Nc=$e("runner.hud"),zt=(e,t)=>{let r=Number(e.vars.view_w??720),s=Number(e.vars.view_h??1280),n=Math.min(s*.11,r*.2,s*.5/t),o=s*.6-n*t/2;return {viewW:r,viewH:s,top:o,laneH:n,playerX:Math.min(r*.24,s*.3)}},Gn=(e,t)=>e.top+e.laneH*(t+.72),zo=(e,t)=>{let r=Number(e.vars[t]??0);return Number.isFinite(r)?r:0},Dt={wall:1.3,barrier:.5,mover:1,train:.95,rock:1.05,jump:1.25,flight:1.9},As={id:"lane-runner",version:2,engines:["phaser"],requires:["round"],params:{lanes:{type:"number",default:3,min:2,max:5,integer:true},difficulty:{type:"number",default:.5,min:0,max:1},coinRate:{type:"number",default:.7,min:0,max:1},powerRate:{type:"number",default:.22,min:0,max:1},lives:{type:"number",default:3,min:1,max:9,integer:true},coinScore:{type:"number",default:10,min:0,max:1e3,integer:true},graceTime:{type:"number",default:1.2,min:0,max:5},jumpTime:{type:"number",default:.62,min:.3,max:1.5},lengthScale:{type:"number",default:1,min:.05,max:5}},setup({world:e,params:t}){let r=R=>cr(t,R),s=r("lanes"),n=e.rng.stream("lane-runner"),o=null,a=Hn(1,r("difficulty")),c=a.length,p=0,x=0,E=0,L=false,O=false,C=false,I=0,K=0,ne=0,V=0,ce=0,oe=0,le=0,Ae=3,xe=0,we=false,ge=new Map,ke=new Map,pe=()=>Vn.find(R=>R.id===e.vars["meta:hero"])??Vn[0],Te=R=>(vr[R].seconds+zo(e,vr[R].var))*(pe().perk==="power"?1.25:1),Be=()=>e.vars.reviving===true,ze=()=>{for(let S of e.query(Rs))e.destroy(S);let R=zt(e,s);Ot(e,"side",R.top+2);for(let S=0;S<s;S++){let $=e.create();e.set($,Rs,{index:S}),e.set($,G,{x:R.viewW/2,y:R.top+R.laneH*(S+.5)}),e.set($,te,{shape:"tile",art:"road",w:R.viewW,h:R.laneH,unit:R.laneH*1.28,depth:-20+S*.1});}let z=R.viewH-(R.top+R.laneH*s),y=e.create();e.set(y,Rs,{index:-1}),e.set(y,G,{x:R.viewW/2,y:R.viewH-z/2+1}),e.set(y,te,{shape:"tile",art:"ground",w:R.viewW,h:z+2,unit:R.laneH*1.2,depth:-21});},Y=(R,z,y)=>Gn(R,z.lane)-z.alt-y/2,Le=(R,z,y,S,$)=>{let l=R.laneH,h=9+y;switch(z){case "wall":return {v:{shape:"sprite",art:"obstacle",w:S,h:l*Dt.wall,depth:h},h:l*Dt.wall};case "barrier":return {v:{shape:"sprite",art:"hurdle",w:S,h:l*Dt.barrier,depth:h},h:l*Dt.barrier};case "pit":return {v:{shape:"sprite",art:"pit",w:S,h:l*.42,depth:-19+y*.1+.05},h:-l*.42};case "mover":return {v:{shape:"actor",cast:"foe",h:l*1.5,pose:"run",facing:-1,depth:h},h:l*1.5};case "train":return {v:{shape:"sprite",art:"wagon",w:S,h:l*Dt.train,depth:h},h:l*Dt.train};case "ramp":return {v:{shape:"sprite",art:"ramp",w:S,h:l*Dt.train,depth:h},h:l*Dt.train};case "rock":return {v:{shape:"sprite",art:"shadow",w:S,h:l*.3,alpha:.5,depth:-19+y*.1+.06},h:-l*.3};case "coin":return {v:{shape:"sprite",art:"coin",w:S,h:S,depth:h+.2},h:S};case "power":return {v:{shape:"sprite",art:vr[$??"magnet"].art,color:vr[$??"magnet"].color,w:S,h:S,depth:h+.2},h:S};case "finish":return {v:{shape:"sprite",art:"finish",w:l*.7,h:l*s+l*.9,depth:8},h:0}}},J=(R,z,y,S={})=>{let $=zt(e,s),l=S.size??(R==="coin"?$.laneH*.42:R==="power"?$.laneH*.62:$.laneH*.85),h=S.alt??(R==="coin"?$.laneH*.5:R==="power"?$.laneH*.6:0),m=e.create();e.set(m,Mt,{lane:z,kind:R,size:l,alt:h,...S.power!==void 0?{power:S.power}:{}});let{v:g,h:T}=Le($,R,z,l,S.power),N=$.viewW+$.laneH+l/2+y,P=R==="finish"?$.top+$.laneH*s/2:T<0?Gn($,z)+T/2+$.laneH*.08:Y($,{lane:z,alt:h},T);return e.set(m,G,{x:N,y:P}),e.set(m,te,g),R==="coin"&&V++,m},Se=(R,z,y,S)=>{let $=zt(e,s);for(let l=0;l<y;l++)J("coin",R,z+l*$.laneH*.75,S!==void 0?{alt:S}:{});},Ee=(R,z)=>{let y=1+zo(e,"meta:luck");n.chance(Math.min(.9,r("powerRate")*y))&&J("power",R,z,{power:n.weighted(Io,S=>vr[S].weight)});},ve=R=>a.kinds.includes(R),Pe=()=>[...Array(s).keys()],Ue=R=>{let z=["wall",...ve("barrier")?["barrier"]:[],...ve("pit")?["pit"]:[]],y=new Map;for(let l of Pe())n.chance(a.density)&&y.set(l,n.pick(z));y.size>=s&&y.delete(n.int(0,s-1));let S=zt(e,s);for(let[l,h]of y)J(h,l,R,h==="pit"?{size:S.laneH*1.25}:{});let $=Pe().filter(l=>!y.has(l));$.length>0&&n.chance(r("coinRate"))&&Se(n.pick($),R-S.laneH,3);for(let[l,h]of y)(h==="barrier"||h==="pit")&&n.chance(.5)&&Se(l,R-S.laneH*.75,3,S.laneH*1.3);},se=()=>{let z=zt(e,s).laneH,y=$=>$+Math.round(a.density*3),S=[{id:"scatter",weight:3,make:$=>{let l=y(2);for(let h=0;h<l;h++)Ue(h*$);return Ee(n.int(0,s-1),l*$-$/2),l*$}},{id:"rest",weight:1,make:$=>{let l=n.int(0,s-1);for(let h=0;h<4;h++)Se(l,h*$*.8,3),l=Math.max(0,Math.min(s-1,l+(n.chance(.5)?1:-1)));return Ee(l,4*$*.8),4*$*.8}}];return a.level>=3&&S.push({id:"corridor",weight:2,make:$=>{let l=y(3),h=n.int(0,s-1);for(let m=0;m<l;m++){for(let g of Pe())g!==h&&J("wall",g,m*$);Se(h,m*$-z*.4,2),m%2===1&&(h=Math.max(0,Math.min(s-1,h+(n.chance(.5)?1:-1))));}return l*$}}),(ve("barrier")||ve("pit"))&&S.push({id:"hurdles",weight:2,make:()=>{let $=Math.max(z*3.6,a.speed*r("jumpTime")*1.45),l=2+Math.round(a.density*2),h=[...ve("barrier")?["barrier"]:[],...ve("pit")?["pit"]:[]],m=n.int(0,s-1);for(let g=0;g<l;g++){for(let T of Pe()){let N=n.pick(h);J(N,T,g*$,N==="pit"?{size:z*1.25}:{});}Se(m,g*$-z*.75,3,z*1.3);}return l*$}}),ve("train")&&S.push({id:"train",weight:2,make:$=>{let l=n.int(0,s-1),h=z*n.int(5,8),m=n.chance(.75),g=z*1.4;m&&J("ramp",l,0,{size:g}),J("train",l,(m?g:0)+h/2-z*.42,{size:h}),m&&Se(l,g+z*.4,Math.floor(h/(z*.75))-1,z*(Dt.train+.5));let T=Pe().filter(P=>P!==l),N=n.pick(T);if(n.chance(.5))J("train",N,$*.5+h/2,{size:h*.8});else for(let P=0;P<2;P++)J("wall",N,$*(.5+P*1.4));return (m?g:0)+h+$*.5}}),ve("mover")&&S.push({id:"movers",weight:1.5,make:$=>{let l=1+(n.chance(a.density)?1:0),h=new Set;for(let g=0;g<l;g++){let T=n.int(0,s-1);h.has(T)&&(T=(T+1)%s),h.add(T),J("mover",T,g*$*1.6,{size:z*.6});}let m=Pe().filter(g=>!h.has(g));return m.length>0&&Se(n.pick(m),0,4),l*$*1.6}}),ve("rock")&&S.push({id:"rocks",weight:1.5,make:$=>{let l=2+(n.chance(a.density)?1:0);for(let h=0;h<l;h++){let m=n.int(0,s-1);J("rock",m,h*$*1.2,{size:z*.9});let g=Pe().filter(T=>T!==m);Se(n.pick(g),h*$*1.2,2);}return l*$*1.2}}),S},Me=R=>{let z=zt(e,s),y=Math.floor(s/2),S=a.fresh;if(S===null||S==="wall")return 0;if(S==="barrier"||S==="pit"){for(let $=0;$<3;$++)J(S,y,$*R*1.6,S==="pit"?{size:z.laneH*1.25}:{}),Se(y,$*R*1.6-z.laneH*.75,3,z.laneH*1.3);return 3*R*1.6}return S==="train"?(J("ramp",y,0,{size:z.laneH*1.4}),J("train",y,z.laneH*1.4+z.laneH*3-z.laneH*.42,{size:z.laneH*6}),Se(y,z.laneH*1.8,7,z.laneH*(Dt.train+.5)),z.laneH*8+R):(J(S,y,0,{size:S==="mover"?z.laneH*.6:z.laneH*.9}),R*1.5)},lt=()=>{let R=Math.max(zt(e,s).laneH*2.1,300-a.density*110),z;if(!we&&a.fresh!==null&&a.fresh!=="wall")we=true,z=Me(R);else {let y=se();z=(E>0&&E%4===3?y.find($=>$.id==="rest"):n.weighted(y,$=>$.weight)).make(R);}E++,x=Number(e.vars.distance??0)+z+R*1.2;},_e=(R,z,y)=>{let S=R.laneH*1.05;return {x:R.playerX,y:Gn(R,z)-y-S/2,h:S}},ct=()=>{let R=zt(e,s);(o===null||!e.isAlive(o))&&(o=e.create(),e.set(o,jr,{lane:Math.floor(s/2),size:R.laneH*.5,alt:0,vy:0}),e.set(o,te,{shape:"actor",cast:pe().cast,h:0,pose:"idle",depth:10}));let z=e.need(o,jr);z.size=R.laneH*.5;let y=_e(R,z.lane,z.alt);e.set(o,G,{x:y.x,y:y.y});let S=e.need(o,te);S.shape==="actor"&&(S.cast=pe().cast,S.h=y.h,S.depth=10+z.lane);},dt=()=>{for(let z of e.query(Mt))e.destroy(z);yt(),a=Hn(zo(e,"meta:chapter")||1,r("difficulty")),c=Math.round(a.length*r("lengthScale")),Ae=r("lives")+(pe().perk==="heart"?1:0),e.vars.distance=0,e.vars.meters=0,e.vars.level_length=c,e.vars.runner_length_scale=r("lengthScale"),e.vars.runner_level=a.level,e.vars.speed=a.speed,e.vars.lives=Ae,e.vars.coins=0,e.vars.score=0,e.vars.mult=1,e.vars.stars=0,e.vars.reviving=false,p=0,x=zt(e,s).laneH*2,E=0,L=false,O=false,C=false,I=0,K=0,ne=0,V=0,ce=0,oe=0,le=0,xe=0,we=false,ge.clear();let R=zo(e,"meta:head_start");if(R>0&&ge.set("dash",R),o!==null&&e.isAlive(o)){let z=e.need(o,jr);z.lane=Math.floor(s/2),z.alt=0,z.vy=0;}ct();},st=R=>{if(!rt(e)||Be()||o===null)return;let z=e.need(o,jr),y=Math.min(s-1,Math.max(0,z.lane+R));y!==z.lane&&$t(e,"runner-lanes"),z.lane=y;},Ye=()=>{let R=zt(e,s),z=r("jumpTime");return 8*R.laneH*Dt.jump/(z*z)},ft=(R,z,y)=>{let S=zt(R,s),$=S.playerX,l=S.laneH*.22,h=0;for(let m of R.query(Mt)){let g=R.need(m,Mt);if(g.lane!==z||g.kind!=="train"&&g.kind!=="ramp")continue;let T=R.need(m,G),N=T.x-g.size/2,P=T.x+g.size/2;if($+l<N||$-l>P)continue;let Z=S.laneH*Dt.train;if(g.kind==="ramp")h=Math.max(h,Z*Math.max(0,Math.min(1,($-N)/g.size)));else if(y>=Z-S.laneH*.12)h=Math.max(h,Z);else return null}return h},qe=()=>{if(!rt(e)||Be()||o===null||ge.has("flight"))return;let R=e.need(o,jr),z=ft(e,R.lane,R.alt)??0;R.alt-z>2||(R.vy=Ye()*r("jumpTime")/2,le++,$t(e,"runner-jump"),Ct(e),e.emit("jumped",{}),Ge(e,o,"jump"));},wt=()=>{if(xt(e,"runner-lanes")||o===null)return;let R=zt(e,s),z=R.playerX+R.laneH*1.6,y=Gn(R,Math.floor(s/2))-R.laneH*.4;bt(e,"swipe",{x:z,y:y+R.laneH*.5},{x:z,y:y-R.laneH*.9},R.laneH);},Je=(R,z,y,S)=>{let $=ke.get(R);($===void 0||!e.isAlive($))&&($=e.create(),e.set($,Nc,{id:R}),ke.set(R,$)),e.set($,G,{x:z,y}),e.set($,te,S);},pt=R=>{let z=ke.get(R);z!==void 0&&e.destroy(z),ke.delete(R);};function yt(){for(let R of ke.values())e.destroy(R);ke.clear(),at(e,Nc);}let et=(R,z,y,S,$,l,h,m=41)=>{let g=Math.max(0,Math.min(1,Math.round(l*100)/100));Je(`${R}:bg`,z,y,{shape:"rect",w:S,h:$,color:"#000000",alpha:.45,radius:$/2,depth:m});let T=Math.max(0,(S-4)*g);T<1?pt(`${R}:fill`):Je(`${R}:fill`,z-(S-4)/2+T/2,y,{shape:"rect",w:T,h:$-4,color:h,radius:($-4)/2,depth:m+.01});},Ze=R=>{let z=zt(R,s),y=Math.min(z.viewW,z.viewH),S=z.viewH*.085,$=z.viewW*.66,l=Math.max(10,y*.026),h=Number(R.vars.distance??0)/Math.max(1,c);et("way",z.viewW/2,S,$,l,h,"accent");let m=y*.055;Je("flag",z.viewW/2+$/2+m*.45,S-m*.25,{shape:"sprite",art:"flag",w:m,h:m,depth:42}),Je("lvl",z.viewW/2-$/2-y*.05,S,{shape:"text",text:`${a.level}`,size:Math.round(y*.04),color:"text",bold:true,depth:42});let g=S+y*.07,T=y*.05,N=Number(R.vars.lives??0);for(let Ce=0;Ce<Ae;Ce++)Je(`h${Ce}`,z.viewW*.07+Ce*T*1.1,g,{shape:"sprite",art:"heart",w:T,h:T,alpha:Ce<N?1:.25,depth:42});for(let Ce=Ae;Ce<10;Ce++)pt(`h${Ce}`);let P=y*.045,Z=String(R.vars.coins??0);Je("coin:i",z.viewW*.93-Z.length*P*.6-P*.7,g,{shape:"sprite",art:"coin",w:P,h:P,depth:42}),Je("coin",z.viewW*.93-Z.length*P*.6/2,g,{shape:"text",text:Z,size:Math.round(P),color:"text",bold:true,depth:42});let ie=Number(R.vars.mult??1);ie>1?Je("mult",z.viewW*.9,g+P*1.2,{shape:"text",text:`x${ie}`,size:Math.round(P*1.05),color:"coin",bold:true,depth:42}):pt("mult");let re=y*.055,Ie=0;for(let Ce of Io){let De=ge.get(Ce);if(De===void 0){pt(`p:${Ce}`),pt(`pb:${Ce}:bg`),pt(`pb:${Ce}:fill`);continue}let F=z.viewW*.07+Ie*re*1.25,ae=g+T*1.25;Je(`p:${Ce}`,F,ae,{shape:"sprite",art:vr[Ce].art,color:vr[Ce].color,w:re,h:re,depth:42}),et(`pb:${Ce}`,F,ae+re*.7,re,Math.max(6,y*.011),De/Math.max(.1,Te(Ce)),"coin",42),Ie++;}},ut=(R,z)=>{if(!rt(R)||O)return;O=true;let y=z==="cleared",S=y?1+(V>0&&ce>=V*a.coinStar?1:0)+(oe===0?1:0):0;R.vars.stars=S,y&&R.vars["meta:first_clear"]===true&&Ke(R,"coins",a.firstClearGold);let $=Bn(Number(R.vars.distance??0));R.vars.score=xe+$*2+(y?500*S:0),R.vars.reviving=false,R.emit(Bt,{reason:z,stats:{chapter:a.level,seconds:Math.floor(I),cleared:y,stars:S,coins:ce,meters:$,jumps:le,hits:oe}});},gt=R=>{if(R.vars.revive_ready===true&&!C){R.vars.reviving=true,Ct(R),R.emit(Kt,{});return}ut(R,"crashed");},Wt=R=>{if(!Be())return;C=true,R.vars.reviving=false,R.vars.lives=Math.max(1,Math.ceil(Ae/2)),p=2.5,ge.set("shield",Math.max(ge.get("shield")??0,3));let z=zt(R,s);for(let y of R.query(Mt)){let S=R.need(y,Mt);if(S.kind==="coin"||S.kind==="power"||S.kind==="finish")continue;let $=R.need(y,G);$.x-S.size/2<z.playerX+z.laneH*6&&(H(R,{kind:"burst",x:$.x,y:$.y,color:"coin",n:8,size:z.laneH*.6}),R.destroy(y));}if(o!==null){let y=R.need(o,jr);y.alt=0,y.vy=0,ot(R,o,"run");let S=R.need(o,G);H(R,{kind:"ring",x:S.x,y:S.y,color:"coin",size:z.laneH*4});}H(R,{kind:"flash",color:"coin"});},Ft=(R,z)=>{if(o===null)return;let y=R.need(z,G),S=zt(R,s);if(ge.has("dash")){H(R,{kind:"burst",x:y.x,y:y.y,color:"accent",n:14,size:S.laneH*.8}),H(R,{kind:"shake",power:.6}),R.need(z,Mt).kind!=="pit"&&R.destroy(z);return}if(p>0)return;if(ge.has("shield")){ge.delete("shield"),p=.8,H(R,{kind:"ring",x:S.playerX,y:R.need(o,G).y,color:"muted",size:S.laneH*2}),R.need(z,Mt).kind!=="pit"&&R.destroy(z);return}oe++,K=0,R.vars.mult=1;let $=Number(R.vars.lives??1)-1;R.vars.lives=$,R.emit("player-hit",{lives:$}),H(R,{kind:"burst",x:y.x,y:y.y,color:"danger",n:14,size:S.laneH*.9}),H(R,{kind:"shake",power:1.5}),Ge(R,o,"hit"),R.need(z,Mt).kind!=="pit"&&R.destroy(z),p=r("graceTime"),$<=0&>(R);},Ut=(R,z)=>{let y=R.need(z,Mt),S=R.need(z,G),$=zt(R,s);if(y.kind==="power"&&y.power!==void 0){ge.set(y.power,Te(y.power)),R.emit("power-up",{id:y.power}),H(R,{kind:"ring",x:S.x,y:S.y,color:vr[y.power].color,size:$.laneH*1.6}),R.destroy(z);return}K++;let l=Math.min(5,1+Math.floor(K/12));l>Number(R.vars.mult??1)&&H(R,{kind:"pop",x:$.playerX,y:S.y-$.laneH,text:`x${l}`,color:"coin",size:Math.round($.laneH*.42)}),R.vars.mult=l;let h=(ge.has("double")?2:1)*(1+zo(R,"meta:greed"));ne+=h;let m=Math.floor(ne);ne-=m,m>0&&Ke(R,"coins",m),ce++,xe+=Math.round(h*r("coinScore")*l),R.emit("coin-collected",{value:h}),H(R,{kind:"burst",x:S.x,y:S.y,color:"coin",n:6,size:y.size*1.3}),R.destroy(z);};e.on(Tt,R=>{let z=R;e.vars.started_tick!==e.tick&&(z.type==="swipe"&&(z.dir==="up"||z.dir==="down")?st(z.dir==="up"?-1:1):z.type==="swipe"&&z.dir==="right"?qe():z.type==="key"&&(z.key==="left"||z.key==="up")?st(-1):z.type==="key"&&(z.key==="right"||z.key==="down")?st(1):(z.type==="key"&&z.key==="action"||z.type==="tap")&&qe());}),e.on(Ht,()=>{dt(),o!==null&&ot(e,o,"run"),wt();}),e.on(Gt,dt),e.on(Zt,()=>Wt(e)),e.on(Qt,()=>{Be()&&(e.vars.reviving=false,ut(e,"crashed"));}),e.on(Vt,R=>{o!==null&&e.isAlive(o)&&ot(e,o,R.reason==="cleared"?"dance":"die");for(let z of e.query(Mt))e.need(z,Mt).kind==="mover"&&ot(e,z,"idle");yt();}),e.on(jt,()=>{ze(),o!==null&&ct();let R=zt(e,s);for(let z of e.query(Mt)){let y=e.need(z,Mt),{v:S,h:$}=Le(R,y.kind,y.lane,y.size,y.power);e.set(z,te,S),e.need(z,G).y=y.kind==="finish"?R.top+R.laneH*s/2:$<0?Gn(R,y.lane)+$/2+R.laneH*.08:Y(R,y,$);}}),e.addSystem({id:"lane-runner",order:0,run(R,z){if(!rt(R)||o===null||O||Be())return;let y=zt(R,s),S=y.laneH;I+=z;let $=Number(R.vars.distance??0),h=(a.speed+(a.topSpeed-a.speed)*Math.min(1,$/Math.max(1,c)))*(ge.has("dash")?1.6:1);R.vars.speed=Math.round(h);let m=h*z;R.vars.distance=$+m,R.vars.meters=Bn($+m),p>0&&(p=Math.max(0,p-z));for(let[De,F]of [...ge])F-z<=0?(ge.delete(De),De==="flight"&&(p=Math.max(p,.8))):ge.set(De,F-z);Co(R,m);for(let De of R.query(Rs)){let F=R.need(De,te);F.shape==="tile"&&(F.scrollX=(F.scrollX??0)+m);}let g=c-($+m);if(!L&&g<=y.viewW-y.playerX+S){L=true;let De=J("finish",0,0);R.need(De,G).x=y.playerX+g;}else !L&&$>=x&&g>y.viewW&<();let T=R.need(o,jr),N=ge.has("flight");if(N)T.alt+=(S*Dt.flight-T.alt)*Math.min(1,z*6),T.vy=0,Math.floor(($+m)/(S*.9))!==Math.floor($/(S*.9))&&J("coin",T.lane,0,{alt:S*(Dt.flight+.4)});else {T.vy-=Ye()*z,T.alt+=T.vy*z;let De=ft(R,T.lane,T.alt);if(De===null){let F=R.query(Mt).find(ae=>{let Oe=R.need(ae,Mt);return Oe.lane===T.lane&&Oe.kind==="train"&&Math.abs(R.need(ae,G).x-y.playerX)<Oe.size/2+S*.22});if(F!==void 0&&Ft(R,F),O||Be())return;T.alt=Math.max(0,T.alt);}else T.alt<=De&&(T.alt=De,T.vy=0);}let P=R.need(o,G),Z=_e(y,T.lane,T.alt);P.y+=(Z.y-P.y)*Math.min(1,z*14),P.x=Z.x;let ie=R.need(o,te);ie.shape==="actor"&&(ie.alpha=p>0&&Math.floor(R.time*12)%2===0?.35:1,ie.depth=10+T.lane+.5,ie.speed=h,ie.pose=T.alt>2&&T.vy!==0?"air":"run");let re=S*.24,Ie=ge.has("magnet"),Ce=T.alt+S*.5;for(let De of R.query(Mt)){if(!R.isAlive(De)||!R.has(De,Mt))continue;let F=R.need(De,Mt),ae=R.need(De,G);if(ae.x-=m,F.kind==="mover"){if(ae.x-=h*.35*z,F.to===void 0&&ae.x-y.playerX<S*6&&ae.x-y.playerX>S*3){let ue=[F.lane-1,F.lane+1].filter(Q=>Q>=0&&Q<s);F.to=T.lane!==F.lane&&ue.includes(T.lane)?T.lane:n.pick(ue),F.warn=.45;}if(F.warn!==void 0&&F.warn>0){F.warn-=z;let ue=R.need(De,te);ue.alpha=Math.floor(R.time*14)%2===0?.4:1,F.warn<=0&&F.to!==void 0&&(F.lane=F.to,ue.alpha=1,ue.depth=9+F.lane);}ae.y+=(Y(y,F,S*1.5)-ae.y)*Math.min(1,z*10);}if(F.kind==="rock"&&!F.landed&&ae.x-y.playerX<S*2.6&&(F.landed=true,R.set(De,te,{shape:"sprite",art:"rock",w:F.size,h:S*Dt.rock,depth:9+F.lane}),ae.y=Gn(y,F.lane)-S*Dt.rock/2,H(R,{kind:"burst",x:ae.x,y:ae.y+S*.4,color:"muted",n:10,size:S*.7}),H(R,{kind:"shake",power:.5})),F.kind==="rock"&&!F.landed){let ue=R.need(De,te);ue.shape==="sprite"&&(ue.alpha=.35+.3*Math.abs(Math.sin(R.time*6)));}if(F.kind==="power"&&(ae.y=Y(y,F,F.size)+Math.sin(R.time*4+ae.x*.01)*S*.06),ae.x+F.size/2<-S*2){R.destroy(De);continue}if(F.kind==="finish"){if(ae.x<=y.playerX){H(R,{kind:"flash",color:"coin"}),ut(R,"cleared");return}continue}if(F.kind==="coin"&&Ie&&ae.x>y.playerX-S*.5&&ae.x<y.playerX+S*4&&(F.pulled=true),F.kind==="coin"&&F.pulled){ae.x+=(y.playerX-ae.x)*Math.min(1,z*10),ae.y+=(P.y-ae.y)*Math.min(1,z*10),Math.hypot(ae.x-y.playerX,ae.y-P.y)<S*.4&&Ut(R,De);continue}let Oe=F.kind==="barrier"?F.size*.3:F.size/2;if(Math.abs(ae.x-y.playerX)>re+Oe||F.lane!==T.lane)continue;if(F.kind==="coin"||F.kind==="power"){(Math.abs(F.alt-Ce)<S*.6||N)&&Ut(R,De);continue}if(N||F.kind==="ramp"||F.kind==="train"||F.kind==="rock"&&!F.landed)continue;let me=F.kind==="wall"?Dt.wall:F.kind==="barrier"?Dt.barrier*.85:F.kind==="mover"?Dt.mover:F.kind==="rock"?Dt.rock:0;if(F.kind==="pit"?T.alt<2&&Math.abs(ae.x-y.playerX)<F.size*.32&&Ft(R,De):T.alt<S*me&&Ft(R,De),O||Be())return}xt(R,"runner-jump")||R.query(Mt).find(F=>{let ae=R.need(F,Mt),Oe=R.need(F,G).x-y.playerX;return (ae.kind==="barrier"||ae.kind==="pit")&&ae.lane===T.lane&&Oe>S*1.5&&Oe<S*3.2})!==void 0&&!kr(R)&&bt(R,"tap",{x:y.playerX+S*1.2,y:P.y}),R.vars.score=xe+Bn($+m)*2,Ze(R);}}),ze(),dt();}};var yn=[{id:"rainbow",shape:"color",art:"m3_rainbow",make:e=>e>=5},{id:"bomb",shape:"area:1",art:"m3_bomb",make:(e,t)=>t},{id:"col",shape:"col",art:"m3_col",make:(e,t,r)=>e===4&&r==="h"},{id:"row",shape:"row",art:"m3_row",make:(e,t,r)=>e===4&&r==="v"}],Wc=[{a:"row",b:"row",effect:"cross"},{a:"col",b:"col",effect:"cross"},{a:"row",b:"col",effect:"cross"},{a:"bomb",b:"row",effect:"cross:1"},{a:"bomb",b:"col",effect:"cross:1"},{a:"bomb",b:"bomb",effect:"area:2"},{a:"rainbow",b:"plain",effect:"color"},{a:"rainbow",b:"row",effect:"turn"},{a:"rainbow",b:"col",effect:"turn"},{a:"rainbow",b:"bomb",effect:"turn"},{a:"rainbow",b:"rainbow",effect:"all"}],Hr={ice:{id:"ice",layer:"under",hp:1,art:"m3_ice",max:20},slime:{id:"slime",layer:"under",hp:1,art:"m3_slime",spreads:true,max:16},chain:{id:"chain",layer:"over",hp:1,art:"m3_chain",max:10},stone:{id:"stone",layer:"block",hp:1,art:"m3_stone",hitByNear:true,max:10},cage:{id:"cage",layer:"block",hp:1,art:"m3_cage",hitByNear:true}},ka={"-":{},".":{hole:true},i:{under:{id:"ice",hp:1}},I:{under:{id:"ice",hp:2}},m:{under:{id:"slime",hp:1}},c:{over:{id:"chain",hp:1}},s:{block:{id:"stone",hp:1}},S:{block:{id:"stone",hp:2}},g:{block:{id:"cage",hp:1}}},jo={fire:{beats:["nature"],color:"piece1"},water:{beats:["fire"],color:"piece2"},nature:{beats:["water"],color:"piece3"},light:{beats:["dark"],color:"piece4"},dark:{beats:["light"],color:"piece5"}},va=[{index:0,art:"gem1",color:"piece1",role:"attack",element:"fire"},{index:1,art:"gem2",color:"piece2",role:"attack",element:"water"},{index:2,art:"gem3",color:"piece3",role:"attack",element:"nature"},{index:3,art:"gem4",color:"piece4",role:"attack",element:"light"},{index:4,art:"gem5",color:"piece5",role:"attack",element:"dark"},{index:5,art:"m3_heart",color:"danger",role:"heal"},{index:6,art:"m3_shield",color:"primary",role:"shield"},{index:7,art:"gem6",color:"piece6",role:"attack"}],Ho=e=>va.find(t=>t.index===e),$a=[{id:"goblin",cast:"foe5",element:"nature",hp:1,attack:1,every:3,size:.8},{id:"wolf",cast:"foe",element:"nature",hp:.8,attack:.7,every:2,size:.85},{id:"orc",cast:"foe",variant:5,element:"fire",hp:1.4,attack:1.3,every:3,skill:{kind:"sow",obstacle:"stone",count:2},size:.95},{id:"frost-imp",cast:"foe3",element:"water",hp:1,attack:.9,every:3,skill:{kind:"sow",obstacle:"ice",count:3},size:.85},{id:"spider",cast:"foe4",element:"dark",hp:1.1,attack:1,every:3,skill:{kind:"sow",obstacle:"chain",count:3},size:.85},{id:"golem",cast:"foe2",element:"light",hp:2,attack:1.5,every:4,skill:{kind:"sow",obstacle:"stone",count:3},size:1.05},{id:"slime-beast",cast:"foe2",variant:9,element:"water",hp:1.3,attack:1.1,every:3,skill:{kind:"sow",obstacle:"slime",count:2},size:.95},{id:"shaman",cast:"foe4",variant:7,element:"dark",hp:1,attack:.9,every:3,skill:{kind:"heal",share:.15},size:.9},{id:"troll",cast:"boss",element:"nature",hp:3,attack:1.6,every:3,skill:{kind:"sow",obstacle:"stone",count:3},boss:true,enrage:.5,size:1.2},{id:"frost-queen",cast:"boss",variant:4,element:"water",hp:3.5,attack:1.5,every:3,skill:{kind:"sow",obstacle:"ice",count:5},boss:true,enrage:.5,size:1.2},{id:"spider-queen",cast:"boss",variant:9,element:"dark",hp:4,attack:1.7,every:3,skill:{kind:"sow",obstacle:"chain",count:4},boss:true,enrage:.5,size:1.2},{id:"lich",cast:"boss",variant:13,element:"dark",hp:4.5,attack:1.8,every:3,skill:{kind:"sow",obstacle:"slime",count:3},boss:true,enrage:.5,size:1.25}],Bo=e=>$a.find(t=>t.id===e),Ds=100,jc=4,Hc=1.5,Bc=2,Vc=1,Ma=[{id:"blast",art:"m3_skill_blast",mana:30,kind:"shape",shape:"area:1",bigShape:"area:2",bigAt:1.5,damage:6},{id:"cross",art:"m3_skill_cross",mana:28,kind:"shape",shape:"cross",bigShape:"cross:1",bigAt:1.5,damage:5},{id:"storm",art:"m3_skill_storm",mana:34,kind:"storm",count:4,damage:4}],Ts=e=>Ma.find(t=>t.id===e),Fn=[{id:"hero",cast:"hero",gems:0,element:"fire",skill:"blast"},{id:"hero2",cast:"hero2",gems:150,element:"light",skill:"cross"},{id:"hero3",cast:"hero3",gems:300,element:"water",skill:"storm"}],Os={plain:["--------","--------","--------","--------","--------","--------","--------","--------"],diamond:["..----..",".------.","--------","--------","--------","--------",".------.","..----.."],"ice-mid":["--------","--------","--iiii--","--iiii--","--iiii--","--iiii--","--------","--------"],"ice-low":["--------","--------","--------","--------","iiiiiiii","iiiiiiii","IIIIIIII","IIIIIIII"],stones:["--------","--------","--------","ss-ss-ss","--------","--------","--------","--------"],chains:["--------","-c----c-","--c--c--","---cc---","---cc---","--c--c--","-c----c-","--------"],cages:["--------","-g----g-","--------","---gg---","--------","--------","-g----g-","--------"],slime:["--------","--------","--------","--------","--------","--------","mm----mm","mmm--mmm"],hourglass:["--------","--------",".------.","..----..","..----..",".------.","--------","--------"],ring:["--------","--------","--------","---..---","---..---","--------","--------","--------"],"ice-stone":["--------","-S----S-","--IIII--","--IIII--","--IIII--","--IIII--","-S----S-","--------"],fortress:["s------s","-iiiiii-","-i-cc-i-","-ic--ci-","-ic--ci-","-i-cc-i-","-iiiiii-","s------s"],"slime-cages":["-g----g-","--------","--------","---mm---","---mm---","--------","--------","-g----g-"],"cross-holes":["---..---","--------","--------",".------.",".------.","--------","--------","---..---"]},kt=(e,t,r,s,n)=>({kind:"goal",board:e,moves:t,colors:r,goals:s,...n?{drops:n}:{}}),Yt=(e,t,...r)=>({kind:"battle",board:e,elements:t,enemies:r}),pr=(e,t)=>({kind:"color",color:e,count:t}),Et=e=>({kind:"clear",obstacle:e}),No=e=>({kind:"drops",count:e}),Cs=[kt("plain",20,5,[pr(0,12),pr(1,12)]),kt("diamond",20,5,[pr(2,15),pr(3,15)]),Yt("plain",3,"goblin"),kt("ice-mid",22,5,[Et("ice")]),kt("ring",20,5,[pr(0,20),pr(4,20)]),Yt("plain",3,"goblin","wolf"),kt("stones",22,5,[Et("stone"),pr(1,15)]),kt("ice-low",25,5,[Et("ice")]),Yt("diamond",3,"wolf","orc"),Yt("plain",3,"troll"),kt("chains",24,5,[Et("chain")]),kt("plain",25,5,[No(3)],3),Yt("plain",4,"frost-imp","goblin"),kt("cages",22,5,[Et("cage")]),kt("slime",25,5,[Et("slime")]),Yt("ice-mid",4,"orc","frost-imp"),kt("hourglass",24,5,[No(3),pr(2,20)],3),kt("ice-low",26,5,[Et("ice")]),Yt("plain",4,"spider","frost-imp","wolf"),Yt("plain",4,"frost-queen"),kt("ice-stone",26,5,[Et("ice"),Et("stone")]),kt("cross-holes",26,6,[pr(0,20),pr(3,20)]),Yt("chains",4,"spider","golem"),kt("fortress",28,5,[Et("ice"),Et("chain")]),kt("slime-cages",26,5,[Et("cage"),Et("slime")]),Yt("plain",4,"slime-beast","golem"),kt("diamond",28,5,[No(3)],3),kt("ice-low",28,5,[Et("ice"),pr(4,20)]),Yt("ring",5,"shaman","golem","spider"),Yt("plain",5,"spider-queen"),kt("fortress",28,6,[Et("ice"),Et("chain")]),kt("slime",28,5,[Et("slime"),No(3)],3),Yt("ice-stone",5,"golem","shaman"),kt("ice-stone",28,6,[Et("ice"),Et("stone")]),kt("slime-cages",28,6,[Et("cage"),Et("slime")]),Yt("plain",5,"slime-beast","shaman","orc"),kt("cross-holes",30,5,[No(3),pr(1,18)],3),kt("fortress",32,5,[Et("ice"),Et("chain"),pr(2,15)]),Yt("diamond",5,"golem","shaman","spider"),Yt("plain",5,"lich")],Wo=10,Gc=4,Ps=Cs.length,Ea=[0,18,45,75];function Bp(e){return e.kind==="goal"?[0,1,2,3,4,7].slice(0,Math.max(3,Math.min(6,e.colors))):[...[0,1,2,3,4].slice(0,Math.max(2,Math.min(5,e.elements))),5,6]}function Un(e,t=.5){let r=Math.max(1,Math.min(Ps,Math.floor(e))),s=Cs[r-1],n=Math.ceil(r/Wo),o=s.kind==="battle"&&s.enemies.some(a=>Bo(a)?.boss);return {level:r,world:n,index:r-(n-1)*Wo,def:s,boss:o,colors:Bp(s),enemyHp:180*Math.pow(1.07,r-1)*(.8+t*.4),enemyAttack:14*Math.pow(1.06,r-1)*(.8+t*.4),firstClearGold:(o?120:50)+(r-1)*10}}var Sa=e=>Ea[Math.ceil(Math.max(1,e)/Wo)-1]??0,wa=(e,t)=>t?e>=.7?3:e>=.35?2:1:e>=.3?3:e>=.1?2:1,Fc=5,Uc=.5,La="kit-match3",_a=[{id:"Attack",var:"meta:attack",art:"m3_skill_blast",color:"danger",perLevel:5,unit:"%",maxLevel:20,price:40,growth:.12},{id:"Health",var:"meta:health",art:"m3_heart",color:"danger",perLevel:6,unit:"%",maxLevel:20,price:40,growth:.12},{id:"Defense",var:"meta:defense",art:"m3_shield",color:"primary",perLevel:5,unit:"%",maxLevel:15,price:45,growth:.12},{id:"SkillPower",var:"meta:skill",art:"m3_skill_cross",color:"secondary",perLevel:8,unit:"%",maxLevel:10,price:50,growth:.12},{id:"ManaGain",var:"meta:mana",art:"m3_skill_storm",color:"secondary",perLevel:5,unit:"%",maxLevel:10,price:50,growth:.12},{id:"Moves",var:"meta:moves",art:"m3_bomb",color:"coin",perLevel:1,unit:"",maxLevel:5,price:120,growth:.2}],Xc={game:"match3",character:La,stats:_a,heroes:Fn,levels:Ps,firstClearGold:e=>Un(e).firstClearGold,stars:3,starsToEnter:Sa};var Da=()=>({cleared:[],created:[],fired:[],hits:[],spawned:[],dropsCollected:0,slimeCleared:false}),Ta=-1,Br=-2,Ns=(e,t,r)=>t>=0&&r>=0&&t<e.cols&&r<e.rows,nn=(e,t,r)=>Ns(e,t,r)?e.cells[r][t]:null,Ws=(e,t)=>t[Math.floor(e.rnd()*t.length)%t.length],qc=[[1,0],[-1,0],[0,1],[0,-1]],Ra=e=>e.hole||e.block!==null||e.over!==null,Vp=e=>e!==null&&e.color>=0;function js(e,t,r,s,n=0){let o={cols:e[0].length,rows:e.length,cells:e.map(a=>[...a].map(c=>{let p=s[c]??{};return {hole:p.hole===true,piece:null,under:p.under?{...p.under}:null,over:p.over?{...p.over}:null,block:p.block?{...p.block}:null}})),colors:t,nextId:1,dropsToSpawn:n,rnd:r};return Aa(o),o}var zs=(e,t,r=null)=>({id:e.nextId++,color:t,special:r});function Aa(e){for(let t=0;t<50;t++){for(let r=0;r<e.rows;r++)for(let s=0;s<e.cols;s++){let n=e.cells[r][s];if(n.hole||n.block||n.piece&&n.piece.color<0||n.piece?.special)continue;let o=new Set,a=nn(e,s-1,r)?.piece,c=nn(e,s-2,r)?.piece;a&&c&&a.color>=0&&a.color===c.color&&o.add(a.color);let p=nn(e,s,r-1)?.piece,x=nn(e,s,r-2)?.piece;p&&x&&p.color>=0&&p.color===x.color&&o.add(p.color);let E=e.colors.filter(O=>!o.has(O)),L=Ws(e,E.length>0?E:e.colors);n.piece?n.piece.color=L:n.piece=zs(e,L);}if(Xn(Hs(e)).size===0&&qn(e)!==null)return}}function Oa(e){for(let t=0;t<e.rows;t++)for(let r=0;r<e.cols;r++){let s=e.cells[t][r].piece;s&&s.color>=0&&!s.special&&!e.cells[t][r].over&&(s.color=-100);}for(let t=0;t<e.rows;t++)for(let r=0;r<e.cols;r++)e.cells[t][r].piece?.color===-100&&(e.cells[t][r].piece.color=Ws(e,e.colors));if(Aa(e),qn(e)===null){for(let t of e.cells)for(let r of t)r.over=null;Aa(e);}}var Hs=e=>e.cells.map(t=>t.map(r=>r.piece&&r.piece.color>=0&&!r.block?r.piece.color:null));function Xn(e){let t=new Set;for(let r of Kc(e))for(let[s,n]of r.cells)t.add(`${s},${n}`);return t}function Kc(e){let t=[],r=e.length,s=e[0]?.length??0;for(let n=0;n<r;n++)for(let o=0;o<s;){let a=e[n][o],c=1;for(;a!=null&&o+c<s&&e[n][o+c]===a;)c++;a!=null&&c>=3&&t.push({cells:Array.from({length:c},(p,x)=>[o+x,n]),dir:"h"}),o+=c;}for(let n=0;n<s;n++)for(let o=0;o<r;){let a=e[o][n],c=1;for(;a!=null&&o+c<r&&e[o+c][n]===a;)c++;a!=null&&c>=3&&t.push({cells:Array.from({length:c},(p,x)=>[n,o+x]),dir:"v"}),o+=c;}return t}function Ca(e){return Gp(e)!==null}function Gp(e){let t=e.length,r=e[0]?.length??0,s=(n,o)=>{let a=e[n[1]][n[0]];e[n[1]][n[0]]=e[o[1]][o[0]],e[o[1]][o[0]]=a;};for(let n=0;n<t;n++)for(let o=0;o<r;o++)for(let[a,c]of [[1,0],[0,1]]){if(o+a>=r||n+c>=t||e[n][o]===null||e[n+c][o+a]===null)continue;s([o,n],[o+a,n+c]);let p=Xn(e).size>0;if(s([o,n],[o+a,n+c]),p)return [[o,n],[o+a,n+c]]}return null}function Vo(e,t,r){if(Math.abs(t.col-r.col)+Math.abs(t.row-r.row)!==1)return false;let s=nn(e,t.col,t.row),n=nn(e,r.col,r.row);if(!s||!n)return false;for(let o of [s,n])if(o.hole||o.block||o.over||!o.piece)return false;return true}function qn(e){let t=Hs(e);for(let r=0;r<e.rows;r++)for(let s=0;s<e.cols;s++)for(let[n,o]of [[1,0],[0,1]]){let a={col:s,row:r},c={col:s+n,row:r+o};if(!Vo(e,a,c))continue;let p=e.cells[r][s].piece,x=e.cells[c.row][c.col].piece;if(p.color===Br&&x.color===Br)continue;if(p.special==="rainbow"||x.special==="rainbow")return [a,c];if(p.special&&x.special)return [a,c];let E=t[r][s];t[r][s]=t[c.row][c.col],t[c.row][c.col]=E;let L=Xn(t).size>0;if(t[c.row][c.col]=t[r][s],t[r][s]=E,L)return [a,c]}return null}function Pa(e){let t=new Map;for(let r=0;r<e.rows;r++)for(let s=0;s<e.cols;s++){let n=e.cells[r][s].piece;n&&t.set(n.id,{col:s,row:r,piece:n});}return t}function Bs(e,t){let r=0;for(let s of e.cells)for(let n of s)for(let o of [n.under,n.over,n.block])o?.id===t&&r++;return r}function Ia(e,t,r){if(!Vo(e,t,r))return null;let s=e.cells[t.row][t.col],n=e.cells[r.row][r.col],o=s.piece,a=n.piece;if(o.special==="rainbow"||a.special==="rainbow"||o.special&&a.special){s.piece=a,n.piece=o;let p=Da();return qp(e,p,r,o,t,a),Ha(e,p),p}s.piece=a,n.piece=o;let c=Zc(e,[t,r]);return c||(s.piece=o,n.piece=a,null)}function Vs(e){return Zc(e,[])}function Gs(e,t,r="skill"){let s=Da(),n=t.filter(o=>Ns(e,o.col,o.row)).map(o=>({...o,match:false}));return t[0]&&s.fired.push({...t[0],kind:r}),Wa(e,s,n),Ha(e,s),s}function za(e,t){let r=[];if(t)return r;let s=Object.values(Hr).filter(n=>n.spreads);for(let n of s){let o=[];for(let p=0;p<e.rows;p++)for(let x=0;x<e.cols;x++)e.cells[p][x].under?.id===n.id&&o.push({col:x,row:p});if(o.length===0)continue;let a=[];for(let p of o)for(let[x,E]of qc){let L=nn(e,p.col+x,p.row+E);L&&!L.hole&&!L.block&&!L.under&&a.push({col:p.col+x,row:p.row+E});}if(a.length===0)continue;let c=Ws(e,a);e.cells[c.row][c.col].under={id:n.id,hp:1},r.push(c);}return r}function Na(e,t,r){let s=Hr[t];if(!s)return [];let n=[];for(let c=0;c<e.rows;c++)for(let p=0;p<e.cols;p++){let x=e.cells[c][p];x.hole||x.block||!x.piece||x.piece.color<0||x.piece.special||s.layer==="under"&&x.under||s.layer==="over"&&x.over||n.push({col:p,row:c});}let o=[],a=s.max===void 0?r:Math.max(0,s.max-Bs(e,t));for(let c=0;c<Math.min(r,a)&&n.length>0;c++){let p=Math.floor(e.rnd()*n.length)%n.length,x=n.splice(p,1)[0],E=e.cells[x.row][x.col],L={id:t,hp:s.hp};s.layer==="under"?E.under=L:s.layer==="over"?E.over=L:(E.block=L,E.piece=null),o.push(x);}return o}function Fs(e,t,r){let s=[];for(let o=0;o<e.rows;o++)for(let a=0;a<e.cols;a++){let c=e.cells[o][a].piece;c&&c.color>=0&&!c.special&&!e.cells[o][a].over&&s.push({col:a,row:o});}let n=[];for(let o=0;o<r&&s.length>0;o++){let a=s.splice(Math.floor(e.rnd()*s.length)%s.length,1)[0];e.cells[a.row][a.col].piece.special=e.rnd()<.5?"row":"col",n.push(a);}return n}function Zc(e,t){let r=Kc(Hs(e));if(r.length===0)return null;let s=Da(),n=[];for(let c of r){let p=new Set(c.cells.map(([L,O])=>`${L},${O}`)),x=n.filter(L=>L.some(O=>O.cells.some(([C,I])=>p.has(`${C},${I}`)))),E=[c,...x.flat()];for(let L of x)n.splice(n.indexOf(L),1);n.push(E);}let o=[],a=[];for(let c of n){let p=new Map;for(let O of c)for(let[C,I]of O.cells)p.set(`${C},${I}`,{col:C,row:I});let x=c.reduce((O,C)=>Math.max(O,C.cells.length),0),E=c.some(O=>O.dir==="h")&&c.some(O=>O.dir==="v"),L=yn.filter(O=>O.make!==null).find(O=>O.make(x,E,c.find(C=>C.cells.length===x).dir));if(L){let O=t.find(I=>p.has(`${I.col},${I.row}`))??(E?Fp(c):null)??Up(c.find(I=>I.cells.length===x)),C=e.cells[O.row][O.col].piece?.color??0;a.push({at:O,special:L.id,color:C});}for(let O of p.values())o.push({...O,match:true});}Wa(e,s,o);for(let c of a){let p=e.cells[c.at.row][c.at.col];p.piece||p.block||p.hole||(p.piece=zs(e,c.special==="rainbow"?Ta:c.color,c.special),s.created.push({...c.at,piece:p.piece}));}return Ha(e,s),s}function Fp(e){let t=new Set;for(let r of e)for(let[s,n]of r.cells){let o=`${s},${n}`;if(t.has(o))return {col:s,row:n};t.add(o);}return null}var Up=e=>{let[t,r]=e.cells[Math.floor(e.cells.length/2)];return {col:t,row:r}};function Wa(e,t,r){let s=new Set,n=new Set;for(;r.length>0;){let o=r.shift(),a=`${o.col},${o.row}`;if(!Ns(e,o.col,o.row))continue;let c=e.cells[o.row][o.col];if(c.hole)continue;if(c.block){!o.match&&!n.has(a)&&(n.add(a),Is(t,c,"block",o));continue}if(s.has(a))continue;s.add(a);let p=c.piece;if(p){if(c.over){Is(t,c,"over",o);continue}if(p.color!==Br){if(c.piece=null,t.cleared.push({...o,piece:p}),c.under&&(c.under.id==="slime"&&(t.slimeCleared=true),Is(t,c,"under",o)),o.match)for(let[x,E]of qc){let L=nn(e,o.col+x,o.row+E),O=`${o.col+x},${o.row+E}`;L?.block&&!n.has(O)&&Hr[L.block.id]?.hitByNear&&(n.add(O),Is(t,L,"block",{col:o.col+x,row:o.row+E}));}p.special&&Xp(e,t,p.special,o,p.color,r);}}}}function Is(e,t,r,s){let n=t[r];n.hp-=1,e.hits.push({...s,id:n.id,hp:Math.max(0,n.hp)}),n.hp<=0&&(t[r]=null);}function Xp(e,t,r,s,n,o){t.fired.push({...s,kind:r});let c=yn.find(p=>p.id===r)?.shape??r;for(let p of ja(e,c,s,n))o.push({...p,match:false});}var Us=(e,t,r)=>ja(e,t,r,-1);function ja(e,t,r,s){let n=[],o=c=>{for(let p=0;p<e.cols;p++)n.push({col:p,row:c});},a=c=>{for(let p=0;p<e.rows;p++)n.push({col:c,row:p});};if(t==="row")o(r.row);else if(t==="col")a(r.col);else if(t==="cross")o(r.row),a(r.col);else if(t.startsWith("cross:")){let c=Number(t.slice(6));for(let p=-c;p<=c;p++)o(r.row+p),a(r.col+p);}else if(t.startsWith("area:")){let c=Number(t.slice(5));for(let p=-c;p<=c;p++)for(let x=-c;x<=c;x++)n.push({col:r.col+x,row:r.row+p});}else if(t==="color"){let c=s>=0?s:Qc(e);for(let p=0;p<e.rows;p++)for(let x=0;x<e.cols;x++)e.cells[p][x].piece?.color===c&&n.push({col:x,row:p});}else if(t==="all")for(let c=0;c<e.rows;c++)o(c);return n.filter(c=>Ns(e,c.col,c.row))}function Qc(e){let t=new Map;for(let n of e.cells)for(let o of n)Vp(o.piece)&&!o.block&&t.set(o.piece.color,(t.get(o.piece.color)??0)+1);let r=e.colors[0]??0,s=-1;for(let[n,o]of t)o>s&&(s=o,r=n);return r}function qp(e,t,r,s,n,o){let a=[],c=s.special??"plain",p=o.special??"plain",x=Wc.find(L=>L.a===c&&L.b===p||L.a===p&&L.b===c);e.cells[r.row][r.col].piece=null,e.cells[n.row][n.col].piece=null,t.cleared.push({...r,piece:s},{...n,piece:o}),t.fired.push({...n,kind:x?.effect??"combo"});let E=c==="rainbow"?o:s;if(x?.effect==="color"||x?.effect==="turn"){let L=E.color>=0?E.color:Qc(e);for(let O=0;O<e.rows;O++)for(let C=0;C<e.cols;C++){let I=e.cells[O][C].piece;I?.color===L&&(x.effect==="turn"&&E.special&&E.special!=="rainbow"&&(I.special=E.special==="row"||E.special==="col"?e.rnd()<.5?"row":"col":E.special),a.push({col:C,row:O,match:false}));}}else for(let L of ja(e,x?.effect??"cross",n,E.color))a.push({...L,match:false});Wa(e,t,a);}function Ha(e,t){for(let r=0;r<4;r++){for(let n=0;n<e.cols;n++){let o=e.rows-1;for(;o>=0;){if(Ra(e.cells[o][n])){o--;continue}let a=o;for(;a-1>=0&&!Ra(e.cells[a-1][n]);)a--;let c=[];for(let E=o;E>=a;E--){let L=e.cells[E][n].piece;L&&c.push(L);}let p=o;for(let E of c)e.cells[p--][n].piece=E;let x=-1;for(;p>=a;p--){let E=a===Kp(e,n)&&e.dropsToSpawn>0&&Qp(e)<2&&e.rnd()<.35,L=E?zs(e,Br):zs(e,Ws(e,e.colors));E&&e.dropsToSpawn--,e.cells[p][n].piece=L,t.spawned.push({col:n,row:p,piece:L,from:a+x--});}o=a-1;}}let s=false;for(let n=0;n<e.cols;n++){let o=Zp(e,n);if(o<0)continue;let a=e.cells[o][n];a.piece?.color===Br&&(a.piece=null,t.dropsCollected++,s=true);}if(!s)break}}var Kp=(e,t)=>{for(let r=0;r<e.rows;r++)if(!Ra(e.cells[r][t]))return r;return -1},Zp=(e,t)=>{for(let r=e.rows-1;r>=0;r--)if(!e.cells[r][t].hole)return e.cells[r][t].block?-1:r;return -1},Qp=e=>{let t=0;for(let r of e.cells)for(let s of r)s.piece?.color===Br&&t++;return t};var Yp="boss-spawned",Jp="boss-defeated",on=$e("match3.gem"),Yc=$e("match3.overlay"),Ba=$e("match3.layer"),Jc=$e("match3.backdrop"),ed=$e("match3.part"),Vr=(e,t)=>{let r=Number(e.vars[t]??0);return Number.isFinite(r)?r:0},Xs={id:"match3",version:2,engines:["phaser"],requires:["round"],params:{difficulty:{type:"number",default:.5,min:0,max:1},pieceScore:{type:"number",default:10,min:1,max:1e3,integer:true},coinEvery:{type:"number",default:8,min:1,max:100,integer:true},moveBonus:{type:"number",default:100,min:0,max:1e4,integer:true}},setup({world:e,params:t}){let r=i=>cr(t,i),s=e.rng.stream("match3"),n=Un(1,r("difficulty")),o=js(Os.plain,[0,1,2,3,4],()=>s.next(),ka),a=st(),c="idle",p=new Map,x=new Map,E=null,L=null,O=null,C=null,I=0,K=false,ne=0,V=0,ce=0,oe=0,le=0,Ae=false,xe=false,we={colors:new Map,drops:0},ge=Ds,ke=Ds,pe=0,Te=0,Be=false,ze=[],Y=null,Le=0,J=0,Se=0,Ee=null,ve=[],Pe=new Map,Ue=()=>Fn.find(i=>i.id===e.vars["meta:hero"])??Fn[0],se=()=>Ts(Ue().skill),Me=()=>n.def.kind==="battle",lt=()=>e.vars.reviving===true,_e=()=>jc*Math.pow(1.06,n.level-1)*(1+Vr(e,"meta:attack")),ct=()=>1+Vr(e,"meta:skill"),dt=()=>se().mana;function st(){return rn(Ne(e),o.cols,o.rows,{top:.33,bottom:.96,widthShare:.94})}let Ye=()=>a.cell,ft=new Set,qe=(i,f,k,d,u=1)=>{ft.add(i);let w=Pe.get(i);(w===void 0||!e.isAlive(w))&&(w=e.create(),e.set(w,ed,{id:i}),Pe.set(i,w)),e.set(w,G,{x:f,y:k,scale:u}),e.set(w,te,d);},wt=i=>{for(let[f,k]of [...Pe])f.startsWith(i)&&(e.destroy(k),Pe.delete(f));},Je=i=>{let f=Ye();if(i===Ta)return {shape:"sprite",art:"m3_rainbow",w:f*.9,h:f*.9,depth:3};if(i===Br)return {shape:"sprite",art:"m3_crate",w:f*.86,h:f*.86,depth:3};let k=Ho(i);return {shape:"sprite",art:k?.art??"gem1",w:f*.88,h:f*.88,color:k?.color??"piece1",depth:3}},pt=(i,f,k,d,u)=>{let w=nt(a,f,u),M=e.create();return e.set(M,on,{id:i,col:f,row:k,kind:d}),e.set(M,G,{x:w.x,y:w.y}),e.set(M,te,Je(d)),p.set(i,M),M},yt=()=>{let i=Pa(o);for(let[f,k]of [...p])i.has(f)||(e.destroy(k),p.delete(f));for(let[f,k]of i){let d=p.get(f);d===void 0&&(d=pt(f,k.col,k.row,k.piece.color,k.row-o.rows));let u=e.need(d,on);u.col=k.col,u.row=k.row,u.kind!==k.piece.color&&(u.kind=k.piece.color,e.set(d,te,Je(k.piece.color)));let w=k.piece.special&&k.piece.special!=="rainbow"?yn.find(v=>v.id===k.piece.special):void 0,M=x.get(f);w&&M===void 0&&(M=e.create(),e.set(M,Yc,{of:f}),e.set(M,G,{x:0,y:0}),x.set(f,M)),w&&M!==void 0&&e.set(M,te,{shape:"sprite",art:w.art,w:Ye()*.95,h:Ye()*.95,depth:4}),!w&&M!==void 0&&(e.destroy(M),x.delete(f));}for(let[f,k]of [...x])i.has(f)||(e.destroy(k),x.delete(f));et();},et=()=>{at(e,Ba);let i=Ye();for(let f=0;f<o.rows;f++)for(let k=0;k<o.cols;k++){let d=o.cells[f][k],u=nt(a,k,f),w=(M,v,b,_=1)=>{if(!v)return;let A=Hr[v.id],D=e.create();e.set(D,Ba,{key:M}),e.set(D,G,{x:u.x,y:u.y}),e.set(D,te,{shape:"sprite",art:v.hp>=2&&A?.id==="ice"?"m3_ice2":v.hp>=2&&A?.id==="stone"?"m3_stone2":A?.art??"m3_stone",w:i*_,h:i*_,depth:b});};w(`u${k},${f}`,d.under,1.5,.98),w(`o${k},${f}`,d.over,5,.98),w(`b${k},${f}`,d.block,3,.95);}},Ze=()=>{at(e,Jc),Ot(e,"board",a.top+a.cell*o.rows*.35);let i=Ye(),f=nt(a,(o.cols-1)/2,(o.rows-1)/2),k=i*.25,d=(u,w,M)=>{let v=e.create();e.set(v,Jc,{i:0}),e.set(v,G,{x:u,y:w}),e.set(v,te,M);};d(f.x,f.y,{shape:"sprite",art:"panel",w:i*o.cols+k*2,h:i*o.rows+k*2,color:"panel",alpha:.9,depth:-10});for(let u=0;u<o.rows;u++)for(let w=0;w<o.cols;w++){if(o.cells[u][w].hole)continue;let M=nt(a,w,u);d(M.x,M.y,{shape:"sprite",art:"cell",w:i-2,h:i-2,color:(u+w)%2?"panel":"ground",alpha:.85,depth:-9});}},ut=()=>{let i=Ne(e),f=i.h*.12,k=a.top-Ye()*.4,d=Math.max(40,(k-f)*.92);if((Ee===null||!e.isAlive(Ee))&&(Ee=e.create()),e.set(Ee,G,{x:i.w*.15,y:k-d/2}),e.set(Ee,te,{shape:"actor",cast:Ue().cast,h:d,pose:"idle",facing:1,depth:20}),Y&&e.isAlive(Y.entity)){let u=d*Y.def.size;e.set(Y.entity,G,{x:i.w*.82,y:k-u/2});let w=e.need(Y.entity,te);w.shape==="actor"&&(w.h=u);}},gt=()=>n.def.kind!=="goal"?[]:n.def.goals.map(i=>({goal:i,left:i.kind==="color"?Math.max(0,i.count-(we.colors.get(i.color)??0)):i.kind==="clear"?Bs(o,i.obstacle):i.kind==="drops"?Math.max(0,i.count-we.drops):Math.max(0,i.value-Number(e.vars.score??0))})),Wt=()=>gt().every(i=>i.left===0),Ft=i=>{let f=Ne(e).w*.07;if(i.kind==="color"){let k=Ho(i.color);return {shape:"sprite",art:k?.art??"gem1",w:f,h:f,color:k?.color??"piece1",depth:70}}return i.kind==="clear"?{shape:"sprite",art:Hr[i.obstacle]?.art??"m3_stone",w:f,h:f,depth:70}:i.kind==="drops"?{shape:"sprite",art:"m3_crate",w:f,h:f,depth:70}:{shape:"sprite",art:"coin",w:f,h:f,depth:70}},Ut=(i,f,k,d,u,w)=>{let M=Math.max(8,d*.09);qe(`${i}:bg`,f,k,{shape:"rect",w:d,h:M,color:"#000000",alpha:.5,radius:M/2,depth:69});let v=Math.max(1,(d-4)*Math.max(0,Math.min(1,u)));qe(`${i}:fill`,f-(d-4)/2+v/2,k,{shape:"rect",w:v,h:M-4,color:w,radius:(M-4)/2,depth:69.1});},R=()=>{let i=Ne(e),f=Math.min(i.w,i.h),k=(_,A,D,j,q="text",B=f*.045)=>qe(_,A,D,{shape:"text",text:j,size:Math.round(B),color:q,bold:true,depth:70}),d=a.top-Ye()*.4,u=i.h*.085;ve=[],ft.clear();let w=i.w*.36,M=(u+d)/2+f*.02,v=f*.07,b=Te>=dt();if(ve.push({id:"skill",x:w,y:M,r:v*1.15}),b&&qe("h:skill:glow",w,M,{shape:"circle",r:v*1.25,color:Be?"coin":"secondary",alpha:.5+.3*Math.sin(e.time*7),depth:68.9}),qe("h:skill:bg",w,M,{shape:"circle",r:v,color:"panel",alpha:.95,depth:69}),qe("h:skill:i",w,M,{shape:"sprite",art:se().art,w:v*1.4,h:v*1.4,alpha:b?1:.45,depth:69.2}),Ut("h:mana",w,M+v*1.45,v*2.2,Te/dt(),"secondary"),Me()){let _=i.w*.15;if(Ut("h:hp",_,u,i.w*.24,ge/ke,"accent"),k("h:hp:t",_+i.w*.12+f*.05,u,`${Math.ceil(ge)}`,"text",f*.034),pe>0&&(qe("h:sh:i",_+i.w*.12+f*.05,u+f*.055,{shape:"sprite",art:"m3_shield",w:f*.045,h:f*.045,color:"primary",depth:70}),k("h:sh:t",_+i.w*.12+f*.11,u+f*.055,`${Math.ceil(pe)}`,"primary",f*.03)),Y){let A=i.w*.78;Ut("h:foe",A,u,i.w*.26,Y.hp/Y.max,"danger"),k("h:foe:t",A-i.w*.13-f*.05,u,`${Math.ceil(Y.hp)}`,"text",f*.034);let D=jo[Y.def.element];qe("h:foe:el",A+i.w*.13+f*.03,u,{shape:"circle",r:f*.018,color:D.color,depth:70});let j=(u+d)/2;qe("h:foe:in:bg",i.w*.62,j,{shape:"circle",r:f*.045,color:Y.in<=1?"danger":"panel",alpha:.95,depth:69}),k("h:foe:in",i.w*.62,j,String(Y.in),"text",f*.045);let q=n.def.kind==="battle"?n.def.enemies.length:0;for(let B=0;B<q;B++)qe(`h:q:${B}`,i.w*.8+(B-(q-1)/2)*f*.04,d+f*.005,{shape:"circle",r:f*.012,color:B<Le?"muted":B===Le?"danger":"text",alpha:.9,depth:70});}}else {k("h:moves",i.w*.5,u+f*.01,String(V),V<=3?"danger":"text",f*.075);let _=gt(),A=i.w*.64,D=i.w*.11,j=(u+d)/2+f*.02;_.forEach((q,B)=>{let de=A+B*D;qe(`h:g:${B}`,de,j,Ft(q.goal)),k(`h:g:${B}:t`,de,j+f*.06,q.left===0?"\u2713":String(q.left),q.left===0?"accent":"text",f*.038);});}e.vars.m3_phase=c,e.vars.m3_buttons=ve.map(_=>`${_.id}@${Math.round(_.x)},${Math.round(_.y)}`).join(";");for(let[_,A]of [...Pe])!_.startsWith("h:")||ft.has(_)||(e.destroy(A),Pe.delete(_));},z=()=>{Y&&e.isAlive(Y.entity)&&ot(e,Y.entity,"die");let i=ze.shift();if(i===void 0){Y=null;return}let f=Bo(i),k=e.create();e.set(k,G,{x:0,y:0}),e.set(k,te,{shape:"actor",cast:f.cast,variant:f.variant??s.int(0,99),h:50,pose:"idle",facing:-1,depth:20});let d=f.hp*n.enemyHp;Y={def:f,hp:d,max:d,in:f.every,rage:1,entity:k},ut(),f.boss&&(e.emit(Yp,{kind:i}),H(e,{kind:"shake",power:1})),y();},y=()=>{if(e.vars.moves=V,e.vars.hero_hp=Math.ceil(ge),e.vars.mana=Math.floor(Te),e.vars.m3_goals=gt().map(i=>`${i.goal.kind==="color"?`color${i.goal.color}`:i.goal.kind==="clear"?i.goal.obstacle:i.goal.kind}:${i.left}`).join(","),e.vars.m3_enemy=Y?`${Y.def.id}:${Math.ceil(Y.hp)}/${Math.ceil(Y.max)}:${Y.in}`:"",Me()){let i=n.def.kind==="battle"?n.def.enemies.length:1;e.vars.level_progress=Math.min(1,(Le+(Y?1-Y.hp/Y.max:0))/i);}else {let i=n.def;if(i.kind==="goal"){let f=i.goals.map(d=>d.kind==="color"||d.kind==="drops"?d.count:d.kind==="score"?d.value:1),k=gt();e.vars.level_progress=k.reduce((d,u,w)=>d+(u.goal.kind==="clear"?u.left===0?1:0:1-u.left/f[w]),0)/Math.max(1,k.length);}}},S=()=>{at(e,on),at(e,Yc),at(e,Ba),at(e,ed),p.clear(),x.clear(),Pe.clear(),Y&&e.isAlive(Y.entity)&&e.destroy(Y.entity),Y=null,n=Un(Vr(e,"meta:chapter")||1,r("difficulty"));let i=n.def;o=js(Os[i.board]??Os.plain,n.colors,()=>s.next(),ka,i.kind==="goal"?i.drops??0:0),a=st(),Ze(),c="idle",E=null,L=null,O=null,C=null,I=0,K=false,ne=0,we.colors.clear(),we.drops=0,V=i.kind==="goal"?i.moves+Vr(e,"meta:moves"):0,ce=V,oe=0,le=0,Ae=false,xe=false,ke=Ds*Math.pow(1.06,n.level-1)*(1+Vr(e,"meta:health")),ge=ke,pe=0,Te=0,Be=false,Le=0,J=0,Se=0,ze=i.kind==="battle"?[...i.enemies]:[],e.vars.m3_level=n.level,e.vars.m3_world=n.world,e.vars.m3_kind=i.kind,e.vars.coins=0,e.vars.score=0,e.vars.stars=0,e.vars.reviving=false,yt(),ut(),i.kind==="battle"&&z(),y();},$=i=>{if(!i||!Y)return 1;let f=jo[i].beats.includes(Y.def.element),k=i===Y.def.element;return (f?1.5:k?.5:1)*(i===Ue().element?1.25:1)},l=(i,f=0)=>{I++,K||=i.slimeCleared,we.drops+=i.dropsCollected;let k=f,d=0,u=0,w=Ye();for(let _ of i.cleared){let A=_.piece;A.color>=0&&we.colors.set(A.color,(we.colors.get(A.color)??0)+1);let D=Ho(A.color),j=nt(a,_.col,_.row);H(e,{kind:"burst",x:j.x,y:j.y,color:D?.color??"coin",n:6,size:w*.8}),Te=Math.min(dt(),Te+Vc*(1+Vr(e,"meta:mana"))),!(!Me()||!D)&&(D.role==="attack"?k+=_e()*$(D.element)*(1+.25*(I-1)):D.role==="heal"?d+=Hc*Math.pow(1.06,n.level-1)*(1+Vr(e,"meta:health")):D.role==="shield"&&(u+=Bc*Math.pow(1.06,n.level-1)*(1+Vr(e,"meta:defense"))));}for(let _ of i.fired){let A=nt(a,_.col,_.row);H(e,{kind:"ring",x:A.x,y:A.y,color:"coin",size:w*2.4});}i.fired.length>0&&H(e,{kind:"shake",power:.4+Math.min(1,i.fired.length*.2)});for(let _ of i.created)e.emit("special-made",{kind:_.piece.special});let M=i.cleared.length*r("pieceScore")*I+i.fired.length*30;Ke(e,"score",M),ne+=i.cleared.length;let b=Math.floor(ne/r("coinEvery"))-Math.floor((ne-i.cleared.length)/r("coinEvery"));b>0&&(Ke(e,"coins",b),e.emit("coin-collected",{value:b})),e.emit("pieces-cleared",{count:i.cleared.length,cascade:I}),Me()&&(d>0&&(ge=Math.min(ke,ge+d),Ee!==null&&H(e,{kind:"pop",x:e.need(Ee,G).x,y:e.need(Ee,G).y-w,text:`+${Math.round(d)}`,color:"accent",size:Math.round(w*.45)})),u>0&&(pe+=u),k>0&&Y&&h(k)),yt(),y();},h=i=>{if(!Y)return;Y.hp-=i,Ee!==null&&Ge(e,Ee,"attack"),Ge(e,Y.entity,"hit");let f=e.need(Y.entity,G);H(e,{kind:"pop",x:f.x,y:f.y-Ye(),text:`-${Math.round(i)}`,color:"danger",size:Math.round(Ye()*.5)}),!(Y.hp>0)&&(Le++,e.emit("enemy-defeated",{kind:Y.def.id}),m(),Y.def.boss&&(J++,Ke(e,"coins",10),e.emit(Jp,{kind:Y.def.id}),H(e,{kind:"flash",color:"coin"})),z());},m=()=>{if(!Y)return;ot(e,Y.entity,"die");let i=Y.entity;e.need(i,te).alpha=.6,T(()=>{e.isAlive(i)&&e.destroy(i);});},g=[],T=i=>g.push({t:.9,f:i}),N=()=>{if(za(o,K),K=false,I=0,yt(),n.def.kind==="goal"){if(Wt())return ie();if(V<=0)return Ie("out-of-moves")}else {if(!Y)return ie();if(Y.in--,Y.in<=0){c="enemy",le=.45;return}}P();},P=()=>{c="idle",qn(o)===null&&(Oa(o),yt(),e.emit("board-shuffled",{})),y();},Z=()=>{if(!Y)return P();let i=Y.def,f=n.enemyAttack*i.attack*Y.rage;Y.rage=1,Ge(e,Y.entity,"attack");let k=Math.min(pe,f);if(pe-=k,f=(f-k)*(1-Math.min(.6,Vr(e,"meta:defense"))),f>0){if(ge-=f,Ee!==null){Ge(e,Ee,"hit");let u=e.need(Ee,G);H(e,{kind:"pop",x:u.x,y:u.y-Ye(),text:`-${Math.round(f)}`,color:"danger",size:Math.round(Ye()*.5)});}H(e,{kind:"shake",power:.8}),e.emit("player-hit",{hp:Math.ceil(ge)});}let d=i.skill;if(d?.kind==="sow"?Na(o,d.obstacle,d.count):d?.kind==="heal"?Y.hp=Math.min(Y.max,Y.hp+Y.max*d.share):d?.kind==="rage"&&(Y.rage=d.mult),Y.in=i.enrage&&Y.hp<Y.max*i.enrage?Math.max(1,i.every-1):i.every,yt(),ge<=0)return ge=0,Ie("fell");P();},ie=()=>{if(n.def.kind==="goal"){Se=Math.min(V,12),e.vars.stars=Math.min(Ae?1:3,wa(V/Math.max(1,ce),false)),Ke(e,"score",V*r("moveBonus")),c="finale",le=.3;return}e.vars.stars=Math.min(Ae?1:3,wa(ge/ke,true)),re("cleared");},re=i=>{if(xe)return;xe=true,c="over";let f=i==="cleared";f&&e.vars["meta:first_clear"]===true&&Ke(e,"coins",n.firstClearGold),f||(e.vars.stars=0),e.vars.reviving=false,y(),e.emit(Bt,{reason:i,stats:{chapter:n.level,seconds:Math.floor(oe),cleared:f,stars:Number(e.vars.stars??0),coins:Number(e.vars.coins??0),bosses:J,kills:Le,battle:Me()}});},Ie=i=>{if(e.vars.revive_ready===true&&!Ae){e.vars.reviving=true,e.vars.m3_revive_reason=i,c="idle",e.emit(Kt,{});return}re(i);},Ce=()=>{lt()&&(Ae=true,e.vars.reviving=false,Me()?(ge=ke*Uc,Y&&(Y.in=Y.def.every)):V+=Fc,H(e,{kind:"flash",color:"coin"}),P());},De=i=>{let f=o.cells[i.row]?.[i.col];if(!f||f.hole)return 0;let k=n.def.kind==="goal"?n.def.goals:[],d=0;for(let w of [f.under,f.over,f.block])w&&(d+=k.some(M=>M.kind==="clear"&&M.obstacle===w.id)?6:3);let u=f.piece;if(u&&!f.block){d+=1,u.special&&(d+=3),k.some(M=>M.kind==="color"&&M.color===u.color)&&(d+=2);let w=Ho(u.color);Me()&&w?.role==="attack"&&(d+=$(w.element));}if(k.some(w=>w.kind==="drops"))for(let w=0;w<i.row;w++)o.cells[w][i.col].piece?.color===Br&&(d+=2);return d},F=i=>{let f={col:Math.floor(o.cols/2),row:Math.floor(o.rows/2)},k=-1;for(let d=0;d<o.rows;d++)for(let u=0;u<o.cols;u++){if(o.cells[d][u].hole)continue;let w=Us(o,i,{col:u,row:d}).reduce((M,v)=>M+De(v),0);w>k&&(k=w,f={col:u,row:d});}return f},ae=()=>{let i=se();if(Te<i.mana||c!=="idle")return false;let f=ct(),k=[];if(i.kind==="shape"){let w=f>=(i.bigAt??99)&&i.bigShape?i.bigShape:i.shape??"area:1",M=F(w);k=Us(o,w,M);let v=nt(a,M.col,M.row);H(e,{kind:"ring",x:v.x,y:v.y,color:"coin",size:Ye()*4}),H(e,{kind:"flash",color:"coin"});}else k=Fs(o,"line",Math.round((i.count??3)*f));Te=0,Be=false,I=0,Ee!==null&&Ge(e,Ee,"attack"),e.emit("skill-cast",{id:i.id}),$t(e,"m3-skill");let d=Me()&&Y?i.damage*_e()*f*$(Ue().element):0,u=Gs(o,k,i.id);return l(u,d),c="falling",true},Oe=i=>{if(O){let f=o.cells[O.row]?.[O.col]?.piece?.id,k=f!==void 0?p.get(f):void 0;k!==void 0&&(e.need(k,G).scale=1);}if(O=i,i){let f=o.cells[i.row]?.[i.col]?.piece?.id,k=f!==void 0?p.get(f):void 0;k!==void 0&&(e.need(k,G).scale=1.15);}},me=0,ue=(i,f)=>{if(me=0,Ct(e),c!=="idle"||lt()||!Vo(o,i,f))return;Oe(null);let k=o.cells[i.row][i.col].piece.id,d=o.cells[f.row][f.col].piece.id;E=new Map([[k,f],[d,i]]),L=[i,f],c="swapping",$t(e,"match3-swap");};e.on(Tt,i=>{let f=i;if(!(!rt(e)||tn(e)||xe||lt()))if(f.type==="tap"){if(ve.find(u=>Math.hypot(f.x-u.x,f.y-u.y)<=u.r)?.id==="skill"){if(Te<dt())return;ae()||(Be=true);return}let d=Wr(a,f.x,f.y);if(!d||c!=="idle")return;O&&Math.abs(O.col-d.col)+Math.abs(O.row-d.row)===1?ue(O,d):Oe(O&&O.col===d.col&&O.row===d.row?null:d);}else if(f.type==="press"){let k=Wr(a,f.x,f.y);C=k?{x:f.x,y:f.y,...k}:null;}else if(f.type==="move"&&C){let k=f.x-C.x,d=f.y-C.y;if(Math.max(Math.abs(k),Math.abs(d))<a.cell*.45)return;let u={col:C.col,row:C.row},w=Math.abs(k)>Math.abs(d)?{col:u.col+Math.sign(k),row:u.row}:{col:u.col,row:u.row+Math.sign(d)};C=null,ue(u,w);}else f.type==="release"&&(C=null);}),e.on(Ht,()=>{S(),e.vars.level=n.level;}),e.on(Gt,S),e.on(Zt,Ce),e.on(Qt,()=>{lt()&&(e.vars.reviving=false,re(Me()?"fell":"out-of-moves"));}),e.on(Vt,i=>{wt("h:"),ve=[],Ee!==null&&e.isAlive(Ee)&&ot(e,Ee,i.reason==="cleared"?"dance":"die");}),e.on(jt,()=>{a=st(),Ze();for(let[i,f]of p){let k=e.need(f,on);e.set(f,te,Je(k.kind));}yt(),ut();});let Q=i=>{let f=true,k=Math.min(1,i*14),d=Ye();for(let u of e.query(on)){let w=e.need(u,on),M=E?.get(w.id)??w,v=e.need(u,G),b=nt(a,M.col,M.row),_=b.x-v.x,A=b.y-v.y,D=e.need(u,te);Math.abs(_)<.5&&Math.abs(A)<.5?(v.x=b.x,v.y=b.y,D.alpha=1):(f=false,D.alpha=v.y<a.top-d*.3?0:1,v.x+=_*k,v.y+=Math.abs(A)>d*.3?Math.sign(A)*Math.min(Math.abs(A),d*12*i):A*k);}for(let[u,w]of x){let M=p.get(u);if(M===void 0)continue;let v=e.need(M,G);e.set(w,G,{x:v.x,y:v.y,scale:1+.06*Math.sin(e.time*6)}),e.need(w,te).alpha=e.need(M,te).alpha??1;}return f};e.addSystem({id:"match3",order:0,run(i,f){for(let k of [...g])k.t-=f,k.t<=0&&(g.splice(g.indexOf(k),1),k.f());if(!rt(i)||xe){Q(f);return}if(oe+=f,R(),!lt()&&Q(f)){if(le>0){le-=f;return}if(c==="swapping"&&L){let[k,d]=L;L=null,E=null,I=0;let u=Ia(o,k,d);if(!u){let w=o.cells[k.row][k.col].piece.id,M=o.cells[d.row][d.col].piece.id;E=new Map([[w,d],[M,k]]),c="returning";return}n.def.kind==="goal"&&V--,l(u),c="falling";return}if(c==="returning"){if(E){E=null;return}c="idle";return}if(c==="falling"){let k=Vs(o);if(k){l(k);return}N();return}if(c==="enemy"){Z();return}if(c==="finale"){if(Se>0){Se--,V=Math.max(0,V-1);let d=Fs(o,"line",1);d.length>0&&l(Gs(o,d,"finale")),yt(),le=.12;return}let k=Vs(o);if(k){l(k);return}re("cleared");return}if(c==="idle"&&Be){ae();return}if(c==="idle"){if(me+=f,(!xt(i,"match3-swap")||me>7)&&!kr(i)){let k=qn(o);k&&bt(i,"swipe",nt(a,k[0].col,k[0].row),nt(a,k[1].col,k[1].row),a.cell*1.1);}if(Te>=dt()&&!xt(i,"m3-skill")&&!kr(i)){let k=ve.find(d=>d.id==="skill");k&&bt(i,"tap",k,void 0,a.cell*1.2);}}}}}),S();}};var Go=[{id:"garden",prefix:"item",levels:8,color:"accent",gen:"mg_gen_garden"},{id:"bake",prefix:"mg_bake",levels:7,color:"coin",gen:"mg_gen_bake"},{id:"jewel",prefix:"mg_jewel",levels:7,color:"primary",gen:"mg_gen_jewel"},{id:"potion",prefix:"mg_potion",levels:7,color:"secondary",gen:"mg_gen_potion"}],wr=e=>Go.find(t=>t.id===e),Va=3,td=[0,.2,.35],rd=.06,dr={box:{id:"box",layer:"block",art:["mg_box","mg_box2"],neighbour:true,coins:1},fog:{id:"fog",layer:"cover",art:["mg_fog"],neighbour:true,hides:true},web:{id:"web",layer:"cover",art:["mg_web"],neighbour:true,mergeInto:true},bubble:{id:"bubble",layer:"cover",art:["mg_bubble"],neighbour:false,mergeInto:true,ttl:14}},Ga=[{id:"joker",art:"mg_joker",effect:"joker"},{id:"scissors",art:"mg_scissors",effect:"split"},{id:"chest",art:"chest",effect:"chest",amount:3},{id:"battery",art:"mg_energy",effect:"energy",amount:6}],Gr=e=>Ga.find(t=>t.id===e),Fa=[[1,.5],[2,.35],[3,.15]],Ua={"-":{kind:"free"},".":{kind:"hole"},A:{kind:"gen",chain:0},B:{kind:"gen",chain:1},C:{kind:"gen",chain:2},D:{kind:"gen",chain:3},a:{kind:"item",chain:0,level:1},b:{kind:"item",chain:1,level:1},c:{kind:"item",chain:2,level:1},d:{kind:"item",chain:3,level:1},x:{kind:"block",obstacle:"box",hp:1},X:{kind:"block",obstacle:"box",hp:2},f:{kind:"cover",obstacle:"fog",levels:[1,2,2,3]},w:{kind:"cover",obstacle:"web",levels:[2,2,3]},u:{kind:"cover",obstacle:"bubble",levels:[3,3,4]},J:{kind:"special",special:"joker"},S:{kind:"special",special:"scissors"},K:{kind:"special",special:"chest"},E:{kind:"special",special:"battery"}},nd=7,od=8,gn={start:["-------","-------","--a-a--","---A---","--a----","-------","-------","-------"],two:["-------","-------","-a---b-","--A-B--","-------","-------","-------","-------"],boxes:["-------","-------","--A-B--","-------","xxxxxxx","x--K--x","x-----x","xxxxxxx"],fog:["fffffff","fffffff","-------","--A-B--","-------","-------","xx-E-xx","xx---xx"],yard:["X-----X","-------","-A-J-B-","-------","xx---xx","fx---xf","ffx-xff","fffffff"],cellar:["XxxxxxX","x-----x","x-A-B-x","x-----x","x--K--x","xfffffx","xfffffx","XxxxxxX"],webs:["-------","-w---w-","--A-B--","---C---","-w---w-","-------","--www--","-------"],mine:["XX---XX","X--S--X","--A-C--","---B---","-------","ffXXXff","fff-fff","fffffff"],workshop:["w--E--w","-------","-A-B-C-","-------","xwxwxwx","-------","x--K--x","XXXXXXX"],vault:["XfffffX","fx---xf","f-A-B-f","f--J--f","f-C---f","fx---xf","XfffffX","XXXXXXX"],bubbles:["-------","-u---u-","--A-B--","---C---","-------","-u---u-","--uuu--","-------"],holes:["..---..",".-----.","--A-B--","---C---","---D---","--fff--",".-fff-.","..---.."],lab:["u-----u","-x-E-x-","--A-D--","-------","--B-C--","-w---w-","xxwuwxx","XXXXXXX"],terrace:["...-...","..---..",".-A-B-.","---J---","-C---D-","-u-x-u-","xxfffxx","XXfffXX"],four:["-------","-A---B-","-------","---J---","-------","-C---D-","xxxxxxx","XXXXXXX"],fortress:["ffXXXff","fx---xf","X-A-B-X","X--S--X","X-C-D-X","fx-K-xf","ffXXXff","fffffff"],maze:["-x-u-x-","-x---x-","-xA-Bx-","--w-w--","-xC-Dx-","-x---x-","-xfffx-","XXfffXX"],palace:["uXXXXXu","X--E--X","X-A-B-X","X--J--X","X-C-D-X","Xw---wX","XffKffX","XXXXXXX"]},Xa=[{id:"upgrade",art:"mg_sk_merge",charge:10,effect:"upgrade",count:3},{id:"free",art:"mg_sk_free",charge:9,effect:"free",count:6},{id:"joker",art:"mg_sk_joker",charge:12,effect:"joker",count:2}],Zs=e=>Xa.find(t=>t.id===e),Zn=[{id:"hero",cast:"hero",gems:0,skill:"upgrade"},{id:"hero2",cast:"hero2",gems:150,skill:"free"},{id:"hero3",cast:"hero3",gems:300,skill:"joker"}],We=(e,t,r,s,n=0,o=3,a)=>({board:e,chains:[...t].map(c=>({g:"garden",b:"bake",j:"jewel",p:"potion"})[c]??"garden"),orders:r,top:s,double:n,visible:o,...a?{slack:a}:{}}),qs=e=>({...e,vip:true}),Jt=(e,t)=>({...e,extra:t}),Qs=[We("start","g",3,3,0,1,1.6),We("start","g",4,3,0,2,1.5),We("two","gb",4,3,0,2,1.45),We("two","gb",5,4,0,2),We("boxes","gb",5,4,0,3),We("boxes","gb",6,4,.2,3),We("fog","gb",6,4,.2,3),We("yard","gb",6,5,.2,3),We("fog","gb",7,5,.3,3),Jt(qs(We("cellar","gb",6,5,.3,3)),.92),Jt(We("webs","gbj",5,4,.2,3),.92),Jt(We("webs","gbj",6,4,.3,3),.92),Jt(We("mine","gbj",6,5,.2,3),1.15),Jt(We("workshop","gbj",6,5,.3,3),.9),Jt(We("mine","gbj",7,5,.3,3),1.08),Jt(We("yard","gj",6,5,.3,3),1.15),Jt(We("workshop","gbj",7,5,.4,3),.92),We("vault","gbj",7,5,.3,3),Jt(We("webs","jbg",7,6,.3,3),.92),qs(We("vault","gbj",7,6,.4,3)),Jt(We("bubbles","gbp",6,5,.2,3),1.15),Jt(We("bubbles","gbp",6,5,.3,3),1.12),Jt(We("holes","gbpj",6,5,.3,3),.92),Jt(We("lab","gbjp",7,5,.3,3),.92),We("holes","gbpj",7,5,.4,3),We("bubbles","pjg",7,6,.3,3),We("lab","gbjp",7,6,.4,3),We("terrace","gbjp",8,5,.4,3),We("holes","gbpj",8,6,.4,3),qs(We("terrace","gbjp",7,6,.4,3)),We("four","gbjp",7,5,.3,3),Jt(We("fortress","gbjp",7,5,.4,3),1.06),We("maze","gbjp",7,6,.4,3),We("four","gbjp",8,6,.4,3),Jt(We("fortress","gbjp",8,6,.5,3),1.06),We("palace","gbjp",8,6,.4,3),We("maze","gbjp",8,6,.5,3),We("lab","gbjp",9,6,.5,3),We("palace","gbjp",9,6,.5,3),Jt(qs(We("fortress","gbjp",8,6,.5,3)),1.06)],Kn=10,sd=4,Ys=Qs.length,qa=[0,18,45,75];function eh(e){let t=e>>>0;return ()=>{t=t+1831565813>>>0;let r=t;return r=Math.imul(r^r>>>15,r|1),r^=r+Math.imul(r^r>>>7,r|61),((r^r>>>14)>>>0)/4294967296}}var Ks=e=>Math.pow(2,Math.max(0,e-1));function th(e,t){let r=eh(t*7919+13),s=[],n=e.chains;for(let o=0;o<e.orders;o++){let a=e.orders<=1?1:o/(e.orders-1),c=e.vip===true&&o===e.orders-1,p=2+Math.round(a*(e.top-2)),x=Math.max(2,Math.min(e.top,p-(r()<.3?1:0))),E=n[(o+Math.floor(r()*n.length))%n.length],L=[{chain:E,level:c?Math.min(e.top+1,(wr(E)?.levels??7)-1):x}];if(c||o>0&&n.length>1&&r()<e.double){let O=n[(n.indexOf(E)+1+Math.floor(r()*(n.length-1)))%n.length];L.push({chain:O,level:c?e.top:Math.max(2,x-1)});}s.push({wants:L,vip:c});}return s}function rh(e){let t=n=>n.reduce((o,a)=>o+Ks(a),0)/Math.max(1,n.length),r=Fa.reduce((n,[o,a])=>n+Ks(o)*a,0),s=0;for(let n of e.join("")){let o=Ua[n];if(o){if(o.kind==="item")s+=Ks(o.level);else if(o.kind==="cover")s+=t(o.levels)*(dr[o.obstacle]?.mergeInto&&!dr[o.obstacle]?.ttl?.5:.2);else if(o.kind==="special"){let a=Gr(o.special);s+=a?.effect==="energy"?a.amount??0:a?.effect==="chest"?r*(a.amount??0):a?.effect==="joker"?3:2;}}}return s}function Qn(e,t=.5){let r=Math.max(1,Math.min(Ys,Math.floor(e))),s=Qs[r-1],n=Math.ceil(r/Kn),o=th(s,r),a=o.reduce((x,E)=>x+E.wants.reduce((L,O)=>L+Ks(O.level),0),0),c=Math.max(a*.4,a-rh(gn[s.board]??[])*.7),p=(s.slack??1.32-(n-1)*.08-(r-(n-1)*Kn)*.006)*(1.1-t*.2)*(s.extra??1);return {level:r,world:n,index:r-(n-1)*Kn,def:s,boss:s.vip===true,orders:o,energy:Math.ceil(c*p),firstClearGold:(s.vip?120:50)+(r-1)*10}}var Ka=e=>qa[Math.ceil(Math.max(1,e)/Kn)-1]??0,Js=e=>e>=.2?3:e>=.08?2:1,ei=15,Za="kit-merge",Qa=[{id:"Energy",var:"meta:energy",art:"mg_energy",color:"coin",perLevel:2,unit:"",maxLevel:15,price:40,growth:.12},{id:"GenLuck",var:"meta:luck",art:"mg_joker",color:"secondary",perLevel:2,unit:"%",maxLevel:15,price:45,growth:.12},{id:"Reward",var:"meta:reward",art:"coin",color:"coin",perLevel:5,unit:"%",maxLevel:20,price:40,growth:.12},{id:"SkillPower",var:"meta:skill",art:"mg_sk_merge",color:"secondary",perLevel:8,unit:"%",maxLevel:10,price:50,growth:.12},{id:"Charge",var:"meta:charge",art:"mg_sk_free",color:"primary",perLevel:5,unit:"%",maxLevel:10,price:50,growth:.12}],id={game:"merge",character:Za,stats:Qa,heroes:Zn,levels:Ys,firstClearGold:e=>Qn(e).firstClearGold,stars:3,starsToEnter:Ka};var ti=e=>({kind:"none",at:e,hits:[],coins:0}),Fr=e=>wr(e)?.levels??8,Ya=(e,t,r,s,n="")=>({id:e.nextId++,kind:t,chain:r,level:s,special:n}),Fo=(e,t,r)=>Ya(e,"item",t,r),ld=(e,t)=>Ya(e,"special","",0,t);function Ja(e,t,r){let s=Math.max(...e.map(a=>a.length)),n={cols:s,rows:e.length,cells:[],chains:t,nextId:1,rand:r},o=a=>t[a]??null;for(let a=0;a<e.length;a++){let c=[];for(let p=0;p<s;p++){let x=Ua[e[a][p]??"-"]??{kind:"free"},E={hole:x.kind==="hole",thing:null,cover:null,block:null};if(x.kind==="gen"){let L=o(x.chain);L&&(E.thing=Ya(n,"gen",L,1));}else if(x.kind==="item"){let L=o(x.chain);L&&(E.thing=Fo(n,L,x.level));}else if(x.kind==="block")E.block={id:x.obstacle,hp:x.hp};else if(x.kind==="cover"){let L=t[Math.floor(r()*t.length)]??"garden",O=Math.min(Fr(L)-1,x.levels[Math.floor(r()*x.levels.length)]??1);E.thing=Fo(n,L,O);let C=dr[x.obstacle];E.cover={id:x.obstacle,hp:1,...C?.ttl?{ttl:C.ttl}:{}};}else x.kind==="special"&&(E.thing=ld(n,x.special));c.push(E);}n.cells.push(c);}return n}var bn=(e,t)=>e.cells[t.row]?.[t.col],cd=(e,t)=>t.col>=0&&t.row>=0&&t.col<e.cols&&t.row<e.rows,dd=e=>!!e&&!e.hole&&!e.thing&&!e.block,Yn=(e,t)=>{let r=bn(e,t);return !!r&&!!r.thing&&!r.cover&&!r.block};function Lr(e){let t=[];for(let r=0;r<e.rows;r++)for(let s=0;s<e.cols;s++){let n=e.cells[r][s];n.thing&&t.push({at:{col:s,row:r},thing:n.thing,cell:n});}return t}var nh=e=>e.cells.reduce((t,r)=>t+r.filter(dd).length,0);function ri(e,t){let r=null,s=1/0;for(let n=0;n<e.rows;n++)for(let o=0;o<e.cols;o++){if(!dd(e.cells[n][o]))continue;let a=Math.hypot(o-t.col,(n-t.row)*1.05);a<s-1e-9&&(s=a,r={col:o,row:n});}return r}function ni(e,t){let r=t?.thing;return !t||!r||t.block||r===e||e.kind!==r.kind||e.kind==="special"||t.cover&&!dr[t.cover.id]?.mergeInto||e.chain!==r.chain||e.level!==r.level?false:e.kind==="gen"?e.level<Va:e.level<Fr(e.chain)}function ad(e,t){let r=[],s=0;for(let[n,o]of [[1,0],[-1,0],[0,1],[0,-1]]){let a={col:t.col+n,row:t.row+o};if(!cd(e,a))continue;let c=e.cells[a.row][a.col];for(let p of ["block","cover"]){let x=c[p];if(!x)continue;let E=dr[x.id];if(!E?.neighbour)continue;x.hp--;let L=x.hp<=0;L&&(c[p]=null,s+=E.coins??0),r.push({at:a,id:x.id,gone:L,revealed:L&&!!E.hides});}}return {hits:r,coins:s}}function fd(e,t,r){if(!Yn(e,t)||!cd(e,r)||t.col===r.col&&t.row===r.row)return ti(t);let s=bn(e,t),n=bn(e,r),o=s.thing;if(n.hole||n.block)return ti(t);if(ni(o,n)){let x=n.thing;s.thing=null,x.level++;let E=n.cover?.id;n.cover=null;let L=ad(e,r);return {kind:"merge",at:r,level:x.level,...E?{freed:E}:{},hits:L.hits,coins:L.coins}}let a=o.kind==="special"?Gr(o.special):void 0,c=n.thing,p=!n.cover||!!dr[n.cover.id]?.mergeInto;if(a?.effect==="joker"&&c?.kind==="item"&&p&&c.level<Fr(c.chain)){s.thing=null,c.level++;let x=n.cover?.id;n.cover=null;let E=ad(e,r);return {kind:"joker",at:r,level:c.level,...x?{freed:x}:{},hits:E.hits,coins:E.coins}}if(a?.effect==="split"&&c?.kind==="item"&&!n.cover&&c.level>=2){s.thing=null;let x=ri(e,r);return x?(c.level--,e.cells[x.row][x.col].thing=Fo(e,c.chain,c.level),{kind:"split",at:r,level:c.level,second:x,hits:[],coins:0}):(s.thing=o,ti(t))}return c?n.cover?ti(t):(s.thing=c,n.thing=o,{kind:"swap",at:r,hits:[],coins:0}):(s.thing=null,n.thing=o,{kind:"move",at:r,hits:[],coins:0})}function pd(e,t,r=0){let s=bn(e,t)?.thing;if(!s||s.kind!=="gen"||bn(e,t).cover)return null;let n=ri(e,t);if(!n)return null;let o=e.rand(),a=Math.max(1,Math.min(Va,s.level)),c=a>=3&&o<rd?3:o<(td[a-1]??0)+r?2:1,p=Fo(e,s.chain,Math.min(c,Fr(s.chain)));return e.cells[n.row][n.col].thing=p,{at:n,thing:p,burst:oh(e)}}function oh(e){let t=[];for(let r=0;r<e.rows;r++)for(let s=0;s<e.cols;s++){let n=e.cells[r][s];n.cover?.ttl!==void 0&&(n.cover.ttl--,!(n.cover.ttl>0)&&(n.cover=null,n.thing=null,t.push({col:s,row:r})));}return t}var sh=e=>{let t=0;for(let[r,s]of Fa)if(t+=s,e<t)return r;return 1};function hd(e,t){let r=bn(e,t),s=r?.thing;if(!r||!s||s.kind!=="special"||r.cover)return null;let n=Gr(s.special);if(n?.effect==="energy")return r.thing=null,{energy:n.amount??5,spawned:[]};if(n?.effect!=="chest")return null;r.thing=null;let o=[];for(let a=0;a<(n.amount??3);a++){let c=ri(e,t);if(!c)break;let p=e.chains[Math.floor(e.rand()*e.chains.length)]??Go[0].id,x=Fo(e,p,Math.min(Fr(p),sh(e.rand())));e.cells[c.row][c.col].thing=x,o.push({at:c,thing:x});}return o.length===0?(r.thing=s,null):{energy:0,spawned:o}}function ud(e,t={}){let r=Lr(e).filter(o=>Yn(e,o.at)&&(o.thing.kind==="item"||t.gens!==false&&o.thing.kind==="gen")),s=null,n=1/0;for(let o of r)for(let a=0;a<e.rows;a++)for(let c=0;c<e.cols;c++){let p=e.cells[a][c];if(!ni(o.thing,p))continue;let x=(o.thing.kind==="gen"?100:0)+o.thing.level-(p.cover?.5:0);x<n&&(n=x,s=[o.at,{col:c,row:a}]);}return s}function xn(e,t){let r=new Set,s=[],n=Lr(e);for(let o of t){let a=n.find(c=>c.thing.kind==="item"&&!c.cell.cover&&!r.has(c.thing.id)&&c.thing.chain===o.chain&&c.thing.level===o.level);if(!a)return null;r.add(a.thing.id),s.push(a.at);}return s}function el(e,t){let r=bn(e,t);if(!r?.thing)return null;let s=r.thing;return r.thing=null,s}function tl(e,t,r){let s=ri(e,r),n=ld(e,t);if(s)return e.cells[s.row][s.col].thing=n,{at:s,thing:n};let o=Lr(e).filter(a=>a.thing.kind==="item"&&!a.cell.cover).sort((a,c)=>a.thing.level-c.thing.level)[0];return o?(o.cell.thing=n,{at:o.at,thing:n}):null}function md(e){let t=Lr(e),r=nh(e)>0;for(let s of t){if(s.thing.kind!=="special"||s.cell.cover)continue;let n=Gr(s.thing.special);if(n?.effect==="energy"||n?.effect==="chest"&&r||n?.effect==="joker"&&t.some(o=>o.thing.kind==="item"&&(!o.cell.cover||dr[o.cell.cover.id]?.mergeInto)&&o.thing.level<Fr(o.thing.chain))||n?.effect==="split"&&r&&t.some(o=>o.thing.kind==="item"&&!o.cell.cover&&o.thing.level>=2))return true}return false}function yd(e,t,r){let s=[];for(let n=0;n<t;n++){let o=Lr(e).filter(p=>p.thing.kind==="item"&&!p.cell.cover&&p.thing.level<Fr(p.thing.chain)&&!s.some(x=>x.col===p.at.col&&x.row===p.at.row));if(o.length===0)break;let a=p=>r.some(x=>x.chain===p.thing.chain&&x.level===p.thing.level+1);o.sort((p,x)=>Number(a(x))-Number(a(p))||p.thing.level-x.thing.level);let c=o[0];c.thing.level++,s.push(c.at);}return s}var rl=90,Uo=$e("merge.item"),xd=$e("merge.order"),nl=$e("merge.layer"),gd=$e("merge.backdrop"),bd=$e("merge.part"),Jn=$e("merge.customer"),eo=(e,t)=>{let r=Number(e.vars[t]??0);return Number.isFinite(r)?r:0},oi={id:"merge",version:2,engines:["phaser"],requires:["round"],params:{difficulty:{type:"number",default:.5,min:0,max:1},orderReward:{type:"number",default:1,min:0,max:100},mergeScore:{type:"number",default:10,min:1,max:1e3,integer:true},energyBonus:{type:"number",default:20,min:0,max:1e4,integer:true}},setup({world:e,params:t}){let r=l=>cr(t,l),s=e.rng.stream("merge"),n=Qn(1,r("difficulty")),o=Ja(gn.start,["garden"],()=>s.next()),a=Y(),c=new Map,p=new Map,x=null,E=[],L=[],O=0,C=0,I=0,K=0,ne=0,V=0,ce=0,oe=0,le=false,Ae=false,xe=null,we=[],ge=()=>Zn.find(l=>l.id===e.vars["meta:hero"])??Zn[0],ke=()=>Zs(ge().skill),pe=()=>e.vars.reviving===true,Te=()=>ke().charge,Be=()=>eo(e,"meta:luck"),ze=()=>E.flatMap(l=>l.order.wants);function Y(){return rn(Ne(e),o.cols,o.rows,{top:.3,bottom:.86,widthShare:.94})}let Le=()=>a.cell,J=new Set,Se=(l,h,m,g,T=1)=>{J.add(l);let N=p.get(l);(N===void 0||!e.isAlive(N))&&(N=e.create(),e.set(N,bd,{id:l}),p.set(l,N)),e.set(N,G,{x:h,y:m,scale:T}),e.set(N,te,g);},Ee=()=>{for(let[l,h]of [...p])J.has(l)||(e.destroy(h),p.delete(l));},ve=l=>{if(l.kind==="special")return Gr(l.special)?.art??"chest";let h=wr(l.chain);return l.kind==="gen"?h?.gen??"chest":`${h?.prefix??"item"}${Math.min(l.level,h?.levels??8)}`},Pe=l=>{let h=Le(),m=l.kind==="gen"?.94:.92;return {shape:"sprite",art:ve(l),w:h*m,h:h*m,depth:3}},Ue=()=>{let l=new Map(Lr(o).map(h=>[h.thing.id,h]));for(let[h,m]of [...c])l.has(h)||(e.destroy(m),c.delete(h));for(let[h,m]of l){let g=c.get(h);if(g===void 0){g=e.create();let P=nt(a,m.at.col,m.at.row);e.set(g,G,{x:P.x,y:P.y,scale:.3}),c.set(h,g);}e.set(g,Uo,{id:h,col:m.at.col,row:m.at.row});let T=Pe(m.thing),N=m.cell.cover&&dr[m.cell.cover.id]?.hides;e.set(g,te,{...T,alpha:N?0:1,depth:x?.id===h?30:3});}se(),Je();},se=()=>{at(e,nl);let l=Le();for(let h=0;h<o.rows;h++)for(let m=0;m<o.cols;m++){let g=o.cells[h][m],T=nt(a,m,h);for(let[N,P,Z]of [["b",g.block,3],["c",g.cover,5]]){if(!P)continue;let ie=dr[P.id],re=ie?.art[Math.min(ie.art.length,Math.max(1,P.hp))-1]??"mg_box",Ie=e.create();e.set(Ie,nl,{key:`${N}${m},${h}`}),e.set(Ie,G,{x:T.x,y:T.y}),e.set(Ie,te,{shape:"sprite",art:re,w:l*.98,h:l*.98,depth:Z,alpha:P.id==="bubble"&&(P.ttl??99)<=3?.55+.4*Math.abs(Math.sin(e.time*6)):1});}}},Me=()=>{at(e,gd),Ot(e,"board",a.top+a.cell*o.rows*.3);let l=Le(),h=nt(a,(o.cols-1)/2,(o.rows-1)/2),m=l*.22,g=(T,N,P)=>{let Z=e.create();e.set(Z,gd,{i:0}),e.set(Z,G,{x:T,y:N}),e.set(Z,te,P);};g(h.x,h.y,{shape:"sprite",art:"panel",w:l*o.cols+m*2,h:l*o.rows+m*2,color:"panel",alpha:.9,depth:-10});for(let T=0;T<o.rows;T++)for(let N=0;N<o.cols;N++){if(o.cells[T][N].hole)continue;let P=nt(a,N,T);g(P.x,P.y,{shape:"sprite",art:"cell",w:l-3,h:l-3,color:(T+N)%2?"panel":"ground",alpha:.85,depth:-9});}},lt=()=>Math.max(1,n.def.visible),_e=l=>{let h=Ne(e),m=lt(),g=Math.min(h.w*.3,Le()*2.6),T=h.w/2+(l-(m-1)/2)*(g+Le()*.2),N=g*(m>2?.62:.72),P=h.h*.118+N/2,Z=a.top-Le()*.18;return {x:T,y:P,w:g,h:N,feet:Z}},ct=(l,h,m)=>{let g=_e(l),T=Math.max(24,(g.feet-(g.y+g.h/2))*1.05),N=m?-T:g.x,P=e.create();return e.set(P,G,{x:N,y:g.feet-T/2}),e.set(P,te,{shape:"actor",cast:h.vip?"boss":"helper",variant:h.vip?7:s.int(0,99),h:T,pose:m?"walk":"idle",facing:1,speed:rl,depth:6}),e.set(P,Jn,{slot:l,to:g.x,leaving:-1}),P},dt=l=>{for(let h=0;h<lt();h++){if(E.some(g=>g.slot===h))continue;let m=L.shift();m&&E.push({order:m,slot:h,customer:ct(h,m,l)});}},st=(l,h)=>{for(let m of l.query(Jn)){let g=l.need(m,Jn),T=l.need(m,G),N=l.need(m,te);if(N.shape!=="actor")continue;if(g.leaving>=0){g.leaving+=h,g.leaving>.7&&(N.pose="walk",N.facing=1,T.x+=rl*1.4*h);continue}let P=g.to-T.x;Math.abs(P)>1?(T.x+=Math.sign(P)*Math.min(Math.abs(P),rl*2*h),N.pose="walk",N.facing=P>0?1:-1):N.pose==="walk"&&(T.x=g.to,N.pose="idle");}},Ye=l=>Math.max(1,Math.round(l.wants.reduce((h,m)=>h+m.level,0)*r("orderReward")*(l.vip?3:1)*(1+eo(e,"meta:reward")))),ft=l=>{let h=xn(o,l.order.wants);if(!h)return false;let m=_e(l.slot);for(let N of h){let P=nt(a,N.col,N.row);H(e,{kind:"burst",x:P.x,y:P.y,color:"coin",n:8,size:Le()*.8}),el(o,N);}let g=Ye(l.order);Ke(e,"coins",g),Ke(e,"score",g*25),H(e,{kind:"burst",x:m.x,y:m.y,color:"coin",n:14,size:m.w*.8}),H(e,{kind:"pop",x:m.x,y:m.y-m.h*.5,text:`+${g}`,color:"coin",size:Math.round(m.h*.42)}),e.emit("coin-collected",{value:g}),e.emit("order-filled",{reward:g,vip:l.order.vip}),$t(e,"merge-order"),ne++;let T=e.get(l.customer,Jn);return T&&(T.leaving=0,Ge(e,l.customer,"cheer"),mn(e,l.customer,2.4)),E=E.filter(N=>N!==l),dt(true),Ue(),E.length===0&&L.length===0&&yt(),true},qe=(l,h,m,g,T,N)=>{let P=Math.max(8,g*.11);Se(`${l}:bg`,h,m,{shape:"rect",w:g,h:P,color:"#000000",alpha:.5,radius:P/2,depth:69});let Z=Math.max(1,(g-4)*Math.max(0,Math.min(1,T)));Se(`${l}:fill`,h-(g-4)/2+Z/2,m,{shape:"rect",w:Z,h:P-4,color:N,radius:(P-4)/2,depth:69.1});},wt=()=>{let l=Ne(e),h=Math.min(l.w,l.h),m=Le(),g=(me,ue,Q,i,f="text",k=h*.045,d=70)=>Se(me,ue,Q,{shape:"text",text:i,size:Math.round(k),color:f,bold:true,depth:d});we=[],J.clear();let T=l.h*.085;Se("h:en:i",l.w*.1,T,{shape:"sprite",art:"mg_energy",w:h*.07,h:h*.07,depth:70}),g("h:en",l.w*.1+h*.075,T,String(O),O<=3&&I===0?"danger":"text",h*.06),I>0&&g("h:free",l.w*.1+h*.17,T,`+${I}`,"secondary",h*.04);let N=E.length+L.length;Se("h:ord:i",l.w*.8,T,{shape:"sprite",art:"ticket",w:h*.075,h:h*.05,color:"panel",depth:70}),g("h:ord",l.w*.8+h*.08,T,String(N),"text",h*.05);for(let me of E){let ue=_e(me.slot);xn(o,me.order.wants)!==null&&Se(`h:t${me.slot}:glow`,ue.x,ue.y,{shape:"rect",w:ue.w*1.08,h:ue.h*1.14,color:"accent",alpha:.45+.3*Math.sin(e.time*6),radius:ue.h*.2,depth:7.9}),Se(`h:t${me.slot}`,ue.x,ue.y,{shape:"sprite",art:"ticket",w:ue.w,h:ue.h,color:me.order.vip?"coin":"panel",depth:8});let i=me.order.wants.length,f=Math.min(ue.h*.58,ue.w*.86/i);me.order.wants.forEach((k,d)=>{let u=ue.x+(d-(i-1)/2)*f*1.05,w=ue.y-ue.h*.12,M=wr(k.chain);Se(`h:t${me.slot}:${d}`,u,w,{shape:"sprite",art:`${M?.prefix??"item"}${Math.min(k.level,M?.levels??8)}`,w:f,h:f,depth:8.1}),xn(o,[k])?g(`h:t${me.slot}:${d}:ok`,u+f*.32,w+f*.32,"\u2713","accent",f*.42,8.2):g(`h:t${me.slot}:${d}:lv`,u+f*.34,w+f*.34,String(k.level),"coin",f*.3,8.2);}),Se(`h:t${me.slot}:c`,ue.x-ue.w*.1,ue.y+ue.h*.3,{shape:"sprite",art:"coin",w:ue.h*.19,h:ue.h*.19,depth:8.1}),g(`h:t${me.slot}:cv`,ue.x+ue.w*.07,ue.y+ue.h*.3,String(Ye(me.order)),"coin",ue.h*.2,8.1),we.push({id:`order${me.slot}`,x:ue.x,y:ue.y,r:ue.w*.5});}let P=ze();for(let me of Lr(o)){if(me.cell.cover&&dr[me.cell.cover.id]?.hides)continue;let ue=c.get(me.thing.id);if(ue===void 0)continue;let Q=e.need(ue,G),i=x?.id===me.thing.id?31:6;if(me.thing.kind==="gen")for(let f=0;f<me.thing.level;f++)Se(`h:i${me.thing.id}:s${f}`,Q.x+(f-(me.thing.level-1)/2)*m*.2,Q.y+m*.38,{shape:"circle",r:m*.075,color:"coin",depth:i});else me.thing.kind==="item"&&(P.some(f=>f.chain===me.thing.chain&&f.level===me.thing.level)&&(Se(`h:i${me.thing.id}:ok`,Q.x+m*.3,Q.y-m*.3,{shape:"circle",r:m*.12,color:"accent",depth:i}),g(`h:i${me.thing.id}:okt`,Q.x+m*.3,Q.y-m*.3,"\u2713","#ffffff",m*.18,i+.1)),g(`h:i${me.thing.id}:lv`,Q.x+m*.3,Q.y+m*.3,String(me.thing.level),"coin",m*.22,i));}let Z=a.top+m*o.rows+(l.h-(a.top+m*o.rows))*.5,ie=Math.min(h*.075,(l.h-(a.top+m*o.rows))*.38),re=l.w*.3,Ie=K>=Te();we.push({id:"skill",x:re,y:Z,r:ie*1.2}),Ie&&Se("h:skill:glow",re,Z,{shape:"circle",r:ie*1.28,color:"secondary",alpha:.5+.3*Math.sin(e.time*7),depth:68.9}),Se("h:skill:bg",re,Z,{shape:"circle",r:ie,color:"panel",alpha:.95,depth:69}),Se("h:skill:i",re,Z,{shape:"sprite",art:ke().art,w:ie*1.4,h:ie*1.4,alpha:Ie?1:.45,depth:69.2}),qe("h:charge",re+ie*2.6,Z,ie*2.4,K/Te(),"secondary");let Ce=l.w*.88;we.push({id:"bin",x:Ce,y:Z,r:ie*1.1});let De=x?c.get(x.id):void 0,F=De!==void 0?e.need(De,G):null,ae=F!==null&&Math.hypot(F.x-Ce,F.y-Z)<ie*1.3;Se("h:bin:bg",Ce,Z,{shape:"circle",r:ie,color:ae?"danger":"panel",alpha:.95,depth:69}),Se("h:bin",Ce,Z,{shape:"sprite",art:"mg_bin",w:ie*1.3,h:ie*1.3,alpha:x?1:.7,depth:69.2}),(xe===null||!e.isAlive(xe))&&(xe=e.create(),e.set(xe,te,{shape:"actor",cast:ge().cast,h:ie*2.6,pose:"idle",facing:1,depth:20})),e.set(xe,G,{x:l.w*.11,y:Z-ie*.1});let Oe=e.need(xe,te);Oe.shape==="actor"&&(Oe.h=ie*2.6),e.vars.mg_buttons=we.map(me=>`${me.id}@${Math.round(me.x)},${Math.round(me.y)}`).join(";"),Ee();},Je=()=>{e.vars.energy=O,e.vars.mg_free=I,e.vars.mg_charge=Math.floor(K),e.vars.orders_left=E.length+L.length,e.vars.mg_orders=E.slice().sort((l,h)=>l.slot-h.slot).map(l=>l.order.wants.map(h=>`${h.chain}:${h.level}`).join("+")).join("|"),e.vars.level_progress=n.orders.length?ne/n.orders.length:0;},pt=()=>{at(e,Uo),at(e,nl),at(e,bd),at(e,Jn),c.clear(),p.clear(),xe!==null&&e.isAlive(xe)&&e.destroy(xe),xe=null,n=Qn(eo(e,"meta:chapter")||1,r("difficulty")),o=Ja(gn[n.def.board]??gn.start,n.def.chains,()=>s.next()),a=Y(),Me(),x=null,E=[],L=[...n.orders],O=Math.max(0,n.energy+Math.round(eo(e,"meta:energy"))),C=O,I=0,K=0,ne=0,V=0,ce=0,oe=0,le=false,Ae=false,e.vars.mg_level=n.level,e.vars.mg_world=n.world,e.vars.coins=0,e.vars.score=0,e.vars.stars=0,e.vars.reviving=false,dt(false),Ue();},yt=()=>{Ae||(e.vars.stars=Math.min(le?1:3,Js(O/Math.max(1,C))),Ke(e,"score",O*r("energyBonus")),H(e,{kind:"flash",color:"coin"}),et("cleared"));},et=l=>{if(Ae)return;Ae=true;let h=l==="cleared";h&&e.vars["meta:first_clear"]===true&&Ke(e,"coins",n.firstClearGold),h||(e.vars.stars=0),e.vars.reviving=false,Je(),e.emit(Bt,{reason:l,stats:{chapter:n.level,seconds:Math.floor(ce),cleared:h,stars:Number(e.vars.stars??0),coins:Number(e.vars.coins??0),orders:ne,merges:V}});},Ze=()=>{if(e.vars.revive_ready===true&&!le){e.vars.reviving=true,e.emit(Kt,{});return}et("out-of-energy");},ut=()=>{pe()&&(le=true,e.vars.reviving=false,O+=ei,tl(o,"joker",{col:Math.floor(o.cols/2),row:Math.floor(o.rows/2)}),H(e,{kind:"flash",color:"coin"}),Ue());},gt=()=>{if(O>0||I>0||K>=Te()||E.some(m=>xn(o,m.order.wants))||md(o))return true;let l=[...ze(),...L.flatMap(m=>m.wants)],h=Lr(o);for(let m of h)if(!(!Yn(o,m.at)||m.thing.kind!=="item")&&l.some(g=>g.chain===m.thing.chain&&g.level>m.thing.level)&&h.some(g=>ni(m.thing,g.cell)))return true;return false},Wt=l=>{let h=Le(),m=nt(a,l.at.col,l.at.row);if(l.kind==="merge"||l.kind==="joker"){let g=o.cells[l.at.row][l.at.col].thing,T=wr(g.chain)?.color??"coin";H(e,{kind:"ring",x:m.x,y:m.y,color:T,size:h*1.4}),H(e,{kind:"burst",x:m.x,y:m.y,color:"coin",n:8,size:h*.8});let N=c.get(g.id);N!==void 0&&(e.need(N,G).scale=1.35),V++,K=Math.min(Te(),K+1+eo(e,"meta:charge")),Ke(e,"score",Math.pow(2,g.level)*r("mergeScore")),e.emit("items-merged",{level:g.level,chain:g.chain}),$t(e,"merge-merge"),g.kind==="item"&&g.level===Fr(g.chain)&&H(e,{kind:"flash",color:"coin"});for(let P of E)P.order.wants.some(Z=>Z.chain===g.chain&&Z.level===g.level)&&Ge(e,P.customer,"wave");}l.kind==="split"&&H(e,{kind:"ring",x:m.x,y:m.y,color:"secondary",size:h*1.2}),l.freed&&e.emit("obstacle-cleared",{kind:l.freed});for(let g of l.hits){let T=nt(a,g.at.col,g.at.row);H(e,{kind:"burst",x:T.x,y:T.y,color:g.id==="fog"?"#ffffff":"ground",n:g.gone?10:4,size:h*.9}),g.gone&&e.emit("obstacle-cleared",{kind:g.id});}l.coins>0&&(Ke(e,"coins",l.coins),e.emit("coin-collected",{value:l.coins}),H(e,{kind:"pop",x:m.x,y:m.y-h*.5,text:`+${l.coins}`,color:"coin",size:Math.round(h*.4)})),l.hits.length&&H(e,{kind:"shake",power:.25});},Ft=l=>{if(O<=0&&I<=0){let N=nt(a,l.col,l.row);H(e,{kind:"pop",x:N.x,y:N.y-Le()*.5,text:"0",color:"danger",size:Math.round(Le()*.4)});return}let h=pd(o,l,Be()),m=nt(a,l.col,l.row);if(!h){H(e,{kind:"shake",power:.2}),H(e,{kind:"pop",x:m.x,y:m.y-Le()*.5,text:"\u2715",color:"danger",size:Math.round(Le()*.45)});return}I>0?I--:O--,$t(e,"merge-generate");let g=c.get(o.cells[l.row][l.col].thing.id);g!==void 0&&(e.need(g,G).scale=1.2),H(e,{kind:"burst",x:m.x,y:m.y,color:wr(h.thing.chain)?.color??"accent",n:6,size:Le()*.7}),e.emit("item-spawned",{level:h.thing.level,chain:h.thing.chain}),Ue();let T=c.get(h.thing.id);T!==void 0&&e.set(T,G,{x:m.x,y:m.y,scale:.4});for(let N of h.burst){let P=nt(a,N.col,N.row);H(e,{kind:"burst",x:P.x,y:P.y,color:"#ffffff",n:10,size:Le()});}},Ut=l=>{let h=hd(o,l);if(!h)return;let m=nt(a,l.col,l.row);H(e,{kind:"ring",x:m.x,y:m.y,color:"coin",size:Le()*1.6}),h.energy>0&&(O+=h.energy,H(e,{kind:"pop",x:m.x,y:m.y-Le()*.5,text:`+${h.energy}`,color:"coin",size:Math.round(Le()*.45)})),Ue();for(let g of h.spawned){let T=c.get(g.thing.id);T!==void 0&&e.set(T,G,{x:m.x,y:m.y,scale:.4});}},R=()=>{let l=ke();if(K<l.charge)return false;let h=1+eo(e,"meta:skill"),m=Math.max(1,Math.round(l.count*h));if(K=0,xe!==null&&Ge(e,xe,"cheer"),H(e,{kind:"flash",color:"secondary"}),l.effect==="upgrade")for(let g of yd(o,m,[...ze(),...L.slice(0,2).flatMap(T=>T.wants)])){let T=nt(a,g.col,g.row);H(e,{kind:"ring",x:T.x,y:T.y,color:"secondary",size:Le()*1.4});}else if(l.effect==="free")I+=m;else for(let g=0;g<m;g++)tl(o,"joker",{col:Math.floor(o.cols/2),row:Math.floor(o.rows/2)});return e.emit("skill-cast",{id:l.id}),$t(e,"merge-skill"),Ue(),true},z=(l,h)=>we.find(m=>Math.hypot(l-m.x,h-m.y)<=m.r);e.on(Tt,l=>{let h=l;if(!(!rt(e)||tn(e)||Ae||pe())){if(h.type==="press"){Ct(e),oe=0;let m=Wr(a,h.x,h.y);if(!m||!Yn(o,m))return;let g=o.cells[m.row][m.col].thing.id,T=c.get(g);if(T===void 0)return;let N=e.need(T,G);x={id:g,from:m,dx:N.x-h.x,dy:N.y-h.y,x0:h.x,y0:h.y},e.need(T,te).depth=30;}else if(h.type==="move"&&x){let m=c.get(x.id);if(m===void 0)return;let g=e.need(m,G);g.x=h.x+x.dx,g.y=h.y+x.dy,g.scale=1.12;}else if(h.type==="release"&&x){let m=x;x=null;let g=c.get(m.id);if(g!==void 0&&(e.need(g,te).depth=3),Math.hypot(h.x-m.x0,h.y-m.y0)<Le()*.3)return;let T=z(h.x,h.y),N=o.cells[m.from.row][m.from.col].thing;if(T?.id==="bin"&&N&&N.kind!=="gen"){el(o,m.from),$t(e,"merge-bin"),Ue();return}let P=T?.id.startsWith("order")?E.find(re=>`order${re.slot}`===T.id):void 0;if(P&&N?.kind==="item"&&P.order.wants.some(re=>re.chain===N.chain&&re.level===N.level)&&ft(P))return;let Z=Wr(a,h.x,h.y);if(!Z)return;let ie=fd(o,m.from,Z);ie.kind!=="none"&&Wt(ie),Ue();}else if(h.type==="tap"){oe=0;let m=z(h.x,h.y);if(m?.id==="skill"){R();return}if(m?.id.startsWith("order")){let N=E.find(P=>`order${P.slot}`===m.id);N&&ft(N);return}let g=Wr(a,h.x,h.y),T=g?o.cells[g.row][g.col].thing:null;if(!g||!T||!Yn(o,g))return;if(T.kind==="gen")Ft(g);else if(T.kind==="special")Ut(g);else {let N=E.find(P=>P.order.wants.some(Z=>Z.chain===T.chain&&Z.level===T.level)&&xn(o,P.order.wants));N&&ft(N);}}}}),e.on(Ht,()=>{pt(),e.vars.level=n.level;}),e.on(Gt,pt),e.on(Zt,ut),e.on(Qt,()=>{pe()&&(e.vars.reviving=false,et("out-of-energy"));}),e.on(Vt,l=>{J.clear(),Ee(),we=[],xe!==null&&e.isAlive(xe)&&ot(e,xe,l.reason==="cleared"?"dance":"idle");}),e.on(jt,()=>{a=Y(),Me();for(let l of E){let h=_e(l.slot),m=e.get(l.customer,Jn);m&&(m.to=h.x);let g=e.get(l.customer,G),T=Math.max(24,(h.feet-(h.y+h.h/2))*1.05);g&&e.set(l.customer,G,{x:h.x,y:h.feet-T/2});let N=e.get(l.customer,te);N?.shape==="actor"&&(N.h=T);}Ue();});let y=l=>{let h=Math.min(1,l*16);for(let[m,g]of c){if(x?.id===m)continue;let T=e.get(g,Uo);if(!T)continue;let N=e.need(g,G),P=nt(a,T.col,T.row);N.x+=(P.x-N.x)*h,N.y+=(P.y-N.y)*h;let Z=N.scale??1;N.scale=Z+(1-Z)*Math.min(1,l*10);}},S=l=>{let h=E.find(g=>xn(o,g.order.wants));if(h&&(!xt(l,"merge-order")||oe>6)){let g=_e(h.slot);return bt(l,"tap",{x:g.x,y:g.y},void 0,Le()*1.1)}let m=ud(o,{gens:false});if(m&&(!xt(l,"merge-merge")||oe>6))return bt(l,"swipe",nt(a,m[0].col,m[0].row),nt(a,m[1].col,m[1].row),Le()*1.1);if(K>=Te()&&!xt(l,"merge-skill")){let g=we.find(T=>T.id==="skill");if(g)return bt(l,"tap",g,void 0,Le()*1.1)}if(!xt(l,"merge-generate")||oe>6){let g=Lr(o).find(T=>T.thing.kind==="gen"&&!T.cell.cover);g&&(O>0||I>0)&&bt(l,"tap",nt(a,g.at.col,g.at.row),void 0,Le()*1.1);}},$=0;e.addSystem({id:"merge",order:0,run(l,h){st(l,h),y(h),!(!rt(l)||Ae)&&(ce+=h,oe+=h,wt(),++$%20===0&&o.cells.some(m=>m.some(g=>g.cover?.ttl!==void 0&&g.cover.ttl<=3))&&se(),!(pe()||x)&&(kr(l)||S(l),gt()||Ze()));}}),pt();}};var Nt=10,kd={id:"start",needs:[],rows:["..............","..............","..............","..............","..............","..............",".......o.o.o..",".P............","##############","##############"]},vd={id:"checkpoint",needs:[],rows:["..........","..........","..........","..........","..........","..........","...o..o...","....C.....","##########","##########"]},$d={id:"end",needs:[],rows:["..............","..............","..............","..............","..............","..............",".....o.o......","..........E...","##############","##############"]},Md={id:"boss",needs:[],rows:["..................","..................","..................","..................","...===......===...","..................","..................","..................","##################","##################"]},ii=[{id:"walk",needs:["walker"],rows:["..............","..............","..............","..............",".....ooo......","....o...o.....","..............",".........W....","##############","##############"]},{id:"two-walkers",needs:["walker"],rows:["..............","..............","..............","......*.......",".....===......","..............","..o........o..","...W......W...","##############","##############"]},{id:"gaps",needs:["gaps"],rows:["..............","..............","..............","..............","..............","....o.....o...","...o.o...o.o..","..............","###...###...##","###...###...##"]},{id:"stairs",needs:["stairs"],rows:["..............","...........*..","..........===.","..............",".......###....",".......###.o..","....##########","....##########","##############","##############"]},{id:"spikes",needs:["spikes"],rows:["..............","..............","..............","..............","..............",".....ooo......","....=====.....","..............","###^^^^^^^####","##############"]},{id:"pits",needs:["pits"],rows:["..............","..............","..............","..............","......o.......",".....===...o..","..o.......===.",".===..........","##..........##","##..........##"]},{id:"spring",needs:["spring"],rows:["..............",".........*....","........####..","..............","..............","..............","..............","...T..........","##############","##############"]},{id:"hopper",needs:["hopper"],rows:["..............","..............","..............","..............",".....o...o....","..............","..............",".......J......","##############","##############"]},{id:"crumble",needs:["crumble"],rows:["..............","..............","..............","..............","..............","...o.o.o.o....","...______.....","..............","##........####","##........####"]},{id:"spiky",needs:["spiky"],rows:["..............","..............","..............","..............","..............","......ooo.....","..............",".......S......","##############","##############"]},{id:"moving",needs:["moving"],rows:["..............","..............","..............","..............",".....o..o.....","..............",".....M........","..............","##..........##","##..........##"]},{id:"flyer",needs:["flyer"],rows:["..............","..............","..............","......F.......","..............","..............","...o......o...","..............","##############","##############"]},{id:"key",needs:["key"],rows:["..............","..............","..K...........",".===..........","..............",".......===....","..............","...........B..","##############","##############"]},{id:"gunner",needs:["gunner"],rows:["..............","..............","..............","..............","..............",".....o.o......","....=====.....","...........G..","##############","##############"]},{id:"heart",needs:["walker","stairs"],rows:["..............","..............","..*...........","..............","......H.......",".....===......","..............","...W......W...","##############","##############"]},{id:"secret-high",needs:["spring","gaps"],rows:["..............","..*...........",".===..........","..............","..............","..............","........T.....","..............","#####...######","#####...######"]}],ol=4,kn=5,ai=ol*kn,si={walker:1,gaps:1,spikes:2,stairs:2,pits:3,spring:3,hopper:4,crumble:4,spiky:6,moving:6,flyer:7,key:8,gunner:9},sl=[0,9,24,39];function to(e,t=.5){let r=Math.max(1,Math.min(ai,Math.floor(e))),s=Math.ceil(r/kn),n=r-(s-1)*kn,o=n===kn,a=Object.keys(si).filter(p=>si[p]<=r),c=Object.keys(si).find(p=>si[p]===r)??null;return {level:r,world:s,index:n,boss:o,features:a,fresh:c,rooms:o?2:3+Math.min(5,Math.floor((r-1)/2)),pace:.85+t*.3+(r-1)*.02,bossHp:3+s,firstClearGold:(o?150:60)+(r-1)*20}}var il=e=>sl[Math.ceil(Math.max(1,e)/kn)-1]??0,al=[{id:"double",stars:6},{id:"dash",stars:15},{id:"wall",stars:27}],li=e=>al.filter(t=>e>=t.stars).map(t=>t.id),ro=[{id:"hero",cast:"hero",gems:0,perk:"none"},{id:"hero2",cast:"hero2",gems:150,perk:"heart"},{id:"hero3",cast:"hero3",gems:300,perk:"jump"}],ll="kit-platformer",cl=[{id:"Hearts",var:"meta:hearts",art:"heart",color:"danger",perLevel:1,unit:"",maxLevel:3,price:150,growth:1.2},{id:"JumpPower",var:"meta:jump",art:"boot",color:"accent",perLevel:2,unit:"%",maxLevel:10,price:40,growth:.15},{id:"Magnet",var:"meta:magnet",art:"magnet",color:"danger",perLevel:10,unit:"%",maxLevel:10,price:30,growth:.12},{id:"Grace",var:"meta:grace",art:"shield",color:"muted",perLevel:.2,unit:"s",maxLevel:10,price:35,growth:.12},{id:"Greed",var:"meta:greed",art:"coin",color:"coin",perLevel:2,unit:"%",maxLevel:25,price:40,growth:.1}],Ed={game:"platformer",character:ll,stats:cl,heroes:ro,levels:ai,firstClearGold:e=>to(e).firstClearGold,stars:3,starsToEnter:il};var ih="boss-spawned",ah="boss-defeated",dl="level-cleared",er=$e("platformer.body"),ht=$e("platformer.thing"),Xo=$e("platformer.strip"),gr=$e("platformer.hero"),Sd=$e("platformer.hud"),sn=(e,t)=>{let r=Number(e.vars[t]??0);return Number.isFinite(r)?r:0},lh=6,vn=40,ch=3.3,dh=6.8,fh=.7,wd=1.3,ci={id:"platformer",version:2,engines:["phaser"],requires:["round"],params:{difficulty:{type:"number",default:.5,min:0,max:1},lives:{type:"number",default:3,min:1,max:9,integer:true},coinScore:{type:"number",default:10,min:0,max:1e3,integer:true},starScore:{type:"number",default:300,min:0,max:1e4,integer:true},clearBonus:{type:"number",default:500,min:0,max:1e5,integer:true},graceTime:{type:"number",default:1.2,min:0,max:5},doubleJump:{type:"boolean",default:false}},setup({world:e,params:t}){let r=y=>cr(t,y),s=Wn(e),n=to(1,r("difficulty")),o=[],a=0,c=null,p=0,x={x:2,y:8},E=3,L=3,O=0,C=false,I=false,K=0,ne=0,V=0,ce=false,oe=false,le=[],Ae=[false,false,false],xe=new Map,we=new Map,ge=()=>ro.find(y=>y.id===e.vars["meta:hero"])??ro[0],ke=()=>e.vars.reviving===true,pe=()=>{let y=Number(e.vars.view_w??720),S=Number(e.vars.view_h??1280);return Math.min(y/8,S*.66/10)},Te=()=>Number(e.vars.view_h??1280)*.86-10*pe(),Be=()=>Number(e.vars.view_w??720)/pe(),ze=(y,S)=>{if(S<0)return ".";if(y<0||y>=a)return "#";if(S>=10)return ".";let $=o[S]?.[y]??".";return $==="_"&&(xe.get(`${y},${S}`)??0)>.5?".":$},Y=y=>y==="#",Le=y=>y==="="||y==="_"||y==="^",J=()=>{for(let P of e.query(ht))e.destroy(P);for(let P of e.query(Xo))e.destroy(P);xe.clear(),n=to(sn(e,"meta:chapter")||1,r("difficulty"));let y=e.rng.stream(`platformer-level-${n.level}`),S=ii.filter(P=>P.needs.every(Z=>n.features.includes(Z))),$=[],l=n.fresh!==null?S.find(P=>P.needs.includes(n.fresh)):void 0;for(l&&$.push(l);$.length<n.rooms;)$.push(y.pick(S));let h=Math.ceil($.length/2),m=[kd,...$.slice(0,h),vd,...$.slice(h),n.boss?Md:$d];o=Array.from({length:10},(P,Z)=>m.map(ie=>ie.rows[Z]??"").join("")),a=o[0].length;let g=[];for(let P=0;P<10;P++)for(let Z=0;Z<a;Z++)o[P][Z]==="*"&&g.push({c:Z,r:P});let T=g.length<=3?g:[g[0],g[Math.floor(g.length/2)],g[g.length-1]];for(let P=T.length;P<3;P++)T.push({c:Math.floor(a*(P+1)/4),r:5});let N=0;for(let P=0;P<10;P++)for(let Z=0;Z<a;Z++){let ie=o[P][Z],re={x:Z+.5,y:P+1};ie==="P"?x={...re}:ie==="o"?ve("coin",re.x,P+.85,.5,.5):ie==="H"&&N++<1?ve("heart",re.x,P+.9,.6,.6):ie==="K"?ve("key",re.x,P+.9,.6,.6):ie==="B"?ve("chest",re.x,re.y,1,.8):ie==="T"?ve("spring",re.x,re.y,1,.5):ie==="M"?ve("mover",re.x+.5,P+.4,2,.4).baseX=re.x+.5:ie==="C"?ve("checkpoint",re.x,re.y,.6,1.6):ie==="E"?ve("flag",re.x,re.y,.8,2.6):ie==="W"?ve("walker",re.x,re.y,.8,1):ie==="S"?ve("spiky",re.x,re.y,.8,1):ie==="J"?ve("hopper",re.x,re.y,.8,1):ie==="F"?ve("flyer",re.x,re.y,.9,.8):ie==="G"&&ve("gunner",re.x,re.y,.8,1.1),/[PoHKBTMCEWSJFG*]/.test(ie)&&(o[P]=Se(o[P],Z,"."));}if(T.forEach((P,Z)=>ve("star",P.c+.5,P.r+.95,.85,.85).tag=String(Z)),n.boss){let P=ve("boss",a-5,8,2.2,2.4);P.hp=n.bossHp,P.tag="walk",P.t=2;}Pe();},Se=(y,S,$)=>y.slice(0,S)+$+y.slice(S+1),Ee=(y,S,$,l)=>{switch(y){case "walker":return {shape:"actor",cast:"foe",h:$*l*1.35,pose:"walk",depth:8};case "spiky":return {shape:"actor",cast:"foe2",h:$*l*1.4,pose:"walk",depth:8};case "hopper":return {shape:"actor",cast:"foe3",h:$*l*1.35,pose:"idle",depth:8};case "flyer":return {shape:"actor",cast:"foe5",h:$*l*1.4,pose:"air",depth:8};case "gunner":return {shape:"actor",cast:"foe4",h:$*l*1.3,pose:"idle",depth:8};case "boss":return {shape:"actor",cast:"boss",h:$*l*1.2,pose:"walk",depth:8};case "bullet":return {shape:"sprite",art:"shot",color:"danger",w:S*l,h:$*l,depth:9};case "wave":return {shape:"sprite",art:"burst",color:"danger",w:S*l,h:$*l,depth:9};case "coin":return {shape:"sprite",art:"coin",w:S*l,h:$*l,depth:7};case "star":return {shape:"sprite",art:"bigstar",w:S*l,h:$*l,depth:7};case "heart":return {shape:"sprite",art:"heart",w:S*l,h:$*l,depth:7};case "key":return {shape:"sprite",art:"key",w:S*l,h:$*l,depth:7};case "chest":return {shape:"sprite",art:"chest",w:S*l,h:$*l*1.1,depth:6};case "spring":return {shape:"sprite",art:"spring",w:S*l,h:$*l*1.4,depth:6};case "mover":return {shape:"tile",art:"platform",w:S*l,h:$*l,unit:l,depth:5};case "checkpoint":return {shape:"sprite",art:"flag",color:"muted",w:S*l*1.6,h:$*l,depth:5};case "flag":return {shape:"sprite",art:"flag",w:S*l*1.4,h:$*l,depth:5}}};function ve(y,S,$,l,h){let m=e.create(),g={kind:y,vx:0,vy:0,dir:-1,t:0,baseX:S,baseY:$,hp:1,tag:"",safe:0};return e.set(m,ht,g),e.set(m,er,{x:S,y:$,w:l,h}),e.set(m,G,{x:0,y:0}),e.set(m,te,Ee(y,l,h,pe())),e.need(m,ht)}function Pe(){for(let S of e.query(Xo))e.destroy(S);let y=(Number(e.vars.view_h??1280)-(Te()+10*pe()))/pe()+.5;for(let S=0;S<10;S++){let $=0;for(;$<a;){let l=o[S][$];if(l==="."||l==="_"){l==="_"&&Ue("_",$,S,1,.45),$++;continue}let h=l==="#"&&ze($,S-1)!=="#",m=$;for(;m<a&&o[S][m]===l&&(l!=="#"||ze(m,S-1)!=="#"===h);)m++;if(l==="#"&&h){let g=0;for(;S+g<10&&o[S+g][$]==="#";)g++;Ue("#",$,S,m-$,g+(S+g>=10?y:0));}else l!=="#"&&Ue(l,$,S,m-$,l==="="?.45:.7);$=m;}}}function Ue(y,S,$,l,h){let m=pe(),g=e.create();e.set(g,Xo,{char:y}),e.set(g,er,{x:S+l/2,y:y==="^"?$+1:$+h,w:l,h}),e.set(g,G,{x:0,y:0});let T=y==="^"?{shape:"tile",art:"spike",w:l*m,h:h*m,unit:m,depth:4}:y==="#"?{shape:"tile",art:"ground",w:l*m,h:h*m,unit:m*1.2,depth:3}:{shape:"tile",art:"platform",w:l*m,h:h*m,unit:m,depth:3,...y==="_"?{color:"muted",alpha:.85}:{}};e.set(g,te,T),y==="_"&&e.set(g,ht,{kind:"mover",vx:0,vy:0,dir:0,t:0,baseX:S,baseY:$,hp:0,tag:"crumble",safe:0});}let se=()=>{(c===null||!e.isAlive(c))&&(c=e.create(),e.set(c,gr,{vx:0,vy:0,grounded:true,facing:1,jumps:0,coyote:0,buffer:0,dash:0,dashCd:0,wall:0,swing:0,swingCd:0}),e.set(c,er,{x:x.x,y:x.y,w:fh,h:wd}),e.set(c,G,{x:0,y:0})),e.set(c,te,{shape:"actor",cast:ge().cast,h:wd*pe()*1.25,pose:"idle",depth:10});},Me=()=>Math.sqrt(2*vn*ch*(1+sn(e,"meta:jump"))*(ge().perk==="jump"?1.15:1)),lt=()=>{if(c===null)return;let y=e.need(c,er),S=e.need(c,gr);y.x=x.x,y.y=x.y,S.vx=0,S.vy=0;for(let $ of e.query(ht))(e.need($,ht).kind==="bullet"||e.need($,ht).kind==="wave")&&e.destroy($);},_e=()=>{Ft(),J(),L=r("lives")+sn(e,"meta:hearts")+(ge().perk==="heart"?1:0),E=L,O=0,C=false,I=false,K=0,ne=0,V=0,ce=false,oe=!n.boss,Ae.fill(false),le=li(sn(e,"meta:stars_total")),r("doubleJump")&&!le.includes("double")&&le.push("double"),e.vars.abilities=le.join(","),e.vars.platformer_level=n.level,e.vars.platformer_world=n.world,e.vars.lives=E,e.vars.coins=0,e.vars.score=0,e.vars.stars=0,e.vars.reviving=false,p=0,se(),lt(),c!==null&&(e.need(c,gr).facing=1,ot(e,c,"idle")),n.boss&&e.emit(ih,{}),ut(e);},ct=()=>{!rt(e)||ke()||c===null||(e.need(c,gr).buffer=.13);},dt=()=>{if(c===null)return;let y=e.need(c,gr);y.vy<0&&(y.vy*=.5);},st=()=>{if(!rt(e)||ke()||c===null||!le.includes("dash"))return;let y=e.need(c,gr);y.dashCd>0||(y.dash=.2,y.dashCd=.8,y.vy=0,Ge(e,c,"attack"));},Ye=()=>{if(!rt(e)||ke()||c===null)return;let y=e.need(c,gr);y.swingCd>0||(y.swing=.16,y.swingCd=.32,Ge(e,c,"attack"));};e.on(Tt,y=>{let S=y;e.vars.started_tick!==e.tick&&(S.type==="key"&&(S.key==="up"||S.key==="action")?ct():S.type==="key-up"&&(S.key==="up"||S.key==="action")?dt():S.type==="key"&&S.key==="down"?st():S.type==="tap"?Ye():S.type==="swipe"&&S.dir==="up"&&ct());});let ft=(y,S)=>{if(!rt(y)||C)return;C=true;let $=S==="cleared",l=Ae.filter(Boolean).length;y.vars.stars=l,$&&y.vars["meta:first_clear"]===true&&Ke(y,"coins",n.firstClearGold),y.vars.score=V*r("coinScore")+l*r("starScore")+($?r("clearBonus"):0),y.vars.reviving=false,$&&y.emit(dl,{level:n.level}),y.emit(Bt,{reason:S,stats:{chapter:n.level,seconds:Math.floor(K),cleared:$,stars:$?l:0,coins:V,bosses:n.boss&&oe?1:0}});},qe=y=>{if(y.vars.revive_ready===true&&!I){y.vars.reviving=true,y.emit(Kt,{});return}ft(y,"fell");},wt=y=>{ke()&&(I=true,y.vars.reviving=false,E=Math.max(2,Math.ceil(L/2)),y.vars.lives=E,O=2.5,lt(),c!==null&&ot(y,c,"idle"),H(y,{kind:"flash",color:"coin"}));},Je=(y,S)=>{if(c===null||O>0||C)return;let $=y.need(c,gr);$.dash>0||(E--,y.vars.lives=E,y.emit("player-hit",{lives:E}),O=r("graceTime")+sn(y,"meta:grace"),$.vy=-Me()*.55,$.vx=(S===null?-$.facing:Math.sign(y.need(c,er).x-S)||-$.facing)*5,Ge(y,c,"hit"),H(y,{kind:"shake",power:1.2}),H(y,{kind:"flash",color:"danger"}),E<=0&&qe(y));},pt=(y,S,$)=>{let l=y.need(S,ht),h=y.need(S,er),m=pe();H(y,{kind:"burst",x:et(h.x),y:Ze(h.y-h.h/2),color:"danger",n:12,size:m*.9}),y.emit("enemy-defeated",{kind:l.kind,by:$}),Ke(y,"score",50),y.destroy(S);},yt=(y,S)=>{let $=y.need(S,er);ne+=1+sn(y,"meta:greed");let l=Math.floor(ne);ne-=l,l>0&&Ke(y,"coins",l),V++,y.emit("coin-collected",{value:1}),H(y,{kind:"burst",x:et($.x),y:Ze($.y-$.h/2),color:"coin",n:6,size:pe()*.6}),y.destroy(S);},et=y=>y*pe()-p*pe(),Ze=y=>Te()+y*pe();function ut(y){pe();for(let $ of y.query(er)){let l=y.need($,er),h=y.get($,G);if(!h)continue;h.x=et(l.x),h.y=Ze(l.y-l.h/2);let m=y.get($,te);if(m&&m.shape==="actor"&&y.has($,ht)){let g=y.need($,ht);m.facing=g.dir>=0?1:-1,m.alpha=g.safe>0&&Math.floor(y.time*12)%2===0?.35:1,h.y=Ze(l.y)-m.h/2;}if(m&&m.shape==="actor"&&y.has($,gr)&&(h.y=Ze(l.y)-m.h/2),m&&y.has($,Xo)&&y.need($,Xo).char==="_"){let g=xe.get(`${Math.floor(l.x)},${Math.round(l.y-l.h)}`)??0;m.alpha=g>.5?0:g>0?.5+.5*Math.abs(Math.sin(y.time*30)):.85;}}}let gt=(y,S,$,l)=>{let h=we.get(y);(h===void 0||!e.isAlive(h))&&(h=e.create(),e.set(h,Sd,{id:y}),we.set(y,h)),e.set(h,G,{x:S,y:$}),e.set(h,te,l);},Wt=y=>{let S=we.get(y);S!==void 0&&e.destroy(S),we.delete(y);};function Ft(){for(let y of we.values())e.destroy(y);we.clear(),at(e,Sd);}let Ut=y=>{let S=Number(y.vars.view_w??720),$=Number(y.vars.view_h??1280),l=Math.min(S,$),h=$*.085;gt("lvl",S*.08,h,{shape:"text",text:`${n.world}-${n.index}`,size:Math.round(l*.042),color:"text",bold:true,depth:42});let m=l*.05;for(let P=0;P<L;P++)gt(`h${P}`,S*.07+P*m*1.1,h+l*.065,{shape:"sprite",art:"heart",w:m,h:m,alpha:P<E?1:.25,depth:42});for(let P=L;P<12;P++)Wt(`h${P}`);let g=l*.06;for(let P=0;P<3;P++)gt(`s${P}`,S/2+(P-1)*g*1.15,h,{shape:"sprite",art:"bigstar",w:g,h:g,alpha:Ae[P]?1:.25,depth:42});let T=l*.045,N=String(y.vars.coins??0);if(gt("coin:i",S*.92-N.length*T*.6-T*.7,h,{shape:"sprite",art:"coin",w:T,h:T,depth:42}),gt("coin",S*.92-N.length*T*.6/2,h,{shape:"text",text:N,size:Math.round(T),color:"text",bold:true,depth:42}),ce?gt("key",S*.92-T*.3,h+l*.065,{shape:"sprite",art:"key",w:T,h:T,depth:42}):Wt("key"),n.boss){let P=y.query(ht).find(Ce=>y.need(Ce,ht).kind==="boss"),Z=P!==void 0?y.need(P,ht).hp/n.bossHp:0,ie=S*.5,re=Math.max(10,l*.022);gt("boss:bg",S/2,h+l*.075,{shape:"rect",w:ie,h:re,color:"#000000",alpha:.45,radius:re/2,depth:41});let Ie=Math.max(0,(ie-4)*Math.round(Z*100)/100);Ie<1?Wt("boss:fill"):gt("boss:fill",S/2-(ie-4)/2+Ie/2,h+l*.075,{shape:"rect",w:Ie,h:re-4,color:"danger",radius:(re-4)/2,depth:41.1});}};e.on(Ht,()=>{_e(),e.vars.level=n.level;}),e.on(Gt,_e),e.on(Zt,()=>wt(e)),e.on(Qt,()=>{ke()&&(e.vars.reviving=false,ft(e,"fell"));}),e.on(Vt,y=>{c!==null&&e.isAlive(c)&&ot(e,c,y.reason==="cleared"?"dance":"die"),Ft();}),e.on(jt,()=>{Ot(e,"side",Te()+8*pe()+2);let y=pe();for(let S of e.query(ht)){let $=e.need(S,ht);if($.tag==="crumble")continue;let l=e.need(S,er);e.set(S,te,Ee($.kind,l.w,l.h,y));}Pe(),se(),ut(e);}),e.addSystem({id:"platformer",order:0,run(y,S){if(!rt(y)||c===null||C||ke())return;K+=S,O>0&&(O=Math.max(0,O-S));let $=y.need(c,er),l=y.need(c,gr),h=n.pace;for(let[Q,i]of [...xe]){let f=i+S;f>3.5?xe.delete(Q):xe.set(Q,f);}let m=s.axis().x;if(m!==0&&(l.facing=m),l.dash>0)l.dash-=S,l.vx=l.facing*15,l.vy=0;else {let Q=m*lh,i=l.grounded?60:32;l.vx+=Math.max(-i*S,Math.min(i*S,Q-l.vx)),l.vy+=vn*S,l.vy>22&&(l.vy=22);}if(l.dashCd>0&&(l.dashCd-=S),l.swingCd>0&&(l.swingCd-=S),l.swing>0){l.swing-=S;let Q={l:l.facing>0?$.x:$.x-1.4,r:l.facing>0?$.x+1.4:$.x,t:$.y-$.h-.2,b:$.y};for(let i of y.query(ht)){if(!y.isAlive(i)||!y.has(i,ht))continue;let f=y.need(i,ht);if(!["walker","spiky","hopper","flyer","gunner","boss","bullet"].includes(f.kind))continue;let k=y.need(i,er);k.x+k.w/2<Q.l||k.x-k.w/2>Q.r||k.y-k.h>Q.b||k.y<Q.t||(f.kind==="bullet"?(H(y,{kind:"burst",x:et(k.x),y:Ze(k.y-k.h/2),color:"text",n:6,size:pe()*.5}),y.destroy(i)):f.kind==="boss"?R(y,i,"sword"):pt(y,i,"sword"));}}if(l.coyote=l.grounded?.1:Math.max(0,l.coyote-S),l.buffer>0){l.buffer-=S;let Q=le.includes("double")&&l.jumps<2;l.coyote>0||l.grounded?(l.vy=-Me(),l.jumps=1,l.buffer=0,l.grounded=false,l.coyote=0):l.wall!==0&&le.includes("wall")?(l.vy=-Me()*.95,l.vx=-l.wall*7,l.facing=-l.wall,l.jumps=1,l.buffer=0):Q&&l.jumps>=1&&(l.vy=-Me()*.9,l.jumps=2,l.buffer=0,H(y,{kind:"ring",x:et($.x),y:Ze($.y),color:"text",size:pe()*1.2})),l.buffer===0&&Ge(y,c,"jump");}let g=$.w/2,T=$.x+l.vx*S;l.wall=0;let N=Q=>{let i=[];for(let f=Math.floor(Q-$.h+.05);f<=Math.floor(Q-.05);f++)i.push(f);return i};if(l.vx>0){let Q=Math.floor(T+g);N($.y).some(i=>Y(ze(Q,i)))&&(T=Q-g-.001,l.grounded||(l.wall=1),l.vx=0);}else if(l.vx<0){let Q=Math.floor(T-g);N($.y).some(i=>Y(ze(Q,i)))&&(T=Q+1+g+.001,l.grounded||(l.wall=-1),l.vx=0);}l.wall===0&&!l.grounded&&m!==0&&N($.y).some(Q=>Y(ze(Math.floor(T+m*(g+.05)),Q)))&&(l.wall=m),$.x=Math.max(g,Math.min(a-g,T));let P=$.y,Z=$.y+l.vy*S,ie=l.grounded;l.grounded=false;let re=[Math.floor($.x-g+.05),Math.floor($.x+g-.05)];if(l.vy>=0){let Q=Math.floor(Z);for(let i of re){let f=ze(i,Q),k=Q;if((Y(f)||Le(f)&&P<=k+.05)&&Z>=k){Z=k,l.vy=0,l.grounded=true,l.jumps=0,f==="_"&&!xe.has(`${i},${Q}`)&&xe.set(`${i},${Q}`,.001),f==="^"&&(Je(y,null),l.vy=-Me()*.7,l.grounded=false);break}}}else {let Q=Math.floor(Z-$.h);re.some(i=>Y(ze(i,Q)))&&(Z=Q+1+$.h,l.vy=0);}$.y=Z,!ie&&l.grounded&&Ge(y,c,"jump");for(let Q of y.query(ht)){let i=y.need(Q,ht);if(i.kind!=="mover"||i.tag==="crumble")continue;let f=y.need(Q,er),k=f.x;i.t+=S,f.x=i.baseX+Math.sin(i.t*.9)*2.2;let d=f.y-f.h;l.vy>=0&&Math.abs($.x-f.x)<f.w/2+g*.6&&P<=d+.1&&$.y>=d-.05&&($.y=d,l.vy=0,l.grounded=true,l.jumps=0,$.x+=f.x-k);}if($.y>12&&(Je(y,null),O=Math.max(O,1),!ke()&&!C&<(),C||ke()))return;let Ie={l:$.x-g,r:$.x+g,t:$.y-$.h,b:$.y},Ce=Q=>Ie.r>Q.x-Q.w/2&&Ie.l<Q.x+Q.w/2&&Ie.b>Q.y-Q.h&&Ie.t<Q.y,De=1.2*(1+sn(y,"meta:magnet")),F=$.x;for(let Q of y.query(ht)){if(!y.isAlive(Q)||!y.has(Q,ht))continue;let i=y.need(Q,ht),f=y.need(Q,er);switch(i.safe>0&&(i.safe-=S),i.kind){case "walker":case "spiky":{i.vx=i.dir*1.6*h;let k=f.x+i.dir*(f.w/2+.05)+i.vx*S,d=Y(ze(Math.floor(k),Math.floor(f.y-.5))),u=ze(Math.floor(k),Math.floor(f.y));d||!(Y(u)||Le(u))?i.dir=-i.dir:f.x+=i.vx*S;break}case "hopper":{i.t+=S,i.vy+=vn*.6*S,f.y+=i.vy*S,f.y>=i.baseY&&(f.y=i.baseY,i.vy=0,i.t>1.5/h&&(i.t=0,i.vy=-Math.sqrt(2*vn*.6*2.4))),i.dir=F<f.x?-1:1;break}case "flyer":i.t+=S*h,f.x=i.baseX+Math.sin(i.t*.9)*3,f.y=i.baseY+Math.sin(i.t*1.8)*.9,i.dir=Math.cos(i.t*.9)>=0?1:-1;break;case "gunner":{if(i.dir=F<f.x?-1:1,i.t+=S,i.t>2.2/h&&Math.abs(F-f.x)<9){i.t=0;let k=ve("bullet",f.x+i.dir*.6,f.y-.45,.45,.3);k.vx=i.dir*6*h,k.dir=i.dir,Ge(y,Q,"attack");}break}case "bullet":case "wave":if(f.x+=i.vx*S,i.t+=S,i.t>(i.kind==="wave"?2.2:3.5)||Y(ze(Math.floor(f.x),Math.floor(f.y-.1)))){y.destroy(Q);continue}break;case "boss":z(y,Q,i,f,F,S);break;case "coin":Math.hypot(f.x-$.x,f.y-($.y-$.h/2))<De&&De>1.21&&(f.x+=($.x-f.x)*Math.min(1,S*10),f.y+=($.y-$.h/2-f.y)*Math.min(1,S*10));break;}if(!(!y.isAlive(Q)||!Ce(f))){switch(i.kind){case "coin":yt(y,Q);break;case "star":{let k=Number(i.tag);Ae[k]=true,y.vars.stars=Ae.filter(Boolean).length,y.emit("star-collected",{index:k}),H(y,{kind:"ring",x:et(f.x),y:Ze(f.y-f.h/2),color:"coin",size:pe()*2.4}),H(y,{kind:"flash",color:"coin"}),y.destroy(Q);break}case "heart":E=Math.min(L,E+1),y.vars.lives=E,H(y,{kind:"ring",x:et(f.x),y:Ze(f.y-f.h/2),color:"danger",size:pe()*1.6}),y.destroy(Q);break;case "key":ce=true,H(y,{kind:"ring",x:et(f.x),y:Ze(f.y-f.h/2),color:"coin",size:pe()*1.6}),y.destroy(Q);break;case "chest":if(ce&&i.tag!=="open"){i.tag="open",ce=false;for(let d=0;d<15;d++)ne+=1+sn(y,"meta:greed"),V++;let k=Math.floor(ne);ne-=k,Ke(y,"coins",k),H(y,{kind:"burst",x:et(f.x),y:Ze(f.y-f.h/2),color:"coin",n:24,size:pe()*1.4}),H(y,{kind:"pop",x:et(f.x),y:Ze(f.y-f.h*1.4),text:"+15",color:"coin",size:Math.round(pe()*.5)});}break;case "spring":l.vy>0&&$.y-(f.y-f.h)<.5&&(l.vy=-Math.sqrt(2*vn*dh),l.jumps=1,H(y,{kind:"ring",x:et(f.x),y:Ze(f.y-f.h),color:"accent",size:pe()*1.4}));break;case "checkpoint":if(i.tag!=="on"){i.tag="on",x={x:f.x,y:f.y};let k=y.need(Q,te);k.shape==="sprite"&&(k.color="accent"),y.emit("checkpoint",{}),H(y,{kind:"ring",x:et(f.x),y:Ze(f.y-f.h/2),color:"accent",size:pe()*2});}break;case "flag":if(oe){ft(y,"cleared");return}break;case "walker":case "hopper":case "flyer":case "gunner":case "spiky":case "boss":{let k=l.vy>0&&$.y-(f.y-f.h)<.55&&i.kind!=="spiky";l.dash>0&&i.kind!=="boss"?pt(y,Q,"dash"):k?(l.vy=-Me()*.65,l.jumps=1,i.kind==="boss"?R(y,Q,"stomp"):pt(y,Q,"stomp")):Je(y,f.x);break}case "bullet":case "wave":Je(y,f.x),y.destroy(Q);break;}if(C||ke())return}}let ae=Be(),Oe=Math.max(0,Math.min(Math.max(0,a-ae),$.x-ae*.4+l.facing*ae*.08)),me=p;p+=(Oe-p)*Math.min(1,S*6),Co(y,(p-me)*pe()),y.vars.level_progress=Math.min(1,$.x/Math.max(1,a));let ue=y.need(c,te);ue.shape==="actor"&&(ue.facing=l.facing>=0?1:-1,ue.pose=l.grounded?Math.abs(l.vx)>.5?"run":"idle":"air",ue.speed=Math.abs(l.vx)*pe(),ue.alpha=O>0&&Math.floor(y.time*12)%2===0?.35:1),ut(y),Ut(y);}});function R(y,S,$){let l=y.need(S,ht);l.safe>0||(l.hp--,l.safe=1,Ge(y,S,"hit"),H(y,{kind:"shake",power:1}),l.hp<=0&&(oe=true,y.emit(ah,{}),pt(y,S,$),ve("flag",a-2,8,.8,2.6)));}function z(y,S,$,l,h,m){if($.t-=m,$.vy+=vn*m,l.y=Math.min($.baseY,l.y+$.vy*m),l.y>=$.baseY){if($.tag==="slam-air"){$.tag="walk",$.t=1.6,H(y,{kind:"shake",power:1.4});for(let g of [-1,1]){let T=ve("wave",l.x+g*1.2,$.baseY,.9,.6);T.vx=g*8*n.pace;}}$.vy=0;}if($.tag==="walk"){if($.dir=h<l.x?-1:1,l.x+=$.dir*1.4*n.pace*m,$.t<=0){let g=Math.floor(y.rng.next()*3);if(g===0)$.tag="charge",$.t=1.1,$.vx=$.dir*9*n.pace,ot(y,S,"run");else if(g===1)$.tag="slam-air",$.vy=-Math.sqrt(2*vn*4),Ge(y,S,"jump");else {$.tag="walk",$.t=2.4;for(let T of [a-15,a-3])ve("walker",T,$.baseY,.8,1).dir=T<l.x?1:-1;Ge(y,S,"cheer");}}}else $.tag==="charge"&&(l.x+=$.vx*m,($.t<=0||Y(ze(Math.floor(l.x+Math.sign($.vx)*1.2),Math.floor($.baseY-1))))&&($.tag="walk",$.t=1.8,ot(y,S,"walk")));l.x=Math.max(a-17.5,Math.min(a-1.2,l.x));}Ot(e,"side",Te()+8*pe()+2),_e();}};var ir=5,di=6,fi=6,_r={blaster:{id:"blaster",art:"shot",color:"coin",damage:[10,13,15,18,24],cooldown:[.8,.7,.62,.55,.42],count:[1,1,2,2,3],pierce:[1,1,1,2,3]},blades:{id:"blades",art:"blade",color:"primary",damage:[8,10,12,14,19],cooldown:[.45,.42,.4,.38,.32],count:[2,2,3,3,5],reach:[.15,.16,.17,.18,.21]},aura:{id:"aura",art:"aura",color:"secondary",damage:[5,7,9,11,16],cooldown:[.5,.5,.45,.45,.4],count:[1,1,1,1,1],reach:[.11,.125,.14,.155,.19]},boomerang:{id:"boomerang",art:"boomerang",color:"accent",damage:[16,20,24,28,38],cooldown:[1.8,1.6,1.4,1.25,1],count:[1,1,2,2,3],reach:[.34,.36,.38,.4,.46]},lightning:{id:"lightning",art:"lightning",color:"primary",damage:[18,22,26,30,42],cooldown:[2,1.8,1.6,1.4,1.1],count:[2,3,4,5,7],reach:[.22,.23,.24,.25,.3]},drone:{id:"drone",art:"drone",color:"piece6",damage:[9,11,13,15,21],cooldown:[1,.9,.8,.7,.55],count:[1,1,2,2,3],reach:[.11,.11,.12,.12,.13]}},no=Object.keys(_r),oo={might:{id:"might",art:"fist",color:"danger",step:.12},haste:{id:"haste",art:"hourglass",color:"primary",step:.07},area:{id:"area",art:"aura",color:"secondary",step:.1},swift:{id:"swift",art:"boot",color:"accent",step:.08},vigor:{id:"vigor",art:"heart",color:"danger",step:20},armor:{id:"armor",art:"shield",color:"muted",step:1.5},magnet:{id:"magnet",art:"magnet",color:"danger",step:.3},luck:{id:"luck",art:"clover",color:"accent",step:.2},growth:{id:"growth",art:"crystal",color:"accent",step:.1}},pi=Object.keys(oo),$n={swarm:{kind:"swarm",cast:"foe5",hp:.6,speed:118,size:.045,damage:5,xp:1,from:0,weight:3},grunt:{kind:"grunt",cast:"foe",hp:1,speed:95,size:.055,damage:8,xp:1,from:0,weight:4},archer:{kind:"archer",cast:"foe3",hp:1.2,speed:88,size:.055,damage:7,xp:2,from:.8,weight:2},brute:{kind:"brute",cast:"foe2",hp:5,speed:62,size:.085,damage:14,xp:5,from:1.6,weight:1.2},charger:{kind:"charger",cast:"foe4",hp:2.5,speed:80,size:.065,damage:12,xp:3,from:2.4,weight:1.4},bomber:{kind:"bomber",cast:"foe5",hp:1.5,speed:120,size:.055,damage:16,xp:2,from:3.2,weight:1.4},miniboss:{kind:"miniboss",cast:"boss",hp:45,speed:75,size:.12,damage:18,xp:25,from:99,weight:0},boss:{kind:"boss",cast:"boss",hp:160,speed:70,size:.16,damage:24,xp:0,from:99,weight:0}},Ld=["swarm","grunt","archer","brute","charger","bomber"],hi=10;function so(e,t){let r=Math.max(1,Math.min(hi,Math.floor(e)));return {chapter:r,duration:Math.min(600,t+(r-1)*30),hp:1+(r-1)*.45,damage:1+(r-1)*.12,headStart:(r-1)*.4,firstClearGold:100+(r-1)*60}}var io=[{id:"hero",cast:"hero",weapon:"blaster",passive:null,gems:0},{id:"hero2",cast:"hero2",weapon:"blades",passive:"vigor",gems:150},{id:"hero3",cast:"hero3",weapon:"lightning",passive:"area",gems:300}],fl=[{id:"Might",var:"meta:might",art:"fist",color:"danger",perLevel:4,unit:"%",maxLevel:50,price:30,growth:.09},{id:"Vitality",var:"meta:hp",art:"heart",color:"danger",perLevel:8,unit:"",maxLevel:50,price:25,growth:.09},{id:"Armor",var:"meta:armor",art:"shield",color:"muted",perLevel:.5,unit:"",maxLevel:30,price:40,growth:.1},{id:"Swiftness",var:"meta:speed",art:"boot",color:"accent",perLevel:2,unit:"%",maxLevel:25,price:35,growth:.1},{id:"Magnet",var:"meta:magnet",art:"magnet",color:"danger",perLevel:6,unit:"%",maxLevel:25,price:20,growth:.1},{id:"Luck",var:"meta:luck",art:"clover",color:"accent",perLevel:5,unit:"%",maxLevel:25,price:30,growth:.1},{id:"Growth",var:"meta:growth",art:"crystal",color:"accent",perLevel:3,unit:"%",maxLevel:30,price:30,growth:.1},{id:"Recovery",var:"meta:regen",art:"potion",color:"accent",perLevel:.1,unit:"",maxLevel:30,price:45,growth:.1}],pl="kit-survivors",_d=30,Rd=10,Ad={game:"survivors",character:pl,stats:fl,heroes:io,levels:hi,firstClearGold:e=>so(e,300).firstClearGold,stars:0};var mi=$e("survivors.hero"),je=$e("survivors.foe"),Sn=$e("survivors.shot"),Xr=$e("survivors.bullet"),tr=$e("survivors.drop"),an=$e("survivors.blade"),Mn=$e("survivors.aura"),En=$e("survivors.drone"),qo=$e("survivors.boomerang"),Ko=$e("survivors.zap"),ao=$e("survivors.halo"),Dd=$e("survivors.hud"),ln=$e("survivors.joystick"),hl="level-up",ul="upgrade-picked",ml="upgrade-pick",yl="upgrade-reroll";var yi="boss-spawned",gl="boss-defeated",bl=e=>[...Object.entries(e.weapons).map(([t,r])=>`w:${t}:${r}`),...Object.entries(e.passives).map(([t,r])=>`p:${t}:${r}`)].join(","),Td=e=>{let t={},r={};for(let s of String(e??"").split(",")){let[n,o,a]=s.split(":");n==="w"&&o&&o in _r?t[o]=Number(a):n==="p"&&o&&o in oo&&(r[o]=Number(a));}return {weapons:t,passives:r}},xl=e=>e.map(t=>`${t.kind}:${t.id}:${t.level}`).join(","),Od=e=>String(e??"").split(",").filter(Boolean).map(t=>{let[r,s,n]=t.split(":");return {kind:r,id:s??"",level:Number(n??1)}}),ui=e=>e.vars.reviving===true,Ur=(e,t)=>{let r=Number(e.vars[t]??0);return Number.isFinite(r)?r:0},gi={id:"survivors",version:2,engines:["phaser"],requires:["round"],params:{duration:{type:"number",default:300,min:20,max:900},heroSpeed:{type:"number",default:260,min:80,max:800},hp:{type:"number",default:100,min:10,max:2e3},spawnRate:{type:"number",default:1.2,min:.1,max:10},spawnGrowth:{type:"number",default:.9,min:0,max:10},foeHp:{type:"number",default:10,min:1,max:1e3},foeHpGrowth:{type:"number",default:.45,min:0,max:5},foeDamage:{type:"number",default:1,min:.1,max:10},foeSpeed:{type:"number",default:1,min:.3,max:3},damage:{type:"number",default:1,min:.1,max:100},shotSpeed:{type:"number",default:640,min:100,max:2e3},xpFirst:{type:"number",default:4,min:1,max:100,integer:true},xpGrowth:{type:"number",default:1.25,min:1,max:2},coinRate:{type:"number",default:.25,min:0,max:1},killScore:{type:"number",default:10,min:0,max:1e3,integer:true},bossScore:{type:"number",default:500,min:0,max:1e5,integer:true},clearBonus:{type:"number",default:1e3,min:0,max:1e5,integer:true},graceTime:{type:"number",default:.6,min:0,max:5},maxFoes:{type:"number",default:46,min:5,max:160,integer:true},minibossEvery:{type:"number",default:120,min:0,max:900},eliteEvery:{type:"number",default:50,min:0,max:900}},setup({world:e,params:t}){let r=e.rng.stream("survivors"),s=Wn(e),n=i=>cr(t,i),o=null,a=null,c=0,p={},x={},E={},L=0,O=0,C=0,I=1,K=0,ne=0,V=[],ce="level",oe=0,le=0,Ae=0,xe=false,we=0,ge=0,ke=300,pe=so(1,300),Te=false,Be=null,ze=0,Y=0,Le=0,J=0,Se=null,Ee=0,ve=0,Pe=false,Ue=new Map,se={maxHp:100,hp:100,regen:0,armor:0,speed:260,magnet:80,might:1,haste:1,area:1,luck:1,growth:1},Me=()=>Math.min(Ne(e).w,Ne(e).h),lt=()=>Me()/720,_e=()=>Me()*.07,ct=()=>{let i=Ne(e);return {x:i.w/2,y:i.h/2}},dt=()=>{let i=k=>x[k]??0,f=se.maxHp;se.might=(1+Ur(e,"meta:might")+.12*i("might"))*n("damage"),se.haste=Math.max(.4,1-.07*i("haste")),se.area=1+.1*i("area"),se.speed=n("heroSpeed")*lt()*(1+Ur(e,"meta:speed")+.08*i("swift")),se.maxHp=n("hp")+Ur(e,"meta:hp")+20*i("vigor"),se.regen=Ur(e,"meta:regen")+.3*i("vigor"),se.armor=Ur(e,"meta:armor")+1.5*i("armor"),se.magnet=Me()*.12*(1+Ur(e,"meta:magnet")+.3*i("magnet")),se.luck=1+Ur(e,"meta:luck")+.2*i("luck"),se.growth=1+Ur(e,"meta:growth")+.1*i("growth"),se.maxHp>f&&(se.hp+=se.maxHp-f),se.hp=Math.min(se.hp,se.maxHp),e.vars.survivors_build=bl({weapons:p,passives:x});},st=i=>Math.ceil(n("xpFirst")*Math.pow(i,n("xpGrowth"))),Ye=()=>io.find(i=>i.id===e.vars["meta:hero"])??io[0],ft=()=>{let i=ct(),f=_e();(o===null||!e.isAlive(o))&&(o=e.create(),e.set(o,mi,{size:f})),e.need(o,mi).size=f,e.set(o,G,{x:i.x,y:i.y}),e.set(o,te,{shape:"actor",cast:Ye().cast,h:f*2.3,feet:f*.6,pose:"idle",depth:qt(e,i.y)});},qe=(i,f,k,d)=>{let u=Ue.get(i);(u===void 0||!e.isAlive(u))&&(u=e.create(),e.set(u,Dd,{id:i}),Ue.set(i,u)),e.set(u,G,{x:f,y:k}),e.set(u,te,d);},wt=i=>{let f=Ue.get(i);f!==void 0&&e.destroy(f),Ue.delete(i);},Je=()=>{for(let i of Ue.values())e.destroy(i);Ue.clear(),at(e,Dd);},pt=(i,f,k,d,u,w,M,v=41)=>{let b=Math.max(0,Math.min(1,Math.round(w*100)/100));qe(`${i}:bg`,f,k,{shape:"rect",w:d,h:u,color:"#000000",alpha:.45,radius:u/2,depth:v});let _=Math.max(0,(d-4)*b);_<1?wt(`${i}:fill`):qe(`${i}:fill`,f-(d-4)/2+_/2,k,{shape:"rect",w:_,h:u-4,color:M,radius:(u-4)/2,depth:v+.01});},yt=i=>{let f=Ne(i),k=Me(),d=f.h*.085,u=f.w*.9,w=Math.max(10,k*.026);pt("xp",f.w/2,d,u,w,C/st(I),"accent"),qe("lv",f.w/2+u/2-k*.04,d+w*1.6,{shape:"text",text:`Lv ${I}`,size:Math.round(k*.032),color:"text",bold:true,depth:42});let M=d+k*.075;if(Be!==null&&i.isAlive(Be)&&i.has(Be,je)){let B=i.need(Be,je);pt("boss",f.w/2,M,f.w*.62,Math.max(14,k*.034),B.hp/B.maxHp,"danger"),qe("time",f.w/2,M-k*.05,{shape:"text",text:B.kind==="boss"?"BOSS":"MINI BOSS",size:Math.round(k*.036),color:"danger",bold:true,depth:42}),i.vars.boss_hp=B.hp/B.maxHp;}else wt("boss:bg"),wt("boss:fill"),qe("time",f.w/2,M,{shape:"text",text:ws(Number(i.vars.time_left??0)),size:Math.round(k*.05),color:"text",bold:true,depth:42}),i.vars.boss_hp=0;let v=Math.round(k*.036);qe("kills:i",f.w*.06,M,{shape:"sprite",art:"skull",w:v*1.1,h:v*1.1,color:"text",depth:42}),qe("kills",f.w*.06+v*.75+String(le).length*v*.28,M,{shape:"text",text:String(le),size:v,color:"text",bold:true,depth:42});let b=k*.05,_=0,A=new Set,D=(B,de,he,be,ye,Ve)=>{A.add(B),qe(`b:${B}`,ye,Ve,{shape:"sprite",art:de,w:b,h:b,color:he,alpha:.95,depth:41}),qe(`b:${B}:l`,ye+b*.38,Ve+b*.36,{shape:"text",text:be>=5?"\u2605":String(be),size:Math.round(b*.42),color:be>=5?"coin":"text",bold:true,depth:42});};for(let[B,de]of Object.entries(p)){let he=_r[B];D(B,he.art,he.color,de??1,f.w*.06+_*b*1.12,M+k*.075),_++;}_=0;for(let[B,de]of Object.entries(x)){let he=oo[B];D(B,he.art,he.color,de??1,f.w*.06+_*b*.95,M+k*.075+b*1.1),_++;}for(let B of [...Ue.keys()])if(B.startsWith("b:")){let de=B.slice(2).replace(/:l$/,"");A.has(de)||wt(B);}let j=_e(),q=ct();pt("hp",q.x,q.y+j*1.05,j*1.7,Math.max(7,k*.013),se.hp/se.maxHp,se.hp/se.maxHp>.35?"accent":"danger",40);},et=(i=-1)=>{let f=Ne(e),k=Me()*.08,d=i>=0?i:r.int(0,3);return {x:d===0?-k:d===1?f.w+k:r.range(-k,f.w+k),y:d===2?-k:d===3?f.h+k:r.range(-k,f.h+k)}},Ze=()=>n("foeHp")*pe.hp*(1+n("foeHpGrowth")*(ge/60)),ut=(i,f,k=false)=>{let d=$n[i],u=i==="boss"||i==="miniboss",w=Me()*d.size*(k?1.3:1),M=Ze()*d.hp*(k?8:1),v=At(e,f.x,f.y,{shape:"actor",cast:d.cast,variant:r.int(0,99),h:w*(u?1.9:i==="brute"?1.75:2.2),feet:w*.6,pose:i==="brute"||u?"walk":"run",depth:qt(e,f.y)},{type:je,data:{kind:i,hp:M,maxHp:M,speed:d.speed*lt()*n("foeSpeed")*(1+Math.min(.5,ge/600)),size:w,damage:d.damage*pe.damage*n("foeDamage")*(k?1.4:1),xp:d.xp*(k?5:1),elite:k,t:r.range(0,1.5),phase:"walk",vx:0,vy:0,hurtAt:{},next:0}});return (k||u)&&At(e,f.x,f.y+w*.5,{shape:"sprite",art:"aura_field",w:w*2.2,h:w*1.1,color:u?"danger":"coin",alpha:.85,depth:2},{type:ao,data:{of:v}}),v},gt=()=>{let i=ge/60+pe.headStart,f=Ld.filter(u=>$n[u].from<=i),k=0;for(let u of f)k+=$n[u].weight;let d=r.range(0,k);for(let u of f)if(d-=$n[u].weight,d<=0)return u;return f[0]??"grunt"},Wt=()=>e.query(je).length,Ft=(i,f)=>{let k=ge/60+pe.headStart,d=n("spawnRate")*(1+n("spawnGrowth")*k);for(Ee>0&&(Ee-=f,d*=.25),Te&&(d*=.45),Se&&(Se.left-=f,d*=2.6),we+=f*d;we>=1;)we-=1,!(Wt()>=n("maxFoes"))&&ut(gt(),et(Se?Se.side:-1));if(Se&&Se.left<=0&&(Se=null),!Te){if(ge>=Le){Le=ge+r.range(26,36);let u=J++%3;if(u===0){let w=ct(),M=12+Math.min(12,Math.floor(k*2)),v=Me()*.62;for(let b=0;b<M;b++){let _=b/M*Math.PI*2;ut(k>3?"grunt":"swarm",{x:w.x+Math.cos(_)*v,y:w.y+Math.sin(_)*v*1.25});}H(i,{kind:"flash",color:"danger"});}else u===1?Se={left:4,side:r.int(0,3)}:Ee=5;}if(n("eliteEvery")>0&&ge>=Y){Y=ge+n("eliteEvery");let u=gt();ut(u==="swarm"?"grunt":u,et(),true);}n("minibossEvery")>0&&ge>=ze&&ke-ge>30&&(ze=ge+n("minibossEvery"),(Be===null||!i.isAlive(Be))&&(Be=ut("miniboss",et()),i.emit(yi,{kind:"miniboss"}),H(i,{kind:"shake",power:1.2})));}},Ut=i=>{Te=true,i.vars.time_left=0;let f=ct();for(let k of i.query(je)){let d=i.get(k,je);if(!d||d.kind==="miniboss")continue;let u=i.need(k,G);Math.hypot(u.x-f.x,u.y-f.y)<Me()*.3&&z(i,k,null,false);}Be=ut("boss",{x:f.x,y:f.y-Ne(i).h*.42}),H(i,{kind:"shake",power:2}),H(i,{kind:"flash",color:"danger"}),i.emit(yi,{kind:"boss"});},R=(i,f,k,d=1)=>{let u=_e(),w=i==="xp"?{shape:"sprite",art:"crystal",w:u*(d>=25?.62:d>=5?.5:.38),h:u*(d>=25?.62:d>=5?.5:.38),color:d>=25?"secondary":d>=5?"primary":"accent",depth:3}:i==="coin"?{shape:"sprite",art:"coin",w:u*.4,h:u*.4,depth:3}:i==="food"?{shape:"sprite",art:"heart",w:u*.5,h:u*.5,depth:3}:i==="magnet"?{shape:"sprite",art:"magnet",w:u*.6,h:u*.6,depth:3}:i==="bomb"?{shape:"sprite",art:"bomb",w:u*.6,h:u*.6,depth:3}:{shape:"sprite",art:"chest",w:u*.9,h:u*.9,color:"coin",depth:3};At(e,f,k,w,{type:tr,data:{kind:i,value:d,pulled:false}});},z=(i,f,k,d=true)=>{let u=i.get(f,je);if(!u)return;let w=i.need(f,G),M=w.x,v=w.y;i.remove(f,je);for(let A of i.query(ao))i.need(A,ao).of===f&&i.destroy(A);ot(i,f,"die");let b=i.need(f,te);if(b.shape==="actor"&&(b.depth=qt(i,v)-.2),mn(i,f,1.4),H(i,{kind:"burst",x:M,y:v,color:"danger",n:u.elite||u.kind==="boss"?22:8,size:u.size*1.4}),!d)return;le+=1,i.vars.kills=le,i.emit("enemy-defeated",{kind:u.kind,elite:u.elite,by:k});let _=_e();if(u.xp>0&&R("xp",M,v+u.size*.4,u.xp),r.chance(Math.min(.95,n("coinRate")*se.luck))&&R("coin",M+_*.3,v+u.size*.4),r.chance(.012*se.luck)&&R("food",M-_*.3,v),r.chance(.004)&&!i.query(tr).some(A=>i.need(A,tr).kind==="magnet")&&R("magnet",M,v-_*.3),r.chance(.004)&&R("bomb",M,v-_*.3),u.elite||u.kind==="miniboss"){R("chest",M,v);for(let A=0;A<3;A++)R("coin",M+r.range(-_,_),v+r.range(-_,_));}if(u.kind==="bomber"){let A=Me()*.11*se.area;H(i,{kind:"ring",x:M,y:v,color:"piece6",size:A*2});for(let D of i.query(je)){let j=i.need(D,G);Math.hypot(j.x-M,j.y-v)<A&&y(i,D,Ze()*2.5,"blast");}}if((u.kind==="miniboss"||u.kind==="boss")&&(Ae+=1,i.vars.bosses=Ae,f===Be&&(Be=null),i.emit(gl,{kind:u.kind}),H(i,{kind:"shake",power:2}),u.kind==="boss")){for(let A of i.query(je))z(i,A,null,false);m(i,"cleared");}},y=(i,f,k,d)=>{if(!i.has(f,je))return;let u=i.need(f,je);if(u.hp-=k,(u.elite||u.kind==="boss"||u.kind==="miniboss")&&ve>0){ve-=1;let w=i.need(f,G);H(i,{kind:"pop",x:w.x+r.range(-10,10),y:w.y-u.size,text:String(Math.round(k)),color:"text",size:Math.round(Me()*.03)});}u.hp<=0?z(i,f,d):u.kind!=="boss"&&u.kind!=="miniboss"&&Ge(i,f,"hit");},S=(i,f,k,d,u)=>{let w=i.get(f,je);if(!w||w.kind==="boss"||w.kind==="miniboss"||w.phase==="dash")return;let M=i.need(f,G),v=M.x-k,b=M.y-d,_=Math.hypot(v,b)||1;M.x+=v/_*u,M.y+=b/_*u;},$=(i,f)=>{if(oe>0||o===null)return;let k=Math.max(1,f-se.armor);se.hp-=k,oe=n("graceTime"),i.vars.hp=Math.max(0,Math.ceil(se.hp)),i.emit("player-hit",{hp:i.vars.hp}),Ge(i,o,"hit"),H(i,{kind:"flash",color:"danger"}),H(i,{kind:"shake",power:.8});let d=ct();H(i,{kind:"pop",x:d.x,y:d.y-_e()*1.4,text:`-${Math.round(k)}`,color:"danger",size:Math.round(Me()*.034)}),se.hp<=0&&l(i);},l=i=>{if(i.vars.revive_ready===true&&!xe){i.vars.reviving=true,Ct(i),a=null,i.emit(Kt,{});return}m(i,"died");},h=i=>{if(i.vars.reviving!==true)return;xe=true,i.vars.reviving=false,se.hp=se.maxHp,i.vars.hp=Math.ceil(se.hp),oe=2.5;let f=ct();for(let k of i.query(je)){let d=i.need(k,G);if(Math.hypot(d.x-f.x,d.y-f.y)<Me()*.4){let u=i.get(k,je);if(!u)continue;u.kind==="boss"||u.kind==="miniboss"?S(i,k,f.x,f.y,Me()*.2):z(i,k,"revive");}}for(let k of i.query(Xr))i.destroy(k);H(i,{kind:"ring",x:f.x,y:f.y,color:"coin",size:Me()*.8}),H(i,{kind:"flash",color:"coin"}),o!==null&&ot(i,o,"idle");},m=(i,f)=>{if(!rt(i)||Pe)return;Pe=true;let k=Math.floor(ge);f==="cleared"&&i.vars["meta:first_clear"]===true&&Ke(i,"coins",pe.firstClearGold),i.vars.score=le*n("killScore")+k*5+Ae*n("bossScore")+(f==="cleared"?n("clearBonus")*pe.chapter:0),i.vars.choosing=false,i.vars.reviving=false,i.emit(Bt,{reason:f,stats:{kills:le,seconds:k,bosses:Ae,chapter:pe.chapter,level:I,cleared:f==="cleared"}});},g=()=>{let i=[],f=Object.keys(p).length,k=Object.keys(x).length;for(let u of no){let w=p[u];w!==void 0&&w<5?i.push({o:{kind:"weapon",id:u,level:w+1},weight:3}):w===void 0&&f<6&&i.push({o:{kind:"weapon",id:u,level:1},weight:1.6});}for(let u of pi){let w=x[u];w!==void 0&&w<5?i.push({o:{kind:"passive",id:u,level:w+1},weight:2}):w===void 0&&k<6&&i.push({o:{kind:"passive",id:u,level:1},weight:1.2});}let d=[];for(;d.length<3&&i.length>0;){let u=0;for(let v of i)u+=v.weight;let w=r.range(0,u),M=0;for(;M<i.length-1&&(w-=i[M].weight,!(w<=0));M++);d.push(i[M].o),i.splice(M,1);}return d.length<3&&d.push({kind:"heal",id:"heal",level:1}),d.length<3&&d.push({kind:"gold",id:"gold",level:1}),d},T=(i,f)=>{V=g(),ce=f,i.vars.choosing=true,i.vars.survivors_offer=xl(V),Ct(i),a=null,at(i,ln);let k=ct();H(i,{kind:"ring",x:k.x,y:k.y,color:f==="chest"?"coin":"accent",size:Me()*.5}),i.emit(hl,{level:I,source:f,options:V,build:{weapons:{...p},passives:{...x}}});},N=i=>{i.vars.choosing===true||!rt(i)||(K>0?(K-=1,T(i,"level")):ne>0&&(ne-=1,T(i,"chest")));},P=(i,f)=>{f.kind==="weapon"?(p[f.id]=f.level,E[f.id]=0):f.kind==="passive"?x[f.id]=f.level:f.kind==="heal"?se.hp=Math.min(se.maxHp,se.hp+se.maxHp*.3):f.kind==="gold"&&Ke(i,"coins",10),dt(),i.vars.hp=Math.ceil(se.hp),ie(i);},Z=(i,f)=>{if(i.vars.choosing!==true)return;let k=V[f];k&&(P(i,k),V=[],i.vars.choosing=false,i.vars.survivors_offer="",i.emit(ul,{kind:k.kind,id:k.id,level:k.level,source:ce}),N(i));},ie=i=>{let f=ct(),k=Me(),d=p.blades,u=d?_r.blades.count[d-1]:0,w=i.query(an);for(let D of w)i.need(D,an).index>=u&&i.destroy(D);for(let D=0;D<u;D++)w.some(j=>i.isAlive(j)&&i.need(j,an).index===D)||At(i,f.x,f.y,{shape:"sprite",art:"blade",w:k*.075,h:k*.075,color:"primary",depth:31},{type:an,data:{index:D}});for(let D of i.query(an)){let j=i.need(D,te);j.shape==="sprite"&&(j.w=j.h=k*(d===5?.095:.075)*Math.sqrt(se.area));}let M=p.aura,v=i.query(Mn);if(M){let D=k*_r.aura.reach[M-1]*se.area;v.length===0&&At(i,f.x,f.y,{shape:"sprite",art:"aura_field",w:D*2,h:D*2,color:M===5?"coin":"secondary",alpha:.9,depth:1.5},{type:Mn,data:{r:D}});for(let j of i.query(Mn)){i.need(j,Mn).r=D;let q=i.need(j,te);q.shape==="sprite"&&(q.w=q.h=D*2,q.color=M===5?"coin":"secondary");}}else for(let D of v)i.destroy(D);let b=p.drone,_=b?_r.drone.count[b-1]:0,A=i.query(En);for(let D of A)i.need(D,En).index>=_&&i.destroy(D);for(let D=0;D<_;D++)A.some(j=>i.isAlive(j)&&i.need(j,En).index===D)||At(i,f.x,f.y,{shape:"sprite",art:"drone",w:k*.06,h:k*.06,color:"piece6",depth:33},{type:En,data:{index:D,cd:.3*D}});},re=(i,f,k,d,u)=>{let w=null,M=d;for(let v of i.query(je)){if(u&&u.includes(v))continue;let b=i.need(v,G),_=Math.hypot(b.x-f,b.y-k);_<M&&(M=_,w=v);}return w},Ie=(i,f,k,d,u,w,M,v,b=1)=>{let _=_e()*b,A=n("shotSpeed")*lt(),D=At(i,f,k,{shape:"sprite",art:"shot",w:_*.95,h:_*.48,color:v,depth:30},{type:Sn,data:{vx:Math.cos(d)*A,vy:Math.sin(d)*A,life:1.4,damage:u,pierce:w,hit:[],by:M}});i.need(D,G).rotation=d;},Ce=(i,f,k)=>{if(o===null)return;let d=ct(),u=Me(),w=_e();for(let M of no){let v=p[M];if(v===void 0)continue;let b=_r[M],_=v-1,A=b.damage[_]*se.might;if(E[M]=(E[M]??0)-f,M==="blaster"&&E[M]<=0){let D=re(i,d.x,d.y,u*.75);if(D===null){E[M]=0;continue}E[M]=b.cooldown[_]*se.haste;let j=i.need(D,G),q=Math.atan2(j.y-(d.y-w*.3),j.x-d.x),B=b.count[_];for(let he=0;he<B;he++)Ie(i,d.x,d.y-w*.3,q+(he-(B-1)/2)*.16,A,b.pierce[_],"blaster",v===5?"piece6":"coin",v===5?1.25:1);Ge(i,o,"attack");let de=i.need(o,te);de.shape==="actor"&&(de.actRate=1/Math.max(.2,b.cooldown[_]*se.haste),k||(de.facing=j.x>=d.x?1:-1));}else if(M==="blades"){let D=u*b.reach[_]*se.area,j=3+.35*v;L+=j*f;let q=i.query(an),B=q.length||1;for(let de of q){let he=i.need(de,an),be=L+he.index/B*Math.PI*2,ye=i.need(de,G);ye.x=d.x+Math.cos(be)*D,ye.y=d.y-w*.2+Math.sin(be)*D,ye.rotation=L*2.2;let Ve=u*.04*Math.sqrt(se.area);for(let tt of i.query(je)){let mt=i.get(tt,je);if(!mt)continue;let Pt=i.need(tt,G);Math.hypot(Pt.x-ye.x,Pt.y-ye.y)>Ve+mt.size*.55||i.time-(mt.hurtAt.blades??-9)<b.cooldown[_]||(mt.hurtAt.blades=i.time,y(i,tt,A,"blades"),S(i,tt,d.x,d.y,u*.012));}}}else if(M==="aura"){let D=i.query(Mn)[0];if(D===void 0)continue;let j=i.need(D,G);if(j.x=d.x,j.y=d.y+w*.3,i.need(D,G).rotation=i.time*.6,E[M]>0)continue;E[M]=b.cooldown[_];let q=i.need(D,Mn).r;for(let B of i.query(je)){let de=i.need(B,G),he=i.get(B,je);!he||Math.hypot(de.x-d.x,de.y-d.y)>q+he.size*.3||(y(i,B,A,"aura"),S(i,B,d.x,d.y,u*.008));}}else if(M==="boomerang"&&E[M]<=0){let D=re(i,d.x,d.y,u*.8);if(D===null){E[M]=0;continue}E[M]=b.cooldown[_]*se.haste;let j=i.need(D,G),q=Math.atan2(j.y-d.y,j.x-d.x),B=b.count[_];for(let de=0;de<B;de++){let he=q+de*Math.PI*2/B,be=u*(v===5?.085:.065);At(i,d.x,d.y,{shape:"sprite",art:"boomerang",w:be,h:be,color:"accent",depth:32},{type:qo,data:{dx:Math.cos(he),dy:Math.sin(he),dist:0,range:u*b.reach[_]*se.area,back:false,damage:A,hit:[]}});}}else if(M==="lightning"&&E[M]<=0){let D=re(i,d.x,d.y,u*.55);if(D===null){E[M]=0;continue}E[M]=b.cooldown[_]*se.haste;let j=[],q={x:d.x,y:d.y-w},B=D;for(let de=0;de<b.count[_]&&B!==null;de++){let he=i.get(B,je);if(!he)break;let be=i.need(B,G),ye={x:be.x,y:be.y-he.size*.4};De(i,q,ye,v===5?"coin":"primary"),j.push(B);let Ve=re(i,be.x,be.y,u*b.reach[_]*se.area,j);y(i,B,A,"lightning"),q=ye,B=Ve;}}else if(M==="drone"){O+=1.8*f;let D=i.query(En),j=D.length||1,q=u*b.reach[_];for(let B of D){let de=i.need(B,En),he=O+de.index/j*Math.PI*2,be=i.need(B,G);if(be.x=d.x+Math.cos(he)*q,be.y=d.y-w*1.1+Math.sin(he)*q*.5,de.cd-=f,de.cd>0)continue;let ye=re(i,be.x,be.y,u*.6);if(ye===null){de.cd=0;continue}de.cd=b.cooldown[_]*se.haste;let Ve=i.need(ye,G);Ie(i,be.x,be.y,Math.atan2(Ve.y-be.y,Ve.x-be.x),A,v===5?2:1,"drone","piece6",.7);}}}},De=(i,f,k,d)=>{let u=Math.hypot(k.x-f.x,k.y-f.y),w=At(i,(f.x+k.x)/2,(f.y+k.y)/2,{shape:"sprite",art:"zap",w:Math.max(8,u),h:Me()*.035,color:d,depth:34},{type:Ko,data:{life:.16}});i.need(w,G).rotation=Math.atan2(k.y-f.y,k.x-f.x);},F=(i,f)=>{let k=ct(),d=_e(),u=Me(),w=Ne(i),M=Math.hypot(w.w,w.h)*.75,v=i.query(je);for(let _ of v){let A=i.get(_,je);if(!A)continue;let D=i.need(_,G),j=k.x-D.x,q=k.y-D.y,B=Math.hypot(j,q)||1;j/=B,q/=B;let de=A.kind==="boss"||A.kind==="miniboss";if(B>(de?M*1.3:M)){let tt=et();D.x=tt.x,D.y=tt.y;continue}A.t-=f;let he=A.speed,be=j,ye=q;if(A.kind==="archer"){let tt=u*.3;if(B<tt?he*=-0.6:B<tt*1.4&&(he=0),A.t<=0&&B<u*.6){A.t=2.4,Ge(i,_,"attack");let mt=260*lt();At(i,D.x,D.y-A.size*.6,{shape:"sprite",art:"orb",w:u*.03,h:u*.03,color:"danger",depth:29},{type:Xr,data:{vx:j*mt,vy:q*mt,life:3,damage:A.damage}});}}else (A.kind==="charger"||A.kind==="miniboss"||A.kind==="boss")&&(A.phase==="walk"&&A.t<=0&&B<u*(de?.6:.38)?A.kind!=="boss"||A.next%3===0?(A.phase="wind",A.t=de?.7:.55,Ge(i,_,"surprised"),H(i,{kind:"ring",x:D.x,y:D.y,color:"danger",size:A.size*2.2})):ae(i,_,A):A.phase==="wind"?(he=0,A.t<=0&&(A.phase="dash",A.t=de?.6:.45,A.vx=j,A.vy=q)):A.phase==="dash"&&(he=A.speed*(de?4:3.6),be=A.vx,ye=A.vy,A.t<=0&&(A.phase="walk",A.t=de?A.hp<A.maxHp/2?1.6:2.4:2.8,A.kind==="boss"&&(A.next+=1))));D.x+=be*he*f,D.y+=ye*he*f;let Ve=i.need(_,te);if(Ve.shape==="actor"&&(Math.abs(k.x-D.x)>A.size*.4&&(Ve.facing=k.x>=D.x?1:-1),Ve.depth=qt(i,D.y),Ve.speed=Math.abs(he),Ve.pose=he===0?"idle":A.kind==="brute"||de?"walk":"run"),B<(A.size+d)/2){if(A.kind==="bomber"){H(i,{kind:"ring",x:D.x,y:D.y,color:"piece6",size:u*.22}),$(i,A.damage),z(i,_,null,false);continue}if(oe<=0&&(Ge(i,_,"attack"),$(i,A.damage),Pe||ui(i)))return}}let b=i.query(je);for(let _=0;_<b.length;_++){let A=i.need(b[_],je),D=i.need(b[_],G);for(let j=_+1;j<b.length;j++){let q=i.need(b[j],je),B=i.need(b[j],G),de=(A.size+q.size)*.42,he=B.x-D.x,be=B.y-D.y,ye=he*he+be*be;if(ye>=de*de||ye===0)continue;let Ve=Math.sqrt(ye),tt=(de-Ve)*.5,mt=he/Ve*tt,Pt=be/Ve*tt,Or=A.kind==="boss"||A.kind==="miniboss",Er=q.kind==="boss"||q.kind==="miniboss";Or||(D.x-=mt,D.y-=Pt),Er||(B.x+=mt,B.y+=Pt);}}for(let _ of i.query(ao)){let A=i.need(_,ao).of;if(!i.isAlive(A)||!i.has(A,je)){i.destroy(_);continue}let D=i.need(A,G),j=i.need(_,G);j.x=D.x,j.y=D.y+i.need(A,je).size*.55;let q=i.need(_,te);q.shape==="sprite"&&(q.alpha=.6+.3*Math.sin(i.time*6));}},ae=(i,f,k)=>{let d=i.need(f,G),u=Me(),w=k.next%3;if(k.next+=1,k.t=k.hp<k.maxHp/2?1.4:2.2,w===1){let M=k.hp<k.maxHp/2?18:12,v=220*lt();for(let b=0;b<M;b++){let _=b/M*Math.PI*2+i.time;At(i,d.x,d.y-k.size*.4,{shape:"sprite",art:"orb",w:u*.035,h:u*.035,color:"danger",depth:29},{type:Xr,data:{vx:Math.cos(_)*v,vy:Math.sin(_)*v,life:3.5,damage:k.damage*.6}});}Ge(i,f,"attack"),H(i,{kind:"ring",x:d.x,y:d.y,color:"danger",size:k.size*3});}else {for(let M=0;M<6;M++){let v=M/6*Math.PI*2;ut("swarm",{x:d.x+Math.cos(v)*k.size*1.6,y:d.y+Math.sin(v)*k.size*1.6});}Ge(i,f,"cheer");}},Oe=(i,f)=>{let k=Ne(i),d=ct(),u=_e(),w=Me()*.2;for(let v of i.query(Sn)){let b=i.need(v,Sn),_=i.need(v,G);if(_.x+=b.vx*f,_.y+=b.vy*f,b.life-=f,b.life<=0||_.x<-w||_.y<-w||_.x>k.w+w||_.y>k.h+w){i.destroy(v);continue}for(let A of i.query(je)){if(b.hit.includes(A))continue;let D=i.get(A,je);if(!D)continue;let j=i.need(A,G);if(!(Math.abs(j.x-_.x)>D.size/2+4||Math.abs(j.y-(_.y+D.size*.2))>D.size*.9+4)&&(b.hit.push(A),H(i,{kind:"burst",x:_.x,y:_.y,color:"coin",n:4,size:u*.5}),S(i,A,d.x,d.y,Me()*.01),y(i,A,b.damage,b.by),b.hit.length>=b.pierce)){i.destroy(v);break}}}for(let v of i.query(Xr)){let b=i.need(v,Xr),_=i.need(v,G);if(_.x+=b.vx*f,_.y+=b.vy*f,b.life-=f,b.life<=0){i.destroy(v);continue}if(Math.hypot(_.x-d.x,_.y-(d.y-u*.3))<u*.55&&(i.destroy(v),$(i,b.damage),Pe||ui(i)))return}let M=Me()*1.5;for(let v of i.query(qo)){let b=i.need(v,qo),_=i.need(v,G);if(_.rotation=(_.rotation??0)+f*14,b.back){let D=d.x-_.x,j=d.y-_.y,q=Math.hypot(D,j)||1;if(q<u*.5){i.destroy(v);continue}_.x+=D/q*M*f,_.y+=j/q*M*f;}else {let D=M*f*Math.max(.35,1-b.dist/b.range);_.x+=b.dx*D,_.y+=b.dy*D,b.dist+=D,b.dist>=b.range*.98&&(b.back=true,b.hit=[]);}let A=i.need(v,te).w*.5;for(let D of i.query(je)){if(b.hit.includes(D))continue;let j=i.get(D,je);if(!j)continue;let q=i.need(D,G);Math.hypot(q.x-_.x,q.y-_.y)>A+j.size*.5||(b.hit.push(D),S(i,D,_.x,_.y,Me()*.015),y(i,D,b.damage,"boomerang"));}}for(let v of i.query(Ko)){let b=i.need(v,Ko);b.life-=f;let _=i.need(v,te);_.shape==="sprite"&&(_.alpha=Math.max(0,b.life/.16)),b.life<=0&&i.destroy(v);}},me=(i,f)=>{let k=ct(),d=_e(),w=i.query(tr).filter(M=>i.need(M,tr).kind==="xp");if(w.length>90){let M=w.map(D=>({e:D,d:Math.hypot(i.need(D,G).x-k.x,i.need(D,G).y-k.y)})).sort((D,j)=>j.d-D.d).slice(0,30),v=0,b=i.need(M[0].e,G),_=b.x,A=b.y;for(let D of M)v+=i.need(D.e,tr).value,i.destroy(D.e);R("xp",_,A,Math.max(25,v));}for(let M of i.query(tr)){let v=i.need(M,tr),b=i.need(M,G),_=Math.hypot(k.x-b.x,k.y-b.y);if(_<se.magnet||v.pulled){v.pulled=true;let A=Me()*(v.kind==="xp"&&_>se.magnet?2.4:1.4),D=Math.min(1,f*A/Math.max(1,_));b.x+=(k.x-b.x)*D,b.y+=(k.y-b.y)*D;}if(!(_>d*.6))if(i.destroy(M),v.kind==="coin")Ke(i,"coins",v.value),i.emit("coin-collected",{value:v.value}),H(i,{kind:"pop",x:k.x,y:k.y-d*1.6,text:`+${v.value}`,size:Math.round(d*.45)});else if(v.kind==="xp"){for(C+=v.value*se.growth;C>=st(I);)C-=st(I),I+=1,K+=1;i.vars.xp_level=I;}else if(v.kind==="food")se.hp=Math.min(se.maxHp,se.hp+se.maxHp*.25),i.vars.hp=Math.ceil(se.hp),H(i,{kind:"ring",x:k.x,y:k.y,color:"accent",size:d*3});else if(v.kind==="magnet"){for(let A of i.query(tr))(i.need(A,tr).kind==="xp"||i.need(A,tr).kind==="coin")&&(i.need(A,tr).pulled=true);H(i,{kind:"ring",x:k.x,y:k.y,color:"coin",size:Me()*1.2});}else if(v.kind==="bomb"){let A=Ne(i);H(i,{kind:"flash",color:"#ffffff"}),H(i,{kind:"shake",power:2});for(let D of i.query(je)){let j=i.need(D,G);if(j.x<0||j.y<0||j.x>A.w||j.y>A.h)continue;let q=i.get(D,je);q&&y(i,D,q.kind==="boss"||q.kind==="miniboss"?q.maxHp*.1:q.hp+1,"bomb");}}else v.kind==="chest"&&(ne+=1,H(i,{kind:"burst",x:k.x,y:k.y,color:"coin",n:20,size:d*2}));}N(i);},ue=()=>{for(let f of [je,Sn,Xr,tr,an,Mn,En,qo,Ko,ao,ln])at(e,f);at(e,zn),Je(),Ot(e,"top",void 0,{pan:true}),e.vars.field_x=0,e.vars.field_y=0,a=null,c=0,pe=so(Ur(e,"meta:chapter")||1,n("duration")),ke=pe.duration;let i=Ye();p={[i.weapon]:1},x=i.passive?{[i.passive]:1}:{};for(let f of no)E[f]=.4;C=0,I=1,K=0,ne=0,V=[],oe=0,le=0,Ae=0,xe=false,Pe=false,we=0,ge=0,Te=false,Be=null,ze=n("minibossEvery")>0?n("minibossEvery"):1/0,Y=n("eliteEvery")>0?n("eliteEvery")*.8:1/0,Le=22,J=0,Se=null,Ee=0,se.maxHp=0,se.hp=0,dt(),se.hp=se.maxHp,e.vars.hp=Math.ceil(se.hp),e.vars.hp_max=se.maxHp,e.vars.time_left=ke,e.vars.xp_level=1,e.vars.kills=0,e.vars.bosses=0,e.vars.chapter=pe.chapter,e.vars.choosing=false,e.vars.reviving=false,e.vars.boss_hp=0,e.vars.survivors_offer="",ft(),ie(e);};e.on(Tt,i=>{let f=i,k=e.vars.choosing===true||e.vars.reviving===true;f.type==="press"&&rt(e)&&!k?a={x:f.x,y:f.y}:f.type==="release"&&(a=null),f.type==="key"&&e.vars.choosing===true&&(f.key==="left"||f.key==="action"||f.key==="right")&&Z(e,f.key==="left"?0:f.key==="action"?1:2);}),e.on(ml,i=>Z(e,Number(i.index??-1))),e.on(yl,()=>{e.vars.choosing===true&&(e.vars.choosing=false,T(e,ce));}),e.on(Zt,()=>h(e)),e.on(Qt,()=>{e.vars.reviving===true&&(e.vars.reviving=false,m(e,"died"));}),e.on(Ht,ue),e.on(Gt,ue),e.on(Vt,i=>{for(let f of e.query(je))ot(e,f,"idle");o!==null&&e.isAlive(o)&&ot(e,o,i.reason==="cleared"?"dance":"die"),Je(),at(e,ln);}),e.on(jt,()=>{Ot(e,"top",void 0,{pan:true}),ft(),rt(e)&&ie(e);});let Q=(i,f)=>{let k=a!==null&&s.pointer.down&&i.vars.choosing!==true,d=i.query(ln);if(!k||a===null){for(let b of d)i.destroy(b);return}d.length===0&&(At(i,a.x,a.y,{shape:"circle",r:f,color:"#ffffff",alpha:.16,depth:70},{type:ln,data:{part:0}}),At(i,a.x,a.y,{shape:"circle",r:f*.42,color:"#ffffff",alpha:.55,depth:71},{type:ln,data:{part:1}}));let u=s.pointer.x-a.x,w=s.pointer.y-a.y,M=Math.hypot(u,w)||1,v=Math.min(1,f/M);for(let b of i.query(ln)){let _=i.need(b,G);i.need(b,ln).part===0?(_.x=a.x,_.y=a.y):(_.x=a.x+u*v,_.y=a.y+w*v);}};e.addSystem({id:"survivors",order:0,run(i,f){if(!rt(i)||o===null||Pe)return;let k=i.vars.choosing===true||i.vars.reviving===true;for(let q of [o,...i.query(je)]){let B=i.get(q,te);B?.shape==="actor"&&(B.paused=k);}if(k)return;ve=Math.min(12,ve+f*10);let d=Ne(i);if(ge+=f,!Te){let q=Math.max(0,ke-ge);i.vars.time_left=q,q<=0&&Ut(i);}oe>0&&(oe=Math.max(0,oe-f)),se.regen>0&&se.hp<se.maxHp&&(se.hp=Math.min(se.maxHp,se.hp+se.regen*f),i.vars.hp=Math.ceil(se.hp)),i.vars.hp_max=se.maxHp;let u=ct(),w=Me()*.11,M=s.axis(),v=M.x,b=M.y,_=v!==0||b!==0?1:0;if(_===0&&a&&s.pointer.down){v=s.pointer.x-a.x,b=s.pointer.y-a.y;let q=Math.hypot(v,b);_=q<w*.18?0:Math.min(1,q/w);}Q(i,w);let A=Math.hypot(v,b),D=A>0&&_>0;if(D){let q=v/A*se.speed*_*f,B=b/A*se.speed*_*f;for(let de of [...i.query(je),...i.query(Sn),...i.query(Xr),...i.query(tr),...i.query(zn),...i.query(qo),...i.query(Ko)]){let he=i.need(de,G);he.x-=q,he.y-=B;}Pc(i,q,B),Ke(i,"field_x",q),Ke(i,"field_y",B),c+=f,c>.6&&$t(i,"survivors-move");}!xt(i,"survivors-move")&&!kr(i)&&bt(i,"circle",{x:d.w/2,y:d.h*.8},{x:w*.6,y:0});let j=i.need(o,te);j.alpha=oe>0&&Math.floor(i.time*12)%2===0?.4:1,j.shape==="actor"&&(j.pose=D?"run":"idle",j.speed=se.speed*Math.max(.3,_),D&&Math.abs(v)>A*.15&&(j.facing=v>0?1:-1),j.depth=qt(i,u.y)+5e-4),Ft(i,f),F(i,f),!(Pe||ui(i))&&(Ce(i,f,D),Oe(i,f),!(Pe||ui(i))&&(me(i,f),!Pe&&(i.vars.score=le*n("killScore")+Math.floor(ge)*5+Ae*n("bossScore"),yt(i))));}}),e.vars.survivors_base=n("duration"),ue();}};var bi=[{id:"archer",base:{damage:6,type:"physical",range:2.6,rate:1.2,air:true,ground:true,shot:"td_arrow",shotSpeed:13},tiers:[{cost:70,stats:{},art:"td_archer1"},{cost:100,stats:{damage:9,range:2.8,rate:1.35},art:"td_archer2"},{cost:150,stats:{damage:14,range:3,rate:1.5},art:"td_archer3"}],branches:[{id:"ranger",cost:240,stats:{damage:17,rate:2.5,multishot:2,range:3.1},art:"td_archer_ranger"},{id:"sniper",cost:260,stats:{damage:72,rate:.5,range:4.6,pierce:1,crit:.2,shotSpeed:22},art:"td_archer_sniper"}],unlockLevel:1,metaVar:"meta:tower:archer"},{id:"cannon",base:{damage:12,type:"physical",range:2.3,rate:.5,air:false,ground:true,shot:"bomb",shotSpeed:6,lob:true,splash:.9},tiers:[{cost:110,stats:{},art:"td_cannon1"},{cost:150,stats:{damage:22,splash:1},art:"td_cannon2"},{cost:210,stats:{damage:36,splash:1.1,range:2.5},art:"td_cannon3"}],branches:[{id:"bombard",cost:300,stats:{damage:72,splash:1.5,rate:.42,range:2.8,stun:.25,stunTime:.6},art:"td_cannon_bombard"},{id:"flamer",cost:280,stats:{damage:20,splash:1,rate:.9,burn:12,burnTime:3},art:"td_cannon_flamer"}],unlockLevel:1,metaVar:"meta:tower:cannon"},{id:"mage",base:{damage:14,type:"magic",range:2.4,rate:.7,air:true,ground:true,shot:"orb",shotSpeed:9},tiers:[{cost:100,stats:{},art:"td_mage1"},{cost:140,stats:{damage:26},art:"td_mage2"},{cost:200,stats:{damage:42,range:2.6},art:"td_mage3"}],branches:[{id:"arcane",cost:300,stats:{damage:110,type:"true",rate:.55,range:2.9},art:"td_mage_arcane"},{id:"storm",cost:280,stats:{damage:32,rate:.9,chain:4,beam:true,shot:"zap"},art:"td_mage_storm"}],unlockLevel:3,metaVar:"meta:tower:mage"},{id:"frost",base:{damage:3,type:"magic",range:2.2,rate:.8,air:true,ground:true,shot:"crystal",shotSpeed:10,splash:.5,slow:.35,slowTime:1.6},tiers:[{cost:90,stats:{},art:"td_frost1"},{cost:120,stats:{damage:5,slow:.45,slowTime:1.9},art:"td_frost2"},{cost:170,stats:{damage:8,slow:.5,slowTime:2.2,splash:.7,range:2.4},art:"td_frost3"}],branches:[{id:"glacier",cost:260,stats:{damage:14,slow:.6,slowTime:2.6,stun:.15,stunTime:1},art:"td_frost_glacier"},{id:"blizzard",cost:260,stats:{damage:10,splash:1.4,slow:.5,slowTime:2.4,range:2.7},art:"td_frost_blizzard"}],unlockLevel:5,metaVar:"meta:tower:frost"}],kl=6,Zo=.7,Ar=e=>bi.find(t=>t.id===e);function Qo(e,t,r){let s=e.base;for(let o=1;o<Math.min(t,e.tiers.length);o++)s={...s,...e.tiers[o].stats};let n=r?e.branches.find(o=>o.id===r):void 0;return n?{...s,...n.stats}:s}function Yo(e,t,r){let s=0;for(let o=0;o<Math.min(t,e.tiers.length);o++)s+=e.tiers[o].cost;let n=r?e.branches.find(o=>o.id===r):void 0;return s+(n?.cost??0)}var xi=(e,t,r)=>(r?e.branches.find(s=>s.id===r)?.art:void 0)??e.tiers[Math.min(t,e.tiers.length)-1].art,cn=[{id:"grunt",cast:"foe",hp:1,speed:1,armor:0,resist:0,bounty:6,leak:1,size:.82,hit:.25,firstLevel:1,cost:1},{id:"runner",cast:"foe5",hp:.55,speed:1.8,armor:0,resist:0,bounty:4,leak:1,size:.72,hit:.15,firstLevel:2,cost:.7},{id:"brute",cast:"foe2",hp:2.6,speed:.7,armor:.6,resist:0,bounty:14,leak:2,size:1,hit:.5,firstLevel:3,cost:2.4,badge:"shield"},{id:"flyer",cast:"foe3",hp:.8,speed:1.2,armor:0,resist:0,flying:true,bounty:8,leak:1,size:.75,hit:0,firstLevel:4,cost:1.3,badge:"wing"},{id:"shaman",cast:"foe4",hp:1.6,speed:.9,armor:0,resist:.7,bounty:12,leak:1,size:.86,hit:.3,firstLevel:6,cost:2,badge:"orb"},{id:"healer",cast:"foe4",variant:7,hp:1.3,speed:.9,armor:.2,resist:.2,bounty:14,leak:1,size:.86,hit:.2,heals:{radius:1.6,share:.08,every:2},firstLevel:8,cost:2.2,badge:"potion"},{id:"splitter",cast:"foe2",variant:5,hp:2,speed:.85,armor:.2,resist:0,bounty:10,leak:2,size:.95,hit:.4,splits:{into:"spawnling",count:3},firstLevel:11,cost:2.6,badge:"skull"},{id:"spawnling",cast:"foe5",variant:3,hp:.35,speed:1.6,armor:0,resist:0,bounty:2,leak:1,size:.55,hit:.1,firstLevel:0,cost:.4},{id:"warlord",cast:"boss",hp:30,speed:.55,armor:.2,resist:0,bounty:120,leak:10,size:1.5,hit:2,summons:{id:"grunt",count:3,every:6},boss:1,firstLevel:0,cost:0},{id:"ironclad",cast:"boss",variant:4,hp:50,speed:.5,armor:.65,resist:0,bounty:160,leak:10,size:1.6,hit:2.5,enrage:{below:.5,speed:1.7},boss:2,firstLevel:0,cost:0,badge:"shield"},{id:"broodmother",cast:"boss",variant:9,hp:62,speed:.5,armor:.2,resist:.3,bounty:200,leak:10,size:1.6,hit:2.5,summons:{id:"spawnling",count:4,every:5},splits:{into:"spawnling",count:8},boss:3,firstLevel:0,cost:0,badge:"skull"},{id:"lich",cast:"boss",variant:13,hp:80,speed:.48,armor:.3,resist:.5,bounty:260,leak:15,size:1.7,hit:3,heals:{radius:2.2,share:.05,every:3},summons:{id:"shaman",count:2,every:7},boss:4,firstLevel:0,cost:0,badge:"orb"}],ar=e=>cn.find(t=>t.id===e),lo=[{id:"meteor",icon:"td_meteor",kind:"strike",cooldown:35,unlockLevel:2,damage:2.2,count:3,radius:1.1,burn:.3},{id:"reinforce",icon:"shield",kind:"summon",cooldown:22,unlockLevel:4,count:2,cast:"helper",hp:4,dps:.6,time:14}],Dr=9,Tr=13,vl=[{id:"meadow-a",rows:["..S......",".o#o..t..","..#......","..#####o.",".o....#..","..t...#o.",".o#####..","..#..o..t","..#.*....","o.####o..","....o#...",".t...#.o.",".....X..."]},{id:"meadow-b",rows:["......S..",".t..o.#o.","......#..",".o#####..","..#..o...","..#.t..o.","..####...",".o..o#.t.","..*..#...","..####o..",".o#......","..#.o..t.","..X......"]},{id:"meadow-c",rows:[".S.......",".#.o..o..",".#.....#X",".#o.t.o#.",".#.....#.",".#o.o..#.",".#..r..#.",".#.o.o.#o",".#.....#.",".#o.*.o#.",".#######.","..o.o.o..","t.......t"]},{id:"meadow-boss",rows:["....S....","..o.#.o..","....#....",".####.o..",".#..o....",".#.o..t..",".#######.","..o.o..#.",".o.....#o","..######.","..#.o.o..",".o#......","..X......"]},{id:"river-a",rows:[".........","S####.o..",".o..#....","..o.#.~~.","....####.",".o.r...#.","...o...#o",".#######.",".#.o.o...",".#....r..",".####.o..","..o.#....","....X...."]},{id:"river-b",rows:[".S.....S.",".#.o.o.#.",".#..t..#.",".###.###.",".o.#o#.o.","...#.#...","..o###o..","....#....",".o..#.o..","...o#....","..r.#.o..",".o..#..t.","....X...."]},{id:"river-c",rows:["..~~.....","o...####S","..o.#..o.","....#.~~.",".####.~~.",".#..o....",".#.o..r..",".######o.","..o...#..",".~~.o.#..","X######o.","..o.o....","..~~...t."]},{id:"river-boss",rows:[".o.....o.","S##.o.##S","..#.r.#..",".o#####o.","....#....",".o..#.o..",".####..t.",".#..o..o.",".#.o.....",".#######.","..o.o..#.",".o.....#o",".......X."]},{id:"wood-a",rows:["..o...o..","S#######.",".o.....#.","...o.o.#o",".#####.#.",".#.o.#.#.",".#.X.#.#.",".#.###.#.",".#..o..#.",".#######.","..o.o.o..",".t..r..o.","........."]},{id:"wood-b",rows:["...S.....",".o.#..o..","...#.t...",".o.####o.","......#..",".o.o..#o.","......##X",".o.o..#o.","......#..",".o.####o.","...#.r...",".o.#..o..","...S....."]},{id:"wood-c",rows:[".o..o..o.",".#######S",".#.o..o..",".#######.","..o.o..#.",".#######.",".#..o..o.",".#######.","..o..o.#.",".#######.",".#.o..o..",".#..r..t.",".X......."]},{id:"wood-boss",rows:["....X....",".o..#..o.","..o.#....",".####.o..",".#..o..t.",".#.o..o..",".#######.","..o..o.#.",".o.....#.","..######.","..#.o..o.",".o#..r...","..S......"]},{id:"ash-a",rows:["....S....",".o..#..o.","S##.#.##S","..#.#.#..",".o#o#o#o.","..#####..",".o..#..o.","...o#o...",".t..#..t.",".o..#..o.","..r.#.r..",".o..#..o.","....X...."]},{id:"ash-b",rows:[".S.....S.",".#.o.o.#.",".#..o..#.",".###.###.","...#o#...",".o.#.#.o.","...#o#...",".###.###.",".#.o.o.#.",".#.....#.",".#######.","..o.#.o..","....X...."]},{id:"ash-c",rows:[".S.....X.",".#.###.#.",".#o#o#o#.",".#.#.#.#.",".#o#.#o#.",".#.#o#.#.","o#.#.#.#o",".#o#.#o#.",".#.#o#.#.",".#.#.#.#.",".#o#.#o#.",".###.###.","........."]},{id:"ash-boss",rows:[".o.....o.","S#.o.o.#S",".#.....#.",".#o.r.o#.",".#.....#.",".#o.X.o#.",".#..#..#.",".#o.#.o#.",".#..#..#.",".#.o#o.#.",".#######.","..o.o.o..",".t.....t."]}],ki=e=>vl.find(t=>t.id===e);function co(e,t){return t==="x"?e.rows.map(r=>[...r].reverse().join("")):t==="y"?[...e.rows].reverse():e.rows}var ph=e=>e==="#"||e==="S"||e==="X";function fo(e){let t=(E,L)=>e[L]?.[E],r=null,s=[],n=[];for(let E=0;E<e.length;E++)for(let L=0;L<e[E].length;L++){let O=t(L,E);O==="X"?r={col:L,row:E}:O==="S"?s.push({col:L,row:E}):O==="o"&&n.push({col:L,row:E});}if(!r)throw new Error("tower-defense map: no gate (X)");if(s.length===0)throw new Error("tower-defense map: no entry (S)");let o=new Map,a=(E,L)=>`${E},${L}`,c=[r];o.set(a(r.col,r.row),0);let p=[[0,1],[-1,0],[1,0],[0,-1]];for(;c.length>0;){let E=c.shift(),L=o.get(a(E.col,E.row));for(let[O,C]of p){let I=E.col+O,K=E.row+C;!ph(t(I,K))||o.has(a(I,K))||(o.set(a(I,K),L+1),c.push({col:I,row:K}));}}let x=s.map(E=>{if(!o.has(a(E.col,E.row)))throw new Error(`tower-defense map: the entry ${E.col},${E.row} has no road to the gate`);let L=[E],O=E;for(;O.col!==r.col||O.row!==r.row;){let C=o.get(a(O.col,O.row)),I=p.map(([K,ne])=>({col:O.col+K,row:O.row+ne})).find(K=>o.get(a(K.col,K.row))===C-1);L.push(I),O=I;}return L});return {rows:e,paths:x,gate:r,spots:n}}var $l=4,Rr=5,Jo=$l*Rr,Ml=[0,9,24,39],El=[{map:"meadow-a",mirror:"none"},{map:"meadow-b",mirror:"none"},{map:"meadow-c",mirror:"none"},{map:"meadow-a",mirror:"x"},{map:"meadow-boss",mirror:"none"},{map:"river-a",mirror:"none"},{map:"river-b",mirror:"none"},{map:"river-c",mirror:"none"},{map:"river-a",mirror:"x"},{map:"river-boss",mirror:"none"},{map:"wood-a",mirror:"none"},{map:"wood-b",mirror:"none"},{map:"wood-c",mirror:"none"},{map:"wood-b",mirror:"x"},{map:"wood-boss",mirror:"none"},{map:"ash-a",mirror:"none"},{map:"ash-b",mirror:"none"},{map:"ash-c",mirror:"none"},{map:"ash-a",mirror:"y"},{map:"ash-boss",mirror:"none"}];function hh(e){let t=e>>>0;return ()=>{t=t+1831565813>>>0;let r=t;return r=Math.imul(r^r>>>15,r|1),r^=r+Math.imul(r^r>>>7,r|61),((r^r>>>14)>>>0)/4294967296}}function Sl(e,t){let r=Math.max(1,Math.min(Jo,Math.floor(e))),s=hh(r*7919+13),n=cn.filter(E=>E.firstLevel>0&&E.firstLevel<=r),o=cn.find(E=>E.firstLevel===r),a=Math.ceil(r/Rr),c=r%Rr===0?cn.find(E=>E.boss===a):void 0,p=6+Math.floor((r-1)/2),x=[];for(let E=1;E<=p;E++){let L=5+E*1.6+r*.35,O=[],C=0,I=0,K=[];if(E===1)K.push(n[0]);else {o&&E===2&&K.push(o);let V=Math.min(4,1+Math.floor(E/3));for(;K.length<V;)K.push(n[Math.floor(s()*n.length)]);}let ne=L/K.length;for(let V of K){let ce=Math.max(1,Math.round(ne/V.cost)),oe=V.speed>=1.5?.55:V.hp>=2?1.3:.85;O.push({enemy:V.id,count:ce,gap:oe,delay:C,entry:I%Math.max(1,t)}),C+=ce*oe*.55+1,I++;}c&&E===p&&O.push({enemy:c.id,count:1,gap:1,delay:C+2,entry:0}),x.push({groups:O});}return x}function po(e,t=.5){let r=Math.max(1,Math.min(Jo,Math.floor(e))),s=Math.ceil(r/Rr),n=r-(s-1)*Rr,o=El[r-1],a=fo(co(ki(o.map),o.mirror)).paths.length;return {level:r,world:s,index:n,boss:n===Rr,map:o.map,mirror:o.mirror,hp:16*Math.pow(1.075,r-1)*(.8+t*.4),waves:Sl(r,a),gold:220+(r-1)*25,bounty:1+(r-1)*.03,towers:bi.filter(c=>c.unlockLevel<=r).map(c=>c.id),spells:lo.filter(c=>c.unlockLevel<=r).map(c=>c.id),branches:r>=kl,fresh:cn.find(c=>c.firstLevel===r)?.id??null,enemies:cn.filter(c=>c.firstLevel>0&&c.firstLevel<=r).map(c=>c.id),firstClearGold:(n===Rr?150:60)+(r-1)*20}}var wl=e=>Ml[Math.ceil(Math.max(1,e)/Rr)-1]??0,vi=(e,t)=>e>=t*.9?3:e>=t*.5?2:1,$i=5,Cd=20,ho=[{id:"hero",cast:"hero",gems:0,perk:"none"},{id:"hero2",cast:"hero2",gems:150,perk:"gold"},{id:"hero3",cast:"hero3",gems:300,perk:"spells"}],Ll="kit-td",_l=[{id:"StartGold",var:"meta:start_gold",art:"td_gold",color:"coin",perLevel:20,unit:"",maxLevel:10,price:40,growth:.12},{id:"Lives",var:"meta:lives",art:"heart",color:"danger",perLevel:1,unit:"",maxLevel:5,price:120,growth:.2},{id:"Archer",var:"meta:tower:archer",art:"td_archer1",color:"primary",perLevel:6,unit:"%",maxLevel:10,price:40,growth:.12},{id:"Cannon",var:"meta:tower:cannon",art:"td_cannon1",color:"primary",perLevel:6,unit:"%",maxLevel:10,price:40,growth:.12},{id:"Mage",var:"meta:tower:mage",art:"td_mage1",color:"primary",perLevel:6,unit:"%",maxLevel:10,price:45,growth:.12},{id:"Frost",var:"meta:tower:frost",art:"td_frost1",color:"primary",perLevel:6,unit:"%",maxLevel:10,price:45,growth:.12},{id:"Spells",var:"meta:spells",art:"td_meteor",color:"danger",perLevel:8,unit:"%",maxLevel:10,price:50,growth:.12}],Pd={game:"tower-defense",character:Ll,stats:_l,heroes:ho,levels:Jo,firstClearGold:e=>po(e).firstClearGold,stars:3,starsToEnter:wl};var uh="boss-spawned",mh="boss-defeated",Al="wave-started",Si=$e("td.spot"),hr=$e("td.tower"),Re=$e("td.raider"),wn=$e("td.missile"),$r=$e("td.soldier"),Mi=$e("td.meteor"),Id=$e("td.ground"),Rl=$e("td.part"),zd=$e("td.bar"),Ei=$e("td.zap"),es=(e,t)=>{let r=Number(e.vars[t]??0);return Number.isFinite(r)?r:0},yh=.5,gh=.55,wi={id:"tower-defense",version:2,engines:["phaser"],requires:["round"],params:{difficulty:{type:"number",default:.5,min:0,max:1},lives:{type:"number",default:20,min:1,max:100,integer:true},gold:{type:"number",default:0,min:0,max:1e5,integer:true},wavePause:{type:"number",default:14,min:2,max:60},firstWait:{type:"number",default:25,min:1,max:600},earlyGold:{type:"number",default:2,min:0,max:100},coinRate:{type:"number",default:.15,min:0,max:1}},setup({world:e,params:t}){let r=d=>cr(t,d),s=e.rng.stream("tower-defense"),n=po(1,r("difficulty")),o=fo(co(ki(n.map),n.mirror)),a=[],c=Le(),p=0,x=20,E=20,L=0,O=[],C=0,I=null,K=0,ne=0,V=0,ce=false,oe=false,le=1,Ae=null,xe=[],we=null,ge=new Map,ke=[],pe=null,Te=new Map,Be=new Map,ze=()=>ho.find(d=>d.id===e.vars["meta:hero"])??ho[0],Y=()=>e.vars.reviving===true;function Le(){return rn(Ne(e),Dr,Tr,{top:.15,bottom:.86,widthShare:.98})}let J=()=>c.cell,Se=d=>c.left+d*c.cell,Ee=d=>c.top+d*c.cell,ve=d=>({x:Se(d.col+.5),y:Ee(d.row+.5)}),Pe=(d,u)=>({x:(d-c.left)/c.cell,y:(u-c.top)/c.cell}),Ue=d=>d.row===0?{x:d.col+.5,y:-0.5}:d.row===Tr-1?{x:d.col+.5,y:Tr+.5}:d.col===0?{x:-0.5,y:d.row+.5}:d.col===Dr-1?{x:Dr+.5,y:d.row+.5}:null,se=()=>{a=o.paths.map(d=>{let u=d.map(M=>({x:M.col+.5,y:M.row+.5})),w=Ue(d[0]);return w&&u.unshift(w),{pts:u,len:u.length-1}});},Me=(d,u)=>{if(u<=0)return d.pts[0];if(u>=d.len)return d.pts[d.len];let w=Math.floor(u),M=d.pts[w],v=d.pts[w+1],b=u-w;return {x:M.x+(v.x-M.x)*b,y:M.y+(v.y-M.y)*b}},lt=new Set,_e=(d,u,w,M,v=1)=>{lt.add(d);let b=Te.get(d);(b===void 0||!e.isAlive(b))&&(b=e.create(),e.set(b,Rl,{id:d}),Te.set(d,b)),e.set(b,G,{x:u,y:w,scale:v}),e.set(b,te,M);},ct=d=>{for(let[u,w]of [...Te])lt.has(u)||!d.some(M=>u.startsWith(M))||(e.destroy(w),Te.delete(u));},dt=d=>{for(let[u,w]of [...Te])u.startsWith(d)&&(e.destroy(w),Te.delete(u));},st=(d,u,w,M)=>{let v=e.create();return e.set(v,Id,{kind:d}),e.set(v,G,{x:u,y:w}),e.set(v,te,M),v},Ye=()=>{at(e,Id),at(e,Si);let d=J();st("grass",Se(Dr/2),Ee(Tr/2),{shape:"tile",art:"tile_grass",w:d*Dr,h:d*Tr,unit:d,color:"ground",depth:-10}),o.rows.forEach((_,A)=>[..._].forEach((D,j)=>{let q=ve({col:j,row:A}),B=q.y+d*.45;D==="#"||D==="S"||D==="X"?st("road",q.x,q.y,{shape:"sprite",art:"tile_road",w:d+1,h:d+1,color:"lane",depth:-9}):D==="~"?st("water",q.x,q.y,{shape:"rect",w:d+1,h:d+1,color:"primary",alpha:.45,depth:-9}):D==="t"?st("tree",q.x,B-d*.65,{shape:"sprite",art:"td_tree",w:d*1.05,h:d*1.3,depth:qt(e,B,5)}):D==="r"?st("rock",q.x,B-d*.3,{shape:"sprite",art:"rock",w:d*.8,h:d*.6,depth:qt(e,B,5)}):D==="*"&&st("bush",q.x,B-d*.3,{shape:"sprite",art:"td_bush",w:d*.85,h:d*.6,depth:qt(e,B,5)});})),o.spots.forEach((_,A)=>{let D=ve(_),j=st("spot",D.x,D.y+d*.18,{shape:"sprite",art:"td_spot",w:d*.95,h:d*.62,depth:-8});e.set(j,Si,{index:A,col:_.col,row:_.row});});let u=ve(o.gate),w=Ue(o.gate),M=w&&w.y>=0?w:null,v=M?Se(o.gate.col+.5+(M.x-(o.gate.col+.5))*.35):u.x,b=M?Ee(o.gate.row+.5+(M.y-(o.gate.row+.5))*.35):u.y;st("gate",v,b-d*.2,{shape:"sprite",art:"td_gate",w:d*1.35,h:d*1.35,depth:qt(e,b+d*.45,5)});for(let _ of o.paths){if(Ue(_[0]))continue;let A=ve(_[0]);st("portal",A.x,A.y-d*.1,{shape:"sprite",art:"td_portal",w:d*1.05,h:d*.95,depth:qt(e,A.y,4)});}},ft=d=>e.query(hr).find(u=>e.need(u,hr).spot===d),qe=d=>{let u=e.need(d,hr),w=Ar(u.kind),M=ve(o.spots[u.spot]),v=J(),b=v*1.45,_=M.y+v*.42;e.set(d,G,{x:M.x,y:_-b/2}),e.set(d,te,{shape:"sprite",art:xi(w,u.tier,u.branch||null),w:v*1.1,h:b,depth:qt(e,_,5)});},wt=d=>{p=Math.max(0,Math.round(d)),e.vars.gold=p;},Je=(d,u)=>{let w=ve(o.spots[d]);H(e,{kind:"ring",x:w.x,y:w.y,color:u,size:J()*1.5}),H(e,{kind:"burst",x:w.x,y:w.y-J()*.4,color:u,n:10,size:J()});},pt=(d,u)=>{let w=Ar(u);if(!w||ft(d)!==void 0)return false;let M=w.tiers[0].cost;if(p<M)return false;wt(p-M);let v=e.create();return e.set(v,hr,{spot:d,kind:u,tier:1,branch:"",cooldown:.2}),qe(v),Je(d,"text"),e.emit("tower-built",{kind:u}),xt(e,"td-build")||($t(e,"td-build"),Oe()),true},yt=(d,u)=>{let w=ft(d);if(w===void 0)return false;let M=e.need(w,hr),v=Ar(M.kind),b;if(u){let _=v.branches.find(A=>A.id===u);if(!_||M.branch||M.tier<v.tiers.length||!n.branches)return false;b=_.cost;}else {if(M.tier>=v.tiers.length)return false;b=v.tiers[M.tier].cost;}return p<b?false:(wt(p-b),u?M.branch=u:M.tier++,qe(w),Je(d,"coin"),e.emit("tower-upgraded",{kind:M.kind,tier:M.tier,branch:M.branch}),true)},et=d=>{let u=ft(d);if(u===void 0)return false;let w=e.need(u,hr),M=Math.floor(Yo(Ar(w.kind),w.tier,w.branch||null)*Zo);wt(p+M);let v=ve(o.spots[d]);return H(e,{kind:"pop",x:v.x,y:v.y-J()*.8,text:`+${M}`,color:"coin",size:Math.round(J()*.3)}),H(e,{kind:"burst",x:v.x,y:v.y,color:"muted",n:12,size:J()}),e.destroy(u),e.emit("tower-sold",{kind:w.kind}),true},Ze=()=>{Ae=null,xe=[],dt("m:"),e.vars.td_menu="";},ut=d=>d.map(u=>`${u.action??u.id}@${Math.round(u.x)},${Math.round(u.y)}`).join(";"),gt=d=>{Ze(),Ae=d,Wt();},Wt=()=>{if(Ae===null)return;let d=Ae;xe=[];let u=J(),w=Ne(e),M=Math.min(w.w,w.h),v=Math.max(u*.46,M*.062),b=Math.max(u*1.1,v*2.3),_=ve(o.spots[d]),A=Math.max(b+v,Math.min(w.w-b-v,_.x)),D=Math.max(w.h*.1+b+v,Math.min(w.h*.88-b-v,_.y-u*.2)),j=(ye,Ve,tt,mt,Pt,Or,Er)=>{let mr=A+Ve*b,Zr=D+tt*b;xe.push({action:ye,x:mr,y:Zr,r:v,ok:Er}),e.vars.td_menu=ut(xe),_e(`m:${ye}:bg`,mr,Zr,{shape:"circle",r:v,color:"panel",alpha:.94,depth:60});let Rn=ye==="sell";_e(`m:${ye}:rim`,mr,Zr,{shape:"circle",r:v*1.08,color:Rn?"danger":Er?"coin":"muted",alpha:Er?.9:.5,depth:59.9}),_e(`m:${ye}:art`,mr,Zr-v*.12,{shape:"sprite",art:mt,w:Rn?v*1.25:v*1.15,h:Rn?v*1.25:v*1.3,alpha:Er?1:.45,depth:60.1}),Or&&_e(`m:${ye}:txt`,mr,Zr+v*.78,{shape:"text",text:Or,size:Math.round(v*.52),color:Pt!==null&&!Er?"danger":"coin",bold:true,depth:60.2});},q=ft(d);if(q===void 0){let ye=n.towers.map(tt=>Ar(tt)).filter(Boolean),Ve=ye.length<=1?[[0,-1]]:ye.length===2?[[-0.8,-0.7],[.8,-0.7]]:ye.length===3?[[-0.85,-0.6],[.85,-0.6],[0,.9]]:[[-0.8,-0.75],[.8,-0.75],[-0.8,.75],[.8,.75]];ye.slice(0,4).forEach((tt,mt)=>{let Pt=tt.tiers[0].cost;j(`build:${tt.id}`,Ve[mt][0],Ve[mt][1],tt.tiers[0].art,Pt,String(Pt),p>=Pt);});return}let B=e.need(q,hr),de=Ar(B.kind),he=Qo(de,B.tier,B.branch||null);if(_e("m:range",_.x,_.y,{shape:"sprite",art:"aura_field",w:he.range*u*2,h:he.range*u*2,color:"primary",alpha:.4,depth:1}),B.tier<de.tiers.length){let ye=de.tiers[B.tier];j("up",0,-1,ye.art,ye.cost,String(ye.cost),p>=ye.cost);}else !B.branch&&n.branches&&de.branches.slice(0,2).forEach((ye,Ve)=>j(`branch:${ye.id}`,Ve===0?-0.85:.85,-0.7,ye.art,ye.cost,String(ye.cost),p>=ye.cost));let be=Math.floor(Yo(de,B.tier,B.branch||null)*Zo);j("sell",0,1,"td_sell",null,`+${be}`,true);},Ft=d=>{if(Ae===null)return;let u=Ae,w=false;if(d.startsWith("build:")?w=pt(u,d.slice(6)):d==="up"?w=yt(u):d.startsWith("branch:")?w=yt(u,d.slice(7)):d==="sell"&&(w=et(u)),!w){H(e,{kind:"shake",power:.3});return}Ze();},Ut=(d,u)=>{let w=J(),M=-1,v=1/0;return o.spots.forEach((b,_)=>{let A=ve(b),D=ft(_)!==void 0?A.y-w*1.1:A.y-w*.5;if(Math.abs(d-A.x)>w*.55||u<D||u>A.y+w*.55)return;let j=Math.abs(d-A.x)+Math.abs(u-A.y);j<v&&(v=j,M=_);}),M},R=d=>1+.07*(d-1),z=(d,u,w,M)=>{let v=ar(d);if(!v||a.length===0)return null;let b=v.hp*n.hp*(v.boss?1:R(M)),_=e.create();return e.set(_,Re,{kind:d,hp:b,maxHp:b,route:u%a.length,progress:w,x:0,y:0,slow:0,slowLeft:0,stun:0,burn:0,burnLeft:0,healCd:v.heals?.every??0,summonCd:v.summons?.every??0,heldBy:-1,enraged:false,wave:M}),e.set(_,G,{x:0,y:0}),e.set(_,te,{shape:"actor",cast:v.cast,variant:v.variant??s.int(0,99),h:J()*v.size*1.15,pose:v.flying?"air":"walk",depth:6}),y(_),v.boss&&(e.emit(uh,{kind:d}),H(e,{kind:"shake",power:1})),_},y=d=>{let u=e.need(d,Re),w=ar(u.kind),M=a[u.route],v=Me(M,u.progress),b=Me(M,u.progress+.05);u.x=v.x,u.y=v.y;let _=J(),A=e.need(d,G),D=e.need(d,te),j=Ee(v.y)+_*.2;if(A.x=Se(v.x),A.y=j-(w.flying?_*.55:0)-(D.shape==="actor"?D.h/2:0),D.shape==="actor"){Math.abs(b.x-v.x)>1e-4&&(D.facing=b.x>v.x?1:-1),D.depth=qt(e,j,5),D.h=_*w.size*1.15;let q=u.heldBy<0&&u.stun<=0;D.pose=w.flying?"air":q?"walk":"idle",D.speed=w.speed*(1-u.slow)*_*le;}},S=d=>a[d.route].len-d.progress,$=d=>{let u=e.need(d,G);return {x:u.x,y:u.y}},l=(d,u,w,M,v=1,b="tower")=>{let _=e.get(d,Re);if(!_)return;let A=ar(_.kind),D=u.damage*w*v*(M?2:1);if(u.type==="physical"?D*=1-A.armor*(1-(u.pierce??0)):u.type==="magic"&&(D*=1-A.resist),u.slow&&(_.slow=Math.max(_.slow,u.slow*(A.boss?.5:1)),_.slowLeft=Math.max(_.slowLeft,(u.slowTime??1)*w)),u.burn&&(_.burn=Math.max(_.burn,u.burn*w),_.burnLeft=Math.max(_.burnLeft,u.burnTime??2)),u.stun&&!A.boss&&s.chance(u.stun)&&(_.stun=Math.max(_.stun,u.stunTime??.5)),M){let j=$(d);H(e,{kind:"pop",x:j.x,y:j.y-J()*.5,text:String(Math.round(D)),color:"danger",size:Math.round(J()*.3)});}h(d,D,b);},h=(d,u,w)=>{let M=e.get(d,Re);M&&(M.hp-=u,M.hp<=0&&m(d,w));},m=(d,u)=>{let w=e.need(d,Re),M=ar(w.kind);e.remove(d,Re),ot(e,d,"die"),mn(e,d,1),ne++;let v=Math.round(M.bounty*n.bounty);wt(p+v);let b=$(d);if(H(e,{kind:"pop",x:b.x,y:b.y-J()*.6,text:`+${v}`,color:"coin",size:Math.round(J()*.28)}),e.emit("enemy-defeated",{kind:w.kind,by:u}),M.boss?(V++,Ke(e,"coins",10),e.emit(mh,{kind:w.kind}),H(e,{kind:"shake",power:1.4}),H(e,{kind:"flash",color:"coin"})):s.chance(r("coinRate"))&&(Ke(e,"coins",1),e.emit("coin-collected",{value:1})),M.splits)for(let _=0;_<M.splits.count;_++)z(M.splits.into,w.route,Math.max(0,w.progress-.18*_),w.wave);},g=d=>{let u=e.need(d,Re),w=ar(u.kind),M=ve(o.gate);H(e,{kind:"burst",x:M.x,y:M.y,color:"danger",n:12,size:J()}),e.destroy(d),x=Math.max(0,x-w.leak),e.vars.lives=x,e.emit("player-hit",{lives:x}),H(e,{kind:"flash",color:"danger"}),H(e,{kind:"shake",power:w.boss?1.6:.8}),x<=0&&Z();},T=()=>{if(!(L>=n.waves.length)){L++,e.vars.wave=L,O=[];for(let d of n.waves[L-1].groups)for(let u=0;u<d.count;u++)O.push({at:d.delay+u*d.gap,enemy:d.enemy,entry:d.entry});O.sort((d,u)=>d.at-u.at),C=0,I=null,e.emit(Al,{wave:L});}},N=()=>{if(!(I===null||L>=n.waves.length)){if(L>0){let d=Math.ceil(I*r("earlyGold")*n.bounty);if(d>0){wt(p+d);let u=ke.find(w=>w.id.startsWith("call"));u&&H(e,{kind:"pop",x:u.x,y:u.y-J()*.6,text:`+${d}`,color:"coin",size:Math.round(J()*.32)});}}$t(e,"td-call"),T();}},P=d=>{if(ce||!rt(e))return;ce=true;let u=d==="defended",w=u?Math.min(oe?1:3,vi(x,E)):0;e.vars.stars=w,u&&e.vars["meta:first_clear"]===true&&Ke(e,"coins",n.firstClearGold),e.vars.score=re()+(u?1e3+w*300:0),e.vars.reviving=false,Ze(),e.emit(Bt,{reason:d,stats:{chapter:n.level,seconds:Math.floor(K),cleared:u,stars:w,coins:Number(e.vars.coins??0),bosses:V,kills:ne,lives:x}});},Z=()=>{if(e.vars.revive_ready===true&&!oe){e.vars.reviving=true,Ze(),e.emit(Kt,{});return}P("overrun");},ie=()=>{if(Y()){oe=true,e.vars.reviving=false,x=$i,e.vars.lives=x;for(let d of e.query(Re))e.need(d,Re).stun=2;H(e,{kind:"flash",color:"coin"});}},re=()=>ne*10+x*50+Math.max(0,L-1)*100,Ie=()=>1+es(e,"meta:spells"),Ce=(d,u,w)=>{let M=lo.find(_=>_.id===d);if(!M||(ge.get(d)??0)>0)return;let v=Pe(u,w);if(v.x<-0.5||v.y<-0.5||v.x>Dr+.5||v.y>Tr+.5)return;if(M.kind==="strike")for(let _=0;_<(M.count??1);_++){let A=e.create(),D=(M.radius??1)*.9;e.set(A,Mi,{x:v.x+(_===0?0:(s.next()-.5)*D*2),y:v.y+(_===0?0:(s.next()-.5)*D*2),t:0,delay:_*.2,damage:(M.damage??1)*n.hp*Ie(),radius:M.radius??1,burn:(M.burn??0)*n.hp*Ie()}),e.set(A,G,{x:-999,y:-999}),e.set(A,te,{shape:"sprite",art:"td_meteor",w:J()*.9,h:J()*.9,alpha:0,depth:45});}else {let _={route:0,q:0,d:1/0};a.forEach((D,j)=>{for(let q=.5;q<=D.len-.5;q+=.25){let B=Me(D,q),de=Math.hypot(B.x-v.x,B.y-v.y);de<_.d&&(_={route:j,q,d:de});}});let A=M.count??1;for(let D=0;D<A;D++){let j=e.create(),q=(M.hp??3)*n.hp*Ie();e.set(j,$r,{hp:q,maxHp:q,dps:(M.dps??.5)*n.hp*Ie(),left:M.time??12,route:_.route,progress:Math.max(.3,Math.min(a[_.route].len-.3,_.q+(D-(A-1)/2)*.45)),swing:0}),e.set(j,G,{x:0,y:0}),e.set(j,te,{shape:"actor",cast:M.cast??"helper",variant:s.int(0,99),h:J()*.85,pose:"idle",depth:6}),De(j);let B=e.need(j,G);H(e,{kind:"ring",x:B.x,y:B.y,color:"accent",size:J()*1.2});}}let b=M.cooldown*(ze().perk==="spells"?.7:1);ge.set(d,b),we=null,pe!==null&&e.isAlive(pe)&&Ge(e,pe,"attack"),e.emit("spell-cast",{id:d});},De=d=>{let u=e.need(d,$r),w=a[u.route],M=Me(w,u.progress),v=Me(w,u.progress-.2),b=J(),_=e.need(d,G),A=e.need(d,te),D=Ee(M.y)+b*.2;_.x=Se(M.x),_.y=D-(A.shape==="actor"?A.h/2:0),A.shape==="actor"&&(Math.abs(v.x-M.x)>1e-4&&(A.facing=v.x>M.x?1:-1),A.depth=qt(e,D,5),A.h=b*.85);},F=()=>{(pe===null||!e.isAlive(pe))&&(pe=e.create());let d=J(),u=o.gate,w=[[1,0],[-1,0],[0,-1],[0,1]].map(([b,_])=>({col:u.col+b,row:u.row+_})).find(b=>b.col>=0&&b.row>=0&&b.col<Dr&&b.row<Tr&&".tr*".includes(o.rows[b.row][b.col]))??u,M=ve(w),v=M.y+d*.35;e.set(pe,G,{x:M.x,y:v-d*.6}),e.set(pe,te,{shape:"actor",cast:ze().cast,h:d*1.2,pose:"idle",facing:w.col>u.col?-1:1,depth:qt(e,v,5)});},ae=()=>{if(xt(e,"td-build")||o.spots.length===0)return;let d=a[0],u=Me(d,d.len*.4),w=0,M=1/0;o.spots.forEach((v,b)=>{let _=Math.hypot(v.col+.5-u.x,v.row+.5-u.y);_<M&&(M=_,w=b);}),bt(e,"tap",ve(o.spots[w]),void 0,J()*1.2);},Oe=()=>{if(xt(e,"td-call")||L>0)return;let d=ve(o.paths[0][0]);bt(e,"tap",d,void 0,J()*1.2);},me=()=>{let d=Ne(e),u=Math.min(d.w,d.h),w=J(),M=d.h*.085,v=u*.05,b=(B,de,he,be,ye="text",Ve=u*.042)=>_e(B,de,he,{shape:"text",text:be,size:Math.round(Ve),color:ye,bold:true,depth:70});_e("h:lives:i",d.w*.07,M,{shape:"sprite",art:"heart",w:v,h:v,depth:70}),b("h:lives",d.w*.15,M,String(x),x<=5?"danger":"text"),_e("h:gold:i",d.w*.3,M,{shape:"sprite",art:"td_gold",w:v*1.15,h:v,depth:70}),b("h:gold",d.w*.4,M,String(p),"coin"),_e("h:wave:i",d.w*.56,M,{shape:"sprite",art:"td_call",w:v,h:v,depth:70}),b("h:wave",d.w*.66,M,`${L}/${n.waves.length}`),_e("h:coin:i",d.w*.8,M,{shape:"sprite",art:"coin",w:v*.9,h:v*.9,depth:70}),b("h:coin",d.w*.89,M,String(e.vars.coins??0));let _=d.h*.125,A=e.query(Re).find(B=>ar(e.need(B,Re).kind)?.boss);if(A!==void 0){let B=e.need(A,Re),de=d.w*.55,he=Math.max(10,u*.022);_e("h:n:boss:bg",d.w/2,_,{shape:"rect",w:de,h:he,color:"#000000",alpha:.5,radius:he/2,depth:69});let be=Math.max(1,(de-4)*Math.max(0,B.hp/B.maxHp));_e("h:n:boss:fill",d.w/2-(de-4)/2+be/2,_,{shape:"rect",w:be,h:he-4,color:"danger",radius:(he-4)/2,depth:69.1}),_e("h:n:boss:i",d.w/2-de/2-v*.7,_,{shape:"sprite",art:"skull",w:v,h:v,depth:70});}else if(I!==null&&L<n.waves.length){let B=new Map;for(let ye of n.waves[L].groups)B.set(ye.enemy,(B.get(ye.enemy)??0)+ye.count);let de=[...B].slice(0,5),he=u*.15,be=d.w/2-(de.length-1)*he/2;de.forEach(([ye,Ve],tt)=>{let mt=ar(ye),Pt=be+tt*he;_e(`h:n:${ye}:a`,Pt-v*.4,_+v*.1,{shape:"actor",cast:mt.cast,variant:mt.variant??1,h:v*1.5*Math.min(1.3,mt.size+.25),pose:mt.flying?"air":"idle",depth:70}),b(`h:n:${ye}:t`,Pt+v*.55,_+v*.1,`\xD7${Ve}`,mt.boss?"danger":"text",u*.034);});}if(ke=[],I!==null&&L<n.waves.length){let B=L===0?1+.08*Math.sin(e.time*6):1;o.paths.forEach((de,he)=>{let be=ve(de[0]),ye=w*.42;ke.push({id:`call:${he}`,x:be.x,y:be.y,r:ye*1.2}),_e(`b:call:${he}:bg`,be.x,be.y,{shape:"circle",r:ye,color:"danger",alpha:.92,depth:65},B),_e(`b:call:${he}:i`,be.x,be.y,{shape:"sprite",art:"td_call",w:ye*1.3,h:ye*1.3,depth:65.1},B),_e(`b:call:${he}:t`,be.x,be.y+ye*1.25,{shape:"text",text:String(Math.ceil(I??0)),size:Math.round(w*.26),color:"text",bold:true,depth:65.2});});}let D=d.h*.925,j=u*.065;lo.filter(B=>n.spells.includes(B.id)).forEach((B,de)=>{let he=d.w*.12+de*j*2.6,be=ge.get(B.id)??0;ke.push({id:`spell:${B.id}`,x:he,y:D,r:j*1.15}),we===B.id&&_e(`b:s:${B.id}:rim`,he,D,{shape:"circle",r:j*1.18,color:"coin",alpha:.6+.4*Math.sin(e.time*8),depth:64.9}),_e(`b:s:${B.id}:bg`,he,D,{shape:"circle",r:j,color:"panel",alpha:.92,depth:65}),_e(`b:s:${B.id}:i`,he,D,{shape:"sprite",art:B.icon,w:j*1.25,h:j*1.25,alpha:be>0?.4:1,depth:65.1}),be>0&&_e(`b:s:${B.id}:t`,he,D,{shape:"text",text:String(Math.ceil(be)),size:Math.round(j*.8),color:"text",bold:true,depth:65.2});});let q=d.w*.88;ke.push({id:"speed",x:q,y:D,r:j*1.15}),_e("b:speed:bg",q,D,{shape:"circle",r:j,color:le>1?"coin":"panel",alpha:.92,depth:65}),e.vars.td_buttons=ut(ke),_e("b:speed:t",q,D,{shape:"text",text:`x${le}`,size:Math.round(j*.75),color:le>1?"panel":"text",bold:true,depth:65.1});},ue=()=>{let d=J(),u=new Set,w=(M,v,b,_,A)=>{u.add(M);let D=Be.get(M);if(!D){D=[e.create(),e.create(),e.create(),e.create(),e.create()];for(let[Pt,Or]of D.entries())e.set(Or,zd,{of:M,part:String(Pt)});Be.set(M,D);}let j=e.need(M,G),q=e.need(M,te),B=q.shape==="actor"?q.h:d,de=j.y-B/2-d*.08,he=Math.min(Ne(e).w,Ne(e).h),be=Math.max(d*.62,he*.065),ye=Math.max(5,be*.13),Ve=v<.999;e.set(D[0],G,{x:j.x,y:de}),e.set(D[0],te,{shape:"rect",w:be,h:ye,color:"#000000",alpha:Ve?.55:0,radius:ye/2,depth:30});let tt=Math.max(1,(be-2)*Math.max(0,v));e.set(D[1],G,{x:j.x-(be-2)/2+tt/2,y:de}),e.set(D[1],te,{shape:"rect",w:tt,h:ye-2,color:b,alpha:Ve?1:0,radius:(ye-2)/2,depth:30.1}),e.set(D[2],G,{x:j.x-be/2-d*.12,y:de}),e.set(D[2],te,{shape:"sprite",art:_??"shield",w:d*.24,h:d*.24,alpha:_?1:0,depth:30.2});let mt=j.y+B/2;e.set(D[3],G,{x:j.x,y:mt}),e.set(D[3],te,{shape:"sprite",art:"aura_field",w:d*.75,h:d*.32,color:"primary",alpha:A?.slow?.75:0,depth:2}),e.set(D[4],G,{x:j.x,y:j.y}),e.set(D[4],te,{shape:"sprite",art:"burst",w:d*.45,h:d*.45,color:"danger",alpha:A?.burn?.5+.4*Math.sin(e.time*20):0,depth:29});};for(let M of e.query(Re)){let v=e.need(M,Re);w(M,v.hp/v.maxHp,"danger",ar(v.kind)?.badge,{slow:v.slowLeft>0,burn:v.burnLeft>0});}for(let M of e.query($r)){let v=e.need(M,$r);w(M,v.hp/v.maxHp,"accent",void 0,null);}for(let[M,v]of [...Be])if(!u.has(M)){for(let b of v)e.destroy(b);Be.delete(M);}},Q=()=>{for(let d of [hr,Re,wn,$r,Mi,Ei,zd,Rl])at(e,d);Te.clear(),Be.clear();for(let d of e.query(te))e.need(d,te).shape==="actor"&&d!==pe&&!e.has(d,Rl)&&e.destroy(d);},i=()=>{Q(),n=po(es(e,"meta:chapter")||1,r("difficulty")),o=fo(co(ki(n.map),n.mirror)),se(),Ot(e,"top"),c=Le(),Ye(),p=0,wt((n.gold+r("gold")+es(e,"meta:start_gold"))*(ze().perk==="gold"?1.25:1)),E=r("lives")+es(e,"meta:lives"),x=E,L=0,O=[],C=0,I=r("firstWait"),K=0,ne=0,V=0,ce=false,oe=false,le=1,Ae=null,xe=[],we=null,ge.clear(),ke=[],e.vars.lives=x,e.vars.wave=0,e.vars.waves=n.waves.length,e.vars.td_level=n.level,e.vars.td_world=n.world,e.vars.coins=0,e.vars.score=0,e.vars.stars=0,e.vars.reviving=false,e.vars.td_speed=1,e.vars.level_progress=0,F();},f=d=>{if(d.startsWith("call"))N();else if(d==="speed")le=le>1?1:2,e.vars.td_speed=le;else if(d.startsWith("spell:")){let u=d.slice(6);we===u?we=null:(ge.get(u)??0)<=0&&(we=u,Ze());}};e.on(Tt,d=>{let u=d;if(u.type!=="tap"||!rt(e)||tn(e)||ce||Y())return;if(Ae!==null){let v=xe.find(b=>Math.hypot(u.x-b.x,u.y-b.y)<=b.r);if(v){Ft(v.action);return}Ze();}let w=ke.find(v=>Math.hypot(u.x-v.x,u.y-v.y)<=v.r);if(w){f(w.id);return}if(we!==null){Ce(we,u.x,u.y);return}let M=Ut(u.x,u.y);M>=0&&(xt(e,"td-build")||Ct(e),gt(M));}),e.on(Ht,()=>{i(),e.vars.level=n.level,ae();}),e.on(Gt,i),e.on(Zt,ie),e.on(Qt,()=>{Y()&&(e.vars.reviving=false,P("overrun"));}),e.on(Vt,d=>{Ze(),dt("b:"),ke=[],pe!==null&&e.isAlive(pe)&&ot(e,pe,d.reason==="defended"?"dance":"die");for(let u of e.query(Re))ot(e,u,"idle");}),e.on(jt,()=>{Ot(e,"top"),c=Le(),Ye();for(let d of e.query(hr))qe(d);at(e,wn),Ae!==null&&Wt(),F();}),e.addSystem({id:"tower-defense",order:0,run(d,u){if(!rt(d)||ce||Y())return;let w=u*le;K+=u;let M=J();for(let[v,b]of ge)b>0&&ge.set(v,Math.max(0,b-w));if(O.length>0){for(C+=w;O.length>0&&O[0].at<=C;){let v=O.shift();z(v.enemy,v.entry,0,L);}O.length===0&&L<n.waves.length&&(I=r("wavePause"));}else I!==null&&(I-=w,I<=0&&T());for(let v of d.query($r)){let b=d.need(v,$r);if(b.left-=w,b.left<=0||b.hp<=0){d.remove(v,$r),ot(d,v,"die"),mn(d,v,.8);for(let D of d.query(Re))d.need(D,Re).heldBy===v&&(d.need(D,Re).heldBy=-1);continue}let _=Me(a[b.route],b.progress),A=d.query(Re).filter(D=>d.need(D,Re).heldBy===v);if(A.length<2){let D=d.query(Re).filter(j=>{let q=d.need(j,Re),B=ar(q.kind);return q.heldBy<0&&!B.flying&&!B.boss&&Math.hypot(q.x-_.x,q.y-_.y)<=gh}).slice(0,2-A.length);for(let j of D)d.need(j,Re).heldBy=v,A.push(j);}A.length>0&&(h(A[0],b.dps*w,"soldier"),b.swing-=w,b.swing<=0&&(Ge(d,v,"attack"),b.swing=.6)),De(v);}for(let v of d.query(Re)){let b=d.get(v,Re);if(!b)continue;let _=ar(b.kind);if(!(b.burnLeft>0&&(b.burnLeft-=w,h(v,b.burn*w,"burn"),!d.has(v,Re)))){if(b.slowLeft>0&&(b.slowLeft-=w,b.slowLeft<=0&&(b.slow=0)),b.stun>0&&(b.stun-=w),_.heals&&(b.healCd-=w,b.healCd<=0)){b.healCd=_.heals.every;for(let D of d.query(Re)){let j=d.need(D,Re);Math.hypot(j.x-b.x,j.y-b.y)>_.heals.radius||(j.hp=Math.min(j.maxHp,j.hp+j.maxHp*_.heals.share));}let A=$(v);H(d,{kind:"ring",x:A.x,y:A.y,color:"accent",size:_.heals.radius*M*2});}if(_.summons&&(b.summonCd-=w,b.summonCd<=0)){b.summonCd=_.summons.every;for(let A=0;A<_.summons.count;A++)z(_.summons.id,b.route,Math.max(0,b.progress-.45*(A+1)),b.wave);Ge(d,v,"cheer");}if(_.enrage&&!b.enraged&&b.hp<b.maxHp*_.enrage.below){b.enraged=true;let A=$(v);H(d,{kind:"ring",x:A.x,y:A.y,color:"danger",size:M*2});}if(b.heldBy>=0&&!d.has(b.heldBy,$r)&&(b.heldBy=-1),b.heldBy<0&&b.stun<=0&&(b.progress+=_.speed*(1-b.slow)*(b.enraged&&_.enrage?_.enrage.speed:1)*w),b.progress>=a[b.route].len){if(g(v),ce||Y())return;continue}y(v);}}for(let v of d.query(hr)){let b=d.need(v,hr);if(b.cooldown-=w,b.cooldown>0)continue;let _=Ar(b.kind),A=Qo(_,b.tier,b.branch||null),D=1+es(d,_.metaVar),j=o.spots[b.spot],q=j.col+.5,B=j.row+.5,de=d.query(Re).filter(be=>{let ye=d.need(be,Re);return (ar(ye.kind).flying?A.air:A.ground)&&ye.progress>0&&Math.hypot(ye.x-q,ye.y-B)<=A.range}).sort((be,ye)=>S(d.need(be,Re))-S(d.need(ye,Re))).slice(0,A.multishot??1);if(de.length===0){b.cooldown=0;continue}b.cooldown=1/A.rate;let he={x:Se(q),y:Ee(B)-M*.75};for(let be of de){let ye=A.crit!==void 0&&s.chance(A.crit);if(A.beam){let Or=[],Er=he,mr=be,Zr=1;for(let Rn=0;Rn<=(A.chain??0)&&mr!==void 0;Rn++){let ec=$(mr);k(Er,ec,A.type==="magic"?"secondary":"primary"),Or.push(mr);let An=d.need(mr,Re),lf=d.query(Re).filter(Dn=>!Or.includes(Dn)&&Math.hypot(d.need(Dn,Re).x-An.x,d.need(Dn,Re).y-An.y)<=1.6).sort((Dn,tc)=>Math.hypot(d.need(Dn,Re).x-An.x,d.need(Dn,Re).y-An.y)-Math.hypot(d.need(tc,Re).x-An.x,d.need(tc,Re).y-An.y))[0];l(mr,A,D,ye,Zr),Er=ec,mr=lf,Zr*=.7;}continue}let Ve=$(be),tt=d.create(),mt=Math.max(1,Math.hypot(Ve.x-he.x,Ve.y-he.y));d.set(tt,wn,{target:be,x:he.x,y:he.y,ax:Ve.x,ay:Ve.y,dist0:mt,went:0,stats:A,power:D,crit:ye}),d.set(tt,G,{x:he.x,y:he.y});let Pt=A.shot==="td_arrow"?{w:M*.55,h:M*.18}:A.lob?{w:M*.34,h:M*.34}:{w:M*.3,h:M*.3};d.set(tt,te,{shape:"sprite",art:A.shot,...Pt,...A.burn?{color:"danger"}:A.slow?{color:"primary"}:A.type==="magic"?{color:"secondary"}:{},depth:40});}}for(let v of d.query(wn)){let b=d.need(v,wn);if(d.has(b.target,Re)){let B=$(b.target);b.ax=B.x,b.ay=B.y;}let _=b.ax-b.x,A=b.ay-b.y,D=Math.hypot(_,A),j=b.stats.shotSpeed*M*w,q=d.need(v,G);if(D>j){b.x+=_/D*j,b.y+=A/D*j,b.went+=j;let B=Math.min(1,b.went/b.dist0);q.x=b.x,q.y=b.y-(b.stats.lob?Math.sin(Math.PI*B)*M*.9:0),q.rotation=b.stats.lob?(q.rotation??0)+w*8:Math.atan2(A,_);continue}if(d.destroy(v),b.stats.splash){let B=Pe(b.ax,b.ay);H(d,{kind:"burst",x:b.ax,y:b.ay,color:b.stats.burn?"danger":b.stats.slow?"primary":"coin",n:12,size:b.stats.splash*M*1.6}),b.stats.lob&&H(d,{kind:"shake",power:.25});for(let de of d.query(Re)){let he=d.need(de,Re),be=ar(he.kind);(be.flying?b.stats.air:b.stats.ground)&&Math.hypot(he.x-B.x,he.y+(be.flying?-0.55:0)-B.y)<=b.stats.splash&&l(de,b.stats,b.power,b.crit);}}else d.has(b.target,Re)&&(H(d,{kind:"burst",x:b.ax,y:b.ay,color:b.stats.type==="magic"?"secondary":"coin",n:5,size:M*.5}),l(b.target,b.stats,b.power,b.crit));if(ce||Y())return}for(let v of d.query(Mi)){let b=d.need(v,Mi);b.t+=w;let _=(b.t-b.delay)/yh,A=d.need(v,G),D=d.need(v,te);if(_<0)continue;if(_<1){let q=Ne(d).h;A.x=Se(b.x)+(1-_)*M*2,A.y=Ee(b.y)-(1-_)*q*.5,A.rotation=-0.9,D.shape==="sprite"&&(D.alpha=1);continue}d.destroy(v),H(d,{kind:"burst",x:Se(b.x),y:Ee(b.y),color:"danger",n:20,size:b.radius*M*2}),H(d,{kind:"ring",x:Se(b.x),y:Ee(b.y),color:"coin",size:b.radius*M*2.2}),H(d,{kind:"shake",power:.8});let j={damage:b.damage,type:"true",...b.burn>0?{burn:b.burn,burnTime:2}:{}};for(let q of d.query(Re)){let B=d.need(q,Re);Math.hypot(B.x-b.x,B.y-b.y)<=b.radius&&l(q,j,1,false,1,"spell");}if(ce||Y())return}for(let v of d.query(Ei)){let b=d.need(v,Ei);b.life-=u,b.life<=0&&d.destroy(v);}if(L>=n.waves.length&&O.length===0&&d.query(Re).length===0){P("defended");return}d.vars.level_progress=n.waves.length>0?Math.min(1,(L-(O.length>0||d.query(Re).length>0?.5:0))/n.waves.length):0,d.vars.score=re(),lt.clear(),Ae!==null&&Wt(),ue(),me(),ct(["m:","h:","b:"]);}});let k=(d,u,w)=>{let M=Math.hypot(u.x-d.x,u.y-d.y),v=e.create();e.set(v,Ei,{life:.16}),e.set(v,G,{x:(d.x+u.x)/2,y:(d.y+u.y)/2,rotation:Math.atan2(u.y-d.y,u.x-d.x)}),e.set(v,te,{shape:"sprite",art:"zap",w:Math.max(8,M),h:J()*.22,color:w,depth:41});};se(),i();}};var ts=[{id:"lemon",art:"biz1",color:"coin",cost:4,income:1,cycle:1,growth:1.07,manager:60},{id:"bakery",art:"biz2",color:"accent",cost:50,income:17,cycle:2,growth:1.1,manager:600},{id:"cafe",art:"biz3",color:"secondary",cost:600,income:225,cycle:3,growth:1.11,manager:7e3},{id:"workshop",art:"biz4",color:"primary",cost:7e3,income:2800,cycle:4,growth:1.11,manager:8e4},{id:"cinema",art:"ty_cinema",color:"danger",cost:8e4,income:4e4,cycle:6,growth:1.11,manager:1e6},{id:"hotel",art:"biz6",color:"secondary",cost:9e5,income:51e4,cycle:8,growth:1.11,manager:11e6},{id:"bank",art:"biz5",color:"coin",cost:1e7,income:62e5,cycle:10,growth:1.11,manager:12e7},{id:"port",art:"ty_port",color:"primary",cost:12e7,income:8e7,cycle:12,growth:1.11,manager:15e8}],Ln=e=>ts.find(t=>t.id===e),rs=[{at:10,speed:2},{at:25,speed:2},{at:50,speed:2},{at:75,income:3},{at:100,speed:2},{at:150,income:3}],_i=.1,Ri=[{id:"double",scope:"one",art:"ty_up",mult:2,price:60,after:5},{id:"triple",scope:"one",art:"ty_up3",mult:3,price:2500,after:25},{id:"all",scope:"all",art:"ty_upall",mult:2,price:40,after:15}],ns=[{id:"rush",art:"ty_rush",effect:"rush",weight:3,ttl:7,mult:3,seconds:10},{id:"break",art:"ty_wrench",effect:"break",weight:2,ttl:99,taps:3},{id:"invest",art:"ty_investor",effect:"invest",weight:1,ttl:9,now:25,mult:2,seconds:30},{id:"courier",art:"chest",effect:"courier",weight:2,ttl:6,now:15,coins:2}],Nd=e=>ns.find(t=>t.id===e),Dl=[11,18],Tl=[{id:"rush",art:"ty_sk_rush",charge:30,effect:"rush",mult:5,seconds:12},{id:"instant",art:"ty_sk_instant",charge:26,effect:"instant",cycles:8},{id:"sale",art:"ty_sk_sale",charge:28,effect:"sale",mult:.5,seconds:15}],Ai=e=>Tl.find(t=>t.id===e),Wd=.4,jd=3,mo=[{id:"hero",cast:"hero",gems:0,skill:"rush"},{id:"hero2",cast:"hero2",gems:150,skill:"instant"},{id:"hero3",cast:"hero3",gems:300,skill:"sale"}];var Hd={l:"lemon",b:"bakery",c:"cafe",w:"workshop",n:"cinema",h:"hotel",k:"bank",p:"port"},bh={r:"rush",b:"break",i:"invest",c:"courier"},He=(e,t,r="",s)=>({businesses:[...e].map(n=>Hd[n]??"lemon"),goals:t,events:[...r].map(n=>bh[n]??"rush"),...{}}),Li=e=>({...e,vip:true}),Xe=e=>({kind:"cash",n:e}),St=(e,t)=>({kind:"level",biz:Hd[e]??"lemon",n:t}),rr=e=>({kind:"managers",n:e}),_n=[He("lb",[Xe(5200)]),He("lb",[St("l",25),Xe(62e3)]),He("lbc",[Xe(17e3)],"r"),He("lbc",[rr(2),Xe(34e3)],"r"),He("lbc",[St("b",25),Xe(51e3)],"rc"),He("lbcw",[Xe(21e4)],"rc"),He("lbcw",[St("c",25),rr(2)],"rc"),He("lbcw",[rr(3),Xe(46e4)],"rc"),He("lbcw",[St("w",10),Xe(1e6)],"rc"),Li(He("lbcw",[St("c",25),rr(4),Xe(5e6)],"rc")),He("bcw",[Xe(73e3)],"rb"),He("bcw",[St("c",25),Xe(17e4)],"rcb"),He("bcwn",[Xe(2e5)],"rcb"),He("bcwn",[rr(2),Xe(42e4)],"rcb"),He("bcwn",[St("n",5),Xe(97e4)],"rcb"),He("bcwn",[St("w",25),Xe(24e5)],"rcb"),He("bcwn",[rr(3),Xe(19e5)],"rcb"),He("bcwn",[St("c",50),Xe(32e5)],"rcb"),He("bcwn",[St("n",10),rr(3)],"rcb"),Li(He("bcwn",[St("n",10),rr(4),Xe(64e6)],"rcb")),He("cwn",[Xe(12e5)],"rcbi"),He("cwn",[St("w",25),Xe(2e6)],"rcbi"),He("cwnh",[Xe(27e5)],"rcbi"),He("cwnh",[rr(2),Xe(32e5)],"rcbi"),He("cwnh",[St("h",5),Xe(16e6)],"rcbi"),He("cwnh",[St("n",25),Xe(26e6)],"rcbi"),He("cwnh",[rr(3),Xe(15e6)],"rcbi"),He("cwnh",[St("w",50),Xe(42e6)],"rcbi"),He("cwnh",[St("h",10),rr(3)],"rcbi"),Li(He("cwnh",[St("h",10),rr(4),Xe(26e7)],"rcbi")),He("wnhk",[Xe(12e6)],"rcbi"),He("wnhk",[St("h",10),Xe(36e6)],"rcbi"),He("wnhk",[rr(3),Xe(21e7)],"rcbi"),He("nhkp",[Xe(21e7)],"rcbi"),He("nhkp",[St("k",10),Xe(38e7)],"rcbi"),He("nhkp",[rr(2),Xe(42e7)],"rcbi"),He("nhkp",[St("p",5),Xe(27e8)],"rcbi"),He("nhkp",[St("k",25),Xe(32e8)],"rcbi"),He("nhkp",[St("p",10),rr(3)],"rcbi"),Li(He("nhkp",[St("p",10),rr(4),Xe(11e9)],"rcbi"))],yo=10,Bd=4,uo=_n.length,Ol=[0,18,45,75],Cl=e=>Ol[Math.ceil(Math.max(1,e)/yo)-1]??0,Di=e=>e>=.3?3:e>=.12?2:1,Ti=30,Vd=(e,t)=>Math.round((t?40:20)+(e-1)*2),Pl=(e,t)=>(t?120:50)+(e-1)*10,Il="kit-tycoon",zl=[{id:"StartCash",var:"meta:cash",art:"coin",color:"coin",perLevel:20,unit:"%",maxLevel:15,price:40,growth:.12},{id:"CycleSpeed",var:"meta:speed",art:"hourglass",color:"secondary",perLevel:3,unit:"%",maxLevel:15,price:45,growth:.12},{id:"Income",var:"meta:income",art:"ty_up",color:"accent",perLevel:5,unit:"%",maxLevel:20,price:40,growth:.12},{id:"Discount",var:"meta:discount",art:"ty_sk_sale",color:"primary",perLevel:2,unit:"%",maxLevel:15,price:50,growth:.12},{id:"SkillPower",var:"meta:skill",art:"ty_sk_rush",color:"secondary",perLevel:8,unit:"%",maxLevel:10,price:50,growth:.12}],Gd={game:"tycoon",character:Il,stats:zl,heroes:mo,levels:uo,firstClearGold:e=>Pl(e,_n[Math.max(1,Math.min(uo,e))-1]?.vip===true),stars:3,starsToEnter:Cl};var xh={income:0,speed:0,discount:0};function ss(e,t=xh,r){return {biz:e.businesses.map((n,o)=>({def:Ln(n)??ts[0],level:o===0?1:0,progress:0,ready:false,manager:false,mult:1,rush:0,rushMult:1,broken:0})),cash:r??Ud(e),earned:0,allMult:1,bought:new Set,timed:[],mods:t}}var Ud=e=>e.cash??(Ln(e.businesses[1]??e.businesses[0]??"lemon")?.cost??4)*2,kh=e=>e.timed.reduce((t,r)=>t*r.income,1),vh=e=>e.timed.reduce((t,r)=>t*r.price,1);function is(e){let t=1,r=1,s=0;for(let n of rs)e>=n.at?(t*=n.speed??1,r*=n.income??1):s===0&&(s=n.at);return {speed:t,income:r,next:s}}function dn(e,t){let r=is(t.level);return Math.max(_i,t.def.cycle/r.speed/(1+e.mods.speed))}function Mr(e,t,r=t.level){if(r<=0)return 0;let s=is(r),n=t.def.cycle/s.speed/(1+e.mods.speed),o=n<_i?_i/n:1;return t.def.income*r*s.income*o*t.mult*e.allMult*(1+e.mods.income)*(t.rush>0?t.rushMult:1)*kh(e)}var Oi=(e,t)=>t.level<=0||t.broken>0?0:Mr(e,t)/dn(e,t),Ci=e=>e.biz.reduce((t,r)=>t+Oi(e,r),0),os=e=>Math.max(.1,1-Math.min(.9,e.mods.discount))*vh(e);function fn(e,t,r=1){let s=t.def.growth,n=t.def.cost*Math.pow(s,t.level),o=r<=1?n:n*(Math.pow(s,r)-1)/(s-1);return Math.ceil(o*os(e))}function Wl(e,t,r=1e3){let s=t.def.growth,n=t.def.cost*Math.pow(s,t.level)*os(e);if(e.cash<n)return 0;let o=Math.floor(Math.log(e.cash*(s-1)/n+1)/Math.log(s)),a=Math.max(1,Math.min(r,o));for(;a>1&&fn(e,t,a)>e.cash;)a--;return fn(e,t,a)<=e.cash?a:0}var go=(e,t)=>Math.ceil(t.def.manager*os(e));function Pi(e,t,r=1){let s=e.biz[t];if(!s||r<1)return {ok:false,milestones:[]};let n=fn(e,s,r);if(e.cash<n)return {ok:false,milestones:[]};e.cash-=n;let o=s.level;return s.level+=r,{ok:true,milestones:rs.filter(a=>o<a.at&&s.level>=a.at).map(a=>a.at)}}function Ii(e,t){let r=e.biz[t];if(!r||r.manager||r.level<=0)return false;let s=go(e,r);return e.cash<s?false:(e.cash-=s,r.manager=true,r.ready&&(r.ready=false,r.progress=0,as(e,Mr(e,r))),true)}var as=(e,t)=>{e.cash+=t,e.earned+=t;};function zi(e,t){let r=e.biz[t];if(!r||!r.ready)return 0;r.ready=false,r.progress=0;let s=Mr(e,r);return as(e,s),s}function Ni(e,t){let r=e.biz[t];return !r||r.broken<=0?false:(r.broken--,r.broken===0)}function jl(e,t){let r=0;for(let s of e.biz)s.level<=0||s.broken>0||(r+=Mr(e,s)*t);return as(e,r),r}var Hl=(e,t)=>as(e,t);function Wi(e,t){let r=e.timed.findIndex(s=>s.id===t.id);r>=0&&e.timed.splice(r,1),e.timed.push(t);}function ji(e,t){let r=[],s=[];e.biz.forEach((n,o)=>{if(n.rush>0&&(n.rush=Math.max(0,n.rush-t)),!(n.level<=0||n.ready||n.broken>0)&&(n.progress+=t/dn(e,n),!(n.progress<1)))if(n.manager){let a=Math.floor(n.progress);n.progress-=a;let c=Mr(e,n)*a;as(e,c),s.push({index:o,amount:c});}else n.progress=1,n.ready=true,r.push(o);});for(let n=e.timed.length-1;n>=0;n--){let o=e.timed[n];o.left-=t,o.left<=0&&e.timed.splice(n,1);}return {ready:r,paid:s}}function Bl(e){let t=[],r=e.biz.reduce((s,n)=>Math.max(s,n.def.cost),0);for(let s of Ri)s.scope==="all"?t.push({key:s.id,def:s,index:-1,price:Math.ceil(r*s.price*os(e))}):e.biz.forEach((n,o)=>t.push({key:`${s.id}:${n.def.id}`,def:s,index:o,price:Math.ceil(n.def.cost*s.price*os(e))}));return t}function Hi(e,t=3){return Bl(e).filter(r=>!e.bought.has(r.key)&&(r.index<0?(e.biz[0]?.level??0)>=r.def.after:(e.biz[r.index]?.level??0)>=r.def.after)).sort((r,s)=>r.price-s.price).slice(0,t)}function Bi(e,t){let r=Bl(e).find(s=>s.key===t);return !r||e.bought.has(t)||e.cash<r.price?false:(e.cash-=r.price,e.bought.add(t),r.index<0?e.allMult*=r.def.mult:e.biz[r.index].mult*=r.def.mult,true)}var Vi=e=>e.biz.filter(t=>t.manager).length;function qr(e,t){if(t.kind==="cash")return Math.min(1,e.earned/Math.max(1,t.n));if(t.kind==="managers")return Math.min(1,Vi(e)/Math.max(1,t.n));let r=e.biz.find(s=>s.def.id===t.biz);return Math.min(1,(r?.level??0)/Math.max(1,t.n))}var ls=(e,t)=>t.every(r=>qr(e,r)>=1),Gi=(e,t)=>t.length?t.reduce((r,s)=>r+qr(e,s),0)/t.length:1,Nl=(e,t)=>t.manager?1:dn(e,t)/(dn(e,t)+1.2);function Fi(e,t){let r=e.biz.findIndex(L=>L.broken>0);if(r>=0)return {kind:"fix",index:r};let s=null,n=Ci(e),o=(L,O,C)=>{if(C>e.cash+n*8)return;let I=O/Math.max(1,C);(!s||I>s.value)&&(s={move:L,value:I,price:C});},a=L=>t.some(O=>O.kind==="level"&&O.biz===L&&qr(e,O)<1),c=t.some(L=>L.kind==="managers"&&qr(e,L)<1),p=t.some(L=>L.kind==="cash"&&qr(e,L)<1);e.biz.forEach((L,O)=>{let C=Oi(e,L)*Nl(e,L),I={...L,level:L.level+1},ne=(Mr(e,I)/dn(e,I)*Nl(e,I)-C)*(L.level===0?3:1)*(a(L.def.id)?3:1);o({kind:"buy",index:O},ne+(a(L.def.id)&&!p?n*.05:0),fn(e,L)),L.level>0&&!L.manager&&o({kind:"hire",index:O},Oi(e,L)*(1-Nl(e,L))*1.6*(c?3:1)+(c?n*.05:0),go(e,L));});for(let L of Hi(e,6)){let O=L.index<0?n*(L.def.mult-1):Oi(e,e.biz[L.index])*(L.def.mult-1);o({kind:"upgrade",key:L.key},O,L.price);}let x=e.biz.map((L,O)=>({b:L,i:O})).filter(L=>L.b.ready).sort((L,O)=>Mr(e,O.b)-Mr(e,L.b))[0],E=s;return E&&E.price<=e.cash?E.move:x?{kind:"collect",index:x.i}:null}function Xd(e,t){return t?t.kind==="collect"?zi(e,t.index)>0:t.kind==="buy"?Pi(e,t.index).ok:t.kind==="hire"?Ii(e,t.index):t.kind==="fix"?Ni(e,t.index)||true:Bi(e,t.key):false}function qd(e,t={}){let r=ss(e,t.mods),s=.05,n=t.tapEvery??.4,o=t.max??900,a=0,c=0;for(;a<o;){if(ls(r,e.goals))return a;if(ji(r,s),a+=s,a>=c){let p=Fi(r,e.goals);p&&(Xd(r,p),c=a+n);}}return 1/0}var Fd=new Map;function Ui(e){let t=Fd.get(e);return t===void 0&&(t=qd(_n[e-1]),Fd.set(e,t)),t}function bo(e,t=.5){let r=Math.max(1,Math.min(uo,Math.floor(e))),s=_n[r-1],n=Math.ceil(r/yo),o=r-(n-1)*yo,a=Ui(r),c=(1.6-(n-1)*.08-o*.01)*(1.1-t*.2)*(s.extra??1),p=Math.max(45,Math.min(600,Math.ceil((Number.isFinite(a)?a:400)*c/5)*5));return {level:r,world:n,index:o,def:s,boss:s.vip===true,day:p,cash:Ud(s),coins:Vd(r,s.vip===true),firstClearGold:Pl(r,s.vip===true)}}var $h=$e("tycoon.part"),Vl=$e("tycoon.manager"),xo=(e,t)=>{let r=Number(e.vars[t]??0);return Number.isFinite(r)?r:0},ur=e=>{let t=Math.abs(e);for(let[r,s]of [[1e12,"T"],[1e9,"B"],[1e6,"M"],[1e3,"K"]])if(t>=r)return `${(e/r).toFixed(t>=r*100?0:1).replace(/\.0$/,"")}${s}`;return String(Math.floor(e))},Kd=new WeakMap,Zd=e=>Kd.get(e),cs=[1,10,0],Xi={id:"tycoon",version:2,engines:["phaser"],requires:["round"],params:{difficulty:{type:"number",default:.5,min:0,max:1},coinReward:{type:"number",default:1,min:0,max:10}},setup({world:e,params:t}){let r=l=>cr(t,l),s=e.rng.stream("tycoon"),n=bo(1,r("difficulty")),o=ss(n.def),a=new Map,c=new Map,p=null,x=[],E=0,L=0,O=0,C=0,I=0,K=false,ne=false,V=0,ce=null,oe=null,le=null,Ae=()=>mo.find(l=>l.id===e.vars["meta:hero"])??mo[0],xe=()=>Ai(Ae().skill),we=()=>e.vars.reviving===true,ge=()=>n.def.goals,ke=()=>{let l=Ne(e);return {...l,U:Math.min(l.w,l.h)}},pe=l=>{let h=ke(),m=Math.max(1,o.biz.length),g=h.h*.25,T=h.h*.81,N=Math.max(6,h.h*.012),P=Math.min((T-g-N*(m-1))/m,150,h.w*.26),Z=Math.min(h.w*.96,660),ie=g+(T-g-(m*P+(m-1)*N))/2;return {x:h.w/2,y:ie+l*(P+N)+P/2,w:Z,h:P}},Te=l=>{let h=pe(l);return {x:h.x-h.w/2+h.h*.56,y:h.y,size:h.h*.9}},Be=()=>ke().h*.9,ze=()=>{let l=ke();return Math.min(l.U*.075,l.h*.055)},Y=()=>{let l=ke(),h=oe?1-oe.left/oe.def.ttl:0;return {x:-l.w*.05+h*l.w*1.1,y:l.h*.21,r:l.U*.06}},Le=new Set,J=(l,h,m,g,T=1)=>{Le.add(l);let N=a.get(l);(N===void 0||!e.isAlive(N))&&(N=e.create(),e.set(N,$h,{id:l}),a.set(l,N)),e.set(N,G,{x:h,y:m,scale:T}),e.set(N,te,g);},Se=()=>{for(let[l,h]of [...a])Le.has(l)||(e.destroy(h),a.delete(l));},Ee=(l,h,m,g,T,N,P=70)=>J(l,h,m,{shape:"text",text:g,size:Math.max(9,Math.round(N)),color:T,bold:true,depth:P}),ve=(l,h,m,g,T,N,P,Z=2)=>{J(`${l}:bg`,h,m,{shape:"rect",w:g+4,h:T+4,color:"#000000",alpha:.4,radius:(T+4)/2,depth:Z});let ie=Math.max(1,g*Math.max(0,Math.min(1,N)));J(`${l}:fill`,h-g/2+ie/2,m,{shape:"rect",w:ie,h:T,color:P,radius:T/2,depth:Z+.1});},Pe=l=>x.push(l),Ue=l=>{let h=o.biz[l],m=cs[I]??1;return m===0?Math.max(1,Wl(o,h)):m},se=()=>{o.biz.forEach((l,h)=>{let m=pe(h),g=Te(h),T=l.level>0,N=l.def.color;J(`r${h}`,m.x,m.y,{shape:"sprite",art:"panel",w:m.w,h:m.h,color:"panel",depth:0}),l.rush>0&&J(`r${h}:rush`,g.x,g.y,{shape:"circle",r:g.size*.55,color:"coin",alpha:.35+.2*Math.sin(e.time*8),depth:.5});let P=l.ready?1+.06*Math.abs(Math.sin(e.time*6)):1;J(`r${h}:b`,g.x,g.y,{shape:"sprite",art:l.def.art,w:g.size,h:g.size,color:N,alpha:T?l.broken>0?.55:1:.35,depth:1},P),Pe({id:`biz${h}`,x:g.x,y:g.y,w:g.size,h:g.size});let Z=m.x-m.w*.12,ie=m.h*.2,re=is(l.level);if(Ee(`r${h}:lv`,Z,m.y-m.h*.26,T?`Lv ${l.level}${re.next?`/${re.next}`:""}`:"Lv 0","text",ie,2),T){Ee(`r${h}:inc`,Z,m.y+m.h*0,`+${ur(Mr(o,l))}`,"coin",ie*.95,2);let i=l.ready||dn(o,l)<=.15&&l.manager?1:l.progress;ve(`r${h}:bar`,Z,m.y+m.h*.28,m.w*.3,Math.max(6,m.h*.12),i,l.broken>0?"danger":N),l.ready&&!l.manager&&Ee(`r${h}:ok`,g.x+g.size*.36,g.y+g.size*.34,"$","coin",g.size*.3,3);}if(ce?.index===h){let i=1+.12*Math.sin(e.time*9);J(`r${h}:ev`,g.x+g.size*.32,g.y-g.size*.3,{shape:"sprite",art:ce.def.art,w:g.size*.5,h:g.size*.5,depth:4},i);}else l.broken>0&&(J(`r${h}:ev`,g.x+g.size*.3,g.y-g.size*.28,{shape:"sprite",art:"ty_wrench",w:g.size*.48,h:g.size*.48,depth:4},1+.08*Math.sin(e.time*10)),Ee(`r${h}:evn`,g.x+g.size*.3,g.y+g.size*.05,String(l.broken),"danger",g.size*.26,4.1));let Ie=m.x+m.w*.13,Ce=m.h*.27;if(T&&!l.manager){let i=go(o,l),f=o.cash>=i;J(`r${h}:m:bg`,Ie,m.y-m.h*.08,{shape:"circle",r:Ce,color:f?"secondary":"panel",alpha:f?.95:.7,depth:1}),J(`r${h}:m`,Ie,m.y-m.h*.08,{shape:"sprite",art:"ty_manager",w:Ce*1.7,h:Ce*1.7,alpha:f?1:.5,depth:1.2}),Ee(`r${h}:m:p`,Ie,m.y+m.h*.32,ur(i),f?"text":"muted",ie*.8,2),Pe({id:`mgr${h}`,x:Ie,y:m.y,w:Ce*2.2,h:m.h*.9});}let De=m.x+m.w/2-m.w*.14,F=m.w*.25,ae=m.h*.72,Oe=Ue(h),me=fn(o,l,Oe),ue=o.cash>=me;J(`r${h}:buy`,De,m.y,{shape:"sprite",art:"button",w:F,h:ae,color:ue?"accent":"panel",alpha:ue?1:.6,depth:1}),Ee(`r${h}:buy:n`,De,m.y-ae*.2,T?`+${Oe}`:"OPEN","text",ie*.9,2),J(`r${h}:buy:c`,De-F*.3,m.y+ae*.2,{shape:"sprite",art:"coin",w:ie*.8,h:ie*.8,depth:2}),Ee(`r${h}:buy:p`,De+F*.08,m.y+ae*.2,ur(me),ue?"coin":"muted",ie*.85,2),Pe({id:`buy${h}`,x:De,y:m.y,w:F,h:ae});let Q=c.get(h);if(l.manager&&(Q===void 0||!e.isAlive(Q))&&(Q=e.create(),e.set(Q,Vl,{index:h}),e.set(Q,te,{shape:"actor",cast:"helper",variant:h*13+5,h:m.h*.78,pose:"idle",facing:1,depth:2}),c.set(h,Q)),Q!==void 0&&e.isAlive(Q)){e.set(Q,G,{x:Ie,y:m.y+m.h*.02});let i=e.need(Q,te);i.shape==="actor"&&(i.h=m.h*.78);}});},Me=l=>l.kind==="cash"?"coin":l.kind==="managers"?"ty_manager":Ln(l.biz??"")?.art??"biz1",lt=l=>l.kind==="cash"?o.earned:l.kind==="managers"?Vi(o):o.biz.find(h=>h.def.id===l.biz)?.level??0,_e=()=>{let l=ke(),h=l.U,m=l.h*.09;J("h:t:i",l.w*.09,m,{shape:"sprite",art:"hourglass",w:h*.06,h:h*.06,depth:70}),Ee("h:t",l.w*.09+h*.09,m,ws(E),E<=15?"danger":"text",h*.05),J("h:c:i",l.w*.42,m,{shape:"sprite",art:"coin",w:h*.07,h:h*.07,depth:70}),Ee("h:c",l.w*.42+h*.13,m,ur(o.cash),"coin",h*.065);let g=h*.17;J("h:mode",l.w*.88,m,{shape:"sprite",art:"button",w:g,h:h*.08,color:"secondary",depth:70}),Ee("h:mode:t",l.w*.88,m,cs[I]===0?"MAX":`\xD7${cs[I]}`,"text",h*.042,70.1),Pe({id:"mode",x:l.w*.88,y:m,w:g,h:h*.09});let T=ge(),N=Math.min(l.w*.3,230),P=Math.max(30,l.h*.05),Z=l.h*.15;if(T.forEach((F,ae)=>{let Oe=l.w/2+(ae-(T.length-1)/2)*(N+h*.02),me=qr(o,F)>=1;J(`h:g${ae}`,Oe,Z,{shape:"sprite",art:"panel",w:N,h:P,color:me?"accent":"panel",depth:70}),J(`h:g${ae}:i`,Oe-N*.36,Z-P*.06,{shape:"sprite",art:Me(F),w:P*.75,h:P*.75,depth:70.1});let ue=lt(F),Q=me?"\u2713":F.kind==="cash"?`${ur(ue)}/${ur(F.n)}`:F.kind==="level"?`Lv ${ue}/${F.n}`:`${ue}/${F.n}`;Ee(`h:g${ae}:t`,Oe+N*.1,Z-P*.08,Q,"text",P*.36,70.1),ve(`h:g${ae}:bar`,Oe+N*.1,Z+P*.3,N*.62,Math.max(4,P*.1),qr(o,F),me?"accent":"coin",70.1);}),o.timed.forEach((F,ae)=>{let Oe=l.w*.9-ae*h*.16,me=F.id==="sale"?"ty_sk_sale":F.id==="invest"?"ty_investor":xe().art;J(`h:tm${ae}`,Oe-h*.04,l.h*.205,{shape:"sprite",art:me,w:h*.06,h:h*.06,depth:70}),Ee(`h:tm${ae}:t`,Oe+h*.035,l.h*.205,`${Math.ceil(F.left)}`,"secondary",h*.04);}),oe){let F=Y();J("h:courier",F.x,F.y+Math.sin(e.time*10)*F.r*.08,{shape:"sprite",art:oe.def.art,w:F.r*2,h:F.r*2,depth:72}),Pe({id:"courier",x:F.x,y:F.y,w:F.r*2.6,h:F.r*2.6});}let ie=Be(),re=ze(),Ie=l.w*.25,Ce=C>=xe().charge;Ce&&J("h:sk:glow",Ie,ie,{shape:"circle",r:re*1.28,color:"secondary",alpha:.5+.3*Math.sin(e.time*7),depth:68.9}),J("h:sk:bg",Ie,ie,{shape:"circle",r:re,color:"panel",alpha:.95,depth:69}),J("h:sk",Ie,ie,{shape:"sprite",art:xe().art,w:re*1.4,h:re*1.4,alpha:Ce?1:.45,depth:69.2}),ve("h:charge",Ie,ie+re*1.3,re*2,Math.max(5,re*.2),C/xe().charge,"secondary",69),Pe({id:"skill",x:Ie,y:ie,w:re*2.4,h:re*2.4}),Hi(o,3).forEach((F,ae)=>{let Oe=l.w*(.47+ae*.18),me=o.cash>=F.price;J(`h:u${ae}:bg`,Oe,ie,{shape:"circle",r:re,color:me?"accent":"panel",alpha:me?.95:.7,depth:69}),J(`h:u${ae}`,Oe,ie-re*.08,{shape:"sprite",art:F.def.art,w:re*1.5,h:re*1.5,alpha:me?1:.55,depth:69.2});let ue=F.index>=0?o.biz[F.index]:void 0;ue&&J(`h:u${ae}:b`,Oe+re*.7,ie-re*.6,{shape:"sprite",art:ue.def.art,w:re*.9,h:re*.9,color:ue.def.color,depth:69.3}),Ee(`h:u${ae}:p`,Oe,ie+re*1.3,ur(F.price),me?"coin":"muted",re*.42,69.3),Pe({id:`up:${F.key}`,x:Oe,y:ie,w:re*2.3,h:re*2.6});}),(p===null||!e.isAlive(p))&&(p=e.create(),e.set(p,te,{shape:"actor",cast:Ae().cast,h:re*2.6,pose:"idle",facing:1,depth:20})),e.set(p,G,{x:l.w*.09,y:ie-re*.1});let De=e.need(p,te);if(De.shape==="actor"&&(De.h=re*2.6),le){let F=Math.min(l.w*.86,500),ae=F*.42,Oe=l.w/2,me=l.h*.5;J("h:inv:dim",Oe,me,{shape:"rect",w:l.w,h:l.h,color:"#000000",alpha:.35,depth:79}),J("h:inv",Oe,me,{shape:"sprite",art:"panel",w:F,h:ae,color:"panel",depth:80}),J("h:inv:i",Oe-F*.34,me,{shape:"sprite",art:le.def.art,w:ae*.62,h:ae*.62,depth:80.1});let ue=F*.3,Q=ae*.5,i=pt();J("h:inv:a",Oe+F*.02,me-ae*.04,{shape:"sprite",art:"button",w:ue,h:Q,color:"accent",depth:80.1}),J("h:inv:a:c",Oe+F*.02-ue*.28,me-ae*.04,{shape:"sprite",art:"coin",w:Q*.4,h:Q*.4,depth:80.2}),Ee("h:inv:a:t",Oe+F*.02+ue*.1,me-ae*.04,ur(i),"coin",Q*.3,80.2),J("h:inv:b",Oe+F*.33,me-ae*.04,{shape:"sprite",art:"button",w:ue,h:Q,color:"secondary",depth:80.1}),Ee("h:inv:b:t",Oe+F*.33,me-ae*.04,`\xD7${le.def.mult??2} ${le.def.seconds??30}s`,"text",Q*.28,80.2),ve("h:inv:bar",Oe+F*.17,me+ae*.32,F*.6,Math.max(4,ae*.05),le.left/le.def.ttl,"coin",80.1),Pe({id:"inv_now",x:Oe+F*.02,y:me-ae*.04,w:ue,h:Q}),Pe({id:"inv_share",x:Oe+F*.33,y:me-ae*.04,w:ue,h:Q});}},ct=()=>{x=[],Le.clear(),se(),_e(),Se(),e.vars.ty_buttons=x.map(l=>`${l.id}@${Math.round(l.x)},${Math.round(l.y)}`).join(";");},dt=()=>{e.vars.cash=Math.floor(o.cash),e.vars.earned=Math.floor(o.earned),e.vars.time_left=E,e.vars.ty_charge=Math.floor(C),e.vars.ty_mode=cs[I]??1,e.vars.level_progress=Gi(o,ge()),e.vars.ty_goals=ge().map(l=>`${l.kind}:${Math.floor(lt(l))}/${l.n}`).join("|");},st=()=>{for(let h of [...a.values(),...c.values()])e.isAlive(h)&&e.destroy(h);a.clear(),c.clear(),p!==null&&e.isAlive(p)&&e.destroy(p),p=null,n=bo(xo(e,"meta:chapter")||1,r("difficulty"));let l={income:xo(e,"meta:income"),speed:xo(e,"meta:speed"),discount:xo(e,"meta:discount")};o=ss(n.def,l,Math.round(n.cash*(1+xo(e,"meta:cash")))),Kd.set(e,{s:o,level:n}),Ot(e,"board",Ne(e).h*.24),E=n.day,L=0,O=0,C=0,K=false,ne=false,V=8+s.range(0,4),ce=null,oe=null,le=null,e.vars.ty_level=n.level,e.vars.ty_world=n.world,e.vars.coins=0,e.vars.score=0,e.vars.stars=0,e.vars.reviving=false,dt();},Ye=l=>{if(ne)return;ne=true;let h=l==="cleared",m=Gi(o,ge()),g=h?Math.min(K?1:3,Di(E/Math.max(1,n.day))):0,T=Math.round(n.coins*r("coinReward")*(h?[1,1,1.25,1.5][g]:m*.5));T>0&&(Ke(e,"coins",T),e.emit("coin-collected",{value:T})),h&&e.vars["meta:first_clear"]===true&&Ke(e,"coins",n.firstClearGold),e.vars.stars=g,e.vars.score=Math.round(m*1e3)+(h?g*500+Math.floor(E)*10:0),e.vars.reviving=false,ce=null,oe=null,le=null,dt(),e.emit(Bt,{reason:l,stats:{chapter:n.level,seconds:Math.floor(L),cleared:h,stars:g,coins:Number(e.vars.coins??0),earned:Math.floor(o.earned),managers:Vi(o)}});},ft=()=>{ne||(H(e,{kind:"flash",color:"coin"}),Ye("cleared"));},qe=()=>{if(e.vars.revive_ready===true&&!K){e.vars.reviving=true,e.emit(Kt,{});return}Ye("out-of-time");},wt=()=>{we()&&(K=true,e.vars.reviving=false,E+=Ti,H(e,{kind:"flash",color:"coin"}),dt());},Je=()=>Math.max(Ci(o),n.cash*.05),pt=()=>Math.round(Je()*(le?.def.now??25)),yt=l=>{C=Math.min(xe().charge,C+jd),e.emit("event-handled",{id:l});},et=()=>{let l=o.biz.map((P,Z)=>({b:P,i:Z})).filter(P=>P.b.level>0&&P.b.broken===0),h=P=>P.effect==="rush"?!ce&&l.some(Z=>Z.b.rush<=0):P.effect==="break"?!o.biz.some(Z=>Z.broken>0)&&l.some(Z=>Z.b.level>=3):P.effect==="invest"?!le:!oe,m=n.def.events.map(P=>ns.find(Z=>Z.id===P)).filter(P=>!!P&&h(P));if(!m.length)return;let g=m.reduce((P,Z)=>P+Z.weight,0),T=s.range(0,g),N=m.find(P=>(T-=P.weight)<0)??m[0];if(N.effect==="rush"){let P=l.filter(Z=>Z.b.rush<=0);ce={index:P[s.int(0,P.length-1)].i,left:N.ttl,def:N};}else if(N.effect==="break"){let P=l.filter(ie=>ie.b.level>=3),Z=P[s.int(0,P.length-1)];Z.b.broken=N.taps??3,H(e,{kind:"shake",power:.3});}else N.effect==="invest"?le={left:N.ttl,def:N}:oe={left:N.ttl,def:N};e.emit("event-started",{id:N.id});},Ze=l=>{ce&&(ce.left-=l)<=0&&(ce=null),oe&&(oe.left-=l)<=0&&(oe=null),le&&(le.left-=l)<=0&&(le=null),n.def.events.length&&(V-=l,V<=0&&(et(),V=s.range(Dl[0],Dl[1])));},ut=l=>{let h=o.biz[l];if(!h||h.level<=0)return;let m=Te(l);if(h.broken>0){H(e,{kind:"burst",x:m.x,y:m.y,color:"ground",n:6,size:m.size*.6}),Ni(o,l)&&(H(e,{kind:"ring",x:m.x,y:m.y,color:"accent",size:m.size*1.2}),yt("break"));return}ce?.index===l&&(h.rush=ce.def.seconds??10,h.rushMult=ce.def.mult??3,H(e,{kind:"ring",x:m.x,y:m.y,color:"coin",size:m.size*1.4}),H(e,{kind:"pop",x:m.x,y:m.y-m.size*.45,text:`\xD7${h.rushMult}`,color:"coin",size:Math.round(m.size*.3)}),ce=null,yt("rush"));let g=zi(o,l);g<=0||(C=Math.min(xe().charge,C+Wd),$t(e,"tycoon-collect"),H(e,{kind:"burst",x:m.x,y:m.y,color:"coin",n:8,size:m.size*.7}),H(e,{kind:"pop",x:m.x,y:m.y-m.size*.35,text:`+${ur(g)}`,color:"coin",size:Math.round(m.size*.24)}),e.emit("cycle-collected",{index:l,amount:g}));},gt=l=>{let h=o.biz[l];if(!h)return;let m=Pi(o,l,Ue(l)),g=pe(l),T=g.x+g.w/2-g.w*.14;if(!m.ok){H(e,{kind:"shake",power:.1});return}$t(e,"tycoon-buy");let N=Te(l);H(e,{kind:"ring",x:N.x,y:N.y,color:"coin",size:N.size*1.1}),H(e,{kind:"burst",x:T,y:g.y,color:"accent",n:5,size:g.h*.5}),e.emit("business-bought",{id:h.def.id,level:h.level});for(let P of m.milestones)H(e,{kind:"flash",color:"coin"}),H(e,{kind:"pop",x:N.x,y:N.y-N.size*.5,text:`\u2605 ${P}`,color:"coin",size:Math.round(N.size*.3)}),e.emit("milestone",{id:h.def.id,at:P});},Wt=l=>{let h=o.biz[l];if(!h||!Ii(o,l))return;$t(e,"tycoon-manager");let m=Te(l);H(e,{kind:"ring",x:m.x,y:m.y,color:"secondary",size:m.size*1.3}),H(e,{kind:"pop",x:m.x,y:m.y-m.size*.5,text:"\u2605",color:"secondary",size:Math.round(m.size*.35)}),e.emit("manager-hired",{id:h.def.id});},Ft=(l,h,m)=>{Bi(o,l)&&($t(e,"tycoon-upgrade"),H(e,{kind:"ring",x:h,y:m,color:"accent",size:ze()*2.6}),H(e,{kind:"flash",color:"accent"}),e.emit("upgrade-bought",{key:l}));},Ut=()=>{let l=xe();if(C<l.charge)return false;let h=1+xo(e,"meta:skill");if(C=0,p!==null&&Ge(e,p,"cheer"),H(e,{kind:"flash",color:"secondary"}),l.effect==="rush")Wi(o,{id:"skill",left:(l.seconds??12)*h,income:l.mult??5,price:1});else if(l.effect==="sale")Wi(o,{id:"sale",left:(l.seconds??15)*h,income:1,price:l.mult??.5});else {let m=jl(o,Math.max(1,Math.round((l.cycles??8)*h))),g=ke();H(e,{kind:"pop",x:g.w/2,y:g.h*.16,text:`+${ur(m)}`,color:"coin",size:Math.round(g.U*.07)}),o.biz.forEach((T,N)=>{if(T.level<=0)return;let P=Te(N);H(e,{kind:"burst",x:P.x,y:P.y,color:"coin",n:10,size:P.size*.8});});}return e.emit("skill-cast",{id:l.id}),$t(e,"tycoon-skill"),true},R=()=>{if(!oe)return;let l=Y(),h=Math.round(Je()*(oe.def.now??15));Hl(o,h);let m=Math.round((oe.def.coins??0)*r("coinReward"));m>0&&(Ke(e,"coins",m),e.emit("coin-collected",{value:m})),H(e,{kind:"burst",x:l.x,y:l.y,color:"coin",n:14,size:l.r*2}),H(e,{kind:"pop",x:l.x,y:l.y+l.r*1.4,text:`+${ur(h)}`,color:"coin",size:Math.round(l.r*.7)}),oe=null,yt("courier");},z=l=>{if(!le)return;let h=le.def;l?Wi(o,{id:"invest",left:h.seconds??30,income:h.mult??2,price:1}):Hl(o,pt()),le=null,H(e,{kind:"flash",color:"coin"}),yt("invest");},y=(l,h,m)=>x.find(g=>(!m||g.id.startsWith(m))&&Math.abs(l-g.x)<=g.w/2&&Math.abs(h-g.y)<=g.h/2);e.on(Tt,l=>{let h=l;if(h.type!=="tap"||!rt(e)||tn(e)||ne||we())return;Ct(e),O=0;let m=le?y(h.x,h.y,"inv_")??y(h.x,h.y):y(h.x,h.y,"courier")??y(h.x,h.y);m&&(m.id==="inv_now"?z(false):m.id==="inv_share"?z(true):m.id==="courier"?R():m.id==="mode"?I=(I+1)%cs.length:m.id==="skill"?Ut():m.id.startsWith("up:")?Ft(m.id.slice(3),m.x,m.y):m.id.startsWith("biz")?ut(Number(m.id.slice(3))):m.id.startsWith("buy")?gt(Number(m.id.slice(3))):m.id.startsWith("mgr")&&Wt(Number(m.id.slice(3))),dt(),ls(o,ge())&&ft());}),e.on(Ht,()=>{st(),e.vars.level=n.level;}),e.on(Gt,st),e.on(Zt,wt),e.on(Qt,()=>{we()&&(e.vars.reviving=false,Ye("out-of-time"));}),e.on(Vt,l=>{Le.clear(),Se(),x=[],e.vars.ty_buttons="",p!==null&&e.isAlive(p)&&ot(e,p,l.reason==="cleared"?"dance":"idle");}),e.on(jt,()=>Ot(e,"board",Ne(e).h*.24));let S=l=>{if(!l)return;let h=l.kind==="collect"||l.kind==="fix"?`biz${l.index}`:l.kind==="buy"?`buy${l.index}`:l.kind==="hire"?`mgr${l.index}`:`up:${l.key}`;return x.find(m=>m.id===h)},$=l=>{let h=ke().U,m=o.biz.findIndex(g=>g.ready);if(!xt(l,"tycoon-collect")&&m>=0){let g=Te(m);return bt(l,"tap",g,void 0,g.size*.8)}if(!xt(l,"tycoon-buy")){let g=o.biz.findIndex(N=>o.cash>=fn(o,N,Ue(o.biz.indexOf(N)))),T=x.find(N=>N.id===`buy${g}`);if(g>=0&&T)return bt(l,"tap",T,void 0,T.h)}if(!xt(l,"tycoon-manager")){let g=o.biz.findIndex(N=>N.level>0&&!N.manager&&o.cash>=go(o,N)),T=x.find(N=>N.id===`mgr${g}`);if(g>=0&&T)return bt(l,"tap",T,void 0,T.w)}if(C>=xe().charge&&!xt(l,"tycoon-skill")){let g=x.find(T=>T.id==="skill");if(g)return bt(l,"tap",g,void 0,g.w)}if(O>6){let g=S(Fi(o,ge()));g&&bt(l,"tap",g,void 0,Math.min(g.w,h*.18));}};e.addSystem({id:"tycoon",order:0,run(l,h){if(!(!rt(l)||ne)){if(!we()){L+=h,O+=h,E=Math.max(0,E-h);for(let m of ji(o,h).paid)m.amount<=0||l.emit("cycle-collected",{index:m.index,amount:m.amount});C=Math.min(xe().charge,C+h),Ze(h);}if(ct(),dt(),!we()){if(ls(o,ge()))return ft();kr(l)||$(l),E<=0&&qe();}}}}),st();}};var Kr=(e,t,r,s,n,o,a,c,p)=>({en:e,ru:t,kz:r,zh:s,ko:n,ja:o,hi:a,pt:c,de:p}),qi=Kr("Score","\u041E\u0447\u043A\u0438","\u04B0\u043F\u0430\u0439","\u5206\u6570","\uC810\uC218","\u30B9\u30B3\u30A2","\u0938\u094D\u0915\u094B\u0930","Pontos","Punkte"),Fl={id:"fantasy",version:1,setting:"fantasy",names:Kr("Fantasy","\u0424\u044D\u043D\u0442\u0435\u0437\u0438","\u0424\u044D\u043D\u0442\u0435\u0437\u0438","\u5947\u5E7B","\uD310\uD0C0\uC9C0","\u30D5\u30A1\u30F3\u30BF\u30B8\u30FC","\u092B\u093C\u0948\u0902\u091F\u0947\u0938\u0940","Fantasia","Fantasy"),palette:{background:"#1f2a1d",ground:"#3b4a2e",lane:"#56683f",primary:"#4fa3e0",secondary:"#8e5bd1",danger:"#d0483b",coin:"#f2c14e",accent:"#6fbf4a",text:"#fff6e0",muted:"#b9b08f",piece1:"#e0443e",piece2:"#3f7fe0",piece3:"#43b05c",piece4:"#f2c14e",piece5:"#9b59d0",piece6:"#ef8a2f",panel:"#3a2f25"},texts:{"res.coins":Kr("Gold","\u0417\u043E\u043B\u043E\u0442\u043E","\u0410\u043B\u0442\u044B\u043D","\u91D1\u5E01","\uACE8\uB4DC","\u30B4\u30FC\u30EB\u30C9","\u0938\u094B\u0928\u093E","Ouro","Gold"),"res.score":qi},races:["human","elf","dwarf","orc","undead"],cast:{hero:{preset:"knight",races:["human"]},foe:{preset:"berserker",parts:{Hat:null,Offhand:null,Weapon:"weapon/battle_axe"},races:["orc"]},foe2:{preset:"viking",parts:{Weapon:"weapon/double_axe"},races:["orc"]},boss:{preset:"dark_knight",races:["orc"]},helper:{preset:"hunter",parts:{Weapon:null,Hat:null},races:["elf","dwarf","human"]},foe3:{preset:"crossbowman",parts:{Weapon:"weapon/crossbow"},races:["undead"]},foe4:{preset:"lumberjack",parts:{Weapon:"weapon/spear",Back:null},races:["undead"]},foe5:{preset:"hunter",parts:{Hat:null,Back:null,Weapon:"weapon/dagger"},races:["undead"]},hero2:{preset:"crusader",races:["human","dwarf"]},hero3:{preset:"archmage",races:["elf"]}}},Ul={id:"sci-fi",version:1,setting:"sci-fi",names:Kr("Sci-fi","\u041D\u0430\u0443\u0447\u043D\u0430\u044F \u0444\u0430\u043D\u0442\u0430\u0441\u0442\u0438\u043A\u0430","\u0492\u044B\u043B\u044B\u043C\u0438 \u0444\u0430\u043D\u0442\u0430\u0441\u0442\u0438\u043A\u0430","\u79D1\u5E7B","SF","SF","\u0935\u093F\u091C\u094D\u091E\u093E\u0928 \u0915\u0925\u093E","Fic\xE7\xE3o cient\xEDfica","Science-Fiction"),palette:{background:"#0b1020",ground:"#151d33",lane:"#22305a",primary:"#36e3ff",secondary:"#b45cff",danger:"#ff3d6e",coin:"#ffe14d",accent:"#3dff9a",text:"#e8f6ff",muted:"#7d8fb3",piece1:"#ff3d6e",piece2:"#36a3ff",piece3:"#3dff9a",piece4:"#ffe14d",piece5:"#b45cff",piece6:"#ff8f3d",panel:"#18213d"},texts:{"res.coins":Kr("Chips","\u0427\u0438\u043F\u044B","\u0427\u0438\u043F\u0442\u0435\u0440","\u82AF\u7247","\uCE69","\u30C1\u30C3\u30D7","\u091A\u093F\u092A\u094D\u0938","Chips","Chips"),"res.score":qi},races:["human"],cast:{hero:{preset:"soldier",races:["human"]},foe:{preset:"soldier",parts:{Hat:"hat/great_helm",Weapon:"weapon/pistol"},races:["undead"]},foe2:{preset:"gunslinger",parts:{Weapon:"weapon/rifle",Back:null},races:["orc"]},boss:{preset:"dark_knight",parts:{Weapon:"weapon/flame_sword"},races:["orc"]},helper:{preset:"gunslinger",parts:{Weapon:null,Back:null},races:["elf","human"]},foe3:{preset:"gunslinger",parts:{Weapon:"weapon/pistol",Back:null},races:["undead"]},foe4:{preset:"soldier",parts:{Hat:"hat/great_helm",Weapon:"weapon/spear"},races:["orc"]},foe5:{preset:"soldier",parts:{Hat:null,Back:null,Weapon:"weapon/dagger"},races:["undead"]},hero2:{preset:"musketeer",parts:{Weapon:"weapon/rifle"},races:["human"]},hero3:{preset:"archmage",parts:{Weapon:"weapon/wizard_staff"},races:["elf","human"]}}},Xl={id:"cozy",version:1,setting:"cozy",names:Kr("Cozy cartoon","\u0423\u044E\u0442\u043D\u044B\u0439 \u043C\u0443\u043B\u044C\u0442\u044F\u0448\u043D\u044B\u0439","\u0416\u0430\u0439\u043B\u044B \u043C\u0443\u043B\u044C\u0442\u0444\u0438\u043B\u044C\u043C","\u6E29\u99A8\u5361\u901A","\uC544\uB291\uD55C \uCE74\uD230","\u307B\u306E\u307C\u306E\u30AB\u30FC\u30C8\u30A5\u30FC\u30F3","\u0906\u0930\u093E\u092E\u0926\u093E\u092F\u0915 \u0915\u093E\u0930\u094D\u091F\u0942\u0928","Cartoon aconchegante","Gem\xFCtlicher Cartoon"),palette:{background:"#fdf1e4",ground:"#f3d9bf",lane:"#e9c6a3",primary:"#ff8fab",secondary:"#8fb8ff",danger:"#ff6b6b",coin:"#ffb627",accent:"#7ccf8a",text:"#3d2b25",muted:"#9c8478",piece1:"#ff8fab",piece2:"#7fb8ff",piece3:"#8cd98f",piece4:"#ffd166",piece5:"#c39bff",piece6:"#ffa96b",panel:"#fff8f0"},texts:{"res.coins":Kr("Coins","\u041C\u043E\u043D\u0435\u0442\u043A\u0438","\u0422\u0438\u044B\u043D\u0434\u0430\u0440","\u786C\u5E01","\uCF54\uC778","\u30B3\u30A4\u30F3","\u0938\u093F\u0915\u094D\u0915\u0947","Moedas","M\xFCnzen"),"res.score":qi},races:["human","elf","dwarf"],cast:{hero:{preset:"camper",parts:{Glasses:null},races:["human"]},foe:{preset:"lumberjack",parts:{Weapon:"weapon/3",Back:null},races:["orc"]},foe2:{preset:"lumberjack",parts:{Weapon:null,Back:null},races:["dwarf"]},boss:{preset:"viking",races:["orc"]},helper:{preset:"camper",parts:{Weapon:null,Back:null,Glasses:null},races:["human","elf","dwarf"]},foe3:{preset:"hunter",parts:{Weapon:"weapon/hunting_bow"},races:["orc"]},foe4:{preset:"quarterback",races:["orc"]},foe5:{preset:"camper",parts:{Weapon:null,Back:null,Glasses:null},races:["orc"]},hero2:{preset:"quarterback",races:["human"]},hero3:{preset:"wizard",races:["elf"]}}},ql={id:"post-apocalypse",version:1,setting:"post-apocalypse",names:Kr("Post-apocalypse","\u041F\u043E\u0441\u0442\u0430\u043F\u043E\u043A\u0430\u043B\u0438\u043F\u0441\u0438\u0441","\u041F\u043E\u0441\u0442\u0430\u043F\u043E\u043A\u0430\u043B\u0438\u043F\u0441\u0438\u0441","\u672B\u65E5\u5E9F\u571F","\uD3EC\uC2A4\uD2B8 \uC544\uD3EC\uCE7C\uB9BD\uC2A4","\u30DD\u30B9\u30C8\u30A2\u30DD\u30AB\u30EA\u30D7\u30B9","\u092A\u094D\u0930\u0932\u092F \u0915\u0947 \u092C\u093E\u0926","P\xF3s-apocalipse","Postapokalypse"),palette:{background:"#1d1a16",ground:"#3a3328",lane:"#4d4436",primary:"#d9a441",secondary:"#7a8f5b",danger:"#b8402d",coin:"#e0c060",accent:"#8fa35a",text:"#f0e6d2",muted:"#a39a86",piece1:"#b8402d",piece2:"#5a7f9a",piece3:"#7a8f5b",piece4:"#e0c060",piece5:"#8a6a4a",piece6:"#d9762f",panel:"#2c2620"},texts:{"res.coins":Kr("Caps","\u041A\u0440\u044B\u0448\u043A\u0438","\u049A\u0430\u049B\u043F\u0430\u049B\u0442\u0430\u0440","\u74F6\u76D6","\uBCD1\uB69C\uAED1","\u30AD\u30E3\u30C3\u30D7","\u0922\u0915\u094D\u0915\u0928","Tampinhas","Kronkorken"),"res.score":qi},races:["human","undead","orc"],cast:{hero:{preset:"soldier",parts:{Hat:null,Gloves:"gloves/bracers"},races:["human"]},foe:{preset:"lumberjack",parts:{Weapon:null,Back:null,Gloves:null},races:["undead"]},foe2:{preset:"berserker",parts:{Hat:null,Offhand:null,Weapon:"weapon/mace"},races:["orc"]},boss:{preset:"berserker",parts:{Hat:"hat/great_helm",Weapon:"weapon/double_axe"},races:["orc"]},helper:{preset:"soldier",parts:{Hat:null,Weapon:null},races:["human"]},foe3:{preset:"musketeer",parts:{Weapon:"weapon/musket",Hat:null},races:["undead"]},foe4:{preset:"viking",parts:{Weapon:"weapon/mace"},races:["undead"]},foe5:{preset:"lumberjack",parts:{Weapon:"weapon/dagger",Back:null},races:["undead"]},hero2:{preset:"viking",parts:{Hat:null},races:["human"]},hero3:{preset:"ranger",races:["human"]}}},Ki=[Fl,Ul,Xl,ql],Gl=(e,t)=>(e.flows??[]).some(r=>r.resource===t.resource&&r.by===t.by&&r.kind===t.kind)?e:{...e,flows:[...e.flows??[],t]},Qd=e=>e.resources?.find(t=>t.kind==="currency")?.id??"coins",Kl=e=>t=>Gl(t,{resource:Qd(t),by:`system:${e}`,kind:"sink"}),Zl={id:"hero-upgrade",version:1,name:"link.hero-upgrade",core:["runner","platformer","survivors","tower-defense"],systems:["character"],apply:Kl("character")},Ql={id:"puzzle-city",version:1,name:"link.puzzle-city",core:["match3","merge"],systems:[],apply(e){if(e.modes.some(s=>s.id==="city"))return e;let t=Qd(e),r={...e,modes:[...e.modes,{id:"city",preset:"tycoon",role:"meta"}]};return Gl(Gl(r,{resource:t,by:"city",kind:"source",amount:"vars.coins"}),{resource:t,by:"system:store",kind:"sink"})}},Yl={id:"runner-collection",version:1,name:"link.runner-collection",core:["runner","platformer"],systems:["lootboxes","collections"],apply:Kl("lootboxes")},Jl={id:"defense-boosts",version:1,name:"link.defense-boosts",core:["tower-defense","survivors"],systems:["boosts"],apply:Kl("boosts")},Zi=[Zl,Ql,Yl,Jl];var Yd=(e,t)=>`${e.character}-${t}`;var Jd={id:"runner",version:1,engine:"phaser",genre:"runner",name:"preset.runner",blocks:["round","lane-runner"],params:{difficulty:{type:"number",default:.5,min:0,max:1},generosity:{type:"number",default:.6,min:0,max:1},lanes:{type:"number",default:3,min:2,max:5,integer:true},lives:{type:"number",default:3,min:1,max:9,integer:true},length:{type:"number",default:1,min:.05,max:5}},blockParams:{"lane-runner":{lanes:"params.lanes",lives:"params.lives",difficulty:"params.difficulty",coinRate:"0.5 + params.generosity * 0.4",powerRate:"0.12 + params.generosity * 0.2",lengthScale:"params.length"}},produces:["soft","score"],placements:[{id:"reward_window",kind:"reward-window"},{id:"revive",kind:"revive",dailyLimit:5}]},ko={difficulty:{type:"number",default:.5,min:0,max:1},generosity:{type:"number",default:.6,min:0,max:1}},vo=[{id:"reward_window",kind:"reward-window"}],ef={id:"platformer",version:1,engine:"phaser",genre:"platformer",name:"preset.platformer",blocks:["round","platformer"],params:{...ko,lives:{type:"number",default:3,min:1,max:9,integer:true},doubleJump:{type:"boolean",default:false}},blockParams:{platformer:{difficulty:"params.difficulty",lives:"params.lives",doubleJump:"params.doubleJump"}},produces:["soft","score"],placements:[...vo,{id:"revive",kind:"revive",dailyLimit:5}]},tf={id:"survivors",version:1,engine:"phaser",genre:"survivors",name:"preset.survivors",blocks:["round","survivors"],params:{...ko,minutes:{type:"number",default:5,min:.5,max:15}},blockParams:{survivors:{duration:"params.minutes * 60",spawnRate:"0.9 + params.difficulty * 0.6",spawnGrowth:"0.6 + params.difficulty * 0.6",foeHpGrowth:"0.3 + params.difficulty * 0.3",foeDamage:"0.8 + params.difficulty * 0.4",coinRate:"0.15 + params.generosity * 0.3",hp:"120 - params.difficulty * 40"}},produces:["soft","score"],placements:[...vo,{id:"revive",kind:"revive",dailyLimit:5},{id:"reroll",kind:"retry",dailyLimit:10}]},rf={id:"tower-defense",version:2,engine:"phaser",genre:"tower-defense",name:"preset.tower-defense",blocks:["round","tower-defense"],params:{...ko,lives:{type:"number",default:20,min:1,max:100,integer:true}},blockParams:{"tower-defense":{difficulty:"params.difficulty",lives:"params.lives",coinRate:"0.08 + params.generosity * 0.25",earlyGold:"1 + params.generosity * 2"}},produces:["soft","score"],placements:[...vo,{id:"revive",kind:"revive",dailyLimit:5}]},nf={id:"match3",version:2,engine:"phaser",genre:"match3",name:"preset.match3",blocks:["round","match3"],params:{...ko},blockParams:{match3:{difficulty:"params.difficulty",coinEvery:"12 - params.generosity * 7"}},produces:["soft","score","stars"],placements:[...vo,{id:"revive",kind:"revive",dailyLimit:5}]},of={id:"merge",version:2,engine:"phaser",genre:"merge",name:"preset.merge",blocks:["round","merge"],params:{...ko},blockParams:{merge:{difficulty:"params.difficulty",orderReward:"0.6 + params.generosity * 0.8"}},produces:["soft","score","stars"],placements:[...vo,{id:"revive",kind:"revive",dailyLimit:5}]},sf={id:"tycoon",version:2,engine:"phaser",genre:"idle-tycoon",name:"preset.tycoon",blocks:["round","tycoon"],params:{...ko},blockParams:{tycoon:{difficulty:"params.difficulty",coinReward:"0.6 + params.generosity * 0.8"}},produces:["soft","score","stars"],placements:[...vo,{id:"revive",kind:"revive",dailyLimit:5}]},af=[Jd,ef,tf,rf,nf,of,sf],Mh=[Ls,As,ci,gi,wi,Xs,oi,Xi];function Eh(e){Eo(e);for(let t of Mh)e.has(Yr,t.id)||e.define(Yr,t);for(let t of Ki)e.has(Tn,t.id)||e.define(Tn,t);for(let t of Zi)e.has(So,t.id)||e.define(So,t);for(let t of af)e.has(Jr,t.id)||e.define(Jr,t);}var Sh={v:1,engine:"phaser",seed:"demo-runner",modes:[{id:"run",preset:"runner",role:"core"}],resources:[{id:"coins",kind:"currency",ref:"CO",name:"res.coins"},{id:"score",kind:"score",name:"res.score"}],flows:[{resource:"coins",by:"run",kind:"source",amount:"vars.coins"},{resource:"coins",by:"system:store",kind:"sink"},{resource:"score",by:"run",kind:"source",amount:"vars.score"}],texts:{title:{en:"Lane Dash",ru:"\u0420\u044B\u0432\u043E\u043A \u043F\u043E \u043F\u043E\u043B\u043E\u0441\u0430\u043C"},hint:{en:"Swipe or tap a side to change lanes",ru:"\u0421\u0432\u0430\u0439\u043F \u0438\u043B\u0438 \u043D\u0430\u0436\u0430\u0442\u0438\u0435 \u0441\u0431\u043E\u043A\u0443 \u043C\u0435\u043D\u044F\u0435\u0442 \u043F\u043E\u043B\u043E\u0441\u0443"}}};function wh(e,t={}){let r=e==="runner"?"run":"main";return {v:1,engine:"phaser",seed:t.seed??e,modes:[{id:r,preset:e,role:"core",...t.params?{params:t.params}:{}}],resources:[{id:"coins",kind:"currency",ref:t.coinRef??"CO",name:"res.coins"},{id:"score",kind:"score",name:"res.score"}],flows:[{resource:"coins",by:r,kind:"source",amount:"vars.coins"},{resource:"coins",by:"system:store",kind:"sink"},{resource:"score",by:r,kind:"source",amount:"vars.score"}],...t.texts?{texts:t.texts}:{},...t.palette?{palette:t.palette}:{},...t.assets?{assets:t.assets}:{}}}
|
|
3
|
-
exports.ABILITIES=
|
|
1
|
+
'use strict';function Vr(e){if(!ap.test(e))throw new Error(`registry: bad kind name "${e}"`);return Object.freeze({name:e})}var Oc=/^[a-z0-9][a-z0-9-]*(?:\.[a-z0-9][a-z0-9-]*)*$/,ap=/^[a-z][a-z0-9-]*$/;function Ls(e){let t=new Map,r=n=>{let s=t.get(n);return s||(s=new Map,t.set(n,s)),s},o={define(n,s,a){if(!s||typeof s!="object")throw new Error(`registry: ${n.name} entry must be an object`);if(typeof s.id!="string"||!Oc.test(s.id))throw new Error(`registry: ${n.name} has a bad id "${String(s.id)}"`);if(!Number.isInteger(s.version)||s.version<1)throw new Error(`registry: ${n.name} "${s.id}" needs an integer version \u2265 1`);let i=r(n.name);if((i.has(s.id)||(e?.has(n,s.id)??false))&&!a?.override)throw new Error(`registry: ${n.name} "${s.id}" is already defined (pass { override: true } to replace it)`);let m=Object.freeze({...s});return i.set(s.id,m),m},get(n,s){let a=t.get(n.name)?.get(s);return a||e?.get(n,s)},require(n,s){let a=o.get(n,s);if(!a)throw new Error(`registry: no ${n.name} "${s}"`);return a},has(n,s){return o.get(n,s)!==void 0},list(n){let s=new Map;for(let a of e?.list(n)??[])s.set(a.id,a);for(let[a,i]of t.get(n.name)??[])s.set(a,i);return [...s.values()].sort((a,i)=>a.id<i.id?-1:a.id>i.id?1:0)},extend(){return Ls(o)}};return o}function ip(e){let t=1779033703^e.length;for(let r=0;r<e.length;r++)t=Math.imul(t^e.charCodeAt(r),3432918353),t=t<<13|t>>>19;return ()=>(t=Math.imul(t^t>>>16,2246822507),t=Math.imul(t^t>>>13,3266489909),t^=t>>>16,t>>>0)}function lp(e,t,r,o){return ()=>{e>>>=0,t>>>=0,r>>>=0,o>>>=0;let n=e+t|0;return e=t^t>>>9,t=r+(r<<3)|0,r=r<<21|r>>>11,o=o+1|0,n=n+o|0,r=r+n|0,(n>>>0)/4294967296}}function _s(e){let t=String(e),r=ip(t),o=lp(r(),r(),r(),r());for(let s=0;s<12;s++)o();return {seed:t,next:o,int(s,a){if(!Number.isFinite(s)||!Number.isFinite(a))throw new RangeError("int: bounds must be finite");let i=Math.ceil(Math.min(s,a)),p=Math.floor(Math.max(s,a));return i+Math.floor(o()*(p-i+1))},range(s,a){return s+o()*(a-s)},chance(s){return o()<s},pick(s){if(s.length===0)throw new RangeError("pick: empty list");return s[Math.floor(o()*s.length)]},weighted(s,a){let i=0;for(let m of s)i+=Math.max(0,a(m));if(i<=0)throw new RangeError("weighted: no positive weight");let p=o()*i;for(let m of s){let $=Math.max(0,a(m));if(!($<=0)){if(p<$)return m;p-=$;}}for(let m=s.length-1;m>=0;m--){let $=s[m];if(a($)>0)return $}throw new RangeError("weighted: no positive weight")},shuffle(s){let a=s.slice();for(let i=a.length-1;i>0;i--){let p=Math.floor(o()*(i+1)),m=a[i];a[i]=a[p],a[p]=m;}return a},stream(s){return _s(`${t}/${s}`)}}}var dr=class extends Error{constructor(r,o,n){super(`${r} at ${n} in "${o}"`);this.source=o;this.at=n;this.name="ExprError";}source;at},Cc=2e3,vi=64,ct=e=>{let t=typeof e=="number"?e:typeof e=="boolean"?e?1:0:Number(e);return Number.isFinite(t)?t:0},En=e=>typeof e=="string"?e.length>0:!!e,$i={min:(...e)=>e.length?Math.min(...e):0,max:(...e)=>e.length?Math.max(...e):0,abs:(e=0)=>Math.abs(e),floor:(e=0)=>Math.floor(e),ceil:(e=0)=>Math.ceil(e),round:(e=0)=>Math.round(e),sqrt:(e=0)=>Math.sqrt(Math.max(0,e)),pow:(e=0,t=1)=>Math.pow(e,t),log:(e=1)=>e>0?Math.log(e):0,clamp:(e=0,t=0,r=1)=>Math.min(Math.max(e,t),r),lerp:(e=0,t=0,r=0)=>e+(t-e)*r,sign:(e=0)=>Math.sign(e),step:(e=0,t=0)=>t<e?0:1},cp=["&&","||","==","!=","<=",">=","+","-","*","/","%","^","<",">","!","?",":","(",")",","];function dp(e){let t=[],r=0;for(;r<e.length;){let o=e[r];if(o===" "||o===" "||o===`
|
|
2
|
+
`||o==="\r"){r++;continue}if(o>="0"&&o<="9"||o==="."&&/[0-9]/.test(e[r+1]??"")){let s=/^(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/.exec(e.slice(r));if(!s)throw new dr("bad number",e,r);t.push({t:"num",v:Number(s[0]),at:r}),r+=s[0].length;continue}if(o==="'"||o==='"'){let s=e.indexOf(o,r+1);if(s<0)throw new dr("unclosed string",e,r);t.push({t:"str",v:e.slice(r+1,s),at:r}),r=s+1;continue}if(/[A-Za-z_$]/.test(o)){let s=/^[A-Za-z_$][A-Za-z0-9_$]*(?:\.[A-Za-z_$][A-Za-z0-9_$]*)*/.exec(e.slice(r));if(!s)throw new dr("bad name",e,r);t.push({t:"id",v:s[0],at:r}),r+=s[0].length;continue}let n=cp.find(s=>e.startsWith(s,r));if(!n)throw new dr(`unexpected "${o}"`,e,r);t.push({t:"op",v:n,at:r}),r+=n.length;}return t.push({t:"end",at:e.length}),t}var Pc={"||":1,"&&":2,"==":3,"!=":3,"<":4,"<=":4,">":4,">=":4,"+":5,"-":5,"*":6,"/":6,"%":6,"^":8};function fp(e){let t=dp(e),r=0,o=()=>t[r],n=()=>t[r++],s=C=>{let z=o();return z.t==="op"&&z.v===C},a=C=>{let z=n();if(z.t!=="op"||z.v!==C)throw new dr(`expected "${C}"`,e,z.at)},i=C=>{if(C>vi)throw new dr("formula is nested too deep",e,o().at);let z=p(0,C+1);if(!s("?"))return z;n();let F=i(C+1);a(":");let ne=i(C+1);return {k:"cond",c:z,a:F,b:ne}},p=(C,z)=>{if(z>vi)throw new dr("formula is nested too deep",e,o().at);let F=m(z+1);for(;;){let ne=o();if(ne.t!=="op")break;let X=Pc[ne.v];if(X===void 0||X<C)break;n();let ye=ne.v==="^"?p(X,z+1):p(X+1,z+1);F={k:"bin",op:ne.v,a:F,b:ye};}return F},m=C=>{if(C>vi)throw new dr("formula is nested too deep",e,o().at);return s("-")||s("!")?{k:"un",op:n().v,a:p(Pc["^"],C+1)}:$(C+1)},$=C=>{let z=n();if(z.t==="num")return {k:"num",v:z.v};if(z.t==="str")return {k:"str",v:z.v};if(z.t==="op"&&z.v==="("){let F=i(C+1);return a(")"),F}if(z.t==="id"){if(z.v==="true")return {k:"bool",v:true};if(z.v==="false")return {k:"bool",v:false};if(s("(")){if(!Object.prototype.hasOwnProperty.call($i,z.v))throw new dr(`unknown function "${z.v}"`,e,z.at);n();let F=[];if(!s(")"))for(;;){if(F.push(i(C+1)),s(",")){n();continue}break}return a(")"),{k:"call",fn:z.v,args:F}}return {k:"var",path:z.v.split(".")}}throw new dr(z.t==="end"?"unexpected end":"unexpected token",e,z.at)},k=i(0),O=o();if(O.t!=="end")throw new dr("unexpected token",e,O.at);return k}function pp(e,t){let r=e;for(let o of t){if(r===null||typeof r!="object"||!Object.prototype.hasOwnProperty.call(r,o))return 0;r=r[o];}return typeof r=="number"||typeof r=="string"||typeof r=="boolean"?r:0}function cr(e,t){switch(e.k){case "num":case "str":case "bool":return e.v;case "var":return pp(t,e.path);case "un":return e.op==="-"?-ct(cr(e.a,t)):!En(cr(e.a,t));case "cond":return En(cr(e.c,t))?cr(e.a,t):cr(e.b,t);case "call":return ct($i[e.fn](...e.args.map(r=>ct(cr(r,t)))));case "bin":{if(e.op==="&&")return En(cr(e.a,t))&&En(cr(e.b,t));if(e.op==="||")return En(cr(e.a,t))||En(cr(e.b,t));let r=cr(e.a,t),o=cr(e.b,t);switch(e.op){case "==":return typeof r=="string"||typeof o=="string"?String(r)===String(o):ct(r)===ct(o);case "!=":return typeof r=="string"||typeof o=="string"?String(r)!==String(o):ct(r)!==ct(o);case "<":return ct(r)<ct(o);case "<=":return ct(r)<=ct(o);case ">":return ct(r)>ct(o);case ">=":return ct(r)>=ct(o);case "+":return typeof r=="string"||typeof o=="string"?`${r}${o}`:ct(r)+ct(o);case "-":return ct(r)-ct(o);case "*":return ct(r)*ct(o);case "/":{let n=ct(o);return n===0?0:ct(r)/n}case "%":{let n=ct(o);return n===0?0:ct(r)%n}case "^":return ct(Math.pow(ct(r),ct(o)))}return 0}}}function cn(e,t){switch(e.k){case "var":t.add(e.path.join("."));return;case "un":cn(e.a,t);return;case "bin":cn(e.a,t),cn(e.b,t);return;case "cond":cn(e.c,t),cn(e.a,t),cn(e.b,t);return;case "call":for(let r of e.args)cn(r,t);return;default:return}}var Rs=new Map;function Er(e){let t=Rs.get(e);if(t)return t;if(e.length>Cc)throw new dr("formula is too long",e,Cc);let r=fp(e),o=new Set;cn(r,o);let n={source:e,reads:[...o],eval:s=>cr(r,s),num:s=>ct(cr(r,s)),bool:s=>En(cr(r,s))};return Rs.size>5e3&&Rs.clear(),Rs.set(e,n),n}function Mi(e){try{return Er(e),null}catch(t){return t instanceof Error?t.message:String(t)}}function wi(e,t,r=0){return e===void 0?r:typeof e=="number"?Number.isFinite(e)?e:r:Er(e).num(t)}var hp=/^[a-z][a-z0-9-]*(?:\.[a-z0-9-]+)*$/;function ve(e){if(!hp.test(e))throw new Error(`world: bad component name "${e}"`);return Object.freeze({name:e})}var zo=class{rng;vars;tick=0;time=0;nextId=1;alive=new Set;stores=new Map;doomed=new Set;systems=[];systemSeq=0;handlers=new Map;queue=[];maxEventRounds;stepping=false;constructor(t={}){this.rng=_s(t.seed??"world"),this.vars={...t.vars??{}},this.maxEventRounds=t.maxEventRounds??16;}create(){let t=this.nextId++;return this.alive.add(t),t}destroy(t){this.alive.has(t)&&(this.stepping?this.doomed.add(t):this.purge(t));}isAlive(t){return this.alive.has(t)&&!this.doomed.has(t)}get entityCount(){return this.alive.size-this.doomed.size}set(t,r,o){if(!this.alive.has(t))throw new Error(`world: entity ${t} does not exist`);let n=this.stores.get(r.name);return n||(n=new Map,this.stores.set(r.name,n)),n.set(t,o),t}get(t,r){return this.stores.get(r.name)?.get(t)}need(t,r){let o=this.get(t,r);if(o===void 0)throw new Error(`world: entity ${t} has no ${r.name}`);return o}has(t,r){return this.stores.get(r.name)?.has(t)??false}remove(t,r){this.stores.get(r.name)?.delete(t);}query(...t){if(t.length===0)return [...this.alive].filter(a=>!this.doomed.has(a)).sort((a,i)=>a-i);let r=t.map(a=>this.stores.get(a.name));if(r.some(a=>!a||a.size===0))return [];let o=r,n=o.reduce((a,i)=>i.size<a.size?i:a),s=[];for(let a of n.keys())this.doomed.has(a)||o.every(i=>i.has(a))&&s.push(a);return s.sort((a,i)=>a-i)}addSystem(t){if(this.systems.some(r=>r.system.id===t.id))throw new Error(`world: system "${t.id}" is already added`);this.systems.push({system:t,seq:this.systemSeq++}),this.systems.sort((r,o)=>(r.system.order??0)-(o.system.order??0)||r.seq-o.seq);}removeSystem(t){this.systems=this.systems.filter(r=>r.system.id!==t);}get systemIds(){return this.systems.map(t=>t.system.id)}on(t,r){let o=this.handlers.get(t)??[];return o.push(r),this.handlers.set(t,o),()=>{let n=this.handlers.get(t);if(!n)return;let s=n.indexOf(r);s>=0&&n.splice(s,1);}}emit(t,r={}){this.queue.push({topic:t,payload:r});}flushEvents(){for(let t=0;t<this.maxEventRounds&&this.queue.length>0;t++){let r=this.queue;this.queue=[];for(let{topic:o,payload:n}of r){let s=this.handlers.get(o);if(!s)continue;for(let i of s.slice())i(n,this);let a=this.handlers.get("*");if(a)for(let i of a.slice())i({...n,topic:o},this);}}this.queue.length>0&&(this.queue=[],this.overflowed++);}overflowed=0;step(t){if(!(t>=0)||!Number.isFinite(t))throw new RangeError("world: dt must be a finite number \u2265 0");this.stepping=true;try{this.tick++,this.time+=t;for(let{system:r}of this.systems.slice())r.run(this,t);this.flushEvents();}finally{this.stepping=false;for(let r of this.doomed)this.purge(r);this.doomed.clear();}}purge(t){this.alive.delete(t);for(let r of this.stores.values())r.delete(t);}};function up(e,t={}){let r=t.step??.016666666666666666,o=t.maxSteps??5,n=0;return {step:r,advance(s){if(!(s>0)||!Number.isFinite(s))return 0;n+=s;let a=0;for(;n>=r&&a<o;)e.step(r),n-=r,a++;return a===o&&(n=0),a},get alpha(){return n/r}}}var Bo=Vr("effect"),mp=/^[a-z][a-z0-9_]*$/,Ic=e=>{let t=e.name;if(typeof t!="string"||!mp.test(t))throw new Error(`effect ${e.type}: bad var name`);return t},Nc=[{id:"set-var",version:1,required:["name","value"],formulas:["value"],run(e,t){let r=t.value,o=typeof r=="string"?Er(r).eval(e.scope):typeof r=="number"||typeof r=="boolean"?r:0;e.world.vars[Ic(t)]=o;}},{id:"add-var",version:1,required:["name","amount"],formulas:["amount","min","max"],run(e,t){let r=Ic(t),o=e.world.vars[r],n=(typeof o=="number"?o:0)+e.num(t.amount);t.min!==void 0&&(n=Math.max(n,e.num(t.min))),t.max!==void 0&&(n=Math.min(n,e.num(t.max))),e.world.vars[r]=n;}},{id:"emit",version:1,required:["topic"],run(e,t){let r=t.topic;if(typeof r!="string"||r.length===0)throw new Error("effect emit: topic required");let o=t.payload,n={};if(o&&typeof o=="object")for(let[s,a]of Object.entries(o))n[s]=typeof a=="string"?Er(a).eval(e.scope):a;e.world.emit(r,n);}}];function Ho(e){for(let t of Nc)e.has(Bo,t.id)||e.define(Bo,t);}function As(e,t,r,o){let n=new Set;e.forEach((s,a)=>{let i=`${r}.${a}`;if(!s||typeof s!="object"){o.push({level:"error",path:i,code:"RULE_SHAPE",message:"a rule must be an object"});return}if(typeof s.id!="string"||s.id.length===0?o.push({level:"error",path:`${i}.id`,code:"RULE_ID",message:"a rule needs an id"}):n.has(s.id)?o.push({level:"error",path:`${i}.id`,code:"RULE_DUPLICATE",message:`rule "${s.id}" is defined twice`}):n.add(s.id),(typeof s.on!="string"||s.on.length===0)&&o.push({level:"error",path:`${i}.on`,code:"RULE_TRIGGER",message:"a rule needs an event topic in `on`"}),s.when!==void 0)try{Er(String(s.when));}catch(p){o.push({level:"error",path:`${i}.when`,code:"RULE_FORMULA",message:p.message});}if(!Array.isArray(s.do)||s.do.length===0){o.push({level:"error",path:`${i}.do`,code:"RULE_EFFECTS",message:"a rule needs at least one effect"});return}s.do.forEach((p,m)=>{let $=`${i}.do.${m}`,k=typeof p?.type=="string"?t.get(Bo,p.type):void 0;if(!k){o.push({level:"error",path:`${$}.type`,code:"EFFECT_UNKNOWN",message:`unknown effect "${String(p?.type)}"`});return}for(let O of k.required??[])p[O]===void 0&&o.push({level:"error",path:`${$}.${O}`,code:"EFFECT_PARAM",message:`effect "${k.id}" needs "${O}"`});for(let O of k.formulas??[]){let C=p[O];if(typeof C=="string")try{Er(C);}catch(z){o.push({level:"error",path:`${$}.${O}`,code:"RULE_FORMULA",message:z.message});}}});});}function Ei(e,t,r,o={}){let n=t.map(i=>({def:i,...i.when!==void 0?{when:Er(i.when)}:{},effects:i.do.map(p=>({spec:p,def:r.require(Bo,p.type)})),hits:0,runs:0,lastRunAt:Number.NEGATIVE_INFINITY})),s=new Map;for(let i of n){let p=s.get(i.def.on)??[];p.push(i),s.set(i.def.on,p);}let a=[...s.entries()].map(([i,p])=>e.on(i,m=>{for(let $ of p){if($.def.once&&$.runs>0)continue;let k={event:m,vars:e.vars,tick:e.tick,time:e.time};if($.when&&!$.when.bool(k)||($.hits++,$.def.every!==void 0&&$.def.every>1&&$.hits%$.def.every!==0)||$.def.cooldown!==void 0&&e.time-$.lastRunAt<$.def.cooldown)continue;$.runs++,$.lastRunAt=e.time;let O={world:e,rule:$.def,event:m,scope:k,num:(C,z=0)=>typeof C=="number"||typeof C=="string"?wi(C,k,z):z};for(let C of $.effects)try{C.def.run(O,C.spec);}catch(z){o.onError?.($.def,z);}}}));return ()=>a.forEach(i=>i())}var Si=e=>e.some(t=>t.level==="error");function Ts(e,t,r,o){let n={};for(let[s,a]of Object.entries(e))n[s]=a.default;if(!t)return n;for(let[s,a]of Object.entries(t)){let i=e[s],p=`${r}.${s}`;if(!i){o.push({level:"warning",path:p,code:"PARAM_UNKNOWN",message:`unknown parameter "${s}"`});continue}switch(i.type){case "number":{if(typeof a!="number"||!Number.isFinite(a)){o.push({level:"warning",path:p,code:"PARAM_TYPE",message:"expected a number, default used"});break}let m=i.integer?Math.round(a):a;i.min!==void 0&&m<i.min&&(m=i.min),i.max!==void 0&&m>i.max&&(m=i.max),m!==a&&o.push({level:"warning",path:p,code:"PARAM_CLAMPED",message:`${a} \u2192 ${m}`}),n[s]=m;break}case "enum":typeof a=="string"&&i.values.includes(a)?n[s]=a:o.push({level:"warning",path:p,code:"PARAM_ENUM",message:`not one of ${i.values.join(", ")}, default used`});break;case "boolean":typeof a=="boolean"?n[s]=a:o.push({level:"warning",path:p,code:"PARAM_TYPE",message:"expected true/false, default used"});break;case "string":if(typeof a=="string"){let m=i.maxLength??500;n[s]=a.length>m?a.slice(0,m):a,a.length>m&&o.push({level:"warning",path:p,code:"PARAM_CLAMPED",message:`cut to ${m} characters`});}else o.push({level:"warning",path:p,code:"PARAM_TYPE",message:"expected text, default used"});break}}return n}var Ds=["phaser","three","dom"],dn=Vr("block"),fn=Vr("preset");var zc=["store","premium","character","inventory","lootboxes","boosts","leaderboard","rewards","quests","collections","craft","marketplace","deals","events","coop-events","season","pvp","mailbox","reward-window","idle"],yp=/^system:([a-z][a-z0-9-]*)$/,gp=new Set(["currency","item"]);function Li(e,t,r,o){let n=new Set(e.map(p=>p.id)),s=new Set(t.map(p=>p.id)),a=new Map,i=new Map;r.forEach((p,m)=>{let $=`flows.${m}`;s.has(p.resource)||o.push({level:"error",path:`${$}.resource`,code:"FLOW_RESOURCE_UNKNOWN",message:`no resource "${p.resource}"`});let k=yp.exec(p.by);k?zc.includes(k[1])||o.push({level:"warning",path:`${$}.by`,code:"FLOW_SYSTEM_UNKNOWN",message:`"${p.by}" is not a platform system`}):n.has(p.by)||o.push({level:"error",path:`${$}.by`,code:"FLOW_BY_UNKNOWN",message:`"${p.by}" is neither a mode of the spec nor "system:<id>"`}),p.kind!=="source"&&p.kind!=="sink"&&o.push({level:"error",path:`${$}.kind`,code:"FLOW_KIND",message:'kind is "source" or "sink"'});let O=p.kind==="source"?a:i;O.set(p.resource,(O.get(p.resource)??0)+1);}),t.forEach((p,m)=>{let $=`resources.${m}`,k=a.get(p.id)??0,O=i.get(p.id)??0;k===0&&o.push({level:"error",path:$,code:"RESOURCE_NO_SOURCE",message:`nothing produces "${p.id}"`}),gp.has(p.kind)&&O===0&&o.push({level:"error",path:$,code:"RESOURCE_NO_SINK",message:`nothing spends "${p.id}"`});});}var K=ve("transform"),ie=ve("visual"),Ri=Object.freeze({background:"#1b2133",ground:"#273047",lane:"#313b56",primary:"#4fc3f7",secondary:"#ba68c8",danger:"#ef5350",coin:"#ffd54f",accent:"#66bb6a",text:"#ffffff",muted:"#9aa3b8",piece1:"#ef5350",piece2:"#42a5f5",piece3:"#66bb6a",piece4:"#ffd54f",piece5:"#ab47bc",piece6:"#ff8a3d",panel:"#2b3550"}),_i=/^#[0-9a-fA-F]{6}(?:[0-9a-fA-F]{2})?$/;function Ai(e,t){let r=_i.test(e)?e:t[e]??Ri[e]??t.text??"#ffffff";return _i.test(r)?r.slice(0,7):"#ffffff"}function Ti(e){let t={...Ri};for(let[r,o]of Object.entries(e??{}))typeof o=="string"&&_i.test(o)&&(t[r]=o);return t}var Nt="input",qt="view-resized",Os=Object.freeze({hero:{preset:"knight",races:["human"]},foe:{preset:"berserker",parts:{Hat:null,Offhand:null,Weapon:"weapon/battle_axe"},races:["orc"]},foe2:{preset:"crossbowman",parts:{Weapon:"weapon/broadsword"},races:["undead"]},boss:{preset:"dark_knight",races:["orc"]},helper:{preset:"camper",parts:{Weapon:null,Back:null,Glasses:null},races:["human","elf","dwarf"]},foe3:{preset:"crossbowman",races:["undead"]},foe4:{preset:"viking",parts:{Weapon:"weapon/warhammer"},races:["orc"]},foe5:{preset:"hunter",parts:{Hat:null,Back:null,Weapon:"weapon/dagger"},races:["undead"]},hero2:{preset:"crusader",races:["human"]},hero3:{preset:"archmage",races:["elf"]}}),Di=Object.freeze({style:"default",cast:Os}),Oi="fx";var Fn=Vr("asset-pack"),Wo=Vr("link"),bp=(e,t="en")=>e.names[t]??e.names.en??e.id;function xp(e,t,r){let o=[],n=r.get(Wo,t);if(!n)return o.push({level:"error",path:"link",code:"LINK_UNKNOWN",message:`no link "${t}"`}),{spec:e,systems:[],issues:o};let s=e.modes.find(i=>i.role==="core")??e.modes[0],a=s?r.get(fn,s.preset)?.genre:void 0;return !a||!n.core.includes(a)?(o.push({level:"error",path:"link",code:"LINK_GENRE",message:`link "${t}" fits ${n.core.join(", ")}, not "${a??"?"}"`}),{spec:e,systems:[],issues:o}):{spec:n.apply(e),systems:n.systems,issues:o}}var Vo=1;function Sr(e,t,r){let o=e?.content[t];if(!o||o.length===0)return r;let n=r.filter(s=>!o.includes(s));return n.length>0?n:r}var Hc=Object.freeze({window:"round",adMultiplier:3,vipMultiplier:5}),kp={};function Wc(e,t){let r={...e},o=r.v===void 0?1:r.v;if(typeof o!="number"||!Number.isInteger(o)||o<1)return t.push({level:"error",path:"v",code:"SPEC_VERSION",message:"v must be an integer \u2265 1"}),null;if(o>Vo)return t.push({level:"error",path:"v",code:"SPEC_TOO_NEW",message:`spec v${o} is newer than this kit (v${Vo})`}),null;for(;o<Vo;){let n=kp[o];if(!n)return t.push({level:"error",path:"v",code:"SPEC_NO_MIGRATION",message:`no migration from v${o}`}),null;r=n(r),o++;}return r.v=Vo,r}var Ci=/^[a-z][a-z0-9_]*$/,vp=/^#[0-9a-fA-F]{6}(?:[0-9a-fA-F]{2})?$/,$p=/^[a-z]{2}(?:-[A-Z]{2})?$/,Mp=/^[a-z][a-z0-9_.-]*$/,Bc=["none","async","coop","pvp"],xt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),jo=e=>Array.isArray(e)?e:[];function wp(e,t){let r=[];if(!xt(e))return r.push({level:"error",path:"",code:"SPEC_SHAPE",message:"a spec must be an object"}),{ok:false,issues:r};let o=Wc(e,r);if(!o)return {ok:false,issues:r};let n=o;Ds.includes(n.engine)||r.push({level:"error",path:"engine",code:"SPEC_ENGINE",message:`engine is one of ${Ds.join(", ")}`});let s=jo(n.modes);s.length===0&&r.push({level:"error",path:"modes",code:"SPEC_NO_MODES",message:"a game needs at least one mode"});let a=new Set,i=[];s.forEach((X,ye)=>{let be=`modes.${ye}`;if(!xt(X)){r.push({level:"error",path:be,code:"MODE_SHAPE",message:"a mode must be an object"});return}typeof X.id!="string"||!Ci.test(X.id)?r.push({level:"error",path:`${be}.id`,code:"MODE_ID",message:"mode id: snake_case, starts with a letter"}):a.has(X.id)?r.push({level:"error",path:`${be}.id`,code:"MODE_DUPLICATE",message:`mode "${X.id}" is defined twice`}):a.add(X.id);let fe=typeof X.preset=="string"?t.get(fn,X.preset):void 0;if(!fe){r.push({level:"error",path:`${be}.preset`,code:"MODE_PRESET_UNKNOWN",message:`no preset "${String(X.preset)}"`});return}fe.engine!==n.engine&&r.push({level:"error",path:`${be}.preset`,code:"MODE_ENGINE",message:`preset "${fe.id}" runs on ${fe.engine}, the spec on ${String(n.engine)}`}),X.role!==void 0&&!["core","meta","embedded"].includes(X.role)&&r.push({level:"error",path:`${be}.role`,code:"MODE_ROLE",message:"role is core, meta or embedded"});let we=Ts(fe.params??{},xt(X.params)?X.params:void 0,`${be}.params`,r),de={},Re=new Set(fe.blocks);for(let ce of fe.blocks){let ue=t.get(dn,ce);if(!ue){r.push({level:"error",path:`${be}.preset`,code:"PRESET_BLOCK_UNKNOWN",message:`preset "${fe.id}" uses unknown block "${ce}"`});continue}ue.engines&&!ue.engines.includes(fe.engine)&&r.push({level:"error",path:`${be}.preset`,code:"BLOCK_ENGINE",message:`block "${ce}" is not drawn by ${fe.engine}`});for(let oe of ue.requires??[])Re.has(oe)||r.push({level:"error",path:`${be}.preset`,code:"BLOCK_REQUIRES",message:`block "${ce}" needs "${oe}" in the same preset`});let Pe={};for(let[oe,Ee]of Object.entries(fe.blockParams?.[ce]??{})){let tt=ue.params?.[oe];if(typeof Ee=="string"&&(tt?.type==="number"||tt?.type==="boolean"))try{let Ne=Er(Ee).eval({params:we});Pe[oe]=tt.type==="number"?Number(Ne):!!Ne;}catch(Ne){r.push({level:"error",path:`${be}.preset`,code:"PRESET_FORMULA",message:`preset "${fe.id}", ${ce}.${oe}: ${Ne.message}`});}else Pe[oe]=Ee;}let Le={...Pe,...xt(X.blockParams)&&xt(X.blockParams[ce])?X.blockParams[ce]:{}};de[ce]=Ts(ue.params??{},Le,`${be}.blockParams.${ce}`,r);}if(xt(X.blockParams))for(let ce of Object.keys(X.blockParams))Re.has(ce)||r.push({level:"warning",path:`${be}.blockParams.${ce}`,code:"BLOCK_NOT_IN_PRESET",message:`preset "${fe.id}" has no block "${ce}"`});let Ce=[...fe.rules??[],...jo(X.rules)];As(Ce,t,`${be}.rules`,r);let Me={};if(X.content!==void 0)if(!xt(X.content))r.push({level:"warning",path:`${be}.content`,code:"CONTENT_SHAPE",message:"content is { kind: { without: [ids] } }; ignored"});else for(let[ce,ue]of Object.entries(X.content)){let Pe=xt(ue)?ue.without:void 0;Array.isArray(Pe)&&Pe.every(Le=>typeof Le=="string")?Me[ce]=[...Pe]:r.push({level:"warning",path:`${be}.content.${ce}`,code:"CONTENT_SHAPE",message:"expected { without: [ids] }; ignored"});}i.push({id:X.id,role:X.role??(ye===0?"core":"meta"),preset:fe,params:we,blockParams:de,rules:Ce,content:Me});}),s.length>0&&!s.some((X,ye)=>xt(X)?(X.role??(ye===0?"core":"meta"))==="core":false)&&r.push({level:"error",path:"modes",code:"SPEC_NO_CORE",message:"one mode must be the core (what the player plays)"});let p=jo(n.resources),m=new Set;p.forEach((X,ye)=>{let be=`resources.${ye}`;if(!xt(X)||typeof X.id!="string"||!Ci.test(X.id)){r.push({level:"error",path:be,code:"RESOURCE_ID",message:"resource id: snake_case, starts with a letter"});return}m.has(X.id)&&r.push({level:"error",path:`${be}.id`,code:"RESOURCE_DUPLICATE",message:`resource "${X.id}" is defined twice`}),m.add(X.id),["currency","item","score","local"].includes(X.kind)||r.push({level:"error",path:`${be}.kind`,code:"RESOURCE_KIND",message:"kind is currency, item, score or local"}),(X.kind==="currency"||X.kind==="item")&&X.ref!==void 0&&(typeof X.ref!="string"||X.ref.length===0)&&r.push({level:"error",path:`${be}.ref`,code:"RESOURCE_REF",message:"ref is the engine currency or item id"});});let $=jo(n.flows);$.forEach((X,ye)=>{if(typeof X?.amount=="string"){let be=Mi(X.amount);be&&r.push({level:"error",path:`flows.${ye}.amount`,code:"FLOW_FORMULA",message:be});}}),Li(s.filter(xt),p.filter(X=>xt(X)&&typeof X.id=="string"),$.filter(xt),r);let k=jo(n.rules);As(k,t,"rules",r);let O={};if(n.vars!==void 0)if(!xt(n.vars))r.push({level:"error",path:"vars",code:"VARS_SHAPE",message:"vars must be an object"});else for(let[X,ye]of Object.entries(n.vars))Ci.test(X)?typeof ye=="number"||typeof ye=="string"||typeof ye=="boolean"?O[X]=ye:r.push({level:"error",path:`vars.${X}`,code:"VAR_TYPE",message:"a var is a number, text or true/false"}):r.push({level:"error",path:`vars.${X}`,code:"VAR_NAME",message:"var name: snake_case"});let C=typeof n.assets=="string"&&n.assets?t.get(Fn,n.assets):void 0;if(n.assets!==void 0&&!C&&r.push({level:"warning",path:"assets",code:"ASSETS_UNKNOWN",message:`no asset pack "${String(n.assets)}"; the default look is used`}),n.palette!==void 0)if(!xt(n.palette))r.push({level:"error",path:"palette",code:"PALETTE_SHAPE",message:"palette must be an object"});else for(let[X,ye]of Object.entries(n.palette))(typeof ye!="string"||!vp.test(ye))&&r.push({level:"warning",path:`palette.${X}`,code:"PALETTE_COLOR",message:"a colour is #rrggbb or #rrggbbaa; ignored"});if(n.texts!==void 0)if(!xt(n.texts))r.push({level:"error",path:"texts",code:"TEXTS_SHAPE",message:"texts must be an object"});else for(let[X,ye]of Object.entries(n.texts)){if(Mp.test(X)||r.push({level:"error",path:`texts.${X}`,code:"TEXT_KEY",message:"text key: lower case, digits, _ . -"}),!xt(ye)){r.push({level:"error",path:`texts.${X}`,code:"TEXT_SHAPE",message:"a text is { lang: text }"});continue}for(let[be,fe]of Object.entries(ye))(!$p.test(be)||typeof fe!="string")&&r.push({level:"error",path:`texts.${X}.${be}`,code:"TEXT_LANG",message:"language code like en or pt-BR, value text"});ye.en===void 0&&r.push({level:"warning",path:`texts.${X}`,code:"TEXT_NO_EN",message:"no English text: other languages fall back to it"});}let z={...Hc};if(n.rewards!==void 0)if(!xt(n.rewards))r.push({level:"error",path:"rewards",code:"REWARDS_SHAPE",message:"rewards must be an object"});else {let X=(be,fe,we)=>{let de=n.rewards[be];if(de===void 0)return;if(typeof de!="number"||!Number.isFinite(de)){r.push({level:"warning",path:`rewards.${be}`,code:"PARAM_TYPE",message:"expected a number, default used"});return}let Re=Math.min(Math.max(de,fe),we);Re!==de&&r.push({level:"warning",path:`rewards.${be}`,code:"PARAM_CLAMPED",message:`${de} \u2192 ${Re}`}),z[be]=Re;};X("adMultiplier",1,10),X("vipMultiplier",1,20);let ye=n.rewards.window;ye!==void 0&&(typeof ye=="string"&&/^[A-Za-z0-9_-]{1,64}$/.test(ye)?z.window=ye:r.push({level:"warning",path:"rewards.window",code:"PARAM_TYPE",message:"expected a window id, default used"}));}let F=n.multiplayer??"none";Bc.includes(F)||r.push({level:"error",path:"multiplayer",code:"SPEC_MULTIPLAYER",message:`multiplayer is one of ${Bc.join(", ")}`});let ne=!Si(r);return {ok:ne,issues:r,spec:n,...ne?{resolved:{spec:n,engine:n.engine,seed:typeof n.seed=="string"&&n.seed.length>0?n.seed:"game",modes:i,resources:p,flows:$,rules:k,vars:O,rewards:z,multiplayer:F,palette:Ti({...C?.palette,...xt(n.palette)?n.palette:{}}),texts:Sp(C?.texts,xt(n.texts)?n.texts:void 0),look:{style:C?C.style??C.id:Di.style,cast:Ep({...Os,...C?.cast},n.cast)}}}:{}}}function Ep(e,t){let r={...e};if(!xt(t))return r;for(let[o,n]of Object.entries(t)){if(!xt(n))continue;let s={...r[o]};typeof n.preset=="string"&&(s.preset=n.preset),Array.isArray(n.races)&&n.races.every(a=>typeof a=="string")&&n.races.length>0&&(s.races=n.races),xt(n.parts)&&(s.parts={...s.parts,...n.parts}),xt(n.colors)&&(s.colors={...s.colors,...n.colors}),r[o]=s;}return r}function Sp(e,t){let r={};for(let o of [e,t])for(let[n,s]of Object.entries(o??{}))if(s&&typeof s=="object")for(let[a,i]of Object.entries(s))typeof i=="string"&&((r[n]??={})[a]=i);return r}function Lp(){let e=Ls();return Ho(e),e}function _p(e,t,r,o={}){let n=e.modes.find(i=>i.id===t);if(!n)throw new Error(`game: no mode "${t}"`);let s=new zo({seed:`${e.seed}/${n.id}${o.salt!==void 0?`/${o.salt}`:""}`,vars:e.vars});for(let i of n.preset.blocks)r.require(dn,i).setup?.({world:s,spec:e,mode:n,params:n.blockParams[i]??{},registry:r});let a=Ei(s,[...n.rules,...e.rules],r,{...o.onRuleError?{onError:o.onRuleError}:{}});return s.emit("mode-started",{mode:n.id}),s.flushEvents(),{world:s,mode:n,stop:a}}var Rp=(e,t=0,r=255)=>Math.min(r,Math.max(t,e)),Pi=e=>{let t=/^#[0-9a-fA-F]{6}/.test(e)?e.slice(1,7):"ffffff";return [Number.parseInt(t.slice(0,2),16),Number.parseInt(t.slice(2,4),16),Number.parseInt(t.slice(4,6),16)]},Ap=(e,t,r)=>`#${[e,t,r].map(o=>Math.round(Rp(o)).toString(16).padStart(2,"0")).join("")}`;function qn(e,t,r){let o=Pi(e),n=Pi(t);return Ap(o[0]+(n[0]-o[0])*r,o[1]+(n[1]-o[1])*r,o[2]+(n[2]-o[2])*r)}var W=(e,t)=>qn(e,"#000000",t),Z=(e,t)=>qn(e,"#ffffff",t),Cs=e=>{let[t,r,o]=Pi(e);return (t*.299+r*.587+o*.114)/255},pe=(e,t,r=false)=>`<linearGradient id="${e}" x1="0" y1="0" x2="${r?1:0}" y2="${r?0:1}">${t.map(([o,n,s])=>`<stop offset="${o}" stop-color="${n}"${s===void 0?"":` stop-opacity="${s}"`}/>`).join("")}</linearGradient>`,qe=(e,t,r=.5,o=.5,n=.5)=>`<radialGradient id="${e}" cx="${r}" cy="${o}" r="${n}">${t.map(([s,a,i])=>`<stop offset="${s}" stop-color="${a}"${i===void 0?"":` stop-opacity="${i}"`}/>`).join("")}</radialGradient>`,ae=(...e)=>`<defs>${e.join("")}</defs>`,Sn=e=>(Math.round(e*10)/10).toString(),et=(e,t,r,o,n=5,s=-Math.PI/2)=>{let a=[];for(let i=0;i<n*2;i++){let p=i%2===0?r:o,m=s+i*Math.PI/n;a.push(`${Sn(e+Math.cos(m)*p)},${Sn(t+Math.sin(m)*p)}`);}return a.join(" ")},Tt=(e,t,r,o,n=-Math.PI/2)=>{let s=[];for(let a=0;a<o;a++){let i=n+a*2*Math.PI/o;s.push(`${Sn(e+Math.cos(i)*r)},${Sn(t+Math.sin(i)*r)}`);}return s.join(" ")},Go=(e,t,r,o,n)=>{let s=[],a=o*4;for(let i=0;i<a;i++){let p=i/a*Math.PI*2,m=i%4<2?r:r-n;s.push(`${Sn(e+Math.cos(p)*m)},${Sn(t+Math.sin(p)*m)}`);}return `M${s.join("L")}Z`};function Mr(e){let t=e>>>0||1;return ()=>(t=t*1664525+1013904223>>>0,t/4294967296)}var jc=e=>e==="cozy"?"#5b3b33":e==="sci-fi"?"#05070f":e==="post-apocalypse"?"#1a120c":"#1c1622",q=Sn;var Dt=(e,t,r,o,n=.28)=>`<ellipse cx="${e}" cy="${t}" rx="${r}" ry="${o}" fill="#000" opacity="${n}"/>`,Gr=(e,t=4,r=.55)=>`<path d="${e}" fill="none" stroke="#fff" stroke-width="${t}" stroke-linecap="round" opacity="${r}"/>`,Tp={w:64,h:64,main:"coin",draw({main:e,ink:t,style:r}){let o=W(e,.25),n;return r==="sci-fi"?n=`<polygon points="${Tt(32,31,11,6)}" fill="none" stroke="${W(e,.45)}" stroke-width="3.5"/><circle cx="32" cy="31" r="3.5" fill="${W(e,.45)}"/>`:r==="cozy"?n=`<path d="M32 41 C22 34 19 29 22 25 C25 21 30 22 32 26 C34 22 39 21 42 25 C45 29 42 34 32 41Z" fill="${W(e,.35)}"/>`:r==="post-apocalypse"?n=`<path d="${Go(32,31,13,10,3)}" fill="${W(e,.4)}"/><circle cx="32" cy="31" r="5" fill="${e}"/>`:n=`<polygon points="${et(32,31,12,5.5)}" fill="${W(e,.35)}"/>`,ae(pe("g",[[0,Z(e,.45)],[.55,e],[1,W(e,.2)]]))+`<circle cx="32" cy="35" r="26" fill="${W(e,.5)}" stroke="${t}" stroke-width="3"/><circle cx="32" cy="31" r="26" fill="url(#g)" stroke="${t}" stroke-width="3"/><circle cx="32" cy="31" r="19" fill="none" stroke="${o}" stroke-width="2.5"/>`+n+Gr("M15 24 A19 19 0 0 1 28 12")}},Dp={w:64,h:64,main:"accent",draw({main:e,ink:t}){return Dt(32,59,14,3.5)+`<polygon points="32,4 52,22 44,57 20,57 12,22" fill="${e}" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><polygon points="32,4 12,22 26,24" fill="${Z(e,.5)}"/><polygon points="32,4 26,24 38,24" fill="${Z(e,.3)}"/><polygon points="32,4 38,24 52,22" fill="${W(e,.1)}"/><polygon points="12,22 26,24 20,57" fill="${Z(e,.15)}"/><polygon points="52,22 38,24 44,57" fill="${W(e,.3)}"/><polygon points="26,24 38,24 44,57 20,57" fill="${e}"/>`+Gr("M22 18 L28 10",3,.8)}},Op={w:64,h:64,main:"danger",draw({main:e,ink:t}){return ae(pe("g",[[0,Z(e,.3)],[1,W(e,.25)]]))+`<path d="M32 56 C12 42 5 32 8 21 C11 10 25 8 32 19 C39 8 53 10 56 21 C59 32 52 42 32 56Z" fill="url(#g)" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/>`+Gr("M16 22 C17 16 22 14 26 17",4,.7)}},Cp={w:100,h:100,draw({style:e,ink:t,c:r}){if(e==="sci-fi"){let n=r("primary");return ae(pe("m",[[0,"#5d6f96"],[1,"#2a3452"]]),qe("o",[[0,Z(n,.6)],[.5,n,.9],[1,n,0]]))+Dt(50,95,40,5)+`<rect x="12" y="18" width="76" height="74" rx="10" fill="url(#m)" stroke="${t}" stroke-width="4"/><rect x="20" y="26" width="60" height="10" rx="3" fill="#1a2238"/><rect x="22" y="28" width="56" height="6" rx="2" fill="${n}" opacity="0.85"/><circle cx="50" cy="62" r="20" fill="url(#o)"/><circle cx="50" cy="62" r="11" fill="${Z(n,.3)}" stroke="${t}" stroke-width="3"/><circle cx="22" cy="84" r="3" fill="#9fb2d8"/><circle cx="78" cy="84" r="3" fill="#9fb2d8"/>`}if(e==="cozy"){let n="#f2c862";return ae(pe("h",[[0,Z(n,.25)],[1,W(n,.2)]]))+Dt(50,94,42,5)+`<rect x="8" y="26" width="84" height="66" rx="22" fill="url(#h)" stroke="${t}" stroke-width="4"/>`+[36,50,64,78].map(s=>`<path d="M18 ${s} Q50 ${s-5} 82 ${s}" stroke="${W(n,.25)}" stroke-width="2.5" fill="none"/>`).join("")+`<rect x="30" y="24" width="7" height="70" fill="#c0563d" stroke="${t}" stroke-width="2"/><rect x="63" y="24" width="7" height="70" fill="#c0563d" stroke="${t}" stroke-width="2"/>`+Gr("M20 38 Q30 32 44 33",4,.5)}if(e==="post-apocalypse"){let n="#9a4a26";return ae(pe("r",[[0,"#6a2e18"],[.35,Z(n,.15)],[.7,n],[1,"#4a2010"]],true))+Dt(50,95,34,5)+`<rect x="18" y="10" width="64" height="84" rx="8" fill="url(#r)" stroke="${t}" stroke-width="4"/><rect x="16" y="28" width="68" height="6" fill="#5a2814" stroke="${t}" stroke-width="2"/><rect x="16" y="68" width="68" height="6" fill="#5a2814" stroke="${t}" stroke-width="2"/><polygon points="50,40 62,60 38,60" fill="#e8c23a" stroke="${t}" stroke-width="2.5" stroke-linejoin="round"/><rect x="48.5" y="45" width="3" height="8" fill="${t}"/><circle cx="50" cy="56.5" r="1.8" fill="${t}"/><path d="M24 82 q6 -6 10 2 q4 6 9 0" stroke="#3a1608" stroke-width="3" fill="none" opacity="0.6"/>`}if(e==="fantasy"){let n="#9a6234";return ae(pe("w",[[0,"#5a3418"],[.3,Z(n,.15)],[.7,n],[1,"#4a2a12"]],true))+Dt(50,95,36,5)+`<path d="M24 10 Q14 52 24 94 L76 94 Q86 52 76 10Z" fill="url(#w)" stroke="${t}" stroke-width="4" stroke-linejoin="round"/>`+[38,50,62].map(s=>`<path d="M${s} 12 Q${s+(s-50)*.25} 52 ${s} 92" stroke="${W(n,.35)}" stroke-width="2" fill="none"/>`).join("")+[24,76].map(s=>`<path d="M19 ${s} Q50 ${s+4} 81 ${s}" stroke="#4d525c" stroke-width="7" fill="none"/><path d="M19 ${s-2} Q50 ${s+2} 81 ${s-2}" stroke="#8d939e" stroke-width="2" fill="none"/>`).join("")+Gr("M28 30 Q26 50 28 66",4,.35)}let o="#b07a44";return Dt(50,95,42,5)+`<rect x="10" y="14" width="80" height="80" rx="6" fill="${o}" stroke="${t}" stroke-width="4"/><rect x="18" y="22" width="64" height="64" fill="${W(o,.12)}" stroke="${W(o,.4)}" stroke-width="3"/><path d="M20 24 L80 84 M80 24 L20 84" stroke="${Z(o,.15)}" stroke-width="9"/><path d="M20 24 L80 84 M80 24 L20 84" stroke="${W(o,.4)}" stroke-width="2" fill="none" opacity="0.5"/>`+[18,82].flatMap(n=>[22,86].map(s=>`<circle cx="${n}" cy="${s}" r="3" fill="#6b6f78"/>`)).join("")}},Pp={w:100,h:60,draw({style:e,ink:t,c:r}){let o=[18,50,82];if(e==="sci-fi"){let s=r("danger");return ae(pe("l",[[0,Z(s,.6),.95],[1,s,.2]]))+o.map(a=>`<polygon points="${a-9},52 ${a},6 ${a+9},52" fill="url(#l)"/>`).join("")+o.map(a=>`<line x1="${a}" y1="10" x2="${a}" y2="50" stroke="#fff" stroke-width="2" opacity="0.8"/>`).join("")+`<rect x="2" y="48" width="96" height="11" rx="3" fill="#2a3452" stroke="${t}" stroke-width="3"/>`+o.map(a=>`<circle cx="${a}" cy="53" r="3" fill="${s}"/>`).join("")}if(e==="cozy")return `<path d="M6 58 C2 40 14 26 26 30 C30 14 48 10 54 24 C64 12 86 18 84 34 C98 36 100 52 94 58Z" fill="#6cbf5c" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/>`+[[18,36],[36,24],[56,22],[74,30],[88,44],[28,48],[62,44]].map(([a,i])=>`<polygon points="${a-3},${i+2} ${a},${i-7} ${a+3},${i+2}" fill="#fff4e6" stroke="${t}" stroke-width="1.5"/>`).join("")+'<circle cx="44" cy="40" r="4" fill="#ff8fab"/><circle cx="72" cy="46" r="3.5" fill="#ff8fab"/>';let n=e==="post-apocalypse"?"#8a6a52":"#b9c1cd";return ae(pe("s",[[0,Z(n,.4)],[.5,n],[1,W(n,.45)]],true))+o.map(s=>`<polygon points="${s-14},50 ${s},4 ${s+14},50" fill="url(#s)" stroke="${t}" stroke-width="3" stroke-linejoin="round"/>`).join("")+(e==="post-apocalypse"?'<path d="M2 40 q8 -10 16 0 q8 10 16 0 q8 -10 16 0 q8 10 16 0 q8 -10 16 0 q8 10 16 0" stroke="#5a4a3a" stroke-width="3" fill="none"/>':"")+`<rect x="2" y="47" width="96" height="12" rx="3" fill="${e==="post-apocalypse"?"#4a3a2a":"#5a4636"}" stroke="${t}" stroke-width="3"/>`}},Ip={w:60,h:180,main:"accent",draw({style:e,ink:t,main:r,c:o}){if(e==="sci-fi"){let a=o("primary");return ae(qe("b",[[0,"#fff"],[.4,a],[1,a,0]]))+`<rect x="24" y="30" width="10" height="146" rx="3" fill="#4a5a80" stroke="${t}" stroke-width="3"/><circle cx="29" cy="24" r="22" fill="url(#b)"/><circle cx="29" cy="24" r="8" fill="#fff" stroke="${t}" stroke-width="2"/><rect x="34" y="50" width="24" height="34" rx="3" fill="${r}" opacity="0.75" stroke="${Z(r,.5)}" stroke-width="2"/><rect x="14" y="166" width="30" height="12" rx="3" fill="#2a3452" stroke="${t}" stroke-width="3"/>`}let n=e==="post-apocalypse"?"#7a6a5a":e==="cozy"?"#e8d8c8":"#c8a060",s=e==="post-apocalypse"?`<path d="M30 22 L58 28 L52 40 L58 52 L40 50 L44 60 L30 58Z" fill="${r}" stroke="${t}" stroke-width="3" stroke-linejoin="round"/>`:e==="cozy"?`<path d="M30 22 Q46 16 58 26 Q50 40 58 54 Q44 46 30 56Z" fill="${r}" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><path d="M44 44 C38 40 37 37 39 35 C41 33 43 34 44 36 C45 34 47 33 49 35 C51 37 50 40 44 44Z" fill="#fff"/>`:`<path d="M30 22 L58 22 L58 62 L44 54 L30 62Z" fill="${r}" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><polygon points="${et(44,38,8,3.5)}" fill="${o("coin")}"/>`;return Dt(30,176,18,3.5)+`<rect x="25" y="14" width="8" height="162" rx="3" fill="${n}" stroke="${t}" stroke-width="3"/>`+s+`<circle cx="29" cy="12" r="7" fill="${o("coin")}" stroke="${t}" stroke-width="3"/>`}},Vc={w:64,h:32,main:"primary",draw({style:e,main:t,c:r}){return e==="sci-fi"?ae(pe("t",[[0,t,0],[1,t,.9]],true))+`<rect x="2" y="11" width="44" height="10" rx="5" fill="url(#t)"/><rect x="22" y="9" width="40" height="14" rx="7" fill="${t}"/><rect x="28" y="13" width="30" height="6" rx="3" fill="#fff"/>`:e==="post-apocalypse"?ae(pe("t",[[0,r("coin"),0],[1,r("coin"),.8]],true))+'<rect x="0" y="13" width="44" height="6" rx="3" fill="url(#t)"/><path d="M40 10 L54 10 Q62 16 54 22 L40 22Z" fill="#c9a24a" stroke="#3a2a12" stroke-width="2"/>':e==="cozy"?ae(pe("t",[[0,t,0],[1,t,.7]],true))+`<rect x="0" y="12" width="40" height="8" rx="4" fill="url(#t)"/><polygon points="${et(46,16,14,6)}" fill="${r("coin")}" stroke="#5b3b33" stroke-width="2" stroke-linejoin="round"/>`:ae(pe("t",[[0,t,0],[1,t,.85]],true),qe("o",[[0,"#fff"],[.45,Z(t,.4)],[1,t,0]]))+'<path d="M2 16 Q20 8 40 10 L40 22 Q20 24 2 16Z" fill="url(#t)"/><circle cx="46" cy="16" r="15" fill="url(#o)"/><circle cx="46" cy="16" r="6" fill="#fff"/>'}},Np=e=>({w:100,h:100,main:`piece${e}`,draw({main:t,ink:r}){let o=Z(t,.55),n=Z(t,.2),s=W(t,.32),a=ae(pe("g",[[0,Z(t,.35)],[1,W(t,.25)]])),i=`stroke="${r}" stroke-width="4" stroke-linejoin="round"`,p;switch(e){case 1:p=`<circle cx="50" cy="52" r="40" fill="url(#g)" ${i}/><polygon points="${Tt(50,52,22,8,-Math.PI/8)}" fill="${n}"/><polygon points="${Tt(50,52,22,8,-Math.PI/8).split(" ").slice(5,8).join(" ")} 50,52" fill="${o}"/><polygon points="${Tt(50,52,22,8,-Math.PI/8).split(" ").slice(1,4).join(" ")} 50,52" fill="${s}"/>`;break;case 2:p=`<path d="M50 8 C66 30 84 46 84 64 C84 82 68 92 50 92 C32 92 16 82 16 64 C16 46 34 30 50 8Z" fill="url(#g)" ${i}/><path d="M50 24 C60 40 70 50 70 64 C70 76 60 82 50 82Z" fill="${s}" opacity="0.6"/><path d="M50 24 C40 40 30 50 30 64 C30 76 40 82 50 82Z" fill="${n}" opacity="0.7"/>`;break;case 3:p=`<polygon points="28,10 72,10 90,28 90,72 72,90 28,90 10,72 10,28" fill="url(#g)" ${i}/><polygon points="32,24 68,24 76,32 76,68 68,76 32,76 24,68 24,32" fill="${n}"/><polygon points="28,10 72,10 68,24 32,24" fill="${o}"/><polygon points="90,28 90,72 76,68 76,32" fill="${s}"/><polygon points="36,34 64,34 64,66 36,66" fill="${t}"/>`;break;case 4:p=`<polygon points="${et(50,54,44,20)}" fill="url(#g)" ${i}/><polygon points="${et(50,54,22,10)}" fill="${n}"/><polygon points="50,10 50,54 30,44" fill="${o}" opacity="0.7"/>`;break;case 5:p=`<polygon points="50,6 90,50 50,94 10,50" fill="url(#g)" ${i}/><polygon points="50,6 10,50 50,50" fill="${o}"/><polygon points="50,6 90,50 50,50" fill="${n}"/><polygon points="10,50 50,94 50,50" fill="${t}"/><polygon points="90,50 50,94 50,50" fill="${s}"/><polygon points="50,30 64,50 50,70 36,50" fill="${Z(t,.35)}"/>`;break;default:p=`<polygon points="${Tt(50,50,42,6)}" fill="url(#g)" ${i}/><polygon points="${Tt(50,50,24,6)}" fill="${n}"/><polygon points="${Tt(50,50,42,6).split(" ").slice(4,6).join(" ")} ${Tt(50,50,42,6).split(" ")[0]} 50,50" fill="${o}" opacity="0.6"/><polygon points="${Tt(50,50,42,6).split(" ").slice(1,4).join(" ")} 50,50" fill="${s}" opacity="0.55"/>`;}return a+Dt(50,94,30,4,.22)+p+Gr("M28 30 Q32 22 40 20",5,.75)}}),Ps=e=>`<path d="M24 86 Q50 72 76 86 Q76 94 50 94 Q24 94 24 86Z" fill="#7a5032" stroke="${e}" stroke-width="3"/>`,Un=(e,t,r,o,n,s)=>`<path transform="translate(${e} ${t}) rotate(${r}) scale(${o})" d="M0 0 C6 -10 18 -10 22 0 C18 8 6 8 0 0Z" fill="${n}" stroke="${s}" stroke-width="${q(2.4/o)}"/>`,Ko=(e,t,r,o,n)=>`<circle cx="${e-r*.55}" cy="${t+r*.2}" r="${r*.7}" fill="${W(o,.1)}" stroke="${n}" stroke-width="3"/><circle cx="${e+r*.55}" cy="${t+r*.2}" r="${r*.7}" fill="${W(o,.1)}" stroke="${n}" stroke-width="3"/><circle cx="${e}" cy="${t-r*.15}" r="${r*.85}" fill="${o}" stroke="${n}" stroke-width="3"/><circle cx="${e-r*.3}" cy="${t-r*.4}" r="${r*.3}" fill="${Z(o,.3)}"/>`,Ii=(e,t=50)=>`<path d="M45 92 L47 ${t} L53 ${t} L55 92Z" fill="#8a5a32" stroke="${e}" stroke-width="3" stroke-linejoin="round"/>`;function zp(e,t){let{ink:r}=t,o=t.style==="cozy"?"#7fd36e":"#58b04a",n=t.c("primary");switch(e){case 1:return Dt(50,84,18,4)+`<ellipse cx="50" cy="64" rx="15" ry="20" fill="#b07a44" stroke="${r}" stroke-width="3.5"/>`+Gr("M44 54 Q46 48 50 47",3.5,.6);case 2:return Ps(r)+`<path d="M50 84 Q48 66 50 56" stroke="${W(o,.2)}" stroke-width="5" fill="none" stroke-linecap="round"/>`+Un(50,60,-150,1,o,r)+Un(50,60,-30,1,o,r);case 3:return Ps(r)+`<path d="M50 84 Q47 60 50 38" stroke="${W(o,.2)}" stroke-width="5" fill="none" stroke-linecap="round"/>`+Un(50,66,-160,1.1,o,r)+Un(50,62,-20,1.1,o,r)+Un(50,44,-130,.9,Z(o,.15),r)+Un(50,42,-50,.9,Z(o,.15),r);case 4:return Ps(r)+Ko(50,62,26,o,r);case 5:return Ps(r)+Ko(50,62,28,o,r)+[[34,56],[56,44],[66,64],[46,70]].map(([s,a])=>`<polygon points="${et(s,a,7,3.5,5)}" fill="${n}" stroke="${r}" stroke-width="1.5"/><circle cx="${s}" cy="${a}" r="2" fill="#fff6c0"/>`).join("");case 6:return Dt(50,93,26,4)+Ii(r,52)+Ko(50,40,32,o,r);case 7:return Dt(50,93,28,4)+Ii(r,54)+Ko(50,40,34,W(o,.05),r)+[[34,36],[58,26],[66,46],[44,52],[52,38]].map(([s,a])=>`<circle cx="${s}" cy="${a}" r="5.5" fill="${t.c("danger")}" stroke="${r}" stroke-width="2"/><circle cx="${s-1.5}" cy="${a-1.5}" r="1.6" fill="#fff" opacity="0.8"/>`).join("");default:{let s=t.c("coin");return Dt(50,93,30,4)+Ii(r,54)+Ko(50,38,36,s,r)+[[22,18],[80,22],[74,64],[24,60],[50,6]].map(([a,i])=>`<polygon points="${et(a,i,6,2,4)}" fill="#fff"/>`).join("")}}}function Bp(e,t){let{ink:r}=t,o=t.style==="post-apocalypse"?"#9a8a72":"#a9b8d6",n=t.style==="post-apocalypse"?t.c("coin"):t.c("primary"),s=ae(pe("m",[[0,Z(o,.35)],[1,W(o,.35)]]));switch(e){case 1:return s+Dt(50,88,16,4)+`<rect x="44" y="34" width="12" height="50" rx="2" fill="url(#m)" stroke="${r}" stroke-width="3"/>`+[44,54,64,74].map(a=>`<line x1="44" y1="${a}" x2="56" y2="${a-4}" stroke="${W(o,.45)}" stroke-width="2"/>`).join("")+`<rect x="32" y="22" width="36" height="14" rx="5" fill="url(#m)" stroke="${r}" stroke-width="3"/><line x1="42" y1="29" x2="58" y2="29" stroke="${r}" stroke-width="3"/>`;case 2:return s+Dt(50,86,26,4)+`<polygon points="${Tt(50,54,30,6)}" fill="url(#m)" stroke="${r}" stroke-width="3.5"/><circle cx="50" cy="54" r="12" fill="${W(o,.5)}" stroke="${r}" stroke-width="3"/>`+Gr("M30 42 L42 34",3.5,.6);case 3:return s+Dt(50,90,30,4)+`<path d="${Go(50,52,36,10,8)}" fill="url(#m)" stroke="${r}" stroke-width="3"/><circle cx="50" cy="52" r="12" fill="${W(o,.5)}" stroke="${r}" stroke-width="3"/>`;case 4:return s+Dt(50,90,34,4)+`<path d="${Go(36,60,26,9,6)}" fill="url(#m)" stroke="${r}" stroke-width="3"/><path d="${Go(66,38,22,8,6)}" fill="${Z(o,.1)}" stroke="${r}" stroke-width="3"/><circle cx="36" cy="60" r="8" fill="${n}" stroke="${r}" stroke-width="2.5"/><circle cx="66" cy="38" r="7" fill="${W(o,.5)}" stroke="${r}" stroke-width="2.5"/>`;case 5:return s+Dt(50,90,34,4)+[26,38,50,62,74].map(a=>`<rect x="${a-2}" y="12" width="4" height="12" fill="#c9a24a"/><rect x="${a-2}" y="76" width="4" height="12" fill="#c9a24a"/>`).join("")+`<rect x="18" y="22" width="64" height="56" rx="6" fill="#2a3040" stroke="${r}" stroke-width="3.5"/><rect x="32" y="36" width="36" height="28" rx="3" fill="${n}" opacity="0.85"/><path d="M36 50 H46 V42 H54 V58 H64" stroke="#fff" stroke-width="2.5" fill="none"/>`;case 6:return s+Dt(50,92,22,4)+`<rect x="28" y="20" width="44" height="70" rx="8" fill="url(#m)" stroke="${r}" stroke-width="3.5"/><rect x="40" y="10" width="20" height="12" rx="3" fill="${W(o,.3)}" stroke="${r}" stroke-width="3"/><rect x="34" y="30" width="32" height="52" rx="4" fill="#1d2230"/>`+[0,1,2].map(a=>`<rect x="38" y="${66-a*15}" width="24" height="11" rx="2" fill="${n}" opacity="${.95-a*.25}"/>`).join("");case 7:return s+Dt(50,94,32,4)+`<line x1="50" y1="6" x2="50" y2="20" stroke="${r}" stroke-width="3"/><circle cx="50" cy="6" r="5" fill="${t.c("danger")}" stroke="${r}" stroke-width="2"/><rect x="16" y="20" width="68" height="60" rx="16" fill="url(#m)" stroke="${r}" stroke-width="3.5"/><rect x="26" y="34" width="48" height="24" rx="10" fill="#1d2230"/><circle cx="40" cy="46" r="7" fill="${n}"/><circle cx="60" cy="46" r="7" fill="${n}"/><rect x="38" y="64" width="24" height="6" rx="3" fill="${W(o,.5)}"/><rect x="6" y="38" width="10" height="22" rx="4" fill="${W(o,.2)}" stroke="${r}" stroke-width="3"/><rect x="84" y="38" width="10" height="22" rx="4" fill="${W(o,.2)}" stroke="${r}" stroke-width="3"/>`;default:return s+ae(qe("f",[[0,"#fff"],[.4,t.c("coin")],[1,t.c("danger"),0]]))+`<ellipse cx="50" cy="88" rx="16" ry="12" fill="url(#f)"/><path d="M50 4 C66 18 70 40 66 70 L34 70 C30 40 34 18 50 4Z" fill="url(#m)" stroke="${r}" stroke-width="3.5"/><circle cx="50" cy="34" r="9" fill="${n}" stroke="${r}" stroke-width="3"/><path d="M34 54 L20 76 L34 72Z M66 54 L80 76 L66 72Z" fill="${t.c("danger")}" stroke="${r}" stroke-width="3" stroke-linejoin="round"/>`}}var Hp=e=>({w:100,h:100,draw(t){return t.style==="sci-fi"||t.style==="post-apocalypse"?Bp(e,t):zp(e,t)}}),Wp={w:100,h:100,main:"accent",draw({style:e,ink:t,c:r}){let o=e==="sci-fi"?"#4a5a80":e==="post-apocalypse"?"#5e6a3a":e==="cozy"?"#e09a5a":"#9a5a2c",n=e==="sci-fi"?r("primary"):e==="post-apocalypse"?"#8a8a7a":r("coin");return ae(pe("b",[[0,Z(o,.2)],[1,W(o,.3)]]),pe("l",[[0,Z(o,.35)],[1,o]]))+Dt(50,92,40,5)+`<rect x="10" y="44" width="80" height="46" rx="6" fill="url(#b)" stroke="${t}" stroke-width="4"/><path d="M10 46 L10 34 Q50 4 90 34 L90 46Z" fill="url(#l)" stroke="${t}" stroke-width="4" stroke-linejoin="round"/><rect x="10" y="42" width="80" height="8" fill="${n}" stroke="${t}" stroke-width="3"/><rect x="20" y="18" width="8" height="72" fill="${n}" opacity="0.9"/><rect x="72" y="18" width="8" height="72" fill="${n}" opacity="0.9"/><rect x="40" y="44" width="20" height="22" rx="4" fill="${n}" stroke="${t}" stroke-width="3"/><circle cx="50" cy="54" r="3.5" fill="${t}"/>`+Gr("M18 32 Q34 18 48 16",4,.45)}},Gc={coin:Tp,crystal:Dp,heart:Op,obstacle:Cp,spike:Pp,flag:Ip,shot:Vc,bolt:Vc,chest:Wp,...Object.fromEntries([1,2,3,4,5,6].map(e=>[`gem${e}`,Np(e)])),...Object.fromEntries([1,2,3,4,5,6,7,8].map(e=>[`item${e}`,Hp(e)]))};var pn=(e,t,r)=>q(Math.min(e,t)*r),jp={w:0,h:0,exact:true,main:"panel",draw({w:e,h:t,main:r,ink:o}){let n=Math.max(2,Math.min(Math.min(e,t)*.035,7)),s=q(Math.min(Math.min(e,t)*.14,24)),a=Cs(r)>.6;return ae(pe("p",[[0,Z(r,a?.3:.12)],[1,W(r,a?.06:.25)]]))+`<rect x="${q(n/2)}" y="${q(n*1.5)}" width="${q(e-n)}" height="${q(t-n*2)}" rx="${s}" fill="#000" opacity="0.25"/><rect x="${q(n/2)}" y="${q(n/2)}" width="${q(e-n)}" height="${q(t-n*2)}" rx="${s}" fill="url(#p)" stroke="${a?W(r,.3):o}" stroke-width="${q(n)}"/><rect x="${q(n*2)}" y="${q(n*2)}" width="${q(e-n*4)}" height="${q(Math.max(1,t*.12))}" rx="${pn(e,t,.06)}" fill="#fff" opacity="0.1"/>`}},Vp={w:0,h:0,exact:true,main:"panel",draw({w:e,h:t,main:r,ink:o,c:n}){let s=Math.max(3,e*.03),a=n("coin");return ae(pe("p",[[0,Z(r,.18)],[1,W(r,.3)]]),pe("g",[[0,Z(a,.35)],[1,W(a,.25)]]))+`<rect x="${q(s)}" y="${q(s*2)}" width="${q(e-s*2)}" height="${q(t-s*2.5)}" rx="${pn(e,t,.1)}" fill="#000" opacity="0.35"/><rect x="${q(s)}" y="${q(s)}" width="${q(e-s*2)}" height="${q(t-s*2.5)}" rx="${pn(e,t,.1)}" fill="url(#g)" stroke="${o}" stroke-width="${q(s*.8)}"/><rect x="${q(s*2.4)}" y="${q(s*2.4)}" width="${q(e-s*4.8)}" height="${q(t-s*5.3)}" rx="${pn(e,t,.07)}" fill="url(#p)"/><circle cx="${q(e/2)}" cy="${q(t*.3)}" r="${q(e*.2)}" fill="${a}" opacity="0.18"/>`}},Gp={w:0,h:0,exact:true,main:"accent",draw({w:e,h:t,main:r,ink:o}){let n=Math.max(2,Math.min(e,t)*.06),s=t*.12;return ae(pe("b",[[0,Z(r,.3)],[1,W(r,.1)]]))+`<rect x="${q(n/2)}" y="${q(s)}" width="${q(e-n)}" height="${q(t-s-n/2)}" rx="${pn(e,t,.3)}" fill="${W(r,.45)}" stroke="${o}" stroke-width="${q(n)}"/><rect x="${q(n/2)}" y="${q(n/2)}" width="${q(e-n)}" height="${q(t-s-n/2)}" rx="${pn(e,t,.3)}" fill="url(#b)" stroke="${o}" stroke-width="${q(n)}"/><rect x="${q(e*.12)}" y="${q(t*.12)}" width="${q(e*.76)}" height="${q(t*.16)}" rx="${q(t*.08)}" fill="#fff" opacity="0.35"/>`}},Kp={w:0,h:0,exact:true,main:"ground",draw({w:e,h:t,main:r}){let o=Cs(r)>.55;return ae(pe("c",[[0,W(r,o?.12:.3)],[1,Z(r,o?.1:.06)]]))+`<rect x="1.5" y="1.5" width="${q(e-3)}" height="${q(t-3)}" rx="${pn(e,t,.16)}" fill="url(#c)"/><rect x="1.5" y="1.5" width="${q(e-3)}" height="${q(t-3)}" rx="${pn(e,t,.16)}" fill="none" stroke="#000" stroke-opacity="0.18" stroke-width="2"/>`}},Fp={w:0,h:0,exact:true,main:"panel",draw({w:e,h:t,main:r,ink:o}){let n=t*.16,s=Math.max(2,Math.min(e,t)*.05),i=Cs(r)>.6?Z(r,.4):Z(r,.85);return `<path d="M${q(s)} ${q(s)} H${q(e-s)} V${q(t-n-s)} H${q(e*.58)} L${q(e*.5)} ${q(t-s)} L${q(e*.42)} ${q(t-n-s)} H${q(s)}Z" fill="${i}" stroke="${o}" stroke-width="${q(s)}" stroke-linejoin="round"/>`}},qp={w:100,h:100,draw(){let e="#1c1622",t="#ffffff",r="#d9dde8";return `<ellipse cx="60" cy="96" rx="26" ry="4" fill="#000" opacity="0.18"/><path d="M30 52 L30 14 Q30 5 39 5 Q48 5 48 14 L48 44 Q50 38 57 38 Q64 38 65 45 Q67 40 73 40 Q80 41 80 49 Q82 45 86 46 Q92 48 91 56 L89 76 Q86 92 70 94 L48 94 Q36 93 31 82 L17 64 Q13 58 18 54 Q23 50 28 55 Z" fill="${t}" stroke="${e}" stroke-width="4" stroke-linejoin="round"/><path d="M48 44 L48 58 M65 45 L65 58 M80 49 L80 60" stroke="${e}" stroke-width="3" stroke-linecap="round"/><path d="M34 86 Q44 92 58 91" stroke="${r}" stroke-width="5" fill="none" stroke-linecap="round"/><path d="M35 14 Q36 9 40 9" stroke="${r}" stroke-width="3" fill="none" stroke-linecap="round"/>`}},Up={w:100,h:100,main:"accent",draw({main:e,ink:t}){return ae(pe("p",[[0,Z(e,.35)],[1,W(e,.15)]]))+`<circle cx="50" cy="54" r="44" fill="${W(e,.45)}"/><circle cx="50" cy="50" r="44" fill="url(#p)" stroke="${t}" stroke-width="4"/><circle cx="50" cy="50" r="36" fill="none" stroke="#fff" stroke-opacity="0.35" stroke-width="3"/><path d="M41 30 L72 50 L41 70 Z" fill="#fff" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/><path d="M22 38 Q28 22 44 16" stroke="#fff" stroke-width="5" fill="none" stroke-linecap="round" opacity="0.55"/>`}},Kc={panel:jp,card:Vp,button:Gp,cell:Kp,ticket:Fp,hand:qp,play:Up};var Lr=(e,t=4,r=.55)=>`<path d="${e}" fill="none" stroke="#fff" stroke-width="${t}" stroke-linecap="round" opacity="${r}"/>`,mr=(e,t)=>({w:64,h:64,main:e,draw:({main:r,ink:o})=>t(r,o)}),Xp=mr("primary",(e,t)=>ae(pe("b",[[0,Z(e,.55)],[1,W(e,.15)]]))+`<path d="M32 4 C50 10 58 28 52 46 C48 34 40 26 30 24 C28 16 29 9 32 4Z" fill="url(#b)" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><path d="M32 60 C14 54 6 36 12 18 C16 30 24 38 34 40 C36 48 35 55 32 60Z" fill="url(#b)" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><circle cx="32" cy="32" r="8" fill="${W(e,.35)}" stroke="${t}" stroke-width="3"/><circle cx="32" cy="32" r="3" fill="${Z(e,.6)}"/>`+Lr("M36 9 C44 13 49 20 51 28",3,.7)),Zp=mr("secondary",(e,t)=>ae(qe("a",[[0,Z(e,.7),.95],[.55,e,.55],[1,e,0]]))+`<circle cx="32" cy="32" r="29" fill="url(#a)"/><circle cx="32" cy="32" r="20" fill="none" stroke="${Z(e,.4)}" stroke-width="3" stroke-dasharray="7 5"/><circle cx="32" cy="32" r="10" fill="${Z(e,.5)}" stroke="${t}" stroke-width="2.5"/>`),Qp={w:100,h:100,main:"secondary",draw:({main:e})=>ae(qe("a",[[0,e,.05],[.7,e,.18],[.94,Z(e,.3),.5],[1,Z(e,.4),0]]))+`<circle cx="50" cy="50" r="50" fill="url(#a)"/><circle cx="50" cy="50" r="46" fill="none" stroke="${Z(e,.5)}" stroke-width="1.5" stroke-dasharray="6 6" opacity="0.7"/>`},Yp=mr("accent",(e,t)=>ae(pe("g",[[0,Z(e,.4)],[1,W(e,.25)]]))+`<path d="M8 14 C22 10 34 18 38 30 C46 32 54 42 56 54 C48 50 40 46 32 44 C28 32 20 24 8 14Z" fill="url(#g)" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/><path d="M14 16 C24 16 31 22 34 32" fill="none" stroke="${W(e,.35)}" stroke-width="2.5"/>`+Lr("M14 15 C22 14 28 18 31 24",3,.7)),Jp=mr("primary",(e,t)=>ae(pe("l",[[0,Z(e,.7)],[1,e]]))+`<polygon points="36,3 12,36 28,36 22,61 52,24 35,24 44,3" fill="url(#l)" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/>`+Lr("M33 9 L20 30",3,.75)),e0={w:100,h:20,main:"primary",draw:({main:e})=>`<polyline points="0,10 14,4 26,15 40,5 54,14 66,4 80,15 92,6 100,10" fill="none" stroke="${Z(e,.4)}" stroke-width="7" stroke-linejoin="round" opacity="0.55"/><polyline points="0,10 14,4 26,15 40,5 54,14 66,4 80,15 92,6 100,10" fill="none" stroke="#fff" stroke-width="2.5" stroke-linejoin="round"/>`},t0=mr("piece6",(e,t)=>ae(pe("d",[[0,Z(e,.45)],[1,W(e,.2)]]))+`<rect x="4" y="18" width="20" height="5" rx="2.5" fill="${W(e,.4)}" stroke="${t}" stroke-width="2"/><rect x="40" y="18" width="20" height="5" rx="2.5" fill="${W(e,.4)}" stroke="${t}" stroke-width="2"/><path d="M14 23 L22 32 M50 23 L42 32" stroke="${t}" stroke-width="3"/><ellipse cx="32" cy="38" rx="17" ry="13" fill="url(#d)" stroke="${t}" stroke-width="3"/><circle cx="32" cy="38" r="6" fill="#16223a" stroke="${t}" stroke-width="2"/><circle cx="33.5" cy="36.5" r="2" fill="#7fe7ff"/>`+Lr("M21 32 C24 28 28 27 31 27",3,.6)),r0=mr("danger",(e,t)=>ae(pe("f",[[0,Z(e,.35)],[1,W(e,.2)]]))+`<path d="M14 26 C14 18 20 14 26 15 L46 15 C52 15 54 20 54 25 L54 40 C54 50 46 58 36 58 L28 58 C20 58 14 52 14 44Z" fill="url(#f)" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/>`+[24,34,44].map(r=>`<path d="M${r} 16 L${r} 30" stroke="${W(e,.4)}" stroke-width="2.5"/>`).join("")+`<path d="M14 34 C22 30 30 32 32 38" fill="none" stroke="${t}" stroke-width="3"/>`+Lr("M20 20 C22 18 26 18 30 18",3,.6)),n0=mr("primary",(e,t)=>`<rect x="12" y="5" width="40" height="7" rx="3" fill="${W(e,.3)}" stroke="${t}" stroke-width="3"/><rect x="12" y="52" width="40" height="7" rx="3" fill="${W(e,.3)}" stroke="${t}" stroke-width="3"/><path d="M17 12 C17 26 30 28 30 32 C30 36 17 38 17 52 L47 52 C47 38 34 36 34 32 C34 28 47 26 47 12Z" fill="${Z(e,.75)}" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><path d="M22 49 C24 42 30 40 32 40 C34 40 40 42 42 49Z" fill="${e}"/><path d="M24 16 L40 16 C38 22 34 24 32 26 C30 24 26 22 24 16Z" fill="${e}"/>`),o0=mr("accent",(e,t)=>ae(pe("b",[[0,Z(e,.35)],[1,W(e,.25)]]))+`<path d="M18 6 L38 6 L38 34 L54 40 C58 42 58 50 54 52 L14 52 C12 52 11 50 12 48 L18 34Z" fill="url(#b)" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/><rect x="12" y="52" width="46" height="6" rx="3" fill="${W(e,.45)}" stroke="${t}" stroke-width="3"/><path d="M6 22 L14 22 M3 30 L13 30 M7 38 L13 38" stroke="${Z(e,.5)}" stroke-width="3" stroke-linecap="round"/>`+Lr("M23 11 L23 30",3,.6)),s0=mr("muted",(e,t)=>ae(pe("s",[[0,Z(e,.45)],[1,W(e,.3)]]))+`<path d="M32 4 L54 12 C54 34 46 50 32 60 C18 50 10 34 10 12Z" fill="url(#s)" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/><path d="M32 12 L46 17 C46 32 41 43 32 51Z" fill="${Z(e,.25)}" opacity="0.6"/>`+Lr("M17 16 C17 26 19 34 23 40",3,.55)),a0=mr("danger",(e,t)=>`<path d="M10 8 L24 8 L24 34 C24 40 28 44 32 44 C36 44 40 40 40 34 L40 8 L54 8 L54 34 C54 48 44 58 32 58 C20 58 10 48 10 34Z" fill="${e}" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/><rect x="10" y="8" width="14" height="10" fill="#e8edf5" stroke="${t}" stroke-width="3"/><rect x="40" y="8" width="14" height="10" fill="#e8edf5" stroke="${t}" stroke-width="3"/>`+Lr("M15 26 C15 38 20 46 26 50",3,.55)),i0=mr("accent",(e,t)=>[[32,18],[46,32],[32,46],[18,32]].map(([r,o])=>`<circle cx="${r}" cy="${o}" r="12" fill="${e}" stroke="${t}" stroke-width="3"/>`).join("")+`<circle cx="32" cy="32" r="7" fill="${Z(e,.3)}"/><path d="M36 40 C40 50 44 56 50 60" fill="none" stroke="${t}" stroke-width="3.5" stroke-linecap="round"/>`+Lr("M26 12 C28 9 32 8 35 9",3,.6)),l0=mr("accent",(e,t)=>ae(pe("p",[[0,Z(e,.4)],[1,W(e,.2)]]))+`<rect x="25" y="4" width="14" height="8" rx="2" fill="#b07a44" stroke="${t}" stroke-width="3"/><path d="M26 12 L38 12 L38 22 C48 26 54 34 54 42 C54 52 44 60 32 60 C20 60 10 52 10 42 C10 34 16 26 26 22Z" fill="#e8f2ff" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/><path d="M13 40 C20 36 44 36 51 40 C51 50 43 57 32 57 C21 57 13 50 13 40Z" fill="url(#p)"/>`+Lr("M18 32 C20 28 24 26 27 25",3,.7)),c0=mr("muted",(e,t)=>ae(qe("b",[[0,"#6a7080"],[1,"#1c1f28"]],.35,.35,.7))+`<circle cx="30" cy="38" r="22" fill="url(#b)" stroke="${t}" stroke-width="3.5"/><rect x="34" y="12" width="12" height="10" rx="2" transform="rotate(35 40 17)" fill="#4a4f5c" stroke="${t}" stroke-width="3"/><path d="M44 12 C48 6 54 6 56 10" fill="none" stroke="#b07a44" stroke-width="3"/><polygon points="${et(57,9,7,3,6)}" fill="#ffd54f" stroke="${t}" stroke-width="1.5"/>`+Lr("M18 30 C20 25 24 22 28 21",4,.5)+`<circle cx="30" cy="38" r="22" fill="${e}" opacity="0.08"/>`),d0={w:40,h:40,main:"danger",draw:({main:e,ink:t})=>ae(qe("o",[[0,"#fff"],[.45,Z(e,.3)],[1,e]]))+`<circle cx="20" cy="20" r="17" fill="${e}" opacity="0.35"/><circle cx="20" cy="20" r="11" fill="url(#o)" stroke="${t}" stroke-width="2.5"/>`},f0=mr("text",(e,t)=>`<path d="M32 6 C18 6 9 16 9 28 C9 36 13 41 18 44 L18 54 C18 57 20 58 22 58 L42 58 C44 58 46 57 46 54 L46 44 C51 41 55 36 55 28 C55 16 46 6 32 6Z" fill="${Z(e,.1)}" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/><circle cx="22" cy="30" r="7" fill="${t}"/><circle cx="42" cy="30" r="7" fill="${t}"/><path d="M32 38 L28 45 L36 45Z" fill="${t}"/>`+[26,32,38].map(r=>`<path d="M${r} 50 L${r} 58" stroke="${t}" stroke-width="2.5"/>`).join("")),p0={w:64,h:64,main:"coin",draw:({main:e,ink:t})=>`<polygon points="${et(32,32,29,17,10)}" fill="${Z(e,.25)}" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><polygon points="${Tt(32,32,12,6)}" fill="${e}"/>`},Fc={blade:Xp,aura:Zp,aura_field:Qp,boomerang:Yp,lightning:Jp,zap:e0,drone:t0,fist:r0,hourglass:n0,boot:o0,shield:s0,magnet:a0,clover:i0,potion:l0,bomb:c0,orb:d0,skull:f0,burst:p0};var Ni=(e,t=4,r=.5)=>`<path d="${e}" fill="none" stroke="#fff" stroke-width="${t}" stroke-linecap="round" opacity="${r}"/>`,Is=(e,t)=>e==="sci-fi"?{body:"#4f5f86",trim:t("primary"),dark:"#232c47"}:e==="cozy"?{body:"#d9935a",trim:"#f6d38a",dark:"#7a4a2e"}:e==="post-apocalypse"?{body:"#8a6a52",trim:"#c9a14a",dark:"#3d2f24"}:{body:"#9a6b43",trim:t("accent"),dark:"#4a3322"},h0={w:100,h:60,draw({style:e,ink:t,c:r}){let o=Is(e,r),n=r("danger");return ae(pe("b",[[0,Z(o.trim,.4)],[1,W(o.trim,.15)]]))+`<ellipse cx="50" cy="57" rx="44" ry="3" fill="#000" opacity="0.25"/><rect x="10" y="14" width="9" height="44" rx="3" fill="${o.body}" stroke="${t}" stroke-width="3"/><rect x="81" y="14" width="9" height="44" rx="3" fill="${o.body}" stroke="${t}" stroke-width="3"/><rect x="4" y="10" width="92" height="17" rx="5" fill="url(#b)" stroke="${t}" stroke-width="3.5"/>`+[16,38,60,82].map(s=>`<path d="M${s} 11 L${s+10} 11 L${s+2} 26 L${s-8} 26Z" fill="${n}" opacity="0.9"/>`).join("")+`<rect x="4" y="10" width="92" height="17" rx="5" fill="none" stroke="${t}" stroke-width="3.5"/><rect x="14" y="32" width="72" height="8" rx="3" fill="${W(o.trim,.1)}" stroke="${t}" stroke-width="2.5"/>`+Ni("M12 15 L88 15",2.5,.55)}},u0={w:120,h:40,draw({style:e,ink:t,c:r}){let o=Is(e,r);return ae(qe("p",[[0,"#000000",1],[.7,"#0b0d14",.95],[1,W(o.dark,.2),.9]]))+`<path d="M8 20 C10 6 32 3 60 4 C90 3 112 7 112 20 C112 33 90 37 60 36 C30 37 8 34 8 20Z" fill="${o.dark}" stroke="${t}" stroke-width="3"/><path d="M16 21 C18 11 36 9 60 9 C86 9 104 12 104 21 C104 30 86 32 60 32 C34 32 16 30 16 21Z" fill="url(#p)"/><path d="M20 12 L28 16 L34 10 L44 15 L52 9 L62 14 L72 9 L82 14 L92 10 L100 15" fill="none" stroke="${Z(o.dark,.25)}" stroke-width="2.5" stroke-linejoin="round"/>`}},m0={w:300,h:100,draw({style:e,ink:t,c:r}){let o=Is(e,r),n=r("secondary");return ae(pe("w",[[0,Z(n,.35)],[1,W(n,.3)]]))+`<rect x="4" y="8" width="292" height="72" rx="10" fill="url(#w)" stroke="${t}" stroke-width="4"/><rect x="4" y="8" width="292" height="12" rx="6" fill="${Z(n,.45)}" stroke="${t}" stroke-width="3"/>`+[30,100,170,240].map(s=>`<rect x="${s}" y="30" width="40" height="24" rx="4" fill="${Z(o.trim,.55)}" stroke="${t}" stroke-width="3"/>`).join("")+`<rect x="4" y="64" width="292" height="10" fill="${W(n,.4)}"/>`+[40,90,210,260].map(s=>`<circle cx="${s}" cy="84" r="12" fill="${o.dark}" stroke="${t}" stroke-width="3.5"/><circle cx="${s}" cy="84" r="4" fill="${o.trim}"/>`).join("")+Ni("M14 26 L120 26",3,.4)}},y0={w:140,h:100,draw({style:e,ink:t,c:r}){let o=Is(e,r);return ae(pe("r",[[0,Z(o.trim,.3)],[1,W(o.trim,.25)]]))+`<path d="M4 96 L136 8 L136 96Z" fill="${o.body}" stroke="${t}" stroke-width="4" stroke-linejoin="round"/><path d="M4 96 L136 8 L136 20 L22 96Z" fill="url(#r)" stroke="${t}" stroke-width="3" stroke-linejoin="round"/>`+[0,1,2].map(n=>{let s=60+n*22,a=70-n*15;return `<path d="M${s-8} ${a+6} L${s} ${a-4} L${s+8} ${a+6}" fill="none" stroke="#fff" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" opacity="0.8"/>`}).join("")}},g0={w:100,h:100,draw({style:e,ink:t,c:r}){let o=e==="sci-fi"?"#7c86a8":e==="cozy"?"#b8a99a":"#8f8a82",n=e==="cozy"?"#7ccf6a":e==="sci-fi"?r("primary"):"#6b8f4a";return ae(pe("s",[[0,Z(o,.35)],[1,W(o,.35)]]))+`<ellipse cx="50" cy="95" rx="42" ry="5" fill="#000" opacity="0.28"/><path d="M10 92 C4 70 14 44 30 32 C40 14 66 10 80 26 C96 40 98 70 90 92Z" fill="url(#s)" stroke="${t}" stroke-width="4" stroke-linejoin="round"/><path d="M34 50 L46 62 M62 40 L70 54 M28 74 L40 70" stroke="${W(o,.45)}" stroke-width="3" stroke-linecap="round"/><path d="M30 34 C40 26 52 24 62 28" fill="none" stroke="${n}" stroke-width="6" stroke-linecap="round" opacity="0.85"/>`+Ni("M24 48 C28 38 36 32 44 30",4,.45)}},b0={w:100,h:30,draw:()=>ae(qe("d",[[0,"#000000",.8],[.7,"#000000",.5],[1,"#000000",0]]))+'<ellipse cx="50" cy="15" rx="50" ry="15" fill="url(#d)"/>'},x0={w:60,h:300,draw({ink:e,c:t}){let r="#ffffff",o="#1b1d24",n=[];for(let s=0;s<14;s++)for(let a=0;a<2;a++)n.push(`<rect x="${16+a*14}" y="${18+s*18}" width="14" height="18" fill="${(s+a)%2===0?r:o}"/>`);return `<rect x="10" y="10" width="40" height="270" rx="4" fill="${o}" stroke="${e}" stroke-width="4"/>`+n.join("")+`<rect x="10" y="10" width="40" height="270" rx="4" fill="none" stroke="${e}" stroke-width="4"/><rect x="4" y="276" width="52" height="20" rx="5" fill="${t("accent")}" stroke="${e}" stroke-width="3.5"/><circle cx="30" cy="8" r="7" fill="${t("coin")}" stroke="${e}" stroke-width="3"/>`}},k0={w:64,h:64,main:"coin",draw:({main:e,ink:t})=>ae(qe("c",[[0,Z(e,.5)],[.7,e],[1,W(e,.2)]]))+`<circle cx="24" cy="36" r="18" fill="url(#c)" stroke="${t}" stroke-width="3.5"/><circle cx="40" cy="26" r="18" fill="url(#c)" stroke="${t}" stroke-width="3.5"/><circle cx="40" cy="26" r="11" fill="none" stroke="${W(e,.25)}" stroke-width="2.5"/><rect x="30" y="40" width="30" height="20" rx="7" fill="${W(e,.55)}" stroke="${t}" stroke-width="3"/><path d="M36 45 L43 55 M43 45 L36 55" stroke="#fff" stroke-width="3.2" stroke-linecap="round"/><path d="M47 47 C48 43 55 43 55 47 C55 50 47 53 47 55 L55 55" fill="none" stroke="#fff" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>`},v0={w:64,h:64,main:"secondary",draw:({main:e,ink:t})=>ae(pe("g",[[0,Z(e,.6)],[1,W(e,.15)]]))+`<path d="M32 40 C22 22 10 14 4 14 C6 26 10 40 20 48 C10 48 8 52 6 56 C18 58 28 54 32 48Z" fill="url(#g)" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><path d="M32 40 C42 22 54 14 60 14 C58 26 54 40 44 48 C54 48 56 52 58 56 C46 58 36 54 32 48Z" fill="url(#g)" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><path d="M12 22 C16 30 20 36 26 40 M52 22 C48 30 44 36 38 40" fill="none" stroke="${Z(e,.7)}" stroke-width="2.5" stroke-linecap="round"/><circle cx="32" cy="44" r="5" fill="${Z(e,.4)}" stroke="${t}" stroke-width="2.5"/>`},qc={hurdle:h0,pit:u0,wagon:m0,ramp:y0,rock:g0,shadow:b0,finish:x0,coin2x:k0,wing:v0};var zi=(e,t=4,r=.55)=>`<path d="${e}" fill="none" stroke="#fff" stroke-width="${t}" stroke-linecap="round" opacity="${r}"/>`,$0={w:100,h:100,main:"coin",draw:({main:e,ink:t})=>ae(qe("g",[[0,Z(e,.6),.75],[.6,e,.25],[1,e,0]]),pe("s",[[0,Z(e,.55)],[1,W(e,.25)]]))+`<circle cx="50" cy="52" r="48" fill="url(#g)"/><polygon points="${et(50,54,40,18)}" fill="url(#s)" stroke="${t}" stroke-width="4.5" stroke-linejoin="round"/><polygon points="${et(50,54,22,10)}" fill="${Z(e,.45)}" opacity="0.7"/>`+zi("M38 32 L46 22",4,.75)},M0={w:64,h:64,main:"coin",draw:({main:e,ink:t})=>ae(pe("k",[[0,Z(e,.45)],[1,W(e,.25)]]))+`<circle cx="20" cy="22" r="14" fill="url(#k)" stroke="${t}" stroke-width="3.5"/><circle cx="20" cy="22" r="5.5" fill="${W(e,.5)}"/><path d="M29 31 L54 56 M44 46 L50 40 M50 52 L56 46" stroke="${t}" stroke-width="9" stroke-linecap="round"/><path d="M29 31 L54 56 M44 46 L50 40 M50 52 L56 46" stroke="url(#k)" stroke-width="4.5" stroke-linecap="round"/>`+zi("M12 18 C13 13 16 11 20 10",3,.7)},w0={w:80,h:60,main:"accent",draw:({main:e,ink:t})=>ae(pe("p",[[0,Z(e,.4)],[1,W(e,.2)]]))+`<rect x="14" y="50" width="52" height="8" rx="3" fill="#5a6070" stroke="${t}" stroke-width="3"/><path d="M24 50 L56 44 L24 38 L56 32 L24 26 L56 20" fill="none" stroke="${t}" stroke-width="7" stroke-linejoin="round"/><path d="M24 50 L56 44 L24 38 L56 32 L24 26 L56 20" fill="none" stroke="#c9d1dc" stroke-width="3.5" stroke-linejoin="round"/><rect x="6" y="6" width="68" height="14" rx="6" fill="url(#p)" stroke="${t}" stroke-width="3.5"/>`+zi("M14 10 L60 10",2.5,.6)},Uc={bigstar:$0,key:M0,spring:w0};var Ns=(e,t=4,r=.5)=>`<path d="${e}" fill="none" stroke="#fff" stroke-width="${t}" stroke-linecap="round" opacity="${r}"/>`,Kr=e=>e==="sci-fi"?{stone:"#5d6f96",wood:"#2f3a5c",metal:"#8fa3c8"}:e==="cozy"?{stone:"#f1e2cf",wood:"#c98b5a",metal:"#9aa3b0"}:e==="post-apocalypse"?{stone:"#8a7a62",wood:"#5e4a36",metal:"#7d7466"}:{stone:"#aeb0b8",wood:"#8a5a34",metal:"#6a7080"},Bi=e=>78-e*12,zs='<ellipse cx="50" cy="123" rx="38" ry="7" fill="#000" opacity="0.28"/>';function Xc(e,t,r,o,n){let s="";for(let a=r+10;a<116;a+=11){s+=`<line x1="${e+2}" y1="${a}" x2="${e+t-2}" y2="${a}" stroke="${W(o,.25)}" stroke-width="2"/>`;for(let i=1;i<3;i++){let p=e+t*i/3+((a-r)/11%2?6:0);s+=`<line x1="${p}" y1="${a}" x2="${p}" y2="${a+11}" stroke="${W(o,.25)}" stroke-width="2"/>`;}}return ae(pe("s",[[0,Z(o,.25)],[1,W(o,.22)]],true))+`<rect x="${e}" y="${r}" width="${t}" height="${118-r}" fill="url(#s)" stroke="${n}" stroke-width="3.5"/>`+s+`<path d="M43 118 L43 105 A7 7 0 0 1 57 105 L57 118Z" fill="#3a2a1e" stroke="${n}" stroke-width="2.5"/>`}function E0(e,t,r){let{style:o,ink:n,c:s}=e,a=Kr(o),i=Bi(t)-(r?8:0),p=s(r==="sniper"?"danger":r==="ranger"?"coin":"accent"),m=Xc(28,44,i+18,a.stone,n),$=`<rect x="20" y="${i+8}" width="60" height="12" rx="2" fill="${a.wood}" stroke="${n}" stroke-width="3"/>`+[26,38,50,62,74].map(F=>`<rect x="${F-2}" y="${i-6}" width="4" height="15" fill="${Z(a.wood,.15)}" stroke="${n}" stroke-width="1.5"/>`).join("")+`<rect x="20" y="${i-8}" width="60" height="5" rx="2" fill="${Z(a.wood,.2)}" stroke="${n}" stroke-width="2.5"/>`,k=t>=2?`<polygon points="14,${i-8} 50,${i-36} 86,${i-8}" fill="${p}" stroke="${n}" stroke-width="3.5" stroke-linejoin="round"/><polygon points="14,${i-8} 50,${i-36} 38,${i-8}" fill="${Z(p,.25)}"/>`:"",O=t>=3?`<line x1="50" y1="${i-36}" x2="50" y2="${i-54}" stroke="${n}" stroke-width="3"/><path d="M50 ${i-54} L70 ${i-48} L50 ${i-42}Z" fill="${s("coin")}" stroke="${n}" stroke-width="2"/>`:"",C=(F,ne,X=1)=>`<path d="M${F} ${ne-12*X} Q${F+9*X} ${ne} ${F} ${ne+12*X}" fill="none" stroke="${a.wood}" stroke-width="${3.5*X}" stroke-linecap="round"/><line x1="${F}" y1="${ne-12*X}" x2="${F}" y2="${ne+12*X}" stroke="#eee" stroke-width="1.5"/>`,z=C(66,i-2);return r==="ranger"&&(z=C(30,i-2)+C(68,i-2)),r==="sniper"&&(z=`<rect x="44" y="${i-6}" width="44" height="6" rx="2" fill="${a.metal}" stroke="${n}" stroke-width="2.5"/><rect x="56" y="${i-13}" width="14" height="6" rx="2" fill="${W(a.metal,.3)}" stroke="${n}" stroke-width="2"/>`),zs+m+$+z+k+O+Ns(`M24 ${i+11} L44 ${i+11}`,2.5,.45)}function S0(e,t,r){let{style:o,ink:n,c:s}=e,a=Kr(o),i=Bi(t)+14-(r?6:0),p=ae(pe("b",[[0,Z(a.stone,.3)],[1,W(a.stone,.25)]],true),pe("m",[[0,Z(a.metal,.35)],[1,W(a.metal,.35)]]))+`<path d="M20 118 L24 ${i} L76 ${i} L80 118Z" fill="url(#b)" stroke="${n}" stroke-width="3.5" stroke-linejoin="round"/>`+[0,1,2].map(ne=>`<rect x="${22+ne*20}" y="${i-9}" width="14" height="11" fill="${a.stone}" stroke="${n}" stroke-width="2.5"/>`).join("")+(t>=2?`<rect x="22" y="${i+14}" width="56" height="7" fill="${W(a.stone,.2)}" stroke="${n}" stroke-width="2"/>`:"")+(t>=3?`<rect x="22" y="${i+30}" width="56" height="7" fill="${s("coin")}" stroke="${n}" stroke-width="2"/>`:""),m=r==="bombard"?1.45:1+t*.08,$=34*m,k=13*m,O=`<g transform="rotate(-28 50 ${i-4})"><rect x="46" y="${i-4-k/2}" width="${$}" height="${k}" rx="${k/3}" fill="url(#m)" stroke="${n}" stroke-width="3"/><rect x="${46+$-7}" y="${i-4-k/2-2}" width="8" height="${k+4}" rx="2" fill="${W(a.metal,.3)}" stroke="${n}" stroke-width="2.5"/></g><circle cx="50" cy="${i-4}" r="${9*m}" fill="${W(a.metal,.2)}" stroke="${n}" stroke-width="3"/>`,C=44+$,z=r==="flamer"?`<g transform="rotate(-28 50 ${i-4})"><path d="M${C} ${i-16} C${C+14} ${i-22} ${C+30} ${i-10} ${C+22} ${i-4} C${C+30} ${i+2} ${C+14} ${i+14} ${C} ${i+8}Z" fill="#ff7a1a" stroke="${n}" stroke-width="2.5" stroke-linejoin="round"/><path d="M${C+2} ${i-9} C${C+12} ${i-12} ${C+18} ${i-6} ${C+13} ${i-3} C${C+18} ${i} ${C+10} ${i+6} ${C+2} ${i+2}Z" fill="#ffd34a"/></g>`:"",F=r==="bombard"?`<polygon points="${et(50,i+24,8,3.5)}" fill="${s("danger")}" stroke="${n}" stroke-width="2"/>`:"";return zs+p+O+z+F+Ns(`M28 ${i+4} L28 ${i+40}`,3,.4)}function L0(e,t,r){let{style:o,ink:n,c:s}=e,a=Kr(o),i=64-t*6-(r?4:0),p=r==="storm"?s("coin"):r==="arcane"?Z(s("secondary"),.2):s("secondary"),m=Xc(32,36,i,a.stone,n)+`<rect x="44" y="${i+16}" width="12" height="16" rx="6" fill="${p}" stroke="${n}" stroke-width="2.5" opacity="0.9"/>`,$=i-28,k=`<polygon points="26,${i+2} 50,${$} 74,${i+2}" fill="${s("secondary")}" stroke="${n}" stroke-width="3.5" stroke-linejoin="round"/><polygon points="26,${i+2} 50,${$} 42,${i+2}" fill="${Z(s("secondary"),.25)}"/>`,O=7+t*1.3+(r==="arcane"?3:0),C=Math.max(O+6+(r==="arcane"?8:0),$-O*.5),z=ae(qe("o",[[0,"#ffffff",1],[.45,p,.95],[1,p,.3]]))+`<circle cx="50" cy="${C}" r="${O+7}" fill="${p}" opacity="0.25"/><circle cx="50" cy="${C}" r="${O}" fill="url(#o)" stroke="${n}" stroke-width="2.5"/>`,F=r==="storm"?[-1,1].map(ne=>`<path d="M${50+ne*(O+3)} ${C-6} L${50+ne*(O+10)} ${C} L${50+ne*(O+5)} ${C+2} L${50+ne*(O+13)} ${C+10}" fill="none" stroke="${s("coin")}" stroke-width="3" stroke-linejoin="round"/>`).join(""):r==="arcane"?`<circle cx="50" cy="${C}" r="${O+11}" fill="none" stroke="${p}" stroke-width="2.5" stroke-dasharray="5 4"/>`:"";return zs+m+k+z+F}function _0(e,t,r){let{style:o,ink:n,c:s}=e,a=Kr(o),i=Bi(t)+10-(r?6:0),p=r==="glacier"?W(s("primary"),.15):Z(s("primary"),.35),m=ae(pe("p",[[0,Z(a.stone,.25)],[1,W(a.stone,.25)]],true),pe("i",[[0,"#ffffff"],[.5,p],[1,W(p,.25)]]))+`<path d="M24 118 L28 ${i+18} L72 ${i+18} L76 118Z" fill="url(#p)" stroke="${n}" stroke-width="3.5" stroke-linejoin="round"/>`,$=(C,z,F,ne)=>`<g transform="rotate(${ne} ${C} ${i+20})"><polygon points="${C-F},${i+20} ${C-F*.8},${i+20-z*.75} ${C},${i+20-z} ${C+F*.8},${i+20-z*.75} ${C+F},${i+20}" fill="url(#i)" stroke="${n}" stroke-width="2.5" stroke-linejoin="round"/><line x1="${C}" y1="${i+20-z}" x2="${C}" y2="${i+18}" stroke="#fff" stroke-width="1.5" opacity="0.6"/></g>`,k=$(50,38+t*6,10,0);t>=2&&(k=$(36,26+t*3,7,-14)+$(64,26+t*3,7,14)+k),t>=3&&(k=$(28,20,5,-26)+$(72,20,5,26)+k),r==="glacier"&&(k+=$(50,70,15,0));let O=r==="blizzard"?[0,1,2,3,4].map(C=>`<polygon points="${et(22+C*14,i-30+C%2*12,5,2,6)}" fill="#fff" stroke="${n}" stroke-width="1.2"/>`).join(""):"";return zs+m+k+O}var R0={archer:E0,cannon:S0,mage:L0,frost:_0},Ot=(e,t,r="")=>({w:100,h:130,draw:o=>R0[e](o,t,r)}),A0={w:100,h:64,draw({style:e,ink:t,c:r}){let o=Kr(e),n=Array.from({length:10},(s,a)=>{let i=a/10*Math.PI*2;return `<ellipse cx="${(50+Math.cos(i)*38).toFixed(1)}" cy="${(34+Math.sin(i)*20).toFixed(1)}" rx="9" ry="6" fill="${a%2?o.stone:Z(o.stone,.15)}" stroke="${t}" stroke-width="2.5"/>`}).join("");return `<ellipse cx="50" cy="34" rx="40" ry="22" fill="${W(o.stone,.45)}" opacity="0.55"/>`+n+`<line x1="78" y1="30" x2="78" y2="6" stroke="${t}" stroke-width="2.5"/><path d="M78 6 L92 10 L78 15Z" fill="${r("coin")}" stroke="${t}" stroke-width="1.5"/>`}},T0={w:100,h:100,draw({style:e,ink:t,c:r}){let o=Kr(e),n=a=>`<rect x="${a}" y="22" width="22" height="72" fill="${o.stone}" stroke="${t}" stroke-width="3"/>`+[0,1].map(i=>`<rect x="${a+i*13}" y="13" width="9" height="11" fill="${o.stone}" stroke="${t}" stroke-width="2.5"/>`).join("")+`<polygon points="${a-3},22 ${a+11},2 ${a+25},22" fill="${r("danger")}" stroke="${t}" stroke-width="3" stroke-linejoin="round"/>`,s="";for(let a=38;a<=62;a+=6)s+=`<line x1="${a}" y1="52" x2="${a}" y2="94" stroke="${W(o.metal,.3)}" stroke-width="3"/>`;return `<ellipse cx="50" cy="95" rx="46" ry="5" fill="#000" opacity="0.28"/><rect x="22" y="36" width="56" height="58" fill="${Z(o.stone,.1)}" stroke="${t}" stroke-width="3.5"/><path d="M34 94 L34 60 A16 16 0 0 1 66 60 L66 94Z" fill="#241a14" stroke="${t}" stroke-width="3"/>`+s+n(8)+n(70)+`<rect x="44" y="40" width="12" height="9" fill="${r("coin")}" stroke="${t}" stroke-width="2"/>`}},D0={w:100,h:90,draw({style:e,ink:t}){let r=Kr(e);return `<path d="M6 86 C6 40 26 10 50 10 C74 10 94 40 94 86Z" fill="${W(r.stone,.15)}" stroke="${t}" stroke-width="4" stroke-linejoin="round"/><path d="M24 86 C24 52 36 30 50 30 C64 30 76 52 76 86Z" fill="#120c10" stroke="${t}" stroke-width="3"/><circle cx="42" cy="58" r="3" fill="#ff5a3a"/><circle cx="56" cy="58" r="3" fill="#ff5a3a"/>`}},O0={w:100,h:130,draw({style:e,ink:t,c:r}){let o=Kr(e),n=e==="post-apocalypse"?"#6b6a3a":e==="sci-fi"?r("secondary"):e==="cozy"?"#6fcf6a":"#3f8f3a";return e==="post-apocalypse"?`<ellipse cx="50" cy="124" rx="26" ry="5" fill="#000" opacity="0.28"/><path d="M46 124 L48 60 L30 40 M48 70 L68 46 M48 84 L32 74" fill="none" stroke="${o.wood}" stroke-width="8" stroke-linecap="round"/><path d="M46 124 L48 60" stroke="${t}" stroke-width="2" opacity="0.4"/>`:ae(qe("l",[[0,Z(n,.35),1],[1,W(n,.2),1]],.4,.35,.65))+`<ellipse cx="50" cy="124" rx="30" ry="6" fill="#000" opacity="0.28"/><rect x="42" y="78" width="16" height="46" rx="4" fill="${o.wood}" stroke="${t}" stroke-width="3"/>`+(e==="sci-fi"?`<polygon points="${Tt(50,50,36,6)}" fill="url(#l)" stroke="${t}" stroke-width="3.5"/>`:`<circle cx="34" cy="62" r="24" fill="url(#l)" stroke="${t}" stroke-width="3.5"/><circle cx="66" cy="62" r="24" fill="url(#l)" stroke="${t}" stroke-width="3.5"/><circle cx="50" cy="38" r="28" fill="url(#l)" stroke="${t}" stroke-width="3.5"/>`)+Ns("M36 26 C42 20 50 18 56 20",4,.4)}},C0={w:100,h:70,draw({style:e,ink:t,c:r}){let o=e==="post-apocalypse"?"#7a6a3a":e==="sci-fi"?r("secondary"):e==="cozy"?"#7fd87a":"#4a9a3e";return `<ellipse cx="50" cy="64" rx="40" ry="5" fill="#000" opacity="0.25"/><circle cx="30" cy="44" r="20" fill="${o}" stroke="${t}" stroke-width="3"/><circle cx="70" cy="44" r="20" fill="${o}" stroke="${t}" stroke-width="3"/><circle cx="50" cy="32" r="24" fill="${Z(o,.12)}" stroke="${t}" stroke-width="3"/>`+[30,54,70].map((n,s)=>`<circle cx="${n}" cy="${36+s%2*10}" r="4" fill="${r(s===1?"coin":"danger")}"/>`).join("")}},P0={w:100,h:30,draw:({ink:e})=>`<line x1="10" y1="15" x2="80" y2="15" stroke="#8a5a34" stroke-width="5" stroke-linecap="round"/><polygon points="78,6 98,15 78,24" fill="#d8dde6" stroke="${e}" stroke-width="2.5" stroke-linejoin="round"/><path d="M4 7 L20 15 L4 23 M12 7 L26 15 L12 23" fill="none" stroke="#e8e0d0" stroke-width="3"/>`},I0={w:100,h:100,main:"danger",draw:({main:e,ink:t})=>ae(qe("f",[[0,"#fff6c0",1],[.4,"#ffb23a",1],[1,e,.9]]))+`<path d="M62 10 C82 18 96 30 98 40 L70 62 Z" fill="#ff8a2a" opacity="0.75"/><path d="M50 16 C70 26 84 40 86 52 L60 66 Z" fill="#ffd34a" opacity="0.6"/><circle cx="40" cy="62" r="26" fill="url(#f)" stroke="${t}" stroke-width="3.5"/><circle cx="32" cy="56" r="5" fill="${W(e,.35)}"/><circle cx="48" cy="70" r="4" fill="${W(e,.35)}"/>`},N0={w:100,h:80,main:"coin",draw:({main:e,ink:t})=>{let r=(o,n)=>`<polygon points="${o},${n+18} ${o+6},${n} ${o+34},${n} ${o+40},${n+18}" fill="url(#g)" stroke="${t}" stroke-width="3" stroke-linejoin="round"/>`+Ns(`M${o+10} ${n+5} L${o+24} ${n+5}`,2.5,.7);return ae(pe("g",[[0,Z(e,.5)],[1,W(e,.25)]]))+'<ellipse cx="50" cy="74" rx="44" ry="5" fill="#000" opacity="0.25"/>'+r(8,52)+r(52,52)+r(30,32)+r(30,12)}},z0={w:100,h:100,draw:({ink:e})=>`<path d="M14 86 L86 14 M14 14 L86 86" stroke="#d8dde6" stroke-width="9" stroke-linecap="round"/><path d="M14 86 L86 14 M14 14 L86 86" stroke="${e}" stroke-width="2.5" stroke-linecap="round" opacity="0.6"/><path d="M26 46 C26 24 38 14 50 14 C62 14 74 24 74 46 C74 58 68 62 64 64 L64 76 L36 76 L36 64 C32 62 26 58 26 46Z" fill="#f4efe4" stroke="${e}" stroke-width="4" stroke-linejoin="round"/><circle cx="40" cy="46" r="8" fill="#2a1e1e"/><circle cx="60" cy="46" r="8" fill="#2a1e1e"/><path d="M50 54 L46 62 L54 62Z" fill="#2a1e1e"/><path d="M42 76 L42 68 M50 76 L50 68 M58 76 L58 68" stroke="${e}" stroke-width="2.5"/>`},B0={w:100,h:100,draw({style:e,ink:t,c:r}){let o=Kr(e),n=r("danger");return `<rect x="30" y="30" width="34" height="56" fill="${o.stone}" stroke="${t}" stroke-width="3.5"/>`+[30,41,52].map(s=>`<rect x="${s+1}" y="20" width="8" height="11" fill="${o.stone}" stroke="${t}" stroke-width="2.5"/>`).join("")+`<path d="M41 86 L41 74 A6 6 0 0 1 53 74 L53 86Z" fill="#3a2a1e" stroke="${t}" stroke-width="2.5"/><circle cx="47" cy="52" r="38" fill="none" stroke="${t}" stroke-width="13"/><circle cx="47" cy="52" r="38" fill="none" stroke="${n}" stroke-width="8"/><line x1="20" y1="79" x2="74" y2="25" stroke="${t}" stroke-width="13" stroke-linecap="round"/><line x1="20" y1="79" x2="74" y2="25" stroke="${n}" stroke-width="8" stroke-linecap="round"/>`+ae(pe("g",[[0,Z(r("coin"),.45)],[1,W(r("coin"),.2)]]))+`<circle cx="78" cy="80" r="17" fill="url(#g)" stroke="${t}" stroke-width="3.5"/><path d="M78 71 L78 89 M69 80 L87 80" stroke="${W(r("coin"),.45)}" stroke-width="4" stroke-linecap="round"/>`}},Zc={td_sell:B0,td_archer1:Ot("archer",1),td_archer2:Ot("archer",2),td_archer3:Ot("archer",3),td_archer_ranger:Ot("archer",3,"ranger"),td_archer_sniper:Ot("archer",3,"sniper"),td_cannon1:Ot("cannon",1),td_cannon2:Ot("cannon",2),td_cannon3:Ot("cannon",3),td_cannon_bombard:Ot("cannon",3,"bombard"),td_cannon_flamer:Ot("cannon",3,"flamer"),td_mage1:Ot("mage",1),td_mage2:Ot("mage",2),td_mage3:Ot("mage",3),td_mage_arcane:Ot("mage",3,"arcane"),td_mage_storm:Ot("mage",3,"storm"),td_frost1:Ot("frost",1),td_frost2:Ot("frost",2),td_frost3:Ot("frost",3),td_frost_glacier:Ot("frost",3,"glacier"),td_frost_blizzard:Ot("frost",3,"blizzard"),td_spot:A0,td_gate:T0,td_portal:D0,td_tree:O0,td_bush:C0,td_arrow:P0,td_meteor:I0,td_gold:N0,td_call:z0};var Fo=(e,t=4,r=.5)=>`<path d="${e}" fill="none" stroke="#fff" stroke-width="${t}" stroke-linecap="round" opacity="${r}"/>`,H0={w:100,h:100,draw:({ink:e})=>{let r=["#ff5a5a","#ffb03a","#ffe14a","#5ad35a","#4aa8ff","#a26bff"].map((o,n)=>{let s=n/6*Math.PI*2,a=(n+1)/6*Math.PI*2,i=p=>`${(50+Math.cos(p)*38).toFixed(1)} ${(50+Math.sin(p)*38).toFixed(1)}`;return `<path d="M50 50 L${i(s)} A38 38 0 0 1 ${i(a)}Z" fill="${o}"/>`});return ae(qe("g",[[0,"#ffffff",.95],[.5,"#ffffff",.2],[1,"#ffffff",0]],.38,.35,.5))+'<circle cx="50" cy="50" r="46" fill="#ffffff" opacity="0.25"/>'+r.join("")+`<circle cx="50" cy="50" r="38" fill="url(#g)" stroke="${e}" stroke-width="4"/><polygon points="${et(50,50,13,6)}" fill="#fff" opacity="0.9"/>`}},Qc=e=>({w:100,h:100,draw:({ink:t})=>{let r=`<path d="M8 50 L24 38 L24 45 L76 45 L76 38 L92 50 L76 62 L76 55 L24 55 L24 62Z" fill="#fff" stroke="${t}" stroke-width="3" stroke-linejoin="round"/>`;return `<g ${e?'transform="rotate(90 50 50)"':""} opacity="0.95">${r}</g>`}}),W0={w:100,h:100,draw:({ink:e})=>`<circle cx="50" cy="50" r="40" fill="none" stroke="#fff" stroke-width="7" opacity="0.9"/><circle cx="50" cy="50" r="40" fill="none" stroke="${e}" stroke-width="2" opacity="0.6"/><polygon points="${et(78,20,13,5,8)}" fill="#ffd34a" stroke="${e}" stroke-width="2"/>`},Yc=e=>({w:100,h:100,draw:({ink:t})=>ae(pe("i",[[0,"#e6f6ff",.75],[1,"#7cc4ff",e>1?.85:.6]]))+`<rect x="3" y="3" width="94" height="94" rx="12" fill="url(#i)" stroke="${t}" stroke-width="3" opacity="0.95"/>`+(e>1?'<rect x="12" y="12" width="76" height="76" rx="8" fill="none" stroke="#fff" stroke-width="4" opacity="0.8"/>':"")+Fo("M14 30 L30 14",5,.8)+Fo("M70 88 L86 72",4,.5)}),j0={w:100,h:100,draw:({ink:e})=>`<path d="M4 20 C4 8 14 4 24 6 C36 0 56 10 64 4 C78 0 96 8 96 22 L96 80 C96 94 84 98 72 94 C60 100 44 90 30 96 C16 100 4 92 4 80Z" fill="#8edc4a" opacity="0.6" stroke="${e}" stroke-width="3"/><circle cx="28" cy="70" r="6" fill="#c6f58a" opacity="0.9"/><circle cx="72" cy="30" r="5" fill="#c6f58a" opacity="0.9"/>`},V0={w:100,h:100,draw:({ink:e})=>{let t=(r,o,n)=>`<rect x="${r-14}" y="${o-8}" width="28" height="16" rx="8" fill="none" stroke="#9aa3b0" stroke-width="7" transform="rotate(${n} ${r} ${o})"/><rect x="${r-14}" y="${o-8}" width="28" height="16" rx="8" fill="none" stroke="${e}" stroke-width="1.5" transform="rotate(${n} ${r} ${o})"/>`;return [t(18,18,45),t(36,36,45),t(64,64,45),t(82,82,45),t(82,18,-45),t(64,36,-45),t(36,64,-45),t(18,82,-45)].join("")+`<circle cx="50" cy="50" r="12" fill="#c9a14a" stroke="${e}" stroke-width="3"/><rect x="46" y="48" width="8" height="10" fill="${e}"/>`}},Jc=e=>({w:100,h:100,draw:({style:t,ink:r})=>{let o=t==="sci-fi"?"#7c86a8":t==="cozy"?"#b8a99a":"#8f8a82";return ae(pe("s",[[0,Z(o,.35)],[1,W(o,.35)]]))+`<path d="M10 30 L28 8 L72 6 L92 26 L94 72 L74 94 L26 94 L6 72Z" fill="url(#s)" stroke="${r}" stroke-width="4" stroke-linejoin="round"/>`+(e?"":`<path d="M30 30 L44 50 L36 70 M60 24 L66 44 L80 54" fill="none" stroke="${W(o,.5)}" stroke-width="3.5" stroke-linecap="round"/>`)+(e?`<path d="M30 40 L70 40 M30 60 L70 60" stroke="${W(o,.4)}" stroke-width="4"/>`:"")+Fo("M20 30 L34 14",4,.45)}}),G0={w:100,h:100,draw:({ink:e,c:t})=>{let r="";for(let o=18;o<=82;o+=16)r+=`<line x1="${o}" y1="18" x2="${o}" y2="88" stroke="#b07a3a" stroke-width="5"/>`;return `<circle cx="50" cy="58" r="22" fill="${t("coin")}" stroke="${e}" stroke-width="3"/><circle cx="42" cy="54" r="4" fill="${e}"/><circle cx="58" cy="54" r="4" fill="${e}"/><path d="M44 66 Q50 71 56 66" fill="none" stroke="${e}" stroke-width="3" stroke-linecap="round"/><path d="M34 40 L30 28 L42 36Z M66 40 L70 28 L58 36Z" fill="${t("coin")}" stroke="${e}" stroke-width="2.5"/>`+r+`<rect x="10" y="10" width="80" height="10" rx="4" fill="#8a5a2a" stroke="${e}" stroke-width="3"/><rect x="10" y="86" width="80" height="10" rx="4" fill="#8a5a2a" stroke="${e}" stroke-width="3"/>`}},K0={w:100,h:100,draw:({ink:e})=>ae(pe("w",[[0,"#d9a066"],[1,"#9a6236"]]))+`<rect x="8" y="8" width="84" height="84" rx="6" fill="url(#w)" stroke="${e}" stroke-width="4"/><rect x="16" y="16" width="68" height="68" fill="none" stroke="#7a4a26" stroke-width="4"/><path d="M18 18 L82 82 M82 18 L18 82" stroke="#7a4a26" stroke-width="6"/><path d="M50 30 L50 64 M38 54 L50 66 L62 54" fill="none" stroke="#fff4d0" stroke-width="7" stroke-linecap="round" stroke-linejoin="round"/>`},F0={w:100,h:100,main:"danger",draw:({main:e,ink:t})=>ae(pe("h",[[0,Z(e,.45)],[1,W(e,.2)]]))+`<path d="M50 88 C20 66 8 50 8 32 C8 18 20 8 32 8 C40 8 46 12 50 20 C54 12 60 8 68 8 C80 8 92 18 92 32 C92 50 80 66 50 88Z" fill="url(#h)" stroke="${t}" stroke-width="4.5" stroke-linejoin="round"/>`+Fo("M22 30 C22 22 28 18 34 18",5,.7)},q0={w:100,h:100,main:"primary",draw:({main:e,ink:t})=>ae(pe("s",[[0,Z(e,.45)],[1,W(e,.25)]]))+`<path d="M50 6 L88 18 L86 52 C84 74 68 88 50 96 C32 88 16 74 14 52 L12 18Z" fill="url(#s)" stroke="${t}" stroke-width="4.5" stroke-linejoin="round"/><path d="M50 20 L74 28 L72 52 C70 66 60 76 50 82Z" fill="${Z(e,.3)}" opacity="0.7"/>`+Fo("M24 26 L36 22",4,.7)},U0={w:100,h:100,draw:({ink:e})=>ae(qe("f",[[0,"#fff6c0",1],[.45,"#ffb23a",1],[1,"#e0442e",1]]))+`<polygon points="${et(50,50,46,22,10)}" fill="url(#f)" stroke="${e}" stroke-width="4" stroke-linejoin="round"/><circle cx="50" cy="50" r="12" fill="#fff6c0"/>`},X0={w:100,h:100,draw:({ink:e,c:t})=>`<path d="M40 6 L60 6 L60 40 L94 40 L94 60 L60 60 L60 94 L40 94 L40 60 L6 60 L6 40 L40 40Z" fill="${t("coin")}" stroke="${e}" stroke-width="4" stroke-linejoin="round"/><circle cx="50" cy="50" r="13" fill="#fffbe0" stroke="${e}" stroke-width="3"/>`},Z0={w:100,h:100,draw:({ink:e,c:t})=>`<path d="M20 44 C10 44 6 34 12 26 C16 18 26 18 30 22 C34 10 52 8 60 18 C70 12 86 18 86 30 C96 32 96 46 84 48Z" fill="#d8e2f0" stroke="${e}" stroke-width="4" stroke-linejoin="round"/><path d="M48 48 L36 72 L50 72 L42 96 L68 62 L54 62 L62 48Z" fill="${t("coin")}" stroke="${e}" stroke-width="3.5" stroke-linejoin="round"/>`},ed={m3_rainbow:H0,m3_row:Qc(false),m3_col:Qc(true),m3_bomb:W0,m3_ice:Yc(1),m3_ice2:Yc(2),m3_slime:j0,m3_chain:V0,m3_stone:Jc(false),m3_stone2:Jc(true),m3_cage:G0,m3_crate:K0,m3_heart:F0,m3_shield:q0,m3_skill_blast:U0,m3_skill_cross:X0,m3_skill_storm:Z0};var St=(e,t,r,o,n=.28)=>`<ellipse cx="${e}" cy="${t}" rx="${r}" ry="${o}" fill="#000" opacity="${n}"/>`,br=(e,t=4,r=.55)=>`<path d="${e}" fill="none" stroke="#fff" stroke-width="${t}" stroke-linecap="round" opacity="${r}"/>`,Jt=e=>({w:100,h:100,draw:({ink:t})=>e(t)}),qo="#e8b84a",Ln="#c9803a",Q0=e=>Jt(t=>{switch(e){case 1:{let r=[0,1,2,3].map(o=>`<ellipse cx="${44-o%2*0}" cy="${30+o*11}" rx="7" ry="5" fill="${qo}" stroke="${t}" stroke-width="2.5" transform="rotate(-30 44 ${30+o*11})"/><ellipse cx="57" cy="${30+o*11}" rx="7" ry="5" fill="${Z(qo,.1)}" stroke="${t}" stroke-width="2.5" transform="rotate(30 57 ${30+o*11})"/>`);return St(50,90,14,3)+`<path d="M50 90 L50 22" stroke="${W(qo,.3)}" stroke-width="4" stroke-linecap="round"/>`+r.join("")+`<ellipse cx="50" cy="20" rx="5" ry="8" fill="${qo}" stroke="${t}" stroke-width="2.5"/>`}case 2:return ae(pe("s",[[0,"#f6ecd6"],[1,"#d6c29a"]]))+St(50,90,28,5)+`<path d="M24 40 Q22 86 30 88 L70 88 Q78 86 76 40 Q50 30 24 40Z" fill="url(#s)" stroke="${t}" stroke-width="3.5"/><path d="M28 40 Q38 22 50 30 Q62 22 72 40" fill="#f6ecd6" stroke="${t}" stroke-width="3"/><path d="M36 38 L64 38" stroke="${Ln}" stroke-width="5"/><path d="M50 52 L56 62 L50 72 L44 62Z" fill="${qo}" stroke="${t}" stroke-width="2"/><circle cx="50" cy="20" r="6" fill="#fff" opacity="0.9"/><circle cx="58" cy="16" r="4" fill="#fff" opacity="0.8"/>`;case 3:return ae(qe("d",[[0,"#fff6e6"],[1,"#e8cfa2"]],.4,.35))+St(50,86,30,5)+`<path d="M18 70 Q14 44 36 38 Q50 30 64 38 Q86 44 82 70 Q78 84 50 84 Q22 84 18 70Z" fill="url(#d)" stroke="${t}" stroke-width="3.5"/>`+br("M30 52 Q36 44 46 42",4,.7);case 4:return ae(pe("b",[[0,"#f0b25a"],[1,Ln]]))+St(50,86,32,5)+`<path d="M16 72 Q14 40 50 34 Q86 40 84 72 Q80 84 50 84 Q20 84 16 72Z" fill="url(#b)" stroke="${t}" stroke-width="3.5"/>`+[[36,50],[50,46],[64,50],[44,60],[58,60]].map(([r,o])=>`<ellipse cx="${r}" cy="${o}" rx="3" ry="1.8" fill="#fff6d6" stroke="${t}" stroke-width="1"/>`).join("")+br("M26 56 Q30 46 40 42",4,.5);case 5:return ae(pe("l",[[0,"#f2bb66"],[1,W(Ln,.1)]]))+St(50,84,40,5)+`<path d="M8 66 Q8 36 50 32 Q92 36 92 66 Q92 80 50 80 Q8 80 8 66Z" fill="url(#l)" stroke="${t}" stroke-width="3.5"/>`+[26,42,58,74].map(r=>`<path d="M${r-6} 52 Q${r} 42 ${r+6} 40" stroke="${W(Ln,.35)}" stroke-width="4" fill="none" stroke-linecap="round"/>`).join("")+br("M16 60 Q18 46 30 40",4,.45);case 6:return ae(pe("p",[[0,"#f4c070"],[1,Ln]]))+St(50,86,42,5)+`<path d="M8 60 L14 80 L86 80 L92 60Z" fill="#b8b8c8" stroke="${t}" stroke-width="3.5"/><ellipse cx="50" cy="58" rx="42" ry="16" fill="url(#p)" stroke="${t}" stroke-width="3.5"/><ellipse cx="50" cy="56" rx="32" ry="10" fill="#c43a5a"/>`+[-20,-7,6,19].map(r=>`<line x1="${50+r}" y1="46" x2="${50+r+6}" y2="67" stroke="${Z(Ln,.2)}" stroke-width="4"/>`).join("")+[-20,0,20].map(r=>`<line x1="20" y1="${56+r*.3}" x2="80" y2="${56+r*.3}" stroke="${Z(Ln,.2)}" stroke-width="4" opacity="0.9"/>`).join("")+`<ellipse cx="50" cy="58" rx="42" ry="16" fill="none" stroke="${t}" stroke-width="3.5"/>`;default:return ae(pe("c",[[0,"#fff4f6"],[1,"#f2c6d2"]]),pe("t",[[0,"#ffd6e0"],[1,"#e89ab0"]]))+St(50,94,40,4)+`<rect x="12" y="62" width="76" height="28" rx="6" fill="url(#c)" stroke="${t}" stroke-width="3.5"/><rect x="24" y="38" width="52" height="26" rx="6" fill="url(#t)" stroke="${t}" stroke-width="3.5"/><path d="M12 70 Q20 78 28 70 Q36 78 44 70 Q52 78 60 70 Q68 78 76 70 Q84 78 88 70" fill="none" stroke="#fff" stroke-width="4"/><path d="M24 46 Q32 52 40 46 Q48 52 56 46 Q64 52 76 46" fill="none" stroke="#fff" stroke-width="4"/>`+[36,50,64].map(r=>`<rect x="${r-2.5}" y="22" width="5" height="16" rx="2" fill="#7cc4ff" stroke="${t}" stroke-width="1.5"/><path d="M${r} 12 Q${r+4} 18 ${r} 21 Q${r-4} 18 ${r} 12Z" fill="#ffc83a"/>`).join("")+`<circle cx="50" cy="40" r="5" fill="#d62a3a" stroke="${t}" stroke-width="2"/>`}}),Or="#4ac8ff",Uo="#ffc83a",Xn=(e,t,r,o,n,s)=>`<path d="M${e} ${t-r} L${e+o} ${t-r*.6} L${e+o*.8} ${t} L${e-o*.8} ${t} L${e-o} ${t-r*.6}Z" fill="${n}" stroke="${s}" stroke-width="3" stroke-linejoin="round"/><path d="M${e} ${t-r} L${e} ${t}" stroke="#fff" stroke-width="2" opacity="0.6"/>`,Y0=e=>Jt(t=>{switch(e){case 1:return ae(qe("r",[[0,"#c8ccd6"],[1,"#7a8090"]],.4,.35))+St(50,84,28,5)+`<path d="M20 70 Q16 48 34 40 Q52 30 70 42 Q86 54 78 72 Q66 84 44 82 Q24 80 20 70Z" fill="url(#r)" stroke="${t}" stroke-width="3.5"/><path d="M58 52 L66 58 L60 64Z" fill="${Or}" stroke="${t}" stroke-width="1.5"/>`+br("M30 52 Q36 44 46 42",4,.5);case 2:return St(50,88,22,4)+Xn(50,86,66,18,Or,t)+br("M44 40 L46 30",3,.7);case 3:return St(50,90,34,5)+Xn(30,88,44,13,W(Or,.15),t)+Xn(70,88,48,13,"#a88aff",t)+Xn(50,88,70,16,Or,t);case 4:return ae(pe("g",[[0,Z(Or,.4)],[1,W(Or,.3)]]))+St(50,90,30,5)+`<path d="M20 38 L34 20 L66 20 L80 38 L50 86Z" fill="url(#g)" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/><path d="M20 38 L80 38 M34 20 L42 38 L50 86 L58 38 L66 20 M42 38 L50 20 L58 38" fill="none" stroke="${t}" stroke-width="2" opacity="0.7"/><path d="M28 34 L36 24" stroke="#fff" stroke-width="4" stroke-linecap="round" opacity="0.8"/>`;case 5:return St(50,90,26,4)+`<circle cx="50" cy="62" r="24" fill="none" stroke="${t}" stroke-width="13"/><circle cx="50" cy="62" r="24" fill="none" stroke="${Uo}" stroke-width="8"/><path d="M50 62 m-16 -20" stroke="#fff" stroke-width="3" opacity="0.5"/><path d="M36 32 L42 22 L58 22 L64 32 L50 48Z" fill="#ff4a8a" stroke="${t}" stroke-width="3" stroke-linejoin="round"/>`+br("M30 70 Q30 54 40 46",3,.6);case 6:return St(50,92,24,4)+`<path d="M18 16 Q20 58 50 66 Q80 58 82 16" fill="none" stroke="${t}" stroke-width="7"/><path d="M18 16 Q20 58 50 66 Q80 58 82 16" fill="none" stroke="${Uo}" stroke-width="4" stroke-dasharray="5 3"/><path d="M50 62 L64 74 L50 92 L36 74Z" fill="${Or}" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><circle cx="34" cy="52" r="4" fill="#ff4a8a" stroke="${t}" stroke-width="1.5"/><circle cx="66" cy="52" r="4" fill="#ff4a8a" stroke="${t}" stroke-width="1.5"/>`+br("M44 72 L50 66",3,.7);default:return ae(pe("k",[[0,Z(Uo,.3)],[1,W(Uo,.25)]]))+St(50,90,38,5)+`<path d="M12 80 L8 30 L30 50 L50 18 L70 50 L92 30 L88 80Z" fill="url(#k)" stroke="${t}" stroke-width="3.5" stroke-linejoin="round"/><rect x="12" y="72" width="76" height="12" rx="3" fill="${W(Uo,.15)}" stroke="${t}" stroke-width="3"/><circle cx="50" cy="60" r="7" fill="#ff4a8a" stroke="${t}" stroke-width="2.5"/><circle cx="30" cy="64" r="5" fill="${Or}" stroke="${t}" stroke-width="2"/><circle cx="70" cy="64" r="5" fill="${Or}" stroke="${t}" stroke-width="2"/>`+[[8,30],[50,18],[92,30]].map(([r,o])=>`<circle cx="${r}" cy="${o}" r="5" fill="#fff6c0" stroke="${t}" stroke-width="2"/>`).join("")}}),Fr="#a26bff",td="#dff2ff",J0=e=>Jt(t=>{switch(e){case 1:return St(50,90,18,4)+'<path d="M50 90 Q46 60 52 30" stroke="#3f8a3a" stroke-width="4" fill="none" stroke-linecap="round"/>'+[[52,34,-40],[49,50,210],[51,64,-30],[48,76,200]].map(([r,o,n])=>`<ellipse cx="${r+12*Math.cos(n*Math.PI/180)}" cy="${o+12*Math.sin(n*Math.PI/180)}" rx="13" ry="6" fill="#5ad35a" stroke="${t}" stroke-width="2.5" transform="rotate(${n} ${r+12*Math.cos(n*Math.PI/180)} ${o+12*Math.sin(n*Math.PI/180)})"/>`).join("");case 2:return ae(qe("d",[[0,Z(Fr,.5)],[1,W(Fr,.2)]],.4,.55))+St(50,90,18,4)+`<path d="M50 12 Q74 46 74 62 A24 24 0 0 1 26 62 Q26 46 50 12Z" fill="url(#d)" stroke="${t}" stroke-width="3.5"/>`+br("M38 58 Q38 48 44 40",4,.7);case 3:return St(50,92,14,3)+`<rect x="38" y="12" width="24" height="8" rx="2" fill="#a8774a" stroke="${t}" stroke-width="2.5"/><path d="M40 20 L40 78 A10 10 0 0 0 60 78 L60 20Z" fill="${td}" stroke="${t}" stroke-width="3" opacity="0.95"/><path d="M41 52 L41 78 A9 9 0 0 0 59 78 L59 52Z" fill="#4ad3a0"/>`+br("M45 26 L45 72",3,.7);case 4:return St(50,92,26,4)+`<rect x="42" y="10" width="16" height="10" rx="2" fill="#a8774a" stroke="${t}" stroke-width="2.5"/><path d="M44 20 L44 40 A26 26 0 1 0 56 40 L56 20Z" fill="${td}" stroke="${t}" stroke-width="3"/><path d="M27 62 A23 23 0 0 0 73 62Z" fill="#ff6a5a"/><circle cx="44" cy="70" r="3" fill="#fff" opacity="0.7"/><circle cx="56" cy="74" r="2" fill="#fff" opacity="0.7"/>`+br("M34 52 Q32 62 36 70",3.5,.7);case 5:return ae(pe("b",[[0,Z(Fr,.3)],[1,W(Fr,.3)]]))+St(50,94,26,4)+`<rect x="40" y="6" width="20" height="12" rx="3" fill="#a8774a" stroke="${t}" stroke-width="2.5"/><path d="M42 18 L42 30 Q22 38 22 60 L22 82 Q22 90 30 90 L70 90 Q78 90 78 82 L78 60 Q78 38 58 30 L58 18Z" fill="url(#b)" stroke="${t}" stroke-width="3.5"/><rect x="30" y="56" width="40" height="22" rx="4" fill="#fff6e6" stroke="${t}" stroke-width="2"/><path d="M50 74 L40 64 A5 5 0 0 1 50 60 A5 5 0 0 1 60 64Z" fill="#e8384a"/>`+br("M30 44 Q28 52 28 60",4,.6);case 6:return ae(pe("k",[[0,"#5a5a6a"],[1,"#22222c"]]))+St(50,94,36,4)+[[30,30,6],[46,20,8],[62,28,5]].map(([r,o,n])=>`<circle cx="${r}" cy="${o}" r="${n}" fill="${Z("#4ad3a0",.2)}" stroke="${t}" stroke-width="2"/>`).join("")+`<ellipse cx="50" cy="44" rx="38" ry="10" fill="#4ad3a0" stroke="${t}" stroke-width="3"/><path d="M12 44 Q12 86 50 86 Q88 86 88 44Z" fill="url(#k)" stroke="${t}" stroke-width="3.5"/><path d="M26 86 L22 94 M74 86 L78 94" stroke="${t}" stroke-width="5" stroke-linecap="round"/>`+br("M20 54 Q22 68 30 76",4,.35);default:return ae(qe("o",[[0,"#ffffff"],[.35,Z(Fr,.4)],[1,W(Fr,.35)]],.4,.35))+St(50,94,26,4)+`<path d="M28 94 L34 76 L66 76 L72 94Z" fill="#a8774a" stroke="${t}" stroke-width="3"/><circle cx="50" cy="44" r="34" fill="${Fr}" opacity="0.25"/><circle cx="50" cy="46" r="28" fill="url(#o)" stroke="${t}" stroke-width="3.5"/><polygon points="${et(50,46,12,5,4)}" fill="#fff" opacity="0.85"/>`+[[18,20],[84,26],[80,70],[16,66]].map(([r,o])=>`<polygon points="${et(r,o,5,2,4)}" fill="#fff6c0"/>`).join("")}}),Bs=(e,t)=>ae(pe("pad",[[0,Z(e,.25)],[1,W(e,.25)]]))+`<rect x="6" y="6" width="88" height="88" rx="20" fill="url(#pad)" stroke="${t}" stroke-width="4"/><rect x="12" y="12" width="76" height="40" rx="14" fill="#fff" opacity="0.18"/>`,eh=Jt(e=>Bs("#5ab04a",e)+`<path d="M26 44 Q24 84 32 84 L68 84 Q76 84 74 44 Q50 36 26 44Z" fill="#d8b884" stroke="${e}" stroke-width="3.5"/><path d="M30 46 Q40 32 50 40 Q60 32 70 46" fill="#e8cc9a" stroke="${e}" stroke-width="3"/><path d="M50 40 Q48 26 50 18" stroke="#3f8a3a" stroke-width="4" fill="none" stroke-linecap="round"/><ellipse cx="41" cy="22" rx="9" ry="5" fill="#7fd36e" stroke="${e}" stroke-width="2.5" transform="rotate(-25 41 22)"/><ellipse cx="59" cy="20" rx="9" ry="5" fill="#7fd36e" stroke="${e}" stroke-width="2.5" transform="rotate(25 59 20)"/>`+[[42,64],[52,70],[58,60]].map(([t,r])=>`<ellipse cx="${t}" cy="${r}" rx="3" ry="4" fill="#8a5a32"/>`).join("")),th=Jt(e=>Bs("#e09a3a",e)+`<path d="M16 84 L16 50 Q16 20 50 20 Q84 20 84 50 L84 84Z" fill="#c8634a" stroke="${e}" stroke-width="3.5"/>`+[30,44,58].map(t=>`<path d="M18 ${t} L82 ${t}" stroke="${W("#c8634a",.3)}" stroke-width="2"/>`).join("")+`<path d="M30 84 L30 60 Q30 46 50 46 Q70 46 70 84Z" fill="#2a1a14" stroke="${e}" stroke-width="3"/><path d="M38 84 Q36 70 44 64 Q44 72 50 70 Q50 60 58 58 Q66 70 62 84Z" fill="#ffb03a"/><path d="M44 84 Q44 76 50 74 Q56 76 56 84Z" fill="#ffe66a"/>`),rh=Jt(e=>Bs("#4a7ad3",e)+`<path d="M14 84 L22 46 L42 28 L66 32 L84 54 L86 84Z" fill="#8a8a9a" stroke="${e}" stroke-width="3.5" stroke-linejoin="round"/><path d="M22 46 L40 56 L42 28 M40 56 L66 32 M40 56 L60 84 M66 32 L68 60 L84 54 M68 60 L60 84" fill="none" stroke="${W("#8a8a9a",.3)}" stroke-width="2"/>`+Xn(36,76,18,6,Or,e)+Xn(70,78,14,5,"#ff4a8a",e)+`<path d="M58 14 L84 26" stroke="#8a5a32" stroke-width="5" stroke-linecap="round"/><path d="M76 12 Q86 20 90 34 L82 30 Q80 22 72 18Z" fill="#c8ccd6" stroke="${e}" stroke-width="2.5"/>`),nh=Jt(e=>Bs("#8a4ad3",e)+`<rect x="16" y="20" width="68" height="66" rx="6" fill="#8a5a32" stroke="${e}" stroke-width="3.5"/><path d="M16 52 L84 52" stroke="${e}" stroke-width="3"/>`+[[30,44,"#4ad3a0"],[50,44,"#ff6a5a"],[70,44,Fr],[30,78,Fr],[50,78,"#ffc83a"],[70,78,"#4ad3a0"]].map(([t,r,o])=>`<rect x="${Number(t)-4}" y="${Number(r)-20}" width="8" height="6" fill="#d8b884"/><path d="M${Number(t)-6} ${Number(r)-14} L${Number(t)+6} ${Number(r)-14} L${Number(t)+7} ${r} L${Number(t)-7} ${r}Z" fill="${o}" stroke="${e}" stroke-width="2"/>`).join("")),rd=e=>Jt(t=>{let r="#c08a4a";return ae(pe("w",[[0,Z(r,.15)],[1,W(r,.2)]]))+`<rect x="6" y="6" width="88" height="88" rx="8" fill="url(#w)" stroke="${t}" stroke-width="4"/>`+[30,50,70].map(o=>`<line x1="8" y1="${o}" x2="92" y2="${o}" stroke="${W(r,.35)}" stroke-width="2"/>`).join("")+`<path d="M14 14 L86 86 M86 14 L14 86" stroke="${W(r,.3)}" stroke-width="7"/><rect x="6" y="6" width="88" height="88" rx="8" fill="none" stroke="${t}" stroke-width="4"/>`+(e?`<rect x="6" y="22" width="88" height="10" fill="#8a96aa" stroke="${t}" stroke-width="2.5"/><rect x="6" y="68" width="88" height="10" fill="#8a96aa" stroke="${t}" stroke-width="2.5"/>`+[16,50,84].map(o=>`<circle cx="${o}" cy="27" r="2.5" fill="${t}"/><circle cx="${o}" cy="73" r="2.5" fill="${t}"/>`).join(""):"")}),oh={w:100,h:100,draw:()=>ae(qe("f",[[0,"#ffffff"],[1,"#c8d2e0"]],.45,.4,.6))+'<rect x="2" y="2" width="96" height="96" rx="14" fill="url(#f)" opacity="0.97"/>'+[[28,34,18],[62,30,20],[44,58,22],[76,64,16],[22,70,14]].map(([e,t,r])=>`<circle cx="${e}" cy="${t}" r="${r}" fill="#ffffff" opacity="0.75"/>`).join("")+'<text x="50" y="62" font-size="30" font-family="sans-serif" font-weight="900" text-anchor="middle" fill="#8a96aa" opacity="0.8">?</text>'},sh=Jt(e=>'<g stroke="#ffffff" stroke-width="2.5" fill="none" opacity="0.9">'+[0,45,90,135].map(t=>`<line x1="${50-46*Math.cos(t*Math.PI/180)}" y1="${50-46*Math.sin(t*Math.PI/180)}" x2="${50+46*Math.cos(t*Math.PI/180)}" y2="${50+46*Math.sin(t*Math.PI/180)}"/>`).join("")+[14,28,42].map(t=>`<polygon points="${Tt(50,50,t,8,0)}"/>`).join("")+`</g><g stroke="${e}" stroke-width="1" fill="none" opacity="0.35">`+[14,28,42].map(t=>`<polygon points="${Tt(50,50,t,8,0)}"/>`).join("")+"</g>"),ah={w:100,h:100,draw:()=>ae(qe("u",[[0,"#ffffff",0],[.75,"#9ad8ff",.25],[1,"#4ab0ff",.7]]))+'<circle cx="50" cy="50" r="46" fill="url(#u)" stroke="#ffffff" stroke-width="3" opacity="0.95"/>'+br("M24 38 Q28 24 42 18",6,.85)+'<circle cx="72" cy="72" r="4" fill="#fff" opacity="0.7"/>'},ih=Jt(e=>ae(pe("j",[[0,"#ff6a8a"],[.35,"#ffc83a"],[.7,"#5ad35a"],[1,"#4aa8ff"]]))+St(50,90,26,4)+`<circle cx="50" cy="50" r="40" fill="#fff" opacity="0.25"/><polygon points="${et(50,50,40,18,5)}" fill="url(#j)" stroke="${e}" stroke-width="3.5" stroke-linejoin="round"/><circle cx="42" cy="46" r="4" fill="${e}"/><circle cx="58" cy="46" r="4" fill="${e}"/><path d="M42 58 Q50 64 58 58" stroke="${e}" stroke-width="3" fill="none" stroke-linecap="round"/>`),lh=Jt(e=>St(50,92,22,4)+`<path d="M50 54 L26 12 L34 10 L54 48Z" fill="#d8dee8" stroke="${e}" stroke-width="3" stroke-linejoin="round"/><path d="M50 54 L74 12 L66 10 L46 48Z" fill="#eef2f8" stroke="${e}" stroke-width="3" stroke-linejoin="round"/><circle cx="34" cy="74" r="14" fill="none" stroke="${e}" stroke-width="10"/><circle cx="34" cy="74" r="14" fill="none" stroke="#e8384a" stroke-width="6"/><circle cx="66" cy="74" r="14" fill="none" stroke="${e}" stroke-width="10"/><circle cx="66" cy="74" r="14" fill="none" stroke="#e8384a" stroke-width="6"/><circle cx="50" cy="54" r="5" fill="#ffc83a" stroke="${e}" stroke-width="2"/>`),ch=Jt(e=>ae(qe("e",[[0,"#fff6a0"],[1,"#ffb000"]],.4,.35))+`<circle cx="50" cy="50" r="44" fill="url(#e)" stroke="${e}" stroke-width="4"/><path d="M56 12 L26 56 L46 56 L40 88 L74 40 L54 40Z" fill="#fff" stroke="${e}" stroke-width="3.5" stroke-linejoin="round"/>`),dh=Jt(e=>ae(pe("t",[[0,"#9aa6ba"],[1,"#5a6478"]],true))+`<rect x="36" y="8" width="28" height="10" rx="4" fill="#5a6478" stroke="${e}" stroke-width="3"/><rect x="14" y="16" width="72" height="12" rx="4" fill="#7a869a" stroke="${e}" stroke-width="3.5"/><path d="M20 30 L26 90 L74 90 L80 30Z" fill="url(#t)" stroke="${e}" stroke-width="3.5" stroke-linejoin="round"/>`+[36,50,64].map(t=>`<line x1="${t}" y1="40" x2="${t}" y2="80" stroke="${e}" stroke-width="3" stroke-linecap="round" opacity="0.6"/>`).join("")),fh=Jt(e=>`<path d="M50 10 L80 44 L62 44 L62 84 L38 84 L38 44 L20 44Z" fill="#7cf0a0" stroke="${e}" stroke-width="4" stroke-linejoin="round"/>`+[[18,20],[84,66],[16,74]].map(([t,r])=>`<polygon points="${et(t,r,9,3.5,4)}" fill="#fff6a0" stroke="${e}" stroke-width="1.5"/>`).join("")),ph=Jt(e=>`<path d="M40 8 L16 50 L32 50 L26 90 L56 40 L40 40Z" fill="#ffd34a" stroke="${e}" stroke-width="3.5" stroke-linejoin="round"/><path d="M70 18 L52 50 L64 50 L60 82 L84 44 L72 44Z" fill="#fff6a0" stroke="${e}" stroke-width="3" stroke-linejoin="round"/>`),hh=Jt(e=>`<path d="M22 84 L64 42" stroke="${e}" stroke-width="12" stroke-linecap="round"/><path d="M22 84 L64 42" stroke="#8a5a32" stroke-width="7" stroke-linecap="round"/><polygon points="${et(70,34,24,10,5)}" fill="#ffc83a" stroke="${e}" stroke-width="3.5" stroke-linejoin="round"/>`+[[30,22],[88,70],[52,82]].map(([t,r])=>`<polygon points="${et(t,r,7,2.5,4)}" fill="#fff"/>`).join("")),nd={...Object.fromEntries([1,2,3,4,5,6,7].map(e=>[`mg_bake${e}`,Q0(e)])),...Object.fromEntries([1,2,3,4,5,6,7].map(e=>[`mg_jewel${e}`,Y0(e)])),...Object.fromEntries([1,2,3,4,5,6,7].map(e=>[`mg_potion${e}`,J0(e)])),mg_gen_garden:eh,mg_gen_bake:th,mg_gen_jewel:rh,mg_gen_potion:nh,mg_box:rd(false),mg_box2:rd(true),mg_fog:oh,mg_web:sh,mg_bubble:ah,mg_joker:ih,mg_scissors:lh,mg_energy:ch,mg_bin:dh,mg_sk_merge:fh,mg_sk_free:ph,mg_sk_joker:hh};var od={fantasy:{skyTop:"#3f6aa8",skyBottom:"#f4c98e",far1:"#7b8fb8",far2:"#566f94",near:"#2c5638",crust:"#6dbb45",soil:"#7a5232",deep:"#4e331e",floor:"#5f9a3e",detail:"#7ab552",road:"#a57d4f",edge:"#7a5a36",wall:"#e8d9b8",roof:"#b8483a"},"sci-fi":{skyTop:"#050816",skyBottom:"#3b1f63",far1:"#232b5c",far2:"#161c40",near:"#0e1430",crust:"#36e3ff",soil:"#2a3452",deep:"#151b30",floor:"#1b2340",detail:"#2a3762",road:"#2b3868",edge:"#36e3ff",wall:"#3a4a72",roof:"#232c4a"},cozy:{skyTop:"#8fd3ff",skyBottom:"#fff3d6",far1:"#b6e2a2",far2:"#8fcc7e",near:"#5fae5a",crust:"#8ed46f",soil:"#c98b5a",deep:"#9e6a42",floor:"#a8dc8a",detail:"#c6ecab",road:"#efc89a",edge:"#d9a676",wall:"#fff1e0",roof:"#ff8f8f"},"post-apocalypse":{skyTop:"#3b2a26",skyBottom:"#d0803e",far1:"#7a5442",far2:"#4e3a2e",near:"#2a201a",crust:"#5a5248",soil:"#6b6358",deep:"#3e3832",floor:"#5e5648",detail:"#4a4438",road:"#46423c",edge:"#2e2a26",wall:"#8a7a62",roof:"#5a3a2a"},default:{skyTop:"#25365e",skyBottom:"#7d9fd6",far1:"#4f6494",far2:"#3a4b72",near:"#283958",crust:"#5fae5a",soil:"#6b4a2e",deep:"#45301c",floor:"#3e5a46",detail:"#4b6a52",road:"#5a5f78",edge:"#454a60",wall:"#e6dccb",roof:"#5a6fae"}},fr=e=>od[e]??od.default,uh={w:100,h:200,draw({style:e}){let t=fr(e),r="";if(e==="sci-fi"){let o=Mr(7);r=Array.from({length:60},()=>`<circle cx="${q(o()*100)}" cy="${q(o()*150)}" r="${q(.3+o()*.6)}" fill="#fff" opacity="${q(.3+o()*.7)}"/>`).join("");}return ae(pe("s",[[0,t.skyTop],[.75,qn(t.skyTop,t.skyBottom,.7)],[1,t.skyBottom]]))+'<rect width="100" height="200" fill="url(#s)"/>'+r}},mh={w:100,h:100,draw({style:e}){if(e==="sci-fi")return ae(pe("p",[[0,"#ff9ad5"],[1,"#6a3cc8"]]),qe("h",[[0,"#ff9ad5",.5],[1,"#ff9ad5",0]]))+'<circle cx="50" cy="50" r="48" fill="url(#h)"/><circle cx="50" cy="50" r="26" fill="url(#p)"/><ellipse cx="50" cy="52" rx="44" ry="9" fill="none" stroke="#ffd0f0" stroke-width="3" opacity="0.8" transform="rotate(-14 50 52)"/>';let t=e==="post-apocalypse"?"#ff7a3a":e==="cozy"?"#fff2a8":"#fff0c0",r=e==="post-apocalypse"?"#ff5a2a":"#fff6d0";return ae(qe("h",[[0,r,.85],[.45,r,.35],[1,r,0]]))+`<circle cx="50" cy="50" r="50" fill="url(#h)"/><circle cx="50" cy="50" r="20" fill="${t}"/>`}},Hs=(e,t,r,o,n,s)=>{let a=Mr(e),i=Array.from({length:s},()=>o-a()*n);i.push(i[0]);let p=i.map((m,$)=>`${q($/s*t)},${q(m)}`);return `M0 ${r} L${p.join(" L")} L${t} ${r}Z`},yh={w:512,h:200,band:true,draw({style:e}){let t=fr(e),r=qn(t.far1,t.skyBottom,.35);if(e==="sci-fi"){let p=Mr(11),m=0,$="",k="";for(;m<500;){let O=26+Math.floor(p()*40),C=50+Math.floor(p()*130),z=Math.min(O,512-m);$+=`<rect x="${m}" y="${200-C}" width="${z}" height="${C}" fill="${p()<.5?t.far1:t.far2}"/>`,p()<.3&&($+=`<rect x="${m+z/2-1}" y="${200-C-18}" width="2" height="18" fill="${t.far1}"/><circle cx="${m+z/2}" cy="${200-C-18}" r="2" fill="#ff3d6e"/>`);for(let F=200-C+8;F<196;F+=10)for(let ne=m+4;ne<m+z-4;ne+=7)p()<.35&&(k+=`<rect x="${ne}" y="${F}" width="3" height="4" fill="${p()<.5?"#36e3ff":"#ffd36e"}" opacity="0.8"/>`);m+=z+2;}return $+k}if(e==="post-apocalypse"){let p=Mr(13),m=6,$=`<path d="${Hs(3,512,200,170,22,8)}" fill="${r}"/>`;for(;m<490;){let k=30+Math.floor(p()*36),C=200-(60+Math.floor(p()*110)),z=p()*20;$+=`<path d="M${m} 200 L${m} ${C+z} L${m+k*.3} ${C} L${m+k*.55} ${C+14+z} L${m+k} ${C+6} L${m+k} 200Z" fill="${p()<.5?t.far1:t.far2}"/>`;for(let F=C+20;F<190;F+=14)for(let ne=m+5;ne<m+k-6;ne+=10)p()<.5&&($+=`<rect x="${ne}" y="${F}" width="4" height="6" fill="${t.near}" opacity="0.7"/>`);m+=k+8+Math.floor(p()*20);}return $+'<ellipse cx="380" cy="60" rx="60" ry="14" fill="#2a1a14" opacity="0.25"/>'}if(e==="cozy"){let p=[80,230,400].map((m,$)=>`<rect x="${m}" y="${132-$*6}" width="22" height="18" fill="#fff4e8"/><polygon points="${m-3},${133-$*6} ${m+11},${120-$*6} ${m+25},${133-$*6}" fill="${["#ff8f8f","#8fb8ff","#ffb86b"][$]}"/><rect x="${m+8}" y="${140-$*6}" width="6" height="10" fill="#c98b5a"/>`).join("");return `<path d="${Hs(5,512,200,140,30,6)}" fill="${t.far1}"/>`+p+`<path d="${Hs(9,512,200,168,22,5)}" fill="${t.far2}"/>`+[40,170,300,460].map(m=>`<circle cx="${m}" cy="158" r="12" fill="${W(t.far2,.12)}"/>`).join("")}let o=Mr(17),n=[],s=[],a=(p,m)=>{n.push(`M${q(p-110)} 200 L${q(p)} ${q(m)} L${q(p+110)} 200Z`),s.push(`M${q(p-24)} ${q(m+26)} L${q(p)} ${q(m)} L${q(p+24)} ${q(m+26)} L${q(p+10)} ${q(m+20)} L${q(p)} ${q(m+28)} L${q(p-10)} ${q(m+20)}Z`);};for(let p=0;p<4;p++){let m=64+p*128+(o()-.5)*30,$=30+o()*40;a(m,$),m-110<0&&a(m+512,$),m+110>512&&a(m-512,$);}let i=e==="fantasy"?`<g fill="${W(t.far2,.15)}"><rect x="300" y="120" width="40" height="80"/><rect x="292" y="104" width="14" height="96"/><rect x="334" y="100" width="14" height="100"/><polygon points="290,104 299,84 308,104"/><polygon points="332,100 341,78 350,100"/>${[300,310,320,330].map(p=>`<rect x="${p}" y="114" width="6" height="8"/>`).join("")}</g><rect x="340" y="82" width="10" height="6" fill="#d0483b"/>`:"";return `<path d="${n.join(" ")}" fill="${r}"/><path d="${s.join(" ")}" fill="#f4f6ff" opacity="0.85"/><path d="${Hs(21,512,200,160,40,9)}" fill="${t.far2}"/>`+i}},gh={w:512,h:160,band:true,draw({style:e}){let t=fr(e),r=Mr(29),o=`<rect x="0" y="146" width="512" height="14" fill="${t.near}"/>`;if(e==="sci-fi"){let s=o;for(let a=30;a<500;a+=90+Math.floor(r()*40)){let i=60+r()*70;s+=`<rect x="${a}" y="${150-i}" width="8" height="${i}" fill="${t.near}"/><rect x="${a-14}" y="${150-i}" width="36" height="5" fill="${t.near}"/><circle cx="${a+4}" cy="${146-i}" r="3" fill="#36e3ff"/>`;}return s+=`<path d="M180 150 A40 40 0 0 1 260 150Z" fill="${t.near}"/><path d="M200 140 A22 22 0 0 1 240 140" stroke="#36e3ff" stroke-width="2" fill="none" opacity="0.7"/>`,s}if(e==="post-apocalypse"){let s=o,a=(i,p)=>`<path d="M${i} 150 L${i+3} ${150-p} M${i+2} ${150-p*.6} L${i-14} ${150-p*.85} M${i+2} ${150-p*.45} L${i+18} ${150-p*.7} M${i+3} ${150-p*.8} L${i+12} ${150-p}" stroke="${t.near}" stroke-width="5" stroke-linecap="round" fill="none"/>`;return s+=a(40,90)+a(300,110)+a(460,70),s+=`<rect x="150" y="18" width="5" height="132" fill="${t.near}"/><rect x="138" y="28" width="30" height="4" fill="${t.near}"/><path d="M0 34 Q75 54 152 30 Q260 58 360 34 Q440 50 512 34" stroke="${t.near}" stroke-width="1.5" fill="none"/>`,s+=`<path d="M180 150 L188 128 L232 124 L246 136 L262 138 L262 150Z" fill="${t.near}"/><circle cx="198" cy="150" r="8" fill="#1a120c"/><circle cx="246" cy="150" r="8" fill="#1a120c"/>`,s}if(e==="cozy"){let s=o;for(let a=20;a<500;a+=100+Math.floor(r()*30)){let i=50+r()*30;s+=`<rect x="${a+16}" y="${150-i*.5}" width="8" height="${i*.5}" fill="#9e6a42"/><circle cx="${a+20}" cy="${150-i*.6}" r="${i*.36}" fill="${t.near}"/><circle cx="${a+12}" cy="${150-i*.7}" r="${i*.12}" fill="${Z(t.near,.25)}"/>`;}for(let a=4;a<512;a+=16)s+=`<rect x="${a}" y="128" width="8" height="22" rx="3" fill="#fff8f0"/>`;return s+='<rect x="0" y="134" width="512" height="4" fill="#fff8f0"/>',s}let n=o;for(let s=14;s<500;s+=44+Math.floor(r()*50)){let a=70+r()*60,i=a*.36;n+=`<rect x="${s-3}" y="${150-a*.18}" width="6" height="${a*.18}" fill="${W(t.near,.3)}"/>`;for(let p=0;p<3;p++){let m=150-a*.15-p*a*.26,$=i*(1-p*.25);n+=`<polygon points="${q(s-$)},${q(m)} ${q(s)},${q(m-a*.42)} ${q(s+$)},${q(m)}" fill="${p===2?Z(t.near,.08):t.near}"/>`;}}return n}};function sd(e,t){let r=fr(e.style);if(e.style==="sci-fi")return `<rect x="0" y="0" width="${t}" height="16" fill="#3a4a72"/><rect x="0" y="0" width="${t}" height="4" fill="${e.c("primary")}"/><rect x="0" y="14" width="${t}" height="3" fill="#11172a"/>`+[16,48,80,112].filter(n=>n<t).map(n=>`<rect x="${n}" y="6" width="14" height="4" rx="2" fill="${e.c("primary")}" opacity="0.5"/>`).join("");if(e.style==="post-apocalypse")return `<path d="M0 0 L${t} 0 L${t} 14 L${t*.8} 18 L${t*.62} 12 L${t*.4} 20 L${t*.2} 13 L0 16Z" fill="#3a3530"/><path d="M${t*.15} 4 L${t*.3} 8 M${t*.6} 3 L${t*.75} 9" stroke="#24201c" stroke-width="2"/>`;if(e.style==="cozy"){let n="";for(let s=0;s<t;s+=32)n+=`<circle cx="${s+16}" cy="14" r="16" fill="${r.crust}"/>`;return `<rect x="0" y="0" width="${t}" height="14" fill="${r.crust}"/>${n}<circle cx="${t*.3}" cy="8" r="3" fill="#fff"/><circle cx="${t*.75}" cy="10" r="3" fill="#ff8fab"/>`}let o="";for(let n=2;n<t;n+=8)o+=`<polygon points="${n},12 ${n+3},${2+n*7%5} ${n+6},12" fill="${Z(r.crust,.15)}"/>`;return `<rect x="0" y="6" width="${t}" height="16" fill="${r.crust}"/>${o}<rect x="0" y="20" width="${t}" height="4" fill="${W(r.crust,.3)}"/>`}var bh={w:128,h:512,draw(e){let t=fr(e.style),r=Mr(41),o="";for(let n=0;n<14;n++)o+=`<ellipse cx="${q(8+r()*112)}" cy="${q(40+r()*460)}" rx="${q(4+r()*7)}" ry="${q(3+r()*4)}" fill="${W(t.soil,.2+r()*.15)}"/>`;return e.style==="sci-fi"&&(o=[80,180,280,380].map(n=>`<rect x="0" y="${n}" width="128" height="2" fill="#11172a"/>`).join("")+'<rect x="62" y="20" width="2" height="492" fill="#11172a"/>'+[100,300].map(n=>`<circle cx="20" cy="${n}" r="3" fill="#4a5a88"/><circle cx="108" cy="${n}" r="3" fill="#4a5a88"/>`).join("")),ae(pe("d",[[0,t.soil],[1,t.deep]]))+'<rect width="128" height="512" fill="url(#d)"/>'+o+sd(e,128)}},xh={w:128,h:40,draw(e){let t=fr(e.style);return ae(pe("d",[[0,t.soil],[1,t.deep]]))+'<path d="M0 10 L128 10 L128 26 Q96 40 64 36 Q32 40 0 26Z" fill="url(#d)"/>'+sd(e,128)+`<path d="M0 26 Q32 40 64 36 Q96 40 128 26" stroke="${e.ink}" stroke-width="2.5" fill="none" opacity="0.5"/>`}},kh={w:128,h:100,draw(e){let t=fr(e.style);if(e.style==="sci-fi")return `<rect width="128" height="100" fill="${t.road}"/><rect y="0" width="128" height="5" fill="${e.c("primary")}" opacity="0.8"/><rect y="95" width="128" height="5" fill="${e.c("primary")}" opacity="0.8"/><path d="M40 38 L58 50 L40 62 M74 38 L92 50 L74 62" stroke="${e.c("primary")}" stroke-width="5" fill="none" opacity="0.35"/>`;if(e.style==="cozy"){let s="";for(let a=0;a<5;a++)for(let i=a%2*-16;i<128;i+=32)s+=`<rect x="${i+1}" y="${a*20+1}" width="30" height="18" rx="4" fill="${a%2?t.road:Z(t.road,.08)}" stroke="${t.edge}" stroke-width="2"/>`;return `<rect width="128" height="100" fill="${t.edge}"/>${s}`}let r=Mr(53),o="";for(let s=0;s<12;s++)o+=`<ellipse cx="${q(r()*128)}" cy="${q(10+r()*80)}" rx="${q(2+r()*3)}" ry="${q(1.5+r()*2)}" fill="${W(t.road,.25)}"/>`;let n=e.style==="post-apocalypse"?'<rect x="20" y="47" width="40" height="6" fill="#c9a43a" opacity="0.75"/><path d="M80 20 L96 36 L90 52" stroke="#2a2622" stroke-width="2" fill="none"/>':"";return `<rect width="128" height="100" fill="${t.road}"/><rect width="128" height="6" fill="${t.edge}"/><rect y="94" width="128" height="6" fill="${t.edge}"/>${o}${n}`}},vh={w:128,h:128,draw({style:e}){let t=fr(e),r=Mr(61),o="";if(e==="sci-fi")o=`<rect x="2" y="2" width="60" height="60" rx="4" fill="${t.detail}"/><rect x="66" y="66" width="60" height="60" rx="4" fill="${t.detail}"/><rect x="66" y="2" width="60" height="60" rx="4" fill="${Z(t.floor,.05)}"/><rect x="2" y="66" width="60" height="60" rx="4" fill="${Z(t.floor,.05)}"/><rect x="62" y="0" width="4" height="128" fill="#36e3ff" opacity="0.18"/><rect x="0" y="62" width="128" height="4" fill="#36e3ff" opacity="0.18"/>`;else if(e==="post-apocalypse")o=`<path d="M10 20 L40 44 L36 70 L60 96 M80 10 L92 40 L120 52 M70 80 L100 110" stroke="${t.detail}" stroke-width="2.5" fill="none"/>`;else for(let n=0;n<18;n++){let s=6+r()*116,a=6+r()*116;o+=`<path d="M${q(s)} ${q(a)} l-3 -6 M${q(s)} ${q(a)} l0 -7 M${q(s)} ${q(a)} l3 -6" stroke="${t.detail}" stroke-width="2" stroke-linecap="round"/>`,e==="cozy"&&n%5===0&&(o+=`<circle cx="${q(s+6)}" cy="${q(a)}" r="2.5" fill="${["#fff","#ff8fab","#ffd166"][n%3]}"/>`);}return `<rect width="128" height="128" fill="${t.floor}"/>${o}`}},$h=e=>({w:64,h:64,draw({style:t,ink:r}){let o=fr(t),n='<ellipse cx="32" cy="50" rx="20" ry="6" fill="#000" opacity="0.22"/>';if(t==="sci-fi"){let i=[`<rect x="14" y="16" width="36" height="32" rx="4" fill="#4a5a80" stroke="${r}" stroke-width="3"/><rect x="20" y="24" width="24" height="5" fill="#36e3ff"/>`,`<circle cx="32" cy="32" r="16" fill="#2a3452" stroke="${r}" stroke-width="3"/>${[0,1,2,3].map(p=>`<rect x="22" y="${23+p*5}" width="20" height="2" fill="#11172a"/>`).join("")}`,`<rect x="6" y="28" width="52" height="10" rx="5" fill="#5d6f96" stroke="${r}" stroke-width="3"/><circle cx="18" cy="33" r="3" fill="#ff3d6e"/>`,'<circle cx="32" cy="32" r="8" fill="#b45cff"/><circle cx="32" cy="32" r="14" fill="none" stroke="#b45cff" stroke-width="2" opacity="0.5"/>'];return n+i[(e-1)%4]}if(t==="post-apocalypse"){let i=[`<circle cx="32" cy="32" r="18" fill="#1e1a16" stroke="${r}" stroke-width="3"/><circle cx="32" cy="32" r="8" fill="${o.floor}"/>`,`<circle cx="32" cy="32" r="16" fill="#8a3d24" stroke="${r}" stroke-width="3"/><circle cx="32" cy="32" r="10" fill="none" stroke="#5a2814" stroke-width="2"/>`,`<polygon points="10,40 22,22 38,30 52,18 54,44 30,48" fill="#6b6358" stroke="${r}" stroke-width="3" stroke-linejoin="round"/>`,'<path d="M20 44 L24 20 M32 46 L32 16 M42 44 L38 22" stroke="#7a6a3a" stroke-width="3" stroke-linecap="round"/>'];return n+i[(e-1)%4]}let s=t==="cozy"?"#6fc46a":"#3f7f3a",a=[`<circle cx="22" cy="34" r="12" fill="${s}" stroke="${r}" stroke-width="3"/><circle cx="42" cy="34" r="12" fill="${s}" stroke="${r}" stroke-width="3"/><circle cx="32" cy="24" r="13" fill="${Z(s,.1)}" stroke="${r}" stroke-width="3"/>`,`<path d="M12 44 Q14 22 32 20 Q50 22 52 44Z" fill="#9aa0a8" stroke="${r}" stroke-width="3"/><path d="M22 28 Q30 24 36 26" stroke="#fff" stroke-width="3" opacity="0.5" fill="none"/>`,[[22,28],[40,24],[32,40],[46,40]].map(([i,p],m)=>`<polygon points="${et(i,p,7,3,5)}" fill="${["#ff8fab","#ffd166","#fff","#c39bff"][m]}" stroke="${r}" stroke-width="1.5"/>`).join(""),t==="cozy"?`<rect x="28" y="30" width="8" height="16" fill="#fff4e6" stroke="${r}" stroke-width="2.5"/><path d="M14 32 Q32 8 50 32Z" fill="#ff6b6b" stroke="${r}" stroke-width="3"/><circle cx="26" cy="24" r="3" fill="#fff"/><circle cx="38" cy="26" r="2.5" fill="#fff"/>`:`<ellipse cx="32" cy="38" rx="16" ry="9" fill="#8a5a32" stroke="${r}" stroke-width="3"/><ellipse cx="32" cy="34" rx="16" ry="9" fill="#c49a6a" stroke="${r}" stroke-width="3"/><ellipse cx="32" cy="34" rx="8" ry="4" fill="none" stroke="#8a5a32" stroke-width="2"/>`];return n+a[(e-1)%4]}}),Mh={w:0,h:0,exact:true,main:"ground",draw({style:e,w:t,h:r}){let o=fr(e),n=Mr(Math.round(t*13+r)),s="";for(let a=0;a<4;a++){let i=t*(.15+n()*.7),p=r*(.2+n()*.65);s+=e==="sci-fi"?`<circle cx="${q(i)}" cy="${q(p)}" r="${q(t*.02)}" fill="#4a5a88"/>`:`<path d="M${q(i)} ${q(p)} l${q(-t*.04)} ${q(-r*.08)} M${q(i)} ${q(p)} l0 ${q(-r*.1)} M${q(i)} ${q(p)} l${q(t*.04)} ${q(-r*.08)}" stroke="${o.detail}" stroke-width="${q(t*.025)}" stroke-linecap="round"/>`;}return `<rect width="${t}" height="${r}" fill="${o.floor}"/><rect x="0.5" y="0.5" width="${t-1}" height="${r-1}" fill="none" stroke="${W(o.floor,.25)}" stroke-opacity="0.35" stroke-width="1"/>${s}`}},wh={w:0,h:0,exact:true,main:"lane",draw({style:e,w:t,h:r,c:o}){let n=fr(e),s=Mr(Math.round(t*7+r*3)),a="";for(let p=0;p<5;p++)a+=`<ellipse cx="${q(t*(.15+s()*.7))}" cy="${q(r*(.15+s()*.7))}" rx="${q(t*(.04+s()*.05))}" ry="${q(r*.035)}" fill="${W(n.road,.18)}"/>`;let i=e==="sci-fi"?`<rect x="${q(t*.42)}" y="${q(r*.42)}" width="${q(t*.16)}" height="${q(r*.16)}" rx="2" fill="${o("primary")}" opacity="0.45"/>`:"";return `<rect width="${t}" height="${r}" fill="${n.road}"/>${a}${i}`}},Eh=e=>({w:100,h:130,main:"primary",draw({style:t,ink:r,main:o,c:n}){let s='<ellipse cx="50" cy="122" rx="38" ry="8" fill="#000" opacity="0.28"/>';if(t==="sci-fi"||t==="post-apocalypse"){let C=t==="sci-fi"?"#5d6f96":"#7a6a52",z=t==="sci-fi"?o:n("coin"),F=Array.from({length:e},(X,ye)=>`<rect x="50" y="${52-(e-1)*5+ye*10}" width="${36+e*2}" height="8" rx="3" fill="${W(C,.25)}" stroke="${r}" stroke-width="2.5"/>`).join(""),ne=t==="post-apocalypse"?[0,1,2].map(X=>`<ellipse cx="${26+X*24}" cy="106" rx="14" ry="9" fill="#a89070" stroke="${r}" stroke-width="2.5"/>`).join("")+[0,1].map(X=>`<ellipse cx="${38+X*24}" cy="94" rx="14" ry="9" fill="#b8a080" stroke="${r}" stroke-width="2.5"/>`).join(""):`<polygon points="${Tt(50,100,34,6,0)}" fill="#2a3452" stroke="${r}" stroke-width="3.5"/><polygon points="${Tt(50,100,22,6,0)}" fill="${z}" opacity="0.4"/>`;return s+ne+`<rect x="38" y="64" width="24" height="30" fill="${C}" stroke="${r}" stroke-width="3"/>`+F+`<path d="M24 68 A26 26 0 0 1 76 68Z" fill="${Z(C,.15)}" stroke="${r}" stroke-width="3.5"/><circle cx="50" cy="56" r="${5+e}" fill="${z}" stroke="${r}" stroke-width="2.5"/>`}let a=t==="cozy"?"#f4e6d4":"#a7a9b2",i=t==="cozy"?n("primary"):o,p=70-e*14,m="";for(let C=p+10;C<112;C+=12)m+=`<line x1="26" y1="${C}" x2="74" y2="${C}" stroke="${W(a,.25)}" stroke-width="2"/>`+[0,1].map(z=>`<line x1="${36+z*16+C/12%2*8}" y1="${C}" x2="${36+z*16+C/12%2*8}" y2="${C+12}" stroke="${W(a,.25)}" stroke-width="2"/>`).join("");let $=[26,40,54,68].map(C=>`<rect x="${C}" y="${p-10}" width="8" height="12" fill="${a}" stroke="${r}" stroke-width="2.5"/>`).join(""),k=e>=2?`<polygon points="20,${p-2} 50,${p-44} 80,${p-2}" fill="${i}" stroke="${r}" stroke-width="3.5" stroke-linejoin="round"/><polygon points="20,${p-2} 50,${p-44} 40,${p-2}" fill="${Z(i,.2)}"/>`:$,O=e>=3?`<line x1="50" y1="${p-44}" x2="50" y2="${p-64}" stroke="${r}" stroke-width="3"/><path d="M50 ${p-64} L70 ${p-58} L50 ${p-52}Z" fill="${n("coin")}" stroke="${r}" stroke-width="2"/>`:"";return s+ae(pe("s",[[0,Z(a,.2)],[1,W(a,.2)]],true))+`<rect x="24" y="${p}" width="52" height="${116-p}" fill="url(#s)" stroke="${r}" stroke-width="3.5"/>`+m+`<rect x="44" y="${p+16}" width="12" height="18" rx="6" fill="#2a2030" stroke="${r}" stroke-width="2.5"/><path d="M42 116 L42 100 A8 8 0 0 1 58 100 L58 116Z" fill="#6a4628" stroke="${r}" stroke-width="2.5"/>`+k+O}}),Sh=e=>({w:120,h:120,main:`piece${e}`,draw({style:t,ink:r,main:o,c:n}){let s=fr(t),a=t==="cozy"?Z(o,.6):s.wall,i=t==="sci-fi"?n("primary"):t==="post-apocalypse"?"#3a3530":"#9fd2f0",p=(k,O,C=12,z=14)=>`<rect x="${k}" y="${O}" width="${C}" height="${z}" rx="2" fill="${i}" stroke="${r}" stroke-width="2"/>`+(t==="post-apocalypse"?`<path d="M${k} ${O+3} L${k+C} ${O+z-3}" stroke="#8a6a3a" stroke-width="3"/>`:`<rect x="${k+2}" y="${O+2}" width="${C*.3}" height="${z*.4}" fill="#fff" opacity="0.5"/>`),m='<ellipse cx="60" cy="114" rx="50" ry="6" fill="#000" opacity="0.25"/>',$=(k,O,C)=>{let z="";for(let F=0;F<C;F+=12)z+=`<path d="M${k+F} ${O} h12 v10 q-6 6 -12 0Z" fill="${F/12%2?"#fff":o}" stroke="${r}" stroke-width="2"/>`;return z};switch(e){case 1:return m+`<rect x="22" y="64" width="76" height="46" fill="${a}" stroke="${r}" stroke-width="3"/><rect x="16" y="60" width="88" height="8" fill="${W(a,.2)}" stroke="${r}" stroke-width="3"/><rect x="28" y="30" width="4" height="34" fill="${r}"/><rect x="88" y="30" width="4" height="34" fill="${r}"/>`+$(22,24,76)+`<circle cx="44" cy="56" r="6" fill="${n("coin")}" stroke="${r}" stroke-width="2"/><circle cx="60" cy="54" r="7" fill="${o}" stroke="${r}" stroke-width="2"/><circle cx="76" cy="56" r="6" fill="${n("accent")}" stroke="${r}" stroke-width="2"/>`;case 2:return m+`<rect x="18" y="40" width="84" height="70" fill="${a}" stroke="${r}" stroke-width="3"/><polygon points="12,42 60,14 108,42" fill="${s.roof}" stroke="${r}" stroke-width="3" stroke-linejoin="round"/>`+$(22,54,76)+p(28,72,28,24)+`<rect x="68" y="72" width="22" height="38" fill="${W(o,.2)}" stroke="${r}" stroke-width="3"/>`;case 3:return m+`<rect x="20" y="26" width="80" height="84" fill="${a}" stroke="${r}" stroke-width="3"/><rect x="14" y="18" width="92" height="10" fill="${s.roof}" stroke="${r}" stroke-width="3"/>`+p(30,36)+p(54,36)+p(78,36)+$(20,62,80)+p(30,78,26,22)+`<rect x="66" y="78" width="22" height="32" fill="${W(o,.25)}" stroke="${r}" stroke-width="3"/><rect x="42" y="4" width="36" height="16" rx="4" fill="${o}" stroke="${r}" stroke-width="2.5"/><path d="M54 8 h10 v6 a4 4 0 0 1 -10 0Z" fill="#fff"/>`;case 4:return m+`<rect x="80" y="14" width="12" height="40" fill="${W(s.wall,.35)}" stroke="${r}" stroke-width="3"/><circle cx="90" cy="8" r="7" fill="#cfcfd8" opacity="0.75"/><circle cx="100" cy="2" r="5" fill="#cfcfd8" opacity="0.5"/><path d="M12 110 L12 50 L36 36 L36 50 L60 36 L60 50 L84 36 L84 50 L108 50 L108 110Z" fill="${W(a,.08)}" stroke="${r}" stroke-width="3" stroke-linejoin="round"/>`+p(22,62)+p(46,62)+p(70,62)+`<rect x="40" y="84" width="40" height="26" fill="${o}" stroke="${r}" stroke-width="3"/>`+[0,1,2].map(k=>`<line x1="40" y1="${90+k*7}" x2="80" y2="${90+k*7}" stroke="${W(o,.35)}" stroke-width="2"/>`).join("");case 5:return m+`<polygon points="8,42 60,12 112,42" fill="${Z(s.wall,.15)}" stroke="${r}" stroke-width="3" stroke-linejoin="round"/><circle cx="60" cy="32" r="8" fill="${n("coin")}" stroke="${r}" stroke-width="2.5"/><rect x="14" y="42" width="92" height="8" fill="${W(s.wall,.1)}" stroke="${r}" stroke-width="3"/>`+[20,40,72,92].map(k=>`<rect x="${k}" y="50" width="8" height="52" fill="${Z(s.wall,.2)}" stroke="${r}" stroke-width="2.5"/>`).join("")+`<rect x="50" y="62" width="20" height="40" fill="${o}" stroke="${r}" stroke-width="3"/><rect x="10" y="102" width="100" height="8" fill="${W(s.wall,.15)}" stroke="${r}" stroke-width="3"/>`;default:{let k="";for(let O=22;O<92;O+=18)k+=p(40,O,12,12)+p(62,O,12,12);return m+`<rect x="58" y="2" width="3" height="14" fill="${r}"/><circle cx="59.5" cy="2" r="3" fill="${n("danger")}"/><rect x="32" y="14" width="56" height="96" fill="${t==="cozy"?a:qn(s.wall,o,.25)}" stroke="${r}" stroke-width="3"/>`+k+`<rect x="50" y="94" width="20" height="16" fill="${W(o,.25)}" stroke="${r}" stroke-width="2.5"/>`}}}}),ad={sky:uh,sun:mh,far:yh,near:gh,ground:bh,platform:xh,road:kh,floor:vh,tile_grass:Mh,tile_road:wh,...Object.fromEntries([1,2,3,4].map(e=>[`decor${e}`,$h(e)])),...Object.fromEntries([1,2,3].map(e=>[`tower${e}`,Eh(e)])),...Object.fromEntries([1,2,3,4,5,6].map(e=>[`biz${e}`,Sh(e)]))};var Xo=(e,t,r,o,n=.28)=>`<ellipse cx="${e}" cy="${t}" rx="${r}" ry="${o}" fill="#000" opacity="${n}"/>`,Hi=(e,t=4,r=.55)=>`<path d="${e}" fill="none" stroke="#fff" stroke-width="${t}" stroke-linecap="round" opacity="${r}"/>`,qr=e=>({w:100,h:100,draw:({ink:t})=>e(t)}),Lh={w:120,h:120,main:"danger",draw({style:e,ink:t,main:r,c:o}){let n=fr(e),s=Array.from({length:9},(a,i)=>`<circle cx="${24+i*9}" cy="30" r="2.6" fill="${o("coin")}" stroke="${t}" stroke-width="1"/>`).join("");return Xo(60,114,50,6,.25)+`<rect x="14" y="40" width="92" height="70" fill="${n.wall}" stroke="${t}" stroke-width="3"/><rect x="10" y="18" width="100" height="24" rx="4" fill="${r}" stroke="${t}" stroke-width="3"/>`+s+`<rect x="34" y="46" width="52" height="22" rx="3" fill="${W(n.wall,.6)}" stroke="${t}" stroke-width="2.5"/><polygon points="54,51 54,63 66,57" fill="${o("coin")}"/><rect x="24" y="76" width="30" height="34" fill="${W(r,.25)}" stroke="${t}" stroke-width="3"/><rect x="66" y="76" width="30" height="34" fill="${W(r,.25)}" stroke="${t}" stroke-width="3"/><line x1="39" y1="76" x2="39" y2="110" stroke="${t}" stroke-width="2"/><line x1="81" y1="76" x2="81" y2="110" stroke="${t}" stroke-width="2"/><polygon points="${et(60,9,8,3.5)}" fill="${o("coin")}" stroke="${t}" stroke-width="2"/>`}},_h={w:120,h:120,main:"primary",draw({style:e,ink:t,main:r,c:o}){let n=fr(e);return Xo(60,114,52,6,.25)+`<path d="M8 110 L8 84 Q60 62 112 84 L112 110Z" fill="${n.wall}" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><rect x="16" y="90" width="14" height="10" rx="2" fill="#9fd2f0" stroke="${t}" stroke-width="2"/><rect x="90" y="90" width="14" height="10" rx="2" fill="#9fd2f0" stroke="${t}" stroke-width="2"/><rect x="78" y="22" width="6" height="66" fill="${W(n.wall,.35)}" stroke="${t}" stroke-width="2.5"/>`+[34,50,66].map(s=>`<line x1="84" y1="${s}" x2="70" y2="${s}" stroke="${t}" stroke-width="2.5"/>`).join("")+`<path d="M60 6 Q72 22 70 64 L50 64 Q48 22 60 6Z" fill="${Z(r,.75)}" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><circle cx="60" cy="34" r="6" fill="#9fd2f0" stroke="${t}" stroke-width="2.5"/><path d="M50 52 L40 70 L50 66Z M70 52 L80 70 L70 66Z" fill="${r}" stroke="${t}" stroke-width="2.5" stroke-linejoin="round"/><path d="M54 64 L60 82 L66 64Z" fill="${o("coin")}" stroke="${t}" stroke-width="2"/><path d="M57 64 L60 74 L63 64Z" fill="#fff"/>`}},id=(e,t)=>qr(r=>`<circle cx="50" cy="50" r="44" fill="${Z(e,.7)}" stroke="${r}" stroke-width="4"/><path d="M50 12 L76 40 L60 40 L60 62 L40 62 L40 40 L24 40Z" fill="${e}" stroke="${r}" stroke-width="3.5" stroke-linejoin="round"/><text x="50" y="88" text-anchor="middle" font-family="Arial, sans-serif" font-weight="900" font-size="24" fill="${r}">${t}</text>`),Rh=qr(e=>`<circle cx="50" cy="50" r="44" fill="#ffe8a8" stroke="${e}" stroke-width="4"/>`+[30,50,70].map((t,r)=>`<path d="M${t} ${16+(r===1?0:8)} L${t+13} ${32+(r===1?0:8)} L${t+6} ${32+(r===1?0:8)} L${t+6} 56 L${t-6} 56 L${t-6} ${32+(r===1?0:8)} L${t-13} ${32+(r===1?0:8)}Z" fill="#ffb21a" stroke="${e}" stroke-width="2.5" stroke-linejoin="round"/>`).join("")+`<text x="50" y="88" text-anchor="middle" font-family="Arial, sans-serif" font-weight="900" font-size="24" fill="${e}">\xD72</text>`),Ah=qr(e=>ae(qe("r",[[0,"#fff6a0"],[1,"#ff7a1a"]],.5,.6))+`<path d="M50 8 Q70 30 66 46 Q78 40 76 26 Q92 46 86 66 Q80 90 50 92 Q20 90 14 66 Q10 46 26 30 Q28 46 38 48 Q30 26 50 8Z" fill="url(#r)" stroke="${e}" stroke-width="3.5" stroke-linejoin="round"/><text x="50" y="76" text-anchor="middle" font-family="Arial, sans-serif" font-weight="900" font-size="30" fill="#fff" stroke="${e}" stroke-width="2">\xD73</text>`),Th=qr(e=>Xo(50,92,24,4)+`<path d="M30 80 L62 46" stroke="${e}" stroke-width="16" stroke-linecap="round"/><path d="M30 80 L62 46" stroke="#a8b2c2" stroke-width="10" stroke-linecap="round"/><path d="M58 24 A20 20 0 1 0 80 50 L70 50 L62 42 L62 30Z" fill="#c8d0dc" stroke="${e}" stroke-width="3.5" stroke-linejoin="round"/>`+Hi("M66 22 Q76 24 80 32",3,.7)+`<circle cx="26" cy="22" r="10" fill="#e8384a" stroke="${e}" stroke-width="3"/><path d="M26 15 L26 23 M26 27 L26 28" stroke="#fff" stroke-width="3.5" stroke-linecap="round"/>`),Dh=qr(e=>ae(pe("c",[[0,"#8a5a32"],[1,"#5a381c"]]))+Xo(50,90,34,5)+`<path d="M38 26 L38 18 Q38 14 42 14 L58 14 Q62 14 62 18 L62 26" fill="none" stroke="${e}" stroke-width="5"/><rect x="12" y="26" width="76" height="56" rx="8" fill="url(#c)" stroke="${e}" stroke-width="4"/><line x1="12" y1="46" x2="88" y2="46" stroke="${e}" stroke-width="3"/><rect x="44" y="40" width="12" height="12" rx="2" fill="#ffc83a" stroke="${e}" stroke-width="2.5"/><text x="50" y="74" text-anchor="middle" font-family="Arial, sans-serif" font-weight="900" font-size="20" fill="#ffd34a">$</text>`+Hi("M20 32 L40 32",3,.5)),Oh=qr(e=>`<circle cx="50" cy="50" r="44" fill="#d8ecff" stroke="${e}" stroke-width="4"/><circle cx="50" cy="36" r="14" fill="#f4c9a0" stroke="${e}" stroke-width="3"/><path d="M36 30 Q50 14 64 30 Q60 22 50 22 Q40 22 36 30Z" fill="#5a381c" stroke="${e}" stroke-width="2"/><path d="M22 86 Q22 56 50 54 Q78 56 78 86Z" fill="#3a4a72" stroke="${e}" stroke-width="3" stroke-linejoin="round"/><path d="M46 56 L54 56 L56 76 L50 82 L44 76Z" fill="#e8384a" stroke="${e}" stroke-width="2" stroke-linejoin="round"/>`),Ch=qr(e=>`<circle cx="48" cy="54" r="34" fill="#fff" stroke="${e}" stroke-width="4"/><path d="M48 54 L48 32 M48 54 L64 62" stroke="${e}" stroke-width="5" stroke-linecap="round"/><path d="M74 10 Q86 22 82 34 Q92 30 90 20 Q100 34 92 46 Q84 56 72 50 Q62 42 68 30 Q72 36 76 34 Q70 22 74 10Z" fill="#ff7a1a" stroke="${e}" stroke-width="2.5" stroke-linejoin="round"/><rect x="40" y="12" width="16" height="8" rx="3" fill="#8a96aa" stroke="${e}" stroke-width="2.5"/>`),Ph=qr(e=>ae(qe("i",[[0,"#fff6a0"],[1,"#ffb000"]],.45,.4))+`<circle cx="50" cy="50" r="42" fill="url(#i)" stroke="${e}" stroke-width="4"/><path d="M58 10 L28 54 L48 54 L40 90 L74 42 L54 42Z" fill="#fff" stroke="${e}" stroke-width="3.5" stroke-linejoin="round"/>`+[[18,24],[82,74],[20,78]].map(([t,r])=>`<polygon points="${et(t,r,7,2.5,4)}" fill="#fff" stroke="${e}" stroke-width="1.5"/>`).join("")),Ih=qr(e=>Xo(50,92,24,4)+`<path d="M14 46 L46 12 L86 12 L86 52 L52 86Z" fill="#ff5a7a" stroke="${e}" stroke-width="4" stroke-linejoin="round"/><circle cx="72" cy="26" r="7" fill="#fff" stroke="${e}" stroke-width="3"/><text x="54" y="62" text-anchor="middle" font-family="Arial, sans-serif" font-weight="900" font-size="24" fill="#fff" stroke="${e}" stroke-width="1.5" transform="rotate(-45 54 54)">%</text>`+Hi("M48 18 L24 44",3,.6)),ld={ty_cinema:Lh,ty_port:_h,ty_up:id("#5ad35a","\xD72"),ty_up3:id("#4aa8ff","\xD73"),ty_upall:Rh,ty_rush:Ah,ty_wrench:Th,ty_investor:Dh,ty_manager:Oh,ty_sk_rush:Ch,ty_sk_instant:Ph,ty_sk_sale:Ih};var Ws=Object.freeze({...Gc,...Fc,...qc,...Uc,...Zc,...ed,...nd,...ld,...ad,...Kc}),Nh=e=>Object.prototype.hasOwnProperty.call(Ws,e);function zh(e,t){let r=Ws[e];return r?r.exact?t.w/Math.max(1,t.h):r.w/r.h:1}function Bh(e,t){let r=Ws[e];if(!r)return null;let{palette:o,style:n,box:s,px:a}=t,i=z=>Ai(z,o),p=r.exact?s.w:r.w,m=r.exact?s.h:r.h,$=r.draw({style:n,c:i,main:i(t.color??r.main??"primary"),ink:jc(n),w:p,h:m}),k=Math.max(1,Math.round(a.h)),O=Math.max(0,Math.round(t.padBottom??0)),C=O>0?m*(k+O)/k:m;return `<svg xmlns="http://www.w3.org/2000/svg" width="${Math.max(1,Math.round(a.w))}" height="${k+O}" viewBox="0 0 ${p} ${C}" preserveAspectRatio="none">${$}</svg>`}var He=e=>({w:Number(e.vars.view_w??720),h:Number(e.vars.view_h??1280)}),st=e=>e.vars.state==="playing",hn=e=>e.vars.started_tick===e.tick,Je=(e,t,r)=>{let o=Number(e.vars[t]??0)+r;return e.vars[t]=o,o},yr=(e,t)=>Number(e[t]);function Ct(e,t,r,o,n){let s=e.create();return e.set(s,K,{x:t,y:r}),e.set(s,ie,o),n&&e.set(s,n.type,n.data),s}var dt=(e,t)=>{for(let r of e.query(t))e.destroy(r);};function Jn(e){let t=new Set,r={down:false,x:0,y:0};return e.on(Nt,o=>{let n=o;n.type==="key"?t.add(n.key):n.type==="key-up"?t.delete(n.key):n.type==="press"||n.type==="move"?(r.down=true,r.x=n.x,r.y=n.y):n.type==="release"&&(r.down=false);}),{keys:t,pointer:r,axis(){return {x:(t.has("right")?1:0)-(t.has("left")?1:0),y:(t.has("down")?1:0)-(t.has("up")?1:0)}}}}function un(e,t,r,o){let n=e.h*(o.bottom-o.top),s=Math.floor(Math.min(e.w*(o.widthShare??.94)/t,n/r)),a=(e.w-s*t)/2,i=e.h*o.top+(n-s*r)/2;return {cols:t,rows:r,cell:s,left:a,top:i}}var at=(e,t,r)=>({x:e.left+e.cell*(t+.5),y:e.top+e.cell*(r+.5)});function Ur(e,t,r){let o=Math.floor((t-e.left)/e.cell),n=Math.floor((r-e.top)/e.cell);return o>=0&&o<e.cols&&n>=0&&n<e.rows?{col:o,row:n}:null}var fd=["piece1","piece2","piece3","piece4","piece5","piece6"];ve("kit.status");var Vs=e=>{let t=Math.max(0,Math.ceil(e));return `${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`},G=(e,t)=>e.emit(Oi,t),Yn=ve("kit.backdrop");function zt(e,t,r,o={}){for(let $ of e.query(Yn))e.destroy($);let n=He(e),s=($,k,O,C)=>Ct(e,k,O,C,{type:Yn,data:{speed:$}});if(t==="top"){let $=o.pan?1:0;s($,n.w/2,n.h/2,{shape:"tile",art:"floor",w:n.w,h:n.h,unit:Math.min(n.w,n.h)*.24,depth:-100});let k=e.rng.stream("backdrop"),O=Math.round(n.w*n.h/52e3),C=Math.min(n.w,n.h);for(let z=0;z<O;z++){let F=C*k.range(.06,.1);s($,k.range(0,n.w),k.range(0,n.h),{shape:"sprite",art:`decor${k.int(1,4)}`,w:F,h:F,depth:-95});}return}let a=r??n.h*.62;s(0,n.w/2,n.h/2,{shape:"sprite",art:"sky",w:n.w,h:n.h,depth:-100});let i=Math.min(n.w,n.h)*.34;s(.02,n.w*.74,a*.3,{shape:"sprite",art:"sun",w:i,h:i,depth:-99});let p=Math.min(n.h*.32,n.w*.55);s(.12,n.w/2,a-p/2,{shape:"tile",art:"far",w:n.w,h:p,depth:-90});let m=p*.62;s(.4,n.w/2,a-m/2+2,{shape:"tile",art:"near",w:n.w,h:m,depth:-80}),t==="board"?s(0,n.w/2,(n.h+a)/2,{shape:"tile",art:"ground",w:n.w,h:n.h-a+4,unit:p*.7,depth:-79}):s(0,n.w/2,(n.h+a)/2,{shape:"rect",w:n.w,h:n.h-a,color:"#140f0c",alpha:.92,depth:-79});}function Zo(e,t){for(let r of e.query(Yn)){let o=e.need(r,Yn).speed;if(o<=0)continue;let n=e.need(r,ie);n.shape==="tile"&&(n.scrollX=(n.scrollX??0)+t*o);}}function pd(e,t,r){let o=He(e),n=Math.min(o.w,o.h)*.1;for(let s of e.query(Yn)){if(e.need(s,Yn).speed<=0)continue;let a=e.need(s,ie);if(a.shape==="tile"){a.scrollX=(a.scrollX??0)+t,a.scrollY=(a.scrollY??0)+r;continue}let i=e.need(s,K);i.x-=t,i.y-=r,i.x<-n?i.x+=o.w+2*n:i.x>o.w+n&&(i.x-=o.w+2*n),i.y<-n?i.y+=o.h+2*n:i.y>o.h+n&&(i.y-=o.h+2*n);}}function it(e,t,r){let o=e.get(t,ie);o?.shape==="actor"&&(o.pose=r);}function Fe(e,t,r){let o=e.get(t,ie);o?.shape==="actor"&&(o.act=r,o.actN=(o.actN??0)+1);}var Qn=ve("kit.fading"),cd=new WeakSet;function _n(e,t,r){e.set(t,Qn,{left:r,total:r}),!cd.has(e)&&(cd.add(e),e.addSystem({id:"kit.fading",order:90,run(o,n){for(let s of o.query(Qn)){let a=o.need(s,Qn);a.left-=n;let i=o.get(s,ie);i&&(i.alpha=Math.max(0,Math.min(1,a.left/a.total*2))),a.left<=0&&o.destroy(s);}}}));}var er=(e,t,r=5)=>r+t/Math.max(1,He(e).h),Zn=ve("kit.hint"),dd=new WeakSet,js=(e,t,r)=>({x:e+r*.11,y:t+r*.42});function kt(e,t,r,o=r,n){Bt(e);let s=n??Math.min(He(e).w,He(e).h)*.13,a={kind:t,ax:r.x,ay:r.y,bx:o.x,by:o.y,size:s,t:0},i=js(r.x,r.y,s);Ct(e,r.x,r.y,{shape:"circle",r:s*.22,color:"#ffffff",alpha:0,depth:89},{type:Zn,data:{...a,part:"ring"}}),Ct(e,i.x,i.y,{shape:"sprite",art:"hand",w:s,h:s,alpha:0,depth:90},{type:Zn,data:{...a,part:"hand"}}),!dd.has(e)&&(dd.add(e),e.addSystem({id:"kit.hints",order:95,run(p,m){for(let $ of p.query(Zn)){let k=p.need($,Zn);k.t+=m;let O=p.need($,K),C=p.need($,ie);if(k.kind==="tap"){let z=k.t%1.2/1.2,F=z>.35&&z<.55;if(k.part==="hand"){let ne=js(k.ax,k.ay+(F?k.size*.06:0),k.size);O.x=ne.x,O.y=ne.y,O.scale=F?.9:1,C.alpha=Math.min(1,k.t*4);}else {let ne=z<.4?0:(z-.4)/.6;O.scale=1+ne*2.2,C.alpha=z<.4?0:.55*(1-ne);}}else if(k.kind==="swipe"){let z=k.t%1.6/1.6,F=z<.15?0:z>.75?1:(z-.15)/.6,ne=F*F*(3-2*F),X=k.ax+(k.bx-k.ax)*ne,ye=k.ay+(k.by-k.ay)*ne;if(k.part==="hand"){let be=js(X,ye,k.size);O.x=be.x,O.y=be.y,C.alpha=z<.1?z*10:z>.85?Math.max(0,(1-z)/.15):1;}else O.x=X,O.y=ye,C.alpha=z>.15&&z<.8?.35:0;}else {let z=k.t*3,F=k.ax+Math.cos(z)*k.bx,ne=k.ay+Math.sin(z)*k.bx;if(k.part==="hand"){let X=js(F,ne,k.size);O.x=X.x,O.y=X.y,C.alpha=Math.min(1,k.t*3);}else O.x=F,O.y=ne,C.alpha=.3;}}}}));}function Bt(e){for(let t of e.query(Zn))e.destroy(t);}var _r=e=>e.query(Zn).length>0,vt=(e,t)=>e.vars[`learned:${t}`]===true;function Lt(e,t){vt(e,t)||(e.vars[`learned:${t}`]=true,Bt(e));}var eo=ve("round.start"),Ut="round-started",Xt="round-over",Zt="round-ended",Wi="start-round",Qt="show-start",tr="revive-offer",rr="revive",nr="give-up",Gs={id:"round",version:1,setup({world:e}){e.vars.state="ready",e.vars.score=0,e.vars.coins=0,e.vars.best=typeof e.vars.best=="number"?e.vars.best:0,e.vars.round=0;let t=o=>{for(let i of o.query(eo))o.destroy(i);if(o.vars.state!=="ready")return;let n=He(o),s=Math.min(n.w,n.h)*.26,a={x:n.w/2,y:n.h*.55};Ct(o,n.w/2,n.h/2,{shape:"rect",w:n.w,h:n.h,color:"#05040a",alpha:.4,depth:84},{type:eo,data:{t:-1}}),Ct(o,a.x,a.y,{shape:"sprite",art:"play",w:s,h:s,color:"accent",depth:85},{type:eo,data:{t:0}}),kt(o,"tap",{x:a.x+s*.12,y:a.y+s*.1});},r=()=>{for(let o of e.query(eo))e.destroy(o);Bt(e),e.vars.state="playing",e.vars.score=0,e.vars.coins=0,e.vars.round=Number(e.vars.round??0)+1,e.vars.started_tick=e.tick,e.emit(Ut,{round:e.vars.round});};e.on(Nt,o=>{let n=o;e.vars.state==="ready"&&(n.type==="tap"||n.type==="key"&&n.key==="action")&&r();}),e.on(Wi,()=>{e.vars.state!=="playing"&&r();}),e.on(Qt,()=>{e.vars.state==="ended"&&(e.vars.state="ready",t(e));}),e.on(qt,()=>t(e)),e.addSystem({id:"round.start",order:96,run(o,n){for(let s of o.query(eo)){let a=o.need(s,eo);a.t<0||(a.t+=n,o.need(s,K).scale=1+.06*Math.sin(a.t*5));}}}),t(e),e.on(Xt,o=>{if(e.vars.state!=="playing")return;e.vars.state="ended",Bt(e);let n=Number(e.vars.score??0),s=Math.max(Number(e.vars.best??0),n);e.vars.best=s,e.emit(Zt,{score:n,coins:Number(e.vars.coins??0),best:s,reason:typeof o.reason=="string"?o.reason:"over",...o.stats&&typeof o.stats=="object"?{stats:o.stats}:{}});});}};var Ks=["wall","barrier","pit","mover","train","rock"];var Yo=["magnet","shield","double","dash","flight"],Rr={magnet:{art:"magnet",color:"danger",seconds:6,var:"meta:magnet_t",weight:3},shield:{art:"shield",color:"muted",seconds:8,var:"meta:shield_t",weight:2.5},double:{art:"coin2x",color:"coin",seconds:8,var:"meta:double_t",weight:2.5},dash:{art:"boot",color:"accent",seconds:2.5,var:"meta:dash_t",weight:1.5},flight:{art:"wing",color:"secondary",seconds:4,var:"meta:flight_t",weight:1}},Qo=20,hd={wall:1,barrier:2,pit:3,mover:4,train:5,rock:6};function to(e,t=.5){let r=Math.max(1,Math.min(Qo,Math.floor(e))),o=(r-1)/(Qo-1),n=Ks.filter(i=>hd[i]<=r),s=Ks.find(i=>hd[i]===r)??null,a=330+t*120+o*220;return {level:r,length:Math.round(16e3+(r-1)*3e3),speed:a,topSpeed:a*(1.25+o*.1),density:Math.min(.72,.3+t*.12+o*.3),kinds:n,fresh:s,coinStar:.6,firstClearGold:60+(r-1)*25}}var ro=e=>Math.floor(e/30),no=[{id:"hero",cast:"hero",gems:0,perk:"none"},{id:"hero2",cast:"hero2",gems:150,perk:"heart"},{id:"hero3",cast:"hero3",gems:300,perk:"power"}],ji="kit-runner",Vi=[{id:"MagnetTime",var:"meta:magnet_t",art:"magnet",color:"danger",perLevel:.6,unit:"s",maxLevel:15,price:20,growth:.12},{id:"ShieldTime",var:"meta:shield_t",art:"shield",color:"muted",perLevel:.8,unit:"s",maxLevel:15,price:25,growth:.12},{id:"DoubleTime",var:"meta:double_t",art:"coin2x",color:"coin",perLevel:.8,unit:"s",maxLevel:15,price:25,growth:.12},{id:"DashTime",var:"meta:dash_t",art:"boot",color:"accent",perLevel:.3,unit:"s",maxLevel:15,price:30,growth:.12},{id:"FlightTime",var:"meta:flight_t",art:"wing",color:"secondary",perLevel:.4,unit:"s",maxLevel:15,price:35,growth:.12},{id:"Luck",var:"meta:luck",art:"clover",color:"accent",perLevel:5,unit:"%",maxLevel:20,price:30,growth:.1},{id:"HeadStart",var:"meta:head_start",art:"lightning",color:"primary",perLevel:.4,unit:"s",maxLevel:10,price:50,growth:.15},{id:"Greed",var:"meta:greed",art:"coin",color:"coin",perLevel:2,unit:"%",maxLevel:25,price:40,growth:.1}],ud={game:"runner",character:ji,stats:Vi,heroes:no,levels:Qo,firstClearGold:e=>to(e).firstClearGold,stars:3};var _t=ve("runner.item"),Xr=ve("runner.player"),Fs=ve("runner.stripe"),md=ve("runner.hud"),Wt=(e,t)=>{let r=Number(e.vars.view_w??720),o=Number(e.vars.view_h??1280),n=Math.min(o*.11,r*.2,o*.5/t),s=o*.6-n*t/2;return {viewW:r,viewH:o,top:s,laneH:n,playerX:Math.min(r*.24,o*.3)}},oo=(e,t)=>e.top+e.laneH*(t+.72),Jo=(e,t)=>{let r=Number(e.vars[t]??0);return Number.isFinite(r)?r:0},Pt={wall:1.3,barrier:.5,mover:1,train:.95,rock:1.05,jump:1.25,flight:1.9},qs={id:"lane-runner",version:2,engines:["phaser"],requires:["round"],params:{lanes:{type:"number",default:3,min:2,max:5,integer:true},difficulty:{type:"number",default:.5,min:0,max:1},coinRate:{type:"number",default:.7,min:0,max:1},powerRate:{type:"number",default:.22,min:0,max:1},lives:{type:"number",default:3,min:1,max:9,integer:true},coinScore:{type:"number",default:10,min:0,max:1e3,integer:true},graceTime:{type:"number",default:1.2,min:0,max:5},jumpTime:{type:"number",default:.62,min:.3,max:1.5},lengthScale:{type:"number",default:1,min:.05,max:5}},setup({world:e,params:t,mode:r}){let o=u=>yr(t,u),n=o("lanes"),s=e.rng.stream("lane-runner"),a=null,i=u=>({...u,kinds:[...Sr(r,"obstacles",u.kinds)]}),p=Sr(r,"powers",Yo),m=i(to(1,o("difficulty"))),$=m.length,k=0,O=0,C=0,z=false,F=false,ne=false,X=0,ye=0,be=0,fe=0,we=0,de=0,Re=0,Ce=3,Me=0,ce=false,ue=new Map,Pe=new Map,Le=()=>no.find(u=>u.id===e.vars["meta:hero"])??no[0],oe=u=>(Rr[u].seconds+Jo(e,Rr[u].var))*(Le().perk==="power"?1.25:1),Ee=()=>e.vars.reviving===true,tt=()=>{for(let b of e.query(Fs))e.destroy(b);let u=Wt(e,n);zt(e,"side",u.top+2);for(let b=0;b<n;b++){let d=e.create();e.set(d,Fs,{index:b}),e.set(d,K,{x:u.viewW/2,y:u.top+u.laneH*(b+.5)}),e.set(d,ie,{shape:"tile",art:"road",w:u.viewW,h:u.laneH,unit:u.laneH*1.28,depth:-20+b*.1});}let g=u.viewH-(u.top+u.laneH*n),f=e.create();e.set(f,Fs,{index:-1}),e.set(f,K,{x:u.viewW/2,y:u.viewH-g/2+1}),e.set(f,ie,{shape:"tile",art:"ground",w:u.viewW,h:g+2,unit:u.laneH*1.2,depth:-21});},Ne=(u,g,f)=>oo(u,g.lane)-g.alt-f/2,se=(u,g,f,b,d)=>{let h=u.laneH,v=9+f;switch(g){case "wall":return {v:{shape:"sprite",art:"obstacle",w:b,h:h*Pt.wall,depth:v},h:h*Pt.wall};case "barrier":return {v:{shape:"sprite",art:"hurdle",w:b,h:h*Pt.barrier,depth:v},h:h*Pt.barrier};case "pit":return {v:{shape:"sprite",art:"pit",w:b,h:h*.42,depth:-19+f*.1+.05},h:-h*.42};case "mover":return {v:{shape:"actor",cast:"foe",h:h*1.5,pose:"run",facing:-1,depth:v},h:h*1.5};case "train":return {v:{shape:"sprite",art:"wagon",w:b,h:h*Pt.train,depth:v},h:h*Pt.train};case "ramp":return {v:{shape:"sprite",art:"ramp",w:b,h:h*Pt.train,depth:v},h:h*Pt.train};case "rock":return {v:{shape:"sprite",art:"shadow",w:b,h:h*.3,alpha:.5,depth:-19+f*.1+.06},h:-h*.3};case "coin":return {v:{shape:"sprite",art:"coin",w:b,h:b,depth:v+.2},h:b};case "power":return {v:{shape:"sprite",art:Rr[d??"magnet"].art,color:Rr[d??"magnet"].color,w:b,h:b,depth:v+.2},h:b};case "finish":return {v:{shape:"sprite",art:"finish",w:h*.7,h:h*n+h*.9,depth:8},h:0}}},ke=(u,g,f,b={})=>{let d=Wt(e,n),h=b.size??(u==="coin"?d.laneH*.42:u==="power"?d.laneH*.62:d.laneH*.85),v=b.alt??(u==="coin"?d.laneH*.5:u==="power"?d.laneH*.6:0),A=e.create();e.set(A,_t,{lane:g,kind:u,size:h,alt:v,...b.power!==void 0?{power:b.power}:{}});let{v:N,h:B}=se(d,u,g,h,b.power),Q=d.viewW+d.laneH+h/2+f,J=u==="finish"?d.top+d.laneH*n/2:B<0?oo(d,g)+B/2+d.laneH*.08:Ne(d,{lane:g,alt:v},B);return e.set(A,K,{x:Q,y:J}),e.set(A,ie,N),u==="coin"&&fe++,A},_e=(u,g,f,b)=>{let d=Wt(e,n);for(let h=0;h<f;h++)ke("coin",u,g+h*d.laneH*.75,b!==void 0?{alt:b}:{});},Te=(u,g)=>{let f=1+Jo(e,"meta:luck");s.chance(Math.min(.9,o("powerRate")*f))&&ke("power",u,g,{power:s.weighted(p,b=>Rr[b].weight)});},Be=u=>m.kinds.includes(u),ee=()=>[...Array(n).keys()],Ie=u=>{let g=["wall",...Be("barrier")?["barrier"]:[],...Be("pit")?["pit"]:[]],f=new Map;for(let h of ee())s.chance(m.density)&&f.set(h,s.pick(g));f.size>=n&&f.delete(s.int(0,n-1));let b=Wt(e,n);for(let[h,v]of f)ke(v,h,u,v==="pit"?{size:b.laneH*1.25}:{});let d=ee().filter(h=>!f.has(h));d.length>0&&s.chance(o("coinRate"))&&_e(s.pick(d),u-b.laneH,3);for(let[h,v]of f)(v==="barrier"||v==="pit")&&s.chance(.5)&&_e(h,u-b.laneH*.75,3,b.laneH*1.3);},nt=()=>{let g=Wt(e,n).laneH,f=d=>d+Math.round(m.density*3),b=[{id:"scatter",weight:3,make:d=>{let h=f(2);for(let v=0;v<h;v++)Ie(v*d);return Te(s.int(0,n-1),h*d-d/2),h*d}},{id:"rest",weight:1,make:d=>{let h=s.int(0,n-1);for(let v=0;v<4;v++)_e(h,v*d*.8,3),h=Math.max(0,Math.min(n-1,h+(s.chance(.5)?1:-1)));return Te(h,4*d*.8),4*d*.8}}];return m.level>=3&&b.push({id:"corridor",weight:2,make:d=>{let h=f(3),v=s.int(0,n-1);for(let A=0;A<h;A++){for(let N of ee())N!==v&&ke("wall",N,A*d);_e(v,A*d-g*.4,2),A%2===1&&(v=Math.max(0,Math.min(n-1,v+(s.chance(.5)?1:-1))));}return h*d}}),(Be("barrier")||Be("pit"))&&b.push({id:"hurdles",weight:2,make:()=>{let d=Math.max(g*3.6,m.speed*o("jumpTime")*1.45),h=2+Math.round(m.density*2),v=[...Be("barrier")?["barrier"]:[],...Be("pit")?["pit"]:[]],A=s.int(0,n-1);for(let N=0;N<h;N++){for(let B of ee()){let Q=s.pick(v);ke(Q,B,N*d,Q==="pit"?{size:g*1.25}:{});}_e(A,N*d-g*.75,3,g*1.3);}return h*d}}),Be("train")&&b.push({id:"train",weight:2,make:d=>{let h=s.int(0,n-1),v=g*s.int(5,8),A=s.chance(.75),N=g*1.4;A&&ke("ramp",h,0,{size:N}),ke("train",h,(A?N:0)+v/2-g*.42,{size:v}),A&&_e(h,N+g*.4,Math.floor(v/(g*.75))-1,g*(Pt.train+.5));let B=ee().filter(J=>J!==h),Q=s.pick(B);if(s.chance(.5))ke("train",Q,d*.5+v/2,{size:v*.8});else for(let J=0;J<2;J++)ke("wall",Q,d*(.5+J*1.4));return (A?N:0)+v+d*.5}}),Be("mover")&&b.push({id:"movers",weight:1.5,make:d=>{let h=1+(s.chance(m.density)?1:0),v=new Set;for(let N=0;N<h;N++){let B=s.int(0,n-1);v.has(B)&&(B=(B+1)%n),v.add(B),ke("mover",B,N*d*1.6,{size:g*.6});}let A=ee().filter(N=>!v.has(N));return A.length>0&&_e(s.pick(A),0,4),h*d*1.6}}),Be("rock")&&b.push({id:"rocks",weight:1.5,make:d=>{let h=2+(s.chance(m.density)?1:0);for(let v=0;v<h;v++){let A=s.int(0,n-1);ke("rock",A,v*d*1.2,{size:g*.9});let N=ee().filter(B=>B!==A);_e(s.pick(N),v*d*1.2,2);}return h*d*1.2}}),b},ht=u=>{let g=Wt(e,n),f=Math.floor(n/2),b=m.fresh;if(b===null||b==="wall")return 0;if(b==="barrier"||b==="pit"){for(let d=0;d<3;d++)ke(b,f,d*u*1.6,b==="pit"?{size:g.laneH*1.25}:{}),_e(f,d*u*1.6-g.laneH*.75,3,g.laneH*1.3);return 3*u*1.6}return b==="train"?(ke("ramp",f,0,{size:g.laneH*1.4}),ke("train",f,g.laneH*1.4+g.laneH*3-g.laneH*.42,{size:g.laneH*6}),_e(f,g.laneH*1.8,7,g.laneH*(Pt.train+.5)),g.laneH*8+u):(ke(b,f,0,{size:b==="mover"?g.laneH*.6:g.laneH*.9}),u*1.5)},Ae=()=>{let u=Math.max(Wt(e,n).laneH*2.1,300-m.density*110),g;if(!ce&&m.fresh!==null&&m.fresh!=="wall")ce=true,g=ht(u);else {let f=nt();g=(C>0&&C%4===3?f.find(d=>d.id==="rest"):s.weighted(f,d=>d.weight)).make(u);}C++,O=Number(e.vars.distance??0)+g+u*1.2;},Gt=(u,g,f)=>{let b=u.laneH*1.05;return {x:u.playerX,y:oo(u,g)-f-b/2,h:b}},Xe=()=>{let u=Wt(e,n);(a===null||!e.isAlive(a))&&(a=e.create(),e.set(a,Xr,{lane:Math.floor(n/2),size:u.laneH*.5,alt:0,vy:0}),e.set(a,ie,{shape:"actor",cast:Le().cast,h:0,pose:"idle",depth:10}));let g=e.need(a,Xr);g.size=u.laneH*.5;let f=Gt(u,g.lane,g.alt);e.set(a,K,{x:f.x,y:f.y});let b=e.need(a,ie);b.shape==="actor"&&(b.cast=Le().cast,b.h=f.h,b.depth=10+g.lane);},rt=()=>{for(let g of e.query(_t))e.destroy(g);It(),m=i(to(Jo(e,"meta:chapter")||1,o("difficulty"))),$=Math.round(m.length*o("lengthScale")),Ce=o("lives")+(Le().perk==="heart"?1:0),e.vars.distance=0,e.vars.meters=0,e.vars.level_length=$,e.vars.runner_length_scale=o("lengthScale"),e.vars.runner_level=m.level,e.vars.speed=m.speed,e.vars.lives=Ce,e.vars.coins=0,e.vars.score=0,e.vars.mult=1,e.vars.stars=0,e.vars.reviving=false,k=0,O=Wt(e,n).laneH*2,C=0,z=false,F=false,ne=false,X=0,ye=0,be=0,fe=0,we=0,de=0,Re=0,Me=0,ce=false,ue.clear();let u=Jo(e,"meta:head_start");if(u>0&&ue.set("dash",u),a!==null&&e.isAlive(a)){let g=e.need(a,Xr);g.lane=Math.floor(n/2),g.alt=0,g.vy=0;}Xe();},lt=u=>{if(!st(e)||Ee()||a===null)return;let g=e.need(a,Xr),f=Math.min(n-1,Math.max(0,g.lane+u));f!==g.lane&&Lt(e,"runner-lanes"),g.lane=f;},ft=()=>{let u=Wt(e,n),g=o("jumpTime");return 8*u.laneH*Pt.jump/(g*g)},yt=(u,g,f)=>{let b=Wt(u,n),d=b.playerX,h=b.laneH*.22,v=0;for(let A of u.query(_t)){let N=u.need(A,_t);if(N.lane!==g||N.kind!=="train"&&N.kind!=="ramp")continue;let B=u.need(A,K),Q=B.x-N.size/2,J=B.x+N.size/2;if(d+h<Q||d-h>J)continue;let $e=b.laneH*Pt.train;if(N.kind==="ramp")v=Math.max(v,$e*Math.max(0,Math.min(1,(d-Q)/N.size)));else if(f>=$e-b.laneH*.12)v=Math.max(v,$e);else return null}return v},ut=()=>{if(!st(e)||Ee()||a===null||ue.has("flight"))return;let u=e.need(a,Xr),g=yt(e,u.lane,u.alt)??0;u.alt-g>2||(u.vy=ft()*o("jumpTime")/2,Re++,Lt(e,"runner-jump"),Bt(e),e.emit("jumped",{}),Fe(e,a,"jump"));},Et=()=>{if(vt(e,"runner-lanes")||a===null)return;let u=Wt(e,n),g=u.playerX+u.laneH*1.6,f=oo(u,Math.floor(n/2))-u.laneH*.4;kt(e,"swipe",{x:g,y:f+u.laneH*.5},{x:g,y:f-u.laneH*.9},u.laneH);},Ze=(u,g,f,b)=>{let d=Pe.get(u);(d===void 0||!e.isAlive(d))&&(d=e.create(),e.set(d,md,{id:u}),Pe.set(u,d)),e.set(d,K,{x:g,y:f}),e.set(d,ie,b);},Ge=u=>{let g=Pe.get(u);g!==void 0&&e.destroy(g),Pe.delete(u);};function It(){for(let u of Pe.values())e.destroy(u);Pe.clear(),dt(e,md);}let Qe=(u,g,f,b,d,h,v,A=41)=>{let N=Math.max(0,Math.min(1,Math.round(h*100)/100));Ze(`${u}:bg`,g,f,{shape:"rect",w:b,h:d,color:"#000000",alpha:.45,radius:d/2,depth:A});let B=Math.max(0,(b-4)*N);B<1?Ge(`${u}:fill`):Ze(`${u}:fill`,g-(b-4)/2+B/2,f,{shape:"rect",w:B,h:d-4,color:v,radius:(d-4)/2,depth:A+.01});},Kt=u=>{let g=Wt(u,n),f=Math.min(g.viewW,g.viewH),b=g.viewH*.085,d=g.viewW*.66,h=Math.max(10,f*.026),v=Number(u.vars.distance??0)/Math.max(1,$);Qe("way",g.viewW/2,b,d,h,v,"accent");let A=f*.055;Ze("flag",g.viewW/2+d/2+A*.45,b-A*.25,{shape:"sprite",art:"flag",w:A,h:A,depth:42}),Ze("lvl",g.viewW/2-d/2-f*.05,b,{shape:"text",text:`${m.level}`,size:Math.round(f*.04),color:"text",bold:true,depth:42});let N=b+f*.07,B=f*.05,Q=Number(u.vars.lives??0);for(let ze=0;ze<Ce;ze++)Ze(`h${ze}`,g.viewW*.07+ze*B*1.1,N,{shape:"sprite",art:"heart",w:B,h:B,alpha:ze<Q?1:.25,depth:42});for(let ze=Ce;ze<10;ze++)Ge(`h${ze}`);let J=f*.045,$e=String(u.vars.coins??0);Ze("coin:i",g.viewW*.93-$e.length*J*.6-J*.7,N,{shape:"sprite",art:"coin",w:J,h:J,depth:42}),Ze("coin",g.viewW*.93-$e.length*J*.6/2,N,{shape:"text",text:$e,size:Math.round(J),color:"text",bold:true,depth:42});let Se=Number(u.vars.mult??1);Se>1?Ze("mult",g.viewW*.9,N+J*1.2,{shape:"text",text:`x${Se}`,size:Math.round(J*1.05),color:"coin",bold:true,depth:42}):Ge("mult");let Ye=f*.055,pt=0;for(let ze of Yo){let le=ue.get(ze);if(le===void 0){Ge(`p:${ze}`),Ge(`pb:${ze}:bg`),Ge(`pb:${ze}:fill`);continue}let V=g.viewW*.07+pt*Ye*1.25,te=N+B*1.25;Ze(`p:${ze}`,V,te,{shape:"sprite",art:Rr[ze].art,color:Rr[ze].color,w:Ye,h:Ye,depth:42}),Qe(`pb:${ze}`,V,te+Ye*.7,Ye,Math.max(6,f*.011),le/Math.max(.1,oe(ze)),"coin",42),pt++;}},Yt=(u,g)=>{if(!st(u)||F)return;F=true;let f=g==="cleared",b=f?1+(fe>0&&we>=fe*m.coinStar?1:0)+(de===0?1:0):0;u.vars.stars=b,f&&u.vars["meta:first_clear"]===true&&Je(u,"coins",m.firstClearGold);let d=ro(Number(u.vars.distance??0));u.vars.score=Me+d*2+(f?500*b:0),u.vars.reviving=false,u.emit(Xt,{reason:g,stats:{chapter:m.level,seconds:Math.floor(X),cleared:f,stars:b,coins:we,meters:d,jumps:Re,hits:de}});},Ft=u=>{if(u.vars.revive_ready===true&&!ne){u.vars.reviving=true,Bt(u),u.emit(tr,{});return}Yt(u,"crashed");},ur=u=>{if(!Ee())return;ne=true,u.vars.reviving=false,u.vars.lives=Math.max(1,Math.ceil(Ce/2)),k=2.5,ue.set("shield",Math.max(ue.get("shield")??0,3));let g=Wt(u,n);for(let f of u.query(_t)){let b=u.need(f,_t);if(b.kind==="coin"||b.kind==="power"||b.kind==="finish")continue;let d=u.need(f,K);d.x-b.size/2<g.playerX+g.laneH*6&&(G(u,{kind:"burst",x:d.x,y:d.y,color:"coin",n:8,size:g.laneH*.6}),u.destroy(f));}if(a!==null){let f=u.need(a,Xr);f.alt=0,f.vy=0,it(u,a,"run");let b=u.need(a,K);G(u,{kind:"ring",x:b.x,y:b.y,color:"coin",size:g.laneH*4});}G(u,{kind:"flash",color:"coin"});},bt=(u,g)=>{if(a===null)return;let f=u.need(g,K),b=Wt(u,n);if(ue.has("dash")){G(u,{kind:"burst",x:f.x,y:f.y,color:"accent",n:14,size:b.laneH*.8}),G(u,{kind:"shake",power:.6}),u.need(g,_t).kind!=="pit"&&u.destroy(g);return}if(k>0)return;if(ue.has("shield")){ue.delete("shield"),k=.8,G(u,{kind:"ring",x:b.playerX,y:u.need(a,K).y,color:"muted",size:b.laneH*2}),u.need(g,_t).kind!=="pit"&&u.destroy(g);return}de++,ye=0,u.vars.mult=1;let d=Number(u.vars.lives??1)-1;u.vars.lives=d,u.emit("player-hit",{lives:d}),G(u,{kind:"burst",x:f.x,y:f.y,color:"danger",n:14,size:b.laneH*.9}),G(u,{kind:"shake",power:1.5}),Fe(u,a,"hit"),u.need(g,_t).kind!=="pit"&&u.destroy(g),k=o("graceTime"),d<=0&&Ft(u);},D=(u,g)=>{let f=u.need(g,_t),b=u.need(g,K),d=Wt(u,n);if(f.kind==="power"&&f.power!==void 0){ue.set(f.power,oe(f.power)),u.emit("power-up",{id:f.power}),G(u,{kind:"ring",x:b.x,y:b.y,color:Rr[f.power].color,size:d.laneH*1.6}),u.destroy(g);return}ye++;let h=Math.min(5,1+Math.floor(ye/12));h>Number(u.vars.mult??1)&&G(u,{kind:"pop",x:d.playerX,y:b.y-d.laneH,text:`x${h}`,color:"coin",size:Math.round(d.laneH*.42)}),u.vars.mult=h;let v=(ue.has("double")?2:1)*(1+Jo(u,"meta:greed"));be+=v;let A=Math.floor(be);be-=A,A>0&&Je(u,"coins",A),we++,Me+=Math.round(v*o("coinScore")*h),u.emit("coin-collected",{value:v}),G(u,{kind:"burst",x:b.x,y:b.y,color:"coin",n:6,size:f.size*1.3}),u.destroy(g);};e.on(Nt,u=>{let g=u;e.vars.started_tick!==e.tick&&(g.type==="swipe"&&(g.dir==="up"||g.dir==="down")?lt(g.dir==="up"?-1:1):g.type==="swipe"&&g.dir==="right"?ut():g.type==="key"&&(g.key==="left"||g.key==="up")?lt(-1):g.type==="key"&&(g.key==="right"||g.key==="down")?lt(1):(g.type==="key"&&g.key==="action"||g.type==="tap")&&ut());}),e.on(Ut,()=>{rt(),a!==null&&it(e,a,"run"),Et();}),e.on(Qt,rt),e.on(rr,()=>ur(e)),e.on(nr,()=>{Ee()&&(e.vars.reviving=false,Yt(e,"crashed"));}),e.on(Zt,u=>{a!==null&&e.isAlive(a)&&it(e,a,u.reason==="cleared"?"dance":"die");for(let g of e.query(_t))e.need(g,_t).kind==="mover"&&it(e,g,"idle");It();}),e.on(qt,()=>{tt(),a!==null&&Xe();let u=Wt(e,n);for(let g of e.query(_t)){let f=e.need(g,_t),{v:b,h:d}=se(u,f.kind,f.lane,f.size,f.power);e.set(g,ie,b),e.need(g,K).y=f.kind==="finish"?u.top+u.laneH*n/2:d<0?oo(u,f.lane)+d/2+u.laneH*.08:Ne(u,f,d);}}),e.addSystem({id:"lane-runner",order:0,run(u,g){if(!st(u)||a===null||F||Ee())return;let f=Wt(u,n),b=f.laneH;X+=g;let d=Number(u.vars.distance??0),v=(m.speed+(m.topSpeed-m.speed)*Math.min(1,d/Math.max(1,$)))*(ue.has("dash")?1.6:1);u.vars.speed=Math.round(v);let A=v*g;u.vars.distance=d+A,u.vars.meters=ro(d+A),k>0&&(k=Math.max(0,k-g));for(let[le,V]of [...ue])V-g<=0?(ue.delete(le),le==="flight"&&(k=Math.max(k,.8))):ue.set(le,V-g);Zo(u,A);for(let le of u.query(Fs)){let V=u.need(le,ie);V.shape==="tile"&&(V.scrollX=(V.scrollX??0)+A);}let N=$-(d+A);if(!z&&N<=f.viewW-f.playerX+b){z=true;let le=ke("finish",0,0);u.need(le,K).x=f.playerX+N;}else !z&&d>=O&&N>f.viewW&&Ae();let B=u.need(a,Xr),Q=ue.has("flight");if(Q)B.alt+=(b*Pt.flight-B.alt)*Math.min(1,g*6),B.vy=0,Math.floor((d+A)/(b*.9))!==Math.floor(d/(b*.9))&&ke("coin",B.lane,0,{alt:b*(Pt.flight+.4)});else {B.vy-=ft()*g,B.alt+=B.vy*g;let le=yt(u,B.lane,B.alt);if(le===null){let V=u.query(_t).find(te=>{let Y=u.need(te,_t);return Y.lane===B.lane&&Y.kind==="train"&&Math.abs(u.need(te,K).x-f.playerX)<Y.size/2+b*.22});if(V!==void 0&&bt(u,V),F||Ee())return;B.alt=Math.max(0,B.alt);}else B.alt<=le&&(B.alt=le,B.vy=0);}let J=u.need(a,K),$e=Gt(f,B.lane,B.alt);J.y+=($e.y-J.y)*Math.min(1,g*14),J.x=$e.x;let Se=u.need(a,ie);Se.shape==="actor"&&(Se.alpha=k>0&&Math.floor(u.time*12)%2===0?.35:1,Se.depth=10+B.lane+.5,Se.speed=v,Se.pose=B.alt>2&&B.vy!==0?"air":"run");let Ye=b*.24,pt=ue.has("magnet"),ze=B.alt+b*.5;for(let le of u.query(_t)){if(!u.isAlive(le)||!u.has(le,_t))continue;let V=u.need(le,_t),te=u.need(le,K);if(te.x-=A,V.kind==="mover"){if(te.x-=v*.35*g,V.to===void 0&&te.x-f.playerX<b*6&&te.x-f.playerX>b*3){let S=[V.lane-1,V.lane+1].filter(l=>l>=0&&l<n);V.to=B.lane!==V.lane&&S.includes(B.lane)?B.lane:s.pick(S),V.warn=.45;}if(V.warn!==void 0&&V.warn>0){V.warn-=g;let S=u.need(le,ie);S.alpha=Math.floor(u.time*14)%2===0?.4:1,V.warn<=0&&V.to!==void 0&&(V.lane=V.to,S.alpha=1,S.depth=9+V.lane);}te.y+=(Ne(f,V,b*1.5)-te.y)*Math.min(1,g*10);}if(V.kind==="rock"&&!V.landed&&te.x-f.playerX<b*2.6&&(V.landed=true,u.set(le,ie,{shape:"sprite",art:"rock",w:V.size,h:b*Pt.rock,depth:9+V.lane}),te.y=oo(f,V.lane)-b*Pt.rock/2,G(u,{kind:"burst",x:te.x,y:te.y+b*.4,color:"muted",n:10,size:b*.7}),G(u,{kind:"shake",power:.5})),V.kind==="rock"&&!V.landed){let S=u.need(le,ie);S.shape==="sprite"&&(S.alpha=.35+.3*Math.abs(Math.sin(u.time*6)));}if(V.kind==="power"&&(te.y=Ne(f,V,V.size)+Math.sin(u.time*4+te.x*.01)*b*.06),te.x+V.size/2<-b*2){u.destroy(le);continue}if(V.kind==="finish"){if(te.x<=f.playerX){G(u,{kind:"flash",color:"coin"}),Yt(u,"cleared");return}continue}if(V.kind==="coin"&&pt&&te.x>f.playerX-b*.5&&te.x<f.playerX+b*4&&(V.pulled=true),V.kind==="coin"&&V.pulled){te.x+=(f.playerX-te.x)*Math.min(1,g*10),te.y+=(J.y-te.y)*Math.min(1,g*10),Math.hypot(te.x-f.playerX,te.y-J.y)<b*.4&&D(u,le);continue}let Y=V.kind==="barrier"?V.size*.3:V.size/2;if(Math.abs(te.x-f.playerX)>Ye+Y||V.lane!==B.lane)continue;if(V.kind==="coin"||V.kind==="power"){(Math.abs(V.alt-ze)<b*.6||Q)&&D(u,le);continue}if(Q||V.kind==="ramp"||V.kind==="train"||V.kind==="rock"&&!V.landed)continue;let w=V.kind==="wall"?Pt.wall:V.kind==="barrier"?Pt.barrier*.85:V.kind==="mover"?Pt.mover:V.kind==="rock"?Pt.rock:0;if(V.kind==="pit"?B.alt<2&&Math.abs(te.x-f.playerX)<V.size*.32&&bt(u,le):B.alt<b*w&&bt(u,le),F||Ee())return}vt(u,"runner-jump")||u.query(_t).find(V=>{let te=u.need(V,_t),Y=u.need(V,K).x-f.playerX;return (te.kind==="barrier"||te.kind==="pit")&&te.lane===B.lane&&Y>b*1.5&&Y<b*3.2})!==void 0&&!_r(u)&&kt(u,"tap",{x:f.playerX+b*1.2,y:J.y}),u.vars.score=Me+ro(d+A)*2,Kt(u);}}),tt(),rt();}};var Rn=[{id:"rainbow",shape:"color",art:"m3_rainbow",make:e=>e>=5},{id:"bomb",shape:"area:1",art:"m3_bomb",make:(e,t)=>t},{id:"col",shape:"col",art:"m3_col",make:(e,t,r)=>e===4&&r==="h"},{id:"row",shape:"row",art:"m3_row",make:(e,t,r)=>e===4&&r==="v"}],yd=[{a:"row",b:"row",effect:"cross"},{a:"col",b:"col",effect:"cross"},{a:"row",b:"col",effect:"cross"},{a:"bomb",b:"row",effect:"cross:1"},{a:"bomb",b:"col",effect:"cross:1"},{a:"bomb",b:"bomb",effect:"area:2"},{a:"rainbow",b:"plain",effect:"color"},{a:"rainbow",b:"row",effect:"turn"},{a:"rainbow",b:"col",effect:"turn"},{a:"rainbow",b:"bomb",effect:"turn"},{a:"rainbow",b:"rainbow",effect:"all"}],Zr={ice:{id:"ice",layer:"under",hp:1,art:"m3_ice",max:20},slime:{id:"slime",layer:"under",hp:1,art:"m3_slime",spreads:true,max:16},chain:{id:"chain",layer:"over",hp:1,art:"m3_chain",max:10},stone:{id:"stone",layer:"block",hp:1,art:"m3_stone",hitByNear:true,max:10},cage:{id:"cage",layer:"block",hp:1,art:"m3_cage",hitByNear:true}},Gi={"-":{},".":{hole:true},i:{under:{id:"ice",hp:1}},I:{under:{id:"ice",hp:2}},m:{under:{id:"slime",hp:1}},c:{over:{id:"chain",hp:1}},s:{block:{id:"stone",hp:1}},S:{block:{id:"stone",hp:2}},g:{block:{id:"cage",hp:1}}},rs={fire:{beats:["nature"],color:"piece1"},water:{beats:["fire"],color:"piece2"},nature:{beats:["water"],color:"piece3"},light:{beats:["dark"],color:"piece4"},dark:{beats:["light"],color:"piece5"}},Ki=[{index:0,art:"gem1",color:"piece1",role:"attack",element:"fire"},{index:1,art:"gem2",color:"piece2",role:"attack",element:"water"},{index:2,art:"gem3",color:"piece3",role:"attack",element:"nature"},{index:3,art:"gem4",color:"piece4",role:"attack",element:"light"},{index:4,art:"gem5",color:"piece5",role:"attack",element:"dark"},{index:5,art:"m3_heart",color:"danger",role:"heal"},{index:6,art:"m3_shield",color:"primary",role:"shield"},{index:7,art:"gem6",color:"piece6",role:"attack"}],ns=e=>Ki.find(t=>t.index===e),Fi=[{id:"goblin",cast:"foe5",element:"nature",hp:1,attack:1,every:3,size:.8},{id:"wolf",cast:"foe",element:"nature",hp:.8,attack:.7,every:2,size:.85},{id:"orc",cast:"foe",variant:5,element:"fire",hp:1.4,attack:1.3,every:3,skill:{kind:"sow",obstacle:"stone",count:2},size:.95},{id:"frost-imp",cast:"foe3",element:"water",hp:1,attack:.9,every:3,skill:{kind:"sow",obstacle:"ice",count:3},size:.85},{id:"spider",cast:"foe4",element:"dark",hp:1.1,attack:1,every:3,skill:{kind:"sow",obstacle:"chain",count:3},size:.85},{id:"golem",cast:"foe2",element:"light",hp:2,attack:1.5,every:4,skill:{kind:"sow",obstacle:"stone",count:3},size:1.05},{id:"slime-beast",cast:"foe2",variant:9,element:"water",hp:1.3,attack:1.1,every:3,skill:{kind:"sow",obstacle:"slime",count:2},size:.95},{id:"shaman",cast:"foe4",variant:7,element:"dark",hp:1,attack:.9,every:3,skill:{kind:"heal",share:.15},size:.9},{id:"troll",cast:"boss",element:"nature",hp:3,attack:1.6,every:3,skill:{kind:"sow",obstacle:"stone",count:3},boss:true,enrage:.5,size:1.2},{id:"frost-queen",cast:"boss",variant:4,element:"water",hp:3.5,attack:1.5,every:3,skill:{kind:"sow",obstacle:"ice",count:5},boss:true,enrage:.5,size:1.2},{id:"spider-queen",cast:"boss",variant:9,element:"dark",hp:4,attack:1.7,every:3,skill:{kind:"sow",obstacle:"chain",count:4},boss:true,enrage:.5,size:1.2},{id:"lich",cast:"boss",variant:13,element:"dark",hp:4.5,attack:1.8,every:3,skill:{kind:"sow",obstacle:"slime",count:3},boss:true,enrage:.5,size:1.25}],os=e=>Fi.find(t=>t.id===e),Us=100,gd=4,bd=1.5,xd=2,kd=1,qi=[{id:"blast",art:"m3_skill_blast",mana:30,kind:"shape",shape:"area:1",bigShape:"area:2",bigAt:1.5,damage:6},{id:"cross",art:"m3_skill_cross",mana:28,kind:"shape",shape:"cross",bigShape:"cross:1",bigAt:1.5,damage:5},{id:"storm",art:"m3_skill_storm",mana:34,kind:"storm",count:4,damage:4}],Xs=e=>qi.find(t=>t.id===e),so=[{id:"hero",cast:"hero",gems:0,element:"fire",skill:"blast"},{id:"hero2",cast:"hero2",gems:150,element:"light",skill:"cross"},{id:"hero3",cast:"hero3",gems:300,element:"water",skill:"storm"}],Zs={plain:["--------","--------","--------","--------","--------","--------","--------","--------"],diamond:["..----..",".------.","--------","--------","--------","--------",".------.","..----.."],"ice-mid":["--------","--------","--iiii--","--iiii--","--iiii--","--iiii--","--------","--------"],"ice-low":["--------","--------","--------","--------","iiiiiiii","iiiiiiii","IIIIIIII","IIIIIIII"],stones:["--------","--------","--------","ss-ss-ss","--------","--------","--------","--------"],chains:["--------","-c----c-","--c--c--","---cc---","---cc---","--c--c--","-c----c-","--------"],cages:["--------","-g----g-","--------","---gg---","--------","--------","-g----g-","--------"],slime:["--------","--------","--------","--------","--------","--------","mm----mm","mmm--mmm"],hourglass:["--------","--------",".------.","..----..","..----..",".------.","--------","--------"],ring:["--------","--------","--------","---..---","---..---","--------","--------","--------"],"ice-stone":["--------","-S----S-","--IIII--","--IIII--","--IIII--","--IIII--","-S----S-","--------"],fortress:["s------s","-iiiiii-","-i-cc-i-","-ic--ci-","-ic--ci-","-i-cc-i-","-iiiiii-","s------s"],"slime-cages":["-g----g-","--------","--------","---mm---","---mm---","--------","--------","-g----g-"],"cross-holes":["---..---","--------","--------",".------.",".------.","--------","--------","---..---"]},$t=(e,t,r,o,n)=>({kind:"goal",board:e,moves:t,colors:r,goals:o,...n?{drops:n}:{}}),or=(e,t,...r)=>({kind:"battle",board:e,elements:t,enemies:r}),xr=(e,t)=>({kind:"color",color:e,count:t}),Rt=e=>({kind:"clear",obstacle:e}),es=e=>({kind:"drops",count:e}),Qs=[$t("plain",20,5,[xr(0,12),xr(1,12)]),$t("diamond",20,5,[xr(2,15),xr(3,15)]),or("plain",3,"goblin"),$t("ice-mid",22,5,[Rt("ice")]),$t("ring",20,5,[xr(0,20),xr(4,20)]),or("plain",3,"goblin","wolf"),$t("stones",22,5,[Rt("stone"),xr(1,15)]),$t("ice-low",25,5,[Rt("ice")]),or("diamond",3,"wolf","orc"),or("plain",3,"troll"),$t("chains",24,5,[Rt("chain")]),$t("plain",25,5,[es(3)],3),or("plain",4,"frost-imp","goblin"),$t("cages",22,5,[Rt("cage")]),$t("slime",25,5,[Rt("slime")]),or("ice-mid",4,"orc","frost-imp"),$t("hourglass",24,5,[es(3),xr(2,20)],3),$t("ice-low",26,5,[Rt("ice")]),or("plain",4,"spider","frost-imp","wolf"),or("plain",4,"frost-queen"),$t("ice-stone",26,5,[Rt("ice"),Rt("stone")]),$t("cross-holes",26,6,[xr(0,20),xr(3,20)]),or("chains",4,"spider","golem"),$t("fortress",28,5,[Rt("ice"),Rt("chain")]),$t("slime-cages",26,5,[Rt("cage"),Rt("slime")]),or("plain",4,"slime-beast","golem"),$t("diamond",28,5,[es(3)],3),$t("ice-low",28,5,[Rt("ice"),xr(4,20)]),or("ring",5,"shaman","golem","spider"),or("plain",5,"spider-queen"),$t("fortress",28,6,[Rt("ice"),Rt("chain")]),$t("slime",28,5,[Rt("slime"),es(3)],3),or("ice-stone",5,"golem","shaman"),$t("ice-stone",28,6,[Rt("ice"),Rt("stone")]),$t("slime-cages",28,6,[Rt("cage"),Rt("slime")]),or("plain",5,"slime-beast","shaman","orc"),$t("cross-holes",30,5,[es(3),xr(1,18)],3),$t("fortress",32,5,[Rt("ice"),Rt("chain"),xr(2,15)]),or("diamond",5,"golem","shaman","spider"),or("plain",5,"lich")],ts=10,vd=4,Ys=Qs.length,Ui=[0,18,45,75];function Hh(e){return e.kind==="goal"?[0,1,2,3,4,7].slice(0,Math.max(3,Math.min(6,e.colors))):[...[0,1,2,3,4].slice(0,Math.max(2,Math.min(5,e.elements))),5,6]}function ao(e,t=.5){let r=Math.max(1,Math.min(Ys,Math.floor(e))),o=Qs[r-1],n=Math.ceil(r/ts),s=o.kind==="battle"&&o.enemies.some(a=>os(a)?.boss);return {level:r,world:n,index:r-(n-1)*ts,def:o,boss:s,colors:Hh(o),enemyHp:180*Math.pow(1.07,r-1)*(.8+t*.4),enemyAttack:14*Math.pow(1.06,r-1)*(.8+t*.4),firstClearGold:(s?120:50)+(r-1)*10}}var Xi=e=>Ui[Math.ceil(Math.max(1,e)/ts)-1]??0,Zi=(e,t)=>t?e>=.7?3:e>=.35?2:1:e>=.3?3:e>=.1?2:1,$d=5,Md=.5,Qi="kit-match3",Yi=[{id:"Attack",var:"meta:attack",art:"m3_skill_blast",color:"danger",perLevel:5,unit:"%",maxLevel:20,price:40,growth:.12},{id:"Health",var:"meta:health",art:"m3_heart",color:"danger",perLevel:6,unit:"%",maxLevel:20,price:40,growth:.12},{id:"Defense",var:"meta:defense",art:"m3_shield",color:"primary",perLevel:5,unit:"%",maxLevel:15,price:45,growth:.12},{id:"SkillPower",var:"meta:skill",art:"m3_skill_cross",color:"secondary",perLevel:8,unit:"%",maxLevel:10,price:50,growth:.12},{id:"ManaGain",var:"meta:mana",art:"m3_skill_storm",color:"secondary",perLevel:5,unit:"%",maxLevel:10,price:50,growth:.12},{id:"Moves",var:"meta:moves",art:"m3_bomb",color:"coin",perLevel:1,unit:"",maxLevel:5,price:120,growth:.2}],wd={game:"match3",character:Qi,stats:Yi,heroes:so,levels:Ys,firstClearGold:e=>ao(e).firstClearGold,stars:3,starsToEnter:Xi};var tl=()=>({cleared:[],created:[],fired:[],hits:[],spawned:[],dropsCollected:0,slimeCleared:false}),rl=-1,Qr=-2,ta=(e,t,r)=>t>=0&&r>=0&&t<e.cols&&r<e.rows,mn=(e,t,r)=>ta(e,t,r)?e.cells[r][t]:null,ra=(e,t)=>t[Math.floor(e.rnd()*t.length)%t.length],Ed=[[1,0],[-1,0],[0,1],[0,-1]],Ji=e=>e.hole||e.block!==null||e.over!==null,Wh=e=>e!==null&&e.color>=0;function na(e,t,r,o,n=0){let s={cols:e[0].length,rows:e.length,cells:e.map(a=>[...a].map(i=>{let p=o[i]??{};return {hole:p.hole===true,piece:null,under:p.under?{...p.under}:null,over:p.over?{...p.over}:null,block:p.block?{...p.block}:null}})),colors:t,nextId:1,dropsToSpawn:n,rnd:r};return el(s),s}var ea=(e,t,r=null)=>({id:e.nextId++,color:t,special:r});function el(e){for(let t=0;t<50;t++){for(let r=0;r<e.rows;r++)for(let o=0;o<e.cols;o++){let n=e.cells[r][o];if(n.hole||n.block||n.piece&&n.piece.color<0||n.piece?.special)continue;let s=new Set,a=mn(e,o-1,r)?.piece,i=mn(e,o-2,r)?.piece;a&&i&&a.color>=0&&a.color===i.color&&s.add(a.color);let p=mn(e,o,r-1)?.piece,m=mn(e,o,r-2)?.piece;p&&m&&p.color>=0&&p.color===m.color&&s.add(p.color);let $=e.colors.filter(O=>!s.has(O)),k=ra(e,$.length>0?$:e.colors);n.piece?n.piece.color=k:n.piece=ea(e,k);}if(io(oa(e)).size===0&&lo(e)!==null)return}}function nl(e){for(let t=0;t<e.rows;t++)for(let r=0;r<e.cols;r++){let o=e.cells[t][r].piece;o&&o.color>=0&&!o.special&&!e.cells[t][r].over&&(o.color=-100);}for(let t=0;t<e.rows;t++)for(let r=0;r<e.cols;r++)e.cells[t][r].piece?.color===-100&&(e.cells[t][r].piece.color=ra(e,e.colors));if(el(e),lo(e)===null){for(let t of e.cells)for(let r of t)r.over=null;el(e);}}var oa=e=>e.cells.map(t=>t.map(r=>r.piece&&r.piece.color>=0&&!r.block?r.piece.color:null));function io(e){let t=new Set;for(let r of Sd(e))for(let[o,n]of r.cells)t.add(`${o},${n}`);return t}function Sd(e){let t=[],r=e.length,o=e[0]?.length??0;for(let n=0;n<r;n++)for(let s=0;s<o;){let a=e[n][s],i=1;for(;a!=null&&s+i<o&&e[n][s+i]===a;)i++;a!=null&&i>=3&&t.push({cells:Array.from({length:i},(p,m)=>[s+m,n]),dir:"h"}),s+=i;}for(let n=0;n<o;n++)for(let s=0;s<r;){let a=e[s][n],i=1;for(;a!=null&&s+i<r&&e[s+i][n]===a;)i++;a!=null&&i>=3&&t.push({cells:Array.from({length:i},(p,m)=>[n,s+m]),dir:"v"}),s+=i;}return t}function ol(e){return jh(e)!==null}function jh(e){let t=e.length,r=e[0]?.length??0,o=(n,s)=>{let a=e[n[1]][n[0]];e[n[1]][n[0]]=e[s[1]][s[0]],e[s[1]][s[0]]=a;};for(let n=0;n<t;n++)for(let s=0;s<r;s++)for(let[a,i]of [[1,0],[0,1]]){if(s+a>=r||n+i>=t||e[n][s]===null||e[n+i][s+a]===null)continue;o([s,n],[s+a,n+i]);let p=io(e).size>0;if(o([s,n],[s+a,n+i]),p)return [[s,n],[s+a,n+i]]}return null}function ss(e,t,r){if(Math.abs(t.col-r.col)+Math.abs(t.row-r.row)!==1)return false;let o=mn(e,t.col,t.row),n=mn(e,r.col,r.row);if(!o||!n)return false;for(let s of [o,n])if(s.hole||s.block||s.over||!s.piece)return false;return true}function lo(e){let t=oa(e);for(let r=0;r<e.rows;r++)for(let o=0;o<e.cols;o++)for(let[n,s]of [[1,0],[0,1]]){let a={col:o,row:r},i={col:o+n,row:r+s};if(!ss(e,a,i))continue;let p=e.cells[r][o].piece,m=e.cells[i.row][i.col].piece;if(p.color===Qr&&m.color===Qr)continue;if(p.special==="rainbow"||m.special==="rainbow")return [a,i];if(p.special&&m.special)return [a,i];let $=t[r][o];t[r][o]=t[i.row][i.col],t[i.row][i.col]=$;let k=io(t).size>0;if(t[i.row][i.col]=t[r][o],t[r][o]=$,k)return [a,i]}return null}function sl(e){let t=new Map;for(let r=0;r<e.rows;r++)for(let o=0;o<e.cols;o++){let n=e.cells[r][o].piece;n&&t.set(n.id,{col:o,row:r,piece:n});}return t}function sa(e,t){let r=0;for(let o of e.cells)for(let n of o)for(let s of [n.under,n.over,n.block])s?.id===t&&r++;return r}function al(e,t,r){if(!ss(e,t,r))return null;let o=e.cells[t.row][t.col],n=e.cells[r.row][r.col],s=o.piece,a=n.piece;if(s.special==="rainbow"||a.special==="rainbow"||s.special&&a.special){o.piece=a,n.piece=s;let p=tl();return Fh(e,p,r,s,t,a),fl(e,p),p}o.piece=a,n.piece=s;let i=Ld(e,[t,r]);return i||(o.piece=s,n.piece=a,null)}function aa(e){return Ld(e,[])}function ia(e,t,r="skill"){let o=tl(),n=t.filter(s=>ta(e,s.col,s.row)).map(s=>({...s,match:false}));return t[0]&&o.fired.push({...t[0],kind:r}),cl(e,o,n),fl(e,o),o}function il(e,t){let r=[];if(t)return r;let o=Object.values(Zr).filter(n=>n.spreads);for(let n of o){let s=[];for(let p=0;p<e.rows;p++)for(let m=0;m<e.cols;m++)e.cells[p][m].under?.id===n.id&&s.push({col:m,row:p});if(s.length===0)continue;let a=[];for(let p of s)for(let[m,$]of Ed){let k=mn(e,p.col+m,p.row+$);k&&!k.hole&&!k.block&&!k.under&&a.push({col:p.col+m,row:p.row+$});}if(a.length===0)continue;let i=ra(e,a);e.cells[i.row][i.col].under={id:n.id,hp:1},r.push(i);}return r}function ll(e,t,r){let o=Zr[t];if(!o)return [];let n=[];for(let i=0;i<e.rows;i++)for(let p=0;p<e.cols;p++){let m=e.cells[i][p];m.hole||m.block||!m.piece||m.piece.color<0||m.piece.special||o.layer==="under"&&m.under||o.layer==="over"&&m.over||n.push({col:p,row:i});}let s=[],a=o.max===void 0?r:Math.max(0,o.max-sa(e,t));for(let i=0;i<Math.min(r,a)&&n.length>0;i++){let p=Math.floor(e.rnd()*n.length)%n.length,m=n.splice(p,1)[0],$=e.cells[m.row][m.col],k={id:t,hp:o.hp};o.layer==="under"?$.under=k:o.layer==="over"?$.over=k:($.block=k,$.piece=null),s.push(m);}return s}function la(e,t,r){let o=[];for(let s=0;s<e.rows;s++)for(let a=0;a<e.cols;a++){let i=e.cells[s][a].piece;i&&i.color>=0&&!i.special&&!e.cells[s][a].over&&o.push({col:a,row:s});}let n=[];for(let s=0;s<r&&o.length>0;s++){let a=o.splice(Math.floor(e.rnd()*o.length)%o.length,1)[0];e.cells[a.row][a.col].piece.special=e.rnd()<.5?"row":"col",n.push(a);}return n}function Ld(e,t){let r=Sd(oa(e));if(r.length===0)return null;let o=tl(),n=[];for(let i of r){let p=new Set(i.cells.map(([k,O])=>`${k},${O}`)),m=n.filter(k=>k.some(O=>O.cells.some(([C,z])=>p.has(`${C},${z}`)))),$=[i,...m.flat()];for(let k of m)n.splice(n.indexOf(k),1);n.push($);}let s=[],a=[];for(let i of n){let p=new Map;for(let O of i)for(let[C,z]of O.cells)p.set(`${C},${z}`,{col:C,row:z});let m=i.reduce((O,C)=>Math.max(O,C.cells.length),0),$=i.some(O=>O.dir==="h")&&i.some(O=>O.dir==="v"),k=Rn.filter(O=>O.make!==null).find(O=>O.make(m,$,i.find(C=>C.cells.length===m).dir));if(k){let O=t.find(z=>p.has(`${z.col},${z.row}`))??($?Vh(i):null)??Gh(i.find(z=>z.cells.length===m)),C=e.cells[O.row][O.col].piece?.color??0;a.push({at:O,special:k.id,color:C});}for(let O of p.values())s.push({...O,match:true});}cl(e,o,s);for(let i of a){let p=e.cells[i.at.row][i.at.col];p.piece||p.block||p.hole||(p.piece=ea(e,i.special==="rainbow"?rl:i.color,i.special),o.created.push({...i.at,piece:p.piece}));}return fl(e,o),o}function Vh(e){let t=new Set;for(let r of e)for(let[o,n]of r.cells){let s=`${o},${n}`;if(t.has(s))return {col:o,row:n};t.add(s);}return null}var Gh=e=>{let[t,r]=e.cells[Math.floor(e.cells.length/2)];return {col:t,row:r}};function cl(e,t,r){let o=new Set,n=new Set;for(;r.length>0;){let s=r.shift(),a=`${s.col},${s.row}`;if(!ta(e,s.col,s.row))continue;let i=e.cells[s.row][s.col];if(i.hole)continue;if(i.block){!s.match&&!n.has(a)&&(n.add(a),Js(t,i,"block",s));continue}if(o.has(a))continue;o.add(a);let p=i.piece;if(p){if(i.over){Js(t,i,"over",s);continue}if(p.color!==Qr){if(i.piece=null,t.cleared.push({...s,piece:p}),i.under&&(i.under.id==="slime"&&(t.slimeCleared=true),Js(t,i,"under",s)),s.match)for(let[m,$]of Ed){let k=mn(e,s.col+m,s.row+$),O=`${s.col+m},${s.row+$}`;k?.block&&!n.has(O)&&Zr[k.block.id]?.hitByNear&&(n.add(O),Js(t,k,"block",{col:s.col+m,row:s.row+$}));}p.special&&Kh(e,t,p.special,s,p.color,r);}}}}function Js(e,t,r,o){let n=t[r];n.hp-=1,e.hits.push({...o,id:n.id,hp:Math.max(0,n.hp)}),n.hp<=0&&(t[r]=null);}function Kh(e,t,r,o,n,s){t.fired.push({...o,kind:r});let i=Rn.find(p=>p.id===r)?.shape??r;for(let p of dl(e,i,o,n))s.push({...p,match:false});}var ca=(e,t,r)=>dl(e,t,r,-1);function dl(e,t,r,o){let n=[],s=i=>{for(let p=0;p<e.cols;p++)n.push({col:p,row:i});},a=i=>{for(let p=0;p<e.rows;p++)n.push({col:i,row:p});};if(t==="row")s(r.row);else if(t==="col")a(r.col);else if(t==="cross")s(r.row),a(r.col);else if(t.startsWith("cross:")){let i=Number(t.slice(6));for(let p=-i;p<=i;p++)s(r.row+p),a(r.col+p);}else if(t.startsWith("area:")){let i=Number(t.slice(5));for(let p=-i;p<=i;p++)for(let m=-i;m<=i;m++)n.push({col:r.col+m,row:r.row+p});}else if(t==="color"){let i=o>=0?o:_d(e);for(let p=0;p<e.rows;p++)for(let m=0;m<e.cols;m++)e.cells[p][m].piece?.color===i&&n.push({col:m,row:p});}else if(t==="all")for(let i=0;i<e.rows;i++)s(i);return n.filter(i=>ta(e,i.col,i.row))}function _d(e){let t=new Map;for(let n of e.cells)for(let s of n)Wh(s.piece)&&!s.block&&t.set(s.piece.color,(t.get(s.piece.color)??0)+1);let r=e.colors[0]??0,o=-1;for(let[n,s]of t)s>o&&(o=s,r=n);return r}function Fh(e,t,r,o,n,s){let a=[],i=o.special??"plain",p=s.special??"plain",m=yd.find(k=>k.a===i&&k.b===p||k.a===p&&k.b===i);e.cells[r.row][r.col].piece=null,e.cells[n.row][n.col].piece=null,t.cleared.push({...r,piece:o},{...n,piece:s}),t.fired.push({...n,kind:m?.effect??"combo"});let $=i==="rainbow"?s:o;if(m?.effect==="color"||m?.effect==="turn"){let k=$.color>=0?$.color:_d(e);for(let O=0;O<e.rows;O++)for(let C=0;C<e.cols;C++){let z=e.cells[O][C].piece;z?.color===k&&(m.effect==="turn"&&$.special&&$.special!=="rainbow"&&(z.special=$.special==="row"||$.special==="col"?e.rnd()<.5?"row":"col":$.special),a.push({col:C,row:O,match:false}));}}else for(let k of dl(e,m?.effect??"cross",n,$.color))a.push({...k,match:false});cl(e,t,a);}function fl(e,t){for(let r=0;r<4;r++){for(let n=0;n<e.cols;n++){let s=e.rows-1;for(;s>=0;){if(Ji(e.cells[s][n])){s--;continue}let a=s;for(;a-1>=0&&!Ji(e.cells[a-1][n]);)a--;let i=[];for(let $=s;$>=a;$--){let k=e.cells[$][n].piece;k&&i.push(k);}let p=s;for(let $ of i)e.cells[p--][n].piece=$;let m=-1;for(;p>=a;p--){let $=a===qh(e,n)&&e.dropsToSpawn>0&&Xh(e)<2&&e.rnd()<.35,k=$?ea(e,Qr):ea(e,ra(e,e.colors));$&&e.dropsToSpawn--,e.cells[p][n].piece=k,t.spawned.push({col:n,row:p,piece:k,from:a+m--});}s=a-1;}}let o=false;for(let n=0;n<e.cols;n++){let s=Uh(e,n);if(s<0)continue;let a=e.cells[s][n];a.piece?.color===Qr&&(a.piece=null,t.dropsCollected++,o=true);}if(!o)break}}var qh=(e,t)=>{for(let r=0;r<e.rows;r++)if(!Ji(e.cells[r][t]))return r;return -1},Uh=(e,t)=>{for(let r=e.rows-1;r>=0;r--)if(!e.cells[r][t].hole)return e.cells[r][t].block?-1:r;return -1},Xh=e=>{let t=0;for(let r of e.cells)for(let o of r)o.piece?.color===Qr&&t++;return t};var Zh="boss-spawned",Qh="boss-defeated",yn=ve("match3.gem"),Rd=ve("match3.overlay"),pl=ve("match3.layer"),Ad=ve("match3.backdrop"),Td=ve("match3.part"),Yr=(e,t)=>{let r=Number(e.vars[t]??0);return Number.isFinite(r)?r:0},da={id:"match3",version:2,engines:["phaser"],requires:["round"],params:{difficulty:{type:"number",default:.5,min:0,max:1},pieceScore:{type:"number",default:10,min:1,max:1e3,integer:true},coinEvery:{type:"number",default:8,min:1,max:100,integer:true},moveBonus:{type:"number",default:100,min:0,max:1e4,integer:true}},setup({world:e,params:t}){let r=w=>yr(t,w),o=e.rng.stream("match3"),n=ao(1,r("difficulty")),s=na(Zs.plain,[0,1,2,3,4],()=>o.next(),Gi),a=Gt(),i="idle",p=new Map,m=new Map,$=null,k=null,O=null,C=null,z=0,F=false,ne=0,X=0,ye=0,be=0,fe=0,we=false,de=false,Re={colors:new Map,drops:0},Ce=Us,Me=Us,ce=0,ue=0,Pe=false,Le=[],oe=null,Ee=0,tt=0,Ne=0,se=null,ke=[],_e=new Map,Te=()=>so.find(w=>w.id===e.vars["meta:hero"])??so[0],Be=()=>Xs(Te().skill),ee=()=>n.def.kind==="battle",Ie=()=>e.vars.reviving===true,nt=()=>gd*Math.pow(1.06,n.level-1)*(1+Yr(e,"meta:attack")),ht=()=>1+Yr(e,"meta:skill"),Ae=()=>Be().mana;function Gt(){return un(He(e),s.cols,s.rows,{top:.33,bottom:.96,widthShare:.94})}let Xe=()=>a.cell,rt=new Set,lt=(w,S,l,E,T=1)=>{rt.add(w);let c=_e.get(w);(c===void 0||!e.isAlive(c))&&(c=e.create(),e.set(c,Td,{id:w}),_e.set(w,c)),e.set(c,K,{x:S,y:l,scale:T}),e.set(c,ie,E);},ft=w=>{for(let[S,l]of [..._e])S.startsWith(w)&&(e.destroy(l),_e.delete(S));},yt=w=>{let S=Xe();if(w===rl)return {shape:"sprite",art:"m3_rainbow",w:S*.9,h:S*.9,depth:3};if(w===Qr)return {shape:"sprite",art:"m3_crate",w:S*.86,h:S*.86,depth:3};let l=ns(w);return {shape:"sprite",art:l?.art??"gem1",w:S*.88,h:S*.88,color:l?.color??"piece1",depth:3}},ut=(w,S,l,E,T)=>{let c=at(a,S,T),y=e.create();return e.set(y,yn,{id:w,col:S,row:l,kind:E}),e.set(y,K,{x:c.x,y:c.y}),e.set(y,ie,yt(E)),p.set(w,y),y},Et=()=>{let w=sl(s);for(let[S,l]of [...p])w.has(S)||(e.destroy(l),p.delete(S));for(let[S,l]of w){let E=p.get(S);E===void 0&&(E=ut(S,l.col,l.row,l.piece.color,l.row-s.rows));let T=e.need(E,yn);T.col=l.col,T.row=l.row,T.kind!==l.piece.color&&(T.kind=l.piece.color,e.set(E,ie,yt(l.piece.color)));let c=l.piece.special&&l.piece.special!=="rainbow"?Rn.find(R=>R.id===l.piece.special):void 0,y=m.get(S);c&&y===void 0&&(y=e.create(),e.set(y,Rd,{of:S}),e.set(y,K,{x:0,y:0}),m.set(S,y)),c&&y!==void 0&&e.set(y,ie,{shape:"sprite",art:c.art,w:Xe()*.95,h:Xe()*.95,depth:4}),!c&&y!==void 0&&(e.destroy(y),m.delete(S));}for(let[S,l]of [...m])w.has(S)||(e.destroy(l),m.delete(S));Ze();},Ze=()=>{dt(e,pl);let w=Xe();for(let S=0;S<s.rows;S++)for(let l=0;l<s.cols;l++){let E=s.cells[S][l],T=at(a,l,S),c=(y,R,L,M=1)=>{if(!R)return;let x=Zr[R.id],_=e.create();e.set(_,pl,{key:y}),e.set(_,K,{x:T.x,y:T.y}),e.set(_,ie,{shape:"sprite",art:R.hp>=2&&x?.id==="ice"?"m3_ice2":R.hp>=2&&x?.id==="stone"?"m3_stone2":x?.art??"m3_stone",w:w*M,h:w*M,depth:L});};c(`u${l},${S}`,E.under,1.5,.98),c(`o${l},${S}`,E.over,5,.98),c(`b${l},${S}`,E.block,3,.95);}},Ge=()=>{dt(e,Ad),zt(e,"board",a.top+a.cell*s.rows*.35);let w=Xe(),S=at(a,(s.cols-1)/2,(s.rows-1)/2),l=w*.25,E=(T,c,y)=>{let R=e.create();e.set(R,Ad,{i:0}),e.set(R,K,{x:T,y:c}),e.set(R,ie,y);};E(S.x,S.y,{shape:"sprite",art:"panel",w:w*s.cols+l*2,h:w*s.rows+l*2,color:"panel",alpha:.9,depth:-10});for(let T=0;T<s.rows;T++)for(let c=0;c<s.cols;c++){if(s.cells[T][c].hole)continue;let y=at(a,c,T);E(y.x,y.y,{shape:"sprite",art:"cell",w:w-2,h:w-2,color:(T+c)%2?"panel":"ground",alpha:.85,depth:-9});}},It=()=>{let w=He(e),S=w.h*.12,l=a.top-Xe()*.4,E=Math.max(40,(l-S)*.92);if((se===null||!e.isAlive(se))&&(se=e.create()),e.set(se,K,{x:w.w*.15,y:l-E/2}),e.set(se,ie,{shape:"actor",cast:Te().cast,h:E,pose:"idle",facing:1,depth:20}),oe&&e.isAlive(oe.entity)){let T=E*oe.def.size;e.set(oe.entity,K,{x:w.w*.82,y:l-T/2});let c=e.need(oe.entity,ie);c.shape==="actor"&&(c.h=T);}},Qe=()=>n.def.kind!=="goal"?[]:n.def.goals.map(w=>({goal:w,left:w.kind==="color"?Math.max(0,w.count-(Re.colors.get(w.color)??0)):w.kind==="clear"?sa(s,w.obstacle):w.kind==="drops"?Math.max(0,w.count-Re.drops):Math.max(0,w.value-Number(e.vars.score??0))})),Kt=()=>Qe().every(w=>w.left===0),Yt=w=>{let S=He(e).w*.07;if(w.kind==="color"){let l=ns(w.color);return {shape:"sprite",art:l?.art??"gem1",w:S,h:S,color:l?.color??"piece1",depth:70}}return w.kind==="clear"?{shape:"sprite",art:Zr[w.obstacle]?.art??"m3_stone",w:S,h:S,depth:70}:w.kind==="drops"?{shape:"sprite",art:"m3_crate",w:S,h:S,depth:70}:{shape:"sprite",art:"coin",w:S,h:S,depth:70}},Ft=(w,S,l,E,T,c)=>{let y=Math.max(8,E*.09);lt(`${w}:bg`,S,l,{shape:"rect",w:E,h:y,color:"#000000",alpha:.5,radius:y/2,depth:69});let R=Math.max(1,(E-4)*Math.max(0,Math.min(1,T)));lt(`${w}:fill`,S-(E-4)/2+R/2,l,{shape:"rect",w:R,h:y-4,color:c,radius:(y-4)/2,depth:69.1});},ur=()=>{let w=He(e),S=Math.min(w.w,w.h),l=(M,x,_,I,P="text",H=S*.045)=>lt(M,x,_,{shape:"text",text:I,size:Math.round(H),color:P,bold:true,depth:70}),E=a.top-Xe()*.4,T=w.h*.085;ke=[],rt.clear();let c=w.w*.36,y=(T+E)/2+S*.02,R=S*.07,L=ue>=Ae();if(ke.push({id:"skill",x:c,y,r:R*1.15}),L&<("h:skill:glow",c,y,{shape:"circle",r:R*1.25,color:Pe?"coin":"secondary",alpha:.5+.3*Math.sin(e.time*7),depth:68.9}),lt("h:skill:bg",c,y,{shape:"circle",r:R,color:"panel",alpha:.95,depth:69}),lt("h:skill:i",c,y,{shape:"sprite",art:Be().art,w:R*1.4,h:R*1.4,alpha:L?1:.45,depth:69.2}),Ft("h:mana",c,y+R*1.45,R*2.2,ue/Ae(),"secondary"),ee()){let M=w.w*.15;if(Ft("h:hp",M,T,w.w*.24,Ce/Me,"accent"),l("h:hp:t",M+w.w*.12+S*.05,T,`${Math.ceil(Ce)}`,"text",S*.034),ce>0&&(lt("h:sh:i",M+w.w*.12+S*.05,T+S*.055,{shape:"sprite",art:"m3_shield",w:S*.045,h:S*.045,color:"primary",depth:70}),l("h:sh:t",M+w.w*.12+S*.11,T+S*.055,`${Math.ceil(ce)}`,"primary",S*.03)),oe){let x=w.w*.78;Ft("h:foe",x,T,w.w*.26,oe.hp/oe.max,"danger"),l("h:foe:t",x-w.w*.13-S*.05,T,`${Math.ceil(oe.hp)}`,"text",S*.034);let _=rs[oe.def.element];lt("h:foe:el",x+w.w*.13+S*.03,T,{shape:"circle",r:S*.018,color:_.color,depth:70});let I=(T+E)/2;lt("h:foe:in:bg",w.w*.62,I,{shape:"circle",r:S*.045,color:oe.in<=1?"danger":"panel",alpha:.95,depth:69}),l("h:foe:in",w.w*.62,I,String(oe.in),"text",S*.045);let P=n.def.kind==="battle"?n.def.enemies.length:0;for(let H=0;H<P;H++)lt(`h:q:${H}`,w.w*.8+(H-(P-1)/2)*S*.04,E+S*.005,{shape:"circle",r:S*.012,color:H<Ee?"muted":H===Ee?"danger":"text",alpha:.9,depth:70});}}else {l("h:moves",w.w*.5,T+S*.01,String(X),X<=3?"danger":"text",S*.075);let M=Qe(),x=w.w*.64,_=w.w*.11,I=(T+E)/2+S*.02;M.forEach((P,H)=>{let re=x+H*_;lt(`h:g:${H}`,re,I,Yt(P.goal)),l(`h:g:${H}:t`,re,I+S*.06,P.left===0?"\u2713":String(P.left),P.left===0?"accent":"text",S*.038);});}e.vars.m3_phase=i,e.vars.m3_buttons=ke.map(M=>`${M.id}@${Math.round(M.x)},${Math.round(M.y)}`).join(";");for(let[M,x]of [..._e])!M.startsWith("h:")||rt.has(M)||(e.destroy(x),_e.delete(M));},bt=()=>{oe&&e.isAlive(oe.entity)&&it(e,oe.entity,"die");let w=Le.shift();if(w===void 0){oe=null;return}let S=os(w),l=e.create();e.set(l,K,{x:0,y:0}),e.set(l,ie,{shape:"actor",cast:S.cast,variant:S.variant??o.int(0,99),h:50,pose:"idle",facing:-1,depth:20});let E=S.hp*n.enemyHp;oe={def:S,hp:E,max:E,in:S.every,rage:1,entity:l},It(),S.boss&&(e.emit(Zh,{kind:w}),G(e,{kind:"shake",power:1})),D();},D=()=>{if(e.vars.moves=X,e.vars.hero_hp=Math.ceil(Ce),e.vars.mana=Math.floor(ue),e.vars.m3_goals=Qe().map(w=>`${w.goal.kind==="color"?`color${w.goal.color}`:w.goal.kind==="clear"?w.goal.obstacle:w.goal.kind}:${w.left}`).join(","),e.vars.m3_enemy=oe?`${oe.def.id}:${Math.ceil(oe.hp)}/${Math.ceil(oe.max)}:${oe.in}`:"",ee()){let w=n.def.kind==="battle"?n.def.enemies.length:1;e.vars.level_progress=Math.min(1,(Ee+(oe?1-oe.hp/oe.max:0))/w);}else {let w=n.def;if(w.kind==="goal"){let S=w.goals.map(E=>E.kind==="color"||E.kind==="drops"?E.count:E.kind==="score"?E.value:1),l=Qe();e.vars.level_progress=l.reduce((E,T,c)=>E+(T.goal.kind==="clear"?T.left===0?1:0:1-T.left/S[c]),0)/Math.max(1,l.length);}}},u=()=>{dt(e,yn),dt(e,Rd),dt(e,pl),dt(e,Td),p.clear(),m.clear(),_e.clear(),oe&&e.isAlive(oe.entity)&&e.destroy(oe.entity),oe=null,n=ao(Yr(e,"meta:chapter")||1,r("difficulty"));let w=n.def;s=na(Zs[w.board]??Zs.plain,n.colors,()=>o.next(),Gi,w.kind==="goal"?w.drops??0:0),a=Gt(),Ge(),i="idle",$=null,k=null,O=null,C=null,z=0,F=false,ne=0,Re.colors.clear(),Re.drops=0,X=w.kind==="goal"?w.moves+Yr(e,"meta:moves"):0,ye=X,be=0,fe=0,we=false,de=false,Me=Us*Math.pow(1.06,n.level-1)*(1+Yr(e,"meta:health")),Ce=Me,ce=0,ue=0,Pe=false,Ee=0,tt=0,Ne=0,Le=w.kind==="battle"?[...w.enemies]:[],e.vars.m3_level=n.level,e.vars.m3_world=n.world,e.vars.m3_kind=w.kind,e.vars.coins=0,e.vars.score=0,e.vars.stars=0,e.vars.reviving=false,Et(),It(),w.kind==="battle"&&bt(),D();},g=w=>{if(!w||!oe)return 1;let S=rs[w].beats.includes(oe.def.element),l=w===oe.def.element;return (S?1.5:l?.5:1)*(w===Te().element?1.25:1)},f=(w,S=0)=>{z++,F||=w.slimeCleared,Re.drops+=w.dropsCollected;let l=S,E=0,T=0,c=Xe();for(let M of w.cleared){let x=M.piece;x.color>=0&&Re.colors.set(x.color,(Re.colors.get(x.color)??0)+1);let _=ns(x.color),I=at(a,M.col,M.row);G(e,{kind:"burst",x:I.x,y:I.y,color:_?.color??"coin",n:6,size:c*.8}),ue=Math.min(Ae(),ue+kd*(1+Yr(e,"meta:mana"))),!(!ee()||!_)&&(_.role==="attack"?l+=nt()*g(_.element)*(1+.25*(z-1)):_.role==="heal"?E+=bd*Math.pow(1.06,n.level-1)*(1+Yr(e,"meta:health")):_.role==="shield"&&(T+=xd*Math.pow(1.06,n.level-1)*(1+Yr(e,"meta:defense"))));}for(let M of w.fired){let x=at(a,M.col,M.row);G(e,{kind:"ring",x:x.x,y:x.y,color:"coin",size:c*2.4});}w.fired.length>0&&G(e,{kind:"shake",power:.4+Math.min(1,w.fired.length*.2)});for(let M of w.created)e.emit("special-made",{kind:M.piece.special});let y=w.cleared.length*r("pieceScore")*z+w.fired.length*30;Je(e,"score",y),ne+=w.cleared.length;let L=Math.floor(ne/r("coinEvery"))-Math.floor((ne-w.cleared.length)/r("coinEvery"));L>0&&(Je(e,"coins",L),e.emit("coin-collected",{value:L})),e.emit("pieces-cleared",{count:w.cleared.length,cascade:z}),ee()&&(E>0&&(Ce=Math.min(Me,Ce+E),se!==null&&G(e,{kind:"pop",x:e.need(se,K).x,y:e.need(se,K).y-c,text:`+${Math.round(E)}`,color:"accent",size:Math.round(c*.45)})),T>0&&(ce+=T),l>0&&oe&&b(l)),Et(),D();},b=w=>{if(!oe)return;oe.hp-=w,se!==null&&Fe(e,se,"attack"),Fe(e,oe.entity,"hit");let S=e.need(oe.entity,K);G(e,{kind:"pop",x:S.x,y:S.y-Xe(),text:`-${Math.round(w)}`,color:"danger",size:Math.round(Xe()*.5)}),!(oe.hp>0)&&(Ee++,e.emit("enemy-defeated",{kind:oe.def.id}),d(),oe.def.boss&&(tt++,Je(e,"coins",10),e.emit(Qh,{kind:oe.def.id}),G(e,{kind:"flash",color:"coin"})),bt());},d=()=>{if(!oe)return;it(e,oe.entity,"die");let w=oe.entity;e.need(w,ie).alpha=.6,v(()=>{e.isAlive(w)&&e.destroy(w);});},h=[],v=w=>h.push({t:.9,f:w}),A=()=>{if(il(s,F),F=false,z=0,Et(),n.def.kind==="goal"){if(Kt())return Q();if(X<=0)return $e("out-of-moves")}else {if(!oe)return Q();if(oe.in--,oe.in<=0){i="enemy",fe=.45;return}}N();},N=()=>{i="idle",lo(s)===null&&(nl(s),Et(),e.emit("board-shuffled",{})),D();},B=()=>{if(!oe)return N();let w=oe.def,S=n.enemyAttack*w.attack*oe.rage;oe.rage=1,Fe(e,oe.entity,"attack");let l=Math.min(ce,S);if(ce-=l,S=(S-l)*(1-Math.min(.6,Yr(e,"meta:defense"))),S>0){if(Ce-=S,se!==null){Fe(e,se,"hit");let T=e.need(se,K);G(e,{kind:"pop",x:T.x,y:T.y-Xe(),text:`-${Math.round(S)}`,color:"danger",size:Math.round(Xe()*.5)});}G(e,{kind:"shake",power:.8}),e.emit("player-hit",{hp:Math.ceil(Ce)});}let E=w.skill;if(E?.kind==="sow"?ll(s,E.obstacle,E.count):E?.kind==="heal"?oe.hp=Math.min(oe.max,oe.hp+oe.max*E.share):E?.kind==="rage"&&(oe.rage=E.mult),oe.in=w.enrage&&oe.hp<oe.max*w.enrage?Math.max(1,w.every-1):w.every,Et(),Ce<=0)return Ce=0,$e("fell");N();},Q=()=>{if(n.def.kind==="goal"){Ne=Math.min(X,12),e.vars.stars=Math.min(we?1:3,Zi(X/Math.max(1,ye),false)),Je(e,"score",X*r("moveBonus")),i="finale",fe=.3;return}e.vars.stars=Math.min(we?1:3,Zi(Ce/Me,true)),J("cleared");},J=w=>{if(de)return;de=true,i="over";let S=w==="cleared";S&&e.vars["meta:first_clear"]===true&&Je(e,"coins",n.firstClearGold),S||(e.vars.stars=0),e.vars.reviving=false,D(),e.emit(Xt,{reason:w,stats:{chapter:n.level,seconds:Math.floor(be),cleared:S,stars:Number(e.vars.stars??0),coins:Number(e.vars.coins??0),bosses:tt,kills:Ee,battle:ee()}});},$e=w=>{if(e.vars.revive_ready===true&&!we){e.vars.reviving=true,e.vars.m3_revive_reason=w,i="idle",e.emit(tr,{});return}J(w);},Se=()=>{Ie()&&(we=true,e.vars.reviving=false,ee()?(Ce=Me*Md,oe&&(oe.in=oe.def.every)):X+=$d,G(e,{kind:"flash",color:"coin"}),N());},Ye=w=>{let S=s.cells[w.row]?.[w.col];if(!S||S.hole)return 0;let l=n.def.kind==="goal"?n.def.goals:[],E=0;for(let c of [S.under,S.over,S.block])c&&(E+=l.some(y=>y.kind==="clear"&&y.obstacle===c.id)?6:3);let T=S.piece;if(T&&!S.block){E+=1,T.special&&(E+=3),l.some(y=>y.kind==="color"&&y.color===T.color)&&(E+=2);let c=ns(T.color);ee()&&c?.role==="attack"&&(E+=g(c.element));}if(l.some(c=>c.kind==="drops"))for(let c=0;c<w.row;c++)s.cells[c][w.col].piece?.color===Qr&&(E+=2);return E},pt=w=>{let S={col:Math.floor(s.cols/2),row:Math.floor(s.rows/2)},l=-1;for(let E=0;E<s.rows;E++)for(let T=0;T<s.cols;T++){if(s.cells[E][T].hole)continue;let c=ca(s,w,{col:T,row:E}).reduce((y,R)=>y+Ye(R),0);c>l&&(l=c,S={col:T,row:E});}return S},ze=()=>{let w=Be();if(ue<w.mana||i!=="idle")return false;let S=ht(),l=[];if(w.kind==="shape"){let c=S>=(w.bigAt??99)&&w.bigShape?w.bigShape:w.shape??"area:1",y=pt(c);l=ca(s,c,y);let R=at(a,y.col,y.row);G(e,{kind:"ring",x:R.x,y:R.y,color:"coin",size:Xe()*4}),G(e,{kind:"flash",color:"coin"});}else l=la(s,"line",Math.round((w.count??3)*S));ue=0,Pe=false,z=0,se!==null&&Fe(e,se,"attack"),e.emit("skill-cast",{id:w.id}),Lt(e,"m3-skill");let E=ee()&&oe?w.damage*nt()*S*g(Te().element):0,T=ia(s,l,w.id);return f(T,E),i="falling",true},le=w=>{if(O){let S=s.cells[O.row]?.[O.col]?.piece?.id,l=S!==void 0?p.get(S):void 0;l!==void 0&&(e.need(l,K).scale=1);}if(O=w,w){let S=s.cells[w.row]?.[w.col]?.piece?.id,l=S!==void 0?p.get(S):void 0;l!==void 0&&(e.need(l,K).scale=1.15);}},V=0,te=(w,S)=>{if(V=0,Bt(e),i!=="idle"||Ie()||!ss(s,w,S))return;le(null);let l=s.cells[w.row][w.col].piece.id,E=s.cells[S.row][S.col].piece.id;$=new Map([[l,S],[E,w]]),k=[w,S],i="swapping",Lt(e,"match3-swap");};e.on(Nt,w=>{let S=w;if(!(!st(e)||hn(e)||de||Ie()))if(S.type==="tap"){if(ke.find(T=>Math.hypot(S.x-T.x,S.y-T.y)<=T.r)?.id==="skill"){if(ue<Ae())return;ze()||(Pe=true);return}let E=Ur(a,S.x,S.y);if(!E||i!=="idle")return;O&&Math.abs(O.col-E.col)+Math.abs(O.row-E.row)===1?te(O,E):le(O&&O.col===E.col&&O.row===E.row?null:E);}else if(S.type==="press"){let l=Ur(a,S.x,S.y);C=l?{x:S.x,y:S.y,...l}:null;}else if(S.type==="move"&&C){let l=S.x-C.x,E=S.y-C.y;if(Math.max(Math.abs(l),Math.abs(E))<a.cell*.45)return;let T={col:C.col,row:C.row},c=Math.abs(l)>Math.abs(E)?{col:T.col+Math.sign(l),row:T.row}:{col:T.col,row:T.row+Math.sign(E)};C=null,te(T,c);}else S.type==="release"&&(C=null);}),e.on(Ut,()=>{u(),e.vars.level=n.level;}),e.on(Qt,u),e.on(rr,Se),e.on(nr,()=>{Ie()&&(e.vars.reviving=false,J(ee()?"fell":"out-of-moves"));}),e.on(Zt,w=>{ft("h:"),ke=[],se!==null&&e.isAlive(se)&&it(e,se,w.reason==="cleared"?"dance":"die");}),e.on(qt,()=>{a=Gt(),Ge();for(let[w,S]of p){let l=e.need(S,yn);e.set(S,ie,yt(l.kind));}Et(),It();});let Y=w=>{let S=true,l=Math.min(1,w*14),E=Xe();for(let T of e.query(yn)){let c=e.need(T,yn),y=$?.get(c.id)??c,R=e.need(T,K),L=at(a,y.col,y.row),M=L.x-R.x,x=L.y-R.y,_=e.need(T,ie);Math.abs(M)<.5&&Math.abs(x)<.5?(R.x=L.x,R.y=L.y,_.alpha=1):(S=false,_.alpha=R.y<a.top-E*.3?0:1,R.x+=M*l,R.y+=Math.abs(x)>E*.3?Math.sign(x)*Math.min(Math.abs(x),E*12*w):x*l);}for(let[T,c]of m){let y=p.get(T);if(y===void 0)continue;let R=e.need(y,K);e.set(c,K,{x:R.x,y:R.y,scale:1+.06*Math.sin(e.time*6)}),e.need(c,ie).alpha=e.need(y,ie).alpha??1;}return S};e.addSystem({id:"match3",order:0,run(w,S){for(let l of [...h])l.t-=S,l.t<=0&&(h.splice(h.indexOf(l),1),l.f());if(!st(w)||de){Y(S);return}if(be+=S,ur(),!Ie()&&Y(S)){if(fe>0){fe-=S;return}if(i==="swapping"&&k){let[l,E]=k;k=null,$=null,z=0;let T=al(s,l,E);if(!T){let c=s.cells[l.row][l.col].piece.id,y=s.cells[E.row][E.col].piece.id;$=new Map([[c,E],[y,l]]),i="returning";return}n.def.kind==="goal"&&X--,f(T),i="falling";return}if(i==="returning"){if($){$=null;return}i="idle";return}if(i==="falling"){let l=aa(s);if(l){f(l);return}A();return}if(i==="enemy"){B();return}if(i==="finale"){if(Ne>0){Ne--,X=Math.max(0,X-1);let E=la(s,"line",1);E.length>0&&f(ia(s,E,"finale")),Et(),fe=.12;return}let l=aa(s);if(l){f(l);return}J("cleared");return}if(i==="idle"&&Pe){ze();return}if(i==="idle"){if(V+=S,(!vt(w,"match3-swap")||V>7)&&!_r(w)){let l=lo(s);l&&kt(w,"swipe",at(a,l[0].col,l[0].row),at(a,l[1].col,l[1].row),a.cell*1.1);}if(ue>=Ae()&&!vt(w,"m3-skill")&&!_r(w)){let l=ke.find(E=>E.id==="skill");l&&kt(w,"tap",l,void 0,a.cell*1.2);}}}}}),u();}};var as=[{id:"garden",prefix:"item",levels:8,color:"accent",gen:"mg_gen_garden"},{id:"bake",prefix:"mg_bake",levels:7,color:"coin",gen:"mg_gen_bake"},{id:"jewel",prefix:"mg_jewel",levels:7,color:"primary",gen:"mg_gen_jewel"},{id:"potion",prefix:"mg_potion",levels:7,color:"secondary",gen:"mg_gen_potion"}],Cr=e=>as.find(t=>t.id===e),hl=3,Dd=[0,.2,.35],Od=.06,gr={box:{id:"box",layer:"block",art:["mg_box","mg_box2"],neighbour:true,coins:1},fog:{id:"fog",layer:"cover",art:["mg_fog"],neighbour:true,hides:true},web:{id:"web",layer:"cover",art:["mg_web"],neighbour:true,mergeInto:true},bubble:{id:"bubble",layer:"cover",art:["mg_bubble"],neighbour:false,mergeInto:true,ttl:14}},ul=[{id:"joker",art:"mg_joker",effect:"joker"},{id:"scissors",art:"mg_scissors",effect:"split"},{id:"chest",art:"chest",effect:"chest",amount:3},{id:"battery",art:"mg_energy",effect:"energy",amount:6}],Jr=e=>ul.find(t=>t.id===e),ml=[[1,.5],[2,.35],[3,.15]],yl={"-":{kind:"free"},".":{kind:"hole"},A:{kind:"gen",chain:0},B:{kind:"gen",chain:1},C:{kind:"gen",chain:2},D:{kind:"gen",chain:3},a:{kind:"item",chain:0,level:1},b:{kind:"item",chain:1,level:1},c:{kind:"item",chain:2,level:1},d:{kind:"item",chain:3,level:1},x:{kind:"block",obstacle:"box",hp:1},X:{kind:"block",obstacle:"box",hp:2},f:{kind:"cover",obstacle:"fog",levels:[1,2,2,3]},w:{kind:"cover",obstacle:"web",levels:[2,2,3]},u:{kind:"cover",obstacle:"bubble",levels:[3,3,4]},J:{kind:"special",special:"joker"},S:{kind:"special",special:"scissors"},K:{kind:"special",special:"chest"},E:{kind:"special",special:"battery"}},Cd=7,Pd=8,An={start:["-------","-------","--a-a--","---A---","--a----","-------","-------","-------"],two:["-------","-------","-a---b-","--A-B--","-------","-------","-------","-------"],boxes:["-------","-------","--A-B--","-------","xxxxxxx","x--K--x","x-----x","xxxxxxx"],fog:["fffffff","fffffff","-------","--A-B--","-------","-------","xx-E-xx","xx---xx"],yard:["X-----X","-------","-A-J-B-","-------","xx---xx","fx---xf","ffx-xff","fffffff"],cellar:["XxxxxxX","x-----x","x-A-B-x","x-----x","x--K--x","xfffffx","xfffffx","XxxxxxX"],webs:["-------","-w---w-","--A-B--","---C---","-w---w-","-------","--www--","-------"],mine:["XX---XX","X--S--X","--A-C--","---B---","-------","ffXXXff","fff-fff","fffffff"],workshop:["w--E--w","-------","-A-B-C-","-------","xwxwxwx","-------","x--K--x","XXXXXXX"],vault:["XfffffX","fx---xf","f-A-B-f","f--J--f","f-C---f","fx---xf","XfffffX","XXXXXXX"],bubbles:["-------","-u---u-","--A-B--","---C---","-------","-u---u-","--uuu--","-------"],holes:["..---..",".-----.","--A-B--","---C---","---D---","--fff--",".-fff-.","..---.."],lab:["u-----u","-x-E-x-","--A-D--","-------","--B-C--","-w---w-","xxwuwxx","XXXXXXX"],terrace:["...-...","..---..",".-A-B-.","---J---","-C---D-","-u-x-u-","xxfffxx","XXfffXX"],four:["-------","-A---B-","-------","---J---","-------","-C---D-","xxxxxxx","XXXXXXX"],fortress:["ffXXXff","fx---xf","X-A-B-X","X--S--X","X-C-D-X","fx-K-xf","ffXXXff","fffffff"],maze:["-x-u-x-","-x---x-","-xA-Bx-","--w-w--","-xC-Dx-","-x---x-","-xfffx-","XXfffXX"],palace:["uXXXXXu","X--E--X","X-A-B-X","X--J--X","X-C-D-X","Xw---wX","XffKffX","XXXXXXX"]},gl=[{id:"upgrade",art:"mg_sk_merge",charge:10,effect:"upgrade",count:3},{id:"free",art:"mg_sk_free",charge:9,effect:"free",count:6},{id:"joker",art:"mg_sk_joker",charge:12,effect:"joker",count:2}],ha=e=>gl.find(t=>t.id===e),fo=[{id:"hero",cast:"hero",gems:0,skill:"upgrade"},{id:"hero2",cast:"hero2",gems:150,skill:"free"},{id:"hero3",cast:"hero3",gems:300,skill:"joker"}],We=(e,t,r,o,n=0,s=3,a)=>({board:e,chains:[...t].map(i=>({g:"garden",b:"bake",j:"jewel",p:"potion"})[i]??"garden"),orders:r,top:o,double:n,visible:s,...a?{slack:a}:{}}),fa=e=>({...e,vip:true}),sr=(e,t)=>({...e,extra:t}),ua=[We("start","g",3,3,0,1,1.6),We("start","g",4,3,0,2,1.5),We("two","gb",4,3,0,2,1.45),We("two","gb",5,4,0,2),We("boxes","gb",5,4,0,3),We("boxes","gb",6,4,.2,3),We("fog","gb",6,4,.2,3),We("yard","gb",6,5,.2,3),We("fog","gb",7,5,.3,3),sr(fa(We("cellar","gb",6,5,.3,3)),.92),sr(We("webs","gbj",5,4,.2,3),.92),sr(We("webs","gbj",6,4,.3,3),.92),sr(We("mine","gbj",6,5,.2,3),1.15),sr(We("workshop","gbj",6,5,.3,3),.9),sr(We("mine","gbj",7,5,.3,3),1.08),sr(We("yard","gj",6,5,.3,3),1.15),sr(We("workshop","gbj",7,5,.4,3),.92),We("vault","gbj",7,5,.3,3),sr(We("webs","jbg",7,6,.3,3),.92),fa(We("vault","gbj",7,6,.4,3)),sr(We("bubbles","gbp",6,5,.2,3),1.15),sr(We("bubbles","gbp",6,5,.3,3),1.12),sr(We("holes","gbpj",6,5,.3,3),.92),sr(We("lab","gbjp",7,5,.3,3),.92),We("holes","gbpj",7,5,.4,3),We("bubbles","pjg",7,6,.3,3),We("lab","gbjp",7,6,.4,3),We("terrace","gbjp",8,5,.4,3),We("holes","gbpj",8,6,.4,3),fa(We("terrace","gbjp",7,6,.4,3)),We("four","gbjp",7,5,.3,3),sr(We("fortress","gbjp",7,5,.4,3),1.06),We("maze","gbjp",7,6,.4,3),We("four","gbjp",8,6,.4,3),sr(We("fortress","gbjp",8,6,.5,3),1.06),We("palace","gbjp",8,6,.4,3),We("maze","gbjp",8,6,.5,3),We("lab","gbjp",9,6,.5,3),We("palace","gbjp",9,6,.5,3),sr(fa(We("fortress","gbjp",8,6,.5,3)),1.06)],co=10,Id=4,ma=ua.length,bl=[0,18,45,75];function Yh(e){let t=e>>>0;return ()=>{t=t+1831565813>>>0;let r=t;return r=Math.imul(r^r>>>15,r|1),r^=r+Math.imul(r^r>>>7,r|61),((r^r>>>14)>>>0)/4294967296}}var pa=e=>Math.pow(2,Math.max(0,e-1));function Jh(e,t){let r=Yh(t*7919+13),o=[],n=e.chains;for(let s=0;s<e.orders;s++){let a=e.orders<=1?1:s/(e.orders-1),i=e.vip===true&&s===e.orders-1,p=2+Math.round(a*(e.top-2)),m=Math.max(2,Math.min(e.top,p-(r()<.3?1:0))),$=n[(s+Math.floor(r()*n.length))%n.length],k=[{chain:$,level:i?Math.min(e.top+1,(Cr($)?.levels??7)-1):m}];if(i||s>0&&n.length>1&&r()<e.double){let O=n[(n.indexOf($)+1+Math.floor(r()*(n.length-1)))%n.length];k.push({chain:O,level:i?e.top:Math.max(2,m-1)});}o.push({wants:k,vip:i});}return o}function eu(e){let t=n=>n.reduce((s,a)=>s+pa(a),0)/Math.max(1,n.length),r=ml.reduce((n,[s,a])=>n+pa(s)*a,0),o=0;for(let n of e.join("")){let s=yl[n];if(s){if(s.kind==="item")o+=pa(s.level);else if(s.kind==="cover")o+=t(s.levels)*(gr[s.obstacle]?.mergeInto&&!gr[s.obstacle]?.ttl?.5:.2);else if(s.kind==="special"){let a=Jr(s.special);o+=a?.effect==="energy"?a.amount??0:a?.effect==="chest"?r*(a.amount??0):a?.effect==="joker"?3:2;}}}return o}function po(e,t=.5){let r=Math.max(1,Math.min(ma,Math.floor(e))),o=ua[r-1],n=Math.ceil(r/co),s=Jh(o,r),a=s.reduce((m,$)=>m+$.wants.reduce((k,O)=>k+pa(O.level),0),0),i=Math.max(a*.4,a-eu(An[o.board]??[])*.7),p=(o.slack??1.32-(n-1)*.08-(r-(n-1)*co)*.006)*(1.1-t*.2)*(o.extra??1);return {level:r,world:n,index:r-(n-1)*co,def:o,boss:o.vip===true,orders:s,energy:Math.ceil(i*p),firstClearGold:(o.vip?120:50)+(r-1)*10}}var xl=e=>bl[Math.ceil(Math.max(1,e)/co)-1]??0,ya=e=>e>=.2?3:e>=.08?2:1,ga=15,kl="kit-merge",vl=[{id:"Energy",var:"meta:energy",art:"mg_energy",color:"coin",perLevel:2,unit:"",maxLevel:15,price:40,growth:.12},{id:"GenLuck",var:"meta:luck",art:"mg_joker",color:"secondary",perLevel:2,unit:"%",maxLevel:15,price:45,growth:.12},{id:"Reward",var:"meta:reward",art:"coin",color:"coin",perLevel:5,unit:"%",maxLevel:20,price:40,growth:.12},{id:"SkillPower",var:"meta:skill",art:"mg_sk_merge",color:"secondary",perLevel:8,unit:"%",maxLevel:10,price:50,growth:.12},{id:"Charge",var:"meta:charge",art:"mg_sk_free",color:"primary",perLevel:5,unit:"%",maxLevel:10,price:50,growth:.12}],Nd={game:"merge",character:kl,stats:vl,heroes:fo,levels:ma,firstClearGold:e=>po(e).firstClearGold,stars:3,starsToEnter:xl};var ba=e=>({kind:"none",at:e,hits:[],coins:0}),en=e=>Cr(e)?.levels??8,$l=(e,t,r,o,n="")=>({id:e.nextId++,kind:t,chain:r,level:o,special:n}),is=(e,t,r)=>$l(e,"item",t,r),Bd=(e,t)=>$l(e,"special","",0,t);function Ml(e,t,r){let o=Math.max(...e.map(a=>a.length)),n={cols:o,rows:e.length,cells:[],chains:t,nextId:1,rand:r},s=a=>t[a]??null;for(let a=0;a<e.length;a++){let i=[];for(let p=0;p<o;p++){let m=yl[e[a][p]??"-"]??{kind:"free"},$={hole:m.kind==="hole",thing:null,cover:null,block:null};if(m.kind==="gen"){let k=s(m.chain);k&&($.thing=$l(n,"gen",k,1));}else if(m.kind==="item"){let k=s(m.chain);k&&($.thing=is(n,k,m.level));}else if(m.kind==="block")$.block={id:m.obstacle,hp:m.hp};else if(m.kind==="cover"){let k=t[Math.floor(r()*t.length)]??"garden",O=Math.min(en(k)-1,m.levels[Math.floor(r()*m.levels.length)]??1);$.thing=is(n,k,O);let C=gr[m.obstacle];$.cover={id:m.obstacle,hp:1,...C?.ttl?{ttl:C.ttl}:{}};}else m.kind==="special"&&($.thing=Bd(n,m.special));i.push($);}n.cells.push(i);}return n}var Tn=(e,t)=>e.cells[t.row]?.[t.col],Hd=(e,t)=>t.col>=0&&t.row>=0&&t.col<e.cols&&t.row<e.rows,Wd=e=>!!e&&!e.hole&&!e.thing&&!e.block,ho=(e,t)=>{let r=Tn(e,t);return !!r&&!!r.thing&&!r.cover&&!r.block};function Pr(e){let t=[];for(let r=0;r<e.rows;r++)for(let o=0;o<e.cols;o++){let n=e.cells[r][o];n.thing&&t.push({at:{col:o,row:r},thing:n.thing,cell:n});}return t}var tu=e=>e.cells.reduce((t,r)=>t+r.filter(Wd).length,0);function xa(e,t){let r=null,o=1/0;for(let n=0;n<e.rows;n++)for(let s=0;s<e.cols;s++){if(!Wd(e.cells[n][s]))continue;let a=Math.hypot(s-t.col,(n-t.row)*1.05);a<o-1e-9&&(o=a,r={col:s,row:n});}return r}function ka(e,t){let r=t?.thing;return !t||!r||t.block||r===e||e.kind!==r.kind||e.kind==="special"||t.cover&&!gr[t.cover.id]?.mergeInto||e.chain!==r.chain||e.level!==r.level?false:e.kind==="gen"?e.level<hl:e.level<en(e.chain)}function zd(e,t){let r=[],o=0;for(let[n,s]of [[1,0],[-1,0],[0,1],[0,-1]]){let a={col:t.col+n,row:t.row+s};if(!Hd(e,a))continue;let i=e.cells[a.row][a.col];for(let p of ["block","cover"]){let m=i[p];if(!m)continue;let $=gr[m.id];if(!$?.neighbour)continue;m.hp--;let k=m.hp<=0;k&&(i[p]=null,o+=$.coins??0),r.push({at:a,id:m.id,gone:k,revealed:k&&!!$.hides});}}return {hits:r,coins:o}}function jd(e,t,r){if(!ho(e,t)||!Hd(e,r)||t.col===r.col&&t.row===r.row)return ba(t);let o=Tn(e,t),n=Tn(e,r),s=o.thing;if(n.hole||n.block)return ba(t);if(ka(s,n)){let m=n.thing;o.thing=null,m.level++;let $=n.cover?.id;n.cover=null;let k=zd(e,r);return {kind:"merge",at:r,level:m.level,...$?{freed:$}:{},hits:k.hits,coins:k.coins}}let a=s.kind==="special"?Jr(s.special):void 0,i=n.thing,p=!n.cover||!!gr[n.cover.id]?.mergeInto;if(a?.effect==="joker"&&i?.kind==="item"&&p&&i.level<en(i.chain)){o.thing=null,i.level++;let m=n.cover?.id;n.cover=null;let $=zd(e,r);return {kind:"joker",at:r,level:i.level,...m?{freed:m}:{},hits:$.hits,coins:$.coins}}if(a?.effect==="split"&&i?.kind==="item"&&!n.cover&&i.level>=2){o.thing=null;let m=xa(e,r);return m?(i.level--,e.cells[m.row][m.col].thing=is(e,i.chain,i.level),{kind:"split",at:r,level:i.level,second:m,hits:[],coins:0}):(o.thing=s,ba(t))}return i?n.cover?ba(t):(o.thing=i,n.thing=s,{kind:"swap",at:r,hits:[],coins:0}):(o.thing=null,n.thing=s,{kind:"move",at:r,hits:[],coins:0})}function Vd(e,t,r=0){let o=Tn(e,t)?.thing;if(!o||o.kind!=="gen"||Tn(e,t).cover)return null;let n=xa(e,t);if(!n)return null;let s=e.rand(),a=Math.max(1,Math.min(hl,o.level)),i=a>=3&&s<Od?3:s<(Dd[a-1]??0)+r?2:1,p=is(e,o.chain,Math.min(i,en(o.chain)));return e.cells[n.row][n.col].thing=p,{at:n,thing:p,burst:ru(e)}}function ru(e){let t=[];for(let r=0;r<e.rows;r++)for(let o=0;o<e.cols;o++){let n=e.cells[r][o];n.cover?.ttl!==void 0&&(n.cover.ttl--,!(n.cover.ttl>0)&&(n.cover=null,n.thing=null,t.push({col:o,row:r})));}return t}var nu=e=>{let t=0;for(let[r,o]of ml)if(t+=o,e<t)return r;return 1};function Gd(e,t){let r=Tn(e,t),o=r?.thing;if(!r||!o||o.kind!=="special"||r.cover)return null;let n=Jr(o.special);if(n?.effect==="energy")return r.thing=null,{energy:n.amount??5,spawned:[]};if(n?.effect!=="chest")return null;r.thing=null;let s=[];for(let a=0;a<(n.amount??3);a++){let i=xa(e,t);if(!i)break;let p=e.chains[Math.floor(e.rand()*e.chains.length)]??as[0].id,m=is(e,p,Math.min(en(p),nu(e.rand())));e.cells[i.row][i.col].thing=m,s.push({at:i,thing:m});}return s.length===0?(r.thing=o,null):{energy:0,spawned:s}}function Kd(e,t={}){let r=Pr(e).filter(s=>ho(e,s.at)&&(s.thing.kind==="item"||t.gens!==false&&s.thing.kind==="gen")),o=null,n=1/0;for(let s of r)for(let a=0;a<e.rows;a++)for(let i=0;i<e.cols;i++){let p=e.cells[a][i];if(!ka(s.thing,p))continue;let m=(s.thing.kind==="gen"?100:0)+s.thing.level-(p.cover?.5:0);m<n&&(n=m,o=[s.at,{col:i,row:a}]);}return o}function Dn(e,t){let r=new Set,o=[],n=Pr(e);for(let s of t){let a=n.find(i=>i.thing.kind==="item"&&!i.cell.cover&&!r.has(i.thing.id)&&i.thing.chain===s.chain&&i.thing.level===s.level);if(!a)return null;r.add(a.thing.id),o.push(a.at);}return o}function wl(e,t){let r=Tn(e,t);if(!r?.thing)return null;let o=r.thing;return r.thing=null,o}function El(e,t,r){let o=xa(e,r),n=Bd(e,t);if(o)return e.cells[o.row][o.col].thing=n,{at:o,thing:n};let s=Pr(e).filter(a=>a.thing.kind==="item"&&!a.cell.cover).sort((a,i)=>a.thing.level-i.thing.level)[0];return s?(s.cell.thing=n,{at:s.at,thing:n}):null}function Fd(e){let t=Pr(e),r=tu(e)>0;for(let o of t){if(o.thing.kind!=="special"||o.cell.cover)continue;let n=Jr(o.thing.special);if(n?.effect==="energy"||n?.effect==="chest"&&r||n?.effect==="joker"&&t.some(s=>s.thing.kind==="item"&&(!s.cell.cover||gr[s.cell.cover.id]?.mergeInto)&&s.thing.level<en(s.thing.chain))||n?.effect==="split"&&r&&t.some(s=>s.thing.kind==="item"&&!s.cell.cover&&s.thing.level>=2))return true}return false}function qd(e,t,r){let o=[];for(let n=0;n<t;n++){let s=Pr(e).filter(p=>p.thing.kind==="item"&&!p.cell.cover&&p.thing.level<en(p.thing.chain)&&!o.some(m=>m.col===p.at.col&&m.row===p.at.row));if(s.length===0)break;let a=p=>r.some(m=>m.chain===p.thing.chain&&m.level===p.thing.level+1);s.sort((p,m)=>Number(a(m))-Number(a(p))||p.thing.level-m.thing.level);let i=s[0];i.thing.level++,o.push(i.at);}return o}var Sl=90,ls=ve("merge.item"),Zd=ve("merge.order"),Ll=ve("merge.layer"),Ud=ve("merge.backdrop"),Xd=ve("merge.part"),uo=ve("merge.customer"),mo=(e,t)=>{let r=Number(e.vars[t]??0);return Number.isFinite(r)?r:0},va={id:"merge",version:2,engines:["phaser"],requires:["round"],params:{difficulty:{type:"number",default:.5,min:0,max:1},orderReward:{type:"number",default:1,min:0,max:100},mergeScore:{type:"number",default:10,min:1,max:1e3,integer:true},energyBonus:{type:"number",default:20,min:0,max:1e4,integer:true}},setup({world:e,params:t}){let r=f=>yr(t,f),o=e.rng.stream("merge"),n=po(1,r("difficulty")),s=Ml(An.start,["garden"],()=>o.next()),a=oe(),i=new Map,p=new Map,m=null,$=[],k=[],O=0,C=0,z=0,F=0,ne=0,X=0,ye=0,be=0,fe=false,we=false,de=null,Re=[],Ce=()=>fo.find(f=>f.id===e.vars["meta:hero"])??fo[0],Me=()=>ha(Ce().skill),ce=()=>e.vars.reviving===true,ue=()=>Me().charge,Pe=()=>mo(e,"meta:luck"),Le=()=>$.flatMap(f=>f.order.wants);function oe(){return un(He(e),s.cols,s.rows,{top:.3,bottom:.86,widthShare:.94})}let Ee=()=>a.cell,tt=new Set,Ne=(f,b,d,h,v=1)=>{tt.add(f);let A=p.get(f);(A===void 0||!e.isAlive(A))&&(A=e.create(),e.set(A,Xd,{id:f}),p.set(f,A)),e.set(A,K,{x:b,y:d,scale:v}),e.set(A,ie,h);},se=()=>{for(let[f,b]of [...p])tt.has(f)||(e.destroy(b),p.delete(f));},ke=f=>{if(f.kind==="special")return Jr(f.special)?.art??"chest";let b=Cr(f.chain);return f.kind==="gen"?b?.gen??"chest":`${b?.prefix??"item"}${Math.min(f.level,b?.levels??8)}`},_e=f=>{let b=Ee(),d=f.kind==="gen"?.94:.92;return {shape:"sprite",art:ke(f),w:b*d,h:b*d,depth:3}},Te=()=>{let f=new Map(Pr(s).map(b=>[b.thing.id,b]));for(let[b,d]of [...i])f.has(b)||(e.destroy(d),i.delete(b));for(let[b,d]of f){let h=i.get(b);if(h===void 0){h=e.create();let N=at(a,d.at.col,d.at.row);e.set(h,K,{x:N.x,y:N.y,scale:.3}),i.set(b,h);}e.set(h,ls,{id:b,col:d.at.col,row:d.at.row});let v=_e(d.thing),A=d.cell.cover&&gr[d.cell.cover.id]?.hides;e.set(h,ie,{...v,alpha:A?0:1,depth:m?.id===b?30:3});}Be(),yt();},Be=()=>{dt(e,Ll);let f=Ee();for(let b=0;b<s.rows;b++)for(let d=0;d<s.cols;d++){let h=s.cells[b][d],v=at(a,d,b);for(let[A,N,B]of [["b",h.block,3],["c",h.cover,5]]){if(!N)continue;let Q=gr[N.id],J=Q?.art[Math.min(Q.art.length,Math.max(1,N.hp))-1]??"mg_box",$e=e.create();e.set($e,Ll,{key:`${A}${d},${b}`}),e.set($e,K,{x:v.x,y:v.y}),e.set($e,ie,{shape:"sprite",art:J,w:f*.98,h:f*.98,depth:B,alpha:N.id==="bubble"&&(N.ttl??99)<=3?.55+.4*Math.abs(Math.sin(e.time*6)):1});}}},ee=()=>{dt(e,Ud),zt(e,"board",a.top+a.cell*s.rows*.3);let f=Ee(),b=at(a,(s.cols-1)/2,(s.rows-1)/2),d=f*.22,h=(v,A,N)=>{let B=e.create();e.set(B,Ud,{i:0}),e.set(B,K,{x:v,y:A}),e.set(B,ie,N);};h(b.x,b.y,{shape:"sprite",art:"panel",w:f*s.cols+d*2,h:f*s.rows+d*2,color:"panel",alpha:.9,depth:-10});for(let v=0;v<s.rows;v++)for(let A=0;A<s.cols;A++){if(s.cells[v][A].hole)continue;let N=at(a,A,v);h(N.x,N.y,{shape:"sprite",art:"cell",w:f-3,h:f-3,color:(v+A)%2?"panel":"ground",alpha:.85,depth:-9});}},Ie=()=>Math.max(1,n.def.visible),nt=f=>{let b=He(e),d=Ie(),h=Math.min(b.w*.3,Ee()*2.6),v=b.w/2+(f-(d-1)/2)*(h+Ee()*.2),A=h*(d>2?.62:.72),N=b.h*.118+A/2,B=a.top-Ee()*.18;return {x:v,y:N,w:h,h:A,feet:B}},ht=(f,b,d)=>{let h=nt(f),v=Math.max(24,(h.feet-(h.y+h.h/2))*1.05),A=d?-v:h.x,N=e.create();return e.set(N,K,{x:A,y:h.feet-v/2}),e.set(N,ie,{shape:"actor",cast:b.vip?"boss":"helper",variant:b.vip?7:o.int(0,99),h:v,pose:d?"walk":"idle",facing:1,speed:Sl,depth:6}),e.set(N,uo,{slot:f,to:h.x,leaving:-1}),N},Ae=f=>{for(let b=0;b<Ie();b++){if($.some(h=>h.slot===b))continue;let d=k.shift();d&&$.push({order:d,slot:b,customer:ht(b,d,f)});}},Gt=(f,b)=>{for(let d of f.query(uo)){let h=f.need(d,uo),v=f.need(d,K),A=f.need(d,ie);if(A.shape!=="actor")continue;if(h.leaving>=0){h.leaving+=b,h.leaving>.7&&(A.pose="walk",A.facing=1,v.x+=Sl*1.4*b);continue}let N=h.to-v.x;Math.abs(N)>1?(v.x+=Math.sign(N)*Math.min(Math.abs(N),Sl*2*b),A.pose="walk",A.facing=N>0?1:-1):A.pose==="walk"&&(v.x=h.to,A.pose="idle");}},Xe=f=>Math.max(1,Math.round(f.wants.reduce((b,d)=>b+d.level,0)*r("orderReward")*(f.vip?3:1)*(1+mo(e,"meta:reward")))),rt=f=>{let b=Dn(s,f.order.wants);if(!b)return false;let d=nt(f.slot);for(let A of b){let N=at(a,A.col,A.row);G(e,{kind:"burst",x:N.x,y:N.y,color:"coin",n:8,size:Ee()*.8}),wl(s,A);}let h=Xe(f.order);Je(e,"coins",h),Je(e,"score",h*25),G(e,{kind:"burst",x:d.x,y:d.y,color:"coin",n:14,size:d.w*.8}),G(e,{kind:"pop",x:d.x,y:d.y-d.h*.5,text:`+${h}`,color:"coin",size:Math.round(d.h*.42)}),e.emit("coin-collected",{value:h}),e.emit("order-filled",{reward:h,vip:f.order.vip}),Lt(e,"merge-order"),ne++;let v=e.get(f.customer,uo);return v&&(v.leaving=0,Fe(e,f.customer,"cheer"),_n(e,f.customer,2.4)),$=$.filter(A=>A!==f),Ae(true),Te(),$.length===0&&k.length===0&&Et(),true},lt=(f,b,d,h,v,A)=>{let N=Math.max(8,h*.11);Ne(`${f}:bg`,b,d,{shape:"rect",w:h,h:N,color:"#000000",alpha:.5,radius:N/2,depth:69});let B=Math.max(1,(h-4)*Math.max(0,Math.min(1,v)));Ne(`${f}:fill`,b-(h-4)/2+B/2,d,{shape:"rect",w:B,h:N-4,color:A,radius:(N-4)/2,depth:69.1});},ft=()=>{let f=He(e),b=Math.min(f.w,f.h),d=Ee(),h=(V,te,Y,w,S="text",l=b*.045,E=70)=>Ne(V,te,Y,{shape:"text",text:w,size:Math.round(l),color:S,bold:true,depth:E});Re=[],tt.clear();let v=f.h*.085;Ne("h:en:i",f.w*.1,v,{shape:"sprite",art:"mg_energy",w:b*.07,h:b*.07,depth:70}),h("h:en",f.w*.1+b*.075,v,String(O),O<=3&&z===0?"danger":"text",b*.06),z>0&&h("h:free",f.w*.1+b*.17,v,`+${z}`,"secondary",b*.04);let A=$.length+k.length;Ne("h:ord:i",f.w*.8,v,{shape:"sprite",art:"ticket",w:b*.075,h:b*.05,color:"panel",depth:70}),h("h:ord",f.w*.8+b*.08,v,String(A),"text",b*.05);for(let V of $){let te=nt(V.slot);Dn(s,V.order.wants)!==null&&Ne(`h:t${V.slot}:glow`,te.x,te.y,{shape:"rect",w:te.w*1.08,h:te.h*1.14,color:"accent",alpha:.45+.3*Math.sin(e.time*6),radius:te.h*.2,depth:7.9}),Ne(`h:t${V.slot}`,te.x,te.y,{shape:"sprite",art:"ticket",w:te.w,h:te.h,color:V.order.vip?"coin":"panel",depth:8});let w=V.order.wants.length,S=Math.min(te.h*.58,te.w*.86/w);V.order.wants.forEach((l,E)=>{let T=te.x+(E-(w-1)/2)*S*1.05,c=te.y-te.h*.12,y=Cr(l.chain);Ne(`h:t${V.slot}:${E}`,T,c,{shape:"sprite",art:`${y?.prefix??"item"}${Math.min(l.level,y?.levels??8)}`,w:S,h:S,depth:8.1}),Dn(s,[l])?h(`h:t${V.slot}:${E}:ok`,T+S*.32,c+S*.32,"\u2713","accent",S*.42,8.2):h(`h:t${V.slot}:${E}:lv`,T+S*.34,c+S*.34,String(l.level),"coin",S*.3,8.2);}),Ne(`h:t${V.slot}:c`,te.x-te.w*.1,te.y+te.h*.3,{shape:"sprite",art:"coin",w:te.h*.19,h:te.h*.19,depth:8.1}),h(`h:t${V.slot}:cv`,te.x+te.w*.07,te.y+te.h*.3,String(Xe(V.order)),"coin",te.h*.2,8.1),Re.push({id:`order${V.slot}`,x:te.x,y:te.y,r:te.w*.5});}let N=Le();for(let V of Pr(s)){if(V.cell.cover&&gr[V.cell.cover.id]?.hides)continue;let te=i.get(V.thing.id);if(te===void 0)continue;let Y=e.need(te,K),w=m?.id===V.thing.id?31:6;if(V.thing.kind==="gen")for(let S=0;S<V.thing.level;S++)Ne(`h:i${V.thing.id}:s${S}`,Y.x+(S-(V.thing.level-1)/2)*d*.2,Y.y+d*.38,{shape:"circle",r:d*.075,color:"coin",depth:w});else V.thing.kind==="item"&&(N.some(S=>S.chain===V.thing.chain&&S.level===V.thing.level)&&(Ne(`h:i${V.thing.id}:ok`,Y.x+d*.3,Y.y-d*.3,{shape:"circle",r:d*.12,color:"accent",depth:w}),h(`h:i${V.thing.id}:okt`,Y.x+d*.3,Y.y-d*.3,"\u2713","#ffffff",d*.18,w+.1)),h(`h:i${V.thing.id}:lv`,Y.x+d*.3,Y.y+d*.3,String(V.thing.level),"coin",d*.22,w));}let B=a.top+d*s.rows+(f.h-(a.top+d*s.rows))*.5,Q=Math.min(b*.075,(f.h-(a.top+d*s.rows))*.38),J=f.w*.3,$e=F>=ue();Re.push({id:"skill",x:J,y:B,r:Q*1.2}),$e&&Ne("h:skill:glow",J,B,{shape:"circle",r:Q*1.28,color:"secondary",alpha:.5+.3*Math.sin(e.time*7),depth:68.9}),Ne("h:skill:bg",J,B,{shape:"circle",r:Q,color:"panel",alpha:.95,depth:69}),Ne("h:skill:i",J,B,{shape:"sprite",art:Me().art,w:Q*1.4,h:Q*1.4,alpha:$e?1:.45,depth:69.2}),lt("h:charge",J+Q*2.6,B,Q*2.4,F/ue(),"secondary");let Se=f.w*.88;Re.push({id:"bin",x:Se,y:B,r:Q*1.1});let Ye=m?i.get(m.id):void 0,pt=Ye!==void 0?e.need(Ye,K):null,ze=pt!==null&&Math.hypot(pt.x-Se,pt.y-B)<Q*1.3;Ne("h:bin:bg",Se,B,{shape:"circle",r:Q,color:ze?"danger":"panel",alpha:.95,depth:69}),Ne("h:bin",Se,B,{shape:"sprite",art:"mg_bin",w:Q*1.3,h:Q*1.3,alpha:m?1:.7,depth:69.2}),(de===null||!e.isAlive(de))&&(de=e.create(),e.set(de,ie,{shape:"actor",cast:Ce().cast,h:Q*2.6,pose:"idle",facing:1,depth:20})),e.set(de,K,{x:f.w*.11,y:B-Q*.1});let le=e.need(de,ie);le.shape==="actor"&&(le.h=Q*2.6),e.vars.mg_buttons=Re.map(V=>`${V.id}@${Math.round(V.x)},${Math.round(V.y)}`).join(";"),se();},yt=()=>{e.vars.energy=O,e.vars.mg_free=z,e.vars.mg_charge=Math.floor(F),e.vars.orders_left=$.length+k.length,e.vars.mg_orders=$.slice().sort((f,b)=>f.slot-b.slot).map(f=>f.order.wants.map(b=>`${b.chain}:${b.level}`).join("+")).join("|"),e.vars.level_progress=n.orders.length?ne/n.orders.length:0;},ut=()=>{dt(e,ls),dt(e,Ll),dt(e,Xd),dt(e,uo),i.clear(),p.clear(),de!==null&&e.isAlive(de)&&e.destroy(de),de=null,n=po(mo(e,"meta:chapter")||1,r("difficulty")),s=Ml(An[n.def.board]??An.start,n.def.chains,()=>o.next()),a=oe(),ee(),m=null,$=[],k=[...n.orders],O=Math.max(0,n.energy+Math.round(mo(e,"meta:energy"))),C=O,z=0,F=0,ne=0,X=0,ye=0,be=0,fe=false,we=false,e.vars.mg_level=n.level,e.vars.mg_world=n.world,e.vars.coins=0,e.vars.score=0,e.vars.stars=0,e.vars.reviving=false,Ae(false),Te();},Et=()=>{we||(e.vars.stars=Math.min(fe?1:3,ya(O/Math.max(1,C))),Je(e,"score",O*r("energyBonus")),G(e,{kind:"flash",color:"coin"}),Ze("cleared"));},Ze=f=>{if(we)return;we=true;let b=f==="cleared";b&&e.vars["meta:first_clear"]===true&&Je(e,"coins",n.firstClearGold),b||(e.vars.stars=0),e.vars.reviving=false,yt(),e.emit(Xt,{reason:f,stats:{chapter:n.level,seconds:Math.floor(ye),cleared:b,stars:Number(e.vars.stars??0),coins:Number(e.vars.coins??0),orders:ne,merges:X}});},Ge=()=>{if(e.vars.revive_ready===true&&!fe){e.vars.reviving=true,e.emit(tr,{});return}Ze("out-of-energy");},It=()=>{ce()&&(fe=true,e.vars.reviving=false,O+=ga,El(s,"joker",{col:Math.floor(s.cols/2),row:Math.floor(s.rows/2)}),G(e,{kind:"flash",color:"coin"}),Te());},Qe=()=>{if(O>0||z>0||F>=ue()||$.some(d=>Dn(s,d.order.wants))||Fd(s))return true;let f=[...Le(),...k.flatMap(d=>d.wants)],b=Pr(s);for(let d of b)if(!(!ho(s,d.at)||d.thing.kind!=="item")&&f.some(h=>h.chain===d.thing.chain&&h.level>d.thing.level)&&b.some(h=>ka(d.thing,h.cell)))return true;return false},Kt=f=>{let b=Ee(),d=at(a,f.at.col,f.at.row);if(f.kind==="merge"||f.kind==="joker"){let h=s.cells[f.at.row][f.at.col].thing,v=Cr(h.chain)?.color??"coin";G(e,{kind:"ring",x:d.x,y:d.y,color:v,size:b*1.4}),G(e,{kind:"burst",x:d.x,y:d.y,color:"coin",n:8,size:b*.8});let A=i.get(h.id);A!==void 0&&(e.need(A,K).scale=1.35),X++,F=Math.min(ue(),F+1+mo(e,"meta:charge")),Je(e,"score",Math.pow(2,h.level)*r("mergeScore")),e.emit("items-merged",{level:h.level,chain:h.chain}),Lt(e,"merge-merge"),h.kind==="item"&&h.level===en(h.chain)&&G(e,{kind:"flash",color:"coin"});for(let N of $)N.order.wants.some(B=>B.chain===h.chain&&B.level===h.level)&&Fe(e,N.customer,"wave");}f.kind==="split"&&G(e,{kind:"ring",x:d.x,y:d.y,color:"secondary",size:b*1.2}),f.freed&&e.emit("obstacle-cleared",{kind:f.freed});for(let h of f.hits){let v=at(a,h.at.col,h.at.row);G(e,{kind:"burst",x:v.x,y:v.y,color:h.id==="fog"?"#ffffff":"ground",n:h.gone?10:4,size:b*.9}),h.gone&&e.emit("obstacle-cleared",{kind:h.id});}f.coins>0&&(Je(e,"coins",f.coins),e.emit("coin-collected",{value:f.coins}),G(e,{kind:"pop",x:d.x,y:d.y-b*.5,text:`+${f.coins}`,color:"coin",size:Math.round(b*.4)})),f.hits.length&&G(e,{kind:"shake",power:.25});},Yt=f=>{if(O<=0&&z<=0){let A=at(a,f.col,f.row);G(e,{kind:"pop",x:A.x,y:A.y-Ee()*.5,text:"0",color:"danger",size:Math.round(Ee()*.4)});return}let b=Vd(s,f,Pe()),d=at(a,f.col,f.row);if(!b){G(e,{kind:"shake",power:.2}),G(e,{kind:"pop",x:d.x,y:d.y-Ee()*.5,text:"\u2715",color:"danger",size:Math.round(Ee()*.45)});return}z>0?z--:O--,Lt(e,"merge-generate");let h=i.get(s.cells[f.row][f.col].thing.id);h!==void 0&&(e.need(h,K).scale=1.2),G(e,{kind:"burst",x:d.x,y:d.y,color:Cr(b.thing.chain)?.color??"accent",n:6,size:Ee()*.7}),e.emit("item-spawned",{level:b.thing.level,chain:b.thing.chain}),Te();let v=i.get(b.thing.id);v!==void 0&&e.set(v,K,{x:d.x,y:d.y,scale:.4});for(let A of b.burst){let N=at(a,A.col,A.row);G(e,{kind:"burst",x:N.x,y:N.y,color:"#ffffff",n:10,size:Ee()});}},Ft=f=>{let b=Gd(s,f);if(!b)return;let d=at(a,f.col,f.row);G(e,{kind:"ring",x:d.x,y:d.y,color:"coin",size:Ee()*1.6}),b.energy>0&&(O+=b.energy,G(e,{kind:"pop",x:d.x,y:d.y-Ee()*.5,text:`+${b.energy}`,color:"coin",size:Math.round(Ee()*.45)})),Te();for(let h of b.spawned){let v=i.get(h.thing.id);v!==void 0&&e.set(v,K,{x:d.x,y:d.y,scale:.4});}},ur=()=>{let f=Me();if(F<f.charge)return false;let b=1+mo(e,"meta:skill"),d=Math.max(1,Math.round(f.count*b));if(F=0,de!==null&&Fe(e,de,"cheer"),G(e,{kind:"flash",color:"secondary"}),f.effect==="upgrade")for(let h of qd(s,d,[...Le(),...k.slice(0,2).flatMap(v=>v.wants)])){let v=at(a,h.col,h.row);G(e,{kind:"ring",x:v.x,y:v.y,color:"secondary",size:Ee()*1.4});}else if(f.effect==="free")z+=d;else for(let h=0;h<d;h++)El(s,"joker",{col:Math.floor(s.cols/2),row:Math.floor(s.rows/2)});return e.emit("skill-cast",{id:f.id}),Lt(e,"merge-skill"),Te(),true},bt=(f,b)=>Re.find(d=>Math.hypot(f-d.x,b-d.y)<=d.r);e.on(Nt,f=>{let b=f;if(!(!st(e)||hn(e)||we||ce())){if(b.type==="press"){Bt(e),be=0;let d=Ur(a,b.x,b.y);if(!d||!ho(s,d))return;let h=s.cells[d.row][d.col].thing.id,v=i.get(h);if(v===void 0)return;let A=e.need(v,K);m={id:h,from:d,dx:A.x-b.x,dy:A.y-b.y,x0:b.x,y0:b.y},e.need(v,ie).depth=30;}else if(b.type==="move"&&m){let d=i.get(m.id);if(d===void 0)return;let h=e.need(d,K);h.x=b.x+m.dx,h.y=b.y+m.dy,h.scale=1.12;}else if(b.type==="release"&&m){let d=m;m=null;let h=i.get(d.id);if(h!==void 0&&(e.need(h,ie).depth=3),Math.hypot(b.x-d.x0,b.y-d.y0)<Ee()*.3)return;let v=bt(b.x,b.y),A=s.cells[d.from.row][d.from.col].thing;if(v?.id==="bin"&&A&&A.kind!=="gen"){wl(s,d.from),Lt(e,"merge-bin"),Te();return}let N=v?.id.startsWith("order")?$.find(J=>`order${J.slot}`===v.id):void 0;if(N&&A?.kind==="item"&&N.order.wants.some(J=>J.chain===A.chain&&J.level===A.level)&&rt(N))return;let B=Ur(a,b.x,b.y);if(!B)return;let Q=jd(s,d.from,B);Q.kind!=="none"&&Kt(Q),Te();}else if(b.type==="tap"){be=0;let d=bt(b.x,b.y);if(d?.id==="skill"){ur();return}if(d?.id.startsWith("order")){let A=$.find(N=>`order${N.slot}`===d.id);A&&rt(A);return}let h=Ur(a,b.x,b.y),v=h?s.cells[h.row][h.col].thing:null;if(!h||!v||!ho(s,h))return;if(v.kind==="gen")Yt(h);else if(v.kind==="special")Ft(h);else {let A=$.find(N=>N.order.wants.some(B=>B.chain===v.chain&&B.level===v.level)&&Dn(s,N.order.wants));A&&rt(A);}}}}),e.on(Ut,()=>{ut(),e.vars.level=n.level;}),e.on(Qt,ut),e.on(rr,It),e.on(nr,()=>{ce()&&(e.vars.reviving=false,Ze("out-of-energy"));}),e.on(Zt,f=>{tt.clear(),se(),Re=[],de!==null&&e.isAlive(de)&&it(e,de,f.reason==="cleared"?"dance":"idle");}),e.on(qt,()=>{a=oe(),ee();for(let f of $){let b=nt(f.slot),d=e.get(f.customer,uo);d&&(d.to=b.x);let h=e.get(f.customer,K),v=Math.max(24,(b.feet-(b.y+b.h/2))*1.05);h&&e.set(f.customer,K,{x:b.x,y:b.feet-v/2});let A=e.get(f.customer,ie);A?.shape==="actor"&&(A.h=v);}Te();});let D=f=>{let b=Math.min(1,f*16);for(let[d,h]of i){if(m?.id===d)continue;let v=e.get(h,ls);if(!v)continue;let A=e.need(h,K),N=at(a,v.col,v.row);A.x+=(N.x-A.x)*b,A.y+=(N.y-A.y)*b;let B=A.scale??1;A.scale=B+(1-B)*Math.min(1,f*10);}},u=f=>{let b=$.find(h=>Dn(s,h.order.wants));if(b&&(!vt(f,"merge-order")||be>6)){let h=nt(b.slot);return kt(f,"tap",{x:h.x,y:h.y},void 0,Ee()*1.1)}let d=Kd(s,{gens:false});if(d&&(!vt(f,"merge-merge")||be>6))return kt(f,"swipe",at(a,d[0].col,d[0].row),at(a,d[1].col,d[1].row),Ee()*1.1);if(F>=ue()&&!vt(f,"merge-skill")){let h=Re.find(v=>v.id==="skill");if(h)return kt(f,"tap",h,void 0,Ee()*1.1)}if(!vt(f,"merge-generate")||be>6){let h=Pr(s).find(v=>v.thing.kind==="gen"&&!v.cell.cover);h&&(O>0||z>0)&&kt(f,"tap",at(a,h.at.col,h.at.row),void 0,Ee()*1.1);}},g=0;e.addSystem({id:"merge",order:0,run(f,b){Gt(f,b),D(b),!(!st(f)||we)&&(ye+=b,be+=b,ft(),++g%20===0&&s.cells.some(d=>d.some(h=>h.cover?.ttl!==void 0&&h.cover.ttl<=3))&&Be(),!(ce()||m)&&(_r(f)||u(f),Qe()||Ge()));}}),ut();}};var jt=10,Qd={id:"start",needs:[],rows:["..............","..............","..............","..............","..............","..............",".......o.o.o..",".P............","##############","##############"]},Yd={id:"checkpoint",needs:[],rows:["..........","..........","..........","..........","..........","..........","...o..o...","....C.....","##########","##########"]},Jd={id:"end",needs:[],rows:["..............","..............","..............","..............","..............","..............",".....o.o......","..........E...","##############","##############"]},ef={id:"boss",needs:[],rows:["..................","..................","..................","..................","...===......===...","..................","..................","..................","##################","##################"]},Ma=[{id:"walk",needs:["walker"],rows:["..............","..............","..............","..............",".....ooo......","....o...o.....","..............",".........W....","##############","##############"]},{id:"two-walkers",needs:["walker"],rows:["..............","..............","..............","......*.......",".....===......","..............","..o........o..","...W......W...","##############","##############"]},{id:"gaps",needs:["gaps"],rows:["..............","..............","..............","..............","..............","....o.....o...","...o.o...o.o..","..............","###...###...##","###...###...##"]},{id:"stairs",needs:["stairs"],rows:["..............","...........*..","..........===.","..............",".......###....",".......###.o..","....##########","....##########","##############","##############"]},{id:"spikes",needs:["spikes"],rows:["..............","..............","..............","..............","..............",".....ooo......","....=====.....","..............","###^^^^^^^####","##############"]},{id:"pits",needs:["pits"],rows:["..............","..............","..............","..............","......o.......",".....===...o..","..o.......===.",".===..........","##..........##","##..........##"]},{id:"spring",needs:["spring"],rows:["..............",".........*....","........####..","..............","..............","..............","..............","...T..........","##############","##############"]},{id:"hopper",needs:["hopper"],rows:["..............","..............","..............","..............",".....o...o....","..............","..............",".......J......","##############","##############"]},{id:"crumble",needs:["crumble"],rows:["..............","..............","..............","..............","..............","...o.o.o.o....","...______.....","..............","##........####","##........####"]},{id:"spiky",needs:["spiky"],rows:["..............","..............","..............","..............","..............","......ooo.....","..............",".......S......","##############","##############"]},{id:"moving",needs:["moving"],rows:["..............","..............","..............","..............",".....o..o.....","..............",".....M........","..............","##..........##","##..........##"]},{id:"flyer",needs:["flyer"],rows:["..............","..............","..............","......F.......","..............","..............","...o......o...","..............","##############","##############"]},{id:"key",needs:["key"],rows:["..............","..............","..K...........",".===..........","..............",".......===....","..............","...........B..","##############","##############"]},{id:"gunner",needs:["gunner"],rows:["..............","..............","..............","..............","..............",".....o.o......","....=====.....","...........G..","##############","##############"]},{id:"heart",needs:["walker","stairs"],rows:["..............","..............","..*...........","..............","......H.......",".....===......","..............","...W......W...","##############","##############"]},{id:"secret-high",needs:["spring","gaps"],rows:["..............","..*...........",".===..........","..............","..............","..............","........T.....","..............","#####...######","#####...######"]}],_l=4,On=5,wa=_l*On,$a={walker:1,gaps:1,spikes:2,stairs:2,pits:3,spring:3,hopper:4,crumble:4,spiky:6,moving:6,flyer:7,key:8,gunner:9},Rl=[0,9,24,39];function yo(e,t=.5){let r=Math.max(1,Math.min(wa,Math.floor(e))),o=Math.ceil(r/On),n=r-(o-1)*On,s=n===On,a=Object.keys($a).filter(p=>$a[p]<=r),i=Object.keys($a).find(p=>$a[p]===r)??null;return {level:r,world:o,index:n,boss:s,features:a,fresh:i,rooms:s?2:3+Math.min(5,Math.floor((r-1)/2)),pace:.85+t*.3+(r-1)*.02,bossHp:3+o,firstClearGold:(s?150:60)+(r-1)*20}}var Al=e=>Rl[Math.ceil(Math.max(1,e)/On)-1]??0,Tl=[{id:"double",stars:6},{id:"dash",stars:15},{id:"wall",stars:27}],Ea=e=>Tl.filter(t=>e>=t.stars).map(t=>t.id),go=[{id:"hero",cast:"hero",gems:0,perk:"none"},{id:"hero2",cast:"hero2",gems:150,perk:"heart"},{id:"hero3",cast:"hero3",gems:300,perk:"jump"}],Dl="kit-platformer",Ol=[{id:"Hearts",var:"meta:hearts",art:"heart",color:"danger",perLevel:1,unit:"",maxLevel:3,price:150,growth:1.2},{id:"JumpPower",var:"meta:jump",art:"boot",color:"accent",perLevel:2,unit:"%",maxLevel:10,price:40,growth:.15},{id:"Magnet",var:"meta:magnet",art:"magnet",color:"danger",perLevel:10,unit:"%",maxLevel:10,price:30,growth:.12},{id:"Grace",var:"meta:grace",art:"shield",color:"muted",perLevel:.2,unit:"s",maxLevel:10,price:35,growth:.12},{id:"Greed",var:"meta:greed",art:"coin",color:"coin",perLevel:2,unit:"%",maxLevel:25,price:40,growth:.1}],tf={game:"platformer",character:Dl,stats:Ol,heroes:go,levels:wa,firstClearGold:e=>yo(e).firstClearGold,stars:3,starsToEnter:Al};var ou="boss-spawned",su="boss-defeated",Cl="level-cleared",ar=ve("platformer.body"),mt=ve("platformer.thing"),cs=ve("platformer.strip"),wr=ve("platformer.hero"),rf=ve("platformer.hud"),gn=(e,t)=>{let r=Number(e.vars[t]??0);return Number.isFinite(r)?r:0},au=6,Cn=40,iu=3.3,lu=6.8,cu=.7,nf=1.3,Sa={id:"platformer",version:2,engines:["phaser"],requires:["round"],params:{difficulty:{type:"number",default:.5,min:0,max:1},lives:{type:"number",default:3,min:1,max:9,integer:true},coinScore:{type:"number",default:10,min:0,max:1e3,integer:true},starScore:{type:"number",default:300,min:0,max:1e4,integer:true},clearBonus:{type:"number",default:500,min:0,max:1e5,integer:true},graceTime:{type:"number",default:1.2,min:0,max:5},doubleJump:{type:"boolean",default:false}},setup({world:e,params:t}){let r=D=>yr(t,D),o=Jn(e),n=yo(1,r("difficulty")),s=[],a=0,i=null,p=0,m={x:2,y:8},$=3,k=3,O=0,C=false,z=false,F=0,ne=0,X=0,ye=false,be=false,fe=[],we=[false,false,false],de=new Map,Re=new Map,Ce=()=>go.find(D=>D.id===e.vars["meta:hero"])??go[0],Me=()=>e.vars.reviving===true,ce=()=>{let D=Number(e.vars.view_w??720),u=Number(e.vars.view_h??1280);return Math.min(D/8,u*.66/10)},ue=()=>Number(e.vars.view_h??1280)*.86-10*ce(),Pe=()=>Number(e.vars.view_w??720)/ce(),Le=(D,u)=>{if(u<0)return ".";if(D<0||D>=a)return "#";if(u>=10)return ".";let g=s[u]?.[D]??".";return g==="_"&&(de.get(`${D},${u}`)??0)>.5?".":g},oe=D=>D==="#",Ee=D=>D==="="||D==="_"||D==="^",tt=()=>{for(let N of e.query(mt))e.destroy(N);for(let N of e.query(cs))e.destroy(N);de.clear(),n=yo(gn(e,"meta:chapter")||1,r("difficulty"));let D=e.rng.stream(`platformer-level-${n.level}`),u=Ma.filter(N=>N.needs.every(B=>n.features.includes(B))),g=[],f=n.fresh!==null?u.find(N=>N.needs.includes(n.fresh)):void 0;for(f&&g.push(f);g.length<n.rooms;)g.push(D.pick(u));let b=Math.ceil(g.length/2),d=[Qd,...g.slice(0,b),Yd,...g.slice(b),n.boss?ef:Jd];s=Array.from({length:10},(N,B)=>d.map(Q=>Q.rows[B]??"").join("")),a=s[0].length;let h=[];for(let N=0;N<10;N++)for(let B=0;B<a;B++)s[N][B]==="*"&&h.push({c:B,r:N});let v=h.length<=3?h:[h[0],h[Math.floor(h.length/2)],h[h.length-1]];for(let N=v.length;N<3;N++)v.push({c:Math.floor(a*(N+1)/4),r:5});let A=0;for(let N=0;N<10;N++)for(let B=0;B<a;B++){let Q=s[N][B],J={x:B+.5,y:N+1};Q==="P"?m={...J}:Q==="o"?ke("coin",J.x,N+.85,.5,.5):Q==="H"&&A++<1?ke("heart",J.x,N+.9,.6,.6):Q==="K"?ke("key",J.x,N+.9,.6,.6):Q==="B"?ke("chest",J.x,J.y,1,.8):Q==="T"?ke("spring",J.x,J.y,1,.5):Q==="M"?ke("mover",J.x+.5,N+.4,2,.4).baseX=J.x+.5:Q==="C"?ke("checkpoint",J.x,J.y,.6,1.6):Q==="E"?ke("flag",J.x,J.y,.8,2.6):Q==="W"?ke("walker",J.x,J.y,.8,1):Q==="S"?ke("spiky",J.x,J.y,.8,1):Q==="J"?ke("hopper",J.x,J.y,.8,1):Q==="F"?ke("flyer",J.x,J.y,.9,.8):Q==="G"&&ke("gunner",J.x,J.y,.8,1.1),/[PoHKBTMCEWSJFG*]/.test(Q)&&(s[N]=Ne(s[N],B,"."));}if(v.forEach((N,B)=>ke("star",N.c+.5,N.r+.95,.85,.85).tag=String(B)),n.boss){let N=ke("boss",a-5,8,2.2,2.4);N.hp=n.bossHp,N.tag="walk",N.t=2;}_e();},Ne=(D,u,g)=>D.slice(0,u)+g+D.slice(u+1),se=(D,u,g,f)=>{switch(D){case "walker":return {shape:"actor",cast:"foe",h:g*f*1.35,pose:"walk",depth:8};case "spiky":return {shape:"actor",cast:"foe2",h:g*f*1.4,pose:"walk",depth:8};case "hopper":return {shape:"actor",cast:"foe3",h:g*f*1.35,pose:"idle",depth:8};case "flyer":return {shape:"actor",cast:"foe5",h:g*f*1.4,pose:"air",depth:8};case "gunner":return {shape:"actor",cast:"foe4",h:g*f*1.3,pose:"idle",depth:8};case "boss":return {shape:"actor",cast:"boss",h:g*f*1.2,pose:"walk",depth:8};case "bullet":return {shape:"sprite",art:"shot",color:"danger",w:u*f,h:g*f,depth:9};case "wave":return {shape:"sprite",art:"burst",color:"danger",w:u*f,h:g*f,depth:9};case "coin":return {shape:"sprite",art:"coin",w:u*f,h:g*f,depth:7};case "star":return {shape:"sprite",art:"bigstar",w:u*f,h:g*f,depth:7};case "heart":return {shape:"sprite",art:"heart",w:u*f,h:g*f,depth:7};case "key":return {shape:"sprite",art:"key",w:u*f,h:g*f,depth:7};case "chest":return {shape:"sprite",art:"chest",w:u*f,h:g*f*1.1,depth:6};case "spring":return {shape:"sprite",art:"spring",w:u*f,h:g*f*1.4,depth:6};case "mover":return {shape:"tile",art:"platform",w:u*f,h:g*f,unit:f,depth:5};case "checkpoint":return {shape:"sprite",art:"flag",color:"muted",w:u*f*1.6,h:g*f,depth:5};case "flag":return {shape:"sprite",art:"flag",w:u*f*1.4,h:g*f,depth:5}}};function ke(D,u,g,f,b){let d=e.create(),h={kind:D,vx:0,vy:0,dir:-1,t:0,baseX:u,baseY:g,hp:1,tag:"",safe:0};return e.set(d,mt,h),e.set(d,ar,{x:u,y:g,w:f,h:b}),e.set(d,K,{x:0,y:0}),e.set(d,ie,se(D,f,b,ce())),e.need(d,mt)}function _e(){for(let u of e.query(cs))e.destroy(u);let D=(Number(e.vars.view_h??1280)-(ue()+10*ce()))/ce()+.5;for(let u=0;u<10;u++){let g=0;for(;g<a;){let f=s[u][g];if(f==="."||f==="_"){f==="_"&&Te("_",g,u,1,.45),g++;continue}let b=f==="#"&&Le(g,u-1)!=="#",d=g;for(;d<a&&s[u][d]===f&&(f!=="#"||Le(d,u-1)!=="#"===b);)d++;if(f==="#"&&b){let h=0;for(;u+h<10&&s[u+h][g]==="#";)h++;Te("#",g,u,d-g,h+(u+h>=10?D:0));}else f!=="#"&&Te(f,g,u,d-g,f==="="?.45:.7);g=d;}}}function Te(D,u,g,f,b){let d=ce(),h=e.create();e.set(h,cs,{char:D}),e.set(h,ar,{x:u+f/2,y:D==="^"?g+1:g+b,w:f,h:b}),e.set(h,K,{x:0,y:0});let v=D==="^"?{shape:"tile",art:"spike",w:f*d,h:b*d,unit:d,depth:4}:D==="#"?{shape:"tile",art:"ground",w:f*d,h:b*d,unit:d*1.2,depth:3}:{shape:"tile",art:"platform",w:f*d,h:b*d,unit:d,depth:3,...D==="_"?{color:"muted",alpha:.85}:{}};e.set(h,ie,v),D==="_"&&e.set(h,mt,{kind:"mover",vx:0,vy:0,dir:0,t:0,baseX:u,baseY:g,hp:0,tag:"crumble",safe:0});}let Be=()=>{(i===null||!e.isAlive(i))&&(i=e.create(),e.set(i,wr,{vx:0,vy:0,grounded:true,facing:1,jumps:0,coyote:0,buffer:0,dash:0,dashCd:0,wall:0,swing:0,swingCd:0}),e.set(i,ar,{x:m.x,y:m.y,w:cu,h:nf}),e.set(i,K,{x:0,y:0})),e.set(i,ie,{shape:"actor",cast:Ce().cast,h:nf*ce()*1.25,pose:"idle",depth:10});},ee=()=>Math.sqrt(2*Cn*iu*(1+gn(e,"meta:jump"))*(Ce().perk==="jump"?1.15:1)),Ie=()=>{if(i===null)return;let D=e.need(i,ar),u=e.need(i,wr);D.x=m.x,D.y=m.y,u.vx=0,u.vy=0;for(let g of e.query(mt))(e.need(g,mt).kind==="bullet"||e.need(g,mt).kind==="wave")&&e.destroy(g);},nt=()=>{Yt(),tt(),k=r("lives")+gn(e,"meta:hearts")+(Ce().perk==="heart"?1:0),$=k,O=0,C=false,z=false,F=0,ne=0,X=0,ye=false,be=!n.boss,we.fill(false),fe=Ea(gn(e,"meta:stars_total")),r("doubleJump")&&!fe.includes("double")&&fe.push("double"),e.vars.abilities=fe.join(","),e.vars.platformer_level=n.level,e.vars.platformer_world=n.world,e.vars.lives=$,e.vars.coins=0,e.vars.score=0,e.vars.stars=0,e.vars.reviving=false,p=0,Be(),Ie(),i!==null&&(e.need(i,wr).facing=1,it(e,i,"idle")),n.boss&&e.emit(ou,{}),It(e);},ht=()=>{!st(e)||Me()||i===null||(e.need(i,wr).buffer=.13);},Ae=()=>{if(i===null)return;let D=e.need(i,wr);D.vy<0&&(D.vy*=.5);},Gt=()=>{if(!st(e)||Me()||i===null||!fe.includes("dash"))return;let D=e.need(i,wr);D.dashCd>0||(D.dash=.2,D.dashCd=.8,D.vy=0,Fe(e,i,"attack"));},Xe=()=>{if(!st(e)||Me()||i===null)return;let D=e.need(i,wr);D.swingCd>0||(D.swing=.16,D.swingCd=.32,Fe(e,i,"attack"));};e.on(Nt,D=>{let u=D;e.vars.started_tick!==e.tick&&(u.type==="key"&&(u.key==="up"||u.key==="action")?ht():u.type==="key-up"&&(u.key==="up"||u.key==="action")?Ae():u.type==="key"&&u.key==="down"?Gt():u.type==="tap"?Xe():u.type==="swipe"&&u.dir==="up"&&ht());});let rt=(D,u)=>{if(!st(D)||C)return;C=true;let g=u==="cleared",f=we.filter(Boolean).length;D.vars.stars=f,g&&D.vars["meta:first_clear"]===true&&Je(D,"coins",n.firstClearGold),D.vars.score=X*r("coinScore")+f*r("starScore")+(g?r("clearBonus"):0),D.vars.reviving=false,g&&D.emit(Cl,{level:n.level}),D.emit(Xt,{reason:u,stats:{chapter:n.level,seconds:Math.floor(F),cleared:g,stars:g?f:0,coins:X,bosses:n.boss&&be?1:0}});},lt=D=>{if(D.vars.revive_ready===true&&!z){D.vars.reviving=true,D.emit(tr,{});return}rt(D,"fell");},ft=D=>{Me()&&(z=true,D.vars.reviving=false,$=Math.max(2,Math.ceil(k/2)),D.vars.lives=$,O=2.5,Ie(),i!==null&&it(D,i,"idle"),G(D,{kind:"flash",color:"coin"}));},yt=(D,u)=>{if(i===null||O>0||C)return;let g=D.need(i,wr);g.dash>0||($--,D.vars.lives=$,D.emit("player-hit",{lives:$}),O=r("graceTime")+gn(D,"meta:grace"),g.vy=-ee()*.55,g.vx=(u===null?-g.facing:Math.sign(D.need(i,ar).x-u)||-g.facing)*5,Fe(D,i,"hit"),G(D,{kind:"shake",power:1.2}),G(D,{kind:"flash",color:"danger"}),$<=0&<(D));},ut=(D,u,g)=>{let f=D.need(u,mt),b=D.need(u,ar),d=ce();G(D,{kind:"burst",x:Ze(b.x),y:Ge(b.y-b.h/2),color:"danger",n:12,size:d*.9}),D.emit("enemy-defeated",{kind:f.kind,by:g}),Je(D,"score",50),D.destroy(u);},Et=(D,u)=>{let g=D.need(u,ar);ne+=1+gn(D,"meta:greed");let f=Math.floor(ne);ne-=f,f>0&&Je(D,"coins",f),X++,D.emit("coin-collected",{value:1}),G(D,{kind:"burst",x:Ze(g.x),y:Ge(g.y-g.h/2),color:"coin",n:6,size:ce()*.6}),D.destroy(u);},Ze=D=>D*ce()-p*ce(),Ge=D=>ue()+D*ce();function It(D){ce();for(let g of D.query(ar)){let f=D.need(g,ar),b=D.get(g,K);if(!b)continue;b.x=Ze(f.x),b.y=Ge(f.y-f.h/2);let d=D.get(g,ie);if(d&&d.shape==="actor"&&D.has(g,mt)){let h=D.need(g,mt);d.facing=h.dir>=0?1:-1,d.alpha=h.safe>0&&Math.floor(D.time*12)%2===0?.35:1,b.y=Ge(f.y)-d.h/2;}if(d&&d.shape==="actor"&&D.has(g,wr)&&(b.y=Ge(f.y)-d.h/2),d&&D.has(g,cs)&&D.need(g,cs).char==="_"){let h=de.get(`${Math.floor(f.x)},${Math.round(f.y-f.h)}`)??0;d.alpha=h>.5?0:h>0?.5+.5*Math.abs(Math.sin(D.time*30)):.85;}}}let Qe=(D,u,g,f)=>{let b=Re.get(D);(b===void 0||!e.isAlive(b))&&(b=e.create(),e.set(b,rf,{id:D}),Re.set(D,b)),e.set(b,K,{x:u,y:g}),e.set(b,ie,f);},Kt=D=>{let u=Re.get(D);u!==void 0&&e.destroy(u),Re.delete(D);};function Yt(){for(let D of Re.values())e.destroy(D);Re.clear(),dt(e,rf);}let Ft=D=>{let u=Number(D.vars.view_w??720),g=Number(D.vars.view_h??1280),f=Math.min(u,g),b=g*.085;Qe("lvl",u*.08,b,{shape:"text",text:`${n.world}-${n.index}`,size:Math.round(f*.042),color:"text",bold:true,depth:42});let d=f*.05;for(let N=0;N<k;N++)Qe(`h${N}`,u*.07+N*d*1.1,b+f*.065,{shape:"sprite",art:"heart",w:d,h:d,alpha:N<$?1:.25,depth:42});for(let N=k;N<12;N++)Kt(`h${N}`);let h=f*.06;for(let N=0;N<3;N++)Qe(`s${N}`,u/2+(N-1)*h*1.15,b,{shape:"sprite",art:"bigstar",w:h,h,alpha:we[N]?1:.25,depth:42});let v=f*.045,A=String(D.vars.coins??0);if(Qe("coin:i",u*.92-A.length*v*.6-v*.7,b,{shape:"sprite",art:"coin",w:v,h:v,depth:42}),Qe("coin",u*.92-A.length*v*.6/2,b,{shape:"text",text:A,size:Math.round(v),color:"text",bold:true,depth:42}),ye?Qe("key",u*.92-v*.3,b+f*.065,{shape:"sprite",art:"key",w:v,h:v,depth:42}):Kt("key"),n.boss){let N=D.query(mt).find(Se=>D.need(Se,mt).kind==="boss"),B=N!==void 0?D.need(N,mt).hp/n.bossHp:0,Q=u*.5,J=Math.max(10,f*.022);Qe("boss:bg",u/2,b+f*.075,{shape:"rect",w:Q,h:J,color:"#000000",alpha:.45,radius:J/2,depth:41});let $e=Math.max(0,(Q-4)*Math.round(B*100)/100);$e<1?Kt("boss:fill"):Qe("boss:fill",u/2-(Q-4)/2+$e/2,b+f*.075,{shape:"rect",w:$e,h:J-4,color:"danger",radius:(J-4)/2,depth:41.1});}};e.on(Ut,()=>{nt(),e.vars.level=n.level;}),e.on(Qt,nt),e.on(rr,()=>ft(e)),e.on(nr,()=>{Me()&&(e.vars.reviving=false,rt(e,"fell"));}),e.on(Zt,D=>{i!==null&&e.isAlive(i)&&it(e,i,D.reason==="cleared"?"dance":"die"),Yt();}),e.on(qt,()=>{zt(e,"side",ue()+8*ce()+2);let D=ce();for(let u of e.query(mt)){let g=e.need(u,mt);if(g.tag==="crumble")continue;let f=e.need(u,ar);e.set(u,ie,se(g.kind,f.w,f.h,D));}_e(),Be(),It(e);}),e.addSystem({id:"platformer",order:0,run(D,u){if(!st(D)||i===null||C||Me())return;F+=u,O>0&&(O=Math.max(0,O-u));let g=D.need(i,ar),f=D.need(i,wr),b=n.pace;for(let[Y,w]of [...de]){let S=w+u;S>3.5?de.delete(Y):de.set(Y,S);}let d=o.axis().x;if(d!==0&&(f.facing=d),f.dash>0)f.dash-=u,f.vx=f.facing*15,f.vy=0;else {let Y=d*au,w=f.grounded?60:32;f.vx+=Math.max(-w*u,Math.min(w*u,Y-f.vx)),f.vy+=Cn*u,f.vy>22&&(f.vy=22);}if(f.dashCd>0&&(f.dashCd-=u),f.swingCd>0&&(f.swingCd-=u),f.swing>0){f.swing-=u;let Y={l:f.facing>0?g.x:g.x-1.4,r:f.facing>0?g.x+1.4:g.x,t:g.y-g.h-.2,b:g.y};for(let w of D.query(mt)){if(!D.isAlive(w)||!D.has(w,mt))continue;let S=D.need(w,mt);if(!["walker","spiky","hopper","flyer","gunner","boss","bullet"].includes(S.kind))continue;let l=D.need(w,ar);l.x+l.w/2<Y.l||l.x-l.w/2>Y.r||l.y-l.h>Y.b||l.y<Y.t||(S.kind==="bullet"?(G(D,{kind:"burst",x:Ze(l.x),y:Ge(l.y-l.h/2),color:"text",n:6,size:ce()*.5}),D.destroy(w)):S.kind==="boss"?ur(D,w,"sword"):ut(D,w,"sword"));}}if(f.coyote=f.grounded?.1:Math.max(0,f.coyote-u),f.buffer>0){f.buffer-=u;let Y=fe.includes("double")&&f.jumps<2;f.coyote>0||f.grounded?(f.vy=-ee(),f.jumps=1,f.buffer=0,f.grounded=false,f.coyote=0):f.wall!==0&&fe.includes("wall")?(f.vy=-ee()*.95,f.vx=-f.wall*7,f.facing=-f.wall,f.jumps=1,f.buffer=0):Y&&f.jumps>=1&&(f.vy=-ee()*.9,f.jumps=2,f.buffer=0,G(D,{kind:"ring",x:Ze(g.x),y:Ge(g.y),color:"text",size:ce()*1.2})),f.buffer===0&&Fe(D,i,"jump");}let h=g.w/2,v=g.x+f.vx*u;f.wall=0;let A=Y=>{let w=[];for(let S=Math.floor(Y-g.h+.05);S<=Math.floor(Y-.05);S++)w.push(S);return w};if(f.vx>0){let Y=Math.floor(v+h);A(g.y).some(w=>oe(Le(Y,w)))&&(v=Y-h-.001,f.grounded||(f.wall=1),f.vx=0);}else if(f.vx<0){let Y=Math.floor(v-h);A(g.y).some(w=>oe(Le(Y,w)))&&(v=Y+1+h+.001,f.grounded||(f.wall=-1),f.vx=0);}f.wall===0&&!f.grounded&&d!==0&&A(g.y).some(Y=>oe(Le(Math.floor(v+d*(h+.05)),Y)))&&(f.wall=d),g.x=Math.max(h,Math.min(a-h,v));let N=g.y,B=g.y+f.vy*u,Q=f.grounded;f.grounded=false;let J=[Math.floor(g.x-h+.05),Math.floor(g.x+h-.05)];if(f.vy>=0){let Y=Math.floor(B);for(let w of J){let S=Le(w,Y),l=Y;if((oe(S)||Ee(S)&&N<=l+.05)&&B>=l){B=l,f.vy=0,f.grounded=true,f.jumps=0,S==="_"&&!de.has(`${w},${Y}`)&&de.set(`${w},${Y}`,.001),S==="^"&&(yt(D,null),f.vy=-ee()*.7,f.grounded=false);break}}}else {let Y=Math.floor(B-g.h);J.some(w=>oe(Le(w,Y)))&&(B=Y+1+g.h,f.vy=0);}g.y=B,!Q&&f.grounded&&Fe(D,i,"jump");for(let Y of D.query(mt)){let w=D.need(Y,mt);if(w.kind!=="mover"||w.tag==="crumble")continue;let S=D.need(Y,ar),l=S.x;w.t+=u,S.x=w.baseX+Math.sin(w.t*.9)*2.2;let E=S.y-S.h;f.vy>=0&&Math.abs(g.x-S.x)<S.w/2+h*.6&&N<=E+.1&&g.y>=E-.05&&(g.y=E,f.vy=0,f.grounded=true,f.jumps=0,g.x+=S.x-l);}if(g.y>12&&(yt(D,null),O=Math.max(O,1),!Me()&&!C&&Ie(),C||Me()))return;let $e={l:g.x-h,r:g.x+h,t:g.y-g.h,b:g.y},Se=Y=>$e.r>Y.x-Y.w/2&&$e.l<Y.x+Y.w/2&&$e.b>Y.y-Y.h&&$e.t<Y.y,Ye=1.2*(1+gn(D,"meta:magnet")),pt=g.x;for(let Y of D.query(mt)){if(!D.isAlive(Y)||!D.has(Y,mt))continue;let w=D.need(Y,mt),S=D.need(Y,ar);switch(w.safe>0&&(w.safe-=u),w.kind){case "walker":case "spiky":{w.vx=w.dir*1.6*b;let l=S.x+w.dir*(S.w/2+.05)+w.vx*u,E=oe(Le(Math.floor(l),Math.floor(S.y-.5))),T=Le(Math.floor(l),Math.floor(S.y));E||!(oe(T)||Ee(T))?w.dir=-w.dir:S.x+=w.vx*u;break}case "hopper":{w.t+=u,w.vy+=Cn*.6*u,S.y+=w.vy*u,S.y>=w.baseY&&(S.y=w.baseY,w.vy=0,w.t>1.5/b&&(w.t=0,w.vy=-Math.sqrt(2*Cn*.6*2.4))),w.dir=pt<S.x?-1:1;break}case "flyer":w.t+=u*b,S.x=w.baseX+Math.sin(w.t*.9)*3,S.y=w.baseY+Math.sin(w.t*1.8)*.9,w.dir=Math.cos(w.t*.9)>=0?1:-1;break;case "gunner":{if(w.dir=pt<S.x?-1:1,w.t+=u,w.t>2.2/b&&Math.abs(pt-S.x)<9){w.t=0;let l=ke("bullet",S.x+w.dir*.6,S.y-.45,.45,.3);l.vx=w.dir*6*b,l.dir=w.dir,Fe(D,Y,"attack");}break}case "bullet":case "wave":if(S.x+=w.vx*u,w.t+=u,w.t>(w.kind==="wave"?2.2:3.5)||oe(Le(Math.floor(S.x),Math.floor(S.y-.1)))){D.destroy(Y);continue}break;case "boss":bt(D,Y,w,S,pt,u);break;case "coin":Math.hypot(S.x-g.x,S.y-(g.y-g.h/2))<Ye&&Ye>1.21&&(S.x+=(g.x-S.x)*Math.min(1,u*10),S.y+=(g.y-g.h/2-S.y)*Math.min(1,u*10));break;}if(!(!D.isAlive(Y)||!Se(S))){switch(w.kind){case "coin":Et(D,Y);break;case "star":{let l=Number(w.tag);we[l]=true,D.vars.stars=we.filter(Boolean).length,D.emit("star-collected",{index:l}),G(D,{kind:"ring",x:Ze(S.x),y:Ge(S.y-S.h/2),color:"coin",size:ce()*2.4}),G(D,{kind:"flash",color:"coin"}),D.destroy(Y);break}case "heart":$=Math.min(k,$+1),D.vars.lives=$,G(D,{kind:"ring",x:Ze(S.x),y:Ge(S.y-S.h/2),color:"danger",size:ce()*1.6}),D.destroy(Y);break;case "key":ye=true,G(D,{kind:"ring",x:Ze(S.x),y:Ge(S.y-S.h/2),color:"coin",size:ce()*1.6}),D.destroy(Y);break;case "chest":if(ye&&w.tag!=="open"){w.tag="open",ye=false;for(let E=0;E<15;E++)ne+=1+gn(D,"meta:greed"),X++;let l=Math.floor(ne);ne-=l,Je(D,"coins",l),G(D,{kind:"burst",x:Ze(S.x),y:Ge(S.y-S.h/2),color:"coin",n:24,size:ce()*1.4}),G(D,{kind:"pop",x:Ze(S.x),y:Ge(S.y-S.h*1.4),text:"+15",color:"coin",size:Math.round(ce()*.5)});}break;case "spring":f.vy>0&&g.y-(S.y-S.h)<.5&&(f.vy=-Math.sqrt(2*Cn*lu),f.jumps=1,G(D,{kind:"ring",x:Ze(S.x),y:Ge(S.y-S.h),color:"accent",size:ce()*1.4}));break;case "checkpoint":if(w.tag!=="on"){w.tag="on",m={x:S.x,y:S.y};let l=D.need(Y,ie);l.shape==="sprite"&&(l.color="accent"),D.emit("checkpoint",{}),G(D,{kind:"ring",x:Ze(S.x),y:Ge(S.y-S.h/2),color:"accent",size:ce()*2});}break;case "flag":if(be){rt(D,"cleared");return}break;case "walker":case "hopper":case "flyer":case "gunner":case "spiky":case "boss":{let l=f.vy>0&&g.y-(S.y-S.h)<.55&&w.kind!=="spiky";f.dash>0&&w.kind!=="boss"?ut(D,Y,"dash"):l?(f.vy=-ee()*.65,f.jumps=1,w.kind==="boss"?ur(D,Y,"stomp"):ut(D,Y,"stomp")):yt(D,S.x);break}case "bullet":case "wave":yt(D,S.x),D.destroy(Y);break;}if(C||Me())return}}let ze=Pe(),le=Math.max(0,Math.min(Math.max(0,a-ze),g.x-ze*.4+f.facing*ze*.08)),V=p;p+=(le-p)*Math.min(1,u*6),Zo(D,(p-V)*ce()),D.vars.level_progress=Math.min(1,g.x/Math.max(1,a));let te=D.need(i,ie);te.shape==="actor"&&(te.facing=f.facing>=0?1:-1,te.pose=f.grounded?Math.abs(f.vx)>.5?"run":"idle":"air",te.speed=Math.abs(f.vx)*ce(),te.alpha=O>0&&Math.floor(D.time*12)%2===0?.35:1),It(D),Ft(D);}});function ur(D,u,g){let f=D.need(u,mt);f.safe>0||(f.hp--,f.safe=1,Fe(D,u,"hit"),G(D,{kind:"shake",power:1}),f.hp<=0&&(be=true,D.emit(su,{}),ut(D,u,g),ke("flag",a-2,8,.8,2.6)));}function bt(D,u,g,f,b,d){if(g.t-=d,g.vy+=Cn*d,f.y=Math.min(g.baseY,f.y+g.vy*d),f.y>=g.baseY){if(g.tag==="slam-air"){g.tag="walk",g.t=1.6,G(D,{kind:"shake",power:1.4});for(let h of [-1,1]){let v=ke("wave",f.x+h*1.2,g.baseY,.9,.6);v.vx=h*8*n.pace;}}g.vy=0;}if(g.tag==="walk"){if(g.dir=b<f.x?-1:1,f.x+=g.dir*1.4*n.pace*d,g.t<=0){let h=Math.floor(D.rng.next()*3);if(h===0)g.tag="charge",g.t=1.1,g.vx=g.dir*9*n.pace,it(D,u,"run");else if(h===1)g.tag="slam-air",g.vy=-Math.sqrt(2*Cn*4),Fe(D,u,"jump");else {g.tag="walk",g.t=2.4;for(let v of [a-15,a-3])ke("walker",v,g.baseY,.8,1).dir=v<f.x?1:-1;Fe(D,u,"cheer");}}}else g.tag==="charge"&&(f.x+=g.vx*d,(g.t<=0||oe(Le(Math.floor(f.x+Math.sign(g.vx)*1.2),Math.floor(g.baseY-1))))&&(g.tag="walk",g.t=1.8,it(D,u,"walk")));f.x=Math.max(a-17.5,Math.min(a-1.2,f.x));}zt(e,"side",ue()+8*ce()+2),nt();}};var pr=5,La=6,_a=6,Ir={blaster:{id:"blaster",art:"shot",color:"coin",damage:[10,13,15,18,24],cooldown:[.8,.7,.62,.55,.42],count:[1,1,2,2,3],pierce:[1,1,1,2,3]},blades:{id:"blades",art:"blade",color:"primary",damage:[8,10,12,14,19],cooldown:[.45,.42,.4,.38,.32],count:[2,2,3,3,5],reach:[.15,.16,.17,.18,.21]},aura:{id:"aura",art:"aura",color:"secondary",damage:[5,7,9,11,16],cooldown:[.5,.5,.45,.45,.4],count:[1,1,1,1,1],reach:[.11,.125,.14,.155,.19]},boomerang:{id:"boomerang",art:"boomerang",color:"accent",damage:[16,20,24,28,38],cooldown:[1.8,1.6,1.4,1.25,1],count:[1,1,2,2,3],reach:[.34,.36,.38,.4,.46]},lightning:{id:"lightning",art:"lightning",color:"primary",damage:[18,22,26,30,42],cooldown:[2,1.8,1.6,1.4,1.1],count:[2,3,4,5,7],reach:[.22,.23,.24,.25,.3]},drone:{id:"drone",art:"drone",color:"piece6",damage:[9,11,13,15,21],cooldown:[1,.9,.8,.7,.55],count:[1,1,2,2,3],reach:[.11,.11,.12,.12,.13]}},Pn=Object.keys(Ir),bo={might:{id:"might",art:"fist",color:"danger",step:.12},haste:{id:"haste",art:"hourglass",color:"primary",step:.07},area:{id:"area",art:"aura",color:"secondary",step:.1},swift:{id:"swift",art:"boot",color:"accent",step:.08},vigor:{id:"vigor",art:"heart",color:"danger",step:20},armor:{id:"armor",art:"shield",color:"muted",step:1.5},magnet:{id:"magnet",art:"magnet",color:"danger",step:.3},luck:{id:"luck",art:"clover",color:"accent",step:.2},growth:{id:"growth",art:"crystal",color:"accent",step:.1}},Ra=Object.keys(bo),tn={swarm:{kind:"swarm",cast:"foe5",hp:.6,speed:118,size:.045,damage:5,xp:1,from:0,weight:3},grunt:{kind:"grunt",cast:"foe",hp:1,speed:95,size:.055,damage:8,xp:1,from:0,weight:4},archer:{kind:"archer",cast:"foe3",hp:1.2,speed:88,size:.055,damage:7,xp:2,from:.8,weight:2},brute:{kind:"brute",cast:"foe2",hp:5,speed:62,size:.085,damage:14,xp:5,from:1.6,weight:1.2},charger:{kind:"charger",cast:"foe4",hp:2.5,speed:80,size:.065,damage:12,xp:3,from:2.4,weight:1.4},bomber:{kind:"bomber",cast:"foe5",hp:1.5,speed:120,size:.055,damage:16,xp:2,from:3.2,weight:1.4},miniboss:{kind:"miniboss",cast:"boss",hp:45,speed:75,size:.12,damage:18,xp:25,from:99,weight:0},boss:{kind:"boss",cast:"boss",hp:160,speed:70,size:.16,damage:24,xp:0,from:99,weight:0}},of=["swarm","grunt","archer","brute","charger","bomber"],Aa=10;function xo(e,t){let r=Math.max(1,Math.min(Aa,Math.floor(e)));return {chapter:r,duration:Math.min(600,t+(r-1)*30),hp:1+(r-1)*.45,damage:1+(r-1)*.12,headStart:(r-1)*.4,firstClearGold:100+(r-1)*60}}var ko=[{id:"hero",cast:"hero",weapon:"blaster",passive:null,gems:0},{id:"hero2",cast:"hero2",weapon:"blades",passive:"vigor",gems:150},{id:"hero3",cast:"hero3",weapon:"lightning",passive:"area",gems:300}],Pl=[{id:"Might",var:"meta:might",art:"fist",color:"danger",perLevel:4,unit:"%",maxLevel:50,price:30,growth:.09},{id:"Vitality",var:"meta:hp",art:"heart",color:"danger",perLevel:8,unit:"",maxLevel:50,price:25,growth:.09},{id:"Armor",var:"meta:armor",art:"shield",color:"muted",perLevel:.5,unit:"",maxLevel:30,price:40,growth:.1},{id:"Swiftness",var:"meta:speed",art:"boot",color:"accent",perLevel:2,unit:"%",maxLevel:25,price:35,growth:.1},{id:"Magnet",var:"meta:magnet",art:"magnet",color:"danger",perLevel:6,unit:"%",maxLevel:25,price:20,growth:.1},{id:"Luck",var:"meta:luck",art:"clover",color:"accent",perLevel:5,unit:"%",maxLevel:25,price:30,growth:.1},{id:"Growth",var:"meta:growth",art:"crystal",color:"accent",perLevel:3,unit:"%",maxLevel:30,price:30,growth:.1},{id:"Recovery",var:"meta:regen",art:"potion",color:"accent",perLevel:.1,unit:"",maxLevel:30,price:45,growth:.1}],Il="kit-survivors",sf=30,af=10,lf={game:"survivors",character:Il,stats:Pl,heroes:ko,levels:Aa,firstClearGold:e=>xo(e,300).firstClearGold,stars:0};var Da=ve("survivors.hero"),je=ve("survivors.foe"),zn=ve("survivors.shot"),nn=ve("survivors.bullet"),ir=ve("survivors.drop"),bn=ve("survivors.blade"),In=ve("survivors.aura"),Nn=ve("survivors.drone"),ds=ve("survivors.boomerang"),fs=ve("survivors.zap"),vo=ve("survivors.halo"),cf=ve("survivors.hud"),xn=ve("survivors.joystick"),Nl="level-up",zl="upgrade-picked",Bl="upgrade-pick",Hl="upgrade-reroll";var Oa="boss-spawned",Wl="boss-defeated",jl=e=>[...Object.entries(e.weapons).map(([t,r])=>`w:${t}:${r}`),...Object.entries(e.passives).map(([t,r])=>`p:${t}:${r}`)].join(","),df=e=>{let t={},r={};for(let o of String(e??"").split(",")){let[n,s,a]=o.split(":");n==="w"&&s&&s in Ir?t[s]=Number(a):n==="p"&&s&&s in bo&&(r[s]=Number(a));}return {weapons:t,passives:r}},Vl=e=>e.map(t=>`${t.kind}:${t.id}:${t.level}`).join(","),ff=e=>String(e??"").split(",").filter(Boolean).map(t=>{let[r,o,n]=t.split(":");return {kind:r,id:o??"",level:Number(n??1)}}),Ta=e=>e.vars.reviving===true,rn=(e,t)=>{let r=Number(e.vars[t]??0);return Number.isFinite(r)?r:0},Ca={id:"survivors",version:2,engines:["phaser"],requires:["round"],params:{duration:{type:"number",default:300,min:20,max:900},heroSpeed:{type:"number",default:260,min:80,max:800},hp:{type:"number",default:100,min:10,max:2e3},spawnRate:{type:"number",default:1.2,min:.1,max:10},spawnGrowth:{type:"number",default:.9,min:0,max:10},foeHp:{type:"number",default:10,min:1,max:1e3},foeHpGrowth:{type:"number",default:.45,min:0,max:5},foeDamage:{type:"number",default:1,min:.1,max:10},foeSpeed:{type:"number",default:1,min:.3,max:3},damage:{type:"number",default:1,min:.1,max:100},shotSpeed:{type:"number",default:640,min:100,max:2e3},xpFirst:{type:"number",default:4,min:1,max:100,integer:true},xpGrowth:{type:"number",default:1.25,min:1,max:2},coinRate:{type:"number",default:.25,min:0,max:1},killScore:{type:"number",default:10,min:0,max:1e3,integer:true},bossScore:{type:"number",default:500,min:0,max:1e5,integer:true},clearBonus:{type:"number",default:1e3,min:0,max:1e5,integer:true},graceTime:{type:"number",default:.6,min:0,max:5},maxFoes:{type:"number",default:46,min:5,max:160,integer:true},minibossEvery:{type:"number",default:120,min:0,max:900},eliteEvery:{type:"number",default:50,min:0,max:900}},setup({world:e,params:t,mode:r}){let o=e.rng.stream("survivors"),n=Jn(e),s=l=>yr(t,l),a=null,i=null,p=0,m={},$={},k={},O=0,C=0,z=0,F=1,ne=0,X=0,ye=[],be="level",fe=0,we=0,de=0,Re=false,Ce=0,Me=0,ce=300,ue=xo(1,300),Pe=false,Le=null,oe=0,Ee=0,tt=0,Ne=0,se=null,ke=0,_e=0,Te=false,Be=new Map,ee={maxHp:100,hp:100,regen:0,armor:0,speed:260,magnet:80,might:1,haste:1,area:1,luck:1,growth:1},Ie=()=>Math.min(He(e).w,He(e).h),nt=()=>Ie()/720,ht=()=>Ie()*.07,Ae=()=>{let l=He(e);return {x:l.w/2,y:l.h/2}},Gt=()=>{let l=T=>$[T]??0,E=ee.maxHp;ee.might=(1+rn(e,"meta:might")+.12*l("might"))*s("damage"),ee.haste=Math.max(.4,1-.07*l("haste")),ee.area=1+.1*l("area"),ee.speed=s("heroSpeed")*nt()*(1+rn(e,"meta:speed")+.08*l("swift")),ee.maxHp=s("hp")+rn(e,"meta:hp")+20*l("vigor"),ee.regen=rn(e,"meta:regen")+.3*l("vigor"),ee.armor=rn(e,"meta:armor")+1.5*l("armor"),ee.magnet=Ie()*.12*(1+rn(e,"meta:magnet")+.3*l("magnet")),ee.luck=1+rn(e,"meta:luck")+.2*l("luck"),ee.growth=1+rn(e,"meta:growth")+.1*l("growth"),ee.maxHp>E&&(ee.hp+=ee.maxHp-E),ee.hp=Math.min(ee.hp,ee.maxHp),e.vars.survivors_build=jl({weapons:m,passives:$});},Xe=l=>Math.ceil(s("xpFirst")*Math.pow(l,s("xpGrowth"))),rt=()=>ko.find(l=>l.id===e.vars["meta:hero"])??ko[0],lt=()=>{let l=Ae(),E=ht();(a===null||!e.isAlive(a))&&(a=e.create(),e.set(a,Da,{size:E})),e.need(a,Da).size=E,e.set(a,K,{x:l.x,y:l.y}),e.set(a,ie,{shape:"actor",cast:rt().cast,h:E*2.3,feet:E*.6,pose:"idle",depth:er(e,l.y)});},ft=(l,E,T,c)=>{let y=Be.get(l);(y===void 0||!e.isAlive(y))&&(y=e.create(),e.set(y,cf,{id:l}),Be.set(l,y)),e.set(y,K,{x:E,y:T}),e.set(y,ie,c);},yt=l=>{let E=Be.get(l);E!==void 0&&e.destroy(E),Be.delete(l);},ut=()=>{for(let l of Be.values())e.destroy(l);Be.clear(),dt(e,cf);},Et=(l,E,T,c,y,R,L,M=41)=>{let x=Math.max(0,Math.min(1,Math.round(R*100)/100));ft(`${l}:bg`,E,T,{shape:"rect",w:c,h:y,color:"#000000",alpha:.45,radius:y/2,depth:M});let _=Math.max(0,(c-4)*x);_<1?yt(`${l}:fill`):ft(`${l}:fill`,E-(c-4)/2+_/2,T,{shape:"rect",w:_,h:y-4,color:L,radius:(y-4)/2,depth:M+.01});},Ze=l=>{let E=He(l),T=Ie(),c=E.h*.085,y=E.w*.9,R=Math.max(10,T*.026);Et("xp",E.w/2,c,y,R,z/Xe(F),"accent"),ft("lv",E.w/2+y/2-T*.04,c+R*1.6,{shape:"text",text:`Lv ${F}`,size:Math.round(T*.032),color:"text",bold:true,depth:42});let L=c+T*.075;if(Le!==null&&l.isAlive(Le)&&l.has(Le,je)){let U=l.need(Le,je);Et("boss",E.w/2,L,E.w*.62,Math.max(14,T*.034),U.hp/U.maxHp,"danger"),ft("time",E.w/2,L-T*.05,{shape:"text",text:U.kind==="boss"?"BOSS":"MINI BOSS",size:Math.round(T*.036),color:"danger",bold:true,depth:42}),l.vars.boss_hp=U.hp/U.maxHp;}else yt("boss:bg"),yt("boss:fill"),ft("time",E.w/2,L,{shape:"text",text:Vs(Number(l.vars.time_left??0)),size:Math.round(T*.05),color:"text",bold:true,depth:42}),l.vars.boss_hp=0;let M=Math.round(T*.036);ft("kills:i",E.w*.06,L,{shape:"sprite",art:"skull",w:M*1.1,h:M*1.1,color:"text",depth:42}),ft("kills",E.w*.06+M*.75+String(we).length*M*.28,L,{shape:"text",text:String(we),size:M,color:"text",bold:true,depth:42});let x=T*.05,_=0,I=new Set,P=(U,me,he,xe,ge,Ke)=>{I.add(U),ft(`b:${U}`,ge,Ke,{shape:"sprite",art:me,w:x,h:x,color:he,alpha:.95,depth:41}),ft(`b:${U}:l`,ge+x*.38,Ke+x*.36,{shape:"text",text:xe>=5?"\u2605":String(xe),size:Math.round(x*.42),color:xe>=5?"coin":"text",bold:true,depth:42});};for(let[U,me]of Object.entries(m)){let he=Ir[U];P(U,he.art,he.color,me??1,E.w*.06+_*x*1.12,L+T*.075),_++;}_=0;for(let[U,me]of Object.entries($)){let he=bo[U];P(U,he.art,he.color,me??1,E.w*.06+_*x*.95,L+T*.075+x*1.1),_++;}for(let U of [...Be.keys()])if(U.startsWith("b:")){let me=U.slice(2).replace(/:l$/,"");I.has(me)||yt(U);}let H=ht(),re=Ae();Et("hp",re.x,re.y+H*1.05,H*1.7,Math.max(7,T*.013),ee.hp/ee.maxHp,ee.hp/ee.maxHp>.35?"accent":"danger",40);},Ge=(l=-1)=>{let E=He(e),T=Ie()*.08,c=l>=0?l:o.int(0,3);return {x:c===0?-T:c===1?E.w+T:o.range(-T,E.w+T),y:c===2?-T:c===3?E.h+T:o.range(-T,E.h+T)}},It=()=>s("foeHp")*ue.hp*(1+s("foeHpGrowth")*(Me/60)),Qe=(l,E,T=false)=>{let c=tn[l],y=l==="boss"||l==="miniboss",R=Ie()*c.size*(T?1.3:1),L=It()*c.hp*(T?8:1),M=Ct(e,E.x,E.y,{shape:"actor",cast:c.cast,variant:o.int(0,99),h:R*(y?1.9:l==="brute"?1.75:2.2),feet:R*.6,pose:l==="brute"||y?"walk":"run",depth:er(e,E.y)},{type:je,data:{kind:l,hp:L,maxHp:L,speed:c.speed*nt()*s("foeSpeed")*(1+Math.min(.5,Me/600)),size:R,damage:c.damage*ue.damage*s("foeDamage")*(T?1.4:1),xp:c.xp*(T?5:1),elite:T,t:o.range(0,1.5),phase:"walk",vx:0,vy:0,hurtAt:{},next:0}});return (T||y)&&Ct(e,E.x,E.y+R*.5,{shape:"sprite",art:"aura_field",w:R*2.2,h:R*1.1,color:y?"danger":"coin",alpha:.85,depth:2},{type:vo,data:{of:M}}),M},Kt=()=>{let l=Me/60+ue.headStart,E=Sr(r,"foes",of),T=E.filter(L=>tn[L].from<=l),c=T.length>0?T:[E.reduce((L,M)=>tn[L].from<=tn[M].from?L:M)],y=0;for(let L of c)y+=tn[L].weight;let R=o.range(0,y);for(let L of c)if(R-=tn[L].weight,R<=0)return L;return c[0]??"grunt"},Yt=()=>e.query(je).length,Ft=(l,E)=>{let T=Me/60+ue.headStart,c=s("spawnRate")*(1+s("spawnGrowth")*T);for(ke>0&&(ke-=E,c*=.25),Pe&&(c*=.45),se&&(se.left-=E,c*=2.6),Ce+=E*c;Ce>=1;)Ce-=1,!(Yt()>=s("maxFoes"))&&Qe(Kt(),Ge(se?se.side:-1));if(se&&se.left<=0&&(se=null),!Pe){if(Me>=tt){tt=Me+o.range(26,36);let y=Ne++%3;if(y===0){let R=Ae(),L=12+Math.min(12,Math.floor(T*2)),M=Ie()*.62;for(let x=0;x<L;x++){let _=x/L*Math.PI*2;Qe(T>3?"grunt":"swarm",{x:R.x+Math.cos(_)*M,y:R.y+Math.sin(_)*M*1.25});}G(l,{kind:"flash",color:"danger"});}else y===1?se={left:4,side:o.int(0,3)}:ke=5;}if(s("eliteEvery")>0&&Me>=Ee){Ee=Me+s("eliteEvery");let y=Kt();Qe(y==="swarm"?"grunt":y,Ge(),true);}s("minibossEvery")>0&&Me>=oe&&ce-Me>30&&(oe=Me+s("minibossEvery"),(Le===null||!l.isAlive(Le))&&(Le=Qe("miniboss",Ge()),l.emit(Oa,{kind:"miniboss"}),G(l,{kind:"shake",power:1.2})));}},ur=l=>{Pe=true,l.vars.time_left=0;let E=Ae();for(let T of l.query(je)){let c=l.get(T,je);if(!c||c.kind==="miniboss")continue;let y=l.need(T,K);Math.hypot(y.x-E.x,y.y-E.y)<Ie()*.3&&D(l,T,null,false);}Le=Qe("boss",{x:E.x,y:E.y-He(l).h*.42}),G(l,{kind:"shake",power:2}),G(l,{kind:"flash",color:"danger"}),l.emit(Oa,{kind:"boss"});},bt=(l,E,T,c=1)=>{let y=ht(),R=l==="xp"?{shape:"sprite",art:"crystal",w:y*(c>=25?.62:c>=5?.5:.38),h:y*(c>=25?.62:c>=5?.5:.38),color:c>=25?"secondary":c>=5?"primary":"accent",depth:3}:l==="coin"?{shape:"sprite",art:"coin",w:y*.4,h:y*.4,depth:3}:l==="food"?{shape:"sprite",art:"heart",w:y*.5,h:y*.5,depth:3}:l==="magnet"?{shape:"sprite",art:"magnet",w:y*.6,h:y*.6,depth:3}:l==="bomb"?{shape:"sprite",art:"bomb",w:y*.6,h:y*.6,depth:3}:{shape:"sprite",art:"chest",w:y*.9,h:y*.9,color:"coin",depth:3};Ct(e,E,T,R,{type:ir,data:{kind:l,value:c,pulled:false}});},D=(l,E,T,c=true)=>{let y=l.get(E,je);if(!y)return;let R=l.need(E,K),L=R.x,M=R.y;l.remove(E,je);for(let I of l.query(vo))l.need(I,vo).of===E&&l.destroy(I);it(l,E,"die");let x=l.need(E,ie);if(x.shape==="actor"&&(x.depth=er(l,M)-.2),_n(l,E,1.4),G(l,{kind:"burst",x:L,y:M,color:"danger",n:y.elite||y.kind==="boss"?22:8,size:y.size*1.4}),!c)return;we+=1,l.vars.kills=we,l.emit("enemy-defeated",{kind:y.kind,elite:y.elite,by:T});let _=ht();if(y.xp>0&&bt("xp",L,M+y.size*.4,y.xp),o.chance(Math.min(.95,s("coinRate")*ee.luck))&&bt("coin",L+_*.3,M+y.size*.4),o.chance(.012*ee.luck)&&bt("food",L-_*.3,M),o.chance(.004)&&!l.query(ir).some(I=>l.need(I,ir).kind==="magnet")&&bt("magnet",L,M-_*.3),o.chance(.004)&&bt("bomb",L,M-_*.3),y.elite||y.kind==="miniboss"){bt("chest",L,M);for(let I=0;I<3;I++)bt("coin",L+o.range(-_,_),M+o.range(-_,_));}if(y.kind==="bomber"){let I=Ie()*.11*ee.area;G(l,{kind:"ring",x:L,y:M,color:"piece6",size:I*2});for(let P of l.query(je)){let H=l.need(P,K);Math.hypot(H.x-L,H.y-M)<I&&u(l,P,It()*2.5,"blast");}}if((y.kind==="miniboss"||y.kind==="boss")&&(de+=1,l.vars.bosses=de,E===Le&&(Le=null),l.emit(Wl,{kind:y.kind}),G(l,{kind:"shake",power:2}),y.kind==="boss")){for(let I of l.query(je))D(l,I,null,false);h(l,"cleared");}},u=(l,E,T,c)=>{if(!l.has(E,je))return;let y=l.need(E,je);if(y.hp-=T,(y.elite||y.kind==="boss"||y.kind==="miniboss")&&_e>0){_e-=1;let R=l.need(E,K);G(l,{kind:"pop",x:R.x+o.range(-10,10),y:R.y-y.size,text:String(Math.round(T)),color:"text",size:Math.round(Ie()*.03)});}y.hp<=0?D(l,E,c):y.kind!=="boss"&&y.kind!=="miniboss"&&Fe(l,E,"hit");},g=(l,E,T,c,y)=>{let R=l.get(E,je);if(!R||R.kind==="boss"||R.kind==="miniboss"||R.phase==="dash")return;let L=l.need(E,K),M=L.x-T,x=L.y-c,_=Math.hypot(M,x)||1;L.x+=M/_*y,L.y+=x/_*y;},f=(l,E)=>{if(fe>0||a===null)return;let T=Math.max(1,E-ee.armor);ee.hp-=T,fe=s("graceTime"),l.vars.hp=Math.max(0,Math.ceil(ee.hp)),l.emit("player-hit",{hp:l.vars.hp}),Fe(l,a,"hit"),G(l,{kind:"flash",color:"danger"}),G(l,{kind:"shake",power:.8});let c=Ae();G(l,{kind:"pop",x:c.x,y:c.y-ht()*1.4,text:`-${Math.round(T)}`,color:"danger",size:Math.round(Ie()*.034)}),ee.hp<=0&&b(l);},b=l=>{if(l.vars.revive_ready===true&&!Re){l.vars.reviving=true,Bt(l),i=null,l.emit(tr,{});return}h(l,"died");},d=l=>{if(l.vars.reviving!==true)return;Re=true,l.vars.reviving=false,ee.hp=ee.maxHp,l.vars.hp=Math.ceil(ee.hp),fe=2.5;let E=Ae();for(let T of l.query(je)){let c=l.need(T,K);if(Math.hypot(c.x-E.x,c.y-E.y)<Ie()*.4){let y=l.get(T,je);if(!y)continue;y.kind==="boss"||y.kind==="miniboss"?g(l,T,E.x,E.y,Ie()*.2):D(l,T,"revive");}}for(let T of l.query(nn))l.destroy(T);G(l,{kind:"ring",x:E.x,y:E.y,color:"coin",size:Ie()*.8}),G(l,{kind:"flash",color:"coin"}),a!==null&&it(l,a,"idle");},h=(l,E)=>{if(!st(l)||Te)return;Te=true;let T=Math.floor(Me);E==="cleared"&&l.vars["meta:first_clear"]===true&&Je(l,"coins",ue.firstClearGold),l.vars.score=we*s("killScore")+T*5+de*s("bossScore")+(E==="cleared"?s("clearBonus")*ue.chapter:0),l.vars.choosing=false,l.vars.reviving=false,l.emit(Xt,{reason:E,stats:{kills:we,seconds:T,bosses:de,chapter:ue.chapter,level:F,cleared:E==="cleared"}});},v=Sr(r,"weapons",Pn),A=()=>{let l=[],E=Object.keys(m).length,T=Object.keys($).length;for(let y of Pn){let R=m[y];R!==void 0&&R<5?l.push({o:{kind:"weapon",id:y,level:R+1},weight:3}):R===void 0&&E<6&&v.includes(y)&&l.push({o:{kind:"weapon",id:y,level:1},weight:1.6});}for(let y of Ra){let R=$[y];R!==void 0&&R<5?l.push({o:{kind:"passive",id:y,level:R+1},weight:2}):R===void 0&&T<6&&l.push({o:{kind:"passive",id:y,level:1},weight:1.2});}let c=[];for(;c.length<3&&l.length>0;){let y=0;for(let M of l)y+=M.weight;let R=o.range(0,y),L=0;for(;L<l.length-1&&(R-=l[L].weight,!(R<=0));L++);c.push(l[L].o),l.splice(L,1);}return c.length<3&&c.push({kind:"heal",id:"heal",level:1}),c.length<3&&c.push({kind:"gold",id:"gold",level:1}),c},N=(l,E)=>{ye=A(),be=E,l.vars.choosing=true,l.vars.survivors_offer=Vl(ye),Bt(l),i=null,dt(l,xn);let T=Ae();G(l,{kind:"ring",x:T.x,y:T.y,color:E==="chest"?"coin":"accent",size:Ie()*.5}),l.emit(Nl,{level:F,source:E,options:ye,build:{weapons:{...m},passives:{...$}}});},B=l=>{l.vars.choosing===true||!st(l)||(ne>0?(ne-=1,N(l,"level")):X>0&&(X-=1,N(l,"chest")));},Q=(l,E)=>{E.kind==="weapon"?(m[E.id]=E.level,k[E.id]=0):E.kind==="passive"?$[E.id]=E.level:E.kind==="heal"?ee.hp=Math.min(ee.maxHp,ee.hp+ee.maxHp*.3):E.kind==="gold"&&Je(l,"coins",10),Gt(),l.vars.hp=Math.ceil(ee.hp),$e(l);},J=(l,E)=>{if(l.vars.choosing!==true)return;let T=ye[E];T&&(Q(l,T),ye=[],l.vars.choosing=false,l.vars.survivors_offer="",l.emit(zl,{kind:T.kind,id:T.id,level:T.level,source:be}),B(l));},$e=l=>{let E=Ae(),T=Ie(),c=m.blades,y=c?Ir.blades.count[c-1]:0,R=l.query(bn);for(let P of R)l.need(P,bn).index>=y&&l.destroy(P);for(let P=0;P<y;P++)R.some(H=>l.isAlive(H)&&l.need(H,bn).index===P)||Ct(l,E.x,E.y,{shape:"sprite",art:"blade",w:T*.075,h:T*.075,color:"primary",depth:31},{type:bn,data:{index:P}});for(let P of l.query(bn)){let H=l.need(P,ie);H.shape==="sprite"&&(H.w=H.h=T*(c===5?.095:.075)*Math.sqrt(ee.area));}let L=m.aura,M=l.query(In);if(L){let P=T*Ir.aura.reach[L-1]*ee.area;M.length===0&&Ct(l,E.x,E.y,{shape:"sprite",art:"aura_field",w:P*2,h:P*2,color:L===5?"coin":"secondary",alpha:.9,depth:1.5},{type:In,data:{r:P}});for(let H of l.query(In)){l.need(H,In).r=P;let re=l.need(H,ie);re.shape==="sprite"&&(re.w=re.h=P*2,re.color=L===5?"coin":"secondary");}}else for(let P of M)l.destroy(P);let x=m.drone,_=x?Ir.drone.count[x-1]:0,I=l.query(Nn);for(let P of I)l.need(P,Nn).index>=_&&l.destroy(P);for(let P=0;P<_;P++)I.some(H=>l.isAlive(H)&&l.need(H,Nn).index===P)||Ct(l,E.x,E.y,{shape:"sprite",art:"drone",w:T*.06,h:T*.06,color:"piece6",depth:33},{type:Nn,data:{index:P,cd:.3*P}});},Se=(l,E,T,c,y)=>{let R=null,L=c;for(let M of l.query(je)){if(y&&y.includes(M))continue;let x=l.need(M,K),_=Math.hypot(x.x-E,x.y-T);_<L&&(L=_,R=M);}return R},Ye=(l,E,T,c,y,R,L,M,x=1)=>{let _=ht()*x,I=s("shotSpeed")*nt(),P=Ct(l,E,T,{shape:"sprite",art:"shot",w:_*.95,h:_*.48,color:M,depth:30},{type:zn,data:{vx:Math.cos(c)*I,vy:Math.sin(c)*I,life:1.4,damage:y,pierce:R,hit:[],by:L}});l.need(P,K).rotation=c;},pt=(l,E,T)=>{if(a===null)return;let c=Ae(),y=Ie(),R=ht();for(let L of Pn){let M=m[L];if(M===void 0)continue;let x=Ir[L],_=M-1,I=x.damage[_]*ee.might;if(k[L]=(k[L]??0)-E,L==="blaster"&&k[L]<=0){let P=Se(l,c.x,c.y,y*.75);if(P===null){k[L]=0;continue}k[L]=x.cooldown[_]*ee.haste;let H=l.need(P,K),re=Math.atan2(H.y-(c.y-R*.3),H.x-c.x),U=x.count[_];for(let he=0;he<U;he++)Ye(l,c.x,c.y-R*.3,re+(he-(U-1)/2)*.16,I,x.pierce[_],"blaster",M===5?"piece6":"coin",M===5?1.25:1);Fe(l,a,"attack");let me=l.need(a,ie);me.shape==="actor"&&(me.actRate=1/Math.max(.2,x.cooldown[_]*ee.haste),T||(me.facing=H.x>=c.x?1:-1));}else if(L==="blades"){let P=y*x.reach[_]*ee.area,H=3+.35*M;O+=H*E;let re=l.query(bn),U=re.length||1;for(let me of re){let he=l.need(me,bn),xe=O+he.index/U*Math.PI*2,ge=l.need(me,K);ge.x=c.x+Math.cos(xe)*P,ge.y=c.y-R*.2+Math.sin(xe)*P,ge.rotation=O*2.2;let Ke=y*.04*Math.sqrt(ee.area);for(let ot of l.query(je)){let gt=l.get(ot,je);if(!gt)continue;let Ht=l.need(ot,K);Math.hypot(Ht.x-ge.x,Ht.y-ge.y)>Ke+gt.size*.55||l.time-(gt.hurtAt.blades??-9)<x.cooldown[_]||(gt.hurtAt.blades=l.time,u(l,ot,I,"blades"),g(l,ot,c.x,c.y,y*.012));}}}else if(L==="aura"){let P=l.query(In)[0];if(P===void 0)continue;let H=l.need(P,K);if(H.x=c.x,H.y=c.y+R*.3,l.need(P,K).rotation=l.time*.6,k[L]>0)continue;k[L]=x.cooldown[_];let re=l.need(P,In).r;for(let U of l.query(je)){let me=l.need(U,K),he=l.get(U,je);!he||Math.hypot(me.x-c.x,me.y-c.y)>re+he.size*.3||(u(l,U,I,"aura"),g(l,U,c.x,c.y,y*.008));}}else if(L==="boomerang"&&k[L]<=0){let P=Se(l,c.x,c.y,y*.8);if(P===null){k[L]=0;continue}k[L]=x.cooldown[_]*ee.haste;let H=l.need(P,K),re=Math.atan2(H.y-c.y,H.x-c.x),U=x.count[_];for(let me=0;me<U;me++){let he=re+me*Math.PI*2/U,xe=y*(M===5?.085:.065);Ct(l,c.x,c.y,{shape:"sprite",art:"boomerang",w:xe,h:xe,color:"accent",depth:32},{type:ds,data:{dx:Math.cos(he),dy:Math.sin(he),dist:0,range:y*x.reach[_]*ee.area,back:false,damage:I,hit:[]}});}}else if(L==="lightning"&&k[L]<=0){let P=Se(l,c.x,c.y,y*.55);if(P===null){k[L]=0;continue}k[L]=x.cooldown[_]*ee.haste;let H=[],re={x:c.x,y:c.y-R},U=P;for(let me=0;me<x.count[_]&&U!==null;me++){let he=l.get(U,je);if(!he)break;let xe=l.need(U,K),ge={x:xe.x,y:xe.y-he.size*.4};ze(l,re,ge,M===5?"coin":"primary"),H.push(U);let Ke=Se(l,xe.x,xe.y,y*x.reach[_]*ee.area,H);u(l,U,I,"lightning"),re=ge,U=Ke;}}else if(L==="drone"){C+=1.8*E;let P=l.query(Nn),H=P.length||1,re=y*x.reach[_];for(let U of P){let me=l.need(U,Nn),he=C+me.index/H*Math.PI*2,xe=l.need(U,K);if(xe.x=c.x+Math.cos(he)*re,xe.y=c.y-R*1.1+Math.sin(he)*re*.5,me.cd-=E,me.cd>0)continue;let ge=Se(l,xe.x,xe.y,y*.6);if(ge===null){me.cd=0;continue}me.cd=x.cooldown[_]*ee.haste;let Ke=l.need(ge,K);Ye(l,xe.x,xe.y,Math.atan2(Ke.y-xe.y,Ke.x-xe.x),I,M===5?2:1,"drone","piece6",.7);}}}},ze=(l,E,T,c)=>{let y=Math.hypot(T.x-E.x,T.y-E.y),R=Ct(l,(E.x+T.x)/2,(E.y+T.y)/2,{shape:"sprite",art:"zap",w:Math.max(8,y),h:Ie()*.035,color:c,depth:34},{type:fs,data:{life:.16}});l.need(R,K).rotation=Math.atan2(T.y-E.y,T.x-E.x);},le=(l,E)=>{let T=Ae(),c=ht(),y=Ie(),R=He(l),L=Math.hypot(R.w,R.h)*.75,M=l.query(je);for(let _ of M){let I=l.get(_,je);if(!I)continue;let P=l.need(_,K),H=T.x-P.x,re=T.y-P.y,U=Math.hypot(H,re)||1;H/=U,re/=U;let me=I.kind==="boss"||I.kind==="miniboss";if(U>(me?L*1.3:L)){let ot=Ge();P.x=ot.x,P.y=ot.y;continue}I.t-=E;let he=I.speed,xe=H,ge=re;if(I.kind==="archer"){let ot=y*.3;if(U<ot?he*=-0.6:U<ot*1.4&&(he=0),I.t<=0&&U<y*.6){I.t=2.4,Fe(l,_,"attack");let gt=260*nt();Ct(l,P.x,P.y-I.size*.6,{shape:"sprite",art:"orb",w:y*.03,h:y*.03,color:"danger",depth:29},{type:nn,data:{vx:H*gt,vy:re*gt,life:3,damage:I.damage}});}}else (I.kind==="charger"||I.kind==="miniboss"||I.kind==="boss")&&(I.phase==="walk"&&I.t<=0&&U<y*(me?.6:.38)?I.kind!=="boss"||I.next%3===0?(I.phase="wind",I.t=me?.7:.55,Fe(l,_,"surprised"),G(l,{kind:"ring",x:P.x,y:P.y,color:"danger",size:I.size*2.2})):V(l,_,I):I.phase==="wind"?(he=0,I.t<=0&&(I.phase="dash",I.t=me?.6:.45,I.vx=H,I.vy=re)):I.phase==="dash"&&(he=I.speed*(me?4:3.6),xe=I.vx,ge=I.vy,I.t<=0&&(I.phase="walk",I.t=me?I.hp<I.maxHp/2?1.6:2.4:2.8,I.kind==="boss"&&(I.next+=1))));P.x+=xe*he*E,P.y+=ge*he*E;let Ke=l.need(_,ie);if(Ke.shape==="actor"&&(Math.abs(T.x-P.x)>I.size*.4&&(Ke.facing=T.x>=P.x?1:-1),Ke.depth=er(l,P.y),Ke.speed=Math.abs(he),Ke.pose=he===0?"idle":I.kind==="brute"||me?"walk":"run"),U<(I.size+c)/2){if(I.kind==="bomber"){G(l,{kind:"ring",x:P.x,y:P.y,color:"piece6",size:y*.22}),f(l,I.damage),D(l,_,null,false);continue}if(fe<=0&&(Fe(l,_,"attack"),f(l,I.damage),Te||Ta(l)))return}}let x=l.query(je);for(let _=0;_<x.length;_++){let I=l.need(x[_],je),P=l.need(x[_],K);for(let H=_+1;H<x.length;H++){let re=l.need(x[H],je),U=l.need(x[H],K),me=(I.size+re.size)*.42,he=U.x-P.x,xe=U.y-P.y,ge=he*he+xe*xe;if(ge>=me*me||ge===0)continue;let Ke=Math.sqrt(ge),ot=(me-Ke)*.5,gt=he/Ke*ot,Ht=xe/Ke*ot,jr=I.kind==="boss"||I.kind==="miniboss",Dr=re.kind==="boss"||re.kind==="miniboss";jr||(P.x-=gt,P.y-=Ht),Dr||(U.x+=gt,U.y+=Ht);}}for(let _ of l.query(vo)){let I=l.need(_,vo).of;if(!l.isAlive(I)||!l.has(I,je)){l.destroy(_);continue}let P=l.need(I,K),H=l.need(_,K);H.x=P.x,H.y=P.y+l.need(I,je).size*.55;let re=l.need(_,ie);re.shape==="sprite"&&(re.alpha=.6+.3*Math.sin(l.time*6));}},V=(l,E,T)=>{let c=l.need(E,K),y=Ie(),R=T.next%3;if(T.next+=1,T.t=T.hp<T.maxHp/2?1.4:2.2,R===1){let L=T.hp<T.maxHp/2?18:12,M=220*nt();for(let x=0;x<L;x++){let _=x/L*Math.PI*2+l.time;Ct(l,c.x,c.y-T.size*.4,{shape:"sprite",art:"orb",w:y*.035,h:y*.035,color:"danger",depth:29},{type:nn,data:{vx:Math.cos(_)*M,vy:Math.sin(_)*M,life:3.5,damage:T.damage*.6}});}Fe(l,E,"attack"),G(l,{kind:"ring",x:c.x,y:c.y,color:"danger",size:T.size*3});}else {for(let L=0;L<6;L++){let M=L/6*Math.PI*2;Qe("swarm",{x:c.x+Math.cos(M)*T.size*1.6,y:c.y+Math.sin(M)*T.size*1.6});}Fe(l,E,"cheer");}},te=(l,E)=>{let T=He(l),c=Ae(),y=ht(),R=Ie()*.2;for(let M of l.query(zn)){let x=l.need(M,zn),_=l.need(M,K);if(_.x+=x.vx*E,_.y+=x.vy*E,x.life-=E,x.life<=0||_.x<-R||_.y<-R||_.x>T.w+R||_.y>T.h+R){l.destroy(M);continue}for(let I of l.query(je)){if(x.hit.includes(I))continue;let P=l.get(I,je);if(!P)continue;let H=l.need(I,K);if(!(Math.abs(H.x-_.x)>P.size/2+4||Math.abs(H.y-(_.y+P.size*.2))>P.size*.9+4)&&(x.hit.push(I),G(l,{kind:"burst",x:_.x,y:_.y,color:"coin",n:4,size:y*.5}),g(l,I,c.x,c.y,Ie()*.01),u(l,I,x.damage,x.by),x.hit.length>=x.pierce)){l.destroy(M);break}}}for(let M of l.query(nn)){let x=l.need(M,nn),_=l.need(M,K);if(_.x+=x.vx*E,_.y+=x.vy*E,x.life-=E,x.life<=0){l.destroy(M);continue}if(Math.hypot(_.x-c.x,_.y-(c.y-y*.3))<y*.55&&(l.destroy(M),f(l,x.damage),Te||Ta(l)))return}let L=Ie()*1.5;for(let M of l.query(ds)){let x=l.need(M,ds),_=l.need(M,K);if(_.rotation=(_.rotation??0)+E*14,x.back){let P=c.x-_.x,H=c.y-_.y,re=Math.hypot(P,H)||1;if(re<y*.5){l.destroy(M);continue}_.x+=P/re*L*E,_.y+=H/re*L*E;}else {let P=L*E*Math.max(.35,1-x.dist/x.range);_.x+=x.dx*P,_.y+=x.dy*P,x.dist+=P,x.dist>=x.range*.98&&(x.back=true,x.hit=[]);}let I=l.need(M,ie).w*.5;for(let P of l.query(je)){if(x.hit.includes(P))continue;let H=l.get(P,je);if(!H)continue;let re=l.need(P,K);Math.hypot(re.x-_.x,re.y-_.y)>I+H.size*.5||(x.hit.push(P),g(l,P,_.x,_.y,Ie()*.015),u(l,P,x.damage,"boomerang"));}}for(let M of l.query(fs)){let x=l.need(M,fs);x.life-=E;let _=l.need(M,ie);_.shape==="sprite"&&(_.alpha=Math.max(0,x.life/.16)),x.life<=0&&l.destroy(M);}},Y=(l,E)=>{let T=Ae(),c=ht(),R=l.query(ir).filter(L=>l.need(L,ir).kind==="xp");if(R.length>90){let L=R.map(P=>({e:P,d:Math.hypot(l.need(P,K).x-T.x,l.need(P,K).y-T.y)})).sort((P,H)=>H.d-P.d).slice(0,30),M=0,x=l.need(L[0].e,K),_=x.x,I=x.y;for(let P of L)M+=l.need(P.e,ir).value,l.destroy(P.e);bt("xp",_,I,Math.max(25,M));}for(let L of l.query(ir)){let M=l.need(L,ir),x=l.need(L,K),_=Math.hypot(T.x-x.x,T.y-x.y);if(_<ee.magnet||M.pulled){M.pulled=true;let I=Ie()*(M.kind==="xp"&&_>ee.magnet?2.4:1.4),P=Math.min(1,E*I/Math.max(1,_));x.x+=(T.x-x.x)*P,x.y+=(T.y-x.y)*P;}if(!(_>c*.6))if(l.destroy(L),M.kind==="coin")Je(l,"coins",M.value),l.emit("coin-collected",{value:M.value}),G(l,{kind:"pop",x:T.x,y:T.y-c*1.6,text:`+${M.value}`,size:Math.round(c*.45)});else if(M.kind==="xp"){for(z+=M.value*ee.growth;z>=Xe(F);)z-=Xe(F),F+=1,ne+=1;l.vars.xp_level=F;}else if(M.kind==="food")ee.hp=Math.min(ee.maxHp,ee.hp+ee.maxHp*.25),l.vars.hp=Math.ceil(ee.hp),G(l,{kind:"ring",x:T.x,y:T.y,color:"accent",size:c*3});else if(M.kind==="magnet"){for(let I of l.query(ir))(l.need(I,ir).kind==="xp"||l.need(I,ir).kind==="coin")&&(l.need(I,ir).pulled=true);G(l,{kind:"ring",x:T.x,y:T.y,color:"coin",size:Ie()*1.2});}else if(M.kind==="bomb"){let I=He(l);G(l,{kind:"flash",color:"#ffffff"}),G(l,{kind:"shake",power:2});for(let P of l.query(je)){let H=l.need(P,K);if(H.x<0||H.y<0||H.x>I.w||H.y>I.h)continue;let re=l.get(P,je);re&&u(l,P,re.kind==="boss"||re.kind==="miniboss"?re.maxHp*.1:re.hp+1,"bomb");}}else M.kind==="chest"&&(X+=1,G(l,{kind:"burst",x:T.x,y:T.y,color:"coin",n:20,size:c*2}));}B(l);},w=()=>{for(let E of [je,zn,nn,ir,bn,In,Nn,ds,fs,vo,xn])dt(e,E);dt(e,Qn),ut(),zt(e,"top",void 0,{pan:true}),e.vars.field_x=0,e.vars.field_y=0,i=null,p=0,ue=xo(rn(e,"meta:chapter")||1,s("duration")),ce=ue.duration;let l=rt();m={[l.weapon]:1},$=l.passive?{[l.passive]:1}:{};for(let E of Pn)k[E]=.4;z=0,F=1,ne=0,X=0,ye=[],fe=0,we=0,de=0,Re=false,Te=false,Ce=0,Me=0,Pe=false,Le=null,oe=s("minibossEvery")>0?s("minibossEvery"):1/0,Ee=s("eliteEvery")>0?s("eliteEvery")*.8:1/0,tt=22,Ne=0,se=null,ke=0,ee.maxHp=0,ee.hp=0,Gt(),ee.hp=ee.maxHp,e.vars.hp=Math.ceil(ee.hp),e.vars.hp_max=ee.maxHp,e.vars.time_left=ce,e.vars.xp_level=1,e.vars.kills=0,e.vars.bosses=0,e.vars.chapter=ue.chapter,e.vars.choosing=false,e.vars.reviving=false,e.vars.boss_hp=0,e.vars.survivors_offer="",lt(),$e(e);};e.on(Nt,l=>{let E=l,T=e.vars.choosing===true||e.vars.reviving===true;E.type==="press"&&st(e)&&!T?i={x:E.x,y:E.y}:E.type==="release"&&(i=null),E.type==="key"&&e.vars.choosing===true&&(E.key==="left"||E.key==="action"||E.key==="right")&&J(e,E.key==="left"?0:E.key==="action"?1:2);}),e.on(Bl,l=>J(e,Number(l.index??-1))),e.on(Hl,()=>{e.vars.choosing===true&&(e.vars.choosing=false,N(e,be));}),e.on(rr,()=>d(e)),e.on(nr,()=>{e.vars.reviving===true&&(e.vars.reviving=false,h(e,"died"));}),e.on(Ut,w),e.on(Qt,w),e.on(Zt,l=>{for(let E of e.query(je))it(e,E,"idle");a!==null&&e.isAlive(a)&&it(e,a,l.reason==="cleared"?"dance":"die"),ut(),dt(e,xn);}),e.on(qt,()=>{zt(e,"top",void 0,{pan:true}),lt(),st(e)&&$e(e);});let S=(l,E)=>{let T=i!==null&&n.pointer.down&&l.vars.choosing!==true,c=l.query(xn);if(!T||i===null){for(let x of c)l.destroy(x);return}c.length===0&&(Ct(l,i.x,i.y,{shape:"circle",r:E,color:"#ffffff",alpha:.16,depth:70},{type:xn,data:{part:0}}),Ct(l,i.x,i.y,{shape:"circle",r:E*.42,color:"#ffffff",alpha:.55,depth:71},{type:xn,data:{part:1}}));let y=n.pointer.x-i.x,R=n.pointer.y-i.y,L=Math.hypot(y,R)||1,M=Math.min(1,E/L);for(let x of l.query(xn)){let _=l.need(x,K);l.need(x,xn).part===0?(_.x=i.x,_.y=i.y):(_.x=i.x+y*M,_.y=i.y+R*M);}};e.addSystem({id:"survivors",order:0,run(l,E){if(!st(l)||a===null||Te)return;let T=l.vars.choosing===true||l.vars.reviving===true;for(let re of [a,...l.query(je)]){let U=l.get(re,ie);U?.shape==="actor"&&(U.paused=T);}if(T)return;_e=Math.min(12,_e+E*10);let c=He(l);if(Me+=E,!Pe){let re=Math.max(0,ce-Me);l.vars.time_left=re,re<=0&&ur(l);}fe>0&&(fe=Math.max(0,fe-E)),ee.regen>0&&ee.hp<ee.maxHp&&(ee.hp=Math.min(ee.maxHp,ee.hp+ee.regen*E),l.vars.hp=Math.ceil(ee.hp)),l.vars.hp_max=ee.maxHp;let y=Ae(),R=Ie()*.11,L=n.axis(),M=L.x,x=L.y,_=M!==0||x!==0?1:0;if(_===0&&i&&n.pointer.down){M=n.pointer.x-i.x,x=n.pointer.y-i.y;let re=Math.hypot(M,x);_=re<R*.18?0:Math.min(1,re/R);}S(l,R);let I=Math.hypot(M,x),P=I>0&&_>0;if(P){let re=M/I*ee.speed*_*E,U=x/I*ee.speed*_*E;for(let me of [...l.query(je),...l.query(zn),...l.query(nn),...l.query(ir),...l.query(Qn),...l.query(ds),...l.query(fs)]){let he=l.need(me,K);he.x-=re,he.y-=U;}pd(l,re,U),Je(l,"field_x",re),Je(l,"field_y",U),p+=E,p>.6&&Lt(l,"survivors-move");}!vt(l,"survivors-move")&&!_r(l)&&kt(l,"circle",{x:c.w/2,y:c.h*.8},{x:R*.6,y:0});let H=l.need(a,ie);H.alpha=fe>0&&Math.floor(l.time*12)%2===0?.4:1,H.shape==="actor"&&(H.pose=P?"run":"idle",H.speed=ee.speed*Math.max(.3,_),P&&Math.abs(M)>I*.15&&(H.facing=M>0?1:-1),H.depth=er(l,y.y)+5e-4),Ft(l,E),le(l,E),!(Te||Ta(l))&&(pt(l,E,P),te(l,E),!(Te||Ta(l))&&(Y(l,E),!Te&&(l.vars.score=we*s("killScore")+Math.floor(Me)*5+de*s("bossScore"),Ze(l))));}}),e.vars.survivors_base=s("duration"),w();}};var Pa=[{id:"archer",base:{damage:6,type:"physical",range:2.6,rate:1.2,air:true,ground:true,shot:"td_arrow",shotSpeed:13},tiers:[{cost:70,stats:{},art:"td_archer1"},{cost:100,stats:{damage:9,range:2.8,rate:1.35},art:"td_archer2"},{cost:150,stats:{damage:14,range:3,rate:1.5},art:"td_archer3"}],branches:[{id:"ranger",cost:240,stats:{damage:17,rate:2.5,multishot:2,range:3.1},art:"td_archer_ranger"},{id:"sniper",cost:260,stats:{damage:72,rate:.5,range:4.6,pierce:1,crit:.2,shotSpeed:22},art:"td_archer_sniper"}],unlockLevel:1,metaVar:"meta:tower:archer"},{id:"cannon",base:{damage:12,type:"physical",range:2.3,rate:.5,air:false,ground:true,shot:"bomb",shotSpeed:6,lob:true,splash:.9},tiers:[{cost:110,stats:{},art:"td_cannon1"},{cost:150,stats:{damage:22,splash:1},art:"td_cannon2"},{cost:210,stats:{damage:36,splash:1.1,range:2.5},art:"td_cannon3"}],branches:[{id:"bombard",cost:300,stats:{damage:72,splash:1.5,rate:.42,range:2.8,stun:.25,stunTime:.6},art:"td_cannon_bombard"},{id:"flamer",cost:280,stats:{damage:20,splash:1,rate:.9,burn:12,burnTime:3},art:"td_cannon_flamer"}],unlockLevel:1,metaVar:"meta:tower:cannon"},{id:"mage",base:{damage:14,type:"magic",range:2.4,rate:.7,air:true,ground:true,shot:"orb",shotSpeed:9},tiers:[{cost:100,stats:{},art:"td_mage1"},{cost:140,stats:{damage:26},art:"td_mage2"},{cost:200,stats:{damage:42,range:2.6},art:"td_mage3"}],branches:[{id:"arcane",cost:300,stats:{damage:110,type:"true",rate:.55,range:2.9},art:"td_mage_arcane"},{id:"storm",cost:280,stats:{damage:32,rate:.9,chain:4,beam:true,shot:"zap"},art:"td_mage_storm"}],unlockLevel:3,metaVar:"meta:tower:mage"},{id:"frost",base:{damage:3,type:"magic",range:2.2,rate:.8,air:true,ground:true,shot:"crystal",shotSpeed:10,splash:.5,slow:.35,slowTime:1.6},tiers:[{cost:90,stats:{},art:"td_frost1"},{cost:120,stats:{damage:5,slow:.45,slowTime:1.9},art:"td_frost2"},{cost:170,stats:{damage:8,slow:.5,slowTime:2.2,splash:.7,range:2.4},art:"td_frost3"}],branches:[{id:"glacier",cost:260,stats:{damage:14,slow:.6,slowTime:2.6,stun:.15,stunTime:1},art:"td_frost_glacier"},{id:"blizzard",cost:260,stats:{damage:10,splash:1.4,slow:.5,slowTime:2.4,range:2.7},art:"td_frost_blizzard"}],unlockLevel:5,metaVar:"meta:tower:frost"}],Gl=6,ps=.7,zr=e=>Pa.find(t=>t.id===e);function hs(e,t,r){let o=e.base;for(let s=1;s<Math.min(t,e.tiers.length);s++)o={...o,...e.tiers[s].stats};let n=r?e.branches.find(s=>s.id===r):void 0;return n?{...o,...n.stats}:o}function us(e,t,r){let o=0;for(let s=0;s<Math.min(t,e.tiers.length);s++)o+=e.tiers[s].cost;let n=r?e.branches.find(s=>s.id===r):void 0;return o+(n?.cost??0)}var Ia=(e,t,r)=>(r?e.branches.find(o=>o.id===r)?.art:void 0)??e.tiers[Math.min(t,e.tiers.length)-1].art,Bn=[{id:"grunt",cast:"foe",hp:1,speed:1,armor:0,resist:0,bounty:6,leak:1,size:.82,hit:.25,firstLevel:1,cost:1},{id:"runner",cast:"foe5",hp:.55,speed:1.8,armor:0,resist:0,bounty:4,leak:1,size:.72,hit:.15,firstLevel:2,cost:.7},{id:"brute",cast:"foe2",hp:2.6,speed:.7,armor:.6,resist:0,bounty:14,leak:2,size:1,hit:.5,firstLevel:3,cost:2.4,badge:"shield"},{id:"flyer",cast:"foe3",hp:.8,speed:1.2,armor:0,resist:0,flying:true,bounty:8,leak:1,size:.75,hit:0,firstLevel:4,cost:1.3,badge:"wing"},{id:"shaman",cast:"foe4",hp:1.6,speed:.9,armor:0,resist:.7,bounty:12,leak:1,size:.86,hit:.3,firstLevel:6,cost:2,badge:"orb"},{id:"healer",cast:"foe4",variant:7,hp:1.3,speed:.9,armor:.2,resist:.2,bounty:14,leak:1,size:.86,hit:.2,heals:{radius:1.6,share:.08,every:2},firstLevel:8,cost:2.2,badge:"potion"},{id:"splitter",cast:"foe2",variant:5,hp:2,speed:.85,armor:.2,resist:0,bounty:10,leak:2,size:.95,hit:.4,splits:{into:"spawnling",count:3},firstLevel:11,cost:2.6,badge:"skull"},{id:"spawnling",cast:"foe5",variant:3,hp:.35,speed:1.6,armor:0,resist:0,bounty:2,leak:1,size:.55,hit:.1,firstLevel:0,cost:.4},{id:"warlord",cast:"boss",hp:30,speed:.55,armor:.2,resist:0,bounty:120,leak:10,size:1.5,hit:2,summons:{id:"grunt",count:3,every:6},boss:1,firstLevel:0,cost:0},{id:"ironclad",cast:"boss",variant:4,hp:50,speed:.5,armor:.65,resist:0,bounty:160,leak:10,size:1.6,hit:2.5,enrage:{below:.5,speed:1.7},boss:2,firstLevel:0,cost:0,badge:"shield"},{id:"broodmother",cast:"boss",variant:9,hp:62,speed:.5,armor:.2,resist:.3,bounty:200,leak:10,size:1.6,hit:2.5,summons:{id:"spawnling",count:4,every:5},splits:{into:"spawnling",count:8},boss:3,firstLevel:0,cost:0,badge:"skull"},{id:"lich",cast:"boss",variant:13,hp:80,speed:.48,armor:.3,resist:.5,bounty:260,leak:15,size:1.7,hit:3,heals:{radius:2.2,share:.05,every:3},summons:{id:"shaman",count:2,every:7},boss:4,firstLevel:0,cost:0,badge:"orb"}],hr=e=>Bn.find(t=>t.id===e),$o=[{id:"meteor",icon:"td_meteor",kind:"strike",cooldown:35,unlockLevel:2,damage:2.2,count:3,radius:1.1,burn:.3},{id:"reinforce",icon:"shield",kind:"summon",cooldown:22,unlockLevel:4,count:2,cast:"helper",hp:4,dps:.6,time:14}],Br=9,Hr=13,Kl=[{id:"meadow-a",rows:["..S......",".o#o..t..","..#......","..#####o.",".o....#..","..t...#o.",".o#####..","..#..o..t","..#.*....","o.####o..","....o#...",".t...#.o.",".....X..."]},{id:"meadow-b",rows:["......S..",".t..o.#o.","......#..",".o#####..","..#..o...","..#.t..o.","..####...",".o..o#.t.","..*..#...","..####o..",".o#......","..#.o..t.","..X......"]},{id:"meadow-c",rows:[".S.......",".#.o..o..",".#.....#X",".#o.t.o#.",".#.....#.",".#o.o..#.",".#..r..#.",".#.o.o.#o",".#.....#.",".#o.*.o#.",".#######.","..o.o.o..","t.......t"]},{id:"meadow-boss",rows:["....S....","..o.#.o..","....#....",".####.o..",".#..o....",".#.o..t..",".#######.","..o.o..#.",".o.....#o","..######.","..#.o.o..",".o#......","..X......"]},{id:"river-a",rows:[".........","S####.o..",".o..#....","..o.#.~~.","....####.",".o.r...#.","...o...#o",".#######.",".#.o.o...",".#....r..",".####.o..","..o.#....","....X...."]},{id:"river-b",rows:[".S.....S.",".#.o.o.#.",".#..t..#.",".###.###.",".o.#o#.o.","...#.#...","..o###o..","....#....",".o..#.o..","...o#....","..r.#.o..",".o..#..t.","....X...."]},{id:"river-c",rows:["..~~.....","o...####S","..o.#..o.","....#.~~.",".####.~~.",".#..o....",".#.o..r..",".######o.","..o...#..",".~~.o.#..","X######o.","..o.o....","..~~...t."]},{id:"river-boss",rows:[".o.....o.","S##.o.##S","..#.r.#..",".o#####o.","....#....",".o..#.o..",".####..t.",".#..o..o.",".#.o.....",".#######.","..o.o..#.",".o.....#o",".......X."]},{id:"wood-a",rows:["..o...o..","S#######.",".o.....#.","...o.o.#o",".#####.#.",".#.o.#.#.",".#.X.#.#.",".#.###.#.",".#..o..#.",".#######.","..o.o.o..",".t..r..o.","........."]},{id:"wood-b",rows:["...S.....",".o.#..o..","...#.t...",".o.####o.","......#..",".o.o..#o.","......##X",".o.o..#o.","......#..",".o.####o.","...#.r...",".o.#..o..","...S....."]},{id:"wood-c",rows:[".o..o..o.",".#######S",".#.o..o..",".#######.","..o.o..#.",".#######.",".#..o..o.",".#######.","..o..o.#.",".#######.",".#.o..o..",".#..r..t.",".X......."]},{id:"wood-boss",rows:["....X....",".o..#..o.","..o.#....",".####.o..",".#..o..t.",".#.o..o..",".#######.","..o..o.#.",".o.....#.","..######.","..#.o..o.",".o#..r...","..S......"]},{id:"ash-a",rows:["....S....",".o..#..o.","S##.#.##S","..#.#.#..",".o#o#o#o.","..#####..",".o..#..o.","...o#o...",".t..#..t.",".o..#..o.","..r.#.r..",".o..#..o.","....X...."]},{id:"ash-b",rows:[".S.....S.",".#.o.o.#.",".#..o..#.",".###.###.","...#o#...",".o.#.#.o.","...#o#...",".###.###.",".#.o.o.#.",".#.....#.",".#######.","..o.#.o..","....X...."]},{id:"ash-c",rows:[".S.....X.",".#.###.#.",".#o#o#o#.",".#.#.#.#.",".#o#.#o#.",".#.#o#.#.","o#.#.#.#o",".#o#.#o#.",".#.#o#.#.",".#.#.#.#.",".#o#.#o#.",".###.###.","........."]},{id:"ash-boss",rows:[".o.....o.","S#.o.o.#S",".#.....#.",".#o.r.o#.",".#.....#.",".#o.X.o#.",".#..#..#.",".#o.#.o#.",".#..#..#.",".#.o#o.#.",".#######.","..o.o.o..",".t.....t."]}],Na=e=>Kl.find(t=>t.id===e);function Mo(e,t){return t==="x"?e.rows.map(r=>[...r].reverse().join("")):t==="y"?[...e.rows].reverse():e.rows}var du=e=>e==="#"||e==="S"||e==="X";function wo(e){let t=($,k)=>e[k]?.[$],r=null,o=[],n=[];for(let $=0;$<e.length;$++)for(let k=0;k<e[$].length;k++){let O=t(k,$);O==="X"?r={col:k,row:$}:O==="S"?o.push({col:k,row:$}):O==="o"&&n.push({col:k,row:$});}if(!r)throw new Error("tower-defense map: no gate (X)");if(o.length===0)throw new Error("tower-defense map: no entry (S)");let s=new Map,a=($,k)=>`${$},${k}`,i=[r];s.set(a(r.col,r.row),0);let p=[[0,1],[-1,0],[1,0],[0,-1]];for(;i.length>0;){let $=i.shift(),k=s.get(a($.col,$.row));for(let[O,C]of p){let z=$.col+O,F=$.row+C;!du(t(z,F))||s.has(a(z,F))||(s.set(a(z,F),k+1),i.push({col:z,row:F}));}}let m=o.map($=>{if(!s.has(a($.col,$.row)))throw new Error(`tower-defense map: the entry ${$.col},${$.row} has no road to the gate`);let k=[$],O=$;for(;O.col!==r.col||O.row!==r.row;){let C=s.get(a(O.col,O.row)),z=p.map(([F,ne])=>({col:O.col+F,row:O.row+ne})).find(F=>s.get(a(F.col,F.row))===C-1);k.push(z),O=z;}return k});return {rows:e,paths:m,gate:r,spots:n}}var Fl=4,Nr=5,ms=Fl*Nr,ql=[0,9,24,39],Ul=[{map:"meadow-a",mirror:"none"},{map:"meadow-b",mirror:"none"},{map:"meadow-c",mirror:"none"},{map:"meadow-a",mirror:"x"},{map:"meadow-boss",mirror:"none"},{map:"river-a",mirror:"none"},{map:"river-b",mirror:"none"},{map:"river-c",mirror:"none"},{map:"river-a",mirror:"x"},{map:"river-boss",mirror:"none"},{map:"wood-a",mirror:"none"},{map:"wood-b",mirror:"none"},{map:"wood-c",mirror:"none"},{map:"wood-b",mirror:"x"},{map:"wood-boss",mirror:"none"},{map:"ash-a",mirror:"none"},{map:"ash-b",mirror:"none"},{map:"ash-c",mirror:"none"},{map:"ash-a",mirror:"y"},{map:"ash-boss",mirror:"none"}];function fu(e){let t=e>>>0;return ()=>{t=t+1831565813>>>0;let r=t;return r=Math.imul(r^r>>>15,r|1),r^=r+Math.imul(r^r>>>7,r|61),((r^r>>>14)>>>0)/4294967296}}var pf=Bn.filter(e=>e.firstLevel>0).map(e=>e.id);function hf(e,t){let r=Bn.filter(n=>n.firstLevel>0&&n.firstLevel<=e);if(!t)return r;let o=r.filter(n=>t.includes(n.id));return o.length>0?o:r}function uf(e,t){let r=Bn.find(o=>o.firstLevel===e);return r&&(!t||t.includes(r.id))?r:void 0}function Xl(e,t,r){let o=Math.max(1,Math.min(ms,Math.floor(e))),n=fu(o*7919+13),s=hf(o,r),a=uf(o,r),i=Math.ceil(o/Nr),p=o%Nr===0?Bn.find(k=>k.boss===i):void 0,m=6+Math.floor((o-1)/2),$=[];for(let k=1;k<=m;k++){let O=5+k*1.6+o*.35,C=[],z=0,F=0,ne=[];if(k===1)ne.push(s[0]);else {a&&k===2&&ne.push(a);let ye=Math.min(4,1+Math.floor(k/3));for(;ne.length<ye;)ne.push(s[Math.floor(n()*s.length)]);}let X=O/ne.length;for(let ye of ne){let be=Math.max(1,Math.round(X/ye.cost)),fe=ye.speed>=1.5?.55:ye.hp>=2?1.3:.85;C.push({enemy:ye.id,count:be,gap:fe,delay:z,entry:F%Math.max(1,t)}),z+=be*fe*.55+1,F++;}p&&k===m&&C.push({enemy:p.id,count:1,gap:1,delay:z+2,entry:0}),$.push({groups:C});}return $}function Eo(e,t=.5,r){let o=Math.max(1,Math.min(ms,Math.floor(e))),n=Math.ceil(o/Nr),s=o-(n-1)*Nr,a=Ul[o-1],i=wo(Mo(Na(a.map),a.mirror)).paths.length;return {level:o,world:n,index:s,boss:s===Nr,map:a.map,mirror:a.mirror,hp:16*Math.pow(1.075,o-1)*(.8+t*.4),waves:Xl(o,i,r),gold:220+(o-1)*25,bounty:1+(o-1)*.03,towers:Pa.filter(p=>p.unlockLevel<=o).map(p=>p.id),spells:$o.filter(p=>p.unlockLevel<=o).map(p=>p.id),branches:o>=Gl,fresh:uf(o,r)?.id??null,enemies:hf(o,r).map(p=>p.id),firstClearGold:(s===Nr?150:60)+(o-1)*20}}var Zl=e=>ql[Math.ceil(Math.max(1,e)/Nr)-1]??0,za=(e,t)=>e>=t*.9?3:e>=t*.5?2:1,Ba=5,mf=20,So=[{id:"hero",cast:"hero",gems:0,perk:"none"},{id:"hero2",cast:"hero2",gems:150,perk:"gold"},{id:"hero3",cast:"hero3",gems:300,perk:"spells"}],Ql="kit-td",Yl=[{id:"StartGold",var:"meta:start_gold",art:"td_gold",color:"coin",perLevel:20,unit:"",maxLevel:10,price:40,growth:.12},{id:"Lives",var:"meta:lives",art:"heart",color:"danger",perLevel:1,unit:"",maxLevel:5,price:120,growth:.2},{id:"Archer",var:"meta:tower:archer",art:"td_archer1",color:"primary",perLevel:6,unit:"%",maxLevel:10,price:40,growth:.12},{id:"Cannon",var:"meta:tower:cannon",art:"td_cannon1",color:"primary",perLevel:6,unit:"%",maxLevel:10,price:40,growth:.12},{id:"Mage",var:"meta:tower:mage",art:"td_mage1",color:"primary",perLevel:6,unit:"%",maxLevel:10,price:45,growth:.12},{id:"Frost",var:"meta:tower:frost",art:"td_frost1",color:"primary",perLevel:6,unit:"%",maxLevel:10,price:45,growth:.12},{id:"Spells",var:"meta:spells",art:"td_meteor",color:"danger",perLevel:8,unit:"%",maxLevel:10,price:50,growth:.12}],yf={game:"tower-defense",character:Ql,stats:Yl,heroes:So,levels:ms,firstClearGold:e=>Eo(e).firstClearGold,stars:3,starsToEnter:Zl};var pu="boss-spawned",hu="boss-defeated",ec="wave-started",ja=ve("td.spot"),kr=ve("td.tower"),De=ve("td.raider"),Hn=ve("td.missile"),Ar=ve("td.soldier"),Ha=ve("td.meteor"),gf=ve("td.ground"),Jl=ve("td.part"),bf=ve("td.bar"),Wa=ve("td.zap"),ys=(e,t)=>{let r=Number(e.vars[t]??0);return Number.isFinite(r)?r:0},uu=.5,mu=.55,Va={id:"tower-defense",version:2,engines:["phaser"],requires:["round"],params:{difficulty:{type:"number",default:.5,min:0,max:1},lives:{type:"number",default:20,min:1,max:100,integer:true},gold:{type:"number",default:0,min:0,max:1e5,integer:true},wavePause:{type:"number",default:14,min:2,max:60},firstWait:{type:"number",default:25,min:1,max:600},earlyGold:{type:"number",default:2,min:0,max:100},coinRate:{type:"number",default:.15,min:0,max:1}},setup({world:e,params:t,mode:r}){let o=c=>yr(t,c),n=e.rng.stream("tower-defense"),s=Sr(r,"foes",pf),a=Eo(1,o("difficulty"),s),i=wo(Mo(Na(a.map),a.mirror)),p=[],m=Ne(),$=0,k=20,O=20,C=0,z=[],F=0,ne=null,X=0,ye=0,be=0,fe=false,we=false,de=1,Re=null,Ce=[],Me=null,ce=new Map,ue=[],Pe=null,Le=new Map,oe=new Map,Ee=()=>So.find(c=>c.id===e.vars["meta:hero"])??So[0],tt=()=>e.vars.reviving===true;function Ne(){return un(He(e),Br,Hr,{top:.15,bottom:.86,widthShare:.98})}let se=()=>m.cell,ke=c=>m.left+c*m.cell,_e=c=>m.top+c*m.cell,Te=c=>({x:ke(c.col+.5),y:_e(c.row+.5)}),Be=(c,y)=>({x:(c-m.left)/m.cell,y:(y-m.top)/m.cell}),ee=c=>c.row===0?{x:c.col+.5,y:-0.5}:c.row===Hr-1?{x:c.col+.5,y:Hr+.5}:c.col===0?{x:-0.5,y:c.row+.5}:c.col===Br-1?{x:Br+.5,y:c.row+.5}:null,Ie=()=>{p=i.paths.map(c=>{let y=c.map(L=>({x:L.col+.5,y:L.row+.5})),R=ee(c[0]);return R&&y.unshift(R),{pts:y,len:y.length-1}});},nt=(c,y)=>{if(y<=0)return c.pts[0];if(y>=c.len)return c.pts[c.len];let R=Math.floor(y),L=c.pts[R],M=c.pts[R+1],x=y-R;return {x:L.x+(M.x-L.x)*x,y:L.y+(M.y-L.y)*x}},ht=new Set,Ae=(c,y,R,L,M=1)=>{ht.add(c);let x=Le.get(c);(x===void 0||!e.isAlive(x))&&(x=e.create(),e.set(x,Jl,{id:c}),Le.set(c,x)),e.set(x,K,{x:y,y:R,scale:M}),e.set(x,ie,L);},Gt=c=>{for(let[y,R]of [...Le])ht.has(y)||!c.some(L=>y.startsWith(L))||(e.destroy(R),Le.delete(y));},Xe=c=>{for(let[y,R]of [...Le])y.startsWith(c)&&(e.destroy(R),Le.delete(y));},rt=(c,y,R,L)=>{let M=e.create();return e.set(M,gf,{kind:c}),e.set(M,K,{x:y,y:R}),e.set(M,ie,L),M},lt=()=>{dt(e,gf),dt(e,ja);let c=se();rt("grass",ke(Br/2),_e(Hr/2),{shape:"tile",art:"tile_grass",w:c*Br,h:c*Hr,unit:c,color:"ground",depth:-10}),i.rows.forEach((_,I)=>[..._].forEach((P,H)=>{let re=Te({col:H,row:I}),U=re.y+c*.45;P==="#"||P==="S"||P==="X"?rt("road",re.x,re.y,{shape:"sprite",art:"tile_road",w:c+1,h:c+1,color:"lane",depth:-9}):P==="~"?rt("water",re.x,re.y,{shape:"rect",w:c+1,h:c+1,color:"primary",alpha:.45,depth:-9}):P==="t"?rt("tree",re.x,U-c*.65,{shape:"sprite",art:"td_tree",w:c*1.05,h:c*1.3,depth:er(e,U,5)}):P==="r"?rt("rock",re.x,U-c*.3,{shape:"sprite",art:"rock",w:c*.8,h:c*.6,depth:er(e,U,5)}):P==="*"&&rt("bush",re.x,U-c*.3,{shape:"sprite",art:"td_bush",w:c*.85,h:c*.6,depth:er(e,U,5)});})),i.spots.forEach((_,I)=>{let P=Te(_),H=rt("spot",P.x,P.y+c*.18,{shape:"sprite",art:"td_spot",w:c*.95,h:c*.62,depth:-8});e.set(H,ja,{index:I,col:_.col,row:_.row});});let y=Te(i.gate),R=ee(i.gate),L=R&&R.y>=0?R:null,M=L?ke(i.gate.col+.5+(L.x-(i.gate.col+.5))*.35):y.x,x=L?_e(i.gate.row+.5+(L.y-(i.gate.row+.5))*.35):y.y;rt("gate",M,x-c*.2,{shape:"sprite",art:"td_gate",w:c*1.35,h:c*1.35,depth:er(e,x+c*.45,5)});for(let _ of i.paths){if(ee(_[0]))continue;let I=Te(_[0]);rt("portal",I.x,I.y-c*.1,{shape:"sprite",art:"td_portal",w:c*1.05,h:c*.95,depth:er(e,I.y,4)});}},ft=c=>e.query(kr).find(y=>e.need(y,kr).spot===c),yt=c=>{let y=e.need(c,kr),R=zr(y.kind),L=Te(i.spots[y.spot]),M=se(),x=M*1.45,_=L.y+M*.42;e.set(c,K,{x:L.x,y:_-x/2}),e.set(c,ie,{shape:"sprite",art:Ia(R,y.tier,y.branch||null),w:M*1.1,h:x,depth:er(e,_,5)});},ut=c=>{$=Math.max(0,Math.round(c)),e.vars.gold=$;},Et=(c,y)=>{let R=Te(i.spots[c]);G(e,{kind:"ring",x:R.x,y:R.y,color:y,size:se()*1.5}),G(e,{kind:"burst",x:R.x,y:R.y-se()*.4,color:y,n:10,size:se()});},Ze=(c,y)=>{let R=zr(y);if(!R||ft(c)!==void 0)return false;let L=R.tiers[0].cost;if($<L)return false;ut($-L);let M=e.create();return e.set(M,kr,{spot:c,kind:y,tier:1,branch:"",cooldown:.2}),yt(M),Et(c,"text"),e.emit("tower-built",{kind:y}),vt(e,"td-build")||(Lt(e,"td-build"),te()),true},Ge=(c,y)=>{let R=ft(c);if(R===void 0)return false;let L=e.need(R,kr),M=zr(L.kind),x;if(y){let _=M.branches.find(I=>I.id===y);if(!_||L.branch||L.tier<M.tiers.length||!a.branches)return false;x=_.cost;}else {if(L.tier>=M.tiers.length)return false;x=M.tiers[L.tier].cost;}return $<x?false:(ut($-x),y?L.branch=y:L.tier++,yt(R),Et(c,"coin"),e.emit("tower-upgraded",{kind:L.kind,tier:L.tier,branch:L.branch}),true)},It=c=>{let y=ft(c);if(y===void 0)return false;let R=e.need(y,kr),L=Math.floor(us(zr(R.kind),R.tier,R.branch||null)*ps);ut($+L);let M=Te(i.spots[c]);return G(e,{kind:"pop",x:M.x,y:M.y-se()*.8,text:`+${L}`,color:"coin",size:Math.round(se()*.3)}),G(e,{kind:"burst",x:M.x,y:M.y,color:"muted",n:12,size:se()}),e.destroy(y),e.emit("tower-sold",{kind:R.kind}),true},Qe=()=>{Re=null,Ce=[],Xe("m:"),e.vars.td_menu="";},Kt=c=>c.map(y=>`${y.action??y.id}@${Math.round(y.x)},${Math.round(y.y)}`).join(";"),Yt=c=>{Qe(),Re=c,Ft();},Ft=()=>{if(Re===null)return;let c=Re;Ce=[];let y=se(),R=He(e),L=Math.min(R.w,R.h),M=Math.max(y*.46,L*.062),x=Math.max(y*1.1,M*2.3),_=Te(i.spots[c]),I=Math.max(x+M,Math.min(R.w-x-M,_.x)),P=Math.max(R.h*.1+x+M,Math.min(R.h*.88-x-M,_.y-y*.2)),H=(ge,Ke,ot,gt,Ht,jr,Dr)=>{let $r=I+Ke*x,ln=P+ot*x;Ce.push({action:ge,x:$r,y:ln,r:M,ok:Dr}),e.vars.td_menu=Kt(Ce),Ae(`m:${ge}:bg`,$r,ln,{shape:"circle",r:M,color:"panel",alpha:.94,depth:60});let Vn=ge==="sell";Ae(`m:${ge}:rim`,$r,ln,{shape:"circle",r:M*1.08,color:Vn?"danger":Dr?"coin":"muted",alpha:Dr?.9:.5,depth:59.9}),Ae(`m:${ge}:art`,$r,ln-M*.12,{shape:"sprite",art:gt,w:Vn?M*1.25:M*1.15,h:Vn?M*1.25:M*1.3,alpha:Dr?1:.45,depth:60.1}),jr&&Ae(`m:${ge}:txt`,$r,ln+M*.78,{shape:"text",text:jr,size:Math.round(M*.52),color:Ht!==null&&!Dr?"danger":"coin",bold:true,depth:60.2});},re=ft(c);if(re===void 0){let ge=a.towers.map(ot=>zr(ot)).filter(Boolean),Ke=ge.length<=1?[[0,-1]]:ge.length===2?[[-0.8,-0.7],[.8,-0.7]]:ge.length===3?[[-0.85,-0.6],[.85,-0.6],[0,.9]]:[[-0.8,-0.75],[.8,-0.75],[-0.8,.75],[.8,.75]];ge.slice(0,4).forEach((ot,gt)=>{let Ht=ot.tiers[0].cost;H(`build:${ot.id}`,Ke[gt][0],Ke[gt][1],ot.tiers[0].art,Ht,String(Ht),$>=Ht);});return}let U=e.need(re,kr),me=zr(U.kind),he=hs(me,U.tier,U.branch||null);if(Ae("m:range",_.x,_.y,{shape:"sprite",art:"aura_field",w:he.range*y*2,h:he.range*y*2,color:"primary",alpha:.4,depth:1}),U.tier<me.tiers.length){let ge=me.tiers[U.tier];H("up",0,-1,ge.art,ge.cost,String(ge.cost),$>=ge.cost);}else !U.branch&&a.branches&&me.branches.slice(0,2).forEach((ge,Ke)=>H(`branch:${ge.id}`,Ke===0?-0.85:.85,-0.7,ge.art,ge.cost,String(ge.cost),$>=ge.cost));let xe=Math.floor(us(me,U.tier,U.branch||null)*ps);H("sell",0,1,"td_sell",null,`+${xe}`,true);},ur=c=>{if(Re===null)return;let y=Re,R=false;if(c.startsWith("build:")?R=Ze(y,c.slice(6)):c==="up"?R=Ge(y):c.startsWith("branch:")?R=Ge(y,c.slice(7)):c==="sell"&&(R=It(y)),!R){G(e,{kind:"shake",power:.3});return}Qe();},bt=(c,y)=>{let R=se(),L=-1,M=1/0;return i.spots.forEach((x,_)=>{let I=Te(x),P=ft(_)!==void 0?I.y-R*1.1:I.y-R*.5;if(Math.abs(c-I.x)>R*.55||y<P||y>I.y+R*.55)return;let H=Math.abs(c-I.x)+Math.abs(y-I.y);H<M&&(M=H,L=_);}),L},D=c=>1+.07*(c-1),u=(c,y,R,L)=>{let M=hr(c);if(!M||p.length===0)return null;let x=M.hp*a.hp*(M.boss?1:D(L)),_=e.create();return e.set(_,De,{kind:c,hp:x,maxHp:x,route:y%p.length,progress:R,x:0,y:0,slow:0,slowLeft:0,stun:0,burn:0,burnLeft:0,healCd:M.heals?.every??0,summonCd:M.summons?.every??0,heldBy:-1,enraged:false,wave:L}),e.set(_,K,{x:0,y:0}),e.set(_,ie,{shape:"actor",cast:M.cast,variant:M.variant??n.int(0,99),h:se()*M.size*1.15,pose:M.flying?"air":"walk",depth:6}),g(_),M.boss&&(e.emit(pu,{kind:c}),G(e,{kind:"shake",power:1})),_},g=c=>{let y=e.need(c,De),R=hr(y.kind),L=p[y.route],M=nt(L,y.progress),x=nt(L,y.progress+.05);y.x=M.x,y.y=M.y;let _=se(),I=e.need(c,K),P=e.need(c,ie),H=_e(M.y)+_*.2;if(I.x=ke(M.x),I.y=H-(R.flying?_*.55:0)-(P.shape==="actor"?P.h/2:0),P.shape==="actor"){Math.abs(x.x-M.x)>1e-4&&(P.facing=x.x>M.x?1:-1),P.depth=er(e,H,5),P.h=_*R.size*1.15;let re=y.heldBy<0&&y.stun<=0;P.pose=R.flying?"air":re?"walk":"idle",P.speed=R.speed*(1-y.slow)*_*de;}},f=c=>p[c.route].len-c.progress,b=c=>{let y=e.need(c,K);return {x:y.x,y:y.y}},d=(c,y,R,L,M=1,x="tower")=>{let _=e.get(c,De);if(!_)return;let I=hr(_.kind),P=y.damage*R*M*(L?2:1);if(y.type==="physical"?P*=1-I.armor*(1-(y.pierce??0)):y.type==="magic"&&(P*=1-I.resist),y.slow&&(_.slow=Math.max(_.slow,y.slow*(I.boss?.5:1)),_.slowLeft=Math.max(_.slowLeft,(y.slowTime??1)*R)),y.burn&&(_.burn=Math.max(_.burn,y.burn*R),_.burnLeft=Math.max(_.burnLeft,y.burnTime??2)),y.stun&&!I.boss&&n.chance(y.stun)&&(_.stun=Math.max(_.stun,y.stunTime??.5)),L){let H=b(c);G(e,{kind:"pop",x:H.x,y:H.y-se()*.5,text:String(Math.round(P)),color:"danger",size:Math.round(se()*.3)});}h(c,P,x);},h=(c,y,R)=>{let L=e.get(c,De);L&&(L.hp-=y,L.hp<=0&&v(c,R));},v=(c,y)=>{let R=e.need(c,De),L=hr(R.kind);e.remove(c,De),it(e,c,"die"),_n(e,c,1),ye++;let M=Math.round(L.bounty*a.bounty);ut($+M);let x=b(c);if(G(e,{kind:"pop",x:x.x,y:x.y-se()*.6,text:`+${M}`,color:"coin",size:Math.round(se()*.28)}),e.emit("enemy-defeated",{kind:R.kind,by:y}),L.boss?(be++,Je(e,"coins",10),e.emit(hu,{kind:R.kind}),G(e,{kind:"shake",power:1.4}),G(e,{kind:"flash",color:"coin"})):n.chance(o("coinRate"))&&(Je(e,"coins",1),e.emit("coin-collected",{value:1})),L.splits)for(let _=0;_<L.splits.count;_++)u(L.splits.into,R.route,Math.max(0,R.progress-.18*_),R.wave);},A=c=>{let y=e.need(c,De),R=hr(y.kind),L=Te(i.gate);G(e,{kind:"burst",x:L.x,y:L.y,color:"danger",n:12,size:se()}),e.destroy(c),k=Math.max(0,k-R.leak),e.vars.lives=k,e.emit("player-hit",{lives:k}),G(e,{kind:"flash",color:"danger"}),G(e,{kind:"shake",power:R.boss?1.6:.8}),k<=0&&J();},N=()=>{if(!(C>=a.waves.length)){C++,e.vars.wave=C,z=[];for(let c of a.waves[C-1].groups)for(let y=0;y<c.count;y++)z.push({at:c.delay+y*c.gap,enemy:c.enemy,entry:c.entry});z.sort((c,y)=>c.at-y.at),F=0,ne=null,e.emit(ec,{wave:C});}},B=()=>{if(!(ne===null||C>=a.waves.length)){if(C>0){let c=Math.ceil(ne*o("earlyGold")*a.bounty);if(c>0){ut($+c);let y=ue.find(R=>R.id.startsWith("call"));y&&G(e,{kind:"pop",x:y.x,y:y.y-se()*.6,text:`+${c}`,color:"coin",size:Math.round(se()*.32)});}}Lt(e,"td-call"),N();}},Q=c=>{if(fe||!st(e))return;fe=true;let y=c==="defended",R=y?Math.min(we?1:3,za(k,O)):0;e.vars.stars=R,y&&e.vars["meta:first_clear"]===true&&Je(e,"coins",a.firstClearGold),e.vars.score=Se()+(y?1e3+R*300:0),e.vars.reviving=false,Qe(),e.emit(Xt,{reason:c,stats:{chapter:a.level,seconds:Math.floor(X),cleared:y,stars:R,coins:Number(e.vars.coins??0),bosses:be,kills:ye,lives:k}});},J=()=>{if(e.vars.revive_ready===true&&!we){e.vars.reviving=true,Qe(),e.emit(tr,{});return}Q("overrun");},$e=()=>{if(tt()){we=true,e.vars.reviving=false,k=Ba,e.vars.lives=k;for(let c of e.query(De))e.need(c,De).stun=2;G(e,{kind:"flash",color:"coin"});}},Se=()=>ye*10+k*50+Math.max(0,C-1)*100,Ye=()=>1+ys(e,"meta:spells"),pt=(c,y,R)=>{let L=$o.find(_=>_.id===c);if(!L||(ce.get(c)??0)>0)return;let M=Be(y,R);if(M.x<-0.5||M.y<-0.5||M.x>Br+.5||M.y>Hr+.5)return;if(L.kind==="strike")for(let _=0;_<(L.count??1);_++){let I=e.create(),P=(L.radius??1)*.9;e.set(I,Ha,{x:M.x+(_===0?0:(n.next()-.5)*P*2),y:M.y+(_===0?0:(n.next()-.5)*P*2),t:0,delay:_*.2,damage:(L.damage??1)*a.hp*Ye(),radius:L.radius??1,burn:(L.burn??0)*a.hp*Ye()}),e.set(I,K,{x:-999,y:-999}),e.set(I,ie,{shape:"sprite",art:"td_meteor",w:se()*.9,h:se()*.9,alpha:0,depth:45});}else {let _={route:0,q:0,d:1/0};p.forEach((P,H)=>{for(let re=.5;re<=P.len-.5;re+=.25){let U=nt(P,re),me=Math.hypot(U.x-M.x,U.y-M.y);me<_.d&&(_={route:H,q:re,d:me});}});let I=L.count??1;for(let P=0;P<I;P++){let H=e.create(),re=(L.hp??3)*a.hp*Ye();e.set(H,Ar,{hp:re,maxHp:re,dps:(L.dps??.5)*a.hp*Ye(),left:L.time??12,route:_.route,progress:Math.max(.3,Math.min(p[_.route].len-.3,_.q+(P-(I-1)/2)*.45)),swing:0}),e.set(H,K,{x:0,y:0}),e.set(H,ie,{shape:"actor",cast:L.cast??"helper",variant:n.int(0,99),h:se()*.85,pose:"idle",depth:6}),ze(H);let U=e.need(H,K);G(e,{kind:"ring",x:U.x,y:U.y,color:"accent",size:se()*1.2});}}let x=L.cooldown*(Ee().perk==="spells"?.7:1);ce.set(c,x),Me=null,Pe!==null&&e.isAlive(Pe)&&Fe(e,Pe,"attack"),e.emit("spell-cast",{id:c});},ze=c=>{let y=e.need(c,Ar),R=p[y.route],L=nt(R,y.progress),M=nt(R,y.progress-.2),x=se(),_=e.need(c,K),I=e.need(c,ie),P=_e(L.y)+x*.2;_.x=ke(L.x),_.y=P-(I.shape==="actor"?I.h/2:0),I.shape==="actor"&&(Math.abs(M.x-L.x)>1e-4&&(I.facing=M.x>L.x?1:-1),I.depth=er(e,P,5),I.h=x*.85);},le=()=>{(Pe===null||!e.isAlive(Pe))&&(Pe=e.create());let c=se(),y=i.gate,R=[[1,0],[-1,0],[0,-1],[0,1]].map(([x,_])=>({col:y.col+x,row:y.row+_})).find(x=>x.col>=0&&x.row>=0&&x.col<Br&&x.row<Hr&&".tr*".includes(i.rows[x.row][x.col]))??y,L=Te(R),M=L.y+c*.35;e.set(Pe,K,{x:L.x,y:M-c*.6}),e.set(Pe,ie,{shape:"actor",cast:Ee().cast,h:c*1.2,pose:"idle",facing:R.col>y.col?-1:1,depth:er(e,M,5)});},V=()=>{if(vt(e,"td-build")||i.spots.length===0)return;let c=p[0],y=nt(c,c.len*.4),R=0,L=1/0;i.spots.forEach((M,x)=>{let _=Math.hypot(M.col+.5-y.x,M.row+.5-y.y);_<L&&(L=_,R=x);}),kt(e,"tap",Te(i.spots[R]),void 0,se()*1.2);},te=()=>{if(vt(e,"td-call")||C>0)return;let c=Te(i.paths[0][0]);kt(e,"tap",c,void 0,se()*1.2);},Y=()=>{let c=He(e),y=Math.min(c.w,c.h),R=se(),L=c.h*.085,M=y*.05,x=(U,me,he,xe,ge="text",Ke=y*.042)=>Ae(U,me,he,{shape:"text",text:xe,size:Math.round(Ke),color:ge,bold:true,depth:70});Ae("h:lives:i",c.w*.07,L,{shape:"sprite",art:"heart",w:M,h:M,depth:70}),x("h:lives",c.w*.15,L,String(k),k<=5?"danger":"text"),Ae("h:gold:i",c.w*.3,L,{shape:"sprite",art:"td_gold",w:M*1.15,h:M,depth:70}),x("h:gold",c.w*.4,L,String($),"coin"),Ae("h:wave:i",c.w*.56,L,{shape:"sprite",art:"td_call",w:M,h:M,depth:70}),x("h:wave",c.w*.66,L,`${C}/${a.waves.length}`),Ae("h:coin:i",c.w*.8,L,{shape:"sprite",art:"coin",w:M*.9,h:M*.9,depth:70}),x("h:coin",c.w*.89,L,String(e.vars.coins??0));let _=c.h*.125,I=e.query(De).find(U=>hr(e.need(U,De).kind)?.boss);if(I!==void 0){let U=e.need(I,De),me=c.w*.55,he=Math.max(10,y*.022);Ae("h:n:boss:bg",c.w/2,_,{shape:"rect",w:me,h:he,color:"#000000",alpha:.5,radius:he/2,depth:69});let xe=Math.max(1,(me-4)*Math.max(0,U.hp/U.maxHp));Ae("h:n:boss:fill",c.w/2-(me-4)/2+xe/2,_,{shape:"rect",w:xe,h:he-4,color:"danger",radius:(he-4)/2,depth:69.1}),Ae("h:n:boss:i",c.w/2-me/2-M*.7,_,{shape:"sprite",art:"skull",w:M,h:M,depth:70});}else if(ne!==null&&C<a.waves.length){let U=new Map;for(let ge of a.waves[C].groups)U.set(ge.enemy,(U.get(ge.enemy)??0)+ge.count);let me=[...U].slice(0,5),he=y*.15,xe=c.w/2-(me.length-1)*he/2;me.forEach(([ge,Ke],ot)=>{let gt=hr(ge),Ht=xe+ot*he;Ae(`h:n:${ge}:a`,Ht-M*.4,_+M*.1,{shape:"actor",cast:gt.cast,variant:gt.variant??1,h:M*1.5*Math.min(1.3,gt.size+.25),pose:gt.flying?"air":"idle",depth:70}),x(`h:n:${ge}:t`,Ht+M*.55,_+M*.1,`\xD7${Ke}`,gt.boss?"danger":"text",y*.034);});}if(ue=[],ne!==null&&C<a.waves.length){let U=C===0?1+.08*Math.sin(e.time*6):1;i.paths.forEach((me,he)=>{let xe=Te(me[0]),ge=R*.42;ue.push({id:`call:${he}`,x:xe.x,y:xe.y,r:ge*1.2}),Ae(`b:call:${he}:bg`,xe.x,xe.y,{shape:"circle",r:ge,color:"danger",alpha:.92,depth:65},U),Ae(`b:call:${he}:i`,xe.x,xe.y,{shape:"sprite",art:"td_call",w:ge*1.3,h:ge*1.3,depth:65.1},U),Ae(`b:call:${he}:t`,xe.x,xe.y+ge*1.25,{shape:"text",text:String(Math.ceil(ne??0)),size:Math.round(R*.26),color:"text",bold:true,depth:65.2});});}let P=c.h*.925,H=y*.065;$o.filter(U=>a.spells.includes(U.id)).forEach((U,me)=>{let he=c.w*.12+me*H*2.6,xe=ce.get(U.id)??0;ue.push({id:`spell:${U.id}`,x:he,y:P,r:H*1.15}),Me===U.id&&Ae(`b:s:${U.id}:rim`,he,P,{shape:"circle",r:H*1.18,color:"coin",alpha:.6+.4*Math.sin(e.time*8),depth:64.9}),Ae(`b:s:${U.id}:bg`,he,P,{shape:"circle",r:H,color:"panel",alpha:.92,depth:65}),Ae(`b:s:${U.id}:i`,he,P,{shape:"sprite",art:U.icon,w:H*1.25,h:H*1.25,alpha:xe>0?.4:1,depth:65.1}),xe>0&&Ae(`b:s:${U.id}:t`,he,P,{shape:"text",text:String(Math.ceil(xe)),size:Math.round(H*.8),color:"text",bold:true,depth:65.2});});let re=c.w*.88;ue.push({id:"speed",x:re,y:P,r:H*1.15}),Ae("b:speed:bg",re,P,{shape:"circle",r:H,color:de>1?"coin":"panel",alpha:.92,depth:65}),e.vars.td_buttons=Kt(ue),Ae("b:speed:t",re,P,{shape:"text",text:`x${de}`,size:Math.round(H*.75),color:de>1?"panel":"text",bold:true,depth:65.1});},w=()=>{let c=se(),y=new Set,R=(L,M,x,_,I)=>{y.add(L);let P=oe.get(L);if(!P){P=[e.create(),e.create(),e.create(),e.create(),e.create()];for(let[Ht,jr]of P.entries())e.set(jr,bf,{of:L,part:String(Ht)});oe.set(L,P);}let H=e.need(L,K),re=e.need(L,ie),U=re.shape==="actor"?re.h:c,me=H.y-U/2-c*.08,he=Math.min(He(e).w,He(e).h),xe=Math.max(c*.62,he*.065),ge=Math.max(5,xe*.13),Ke=M<.999;e.set(P[0],K,{x:H.x,y:me}),e.set(P[0],ie,{shape:"rect",w:xe,h:ge,color:"#000000",alpha:Ke?.55:0,radius:ge/2,depth:30});let ot=Math.max(1,(xe-2)*Math.max(0,M));e.set(P[1],K,{x:H.x-(xe-2)/2+ot/2,y:me}),e.set(P[1],ie,{shape:"rect",w:ot,h:ge-2,color:x,alpha:Ke?1:0,radius:(ge-2)/2,depth:30.1}),e.set(P[2],K,{x:H.x-xe/2-c*.12,y:me}),e.set(P[2],ie,{shape:"sprite",art:_??"shield",w:c*.24,h:c*.24,alpha:_?1:0,depth:30.2});let gt=H.y+U/2;e.set(P[3],K,{x:H.x,y:gt}),e.set(P[3],ie,{shape:"sprite",art:"aura_field",w:c*.75,h:c*.32,color:"primary",alpha:I?.slow?.75:0,depth:2}),e.set(P[4],K,{x:H.x,y:H.y}),e.set(P[4],ie,{shape:"sprite",art:"burst",w:c*.45,h:c*.45,color:"danger",alpha:I?.burn?.5+.4*Math.sin(e.time*20):0,depth:29});};for(let L of e.query(De)){let M=e.need(L,De);R(L,M.hp/M.maxHp,"danger",hr(M.kind)?.badge,{slow:M.slowLeft>0,burn:M.burnLeft>0});}for(let L of e.query(Ar)){let M=e.need(L,Ar);R(L,M.hp/M.maxHp,"accent",void 0,null);}for(let[L,M]of [...oe])if(!y.has(L)){for(let x of M)e.destroy(x);oe.delete(L);}},S=()=>{for(let c of [kr,De,Hn,Ar,Ha,Wa,bf,Jl])dt(e,c);Le.clear(),oe.clear();for(let c of e.query(ie))e.need(c,ie).shape==="actor"&&c!==Pe&&!e.has(c,Jl)&&e.destroy(c);},l=()=>{S(),a=Eo(ys(e,"meta:chapter")||1,o("difficulty"),s),i=wo(Mo(Na(a.map),a.mirror)),Ie(),zt(e,"top"),m=Ne(),lt(),$=0,ut((a.gold+o("gold")+ys(e,"meta:start_gold"))*(Ee().perk==="gold"?1.25:1)),O=o("lives")+ys(e,"meta:lives"),k=O,C=0,z=[],F=0,ne=o("firstWait"),X=0,ye=0,be=0,fe=false,we=false,de=1,Re=null,Ce=[],Me=null,ce.clear(),ue=[],e.vars.lives=k,e.vars.wave=0,e.vars.waves=a.waves.length,e.vars.td_level=a.level,e.vars.td_world=a.world,e.vars.coins=0,e.vars.score=0,e.vars.stars=0,e.vars.reviving=false,e.vars.td_speed=1,e.vars.level_progress=0,le();},E=c=>{if(c.startsWith("call"))B();else if(c==="speed")de=de>1?1:2,e.vars.td_speed=de;else if(c.startsWith("spell:")){let y=c.slice(6);Me===y?Me=null:(ce.get(y)??0)<=0&&(Me=y,Qe());}};e.on(Nt,c=>{let y=c;if(y.type!=="tap"||!st(e)||hn(e)||fe||tt())return;if(Re!==null){let M=Ce.find(x=>Math.hypot(y.x-x.x,y.y-x.y)<=x.r);if(M){ur(M.action);return}Qe();}let R=ue.find(M=>Math.hypot(y.x-M.x,y.y-M.y)<=M.r);if(R){E(R.id);return}if(Me!==null){pt(Me,y.x,y.y);return}let L=bt(y.x,y.y);L>=0&&(vt(e,"td-build")||Bt(e),Yt(L));}),e.on(Ut,()=>{l(),e.vars.level=a.level,V();}),e.on(Qt,l),e.on(rr,$e),e.on(nr,()=>{tt()&&(e.vars.reviving=false,Q("overrun"));}),e.on(Zt,c=>{Qe(),Xe("b:"),ue=[],Pe!==null&&e.isAlive(Pe)&&it(e,Pe,c.reason==="defended"?"dance":"die");for(let y of e.query(De))it(e,y,"idle");}),e.on(qt,()=>{zt(e,"top"),m=Ne(),lt();for(let c of e.query(kr))yt(c);dt(e,Hn),Re!==null&&Ft(),le();}),e.addSystem({id:"tower-defense",order:0,run(c,y){if(!st(c)||fe||tt())return;let R=y*de;X+=y;let L=se();for(let[M,x]of ce)x>0&&ce.set(M,Math.max(0,x-R));if(z.length>0){for(F+=R;z.length>0&&z[0].at<=F;){let M=z.shift();u(M.enemy,M.entry,0,C);}z.length===0&&C<a.waves.length&&(ne=o("wavePause"));}else ne!==null&&(ne-=R,ne<=0&&N());for(let M of c.query(Ar)){let x=c.need(M,Ar);if(x.left-=R,x.left<=0||x.hp<=0){c.remove(M,Ar),it(c,M,"die"),_n(c,M,.8);for(let P of c.query(De))c.need(P,De).heldBy===M&&(c.need(P,De).heldBy=-1);continue}let _=nt(p[x.route],x.progress),I=c.query(De).filter(P=>c.need(P,De).heldBy===M);if(I.length<2){let P=c.query(De).filter(H=>{let re=c.need(H,De),U=hr(re.kind);return re.heldBy<0&&!U.flying&&!U.boss&&Math.hypot(re.x-_.x,re.y-_.y)<=mu}).slice(0,2-I.length);for(let H of P)c.need(H,De).heldBy=M,I.push(H);}I.length>0&&(h(I[0],x.dps*R,"soldier"),x.swing-=R,x.swing<=0&&(Fe(c,M,"attack"),x.swing=.6)),ze(M);}for(let M of c.query(De)){let x=c.get(M,De);if(!x)continue;let _=hr(x.kind);if(!(x.burnLeft>0&&(x.burnLeft-=R,h(M,x.burn*R,"burn"),!c.has(M,De)))){if(x.slowLeft>0&&(x.slowLeft-=R,x.slowLeft<=0&&(x.slow=0)),x.stun>0&&(x.stun-=R),_.heals&&(x.healCd-=R,x.healCd<=0)){x.healCd=_.heals.every;for(let P of c.query(De)){let H=c.need(P,De);Math.hypot(H.x-x.x,H.y-x.y)>_.heals.radius||(H.hp=Math.min(H.maxHp,H.hp+H.maxHp*_.heals.share));}let I=b(M);G(c,{kind:"ring",x:I.x,y:I.y,color:"accent",size:_.heals.radius*L*2});}if(_.summons&&(x.summonCd-=R,x.summonCd<=0)){x.summonCd=_.summons.every;for(let I=0;I<_.summons.count;I++)u(_.summons.id,x.route,Math.max(0,x.progress-.45*(I+1)),x.wave);Fe(c,M,"cheer");}if(_.enrage&&!x.enraged&&x.hp<x.maxHp*_.enrage.below){x.enraged=true;let I=b(M);G(c,{kind:"ring",x:I.x,y:I.y,color:"danger",size:L*2});}if(x.heldBy>=0&&!c.has(x.heldBy,Ar)&&(x.heldBy=-1),x.heldBy<0&&x.stun<=0&&(x.progress+=_.speed*(1-x.slow)*(x.enraged&&_.enrage?_.enrage.speed:1)*R),x.progress>=p[x.route].len){if(A(M),fe||tt())return;continue}g(M);}}for(let M of c.query(kr)){let x=c.need(M,kr);if(x.cooldown-=R,x.cooldown>0)continue;let _=zr(x.kind),I=hs(_,x.tier,x.branch||null),P=1+ys(c,_.metaVar),H=i.spots[x.spot],re=H.col+.5,U=H.row+.5,me=c.query(De).filter(xe=>{let ge=c.need(xe,De);return (hr(ge.kind).flying?I.air:I.ground)&&ge.progress>0&&Math.hypot(ge.x-re,ge.y-U)<=I.range}).sort((xe,ge)=>f(c.need(xe,De))-f(c.need(ge,De))).slice(0,I.multishot??1);if(me.length===0){x.cooldown=0;continue}x.cooldown=1/I.rate;let he={x:ke(re),y:_e(U)-L*.75};for(let xe of me){let ge=I.crit!==void 0&&n.chance(I.crit);if(I.beam){let jr=[],Dr=he,$r=xe,ln=1;for(let Vn=0;Vn<=(I.chain??0)&&$r!==void 0;Vn++){let Tc=b($r);T(Dr,Tc,I.type==="magic"?"secondary":"primary"),jr.push($r);let Gn=c.need($r,De),sp=c.query(De).filter(Kn=>!jr.includes(Kn)&&Math.hypot(c.need(Kn,De).x-Gn.x,c.need(Kn,De).y-Gn.y)<=1.6).sort((Kn,Dc)=>Math.hypot(c.need(Kn,De).x-Gn.x,c.need(Kn,De).y-Gn.y)-Math.hypot(c.need(Dc,De).x-Gn.x,c.need(Dc,De).y-Gn.y))[0];d($r,I,P,ge,ln),Dr=Tc,$r=sp,ln*=.7;}continue}let Ke=b(xe),ot=c.create(),gt=Math.max(1,Math.hypot(Ke.x-he.x,Ke.y-he.y));c.set(ot,Hn,{target:xe,x:he.x,y:he.y,ax:Ke.x,ay:Ke.y,dist0:gt,went:0,stats:I,power:P,crit:ge}),c.set(ot,K,{x:he.x,y:he.y});let Ht=I.shot==="td_arrow"?{w:L*.55,h:L*.18}:I.lob?{w:L*.34,h:L*.34}:{w:L*.3,h:L*.3};c.set(ot,ie,{shape:"sprite",art:I.shot,...Ht,...I.burn?{color:"danger"}:I.slow?{color:"primary"}:I.type==="magic"?{color:"secondary"}:{},depth:40});}}for(let M of c.query(Hn)){let x=c.need(M,Hn);if(c.has(x.target,De)){let U=b(x.target);x.ax=U.x,x.ay=U.y;}let _=x.ax-x.x,I=x.ay-x.y,P=Math.hypot(_,I),H=x.stats.shotSpeed*L*R,re=c.need(M,K);if(P>H){x.x+=_/P*H,x.y+=I/P*H,x.went+=H;let U=Math.min(1,x.went/x.dist0);re.x=x.x,re.y=x.y-(x.stats.lob?Math.sin(Math.PI*U)*L*.9:0),re.rotation=x.stats.lob?(re.rotation??0)+R*8:Math.atan2(I,_);continue}if(c.destroy(M),x.stats.splash){let U=Be(x.ax,x.ay);G(c,{kind:"burst",x:x.ax,y:x.ay,color:x.stats.burn?"danger":x.stats.slow?"primary":"coin",n:12,size:x.stats.splash*L*1.6}),x.stats.lob&&G(c,{kind:"shake",power:.25});for(let me of c.query(De)){let he=c.need(me,De),xe=hr(he.kind);(xe.flying?x.stats.air:x.stats.ground)&&Math.hypot(he.x-U.x,he.y+(xe.flying?-0.55:0)-U.y)<=x.stats.splash&&d(me,x.stats,x.power,x.crit);}}else c.has(x.target,De)&&(G(c,{kind:"burst",x:x.ax,y:x.ay,color:x.stats.type==="magic"?"secondary":"coin",n:5,size:L*.5}),d(x.target,x.stats,x.power,x.crit));if(fe||tt())return}for(let M of c.query(Ha)){let x=c.need(M,Ha);x.t+=R;let _=(x.t-x.delay)/uu,I=c.need(M,K),P=c.need(M,ie);if(_<0)continue;if(_<1){let re=He(c).h;I.x=ke(x.x)+(1-_)*L*2,I.y=_e(x.y)-(1-_)*re*.5,I.rotation=-0.9,P.shape==="sprite"&&(P.alpha=1);continue}c.destroy(M),G(c,{kind:"burst",x:ke(x.x),y:_e(x.y),color:"danger",n:20,size:x.radius*L*2}),G(c,{kind:"ring",x:ke(x.x),y:_e(x.y),color:"coin",size:x.radius*L*2.2}),G(c,{kind:"shake",power:.8});let H={damage:x.damage,type:"true",...x.burn>0?{burn:x.burn,burnTime:2}:{}};for(let re of c.query(De)){let U=c.need(re,De);Math.hypot(U.x-x.x,U.y-x.y)<=x.radius&&d(re,H,1,false,1,"spell");}if(fe||tt())return}for(let M of c.query(Wa)){let x=c.need(M,Wa);x.life-=y,x.life<=0&&c.destroy(M);}if(C>=a.waves.length&&z.length===0&&c.query(De).length===0){Q("defended");return}c.vars.level_progress=a.waves.length>0?Math.min(1,(C-(z.length>0||c.query(De).length>0?.5:0))/a.waves.length):0,c.vars.score=Se(),ht.clear(),Re!==null&&Ft(),w(),Y(),Gt(["m:","h:","b:"]);}});let T=(c,y,R)=>{let L=Math.hypot(y.x-c.x,y.y-c.y),M=e.create();e.set(M,Wa,{life:.16}),e.set(M,K,{x:(c.x+y.x)/2,y:(c.y+y.y)/2,rotation:Math.atan2(y.y-c.y,y.x-c.x)}),e.set(M,ie,{shape:"sprite",art:"zap",w:Math.max(8,L),h:se()*.22,color:R,depth:41});};Ie(),l();}};var gs=[{id:"lemon",art:"biz1",color:"coin",cost:4,income:1,cycle:1,growth:1.07,manager:60},{id:"bakery",art:"biz2",color:"accent",cost:50,income:17,cycle:2,growth:1.1,manager:600},{id:"cafe",art:"biz3",color:"secondary",cost:600,income:225,cycle:3,growth:1.11,manager:7e3},{id:"workshop",art:"biz4",color:"primary",cost:7e3,income:2800,cycle:4,growth:1.11,manager:8e4},{id:"cinema",art:"ty_cinema",color:"danger",cost:8e4,income:4e4,cycle:6,growth:1.11,manager:1e6},{id:"hotel",art:"biz6",color:"secondary",cost:9e5,income:51e4,cycle:8,growth:1.11,manager:11e6},{id:"bank",art:"biz5",color:"coin",cost:1e7,income:62e5,cycle:10,growth:1.11,manager:12e7},{id:"port",art:"ty_port",color:"primary",cost:12e7,income:8e7,cycle:12,growth:1.11,manager:15e8}],Wn=e=>gs.find(t=>t.id===e),bs=[{at:10,speed:2},{at:25,speed:2},{at:50,speed:2},{at:75,income:3},{at:100,speed:2},{at:150,income:3}],Ka=.1,Fa=[{id:"double",scope:"one",art:"ty_up",mult:2,price:60,after:5},{id:"triple",scope:"one",art:"ty_up3",mult:3,price:2500,after:25},{id:"all",scope:"all",art:"ty_upall",mult:2,price:40,after:15}],_o=[{id:"rush",art:"ty_rush",effect:"rush",weight:3,ttl:7,mult:3,seconds:10},{id:"break",art:"ty_wrench",effect:"break",weight:2,ttl:99,taps:3},{id:"invest",art:"ty_investor",effect:"invest",weight:1,ttl:9,now:25,mult:2,seconds:30},{id:"courier",art:"chest",effect:"courier",weight:2,ttl:6,now:15,coins:2}],xf=e=>_o.find(t=>t.id===e),tc=[11,18],rc=[{id:"rush",art:"ty_sk_rush",charge:30,effect:"rush",mult:5,seconds:12},{id:"instant",art:"ty_sk_instant",charge:26,effect:"instant",cycles:8},{id:"sale",art:"ty_sk_sale",charge:28,effect:"sale",mult:.5,seconds:15}],qa=e=>rc.find(t=>t.id===e),kf=.4,vf=3,Ro=[{id:"hero",cast:"hero",gems:0,skill:"rush"},{id:"hero2",cast:"hero2",gems:150,skill:"instant"},{id:"hero3",cast:"hero3",gems:300,skill:"sale"}];var $f={l:"lemon",b:"bakery",c:"cafe",w:"workshop",n:"cinema",h:"hotel",k:"bank",p:"port"},yu={r:"rush",b:"break",i:"invest",c:"courier"},Ve=(e,t,r="",o)=>({businesses:[...e].map(n=>$f[n]??"lemon"),goals:t,events:[...r].map(n=>yu[n]??"rush"),...{}}),Ga=e=>({...e,vip:true}),Ue=e=>({kind:"cash",n:e}),At=(e,t)=>({kind:"level",biz:$f[e]??"lemon",n:t}),lr=e=>({kind:"managers",n:e}),jn=[Ve("lb",[Ue(5200)]),Ve("lb",[At("l",25),Ue(62e3)]),Ve("lbc",[Ue(17e3)],"r"),Ve("lbc",[lr(2),Ue(34e3)],"r"),Ve("lbc",[At("b",25),Ue(51e3)],"rc"),Ve("lbcw",[Ue(21e4)],"rc"),Ve("lbcw",[At("c",25),lr(2)],"rc"),Ve("lbcw",[lr(3),Ue(46e4)],"rc"),Ve("lbcw",[At("w",10),Ue(1e6)],"rc"),Ga(Ve("lbcw",[At("c",25),lr(4),Ue(5e6)],"rc")),Ve("bcw",[Ue(73e3)],"rb"),Ve("bcw",[At("c",25),Ue(17e4)],"rcb"),Ve("bcwn",[Ue(2e5)],"rcb"),Ve("bcwn",[lr(2),Ue(42e4)],"rcb"),Ve("bcwn",[At("n",5),Ue(97e4)],"rcb"),Ve("bcwn",[At("w",25),Ue(24e5)],"rcb"),Ve("bcwn",[lr(3),Ue(19e5)],"rcb"),Ve("bcwn",[At("c",50),Ue(32e5)],"rcb"),Ve("bcwn",[At("n",10),lr(3)],"rcb"),Ga(Ve("bcwn",[At("n",10),lr(4),Ue(64e6)],"rcb")),Ve("cwn",[Ue(12e5)],"rcbi"),Ve("cwn",[At("w",25),Ue(2e6)],"rcbi"),Ve("cwnh",[Ue(27e5)],"rcbi"),Ve("cwnh",[lr(2),Ue(32e5)],"rcbi"),Ve("cwnh",[At("h",5),Ue(16e6)],"rcbi"),Ve("cwnh",[At("n",25),Ue(26e6)],"rcbi"),Ve("cwnh",[lr(3),Ue(15e6)],"rcbi"),Ve("cwnh",[At("w",50),Ue(42e6)],"rcbi"),Ve("cwnh",[At("h",10),lr(3)],"rcbi"),Ga(Ve("cwnh",[At("h",10),lr(4),Ue(26e7)],"rcbi")),Ve("wnhk",[Ue(12e6)],"rcbi"),Ve("wnhk",[At("h",10),Ue(36e6)],"rcbi"),Ve("wnhk",[lr(3),Ue(21e7)],"rcbi"),Ve("nhkp",[Ue(21e7)],"rcbi"),Ve("nhkp",[At("k",10),Ue(38e7)],"rcbi"),Ve("nhkp",[lr(2),Ue(42e7)],"rcbi"),Ve("nhkp",[At("p",5),Ue(27e8)],"rcbi"),Ve("nhkp",[At("k",25),Ue(32e8)],"rcbi"),Ve("nhkp",[At("p",10),lr(3)],"rcbi"),Ga(Ve("nhkp",[At("p",10),lr(4),Ue(11e9)],"rcbi"))],Ao=10,Mf=4,Lo=jn.length,nc=[0,18,45,75],oc=e=>nc[Math.ceil(Math.max(1,e)/Ao)-1]??0,Ua=e=>e>=.3?3:e>=.12?2:1,Xa=30,wf=(e,t)=>Math.round((t?40:20)+(e-1)*2),sc=(e,t)=>(t?120:50)+(e-1)*10,ac="kit-tycoon",ic=[{id:"StartCash",var:"meta:cash",art:"coin",color:"coin",perLevel:20,unit:"%",maxLevel:15,price:40,growth:.12},{id:"CycleSpeed",var:"meta:speed",art:"hourglass",color:"secondary",perLevel:3,unit:"%",maxLevel:15,price:45,growth:.12},{id:"Income",var:"meta:income",art:"ty_up",color:"accent",perLevel:5,unit:"%",maxLevel:20,price:40,growth:.12},{id:"Discount",var:"meta:discount",art:"ty_sk_sale",color:"primary",perLevel:2,unit:"%",maxLevel:15,price:50,growth:.12},{id:"SkillPower",var:"meta:skill",art:"ty_sk_rush",color:"secondary",perLevel:8,unit:"%",maxLevel:10,price:50,growth:.12}],Ef={game:"tycoon",character:ac,stats:ic,heroes:Ro,levels:Lo,firstClearGold:e=>sc(e,jn[Math.max(1,Math.min(Lo,e))-1]?.vip===true),stars:3,starsToEnter:oc};var gu={income:0,speed:0,discount:0};function ks(e,t=gu,r){return {biz:e.businesses.map((n,s)=>({def:Wn(n)??gs[0],level:s===0?1:0,progress:0,ready:false,manager:false,mult:1,rush:0,rushMult:1,broken:0})),cash:r??Lf(e),earned:0,allMult:1,bought:new Set,timed:[],mods:t}}var Lf=e=>e.cash??(Wn(e.businesses[1]??e.businesses[0]??"lemon")?.cost??4)*2,bu=e=>e.timed.reduce((t,r)=>t*r.income,1),xu=e=>e.timed.reduce((t,r)=>t*r.price,1);function vs(e){let t=1,r=1,o=0;for(let n of bs)e>=n.at?(t*=n.speed??1,r*=n.income??1):o===0&&(o=n.at);return {speed:t,income:r,next:o}}function kn(e,t){let r=vs(t.level);return Math.max(Ka,t.def.cycle/r.speed/(1+e.mods.speed))}function Tr(e,t,r=t.level){if(r<=0)return 0;let o=vs(r),n=t.def.cycle/o.speed/(1+e.mods.speed),s=n<Ka?Ka/n:1;return t.def.income*r*o.income*s*t.mult*e.allMult*(1+e.mods.income)*(t.rush>0?t.rushMult:1)*bu(e)}var Za=(e,t)=>t.level<=0||t.broken>0?0:Tr(e,t)/kn(e,t),Qa=e=>e.biz.reduce((t,r)=>t+Za(e,r),0),xs=e=>Math.max(.1,1-Math.min(.9,e.mods.discount))*xu(e);function vn(e,t,r=1){let o=t.def.growth,n=t.def.cost*Math.pow(o,t.level),s=r<=1?n:n*(Math.pow(o,r)-1)/(o-1);return Math.ceil(s*xs(e))}function cc(e,t,r=1e3){let o=t.def.growth,n=t.def.cost*Math.pow(o,t.level)*xs(e);if(e.cash<n)return 0;let s=Math.floor(Math.log(e.cash*(o-1)/n+1)/Math.log(o)),a=Math.max(1,Math.min(r,s));for(;a>1&&vn(e,t,a)>e.cash;)a--;return vn(e,t,a)<=e.cash?a:0}var To=(e,t)=>Math.ceil(t.def.manager*xs(e));function Ya(e,t,r=1){let o=e.biz[t];if(!o||r<1)return {ok:false,milestones:[]};let n=vn(e,o,r);if(e.cash<n)return {ok:false,milestones:[]};e.cash-=n;let s=o.level;return o.level+=r,{ok:true,milestones:bs.filter(a=>s<a.at&&o.level>=a.at).map(a=>a.at)}}function Ja(e,t){let r=e.biz[t];if(!r||r.manager||r.level<=0)return false;let o=To(e,r);return e.cash<o?false:(e.cash-=o,r.manager=true,r.ready&&(r.ready=false,r.progress=0,$s(e,Tr(e,r))),true)}var $s=(e,t)=>{e.cash+=t,e.earned+=t;};function ei(e,t){let r=e.biz[t];if(!r||!r.ready)return 0;r.ready=false,r.progress=0;let o=Tr(e,r);return $s(e,o),o}function ti(e,t){let r=e.biz[t];return !r||r.broken<=0?false:(r.broken--,r.broken===0)}function dc(e,t){let r=0;for(let o of e.biz)o.level<=0||o.broken>0||(r+=Tr(e,o)*t);return $s(e,r),r}var fc=(e,t)=>$s(e,t);function ri(e,t){let r=e.timed.findIndex(o=>o.id===t.id);r>=0&&e.timed.splice(r,1),e.timed.push(t);}function ni(e,t){let r=[],o=[];e.biz.forEach((n,s)=>{if(n.rush>0&&(n.rush=Math.max(0,n.rush-t)),!(n.level<=0||n.ready||n.broken>0)&&(n.progress+=t/kn(e,n),!(n.progress<1)))if(n.manager){let a=Math.floor(n.progress);n.progress-=a;let i=Tr(e,n)*a;$s(e,i),o.push({index:s,amount:i});}else n.progress=1,n.ready=true,r.push(s);});for(let n=e.timed.length-1;n>=0;n--){let s=e.timed[n];s.left-=t,s.left<=0&&e.timed.splice(n,1);}return {ready:r,paid:o}}function pc(e){let t=[],r=e.biz.reduce((o,n)=>Math.max(o,n.def.cost),0);for(let o of Fa)o.scope==="all"?t.push({key:o.id,def:o,index:-1,price:Math.ceil(r*o.price*xs(e))}):e.biz.forEach((n,s)=>t.push({key:`${o.id}:${n.def.id}`,def:o,index:s,price:Math.ceil(n.def.cost*o.price*xs(e))}));return t}function oi(e,t=3){return pc(e).filter(r=>!e.bought.has(r.key)&&(r.index<0?(e.biz[0]?.level??0)>=r.def.after:(e.biz[r.index]?.level??0)>=r.def.after)).sort((r,o)=>r.price-o.price).slice(0,t)}function si(e,t){let r=pc(e).find(o=>o.key===t);return !r||e.bought.has(t)||e.cash<r.price?false:(e.cash-=r.price,e.bought.add(t),r.index<0?e.allMult*=r.def.mult:e.biz[r.index].mult*=r.def.mult,true)}var ai=e=>e.biz.filter(t=>t.manager).length;function on(e,t){if(t.kind==="cash")return Math.min(1,e.earned/Math.max(1,t.n));if(t.kind==="managers")return Math.min(1,ai(e)/Math.max(1,t.n));let r=e.biz.find(o=>o.def.id===t.biz);return Math.min(1,(r?.level??0)/Math.max(1,t.n))}var Ms=(e,t)=>t.every(r=>on(e,r)>=1),ii=(e,t)=>t.length?t.reduce((r,o)=>r+on(e,o),0)/t.length:1,lc=(e,t)=>t.manager?1:kn(e,t)/(kn(e,t)+1.2);function li(e,t){let r=e.biz.findIndex(k=>k.broken>0);if(r>=0)return {kind:"fix",index:r};let o=null,n=Qa(e),s=(k,O,C)=>{if(C>e.cash+n*8)return;let z=O/Math.max(1,C);(!o||z>o.value)&&(o={move:k,value:z,price:C});},a=k=>t.some(O=>O.kind==="level"&&O.biz===k&&on(e,O)<1),i=t.some(k=>k.kind==="managers"&&on(e,k)<1),p=t.some(k=>k.kind==="cash"&&on(e,k)<1);e.biz.forEach((k,O)=>{let C=Za(e,k)*lc(e,k),z={...k,level:k.level+1},ne=(Tr(e,z)/kn(e,z)*lc(e,z)-C)*(k.level===0?3:1)*(a(k.def.id)?3:1);s({kind:"buy",index:O},ne+(a(k.def.id)&&!p?n*.05:0),vn(e,k)),k.level>0&&!k.manager&&s({kind:"hire",index:O},Za(e,k)*(1-lc(e,k))*1.6*(i?3:1)+(i?n*.05:0),To(e,k));});for(let k of oi(e,6)){let O=k.index<0?n*(k.def.mult-1):Za(e,e.biz[k.index])*(k.def.mult-1);s({kind:"upgrade",key:k.key},O,k.price);}let m=e.biz.map((k,O)=>({b:k,i:O})).filter(k=>k.b.ready).sort((k,O)=>Tr(e,O.b)-Tr(e,k.b))[0],$=o;return $&&$.price<=e.cash?$.move:m?{kind:"collect",index:m.i}:null}function _f(e,t){return t?t.kind==="collect"?ei(e,t.index)>0:t.kind==="buy"?Ya(e,t.index).ok:t.kind==="hire"?Ja(e,t.index):t.kind==="fix"?ti(e,t.index)||true:si(e,t.key):false}function Rf(e,t={}){let r=ks(e,t.mods),o=.05,n=t.tapEvery??.4,s=t.max??900,a=0,i=0;for(;a<s;){if(Ms(r,e.goals))return a;if(ni(r,o),a+=o,a>=i){let p=li(r,e.goals);p&&(_f(r,p),i=a+n);}}return 1/0}var Sf=new Map;function ci(e){let t=Sf.get(e);return t===void 0&&(t=Rf(jn[e-1]),Sf.set(e,t)),t}function Do(e,t=.5){let r=Math.max(1,Math.min(Lo,Math.floor(e))),o=jn[r-1],n=Math.ceil(r/Ao),s=r-(n-1)*Ao,a=ci(r),i=(1.6-(n-1)*.08-s*.01)*(1.1-t*.2)*(o.extra??1),p=Math.max(45,Math.min(600,Math.ceil((Number.isFinite(a)?a:400)*i/5)*5));return {level:r,world:n,index:s,def:o,boss:o.vip===true,day:p,cash:Lf(o),coins:wf(r,o.vip===true),firstClearGold:sc(r,o.vip===true)}}var ku=ve("tycoon.part"),hc=ve("tycoon.manager"),Oo=(e,t)=>{let r=Number(e.vars[t]??0);return Number.isFinite(r)?r:0},vr=e=>{let t=Math.abs(e);for(let[r,o]of [[1e12,"T"],[1e9,"B"],[1e6,"M"],[1e3,"K"]])if(t>=r)return `${(e/r).toFixed(t>=r*100?0:1).replace(/\.0$/,"")}${o}`;return String(Math.floor(e))},Af=new WeakMap,Tf=e=>Af.get(e),ws=[1,10,0],di={id:"tycoon",version:2,engines:["phaser"],requires:["round"],params:{difficulty:{type:"number",default:.5,min:0,max:1},coinReward:{type:"number",default:1,min:0,max:10}},setup({world:e,params:t,mode:r}){let o=d=>yr(t,d),n=e.rng.stream("tycoon"),s=Sr(r,"events",_o.map(d=>d.id)),a=Do(1,o("difficulty")),i=ks(a.def),p=new Map,m=new Map,$=null,k=[],O=0,C=0,z=0,F=0,ne=0,X=false,ye=false,be=0,fe=null,we=null,de=null,Re=()=>Ro.find(d=>d.id===e.vars["meta:hero"])??Ro[0],Ce=()=>qa(Re().skill),Me=()=>e.vars.reviving===true,ce=()=>a.def.goals,ue=()=>{let d=He(e);return {...d,U:Math.min(d.w,d.h)}},Pe=d=>{let h=ue(),v=Math.max(1,i.biz.length),A=h.h*.25,N=h.h*.81,B=Math.max(6,h.h*.012),Q=Math.min((N-A-B*(v-1))/v,150,h.w*.26),J=Math.min(h.w*.96,660),$e=A+(N-A-(v*Q+(v-1)*B))/2;return {x:h.w/2,y:$e+d*(Q+B)+Q/2,w:J,h:Q}},Le=d=>{let h=Pe(d);return {x:h.x-h.w/2+h.h*.56,y:h.y,size:h.h*.9}},oe=()=>ue().h*.9,Ee=()=>{let d=ue();return Math.min(d.U*.075,d.h*.055)},tt=()=>{let d=ue(),h=we?1-we.left/we.def.ttl:0;return {x:-d.w*.05+h*d.w*1.1,y:d.h*.21,r:d.U*.06}},Ne=new Set,se=(d,h,v,A,N=1)=>{Ne.add(d);let B=p.get(d);(B===void 0||!e.isAlive(B))&&(B=e.create(),e.set(B,ku,{id:d}),p.set(d,B)),e.set(B,K,{x:h,y:v,scale:N}),e.set(B,ie,A);},ke=()=>{for(let[d,h]of [...p])Ne.has(d)||(e.destroy(h),p.delete(d));},_e=(d,h,v,A,N,B,Q=70)=>se(d,h,v,{shape:"text",text:A,size:Math.max(9,Math.round(B)),color:N,bold:true,depth:Q}),Te=(d,h,v,A,N,B,Q,J=2)=>{se(`${d}:bg`,h,v,{shape:"rect",w:A+4,h:N+4,color:"#000000",alpha:.4,radius:(N+4)/2,depth:J});let $e=Math.max(1,A*Math.max(0,Math.min(1,B)));se(`${d}:fill`,h-A/2+$e/2,v,{shape:"rect",w:$e,h:N,color:Q,radius:N/2,depth:J+.1});},Be=d=>k.push(d),ee=d=>{let h=i.biz[d],v=ws[ne]??1;return v===0?Math.max(1,cc(i,h)):v},Ie=()=>{i.biz.forEach((d,h)=>{let v=Pe(h),A=Le(h),N=d.level>0,B=d.def.color;se(`r${h}`,v.x,v.y,{shape:"sprite",art:"panel",w:v.w,h:v.h,color:"panel",depth:0}),d.rush>0&&se(`r${h}:rush`,A.x,A.y,{shape:"circle",r:A.size*.55,color:"coin",alpha:.35+.2*Math.sin(e.time*8),depth:.5});let Q=d.ready?1+.06*Math.abs(Math.sin(e.time*6)):1;se(`r${h}:b`,A.x,A.y,{shape:"sprite",art:d.def.art,w:A.size,h:A.size,color:B,alpha:N?d.broken>0?.55:1:.35,depth:1},Q),Be({id:`biz${h}`,x:A.x,y:A.y,w:A.size,h:A.size});let J=v.x-v.w*.12,$e=v.h*.2,Se=vs(d.level);if(_e(`r${h}:lv`,J,v.y-v.h*.26,N?`Lv ${d.level}${Se.next?`/${Se.next}`:""}`:"Lv 0","text",$e,2),N){_e(`r${h}:inc`,J,v.y+v.h*0,`+${vr(Tr(i,d))}`,"coin",$e*.95,2);let l=d.ready||kn(i,d)<=.15&&d.manager?1:d.progress;Te(`r${h}:bar`,J,v.y+v.h*.28,v.w*.3,Math.max(6,v.h*.12),l,d.broken>0?"danger":B),d.ready&&!d.manager&&_e(`r${h}:ok`,A.x+A.size*.36,A.y+A.size*.34,"$","coin",A.size*.3,3);}if(fe?.index===h){let l=1+.12*Math.sin(e.time*9);se(`r${h}:ev`,A.x+A.size*.32,A.y-A.size*.3,{shape:"sprite",art:fe.def.art,w:A.size*.5,h:A.size*.5,depth:4},l);}else d.broken>0&&(se(`r${h}:ev`,A.x+A.size*.3,A.y-A.size*.28,{shape:"sprite",art:"ty_wrench",w:A.size*.48,h:A.size*.48,depth:4},1+.08*Math.sin(e.time*10)),_e(`r${h}:evn`,A.x+A.size*.3,A.y+A.size*.05,String(d.broken),"danger",A.size*.26,4.1));let Ye=v.x+v.w*.13,pt=v.h*.27;if(N&&!d.manager){let l=To(i,d),E=i.cash>=l;se(`r${h}:m:bg`,Ye,v.y-v.h*.08,{shape:"circle",r:pt,color:E?"secondary":"panel",alpha:E?.95:.7,depth:1}),se(`r${h}:m`,Ye,v.y-v.h*.08,{shape:"sprite",art:"ty_manager",w:pt*1.7,h:pt*1.7,alpha:E?1:.5,depth:1.2}),_e(`r${h}:m:p`,Ye,v.y+v.h*.32,vr(l),E?"text":"muted",$e*.8,2),Be({id:`mgr${h}`,x:Ye,y:v.y,w:pt*2.2,h:v.h*.9});}let ze=v.x+v.w/2-v.w*.14,le=v.w*.25,V=v.h*.72,te=ee(h),Y=vn(i,d,te),w=i.cash>=Y;se(`r${h}:buy`,ze,v.y,{shape:"sprite",art:"button",w:le,h:V,color:w?"accent":"panel",alpha:w?1:.6,depth:1}),_e(`r${h}:buy:n`,ze,v.y-V*.2,N?`+${te}`:"OPEN","text",$e*.9,2),se(`r${h}:buy:c`,ze-le*.3,v.y+V*.2,{shape:"sprite",art:"coin",w:$e*.8,h:$e*.8,depth:2}),_e(`r${h}:buy:p`,ze+le*.08,v.y+V*.2,vr(Y),w?"coin":"muted",$e*.85,2),Be({id:`buy${h}`,x:ze,y:v.y,w:le,h:V});let S=m.get(h);if(d.manager&&(S===void 0||!e.isAlive(S))&&(S=e.create(),e.set(S,hc,{index:h}),e.set(S,ie,{shape:"actor",cast:"helper",variant:h*13+5,h:v.h*.78,pose:"idle",facing:1,depth:2}),m.set(h,S)),S!==void 0&&e.isAlive(S)){e.set(S,K,{x:Ye,y:v.y+v.h*.02});let l=e.need(S,ie);l.shape==="actor"&&(l.h=v.h*.78);}});},nt=d=>d.kind==="cash"?"coin":d.kind==="managers"?"ty_manager":Wn(d.biz??"")?.art??"biz1",ht=d=>d.kind==="cash"?i.earned:d.kind==="managers"?ai(i):i.biz.find(h=>h.def.id===d.biz)?.level??0,Ae=()=>{let d=ue(),h=d.U,v=d.h*.09;se("h:t:i",d.w*.09,v,{shape:"sprite",art:"hourglass",w:h*.06,h:h*.06,depth:70}),_e("h:t",d.w*.09+h*.09,v,Vs(O),O<=15?"danger":"text",h*.05),se("h:c:i",d.w*.42,v,{shape:"sprite",art:"coin",w:h*.07,h:h*.07,depth:70}),_e("h:c",d.w*.42+h*.13,v,vr(i.cash),"coin",h*.065);let A=h*.17;se("h:mode",d.w*.88,v,{shape:"sprite",art:"button",w:A,h:h*.08,color:"secondary",depth:70}),_e("h:mode:t",d.w*.88,v,ws[ne]===0?"MAX":`\xD7${ws[ne]}`,"text",h*.042,70.1),Be({id:"mode",x:d.w*.88,y:v,w:A,h:h*.09});let N=ce(),B=Math.min(d.w*.3,230),Q=Math.max(30,d.h*.05),J=d.h*.15;if(N.forEach((le,V)=>{let te=d.w/2+(V-(N.length-1)/2)*(B+h*.02),Y=on(i,le)>=1;se(`h:g${V}`,te,J,{shape:"sprite",art:"panel",w:B,h:Q,color:Y?"accent":"panel",depth:70}),se(`h:g${V}:i`,te-B*.36,J-Q*.06,{shape:"sprite",art:nt(le),w:Q*.75,h:Q*.75,depth:70.1});let w=ht(le),S=Y?"\u2713":le.kind==="cash"?`${vr(w)}/${vr(le.n)}`:le.kind==="level"?`Lv ${w}/${le.n}`:`${w}/${le.n}`;_e(`h:g${V}:t`,te+B*.1,J-Q*.08,S,"text",Q*.36,70.1),Te(`h:g${V}:bar`,te+B*.1,J+Q*.3,B*.62,Math.max(4,Q*.1),on(i,le),Y?"accent":"coin",70.1);}),i.timed.forEach((le,V)=>{let te=d.w*.9-V*h*.16,Y=le.id==="sale"?"ty_sk_sale":le.id==="invest"?"ty_investor":Ce().art;se(`h:tm${V}`,te-h*.04,d.h*.205,{shape:"sprite",art:Y,w:h*.06,h:h*.06,depth:70}),_e(`h:tm${V}:t`,te+h*.035,d.h*.205,`${Math.ceil(le.left)}`,"secondary",h*.04);}),we){let le=tt();se("h:courier",le.x,le.y+Math.sin(e.time*10)*le.r*.08,{shape:"sprite",art:we.def.art,w:le.r*2,h:le.r*2,depth:72}),Be({id:"courier",x:le.x,y:le.y,w:le.r*2.6,h:le.r*2.6});}let $e=oe(),Se=Ee(),Ye=d.w*.25,pt=F>=Ce().charge;pt&&se("h:sk:glow",Ye,$e,{shape:"circle",r:Se*1.28,color:"secondary",alpha:.5+.3*Math.sin(e.time*7),depth:68.9}),se("h:sk:bg",Ye,$e,{shape:"circle",r:Se,color:"panel",alpha:.95,depth:69}),se("h:sk",Ye,$e,{shape:"sprite",art:Ce().art,w:Se*1.4,h:Se*1.4,alpha:pt?1:.45,depth:69.2}),Te("h:charge",Ye,$e+Se*1.3,Se*2,Math.max(5,Se*.2),F/Ce().charge,"secondary",69),Be({id:"skill",x:Ye,y:$e,w:Se*2.4,h:Se*2.4}),oi(i,3).forEach((le,V)=>{let te=d.w*(.47+V*.18),Y=i.cash>=le.price;se(`h:u${V}:bg`,te,$e,{shape:"circle",r:Se,color:Y?"accent":"panel",alpha:Y?.95:.7,depth:69}),se(`h:u${V}`,te,$e-Se*.08,{shape:"sprite",art:le.def.art,w:Se*1.5,h:Se*1.5,alpha:Y?1:.55,depth:69.2});let w=le.index>=0?i.biz[le.index]:void 0;w&&se(`h:u${V}:b`,te+Se*.7,$e-Se*.6,{shape:"sprite",art:w.def.art,w:Se*.9,h:Se*.9,color:w.def.color,depth:69.3}),_e(`h:u${V}:p`,te,$e+Se*1.3,vr(le.price),Y?"coin":"muted",Se*.42,69.3),Be({id:`up:${le.key}`,x:te,y:$e,w:Se*2.3,h:Se*2.6});}),($===null||!e.isAlive($))&&($=e.create(),e.set($,ie,{shape:"actor",cast:Re().cast,h:Se*2.6,pose:"idle",facing:1,depth:20})),e.set($,K,{x:d.w*.09,y:$e-Se*.1});let ze=e.need($,ie);if(ze.shape==="actor"&&(ze.h=Se*2.6),de){let le=Math.min(d.w*.86,500),V=le*.42,te=d.w/2,Y=d.h*.5;se("h:inv:dim",te,Y,{shape:"rect",w:d.w,h:d.h,color:"#000000",alpha:.35,depth:79}),se("h:inv",te,Y,{shape:"sprite",art:"panel",w:le,h:V,color:"panel",depth:80}),se("h:inv:i",te-le*.34,Y,{shape:"sprite",art:de.def.art,w:V*.62,h:V*.62,depth:80.1});let w=le*.3,S=V*.5,l=Ze();se("h:inv:a",te+le*.02,Y-V*.04,{shape:"sprite",art:"button",w,h:S,color:"accent",depth:80.1}),se("h:inv:a:c",te+le*.02-w*.28,Y-V*.04,{shape:"sprite",art:"coin",w:S*.4,h:S*.4,depth:80.2}),_e("h:inv:a:t",te+le*.02+w*.1,Y-V*.04,vr(l),"coin",S*.3,80.2),se("h:inv:b",te+le*.33,Y-V*.04,{shape:"sprite",art:"button",w,h:S,color:"secondary",depth:80.1}),_e("h:inv:b:t",te+le*.33,Y-V*.04,`\xD7${de.def.mult??2} ${de.def.seconds??30}s`,"text",S*.28,80.2),Te("h:inv:bar",te+le*.17,Y+V*.32,le*.6,Math.max(4,V*.05),de.left/de.def.ttl,"coin",80.1),Be({id:"inv_now",x:te+le*.02,y:Y-V*.04,w,h:S}),Be({id:"inv_share",x:te+le*.33,y:Y-V*.04,w,h:S});}},Gt=()=>{k=[],Ne.clear(),Ie(),Ae(),ke(),e.vars.ty_buttons=k.map(d=>`${d.id}@${Math.round(d.x)},${Math.round(d.y)}`).join(";");},Xe=()=>{e.vars.cash=Math.floor(i.cash),e.vars.earned=Math.floor(i.earned),e.vars.time_left=O,e.vars.ty_charge=Math.floor(F),e.vars.ty_mode=ws[ne]??1,e.vars.level_progress=ii(i,ce()),e.vars.ty_goals=ce().map(d=>`${d.kind}:${Math.floor(ht(d))}/${d.n}`).join("|");},rt=()=>{for(let h of [...p.values(),...m.values()])e.isAlive(h)&&e.destroy(h);p.clear(),m.clear(),$!==null&&e.isAlive($)&&e.destroy($),$=null,a=Do(Oo(e,"meta:chapter")||1,o("difficulty"));let d={income:Oo(e,"meta:income"),speed:Oo(e,"meta:speed"),discount:Oo(e,"meta:discount")};i=ks(a.def,d,Math.round(a.cash*(1+Oo(e,"meta:cash")))),Af.set(e,{s:i,level:a}),zt(e,"board",He(e).h*.24),O=a.day,C=0,z=0,F=0,X=false,ye=false,be=8+n.range(0,4),fe=null,we=null,de=null,e.vars.ty_level=a.level,e.vars.ty_world=a.world,e.vars.coins=0,e.vars.score=0,e.vars.stars=0,e.vars.reviving=false,Xe();},lt=d=>{if(ye)return;ye=true;let h=d==="cleared",v=ii(i,ce()),A=h?Math.min(X?1:3,Ua(O/Math.max(1,a.day))):0,N=Math.round(a.coins*o("coinReward")*(h?[1,1,1.25,1.5][A]:v*.5));N>0&&(Je(e,"coins",N),e.emit("coin-collected",{value:N})),h&&e.vars["meta:first_clear"]===true&&Je(e,"coins",a.firstClearGold),e.vars.stars=A,e.vars.score=Math.round(v*1e3)+(h?A*500+Math.floor(O)*10:0),e.vars.reviving=false,fe=null,we=null,de=null,Xe(),e.emit(Xt,{reason:d,stats:{chapter:a.level,seconds:Math.floor(C),cleared:h,stars:A,coins:Number(e.vars.coins??0),earned:Math.floor(i.earned),managers:ai(i)}});},ft=()=>{ye||(G(e,{kind:"flash",color:"coin"}),lt("cleared"));},yt=()=>{if(e.vars.revive_ready===true&&!X){e.vars.reviving=true,e.emit(tr,{});return}lt("out-of-time");},ut=()=>{Me()&&(X=true,e.vars.reviving=false,O+=Xa,G(e,{kind:"flash",color:"coin"}),Xe());},Et=()=>Math.max(Qa(i),a.cash*.05),Ze=()=>Math.round(Et()*(de?.def.now??25)),Ge=d=>{F=Math.min(Ce().charge,F+vf),e.emit("event-handled",{id:d});},It=()=>{let d=i.biz.map((Q,J)=>({b:Q,i:J})).filter(Q=>Q.b.level>0&&Q.b.broken===0),h=Q=>Q.effect==="rush"?!fe&&d.some(J=>J.b.rush<=0):Q.effect==="break"?!i.biz.some(J=>J.broken>0)&&d.some(J=>J.b.level>=3):Q.effect==="invest"?!de:!we,v=a.def.events.filter(Q=>s.includes(Q)).map(Q=>_o.find(J=>J.id===Q)).filter(Q=>!!Q&&h(Q));if(!v.length)return;let A=v.reduce((Q,J)=>Q+J.weight,0),N=n.range(0,A),B=v.find(Q=>(N-=Q.weight)<0)??v[0];if(B.effect==="rush"){let Q=d.filter(J=>J.b.rush<=0);fe={index:Q[n.int(0,Q.length-1)].i,left:B.ttl,def:B};}else if(B.effect==="break"){let Q=d.filter($e=>$e.b.level>=3),J=Q[n.int(0,Q.length-1)];J.b.broken=B.taps??3,G(e,{kind:"shake",power:.3});}else B.effect==="invest"?de={left:B.ttl,def:B}:we={left:B.ttl,def:B};e.emit("event-started",{id:B.id});},Qe=d=>{fe&&(fe.left-=d)<=0&&(fe=null),we&&(we.left-=d)<=0&&(we=null),de&&(de.left-=d)<=0&&(de=null),a.def.events.length&&(be-=d,be<=0&&(It(),be=n.range(tc[0],tc[1])));},Kt=d=>{let h=i.biz[d];if(!h||h.level<=0)return;let v=Le(d);if(h.broken>0){G(e,{kind:"burst",x:v.x,y:v.y,color:"ground",n:6,size:v.size*.6}),ti(i,d)&&(G(e,{kind:"ring",x:v.x,y:v.y,color:"accent",size:v.size*1.2}),Ge("break"));return}fe?.index===d&&(h.rush=fe.def.seconds??10,h.rushMult=fe.def.mult??3,G(e,{kind:"ring",x:v.x,y:v.y,color:"coin",size:v.size*1.4}),G(e,{kind:"pop",x:v.x,y:v.y-v.size*.45,text:`\xD7${h.rushMult}`,color:"coin",size:Math.round(v.size*.3)}),fe=null,Ge("rush"));let A=ei(i,d);A<=0||(F=Math.min(Ce().charge,F+kf),Lt(e,"tycoon-collect"),G(e,{kind:"burst",x:v.x,y:v.y,color:"coin",n:8,size:v.size*.7}),G(e,{kind:"pop",x:v.x,y:v.y-v.size*.35,text:`+${vr(A)}`,color:"coin",size:Math.round(v.size*.24)}),e.emit("cycle-collected",{index:d,amount:A}));},Yt=d=>{let h=i.biz[d];if(!h)return;let v=Ya(i,d,ee(d)),A=Pe(d),N=A.x+A.w/2-A.w*.14;if(!v.ok){G(e,{kind:"shake",power:.1});return}Lt(e,"tycoon-buy");let B=Le(d);G(e,{kind:"ring",x:B.x,y:B.y,color:"coin",size:B.size*1.1}),G(e,{kind:"burst",x:N,y:A.y,color:"accent",n:5,size:A.h*.5}),e.emit("business-bought",{id:h.def.id,level:h.level});for(let Q of v.milestones)G(e,{kind:"flash",color:"coin"}),G(e,{kind:"pop",x:B.x,y:B.y-B.size*.5,text:`\u2605 ${Q}`,color:"coin",size:Math.round(B.size*.3)}),e.emit("milestone",{id:h.def.id,at:Q});},Ft=d=>{let h=i.biz[d];if(!h||!Ja(i,d))return;Lt(e,"tycoon-manager");let v=Le(d);G(e,{kind:"ring",x:v.x,y:v.y,color:"secondary",size:v.size*1.3}),G(e,{kind:"pop",x:v.x,y:v.y-v.size*.5,text:"\u2605",color:"secondary",size:Math.round(v.size*.35)}),e.emit("manager-hired",{id:h.def.id});},ur=(d,h,v)=>{si(i,d)&&(Lt(e,"tycoon-upgrade"),G(e,{kind:"ring",x:h,y:v,color:"accent",size:Ee()*2.6}),G(e,{kind:"flash",color:"accent"}),e.emit("upgrade-bought",{key:d}));},bt=()=>{let d=Ce();if(F<d.charge)return false;let h=1+Oo(e,"meta:skill");if(F=0,$!==null&&Fe(e,$,"cheer"),G(e,{kind:"flash",color:"secondary"}),d.effect==="rush")ri(i,{id:"skill",left:(d.seconds??12)*h,income:d.mult??5,price:1});else if(d.effect==="sale")ri(i,{id:"sale",left:(d.seconds??15)*h,income:1,price:d.mult??.5});else {let v=dc(i,Math.max(1,Math.round((d.cycles??8)*h))),A=ue();G(e,{kind:"pop",x:A.w/2,y:A.h*.16,text:`+${vr(v)}`,color:"coin",size:Math.round(A.U*.07)}),i.biz.forEach((N,B)=>{if(N.level<=0)return;let Q=Le(B);G(e,{kind:"burst",x:Q.x,y:Q.y,color:"coin",n:10,size:Q.size*.8});});}return e.emit("skill-cast",{id:d.id}),Lt(e,"tycoon-skill"),true},D=()=>{if(!we)return;let d=tt(),h=Math.round(Et()*(we.def.now??15));fc(i,h);let v=Math.round((we.def.coins??0)*o("coinReward"));v>0&&(Je(e,"coins",v),e.emit("coin-collected",{value:v})),G(e,{kind:"burst",x:d.x,y:d.y,color:"coin",n:14,size:d.r*2}),G(e,{kind:"pop",x:d.x,y:d.y+d.r*1.4,text:`+${vr(h)}`,color:"coin",size:Math.round(d.r*.7)}),we=null,Ge("courier");},u=d=>{if(!de)return;let h=de.def;d?ri(i,{id:"invest",left:h.seconds??30,income:h.mult??2,price:1}):fc(i,Ze()),de=null,G(e,{kind:"flash",color:"coin"}),Ge("invest");},g=(d,h,v)=>k.find(A=>(!v||A.id.startsWith(v))&&Math.abs(d-A.x)<=A.w/2&&Math.abs(h-A.y)<=A.h/2);e.on(Nt,d=>{let h=d;if(h.type!=="tap"||!st(e)||hn(e)||ye||Me())return;Bt(e),z=0;let v=de?g(h.x,h.y,"inv_")??g(h.x,h.y):g(h.x,h.y,"courier")??g(h.x,h.y);v&&(v.id==="inv_now"?u(false):v.id==="inv_share"?u(true):v.id==="courier"?D():v.id==="mode"?ne=(ne+1)%ws.length:v.id==="skill"?bt():v.id.startsWith("up:")?ur(v.id.slice(3),v.x,v.y):v.id.startsWith("biz")?Kt(Number(v.id.slice(3))):v.id.startsWith("buy")?Yt(Number(v.id.slice(3))):v.id.startsWith("mgr")&&Ft(Number(v.id.slice(3))),Xe(),Ms(i,ce())&&ft());}),e.on(Ut,()=>{rt(),e.vars.level=a.level;}),e.on(Qt,rt),e.on(rr,ut),e.on(nr,()=>{Me()&&(e.vars.reviving=false,lt("out-of-time"));}),e.on(Zt,d=>{Ne.clear(),ke(),k=[],e.vars.ty_buttons="",$!==null&&e.isAlive($)&&it(e,$,d.reason==="cleared"?"dance":"idle");}),e.on(qt,()=>zt(e,"board",He(e).h*.24));let f=d=>{if(!d)return;let h=d.kind==="collect"||d.kind==="fix"?`biz${d.index}`:d.kind==="buy"?`buy${d.index}`:d.kind==="hire"?`mgr${d.index}`:`up:${d.key}`;return k.find(v=>v.id===h)},b=d=>{let h=ue().U,v=i.biz.findIndex(A=>A.ready);if(!vt(d,"tycoon-collect")&&v>=0){let A=Le(v);return kt(d,"tap",A,void 0,A.size*.8)}if(!vt(d,"tycoon-buy")){let A=i.biz.findIndex(B=>i.cash>=vn(i,B,ee(i.biz.indexOf(B)))),N=k.find(B=>B.id===`buy${A}`);if(A>=0&&N)return kt(d,"tap",N,void 0,N.h)}if(!vt(d,"tycoon-manager")){let A=i.biz.findIndex(B=>B.level>0&&!B.manager&&i.cash>=To(i,B)),N=k.find(B=>B.id===`mgr${A}`);if(A>=0&&N)return kt(d,"tap",N,void 0,N.w)}if(F>=Ce().charge&&!vt(d,"tycoon-skill")){let A=k.find(N=>N.id==="skill");if(A)return kt(d,"tap",A,void 0,A.w)}if(z>6){let A=f(li(i,ce()));A&&kt(d,"tap",A,void 0,Math.min(A.w,h*.18));}};e.addSystem({id:"tycoon",order:0,run(d,h){if(!(!st(d)||ye)){if(!Me()){C+=h,z+=h,O=Math.max(0,O-h);for(let v of ni(i,h).paid)v.amount<=0||d.emit("cycle-collected",{index:v.index,amount:v.amount});F=Math.min(Ce().charge,F+h),Qe(h);}if(Gt(),Xe(),!Me()){if(Ms(i,ce()))return ft();_r(d)||b(d),O<=0&&yt();}}}}),rt();}};var sn=(e,t,r,o,n,s,a,i,p)=>({en:e,ru:t,kz:r,zh:o,ko:n,ja:s,hi:a,pt:i,de:p}),fi=sn("Score","\u041E\u0447\u043A\u0438","\u04B0\u043F\u0430\u0439","\u5206\u6570","\uC810\uC218","\u30B9\u30B3\u30A2","\u0938\u094D\u0915\u094B\u0930","Pontos","Punkte"),mc={id:"fantasy",version:1,setting:"fantasy",names:sn("Fantasy","\u0424\u044D\u043D\u0442\u0435\u0437\u0438","\u0424\u044D\u043D\u0442\u0435\u0437\u0438","\u5947\u5E7B","\uD310\uD0C0\uC9C0","\u30D5\u30A1\u30F3\u30BF\u30B8\u30FC","\u092B\u093C\u0948\u0902\u091F\u0947\u0938\u0940","Fantasia","Fantasy"),palette:{background:"#1f2a1d",ground:"#3b4a2e",lane:"#56683f",primary:"#4fa3e0",secondary:"#8e5bd1",danger:"#d0483b",coin:"#f2c14e",accent:"#6fbf4a",text:"#fff6e0",muted:"#b9b08f",piece1:"#e0443e",piece2:"#3f7fe0",piece3:"#43b05c",piece4:"#f2c14e",piece5:"#9b59d0",piece6:"#ef8a2f",panel:"#3a2f25"},texts:{"res.coins":sn("Gold","\u0417\u043E\u043B\u043E\u0442\u043E","\u0410\u043B\u0442\u044B\u043D","\u91D1\u5E01","\uACE8\uB4DC","\u30B4\u30FC\u30EB\u30C9","\u0938\u094B\u0928\u093E","Ouro","Gold"),"res.score":fi},races:["human","elf","dwarf","orc","undead"],cast:{hero:{preset:"knight",races:["human"]},foe:{preset:"berserker",parts:{Hat:null,Offhand:null,Weapon:"weapon/battle_axe"},races:["orc"]},foe2:{preset:"viking",parts:{Weapon:"weapon/double_axe"},races:["orc"]},boss:{preset:"dark_knight",races:["orc"]},helper:{preset:"hunter",parts:{Weapon:null,Hat:null},races:["elf","dwarf","human"]},foe3:{preset:"crossbowman",parts:{Weapon:"weapon/crossbow"},races:["undead"]},foe4:{preset:"lumberjack",parts:{Weapon:"weapon/spear",Back:null},races:["undead"]},foe5:{preset:"hunter",parts:{Hat:null,Back:null,Weapon:"weapon/dagger"},races:["undead"]},hero2:{preset:"crusader",races:["human","dwarf"]},hero3:{preset:"archmage",races:["elf"]}}},yc={id:"sci-fi",version:1,setting:"sci-fi",names:sn("Sci-fi","\u041D\u0430\u0443\u0447\u043D\u0430\u044F \u0444\u0430\u043D\u0442\u0430\u0441\u0442\u0438\u043A\u0430","\u0492\u044B\u043B\u044B\u043C\u0438 \u0444\u0430\u043D\u0442\u0430\u0441\u0442\u0438\u043A\u0430","\u79D1\u5E7B","SF","SF","\u0935\u093F\u091C\u094D\u091E\u093E\u0928 \u0915\u0925\u093E","Fic\xE7\xE3o cient\xEDfica","Science-Fiction"),palette:{background:"#0b1020",ground:"#151d33",lane:"#22305a",primary:"#36e3ff",secondary:"#b45cff",danger:"#ff3d6e",coin:"#ffe14d",accent:"#3dff9a",text:"#e8f6ff",muted:"#7d8fb3",piece1:"#ff3d6e",piece2:"#36a3ff",piece3:"#3dff9a",piece4:"#ffe14d",piece5:"#b45cff",piece6:"#ff8f3d",panel:"#18213d"},texts:{"res.coins":sn("Chips","\u0427\u0438\u043F\u044B","\u0427\u0438\u043F\u0442\u0435\u0440","\u82AF\u7247","\uCE69","\u30C1\u30C3\u30D7","\u091A\u093F\u092A\u094D\u0938","Chips","Chips"),"res.score":fi},races:["human"],cast:{hero:{preset:"soldier",races:["human"]},foe:{preset:"soldier",parts:{Hat:"hat/great_helm",Weapon:"weapon/pistol"},races:["undead"]},foe2:{preset:"gunslinger",parts:{Weapon:"weapon/rifle",Back:null},races:["orc"]},boss:{preset:"dark_knight",parts:{Weapon:"weapon/flame_sword"},races:["orc"]},helper:{preset:"gunslinger",parts:{Weapon:null,Back:null},races:["elf","human"]},foe3:{preset:"gunslinger",parts:{Weapon:"weapon/pistol",Back:null},races:["undead"]},foe4:{preset:"soldier",parts:{Hat:"hat/great_helm",Weapon:"weapon/spear"},races:["orc"]},foe5:{preset:"soldier",parts:{Hat:null,Back:null,Weapon:"weapon/dagger"},races:["undead"]},hero2:{preset:"musketeer",parts:{Weapon:"weapon/rifle"},races:["human"]},hero3:{preset:"archmage",parts:{Weapon:"weapon/wizard_staff"},races:["elf","human"]}}},gc={id:"cozy",version:1,setting:"cozy",names:sn("Cozy cartoon","\u0423\u044E\u0442\u043D\u044B\u0439 \u043C\u0443\u043B\u044C\u0442\u044F\u0448\u043D\u044B\u0439","\u0416\u0430\u0439\u043B\u044B \u043C\u0443\u043B\u044C\u0442\u0444\u0438\u043B\u044C\u043C","\u6E29\u99A8\u5361\u901A","\uC544\uB291\uD55C \uCE74\uD230","\u307B\u306E\u307C\u306E\u30AB\u30FC\u30C8\u30A5\u30FC\u30F3","\u0906\u0930\u093E\u092E\u0926\u093E\u092F\u0915 \u0915\u093E\u0930\u094D\u091F\u0942\u0928","Cartoon aconchegante","Gem\xFCtlicher Cartoon"),palette:{background:"#fdf1e4",ground:"#f3d9bf",lane:"#e9c6a3",primary:"#ff8fab",secondary:"#8fb8ff",danger:"#ff6b6b",coin:"#ffb627",accent:"#7ccf8a",text:"#3d2b25",muted:"#9c8478",piece1:"#ff8fab",piece2:"#7fb8ff",piece3:"#8cd98f",piece4:"#ffd166",piece5:"#c39bff",piece6:"#ffa96b",panel:"#fff8f0"},texts:{"res.coins":sn("Coins","\u041C\u043E\u043D\u0435\u0442\u043A\u0438","\u0422\u0438\u044B\u043D\u0434\u0430\u0440","\u786C\u5E01","\uCF54\uC778","\u30B3\u30A4\u30F3","\u0938\u093F\u0915\u094D\u0915\u0947","Moedas","M\xFCnzen"),"res.score":fi},races:["human","elf","dwarf"],cast:{hero:{preset:"camper",parts:{Glasses:null},races:["human"]},foe:{preset:"lumberjack",parts:{Weapon:"weapon/3",Back:null},races:["orc"]},foe2:{preset:"lumberjack",parts:{Weapon:null,Back:null},races:["dwarf"]},boss:{preset:"viking",races:["orc"]},helper:{preset:"camper",parts:{Weapon:null,Back:null,Glasses:null},races:["human","elf","dwarf"]},foe3:{preset:"hunter",parts:{Weapon:"weapon/hunting_bow"},races:["orc"]},foe4:{preset:"quarterback",races:["orc"]},foe5:{preset:"camper",parts:{Weapon:null,Back:null,Glasses:null},races:["orc"]},hero2:{preset:"quarterback",races:["human"]},hero3:{preset:"wizard",races:["elf"]}}},bc={id:"post-apocalypse",version:1,setting:"post-apocalypse",names:sn("Post-apocalypse","\u041F\u043E\u0441\u0442\u0430\u043F\u043E\u043A\u0430\u043B\u0438\u043F\u0441\u0438\u0441","\u041F\u043E\u0441\u0442\u0430\u043F\u043E\u043A\u0430\u043B\u0438\u043F\u0441\u0438\u0441","\u672B\u65E5\u5E9F\u571F","\uD3EC\uC2A4\uD2B8 \uC544\uD3EC\uCE7C\uB9BD\uC2A4","\u30DD\u30B9\u30C8\u30A2\u30DD\u30AB\u30EA\u30D7\u30B9","\u092A\u094D\u0930\u0932\u092F \u0915\u0947 \u092C\u093E\u0926","P\xF3s-apocalipse","Postapokalypse"),palette:{background:"#1d1a16",ground:"#3a3328",lane:"#4d4436",primary:"#d9a441",secondary:"#7a8f5b",danger:"#b8402d",coin:"#e0c060",accent:"#8fa35a",text:"#f0e6d2",muted:"#a39a86",piece1:"#b8402d",piece2:"#5a7f9a",piece3:"#7a8f5b",piece4:"#e0c060",piece5:"#8a6a4a",piece6:"#d9762f",panel:"#2c2620"},texts:{"res.coins":sn("Caps","\u041A\u0440\u044B\u0448\u043A\u0438","\u049A\u0430\u049B\u043F\u0430\u049B\u0442\u0430\u0440","\u74F6\u76D6","\uBCD1\uB69C\uAED1","\u30AD\u30E3\u30C3\u30D7","\u0922\u0915\u094D\u0915\u0928","Tampinhas","Kronkorken"),"res.score":fi},races:["human","undead","orc"],cast:{hero:{preset:"soldier",parts:{Hat:null,Gloves:"gloves/bracers"},races:["human"]},foe:{preset:"lumberjack",parts:{Weapon:null,Back:null,Gloves:null},races:["undead"]},foe2:{preset:"berserker",parts:{Hat:null,Offhand:null,Weapon:"weapon/mace"},races:["orc"]},boss:{preset:"berserker",parts:{Hat:"hat/great_helm",Weapon:"weapon/double_axe"},races:["orc"]},helper:{preset:"soldier",parts:{Hat:null,Weapon:null},races:["human"]},foe3:{preset:"musketeer",parts:{Weapon:"weapon/musket",Hat:null},races:["undead"]},foe4:{preset:"viking",parts:{Weapon:"weapon/mace"},races:["undead"]},foe5:{preset:"lumberjack",parts:{Weapon:"weapon/dagger",Back:null},races:["undead"]},hero2:{preset:"viking",parts:{Hat:null},races:["human"]},hero3:{preset:"ranger",races:["human"]}}},Co=[mc,yc,gc,bc],uc=(e,t)=>(e.flows??[]).some(r=>r.resource===t.resource&&r.by===t.by&&r.kind===t.kind)?e:{...e,flows:[...e.flows??[],t]},Df=e=>e.resources?.find(t=>t.kind==="currency")?.id??"coins",xc=e=>t=>uc(t,{resource:Df(t),by:`system:${e}`,kind:"sink"}),kc={id:"hero-upgrade",version:1,name:"link.hero-upgrade",core:["runner","platformer","survivors","tower-defense"],systems:["character"],apply:xc("character")},vc={id:"puzzle-city",version:1,name:"link.puzzle-city",core:["match3","merge"],systems:[],apply(e){if(e.modes.some(o=>o.id==="city"))return e;let t=Df(e),r={...e,modes:[...e.modes,{id:"city",preset:"tycoon",role:"meta"}]};return uc(uc(r,{resource:t,by:"city",kind:"source",amount:"vars.coins"}),{resource:t,by:"system:store",kind:"sink"})}},$c={id:"runner-collection",version:1,name:"link.runner-collection",core:["runner","platformer"],systems:["lootboxes","collections"],apply:xc("lootboxes")},Mc={id:"defense-boosts",version:1,name:"link.defense-boosts",core:["tower-defense","survivors"],systems:["boosts"],apply:xc("boosts")},pi=[kc,vc,$c,Mc];var Of=(e,t)=>`${e.character}-${t}`;var Cf={id:"runner",version:1,engine:"phaser",genre:"runner",name:"preset.runner",blocks:["round","lane-runner"],params:{difficulty:{type:"number",default:.5,min:0,max:1},generosity:{type:"number",default:.6,min:0,max:1},lanes:{type:"number",default:3,min:2,max:5,integer:true},lives:{type:"number",default:3,min:1,max:9,integer:true},length:{type:"number",default:1,min:.05,max:5}},blockParams:{"lane-runner":{lanes:"params.lanes",lives:"params.lives",difficulty:"params.difficulty",coinRate:"0.5 + params.generosity * 0.4",powerRate:"0.12 + params.generosity * 0.2",lengthScale:"params.length"}},produces:["soft","score"],placements:[{id:"reward_window",kind:"reward-window"},{id:"revive",kind:"revive",dailyLimit:5}]},Po={difficulty:{type:"number",default:.5,min:0,max:1},generosity:{type:"number",default:.6,min:0,max:1}},Io=[{id:"reward_window",kind:"reward-window"}],Pf={id:"platformer",version:1,engine:"phaser",genre:"platformer",name:"preset.platformer",blocks:["round","platformer"],params:{...Po,lives:{type:"number",default:3,min:1,max:9,integer:true},doubleJump:{type:"boolean",default:false}},blockParams:{platformer:{difficulty:"params.difficulty",lives:"params.lives",doubleJump:"params.doubleJump"}},produces:["soft","score"],placements:[...Io,{id:"revive",kind:"revive",dailyLimit:5}]},If={id:"survivors",version:1,engine:"phaser",genre:"survivors",name:"preset.survivors",blocks:["round","survivors"],params:{...Po,minutes:{type:"number",default:5,min:.5,max:15}},blockParams:{survivors:{duration:"params.minutes * 60",spawnRate:"0.9 + params.difficulty * 0.6",spawnGrowth:"0.6 + params.difficulty * 0.6",foeHpGrowth:"0.3 + params.difficulty * 0.3",foeDamage:"0.8 + params.difficulty * 0.4",coinRate:"0.15 + params.generosity * 0.3",hp:"120 - params.difficulty * 40"}},produces:["soft","score"],placements:[...Io,{id:"revive",kind:"revive",dailyLimit:5},{id:"reroll",kind:"retry",dailyLimit:10}]},Nf={id:"tower-defense",version:2,engine:"phaser",genre:"tower-defense",name:"preset.tower-defense",blocks:["round","tower-defense"],params:{...Po,lives:{type:"number",default:20,min:1,max:100,integer:true}},blockParams:{"tower-defense":{difficulty:"params.difficulty",lives:"params.lives",coinRate:"0.08 + params.generosity * 0.25",earlyGold:"1 + params.generosity * 2"}},produces:["soft","score"],placements:[...Io,{id:"revive",kind:"revive",dailyLimit:5}]},zf={id:"match3",version:2,engine:"phaser",genre:"match3",name:"preset.match3",blocks:["round","match3"],params:{...Po},blockParams:{match3:{difficulty:"params.difficulty",coinEvery:"12 - params.generosity * 7"}},produces:["soft","score","stars"],placements:[...Io,{id:"revive",kind:"revive",dailyLimit:5}]},Bf={id:"merge",version:2,engine:"phaser",genre:"merge",name:"preset.merge",blocks:["round","merge"],params:{...Po},blockParams:{merge:{difficulty:"params.difficulty",orderReward:"0.6 + params.generosity * 0.8"}},produces:["soft","score","stars"],placements:[...Io,{id:"revive",kind:"revive",dailyLimit:5}]},Hf={id:"tycoon",version:2,engine:"phaser",genre:"idle-tycoon",name:"preset.tycoon",blocks:["round","tycoon"],params:{...Po},blockParams:{tycoon:{difficulty:"params.difficulty",coinReward:"0.6 + params.generosity * 0.8"}},produces:["soft","score","stars"],placements:[...Io,{id:"revive",kind:"revive",dailyLimit:5}]},Wf=[Cf,Pf,If,Nf,zf,Bf,Hf],vu=[Gs,qs,Sa,Ca,Va,da,va,di];function $u(e){Ho(e);for(let t of vu)e.has(dn,t.id)||e.define(dn,t);for(let t of Co)e.has(Fn,t.id)||e.define(Fn,t);for(let t of pi)e.has(Wo,t.id)||e.define(Wo,t);for(let t of Wf)e.has(fn,t.id)||e.define(fn,t);}var Mu={v:1,engine:"phaser",seed:"demo-runner",modes:[{id:"run",preset:"runner",role:"core"}],resources:[{id:"coins",kind:"currency",ref:"CO",name:"res.coins"},{id:"score",kind:"score",name:"res.score"}],flows:[{resource:"coins",by:"run",kind:"source",amount:"vars.coins"},{resource:"coins",by:"system:store",kind:"sink"},{resource:"score",by:"run",kind:"source",amount:"vars.score"}],texts:{title:{en:"Lane Dash",ru:"\u0420\u044B\u0432\u043E\u043A \u043F\u043E \u043F\u043E\u043B\u043E\u0441\u0430\u043C"},hint:{en:"Swipe or tap a side to change lanes",ru:"\u0421\u0432\u0430\u0439\u043F \u0438\u043B\u0438 \u043D\u0430\u0436\u0430\u0442\u0438\u0435 \u0441\u0431\u043E\u043A\u0443 \u043C\u0435\u043D\u044F\u0435\u0442 \u043F\u043E\u043B\u043E\u0441\u0443"}}};function wu(e,t={}){let r=e==="runner"?"run":"main";return {v:1,engine:"phaser",seed:t.seed??e,modes:[{id:r,preset:e,role:"core",...t.params?{params:t.params}:{}}],resources:[{id:"coins",kind:"currency",ref:t.coinRef??"CO",name:"res.coins"},{id:"score",kind:"score",name:"res.score"}],flows:[{resource:"coins",by:r,kind:"source",amount:"vars.coins"},{resource:"coins",by:"system:store",kind:"sink"},{resource:"score",by:r,kind:"source",amount:"vars.score"}],...t.texts?{texts:t.texts}:{},...t.palette?{palette:t.palette}:{},...t.assets?{assets:t.assets}:{}}}var jf=255,Vf=10;var an=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),ui=e=>e===void 0?e:JSON.parse(JSON.stringify(e)),Gf=(e,t)=>JSON.stringify(e)===JSON.stringify(t),Eu=/^([A-Za-z0-9_-]+)(?:\[([A-Za-z0-9_-]+)=([^\]]*)\])?$/,Su=/^'([^']+)'$/;function Lu(e){let t=[],r="",o=false;for(let n of e)n==="'"&&(o=!o),n==="."&&!o?(t.push(r),r=""):r+=n;return t.push(r),t}function mi(e){if(!e)return [];let t=[];for(let r of Lu(e)){let o=Su.exec(r);if(o){t.push({key:o[1]});continue}let n=Eu.exec(r);if(!n)return null;t.push(n[2]!==void 0?{key:n[1],match:{field:n[2],value:n[3]??""}}:{key:n[1]});}return t}function Kf(e,t){let r=e.range;if(!r||t===void 0)return e.value;let o=Math.min(Math.max(Number.isFinite(t)?t:.5,0),1),n=r.min+o*(r.max-r.min);if(r.integer)return Math.round(n);let s=10**(r.digits??2);return Math.round(n*s)/s}function hi(e,t){if(!an(e)||!an(t))return ui(t);let r={...e};for(let[o,n]of Object.entries(t))r[o]=o in r?hi(r[o],n):ui(n);return r}function _u(e,t,r){let o=an(e)?ui(e):{},n=[];return t.forEach((s,a)=>{let i=mi(s.path);if(!i){n.push(a);return}let p=ui(Kf(s,r));if(i.length===0){s.op==="set"&&an(p)?o=p:s.op==="merge"&&an(p)?o=hi(o,p):n.push(a);return}let m=o;for(let k=0;k<i.length-1;k++){let O=Ru(m,i[k],s.ifExists!==true);if(O===void 0){n.push(a);return}m=O;}let $=i[i.length-1];if(!an(m)){n.push(a);return}if($.match){let k=m[$.key];if(!Array.isArray(k)){n.push(a);return}let O=k.findIndex(C=>an(C)&&String(C[$.match.field])===$.match.value);if(O<0){n.push(a);return}s.op==="set"?k[O]=p:s.op==="merge"?k[O]=hi(k[O],p):s.op==="unset"?k.splice(O,1):n.push(a);return}if(s.ifExists===true&&m[$.key]===void 0){n.push(a);return}switch(s.op){case "set":m[$.key]=p;break;case "merge":m[$.key]=m[$.key]===void 0?p:hi(m[$.key],p);break;case "unset":delete m[$.key];break;case "add":case "remove":{let k=Array.isArray(p)?p:[p],O=m[$.key];if(O!==void 0&&!Array.isArray(O)){n.push(a);return}let C=O?[...O]:[];if(s.op==="add")for(let z of k)C.some(F=>Gf(F,z))||C.push(z);else for(let z of k){let F=C.findIndex(ne=>Gf(ne,z));F>=0&&C.splice(F,1);}m[$.key]=C;break}}}),{value:o,skipped:n}}function Ru(e,t,r){if(an(e)){if(t.match){let o=e[t.key];return Array.isArray(o)?o.find(n=>an(n)&&String(n[t.match.field])===t.match.value):void 0}if(e[t.key]===void 0||e[t.key]===null){if(!r)return;e[t.key]={};}return e[t.key]}}function Au(e){return [...new Set(e.map(t=>`${t.section}:${t.path??""}`))]}var Tu=/^#([0-9a-f]{6})$/i;function Ff(e){let t=Tu.exec(e);if(!t)return [0,0,.5];let r=parseInt(t[1],16),o=(r>>16&255)/255,n=(r>>8&255)/255,s=(r&255)/255,a=Math.max(o,n,s),i=Math.min(o,n,s),p=(a+i)/2;if(a===i)return [0,0,p];let m=a-i,$=p>.5?m/(2-a-i):m/(a+i),k=a===o?(n-s)/m+(n<s?6:0):a===n?(s-o)/m+2:(o-n)/m+4;return k*=60,[k,$,p]}function qf(e,t,r){let o=(e%360+360)%360/360,n=Math.min(Math.max(t,0),1),s=Math.min(Math.max(r,0),1),a=p=>{let m=p;m<0&&(m+=1),m>1&&(m-=1);let $=s<.5?s*(1+n):s+n-s*n,k=2*s-$;return m<1/6?k+($-k)*6*m:m<1/2?$:m<2/3?k+($-k)*(2/3-m)*6:k},i=p=>Math.round(p*255).toString(16).padStart(2,"0");return n===0?`#${i(s)}${i(s)}${i(s)}`:`#${i(a(o+1/3))}${i(a(o))}${i(a(o-1/3))}`}function yi(e,t,r=1,o=0){let[n,s,a]=Ff(e);return qf(n+t,s*r,a+o)}function gi(e,t){let[r,o,n]=Ff(e);return qf(r,o,n*(1-t))}var Oe=(e,t)=>({en:e,ru:t}),Ec=(e,t)=>({section:"Look",op:"set",path:e,value:t}),wc=(e,t)=>({section:"GameSpec",op:"set",path:e,value:t}),Du=[{id:"casual-violet",title:Oe("Violet casual","\u0424\u0438\u043E\u043B\u0435\u0442\u043E\u0432\u044B\u0439 \u043A\u0430\u0437\u0443\u0430\u043B"),what:"Bright blue-violet screens, chunky glossy buttons: the classic mobile casual look.",examples:["any casual game","puzzle","arcade"],bgTop:"#5865f2",bgBottom:"#5a3fd6",panel:"#3d8ff5",nav:"#2c3794",ink:"#17193a"},{id:"candy-pink",title:Oe("Candy pink","\u0420\u043E\u0437\u043E\u0432\u0430\u044F \u043A\u043E\u043D\u0444\u0435\u0442\u0430"),what:"Sweet pink and raspberry, playful and girly, candy shop mood.",examples:["sweets","fashion","pets","kids"],bgTop:"#ff7ac6",bgBottom:"#d94a9c",panel:"#ff9ad5",nav:"#a8306f",ink:"#4a1235"},{id:"sunny-orange",title:Oe("Sunny orange","\u0421\u043E\u043B\u043D\u0435\u0447\u043D\u044B\u0439 \u043E\u0440\u0430\u043D\u0436\u0435\u0432\u044B\u0439"),what:"Warm orange and yellow, cheerful summer energy.",examples:["beach","fruit","summer","food"],bgTop:"#ffb347",bgBottom:"#ff7a2f",panel:"#ffc75f",nav:"#c4521b",ink:"#4a2410"},{id:"forest-green",title:Oe("Forest green","\u041B\u0435\u0441\u043D\u043E\u0439 \u0437\u0435\u043B\u0451\u043D\u044B\u0439"),what:"Deep greens of a forest, calm nature mood.",examples:["farm","nature","elves","camping"],bgTop:"#4caf50",bgBottom:"#2e7d32",panel:"#66bb6a",nav:"#1b5e20",ink:"#0f2e12"},{id:"ocean-blue",title:Oe("Ocean blue","\u041E\u043A\u0435\u0430\u043D\u0441\u043A\u0438\u0439 \u0441\u0438\u043D\u0438\u0439"),what:"Sea blue and aqua, fresh water mood.",examples:["ocean","fishing","pirates","islands"],bgTop:"#29b6f6",bgBottom:"#0277bd",panel:"#4fc3f7",nav:"#01579b",ink:"#062c47"},{id:"midnight-navy",title:Oe("Midnight navy","\u041F\u043E\u043B\u043D\u043E\u0447\u043D\u044B\u0439 \u0441\u0438\u043D\u0438\u0439"),what:"Dark navy night, calm and serious, stars at night.",examples:["space","night","strategy","sleep"],bgTop:"#283593",bgBottom:"#0d1442",panel:"#3949ab",nav:"#141a52",ink:"#070a22"},{id:"neon-cyber",title:Oe("Neon cyber","\u041D\u0435\u043E\u043D\u043E\u0432\u044B\u0439 \u043A\u0438\u0431\u0435\u0440"),what:"Black with neon cyan and magenta, cyberpunk and synthwave.",examples:["cyberpunk","hackers","racing at night","sci-fi"],bgTop:"#1a1033",bgBottom:"#07040f",panel:"#2b1a55",nav:"#120a26",ink:"#00e5ff",gold:"#ff3df5",green:"#00ffa3"},{id:"space-purple",title:Oe("Space purple","\u041A\u043E\u0441\u043C\u0438\u0447\u0435\u0441\u043A\u0438\u0439 \u043F\u0443\u0440\u043F\u0443\u0440"),what:"Deep purple space with nebula tones.",examples:["space","aliens","galaxy","magic"],bgTop:"#6a1b9a",bgBottom:"#2a0845",panel:"#8e24aa",nav:"#38006b",ink:"#16001f"},{id:"lava-red",title:Oe("Lava red","\u041B\u0430\u0432\u043E\u0432\u044B\u0439 \u043A\u0440\u0430\u0441\u043D\u044B\u0439"),what:"Hot red and black, danger, fire and action.",examples:["fire","volcano","action","boss fights"],bgTop:"#e53935",bgBottom:"#7f0000",panel:"#ef5350",nav:"#5c0000",ink:"#2a0000"},{id:"royal-gold",title:Oe("Royal gold","\u041A\u043E\u0440\u043E\u043B\u0435\u0432\u0441\u043A\u043E\u0435 \u0437\u043E\u043B\u043E\u0442\u043E"),what:"Gold and deep burgundy, rich, royal and luxurious.",examples:["kings","casino","treasure","empire"],bgTop:"#8e2b3a",bgBottom:"#4a0f1c",panel:"#b3424f",nav:"#3a0a15",ink:"#1f0509",gold:"#ffcf40"},{id:"ice-frost",title:Oe("Ice frost","\u041B\u0435\u0434\u044F\u043D\u043E\u0439"),what:"Pale icy blue and white, winter and snow.",examples:["winter","snow","christmas","north"],bgTop:"#e3f6ff",bgBottom:"#9fd7f5",panel:"#ffffff",nav:"#5aa6d6",ink:"#1d4a6b",light:true},{id:"paper-light",title:Oe("Paper light","\u0421\u0432\u0435\u0442\u043B\u0430\u044F \u0431\u0443\u043C\u0430\u0433\u0430"),what:"Clean light paper, minimal and calm, for word and brain games.",examples:["words","quiz","sudoku","education"],bgTop:"#fbf7ef",bgBottom:"#efe6d5",panel:"#ffffff",nav:"#cdbfa6",ink:"#3d3428",light:true},{id:"mint-fresh",title:Oe("Mint fresh","\u0421\u0432\u0435\u0436\u0430\u044F \u043C\u044F\u0442\u0430"),what:"Light mint and teal, fresh and soft.",examples:["cafe","health","relax","spa"],bgTop:"#b9f6e3",bgBottom:"#5fd4b0",panel:"#e6fff7",nav:"#2f9b80",ink:"#0e3d33",light:true},{id:"lemon-pop",title:Oe("Lemon pop","\u041B\u0438\u043C\u043E\u043D\u043D\u044B\u0439 \u043F\u043E\u043F"),what:"Bright lemon yellow, loud and happy pop art.",examples:["comics","party","kids","music"],bgTop:"#fff176",bgBottom:"#fbc02d",panel:"#fff9c4",nav:"#c49000",ink:"#3d2c00",light:true},{id:"peach-soft",title:Oe("Soft peach","\u041D\u0435\u0436\u043D\u044B\u0439 \u043F\u0435\u0440\u0441\u0438\u043A"),what:"Soft peach and coral pastel, cosy and gentle.",examples:["cooking","home decor","romance","pets"],bgTop:"#ffd3b6",bgBottom:"#ffaa85",panel:"#fff0e6",nav:"#d9775a",ink:"#4a2418",light:true},{id:"lavender-dream",title:Oe("Lavender dream","\u041B\u0430\u0432\u0430\u043D\u0434\u043E\u0432\u044B\u0439 \u0441\u043E\u043D"),what:"Pastel lavender, dreamy and magical.",examples:["fairies","unicorns","dreams","princess"],bgTop:"#e1d5ff",bgBottom:"#b39ddb",panel:"#f5f0ff",nav:"#7e57c2",ink:"#2e1a4d",light:true},{id:"toxic-lime",title:Oe("Toxic lime","\u042F\u0434\u043E\u0432\u0438\u0442\u044B\u0439 \u043B\u0430\u0439\u043C"),what:"Acid lime on dark, toxic, zombies and slime.",examples:["zombies","slime","chemistry","monsters"],bgTop:"#33402a",bgBottom:"#141a10",panel:"#4b5e35",nav:"#1c2414",ink:"#a6ff00",gold:"#d4ff3d",green:"#7dff2a"},{id:"desert-sand",title:Oe("Desert sand","\u041F\u0443\u0441\u0442\u044B\u043D\u043D\u044B\u0439 \u043F\u0435\u0441\u043E\u043A"),what:"Sand, ochre and terracotta, desert and ancient ruins.",examples:["egypt","western","desert","archaeology"],bgTop:"#e0b075",bgBottom:"#b5763f",panel:"#f0c995",nav:"#8a5126",ink:"#3b2210"},{id:"rust-wasteland",title:Oe("Rust wasteland","\u0420\u0436\u0430\u0432\u0430\u044F \u043F\u0443\u0441\u0442\u043E\u0448\u044C"),what:"Rusty brown and dusty orange, post-apocalypse scrap.",examples:["post-apocalypse","scrap","survival","mad roads"],bgTop:"#6d4c41",bgBottom:"#2e1f1a",panel:"#8d6e63",nav:"#3e2723",ink:"#140c09",gold:"#ff9e40"},{id:"steel-gray",title:Oe("Steel gray","\u0421\u0442\u0430\u043B\u044C\u043D\u043E\u0439 \u0441\u0435\u0440\u044B\u0439"),what:"Cool steel and graphite, military and industrial.",examples:["army","tanks","factory","robots"],bgTop:"#607d8b",bgBottom:"#263238",panel:"#78909c",nav:"#1c262b",ink:"#0b1013"},{id:"jungle-teal",title:Oe("Jungle teal","\u0422\u0440\u043E\u043F\u0438\u0447\u0435\u0441\u043A\u0438\u0439 \u0431\u0438\u0440\u044E\u0437\u043E\u0432\u044B\u0439"),what:"Teal and jungle green, tropical adventure.",examples:["jungle","tropics","dinosaurs","explorers"],bgTop:"#26a69a",bgBottom:"#00695c",panel:"#4db6ac",nav:"#004d40",ink:"#00211c"},{id:"berry-plum",title:Oe("Berry plum","\u042F\u0433\u043E\u0434\u043D\u0430\u044F \u0441\u043B\u0438\u0432\u0430"),what:"Plum and berry purple, juicy and rich.",examples:["berries","potions","fashion","music"],bgTop:"#ad1457",bgBottom:"#4a0072",panel:"#c2185b",nav:"#38004d",ink:"#1a0024"},{id:"sky-day",title:Oe("Clear sky","\u042F\u0441\u043D\u043E\u0435 \u043D\u0435\u0431\u043E"),what:"Light sky blue with white clouds, open and friendly.",examples:["flying","birds","kids","travel"],bgTop:"#bfe9ff",bgBottom:"#6ec6ff",panel:"#ffffff",nav:"#3a9ad9",ink:"#123a5a",light:true},{id:"chocolate",title:Oe("Chocolate","\u0428\u043E\u043A\u043E\u043B\u0430\u0434"),what:"Brown chocolate and caramel, sweet and warm.",examples:["bakery","coffee","sweets","autumn"],bgTop:"#8d5a3b",bgBottom:"#4e2c1a",panel:"#a6704b",nav:"#3b2012",ink:"#1a0d06",gold:"#ffc56b"},{id:"autumn-maple",title:Oe("Autumn maple","\u041E\u0441\u0435\u043D\u043D\u0438\u0439 \u043A\u043B\u0451\u043D"),what:"Orange and red autumn leaves, harvest mood.",examples:["autumn","halloween","harvest","forest"],bgTop:"#ef6c00",bgBottom:"#8c2f00",panel:"#f57c00",nav:"#6b2300",ink:"#2b0e00"},{id:"spooky-night",title:Oe("Spooky night","\u0416\u0443\u0442\u043A\u0430\u044F \u043D\u043E\u0447\u044C"),what:"Dark purple and pumpkin orange, ghosts and halloween.",examples:["halloween","ghosts","horror lite","witches"],bgTop:"#311b92",bgBottom:"#120838",panel:"#4527a0",nav:"#0d0629",ink:"#05020f",gold:"#ff8f00"},{id:"sakura",title:Oe("Sakura","\u0421\u0430\u043A\u0443\u0440\u0430"),what:"Cherry blossom pink with soft white, japanese spring.",examples:["japan","anime","spring","ninja lite"],bgTop:"#ffd6e7",bgBottom:"#f48fb1",panel:"#fff3f8",nav:"#c2185b",ink:"#4d0f2a",light:true},{id:"matrix-green",title:Oe("Terminal green","\u0422\u0435\u0440\u043C\u0438\u043D\u0430\u043B\u044C\u043D\u044B\u0439 \u0437\u0435\u043B\u0451\u043D\u044B\u0439"),what:"Black with bright terminal green, hacker console.",examples:["hacking","code","retro computers","spy"],bgTop:"#0b1f0f",bgBottom:"#000000",panel:"#123317",nav:"#06120a",ink:"#39ff6a",gold:"#c6ff00",green:"#39ff6a"},{id:"retro-arcade",title:Oe("Retro arcade","\u0420\u0435\u0442\u0440\u043E-\u0430\u0440\u043A\u0430\u0434\u0430"),what:"Eighties arcade: deep blue with hot pink and yellow.",examples:["retro","pixel","80s","arcade"],bgTop:"#1e2a78",bgBottom:"#0a0f3d",panel:"#ff2e88",nav:"#0a0f3d",ink:"#05071f",gold:"#ffe600"},{id:"stone-dungeon",title:Oe("Stone dungeon","\u041A\u0430\u043C\u0435\u043D\u043D\u043E\u0435 \u043F\u043E\u0434\u0437\u0435\u043C\u0435\u043B\u044C\u0435"),what:"Dark stone and torchlight, dungeons and castles.",examples:["dungeon","castle","knights","rpg"],bgTop:"#4e4a46",bgBottom:"#1f1c1a",panel:"#6b655e",nav:"#171513",ink:"#0a0908",gold:"#ffb300"},{id:"emerald-luxe",title:Oe("Emerald luxe","\u0418\u0437\u0443\u043C\u0440\u0443\u0434\u043D\u044B\u0439 \u043B\u044E\u043A\u0441"),what:"Emerald green with gold, wealth and luck.",examples:["casino","luck","money","irish"],bgTop:"#00695c",bgBottom:"#00251a",panel:"#00897b",nav:"#001a12",ink:"#000c08",gold:"#ffd54f"},{id:"bubblegum",title:Oe("Bubblegum","\u0416\u0432\u0430\u0447\u043A\u0430"),what:"Pastel cyan and pink together, fun and bouncy.",examples:["kids","toys","party","bubbles"],bgTop:"#a0f0ff",bgBottom:"#ff9fe0",panel:"#ffffff",nav:"#d66bb4",ink:"#3a1f4d",light:true},{id:"military-olive",title:Oe("Military olive","\u0410\u0440\u043C\u0435\u0439\u0441\u043A\u0430\u044F \u043E\u043B\u0438\u0432\u0430"),what:"Olive drab and khaki, army and survival.",examples:["army","war","survival","hunting"],bgTop:"#6b7a3a",bgBottom:"#33391b",panel:"#808f4a",nav:"#262b14",ink:"#101207",gold:"#e6c34d"},{id:"deep-sea",title:Oe("Deep sea","\u041C\u043E\u0440\u0441\u043A\u0430\u044F \u0431\u0435\u0437\u0434\u043D\u0430"),what:"Very dark teal-blue of the deep ocean with glowing tones.",examples:["submarine","deep sea","mermaids","monsters"],bgTop:"#004e64",bgBottom:"#001219",panel:"#00677f",nav:"#000c11",ink:"#000508",gold:"#94fbab",green:"#4dfff3"},{id:"sunset",title:Oe("Sunset","\u0417\u0430\u043A\u0430\u0442"),what:"Orange to purple sunset gradient, warm evening.",examples:["travel","music","romance","racing"],bgTop:"#ff8a65",bgBottom:"#6a1b9a",panel:"#ff7043",nav:"#4a148c",ink:"#1f0738"},{id:"arctic-night",title:Oe("Polar night","\u041F\u043E\u043B\u044F\u0440\u043D\u0430\u044F \u043D\u043E\u0447\u044C"),what:"Dark blue with aurora green and cyan.",examples:["aurora","north","winter night","magic"],bgTop:"#0d3b66",bgBottom:"#021526",panel:"#145374",nav:"#01101e",ink:"#000810",gold:"#7cf5c8",green:"#3ff2a0"},{id:"honey",title:Oe("Honey","\u041C\u0451\u0434"),what:"Golden honey amber, warm and sweet, bees and farms.",examples:["bees","farm","bakery","sunny"],bgTop:"#ffca28",bgBottom:"#ff8f00",panel:"#ffe082",nav:"#b26a00",ink:"#3d2400"},{id:"monochrome",title:Oe("Monochrome","\u041C\u043E\u043D\u043E\u0445\u0440\u043E\u043C"),what:"Black, white and gray only, strict and stylish.",examples:["noir","minimal","chess","detective"],bgTop:"#3a3a3a",bgBottom:"#111111",panel:"#555555",nav:"#0c0c0c",ink:"#000000",gold:"#ffffff",green:"#d9d9d9"},{id:"tropical-punch",title:Oe("Tropical punch","\u0422\u0440\u043E\u043F\u0438\u0447\u0435\u0441\u043A\u0438\u0439 \u043F\u0443\u043D\u0448"),what:"Hot coral, turquoise and yellow, tropical party.",examples:["tropics","summer party","cocktails","carnival"],bgTop:"#ff5e62",bgBottom:"#ff9966",panel:"#1de9b6",nav:"#c2364a",ink:"#3d0f16"},{id:"cloud-gray",title:Oe("Soft gray","\u041C\u044F\u0433\u043A\u0438\u0439 \u0441\u0435\u0440\u044B\u0439"),what:"Light neutral gray, calm and modern, apps and tools.",examples:["tools","productivity","calm puzzle","office"],bgTop:"#f2f4f7",bgBottom:"#d5dae1",panel:"#ffffff",nav:"#8a94a6",ink:"#2b313b",light:true}];function Ou(e){let t={bgTop:e.bgTop,bgBottom:e.bgBottom,panel:e.panel,panelDeep:gi(e.panel,.18),panelEdge:e.ink,ink:e.ink,nav:e.nav,text:e.light?e.ink:"#ffffff",textDim:e.light?yi(e.ink,0,.6,.25):yi(e.panel,0,.5,.35)};return e.gold&&(t.gold=e.gold,t.goldDeep=gi(e.gold,.2)),e.green&&(t.green=e.green,t.greenDeep=gi(e.green,.25)),{id:e.id,title:e.title,what:e.what,examples:e.examples,swatch:[e.bgTop,e.bgBottom,e.panel,e.gold??"#ffd43b"],patches:[Ec("Theme",t)]}}var Uf=Du.map(Ou),Cu=[{id:"classic",title:Oe("Classic","\u041A\u043B\u0430\u0441\u0441\u0438\u043A\u0430"),what:"The pack's own colours.",dh:0,sat:1,dl:0},{id:"dawn",title:Oe("Dawn","\u0420\u0430\u0441\u0441\u0432\u0435\u0442"),what:"Lighter and warmer, a morning mood.",dh:20,sat:1.05,dl:.08},{id:"night",title:Oe("Night","\u041D\u043E\u0447\u044C"),what:"Darker and bluer, a night mood.",dh:-35,sat:.9,dl:-0.07},{id:"ember",title:Oe("Ember","\u0423\u0433\u043B\u0438"),what:"Shifted to red and orange, hot and dangerous.",dh:-60,sat:1.15,dl:0},{id:"frost",title:Oe("Frost","\u0418\u043D\u0435\u0439"),what:"Shifted to cyan and pale blue, cold and icy.",dh:140,sat:.8,dl:.05},{id:"toxic",title:Oe("Toxic","\u042F\u0434"),what:"Shifted to acid green and yellow, toxic.",dh:70,sat:1.25,dl:0},{id:"royal",title:Oe("Royal","\u041A\u043E\u0440\u043E\u043B\u0435\u0432\u0441\u043A\u0438\u0439"),what:"Shifted to purple and violet, magical and noble.",dh:200,sat:1.1,dl:0},{id:"faded",title:Oe("Faded","\u0412\u044B\u0446\u0432\u0435\u0442\u0448\u0438\u0439"),what:"Muted, low saturation, old photo and dusty.",dh:0,sat:.45,dl:.03}],Pu=["background","ground","lane","primary","secondary","accent","muted","panel"],Xf=Co.flatMap(e=>Cu.map(t=>{let r={...e.palette};for(let o of Pu){let n=e.palette[o];n&&(r[o]=yi(n,t.dh,t.sat,t.dl));}return {id:`${e.id}-${t.id}`,title:{en:`${e.names.en??e.id}: ${t.title.en}`,ru:`${e.names.ru??e.id}: ${t.title.ru}`},what:`${e.names.en??e.id} world. ${t.what}`,swatch:[r.background,r.ground,r.primary,r.accent],patches:[wc("assets",e.id),wc("palette",r)]}})),Iu=[["knight","Knight","\u0420\u044B\u0446\u0430\u0440\u044C","An armoured knight with a sword and shield, brave and classic."],["dark_knight","Dark knight","\u0422\u0451\u043C\u043D\u044B\u0439 \u0440\u044B\u0446\u0430\u0440\u044C","A knight in black armour, grim and mighty."],["archmage","Archmage","\u0410\u0440\u0445\u0438\u043C\u0430\u0433","An old wizard in robes with a staff, magic and wisdom."],["berserker","Berserker","\u0411\u0435\u0440\u0441\u0435\u0440\u043A","A wild warrior with a big axe, rage and strength."],["hunter","Hunter","\u041E\u0445\u043E\u0442\u043D\u0438\u043A","A hunter with a bow and a hood, forests and tracking."],["crossbowman","Crossbowman","\u0410\u0440\u0431\u0430\u043B\u0435\u0442\u0447\u0438\u043A","A soldier with a crossbow, a careful shooter."],["gunslinger","Gunslinger","\u0421\u0442\u0440\u0435\u043B\u043E\u043A","A cowboy gunslinger, the wild west and duels."],["musketeer","Musketeer","\u041C\u0443\u0448\u043A\u0435\u0442\u0451\u0440","A musketeer with a hat and a musket, honour and adventure."],["soldier","Soldier","\u0421\u043E\u043B\u0434\u0430\u0442","A modern soldier with a rifle, war and missions."],["quarterback","Quarterback","\u041A\u0432\u043E\u0442\u0435\u0440\u0431\u0435\u043A","An american football player, sport and teams."],["lumberjack","Lumberjack","\u041B\u0435\u0441\u043E\u0440\u0443\u0431","A bearded lumberjack in a checked shirt with an axe, woods and work."],["viking","Viking","\u0412\u0438\u043A\u0438\u043D\u0433","A horned viking with a hammer, the north and raids."],["wizard","Wizard","\u0412\u043E\u043B\u0448\u0435\u0431\u043D\u0438\u043A","A young wizard with a pointy hat, spells and school of magic."],["ranger","Ranger","\u0421\u043B\u0435\u0434\u043E\u043F\u044B\u0442","A ranger of the wild, light armour and a long bow."],["king","King","\u041A\u043E\u0440\u043E\u043B\u044C","A king with a crown and a cape, kingdoms and rule."],["camper","Camper","\u0422\u0443\u0440\u0438\u0441\u0442","A casual hiker with a backpack, everyday modern life."],["crusader","Crusader","\u041A\u0440\u0435\u0441\u0442\u043E\u043D\u043E\u0441\u0435\u0446","A holy warrior in white and gold, light against darkness."]],Zf=Iu.map(([e,t,r,o])=>({id:e,title:Oe(t,r),what:o,patches:[wc("cast.hero.preset",e)]})),Qf=[["gear","Game gear","\u0418\u0433\u0440\u043E\u0432\u044B\u0435 \u043F\u0440\u0435\u0434\u043C\u0435\u0442\u044B","Faint swords, shields, potions, gems and crowns: the classic casual game look."],["plain","Plain gradient","\u0427\u0438\u0441\u0442\u044B\u0439 \u0433\u0440\u0430\u0434\u0438\u0435\u043D\u0442","No pattern, only the theme's gradient."],["dots","Polka dots","\u0413\u043E\u0440\u043E\u0448\u0435\u043A","Soft polka dots, playful."],["stripes","Diagonal stripes","\u0414\u0438\u0430\u0433\u043E\u043D\u0430\u043B\u044C\u043D\u044B\u0435 \u043F\u043E\u043B\u043E\u0441\u044B","Diagonal stripes, energetic and sporty."],["grid","Grid","\u0421\u0435\u0442\u043A\u0430","A thin grid like graph paper, tech or puzzle."],["hex","Honeycomb","\u0421\u043E\u0442\u044B","A honeycomb pattern, bees, sci-fi or strategy."],["stars","Stars","\u0417\u0432\u0451\u0437\u0434\u044B","Small scattered stars, night, space or magic."],["waves","Waves","\u0412\u043E\u043B\u043D\u044B","Soft waves, water and the sea."],["checker","Checkerboard","\u0428\u0430\u0445\u043C\u0430\u0442\u043A\u0430","A checkerboard, board games, racing flags."],["confetti","Confetti","\u041A\u043E\u043D\u0444\u0435\u0442\u0442\u0438","Colourful confetti bits, party and celebration."],["bubbles","Bubbles","\u041F\u0443\u0437\u044B\u0440\u0438","Round bubbles of different sizes, underwater or soda."],["zigzag","Zigzag","\u0417\u0438\u0433\u0437\u0430\u0433","A bold zigzag, retro and pop."],["diamonds","Diamonds","\u0420\u043E\u043C\u0431\u044B","A diamond pattern, cards, casino, royal."],["clouds","Clouds","\u041E\u0431\u043B\u0430\u043A\u0430","Puffy clouds, sky and dreams."],["leaves","Leaves","\u041B\u0438\u0441\u0442\u044C\u044F","Scattered leaves, nature, forest and autumn."],["circuit","Circuit","\u041C\u0438\u043A\u0440\u043E\u0441\u0445\u0435\u043C\u0430","Circuit board lines, robots, hackers and tech."],["sparkles","Sparkles","\u0418\u0441\u043A\u0440\u044B","Twinkling sparkles, magic, fairies and treasure."],["rays","Sun rays","\u041B\u0443\u0447\u0438","Rays from the centre, victory and big wins."],["bricks","Bricks","\u041A\u0438\u0440\u043F\u0438\u0447\u0438","A brick wall, city, castle or dungeon."],["paws","Paw prints","\u0421\u043B\u0435\u0434\u044B \u043B\u0430\u043F","Little paw prints, pets and animals."],["snow","Snowflakes","\u0421\u043D\u0435\u0436\u0438\u043D\u043A\u0438","Falling snowflakes, winter and holidays."]],Yf=Qf.map(([e,t,r,o])=>({id:e,title:Oe(t,r),what:o,patches:[Ec("Background",e)]})),Jf=[["classic","Classic","\u041A\u043B\u0430\u0441\u0441\u0438\u043A\u0430","The kit's default bright casual clicks and coins."],["soft","Soft","\u041C\u044F\u0433\u043A\u0438\u0435","Quiet, rounded, calm sounds for relaxing games."],["retro","Retro 8-bit","\u0420\u0435\u0442\u0440\u043E 8-\u0431\u0438\u0442","Square-wave chiptune bleeps of old consoles."],["magic","Magic","\u041C\u0430\u0433\u0438\u044F","Shimmering chimes and sparkles, fairy-tale."],["sci-fi","Sci-fi","\u0424\u0430\u043D\u0442\u0430\u0441\u0442\u0438\u043A\u0430","Electronic blips and sweeps, space and robots."],["wood","Wooden","\u0414\u0435\u0440\u0435\u0432\u044F\u043D\u043D\u044B\u0435","Short wooden knocks and marimba, cosy and natural."]],ep=Jf.map(([e,t,r,o])=>({id:e,title:Oe(t,r),what:o,patches:[Ec("SoundSet",e)]})),Nu={backgrounds:Qf.map(e=>e[0]),soundSets:Jf.map(e=>e[0])},Sc={"ui-themes":Uf,"kit-palettes":Xf,"hero-looks":Zf,backgrounds:Yf,"sound-sets":ep};var tp=1,j=(e,t)=>({en:e,ru:t}),Mt=(e,t)=>({section:"Look",op:"set",path:e,value:t}),$n=(e,t,r,o=false)=>({section:"GameSpec",op:"set",path:`modes[role=core].params.${e}`,range:{min:t,max:r,...o?{integer:true}:{}}}),Vt=(e,t)=>({section:"GameSpec",op:"add",path:`modes[role=core].content.${e}.without`,value:t}),wt=(e,t)=>({section:"GameSpec",op:"remove",path:`modes[role=core].content.${e}.without`,value:t}),Ss={modules:["kit-game"]},zu=[{id:"look.theme",group:"look",title:j("Interface colours","\u0426\u0432\u0435\u0442\u0430 \u0438\u043D\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430"),hint:j("Screens, panels and buttons of the whole app.","\u042D\u043A\u0440\u0430\u043D\u044B, \u043F\u0430\u043D\u0435\u043B\u0438 \u0438 \u043A\u043D\u043E\u043F\u043A\u0438 \u0432\u0441\u0435\u0433\u043E \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u044F."),question:"Pick the colour theme of the app's interface (menus, panels, buttons) that fits this product best.",kind:"choice",list:"ui-themes"},{id:"look.background",group:"look",title:j("Screen pattern","\u0423\u0437\u043E\u0440 \u0444\u043E\u043D\u0430"),hint:j("A pattern over the screens' gradient.","\u0423\u0437\u043E\u0440 \u043F\u043E\u0432\u0435\u0440\u0445 \u0433\u0440\u0430\u0434\u0438\u0435\u043D\u0442\u0430 \u044D\u043A\u0440\u0430\u043D\u043E\u0432."),question:"Pick the background pattern of the app's screens that fits this product best.",kind:"choice",list:"backgrounds"},{id:"look.shape",group:"look",title:j("Shape of buttons","\u0424\u043E\u0440\u043C\u0430 \u043A\u043D\u043E\u043F\u043E\u043A"),question:"What shape should the buttons and panels of the interface have?",kind:"choice",options:[{id:"chunky",title:j("Chunky round","\u041F\u0443\u0445\u043B\u044B\u0435 \u043A\u0440\u0443\u0433\u043B\u044B\u0435"),what:"Big rounded corners and a thick outline: toy-like, casual, for kids.",patches:[Mt("Radius",18),Mt("ButtonRadius",16),Mt("Outline",3)]},{id:"classic",title:j("Classic","\u041A\u043B\u0430\u0441\u0441\u0438\u043A\u0430"),what:"Medium rounded corners and a normal outline: the default mobile casual look.",patches:[Mt("Radius",14),Mt("ButtonRadius",12),Mt("Outline",3)]},{id:"sharp",title:j("Sharp","\u0421\u0442\u0440\u043E\u0433\u0438\u0435"),what:"Small corners and a thin outline: serious, tactical, strategy or sci-fi.",patches:[Mt("Radius",4),Mt("ButtonRadius",4),Mt("Outline",2)]},{id:"pill",title:j("Pills","\u0422\u0430\u0431\u043B\u0435\u0442\u043A\u0438"),what:"Fully round pill buttons, no outline: soft, modern, minimal.",patches:[Mt("Radius",24),Mt("ButtonRadius",32),Mt("Outline",0)]}]},{id:"look.motion",group:"look",title:j("Animations","\u0410\u043D\u0438\u043C\u0430\u0446\u0438\u0438"),question:"How lively should the interface animations be?",kind:"choice",options:[{id:"calm",title:j("Calm","\u0421\u043F\u043E\u043A\u043E\u0439\u043D\u044B\u0435"),what:"Slow, soft, no bounce: relaxing, meditative, for brain games.",patches:[Mt("MotionSpeed",.7),Mt("MotionIntensity",.3),Mt("Particles",false)]},{id:"normal",title:j("Normal","\u041E\u0431\u044B\u0447\u043D\u044B\u0435"),what:"The default lively casual animations.",patches:[Mt("MotionSpeed",1),Mt("MotionIntensity",1),Mt("Particles",true)]},{id:"bouncy",title:j("Bouncy","\u041F\u0440\u0443\u0436\u0438\u043D\u0438\u0441\u0442\u044B\u0435"),what:"Strong bounces and overshoots: cartoonish, playful, for kids.",patches:[Mt("MotionSpeed",1.1),Mt("MotionIntensity",2),Mt("Particles",true)]},{id:"snappy",title:j("Snappy","\u0420\u0435\u0437\u043A\u0438\u0435"),what:"Very fast and short, little bounce: action, arcade, competitive.",patches:[Mt("MotionSpeed",1.8),Mt("MotionIntensity",.6),Mt("Particles",true)]}]},{id:"look.sound",group:"look",title:j("Interface sounds","\u0417\u0432\u0443\u043A\u0438 \u0438\u043D\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430"),question:"Pick the sound style of the interface (clicks, rewards, coins) that fits this product best.",kind:"choice",list:"sound-sets"}],Bu=[{id:"look.kit.palette",group:"look",title:j("World and colours of the game","\u041C\u0438\u0440 \u0438 \u0446\u0432\u0435\u0442\u0430 \u0438\u0433\u0440\u044B"),hint:j("The game's world (fantasy, sci-fi, cozy, post-apocalypse) and its colour mood.","\u041C\u0438\u0440 \u0438\u0433\u0440\u044B (\u0444\u044D\u043D\u0442\u0435\u0437\u0438, \u0444\u0430\u043D\u0442\u0430\u0441\u0442\u0438\u043A\u0430, \u0443\u044E\u0442, \u043F\u043E\u0441\u0442\u0430\u043F\u043E\u043A\u0430\u043B\u0438\u043F\u0441\u0438\u0441) \u0438 \u043D\u0430\u0441\u0442\u0440\u043E\u0435\u043D\u0438\u0435 \u0446\u0432\u0435\u0442\u0430."),for:Ss,question:"Pick the world and colour mood of the game scene that fits this idea best.",kind:"choice",list:"kit-palettes"},{id:"look.kit.hero",group:"look",title:j("The hero","\u0413\u0435\u0440\u043E\u0439"),for:Ss,question:"Pick the look of the game's main hero that fits this idea best.",kind:"choice",list:"hero-looks"},{id:"look.kit.race",group:"look",title:j("Hero's race","\u0420\u0430\u0441\u0430 \u0433\u0435\u0440\u043E\u044F"),for:Ss,question:"Which race should the main hero be?",kind:"choice",options:[["human","Human","\u0427\u0435\u043B\u043E\u0432\u0435\u043A","An ordinary human."],["elf","Elf","\u042D\u043B\u044C\u0444","A graceful elf with pointed ears: forests, magic, archery."],["dwarf","Dwarf","\u0413\u043D\u043E\u043C","A stout bearded dwarf: mines, forges, hammers."],["orc","Orc","\u041E\u0440\u043A","A green orc with tusks: brute strength, war, savage lands."],["undead","Undead","\u041D\u0435\u0436\u0438\u0442\u044C","A pale undead: skeletons, graveyards, dark magic, halloween."]].map(([e,t,r,o])=>({id:e,title:j(t,r),what:o,patches:[{section:"GameSpec",op:"set",path:"cast.hero.races",value:[e]}]}))}],Hu=[{id:"feel.difficulty",group:"feel",title:j("Difficulty","\u0421\u043B\u043E\u0436\u043D\u043E\u0441\u0442\u044C"),for:Ss,question:"How hard should this game be for its players?",kind:"score",levelTitles:[j("Very easy","\u041E\u0447\u0435\u043D\u044C \u043B\u0435\u0433\u043A\u043E"),j("Easy","\u041B\u0435\u0433\u043A\u043E"),j("Balanced","\u0421\u0431\u0430\u043B\u0430\u043D\u0441\u0438\u0440\u043E\u0432\u0430\u043D\u043D\u043E"),j("Hard","\u0421\u043B\u043E\u0436\u043D\u043E"),j("Very hard","\u041E\u0447\u0435\u043D\u044C \u0441\u043B\u043E\u0436\u043D\u043E")],levels:["Very easy and relaxing, for kids or a calm break.","Easy, casual.","Balanced: easy to start, harder later.","Hard, for players who like a challenge.","Very hard and punishing."],patches:[$n("difficulty",0,1)]},{id:"feel.generosity",group:"feel",title:j("Rewards in the game","\u041D\u0430\u0433\u0440\u0430\u0434\u044B \u0432 \u0438\u0433\u0440\u0435"),for:Ss,question:"How generous should the game's rewards be?",kind:"score",levelTitles:[j("Stingy","\u0421\u043A\u0443\u043F\u043E"),j("Modest","\u0421\u043A\u0440\u043E\u043C\u043D\u043E"),j("Normal","\u041E\u0431\u044B\u0447\u043D\u043E"),j("Generous","\u0429\u0435\u0434\u0440\u043E"),j("Very generous","\u041E\u0447\u0435\u043D\u044C \u0449\u0435\u0434\u0440\u043E")],levels:["Stingy: rewards are rare and earned slowly.","Modest rewards.","Normal rewards.","Generous rewards.","Very generous: rewards rain down."],patches:[$n("generosity",0,1)]},{id:"feel.runner.lanes",group:"feel",title:j("Lanes","\u041F\u043E\u043B\u043E\u0441\u044B"),for:{modules:["kit-game"],presets:["runner"]},question:"How wide should the running track be?",kind:"score",levelTitles:[j("2 lanes","2 \u043F\u043E\u043B\u043E\u0441\u044B"),j("3 lanes","3 \u043F\u043E\u043B\u043E\u0441\u044B"),j("4 lanes","4 \u043F\u043E\u043B\u043E\u0441\u044B"),j("5 lanes","5 \u043F\u043E\u043B\u043E\u0441")],levels:["Narrow: two lanes, simple and quick.","Normal: three lanes.","Wide: four lanes.","Very wide: five lanes, lots of dodging."],patches:[$n("lanes",2,5,true)]},{id:"feel.runner.lives",group:"feel",title:j("Lives in a run","\u0416\u0438\u0437\u043D\u0438 \u0432 \u0437\u0430\u0431\u0435\u0433\u0435"),for:{modules:["kit-game"],presets:["runner"]},question:"How many hits should the runner survive?",kind:"score",levelTitles:[j("One hit","\u041E\u0434\u0438\u043D \u0443\u0434\u0430\u0440"),j("A few","\u041D\u0435\u0441\u043A\u043E\u043B\u044C\u043A\u043E"),j("Many","\u041C\u043D\u043E\u0433\u043E")],levels:["One hit ends the run.","A few lives.","Many lives, forgiving."],patches:[$n("lives",1,6,true)]},{id:"feel.runner.length",group:"feel",title:j("Length of levels","\u0414\u043B\u0438\u043D\u0430 \u0443\u0440\u043E\u0432\u043D\u0435\u0439"),for:{modules:["kit-game"],presets:["runner"]},question:"How long should one level of the run be?",kind:"score",levelTitles:[j("Very short","\u041E\u0447\u0435\u043D\u044C \u043A\u043E\u0440\u043E\u0442\u043A\u0438\u0435"),j("Short","\u041A\u043E\u0440\u043E\u0442\u043A\u0438\u0435"),j("Normal","\u041E\u0431\u044B\u0447\u043D\u044B\u0435"),j("Long","\u0414\u043B\u0438\u043D\u043D\u044B\u0435")],levels:["Very short bursts for a quick break.","Short.","Normal.","Long runs."],patches:[$n("length",.5,2)]},{id:"feel.runner.powers",group:"feel",title:j("Power-ups","\u0423\u0441\u0438\u043B\u0435\u043D\u0438\u044F"),for:{modules:["kit-game"],presets:["runner"]},question:"Which power-ups fit this runner best?",kind:"choice",options:[{id:"all",title:j("All of them","\u0412\u0441\u0435"),what:"Magnet, shield, double coins, dash and flight: the full set.",patches:[wt("powers",["magnet","shield","double","dash","flight"])]},{id:"grounded",title:j("On the ground","\u0411\u0435\u0437 \u043F\u043E\u043B\u0451\u0442\u0430"),what:"No flight: magnet, shield, double coins and dash. Realistic, sports, city.",patches:[wt("powers",["magnet","shield","double","dash"]),Vt("powers",["flight"])]},{id:"coins",title:j("Coin hunter","\u041E\u0445\u043E\u0442\u0430 \u0437\u0430 \u043C\u043E\u043D\u0435\u0442\u0430\u043C\u0438"),what:"Only the coin ones: magnet and double coins. Collecting, greed, treasure.",patches:[wt("powers",["magnet","double"]),Vt("powers",["shield","dash","flight"])]},{id:"hardcore",title:j("Hardcore","\u0425\u0430\u0440\u0434\u043A\u043E\u0440"),what:"No shield and no flight: dodging is everything. Skill, challenge.",patches:[wt("powers",["magnet","double","dash"]),Vt("powers",["shield","flight"])]}]},{id:"feel.runner.obstacles",group:"feel",title:j("Obstacles","\u041F\u0440\u0435\u043F\u044F\u0442\u0441\u0442\u0432\u0438\u044F"),for:{modules:["kit-game"],presets:["runner"]},question:"Which obstacles fit this runner best?",kind:"choice",options:[{id:"all",title:j("Everything","\u0412\u0441\u0451 \u043F\u043E\u0434\u0440\u044F\u0434"),what:"Walls, barriers, pits, moving blocks, trains and rocks.",patches:[wt("obstacles",["wall","barrier","pit","mover","train","rock"])]},{id:"city",title:j("City streets","\u0413\u043E\u0440\u043E\u0434\u0441\u043A\u0438\u0435 \u0443\u043B\u0438\u0446\u044B"),what:"Walls, barriers, moving blocks and trains: a city, a subway, traffic.",patches:[wt("obstacles",["wall","barrier","mover","train"]),Vt("obstacles",["pit","rock"])]},{id:"wild",title:j("Wild lands","\u0414\u0438\u043A\u0438\u0435 \u0437\u0435\u043C\u043B\u0438"),what:"Walls, pits, rocks and barriers: forests, mountains, ruins, no trains.",patches:[wt("obstacles",["wall","barrier","pit","rock"]),Vt("obstacles",["mover","train"])]},{id:"simple",title:j("Simple","\u041F\u0440\u043E\u0441\u0442\u044B\u0435"),what:"Only walls, barriers and pits: easy to read, for kids.",patches:[wt("obstacles",["wall","barrier","pit"]),Vt("obstacles",["mover","train","rock"])]}]},{id:"feel.platformer.lives",group:"feel",title:j("Lives on a level","\u0416\u0438\u0437\u043D\u0438 \u043D\u0430 \u0443\u0440\u043E\u0432\u043D\u0435"),for:{modules:["kit-game"],presets:["platformer"]},question:"How many hits should the hero survive on a level?",kind:"score",levelTitles:[j("One hit","\u041E\u0434\u0438\u043D \u0443\u0434\u0430\u0440"),j("A few hearts","\u041D\u0435\u0441\u043A\u043E\u043B\u044C\u043A\u043E \u0441\u0435\u0440\u0434\u0435\u0446"),j("Many hearts","\u041C\u043D\u043E\u0433\u043E \u0441\u0435\u0440\u0434\u0435\u0446")],levels:["One hit and the level restarts.","A few hearts.","Many hearts, forgiving."],patches:[$n("lives",1,6,true)]},{id:"feel.platformer.double-jump",group:"feel",title:j("Double jump from the start","\u0414\u0432\u043E\u0439\u043D\u043E\u0439 \u043F\u0440\u044B\u0436\u043E\u043A \u0441\u0440\u0430\u0437\u0443"),for:{modules:["kit-game"],presets:["platformer"]},question:"Should the hero have a double jump from the very first level?",kind:"noul",yes:"Yes: the game is light and acrobatic, the hero flies around from the start.",no:"No: the double jump is earned later, the start is grounded and careful.",onYes:[{section:"GameSpec",op:"set",path:"modes[role=core].params.doubleJump",value:true}],onNo:[{section:"GameSpec",op:"set",path:"modes[role=core].params.doubleJump",value:false}]},{id:"feel.survivors.minutes",group:"feel",title:j("Length of a chapter","\u0414\u043B\u0438\u043D\u0430 \u0433\u043B\u0430\u0432\u044B"),for:{modules:["kit-game"],presets:["survivors"]},question:"How long should one chapter of survival last?",kind:"score",levelTitles:[j("2 minutes","2 \u043C\u0438\u043D\u0443\u0442\u044B"),j("5 minutes","5 \u043C\u0438\u043D\u0443\u0442"),j("10 minutes","10 \u043C\u0438\u043D\u0443\u0442"),j("15 minutes","15 \u043C\u0438\u043D\u0443\u0442")],levels:["Two minutes: quick bursts.","Five minutes.","Ten minutes.","Fifteen minutes: long sessions."],patches:[$n("minutes",2,15)]},{id:"feel.survivors.foes",group:"feel",title:j("Monsters","\u041C\u043E\u043D\u0441\u0442\u0440\u044B"),for:{modules:["kit-game"],presets:["survivors"]},question:"Which kinds of monsters fit this game best?",kind:"choice",options:[{id:"all",title:j("The whole horde","\u0412\u0441\u044F \u043E\u0440\u0434\u0430"),what:"Swarms, grunts, archers, brutes, chargers and bombers.",patches:[wt("foes",["swarm","grunt","archer","brute","charger","bomber"])]},{id:"melee",title:j("Close combat","\u0411\u043B\u0438\u0436\u043D\u0438\u0439 \u0431\u043E\u0439"),what:"No shooters: swarms, grunts, brutes and chargers. Zombies, beasts.",patches:[wt("foes",["swarm","grunt","brute","charger"]),Vt("foes",["archer","bomber"])]},{id:"army",title:j("An army","\u0410\u0440\u043C\u0438\u044F"),what:"Grunts, archers, brutes and chargers, no swarms: soldiers, knights, war.",patches:[wt("foes",["grunt","archer","brute","charger"]),Vt("foes",["swarm","bomber"])]},{id:"chaos",title:j("Chaos","\u0425\u0430\u043E\u0441"),what:"Swarms, bombers and chargers: fast, explosive, crazy.",patches:[wt("foes",["swarm","charger","bomber","grunt"]),Vt("foes",["archer","brute"])]}]},{id:"feel.td.lives",group:"feel",title:j("Lives of the base","\u0416\u0438\u0437\u043D\u0438 \u0431\u0430\u0437\u044B"),for:{modules:["kit-game"],presets:["tower-defense"]},question:"How many enemies may slip through before the level is lost?",kind:"score",levelTitles:[j("Very few","\u041E\u0447\u0435\u043D\u044C \u043C\u0430\u043B\u043E"),j("Some","\u0421\u0440\u0435\u0434\u043D\u0435"),j("Many","\u041C\u043D\u043E\u0433\u043E")],levels:["Very few: every leak hurts.","Some.","Many: forgiving."],patches:[$n("lives",5,40,true)]},{id:"feel.td.foes",group:"feel",title:j("Enemies in the waves","\u0412\u0440\u0430\u0433\u0438 \u0432 \u0432\u043E\u043B\u043D\u0430\u0445"),for:{modules:["kit-game"],presets:["tower-defense"]},question:"Which enemies should march in the waves of this tower defense?",kind:"choice",options:[{id:"all",title:j("The whole army","\u0412\u0441\u044F \u0430\u0440\u043C\u0438\u044F"),what:"Grunts, runners, brutes, flyers, shamans, healers and splitters: the full mix.",patches:[wt("foes",["grunt","runner","brute","flyer","shaman","healer","splitter"])]},{id:"ground",title:j("Only on foot","\u0422\u043E\u043B\u044C\u043A\u043E \u043F\u0435\u0448\u0438\u0435"),what:"No flyers: every enemy walks the road. Medieval, zombies, ground war.",patches:[wt("foes",["grunt","runner","brute","shaman","healer","splitter"]),Vt("foes",["flyer"])]},{id:"simple",title:j("Plain and clear","\u041F\u0440\u043E\u0441\u0442\u044B\u0435"),what:"No shamans, healers or splitters: easy to read, for kids and casual players.",patches:[wt("foes",["grunt","runner","brute","flyer"]),Vt("foes",["shaman","healer","splitter"])]},{id:"swarm",title:j("Fast hordes","\u0411\u044B\u0441\u0442\u0440\u044B\u0435 \u043E\u0440\u0434\u044B"),what:"No brutes or shamans: many fast weak foes, a frantic pace. Insects, rats, robots.",patches:[wt("foes",["grunt","runner","flyer","healer","splitter"]),Vt("foes",["brute","shaman"])]}]},{id:"feel.survivors.weapons",group:"feel",title:j("Weapons to find","\u041E\u0440\u0443\u0436\u0438\u0435 \u0432 \u0437\u0430\u0431\u0435\u0433\u0435"),hint:j("Which new weapons a level-up may offer.","\u041A\u0430\u043A\u043E\u0435 \u043D\u043E\u0432\u043E\u0435 \u043E\u0440\u0443\u0436\u0438\u0435 \u043F\u0440\u0435\u0434\u043B\u0430\u0433\u0430\u0435\u0442 \u043F\u043E\u0432\u044B\u0448\u0435\u043D\u0438\u0435 \u0443\u0440\u043E\u0432\u043D\u044F."),for:{modules:["kit-game"],presets:["survivors"]},question:"Which weapons fit the hero of this survival game best?",kind:"choice",options:[{id:"all",title:j("Everything","\u0412\u0441\u0451"),what:"Blaster, blades, aura, boomerang, lightning and drone: the full arsenal.",patches:[wt("weapons",["blaster","blades","aura","boomerang","lightning","drone"])]},{id:"tech",title:j("Technology","\u0422\u0435\u0445\u043D\u0438\u043A\u0430"),what:"Blaster, drone and lightning: guns and gadgets. Sci-fi, robots, the future.",patches:[wt("weapons",["blaster","drone","lightning"]),Vt("weapons",["blades","aura","boomerang"])]},{id:"magic",title:j("Magic and steel","\u041C\u0430\u0433\u0438\u044F \u0438 \u0441\u0442\u0430\u043B\u044C"),what:"Blades, aura, boomerang and lightning, no guns: fantasy, wizards, knights.",patches:[wt("weapons",["blades","aura","boomerang","lightning"]),Vt("weapons",["blaster","drone"])]},{id:"classic",title:j("Classic","\u041A\u043B\u0430\u0441\u0441\u0438\u043A\u0430"),what:"Blaster, blades and boomerang: simple weapons that are easy to read.",patches:[wt("weapons",["blaster","blades","boomerang"]),Vt("weapons",["aura","lightning","drone"])]}]},{id:"feel.tycoon.events",group:"feel",title:j("Events in the city","\u0421\u043E\u0431\u044B\u0442\u0438\u044F \u0432 \u0433\u043E\u0440\u043E\u0434\u0435"),for:{modules:["kit-game"],presets:["tycoon"]},question:"Which events should pop up while this tycoon city earns money?",kind:"choice",options:[{id:"all",title:j("Busy life","\u0411\u0443\u0440\u043D\u0430\u044F \u0436\u0438\u0437\u043D\u044C"),what:"Rushes, breakdowns, investors and couriers: always something to tap.",patches:[wt("events",["rush","break","invest","courier"])]},{id:"calm",title:j("No breakdowns","\u0411\u0435\u0437 \u043F\u043E\u043B\u043E\u043C\u043E\u043A"),what:"Rushes, investors and couriers, nothing ever breaks: a calm, cozy business.",patches:[wt("events",["rush","invest","courier"]),Vt("events",["break"])]},{id:"hands-on",title:j("Hands on","\u0421\u0432\u043E\u0438\u043C\u0438 \u0440\u0443\u043A\u0430\u043C\u0438"),what:"Rushes, breakdowns and couriers, no investors: the city grows by your own work.",patches:[wt("events",["rush","break","courier"]),Vt("events",["invest"])]},{id:"minimal",title:j("Only rushes","\u0422\u043E\u043B\u044C\u043A\u043E \u0430\u0436\u0438\u043E\u0442\u0430\u0436"),what:"Only rush hours: a quiet idle game with few interruptions.",patches:[wt("events",["rush"]),Vt("events",["break","invest","courier"])]}]}],Wu=(e,t)=>({Type:"VirtualCurrency",CurrencyID:e,Amount:t}),bi=(e,t,r,o,n)=>({id:e,title:j(t,r),what:o,patches:n.map((s,a)=>({section:"Reward",op:"set",path:`DailyCalendars.daily_login.Days[DayNumber=${a+1}].Rewards.Standard.Entries`,value:s.map(([i,p])=>Wu(i,p))}))}),Lc=(e,t)=>`StoreOffers.${e}.${t}`,ju=[{id:"economy.shop-ad-gems",group:"economy",title:j("Gems for an ad in the shop","\u041A\u0440\u0438\u0441\u0442\u0430\u043B\u043B\u044B \u0437\u0430 \u0440\u0435\u043A\u043B\u0430\u043C\u0443 \u0432 \u043C\u0430\u0433\u0430\u0437\u0438\u043D\u0435"),for:{sections:["Store"]},question:"How many gems should one rewarded ad in the shop give?",kind:"score",levelTitles:[j("A few","\u041C\u0430\u043B\u043E"),j("Some","\u0421\u0440\u0435\u0434\u043D\u0435"),j("A handful","\u041F\u0440\u0438\u043B\u0438\u0447\u043D\u043E"),j("Many","\u041C\u043D\u043E\u0433\u043E")],levels:["A few: gems are rare.","Some.","A good handful.","Many: gems flow freely."],patches:[{section:"Store",op:"set",path:Lc("kit_gems_ad","Reward.Grant.Standard.Entries[Type=VirtualCurrency].Amount"),range:{min:2,max:15,integer:true}}]},{id:"economy.shop-ad-cap",group:"economy",title:j("Ads in the shop a day","\u0420\u0435\u043A\u043B\u0430\u043C\u0430 \u0432 \u043C\u0430\u0433\u0430\u0437\u0438\u043D\u0435 \u0437\u0430 \u0434\u0435\u043D\u044C"),for:{sections:["Store"]},question:"How many times a day may a player watch an ad for gems in the shop?",kind:"score",levelTitles:[j("A few times","\u041D\u0435\u0441\u043A\u043E\u043B\u044C\u043A\u043E \u0440\u0430\u0437"),j("About ten","\u041E\u043A\u043E\u043B\u043E \u0434\u0435\u0441\u044F\u0442\u0438"),j("Many times","\u041C\u043D\u043E\u0433\u043E \u0440\u0430\u0437")],levels:["A few times.","About ten.","Many times."],patches:[{section:"Store",op:"set",path:Lc("kit_gems_ad","Availability.Limits.DailyCap"),range:{min:3,max:20,integer:true}}]},{id:"economy.shop-pack",group:"economy",title:j("Size of the gem pack","\u0420\u0430\u0437\u043C\u0435\u0440 \u043D\u0430\u0431\u043E\u0440\u0430 \u043A\u0440\u0438\u0441\u0442\u0430\u043B\u043B\u043E\u0432"),for:{sections:["Store"]},question:"How many gems should the paid gem pack hold?",kind:"score",levelTitles:[j("Small","\u041C\u0430\u043B\u0435\u043D\u044C\u043A\u0438\u0439"),j("Normal","\u041E\u0431\u044B\u0447\u043D\u044B\u0439"),j("Big","\u0411\u043E\u043B\u044C\u0448\u043E\u0439"),j("Huge","\u041E\u0433\u0440\u043E\u043C\u043D\u044B\u0439")],levels:["A small pack.","A normal pack.","A big pack.","A huge pack: the best deal."],patches:[{section:"Store",op:"set",path:Lc("kit_gems_pack","Reward.Grant.Standard.Entries[Type=VirtualCurrency].Amount"),range:{min:60,max:200,integer:true}}]},{id:"economy.start-coins",group:"economy",title:j("Coins at the start","\u041C\u043E\u043D\u0435\u0442\u044B \u043D\u0430 \u0441\u0442\u0430\u0440\u0442\u0435"),for:{sections:["Currency"]},question:"How many coins should a new player start with?",kind:"score",levelTitles:[j("A few","\u041C\u0430\u043B\u043E"),j("Some","\u0421\u0440\u0435\u0434\u043D\u0435"),j("Comfortable","\u041A\u043E\u043C\u0444\u043E\u0440\u0442\u043D\u043E"),j("Rich","\u0411\u043E\u0433\u0430\u0442\u043E")],levels:["A few: everything is earned.","Some.","A comfortable start.","A rich start: buy upgrades right away."],patches:[{section:"Currency",op:"set",path:"VirtualCurrencies.CO.Economy.InitialDeposit",range:{min:100,max:3e3,integer:true}}]},{id:"economy.ad-multiplier",group:"economy",title:j("Round reward for an ad","\u041D\u0430\u0433\u0440\u0430\u0434\u0430 \u0440\u0430\u0443\u043D\u0434\u0430 \u0437\u0430 \u0440\u0435\u043A\u043B\u0430\u043C\u0443"),hint:j("How many times the round's coins grow for a rewarded ad (in the app).","\u0412\u043E \u0441\u043A\u043E\u043B\u044C\u043A\u043E \u0440\u0430\u0437 \u0440\u0430\u0441\u0442\u0443\u0442 \u043C\u043E\u043D\u0435\u0442\u044B \u0440\u0430\u0443\u043D\u0434\u0430 \u0437\u0430 \u0440\u0435\u043A\u043B\u0430\u043C\u0443 (\u0432 \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u0438)."),for:{modules:["kit-game"],sections:["Reward"]},question:"How big should the bonus for watching an ad after a round be?",kind:"score",levelTitles:[j("x2","x2"),j("x3","x3"),j("x4","x4"),j("x5","x5")],levels:["Double.","Triple.","Four times.","Five times."],patches:[{section:"Reward",op:"set",path:"Windows.round.AdMultiplier",range:{min:2,max:5,integer:true}}]},{id:"economy.vip-multiplier",group:"economy",title:j("Round reward for VIP","\u041D\u0430\u0433\u0440\u0430\u0434\u0430 \u0440\u0430\u0443\u043D\u0434\u0430 \u0434\u043B\u044F VIP"),for:{modules:["kit-game"],sections:["Reward"]},question:"How big should the round reward bonus of VIP players be?",kind:"score",levelTitles:[j("x3","x3"),j("x5","x5"),j("x8","x8")],levels:["Triple.","Five times.","Eight times."],patches:[{section:"Reward",op:"set",path:"Windows.round.VipMultiplier",range:{min:3,max:8,integer:true}}]},{id:"economy.vip-price",group:"economy",title:j("Price of VIP","\u0426\u0435\u043D\u0430 VIP"),for:{sections:["Premium"]},question:"How expensive should the VIP pass be, in gems?",kind:"score",levelTitles:[j("Cheap","\u0414\u0451\u0448\u0435\u0432\u043E"),j("Normal","\u041E\u0431\u044B\u0447\u043D\u043E"),j("Expensive","\u0414\u043E\u0440\u043E\u0433\u043E")],levels:["Cheap, an easy first purchase.","Normal.","Expensive, for the most devoted."],patches:[{section:"Premium",op:"set",path:"Definitions.vip.PriceOptions.default.Cost.Standard.Entries[Type=VirtualCurrency].Amount",range:{min:20,max:120,integer:true}}]},{id:"economy.daily-calendar",group:"economy",title:j("Daily login rewards","\u041D\u0430\u0433\u0440\u0430\u0434\u044B \u0437\u0430 \u0432\u0445\u043E\u0434"),for:{sections:["Reward"]},question:"Which daily login reward plan fits this game best?",kind:"choice",options:[bi("gentle","Gentle","\u0421\u043A\u0440\u043E\u043C\u043D\u044B\u0435","Small steady rewards every day: a calm game with a slow economy.",[[["CO",50]],[["CO",60]],[["CO",80]],[["GE",2]],[["CO",100]],[["CO",120]],[["GE",8],["CO",150]]]),bi("standard","Standard","\u041E\u0431\u044B\u0447\u043D\u044B\u0435","Growing coins with gems on day 4 and a big day 7.",[[["CO",100]],[["CO",150]],[["CO",200]],[["GE",5]],[["CO",300]],[["CO",400]],[["GE",20],["CO",500]]]),bi("generous","Generous","\u0429\u0435\u0434\u0440\u044B\u0435","Big rewards every day, gems often: a fast, rewarding economy.",[[["CO",300]],[["GE",5]],[["CO",500]],[["GE",10]],[["CO",800]],[["GE",15]],[["GE",40],["CO",1500]]]),bi("jackpot","Jackpot day 7","\u0414\u0436\u0435\u043A\u043F\u043E\u0442 \u043D\u0430 7-\u0439 \u0434\u0435\u043D\u044C","Small days and a huge jackpot on day 7: come back every day.",[[["CO",50]],[["CO",50]],[["CO",80]],[["CO",80]],[["CO",100]],[["CO",150]],[["GE",60],["CO",3e3]]])]}],No=(e,t,r)=>({section:"Quest",op:"set",path:`Quests.${e}.Reward.Grant.Standard.Entries[Type=VirtualCurrency].Amount`,range:{min:t,max:r,integer:true}}),Es=(e,t,r,o)=>({section:"Quest",op:"set",path:`Quests.${e}.Objectives.${t}.TargetValue`,range:{min:r,max:o,integer:true}}),rp="Definitions.star_festival",Mn=e=>{let[t,r]=e.name,[o,n]=e.token,s=`Collect ${o.toLowerCase()} by playing rounds, shopping and finishing quests. VIP gets a second prize on every milestone.`,a=`\u0421\u043E\u0431\u0438\u0440\u0430\u0439\u0442\u0435 ${n.toLowerCase()} \u0432 \u0440\u0430\u0443\u043D\u0434\u0430\u0445, \u043F\u043E\u043A\u0443\u043F\u043A\u0430\u0445 \u0438 \u0437\u0430\u0434\u0430\u043D\u0438\u044F\u0445. VIP \u043F\u043E\u043B\u0443\u0447\u0430\u0435\u0442 \u0432\u0442\u043E\u0440\u043E\u0439 \u043F\u0440\u0438\u0437 \u043D\u0430 \u043A\u0430\u0436\u0434\u043E\u0439 \u0432\u0435\u0445\u0435.`,i=[["stars_10",10],["stars_50",50],["stars_120",120],["stars_250",250]],p=(m,$)=>({section:"TimedEvent",op:"set",path:`${rp}.${m}`,value:$});return {id:e.id,title:j(t,r),what:e.what,patches:[p("DisplayName",t),p("Description",s),p("Content.DisplayName",t),p("Content.Description",s),p("Content.Token.DisplayName",o),...i.map(([m,$])=>p(`Content.Milestones.${m}.DisplayName`,`${$} ${e.unit[0]}`)),p("Content.Milestones.stars_400.DisplayName",e.crown[0])],translations:{ru:{[t]:r,[s]:a,[o]:n,[e.crown[0]]:e.crown[1],...Object.fromEntries(i.map(([,m])=>[`${m} ${e.unit[0]}`,`${m} ${e.unit[1]}`]))}}}},_c=(e,t,r,o,n,s,a)=>({id:e,title:j(t,r),what:a,patches:[{section:"TimedBoost",op:"set",path:"Definitions.double_rewards.Effect.Value",value:o},{section:"TimedBoost",op:"set",path:"Definitions.double_rewards.DisplayName",value:t},{section:"TimedBoost",op:"set",path:"Definitions.double_rewards.Description",value:n}],translations:{ru:{[t]:r,[n]:s}}}),Vu=[{id:"liveops.event-theme",group:"liveops",title:j("Theme of the weekly event","\u0422\u0435\u043C\u0430 \u043D\u0435\u0434\u0435\u043B\u044C\u043D\u043E\u0433\u043E \u0438\u0432\u0435\u043D\u0442\u0430"),hint:j("Name of the event, its tokens and prizes.","\u041D\u0430\u0437\u0432\u0430\u043D\u0438\u0435 \u0438\u0432\u0435\u043D\u0442\u0430, \u0435\u0433\u043E \u0436\u0435\u0442\u043E\u043D\u043E\u0432 \u0438 \u043F\u0440\u0438\u0437\u043E\u0432."),for:{sections:["TimedEvent"]},question:"Which weekly event theme fits this product best?",kind:"choice",options:[Mn({id:"star-festival",name:["Star festival","\u0417\u0432\u0451\u0437\u0434\u043D\u044B\u0439 \u0444\u0435\u0441\u0442\u0438\u0432\u0430\u043B\u044C"],token:["Festival stars","\u0417\u0432\u0451\u0437\u0434\u044B \u0444\u0435\u0441\u0442\u0438\u0432\u0430\u043B\u044F"],unit:["stars","\u0437\u0432\u0451\u0437\u0434"],crown:["Festival crown","\u041A\u043E\u0440\u043E\u043D\u0430 \u0444\u0435\u0441\u0442\u0438\u0432\u0430\u043B\u044F"],what:"A cheerful festival of stars: fits anything."}),Mn({id:"harvest",name:["Harvest fair","\u042F\u0440\u043C\u0430\u0440\u043A\u0430 \u0443\u0440\u043E\u0436\u0430\u044F"],token:["Golden apples","\u0417\u043E\u043B\u043E\u0442\u044B\u0435 \u044F\u0431\u043B\u043E\u043A\u0438"],unit:["apples","\u044F\u0431\u043B\u043E\u043A"],crown:["Golden basket","\u0417\u043E\u043B\u043E\u0442\u0430\u044F \u043A\u043E\u0440\u0437\u0438\u043D\u0430"],what:"Farm, nature, cozy village, autumn."}),Mn({id:"monster-hunt",name:["Monster hunt","\u041E\u0445\u043E\u0442\u0430 \u043D\u0430 \u043C\u043E\u043D\u0441\u0442\u0440\u043E\u0432"],token:["Trophies","\u0422\u0440\u043E\u0444\u0435\u0438"],unit:["trophies","\u0442\u0440\u043E\u0444\u0435\u0435\u0432"],crown:["Hunter's crown","\u041A\u043E\u0440\u043E\u043D\u0430 \u043E\u0445\u043E\u0442\u043D\u0438\u043A\u0430"],what:"Action, fantasy, battles, monsters."}),Mn({id:"space-week",name:["Space week","\u041A\u043E\u0441\u043C\u0438\u0447\u0435\u0441\u043A\u0430\u044F \u043D\u0435\u0434\u0435\u043B\u044F"],token:["Star shards","\u0417\u0432\u0451\u0437\u0434\u043D\u044B\u0435 \u043E\u0441\u043A\u043E\u043B\u043A\u0438"],unit:["shards","\u043E\u0441\u043A\u043E\u043B\u043A\u043E\u0432"],crown:["Galaxy medal","\u041C\u0435\u0434\u0430\u043B\u044C \u0433\u0430\u043B\u0430\u043A\u0442\u0438\u043A\u0438"],what:"Sci-fi, space, robots, the future."}),Mn({id:"winter",name:["Winter holidays","\u0417\u0438\u043C\u043D\u0438\u0435 \u043F\u0440\u0430\u0437\u0434\u043D\u0438\u043A\u0438"],token:["Snowflakes","\u0421\u043D\u0435\u0436\u0438\u043D\u043A\u0438"],unit:["snowflakes","\u0441\u043D\u0435\u0436\u0438\u043D\u043E\u043A"],crown:["Ice crown","\u041B\u0435\u0434\u044F\u043D\u0430\u044F \u043A\u043E\u0440\u043E\u043D\u0430"],what:"Winter, new year, cozy and festive."}),Mn({id:"beach",name:["Beach party","\u041F\u043B\u044F\u0436\u043D\u0430\u044F \u0432\u0435\u0447\u0435\u0440\u0438\u043D\u043A\u0430"],token:["Seashells","\u0420\u0430\u043A\u0443\u0448\u043A\u0438"],unit:["seashells","\u0440\u0430\u043A\u0443\u0448\u0435\u043A"],crown:["Golden surfboard","\u0417\u043E\u043B\u043E\u0442\u0430\u044F \u0434\u043E\u0441\u043A\u0430"],what:"Summer, the sea, islands, holidays."}),Mn({id:"treasure",name:["Treasure hunt","\u041E\u0445\u043E\u0442\u0430 \u0437\u0430 \u0441\u043E\u043A\u0440\u043E\u0432\u0438\u0449\u0430\u043C\u0438"],token:["Map pieces","\u041A\u0443\u0441\u043E\u0447\u043A\u0438 \u043A\u0430\u0440\u0442\u044B"],unit:["pieces","\u043A\u0443\u0441\u043E\u0447\u043A\u043E\u0432"],crown:["Pirate chest","\u041F\u0438\u0440\u0430\u0442\u0441\u043A\u0438\u0439 \u0441\u0443\u043D\u0434\u0443\u043A"],what:"Pirates, adventure, exploring, mysteries."}),Mn({id:"carnival",name:["Carnival","\u041A\u0430\u0440\u043D\u0430\u0432\u0430\u043B"],token:["Masks","\u041C\u0430\u0441\u043A\u0438"],unit:["masks","\u043C\u0430\u0441\u043E\u043A"],crown:["Carnival crown","\u041A\u043E\u0440\u043E\u043D\u0430 \u043A\u0430\u0440\u043D\u0430\u0432\u0430\u043B\u0430"],what:"Music, dance, a bright party, cartoon fun."})]},{id:"liveops.event-pace",group:"liveops",title:j("Pace of the weekly event","\u0422\u0435\u043C\u043F \u043D\u0435\u0434\u0435\u043B\u044C\u043D\u043E\u0433\u043E \u0438\u0432\u0435\u043D\u0442\u0430"),for:{sections:["TimedEvent"]},question:"How fast should players collect the weekly event tokens by playing rounds?",kind:"score",levelTitles:[j("Slow","\u041C\u0435\u0434\u043B\u0435\u043D\u043D\u043E"),j("Normal","\u041E\u0431\u044B\u0447\u043D\u043E"),j("Fast","\u0411\u044B\u0441\u0442\u0440\u043E"),j("Very fast","\u041E\u0447\u0435\u043D\u044C \u0431\u044B\u0441\u0442\u0440\u043E")],levels:["Slow: the top prize is for the most devoted.","Normal.","Fast.","Very fast: most players reach the top."],patches:[{section:"TimedEvent",op:"set",path:`${rp}.Content.TokenSources[SourceType=CustomAction].BaseWeight`,range:{min:2,max:10,integer:true}}]},{id:"liveops.boost-power",group:"liveops",title:j("Power of the reward boost","\u0421\u0438\u043B\u0430 \u0431\u0443\u0441\u0442\u0430 \u043D\u0430\u0433\u0440\u0430\u0434"),for:{sections:["TimedBoost"]},question:"How strong should the paid reward boost be?",kind:"choice",options:[_c("x1-5","Rewards x1.5","\u041D\u0430\u0433\u0440\u0430\u0434\u044B x1.5",1.5,"Every reward is 1.5 times bigger for an hour.","\u041A\u0430\u0436\u0434\u0430\u044F \u043D\u0430\u0433\u0440\u0430\u0434\u0430 \u0432 1.5 \u0440\u0430\u0437\u0430 \u0431\u043E\u043B\u044C\u0448\u0435 \u0432 \u0442\u0435\u0447\u0435\u043D\u0438\u0435 \u0447\u0430\u0441\u0430.","A gentle boost: a slow, balanced economy."),_c("x2","Double rewards","\u0414\u0432\u043E\u0439\u043D\u044B\u0435 \u043D\u0430\u0433\u0440\u0430\u0434\u044B",2,"Every reward is doubled for an hour.","\u041A\u0430\u0436\u0434\u0430\u044F \u043D\u0430\u0433\u0440\u0430\u0434\u0430 \u0443\u0434\u0432\u043E\u0435\u043D\u0430 \u043D\u0430 \u0447\u0430\u0441.","The classic double: fits most games."),_c("x3","Triple rewards","\u0422\u0440\u043E\u0439\u043D\u044B\u0435 \u043D\u0430\u0433\u0440\u0430\u0434\u044B",3,"Every reward is tripled for an hour.","\u041A\u0430\u0436\u0434\u0430\u044F \u043D\u0430\u0433\u0440\u0430\u0434\u0430 \u0443\u0442\u0440\u043E\u0435\u043D\u0430 \u043D\u0430 \u0447\u0430\u0441.","A big boost: a fast, generous economy.")]},{id:"liveops.quest-effort",group:"liveops",title:j("Effort of daily quests","\u0421\u043B\u043E\u0436\u043D\u043E\u0441\u0442\u044C \u0435\u0436\u0435\u0434\u043D\u0435\u0432\u043D\u044B\u0445 \u0437\u0430\u0434\u0430\u043D\u0438\u0439"),for:{sections:["Quest"]},question:"How much play should the daily quests ask for?",kind:"score",levelTitles:[j("A few minutes","\u041F\u0430\u0440\u0430 \u043C\u0438\u043D\u0443\u0442"),j("Short","\u041A\u043E\u0440\u043E\u0442\u043A\u043E"),j("Normal","\u041E\u0431\u044B\u0447\u043D\u043E"),j("Long","\u0414\u043E\u043B\u0433\u043E")],levels:["Very little: done in a few minutes.","A short session.","A normal session.","A long session: for devoted players."],patches:[Es("daily_play","play",1,8),Es("daily_earn","earn",50,500),Es("kit_daily_coins","coins",100,1500),Es("kit_daily_time","seconds",180,1800),Es("kit_daily_levels","levels",1,6)]},{id:"liveops.quest-rewards",group:"liveops",title:j("Rewards of daily quests","\u041D\u0430\u0433\u0440\u0430\u0434\u044B \u0437\u0430 \u0437\u0430\u0434\u0430\u043D\u0438\u044F"),for:{sections:["Quest"]},question:"How generous should the rewards of the daily quests be?",kind:"score",levelTitles:[j("Small","\u041C\u0430\u043B\u0435\u043D\u044C\u043A\u0438\u0435"),j("Normal","\u041E\u0431\u044B\u0447\u043D\u044B\u0435"),j("Big","\u0411\u043E\u043B\u044C\u0448\u0438\u0435"),j("Very big","\u041E\u0447\u0435\u043D\u044C \u0431\u043E\u043B\u044C\u0448\u0438\u0435")],levels:["Small.","Normal.","Big.","Very big."],patches:[No("daily_visit",10,100),No("daily_earn",30,300),No("daily_play",80,600),No("kit_daily_coins",50,500),No("kit_daily_time",50,500),No("kit_daily_levels",5,40)]},{id:"liveops.leaderboard",group:"liveops",title:j("Weekly leaderboard","\u041D\u0435\u0434\u0435\u043B\u044C\u043D\u044B\u0439 \u0440\u0435\u0439\u0442\u0438\u043D\u0433"),for:{sections:["Leaderboard"]},question:"Is competing on a weekly leaderboard a good fit for this product?",kind:"noul",yes:"Yes: players like to compete and compare their scores.",no:"No: it is a calm, personal or creative product without competition.",onYes:[{section:"Leaderboard",op:"set",path:"Definitions.weekly_score.IsEnabled",value:true}],onNo:[{section:"Leaderboard",op:"set",path:"Definitions.weekly_score.IsEnabled",value:false}]}],Wr=(e,t,r,o)=>({id:e,title:j(t,r),what:o,patches:[{section:"Currency",op:"set",path:"VirtualCurrencies.CO.DisplayName",value:t},{section:"GameSpec",op:"set",path:"texts.'res.coins'",value:{en:t,ru:r}}],translations:{ru:{[t]:r}}}),wn=(e,t,r,o)=>({id:e,title:j(t,r),what:o,patches:[{section:"Currency",op:"set",path:"VirtualCurrencies.GE.DisplayName",value:t}],translations:{ru:{[t]:r}}}),Gu=[{id:"texts.coin-name",group:"texts",title:j("Name of the coins","\u041D\u0430\u0437\u0432\u0430\u043D\u0438\u0435 \u043C\u043E\u043D\u0435\u0442"),for:{sections:["Currency"]},question:"What should the game's soft currency (earned in rounds) be called?",kind:"choice",options:[Wr("coins","Coins","\u041C\u043E\u043D\u0435\u0442\u044B","Plain coins: fits anything."),Wr("gold","Gold","\u0417\u043E\u043B\u043E\u0442\u043E","Gold: fantasy, medieval, pirates, treasure."),Wr("credits","Credits","\u041A\u0440\u0435\u0434\u0438\u0442\u044B","Credits: sci-fi, space, future, robots."),Wr("cash","Cash","\u041D\u0430\u043B\u0438\u0447\u043D\u044B\u0435","Cash: business, city, modern life, tycoon."),Wr("scrap","Scrap","\u0425\u043B\u0430\u043C","Scrap: post-apocalypse, survival, junk."),Wr("candies","Candies","\u041A\u043E\u043D\u0444\u0435\u0442\u044B","Candies: sweets, kids, cozy cartoon."),Wr("stars","Stars","\u0417\u0432\u0451\u0437\u0434\u044B","Stars: kids, space, dreams, music."),Wr("bones","Bones","\u041A\u043E\u0441\u0442\u0438","Bones: pets, dogs, dinosaurs, halloween."),Wr("shells","Shells","\u0420\u0430\u043A\u0443\u0448\u043A\u0438","Shells: the sea, islands, mermaids."),Wr("leaves","Leaves","\u041B\u0438\u0441\u0442\u044C\u044F","Leaves: nature, forest, farm, elves.")]},{id:"texts.gem-name",group:"texts",title:j("Name of the gems","\u041D\u0430\u0437\u0432\u0430\u043D\u0438\u0435 \u043A\u0440\u0438\u0441\u0442\u0430\u043B\u043B\u043E\u0432"),for:{sections:["Currency"]},question:"What should the game's premium currency be called?",kind:"choice",options:[wn("gems","Gems","\u041A\u0440\u0438\u0441\u0442\u0430\u043B\u043B\u044B","Gems: fits anything."),wn("diamonds","Diamonds","\u0410\u043B\u043C\u0430\u0437\u044B","Diamonds: luxury, mining, treasure."),wn("rubies","Rubies","\u0420\u0443\u0431\u0438\u043D\u044B","Rubies: fantasy, royal, magic."),wn("crystals","Energy cells","\u042D\u043D\u0435\u0440\u0433\u043E\u044F\u0447\u0435\u0439\u043A\u0438","Energy cells: sci-fi, robots, space."),wn("pearls","Pearls","\u0416\u0435\u043C\u0447\u0443\u0433","Pearls: the sea, mermaids, elegance."),wn("orbs","Orbs","\u0421\u0444\u0435\u0440\u044B","Magic orbs: wizards, spells, mystery."),wn("tokens","Tokens","\u0416\u0435\u0442\u043E\u043D\u044B","Tokens: arcade, casino, retro."),wn("hearts","Hearts","\u0421\u0435\u0440\u0434\u0435\u0447\u043A\u0438","Hearts: cute, love, pets, kids.")]}],Ku=new Set(["Look","GameSpec"]),xi=e=>e?.map(t=>Ku.has(t.section)?t:{...t,ifExists:true}),Fu=e=>{switch(e.kind){case "choice":return e.options?{...e,options:e.options.map(t=>({...t,patches:xi(t.patches)}))}:e;case "score":return {...e,patches:xi(e.patches)};case "noul":return {...e,onYes:xi(e.onYes),...e.onNo?{onNo:xi(e.onNo)}:{}}}},np=[...zu,...Bu,...Hu,...ju,...Vu,...Gu].map(Fu),qu={version:tp,knobs:np,lists:Sc};var Rc=/^[a-z0-9][a-z0-9_.-]{0,63}$/,Uu=new Set(["set","merge","unset","add","remove"]),Xu=/[\u2013\u2014]/;function ki(e,t,r,o=false){(!e||e.length===0)&&r.push(`${t}: no patches`);for(let[n,s]of (e??[]).entries())(!s.section||!/^[A-Z][A-Za-z0-9]*$/.test(s.section))&&r.push(`${t}.patches[${n}]: section "${s.section}"`),Uu.has(s.op)||r.push(`${t}.patches[${n}]: op "${s.op}"`),mi(s.path)===null&&r.push(`${t}.patches[${n}]: path "${s.path}"`),o&&s.op==="set"&&!s.range&&s.value===void 0&&r.push(`${t}.patches[${n}]: a score patch needs a range`),s.range&&!(Number.isFinite(s.range.min)&&Number.isFinite(s.range.max))&&r.push(`${t}.patches[${n}]: range`);}function op(e,t,r){e.length===0&&r.push(`${t}: no options`),e.length>255&&r.push(`${t}: ${e.length} options, the decision model takes ${255}`);let o=new Set;for(let n of e)Rc.test(n.id)||r.push(`${t}: option id "${n.id}"`),o.has(n.id)&&r.push(`${t}: option "${n.id}" twice`),o.add(n.id),n.title?.en||r.push(`${t}.${n.id}: no English title`),n.what||r.push(`${t}.${n.id}: no description for the decision model`),ki(n.patches,`${t}.${n.id}`,r);}function Ac(e,t){if(typeof e=="string")t.push(e);else if(Array.isArray(e))for(let r of e)Ac(r,t);else if(e&&typeof e=="object")for(let r of Object.values(e))Ac(r,t);}function Zu(e){let t=[];for(let[n,s]of Object.entries(e.lists))Rc.test(n)||t.push(`list "${n}": id`),op(s,`list ${n}`,t);let r=new Set;for(let n of e.knobs){let s=`knob ${n.id}`;Rc.test(n.id)||t.push(`${s}: id`),r.has(n.id)&&t.push(`${s}: twice`),r.add(n.id),n.title?.en||t.push(`${s}: no English title`),n.question||t.push(`${s}: no question`),n.kind==="choice"?(n.list&&n.options&&t.push(`${s}: options OR a list, not both`),n.list&&!e.lists[n.list]&&t.push(`${s}: no list "${n.list}"`),n.list||op(n.options??[],s,t)):n.kind==="score"?((n.levels.length<2||n.levels.length>10)&&t.push(`${s}: ${n.levels.length} levels, 2..${10}`),n.levelTitles?.length!==n.levels.length?t.push(`${s}: levelTitles must name every level`):n.levelTitles.forEach((a,i)=>{(!a.en||!a.ru)&&t.push(`${s}: level ${i} needs en and ru titles`);}),ki(n.patches,s,t,true)):n.kind==="noul"?((!n.yes||!n.no)&&t.push(`${s}: yes and no`),ki(n.onYes,s,t),n.onNo&&ki(n.onNo,`${s}.no`,t)):t.push(`${s}: kind`);}let o=[];Ac(e,o);for(let n of o)Xu.test(n)&&t.push(`a long dash in "${n.slice(0,60)}"`);return t}
|
|
3
|
+
exports.ABILITIES=Tl;exports.ART=Ws;exports.ASSET_PACKS=Fn;exports.BACKGROUND_OPTIONS=Yf;exports.BLOCKS=dn;exports.BOSS_DEFEATED=Wl;exports.BOSS_SPAWNED=Oa;exports.BRANCH_LEVEL=Gl;exports.Body=ar;exports.Bullet=nn;exports.CHAPTERS=Aa;exports.CORE_EFFECTS=Nc;exports.DECISION_MAX_LEVELS=Vf;exports.DECISION_MAX_OPTIONS=jf;exports.DEFAULT_CAST=Os;exports.DEFAULT_LOOK=Di;exports.DEFAULT_PALETTE=Ri;exports.DEFAULT_REWARDS=Hc;exports.DEMO_SPEC=Mu;exports.Drop=ir;exports.EFFECTS=Bo;exports.ENEMIES=Bn;exports.ENGINES=Ds;exports.ENTRY_ID_RE=Oc;exports.ExprError=dr;exports.FOES=tn;exports.FUNCTIONS=$i;exports.FX_TOPIC=Oi;exports.Foe=je;exports.GIVE_UP=nr;exports.Gem=yn;exports.HEROES=ko;exports.HERO_LOOK_OPTIONS=Zf;exports.INPUT_TOPIC=Nt;exports.Jumper=wr;exports.KIT_PALETTES=Xf;exports.KNOBS=np;exports.KNOB_CATALOG=qu;exports.KNOB_CATALOG_VERSION=tp;exports.KNOB_LISTS=Sc;exports.KNOWN_SYSTEMS=zc;exports.LEVELS_PER_WORLD=On;exports.LEVEL_CLEARED=Cl;exports.LEVEL_MAPS=Ul;exports.LEVEL_UP=Nl;exports.LINKS=Wo;exports.LOOK_RUNTIME_IDS=Nu;exports.M3_CHARACTER=Qi;exports.M3_ELEMENTS=rs;exports.M3_ENEMIES=Fi;exports.M3_HEROES=so;exports.M3_LEVELS=Ys;exports.M3_LEVELS_PER_WORLD=ts;exports.M3_LEVEL_DEFS=Qs;exports.M3_META=wd;exports.M3_META_STATS=Yi;exports.M3_OBSTACLES=Zr;exports.M3_PIECES=Ki;exports.M3_SKILLS=qi;exports.M3_SPECIALS=Rn;exports.M3_WORLDS=vd;exports.M3_WORLD_STARS=Ui;exports.MAPS=Kl;exports.MAP_COLS=Br;exports.MAP_ROWS=Hr;exports.MAX_LEVEL=pr;exports.MAX_PASSIVES=_a;exports.MAX_WEAPONS=La;exports.META_CHARACTER=Il;exports.META_STATS=Pl;exports.MG_BOARDS=An;exports.MG_CHAINS=as;exports.MG_CHARACTER=kl;exports.MG_COLS=Cd;exports.MG_HEROES=fo;exports.MG_LEVELS=ma;exports.MG_LEVELS_PER_WORLD=co;exports.MG_LEVEL_DEFS=ua;exports.MG_META=Nd;exports.MG_META_STATS=vl;exports.MG_OBSTACLES=gr;exports.MG_REVIVE_ENERGY=ga;exports.MG_ROWS=Pd;exports.MG_SKILLS=gl;exports.MG_SPECIAL_ITEMS=ul;exports.MG_WORLDS=Id;exports.MG_WORLD_STARS=bl;exports.MergeItem=ls;exports.Missile=Hn;exports.OBSTACLE_KINDS=Ks;exports.Order=Zd;exports.PASSIVES=bo;exports.PASSIVE_IDS=Ra;exports.PIECE_COLORS=fd;exports.PLATFORMER_CHARACTER=Dl;exports.PLATFORMER_HEROES=go;exports.PLATFORMER_LEVELS=wa;exports.PLATFORMER_META=tf;exports.PLATFORMER_META_STATS=Ol;exports.PLATFORM_LINKS=pi;exports.PLATFORM_PACKS=Co;exports.PLATFORM_PRESETS=Wf;exports.POWERS=Rr;exports.POWER_IDS=Yo;exports.PRESETS=fn;exports.REROLL_GEMS=af;exports.REVIVE=rr;exports.REVIVE_GEMS=sf;exports.REVIVE_OFFER=tr;exports.ROOMS=Ma;exports.ROOM_ROWS=jt;exports.ROUND_ENDED=Zt;exports.ROUND_OVER=Xt;exports.ROUND_STARTED=Ut;exports.RUNNER_CHARACTER=ji;exports.RUNNER_HEROES=no;exports.RUNNER_LEVELS=Qo;exports.RUNNER_META=ud;exports.RUNNER_META_STATS=Vi;exports.Raider=De;exports.RoadItem=_t;exports.Runner=Xr;exports.SELL_SHARE=ps;exports.SHOW_START=Qt;exports.SOUND_SET_OPTIONS=ep;exports.SPEC_VERSION=Vo;exports.SPELLS=$o;exports.START_ROUND=Wi;exports.SURVIVORS_META=lf;exports.Shot=zn;exports.Soldier=Ar;exports.Spot=ja;exports.Survivor=Da;exports.TD_CHARACTER=Ql;exports.TD_HEROES=So;exports.TD_LEVELS=ms;exports.TD_LEVELS_PER_WORLD=Nr;exports.TD_LIVES=mf;exports.TD_META=yf;exports.TD_META_STATS=Yl;exports.TD_REVIVE_LIVES=Ba;exports.TD_WORLDS=Fl;exports.TD_WORLD_STARS=ql;exports.TOWERS=Pa;exports.TY_BUSINESSES=gs;exports.TY_CHARACTER=ac;exports.TY_EVENTS=_o;exports.TY_HEROES=Ro;exports.TY_LEVELS=Lo;exports.TY_LEVELS_PER_WORLD=Ao;exports.TY_LEVEL_DEFS=jn;exports.TY_META=Ef;exports.TY_META_STATS=ic;exports.TY_MILESTONES=bs;exports.TY_REVIVE_SECONDS=Xa;exports.TY_SKILLS=rc;exports.TY_UPGRADES=Fa;exports.TY_WORLDS=Mf;exports.TY_WORLD_STARS=nc;exports.Thing=mt;exports.Tower=kr;exports.Transform=K;exports.TyManager=hc;exports.UI_THEMES=Uf;exports.UPGRADE_PICK=Bl;exports.UPGRADE_PICKED=zl;exports.UPGRADE_REROLL=Hl;exports.VIEW_RESIZED_TOPIC=qt;exports.Visual=ie;exports.WAVE_STARTED=ec;exports.WEAPONS=Ir;exports.WEAPON_IDS=Pn;exports.WORLDS=_l;exports.WORLD_STARS=Rl;exports.World=zo;exports.abilitiesFor=Ea;exports.act=Fe;exports.applyLink=xp;exports.applyPatches=_u;exports.artAspect=zh;exports.artDocument=Bh;exports.attachRules=Ei;exports.boardOf=un;exports.buildFromVar=df;exports.buildToVar=jl;exports.cellAt=Ur;exports.cellCenter=at;exports.chapterOf=xo;exports.checkEconomy=Li;exports.checkExpr=Mi;exports.checkRules=As;exports.compileExpr=Er;exports.contentOf=Sr;exports.cozyPack=gc;exports.createFixedStepper=up;exports.createKitRegistry=Lp;exports.createRegistry=Ls;exports.createRng=_s;exports.defenseBoostsLink=Mc;exports.defineComponent=ve;exports.defineKind=Vr;exports.enemyOf=hr;exports.evalNumber=wi;exports.fantasyPack=mc;exports.findMatches=io;exports.fx=G;exports.hasArt=Nh;exports.hasErrors=Si;exports.hasMove=ol;exports.heroCharacterOf=Of;exports.heroUpgradeLink=kc;exports.laneRunnerBlock=qs;exports.levelOf=to;exports.m3EnemyOf=os;exports.m3LevelOf=ao;exports.m3SkillOf=Xs;exports.m3StarsToEnter=Xi;exports.match3Block=da;exports.match3Preset=zf;exports.mergeBlock=va;exports.mergePalette=Ti;exports.mergePreset=Bf;exports.metersOf=ro;exports.mgChainOf=Cr;exports.mgLevelOf=po;exports.mgSkillOf=ha;exports.mgSpecialOf=Jr;exports.mgStarsFor=ya;exports.mgStarsToEnter=xl;exports.migrateSpec=Wc;exports.mirrored=Mo;exports.offerFromVar=ff;exports.offerToVar=Vl;exports.packName=bp;exports.parseKnobPath=mi;exports.patchTargets=Au;exports.patchValue=Kf;exports.placeBackdrop=zt;exports.platformerBlock=Sa;exports.platformerLevelOf=yo;exports.platformerPreset=Pf;exports.postApocalypsePack=bc;exports.puzzleCityLink=vc;exports.registerCoreEffects=Ho;exports.registerPlatformKit=$u;exports.resolveColor=Ai;exports.resolveParams=Ts;exports.roundBlock=Gs;exports.runnerCollectionLink=$c;exports.runnerPreset=Cf;exports.sciFiPack=yc;exports.scrollBackdrop=Zo;exports.setPose=it;exports.shortCash=vr;exports.specForPreset=wu;exports.starsToEnter=Al;exports.startMode=_p;exports.survivorsBlock=Ca;exports.survivorsPreset=If;exports.tdLevelOf=Eo;exports.tdStarsFor=za;exports.tdStarsToEnter=Zl;exports.tdWavesOf=Xl;exports.towerArt=Ia;exports.towerDefenseBlock=Va;exports.towerDefensePreset=Nf;exports.towerOf=zr;exports.towerSpent=us;exports.towerStats=hs;exports.traceMap=wo;exports.trackControls=Jn;exports.tyBotTimeOf=ci;exports.tyBusinessOf=Wn;exports.tyEventOf=xf;exports.tyLevelOf=Do;exports.tySkillOf=qa;exports.tyStarsFor=Ua;exports.tyStarsToEnter=oc;exports.tycoonBlock=di;exports.tycoonPreset=Hf;exports.tycoonStateOf=Tf;exports.validateKnobCatalog=Zu;exports.validateSpec=wp;exports.viewOf=He;
|