local recipes = {
[1] = {name = "Backpack",
options = {
[1] = {name = "Leather Backpack", learned = false, learnStorage = 0, storage = {40000}, level = {1}, tries = 1, count = 1, id = 26516,
needed = {
[1] = {name = "Soft Leather", id = 27851, count = 5}
}
}
}
},
}
local modalId = 1005
local Type = {}
local Option = {}
local training = {
[40000] = "Basic Smithing",
[40001] = "Advanced Smithing",
[40002] = "Legendary Smithing",
[40003] = "Ammunition Smithing",
[40004] = "Amulet Smithing",
[40005] = "Axe Smithing",
[40006] = "Bow Smithing",
[40007] = "Claw Smithing",
[40008] = "Club Smithing",
[40009] = "Crossbow Smithing",
[40010] = "Dagger Smithing",
[40011] = "Gun Smithing",
[40012] = "Heavy Armor Smithing",
[40013] = "Heavy Boots Smithing",
[40014] = "Heavy Helmet Smithing",
[40015] = "Heavy Legs Smithing",
[40016] = "Light Armor Smithing",
[40017] = "Light Boots Smithing",
[40018] = "Light Helmet Smithing",
[40019] = "Light Legs Smithing",
[40020] = "Medium Armor Smithing",
[40021] = "Medium Boots Smithing",
[40022] = "Medium Helmet Smithing",
[40023] = "Medium Legs Smithing",
[40024] = "Ring Smithing",
[40025] = "Shield Smithing",
[40026] = "Spellbook Smithing",
[40027] = "Staff Smithing",
[40028] = "Sword Smithing",
}
-- Checks if player has the items required for a recipe - used for bringing the craft option back up after each craft if they have enough to do it again - enables quick, easy crafting
function Player:hasReq(recipe)
for i = 1, #recipe.needed do
if self:getItemCount(recipe.needed[i].id) < recipe.needed[i].count then
return false
end
end
return true
end
function Player:sendSortedWindow(type)
local window = ModalWindow(1011, recipes[type].name, "Expand the item you want to produce to view the requirements.\nYou are trained in the following specialties:\n")
local choices = 0
local temp = 0
for i = 40000, 40028 do
if self:getCSkill(training[i]) >= 10 then
temp = temp + 1
window:setMessage(window:getMessage() .. training[i] .. " (" .. self:getCSkill(training[i]) .. ")\n")
end
end
if temp == 0 then
window:setMessage(window:getMessage() .. "No specialty training.\n")
end
for i = 1, #recipes[type].options do
if (recipes[type].options[i].learned and self:getStorageValue(recipes[type].options[i].learnStorage) >= 1) or not recipes[type].options[i].learned then
if recipes[type].options[i].count > 1 then
window:addChoice(i, recipes[type].options[i].count .. " " .. recipes[type].options[i].name)
else
window:addChoice(i, recipes[type].options[i].name)
end
end
end
window:addButton(1, "Expand")
window:setDefaultEnterButton(1)
window:addButton(2, "Back")
window:setDefaultEscapeButton(2)
window:sendToPlayer(self)
return true
end
function Player:sendEquipmentWindow()
local window = ModalWindow(modalId, "Smithing", "Expand the type of item you want to craft to view the available items.\nYou are trained in the following specialties:\n")
local choices = 0
local temp = 0
for i = 40000, 40028 do
if self:getCSkill(training[i]) >= 10 then
temp = temp + 1
window:setMessage(window:getMessage() .. training[i] .. " (" .. self:getCSkill(training[i]) .. ")\n")
end
end
if temp == 0 then
window:setMessage(window:getMessage() .. "No specialty training.\n")
end
for i = 1, #recipes do
local t = false
for j = 1, #recipes[i].options do
if (recipes[i].options[j].learned and self:getStorageValue(recipes[i].options[j].learnStorage) >= 1) or not recipes[i].options[j].learned then
t = true
break
end
end
if t then
window:addChoice(i, recipes[i].name)
end
end
window:addButton(1, "Expand")
window:setDefaultEnterButton(1)
window:addButton(2, "Exit")
window:setDefaultEscapeButton(2)
window:sendToPlayer(self)
return true
end
function Player:sendERecipeWindow(type, option)
local window = ModalWindow(modalId + 1, recipes[type].options[option].name, "To produce this item, you need:\n")
for i = 1, #recipes[type].options[option].needed do
window:setMessage(window:getMessage() .. recipes[type].options[option].needed[i].count .. " " .. recipes[type].options[option].needed[i].name .. " (" .. self:getItemCount(recipes[type].options[option].needed[i].id) .. ")\n")
end
if recipes[type].options[option].storage then
for i = 1, #recipes[type].options[option].storage do
local lev = self:getCSkill(training[recipes[type].options[option].storage[i]])
window:setMessage(window:getMessage() .. training[recipes[type].options[option].storage[i]] .. " " .. recipes[type].options[option].level[i] .. " (" .. lev .. ")\n")
end
end
for i = 1, #recipes[type].options[option].needed do
if self:getItemCount(recipes[type].options[option].needed[i].id) < recipes[type].options[option].needed[i].count then
return window:addButton(2, "Back"), window:setDefaultEscapeButton(2), window:setDefaultEnterButton(2), window:sendToPlayer(self)
end
end
for i = 1, #recipes[type].options[option].storage do
if self:getCSkill(training[recipes[type].options[option].storage[i]]) < recipes[type].options[option].level[i] then
return window:addButton(2, "Back"), window:setDefaultEscapeButton(2), window:setDefaultEnterButton(2), window:sendToPlayer(self)
end
end
window:addButton(1, "Make It!")
window:setDefaultEnterButton(1)
window:addButton(2, "Back")
window:setDefaultEscapeButton(2)
window:sendToPlayer(self)
return true
end
function Player:sortedWindowChoice(windowId, buttonId, choiceId)
local p = self:getGuid()
if windowId == 1011 then
if buttonId == 1 then
Option[p] = choiceId
self:sendERecipeWindow(Type[p], Option[p])
return true
elseif buttonId == 2 then
self:sendEquipmentWindow()
return true
end
return false
end
return false
end
function Player:equipmentWindowChoice(windowId, buttonId, choiceId)
local p = self:getGuid()
if windowId == modalId then
if buttonId == 1 then
Type[p] = choiceId
self:sendSortedWindow(Type[p])
return true
else
Type[p] = nil
Option[p] = nil
return false
end
end
return false
end
function Player:eRecipeWindowChoice(windowId, buttonId, choiceId)
local p = self:getGuid()
if windowId == modalId + 1 then
if buttonId == 1 then
local rand = math.random(1,100000)
local half = false
local chance = (cSkills[training[recipes[Type[p]].options[Option[p]].storage[1]]].bonus * self:getCSkill(training[recipes[Type[p]].options[Option[p]].storage[1]])) * 100
if rand < chance * 1000 then
half = true
end
for i = 1, #recipes[Type[p]].options[Option[p]].needed do
if half then
self:removeItem(recipes[Type[p]].options[Option[p]].needed[i].id, math.ceil(recipes[Type[p]].options[Option[p]].needed[i].count / 2))
else
self:removeItem(recipes[Type[p]].options[Option[p]].needed[i].id, recipes[Type[p]].options[Option[p]].needed[i].count)
end
end
self:addItem(recipes[Type[p]].options[Option[p]].id, recipes[Type[p]].options[Option[p]].count)
if half then
self:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have crafted " .. recipes[Type[p]].options[Option[p]].count .. " " .. recipes[Type[p]].options[Option[p]].name .. " at half the usual cost!")
else
self:sendTextMessage(MESSAGE_INFO_DESCR, "You have crafted " .. recipes[Type[p]].options[Option[p]].count .. " " .. recipes[Type[p]].options[Option[p]].name .. "!")
end
for i = 1, #recipes[Type[p]].options[Option[p]].storage do
self:addCSkillTries(training[recipes[Type[p]].options[Option[p]].storage[i]], recipes[Type[p]].options[Option[p]].tries)
end
if recipes[Type[p]].options[Option[p]].set then
if self:getStorageValue(sets[recipes[Type[p]].options[Option[p]].set].pieces[recipes[Type[p]].options[Option[p]].piece].storage) ~= 1 then
self:setStorageValue(sets[recipes[Type[p]].options[Option[p]].set].pieces[recipes[Type[p]].options[Option[p]].piece].storage, 1)
end
local tempStore = true
for i = 1, #sets[recipes[Type[p]].options[Option[p]].set].pieces do
if self:getStorageValue(sets[recipes[Type[p]].options[Option[p]].set].pieces[recipes[Type[p]].options[Option[p]].piece].storage) ~= 1 then
tempStore = false
end
end
if tempStore then
self:addAchievement(sets[recipes[Type[p]].options[Option[p]].set].achievement)
end
end
return self:hasReq(recipes[Type[p]].options[Option[p]]) and self:sendERecipeWindow(Type[p], Option[p]) or self:sendSortedWindow(Type[p])
elseif buttonId == 2 then
self:sendSortedWindow(Type[p])
end
return false
end
return false
end