local reward = {
container = 5801,
commonItems = {
{id = 18559, amount = 1}, -- Adventurer's stone
{id = 2160, amount = 10}
},
vocationItems = {
-- Sorcerer
[14025] = {
{id = 7901, amount = 1}, -- Lightning Headband
{id = 8892, amount = 1}, -- Ethno Coat
{id = 7730, amount = 1}, -- blue legs
{id = 3982, amount = 1}, -- crocodile boots
{id = 2190, amount = 1}, -- Wand of vortex
{id = 2175, amount = 1} -- Spellbook
},
-- Druid
[14026] = {
{id = 7901, amount = 1}, -- Lightning Headband
{id = 8892, amount = 1}, -- Ethno Coat
{id = 7730, amount = 1}, -- blue legs
{id = 3982, amount = 1}, -- crocodile boots
{id = 2182, amount = 1}, -- Snakebite rod
{id = 2175, amount = 1} -- Spellbook
},
-- Paladin
[14027] = {
{id = 2491, amount = 1}, -- Crown Helmet
{id = 21706, amount = 1}, -- Goo Shell
{id = 7730, amount = 1}, -- blue legs
{id = 3982, amount = 1}, -- crocodile boots
{id = 2456, amount = 1}, -- Bow
{id = 2389, amount = 3}, -- Spear
{id = 40397, amount = 1}, -- Quiver
{id = 2544, amount = 60} -- Arrows
},
-- Knight
[14028] = {
{id = 2491, amount = 1}, -- Crown Helmet
{id = 21706, amount = 1}, -- Goo Shell
{id = 7730, amount = 1}, -- blue legs
{id = 3982, amount = 1}, -- crocodile boots
{id = 8602, amount = 1}, -- Jagged sword
{id = 8601, amount = 1}, -- steel axe
{id = 2439, amount = 1}, -- daramian mace
{id = 2509, amount = 1} -- Steel shield
}
}
}
local vocationReward = Action()
function vocationReward.onUse(player, item, fromPosition, itemEx, toPosition)
local vocationItems = reward.vocationItems[item.uid]
-- Check there is items for item.uid
if not vocationItems then
return true
end
-- Check quest storage
if player:getStorageValue(Storage.Quest.Dawnport.VocationReward) == 1 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The " .. item:getName() .. " is empty.")
return true
end
-- Calculate reward weight
local rewardsWeight = ItemType(reward.container):getWeight()
for i = 1, #vocationItems do
rewardsWeight = rewardsWeight + (ItemType(vocationItems[i].id):getWeight() * vocationItems[i].amount)
end
for i = 1, #reward.commonItems do
rewardsWeight = rewardsWeight + (ItemType(reward.commonItems[i].id):getWeight() * reward.commonItems[i].amount)
end
-- Check if enough weight capacity
if player:getFreeCapacity() < rewardsWeight then
player:sendTextMessage(
MESSAGE_EVENT_ADVANCE,
"You have found a " .. getItemName(reward.container) ..
". Weighing " .. (rewardsWeight / 100) .. " oz it is too heavy."
)
return true
end
-- Check if enough free slots
if player:getFreeBackpackSlots() < 1 then
player:sendTextMessage(
MESSAGE_EVENT_ADVANCE,
"You have found a " .. getItemName(reward.container) .. ". There is no room."
)
return true
end
-- Create reward container
local container = Game.createItem(reward.container)
-- Iterate in inverse order due on addItem/addItemEx by default its added at first index
-- Add common items
for i = #reward.commonItems, 1, -1 do
if reward.commonItems[i].text then
-- Create item to customize
local document = Game.createItem(reward.commonItems[i].id)
document:setAttribute(ITEM_ATTRIBUTE_TEXT, reward.commonItems[i].text)
container:addItemEx(document)
else
container:addItem(reward.commonItems[i].id, reward.commonItems[i].amount)
end
end
-- Add vocation items
for i = #vocationItems, 1, -1 do
container:addItem(vocationItems[i].id, vocationItems[i].amount)
end
-- Ensure reward was added properly to player
if player:addItemEx(container, false, CONST_SLOT_WHEREEVER) == RETURNVALUE_NOERROR then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a " .. container:getName() .. ".")
player:setStorageValue(Storage.Quest.Dawnport.VocationReward, 1)
end
return true
end
for index, value in pairs(reward.vocationItems) do
vocationReward:uid(index)
end
vocationReward:register()