@idosgames/game-kit 0.1.0 → 0.1.2
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 +70 -70
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)),h=Math.floor(Math.max(s,a));return i+Math.floor(o()*(h-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 h=o()*i;for(let m of s){let v=Math.max(0,a(m));if(!(v<=0)){if(h<v)return m;h-=v;}}for(let m=s.length-1;m>=0;m--){let v=s[m];if(a(v)>0)return v}throw new RangeError("weighted: no positive weight")},shuffle(s){let a=s.slice();for(let i=a.length-1;i>0;i--){let h=Math.floor(o()*(i+1)),m=a[i];a[i]=a[h],a[h]=m;}return a},stream(s){return _s(`${t}/${s}`)}}}var cr=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,lt=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 cr("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 cr("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 cr("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 cr(`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=O=>{let N=o();return N.t==="op"&&N.v===O},a=O=>{let N=n();if(N.t!=="op"||N.v!==O)throw new cr(`expected "${O}"`,e,N.at)},i=O=>{if(O>vi)throw new cr("formula is nested too deep",e,o().at);let N=h(0,O+1);if(!s("?"))return N;n();let q=i(O+1);a(":");let ne=i(O+1);return {k:"cond",c:N,a:q,b:ne}},h=(O,N)=>{if(N>vi)throw new cr("formula is nested too deep",e,o().at);let q=m(N+1);for(;;){let ne=o();if(ne.t!=="op")break;let Z=Pc[ne.v];if(Z===void 0||Z<O)break;n();let ye=ne.v==="^"?h(Z,N+1):h(Z+1,N+1);q={k:"bin",op:ne.v,a:q,b:ye};}return q},m=O=>{if(O>vi)throw new cr("formula is nested too deep",e,o().at);return s("-")||s("!")?{k:"un",op:n().v,a:h(Pc["^"],O+1)}:v(O+1)},v=O=>{let N=n();if(N.t==="num")return {k:"num",v:N.v};if(N.t==="str")return {k:"str",v:N.v};if(N.t==="op"&&N.v==="("){let q=i(O+1);return a(")"),q}if(N.t==="id"){if(N.v==="true")return {k:"bool",v:true};if(N.v==="false")return {k:"bool",v:false};if(s("(")){if(!Object.prototype.hasOwnProperty.call($i,N.v))throw new cr(`unknown function "${N.v}"`,e,N.at);n();let q=[];if(!s(")"))for(;;){if(q.push(i(O+1)),s(",")){n();continue}break}return a(")"),{k:"call",fn:N.v,args:q}}return {k:"var",path:N.v.split(".")}}throw new cr(N.t==="end"?"unexpected end":"unexpected token",e,N.at)},x=i(0),D=o();if(D.t!=="end")throw new cr("unexpected token",e,D.at);return x}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 lr(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==="-"?-lt(lr(e.a,t)):!En(lr(e.a,t));case "cond":return En(lr(e.c,t))?lr(e.a,t):lr(e.b,t);case "call":return lt($i[e.fn](...e.args.map(r=>lt(lr(r,t)))));case "bin":{if(e.op==="&&")return En(lr(e.a,t))&&En(lr(e.b,t));if(e.op==="||")return En(lr(e.a,t))||En(lr(e.b,t));let r=lr(e.a,t),o=lr(e.b,t);switch(e.op){case "==":return typeof r=="string"||typeof o=="string"?String(r)===String(o):lt(r)===lt(o);case "!=":return typeof r=="string"||typeof o=="string"?String(r)!==String(o):lt(r)!==lt(o);case "<":return lt(r)<lt(o);case "<=":return lt(r)<=lt(o);case ">":return lt(r)>lt(o);case ">=":return lt(r)>=lt(o);case "+":return typeof r=="string"||typeof o=="string"?`${r}${o}`:lt(r)+lt(o);case "-":return lt(r)-lt(o);case "*":return lt(r)*lt(o);case "/":{let n=lt(o);return n===0?0:lt(r)/n}case "%":{let n=lt(o);return n===0?0:lt(r)%n}case "^":return lt(Math.pow(lt(r),lt(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 cr("formula is too long",e,Cc);let r=fp(e),o=new Set;cn(r,o);let n={source:e,reads:[...o],eval:s=>lr(r,s),num:s=>lt(lr(r,s)),bool:s=>En(lr(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(h){o.push({level:"error",path:`${i}.when`,code:"RULE_FORMULA",message:h.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((h,m)=>{let v=`${i}.do.${m}`,x=typeof h?.type=="string"?t.get(Bo,h.type):void 0;if(!x){o.push({level:"error",path:`${v}.type`,code:"EFFECT_UNKNOWN",message:`unknown effect "${String(h?.type)}"`});return}for(let D of x.required??[])h[D]===void 0&&o.push({level:"error",path:`${v}.${D}`,code:"EFFECT_PARAM",message:`effect "${x.id}" needs "${D}"`});for(let D of x.formulas??[]){let O=h[D];if(typeof O=="string")try{Er(O);}catch(N){o.push({level:"error",path:`${v}.${D}`,code:"RULE_FORMULA",message:N.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(h=>({spec:h,def:r.require(Bo,h.type)})),hits:0,runs:0,lastRunAt:Number.NEGATIVE_INFINITY})),s=new Map;for(let i of n){let h=s.get(i.def.on)??[];h.push(i),s.set(i.def.on,h);}let a=[...s.entries()].map(([i,h])=>e.on(i,m=>{for(let v of h){if(v.def.once&&v.runs>0)continue;let x={event:m,vars:e.vars,tick:e.tick,time:e.time};if(v.when&&!v.when.bool(x)||(v.hits++,v.def.every!==void 0&&v.def.every>1&&v.hits%v.def.every!==0)||v.def.cooldown!==void 0&&e.time-v.lastRunAt<v.def.cooldown)continue;v.runs++,v.lastRunAt=e.time;let D={world:e,rule:v.def,event:m,scope:x,num:(O,N=0)=>typeof O=="number"||typeof O=="string"?wi(O,x,N):N};for(let O of v.effects)try{O.def.run(D,O.spec);}catch(N){o.onError?.(v.def,N);}}}));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],h=`${r}.${s}`;if(!i){o.push({level:"warning",path:h,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:h,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:h,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:h,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:h,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:h,code:"PARAM_CLAMPED",message:`cut to ${m} characters`});}else o.push({level:"warning",path:h,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(h=>h.id)),s=new Set(t.map(h=>h.id)),a=new Map,i=new Map;r.forEach((h,m)=>{let v=`flows.${m}`;s.has(h.resource)||o.push({level:"error",path:`${v}.resource`,code:"FLOW_RESOURCE_UNKNOWN",message:`no resource "${h.resource}"`});let x=yp.exec(h.by);x?zc.includes(x[1])||o.push({level:"warning",path:`${v}.by`,code:"FLOW_SYSTEM_UNKNOWN",message:`"${h.by}" is not a platform system`}):n.has(h.by)||o.push({level:"error",path:`${v}.by`,code:"FLOW_BY_UNKNOWN",message:`"${h.by}" is neither a mode of the spec nor "system:<id>"`}),h.kind!=="source"&&h.kind!=="sink"&&o.push({level:"error",path:`${v}.kind`,code:"FLOW_KIND",message:'kind is "source" or "sink"'});let D=h.kind==="source"?a:i;D.set(h.resource,(D.get(h.resource)??0)+1);}),t.forEach((h,m)=>{let v=`resources.${m}`,x=a.get(h.id)??0,D=i.get(h.id)??0;x===0&&o.push({level:"error",path:v,code:"RESOURCE_NO_SOURCE",message:`nothing produces "${h.id}"`}),gp.has(h.kind)&&D===0&&o.push({level:"error",path:v,code:"RESOURCE_NO_SINK",message:`nothing spends "${h.id}"`});});}var F=ve("transform"),le=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 zt="input",Ft="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((Z,ye)=>{let be=`modes.${ye}`;if(!xt(Z)){r.push({level:"error",path:be,code:"MODE_SHAPE",message:"a mode must be an object"});return}typeof Z.id!="string"||!Ci.test(Z.id)?r.push({level:"error",path:`${be}.id`,code:"MODE_ID",message:"mode id: snake_case, starts with a letter"}):a.has(Z.id)?r.push({level:"error",path:`${be}.id`,code:"MODE_DUPLICATE",message:`mode "${Z.id}" is defined twice`}):a.add(Z.id);let fe=typeof Z.preset=="string"?t.get(fn,Z.preset):void 0;if(!fe){r.push({level:"error",path:`${be}.preset`,code:"MODE_PRESET_UNKNOWN",message:`no preset "${String(Z.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)}`}),Z.role!==void 0&&!["core","meta","embedded"].includes(Z.role)&&r.push({level:"error",path:`${be}.role`,code:"MODE_ROLE",message:"role is core, meta or embedded"});let Ee=Ts(fe.params??{},xt(Z.params)?Z.params:void 0,`${be}.params`,r),de={},Ae=new Set(fe.blocks);for(let ce of fe.blocks){let ke=t.get(dn,ce);if(!ke){r.push({level:"error",path:`${be}.preset`,code:"PRESET_BLOCK_UNKNOWN",message:`preset "${fe.id}" uses unknown block "${ce}"`});continue}ke.engines&&!ke.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 ke.requires??[])Ae.has(oe)||r.push({level:"error",path:`${be}.preset`,code:"BLOCK_REQUIRES",message:`block "${ce}" needs "${oe}" in the same preset`});let Le={};for(let[oe,Te]of Object.entries(fe.blockParams?.[ce]??{})){let Ke=ke.params?.[oe];if(typeof Te=="string"&&(Ke?.type==="number"||Ke?.type==="boolean"))try{let Ne=Er(Te).eval({params:Ee});Le[oe]=Ke.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 Le[oe]=Te;}let _e={...Le,...xt(Z.blockParams)&&xt(Z.blockParams[ce])?Z.blockParams[ce]:{}};de[ce]=Ts(ke.params??{},_e,`${be}.blockParams.${ce}`,r);}if(xt(Z.blockParams))for(let ce of Object.keys(Z.blockParams))Ae.has(ce)||r.push({level:"warning",path:`${be}.blockParams.${ce}`,code:"BLOCK_NOT_IN_PRESET",message:`preset "${fe.id}" has no block "${ce}"`});let Pe=[...fe.rules??[],...jo(Z.rules)];As(Pe,t,`${be}.rules`,r);let we={};if(Z.content!==void 0)if(!xt(Z.content))r.push({level:"warning",path:`${be}.content`,code:"CONTENT_SHAPE",message:"content is { kind: { without: [ids] } }; ignored"});else for(let[ce,ke]of Object.entries(Z.content)){let Le=xt(ke)?ke.without:void 0;Array.isArray(Le)&&Le.every(_e=>typeof _e=="string")?we[ce]=[...Le]:r.push({level:"warning",path:`${be}.content.${ce}`,code:"CONTENT_SHAPE",message:"expected { without: [ids] }; ignored"});}i.push({id:Z.id,role:Z.role??(ye===0?"core":"meta"),preset:fe,params:Ee,blockParams:de,rules:Pe,content:we});}),s.length>0&&!s.some((Z,ye)=>xt(Z)?(Z.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 h=jo(n.resources),m=new Set;h.forEach((Z,ye)=>{let be=`resources.${ye}`;if(!xt(Z)||typeof Z.id!="string"||!Ci.test(Z.id)){r.push({level:"error",path:be,code:"RESOURCE_ID",message:"resource id: snake_case, starts with a letter"});return}m.has(Z.id)&&r.push({level:"error",path:`${be}.id`,code:"RESOURCE_DUPLICATE",message:`resource "${Z.id}" is defined twice`}),m.add(Z.id),["currency","item","score","local"].includes(Z.kind)||r.push({level:"error",path:`${be}.kind`,code:"RESOURCE_KIND",message:"kind is currency, item, score or local"}),(Z.kind==="currency"||Z.kind==="item")&&Z.ref!==void 0&&(typeof Z.ref!="string"||Z.ref.length===0)&&r.push({level:"error",path:`${be}.ref`,code:"RESOURCE_REF",message:"ref is the engine currency or item id"});});let v=jo(n.flows);v.forEach((Z,ye)=>{if(typeof Z?.amount=="string"){let be=Mi(Z.amount);be&&r.push({level:"error",path:`flows.${ye}.amount`,code:"FLOW_FORMULA",message:be});}}),Li(s.filter(xt),h.filter(Z=>xt(Z)&&typeof Z.id=="string"),v.filter(xt),r);let x=jo(n.rules);As(x,t,"rules",r);let D={};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[Z,ye]of Object.entries(n.vars))Ci.test(Z)?typeof ye=="number"||typeof ye=="string"||typeof ye=="boolean"?D[Z]=ye:r.push({level:"error",path:`vars.${Z}`,code:"VAR_TYPE",message:"a var is a number, text or true/false"}):r.push({level:"error",path:`vars.${Z}`,code:"VAR_NAME",message:"var name: snake_case"});let O=typeof n.assets=="string"&&n.assets?t.get(Fn,n.assets):void 0;if(n.assets!==void 0&&!O&&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[Z,ye]of Object.entries(n.palette))(typeof ye!="string"||!vp.test(ye))&&r.push({level:"warning",path:`palette.${Z}`,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[Z,ye]of Object.entries(n.texts)){if(Mp.test(Z)||r.push({level:"error",path:`texts.${Z}`,code:"TEXT_KEY",message:"text key: lower case, digits, _ . -"}),!xt(ye)){r.push({level:"error",path:`texts.${Z}`,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.${Z}.${be}`,code:"TEXT_LANG",message:"language code like en or pt-BR, value text"});ye.en===void 0&&r.push({level:"warning",path:`texts.${Z}`,code:"TEXT_NO_EN",message:"no English text: other languages fall back to it"});}let N={...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 Z=(be,fe,Ee)=>{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 Ae=Math.min(Math.max(de,fe),Ee);Ae!==de&&r.push({level:"warning",path:`rewards.${be}`,code:"PARAM_CLAMPED",message:`${de} \u2192 ${Ae}`}),N[be]=Ae;};Z("adMultiplier",1,10),Z("vipMultiplier",1,20);let ye=n.rewards.window;ye!==void 0&&(typeof ye=="string"&&/^[A-Za-z0-9_-]{1,64}$/.test(ye)?N.window=ye:r.push({level:"warning",path:"rewards.window",code:"PARAM_TYPE",message:"expected a window id, default used"}));}let q=n.multiplayer??"none";Bc.includes(q)||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:h,flows:v,rules:x,vars:D,rewards:N,multiplayer:q,palette:Ti({...O?.palette,...xt(n.palette)?n.palette:{}}),texts:Sp(O?.texts,xt(n.texts)?n.texts:void 0),look:{style:O?O.style??O.id:Di.style,cast:Ep({...Os,...O?.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 V=(e,t)=>qn(e,"#000000",t),Q=(e,t)=>qn(e,"#ffffff",t),Cs=e=>{let[t,r,o]=Pi(e);return (t*.299+r*.587+o*.114)/255},he=(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>`,Fe=(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>`,ie=(...e)=>`<defs>${e.join("")}</defs>`,Sn=e=>(Math.round(e*10)/10).toString(),Je=(e,t,r,o,n=5,s=-Math.PI/2)=>{let a=[];for(let i=0;i<n*2;i++){let h=i%2===0?r:o,m=s+i*Math.PI/n;a.push(`${Sn(e+Math.cos(m)*h)},${Sn(t+Math.sin(m)*h)}`);}return a.join(" ")},Dt=(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 h=i/a*Math.PI*2,m=i%4<2?r:r-n;s.push(`${Sn(e+Math.cos(h)*m)},${Sn(t+Math.sin(h)*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",U=Sn;var Ot=(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=V(e,.25),n;return r==="sci-fi"?n=`<polygon points="${Dt(32,31,11,6)}" fill="none" stroke="${V(e,.45)}" stroke-width="3.5"/><circle cx="32" cy="31" r="3.5" fill="${V(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="${V(e,.35)}"/>`:r==="post-apocalypse"?n=`<path d="${Go(32,31,13,10,3)}" fill="${V(e,.4)}"/><circle cx="32" cy="31" r="5" fill="${e}"/>`:n=`<polygon points="${Je(32,31,12,5.5)}" fill="${V(e,.35)}"/>`,ie(he("g",[[0,Q(e,.45)],[.55,e],[1,V(e,.2)]]))+`<circle cx="32" cy="35" r="26" fill="${V(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 Ot(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="${Q(e,.5)}"/><polygon points="32,4 26,24 38,24" fill="${Q(e,.3)}"/><polygon points="32,4 38,24 52,22" fill="${V(e,.1)}"/><polygon points="12,22 26,24 20,57" fill="${Q(e,.15)}"/><polygon points="52,22 38,24 44,57" fill="${V(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 ie(he("g",[[0,Q(e,.3)],[1,V(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 ie(he("m",[[0,"#5d6f96"],[1,"#2a3452"]]),Fe("o",[[0,Q(n,.6)],[.5,n,.9],[1,n,0]]))+Ot(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="${Q(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 ie(he("h",[[0,Q(n,.25)],[1,V(n,.2)]]))+Ot(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="${V(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 ie(he("r",[[0,"#6a2e18"],[.35,Q(n,.15)],[.7,n],[1,"#4a2010"]],true))+Ot(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 ie(he("w",[[0,"#5a3418"],[.3,Q(n,.15)],[.7,n],[1,"#4a2a12"]],true))+Ot(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="${V(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 Ot(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="${V(o,.12)}" stroke="${V(o,.4)}" stroke-width="3"/><path d="M20 24 L80 84 M80 24 L20 84" stroke="${Q(o,.15)}" stroke-width="9"/><path d="M20 24 L80 84 M80 24 L20 84" stroke="${V(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 ie(he("l",[[0,Q(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 ie(he("s",[[0,Q(n,.4)],[.5,n],[1,V(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 ie(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="${Q(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="${Je(44,38,8,3.5)}" fill="${o("coin")}"/>`;return Ot(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"?ie(he("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"?ie(he("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"?ie(he("t",[[0,t,0],[1,t,.7]],true))+`<rect x="0" y="12" width="40" height="8" rx="4" fill="url(#t)"/><polygon points="${Je(46,16,14,6)}" fill="${r("coin")}" stroke="#5b3b33" stroke-width="2" stroke-linejoin="round"/>`:ie(he("t",[[0,t,0],[1,t,.85]],true),Fe("o",[[0,"#fff"],[.45,Q(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=Q(t,.55),n=Q(t,.2),s=V(t,.32),a=ie(he("g",[[0,Q(t,.35)],[1,V(t,.25)]])),i=`stroke="${r}" stroke-width="4" stroke-linejoin="round"`,h;switch(e){case 1:h=`<circle cx="50" cy="52" r="40" fill="url(#g)" ${i}/><polygon points="${Dt(50,52,22,8,-Math.PI/8)}" fill="${n}"/><polygon points="${Dt(50,52,22,8,-Math.PI/8).split(" ").slice(5,8).join(" ")} 50,52" fill="${o}"/><polygon points="${Dt(50,52,22,8,-Math.PI/8).split(" ").slice(1,4).join(" ")} 50,52" fill="${s}"/>`;break;case 2:h=`<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:h=`<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:h=`<polygon points="${Je(50,54,44,20)}" fill="url(#g)" ${i}/><polygon points="${Je(50,54,22,10)}" fill="${n}"/><polygon points="50,10 50,54 30,44" fill="${o}" opacity="0.7"/>`;break;case 5:h=`<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="${Q(t,.35)}"/>`;break;default:h=`<polygon points="${Dt(50,50,42,6)}" fill="url(#g)" ${i}/><polygon points="${Dt(50,50,24,6)}" fill="${n}"/><polygon points="${Dt(50,50,42,6).split(" ").slice(4,6).join(" ")} ${Dt(50,50,42,6).split(" ")[0]} 50,50" fill="${o}" opacity="0.6"/><polygon points="${Dt(50,50,42,6).split(" ").slice(1,4).join(" ")} 50,50" fill="${s}" opacity="0.55"/>`;}return a+Ot(50,94,30,4,.22)+h+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="${U(2.4/o)}"/>`,Ko=(e,t,r,o,n)=>`<circle cx="${e-r*.55}" cy="${t+r*.2}" r="${r*.7}" fill="${V(o,.1)}" stroke="${n}" stroke-width="3"/><circle cx="${e+r*.55}" cy="${t+r*.2}" r="${r*.7}" fill="${V(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="${Q(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 Ot(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="${V(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="${V(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,Q(o,.15),r)+Un(50,42,-50,.9,Q(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="${Je(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 Ot(50,93,26,4)+Ii(r,52)+Ko(50,40,32,o,r);case 7:return Ot(50,93,28,4)+Ii(r,54)+Ko(50,40,34,V(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 Ot(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="${Je(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=ie(he("m",[[0,Q(o,.35)],[1,V(o,.35)]]));switch(e){case 1:return s+Ot(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="${V(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+Ot(50,86,26,4)+`<polygon points="${Dt(50,54,30,6)}" fill="url(#m)" stroke="${r}" stroke-width="3.5"/><circle cx="50" cy="54" r="12" fill="${V(o,.5)}" stroke="${r}" stroke-width="3"/>`+Gr("M30 42 L42 34",3.5,.6);case 3:return s+Ot(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="${V(o,.5)}" stroke="${r}" stroke-width="3"/>`;case 4:return s+Ot(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="${Q(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="${V(o,.5)}" stroke="${r}" stroke-width="2.5"/>`;case 5:return s+Ot(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+Ot(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="${V(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+Ot(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="${V(o,.5)}"/><rect x="6" y="38" width="10" height="22" rx="4" fill="${V(o,.2)}" stroke="${r}" stroke-width="3"/><rect x="84" y="38" width="10" height="22" rx="4" fill="${V(o,.2)}" stroke="${r}" stroke-width="3"/>`;default:return s+ie(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 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 ie(he("b",[[0,Q(o,.2)],[1,V(o,.3)]]),he("l",[[0,Q(o,.35)],[1,o]]))+Ot(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)=>U(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=U(Math.min(Math.min(e,t)*.14,24)),a=Cs(r)>.6;return ie(he("p",[[0,Q(r,a?.3:.12)],[1,V(r,a?.06:.25)]]))+`<rect x="${U(n/2)}" y="${U(n*1.5)}" width="${U(e-n)}" height="${U(t-n*2)}" rx="${s}" fill="#000" opacity="0.25"/><rect x="${U(n/2)}" y="${U(n/2)}" width="${U(e-n)}" height="${U(t-n*2)}" rx="${s}" fill="url(#p)" stroke="${a?V(r,.3):o}" 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="${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 ie(he("p",[[0,Q(r,.18)],[1,V(r,.3)]]),he("g",[[0,Q(a,.35)],[1,V(a,.25)]]))+`<rect x="${U(s)}" y="${U(s*2)}" width="${U(e-s*2)}" height="${U(t-s*2.5)}" rx="${pn(e,t,.1)}" fill="#000" opacity="0.35"/><rect x="${U(s)}" y="${U(s)}" width="${U(e-s*2)}" height="${U(t-s*2.5)}" rx="${pn(e,t,.1)}" fill="url(#g)" stroke="${o}" stroke-width="${U(s*.8)}"/><rect x="${U(s*2.4)}" y="${U(s*2.4)}" width="${U(e-s*4.8)}" height="${U(t-s*5.3)}" rx="${pn(e,t,.07)}" fill="url(#p)"/><circle cx="${U(e/2)}" cy="${U(t*.3)}" r="${U(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 ie(he("b",[[0,Q(r,.3)],[1,V(r,.1)]]))+`<rect x="${U(n/2)}" y="${U(s)}" width="${U(e-n)}" height="${U(t-s-n/2)}" rx="${pn(e,t,.3)}" fill="${V(r,.45)}" stroke="${o}" stroke-width="${U(n)}"/><rect x="${U(n/2)}" y="${U(n/2)}" width="${U(e-n)}" height="${U(t-s-n/2)}" rx="${pn(e,t,.3)}" fill="url(#b)" stroke="${o}" 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"/>`}},Kp={w:0,h:0,exact:true,main:"ground",draw({w:e,h:t,main:r}){let o=Cs(r)>.55;return ie(he("c",[[0,V(r,o?.12:.3)],[1,Q(r,o?.1:.06)]]))+`<rect x="1.5" y="1.5" width="${U(e-3)}" height="${U(t-3)}" rx="${pn(e,t,.16)}" fill="url(#c)"/><rect x="1.5" y="1.5" width="${U(e-3)}" height="${U(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?Q(r,.4):Q(r,.85);return `<path d="M${U(s)} ${U(s)} H${U(e-s)} V${U(t-n-s)} H${U(e*.58)} L${U(e*.5)} ${U(t-s)} L${U(e*.42)} ${U(t-n-s)} H${U(s)}Z" fill="${i}" stroke="${o}" stroke-width="${U(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 ie(he("p",[[0,Q(e,.35)],[1,V(e,.15)]]))+`<circle cx="50" cy="54" r="44" fill="${V(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)=>ie(he("b",[[0,Q(e,.55)],[1,V(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="${V(e,.35)}" stroke="${t}" stroke-width="3"/><circle cx="32" cy="32" r="3" fill="${Q(e,.6)}"/>`+Lr("M36 9 C44 13 49 20 51 28",3,.7)),Zp=mr("secondary",(e,t)=>ie(Fe("a",[[0,Q(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="${Q(e,.4)}" stroke-width="3" stroke-dasharray="7 5"/><circle cx="32" cy="32" r="10" fill="${Q(e,.5)}" stroke="${t}" stroke-width="2.5"/>`),Qp={w:100,h:100,main:"secondary",draw:({main:e})=>ie(Fe("a",[[0,e,.05],[.7,e,.18],[.94,Q(e,.3),.5],[1,Q(e,.4),0]]))+`<circle cx="50" cy="50" r="50" fill="url(#a)"/><circle cx="50" cy="50" r="46" fill="none" stroke="${Q(e,.5)}" stroke-width="1.5" stroke-dasharray="6 6" opacity="0.7"/>`},Yp=mr("accent",(e,t)=>ie(he("g",[[0,Q(e,.4)],[1,V(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="${V(e,.35)}" stroke-width="2.5"/>`+Lr("M14 15 C22 14 28 18 31 24",3,.7)),Jp=mr("primary",(e,t)=>ie(he("l",[[0,Q(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="${Q(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)=>ie(he("d",[[0,Q(e,.45)],[1,V(e,.2)]]))+`<rect x="4" y="18" width="20" height="5" rx="2.5" fill="${V(e,.4)}" stroke="${t}" stroke-width="2"/><rect x="40" y="18" width="20" height="5" rx="2.5" fill="${V(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)=>ie(he("f",[[0,Q(e,.35)],[1,V(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="${V(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="${V(e,.3)}" stroke="${t}" stroke-width="3"/><rect x="12" y="52" width="40" height="7" rx="3" fill="${V(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="${Q(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)=>ie(he("b",[[0,Q(e,.35)],[1,V(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="${V(e,.45)}" stroke="${t}" stroke-width="3"/><path d="M6 22 L14 22 M3 30 L13 30 M7 38 L13 38" stroke="${Q(e,.5)}" stroke-width="3" stroke-linecap="round"/>`+Lr("M23 11 L23 30",3,.6)),s0=mr("muted",(e,t)=>ie(he("s",[[0,Q(e,.45)],[1,V(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="${Q(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="${Q(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)=>ie(he("p",[[0,Q(e,.4)],[1,V(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)=>ie(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="${Je(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})=>ie(Fe("o",[[0,"#fff"],[.45,Q(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="${Q(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="${Je(32,32,29,17,10)}" fill="${Q(e,.25)}" stroke="${t}" stroke-width="3" stroke-linejoin="round"/><polygon points="${Dt(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 ie(he("b",[[0,Q(o.trim,.4)],[1,V(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="${V(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 ie(Fe("p",[[0,"#000000",1],[.7,"#0b0d14",.95],[1,V(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="${Q(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 ie(he("w",[[0,Q(n,.35)],[1,V(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="${Q(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="${Q(o.trim,.55)}" stroke="${t}" stroke-width="3"/>`).join("")+`<rect x="4" y="64" width="292" height="10" fill="${V(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 ie(he("r",[[0,Q(o.trim,.3)],[1,V(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 ie(he("s",[[0,Q(o,.35)],[1,V(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="${V(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:()=>ie(Fe("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})=>ie(Fe("c",[[0,Q(e,.5)],[.7,e],[1,V(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="${V(e,.25)}" stroke-width="2.5"/><rect x="30" y="40" width="30" height="20" rx="7" fill="${V(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})=>ie(he("g",[[0,Q(e,.6)],[1,V(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="${Q(e,.7)}" stroke-width="2.5" stroke-linecap="round"/><circle cx="32" cy="44" r="5" fill="${Q(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})=>ie(Fe("g",[[0,Q(e,.6),.75],[.6,e,.25],[1,e,0]]),he("s",[[0,Q(e,.55)],[1,V(e,.25)]]))+`<circle cx="50" cy="52" r="48" fill="url(#g)"/><polygon points="${Je(50,54,40,18)}" fill="url(#s)" stroke="${t}" stroke-width="4.5" stroke-linejoin="round"/><polygon points="${Je(50,54,22,10)}" fill="${Q(e,.45)}" opacity="0.7"/>`+zi("M38 32 L46 22",4,.75)},M0={w:64,h:64,main:"coin",draw:({main:e,ink:t})=>ie(he("k",[[0,Q(e,.45)],[1,V(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="${V(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})=>ie(he("p",[[0,Q(e,.4)],[1,V(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="${V(o,.25)}" stroke-width="2"/>`;for(let i=1;i<3;i++){let h=e+t*i/3+((a-r)/11%2?6:0);s+=`<line x1="${h}" y1="${a}" x2="${h}" y2="${a+11}" stroke="${V(o,.25)}" stroke-width="2"/>`;}}return ie(he("s",[[0,Q(o,.25)],[1,V(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),h=s(r==="sniper"?"danger":r==="ranger"?"coin":"accent"),m=Xc(28,44,i+18,a.stone,n),v=`<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(q=>`<rect x="${q-2}" y="${i-6}" width="4" height="15" fill="${Q(a.wood,.15)}" stroke="${n}" stroke-width="1.5"/>`).join("")+`<rect x="20" y="${i-8}" width="60" height="5" rx="2" fill="${Q(a.wood,.2)}" stroke="${n}" stroke-width="2.5"/>`,x=t>=2?`<polygon points="14,${i-8} 50,${i-36} 86,${i-8}" fill="${h}" stroke="${n}" stroke-width="3.5" stroke-linejoin="round"/><polygon points="14,${i-8} 50,${i-36} 38,${i-8}" fill="${Q(h,.25)}"/>`:"",D=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"/>`:"",O=(q,ne,Z=1)=>`<path d="M${q} ${ne-12*Z} Q${q+9*Z} ${ne} ${q} ${ne+12*Z}" fill="none" stroke="${a.wood}" stroke-width="${3.5*Z}" stroke-linecap="round"/><line x1="${q}" y1="${ne-12*Z}" x2="${q}" y2="${ne+12*Z}" stroke="#eee" stroke-width="1.5"/>`,N=O(66,i-2);return r==="ranger"&&(N=O(30,i-2)+O(68,i-2)),r==="sniper"&&(N=`<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="${V(a.metal,.3)}" stroke="${n}" stroke-width="2"/>`),zs+m+v+N+x+D+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),h=ie(he("b",[[0,Q(a.stone,.3)],[1,V(a.stone,.25)]],true),he("m",[[0,Q(a.metal,.35)],[1,V(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="${V(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,v=34*m,x=13*m,D=`<g transform="rotate(-28 50 ${i-4})"><rect x="46" y="${i-4-x/2}" width="${v}" height="${x}" rx="${x/3}" fill="url(#m)" stroke="${n}" stroke-width="3"/><rect x="${46+v-7}" y="${i-4-x/2-2}" width="8" height="${x+4}" rx="2" fill="${V(a.metal,.3)}" stroke="${n}" stroke-width="2.5"/></g><circle cx="50" cy="${i-4}" r="${9*m}" fill="${V(a.metal,.2)}" stroke="${n}" stroke-width="3"/>`,O=44+v,N=r==="flamer"?`<g transform="rotate(-28 50 ${i-4})"><path d="M${O} ${i-16} C${O+14} ${i-22} ${O+30} ${i-10} ${O+22} ${i-4} C${O+30} ${i+2} ${O+14} ${i+14} ${O} ${i+8}Z" fill="#ff7a1a" stroke="${n}" stroke-width="2.5" stroke-linejoin="round"/><path d="M${O+2} ${i-9} C${O+12} ${i-12} ${O+18} ${i-6} ${O+13} ${i-3} C${O+18} ${i} ${O+10} ${i+6} ${O+2} ${i+2}Z" fill="#ffd34a"/></g>`:"",q=r==="bombard"?`<polygon points="${Je(50,i+24,8,3.5)}" fill="${s("danger")}" stroke="${n}" stroke-width="2"/>`:"";return zs+h+D+N+q+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),h=r==="storm"?s("coin"):r==="arcane"?Q(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="${h}" stroke="${n}" stroke-width="2.5" opacity="0.9"/>`,v=i-28,x=`<polygon points="26,${i+2} 50,${v} 74,${i+2}" fill="${s("secondary")}" stroke="${n}" stroke-width="3.5" stroke-linejoin="round"/><polygon points="26,${i+2} 50,${v} 42,${i+2}" fill="${Q(s("secondary"),.25)}"/>`,D=7+t*1.3+(r==="arcane"?3:0),O=Math.max(D+6+(r==="arcane"?8:0),v-D*.5),N=ie(Fe("o",[[0,"#ffffff",1],[.45,h,.95],[1,h,.3]]))+`<circle cx="50" cy="${O}" r="${D+7}" fill="${h}" opacity="0.25"/><circle cx="50" cy="${O}" r="${D}" fill="url(#o)" stroke="${n}" stroke-width="2.5"/>`,q=r==="storm"?[-1,1].map(ne=>`<path d="M${50+ne*(D+3)} ${O-6} L${50+ne*(D+10)} ${O} L${50+ne*(D+5)} ${O+2} L${50+ne*(D+13)} ${O+10}" fill="none" stroke="${s("coin")}" stroke-width="3" stroke-linejoin="round"/>`).join(""):r==="arcane"?`<circle cx="50" cy="${O}" r="${D+11}" fill="none" stroke="${h}" stroke-width="2.5" stroke-dasharray="5 4"/>`:"";return zs+m+x+N+q}function _0(e,t,r){let{style:o,ink:n,c:s}=e,a=Kr(o),i=Bi(t)+10-(r?6:0),h=r==="glacier"?V(s("primary"),.15):Q(s("primary"),.35),m=ie(he("p",[[0,Q(a.stone,.25)],[1,V(a.stone,.25)]],true),he("i",[[0,"#ffffff"],[.5,h],[1,V(h,.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"/>`,v=(O,N,q,ne)=>`<g transform="rotate(${ne} ${O} ${i+20})"><polygon points="${O-q},${i+20} ${O-q*.8},${i+20-N*.75} ${O},${i+20-N} ${O+q*.8},${i+20-N*.75} ${O+q},${i+20}" fill="url(#i)" stroke="${n}" stroke-width="2.5" stroke-linejoin="round"/><line x1="${O}" y1="${i+20-N}" x2="${O}" y2="${i+18}" stroke="#fff" stroke-width="1.5" opacity="0.6"/></g>`,x=v(50,38+t*6,10,0);t>=2&&(x=v(36,26+t*3,7,-14)+v(64,26+t*3,7,14)+x),t>=3&&(x=v(28,20,5,-26)+v(72,20,5,26)+x),r==="glacier"&&(x+=v(50,70,15,0));let D=r==="blizzard"?[0,1,2,3,4].map(O=>`<polygon points="${Je(22+O*14,i-30+O%2*12,5,2,6)}" fill="#fff" stroke="${n}" stroke-width="1.2"/>`).join(""):"";return zs+m+x+D}var R0={archer:E0,cannon:S0,mage:L0,frost:_0},Ct=(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:Q(o.stone,.15)}" stroke="${t}" stroke-width="2.5"/>`}).join("");return `<ellipse cx="50" cy="34" rx="40" ry="22" fill="${V(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="${V(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="${Q(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="${V(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"/>`:ie(Fe("l",[[0,Q(n,.35),1],[1,V(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="${Dt(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="${Q(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})=>ie(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="${V(e,.35)}"/><circle cx="48" cy="70" r="4" fill="${V(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 ie(he("g",[[0,Q(e,.5)],[1,V(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"/>`+ie(he("g",[[0,Q(r("coin"),.45)],[1,V(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="${V(r("coin"),.45)}" stroke-width="4" stroke-linecap="round"/>`}},Zc={td_sell:B0,td_archer1:Ct("archer",1),td_archer2:Ct("archer",2),td_archer3:Ct("archer",3),td_archer_ranger:Ct("archer",3,"ranger"),td_archer_sniper:Ct("archer",3,"sniper"),td_cannon1:Ct("cannon",1),td_cannon2:Ct("cannon",2),td_cannon3:Ct("cannon",3),td_cannon_bombard:Ct("cannon",3,"bombard"),td_cannon_flamer:Ct("cannon",3,"flamer"),td_mage1:Ct("mage",1),td_mage2:Ct("mage",2),td_mage3:Ct("mage",3),td_mage_arcane:Ct("mage",3,"arcane"),td_mage_storm:Ct("mage",3,"storm"),td_frost1:Ct("frost",1),td_frost2:Ct("frost",2),td_frost3:Ct("frost",3),td_frost_glacier:Ct("frost",3,"glacier"),td_frost_blizzard:Ct("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=h=>`${(50+Math.cos(h)*38).toFixed(1)} ${(50+Math.sin(h)*38).toFixed(1)}`;return `<path d="M50 50 L${i(s)} A38 38 0 0 1 ${i(a)}Z" fill="${o}"/>`});return ie(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="${Je(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="${Je(78,20,13,5,8)}" fill="#ffd34a" stroke="${e}" stroke-width="2"/>`},Yc=e=>({w:100,h:100,draw:({ink:t})=>ie(he("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 ie(he("s",[[0,Q(o,.35)],[1,V(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="${V(o,.5)}" stroke-width="3.5" stroke-linecap="round"/>`)+(e?`<path d="M30 40 L70 40 M30 60 L70 60" stroke="${V(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})=>ie(he("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})=>ie(he("h",[[0,Q(e,.45)],[1,V(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})=>ie(he("s",[[0,Q(e,.45)],[1,V(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="${Q(e,.3)}" opacity="0.7"/>`+Fo("M24 26 L36 22",4,.7)},U0={w:100,h:100,draw:({ink:e})=>ie(Fe("f",[[0,"#fff6c0",1],[.45,"#ffb23a",1],[1,"#e0442e",1]]))+`<polygon points="${Je(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}"/>`,Yt=e=>({w:100,h:100,draw:({ink:t})=>e(t)}),qo="#e8b84a",Ln="#c9803a",Q0=e=>Yt(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="${Q(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="${V(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 ie(he("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 ie(Fe("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 ie(he("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 ie(he("l",[[0,"#f2bb66"],[1,V(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="${V(Ln,.35)}" stroke-width="4" fill="none" stroke-linecap="round"/>`).join("")+br("M16 60 Q18 46 30 40",4,.45);case 6:return ie(he("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="${Q(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="${Q(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 ie(he("c",[[0,"#fff4f6"],[1,"#f2c6d2"]]),he("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=>Yt(t=>{switch(e){case 1:return ie(Fe("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,V(Or,.15),t)+Xn(70,88,48,13,"#a88aff",t)+Xn(50,88,70,16,Or,t);case 4:return ie(he("g",[[0,Q(Or,.4)],[1,V(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 ie(he("k",[[0,Q(Uo,.3)],[1,V(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="${V(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=>Yt(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 ie(Fe("d",[[0,Q(Fr,.5)],[1,V(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 ie(he("b",[[0,Q(Fr,.3)],[1,V(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 ie(he("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="${Q("#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 ie(Fe("o",[[0,"#ffffff"],[.35,Q(Fr,.4)],[1,V(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="${Je(50,46,12,5,4)}" fill="#fff" opacity="0.85"/>`+[[18,20],[84,26],[80,70],[16,66]].map(([r,o])=>`<polygon points="${Je(r,o,5,2,4)}" fill="#fff6c0"/>`).join("")}}),Bs=(e,t)=>ie(he("pad",[[0,Q(e,.25)],[1,V(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=Yt(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=Yt(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="${V("#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=Yt(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="${V("#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=Yt(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=>Yt(t=>{let r="#c08a4a";return ie(he("w",[[0,Q(r,.15)],[1,V(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="${V(r,.35)}" stroke-width="2"/>`).join("")+`<path d="M14 14 L86 86 M86 14 L14 86" stroke="${V(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:()=>ie(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>'},sh=Yt(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="${Dt(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="${Dt(50,50,t,8,0)}"/>`).join("")+"</g>"),ah={w:100,h:100,draw:()=>ie(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"/>'+br("M24 38 Q28 24 42 18",6,.85)+'<circle cx="72" cy="72" r="4" fill="#fff" opacity="0.7"/>'},ih=Yt(e=>ie(he("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="${Je(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=Yt(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=Yt(e=>ie(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"/>`),dh=Yt(e=>ie(he("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=Yt(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="${Je(t,r,9,3.5,4)}" fill="#fff6a0" stroke="${e}" stroke-width="1.5"/>`).join("")),ph=Yt(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=Yt(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="${Je(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="${Je(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"}},dr=e=>od[e]??od.default,uh={w:100,h:200,draw({style:e}){let t=dr(e),r="";if(e==="sci-fi"){let o=Mr(7);r=Array.from({length:60},()=>`<circle cx="${U(o()*100)}" cy="${U(o()*150)}" r="${U(.3+o()*.6)}" fill="#fff" opacity="${U(.3+o()*.7)}"/>`).join("");}return ie(he("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 ie(he("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 ie(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}"/>`}},Hs=(e,t,r,o,n,s)=>{let a=Mr(e),i=Array.from({length:s},()=>o-a()*n);i.push(i[0]);let h=i.map((m,v)=>`${U(v/s*t)},${U(m)}`);return `M0 ${r} L${h.join(" L")} L${t} ${r}Z`},yh={w:512,h:200,band:true,draw({style:e}){let t=dr(e),r=qn(t.far1,t.skyBottom,.35);if(e==="sci-fi"){let h=Mr(11),m=0,v="",x="";for(;m<500;){let D=26+Math.floor(h()*40),O=50+Math.floor(h()*130),N=Math.min(D,512-m);v+=`<rect x="${m}" y="${200-O}" width="${N}" height="${O}" fill="${h()<.5?t.far1:t.far2}"/>`,h()<.3&&(v+=`<rect x="${m+N/2-1}" y="${200-O-18}" width="2" height="18" fill="${t.far1}"/><circle cx="${m+N/2}" cy="${200-O-18}" r="2" fill="#ff3d6e"/>`);for(let q=200-O+8;q<196;q+=10)for(let ne=m+4;ne<m+N-4;ne+=7)h()<.35&&(x+=`<rect x="${ne}" y="${q}" width="3" height="4" fill="${h()<.5?"#36e3ff":"#ffd36e"}" opacity="0.8"/>`);m+=N+2;}return v+x}if(e==="post-apocalypse"){let h=Mr(13),m=6,v=`<path d="${Hs(3,512,200,170,22,8)}" fill="${r}"/>`;for(;m<490;){let x=30+Math.floor(h()*36),O=200-(60+Math.floor(h()*110)),N=h()*20;v+=`<path d="M${m} 200 L${m} ${O+N} L${m+x*.3} ${O} L${m+x*.55} ${O+14+N} L${m+x} ${O+6} L${m+x} 200Z" fill="${h()<.5?t.far1:t.far2}"/>`;for(let q=O+20;q<190;q+=14)for(let ne=m+5;ne<m+x-6;ne+=10)h()<.5&&(v+=`<rect x="${ne}" y="${q}" width="4" height="6" fill="${t.near}" opacity="0.7"/>`);m+=x+8+Math.floor(h()*20);}return v+'<ellipse cx="380" cy="60" rx="60" ry="14" fill="#2a1a14" opacity="0.25"/>'}if(e==="cozy"){let h=[80,230,400].map((m,v)=>`<rect x="${m}" y="${132-v*6}" width="22" height="18" fill="#fff4e8"/><polygon points="${m-3},${133-v*6} ${m+11},${120-v*6} ${m+25},${133-v*6}" fill="${["#ff8f8f","#8fb8ff","#ffb86b"][v]}"/><rect x="${m+8}" y="${140-v*6}" width="6" height="10" fill="#c98b5a"/>`).join("");return `<path d="${Hs(5,512,200,140,30,6)}" fill="${t.far1}"/>`+h+`<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="${V(t.far2,.12)}"/>`).join("")}let o=Mr(17),n=[],s=[],a=(h,m)=>{n.push(`M${U(h-110)} 200 L${U(h)} ${U(m)} L${U(h+110)} 200Z`),s.push(`M${U(h-24)} ${U(m+26)} L${U(h)} ${U(m)} L${U(h+24)} ${U(m+26)} L${U(h+10)} ${U(m+20)} L${U(h)} ${U(m+28)} L${U(h-10)} ${U(m+20)}Z`);};for(let h=0;h<4;h++){let m=64+h*128+(o()-.5)*30,v=30+o()*40;a(m,v),m-110<0&&a(m+512,v),m+110>512&&a(m-512,v);}let i=e==="fantasy"?`<g fill="${V(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(h=>`<rect x="${h}" 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=dr(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,h)=>`<path d="M${i} 150 L${i+3} ${150-h} M${i+2} ${150-h*.6} L${i-14} ${150-h*.85} M${i+2} ${150-h*.45} L${i+18} ${150-h*.7} M${i+3} ${150-h*.8} L${i+12} ${150-h}" 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="${Q(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="${V(t.near,.3)}"/>`;for(let h=0;h<3;h++){let m=150-a*.15-h*a*.26,v=i*(1-h*.25);n+=`<polygon points="${U(s-v)},${U(m)} ${U(s)},${U(m-a*.42)} ${U(s+v)},${U(m)}" fill="${h===2?Q(t.near,.08):t.near}"/>`;}}return n}};function sd(e,t){let r=dr(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="${Q(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="${V(r.crust,.3)}"/>`}var bh={w:128,h:512,draw(e){let t=dr(e.style),r=Mr(41),o="";for(let n=0;n<14;n++)o+=`<ellipse cx="${U(8+r()*112)}" cy="${U(40+r()*460)}" rx="${U(4+r()*7)}" ry="${U(3+r()*4)}" fill="${V(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("")),ie(he("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=dr(e.style);return ie(he("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=dr(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:Q(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="${U(r()*128)}" cy="${U(10+r()*80)}" rx="${U(2+r()*3)}" ry="${U(1.5+r()*2)}" fill="${V(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=dr(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="${Q(t.floor,.05)}"/><rect x="2" y="66" width="60" height="60" rx="4" fill="${Q(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${U(s)} ${U(a)} l-3 -6 M${U(s)} ${U(a)} l0 -7 M${U(s)} ${U(a)} l3 -6" stroke="${t.detail}" stroke-width="2" stroke-linecap="round"/>`,e==="cozy"&&n%5===0&&(o+=`<circle cx="${U(s+6)}" cy="${U(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=dr(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(h=>`<rect x="22" y="${23+h*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="${Q(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,h],m)=>`<polygon points="${Je(i,h,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=dr(e),n=Mr(Math.round(t*13+r)),s="";for(let a=0;a<4;a++){let i=t*(.15+n()*.7),h=r*(.2+n()*.65);s+=e==="sci-fi"?`<circle cx="${U(i)}" cy="${U(h)}" r="${U(t*.02)}" fill="#4a5a88"/>`:`<path d="M${U(i)} ${U(h)} l${U(-t*.04)} ${U(-r*.08)} M${U(i)} ${U(h)} l0 ${U(-r*.1)} M${U(i)} ${U(h)} l${U(t*.04)} ${U(-r*.08)}" stroke="${o.detail}" stroke-width="${U(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="${V(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=dr(e),s=Mr(Math.round(t*7+r*3)),a="";for(let h=0;h<5;h++)a+=`<ellipse cx="${U(t*(.15+s()*.7))}" cy="${U(r*(.15+s()*.7))}" rx="${U(t*(.04+s()*.05))}" ry="${U(r*.035)}" fill="${V(n.road,.18)}"/>`;let i=e==="sci-fi"?`<rect x="${U(t*.42)}" y="${U(r*.42)}" width="${U(t*.16)}" height="${U(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 O=t==="sci-fi"?"#5d6f96":"#7a6a52",N=t==="sci-fi"?o:n("coin"),q=Array.from({length:e},(Z,ye)=>`<rect x="50" y="${52-(e-1)*5+ye*10}" width="${36+e*2}" height="8" rx="3" fill="${V(O,.25)}" stroke="${r}" stroke-width="2.5"/>`).join(""),ne=t==="post-apocalypse"?[0,1,2].map(Z=>`<ellipse cx="${26+Z*24}" cy="106" rx="14" ry="9" fill="#a89070" stroke="${r}" stroke-width="2.5"/>`).join("")+[0,1].map(Z=>`<ellipse cx="${38+Z*24}" cy="94" rx="14" ry="9" fill="#b8a080" stroke="${r}" stroke-width="2.5"/>`).join(""):`<polygon points="${Dt(50,100,34,6,0)}" fill="#2a3452" stroke="${r}" stroke-width="3.5"/><polygon points="${Dt(50,100,22,6,0)}" fill="${N}" opacity="0.4"/>`;return s+ne+`<rect x="38" y="64" width="24" height="30" fill="${O}" stroke="${r}" stroke-width="3"/>`+q+`<path d="M24 68 A26 26 0 0 1 76 68Z" fill="${Q(O,.15)}" stroke="${r}" stroke-width="3.5"/><circle cx="50" cy="56" r="${5+e}" fill="${N}" stroke="${r}" stroke-width="2.5"/>`}let a=t==="cozy"?"#f4e6d4":"#a7a9b2",i=t==="cozy"?n("primary"):o,h=70-e*14,m="";for(let O=h+10;O<112;O+=12)m+=`<line x1="26" y1="${O}" x2="74" y2="${O}" stroke="${V(a,.25)}" stroke-width="2"/>`+[0,1].map(N=>`<line x1="${36+N*16+O/12%2*8}" y1="${O}" x2="${36+N*16+O/12%2*8}" y2="${O+12}" stroke="${V(a,.25)}" stroke-width="2"/>`).join("");let v=[26,40,54,68].map(O=>`<rect x="${O}" y="${h-10}" width="8" height="12" fill="${a}" stroke="${r}" stroke-width="2.5"/>`).join(""),x=e>=2?`<polygon points="20,${h-2} 50,${h-44} 80,${h-2}" fill="${i}" stroke="${r}" stroke-width="3.5" stroke-linejoin="round"/><polygon points="20,${h-2} 50,${h-44} 40,${h-2}" fill="${Q(i,.2)}"/>`:v,D=e>=3?`<line x1="50" y1="${h-44}" x2="50" y2="${h-64}" stroke="${r}" stroke-width="3"/><path d="M50 ${h-64} L70 ${h-58} L50 ${h-52}Z" fill="${n("coin")}" stroke="${r}" stroke-width="2"/>`:"";return s+ie(he("s",[[0,Q(a,.2)],[1,V(a,.2)]],true))+`<rect x="24" y="${h}" width="52" height="${116-h}" fill="url(#s)" stroke="${r}" stroke-width="3.5"/>`+m+`<rect x="44" y="${h+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"/>`+x+D}}),Sh=e=>({w:120,h:120,main:`piece${e}`,draw({style:t,ink:r,main:o,c:n}){let s=dr(t),a=t==="cozy"?Q(o,.6):s.wall,i=t==="sci-fi"?n("primary"):t==="post-apocalypse"?"#3a3530":"#9fd2f0",h=(x,D,O=12,N=14)=>`<rect x="${x}" y="${D}" width="${O}" height="${N}" rx="2" fill="${i}" stroke="${r}" stroke-width="2"/>`+(t==="post-apocalypse"?`<path d="M${x} ${D+3} L${x+O} ${D+N-3}" stroke="#8a6a3a" stroke-width="3"/>`:`<rect x="${x+2}" y="${D+2}" width="${O*.3}" height="${N*.4}" fill="#fff" opacity="0.5"/>`),m='<ellipse cx="60" cy="114" rx="50" ry="6" fill="#000" opacity="0.25"/>',v=(x,D,O)=>{let N="";for(let q=0;q<O;q+=12)N+=`<path d="M${x+q} ${D} h12 v10 q-6 6 -12 0Z" fill="${q/12%2?"#fff":o}" stroke="${r}" stroke-width="2"/>`;return N};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="${V(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}"/>`+v(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"/>`+v(22,54,76)+h(28,72,28,24)+`<rect x="68" y="72" width="22" height="38" fill="${V(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"/>`+h(30,36)+h(54,36)+h(78,36)+v(20,62,80)+h(30,78,26,22)+`<rect x="66" y="78" width="22" height="32" fill="${V(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="${V(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="${V(a,.08)}" stroke="${r}" stroke-width="3" stroke-linejoin="round"/>`+h(22,62)+h(46,62)+h(70,62)+`<rect x="40" y="84" width="40" height="26" fill="${o}" stroke="${r}" stroke-width="3"/>`+[0,1,2].map(x=>`<line x1="40" y1="${90+x*7}" x2="80" y2="${90+x*7}" stroke="${V(o,.35)}" stroke-width="2"/>`).join("");case 5:return m+`<polygon points="8,42 60,12 112,42" fill="${Q(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="${V(s.wall,.1)}" stroke="${r}" stroke-width="3"/>`+[20,40,72,92].map(x=>`<rect x="${x}" y="50" width="8" height="52" fill="${Q(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="${V(s.wall,.15)}" stroke="${r}" stroke-width="3"/>`;default:{let x="";for(let D=22;D<92;D+=18)x+=h(40,D,12,12)+h(62,D,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"/>`+x+`<rect x="50" y="94" width="20" height="16" fill="${V(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=dr(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="${V(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="${V(r,.25)}" stroke="${t}" stroke-width="3"/><rect x="66" y="76" width="30" height="34" fill="${V(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="${Je(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=dr(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="${V(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="${Q(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="${Q(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=>ie(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>`),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=>ie(he("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=>ie(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="${Je(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=N=>Ai(N,o),h=r.exact?s.w:r.w,m=r.exact?s.h:r.h,v=r.draw({style:n,c:i,main:i(t.color??r.main??"primary"),ink:jc(n),w:h,h:m}),x=Math.max(1,Math.round(a.h)),D=Math.max(0,Math.round(t.padBottom??0)),O=D>0?m*(x+D)/x:m;return `<svg xmlns="http://www.w3.org/2000/svg" width="${Math.max(1,Math.round(a.w))}" height="${x+D}" viewBox="0 0 ${h} ${O}" preserveAspectRatio="none">${v}</svg>`}var Be=e=>({w:Number(e.vars.view_w??720),h:Number(e.vars.view_h??1280)}),ot=e=>e.vars.state==="playing",hn=e=>e.vars.started_tick===e.tick,Qe=(e,t,r)=>{let o=Number(e.vars[t]??0)+r;return e.vars[t]=o,o},yr=(e,t)=>Number(e[t]);function Pt(e,t,r,o,n){let s=e.create();return e.set(s,F,{x:t,y:r}),e.set(s,le,o),n&&e.set(s,n.type,n.data),s}var ct=(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(zt,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 st=(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")}`},K=(e,t)=>e.emit(Oi,t),Yn=ve("kit.backdrop");function Bt(e,t,r,o={}){for(let v of e.query(Yn))e.destroy(v);let n=Be(e),s=(v,x,D,O)=>Pt(e,x,D,O,{type:Yn,data:{speed:v}});if(t==="top"){let v=o.pan?1:0;s(v,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 x=e.rng.stream("backdrop"),D=Math.round(n.w*n.h/52e3),O=Math.min(n.w,n.h);for(let N=0;N<D;N++){let q=O*x.range(.06,.1);s(v,x.range(0,n.w),x.range(0,n.h),{shape:"sprite",art:`decor${x.int(1,4)}`,w:q,h:q,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 h=Math.min(n.h*.32,n.w*.55);s(.12,n.w/2,a-h/2,{shape:"tile",art:"far",w:n.w,h,depth:-90});let m=h*.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:h*.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,le);n.shape==="tile"&&(n.scrollX=(n.scrollX??0)+t*o);}}function pd(e,t,r){let o=Be(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,le);if(a.shape==="tile"){a.scrollX=(a.scrollX??0)+t,a.scrollY=(a.scrollY??0)+r;continue}let i=e.need(s,F);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 at(e,t,r){let o=e.get(t,le);o?.shape==="actor"&&(o.pose=r);}function Ge(e,t,r){let o=e.get(t,le);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,le);i&&(i.alpha=Math.max(0,Math.min(1,a.left/a.total*2))),a.left<=0&&o.destroy(s);}}}));}var Jt=(e,t,r=5)=>r+t/Math.max(1,Be(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){Ht(e);let s=n??Math.min(Be(e).w,Be(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);Pt(e,r.x,r.y,{shape:"circle",r:s*.22,color:"#ffffff",alpha:0,depth:89},{type:Zn,data:{...a,part:"ring"}}),Pt(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(h,m){for(let v of h.query(Zn)){let x=h.need(v,Zn);x.t+=m;let D=h.need(v,F),O=h.need(v,le);if(x.kind==="tap"){let N=x.t%1.2/1.2,q=N>.35&&N<.55;if(x.part==="hand"){let ne=js(x.ax,x.ay+(q?x.size*.06:0),x.size);D.x=ne.x,D.y=ne.y,D.scale=q?.9:1,O.alpha=Math.min(1,x.t*4);}else {let ne=N<.4?0:(N-.4)/.6;D.scale=1+ne*2.2,O.alpha=N<.4?0:.55*(1-ne);}}else if(x.kind==="swipe"){let N=x.t%1.6/1.6,q=N<.15?0:N>.75?1:(N-.15)/.6,ne=q*q*(3-2*q),Z=x.ax+(x.bx-x.ax)*ne,ye=x.ay+(x.by-x.ay)*ne;if(x.part==="hand"){let be=js(Z,ye,x.size);D.x=be.x,D.y=be.y,O.alpha=N<.1?N*10:N>.85?Math.max(0,(1-N)/.15):1;}else D.x=Z,D.y=ye,O.alpha=N>.15&&N<.8?.35:0;}else {let N=x.t*3,q=x.ax+Math.cos(N)*x.bx,ne=x.ay+Math.sin(N)*x.bx;if(x.part==="hand"){let Z=js(q,ne,x.size);D.x=Z.x,D.y=Z.y,O.alpha=Math.min(1,x.t*3);}else D.x=q,D.y=ne,O.alpha=.3;}}}}));}function Ht(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,Ht(e));}var eo=ve("round.start"),qt="round-started",Ut="round-over",Xt="round-ended",Wi="start-round",Zt="show-start",er="revive-offer",tr="revive",rr="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=Be(o),s=Math.min(n.w,n.h)*.26,a={x:n.w/2,y:n.h*.55};Pt(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}}),Pt(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);Ht(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(qt,{round:e.vars.round});};e.on(zt,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(Zt,()=>{e.vars.state==="ended"&&(e.vars.state="ready",t(e));}),e.on(Ft,()=>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,F).scale=1+.06*Math.sin(a.t*5));}}}),t(e),e.on(Ut,o=>{if(e.vars.state!=="playing")return;e.vars.state="ended",Ht(e);let n=Number(e.vars.score??0),s=Math.max(Number(e.vars.best??0),n);e.vars.best=s,e.emit(Xt,{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"),Vt=(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},It={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)]}),h=Sr(r,"powers",Yo),m=i(to(1,o("difficulty"))),v=m.length,x=0,D=0,O=0,N=false,q=false,ne=false,Z=0,ye=0,be=0,fe=0,Ee=0,de=0,Ae=0,Pe=3,we=0,ce=false,ke=null,Le=new Map,_e=new Map,oe=()=>no.find(u=>u.id===e.vars["meta:hero"])??no[0],Te=u=>(Rr[u].seconds+Jo(e,Rr[u].var))*(oe().perk==="power"?1.25:1),Ke=()=>e.vars.reviving===true,Ne=()=>{for(let c of e.query(Fs))e.destroy(c);let u=Vt(e,n);Bt(e,"side",u.top+2);for(let c=0;c<n;c++){let p=e.create();e.set(p,Fs,{index:c}),e.set(p,F,{x:u.viewW/2,y:u.top+u.laneH*(c+.5)}),e.set(p,le,{shape:"tile",art:"road",w:u.viewW,h:u.laneH,unit:u.laneH*1.28,depth:-20+c*.1});}let f=u.viewH-(u.top+u.laneH*n),b=e.create();e.set(b,Fs,{index:-1}),e.set(b,F,{x:u.viewW/2,y:u.viewH-f/2+1}),e.set(b,le,{shape:"tile",art:"ground",w:u.viewW,h:f+2,unit:u.laneH*1.2,depth:-21});},se=(u,f,b)=>oo(u,f.lane)-f.alt-b/2,Ie=(u,f,b,c,p)=>{let k=u.laneH,_=9+b;switch(f){case "wall":return {v:{shape:"sprite",art:"obstacle",w:c,h:k*It.wall,depth:_},h:k*It.wall};case "barrier":return {v:{shape:"sprite",art:"hurdle",w:c,h:k*It.barrier,depth:_},h:k*It.barrier};case "pit":return {v:{shape:"sprite",art:"pit",w:c,h:k*.42,depth:-19+b*.1+.05},h:-k*.42};case "mover":return {v:{shape:"actor",cast:"foe",h:k*1.5,pose:"run",facing:-1,depth:_},h:k*1.5};case "train":return {v:{shape:"sprite",art:"wagon",w:c,h:k*It.train,depth:_},h:k*It.train};case "ramp":return {v:{shape:"sprite",art:"ramp",w:c,h:k*It.train,depth:_},h:k*It.train};case "rock":return {v:{shape:"sprite",art:"shadow",w:c,h:k*.3,alpha:.5,depth:-19+b*.1+.06},h:-k*.3};case "coin":return {v:{shape:"sprite",art:"coin",w:c,h:c,depth:_+.2},h:c};case "power":return {v:{shape:"sprite",art:Rr[p??"magnet"].art,color:Rr[p??"magnet"].color,w:c,h:c,depth:_+.2},h:c};case "finish":return {v:{shape:"sprite",art:"finish",w:k*.7,h:k*n+k*.9,depth:8},h:0}}},$e=(u,f,b,c={})=>{let p=Vt(e,n),k=c.size??(u==="coin"?p.laneH*.42:u==="power"?p.laneH*.62:p.laneH*.85),_=c.alt??(u==="coin"?p.laneH*.5:u==="power"?p.laneH*.6:0),C=e.create();e.set(C,_t,{lane:f,kind:u,size:k,alt:_,...c.power!==void 0?{power:c.power}:{}});let{v:z,h:B}=Ie(p,u,f,k,c.power),ae=p.viewW+p.laneH+k/2+b,pe=u==="finish"?p.top+p.laneH*n/2:B<0?oo(p,f)+B/2+p.laneH*.08:se(p,{lane:f,alt:_},B);return e.set(C,F,{x:ae,y:pe}),e.set(C,le,z),u==="coin"&&fe++,C},Se=(u,f,b,c)=>{let p=Vt(e,n);for(let k=0;k<b;k++)$e("coin",u,f+k*p.laneH*.75,c!==void 0?{alt:c}:{});},Ye=(u,f)=>{let b=1+Jo(e,"meta:luck");s.chance(Math.min(.9,o("powerRate")*b))&&$e("power",u,f,{power:s.weighted(h,c=>Rr[c].weight)});},ee=u=>m.kinds.includes(u),Re=()=>[...Array(n).keys()],rt=u=>{let f=["wall",...ee("barrier")?["barrier"]:[],...ee("pit")?["pit"]:[]],b=new Map;for(let k of Re())s.chance(m.density)&&b.set(k,s.pick(f));b.size>=n&&b.delete(s.int(0,n-1));let c=Vt(e,n);for(let[k,_]of b)$e(_,k,u,_==="pit"?{size:c.laneH*1.25}:{});let p=Re().filter(k=>!b.has(k));p.length>0&&s.chance(o("coinRate"))&&Se(s.pick(p),u-c.laneH,3);for(let[k,_]of b)(_==="barrier"||_==="pit")&&s.chance(.5)&&Se(k,u-c.laneH*.75,3,c.laneH*1.3);},ht=()=>{let f=Vt(e,n).laneH,b=p=>p+Math.round(m.density*3),c=[{id:"scatter",weight:3,make:p=>{let k=b(2);for(let _=0;_<k;_++)rt(_*p);return Ye(s.int(0,n-1),k*p-p/2),k*p}},{id:"rest",weight:1,make:p=>{let k=s.int(0,n-1);for(let _=0;_<4;_++)Se(k,_*p*.8,3),k=Math.max(0,Math.min(n-1,k+(s.chance(.5)?1:-1)));return Ye(k,4*p*.8),4*p*.8}}];return m.level>=3&&c.push({id:"corridor",weight:2,make:p=>{let k=b(3),_=s.int(0,n-1);for(let C=0;C<k;C++){for(let z of Re())z!==_&&$e("wall",z,C*p);Se(_,C*p-f*.4,2),C%2===1&&(_=Math.max(0,Math.min(n-1,_+(s.chance(.5)?1:-1))));}return k*p}}),(ee("barrier")||ee("pit"))&&c.push({id:"hurdles",weight:2,make:()=>{let p=Math.max(f*3.6,m.speed*o("jumpTime")*1.45),k=2+Math.round(m.density*2),_=[...ee("barrier")?["barrier"]:[],...ee("pit")?["pit"]:[]],C=s.int(0,n-1);for(let z=0;z<k;z++){for(let B of Re()){let ae=s.pick(_);$e(ae,B,z*p,ae==="pit"?{size:f*1.25}:{});}Se(C,z*p-f*.75,3,f*1.3);}return k*p}}),ee("train")&&c.push({id:"train",weight:2,make:p=>{let k=s.int(0,n-1),_=f*s.int(5,8),C=s.chance(.75),z=f*1.4;C&&$e("ramp",k,0,{size:z}),$e("train",k,(C?z:0)+_/2-f*.42,{size:_}),C&&Se(k,z+f*.4,Math.floor(_/(f*.75))-1,f*(It.train+.5));let B=Re().filter(pe=>pe!==k),ae=s.pick(B);if(s.chance(.5))$e("train",ae,p*.5+_/2,{size:_*.8});else for(let pe=0;pe<2;pe++)$e("wall",ae,p*(.5+pe*1.4));return (C?z:0)+_+p*.5}}),ee("mover")&&c.push({id:"movers",weight:1.5,make:p=>{let k=1+(s.chance(m.density)?1:0),_=new Set;for(let z=0;z<k;z++){let B=s.int(0,n-1);_.has(B)&&(B=(B+1)%n),_.add(B),$e("mover",B,z*p*1.6,{size:f*.6});}let C=Re().filter(z=>!_.has(z));return C.length>0&&Se(s.pick(C),0,4),k*p*1.6}}),ee("rock")&&c.push({id:"rocks",weight:1.5,make:p=>{let k=2+(s.chance(m.density)?1:0);for(let _=0;_<k;_++){let C=s.int(0,n-1);$e("rock",C,_*p*1.2,{size:f*.9});let z=Re().filter(B=>B!==C);Se(s.pick(z),_*p*1.2,2);}return k*p*1.2}}),c},De=u=>{let f=Vt(e,n),b=Math.floor(n/2),c=m.fresh;if(c===null||c==="wall")return 0;if(c==="barrier"||c==="pit"){for(let p=0;p<3;p++)$e(c,b,p*u*1.6,c==="pit"?{size:f.laneH*1.25}:{}),Se(b,p*u*1.6-f.laneH*.75,3,f.laneH*1.3);return 3*u*1.6}return c==="train"?($e("ramp",b,0,{size:f.laneH*1.4}),$e("train",b,f.laneH*1.4+f.laneH*3-f.laneH*.42,{size:f.laneH*6}),Se(b,f.laneH*1.8,7,f.laneH*(It.train+.5)),f.laneH*8+u):($e(c,b,0,{size:c==="mover"?f.laneH*.6:f.laneH*.9}),u*1.5)},Qt=()=>{let u=Math.max(Vt(e,n).laneH*2.1,300-m.density*110),f;if(!ce&&m.fresh!==null&&m.fresh!=="wall")ce=true,f=De(u);else {let b=ht();f=(O>0&&O%4===3?b.find(p=>p.id==="rest"):s.weighted(b,p=>p.weight)).make(u);}O++,D=Number(e.vars.distance??0)+f+u*1.2;},Xe=(u,f,b)=>{let c=u.laneH*1.05;return {x:u.playerX,y:oo(u,f)-b-c/2,h:c}},et=()=>{let u=Vt(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,le,{shape:"actor",cast:oe().cast,h:0,pose:"idle",depth:10}));let f=e.need(a,Xr);f.size=u.laneH*.5;let b=Xe(u,f.lane,f.alt);e.set(a,F,{x:b.x,y:b.y});let c=e.need(a,le);c.shape==="actor"&&(c.cast=oe().cast,c.h=b.h,c.depth=10+f.lane);},it=()=>{for(let f of e.query(_t))e.destroy(f);Ze(),m=i(to(Jo(e,"meta:chapter")||1,o("difficulty"))),v=Math.round(m.length*o("lengthScale")),Pe=o("lives")+(oe().perk==="heart"?1:0),e.vars.distance=0,e.vars.meters=0,e.vars.level_length=v,e.vars.runner_length_scale=o("lengthScale"),e.vars.runner_level=m.level,e.vars.speed=m.speed,e.vars.lives=Pe,e.vars.coins=0,e.vars.score=0,e.vars.mult=1,e.vars.stars=0,e.vars.reviving=false,x=0,D=Vt(e,n).laneH*2,O=0,N=false,q=false,ne=false,Z=0,ye=0,be=0,fe=0,Ee=0,de=0,Ae=0,we=0,ce=false,ke=null,Le.clear();let u=Jo(e,"meta:head_start");if(u>0&&Le.set("dash",u),a!==null&&e.isAlive(a)){let f=e.need(a,Xr);f.lane=Math.floor(n/2),f.alt=0,f.vy=0;}et();},dt=u=>{if(!ot(e)||Ke()||a===null)return;let f=e.need(a,Xr),b=Math.min(n-1,Math.max(0,f.lane+u));b!==f.lane&&(Lt(e,"runner-lanes"),ke=f.lane),f.lane=b;},mt=()=>{let u=Vt(e,n),f=o("jumpTime");return 8*u.laneH*It.jump/(f*f)},yt=(u,f,b)=>{let c=Vt(u,n),p=c.playerX,k=c.laneH*.22,_=0;for(let C of u.query(_t)){let z=u.need(C,_t);if(z.lane!==f||z.kind!=="train"&&z.kind!=="ramp")continue;let B=u.need(C,F),ae=B.x-z.size/2,pe=B.x+z.size/2;if(p+k<ae||p-k>pe)continue;let Me=c.laneH*It.train;if(z.kind==="ramp")_=Math.max(_,Me*Math.max(0,Math.min(1,(p-ae)/z.size)));else if(b>=Me-c.laneH*.12)_=Math.max(_,Me);else return null}return _},gt=()=>{if(!ot(e)||Ke()||a===null||Le.has("flight"))return;let u=e.need(a,Xr),f=yt(e,u.lane,u.alt)??0;u.alt-f>2||(u.vy=mt()*o("jumpTime")/2,Ae++,Lt(e,"runner-jump"),Ht(e),e.emit("jumped",{}),Ge(e,a,"jump"));},ft=()=>{if(vt(e,"runner-lanes")||a===null)return;let u=Vt(e,n),f=u.playerX+u.laneH*1.6,b=oo(u,Math.floor(n/2))-u.laneH*.4;kt(e,"swipe",{x:f,y:b+u.laneH*.5},{x:f,y:b-u.laneH*.9},u.laneH);},ze=(u,f,b,c)=>{let p=_e.get(u);(p===void 0||!e.isAlive(p))&&(p=e.create(),e.set(p,md,{id:u}),_e.set(u,p)),e.set(p,F,{x:f,y:b}),e.set(p,le,c);},Et=u=>{let f=_e.get(u);f!==void 0&&e.destroy(f),_e.delete(u);};function Ze(){for(let u of _e.values())e.destroy(u);_e.clear(),ct(e,md);}let Wt=(u,f,b,c,p,k,_,C=41)=>{let z=Math.max(0,Math.min(1,Math.round(k*100)/100));ze(`${u}:bg`,f,b,{shape:"rect",w:c,h:p,color:"#000000",alpha:.45,radius:p/2,depth:C});let B=Math.max(0,(c-4)*z);B<1?Et(`${u}:fill`):ze(`${u}:fill`,f-(c-4)/2+B/2,b,{shape:"rect",w:B,h:p-4,color:_,radius:(p-4)/2,depth:C+.01});},hr=u=>{let f=Vt(u,n),b=Math.min(f.viewW,f.viewH),c=f.viewH*.085,p=f.viewW*.66,k=Math.max(10,b*.026),_=Number(u.vars.distance??0)/Math.max(1,v);Wt("way",f.viewW/2,c,p,k,_,"accent");let C=b*.055;ze("flag",f.viewW/2+p/2+C*.45,c-C*.25,{shape:"sprite",art:"flag",w:C,h:C,depth:42}),ze("lvl",f.viewW/2-p/2-b*.05,c,{shape:"text",text:`${m.level}`,size:Math.round(b*.04),color:"text",bold:true,depth:42});let z=c+b*.07,B=b*.05,ae=Number(u.vars.lives??0);for(let re=0;re<Pe;re++)ze(`h${re}`,f.viewW*.07+re*B*1.1,z,{shape:"sprite",art:"heart",w:B,h:B,alpha:re<ae?1:.25,depth:42});for(let re=Pe;re<10;re++)Et(`h${re}`);let pe=b*.045,Me=String(u.vars.coins??0);ze("coin:i",f.viewW*.93-Me.length*pe*.6-pe*.7,z,{shape:"sprite",art:"coin",w:pe,h:pe,depth:42}),ze("coin",f.viewW*.93-Me.length*pe*.6/2,z,{shape:"text",text:Me,size:Math.round(pe),color:"text",bold:true,depth:42});let qe=Number(u.vars.mult??1);qe>1?ze("mult",f.viewW*.9,z+pe*1.2,{shape:"text",text:`x${qe}`,size:Math.round(pe*1.05),color:"coin",bold:true,depth:42}):Et("mult");let tt=b*.055,pt=0;for(let re of Yo){let j=Le.get(re);if(j===void 0){Et(`p:${re}`),Et(`pb:${re}:bg`),Et(`pb:${re}:fill`);continue}let J=f.viewW*.07+pt*tt*1.25,Y=z+B*1.25;ze(`p:${re}`,J,Y,{shape:"sprite",art:Rr[re].art,color:Rr[re].color,w:tt,h:tt,depth:42}),Wt(`pb:${re}`,J,Y+tt*.7,tt,Math.max(6,b*.011),j/Math.max(.1,Te(re)),"coin",42),pt++;}},Nt=(u,f)=>{if(!ot(u)||q)return;q=true;let b=f==="cleared",c=b?1+(fe>0&&Ee>=fe*m.coinStar?1:0)+(de===0?1:0):0;u.vars.stars=c,b&&u.vars["meta:first_clear"]===true&&Qe(u,"coins",m.firstClearGold);let p=ro(Number(u.vars.distance??0));u.vars.score=we+p*2+(b?500*c:0),u.vars.reviving=false,u.emit(Ut,{reason:f,stats:{chapter:m.level,seconds:Math.floor(Z),cleared:b,stars:c,coins:Ee,meters:p,jumps:Ae,hits:de}});},ur=u=>{if(u.vars.revive_ready===true&&!ne){u.vars.reviving=true,Ht(u),u.emit(er,{});return}Nt(u,"crashed");},Tt=u=>{if(!Ke())return;ne=true,u.vars.reviving=false,u.vars.lives=Math.max(1,Math.ceil(Pe/2)),x=2.5,Le.set("shield",Math.max(Le.get("shield")??0,3));let f=Vt(u,n);for(let b of u.query(_t)){let c=u.need(b,_t);if(c.kind==="coin"||c.kind==="power"||c.kind==="finish")continue;let p=u.need(b,F);p.x-c.size/2<f.playerX+f.laneH*6&&(K(u,{kind:"burst",x:p.x,y:p.y,color:"coin",n:8,size:f.laneH*.6}),u.destroy(b));}if(a!==null){let b=u.need(a,Xr);b.alt=0,b.vy=0,at(u,a,"run");let c=u.need(a,F);K(u,{kind:"ring",x:c.x,y:c.y,color:"coin",size:f.laneH*4});}K(u,{kind:"flash",color:"coin"});},T=(u,f)=>{if(a===null)return;let b=u.need(f,F),c=Vt(u,n);if(Le.has("dash")){K(u,{kind:"burst",x:b.x,y:b.y,color:"accent",n:14,size:c.laneH*.8}),K(u,{kind:"shake",power:.6}),u.need(f,_t).kind!=="pit"&&u.destroy(f);return}if(x>0)return;if(Le.has("shield")){Le.delete("shield"),x=.8,K(u,{kind:"ring",x:c.playerX,y:u.need(a,F).y,color:"muted",size:c.laneH*2}),u.need(f,_t).kind!=="pit"&&u.destroy(f);return}de++,ye=0,u.vars.mult=1;let p=Number(u.vars.lives??1)-1;u.vars.lives=p,u.emit("player-hit",{lives:p}),K(u,{kind:"burst",x:b.x,y:b.y,color:"danger",n:14,size:c.laneH*.9}),K(u,{kind:"shake",power:1.5}),Ge(u,a,"hit"),u.need(f,_t).kind!=="pit"&&u.destroy(f),x=o("graceTime"),p<=0&&ur(u);},H=(u,f)=>{let b=u.need(f,_t),c=u.need(f,F),p=Vt(u,n);if(b.kind==="power"&&b.power!==void 0){Le.set(b.power,Te(b.power)),u.emit("power-up",{id:b.power}),K(u,{kind:"ring",x:c.x,y:c.y,color:Rr[b.power].color,size:p.laneH*1.6}),u.destroy(f);return}ye++;let k=Math.min(5,1+Math.floor(ye/12));k>Number(u.vars.mult??1)&&K(u,{kind:"pop",x:p.playerX,y:c.y-p.laneH,text:`x${k}`,color:"coin",size:Math.round(p.laneH*.42)}),u.vars.mult=k;let _=(Le.has("double")?2:1)*(1+Jo(u,"meta:greed"));be+=_;let C=Math.floor(be);be-=C,C>0&&Qe(u,"coins",C),Ee++,we+=Math.round(_*o("coinScore")*k),u.emit("coin-collected",{value:_}),K(u,{kind:"burst",x:c.x,y:c.y,color:"coin",n:6,size:b.size*1.3}),u.destroy(f);};e.on(zt,u=>{let f=u;e.vars.started_tick!==e.tick&&(f.type==="swipe"&&(f.dir==="up"||f.dir==="down")?dt(f.dir==="up"?-1:1):f.type==="swipe"&&f.dir==="right"?gt():f.type==="key"&&(f.key==="left"||f.key==="up")?dt(-1):f.type==="key"&&(f.key==="right"||f.key==="down")?dt(1):(f.type==="key"&&f.key==="action"||f.type==="tap")&>());}),e.on(qt,()=>{it(),a!==null&&at(e,a,"run"),ft();}),e.on(Zt,it),e.on(tr,()=>Tt(e)),e.on(rr,()=>{Ke()&&(e.vars.reviving=false,Nt(e,"crashed"));}),e.on(Xt,u=>{a!==null&&e.isAlive(a)&&at(e,a,u.reason==="cleared"?"dance":"die");for(let f of e.query(_t))e.need(f,_t).kind==="mover"&&at(e,f,"idle");Ze();}),e.on(Ft,()=>{Ne(),a!==null&&et();let u=Vt(e,n);for(let f of e.query(_t)){let b=e.need(f,_t),{v:c,h:p}=Ie(u,b.kind,b.lane,b.size,b.power);e.set(f,le,c),e.need(f,F).y=b.kind==="finish"?u.top+u.laneH*n/2:p<0?oo(u,b.lane)+p/2+u.laneH*.08:se(u,b,p);}}),e.addSystem({id:"lane-runner",order:0,run(u,f){if(!ot(u)||a===null||q||Ke())return;let b=Vt(u,n),c=b.laneH;Z+=f;let p=Number(u.vars.distance??0),_=(m.speed+(m.topSpeed-m.speed)*Math.min(1,p/Math.max(1,v)))*(Le.has("dash")?1.6:1);u.vars.speed=Math.round(_);let C=_*f;u.vars.distance=p+C,u.vars.meters=ro(p+C),x>0&&(x=Math.max(0,x-f));for(let[re,j]of [...Le])j-f<=0?(Le.delete(re),re==="flight"&&(x=Math.max(x,.8))):Le.set(re,j-f);Zo(u,C);for(let re of u.query(Fs)){let j=u.need(re,le);j.shape==="tile"&&(j.scrollX=(j.scrollX??0)+C);}let z=v-(p+C);if(!N&&z<=b.viewW-b.playerX+c){N=true;let re=$e("finish",0,0);u.need(re,F).x=b.playerX+z;}else !N&&p>=D&&z>b.viewW&&Qt();let B=u.need(a,Xr),ae=Le.has("flight");if(ae)B.alt+=(c*It.flight-B.alt)*Math.min(1,f*6),B.vy=0,Math.floor((p+C)/(c*.9))!==Math.floor(p/(c*.9))&&$e("coin",B.lane,0,{alt:c*(It.flight+.4)});else {B.vy-=mt()*f,B.alt+=B.vy*f;let re=yt(u,B.lane,B.alt);if(re===null){let j=u.query(_t).find(J=>{let Y=u.need(J,_t);return Y.lane===B.lane&&Y.kind==="train"&&Math.abs(u.need(J,F).x-b.playerX)<Y.size/2+c*.22});if(j!==void 0&&T(u,j),q||Ke())return;B.alt=Math.max(0,B.alt);}else B.alt<=re&&(B.alt=re,B.vy=0);}let pe=u.need(a,F),Me=Xe(b,B.lane,B.alt);pe.y+=(Me.y-pe.y)*Math.min(1,f*14),pe.x=Me.x,ke!==null&&Math.abs(Me.y-pe.y)<c*.15&&(ke=null);let qe=u.need(a,le);qe.shape==="actor"&&(qe.alpha=x>0&&Math.floor(u.time*12)%2===0?.35:1,qe.depth=10+B.lane+.5,qe.speed=_,qe.pose=B.alt>2&&B.vy!==0?"air":"run");let tt=c*.24,pt=Le.has("magnet");for(let re of u.query(_t)){if(!u.isAlive(re)||!u.has(re,_t))continue;let j=u.need(re,_t),J=u.need(re,F);if(J.x-=C,j.kind==="mover"){if(J.x-=_*.35*f,j.to===void 0&&J.x-b.playerX<c*6&&J.x-b.playerX>c*3){let E=[j.lane-1,j.lane+1].filter(l=>l>=0&&l<n);j.to=B.lane!==j.lane&&E.includes(B.lane)?B.lane:s.pick(E),j.warn=.45;}if(j.warn!==void 0&&j.warn>0){j.warn-=f;let E=u.need(re,le);E.alpha=Math.floor(u.time*14)%2===0?.4:1,j.warn<=0&&j.to!==void 0&&(j.lane=j.to,E.alpha=1,E.depth=9+j.lane);}J.y+=(se(b,j,c*1.5)-J.y)*Math.min(1,f*10);}if(j.kind==="rock"&&!j.landed&&J.x-b.playerX<c*2.6&&(j.landed=true,u.set(re,le,{shape:"sprite",art:"rock",w:j.size,h:c*It.rock,depth:9+j.lane}),J.y=oo(b,j.lane)-c*It.rock/2,K(u,{kind:"burst",x:J.x,y:J.y+c*.4,color:"muted",n:10,size:c*.7}),K(u,{kind:"shake",power:.5})),j.kind==="rock"&&!j.landed){let E=u.need(re,le);E.shape==="sprite"&&(E.alpha=.35+.3*Math.abs(Math.sin(u.time*6)));}if(j.kind==="power"&&(J.y=se(b,j,j.size)+Math.sin(u.time*4+J.x*.01)*c*.06),J.x+j.size/2<-c*2){u.destroy(re);continue}if(j.kind==="finish"){if(J.x<=b.playerX){K(u,{kind:"flash",color:"coin"}),Nt(u,"cleared");return}continue}if(j.kind==="coin"&&pt&&J.x>b.playerX-c*.5&&J.x<b.playerX+c*4&&(j.pulled=true),j.kind==="coin"&&j.pulled){J.x+=(b.playerX-J.x)*Math.min(1,f*10),J.y+=(pe.y-J.y)*Math.min(1,f*10),Math.hypot(J.x-b.playerX,J.y-pe.y)<c*.4&&H(u,re);continue}if(j.kind==="coin"||j.kind==="power"){if(j.lane!==B.lane&&j.lane!==ke)continue;let E=tt+j.size/2+c*.06;if(J.x-E>b.playerX||J.x+C+E<b.playerX)continue;let l=j.size/2+c*.08;(ae||J.y+l>pe.y-Me.h/2&&J.y-l<pe.y+Me.h/2)&&H(u,re);continue}let Y=j.kind==="barrier"?j.size*.3:j.size/2;if(Math.abs(J.x-b.playerX)>tt+Y||j.lane!==B.lane||ae||j.kind==="ramp"||j.kind==="train"||j.kind==="rock"&&!j.landed)continue;let M=j.kind==="wall"?It.wall:j.kind==="barrier"?It.barrier*.85:j.kind==="mover"?It.mover:j.kind==="rock"?It.rock:0;if(j.kind==="pit"?B.alt<2&&Math.abs(J.x-b.playerX)<j.size*.32&&T(u,re):B.alt<c*M&&T(u,re),q||Ke())return}vt(u,"runner-jump")||u.query(_t).find(j=>{let J=u.need(j,_t),Y=u.need(j,F).x-b.playerX;return (J.kind==="barrier"||J.kind==="pit")&&J.lane===B.lane&&Y>c*1.5&&Y<c*3.2})!==void 0&&!_r(u)&&kt(u,"tap",{x:b.playerX+c*1.2,y:pe.y}),u.vars.score=we+ro(p+C)*2,hr(u);}}),Ne(),it();}};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}:{}}),nr=(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)]),nr("plain",3,"goblin"),$t("ice-mid",22,5,[Rt("ice")]),$t("ring",20,5,[xr(0,20),xr(4,20)]),nr("plain",3,"goblin","wolf"),$t("stones",22,5,[Rt("stone"),xr(1,15)]),$t("ice-low",25,5,[Rt("ice")]),nr("diamond",3,"wolf","orc"),nr("plain",3,"troll"),$t("chains",24,5,[Rt("chain")]),$t("plain",25,5,[es(3)],3),nr("plain",4,"frost-imp","goblin"),$t("cages",22,5,[Rt("cage")]),$t("slime",25,5,[Rt("slime")]),nr("ice-mid",4,"orc","frost-imp"),$t("hourglass",24,5,[es(3),xr(2,20)],3),$t("ice-low",26,5,[Rt("ice")]),nr("plain",4,"spider","frost-imp","wolf"),nr("plain",4,"frost-queen"),$t("ice-stone",26,5,[Rt("ice"),Rt("stone")]),$t("cross-holes",26,6,[xr(0,20),xr(3,20)]),nr("chains",4,"spider","golem"),$t("fortress",28,5,[Rt("ice"),Rt("chain")]),$t("slime-cages",26,5,[Rt("cage"),Rt("slime")]),nr("plain",4,"slime-beast","golem"),$t("diamond",28,5,[es(3)],3),$t("ice-low",28,5,[Rt("ice"),xr(4,20)]),nr("ring",5,"shaman","golem","spider"),nr("plain",5,"spider-queen"),$t("fortress",28,6,[Rt("ice"),Rt("chain")]),$t("slime",28,5,[Rt("slime"),es(3)],3),nr("ice-stone",5,"golem","shaman"),$t("ice-stone",28,6,[Rt("ice"),Rt("stone")]),$t("slime-cages",28,6,[Rt("cage"),Rt("slime")]),nr("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)]),nr("diamond",5,"golem","shaman","spider"),nr("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 h=o[i]??{};return {hole:h.hole===true,piece:null,under:h.under?{...h.under}:null,over:h.over?{...h.over}:null,block:h.block?{...h.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 h=mn(e,o,r-1)?.piece,m=mn(e,o,r-2)?.piece;h&&m&&h.color>=0&&h.color===m.color&&s.add(h.color);let v=e.colors.filter(D=>!s.has(D)),x=ra(e,v.length>0?v:e.colors);n.piece?n.piece.color=x:n.piece=ea(e,x);}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},(h,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},(h,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 h=io(e).size>0;if(o([s,n],[s+a,n+i]),h)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 h=e.cells[r][o].piece,m=e.cells[i.row][i.col].piece;if(h.color===Qr&&m.color===Qr)continue;if(h.special==="rainbow"||m.special==="rainbow")return [a,i];if(h.special&&m.special)return [a,i];let v=t[r][o];t[r][o]=t[i.row][i.col],t[i.row][i.col]=v;let x=io(t).size>0;if(t[i.row][i.col]=t[r][o],t[r][o]=v,x)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 h=tl();return Fh(e,h,r,s,t,a),fl(e,h),h}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 h=0;h<e.rows;h++)for(let m=0;m<e.cols;m++)e.cells[h][m].under?.id===n.id&&s.push({col:m,row:h});if(s.length===0)continue;let a=[];for(let h of s)for(let[m,v]of Ed){let x=mn(e,h.col+m,h.row+v);x&&!x.hole&&!x.block&&!x.under&&a.push({col:h.col+m,row:h.row+v});}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 h=0;h<e.cols;h++){let m=e.cells[i][h];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:h,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 h=Math.floor(e.rnd()*n.length)%n.length,m=n.splice(h,1)[0],v=e.cells[m.row][m.col],x={id:t,hp:o.hp};o.layer==="under"?v.under=x:o.layer==="over"?v.over=x:(v.block=x,v.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 h=new Set(i.cells.map(([x,D])=>`${x},${D}`)),m=n.filter(x=>x.some(D=>D.cells.some(([O,N])=>h.has(`${O},${N}`)))),v=[i,...m.flat()];for(let x of m)n.splice(n.indexOf(x),1);n.push(v);}let s=[],a=[];for(let i of n){let h=new Map;for(let D of i)for(let[O,N]of D.cells)h.set(`${O},${N}`,{col:O,row:N});let m=i.reduce((D,O)=>Math.max(D,O.cells.length),0),v=i.some(D=>D.dir==="h")&&i.some(D=>D.dir==="v"),x=Rn.filter(D=>D.make!==null).find(D=>D.make(m,v,i.find(O=>O.cells.length===m).dir));if(x){let D=t.find(N=>h.has(`${N.col},${N.row}`))??(v?Vh(i):null)??Gh(i.find(N=>N.cells.length===m)),O=e.cells[D.row][D.col].piece?.color??0;a.push({at:D,special:x.id,color:O});}for(let D of h.values())s.push({...D,match:true});}cl(e,o,s);for(let i of a){let h=e.cells[i.at.row][i.at.col];h.piece||h.block||h.hole||(h.piece=ea(e,i.special==="rainbow"?rl:i.color,i.special),o.created.push({...i.at,piece:h.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 h=i.piece;if(h){if(i.over){Js(t,i,"over",s);continue}if(h.color!==Qr){if(i.piece=null,t.cleared.push({...s,piece:h}),i.under&&(i.under.id==="slime"&&(t.slimeCleared=true),Js(t,i,"under",s)),s.match)for(let[m,v]of Ed){let x=mn(e,s.col+m,s.row+v),D=`${s.col+m},${s.row+v}`;x?.block&&!n.has(D)&&Zr[x.block.id]?.hitByNear&&(n.add(D),Js(t,x,"block",{col:s.col+m,row:s.row+v}));}h.special&&Kh(e,t,h.special,s,h.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(h=>h.id===r)?.shape??r;for(let h of dl(e,i,o,n))s.push({...h,match:false});}var ca=(e,t,r)=>dl(e,t,r,-1);function dl(e,t,r,o){let n=[],s=i=>{for(let h=0;h<e.cols;h++)n.push({col:h,row:i});},a=i=>{for(let h=0;h<e.rows;h++)n.push({col:i,row:h});};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 h=-i;h<=i;h++)s(r.row+h),a(r.col+h);}else if(t.startsWith("area:")){let i=Number(t.slice(5));for(let h=-i;h<=i;h++)for(let m=-i;m<=i;m++)n.push({col:r.col+m,row:r.row+h});}else if(t==="color"){let i=o>=0?o:_d(e);for(let h=0;h<e.rows;h++)for(let m=0;m<e.cols;m++)e.cells[h][m].piece?.color===i&&n.push({col:m,row:h});}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",h=s.special??"plain",m=yd.find(x=>x.a===i&&x.b===h||x.a===h&&x.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 v=i==="rainbow"?s:o;if(m?.effect==="color"||m?.effect==="turn"){let x=v.color>=0?v.color:_d(e);for(let D=0;D<e.rows;D++)for(let O=0;O<e.cols;O++){let N=e.cells[D][O].piece;N?.color===x&&(m.effect==="turn"&&v.special&&v.special!=="rainbow"&&(N.special=v.special==="row"||v.special==="col"?e.rnd()<.5?"row":"col":v.special),a.push({col:O,row:D,match:false}));}}else for(let x of dl(e,m?.effect??"cross",n,v.color))a.push({...x,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 v=s;v>=a;v--){let x=e.cells[v][n].piece;x&&i.push(x);}let h=s;for(let v of i)e.cells[h--][n].piece=v;let m=-1;for(;h>=a;h--){let v=a===qh(e,n)&&e.dropsToSpawn>0&&Xh(e)<2&&e.rnd()<.35,x=v?ea(e,Qr):ea(e,ra(e,e.colors));v&&e.dropsToSpawn--,e.cells[h][n].piece=x,t.spawned.push({col:n,row:h,piece:x,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=M=>yr(t,M),o=e.rng.stream("match3"),n=ao(1,r("difficulty")),s=na(Zs.plain,[0,1,2,3,4],()=>o.next(),Gi),a=Qt(),i="idle",h=new Map,m=new Map,v=null,x=null,D=null,O=null,N=0,q=false,ne=0,Z=0,ye=0,be=0,fe=0,Ee=false,de=false,Ae={colors:new Map,drops:0},Pe=Us,we=Us,ce=0,ke=0,Le=false,_e=[],oe=null,Te=0,Ke=0,Ne=0,se=null,Ie=[],$e=new Map,Se=()=>so.find(M=>M.id===e.vars["meta:hero"])??so[0],Ye=()=>Xs(Se().skill),ee=()=>n.def.kind==="battle",Re=()=>e.vars.reviving===true,rt=()=>gd*Math.pow(1.06,n.level-1)*(1+Yr(e,"meta:attack")),ht=()=>1+Yr(e,"meta:skill"),De=()=>Ye().mana;function Qt(){return un(Be(e),s.cols,s.rows,{top:.33,bottom:.96,widthShare:.94})}let Xe=()=>a.cell,et=new Set,it=(M,E,l,w,A=1)=>{et.add(M);let d=$e.get(M);(d===void 0||!e.isAlive(d))&&(d=e.create(),e.set(d,Td,{id:M}),$e.set(M,d)),e.set(d,F,{x:E,y:l,scale:A}),e.set(d,le,w);},dt=M=>{for(let[E,l]of [...$e])E.startsWith(M)&&(e.destroy(l),$e.delete(E));},mt=M=>{let E=Xe();if(M===rl)return {shape:"sprite",art:"m3_rainbow",w:E*.9,h:E*.9,depth:3};if(M===Qr)return {shape:"sprite",art:"m3_crate",w:E*.86,h:E*.86,depth:3};let l=ns(M);return {shape:"sprite",art:l?.art??"gem1",w:E*.88,h:E*.88,color:l?.color??"piece1",depth:3}},yt=(M,E,l,w,A)=>{let d=st(a,E,A),y=e.create();return e.set(y,yn,{id:M,col:E,row:l,kind:w}),e.set(y,F,{x:d.x,y:d.y}),e.set(y,le,mt(w)),h.set(M,y),y},gt=()=>{let M=sl(s);for(let[E,l]of [...h])M.has(E)||(e.destroy(l),h.delete(E));for(let[E,l]of M){let w=h.get(E);w===void 0&&(w=yt(E,l.col,l.row,l.piece.color,l.row-s.rows));let A=e.need(w,yn);A.col=l.col,A.row=l.row,A.kind!==l.piece.color&&(A.kind=l.piece.color,e.set(w,le,mt(l.piece.color)));let d=l.piece.special&&l.piece.special!=="rainbow"?Rn.find(R=>R.id===l.piece.special):void 0,y=m.get(E);d&&y===void 0&&(y=e.create(),e.set(y,Rd,{of:E}),e.set(y,F,{x:0,y:0}),m.set(E,y)),d&&y!==void 0&&e.set(y,le,{shape:"sprite",art:d.art,w:Xe()*.95,h:Xe()*.95,depth:4}),!d&&y!==void 0&&(e.destroy(y),m.delete(E));}for(let[E,l]of [...m])M.has(E)||(e.destroy(l),m.delete(E));ft();},ft=()=>{ct(e,pl);let M=Xe();for(let E=0;E<s.rows;E++)for(let l=0;l<s.cols;l++){let w=s.cells[E][l],A=st(a,l,E),d=(y,R,S,$=1)=>{if(!R)return;let g=Zr[R.id],L=e.create();e.set(L,pl,{key:y}),e.set(L,F,{x:A.x,y:A.y}),e.set(L,le,{shape:"sprite",art:R.hp>=2&&g?.id==="ice"?"m3_ice2":R.hp>=2&&g?.id==="stone"?"m3_stone2":g?.art??"m3_stone",w:M*$,h:M*$,depth:S});};d(`u${l},${E}`,w.under,1.5,.98),d(`o${l},${E}`,w.over,5,.98),d(`b${l},${E}`,w.block,3,.95);}},ze=()=>{ct(e,Ad),Bt(e,"board",a.top+a.cell*s.rows*.35);let M=Xe(),E=st(a,(s.cols-1)/2,(s.rows-1)/2),l=M*.25,w=(A,d,y)=>{let R=e.create();e.set(R,Ad,{i:0}),e.set(R,F,{x:A,y:d}),e.set(R,le,y);};w(E.x,E.y,{shape:"sprite",art:"panel",w:M*s.cols+l*2,h:M*s.rows+l*2,color:"panel",alpha:.9,depth:-10});for(let A=0;A<s.rows;A++)for(let d=0;d<s.cols;d++){if(s.cells[A][d].hole)continue;let y=st(a,d,A);w(y.x,y.y,{shape:"sprite",art:"cell",w:M-2,h:M-2,color:(A+d)%2?"panel":"ground",alpha:.85,depth:-9});}},Et=()=>{let M=Be(e),E=M.h*.12,l=a.top-Xe()*.4,w=Math.max(40,(l-E)*.92);if((se===null||!e.isAlive(se))&&(se=e.create()),e.set(se,F,{x:M.w*.15,y:l-w/2}),e.set(se,le,{shape:"actor",cast:Se().cast,h:w,pose:"idle",facing:1,depth:20}),oe&&e.isAlive(oe.entity)){let A=w*oe.def.size;e.set(oe.entity,F,{x:M.w*.82,y:l-A/2});let d=e.need(oe.entity,le);d.shape==="actor"&&(d.h=A);}},Ze=()=>n.def.kind!=="goal"?[]:n.def.goals.map(M=>({goal:M,left:M.kind==="color"?Math.max(0,M.count-(Ae.colors.get(M.color)??0)):M.kind==="clear"?sa(s,M.obstacle):M.kind==="drops"?Math.max(0,M.count-Ae.drops):Math.max(0,M.value-Number(e.vars.score??0))})),Wt=()=>Ze().every(M=>M.left===0),hr=M=>{let E=Be(e).w*.07;if(M.kind==="color"){let l=ns(M.color);return {shape:"sprite",art:l?.art??"gem1",w:E,h:E,color:l?.color??"piece1",depth:70}}return M.kind==="clear"?{shape:"sprite",art:Zr[M.obstacle]?.art??"m3_stone",w:E,h:E,depth:70}:M.kind==="drops"?{shape:"sprite",art:"m3_crate",w:E,h:E,depth:70}:{shape:"sprite",art:"coin",w:E,h:E,depth:70}},Nt=(M,E,l,w,A,d)=>{let y=Math.max(8,w*.09);it(`${M}:bg`,E,l,{shape:"rect",w,h:y,color:"#000000",alpha:.5,radius:y/2,depth:69});let R=Math.max(1,(w-4)*Math.max(0,Math.min(1,A)));it(`${M}:fill`,E-(w-4)/2+R/2,l,{shape:"rect",w:R,h:y-4,color:d,radius:(y-4)/2,depth:69.1});},ur=()=>{let M=Be(e),E=Math.min(M.w,M.h),l=($,g,L,I,P="text",W=E*.045)=>it($,g,L,{shape:"text",text:I,size:Math.round(W),color:P,bold:true,depth:70}),w=a.top-Xe()*.4,A=M.h*.085;Ie=[],et.clear();let d=M.w*.36,y=(A+w)/2+E*.02,R=E*.07,S=ke>=De();if(Ie.push({id:"skill",x:d,y,r:R*1.15}),S&&it("h:skill:glow",d,y,{shape:"circle",r:R*1.25,color:Le?"coin":"secondary",alpha:.5+.3*Math.sin(e.time*7),depth:68.9}),it("h:skill:bg",d,y,{shape:"circle",r:R,color:"panel",alpha:.95,depth:69}),it("h:skill:i",d,y,{shape:"sprite",art:Ye().art,w:R*1.4,h:R*1.4,alpha:S?1:.45,depth:69.2}),Nt("h:mana",d,y+R*1.45,R*2.2,ke/De(),"secondary"),ee()){let $=M.w*.15;if(Nt("h:hp",$,A,M.w*.24,Pe/we,"accent"),l("h:hp:t",$+M.w*.12+E*.05,A,`${Math.ceil(Pe)}`,"text",E*.034),ce>0&&(it("h:sh:i",$+M.w*.12+E*.05,A+E*.055,{shape:"sprite",art:"m3_shield",w:E*.045,h:E*.045,color:"primary",depth:70}),l("h:sh:t",$+M.w*.12+E*.11,A+E*.055,`${Math.ceil(ce)}`,"primary",E*.03)),oe){let g=M.w*.78;Nt("h:foe",g,A,M.w*.26,oe.hp/oe.max,"danger"),l("h:foe:t",g-M.w*.13-E*.05,A,`${Math.ceil(oe.hp)}`,"text",E*.034);let L=rs[oe.def.element];it("h:foe:el",g+M.w*.13+E*.03,A,{shape:"circle",r:E*.018,color:L.color,depth:70});let I=(A+w)/2;it("h:foe:in:bg",M.w*.62,I,{shape:"circle",r:E*.045,color:oe.in<=1?"danger":"panel",alpha:.95,depth:69}),l("h:foe:in",M.w*.62,I,String(oe.in),"text",E*.045);let P=n.def.kind==="battle"?n.def.enemies.length:0;for(let W=0;W<P;W++)it(`h:q:${W}`,M.w*.8+(W-(P-1)/2)*E*.04,w+E*.005,{shape:"circle",r:E*.012,color:W<Te?"muted":W===Te?"danger":"text",alpha:.9,depth:70});}}else {l("h:moves",M.w*.5,A+E*.01,String(Z),Z<=3?"danger":"text",E*.075);let $=Ze(),g=M.w*.64,L=M.w*.11,I=(A+w)/2+E*.02;$.forEach((P,W)=>{let te=g+W*L;it(`h:g:${W}`,te,I,hr(P.goal)),l(`h:g:${W}:t`,te,I+E*.06,P.left===0?"\u2713":String(P.left),P.left===0?"accent":"text",E*.038);});}e.vars.m3_phase=i,e.vars.m3_buttons=Ie.map($=>`${$.id}@${Math.round($.x)},${Math.round($.y)}`).join(";");for(let[$,g]of [...$e])!$.startsWith("h:")||et.has($)||(e.destroy(g),$e.delete($));},Tt=()=>{oe&&e.isAlive(oe.entity)&&at(e,oe.entity,"die");let M=_e.shift();if(M===void 0){oe=null;return}let E=os(M),l=e.create();e.set(l,F,{x:0,y:0}),e.set(l,le,{shape:"actor",cast:E.cast,variant:E.variant??o.int(0,99),h:50,pose:"idle",facing:-1,depth:20});let w=E.hp*n.enemyHp;oe={def:E,hp:w,max:w,in:E.every,rage:1,entity:l},Et(),E.boss&&(e.emit(Zh,{kind:M}),K(e,{kind:"shake",power:1})),T();},T=()=>{if(e.vars.moves=Z,e.vars.hero_hp=Math.ceil(Pe),e.vars.mana=Math.floor(ke),e.vars.m3_goals=Ze().map(M=>`${M.goal.kind==="color"?`color${M.goal.color}`:M.goal.kind==="clear"?M.goal.obstacle:M.goal.kind}:${M.left}`).join(","),e.vars.m3_enemy=oe?`${oe.def.id}:${Math.ceil(oe.hp)}/${Math.ceil(oe.max)}:${oe.in}`:"",ee()){let M=n.def.kind==="battle"?n.def.enemies.length:1;e.vars.level_progress=Math.min(1,(Te+(oe?1-oe.hp/oe.max:0))/M);}else {let M=n.def;if(M.kind==="goal"){let E=M.goals.map(w=>w.kind==="color"||w.kind==="drops"?w.count:w.kind==="score"?w.value:1),l=Ze();e.vars.level_progress=l.reduce((w,A,d)=>w+(A.goal.kind==="clear"?A.left===0?1:0:1-A.left/E[d]),0)/Math.max(1,l.length);}}},H=()=>{ct(e,yn),ct(e,Rd),ct(e,pl),ct(e,Td),h.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 M=n.def;s=na(Zs[M.board]??Zs.plain,n.colors,()=>o.next(),Gi,M.kind==="goal"?M.drops??0:0),a=Qt(),ze(),i="idle",v=null,x=null,D=null,O=null,N=0,q=false,ne=0,Ae.colors.clear(),Ae.drops=0,Z=M.kind==="goal"?M.moves+Yr(e,"meta:moves"):0,ye=Z,be=0,fe=0,Ee=false,de=false,we=Us*Math.pow(1.06,n.level-1)*(1+Yr(e,"meta:health")),Pe=we,ce=0,ke=0,Le=false,Te=0,Ke=0,Ne=0,_e=M.kind==="battle"?[...M.enemies]:[],e.vars.m3_level=n.level,e.vars.m3_world=n.world,e.vars.m3_kind=M.kind,e.vars.coins=0,e.vars.score=0,e.vars.stars=0,e.vars.reviving=false,gt(),Et(),M.kind==="battle"&&Tt(),T();},u=M=>{if(!M||!oe)return 1;let E=rs[M].beats.includes(oe.def.element),l=M===oe.def.element;return (E?1.5:l?.5:1)*(M===Se().element?1.25:1)},f=(M,E=0)=>{N++,q||=M.slimeCleared,Ae.drops+=M.dropsCollected;let l=E,w=0,A=0,d=Xe();for(let $ of M.cleared){let g=$.piece;g.color>=0&&Ae.colors.set(g.color,(Ae.colors.get(g.color)??0)+1);let L=ns(g.color),I=st(a,$.col,$.row);K(e,{kind:"burst",x:I.x,y:I.y,color:L?.color??"coin",n:6,size:d*.8}),ke=Math.min(De(),ke+kd*(1+Yr(e,"meta:mana"))),!(!ee()||!L)&&(L.role==="attack"?l+=rt()*u(L.element)*(1+.25*(N-1)):L.role==="heal"?w+=bd*Math.pow(1.06,n.level-1)*(1+Yr(e,"meta:health")):L.role==="shield"&&(A+=xd*Math.pow(1.06,n.level-1)*(1+Yr(e,"meta:defense"))));}for(let $ of M.fired){let g=st(a,$.col,$.row);K(e,{kind:"ring",x:g.x,y:g.y,color:"coin",size:d*2.4});}M.fired.length>0&&K(e,{kind:"shake",power:.4+Math.min(1,M.fired.length*.2)});for(let $ of M.created)e.emit("special-made",{kind:$.piece.special});let y=M.cleared.length*r("pieceScore")*N+M.fired.length*30;Qe(e,"score",y),ne+=M.cleared.length;let S=Math.floor(ne/r("coinEvery"))-Math.floor((ne-M.cleared.length)/r("coinEvery"));S>0&&(Qe(e,"coins",S),e.emit("coin-collected",{value:S})),e.emit("pieces-cleared",{count:M.cleared.length,cascade:N}),ee()&&(w>0&&(Pe=Math.min(we,Pe+w),se!==null&&K(e,{kind:"pop",x:e.need(se,F).x,y:e.need(se,F).y-d,text:`+${Math.round(w)}`,color:"accent",size:Math.round(d*.45)})),A>0&&(ce+=A),l>0&&oe&&b(l)),gt(),T();},b=M=>{if(!oe)return;oe.hp-=M,se!==null&&Ge(e,se,"attack"),Ge(e,oe.entity,"hit");let E=e.need(oe.entity,F);K(e,{kind:"pop",x:E.x,y:E.y-Xe(),text:`-${Math.round(M)}`,color:"danger",size:Math.round(Xe()*.5)}),!(oe.hp>0)&&(Te++,e.emit("enemy-defeated",{kind:oe.def.id}),c(),oe.def.boss&&(Ke++,Qe(e,"coins",10),e.emit(Qh,{kind:oe.def.id}),K(e,{kind:"flash",color:"coin"})),Tt());},c=()=>{if(!oe)return;at(e,oe.entity,"die");let M=oe.entity;e.need(M,le).alpha=.6,k(()=>{e.isAlive(M)&&e.destroy(M);});},p=[],k=M=>p.push({t:.9,f:M}),_=()=>{if(il(s,q),q=false,N=0,gt(),n.def.kind==="goal"){if(Wt())return B();if(Z<=0)return pe("out-of-moves")}else {if(!oe)return B();if(oe.in--,oe.in<=0){i="enemy",fe=.45;return}}C();},C=()=>{i="idle",lo(s)===null&&(nl(s),gt(),e.emit("board-shuffled",{})),T();},z=()=>{if(!oe)return C();let M=oe.def,E=n.enemyAttack*M.attack*oe.rage;oe.rage=1,Ge(e,oe.entity,"attack");let l=Math.min(ce,E);if(ce-=l,E=(E-l)*(1-Math.min(.6,Yr(e,"meta:defense"))),E>0){if(Pe-=E,se!==null){Ge(e,se,"hit");let A=e.need(se,F);K(e,{kind:"pop",x:A.x,y:A.y-Xe(),text:`-${Math.round(E)}`,color:"danger",size:Math.round(Xe()*.5)});}K(e,{kind:"shake",power:.8}),e.emit("player-hit",{hp:Math.ceil(Pe)});}let w=M.skill;if(w?.kind==="sow"?ll(s,w.obstacle,w.count):w?.kind==="heal"?oe.hp=Math.min(oe.max,oe.hp+oe.max*w.share):w?.kind==="rage"&&(oe.rage=w.mult),oe.in=M.enrage&&oe.hp<oe.max*M.enrage?Math.max(1,M.every-1):M.every,gt(),Pe<=0)return Pe=0,pe("fell");C();},B=()=>{if(n.def.kind==="goal"){Ne=Math.min(Z,12),e.vars.stars=Math.min(Ee?1:3,Zi(Z/Math.max(1,ye),false)),Qe(e,"score",Z*r("moveBonus")),i="finale",fe=.3;return}e.vars.stars=Math.min(Ee?1:3,Zi(Pe/we,true)),ae("cleared");},ae=M=>{if(de)return;de=true,i="over";let E=M==="cleared";E&&e.vars["meta:first_clear"]===true&&Qe(e,"coins",n.firstClearGold),E||(e.vars.stars=0),e.vars.reviving=false,T(),e.emit(Ut,{reason:M,stats:{chapter:n.level,seconds:Math.floor(be),cleared:E,stars:Number(e.vars.stars??0),coins:Number(e.vars.coins??0),bosses:Ke,kills:Te,battle:ee()}});},pe=M=>{if(e.vars.revive_ready===true&&!Ee){e.vars.reviving=true,e.vars.m3_revive_reason=M,i="idle",e.emit(er,{});return}ae(M);},Me=()=>{Re()&&(Ee=true,e.vars.reviving=false,ee()?(Pe=we*Md,oe&&(oe.in=oe.def.every)):Z+=$d,K(e,{kind:"flash",color:"coin"}),C());},qe=M=>{let E=s.cells[M.row]?.[M.col];if(!E||E.hole)return 0;let l=n.def.kind==="goal"?n.def.goals:[],w=0;for(let d of [E.under,E.over,E.block])d&&(w+=l.some(y=>y.kind==="clear"&&y.obstacle===d.id)?6:3);let A=E.piece;if(A&&!E.block){w+=1,A.special&&(w+=3),l.some(y=>y.kind==="color"&&y.color===A.color)&&(w+=2);let d=ns(A.color);ee()&&d?.role==="attack"&&(w+=u(d.element));}if(l.some(d=>d.kind==="drops"))for(let d=0;d<M.row;d++)s.cells[d][M.col].piece?.color===Qr&&(w+=2);return w},tt=M=>{let E={col:Math.floor(s.cols/2),row:Math.floor(s.rows/2)},l=-1;for(let w=0;w<s.rows;w++)for(let A=0;A<s.cols;A++){if(s.cells[w][A].hole)continue;let d=ca(s,M,{col:A,row:w}).reduce((y,R)=>y+qe(R),0);d>l&&(l=d,E={col:A,row:w});}return E},pt=()=>{let M=Ye();if(ke<M.mana||i!=="idle")return false;let E=ht(),l=[];if(M.kind==="shape"){let d=E>=(M.bigAt??99)&&M.bigShape?M.bigShape:M.shape??"area:1",y=tt(d);l=ca(s,d,y);let R=st(a,y.col,y.row);K(e,{kind:"ring",x:R.x,y:R.y,color:"coin",size:Xe()*4}),K(e,{kind:"flash",color:"coin"});}else l=la(s,"line",Math.round((M.count??3)*E));ke=0,Le=false,N=0,se!==null&&Ge(e,se,"attack"),e.emit("skill-cast",{id:M.id}),Lt(e,"m3-skill");let w=ee()&&oe?M.damage*rt()*E*u(Se().element):0,A=ia(s,l,M.id);return f(A,w),i="falling",true},re=M=>{if(D){let E=s.cells[D.row]?.[D.col]?.piece?.id,l=E!==void 0?h.get(E):void 0;l!==void 0&&(e.need(l,F).scale=1);}if(D=M,M){let E=s.cells[M.row]?.[M.col]?.piece?.id,l=E!==void 0?h.get(E):void 0;l!==void 0&&(e.need(l,F).scale=1.15);}},j=0,J=(M,E)=>{if(j=0,Ht(e),i!=="idle"||Re()||!ss(s,M,E))return;re(null);let l=s.cells[M.row][M.col].piece.id,w=s.cells[E.row][E.col].piece.id;v=new Map([[l,E],[w,M]]),x=[M,E],i="swapping",Lt(e,"match3-swap");};e.on(zt,M=>{let E=M;if(!(!ot(e)||hn(e)||de||Re()))if(E.type==="tap"){if(Ie.find(A=>Math.hypot(E.x-A.x,E.y-A.y)<=A.r)?.id==="skill"){if(ke<De())return;pt()||(Le=true);return}let w=Ur(a,E.x,E.y);if(!w||i!=="idle")return;D&&Math.abs(D.col-w.col)+Math.abs(D.row-w.row)===1?J(D,w):re(D&&D.col===w.col&&D.row===w.row?null:w);}else if(E.type==="press"){let l=Ur(a,E.x,E.y);O=l?{x:E.x,y:E.y,...l}:null;}else if(E.type==="move"&&O){let l=E.x-O.x,w=E.y-O.y;if(Math.max(Math.abs(l),Math.abs(w))<a.cell*.45)return;let A={col:O.col,row:O.row},d=Math.abs(l)>Math.abs(w)?{col:A.col+Math.sign(l),row:A.row}:{col:A.col,row:A.row+Math.sign(w)};O=null,J(A,d);}else E.type==="release"&&(O=null);}),e.on(qt,()=>{H(),e.vars.level=n.level;}),e.on(Zt,H),e.on(tr,Me),e.on(rr,()=>{Re()&&(e.vars.reviving=false,ae(ee()?"fell":"out-of-moves"));}),e.on(Xt,M=>{dt("h:"),Ie=[],se!==null&&e.isAlive(se)&&at(e,se,M.reason==="cleared"?"dance":"die");}),e.on(Ft,()=>{a=Qt(),ze();for(let[M,E]of h){let l=e.need(E,yn);e.set(E,le,mt(l.kind));}gt(),Et();});let Y=M=>{let E=true,l=Math.min(1,M*14),w=Xe();for(let A of e.query(yn)){let d=e.need(A,yn),y=v?.get(d.id)??d,R=e.need(A,F),S=st(a,y.col,y.row),$=S.x-R.x,g=S.y-R.y,L=e.need(A,le);Math.abs($)<.5&&Math.abs(g)<.5?(R.x=S.x,R.y=S.y,L.alpha=1):(E=false,L.alpha=R.y<a.top-w*.3?0:1,R.x+=$*l,R.y+=Math.abs(g)>w*.3?Math.sign(g)*Math.min(Math.abs(g),w*12*M):g*l);}for(let[A,d]of m){let y=h.get(A);if(y===void 0)continue;let R=e.need(y,F);e.set(d,F,{x:R.x,y:R.y,scale:1+.06*Math.sin(e.time*6)}),e.need(d,le).alpha=e.need(y,le).alpha??1;}return E};e.addSystem({id:"match3",order:0,run(M,E){for(let l of [...p])l.t-=E,l.t<=0&&(p.splice(p.indexOf(l),1),l.f());if(!ot(M)||de){Y(E);return}if(be+=E,ur(),!Re()&&Y(E)){if(fe>0){fe-=E;return}if(i==="swapping"&&x){let[l,w]=x;x=null,v=null,N=0;let A=al(s,l,w);if(!A){let d=s.cells[l.row][l.col].piece.id,y=s.cells[w.row][w.col].piece.id;v=new Map([[d,w],[y,l]]),i="returning";return}n.def.kind==="goal"&&Z--,f(A),i="falling";return}if(i==="returning"){if(v){v=null;return}i="idle";return}if(i==="falling"){let l=aa(s);if(l){f(l);return}_();return}if(i==="enemy"){z();return}if(i==="finale"){if(Ne>0){Ne--,Z=Math.max(0,Z-1);let w=la(s,"line",1);w.length>0&&f(ia(s,w,"finale")),gt(),fe=.12;return}let l=aa(s);if(l){f(l);return}ae("cleared");return}if(i==="idle"&&Le){pt();return}if(i==="idle"){if(j+=E,(!vt(M,"match3-swap")||j>7)&&!_r(M)){let l=lo(s);l&&kt(M,"swipe",st(a,l[0].col,l[0].row),st(a,l[1].col,l[1].row),a.cell*1.1);}if(ke>=De()&&!vt(M,"m3-skill")&&!_r(M)){let l=Ie.find(w=>w.id==="skill");l&&kt(M,"tap",l,void 0,a.cell*1.2);}}}}}),H();}};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"}],He=(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}),or=(e,t)=>({...e,extra:t}),ua=[He("start","g",3,3,0,1,1.6),He("start","g",4,3,0,2,1.5),He("two","gb",4,3,0,2,1.45),He("two","gb",5,4,0,2),He("boxes","gb",5,4,0,3),He("boxes","gb",6,4,.2,3),He("fog","gb",6,4,.2,3),He("yard","gb",6,5,.2,3),He("fog","gb",7,5,.3,3),or(fa(He("cellar","gb",6,5,.3,3)),.92),or(He("webs","gbj",5,4,.2,3),.92),or(He("webs","gbj",6,4,.3,3),.92),or(He("mine","gbj",6,5,.2,3),1.15),or(He("workshop","gbj",6,5,.3,3),.9),or(He("mine","gbj",7,5,.3,3),1.08),or(He("yard","gj",6,5,.3,3),1.15),or(He("workshop","gbj",7,5,.4,3),.92),He("vault","gbj",7,5,.3,3),or(He("webs","jbg",7,6,.3,3),.92),fa(He("vault","gbj",7,6,.4,3)),or(He("bubbles","gbp",6,5,.2,3),1.15),or(He("bubbles","gbp",6,5,.3,3),1.12),or(He("holes","gbpj",6,5,.3,3),.92),or(He("lab","gbjp",7,5,.3,3),.92),He("holes","gbpj",7,5,.4,3),He("bubbles","pjg",7,6,.3,3),He("lab","gbjp",7,6,.4,3),He("terrace","gbjp",8,5,.4,3),He("holes","gbpj",8,6,.4,3),fa(He("terrace","gbjp",7,6,.4,3)),He("four","gbjp",7,5,.3,3),or(He("fortress","gbjp",7,5,.4,3),1.06),He("maze","gbjp",7,6,.4,3),He("four","gbjp",8,6,.4,3),or(He("fortress","gbjp",8,6,.5,3),1.06),He("palace","gbjp",8,6,.4,3),He("maze","gbjp",8,6,.5,3),He("lab","gbjp",9,6,.5,3),He("palace","gbjp",9,6,.5,3),or(fa(He("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,h=2+Math.round(a*(e.top-2)),m=Math.max(2,Math.min(e.top,h-(r()<.3?1:0))),v=n[(s+Math.floor(r()*n.length))%n.length],x=[{chain:v,level:i?Math.min(e.top+1,(Cr(v)?.levels??7)-1):m}];if(i||s>0&&n.length>1&&r()<e.double){let D=n[(n.indexOf(v)+1+Math.floor(r()*(n.length-1)))%n.length];x.push({chain:D,level:i?e.top:Math.max(2,m-1)});}o.push({wants:x,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,v)=>m+v.wants.reduce((x,D)=>x+pa(D.level),0),0),i=Math.max(a*.4,a-eu(An[o.board]??[])*.7),h=(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*h),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 h=0;h<o;h++){let m=yl[e[a][h]??"-"]??{kind:"free"},v={hole:m.kind==="hole",thing:null,cover:null,block:null};if(m.kind==="gen"){let x=s(m.chain);x&&(v.thing=$l(n,"gen",x,1));}else if(m.kind==="item"){let x=s(m.chain);x&&(v.thing=is(n,x,m.level));}else if(m.kind==="block")v.block={id:m.obstacle,hp:m.hp};else if(m.kind==="cover"){let x=t[Math.floor(r()*t.length)]??"garden",D=Math.min(en(x)-1,m.levels[Math.floor(r()*m.levels.length)]??1);v.thing=is(n,x,D);let O=gr[m.obstacle];v.cover={id:m.obstacle,hp:1,...O?.ttl?{ttl:O.ttl}:{}};}else m.kind==="special"&&(v.thing=Bd(n,m.special));i.push(v);}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 h of ["block","cover"]){let m=i[h];if(!m)continue;let v=gr[m.id];if(!v?.neighbour)continue;m.hp--;let x=m.hp<=0;x&&(i[h]=null,o+=v.coins??0),r.push({at:a,id:m.id,gone:x,revealed:x&&!!v.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 v=n.cover?.id;n.cover=null;let x=zd(e,r);return {kind:"merge",at:r,level:m.level,...v?{freed:v}:{},hits:x.hits,coins:x.coins}}let a=s.kind==="special"?Jr(s.special):void 0,i=n.thing,h=!n.cover||!!gr[n.cover.id]?.mergeInto;if(a?.effect==="joker"&&i?.kind==="item"&&h&&i.level<en(i.chain)){o.thing=null,i.level++;let m=n.cover?.id;n.cover=null;let v=zd(e,r);return {kind:"joker",at:r,level:i.level,...m?{freed:m}:{},hits:v.hits,coins:v.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,h=is(e,o.chain,Math.min(i,en(o.chain)));return e.cells[n.row][n.col].thing=h,{at:n,thing:h,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 h=e.chains[Math.floor(e.rand()*e.chains.length)]??as[0].id,m=is(e,h,Math.min(en(h),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 h=e.cells[a][i];if(!ka(s.thing,h))continue;let m=(s.thing.kind==="gen"?100:0)+s.thing.level-(h.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(h=>h.thing.kind==="item"&&!h.cell.cover&&h.thing.level<en(h.thing.chain)&&!o.some(m=>m.col===h.at.col&&m.row===h.at.row));if(s.length===0)break;let a=h=>r.some(m=>m.chain===h.thing.chain&&m.level===h.thing.level+1);s.sort((h,m)=>Number(a(m))-Number(a(h))||h.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,h=new Map,m=null,v=[],x=[],D=0,O=0,N=0,q=0,ne=0,Z=0,ye=0,be=0,fe=false,Ee=false,de=null,Ae=[],Pe=()=>fo.find(f=>f.id===e.vars["meta:hero"])??fo[0],we=()=>ha(Pe().skill),ce=()=>e.vars.reviving===true,ke=()=>we().charge,Le=()=>mo(e,"meta:luck"),_e=()=>v.flatMap(f=>f.order.wants);function oe(){return un(Be(e),s.cols,s.rows,{top:.3,bottom:.86,widthShare:.94})}let Te=()=>a.cell,Ke=new Set,Ne=(f,b,c,p,k=1)=>{Ke.add(f);let _=h.get(f);(_===void 0||!e.isAlive(_))&&(_=e.create(),e.set(_,Xd,{id:f}),h.set(f,_)),e.set(_,F,{x:b,y:c,scale:k}),e.set(_,le,p);},se=()=>{for(let[f,b]of [...h])Ke.has(f)||(e.destroy(b),h.delete(f));},Ie=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=Te(),c=f.kind==="gen"?.94:.92;return {shape:"sprite",art:Ie(f),w:b*c,h:b*c,depth:3}},Se=()=>{let f=new Map(Pr(s).map(b=>[b.thing.id,b]));for(let[b,c]of [...i])f.has(b)||(e.destroy(c),i.delete(b));for(let[b,c]of f){let p=i.get(b);if(p===void 0){p=e.create();let C=st(a,c.at.col,c.at.row);e.set(p,F,{x:C.x,y:C.y,scale:.3}),i.set(b,p);}e.set(p,ls,{id:b,col:c.at.col,row:c.at.row});let k=$e(c.thing),_=c.cell.cover&&gr[c.cell.cover.id]?.hides;e.set(p,le,{...k,alpha:_?0:1,depth:m?.id===b?30:3});}Ye(),mt();},Ye=()=>{ct(e,Ll);let f=Te();for(let b=0;b<s.rows;b++)for(let c=0;c<s.cols;c++){let p=s.cells[b][c],k=st(a,c,b);for(let[_,C,z]of [["b",p.block,3],["c",p.cover,5]]){if(!C)continue;let B=gr[C.id],ae=B?.art[Math.min(B.art.length,Math.max(1,C.hp))-1]??"mg_box",pe=e.create();e.set(pe,Ll,{key:`${_}${c},${b}`}),e.set(pe,F,{x:k.x,y:k.y}),e.set(pe,le,{shape:"sprite",art:ae,w:f*.98,h:f*.98,depth:z,alpha:C.id==="bubble"&&(C.ttl??99)<=3?.55+.4*Math.abs(Math.sin(e.time*6)):1});}}},ee=()=>{ct(e,Ud),Bt(e,"board",a.top+a.cell*s.rows*.3);let f=Te(),b=st(a,(s.cols-1)/2,(s.rows-1)/2),c=f*.22,p=(k,_,C)=>{let z=e.create();e.set(z,Ud,{i:0}),e.set(z,F,{x:k,y:_}),e.set(z,le,C);};p(b.x,b.y,{shape:"sprite",art:"panel",w:f*s.cols+c*2,h:f*s.rows+c*2,color:"panel",alpha:.9,depth:-10});for(let k=0;k<s.rows;k++)for(let _=0;_<s.cols;_++){if(s.cells[k][_].hole)continue;let C=st(a,_,k);p(C.x,C.y,{shape:"sprite",art:"cell",w:f-3,h:f-3,color:(k+_)%2?"panel":"ground",alpha:.85,depth:-9});}},Re=()=>Math.max(1,n.def.visible),rt=f=>{let b=Be(e),c=Re(),p=Math.min(b.w*.3,Te()*2.6),k=b.w/2+(f-(c-1)/2)*(p+Te()*.2),_=p*(c>2?.62:.72),C=b.h*.118+_/2,z=a.top-Te()*.18;return {x:k,y:C,w:p,h:_,feet:z}},ht=(f,b,c)=>{let p=rt(f),k=Math.max(24,(p.feet-(p.y+p.h/2))*1.05),_=c?-k:p.x,C=e.create();return e.set(C,F,{x:_,y:p.feet-k/2}),e.set(C,le,{shape:"actor",cast:b.vip?"boss":"helper",variant:b.vip?7:o.int(0,99),h:k,pose:c?"walk":"idle",facing:1,speed:Sl,depth:6}),e.set(C,uo,{slot:f,to:p.x,leaving:-1}),C},De=f=>{for(let b=0;b<Re();b++){if(v.some(p=>p.slot===b))continue;let c=x.shift();c&&v.push({order:c,slot:b,customer:ht(b,c,f)});}},Qt=(f,b)=>{for(let c of f.query(uo)){let p=f.need(c,uo),k=f.need(c,F),_=f.need(c,le);if(_.shape!=="actor")continue;if(p.leaving>=0){p.leaving+=b,p.leaving>.7&&(_.pose="walk",_.facing=1,k.x+=Sl*1.4*b);continue}let C=p.to-k.x;Math.abs(C)>1?(k.x+=Math.sign(C)*Math.min(Math.abs(C),Sl*2*b),_.pose="walk",_.facing=C>0?1:-1):_.pose==="walk"&&(k.x=p.to,_.pose="idle");}},Xe=f=>Math.max(1,Math.round(f.wants.reduce((b,c)=>b+c.level,0)*r("orderReward")*(f.vip?3:1)*(1+mo(e,"meta:reward")))),et=f=>{let b=Dn(s,f.order.wants);if(!b)return false;let c=rt(f.slot);for(let _ of b){let C=st(a,_.col,_.row);K(e,{kind:"burst",x:C.x,y:C.y,color:"coin",n:8,size:Te()*.8}),wl(s,_);}let p=Xe(f.order);Qe(e,"coins",p),Qe(e,"score",p*25),K(e,{kind:"burst",x:c.x,y:c.y,color:"coin",n:14,size:c.w*.8}),K(e,{kind:"pop",x:c.x,y:c.y-c.h*.5,text:`+${p}`,color:"coin",size:Math.round(c.h*.42)}),e.emit("coin-collected",{value:p}),e.emit("order-filled",{reward:p,vip:f.order.vip}),Lt(e,"merge-order"),ne++;let k=e.get(f.customer,uo);return k&&(k.leaving=0,Ge(e,f.customer,"cheer"),_n(e,f.customer,2.4)),v=v.filter(_=>_!==f),De(true),Se(),v.length===0&&x.length===0&>(),true},it=(f,b,c,p,k,_)=>{let C=Math.max(8,p*.11);Ne(`${f}:bg`,b,c,{shape:"rect",w:p,h:C,color:"#000000",alpha:.5,radius:C/2,depth:69});let z=Math.max(1,(p-4)*Math.max(0,Math.min(1,k)));Ne(`${f}:fill`,b-(p-4)/2+z/2,c,{shape:"rect",w:z,h:C-4,color:_,radius:(C-4)/2,depth:69.1});},dt=()=>{let f=Be(e),b=Math.min(f.w,f.h),c=Te(),p=(j,J,Y,M,E="text",l=b*.045,w=70)=>Ne(j,J,Y,{shape:"text",text:M,size:Math.round(l),color:E,bold:true,depth:w});Ae=[],Ke.clear();let k=f.h*.085;Ne("h:en:i",f.w*.1,k,{shape:"sprite",art:"mg_energy",w:b*.07,h:b*.07,depth:70}),p("h:en",f.w*.1+b*.075,k,String(D),D<=3&&N===0?"danger":"text",b*.06),N>0&&p("h:free",f.w*.1+b*.17,k,`+${N}`,"secondary",b*.04);let _=v.length+x.length;Ne("h:ord:i",f.w*.8,k,{shape:"sprite",art:"ticket",w:b*.075,h:b*.05,color:"panel",depth:70}),p("h:ord",f.w*.8+b*.08,k,String(_),"text",b*.05);for(let j of v){let J=rt(j.slot);Dn(s,j.order.wants)!==null&&Ne(`h:t${j.slot}:glow`,J.x,J.y,{shape:"rect",w:J.w*1.08,h:J.h*1.14,color:"accent",alpha:.45+.3*Math.sin(e.time*6),radius:J.h*.2,depth:7.9}),Ne(`h:t${j.slot}`,J.x,J.y,{shape:"sprite",art:"ticket",w:J.w,h:J.h,color:j.order.vip?"coin":"panel",depth:8});let M=j.order.wants.length,E=Math.min(J.h*.58,J.w*.86/M);j.order.wants.forEach((l,w)=>{let A=J.x+(w-(M-1)/2)*E*1.05,d=J.y-J.h*.12,y=Cr(l.chain);Ne(`h:t${j.slot}:${w}`,A,d,{shape:"sprite",art:`${y?.prefix??"item"}${Math.min(l.level,y?.levels??8)}`,w:E,h:E,depth:8.1}),Dn(s,[l])?p(`h:t${j.slot}:${w}:ok`,A+E*.32,d+E*.32,"\u2713","accent",E*.42,8.2):p(`h:t${j.slot}:${w}:lv`,A+E*.34,d+E*.34,String(l.level),"coin",E*.3,8.2);}),Ne(`h:t${j.slot}:c`,J.x-J.w*.1,J.y+J.h*.3,{shape:"sprite",art:"coin",w:J.h*.19,h:J.h*.19,depth:8.1}),p(`h:t${j.slot}:cv`,J.x+J.w*.07,J.y+J.h*.3,String(Xe(j.order)),"coin",J.h*.2,8.1),Ae.push({id:`order${j.slot}`,x:J.x,y:J.y,r:J.w*.5});}let C=_e();for(let j of Pr(s)){if(j.cell.cover&&gr[j.cell.cover.id]?.hides)continue;let J=i.get(j.thing.id);if(J===void 0)continue;let Y=e.need(J,F),M=m?.id===j.thing.id?31:6;if(j.thing.kind==="gen")for(let E=0;E<j.thing.level;E++)Ne(`h:i${j.thing.id}:s${E}`,Y.x+(E-(j.thing.level-1)/2)*c*.2,Y.y+c*.38,{shape:"circle",r:c*.075,color:"coin",depth:M});else j.thing.kind==="item"&&(C.some(E=>E.chain===j.thing.chain&&E.level===j.thing.level)&&(Ne(`h:i${j.thing.id}:ok`,Y.x+c*.3,Y.y-c*.3,{shape:"circle",r:c*.12,color:"accent",depth:M}),p(`h:i${j.thing.id}:okt`,Y.x+c*.3,Y.y-c*.3,"\u2713","#ffffff",c*.18,M+.1)),p(`h:i${j.thing.id}:lv`,Y.x+c*.3,Y.y+c*.3,String(j.thing.level),"coin",c*.22,M));}let z=a.top+c*s.rows+(f.h-(a.top+c*s.rows))*.5,B=Math.min(b*.075,(f.h-(a.top+c*s.rows))*.38),ae=f.w*.3,pe=q>=ke();Ae.push({id:"skill",x:ae,y:z,r:B*1.2}),pe&&Ne("h:skill:glow",ae,z,{shape:"circle",r:B*1.28,color:"secondary",alpha:.5+.3*Math.sin(e.time*7),depth:68.9}),Ne("h:skill:bg",ae,z,{shape:"circle",r:B,color:"panel",alpha:.95,depth:69}),Ne("h:skill:i",ae,z,{shape:"sprite",art:we().art,w:B*1.4,h:B*1.4,alpha:pe?1:.45,depth:69.2}),it("h:charge",ae+B*2.6,z,B*2.4,q/ke(),"secondary");let Me=f.w*.88;Ae.push({id:"bin",x:Me,y:z,r:B*1.1});let qe=m?i.get(m.id):void 0,tt=qe!==void 0?e.need(qe,F):null,pt=tt!==null&&Math.hypot(tt.x-Me,tt.y-z)<B*1.3;Ne("h:bin:bg",Me,z,{shape:"circle",r:B,color:pt?"danger":"panel",alpha:.95,depth:69}),Ne("h:bin",Me,z,{shape:"sprite",art:"mg_bin",w:B*1.3,h:B*1.3,alpha:m?1:.7,depth:69.2}),(de===null||!e.isAlive(de))&&(de=e.create(),e.set(de,le,{shape:"actor",cast:Pe().cast,h:B*2.6,pose:"idle",facing:1,depth:20})),e.set(de,F,{x:f.w*.11,y:z-B*.1});let re=e.need(de,le);re.shape==="actor"&&(re.h=B*2.6),e.vars.mg_buttons=Ae.map(j=>`${j.id}@${Math.round(j.x)},${Math.round(j.y)}`).join(";"),se();},mt=()=>{e.vars.energy=D,e.vars.mg_free=N,e.vars.mg_charge=Math.floor(q),e.vars.orders_left=v.length+x.length,e.vars.mg_orders=v.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;},yt=()=>{ct(e,ls),ct(e,Ll),ct(e,Xd),ct(e,uo),i.clear(),h.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,v=[],x=[...n.orders],D=Math.max(0,n.energy+Math.round(mo(e,"meta:energy"))),O=D,N=0,q=0,ne=0,Z=0,ye=0,be=0,fe=false,Ee=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,De(false),Se();},gt=()=>{Ee||(e.vars.stars=Math.min(fe?1:3,ya(D/Math.max(1,O))),Qe(e,"score",D*r("energyBonus")),K(e,{kind:"flash",color:"coin"}),ft("cleared"));},ft=f=>{if(Ee)return;Ee=true;let b=f==="cleared";b&&e.vars["meta:first_clear"]===true&&Qe(e,"coins",n.firstClearGold),b||(e.vars.stars=0),e.vars.reviving=false,mt(),e.emit(Ut,{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:Z}});},ze=()=>{if(e.vars.revive_ready===true&&!fe){e.vars.reviving=true,e.emit(er,{});return}ft("out-of-energy");},Et=()=>{ce()&&(fe=true,e.vars.reviving=false,D+=ga,El(s,"joker",{col:Math.floor(s.cols/2),row:Math.floor(s.rows/2)}),K(e,{kind:"flash",color:"coin"}),Se());},Ze=()=>{if(D>0||N>0||q>=ke()||v.some(c=>Dn(s,c.order.wants))||Fd(s))return true;let f=[..._e(),...x.flatMap(c=>c.wants)],b=Pr(s);for(let c of b)if(!(!ho(s,c.at)||c.thing.kind!=="item")&&f.some(p=>p.chain===c.thing.chain&&p.level>c.thing.level)&&b.some(p=>ka(c.thing,p.cell)))return true;return false},Wt=f=>{let b=Te(),c=st(a,f.at.col,f.at.row);if(f.kind==="merge"||f.kind==="joker"){let p=s.cells[f.at.row][f.at.col].thing,k=Cr(p.chain)?.color??"coin";K(e,{kind:"ring",x:c.x,y:c.y,color:k,size:b*1.4}),K(e,{kind:"burst",x:c.x,y:c.y,color:"coin",n:8,size:b*.8});let _=i.get(p.id);_!==void 0&&(e.need(_,F).scale=1.35),Z++,q=Math.min(ke(),q+1+mo(e,"meta:charge")),Qe(e,"score",Math.pow(2,p.level)*r("mergeScore")),e.emit("items-merged",{level:p.level,chain:p.chain}),Lt(e,"merge-merge"),p.kind==="item"&&p.level===en(p.chain)&&K(e,{kind:"flash",color:"coin"});for(let C of v)C.order.wants.some(z=>z.chain===p.chain&&z.level===p.level)&&Ge(e,C.customer,"wave");}f.kind==="split"&&K(e,{kind:"ring",x:c.x,y:c.y,color:"secondary",size:b*1.2}),f.freed&&e.emit("obstacle-cleared",{kind:f.freed});for(let p of f.hits){let k=st(a,p.at.col,p.at.row);K(e,{kind:"burst",x:k.x,y:k.y,color:p.id==="fog"?"#ffffff":"ground",n:p.gone?10:4,size:b*.9}),p.gone&&e.emit("obstacle-cleared",{kind:p.id});}f.coins>0&&(Qe(e,"coins",f.coins),e.emit("coin-collected",{value:f.coins}),K(e,{kind:"pop",x:c.x,y:c.y-b*.5,text:`+${f.coins}`,color:"coin",size:Math.round(b*.4)})),f.hits.length&&K(e,{kind:"shake",power:.25});},hr=f=>{if(D<=0&&N<=0){let _=st(a,f.col,f.row);K(e,{kind:"pop",x:_.x,y:_.y-Te()*.5,text:"0",color:"danger",size:Math.round(Te()*.4)});return}let b=Vd(s,f,Le()),c=st(a,f.col,f.row);if(!b){K(e,{kind:"shake",power:.2}),K(e,{kind:"pop",x:c.x,y:c.y-Te()*.5,text:"\u2715",color:"danger",size:Math.round(Te()*.45)});return}N>0?N--:D--,Lt(e,"merge-generate");let p=i.get(s.cells[f.row][f.col].thing.id);p!==void 0&&(e.need(p,F).scale=1.2),K(e,{kind:"burst",x:c.x,y:c.y,color:Cr(b.thing.chain)?.color??"accent",n:6,size:Te()*.7}),e.emit("item-spawned",{level:b.thing.level,chain:b.thing.chain}),Se();let k=i.get(b.thing.id);k!==void 0&&e.set(k,F,{x:c.x,y:c.y,scale:.4});for(let _ of b.burst){let C=st(a,_.col,_.row);K(e,{kind:"burst",x:C.x,y:C.y,color:"#ffffff",n:10,size:Te()});}},Nt=f=>{let b=Gd(s,f);if(!b)return;let c=st(a,f.col,f.row);K(e,{kind:"ring",x:c.x,y:c.y,color:"coin",size:Te()*1.6}),b.energy>0&&(D+=b.energy,K(e,{kind:"pop",x:c.x,y:c.y-Te()*.5,text:`+${b.energy}`,color:"coin",size:Math.round(Te()*.45)})),Se();for(let p of b.spawned){let k=i.get(p.thing.id);k!==void 0&&e.set(k,F,{x:c.x,y:c.y,scale:.4});}},ur=()=>{let f=we();if(q<f.charge)return false;let b=1+mo(e,"meta:skill"),c=Math.max(1,Math.round(f.count*b));if(q=0,de!==null&&Ge(e,de,"cheer"),K(e,{kind:"flash",color:"secondary"}),f.effect==="upgrade")for(let p of qd(s,c,[..._e(),...x.slice(0,2).flatMap(k=>k.wants)])){let k=st(a,p.col,p.row);K(e,{kind:"ring",x:k.x,y:k.y,color:"secondary",size:Te()*1.4});}else if(f.effect==="free")N+=c;else for(let p=0;p<c;p++)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"),Se(),true},Tt=(f,b)=>Ae.find(c=>Math.hypot(f-c.x,b-c.y)<=c.r);e.on(zt,f=>{let b=f;if(!(!ot(e)||hn(e)||Ee||ce())){if(b.type==="press"){Ht(e),be=0;let c=Ur(a,b.x,b.y);if(!c||!ho(s,c))return;let p=s.cells[c.row][c.col].thing.id,k=i.get(p);if(k===void 0)return;let _=e.need(k,F);m={id:p,from:c,dx:_.x-b.x,dy:_.y-b.y,x0:b.x,y0:b.y},e.need(k,le).depth=30;}else if(b.type==="move"&&m){let c=i.get(m.id);if(c===void 0)return;let p=e.need(c,F);p.x=b.x+m.dx,p.y=b.y+m.dy,p.scale=1.12;}else if(b.type==="release"&&m){let c=m;m=null;let p=i.get(c.id);if(p!==void 0&&(e.need(p,le).depth=3),Math.hypot(b.x-c.x0,b.y-c.y0)<Te()*.3)return;let k=Tt(b.x,b.y),_=s.cells[c.from.row][c.from.col].thing;if(k?.id==="bin"&&_&&_.kind!=="gen"){wl(s,c.from),Lt(e,"merge-bin"),Se();return}let C=k?.id.startsWith("order")?v.find(ae=>`order${ae.slot}`===k.id):void 0;if(C&&_?.kind==="item"&&C.order.wants.some(ae=>ae.chain===_.chain&&ae.level===_.level)&&et(C))return;let z=Ur(a,b.x,b.y);if(!z)return;let B=jd(s,c.from,z);B.kind!=="none"&&Wt(B),Se();}else if(b.type==="tap"){be=0;let c=Tt(b.x,b.y);if(c?.id==="skill"){ur();return}if(c?.id.startsWith("order")){let _=v.find(C=>`order${C.slot}`===c.id);_&&et(_);return}let p=Ur(a,b.x,b.y),k=p?s.cells[p.row][p.col].thing:null;if(!p||!k||!ho(s,p))return;if(k.kind==="gen")hr(p);else if(k.kind==="special")Nt(p);else {let _=v.find(C=>C.order.wants.some(z=>z.chain===k.chain&&z.level===k.level)&&Dn(s,C.order.wants));_&&et(_);}}}}),e.on(qt,()=>{yt(),e.vars.level=n.level;}),e.on(Zt,yt),e.on(tr,Et),e.on(rr,()=>{ce()&&(e.vars.reviving=false,ft("out-of-energy"));}),e.on(Xt,f=>{Ke.clear(),se(),Ae=[],de!==null&&e.isAlive(de)&&at(e,de,f.reason==="cleared"?"dance":"idle");}),e.on(Ft,()=>{a=oe(),ee();for(let f of v){let b=rt(f.slot),c=e.get(f.customer,uo);c&&(c.to=b.x);let p=e.get(f.customer,F),k=Math.max(24,(b.feet-(b.y+b.h/2))*1.05);p&&e.set(f.customer,F,{x:b.x,y:b.feet-k/2});let _=e.get(f.customer,le);_?.shape==="actor"&&(_.h=k);}Se();});let T=f=>{let b=Math.min(1,f*16);for(let[c,p]of i){if(m?.id===c)continue;let k=e.get(p,ls);if(!k)continue;let _=e.need(p,F),C=st(a,k.col,k.row);_.x+=(C.x-_.x)*b,_.y+=(C.y-_.y)*b;let z=_.scale??1;_.scale=z+(1-z)*Math.min(1,f*10);}},H=f=>{let b=v.find(p=>Dn(s,p.order.wants));if(b&&(!vt(f,"merge-order")||be>6)){let p=rt(b.slot);return kt(f,"tap",{x:p.x,y:p.y},void 0,Te()*1.1)}let c=Kd(s,{gens:false});if(c&&(!vt(f,"merge-merge")||be>6))return kt(f,"swipe",st(a,c[0].col,c[0].row),st(a,c[1].col,c[1].row),Te()*1.1);if(q>=ke()&&!vt(f,"merge-skill")){let p=Ae.find(k=>k.id==="skill");if(p)return kt(f,"tap",p,void 0,Te()*1.1)}if(!vt(f,"merge-generate")||be>6){let p=Pr(s).find(k=>k.thing.kind==="gen"&&!k.cell.cover);p&&(D>0||N>0)&&kt(f,"tap",st(a,p.at.col,p.at.row),void 0,Te()*1.1);}},u=0;e.addSystem({id:"merge",order:0,run(f,b){Qt(f,b),T(b),!(!ot(f)||Ee)&&(ye+=b,be+=b,dt(),++u%20===0&&s.cells.some(c=>c.some(p=>p.cover?.ttl!==void 0&&p.cover.ttl<=3))&&Ye(),!(ce()||m)&&(_r(f)||H(f),Ze()||ze()));}}),yt();}};var Gt=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(h=>$a[h]<=r),i=Object.keys($a).find(h=>$a[h]===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",sr=ve("platformer.body"),ut=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=T=>yr(t,T),o=Jn(e),n=yo(1,r("difficulty")),s=[],a=0,i=null,h=0,m={x:2,y:8},v=3,x=3,D=0,O=false,N=false,q=0,ne=0,Z=0,ye=false,be=false,fe=[],Ee=[false,false,false],de=new Map,Ae=new Map,Pe=()=>go.find(T=>T.id===e.vars["meta:hero"])??go[0],we=()=>e.vars.reviving===true,ce=()=>{let T=Number(e.vars.view_w??720),H=Number(e.vars.view_h??1280);return Math.min(T/8,H*.66/10)},ke=()=>Number(e.vars.view_h??1280)*.86-10*ce(),Le=()=>Number(e.vars.view_w??720)/ce(),_e=(T,H)=>{if(H<0)return ".";if(T<0||T>=a)return "#";if(H>=10)return ".";let u=s[H]?.[T]??".";return u==="_"&&(de.get(`${T},${H}`)??0)>.5?".":u},oe=T=>T==="#",Te=T=>T==="="||T==="_"||T==="^",Ke=()=>{for(let C of e.query(ut))e.destroy(C);for(let C of e.query(cs))e.destroy(C);de.clear(),n=yo(gn(e,"meta:chapter")||1,r("difficulty"));let T=e.rng.stream(`platformer-level-${n.level}`),H=Ma.filter(C=>C.needs.every(z=>n.features.includes(z))),u=[],f=n.fresh!==null?H.find(C=>C.needs.includes(n.fresh)):void 0;for(f&&u.push(f);u.length<n.rooms;)u.push(T.pick(H));let b=Math.ceil(u.length/2),c=[Qd,...u.slice(0,b),Yd,...u.slice(b),n.boss?ef:Jd];s=Array.from({length:10},(C,z)=>c.map(B=>B.rows[z]??"").join("")),a=s[0].length;let p=[];for(let C=0;C<10;C++)for(let z=0;z<a;z++)s[C][z]==="*"&&p.push({c:z,r:C});let k=p.length<=3?p:[p[0],p[Math.floor(p.length/2)],p[p.length-1]];for(let C=k.length;C<3;C++)k.push({c:Math.floor(a*(C+1)/4),r:5});let _=0;for(let C=0;C<10;C++)for(let z=0;z<a;z++){let B=s[C][z],ae={x:z+.5,y:C+1};B==="P"?m={...ae}:B==="o"?Ie("coin",ae.x,C+.85,.5,.5):B==="H"&&_++<1?Ie("heart",ae.x,C+.9,.6,.6):B==="K"?Ie("key",ae.x,C+.9,.6,.6):B==="B"?Ie("chest",ae.x,ae.y,1,.8):B==="T"?Ie("spring",ae.x,ae.y,1,.5):B==="M"?Ie("mover",ae.x+.5,C+.4,2,.4).baseX=ae.x+.5:B==="C"?Ie("checkpoint",ae.x,ae.y,.6,1.6):B==="E"?Ie("flag",ae.x,ae.y,.8,2.6):B==="W"?Ie("walker",ae.x,ae.y,.8,1):B==="S"?Ie("spiky",ae.x,ae.y,.8,1):B==="J"?Ie("hopper",ae.x,ae.y,.8,1):B==="F"?Ie("flyer",ae.x,ae.y,.9,.8):B==="G"&&Ie("gunner",ae.x,ae.y,.8,1.1),/[PoHKBTMCEWSJFG*]/.test(B)&&(s[C]=Ne(s[C],z,"."));}if(k.forEach((C,z)=>Ie("star",C.c+.5,C.r+.95,.85,.85).tag=String(z)),n.boss){let C=Ie("boss",a-5,8,2.2,2.4);C.hp=n.bossHp,C.tag="walk",C.t=2;}$e();},Ne=(T,H,u)=>T.slice(0,H)+u+T.slice(H+1),se=(T,H,u,f)=>{switch(T){case "walker":return {shape:"actor",cast:"foe",h:u*f*1.35,pose:"walk",depth:8};case "spiky":return {shape:"actor",cast:"foe2",h:u*f*1.4,pose:"walk",depth:8};case "hopper":return {shape:"actor",cast:"foe3",h:u*f*1.35,pose:"idle",depth:8};case "flyer":return {shape:"actor",cast:"foe5",h:u*f*1.4,pose:"air",depth:8};case "gunner":return {shape:"actor",cast:"foe4",h:u*f*1.3,pose:"idle",depth:8};case "boss":return {shape:"actor",cast:"boss",h:u*f*1.2,pose:"walk",depth:8};case "bullet":return {shape:"sprite",art:"shot",color:"danger",w:H*f,h:u*f,depth:9};case "wave":return {shape:"sprite",art:"burst",color:"danger",w:H*f,h:u*f,depth:9};case "coin":return {shape:"sprite",art:"coin",w:H*f,h:u*f,depth:7};case "star":return {shape:"sprite",art:"bigstar",w:H*f,h:u*f,depth:7};case "heart":return {shape:"sprite",art:"heart",w:H*f,h:u*f,depth:7};case "key":return {shape:"sprite",art:"key",w:H*f,h:u*f,depth:7};case "chest":return {shape:"sprite",art:"chest",w:H*f,h:u*f*1.1,depth:6};case "spring":return {shape:"sprite",art:"spring",w:H*f,h:u*f*1.4,depth:6};case "mover":return {shape:"tile",art:"platform",w:H*f,h:u*f,unit:f,depth:5};case "checkpoint":return {shape:"sprite",art:"flag",color:"muted",w:H*f*1.6,h:u*f,depth:5};case "flag":return {shape:"sprite",art:"flag",w:H*f*1.4,h:u*f,depth:5}}};function Ie(T,H,u,f,b){let c=e.create(),p={kind:T,vx:0,vy:0,dir:-1,t:0,baseX:H,baseY:u,hp:1,tag:"",safe:0};return e.set(c,ut,p),e.set(c,sr,{x:H,y:u,w:f,h:b}),e.set(c,F,{x:0,y:0}),e.set(c,le,se(T,f,b,ce())),e.need(c,ut)}function $e(){for(let H of e.query(cs))e.destroy(H);let T=(Number(e.vars.view_h??1280)-(ke()+10*ce()))/ce()+.5;for(let H=0;H<10;H++){let u=0;for(;u<a;){let f=s[H][u];if(f==="."||f==="_"){f==="_"&&Se("_",u,H,1,.45),u++;continue}let b=f==="#"&&_e(u,H-1)!=="#",c=u;for(;c<a&&s[H][c]===f&&(f!=="#"||_e(c,H-1)!=="#"===b);)c++;if(f==="#"&&b){let p=0;for(;H+p<10&&s[H+p][u]==="#";)p++;Se("#",u,H,c-u,p+(H+p>=10?T:0));}else f!=="#"&&Se(f,u,H,c-u,f==="="?.45:.7);u=c;}}}function Se(T,H,u,f,b){let c=ce(),p=e.create();e.set(p,cs,{char:T}),e.set(p,sr,{x:H+f/2,y:T==="^"?u+1:u+b,w:f,h:b}),e.set(p,F,{x:0,y:0});let k=T==="^"?{shape:"tile",art:"spike",w:f*c,h:b*c,unit:c,depth:4}:T==="#"?{shape:"tile",art:"ground",w:f*c,h:b*c,unit:c*1.2,depth:3}:{shape:"tile",art:"platform",w:f*c,h:b*c,unit:c,depth:3,...T==="_"?{color:"muted",alpha:.85}:{}};e.set(p,le,k),T==="_"&&e.set(p,ut,{kind:"mover",vx:0,vy:0,dir:0,t:0,baseX:H,baseY:u,hp:0,tag:"crumble",safe:0});}let Ye=()=>{(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,sr,{x:m.x,y:m.y,w:cu,h:nf}),e.set(i,F,{x:0,y:0})),e.set(i,le,{shape:"actor",cast:Pe().cast,h:nf*ce()*1.25,pose:"idle",depth:10});},ee=()=>Math.sqrt(2*Cn*iu*(1+gn(e,"meta:jump"))*(Pe().perk==="jump"?1.15:1)),Re=()=>{if(i===null)return;let T=e.need(i,sr),H=e.need(i,wr);T.x=m.x,T.y=m.y,H.vx=0,H.vy=0;for(let u of e.query(ut))(e.need(u,ut).kind==="bullet"||e.need(u,ut).kind==="wave")&&e.destroy(u);},rt=()=>{hr(),Ke(),x=r("lives")+gn(e,"meta:hearts")+(Pe().perk==="heart"?1:0),v=x,D=0,O=false,N=false,q=0,ne=0,Z=0,ye=false,be=!n.boss,Ee.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=v,e.vars.coins=0,e.vars.score=0,e.vars.stars=0,e.vars.reviving=false,h=0,Ye(),Re(),i!==null&&(e.need(i,wr).facing=1,at(e,i,"idle")),n.boss&&e.emit(ou,{}),Et(e);},ht=()=>{!ot(e)||we()||i===null||(e.need(i,wr).buffer=.13);},De=()=>{if(i===null)return;let T=e.need(i,wr);T.vy<0&&(T.vy*=.5);},Qt=()=>{if(!ot(e)||we()||i===null||!fe.includes("dash"))return;let T=e.need(i,wr);T.dashCd>0||(T.dash=.2,T.dashCd=.8,T.vy=0,Ge(e,i,"attack"));},Xe=()=>{if(!ot(e)||we()||i===null)return;let T=e.need(i,wr);T.swingCd>0||(T.swing=.16,T.swingCd=.32,Ge(e,i,"attack"));};e.on(zt,T=>{let H=T;e.vars.started_tick!==e.tick&&(H.type==="key"&&(H.key==="up"||H.key==="action")?ht():H.type==="key-up"&&(H.key==="up"||H.key==="action")?De():H.type==="key"&&H.key==="down"?Qt():H.type==="tap"?Xe():H.type==="swipe"&&H.dir==="up"&&ht());});let et=(T,H)=>{if(!ot(T)||O)return;O=true;let u=H==="cleared",f=Ee.filter(Boolean).length;T.vars.stars=f,u&&T.vars["meta:first_clear"]===true&&Qe(T,"coins",n.firstClearGold),T.vars.score=Z*r("coinScore")+f*r("starScore")+(u?r("clearBonus"):0),T.vars.reviving=false,u&&T.emit(Cl,{level:n.level}),T.emit(Ut,{reason:H,stats:{chapter:n.level,seconds:Math.floor(q),cleared:u,stars:u?f:0,coins:Z,bosses:n.boss&&be?1:0}});},it=T=>{if(T.vars.revive_ready===true&&!N){T.vars.reviving=true,T.emit(er,{});return}et(T,"fell");},dt=T=>{we()&&(N=true,T.vars.reviving=false,v=Math.max(2,Math.ceil(x/2)),T.vars.lives=v,D=2.5,Re(),i!==null&&at(T,i,"idle"),K(T,{kind:"flash",color:"coin"}));},mt=(T,H)=>{if(i===null||D>0||O)return;let u=T.need(i,wr);u.dash>0||(v--,T.vars.lives=v,T.emit("player-hit",{lives:v}),D=r("graceTime")+gn(T,"meta:grace"),u.vy=-ee()*.55,u.vx=(H===null?-u.facing:Math.sign(T.need(i,sr).x-H)||-u.facing)*5,Ge(T,i,"hit"),K(T,{kind:"shake",power:1.2}),K(T,{kind:"flash",color:"danger"}),v<=0&&it(T));},yt=(T,H,u)=>{let f=T.need(H,ut),b=T.need(H,sr),c=ce();K(T,{kind:"burst",x:ft(b.x),y:ze(b.y-b.h/2),color:"danger",n:12,size:c*.9}),T.emit("enemy-defeated",{kind:f.kind,by:u}),Qe(T,"score",50),T.destroy(H);},gt=(T,H)=>{let u=T.need(H,sr);ne+=1+gn(T,"meta:greed");let f=Math.floor(ne);ne-=f,f>0&&Qe(T,"coins",f),Z++,T.emit("coin-collected",{value:1}),K(T,{kind:"burst",x:ft(u.x),y:ze(u.y-u.h/2),color:"coin",n:6,size:ce()*.6}),T.destroy(H);},ft=T=>T*ce()-h*ce(),ze=T=>ke()+T*ce();function Et(T){ce();for(let u of T.query(sr)){let f=T.need(u,sr),b=T.get(u,F);if(!b)continue;b.x=ft(f.x),b.y=ze(f.y-f.h/2);let c=T.get(u,le);if(c&&c.shape==="actor"&&T.has(u,ut)){let p=T.need(u,ut);c.facing=p.dir>=0?1:-1,c.alpha=p.safe>0&&Math.floor(T.time*12)%2===0?.35:1,b.y=ze(f.y)-c.h/2;}if(c&&c.shape==="actor"&&T.has(u,wr)&&(b.y=ze(f.y)-c.h/2),c&&T.has(u,cs)&&T.need(u,cs).char==="_"){let p=de.get(`${Math.floor(f.x)},${Math.round(f.y-f.h)}`)??0;c.alpha=p>.5?0:p>0?.5+.5*Math.abs(Math.sin(T.time*30)):.85;}}}let Ze=(T,H,u,f)=>{let b=Ae.get(T);(b===void 0||!e.isAlive(b))&&(b=e.create(),e.set(b,rf,{id:T}),Ae.set(T,b)),e.set(b,F,{x:H,y:u}),e.set(b,le,f);},Wt=T=>{let H=Ae.get(T);H!==void 0&&e.destroy(H),Ae.delete(T);};function hr(){for(let T of Ae.values())e.destroy(T);Ae.clear(),ct(e,rf);}let Nt=T=>{let H=Number(T.vars.view_w??720),u=Number(T.vars.view_h??1280),f=Math.min(H,u),b=u*.085;Ze("lvl",H*.08,b,{shape:"text",text:`${n.world}-${n.index}`,size:Math.round(f*.042),color:"text",bold:true,depth:42});let c=f*.05;for(let C=0;C<x;C++)Ze(`h${C}`,H*.07+C*c*1.1,b+f*.065,{shape:"sprite",art:"heart",w:c,h:c,alpha:C<v?1:.25,depth:42});for(let C=x;C<12;C++)Wt(`h${C}`);let p=f*.06;for(let C=0;C<3;C++)Ze(`s${C}`,H/2+(C-1)*p*1.15,b,{shape:"sprite",art:"bigstar",w:p,h:p,alpha:Ee[C]?1:.25,depth:42});let k=f*.045,_=String(T.vars.coins??0);if(Ze("coin:i",H*.92-_.length*k*.6-k*.7,b,{shape:"sprite",art:"coin",w:k,h:k,depth:42}),Ze("coin",H*.92-_.length*k*.6/2,b,{shape:"text",text:_,size:Math.round(k),color:"text",bold:true,depth:42}),ye?Ze("key",H*.92-k*.3,b+f*.065,{shape:"sprite",art:"key",w:k,h:k,depth:42}):Wt("key"),n.boss){let C=T.query(ut).find(Me=>T.need(Me,ut).kind==="boss"),z=C!==void 0?T.need(C,ut).hp/n.bossHp:0,B=H*.5,ae=Math.max(10,f*.022);Ze("boss:bg",H/2,b+f*.075,{shape:"rect",w:B,h:ae,color:"#000000",alpha:.45,radius:ae/2,depth:41});let pe=Math.max(0,(B-4)*Math.round(z*100)/100);pe<1?Wt("boss:fill"):Ze("boss:fill",H/2-(B-4)/2+pe/2,b+f*.075,{shape:"rect",w:pe,h:ae-4,color:"danger",radius:(ae-4)/2,depth:41.1});}};e.on(qt,()=>{rt(),e.vars.level=n.level;}),e.on(Zt,rt),e.on(tr,()=>dt(e)),e.on(rr,()=>{we()&&(e.vars.reviving=false,et(e,"fell"));}),e.on(Xt,T=>{i!==null&&e.isAlive(i)&&at(e,i,T.reason==="cleared"?"dance":"die"),hr();}),e.on(Ft,()=>{Bt(e,"side",ke()+8*ce()+2);let T=ce();for(let H of e.query(ut)){let u=e.need(H,ut);if(u.tag==="crumble")continue;let f=e.need(H,sr);e.set(H,le,se(u.kind,f.w,f.h,T));}$e(),Ye(),Et(e);}),e.addSystem({id:"platformer",order:0,run(T,H){if(!ot(T)||i===null||O||we())return;q+=H,D>0&&(D=Math.max(0,D-H));let u=T.need(i,sr),f=T.need(i,wr),b=n.pace;for(let[Y,M]of [...de]){let E=M+H;E>3.5?de.delete(Y):de.set(Y,E);}let c=o.axis().x;if(c!==0&&(f.facing=c),f.dash>0)f.dash-=H,f.vx=f.facing*15,f.vy=0;else {let Y=c*au,M=f.grounded?60:32;f.vx+=Math.max(-M*H,Math.min(M*H,Y-f.vx)),f.vy+=Cn*H,f.vy>22&&(f.vy=22);}if(f.dashCd>0&&(f.dashCd-=H),f.swingCd>0&&(f.swingCd-=H),f.swing>0){f.swing-=H;let Y={l:f.facing>0?u.x:u.x-1.4,r:f.facing>0?u.x+1.4:u.x,t:u.y-u.h-.2,b:u.y};for(let M of T.query(ut)){if(!T.isAlive(M)||!T.has(M,ut))continue;let E=T.need(M,ut);if(!["walker","spiky","hopper","flyer","gunner","boss","bullet"].includes(E.kind))continue;let l=T.need(M,sr);l.x+l.w/2<Y.l||l.x-l.w/2>Y.r||l.y-l.h>Y.b||l.y<Y.t||(E.kind==="bullet"?(K(T,{kind:"burst",x:ft(l.x),y:ze(l.y-l.h/2),color:"text",n:6,size:ce()*.5}),T.destroy(M)):E.kind==="boss"?ur(T,M,"sword"):yt(T,M,"sword"));}}if(f.coyote=f.grounded?.1:Math.max(0,f.coyote-H),f.buffer>0){f.buffer-=H;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,K(T,{kind:"ring",x:ft(u.x),y:ze(u.y),color:"text",size:ce()*1.2})),f.buffer===0&&Ge(T,i,"jump");}let p=u.w/2,k=u.x+f.vx*H;f.wall=0;let _=Y=>{let M=[];for(let E=Math.floor(Y-u.h+.05);E<=Math.floor(Y-.05);E++)M.push(E);return M};if(f.vx>0){let Y=Math.floor(k+p);_(u.y).some(M=>oe(_e(Y,M)))&&(k=Y-p-.001,f.grounded||(f.wall=1),f.vx=0);}else if(f.vx<0){let Y=Math.floor(k-p);_(u.y).some(M=>oe(_e(Y,M)))&&(k=Y+1+p+.001,f.grounded||(f.wall=-1),f.vx=0);}f.wall===0&&!f.grounded&&c!==0&&_(u.y).some(Y=>oe(_e(Math.floor(k+c*(p+.05)),Y)))&&(f.wall=c),u.x=Math.max(p,Math.min(a-p,k));let C=u.y,z=u.y+f.vy*H,B=f.grounded;f.grounded=false;let ae=[Math.floor(u.x-p+.05),Math.floor(u.x+p-.05)];if(f.vy>=0){let Y=Math.floor(z);for(let M of ae){let E=_e(M,Y),l=Y;if((oe(E)||Te(E)&&C<=l+.05)&&z>=l){z=l,f.vy=0,f.grounded=true,f.jumps=0,E==="_"&&!de.has(`${M},${Y}`)&&de.set(`${M},${Y}`,.001),E==="^"&&(mt(T,null),f.vy=-ee()*.7,f.grounded=false);break}}}else {let Y=Math.floor(z-u.h);ae.some(M=>oe(_e(M,Y)))&&(z=Y+1+u.h,f.vy=0);}u.y=z,!B&&f.grounded&&Ge(T,i,"jump");for(let Y of T.query(ut)){let M=T.need(Y,ut);if(M.kind!=="mover"||M.tag==="crumble")continue;let E=T.need(Y,sr),l=E.x;M.t+=H,E.x=M.baseX+Math.sin(M.t*.9)*2.2;let w=E.y-E.h;f.vy>=0&&Math.abs(u.x-E.x)<E.w/2+p*.6&&C<=w+.1&&u.y>=w-.05&&(u.y=w,f.vy=0,f.grounded=true,f.jumps=0,u.x+=E.x-l);}if(u.y>12&&(mt(T,null),D=Math.max(D,1),!we()&&!O&&Re(),O||we()))return;let pe={l:u.x-p,r:u.x+p,t:u.y-u.h,b:u.y},Me=Y=>pe.r>Y.x-Y.w/2&&pe.l<Y.x+Y.w/2&&pe.b>Y.y-Y.h&&pe.t<Y.y,qe=1.2*(1+gn(T,"meta:magnet")),tt=u.x;for(let Y of T.query(ut)){if(!T.isAlive(Y)||!T.has(Y,ut))continue;let M=T.need(Y,ut),E=T.need(Y,sr);switch(M.safe>0&&(M.safe-=H),M.kind){case "walker":case "spiky":{M.vx=M.dir*1.6*b;let l=E.x+M.dir*(E.w/2+.05)+M.vx*H,w=oe(_e(Math.floor(l),Math.floor(E.y-.5))),A=_e(Math.floor(l),Math.floor(E.y));w||!(oe(A)||Te(A))?M.dir=-M.dir:E.x+=M.vx*H;break}case "hopper":{M.t+=H,M.vy+=Cn*.6*H,E.y+=M.vy*H,E.y>=M.baseY&&(E.y=M.baseY,M.vy=0,M.t>1.5/b&&(M.t=0,M.vy=-Math.sqrt(2*Cn*.6*2.4))),M.dir=tt<E.x?-1:1;break}case "flyer":M.t+=H*b,E.x=M.baseX+Math.sin(M.t*.9)*3,E.y=M.baseY+Math.sin(M.t*1.8)*.9,M.dir=Math.cos(M.t*.9)>=0?1:-1;break;case "gunner":{if(M.dir=tt<E.x?-1:1,M.t+=H,M.t>2.2/b&&Math.abs(tt-E.x)<9){M.t=0;let l=Ie("bullet",E.x+M.dir*.6,E.y-.45,.45,.3);l.vx=M.dir*6*b,l.dir=M.dir,Ge(T,Y,"attack");}break}case "bullet":case "wave":if(E.x+=M.vx*H,M.t+=H,M.t>(M.kind==="wave"?2.2:3.5)||oe(_e(Math.floor(E.x),Math.floor(E.y-.1)))){T.destroy(Y);continue}break;case "boss":Tt(T,Y,M,E,tt,H);break;case "coin":Math.hypot(E.x-u.x,E.y-(u.y-u.h/2))<qe&&qe>1.21&&(E.x+=(u.x-E.x)*Math.min(1,H*10),E.y+=(u.y-u.h/2-E.y)*Math.min(1,H*10));break;}if(!(!T.isAlive(Y)||!Me(E))){switch(M.kind){case "coin":gt(T,Y);break;case "star":{let l=Number(M.tag);Ee[l]=true,T.vars.stars=Ee.filter(Boolean).length,T.emit("star-collected",{index:l}),K(T,{kind:"ring",x:ft(E.x),y:ze(E.y-E.h/2),color:"coin",size:ce()*2.4}),K(T,{kind:"flash",color:"coin"}),T.destroy(Y);break}case "heart":v=Math.min(x,v+1),T.vars.lives=v,K(T,{kind:"ring",x:ft(E.x),y:ze(E.y-E.h/2),color:"danger",size:ce()*1.6}),T.destroy(Y);break;case "key":ye=true,K(T,{kind:"ring",x:ft(E.x),y:ze(E.y-E.h/2),color:"coin",size:ce()*1.6}),T.destroy(Y);break;case "chest":if(ye&&M.tag!=="open"){M.tag="open",ye=false;for(let w=0;w<15;w++)ne+=1+gn(T,"meta:greed"),Z++;let l=Math.floor(ne);ne-=l,Qe(T,"coins",l),K(T,{kind:"burst",x:ft(E.x),y:ze(E.y-E.h/2),color:"coin",n:24,size:ce()*1.4}),K(T,{kind:"pop",x:ft(E.x),y:ze(E.y-E.h*1.4),text:"+15",color:"coin",size:Math.round(ce()*.5)});}break;case "spring":f.vy>0&&u.y-(E.y-E.h)<.5&&(f.vy=-Math.sqrt(2*Cn*lu),f.jumps=1,K(T,{kind:"ring",x:ft(E.x),y:ze(E.y-E.h),color:"accent",size:ce()*1.4}));break;case "checkpoint":if(M.tag!=="on"){M.tag="on",m={x:E.x,y:E.y};let l=T.need(Y,le);l.shape==="sprite"&&(l.color="accent"),T.emit("checkpoint",{}),K(T,{kind:"ring",x:ft(E.x),y:ze(E.y-E.h/2),color:"accent",size:ce()*2});}break;case "flag":if(be){et(T,"cleared");return}break;case "walker":case "hopper":case "flyer":case "gunner":case "spiky":case "boss":{let l=f.vy>0&&u.y-(E.y-E.h)<.55&&M.kind!=="spiky";f.dash>0&&M.kind!=="boss"?yt(T,Y,"dash"):l?(f.vy=-ee()*.65,f.jumps=1,M.kind==="boss"?ur(T,Y,"stomp"):yt(T,Y,"stomp")):mt(T,E.x);break}case "bullet":case "wave":mt(T,E.x),T.destroy(Y);break;}if(O||we())return}}let pt=Le(),re=Math.max(0,Math.min(Math.max(0,a-pt),u.x-pt*.4+f.facing*pt*.08)),j=h;h+=(re-h)*Math.min(1,H*6),Zo(T,(h-j)*ce()),T.vars.level_progress=Math.min(1,u.x/Math.max(1,a));let J=T.need(i,le);J.shape==="actor"&&(J.facing=f.facing>=0?1:-1,J.pose=f.grounded?Math.abs(f.vx)>.5?"run":"idle":"air",J.speed=Math.abs(f.vx)*ce(),J.alpha=D>0&&Math.floor(T.time*12)%2===0?.35:1),Et(T),Nt(T);}});function ur(T,H,u){let f=T.need(H,ut);f.safe>0||(f.hp--,f.safe=1,Ge(T,H,"hit"),K(T,{kind:"shake",power:1}),f.hp<=0&&(be=true,T.emit(su,{}),yt(T,H,u),Ie("flag",a-2,8,.8,2.6)));}function Tt(T,H,u,f,b,c){if(u.t-=c,u.vy+=Cn*c,f.y=Math.min(u.baseY,f.y+u.vy*c),f.y>=u.baseY){if(u.tag==="slam-air"){u.tag="walk",u.t=1.6,K(T,{kind:"shake",power:1.4});for(let p of [-1,1]){let k=Ie("wave",f.x+p*1.2,u.baseY,.9,.6);k.vx=p*8*n.pace;}}u.vy=0;}if(u.tag==="walk"){if(u.dir=b<f.x?-1:1,f.x+=u.dir*1.4*n.pace*c,u.t<=0){let p=Math.floor(T.rng.next()*3);if(p===0)u.tag="charge",u.t=1.1,u.vx=u.dir*9*n.pace,at(T,H,"run");else if(p===1)u.tag="slam-air",u.vy=-Math.sqrt(2*Cn*4),Ge(T,H,"jump");else {u.tag="walk",u.t=2.4;for(let k of [a-15,a-3])Ie("walker",k,u.baseY,.8,1).dir=k<f.x?1:-1;Ge(T,H,"cheer");}}}else u.tag==="charge"&&(f.x+=u.vx*c,(u.t<=0||oe(_e(Math.floor(f.x+Math.sign(u.vx)*1.2),Math.floor(u.baseY-1))))&&(u.tag="walk",u.t=1.8,at(T,H,"walk")));f.x=Math.max(a-17.5,Math.min(a-1.2,f.x));}Bt(e,"side",ke()+8*ce()+2),rt();}};var fr=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"),We=ve("survivors.foe"),zn=ve("survivors.shot"),nn=ve("survivors.bullet"),ar=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,h=0,m={},v={},x={},D=0,O=0,N=0,q=1,ne=0,Z=0,ye=[],be="level",fe=0,Ee=0,de=0,Ae=false,Pe=0,we=0,ce=300,ke=xo(1,300),Le=false,_e=null,oe=0,Te=0,Ke=0,Ne=0,se=null,Ie=0,$e=0,Se=false,Ye=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},Re=()=>Math.min(Be(e).w,Be(e).h),rt=()=>Re()/720,ht=()=>Re()*.07,De=()=>{let l=Be(e);return {x:l.w/2,y:l.h/2}},Qt=()=>{let l=A=>v[A]??0,w=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")*rt()*(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=Re()*.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>w&&(ee.hp+=ee.maxHp-w),ee.hp=Math.min(ee.hp,ee.maxHp),e.vars.survivors_build=jl({weapons:m,passives:v});},Xe=l=>Math.ceil(s("xpFirst")*Math.pow(l,s("xpGrowth"))),et=()=>ko.find(l=>l.id===e.vars["meta:hero"])??ko[0],it=()=>{let l=De(),w=ht();(a===null||!e.isAlive(a))&&(a=e.create(),e.set(a,Da,{size:w})),e.need(a,Da).size=w,e.set(a,F,{x:l.x,y:l.y}),e.set(a,le,{shape:"actor",cast:et().cast,h:w*2.3,feet:w*.6,pose:"idle",depth:Jt(e,l.y)});},dt=(l,w,A,d)=>{let y=Ye.get(l);(y===void 0||!e.isAlive(y))&&(y=e.create(),e.set(y,cf,{id:l}),Ye.set(l,y)),e.set(y,F,{x:w,y:A}),e.set(y,le,d);},mt=l=>{let w=Ye.get(l);w!==void 0&&e.destroy(w),Ye.delete(l);},yt=()=>{for(let l of Ye.values())e.destroy(l);Ye.clear(),ct(e,cf);},gt=(l,w,A,d,y,R,S,$=41)=>{let g=Math.max(0,Math.min(1,Math.round(R*100)/100));dt(`${l}:bg`,w,A,{shape:"rect",w:d,h:y,color:"#000000",alpha:.45,radius:y/2,depth:$});let L=Math.max(0,(d-4)*g);L<1?mt(`${l}:fill`):dt(`${l}:fill`,w-(d-4)/2+L/2,A,{shape:"rect",w:L,h:y-4,color:S,radius:(y-4)/2,depth:$+.01});},ft=l=>{let w=Be(l),A=Re(),d=w.h*.085,y=w.w*.9,R=Math.max(10,A*.026);gt("xp",w.w/2,d,y,R,N/Xe(q),"accent"),dt("lv",w.w/2+y/2-A*.04,d+R*1.6,{shape:"text",text:`Lv ${q}`,size:Math.round(A*.032),color:"text",bold:true,depth:42});let S=d+A*.075;if(_e!==null&&l.isAlive(_e)&&l.has(_e,We)){let X=l.need(_e,We);gt("boss",w.w/2,S,w.w*.62,Math.max(14,A*.034),X.hp/X.maxHp,"danger"),dt("time",w.w/2,S-A*.05,{shape:"text",text:X.kind==="boss"?"BOSS":"MINI BOSS",size:Math.round(A*.036),color:"danger",bold:true,depth:42}),l.vars.boss_hp=X.hp/X.maxHp;}else mt("boss:bg"),mt("boss:fill"),dt("time",w.w/2,S,{shape:"text",text:Vs(Number(l.vars.time_left??0)),size:Math.round(A*.05),color:"text",bold:true,depth:42}),l.vars.boss_hp=0;let $=Math.round(A*.036);dt("kills:i",w.w*.06,S,{shape:"sprite",art:"skull",w:$*1.1,h:$*1.1,color:"text",depth:42}),dt("kills",w.w*.06+$*.75+String(Ee).length*$*.28,S,{shape:"text",text:String(Ee),size:$,color:"text",bold:true,depth:42});let g=A*.05,L=0,I=new Set,P=(X,me,ue,xe,ge,Ve)=>{I.add(X),dt(`b:${X}`,ge,Ve,{shape:"sprite",art:me,w:g,h:g,color:ue,alpha:.95,depth:41}),dt(`b:${X}:l`,ge+g*.38,Ve+g*.36,{shape:"text",text:xe>=5?"\u2605":String(xe),size:Math.round(g*.42),color:xe>=5?"coin":"text",bold:true,depth:42});};for(let[X,me]of Object.entries(m)){let ue=Ir[X];P(X,ue.art,ue.color,me??1,w.w*.06+L*g*1.12,S+A*.075),L++;}L=0;for(let[X,me]of Object.entries(v)){let ue=bo[X];P(X,ue.art,ue.color,me??1,w.w*.06+L*g*.95,S+A*.075+g*1.1),L++;}for(let X of [...Ye.keys()])if(X.startsWith("b:")){let me=X.slice(2).replace(/:l$/,"");I.has(me)||mt(X);}let W=ht(),te=De();gt("hp",te.x,te.y+W*1.05,W*1.7,Math.max(7,A*.013),ee.hp/ee.maxHp,ee.hp/ee.maxHp>.35?"accent":"danger",40);},ze=(l=-1)=>{let w=Be(e),A=Re()*.08,d=l>=0?l:o.int(0,3);return {x:d===0?-A:d===1?w.w+A:o.range(-A,w.w+A),y:d===2?-A:d===3?w.h+A:o.range(-A,w.h+A)}},Et=()=>s("foeHp")*ke.hp*(1+s("foeHpGrowth")*(we/60)),Ze=(l,w,A=false)=>{let d=tn[l],y=l==="boss"||l==="miniboss",R=Re()*d.size*(A?1.3:1),S=Et()*d.hp*(A?8:1),$=Pt(e,w.x,w.y,{shape:"actor",cast:d.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:Jt(e,w.y)},{type:We,data:{kind:l,hp:S,maxHp:S,speed:d.speed*rt()*s("foeSpeed")*(1+Math.min(.5,we/600)),size:R,damage:d.damage*ke.damage*s("foeDamage")*(A?1.4:1),xp:d.xp*(A?5:1),elite:A,t:o.range(0,1.5),phase:"walk",vx:0,vy:0,hurtAt:{},next:0}});return (A||y)&&Pt(e,w.x,w.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:$}}),$},Wt=()=>{let l=we/60+ke.headStart,w=Sr(r,"foes",of),A=w.filter(S=>tn[S].from<=l),d=A.length>0?A:[w.reduce((S,$)=>tn[S].from<=tn[$].from?S:$)],y=0;for(let S of d)y+=tn[S].weight;let R=o.range(0,y);for(let S of d)if(R-=tn[S].weight,R<=0)return S;return d[0]??"grunt"},hr=()=>e.query(We).length,Nt=(l,w)=>{let A=we/60+ke.headStart,d=s("spawnRate")*(1+s("spawnGrowth")*A);for(Ie>0&&(Ie-=w,d*=.25),Le&&(d*=.45),se&&(se.left-=w,d*=2.6),Pe+=w*d;Pe>=1;)Pe-=1,!(hr()>=s("maxFoes"))&&Ze(Wt(),ze(se?se.side:-1));if(se&&se.left<=0&&(se=null),!Le){if(we>=Ke){Ke=we+o.range(26,36);let y=Ne++%3;if(y===0){let R=De(),S=12+Math.min(12,Math.floor(A*2)),$=Re()*.62;for(let g=0;g<S;g++){let L=g/S*Math.PI*2;Ze(A>3?"grunt":"swarm",{x:R.x+Math.cos(L)*$,y:R.y+Math.sin(L)*$*1.25});}K(l,{kind:"flash",color:"danger"});}else y===1?se={left:4,side:o.int(0,3)}:Ie=5;}if(s("eliteEvery")>0&&we>=Te){Te=we+s("eliteEvery");let y=Wt();Ze(y==="swarm"?"grunt":y,ze(),true);}s("minibossEvery")>0&&we>=oe&&ce-we>30&&(oe=we+s("minibossEvery"),(_e===null||!l.isAlive(_e))&&(_e=Ze("miniboss",ze()),l.emit(Oa,{kind:"miniboss"}),K(l,{kind:"shake",power:1.2})));}},ur=l=>{Le=true,l.vars.time_left=0;let w=De();for(let A of l.query(We)){let d=l.get(A,We);if(!d||d.kind==="miniboss")continue;let y=l.need(A,F);Math.hypot(y.x-w.x,y.y-w.y)<Re()*.3&&T(l,A,null,false);}_e=Ze("boss",{x:w.x,y:w.y-Be(l).h*.42}),K(l,{kind:"shake",power:2}),K(l,{kind:"flash",color:"danger"}),l.emit(Oa,{kind:"boss"});},Tt=(l,w,A,d=1)=>{let y=ht(),R=l==="xp"?{shape:"sprite",art:"crystal",w:y*(d>=25?.62:d>=5?.5:.38),h:y*(d>=25?.62:d>=5?.5:.38),color:d>=25?"secondary":d>=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};Pt(e,w,A,R,{type:ar,data:{kind:l,value:d,pulled:false}});},T=(l,w,A,d=true)=>{let y=l.get(w,We);if(!y)return;let R=l.need(w,F),S=R.x,$=R.y;l.remove(w,We);for(let I of l.query(vo))l.need(I,vo).of===w&&l.destroy(I);at(l,w,"die");let g=l.need(w,le);if(g.shape==="actor"&&(g.depth=Jt(l,$)-.2),_n(l,w,1.4),K(l,{kind:"burst",x:S,y:$,color:"danger",n:y.elite||y.kind==="boss"?22:8,size:y.size*1.4}),!d)return;Ee+=1,l.vars.kills=Ee,l.emit("enemy-defeated",{kind:y.kind,elite:y.elite,by:A});let L=ht();if(y.xp>0&&Tt("xp",S,$+y.size*.4,y.xp),o.chance(Math.min(.95,s("coinRate")*ee.luck))&&Tt("coin",S+L*.3,$+y.size*.4),o.chance(.012*ee.luck)&&Tt("food",S-L*.3,$),o.chance(.004)&&!l.query(ar).some(I=>l.need(I,ar).kind==="magnet")&&Tt("magnet",S,$-L*.3),o.chance(.004)&&Tt("bomb",S,$-L*.3),y.elite||y.kind==="miniboss"){Tt("chest",S,$);for(let I=0;I<3;I++)Tt("coin",S+o.range(-L,L),$+o.range(-L,L));}if(y.kind==="bomber"){let I=Re()*.11*ee.area;K(l,{kind:"ring",x:S,y:$,color:"piece6",size:I*2});for(let P of l.query(We)){let W=l.need(P,F);Math.hypot(W.x-S,W.y-$)<I&&H(l,P,Et()*2.5,"blast");}}if((y.kind==="miniboss"||y.kind==="boss")&&(de+=1,l.vars.bosses=de,w===_e&&(_e=null),l.emit(Wl,{kind:y.kind}),K(l,{kind:"shake",power:2}),y.kind==="boss")){for(let I of l.query(We))T(l,I,null,false);p(l,"cleared");}},H=(l,w,A,d)=>{if(!l.has(w,We))return;let y=l.need(w,We);if(y.hp-=A,(y.elite||y.kind==="boss"||y.kind==="miniboss")&&$e>0){$e-=1;let R=l.need(w,F);K(l,{kind:"pop",x:R.x+o.range(-10,10),y:R.y-y.size,text:String(Math.round(A)),color:"text",size:Math.round(Re()*.03)});}y.hp<=0?T(l,w,d):y.kind!=="boss"&&y.kind!=="miniboss"&&Ge(l,w,"hit");},u=(l,w,A,d,y)=>{let R=l.get(w,We);if(!R||R.kind==="boss"||R.kind==="miniboss"||R.phase==="dash")return;let S=l.need(w,F),$=S.x-A,g=S.y-d,L=Math.hypot($,g)||1;S.x+=$/L*y,S.y+=g/L*y;},f=(l,w)=>{if(fe>0||a===null)return;let A=Math.max(1,w-ee.armor);ee.hp-=A,fe=s("graceTime"),l.vars.hp=Math.max(0,Math.ceil(ee.hp)),l.emit("player-hit",{hp:l.vars.hp}),Ge(l,a,"hit"),K(l,{kind:"flash",color:"danger"}),K(l,{kind:"shake",power:.8});let d=De();K(l,{kind:"pop",x:d.x,y:d.y-ht()*1.4,text:`-${Math.round(A)}`,color:"danger",size:Math.round(Re()*.034)}),ee.hp<=0&&b(l);},b=l=>{if(l.vars.revive_ready===true&&!Ae){l.vars.reviving=true,Ht(l),i=null,l.emit(er,{});return}p(l,"died");},c=l=>{if(l.vars.reviving!==true)return;Ae=true,l.vars.reviving=false,ee.hp=ee.maxHp,l.vars.hp=Math.ceil(ee.hp),fe=2.5;let w=De();for(let A of l.query(We)){let d=l.need(A,F);if(Math.hypot(d.x-w.x,d.y-w.y)<Re()*.4){let y=l.get(A,We);if(!y)continue;y.kind==="boss"||y.kind==="miniboss"?u(l,A,w.x,w.y,Re()*.2):T(l,A,"revive");}}for(let A of l.query(nn))l.destroy(A);K(l,{kind:"ring",x:w.x,y:w.y,color:"coin",size:Re()*.8}),K(l,{kind:"flash",color:"coin"}),a!==null&&at(l,a,"idle");},p=(l,w)=>{if(!ot(l)||Se)return;Se=true;let A=Math.floor(we);w==="cleared"&&l.vars["meta:first_clear"]===true&&Qe(l,"coins",ke.firstClearGold),l.vars.score=Ee*s("killScore")+A*5+de*s("bossScore")+(w==="cleared"?s("clearBonus")*ke.chapter:0),l.vars.choosing=false,l.vars.reviving=false,l.emit(Ut,{reason:w,stats:{kills:Ee,seconds:A,bosses:de,chapter:ke.chapter,level:q,cleared:w==="cleared"}});},k=Sr(r,"weapons",Pn),_=()=>{let l=[],w=Object.keys(m).length,A=Object.keys(v).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&&w<6&&k.includes(y)&&l.push({o:{kind:"weapon",id:y,level:1},weight:1.6});}for(let y of Ra){let R=v[y];R!==void 0&&R<5?l.push({o:{kind:"passive",id:y,level:R+1},weight:2}):R===void 0&&A<6&&l.push({o:{kind:"passive",id:y,level:1},weight:1.2});}let d=[];for(;d.length<3&&l.length>0;){let y=0;for(let $ of l)y+=$.weight;let R=o.range(0,y),S=0;for(;S<l.length-1&&(R-=l[S].weight,!(R<=0));S++);d.push(l[S].o),l.splice(S,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},C=(l,w)=>{ye=_(),be=w,l.vars.choosing=true,l.vars.survivors_offer=Vl(ye),Ht(l),i=null,ct(l,xn);let A=De();K(l,{kind:"ring",x:A.x,y:A.y,color:w==="chest"?"coin":"accent",size:Re()*.5}),l.emit(Nl,{level:q,source:w,options:ye,build:{weapons:{...m},passives:{...v}}});},z=l=>{l.vars.choosing===true||!ot(l)||(ne>0?(ne-=1,C(l,"level")):Z>0&&(Z-=1,C(l,"chest")));},B=(l,w)=>{w.kind==="weapon"?(m[w.id]=w.level,x[w.id]=0):w.kind==="passive"?v[w.id]=w.level:w.kind==="heal"?ee.hp=Math.min(ee.maxHp,ee.hp+ee.maxHp*.3):w.kind==="gold"&&Qe(l,"coins",10),Qt(),l.vars.hp=Math.ceil(ee.hp),pe(l);},ae=(l,w)=>{if(l.vars.choosing!==true)return;let A=ye[w];A&&(B(l,A),ye=[],l.vars.choosing=false,l.vars.survivors_offer="",l.emit(zl,{kind:A.kind,id:A.id,level:A.level,source:be}),z(l));},pe=l=>{let w=De(),A=Re(),d=m.blades,y=d?Ir.blades.count[d-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(W=>l.isAlive(W)&&l.need(W,bn).index===P)||Pt(l,w.x,w.y,{shape:"sprite",art:"blade",w:A*.075,h:A*.075,color:"primary",depth:31},{type:bn,data:{index:P}});for(let P of l.query(bn)){let W=l.need(P,le);W.shape==="sprite"&&(W.w=W.h=A*(d===5?.095:.075)*Math.sqrt(ee.area));}let S=m.aura,$=l.query(In);if(S){let P=A*Ir.aura.reach[S-1]*ee.area;$.length===0&&Pt(l,w.x,w.y,{shape:"sprite",art:"aura_field",w:P*2,h:P*2,color:S===5?"coin":"secondary",alpha:.9,depth:1.5},{type:In,data:{r:P}});for(let W of l.query(In)){l.need(W,In).r=P;let te=l.need(W,le);te.shape==="sprite"&&(te.w=te.h=P*2,te.color=S===5?"coin":"secondary");}}else for(let P of $)l.destroy(P);let g=m.drone,L=g?Ir.drone.count[g-1]:0,I=l.query(Nn);for(let P of I)l.need(P,Nn).index>=L&&l.destroy(P);for(let P=0;P<L;P++)I.some(W=>l.isAlive(W)&&l.need(W,Nn).index===P)||Pt(l,w.x,w.y,{shape:"sprite",art:"drone",w:A*.06,h:A*.06,color:"piece6",depth:33},{type:Nn,data:{index:P,cd:.3*P}});},Me=(l,w,A,d,y)=>{let R=null,S=d;for(let $ of l.query(We)){if(y&&y.includes($))continue;let g=l.need($,F),L=Math.hypot(g.x-w,g.y-A);L<S&&(S=L,R=$);}return R},qe=(l,w,A,d,y,R,S,$,g=1)=>{let L=ht()*g,I=s("shotSpeed")*rt(),P=Pt(l,w,A,{shape:"sprite",art:"shot",w:L*.95,h:L*.48,color:$,depth:30},{type:zn,data:{vx:Math.cos(d)*I,vy:Math.sin(d)*I,life:1.4,damage:y,pierce:R,hit:[],by:S}});l.need(P,F).rotation=d;},tt=(l,w,A)=>{if(a===null)return;let d=De(),y=Re(),R=ht();for(let S of Pn){let $=m[S];if($===void 0)continue;let g=Ir[S],L=$-1,I=g.damage[L]*ee.might;if(x[S]=(x[S]??0)-w,S==="blaster"&&x[S]<=0){let P=Me(l,d.x,d.y,y*.75);if(P===null){x[S]=0;continue}x[S]=g.cooldown[L]*ee.haste;let W=l.need(P,F),te=Math.atan2(W.y-(d.y-R*.3),W.x-d.x),X=g.count[L];for(let ue=0;ue<X;ue++)qe(l,d.x,d.y-R*.3,te+(ue-(X-1)/2)*.16,I,g.pierce[L],"blaster",$===5?"piece6":"coin",$===5?1.25:1);Ge(l,a,"attack");let me=l.need(a,le);me.shape==="actor"&&(me.actRate=1/Math.max(.2,g.cooldown[L]*ee.haste),A||(me.facing=W.x>=d.x?1:-1));}else if(S==="blades"){let P=y*g.reach[L]*ee.area,W=3+.35*$;D+=W*w;let te=l.query(bn),X=te.length||1;for(let me of te){let ue=l.need(me,bn),xe=D+ue.index/X*Math.PI*2,ge=l.need(me,F);ge.x=d.x+Math.cos(xe)*P,ge.y=d.y-R*.2+Math.sin(xe)*P,ge.rotation=D*2.2;let Ve=y*.04*Math.sqrt(ee.area);for(let nt of l.query(We)){let bt=l.get(nt,We);if(!bt)continue;let jt=l.need(nt,F);Math.hypot(jt.x-ge.x,jt.y-ge.y)>Ve+bt.size*.55||l.time-(bt.hurtAt.blades??-9)<g.cooldown[L]||(bt.hurtAt.blades=l.time,H(l,nt,I,"blades"),u(l,nt,d.x,d.y,y*.012));}}}else if(S==="aura"){let P=l.query(In)[0];if(P===void 0)continue;let W=l.need(P,F);if(W.x=d.x,W.y=d.y+R*.3,l.need(P,F).rotation=l.time*.6,x[S]>0)continue;x[S]=g.cooldown[L];let te=l.need(P,In).r;for(let X of l.query(We)){let me=l.need(X,F),ue=l.get(X,We);!ue||Math.hypot(me.x-d.x,me.y-d.y)>te+ue.size*.3||(H(l,X,I,"aura"),u(l,X,d.x,d.y,y*.008));}}else if(S==="boomerang"&&x[S]<=0){let P=Me(l,d.x,d.y,y*.8);if(P===null){x[S]=0;continue}x[S]=g.cooldown[L]*ee.haste;let W=l.need(P,F),te=Math.atan2(W.y-d.y,W.x-d.x),X=g.count[L];for(let me=0;me<X;me++){let ue=te+me*Math.PI*2/X,xe=y*($===5?.085:.065);Pt(l,d.x,d.y,{shape:"sprite",art:"boomerang",w:xe,h:xe,color:"accent",depth:32},{type:ds,data:{dx:Math.cos(ue),dy:Math.sin(ue),dist:0,range:y*g.reach[L]*ee.area,back:false,damage:I,hit:[]}});}}else if(S==="lightning"&&x[S]<=0){let P=Me(l,d.x,d.y,y*.55);if(P===null){x[S]=0;continue}x[S]=g.cooldown[L]*ee.haste;let W=[],te={x:d.x,y:d.y-R},X=P;for(let me=0;me<g.count[L]&&X!==null;me++){let ue=l.get(X,We);if(!ue)break;let xe=l.need(X,F),ge={x:xe.x,y:xe.y-ue.size*.4};pt(l,te,ge,$===5?"coin":"primary"),W.push(X);let Ve=Me(l,xe.x,xe.y,y*g.reach[L]*ee.area,W);H(l,X,I,"lightning"),te=ge,X=Ve;}}else if(S==="drone"){O+=1.8*w;let P=l.query(Nn),W=P.length||1,te=y*g.reach[L];for(let X of P){let me=l.need(X,Nn),ue=O+me.index/W*Math.PI*2,xe=l.need(X,F);if(xe.x=d.x+Math.cos(ue)*te,xe.y=d.y-R*1.1+Math.sin(ue)*te*.5,me.cd-=w,me.cd>0)continue;let ge=Me(l,xe.x,xe.y,y*.6);if(ge===null){me.cd=0;continue}me.cd=g.cooldown[L]*ee.haste;let Ve=l.need(ge,F);qe(l,xe.x,xe.y,Math.atan2(Ve.y-xe.y,Ve.x-xe.x),I,$===5?2:1,"drone","piece6",.7);}}}},pt=(l,w,A,d)=>{let y=Math.hypot(A.x-w.x,A.y-w.y),R=Pt(l,(w.x+A.x)/2,(w.y+A.y)/2,{shape:"sprite",art:"zap",w:Math.max(8,y),h:Re()*.035,color:d,depth:34},{type:fs,data:{life:.16}});l.need(R,F).rotation=Math.atan2(A.y-w.y,A.x-w.x);},re=(l,w)=>{let A=De(),d=ht(),y=Re(),R=Be(l),S=Math.hypot(R.w,R.h)*.75,$=l.query(We);for(let L of $){let I=l.get(L,We);if(!I)continue;let P=l.need(L,F),W=A.x-P.x,te=A.y-P.y,X=Math.hypot(W,te)||1;W/=X,te/=X;let me=I.kind==="boss"||I.kind==="miniboss";if(X>(me?S*1.3:S)){let nt=ze();P.x=nt.x,P.y=nt.y;continue}I.t-=w;let ue=I.speed,xe=W,ge=te;if(I.kind==="archer"){let nt=y*.3;if(X<nt?ue*=-0.6:X<nt*1.4&&(ue=0),I.t<=0&&X<y*.6){I.t=2.4,Ge(l,L,"attack");let bt=260*rt();Pt(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:W*bt,vy:te*bt,life:3,damage:I.damage}});}}else (I.kind==="charger"||I.kind==="miniboss"||I.kind==="boss")&&(I.phase==="walk"&&I.t<=0&&X<y*(me?.6:.38)?I.kind!=="boss"||I.next%3===0?(I.phase="wind",I.t=me?.7:.55,Ge(l,L,"surprised"),K(l,{kind:"ring",x:P.x,y:P.y,color:"danger",size:I.size*2.2})):j(l,L,I):I.phase==="wind"?(ue=0,I.t<=0&&(I.phase="dash",I.t=me?.6:.45,I.vx=W,I.vy=te)):I.phase==="dash"&&(ue=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*ue*w,P.y+=ge*ue*w;let Ve=l.need(L,le);if(Ve.shape==="actor"&&(Math.abs(A.x-P.x)>I.size*.4&&(Ve.facing=A.x>=P.x?1:-1),Ve.depth=Jt(l,P.y),Ve.speed=Math.abs(ue),Ve.pose=ue===0?"idle":I.kind==="brute"||me?"walk":"run"),X<(I.size+d)/2){if(I.kind==="bomber"){K(l,{kind:"ring",x:P.x,y:P.y,color:"piece6",size:y*.22}),f(l,I.damage),T(l,L,null,false);continue}if(fe<=0&&(Ge(l,L,"attack"),f(l,I.damage),Se||Ta(l)))return}}let g=l.query(We);for(let L=0;L<g.length;L++){let I=l.need(g[L],We),P=l.need(g[L],F);for(let W=L+1;W<g.length;W++){let te=l.need(g[W],We),X=l.need(g[W],F),me=(I.size+te.size)*.42,ue=X.x-P.x,xe=X.y-P.y,ge=ue*ue+xe*xe;if(ge>=me*me||ge===0)continue;let Ve=Math.sqrt(ge),nt=(me-Ve)*.5,bt=ue/Ve*nt,jt=xe/Ve*nt,jr=I.kind==="boss"||I.kind==="miniboss",Dr=te.kind==="boss"||te.kind==="miniboss";jr||(P.x-=bt,P.y-=jt),Dr||(X.x+=bt,X.y+=jt);}}for(let L of l.query(vo)){let I=l.need(L,vo).of;if(!l.isAlive(I)||!l.has(I,We)){l.destroy(L);continue}let P=l.need(I,F),W=l.need(L,F);W.x=P.x,W.y=P.y+l.need(I,We).size*.55;let te=l.need(L,le);te.shape==="sprite"&&(te.alpha=.6+.3*Math.sin(l.time*6));}},j=(l,w,A)=>{let d=l.need(w,F),y=Re(),R=A.next%3;if(A.next+=1,A.t=A.hp<A.maxHp/2?1.4:2.2,R===1){let S=A.hp<A.maxHp/2?18:12,$=220*rt();for(let g=0;g<S;g++){let L=g/S*Math.PI*2+l.time;Pt(l,d.x,d.y-A.size*.4,{shape:"sprite",art:"orb",w:y*.035,h:y*.035,color:"danger",depth:29},{type:nn,data:{vx:Math.cos(L)*$,vy:Math.sin(L)*$,life:3.5,damage:A.damage*.6}});}Ge(l,w,"attack"),K(l,{kind:"ring",x:d.x,y:d.y,color:"danger",size:A.size*3});}else {for(let S=0;S<6;S++){let $=S/6*Math.PI*2;Ze("swarm",{x:d.x+Math.cos($)*A.size*1.6,y:d.y+Math.sin($)*A.size*1.6});}Ge(l,w,"cheer");}},J=(l,w)=>{let A=Be(l),d=De(),y=ht(),R=Re()*.2;for(let $ of l.query(zn)){let g=l.need($,zn),L=l.need($,F);if(L.x+=g.vx*w,L.y+=g.vy*w,g.life-=w,g.life<=0||L.x<-R||L.y<-R||L.x>A.w+R||L.y>A.h+R){l.destroy($);continue}for(let I of l.query(We)){if(g.hit.includes(I))continue;let P=l.get(I,We);if(!P)continue;let W=l.need(I,F);if(!(Math.abs(W.x-L.x)>P.size/2+4||Math.abs(W.y-(L.y+P.size*.2))>P.size*.9+4)&&(g.hit.push(I),K(l,{kind:"burst",x:L.x,y:L.y,color:"coin",n:4,size:y*.5}),u(l,I,d.x,d.y,Re()*.01),H(l,I,g.damage,g.by),g.hit.length>=g.pierce)){l.destroy($);break}}}for(let $ of l.query(nn)){let g=l.need($,nn),L=l.need($,F);if(L.x+=g.vx*w,L.y+=g.vy*w,g.life-=w,g.life<=0){l.destroy($);continue}if(Math.hypot(L.x-d.x,L.y-(d.y-y*.3))<y*.55&&(l.destroy($),f(l,g.damage),Se||Ta(l)))return}let S=Re()*1.5;for(let $ of l.query(ds)){let g=l.need($,ds),L=l.need($,F);if(L.rotation=(L.rotation??0)+w*14,g.back){let P=d.x-L.x,W=d.y-L.y,te=Math.hypot(P,W)||1;if(te<y*.5){l.destroy($);continue}L.x+=P/te*S*w,L.y+=W/te*S*w;}else {let P=S*w*Math.max(.35,1-g.dist/g.range);L.x+=g.dx*P,L.y+=g.dy*P,g.dist+=P,g.dist>=g.range*.98&&(g.back=true,g.hit=[]);}let I=l.need($,le).w*.5;for(let P of l.query(We)){if(g.hit.includes(P))continue;let W=l.get(P,We);if(!W)continue;let te=l.need(P,F);Math.hypot(te.x-L.x,te.y-L.y)>I+W.size*.5||(g.hit.push(P),u(l,P,L.x,L.y,Re()*.015),H(l,P,g.damage,"boomerang"));}}for(let $ of l.query(fs)){let g=l.need($,fs);g.life-=w;let L=l.need($,le);L.shape==="sprite"&&(L.alpha=Math.max(0,g.life/.16)),g.life<=0&&l.destroy($);}},Y=(l,w)=>{let A=De(),d=ht(),R=l.query(ar).filter(S=>l.need(S,ar).kind==="xp");if(R.length>90){let S=R.map(P=>({e:P,d:Math.hypot(l.need(P,F).x-A.x,l.need(P,F).y-A.y)})).sort((P,W)=>W.d-P.d).slice(0,30),$=0,g=l.need(S[0].e,F),L=g.x,I=g.y;for(let P of S)$+=l.need(P.e,ar).value,l.destroy(P.e);Tt("xp",L,I,Math.max(25,$));}for(let S of l.query(ar)){let $=l.need(S,ar),g=l.need(S,F),L=Math.hypot(A.x-g.x,A.y-g.y);if(L<ee.magnet||$.pulled){$.pulled=true;let I=Re()*($.kind==="xp"&&L>ee.magnet?2.4:1.4),P=Math.min(1,w*I/Math.max(1,L));g.x+=(A.x-g.x)*P,g.y+=(A.y-g.y)*P;}if(!(L>d*.6))if(l.destroy(S),$.kind==="coin")Qe(l,"coins",$.value),l.emit("coin-collected",{value:$.value}),K(l,{kind:"pop",x:A.x,y:A.y-d*1.6,text:`+${$.value}`,size:Math.round(d*.45)});else if($.kind==="xp"){for(N+=$.value*ee.growth;N>=Xe(q);)N-=Xe(q),q+=1,ne+=1;l.vars.xp_level=q;}else if($.kind==="food")ee.hp=Math.min(ee.maxHp,ee.hp+ee.maxHp*.25),l.vars.hp=Math.ceil(ee.hp),K(l,{kind:"ring",x:A.x,y:A.y,color:"accent",size:d*3});else if($.kind==="magnet"){for(let I of l.query(ar))(l.need(I,ar).kind==="xp"||l.need(I,ar).kind==="coin")&&(l.need(I,ar).pulled=true);K(l,{kind:"ring",x:A.x,y:A.y,color:"coin",size:Re()*1.2});}else if($.kind==="bomb"){let I=Be(l);K(l,{kind:"flash",color:"#ffffff"}),K(l,{kind:"shake",power:2});for(let P of l.query(We)){let W=l.need(P,F);if(W.x<0||W.y<0||W.x>I.w||W.y>I.h)continue;let te=l.get(P,We);te&&H(l,P,te.kind==="boss"||te.kind==="miniboss"?te.maxHp*.1:te.hp+1,"bomb");}}else $.kind==="chest"&&(Z+=1,K(l,{kind:"burst",x:A.x,y:A.y,color:"coin",n:20,size:d*2}));}z(l);},M=()=>{for(let w of [We,zn,nn,ar,bn,In,Nn,ds,fs,vo,xn])ct(e,w);ct(e,Qn),yt(),Bt(e,"top",void 0,{pan:true}),e.vars.field_x=0,e.vars.field_y=0,i=null,h=0,ke=xo(rn(e,"meta:chapter")||1,s("duration")),ce=ke.duration;let l=et();m={[l.weapon]:1},v=l.passive?{[l.passive]:1}:{};for(let w of Pn)x[w]=.4;N=0,q=1,ne=0,Z=0,ye=[],fe=0,Ee=0,de=0,Ae=false,Se=false,Pe=0,we=0,Le=false,_e=null,oe=s("minibossEvery")>0?s("minibossEvery"):1/0,Te=s("eliteEvery")>0?s("eliteEvery")*.8:1/0,Ke=22,Ne=0,se=null,Ie=0,ee.maxHp=0,ee.hp=0,Qt(),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=ke.chapter,e.vars.choosing=false,e.vars.reviving=false,e.vars.boss_hp=0,e.vars.survivors_offer="",it(),pe(e);};e.on(zt,l=>{let w=l,A=e.vars.choosing===true||e.vars.reviving===true;w.type==="press"&&ot(e)&&!A?i={x:w.x,y:w.y}:w.type==="release"&&(i=null),w.type==="key"&&e.vars.choosing===true&&(w.key==="left"||w.key==="action"||w.key==="right")&&ae(e,w.key==="left"?0:w.key==="action"?1:2);}),e.on(Bl,l=>ae(e,Number(l.index??-1))),e.on(Hl,()=>{e.vars.choosing===true&&(e.vars.choosing=false,C(e,be));}),e.on(tr,()=>c(e)),e.on(rr,()=>{e.vars.reviving===true&&(e.vars.reviving=false,p(e,"died"));}),e.on(qt,M),e.on(Zt,M),e.on(Xt,l=>{for(let w of e.query(We))at(e,w,"idle");a!==null&&e.isAlive(a)&&at(e,a,l.reason==="cleared"?"dance":"die"),yt(),ct(e,xn);}),e.on(Ft,()=>{Bt(e,"top",void 0,{pan:true}),it(),ot(e)&&pe(e);});let E=(l,w)=>{let A=i!==null&&n.pointer.down&&l.vars.choosing!==true,d=l.query(xn);if(!A||i===null){for(let g of d)l.destroy(g);return}d.length===0&&(Pt(l,i.x,i.y,{shape:"circle",r:w,color:"#ffffff",alpha:.16,depth:70},{type:xn,data:{part:0}}),Pt(l,i.x,i.y,{shape:"circle",r:w*.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,S=Math.hypot(y,R)||1,$=Math.min(1,w/S);for(let g of l.query(xn)){let L=l.need(g,F);l.need(g,xn).part===0?(L.x=i.x,L.y=i.y):(L.x=i.x+y*$,L.y=i.y+R*$);}};e.addSystem({id:"survivors",order:0,run(l,w){if(!ot(l)||a===null||Se)return;let A=l.vars.choosing===true||l.vars.reviving===true;for(let te of [a,...l.query(We)]){let X=l.get(te,le);X?.shape==="actor"&&(X.paused=A);}if(A)return;$e=Math.min(12,$e+w*10);let d=Be(l);if(we+=w,!Le){let te=Math.max(0,ce-we);l.vars.time_left=te,te<=0&&ur(l);}fe>0&&(fe=Math.max(0,fe-w)),ee.regen>0&&ee.hp<ee.maxHp&&(ee.hp=Math.min(ee.maxHp,ee.hp+ee.regen*w),l.vars.hp=Math.ceil(ee.hp)),l.vars.hp_max=ee.maxHp;let y=De(),R=Re()*.11,S=n.axis(),$=S.x,g=S.y,L=$!==0||g!==0?1:0;if(L===0&&i&&n.pointer.down){$=n.pointer.x-i.x,g=n.pointer.y-i.y;let te=Math.hypot($,g);L=te<R*.18?0:Math.min(1,te/R);}E(l,R);let I=Math.hypot($,g),P=I>0&&L>0;if(P){let te=$/I*ee.speed*L*w,X=g/I*ee.speed*L*w;for(let me of [...l.query(We),...l.query(zn),...l.query(nn),...l.query(ar),...l.query(Qn),...l.query(ds),...l.query(fs)]){let ue=l.need(me,F);ue.x-=te,ue.y-=X;}pd(l,te,X),Qe(l,"field_x",te),Qe(l,"field_y",X),h+=w,h>.6&&Lt(l,"survivors-move");}!vt(l,"survivors-move")&&!_r(l)&&kt(l,"circle",{x:d.w/2,y:d.h*.8},{x:R*.6,y:0});let W=l.need(a,le);W.alpha=fe>0&&Math.floor(l.time*12)%2===0?.4:1,W.shape==="actor"&&(W.pose=P?"run":"idle",W.speed=ee.speed*Math.max(.3,L),P&&Math.abs($)>I*.15&&(W.facing=$>0?1:-1),W.depth=Jt(l,y.y)+5e-4),Nt(l,w),re(l,w),!(Se||Ta(l))&&(tt(l,w,P),J(l,w),!(Se||Ta(l))&&(Y(l,w),!Se&&(l.vars.score=Ee*s("killScore")+Math.floor(we)*5+de*s("bossScore"),ft(l))));}}),e.vars.survivors_base=s("duration"),M();}};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"}],pr=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=(v,x)=>e[x]?.[v],r=null,o=[],n=[];for(let v=0;v<e.length;v++)for(let x=0;x<e[v].length;x++){let D=t(x,v);D==="X"?r={col:x,row:v}:D==="S"?o.push({col:x,row:v}):D==="o"&&n.push({col:x,row:v});}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=(v,x)=>`${v},${x}`,i=[r];s.set(a(r.col,r.row),0);let h=[[0,1],[-1,0],[1,0],[0,-1]];for(;i.length>0;){let v=i.shift(),x=s.get(a(v.col,v.row));for(let[D,O]of h){let N=v.col+D,q=v.row+O;!du(t(N,q))||s.has(a(N,q))||(s.set(a(N,q),x+1),i.push({col:N,row:q}));}}let m=o.map(v=>{if(!s.has(a(v.col,v.row)))throw new Error(`tower-defense map: the entry ${v.col},${v.row} has no road to the gate`);let x=[v],D=v;for(;D.col!==r.col||D.row!==r.row;){let O=s.get(a(D.col,D.row)),N=h.map(([q,ne])=>({col:D.col+q,row:D.row+ne})).find(q=>s.get(a(q.col,q.row))===O-1);x.push(N),D=N;}return x});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),h=o%Nr===0?Bn.find(x=>x.boss===i):void 0,m=6+Math.floor((o-1)/2),v=[];for(let x=1;x<=m;x++){let D=5+x*1.6+o*.35,O=[],N=0,q=0,ne=[];if(x===1)ne.push(s[0]);else {a&&x===2&&ne.push(a);let ye=Math.min(4,1+Math.floor(x/3));for(;ne.length<ye;)ne.push(s[Math.floor(n()*s.length)]);}let Z=D/ne.length;for(let ye of ne){let be=Math.max(1,Math.round(Z/ye.cost)),fe=ye.speed>=1.5?.55:ye.hp>=2?1.3:.85;O.push({enemy:ye.id,count:be,gap:fe,delay:N,entry:q%Math.max(1,t)}),N+=be*fe*.55+1,q++;}h&&x===m&&O.push({enemy:h.id,count:1,gap:1,delay:N+2,entry:0}),v.push({groups:O});}return v}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(h=>h.unlockLevel<=o).map(h=>h.id),spells:$o.filter(h=>h.unlockLevel<=o).map(h=>h.id),branches:o>=Gl,fresh:uf(o,r)?.id??null,enemies:hf(o,r).map(h=>h.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"),Oe=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=d=>yr(t,d),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)),h=[],m=Ne(),v=0,x=20,D=20,O=0,N=[],q=0,ne=null,Z=0,ye=0,be=0,fe=false,Ee=false,de=1,Ae=null,Pe=[],we=null,ce=new Map,ke=[],Le=null,_e=new Map,oe=new Map,Te=()=>So.find(d=>d.id===e.vars["meta:hero"])??So[0],Ke=()=>e.vars.reviving===true;function Ne(){return un(Be(e),Br,Hr,{top:.15,bottom:.86,widthShare:.98})}let se=()=>m.cell,Ie=d=>m.left+d*m.cell,$e=d=>m.top+d*m.cell,Se=d=>({x:Ie(d.col+.5),y:$e(d.row+.5)}),Ye=(d,y)=>({x:(d-m.left)/m.cell,y:(y-m.top)/m.cell}),ee=d=>d.row===0?{x:d.col+.5,y:-0.5}:d.row===Hr-1?{x:d.col+.5,y:Hr+.5}:d.col===0?{x:-0.5,y:d.row+.5}:d.col===Br-1?{x:Br+.5,y:d.row+.5}:null,Re=()=>{h=i.paths.map(d=>{let y=d.map(S=>({x:S.col+.5,y:S.row+.5})),R=ee(d[0]);return R&&y.unshift(R),{pts:y,len:y.length-1}});},rt=(d,y)=>{if(y<=0)return d.pts[0];if(y>=d.len)return d.pts[d.len];let R=Math.floor(y),S=d.pts[R],$=d.pts[R+1],g=y-R;return {x:S.x+($.x-S.x)*g,y:S.y+($.y-S.y)*g}},ht=new Set,De=(d,y,R,S,$=1)=>{ht.add(d);let g=_e.get(d);(g===void 0||!e.isAlive(g))&&(g=e.create(),e.set(g,Jl,{id:d}),_e.set(d,g)),e.set(g,F,{x:y,y:R,scale:$}),e.set(g,le,S);},Qt=d=>{for(let[y,R]of [..._e])ht.has(y)||!d.some(S=>y.startsWith(S))||(e.destroy(R),_e.delete(y));},Xe=d=>{for(let[y,R]of [..._e])y.startsWith(d)&&(e.destroy(R),_e.delete(y));},et=(d,y,R,S)=>{let $=e.create();return e.set($,gf,{kind:d}),e.set($,F,{x:y,y:R}),e.set($,le,S),$},it=()=>{ct(e,gf),ct(e,ja);let d=se();et("grass",Ie(Br/2),$e(Hr/2),{shape:"tile",art:"tile_grass",w:d*Br,h:d*Hr,unit:d,color:"ground",depth:-10}),i.rows.forEach((L,I)=>[...L].forEach((P,W)=>{let te=Se({col:W,row:I}),X=te.y+d*.45;P==="#"||P==="S"||P==="X"?et("road",te.x,te.y,{shape:"sprite",art:"tile_road",w:d+1,h:d+1,color:"lane",depth:-9}):P==="~"?et("water",te.x,te.y,{shape:"rect",w:d+1,h:d+1,color:"primary",alpha:.45,depth:-9}):P==="t"?et("tree",te.x,X-d*.65,{shape:"sprite",art:"td_tree",w:d*1.05,h:d*1.3,depth:Jt(e,X,5)}):P==="r"?et("rock",te.x,X-d*.3,{shape:"sprite",art:"rock",w:d*.8,h:d*.6,depth:Jt(e,X,5)}):P==="*"&&et("bush",te.x,X-d*.3,{shape:"sprite",art:"td_bush",w:d*.85,h:d*.6,depth:Jt(e,X,5)});})),i.spots.forEach((L,I)=>{let P=Se(L),W=et("spot",P.x,P.y+d*.18,{shape:"sprite",art:"td_spot",w:d*.95,h:d*.62,depth:-8});e.set(W,ja,{index:I,col:L.col,row:L.row});});let y=Se(i.gate),R=ee(i.gate),S=R&&R.y>=0?R:null,$=S?Ie(i.gate.col+.5+(S.x-(i.gate.col+.5))*.35):y.x,g=S?$e(i.gate.row+.5+(S.y-(i.gate.row+.5))*.35):y.y;et("gate",$,g-d*.2,{shape:"sprite",art:"td_gate",w:d*1.35,h:d*1.35,depth:Jt(e,g+d*.45,5)});for(let L of i.paths){if(ee(L[0]))continue;let I=Se(L[0]);et("portal",I.x,I.y-d*.1,{shape:"sprite",art:"td_portal",w:d*1.05,h:d*.95,depth:Jt(e,I.y,4)});}},dt=d=>e.query(kr).find(y=>e.need(y,kr).spot===d),mt=d=>{let y=e.need(d,kr),R=zr(y.kind),S=Se(i.spots[y.spot]),$=se(),g=$*1.45,L=S.y+$*.42;e.set(d,F,{x:S.x,y:L-g/2}),e.set(d,le,{shape:"sprite",art:Ia(R,y.tier,y.branch||null),w:$*1.1,h:g,depth:Jt(e,L,5)});},yt=d=>{v=Math.max(0,Math.round(d)),e.vars.gold=v;},gt=(d,y)=>{let R=Se(i.spots[d]);K(e,{kind:"ring",x:R.x,y:R.y,color:y,size:se()*1.5}),K(e,{kind:"burst",x:R.x,y:R.y-se()*.4,color:y,n:10,size:se()});},ft=(d,y)=>{let R=zr(y);if(!R||dt(d)!==void 0)return false;let S=R.tiers[0].cost;if(v<S)return false;yt(v-S);let $=e.create();return e.set($,kr,{spot:d,kind:y,tier:1,branch:"",cooldown:.2}),mt($),gt(d,"text"),e.emit("tower-built",{kind:y}),vt(e,"td-build")||(Lt(e,"td-build"),J()),true},ze=(d,y)=>{let R=dt(d);if(R===void 0)return false;let S=e.need(R,kr),$=zr(S.kind),g;if(y){let L=$.branches.find(I=>I.id===y);if(!L||S.branch||S.tier<$.tiers.length||!a.branches)return false;g=L.cost;}else {if(S.tier>=$.tiers.length)return false;g=$.tiers[S.tier].cost;}return v<g?false:(yt(v-g),y?S.branch=y:S.tier++,mt(R),gt(d,"coin"),e.emit("tower-upgraded",{kind:S.kind,tier:S.tier,branch:S.branch}),true)},Et=d=>{let y=dt(d);if(y===void 0)return false;let R=e.need(y,kr),S=Math.floor(us(zr(R.kind),R.tier,R.branch||null)*ps);yt(v+S);let $=Se(i.spots[d]);return K(e,{kind:"pop",x:$.x,y:$.y-se()*.8,text:`+${S}`,color:"coin",size:Math.round(se()*.3)}),K(e,{kind:"burst",x:$.x,y:$.y,color:"muted",n:12,size:se()}),e.destroy(y),e.emit("tower-sold",{kind:R.kind}),true},Ze=()=>{Ae=null,Pe=[],Xe("m:"),e.vars.td_menu="";},Wt=d=>d.map(y=>`${y.action??y.id}@${Math.round(y.x)},${Math.round(y.y)}`).join(";"),hr=d=>{Ze(),Ae=d,Nt();},Nt=()=>{if(Ae===null)return;let d=Ae;Pe=[];let y=se(),R=Be(e),S=Math.min(R.w,R.h),$=Math.max(y*.46,S*.062),g=Math.max(y*1.1,$*2.3),L=Se(i.spots[d]),I=Math.max(g+$,Math.min(R.w-g-$,L.x)),P=Math.max(R.h*.1+g+$,Math.min(R.h*.88-g-$,L.y-y*.2)),W=(ge,Ve,nt,bt,jt,jr,Dr)=>{let $r=I+Ve*g,ln=P+nt*g;Pe.push({action:ge,x:$r,y:ln,r:$,ok:Dr}),e.vars.td_menu=Wt(Pe),De(`m:${ge}:bg`,$r,ln,{shape:"circle",r:$,color:"panel",alpha:.94,depth:60});let Vn=ge==="sell";De(`m:${ge}:rim`,$r,ln,{shape:"circle",r:$*1.08,color:Vn?"danger":Dr?"coin":"muted",alpha:Dr?.9:.5,depth:59.9}),De(`m:${ge}:art`,$r,ln-$*.12,{shape:"sprite",art:bt,w:Vn?$*1.25:$*1.15,h:Vn?$*1.25:$*1.3,alpha:Dr?1:.45,depth:60.1}),jr&&De(`m:${ge}:txt`,$r,ln+$*.78,{shape:"text",text:jr,size:Math.round($*.52),color:jt!==null&&!Dr?"danger":"coin",bold:true,depth:60.2});},te=dt(d);if(te===void 0){let ge=a.towers.map(nt=>zr(nt)).filter(Boolean),Ve=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((nt,bt)=>{let jt=nt.tiers[0].cost;W(`build:${nt.id}`,Ve[bt][0],Ve[bt][1],nt.tiers[0].art,jt,String(jt),v>=jt);});return}let X=e.need(te,kr),me=zr(X.kind),ue=hs(me,X.tier,X.branch||null);if(De("m:range",L.x,L.y,{shape:"sprite",art:"aura_field",w:ue.range*y*2,h:ue.range*y*2,color:"primary",alpha:.4,depth:1}),X.tier<me.tiers.length){let ge=me.tiers[X.tier];W("up",0,-1,ge.art,ge.cost,String(ge.cost),v>=ge.cost);}else !X.branch&&a.branches&&me.branches.slice(0,2).forEach((ge,Ve)=>W(`branch:${ge.id}`,Ve===0?-0.85:.85,-0.7,ge.art,ge.cost,String(ge.cost),v>=ge.cost));let xe=Math.floor(us(me,X.tier,X.branch||null)*ps);W("sell",0,1,"td_sell",null,`+${xe}`,true);},ur=d=>{if(Ae===null)return;let y=Ae,R=false;if(d.startsWith("build:")?R=ft(y,d.slice(6)):d==="up"?R=ze(y):d.startsWith("branch:")?R=ze(y,d.slice(7)):d==="sell"&&(R=Et(y)),!R){K(e,{kind:"shake",power:.3});return}Ze();},Tt=(d,y)=>{let R=se(),S=-1,$=1/0;return i.spots.forEach((g,L)=>{let I=Se(g),P=dt(L)!==void 0?I.y-R*1.1:I.y-R*.5;if(Math.abs(d-I.x)>R*.55||y<P||y>I.y+R*.55)return;let W=Math.abs(d-I.x)+Math.abs(y-I.y);W<$&&($=W,S=L);}),S},T=d=>1+.07*(d-1),H=(d,y,R,S)=>{let $=pr(d);if(!$||h.length===0)return null;let g=$.hp*a.hp*($.boss?1:T(S)),L=e.create();return e.set(L,Oe,{kind:d,hp:g,maxHp:g,route:y%h.length,progress:R,x:0,y:0,slow:0,slowLeft:0,stun:0,burn:0,burnLeft:0,healCd:$.heals?.every??0,summonCd:$.summons?.every??0,heldBy:-1,enraged:false,wave:S}),e.set(L,F,{x:0,y:0}),e.set(L,le,{shape:"actor",cast:$.cast,variant:$.variant??n.int(0,99),h:se()*$.size*1.15,pose:$.flying?"air":"walk",depth:6}),u(L),$.boss&&(e.emit(pu,{kind:d}),K(e,{kind:"shake",power:1})),L},u=d=>{let y=e.need(d,Oe),R=pr(y.kind),S=h[y.route],$=rt(S,y.progress),g=rt(S,y.progress+.05);y.x=$.x,y.y=$.y;let L=se(),I=e.need(d,F),P=e.need(d,le),W=$e($.y)+L*.2;if(I.x=Ie($.x),I.y=W-(R.flying?L*.55:0)-(P.shape==="actor"?P.h/2:0),P.shape==="actor"){Math.abs(g.x-$.x)>1e-4&&(P.facing=g.x>$.x?1:-1),P.depth=Jt(e,W,5),P.h=L*R.size*1.15;let te=y.heldBy<0&&y.stun<=0;P.pose=R.flying?"air":te?"walk":"idle",P.speed=R.speed*(1-y.slow)*L*de;}},f=d=>h[d.route].len-d.progress,b=d=>{let y=e.need(d,F);return {x:y.x,y:y.y}},c=(d,y,R,S,$=1,g="tower")=>{let L=e.get(d,Oe);if(!L)return;let I=pr(L.kind),P=y.damage*R*$*(S?2:1);if(y.type==="physical"?P*=1-I.armor*(1-(y.pierce??0)):y.type==="magic"&&(P*=1-I.resist),y.slow&&(L.slow=Math.max(L.slow,y.slow*(I.boss?.5:1)),L.slowLeft=Math.max(L.slowLeft,(y.slowTime??1)*R)),y.burn&&(L.burn=Math.max(L.burn,y.burn*R),L.burnLeft=Math.max(L.burnLeft,y.burnTime??2)),y.stun&&!I.boss&&n.chance(y.stun)&&(L.stun=Math.max(L.stun,y.stunTime??.5)),S){let W=b(d);K(e,{kind:"pop",x:W.x,y:W.y-se()*.5,text:String(Math.round(P)),color:"danger",size:Math.round(se()*.3)});}p(d,P,g);},p=(d,y,R)=>{let S=e.get(d,Oe);S&&(S.hp-=y,S.hp<=0&&k(d,R));},k=(d,y)=>{let R=e.need(d,Oe),S=pr(R.kind);e.remove(d,Oe),at(e,d,"die"),_n(e,d,1),ye++;let $=Math.round(S.bounty*a.bounty);yt(v+$);let g=b(d);if(K(e,{kind:"pop",x:g.x,y:g.y-se()*.6,text:`+${$}`,color:"coin",size:Math.round(se()*.28)}),e.emit("enemy-defeated",{kind:R.kind,by:y}),S.boss?(be++,Qe(e,"coins",10),e.emit(hu,{kind:R.kind}),K(e,{kind:"shake",power:1.4}),K(e,{kind:"flash",color:"coin"})):n.chance(o("coinRate"))&&(Qe(e,"coins",1),e.emit("coin-collected",{value:1})),S.splits)for(let L=0;L<S.splits.count;L++)H(S.splits.into,R.route,Math.max(0,R.progress-.18*L),R.wave);},_=d=>{let y=e.need(d,Oe),R=pr(y.kind),S=Se(i.gate);K(e,{kind:"burst",x:S.x,y:S.y,color:"danger",n:12,size:se()}),e.destroy(d),x=Math.max(0,x-R.leak),e.vars.lives=x,e.emit("player-hit",{lives:x}),K(e,{kind:"flash",color:"danger"}),K(e,{kind:"shake",power:R.boss?1.6:.8}),x<=0&&ae();},C=()=>{if(!(O>=a.waves.length)){O++,e.vars.wave=O,N=[];for(let d of a.waves[O-1].groups)for(let y=0;y<d.count;y++)N.push({at:d.delay+y*d.gap,enemy:d.enemy,entry:d.entry});N.sort((d,y)=>d.at-y.at),q=0,ne=null,e.emit(ec,{wave:O});}},z=()=>{if(!(ne===null||O>=a.waves.length)){if(O>0){let d=Math.ceil(ne*o("earlyGold")*a.bounty);if(d>0){yt(v+d);let y=ke.find(R=>R.id.startsWith("call"));y&&K(e,{kind:"pop",x:y.x,y:y.y-se()*.6,text:`+${d}`,color:"coin",size:Math.round(se()*.32)});}}Lt(e,"td-call"),C();}},B=d=>{if(fe||!ot(e))return;fe=true;let y=d==="defended",R=y?Math.min(Ee?1:3,za(x,D)):0;e.vars.stars=R,y&&e.vars["meta:first_clear"]===true&&Qe(e,"coins",a.firstClearGold),e.vars.score=Me()+(y?1e3+R*300:0),e.vars.reviving=false,Ze(),e.emit(Ut,{reason:d,stats:{chapter:a.level,seconds:Math.floor(Z),cleared:y,stars:R,coins:Number(e.vars.coins??0),bosses:be,kills:ye,lives:x}});},ae=()=>{if(e.vars.revive_ready===true&&!Ee){e.vars.reviving=true,Ze(),e.emit(er,{});return}B("overrun");},pe=()=>{if(Ke()){Ee=true,e.vars.reviving=false,x=Ba,e.vars.lives=x;for(let d of e.query(Oe))e.need(d,Oe).stun=2;K(e,{kind:"flash",color:"coin"});}},Me=()=>ye*10+x*50+Math.max(0,O-1)*100,qe=()=>1+ys(e,"meta:spells"),tt=(d,y,R)=>{let S=$o.find(L=>L.id===d);if(!S||(ce.get(d)??0)>0)return;let $=Ye(y,R);if($.x<-0.5||$.y<-0.5||$.x>Br+.5||$.y>Hr+.5)return;if(S.kind==="strike")for(let L=0;L<(S.count??1);L++){let I=e.create(),P=(S.radius??1)*.9;e.set(I,Ha,{x:$.x+(L===0?0:(n.next()-.5)*P*2),y:$.y+(L===0?0:(n.next()-.5)*P*2),t:0,delay:L*.2,damage:(S.damage??1)*a.hp*qe(),radius:S.radius??1,burn:(S.burn??0)*a.hp*qe()}),e.set(I,F,{x:-999,y:-999}),e.set(I,le,{shape:"sprite",art:"td_meteor",w:se()*.9,h:se()*.9,alpha:0,depth:45});}else {let L={route:0,q:0,d:1/0};h.forEach((P,W)=>{for(let te=.5;te<=P.len-.5;te+=.25){let X=rt(P,te),me=Math.hypot(X.x-$.x,X.y-$.y);me<L.d&&(L={route:W,q:te,d:me});}});let I=S.count??1;for(let P=0;P<I;P++){let W=e.create(),te=(S.hp??3)*a.hp*qe();e.set(W,Ar,{hp:te,maxHp:te,dps:(S.dps??.5)*a.hp*qe(),left:S.time??12,route:L.route,progress:Math.max(.3,Math.min(h[L.route].len-.3,L.q+(P-(I-1)/2)*.45)),swing:0}),e.set(W,F,{x:0,y:0}),e.set(W,le,{shape:"actor",cast:S.cast??"helper",variant:n.int(0,99),h:se()*.85,pose:"idle",depth:6}),pt(W);let X=e.need(W,F);K(e,{kind:"ring",x:X.x,y:X.y,color:"accent",size:se()*1.2});}}let g=S.cooldown*(Te().perk==="spells"?.7:1);ce.set(d,g),we=null,Le!==null&&e.isAlive(Le)&&Ge(e,Le,"attack"),e.emit("spell-cast",{id:d});},pt=d=>{let y=e.need(d,Ar),R=h[y.route],S=rt(R,y.progress),$=rt(R,y.progress-.2),g=se(),L=e.need(d,F),I=e.need(d,le),P=$e(S.y)+g*.2;L.x=Ie(S.x),L.y=P-(I.shape==="actor"?I.h/2:0),I.shape==="actor"&&(Math.abs($.x-S.x)>1e-4&&(I.facing=$.x>S.x?1:-1),I.depth=Jt(e,P,5),I.h=g*.85);},re=()=>{(Le===null||!e.isAlive(Le))&&(Le=e.create());let d=se(),y=i.gate,R=[[1,0],[-1,0],[0,-1],[0,1]].map(([g,L])=>({col:y.col+g,row:y.row+L})).find(g=>g.col>=0&&g.row>=0&&g.col<Br&&g.row<Hr&&".tr*".includes(i.rows[g.row][g.col]))??y,S=Se(R),$=S.y+d*.35;e.set(Le,F,{x:S.x,y:$-d*.6}),e.set(Le,le,{shape:"actor",cast:Te().cast,h:d*1.2,pose:"idle",facing:R.col>y.col?-1:1,depth:Jt(e,$,5)});},j=()=>{if(vt(e,"td-build")||i.spots.length===0)return;let d=h[0],y=rt(d,d.len*.4),R=0,S=1/0;i.spots.forEach(($,g)=>{let L=Math.hypot($.col+.5-y.x,$.row+.5-y.y);L<S&&(S=L,R=g);}),kt(e,"tap",Se(i.spots[R]),void 0,se()*1.2);},J=()=>{if(vt(e,"td-call")||O>0)return;let d=Se(i.paths[0][0]);kt(e,"tap",d,void 0,se()*1.2);},Y=()=>{let d=Be(e),y=Math.min(d.w,d.h),R=se(),S=d.h*.085,$=y*.05,g=(X,me,ue,xe,ge="text",Ve=y*.042)=>De(X,me,ue,{shape:"text",text:xe,size:Math.round(Ve),color:ge,bold:true,depth:70});De("h:lives:i",d.w*.07,S,{shape:"sprite",art:"heart",w:$,h:$,depth:70}),g("h:lives",d.w*.15,S,String(x),x<=5?"danger":"text"),De("h:gold:i",d.w*.3,S,{shape:"sprite",art:"td_gold",w:$*1.15,h:$,depth:70}),g("h:gold",d.w*.4,S,String(v),"coin"),De("h:wave:i",d.w*.56,S,{shape:"sprite",art:"td_call",w:$,h:$,depth:70}),g("h:wave",d.w*.66,S,`${O}/${a.waves.length}`),De("h:coin:i",d.w*.8,S,{shape:"sprite",art:"coin",w:$*.9,h:$*.9,depth:70}),g("h:coin",d.w*.89,S,String(e.vars.coins??0));let L=d.h*.125,I=e.query(Oe).find(X=>pr(e.need(X,Oe).kind)?.boss);if(I!==void 0){let X=e.need(I,Oe),me=d.w*.55,ue=Math.max(10,y*.022);De("h:n:boss:bg",d.w/2,L,{shape:"rect",w:me,h:ue,color:"#000000",alpha:.5,radius:ue/2,depth:69});let xe=Math.max(1,(me-4)*Math.max(0,X.hp/X.maxHp));De("h:n:boss:fill",d.w/2-(me-4)/2+xe/2,L,{shape:"rect",w:xe,h:ue-4,color:"danger",radius:(ue-4)/2,depth:69.1}),De("h:n:boss:i",d.w/2-me/2-$*.7,L,{shape:"sprite",art:"skull",w:$,h:$,depth:70});}else if(ne!==null&&O<a.waves.length){let X=new Map;for(let ge of a.waves[O].groups)X.set(ge.enemy,(X.get(ge.enemy)??0)+ge.count);let me=[...X].slice(0,5),ue=y*.15,xe=d.w/2-(me.length-1)*ue/2;me.forEach(([ge,Ve],nt)=>{let bt=pr(ge),jt=xe+nt*ue;De(`h:n:${ge}:a`,jt-$*.4,L+$*.1,{shape:"actor",cast:bt.cast,variant:bt.variant??1,h:$*1.5*Math.min(1.3,bt.size+.25),pose:bt.flying?"air":"idle",depth:70}),g(`h:n:${ge}:t`,jt+$*.55,L+$*.1,`\xD7${Ve}`,bt.boss?"danger":"text",y*.034);});}if(ke=[],ne!==null&&O<a.waves.length){let X=O===0?1+.08*Math.sin(e.time*6):1;i.paths.forEach((me,ue)=>{let xe=Se(me[0]),ge=R*.42;ke.push({id:`call:${ue}`,x:xe.x,y:xe.y,r:ge*1.2}),De(`b:call:${ue}:bg`,xe.x,xe.y,{shape:"circle",r:ge,color:"danger",alpha:.92,depth:65},X),De(`b:call:${ue}:i`,xe.x,xe.y,{shape:"sprite",art:"td_call",w:ge*1.3,h:ge*1.3,depth:65.1},X),De(`b:call:${ue}: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=d.h*.925,W=y*.065;$o.filter(X=>a.spells.includes(X.id)).forEach((X,me)=>{let ue=d.w*.12+me*W*2.6,xe=ce.get(X.id)??0;ke.push({id:`spell:${X.id}`,x:ue,y:P,r:W*1.15}),we===X.id&&De(`b:s:${X.id}:rim`,ue,P,{shape:"circle",r:W*1.18,color:"coin",alpha:.6+.4*Math.sin(e.time*8),depth:64.9}),De(`b:s:${X.id}:bg`,ue,P,{shape:"circle",r:W,color:"panel",alpha:.92,depth:65}),De(`b:s:${X.id}:i`,ue,P,{shape:"sprite",art:X.icon,w:W*1.25,h:W*1.25,alpha:xe>0?.4:1,depth:65.1}),xe>0&&De(`b:s:${X.id}:t`,ue,P,{shape:"text",text:String(Math.ceil(xe)),size:Math.round(W*.8),color:"text",bold:true,depth:65.2});});let te=d.w*.88;ke.push({id:"speed",x:te,y:P,r:W*1.15}),De("b:speed:bg",te,P,{shape:"circle",r:W,color:de>1?"coin":"panel",alpha:.92,depth:65}),e.vars.td_buttons=Wt(ke),De("b:speed:t",te,P,{shape:"text",text:`x${de}`,size:Math.round(W*.75),color:de>1?"panel":"text",bold:true,depth:65.1});},M=()=>{let d=se(),y=new Set,R=(S,$,g,L,I)=>{y.add(S);let P=oe.get(S);if(!P){P=[e.create(),e.create(),e.create(),e.create(),e.create()];for(let[jt,jr]of P.entries())e.set(jr,bf,{of:S,part:String(jt)});oe.set(S,P);}let W=e.need(S,F),te=e.need(S,le),X=te.shape==="actor"?te.h:d,me=W.y-X/2-d*.08,ue=Math.min(Be(e).w,Be(e).h),xe=Math.max(d*.62,ue*.065),ge=Math.max(5,xe*.13),Ve=$<.999;e.set(P[0],F,{x:W.x,y:me}),e.set(P[0],le,{shape:"rect",w:xe,h:ge,color:"#000000",alpha:Ve?.55:0,radius:ge/2,depth:30});let nt=Math.max(1,(xe-2)*Math.max(0,$));e.set(P[1],F,{x:W.x-(xe-2)/2+nt/2,y:me}),e.set(P[1],le,{shape:"rect",w:nt,h:ge-2,color:g,alpha:Ve?1:0,radius:(ge-2)/2,depth:30.1}),e.set(P[2],F,{x:W.x-xe/2-d*.12,y:me}),e.set(P[2],le,{shape:"sprite",art:L??"shield",w:d*.24,h:d*.24,alpha:L?1:0,depth:30.2});let bt=W.y+X/2;e.set(P[3],F,{x:W.x,y:bt}),e.set(P[3],le,{shape:"sprite",art:"aura_field",w:d*.75,h:d*.32,color:"primary",alpha:I?.slow?.75:0,depth:2}),e.set(P[4],F,{x:W.x,y:W.y}),e.set(P[4],le,{shape:"sprite",art:"burst",w:d*.45,h:d*.45,color:"danger",alpha:I?.burn?.5+.4*Math.sin(e.time*20):0,depth:29});};for(let S of e.query(Oe)){let $=e.need(S,Oe);R(S,$.hp/$.maxHp,"danger",pr($.kind)?.badge,{slow:$.slowLeft>0,burn:$.burnLeft>0});}for(let S of e.query(Ar)){let $=e.need(S,Ar);R(S,$.hp/$.maxHp,"accent",void 0,null);}for(let[S,$]of [...oe])if(!y.has(S)){for(let g of $)e.destroy(g);oe.delete(S);}},E=()=>{for(let d of [kr,Oe,Hn,Ar,Ha,Wa,bf,Jl])ct(e,d);_e.clear(),oe.clear();for(let d of e.query(le))e.need(d,le).shape==="actor"&&d!==Le&&!e.has(d,Jl)&&e.destroy(d);},l=()=>{E(),a=Eo(ys(e,"meta:chapter")||1,o("difficulty"),s),i=wo(Mo(Na(a.map),a.mirror)),Re(),Bt(e,"top"),m=Ne(),it(),v=0,yt((a.gold+o("gold")+ys(e,"meta:start_gold"))*(Te().perk==="gold"?1.25:1)),D=o("lives")+ys(e,"meta:lives"),x=D,O=0,N=[],q=0,ne=o("firstWait"),Z=0,ye=0,be=0,fe=false,Ee=false,de=1,Ae=null,Pe=[],we=null,ce.clear(),ke=[],e.vars.lives=x,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,re();},w=d=>{if(d.startsWith("call"))z();else if(d==="speed")de=de>1?1:2,e.vars.td_speed=de;else if(d.startsWith("spell:")){let y=d.slice(6);we===y?we=null:(ce.get(y)??0)<=0&&(we=y,Ze());}};e.on(zt,d=>{let y=d;if(y.type!=="tap"||!ot(e)||hn(e)||fe||Ke())return;if(Ae!==null){let $=Pe.find(g=>Math.hypot(y.x-g.x,y.y-g.y)<=g.r);if($){ur($.action);return}Ze();}let R=ke.find($=>Math.hypot(y.x-$.x,y.y-$.y)<=$.r);if(R){w(R.id);return}if(we!==null){tt(we,y.x,y.y);return}let S=Tt(y.x,y.y);S>=0&&(vt(e,"td-build")||Ht(e),hr(S));}),e.on(qt,()=>{l(),e.vars.level=a.level,j();}),e.on(Zt,l),e.on(tr,pe),e.on(rr,()=>{Ke()&&(e.vars.reviving=false,B("overrun"));}),e.on(Xt,d=>{Ze(),Xe("b:"),ke=[],Le!==null&&e.isAlive(Le)&&at(e,Le,d.reason==="defended"?"dance":"die");for(let y of e.query(Oe))at(e,y,"idle");}),e.on(Ft,()=>{Bt(e,"top"),m=Ne(),it();for(let d of e.query(kr))mt(d);ct(e,Hn),Ae!==null&&Nt(),re();}),e.addSystem({id:"tower-defense",order:0,run(d,y){if(!ot(d)||fe||Ke())return;let R=y*de;Z+=y;let S=se();for(let[$,g]of ce)g>0&&ce.set($,Math.max(0,g-R));if(N.length>0){for(q+=R;N.length>0&&N[0].at<=q;){let $=N.shift();H($.enemy,$.entry,0,O);}N.length===0&&O<a.waves.length&&(ne=o("wavePause"));}else ne!==null&&(ne-=R,ne<=0&&C());for(let $ of d.query(Ar)){let g=d.need($,Ar);if(g.left-=R,g.left<=0||g.hp<=0){d.remove($,Ar),at(d,$,"die"),_n(d,$,.8);for(let P of d.query(Oe))d.need(P,Oe).heldBy===$&&(d.need(P,Oe).heldBy=-1);continue}let L=rt(h[g.route],g.progress),I=d.query(Oe).filter(P=>d.need(P,Oe).heldBy===$);if(I.length<2){let P=d.query(Oe).filter(W=>{let te=d.need(W,Oe),X=pr(te.kind);return te.heldBy<0&&!X.flying&&!X.boss&&Math.hypot(te.x-L.x,te.y-L.y)<=mu}).slice(0,2-I.length);for(let W of P)d.need(W,Oe).heldBy=$,I.push(W);}I.length>0&&(p(I[0],g.dps*R,"soldier"),g.swing-=R,g.swing<=0&&(Ge(d,$,"attack"),g.swing=.6)),pt($);}for(let $ of d.query(Oe)){let g=d.get($,Oe);if(!g)continue;let L=pr(g.kind);if(!(g.burnLeft>0&&(g.burnLeft-=R,p($,g.burn*R,"burn"),!d.has($,Oe)))){if(g.slowLeft>0&&(g.slowLeft-=R,g.slowLeft<=0&&(g.slow=0)),g.stun>0&&(g.stun-=R),L.heals&&(g.healCd-=R,g.healCd<=0)){g.healCd=L.heals.every;for(let P of d.query(Oe)){let W=d.need(P,Oe);Math.hypot(W.x-g.x,W.y-g.y)>L.heals.radius||(W.hp=Math.min(W.maxHp,W.hp+W.maxHp*L.heals.share));}let I=b($);K(d,{kind:"ring",x:I.x,y:I.y,color:"accent",size:L.heals.radius*S*2});}if(L.summons&&(g.summonCd-=R,g.summonCd<=0)){g.summonCd=L.summons.every;for(let I=0;I<L.summons.count;I++)H(L.summons.id,g.route,Math.max(0,g.progress-.45*(I+1)),g.wave);Ge(d,$,"cheer");}if(L.enrage&&!g.enraged&&g.hp<g.maxHp*L.enrage.below){g.enraged=true;let I=b($);K(d,{kind:"ring",x:I.x,y:I.y,color:"danger",size:S*2});}if(g.heldBy>=0&&!d.has(g.heldBy,Ar)&&(g.heldBy=-1),g.heldBy<0&&g.stun<=0&&(g.progress+=L.speed*(1-g.slow)*(g.enraged&&L.enrage?L.enrage.speed:1)*R),g.progress>=h[g.route].len){if(_($),fe||Ke())return;continue}u($);}}for(let $ of d.query(kr)){let g=d.need($,kr);if(g.cooldown-=R,g.cooldown>0)continue;let L=zr(g.kind),I=hs(L,g.tier,g.branch||null),P=1+ys(d,L.metaVar),W=i.spots[g.spot],te=W.col+.5,X=W.row+.5,me=d.query(Oe).filter(xe=>{let ge=d.need(xe,Oe);return (pr(ge.kind).flying?I.air:I.ground)&&ge.progress>0&&Math.hypot(ge.x-te,ge.y-X)<=I.range}).sort((xe,ge)=>f(d.need(xe,Oe))-f(d.need(ge,Oe))).slice(0,I.multishot??1);if(me.length===0){g.cooldown=0;continue}g.cooldown=1/I.rate;let ue={x:Ie(te),y:$e(X)-S*.75};for(let xe of me){let ge=I.crit!==void 0&&n.chance(I.crit);if(I.beam){let jr=[],Dr=ue,$r=xe,ln=1;for(let Vn=0;Vn<=(I.chain??0)&&$r!==void 0;Vn++){let Tc=b($r);A(Dr,Tc,I.type==="magic"?"secondary":"primary"),jr.push($r);let Gn=d.need($r,Oe),sp=d.query(Oe).filter(Kn=>!jr.includes(Kn)&&Math.hypot(d.need(Kn,Oe).x-Gn.x,d.need(Kn,Oe).y-Gn.y)<=1.6).sort((Kn,Dc)=>Math.hypot(d.need(Kn,Oe).x-Gn.x,d.need(Kn,Oe).y-Gn.y)-Math.hypot(d.need(Dc,Oe).x-Gn.x,d.need(Dc,Oe).y-Gn.y))[0];c($r,I,P,ge,ln),Dr=Tc,$r=sp,ln*=.7;}continue}let Ve=b(xe),nt=d.create(),bt=Math.max(1,Math.hypot(Ve.x-ue.x,Ve.y-ue.y));d.set(nt,Hn,{target:xe,x:ue.x,y:ue.y,ax:Ve.x,ay:Ve.y,dist0:bt,went:0,stats:I,power:P,crit:ge}),d.set(nt,F,{x:ue.x,y:ue.y});let jt=I.shot==="td_arrow"?{w:S*.55,h:S*.18}:I.lob?{w:S*.34,h:S*.34}:{w:S*.3,h:S*.3};d.set(nt,le,{shape:"sprite",art:I.shot,...jt,...I.burn?{color:"danger"}:I.slow?{color:"primary"}:I.type==="magic"?{color:"secondary"}:{},depth:40});}}for(let $ of d.query(Hn)){let g=d.need($,Hn);if(d.has(g.target,Oe)){let X=b(g.target);g.ax=X.x,g.ay=X.y;}let L=g.ax-g.x,I=g.ay-g.y,P=Math.hypot(L,I),W=g.stats.shotSpeed*S*R,te=d.need($,F);if(P>W){g.x+=L/P*W,g.y+=I/P*W,g.went+=W;let X=Math.min(1,g.went/g.dist0);te.x=g.x,te.y=g.y-(g.stats.lob?Math.sin(Math.PI*X)*S*.9:0),te.rotation=g.stats.lob?(te.rotation??0)+R*8:Math.atan2(I,L);continue}if(d.destroy($),g.stats.splash){let X=Ye(g.ax,g.ay);K(d,{kind:"burst",x:g.ax,y:g.ay,color:g.stats.burn?"danger":g.stats.slow?"primary":"coin",n:12,size:g.stats.splash*S*1.6}),g.stats.lob&&K(d,{kind:"shake",power:.25});for(let me of d.query(Oe)){let ue=d.need(me,Oe),xe=pr(ue.kind);(xe.flying?g.stats.air:g.stats.ground)&&Math.hypot(ue.x-X.x,ue.y+(xe.flying?-0.55:0)-X.y)<=g.stats.splash&&c(me,g.stats,g.power,g.crit);}}else d.has(g.target,Oe)&&(K(d,{kind:"burst",x:g.ax,y:g.ay,color:g.stats.type==="magic"?"secondary":"coin",n:5,size:S*.5}),c(g.target,g.stats,g.power,g.crit));if(fe||Ke())return}for(let $ of d.query(Ha)){let g=d.need($,Ha);g.t+=R;let L=(g.t-g.delay)/uu,I=d.need($,F),P=d.need($,le);if(L<0)continue;if(L<1){let te=Be(d).h;I.x=Ie(g.x)+(1-L)*S*2,I.y=$e(g.y)-(1-L)*te*.5,I.rotation=-0.9,P.shape==="sprite"&&(P.alpha=1);continue}d.destroy($),K(d,{kind:"burst",x:Ie(g.x),y:$e(g.y),color:"danger",n:20,size:g.radius*S*2}),K(d,{kind:"ring",x:Ie(g.x),y:$e(g.y),color:"coin",size:g.radius*S*2.2}),K(d,{kind:"shake",power:.8});let W={damage:g.damage,type:"true",...g.burn>0?{burn:g.burn,burnTime:2}:{}};for(let te of d.query(Oe)){let X=d.need(te,Oe);Math.hypot(X.x-g.x,X.y-g.y)<=g.radius&&c(te,W,1,false,1,"spell");}if(fe||Ke())return}for(let $ of d.query(Wa)){let g=d.need($,Wa);g.life-=y,g.life<=0&&d.destroy($);}if(O>=a.waves.length&&N.length===0&&d.query(Oe).length===0){B("defended");return}d.vars.level_progress=a.waves.length>0?Math.min(1,(O-(N.length>0||d.query(Oe).length>0?.5:0))/a.waves.length):0,d.vars.score=Me(),ht.clear(),Ae!==null&&Nt(),M(),Y(),Qt(["m:","h:","b:"]);}});let A=(d,y,R)=>{let S=Math.hypot(y.x-d.x,y.y-d.y),$=e.create();e.set($,Wa,{life:.16}),e.set($,F,{x:(d.x+y.x)/2,y:(d.y+y.y)/2,rotation:Math.atan2(y.y-d.y,y.x-d.x)}),e.set($,le,{shape:"sprite",art:"zap",w:Math.max(8,S),h:se()*.22,color:R,depth:41});};Re(),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"},je=(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}),ir=e=>({kind:"managers",n:e}),jn=[je("lb",[Ue(5200)]),je("lb",[At("l",25),Ue(62e3)]),je("lbc",[Ue(17e3)],"r"),je("lbc",[ir(2),Ue(34e3)],"r"),je("lbc",[At("b",25),Ue(51e3)],"rc"),je("lbcw",[Ue(21e4)],"rc"),je("lbcw",[At("c",25),ir(2)],"rc"),je("lbcw",[ir(3),Ue(46e4)],"rc"),je("lbcw",[At("w",10),Ue(1e6)],"rc"),Ga(je("lbcw",[At("c",25),ir(4),Ue(5e6)],"rc")),je("bcw",[Ue(73e3)],"rb"),je("bcw",[At("c",25),Ue(17e4)],"rcb"),je("bcwn",[Ue(2e5)],"rcb"),je("bcwn",[ir(2),Ue(42e4)],"rcb"),je("bcwn",[At("n",5),Ue(97e4)],"rcb"),je("bcwn",[At("w",25),Ue(24e5)],"rcb"),je("bcwn",[ir(3),Ue(19e5)],"rcb"),je("bcwn",[At("c",50),Ue(32e5)],"rcb"),je("bcwn",[At("n",10),ir(3)],"rcb"),Ga(je("bcwn",[At("n",10),ir(4),Ue(64e6)],"rcb")),je("cwn",[Ue(12e5)],"rcbi"),je("cwn",[At("w",25),Ue(2e6)],"rcbi"),je("cwnh",[Ue(27e5)],"rcbi"),je("cwnh",[ir(2),Ue(32e5)],"rcbi"),je("cwnh",[At("h",5),Ue(16e6)],"rcbi"),je("cwnh",[At("n",25),Ue(26e6)],"rcbi"),je("cwnh",[ir(3),Ue(15e6)],"rcbi"),je("cwnh",[At("w",50),Ue(42e6)],"rcbi"),je("cwnh",[At("h",10),ir(3)],"rcbi"),Ga(je("cwnh",[At("h",10),ir(4),Ue(26e7)],"rcbi")),je("wnhk",[Ue(12e6)],"rcbi"),je("wnhk",[At("h",10),Ue(36e6)],"rcbi"),je("wnhk",[ir(3),Ue(21e7)],"rcbi"),je("nhkp",[Ue(21e7)],"rcbi"),je("nhkp",[At("k",10),Ue(38e7)],"rcbi"),je("nhkp",[ir(2),Ue(42e7)],"rcbi"),je("nhkp",[At("p",5),Ue(27e8)],"rcbi"),je("nhkp",[At("k",25),Ue(32e8)],"rcbi"),je("nhkp",[At("p",10),ir(3)],"rcbi"),Ga(je("nhkp",[At("p",10),ir(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(x=>x.broken>0);if(r>=0)return {kind:"fix",index:r};let o=null,n=Qa(e),s=(x,D,O)=>{if(O>e.cash+n*8)return;let N=D/Math.max(1,O);(!o||N>o.value)&&(o={move:x,value:N,price:O});},a=x=>t.some(D=>D.kind==="level"&&D.biz===x&&on(e,D)<1),i=t.some(x=>x.kind==="managers"&&on(e,x)<1),h=t.some(x=>x.kind==="cash"&&on(e,x)<1);e.biz.forEach((x,D)=>{let O=Za(e,x)*lc(e,x),N={...x,level:x.level+1},ne=(Tr(e,N)/kn(e,N)*lc(e,N)-O)*(x.level===0?3:1)*(a(x.def.id)?3:1);s({kind:"buy",index:D},ne+(a(x.def.id)&&!h?n*.05:0),vn(e,x)),x.level>0&&!x.manager&&s({kind:"hire",index:D},Za(e,x)*(1-lc(e,x))*1.6*(i?3:1)+(i?n*.05:0),To(e,x));});for(let x of oi(e,6)){let D=x.index<0?n*(x.def.mult-1):Za(e,e.biz[x.index])*(x.def.mult-1);s({kind:"upgrade",key:x.key},D,x.price);}let m=e.biz.map((x,D)=>({b:x,i:D})).filter(x=>x.b.ready).sort((x,D)=>Tr(e,D.b)-Tr(e,x.b))[0],v=o;return v&&v.price<=e.cash?v.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 h=li(r,e.goals);h&&(_f(r,h),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),h=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:h,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=c=>yr(t,c),n=e.rng.stream("tycoon"),s=Sr(r,"events",_o.map(c=>c.id)),a=Do(1,o("difficulty")),i=ks(a.def),h=new Map,m=new Map,v=null,x=[],D=0,O=0,N=0,q=0,ne=0,Z=false,ye=false,be=0,fe=null,Ee=null,de=null,Ae=()=>Ro.find(c=>c.id===e.vars["meta:hero"])??Ro[0],Pe=()=>qa(Ae().skill),we=()=>e.vars.reviving===true,ce=()=>a.def.goals,ke=()=>{let c=Be(e);return {...c,U:Math.min(c.w,c.h)}},Le=c=>{let p=ke(),k=Math.max(1,i.biz.length),_=p.h*.25,C=p.h*.81,z=Math.max(6,p.h*.012),B=Math.min((C-_-z*(k-1))/k,150,p.w*.26),ae=Math.min(p.w*.96,660),pe=_+(C-_-(k*B+(k-1)*z))/2;return {x:p.w/2,y:pe+c*(B+z)+B/2,w:ae,h:B}},_e=c=>{let p=Le(c);return {x:p.x-p.w/2+p.h*.56,y:p.y,size:p.h*.9}},oe=()=>ke().h*.9,Te=()=>{let c=ke();return Math.min(c.U*.075,c.h*.055)},Ke=()=>{let c=ke(),p=Ee?1-Ee.left/Ee.def.ttl:0;return {x:-c.w*.05+p*c.w*1.1,y:c.h*.21,r:c.U*.06}},Ne=new Set,se=(c,p,k,_,C=1)=>{Ne.add(c);let z=h.get(c);(z===void 0||!e.isAlive(z))&&(z=e.create(),e.set(z,ku,{id:c}),h.set(c,z)),e.set(z,F,{x:p,y:k,scale:C}),e.set(z,le,_);},Ie=()=>{for(let[c,p]of [...h])Ne.has(c)||(e.destroy(p),h.delete(c));},$e=(c,p,k,_,C,z,B=70)=>se(c,p,k,{shape:"text",text:_,size:Math.max(9,Math.round(z)),color:C,bold:true,depth:B}),Se=(c,p,k,_,C,z,B,ae=2)=>{se(`${c}:bg`,p,k,{shape:"rect",w:_+4,h:C+4,color:"#000000",alpha:.4,radius:(C+4)/2,depth:ae});let pe=Math.max(1,_*Math.max(0,Math.min(1,z)));se(`${c}:fill`,p-_/2+pe/2,k,{shape:"rect",w:pe,h:C,color:B,radius:C/2,depth:ae+.1});},Ye=c=>x.push(c),ee=c=>{let p=i.biz[c],k=ws[ne]??1;return k===0?Math.max(1,cc(i,p)):k},Re=()=>{i.biz.forEach((c,p)=>{let k=Le(p),_=_e(p),C=c.level>0,z=c.def.color;se(`r${p}`,k.x,k.y,{shape:"sprite",art:"panel",w:k.w,h:k.h,color:"panel",depth:0}),c.rush>0&&se(`r${p}:rush`,_.x,_.y,{shape:"circle",r:_.size*.55,color:"coin",alpha:.35+.2*Math.sin(e.time*8),depth:.5});let B=c.ready?1+.06*Math.abs(Math.sin(e.time*6)):1;se(`r${p}:b`,_.x,_.y,{shape:"sprite",art:c.def.art,w:_.size,h:_.size,color:z,alpha:C?c.broken>0?.55:1:.35,depth:1},B),Ye({id:`biz${p}`,x:_.x,y:_.y,w:_.size,h:_.size});let ae=k.x-k.w*.12,pe=k.h*.2,Me=vs(c.level);if($e(`r${p}:lv`,ae,k.y-k.h*.26,C?`Lv ${c.level}${Me.next?`/${Me.next}`:""}`:"Lv 0","text",pe,2),C){$e(`r${p}:inc`,ae,k.y+k.h*0,`+${vr(Tr(i,c))}`,"coin",pe*.95,2);let l=c.ready||kn(i,c)<=.15&&c.manager?1:c.progress;Se(`r${p}:bar`,ae,k.y+k.h*.28,k.w*.3,Math.max(6,k.h*.12),l,c.broken>0?"danger":z),c.ready&&!c.manager&&$e(`r${p}:ok`,_.x+_.size*.36,_.y+_.size*.34,"$","coin",_.size*.3,3);}if(fe?.index===p){let l=1+.12*Math.sin(e.time*9);se(`r${p}:ev`,_.x+_.size*.32,_.y-_.size*.3,{shape:"sprite",art:fe.def.art,w:_.size*.5,h:_.size*.5,depth:4},l);}else c.broken>0&&(se(`r${p}:ev`,_.x+_.size*.3,_.y-_.size*.28,{shape:"sprite",art:"ty_wrench",w:_.size*.48,h:_.size*.48,depth:4},1+.08*Math.sin(e.time*10)),$e(`r${p}:evn`,_.x+_.size*.3,_.y+_.size*.05,String(c.broken),"danger",_.size*.26,4.1));let qe=k.x+k.w*.13,tt=k.h*.27;if(C&&!c.manager){let l=To(i,c),w=i.cash>=l;se(`r${p}:m:bg`,qe,k.y-k.h*.08,{shape:"circle",r:tt,color:w?"secondary":"panel",alpha:w?.95:.7,depth:1}),se(`r${p}:m`,qe,k.y-k.h*.08,{shape:"sprite",art:"ty_manager",w:tt*1.7,h:tt*1.7,alpha:w?1:.5,depth:1.2}),$e(`r${p}:m:p`,qe,k.y+k.h*.32,vr(l),w?"text":"muted",pe*.8,2),Ye({id:`mgr${p}`,x:qe,y:k.y,w:tt*2.2,h:k.h*.9});}let pt=k.x+k.w/2-k.w*.14,re=k.w*.25,j=k.h*.72,J=ee(p),Y=vn(i,c,J),M=i.cash>=Y;se(`r${p}:buy`,pt,k.y,{shape:"sprite",art:"button",w:re,h:j,color:M?"accent":"panel",alpha:M?1:.6,depth:1}),$e(`r${p}:buy:n`,pt,k.y-j*.2,C?`+${J}`:"OPEN","text",pe*.9,2),se(`r${p}:buy:c`,pt-re*.3,k.y+j*.2,{shape:"sprite",art:"coin",w:pe*.8,h:pe*.8,depth:2}),$e(`r${p}:buy:p`,pt+re*.08,k.y+j*.2,vr(Y),M?"coin":"muted",pe*.85,2),Ye({id:`buy${p}`,x:pt,y:k.y,w:re,h:j});let E=m.get(p);if(c.manager&&(E===void 0||!e.isAlive(E))&&(E=e.create(),e.set(E,hc,{index:p}),e.set(E,le,{shape:"actor",cast:"helper",variant:p*13+5,h:k.h*.78,pose:"idle",facing:1,depth:2}),m.set(p,E)),E!==void 0&&e.isAlive(E)){e.set(E,F,{x:qe,y:k.y+k.h*.02});let l=e.need(E,le);l.shape==="actor"&&(l.h=k.h*.78);}});},rt=c=>c.kind==="cash"?"coin":c.kind==="managers"?"ty_manager":Wn(c.biz??"")?.art??"biz1",ht=c=>c.kind==="cash"?i.earned:c.kind==="managers"?ai(i):i.biz.find(p=>p.def.id===c.biz)?.level??0,De=()=>{let c=ke(),p=c.U,k=c.h*.09;se("h:t:i",c.w*.09,k,{shape:"sprite",art:"hourglass",w:p*.06,h:p*.06,depth:70}),$e("h:t",c.w*.09+p*.09,k,Vs(D),D<=15?"danger":"text",p*.05),se("h:c:i",c.w*.42,k,{shape:"sprite",art:"coin",w:p*.07,h:p*.07,depth:70}),$e("h:c",c.w*.42+p*.13,k,vr(i.cash),"coin",p*.065);let _=p*.17;se("h:mode",c.w*.88,k,{shape:"sprite",art:"button",w:_,h:p*.08,color:"secondary",depth:70}),$e("h:mode:t",c.w*.88,k,ws[ne]===0?"MAX":`\xD7${ws[ne]}`,"text",p*.042,70.1),Ye({id:"mode",x:c.w*.88,y:k,w:_,h:p*.09});let C=ce(),z=Math.min(c.w*.3,230),B=Math.max(30,c.h*.05),ae=c.h*.15;if(C.forEach((re,j)=>{let J=c.w/2+(j-(C.length-1)/2)*(z+p*.02),Y=on(i,re)>=1;se(`h:g${j}`,J,ae,{shape:"sprite",art:"panel",w:z,h:B,color:Y?"accent":"panel",depth:70}),se(`h:g${j}:i`,J-z*.36,ae-B*.06,{shape:"sprite",art:rt(re),w:B*.75,h:B*.75,depth:70.1});let M=ht(re),E=Y?"\u2713":re.kind==="cash"?`${vr(M)}/${vr(re.n)}`:re.kind==="level"?`Lv ${M}/${re.n}`:`${M}/${re.n}`;$e(`h:g${j}:t`,J+z*.1,ae-B*.08,E,"text",B*.36,70.1),Se(`h:g${j}:bar`,J+z*.1,ae+B*.3,z*.62,Math.max(4,B*.1),on(i,re),Y?"accent":"coin",70.1);}),i.timed.forEach((re,j)=>{let J=c.w*.9-j*p*.16,Y=re.id==="sale"?"ty_sk_sale":re.id==="invest"?"ty_investor":Pe().art;se(`h:tm${j}`,J-p*.04,c.h*.205,{shape:"sprite",art:Y,w:p*.06,h:p*.06,depth:70}),$e(`h:tm${j}:t`,J+p*.035,c.h*.205,`${Math.ceil(re.left)}`,"secondary",p*.04);}),Ee){let re=Ke();se("h:courier",re.x,re.y+Math.sin(e.time*10)*re.r*.08,{shape:"sprite",art:Ee.def.art,w:re.r*2,h:re.r*2,depth:72}),Ye({id:"courier",x:re.x,y:re.y,w:re.r*2.6,h:re.r*2.6});}let pe=oe(),Me=Te(),qe=c.w*.25,tt=q>=Pe().charge;tt&&se("h:sk:glow",qe,pe,{shape:"circle",r:Me*1.28,color:"secondary",alpha:.5+.3*Math.sin(e.time*7),depth:68.9}),se("h:sk:bg",qe,pe,{shape:"circle",r:Me,color:"panel",alpha:.95,depth:69}),se("h:sk",qe,pe,{shape:"sprite",art:Pe().art,w:Me*1.4,h:Me*1.4,alpha:tt?1:.45,depth:69.2}),Se("h:charge",qe,pe+Me*1.3,Me*2,Math.max(5,Me*.2),q/Pe().charge,"secondary",69),Ye({id:"skill",x:qe,y:pe,w:Me*2.4,h:Me*2.4}),oi(i,3).forEach((re,j)=>{let J=c.w*(.47+j*.18),Y=i.cash>=re.price;se(`h:u${j}:bg`,J,pe,{shape:"circle",r:Me,color:Y?"accent":"panel",alpha:Y?.95:.7,depth:69}),se(`h:u${j}`,J,pe-Me*.08,{shape:"sprite",art:re.def.art,w:Me*1.5,h:Me*1.5,alpha:Y?1:.55,depth:69.2});let M=re.index>=0?i.biz[re.index]:void 0;M&&se(`h:u${j}:b`,J+Me*.7,pe-Me*.6,{shape:"sprite",art:M.def.art,w:Me*.9,h:Me*.9,color:M.def.color,depth:69.3}),$e(`h:u${j}:p`,J,pe+Me*1.3,vr(re.price),Y?"coin":"muted",Me*.42,69.3),Ye({id:`up:${re.key}`,x:J,y:pe,w:Me*2.3,h:Me*2.6});}),(v===null||!e.isAlive(v))&&(v=e.create(),e.set(v,le,{shape:"actor",cast:Ae().cast,h:Me*2.6,pose:"idle",facing:1,depth:20})),e.set(v,F,{x:c.w*.09,y:pe-Me*.1});let pt=e.need(v,le);if(pt.shape==="actor"&&(pt.h=Me*2.6),de){let re=Math.min(c.w*.86,500),j=re*.42,J=c.w/2,Y=c.h*.5;se("h:inv:dim",J,Y,{shape:"rect",w:c.w,h:c.h,color:"#000000",alpha:.35,depth:79}),se("h:inv",J,Y,{shape:"sprite",art:"panel",w:re,h:j,color:"panel",depth:80}),se("h:inv:i",J-re*.34,Y,{shape:"sprite",art:de.def.art,w:j*.62,h:j*.62,depth:80.1});let M=re*.3,E=j*.5,l=ft();se("h:inv:a",J+re*.02,Y-j*.04,{shape:"sprite",art:"button",w:M,h:E,color:"accent",depth:80.1}),se("h:inv:a:c",J+re*.02-M*.28,Y-j*.04,{shape:"sprite",art:"coin",w:E*.4,h:E*.4,depth:80.2}),$e("h:inv:a:t",J+re*.02+M*.1,Y-j*.04,vr(l),"coin",E*.3,80.2),se("h:inv:b",J+re*.33,Y-j*.04,{shape:"sprite",art:"button",w:M,h:E,color:"secondary",depth:80.1}),$e("h:inv:b:t",J+re*.33,Y-j*.04,`\xD7${de.def.mult??2} ${de.def.seconds??30}s`,"text",E*.28,80.2),Se("h:inv:bar",J+re*.17,Y+j*.32,re*.6,Math.max(4,j*.05),de.left/de.def.ttl,"coin",80.1),Ye({id:"inv_now",x:J+re*.02,y:Y-j*.04,w:M,h:E}),Ye({id:"inv_share",x:J+re*.33,y:Y-j*.04,w:M,h:E});}},Qt=()=>{x=[],Ne.clear(),Re(),De(),Ie(),e.vars.ty_buttons=x.map(c=>`${c.id}@${Math.round(c.x)},${Math.round(c.y)}`).join(";");},Xe=()=>{e.vars.cash=Math.floor(i.cash),e.vars.earned=Math.floor(i.earned),e.vars.time_left=D,e.vars.ty_charge=Math.floor(q),e.vars.ty_mode=ws[ne]??1,e.vars.level_progress=ii(i,ce()),e.vars.ty_goals=ce().map(c=>`${c.kind}:${Math.floor(ht(c))}/${c.n}`).join("|");},et=()=>{for(let p of [...h.values(),...m.values()])e.isAlive(p)&&e.destroy(p);h.clear(),m.clear(),v!==null&&e.isAlive(v)&&e.destroy(v),v=null,a=Do(Oo(e,"meta:chapter")||1,o("difficulty"));let c={income:Oo(e,"meta:income"),speed:Oo(e,"meta:speed"),discount:Oo(e,"meta:discount")};i=ks(a.def,c,Math.round(a.cash*(1+Oo(e,"meta:cash")))),Af.set(e,{s:i,level:a}),Bt(e,"board",Be(e).h*.24),D=a.day,O=0,N=0,q=0,Z=false,ye=false,be=8+n.range(0,4),fe=null,Ee=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();},it=c=>{if(ye)return;ye=true;let p=c==="cleared",k=ii(i,ce()),_=p?Math.min(Z?1:3,Ua(D/Math.max(1,a.day))):0,C=Math.round(a.coins*o("coinReward")*(p?[1,1,1.25,1.5][_]:k*.5));C>0&&(Qe(e,"coins",C),e.emit("coin-collected",{value:C})),p&&e.vars["meta:first_clear"]===true&&Qe(e,"coins",a.firstClearGold),e.vars.stars=_,e.vars.score=Math.round(k*1e3)+(p?_*500+Math.floor(D)*10:0),e.vars.reviving=false,fe=null,Ee=null,de=null,Xe(),e.emit(Ut,{reason:c,stats:{chapter:a.level,seconds:Math.floor(O),cleared:p,stars:_,coins:Number(e.vars.coins??0),earned:Math.floor(i.earned),managers:ai(i)}});},dt=()=>{ye||(K(e,{kind:"flash",color:"coin"}),it("cleared"));},mt=()=>{if(e.vars.revive_ready===true&&!Z){e.vars.reviving=true,e.emit(er,{});return}it("out-of-time");},yt=()=>{we()&&(Z=true,e.vars.reviving=false,D+=Xa,K(e,{kind:"flash",color:"coin"}),Xe());},gt=()=>Math.max(Qa(i),a.cash*.05),ft=()=>Math.round(gt()*(de?.def.now??25)),ze=c=>{q=Math.min(Pe().charge,q+vf),e.emit("event-handled",{id:c});},Et=()=>{let c=i.biz.map((B,ae)=>({b:B,i:ae})).filter(B=>B.b.level>0&&B.b.broken===0),p=B=>B.effect==="rush"?!fe&&c.some(ae=>ae.b.rush<=0):B.effect==="break"?!i.biz.some(ae=>ae.broken>0)&&c.some(ae=>ae.b.level>=3):B.effect==="invest"?!de:!Ee,k=a.def.events.filter(B=>s.includes(B)).map(B=>_o.find(ae=>ae.id===B)).filter(B=>!!B&&p(B));if(!k.length)return;let _=k.reduce((B,ae)=>B+ae.weight,0),C=n.range(0,_),z=k.find(B=>(C-=B.weight)<0)??k[0];if(z.effect==="rush"){let B=c.filter(ae=>ae.b.rush<=0);fe={index:B[n.int(0,B.length-1)].i,left:z.ttl,def:z};}else if(z.effect==="break"){let B=c.filter(pe=>pe.b.level>=3),ae=B[n.int(0,B.length-1)];ae.b.broken=z.taps??3,K(e,{kind:"shake",power:.3});}else z.effect==="invest"?de={left:z.ttl,def:z}:Ee={left:z.ttl,def:z};e.emit("event-started",{id:z.id});},Ze=c=>{fe&&(fe.left-=c)<=0&&(fe=null),Ee&&(Ee.left-=c)<=0&&(Ee=null),de&&(de.left-=c)<=0&&(de=null),a.def.events.length&&(be-=c,be<=0&&(Et(),be=n.range(tc[0],tc[1])));},Wt=c=>{let p=i.biz[c];if(!p||p.level<=0)return;let k=_e(c);if(p.broken>0){K(e,{kind:"burst",x:k.x,y:k.y,color:"ground",n:6,size:k.size*.6}),ti(i,c)&&(K(e,{kind:"ring",x:k.x,y:k.y,color:"accent",size:k.size*1.2}),ze("break"));return}fe?.index===c&&(p.rush=fe.def.seconds??10,p.rushMult=fe.def.mult??3,K(e,{kind:"ring",x:k.x,y:k.y,color:"coin",size:k.size*1.4}),K(e,{kind:"pop",x:k.x,y:k.y-k.size*.45,text:`\xD7${p.rushMult}`,color:"coin",size:Math.round(k.size*.3)}),fe=null,ze("rush"));let _=ei(i,c);_<=0||(q=Math.min(Pe().charge,q+kf),Lt(e,"tycoon-collect"),K(e,{kind:"burst",x:k.x,y:k.y,color:"coin",n:8,size:k.size*.7}),K(e,{kind:"pop",x:k.x,y:k.y-k.size*.35,text:`+${vr(_)}`,color:"coin",size:Math.round(k.size*.24)}),e.emit("cycle-collected",{index:c,amount:_}));},hr=c=>{let p=i.biz[c];if(!p)return;let k=Ya(i,c,ee(c)),_=Le(c),C=_.x+_.w/2-_.w*.14;if(!k.ok){K(e,{kind:"shake",power:.1});return}Lt(e,"tycoon-buy");let z=_e(c);K(e,{kind:"ring",x:z.x,y:z.y,color:"coin",size:z.size*1.1}),K(e,{kind:"burst",x:C,y:_.y,color:"accent",n:5,size:_.h*.5}),e.emit("business-bought",{id:p.def.id,level:p.level});for(let B of k.milestones)K(e,{kind:"flash",color:"coin"}),K(e,{kind:"pop",x:z.x,y:z.y-z.size*.5,text:`\u2605 ${B}`,color:"coin",size:Math.round(z.size*.3)}),e.emit("milestone",{id:p.def.id,at:B});},Nt=c=>{let p=i.biz[c];if(!p||!Ja(i,c))return;Lt(e,"tycoon-manager");let k=_e(c);K(e,{kind:"ring",x:k.x,y:k.y,color:"secondary",size:k.size*1.3}),K(e,{kind:"pop",x:k.x,y:k.y-k.size*.5,text:"\u2605",color:"secondary",size:Math.round(k.size*.35)}),e.emit("manager-hired",{id:p.def.id});},ur=(c,p,k)=>{si(i,c)&&(Lt(e,"tycoon-upgrade"),K(e,{kind:"ring",x:p,y:k,color:"accent",size:Te()*2.6}),K(e,{kind:"flash",color:"accent"}),e.emit("upgrade-bought",{key:c}));},Tt=()=>{let c=Pe();if(q<c.charge)return false;let p=1+Oo(e,"meta:skill");if(q=0,v!==null&&Ge(e,v,"cheer"),K(e,{kind:"flash",color:"secondary"}),c.effect==="rush")ri(i,{id:"skill",left:(c.seconds??12)*p,income:c.mult??5,price:1});else if(c.effect==="sale")ri(i,{id:"sale",left:(c.seconds??15)*p,income:1,price:c.mult??.5});else {let k=dc(i,Math.max(1,Math.round((c.cycles??8)*p))),_=ke();K(e,{kind:"pop",x:_.w/2,y:_.h*.16,text:`+${vr(k)}`,color:"coin",size:Math.round(_.U*.07)}),i.biz.forEach((C,z)=>{if(C.level<=0)return;let B=_e(z);K(e,{kind:"burst",x:B.x,y:B.y,color:"coin",n:10,size:B.size*.8});});}return e.emit("skill-cast",{id:c.id}),Lt(e,"tycoon-skill"),true},T=()=>{if(!Ee)return;let c=Ke(),p=Math.round(gt()*(Ee.def.now??15));fc(i,p);let k=Math.round((Ee.def.coins??0)*o("coinReward"));k>0&&(Qe(e,"coins",k),e.emit("coin-collected",{value:k})),K(e,{kind:"burst",x:c.x,y:c.y,color:"coin",n:14,size:c.r*2}),K(e,{kind:"pop",x:c.x,y:c.y+c.r*1.4,text:`+${vr(p)}`,color:"coin",size:Math.round(c.r*.7)}),Ee=null,ze("courier");},H=c=>{if(!de)return;let p=de.def;c?ri(i,{id:"invest",left:p.seconds??30,income:p.mult??2,price:1}):fc(i,ft()),de=null,K(e,{kind:"flash",color:"coin"}),ze("invest");},u=(c,p,k)=>x.find(_=>(!k||_.id.startsWith(k))&&Math.abs(c-_.x)<=_.w/2&&Math.abs(p-_.y)<=_.h/2);e.on(zt,c=>{let p=c;if(p.type!=="tap"||!ot(e)||hn(e)||ye||we())return;Ht(e),N=0;let k=de?u(p.x,p.y,"inv_")??u(p.x,p.y):u(p.x,p.y,"courier")??u(p.x,p.y);k&&(k.id==="inv_now"?H(false):k.id==="inv_share"?H(true):k.id==="courier"?T():k.id==="mode"?ne=(ne+1)%ws.length:k.id==="skill"?Tt():k.id.startsWith("up:")?ur(k.id.slice(3),k.x,k.y):k.id.startsWith("biz")?Wt(Number(k.id.slice(3))):k.id.startsWith("buy")?hr(Number(k.id.slice(3))):k.id.startsWith("mgr")&&Nt(Number(k.id.slice(3))),Xe(),Ms(i,ce())&&dt());}),e.on(qt,()=>{et(),e.vars.level=a.level;}),e.on(Zt,et),e.on(tr,yt),e.on(rr,()=>{we()&&(e.vars.reviving=false,it("out-of-time"));}),e.on(Xt,c=>{Ne.clear(),Ie(),x=[],e.vars.ty_buttons="",v!==null&&e.isAlive(v)&&at(e,v,c.reason==="cleared"?"dance":"idle");}),e.on(Ft,()=>Bt(e,"board",Be(e).h*.24));let f=c=>{if(!c)return;let p=c.kind==="collect"||c.kind==="fix"?`biz${c.index}`:c.kind==="buy"?`buy${c.index}`:c.kind==="hire"?`mgr${c.index}`:`up:${c.key}`;return x.find(k=>k.id===p)},b=c=>{let p=ke().U,k=i.biz.findIndex(_=>_.ready);if(!vt(c,"tycoon-collect")&&k>=0){let _=_e(k);return kt(c,"tap",_,void 0,_.size*.8)}if(!vt(c,"tycoon-buy")){let _=i.biz.findIndex(z=>i.cash>=vn(i,z,ee(i.biz.indexOf(z)))),C=x.find(z=>z.id===`buy${_}`);if(_>=0&&C)return kt(c,"tap",C,void 0,C.h)}if(!vt(c,"tycoon-manager")){let _=i.biz.findIndex(z=>z.level>0&&!z.manager&&i.cash>=To(i,z)),C=x.find(z=>z.id===`mgr${_}`);if(_>=0&&C)return kt(c,"tap",C,void 0,C.w)}if(q>=Pe().charge&&!vt(c,"tycoon-skill")){let _=x.find(C=>C.id==="skill");if(_)return kt(c,"tap",_,void 0,_.w)}if(N>6){let _=f(li(i,ce()));_&&kt(c,"tap",_,void 0,Math.min(_.w,p*.18));}};e.addSystem({id:"tycoon",order:0,run(c,p){if(!(!ot(c)||ye)){if(!we()){O+=p,N+=p,D=Math.max(0,D-p);for(let k of ni(i,p).paid)k.amount<=0||c.emit("cycle-collected",{index:k.index,amount:k.amount});q=Math.min(Pe().charge,q+p),Ze(p);}if(Qt(),Xe(),!we()){if(Ms(i,ce()))return dt();_r(c)||b(c),D<=0&&mt();}}}}),et();}};var sn=(e,t,r,o,n,s,a,i,h)=>({en:e,ru:t,kz:r,zh:o,ko:n,ja:s,hi:a,pt:i,de:h}),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 h=ui(Kf(s,r));if(i.length===0){s.op==="set"&&an(h)?o=h:s.op==="merge"&&an(h)?o=hi(o,h):n.push(a);return}let m=o;for(let x=0;x<i.length-1;x++){let D=Ru(m,i[x],s.ifExists!==true);if(D===void 0){n.push(a);return}m=D;}let v=i[i.length-1];if(!an(m)){n.push(a);return}if(v.match){let x=m[v.key];if(!Array.isArray(x)){n.push(a);return}let D=x.findIndex(O=>an(O)&&String(O[v.match.field])===v.match.value);if(D<0){n.push(a);return}s.op==="set"?x[D]=h:s.op==="merge"?x[D]=hi(x[D],h):s.op==="unset"?x.splice(D,1):n.push(a);return}if(s.ifExists===true&&m[v.key]===void 0){n.push(a);return}switch(s.op){case "set":m[v.key]=h;break;case "merge":m[v.key]=m[v.key]===void 0?h:hi(m[v.key],h);break;case "unset":delete m[v.key];break;case "add":case "remove":{let x=Array.isArray(h)?h:[h],D=m[v.key];if(D!==void 0&&!Array.isArray(D)){n.push(a);return}let O=D?[...D]:[];if(s.op==="add")for(let N of x)O.some(q=>Gf(q,N))||O.push(N);else for(let N of x){let q=O.findIndex(ne=>Gf(ne,N));q>=0&&O.splice(q,1);}m[v.key]=O;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),h=(a+i)/2;if(a===i)return [0,0,h];let m=a-i,v=h>.5?m/(2-a-i):m/(a+i),x=a===o?(n-s)/m+(n<s?6:0):a===n?(s-o)/m+2:(o-n)/m+4;return x*=60,[x,v,h]}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=h=>{let m=h;m<0&&(m+=1),m>1&&(m-=1);let v=s<.5?s*(1+n):s+n-s*n,x=2*s-v;return m<1/6?x+(v-x)*6*m:m<1/2?v:m<2/3?x+(v-x)*(2/3-m)*6:x},i=h=>Math.round(h*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 Ce=(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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("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:Ce("Classic","\u041A\u043B\u0430\u0441\u0441\u0438\u043A\u0430"),what:"The pack's own colours.",dh:0,sat:1,dl:0},{id:"dawn",title:Ce("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:Ce("Night","\u041D\u043E\u0447\u044C"),what:"Darker and bluer, a night mood.",dh:-35,sat:.9,dl:-0.07},{id:"ember",title:Ce("Ember","\u0423\u0433\u043B\u0438"),what:"Shifted to red and orange, hot and dangerous.",dh:-60,sat:1.15,dl:0},{id:"frost",title:Ce("Frost","\u0418\u043D\u0435\u0439"),what:"Shifted to cyan and pale blue, cold and icy.",dh:140,sat:.8,dl:.05},{id:"toxic",title:Ce("Toxic","\u042F\u0434"),what:"Shifted to acid green and yellow, toxic.",dh:70,sat:1.25,dl:0},{id:"royal",title:Ce("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:Ce("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:Ce(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:Ce(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:Ce(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,G=(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}:{}}}),Kt=(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:G("Interface colours","\u0426\u0432\u0435\u0442\u0430 \u0438\u043D\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430"),hint:G("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:G("Screen pattern","\u0423\u0437\u043E\u0440 \u0444\u043E\u043D\u0430"),hint:G("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:G("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:G("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:G("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:G("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:G("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:G("Animations","\u0410\u043D\u0438\u043C\u0430\u0446\u0438\u0438"),question:"How lively should the interface animations be?",kind:"choice",options:[{id:"calm",title:G("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:G("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:G("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:G("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:G("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:G("World and colours of the game","\u041C\u0438\u0440 \u0438 \u0446\u0432\u0435\u0442\u0430 \u0438\u0433\u0440\u044B"),hint:G("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:G("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:G("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:G(t,r),what:o,patches:[{section:"GameSpec",op:"set",path:"cast.hero.races",value:[e]}]}))}],Hu=[{id:"feel.difficulty",group:"feel",title:G("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:[G("Very easy","\u041E\u0447\u0435\u043D\u044C \u043B\u0435\u0433\u043A\u043E"),G("Easy","\u041B\u0435\u0433\u043A\u043E"),G("Balanced","\u0421\u0431\u0430\u043B\u0430\u043D\u0441\u0438\u0440\u043E\u0432\u0430\u043D\u043D\u043E"),G("Hard","\u0421\u043B\u043E\u0436\u043D\u043E"),G("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:G("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:[G("Stingy","\u0421\u043A\u0443\u043F\u043E"),G("Modest","\u0421\u043A\u0440\u043E\u043C\u043D\u043E"),G("Normal","\u041E\u0431\u044B\u0447\u043D\u043E"),G("Generous","\u0429\u0435\u0434\u0440\u043E"),G("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:G("Lanes","\u041F\u043E\u043B\u043E\u0441\u044B"),for:{modules:["kit-game"],presets:["runner"]},question:"How wide should the running track be?",kind:"score",levelTitles:[G("2 lanes","2 \u043F\u043E\u043B\u043E\u0441\u044B"),G("3 lanes","3 \u043F\u043E\u043B\u043E\u0441\u044B"),G("4 lanes","4 \u043F\u043E\u043B\u043E\u0441\u044B"),G("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:G("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:[G("One hit","\u041E\u0434\u0438\u043D \u0443\u0434\u0430\u0440"),G("A few","\u041D\u0435\u0441\u043A\u043E\u043B\u044C\u043A\u043E"),G("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:G("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:[G("Very short","\u041E\u0447\u0435\u043D\u044C \u043A\u043E\u0440\u043E\u0442\u043A\u0438\u0435"),G("Short","\u041A\u043E\u0440\u043E\u0442\u043A\u0438\u0435"),G("Normal","\u041E\u0431\u044B\u0447\u043D\u044B\u0435"),G("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:G("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:G("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:G("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"]),Kt("powers",["flight"])]},{id:"coins",title:G("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"]),Kt("powers",["shield","dash","flight"])]},{id:"hardcore",title:G("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"]),Kt("powers",["shield","flight"])]}]},{id:"feel.runner.obstacles",group:"feel",title:G("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:G("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:G("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"]),Kt("obstacles",["pit","rock"])]},{id:"wild",title:G("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"]),Kt("obstacles",["mover","train"])]},{id:"simple",title:G("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"]),Kt("obstacles",["mover","train","rock"])]}]},{id:"feel.platformer.lives",group:"feel",title:G("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:[G("One hit","\u041E\u0434\u0438\u043D \u0443\u0434\u0430\u0440"),G("A few hearts","\u041D\u0435\u0441\u043A\u043E\u043B\u044C\u043A\u043E \u0441\u0435\u0440\u0434\u0435\u0446"),G("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:G("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:G("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:[G("2 minutes","2 \u043C\u0438\u043D\u0443\u0442\u044B"),G("5 minutes","5 \u043C\u0438\u043D\u0443\u0442"),G("10 minutes","10 \u043C\u0438\u043D\u0443\u0442"),G("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:G("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:G("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:G("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"]),Kt("foes",["archer","bomber"])]},{id:"army",title:G("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"]),Kt("foes",["swarm","bomber"])]},{id:"chaos",title:G("Chaos","\u0425\u0430\u043E\u0441"),what:"Swarms, bombers and chargers: fast, explosive, crazy.",patches:[wt("foes",["swarm","charger","bomber","grunt"]),Kt("foes",["archer","brute"])]}]},{id:"feel.td.lives",group:"feel",title:G("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:[G("Very few","\u041E\u0447\u0435\u043D\u044C \u043C\u0430\u043B\u043E"),G("Some","\u0421\u0440\u0435\u0434\u043D\u0435"),G("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:G("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:G("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:G("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"]),Kt("foes",["flyer"])]},{id:"simple",title:G("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"]),Kt("foes",["shaman","healer","splitter"])]},{id:"swarm",title:G("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"]),Kt("foes",["brute","shaman"])]}]},{id:"feel.survivors.weapons",group:"feel",title:G("Weapons to find","\u041E\u0440\u0443\u0436\u0438\u0435 \u0432 \u0437\u0430\u0431\u0435\u0433\u0435"),hint:G("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:G("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:G("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"]),Kt("weapons",["blades","aura","boomerang"])]},{id:"magic",title:G("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"]),Kt("weapons",["blaster","drone"])]},{id:"classic",title:G("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"]),Kt("weapons",["aura","lightning","drone"])]}]},{id:"feel.tycoon.events",group:"feel",title:G("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:G("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:G("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"]),Kt("events",["break"])]},{id:"hands-on",title:G("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"]),Kt("events",["invest"])]},{id:"minimal",title:G("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"]),Kt("events",["break","invest","courier"])]}]}],Wu=(e,t)=>({Type:"VirtualCurrency",CurrencyID:e,Amount:t}),bi=(e,t,r,o,n)=>({id:e,title:G(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,h])=>Wu(i,h))}))}),Lc=(e,t)=>`StoreOffers.${e}.${t}`,ju=[{id:"economy.shop-ad-gems",group:"economy",title:G("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:[G("A few","\u041C\u0430\u043B\u043E"),G("Some","\u0421\u0440\u0435\u0434\u043D\u0435"),G("A handful","\u041F\u0440\u0438\u043B\u0438\u0447\u043D\u043E"),G("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:G("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:[G("A few times","\u041D\u0435\u0441\u043A\u043E\u043B\u044C\u043A\u043E \u0440\u0430\u0437"),G("About ten","\u041E\u043A\u043E\u043B\u043E \u0434\u0435\u0441\u044F\u0442\u0438"),G("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:G("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:[G("Small","\u041C\u0430\u043B\u0435\u043D\u044C\u043A\u0438\u0439"),G("Normal","\u041E\u0431\u044B\u0447\u043D\u044B\u0439"),G("Big","\u0411\u043E\u043B\u044C\u0448\u043E\u0439"),G("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:G("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:[G("A few","\u041C\u0430\u043B\u043E"),G("Some","\u0421\u0440\u0435\u0434\u043D\u0435"),G("Comfortable","\u041A\u043E\u043C\u0444\u043E\u0440\u0442\u043D\u043E"),G("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:G("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:G("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:[G("x2","x2"),G("x3","x3"),G("x4","x4"),G("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:G("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:[G("x3","x3"),G("x5","x5"),G("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:G("Price of VIP","\u0426\u0435\u043D\u0430 VIP"),for:{sections:["Premium"]},question:"How expensive should the VIP pass be, in gems?",kind:"score",levelTitles:[G("Cheap","\u0414\u0451\u0448\u0435\u0432\u043E"),G("Normal","\u041E\u0431\u044B\u0447\u043D\u043E"),G("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:G("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]],h=(m,v)=>({section:"TimedEvent",op:"set",path:`${rp}.${m}`,value:v});return {id:e.id,title:G(t,r),what:e.what,patches:[h("DisplayName",t),h("Description",s),h("Content.DisplayName",t),h("Content.Description",s),h("Content.Token.DisplayName",o),...i.map(([m,v])=>h(`Content.Milestones.${m}.DisplayName`,`${v} ${e.unit[0]}`)),h("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:G(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:G("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:G("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:G("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:[G("Slow","\u041C\u0435\u0434\u043B\u0435\u043D\u043D\u043E"),G("Normal","\u041E\u0431\u044B\u0447\u043D\u043E"),G("Fast","\u0411\u044B\u0441\u0442\u0440\u043E"),G("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:G("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:G("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:[G("A few minutes","\u041F\u0430\u0440\u0430 \u043C\u0438\u043D\u0443\u0442"),G("Short","\u041A\u043E\u0440\u043E\u0442\u043A\u043E"),G("Normal","\u041E\u0431\u044B\u0447\u043D\u043E"),G("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:G("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:[G("Small","\u041C\u0430\u043B\u0435\u043D\u044C\u043A\u0438\u0435"),G("Normal","\u041E\u0431\u044B\u0447\u043D\u044B\u0435"),G("Big","\u0411\u043E\u043B\u044C\u0448\u0438\u0435"),G("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:G("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:G(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:G(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:G("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:G("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=sr;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=ar;exports.EFFECTS=Bo;exports.ENEMIES=Bn;exports.ENGINES=Ds;exports.ENTRY_ID_RE=Oc;exports.ExprError=cr;exports.FOES=tn;exports.FUNCTIONS=$i;exports.FX_TOPIC=Oi;exports.Foe=We;exports.GIVE_UP=rr;exports.Gem=yn;exports.HEROES=ko;exports.HERO_LOOK_OPTIONS=Zf;exports.INPUT_TOPIC=zt;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=fr;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=tr;exports.REVIVE_GEMS=sf;exports.REVIVE_OFFER=er;exports.ROOMS=Ma;exports.ROOM_ROWS=Gt;exports.ROUND_ENDED=Xt;exports.ROUND_OVER=Ut;exports.ROUND_STARTED=qt;exports.RUNNER_CHARACTER=ji;exports.RUNNER_HEROES=no;exports.RUNNER_LEVELS=Qo;exports.RUNNER_META=ud;exports.RUNNER_META_STATS=Vi;exports.Raider=Oe;exports.RoadItem=_t;exports.Runner=Xr;exports.SELL_SHARE=ps;exports.SHOW_START=Zt;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=ut;exports.Tower=kr;exports.Transform=F;exports.TyManager=hc;exports.UI_THEMES=Uf;exports.UPGRADE_PICK=Bl;exports.UPGRADE_PICKED=zl;exports.UPGRADE_REROLL=Hl;exports.VIEW_RESIZED_TOPIC=Ft;exports.Visual=le;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=Ge;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=st;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=pr;exports.evalNumber=wi;exports.fantasyPack=mc;exports.findMatches=io;exports.fx=K;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=Bt;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=at;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=Be;
|