private static void PlaceItemOnWorld(Item item) { Rectangle2D rect = new Rectangle2D(0, 0, 5119, 4095); var placeCoords = new Point3D(); Map map = Utility.RandomBool() ? Map.Trammel : Map.Felucca; while (true) { var x = Utility.Random(rect.X, rect.Width); var y = Utility.Random(rect.Y, rect.Height); if (!TreasureMap.ValidateLocation(x, y, map)) { continue; } placeCoords.X = x; placeCoords.Y = y; placeCoords.Z = map.GetAverageZ(x, y); break; } item.MoveToWorld(placeCoords, map); }
private static Point3D?GetValidLocation(Map map) { if (map == null) { return(null); } var index = map == Map.Trammel ? 0 : 1; var attempts = (int)(Math.Sqrt(_Bounds.Width * _Bounds.Height) / 10); int x, y, h; bool valid; do { x = Utility.RandomMinMax(_Bounds.Start.X, _Bounds.End.X); y = Utility.RandomMinMax(_Bounds.Start.Y, _Bounds.End.Y); unchecked { h = (x + map.Width) * y; h = (h * 397) ^ x; h = (h * 397) ^ y; } lock (_InvalidLock) { if (_Invalid[index].Contains(h)) { valid = false; continue; } } valid = TreasureMap.ValidateLocation(x, y, map); if (!valid) { lock (_InvalidLock) { _Invalid[index].Add(h); } } }while (!valid && --attempts >= 0); if (valid) { return(new Point3D(x, y, map.GetAverageZ(x, y))); } return(null); }