Exemple #1
0
        /// <summary>
        /// Returns the value object to use for scriban exporting
        /// </summary>
        /// <param name="parsedData">Parsed data</param>
        /// <param name="project">Project</param>
        /// <param name="errorCollection">Error Collection</param>
        /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param>
        /// <param name="exportSettings">Export Settings</param>
        /// <returns>Value Object</returns>
        protected override async Task <ScribanLearnedSkillConditionData> GetExportObject(LearnedSkillConditionData parsedData, GoNorthProject project, ExportPlaceholderErrorCollection errorCollection, FlexFieldObject flexFieldObject, ExportSettings exportSettings)
        {
            KortistoNpc npc = await ConditionRenderingUtil.GetExportNpc(_cachedDbAccess, project, flexFieldObject, errorCollection, _isPlayer);

            if (npc == null)
            {
                errorCollection.AddDialogNpcNotFoundError();
                return(null);
            }

            EvneSkill skill = await _cachedDbAccess.GetSkillById(parsedData.SelectedSkillId);

            if (skill == null)
            {
                errorCollection.AddDialogSkillNotFoundError();
                return(null);
            }

            ScribanLearnedSkillConditionData conditionData = new ScribanLearnedSkillConditionData();
            ScribanExportNpc convertedNpc = FlexFieldValueCollectorUtil.BuildFlexFieldValueObject <ScribanExportNpc>(null, null, npc, exportSettings, errorCollection);

            convertedNpc.IsPlayer = npc.IsPlayerNpc;
            conditionData.Npc     = convertedNpc;

            conditionData.SelectedSkill = FlexFieldValueCollectorUtil.BuildFlexFieldValueObject <ScribanExportSkill>(null, null, skill, exportSettings, errorCollection);

            return(conditionData);
        }
        /// <summary>
        /// Builds the skills
        /// </summary>
        /// <param name="skillCode">Code for the skills to repeat</param>
        /// <param name="npc">Npc</param>
        /// <returns>Skills of the npc</returns>
        private string BuildSkills(string skillCode, KortistoNpc npc)
        {
            if (npc.Skills == null)
            {
                return(string.Empty);
            }

            int    skillIndex    = 0;
            string skillListCode = string.Empty;

            foreach (KortistoNpcSkill curSkill in npc.Skills)
            {
                string curSkillCode = ExportUtil.BuildPlaceholderRegex(Placeholder_CurSkill_Index).Replace(skillCode, skillIndex.ToString());

                EvneSkill skill = _cachedDbAccess.GetSkillById(curSkill.SkillId).Result;
                if (skill != null)
                {
                    ExportObjectData skillExportData = new ExportObjectData();
                    skillExportData.ExportData.Add(ExportConstants.ExportDataObject, skill);
                    skillExportData.ExportData.Add(ExportConstants.ExportDataObjectType, ExportConstants.ExportObjectTypeSkill);
                    curSkillCode = _skillPlaceholderResolver.FillPlaceholders(curSkillCode, skillExportData).Result;
                }

                skillListCode += curSkillCode;
                ++skillIndex;
            }

            return(skillListCode);
        }
Exemple #3
0
        /// <summary>
        /// Compares a skill
        /// </summary>
        /// <param name="skillId">Id of the skill</param>
        /// <param name="currentSkill">Current skill, if null the skill will be loaded</param>
        /// <returns>Compare Result</returns>
        public async Task <CompareResult> CompareSkill(string skillId, EvneSkill currentSkill = null)
        {
            if (currentSkill == null)
            {
                currentSkill = await _skillDbAccess.GetFlexFieldObjectById(skillId);
            }

            EvneSkill oldSkill = await _skillSnapshotDbAccess.GetSnapshotById(skillId);

            return(CompareObjects(currentSkill, oldSkill));
        }
        /// <summary>
        /// Returns the skill to use
        /// </summary>
        /// <param name="parsedData">Parsed data</param>
        /// <param name="errorCollection">Error Collection</param>
        /// <returns>Value Object</returns>
        private async Task <IFlexFieldExportable> GetSkill(LearnForgetSkillActionRenderer.LearnForgetSkillActionData parsedData, ExportPlaceholderErrorCollection errorCollection)
        {
            EvneSkill skillToUse = await _cachedDbAccess.GetSkillById(parsedData.SkillId);

            if (skillToUse == null)
            {
                errorCollection.AddDialogSkillNotFoundError();
                return(null);
            }

            return(skillToUse);
        }
        /// <summary>
        /// Returns the value object to use
        /// </summary>
        /// <param name="parsedData">Parsed data</param>
        /// <param name="flexFieldObject">Flex field object</param>
        /// <param name="errorCollection">Error Collection</param>
        /// <returns>Value Object</returns>
        protected override async Task <IFlexFieldExportable> GetValueObject(ValueActionRenderBase.ValueFieldActionData parsedData, FlexFieldObject flexFieldObject, ExportPlaceholderErrorCollection errorCollection)
        {
            EvneSkill skill = await _cachedDbAccess.GetSkillById(parsedData.ObjectId);

            if (skill == null)
            {
                errorCollection.AddDialogSkillNotFoundError();
                return(null);
            }

            return(skill);
        }
        /// <summary>
        /// Returns the scriban flex field object for the export
        /// </summary>
        /// <param name="parsedData">Parsed condition</param>
        /// <param name="project">Project</param>
        /// <param name="errorCollection">Error Collection</param>
        /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param>
        /// <param name="exportSettings">Export Settings</param>
        /// <returns>Scriban export object</returns>
        protected override async Task <ScribanFlexFieldObject> GetScribanFlexFieldObject(ValueFieldConditionData parsedData, GoNorthProject project, ExportPlaceholderErrorCollection errorCollection, FlexFieldObject flexFieldObject, ExportSettings exportSettings)
        {
            EvneSkill skill = await _cachedDbAccess.GetSkillById(parsedData.SelectedObjectId);

            if (skill == null)
            {
                errorCollection.AddDialogSkillNotFoundError();
                return(null);
            }

            return(FlexFieldValueCollectorUtil.BuildFlexFieldValueObject <ScribanExportSkill>(null, null, skill, exportSettings, errorCollection));
        }
Exemple #7
0
        /// <summary>
        /// Returns the value object to use
        /// </summary>
        /// <param name="parsedData">Parsed data</param>
        /// <param name="flexFieldObject">Flex field object</param>
        /// <param name="errorCollection">Error Collection</param>
        /// <returns>Value Object</returns>
        protected override IFlexFieldExportable GetValueObject(ValueFieldConditionData parsedData, FlexFieldObject flexFieldObject, ExportPlaceholderErrorCollection errorCollection)
        {
            EvneSkill skill = _cachedDbAccess.GetSkillById(parsedData.SelectedObjectId).Result;

            if (skill == null)
            {
                errorCollection.AddDialogSkillNotFoundError();
                return(null);
            }

            return(skill);
        }
Exemple #8
0
        /// <summary>
        /// Returns a skill by its id
        /// </summary>
        /// <param name="skillId">Skill id</param>
        /// <returns>Skill</returns>
        public async Task <EvneSkill> GetSkillById(string skillId)
        {
            if (_cachedSkills.ContainsKey(skillId))
            {
                return(_cachedSkills[skillId]);
            }

            EvneSkill skill = await _skillDbAccess.GetFlexFieldObjectById(skillId);

            _cachedSkills.Add(skillId, skill);
            return(skill);
        }
Exemple #9
0
        /// <summary>
        /// Builds a condition element from parsed data
        /// </summary>
        /// <param name="template">Export template to use</param>
        /// <param name="parsedData">Parsed data</param>
        /// <param name="project">Project</param>
        /// <param name="errorCollection">Error Collection</param>
        /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param>
        /// <param name="exportSettings">Export Settings</param>
        /// <returns>Condition string</returns>
        public override async Task <string> BuildConditionElementFromParsedData(ExportTemplate template, LearnedSkillConditionData parsedData, GoNorthProject project, ExportPlaceholderErrorCollection errorCollection, FlexFieldObject flexFieldObject, ExportSettings exportSettings)
        {
            EvneSkill skill = await _cachedDbAccess.GetSkillById(parsedData.SelectedSkillId);

            if (skill == null)
            {
                errorCollection.AddDialogSkillNotFoundError();
                return(string.Empty);
            }

            ExportObjectData skillExportData = new ExportObjectData();

            skillExportData.ExportData.Add(ExportConstants.ExportDataObject, skill);
            skillExportData.ExportData.Add(ExportConstants.ExportDataObjectType, ExportConstants.ExportObjectTypeSkill);

            _skillPlaceholderResolver.SetErrorMessageCollection(errorCollection);
            string conditionCode = await _skillPlaceholderResolver.FillPlaceholders(template.Code, skillExportData);

            return(conditionCode);
        }
        /// <summary>
        /// Checks an skill for update
        /// </summary>
        /// <param name="exportSnippet">Export Snippet</param>
        /// <param name="objectId">Object Id</param>
        /// <param name="timelineEvent">Timeline Event</param>
        /// <returns>Result of update</returns>
        private async Task <FlexFieldObject> CheckSkillForUpdate(ObjectExportSnippet exportSnippet, string objectId, TimelineEvent timelineEvent)
        {
            EvneSkill skill = await _skillDbAccess.GetFlexFieldObjectById(objectId);

            if (skill == null)
            {
                return(null);
            }

            await _timelineService.AddTimelineEntry(exportSnippet.ProjectId, timelineEvent, exportSnippet.SnippetName, skill.Name, skill.Id);

            CompareResult result = await _implementationStatusComparer.CompareSkill(skill.Id, skill);

            if (result.CompareDifference != null && result.CompareDifference.Count > 0)
            {
                skill.IsImplemented = false;
                await _skillDbAccess.UpdateFlexFieldObject(skill);
            }

            return(skill);
        }
Exemple #11
0
        public async Task <IActionResult> FlagSkillAsImplemented(string skillId)
        {
            // Check Data
            EvneSkill skill = await _skillDbAccess.GetFlexFieldObjectById(skillId);

            if (skill == null)
            {
                return(StatusCode((int)HttpStatusCode.NotFound));
            }

            // Flag skill as implemented
            skill.IsImplemented = true;
            await _skillSnapshotDbAccess.SaveSnapshot(skill);

            await _skillDbAccess.UpdateFlexFieldObject(skill);

            // Add Timeline entry
            await _timelineService.AddTimelineEntry(TimelineEvent.ImplementedSkill, skill.Id, skill.Name);

            return(Ok());
        }
        /// <summary>
        /// Builds a condition element from parsed data
        /// </summary>
        /// <param name="parsedData">Parsed data</param>
        /// <param name="project">Project</param>
        /// <param name="errorCollection">Error Collection</param>
        /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param>
        /// <param name="exportSettings">Export Settings</param>
        /// <returns>Condition string</returns>
        public override string BuildConditionElementFromParsedData(LearnedSkillConditionResolver.LearnedSkillConditionData parsedData, GoNorthProject project, ExportPlaceholderErrorCollection errorCollection, FlexFieldObject flexFieldObject, ExportSettings exportSettings)
        {
            ExportTemplate conditionTemplate = _defaultTemplateProvider.GetDefaultTemplateByType(project.Id, GetTemplateType()).Result;

            EvneSkill skill = _cachedDbAccess.GetSkillById(parsedData.SelectedSkillId).Result;

            if (skill == null)
            {
                errorCollection.AddDialogSkillNotFoundError();
                return(string.Empty);
            }

            ExportObjectData skillExportData = new ExportObjectData();

            skillExportData.ExportData.Add(ExportConstants.ExportDataObject, skill);
            skillExportData.ExportData.Add(ExportConstants.ExportDataObjectType, ExportConstants.ExportObjectTypeSkill);

            _skillPlaceholderResolver.SetErrorMessageCollection(errorCollection);
            string conditionCode = _skillPlaceholderResolver.FillPlaceholders(conditionTemplate.Code, skillExportData).Result;

            return(conditionCode);
        }
Exemple #13
0
        /// <summary>
        /// Copy Constructor from Base skill
        /// </summary>
        /// <param name="baseSkill">Base Skill</param>
        public SkillJsonExportObject(EvneSkill baseSkill)
        {
            ExportSnippets = new List <ObjectExportSnippet>();

            JsonExportPropertyFill.FillBaseProperties(this, baseSkill);
        }
Exemple #14
0
        /// <summary>
        /// Exports an object
        /// </summary>
        /// <param name="exportFormat">Format to export (Script, JSON or LanguageFile)</param>
        /// <param name="id">Id of the object to export</param>
        /// <param name="templateType">Template type</param>
        /// <returns>Export result</returns>
        private async Task <ExportObjectResult> RunExportObject(string exportFormat, string id, TemplateType templateType)
        {
            // Check Access
            if ((templateType == TemplateType.ObjectNpc && !User.IsInRole(RoleNames.Kortisto)) ||
                (templateType == TemplateType.ObjectItem && !User.IsInRole(RoleNames.Styr)) ||
                (templateType == TemplateType.ObjectSkill && !User.IsInRole(RoleNames.Evne)))
            {
                throw new UnauthorizedAccessException();
            }

            // Get Exporter
            string exporterKey = exportFormat.ToLowerInvariant();

            if (!_exporters.ContainsKey(exporterKey))
            {
                throw new InvalidOperationException("Unknown Export Format");
            }
            IObjectExporter exporter = _exporters[exporterKey];

            // Get Objects
            bool             objectFound = false;
            ExportObjectData objectData  = new ExportObjectData();

            if (templateType == TemplateType.ObjectNpc)
            {
                KortistoNpc npc = await _npcDbAccess.GetFlexFieldObjectById(id);

                if (npc != null)
                {
                    objectData.ExportData.Add(ExportConstants.ExportDataObject, npc);
                    objectData.ExportData.Add(ExportConstants.ExportDataObjectType, ExportConstants.ExportObjectTypeNpc);

                    TaleDialog dialog = await _dialogDbAccess.GetDialogByRelatedObjectId(id);

                    objectData.ExportData.Add(ExportConstants.ExportDataDialog, dialog);

                    objectFound = true;
                }
            }
            else if (templateType == TemplateType.ObjectItem)
            {
                StyrItem item = await _itemDbAccess.GetFlexFieldObjectById(id);

                if (item != null)
                {
                    objectData.ExportData.Add(ExportConstants.ExportDataObject, item);
                    objectData.ExportData.Add(ExportConstants.ExportDataObjectType, ExportConstants.ExportObjectTypeItem);
                    objectFound = true;
                }
            }
            else if (templateType == TemplateType.ObjectSkill)
            {
                EvneSkill skill = await _skillDbAccess.GetFlexFieldObjectById(id);

                if (skill != null)
                {
                    objectData.ExportData.Add(ExportConstants.ExportDataObject, skill);
                    objectData.ExportData.Add(ExportConstants.ExportDataObjectType, ExportConstants.ExportObjectTypeSkill);
                    objectFound = true;
                }
            }
            else
            {
                throw new InvalidOperationException("Template Type not supported for exporting");
            }

            if (!objectFound)
            {
                throw new KeyNotFoundException();
            }

            // Get Template
            ExportTemplateByObjectIdResult template = await GetValidExportTemplateByIdAndType(id, templateType);

            // Run Export
            ExportObjectResult result = await exporter.ExportObject(template.Template, objectData);

            result.ObjectFilename = ((FlexFieldObject)objectData.ExportData[ExportConstants.ExportDataObject]).Name;
            string regexSearch      = Regex.Escape(new string(Path.GetInvalidFileNameChars()));
            Regex  illegalCharRegex = new Regex(string.Format("[{0}]", regexSearch));

            result.ObjectFilename = illegalCharRegex.Replace(result.ObjectFilename, string.Empty);
            return(result);
        }