Advertisement
Guest User

choose_bonus.lua

a guest
Mar 30th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.59 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] = {["str"] = "Max. HP +%d",                               ["value"] = 2000},
  36.                 [2] = {["str"] = "Max. SP +%d",                               ["value"] = 200},
  37.                 [3] = {["str"] = "Vitality +%d",                              ["value"] = 12},
  38.                 [4] = {["str"] = "Intelligence +%d",                          ["value"] = 12},
  39.                 [5] = {["str"] = "Strength +%d",                              ["value"] = 12},
  40.                 [6] = {["str"] = "Dexterity +%d",                             ["value"] = 12},
  41.                 [7] = {["str"] = "Attack Speed +%d%%",                        ["value"] = 8},
  42.                 [8] = {["str"] = "Movement Speed +%d%%",                      ["value"] = 20},
  43.                 [9] = {["str"] = "Casting Speed +%d%%",                       ["value"] = 20},
  44.                 [10] = {["str"] = "HP Regeneration +%d%%",                    ["value"] = 30},
  45.                 [11] = {["str"] = "MP Regeneration +%d%%",                    ["value"] = 30},
  46.                 [12] = {["str"] = "Poisoning Chance +%d%%",                   ["value"] = 8},
  47.                 [13] = {["str"] = "Chance for Blackout +%d%%",                ["value"] = 8},
  48.                 [14] = {["str"] = "Slowing Chance +%d%%",                     ["value"] = 8},
  49.                 [15] = {["str"] = "+%d%% Chance of Critical Hit",             ["value"] = 10},
  50.                 [16] = {["str"] = "+%d%% Chance of Piercing Hit",             ["value"] = 10},
  51.                 [17] = {["str"] = "Strong against Half-Humans +%d%%",         ["value"] = 10},
  52.                 [18] = {["str"] = "Strong against Animals +%d%%",             ["value"] = 20},
  53.                 [19] = {["str"] = "Strong against Orcs +%d%%",                ["value"] = 20},
  54.                 [20] = {["str"] = "Strong against Mystics +%d%%",             ["value"] = 20},
  55.                 [21] = {["str"] = "Strong against Zombies +%d%%",             ["value"] = 20},
  56.                 [22] = {["str"] = "Strong against Devils +%d%%",              ["value"] = 20},
  57.                 [23] = {["str"] = "+%d%% damage will be absorbed by HP",      ["value"] = 10},
  58.                 [24] = {["str"] = "+%d%% damage will be absorbed by SP",      ["value"] = 10},
  59.                 [25] = {["str"] = "%d%% Chance of taking SP from the enemy",  ["value"] = 10},
  60.                 [27] = {["str"] = "+%d%% Chance to Block physical attacks",   ["value"] = 15},
  61.                 [28] = {["str"] = "+%d%% Chance of Evading Arrows",           ["value"] = 15},
  62.                 [29] = {["str"] = "+%d%% Sword Defence",                      ["value"] = 15},
  63.                 [30] = {["str"] = "+%d%% Two-Handed Defence",                 ["value"] = 15},
  64.                 [31] = {["str"] = "+%d%% Dagger Defence",                     ["value"] = 15},
  65.                 [32] = {["str"] = "+%d%% Bell Defence",                       ["value"] = 15},
  66.                 [33] = {["str"] = "+%d%% Fan Defence",                        ["value"] = 15},
  67.                 [34] = {["str"] = "+%d%% Arrow resistance",                   ["value"] = 15},
  68.                 [35] = {["str"] = "+%d%% Fire resistance",                    ["value"] = 15},
  69.                 [36] = {["str"] = "+%d%% Lightning resistance",               ["value"] = 15},
  70.                 [37] = {["str"] = "+%d%% Magic resistance",                   ["value"] = 15},
  71.                 [38] = {["str"] = "+%d%% Wind resistance",                    ["value"] = 15},
  72.                 [39] = {["str"] = "+%d%% Chance to Reflect physical attacks", ["value"] = 10},
  73.                 [41] = {["str"] = "+%d%% Poison Resistance",                  ["value"] = 5},
  74.                 [43] = {["str"] = "+%d%% Chance for EXP bonus",               ["value"] = 20},
  75.                 [44] = {["str"] = "+%d%% Chance of double Yang drop",         ["value"] = 20},
  76.                 [45] = {["str"] = "+%d%% Chance of double Item drop",         ["value"] = 20},
  77.                 [48] = {["str"] = "Defence against Blackouts",                ["value"] = 1},
  78.                 [49] = {["str"] = "Defence against Slowing",                  ["value"] = 1},
  79.                 [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.                 --** Iterate through the item slots to get the bonus for each slot and insert them into a table from which the player can choose which bonus has to be substituted.
  96.                 local item_bonuses = {};
  97.                 for i = 1, 9, +2 do
  98.                     local real_apply_data = choose_bonus.GetApplyData(item_bonus_list[i]);
  99.                     table.insert(item_bonuses, table_is_in(choose_bonus.GetApplyData(), item_bonus_list[i]) and string.format(real_apply_data["str"], real_apply_data["value"]) or string.format("%d. Empty or Unknown Slot", math.ceil(i/2)));
  100.                 end -- for
  101.  
  102.                 table.insert(item_bonuses, "Nothing, close the window");
  103.                 local select_item_bonus = select_table(item_bonuses);
  104.  
  105.                 if (select_item_bonus < table.getn(item_bonuses)) then
  106.                     say_title(string.format("%s:[ENTER]", npc.get_race()))
  107.                     say("Choose the bonus you want for this slot:[ENTER]")
  108.  
  109.                     --** Add the bonus to the possible-to-insert-bonuses table only if the item doesn't already have that bonus.
  110.                     local new_bonuses = {};
  111.                     for i = 1, table.getn(item_bonus_list) do
  112.                         if (not table.is_in(item_bonuses, item_bonus_list[i])) then
  113.                             local real_apply_data = choose_bonus.GetApplyData(item_bonus_list[i]);
  114.                             table.insert(new_bonuses, [i] = {item_bonus_list[i], string.format(real_apply_data["str"], real_apply_data["value"])});
  115.                         end -- if
  116.                     end -- for
  117.  
  118.                     table.insert(new_bonuses, "Nothing, close the window");
  119.                     local select_new_bonus = select_table(new_bonuses);
  120.  
  121.                     if (select_new_bonus < table.getn(new_bonuses)) then
  122.                         --** Make a function which substitutes a determined slot and its value [value = slot_index+1] with new ones (item.set_attr0 does it for every single slot so it's not good).
  123.                     end -- if
  124.                 end -- if
  125.             else
  126.                 say("I can't modify this item's bonuses.[ENTER]")
  127.                 say_item_vnum(item.get_vnum());
  128.             end -- if
  129.         end -- when
  130.     end -- state
  131. end -- quest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement