Advertisement
Guest User

choose_bonus

a guest
Mar 30th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.95 KB | None | 0 0
  1. quest choose_bonus begin
  2.     state start begin
  3.         function GetBonusListPerItemSubType(subtype)
  4.             local bonus_list = {};
  5.             local item_class_list = {
  6.                 [1] = {
  7.                     [0] = {3, 4, 5, 6, 9, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22}, --** Sword
  8.                     [1] = {3, 4, 5, 6, 9, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22}, --** Dagger
  9.                     [2] = {3, 4, 5, 6, 9, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22}, --** Bow
  10.                     [3] = {3, 4, 5, 6, 9, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22}, --** Two-Handed Sword
  11.                     [4] = {3, 4, 5, 6, 9, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22}, --** Bell
  12.                     [5] = {3, 4, 5, 6, 9, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22}, --** Fan
  13.                 },
  14.                 [2] = {
  15.                     [0] = {1, 2, 9, 23, 24, 29, 30, 31, 32, 33, 34, 35, 36, 38, 39, 53},      --** Armor
  16.                     [1] = {7, 10, 11, 12, 17, 18, 19, 20, 21, 22, 24, 28, 35, 36, 37, 38},  --** Helmet
  17.                     [2] = {3, 4, 5, 6, 17, 18, 19, 20, 21, 22, 27, 39, 43, 44, 48, 49},    --** Shield
  18.                     [3] = {1, 2, 16, 17, 18, 19, 20, 21, 22, 23, 25, 35, 36, 37, 38, 45},    --** Armband
  19.                     [4] = {1, 2, 7, 13, 14, 15, 28, 29, 30, 31, 32, 33, 34, 43, 44},          --** Shoes
  20.                     [5] = {1, 2, 10, 11, 13, 15, 16, 24, 25, 29, 30, 31, 32, 33, 34, 43, 44}, --** Necklace
  21.                     [6] = {8, 17, 18, 19, 20, 21, 22, 25, 29, 30, 31, 32, 33, 34, 41, 45}    --** Earrings
  22.                 }
  23.             };
  24.            
  25.             local item_data = item_class_list[item_type][subtype];
  26.             for i = 1, table.getn(item_data) do
  27.                 table.insert(bonus_list, item_data[i]);
  28.             end -- for
  29.  
  30.             return bonus_list;
  31.         end -- function
  32.  
  33.         function GetApplyData(value)
  34.             local apply_data = {
  35.                 [1] = {["id"] = 1, ["str"] = "Max. HP +%d",                                ["value"] = 2000},
  36.                 [2] = {["id"] = 2, ["str"] = "Max. SP +%d",                                ["value"] = 200},
  37.                 [3] = {["id"] = 3, ["str"] = "Vitality +%d",                               ["value"] = 12},
  38.                 [4] = {["id"] = 4, ["str"] = "Intelligence +%d",                           ["value"] = 12},
  39.                 [5] = {["id"] = 5, ["str"] = "Strength +%d",                               ["value"] = 12},
  40.                 [6] = {["id"] = 6, ["str"] = "Dexterity +%d",                              ["value"] = 12},
  41.                 [7] = {["id"] = 7, ["str"] = "Attack Speed +%d%%",                         ["value"] = 8},
  42.                 [8] = {["id"] = 8, ["str"] = "Movement Speed +%d%%",                       ["value"] = 20},
  43.                 [9] = {["id"] = 9, ["str"] = "Casting Speed +%d%%",                        ["value"] = 20},
  44.                 [10] = {["id"] = 10, ["str"] = "HP Regeneration +%d%%",                    ["value"] = 30},
  45.                 [11] = {["id"] = 11, ["str"] = "MP Regeneration +%d%%",                    ["value"] = 30},
  46.                 [12] = {["id"] = 12, ["str"] = "Poisoning Chance +%d%%",                   ["value"] = 8},
  47.                 [13] = {["id"] = 13, ["str"] = "Chance for Blackout +%d%%",                ["value"] = 8},
  48.                 [14] = {["id"] = 14, ["str"] = "Slowing Chance +%d%%",                     ["value"] = 8},
  49.                 [15] = {["id"] = 15, ["str"] = "+%d%% Chance of Critical Hit",             ["value"] = 10},
  50.                 [16] = {["id"] = 16, ["str"] = "+%d%% Chance of Piercing Hit",             ["value"] = 10},
  51.                 [17] = {["id"] = 17, ["str"] = "Strong against Half-Humans +%d%%",         ["value"] = 10},
  52.                 [18] = {["id"] = 18, ["str"] = "Strong against Animals +%d%%",             ["value"] = 20},
  53.                 [19] = {["id"] = 19, ["str"] = "Strong against Orcs +%d%%",                ["value"] = 20},
  54.                 [20] = {["id"] = 20, ["str"] = "Strong against Mystics +%d%%",             ["value"] = 20},
  55.                 [21] = {["id"] = 21, ["str"] = "Strong against Zombies +%d%%",             ["value"] = 20},
  56.                 [22] = {["id"] = 22, ["str"] = "Strong against Devils +%d%%",              ["value"] = 20},
  57.                 [23] = {["id"] = 23, ["str"] = "+%d%% damage will be absorbed by HP",      ["value"] = 10},
  58.                 [24] = {["id"] = 24, ["str"] = "+%d%% damage will be absorbed by SP",      ["value"] = 10},
  59.                 [25] = {["id"] = 25, ["str"] = "%d%% Chance of taking SP from the enemy",  ["value"] = 10},
  60.                 [27] = {["id"] = 27, ["str"] = "+%d%% Chance to Block physical attacks",   ["value"] = 15},
  61.                 [28] = {["id"] = 28, ["str"] = "+%d%% Chance of Evading Arrows",           ["value"] = 15},
  62.                 [29] = {["id"] = 29, ["str"] = "+%d%% Sword Defence",                      ["value"] = 15},
  63.                 [30] = {["id"] = 30, ["str"] = "+%d%% Two-Handed Defence",                 ["value"] = 15},
  64.                 [31] = {["id"] = 31, ["str"] = "+%d%% Dagger Defence",                     ["value"] = 15},
  65.                 [32] = {["id"] = 32, ["str"] = "+%d%% Bell Defence",                       ["value"] = 15},
  66.                 [33] = {["id"] = 33, ["str"] = "+%d%% Fan Defence",                        ["value"] = 15},
  67.                 [34] = {["id"] = 34, ["str"] = "+%d%% Arrow resistance",                   ["value"] = 15},
  68.                 [35] = {["id"] = 35, ["str"] = "+%d%% Fire resistance",                    ["value"] = 15},
  69.                 [36] = {["id"] = 36, ["str"] = "+%d%% Lightning resistance",               ["value"] = 15},
  70.                 [37] = {["id"] = 37, ["str"] = "+%d%% Magic resistance",                   ["value"] = 15},
  71.                 [38] = {["id"] = 38, ["str"] = "+%d%% Wind resistance",                    ["value"] = 15},
  72.                 [39] = {["id"] = 39, ["str"] = "+%d%% Chance to Reflect physical attacks", ["value"] = 10},
  73.                 [41] = {["id"] = 41, ["str"] = "+%d%% Poison Resistance",                  ["value"] = 5},
  74.                 [43] = {["id"] = 43, ["str"] = "+%d%% Chance for EXP bonus",               ["value"] = 20},
  75.                 [44] = {["id"] = 44, ["str"] = "+%d%% Chance of double Yang drop",         ["value"] = 20},
  76.                 [45] = {["id"] = 45, ["str"] = "+%d%% Chance of double Item drop",         ["value"] = 20},
  77.                 [48] = {["id"] = 48, ["str"] = "Defence against Blackouts",                ["value"] = 1},
  78.                 [49] = {["id"] = 49, ["str"] = "Defence against Slowing",                  ["value"] = 1},
  79.                 [53] = {["id"] = 53, ["str"] = "+%d Attack Value",                         ["value"] = 50}
  80.             };
  81.  
  82.             return apply_data[value] or apply_data;
  83.         end -- function
  84.  
  85.         when 20001.take begin
  86.             local item_attributes = item.get_attr0();
  87.             local item_type = item.get_type();
  88.             local item_subtype = item.get_sub_type();
  89.             local item_bonus_list = choose.bonus.GetBonusListPerItemSubType(item_subtype);
  90.  
  91.             say_title(string.format("%s:[ENTER]", npc.get_race()))
  92.             if (item_type == 1 or item_type == 2) then
  93.                 say("Choose the bonus you want to modify on this item:[ENTER]")
  94.  
  95.                 --[[
  96.                     Iterates through the item slots to get the bonus for each slot
  97.                     then inserts them into a table from which the player can choose which bonus has to be substituted.
  98.                 ]]
  99.                 local item_bonuses_id = {};
  100.                 local item_bonuses_str = {};
  101.                 for i = 1, 9, +2 do
  102.                     local real_apply_data = choose_bonus.GetApplyData(item_bonus_list[i]);
  103.                     if (real_apply_data ~= nil) then
  104.                         table.insert(item_bonuses_id, real_apply_data["id"]);
  105.                         table.insert(item_bonuses_str, string.format(real_apply_data["str"], real_apply_data["value"]));
  106.                     else
  107.                         table.insert(item_bonuses_str, string.format("%d. Empty or Unknown Slot", math.ceil(i/2)));
  108.                     end -- if/else
  109.                 end -- for
  110.  
  111.                 table.insert(item_bonuses_str, "Nothing, close the window");
  112.                 local select_item_slot = select_table(item_bonuses_str);
  113.  
  114.                 if (select_item_slot < table.getn(item_bonuses_str)) then
  115.                     say_title(string.format("%s:[ENTER]", npc.get_race()))
  116.                     say("Choose the bonus you want for this slot:[ENTER]")
  117.  
  118.                     --[[
  119.                         Iterates through the all the type of bonuses that piece of equipment can handle
  120.                         then inserts them into a table from which the player can choose whatever bonus he wants to insert.
  121.                     ]]
  122.                     local new_bonus_id = 0;
  123.                     local new_bonuses_str = {};
  124.                     for i = 1, table.getn(item_bonus_list) do
  125.  
  126.                         local real_apply_data = choose_bonus.GetApplyData(item_bonus_list[i]);
  127.                         if (real_apply_data ~= nil) then
  128.                             new_bonus_id = real_apply_data["id"];
  129.                             table.insert(new_bonuses_str, string.format(real_apply_data["str"], real_apply_data["value"]));
  130.                         else
  131.                             say_reward(string.format("[ERROR]: Unsupported bonus type %d.", i))
  132.                             say_reward("[ENTER]Add it to choose_bonus.GetApplyData.[ENTER]")
  133.                             return;
  134.                         end -- if
  135.                     end -- for
  136.  
  137.                     table.insert(new_bonuses_str, "Nothing, close the window");
  138.                     local select_new_bonus = select_table(new_bonuses_str);
  139.  
  140.                     if (select_new_bonus < table.getn(new_bonuses_str)) then
  141.                    
  142.                         --[[
  143.                             Check for duplicate bonus.
  144.                         ]]
  145.                         say_title(string.format("%s:[ENTER]", npc.get_race()))
  146.                         if (not table.is_in(item_bonuses_id, new_bonus_id)) then
  147.                             say("Your item's bonus has been successfully changed.[ENTER]")
  148.                             --[[
  149.                                 Make a function which substitutes a determined slot and its value [value = slot_index+1]
  150.                                 with new ones (item.set_attr0 does it for every single slot at once, so it's not good).
  151.                                
  152.                                 I could always use a query but that would suck massive dick as a workaround.
  153.                                
  154.                                 Structure Example:
  155.                                     item.set_attr_by_slot(slot, new_bonus_id, new_bonus_value);
  156.  
  157.                                 Usage Example:
  158.                                     local new_bonus = choose_bonus.GetApplyData(new_bonus_id);
  159.                                     item.set_attr_by_slot(select_item_slot, new_bonus["id"], new_bonus["value"]);
  160.                             ]]
  161.                         else
  162.                             say("Your item already has that bonus type.[ENTER]")
  163.                         end -- if/else
  164.                     end -- if
  165.                 end -- if
  166.             else
  167.                 say("I can't modify this item's bonuses.[ENTER]")
  168.                 say_item_vnum(item.get_vnum());
  169.             end -- if
  170.         end -- when
  171.     end -- state
  172. end -- quest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement