Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Autopickup single one of an item based on subtype or basename.
- -- (aux armours, buckler/shield, blowgun etc.)
- -- Smart needle pickup. (Until blowgun is found, and while kept in inventory.)
- -- Doesn't work if item's name/subtype isn't known before picking it up.
- -- Ignores useless items.
- -- -- Config
- local pickup_one_subtypes = { "cloak", "boots", "helmet", "gloves" }
- local pickup_one_basenames = { "blowgun", "buckler" }
- local pickup_needles_smart = true
- if you.genus() == "troll" or you.genus() == "ogre" then
- table.insert(pickup_one_basenames, "shield")
- end
- -- -- Helper functions
- local function Set(list)
- local set = {}
- for _, l in ipairs(list) do set[l] = true end
- return set
- end
- local function get_subtype(item)
- local subtype, _ = item.subtype()
- return subtype
- end
- local function get_basename(item)
- if item.artefact then
- local name = item.name("base")
- return name:gsub(" \".-\"$", "")
- else
- return item.name("base")
- end
- end
- local function inventory_match(item_func, value)
- for item in iter.invent_iterator:new(items.inventory()) do
- if item_func(item) == value then
- return item
- end
- end
- return nil
- end
- local function check_item(item)
- if pickup_one_subtypes[get_subtype(item)] then
- c_persist.pickup_one.got_subtype[get_subtype(item)] = true
- end
- if get_basename(item) == "blowgun" or
- pickup_one_basenames[get_basename(item)] then
- c_persist.pickup_one.got_basename[get_basename(item)] = true
- end
- end
- -- -- Interfacing with the game
- local initialized = false
- local function pickup_one(item, name)
- if not initialized then return end
- if item.is_useless then
- return false
- end
- if pickup_one_subtypes[get_subtype(item)] and
- not c_persist.pickup_one.got_subtype[get_subtype(item)] then
- return true
- end
- if pickup_one_basenames[get_basename(item)] and
- not c_persist.pickup_one.got_basename[get_basename(item)] then
- return true
- end
- if pickup_needles_smart and name:find("needle") then
- if not c_persist.pickup_one.got_basename["blowgun"] or
- inventory_match(get_basename, "blowgun") then
- return true
- end
- end
- end
- add_autopickup_func(pickup_one)
- function c_assign_invletter(item)
- check_item(item)
- end
- function ready()
- if not initialized then
- pickup_one_subtypes = Set(pickup_one_subtypes)
- pickup_one_basenames = Set(pickup_one_basenames)
- if you.turns() == 0 or c_persist.pickup_one == nil then
- c_persist.pickup_one = {}
- c_persist.pickup_one.got_subtype = {}
- c_persist.pickup_one.got_basename = {}
- for item in iter.invent_iterator:new(items.inventory()) do
- check_item(item)
- end
- end
- initialized = true
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment