From 71771310adcef2311561ff688f818652db513ca9 Mon Sep 17 00:00:00 2001 From: raymoo Date: Sat, 23 Jan 2016 15:21:56 -0800 Subject: [PATCH] Many fixes --- effect_set.lua | 18 +++++++++--------- init.lua | 36 +++++++++++++++++++++++------------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/effect_set.lua b/effect_set.lua index d08e004..9aa2975 100644 --- a/effect_set.lua +++ b/effect_set.lua @@ -63,7 +63,7 @@ local function setmap_get(setmap, index) end -local function setmap_insert(setmap, indices, uid) +local function setmap_insert(setmap, indices, uid, record) for index, v in pairs(indices) do local set = setmap[index] @@ -73,14 +73,14 @@ local function setmap_insert(setmap, indices, uid) setmap[index] = set end - set[uid] = true + set[uid] = record end end local function setmap_delete(setmap, indices, uid) - for k, index in pairs(indices) do + for index, v in pairs(indices) do local set = setmap[index] if set ~= nil then @@ -101,7 +101,7 @@ local function set_intersect(set1,set2) local res_set = {} - for k, rec in pairs(set1) do + for k in pairs(set1) do res_set[k] = set2[k] end @@ -238,14 +238,14 @@ end -- Mutates the DB to have the new record local function insert_record_with_uid(uid, db, record) db.uid_table[uid] = record - setmap_insert(db.tables.player, record.players, uid) - setmap_insert(db.tables.tag, record.tags, uid) - setmap_insert(db.tables.monoid, record.monoids, uid) - setmap_insert(db.tables.name, {[record.effect_type] = true}, uid) + setmap_insert(db.tables.player, record.players, uid, record) + setmap_insert(db.tables.tag, record.tags, uid, record) + setmap_insert(db.tables.monoid, record.monoids, uid, record) + setmap_insert(db.tables.name, {[record.effect_type] = true}, uid, record) local perm = is_perm(record) - setmap_insert(db.tables.perm, {[perm] = true}, uid) + setmap_insert(db.tables.perm, {[perm] = true}, uid, record) end diff --git a/init.lua b/init.lua index a04ed76..b930ddf 100644 --- a/init.lua +++ b/init.lua @@ -78,7 +78,17 @@ local function calculate_monoid_value(p_name, m_name) local p_m_effects = effectset.set_intersect(p_effects, m_effects) - + for k, rec in pairs(p_m_effects) do + local eff_type = rec.effect_type + local type_def = types[eff_type] + + if type_def ~= nil then + if type_def.values[m_name] ~= nil then + p_m_effects[k] = type_def.values[m_name] + end + end + end + local fold = monoids[m_name].fold local res = fold(p_m_effects) @@ -356,14 +366,14 @@ monoidal_effects.apply_effect = function(effect_type, dur, player_name, values) local dyn = type_def.dynamic - local players = {player_name} + local players = {[player_name] = "true"} local tags = type_def.tags local t_monoids = type_def.monoids local record = - effectset.record(dyn, effect_type, players, tags, monoids, dur, values) + effectset.record(dyn, effect_type, players, tags, t_monoids, dur, values) local p_cache = monoid_cache[player_name] @@ -435,7 +445,7 @@ monoidal_effects.cancel_effect = function(uid) local effect = effects:get(uid) local players = effect.players - local monoids = effect.monoids + local eff_monoids = effect.monoids for i, player in ipairs(all_players) do local p_name = player:get_player_name() @@ -451,8 +461,8 @@ monoidal_effects.cancel_effect = function(uid) for p_name in pairs(player_set) do old_vals[p_name] = {} local p_vals = old_vals[p_name] - for monoid in pairs(monoids) do - p_vals[monoid] = get_monoid_value(monoid, player) + for monoid in pairs(eff_monoids) do + p_vals[monoid] = get_monoid_value(monoid, p_name) end end @@ -460,9 +470,9 @@ monoidal_effects.cancel_effect = function(uid) for p_name, player in pairs(player_set) do local p_vals = old_vals[p_name] - for monoid in pairs(monoids) do + for monoid in pairs(eff_monoids) do clear_cache(monoid, p_name) - local val = get_monoid_value(p_name, monoid) + local val = get_monoid_value(monoid, p_name) local mon_def = monoids[monoid] if (mon_def == nil) then @@ -476,9 +486,9 @@ monoidal_effects.cancel_effect = function(uid) if p_huds ~= nil then local hudinfo = p_huds[uid] if hudinfo ~= nil then - player:remove_hud(hudinfo.text) + player:hud_remove(hudinfo.text) if hudinfo.icon ~= nil then - player:remove_hud(hudinfo.icon) + player:hud_remove(hudinfo.icon) end end p_huds[uid] = nil @@ -554,7 +564,7 @@ local function apply_effects(player) local p_effects = monoidal_effects.get_player_effects(p_name) - local monoids = {} + local eff_monoids = {} for uid in pairs(p_effects) do @@ -563,12 +573,12 @@ local function apply_effects(player) if (effect ~= nil) then for monoid in pairs(effect.monoids) do - monoids[monoid] = true + eff_monoids[monoid] = true end end end - for monoid in pairs(monoids) do + for monoid in pairs(eff_monoids) do local mon_def = monoids[monoid] if (mon_def ~= nil) then