Fix Overspawns

This commit is contained in:
Crowns3bc
2025-10-07 11:44:20 -06:00
committed by GitHub
parent a4b942500c
commit ded6c1f936
+7 -9
View File
@@ -12067,26 +12067,24 @@ function update_instance(instance) {
const currentHpRatio = monster.hp / monster.max_hp;
const key = name + "_hp_" + threshold;
if (currentHpRatio <= threshold && !monster.last[key]) { // trigger once per fight
for (let i = 0; i < count; i++) {
if (currentHpRatio <= threshold && (monster.last[key] == undefined || monster.last[key] < count)) {
const pname = random_one(Object.keys(monster.points));
const player = get_player(pname);
if (!player || player.npc || distance(monster, player) > 400) return;
if (!is_same(player, get_player(monster.target), true)) return;
if (player && !player.npc && distance(monster, player) < 400) {
if (is_same(player, get_player(monster.target), true)) {
const spot = safe_xy_nearby(player.map, player.x + Math.random() * 20 - 10, player.y + Math.random() * 20 - 10);
if (!spot) return;
if (spot) {
new_monster(instance.name, {
type: name,
stype: "spawn",
x: spot.x,
y: spot.y,
target: player.name,
master: monster.id,
});
monster.last[key] = 1 + (monster.last[key] || 0);
}
}
}
monster.last[key] = true; // mark this threshold as triggered
}
}
});