Exemplo n.º 1
0
        public static IMap RetrieveMap(string mapID, bool autoActivate)
        {
            if (mapID.StartsWith("s"))
            {
                IMap map;

                bool mapLoaded = false;
                rwLock.EnterUpgradeableReadLock();
                try {
                    map = MapManager.UnsafeRetrieveActiveMap(mapID);
                    if (map == null)
                    {
                        using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Data)) {
                            map = MapManager.LoadStandardMap(dbConnection, mapID);
                        }
                        mapLoaded = true;
                        if (autoActivate)
                        {
                            rwLock.EnterWriteLock();
                            try {
                                MapManager.UnsafeAddActiveMap(map);
                            } finally {
                                rwLock.ExitWriteLock();
                            }
                        }
                    }
                } finally {
                    rwLock.ExitUpgradeableReadLock();
                }

                if (mapLoaded && autoActivate)
                {
                    // Spawn everything!
                    map.SpawnNpcs();
                    map.SpawnItems();
                }

                return(map);
            }
            else if (mapID.StartsWith("i"))
            {
                // Check if the requested map is already active and loaded
                IMap map = null;

                rwLock.EnterUpgradeableReadLock();
                try {
                    map = MapManager.UnsafeRetrieveActiveMap(mapID);
                    // Null if map is not loaded
                    if (map == null)
                    {
                        using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Data)) {
                            map = LoadInstancedMap(dbConnection, mapID);
                        }
                        bool result = map != null;
                        // Attempt to load the map
                        if (result == true)
                        {
                            if (autoActivate)
                            {
                                // Auto-activate, if needed
                                rwLock.EnterWriteLock();
                                try {
                                    MapManager.UnsafeAddActiveMap(map);
                                } finally {
                                    rwLock.ExitWriteLock();
                                }
                            }
                            Scripting.ScriptManager.InvokeSub("OnMapReloaded", map);
                        }
                        else
                        {
                            map = null;
                        }
                    }
                } finally {
                    rwLock.ExitUpgradeableReadLock();
                }

                if (map == null)
                {
                    // Uh oh! We couldn't load the map! Default to the start map
                    map = RetrieveMap(MapManager.GenerateMapID(Settings.Crossroads));
                }

                return(map);
            }
            else if (mapID.StartsWith("rd"))
            {
                // Check if the requested map is already active and loaded
                IMap map = null;

                rwLock.EnterUpgradeableReadLock();
                try {
                    map = MapManager.UnsafeRetrieveActiveMap(mapID);
                    // Null if map is not loaded
                    if (map == null)
                    {
                        using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Data)) {
                            map = LoadRDungeonMap(dbConnection, mapID);
                        }
                        bool result = map != null;
                        // Attempt to load the map
                        if (result == true)
                        {
                            if (autoActivate)
                            {
                                // Auto-activate, if needed
                                rwLock.EnterWriteLock();
                                try {
                                    MapManager.UnsafeAddActiveMap(map);
                                } finally {
                                    rwLock.ExitWriteLock();
                                }
                            }
                            Scripting.ScriptManager.InvokeSub("OnMapReloaded", map);
                        }
                        else
                        {
                            map = null;
                        }
                    }
                } finally {
                    rwLock.ExitUpgradeableReadLock();
                }

                if (map == null)
                {
                    // Uh oh! We couldn't load the map! Default to the start map
                    map = RetrieveMap(MapManager.GenerateMapID(Settings.Crossroads));
                }

                return(map);
            }
            else if (mapID.StartsWith("h"))
            {
                // Check if the requested map is already active and loaded
                IMap map       = null;
                bool mapLoaded = false;

                rwLock.EnterUpgradeableReadLock();
                try {
                    map = MapManager.UnsafeRetrieveActiveMap(mapID);
                    // Null if map is not loaded
                    if (map == null)
                    {
                        using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Data)) {
                            map = LoadHouseMap(dbConnection, mapID);
                        }
                        bool result = map != null;
                        mapLoaded = true;
                        // Attempt to load the map
                        if (result == true)
                        {
                            if (autoActivate)
                            {
                                // Auto-activate, if needed
                                rwLock.EnterWriteLock();
                                try {
                                    MapManager.UnsafeAddActiveMap(map);
                                } finally {
                                    rwLock.ExitWriteLock();
                                }
                            }
                        }
                        else
                        {
                            map = null;
                        }
                    }
                } finally {
                    rwLock.ExitUpgradeableReadLock();
                }

                //if (map == null) {
                //    // Uh oh! We couldn't load the map! Default to the start map
                //    map = RetrieveMap(MapManager.GenerateMapID(Settings.Crossroads));
                //}

                return(map);
            }
            else if (mapID.StartsWith("void"))
            {
                IMap map       = null;
                bool mapLoaded = false;

                rwLock.EnterUpgradeableReadLock();
                try {
                    map = MapManager.UnsafeRetrieveActiveMap(mapID);
                    if (map == null)
                    {
                        string         charID = mapID.Replace("void-", "");
                        Network.Client client = Network.ClientManager.FindClientFromCharID(charID);
                        if (client != null)
                        {
                            map       = new Void(client.Player);
                            mapLoaded = true;
                            if (autoActivate)
                            {
                                rwLock.EnterWriteLock();
                                try {
                                    MapManager.UnsafeAddActiveMap(map);
                                } finally {
                                    rwLock.ExitWriteLock();
                                }
                            }
                        }
                        else
                        {
                            return(null);
                        }
                    }
                } finally {
                    rwLock.ExitUpgradeableReadLock();
                }

                if (map != null && mapLoaded && autoActivate)
                {
                    // Spawn everything!
                    map.SpawnNpcs();
                    map.SpawnItems();
                }

                return(map);
            }
            else
            {
                return(RetrieveMap(MapManager.GenerateMapID(Settings.Crossroads)));
            }
        }
Exemplo n.º 2
0
        public static IMap RetrieveMap(string mapID, bool autoActivate)
        {
            if (mapID.StartsWith("s")) {
                IMap map;

                bool mapLoaded = false;
                rwLock.EnterUpgradeableReadLock();
                try {
                    map = MapManager.UnsafeRetrieveActiveMap(mapID);
                    if (map == null) {
                        using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Data)) {
                            map = MapManager.LoadStandardMap(dbConnection, mapID);
                        }
                        mapLoaded = true;
                        if (autoActivate) {
                            rwLock.EnterWriteLock();
                            try {
                                MapManager.UnsafeAddActiveMap(map);
                            } finally {
                                rwLock.ExitWriteLock();
                            }
                        }
                    }
                } finally {
                    rwLock.ExitUpgradeableReadLock();
                }

                if (mapLoaded && autoActivate) {
                    // Spawn everything!
                    map.SpawnNpcs();
                    map.SpawnItems();
                }

                return map;
            } else if (mapID.StartsWith("i")) {
                // Check if the requested map is already active and loaded
                IMap map = null;

                rwLock.EnterUpgradeableReadLock();
                try {
                    map = MapManager.UnsafeRetrieveActiveMap(mapID);
                    // Null if map is not loaded
                    if (map == null) {
                        using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Data)) {
                            map = LoadInstancedMap(dbConnection, mapID);
                        }
                        bool result = map != null;
                        // Attempt to load the map
                        if (result == true) {
                            if (autoActivate) {
                                // Auto-activate, if needed
                                rwLock.EnterWriteLock();
                                try {
                                    MapManager.UnsafeAddActiveMap(map);
                                } finally {
                                    rwLock.ExitWriteLock();
                                }
                            }
                            Scripting.ScriptManager.InvokeSub("OnMapReloaded", map);
                        } else {
                            map = null;
                        }
                    }
                } finally {
                    rwLock.ExitUpgradeableReadLock();
                }

                if (map == null) {
                    // Uh oh! We couldn't load the map! Default to the start map
                    map = RetrieveMap(MapManager.GenerateMapID(Settings.Crossroads));
                }

                return map;
            } else if (mapID.StartsWith("rd")) {
                // Check if the requested map is already active and loaded
                IMap map = null;

                rwLock.EnterUpgradeableReadLock();
                try {
                    map = MapManager.UnsafeRetrieveActiveMap(mapID);
                    // Null if map is not loaded
                    if (map == null) {
                        using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Data)) {
                            map = LoadRDungeonMap(dbConnection, mapID);

                        }
                        bool result = map != null;
                        // Attempt to load the map
                        if (result == true) {
                            if (autoActivate) {
                                // Auto-activate, if needed
                                rwLock.EnterWriteLock();
                                try {
                                    MapManager.UnsafeAddActiveMap(map);
                                } finally {
                                    rwLock.ExitWriteLock();
                                }
                            }
                            Scripting.ScriptManager.InvokeSub("OnMapReloaded", map);
                        } else {
                            map = null;
                        }
                    }
                } finally {
                    rwLock.ExitUpgradeableReadLock();
                }

                if (map == null) {
                    // Uh oh! We couldn't load the map! Default to the start map
                    map = RetrieveMap(MapManager.GenerateMapID(Settings.Crossroads));
                }

                return map;
            } else if (mapID.StartsWith("h")) {
                // Check if the requested map is already active and loaded
                IMap map = null;
                bool mapLoaded = false;

                rwLock.EnterUpgradeableReadLock();
                try {
                    map = MapManager.UnsafeRetrieveActiveMap(mapID);
                    // Null if map is not loaded
                    if (map == null) {
                        using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Data)) {
                            map = LoadHouseMap(dbConnection, mapID);
                        }
                        bool result = map != null;
                        mapLoaded = true;
                        // Attempt to load the map
                        if (result == true) {
                            if (autoActivate) {
                                // Auto-activate, if needed
                                rwLock.EnterWriteLock();
                                try {
                                    MapManager.UnsafeAddActiveMap(map);
                                } finally {
                                    rwLock.ExitWriteLock();
                                }
                            }
                        } else {
                            map = null;
                        }
                    }
                } finally {
                    rwLock.ExitUpgradeableReadLock();
                }

                //if (map == null) {
                //    // Uh oh! We couldn't load the map! Default to the start map
                //    map = RetrieveMap(MapManager.GenerateMapID(Settings.Crossroads));
                //}

                return map;
            } else if (mapID.StartsWith("void")) {
                IMap map = null;
                bool mapLoaded = false;

                rwLock.EnterUpgradeableReadLock();
                try {
                    map = MapManager.UnsafeRetrieveActiveMap(mapID);
                    if (map == null) {
                        string charID = mapID.Replace("void-", "");
                        Network.Client client = Network.ClientManager.FindClientFromCharID(charID);
                        if (client != null) {
                            map = new Void(client.Player);
                            mapLoaded = true;
                            if (autoActivate) {
                                rwLock.EnterWriteLock();
                                try {
                                    MapManager.UnsafeAddActiveMap(map);
                                } finally {
                                    rwLock.ExitWriteLock();
                                }
                            }
                        } else {
                            return null;
                        }
                    }
                } finally {
                    rwLock.ExitUpgradeableReadLock();
                }

                if (map != null && mapLoaded && autoActivate) {
                    // Spawn everything!
                    map.SpawnNpcs();
                    map.SpawnItems();
                }

                return map;
            } else {
                return RetrieveMap(MapManager.GenerateMapID(Settings.Crossroads));
            }
        }