Add ranged combat area effects and admin-authored mobs
This commit is contained in:
+18
-10
@@ -39,6 +39,7 @@ let lastProgressAt = 0;
|
||||
function progressSignature(): number | undefined {
|
||||
if (!pendingAction || !snapshot) return undefined;
|
||||
if (pendingAction.op === 'attack') {
|
||||
if (pendingAction.target === snapshot.self.entity.id) return snapshot.self.entity.hp;
|
||||
if (pendingAction.target === 'boss') return snapshot.world.bossHp;
|
||||
return snapshot.entities.find(e => e.id === pendingAction!.target)?.hp;
|
||||
}
|
||||
@@ -65,16 +66,16 @@ 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); 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'}`;} }
|
||||
if (entity) { $('target-name').textContent = entity.name; $('target-health').textContent = ['boss', 'sentinel', 'mob', '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;
|
||||
const now = Date.now();
|
||||
const kinds = op === 'attack' ? ['boss', 'sentinel'] : ['tree', 'ore', 'herb', 'corpse'];
|
||||
const kinds = op === 'attack' ? (snapshot.self.attack?.effect==='heal'?['player']:['boss', 'sentinel','mob']) : ['tree', 'ore', 'herb', 'corpse'];
|
||||
let target = view.selected;
|
||||
if (!target || !kinds.includes(target.kind) || (avoidUntil.get(target.id) ?? 0) > now) {
|
||||
const p = snapshot.self.entity.position;
|
||||
target = snapshot.entities.filter(e => kinds.includes(e.kind) && (avoidUntil.get(e.id) ?? 0) <= now).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))[0];
|
||||
target = [...snapshot.entities,...(snapshot.self.attack?.effect==='heal'?[snapshot.self.entity]:[])].filter(e => kinds.includes(e.kind) && (avoidUntil.get(e.id) ?? 0) <= now).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))[0];
|
||||
}
|
||||
if (!target) { notice('No target nearby.'); return; }
|
||||
selection(target);
|
||||
@@ -202,11 +203,17 @@ async function boot() {
|
||||
}
|
||||
let {x,z} = input.movement;
|
||||
if (x || z) { walkTo = undefined; pendingAction = undefined; }
|
||||
const actionTarget = pendingAction?.target === snapshot.self.entity.id ? snapshot.self.entity : snapshot.entities.find(e => e.id === pendingAction?.target);
|
||||
if (pendingAction?.op === 'attack') {
|
||||
if (!actionTarget || actionTarget.hp <= 0) { walkTo = undefined; pendingAction = undefined; }
|
||||
else walkTo = actionTarget.position;
|
||||
}
|
||||
if (walkTo) {
|
||||
const p = snapshot.self.entity.position, dx = walkTo.x - p.x, dz = walkTo.z - p.z, distance = Math.hypot(dx, dz);
|
||||
const target = snapshot.entities.find(e => e.id === pendingAction?.target);
|
||||
const range = pendingAction ? pendingAction.op === 'attack' ? config.attackRange + (target?.kind === 'boss' ? 3 : -0.5) : config.gatherRange - 0.5 : 0.8;
|
||||
if (distance <= range) {
|
||||
const target = actionTarget;
|
||||
const range = pendingAction ? pendingAction.op === 'attack' ? (snapshot.self.attack?.range??config.attackRange) + (target?.id === 'boss' ? 3 : -0.5) : config.gatherRange - 0.5 : 0.8;
|
||||
const reach = pendingAction?.op === 'attack' && target ? Math.hypot(distance, target.position.y-p.y) : distance;
|
||||
if (reach <= range) {
|
||||
if (!pendingAction) { walkTo = undefined; }
|
||||
// A single fire-and-forget attempt can land a hair outside the authoritative
|
||||
// server position (which may lag a stale/throttled client render) and get
|
||||
@@ -222,15 +229,16 @@ async function boot() {
|
||||
actionElapsed = 0;
|
||||
const sig = progressSignature();
|
||||
if (sig !== undefined && sig !== lastProgress) { lastProgress = sig; lastProgressAt = Date.now(); }
|
||||
if (Date.now() - lastProgressAt > Math.max(5000,((snapshot.gatherRisks?.[target?.resourceId??target?.kind??'']?.seconds??0)+2)*1000)) {
|
||||
const attackWait = pendingAction.op === 'attack' && snapshot.self.attack ? snapshot.self.attack.cooldown + snapshot.self.attack.range / snapshot.self.attack.speed + 2 : 0;
|
||||
if (Date.now() - lastProgressAt > Math.max(5000,attackWait*1000,((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;
|
||||
if(retryOp!=='gather')action(retryOp);else notice('Gathering stopped. Select a resource to try again.');
|
||||
if(retryOp!=='gather' && snapshot.self.attack?.effect!=='heal')action(retryOp);else notice('Action stopped. Select a target 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; }
|
||||
} else if (distance > .01) { x = dx / distance; z = dz / distance; actionElapsed = 0.3; }
|
||||
}
|
||||
view.moving = !!(x || z);
|
||||
if (inputElapsed >= 0.05) { send('move', '', x, z); inputElapsed = 0; }
|
||||
@@ -295,7 +303,7 @@ async function boot() {
|
||||
view.canvas.addEventListener('pointerdown', event => {
|
||||
if (!snapshot || hasOpenMenu() || $<HTMLDialogElement>('arrival').open || $<HTMLDialogElement>('ending').open || event.button !== 0) return;
|
||||
const hit = view.pick(event.clientX, event.clientY);
|
||||
if (hit.entity) { selection(hit.entity); action(['boss', 'sentinel'].includes(hit.entity.kind) ? 'attack' : 'gather'); }
|
||||
if (hit.entity) { selection(hit.entity); action(['boss', 'sentinel','mob','player'].includes(hit.entity.kind) ? 'attack' : 'gather'); }
|
||||
else if (hit.point) { selection(); walkTo = hit.point; pendingAction = undefined; }
|
||||
});
|
||||
Object.defineProperty(window, '__aeternalis', { value: { diagnostics: () => view.diagnostics(), get snapshot() { return snapshot; }, get walkTo() { return walkTo; }, get pendingAction() { return pendingAction; }, get keys() { return input.keys; } }, configurable: true });
|
||||
|
||||
Reference in New Issue
Block a user