Fix Overspawns

This commit is contained in:
Crowns3bc
2025-10-07 11:44:20 -06:00
committed by GitHub
parent a4b942500c
commit ded6c1f936
+27 -29
View File
@@ -12061,36 +12061,34 @@ function update_instance(instance) {
} }
} }
// --- HP threshold spawns (new) --- // --- HP threshold spawns (new) ---
if (typeof condition === "string" && condition.startsWith("hp:")) { if (typeof condition === "string" && condition.startsWith("hp:")) {
const threshold = parseFloat(condition.split(":")[1]); // e.g. 0.75 const threshold = parseFloat(condition.split(":")[1]); // e.g. 0.75
const currentHpRatio = monster.hp / monster.max_hp; const currentHpRatio = monster.hp / monster.max_hp;
const key = name + "_hp_" + threshold; const key = name + "_hp_" + threshold;
if (currentHpRatio <= threshold && !monster.last[key]) { // trigger once per fight if (currentHpRatio <= threshold && (monster.last[key] == undefined || monster.last[key] < count)) {
for (let i = 0; i < count; i++) { const pname = random_one(Object.keys(monster.points));
const pname = random_one(Object.keys(monster.points)); const player = get_player(pname);
const player = get_player(pname); if (player && !player.npc && distance(monster, player) < 400) {
if (!player || player.npc || distance(monster, player) > 400) return; if (is_same(player, get_player(monster.target), true)) {
if (!is_same(player, get_player(monster.target), true)) return; const spot = safe_xy_nearby(player.map, player.x + Math.random() * 20 - 10, player.y + Math.random() * 20 - 10);
if (spot) {
const spot = safe_xy_nearby(player.map, player.x + Math.random() * 20 - 10, player.y + Math.random() * 20 - 10); new_monster(instance.name, {
if (!spot) return; type: name,
stype: "spawn",
new_monster(instance.name, { x: spot.x,
type: name, target: player.name,
stype: "spawn", master: monster.id,
x: spot.x, });
y: spot.y, monster.last[key] = 1 + (monster.last[key] || 0);
target: player.name, }
master: monster.id, }
}); }
} }
monster.last[key] = true; // mark this threshold as triggered }
} });
} }
});
}
function attack_target_or_move() { function attack_target_or_move() {
var player = players[name_to_id[monster.target]]; var player = players[name_to_id[monster.target]];
if (player && ssince(monster.last.attacked) > 20 && Math.random() > monster.rage * 0.99) { if (player && ssince(monster.last.attacked) > 20 && Math.random() > monster.rage * 0.99) {