Spaces:
Running
Running
Fix loot pickup: tap a drop to walk and pick it up, larger pickup range, auto-hunt collects leftover loot first, no drops in map portals
Browse files- index.html +73 -16
- sw.js +1 -1
index.html
CHANGED
|
@@ -629,7 +629,7 @@ button.big.ghost { background:rgba(20,16,10,.8); color:var(--gold); }
|
|
| 629 |
x: 0, y: 0, dir: 4, r: HERO_R, anim: { n: 'stance', t: 0 }, lockUntil: 0,
|
| 630 |
path: [], chase: false, repath: 0, target: null, atkCd: 0, skillCd: [],
|
| 631 |
shieldUntil: 0, shieldAbs: 0, slowUntil: 0, stunUntil: 0,
|
| 632 |
-
pending: null, pendingNpc: null, lootT: 0, dead: false, reviveAt: 0, flash: 0, gold: 0, inv: new Array(INV_CAP).fill(null), eq: {},
|
| 633 |
skills: c.skills.map((id) => S.world.powers[id]).filter(Boolean),
|
| 634 |
basic: S.world.powers[c.basic],
|
| 635 |
};
|
|
@@ -1098,10 +1098,15 @@ button.big.ghost { background:rgba(20,16,10,.8); color:var(--gold); }
|
|
| 1098 |
if (possible.length) out.push(pick(possible));
|
| 1099 |
return out;
|
| 1100 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1101 |
function spawnDrop(x, y, id, qty) {
|
| 1102 |
let px = x, py = y;
|
| 1103 |
for (let k = 0; k < 10; k++) {
|
| 1104 |
-
if (walkCell(S.M, Math.floor(px), Math.floor(py)) && !S.drops.some((d) => dist(d.x, d.y, px, py) < 0.55)) break;
|
| 1105 |
const a = rnd(0, Math.PI * 2), r = rnd(0.5, 1.3);
|
| 1106 |
px = x + Math.cos(a) * r; py = y + Math.sin(a) * r;
|
| 1107 |
}
|
|
@@ -1207,18 +1212,41 @@ button.big.ghost { background:rgba(20,16,10,.8); color:var(--gold); }
|
|
| 1207 |
}
|
| 1208 |
// target validity / auto-lock
|
| 1209 |
if (H.target && H.target.dead) H.target = null;
|
| 1210 |
-
if (!H.target && (S.lock || S.auto) && t >= H.pickT) {
|
| 1211 |
H.pickT = t + 0.4;
|
| 1212 |
const e = S.auto ? nearestEnemyPath(400) : nearestEnemy(LOCK_RANGE_MANUAL);
|
| 1213 |
if (e) H.target = e;
|
| 1214 |
}
|
| 1215 |
if (S.auto && H.target) H.chase = true;
|
| 1216 |
-
//
|
| 1217 |
-
if (
|
| 1218 |
-
|
| 1219 |
-
|
| 1220 |
-
|
| 1221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1222 |
}
|
| 1223 |
// walking to a vendor: open the shop on arrival
|
| 1224 |
if (H.pendingNpc) {
|
|
@@ -1264,7 +1292,7 @@ button.big.ghost { background:rgba(20,16,10,.8); color:var(--gold); }
|
|
| 1264 |
if (!attacking && walking) H.dir = dirKeep(H.dir, wx, wy);
|
| 1265 |
if (!attacking) setAnim(H, walking ? 'run' : 'stance');
|
| 1266 |
manual = true;
|
| 1267 |
-
H.path = []; H.chase = false; H.pending = null; H.pendingNpc = null;
|
| 1268 |
}
|
| 1269 |
}
|
| 1270 |
if (!manual) {
|
|
@@ -1308,9 +1336,9 @@ button.big.ghost { background:rgba(20,16,10,.8); color:var(--gold); }
|
|
| 1308 |
// pickup drops (gold is collected from a bit further, like the engine's autopickup_range)
|
| 1309 |
for (let i = S.drops.length - 1; i >= 0; i--) {
|
| 1310 |
const d = S.drops[i], dd = dist(d.x, d.y, H.x, H.y);
|
| 1311 |
-
if (d.hold) { if (dd > 1.
|
| 1312 |
if (d.skip && invFreeSlots() > 0) d.skip = false;
|
| 1313 |
-
if (!d.skip && dd < (d.id === CURRENCY ? 1.
|
| 1314 |
}
|
| 1315 |
// hotspots -> other map
|
| 1316 |
if (t > S.noHotUntil && !S.changing) {
|
|
@@ -1388,14 +1416,38 @@ button.big.ghost { background:rgba(20,16,10,.8); color:var(--gold); }
|
|
| 1388 |
const iy = (H.x + H.y) * HH + (py - S.H_ / 2) / S.zoom - 40;
|
| 1389 |
return isoInv(ix, iy + 0);
|
| 1390 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1391 |
function talkToNpc(n) {
|
| 1392 |
const H = S.H;
|
| 1393 |
if (dist(H.x, H.y, n.x, n.y) <= 2.6) { H.path = []; openShop(n); return; }
|
| 1394 |
-
H.pendingNpc = n; H.chase = false; H.target = null; H.path = routeTo(S.M, H, n.x, n.y);
|
| 1395 |
toast('前往 ' + n.name.split(',')[0]);
|
| 1396 |
}
|
| 1397 |
function onTap(px, py) {
|
| 1398 |
const H = S.H, z = S.zoom;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1399 |
for (const n of S.npcs) {
|
| 1400 |
const [ix, iy] = iso(n.x, n.y); const [sx, sy] = worldToScreen(ix, iy);
|
| 1401 |
if (px > sx - 44 * z && px < sx + 44 * z && py > sy - 120 * z && py < sy + 24 * z) { talkToNpc(n); return; }
|
|
@@ -1405,7 +1457,7 @@ button.big.ghost { background:rgba(20,16,10,.8); color:var(--gold); }
|
|
| 1405 |
const [ix, iy] = iso(e.x, e.y);
|
| 1406 |
const [sx, sy] = worldToScreen(ix, iy);
|
| 1407 |
if (px > sx - 46 * z && px < sx + 46 * z && py > sy - 130 * z && py < sy + 20 * z) {
|
| 1408 |
-
H.target = e; H.chase = true; H.path = []; H.pending = null;
|
| 1409 |
toast('鎖定:' + e.def.name);
|
| 1410 |
return;
|
| 1411 |
}
|
|
@@ -1418,7 +1470,7 @@ button.big.ghost { background:rgba(20,16,10,.8); color:var(--gold); }
|
|
| 1418 |
const H = S.H, M = S.M;
|
| 1419 |
if (H.dead) return;
|
| 1420 |
const path = routeTo(M, H, cx + 0.5, cy + 0.5);
|
| 1421 |
-
H.chase = false; H.pendingNpc = null; H.target = H.target && !H.target.dead ? H.target : null;
|
| 1422 |
if (path.length === 0 && !(Math.floor(H.x) === cx && Math.floor(H.y) === cy)) { toast('無法到達'); return; }
|
| 1423 |
H.path = path;
|
| 1424 |
const last = path[path.length - 1];
|
|
@@ -2117,7 +2169,7 @@ button.big.ghost { background:rgba(20,16,10,.8); color:var(--gold); }
|
|
| 2117 |
get bag() {
|
| 2118 |
const H = S.H; if (!H) return null;
|
| 2119 |
return { gold: H.gold, inv: H.inv.filter(Boolean).map((x) => ({ id: x.id, name: itemOf(x.id).name, qty: x.qty })), eq: H.eq,
|
| 2120 |
-
drops: S.drops.map((d) => ({ id: d.id, name: dropName(d), x: d.x, y: d.y })), maxhp: H.maxhp, stats: { dlo: H.dmgLo, dhi: H.dmgHi, abs: H.absRange, acc: H.acc } };
|
| 2121 |
},
|
| 2122 |
giveItem(id, qty) { return invAdd(id, qty || 1); },
|
| 2123 |
dropNear(id, qty, dx, dy) { const d = { x: S.H.x + dx, y: S.H.y + dy, id, qty: qty || 1, t0: now(), hold: true }; S.drops.push(d); },
|
|
@@ -2129,6 +2181,11 @@ button.big.ghost { background:rgba(20,16,10,.8); color:var(--gold); }
|
|
| 2129 |
return { x: sx, y: sy - 50 * S.zoom, dist: dist(S.H.x, S.H.y, n.x, n.y), nx: n.x, ny: n.y };
|
| 2130 |
},
|
| 2131 |
debugRoute(x, y) { const H = S.H; return { cells: findPath(S.M, Math.floor(H.x), Math.floor(H.y), Math.floor(x), Math.floor(y)).length, smooth: routeTo(S.M, H, x, y).length, walk: walkCell(S.M, Math.floor(x), Math.floor(y)), alt: nearestWalkable(S.M, Math.floor(x), Math.floor(y), 4) }; },
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2132 |
teleport(x, y) { S.H.x = x; S.H.y = y; S.H.path = []; },
|
| 2133 |
setAuto,
|
| 2134 |
moveTo,
|
|
|
|
| 629 |
x: 0, y: 0, dir: 4, r: HERO_R, anim: { n: 'stance', t: 0 }, lockUntil: 0,
|
| 630 |
path: [], chase: false, repath: 0, target: null, atkCd: 0, skillCd: [],
|
| 631 |
shieldUntil: 0, shieldAbs: 0, slowUntil: 0, stunUntil: 0,
|
| 632 |
+
pending: null, pendingNpc: null, lootGoal: null, lootT: 0, lootStuck: 0, dead: false, reviveAt: 0, flash: 0, gold: 0, inv: new Array(INV_CAP).fill(null), eq: {},
|
| 633 |
skills: c.skills.map((id) => S.world.powers[id]).filter(Boolean),
|
| 634 |
basic: S.world.powers[c.basic],
|
| 635 |
};
|
|
|
|
| 1098 |
if (possible.length) out.push(pick(possible));
|
| 1099 |
return out;
|
| 1100 |
}
|
| 1101 |
+
function inHotspot(x, y) {
|
| 1102 |
+
const cx = Math.floor(x), cy = Math.floor(y);
|
| 1103 |
+
for (const hs of S.M.data.hotspots) { const [hx, hy, w, h] = hs.rect; if (cx >= hx - 1 && cy >= hy - 1 && cx <= hx + w && cy <= hy + h) return true; }
|
| 1104 |
+
return false;
|
| 1105 |
+
}
|
| 1106 |
function spawnDrop(x, y, id, qty) {
|
| 1107 |
let px = x, py = y;
|
| 1108 |
for (let k = 0; k < 10; k++) {
|
| 1109 |
+
if (walkCell(S.M, Math.floor(px), Math.floor(py)) && !inHotspot(px, py) && !S.drops.some((d) => dist(d.x, d.y, px, py) < 0.55)) break;
|
| 1110 |
const a = rnd(0, Math.PI * 2), r = rnd(0.5, 1.3);
|
| 1111 |
px = x + Math.cos(a) * r; py = y + Math.sin(a) * r;
|
| 1112 |
}
|
|
|
|
| 1212 |
}
|
| 1213 |
// target validity / auto-lock
|
| 1214 |
if (H.target && H.target.dead) H.target = null;
|
| 1215 |
+
if (!H.target && !H.lootGoal && (S.lock || S.auto) && t >= H.pickT) {
|
| 1216 |
H.pickT = t + 0.4;
|
| 1217 |
const e = S.auto ? nearestEnemyPath(400) : nearestEnemy(LOCK_RANGE_MANUAL);
|
| 1218 |
if (e) H.target = e;
|
| 1219 |
}
|
| 1220 |
if (S.auto && H.target) H.chase = true;
|
| 1221 |
+
// loot goal: the drop the hero is walking to (set by tapping it, or chosen by auto-hunt)
|
| 1222 |
+
if (H.lootGoal && (S.drops.indexOf(H.lootGoal) < 0 || H.lootGoal.skip || H.dead)) H.lootGoal = null;
|
| 1223 |
+
if (S.auto && !H.lootGoal && !S.joy.on && !S.keyDir && !H.pendingNpc && t >= H.lootT) {
|
| 1224 |
+
H.lootT = t + 0.3;
|
| 1225 |
+
// fights in melee reach finish first; anything left on the ground is collected before the next target is chased
|
| 1226 |
+
const engaged = H.target && !H.target.dead && dist(H.x, H.y, H.target.x, H.target.y) < 3;
|
| 1227 |
+
if (!engaged) {
|
| 1228 |
+
let best = null, bd = 45;
|
| 1229 |
+
for (const d of S.drops) { if (d.skip || d.hold || inHotspot(d.x, d.y)) continue; const dd = dist(d.x, d.y, H.x, H.y); if (dd < bd) { bd = dd; best = d; } }
|
| 1230 |
+
if (best) setLootGoal(best);
|
| 1231 |
+
}
|
| 1232 |
+
}
|
| 1233 |
+
if (H.lootGoal) {
|
| 1234 |
+
const d = H.lootGoal, dd = dist(d.x, d.y, H.x, H.y);
|
| 1235 |
+
if (dd <= 1.0) { pickupDrop(d); H.lootGoal = null; }
|
| 1236 |
+
else {
|
| 1237 |
+
// keep walking; re-route if the path ran out, give up on a drop we cannot get closer to
|
| 1238 |
+
if (!H.path.length) {
|
| 1239 |
+
const path = routeTo(M, H, d.x, d.y);
|
| 1240 |
+
if (path.length) H.path = path;
|
| 1241 |
+
else if (dd <= 1.8) { pickupDrop(d); H.lootGoal = null; }
|
| 1242 |
+
else { d.skip = true; H.lootGoal = null; }
|
| 1243 |
+
}
|
| 1244 |
+
if (H.lootGoal) {
|
| 1245 |
+
if (Math.abs(dd - (H.lootLast || 0)) < 0.02) H.lootStuck += dt; else H.lootStuck = 0;
|
| 1246 |
+
H.lootLast = dd;
|
| 1247 |
+
if (H.lootStuck > 3) { d.skip = true; H.lootGoal = null; H.lootStuck = 0; H.path = []; }
|
| 1248 |
+
}
|
| 1249 |
+
}
|
| 1250 |
}
|
| 1251 |
// walking to a vendor: open the shop on arrival
|
| 1252 |
if (H.pendingNpc) {
|
|
|
|
| 1292 |
if (!attacking && walking) H.dir = dirKeep(H.dir, wx, wy);
|
| 1293 |
if (!attacking) setAnim(H, walking ? 'run' : 'stance');
|
| 1294 |
manual = true;
|
| 1295 |
+
H.path = []; H.chase = false; H.pending = null; H.pendingNpc = null; H.lootGoal = null;
|
| 1296 |
}
|
| 1297 |
}
|
| 1298 |
if (!manual) {
|
|
|
|
| 1336 |
// pickup drops (gold is collected from a bit further, like the engine's autopickup_range)
|
| 1337 |
for (let i = S.drops.length - 1; i >= 0; i--) {
|
| 1338 |
const d = S.drops[i], dd = dist(d.x, d.y, H.x, H.y);
|
| 1339 |
+
if (d.hold) { if (dd > 1.4) d.hold = false; continue; }
|
| 1340 |
if (d.skip && invFreeSlots() > 0) d.skip = false;
|
| 1341 |
+
if (!d.skip && dd < (d.id === CURRENCY ? 1.5 : 1.15)) pickupDrop(d);
|
| 1342 |
}
|
| 1343 |
// hotspots -> other map
|
| 1344 |
if (t > S.noHotUntil && !S.changing) {
|
|
|
|
| 1416 |
const iy = (H.x + H.y) * HH + (py - S.H_ / 2) / S.zoom - 40;
|
| 1417 |
return isoInv(ix, iy + 0);
|
| 1418 |
}
|
| 1419 |
+
function setLootGoal(d) {
|
| 1420 |
+
const H = S.H;
|
| 1421 |
+
H.lootGoal = d; H.lootStuck = 0; H.lootLast = 0; H.pendingNpc = null;
|
| 1422 |
+
H.target = null; H.chase = false; H.pending = null;
|
| 1423 |
+
H.path = routeTo(S.M, H, d.x, d.y);
|
| 1424 |
+
}
|
| 1425 |
function talkToNpc(n) {
|
| 1426 |
const H = S.H;
|
| 1427 |
if (dist(H.x, H.y, n.x, n.y) <= 2.6) { H.path = []; openShop(n); return; }
|
| 1428 |
+
H.pendingNpc = n; H.lootGoal = null; H.chase = false; H.target = null; H.path = routeTo(S.M, H, n.x, n.y);
|
| 1429 |
toast('前往 ' + n.name.split(',')[0]);
|
| 1430 |
}
|
| 1431 |
function onTap(px, py) {
|
| 1432 |
const H = S.H, z = S.zoom;
|
| 1433 |
+
// tapping a drop (its icon or its name label) walks over and picks it up
|
| 1434 |
+
let bestD = null, bdd = 1e9;
|
| 1435 |
+
for (const d of S.drops) {
|
| 1436 |
+
const [ix, iy] = iso(d.x, d.y), [sx, sy] = worldToScreen(ix, iy);
|
| 1437 |
+
if (Math.abs(px - sx) < 52 * z && py > sy - 48 * z && py < sy + 22 * z) {
|
| 1438 |
+
const dd = Math.hypot(px - sx, py - (sy - 12 * z));
|
| 1439 |
+
if (dd < bdd) { bdd = dd; bestD = d; }
|
| 1440 |
+
}
|
| 1441 |
+
}
|
| 1442 |
+
if (bestD) {
|
| 1443 |
+
let onEnemy = false;
|
| 1444 |
+
for (const e of S.enemies) {
|
| 1445 |
+
if (e.dead) continue;
|
| 1446 |
+
const [ix, iy] = iso(e.x, e.y), [sx, sy] = worldToScreen(ix, iy);
|
| 1447 |
+
if (px > sx - 30 * z && px < sx + 30 * z && py > sy - 100 * z && py < sy + 10 * z) onEnemy = true;
|
| 1448 |
+
}
|
| 1449 |
+
if (!onEnemy) { bestD.skip = false; bestD.hold = false; setLootGoal(bestD); return; }
|
| 1450 |
+
}
|
| 1451 |
for (const n of S.npcs) {
|
| 1452 |
const [ix, iy] = iso(n.x, n.y); const [sx, sy] = worldToScreen(ix, iy);
|
| 1453 |
if (px > sx - 44 * z && px < sx + 44 * z && py > sy - 120 * z && py < sy + 24 * z) { talkToNpc(n); return; }
|
|
|
|
| 1457 |
const [ix, iy] = iso(e.x, e.y);
|
| 1458 |
const [sx, sy] = worldToScreen(ix, iy);
|
| 1459 |
if (px > sx - 46 * z && px < sx + 46 * z && py > sy - 130 * z && py < sy + 20 * z) {
|
| 1460 |
+
H.target = e; H.lootGoal = null; H.chase = true; H.path = []; H.pending = null;
|
| 1461 |
toast('鎖定:' + e.def.name);
|
| 1462 |
return;
|
| 1463 |
}
|
|
|
|
| 1470 |
const H = S.H, M = S.M;
|
| 1471 |
if (H.dead) return;
|
| 1472 |
const path = routeTo(M, H, cx + 0.5, cy + 0.5);
|
| 1473 |
+
H.chase = false; H.pendingNpc = null; H.lootGoal = null; H.target = H.target && !H.target.dead ? H.target : null;
|
| 1474 |
if (path.length === 0 && !(Math.floor(H.x) === cx && Math.floor(H.y) === cy)) { toast('無法到達'); return; }
|
| 1475 |
H.path = path;
|
| 1476 |
const last = path[path.length - 1];
|
|
|
|
| 2169 |
get bag() {
|
| 2170 |
const H = S.H; if (!H) return null;
|
| 2171 |
return { gold: H.gold, inv: H.inv.filter(Boolean).map((x) => ({ id: x.id, name: itemOf(x.id).name, qty: x.qty })), eq: H.eq,
|
| 2172 |
+
drops: S.drops.map((d) => ({ id: d.id, name: dropName(d), x: d.x, y: d.y, walk: walkCell(S.M, Math.floor(d.x), Math.floor(d.y)), skip: !!d.skip, hold: !!d.hold, d: dist(d.x, d.y, S.H.x, S.H.y) })), maxhp: H.maxhp, stats: { dlo: H.dmgLo, dhi: H.dmgHi, abs: H.absRange, acc: H.acc } };
|
| 2173 |
},
|
| 2174 |
giveItem(id, qty) { return invAdd(id, qty || 1); },
|
| 2175 |
dropNear(id, qty, dx, dy) { const d = { x: S.H.x + dx, y: S.H.y + dy, id, qty: qty || 1, t0: now(), hold: true }; S.drops.push(d); },
|
|
|
|
| 2181 |
return { x: sx, y: sy - 50 * S.zoom, dist: dist(S.H.x, S.H.y, n.x, n.y), nx: n.x, ny: n.y };
|
| 2182 |
},
|
| 2183 |
debugRoute(x, y) { const H = S.H; return { cells: findPath(S.M, Math.floor(H.x), Math.floor(H.y), Math.floor(x), Math.floor(y)).length, smooth: routeTo(S.M, H, x, y).length, walk: walkCell(S.M, Math.floor(x), Math.floor(y)), alt: nearestWalkable(S.M, Math.floor(x), Math.floor(y), 4) }; },
|
| 2184 |
+
dropScreen(i) {
|
| 2185 |
+
const d = S.drops[i]; if (!d) return null;
|
| 2186 |
+
const [ix, iy] = iso(d.x, d.y), [sx, sy] = worldToScreen(ix, iy);
|
| 2187 |
+
return { x: sx, y: sy - 5 * S.zoom, label: sy - 26 * S.zoom, name: dropName(d) };
|
| 2188 |
+
},
|
| 2189 |
teleport(x, y) { S.H.x = x; S.H.y = y; S.H.path = []; },
|
| 2190 |
setAuto,
|
| 2191 |
moveTo,
|
sw.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
// The Space serves assets with "Cache-Control: no-store", so the browser HTTP cache never keeps them.
|
| 3 |
// Cache Storage (used here) is not affected by that header, so images are downloaded once per build.
|
| 4 |
// The two placeholders below (build id and asset list) are filled in by tools/inline_build.py.
|
| 5 |
-
const BUILD = '
|
| 6 |
const SHELL = 'flare-shell-' + BUILD; // index.html (network first, cache fallback)
|
| 7 |
const ASSETS = 'flare-assets-' + BUILD; // sprites, tiles, icons (cache-first)
|
| 8 |
const KEEP = [SHELL, ASSETS];
|
|
|
|
| 2 |
// The Space serves assets with "Cache-Control: no-store", so the browser HTTP cache never keeps them.
|
| 3 |
// Cache Storage (used here) is not affected by that header, so images are downloaded once per build.
|
| 4 |
// The two placeholders below (build id and asset list) are filled in by tools/inline_build.py.
|
| 5 |
+
const BUILD = '287910de486e';
|
| 6 |
const SHELL = 'flare-shell-' + BUILD; // index.html (network first, cache fallback)
|
| 7 |
const ASSETS = 'flare-assets-' + BUILD; // sprites, tiles, icons (cache-first)
|
| 8 |
const KEEP = [SHELL, ASSETS];
|