عرض مشاركة واحدة
قديم 2019-08-27, 09:49 PM
المشاركة 7
AliNasser
.:: عضو مميز ::.
  • غير متواجد
افتراضي رد: مشكله رخمه في الوحوش الكبيره
دا كلاس ماب شاكك ان المشكله منه


كود:
using System;
using System.IO;
using System.Drawing;
using System.Threading;
using System.Collections.Generic;
using KhaledMohamed.Interfaces;
using System.Text;
using System.Linq;
using KhaledMohamed.Network.GamePackets;
using System.Threading.Generic;
using KhaledMohamed.Client;
using System.Collections.Concurrent;
using KhaledMohamed.Database;

namespace 
KhaledMohamed.Game
{
    public class 
Map
    
{
        public 
Dictionary<uintWindWalker.ThunderCloudClouds = new Dictionary<uintWindWalker.ThunderCloud>();
        public 
DMapPortal[] portals;
        public 
SafeDictionary<uintEntityCompanions;
        [
System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
        public 
struct DMapPortal
        
{
            private 
ushort xCord;
            private 
ushort yCord;
            public 
ushort XCord
            
{
                
get
                
{
                    return 
this.xCord;
                }
                
set
                
{
                    
this.xCord value;
                }
            }
            public 
ushort YCord
            
{
                
get
                
{
                    return 
this.yCord;
                }
                
set
                
{
                    
this.yCord value;
                }
            }
        }
        public 
void AddCloud(WindWalker.ThunderCloud entity)
        {
            try
            {
                if (!
this.Clouds.ContainsKey(entity.UID))
                    
this.Clouds.Add(entity.UIDentity);

            }
            catch (
Exception e)
            {
                
Console.WriteLine(e);
            }
        }

        public 
void PopulatePortals(uint amount)
        {
            
this.portals = new DMapPortal[amount];
        }
        public 
void SetPortal(int PositionDMapPortal portal)
        {
            
this.portals[Position] = portal;
        }

        public static 
Counter DynamicIDs = new KhaledMohamed.Counter(11000)
        {
            
Finish =
                
0
        
};

        public static 
Enums.ConquerAngle[] Angles = new Enums.ConquerAngle[] {
            
Enums.ConquerAngle.SouthWest,
            
Enums.ConquerAngle.West,
            
Enums.ConquerAngle.NorthWest,
            
Enums.ConquerAngle.North,
            
Enums.ConquerAngle.NorthEast,
            
Enums.ConquerAngle.East,
            
Enums.ConquerAngle.SouthEast,
            
Enums.ConquerAngle.South };
        public static 
Floor ArenaBaseFloor null;
        public 
Counter EntityUIDCounter = new KhaledMohamed.Counter(400000);
        public 
Counter EntityUIDCounter2 = new KhaledMohamed.Counter(100000);
        public 
Counter CloneCounter = new KhaledMohamed.Counter(700000);
        public List<
Zoning.ZoneZones = new List<Zoning.Zone>();
        public 
ushort ID;
        public 
ushort BaseID;
        public 
bool WasPKFree false;
        public 
Floor Floor;
        public 
string Path;
        public 
bool IsDynamic()
        {
            return 
BaseID != ID;
        }
        public 
SafeDictionary<uintEntityEntities;
        public 
SafeDictionary<uintEntityAIs;
      
//  public SafeDictionary<uint, Entity> Companions;
        
public Dictionary<uintINpcNpcs;
        public 
Dictionary<uintINpcStatues = new Dictionary<uintINpc>();
        public 
Dictionary<uintINpcTempNpcs = new Dictionary<uintINpc>();
        
//   public Dictionary<uint, SobNpcSpawn> Furniture = new Dictionary<uint, SobNpcSpawn>();  
        
public ConcurrentDictionary<uintFloorItemFloorItems;
        public 
void AddPole(INpc npc)
        {
            
Npcs[npc.UID] = npc;
            
Floor[npc.Xnpc.YMapObjectType.InvalidCastnpc] = false;
        }
        public 
void AddMonesterTimer()
        {
            
Timer MonsterTimers.Add(this);
        }
        public 
void RemovePole(INpc npc)
        {
            
Npcs.Remove(npc.UID);
            
Floor[npc.Xnpc.YMapObjectType.InvalidCastnull] = true;
        }
        public 
void AddNpc(INpc npcbool addquery false)
        {
            if (
Npcs.ContainsKey(npc.UID) == false || addquery)
            {
                if (!
addquery)
                    
Npcs.Add(npc.UIDnpc);
                
#region Setting the near coords invalid to avoid unpickable items.
                
Floor[npc.Xnpc.YMapObjectType.InvalidCastnpc] = false;
                if (
npc.Mesh 10 != 108 && (byte)npc.Type 10)
                {
                    
ushort X npc.Xnpc.Y;
                    foreach (
Enums.ConquerAngle angle in Angles)
                    {
                        
ushort xX XyY Y;
                        
UpdateCoordonatesForAngle(ref xXref yYangle);
                        
Floor[xXyYMapObjectType.InvalidCastnull] = false;
                    }
                }
                
#endregion
            
}
        }
        public 
void SpawnGoldBox(Client.GameState clientushort IDushort xushort y)
        {

            
MonsterInformation mt;
            
MonsterInformation.MonsterInformations.TryGetValue(7562out mt);
            if (
mt == null) return;
            
mt.IsRespawnAble false;
            for (var 
01i++)
            {
                var 
entity = new Entity(EntityFlag.Monsterfalse)
                {
                    
MapObjType MapObjectType.Monster,
                    
MonsterInfo mt.Copy()
                };
                
entity.MonsterInfo.Owner entity;
                
entity.Name string.Intern(mt.Name);
                
entity.MinAttack mt.MinAttack;
                
entity.MaxAttack entity.MagicAttack mt.MaxAttack;
                
entity.Hitpoints entity.MaxHitpoints mt.Hitpoints;
                
entity.Body mt.Mesh;
                
entity.Level mt.Level;
                
entity.MapID 3846;
                
entity.SendUpdates true;
                
entity.UID Kernel.Maps[3846].EntityUIDCounter.Next;
                
entity.= (ushort)x;
                
entity.= (ushort)y;
                
Kernel.Maps[3846].AddEntity(entity);
            }

        }
        public 
void AddEntity(Entity entity)
        {
            if (
entity.UID 800000 || entity.Body == 1003)
            {
                if (
Entities.ContainsKey(entity.UID) == false)
                {
                    
Entities.Add(entity.UIDentity);
                    
Floor[entity.Xentity.YMapObjectType.Monsterentity] = false;
                }
            }
        }
        public 
void AddAI(Entity entity)
        {
            if (!
this.AIs.ContainsKey(entity.UID))
            {
                
this.AIs.Add(entity.UIDentity);
                
this.Floor[entity.Xentity.YMapObjectType.Entityentity] = false;
            }
            else
            {
                
this.RemoveEntity(entity);
                
this.AIs.Add(entity.UIDentity);
                
this.Floor[entity.Xentity.YMapObjectType.Entityentity] = false;
            }
        }
        public 
void RemoveAI(Entity entity)
        {
            if (
this.AIs.ContainsKey(entity.UID))
            {
                
this.AIs.Remove(entity.UID);
                
this.Floor[entity.Xentity.YMapObjectType.Entityentity] = true;
            }
        }
        public 
void RemoveEntity(Entity entity)
        {
            if (
Entities.ContainsKey(entity.UID) == true)
            {
                
Entities.Remove(entity.UID);
                
Floor[entity.Xentity.YMapObjectType.Monsterentity] = true;
            }
            
//if (Companions.ContainsKey(entity.UID) == true)
            //{
            //    Companions.Remove(entity.UID);
            //    Floor[entity.X, entity.Y, MapObjectType.Monster, entity] = true;
            //}
        
}
        public 
void AddFloorItem(Network.GamePackets.FloorItem floorItem)
        {
            
FloorItems.Add(floorItem.UIDfloorItem);
            
Floor[floorItem.XfloorItem.YMapObjectType.ItemfloorItem] = false;
        }
        public 
void RemoveFloorItem(Network.GamePackets.FloorItem floorItem)
        {
            
FloorItems.Remove(floorItem.UID);
            
Floor[floorItem.XfloorItem.YMapObjectType.ItemfloorItem] = true;
        }

        public 
bool SelectCoordonates(ref ushort Xref ushort Y)
        {
            if (
Floor[XYMapObjectType.Itemnull])
            {
                
bool can true;
                if (
Zones.Count != 0)
                {
                    foreach (
Zoning.Zone z in Zones)
                    {
                        if (
z.IsPartOfRectangle(new Point() { X}))
                        {
                            
can false;
                            break;
                        }
                    }
                }
                if (
can)
                    return 
true;
            }

            foreach (
Enums.ConquerAngle angle in Angles)
            {
                
ushort xX XyY Y;
                
UpdateCoordonatesForAngle(ref xXref yYangle);
                if (
Floor[xXyYMapObjectType.Itemnull])
                {
                    if (
Zones.Count != 0)
                    {
                        
bool can true;
                        foreach (
Zoning.Zone z in Zones)
                        {
                            if (
z.IsPartOfRectangle(new Point() { xXyY })) { can false; break; }
                        }
                        if (!
can)
                            continue;
                    }
                    
xX;
                    
yY;
                    return 
true;
                }
            }
            return 
false;
        }
        public static 
void UpdateCoordonatesForAngle(ref ushort Xref ushort YEnums.ConquerAngle angle)
        {
            
sbyte xi 0yi 0;
            switch (
angle)
            {
                case 
Enums.ConquerAngle.Northxi = -1yi = -1; break;
                case 
Enums.ConquerAngle.Southxi 1yi 1; break;
                case 
Enums.ConquerAngle.Eastxi 1yi = -1; break;
                case 
Enums.ConquerAngle.Westxi = -1yi 1; break;
                case 
Enums.ConquerAngle.NorthWestxi = -1; break;
                case 
Enums.ConquerAngle.SouthWestyi 1; break;
                case 
Enums.ConquerAngle.NorthEastyi = -1; break;
                case 
Enums.ConquerAngle.SouthEastxi 1; break;
            }
            
= (ushort)(xi);
            
= (ushort)(yi);
        }

        public static 
void Pushback(ref ushort xref ushort yEnums.ConquerAngle angleint paces)
        {
            
sbyte xi 0yi 0;
            for (
int i 0pacesi++)
            {
                switch (
angle)
                {
                    case 
Enums.ConquerAngle.Northxi = -1yi = -1; break;
                    case 
Enums.ConquerAngle.Southxi 1yi 1; break;
                    case 
Enums.ConquerAngle.Eastxi 1yi = -1; break;
                    case 
Enums.ConquerAngle.Westxi = -1yi 1; break;
                    case 
Enums.ConquerAngle.NorthWestxi = -1; break;
                    case 
Enums.ConquerAngle.SouthWestyi 1; break;
                    case 
Enums.ConquerAngle.NorthEastyi = -1; break;
                    case 
Enums.ConquerAngle.SouthEastxi 1; break;
                }
                
= (ushort)(xi);
                
= (ushort)(yi);
            }
        }
        
#region Scenes
        
private SceneFile[] Scenes;
        private static 
string NTString(string value)
        {
            
value value.Remove(value.IndexOf("\0"));
            return 
value;
        }
        private 
SceneFile CreateSceneFile(BinaryReader Reader)
        {
            
SceneFile file = new SceneFile();
            
file.SceneFileName NTString(Program.Encoding.GetString(Reader.ReadBytes(260)));
            
file.Location = new Point(Reader.ReadInt32(), Reader.ReadInt32());
            
using (BinaryReader reader = new BinaryReader(new FileStream(Constants.DataHolderPath file.SceneFileNameFileMode.Open)))
            {
                
ScenePart[] partArray = new ScenePart[reader.ReadInt32()];
                for (
int i 0partArray.Lengthi++)
                {
                    
reader.BaseStream.Seek(0x14cLSeekOrigin.Current);
                    
partArray[i].Size = new Size(reader.ReadInt32(), reader.ReadInt32());
                    
reader.BaseStream.Seek(4LSeekOrigin.Current);
                    
partArray[i].StartPosition = new Point(reader.ReadInt32(), reader.ReadInt32());
                    
reader.BaseStream.Seek(4LSeekOrigin.Current);
                    
partArray[i].NoAccess = new bool[partArray[i].Size.WidthpartArray[i].Size.Height];
                    for (
int j 0partArray[i].Size.Heightj++)
                    {
                        for (
int k 0partArray[i].Size.Widthk++)
                        {
                            
partArray[i].NoAccess[kj] = reader.ReadInt32() == 0;
                            
reader.BaseStream.Seek(8LSeekOrigin.Current);
                        }
                    }
                }
                
file.Parts partArray;
            }
            return 
file;
        }
        public 
struct SceneFile
        
{
            public 
string SceneFileName
            
{
                
get;
                
set;
            }
            public 
Point Location
            
{
                
get;
                
set;
            }
            public 
ScenePart[] Parts
            
{
                
get;
                
set;
            }
        }
        public 
struct ScenePart
        
{
            public 
string Animation;
            public 
string PartFile;
            public 
Point Offset;
            public 
int aniInterval;
            public 
System.Drawing.Size Size;
            public 
int Thickness;
            public 
Point StartPosition;
            public 
bool[,] NoAccess;
        }
        
#endregion

        
public Map(ushort idstring path)
        {
            if (!
Kernel.Maps.ContainsKey(id))
                
Kernel.Maps.Add(idthis);
            
Npcs = new Dictionary<uintINpc>();
            
Entities = new SafeDictionary<uintEntity>();
            
AIs = new SafeDictionary<uintEntity>();
            
FloorItems = new ConcurrentDictionary<uintFloorItem>();
            
Floor = new Floor(00id);
           
// Companions = new SafeDictionary<uint, Entity>();
            
ID id;
            
BaseID id;
            if (
path == ""path Database.DMaps.MapPaths[id];
            
Path path;
            
#region Loading floor.
            
if (File.Exists(Constants.DMapsPath "\\maps\\" id.ToString() + ".map"))
            {
             
//   Console.WriteLine("Loading " + ID + " DMap : maps\\" + id.ToString() + ".map");
                
byte[] buff File.ReadAllBytes(Constants.DMapsPath "\\maps\\" id.ToString() + ".map");
                
MemoryStream FS = new MemoryStream(buff);
                
BinaryReader BR = new BinaryReader(FS);
                
int Width BR.ReadInt32();
                
int Height BR.ReadInt32();
                
Floor = new Game.Floor(WidthHeightID);
                if (
id == 700)
                    
ArenaBaseFloor = new Game.Floor(WidthHeightID);
                for (
ushort y 0Height= (ushort)(1))
                {
                    for (
ushort x 0Width= (ushort)(1))
                    {
                        
bool walkable = !(BR.ReadByte() == true false);
                        
Floor[xyMapObjectType.InvalidCastnull] = walkable;
                        if (
id == 700)
                            
ArenaBaseFloor[xyMapObjectType.InvalidCastnull] = walkable;
                    }
                }

                
BR.Close();
                
FS.Close();
            }
            else
            {
                if (
File.Exists(Constants.DMapsPath Path))
                {
              
//      Console.WriteLine("Loading " + ID + " DMap : " + Path);
                    
byte[] buff File.ReadAllBytes(Constants.DMapsPath Path);
                    
MemoryStream FS = new MemoryStream(buff);
                    
BinaryReader BR = new BinaryReader(FS);
                    
BR.ReadBytes(268);
                    
int Width BR.ReadInt32();
                    
int Height BR.ReadInt32();
                    
Floor = new Game.Floor(WidthHeightID);
                    if (
id == 700)
                        
ArenaBaseFloor = new Game.Floor(WidthHeightID);
                    for (
ushort y 0Height= (ushort)(1))
                    {
                        for (
ushort x 0Width= (ushort)(1))
                        {
                            
bool walkable = !Convert.ToBoolean(BR.ReadUInt16());
                            
Floor[xyMapObjectType.InvalidCastnull] = walkable;
                            if (
id == 700)
                                
ArenaBaseFloor[xyMapObjectType.InvalidCastnull] = walkable;
                            
BR.BaseStream.Seek(4LSeekOrigin.Current);
                        }
                        
BR.BaseStream.Seek(4LSeekOrigin.Current);
                    }
                    
uint amount BR.ReadUInt32();
                    
PopulatePortals(amount);
                    for (
ushort j 0amount= (ushort)(1))
                    {
                        
DMapPortal portal = new DMapPortal
                        
{
                            
XCord = (ushort)BR.ReadUInt32(),
                            
YCord = (ushort)BR.ReadUInt32()
                        };
                        
SetPortal(jportal);
                        
BR.BaseStream.Seek(4LSeekOrigin.Current);
                    }
                    
// BR.BaseStream.Seek(amount * 12, SeekOrigin.Current);
                    
LoadMapObjects(BR);
                    
MergeSceneToTextureArea();
                    
BR.Close();
                    
FS.Close();
                    
SaveMap();
                    
SavePortals();
                }
            }
            
#endregion
            
LoadNpcs();
            
LoadZones();
            
LoadMonsters();
            
LoadPortals();

        }
        public 
Map(ushort idushort baseidstring path)
        {
            if (!
Kernel.Maps.ContainsKey(id))
                
Kernel.Maps.Add(idthis);
            else
                
Kernel.Maps[id] = this;
            
Npcs = new Dictionary<uintINpc>();
            
Entities = new SafeDictionary<uintEntity>();
        
//    Companions = new SafeDictionary<uint, Entity>();
            
FloorItems = new ConcurrentDictionary<uintFloorItem>();
            
ID id;
            
BaseID baseid;
            
Path path;
            if (
String.IsNullOrEmpty(path))
                
Path path Database.DMaps.MapPaths[baseid];
            
Floor = new Floor(00id);

            
#region Loading floor.
            
if (id != baseid && baseid == 700 && ArenaBaseFloor != null)
            {
                
Floor = new Game.Floor(ArenaBaseFloor.Bounds.WidthArenaBaseFloor.Bounds.HeightID);
                for (
ushort y 0ArenaBaseFloor.Bounds.Height= (ushort)(1))
                {
                    for (
ushort x 0ArenaBaseFloor.Bounds.Width= (ushort)(1))
                    {
                        
Floor[xyMapObjectType.InvalidCastnull] = !ArenaBaseFloor[xyMapObjectType.InvalidCastnull];
                    }
                }
            }
            else
            {
                if (
File.Exists(Constants.DMapsPath "\\maps\\" baseid.ToString() + ".map"))
                {
                   
// Console.WriteLine("Loading " + ID + " DMap : maps\\" + id.ToString() + ".map");
                    
byte[] buff File.ReadAllBytes(Constants.DMapsPath "\\maps\\" baseid.ToString() + ".map");
                    
MemoryStream FS = new MemoryStream(buff);
                    
BinaryReader BR = new BinaryReader(FS);
                    
int Width BR.ReadInt32();
                    
int Height BR.ReadInt32();

                    
Floor = new Game.Floor(WidthHeightID);

                    for (
ushort y 0Height= (ushort)(1))
                    {
                        for (
ushort x 0Width= (ushort)(1))
                        {
                            
Floor[xyMapObjectType.InvalidCastnull] = !(BR.ReadByte() == true false);
                        }
                    }
                    
BR.Close();
                    
FS.Close();
                }
                else
                {
                    if (
File.Exists(Constants.DMapsPath Path))
                    {
                   
//     Console.WriteLine("Loading "+ID+" DMap : " + Path);
                        
FileStream FS = new FileStream(Constants.DMapsPath PathFileMode.Open);
                        
BinaryReader BR = new BinaryReader(FS);
                        
BR.ReadBytes(268);
                        
int Width BR.ReadInt32();
                        
int Height BR.ReadInt32();

                        
Floor = new Game.Floor(WidthHeightID);

                        for (
ushort y 0Height= (ushort)(1))
                        {
                            for (
ushort x 0Width= (ushort)(1))
                            {
                                
Floor[xyMapObjectType.InvalidCastnull] = !Convert.ToBoolean(BR.ReadUInt16());

                                
BR.BaseStream.Seek(4LSeekOrigin.Current);
                            }
                            
BR.BaseStream.Seek(4LSeekOrigin.Current);
                        }
                        
uint amount BR.ReadUInt32();
                        
PopulatePortals(amount);
                        for (
ushort j 0amount= (ushort)(1))
                        {
                            
DMapPortal portal = new DMapPortal
                            
{
                                
XCord = (ushort)BR.ReadUInt32(),
                                
YCord = (ushort)BR.ReadUInt32()
                            };
                            
SetPortal(jportal);
                            
BR.BaseStream.Seek(4LSeekOrigin.Current);
                        }
                        
//    BR.BaseStream.Seek(amount * 12, SeekOrigin.Current);

                        
int num BR.ReadInt32();
                        List<
SceneFile> list = new List<SceneFile>();
                        for (
int i 0numi++)
                        {
                            switch (
BR.ReadInt32())
                            {
                                case 
10:
                                    
BR.BaseStream.Seek(0x48LSeekOrigin.Current);
                                    break;

                                case 
15:
                                    
BR.BaseStream.Seek(0x114LSeekOrigin.Current);
                                    break;

                                case 
1:
                                    list.
Add(this.CreateSceneFile(BR));
                                    break;

                                case 
4:
                                    
BR.BaseStream.Seek(0x1a0LSeekOrigin.Current);
                                    break;
                            }
                        }
                        
Scenes = list.ToArray();

                        for (
int i 0Scenes.Lengthi++)
                        {
                            foreach (
ScenePart part in Scenes[i].Parts)
                            {
                                for (
int j 0part.Size.Widthj++)
                                {
                                    for (
int k 0part.Size.Heightk++)
                                    {
                                        
Point point = new Point();
                                        
point.= ((Scenes[i].Location.part.StartPosition.X) + j) - part.Size.Width;
                                        
point.= ((Scenes[i].Location.part.StartPosition.Y) + k) - part.Size.Height;
                                        
Floor[(ushort)point.X, (ushort)point.YMapObjectType.InvalidCastnull] = part.NoAccess[jk];
                                    }
                                }
                            }
                        }

                        
BR.Close();
                        
FS.Close();
                        
SaveMap();
                        
SavePortals();
                    }
                }
            }
            
#endregion
            
LoadNpcs();
            
LoadZones();
            
LoadMonsters();
            
LoadPortals();


        }

        private 
void MergeSceneToTextureArea()
        {
            for (
int i 0Scenes.Lengthi++)
            {
                if (
Scenes[i].Parts == null) return;
                foreach (
ScenePart part in Scenes[i].Parts)
                {
                    for (
int j 0part.Size.Widthj++)
                    {
                        for (
int k 0part.Size.Heightk++)
                        {
                            
Point point = new Point
                            
{
                                
= ((Scenes[i].Location.part.StartPosition.X) - j),
                                
= ((Scenes[i].Location.part.StartPosition.Y) - k)
                            };
                            
Floor[(ushort)point.X, (ushort)point.YMapObjectType.InvalidCast] = part.NoAccess[jk];
                        }
                    }
                }
            }
        }
        private 
void LoadMapObjects(BinaryReader Reader)
        {
            
int num Reader.ReadInt32();
            List<
SceneFile> list = new List<SceneFile>();
            for (
int i 0numi++)
            {
                
int id Reader.ReadInt32();
                
id = (byte)id;
                switch (
id)
                {
                    case 
10:
                        
Reader.BaseStream.Seek(0x48LSeekOrigin.Current);
                        break;

                    case 
15:
                        
Reader.BaseStream.Seek(0x114LSeekOrigin.Current);
                        break;

                    case 
1:
                        list.
Add(this.CreateSceneFile(Reader));
                        break;

                    case 
4:
                        
Reader.BaseStream.Seek(0x1a0LSeekOrigin.Current);
                        break;
                }
            }
            
Scenes = list.ToArray();
        }
        private 
void LoadPortals()
        {
            
IniFile file = new KhaledMohamed.IniFile(Constants.PortalsPath);
            
ushort portalCount file.ReadUInt16(BaseID.ToString(), "Count");

            for (
int i 0portalCounti++)
            {
                
string _PortalEnter file.ReadString(BaseID.ToString(), "PortalEnter" i.ToString());
                
string _PortalExit file.ReadString(BaseID.ToString(), "PortalExit" i.ToString());
                
string[] PortalEnter _PortalEnter.Split(' ');
                
string[] PortalExit _PortalExit.Split(' ');
                
Game.Portal portal = new KhaledMohamed.Game.Portal();
                
portal.CurrentMapID Convert.ToUInt16(PortalEnter[0]);
                
portal.CurrentX Convert.ToUInt16(PortalEnter[1]);
                
portal.CurrentY Convert.ToUInt16(PortalEnter[2]);

                if (
PortalExit.Length == 3)
                {
                    
portal.DestinationMapID Convert.ToUInt16(PortalExit[0]);
                    
portal.DestinationX Convert.ToUInt16(PortalExit[1]);
                    
portal.DestinationY Convert.ToUInt16(PortalExit[2]);
                }
                
Portals.Add(portal);
            }
        }
        public List<
Game.PortalPortals = new List<Game.Portal>();
        private 
IDisposable Timer;

        public static 
sbyte[] XDir = new sbyte[] 
        { 
            -
1, -2, -2, -11221,
             
0, -2, -2, -20222
            -
1, -2, -2, -11221,
             
0, -1, -1, -10111,
        };
        public static 
sbyte[] YDir = new sbyte[] 
        {
            
2,  1, -1, -2, -2, -112,
            
2,  2,  0, -2, -2, -202
            
2,  1, -1, -2, -2, -112
            
1,  1,  0, -1, -1, -101
        
};
        public 
SafeConcurrentDictionary<uintStaticEntityStaticEntities = new SafeConcurrentDictionary<uintStaticEntity>();
        public 
void AddStaticEntity(StaticEntity item)
        {
            
Floor[item.Xitem.YMapObjectType.StaticEntitynull] = false;
            
StaticEntities[item.UID] = item;
        }
        public 
void RemoveStaticItem(StaticEntity item)
        {
            
Floor[item.Xitem.YMapObjectType.StaticEntitynull] = true;
            
StaticEntities.Remove(item.UID);
        }
        private 
void SaveMap()
        {
            if (!
File.Exists(Constants.DMapsPath "\\maps\\" BaseID.ToString() + ".map"))
            {
                
FileStream stream = new FileStream(Constants.DMapsPath "\\maps\\" BaseID.ToString() + ".map"FileMode.Create);
                
BinaryWriter writer = new BinaryWriter(stream);
                
writer.Write((uint)Floor.Bounds.Width);
                
writer.Write((uint)Floor.Bounds.Height);
                for (
int y 0Floor.Bounds.Heighty++)
                {
                    for (
int x 0Floor.Bounds.Widthx++)
                    {
                        
writer.Write((byte)(Floor[xyMapObjectType.InvalidCastnull] == true 0));
                    }
                }
                
writer.Close();
                
stream.Close();
            }
        }
        private 
void SavePortals()
        {
            if (!
File.Exists("portals.txt"))
            {
                
File.Create("portals.txt");
            }
            
string ConfigFileName "portals.txt";
            
IniFile IniFile = new IniFile(ConfigFileName);
            var 
id ID.ToString();
            for (
int i 0portals.Lengthi++)
            {
                
IniFile.Write(id"Count"portals.Length.ToString());
                
IniFile.Write(idi.ToString(), string.Format("{0} {1} {2}"idportals[i].XCord.ToString(), portals[i].YCord.ToString()));
            }

        }
        private 
void LoadZones()
        {
            
using (var command = new Database.MySqlCommand(Database.MySqlCommandType.SELECT))
            {
                
command.Select("notavailablepaths").Where("mapid"ID);

                
using (var reader = new Database.MySqlReader(command))
                {
                    while (
reader.Read())
                    {
                        
Zoning.Zone zone = new Zoning.Zone(
                            new 
Point() { reader.ReadInt32("Point1_X"), reader.ReadInt32("Point1_Y") },
                            new 
Point() { reader.ReadInt32("Point2_X"), reader.ReadInt32("Point2_Y") },
                            new 
Point() { reader.ReadInt32("Point3_X"), reader.ReadInt32("Point3_Y") },
                            new 
Point() { reader.ReadInt32("Point4_X"), reader.ReadInt32("Point4_Y") }
                            );
                        
Zones.Add(zone);
                    }
                }
            }
        }
        private 
void LoadNpcs()
        {
            
using (var command = new Database.MySqlCommand(Database.MySqlCommandType.SELECT))
            {
                
command.Select("npcs").Where("mapid"ID);
                
using (var reader = new Database.MySqlReader(command))
                {
                    while (
reader.Read())
                    {
                        
INpc npc = new Network.GamePackets.NpcSpawn();
                        
npc.UID reader.ReadUInt32("id");
                        
npc.Name reader.ReadString("name");
                        
npc.Mesh reader.ReadUInt16("lookface");
                        
npc.Type = (Enums.NpcType)reader.ReadByte("type");
                        
npc.reader.ReadUInt16("cellx");
                        
npc.reader.ReadUInt16("celly");
                        
npc.effect reader.ReadString("effect");
                        
npc.MapID ID;
                       
                        
AddNpc(npc);
                    }
                }
            }
            
using (var command = new Database.MySqlCommand(Database.MySqlCommandType.SELECT))
            {
                
command.Select("sobnpcs").Where("mapid"ID);
                
using (var reader = new Database.MySqlReader(command))
                {
                    while (
reader.Read())
                    {
                        
Network.GamePackets.SobNpcSpawn npc = new Network.GamePackets.SobNpcSpawn();
                        
npc.UID reader.ReadUInt32("id");
                        
npc.Mesh reader.ReadUInt16("lookface");
                        if (
ID == 1039)
                            
npc.Mesh = (ushort)(npc.Mesh npc.Mesh 10 7);
                        
npc.Type = (Enums.NpcType)reader.ReadByte("type");
                        
npc.reader.ReadUInt16("cellx"); ;
                        
npc.reader.ReadUInt16("celly");
                        
npc.MapID reader.ReadUInt16("mapid");
                        
npc.Sort reader.ReadUInt16("sort");
                        
npc.ShowName true;
                        
npc.Name reader.ReadString("name");
                        
npc.Hitpoints reader.ReadUInt32("life");
                        
npc.MaxHitpoints reader.ReadUInt32("maxlife");
                        
npc._isprize reader.ReadBoolean("prize");
                        if (
npc.UID >= 9994 && npc.UID <= 9997)
                        {
                            
Database.GuildCondutors.GuildConductors.Add(npc.UID, new Database.GuildCondutors.Conductor() { npc npc });
                            
Database.GuildCondutors.MoveNpc(npc.UIDnpc.MapIDnpc.Xnpc.Y);
                            
AddNpc(npctrue);
                        }
                        else
                            
AddNpc(npc);
                    }
                }
            }
            
uint nextid 100000;
            
using (var command = new Database.MySqlCommand(Database.MySqlCommandType.SELECT))
            {
                
command.Select("statues").Where("mapid"ID);
                
using (var reader = new Database.MySqlReader(command))
                {
                    while (
reader.Read())
                    {
                        
Network.GamePackets.SobNpcSpawn npc = new Network.GamePackets.SobNpcSpawn();
                        
npc.UID reader.ReadUInt32("id");
                        if (
npc.UID nextid)
                            
nextid npc.UID;
                        
npc.Mesh reader.ReadUInt16("lookface");
                        
npc.Type = (Enums.NpcType)reader.ReadByte("type");
                        
npc.reader.ReadUInt16("cellx"); ;
                        
npc.reader.ReadUInt16("celly");
                        
npc.MapID reader.ReadUInt16("mapid");
                        
npc.ShowName true;
                        
npc.Name reader.ReadString("name");
                        
npc.Hitpoints reader.ReadUInt32("life");
                        
npc.MaxHitpoints reader.ReadUInt32("maxlife");
                        
npc.SpawnPacket reader.ReadBlob("SpawnPacket");
                        
AddNpc(npc);
                    }
                }
            }
            
EntityUIDCounter2 = new Counter(nextid);
        }
        public 
bool FreezeMonsters false;
        public 
void LoadMonsters()
        {
            
//Companions = new SafeDictionary<uint, Entity>();
            
using (var command = new Database.MySqlCommand(Database.MySqlCommandType.SELECT))
            {
                
command.Select("monsterspawns").Where("mapid"ID);
                
using (var reader = new Database.MySqlReader(command))
                {
                    
int mycount 0;
                    try
                    {
                        while (
reader.Read())
                        {
                            
uint monsterID reader.ReadUInt32("npctype");
                            
ushort CircleDiameter reader.ReadUInt16("maxnpc");
                            
ushort X reader.ReadUInt16("bound_x");
                            
ushort Y reader.ReadUInt16("bound_y");
                            
ushort XPlus reader.ReadUInt16("bound_cx");
                            
ushort YPlus reader.ReadUInt16("bound_cy");
                            
ushort Amount reader.ReadUInt16("max_per_gen");
                            
int respawn reader.ReadInt32("rest_secs");
                            if (
Database.MonsterInformation.MonsterInformations.ContainsKey(monsterID))
                            {
                                
Database.MonsterInformation mt Database.MonsterInformation.MonsterInformations[monsterID];
                                
mt.RespawnTime respawn 5;
                                
mt.BoundX X;
                                
mt.BoundY Y;
                                
mt.BoundCX XPlus;
                                
mt.BoundCY YPlus;

                                
bool more true;
                                for (
int count 0count Amountcount++)
                                {
                                    if (!
more)
                                        break;
                                    
Entity entity = new Entity(EntityFlag.Monsterfalse);
                                    
entity.MapObjType MapObjectType.Monster;
                                    
entity.MonsterInfo mt.Copy();
                                    
entity.MonsterInfo.Owner entity;
                                    
entity.Name mt.Name;
                                    
entity.MinAttack mt.MinAttack;
                                    
entity.MaxAttack entity.MagicAttack mt.MaxAttack;   
                                    
entity.Hitpoints entity.MaxHitpoints mt.Hitpoints;
                                    
entity.Defence mt.Defence;
                                    
entity.Body mt.Mesh;
                                    
entity.Level mt.Level;
                                    
entity.UID EntityUIDCounter.Next;
                                    
entity.MapID ID;
                                    
entity.SendUpdates true;
                                    
#region Guards

                                    
if (mt.Name == "Guard1" || mt.Name == "Guard2")
                                    {
                                        
Network.Writer.Write((byte)255271entity.SpawnPacket);//UNKNOWN
                                        
Network.Writer.Write((byte)16272entity.SpawnPacket);//UNKNOWN
                                        
Network.Writer.Write((byte)Kernel.Random.Next(17), Entity._Facingentity.SpawnPacket);//RANDOM~FACING
                                    
}

                                    
#endregion Guards
                                    
entity.= (ushort)(Kernel.Random.Next(0XPlus));
                                    
entity.= (ushort)(Kernel.Random.Next(0YPlus));
                                    for (
int count2 0count2 50count2++)
                                    {
                                        if (!
Floor[entity.Xentity.YMapObjectType.Monsternull])
                                        {
                                            
entity.= (ushort)(Kernel.Random.Next(0XPlus));
                                            
entity.= (ushort)(Kernel.Random.Next(0YPlus));
                                            if (
count2 == 50)
                                                
more false;
                                        }
                                        else
                                            break;
                                    }
                                    if (
more)
                                    {
                                        if (
Floor[entity.Xentity.YMapObjectType.Monsternull])
                                        {
                                            
mycount++;
                                            
AddEntity(entity);
                                        }
                                    }
                                }
                            }
                        }
                        
                    }
                    catch (
Exception e) { Program.SaveException(e); }
                    if (
mycount != 0)
                        
Timer MonsterTimers.Add(this);
                }
            }
        }

        public 
Tuple<ushortushortRandomCoordinates()
        {
            
int times 10000;
            
int x Kernel.Random.Next(Floor.Bounds.Width), Kernel.Random.Next(Floor.Bounds.Height);
            while (
times-- > 0)
            {
                if (!
Floor[xyMapObjectType.Entitynull])
                {
                    
Kernel.Random.Next(Floor.Bounds.Width);
                    
Kernel.Random.Next(Floor.Bounds.Height);
                }
                else break;
            }
            return new 
Tuple<ushortushort>((ushort)x, (ushort)y);
        }
        public 
Tuple<ushortushortRandomCoordinates(int _xint _yint radius)
        {
            
int times 10000;
            
int x _x Kernel.Random.Sign() * Kernel.Random.Next(radius),
                
_y Kernel.Random.Sign() * Kernel.Random.Next(radius);
            while (
times-- > 0)
            {
                if (!
Floor[xyMapObjectType.Entitynull])
                {
                    
_x Kernel.Random.Sign() * Kernel.Random.Next(radius);
                    
_y Kernel.Random.Sign() * Kernel.Random.Next(radius);
                }
                else break;
            }
            return new 
Tuple<ushortushort>((ushort)x, (ushort)y);
        }

        private static 
TimerRule<MapMonsterTimers;
        public static 
void CreateTimerFactories()
        {
            
MonsterTimers = new TimerRule<Map>(_timerCallBack500);
        }

        public 
Time32 LastReload Time32.Now;
        private static 
void _timerCallBack(Map mapint time)
        {
            
//foreach (Entity monster in map.Companions.Values)
            //{
            //    if (!monster.Owner.Socket.Alive)
            //    {
            //        map.RemoveEntity(monster);
            //        break;
            //    }
            //}
            
Time32 now = new Time32(time);
            foreach (
Entity monster in map.Entities.Values.ToList())
            {
                if (
monster == null || monster.Name == "Thundercloud") continue;

                if (
monster.Dead)
                {
                    if (
now monster.DeathStamp.AddSeconds(monster.MonsterInfo.RespawnTime))
                    {
                        
monster.= (ushort)(monster.MonsterInfo.BoundX Kernel.Random.Next(0monster.MonsterInfo.BoundCX));
                        
monster.= (ushort)(monster.MonsterInfo.BoundY Kernel.Random.Next(0monster.MonsterInfo.BoundCY));
                        for (
int count 0count monster.MonsterInfo.BoundCX monster.MonsterInfo.BoundCYcount++)
                        {
                            if (!
map.Floor[monster.Xmonster.YMapObjectType.Monsternull])
                            {
                                
monster.= (ushort)(monster.MonsterInfo.BoundX Kernel.Random.Next(0monster.MonsterInfo.BoundCX));
                                
monster.= (ushort)(monster.MonsterInfo.BoundY Kernel.Random.Next(0monster.MonsterInfo.BoundCY));
                            }
                            else
                                break;
                        }
                        if (
map.Floor[monster.Xmonster.YMapObjectType.Monster] || monster.== monster.MonsterInfo.BoundX && monster.== monster.MonsterInfo.BoundY)
                        {
                            
monster.Hitpoints monster.MonsterInfo.Hitpoints;
                            
monster.RemoveFlag(monster.StatusFlag);
                            var 
stringPacket = new _String(true);
                            
stringPacket.UID monster.UID;
                            
stringPacket.Type _String.Effect;
                            
stringPacket.Texts.Add("MBStandard");
                            
monster.StatusFlag 0;
                            
//if (monster.MonsterInfo.Type == 2)
                            //{
                            //    var value = Update.Flags.BlackName;
                            //    Network.Writer.WriteUInt64(value, 0x16 + 4, monster.SpawnPacket);

                            //}
                            //if (monster.MonsterInfo.Name == "Guard1")
                            //{
                            //    monster.Action = (ushort)Kernel.Random.Next(1, 15);
                            //}
                            
if (monster.Name == "WhiteTiger1" )   اسماء الوحوش الكان فيها مشكله كان هنا ومسحتو بس المشكله متحلتش بردو
                            
{
                                foreach (
Client.GameState client in Program.Values)
                                {
                                    
client.MessageBox(monster.Name " has apeared , Who will Defeat it to Get [5.000.000] ConquerPoints & [2.000] BoundCps ", (p) => { p.Entity.Teleport(monster.MapID, (ushort)(monster.3), (ushort)(monster.3), false); }, null);
                                }
                                
KhaledMohamed.Kernel.SendWorldMessage(new KhaledMohamed.Network.GamePackets.Message(" Warrning " monster.Name " has Apeared in [" monster.MapID.ToString() + "] at " monster.", " monster." Who will Defeat it and get [5.000.000] ConquerPoints & [2.000] BoundCps "System.Drawing.Color.WhiteKhaledMohamed.Network.GamePackets.Message.Center), Program.Values);
                            }
                            foreach (
Client.GameState client in Program.Values)
                            {
                                if (
client.Map.ID == map.ID)
                                {
                                    if (
Kernel.GetDistance(client.Entity.Xclient.Entity.Ymonster.Xmonster.Y) < Constants.nScreenDistance)
                                    {
                                        
monster.CauseOfDeathIsMagic false;
                                        
monster.SendSpawn(clientfalse);
                                        
client.Send(stringPacket);
                                        if (
monster.MaxHitpoints 65535)
                                        {
                                            
Update upd = new Update(true) { UID monster.UID };
                                            
// upd.Append(Update.MaxHitpoints, monster.MaxHitpoints);
                                            
upd.Append(Update.Hitpointsmonster.Hitpoints);
                                            
client.Send(upd);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (
monster.ToxicFogLeft 0)
                    {
                        if (
monster.MonsterInfo.Boss)
                        {
                            
monster.ToxicFogLeft 0;
                            continue;
                        }
                        if (
now monster.ToxicFogStamp.AddSeconds(2))
                        {
                            
monster.ToxicFogLeft--;
                            
monster.ToxicFogStamp now;
                            if (
monster.Hitpoints 1)
                            {
                                
uint damage Attacking.Calculate.Percent(monstermonster.ToxicFogPercent);
                                
monster.Hitpoints -= damage;
                                var 
suse = new SpellUse(true);
                                
suse.Attacker monster.UID;
                                
suse.SpellID 10010;
                                
suse.AddTarget(monsterdamagenull);
                                
monster.MonsterInfo.SendScreen(suse);
                            }
                        }
                    }
                }
            }
        }
        public 
void SpawnMonsterNearToHero(MonsterInformation mtGameState client)
        {
            if (
mt == null) return;
            
mt.RespawnTime 36000;
            
KhaledMohamed.Game.Entity entity = new KhaledMohamed.Game.Entity(EntityFlag.Monsterfalse);
            
entity.MapObjType MapObjectType.Monster;
            
entity.MonsterInfo mt.Copy();
            
entity.MonsterInfo.Owner entity;
            
entity.Name mt.Name;
            
entity.MinAttack mt.MinAttack;
            
entity.MaxAttack entity.MagicAttack mt.MaxAttack;
            
entity.Hitpoints entity.MaxHitpoints mt.Hitpoints;
            
entity.Body mt.Mesh;
            
entity.Level mt.Level;
            
entity.UID EntityUIDCounter.Next;
            
entity.MapID ID;
            
entity.SendUpdates true;
            
entity.= (ushort)(client.Entity.Kernel.Random.Next(5));
            
entity.= (ushort)(client.Entity.Kernel.Random.Next(5));
            
AddEntity(entity);
            
entity.SendSpawn(client);
        }
        public 
void Spawnthis(MonsterInformation mtushort xushort y)
        {
            if (
mt == null) return;
            
mt.RespawnTime 5;
            var 
entity = new Entity(EntityFlag.Monsterfalse);
            
entity.MapObjType MapObjectType.Monster;
            
entity.MonsterInfo mt.Copy();
            
entity.MonsterInfo.Owner entity;
            
entity.Name mt.Name;
            
entity.MinAttack mt.MinAttack;
            
entity.MaxAttack entity.MagicAttack mt.MaxAttack;
            
entity.Hitpoints entity.MaxHitpoints mt.Hitpoints;
            
entity.Body mt.Mesh;
            
entity.Level mt.Level;
            
entity.UID EntityUIDCounter.Next;
            
entity.MapID this.ID;
            
entity.x;
            
entity.y;
            
entity.SendUpdates true;
            
AddEntity(entity);
            foreach (var 
p in Program.GamePool.Where(=> z.Map.ID == this.ID && z.GetDistance(entity) <= Constants.pScreenDistance))
                
entity.SendSpawn(p);
        }
        public 
void Spawnthis(MonsterInformation mtGameState clientushort IDushort xushort y)
        {
            if (
mt == null)
            {
                return;
            }
            
mt.RespawnTime 36000;
            
Entity entity = new Entity(EntityFlag.Monsterfalse);
            
entity.MapObjType MapObjectType.Monster;
            
entity.MonsterInfo mt.Copy();
            
entity.MonsterInfo.Owner entity;
            
entity.Name mt.Name;
            
entity.MinAttack mt.MinAttack;
            
entity.MaxAttack = (entity.MagicAttack mt.MaxAttack);
            
entity.Hitpoints = (entity.MaxHitpoints mt.Hitpoints);
            
entity.Body mt.Mesh;
            
entity.Level mt.Level;
            
entity.UID this.EntityUIDCounter.Next;
            
entity.MapID ID;
            
entity.x;
            
entity.y;
            
entity.SendUpdates true;
            
this.AddEntity(entity);
            
entity.SendSpawn(client);
        }
        public 
Map MakeDynamicMap()
        {
            
ushort id = (ushort)DynamicIDs.Next;
            
Map myDynamic = new Map(idthis.IDthis.Path);
            return 
myDynamic;
        }
        
bool disposed false;
        public 
void Dispose()
        {
            if (!
disposed)
                
Kernel.Maps.Remove(ID);

            
disposed true;
        }

        public 
void RemoveNpc(INpc npcbool query false)
        {
            if (
Npcs.ContainsKey(npc.UID) || query)
            {
                if (!
query)
                    
Npcs.Remove(npc.UID);
                
#region Setting the near coords invalid to avoid unpickable items.
                
Floor[npc.Xnpc.YMapObjectType.InvalidCast] = true;
                if (
npc.Mesh 10 != 108 && (byte)npc.Type 10)
                {
                    
ushort x npc.Xnpc.Y;
                    foreach (
Enums.ConquerAngle angle in Angles)
                    {
                        
ushort xX xyY Y;
                        
UpdateCoordonatesForAngle(ref xXref yYangle);
                        
Floor[xXyYMapObjectType.InvalidCast] = true;
                    }
                }
                
#endregion
            
}
        }
        public 
void Spawnthiskingdom(Database.MonsterInformation mtushort xushort y)
        {
            if (
mt == null) return;
            
mt.RespawnTime 5;
            var 
entity = new Entity(EntityFlag.Monsterfalse);
            
entity.MapObjType MapObjectType.Monster;
            
entity.MonsterInfo mt.Copy();
            
entity.MonsterInfo.Owner entity;
            
entity.Name mt.Name;
            
entity.MinAttack mt.MinAttack;
            
entity.MaxAttack entity.MagicAttack mt.MaxAttack;
            
entity.Hitpoints entity.MaxHitpoints mt.Hitpoints;
            
entity.Body mt.Mesh;
            
entity.Level mt.Level;
            
entity.UID EntityUIDCounter.Next;
            
entity.MapID this.ID;
            
entity.x;
            
entity.y;
            
entity.SendUpdates true;
            
AddEntity(entity);
            foreach (var 
z in Program.GamePool)
                if (
z.Map.ID == this.ID && z.GetDistance(entity) <= Constants.pScreenDistance)
                    
entity.SendSpawn(z);
        }
    }
    public class 
Floor
    
{
        [
Flags]
        public 
enum DMapPointFlag byte
        
{
            
Invalid 1,
            
Monster 2,
            
Npc,
            
Item 4,
            
RaceItem 8
        
}
        public class 
Size
        
{
            public 
int WidthHeight;
            public 
Size(int widthint height)
            {
                
Width width;
                
Height height;
            }
            public 
Size()
            {
                
Width 0;
                
Height 0;
            }
        }
        public 
Size Bounds;
        public 
DMapPointFlag[,] Locations;
        public 
uint FloorMapId;
        public 
Floor(int widthint heightuint mapId)
        {
            
FloorMapId mapId;
            
Bounds = new Size(widthheight);
            
Locations = new DMapPointFlag[widthheight];
        }
        
        public 
ushort ID;
        public 
Counter EntityUIDCounter = new Counter(400000);
        
        private 
void AddEntity(Entity entity)
        {
            throw new 
NotImplementedException();
        }
        public 
bool this[int xint yMapObjectType typeobject obj null]
        {
            
get
            
{
                if (
>= Bounds.Height || >= Bounds.Width || || 0)
                    return 
false;

                
DMapPointFlag filltype Locations[xy];

                if (
type == MapObjectType.InvalidCast)
                    return (
filltype DMapPointFlag.Invalid) == DMapPointFlag.Invalid;
                if ((
filltype DMapPointFlag.Invalid) == DMapPointFlag.Invalid)
                    return 
false;
                if (
type == MapObjectType.Entity)
                    return 
true;
                else
                {
                    if (
type == MapObjectType.Npc)
                        return (
filltype DMapPointFlag.Npc) != DMapPointFlag.Npc;
                    if (
type == MapObjectType.Monster)
                        return (
filltype DMapPointFlag.Monster) != DMapPointFlag.Monster;
                    if (
type == MapObjectType.Item)
                        return (
filltype DMapPointFlag.Item) != DMapPointFlag.Item;
                    if (
type == MapObjectType.StaticEntity)
                        return (
filltype DMapPointFlag.RaceItem) != DMapPointFlag.RaceItem;
                }
                return 
false;
            }
            
set
            
{
                if (
>= Bounds.Height || >= Bounds.Width || || 0)
                    return;
                
DMapPointFlag filltype Locations[xy];

                if (
value)
                {
                    if (
type == MapObjectType.InvalidCast)
                        
TakeFlag(xyDMapPointFlag.Invalid);
                    if (
type == MapObjectType.Item)
                        
TakeFlag(xyDMapPointFlag.Item);
                    if (
type == MapObjectType.Npc)
                        
TakeFlag(xyDMapPointFlag.Npc);
                    if (
type == MapObjectType.Monster)
                        
TakeFlag(xyDMapPointFlag.Monster);
                    if (
type == MapObjectType.StaticEntity)
                        
TakeFlag(xyDMapPointFlag.RaceItem);
                }
                else
                {
                    if (
type == MapObjectType.InvalidCast)
                        
AddFlag(xyDMapPointFlag.Invalid);
                    if (
type == MapObjectType.Npc)
                        
TakeFlag(xyDMapPointFlag.Npc);
                    if (
type == MapObjectType.Item)
                        
AddFlag(xyDMapPointFlag.Item);
                    if (
type == MapObjectType.Monster)
                        
AddFlag(xyDMapPointFlag.Monster);
                    if (
type == MapObjectType.StaticEntity)
                        
AddFlag(xyDMapPointFlag.RaceItem);
                }
            }
        }
        public 
DMapPointFlag AddFlag(int xint yDMapPointFlag extraFlag)
        {
            
Locations[xy] |= extraFlag;
            return 
Locations[xy];
        }
        public 
DMapPointFlag TakeFlag(int xint yDMapPointFlag extraFlag)
        {
            
Locations[xy] &= ~extraFlag;
            return 
Locations[xy];
        }
    }
    public 
enum MapObjectType
    
{
        
SobNpcNpcItemMonsterEntityNothingInvalidCastFloorSpellStaticEntity
    
}
    public class 
Portal
    
{
        public 
Portal(ushort currentMapIdushort currentXushort currentYushort destinationMapIdushort destinationXushort destinationY)
        {
            
CurrentMapID currentMapId;
            
CurrentX currentX;
            
CurrentY currentY;
            
DestinationMapID destinationMapId;
            
DestinationX destinationX;
            
DestinationY destinationY;
        }
        public 
Portal()
        {

        }
        public 
ushort CurrentMapID
        
{
            
get;
            
set;
        }
        public 
ushort CurrentX
        
{
            
get;
            
set;
        }
        public 
ushort CurrentY
        
{
            
get;
            
set;
        }
        public 
ushort DestinationMapID
        
{
            
get;
            
set;
        }
        public 
ushort DestinationX
        
{
            
get;
            
set;
        }
        public 
ushort DestinationY
        
{
            
get;
            
set;
        }
    }