Skip to content

Fix monsters attacking through walls with ranged attacks - #957

Open
eduardosmaniotto wants to merge 1 commit into
MUnique:masterfrom
eduardosmaniotto:fix/monster-los-through-walls
Open

Fix monsters attacking through walls with ranged attacks#957
eduardosmaniotto wants to merge 1 commit into
MUnique:masterfrom
eduardosmaniotto:fix/monster-los-through-walls

Conversation

@eduardosmaniotto

Copy link
Copy Markdown
Contributor

Problem

Monsters with ranged attacks (e.g. Hell Spider, Cursed Wizard)
could target and hit players standing behind walls. Target search
and the attack decision used pure Chebyshev distance with no terrain
check, and damage application only blocks on safezone.

Fix

  • GameMapTerrain.HasLineOfSight(from, to): integer Bresenham over
    WalkMap; blocked intermediate tiles block sight, endpoints are
    excluded so occupants never block themselves, and a diagonal step
    squeezing between two corner-touching blocked tiles is treated as
    blocked. O(range) reads, zero allocations.
  • LocateableExtensions.HasLineOfSightTo: same-map guard + delegation,
    mirroring the existing IsInRange/IsAtSafezone extension pattern.
    Call sites keep cheap IsInRange() as pre-filter, LOS second.
  • AI gates (decision point, so monsters repath instead of camping):
    BasicMonsterIntelligence (search prefers nearest visible with
    nearest fallback, validity + attack gate require sight — also covers
    guards and summoned monsters' base behavior),
    SummonedMonsterIntelligence (same visible-preferred pattern),
    RandomAttackInRangeTrapIntelligence,
    AttackAreaTargetInDirectionTrapIntelligence,
    AttackAreaWhenPressedTrapIntelligence.
  • Player skills intentionally untouched (client already blocks; server
    stays lenient).

Known limitation

Walkability doubles as opacity: the map data has no transparency layer,
so unwalkable-but-transparent tiles (water, pits) also block sight. Noted
in a <remarks> on HasLineOfSight; a dedicated opacity grid would be
needed if a map ever requires shooting across such areas.

Tests

  • dotnet build src/GameLogic — 0 errors.
  • dotnet test tests/MUnique.OpenMU.Tests --filter GameMapTerrainTests
    10/10 passed (3 existing + 7 new: same-tile, clear lines, wall blocks
    symmetrically, endpoints never block, closed diagonal corner blocked,
    single-wall corner visible, diagonally-adjacent tiles visible).

Before patch

Screencast_20260911_193219.webm

After patch

Screencast_20260911_194949.webm-10mb.mp4

Add GameMapTerrain.HasLineOfSight (integer Bresenham over WalkMap with
diagonal corner handling, endpoints excluded) plus a
LocateableExtensions.HasLineOfSightTo helper, and gate all
server-driven attack decisions on it: BasicMonsterIntelligence
(target search prefers visible with nearest fallback, validity and
attack gate require sight), SummonedMonsterIntelligence, and the
ranged/area trap intelligences. Out-of-sight monsters now fall
through to WalkToAsync and path around the wall instead of shooting
through it.

Adds GameMapTerrainTests coverage for clear, blocked, symmetric,
endpoint-exempt and diagonal-corner sight lines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant