Ejemplo n.º 1
0
    public void addWorld(WorldEntry world_entry, bool focus = false, bool mark_completed = false)
    {
        bool replace_stub = stubs.Count != 0;
        var  game_node    = replace_stub ? stubs.First.Value : this.game_scene.Instance() as GameButton;

        if (replace_stub)
        {
            stubs.RemoveFirst();
        }
        game_node.initialize(world_entry);
        game_node.Connect("GamePressed", GetNode <LevelSelection>("../../.."), "_on_GamePressed");
        if (!replace_stub)
        {
            addButton(game_node);
        }

        if (focus)
        {
            game_node.GrabFocus();
        }
        if (mark_completed)
        {
            game_node.markCompleted();
        }
        GamesCount++;
    }
Ejemplo n.º 2
0
        private void CalculateEntityAreaData()
        {
            log.Info("Calculating area information for entities...");

            var mapFiles = new Dictionary <ushort, MapFile>();
            var entities = new HashSet <EntityModel>();

            foreach (EntityModel model in DatabaseManager.Instance.WorldDatabase.GetEntitiesWithoutArea())
            {
                entities.Add(model);

                if (!mapFiles.TryGetValue(model.World, out MapFile mapFile))
                {
                    WorldEntry entry = GameTableManager.Instance.World.GetEntry(model.World);
                    mapFile = BaseMapManager.Instance.GetBaseMap(entry.AssetPath);
                    mapFiles.Add(model.World, mapFile);
                }

                uint worldAreaId = mapFile.GetWorldAreaId(new Vector3(model.X, model.Y, model.Z));
                model.Area = (ushort)worldAreaId;

                log.Info($"Calculated area {worldAreaId} for entity {model.Id}.");
            }

            DatabaseManager.Instance.WorldDatabase.UpdateEntities(entities);

            log.Info($"Calculated area information for {entities.Count} {(entities.Count == 1 ? "entity" : "entities")}.");
        }
Ejemplo n.º 3
0
        protected override void Write(ContentWriter output, WorldEntry <T> value)
        {
            output.WriteRawObject <MapEntry <T> >(value as MapEntry <T>,
                                                  mapEntryWriter);

            output.Write(value.MapContentName);
        }
Ejemplo n.º 4
0
    public void addEntry(float x, float y, float z, GameObject gameObject)
    {
        WorldEntry entry = new WorldEntry();

        entry.loc = new Vector3(x, y, z);
        entry.obj = gameObject;
        levelObjects.Add(entry);
    }
Ejemplo n.º 5
0
        /// <summary>
        /// Generate a base map (.nfmap) file for a single world optionally specifying a single grid.
        /// </summary>
        public static void GenerateWorld(ushort worldId, byte?gridX = null, byte?gridY = null)
        {
            WorldEntry entry = GameTableManager.World.GetEntry(worldId);

            if (entry != null)
            {
                ProcessWorld(entry, gridX, gridY);
            }
        }
Ejemplo n.º 6
0
 public void MergeLocal(WorldEntry info)
 {
     Size           = info.Size;
     Difficulties   = info.Difficulties;
     Categories     = info.Categories;
     Path           = info.Path;
     InstalledTime  = info.InstalledTime;
     LastPlayedTime = info.LastPlayedTime;
 }
Ejemplo n.º 7
0
 private WorldEntry findLocal(WorldEntry world_entry)
 {
     foreach (var entry in finished_entries)
     {
         if (entry.Name == world_entry.Name && entry.Author == world_entry.Author)
         {
             return(entry);
         }
     }
     return(null);
 }
