The following is a script I was working on back in July, but I never got around to finish it, though a good deal should be working. Basically, this script calculates total stats of your char and compares these to theoretical stats if you switch one item of your gear with a selected item from a merch or your inventory.
Chedich wrote a function for this as well and his dps calculation is integrated as well
In case I will never get back to this, someone else might want to pick it up in the meantime.
Code: Select all
ched_addon_register("Item Comp.", "Ched/Mort", "20140517", "lm_buymode_eqcomp_2", "test()", SELECT_BUY)
function test()
local lm_stat_names = {
[1] = "HP ",
[2] = "DEF ",
[3] = "MR ",
[4] = "STR ",
[5] = "DEX ",
[6] = "INT ",
[7] = "AS ",
[8] = "DMG ",
[9] = "DPS ",
[10] = "Ench",
[11] = "Leech ",
[12] = "Mana ",
[13] = "Vigour",
[14] = "Speed",
[15] = "Sight",
[16] = "Material",
[17] = "DMG type",
[18] = "Grade",
[19] = "Gold"
}
lm_gear_array = {
[1] = me.weapon,
[2] = me.shield,
[3] = me.armour,
[4] = me.boots,
[5] = me.gloves,
[6] = me.hat,
[7] = me.trousers,
[8] = me.ring1,
[9] = me.ring2,
[10] = me.amulet,
[11] = me.sigil1,
[12] = me.sigil2,
[13] = me.sigil3
}
local ched_weap_skill_mod = {
["unarmed"]=260,
["longswords"]=300,
["shortswords"]=240,
["maces"]=290,
["polearms"]=300,
["axes"]=310,
["foils"]=240,
["ranged"]=300,
["staves"]=380
}
local hp = {0,0}
local def = {10,10} -- base ac
local mr = {0,0}
local str = {0,0}
local dex = {0,0}
local int = {0,0}
local as = {0,0}
local dmg = {0,0}
local dps = {0,0}
local dmgtype = {"-","-"}
local enchant = {"-","-"}
local mana = {0,0}
local vig = {0,0}
local leeching = {0,0}
local material = {"-","-"}
local grade = {"-","-"}
local speed = {0,0}
local sight = {1,1} -- base sight
local gp = {items:get_qty_basecode(0x100),0}
local delay = {0,0}
-- ARMOUR BONUS
local mr_ab = {0,0}
local armour_weight = {0,0}
-- THACO BONUS
local as_b = {0,0}
-- CLASS BONUS
local fighter_sk = math.max(me:get_skill(0x0),me:get_skill(0x1),me:get_skill(0x2),me:get_skill(0x3),me:get_skill(0x13),me:get_skill(0x1a))
local rogue_sk = math.max(me:get_skill(0x9),me:get_skill(0xd),me:get_skill(0xe),me:get_skill(0xf),me:get_skill(0x11),me:get_skill(0x12),me:get_skill(0x13))
local mage_sk = math.max(me:get_skill(0x7),me:get_skill(0x21))
local priest_sk = math.max(me:get_skill(0x22),me:get_skill(0x24),me:get_skill(0x26))
local monk_sk = math.max(me:get_skill(0xa),me:get_skill(0x28))
-- RACE BONUS FOR STR, DEX AND INT
local hp_rb = 0
local str_rb = 0
local dex_rb = 0
local int_rb = 0
local mr_rb = 0
local dmg_rb = 0
local as_rb = 1
local sight_rb = 0
if me.race == 1 then -- "Draconian"
dmg_rb = 0.1
mr_rb = 0.15
end
if me.race == 2 then -- "Orc"
str_rb = 0.1
mr_rb = 0.1
end
if me.race == 3 then -- "Gnome"
dex_rb = 0.1
int_rb = 0.1
end
if me.race == 5 then -- "Shadowfolk"
str_rb = 0.1
dex_rb = 0.1
sight_rb = 3
end
if me.race == 6 then -- "Bloodkin"
int_rb = 0.1
mr_rb = 0.1
as_rb = 0.15
end
if me.race == 7 then -- "Dwarf"
hp_rb = 0.1
end
if me.race == 8 then -- "Skeletun"
mr_rb = 0.15
end
for i=1,2 do
for item = 1,13 do
-- get magprops of items with ched's script
lm_gear_item=ched_buymode_get_mp(lm_gear_array[item])
if lm_gear_item[tostring(2)] then int[i] = int[i] + tonumber(lm_gear_item[tostring(2)]) end
if lm_gear_item[tostring(3)] then str[i] = str[i] + tonumber(lm_gear_item[tostring(3)]) end
if lm_gear_item[tostring(4)] then dex[i] = dex[i] + tonumber(lm_gear_item[tostring(4)]) end
if lm_gear_item[tostring(5)] then vig[i] = vig[i] + tonumber(lm_gear_item[tostring(5)]) end
if lm_gear_item[tostring(6)] then sight[i] = sight[i] + tonumber(lm_gear_item[tostring(6)]) end
if lm_gear_item[tostring(8)] then enchant[i] = lm_gear_item[tostring(8)] end
if lm_gear_item[tostring(9)] then leeching[i] = leeching[i] + tonumber(lm_gear_item[tostring(9)]) end
if lm_gear_item[tostring(10)] then mr_ab[i] = mr_ab[i] + tonumber(lm_gear_item[tostring(10)]) * 20 end
if lm_gear_item[tostring(1)] then as_b[i] = as_b[i] + tonumber(lm_gear_item[tostring(1)]) end
-- GRADE AND MATERIAL
if wl:is_weapon(get_highlighted_item()) and wl:is_weapon(lm_gear_array[item]) then
if lm_gear_item[tostring(15)] then grade[i] = lm_gear_item[tostring(15)] end
if lm_gear_item[tostring(16)] then material[i] = lm_gear_item[tostring(16)] end
elseif wl:is_shield(get_highlighted_item()) and wl:is_shield(lm_gear_array[item]) then
if lm_gear_item[tostring(15)] then grade[i] = lm_gear_item[tostring(15)] end
if lm_gear_item[tostring(16)] then material[i] = lm_gear_item[tostring(16)] end
elseif wl:is_torso(get_highlighted_item()) and wl:is_torso(lm_gear_array[item]) then
if lm_gear_item[tostring(15)] then grade[i] = lm_gear_item[tostring(15)] end
if lm_gear_item[tostring(16)] then material[i] = lm_gear_item[tostring(16)] end
elseif wl:is_boots(get_highlighted_item()) and wl:is_boots(lm_gear_array[item]) then
if lm_gear_item[tostring(15)] then grade[i] = lm_gear_item[tostring(15)] end
if lm_gear_item[tostring(16)] then material[i] = lm_gear_item[tostring(16)] end
elseif wl:is_gloves(get_highlighted_item()) and wl:is_gloves(lm_gear_array[item]) then
if lm_gear_item[tostring(15)] then grade[i] = lm_gear_item[tostring(15)] end
if lm_gear_item[tostring(16)] then material[i] = lm_gear_item[tostring(16)] end
elseif wl:is_hat(get_highlighted_item()) and wl:is_hat(lm_gear_array[item]) then
if lm_gear_item[tostring(15)] then grade[i] = lm_gear_item[tostring(15)] end
if lm_gear_item[tostring(16)] then material[i] = lm_gear_item[tostring(16)] end
elseif wl:is_trousers(get_highlighted_item()) and wl:is_trousers(lm_gear_array[item]) then
if lm_gear_item[tostring(15)] then grade[i] = lm_gear_item[tostring(15)] end
if lm_gear_item[tostring(16)] then material[i] = lm_gear_item[tostring(16)] end
elseif wl:is_ring(get_highlighted_item()) and wl:is_ring(lm_gear_array[item]) then
if lm_gear_item[tostring(15)] then grade[i] = lm_gear_item[tostring(15)] end
if lm_gear_item[tostring(16)] then material[i] = lm_gear_item[tostring(16)] end
elseif wl:is_amulet(get_highlighted_item()) and wl:is_amulet(lm_gear_array[item]) then
if lm_gear_item[tostring(15)] then grade[i] = lm_gear_item[tostring(15)] end
if lm_gear_item[tostring(16)] then material[i] = lm_gear_item[tostring(16)] end
elseif wl:is_sigil(get_highlighted_item()) and wl:is_sigil(lm_gear_array[item]) then
if lm_gear_item[tostring(15)] then grade[i] = lm_gear_item[tostring(15)] end
if lm_gear_item[tostring(16)] then material[i] = lm_gear_item[tostring(16)] end
end
-- DAMAGE TYPE
if item == 1 then dmgtype[i] = string.char(lm_gear_item[tostring(17)]) end
if dmgtype[i] == "p" then dmgtype[i] = "piercing"
elseif dmgtype[i] == "s" then dmgtype[i] = "slashing"
elseif dmgtype[i] == "b" then dmgtype[i] = "bludgeoning"
end
-- GOLD BONUS FOR NIGHT VISION
if get_material(lm_gear_array[item]) == 7 then sight[i] = sight[i] + 1 end -- gold bonus
-- DEFENCE
if lm_gear_array[item] and item ~= 2 then
if string.char(wl:get_grade(lm_gear_array[item])) == "l" then
skill_bonus = math.max(fighter_sk, priest_sk, rogue_sk)
def[i] = def[i] + skill_bonus*wl:get_ac(lm_gear_array[item])/100
elseif string.char(wl:get_grade(lm_gear_array[item])) == "m" or string.char(wl:get_grade(lm_gear_array[item])) == "h" then
skill_bonus = math.max(fighter_sk, priest_sk)
def[i] = def[i] + skill_bonus*wl:get_ac(lm_gear_array[item])/100
else def[i] = def[i] + wl:get_ac(lm_gear_array[item])
end
end
-- MYTHIC BONUS
if string.find(lm_gear_item[tostring(16)],"mythic") then
if not wl:is_weapon(lm_gear_array[item]) then
mr_ab[i] = mr_ab[i] + 20
else
as_b[i] = as_b[i] + as_b[i] * 0.1
end
end
if string.find(lm_gear_item[tostring(16)],"mystic") and not wl:is_weapon(lm_gear_array[item]) then
vig[i] = vig[i] + 3
end
if string.find(lm_gear_item[tostring(16)],"astral") and not wl:is_weapon(lm_gear_array[item]) then
sight[i] = sight[i] + 1
end
if wl:is_weapon(lm_gear_array[item])
and string.find(lm_gear_item[tostring(16)],"fel")
or string.find(lm_gear_item[tostring(16)],"bal")
or string.find(lm_gear_item[tostring(16)],"dun") then
as_b[i] = as_b[i] + as_b[i] * 0.02
end
-- ARMOUR BONUS FOR MAGIC RESISTANCE
if item == 3 or item == 6 then -- torso/head
if string.char(wl:get_grade(lm_gear_array[item])) == "h" then mr_ab[i] = mr_ab[i] + 30 end -- heavy gear
if string.char(wl:get_grade(lm_gear_array[item])) == "m" then mr_ab[i] = mr_ab[i] + 20 end -- medium gear
if string.char(wl:get_grade(lm_gear_array[item])) == "l" then mr_ab[i] = mr_ab[i] + 10 end -- light gear
elseif item == 7 then -- trousers
if string.char(wl:get_grade(lm_gear_array[item])) == "h" then mr_ab[i] = mr_ab[i] + 20 end -- heavy gear
if string.char(wl:get_grade(lm_gear_array[item])) == "m" then mr_ab[i] = mr_ab[i] + 10 end -- medium gear
elseif item == 4 or item == 5 then -- boots/gloves
if string.char(wl:get_grade(lm_gear_array[item])) == "h" then mr_ab[i] = mr_ab[i] + 10 end -- heavy gear
end
-- MITHRIL/CRYSTAL BONUS FOR MAGIC RESISTANCE
if me.race == 7 and get_material(lm_gear_array[item]) == 10 and lm_gear_item[tostring(7)] then
mr_ab[i] = mr_ab[i] + 10 + 10 * tonumber(lm_gear_item[tostring(7)])
elseif me.race == 7 and get_material(lm_gear_array[item]) == 10 then
mr_ab[i] = mr_ab[i] + 10
end
if get_material(lm_gear_array[item]) == 15 and lm_gear_item[tostring(7)] then
mr_ab[i] = mr_ab[i] + 10 + 10 * tonumber(lm_gear_item[tostring(7)])
elseif get_material(lm_gear_array[item]) == 15 then
mr_ab[i] = mr_ab[i] + 10
end
if item == 3 or item == 4 or item == 5 or item == 6 or item == 7 then -- gear
if string.char(wl:get_grade(lm_gear_array[item])) == "h" and me.race == 2 then -- orc
armour_weight[i] = armour_weight[i]
elseif string.char(wl:get_grade(lm_gear_array[item])) == "m" then
skill_bonus = math.max(fighter_sk, priest_sk)
armour_weight[i] = armour_weight[i] + wl:get_weight(lm_gear_array[item]) * (1 - skill_bonus / 100)
elseif string.char(wl:get_grade(lm_gear_array[item])) == "l" then
skill_bonus = math.max(rogue_sk, fighter_sk, priest_sk)
armour_weight[i] = armour_weight[i] + wl:get_weight(lm_gear_array[item]) * (1 - skill_bonus / 100)
elseif string.char(wl:get_grade(lm_gear_array[item])) == "u" then
armour_weight[i] = armour_weight[i]
else
armour_weight[i] = armour_weight[i] + wl:get_weight(lm_gear_array[item])
end
end
end
-- STRENGTH
str[i] = str[i] + me:get_str() - me:get_str_bonus()
str[i] = str[i] + str[i] * str_rb
-- DEXTERITY
dex[i] = dex[i] + me:get_dex() - me:get_dex_bonus()
dex[i] = dex[i] + dex[i] * dex_rb
-- INTELLIGENCE
int[i] = int[i] + me:get_intel() - me:get_intel_bonus()
int[i] = int[i] + int[i] * int_rb
-- HEALTH POINTS
hp[i] = hp[i] + str[i] / 2 + me.lvl * 1.5 + 10
hp[i] = hp[i] + hp[i] * hp_rb
-- DEFENSE (unarmed and unarmoured needs revision
if string.char(wl:get_grade(lm_gear_array[3])) == "a" or string.char(wl:get_grade(lm_gear_array[3])) == "u"
and string.char(wl:get_grade(lm_gear_array[4])) == "a" or string.char(wl:get_grade(lm_gear_array[4])) == "u"
and string.char(wl:get_grade(lm_gear_array[5])) == "a" or string.char(wl:get_grade(lm_gear_array[5])) == "u"
and string.char(wl:get_grade(lm_gear_array[6])) == "a" or string.char(wl:get_grade(lm_gear_array[6])) == "u"
and string.char(wl:get_grade(lm_gear_array[7])) == "a" or string.char(wl:get_grade(lm_gear_array[7])) == "u"
and wl:get_weapon_skill(lm_gear_array[1]) == 10 and wl:get_weapon_skill(lm_gear_array[2]) == 10 then
def[i] = def[i] + 10*(me:get_skill(sc:get_skill_nr("unarmed")))/100
end
def[i] = def[i] + 2*(me:get_skill(sc:get_skill_nr("tactics")))/100
-- MAGIC RESISTANCE
mr[i] = mr[i] + (int[i]^0.95) + me.lvl
if str[i]+dex[i] >= 250 then mr[i] = mr[i] + ((str[i] + dex[i] - 250) / 3) end
mr[i] = mr[i] + mr[i] * mr_rb
mr[i] = mr[i] + mr_ab[i]
-- MANA
mana[i] = mana[i] + int[i]
-- ATTACK STRENGTH
as[i] = as[i] + 20*me:get_skill(wl:get_weapon_skill(lm_gear_array[1]))/100
as[i] = as[i] + 7*(me:get_skill(sc:get_skill_nr("tactics")))/100
as[i] = as[i] + as_b[i] -- item bonus (dual wield needs to be considered and unarmed)
as[i] = as[i] * as_rb -- racial bonus
if wl:is_weapon(lm_gear_array[1]) and get_material(lm_gear_array[1]) == 0x9 or get_material(lm_gear_array[1]) == 0xe then
as[i] = as[i] * 1.2
end
if wl:get_wep_skill_name(lm_gear_array[1]) == "unarmed" or wl:get_wep_skill_name(lm_gear_array[1]) == "staves" then
SI = 0.5
if str[i] > 200 then
as[i] = as[i] + (str[i] - 200) / 33
end
elseif wl:get_wep_skill_name(lm_gear_array[1]) == "polearms" or wl:get_wep_skill_name(lm_gear_array[1]) == "maces" then
SI = 0.9
if str[i] > 200 then
as[i] = as[i] + (str[i] - 200) / 33
end
elseif wl:get_wep_skill_name(lm_gear_array[1]) == "longswords" or wl:get_wep_skill_name(lm_gear_array[1]) == "axes" then
SI = 0.75
if str[i] > 200 then
as[i] = as[i] + (str[i] - 200) / 33
end
elseif wl:get_wep_skill_name(lm_gear_array[1]) == "shortswords" or wl:get_wep_skill_name(lm_gear_array[1]) == "foils" or wl:get_wep_skill_name(lm_gear_array[1]) == "ranged" then
SI = 0.25
if dex[i] > 200 then
as[i] = as[i] + (dex[i] - 200) / 33
end
end
DI = 1 - SI
if dex[i] > 200 * DI then
as[i] = as[i] + (dex[i] - 200 * DI) * (1 - math.abs(dex[i]/(str[i]+dex[i])-DI)) / 33
end
if str[i] >= 200 * SI then
as[i] = as[i] + (str[i] - 200 * SI) * (1 - math.abs(str[i]/(str[i]+dex[i])-SI)) / 33
end
-- DAMAGE (by CHEDICH)
sdm = ((str[i]+dex[i])/5*(1-math.abs(str[i]/(str[i]+dex[i])-SI))) / 100
dmg[i] = ((((wl:get_no_dice(lm_gear_array[1])+(wl:get_no_sides(lm_gear_array[1])*wl:get_no_dice(lm_gear_array[1])))/2+((sdm*15.15)*(wl:get_speed(lm_gear_array[1])/wl:get_avg_wep_speed())))+(me:get_magic_modifier(MP_WEAPON_BONUS)*(wl:get_speed(lm_gear_array[1])/wl:get_avg_wep_speed())))*wl:get_material_dmg_mult(lm_gear_array[1],false))*1.1
if wl:is_weapon(lm_gear_array[2]) then
dmg[i] = (dmg[i] + ((((wl:get_no_dice(lm_gear_array[2])+(wl:get_no_sides(lm_gear_array[2])*wl:get_no_dice(lm_gear_array[2])))/2+((sdm*15.15)*(wl:get_speed(lm_gear_array[2])/wl:get_avg_wep_speed())))+(me:get_magic_modifier(MP_WEAPON_BONUS)*(wl:get_speed(lm_gear_array[2])/wl:get_avg_wep_speed())))*wl:get_material_dmg_mult(lm_gear_array[2],false))*1.1)/2
end
-- DPS (by CHEDICH)
delay[i] = wl:get_speed(lm_gear_array[1]) * ched_weap_skill_mod[wl:get_wep_skill_name(lm_gear_array[1])]
if (get_material(lm_gear_array[1])==MAT_COPPER) then
delay[i] = dps[i] * 0.9
end
dps[i] = dmg[i]*1000/delay[i]
-- SPEED
local p
if armour_weight[i] <= 7 then
p = 0.018 * (armour_weight[i] - 7)
else
p = 0.03 * (armour_weight[i] - 7)
end
if p > 0 then
p = p * ( 2 * armour_weight[i] * 7 - str[i]) / (armour_weight[i] * 7)
if p < 0 then p=0 end
end
if dex[i] > 250 then
speed[i] = 1000 / ((300) * (1 + p))
else
speed[i] = 1000 / (math.floor((79 * (250 - dex[1]) / 200 + 300) * (1 + p) + 0.5)) -- 79 was determined empirically
end
-- exchange old set with the highlighted item
if wl:is_weapon(get_highlighted_item()) then lm_gear_array[1] = get_highlighted_item()
elseif wl:is_shield(get_highlighted_item()) then lm_gear_array[2] = get_highlighted_item()
elseif wl:is_torso(get_highlighted_item()) then lm_gear_array[3] = get_highlighted_item()
elseif wl:is_boots(get_highlighted_item()) then lm_gear_array[4] = get_highlighted_item()
elseif wl:is_gloves(get_highlighted_item()) then lm_gear_array[5] = get_highlighted_item()
elseif wl:is_hat(get_highlighted_item()) then lm_gear_array[6] = get_highlighted_item()
elseif wl:is_trousers(get_highlighted_item()) then lm_gear_array[7] = get_highlighted_item()
elseif wl:is_ring(get_highlighted_item()) then lm_gear_array[8] = get_highlighted_item()
elseif wl:is_amulet(get_highlighted_item()) then lm_gear_array[10] = get_highlighted_item()
elseif wl:is_sigil(get_highlighted_item()) then lm_gear_array[11] = get_highlighted_item()
--elseif wl:is_sigil2(get_highlighted_item()) then lm_gear_array[12] = get_highlighted_item()
--elseif wl:is_sigil3(get_highlighted_item()) then lm_gear_array[13] = get_highlighted_item()
end
end
gp[2] = wl:get_sell_price(get_highlighted_item())
lm_oldstats = {hp[1],def[1],mr[1],str[1],dex[1],int[1],as[1],dmg[1],dps[1],enchant[1],leeching[1],mana[1],vig[1],speed[1],sight[1],material[1],dmgtype[1],grade[1],gp[1]}
lm_newstats = {hp[2],def[2],mr[2],str[2],dex[2],int[2],as[2],dmg[2],dps[2],enchant[2],leeching[2],mana[2],vig[2],speed[2],sight[2],material[2],dmgtype[2],grade[2],gp[2]}
for i, v in ipairs(lm_stat_names) do
if i == 16 or i == 17 or i == 18 or i == 19 then
auxbox_prop_line(string.format("%s", lm_oldstats[i]),string.format("->%12s", lm_newstats[i]))
elseif i == 10 then
auxbox_prop_line(string.format("%s", lm_stat_names[i]),string.format("%4s -> %5s ", lm_oldstats[i], lm_newstats[i]))
elseif i == 20 then break
else
local lm_stats_dif = lm_newstats[i] - lm_oldstats[i]
if lm_stats_dif > 0 then
lm_stats_operator = "{0f0}+"
elseif lm_stats_dif == 0 then
lm_stats_operator = " "
elseif lm_stats_dif < 0 then
lm_stats_operator = "{f00}-"
lm_stats_dif = math.abs(lm_stats_dif)
end
if i == 2 or i == 14 then
auxbox_prop_line(string.format("%s", lm_stat_names[i]),string.format("%5.1f -> %5.1f %s%4.1f{fff}", lm_oldstats[i], lm_newstats[i], lm_stats_operator, lm_stats_dif))
elseif i == 11 or i == 13 then
auxbox_prop_line(string.format("%s", lm_stat_names[i]),string.format("%4.f -> %5.f %s%4.f{fff}", lm_oldstats[i], lm_newstats[i], lm_stats_operator, lm_stats_dif))
else
auxbox_prop_line(string.format("%s", lm_stat_names[i]),string.format("%5.f -> %5.f %s%4.f{fff}", lm_oldstats[i], lm_newstats[i], lm_stats_operator, lm_stats_dif))
end
end
end
end
function ched_buymode_get_mp(item)
local t_mp = {}
t_mp[tostring(15)]=wl:get_grade_name(item)
t_mp[tostring(16)]=wl:get_short_material_name(item)
t_mp[tostring(17)]=wl:get_weapon_damage_type(item)
for i=0,14 do -- one iteration for each magprop
if wl:get_effect(item, i) then
for j=1,50 do --find magprop value
if wl:has_effect(item, i, j) then
if i == 8 then -- special handling for spell enchants
t_mp[tostring(i)]=spells:get_spell_str(j):upper()
else
t_mp[tostring(i)]=j
end
break
end
end
end
end
return t_mp
end