internal MapMessageEvent(Location2D upperLeft, Location2D lowerRight, int width, int height) { UpperLeft = upperLeft; LowerRight = lowerRight; Width = width; Height = height; }
/* * Methods. */ public void CalcPlaceDistanceFrom(Location2D location2dFrom) { double metres = MuddyTummy.GeoHelpers.DeltaMetresDistance(location2dFrom.Latitude, location2dFrom.Longitude, this.Location2D.Latitude, this.Location2D.Longitude); this.DistanceFrom = new PlaceDistanceData(metres, location2dFrom); }
public bool IsPassable(Location2D start, Direction direction) { var target = start.LocationInDirection(direction); var tiles = Map.Felucca.Tiles.GetStaticTiles(target.X, target.Y); if (tiles.Length != 0) { if (tiles.Any(t => TileData.ItemTable[t.ID].Impassable)) { return(false); } } var targetLand = Map.Felucca.Tiles.GetLandTile(target.X, target.Y); if (TileData.LandTable[targetLand.ID].Flags.HasFlag(TileFlag.Impassable)) { return(false); } var startLand = Map.Felucca.Tiles.GetLandTile(start.X, start.Y); if (Math.Abs(targetLand.Z - startLand.Z) > 10) { return(false); } return(true); }
/* * Geocode the address into a location (asynchronous). */ public async static Task <Location2D> RequestGeocodingAsync(string strAddress) { Location2D location2d = null; if (string.IsNullOrWhiteSpace(strAddress)) { throw new ArgumentNullException(); } Uri uriGeocodeCall = new Uri(_uriGeocodingApi, string.Format("?address={0}&sensor={1}", /* no key required */ Uri.EscapeDataString(strAddress), ApiSensorArg, GoogleAPIs.GoogleAPIKey)); XPathNavigator navDocument = await RequestAndNavToDocumentAsync(uriGeocodeCall); if (null != navDocument) { XPathNavigator navNode = navDocument.SelectSingleNode("/GeocodeResponse/result[1]/geometry") as XPathNavigator; if (null != navNode) { location2d = CreateLocation2DFromNode(navNode); } } return(location2d); }
public Rectangle(int minX, int maxX, int minY, int maxY) { TopLeft = (minX, maxY); TopRight = (maxX, maxY); BottomLeft = (minX, minY); BottomRight = (maxX, minY); }
private void FlipTileAt(Location2D location) { this[location] = this[location] switch { TileColor.White => TileColor.Black, TileColor.Black => TileColor.White, }; }
public StarGrid(Location2D dimensions, Location2D[] values) : base(dimensions) { foreach (var v in values) { this[v] = true; } }
public bool WithinDiamond(Location2D location) { if (!IsValidLocation(location)) { return(false); } return(this[location] != default); }
public int Part2Returner(BeamGrid grid, int squareSize = 100) { for (int y = 0; y < grid.Height; y++) { int x = grid.GetMedianXOfFirstRegion(y, PointType.Beam); bool result = ValidateSquare(x, y); if (result) { Location2D closestLocation = (x, y); for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { if (closestLocation.ManhattanDistanceFromCenter < new Location2D((x - i, y - j)).ManhattanDistanceFromCenter) { continue; } if (ValidateSquare(x - i, y - j)) { closestLocation = (x - i, y - j); } } } return(closestLocation.X * 10000 + closestLocation.Y); } } return(-1); bool ValidateSquare(int x, int y) { if (x == -1) { return(false); } bool isValid = true; for (int x0 = x; isValid && x0 < x + squareSize; x0++) { isValid = grid[x0, y] == PointType.Beam; } if (!isValid) { return(false); } for (int y0 = y; isValid && y0 < y + squareSize; y0++) { isValid = grid[x, y0] == PointType.Beam; } return(isValid); } }
public ObjectId AddNewItemToGround(ModelId type, Location2D location, int amount = 1, Color?color = null) { var newItemId = NewItemId(); var packet = new ObjectInfoPacket(newItemId, type, (Location3D)location, color, (ushort?)amount); sendPacket(packet.RawPacket.Payload); return(newItemId); }
protected virtual void AnalyzeDirections() { Location2D location = (0, 0); GivenPresents.Add(location); foreach (var d in Directions) { location.Forward(d); GivenPresents.Add(location); } }
public string GetPathString(out int steps) { // Find the starting line int x = 0; for (; ; x++) { if (Values[x, 0].Type is DiagramCellType.Pathable) { break; } } string result = ""; steps = 1; Location2D location = (x, 0); var direction = new DirectionalLocation(Direction.Down, invertY: true); while (true) { // Attempt going forward, then attempt turning left, then turning right from original // If neither works; we've found the end Location2D next; if (!AttemptNextLocation()) { direction.TurnLeft(); if (!AttemptNextLocation()) { direction.TurnRight(2); if (!AttemptNextLocation()) { return(result); } } } steps++; location = next; char letter = this[location].Letter; if (letter != default) { result += letter; } bool AttemptNextLocation() { next = location + direction.LocationOffset; return(IsValidLocation(next) && this[next].Type is DiagramCellType.Pathable); } } }
public void PlayerEntersWorld(Location2D location) { var playerId = NewMobileId(); var entersWorldPayload = new byte[37]; var writer = new ArrayPacketWriter(entersWorldPayload); writer.WriteByte(0x1B); // packet writer.WriteId(playerId); // player id writer.WriteInt(0); // unknown writer.WriteModelId(0x190); // body type writer.WriteUShort((ushort)location.X); writer.WriteUShort((ushort)location.Y); writer.WriteByte(0); // unknown writer.WriteByte(0); // zlock writer.WriteByte(0x03); // facing writer.WriteInt(0x00007F00); // unknown writer.WriteInt(0x00061000); // unknown writer.WriteByte(0); // unkwnown writer.WriteUShort(0x0470); // server boundary width - 8 writer.WriteUShort(0x0470); // server boundary height writer.WriteUShort(0x0500); // server boundary height writer.WriteUShort(0x0000); // unknown sendPacket(entersWorldPayload); var drawPlayerPayload = new byte[30]; writer = new ArrayPacketWriter(drawPlayerPayload); writer.WriteByte(0x78); // packet writer.WriteUShort(30); // size writer.WriteId(playerId); // player id writer.WriteUShort(0x190); // graphics id writer.WriteUShort((ushort)location.X); // X writer.WriteUShort((ushort)location.Y); // Y writer.WriteByte(0); // Z writer.WriteByte(0x06); // facing writer.WriteColor((Color)0x0909); // color writer.WriteByte(0x00); // flag writer.WriteByte(0x01); // notoriety var backpackId = NewItemId(); writer.WriteId(backpackId); writer.WriteUShort(0x0E75); writer.WriteByte(0x15); writer.WriteInt(0); sendPacket(drawPlayerPayload); }
public override void Deserialize(Packet rawPacket) { this.rawPacket = rawPacket; var reader = new ArrayPacketReader(rawPacket.Payload); reader.Skip(1); MapId = reader.ReadObjectId(); MapArt = reader.ReadModelId(); UpperLeft = new Location2D(reader.ReadUShort(), reader.ReadUShort()); LowerRight = new Location2D(reader.ReadUShort(), reader.ReadUShort()); Width = reader.ReadUShort(); Height = reader.ReadUShort(); }
/* * Construction/destruction. */ public RegionPlaces(Location2D location2d, double metresradius, List <Place> listplaces) { _location2d = location2d; _metresradius = metresradius; _listplaces = listplaces; if (null != _listplaces) { _arrayIdRefs = new Place.IdRef[_listplaces.Count]; uint index = 0; foreach (Place place in _listplaces) { _arrayIdRefs[index++] = place.IdRefTuple; } } }
public QuestArrowPacket(Location2D location, bool active) { Location = location; Active = active; var payload = new byte[6]; var writer = new ArrayPacketWriter(payload); writer.WriteByte((byte)PacketDefinitions.QuestArrow.Id); writer.WriteByte((byte)(active ? 1 : 0)); writer.WriteUShort((ushort)location.X); writer.WriteUShort((ushort)location.Y); rawPacket = new Packet(payload[0], payload); }
public GridSquare GetMostPowerfulSquare(int size) { int maxPower = int.MinValue; var maxLocation = Location2D.Zero; foreach (var location in Location2D.EnumerateRectangleLocations(Location2D.Zero, Dimensions - (size, size))) { int powerSum = 0; for (int x0 = 0; x0 < size; x0++) { for (int y0 = 0; y0 < size; y0++) { powerSum += this[location + (x0, y0)]; }
private int Part2GeneralFunction(AsteroidGrid asteroids, AsteroidGrid bestSolution) { asteroids.PrintGrid(); if (asteroids.AsteroidCount < 200) { return(0); } asteroids.SetBestLocation(false); var sorted = new List <SlopedLocation>(); for (int x = 0; x < asteroids.Width; x++) { for (int y = 0; y < asteroids.Height; y++) { if (asteroids[x, y]) { var location = new Location2D(x, y); var degrees = AddDegrees(asteroids.BestLocation.GetSlopeDegrees(location), -90); var slopedLocation = new SlopedLocation(location, degrees, asteroids.BestLocation); sorted.Add(slopedLocation); } } } sorted.Sort(); int consecutive = 1; for (int i = 1; i < sorted.Count; i++) { if (sorted[i].HasEqualAbsoluteAngle(sorted[i - 1])) { sorted[i].AddFullCircleRotations(consecutive++); } else { consecutive = 1; } } sorted.Sort(); var l = sorted[199].Location; return(l.X * 100 + l.Y); }
public override void Deserialize(Packet rawPacket) { this.rawPacket = rawPacket; var reader = new ArrayPacketReader(rawPacket.Payload); reader.Skip(1); ItemId = reader.ReadObjectId(); Type = reader.ReadModelId(); reader.Skip(1); Amount = reader.ReadUShort(); Location = new Location2D(reader.ReadUShort(), reader.ReadUShort()); ContainerId = reader.ReadObjectId(); Color = (Color)reader.ReadUShort(); }
protected override void AnalyzeDirections() { Location2D santaLocation = (0, 0); Location2D roboLocation = (0, 0); GivenPresents.Add(santaLocation); for (int i = 0; i < Directions.Length; i += 2) { var santaDirection = Directions[i]; var roboDirection = Directions[i + 1]; santaLocation.Forward(santaDirection); roboLocation.Forward(roboDirection); GivenPresents.Add(santaLocation); GivenPresents.Add(roboLocation); } }
public override void Deserialize(Packet rawPacket) { this.rawPacket = rawPacket; var reader = new ArrayPacketReader(rawPacket.Payload); reader.Skip(1); var activeByte = reader.ReadByte(); if (activeByte != 0 && activeByte != 1) { throw new NotSupportedException($"QuestArrowPacket.Active has unsupported value: {activeByte}"); } Active = activeByte != 0; Location = new Location2D(reader.ReadUShort(), reader.ReadUShort()); }
internal void PurgeUnreachableItems(Location2D referenceLocation, ushort reachableRange) { var itemsOutOfRange = gameObjects.Values.Where(obj => obj.GetDistance(referenceLocation) >= reachableRange && obj.IsOnGround) .ToArray(); OnItemsLeftView(itemsOutOfRange); gameObjects = gameObjects.RemoveRange(itemsOutOfRange.Select(x => x.Id)); // to be perfectly correct, we would need to remove all nested orphaned containers as well, but this is good enough for now var orphanedItemIds = gameObjects.Values.OfType <Item>().Where(i => i.ContainerId.HasValue && i.ContainerId.Value != Player.PlayerId && !gameObjects.ContainsKey(i.ContainerId.Value)) .Select(i => i.Id); gameObjects = gameObjects.RemoveRange(orphanedItemIds); }
private void RunInstructions() { var current = Location2D.Zero; var currentDirection = new DirectionalLocation(Direction.Up); var visitedLocations = new HashSet <Location2D> { current }; bool hasRevisited = false; foreach (var instruction in instructions) { switch (instruction.Direction) { case Direction.Left: currentDirection.TurnLeft(); break; case Direction.Right: currentDirection.TurnRight(); break; } for (int i = 1; i <= instruction.Forward; i++) { current += currentDirection.LocationOffset; if (hasRevisited) { continue; } hasRevisited = !visitedLocations.Add(current); if (hasRevisited) { FirstRevisitedLocation = current; } } } EndingLocation = current; }
/* * Request places given a location (asynchronous). */ public async static Task <RegionPlaces> RequestPlacesAsync(Location2D location2d, string strTypesOfPlace, double metresradius) { List <Place> listplaces = new List <Place>(32 /* default capacity */); Uri uriPlacesCall = new Uri(_uriPlacesApi, string.Format("?location={0},{1}&radius={2}&types={3}&sensor={4}&key={5}", location2d.Latitude, location2d.Longitude, metresradius, /* radius (m) */ strTypesOfPlace, ApiSensorArg, GoogleAPIs.GoogleAPIKey)); XPathNavigator navDocument = await RequestAndNavToDocumentAsync(uriPlacesCall); if (null == navDocument) { return(null); } RegionPlaces regionplaces = null; XPathNodeIterator iteratorPlaces = navDocument.Select("/PlaceSearchResponse/result") as XPathNodeIterator; if (null != iteratorPlaces) { foreach (XPathNavigator navNode in iteratorPlaces) { Place place = CreatePlaceFromNode(navNode); if (null == place) { throw new InvalidOperationException(); } listplaces.Add(place); } regionplaces = new RegionPlaces(location2d, metresradius, listplaces); } return(regionplaces); }
public override void ApplyCommand(ShipCommand command) { switch (command.Type) { case ShipCommandType.North: case ShipCommandType.South: case ShipCommandType.East: case ShipCommandType.West: waypointOffset += new DirectionalLocation((Direction)command.Type).LocationOffset *command.Value; break; case ShipCommandType.Left: waypointOffset.TurnLeftAroundCenter(command.Value / 90); break; case ShipCommandType.Right: waypointOffset.TurnRightAroundCenter(command.Value / 90); break; case ShipCommandType.Forward: ShipLocation.Location += waypointOffset * command.Value; break; } }
public MassPoint(double mass, double x, double y) { Mass = mass; Loc = new Location2D(x, y); }
public MassPoint(double mass, Location2D loc) { Mass = mass; Loc = loc; }
public void Can_parse_two_numbers_separated_bycomma() { var location = Location2D.Parse("1234, 4321"); location.Should().Be(new Location2D(1234, 4321)); }
public static IEnumerable <Item> MinDistance(this IEnumerable <Item> items, Location2D referenceLocation, ushort minDistance) => items.Where(i => i.GetDistance(referenceLocation) >= minDistance);
internal QuestArrowEvent(bool active, Location2D location) { Active = active; Location = location; }