refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-29 13:44:18 +02:00
parent 4b8b0cd9d0
commit 2ea9a9d665
11 changed files with 126 additions and 122 deletions
+5 -5
View File
@@ -28,7 +28,7 @@ function LOAD()
event_listener('NEW_AUCTION_UPDATE', function()
for info in present(info.auction_sell_item()) do
for item_id in present(item_id(info.name)) do
_G.aux_merchant_sell[M.item_id(info.name)] = info.vendor_price / (M.info.max_item_charges(item_id) or info.count)
_G.aux_merchant_sell[M.item_id(info.name)] = info.vendor_price / (aux.info.max_item_charges(item_id) or info.count)
end
end
end)
@@ -86,7 +86,7 @@ function public.item_info(item_id)
local data_string = _G.aux_items[item_id]
if data_string then
local cached_data = persistence.read(items_schema, data_string)
return -object(
return T(
'name', cached_data.name,
'itemstring', 'item:'..item_id..':0:0:0',
'quality', cached_data.quality,
@@ -125,12 +125,12 @@ function merchant_buy_scan()
unit_price = min(buy_info.unit_price, new_unit_price)
end
_G.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, -object(
_G.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, T(
'unit_price', unit_price,
'limited', buy_info.limited and new_limited
))
else
_G.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, -object(
_G.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, T(
'unit_price', new_unit_price,
'limited', new_limited
))
@@ -161,7 +161,7 @@ function scan_wdb(item_id)
local name, _, quality, level, class, subclass, max_stack, slot, texture = GetItemInfo(itemstring)
if name and not _G.aux_item_ids[strlower(name)] then
_G.aux_item_ids[strlower(name)] = item_id
_G.aux_items[item_id] = persistence.write(items_schema, -object(
_G.aux_items[item_id] = persistence.write(items_schema, T(
'name', name,
'quality', quality,
'level', level,
+2 -2
View File
@@ -39,7 +39,7 @@ do
end
function LOAD()
ARMOR = -set(
ARMOR = set(
'INVTYPE_HEAD',
'INVTYPE_NECK',
'INVTYPE_SHOULDER',
@@ -56,7 +56,7 @@ function LOAD()
'INVTYPE_CLOAK',
'INVTYPE_HOLDABLE'
)
WEAPON = -set(
WEAPON = set(
'INVTYPE_2HWEAPON',
'INVTYPE_WEAPONMAINHAND',
'INVTYPE_WEAPON',
+8 -8
View File
@@ -17,19 +17,19 @@ do
end
do
local time = 0
local cache = 0
function private.next_push.get()
if time() > time then
if time() > cache then
local date = date('*t')
date.hour, date.min, date.sec = 24, 0, 0
time = time(date)
cache = time(date)
end
return time
return cache
end
end
function private.new_record.get()
return -object('next_push', next_push, 'data_points', t)
return T('next_push', next_push, 'data_points', t)
end
function read_record(item_key)
@@ -78,7 +78,7 @@ function public.value(item_key)
for _, data_point in item_record.data_points do
local weight = .99 ^ round((item_record.data_points[1].time - data_point.time) / (60 * 60 * 24))
total_weight = total_weight + weight
tinsert(weighted_values, -object('value', data_point.market_value, 'weight', weight))
tinsert(weighted_values, T('value', data_point.market_value, 'weight', weight))
end
for _, weighted_value in weighted_values do
weighted_value.weight = weighted_value.weight / total_weight
@@ -87,7 +87,7 @@ function public.value(item_key)
else
value = calculate_market_value(item_record)
end
value_cache[item_key] = -object('value', value, 'next_push', item_record.next_push)
value_cache[item_key] = T('value', value, 'next_push', item_record.next_push)
end
return value_cache[item_key].value
end
@@ -113,7 +113,7 @@ end
function push_record(item_record)
for market_value in present(calculate_market_value(item_record)) do
tinsert(item_record.data_points, 1, -object('market_value', market_value, 'time', item_record.next_push))
tinsert(item_record.data_points, 1, T('market_value', market_value, 'time', item_record.next_push))
while getn(item_record.data_points) > 11 do
tremove(item_record.data_points)
end