Fix double ground-item qty labels and autorun on combat approach.
Ground tooltips use itemDisplayName so the client can append quantity once. Autorun now tracks attack/cast focus and runs while the server is pathing toward the target.
@@ -99,6 +99,9 @@ let approachMove = null;
99
99
let followTargetId = null;
100
100
/** Destination of the active click/approach moveTo for autorun distance checks. */
101
101
let moveDest = null;
102
/** Entity / tile focus for server-driven approach (attack, cast) — no client moveTo. */
103
let autorunFocusEntityId = null;
104
let autorunFocusTile = null;
102
105
/** After stamina hits 0 while autorunning, wait until ≥50% before running again. */
103
106
let autorunWaitingStamina = false;
104
107
/** Framework can report mousePressed for two frames; latch so one physical click is one command. */
@@ -110,6 +113,7 @@ const AUTORUN_STAMINA_RESUME_RATIO = 0.5;
110
113
function sendPlayerMoveTo (tileX, tileY)
111
114
{
112
115
followTargetId = null;
116
clearAutorunFocus();
113
117
moveDest = { tileX: tileX | 0, tileY: tileY | 0 };
114
118
socket.send({ type: MessageType.moveTo, tileX: moveDest.tileX, tileY: moveDest.tileY });
115
119
syncAutorun();
@@ -119,10 +123,58 @@ function sendPlayerFollow (targetEntityId)
119
123
{
120
124
followTargetId = targetEntityId | 0;
121
125
moveDest = null;
126
clearAutorunFocus();
122
127
autorunWaitingStamina = false;
123
128
socket.send({ type: MessageType.follow, targetEntityId: followTargetId });
124
129
}
125
130
131
function clearAutorunFocus ()
132
{
133
autorunFocusEntityId = null;
134
autorunFocusTile = null;
135
}
136
137
function setAutorunFocusEntity (entityId)
138
{
139
moveDest = null;
140
autorunFocusTile = null;
141
autorunFocusEntityId = entityId | 0;
142
syncAutorun();
143
}
144
145
function setAutorunFocusTile (tileX, tileY)
146
{
147
moveDest = null;
148
autorunFocusEntityId = null;
149
autorunFocusTile = { tileX: tileX | 0, tileY: tileY | 0 };
150
syncAutorun();
151
}
152
153
function resolveAutorunDest ()
154
{
155
if (moveDest)
156
{ return moveDest; }
157
if (autorunFocusEntityId != null)
158
{
159
const target = view?.entities?.get(autorunFocusEntityId);
160
if (!target)
161
{ return null; }
162
return { tileX: target.tileX | 0, tileY: target.tileY | 0 };
163
}
164
return autorunFocusTile;
165
}
166
167
function localEntityIsMoving (local)
168
{
169
if (!local)
170
{ return false; }
171
if (local.lerpStarted != null)
172
{ return true; }
173
const dx = (local.visualX ?? 0) - (local.targetX ?? local.visualX ?? 0);
174
const dy = (local.visualY ?? 0) - (local.targetY ?? local.visualY ?? 0);
175
return (dx * dx + dy * dy) > 0.25;
176
}
177
126
178
function requestGaitIfNeeded (next)
127
179
{
128
180
if (next !== GAIT.walk && next !== GAIT.run)
@@ -149,16 +201,23 @@ function syncAutorun ()
149
201
if (settings.autorun !== "on")
150
202
{ return; }
151
203
const local = view?.entities?.get(view.localEntityId);
152
if (!local || !moveDest)
204
const dest = resolveAutorunDest();
205
if (!local || !dest)
153
206
{ return; }
154
if (local.tileX === moveDest.tileX && local.tileY === moveDest.tileY)
207
if (moveDest && local.tileX === moveDest.tileX && local.tileY === moveDest.tileY)
155
208
{
156
209
moveDest = null;
157
210
autorunWaitingStamina = false;
158
211
requestGaitIfNeeded(GAIT.walk);
159
212
return;
160
213
}
161
const dist = chebyshev(local.tileX, local.tileY, moveDest.tileX, moveDest.tileY);
214
// Attack / cast approach is server-pathed — only run while tiles are changing.
215
if (!moveDest && !localEntityIsMoving(local))
216
{
217
requestGaitIfNeeded(GAIT.walk);
218
return;
219
}
220
const dist = chebyshev(local.tileX, local.tileY, dest.tileX, dest.tileY);
162
221
const wantRun = dist > AUTORUN_DISTANCE_TILES;
163
222
const current = staminaUi?.getCurrent?.() ?? 0;
164
223
const max = Math.max(1, staminaUi?.getMax?.() ?? 1);
@@ -840,6 +899,7 @@ function flushPendingPickup ()
840
899
function requestAttack (targetEntityId)
841
900
{
842
901
clearAllPendingActions();
902
setAutorunFocusEntity(targetEntityId);
843
903
socket.send({ type: MessageType.attack, targetEntityId });
844
904
}
845
905
@@ -863,13 +923,19 @@ function handleLeftClick (mouseX, mouseY)
863
923
const tile = view.screenToTile(mouseX, mouseY);
864
924
const armed = spells?.getArmedSpell?.();
865
925
if (armed?.target === "tile" && armed.canCast && spells.tryCastAtTile(tile.tileX, tile.tileY))
866
{ return; }
926
{
927
setAutorunFocusTile(tile.tileX, tile.tileY);
928
return;
929
}
867
930
868
931
if (armed?.target === "entity" && armed.canCast)
869
932
{
870
933
const snap = nearestSpellEntityAtCursor(mouseX, mouseY);
871
934
if (snap && spells.tryCastAtEntity(snap.entityId))
872
{ return; }
935
{
936
setAutorunFocusEntity(snap.entityId);
937
return;
938
}
873
939
return;
874
940
}
875
941
@@ -1676,6 +1742,8 @@ async function main ()
1676
1742
{ closeOpenUiIfTooFar(); }
1677
1743
break;
1678
1744
case MessageType.entityDespawn:
1745
if (message.entityId === autorunFocusEntityId)
1746
{ clearAutorunFocus(); }
1679
1747
view?.despawnEntity(message.entityId);
1680
1748
break;
1681
1749
case MessageType.entityAppearance:
@@ -2013,6 +2081,7 @@ function returnToMenu (reason = "")
2013
2081
playing = false;
2014
2082
followTargetId = null;
2015
2083
moveDest = null;
2084
clearAutorunFocus();
2016
2085
autorunWaitingStamina = false;
2017
2086
clearAllPendingActions();
2018
2087
clearUiFocus();
@@ -99,6 +99,9 @@ let approachMove = null;99
let followTargetId = null;99
let followTargetId = null;100
/** Destination of the active click/approach moveTo for autorun distance checks. */100
/** Destination of the active click/approach moveTo for autorun distance checks. */101
let moveDest = null;101
let moveDest = null;102
/** Entity / tile focus for server-driven approach (attack, cast) — no client moveTo. */103
let autorunFocusEntityId = null;104
let autorunFocusTile = null;102
/** After stamina hits 0 while autorunning, wait until ≥50% before running again. */105
/** After stamina hits 0 while autorunning, wait until ≥50% before running again. */103
let autorunWaitingStamina = false;106
let autorunWaitingStamina = false;104
/** Framework can report mousePressed for two frames; latch so one physical click is one command. */107
/** Framework can report mousePressed for two frames; latch so one physical click is one command. */@@ -110,6 +113,7 @@ const AUTORUN_STAMINA_RESUME_RATIO = 0.5;110
function sendPlayerMoveTo (tileX, tileY)113
function sendPlayerMoveTo (tileX, tileY)111
{114
{112
followTargetId = null;115
followTargetId = null;116
clearAutorunFocus();113
moveDest = { tileX: tileX | 0, tileY: tileY | 0 };117
moveDest = { tileX: tileX | 0, tileY: tileY | 0 };114
socket.send({ type: MessageType.moveTo, tileX: moveDest.tileX, tileY: moveDest.tileY });118
socket.send({ type: MessageType.moveTo, tileX: moveDest.tileX, tileY: moveDest.tileY });115
syncAutorun();119
syncAutorun();@@ -119,10 +123,58 @@ function sendPlayerFollow (targetEntityId)119
{123
{120
followTargetId = targetEntityId | 0;124
followTargetId = targetEntityId | 0;121
moveDest = null;125
moveDest = null;126
clearAutorunFocus();122
autorunWaitingStamina = false;127
autorunWaitingStamina = false;123
socket.send({ type: MessageType.follow, targetEntityId: followTargetId });128
socket.send({ type: MessageType.follow, targetEntityId: followTargetId });124
}129
}125
130
131
function clearAutorunFocus ()132
{133
autorunFocusEntityId = null;134
autorunFocusTile = null;135
}136
137
function setAutorunFocusEntity (entityId)138
{139
moveDest = null;140
autorunFocusTile = null;141
autorunFocusEntityId = entityId | 0;142
syncAutorun();143
}144
145
function setAutorunFocusTile (tileX, tileY)146
{147
moveDest = null;148
autorunFocusEntityId = null;149
autorunFocusTile = { tileX: tileX | 0, tileY: tileY | 0 };150
syncAutorun();151
}152
153
function resolveAutorunDest ()154
{155
if (moveDest)156
{ return moveDest; }157
if (autorunFocusEntityId != null)158
{159
const target = view?.entities?.get(autorunFocusEntityId);160
if (!target)161
{ return null; }162
return { tileX: target.tileX | 0, tileY: target.tileY | 0 };163
}164
return autorunFocusTile;165
}166
167
function localEntityIsMoving (local)168
{169
if (!local)170
{ return false; }171
if (local.lerpStarted != null)172
{ return true; }173
const dx = (local.visualX ?? 0) - (local.targetX ?? local.visualX ?? 0);174
const dy = (local.visualY ?? 0) - (local.targetY ?? local.visualY ?? 0);175
return (dx * dx + dy * dy) > 0.25;176
}177
126
function requestGaitIfNeeded (next)178
function requestGaitIfNeeded (next)127
{179
{128
if (next !== GAIT.walk && next !== GAIT.run)180
if (next !== GAIT.walk && next !== GAIT.run)@@ -149,16 +201,23 @@ function syncAutorun ()149
if (settings.autorun !== "on")201
if (settings.autorun !== "on")150
{ return; }202
{ return; }151
const local = view?.entities?.get(view.localEntityId);203
const local = view?.entities?.get(view.localEntityId);152
if (!local || !moveDest)204
const dest = resolveAutorunDest();205
if (!local || !dest)153
{ return; }206
{ return; }154
if (local.tileX === moveDest.tileX && local.tileY === moveDest.tileY)207
if (moveDest && local.tileX === moveDest.tileX && local.tileY === moveDest.tileY)155
{208
{156
moveDest = null;209
moveDest = null;157
autorunWaitingStamina = false;210
autorunWaitingStamina = false;158
requestGaitIfNeeded(GAIT.walk);211
requestGaitIfNeeded(GAIT.walk);159
return;212
return;160
}213
}161
const dist = chebyshev(local.tileX, local.tileY, moveDest.tileX, moveDest.tileY);214
// Attack / cast approach is server-pathed — only run while tiles are changing.215
if (!moveDest && !localEntityIsMoving(local))216
{217
requestGaitIfNeeded(GAIT.walk);218
return;219
}220
const dist = chebyshev(local.tileX, local.tileY, dest.tileX, dest.tileY);162
const wantRun = dist > AUTORUN_DISTANCE_TILES;221
const wantRun = dist > AUTORUN_DISTANCE_TILES;163
const current = staminaUi?.getCurrent?.() ?? 0;222
const current = staminaUi?.getCurrent?.() ?? 0;164
const max = Math.max(1, staminaUi?.getMax?.() ?? 1);223
const max = Math.max(1, staminaUi?.getMax?.() ?? 1);@@ -840,6 +899,7 @@ function flushPendingPickup ()840
function requestAttack (targetEntityId)899
function requestAttack (targetEntityId)841
{900
{842
clearAllPendingActions();901
clearAllPendingActions();902
setAutorunFocusEntity(targetEntityId);843
socket.send({ type: MessageType.attack, targetEntityId });903
socket.send({ type: MessageType.attack, targetEntityId });844
}904
}845
905
@@ -863,13 +923,19 @@ function handleLeftClick (mouseX, mouseY)863
const tile = view.screenToTile(mouseX, mouseY);923
const tile = view.screenToTile(mouseX, mouseY);864
const armed = spells?.getArmedSpell?.();924
const armed = spells?.getArmedSpell?.();865
if (armed?.target === "tile" && armed.canCast && spells.tryCastAtTile(tile.tileX, tile.tileY))925
if (armed?.target === "tile" && armed.canCast && spells.tryCastAtTile(tile.tileX, tile.tileY))866
{ return; }926
{927
setAutorunFocusTile(tile.tileX, tile.tileY);928
return;929
}867
930
868
if (armed?.target === "entity" && armed.canCast)931
if (armed?.target === "entity" && armed.canCast)869
{932
{870
const snap = nearestSpellEntityAtCursor(mouseX, mouseY);933
const snap = nearestSpellEntityAtCursor(mouseX, mouseY);871
if (snap && spells.tryCastAtEntity(snap.entityId))934
if (snap && spells.tryCastAtEntity(snap.entityId))872
{ return; }935
{936
setAutorunFocusEntity(snap.entityId);937
return;938
}873
return;939
return;874
}940
}875
941
@@ -1676,6 +1742,8 @@ async function main ()1676
{ closeOpenUiIfTooFar(); }1742
{ closeOpenUiIfTooFar(); }1677
break;1743
break;1678
case MessageType.entityDespawn:1744
case MessageType.entityDespawn:1745
if (message.entityId === autorunFocusEntityId)1746
{ clearAutorunFocus(); }1679
view?.despawnEntity(message.entityId);1747
view?.despawnEntity(message.entityId);1680
break;1748
break;1681
case MessageType.entityAppearance:1749
case MessageType.entityAppearance:@@ -2013,6 +2081,7 @@ function returnToMenu (reason = "")2013
playing = false;2081
playing = false;2014
followTargetId = null;2082
followTargetId = null;2015
moveDest = null;2083
moveDest = null;2084
clearAutorunFocus();2016
autorunWaitingStamina = false;2085
autorunWaitingStamina = false;2017
clearAllPendingActions();2086
clearAllPendingActions();2018
clearUiFocus();2087
clearUiFocus();@@ -4,7 +4,7 @@ import { canEquipItem } from "../../../shared/equipment/stats.js";
4
4
import { EquipmentKind } from "../../../shared/definitions/equipmentKinds.js";
5
5
import { stackRulesFor } from "../../../shared/items/stackRules.js";
6
6
import { BlockType } from "../../../shared/definitions/tiles.js";
7
import { ItemId, itemDefinition, itemSpriteName, stackDisplayLabel, LETTER_MAX_BODY_CHARS, BLANK_CHEQUE_CARRY_CAP } from "../../../shared/definitions/items.js";
7
import { ItemId, itemDefinition, itemSpriteName, itemDisplayName, LETTER_MAX_BODY_CHARS, BLANK_CHEQUE_CARRY_CAP } from "../../../shared/definitions/items.js";
8
8
import
9
9
{
10
10
emptyEquipment,
@@ -56,7 +56,7 @@ export function publicGroundItem (item)
56
56
tileY: item.tileY,
57
57
itemId: item.stack.itemId,
58
58
quantity: item.stack.quantity,
59
displayName: stackDisplayLabel(item.stack),
59
displayName: itemDisplayName(item.stack),
60
60
sprite: itemSpriteName(item.stack.itemId, instance),
61
61
instance: instance && (instance.kind === "potion" || instance.kind === "letter" || instance.kind === "recipe-paper")
62
62
? instance
@@ -4,7 +4,7 @@ import { canEquipItem } from "../../../shared/equipment/stats.js";4
import { EquipmentKind } from "../../../shared/definitions/equipmentKinds.js";4
import { EquipmentKind } from "../../../shared/definitions/equipmentKinds.js";5
import { stackRulesFor } from "../../../shared/items/stackRules.js";5
import { stackRulesFor } from "../../../shared/items/stackRules.js";6
import { BlockType } from "../../../shared/definitions/tiles.js";6
import { BlockType } from "../../../shared/definitions/tiles.js";7
import { ItemId, itemDefinition, itemSpriteName, stackDisplayLabel, LETTER_MAX_BODY_CHARS, BLANK_CHEQUE_CARRY_CAP } from "../../../shared/definitions/items.js";7
import { ItemId, itemDefinition, itemSpriteName, itemDisplayName, LETTER_MAX_BODY_CHARS, BLANK_CHEQUE_CARRY_CAP } from "../../../shared/definitions/items.js";8
import8
import9
{9
{10
emptyEquipment,10
emptyEquipment,@@ -56,7 +56,7 @@ export function publicGroundItem (item)56
tileY: item.tileY,56
tileY: item.tileY,57
itemId: item.stack.itemId,57
itemId: item.stack.itemId,58
quantity: item.stack.quantity,58
quantity: item.stack.quantity,59
displayName: stackDisplayLabel(item.stack),59
displayName: itemDisplayName(item.stack),60
sprite: itemSpriteName(item.stack.itemId, instance),60
sprite: itemSpriteName(item.stack.itemId, instance),61
instance: instance && (instance.kind === "potion" || instance.kind === "letter" || instance.kind === "recipe-paper")61
instance: instance && (instance.kind === "potion" || instance.kind === "letter" || instance.kind === "recipe-paper")62
? instance62
? instance