Exemplo n.º 1
0
        public PSOObject[] GetObjectsForZone(string zone)
        {
            if (zone == "tpmap") // Return empty object array for an tp'd map for now (We spawn in a teleporter manually)
            {
                return(new PSOObject[0]);
            }
            if (!zoneObjects.ContainsKey(zone))
            {
                Dictionary <ulong, PSOObject> objects = new Dictionary <ulong, PSOObject>();

                // Collect from db
                using (var db = new PolarisEf())
                {
                    var dbObjects = from dbo in db.GameObjects
                                    where dbo.ZoneName == zone
                                    select dbo;

                    foreach (var dbObject in dbObjects)
                    {
                        var newObject = PSOObject.FromDBObject(dbObject);
                        objects.Add(newObject.Header.ID, newObject);
                        allTheObjects.Add(newObject.Header.ID, newObject);
                        Logger.WriteInternal("[OBJ] Loaded object {0} for zone {1} from the DB.", newObject.Name, zone);
                    }
                }

                // Fallback
                if (objects.Count < 1 && Directory.Exists("Resources/objects/" + zone))
                {
                    Logger.WriteWarning("[OBJ] No objects defined for zone {0} in the database, falling back to filesystem!", zone);
                    var objectPaths = Directory.GetFiles("Resources/objects/" + zone);
                    Array.Sort(objectPaths);
                    foreach (var path in objectPaths)
                    {
                        if (Path.GetExtension(path) == ".bin")
                        {
                            var newObject = PSOObject.FromPacketBin(File.ReadAllBytes(path));
                            objects.Add(newObject.Header.ID, newObject);
                            allTheObjects.Add(newObject.Header.ID, newObject);
                            Logger.WriteInternal("[OBJ] Loaded object ID {0} with name {1} pos: ({2}, {3}, {4})", newObject.Header.ID, newObject.Name, newObject.Position.PosX,
                                                 newObject.Position.PosY, newObject.Position.PosZ);
                        }
                        else if (Path.GetExtension(path) == ".json")
                        {
                            var newObject = JsonConvert.DeserializeObject <PSOObject>(File.ReadAllText(path));
                            objects.Add(newObject.Header.ID, newObject);
                            allTheObjects.Add(newObject.Header.ID, newObject);
                            Logger.WriteInternal("[OBJ] Loaded object ID {0} with name {1} pos: ({2}, {3}, {4})", newObject.Header.ID, newObject.Name, newObject.Position.PosX,
                                                 newObject.Position.PosY, newObject.Position.PosZ);
                        }
                    }
                }

                zoneObjects.Add(zone, objects);
            }

            return(zoneObjects[zone].Values.ToArray());
        }
Exemplo n.º 2
0
        public PSOObject[] GetObjectsForZone(string zone)
        {
            if (zone == "tpmap") // Return empty object array for an tp'd map for now (We spawn in a teleporter manually)
            {
                return(new PSOObject[0]);
            }

            if (!zoneObjects.ContainsKey(zone))
            {
                Dictionary <ulong, PSOObject> objects = new Dictionary <ulong, PSOObject>();

                if (Directory.Exists("Resources/objects/" + zone))
                {
                    var objectPaths = Directory.GetFiles("Resources/objects/" + zone);

                    Array.Sort(objectPaths);

                    foreach (var path in objectPaths)
                    {
                        if (Path.GetExtension(path) == ".bin")
                        {
                            var newObject = PSOObject.FromPacketBin(File.ReadAllBytes(path));

                            objects.Add(newObject.Header.ID, newObject);
                            allObjects.Add(newObject.Header.ID, newObject);

                            Logger.WriteInternal("[OBJ] Loaded object ID {0} with name {1} pos: ({2}, {3}, {4})", newObject.Header.ID, newObject.Name, newObject.Position.PosX,
                                                 newObject.Position.PosY, newObject.Position.PosZ);
                        }
                        else if (Path.GetExtension(path) == ".json")
                        {
                            var newObject = JsonConvert.DeserializeObject <PSOObject>(File.ReadAllText(path));

                            objects.Add(newObject.Header.ID, newObject);
                            allObjects.Add(newObject.Header.ID, newObject);

                            Logger.WriteInternal("[OBJ] Loaded object ID {0} with name {1} pos: ({2}, {3}, {4})", newObject.Header.ID, newObject.Name, newObject.Position.PosX,
                                                 newObject.Position.PosY, newObject.Position.PosZ);
                        }
                    }
                }

                zoneObjects.Add(zone, objects);
            }

            return(zoneObjects[zone].Values.ToArray());
        }