Skip to content

Commit

Permalink
#165 add Special Assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
Urtgard committed Sep 27, 2024
1 parent 64e1dc8 commit f38e3ba
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 82 deletions.
1 change: 1 addition & 0 deletions Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ WQA.missionList = {}
WQA.itemList = {}
WQA.links = {}
WQA.Criterias = {}
WQA.Rewards = {}
12 changes: 9 additions & 3 deletions Criterias/AreaPoi.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
---@class WQAchievements
local WQA = WQAchievements

WQA.Criterias.AreaPoi = {}

local criteria = WQA.Criterias.AreaPoi
---@alias AreaPoiCriteria
---| { AreaPoiId: integer, MapId: integer}

local criteria = {}
criteria.list = {}
criteria.watched = {}

---@param poi AreaPoiCriteria
---@param rewardType RewardType
---@param emissary boolean?
function criteria:AddReward(poi, rewardType, reward, emissary)
local poiId = poi.AreaPoiId
local mapId = poi.MapId
Expand Down Expand Up @@ -86,3 +90,5 @@ function criteria:Check()
retry = retry
}
end

WQA.Criterias.AreaPoi = criteria
11 changes: 11 additions & 0 deletions Criterias/CriteriaType.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---@class WQAchievements
local WQA = WQAchievements

---@enum CriteriaType
local CriteriaType = {
AreaPoi = "AREA_POI"
}

WQA.Criterias = {
CriteriaType = CriteriaType
}
11 changes: 11 additions & 0 deletions DB/Data/WarWithin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,14 @@ data.achievements = {
}
}
}

-- Miscellaneous
data.miscellaneous = {
{
name = "Special Assignment",
criteriaType = "AREA_POI",
criteria = {
{ AreaPoiId = 7828, MapId = 2215 } -- Special Assignment: Rise of the Colossals
}
},
}
18 changes: 18 additions & 0 deletions Items/Miscellaneous.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---@class WQAchievements
local WQA = WQAchievements
local CriteriaType = WQA.Criterias.CriteriaType
local RewardType = WQA.Rewards.RewardType

---@param items { name: string, criteriaType: CriteriaType, criteria: AreaPoiCriteria[] }[]
function WQA:AddMiscellaneous(items)
for _, item in pairs(items) do
if item.criteriaType == CriteriaType.AreaPoi then
for _, criteria in pairs(item.criteria) do
WQA.Criterias.AreaPoi:AddReward(
criteria --[[@as AreaPoiCriteria]],
RewardType.Miscellaneous,
item.name)
end
end
end
end
94 changes: 94 additions & 0 deletions Rewards/Reward.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---@class WQAchievements
local WQA = WQAchievements
local RewardType = WQA.Rewards.RewardType


---@param rewardType RewardType
function WQA:AddReward(list, rewardType, reward, emissary)
local l = list
if emissary == true then
l.isEmissary = true
end
if not l.reward then
l.reward = {}
end


---@type table <RewardType, any>
l = l.reward
if rewardType == RewardType.Achievement then
if not l.achievement then
l.achievement = {}
end

for _, achievement in ipairs(l.achievement) do
if achievement.id == reward then
return
end
end

l.achievement[#l.achievement + 1] = { id = reward }
elseif rewardType == RewardType.Chance then
if not l.chance then
l.chance = {}
end

for _, v in pairs(l.chance) do
if v.id == reward then
return
end
end

l.chance[#l.chance + 1] = { id = reward }
elseif rewardType == RewardType.Custom then
if not l.custom then
l.custom = true
end
elseif rewardType == RewardType.Item then
if not l.item then
l.item = {}
end
for k, v in pairs(reward) do
l.item[k] = v
end
elseif rewardType == RewardType.Reputation then
if not l.reputation then
l.reputation = {}
end
for k, v in pairs(reward) do
l.reputation[k] = v
end
elseif rewardType == RewardType.Recipe then
l.recipe = reward
elseif rewardType == RewardType.CustomItem then
l.customItem = reward
elseif rewardType == RewardType.Currency then
if not l.currency then
l.currency = {}
end
for k, v in pairs(reward) do
l.currency[k] = v
end
elseif rewardType == RewardType.ProfessionSkillup then
l.professionSkillup = reward
elseif rewardType == RewardType.Gold then
l.gold = reward
elseif rewardType == RewardType.AzeriteTrait then
if not l.azeriteTraits then
l.azeriteTraits = {}
end
for k, v in pairs(l.azeriteTraits) do
if v.spellID == reward then
return
end
end
l.azeriteTraits[#l.azeriteTraits + 1] = { spellID = reward }
elseif rewardType == RewardType.Miscellaneous then
if not l[RewardType.Miscellaneous] then
---@type { [string]: boolean }
l[RewardType.Miscellaneous] = {}
end

table.insert(l[RewardType.Miscellaneous], reward)
end
end
22 changes: 22 additions & 0 deletions Rewards/RewardType.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---@class WQAchievements
local WQA = WQAchievements

---@enum RewardType
local RewardType = {
Achievement = "ACHIEVEMENT",
AzeriteTrait = "AZERITE_TRAIT",
Chance = "CHANCE",
Currency = "CURRENCY",
Custom = "CUSTOM",
CustomItem = "CUSTOM_ITEM",
Gold = "GOLD",
Item = "ITEM",
Miscellaneous = "MISCELLANEOUS",
ProfessionSkillup = "PROFESSION_SKILLUP",
Recipe = "RECIPE",
Reputation = "REPUTATION"
}

WQA.Rewards = {
RewardType = RewardType
}
85 changes: 6 additions & 79 deletions WQAchievements.lua
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ function WQA:CreateQuestList()
if (data.toys) then
self:AddToys(data.toys)
end

if (data.miscellaneous) then
self:AddMiscellaneous(data.miscellaneous)
end
end


Expand Down Expand Up @@ -436,85 +440,6 @@ function WQA:AddRewardToQuest(questID, rewardType, reward, emissary)
self:AddReward(l, rewardType, reward, emissary)
end

function WQA:AddReward(list, rewardType, reward, emissary)
local l = list
if emissary == true then
l.isEmissary = true
end
if not l.reward then
l.reward = {}
end
l = l.reward
if rewardType == "ACHIEVEMENT" then
if not l.achievement then
l.achievement = {}
end

for _, achievement in ipairs(l.achievement) do
if achievement.id == reward then
return
end
end

l.achievement[#l.achievement + 1] = { id = reward }
elseif rewardType == "CHANCE" then
if not l.chance then
l.chance = {}
end

for _, v in pairs(l.chance) do
if v.id == reward then
return
end
end

l.chance[#l.chance + 1] = { id = reward }
elseif rewardType == "CUSTOM" then
if not l.custom then
l.custom = true
end
elseif rewardType == "ITEM" then
if not l.item then
l.item = {}
end
for k, v in pairs(reward) do
l.item[k] = v
end
elseif rewardType == "REPUTATION" then
if not l.reputation then
l.reputation = {}
end
for k, v in pairs(reward) do
l.reputation[k] = v
end
elseif rewardType == "RECIPE" then
l.recipe = reward
elseif rewardType == "CUSTOM_ITEM" then
l.customItem = reward
elseif rewardType == "CURRENCY" then
if not l.currency then
l.currency = {}
end
for k, v in pairs(reward) do
l.currency[k] = v
end
elseif rewardType == "PROFESSION_SKILLUP" then
l.professionSkillup = reward
elseif rewardType == "GOLD" then
l.gold = reward
elseif rewardType == "AZERITE_TRAIT" then
if not l.azeriteTraits then
l.azeriteTraits = {}
end
for k, v in pairs(l.azeriteTraits) do
if v.spellID == reward then
return
end
end
l.azeriteTraits[#l.azeriteTraits + 1] = { spellID = reward }
end
end

function WQA:AddEmissaryReward(questID, rewardType, reward)
self:AddRewardToQuest(questID, rewardType, reward, true)
end
Expand Down Expand Up @@ -1683,6 +1608,8 @@ function WQA:GetRewardLinkByID(questId, key, value, i)
return nil
end
link = GetSpellLink(v[i].spellID)
elseif k == WQA.Rewards.RewardType.Miscellaneous then
link = table.concat(v, ", ")
end
return link
end
Expand Down
6 changes: 6 additions & 0 deletions WQAchievements.toc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ DB\Data\WarWithin.lua
DB\Expansions.lua
DB\Zones.lua

Criterias\CriteriaType.lua
Criterias\AreaPoi.lua

Rewards\RewardType.lua
Rewards\Reward.lua

Items\Miscellaneous.lua

Achievements.lua

Locales.lua
Expand Down

0 comments on commit f38e3ba

Please sign in to comment.