/// <summary> /// Initializes a new instance of the <see cref="Sqm"/> class. /// </summary> /// <param name="sqmNumber">The SQM number.</param> /// <param name="map">The map.</param> /// <param name="playerSqm">The player SQM.</param> public Sqm(uint sqmNumber, GraphicsProvider map, Sqm playerSqm) { Map = map; SqmNumber = sqmNumber; Address = Map.SqmNumberToSqmAddress(SqmNumber); MemoryLocation = map.GetSqmLocation(SqmNumber); WorldLocation = map.MemoryToWorld(MemoryLocation, playerSqm); }
/// <summary> /// Worlds to memory. /// </summary> /// <param name="location">The location.</param> /// <param name="playerSqm">The player SQM.</param> /// <returns></returns> internal Location WorldToMemory(Location location, Sqm playerSqm) { var memoryLocation = playerSqm.MemoryLocation; uint x = Player.Location.X - memoryLocation.X; uint y = Player.Location.Y - memoryLocation.Y; uint z = Player.Location.Z - memoryLocation.Z; return new Location(location.X - x, location.Y - y, location.Z - z); }
/// <summary> /// Memories to world. /// </summary> /// <param name="location">The location.</param> /// <param name="playerSqm">The player SQM.</param> /// <returns></returns> internal Location MemoryToWorld(Location location, Sqm playerSqm) { var memoryLocation = playerSqm.MemoryLocation; uint x = Player.Location.X - memoryLocation.X; uint y = Player.Location.Y - memoryLocation.Y; uint z = Player.Location.Z - memoryLocation.Z; return new Location(location.X + x, location.Y + y, location.Z + z); }
/// <summary> /// Replaces the objects. /// </summary> /// <param name="oldObject">The old object.</param> /// <param name="newObject">The new object.</param> public void ReplaceObjects(uint oldObject, uint newObject) { var playerSqm = GetPlayerSqm(); for (uint i = 0; i < (Memory.Addresses.Map.TilesMax + 1); i++) { var sqm = new Sqm(i, this, playerSqm); var tiles = (from tile in sqm.Tiles where tile.TileId == oldObject select tile); if (tiles.Count() > 0) { tiles.ToList().ForEach(t => t.TileId = newObject); } } }
/// <summary> /// Gets the SQMS with object. /// </summary> /// <param name="objectId">The object id.</param> /// <returns></returns> public List<Sqm> GetSqmsWithObject(uint objectId) { var sqms = new List<Sqm>(); var playerSqm = GetPlayerSqm(); for (uint i = 0; i < (Memory.Addresses.Map.TilesMax + 1); i++) { var sqm = new Sqm(i, this, playerSqm); if (sqm.Contains(objectId)) { sqms.Add(sqm); } } return sqms; }
/// <summary> /// Gets the player SQM. /// </summary> /// <returns></returns> public Sqm GetPlayerSqm() { for (uint i = 0; i < (Memory.Addresses.Map.TilesMax + 1); i++) { var sqm = new Sqm(i, this, Player.Location); var res = (from tile in sqm.Tiles where tile.TileId == 0x63 && tile.Data == Player.Id select tile); if (res.Count() > 0) { return sqm; } } return null; }