diff --git a/src/mudlib/commands/movement.py b/src/mudlib/commands/movement.py index 0fc4059..1cfe8b6 100644 --- a/src/mudlib/commands/movement.py +++ b/src/mudlib/commands/movement.py @@ -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)