Ejemplo n.º 8
0
        public static void HandleCharacterSelect(WorldSession session, ClientCharacterSelect characterSelect)
        {
            Character character = session.Characters.SingleOrDefault(c => c.Id == characterSelect.CharacterId);

            if (character == null)
            {
                session.EnqueueMessageEncrypted(new ServerCharacterSelectFail
                {
                    Result = CharacterSelectResult.Failed
                });
                return;
            }

            session.Player = new Player(session, character);

            WorldEntry entry = GameTableManager.World.GetEntry(character.WorldId);

            if (entry == null)
            {
                throw new ArgumentOutOfRangeException();
            }

            switch (entry.Type)
            {
            // housing map
            case 5:
            {
                // characters logging in to a housing map are returned to their own residence
                session.EnqueueEvent(new TaskGenericEvent <Residence>(ResidenceManager.GetResidence(session.Player.Name),
                                                                      residence =>
                    {
                        if (residence == null)
                        {
                            residence = ResidenceManager.CreateResidence(session.Player);
                        }

                        ResidenceEntrance entrance = ResidenceManager.GetResidenceEntrance(residence);
                        var mapInfo = new MapInfo(entrance.Entry, 0u, residence.Id);
                        MapManager.AddToMap(session.Player, mapInfo, entrance.Position);
                    }));

                break;
            }

            default:
            {
                var mapInfo = new MapInfo(entry);
                var vector3 = new Vector3(character.LocationX, character.LocationY, character.LocationZ);
                MapManager.AddToMap(session.Player, mapInfo, vector3);
                break;
            }
            }
        }
