Add terrain biomes jumping and extensible gathering professions

This commit is contained in:
dingo
2026-09-08 21:54:23 -04:00
parent 141cb9e6b2
commit df7b245ca7
34 changed files with 1895 additions and 184 deletions
+18 -7
View File
@@ -23,6 +23,7 @@ let inputElapsed = 0;
let walkTo: { x: number; z: number } | undefined;
let pendingAction: { op: string; target: string } | undefined;
let actionElapsed = 0;
let riskyArmed = "", gatherSent = 0;
// A gather target can stay legitimately, persistently unreachable for a long time (a
// depleted resource waits out a real respawn timer measured in minutes, not a stray
// frame) -- retrying it forever would starve everything else. But a *working* attack is
@@ -64,7 +65,7 @@ function send(op: string, target = '', x = 0, z = 0, slot = '') {
}
function selection(entity?: Entity) {
view.selected = entity; visible('target', !!entity);
if (entity) { $('target-name').textContent = entity.name; $('target-health').textContent = ['boss', 'sentinel', 'player'].includes(entity.kind) ? `${Math.ceil(entity.hp)} / ${Math.ceil(entity.maxHp)}` : pretty(entity.kind); }
if (entity) { $('target-name').textContent = entity.name; $('target-health').textContent = ['boss', 'sentinel', 'player'].includes(entity.kind) ? `${Math.ceil(entity.hp)} / ${Math.ceil(entity.maxHp)}` : pretty(entity.kind); const risk=snapshot?.gatherRisks?.[entity.resourceId??entity.kind];if(risk){const skill=snapshot?.self.gathering?.[entity.skillId??''];$('target-health').textContent=`${skill?.name??'Gathering'} ${entity.requiredLevel??1} · Yours ${skill?.level??1} (effective ${skill?.effectiveLevel??1}) · ${risk.seconds.toFixed(1)}s interval · ${risk.allowed?`${risk.failure.toFixed(0)}% failure; on failure ${risk.destruction.toFixed(0)}% destruction, ${risk.negative.toFixed(0)}% chance of ${risk.damage.toFixed(0)} damage + fatigue`:'Too difficult: over +20 levels'}`;} }
}
function action(op: string) {
if (!snapshot) return;
@@ -77,6 +78,13 @@ function action(op: string) {
}
if (!target) { notice('No target nearby.'); return; }
selection(target);
const risk=snapshot.gatherRisks?.[target.resourceId??target.kind];
if(op==='gather'&&risk){
walkTo=undefined;pendingAction=undefined;
if(!risk.allowed){notice('This resource is more than 20 levels above your effective gathering level.');return;}
if(risk.failure>0&&riskyArmed!==target.id){riskyArmed=target.id;notice(`Dangerous attempt: ${risk.failure.toFixed(0)}% failure. Inspect the target risks, then press Gather again to attempt.`);return;}
}
riskyArmed='';gatherSent=0;
pendingAction = { op: target.kind === 'corpse' ? 'loot' : op, target: target.id };
walkTo = target.position;
lastProgress = undefined; lastProgressAt = Date.now();
@@ -89,6 +97,8 @@ function connect() {
ws.onmessage = event => {
const value = JSON.parse(event.data) as Snapshot;
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;
snapshot = value; view.update(value); updateHUD(value);
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);
@@ -130,7 +140,8 @@ function inventory(c: Character) {
row.append(label, button); recipes.append(row);
}
const skills = $('skills'); skills.replaceChildren();
for (const skill of ['gathering', 'crafting', 'combat']) { const label = document.createElement('span'); label.textContent = pretty(skill); const amount = document.createElement('b'); amount.textContent = `${c.skills[skill] ?? 0} XP`; label.append(amount); skills.append(label); }
for(const g of Object.values(c.gathering??{})){const label=document.createElement('span');label.textContent=`${g.name} · Level ${g.level} (effective ${g.effectiveLevel})`;const amount=document.createElement('b');amount.textContent=`${g.xp} XP · ${g.xpToNextLevel} to next`;label.append(amount);skills.append(label);}
for (const skill of ['crafting', 'combat']) { const label = document.createElement('span'); label.textContent = pretty(skill); const amount = document.createElement('b'); amount.textContent = `${c.skills[skill] ?? 0} XP`; label.append(amount); skills.append(label); }
}
function minimap(s: Snapshot) {
const canvas = $<HTMLCanvasElement>('minimap'), ctx = canvas.getContext('2d')!;
@@ -180,7 +191,7 @@ 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==='heal'||key==='return')send(key);
else if(key==='heal'||key==='return'||key==='jump')send(key);
});
view.start(dt => {
inputElapsed += dt;
@@ -211,12 +222,12 @@ async function boot() {
actionElapsed = 0;
const sig = progressSignature();
if (sig !== undefined && sig !== lastProgress) { lastProgress = sig; lastProgressAt = Date.now(); }
if (Date.now() - lastProgressAt > 5000) {
if (Date.now() - lastProgressAt > Math.max(5000,((snapshot.gatherRisks?.[target?.resourceId??target?.kind??'']?.seconds??0)+2)*1000)) {
avoidUntil.set(pendingAction.target, Date.now() + 8000);
const retryOp = pendingAction.op === 'loot' ? 'gather' : pendingAction.op;
walkTo = undefined; pendingAction = undefined;
action(retryOp);
} else { send(pendingAction.op, pendingAction.target); }
if(retryOp!=='gather')action(retryOp);else notice('Gathering stopped. Select a resource to try again.');
} else if(pendingAction.op!=='gather'||!gatherSent) { send(pendingAction.op, pendingAction.target);if(pendingAction.op==='gather')gatherSent=sequence; }
}
}
} else { x = dx / distance; z = dz / distance; actionElapsed = 0.3; }
@@ -265,7 +276,7 @@ async function boot() {
};
document.querySelectorAll<HTMLButtonElement>(`[data-close="${id}"]`).forEach(button=>button.onclick=()=>menu.close());
}
$('attack').onclick = () => input.trigger('attack'); $('gather').onclick = () => input.trigger('gather'); $('heal').onclick = () => input.trigger('heal'); $('keystone').onclick = () => input.trigger('return');
$('jump').onclick = () => input.trigger('jump'); $('attack').onclick = () => input.trigger('attack'); $('gather').onclick = () => input.trigger('gather'); $('heal').onclick = () => input.trigger('heal'); $('keystone').onclick = () => input.trigger('return');
$('target-boss').onclick = () => { selection(snapshot?.entities.find(e => e.id === 'boss')); walkTo = { x: 0, z: 0 }; pendingAction = { op: 'attack', target: 'boss' }; lastProgress = undefined; lastProgressAt = Date.now(); };
$('dev-boss').onclick = () => void api('/api/dev/boss', {}).catch(e => notice(e.message));
$('reconnect').onclick = () => location.reload();