Beispiel #1
0
 public Location(
     LocationId locationId,
     IEnumerable <LocationId> locations,
     IEnumerable <RoadId> roads)
 {
     LocationId = locationId;
     Locations  = locations;
     Roads      = roads;
 }
Beispiel #2
0
        public static RoadMovementComponent EnterRoadFrom(Road road, LocationId locationId)
        {
            if (road.FromPoint.LocationId == locationId)
            {
                return(new RoadMovementComponent(road, Distance.Zero, MovementDirection.Forward));
            }

            if (road.ToPoint.LocationId == locationId)
            {
                return(new RoadMovementComponent(road, Distance.Zero, MovementDirection.Backward));
            }

            throw new InvalidOperationException($"Can't enter road {road.RoadId} from location {locationId}.");
        }
Beispiel #3
0
        public ValueTask HandleAsync(ConnectedClient sender, MoveToLocation message, CancellationToken cancellationToken)
        {
            var playerId = new PlayerId(sender.ClientId);
            var player   = _players.Find(playerId);

            if (player == null)
            {
                throw new InvalidOperationException("Player is not found.");
            }

            var locationId = new LocationId(message.LocationId);

            player.MoveToLocation(locationId); // Messaging group will be updated by player itself.
            _players.Save(player);

            return(default);
        public ValueTask HandleAsync(ConnectedClient sender, TeleportPlayerToLocation message, CancellationToken cancellationToken)
        {
            var playerId   = new PlayerId(message.PlayerId);
            var locationId = new LocationId(message.LocationId);

            var player = _players.Find(playerId);

            if (player == null)
            {
                throw new InvalidOperationException("Player does not exist.");
            }

            player.TeleportToLocation(locationId);

            _players.Save(player);
            return(default);