public static void Add_Static( int itemID, Point3D location, Map map, string name ) { var eable = map.GetItemsInRange( location, 0 ); foreach ( Item item in eable ) { if ( item is Sign && item.Z == location.Z && item.ItemID == itemID ) m_ToDelete.Enqueue( item ); } while ( m_ToDelete.Count > 0 ) ( (Item) m_ToDelete.Dequeue() ).Delete(); Item sign; if ( name.StartsWith( "#" ) ) { sign = new LocalizedSign( itemID, Utility.ToInt32( name.Substring( 1 ) ) ); } else { sign = new Sign( itemID ); sign.Name = name; } if ( map == Map.Malas ) { if ( location.X >= 965 && location.Y >= 502 && location.X <= 1012 && location.Y <= 537 ) sign.Hue = 0x47E; else if ( location.X >= 1960 && location.Y >= 1278 && location.X < 2106 && location.Y < 1413 ) sign.Hue = 0x44E; } sign.MoveToWorld( location, map ); }
private static int DeleteMoonGate(Map map, Point3D p) { Queue<Item> m_Queue = new Queue<Item>(); IPooledEnumerable eable = map.GetItemsInRange(p, 0); foreach (Item item in eable) { if (item is PublicMoongate) { int delta = item.Z - p.Z; if (delta >= -12 && delta <= 12) m_Queue.Enqueue(item); } } eable.Free(); int m_Count = m_Queue.Count; while (m_Queue.Count > 0) (m_Queue.Dequeue()).Delete(); return m_Count; }
private static bool CheckItems( Point3D loc, Map map, int range, int maxAmount, bool checkTraps ) { var eable = map.GetItemsInRange( loc, range ); int amount = 0; foreach ( Item item in eable ) { if ( !checkTraps || item is FloorTrap ) amount++; } return amount < maxAmount; }
public static void ClearSpawners( int x, int y, int z, Map map ) { IPooledEnumerable eable = map.GetItemsInRange( new Point3D( x, y, z ), 0 ); foreach ( Item item in eable ) { if ( item is Spawner && item.Z == z ) m_ToDelete.Enqueue( item ); } eable.Free(); while ( m_ToDelete.Count > 0 ) ((Item)m_ToDelete.Dequeue()).Delete(); }
public virtual bool CheckPlantSeed( Point3D location, Map map, int range ) { IPooledEnumerable eable = map.GetItemsInRange( location, range ); int cropCount = 0; foreach( Item i in eable ) { if( i is BaseCrop ) cropCount++; } eable.Free(); return (cropCount == 0); }
private static bool FindMarkContainer( Point3D p, Map map ) { IPooledEnumerable eable = map.GetItemsInRange( p, 0 ); foreach ( Item item in eable ) { if ( item.Z == p.Z && item is MarkContainer ) { eable.Free(); return true; } } eable.Free(); return false; }
public static SHTeleporter FindSHTeleporter(Map map, Point3D p) { IPooledEnumerable eable = map.GetItemsInRange(p, 0); foreach (Item item in eable) { if (item is SHTeleporter && item.Z == p.Z) { eable.Free(); return (SHTeleporter)item; } } eable.Free(); return null; }
public static bool FindTeleporter( Map map, Point3D p ) { IPooledEnumerable eable = map.GetItemsInRange( p, 0 ); foreach ( Item item in eable ) { if ( item is Teleporter && !(item is KeywordTeleporter) && !(item is SkillTeleporter) ) { int delta = item.Z - p.Z; if ( delta >= -12 && delta <= 12 ) m_Queue.Enqueue( item ); } } eable.Free(); while ( m_Queue.Count > 0 ) ((Item)m_Queue.Dequeue()).Delete(); return false; }
public static bool FindItem(Point3D p, Map map, Item test) { bool result = false; IPooledEnumerable eable = map.GetItemsInRange(p); foreach (Item item in eable) { if (item.Z == p.Z && item.ItemID == test.ItemID) { m_DeleteQueue.Enqueue(item); result = true; } } eable.Free(); while (m_DeleteQueue.Count > 0) m_DeleteQueue.Dequeue().Delete(); return result; }
//looks at the location provided for a spawner, and returns it if it exists, otherwise makes a new one public static Spawner MakeUniqueSpawner( Point3D location, Map map ) { IPooledEnumerable ie = map.GetItemsInRange( location, 0 ); Spawner spawner = null; foreach( Item item in ie ) { if( item is Spawner ) { spawner = (Spawner)item; break; } } if( spawner == null ) { spawner = new Spawner(); spawner.MoveToWorld( location, map ); } return spawner; }
public static bool RemoveItem(Point3D p, Map map, Type t) { IPooledEnumerable eable = map.GetItemsInRange(p, 0); foreach (Item i in eable) { if (i.GetType() == t) { i.Delete(); eable.Free(); return true; } } eable.Free(); return false; }
public static void Del_Static( int itemID, Point3D location, Map map ) { IPooledEnumerable eable = map.GetItemsInRange( location, 0 ); foreach ( Item item in eable ) { if ( item is Sign && item.Z == location.Z && item.ItemID == itemID ) { m_ToDelete.Enqueue( item ); m_DelCount++; } } eable.Free(); while ( m_ToDelete.Count > 0 ) m_ToDelete.Dequeue().Delete(); }
public virtual int IsValidLocation( Point3D p, Map m ) { if( m == null ) return 502956; // You cannot place a trap on that. if( Core.AOS ) { foreach( Item item in m.GetItemsInRange( p, 5 ) ) { if( item is BaseFactionTrap && ((BaseFactionTrap)item).Faction == this.Faction ) return 1075263; // There is already a trap belonging to your faction at this location.; } } switch( AllowedPlacing ) { case AllowedPlacing.FactionStronghold: { StrongholdRegion region = (StrongholdRegion) Region.Find( p, m ).GetRegion( typeof( StrongholdRegion ) ); if ( region != null && region.Faction == m_Faction ) return 0; return 1010355; // This trap can only be placed in your stronghold } case AllowedPlacing.AnyFactionTown: { Town town = Town.FromRegion( Region.Find( p, m ) ); if ( town != null ) return 0; return 1010356; // This trap can only be placed in a faction town } case AllowedPlacing.ControlledFactionTown: { Town town = Town.FromRegion( Region.Find( p, m ) ); if ( town != null && town.Owner == m_Faction ) return 0; return 1010357; // This trap can only be placed in a town your faction controls } } return 0; }
public static bool CheckForAltar(Point3D p, Map map) { IPooledEnumerable eable = map.GetItemsInRange(p, 0); foreach (Item i in eable) { if (i is ShameAltar || i is ShameWall) { eable.Free(); return true; } } eable.Free(); return false; }
private bool CanDropCrate(ref Point3D pnt, Map map) { for (int i = 0; i < 45; i++) { int x = Utility.Random(m_Bounds.X, m_Bounds.Width); int y = Utility.Random(m_Bounds.Y, m_Bounds.Height); int z = -2; bool badSpot = false; Point3D p = new Point3D(x, y, z); IPooledEnumerable eable = map.GetItemsInRange(pnt, 0); foreach (Item item in eable) { if (item != null && item is Container && !item.Movable) { badSpot = true; break; } } eable.Free(); if (!badSpot) { pnt = p; return true; } } return false; }
private static void Process(Map map, Rectangle2D[] regions) { m_ShopTable = new Hashtable(); m_ShopList = new ArrayList(); World.Broadcast(0x35, true, "Generating vendor spawns for {0}, please wait.", map); for (int i = 0; i < regions.Length; ++i) { for (int x = 0; x < map.Width; ++x) { for (int y = 0; y < map.Height; ++y) { CheckPoint(map, regions[i].X + x, regions[i].Y + y); } } } for (int i = 0; i < m_ShopList.Count; ++i) { ShopInfo si = (ShopInfo)m_ShopList[i]; int xTotal = 0; int yTotal = 0; bool hasSpawner = false; for (int j = 0; !hasSpawner && j < si.m_Floor.Count; ++j) { Point2D fp = (Point2D)si.m_Floor[j]; xTotal += fp.X; yTotal += fp.Y; IPooledEnumerable eable = map.GetItemsInRange(new Point3D(fp.X, fp.Y, 0), 0); foreach (Item item in eable) { if (item is Spawner) { hasSpawner = true; break; } } eable.Free(); if (hasSpawner) { break; } } if (hasSpawner) { continue; } int xAvg = xTotal / si.m_Floor.Count; int yAvg = yTotal / si.m_Floor.Count; ArrayList names = new ArrayList(); ShopFlags flags = si.m_Flags; if ((flags & ShopFlags.Armor) != 0) { names.Add("armorer"); } if ((flags & ShopFlags.MetalWeapon) != 0) { names.Add("weaponsmith"); } if ((flags & ShopFlags.ArcheryWeapon) != 0) { names.Add("bowyer"); } if ((flags & ShopFlags.Scroll) != 0) { names.Add("mage"); } if ((flags & ShopFlags.Spellbook) != 0) { names.Add("mage"); } if ((flags & ShopFlags.Bread) != 0) { names.Add("baker"); } if ((flags & ShopFlags.Jewel) != 0) { names.Add("jeweler"); } if ((flags & ShopFlags.Potion) != 0) { names.Add("herbalist"); names.Add("alchemist"); names.Add("mage"); } if ((flags & ShopFlags.Reagent) != 0) { names.Add("mage"); names.Add("herbalist"); } if ((flags & ShopFlags.Clothes) != 0) { names.Add("tailor"); names.Add("weaver"); } for (int j = 0; j < names.Count; ++j) { Point2D cp = Point2D.Zero; int dist = 100000; int tz; for (int k = 0; k < si.m_Floor.Count; ++k) { Point2D fp = (Point2D)si.m_Floor[k]; int rx = fp.X - xAvg; int ry = fp.Y - yAvg; int fd = (int)Math.Sqrt(rx * rx + ry * ry); if (fd > 0 && fd < 5) { fd -= Utility.Random(10); } if (fd < dist && GetFloorZ(map, fp.X, fp.Y, out tz)) { dist = fd; cp = fp; } } if (cp == Point2D.Zero) { continue; } int z; if (!GetFloorZ(map, cp.X, cp.Y, out z)) { continue; } new Spawner(1, 1, 1, 0, 4, (string)names[j]).MoveToWorld(new Point3D(cp.X, cp.Y, z), map); } } World.Broadcast(0x35, true, "Generation complete. {0} spawners generated.", m_ShopList.Count); }
public static bool FindItem(Point3D p, Map map, Item test) { IPooledEnumerable eable = map.GetItemsInRange(p); foreach (Item item in eable) { if (item.Z == p.Z && item.ItemID == test.ItemID) { eable.Free(); return true; } } eable.Free(); return false; }
public static ArrayList CheckCrop( Point3D pnt, Map map, int range ) { ArrayList crops = new ArrayList(); IPooledEnumerable eable = map.GetItemsInRange( pnt, range ); foreach ( Item crop in eable ) { if ( ( crop != null ) && ( crop is BaseCrop ) ) crops.Add( (BaseCrop)crop ); } eable.Free(); return crops; }
private static bool FindItem( int x, int y, int z, Map map, Item srcItem ) { int itemID = srcItem.ItemID; bool res = false; IPooledEnumerable eable; if ( (TileData.ItemTable[itemID & TileData.MaxItemValue].Flags & TileFlag.LightSource) != 0 ) { eable = map.GetItemsInRange( new Point3D( x, y, z ), 0 ); LightType lt = srcItem.Light; string srcName = srcItem.ItemData.Name; foreach ( Item item in eable ) { if ( item.Z == z ) { if ( item.ItemID == itemID ) { if ( item.Light != lt ) m_DeleteQueue.Enqueue( item ); else res = true; } else if ( (item.ItemData.Flags & TileFlag.LightSource) != 0 && item.ItemData.Name == srcName ) { m_DeleteQueue.Enqueue( item ); } } } } else { eable = map.GetItemsInRange( new Point3D( x, y, z ), 0 ); foreach ( Item item in eable ) { if ( item.Z == z && item.ItemID == itemID ) { eable.Free(); return true; } } } eable.Free(); while ( m_DeleteQueue.Count > 0 ) ((Item)m_DeleteQueue.Dequeue()).Delete(); return res; }
private static bool FindMarkContainer( Point3D p, Map map ) { var eable = map.GetItemsInRange( p, 0 ); foreach ( Item item in eable ) { if ( item.Z == p.Z && item is MarkContainer ) { return true; } } return false; }
private bool ValidateLocation(Point3D p, Map map) { if (!TreasureMap.ValidateLocation(p.X, p.Y, map)) return false; for (int x = p.X - 1; x <= p.X + 1; x++) { for (int y = p.Y - 1; y <= p.Y + 1; y++) { if(TreasureMap.ValidateLocation(x, y, map)) { int z = map.GetAverageZ(x, y); IPooledEnumerable eable = map.GetItemsInRange(new Point3D(x, y, z), 0); foreach (Item item in eable) { ItemData id = TileData.ItemTable[item.ItemID & TileData.MaxItemValue]; if (item.Z + id.CalcHeight >= z) { eable.Free(); return false; } } eable.Free(); return true; } } } return false; }
private static bool FindItem( int x, int y, int z, Map map, Item srcItem ) { int itemID = srcItem.ItemID; bool res = false; IPooledEnumerable eable; if ( srcItem is BaseDoor ) { eable = map.GetItemsInRange( new Point3D( x, y, z ), 1 ); foreach ( Item item in eable ) { if ( !(item is BaseDoor) ) continue; BaseDoor bd = (BaseDoor)item; Point3D p; int bdItemID; if ( bd.Open ) { p = new Point3D( bd.X - bd.Offset.X, bd.Y - bd.Offset.Y, bd.Z - bd.Offset.Z ); bdItemID = bd.ClosedID; } else { p = bd.Location; bdItemID = bd.ItemID; } if ( p.X != x || p.Y != y ) continue; if ( item.Z == z && bdItemID == itemID ) res = true; else if ( Math.Abs( item.Z - z ) < 8 ) m_DeleteQueue.Enqueue( item ); } } else if ( (TileData.ItemTable[itemID & 0x3FFF].Flags & TileFlag.LightSource) != 0 ) { eable = map.GetItemsInRange( new Point3D( x, y, z ), 0 ); LightType lt = srcItem.Light; string srcName = srcItem.ItemData.Name; foreach ( Item item in eable ) { if ( item.Z == z ) { if ( item.ItemID == itemID ) { if ( item.Light != lt ) m_DeleteQueue.Enqueue( item ); else res = true; } else if ( (item.ItemData.Flags & TileFlag.LightSource) != 0 && item.ItemData.Name == srcName ) { m_DeleteQueue.Enqueue( item ); } } } } else if ( srcItem is Teleporter || srcItem is FillableContainer || srcItem is BaseBook ) { eable = map.GetItemsInRange( new Point3D( x, y, z ), 0 ); Type type = srcItem.GetType(); foreach ( Item item in eable ) { if ( item.Z == z && item.ItemID == itemID ) { if ( item.GetType() != type ) m_DeleteQueue.Enqueue( item ); else res = true; } } } else { eable = map.GetItemsInRange( new Point3D( x, y, z ), 0 ); foreach ( Item item in eable ) { if ( item.Z == z && item.ItemID == itemID ) { eable.Free(); return true; } } } eable.Free(); while ( m_DeleteQueue.Count > 0 ) ((Item)m_DeleteQueue.Dequeue()).Delete(); return res; }
public virtual bool CheckWeeds( Point3D location, Map map ) { IPooledEnumerable eable = map.GetItemsInRange( location, 1 ); foreach( Item i in eable ) { if( i is Weeds ) return true; } return false; }
public void DestroyTeleporter( int x, int y, int z, Map map ) { Point3D p = new Point3D( x, y, z ); IPooledEnumerable eable = map.GetItemsInRange( p, 0 ); foreach ( Item item in eable ) { if ( item is Teleporter && !(item is KeywordTeleporter) && !(item is SkillTeleporter) && item.Z == p.Z ) m_Queue.Enqueue( item ); } eable.Free(); while ( m_Queue.Count > 0 ) ((Item)m_Queue.Dequeue()).Delete(); }
private bool TileAlreadyContainsMine( Point3D location, Map map ) { IPooledEnumerable eable = map.GetItemsInRange( location, 0 ); bool mined = false; foreach ( Item entity in eable ) { if ( Math.Abs( location.Z - entity.Z ) <= 16 ) { if ( entity is BaseMine ) { mined = true; break; } } } eable.Free(); return mined; }
private static void Process( Map map, Rectangle2D[] regions ) { m_ShopTable = new Hashtable(); m_ShopList = new ArrayList(); World.Broadcast( 0x35, true, "Generating vendor spawns for {0}, please wait.", map ); for ( int i = 0; i < regions.Length; ++i ) for ( int x = 0; x < map.Width; ++x ) for ( int y = 0; y < map.Height; ++y ) CheckPoint( map, regions[i].X + x, regions[i].Y + y ); for ( int i = 0; i < m_ShopList.Count; ++i ) { ShopInfo si = (ShopInfo)m_ShopList[i]; int xTotal = 0; int yTotal = 0; bool hasSpawner = false; for ( int j = 0; !hasSpawner && j < si.m_Floor.Count; ++j ) { Point2D fp = (Point2D)si.m_Floor[j]; xTotal += fp.X; yTotal += fp.Y; IPooledEnumerable eable = map.GetItemsInRange( new Point3D( fp.X, fp.Y, 0 ), 0 ); foreach ( Item item in eable ) { if ( item is Spawner ) { hasSpawner = true; break; } } eable.Free(); if ( hasSpawner ) break; } if ( hasSpawner ) continue; int xAvg = xTotal / si.m_Floor.Count; int yAvg = yTotal / si.m_Floor.Count; ArrayList names = new ArrayList(); ShopFlags flags = si.m_Flags; if ( (flags & ShopFlags.Armor) != 0 ) names.Add( "armorer" ); if ( (flags & ShopFlags.MetalWeapon) != 0 ) names.Add( "weaponsmith" ); if ( (flags & ShopFlags.ArcheryWeapon) != 0 ) names.Add( "bowyer" ); if ( (flags & ShopFlags.Scroll) != 0 ) names.Add( "mage" ); if ( (flags & ShopFlags.Spellbook) != 0 ) names.Add( "mage" ); if ( (flags & ShopFlags.Bread) != 0 ) names.Add( "baker" ); if ( (flags & ShopFlags.Jewel) != 0 ) names.Add( "jeweler" ); if ( (flags & ShopFlags.Potion) != 0 ) { names.Add( "herbalist" ); names.Add( "alchemist" ); names.Add( "mage" ); } if ( (flags & ShopFlags.Reagent) != 0 ) { names.Add( "mage" ); names.Add( "herbalist" ); } if ( (flags & ShopFlags.Clothes) != 0 ) { names.Add( "tailor" ); names.Add( "weaver" ); } for ( int j = 0; j < names.Count; ++j ) { Point2D cp = Point2D.Zero; int dist = 100000; int tz; for ( int k = 0; k < si.m_Floor.Count; ++k ) { Point2D fp = (Point2D)si.m_Floor[k]; int rx = fp.X - xAvg; int ry = fp.Y - yAvg; int fd = (int)Math.Sqrt( rx*rx + ry*ry ); if ( fd > 0 && fd < 5 ) fd -= Utility.Random( 10 ); if ( fd < dist && GetFloorZ( map, fp.X, fp.Y, out tz ) ) { dist = fd; cp = fp; } } if ( cp == Point2D.Zero ) continue; int z; if ( !GetFloorZ( map, cp.X, cp.Y, out z ) ) continue; new Spawner( 1, 1, 1, 0, 4, (string)names[j] ).MoveToWorld( new Point3D( cp.X, cp.Y, z ), map ); } } World.Broadcast( 0x35, true, "Generation complete. {0} spawners generated.", m_ShopList.Count ); }
public bool IsValidLocation(int x, int y, int z, Map map) { IPooledEnumerable eable = map.GetItemsInRange(new Point3D(x, y, z), 1); foreach (Item item in eable) { if (item is LobsterTrap) { eable.Free(); return false; } } eable.Free(); return true; }