public void Register() { if (m_Registered) { return; } OnRegister(); m_Registered = true; if (m_Parent != null) { m_Parent.m_Children.Add(this); m_Parent.OnChildAdded(this); } m_Regions.Add(this); m_Map.RegisterRegion(this); List <Sector> sectors = new List <Sector>(); for (int i = 0; i < m_Area.Length; i++) { Rectangle3D rect = m_Area[i]; Point2D start = m_Map.Bound(new Point2D(rect.Start)); Point2D end = m_Map.Bound(new Point2D(rect.End)); Sector startSector = m_Map.GetSector(start); Sector endSector = m_Map.GetSector(end); for (int x = startSector.X; x <= endSector.X; x++) { for (int y = startSector.Y; y <= endSector.Y; y++) { Sector sector = m_Map.GetRealSector(x, y); sector.OnEnter(this, rect); if (!sectors.Contains(sector)) { sectors.Add(sector); } } } } m_Sectors = sectors.ToArray(); }
public static IEnumerable <Region> FindRegions(Point3D p, Map map) { if (map == null) { yield return(Map.Internal.DefaultRegion); } else { Sector sector = map.GetSector(p); List <RegionRect> list = sector.RegionRects; bool found = false; for (int i = 0; i < list.Count; ++i) { RegionRect regRect = list[i]; if (regRect.Contains(p)) { if (!found) { found = true; } yield return(regRect.Region); } } if (!found) { yield return(map.DefaultRegion); } } }
public static bool CheckCitiesInRange(Mobile from, Point3D p) { // Very Speical Thanks To ArteGordon For His Help On This Bool Map map = from.Map; int offset = CityRangeOffset; int offset2 = offset * 3; int x1 = p.X - offset; int y1 = p.Y - offset; int width = offset2; int height = offset2; int depth = p.Z; for (int x = x1; x <= x1 + width; x += Map.SectorSize) { for (int y = y1; y <= y1 + height; y += Map.SectorSize) { Sector s = map.GetSector(new Point3D(x, y, depth)); foreach (RegionRect rect in s.RegionRects) { Region r = rect.Region; if (r is GuardedRegion || r is PlayerCityRegion) { return(true); } } } } return(false); }
private void BoundingBox_Callback( Mobile from, Map map, Point3D start, Point3D end, object state ) { Utility.FixPoints( ref start, ref end ); Rectangle2D rect = new Rectangle2D(start, end); #region MobileSaver from.SendMessage( "Extracting Mobiles" ); foreach ( Mobile m in map.GetMobilesInBounds( rect ) ) { if ( m != null && m is BaseCreature ) { int saveflag = MobileSaver.GetSaveFlag( m ); if ( saveflag > 0 ) { DesignItem designItem = new DesignItem(); designItem.ItemID = (short)0x1; designItem.X = m.X; designItem.Y = m.Y; designItem.Z = m.Z + saveflag; designItem.Hue = (short)m.Hue; } } } #endregion for ( int x = 0; x <= rect.Width; ++x ) { for ( int y = 0; y <= rect.Height; ++y ) { int tileX = rect.Start.X + x; int tileY = rect.Start.Y + y; Sector sector = map.GetSector( tileX, tileY ); for ( int i = 0; i < sector.Items.Count; ++i ) { Item item = (Item)sector.Items[i]; if(_args.UseMinZ && item.Z < _args.MinZ) continue; else if(_args.UseMaxZ && item.Z > _args.MaxZ) continue; if ( item.Visible && item.X == tileX && item.Y == tileY && !((item is BaseMulti) || (item is HouseSign)) ) { _itemSerials.Add(item.Serial.Value); } } } } if(_itemSerials.Count > 0) SendResponse(new SelectItemsResponse((int[])_itemSerials.ToArray(typeof(int)))); else SendResponse(null); }
public virtual void Unregister() { if (m_Coords == null || m_Map == null) { return; } for (int i = 0; i < m_Coords.Count; ++i) { object obj = m_Coords[i]; Point2D start, end; if (obj is Rectangle2D) { Rectangle2D r2d = (Rectangle2D)obj; start = m_Map.Bound(r2d.Start); end = m_Map.Bound(r2d.End); } else if (obj is Rectangle3D) { Rectangle3D r3d = (Rectangle3D)obj; start = m_Map.Bound(new Point2D(r3d.Start)); end = m_Map.Bound(new Point2D(r3d.End)); } else { continue; } Sector startSector = m_Map.GetSector(start); Sector endSector = m_Map.GetSector(end); for (int x = startSector.X; x <= endSector.X; ++x) { for (int y = startSector.Y; y <= endSector.Y; ++y) { m_Map.GetRealSector(x, y).OnLeave(this); } } } }
/// <summary> /// Gets a BaseMulti collection representing all BaseMultis that are within 'range' of 'center' on the given 'map' /// </summary> public static List <BaseMulti> GetMultisInRange(this IPoint3D center, Map map, int range) { if (center == null || map == null) { return(new List <BaseMulti>()); } return (map.GetSector(center).Multis.Where(v => v != null && (v.Contains(center) || v.InRange2D(center, range))).ToList()); }
/// <summary> /// Gets a BaseMulti collection representing all BaseMultis that are within 'range' of 'center' on the given 'map' /// </summary> public static IEnumerable <BaseMulti> FindMultisInRange(this IPoint3D center, Map map, int range) { if (center == null || map == null) { yield break; } var scan = map.GetSector(center).Multis.Where(v => v != null && (v.Contains(center) || v.InRange2D(center, range))); foreach (var m in scan) { yield return(m); } }
public static BaseBoat FindBoatAt( IPoint2D loc, Map map ) { Sector sector = map.GetSector( loc ); for ( int i = 0; i < sector.Multis.Count; i++ ) { BaseBoat boat = sector.Multis[i] as BaseBoat; if ( boat != null && boat.Contains( loc.X, loc.Y ) ) return boat; } return null; }
public static Region Find(Point3D p, Map map) { if (map == null) { return(Map.Internal.DefaultRegion); } Sector sector = map.GetSector(p); ArrayList list = sector.Regions; for (int i = 0; i < list.Count; ++i) { Region region = (Region)list[i]; if (region.Contains(p)) { return(region); } } return(map.DefaultRegion); }
public static Region Find(Point3D p, Map map) { if (map == null) { return(Map.Internal.DefaultRegion); } Sector sector = map.GetSector(p); List <RegionRect> list = sector.RegionRects; for (int i = 0; i < list.Count; ++i) { RegionRect regRect = list[i]; if (regRect.Contains(p)) { return(regRect.Region); } } return(map.DefaultRegion); }
public static Region Find(Point3D p, Map map) { int num1; Region region1; if (map == null) { return(Map.Internal.DefaultRegion); } Sector sector1 = map.GetSector(p); ArrayList list1 = sector1.Regions; for (num1 = 0; (num1 < list1.Count); ++num1) { region1 = ((Region)list1[num1]); if (region1.Contains(p)) { return(region1); } } return(map.DefaultRegion); }
private void BoundingBox_Callback( Mobile from, Map map, Point3D start, Point3D end, object state ) { Utility.FixPoints( ref start, ref end ); Rectangle2D rect = new Rectangle2D(start, end); for ( int x = 0; x <= rect.Width; ++x ) { for ( int y = 0; y <= rect.Height; ++y ) { int tileX = rect.Start.X + x; int tileY = rect.Start.Y + y; Sector sector = map.GetSector( tileX, tileY ); for ( int i = 0; i < sector.Items.Count; ++i ) { Item item = (Item)sector.Items[i]; if(_args.UseMinZ && item.Z < _args.MinZ) continue; else if(_args.UseMaxZ && item.Z > _args.MaxZ) continue; if ( item.Visible && item.X == tileX && item.Y == tileY && !((item is BaseMulti) || (item is HouseSign)) ) { _itemSerials.Add(item.Serial.Value); } } } } if(_itemSerials.Count > 0) SendResponse(new SelectItemsResponse((int[])_itemSerials.ToArray(typeof(int)))); else SendResponse(null); }
public static bool CheckMulti( Point3D p, Map map, bool houses ) { if( map == null || map == Map.Internal ) return false; Sector sector = map.GetSector( p.X, p.Y ); for( int i = 0; i < sector.Multis.Count; ++i ) { BaseMulti multi = sector.Multis[i]; if( multi is BaseHouse ) { if( houses && ((BaseHouse)multi).IsInside( p, 16 ) ) return true; } else if( multi.Contains( p ) ) { return true; } } return false; }
public static object GetTopSurface(this Map map, Point3D p, bool multis) { if (map == Map.Internal) { return(null); } object surface = null; var surfaceZ = int.MinValue; var lt = map.Tiles.GetLandTile(p.X, p.Y); if (!lt.Ignored) { var avgZ = map.GetAverageZ(p.X, p.Y); if (avgZ <= p.Z) { surface = lt; surfaceZ = avgZ; if (surfaceZ == p.Z) { return(surface); } } } var staticTiles = map.Tiles.GetStaticTiles(p.X, p.Y, multis); ItemData id; int tileZ; foreach (var tile in staticTiles) { id = TileData.ItemTable[tile.ID & TileData.MaxItemValue]; if (!id.Surface && (id.Flags & TileFlag.Wet) == 0) { continue; } tileZ = tile.Z + id.CalcHeight; if (tileZ <= surfaceZ || tileZ > p.Z) { continue; } surface = tile; surfaceZ = tileZ; if (surfaceZ == p.Z) { return(surface); } } var sector = map.GetSector(p.X, p.Y); int itemZ; var items = sector.Items.Where( o => o.ItemID <= TileData.MaxItemValue && !o.Movable && !(o is BaseMulti) && o.AtWorldPoint(p.X, p.Y)); foreach (var item in items) { id = item.ItemData; if (!id.Surface && (id.Flags & TileFlag.Wet) == 0) { continue; } itemZ = item.Z + id.CalcHeight; if (itemZ <= surfaceZ || itemZ > p.Z) { continue; } surface = item; surfaceZ = itemZ; if (surfaceZ == p.Z) { return(surface); } } return(surface); }
public bool CheckMovement( Mobile m, Map map, Point3D loc, Direction d, out int newZ ) { if ( map == null || map == Map.Internal ) { newZ = 0; return false; } int xStart = loc.X; int yStart = loc.Y; int xForward = xStart, yForward = yStart; int xRight = xStart, yRight = yStart; int xLeft = xStart, yLeft = yStart; bool checkDiagonals = ((int)d & 0x1) == 0x1; Offset( d, ref xForward, ref yForward ); Offset( (Direction)(((int)d - 1) & 0x7), ref xLeft, ref yLeft ); Offset( (Direction)(((int)d + 1) & 0x7), ref xRight, ref yRight ); if ( xForward < 0 || yForward < 0 || xForward >= map.Width || yForward >= map.Height ) { newZ = 0; return false; } int startZ, startTop; List<Item> itemsStart = m_Pools[0]; List<Item> itemsForward = m_Pools[1]; List<Item> itemsLeft = m_Pools[2]; List<Item> itemsRight = m_Pools[3]; bool ignoreMovableImpassables = m_IgnoreMovableImpassables; TileFlag reqFlags = ImpassableSurface; if ( m.CanSwim ) reqFlags |= TileFlag.Wet; List<Mobile> mobsForward = m_MobPools[0]; List<Mobile> mobsLeft = m_MobPools[1]; List<Mobile> mobsRight = m_MobPools[2]; bool checkMobs = ( m is BaseCreature && !((BaseCreature)m).Controlled && ( xForward != m_Goal.X || yForward != m_Goal.Y ) ); if ( checkDiagonals ) { Sector sectorStart = map.GetSector( xStart, yStart ); Sector sectorForward = map.GetSector( xForward, yForward ); Sector sectorLeft = map.GetSector( xLeft, yLeft ); Sector sectorRight = map.GetSector( xRight, yRight ); List<Sector> sectors = m_Sectors; sectors.Add( sectorStart ); if ( !sectors.Contains( sectorForward ) ) sectors.Add( sectorForward ); if ( !sectors.Contains( sectorLeft ) ) sectors.Add( sectorLeft ); if ( !sectors.Contains( sectorRight ) ) sectors.Add( sectorRight ); for ( int i = 0; i < sectors.Count; ++i ) { Sector sector = sectors[i]; for ( int j = 0; j < sector.Items.Count; ++j ) { Item item = sector.Items[j]; if ( ignoreMovableImpassables && item.Movable && ( item.ItemData.Flags & ImpassableSurface ) != 0 ) continue; if ( (item.ItemData.Flags & reqFlags) == 0 ) continue; if ( sector == sectorStart && item.AtWorldPoint( xStart, yStart ) && !(item is BaseMulti) && item.ItemID <= TileData.MaxItemValue ) itemsStart.Add( item ); else if ( sector == sectorForward && item.AtWorldPoint( xForward, yForward ) && !(item is BaseMulti) && item.ItemID <= TileData.MaxItemValue ) itemsForward.Add( item ); else if ( sector == sectorLeft && item.AtWorldPoint( xLeft, yLeft ) && !(item is BaseMulti) && item.ItemID <= TileData.MaxItemValue ) itemsLeft.Add( item ); else if ( sector == sectorRight && item.AtWorldPoint( xRight, yRight ) && !(item is BaseMulti) && item.ItemID <= TileData.MaxItemValue ) itemsRight.Add( item ); } if ( checkMobs ) { for ( int j = 0; j < sector.Mobiles.Count; ++j ) { Mobile mob = sector.Mobiles[j]; if ( sector == sectorForward && mob.X == xForward && mob.Y == yForward ) mobsForward.Add( mob ); else if ( sector == sectorLeft && mob.X == xLeft && mob.Y == yLeft ) mobsLeft.Add( mob ); else if ( sector == sectorRight && mob.X == xRight && mob.Y == yRight ) mobsRight.Add( mob ); } } } if ( m_Sectors.Count > 0 ) m_Sectors.Clear(); } else { Sector sectorStart = map.GetSector( xStart, yStart ); Sector sectorForward = map.GetSector( xForward, yForward ); if ( sectorStart == sectorForward ) { for ( int i = 0; i < sectorStart.Items.Count; ++i ) { Item item = sectorStart.Items[i]; if ( ignoreMovableImpassables && item.Movable && ( item.ItemData.Flags & ImpassableSurface ) != 0 ) continue; if ( (item.ItemData.Flags & reqFlags) == 0 ) continue; if ( item.AtWorldPoint( xStart, yStart ) && !(item is BaseMulti) && item.ItemID <= TileData.MaxItemValue ) itemsStart.Add( item ); else if ( item.AtWorldPoint( xForward, yForward ) && !(item is BaseMulti) && item.ItemID <= TileData.MaxItemValue ) itemsForward.Add( item ); } } else { for ( int i = 0; i < sectorForward.Items.Count; ++i ) { Item item = sectorForward.Items[i]; if ( ignoreMovableImpassables && item.Movable && ( item.ItemData.Flags & ImpassableSurface ) != 0 ) continue; if ( (item.ItemData.Flags & reqFlags) == 0 ) continue; if ( item.AtWorldPoint( xForward, yForward ) && !(item is BaseMulti) && item.ItemID <= TileData.MaxItemValue ) itemsForward.Add( item ); } for ( int i = 0; i < sectorStart.Items.Count; ++i ) { Item item = sectorStart.Items[i]; if ( ignoreMovableImpassables && item.Movable && ( item.ItemData.Flags & ImpassableSurface ) != 0 ) continue; if ( (item.ItemData.Flags & reqFlags) == 0 ) continue; if ( item.AtWorldPoint( xStart, yStart ) && !(item is BaseMulti) && item.ItemID <= TileData.MaxItemValue ) itemsStart.Add( item ); } } if ( checkMobs ) { for ( int i = 0; i < sectorForward.Mobiles.Count; ++i ) { Mobile mob = sectorForward.Mobiles[i]; if ( mob.X == xForward && mob.Y == yForward ) mobsForward.Add( mob ); } } } GetStartZ( m, map, loc, itemsStart, out startZ, out startTop ); bool moveIsOk = Check( map, m, itemsForward, mobsForward, xForward, yForward, startTop, startZ, m.CanSwim, m.CantWalk, out newZ ); if ( moveIsOk && checkDiagonals ) { int hold; if ( m.Player && m.AccessLevel < AccessLevel.GameMaster ) { if ( !Check( map, m, itemsLeft, mobsLeft, xLeft, yLeft, startTop, startZ, m.CanSwim, m.CantWalk, out hold ) || !Check( map, m, itemsRight, mobsRight, xRight, yRight, startTop, startZ, m.CanSwim, m.CantWalk, out hold ) ) moveIsOk = false; } else { if ( !Check( map, m, itemsLeft, mobsLeft, xLeft, yLeft, startTop, startZ, m.CanSwim, m.CantWalk, out hold ) && !Check( map, m, itemsRight, mobsRight, xRight, yRight, startTop, startZ, m.CanSwim, m.CantWalk, out hold ) ) moveIsOk = false; } } for ( int i = 0; i < (checkDiagonals ? 4 : 2); ++i ) { if ( m_Pools[i].Count != 0 ) m_Pools[i].Clear(); } for ( int i = 0; i < (checkDiagonals ? 3 : 1); ++i ) { if ( m_MobPools[i].Count != 0 ) m_MobPools[i].Clear(); } if ( !moveIsOk ) newZ = startZ; return moveIsOk; }
private static bool CanFit(Map map, int x, int y, int z) { bool hasSurface = false; Tile lt = map.Tiles.GetLandTile(x, y); int lowZ = 0, avgZ = 0, topZ = 0; map.GetAverageZ(x, y, ref lowZ, ref avgZ, ref topZ); TileFlag landFlags = TileData.LandTable[lt.ID & 0x3FFF].Flags; if ((landFlags & TileFlag.Impassable) != 0 && topZ > z && (z + 16) > lowZ) { return(false); } else if ((landFlags & TileFlag.Impassable) == 0 && z == avgZ && !lt.Ignored) { hasSurface = true; } Tile[] staticTiles = map.Tiles.GetStaticTiles(x, y); bool surface, impassable; for (int i = 0; i < staticTiles.Length; ++i) { if (IsDisplayCase(staticTiles[i].ID)) { continue; } ItemData id = TileData.ItemTable[staticTiles[i].ID & 0x3FFF]; surface = id.Surface; impassable = id.Impassable; if ((surface || impassable) && (staticTiles[i].Z + id.CalcHeight) > z && (z + 16) > staticTiles[i].Z) { return(false); } else if (surface && !impassable && z == (staticTiles[i].Z + id.CalcHeight)) { hasSurface = true; } } Sector sector = map.GetSector(x, y); foreach (Item item in sector.Items.Values) { if (item == null) { continue; } if (item.AtWorldPoint(x, y)) { ItemData id = item.ItemData; surface = id.Surface; impassable = id.Impassable; if ((surface || impassable) && (item.Z + id.CalcHeight) > z && (z + 16) > item.Z) { return(false); } else if (surface && !impassable && z == (item.Z + id.CalcHeight)) { hasSurface = true; } } } return(hasSurface); }
public static bool CheckTravel(Map map, Point3D loc, TravelCheckType type, Mobile caster, out bool jail) { jail = false; if ( IsInvalid( map, loc ) ) // null, internal, out of bounds return false; // custom regions CustomRegion reg = Region.Find( loc, map ) as CustomRegion; CustomRegion reg2 = CustomRegion.FindDRDTRegion(caster); if( reg != null ) { try { RegionControl regstone = null; //if a custom region does exsist find its controller regstone = reg.GetRegionControler(); if (regstone != null && caster.AccessLevel == AccessLevel.Player) { if(regstone.AllowTravelSpellsInRegion && reg == reg2) return true; if(regstone.NoRecallInto && type == TravelCheckType.RecallTo) return false; if(regstone.NoGateInto && type == TravelCheckType.GateTo) return false; Spell spell = new GateTravelSpell(caster, null); if(regstone.IsRestrictedSpell(spell, caster) && type == TravelCheckType.GateFrom) return false; if(regstone.CannotEnter && type == TravelCheckType.TeleportTo) return false; } } catch(NullReferenceException e) { LogHelper.LogException(e); Console.WriteLine("{0} Caught exception.", e); } catch(Exception ex) { LogHelper.LogException(ex); } } if( reg2 != null ) { try { RegionControl regstone = null; //if a custom region does exsist find its controller regstone = reg2.GetRegionControler(); if (regstone != null && caster.AccessLevel == AccessLevel.Player) { if(regstone.AllowTravelSpellsInRegion && reg == reg2) return true; if(regstone.NoRecallInto && type == TravelCheckType.RecallTo) return false; if(regstone.NoGateInto && type == TravelCheckType.GateTo) return false; Spell spell = new GateTravelSpell(caster, null); if(regstone.IsRestrictedSpell(spell, caster) && type == TravelCheckType.GateFrom) return false; if(regstone.CannotEnter && type == TravelCheckType.TeleportTo) return false; } } catch(NullReferenceException e) { LogHelper.LogException(e); Console.WriteLine("{0} Caught exception.", e); } catch(Exception ex) { LogHelper.LogException(ex); } } //Deal with house SecurePremises flag if ((type == TravelCheckType.GateTo || type == TravelCheckType.RecallTo || type == TravelCheckType.TeleportTo) && caster.AccessLevel == AccessLevel.Player) { BaseHouse dst_house = null; Sector sector = map.GetSector( loc ); foreach (BaseMulti mx in sector.Multis.Values) { BaseHouse _house = mx as BaseHouse; if (_house == null) continue; if ( _house != null && _house.Region.Contains(loc) ) { dst_house = _house; } } if( dst_house != null ) { if( dst_house.SecurePremises ) { if( !dst_house.IsFriend( caster ) ) { return false; } } } } // Gate inside a PreviewHouse exploit. Go directally to jail, don't collect $200.0 if ((type == TravelCheckType.GateTo ||type == TravelCheckType.RecallTo || type == TravelCheckType.TeleportTo) && caster.AccessLevel == AccessLevel.Player) { if (PreviewHouseAt(caster.Map, loc)) { LogHelper.Cheater(caster, "Travel inside a PreviewHouse exploit.", true); jail = true; return false; } } // Teleport onto a stack of stuff =\ if (type == TravelCheckType.TeleportTo && caster.AccessLevel == AccessLevel.Player) { // if we are teleporting onto a stack of movable items, and at least 3 reside on different Z planes // then it looks too much like an exploit to allow it. if (iStack(caster, loc, 2) == false) { LogHelper.Cheater(caster, "Tele onto a stack of movable items.", true); return false; } } // mark on a stack of stuff =\ // same as teleport above, but different limit and different message if (type == TravelCheckType.Mark && caster.AccessLevel == AccessLevel.Player) { // if we are marking on a stack of movable items, and at least 2 reside on different Z planes // then it looks too much like an exploit to allow it. if (iStack(caster, loc, 2) == false) { LogHelper.Cheater(caster, "Mark on a stack of movable items.", true); return false; } } // disallow teleporting from outside the house into the inside if the doors are closed (no LOS) if ((type == TravelCheckType.TeleportTo) && caster.AccessLevel == AccessLevel.Player) { BaseHouse dst_house = null; Sector sector = map.GetSector(loc); foreach (BaseMulti mx in sector.Multis.Values) { BaseHouse _house = mx as BaseHouse; if (_house == null) continue; if (_house != null && _house.Region.Contains(loc)) { dst_house = _house; } } // is the user trying to shoot through a door without LOS? if (dst_house != null) { if (!caster.InLOS(loc)) { LogHelper.Cheater(caster, "Try to teleport through front door (LOS)", true); return false; } } // is the user not standing on the ground? if (dst_house != null && dst_house.Region != null) { if (!caster.Map.CanSpawnMobile(caster.Location.X, caster.Location.Y, caster.Location.Z, CanFitFlags.requireSurface)) { LogHelper.Cheater(caster, "Try to teleport over front door (Z Axis)", true); return false; } } } // special housing region/multi exploit - teleport from multi to castle courtyard // stop players from teleporting from one multi to another (includes PreviewHouses) if(type == TravelCheckType.TeleportTo && caster.AccessLevel == AccessLevel.Player) { // if there is a house at the destination, then.. // if all the multis and regions do not match between src and dst, fail if (HouseAt(caster.Map, loc) && CheckParity(caster.Map, caster.Location, loc) == false) { LogHelper.Cheater(caster, "Multi to multi teleport exploit.", true); return false; } } // Replaced by above CheckParity() implementation (delete after 5/1/07) // special housing region exploit - teleport from tower roof to castle courtyard /*if(type == TravelCheckType.TeleportTo && caster.AccessLevel == AccessLevel.Player) { BaseHouse src_house = BaseHouse.FindHouseAt( caster ); BaseHouse dst_house = null; // add this redundant check here to eliminate the house enumeration // for the cases when it's not needed. if (src_house != null) { // build super sector that includes both src and dest ArrayList SuperSector = new ArrayList(); SuperSector.Add(src_house); Sector sector = map.GetSector( loc ); for ( int i = 0; i < sector.Multis.Count; ++i ) { BaseHouse _house = sector.Multis[i] as BaseHouse; if ( _house != null ) if (SuperSector.Contains(_house) == false) // disallow duplicates SuperSector.Add(_house); } // now add these if the houses are in different sectors if (sector != map.GetSector( caster )) { sector = map.GetSector( caster ); for ( int i = 0; i < sector.Multis.Count; ++i ) { BaseHouse _house = sector.Multis[i] as BaseHouse; if ( _house != null ) if (SuperSector.Contains(_house) == false) // disallow duplicates SuperSector.Add(_house); } } // get the destination house for ( int i = 0; i < SuperSector.Count; ++i ) { BaseHouse _house = SuperSector[i] as BaseHouse; if ( _house.Region.Contains(loc) ) { //Console.WriteLine("dst_house.region{0}, loc{1}", _house.Region.Coords.ToString(), loc.ToString()); dst_house = _house; } } // okay, if source house and dest house are different, fail bool house = (src_house != null && dst_house != null); if (house == true && src_house != dst_house) { //Console.WriteLine("Caught invalid teleport."); LogHelper.Cheater(caster, "Tower roof teleport exploit: case(1)", true); return false; } // house region overlap test: possible with the Tower overhang, overhanging // another house / courtyard int houses = 0; for ( int i = 0; i < SuperSector.Count; ++i ) { BaseHouse _house = SuperSector[i] as BaseHouse; if ( _house.Region.Contains(caster.Location) ) houses++; } if (houses > 1) { LogHelper.Cheater(caster, "Tower roof teleport exploit: case(2)", true); return false; } } }*/ // okay, now check our locale rules table int v = (int)type; bool isValid = true; for ( int i = 0; isValid && i < m_Validators.Length; ++i ) isValid = ( m_Rules[v, i] || !m_Validators[i]( map, loc ) ); return isValid; }
public static ArrayList FindAll(Point3D p, Map map) { ArrayList all = new ArrayList(); if (map == null) { all.Add(Map.Internal.DefaultRegion); return all; } Sector sector = map.GetSector(p); ArrayList list = sector.Regions; for (int i = 0; i < list.Count; ++i) { if (list[i] is Region) { Region region = list[i] as Region; if (region.Contains(p)) all.Add(region); } } all.Add(map.DefaultRegion); return all; }
private static HousePlacementResult HousePlacementRegionCheck(Mobile from, Map map, Point3D testPoint) { Sector sector = map.GetSector(testPoint); ArrayList list = sector.Regions; for (int i = 0; i < list.Count; ++i) { Region region = (Region)list[i]; if (region.Contains(testPoint)) { if (region is HouseRegion) return HousePlacementResult.BadRegion; if (!region.AllowHousing(from, testPoint)) // Cannot place houses in dungeons, towns, treasure map areas etc { if (region is TreasureRegion) return HousePlacementResult.BadRegionHidden; return HousePlacementResult.BadRegion; } if (region is TownshipRegion) { if (((TownshipRegion)region).CanBuildHouseInTownship(from) == false) { return HousePlacementResult.BadRegionTownship; } } if (region is NoHousingRegion) return HousePlacementResult.BadRegion; } } return HousePlacementResult.Valid; }
private static bool CanFit(Map map, int x, int y, int z) { var hasSurface = false; var lt = map.Tiles.GetLandTile(x, y); int lowZ = 0, avgZ = 0, topZ = 0; map.GetAverageZ(x, y, ref lowZ, ref avgZ, ref topZ); var landFlags = TileData.LandTable[lt.ID & TileData.MaxLandValue].Flags; if ((landFlags & TileFlag.Impassable) != 0 && topZ > z && z + 16 > lowZ) { return(false); } if ((landFlags & TileFlag.Impassable) == 0 && z == avgZ && !lt.Ignored) { hasSurface = true; } var staticTiles = map.Tiles.GetStaticTiles(x, y); bool surface, impassable; for (var i = 0; i < staticTiles.Length; ++i) { if (IsDisplayCase(staticTiles[i].ID)) { continue; } var id = TileData.ItemTable[staticTiles[i].ID & TileData.MaxItemValue]; surface = id.Surface; impassable = id.Impassable; if ((surface || impassable) && staticTiles[i].Z + id.CalcHeight > z && z + 16 > staticTiles[i].Z) { return(false); } if (surface && !impassable && z == staticTiles[i].Z + id.CalcHeight) { hasSurface = true; } } var sector = map.GetSector(x, y); var items = sector.Items; for (var i = 0; i < items.Count; ++i) { var item = items[i]; if (item.AtWorldPoint(x, y)) { var id = item.ItemData; surface = id.Surface; impassable = id.Impassable; if ((surface || impassable) && item.Z + id.CalcHeight > z && z + 16 > item.Z) { return(false); } if (surface && !impassable && z == item.Z + id.CalcHeight) { hasSurface = true; } } } return(hasSurface); }
public static Region Find( Point3D p, Map map ) { if ( map == null ) return Map.Internal.DefaultRegion; Sector sector = map.GetSector( p ); List<RegionRect> list = sector.RegionRects; for ( int i = 0; i < list.Count; ++i ) { RegionRect regRect = list[i]; if ( regRect.Contains( p ) ) return regRect.Region; } return map.DefaultRegion; }
public static BaseHouse FindHouseAt(Point3D loc, Map map, int height) { if (map == null || map == Map.Internal) return null; Sector sector = map.GetSector(loc); foreach (BaseMulti mult in sector.Multis.Values) { BaseHouse house = mult as BaseHouse; if (house != null && house.IsInside(loc, height)) return house; } return null; }
public static List<StaticTile> GetTilesAt(Map map, Point2D p, bool items, bool land, bool statics) { List<StaticTile> list = new List<StaticTile>(); if (map == Map.Internal) return list; if (statics) list.AddRange(map.Tiles.GetStaticTiles(p.X, p.Y, true)); if (items) { Sector sector = map.GetSector(p); foreach (Item item in sector.Items) if (item.AtWorldPoint(p.X, p.Y)) list.Add(new StaticTile((ushort)item.ItemID, (sbyte)item.Z)); } return list; }
private static bool IsPointInNoMurderZone(Point3D p, Map map) { if (map == null) return false; Sector sector = map.GetSector(p); ArrayList list = sector.Regions; bool bReturn = false; for (int i = 0; i < list.Count; ++i) { Region region = (Region)list[i]; if (region.Contains(p)) { if (region.IsNoMurderZone) { bReturn = true; } } } return bReturn; }
public static Region Find( Point3D p, Map map ) { if ( map == null ) return Map.Internal.DefaultRegion; Sector sector = map.GetSector( p ); ArrayList list = sector.Regions; for ( int i = 0; i < list.Count; ++i ) { Region region = (Region)list[i]; if ( region.Contains( p ) ) return region; } return map.DefaultRegion; }
public static BaseHouse FindHouseAt( Point3D loc, Map map, int height ) { if ( map == null || map == Map.Internal ) return null; Sector sector = map.GetSector( loc ); for ( int i = 0; i < sector.Multis.Count; ++i ) { BaseHouse house = sector.Multis[i] as BaseHouse; if ( house != null && house.IsInside( loc, height ) ) return house; } return null; }
public bool CheckMovement( Mobile m, Map map, Point3D loc, Direction d, out int newZ ) { if ( map == null || map == Map.Internal ) { newZ = 0; return false; } int xStart = loc.X; int yStart = loc.Y; int xForward = xStart, yForward = yStart; int xRight = xStart, yRight = yStart; int xLeft = xStart, yLeft = yStart; bool checkDiagonals = ((int)d & 0x1) == 0x1; Offset( d, ref xForward, ref yForward ); Offset( (Direction)(((int)d - 1) & 0x7), ref xLeft, ref yLeft ); Offset( (Direction)(((int)d + 1) & 0x7), ref xRight, ref yRight ); if ( xForward < 0 || yForward < 0 || xForward >= map.Width || yForward >= map.Height ) { newZ = 0; return false; } int startZ, startTop; ArrayList itemsStart = m_Pools[0]; ArrayList itemsForward = m_Pools[1]; ArrayList itemsLeft = m_Pools[2]; ArrayList itemsRight = m_Pools[3]; ArrayList items; bool ignoreMovableImpassables = m_IgnoreMovableImpassables; TileFlag reqFlags = ImpassableSurface; if ( m.CanSwim ) reqFlags |= TileFlag.Wet; if ( checkDiagonals ) { Sector sectorStart = map.GetSector( xStart, yStart ); Sector sectorForward = map.GetSector( xForward, yForward ); Sector sectorLeft = map.GetSector( xLeft, yLeft ); Sector sectorRight = map.GetSector( xRight, yRight ); ArrayList sectors = m_Pools[4]; sectors.Add( sectorStart ); if ( !sectors.Contains( sectorForward ) ) sectors.Add( sectorForward ); if ( !sectors.Contains( sectorLeft ) ) sectors.Add( sectorLeft ); if ( !sectors.Contains( sectorRight ) ) sectors.Add( sectorRight ); for ( int i = 0; i < sectors.Count; ++i ) { Sector sector = (Sector)sectors[i]; items = sector.Items; for ( int j = 0; j < items.Count; ++j ) { Item item = (Item)items[j]; if ( ignoreMovableImpassables && item.Movable && item.ItemData.Impassable ) continue; if ( (item.ItemData.Flags & reqFlags) == 0 ) continue; if ( sector == sectorStart && item.AtWorldPoint( xStart, yStart ) && item.ItemID < 0x4000 ) itemsStart.Add( item ); else if ( sector == sectorForward && item.AtWorldPoint( xForward, yForward ) && item.ItemID < 0x4000 ) itemsForward.Add( item ); else if ( sector == sectorLeft && item.AtWorldPoint( xLeft, yLeft ) && item.ItemID < 0x4000 ) itemsLeft.Add( item ); else if ( sector == sectorRight && item.AtWorldPoint( xRight, yRight ) && item.ItemID < 0x4000 ) itemsRight.Add( item ); } } if ( m_Pools[4].Count > 0 ) m_Pools[4].Clear(); } else { Sector sectorStart = map.GetSector( xStart, yStart ); Sector sectorForward = map.GetSector( xForward, yForward ); if ( sectorStart == sectorForward ) { items = sectorStart.Items; for ( int i = 0; i < items.Count; ++i ) { Item item = (Item)items[i]; if ( ignoreMovableImpassables && item.Movable && item.ItemData.Impassable ) continue; if ( (item.ItemData.Flags & reqFlags) == 0 ) continue; if ( item.AtWorldPoint( xStart, yStart ) && item.ItemID < 0x4000 ) itemsStart.Add( item ); else if ( item.AtWorldPoint( xForward, yForward ) && item.ItemID < 0x4000 ) itemsForward.Add( item ); } } else { items = sectorForward.Items; for ( int i = 0; i < items.Count; ++i ) { Item item = (Item)items[i]; if ( ignoreMovableImpassables && item.Movable && item.ItemData.Impassable ) continue; if ( (item.ItemData.Flags & reqFlags) == 0 ) continue; if ( item.AtWorldPoint( xForward, yForward ) && item.ItemID < 0x4000 ) itemsForward.Add( item ); } items = sectorStart.Items; for ( int i = 0; i < items.Count; ++i ) { Item item = (Item)items[i]; if ( ignoreMovableImpassables && item.Movable && item.ItemData.Impassable ) continue; if ( (item.ItemData.Flags & reqFlags) == 0 ) continue; if ( item.AtWorldPoint( xStart, yStart ) && item.ItemID < 0x4000 ) itemsStart.Add( item ); } } } GetStartZ( m, map, loc, itemsStart, out startZ, out startTop ); bool moveIsOk = Check( map, m, itemsForward, xForward, yForward, startTop, startZ, m.CanSwim, m.CantWalk, out newZ ); if ( moveIsOk && checkDiagonals ) { int hold; if ( !Check( map, m, itemsLeft, xLeft, yLeft, startTop, startZ, m.CanSwim, m.CantWalk, out hold ) && !Check( map, m, itemsRight, xRight, yRight, startTop, startZ, m.CanSwim, m.CantWalk, out hold ) ) moveIsOk = false; } for ( int i = 0; i < (checkDiagonals ? 4 : 2); ++i ) { if ( m_Pools[i].Count > 0 ) m_Pools[i].Clear(); } if ( !moveIsOk ) newZ = startZ; return moveIsOk; }
public static CustomRegion FindDRDTRegion(Map map, Point3D loc) { Point3D p = loc; if (p == Point3D.Zero) return null; if (map == Map.Internal || map == null) return null; Sector sector = map.GetSector(p); if (sector == null || sector.Owner == null || sector == sector.Owner.InvalidSector) return null; if (sector.Regions == null) //new check 2/2/07 return null; ArrayList list = sector.Regions; if (list == null || list.Count == 0) return null; ArrayList list2 = new ArrayList(); for (int i = 0; i < list.Count; ++i) { if (list[i] is Region) //new check 2/2/07 { Region region = (Region)list[i]; if (region == null) continue; if (region.Contains(p)) list2.Add(region); } } foreach (Region reg in list2) { if (reg == null) continue; CustomRegion test = null; if (reg is CustomRegion) { test = reg as CustomRegion; if (test != null) return test; } } //no custom region found return null; }
private static bool IsMobileCountableAtPoint(Mobile m, Point3D p, Map map) { if (map == null) return true; Sector sector = map.GetSector(p); ArrayList list = sector.Regions; bool bReturn = true; for (int i = 0; i < list.Count; ++i) { Region region = (Region)list[i]; if (region.Contains(p)) { if (region.IsMobileCountable(m) == false) { bReturn = false; } } } return bReturn; }
private static bool CanFit( Map map, int x, int y, int z ) { bool hasSurface = false; LandTile lt = map.Tiles.GetLandTile( x, y ); int lowZ = 0, avgZ = 0, topZ = 0; map.GetAverageZ( x, y, ref lowZ, ref avgZ, ref topZ ); TileFlag landFlags = TileData.LandTable[lt.ID & TileData.MaxLandValue].Flags; if ( (landFlags & TileFlag.Impassable) != 0 && topZ > z && (z + 16) > lowZ ) return false; else if ( (landFlags & TileFlag.Impassable) == 0 && z == avgZ && !lt.Ignored ) hasSurface = true; StaticTile[] staticTiles = map.Tiles.GetStaticTiles( x, y ); bool surface, impassable; for ( int i = 0; i < staticTiles.Length; ++i ) { if ( IsDisplayCase( staticTiles[i].ID ) ) continue; ItemData id = TileData.ItemTable[staticTiles[i].ID & TileData.MaxItemValue]; surface = id.Surface; impassable = id.Impassable; if ( (surface || impassable) && (staticTiles[i].Z + id.CalcHeight) > z && (z + 16) > staticTiles[i].Z ) return false; else if ( surface && !impassable && z == (staticTiles[i].Z + id.CalcHeight) ) hasSurface = true; } Sector sector = map.GetSector( x, y ); List<Item> items = sector.Items; for ( int i = 0; i < items.Count; ++i ) { Item item = items[i]; if ( item.AtWorldPoint( x, y ) ) { ItemData id = item.ItemData; surface = id.Surface; impassable = id.Impassable; if ( (surface || impassable) && (item.Z + id.CalcHeight) > z && (z + 16) > item.Z ) return false; else if ( surface && !impassable && z == (item.Z + id.CalcHeight) ) hasSurface = true; } } return hasSurface; }
private Region FindRegion( Point3D location, Map map ) { Region reg = Region.Find( location, map ); if( reg is CustomRegion ) { Sector s = map.GetSector( location ); int highestPriority = 0; for( int i = 0; i < s.RegionRects.Count; i++ ) { if( s.RegionRects[i].Region.Priority > highestPriority ) { highestPriority = s.RegionRects[i].Region.Priority; reg = s.RegionRects[i].Region; } } } if( reg == null || String.IsNullOrEmpty( reg.Name ) || reg.Name == "world" ) return null; return reg; }