/// <summary> /// Creates a new <see cref="QuestScript"/> instance. /// </summary> /// <param name="questId">Quest id.</param> /// <param name="questName">Quest name.</param> /// <param name="luaScriptTable">Lua script table.</param> public QuestScript(int questId, string questName, LuaTable luaScriptTable) : base(luaScriptTable) { Id = questId; Name = questName; Title = LuaScriptHelper.GetValue <string>(luaScriptTable, QuestScriptConstants.Title); StartCharacter = LuaScriptHelper.GetValue <string>(luaScriptTable, QuestScriptConstants.StartCharacter); EndCharacter = LuaScriptHelper.GetValue <string>(luaScriptTable, QuestScriptConstants.EndCharacter); if (string.IsNullOrEmpty(EndCharacter)) { EndCharacter = StartCharacter; } Rewards = new QuestRewards(luaScriptTable, ScriptTable[QuestScriptConstants.Rewards] as LuaTable); StartRequirements = new QuestStartRequirements(ScriptTable[QuestScriptConstants.StartRequirements] as LuaTable); EndConditions = new QuestEndConditions(ScriptTable[QuestScriptConstants.EndConditions] as LuaTable); if (ScriptTable[QuestScriptConstants.Dialogs] is LuaTable dialogsTable) { BeginDialogs = GetDialogs(dialogsTable, QuestScriptConstants.BeginDialogs); AcceptedDialogs = GetDialogs(dialogsTable, QuestScriptConstants.BeginYesDialogs); DeclinedDialogs = GetDialogs(dialogsTable, QuestScriptConstants.BeginNoDialogs); CompletedDialogs = GetDialogs(dialogsTable, QuestScriptConstants.CompletedDialogs); NotFinishedDialogs = GetDialogs(dialogsTable, QuestScriptConstants.NotFinishedDialogs); } }
/// <summary> /// Creates a new <see cref="QuestEndConditions"/> instance. /// </summary> /// <param name="questEndConditionsTable"></param> internal QuestEndConditions(LuaTable questEndConditionsTable) { if (questEndConditionsTable[QuestScriptConstants.Items] is LuaTable items) { Items = items.Values.ToArray <LuaTable>().Select(x => new QuestItem { Id = LuaScriptHelper.GetValue <string>(x, "id"), Quantity = LuaScriptHelper.GetValue <int>(x, "quantity"), Sex = LuaScriptHelper.GetValue <GenderType>(x, "sex"), Remove = LuaScriptHelper.GetValue <bool>(x, "remove") }).ToList(); } if (questEndConditionsTable[QuestScriptConstants.Monsters] is LuaTable monsters) { Monsters = monsters.Values.ToArray <LuaTable>().Select(x => new QuestMonster { Id = LuaScriptHelper.GetValue <string>(x, "id"), Amount = LuaScriptHelper.GetValue <int>(x, "quantity") }).ToList(); } if (questEndConditionsTable[QuestScriptConstants.Patrols] is LuaTable patrols) { Patrols = patrols.Values.ToArray <LuaTable>().Select(x => new QuestPatrol { MapId = LuaScriptHelper.GetValue <string>(x, "map"), Left = LuaScriptHelper.GetValue <int>(x, "left"), Top = LuaScriptHelper.GetValue <int>(x, "top"), Right = LuaScriptHelper.GetValue <int>(x, "right"), Bottom = LuaScriptHelper.GetValue <int>(x, "bottom") }).ToList(); } }
/// <summary> /// Creates a new <see cref="QuestStartRequirements"/> instance. /// </summary> /// <param name="questStartRequirementsTable">Quest requirements lua table.</param> internal QuestStartRequirements(LuaTable questStartRequirementsTable) { MinLevel = LuaScriptHelper.GetValue <int>(questStartRequirementsTable, QuestScriptConstants.MinLevel); MaxLevel = LuaScriptHelper.GetValue <int>(questStartRequirementsTable, QuestScriptConstants.MaxLevel); Jobs = (questStartRequirementsTable[QuestScriptConstants.Job] as LuaTable)?.Values .ToArray <string>() .Select(x => (DefineJob.Job)Enum.Parse(typeof(DefineJob.Job), x)); PreviousQuestId = LuaScriptHelper.GetValue <string>(questStartRequirementsTable, QuestScriptConstants.PreviousQuest); }
/// <summary> /// Creates a new <see cref="QuestRewards"/> instance. /// </summary> /// <param name="mainLuaTable">Main script lua table.</param> /// <param name="questRewardsLuaTable">Quest script rewards section.</param> internal QuestRewards(LuaTable mainLuaTable, LuaTable questRewardsLuaTable) { _mainLuaTable = mainLuaTable; if (questRewardsLuaTable == null) { return; } object gold = questRewardsLuaTable[QuestScriptConstants.Gold]; if (gold != null) { if (gold is LuaTable goldRangeTable) { _minGold = LuaScriptHelper.GetValue <int>(goldRangeTable, QuestScriptConstants.Min); _maxGold = LuaScriptHelper.GetValue <int>(goldRangeTable, QuestScriptConstants.Max); } else { _gold = LuaScriptHelper.GetValue <int>(questRewardsLuaTable, QuestScriptConstants.Gold); } } object experience = questRewardsLuaTable[QuestScriptConstants.Experience]; if (experience != null) { if (experience is LuaTable experienceRangeTable) { _minExperience = LuaScriptHelper.GetValue <long>(experienceRangeTable, QuestScriptConstants.Min); _maxExperience = LuaScriptHelper.GetValue <long>(experienceRangeTable, QuestScriptConstants.Max); } else { _experience = LuaScriptHelper.GetValue <long>(questRewardsLuaTable, QuestScriptConstants.Experience); } } if (questRewardsLuaTable[QuestScriptConstants.Items] is LuaTable items) { Items = items.Values.ToArray <LuaTable>().Select(x => new QuestItem { Id = LuaScriptHelper.GetValue <string>(x, "id"), Quantity = LuaScriptHelper.GetValue <int>(x, "quantity"), Sex = LuaScriptHelper.GetValue <GenderType>(x, "sex"), Refine = LuaScriptHelper.GetValue <byte>(x, "refine"), Element = LuaScriptHelper.GetValue <ElementType>(x, "element"), ElementRefine = LuaScriptHelper.GetValue <byte>(x, "element_refine") }).ToList(); } _rewardJob = LuaScriptHelper.GetValue <DefineJob.Job>(questRewardsLuaTable, QuestScriptConstants.Job); _rewardJobFunction = mainLuaTable[QuestScriptHooksConstants.ChangeJobReward] as LuaFunction; }