private static bool ValidWater(int WorldX, int WorldY) { CanFitFlags flags = CanFitFlags.requireSurface | CanFitFlags.canSwim | CanFitFlags.cantWalk; int z = Map.Felucca.GetAverageZ(WorldX, WorldY); if (Map.Felucca.CanSpawnMobile(new Point2D(WorldX, WorldY), z, flags)) { return(true); } else { return(false); } }
public virtual AddonFitResult CouldFit(bool blocking, IPoint3D p, Map map, Mobile from, ref ArrayList houseList) { if (Deleted) { return(AddonFitResult.Blocked); } ArrayList houses = new ArrayList(); foreach (AddonComponent c in m_Components) { Point3D p3D = new Point3D(p.X + c.Offset.X, p.Y + c.Offset.Y, p.Z + c.Offset.Z); CanFitFlags flags = CanFitFlags.checkMobiles; if (c.Z == 0) { flags |= CanFitFlags.requireSurface; } if (!map.CanFit(p3D.X, p3D.Y, p3D.Z, c.ItemData.Height, flags)) { return(AddonFitResult.Blocked); } else if (!CheckHouse(from, p3D, map, c.ItemData.Height, houses)) { return(AddonFitResult.NotInHouse); } } foreach (BaseHouse house in houses) { ArrayList doors = house.Doors; for (int i = 0; i < doors.Count; ++i) { BaseDoor door = doors[i] as BaseDoor; if (door != null && door.Open) { return(AddonFitResult.DoorsNotClosed); } Point3D doorLoc = door.GetWorldLocation(); int doorHeight = door.ItemData.CalcHeight; foreach (AddonComponent c in m_Components) { Point3D addonLoc = new Point3D(p.X + c.Offset.X, p.Y + c.Offset.Y, p.Z + c.Offset.Z); int addonHeight = c.ItemData.CalcHeight; if (Utility.InRange(doorLoc, addonLoc, 1) && (addonLoc.Z == doorLoc.Z || ((addonLoc.Z + addonHeight) > doorLoc.Z && (doorLoc.Z + doorHeight) > addonLoc.Z))) { if (blocking == true) { return(AddonFitResult.DoorTooClose); } } } } } houseList = houses; return(AddonFitResult.Valid); }
protected virtual Point3D GetSpawnLocation(Mobile m) { //Map map = Map; CanFitFlags flags = CanFitFlags.requireSurface; if (m != null && m.CanSwim == true) { flags |= CanFitFlags.canSwim; } if (m != null && m.CantWalk == true) { flags |= CanFitFlags.cantWalk; } if (Map == null) { return(Location); } // Try 10 times to find a spawnable location not near a player. for (int i = 0; i < 10; i++) { int x; int y; if ((((ChampLevelData)SpawnLevels[m_LevelCounter]).m_Flags & SpawnFlags.SpawnFar) != 0) { x = (int)((double)Location.X + Spawner.RandomFar() * (double)Lvl_MaxRange); y = (int)((double)Location.Y + Spawner.RandomFar() * (double)Lvl_MaxRange); } else { x = Location.X + (Utility.Random((Lvl_MaxRange * 2) + 1) - Lvl_MaxRange); y = Location.Y + (Utility.Random((Lvl_MaxRange * 2) + 1) - Lvl_MaxRange); } int z = Map.GetAverageZ(x, y); if (Map.CanSpawnMobile(new Point2D(x, y), this.Z, flags) && !NearPlayer(new Point3D(x, y, this.Z))) { return(new Point3D(x, y, this.Z)); } if (Map.CanSpawnMobile(new Point2D(x, y), z, flags) && !NearPlayer(new Point3D(x, y, z))) { return(new Point3D(x, y, z)); } } // Try 10 more times to find a any spawnable location. for (int i = 0; i < 10; i++) { int x; int y; if ((((ChampLevelData)SpawnLevels[m_LevelCounter]).m_Flags & SpawnFlags.SpawnFar) != 0) { x = (int)((double)Location.X + Spawner.RandomFar() * (double)Lvl_MaxRange); y = (int)((double)Location.Y + Spawner.RandomFar() * (double)Lvl_MaxRange); } else { x = Location.X + (Utility.Random((Lvl_MaxRange * 2) + 1) - Lvl_MaxRange); y = Location.Y + (Utility.Random((Lvl_MaxRange * 2) + 1) - Lvl_MaxRange); } int z = Map.GetAverageZ(x, y); if (Map.CanSpawnMobile(new Point2D(x, y), this.Z, flags)) { return(new Point3D(x, y, this.Z)); } if (Map.CanSpawnMobile(new Point2D(x, y), z, flags)) { return(new Point3D(x, y, z)); } } // Experimental, property-based, error reporting. // cannot find a valid location to spawn this creature Lvl_LevelError = LevelErrors.No_Location; return(Location); }
protected override Point3D GetSpawnLocation(Mobile m) { //Map map = Map; CanFitFlags flags = CanFitFlags.requireSurface; if (m != null && m.CanSwim == true) { flags |= CanFitFlags.canSwim; } if (m != null && m.CantWalk == true) { flags |= CanFitFlags.cantWalk; } if (Map == null) { return(Location); } Spawner s = null; if (m_CitySpawners.Count > 0) { s = m_CitySpawners.Peek(); //don't remove it yet, PrepMob wants to use it first. } if (s != null) { // Try 10 times to find a spawnable location near the next spawner. for (int i = 0; i < 10; i++) { int x; int y; x = (Utility.Random((s.X + (Utility.RandomBool() ? 10 : -10))) - s.X); y = (Utility.Random((s.Y + (Utility.RandomBool() ? 10 : -10))) - s.Y); int z = Map.GetAverageZ(x, y); if (Map.CanSpawnMobile(new Point2D(x, y), this.Z, flags) && !NearPlayer(new Point3D(x, y, this.Z))) { return(new Point3D(x, y, this.Z)); } if (Map.CanSpawnMobile(new Point2D(x, y), z, flags) && !NearPlayer(new Point3D(x, y, z))) { return(new Point3D(x, y, z)); } } } // Try 10 more times to find a any spawnable location. for (int i = 0; i < 10; i++) { int x; int y; x = Location.X + (Utility.Random((Lvl_MaxRange * 2) + 1) - Lvl_MaxRange); y = Location.Y + (Utility.Random((Lvl_MaxRange * 2) + 1) - Lvl_MaxRange); int z = Map.GetAverageZ(x, y); if (Map.CanSpawnMobile(new Point2D(x, y), this.Z, flags)) { return(new Point3D(x, y, this.Z)); } if (Map.CanSpawnMobile(new Point2D(x, y), z, flags)) { return(new Point3D(x, y, z)); } } // Experimental, property-based, error reporting. // cannot find a valid location to spawn this creature Lvl_LevelError = LevelErrors.No_Location; return(Location); }
public bool CanSpawnMobile(int x, int y, int z, CanFitFlags flags) { if (!Region.Find(new Point3D(x, y, z), this).AllowSpawn()) return false; return CanFit(x, y, z, 16, flags); }
public bool CanSpawnMobile(Point2D p, int z, CanFitFlags flags) { return CanSpawnMobile(p.m_X, p.m_Y, z, flags); }
public bool CanSpawnMobile(Point3D p, CanFitFlags flags) { return CanSpawnMobile(p.m_X, p.m_Y, p.m_Z, flags); }
//Pix: added ignoreDeadMobiles -- default is false (meaning we take them into account) // ignoreDeadMobiles==true means that we'll treat dead mobiles like they're not there. public bool CanFit(int x, int y, int z, int height, CanFitFlags flags) { bool checkBlocksFit = (flags & CanFitFlags.checkBlocksFit) != 0; bool checkMobiles = (flags & CanFitFlags.checkMobiles) != 0; bool requireSurface = (flags & CanFitFlags.requireSurface) != 0; bool ignoreDeadMobiles = (flags & CanFitFlags.ignoreDeadMobiles) != 0; bool canSwim = (flags & CanFitFlags.canSwim) != 0; bool cantWalk = (flags & CanFitFlags.cantWalk) != 0; if (this == Map.Internal) return false; if (x < 0 || y < 0 || x >= m_Width || y >= m_Height) return false; bool hasSurface = false; Tile lt = Tiles.GetLandTile(x, y); int lowZ = 0, avgZ = 0, topZ = 0; GetAverageZ(x, y, ref lowZ, ref avgZ, ref topZ); TileFlag landFlags = TileData.LandTable[lt.ID & 0x3FFF].Flags; if ((landFlags & TileFlag.Impassable) != 0 && avgZ > z && (z + height) > lowZ) return false; // can walk on land else if (!cantWalk && (landFlags & TileFlag.Impassable) == 0 && z == avgZ && !lt.Ignored) hasSurface = true; // can swim in water else if (canSwim && (landFlags & TileFlag.Impassable) != 0 && (landFlags & TileFlag.Wet) != 0 && z == avgZ && !lt.Ignored) hasSurface = true; Tile[] staticTiles = Tiles.GetStaticTiles(x, y, true); bool surface, impassable; for (int i = 0; i < staticTiles.Length; ++i) { ItemData id = TileData.ItemTable[staticTiles[i].ID & 0x3FFF]; surface = id.Surface; impassable = id.Impassable; if ((surface || impassable) && (staticTiles[i].Z + id.CalcHeight) > z && (z + height) > staticTiles[i].Z) return false; else if (surface && !impassable && z == (staticTiles[i].Z + id.CalcHeight)) hasSurface = true; } Sector sector = GetSector(x, y); Dictionary<Server.Serial, object>.ValueCollection items = sector.Items.Values, mobs = sector.Mobiles.Values; foreach (Item item in items) { if (item == null) continue; if (item.ItemID < 0x4000 && item.AtWorldPoint(x, y)) { ItemData id = item.ItemData; surface = id.Surface; impassable = id.Impassable; if ((surface || impassable || (checkBlocksFit && item.BlocksFit)) && (item.Z + id.CalcHeight) > z && (z + height) > item.Z) return false; else if (surface && !impassable && z == (item.Z + id.CalcHeight)) hasSurface = true; } } if (checkMobiles) { foreach (Mobile m in mobs) { if (m == null) continue; if (m.Alive == true || ignoreDeadMobiles == false) { if (m.Location.m_X == x && m.Location.m_Y == y) { if ((m.Z + 16) > z && (z + height) > m.Z) { return false; } } } } } return !requireSurface || hasSurface; }
public bool CanFit(Point3D p, int height, CanFitFlags flags) { return CanFit(p.m_X, p.m_Y, p.m_Z, height, flags); }