@@ -1,4 +1,4 @@ | |||
items = { | |||
itemdb = { | |||
{"entry",25,"class",2,"subclass",7,"name","Worn Shortsword","InventoryType",21,"ItemLevel",2,"RequiredLevel",1,"dmg_min1",1.0,"dmg_max1",3.0,"mobs","Talonsworn Forest-Rager,Crazed Murkblood Miner,Wyrmcult Zealot,Bloodmaul Warlock",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1900}, | |||
{"entry",35,"class",2,"subclass",10,"name","Bent Staff","InventoryType",17,"ItemLevel",2,"RequiredLevel",1,"dmg_min1",3.0,"dmg_max1",5.0,"mobs","",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2900}, | |||
{"entry",36,"class",2,"subclass",4,"name","Worn Mace","InventoryType",21,"ItemLevel",2,"RequiredLevel",1,"dmg_min1",1.0,"dmg_max1",3.0,"mobs","",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1900}, | |||
@@ -24219,5 +24219,5 @@ items = { | |||
{"entry",11042,"class",2,"subclass",7,"name","","InventoryType",13,"ItemLevel",0,"RequiredLevel",0,"dmg_min1",0.0,"dmg_max1",0.0,"mobs","",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1000}, | |||
{"entry",11087,"class",2,"subclass",8,"name","","InventoryType",13,"ItemLevel",0,"RequiredLevel",0,"dmg_min1",0.0,"dmg_max1",0.0,"mobs","",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1000}, | |||
{"entry",30452,"class",2,"subclass",2,"name","","InventoryType",15,"ItemLevel",0,"RequiredLevel",0,"dmg_min1",0.0,"dmg_max1",0.0,"mobs","",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1000}, | |||
{"entry",2704,"class",2,"subclass",4,"name","","InventoryType",13,"ItemLevel",0,"RequiredLevel",0,"dmg_min1",0.0,"dmg_max1",0.0,"mobs","",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1000}, | |||
} | |||
{"entry",2704,"class",2,"subclass",4,"name","","InventoryType",13,"ItemLevel",0,"RequiredLevel",0,"dmg_min1",0.0,"dmg_max1",0.0,"mobs","",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1000} | |||
} |
@@ -1,4 +1,10 @@ | |||
;; coll utils | |||
;; init note | |||
(if (> 1 (# itemdb)) | |||
(print "Failed to load item database") | |||
(print "Item database loaded")) | |||
;; 1a: coll utils | |||
(fn length-of [coll] | |||
(if coll | |||
@@ -13,7 +19,7 @@ | |||
(let [key (next coll)] | |||
(. coll key))) | |||
;; str utils | |||
;; 1b: str utils | |||
(fn starts-with [s patt] | |||
(= (string.sub s 1 (string.len patt)) patt)) | |||
@@ -21,12 +27,12 @@ | |||
(fn un-quote [s] | |||
(string.gsub s "\'" "")) | |||
;; number utils | |||
;; 1c: number utils | |||
(fn max [a b] | |||
(if (> a b) a b)) | |||
;; fennel utils | |||
;; 1d: fennel utils | |||
(fn matches [a b] | |||
(if (starts-with a "lte:") | |||
@@ -43,10 +49,10 @@ | |||
(= a b))) | |||
;; querying | |||
;; 2a: querying | |||
(lambda find-items [params ?sort] | |||
(let [results (icollect [_ row (ipairs items)] | |||
(let [results (icollect [_ row (ipairs itemdb)] | |||
(do | |||
(var hit true) | |||
(each [key param (pairs params)] | |||
@@ -63,9 +69,9 @@ | |||
(lambda find-item [params ?sort] | |||
(let [results (find-items params ?sort)] | |||
(if results | |||
(first results)))) | |||
(. results 1)))) | |||
;; specialized querying | |||
;; 2b: specialized querying | |||
(fn find-item-by-name [name] | |||
(find-item {8 name})) | |||
@@ -87,16 +93,22 @@ | |||
stat-position (string.format "gte:%d" stat-baseline)} | |||
?sort)) | |||
;; arg parsing | |||
;; 3b: specialized parsing | |||
(fn parse-item-id [link] | |||
(tonumber (string.sub (string.match link "item:[%d+]+") 6))) | |||
;; 3c: arg parsing | |||
(fn parse-opts [msg] | |||
(icollect [k v (string.gmatch msg "%w+")] v)) | |||
;; ui | |||
;; 4a: ui | |||
(fn ui-print [msg] | |||
(UIErrorsFrame:AddMessage msg)) | |||
;; 4b | |||
(fn stat-name [n] | |||
(let [stat-names ["Mana" "Health" "No Visible Effect" | |||
"Agility" "Strength" "Intellect" | |||
@@ -132,7 +144,7 @@ | |||
(set val (.. val " " (stat-name (- n 21)) ": " (. item n))))) | |||
val) | |||
;; main | |||
;; 5: main | |||
(global | |||
main | |||
@@ -147,10 +159,9 @@ | |||
inv-slot (GetInventorySlotInfo slot) | |||
i-link (GetInventoryItemLink "player" inv-slot) | |||
i-id (if i-link (parse-item-id i-link)) | |||
p-level (UnitLevel "player")] | |||
;; (print (string.format "slot %s stat %s gear-index %s" slot stat gear-index)) | |||
(if (not i-link) | |||
;; empty | |||
(let [best (. | |||
@@ -183,7 +194,6 @@ | |||
i-level (. stats 12) | |||
i-stat (. stats stat) | |||
best (. (find-next-better-item i-class i-subclass i-invtype p-level i-level stat (max i-stat 1) (fn [a b] (< (. a stat) (. b stat)))) gear-index)] | |||
(if best | |||
(do | |||
(DEFAULT_CHAT_FRAME:AddMessage (string.format "\124Hitem:%d:0:0:0:0:0:0:0:0\124h[%s]\124h\124r" (. best 2) (. best 8))) | |||
@@ -194,9 +204,11 @@ | |||
" at " | |||
(or (. best 20)) "N/A")) | |||
(ui-print (.. "currently equipped " i-name " " (or (. stats stat) "N/A"))))))) | |||
(ui-print (.. "currently equipped " i-name " " (or (. stats stat) "N/A")))))) | |||
(print (.. "Item " (un-quote i-name) " not found"))) | |||
"ok"))))) | |||
;; unused | |||
(fn maxxed [] | |||
(let [slots ["AmmoSlot" | |||
"BackSlot" | |||
@@ -1,3 +1,8 @@ | |||
if (1 > #itemdb) then | |||
print("Failed to load item database") | |||
else | |||
print("Item database loaded") | |||
end | |||
local function length_of(coll) | |||
if coll then | |||
local c = 0 | |||
@@ -40,12 +45,12 @@ local function matches(a, b) | |||
end | |||
end | |||
local function find_items(params, _3fsort) | |||
_G.assert((nil ~= params), "Missing argument params on main.fnl:48") | |||
_G.assert((nil ~= params), "Missing argument params on main.fnl:54") | |||
local results | |||
do | |||
local tbl_17_auto = {} | |||
local i_18_auto = #tbl_17_auto | |||
for _, row in ipairs(items) do | |||
for _, row in ipairs(itemdb) do | |||
local val_19_auto | |||
do | |||
local hit = true | |||
@@ -74,10 +79,10 @@ local function find_items(params, _3fsort) | |||
end | |||
end | |||
local function find_item(params, _3fsort) | |||
_G.assert((nil ~= params), "Missing argument params on main.fnl:63") | |||
_G.assert((nil ~= params), "Missing argument params on main.fnl:69") | |||
local results = find_items(params, _3fsort) | |||
if results then | |||
return first(results) | |||
return results[1] | |||
else | |||
return nil | |||
end | |||
@@ -89,12 +94,15 @@ local function find_next_better_item(class, subclass, invtype, lv, ilv, stat_pos | |||
return find_items({[4] = class, [6] = subclass, [10] = invtype, [14] = string.format("lte:%d", lv), [stat_position] = string.format("gt>:%d", item_stat)}, _3fsort) | |||
end | |||
local function find_good_item(invtype, lv, stat_position, stat_baseline, _3fsort) | |||
_G.assert((nil ~= stat_baseline), "Missing argument stat-baseline on main.fnl:83") | |||
_G.assert((nil ~= stat_position), "Missing argument stat-position on main.fnl:83") | |||
_G.assert((nil ~= lv), "Missing argument lv on main.fnl:83") | |||
_G.assert((nil ~= invtype), "Missing argument invtype on main.fnl:83") | |||
_G.assert((nil ~= stat_baseline), "Missing argument stat-baseline on main.fnl:89") | |||
_G.assert((nil ~= stat_position), "Missing argument stat-position on main.fnl:89") | |||
_G.assert((nil ~= lv), "Missing argument lv on main.fnl:89") | |||
_G.assert((nil ~= invtype), "Missing argument invtype on main.fnl:89") | |||
return find_items({[10] = invtype, [14] = string.format("lte:%d", lv), [stat_position] = string.format("gte:%d", stat_baseline)}, _3fsort) | |||
end | |||
local function parse_item_id(link) | |||
return tonumber(string.sub(string.match(link, "item:[%d+]+"), 6)) | |||
end | |||
local function parse_opts(msg) | |||
local tbl_17_auto = {} | |||
local i_18_auto = #tbl_17_auto | |||
@@ -140,22 +148,28 @@ local function main0(msg) | |||
end | |||
opts = tbl_17_auto | |||
end | |||
local _let_11_ = opts | |||
local slot = _let_11_[1] | |||
local stat = _let_11_[2] | |||
local gear_index = _let_11_[3] | |||
local _let_12_ = opts | |||
local slot = _let_12_[1] | |||
local stat = _let_12_[2] | |||
local gear_index = _let_12_[3] | |||
local slot0 = (slot .. "Slot") | |||
local stat0 = (21 + tonumber(stat)) | |||
local gear_index0 = tonumber((gear_index or "1")) | |||
local inv_slot = GetInventorySlotInfo(slot0) | |||
local i_link = GetInventoryItemLink("player", inv_slot) | |||
local i_id | |||
if i_link then | |||
i_id = parse_item_id(i_link) | |||
else | |||
i_id = nil | |||
end | |||
local p_level = UnitLevel("player") | |||
if not i_link then | |||
local best | |||
local function _12_(a, b) | |||
local function _14_(a, b) | |||
return ((a[stat0] < b[stat0]) and (a[12] < b[12])) | |||
end | |||
best = (find_good_item(inv_slot, UnitLevel("player"), stat0, 1, _12_))[gear_index0] | |||
best = (find_good_item(inv_slot, UnitLevel("player"), stat0, 1, _14_))[gear_index0] | |||
if best then | |||
DEFAULT_CHAT_FRAME:AddMessage(string.format("|Hitem:%d:0:0:0:0:0:0:0:0|h[%s]|h|r", best[2], best[8])) | |||
return ui_print(("next best available: " .. best[8] .. " " .. stat_print(best) .. " at " .. best[20] .. "N/A")) | |||
@@ -172,10 +186,10 @@ local function main0(msg) | |||
local i_level = stats[12] | |||
local i_stat = stats[stat0] | |||
local best | |||
local function _14_(a, b) | |||
local function _16_(a, b) | |||
return (a[stat0] < b[stat0]) | |||
end | |||
best = (find_next_better_item(i_class, i_subclass, i_invtype, p_level, i_level, stat0, max(i_stat, 1), _14_))[gear_index0] | |||
best = (find_next_better_item(i_class, i_subclass, i_invtype, p_level, i_level, stat0, max(i_stat, 1), _16_))[gear_index0] | |||
if best then | |||
DEFAULT_CHAT_FRAME:AddMessage(string.format("|Hitem:%d:0:0:0:0:0:0:0:0|h[%s]|h|r", best[2], best[8])) | |||
ui_print(("next best available: " .. best[8] .. " " .. stat_print(best) .. " at " .. best[20] .. "N/A")) | |||
@@ -183,6 +197,7 @@ local function main0(msg) | |||
else | |||
end | |||
else | |||
print(("Item " .. un_quote(i_name) .. " not found")) | |||
end | |||
return "ok" | |||
end | |||