FeLiPe-Eduardo

data\lib\core\attributes.lua

May 26th, 2021
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 37.71 KB | None | 0 0
  1. --[[ --------------------------------------------------------------------------------------------------------------------------------------
  2.         Author: Leo32
  3.         File: lib/attributes.lua
  4.        
  5.         This is the attributes & rarity library.
  6.         It contains all the functions used to roll 'rare', 'epic' or 'legendary' on items & apply the custom buff conditions (+Skill, +Max Health)
  7.         (!) Rolls that affect combat require the file creatureevents/scripts/attributes.lua
  8.        
  9.         Config:
  10.         stats {}
  11.  
  12.             stats[i].attribute
  13.             stats[i].base
  14.             stats[i].items
  15.        
  16.             [i] = {
  17.                 attribute = {
  18.                     name = 'Attack',
  19.                     rare = {1, 3}, -- Customize roll numbers here
  20.                     epic = {4, 6},
  21.                     legendary = {7, 10},
  22.                 },
  23.                 value = "Percent" -- What type of roll is it? Percent/Static/Damage/Duration
  24.                 base = ITEM_ATTRIBUTE_ATTACK, -- If attribute is a vanilla stat, it should have a default or 'base' amount, what is it? (rollBase)
  25.                 items = {
  26.                     2392, -- These are specifically targeted items, that can roll this attribute.
  27.                     2414
  28.                 }
  29.             },
  30. --]] --------------------------------------------------------------------------------------------------------------------------------------
  31.  
  32. local stats = { -- Define the attribute and their rolls
  33.     [1] = { -- Attack
  34.         attribute = {
  35.             name = 'Attack',
  36.             rare = {1, 3}, -- Customize roll numbers here
  37.             epic = {4, 6},
  38.             legendary = {7, 10},
  39.         },
  40.         value = "Static",
  41.         base = ITEM_ATTRIBUTE_ATTACK -- If attribute is a vanilla stat, it should have a default or 'base' amount, what is it?
  42.     },
  43.     [2] = { -- Defense
  44.         attribute = {
  45.             name = 'Defense',
  46.             rare = {1, 2},
  47.             epic = {3, 4},
  48.             legendary = {5, 6},
  49.         },
  50.         value = "Static",
  51.         base = ITEM_ATTRIBUTE_DEFENSE
  52.     },
  53.     [3] = { -- Extra Defense
  54.         attribute = {
  55.             name = 'Extra Defense',
  56.             rare = {1, 1},
  57.             epic = {2, 3},
  58.             legendary = {4, 5},
  59.         },
  60.         value = "Static",
  61.         base = ITEM_ATTRIBUTE_EXTRADEFENSE 
  62.     },
  63.     [4] = { -- Armor
  64.         attribute = {
  65.             name = 'Armor',
  66.             rare = {1, 1},
  67.             epic = {2, 3},
  68.             legendary = {4, 5},
  69.         },
  70.         value = "Static",
  71.         base = ITEM_ATTRIBUTE_ARMOR
  72.     },
  73.     [5] = { -- Accuracy
  74.         attribute = {
  75.             name = 'Accuracy',
  76.             rare = {1, 5},
  77.             epic = {6, 10},
  78.             legendary = {11, 15},
  79.         },
  80.         value = "Percent",
  81.         base = ITEM_ATTRIBUTE_HITCHANCE
  82.     },
  83.     [6] = { -- Range
  84.         attribute = {
  85.             name = 'Range',
  86.             rare = {1, 1},
  87.             epic = {2, 2},
  88.             legendary = {3, 3},
  89.         },
  90.         value = "Static",
  91.         base = ITEM_ATTRIBUTE_SHOOTRANGE
  92.     },
  93.     [7] = { -- Equipment with < 50 charges
  94.         attribute = {
  95.             name = 'Charges',
  96.             rare = {5, 10},
  97.             epic = {15, 20},
  98.             legendary = {31, 35},
  99.         },
  100.         value = "Static",
  101.         base = ITEM_ATTRIBUTE_CHARGES
  102.     },
  103.     [8] = { -- Equipment with >= 50 charges
  104.         attribute = {
  105.             name = 'Charges',
  106.             rare = {100, 250},
  107.             epic = {350, 500},
  108.             legendary = {1000, 2000},
  109.         },
  110.         value = "Static",
  111.         base = ITEM_ATTRIBUTE_CHARGES
  112.     },
  113.     [9] = { -- Time
  114.         attribute = {
  115.             name = 'Time',
  116.             rare = {300000, 300000},
  117.             epic = {900000, 900000},
  118.             legendary = {2700000, 2700000},
  119.         },
  120.         value = "Duration",
  121.         base = ITEM_ATTRIBUTE_DURATION
  122.     },
  123.     [10] = { -- Crit Chance
  124.         attribute = {
  125.             name = 'Crit Chance',
  126.             rare = {5, 10},
  127.             epic = {10, 15},
  128.             legendary = {16, 20},
  129.         },
  130.         value = "Percent",
  131.         items = { -- These are specifically targeted items, that can roll this attribute.
  132.             2136, -- Demonbone Amulet
  133.             21693,-- Horn
  134.             14327,-- Bronze Ring
  135.             11374 -- Beetle Necklace
  136.         }
  137.     },
  138.     [11] = { -- Crit Amount (Currently Unused)
  139.         attribute = {
  140.             name = 'Crit Amount',
  141.             rare = {10, 30},
  142.             epic = {35, 60},
  143.             legendary = {65, 100},
  144.         },
  145.         value = "Percent",
  146.     },
  147.     [12] = { -- Fire Damage
  148.         attribute = {
  149.             name = 'Enhanced Fire Damage',
  150.             rare = {15, 30},
  151.             epic = {30, 45},
  152.             legendary = {45, 60},
  153.         },
  154.         value = "Damage",
  155.         items = {
  156.             7386, -- Merc Sword
  157.             2392, -- Fire Sword
  158.             7430, -- Dragonbone Staff
  159.             2539, -- Phoenix Shield
  160.             2432, -- Fire Axe
  161.             8858, -- Elemental Bow
  162.             7402, -- Dragonslayer Sword
  163.             7453, -- Executioner
  164.             2414, -- Dragon Lance
  165.             2520, -- Demon Shield
  166.             8927, -- Dark Trinity Mace
  167.             7411, -- Ornamented Axe
  168.             11305,-- Drakinata
  169.             7382  -- Demonrage Sword
  170.         }
  171.     },
  172.     [13] = { -- Ice Damage
  173.         attribute = {
  174.             name = 'Enhanced Ice Damage',
  175.             rare = {10, 15},
  176.             epic = {15, 25},
  177.             legendary = {25, 35},
  178.         },
  179.         value = "Damage",
  180.         items = {
  181.             7386, -- Merc Sword
  182.             7453, -- Executioner
  183.             2445, -- Crystal Mace
  184.             7428, -- Bonebreaker
  185.             7407, -- Haunted Blade
  186.             7437, -- Sapphire Hammer
  187.             7387, -- Diamond Hammer
  188.             7455, -- Mythril Axe
  189.             21696,-- Icicle Bow
  190.             7390, -- Justice Seeker
  191.             21697,-- Runic Ice Shield
  192.             8858, -- Elemental Bow
  193.             7410, -- Queen's Sceptre
  194.             8927, -- Dark Trinity Mace
  195.             2534  -- Vampire Shield
  196.         }
  197.     },
  198.     [14] = { -- Energy Damage
  199.         attribute = {
  200.             name = 'Enhanced Energy Damage',
  201.             rare = {50, 75},
  202.             epic = {100, 125},
  203.             legendary = {200, 250},
  204.         },
  205.         value = "Damage",
  206.         items = {
  207.             7386, -- Merc Sword
  208.             7421, -- Onyx Flail
  209.             8858, -- Elemental Bow
  210.             7388, -- Vile Axe
  211.             7410, -- Queen's Sceptre
  212.             7404, -- Assassin Dagger
  213.             2414, -- Dragon Lance
  214.             2444, -- Hammer of Wrath
  215.             7402, -- Dragonslayer Sword
  216.             2514, -- Mastermind Shield
  217.             2542, -- Tempest Shield
  218.             8924, -- Hellforged Axe
  219.             7433, -- Ravenwing
  220.             2424, -- Silver Mace
  221.             8927, -- Dark Trinity Mace
  222.             7384, -- Mystic Blade
  223.             7382  -- Demonrage Sword
  224.         }
  225.     },
  226.     [15] = { -- Fire Resistance
  227.         attribute = {
  228.             name = 'Fire Resistance',
  229.             rare = {2, 3},
  230.             epic = {4, 6},
  231.             legendary = {7, 10},
  232.         },
  233.         value = "Percent",
  234.         items = {
  235.             2516, -- Dragon Shield
  236.             2520, -- Demon Shield
  237.             2539, -- Phoenix Shield
  238.             2519, -- Crown Shield
  239.             2491, -- Crown Helmet
  240.             2493, -- Demon Helmet
  241.             2494, -- Demon Armor
  242.             2495, -- Demon Legs
  243.             13756,-- Mage's Cap
  244.             2487, -- Crown Armor
  245.             7899, -- Magma Coat
  246.             8867, -- Dragon Robe
  247.             11356,-- Zaoan Robe
  248.             2488, -- Crown Legs
  249.             7894, -- Magma Legs
  250.             7891, -- Magma Boots
  251.             2492, -- Dragon Scale Mail
  252.             2498, -- Royal Helmet
  253.             2655, -- Red Robe
  254.             7900, -- Magma Monocle
  255.             2133, -- Ruby Necklace
  256.             8877, -- Lavos Armor
  257.             2508, -- Native Armor
  258.             2123 -- Ring of the Sky
  259.         }
  260.     },
  261.     [16] = { -- Ice Resistance
  262.         attributes = {
  263.             name = 'Ice Resistance',
  264.             rare = {2, 3},
  265.             epic = {4, 6},
  266.             legendary = {7, 10},
  267.         },
  268.         value = "Percent",
  269.         items = {
  270.             3973, -- Tusk Shield
  271.             7460, -- Norse Shield
  272.             21697,-- Runic Ice Shield
  273.             7461, -- Krimhorn Helmet
  274.             7462, -- Ragnir Helmet
  275.             7902, -- Glacier Mask
  276.             7463, -- Mammoth Fur Cape
  277.             7897, -- Glacier Robe
  278.             8878, -- Crystalline Armor
  279.             8887, -- Frozen Armor
  280.             7896, -- Glacier Kilt
  281.             21700,-- Icy Culotte
  282.             7457, -- Fur Boots
  283.             11117,-- Crystal Boots
  284.             7892, -- Glacier Shoes
  285.             7464, -- Mammoth Fur Shorts
  286.             2125, -- Crystal Necklace
  287.             2124  -- Crystal Ring
  288.         }
  289.     },
  290.     [17] = { -- Energy Resistance
  291.         attribute = {
  292.             name = 'Energy Resistance',
  293.             rare = {2, 3},
  294.             epic = {4, 6},
  295.             legendary = {7, 10},
  296.         },
  297.         value = "Percent",
  298.         items = {
  299.             2514, -- Mastermind Shield
  300.             2515, -- Guardian Shield
  301.             2528, -- Tower Shield
  302.             12644,-- Shield of Corruption
  303.             2535, -- Castle Shield
  304.             2475, -- Warrior Helmet
  305.             2497, -- Crusader Helmet
  306.             7901, -- Lightning Headband
  307.             2472, -- Magic Plate Armor
  308.             2476, -- Knight Helmet
  309.             2492, -- Dragon Scale Mail
  310.             7898, -- Lightning Robe
  311.             8871, -- Focus Cape
  312.             8879, -- Voltage Armor
  313.             11355,-- Spellweaver's Robe
  314.             12607,-- Elite Draken Mail
  315.             2477, -- Knight Legs
  316.             7895, -- Lightning Legs
  317.             23539,-- Mino Shield
  318.             2123, -- Ring of the Sky
  319.             2508, -- Native Armor
  320.             7893  -- Lightning Boots
  321.         }
  322.     },
  323.     [18] = { -- Earth Resistance
  324.         attribute = {
  325.             name = 'Earth Resistance',
  326.             rare = {2, 3},
  327.             epic = {4, 6},
  328.             legendary = {7, 10},
  329.         },
  330.         value = "Percent",
  331.         items = {
  332.             2518, -- Beholder Shield
  333.             2535, -- Castle Shield
  334.             6131, -- Tortoise Shield
  335.             15491,-- Carapace Shield
  336.             20090,-- Spike Shield
  337.             2540, -- Scarab Shield
  338.             2479, -- Strange Helmet
  339.             3971, -- Charmer's Tiara
  340.             3972, -- Beholder Helmet
  341.             7885, -- Terra Legs
  342.             7903, -- Terra Hood
  343.             2664, -- Wood Cape
  344.             7463, -- Mammoth Fur Cape
  345.             7884, -- Terra Mantle
  346.             8869, -- Greenwood Coat
  347.             8880, -- Swamplair Armor
  348.             3982, -- Crocodile Boots
  349.             2123, -- Ring of the Sky
  350.             2135, -- Scarab Amulet
  351.             7886, -- Terra Boots
  352.             2508, -- Native Armor
  353.             21706, -- Goo Shell
  354.             38989 -- Lion Shield
  355.         }
  356.     },
  357.     [19] = { -- Physical Resistance
  358.         attribute = {
  359.             name = 'Physical Resistance',
  360.             rare = {2, 3},
  361.             epic = {4, 6},
  362.             legendary = {7, 10},
  363.         },
  364.         value = "Percent",
  365.         items = {
  366.             2514, -- Mastermind Shield
  367.             2528, -- Tower Shield
  368.             2535, -- Castle Shield
  369.             2536, -- Medusa Shield
  370.             12644,-- Shield of Corruption
  371.             2532, -- Ancient Shield
  372.             2497, -- Crusader Helmet
  373.             3969, -- Horse Helmet
  374.             5741, -- Skull Helmet
  375.             2472, -- Magic Plate Armor
  376.             2466, -- Golden Armor
  377.             3968, -- Leopard Armor
  378.             8889, -- Skullcracker Armor
  379.             8891, -- Paladin Armor
  380.             21692,-- Albino Plate
  381.             2470, -- Golden Legs
  382.             11304,-- Zaoan Legs
  383.             2645, -- Steel Boots
  384.             20109,-- Buckle
  385.             2179, -- Gold Ring
  386.             21693,-- Horn
  387.             11302,-- Zaoan Helmet
  388.             2503, -- Dwarven Armor
  389.             2508, -- Native Armor
  390.             8821, -- Witchunter's Coat
  391.             15406, -- Ornate Chest
  392.             2523 -- Blessed Shield
  393.         }
  394.     },
  395.     [20] = { -- Death Resistance
  396.         attribute = {
  397.             name = 'Death Resistance',
  398.             rare = {2, 3},
  399.             epic = {4, 6},
  400.             legendary = {7, 10},
  401.         },
  402.         value = "Percent",
  403.         items = {
  404.             2521, -- Dark Shield
  405.             2529, -- Black Shield
  406.             2532, -- Ancient Shield
  407.             2536, -- Medusa Shield
  408.             2462, -- Devil Helmet
  409.             2490, -- Dark Helmet
  410.             10016,-- Batwing Hat
  411.             2489, -- Dark Helmet
  412.             8889, -- Skullcracker Armor
  413.             12607,-- Elite Draken Mail
  414.             20109,-- Buckle
  415.             5462, -- Pirate Boots
  416.             2129, -- Wolf Tooth Chain
  417.             2508, -- Native Armor
  418.             8752, -- Ring of the Count
  419.             8885, -- Divine Plate
  420.             21253,-- Vampire Lord Crown
  421.             8821  -- Witchunter's Coat
  422.         }
  423.     },
  424.     [21] = { -- Spell Damage
  425.         attribute = {
  426.             name = 'Spell Damage',
  427.             rare = {3, 5},
  428.             epic = {8, 10},
  429.             legendary = {15, 20},
  430.         },
  431.         value = "Percent",
  432.         items = {
  433.             2123, -- Ring of the Sky
  434.             2131, -- Star Amulet
  435.             8752, -- Ring of the Count
  436.             2662, -- Magician Hat
  437.             21253 -- Vampire Lord Crown
  438.         }
  439.     },
  440.     [22] = { -- Multi Shot
  441.         attribute = {
  442.             name = 'Multi Shot',
  443.             rare = {1, 1},
  444.             epic = {2, 2},
  445.             legendary = {3, 3},
  446.         },
  447.         value = "Static"
  448.         -- Items targeted by this attribute are defined in a different way below.
  449.     },
  450.     [23] = { -- Stun Chance
  451.         attribute = {
  452.             name = 'Stun Chance',
  453.             rare = {3, 5},
  454.             epic = {6, 10},
  455.             legendary = {11, 15},
  456.         },
  457.         value = "Percent",
  458.         items = {
  459.             20090 -- Spike Shield
  460.         }
  461.     },
  462.     [24] = { -- Mana Shield
  463.         atrribute = {
  464.             name = 'Mana Shield',
  465.             rare = {5, 10},
  466.             epic = {11, 20},
  467.             legendary = {21, 30},
  468.         },
  469.         value = "Percent"
  470.     },
  471.     [25] = { -- Sword Skill
  472.         attribute = {
  473.             name = 'Sword Skill',
  474.             rare = {1, 2},
  475.             epic = {3, 5},
  476.             legendary = {6, 10},
  477.         },
  478.         value = "Static",
  479.         items = {
  480.             8881, -- Fireborn
  481.             12644 -- Shield of Corruption
  482.         }
  483.     },
  484.     [26] = { -- Skill Axe
  485.         attribute = {
  486.             name = 'Axe Skill',
  487.             rare = {1, 2},
  488.             epic = {3, 5},
  489.             legendary = {6, 10},
  490.         },
  491.         value = "Static",
  492.         items = {
  493.             8882 -- Earthborn
  494.         }
  495.     },
  496.     [27] = { -- Skill Club
  497.         attribute = {
  498.             name = 'Club Skill',
  499.             rare = {1, 2},
  500.             epic = {3, 5},
  501.             legendary = {6, 10},
  502.         },
  503.         value = "Static",
  504.         items = {
  505.             8883 -- Windborn
  506.         }
  507.     },
  508.     [28] = { -- Skill Melee
  509.         attribute = {
  510.             name = 'Melee Skills',
  511.             rare = {1, 2},
  512.             epic = {3, 5},
  513.             legendary = {6, 10},
  514.         },
  515.         value = "Static",
  516.         items = {
  517.             2342, -- HOTA
  518.             2471, -- Golden Helmet
  519.             15406, -- Ornate Armor
  520.             15412, -- Ornate Legs
  521.             2494, -- Demon Armor
  522.             9776, -- Yalahari Armor
  523.             21692, -- Albino Plate
  524.             2537, -- Amazon Shield
  525.             2522, -- Great Shield
  526.             6391 -- Nightmare Shield
  527.         }
  528.     },
  529.     [29] = { -- Skill Distance
  530.         attribute = {
  531.             name = 'Distance Skill',
  532.             rare = {1, 2},
  533.             epic = {3, 5},
  534.             legendary = {6, 10},
  535.         },
  536.         value = "Static",
  537.         items = {
  538.             8888, -- MAA
  539.             2499, -- Amazon Helmet
  540.             2474, -- Winged Helmet
  541.             12645,-- Elite Draken Helm
  542.             5741, -- Skull Helmet
  543.             2500, -- Amazon Armor
  544.             2505, -- Elven Mail
  545.             8891, -- Paladin Armor
  546.             9777, -- Yalahari Legs
  547.             14327,-- Bronze Ring
  548.             2218, -- Paw Amulet
  549.             15407 -- Depth Lorica
  550.         }
  551.     },
  552.     [30] = { -- Skill Shielding
  553.         attribute = {
  554.             name = 'Shield Skill',
  555.             rare = {1, 2},
  556.             epic = {3, 5},
  557.             legendary = {6, 10},
  558.         },
  559.         value = "Static",
  560.         items = {
  561.             11240, -- Guardian Boots
  562.             2195, -- Boots of Haste
  563.             2503, -- Dwarven Armor
  564.             2505, -- Elven Armor
  565.             15406, -- Depth Lorica
  566.             15410, -- Depth Calcei
  567.             15409, -- Depth Ocrea
  568.             2502 -- Dwarven Helmet
  569.         }
  570.     },
  571.     [31] = { -- Magic Level
  572.         attribute = {
  573.             name = 'Magic Level',
  574.             rare = {1, 2},
  575.             epic = {3, 5},
  576.             legendary = {6, 10},
  577.         },
  578.         value = "Static",
  579.         items = {
  580.             2323, -- Hat of the Mad
  581.             2662, -- Magician Hat
  582.             2506, -- Dragon Scale Helmet
  583.             9778, -- Yalahari Mask
  584.             10016,-- Batwing Hat
  585.             13756,-- Mage's Cape
  586.             18398,-- Gill Gudgel
  587.             8865, -- Dark Lords Cape
  588.             8866, -- Robe of the Ice Queen
  589.             8867, -- Dragon Robe
  590.             8869, -- Greenwood Coat
  591.             8890, -- Robe of the Underworld
  592.             8821, -- Witchhunters Coat
  593.             11355,-- Spell Weavers
  594.             12643,-- Royal Scale Robe
  595.             15489,-- Calop Cape
  596.             11117,-- Crystal Boots
  597.             21700,-- Icy Culotte
  598.             2542, -- Tempest Shield
  599.             6433, -- Necromancer Shield
  600.             2501, -- Ceremonial Mask
  601.             8900, -- Spellbooks
  602.             8901,
  603.             8902,
  604.             8903,
  605.             8904,
  606.             8918,
  607.             12647,
  608.             18401,
  609.             16112,
  610.             22423,
  611.             22424,
  612.             21725, -- Furious Frock
  613.             2139 -- Ancient Tiara
  614.         }
  615.     },
  616.     [32] = { -- Max Health (+100)
  617.         attribute = {
  618.             name = 'Max Health',
  619.             rare = {30, 60},
  620.             epic = {80, 120},
  621.             legendary = {150, 250},
  622.         },
  623.         value = "Static",
  624.         items = {
  625.             2493, -- Demon Helmet
  626.             2496, -- Horned Helmet
  627.             2471, -- Golden Helmet
  628.             2474, -- Winged Helmet
  629.             2498, -- Royal Helmet
  630.             9778, -- Yalahari Mask
  631.             11302,-- Zaoan Helmet
  632.             12645,-- Elite Draken Helmet
  633.             2472, -- MPA
  634.             2492, -- DSM
  635.             2655, -- Red Robe
  636.             2494, -- Demon Armor
  637.             2508, -- Native Armor
  638.             2505, -- Elven Armor
  639.             3968, -- Leopard Armor
  640.             7463, -- Mammoth Fur Cape
  641.             8881, -- Fireborn
  642.             8882, -- Earthborn
  643.             8883, -- Windborn
  644.             8885, -- Divine Plate
  645.             8886, -- Molten Plate
  646.             8887, -- Frozen Plate
  647.             8888, -- MAA
  648.             8889, -- Skullcracker Armor
  649.             8890, -- Underworld Robe
  650.             8821, -- Witch Hunter's Armor
  651.             9776, -- Yalahari Armor
  652.             12607,-- Elite Draken Armor
  653.             12642,-- Royal Draken Mail
  654.             12643,-- Royal Scale Mail
  655.             15406,-- Ornate Chestplate
  656.             15407,-- Depth Lorica
  657.             21692,-- Albino Plate
  658.             21706,-- Goo Shell
  659.             2495, -- Demon Legs
  660.             2470, -- Golen Legs
  661.             7730, -- Blue Legs
  662.             9777, -- Yalahari Leg Piece
  663.             11240,-- Guardian Boots
  664.             11118,-- Dragon Scale Boots
  665.             15410,-- Depth Calcei
  666.             2646, -- Golden Boots
  667.             2522, -- Great Shield
  668.             2539, -- Phoenix Shield
  669.             12644,-- Shield of Corruption
  670.             2139, -- Ancient Tiara
  671.             2539,  -- Phoenix Shield
  672.             2523, -- Blessed Shield
  673.         }
  674.     },
  675.     [33] = { -- Max Mana (+100)
  676.         attribute = {
  677.             name = 'Max Mana',
  678.             rare = {30, 60},
  679.             epic = {80, 120},
  680.             legendary = {150, 250},
  681.         },
  682.         value = "Static",
  683.         items = {
  684.             2662, -- Magician Hat
  685.             2663, -- Mystic Turban
  686.             2323, -- Hat of the Mad
  687.             2472, -- MPA
  688.             3972, -- Beholder Helmet
  689.             7458, -- Fur Cap
  690.             7459, -- Earmuffs
  691.             7903, -- Elemental Hats
  692.             7901,
  693.             7902,
  694.             7900,
  695.             9778, -- Yalahari Mask
  696.             10016,-- Batwing Hat
  697.             13756,-- Mage's Hat
  698.             18398,-- Gill Hat
  699.             2508, -- Native Armor
  700.             2505, -- Elven Armor
  701.             2656, -- Blue Robe
  702.             7884, -- Elemental Coats
  703.             7897,
  704.             7898,
  705.             7899,
  706.             8892, -- Ethno Coat
  707.             8819, -- Magician's Robe
  708.             15489,-- Calopteryx Cape
  709.             11356,-- Zaoan Robe
  710.             18399,-- Gill Coat
  711.             7885, -- Elemental Legs
  712.             7894,
  713.             7895,
  714.             7896,
  715.             7730, -- Blue Legs
  716.             15490,-- Grasshopper Legs
  717.             18400,-- Gill Legs
  718.             7886, -- Elemental Boots
  719.             7891,
  720.             7892,
  721.             7893,
  722.             8900, -- Spellbooks
  723.             8901,
  724.             8902,
  725.             8903,
  726.             8904,
  727.             8918,
  728.             12647,
  729.             18401,
  730.             16112,
  731.             22424,
  732.             21725,-- Furious Frock
  733.             8870, -- Spirit Cloak
  734.             8871, -- Focus Cape
  735.             2139, -- Ancient Tiara
  736.             2195  -- Boots of Haste
  737.         }
  738.     },
  739.     [34] = { -- Max Health % (+10%)
  740.         attribute = {
  741.             name = 'Max Health',
  742.             rare = {1, 3},
  743.             epic = {4, 6},
  744.             legendary = {7, 10},
  745.         },
  746.         value = "Percent",
  747.         items = {
  748.             2523, -- Blessed Shield
  749.         }
  750.     },
  751.     [35] = { -- Max Mana % (+10%)
  752.         attribute = {
  753.             name = 'Max Mana',
  754.             rare = {1, 3},
  755.             epic = {4, 6},
  756.             legendary = {7, 10},
  757.         },
  758.         value = "Percent",
  759.     },
  760.     [36] = { -- Life Leech Chance (Currently Unused)
  761.         attribute = {
  762.             name = 'Mana Leech Chance',
  763.             rare = {3, 5},
  764.             epic = {6, 10},
  765.             legendary = {11, 20},
  766.         },
  767.         value = "Percent"
  768.         -- Items targeted by this attribute are defined in a different way below.
  769.     },
  770.     [37] = { -- Life Leech Amount
  771.         attribute = {
  772.             name = 'Life Leech',
  773.             rare = {3, 5},
  774.             epic = {6, 10},
  775.             legendary = {11, 20},
  776.         },
  777.         value = "Percent"
  778.         -- Items targeted by this attribute are defined in a different way below.
  779.     },
  780.     [38] = { -- Mana Leech Chance (Currently Unused)
  781.         attribute = {
  782.             name = 'Mana Leech Chance',
  783.             rare = {3, 5},
  784.             epic = {6, 10},
  785.             legendary = {11, 20},
  786.         },
  787.         value = "Percent"
  788.         -- Items targeted by this attribute are defined in a different way below.
  789.     },
  790.     [39] = { -- Mana Leech Amount
  791.         attribute = {
  792.             name = 'Mana Leech',
  793.             rare = {3, 5},
  794.             epic = {6, 10},
  795.             legendary = {11, 20},
  796.         },
  797.         value = "Percent"
  798.         -- Items targeted by this attribute are defined in a different way below.
  799.     }
  800. }
  801. local cannotroll = { -- These items are special and cannot be rolled rare/epic/legendary
  802.     8905, -- Rainbow shield
  803.     8906,
  804.     8907,
  805.     8908,
  806.     8909,
  807.     7744, -- These are the standard and transformed Dawnbreaker weapons
  808.     7763,
  809.     7751,
  810.     7770,
  811.     7756,
  812.     7775
  813. }
  814.  
  815. -- Check if item can be rolled (this is for use outside of this lib, actions, quests etc)
  816. function rollCheck(item)
  817.     local itemtype = ItemType(item:getId())
  818.     local itemid = itemtype:getId()
  819.     if table.contains(cannotroll, itemid) then
  820.         return false
  821.     end
  822.     for k,v in pairs(stats) do
  823.         if v.items ~= nil then
  824.             if table.contains(v.items, itemid) then
  825.                 return true
  826.             end
  827.         end
  828.     end
  829.     local weapontype = itemtype:getWeaponType()
  830.     if weapontype > 0 then
  831.         if itemtype:isStackable() then
  832.             return false
  833.         else
  834.             return true
  835.         end
  836.     elseif itemtype:getArmor() > 0 then
  837.         return true
  838.     end
  839.     return false
  840. end
  841.  
  842. -- Get duration literally
  843. function rollBaseDuration(item)
  844.     local it_id = item:getId()
  845.     local tid = ItemType(it_id):getTransformEquipId()
  846.     if tid > 0 then
  847.         item:transform(tid)
  848.         local vx = item:getAttribute(ITEM_ATTRIBUTE_DURATION)
  849.         item:transform(it_id)
  850.         --item:removeAttribute(ITEM_ATTRIBUTE_DURATION)
  851.         return vx
  852.     end
  853.     return 0
  854. end
  855.  
  856. -- Get base/stock stat
  857. function rollBase(item, attr)
  858.     local id = ItemType(item:getId())
  859.     local v = {
  860.         [ITEM_ATTRIBUTE_ATTACK] = id:getAttack(),
  861.         [ITEM_ATTRIBUTE_DEFENSE] = id:getDefense(),
  862.         [ITEM_ATTRIBUTE_EXTRADEFENSE] = id:getExtraDefense(),
  863.         [ITEM_ATTRIBUTE_ARMOR] = id:getArmor(),
  864.         [ITEM_ATTRIBUTE_HITCHANCE] = id:getHitChance(),
  865.         [ITEM_ATTRIBUTE_SHOOTRANGE] = id:getShootRange(),
  866.         [ITEM_ATTRIBUTE_CHARGES] = id:getCharges(),
  867.         [ITEM_ATTRIBUTE_DURATION] = rollBaseDuration(item)
  868.     }
  869.     return v[attr]
  870. end
  871.  
  872. -- Roll a container or item
  873. function rollRarity(container, forced)
  874.     -- Tiers
  875.     local tiers = {
  876.         [1] = {
  877.             prefix = 'rare',
  878.             chance = {
  879.                 [1] = 750, -- 7.5% chance to roll
  880.                 [2] = 2000 -- 20% chance for second stat
  881.             }
  882.         },
  883.  
  884.         [2] = {
  885.             prefix = 'epic',
  886.             chance = {
  887.                 [1] = 375, -- 3.75% chance to roll
  888.                 [2] = 5000 -- 50% chance for second stat
  889.             }
  890.         },
  891.  
  892.         [3] = {
  893.             prefix = 'legendary',
  894.             chance = {
  895.                 [1] = 200, -- 2% chance to roll
  896.                 [2] = 10000 -- 100% chance for second stat
  897.             }
  898.         },
  899.     }
  900.     local rares = 0
  901.     local available_stats = {}
  902.     local it_u = container
  903.     local it_id = ItemType(it_u:getId())
  904.     if it_u:isContainer() then
  905.         local h = it_u:getItemHoldingCount()
  906.         if h > 0 then
  907.             local i = 1
  908.             while i <= h do
  909.                 local bagitem = it_u:getItem(i - 1)
  910.                 if bagitem:isContainer() then
  911.                     h = h - bagitem:getItemHoldingCount()
  912.                 end
  913.                 local manualroll = forced or false
  914.                 local crares = rollRarity(bagitem, manualroll)
  915.                 rares = rares + crares
  916.                 i = i + 1
  917.             end
  918.         end
  919.     else
  920.         if not it_id:isStackable() then
  921.             local wp = it_id:getWeaponType()
  922.             if wp > 0 then
  923.                 -- Shields
  924.                 if wp == WEAPON_SHIELD then
  925.                     table.insert(available_stats, stats[2]) -- Defense
  926.                     table.insert(available_stats, stats[30]) -- Skill Shield
  927.                
  928.                 -- Distance Items
  929.                 elseif wp == WEAPON_DISTANCE then
  930.                     table.insert(available_stats, stats[1]) -- Attack
  931.                     table.insert(available_stats, stats[37]) -- Life Leech
  932.                     table.insert(available_stats, stats[10]) -- Critical Chance
  933.                     table.insert(available_stats, stats[29]) -- Skill Distance
  934.                     --table.insert(available_stats, stats[5]) -- Accuracy
  935.                     if it_u:getId() ~= 5907 then -- Slingshot
  936.                         --table.insert(available_stats, stats[22]) -- Multi Shot
  937.                     end
  938.                
  939.                 -- Wands and Rods
  940.                 elseif wp == WEAPON_WAND then -- type wand
  941.                     table.insert(available_stats, stats[21]) -- Spell Damage
  942.                     table.insert(available_stats, stats[33]) -- Max Mana
  943.                     table.insert(available_stats, stats[31]) -- Magic Level
  944.                     table.insert(available_stats, stats[39]) -- Mana Leech Amount
  945.                
  946.                 -- Sword, Clubs and Axes
  947.                 elseif table.contains({WEAPON_SWORD, WEAPON_CLUB, WEAPON_AXE}, wp) then -- Melee Weapon
  948.                    
  949.                     if wp == WEAPON_SWORD then
  950.                         table.insert(available_stats, stats[25]) -- Sword Skill
  951.                     elseif wp == WEAPON_AXE then
  952.                         table.insert(available_stats, stats[26]) -- Axe Skill
  953.                     elseif wp == WEAPON_CLUB then
  954.                         table.insert(available_stats, stats[27]) -- Club Skill
  955.                     end
  956.                    
  957.                     if it_id:getAttack() > 0 then
  958.                         table.insert(available_stats, stats[1]) -- Attack
  959.                     end
  960.        
  961.                     if it_id:getSlotPosition() == 2096 then -- Two-handed Weapon
  962.                         table.insert(available_stats, stats[2]) -- Defense
  963.                     end
  964.        
  965.                     if it_id:getSlotPosition() == 48 then -- One-handed Weapon
  966.                         table.insert(available_stats, stats[3]) -- Extra Defense
  967.                     end
  968.                     table.insert(available_stats, stats[10]) -- Critical Chance
  969.                     table.insert(available_stats, stats[37]) -- Life Leech
  970.                 end
  971.             else -- Armors, Amulets, Runes and Rings
  972.                 if it_id:getArmor() > 0 then -- Ignore clothing/things with no armor stat
  973.                     table.insert(available_stats, stats[4]) -- Armor
  974.                 end
  975.  
  976.                 -- Duration
  977.                 local eq_id = it_id:getTransformEquipId()
  978.                 if eq_id > 0 then
  979.                     table.insert(available_stats, stats[9]) -- Time
  980.                 end
  981.                
  982.                 -- Charges
  983.                 local chargecount = it_id:getCharges()
  984.                 if chargecount > 0  and it_u.itemid ~= 2173 then -- Ignore AOL
  985.                     if chargecount >= 50 then -- If its base charge is greater than 50
  986.                         table.insert(available_stats, stats[8]) -- High Charges
  987.                     else -- Its base charge is less than 50
  988.                         table.insert(available_stats, stats[7]) -- Low Charges
  989.                     end
  990.                 end
  991.             end
  992.            
  993.             -- Specifically Targeted Items
  994.             for k,v in pairs(stats) do
  995.                 if v.items ~= nil then
  996.                     if table.contains(v.items, it_u.itemid) then
  997.                         table.insert(available_stats, stats[k])
  998.                     end
  999.                 end
  1000.             end
  1001.         end
  1002.     end
  1003.     if #available_stats > 0 then -- Skips it all if it's empty
  1004.         local tier = 0 -- Normal item
  1005.         local rarity = math.random(1, 10000)
  1006.         -- Manual trigger
  1007.         if type(forced) == "string" then -- rollRarity(item, "rare")  OR  /roll legendary
  1008.             for i = 1, #tiers do
  1009.                 if forced == tiers[i].prefix then
  1010.                     tier = i
  1011.                 end
  1012.             end
  1013.         elseif forced == true then -- rollRarity(item, true)  OR  /roll
  1014.             tier = math.random(1,#tiers)
  1015.         -- Natural rolls
  1016.         else
  1017.             for i = 1, #tiers do -- Get best roll
  1018.                 if rarity <= tiers[i].chance[1] then
  1019.                     tier = i -- Rolled a rare/epic/legendary
  1020.                 end
  1021.             end
  1022.         end
  1023.         if tier > 0 then -- Item has rolled rare or higher
  1024.             local stats_used = {}
  1025.             for stat = 1, #tiers[tier].chance do
  1026.                 if #available_stats > 0 then
  1027.                     local roll = math.random(1, 10000)
  1028.                     if stat == 1 then -- First stat is guaranteed
  1029.                         roll = tiers[tier].chance[stat]
  1030.                     end
  1031.                     if roll <= tiers[tier].chance[stat] then -- All other stats are rolled by chance
  1032.                         local selected_stat = math.random(1, #available_stats)
  1033.                         table.insert(stats_used, available_stats[selected_stat])
  1034.                         table.remove(available_stats, selected_stat)
  1035.                     end
  1036.                 end
  1037.             end
  1038.             if #stats_used > 0 then
  1039.                 rares = rares + 1
  1040.                 local stat_desc = {}
  1041.                 for stat = 1, #stats_used do
  1042.                     local statmin = 0
  1043.                     local statmax = 0
  1044.                     if tiers[tier].prefix == tiers[3].prefix then
  1045.                         statmin = stats_used[stat].attribute.legendary[1]
  1046.                         statmax = stats_used[stat].attribute.legendary[2]
  1047.                     elseif tiers[tier].prefix == tiers[2].prefix then
  1048.                         statmin = stats_used[stat].attribute.epic[1]
  1049.                         statmax = stats_used[stat].attribute.epic[2]
  1050.                     else
  1051.                         statmin = stats_used[stat].attribute.rare[1]
  1052.                         statmax = stats_used[stat].attribute.rare[2]
  1053.                     end
  1054.                     -- Apply Attribute
  1055.                     local critv = math.random(statmin, statmax) -- The actual roll amount
  1056.                     if stats_used[stat].value ~= nil then -- Is the value type defined?
  1057.                         local basestat = 0
  1058.                         -- Fill basestat
  1059.                         if stats_used[stat].base ~= nil then
  1060.                             basestat = rollBase(it_u, stats_used[stat].base) -- This is the base/stock value of the stat
  1061.                         end
  1062.                         -- Static
  1063.                         if stats_used[stat].value == "Static" then
  1064.                             table.insert(stat_desc, '[' .. stats_used[stat].attribute.name .. ': +' .. critv .. ']') -- Standard value "+10"
  1065.                         -- Percentage
  1066.                         elseif stats_used[stat].value == "Percent" then
  1067.                             table.insert(stat_desc, '[' .. stats_used[stat].attribute.name ..': +' .. critv .. '%]') -- Percent value "+10%"
  1068.                         -- Damage
  1069.                         elseif stats_used[stat].value == "Damage" then
  1070.                             local minimumDmg = 1 -- the item roll is the MAX damage, how do we get a minimim damage?
  1071.                             if stats_used[stat].attribute.name == "Enhanced Fire Damage" then
  1072.                                 minimumDmg = (critv - math.random(3,5)) -- 3-5 less than the maximum damage
  1073.                             elseif stats_used[stat].attribute.name == "Enhanced Ice Damage" then
  1074.                                 minimumDmg = (critv - math.random(5,9)) -- 5-9 less than the maxximum damage
  1075.                             end -- "Enhanced Energy Damage" always has 1 as minimumDmg
  1076.                             table.insert(stat_desc, '[' .. stats_used[stat].attribute.name ..': '.. minimumDmg .. '-' .. critv .. ']') -- Damage value "13-35"
  1077.                         -- Duration
  1078.                         elseif stats_used[stat].value == "Duration" then
  1079.                             local timeconvert = critv / 60000
  1080.                             table.insert(stat_desc, '[' .. stats_used[stat].attribute.name .. ': +' .. timeconvert .. ' minutes]') -- Duration value "+15 minutes"
  1081.                         end
  1082.                         -- If this is a vanilla attribute, overwrite it with new roll
  1083.                         if basestat > 0 then
  1084.                             it_u:setAttribute(stats_used[stat].base, basestat + critv)
  1085.                         end
  1086.                        
  1087.                     end
  1088.                 end
  1089.                 -- Rarity prefix
  1090.                 if it_id:getArticle() ~= "" then -- Replace article if exists
  1091.                     if tiers[tier].prefix == "epic" then
  1092.                         it_u:setAttribute(ITEM_ATTRIBUTE_ARTICLE, "an " .. tiers[tier].prefix)
  1093.                     else
  1094.                         it_u:setAttribute(ITEM_ATTRIBUTE_ARTICLE, "a " .. tiers[tier].prefix)
  1095.                     end
  1096.                 else -- Add rarity prefix to item article (this allows for easy identification of rolled items in scripts outside of this lib 'item:getArticle():find("rare")')
  1097.                     it_u:setAttribute(ITEM_ATTRIBUTE_ARTICLE, tiers[tier].prefix)
  1098.                 end
  1099.                 -- If item has a description, retain it instead of over-writing it
  1100.                 if it_id:getDescription() == "" then
  1101.                     it_u:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "\n" .. table.concat(stat_desc, "\n"))
  1102.                 else
  1103.                     it_u:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, it_id:getDescription() .. "\n" .. "\n" .. table.concat(stat_desc, "\n"))
  1104.                 end
  1105.                 -- Capitalize tier.prefix to be used for the animated text above corpses
  1106.                 rare_text = (tiers[tier].prefix:gsub("^%l", string.upper) .. "!")
  1107.             end
  1108.         end
  1109.     end
  1110.     return rares
  1111. end
  1112.  
  1113. -- Apply condition
  1114. function rollCondition(player, item, slot)
  1115.     local attributes = {
  1116.          [1] = {"%[" .. stats[25].attribute.name .. ": ", CONDITION_PARAM_SKILL_SWORD}, -- "[Sword Skill: "
  1117.          [2] = {"%[" .. stats[26].attribute.name .. ": ", CONDITION_PARAM_SKILL_AXE},
  1118.          [3] = {"%[" .. stats[27].attribute.name .. ": ", CONDITION_PARAM_SKILL_CLUB},
  1119.          [4] = {"%[" .. stats[28].attribute.name .. ": ", CONDITION_PARAM_SKILL_MELEE},
  1120.          [5] = {"%[" .. stats[29].attribute.name .. ": ", CONDITION_PARAM_SKILL_DISTANCE},
  1121.          [6] = {"%[" .. stats[30].attribute.name .. ": ", CONDITION_PARAM_SKILL_SHIELD},
  1122.          [7] = {"%[" .. stats[31].attribute.name .. ": ", CONDITION_PARAM_STAT_MAGICPOINTS},
  1123.          [8] = {"%[" .. stats[32].attribute.name .. ": ", CONDITION_PARAM_STAT_MAXHITPOINTS},
  1124.          [9] = {"%[" .. stats[33].attribute.name .. ": ", CONDITION_PARAM_STAT_MAXMANAPOINTS},
  1125.         [10] = {"%[" .. stats[34].attribute.name .. ": ", CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, percent = true, absolute = true},
  1126.         [11] = {"%[" .. stats[35].attribute.name .. ": ", CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, percent = true, absolute = true},
  1127.         --[12] = {"%[" .. stats[11].attribute.name .. ": ", CONDITION_PARAM_SPECIALSKILL_CRITICALHITAMOUNT, percent = true, absolute = true},
  1128.         --[13] = {"%[" .. stats[10].attribute.name .. ": ", CONDITION_PARAM_SPECIALSKILL_CRITICALHITCHANCE, percent = true},
  1129.         --[14] = {"%[" .. stats[36].attribute.name .. ": ", CONDITION_PARAM_SPECIALSKILL_LIFELEECHCHANCE, percent = true},
  1130.         --[15] = {"%[" .. stats[37].attribute.name .. ": ", CONDITION_PARAM_SPECIALSKILL_LIFELEECHAMOUNT, percent = true, absolute = true},
  1131.         --[16] = {"%[" .. stats[38].attribute.name .. ": ", CONDITION_PARAM_SPECIALSKILL_MANALEECHCHANCE, percent = true},
  1132.         --[17] = {"%[" .. stats[39].attribute.name .. ": ", CONDITION_PARAM_SPECIALSKILL_MANALEECHAMOUNT, percent = true, absolute = true},
  1133.     }
  1134.     local itemDesc = item:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
  1135.     for k = 1,#attributes do
  1136.         local skillBonus = 0 -- reset
  1137.         local attributeSearchValue = "%+(%d+)%]" -- "+10]"
  1138.         if attributes[k].percent ~= nil then
  1139.             attributeSearchValue = "%+(%d+)%%%]" -- "+10%]"
  1140.             if attributes[k].absolute ~= nil then
  1141.                 skillBonus = 100 -- These conditions require absolutes (108%, 145% etc.)
  1142.             end
  1143.         end
  1144.         local attributeString = attributes[k][1] .. attributeSearchValue -- "%[Attack: %+(%d+)%]"
  1145.         if string.match(itemDesc, attributeString) ~= nil then -- "[Attack: +10]"
  1146.             local offset = (10 * k) + slot -- ((CONST_SLOT_LAST) * k) + slot
  1147.             local skillBonus = skillBonus + tonumber(string.match(itemDesc, attributeString)) -- Raw (%d+) value
  1148.            
  1149.             if player:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, offset) == nil then
  1150.                 local condition = Condition(CONDITION_ATTRIBUTES)
  1151.                 condition:setParameter(CONDITION_PARAM_SUBID, offset)
  1152.                 condition:setParameter(CONDITION_PARAM_TICKS, -1)
  1153.                 condition:setParameter(attributes[k][2], skillBonus)
  1154.                 player:addCondition(condition)
  1155.             else
  1156.                 player:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, offset)
  1157.             end
  1158.         end
  1159.     end
  1160. end
  1161.            
  1162. -- Get item attributes
  1163. function itemAttributes(player, item, slot, equip)
  1164.     -- Check if item is rolled
  1165.     if item:getArticle() ~= "" then
  1166.         if item:getArticle():find("rare") or item:getArticle():find("epic") or item:getArticle():find("legendary") then
  1167.             local appropriateSlot = false
  1168.             local slotType = ItemType(item.itemid):getSlotPosition()
  1169.             -- What slots do we want to check? this ignores CONST_SLOT_AMMO and CONST_SLOT_BACKPACK
  1170.             local raritySlots = {
  1171.                 [CONST_SLOT_LEFT] = {validPositions = {[1] = SLOTP_LEFT,[2] = SLOTP_RIGHT,[3] = SLOTP_TWO_HAND}},
  1172.                 [CONST_SLOT_RIGHT] = {validPositions = {[1] = SLOTP_LEFT,[2] = SLOTP_RIGHT,[3] = SLOTP_TWO_HAND}},
  1173.                 [CONST_SLOT_HEAD] = {validPositions = {[1] = SLOTP_HEAD}},
  1174.                 [CONST_SLOT_NECKLACE] = {validPositions = {[1] = SLOTP_NECKLACE}},
  1175.                 [CONST_SLOT_ARMOR] = {validPositions = {[1] = SLOTP_ARMOR}},
  1176.                 [CONST_SLOT_LEGS] = {validPositions = {[1] = SLOTP_LEGS}},
  1177.                 [CONST_SLOT_FEET] = {validPositions = {[1] = SLOTP_FEET}},
  1178.                 [CONST_SLOT_RING] = {validPositions = {[1] = SLOTP_RING}}
  1179.             }
  1180.             -- If slot is one that we check
  1181.             if raritySlots[slot] ~= nil then
  1182.                 -- Validate that item is being equipped to the right slot
  1183.                 if slot == CONST_SLOT_LEFT or slot == CONST_SLOT_RIGHT then
  1184.                     local weapon = ItemType(item.itemid):getWeaponType()
  1185.                     if weapon ~= WEAPON_NONE then
  1186.                         if weapon ~= WEAPON_AMMO then
  1187.                             appropriateSlot = true
  1188.                         end
  1189.                     end
  1190.                 else
  1191.                     for i = 1,#raritySlots[slot].validPositions do
  1192.                         if bit.band(slotType, raritySlots[slot].validPositions[i]) ~= 0 then
  1193.                             appropriateSlot = true
  1194.                             break
  1195.                         end
  1196.                     end
  1197.                 end
  1198.                 if appropriateSlot then -- Item is in the wrong slotType
  1199.                     -- Checks have all passed, run apply/remove attribute
  1200.                     rollCondition(player, item, slot)
  1201.                 end
  1202.             end
  1203.         end
  1204.     end
  1205. end
  1206.  
  1207. --[[    Legacy version of itemAttributes
  1208. -- Apply skill conditions
  1209. function rollRarityConditions(player, skill, slot, searchString, conditionGuid, bonus)
  1210.     -- Finish loop, player logged out
  1211.     if not Player(player) then
  1212.         return false
  1213.     end
  1214.     local player = Player(player)
  1215.     -- Check slot
  1216.     if player:getSlotItem(slot) then
  1217.         local itemDesc = player:getSlotItem(slot):getDescription()
  1218.         if itemDesc:find(searchString) then
  1219.             -- Validate bonus amount, check if player has replaced the item to one with a different value
  1220.             local skillBonus = tonumber(string.match(itemDesc, searchString .. ": %+(%d+)%]"))
  1221.             if bonus then
  1222.                 if bonus ~= skillBonus then -- skillBonus is not the same, player has replaced item
  1223.                     if player:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, slot + conditionGuid) then
  1224.                         player:removeCondition(CONDITION_ATTRIBUTES, condition, slot + conditionGuid)
  1225.                     end
  1226.                 end
  1227.             end
  1228.             -- Validate player has condition before adding it
  1229.             if player:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, slot + conditionGuid) == nil then
  1230.                 local condition = Condition(CONDITION_ATTRIBUTES)
  1231.                 condition:setParameter(CONDITION_PARAM_SUBID, slot + conditionGuid)
  1232.                 condition:setParameter(CONDITION_PARAM_TICKS, -1)
  1233.                 --condition:setParameter(CONDITION_PARAM_BUFF_SPELL, 1)
  1234.                 condition:setParameter(skill, skillBonus)
  1235.                 player:addCondition(condition)
  1236.             end
  1237.             -- Loop again in 2000ms to re-check if item equipped
  1238.             addEvent(rollRarityConditions, 2000, player.uid, skill, slot, searchString, conditionGuid, skillBonus)
  1239.            
  1240.         else
  1241.             -- Finish loop, item has been unequipped
  1242.             if player:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, slot + conditionGuid) then
  1243.                 player:removeCondition(CONDITION_ATTRIBUTES, condition, slot + conditionGuid)
  1244.             end
  1245.         end
  1246.     else
  1247.         -- Finish loop, item has been unequipped
  1248.         if player:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, slot + conditionGuid) then
  1249.             player:removeCondition(CONDITION_ATTRIBUTES, condition, slot + conditionGuid)
  1250.         end
  1251.     end
  1252.     return true
  1253. end
  1254.  
  1255. -- Activate skill bonuses (check for events/player.lua and creatureevents/login.lua)
  1256. function rollRarityConditionsActivate(player, slot)
  1257.     if not Player(player) then
  1258.         return false
  1259.     end
  1260.     local player = Player(player)
  1261.     -- Validate slot
  1262.     local slotCount = 0
  1263.     for i = 1,#raritySlots do
  1264.         if raritySlots[i][1] == slot then
  1265.             slotCount = i
  1266.             break
  1267.         end
  1268.     end
  1269.     -- Valid slot
  1270.     if slotCount > 0 then
  1271.         -- Check slot
  1272.         if player:getSlotItem(slot) ~= nil then
  1273.             local item = player:getSlotItem(slot)
  1274.             local itemDesc = item:getDescription()
  1275.             local slotType = ItemType(item.itemid):getSlotPosition()
  1276.             -- Validate equipment is equipped to the right slotType before activating (This stops equipment like rings or armor from buffing you if placed in hand slots etc)
  1277.             local appropriateSlot = false
  1278.             if slot == CONST_SLOT_LEFT or slot == CONST_SLOT_RIGHT then
  1279.                 local weapon = ItemType(item.itemid):getWeaponType()
  1280.                 if weapon ~= WEAPON_NONE then
  1281.                     if weapon ~= WEAPON_AMMO then
  1282.                         appropriateSlot = true
  1283.                     end
  1284.                 end
  1285.             else
  1286.                 for j = 1,#raritySlots[slotCount].validPositions do
  1287.                     if bit.band(slotType, raritySlots[slotCount].validPositions[j]) ~= 0 then
  1288.                         appropriateSlot = true
  1289.                         break
  1290.                     end
  1291.                 end
  1292.             end
  1293.             -- Item is in the right slotType
  1294.             if appropriateSlot then
  1295.                 local offset = 0
  1296.                 local attributes = {
  1297.                     [1] = {"%[Sword Skill", CONDITION_PARAM_SKILL_SWORD},
  1298.                     [2] = {"%[Axe Skill", CONDITION_PARAM_SKILL_AXE},
  1299.                     [3] = {"%[Club Skill", CONDITION_PARAM_SKILL_CLUB},
  1300.                     [4] = {"%[Melee Skills", CONDITION_PARAM_SKILL_MELEE},
  1301.                     [5] = {"%[Distance Skill", CONDITION_PARAM_SKILL_DISTANCE},
  1302.                     [6] = {"%[Shield Skill", CONDITION_PARAM_SKILL_SHIELD},
  1303.                     [7] = {"%[Magic Level", CONDITION_PARAM_STAT_MAGICPOINTS},
  1304.                     [8] = {"%[Max Health", CONDITION_PARAM_STAT_MAXHITPOINTS},
  1305.                     [9] = {"%[Max Mana", CONDITION_PARAM_STAT_MAXMANAPOINTS}
  1306.                 }
  1307.                 -- Search item for attributes
  1308.                 for k = 1,#attributes do
  1309.                     if itemDesc:find(attributes[k][1]) then
  1310.                         offset = 12 * k -- This is used for the CONDITION_PARAM_SUBID and allows all slots to have 1 of each attribute active
  1311.                         -- Check condition not already applied
  1312.                         if player:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, slot + offset) == nil then
  1313.                             rollRarityConditions(player.uid, attributes[k][2], slot, attributes[k][1], offset)
  1314.                         end
  1315.                     end
  1316.                 end
  1317.             end
  1318.         end
  1319.     end
  1320.     return true
  1321. end
  1322. --]]
Add Comment
Please, Sign In to add comment