BlueGit

timfa questward

Allow walk-clicks to cancel spell and combat approach.

Entity-armed spells no longer swallow empty-ground clicks, and tile casts yield to walk while approaching so moveTo can clear engage/pending cast.

timfa Tim Falken · pushed by timfa

Authored 2026-08-31 · 2 months ago

Hash
c8fde696fcd2c1fec1ead1fc0c56a64ccef46776
Parent
c2c09cec
1 file changed +26 −6
client/src/play/main.js +26 −6
@@ -918,16 +918,19 @@ function canTalkToEntity (entity)
918 918 return !!(entity && (entity.hasDialogue || entity.talkable || entity.hasShop));
919 919 }
920 920
921 function isApproachingCombatOrCast ()
922 {
923 return autorunFocusEntityId != null || autorunFocusTile != null;
924 }
925
921 926 function handleLeftClick (mouseX, mouseY)
922 927 {
923 928 const tile = view.screenToTile(mouseX, mouseY);
924 929 const armed = spells?.getArmedSpell?.();
925 if (armed?.target === "tile" && armed.canCast && spells.tryCastAtTile(tile.tileX, tile.tileY))
926 {
927 setAutorunFocusTile(tile.tileX, tile.tileY);
928 return;
929 }
930 const approaching = isApproachingCombatOrCast();
930 931
932 // Entity-armed: cast only when a valid target is under the cursor. Empty ground
933 // must fall through so walk cancels cast/attack approach (server moveTo clears it).
931 934 if (armed?.target === "entity" && armed.canCast)
932 935 {
933 936 const snap = nearestSpellEntityAtCursor(mouseX, mouseY);
@@ -936,6 +939,16 @@ function handleLeftClick (mouseX, mouseY)
936 939 setAutorunFocusEntity(snap.entityId);
937 940 return;
938 941 }
942 }
943 // Tile-armed while approaching: prefer walk-cancel over re-targeting the cast.
944 else if (
945 !approaching
946 && armed?.target === "tile"
947 && armed.canCast
948 && spells.tryCastAtTile(tile.tileX, tile.tileY)
949 )
950 {
951 setAutorunFocusTile(tile.tileX, tile.tileY);
939 952 return;
940 953 }
941 954
@@ -1787,14 +1800,21 @@ async function main ()
1787 1800 break;
1788 1801 case MessageType.spellProjectile:
1789 1802 view?.spawnSpellProjectileFx(message);
1803 if (message.casterId === view?.localEntityId)
1804 { clearAutorunFocus(); }
1790 1805 break;
1791 1806 case MessageType.spellFizzle:
1792 1807 view?.spawnSpellFizzleFx(message);
1793 1808 if (message.casterId === view?.localEntityId)
1794 { toasts?.show("Failed to cast spell"); }
1809 {
1810 clearAutorunFocus();
1811 toasts?.show("Failed to cast spell");
1812 }
1795 1813 break;
1796 1814 case MessageType.spellCastFlash:
1797 1815 // Cast-flash dynamic lights skipped (lightmap rebake cost); Light spell uses spellLight*.
1816 if (message.casterId === view?.localEntityId)
1817 { clearAutorunFocus(); }
1798 1818 break;
1799 1819 case MessageType.spellLightAppear:
1800 1820 case MessageType.spellLightUpdate:
@@ -918,16 +918,19 @@ function canTalkToEntity (entity)
918 return !!(entity && (entity.hasDialogue || entity.talkable || entity.hasShop));
918 return !!(entity && (entity.hasDialogue || entity.talkable || entity.hasShop));
919}
919}
920
920
921function isApproachingCombatOrCast ()
922{
923 return autorunFocusEntityId != null || autorunFocusTile != null;
924}
925
921function handleLeftClick (mouseX, mouseY)
926function handleLeftClick (mouseX, mouseY)
922{
927{
923 const tile = view.screenToTile(mouseX, mouseY);
928 const tile = view.screenToTile(mouseX, mouseY);
924 const armed = spells?.getArmedSpell?.();
929 const armed = spells?.getArmedSpell?.();
925 if (armed?.target === "tile" && armed.canCast && spells.tryCastAtTile(tile.tileX, tile.tileY))
930 const approaching = isApproachingCombatOrCast();
926 {
927 setAutorunFocusTile(tile.tileX, tile.tileY);
928 return;
929 }
930
931
932 // Entity-armed: cast only when a valid target is under the cursor. Empty ground
933 // must fall through so walk cancels cast/attack approach (server moveTo clears it).
931 if (armed?.target === "entity" && armed.canCast)
934 if (armed?.target === "entity" && armed.canCast)
932 {
935 {
933 const snap = nearestSpellEntityAtCursor(mouseX, mouseY);
936 const snap = nearestSpellEntityAtCursor(mouseX, mouseY);
@@ -936,6 +939,16 @@ function handleLeftClick (mouseX, mouseY)
936 setAutorunFocusEntity(snap.entityId);
939 setAutorunFocusEntity(snap.entityId);
937 return;
940 return;
938 }
941 }
942 }
943 // Tile-armed while approaching: prefer walk-cancel over re-targeting the cast.
944 else if (
945 !approaching
946 && armed?.target === "tile"
947 && armed.canCast
948 && spells.tryCastAtTile(tile.tileX, tile.tileY)
949 )
950 {
951 setAutorunFocusTile(tile.tileX, tile.tileY);
939 return;
952 return;
940 }
953 }
941
954
@@ -1787,14 +1800,21 @@ async function main ()
1787 break;
1800 break;
1788 case MessageType.spellProjectile:
1801 case MessageType.spellProjectile:
1789 view?.spawnSpellProjectileFx(message);
1802 view?.spawnSpellProjectileFx(message);
1803 if (message.casterId === view?.localEntityId)
1804 { clearAutorunFocus(); }
1790 break;
1805 break;
1791 case MessageType.spellFizzle:
1806 case MessageType.spellFizzle:
1792 view?.spawnSpellFizzleFx(message);
1807 view?.spawnSpellFizzleFx(message);
1793 if (message.casterId === view?.localEntityId)
1808 if (message.casterId === view?.localEntityId)
1794 { toasts?.show("Failed to cast spell"); }
1809 {
1810 clearAutorunFocus();
1811 toasts?.show("Failed to cast spell");
1812 }
1795 break;
1813 break;
1796 case MessageType.spellCastFlash:
1814 case MessageType.spellCastFlash:
1797 // Cast-flash dynamic lights skipped (lightmap rebake cost); Light spell uses spellLight*.
1815 // Cast-flash dynamic lights skipped (lightmap rebake cost); Light spell uses spellLight*.
1816 if (message.casterId === view?.localEntityId)
1817 { clearAutorunFocus(); }
1798 break;
1818 break;
1799 case MessageType.spellLightAppear:
1819 case MessageType.spellLightAppear:
1800 case MessageType.spellLightUpdate:
1820 case MessageType.spellLightUpdate: