/// <summary>
        /// Loads the inventory
        /// </summary>
        /// <param name="parsedTemplate">Parsed scriban template</param>
        /// <param name="inputNpc">Input npc</param>
        /// <returns>List of items</returns>
        private async Task<List<ScribanExportInventoryItem>> LoadInventory(Template parsedTemplate, KortistoNpc inputNpc)
        {
            if(inputNpc.Inventory == null || !inputNpc.Inventory.Any())
            {
                return new List<ScribanExportInventoryItem>();
            }
            

            GoNorthProject project = await _exportCachedDbAccess.GetUserProject();
            ExportSettings exportSettings = await _exportCachedDbAccess.GetExportSettings(project.Id);

            List<ScribanExportInventoryItem> inventoryItems = new List<ScribanExportInventoryItem>();
            List<StyrItem> items = await _exportCachedDbAccess.GetItemsById(inputNpc.Inventory.Select(i => i.ItemId).ToList());
            foreach(KortistoInventoryItem curItem in inputNpc.Inventory)
            {
                StyrItem loadedItem = items.FirstOrDefault(i => i.Id == curItem.ItemId);
                if(loadedItem == null)
                {
                    continue;
                }

                ScribanExportInventoryItem exportItem = FlexFieldValueCollectorUtil.BuildFlexFieldValueObject<ScribanExportInventoryItem>(null, parsedTemplate, loadedItem, exportSettings, _errorCollection);
                exportItem.Quantity = curItem.Quantity;
                exportItem.IsEquipped = curItem.IsEquipped;
                inventoryItems.Add(exportItem);
            }

            return inventoryItems;
        }
Beispiel #2
0
        /// <summary>
        /// Loads the skills
        /// </summary>
        /// <param name="parsedTemplate">Parsed scriban template</param>
        /// <param name="inputNpc">Input npc</param>
        /// <returns>List of skills</returns>
        private async Task <List <ScribanExportSkill> > LoadSkills(Template parsedTemplate, KortistoNpc inputNpc)
        {
            if (inputNpc.Skills == null || !inputNpc.Skills.Any())
            {
                return(new List <ScribanExportSkill>());
            }

            GoNorthProject project = await _exportCachedDbAccess.GetUserProject();

            ExportSettings exportSettings = await _exportCachedDbAccess.GetExportSettings(project.Id);

            List <EvneSkill> skills = await _exportCachedDbAccess.GetSkillsById(inputNpc.Skills.Select(i => i.SkillId).ToList());

            return(skills.Select(s => FlexFieldValueCollectorUtil.BuildFlexFieldValueObject <ScribanExportSkill>(null, parsedTemplate, s, exportSettings, _errorCollection)).ToList());
        }
        /// <summary>
        /// Fills the language key Placeholders
        /// </summary>
        /// <param name="code">Code to fill</param>
        /// <param name="flexFieldObject">Flex Field Object</param>
        /// <returns>Filled Code</returns>
        private async Task <string> FillLanguageKeyPlaceholders(string code, IFlexFieldExportable flexFieldObject)
        {
            GoNorthProject project = await _cachedDbAccess.GetDefaultProject();

            List <LanguageKey> languageKeys = await _languageKeyDbAccess.GetLanguageKeysByGroupId(project.Id, flexFieldObject.Id);

            ExportSettings exportSettings = await _cachedDbAccess.GetExportSettings(project.Id);

            code = ExportUtil.BuildPlaceholderRegex(Placeholder_ObjectName).Replace(code, flexFieldObject.Name);
            code = ExportUtil.BuildRangePlaceholderRegex(Placeholder_LanguageKeys_Start, Placeholder_LanguageKeys_End).Replace(code, m => {
                return(BuildLanguageKeyList(m.Groups[1].Value, languageKeys, exportSettings));
            });

            return(code);
        }
        /// <summary>
        /// Collects the values for an export
        /// </summary>
        /// <param name="templateType">Template type</param>
        /// <param name="parsedTemplate">Parsed scriban template</param>
        /// <param name="scriptObject">Scriban script object to fill</param>
        /// <param name="data">Export Data</param>
        /// <returns>Task</returns>
        public override async Task CollectValues(TemplateType templateType, Template parsedTemplate, ScriptObject scriptObject, ExportObjectData data)
        {
            IFlexFieldExportable exportable = data.ExportData[ExportConstants.ExportDataObject] as IFlexFieldExportable;

            if (exportable == null)
            {
                return;
            }

            _languageKeyGenerator.SetErrorCollection(_errorCollection);

            GoNorthProject project = await _cachedDbAccess.GetUserProject();

            ExportSettings exportSettings = await _cachedDbAccess.GetExportSettings(project.Id);

            scriptObject.AddOrUpdate(ObjectKey, FlexFieldValueCollectorUtil.ExtractScribanFields(exportable, exportSettings, _errorCollection));
            scriptObject.AddOrUpdate(ExportConstants.ScribanLanguageKeyName, _languageKeyGenerator);
        }
Beispiel #5
0
        /// <summary>
        /// Fills the language key Placeholders
        /// </summary>
        /// <param name="code">Code to fill</param>
        /// <param name="flexFieldObject">Flex Field Object</param>
        /// <param name="referencedLanguageKeys">Referenced language keys</param>
        /// <returns>Filled Code</returns>
        private async Task <string> FillLanguageKeyPlaceholders(string code, IFlexFieldExportable flexFieldObject, List <LanguageKey> referencedLanguageKeys)
        {
            GoNorthProject project = await _cachedDbAccess.GetUserProject();

            List <LanguageKey> languageKeys = await _languageKeyDbAccess.GetLanguageKeysByGroupId(project.Id, flexFieldObject.Id);

            ExportSettings exportSettings = await _cachedDbAccess.GetExportSettings(project.Id);

            code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_Has_Referenced_LanguageKeys_Start, Placeholder_Has_Referenced_LanguageKeys_End, referencedLanguageKeys != null && referencedLanguageKeys.Any());
            code = ExportUtil.BuildPlaceholderRegex(Placeholder_ObjectName).Replace(code, flexFieldObject.Name);
            code = ExportUtil.BuildRangePlaceholderRegex(Placeholder_LanguageKeys_Start, Placeholder_LanguageKeys_End).Replace(code, m => {
                return(BuildLanguageKeyList(m.Groups[1].Value, languageKeys, exportSettings));
            });
            code = ExportUtil.BuildRangePlaceholderRegex(Placeholder_Referenced_LanguageKeys_Start, Placeholder_Referenced_LanguageKeys_End).Replace(code, m => {
                return(BuildLanguageKeyList(m.Groups[1].Value, referencedLanguageKeys, exportSettings));
            });

            return(code);
        }
