๐ŸŽฎArcadeLab

Worldline

by GlitchKnight20
262 lines31.4 KB
โ–ถ Play
// ๊ตญ๊ฐ€ ์™ธ๊ตยท์ „์Ÿ ์‹œ๋ฎฌ๋ ˆ์ด์…˜ โ€” GDevelop "JavaScript ์ฝ”๋“œ ์‹คํ–‰" ์•ก์…˜์šฉ (๋‹จ์ผ ์Šคํฌ๋ฆฝํŠธ)
// ์‚ฌ์šฉ๋ฒ•: ์ด๋ฒคํŠธ ์‹œํŠธ โ†’ ์กฐ๊ฑด "์”ฌ ์‹œ์ž‘ ์‹œ" โ†’ ์•ก์…˜ "Execute a JavaScript code" ์— ์ด ํŒŒ์ผ ์ „์ฒด๋ฅผ ๋ถ™์—ฌ๋„ฃ๊ธฐ
(function(){
if(window.NS)return;
const rnd=Math.random,n=x=>Math.round(x),cl=(x,a,b)=>Math.max(a,Math.min(b,x));
const RN=['๐ŸŒพ๋ฐ€','โ›๏ธ์ฒ ','๐ŸŸ์ˆ˜์‚ฐ','๐Ÿ›ข๏ธ์„์œ ','๐Ÿชต๋ชฉ์žฌ','๐ŸŽ๊ณผ์ผ'],RP=[4,8,5,12,3,6],RC=['#e8c547','#c5ced8','#5ad0e0','#222','#7a4a24','#ff5d6c'];
const NM=['์•„๋ฅด์นด','๋ฒจ๋กœ','์นด์—˜','๋„๋ฅธ','์—์Šคํƒ€','ํŽ ๋ผ','๊ทธ๋ ˆ์ด','ํžˆ๋กœ'],CL=['#e5484d','#3e8bff','#d98e1c','#a96bff','#2fbf71','#e0649c','#27a3a3','#9aab2a'];
const TY=['๊ณต๊ฒฉ์ ','ํ‰ํ™”์ ','๋ฌด์—ญ์ค‘์‹ฌ','์ž์›์ค‘์‹ฌ','๊ตฐ์‚ฌ์ค‘์‹ฌ','์™ธ๊ต์ค‘์‹ฌ','๊ณ ๋ฆฝ์ฃผ์˜'];
// [์ „์Ÿ, ๊ตฐ๋น„, ๋™๋งน, ์„ ๋ฌผ, ๋ฌด์—ญํ˜‘์ •, ํŒ๋งค]
const PR=[[.07,.4,.03,0,.02,.05],[0,.1,.05,.06,.04,.05],[.005,.2,.04,.04,.12,.15],[.01,.2,.03,.02,.06,.3],[.05,.6,.03,0,.02,.05],[.005,.2,.09,.12,.06,.08],[.01,.2,0,0,0,.02]];
const MK={trade:'๊ต์—ญ',help:'์š”์ฒญ ์Šน์ธ',refuse:'์š”์ฒญ ๊ฑฐ์ ˆ',gift:'์„ ๋ฌผ',firststrike:'์„ ์ œ๊ณต๊ฒฉ',brk:'์กฐ์•ฝ ์œ„๋ฐ˜',aid:'์ „ํ›„ ์ง€์›',nuke:'ํ•ต ์‚ฌ์šฉ',pact:'๋ฌด์—ญํ˜‘์ •'};
const GW=40,GH=26,NC=8,CS=11,SK='nationsim-v1';
let own,reg,RG,coast,C,rel,mem,wars,pend,logs,chat,hist,pacts,turn,aid,H,me,tab='e',spd=0,acc=0,mute=false,showChat=false,cen,fx=[],frame=0,sp=[];
const sel={r:0,q:25,d:150,g:-1};
const wf=(a,b)=>wars.find(w=>(w.a==a&&w.b==b)||(w.a==b&&w.b==a));
const L=(t,m)=>{logs.unshift(`<b>[${t}]</b> T${turn} ${m}`);if(logs.length>80)logs.pop()};
const CH=m=>{chat.unshift(`T${turn} ${m}`);if(chat.length>80)chat.pop()};
const rem=(a,b,k,v)=>{mem[a][b].push({T:turn,k,v});if(mem[a][b].length>14)mem[a][b].shift();rel[a][b]=cl(rel[a][b]+v,-100,100)};
// ---------- ์†Œ๋ฆฌ ----------
let AC;function snd(k){if(mute)return;try{AC=AC||new(window.AudioContext||window.webkitAudioContext)();
const f={ok:[660,880],no:[300,200],war:[180,120,90],nuke:[60,40,30,25],click:[500],turn:[440,550]}[k];
f.forEach((fr,i)=>{const o=AC.createOscillator(),g=AC.createGain();o.type=(k=='nuke'||k=='war')?'sawtooth':'square';o.frequency.value=fr;g.gain.value=.05;
o.connect(g);g.connect(AC.destination);const t=AC.currentTime+i*.09;o.start(t);g.gain.exponentialRampToValueAtTime(.001,t+.14);o.stop(t+.15)})}catch(e){}}
// ---------- UI ๋ผˆ๋Œ€ ----------
const root=document.createElement('div');root.id='ns';
root.innerHTML=`<style>
#ns{position:fixed;inset:0;z-index:99999;background:#0b1a2b;color:#e8f0fa;font:13px system-ui,sans-serif;display:flex;flex-direction:column;padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px)}
#ns *{box-sizing:border-box}#ns canvas{width:100%;display:block;flex:none;image-rendering:pixelated}
#ns button{border:1px solid #2a4160;border-radius:7px;background:#22395a;color:#e8f0fa;font:inherit;padding:5px 8px;margin:2px 2px 0 0}
#ns button.on{background:#3b82f6}#nh{padding:6px 8px;background:#14263d;font-weight:700}#ni{padding:3px 8px;font-size:12px;color:#9ab;min-height:20px}
#np .cd{margin:3px 8px;padding:6px;background:#3a2a14;border:1px solid #c88a2b;border-radius:8px}
#nt{display:flex;background:#14263d}#nt button{flex:1;border-radius:0;margin:0;padding:8px 0;border:0;background:none}#nt button.on{background:#2b4a78}
#nb{flex:1;min-height:0;overflow:auto;padding:6px 10px}#ns .r{padding:6px 0;border-bottom:1px solid #2a4160}
#ns select,#ns input{background:#0e1d30;color:#e8f0fa;border:1px solid #2a4160;border-radius:6px;padding:4px;font:inherit;width:auto}#ns input{width:70px}
#nx{background:#3b82f6!important;padding:12px!important;border-radius:0!important;margin:0!important;font-size:15px;font-weight:700}
</style><div id=nh></div><canvas id=nc width=${GW*CS} height=${GH*CS}></canvas><div id=ni>์ง€๋„๋ฅผ ํƒญํ•˜๋ฉด ์ง€์—ญ ์ •๋ณด๊ฐ€ ๋ณด์—ฌ์š”</div><div id=np></div>
<div id=nt></div><div id=nb></div><button id=nx onclick="NS.act.nx()">๋‹ค์Œ ํ„ด โ–ถ</button>`;
document.body.appendChild(root);
const $=i=>root.querySelector('#'+i),cv=$('nc'),ctx=cv.getContext('2d');
// ---------- ์„ธ๊ณ„ ์ƒ์„ฑ ----------
function mkCoast(){coast=own.map((o,i)=>{if(o<0)return false;const x=i%GW,y=i/GW|0;return(x>0&&own[i-1]<0)||(x<GW-1&&own[i+1]<0)||(y>0&&own[i-GW]<0)||(y<GH-1&&own[i+GW]<0)})}
function gen(){const sd=[];for(let i=0;i<NC;i++){const cx=(i%4)*10+5,cy=(i>>2)*13+6.5;[[-3,-3],[3,-2],[0,4]].forEach(o=>sd.push({x:cx+o[0]+rnd()*2-1,y:cy+o[1]+rnd()*2-1,o:i}))}
const a=rnd()*6,b=rnd()*6;own=[];reg=[];
for(let y=0;y<GH;y++)for(let x=0;x<GW;x++){
const sea=x<1||y<1||x>=GW-1||y>=GH-1||(Math.abs(y-12.5+Math.sin(x*.45+a)*1.4)<.8&&Math.sin(x*.9+b)>-.3)||Math.sin(x*.5+a)*Math.sin(y*.6+b)>.85;
if(sea){own.push(-1);reg.push(-1);continue}
let bi=0,bd=1e9;sd.forEach((s,i)=>{const d=Math.hypot(s.x-x,s.y-y);if(d<bd){bd=d;bi=i}});own.push(sd[bi].o);reg.push(bi)}
RG=sd.map((s,i)=>({id:i,o:s.o,res:0,dmg:0,n:NM[s.o]+' '+['๋ถ','๋™','๋‚จ'][i%3]+'๋ถ€'}));mkCoast()}
function newGame(){gen();
C=NM.map((nm,i)=>({i,n:nm,c:CL[i],st:Array(6).fill(40),D:i?800:1000,tp:50,mil:60,df:0,sh:2,bm:1,ms:2,al:-1,ty:i?rnd()*7|0:-1,pop:0,blk:0,ind:0,si:0,di:0,wc:0}));
C.forEach(c=>{const pl=[0,1,2,3,4,5].sort(()=>rnd()-.5);for(let j=0;j<3;j++)RG[c.i*3+j].res=pl[j]});
rel=C.map(()=>C.map(()=>n(rnd()*30-8)));mem=C.map(()=>C.map(()=>[]));wars=[];pend=[];logs=[];chat=[];hist=[];pacts=[];turn=1;aid=0;
H=C.map((c,i)=>i==0);me=0;stats();C.forEach(c=>c.pop=c.k*1000);fx=[];
L('์‹œ์Šคํ…œ','๋‹น์‹ ์€ ์•„๋ฅด์นด๋ฅผ ์ด๋•๋‹ˆ๋‹ค. ์ง€์—ญ๋งˆ๋‹ค ํŠน์‚ฐํ’ˆ์ด ๋‹ฌ๋ผ ์ž์›์ด ๋ถ€์กฑํ•ด์š” โ€” ์ด์›ƒ๊ณผ ๊ต์—ญํ•˜์„ธ์š”.');render()}
function stats(){C.forEach(c=>{c.k=0;c.p=[0,0,0,0,0,0]});const sx=Array(NC).fill(0),sy=Array(NC).fill(0);
own.forEach((o,i)=>{if(o<0)return;const c=C[o];c.k++;sx[o]+=i%GW;sy[o]+=i/GW|0;if(!RG[reg[i]].dmg)c.p[RG[reg[i]].res]++});
cen=C.map(c=>c.k?[(sx[c.i]/c.k+.5)*CS,(sy[c.i]/c.k+.5)*CS]:[0,0]);
sp=C.map(c=>{const l=[];own.forEach((o,i)=>{if(o==c.i&&coast[i])l.push(i)});return l.length?[l[0],l[l.length>>1],l[l.length-1]]:[]})}
function cand(a,b,am){const r=[];for(let i=0;i<own.length;i++){if(own[i]!=b)continue;if(am){if(coast[i])r.push(i);continue}
const x=i%GW,y=i/GW|0;if((x>0&&own[i-1]==a)||(x<GW-1&&own[i+1]==a)||(y>0&&own[i-GW]==a)||(y<GH-1&&own[i+GW]==a))r.push(i)}return r}
function take(a,b,am,k){let g=0;for(let j=0;j<k;j++){const c=cand(a,b,am);if(!c.length)break;own[c[rnd()*c.length|0]]=a;g++}return g}
function adj(a){const s=new Set();for(let i=0;i<own.length;i++){if(own[i]!=a)continue;const x=i%GW,y=i/GW|0;
[x>0?i-1:-1,x<GW-1?i+1:-1,y>0?i-GW:-1,y<GH-1?i+GW:-1].forEach(j=>{if(j>=0&&own[j]>=0&&own[j]!=a)s.add(own[j])})}return[...s]}
function regsOf(e){const m={};own.forEach((o,i)=>{if(o==e)m[reg[i]]=(m[reg[i]]||0)+1});return Object.keys(m).map(Number).sort((a,b)=>m[b]-m[a])}
const rpos=g=>{const i=reg.findIndex((r,j)=>r==g&&own[j]==RG[g].o);const k=i<0?reg.indexOf(g):i;return[(k%GW+.5)*CS,((k/GW|0)+.5)*CS]};
const fxa=(k,p,q)=>fx.push({k,x0:p[0],y0:p[1],x1:q[0],y1:q[1],t:0,d:k=='nuke'?30:18});
// ---------- ๊ฒฝ์ œยท์™ธ๊ต ----------
const acc_=(p,f,ratio)=>C[p].blk>0||C[f].blk>0?0:cl(.3+rel[p][f]/150+C[p].tp/250+(ratio-1)*.8-(C[p].ty==6?.25:0),.05,.95);
function trade(b,s,r,q,d){C[s].st[r]-=q;C[b].st[r]+=q;C[b].D-=d;C[s].D+=d;rem(b,s,'trade',3);rem(s,b,'trade',3);C[b].tp+=.5;C[s].tp+=.5}
function ally(a,b){const A=C[a],B=C[b];if(A.al>=0&&B.al>=0)return 0;if(A.al<0&&B.al<0)A.al=B.al=aid++;else if(A.al<0)A.al=B.al;else B.al=A.al;
L('์—ฐํ•ฉ',`${A.n} ยท ${B.n} ์—ฐํ•ฉ ๊ฒฐ์„ฑ/๊ฐ€์ž…`);return 1}
function declare(a,b,force,skip){if(wf(a,b)||!C[a].k||!C[b].k)return;const A=C[a];
if(!force&&!skip){const ids=A.al>=0?C.filter(v=>v.al==A.al&&v.i!=a&&v.i!=b&&v.k).map(v=>v.i):[...new Set([...adj(a),...adj(b)])].filter(v=>v!=a&&v!=b&&C[v].k);
const vo=v=>rel[v][b]<rel[v][a]+8;
if(A.al>=0&&A.al==C[me].al&&H[me]&&a!=me&&ids.includes(me)){pend.push({t:'wv',to:me,a,b,ids,y0:ids.filter(v=>v!=me&&vo(v)).length});return}
const yes=ids.filter(vo).length,ok=!ids.length||yes*2>=ids.length;
if(a==me||b==me||H[a]||H[b])L('์Šน์ธ',`${A.al>=0?'์—ฐํ•ฉ':'์ฃผ๋ณ€๊ตญ'} ํˆฌํ‘œ ${yes}:${ids.length-yes} โ†’ ${ok?'์Šน์ธ':'๋ถ€๊ฒฐ'}`);
if(!ok){if(H[a]||!(A.ty==0&&rnd()<.3))return;force=true}}
pacts=pacts.filter(p=>{if((p.a==a&&p.b==b)||(p.a==b&&p.b==a)){A.tp=Math.max(0,A.tp-8);rem(b,a,'brk',-30);L('์กฐ์•ฝ',`${A.n}์ด(๊ฐ€) ๋ฌด์—ญํ˜‘์ •์„ ํŒŒ๊ธฐ(์•ฝ์† ์œ„๋ฐ˜)`);return false}return true});
const mk=(x,y)=>({a:x,b:y,agg:a,s:0,pu:{},k:[C[x].k,C[y].k],pre:!!force,T:turn});wars.push(mk(a,b));
if(force){A.tp=Math.max(0,A.tp-25);C.forEach(v=>{if(v.i!=a)rel[v.i][a]-=15});rem(b,a,'firststrike',-30);
const t=`${A.n} โ†’ ${C[b].n} ์„ ์ œ๊ณต๊ฒฉ`;hist.unshift(`T${turn} ${t}`);L('๊ตญ์ œ',`๐Ÿšจ <b>${t}</b>! (๋ฐฉ์–ด๊ตญ์€ ์Šน์ธ ์—†์ด ์ฆ‰์‹œ ๋ฐฉ์–ด ๊ฐ€๋Šฅ)`)}
else{hist.unshift(`T${turn} ${A.n} โ†’ ${C[b].n} ์Šน์ธ ์ „์Ÿ`);L('๊ตญ์ œ',`${A.n}์ด(๊ฐ€) ์Šน์ธ์„ ๋ฐ›์•„ ${C[b].n}๊ณผ(์™€) ๊ฐœ์ „`)}
snd('war');
C.forEach(v=>{if(!v.k||v.i==a||v.i==b||v.al<0)return;
if(v.al==C[b].al&&!wf(a,v.i)&&(H[v.i]||rel[v.i][a]<25)){wars.push(mk(a,v.i));L('์—ฐํ•ฉ',`${v.n}์ด(๊ฐ€) ์—ฐํ•ฉ๊ตญ ${C[b].n}์„(๋ฅผ) ์œ„ํ•ด ์ฐธ์ „`)}
else if(!force&&v.al==A.al&&v.al!=C[b].al&&!wf(v.i,b)&&rel[v.i][b]<10){wars.push(mk(v.i,b));L('์—ฐํ•ฉ',`${v.n}์ด(๊ฐ€) ์—ฐํ•ฉ๊ตญ ${A.n}์„(๋ฅผ) ์ง€์›ํ•ด ์ฐธ์ „`)}})}
function endWar(w,win){wars=wars.filter(x=>x!=w);
if(win<0){L('์ „์Ÿ',`${C[w.a].n}-${C[w.b].n} ์ „์Ÿ์ด ๋ฌด์Šน๋ถ€๋กœ ์ข…๊ฒฐ`);return}
const lo=win==w.a?w.b:w.a,W=C[win],Lo=C[lo],d=n(Lo.D*.4);Lo.D-=d;W.D+=d;
for(let r=0;r<6;r++){const q=Math.floor(Lo.st[r]*.4);Lo.st[r]-=q;W.st[r]+=q}
Lo.mil*=.8;Lo.sh=Math.floor(Lo.sh*.7);hist.unshift(`T${turn} ${W.n} ์Šน / ${Lo.n} ํŒจ`);
L('์ „์Ÿ',`${W.n} ์Šน๋ฆฌ โ€” ${Lo.n}์—๊ฒŒ์„œ D ${d}์™€ ์ž์› 40% ํš๋“`);snd('ok');
if(lo==w.agg){Lo.tp=Math.max(0,Lo.tp-20);L('๊ตญ์ œ',`์„ ์ œ๊ณต๊ฒฉ๊ตญ ${Lo.n}์˜ ์™ธ๊ต ์˜จ๋„๊ฐ€ ํฌ๊ฒŒ ํ•˜๋ฝ`)}
else{L('๊ตญ์ œ',`${Lo.n}์€(๋Š”) ์„ ์ œ๊ณต๊ฒฉ ํ”ผํ•ด๊ตญ์œผ๋กœ ์™ธ๊ต ํŽ˜๋„ํ‹ฐ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.`);
C.forEach(v=>{if(v.i==win||v.i==lo||!v.k)return;const al=v.al>=0&&v.al==Lo.al;
if(al||(v.tp>55&&rel[v.i][lo]>=0)){if(H[v.i]){if(al)pend.push({t:'aid',to:v.i,lo});return}
const g=al?200:100;if(v.D<g)return;v.D-=g;Lo.D+=g;v.tp+=2;rem(lo,v.i,'aid',10);L(al?'์—ฐํ•ฉ':'๊ตญ์ œ',`${v.n}์ด(๊ฐ€) ${Lo.n}์— D ${g} ์ง€์›`)}})}}
// ---------- ๊ตฐ์‚ฌ ----------
const COST={a:150,n:120,k:100,v:300,b:200,B:200,m:250,h:1500};
function strike(c,e,t){const w=wf(c.i,e.i);if(!w)return -1;
if(t=='a'&&!cand(c.i,e.i,0).length)return -1;if(t=='v'&&(c.sh<3||!cand(c.i,e.i,1).length))return -1;
if((t=='n'&&c.sh<1)||(t=='k'&&c.sh<2)||((t=='b'||t=='B')&&c.bm<1)||(t=='m'&&c.ms<1))return -1;
if(c.D<COST[t])return 0;c.D-=COST[t];const sg=w.a==c.i?1:-1,V=c.i==me||e.i==me,P0=cen[c.i],P1=cen[e.i];let m;
if(t=='a'){const ap=c.mil*(.6+rnd()*.8),dp=e.mil*(1+e.df*.15)*(.6+rnd()*.8);
if(ap>dp){const g=take(c.i,e.i,0,1+(rnd()*3|0));c.mil*=.93;e.mil*=.95;w.s+=sg*g;m=`${c.n}์˜ ๋Œ๊ฒฉ ์„ฑ๊ณต: ${e.n}์˜ ${g}๊ตฌ์—ญ ์ ๋ น`;fxa('boom',P0,P1)}else{c.mil*=.88;m=`${c.n}์˜ ๋Œ๊ฒฉ์ด ${e.n}์˜ ๋ฐฉ์–ด์— ๋ง‰ํž˜`}}
else if(t=='n'){const ap=c.sh*(.6+rnd()*.8),dp=e.sh*(.6+rnd()*.8);
if(ap>dp){e.sh=Math.floor(e.sh*.6);w.s+=sg;m=`${c.n} ํ•จ๋Œ€๊ฐ€ ${e.n} ํ•จ๋Œ€๋ฅผ ๊ฒฉํŒŒ (ํ•ด์ƒ ํ†ต์ œ)`}else{c.sh=Math.floor(c.sh*.7);m=`${c.n} ํ•จ๋Œ€๊ฐ€ ${e.n} ํ•จ๋Œ€์— ํŒจํ‡ด`}fxa('ship',P0,P1)}
else if(t=='k'){e.blk=4;m=`${c.n}์ด(๊ฐ€) ${e.n}์„(๋ฅผ) ํ•ด์ƒ ๋ด‰์‡„ โ€” ๊ต์—ญยท์™ธ๊ต ์ˆ˜์ž… ๊ฐ์†Œ`;fxa('ship',P0,P1)}
else if(t=='v'){const ap=c.mil*.8+c.sh*6,dp=e.mil*(1+e.df*.15)*(.6+rnd()*.8)*(e.sh>c.sh?1.3:1);
if(ap>dp){const g=take(c.i,e.i,1,1+(rnd()*2|0));c.sh--;w.s+=sg*g;m=`${c.n}์˜ ์ƒ๋ฅ™์ž‘์ „ ์„ฑ๊ณต: ${e.n}์˜ ${g}๊ตฌ์—ญ ์ ๋ น`;fxa('ship',P0,P1)}else{c.sh=Math.max(0,c.sh-2);m=`${c.n}์˜ ์ƒ๋ฅ™์ž‘์ „์ด ${e.n}์— ๊ฒฉํ‡ด๋จ`}}
else if(t=='b'){e.mil*=.82-rnd()*.05;m=`${c.n} ํญ๊ฒฉ๊ธฐ๊ฐ€ ${e.n}์˜ ๊ตฐ์‚ฌ์‹œ์„ค ํญ๊ฒฉ`;w.s+=sg;fxa('plane',P0,P1)}
else if(t=='B'){e.ind=3;e.D=Math.max(0,e.D-80);m=`${c.n} ํญ๊ฒฉ๊ธฐ๊ฐ€ ${e.n}์˜ ์‚ฐ์—…์‹œ์„ค ํญ๊ฒฉ โ€” ์ˆ˜์ž… ๊ฐ์†Œ`;fxa('plane',P0,P1)}
else if(t=='m'){c.ms--;const rs=regsOf(e.i);let g=sel.g;if(c.i!=me||!rs.includes(g))g=rs[c.i==me?0:rnd()*rs.length|0];
if(g==null){c.ms++;c.D+=COST[t];return -1}RG[g].dmg=3;e.mil*=.93;w.s+=sg;m=`${c.n} ๋ฏธ์‚ฌ์ผ์ด ${RG[g].n} ์ง€์—ญ ํƒ€๊ฒฉ โ€” 3ํ„ด๊ฐ„ ์ƒ์‚ฐ ์ •์ง€`;fxa('miss',P0,rpos(g))}
else{e.mil*=.6;const g=take(c.i,e.i,0,6)||take(c.i,e.i,1,6);w.s+=sg*g;C.forEach(v=>{if(v.i!=c.i)rem(v.i,c.i,'nuke',-40)});c.tp=Math.max(0,c.tp-30);
m=`โ˜ข๏ธ ${c.n}์ด(๊ฐ€) ${e.n}์— ์ˆ˜์†Œํญํƒ„ ์‚ฌ์šฉ! ๊ตญ์ œ์‚ฌํšŒ๊ฐ€ ๊ฒฝ์•…ํ•ฉ๋‹ˆ๋‹ค`;fxa('nuke',P0,P1);snd('nuke')}
if(V||t=='h'){L('์ „์Ÿ',m);if(V&&t!='h')snd('war')}else CH(m);stats();
const k0=w.a==e.i?w.k[0]:w.k[1];if(wars.includes(w)&&(e.k<k0*.6||!e.k))endWar(w,c.i);return 1}
function aiStrike(c,e){const o=[],land=cand(c.i,e.i,0).length>0;
if(land)o.push('a','a');if(c.sh>=1)o.push('n');if(c.sh>=3&&!land)o.push('v','v');if(c.sh>=2&&rnd()<.3)o.push('k');if(c.bm>0)o.push('b','B');if(c.ms>0)o.push('m');
if(c.ty==0&&c.mil>e.mil*3&&c.D>3000&&rnd()<.1)o.push('h');
if(!o.length||c.D<150){if(c.D>100){c.D-=100;c.df=Math.min(5,c.df+1)}return}
const t=o[rnd()*o.length|0];strike(c,e,t)}
// ---------- AI ----------
function aiTrade(c,pr){let r=0;c.st.forEach((s,i)=>{if(s<c.st[r])r=i});
if(c.st[r]<(c.ty==6?12:25)){const q=25,cd=C.filter(p=>p.k&&p.i!=c.i&&p.st[r]>q+20&&!wf(c.i,p.i)).sort((a,b)=>rel[c.i][b.i]-rel[c.i][a.i])[0];
if(cd){const d=n(q*RP[r]*(.8+rnd()*.5));
if(H[cd.i]){if(pend.length<6)pend.push({t:'req',to:cd.i,f:c.i,r,q,d})}
else{const ok=rnd()<acc_(cd.i,c.i,d/(q*RP[r]));CH(`${c.n}: ${RN[r]} ${q}๊ฐœ ํ•„์š” โ†’ ${cd.n}: ${ok?'๊ฑฐ๋ž˜ ์Šน์ธ':'์žฌ๊ณ ๊ฐ€ ์ถฉ๋ถ„์น˜ ์•Š๋‹ค (๊ฑฐ์ ˆ)'}`);
if(ok)trade(c.i,cd.i,r,q,d);else rem(cd.i,c.i,'refuse',-1)}}}
else if(rnd()<pr[5]){let r2=0;c.st.forEach((s,i)=>{if(s>c.st[r2])r2=i});
if(c.st[r2]>70){const cd=C.filter(p=>p.k&&p.i!=c.i&&p.st[r2]<30&&p.D>150&&!wf(c.i,p.i))[0];
if(cd){const q=25,d=n(q*RP[r2]*1.1);if(H[cd.i]){if(pend.length<6)pend.push({t:'offer',to:cd.i,f:c.i,r:r2,q,d})}
else if(rnd()<acc_(c.i,cd.i,1)){trade(cd.i,c.i,r2,q,d);CH(`${c.n}: ${RN[r2]} ${q}๊ฐœ ํŒ๋งค โ†’ ${cd.n}: ๊ตฌ๋งค`)}}}}}
function ai(c){if(!c.k||H[c.i])return;const pr=PR[c.ty<0?1:c.ty],w=wars.find(x=>x.a==c.i||x.b==c.i);
if(w){const e=C[w.a==c.i?w.b:w.a],sc=(w.a==c.i?1:-1)*w.s;aiStrike(c,e);
if(wars.includes(w)&&sc<-2&&rnd()<.35){if(H[e.i]){if(pend.length<6)pend.push({t:'peace',to:e.i,w})}else endWar(w,w.s>0?w.a:w.s<0?w.b:-1)}return}
if(c.D>400&&rnd()<pr[1]){const q=rnd()*4|0;if(q==0){c.D-=200;c.mil+=12}else if(q==1){c.D-=300;c.sh+=2}else if(q==2){c.D-=250;c.bm+=2}else{c.D-=300;c.ms+=3}}
aiTrade(c,pr);
if(c.D<80&&c.ty!=6&&rnd()<.2){const f=C.find(v=>H[v.i]&&v.k&&rel[v.i][c.i]>0);if(f&&pend.length<6)pend.push({t:'dreq',to:f.i,f:c.i})}
if(rnd()<pr[4]){const p=C.find(v=>v.k&&v.i!=c.i&&rel[c.i][v.i]>15&&!pacts.some(q=>(q.a==c.i&&q.b==v.i)||(q.a==v.i&&q.b==c.i))&&!wf(c.i,v.i));
if(p){if(H[p.i]){if(pend.length<6)pend.push({t:'pact',to:p.i,f:c.i})}else{pacts.push({a:c.i,b:p.i,exp:turn+10});CH(`${c.n}-${p.n} ๋ฌด์—ญํ˜‘์ • ์ฒด๊ฒฐ`)}}}
if(rnd()<pr[3]){const p=C.filter(v=>v.k&&v.i!=c.i&&rel[c.i][v.i]>0&&v.D<500).sort((a,b)=>a.D-b.D)[0];
if(p&&c.D>400){c.D-=100;p.D+=100;rem(p.i,c.i,'gift',8);if(H[p.i])L('๊ตญ์ œ',`${c.n}์ด(๊ฐ€) ๋‹น์‹ ์—๊ฒŒ D 100์„ ์ง€์›ํ–ˆ์Šต๋‹ˆ๋‹ค`);else CH(`${c.n} โ†’ ${p.n} ์ง€์›๊ธˆ D 100`)}}
if(rnd()<pr[0]&&turn>3){const gr=v=>mem[c.i][v].filter(m=>m.k=='firststrike').length;
const ts=C.filter(v=>v.k&&v.i!=c.i&&!wf(c.i,v.i)&&(c.sh>=3||adj(c.i).includes(v.i))&&v.mil<c.mil*1.15).sort((a,b)=>(a.mil-gr(a.i)*30)-(b.mil-gr(b.i)*30));
if(ts.length)declare(c.i,ts[0].i,false)}
if(rnd()<pr[2]){const p=C.find(v=>v.k&&v.i!=c.i&&!H[v.i]&&PR[v.ty<0?1:v.ty][2]>0&&rel[c.i][v.i]>20&&rel[v.i][c.i]>20);if(p)ally(c.i,p.i)}}
function next(){turn++;pend=[];wars.forEach(w=>w.pu={});stats();
C.forEach(c=>{if(!c.k)return;const f=c.k/104;c.si=n((20+c.tp*.3)*f*(c.ind>0?.6:1));
c.di=n(c.tp*1.5*f*(c.blk>0?.4:1))+pacts.filter(p=>p.a==c.i||p.b==c.i).length*8;c.wc=wars.filter(w=>w.a==c.i||w.b==c.i).length*40;
c.D+=c.si+c.di-c.wc;let sh=0;
for(let r=0;r<6;r++){c.st[r]+=c.p[r]-c.k*.17;if(c.st[r]<0){c.D-=n(-c.st[r]*RP[r]*.6);c.st[r]=0;sh=1}}
c.pop=n(c.pop*(sh?.99:1.01));c.mil+=c.k*.04;c.tp+=(50-c.tp)*.02;c.D=Math.max(0,c.D);if(c.blk>0)c.blk--;if(c.ind>0)c.ind--});
RG.forEach(g=>{if(g.dmg>0)g.dmg--});
pacts=pacts.filter(p=>{if(p.exp>turn)return true;L('์กฐ์•ฝ',`${C[p.a].n}-${C[p.b].n} ๋ฌด์—ญํ˜‘์ • ๋งŒ๋ฃŒ`);return false});
C.forEach(ai);
for(let i=0;i<NC;i++)for(let j=0;j<NC;j++)if(i!=j&&rnd()<.15)rel[i][j]=cl(rel[i][j]+(rnd()<.5?1:-1),-100,100);
C.forEach(c=>c.tp=cl(c.tp,0,100));stats();if(!C[me].k&&H[me]){L('์‹œ์Šคํ…œ','๊ตญ๊ฐ€๊ฐ€ ๋ฉธ๋งํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ด€์ฐฐ ๋ชจ๋“œ๋กœ ์ „ํ™˜ํ•˜์„ธ์š”.')}snd('turn');render()}
// ---------- ์ €์žฅ/๋ถˆ๋Ÿฌ์˜ค๊ธฐ ----------
function save(){const s=JSON.stringify({own,reg,RG,C,rel,mem,wars,pend,logs,chat,hist,pacts,turn,aid,H,me});
try{localStorage.setItem(SK,s)}catch(e){window.__nsSave=s}L('์‹œ์Šคํ…œ','์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค')}
function load(){let s;try{s=localStorage.getItem(SK)}catch(e){}s=s||window.__nsSave;if(!s){L('์‹œ์Šคํ…œ','์ €์žฅ ๋ฐ์ดํ„ฐ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค');return}
const d=JSON.parse(s);({own,reg,RG,C,rel,mem,wars,pend,logs,chat,hist,pacts,turn,aid,H,me}=d);mkCoast();stats();L('์‹œ์Šคํ…œ','๋ถˆ๋Ÿฌ์™”์Šต๋‹ˆ๋‹ค')}
// ---------- ํ”Œ๋ ˆ์ด์–ด ํ–‰๋™ ----------
const can=()=>{if(!H[me]){L('์‹œ์Šคํ…œ','๊ด€์ฐฐ ์ค‘์ธ ๊ตญ๊ฐ€๋Š” ์กฐ์ž‘ํ•  ์ˆ˜ ์—†์–ด์š” (๊ตญ๊ฐ€ ํƒญ์—์„œ ์กฐ์ข… ์ „ํ™˜)');render();return false}return true};
const act={
nx(){if(!pend.length||true){next()}},
cyc(d){me=(me+d+NC)%NC;render()},spd(s){spd=s;acc=0;render()},mute(){mute=!mute;render()},save(){save();render()},load(){load();render()},
tog(){H[me]=!H[me];render()},obs(){H=H.map(()=>false);spd=1;L('์‹œ์Šคํ…œ','๊ด€์ฐฐ ๋ชจ๋“œ: ๋ชจ๋“  ๊ตญ๊ฐ€๋ฅผ AI๊ฐ€ ์šด์˜ํ•ฉ๋‹ˆ๋‹ค');render()},
chat(){showChat=!showChat;render()},ng(){newGame()},
req(b){if(!can())return;const B=C[b],P=C[me],{r,q,d}=sel;
if(P.D<d){L('์™ธ๊ต','D๊ฐ€ ๋ถ€์กฑํ•ฉ๋‹ˆ๋‹ค');return render()}if(B.st[r]<q+15){L('์™ธ๊ต',`${B.n}: ์žฌ๊ณ  ๋ถ€์กฑ์œผ๋กœ ์š”์ฒญ ๋ถˆ๊ฐ€`);return render()}
if(rnd()<acc_(b,me,d/(q*RP[r]))){trade(me,b,r,q,d);L('์™ธ๊ต',`${B.n}์ด(๊ฐ€) ${RN[r]} ${q}๊ฐœ ์š”์ฒญ์„ ์Šน์ธ`);snd('ok')}else{rem(b,me,'refuse',-1);L('์™ธ๊ต',`${B.n}์ด(๊ฐ€) ์š”์ฒญ์„ ๊ฑฐ์ ˆ`);snd('no')}render()},
sell(b){if(!can())return;const B=C[b],P=C[me],{r,q,d}=sel;if(P.st[r]<q){L('์™ธ๊ต','์žฌ๊ณ  ๋ถ€์กฑ');return render()}if(B.D<d){L('์™ธ๊ต',`${B.n}: D ๋ถ€์กฑ`);return render()}
const p=acc_(b,me,Math.min(2,q*RP[r]/Math.max(1,d)))*(B.st[r]<45?1:.3);
if(rnd()<p){trade(b,me,r,q,d);L('์™ธ๊ต',`${B.n}์ด(๊ฐ€) ${RN[r]} ${q}๊ฐœ๋ฅผ D ${d}์— ๊ตฌ๋งค`);snd('ok')}else{L('์™ธ๊ต',`${B.n}์ด(๊ฐ€) ํŒ๋งค ์ œ์•ˆ์„ ๊ฑฐ์ ˆ`);snd('no')}render()},
gift(b){if(!can())return;const P=C[me];if(P.D<100)return;P.D-=100;C[b].D+=100;rem(b,me,'gift',8);P.tp+=1;L('์™ธ๊ต',`${C[b].n}์— D 100 ์„ ๋ฌผ`);render()},
askD(b){if(!can())return;const B=C[b],P=C[me];if(B.D>400&&rnd()<acc_(b,me,1)-.1){B.D-=200;P.D+=200;rem(b,me,'help',4);L('์™ธ๊ต',`${B.n}์ด(๊ฐ€) D 200์„ ์ง€์›`);snd('ok')}else{L('์™ธ๊ต',`${B.n}์ด(๊ฐ€) ์ง€์› ์š”์ฒญ์„ ๊ฑฐ์ ˆ`);snd('no')}render()},
ally(b){if(!can())return;if(rel[b][me]>15&&C[me].tp>40&&C[b].ty!=6&&ally(me,b))snd('ok');else{L('์—ฐํ•ฉ',`${C[b].n}์ด(๊ฐ€) ์—ฐํ•ฉ ์ œ์•ˆ์„ ๊ฑฐ์ ˆ`);snd('no')}render()},
pact(b){if(!can())return;if(rel[b][me]>5&&!pacts.some(p=>(p.a==me&&p.b==b)||(p.a==b&&p.b==me))&&C[b].blk<1){pacts.push({a:me,b,exp:turn+10});rem(b,me,'pact',5);L('์กฐ์•ฝ',`${C[b].n}๊ณผ(์™€) 10ํ„ด ๋ฌด์—ญํ˜‘์ • ์ฒด๊ฒฐ (๋งคํ„ด D+8)`);snd('ok')}else{L('์กฐ์•ฝ',`${C[b].n}์ด(๊ฐ€) ๋ฌด์—ญํ˜‘์ •์„ ๊ฑฐ์ ˆ/์ด๋ฏธ ์ฒด๊ฒฐ`);snd('no')}render()},
leave(){if(!can())return;C[me].al=-1;C[me].tp-=3;L('์—ฐํ•ฉ','์—ฐํ•ฉ์—์„œ ํƒˆํ‡ดํ–ˆ์Šต๋‹ˆ๋‹ค');render()},
help(b){if(!can())return;const P=C[me];if(P.D<150)return;P.D-=150;C[b].D+=150;P.tp+=2;rem(b,me,'aid',10);L('์—ฐํ•ฉ',`${C[b].n}์— ์ง€์›์•ˆ ์‹œํ–‰: D 150`);render()},
war(b,f){if(!can())return;declare(me,b,f);render()},
buy(k){if(!can())return;const P=C[me],T={m:[200,'mil',12],s:[300,'sh',2],b:[250,'bm',2],x:[300,'ms',3],d:[100,'df',1]}[k];if(P.D<T[0]||(k=='d'&&P.df>=5))return;P.D-=T[0];P[T[1]]+=T[2];snd('click');render()},
hit(e,t){if(!can())return;const w=wf(me,e);if(!w)return;if(w.pu[me]){L('๊ตฐ์‚ฌ','์ด๋ฒˆ ํ„ด ์ด๋ฏธ ํ–‰๋™ํ–ˆ์Šต๋‹ˆ๋‹ค');return render()}
w.pu[me]=1;const r=strike(C[me],C[e],t);if(r<1){w.pu[me]=0;L('๊ตฐ์‚ฌ',r<0?'์ˆ˜ํ–‰ ๋ถˆ๊ฐ€: ์กฐ๊ฑด ๋ฏธ์ถฉ์กฑ(๊ตญ๊ฒฝยทํ•จ์„ ยทํญ๊ฒฉ๊ธฐยท๋ฏธ์‚ฌ์ผ)':'D๊ฐ€ ๋ถ€์กฑํ•ฉ๋‹ˆ๋‹ค')}render()},
peace(e){if(!can())return;const w=wf(me,e);if(!w)return;const sa=(w.a==e?1:-1)*w.s;
if(rnd()<(sa<=0?.8:.3))endWar(w,w.s>0?w.a:w.s<0?w.b:-1);else{L('์™ธ๊ต',`${C[e].n}์ด(๊ฐ€) ํ‰ํ™” ํ˜‘์ •์„ ๊ฑฐ์ ˆ`);snd('no')}render()},
ans(i,y){const p=pend.splice(i,1)[0];if(!p)return;const P=C[p.to];
if(p.t=='req'){if(y&&P.st[p.r]>=p.q){trade(p.f,p.to,p.r,p.q,p.d);P.tp+=2;rem(p.f,p.to,'help',6);L('์™ธ๊ต',`${C[p.f].n}์˜ ์š”์ฒญ ์Šน์ธ`)}else{rem(p.f,p.to,'refuse',-3);P.tp-=1;L('์™ธ๊ต',`${C[p.f].n}์˜ ์š”์ฒญ ๊ฑฐ์ ˆ`)}}
else if(p.t=='offer'){if(y&&P.D>=p.d){trade(p.to,p.f,p.r,p.q,p.d);L('์™ธ๊ต',`${C[p.f].n}์—๊ฒŒ์„œ ${RN[p.r]} ${p.q}๊ฐœ ๊ตฌ๋งค`)}}
else if(p.t=='dreq'){if(y&&P.D>=150){P.D-=150;C[p.f].D+=150;P.tp+=2;rem(p.f,p.to,'help',8);L('์™ธ๊ต',`${C[p.f].n}์— D 150 ์ง€์›`)}}
else if(p.t=='pact'){if(y){pacts.push({a:p.f,b:p.to,exp:turn+10});L('์กฐ์•ฝ',`${C[p.f].n}๊ณผ(์™€) ๋ฌด์—ญํ˜‘์ • ์ฒด๊ฒฐ`)}}
else if(p.t=='peace'){if(y&&wars.includes(p.w))endWar(p.w,p.w.s>0?p.w.a:p.w.s<0?p.w.b:-1)}
else if(p.t=='aid'){if(y&&P.D>=150){P.D-=150;C[p.lo].D+=150;P.tp+=3;rem(p.lo,p.to,'aid',10);L('์—ฐํ•ฉ',`${C[p.lo].n} ์ง€์›์•ˆ ์ฐฌ์„ฑ: D 150`)}}
else if(p.t=='wv'){const ok=(p.y0+(y?1:0))*2>=p.ids.length;L('์Šน์ธ',`์—ฐํ•ฉ ํˆฌํ‘œ ${p.y0+(y?1:0)}:${p.ids.length-p.y0-(y?1:0)} โ†’ ${ok?'์Šน์ธ':'๋ถ€๊ฒฐ'}`);if(ok)declare(p.a,p.b,false,true)}
render()}};
const PT=p=>{const f=C[p.f]||{},T={
req:()=>`[์™ธ๊ต ๋‚˜๋ ˆ์ด์…˜] ${f.n}์—์„œ ${RN[p.r]} ${p.q}๊ฐœ๋ฅผ ์š”์ฒญํ–ˆ์Šต๋‹ˆ๋‹ค. (์ œ๊ณต D ${p.d})`,
offer:()=>`[์™ธ๊ต ๋‚˜๋ ˆ์ด์…˜] ${f.n}์ด(๊ฐ€) ${RN[p.r]} ${p.q}๊ฐœ๋ฅผ D ${p.d}์— ํŒ”๊ฒ ๋‹ค๊ณ  ์ œ์•ˆํ–ˆ์Šต๋‹ˆ๋‹ค.`,
dreq:()=>`[์™ธ๊ต ๋‚˜๋ ˆ์ด์…˜] ${f.n}์ด(๊ฐ€) D 150 ์ง€์›์„ ์š”์ฒญํ–ˆ์Šต๋‹ˆ๋‹ค.`,
pact:()=>`[์กฐ์•ฝ ๋‚˜๋ ˆ์ด์…˜] ${f.n}์ด(๊ฐ€) 10ํ„ด ๋ฌด์—ญํ˜‘์ •์„ ์ œ์•ˆํ–ˆ์Šต๋‹ˆ๋‹ค.`,
peace:()=>`[์™ธ๊ต ๋‚˜๋ ˆ์ด์…˜] ${C[p.w.a==p.to?p.w.b:p.w.a].n}์ด(๊ฐ€) ํ‰ํ™” ํ˜‘์ •์„ ์ œ์•ˆํ–ˆ์Šต๋‹ˆ๋‹ค.`,
aid:()=>`[์—ฐํ•ฉ ๋‚˜๋ ˆ์ด์…˜] ${C[p.lo].n} ์ „ํ›„ ๋ณต๊ตฌ ์ง€์›์•ˆ(D 150)์ด ์ œ์ถœ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.`,
wv:()=>`[์—ฐํ•ฉ ๋‚˜๋ ˆ์ด์…˜] ${C[p.a].n}์˜ ${C[p.b].n} ์ „์Ÿ ์•ˆ๊ฑด ํˆฌํ‘œ (ํ˜„์žฌ ์ฐฌ์„ฑ ${p.y0}/${p.ids.length})`};return T[p.t]()};
// ---------- ํ™”๋ฉด ----------
const al=c=>c.al>=0?`๐Ÿค์—ฐํ•ฉ${c.al+1}`:'';
function render(){const P=C[me];
$('nh').innerHTML=`<button onclick="NS.act.cyc(-1)">โ—€</button><b style="color:${P.c}">${P.n}</b>${H[me]?'':'(๊ด€์ฐฐ)'}<button onclick="NS.act.cyc(1)">โ–ถ</button> T${turn} ๐Ÿ’ฐ${n(P.D)} ๐ŸŒก๏ธ${n(P.tp)} โš”๏ธ${n(P.mil)}<br>`+
[[0,'โธ'],[1,'1x'],[2,'2x'],[4,'4x']].map(s=>`<button class="${spd==s[0]?'on':''}" onclick="NS.act.spd(${s[0]})">${s[1]}</button>`).join('')+`<button onclick="NS.act.mute()">${mute?'๐Ÿ”‡':'๐Ÿ”Š'}</button><button onclick="NS.act.save()">๐Ÿ’พ</button><button onclick="NS.act.load()">๐Ÿ“‚</button>`;
$('np').innerHTML=pend.map((p,i)=>p.to!=me?'':`<div class=cd>${PT(p)}<br><button onclick="NS.act.ans(${i},1)">์Šน์ธ/์ฐฌ์„ฑ</button><button onclick="NS.act.ans(${i},0)">๊ฑฐ์ ˆ/๋ฐ˜๋Œ€</button></div>`).join('');
$('nt').innerHTML=[['e','๊ฒฝ์ œ'],['d','์™ธ๊ต'],['m','๊ตฐ์‚ฌ'],['a','์—ฐํ•ฉ'],['i','๊ตญ๊ฐ€'],['l','์†Œ์‹']].map(t=>`<button class="${tab==t[0]?'on':''}" onclick="NS.tab('${t[0]}')">${t[1]}</button>`).join('');
let h='';
if(tab=='e')h=`<div class=r>๐Ÿ’ฐ D ${n(P.D)} ยท ์ž์ฒด +${P.si} ยท ์™ธ๊ต +${P.di} ยท ์ „์Ÿ์œ ์ง€ -${P.wc}<br>๐ŸŒก๏ธ ์˜จ๋„ ${n(P.tp)} ยท ๐Ÿ‘ฅ ์ธ๊ตฌ ${P.pop.toLocaleString()} ยท ์˜ํ†  ${P.k}${P.blk>0?'<br>โš“ ๋ด‰์‡„๋‹นํ•จ '+P.blk+'ํ„ด':''}${P.ind>0?'<br>๐Ÿญ ์‚ฐ์—…์‹œ์„ค ํ”ผํ•ด '+P.ind+'ํ„ด':''}</div>`+
[0,1,2,3,4,5].map(r=>`<div class=r>${RN[r]} ์žฌ๊ณ  <b>${n(P.st[r])}</b> ยท ์ƒ์‚ฐ ${P.p[r]} ยท ์†Œ๋น„ ${n(P.k*.17)} ${P.p[r]<P.k*.17?'โš ๏ธ๋ถ€์กฑ':''}</div>`).join('')+`<div class=r style="color:#9ab">๋ฌด์—ญํ˜‘์ •: ${pacts.filter(p=>p.a==me||p.b==me).map(p=>C[p.a==me?p.b:p.a].n+'('+(p.exp-turn)+'ํ„ด)').join(', ')||'์—†์Œ'}</div>`;
else if(tab=='d')h=`<div class=r>๊ฑฐ๋ž˜ ์„ค์ •: <select onchange="NS.sel.r=+this.value">${RN.map((x,i)=>`<option value=${i} ${sel.r==i?'selected':''}>${x}</option>`)}</select><select onchange="NS.sel.q=+this.value">${[10,25,50].map(x=>`<option ${sel.q==x?'selected':''}>${x}</option>`)}</select> D <input type=number value=${sel.d} onchange="NS.sel.d=+this.value"></div>`+
C.filter(c=>c.i!=me&&c.k).map(c=>{const m=mem[c.i][me].slice(-1)[0];return `<div class=r><b style="color:${c.c}">${c.n}</b> ${wf(me,c.i)?'โš”๏ธ':''}${al(c)} ยท ${TY[c.ty]||'ํ”Œ๋ ˆ์ด์–ด'} ${c.blk>0?'โš“':''}<br>๐ŸŒก๏ธ${n(c.tp)} ยท ๊ด€๊ณ„ ${rel[c.i][me]} ยท ๊ตฐ์‚ฌ ${n(c.mil)}${m?` ยท ๊ธฐ์–ต: ${MK[m.k]||m.k}(T${m.T})`:''}<br>
<button onclick="NS.act.req(${c.i})">์š”์ฒญ(๊ตฌ๋งค)</button><button onclick="NS.act.sell(${c.i})">ํŒ๋งค</button><button onclick="NS.act.gift(${c.i})">์„ ๋ฌผ100</button><button onclick="NS.act.askD(${c.i})">์ง€์›์š”์ฒญ</button><button onclick="NS.act.pact(${c.i})">๋ฌด์—ญํ˜‘์ •</button><button onclick="NS.act.ally(${c.i})">์—ฐํ•ฉ</button><button onclick="NS.act.war(${c.i},false)">์ „์Ÿ(์Šน์ธ)</button><button onclick="NS.act.war(${c.i},true)">์„ ์ œ๊ณต๊ฒฉ</button></div>`}).join('');
else if(tab=='m'){const myw=wars.filter(w=>w.a==me||w.b==me);
h=`<div class=r>โš”๏ธ๊ตฐ์‚ฌ ${n(P.mil)} ยท ๐Ÿ›ก๏ธ๋ฐฉ์–ด์ง„์ง€ Lv.${P.df}/5 ยท โ›ตํ•จ์„  ${P.sh} ยท โœˆ๏ธํญ๊ฒฉ๊ธฐ ${P.bm} ยท ๐Ÿš€๋ฏธ์‚ฌ์ผ ${P.ms}<br>
<button onclick="NS.act.buy('m')">๊ตฐ์‚ฌ๋ ฅ+12 (200)</button><button onclick="NS.act.buy('d')">๋ฐฉ์–ด์ง„์ง€ (100)</button><button onclick="NS.act.buy('s')">ํ•จ์„ +2 (300)</button><button onclick="NS.act.buy('b')">ํญ๊ฒฉ๊ธฐ+2 (250)</button><button onclick="NS.act.buy('x')">๋ฏธ์‚ฌ์ผ+3 (300)</button></div>`+
(myw.map(w=>{const e=w.a==me?w.b:w.a,E=C[e],s=(w.a==me?1:-1)*w.s,rs=regsOf(e);return `<div class=r>โš”๏ธ vs <b style="color:${E.c}">${E.n}</b> ${w.agg==me?'(๋‚ด๊ฐ€ ๊ฐœ์ „)':'(๋ฐฉ์–ด์ „)'}${w.pre?' ยท ์„ ์ œ๊ณต๊ฒฉ ์ „์Ÿ':''} ยท ์  ๊ตฐ์‚ฌ ${n(E.mil)} โ›ต${E.sh} ยท ์ „ํ™ฉ ${s>0?'+':''}${s}<br>
<button onclick="NS.act.hit(${e},'a')">๋Œ๊ฒฉ150</button><button onclick="NS.act.hit(${e},'n')">ํ•ด์ƒ์ „120</button><button onclick="NS.act.hit(${e},'k')">๋ด‰์‡„100</button><button onclick="NS.act.hit(${e},'v')">์ƒ๋ฅ™300</button><button onclick="NS.act.hit(${e},'b')">ํญ๊ฒฉ(๊ตฐ์‚ฌ)200</button><button onclick="NS.act.hit(${e},'B')">ํญ๊ฒฉ(์‚ฐ์—…)200</button><button onclick="NS.act.hit(${e},'m')">๋ฏธ์‚ฌ์ผ250</button><button onclick="NS.act.hit(${e},'h')">โ˜ข๏ธ์ˆ˜์†Œํญํƒ„1500</button><button onclick="NS.act.peace(${e})">ํ‰ํ™”ํ˜‘์ •</button><br>
๋ฏธ์‚ฌ์ผ ๋ชฉํ‘œ: <select onchange="NS.sel.g=+this.value">${rs.map(g=>`<option value=${g} ${sel.g==g?'selected':''}>${RG[g].n} (${RN[RG[g].res]})</option>`)}</select></div>`}).join('')||`<div class=r>ํ˜„์žฌ ์ „์Ÿ ์ค‘์ด ์•„๋‹™๋‹ˆ๋‹ค.</div>`)+
`<div class=r style="color:#9ab">ํ„ด๋‹น ์ „์Ÿ๋ณ„ 1ํšŒ ํ–‰๋™. ๋Œ๊ฒฉ=๊ตญ๊ฒฝ ์ ๋ น, ํ•ด์ƒ์ „=ํ•ด์ƒ ํ†ต์ œ, ์ƒ๋ฅ™=ํ•ด์•ˆ ์นจํˆฌ, ๋ด‰์‡„=๊ต์—ญ ์ฐจ๋‹จ, ์ˆ˜์†Œํญํƒ„=๋Œ€๊ทœ๋ชจ ํƒ€๊ฒฉ+๊ตญ์ œ ํ›„ํญํ’.</div>`}
else if(tab=='a'){const ids=[...new Set(C.filter(c=>c.al>=0).map(c=>c.al))];
h=(P.al>=0?`<div class=r>${al(P)} ์†Œ์† ยท ์—ฐํ•ฉ ๋‚ด ์ „์Ÿ์€ ๋‹ค์ˆ˜๊ฒฐ, ์—ฐํ•ฉ๊ตญ์ด ๊ณต๊ฒฉ๋ฐ›์œผ๋ฉด ์ž๋™ ์ฐธ์ „ <button onclick="NS.act.leave()">ํƒˆํ‡ด</button><br>`+C.filter(v=>v.al==P.al&&v.i!=me).map(v=>`${v.n} D${n(v.D)} <button onclick="NS.act.help(${v.i})">์ง€์› D150</button>`).join('<br>')+`</div>`:`<div class=r>๊ฐ€์ž…ํ•œ ์—ฐํ•ฉ์ด ์—†์Šต๋‹ˆ๋‹ค. ์™ธ๊ต ํƒญ์—์„œ ์—ฐํ•ฉ์„ ์ œ์•ˆํ•˜์„ธ์š”.</div>`)+
ids.map(id=>`<div class=r>๐Ÿค ์—ฐํ•ฉ${id+1}: ${C.filter(c=>c.al==id).map(c=>`<span style="color:${c.c}">${c.n}</span>`).join(', ')}</div>`).join('')}
else if(tab=='i'){h=`<div class=r><b>${P.n}</b> ยท ์„ฑํ–ฅ ${TY[P.ty]||'ํ”Œ๋ ˆ์ด์–ด'} ยท ${H[me]?'์กฐ์ข… ์ค‘':'AI/๊ด€์ฐฐ'}<br><button onclick="NS.act.tog()">${H[me]?'AI์—๊ฒŒ ๋งก๊ธฐ๊ธฐ':'์ด ๊ตญ๊ฐ€ ์ง์ ‘ ์กฐ์ข…'}</button><button onclick="NS.act.obs()">๐Ÿ‘ ๊ด€์ฐฐ ๋ชจ๋“œ</button><button onclick="NS.act.ng()">์ƒˆ ๊ฒŒ์ž„</button></div>
<div class=r><b>์ง€์—ญ</b><br>`+RG.filter(g=>g.o==me).map(g=>`${g.n}: ${RN[g.res]} ${g.dmg?'(ํ”ผํ•ด '+g.dmg+'ํ„ด)':''}`).join('<br>')+`</div><div class=r><b>์ „์Ÿ ๊ธฐ๋ก</b><br>${hist.slice(0,10).join('<br>')||'์—†์Œ'}</div>
<div class=r><b>์™ธ๊ต ๊ธฐ๋ก(์ƒ๋Œ€โ†’${P.n})</b><br>`+C.filter(c=>c.i!=me).map(c=>mem[c.i][me].slice(-2).map(m=>`${c.n}: ${MK[m.k]||m.k} ${m.v>0?'+':''}${m.v} (T${m.T})`).join('<br>')).filter(x=>x).join('<br>')+`</div>`}
else h=`<button onclick="NS.act.chat()">${showChat?'๋‚˜๋ ˆ์ด์…˜ ๋ณด๊ธฐ':'AI๋ผ๋ฆฌ์˜ ๋Œ€ํ™” ๋ณด๊ธฐ(๊ด€์ฐฐ)'}</button>`+(showChat?chat:logs).map(x=>`<div class=r>${x}</div>`).join('');
$('nb').innerHTML=h}
// ---------- ์ง€๋„ ๊ทธ๋ฆฌ๊ธฐ ----------
function draw(){frame++;const W=GW*CS,Hh=GH*CS;ctx.fillStyle='#0c1b2e';ctx.fillRect(0,0,W,Hh);
for(let i=0;i<own.length;i++){const x=i%GW,y=i/GW|0,o=own[i],X=x*CS,Y=y*CS;
if(o<0){ctx.fillStyle=((x+y+(frame>>2))&3)?'#10304f':'#164068';ctx.fillRect(X,Y,CS,CS);continue}
ctx.fillStyle=C[o].c;ctx.fillRect(X,Y,CS,CS);if(coast[i]){ctx.fillStyle='#ffffff30';ctx.fillRect(X,Y,CS,CS)}
const g=RG[reg[i]];if(g.dmg){ctx.fillStyle='#000a';ctx.fillRect(X,Y,CS,CS)}
ctx.fillStyle=RC[g.res];ctx.fillRect(X+4,Y+4,3,3)}
for(let i=0;i<own.length;i++){const x=i%GW,y=i/GW|0;if(own[i]<0)continue;
if(x<GW-1&&own[i+1]>=0&&(own[i+1]!=own[i]||reg[i+1]!=reg[i])){ctx.strokeStyle=own[i+1]!=own[i]?(wf(own[i],own[i+1])?'#ff2a2a':'#000b'):'#fff4';ctx.lineWidth=own[i+1]!=own[i]?2:1;ctx.beginPath();ctx.moveTo((x+1)*CS,y*CS);ctx.lineTo((x+1)*CS,(y+1)*CS);ctx.stroke()}
if(y<GH-1&&own[i+GW]>=0&&(own[i+GW]!=own[i]||reg[i+GW]!=reg[i])){ctx.strokeStyle=own[i+GW]!=own[i]?(wf(own[i],own[i+GW])?'#ff2a2a':'#000b'):'#fff4';ctx.lineWidth=own[i+GW]!=own[i]?2:1;ctx.beginPath();ctx.moveTo(x*CS,(y+1)*CS);ctx.lineTo((x+1)*CS,(y+1)*CS);ctx.stroke()}}
const bob=(frame>>3)&1;C.forEach(c=>{if(!c.k)return;sp[c.i].slice(0,Math.min(3,Math.ceil(c.sh/2))).forEach(i=>{if(own[i]!=c.i)return;const x=(i%GW)*CS,y=(i/GW|0)*CS;ctx.fillStyle='#fff';ctx.fillRect(x+1,y+CS-3+bob,6,2);ctx.fillRect(x+3,y+bob,2,CS-3)})});
ctx.font='bold 12px system-ui';ctx.textAlign='center';ctx.lineWidth=3;ctx.strokeStyle='#000';ctx.fillStyle='#fff';
C.forEach(c=>{if(!c.k)return;const t=(c.i==me?'โ˜…':'')+c.n+(wars.some(w=>w.a==c.i||w.b==c.i)?'โš”':'');ctx.strokeText(t,cen[c.i][0],cen[c.i][1]);ctx.fillText(t,cen[c.i][0],cen[c.i][1])});
fx=fx.filter(f=>{f.t++;const p=Math.min(1,f.t/f.d),x=f.x0+(f.x1-f.x0)*p,y=f.y0+(f.y1-f.y0)*p;
if(f.k=='boom'||(f.k=='nuke'&&f.t>10)){const r=(f.t-(f.k=='nuke'?10:0))*(f.k=='nuke'?1.6:1.1);ctx.fillStyle=f.t%6<3?'#fff':'#ffb020';
for(let a=0;a<8;a++)ctx.fillRect(f.x1+Math.cos(a*.785)*r-2,f.y1+Math.sin(a*.785)*r-2,4,4);if(f.k=='nuke'){ctx.fillStyle='#ffffff'+(f.t<16?'55':'22');ctx.fillRect(0,0,W,Hh)}}
else if(f.k=='miss'){ctx.strokeStyle='#ff6';ctx.lineWidth=2;ctx.beginPath();ctx.moveTo(f.x0,f.y0);ctx.lineTo(x,y);ctx.stroke();ctx.fillStyle='#fff';ctx.fillRect(x-2,y-2,5,5)}
else if(f.k=='ship'||f.k=='plane'){ctx.fillStyle=f.k=='ship'?'#fff':'#ddd';ctx.fillRect(x-4,y-1,9,3);ctx.fillRect(x-1,y-4,3,9)}
if(f.t>=f.d&&f.k!='boom'&&f.k!='nuke'&&f.k!='plane'){if(f.k=='miss'||f.k=='ship')fx.push({k:'boom',x0:0,y0:0,x1:f.x1,y1:f.y1,t:0,d:14})}
return f.t<f.d+(f.k=='nuke'?20:0)})}
cv.addEventListener('pointerdown',e=>{const r=cv.getBoundingClientRect(),x=Math.floor((e.clientX-r.left)/r.width*GW),y=Math.floor((e.clientY-r.top)/r.height*GH),i=y*GW+x;
if(x<0||y<0||x>=GW||y>=GH)return;$('ni').textContent=own[i]<0?'๐ŸŒŠ ๋ฐ”๋‹ค':`${RG[reg[i]].n} ยท ์†Œ์œ  ${C[own[i]].n} ยท ํŠน์‚ฐ ${RN[RG[reg[i]].res]}${coast[i]?' ยท ํ•ด์•ˆ':''}${RG[reg[i]].dmg?' ยท ํ”ผํ•ด':''}`;snd('click')});
setInterval(()=>{draw();if(spd&&!pend.length){acc+=70*spd;if(acc>=3000){acc=0;next()}}},70);
window.NS={act,sel,tab:t=>{tab=t;render()}};
newGame();
})();

Game Source: Worldline

Creator: GlitchKnight20

Libraries: none

Complexity: complex (262 lines, 31.4 KB)

The full source code is displayed above on this page.

Remix Instructions

To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: worldline-glitchknight20" to link back to the original. Then publish at arcadelab.ai/publish.