Wire boundary hooks into player movement
Movement now evaluates boundary enter/exit conditions. Exit checks can block movement based on carrying items (by name or tag). Enter and exit messages sent when crossing boundary borders. All boundary logic lives in move_player() before position update.
This commit is contained in:
parent
4205b174c9
commit
a0360f221c
1 changed files with 52 additions and 0 deletions
|
|
@ -74,6 +74,41 @@ async def move_player(player: Player, dx: int, dy: int, direction_name: str) ->
|
|||
await player.send("You can't go that way.\r\n")
|
||||
return
|
||||
|
||||
# Check boundary exit conditions
|
||||
current_boundary = None
|
||||
target_boundary = None
|
||||
|
||||
for boundary in zone.boundaries:
|
||||
if boundary.contains(player.x, player.y):
|
||||
current_boundary = boundary
|
||||
if boundary.contains(target_x, target_y):
|
||||
target_boundary = boundary
|
||||
|
||||
# If leaving a boundary with an exit check, evaluate it
|
||||
if (
|
||||
current_boundary is not None
|
||||
and current_boundary is not target_boundary
|
||||
and current_boundary.on_exit_check
|
||||
and current_boundary.on_exit_check.startswith("carrying:")
|
||||
):
|
||||
check_value = current_boundary.on_exit_check[9:] # strip "carrying:"
|
||||
# Check if player has any item matching name or tag
|
||||
from mudlib.thing import Thing
|
||||
|
||||
has_item = False
|
||||
for obj in player._contents:
|
||||
if isinstance(obj, Thing) and (
|
||||
obj.name == check_value or check_value in obj.tags
|
||||
):
|
||||
has_item = True
|
||||
break
|
||||
|
||||
if has_item:
|
||||
# Check failed, block movement
|
||||
if current_boundary.on_exit_fail:
|
||||
await player.send(f"{current_boundary.on_exit_fail}\r\n")
|
||||
return
|
||||
|
||||
# If painting, place the brush tile at the current position before moving
|
||||
if player.paint_mode and player.painting:
|
||||
zone.terrain[player.y][player.x] = player.paint_brush
|
||||
|
|
@ -88,6 +123,23 @@ async def move_player(player: Player, dx: int, dy: int, direction_name: str) ->
|
|||
player.x = target_x
|
||||
player.y = target_y
|
||||
|
||||
# Send boundary messages
|
||||
# If leaving a boundary (and check passed), send exit message
|
||||
if (
|
||||
current_boundary is not None
|
||||
and current_boundary is not target_boundary
|
||||
and current_boundary.on_exit_message
|
||||
):
|
||||
await player.send(f"{current_boundary.on_exit_message}\r\n")
|
||||
|
||||
# If entering a boundary, send enter message
|
||||
if (
|
||||
target_boundary is not None
|
||||
and target_boundary is not current_boundary
|
||||
and target_boundary.on_enter_message
|
||||
):
|
||||
await player.send(f"{target_boundary.on_enter_message}\r\n")
|
||||
|
||||
# Check for auto-trigger portals at new position
|
||||
portals_here = [
|
||||
obj for obj in zone.contents_at(target_x, target_y) if isinstance(obj, Portal)
|
||||
|
|
|
|||
Loading…
Reference in a new issue