Spaces:
Running
Running
Manual changes saved
Browse files- index.html +67 -15
index.html
CHANGED
|
@@ -388,8 +388,7 @@
|
|
| 388 |
prioritizeChestsUntil: 0
|
| 389 |
};
|
| 390 |
|
| 391 |
-
|
| 392 |
-
enemy.equippedIndex = 0; // equip the weapon immediately
|
| 393 |
// Slightly bias them to seek chests early so they can refill/reload if needed
|
| 394 |
enemy.prioritizeChestsUntil = now + 10000 + rand(0,2000);
|
| 395 |
// Reduce gather time so they don't idle unnecessarily
|
|
@@ -593,6 +592,24 @@
|
|
| 593 |
else e.equippedIndex = -1;
|
| 594 |
}
|
| 595 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 596 |
function enemyPickupCollect(e, p){
|
| 597 |
if (!e || !p) return;
|
| 598 |
if (p.type === 'weapon'){
|
|
@@ -642,9 +659,15 @@
|
|
| 642 |
} else if (p.type === 'medkit'){
|
| 643 |
for (let s=0;s<5;s++){
|
| 644 |
const it = e.inventory[s];
|
| 645 |
-
if (it && it.type==='medkit'){ it.amount += p.amount;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 646 |
}
|
| 647 |
-
for (let s=0;s<5;s++){ if (!e.inventory[s]) { e.inventory[s] = { type:'medkit', amount:p.amount };
|
|
|
|
|
|
|
| 648 |
e.materials += 3;
|
| 649 |
} else if (p.type === 'materials'){
|
| 650 |
e.materials += p.amount;
|
|
@@ -814,6 +837,28 @@
|
|
| 814 |
if (e.health <= 0) continue;
|
| 815 |
if (!e.spawnSafeUntil) e.spawnSafeUntil = performance.now() + SPAWN_PROTECT_MS;
|
| 816 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 817 |
// === STORM / MOVE TO SAFE ZONE BEHAVIOR ===
|
| 818 |
if (storm.active){
|
| 819 |
const distToSafeCenter = Math.hypot(e.x - storm.centerX, e.y - storm.centerY);
|
|
@@ -907,18 +952,10 @@
|
|
| 907 |
if (now - e.lastAttackedTime < 4000) e.state = 'combat';
|
| 908 |
if (e.state === 'gather') e.gatherTimeLeft -= dt;
|
| 909 |
|
|
|
|
| 910 |
if (e.health < 60 && now >= (e.nextHealTime || 0)){
|
| 911 |
-
|
| 912 |
-
|
| 913 |
-
const it = e.inventory[s];
|
| 914 |
-
if (it && it.type === 'medkit' && it.amount > 0){ medIdx = s; break; }
|
| 915 |
-
}
|
| 916 |
-
if (medIdx !== -1){
|
| 917 |
-
const kit = e.inventory[medIdx];
|
| 918 |
-
kit.amount -= 1;
|
| 919 |
-
e.health = Math.min(120, e.health + 50);
|
| 920 |
-
if (kit.amount <= 0) e.inventory[medIdx] = null;
|
| 921 |
-
e.nextHealTime = now + 6000;
|
| 922 |
continue;
|
| 923 |
}
|
| 924 |
}
|
|
@@ -1372,6 +1409,21 @@
|
|
| 1372 |
ctx.fillStyle = '#cfcfcf';
|
| 1373 |
ctx.fillRect(-6,-4,10,4);
|
| 1374 |
ctx.restore();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1375 |
}
|
| 1376 |
}
|
| 1377 |
|
|
|
|
| 388 |
prioritizeChestsUntil: 0
|
| 389 |
};
|
| 390 |
|
| 391 |
+
enemy.equippedIndex = -1;
|
|
|
|
| 392 |
// Slightly bias them to seek chests early so they can refill/reload if needed
|
| 393 |
enemy.prioritizeChestsUntil = now + 10000 + rand(0,2000);
|
| 394 |
// Reduce gather time so they don't idle unnecessarily
|
|
|
|
| 592 |
else e.equippedIndex = -1;
|
| 593 |
}
|
| 594 |
|
| 595 |
+
function enemyUseMedkit(e, now){
|
| 596 |
+
for (let s=0;s<5;s++){
|
| 597 |
+
const it = e.inventory[s];
|
| 598 |
+
if (it && it.type === 'medkit' && it.amount > 0){
|
| 599 |
+
// visually switch to medkit slot
|
| 600 |
+
e.equippedIndex = s;
|
| 601 |
+
it.amount -= 1;
|
| 602 |
+
e.health = Math.min(120, e.health + 50);
|
| 603 |
+
if (it.amount <= 0) e.inventory[s] = null;
|
| 604 |
+
e.nextHealTime = now + 6000;
|
| 605 |
+
// after healing, prefer to have weapon equipped again
|
| 606 |
+
enemyEquipBestWeapon(e);
|
| 607 |
+
return true;
|
| 608 |
+
}
|
| 609 |
+
}
|
| 610 |
+
return false;
|
| 611 |
+
}
|
| 612 |
+
|
| 613 |
function enemyPickupCollect(e, p){
|
| 614 |
if (!e || !p) return;
|
| 615 |
if (p.type === 'weapon'){
|
|
|
|
| 659 |
} else if (p.type === 'medkit'){
|
| 660 |
for (let s=0;s<5;s++){
|
| 661 |
const it = e.inventory[s];
|
| 662 |
+
if (it && it.type==='medkit'){ it.amount += p.amount;
|
| 663 |
+
// if low health, immediately use medkit (and "swap to heals")
|
| 664 |
+
if (e.health < 60) enemyUseMedkit(e, performance.now());
|
| 665 |
+
return;
|
| 666 |
+
}
|
| 667 |
}
|
| 668 |
+
for (let s=0;s<5;s++){ if (!e.inventory[s]) { e.inventory[s] = { type:'medkit', amount:p.amount };
|
| 669 |
+
if (e.health < 60) enemyUseMedkit(e, performance.now());
|
| 670 |
+
return; } }
|
| 671 |
e.materials += 3;
|
| 672 |
} else if (p.type === 'materials'){
|
| 673 |
e.materials += p.amount;
|
|
|
|
| 837 |
if (e.health <= 0) continue;
|
| 838 |
if (!e.spawnSafeUntil) e.spawnSafeUntil = performance.now() + SPAWN_PROTECT_MS;
|
| 839 |
|
| 840 |
+
// --- NEW: Auto-open chests on proximity ---
|
| 841 |
+
// If an unopened chest is very close, open it immediately and collect its loot.
|
| 842 |
+
for (const chest of chests){
|
| 843 |
+
if (chest.opened) continue;
|
| 844 |
+
const distChest = Math.hypot(chest.x - e.x, chest.y - e.y);
|
| 845 |
+
// Use a slightly larger threshold so enemies who are 'touching' the chest will open it.
|
| 846 |
+
if (distChest <= (e.radius + chestRadius() + 6)){
|
| 847 |
+
chest.opened = true;
|
| 848 |
+
const loot = chest.loot;
|
| 849 |
+
if (loot.type === 'weapon'){
|
| 850 |
+
enemyPickupCollect(e, { type:'weapon', weapon: makeWeaponProto(loot.weapon), ammoInMag: loot.weapon.magSize || 12, ammoReserve: loot.weapon.startReserve || (loot.weapon.magSize*2 || 24) });
|
| 851 |
+
} else if (loot.type === 'medkit'){
|
| 852 |
+
enemyPickupCollect(e, { type:'medkit', amount: loot.amount || 1 });
|
| 853 |
+
} else if (loot.type === 'materials'){
|
| 854 |
+
enemyPickupCollect(e, { type:'materials', amount: loot.amount || 10 });
|
| 855 |
+
}
|
| 856 |
+
// If enemy has acquired a weapon, ensure they equip the best available now.
|
| 857 |
+
enemyEquipBestWeapon(e);
|
| 858 |
+
break;
|
| 859 |
+
}
|
| 860 |
+
}
|
| 861 |
+
|
| 862 |
// === STORM / MOVE TO SAFE ZONE BEHAVIOR ===
|
| 863 |
if (storm.active){
|
| 864 |
const distToSafeCenter = Math.hypot(e.x - storm.centerX, e.y - storm.centerY);
|
|
|
|
| 952 |
if (now - e.lastAttackedTime < 4000) e.state = 'combat';
|
| 953 |
if (e.state === 'gather') e.gatherTimeLeft -= dt;
|
| 954 |
|
| 955 |
+
// Enhanced heal handling: swap to medkit and consume when needed
|
| 956 |
if (e.health < 60 && now >= (e.nextHealTime || 0)){
|
| 957 |
+
// Attempt to use medkit (this will "swap" to medkit slot and then back to weapons)
|
| 958 |
+
if (enemyUseMedkit(e, now)){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 959 |
continue;
|
| 960 |
}
|
| 961 |
}
|
|
|
|
| 1409 |
ctx.fillStyle = '#cfcfcf';
|
| 1410 |
ctx.fillRect(-6,-4,10,4);
|
| 1411 |
ctx.restore();
|
| 1412 |
+
} else {
|
| 1413 |
+
// If equippedIndex refers to a medkit/other, show a small indicator
|
| 1414 |
+
const it = e.inventory[e.equippedIndex];
|
| 1415 |
+
if (it && it.type === 'medkit'){
|
| 1416 |
+
ctx.save();
|
| 1417 |
+
ctx.translate(12, 2);
|
| 1418 |
+
ctx.rotate(-0.05);
|
| 1419 |
+
ctx.fillStyle = '#ff6b6b';
|
| 1420 |
+
ctx.fillRect(0, -6, 10, 10);
|
| 1421 |
+
ctx.fillStyle = '#fff';
|
| 1422 |
+
ctx.font = '8px monospace';
|
| 1423 |
+
ctx.textAlign = 'center';
|
| 1424 |
+
ctx.fillText('M', 5, 2);
|
| 1425 |
+
ctx.restore();
|
| 1426 |
+
}
|
| 1427 |
}
|
| 1428 |
}
|
| 1429 |
|