Ejemplo n.º 9
0
        private IEnumerable <uint> GetTextIds(WorldLocation2Entry entry)
        {
            WorldZoneEntry worldZone = GameTableManager.Instance.WorldZone.GetEntry(entry.WorldZoneId);

            if (worldZone != null && worldZone.LocalizedTextIdName != 0)
            {
                yield return(worldZone.LocalizedTextIdName);
            }
            WorldEntry world = GameTableManager.Instance.World.GetEntry(entry.WorldId);

            if (world != null && world.LocalizedTextIdName != 0)
            {
                yield return(world.LocalizedTextIdName);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Generate a base map (.nfmap) file from supplied <see cref="WorldEntry"/>.
        /// </summary>
        private static void ProcessWorld(WorldEntry entry, byte?gridX = null, byte?gridY = null)
        {
            var mapFile = new WritableMapFile(Path.GetFileName(entry.AssetPath));

            log.Info($"Processing {mapFile.Asset}...");

            if (gridX.HasValue && gridY.HasValue)
            {
                string            path = Path.Combine(entry.AssetPath, $"{mapFile.Asset}.{gridX:x2}{gridY:x2}.area");
                IArchiveFileEntry grid = ArchiveManager.MainArchive.GetFileInfoByPath(path);
                if (grid != null)
                {
                    ProcessGrid(mapFile, grid, gridX.Value, gridY.Value);
                }
            }
            else
            {
                string path = Path.Combine(entry.AssetPath, "*.*.area");
                foreach (IArchiveFileEntry grid in ArchiveManager.MainArchive.IndexFile.GetFiles(path))
                {
                    Regex regex = new Regex(@"[\w]+\.([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})\.area");
                    Match match = regex.Match(grid.FileName);
                    byte  x     = byte.Parse(match.Groups[1].Value, NumberStyles.HexNumber);
                    byte  y     = byte.Parse(match.Groups[2].Value, NumberStyles.HexNumber);

                    ProcessGrid(mapFile, grid, x, y);
                }
            }

            // FIXME: this happens for worlds with no terrain information, this is usually an instance where props are used as terrain
            if (!mapFile.Any())
            {
                log.Info($"Map {mapFile.Asset} has no grid information, skipping");
                return;
            }

            // Path.ChangeExtension(mapFile.Asset, "nfmap")
            // ChangeExtension doesn't behave correctly on linux
            string filePath = Path.Combine("map", $"{mapFile.Asset}.nfmap");

            using (FileStream stream = File.Create(filePath))
                using (var writer = new BinaryWriter(stream))
                {
                    mapFile.Write(writer);
                }
        }
Ejemplo n.º 11
0
    public void updateWorld()
    {
        Vector3 pcPos = pc.transform.position;

        while (levelObjects.Count > 0)
        {
            WorldEntry entry = levelObjects [0];
            if (entry.loc.x < pcPos.x + SPAWN_OFFSET)
            {
                Instantiate(entry.obj, entry.loc, Quaternion.identity);
                levelObjects.RemoveAt(0);
            }
            else
            {
                return;
            }
        }
    }
Ejemplo n.º 12
0
    public void WorldUpdate()
    {
        Vector3 pcPos = pc.transform.position;

        while (levelObjects.Count > 0)
        {
            WorldEntry thisentry = levelObjects [0];
            if (thisentry.loc.x < pcPos.x + spawningOffset)
            {
                Instantiate(thisentry.obj, thisentry.loc, Quaternion.identity);
                levelObjects.RemoveAt(0);
            }
            else
            {
                break;
            }
        }
    }
Ejemplo n.º 13
0
        /// <summary>
        /// Enqueue <see cref="GridEntity"/> to be added to a map.
        /// </summary>
        public static void AddToMap(GridEntity entity, ushort worldId, Vector3 vector3)
        {
            WorldEntry entry = GameTableManager.World.GetEntry(worldId);

            if (entry == null)
            {
                throw new ArgumentException();
            }

            if (maps.TryGetValue(worldId, out BaseMap map))
            {
                map.EnqueueAdd(entity, vector3);
            }
            else
            {
                var newMap = new BaseMap(entry);
                newMap.EnqueueAdd(entity, vector3);
                maps.Add(worldId, newMap);
            }
        }
Ejemplo n.º 14
0
 public bool checkEntry(WorldEntry entry)
 {
     if (category != null && !entry.Categories.Contains(category))
     {
         return(false);
     }
     if (difficulty != null && !entry.Difficulties.Contains(difficulty))
     {
         return(false);
     }
     if (size != null && !entry.Size.Equals(size))
     {
         return(false);
     }
     if (text != null && !entry.Name.ToLower().Contains(text) && !entry.Author.ToLower().Contains(text))
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 15
0
        private void PreCacheMapFiles()
        {
            log.Info("Caching map files...");

            List <ushort> precachedBaseMaps = ConfigurationManager <WorldServerConfiguration> .Instance.Config.Map.PrecacheBaseMaps;

            if (precachedBaseMaps == null)
            {
                return;
            }

            foreach (ushort worldId in precachedBaseMaps)
            {
                WorldEntry entry = GameTableManager.Instance.World.GetEntry(worldId);
                if (entry == null)
                {
                    throw new ConfigurationException($"Invalid world id {worldId} supplied for precached base maps!");
                }

                LoadBaseMap(entry.AssetPath);
            }
        }
Ejemplo n.º 16
0
    private WorldEntry generateRemoteWorld(Dictionary json_item)
    {
        WorldEntry world_info = new WorldEntry();

        world_info.HasServerInfo = true;
        world_info.Name          = HTTPUtil.jsonValue <string>(json_item, "name");
        world_info.Author        = HTTPUtil.jsonValue <string>(json_item, "author");
        world_info.Description   = HTTPUtil.jsonValue <string>(json_item, "description");
        var base64_icon = HTTPUtil.jsonValue <string>(json_item, "icon");

        world_info.Icon = base64_icon != null && base64_icon.Length > 0 ?
                          GDKnyttAssetManager.loadTexture(decompress(Convert.FromBase64String(base64_icon))) : null;
        world_info.Link      = HTTPUtil.jsonValue <string>(json_item, "link");
        world_info.FileSize  = HTTPUtil.jsonInt(json_item, "file_size");
        world_info.Upvotes   = HTTPUtil.jsonInt(json_item, "upvotes");
        world_info.Downvotes = HTTPUtil.jsonInt(json_item, "downvotes");
        world_info.Downloads = HTTPUtil.jsonInt(json_item, "downloads");
        world_info.Complains = HTTPUtil.jsonInt(json_item, "complains");
        world_info.Verified  = HTTPUtil.jsonBool(json_item, "verified");
        world_info.Approved  = HTTPUtil.jsonBool(json_item, "approved");
        return(world_info);
    }
Ejemplo n.º 17
0
    public void initialize(WorldEntry info)
    {
        worldEntry = info;

        GetNode <AnimatedSprite>("AnimatedSprite").Visible = false;
        GetNode <Control>("MainContainer").Visible         = true;
        GetNode <Control>("RatingControl").Visible         = true;

        GetNode <TextureRect>("MainContainer/IconTexture").Texture           = info.Icon;
        GetNode <TextureRect>("MainContainer/IconTexture").RectSize          = new Vector2(30, 30);
        GetNode <Label>("MainContainer/TextContainer/NameLabel").Text        = $"{info.Name} ({info.Author})";
        GetNode <Label>("MainContainer/TextContainer/DescriptionLabel").Text = info.Description;

        progressRect        = GetNode <ColorRect>("ProgressRect");
        startProgressLength = progressRect.RectSize.x - progressRect.MarginLeft;
        varProgressLength   = RectSize.x - startProgressLength - progressRect.MarginLeft * 2;

        var rating_control = GetNode <Control>("RatingControl");

        if (!worldEntry.HasServerInfo)
        {
            rating_control.Visible = false;
            RectMinSize            = new Vector2(RectMinSize.x, 45);
        }
        else
        {
            rating_control.Visible = true;
            RectMinSize            = new Vector2(RectMinSize.x, 55);
            rating_control.GetNode <Label>("SizeLabel").Text      = $"{(worldEntry.FileSize / 1024f / 1024f):0.#} MB";
            rating_control.GetNode <Label>("UpvotesLabel").Text   = $"+{worldEntry.Upvotes}";
            rating_control.GetNode <Label>("DownvotesLabel").Text = $"-{worldEntry.Downvotes}";
            rating_control.GetNode <Label>("DownloadsLabel").Text = $"{worldEntry.Downloads}";
            rating_control.GetNode <Label>("VerifiedLabel").Text  =
                worldEntry.Approved ? "Approved" : worldEntry.Verified ? "Autoverified" : "Not Verified";
            rating_control.GetNode <Label>("VerifiedLabel").AddColorOverride("font_color",
                                                                             worldEntry.Approved || worldEntry.Verified ? new Color(0, 0.5f, 0) : new Color(0.5f, 0, 0));
        }
    }
Ejemplo n.º 18
0
    public void WorldStart()
    {
        // Sorting level by x position
        levelObjects.Sort((x, y) => x.loc.x.CompareTo(y.loc.x));

        spawningOffset = 18;

        Vector3 pcpos = pc.transform.position;

        // Actual starting position
        pc.transform.position = new Vector3(pcpos.x, pcpos.y + 10, pcpos.z);

        // Testing starting position
//		pc.transform.position = new Vector3 (pcpos.x + 420, pcpos.y, pcpos.z);

        // Instantiate all the background panels, so that they'll be layered correctly
        foreach (WorldEntry bg in backgroundObjects)
        {
            Instantiate(bg.obj, bg.loc, Quaternion.identity);
        }


        // Instantiate everything that should be on screen or will be soon
        while (levelObjects.Count > 0)
        {
            WorldEntry thisentry = levelObjects [0];
            if (thisentry.loc.x < spawningOffset)
            {
                Instantiate(thisentry.obj, thisentry.loc, Quaternion.identity);
                levelObjects.RemoveAt(0);
            }
            else
            {
                break;
            }
        }
    }
Ejemplo n.º 19
0
        /// <summary>
        /// Remove the given fixed-combat entry from the current map or quest.
        /// </summary>
        public static void RemoveFixedCombat(MapEntry<FixedCombat> mapEntry)
        {
            // check the parameter
            if (mapEntry == null)
            {
                return;
            }

            // check the map for the item first
            if (TileEngine.Map != null)
            {
                int removedEntries = TileEngine.Map.FixedCombatEntries.RemoveAll(
                    delegate(MapEntry<FixedCombat> entry)
                    {
                        return ((entry.ContentName == mapEntry.ContentName) &&
                            (entry.MapPosition == mapEntry.MapPosition));
                    });
                if (removedEntries > 0)
                {
                    WorldEntry<FixedCombat> worldEntry = new WorldEntry<FixedCombat>();
                    worldEntry.Content = mapEntry.Content;
                    worldEntry.ContentName = mapEntry.ContentName;
                    worldEntry.Count = mapEntry.Count;
                    worldEntry.Direction = mapEntry.Direction;
                    worldEntry.MapContentName = TileEngine.Map.AssetName;
                    worldEntry.MapPosition = mapEntry.MapPosition;
                    singleton.removedMapFixedCombats.Add(worldEntry);
                    return;
                }
            }

            // look for the map entry within the quest
            if (singleton.quest != null)
            {
                int removedEntries = singleton.quest.FixedCombatEntries.RemoveAll(
                    delegate(WorldEntry<FixedCombat> entry)
                    {
                        return ((entry.ContentName == mapEntry.ContentName) &&
                            (entry.MapPosition == mapEntry.MapPosition) &&
                            TileEngine.Map.AssetName.EndsWith(entry.MapContentName));
                    });
                if (removedEntries > 0)
                {
                    WorldEntry<FixedCombat> worldEntry = new WorldEntry<FixedCombat>();
                    worldEntry.Content = mapEntry.Content;
                    worldEntry.ContentName = mapEntry.ContentName;
                    worldEntry.Count = mapEntry.Count;
                    worldEntry.Direction = mapEntry.Direction;
                    worldEntry.MapContentName = TileEngine.Map.AssetName;
                    worldEntry.MapPosition = mapEntry.MapPosition;
                    singleton.removedQuestFixedCombats.Add(worldEntry);
                    return;
                }
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Remove the given player NPC entry from the current map or quest.
        /// </summary>
        public static void RemovePlayerNpc(MapEntry<Player> mapEntry)
        {
            // check the parameter
            if (mapEntry == null)
            {
                return;
            }

            // check the map for the item
            if (TileEngine.Map != null)
            {
                int removedEntries = TileEngine.Map.PlayerNpcEntries.RemoveAll(
                    delegate(MapEntry<Player> entry)
                    {
                        return ((entry.ContentName == mapEntry.ContentName) &&
                            (entry.MapPosition == mapEntry.MapPosition));
                    });
                if (removedEntries > 0)
                {
                    WorldEntry<Player> worldEntry = new WorldEntry<Player>();
                    worldEntry.Content = mapEntry.Content;
                    worldEntry.ContentName = mapEntry.ContentName;
                    worldEntry.Count = mapEntry.Count;
                    worldEntry.Direction = mapEntry.Direction;
                    worldEntry.MapContentName = TileEngine.Map.AssetName;
                    worldEntry.MapPosition = mapEntry.MapPosition;
                    singleton.removedMapPlayerNpcs.Add(worldEntry);
                    return;
                }
            }

            // quests don't have a list of player NPCs
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Generate a base map (.nfmap) file from supplied <see cref="WorldEntry"/>.
        /// </summary>
        private static void ProcessWorld(WorldEntry entry)
        {
            var mapFile = new WritableMapFile(Path.GetFileName(entry.AssetPath));

            log.Info($"Processing {mapFile.Asset}...");

            foreach (IArchiveFileEntry fileEntry in ArchiveManager.MainArchive.IndexFile.GetFiles(Path.Combine(entry.AssetPath, "*.*.area")))
            {
                // skip any low quality grids
                if (fileEntry.FileName.Contains("_low", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                Regex regex = new Regex(@"[\w]+\.([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})\.area");
                Match match = regex.Match(fileEntry.FileName);
                uint  x     = uint.Parse(match.Groups[1].Value, NumberStyles.HexNumber);
                uint  y     = uint.Parse(match.Groups[2].Value, NumberStyles.HexNumber);

                log.Info($"Processing {mapFile.Asset} grid {x},{y}...");

                using (Stream stream = ArchiveManager.MainArchive.OpenFileStream(fileEntry))
                {
                    try
                    {
                        var mapFileGrid = new WritableMapFileGrid(x, y);

                        var areaFile = new AreaFile(stream);
                        foreach (IReadable areaChunk in areaFile.Chunks)
                        {
                            switch (areaChunk)
                            {
                            case Chnk chnk:
                            {
                                foreach (ChnkCell cell in chnk.Cells.Where(c => c != null))
                                {
                                    var mapFileCell = new WritableMapFileCell(cell);
                                    mapFileGrid.AddCell(mapFileCell);
                                }
                                break;
                            }
                            }
                        }

                        mapFile.SetGrid(x, y, mapFileGrid);
                    }
                    catch (Exception e)
                    {
                        log.Error(e);
                    }
                }
            }

            if (!mapFile.Any())
            {
                log.Info($"Map {mapFile.Asset} has no grid information, skipping");
                return;
            }

            // Path.ChangeExtension(mapFile.Asset, "nfmap")
            // ChangeExtension doesn't behave correctly on linux
            string filePath = Path.Combine("map", $"{mapFile.Asset}.nfmap");

            using (FileStream stream = File.Create(filePath))
                using (var writer = new BinaryWriter(stream))
                {
                    mapFile.Write(writer);
                }
        }
Ejemplo n.º 22
0
 public MapInfo(WorldEntry entry, uint instanceId = 0u, ulong residenceId = 0ul)
 {
     Entry       = entry;
     InstanceId  = instanceId;
     ResidenceId = residenceId;
 }
Ejemplo n.º 23
0
 public BaseMap(WorldEntry entry)
 {
     Entry = entry;
     CacheEntitySpawns();
 }
Ejemplo n.º 24
0
        public static void HandleCharacterSelect(WorldSession session, ClientCharacterSelect characterSelect)
        {
            CharacterModel character = session.Characters.SingleOrDefault(c => c.Id == characterSelect.CharacterId);

            if (character == null)
            {
                session.EnqueueMessageEncrypted(new ServerCharacterSelectFail
                {
                    Result = CharacterSelectResult.Failed
                });
                return;
            }

            if (PlayerCleanupManager.HasPendingCleanup(session.Account))
            {
                session.EnqueueMessageEncrypted(new ServerCharacterSelectFail
                {
                    Result = CharacterSelectResult.FailedCharacterInWorld
                });
                return;
            }

            session.Player = new Player(session, character);

            WorldEntry entry = GameTableManager.Instance.World.GetEntry(character.WorldId);

            if (entry == null)
            {
                throw new ArgumentOutOfRangeException();
            }

            switch ((MapType)entry.Type)
            {
            case MapType.Residence:
            case MapType.Community:
            {
                // characters logging in to a housing map are returned to their own residence
                Residence residence = session.Player.ResidenceManager.Residence;
                residence ??= GlobalResidenceManager.Instance.CreateResidence(session.Player);

                ResidenceEntrance entrance = GlobalResidenceManager.Instance.GetResidenceEntrance(residence.PropertyInfoId);
                session.Player.Rotation = entrance.Rotation.ToEulerDegrees();
                MapManager.Instance.AddToMap(session.Player, new MapPosition
                    {
                        Info = new MapInfo
                        {
                            Entry      = entrance.Entry,
                            InstanceId = residence.Parent?.Id ?? residence.Id
                        },
                        Position = entrance.Position
                    });

                break;
            }

            default:
            {
                session.Player.Rotation = new Vector3(character.RotationX, character.RotationY, character.RotationZ);
                MapManager.Instance.AddToMap(session.Player, new MapPosition
                    {
                        Info = new MapInfo
                        {
                            Entry = entry
                        },
                        Position = new Vector3(character.LocationX, character.LocationY, character.LocationZ)
                    });
                break;
            }
            }
        }
Ejemplo n.º 25
0
 public Location(WorldEntry world, Vector3 position, Vector3 rotation)
 {
     World    = world;
     Position = position;
     Rotation = rotation;
 }
Ejemplo n.º 26
0
 public void Initialise(MapInfo info, Player player)
 {
     entry = info.Entry;
 }
Ejemplo n.º 27
0
 public bool addWorld(WorldEntry entry)
 {
     this.Entries.Add(entry);
     return(checkEntry(entry));
 }