public static void SpawnPortal(DelayedAction action)
        {
            int portalId = int.Parse(action.Record.Value1);

            PortalRecord record = PortalRecord.GetPortal(portalId);

            MapRecord targetedMap = null;

            if (action.Value != null)
            {
                ((MapRecord)action.Value).Instance.RemoveEntity(((MapRecord)action.Value).Instance.GetEntities <Portal>().FirstOrDefault(x => x.Template.Id == int.Parse(action.Record.Value1)));
            }

            if (action.Record.Value2 != string.Empty)
            {
                List <MapRecord> subAreaMaps = MapRecord.GetSubAreaMaps(int.Parse(action.Record.Value2))
                                               .ConvertAll <MapRecord>(x => MapRecord.GetMap(x))
                                               .FindAll(x => x.Instance.GetEntities <Portal>().FirstOrDefault(w => w.Template.Id == portalId) == null);

                if (subAreaMaps.Count > 0)
                {
                    targetedMap = subAreaMaps.Random();

                    targetedMap.Instance.AddEntity(new Portal(record, targetedMap.Instance));

                    action.Value = targetedMap;
                }
            }
            else
            {
                List <MapRecord> maps = MapRecord.Maps.FindAll(x => x.Instance.GetEntities <Portal>().FirstOrDefault(w => w.Template.Id == portalId) == null).FindAll(x => x.Position.Outdoor);

                if (maps.Count > 0)
                {
                    targetedMap = maps.Random();

                    targetedMap.Instance.AddEntity(new Portal(record, targetedMap.Instance));

                    action.Value = targetedMap;
                }
            }
        }
        public static void MonstersSub(DelayedAction action)
        {
            ushort[] monsterIds = Array.ConvertAll(action.Record.Value1.Split(','), x => ushort.Parse(x));

            MonsterRecord[] templates = new MonsterRecord[monsterIds.Length];

            for (int i = 0; i < monsterIds.Length; i++)
            {
                templates[i] = MonsterRecord.GetMonster(monsterIds[i]);
            }

            if (action.Value != null)
            {
                MapRecord map = (MapRecord)action.Value;
                if (MonsterSpawnManager.Instance.GroupExist(map.Instance, templates))
                {
                    MonsterSpawnManager.Instance.RemoveGroup(map.Instance, templates);
                }
            }

            MapRecord targetedMap;

            int subAreaId = int.Parse(action.Record.Value2);

            var maps = MapRecord.GetSubAreaMaps(subAreaId).ConvertAll <MapRecord>(x => MapRecord.GetMap(x)).FindAll(w => !MonsterSpawnManager.Instance.GroupExist(w.Instance, templates));

            if (maps.Count > 0)
            {
                targetedMap = maps.Random();

                MonsterSpawnManager.Instance.AddFixedMonsterGroup(targetedMap.Instance, templates, false);


                action.Value = targetedMap;
            }
        }