Add spells, weapon abilities, and durable corpse resurrection
This commit is contained in:
+18
-4
@@ -1,6 +1,7 @@
|
||||
import './style.css';
|
||||
import { showTravel } from './travel';
|
||||
import { craftingPanel } from './crafting-panel';
|
||||
import { createPowerPanel, revivalPanel } from './power-panel';
|
||||
import { createIcons, Crosshair, Settings2, X, Flame, LogOut, Hourglass, Swords, Pickaxe, HeartPulse, Gem, Backpack, ChevronUp, ChevronDown, ChevronLeft, ChevronRight, ArrowRight, RefreshCw } from 'lucide';
|
||||
import { WorldView } from './world-view';
|
||||
import type { Character, Chunk, Entity, Intent, Snapshot } from './generated';
|
||||
@@ -49,6 +50,7 @@ function progressSignature(): number | undefined {
|
||||
const avoidUntil = new Map<string, number>();
|
||||
let requestedClose = false;
|
||||
let input: InputActions;
|
||||
let powers:ReturnType<typeof createPowerPanel>;
|
||||
let view: WorldView;
|
||||
const selectedWorld = new URLSearchParams(location.search).get('world');
|
||||
const worldPrefix = selectedWorld && /^[a-z][a-z0-9-]{0,30}$/.test(selectedWorld) ? `/worlds/${selectedWorld}` : '';
|
||||
@@ -101,11 +103,15 @@ function connect() {
|
||||
if (value.type !== 'snapshot' || value.version !== 1) { ws?.close(); notice('Client and server versions do not match.'); return; }
|
||||
if(pendingAction?.op==='gather' && snapshot && value.self.gatherAttempt!==snapshot.self.gatherAttempt){pendingAction=undefined;walkTo=undefined;gatherSent=0;}
|
||||
if(gatherSent && value.self.ack>=gatherSent)gatherSent=0;
|
||||
const previousState = snapshot?.self.entity.state;
|
||||
snapshot = value; view.update(value); updateHUD(value);
|
||||
$('connection-status').textContent = 'Connected'; $('connection-dot').parentElement!.classList.remove('offline');
|
||||
const state = value.self.entity.state;
|
||||
if (state === 'dead') showEnding('A life, remembered.', 'This character is permanently dead. Their belongings remain in this world.', false);
|
||||
else if (value.self.remainingSeconds <= 0) showEnding('Rest until tomorrow.', 'Your daily play time is complete. Your keystone will return you to your previous location after 00:00 UTC.', false);
|
||||
const ending = $<HTMLDialogElement>('ending');
|
||||
if (previousState === 'dead' && state !== 'dead') ending.close();
|
||||
if (state === 'dead') {
|
||||
if (!ending.open) showEnding('A life, remembered.', 'Your belongings remain on your corpse. Revival requires another player and your consent; replacement makes this death final.', false);
|
||||
} else if (value.self.remainingSeconds <= 0 && !ending.open) showEnding('Rest until tomorrow.', 'Your daily play time is complete. Your keystone will return you to your previous location after 00:00 UTC.', false);
|
||||
};
|
||||
ws.onclose = async () => {
|
||||
$('connection-status').textContent = 'Disconnected'; $('connection-dot').parentElement!.classList.add('offline'); input.clear(); walkTo = undefined;
|
||||
@@ -127,7 +133,8 @@ function showEnding(title: string, detail: string, survivor: boolean) {
|
||||
if (survivor && destinations.children.length === 0) { const p = document.createElement('p'); p.textContent = 'Your passage is saved. No destination world is open yet.'; destinations.append(p); }
|
||||
visible('reconnect', false);
|
||||
visible('new-character', snapshot?.self.entity.state === 'dead' && ['gathering','cataclysm'].includes(snapshot.world.phase));
|
||||
$<HTMLDialogElement>('ending').show();
|
||||
$('ending').querySelector('.revival-panel')?.remove();if(snapshot?.self.entity.state==='dead')$('ending').append(revivalPanel(worldPrefix));
|
||||
$<HTMLDialogElement>('ending').show();
|
||||
}
|
||||
function inventory(c: Character) {
|
||||
$('earned-titles').replaceChildren(permanentTitles(c.titles));
|
||||
@@ -152,6 +159,7 @@ function minimap(s: Snapshot) {
|
||||
}
|
||||
function updateHUD(s: Snapshot) {
|
||||
const c = s.self, w = s.world;
|
||||
powers?.update(c);
|
||||
visible('game-controls', true); visible('movement', ['alive','eligible'].includes(c.entity.state) && $('inventory').hidden && $('settings').hidden);
|
||||
$('character-name').textContent = c.entity.name;
|
||||
$('character-level').textContent = `Level ${c.level || 1}`;
|
||||
@@ -191,6 +199,9 @@ async function boot() {
|
||||
input = new InputActions(() => hasOpenMenu() || isEditing(document.activeElement) || $<HTMLDialogElement>('arrival').open || $<HTMLDialogElement>('ending').open, key => {
|
||||
if(key==='attack'||key==='gather')action(key);
|
||||
else if(key==='inventory')$('inventory-toggle').click();
|
||||
else if(key.startsWith('slot'))powers.useSlot(Number(key.slice(4))-1);
|
||||
else if(key==='cancel-cast')send('cancel-cast');
|
||||
else if(key==='next-target'||key==='previous-target'){if(!snapshot)return;const p=snapshot.self.entity.position,targets=[snapshot.self.entity,...snapshot.entities].filter(e=>['mob','sentinel','boss','player','corpse'].includes(e.kind)).sort((a,b)=>Math.hypot(a.position.x-p.x,a.position.z-p.z)-Math.hypot(b.position.x-p.x,b.position.z-p.z)||a.id.localeCompare(b.id));if(targets.length){const i=targets.findIndex(e=>e.id===view.selected?.id);selection(targets[(i+(key==='next-target'?1:targets.length-1)+targets.length)%targets.length])}}
|
||||
else if(key==='heal'||key==='return'||key==='jump')send(key);
|
||||
});
|
||||
view.start();
|
||||
@@ -201,6 +212,7 @@ async function boot() {
|
||||
const now = performance.now(), dt = (now - lastInputAt) / 1000;
|
||||
lastInputAt = now;
|
||||
inputElapsed += dt;
|
||||
input.pollController();
|
||||
if (!snapshot || ws?.readyState !== WebSocket.OPEN || $<HTMLDialogElement>('ending').open) return;
|
||||
if(document.hidden||hasOpenMenu()||isEditing(document.activeElement)){
|
||||
input.clear();walkTo=undefined;pendingAction=undefined;view.moving=false;
|
||||
@@ -250,6 +262,7 @@ async function boot() {
|
||||
}, 50);
|
||||
const [loadedConfig, chunks] = await Promise.all([api<Config>('/api/config'), api<Chunk[]>('/api/preview'), view.load()]);
|
||||
config = loadedConfig;
|
||||
powers=createPowerPanel((op,target,x,z,slot)=>{if(op==='cast'){input.clear();walkTo=undefined;pendingAction=undefined;send('move')}send(op,target,x,z,slot)},()=>view.selected,notice,worldPrefix);$('recipes').after(powers.root);$('hud').append(powers.hotbar);$('settings').append(input.settings());
|
||||
const travelButton=document.createElement('button');travelButton.id='travel';travelButton.textContent='Travel';travelButton.title='World travel';$('inventory-toggle').before(travelButton);
|
||||
travelButton.onclick=()=>{if(!snapshot)return;input.clear();walkTo=undefined;pendingAction=undefined;send('move');void showTravel({worldId:config.worldId,route:config.kind==='hub'?'hub':snapshot.world.phase==='won'?'portal':'escape',beforeTravel:()=>{requestedClose=true;},afterTravel:departed=>{requestedClose=departed;}});};
|
||||
$<HTMLInputElement>('zoom').value = String(view.distance);
|
||||
@@ -264,7 +277,8 @@ async function boot() {
|
||||
if (me.character.entity.state === 'dead') showEnding('A life, remembered.', 'This character is permanently dead. A fresh world is a new beginning.', false);
|
||||
else connect();
|
||||
} else {
|
||||
if (me?.active) {
|
||||
if(me&&!me.active)$('passages').append(revivalPanel(worldPrefix));
|
||||
if (me?.active) {
|
||||
visible('join-form', false);
|
||||
const link = document.createElement('a'); link.href = me.active.state==='transit'?'/':`/game?world=${encodeURIComponent(me.active.worldId)}`; link.className = 'command'; link.textContent = me.active.state==='transit'?'Resume travel from your account':`Continue ${me.active.name} in ${me.active.worldId}`; $('passages').append(link);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user