BlueGit

timfa questward

Fix batch craft progress and delayed ranged hit FX.

Restart the craft progress bar on continuing batches, steer projectiles toward the live target pose, and show ranged hit feedback only when the projectile lands.

timfa Tim Falken · pushed by timfa

Authored 2026-08-27 · 2 months ago

Hash
e6eae69dab440b62a74f796914bd2ddc88c1c035
Parent
12a56499
7 files changed +129 −13
client/src/play/crafting.js +13 −0
@@ -719,11 +719,24 @@ export function initCrafting ({
719 719 renderDetail();
720 720 return;
721 721 }
722 crafting = true;
723 craftButton.disabled = true;
724 if (craftBatchButton)
725 { craftBatchButton.disabled = true; }
726 if (craftBatchAllButton)
727 { craftBatchAllButton.disabled = true; }
728 progressWrap.hidden = false;
729 progressFill.style.width = "0%";
722 730 statusEl.textContent = "Crafting…";
723 731 craftStartedAt = performance.now();
724 732 const durationMs = craftDurationMs(recipe, CRAFT_DURATION_MS);
725 733 if (craftTimer != null)
726 734 { clearTimeout(craftTimer); }
735 if (craftAnimFrame != null)
736 {
737 cancelAnimationFrame(craftAnimFrame);
738 craftAnimFrame = null;
739 }
727 740 animateProgress(durationMs);
728 741 craftTimer = window.setTimeout(() => finishCraft(true), durationMs);
729 742 renderDetail();
@@ -719,11 +719,24 @@ export function initCrafting ({
719 renderDetail();
719 renderDetail();
720 return;
720 return;
721 }
721 }
722 crafting = true;
723 craftButton.disabled = true;
724 if (craftBatchButton)
725 { craftBatchButton.disabled = true; }
726 if (craftBatchAllButton)
727 { craftBatchAllButton.disabled = true; }
728 progressWrap.hidden = false;
729 progressFill.style.width = "0%";
722 statusEl.textContent = "Crafting…";
730 statusEl.textContent = "Crafting…";
723 craftStartedAt = performance.now();
731 craftStartedAt = performance.now();
724 const durationMs = craftDurationMs(recipe, CRAFT_DURATION_MS);
732 const durationMs = craftDurationMs(recipe, CRAFT_DURATION_MS);
725 if (craftTimer != null)
733 if (craftTimer != null)
726 { clearTimeout(craftTimer); }
734 { clearTimeout(craftTimer); }
735 if (craftAnimFrame != null)
736 {
737 cancelAnimationFrame(craftAnimFrame);
738 craftAnimFrame = null;
739 }
727 animateProgress(durationMs);
740 animateProgress(durationMs);
728 craftTimer = window.setTimeout(() => finishCraft(true), durationMs);
741 craftTimer = window.setTimeout(() => finishCraft(true), durationMs);
729 renderDetail();
742 renderDetail();
client/src/play/main.js +31 −9
@@ -1391,17 +1391,39 @@ async function main ()
1391 1391 crafting?.refresh();
1392 1392 break;
1393 1393 case MessageType.combatHit:
1394 view?.updateEntityHealth(message.targetId, message.health, message.maxHealth);
1395 view?.flashDamage(message.targetId);
1396 view?.spawnDamageNumber(message.targetId, message.damage);
1397 if (message.targetId === view?.localEntityId)
1394 {
1395 const applyHit = () =>
1398 1396 {
1399 healthUi?.apply({
1400 current: message.health,
1401 max: message.maxHealth
1402 });
1403 }
1397 view?.updateEntityHealth(message.targetId, message.health, message.maxHealth);
1398 view?.flashDamage(message.targetId);
1399 view?.spawnDamageNumber(message.targetId, message.damage);
1400 if (message.targetId === view?.localEntityId)
1401 {
1402 healthUi?.apply({
1403 current: message.health,
1404 max: message.maxHealth
1405 });
1406 }
1407 };
1408 if (!view?.deferCombatHit?.(message, applyHit))
1409 { applyHit(); }
1410 break;
1411 }
1412 case MessageType.combatMiss:
1413 view?.markProjectileMiss?.(message);
1404 1414 break;
1415 case MessageType.combatBlock:
1416 {
1417 const applyBlock = () =>
1418 {
1419 view?.flashDamage(message.targetId);
1420 if (message.health != null)
1421 { view?.updateEntityHealth(message.targetId, message.health, message.maxHealth); }
1422 };
1423 if (!view?.deferCombatHit?.(message, applyBlock))
1424 { applyBlock(); }
1425 break;
1426 }
1405 1427 case MessageType.entityHealth:
1406 1428 view?.updateEntityHealth(message.entityId, message.health, message.maxHealth);
1407 1429 if (message.entityId === view?.localEntityId)
@@ -1391,17 +1391,39 @@ async function main ()
1391 crafting?.refresh();
1391 crafting?.refresh();
1392 break;
1392 break;
1393 case MessageType.combatHit:
1393 case MessageType.combatHit:
1394 view?.updateEntityHealth(message.targetId, message.health, message.maxHealth);
1394 {
1395 view?.flashDamage(message.targetId);
1395 const applyHit = () =>
1396 view?.spawnDamageNumber(message.targetId, message.damage);
1397 if (message.targetId === view?.localEntityId)
1398 {
1396 {
1399 healthUi?.apply({
1397 view?.updateEntityHealth(message.targetId, message.health, message.maxHealth);
1400 current: message.health,
1398 view?.flashDamage(message.targetId);
1401 max: message.maxHealth
1399 view?.spawnDamageNumber(message.targetId, message.damage);
1402 });
1400 if (message.targetId === view?.localEntityId)
1403 }
1401 {
1402 healthUi?.apply({
1403 current: message.health,
1404 max: message.maxHealth
1405 });
1406 }
1407 };
1408 if (!view?.deferCombatHit?.(message, applyHit))
1409 { applyHit(); }
1410 break;
1411 }
1412 case MessageType.combatMiss:
1413 view?.markProjectileMiss?.(message);
1404 break;
1414 break;
1415 case MessageType.combatBlock:
1416 {
1417 const applyBlock = () =>
1418 {
1419 view?.flashDamage(message.targetId);
1420 if (message.health != null)
1421 { view?.updateEntityHealth(message.targetId, message.health, message.maxHealth); }
1422 };
1423 if (!view?.deferCombatHit?.(message, applyBlock))
1424 { applyBlock(); }
1425 break;
1426 }
1405 case MessageType.entityHealth:
1427 case MessageType.entityHealth:
1406 view?.updateEntityHealth(message.entityId, message.health, message.maxHealth);
1428 view?.updateEntityHealth(message.entityId, message.health, message.maxHealth);
1407 if (message.entityId === view?.localEntityId)
1429 if (message.entityId === view?.localEntityId)
client/src/render/worldView.js +78 −3
@@ -717,6 +717,50 @@ export class WorldView
717 717 });
718 718 }
719 719
720 /**
721 * Queue combat-hit presentation until a matching in-flight projectile lands.
722 * Returns true when deferred; caller should apply immediately when false.
723 */
724 deferCombatHit (message, apply)
725 {
726 if (typeof apply !== "function" || message?.targetId == null)
727 { return false; }
728 const attackerId = message.attackerId ?? null;
729 const targetId = message.targetId;
730 const swipe = this.swipes.find((entry) =>
731 entry.lerp
732 && entry.onImpact == null
733 && entry.targetId === targetId
734 && (attackerId == null || entry.attackerId === attackerId)
735 && (entry.until ?? 0) > performance.now());
736 if (!swipe)
737 { return false; }
738 swipe.onImpact = apply;
739 swipe.trackTarget = true;
740 return true;
741 }
742
743 /** Stop tracking a living target (misses fly to a fixed tile). */
744 markProjectileMiss (message)
745 {
746 const attackerId = message?.attackerId ?? null;
747 const targetId = message?.targetId ?? null;
748 for (const swipe of this.swipes)
749 {
750 if (!swipe.lerp || swipe.onImpact != null)
751 { continue; }
752 if (targetId != null && swipe.targetId !== targetId)
753 { continue; }
754 if (attackerId != null && swipe.attackerId !== attackerId)
755 { continue; }
756 swipe.trackTarget = false;
757 if (message.tileX != null)
758 { swipe.tileX = message.tileX; }
759 if (message.tileY != null)
760 { swipe.tileY = message.tileY; }
761 }
762 }
763
720 764 spawnSkillLevelUp (entityId, payload)
721 765 {
722 766 const level = payload?.level | 0;
@@ -1390,6 +1434,7 @@ export class WorldView
1390 1434 );
1391 1435 const started = performance.now();
1392 1436 const durationMs = payload.durationMs ?? 400;
1437 const trackTarget = payload.trackTarget !== false && payload.targetId != null;
1393 1438 this.swipes.push({
1394 1439 object,
1395 1440 until: started + durationMs,
@@ -1400,7 +1445,11 @@ export class WorldView
1400 1445 fromTileX: payload.fromTileX,
1401 1446 fromTileY: payload.fromTileY,
1402 1447 tileX: payload.tileX,
1403 tileY: payload.tileY
1448 tileY: payload.tileY,
1449 attackerId: payload.attackerId ?? null,
1450 targetId: payload.targetId ?? null,
1451 trackTarget,
1452 onImpact: null
1404 1453 });
1405 1454 }
1406 1455
@@ -1435,7 +1484,11 @@ export class WorldView
1435 1484 fromTileX: payload.fromTileX,
1436 1485 fromTileY: payload.fromTileY,
1437 1486 tileX: payload.tileX,
1438 tileY: payload.tileY
1487 tileY: payload.tileY,
1488 attackerId: payload.casterId ?? null,
1489 targetId: payload.targetId ?? null,
1490 trackTarget: payload.targetId != null,
1491 onImpact: null
1439 1492 });
1440 1493 }
1441 1494
@@ -3146,7 +3199,7 @@ export class WorldView
3146 3199 const durationMs = swipe.durationMs ?? 400;
3147 3200 const t = Math.min(1, (now - swipe.started) / durationMs);
3148 3201 const fromPivot = tilePivot(swipe.fromTileX, swipe.fromTileY, this.tileSize());
3149 const toPivot = tilePivot(swipe.tileX, swipe.tileY, this.tileSize());
3202 const toPivot = this.#projectileEndPivot(swipe);
3150 3203 const x = fromPivot.x + (toPivot.x - fromPivot.x) * t;
3151 3204 const y = fromPivot.y + (toPivot.y - fromPivot.y) * t;
3152 3205 const sortY = Math.max(fromPivot.y, toPivot.y) + 0.02;
@@ -3190,11 +3243,33 @@ export class WorldView
3190 3243 }
3191 3244 if (swipe.until > now)
3192 3245 { return true; }
3246 const onImpact = swipe.onImpact;
3247 swipe.onImpact = null;
3193 3248 swipe.object?.destroy();
3249 if (typeof onImpact === "function")
3250 {
3251 try
3252 { onImpact(); }
3253 catch (_)
3254 { /* presentation only */ }
3255 }
3194 3256 return false;
3195 3257 });
3196 3258 }
3197 3259
3260 #projectileEndPivot (swipe)
3261 {
3262 if (swipe.trackTarget && swipe.targetId != null)
3263 {
3264 const target = this.entities.get(swipe.targetId);
3265 if (target && Number.isFinite(target.visualX) && Number.isFinite(target.visualY))
3266 {
3267 return { x: target.visualX, y: target.visualY };
3268 }
3269 }
3270 return tilePivot(swipe.tileX, swipe.tileY, this.tileSize());
3271 }
3272
3198 3273 #updateDamageNumbers (now)
3199 3274 {
3200 3275 const layer = this.damageNumbersEl;
@@ -717,6 +717,50 @@ export class WorldView
717 });
717 });
718 }
718 }
719
719
720 /**
721 * Queue combat-hit presentation until a matching in-flight projectile lands.
722 * Returns true when deferred; caller should apply immediately when false.
723 */
724 deferCombatHit (message, apply)
725 {
726 if (typeof apply !== "function" || message?.targetId == null)
727 { return false; }
728 const attackerId = message.attackerId ?? null;
729 const targetId = message.targetId;
730 const swipe = this.swipes.find((entry) =>
731 entry.lerp
732 && entry.onImpact == null
733 && entry.targetId === targetId
734 && (attackerId == null || entry.attackerId === attackerId)
735 && (entry.until ?? 0) > performance.now());
736 if (!swipe)
737 { return false; }
738 swipe.onImpact = apply;
739 swipe.trackTarget = true;
740 return true;
741 }
742
743 /** Stop tracking a living target (misses fly to a fixed tile). */
744 markProjectileMiss (message)
745 {
746 const attackerId = message?.attackerId ?? null;
747 const targetId = message?.targetId ?? null;
748 for (const swipe of this.swipes)
749 {
750 if (!swipe.lerp || swipe.onImpact != null)
751 { continue; }
752 if (targetId != null && swipe.targetId !== targetId)
753 { continue; }
754 if (attackerId != null && swipe.attackerId !== attackerId)
755 { continue; }
756 swipe.trackTarget = false;
757 if (message.tileX != null)
758 { swipe.tileX = message.tileX; }
759 if (message.tileY != null)
760 { swipe.tileY = message.tileY; }
761 }
762 }
763
720 spawnSkillLevelUp (entityId, payload)
764 spawnSkillLevelUp (entityId, payload)
721 {
765 {
722 const level = payload?.level | 0;
766 const level = payload?.level | 0;
@@ -1390,6 +1434,7 @@ export class WorldView
1390 );
1434 );
1391 const started = performance.now();
1435 const started = performance.now();
1392 const durationMs = payload.durationMs ?? 400;
1436 const durationMs = payload.durationMs ?? 400;
1437 const trackTarget = payload.trackTarget !== false && payload.targetId != null;
1393 this.swipes.push({
1438 this.swipes.push({
1394 object,
1439 object,
1395 until: started + durationMs,
1440 until: started + durationMs,
@@ -1400,7 +1445,11 @@ export class WorldView
1400 fromTileX: payload.fromTileX,
1445 fromTileX: payload.fromTileX,
1401 fromTileY: payload.fromTileY,
1446 fromTileY: payload.fromTileY,
1402 tileX: payload.tileX,
1447 tileX: payload.tileX,
1403 tileY: payload.tileY
1448 tileY: payload.tileY,
1449 attackerId: payload.attackerId ?? null,
1450 targetId: payload.targetId ?? null,
1451 trackTarget,
1452 onImpact: null
1404 });
1453 });
1405 }
1454 }
1406
1455
@@ -1435,7 +1484,11 @@ export class WorldView
1435 fromTileX: payload.fromTileX,
1484 fromTileX: payload.fromTileX,
1436 fromTileY: payload.fromTileY,
1485 fromTileY: payload.fromTileY,
1437 tileX: payload.tileX,
1486 tileX: payload.tileX,
1438 tileY: payload.tileY
1487 tileY: payload.tileY,
1488 attackerId: payload.casterId ?? null,
1489 targetId: payload.targetId ?? null,
1490 trackTarget: payload.targetId != null,
1491 onImpact: null
1439 });
1492 });
1440 }
1493 }
1441
1494
@@ -3146,7 +3199,7 @@ export class WorldView
3146 const durationMs = swipe.durationMs ?? 400;
3199 const durationMs = swipe.durationMs ?? 400;
3147 const t = Math.min(1, (now - swipe.started) / durationMs);
3200 const t = Math.min(1, (now - swipe.started) / durationMs);
3148 const fromPivot = tilePivot(swipe.fromTileX, swipe.fromTileY, this.tileSize());
3201 const fromPivot = tilePivot(swipe.fromTileX, swipe.fromTileY, this.tileSize());
3149 const toPivot = tilePivot(swipe.tileX, swipe.tileY, this.tileSize());
3202 const toPivot = this.#projectileEndPivot(swipe);
3150 const x = fromPivot.x + (toPivot.x - fromPivot.x) * t;
3203 const x = fromPivot.x + (toPivot.x - fromPivot.x) * t;
3151 const y = fromPivot.y + (toPivot.y - fromPivot.y) * t;
3204 const y = fromPivot.y + (toPivot.y - fromPivot.y) * t;
3152 const sortY = Math.max(fromPivot.y, toPivot.y) + 0.02;
3205 const sortY = Math.max(fromPivot.y, toPivot.y) + 0.02;
@@ -3190,11 +3243,33 @@ export class WorldView
3190 }
3243 }
3191 if (swipe.until > now)
3244 if (swipe.until > now)
3192 { return true; }
3245 { return true; }
3246 const onImpact = swipe.onImpact;
3247 swipe.onImpact = null;
3193 swipe.object?.destroy();
3248 swipe.object?.destroy();
3249 if (typeof onImpact === "function")
3250 {
3251 try
3252 { onImpact(); }
3253 catch (_)
3254 { /* presentation only */ }
3255 }
3194 return false;
3256 return false;
3195 });
3257 });
3196 }
3258 }
3197
3259
3260 #projectileEndPivot (swipe)
3261 {
3262 if (swipe.trackTarget && swipe.targetId != null)
3263 {
3264 const target = this.entities.get(swipe.targetId);
3265 if (target && Number.isFinite(target.visualX) && Number.isFinite(target.visualY))
3266 {
3267 return { x: target.visualX, y: target.visualY };
3268 }
3269 }
3270 return tilePivot(swipe.tileX, swipe.tileY, this.tileSize());
3271 }
3272
3198 #updateDamageNumbers (now)
3273 #updateDamageNumbers (now)
3199 {
3274 {
3200 const layer = this.damageNumbersEl;
3275 const layer = this.damageNumbersEl;
server/src/combat/service.js +3 −1
@@ -912,7 +912,8 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D
912 912 tileX: endX,
913 913 tileY: endY,
914 914 durationMs: RANGED_PROJECTILE_MS,
915 ...publicDualTint(projectileDualTintFromAttacker(world.ecs, attackerHandle)) ?? {}
915 trackTarget: outcome?.type !== "combat-miss",
916 ...(publicDualTint(projectileDualTintFromAttacker(world.ecs, attackerHandle)) ?? {})
916 917 });
917 918 return events.concat(hitEvents);
918 919 }
@@ -1071,6 +1072,7 @@ export function applyRemoteRangedShot (world, payload)
1071 1072 tileX: endX,
1072 1073 tileY: endY,
1073 1074 durationMs: RANGED_PROJECTILE_MS,
1075 trackTarget: outcome?.type !== "combat-miss",
1074 1076 shaftTint: payload.shaftTint ?? null,
1075 1077 tipTint: payload.tipTint ?? null
1076 1078 }, ...hitEvents];
@@ -912,7 +912,8 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D
912 tileX: endX,
912 tileX: endX,
913 tileY: endY,
913 tileY: endY,
914 durationMs: RANGED_PROJECTILE_MS,
914 durationMs: RANGED_PROJECTILE_MS,
915 ...publicDualTint(projectileDualTintFromAttacker(world.ecs, attackerHandle)) ?? {}
915 trackTarget: outcome?.type !== "combat-miss",
916 ...(publicDualTint(projectileDualTintFromAttacker(world.ecs, attackerHandle)) ?? {})
916 });
917 });
917 return events.concat(hitEvents);
918 return events.concat(hitEvents);
918}
919}
@@ -1071,6 +1072,7 @@ export function applyRemoteRangedShot (world, payload)
1071 tileX: endX,
1072 tileX: endX,
1072 tileY: endY,
1073 tileY: endY,
1073 durationMs: RANGED_PROJECTILE_MS,
1074 durationMs: RANGED_PROJECTILE_MS,
1075 trackTarget: outcome?.type !== "combat-miss",
1074 shaftTint: payload.shaftTint ?? null,
1076 shaftTint: payload.shaftTint ?? null,
1075 tipTint: payload.tipTint ?? null
1077 tipTint: payload.tipTint ?? null
1076 }, ...hitEvents];
1078 }, ...hitEvents];
server/src/gateway/websocket.js +2 −0
@@ -1754,6 +1754,7 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1754 1754 tileX: event.tileX,
1755 1755 tileY: event.tileY,
1756 1756 durationMs: event.durationMs ?? 400,
1757 trackTarget: event.trackTarget !== false,
1757 1758 shaftTint: event.shaftTint ?? null,
1758 1759 tipTint: event.tipTint ?? null
1759 1760 });
@@ -1766,6 +1767,7 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1766 1767 send(session, {
1767 1768 type: MessageType.spellProjectile,
1768 1769 casterId: event.casterId,
1770 targetId: event.targetId ?? null,
1769 1771 spellId: event.spellId,
1770 1772 fromTileX: event.fromTileX,
1771 1773 fromTileY: event.fromTileY,
@@ -1754,6 +1754,7 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1754 tileX: event.tileX,
1754 tileX: event.tileX,
1755 tileY: event.tileY,
1755 tileY: event.tileY,
1756 durationMs: event.durationMs ?? 400,
1756 durationMs: event.durationMs ?? 400,
1757 trackTarget: event.trackTarget !== false,
1757 shaftTint: event.shaftTint ?? null,
1758 shaftTint: event.shaftTint ?? null,
1758 tipTint: event.tipTint ?? null
1759 tipTint: event.tipTint ?? null
1759 });
1760 });
@@ -1766,6 +1767,7 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1766 send(session, {
1767 send(session, {
1767 type: MessageType.spellProjectile,
1768 type: MessageType.spellProjectile,
1768 casterId: event.casterId,
1769 casterId: event.casterId,
1770 targetId: event.targetId ?? null,
1769 spellId: event.spellId,
1771 spellId: event.spellId,
1770 fromTileX: event.fromTileX,
1772 fromTileX: event.fromTileX,
1771 fromTileY: event.fromTileY,
1773 fromTileY: event.fromTileY,
server/src/spells/mobCast.js +1 −0
@@ -99,6 +99,7 @@ export function castMobAttackSpell (world, casterId, targetId, spellId, now = Da
99 99 type: "spell-projectile",
100 100 casterId,
101 101 spellId,
102 targetId,
102 103 fromTileX: from.tileX,
103 104 fromTileY: from.tileY,
104 105 tileX: targetPos.tileX,
@@ -99,6 +99,7 @@ export function castMobAttackSpell (world, casterId, targetId, spellId, now = Da
99 type: "spell-projectile",
99 type: "spell-projectile",
100 casterId,
100 casterId,
101 spellId,
101 spellId,
102 targetId,
102 fromTileX: from.tileX,
103 fromTileX: from.tileX,
103 fromTileY: from.tileY,
104 fromTileY: from.tileY,
104 tileX: targetPos.tileX,
105 tileX: targetPos.tileX,
server/src/spells/service.js +1 −0
@@ -428,6 +428,7 @@ function executeCast (world, sessionId, characterId, spellId, target, now)
428 428 type: "spell-projectile",
429 429 casterId: entityId,
430 430 spellId,
431 targetId: target.targetEntityId ?? null,
431 432 fromTileX: from.tileX,
432 433 fromTileY: from.tileY,
433 434 tileX: target.tileX,
@@ -428,6 +428,7 @@ function executeCast (world, sessionId, characterId, spellId, target, now)
428 type: "spell-projectile",
428 type: "spell-projectile",
429 casterId: entityId,
429 casterId: entityId,
430 spellId,
430 spellId,
431 targetId: target.targetEntityId ?? null,
431 fromTileX: from.tileX,
432 fromTileX: from.tileX,
432 fromTileY: from.tileY,
433 fromTileY: from.tileY,
433 tileX: target.tileX,
434 tileX: target.tileX,