Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- config
- local modalId = 1025
- local bowl = {}
- local recipe = {}
- aingredients = {
- [1] = {name = "bonelord eye", id = 5898, effects = {"potency", "regenhp"}, storages = {20000, 20001}, potency = 1, use = "use"},
- [2] = {name = "honeycomb", id = 5902, effects = {"restorehp", "meleeup"}, storages = {20002, 20003}, potency = 3, use = "with"},
- [3] = {name = "lizard scale", id = 5881, effects = {"regenmp", "duration"}, storages = {20004, 20005}, potency = 1, use = "use"},
- [4] = {name = "green dragon scale", id = 5920, effects = {"absorball", "duration"}, storages = {20006, 20007}, potency = 4, use = "use"},
- }
- aeffects = {
- --["Name"] = {id = ID, fullname = "Full Name", dur = Duration, val = Value, p = IncreasePerPotency, label = "LabelOnItem"},
- ["restorehp"] = {id = 1, fullname = "Restore Health", dur = 0, val = 100, p = 20, label = "Health"},
- ["regenhp"] = {id = 2, fullname = "Regenerate Health", dur = 60, val = 10, p = 2, label = "HP Regen"},
- ["potency"] = {id = 3, fullname = "Increase Potency", dur = 0, val = 1, p = 0, label = "Potency"},
- ["meleeup"] = {id = 4, fullname = "Increase Melee Skill", dur = 60, val = 2, p = 1, label = "Melee"},
- ["duration"] = {id = 5, fullname = "Increase Duration", dur = 0, val = 12, p = 0, label = "Duration"},
- ["restoremp"] = {id = 6, fullname = "Restore Mana", dur = 0, val = 100, p = 20, label = "Mana"},
- ["regenmp"] = {id = 7, fullname = "Regenerate Mana", dur = 60, val = 20, p = 4, label = "MP Regen"},
- ["maxhp"] = {id = 8, fullname = "Fortify Health", dur = 60, val = 200, p = 25, label = "Max HP"},
- ["maxmp"] = {id = 9, fullname = "Fortify Mana", dur = 60, val = 200, p = 25, label = "Max MP"},
- ["speed"] = {id = 10, fullname = "Increase Speed", dur = 60, val = 40, p = 10, label = "Speed"},
- ["fistup"] = {id = 11, fullname = "Increase Fist Skill", dur = 60, val = 2, p = 1, label = "Fist"},
- ["distup"] = {id = 12, fullname = "Increase Distance Skill", dur = 60, val = 2, p = 1, label = "Distance"},
- ["shieldup"] = {id = 13, fullname = "Increase Shielding Skill", dur = 60, val = 2, p = 1, label = "Shielding"},
- ["fishup"] = {id = 14, fullname = "Increase Fishing Skill", dur = 60, val = 2, p = 1, label = "Fishing"},
- ["resistfire"] = {id = 15, fullname = "Resist Fire", dur = 60, val = 5, p = 2, label = "Fire Percent"},
- ["resistearth"] = {id = 16, fullname = "Resist Earth", dur = 60, val = 5, p = 2, label = "Earth Percent"},
- ["resistenergy"] = {id = 17, fullname = "Resist Energy", dur = 60, val = 5, p = 2, label = "Energy Percent"},
- ["resistice"] = {id = 18, fullname = "Resist Ice", dur = 60, val = 5, p = 2, label = "Ice Percent"},
- ["resistdeath"] = {id = 19, fullname = "Resist Death", dur = 60, val = 5, p = 2, label = "Death Percent"},
- ["resistholy"] = {id = 20, fullname = "Resist Holy", dur = 60, val = 5, p = 2, label = "Holy Percent"},
- ["resistphysical"] = {id = 21, fullname = "Resist Physical", dur = 60, val = 5, p = 2, label = "Physical Percent"},
- ["absorbfire"] = {id = 22, fullname = "Absorb Fire", dur = 60, val = 5, p = 2, label = "Fire Percent"},
- ["absorbearth"] = {id = 23, fullname = "Absorb Earth", dur = 60, val = 5, p = 2, label = "Earth Percent"},
- ["absorbenergy"] = {id = 24, fullname = "Absorb Energy", dur = 60, val = 5, p = 2, label = "Energy Percent"},
- ["absorbice"] = {id = 25, fullname = "Absorb Ice", dur = 60, val = 5, p = 2, label = "Ice Percent"},
- ["absorbdeath"] = {id = 26, fullname = "Absorb Death", dur = 60, val = 5, p = 2, label = "Death Percent"},
- ["absorbholy"] = {id = 27, fullname = "Absorb Holy", dur = 60, val = 5, p = 2, label = "Holy Percent"},
- ["absorbphysical"] = {id = 28, fullname = "Absorb Physical", dur = 60, val = 5, p = 2, label = "Physical Percent"},
- ["reflectfire"] = {id = 29, fullname = "Reflect Fire", dur = 60, val = 5, p = 2, label = "Fire Percent"},
- ["reflectearth"] = {id = 30, fullname = "Reflect Earth", dur = 60, val = 5, p = 2, label = "Earth Percent"},
- ["reflectenergy"] = {id = 31, fullname = "Reflect Energy", dur = 60, val = 5, p = 2, label = "Energy Percent"},
- ["reflectice"] = {id = 32, fullname = "Reflect Ice", dur = 60, val = 5, p = 2, label = "Ice Percent"},
- ["reflectdeath"] = {id = 33, fullname = "Reflect Death", dur = 60, val = 5, p = 2, label = "Death Percent"},
- ["reflectholy"] = {id = 34, fullname = "Reflect Holy", dur = 60, val = 5, p = 2, label = "Holy Percent"},
- ["reflectphysical"] = {id = 35, fullname = "Reflect Physical", dur = 60, val = 5, p = 2, label = "Physical Percent"},
- ["deflectfire"] = {id = 36, fullname = "Deflect Fire", dur = 60, val = 5, p = 2, label = "Fire Percent"},
- ["deflectearth"] = {id = 37, fullname = "Deflect Earth", dur = 60, val = 5, p = 2, label = "Earth Percent"},
- ["deflectenergy"] = {id = 38, fullname = "Deflect Energy", dur = 60, val = 5, p = 2, label = "Energy Percent"},
- ["deflectice"] = {id = 39, fullname = "Deflect Ice", dur = 60, val = 5, p = 2, label = "Ice Percent"},
- ["deflectdeath"] = {id = 40, fullname = "Deflect Death", dur = 60, val = 5, p = 2, label = "Death Percent"},
- ["deflectholy"] = {id = 41, fullname = "Deflect Holy", dur = 60, val = 5, p = 2, label = "Holy Percent"},
- ["deflectphysical"] = {id = 42, fullname = "Deflect Physical", dur = 60, val = 5, p = 2, label = "Physical Percent"},
- ["resistall"] = {id = 43, fullname = "Resist All", dur = 60, val = 5, p = 2, label = "All Percent"},
- ["absorball"] = {id = 44, fullname = "Absorb All", dur = 60, val = 5, p = 2, label = "All Percent"},
- ["reflectall"] = {id = 45, fullname = "Reflect All", dur = 60, val = 5, p = 2, label = "All Percent"},
- ["deflectall"] = {id = 46, fullname = "Deflect All", dur = 60, val = 5, p = 2, label = "All Percent"},
- ["restoresoul"] = {id = 47, fullname = "Restore Soul", dur = 0, val = 10, p = 2, label = "Soul"},
- ["regensoul"] = {id = 48, fullname = "Regenerate Soul", dur = 60, val = 2, p = 1, label = "Soul Regen"},
- ["drown"] = {id = 49, fullname = "Waterbreathing", dur = 60, val = 100, p = 0, label = "Drown Percent"},
- }
- arecipes = {
- [1] = {name = "Potion of Double Heal", id = 42, effects = {"restorehp", "regenhp"}, values = {200, 10}, durations = {0, 60}, ingredients = {
- [1] = {name = "bonelord eye", id = 5898, count = 1},
- [2] = {name = "honeycomb", id = 5902, count = 2}
- }, storage = 30000},
- [2] = {name = "Potion of the Warrior", id = 43, effects = {"restorehp", "meleeup", "regenhp"}, values = {500, 5, 40}, durations = {0, 120, 120}, ingredients = {
- [1] = {name = "bonelord eye", id = 5898, count = 7},
- [2] = {name = "honeycomb", id = 5902, count = 2},
- [3] = {name = "lizard scale", id = 5881, count = 4}
- }, storage = 30001},
- [3] = {name = "Potion of the Fire God", id = 50, effects = {"drown"}, values = {100}, durations = {120}, ingredients = {
- [1] = {name = "bonelord eye", id = 5898, count = 1},
- [2] = {name = "honeycomb", id = 5902, count = 2},
- [3] = {name = "lizard scale", id = 5881, count = 1}
- }, storage = 30002},
- [4] = {name = "Potion of the Earth God", id = 51, effects = {"deflectall"}, values = {80}, durations = {120}, ingredients = {
- [1] = {name = "bonelord eye", id = 5898, count = 1},
- [2] = {name = "lizard scale", id = 5881, count = 1}
- }, storage = 30003},
- }
- apotions = {
- [1] = {name = "Potion of Restore Health", id = 58, effect = "restorehp"},
- [2] = {name = "Potion of Regenerate Health", id = 66, effect = "regenhp"},
- [4] = {name = "Potion of Increase Melee Skill", id = 38, effect = "meleeup"},
- [6] = {name = "Potion of Restore Mana", id = 39, effect = "restoremp"},
- [7] = {name = "Potion of Regenerate Mana", id = 47, effect = "regenmp"},
- [8] = {name = "Potion of Fortify Health", id = 74, effect = "maxhp"},
- [9] = {name = "Potion of Fortify Mana", id = 55, effect = "maxmp"},
- [10] = {name = "Potion of Speed", id = 37, effect = "speed"},
- [11] = {name = "Potion of Increase Fist Skill", id = 46, effect = "fistup"},
- [12] = {name = "Potion of Increase Distance Skill", id = 54, effect = "distup"},
- [13] = {name = "Potion of Increase Shielding Skill", id = 61, effect = "shieldup"},
- [14] = {name = "Potion of Increase Fishing Skill", id = 41, effect = "fishup"},
- [15] = {name = "Potion of Resistance", id = 82, effect = "resistfire"},
- [16] = {name = "Potion of Resistance", id = 36, effect = "resistearth"},
- [17] = {name = "Potion of Resistance", id = 63, effect = "resistenergy"},
- [18] = {name = "Potion of Resistance", id = 49, effect = "resistice"},
- [19] = {name = "Potion of Resistance", id = 45, effect = "resistholy"},
- [20] = {name = "Potion of Resistance", id = 43, effect = "resistdeath"},
- [21] = {name = "Potion of Resistance", id = 62, effect = "resistphysical"},
- [22] = {name = "Potion of Absorption", id = 90, effect = "absorbfire"},
- [23] = {name = "Potion of Absorption", id = 44, effect = "absorbearth"},
- [24] = {name = "Potion of Absorption", id = 71, effect = "absorbenergy"},
- [25] = {name = "Potion of Absorption", id = 57, effect = "absorbice"},
- [26] = {name = "Potion of Absorption", id = 53, effect = "absorbholy"},
- [27] = {name = "Potion of Absorption", id = 51, effect = "absorbdeath"},
- [28] = {name = "Potion of Absorption", id = 70, effect = "absorbphysical"},
- [29] = {name = "Potion of Reflection", id = 98, effect = "reflectfire"},
- [39] = {name = "Potion of Reflection", id = 52, effect = "reflectearth"},
- [31] = {name = "Potion of Reflection", id = 79, effect = "reflectenergy"},
- [32] = {name = "Potion of Reflection", id = 65, effect = "reflectice"},
- [33] = {name = "Potion of Reflection", id = 61, effect = "reflectholy"},
- [34] = {name = "Potion of Reflection", id = 59, effect = "reflectdeath"},
- [35] = {name = "Potion of Reflection", id = 78, effect = "reflectphysical"},
- [36] = {name = "Potion of Deflection", id = 106, effect = "deflectfire"},
- [37] = {name = "Potion of Deflection", id = 60, effect = "deflectearth"},
- [38] = {name = "Potion of Deflection", id = 87, effect = "deflectenergy"},
- [39] = {name = "Potion of Deflection", id = 73, effect = "deflectice"},
- [40] = {name = "Potion of Deflection", id = 69, effect = "deflectholy"},
- [41] = {name = "Potion of Deflection", id = 67, effect = "deflectdeath"},
- [42] = {name = "Potion of Deflection", id = 86, effect = "deflectphysical"},
- [43] = {name = "Potion of Resistance", id = 91, effect = "resistall"},
- [44] = {name = "Potion of Absorption", id = 76, effect = "absorball"},
- [45] = {name = "Potion of Reflection", id = 77, effect = "reflectall"},
- [46] = {name = "Potion of Deflection", id = 94, effect = "deflectall"},
- [47] = {name = "Potion of Restore Soul", id = 102, effect = "restoresoul"},
- [48] = {name = "Potion of Regenerate Soul", id = 110, effect = "regensoul"},
- [49] = {name = "Potion of Waterbreathing", id = 89, effect = "drown"},
- }
- apotionids = {
- [58] = {name = "Potion of Restore Health", id = 1, effect = "restorehp"},
- [66] = {name = "Potion of Regenerate Health", id = 2, effect = "regenhp"},
- [38] = {name = "Potion of Increase Melee Skill", id = 4, effect = "meleeup"},
- [39] = {name = "Potion of Restore Mana", id = 6, effect = "restoremp"},
- [47] = {name = "Potion of Regenerate Mana", id = 7, effect = "regenmp"},
- [74] = {name = "Potion of Fortify Health", id = 8, effect = "maxhp"},
- [55] = {name = "Potion of Fortify Mana", id = 9, effect = "maxmp"},
- [37] = {name = "Potion of Speed", id = 10, effect = "speed"},
- [46] = {name = "Potion of Increase Fist Skill", id = 11, effect = "fistup"},
- [54] = {name = "Potion of Increase Distance Skill", id = 12, effect = "distup"},
- [61] = {name = "Potion of Increase Shielding Skill", id = 13, effect = "shieldup"},
- [41] = {name = "Potion of Increase Fishing Skill", id = 14, effect = "fishup"},
- [82] = {name = "Potion of Resistance", id = 15, effect = "resistfire"},
- [36] = {name = "Potion of Resistance", id = 16, effect = "resistearth"},
- [63] = {name = "Potion of Resistance", id = 17, effect = "resistenergy"},
- [49] = {name = "Potion of Resistance", id = 18, effect = "resistice"},
- [45] = {name = "Potion of Resistance", id = 19, effect = "resistholy"},
- [43] = {name = "Potion of Resistance", id = 20, effect = "resistdeath"},
- [62] = {name = "Potion of Resistance", id = 21, effect = "resistphysical"},
- [90] = {name = "Potion of Absorption", id = 22, effect = "absorbfire"},
- [44] = {name = "Potion of Absorption", id = 23, effect = "absorbearth"},
- [71] = {name = "Potion of Absorption", id = 24, effect = "absorbenergy"},
- [57] = {name = "Potion of Absorption", id = 25, effect = "absorbice"},
- [53] = {name = "Potion of Absorption", id = 26, effect = "absorbholy"},
- [51] = {name = "Potion of Absorption", id = 27, effect = "absorbdeath"},
- [70] = {name = "Potion of Absorption", id = 28, effect = "absorbphysical"},
- [98] = {name = "Potion of Reflection", id = 29, effect = "reflectfire"},
- [52] = {name = "Potion of Reflection", id = 30, effect = "reflectearth"},
- [79] = {name = "Potion of Reflection", id = 31, effect = "reflectenergy"},
- [65] = {name = "Potion of Reflection", id = 32, effect = "reflectice"},
- [61] = {name = "Potion of Reflection", id = 33, effect = "reflectholy"},
- [59] = {name = "Potion of Reflection", id = 34, effect = "reflectdeath"},
- [78] = {name = "Potion of Reflection", id = 35, effect = "reflectphysical"},
- [106] = {name = "Potion of Deflection", id = 36, effect = "deflectfire"},
- [60] = {name = "Potion of Deflection", id = 37, effect = "deflectearth"},
- [87] = {name = "Potion of Deflection", id = 38, effect = "deflectenergy"},
- [73] = {name = "Potion of Deflection", id = 39, effect = "deflectice"},
- [69] = {name = "Potion of Deflection", id = 40, effect = "deflectholy"},
- [67] = {name = "Potion of Deflection", id = 41, effect = "deflectdeath"},
- [86] = {name = "Potion of Deflection", id = 42, effect = "deflectphysical"},
- [91] = {name = "Potion of Resistance", id = 43, effect = "resistall"},
- [76] = {name = "Potion of Absorption", id = 44, effect = "absorball"},
- [77] = {name = "Potion of Reflection", id = 45, effect = "reflectall"},
- [94] = {name = "Potion of Deflection", id = 46, effect = "deflectall"},
- [102] = {name = "Potion of Restore Soul", id = 47, effect = "restoresoul"},
- [110] = {name = "Potion of Regenerate Soul", id = 48, effect = "regensoul"},
- [89] = {name = "Potion of Waterbreathing", id = 49, effect = "drown"},
- }
- apotency = {
- [0] = {prefix = ""},
- [1] = {prefix = "Minor"},
- [2] = {prefix = "Minor"},
- [3] = {prefix = "Strong"},
- [4] = {prefix = "Strong"},
- [5] = {prefix = "Powerful"},
- [6] = {prefix = "Powerful"},
- [7] = {prefix = "Major"},
- [8] = {prefix = "Major"},
- [9] = {prefix = "Great"},
- [10] = {prefix = "Great"},
- }
- function Player:hasIn(recipe)
- for i = 1, #arecipes[recipe].ingredients do
- if self:getItemCount(arecipes[recipe].ingredients[i].id) < arecipes[recipe].ingredients[i].count then
- return false
- end
- end
- return true
- end
- function Player:decidePotion()
- local id = self:getGuid()
- local ing = {}
- local ingc = {}
- local pm = false
- local pmp = 0
- for i = 1, #bowl[id] do
- if not isInArray(ing, aingredients[bowl[id][i]].name) then
- ing[#ing + 1] = aingredients[bowl[id][i]].name
- ingc[aingredients[bowl[id][i]].name] = 1
- else
- ingc[aingredients[bowl[id][i]].name] = ingc[aingredients[bowl[id][i]].name] + 1
- end
- end
- local cingc = 0
- for k, v in pairs(ingc) do
- cingc = cingc + 1
- end
- for i = 1, #arecipes do
- if pmp > 0 then
- break
- end
- if #arecipes[i].ingredients == cingc then
- for j = 1, #arecipes[i].ingredients do
- if isInArray(ing, arecipes[i].ingredients[j].name) then
- if ingc[arecipes[i].ingredients[j].name] ~= arecipes[i].ingredients[j].count then
- pmp = 0
- break
- else
- pmp = i
- end
- else
- pmp = 0
- break
- end
- end
- end
- end
- if pmp ~= 0 then
- pm = true
- end
- for i = 1, #arecipes do
- for j = 1, #bowl[id] do
- end
- end
- local e = {} -- effects
- local n = {} -- effect counters
- local f = 0 -- final effect
- local pot = 1
- local dur = 0
- local ptemp = 0
- for i = 1, #bowl[id] do
- ptemp = ptemp + aingredients[bowl[id][i]].potency
- end
- local function round(num, idp)
- local mult = 10^(idp or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- ptemp = round(ptemp / #bowl[id], 0)
- pot = math.max(pot, ptemp)
- for i = 1, #bowl[id] do
- for j = 1, 2 do
- if aingredients[bowl[id][i]].effects[j] ~= "potency" and aingredients[bowl[id][i]].effects[j] ~= "duration" then
- if not isInArray(e, aingredients[bowl[id][i]].effects[j]) then
- e[#e + 1] = aingredients[bowl[id][i]].effects[j]
- n[aeffects[aingredients[bowl[id][i]].effects[j]].id] = 1
- else
- n[aeffects[aingredients[bowl[id][i]].effects[j]].id] = n[aeffects[aingredients[bowl[id][i]].effects[j]].id] + 1
- end
- else
- if aingredients[bowl[id][i]].effects[j] == "potency" then
- if pot < 10 then
- pot = pot + aeffects[aingredients[bowl[id][i]].effects[j]].val
- if pot > 10 then
- pot = 10
- end
- end
- end
- if aingredients[bowl[id][i]].effects[j] == "duration" then
- if dur < 60 then
- dur = dur + aeffects[aingredients[bowl[id][i]].effects[j]].val
- end
- if dur > 60 then
- dur = 60
- end
- end
- end
- end
- end
- local h = 0 -- highest
- local s = 0 -- spot of highest
- local t = {} -- ties
- local ts = {} -- spots of ties
- for k, v in pairs(n) do
- if n[k] > h then
- h = n[k]
- s = k
- elseif n[k] == h then
- t[#t + 1] = n[k]
- ts[#ts + 1] = k
- end
- if #t > 0 then
- for i = 1, #t do
- if #t < i then
- break
- end
- if h > t[i] then
- table.remove(t, i)
- table.remove(ts, i)
- end
- end
- end
- end
- if #t > 0 then
- t[#t + 1] = h
- ts[#ts + 1] = s
- f = ts[math.random(1,#ts)]
- else
- f = s
- end
- local temp = 0
- for k, v in pairs(aeffects) do
- if aeffects[k].id == f then
- temp = k
- end
- end
- if pm then
- if self:getStorageValue(arecipes[pmp].storage) ~= 1 then
- self:setStorageValue(arecipes[pmp].storage, 1)
- self:sendTextMessage(MESSAGE_INFO_DESCR, "You have discovered the recipe for the " .. arecipes[pmp].name .. "!")
- end
- local pass = {arecipes[pmp], pot, dur, 1}
- return pass
- else
- local pass = {apotions[aeffects[temp].id], pot, dur, 2}
- return pass
- end
- end
- function Player:sendAlchemyWindow()
- local window = ModalWindow(modalId, "Alchemy", "Choose from the options below. You can create potions that you know recipes for, or try to combine ingredients to create something new.")
- local p = self:getGuid()
- if bowl[p] == nil then
- bowl[p] = {}
- end
- if recipe[p] == nil then
- recipe[p] = {}
- end
- window:addChoice(1, "Ingredients")
- window:addChoice(2, "Potions")
- window:addButton(1, "Enter")
- window:setDefaultEnterButton(1)
- window:addButton(2, "Exit")
- window:setDefaultEscapeButton(2)
- window:sendToPlayer(self)
- return true
- end
- function Player:sendIngredientWindow()
- local window = ModalWindow(modalId + 1, "Ingredients", "Add ingredients to the bowl or check the info for your ingredients.\nOnly ingredients you're carrying will appear here.\n")
- local temp = 0
- local p = self:getGuid()
- for i = 1, #aingredients do
- if self:getItemCount(aingredients[i].id) >= 1 then
- temp = temp + 1
- end
- end
- if temp == 0 then
- window:setMessage(window:getMessage() .. "You have no usable ingredients.\n")
- window:setDefaultEnterButton(4)
- else
- window:addButton(1, "Info")
- window:setDefaultEnterButton(1)
- window:addButton(2, "Add")
- end
- for i = 1, #aingredients do
- if self:getItemCount(aingredients[i].id) then
- local pc = self:getItemCount(aingredients[i].id)
- local c = 0
- for j = 1, #bowl[p] do
- if aingredients[bowl[p][j]].id == aingredients[i].id then
- c = c + 1
- end
- end
- if c > 0 then
- pc = pc - c
- end
- if pc < 0 then
- bowl[p] = {}
- pc = 0
- c = 0
- end
- if c > 0 or pc > 0 then
- window:addChoice(i, aingredients[i].name .. " (" .. pc .. ")")
- end
- end
- end
- if not bowl[p] then
- bowl[p] = {}
- end
- if #bowl[p] == 0 then
- window:setMessage(window:getMessage() .. "The bowl is empty\n")
- else
- window:setMessage(window:getMessage() .. "The bowl contains:\n")
- window:addButton(3, "Bowl")
- end
- for i = 1, #bowl[p] do
- window:setMessage(window:getMessage() .. aingredients[bowl[p][i]].name .. "\n")
- end
- window:addButton(4, "Back")
- window:setDefaultEscapeButton(4)
- window:sendToPlayer(self)
- return true
- end
- function Player:sendInfoWindow(choice)
- local window = ModalWindow(modalId + 2, aingredients[choice].name, "This ingredient has the following effects:\n")
- local choices = 0
- local temp = 0
- for i = 1, 2 do
- if self:getStorageValue(aingredients[choice].storages[i]) == 1 then
- window:setMessage(window:getMessage() .. aeffects[aingredients[choice].effects[i]].fullname .. "\n")
- else
- window:setMessage(window:getMessage() .. "Unknown\n")
- end
- end
- window:addButton(1, "Back")
- window:setDefaultEnterButton(1)
- window:setDefaultEscapeButton(1)
- window:sendToPlayer(self)
- return true
- end
- function Player:sendPotionWindow()
- local window = ModalWindow(modalId + 3, "Potion Recipes", "Choose from the recipes you know and view the requirements:\n")
- local temp = 0
- for i = 1, #arecipes do
- if self:getStorageValue(arecipes[i].storage) == 1 then
- window:addChoice(i, arecipes[i].name)
- temp = temp + 1
- end
- end
- if temp == 0 then
- window:setMessage(window:getMessage() .. "You do not know any recipes.\n")
- window:setDefaultEnterButton(2)
- else
- window:addButton(1, "Recipe")
- window:setDefaultEnterButton(1)
- end
- window:addButton(2, "Back")
- window:setDefaultEscapeButton(2)
- window:sendToPlayer(self)
- return true
- end
- function Player:sendPotionRecipeWindow(choice)
- local window = ModalWindow(modalId + 4, arecipes[choice].name, "To create this potion you need:\n")
- local temp = true
- local p = self:getGuid()
- recipe[p] = choice
- for i = 1, #arecipes[choice].ingredients do
- window:setMessage(window:getMessage() .. arecipes[choice].ingredients[i].count .. " " .. arecipes[choice].ingredients[i].name .. " (" .. self:getItemCount(arecipes[choice].ingredients[i].id) .. ")\n")
- if self:getItemCount(arecipes[choice].ingredients[i].id) < arecipes[choice].ingredients[i].count then
- temp = false
- end
- end
- if temp then
- window:addButton(1, "Brew")
- window:setDefaultEnterButton(1)
- else
- window:setDefaultEnterButton(2)
- end
- window:addButton(2, "Back")
- window:setDefaultEscapeButton(2)
- window:sendToPlayer(self)
- return true
- end
- function Player:sendBowlWindow()
- local window = ModalWindow(modalId + 5, "Bowl", "The bowl contains the below items. You can remove items or try brewing a new potion.\n")
- local p = self:getGuid()
- window:addButton(3, "Back")
- window:setDefaultEscapeButton(3)
- if #bowl[p] > 0 then
- window:addButton(1, "Brew")
- window:addButton(2, "Remove")
- window:setDefaultEnterButton(1)
- for i = 1, #bowl[p] do
- window:addChoice(i, aingredients[bowl[p][i]].name)
- end
- else
- window:setMessage("The bowl is empty.")
- window:setDefaultEnterButton(3)
- end
- window:sendToPlayer(self)
- return true
- end
- function Player:alchemyWindowChoice(windowId, buttonId, choiceId)
- if choiceId == 255 then
- choiceId = 1
- end
- if windowId == modalId then
- if buttonId == 1 then
- if choiceId == 1 then
- self:sendIngredientWindow()
- elseif choiceId == 2 then
- self:sendPotionWindow()
- end
- return true
- elseif buttonId == 2 then
- return false
- end
- return false
- end
- return false
- end
- function Player:ingredientWindowChoice(windowId, buttonId, choiceId)
- local p = self:getGuid()
- if choiceId == 255 then
- for i = 1, #aingredients do
- if self:getItemCount(aingredients[i].id) >= 1 then
- choiceId = i
- break
- end
- end
- end
- if windowId == modalId + 1 then
- if buttonId == 1 then
- self:sendInfoWindow(choiceId)
- return true
- elseif buttonId == 2 then
- local pc = self:getItemCount(aingredients[choiceId].id)
- local c = 0
- for j = 1, #bowl[p] do
- if aingredients[bowl[p][j]].id == aingredients[choiceId].id then
- c = c + 1
- end
- end
- if c > 0 then
- pc = pc - c
- end
- if pc > 0 then
- bowl[p][#bowl[p] + 1] = choiceId
- end
- self:sendIngredientWindow()
- return true
- elseif buttonId == 3 then
- self:sendBowlWindow()
- return true
- elseif buttonId == 4 then
- self:sendAlchemyWindow()
- return true
- end
- return false
- end
- return false
- end
- function Player:potionWindowChoice(windowId, buttonId, choiceId)
- if choiceId == 255 then
- for i = 1, #arecipes do
- if self:getStorageValue(arecipes[i].storage) == 1 then
- choiceId = i
- break
- end
- end
- end
- if windowId == modalId + 3 then
- if buttonId == 1 then
- self:sendPotionRecipeWindow(choiceId)
- return true
- elseif buttonId == 2 then
- self:sendAlchemyWindow()
- return true
- end
- return false
- end
- return false
- end
- function Player:potionRecipeWindowChoice(windowId, buttonId, choiceId)
- local p = self:getGuid()
- if choiceId == 255 then
- choiceId = 1
- end
- if windowId == modalId + 4 then
- if buttonId == 1 then
- local r = recipe[p]
- for i = 1, #arecipes[r].ingredients do
- self:removeItem(arecipes[r].ingredients[i].id, arecipes[r].ingredients[i].count)
- end
- potion = self:addItem(2006, arecipes[r].id)
- potion:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "Effects:\n")
- for i = 1, #arecipes[r].effects do
- if i > 1 then
- potion:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, potion:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION) .. "\n")
- end
- if arecipes[r].durations[i] > 0 then
- potion:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, potion:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION) .. "[" .. aeffects[arecipes[r].effects[i]].fullname .. "]\n" .. aeffects[arecipes[r].effects[i]].label .. ": " .. arecipes[r].values[i] .. " | Duration: " .. arecipes[r].durations[i])
- else
- potion:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, potion:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION) .. "[" .. aeffects[arecipes[r].effects[i]].fullname .. "]\n" .. aeffects[arecipes[r].effects[i]].label .. ": " .. arecipes[r].values[i])
- end
- end
- self:sendTextMessage(MESSAGE_INFO_DESCR, "You've brewed the " .. arecipes[r].name .. ".")
- return self:hasIn(r) and self:sendPotionRecipeWindow(r) or self:sendPotionWindow()
- elseif buttonId == 2 then
- self:sendPotionWindow()
- return true
- end
- return false
- end
- return false
- end
- function Player:infoWindowChoice(windowId, buttonId, choiceId)
- if choiceId == 255 then
- choiceId = 1
- end
- if windowId == modalId + 2 then
- if buttonId == 1 then
- self:sendIngredientWindow()
- return true
- end
- return false
- end
- return false
- end
- function Player:bowlWindowChoice(windowId, buttonId, choiceId)
- if choiceId == 255 then
- choiceId = 1
- end
- if windowId == modalId + 5 then
- if buttonId == 1 then
- local p = self:decidePotion()
- local id = self:getGuid()
- for i = 1, #bowl[id] do
- if self:getStorageValue(aingredients[bowl[id][i]].storages[2]) ~= 1 then
- self:setStorageValue(aingredients[bowl[id][i]].storages[2], 1)
- self:sendTextMessage(MESSAGE_INFO_DESCR, "You have discovered the effect " .. aeffects[aingredients[bowl[id][i]].effects[2]].fullname .. " from the " .. aingredients[bowl[id][i]].name .. "!")
- end
- if not self:removeItem(aingredients[bowl[id][i]].id, 1) then
- self:sendTextMessage(MESSAGE_STATUS_WARNING, "You removed one or more ingredients from your inventory before brewing.")
- bowl[id] = {}
- return false
- end
- end
- local potion = self:addItem(2006, p[1].id)
- if p[4] == 2 then
- potion:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "Potency: " .. p[2] .. "\n")
- if aeffects[p[1].effect].dur > 0 then
- potion:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, potion:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION) .. aeffects[p[1].effect].label .. ": " .. aeffects[p[1].effect].val + aeffects[p[1].effect].p * p[2] .. " | Duration: " .. aeffects[p[1].effect].dur + p[3])
- else
- potion:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, potion:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION) .. aeffects[p[1].effect].label .. ": " .. aeffects[p[1].effect].val + aeffects[p[1].effect].p * p[2])
- end
- else
- potion:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "Effects:\n")
- for i = 1, #p[1].effects do
- if i > 1 then
- potion:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, potion:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION) .. "\n")
- end
- if p[1].durations[i] > 0 then
- potion:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, potion:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION) .. "[" .. aeffects[p[1].effects[i]].fullname .. "]\n" .. aeffects[p[1].effects[i]].label .. ": " .. p[1].values[i] .. " | Duration: " .. p[1].durations[i])
- else
- potion:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, potion:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION) .. "[" .. aeffects[p[1].effects[i]].fullname .. "]\n" .. aeffects[p[1].effects[i]].label .. ": " .. p[1].values[i])
- end
- end
- end
- self:sendTextMessage(MESSAGE_INFO_DESCR, "You've brewed the " .. p[1].name .. ".")
- bowl[id] = {}
- self:sendIngredientWindow()
- elseif buttonId == 2 then
- local p = self:getGuid()
- table.remove(bowl[p], choiceId)
- self:sendBowlWindow()
- return true
- elseif buttonId == 3 then
- self:sendIngredientWindow()
- return true
- end
- end
- return false
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement