Fix monsters attacking through walls with ranged attacks - #957
Open
eduardosmaniotto wants to merge 1 commit into
Open
Fix monsters attacking through walls with ranged attacks#957eduardosmaniotto wants to merge 1 commit into
eduardosmaniotto wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 overWalkMap; blocked intermediate tiles block sight, endpoints areexcluded 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/IsAtSafezoneextension pattern.Call sites keep cheap
IsInRange()as pre-filter, LOS second.BasicMonsterIntelligence(search prefers nearest visible withnearest fallback, validity + attack gate require sight — also covers
guards and summoned monsters' base behavior),
SummonedMonsterIntelligence(same visible-preferred pattern),RandomAttackInRangeTrapIntelligence,AttackAreaTargetInDirectionTrapIntelligence,AttackAreaWhenPressedTrapIntelligence.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>onHasLineOfSight; a dedicated opacity grid would beneeded 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