Beispiel #6
0
        /// <summary>
        /// Collects the values for an export
        /// </summary>
        /// <param name="templateType">Template type</param>
        /// <param name="parsedTemplate">Parsed scriban template</param>
        /// <param name="scriptObject">Scriban script object to fill</param>
        /// <param name="data">Export Data</param>
        /// <returns>Task</returns>
        public override async Task CollectValues(TemplateType templateType, Template parsedTemplate, ScriptObject scriptObject, ExportObjectData data)
        {
            InputObject inputObject = data.ExportData[ExportConstants.ExportDataObject] as InputObject;

            if (inputObject == null)
            {
                return;
            }

            _languageKeyGenerator.SetErrorCollection(_errorCollection);


            GoNorthProject project = await _exportCachedDbAccess.GetUserProject();

            ExportSettings exportSettings = await _exportCachedDbAccess.GetExportSettings(project.Id);

            ExportClass exportObject = BuildExportObject(parsedTemplate, inputObject, exportSettings);

            scriptObject.Add(GetObjectKey(), exportObject);
            scriptObject.Add(ExportConstants.ScribanLanguageKeyName, _languageKeyGenerator);
            scriptObject.Add(FlexFieldAttributeListRenderer.AttributeListFunctionName, new FlexFieldAttributeListRenderer(_templatePlaceholderResolver, _exportCachedDbAccess, _defaultTemplateProvider, _errorCollection, data));
            AddAdditionalScriptObjectValues(templateType, parsedTemplate, scriptObject, data);
        }
        /// <summary>
        /// Collects the values for an export
        /// </summary>
        /// <param name="templateType">Template type</param>
        /// <param name="parsedTemplate">Parsed scriban template</param>
        /// <param name="scriptObject">Scriban script object to fill</param>
        /// <param name="data">Export Data</param>
        /// <returns>Task</returns>
        public override async Task CollectValues(TemplateType templateType, Template parsedTemplate, ScriptObject scriptObject, ExportObjectData data)
        {
            IFlexFieldExportable flexFieldObject = data.ExportData[ExportConstants.ExportDataObject] as IFlexFieldExportable;

            if (flexFieldObject == null)
            {
                return;
            }

            List <LanguageKey> referencedLanguageKeys = null;

            if (data.ExportData.ContainsKey(ExportConstants.ExportDataReferencedLanguageIds))
            {
                referencedLanguageKeys = data.ExportData[ExportConstants.ExportDataReferencedLanguageIds] as List <LanguageKey>;
            }

            if (referencedLanguageKeys == null)
            {
                referencedLanguageKeys = new List <LanguageKey>();
            }

            GoNorthProject project = await _exportCachedDbAccess.GetUserProject();

            List <LanguageKey> languageKeys = await _languageKeyDbAccess.GetLanguageKeysByGroupId(project.Id, flexFieldObject.Id);

            ExportSettings exportSettings = await _exportCachedDbAccess.GetExportSettings(project.Id);

            languageKeys = languageKeys.OrderBy(l => GetLanguageKeySortOrder(l, flexFieldObject)).ToList();

            ScribanExportLanguageFile languageFileData = new ScribanExportLanguageFile();

            languageFileData.Object                 = FlexFieldValueCollectorUtil.ConvertScribanFlexFieldObject(flexFieldObject, exportSettings, _errorCollection);
            languageFileData.LanguageKeys           = ConvertLanguageKeysToScriban(languageKeys, exportSettings);
            languageFileData.ReferencedLanguageKeys = ConvertLanguageKeysToScriban(referencedLanguageKeys, exportSettings);

            scriptObject.AddOrUpdate(LanguageObjectKey, languageFileData);
        }
        /// <summary>
        /// Maps the daily routine data of an npc
        /// </summary>
        /// <param name="cachedDbAccess">Gecachter Datenzugriff</param>
        /// <param name="dailyRoutineFunctionNameGenerator">Daily routine function name generator</param>
        /// <param name="npc">Npc</param>
        /// <param name="dailyRoutine">Daily routine data</param>
        /// <returns>Mapped daily routine events</returns>
        public static async Task <List <ScribanExportDailyRoutineEvent> > MapNpcDailyRoutineEvents(IExportCachedDbAccess cachedDbAccess, IDailyRoutineFunctionNameGenerator dailyRoutineFunctionNameGenerator, KortistoNpc npc, List <KortistoNpcDailyRoutineEvent> dailyRoutine)
        {
            if (dailyRoutine == null || !dailyRoutine.Any())
            {
                return(new List <ScribanExportDailyRoutineEvent>());
            }

            GoNorthProject project = await cachedDbAccess.GetUserProject();

            MiscProjectConfig projectConfig = await cachedDbAccess.GetMiscProjectConfig();

            ExportSettings exportSettings = await cachedDbAccess.GetExportSettings(project.Id);

            List <ScribanExportDailyRoutineEvent> mappedEvents = new List <ScribanExportDailyRoutineEvent>();

            foreach (KortistoNpcDailyRoutineEvent curEvent in dailyRoutine)
            {
                ScribanExportDailyRoutineEvent convertedEvent = await ConvertDailyRoutineEvent(dailyRoutineFunctionNameGenerator, npc, curEvent, project, projectConfig, exportSettings);

                mappedEvents.Add(convertedEvent);
            }

            return(mappedEvents);
        }
Beispiel #9
0
        /// <summary>
        /// Renders a dialog
        /// </summary>
        /// <param name="exportDialog">Export Dialog</param>
        /// <param name="npc">Npc to which the dialog belongs</param>
        /// <returns>Result of rendering the dialog</returns>
        public async Task <ExportDialogRenderResult> RenderDialog(ExportDialogData exportDialog, KortistoNpc npc)
        {
            _curProject = await _cachedDbAccess.GetDefaultProject();

            _exportSettings = await _cachedDbAccess.GetExportSettings(_curProject.Id);

            SetupStepRenderes();

            ExportDialogRenderResult renderResult = new ExportDialogRenderResult();

            renderResult.StartStepCode           = string.Empty;
            renderResult.AdditionalFunctionsCode = string.Empty;

            // Group to Functions
            ExportDialogFunction rootFunction = new ExportDialogFunction(exportDialog);

            AddNodesToFunction(rootFunction, exportDialog);
            List <ExportDialogFunction> additionalFunctions = ExtractAdditionalFunctions(exportDialog);

            // Render functions
            string startStepCode = await RenderDialogStepList(rootFunction.FunctionSteps, npc);

            string additionalFunctionsCode = string.Empty;

            foreach (ExportDialogFunction curAdditionalFunction in additionalFunctions)
            {
                additionalFunctionsCode += await RenderDialogFunction(curAdditionalFunction, npc);
            }

            ExportTemplate dialogStepTemplate = await _defaultTemplateProvider.GetDefaultTemplateByType(_curProject.Id, TemplateType.TaleDialogStep);

            renderResult.StartStepCode           = ExportUtil.BuildPlaceholderRegex(Placeholder_StepContent).Replace(dialogStepTemplate.Code, startStepCode);
            renderResult.AdditionalFunctionsCode = additionalFunctionsCode;

            return(renderResult);
        }
        /// <summary>
        /// Fills the Flex Field Placeholders
        /// </summary>
        /// <param name="code">Code to fill</param>
        /// <param name="flexFieldObject">Flex Field Object</param>
        /// <param name="objectType">Object Type</param>
        /// <param name="data">Export Data</param>
        /// <returns>Filled Code</returns>
        private async Task <string> FillFlexFieldPlaceholders(string code, IFlexFieldExportable flexFieldObject, string objectType, ExportObjectData data)
        {
            GoNorthProject project = await _exportCachedDbAccess.GetUserProject();

            ExportSettings exportSettings = await _exportCachedDbAccess.GetExportSettings(project.Id);

            HashSet <string> usedFields = new HashSet <string>();

            code = ExportUtil.BuildPlaceholderRegex(BuildFinalPlaceholder(Placeholder_Name)).Replace(code, flexFieldObject.Name);
            code = ExportUtil.RenderPlaceholderIfFuncTrue(code, BuildFinalPlaceholder(Placeholder_Field_Value_Equals_Start), BuildFinalPlaceholder(Placeholder_Field_Value_Equals_End), m => {
                string fieldName = m.Groups[1].Value;
                FlexField field  = FindFlexField(flexFieldObject, fieldName);
                if (field == null)
                {
                    return(false);
                }
                return(m.Groups[2].Value == field.Value);
            });
            code = ExportUtil.RenderPlaceholderIfFuncTrue(code, BuildFinalPlaceholder(Placeholder_Field_Value_NotEquals_Start), BuildFinalPlaceholder(Placeholder_Field_Value_NotEquals_End), m => {
                string fieldName = m.Groups[1].Value;
                FlexField field  = FindFlexField(flexFieldObject, fieldName);
                if (field == null)
                {
                    return(true);
                }
                return(m.Groups[2].Value != field.Value);
            });
            code = ExportUtil.RenderPlaceholderIfFuncTrue(code, BuildFinalPlaceholder(Placeholder_FlexField_HasField_Start), BuildFinalPlaceholder(Placeholder_FlexField_HasField_End), m => {
                string fieldName = m.Groups[1].Value;
                FlexField field  = FindFlexField(flexFieldObject, fieldName);
                return(field != null);
            });
            code = ExportUtil.RenderPlaceholderIfFuncTrue(code, BuildFinalPlaceholder(Placeholder_FlexField_NotHasField_Start), BuildFinalPlaceholder(Placeholder_FlexField_NotHasField_End), m => {
                string fieldName = m.Groups[1].Value;
                FlexField field  = FindFlexField(flexFieldObject, fieldName);
                return(field == null);
            });
            code = ExportUtil.RenderPlaceholderIfFuncTrue(code, BuildFinalPlaceholder(Placeholder_FlexField_FieldIsBlank_Start), BuildFinalPlaceholder(Placeholder_FlexField_FieldIsBlank_End), m => {
                string fieldName = m.Groups[1].Value;
                FlexField field  = FindFlexField(flexFieldObject, fieldName);
                if (field == null)
                {
                    return(true);
                }

                return(string.IsNullOrEmpty(field.Value));
            });
            code = ExportUtil.RenderPlaceholderIfFuncTrue(code, BuildFinalPlaceholder(Placeholder_FlexField_FieldIsNotBlank_Start), BuildFinalPlaceholder(Placeholder_FlexField_FieldIsNotBlank_End), m => {
                string fieldName = m.Groups[1].Value;
                FlexField field  = FindFlexField(flexFieldObject, fieldName);
                if (field == null)
                {
                    return(false);
                }

                return(!string.IsNullOrEmpty(field.Value));
            });
            code = await ExportUtil.BuildPlaceholderRegex(BuildFinalPlaceholder(Placeholder_Name_LangKey)).ReplaceAsync(code, async m => {
                // Run in function to only create language key if required
                string key = await _languageKeyGenerator.GetFlexFieldNameKey(flexFieldObject.Id, flexFieldObject.Name, objectType);
                return(key);
            });

            code = ExportUtil.BuildPlaceholderRegex(BuildFinalPlaceholder(Placeholder_Field_Value)).Replace(code, m => {
                string fieldName = m.Groups[1].Value;
                FlexField field  = FindFlexField(flexFieldObject, fieldName);
                if (field != null)
                {
                    usedFields.Add(field.Id);
                    return(EscapedFieldValue(field, exportSettings));
                }

                _errorCollection.AddErrorFlexField(fieldName, flexFieldObject.Name);
                return("<<" + flexFieldObject.Name + "[" + fieldName + "] MISSING>>");
            });
            code = ExportUtil.BuildPlaceholderRegex(BuildFinalPlaceholder(Placeholder_Field_LangKey)).Replace(code, m => {
                string fieldName = m.Groups[1].Value;
                FlexField field  = FindFlexField(flexFieldObject, fieldName);
                if (field != null && (field.FieldType == ExportConstants.FlexFieldType_String || field.FieldType == ExportConstants.FlexFieldType_Option))
                {
                    usedFields.Add(field.Id);
                    return(BuildFlexFieldLangKey(flexFieldObject, field, objectType));
                }

                _errorCollection.AddErrorFlexField(fieldName, flexFieldObject.Name);
                return("<<" + flexFieldObject.Name + "[" + fieldName + "] MISSING>>");
            });

            code = ExportUtil.RenderPlaceholderIfFuncTrue(code, BuildFinalPlaceholder(Placeholder_HasUnusedFields_Start), BuildFinalPlaceholder(Placeholder_HasUnusedFields_End), m => {
                return(flexFieldObject.Fields.Where(f => !usedFields.Contains(f.Id)).Any());
            });
            code = ExportUtil.BuildRangePlaceholderRegex(BuildFinalPlaceholder(Placeholder_UnusedFields_Start), BuildFinalPlaceholder(Placeholder_UnusedFields_End)).Replace(code, m => {
                List <FlexField> fieldsToUse = flexFieldObject.Fields.Where(f => !usedFields.Contains(f.Id)).ToList();
                return(BuildFlexFieldList(m.Groups[1].Value, fieldsToUse, flexFieldObject, exportSettings, objectType));
            });
            code = ExportUtil.BuildRangePlaceholderRegex(BuildFinalPlaceholder(Placeholder_AllFields_Start), BuildFinalPlaceholder(Placeholder_AllFields_End)).Replace(code, m => {
                return(BuildFlexFieldList(m.Groups[1].Value, flexFieldObject.Fields, flexFieldObject, exportSettings, objectType));
            });
            code = ExportUtil.BuildRangePlaceholderRegex(Placeholder_FlexFieldList_Start, Placeholder_FlexFieldList_End).Replace(code, m => {
                return(BuildFlexFieldList(m.Groups[1].Value, flexFieldObject.Fields, flexFieldObject, exportSettings, objectType));
            });
            code = await ExportUtil.BuildPlaceholderRegex(BuildFinalPlaceholder(Placeholder_UnusedFields), ExportConstants.ListIndentPrefix).ReplaceAsync(code, async m => {
                return(await RenderAttributeList(project, FilterInvalidFlexFields(flexFieldObject.Fields.Where(f => !usedFields.Contains(f.Id)).ToList()), data, m.Groups[1].Value));
            });

            code = await ExportUtil.BuildPlaceholderRegex(BuildFinalPlaceholder(Placeholder_AllFields), ExportConstants.ListIndentPrefix).ReplaceAsync(code, async m => {
                return(await RenderAttributeList(project, FilterInvalidFlexFields(flexFieldObject.Fields), data, m.Groups[1].Value));
            });


            return(code);
        }