Exemple #1
0
        /// <inheritdoc />
        public void Load()
        {
            if (!File.Exists(GameResources.ItemsPropPath))
            {
                this._logger.LogWarning("Unable to load items. Reason: cannot find '{0}' file.", GameResources.ItemsPropPath);
                return;
            }

            using (var propItem = new ResourceTableFile(GameResources.ItemsPropPath, 1, this._defines.Defines, this._texts.Texts))
            {
                var items = propItem.GetRecords <ItemData>();

                foreach (var item in items)
                {
                    if (this._itemsData.ContainsKey(item.Id))
                    {
                        this._itemsData[item.Id] = item;
                        this._logger.LogWarning(GameResources.ObjectOverridedMessage, "Item", item.Id, "already declared");
                    }
                    else
                    {
                        this._itemsData.Add(item.Id, item);
                    }
                }
            }

            this._logger.LogInformation("-> {0} items loaded.", this._itemsData.Count);
        }
Exemple #2
0
        /// <inheritdoc />
        public void Load()
        {
            if (!File.Exists(GameResources.JobPropPath))
            {
                this._logger.LogWarning($"Unable to load job properties. Reason: cannot find '{GameResources.JobPropPath}' file.");
                return;
            }

            using (var propJob = new ResourceTableFile(GameResources.JobPropPath, -1, new [] { '\t', ' ', '\r' }, this._defines.Defines, null))
            {
                var jobs = propJob.GetRecords <JobData>();

                foreach (var job in jobs)
                {
                    if (this._jobsData.ContainsKey(job.Id))
                    {
                        this._jobsData[job.Id] = job;
                        this._logger.LogWarning(GameResources.ObjectOverridedMessage, "JobData", job.Id, "already delcared");
                    }
                    else
                    {
                        this._jobsData.Add(job.Id, job);
                    }
                }
            }

            this._logger.LogInformation($"-> {this._jobsData.Count} jobs data loaded.");
        }
Exemple #3
0
        /// <inheritdoc />
        public void Load()
        {
            string propItemPath = GameResourcesConstants.Paths.ItemsPropPath;

            if (!File.Exists(propItemPath))
            {
                _logger.LogWarning("Unable to load items. Reason: cannot find '{0}' file.", propItemPath);
                return;
            }

            var itemsData = new ConcurrentDictionary <int, ItemData>();

            using (var propItem = new ResourceTableFile(propItemPath, 1, _defines, _texts))
            {
                var items = propItem.GetRecords <ItemData>();

                foreach (ItemData item in items)
                {
                    TransformItem(item);

                    if (itemsData.ContainsKey(item.Id))
                    {
                        itemsData[item.Id] = item;
                        _logger.LogWarning(GameResourcesConstants.Errors.ObjectOverridedMessage, "Item", item.Id, "already declared");
                    }
                    else
                    {
                        itemsData.TryAdd(item.Id, item);
                    }
                }
            }

            _cache.Set(GameResourcesConstants.Items, itemsData);
            _logger.LogInformation("-> {0} items loaded.", itemsData.Count);
        }
Exemple #4
0
        public void OpenResourceTable()
        {
            var resourceTable = new ResourceTableFile(ResourceTablePath, ResourceTableHeaderIndex);

            Assert.NotNull(resourceTable);
            Assert.Equal(ResourceTableCount, resourceTable.Count);

            resourceTable.Dispose();
        }
Exemple #5
0
        /// <inheritdoc />
        public void Load()
        {
            string propJobFile        = GameResourcesConstants.Paths.JobPropPath;
            string jobsDefinitionFile = GameResourcesConstants.Paths.JobsDefinitionsPath;

            if (!File.Exists(propJobFile))
            {
                _logger.LogWarning($"Unable to load job properties. Reason: cannot find '{propJobFile}' file.");
                return;
            }

            if (!File.Exists(jobsDefinitionFile))
            {
                _logger.LogWarning($"Unable to load job definitions. Reason: cannot find '{jobsDefinitionFile}' file.");
                return;
            }

            string jobDefinitionFileContent = File.ReadAllText(jobsDefinitionFile);
            var    jobDefinitions           = JsonConvert.DeserializeObject <Dictionary <DefineJob.Job, JobDefinitionData> >(jobDefinitionFileContent);
            var    jobData = new ConcurrentDictionary <DefineJob.Job, JobData>();

            using (var propJob = new ResourceTableFile(propJobFile, -1, new [] { '\t', ' ', '\r' }, _defines, null))
            {
                IEnumerable <JobData> jobs = propJob.GetRecords <JobData>();

                foreach (JobData job in jobs)
                {
                    if (!jobData.TryAdd(job.Id, job))
                    {
                        _logger.LogWarning(GameResourcesConstants.Errors.ObjectOverridedMessage, "JobData", job.Id, "already delcared");
                    }
                }

                foreach (JobData job in jobData.Values)
                {
                    if (jobDefinitions.TryGetValue(job.Id, out JobDefinitionData jobDefinition))
                    {
                        job.Parent = jobDefinition.Parent.HasValue ? jobData[jobDefinition.Parent.Value] : null;
                        job.Type   = jobDefinition.Type;
                    }
                    else
                    {
                        _logger.LogWarning($"Cannot find job '{job.Id}' definition.");
                    }
                }
            }

            _cache.Set(GameResourcesConstants.Jobs, jobData);
            _logger.LogInformation($"-> {jobData.Count} jobs data loaded.");
        }
Exemple #6
0
        /// <inheritdoc />
        public void Load()
        {
            string propSkillPath    = GameResourcesConstants.Paths.SkillPropPath;
            string propSkillAddPath = GameResourcesConstants.Paths.SkillPropAddPath;

            if (!File.Exists(propSkillPath))
            {
                _logger.LogWarning("Unable to load skills. Reason: cannot find '{0}' file.", propSkillPath);
                return;
            }

            if (!File.Exists(propSkillAddPath))
            {
                _logger.LogWarning("Unable to load skills. Reason: cannot find '{0}' file.", propSkillAddPath);
                return;
            }

            using var propSkill    = new ResourceTableFile(GameResourcesConstants.Paths.SkillPropPath, 1, _defines, _texts);
            using var propSkillAdd = new ResourceTableFile(propSkillAddPath, 1, new[] { ',' }, _defines, _texts);

            var skillsData      = new ConcurrentDictionary <int, SkillData>();
            var skills          = propSkill.GetRecords <SkillData>();
            var skillLevelsData = propSkillAdd.GetRecords <SkillLevelData>().GroupBy(x => x.SkillId).ToDictionary(x => x.Key, x => x.AsEnumerable());

            foreach (SkillData skillData in skills)
            {
                if (skillLevelsData.TryGetValue(skillData.Id, out IEnumerable <SkillLevelData> skillLevels))
                {
                    skillData.SkillLevels = skillLevels.ToDictionary(x => x.Level, x => x);

                    foreach (SkillLevelData skillLevel in skillData.SkillLevels.Values)
                    {
                        if (skillLevel.CooldownTime <= 0)
                        {
                            skillLevel.CooldownTime = skillData.SkillReadyTime;
                        }
                    }

                    if (!skillsData.TryAdd(skillData.Id, skillData))
                    {
                        _logger.LogWarning($"Cannot add skill '{skillData.Name}'. Reason: Already exist.");
                    }
                }
            }

            _cache.Set(GameResourcesConstants.Skills, skillsData);
            _logger.LogInformation("-> {0} skills loaded.", skillsData.Count);
        }
Exemple #7
0
        /// <inheritdoc />
        public void Load()
        {
            if (!File.Exists(GameResources.MoversPropPath))
            {
                this._logger.LogWarning("Unable to load movers. Reason: cannot find '{0}' file.", GameResources.MoversPropPath);
                return;
            }

            using (var moversPropFile = new ResourceTableFile(GameResources.MoversPropPath, 1, this._definesLoader.Defines, this._textsLoader.Texts))
            {
                var movers = moversPropFile.GetRecords <MoverData>();

                foreach (var mover in movers)
                {
                    if (this._moversData.ContainsKey(mover.Id))
                    {
                        this._moversData[mover.Id] = mover;
                        this._logger.LogWarning(GameResources.ObjectOverridedMessage, "Mover", mover.Id, "already declared");
                    }
                    else
                    {
                        this._moversData.Add(mover.Id, mover);
                    }
                }
            }

            using (var moversPropExFile = new IncludeFile(GameResources.MoversPropExPath))
            {
                foreach (Block moverBlock in moversPropExFile.Statements)
                {
                    if (this._definesLoader.Defines.TryGetValue(moverBlock.Name, out int moverId) &&
                        this._moversData.TryGetValue(moverId, out MoverData mover))
                    {
                        this.LoadDropGold(mover, moverBlock.GetInstruction("DropGold"));
                        this.LoadDropItems(mover, moverBlock.GetInstructions("DropItem"));
                        this.LoadDropItemsKind(mover, moverBlock.GetInstructions("DropKind"));

                        mover.MaxDropItem = int.Parse(moverBlock.GetVariable("Maxitem").Value.ToString());
                    }
                }
            }

            this._logger.LogInformation("-> {0} movers loaded.", this._moversData.Count);
        }
Exemple #8
0
        /// <inheritdoc />
        public void Load()
        {
            string propMoverPath   = GameResourcesConstants.Paths.MoversPropPath;
            string propMoverExPath = GameResourcesConstants.Paths.MoversPropExPath;

            if (!File.Exists(propMoverPath))
            {
                _logger.LogWarning("Unable to load movers. Reason: cannot find '{0}' file.", propMoverPath);
                return;
            }

            if (!File.Exists(propMoverExPath))
            {
                _logger.LogWarning("Unable to load movers extras. Reason: cannot find '{0}' file.", propMoverExPath);
                return;
            }

            var moversData = new ConcurrentDictionary <int, MoverData>();

            using (var moversPropFile = new ResourceTableFile(propMoverPath, 1, _defines, _texts))
            {
                var movers = moversPropFile.GetRecords <MoverData>();

                foreach (var mover in movers)
                {
                    if (moversData.ContainsKey(mover.Id))
                    {
                        moversData[mover.Id] = mover;
                        _logger.LogWarning(GameResourcesConstants.Errors.ObjectOverridedMessage, "Mover", mover.Id, "already declared");
                    }
                    else
                    {
                        moversData.TryAdd(mover.Id, mover);
                    }
                }
            }

            using (var moversPropExFile = new IncludeFile(propMoverExPath))
            {
                foreach (var statement in moversPropExFile.Statements)
                {
                    if (!(statement is Block moverBlock))
                    {
                        continue;
                    }

                    if (_defines.TryGetValue(moverBlock.Name, out int moverId) && moversData.TryGetValue(moverId, out MoverData mover))
                    {
                        LoadDropGold(mover, moverBlock.GetInstruction("DropGold"));
                        LoadDropItems(mover, moverBlock.GetInstructions("DropItem"));
                        LoadDropItemsKind(mover, moverBlock.GetInstructions("DropKind"));

                        var maxDropVariable = moverBlock.GetVariable("Maxitem");
                        if (maxDropVariable is null)
                        {
                            continue;
                        }

                        mover.MaxDropItem = int.Parse(maxDropVariable.Value.ToString());
                    }
                }
            }

            _cache.Set(GameResourcesConstants.Movers, moversData);
            _logger.LogInformation($"-> {moversData.Count} movers loaded.");
        }