Require hostile mobs have line of sight before reacting

This commit is contained in:
Tanner committed 2026-11-13 23:53:48 +00:00
1 parent 586772cb3b
commit 8447a85ff0
2 files changed
+43 -1

No files matched your search

+18 -1
View File
@@ -52,6 +52,23 @@ class ThreatMonitor:
return finder(position, distance)
return self.g.world.find_threats(position, distance)
def _visible_hostiles(self, position, distance):
threats = self._nearby_hostiles(position, distance)
line_of_sight = getattr(
self.g.world, '_has_cache_line_of_sight', None)
if not callable(line_of_sight):
return threats
player = self.g.pos
if hasattr(player, 'x'):
px, py, pz = player.x, player.y, player.z
else:
px, py, pz = player
target = (px, py + 1.62, pz)
target_block = utils.pint((px, py, pz))
return [mob for mob in threats if line_of_sight(
(mob.x, mob.y + 1.5, mob.z), target, target_block)]
@staticmethod
def _describe_threat(threat):
mob_name = mobs.MOB_NAMES.get(
@@ -111,7 +128,7 @@ class ThreatMonitor:
if now < self.next_scan_at:
return
self.next_scan_at = now + self.CHECK_INTERVAL
threats = self._nearby_hostiles(
threats = self._visible_hostiles(
utils.pint(self.g.pos), self.THREAT_DISTANCE)
if not threats:
return