From 49e81c2e40dbc7a0837a0e2c89b38bf19637cdf7 Mon Sep 17 00:00:00 2001 From: Hachem_Muche <Hachem_Muche@stanfordalumni.org> Date: Mon, 22 May 2017 21:19:06 -0700 Subject: [PATCH] Update Object:getPowerRank for rares and greater egos. string.fromValue can take negative recursion level to get std tostring Remove debugging code --- game/engines/default/engine/utils.lua | 7 +- game/modules/tome/class/Actor.lua | 2 - game/modules/tome/class/GameState.lua | 3 - game/modules/tome/class/NPC.lua | 24 +----- game/modules/tome/class/Object.lua | 12 +-- .../tome/data/birth/classes/warrior.lua | 2 +- .../tome/data/talents/cunning/stealth.lua | 1 - game/modules/tome/resolvers.lua | 80 ++++--------------- 8 files changed, 23 insertions(+), 108 deletions(-) diff --git a/game/engines/default/engine/utils.lua b/game/engines/default/engine/utils.lua index e18c60ec9c..7678f53900 100644 --- a/game/engines/default/engine/utils.lua +++ b/game/engines/default/engine/utils.lua @@ -845,13 +845,14 @@ end -- similar to tostring, but includes special handling of tables and functions -- surrounds non-numbers/booleans/nils/functions with "" -- @param v: the value --- @param recurse: the recursion level for string.fromTable +-- @param recurse: the recursion level for string.fromTable, set < 0 for basic tostring -- @param offset, prefix, suffix: inputs to string.fromTable for converting tables function string.fromValue(v, recurse, offset, prefix, suffix) recurse, offset, prefix, suffix = recurse or 0, offset or ", ", prefix or "{", suffix or "}" local vt, vs = type(v) if vt == "table" then - if v.__ATOMIC or v.__CLASSNAME then -- create entity/atomic label + if recurse < 0 then vs = tostring(v) + elseif v.__ATOMIC or v.__CLASSNAME then -- create entity/atomic label local abv = {} if v.__CLASSNAME then abv[#abv+1] = "__CLASSNAME="..tostring(v.__CLASSNAME) end if v.__ATOMIC then abv[#abv+1] = "ATOMIC" end @@ -861,7 +862,7 @@ function string.fromValue(v, recurse, offset, prefix, suffix) else vs = prefix.."\""..tostring(v).."\""..suffix end elseif vt == "function" then - vs = string.fromFunction(v) + vs = recurse >= 0 and string.fromFunction(v) or tostring(v) elseif not (vt == "number" or vt == "boolean" or vt == "nil") then vs = "\""..tostring(v).."\"" end diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua index ba6904601a..8379f5cf11 100644 --- a/game/modules/tome/class/Actor.lua +++ b/game/modules/tome/class/Actor.lua @@ -4264,14 +4264,12 @@ function _M:wearAllInventory(force, ...) -- Note: won't remove slot_forbid items or auto-swap tinkers (Actor:doWear) if locs then o = self:removeObject(self.INVEN_INVEN, i) -- remove from main inventory -print("[Actor:wearAllInventory] possible inventories for", o.uid, o.name, locs) table.print(locs) -- debugging for j, inv in ipairs(locs) do local ro, worn = inv.inv[inv.slot] --print("\t\t attempting to wear", o.uid, o.name, "in", inv.inv.name, inv.slot) worn = self:wearObject(o, true, false, inv.inv, inv.slot) if worn then print("[Actor:wearAllInventory]", self.name, self.uid, o.uid, o.name, "WORN IN", inv.inv.name, inv.slot) -game.log("#YELLOW#[Actor:wearAllInventory]#LAST# %s[%s](%s,%s) wearing %s%s", self.name, self.uid, self.x, self.y, o:getName({do_color=true, no_add_name=true}), type(worn)=="table" and ", #YELLOW#REPLACING#LAST# "..worn:getName({do_color=true, no_add_name=true}) or "") -- debugging if type(worn) == "table" then print(" --- replaced:", worn.uid, worn.name) self:addObject(self.INVEN_INVEN, worn) diff --git a/game/modules/tome/class/GameState.lua b/game/modules/tome/class/GameState.lua index 3e1e6c17f4..f67934d1b2 100644 --- a/game/modules/tome/class/GameState.lua +++ b/game/modules/tome/class/GameState.lua @@ -424,9 +424,6 @@ function _M:generateRandart(data) local display = o.display ---o.baseobj = base:cloneFull() -- debugging code ---o.gendata = table.clone(data, true) -- debugging code - -- Load possible random powers local powers_list = engine.Object:loadList(o.randart_able, nil, nil, function(e) diff --git a/game/modules/tome/class/NPC.lua b/game/modules/tome/class/NPC.lua index 218b44ae72..97e37b0595 100644 --- a/game/modules/tome/class/NPC.lua +++ b/game/modules/tome/class/NPC.lua @@ -37,28 +37,6 @@ end _M._silent_talent_failure = true --- debugging: add some extra object resolvers to each NPC definition -local alter = function(e) --- if e.material_level then e.material_level = e.material_level + 5 end -end -function _M.loadList(self, file, no_default, res, mod, loaded) ---print("loading npc list with custom function") - local old_mod = mod - mod = function(e) - print("Custom modify called on:", e.name) - if old_mod then old_mod(e) end - if e.rarity and e.inven and #e.inven > 1 then - if e.inven[1] then e.inven[1].max = math.max(e.inven[1].max, 20) end - e:attr("max_encumber", 100) --- e[#e+1] = resolvers.equip{{properties={"slot"}, not_properties={"imbue_powers"}, alter=alter}} - e[#e+1] = resolvers.inventory{{properties={"slot"}, not_properties={"imbue_powers"}, alter=alter, ignore_material_restriction=true}} - e[#e+1] = resolvers.drops{nb=3, {properties={"slot"}, not_properties={"imbue_powers"}, alter=alter, ignore_material_restriction=true}} - end - end - return engine.Entity.loadList(self, file, no_default, res, mod, loaded) -end --- debugging - function _M:actBase() -- Reduce shoving pressure every turn if self.shove_pressure then @@ -496,7 +474,7 @@ function _M:addedToLevel(level, x, y) for tid, lev in pairs(self.talents) do self:learnTalent(tid, true, math.floor(lev / 2)) end - -- Give unrand bosses extra classes + -- Give randbosses extra classes if not self.randboss and self.rank >= 3.5 and not self.no_difficulty_random_class then local nb_classes = 0 if self.rank >= 10 then nb_classes = 3 diff --git a/game/modules/tome/class/Object.lua b/game/modules/tome/class/Object.lua index c232132336..9742de4c5b 100644 --- a/game/modules/tome/class/Object.lua +++ b/game/modules/tome/class/Object.lua @@ -484,8 +484,9 @@ function _M:getPowerRank() if self.godslayer then return 10 end if self.legendary then return 5 end if self.unique then return 3 end - if self.egoed and self.greater_ego or self.rare then return 2 end - if self.egoed then return 1 end + if self.egoed then + return math.min(2.5, 1 + (self.greater_ego and self.greater_ego or 0) + (self.rare and 1 or 0)) + end return 0 end @@ -2092,13 +2093,6 @@ function _M:getDesc(name_param, compare_with, never_compare, use_actor) self:triggerHook{"Object:descPowerSource", desc=desc, object=self} end --- debugging ---local weight_fn = function(o, inven) return (1 + o:getPowerRank()) * (o.material_level or 1) end ---local weight_fn = function(o, inven) return ((1 + o:getPowerRank())*(o.material_level or 1))^.5 end -local weight_fn = function(o, inven) return (1 + o:getPowerRank())*(o.material_level or 1) end -desc:add({"color", "ORCHID"}, ("Power Value: %2.1f"):format(weight_fn(self)) ,{"color", "LAST"}, true) --- debugging - if self.encumber then desc:add({"color",0x67,0xAD,0x00}, ("%0.2f Encumbrance."):format(self.encumber), {"color", "LAST"}) end diff --git a/game/modules/tome/data/birth/classes/warrior.lua b/game/modules/tome/data/birth/classes/warrior.lua index e81fee9c51..33106c0de8 100644 --- a/game/modules/tome/data/birth/classes/warrior.lua +++ b/game/modules/tome/data/birth/classes/warrior.lua @@ -338,7 +338,7 @@ newBirthDescriptor{ [ActorTalents.T_UNARMED_MASTERY] = 1, -- early game is absolutely stupid without this }, copy = { - resolvers.auto_equip_filters{-- will not try to equip weapons on birth + resolvers.auto_equip_filters{-- will not try to equip weapons MAINHAND = {type="none"}, OFFHAND = {type="none"} }, resolvers.equipbirth{ id=true, diff --git a/game/modules/tome/data/talents/cunning/stealth.lua b/game/modules/tome/data/talents/cunning/stealth.lua index 94fab053e7..3018fb2466 100644 --- a/game/modules/tome/data/talents/cunning/stealth.lua +++ b/game/modules/tome/data/talents/cunning/stealth.lua @@ -26,7 +26,6 @@ local function stealthDetection(self, radius, estimate) local dist = 0 local closest, detect = math.huge, 0 for i, act in ipairs(self.fov.actors_dist) do -print(("stealthDetection: checking actor %s at (%s, %s)"):format(act.name, act.x, act.y)) -- debugging test dist = core.fov.distance(self.x, self.y, act.x, act.y) if dist > radius then break end if act ~= self and act:reactionToward(self) < 0 and not act:attr("blind") and (not act.fov or not act.fov.actors or act.fov.actors[self]) and (not estimate or self:canSee(act)) then diff --git a/game/modules/tome/resolvers.lua b/game/modules/tome/resolvers.lua index 195cf45d15..6255fb419e 100644 --- a/game/modules/tome/resolvers.lua +++ b/game/modules/tome/resolvers.lua @@ -57,13 +57,13 @@ local Talents = require "engine.interface.ActorTalents" function resolvers.resolveObject(e, filter, do_wear, tries) if do_wear then do_wear = e.__is_actor and do_wear end filter = filter and table.clone(filter) or {} ---print("## general resolver using filter:", filter) table.print(filter) + tries = tries or do_wear and 5 or 2 + print("[resolveObject] CREATE FOR", e.uid, e.name, "do_wear/tries:", do_wear, tries, "filter:\n", (string.fromTable(filter, -1))) local o = filter._use_object if o then -- filter contains the object to use print("[resolveObject] using pre-generated object", o.uid, o.name) else - tries = tries or do_wear and 5 or 2 - --print("General Object resolver", e.name, "filter:", filter) table.print(filter, "\t") + --print("[resolveObject]", e.name, "filter:", filter) table.print(filter, "\t") local base_list if filter.base_list then -- load the base list defined for makeEntityByName local _, _, class, file = filter.base_list:find("(.*):(.*)") @@ -83,10 +83,9 @@ function resolvers.resolveObject(e, filter, do_wear, tries) local forced o, forced = game.zone:makeEntityByName(game.level, base_list or "object", filter.defined, filter.random_art_replace and true or false) if forced then -- If generation was forced, object is a previously existing unique - print("[resolveObject] FORCING UNIQUE (replaced on drop):", filter.defined, o.uid, o.name) + print("[resolveObject] FORCING UNIQUE (replaced on drop):", filter.defined, o.uid, o.name) table.set(filter, "random_art_replace", "chance", 100) elseif not o and filter.replace_unique then -- Replace with another object --- local rpl_filter = type(filter.replace_unique) == "table" and filter.replace_unique or nil local rpl_filter = filter.replace_unique if type(rpl_filter) ~= "table" then rpl_filter = table.clone(filter) @@ -100,18 +99,16 @@ function resolvers.resolveObject(e, filter, do_wear, tries) else -- make an object using the normal probabilities after applying the filter o = game.zone:makeEntity(game.level, base_list or "object", filter, nil, true) end --- print("##General Object resolver for ", e.name, "object:", o and o.name, "tries left:", tries) -- check for incompatible equipment if (do_wear or filter.check_antimagic) and not game.state:checkPowers(e, o, nil, "antimagic_only") then ok = false ---game.log("#YELLOW# object rejected for antimagic") print("[resolveObject] for ", e.uid, e.name ," -- incompatible equipment ", o.name, "retrying", tries, "self.not_power_source:", e.not_power_source and table.concat(table.keys(e.not_power_source), ","), "filter forbid ps:", filter.forbid_power_source and table.concat(table.keys(filter.forbid_power_source), ","), "vs ps", o.power_source and table.concat(table.keys(o.power_source), ",")) end until o and ok or tries <= 0 end - + if o then - print("[resolveObject] for ", e.name, "object:", o.uid, o.name, "tries left:", tries) + print("[resolveObject] CREATED OBJECT:", o.uid, o.name, "tries left:", tries) if filter.alter then filter.alter(o, e) end -- curse (done here to ensure object attributes get applied correctly, good place for a talent callback?) if do_wear ~= false and e.knowTalent and e:knowTalent(e.T_DEFILING_TOUCH) then @@ -119,8 +116,7 @@ function resolvers.resolveObject(e, filter, do_wear, tries) end if do_wear then - -- Auto alloc some talents, stats, and (possibly) levels to be able to wear the object - if filter.autoreq then + if filter.autoreq then -- Auto alloc talents, stats, and levels to be able to wear the object local req, oldreq = e:updateObjectRequirements(o) if req then if req.level and e.level < req.level then @@ -173,9 +169,8 @@ function resolvers.resolveObject(e, filter, do_wear, tries) invens = o:wornLocations(e, nil, nil) end if invens then ---print("[resolveObject] found inventory locations for", o.uid, o.name) table.print(invens) -- debugging for i, worn_inv in ipairs(invens) do - print("[resolveObject] trying inventory", worn_inv.inv.name, worn_inv.slot, "for", o.uid, o.name, worn_inv.force and "FORCED" or "unforced") + --print("[resolveObject] trying inventory", worn_inv.inv.name, worn_inv.slot, "for", o.uid, o.name, worn_inv.force and "FORCED" or "unforced") worn = e:wearObject(o, true, false, worn_inv.inv, worn_inv.slot) if worn == false then if worn_inv.force then -- force adding the object @@ -215,22 +210,11 @@ function resolvers.resolveObject(e, filter, do_wear, tries) if filter.force_drop then o.no_drop = false end if filter.never_drop then o.no_drop = true end --- debugging -o.no_unique_lore = true -- to not spam -o:identify(true) ---[[ -local inv, slot, attached = e:searchAllInventories(o, function(o, e, inven, slot, attached) - game.log("#GREY#General Object Resolver:#LAST# %s%s [%s] %s {%s, slot %s} at (%s, %s)", o:getName({do_color=true}), attached and (" (attached to: %s)"):format(attached:getName({do_color=true, no_add_name=true})) or "", e.uid, e.name, inven.name, slot, e.x, e.y) -end) ---]] --- debugging - if filter.random_art_replace then o.__special_boss_drop = filter.random_art_replace end else print("[resolveObject] **FAILED** for", e.uid, e.name, "filter:", (string.fromTable(filter, 2))) -game.log("[%s] %s #YELLOW_GREEN#Object resolver FAILED#LAST# \n#AQUAMARINE#filter:%s#LAST#", e.uid, e.name, string.fromTable(filter, 2)) -- debugging end return o end @@ -259,19 +243,11 @@ end function resolvers.calc.equip(t, e) -- Iterate over object filters, trying to create and equip each for i, filter in ipairs(t[1]) do - print("[resolvers.equip]", e.uid, e.name, (string.fromTable(filter, 1))) + --print("[resolvers.equip]", e.uid, e.name, (string.fromTable(filter, 1))) local o = resolvers.resolveObject(e, filter, true, 5) if o then -o.name = o.name.." <"..tostring(t.__resolver)..">" -- debugging o._resolver_type = t.__resolver if t[1].id then o:identify(t[1].id) end - --- debugging -local inv, slot, attached = e:searchAllInventories(o, function(o, e, inven, slot, attached) - game.log("#ORANGE#resolvers.equip:#LAST# %s%s [%s] %s {%s, slot %s} at (%s, %s)", o:getName({do_color=true}), attached and (" (attached to: %s)"):format(attached:getName({do_color=true, no_add_name=true})) or "", e.uid, e.name, inven.name, slot, e.x, e.y) -end) --- debugging - end end return nil -- Deletes the origin field @@ -300,7 +276,6 @@ function resolvers.calc.auto_equip_filters(t, e, readonly) local cc = table.get(engine.Birther.birth_descriptor_def, "subclass", c_name, "copy") if cc then print("[resolvers.auto_equip_filters] using birth descriptor for subclass:", c_name) -game.log("[%s] %s: #ORCHID#resolvers.auto_equip_filters:#LAST# %s", e.uid, e.name, c_name) -- debugging for i, res in ipairs(cc) do if type(res) == "table" and res.__resolver == "auto_equip_filters" then res = table.clone(res, true) @@ -312,7 +287,6 @@ game.log("[%s] %s: #ORCHID#resolvers.auto_equip_filters:#LAST# %s", e.uid, e.nam if not ok then print("[resolvers.auto_equip_filters] NO BIRTH auto_equip_filter for subclass:", c_name) end return end -game.log("[%s] %s: #ORCHID#resolvers.auto_equip_filters:#LAST# {%s}", e.uid, e.name, table.concat(table.keys(filters), ", ")) -- debugging for inv, filter in pairs(filters) do local inven = e:getInven(inv) if inven then @@ -351,13 +325,11 @@ end function resolvers.calc.attachtinker(t, e) -- Iterate over object filters, trying to create and attach each for i, filter in ipairs(t[1]) do - print("[resolvers.attachtinker]", e.uid, e.name, (string.fromTable(filter, 1))) + --print("[resolvers.attachtinker]", e.uid, e.name, (string.fromTable(filter, 1))) local o = resolvers.resolveObject(e, filter, false, 5) if o then -o.name = o.name.." <"..tostring(t.__resolver)..">" -- debugging o._resolver_type = t.__resolver - --print("Zone made us a Tinker according to filter!", o:getName()) - print("[resolvers.attachtinker] created tinker:", o.uid, o:getName()) + --print("[resolvers.attachtinker] created tinker:", o.uid, o:getName()) local base_inven, base_item = e:findTinkerSpot(o) local base_o = base_inven and base_item and base_inven[base_item] local ok @@ -374,11 +346,6 @@ o.name = o.name.." <"..tostring(t.__resolver)..">" -- debugging end end if ok then game.zone:addEntity(game.level, o, "object") end -- updates uniques list to prevent duplicates --- debugging -local inv, slot, attached = e:searchAllInventories(o, function(o, e, inven, slot, attached) - game.log("#ORANGE#resolvers.attachtinker:#LAST# %s%s [%s] %s {%s, slot %s} at (%s, %s)", o:getName({do_color=true}), attached and (" (attached to: %s)"):format(attached:getName({do_color=true, no_add_name=true})) or "", e.uid, e.name, inven.name, slot, e.x, e.y) -end) --- debugging end end return nil -- Deletes the origin field @@ -409,13 +376,12 @@ end -- @param t the resolver table created by resolvers.inventory -- @param e the entity (Actor) to add the objects to function resolvers.calc.inventory(t, e) - -- Iterate of object requests, try to create them and equip them + -- Iterate over object requests, try to create them and add them for i, filter in ipairs(t[1]) do - print("[resolvers.inventory]", e.uid, e.name, (string.fromTable(filter, 1))) + --print("[resolvers.inventory]", e.uid, e.name, (string.fromTable(filter, 1))) local o = resolvers.resolveObject(e, filter, false) if o then -o.name = o.name.." <"..tostring(t.__resolver)..">" -- debugging o._resolver_type = t.__resolver local inven = filter.inven or t[1].inven print("[resolvers.inventory] created object:", o.uid, o:getName(), "inventory:", inven, "keep:", filter.keep_object) @@ -433,13 +399,6 @@ o.name = o.name.." <"..tostring(t.__resolver)..">" -- debugging print("[resolvers.inventory] created object:", o.uid, o:getName(), "NOT ADDED") end end - --- debugging -local inv, slot, attached = e:searchAllInventories(o, function(o, e, inven, slot, attached) - game.log("#ORANGE#resolvers.inventory:#LAST# %s%s [%s] %s {%s, slot %s} at (%s, %s)", o:getName({do_color=true}), attached and (" (attached to: %s)"):format(attached:getName({do_color=true, no_add_name=true})) or "", e.uid, e.name, inven.name, slot, e.x, e.y) -end) --- debugging - end end return nil -- Delete the origin field @@ -472,18 +431,11 @@ function resolvers.calc.drops(t, e) filter.not_properties = filter.not_properties or {} filter.not_properties[#filter.not_properties+1] = "lore" end - print("[resolvers.drops]", e.uid, e.name, (string.fromTable(filter, 1))) + --print("[resolvers.drops]", e.uid, e.name, (string.fromTable(filter, 1))) local o = resolvers.resolveObject(e, filter, nil) if o then -o.name = o.name.." <drops>" -- debugging o._resolver_type = "drops" --- debugging -local inv, slot, attached = e:searchAllInventories(o, function(o, e, inven, slot, attached) - game.log("#ORANGE#resolvers.drops:#LAST# %s%s [%s] %s {%s, slot %s} at (%s, %s)", o:getName({do_color=true}), attached and (" (attached to: %s)"):format(attached:getName({do_color=true, no_add_name=true})) or "", e.uid, e.name, inven.name, slot, e.x, e.y) -end) --- debugging - o.no_drop = false -- make sure it is dropped if t.id ~= nil then o:identify(t.id) end end @@ -555,13 +507,9 @@ function resolvers.calc.drop_randart(t, e) o = game.state:generateRandart(data) end if o then -o.name = o.name.." <drop_randart>" -- debugging o._resolver_type = "drop_randart" o.no_drop = false if t.id then o:identify(t.id) end - -o:identify(true) -- debugging - if t.no_add then return o else -- GitLab