Advertisement
Alscara

alchemy

Jun 24th, 2015
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 29.12 KB | None | 0 0
  1. -- config
  2. local modalId = 1025
  3.  
  4. local bowl = {}
  5. local recipe = {}
  6. aingredients = {
  7.     [1] = {name = "bonelord eye", id = 5898, effects = {"potency", "regenhp"}, storages = {20000, 20001}, potency = 1, use = "use"},
  8.     [2] = {name = "honeycomb", id = 5902, effects = {"restorehp", "meleeup"}, storages = {20002, 20003}, potency = 3, use = "with"},
  9.     [3] = {name = "lizard scale", id = 5881, effects = {"regenmp", "duration"}, storages = {20004, 20005}, potency = 1, use = "use"},
  10.     [4] = {name = "green dragon scale", id = 5920, effects = {"absorball", "duration"}, storages = {20006, 20007}, potency = 4, use = "use"},
  11. }
  12.  
  13. aeffects = {
  14.     --["Name"] = {id = ID, fullname = "Full Name", dur = Duration, val = Value, p = IncreasePerPotency, label = "LabelOnItem"},
  15.     ["restorehp"] = {id = 1, fullname = "Restore Health", dur = 0, val = 100, p = 20, label = "Health"},
  16.     ["regenhp"] = {id = 2, fullname = "Regenerate Health", dur = 60, val = 10, p = 2, label = "HP Regen"},
  17.     ["potency"] = {id = 3, fullname = "Increase Potency", dur = 0, val = 1, p = 0, label = "Potency"},
  18.     ["meleeup"] = {id = 4, fullname = "Increase Melee Skill", dur = 60, val = 2, p = 1, label = "Melee"},
  19.     ["duration"] = {id = 5, fullname = "Increase Duration", dur = 0, val = 12, p = 0, label = "Duration"},
  20.     ["restoremp"] = {id = 6, fullname = "Restore Mana", dur = 0, val = 100, p = 20, label = "Mana"},
  21.     ["regenmp"] = {id = 7, fullname = "Regenerate Mana", dur = 60, val = 20, p = 4, label = "MP Regen"},
  22.     ["maxhp"] = {id = 8, fullname = "Fortify Health", dur = 60, val = 200, p = 25, label = "Max HP"},
  23.     ["maxmp"] = {id = 9, fullname = "Fortify Mana", dur = 60, val = 200, p = 25, label = "Max MP"},
  24.     ["speed"] = {id = 10, fullname = "Increase Speed", dur = 60, val = 40, p = 10, label = "Speed"},
  25.     ["fistup"] = {id = 11, fullname = "Increase Fist Skill", dur = 60, val = 2, p = 1, label = "Fist"},
  26.     ["distup"] = {id = 12, fullname = "Increase Distance Skill", dur = 60, val = 2, p = 1, label = "Distance"},
  27.     ["shieldup"] = {id = 13, fullname = "Increase Shielding Skill", dur = 60, val = 2, p = 1, label = "Shielding"},
  28.     ["fishup"] = {id = 14, fullname = "Increase Fishing Skill", dur = 60, val = 2, p = 1, label = "Fishing"},
  29.     ["resistfire"] = {id = 15, fullname = "Resist Fire", dur = 60, val = 5, p = 2, label = "Fire Percent"},
  30.     ["resistearth"] = {id = 16, fullname = "Resist Earth", dur = 60, val = 5, p = 2, label = "Earth Percent"},
  31.     ["resistenergy"] = {id = 17, fullname = "Resist Energy", dur = 60, val = 5, p = 2, label = "Energy Percent"},
  32.     ["resistice"] = {id = 18, fullname = "Resist Ice", dur = 60, val = 5, p = 2, label = "Ice Percent"},
  33.     ["resistdeath"] = {id = 19, fullname = "Resist Death", dur = 60, val = 5, p = 2, label = "Death Percent"},
  34.     ["resistholy"] = {id = 20, fullname = "Resist Holy", dur = 60, val = 5, p = 2, label = "Holy Percent"},
  35.     ["resistphysical"] = {id = 21, fullname = "Resist Physical", dur = 60, val = 5, p = 2, label = "Physical Percent"},
  36.     ["absorbfire"] = {id = 22, fullname = "Absorb Fire", dur = 60, val = 5, p = 2, label = "Fire Percent"},
  37.     ["absorbearth"] = {id = 23, fullname = "Absorb Earth", dur = 60, val = 5, p = 2, label = "Earth Percent"},
  38.     ["absorbenergy"] = {id = 24, fullname = "Absorb Energy", dur = 60, val = 5, p = 2, label = "Energy Percent"},
  39.     ["absorbice"] = {id = 25, fullname = "Absorb Ice", dur = 60, val = 5, p = 2, label = "Ice Percent"},
  40.     ["absorbdeath"] = {id = 26, fullname = "Absorb Death", dur = 60, val = 5, p = 2, label = "Death Percent"},
  41.     ["absorbholy"] = {id = 27, fullname = "Absorb Holy", dur = 60, val = 5, p = 2, label = "Holy Percent"},
  42.     ["absorbphysical"] = {id = 28, fullname = "Absorb Physical", dur = 60, val = 5, p = 2, label = "Physical Percent"},
  43.     ["reflectfire"] = {id = 29, fullname = "Reflect Fire", dur = 60, val = 5, p = 2, label = "Fire Percent"},
  44.     ["reflectearth"] = {id = 30, fullname = "Reflect Earth", dur = 60, val = 5, p = 2, label = "Earth Percent"},
  45.     ["reflectenergy"] = {id = 31, fullname = "Reflect Energy", dur = 60, val = 5, p = 2, label = "Energy Percent"},
  46.     ["reflectice"] = {id = 32, fullname = "Reflect Ice", dur = 60, val = 5, p = 2, label = "Ice Percent"},
  47.     ["reflectdeath"] = {id = 33, fullname = "Reflect Death", dur = 60, val = 5, p = 2, label = "Death Percent"},
  48.     ["reflectholy"] = {id = 34, fullname = "Reflect Holy", dur = 60, val = 5, p = 2, label = "Holy Percent"},
  49.     ["reflectphysical"] = {id = 35, fullname = "Reflect Physical", dur = 60, val = 5, p = 2, label = "Physical Percent"},
  50.     ["deflectfire"] = {id = 36, fullname = "Deflect Fire", dur = 60, val = 5, p = 2, label = "Fire Percent"},
  51.     ["deflectearth"] = {id = 37, fullname = "Deflect Earth", dur = 60, val = 5, p = 2, label = "Earth Percent"},
  52.     ["deflectenergy"] = {id = 38, fullname = "Deflect Energy", dur = 60, val = 5, p = 2, label = "Energy Percent"},
  53.     ["deflectice"] = {id = 39, fullname = "Deflect Ice", dur = 60, val = 5, p = 2, label = "Ice Percent"},
  54.     ["deflectdeath"] = {id = 40, fullname = "Deflect Death", dur = 60, val = 5, p = 2, label = "Death Percent"},
  55.     ["deflectholy"] = {id = 41, fullname = "Deflect Holy", dur = 60, val = 5, p = 2, label = "Holy Percent"},
  56.     ["deflectphysical"] = {id = 42, fullname = "Deflect Physical", dur = 60, val = 5, p = 2, label = "Physical Percent"},
  57.     ["resistall"] = {id = 43, fullname = "Resist All", dur = 60, val = 5, p = 2, label = "All Percent"},
  58.     ["absorball"] = {id = 44, fullname = "Absorb All", dur = 60, val = 5, p = 2, label = "All Percent"},
  59.     ["reflectall"] = {id = 45, fullname = "Reflect All", dur = 60, val = 5, p = 2, label = "All Percent"},
  60.     ["deflectall"] = {id = 46, fullname = "Deflect All", dur = 60, val = 5, p = 2, label = "All Percent"},
  61.     ["restoresoul"] = {id = 47, fullname = "Restore Soul", dur = 0, val = 10, p = 2, label = "Soul"},
  62.     ["regensoul"] = {id = 48, fullname = "Regenerate Soul", dur = 60, val = 2, p = 1, label = "Soul Regen"},
  63.     ["drown"] = {id = 49, fullname = "Waterbreathing", dur = 60, val = 100, p = 0, label = "Drown Percent"},
  64. }
  65.  
  66. arecipes = {
  67.     [1] = {name = "Potion of Double Heal", id = 42, effects = {"restorehp", "regenhp"}, values = {200, 10}, durations = {0, 60}, ingredients = {
  68.         [1] = {name = "bonelord eye", id = 5898, count = 1},
  69.         [2] = {name = "honeycomb", id = 5902, count = 2}
  70.     }, storage = 30000},
  71.     [2] = {name = "Potion of the Warrior", id = 43, effects = {"restorehp", "meleeup", "regenhp"}, values = {500, 5, 40}, durations = {0, 120, 120}, ingredients = {
  72.         [1] = {name = "bonelord eye", id = 5898, count = 7},
  73.         [2] = {name = "honeycomb", id = 5902, count = 2},
  74.         [3] = {name = "lizard scale", id = 5881, count = 4}
  75.     }, storage = 30001},
  76.     [3] = {name = "Potion of the Fire God", id = 50, effects = {"drown"}, values = {100}, durations = {120}, ingredients = {
  77.         [1] = {name = "bonelord eye", id = 5898, count = 1},
  78.         [2] = {name = "honeycomb", id = 5902, count = 2},
  79.         [3] = {name = "lizard scale", id = 5881, count = 1}
  80.     }, storage = 30002},
  81.     [4] = {name = "Potion of the Earth God", id = 51, effects = {"deflectall"}, values = {80}, durations = {120}, ingredients = {
  82.         [1] = {name = "bonelord eye", id = 5898, count = 1},
  83.         [2] = {name = "lizard scale", id = 5881, count = 1}
  84.     }, storage = 30003},
  85. }
  86.  
  87. apotions = {
  88.     [1] = {name = "Potion of Restore Health", id = 58, effect = "restorehp"},
  89.     [2] = {name = "Potion of Regenerate Health", id = 66, effect = "regenhp"},
  90.     [4] = {name = "Potion of Increase Melee Skill", id = 38, effect = "meleeup"},
  91.     [6] = {name = "Potion of Restore Mana", id = 39, effect = "restoremp"},
  92.     [7] = {name = "Potion of Regenerate Mana", id = 47, effect = "regenmp"},
  93.     [8] = {name = "Potion of Fortify Health", id = 74, effect = "maxhp"},
  94.     [9] = {name = "Potion of Fortify Mana", id = 55, effect = "maxmp"},
  95.     [10] = {name = "Potion of Speed", id = 37, effect = "speed"},
  96.     [11] = {name = "Potion of Increase Fist Skill", id = 46, effect = "fistup"},
  97.     [12] = {name = "Potion of Increase Distance Skill", id = 54, effect = "distup"},
  98.     [13] = {name = "Potion of Increase Shielding Skill", id = 61, effect = "shieldup"},
  99.     [14] = {name = "Potion of Increase Fishing Skill", id = 41, effect = "fishup"},
  100.     [15] = {name = "Potion of Resistance", id = 82, effect = "resistfire"},
  101.     [16] = {name = "Potion of Resistance", id = 36, effect = "resistearth"},
  102.     [17] = {name = "Potion of Resistance", id = 63, effect = "resistenergy"},
  103.     [18] = {name = "Potion of Resistance", id = 49, effect = "resistice"},
  104.     [19] = {name = "Potion of Resistance", id = 45, effect = "resistholy"},
  105.     [20] = {name = "Potion of Resistance", id = 43, effect = "resistdeath"},
  106.     [21] = {name = "Potion of Resistance", id = 62, effect = "resistphysical"},
  107.     [22] = {name = "Potion of Absorption", id = 90, effect = "absorbfire"},
  108.     [23] = {name = "Potion of Absorption", id = 44, effect = "absorbearth"},
  109.     [24] = {name = "Potion of Absorption", id = 71, effect = "absorbenergy"},
  110.     [25] = {name = "Potion of Absorption", id = 57, effect = "absorbice"},
  111.     [26] = {name = "Potion of Absorption", id = 53, effect = "absorbholy"},
  112.     [27] = {name = "Potion of Absorption", id = 51, effect = "absorbdeath"},
  113.     [28] = {name = "Potion of Absorption", id = 70, effect = "absorbphysical"},
  114.     [29] = {name = "Potion of Reflection", id = 98, effect = "reflectfire"},
  115.     [39] = {name = "Potion of Reflection", id = 52, effect = "reflectearth"},
  116.     [31] = {name = "Potion of Reflection", id = 79, effect = "reflectenergy"},
  117.     [32] = {name = "Potion of Reflection", id = 65, effect = "reflectice"},
  118.     [33] = {name = "Potion of Reflection", id = 61, effect = "reflectholy"},
  119.     [34] = {name = "Potion of Reflection", id = 59, effect = "reflectdeath"},
  120.     [35] = {name = "Potion of Reflection", id = 78, effect = "reflectphysical"},
  121.     [36] = {name = "Potion of Deflection", id = 106, effect = "deflectfire"},
  122.     [37] = {name = "Potion of Deflection", id = 60, effect = "deflectearth"},
  123.     [38] = {name = "Potion of Deflection", id = 87, effect = "deflectenergy"},
  124.     [39] = {name = "Potion of Deflection", id = 73, effect = "deflectice"},
  125.     [40] = {name = "Potion of Deflection", id = 69, effect = "deflectholy"},
  126.     [41] = {name = "Potion of Deflection", id = 67, effect = "deflectdeath"},
  127.     [42] = {name = "Potion of Deflection", id = 86, effect = "deflectphysical"},
  128.     [43] = {name = "Potion of Resistance", id = 91, effect = "resistall"},
  129.     [44] = {name = "Potion of Absorption", id = 76, effect = "absorball"},
  130.     [45] = {name = "Potion of Reflection", id = 77, effect = "reflectall"},
  131.     [46] = {name = "Potion of Deflection", id = 94, effect = "deflectall"},
  132.     [47] = {name = "Potion of Restore Soul", id = 102, effect = "restoresoul"},
  133.     [48] = {name = "Potion of Regenerate Soul", id = 110, effect = "regensoul"},
  134.     [49] = {name = "Potion of Waterbreathing", id = 89, effect = "drown"},
  135. }
  136.  
  137. apotionids = {
  138.     [58] = {name = "Potion of Restore Health", id = 1, effect = "restorehp"},
  139.     [66] = {name = "Potion of Regenerate Health", id = 2, effect = "regenhp"},
  140.     [38] = {name = "Potion of Increase Melee Skill", id = 4, effect = "meleeup"},
  141.     [39] = {name = "Potion of Restore Mana", id = 6, effect = "restoremp"},
  142.     [47] = {name = "Potion of Regenerate Mana", id = 7, effect = "regenmp"},
  143.     [74] = {name = "Potion of Fortify Health", id = 8, effect = "maxhp"},
  144.     [55] = {name = "Potion of Fortify Mana", id = 9, effect = "maxmp"},
  145.     [37] = {name = "Potion of Speed", id = 10, effect = "speed"},
  146.     [46] = {name = "Potion of Increase Fist Skill", id = 11, effect = "fistup"},
  147.     [54] = {name = "Potion of Increase Distance Skill", id = 12, effect = "distup"},
  148.     [61] = {name = "Potion of Increase Shielding Skill", id = 13, effect = "shieldup"},
  149.     [41] = {name = "Potion of Increase Fishing Skill", id = 14, effect = "fishup"},
  150.     [82] = {name = "Potion of Resistance", id = 15, effect = "resistfire"},
  151.     [36] = {name = "Potion of Resistance", id = 16, effect = "resistearth"},
  152.     [63] = {name = "Potion of Resistance", id = 17, effect = "resistenergy"},
  153.     [49] = {name = "Potion of Resistance", id = 18, effect = "resistice"},
  154.     [45] = {name = "Potion of Resistance", id = 19, effect = "resistholy"},
  155.     [43] = {name = "Potion of Resistance", id = 20, effect = "resistdeath"},
  156.     [62] = {name = "Potion of Resistance", id = 21, effect = "resistphysical"},
  157.     [90] = {name = "Potion of Absorption", id = 22, effect = "absorbfire"},
  158.     [44] = {name = "Potion of Absorption", id = 23, effect = "absorbearth"},
  159.     [71] = {name = "Potion of Absorption", id = 24, effect = "absorbenergy"},
  160.     [57] = {name = "Potion of Absorption", id = 25, effect = "absorbice"},
  161.     [53] = {name = "Potion of Absorption", id = 26, effect = "absorbholy"},
  162.     [51] = {name = "Potion of Absorption", id = 27, effect = "absorbdeath"},
  163.     [70] = {name = "Potion of Absorption", id = 28, effect = "absorbphysical"},
  164.     [98] = {name = "Potion of Reflection", id = 29, effect = "reflectfire"},
  165.     [52] = {name = "Potion of Reflection", id = 30, effect = "reflectearth"},
  166.     [79] = {name = "Potion of Reflection", id = 31, effect = "reflectenergy"},
  167.     [65] = {name = "Potion of Reflection", id = 32, effect = "reflectice"},
  168.     [61] = {name = "Potion of Reflection", id = 33, effect = "reflectholy"},
  169.     [59] = {name = "Potion of Reflection", id = 34, effect = "reflectdeath"},
  170.     [78] = {name = "Potion of Reflection", id = 35, effect = "reflectphysical"},
  171.     [106] = {name = "Potion of Deflection", id = 36, effect = "deflectfire"},
  172.     [60] = {name = "Potion of Deflection", id = 37, effect = "deflectearth"},
  173.     [87] = {name = "Potion of Deflection", id = 38, effect = "deflectenergy"},
  174.     [73] = {name = "Potion of Deflection", id = 39, effect = "deflectice"},
  175.     [69] = {name = "Potion of Deflection", id = 40, effect = "deflectholy"},
  176.     [67] = {name = "Potion of Deflection", id = 41, effect = "deflectdeath"},
  177.     [86] = {name = "Potion of Deflection", id = 42, effect = "deflectphysical"},
  178.     [91] = {name = "Potion of Resistance", id = 43, effect = "resistall"},
  179.     [76] = {name = "Potion of Absorption", id = 44, effect = "absorball"},
  180.     [77] = {name = "Potion of Reflection", id = 45, effect = "reflectall"},
  181.     [94] = {name = "Potion of Deflection", id = 46, effect = "deflectall"},
  182.     [102] = {name = "Potion of Restore Soul", id = 47, effect = "restoresoul"},
  183.     [110] = {name = "Potion of Regenerate Soul", id = 48, effect = "regensoul"},
  184.     [89] = {name = "Potion of Waterbreathing", id = 49, effect = "drown"},
  185. }
  186.  
  187. apotency = {
  188.     [0] = {prefix = ""},
  189.     [1] = {prefix = "Minor"},
  190.     [2] = {prefix = "Minor"},
  191.     [3] = {prefix = "Strong"},
  192.     [4] = {prefix = "Strong"},
  193.     [5] = {prefix = "Powerful"},
  194.     [6] = {prefix = "Powerful"},
  195.     [7] = {prefix = "Major"},
  196.     [8] = {prefix = "Major"},
  197.     [9] = {prefix = "Great"},
  198.     [10] = {prefix = "Great"},
  199. }
  200.  
  201. function Player:hasIn(recipe)
  202.     for i = 1, #arecipes[recipe].ingredients do
  203.         if self:getItemCount(arecipes[recipe].ingredients[i].id) < arecipes[recipe].ingredients[i].count then
  204.             return false
  205.         end
  206.     end
  207.     return true
  208. end
  209.  
  210. function Player:decidePotion()
  211.     local id = self:getGuid()
  212.     local ing = {}
  213.     local ingc = {}
  214.     local pm = false
  215.     local pmp = 0
  216.     for i = 1, #bowl[id] do
  217.         if not isInArray(ing, aingredients[bowl[id][i]].name) then
  218.             ing[#ing + 1] = aingredients[bowl[id][i]].name
  219.             ingc[aingredients[bowl[id][i]].name] = 1
  220.         else
  221.             ingc[aingredients[bowl[id][i]].name] = ingc[aingredients[bowl[id][i]].name] + 1
  222.         end
  223.     end
  224.     local cingc = 0
  225.     for k, v in pairs(ingc) do
  226.         cingc = cingc + 1
  227.     end
  228.     for i = 1, #arecipes do
  229.         if pmp > 0 then
  230.             break
  231.         end
  232.         if #arecipes[i].ingredients == cingc then
  233.             for j = 1, #arecipes[i].ingredients do
  234.                 if isInArray(ing, arecipes[i].ingredients[j].name) then
  235.                     if ingc[arecipes[i].ingredients[j].name] ~= arecipes[i].ingredients[j].count then
  236.                         pmp = 0
  237.                         break
  238.                     else
  239.                         pmp = i
  240.                     end
  241.                 else
  242.                     pmp = 0
  243.                     break
  244.                 end
  245.             end
  246.         end
  247.     end
  248.     if pmp ~= 0 then
  249.         pm = true
  250.     end
  251.     for i = 1, #arecipes do
  252.         for j = 1, #bowl[id] do
  253.            
  254.         end
  255.     end
  256.    
  257.     local e = {} -- effects
  258.     local n = {} -- effect counters
  259.     local f = 0 -- final effect
  260.     local pot = 1
  261.     local dur = 0
  262.     local ptemp = 0
  263.    
  264.     for i = 1, #bowl[id] do
  265.         ptemp = ptemp + aingredients[bowl[id][i]].potency
  266.     end
  267.     local function round(num, idp)
  268.         local mult = 10^(idp or 0)
  269.         return math.floor(num * mult + 0.5) / mult
  270.     end
  271.     ptemp = round(ptemp / #bowl[id], 0)
  272.    
  273.     pot = math.max(pot, ptemp)
  274.     for i = 1, #bowl[id] do
  275.         for j = 1, 2 do
  276.             if aingredients[bowl[id][i]].effects[j] ~= "potency" and aingredients[bowl[id][i]].effects[j] ~= "duration" then
  277.                 if not isInArray(e, aingredients[bowl[id][i]].effects[j]) then
  278.                     e[#e + 1] = aingredients[bowl[id][i]].effects[j]
  279.                     n[aeffects[aingredients[bowl[id][i]].effects[j]].id] = 1
  280.                 else
  281.                     n[aeffects[aingredients[bowl[id][i]].effects[j]].id] = n[aeffects[aingredients[bowl[id][i]].effects[j]].id] + 1
  282.                 end
  283.             else
  284.                 if aingredients[bowl[id][i]].effects[j] == "potency" then
  285.                     if pot < 10 then
  286.                         pot = pot + aeffects[aingredients[bowl[id][i]].effects[j]].val
  287.                         if pot > 10 then
  288.                             pot = 10
  289.                         end
  290.                     end
  291.                 end
  292.                 if aingredients[bowl[id][i]].effects[j] == "duration" then
  293.                     if dur < 60 then
  294.                         dur = dur + aeffects[aingredients[bowl[id][i]].effects[j]].val
  295.                     end
  296.                     if dur > 60 then
  297.                         dur = 60
  298.                     end
  299.                 end
  300.             end
  301.         end
  302.     end
  303.     local h = 0 -- highest
  304.     local s = 0 -- spot of highest
  305.     local t = {} -- ties
  306.     local ts = {} -- spots of ties
  307.     for k, v in pairs(n) do
  308.         if n[k] > h then
  309.             h = n[k]
  310.             s = k
  311.            
  312.         elseif n[k] == h then
  313.             t[#t + 1] = n[k]
  314.             ts[#ts + 1] = k
  315.         end
  316.         if #t > 0 then
  317.             for i = 1, #t do
  318.                 if #t < i then
  319.                     break
  320.                 end
  321.                 if h > t[i] then
  322.                     table.remove(t, i)
  323.                     table.remove(ts, i)
  324.                 end
  325.             end
  326.         end
  327.     end
  328.     if #t > 0 then
  329.         t[#t + 1] = h
  330.         ts[#ts + 1] = s
  331.         f = ts[math.random(1,#ts)]
  332.     else
  333.         f = s
  334.     end
  335.     local temp = 0
  336.     for k, v in pairs(aeffects) do
  337.         if aeffects[k].id == f then
  338.             temp = k
  339.         end
  340.     end
  341.     if pm then
  342.         if self:getStorageValue(arecipes[pmp].storage) ~= 1 then
  343.             self:setStorageValue(arecipes[pmp].storage, 1)
  344.             self:sendTextMessage(MESSAGE_INFO_DESCR, "You have discovered the recipe for the " .. arecipes[pmp].name .. "!")
  345.         end
  346.         local pass = {arecipes[pmp], pot, dur, 1}
  347.         return pass
  348.     else
  349.         local pass = {apotions[aeffects[temp].id], pot, dur, 2}
  350.         return pass
  351.     end
  352. end
  353.  
  354. function Player:sendAlchemyWindow()
  355.     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.")
  356.     local p = self:getGuid()
  357.     if bowl[p] == nil then
  358.         bowl[p] = {}
  359.     end
  360.     if recipe[p] == nil then
  361.         recipe[p] = {}
  362.     end
  363.     window:addChoice(1, "Ingredients")
  364.     window:addChoice(2, "Potions")
  365.  
  366.     window:addButton(1, "Enter")
  367.     window:setDefaultEnterButton(1)
  368.     window:addButton(2, "Exit")
  369.     window:setDefaultEscapeButton(2)
  370.     window:sendToPlayer(self)
  371.     return true
  372. end
  373.  
  374.  
  375. function Player:sendIngredientWindow()
  376.     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")
  377.     local temp = 0
  378.     local p = self:getGuid()
  379.     for i = 1, #aingredients do
  380.         if self:getItemCount(aingredients[i].id) >= 1 then
  381.             temp = temp + 1
  382.         end
  383.     end
  384.     if temp == 0 then
  385.         window:setMessage(window:getMessage() .. "You have no usable ingredients.\n")
  386.         window:setDefaultEnterButton(4)
  387.     else
  388.         window:addButton(1, "Info")
  389.         window:setDefaultEnterButton(1)
  390.         window:addButton(2, "Add")
  391.        
  392.     end
  393.     for i = 1, #aingredients do
  394.         if self:getItemCount(aingredients[i].id) then
  395.             local pc = self:getItemCount(aingredients[i].id)
  396.             local c = 0
  397.             for j = 1, #bowl[p] do
  398.                 if aingredients[bowl[p][j]].id == aingredients[i].id then
  399.                     c = c + 1
  400.                 end
  401.             end
  402.             if c > 0 then
  403.                 pc = pc - c
  404.             end
  405.             if pc < 0 then
  406.                 bowl[p] = {}
  407.                 pc = 0
  408.                 c = 0
  409.             end
  410.             if c > 0 or pc > 0 then
  411.                 window:addChoice(i, aingredients[i].name .. " (" .. pc .. ")")
  412.             end
  413.         end
  414.     end
  415.     if not bowl[p] then
  416.         bowl[p] = {}
  417.     end
  418.     if #bowl[p] == 0 then
  419.         window:setMessage(window:getMessage() .. "The bowl is empty\n")
  420.     else
  421.         window:setMessage(window:getMessage() .. "The bowl contains:\n")
  422.         window:addButton(3, "Bowl")
  423.     end
  424.     for i = 1, #bowl[p] do
  425.         window:setMessage(window:getMessage() .. aingredients[bowl[p][i]].name .. "\n")
  426.     end
  427.    
  428.    
  429.    
  430.    
  431.    
  432.     window:addButton(4, "Back")
  433.     window:setDefaultEscapeButton(4)
  434.     window:sendToPlayer(self)
  435.     return true
  436. end
  437.  
  438. function Player:sendInfoWindow(choice)
  439.     local window = ModalWindow(modalId + 2, aingredients[choice].name, "This ingredient has the following effects:\n")
  440.     local choices = 0
  441.     local temp = 0
  442.     for i = 1, 2 do
  443.         if self:getStorageValue(aingredients[choice].storages[i]) == 1 then
  444.             window:setMessage(window:getMessage() .. aeffects[aingredients[choice].effects[i]].fullname .. "\n")
  445.         else
  446.             window:setMessage(window:getMessage() .. "Unknown\n")
  447.         end
  448.     end
  449.     window:addButton(1, "Back")
  450.     window:setDefaultEnterButton(1)
  451.     window:setDefaultEscapeButton(1)
  452.     window:sendToPlayer(self)
  453.     return true
  454. end
  455.  
  456. function Player:sendPotionWindow()
  457.     local window = ModalWindow(modalId + 3, "Potion Recipes", "Choose from the recipes you know and view the requirements:\n")
  458.     local temp = 0
  459.     for i = 1, #arecipes do
  460.         if self:getStorageValue(arecipes[i].storage) == 1 then
  461.             window:addChoice(i, arecipes[i].name)
  462.             temp = temp + 1
  463.         end
  464.     end
  465.     if temp == 0 then
  466.         window:setMessage(window:getMessage() .. "You do not know any recipes.\n")
  467.         window:setDefaultEnterButton(2)
  468.     else
  469.         window:addButton(1, "Recipe")
  470.         window:setDefaultEnterButton(1)
  471.     end
  472.     window:addButton(2, "Back")
  473.     window:setDefaultEscapeButton(2)
  474.     window:sendToPlayer(self)
  475.     return true
  476. end
  477.  
  478. function Player:sendPotionRecipeWindow(choice)
  479.     local window = ModalWindow(modalId + 4, arecipes[choice].name, "To create this potion you need:\n")
  480.     local temp = true
  481.     local p = self:getGuid()
  482.     recipe[p] = choice
  483.     for i = 1, #arecipes[choice].ingredients do
  484.         window:setMessage(window:getMessage() .. arecipes[choice].ingredients[i].count .. " " .. arecipes[choice].ingredients[i].name .. " (" .. self:getItemCount(arecipes[choice].ingredients[i].id) .. ")\n")
  485.         if self:getItemCount(arecipes[choice].ingredients[i].id) < arecipes[choice].ingredients[i].count then
  486.             temp = false
  487.         end
  488.     end
  489.     if temp then
  490.         window:addButton(1, "Brew")
  491.         window:setDefaultEnterButton(1)
  492.     else
  493.         window:setDefaultEnterButton(2)
  494.     end
  495.    
  496.    
  497.     window:addButton(2, "Back")
  498.     window:setDefaultEscapeButton(2)
  499.     window:sendToPlayer(self)
  500.     return true
  501. end
  502.  
  503. function Player:sendBowlWindow()
  504.     local window = ModalWindow(modalId + 5, "Bowl", "The bowl contains the below items. You can remove items or try brewing a new potion.\n")
  505.     local p = self:getGuid()
  506.     window:addButton(3, "Back")
  507.     window:setDefaultEscapeButton(3)
  508.     if #bowl[p] > 0 then
  509.         window:addButton(1, "Brew")
  510.         window:addButton(2, "Remove")
  511.         window:setDefaultEnterButton(1)
  512.         for i = 1, #bowl[p] do
  513.             window:addChoice(i, aingredients[bowl[p][i]].name)
  514.         end
  515.     else
  516.         window:setMessage("The bowl is empty.")
  517.         window:setDefaultEnterButton(3)
  518.     end
  519.    
  520.    
  521.    
  522.     window:sendToPlayer(self)
  523.     return true
  524. end
  525.  
  526. function Player:alchemyWindowChoice(windowId, buttonId, choiceId)
  527.    
  528.     if choiceId == 255 then
  529.         choiceId = 1
  530.     end
  531.     if windowId == modalId then
  532.         if buttonId == 1 then
  533.             if choiceId == 1 then
  534.                 self:sendIngredientWindow()
  535.             elseif choiceId == 2 then
  536.                 self:sendPotionWindow()
  537.             end
  538.            
  539.             return true
  540.         elseif buttonId == 2 then
  541.             return false
  542.         end
  543.         return false
  544.     end
  545.     return false
  546. end
  547.  
  548. function Player:ingredientWindowChoice(windowId, buttonId, choiceId)
  549.     local p = self:getGuid()
  550.     if choiceId == 255 then
  551.         for i = 1, #aingredients do
  552.             if self:getItemCount(aingredients[i].id) >= 1 then
  553.                 choiceId = i
  554.                 break
  555.             end
  556.         end
  557.     end
  558.     if windowId == modalId + 1 then
  559.         if buttonId == 1 then
  560.             self:sendInfoWindow(choiceId)
  561.             return true
  562.         elseif buttonId == 2 then
  563.             local pc = self:getItemCount(aingredients[choiceId].id)
  564.             local c = 0
  565.             for j = 1, #bowl[p] do
  566.                 if aingredients[bowl[p][j]].id == aingredients[choiceId].id then
  567.                     c = c + 1
  568.                 end
  569.             end
  570.             if c > 0 then
  571.                 pc = pc - c
  572.             end
  573.             if pc > 0 then
  574.                 bowl[p][#bowl[p] + 1] = choiceId
  575.             end
  576.             self:sendIngredientWindow()
  577.             return true
  578.         elseif buttonId == 3 then
  579.             self:sendBowlWindow()
  580.             return true
  581.         elseif buttonId == 4 then
  582.             self:sendAlchemyWindow()
  583.             return true
  584.         end
  585.         return false
  586.     end
  587.     return false
  588. end
  589.  
  590.  
  591. function Player:potionWindowChoice(windowId, buttonId, choiceId)
  592.     if choiceId == 255 then
  593.         for i = 1, #arecipes do
  594.             if self:getStorageValue(arecipes[i].storage) == 1 then
  595.                 choiceId = i
  596.                 break
  597.             end
  598.         end
  599.     end
  600.     if windowId == modalId + 3 then
  601.         if buttonId == 1 then
  602.             self:sendPotionRecipeWindow(choiceId)
  603.             return true
  604.         elseif buttonId == 2 then
  605.             self:sendAlchemyWindow()
  606.             return true
  607.         end
  608.         return false
  609.     end
  610.     return false
  611. end
  612.  
  613. function Player:potionRecipeWindowChoice(windowId, buttonId, choiceId)
  614.     local p = self:getGuid()
  615.     if choiceId == 255 then
  616.         choiceId = 1
  617.     end
  618.     if windowId == modalId + 4 then
  619.         if buttonId == 1 then
  620.             local r = recipe[p]
  621.             for i = 1, #arecipes[r].ingredients do
  622.                 self:removeItem(arecipes[r].ingredients[i].id, arecipes[r].ingredients[i].count)
  623.             end
  624.             potion = self:addItem(2006, arecipes[r].id)
  625.             potion:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "Effects:\n")
  626.             for i = 1, #arecipes[r].effects do
  627.                 if i > 1 then
  628.                     potion:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, potion:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION) .. "\n")
  629.                 end
  630.                 if arecipes[r].durations[i] > 0 then
  631.                     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])
  632.                 else
  633.                     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])
  634.                 end
  635.             end
  636.             self:sendTextMessage(MESSAGE_INFO_DESCR, "You've brewed the " .. arecipes[r].name .. ".")
  637.             return self:hasIn(r) and self:sendPotionRecipeWindow(r) or self:sendPotionWindow()
  638.         elseif buttonId == 2 then
  639.             self:sendPotionWindow()
  640.             return true
  641.         end
  642.         return false
  643.     end
  644.     return false
  645. end
  646.  
  647. function Player:infoWindowChoice(windowId, buttonId, choiceId)
  648.     if choiceId == 255 then
  649.         choiceId = 1
  650.     end
  651.     if windowId == modalId + 2 then
  652.         if buttonId == 1 then
  653.             self:sendIngredientWindow()
  654.             return true
  655.         end
  656.         return false
  657.     end
  658.     return false
  659. end
  660.  
  661. function Player:bowlWindowChoice(windowId, buttonId, choiceId)
  662.     if choiceId == 255 then
  663.         choiceId = 1
  664.     end
  665.     if windowId == modalId + 5 then
  666.         if buttonId == 1 then
  667.             local p = self:decidePotion()
  668.             local id = self:getGuid()
  669.             for i = 1, #bowl[id] do
  670.                 if self:getStorageValue(aingredients[bowl[id][i]].storages[2]) ~= 1 then
  671.                     self:setStorageValue(aingredients[bowl[id][i]].storages[2], 1)
  672.                     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 .. "!")
  673.                 end
  674.                 if not self:removeItem(aingredients[bowl[id][i]].id, 1) then
  675.                     self:sendTextMessage(MESSAGE_STATUS_WARNING, "You removed one or more ingredients from your inventory before brewing.")
  676. bowl[id] = {}
  677.                     return false
  678.                 end
  679.             end
  680.            
  681.             local potion = self:addItem(2006, p[1].id)
  682.            
  683.             if p[4] == 2 then
  684.                 potion:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "Potency: " .. p[2] .. "\n")
  685.                 if aeffects[p[1].effect].dur > 0 then
  686.                     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])
  687.                 else
  688.                     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])
  689.                 end
  690.             else
  691.                 potion:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "Effects:\n")
  692.                 for i = 1, #p[1].effects do
  693.                     if i > 1 then
  694.                         potion:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, potion:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION) .. "\n")
  695.                     end
  696.                     if p[1].durations[i] > 0 then
  697.                         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])
  698.                     else
  699.                         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])
  700.                     end
  701.                 end
  702.             end
  703.             self:sendTextMessage(MESSAGE_INFO_DESCR, "You've brewed the " .. p[1].name .. ".")
  704.             bowl[id] = {}
  705.             self:sendIngredientWindow()
  706.         elseif buttonId == 2 then
  707.             local p = self:getGuid()
  708.             table.remove(bowl[p], choiceId)
  709.             self:sendBowlWindow()
  710.             return true
  711.         elseif buttonId == 3 then
  712.             self:sendIngredientWindow()
  713.             return true
  714.         end
  715.     end
  716.     return false
  717. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement