##
## CONFIG.lua
################################################################################################
{
-- Global CONFIG for customizing RC behaviors
CONFIG = { }
CONFIG.emojis = true
}
##
## BEGIN
################################################################################################
: rc_msg("Initializing magus.rc ...")
: crawl.enable_more(false)
##
## Globals/Globals.rc
################################################################################################
# PAUSE variable for ForceMorePrompts.rc
$PAUSE_MORE := PAUSE
##
## Globals/Globals.lua
################################################################################################
{
-- Pause for AnnounceDamage.lua
PAUSE_MORE = "PAUSE"
-- Standard Colors (ignoring black, not visible)
COLORS = { }
COLORS.lightgrey = "lightgrey"
COLORS.white = "white"
COLORS.blue = "blue"
COLORS.lightblue = "lightblue"
COLORS.green = "green"
COLORS.lightgreen = "lightgreen"
COLORS.cyan = "cyan"
COLORS.lightcyan = "lightcyan"
COLORS.red = "red"
COLORS.lightred = "lightred"
COLORS.magenta = "magenta"
COLORS.lightmagenta = "lightmagenta"
COLORS.yellow = "yellow"
COLORS.brown = "brown"
}
##
## Utils.lua
################################################################################################
{
function withColor(color, str)
return string.format("<%s>%s%s>", color, str, color)
end
function rc_out(symbol, color, msg, channel)
-- crawl_mpr source
-- https://sourcegraph.com/search?q=context%3Aglobal+repo%3A%5Egithub%5C.com%2Fcrawl%2Fcrawl%24+file%3A%5Ecrawl-ref%2Fsource%2Fl-crawl%5C.cc+crawl_mpr&patternType=standard&sm=1&groupBy=path
--
-- static const string message_channel_names[] =
-- {
-- "plain", "friend_action", "prompt", "god", "duration", "danger", "warning",
-- "recovery", "sound", "talk", "talk_visual", "intrinsic_gain",
-- "mutation", "monster_spell", "monster_enchant", "friend_spell",
-- "friend_enchant", "monster_damage", "monster_target", "banishment",
-- "equipment", "floor", "multiturn", "examine", "examine_filter", "diagnostic",
-- "error", "tutorial", "orb", "timed_portal", "hell_effect", "monster_warning",
-- "dgl_message",
-- };
crawl.mpr(string.format("%s %s", symbol, withColor(color, msg)), channel)
end
function rc_msg(msg)
rc_out("๐ค", "blue", msg, "diagnostic")
end
function rc_scs(msg)
rc_out("โ
", "green", msg, "diagnostic")
end
function rc_err(msg)
rc_out("โ", "lightred", msg, "danger")
end
function rc_warn(msg)
rc_out("โ ๏ธ", "yellow", msg, "warning")
end
function table_has(table, match)
for index, value in ipairs(table) do
if value == match then
return true
end
end
return false
end
}
##
## AnnounceDamage.lua
################################################################################################
###############
# Damage Calc #
###############
{
local previous_hp = 0
local previous_mp = 0
local previous_form = ""
local was_berserk_last_turn = false
-- Helper function to generate status messages and reduce code duplication.
local function announce_change(change_type, diff, current, max)
local percentage = current / max
local status_color
local template
if change_type == "hp_loss" then
if percentage <= 0.30 then status_color = "lightred"
elseif percentage <= 0.50 then status_color = "red"
elseif percentage <= 0.70 then status_color = "yellow"
elseif percentage <= 0.90 then status_color = "lightgrey"
else status_color = "green" end
--template = "You take %d damage,<%s> and have %d/%d hp.%s>"
template = "%d ๋งํผ hp ํผํด,<%s> ํ์ฌ hp %d/%d.%s>"
crawl.mpr(string.format(template, diff, status_color, current, max, status_color))
elseif change_type == "hp_gain" then
if percentage <= 0.30 then status_color = "lightred"
elseif percentage <= 0.50 then status_color = "red"
elseif percentage <= 0.70 then status_color = "yellow"
elseif percentage <= 0.90 then status_color = "lightgrey"
else status_color = "green" end
--template = "You regained %d hp,<%s> and now have %d/%d hp.%s>"
template = "%d ๋งํผ hp ํ๋ณต,<%s> ํ์ฌ hp %d/%d.%s>"
crawl.mpr(string.format(template, diff, status_color, current, max, status_color))
elseif change_type == "mp_gain" then
if percentage < 0.25 then status_color = "red"
elseif percentage < 0.50 then status_color = "yellow"
else status_color = "green" end
--template = "You regained %d mp,<%s> and now have %d/%d mp.%s>"
template = "%d ๋งํผ mp ํ๋ณต,<%s> ํ์ฌ mp %d/%d.%s>"
crawl.mpr(string.format(template, diff, status_color, current, max, status_color))
elseif change_type == "mp_loss" then
if percentage <= (max / 5) then status_color = "red"
elseif percentage <= (max / 2) then status_color = "yellow"
else status_color = "green" end
--template = "You now have <%s>%d/%d mp.%s>"
template = "ํ์ฌ mp<%s>%d/%d.%s>"
-- The original message for losing MP doesn't include the difference amount.
crawl.mpr(string.format(template, status_color, current, max, status_color))
end
end
function AnnounceDamage()
local current_hp, max_hp = you.hp()
local current_mp, max_mp = you.mp()
local current_form = you.transform()
local you_are_berserk = you.berserk()
local max_hp_increased = false
local max_hp_decreased = false
if (current_form ~= previous_form) then
if (previous_form:find("dragon") or
previous_form:find("statue") or
previous_form:find("tree") or
previous_form:find("ice")) then
max_hp_decreased = true
elseif (current_form:find("dragon") or
current_form:find("statue") or
current_form:find("tree") or
current_form:find("ice")) then
max_hp_increased = true
end
end
if (was_berserk_last_turn and not you_are_berserk) then
max_hp_decreased = true
elseif (you_are_berserk and not was_berserk_last_turn) then
max_hp_increased = true
end
--Skips message on initializing game
if previous_hp > 0 then
if max_hp_increased or max_hp_decreased then
if max_hp_increased then
crawl.mpr("ํ์ฌ " .. current_hp .. "/" .. max_hp .. " hp.")
else
crawl.mpr("ํ์ฌ " .. current_hp .. "/" .. max_hp .. " hp.")
end
else
--On losing health
if (current_hp < previous_hp) then
local hp_difference = previous_hp - current_hp
announce_change("hp_loss", hp_difference, current_hp, max_hp)
if hp_difference > (max_hp * 0.20) then
crawl.mpr("์
! ์ด๊ฑด ์ ๋ง๋ก ์ํ๋ค!")
end
end
--On gaining more than 1 health
if (current_hp > previous_hp) then
local health_gained = current_hp - previous_hp
if (health_gained > 1) and not (current_hp == max_hp) then
announce_change("hp_gain", health_gained, current_hp, max_hp)
end
if (current_hp == max_hp) then
crawl.mpr("hp ๊ฐ๋ ์ฐธ: " .. current_hp .. "")
end
end
--On gaining more than 1 magic
if (current_mp > previous_mp) then
local mp_gained = current_mp - previous_mp
if (mp_gained > 1) and not (current_mp == max_mp) then
announce_change("mp_gain", mp_gained, current_mp, max_mp)
end
if (current_mp == max_mp) then
crawl.mpr("mp ๊ฐ๋ ์ฐธ: " .. current_mp .. "")
end
end
--On losing magic
if current_mp < previous_mp then
local mp_difference = previous_mp - current_mp
announce_change("mp_loss", mp_difference, current_mp, max_mp)
end
end
end
--Set previous hp/mp and form at end of turn
previous_hp = current_hp
previous_mp = current_mp
previous_form = current_form
was_berserk_last_turn = you_are_berserk
end
}
##
## OpenSkills.lua
################################################################################################
{
-- Open skills menu at start of runs
local is_gnoll = table_has({"Gnoll"}, you.race())
local need_skills_opened = not is_gnoll
local function start_open_skills()
if you.turns() == 0 and need_skills_opened then
need_skills_opened = false
crawl.sendkeys("m")
end
end
-- Runs once when parsed during rc init
start_open_skills()
}
##
## PickupEquipment.lua
################################################################################################
{
-- ์ด ๋ณ์๋ค์ ํ์ฌ ์คํฌ๋ฆฝํธ์์๋ ์ฌ์ฉ๋์ง ์์ง๋ง, ํฅํ ํ์ฅ์ฑ์ ์ํด ๋จ๊ฒจ๋ก๋๋ค.
local favor_egos = false
local favor_plus = false
-- ์์ดํ
์ด ๋ธ๋๋(์: ํ์ผ, ๋๊ธฐ)๋ ์๊ณ (์: ์ ํญ, ๋นํ)๋ฅผ ๊ฐ์ก๋์ง ํ์ธํฉ๋๋ค.
local function is_branded_ego(item)
return item.branded or item.ego()
end
-- ์์ดํ
์ด ๋ง๋ฒ ์์ฑ(๋ธ๋๋, ์๊ณ , ์ํฐํฉํธ)์ ๊ฐ์ก๋์ง ํ์ธํฉ๋๋ค.
local function is_magical(item)
return is_branded_ego(item) or item.artefact
end
-- ์์ดํ
์ด nil์ผ ๊ฒฝ์ฐ๋ฅผ ๋๋นํ ๋ฌธ์์ด
local nil_item = "item: nil";
-- (๋๋ฒ๊น
์ฉ) ์์ดํ
์ ์์ธ ์ ๋ณด๋ฅผ ๋ฌธ์์ด๋ก ๋ฐํํฉ๋๋ค.
local function debug_item(item)
if item == nil then
return nil_item
end
local qual = item.name("qual");
local subtype = item.subtype();
if qual == nil or subtype == nil then
return nil_item
end
local magical = tostring(is_magical(item));
local plus = tostring(item.plus);
return string.format("name: %s; subtype: %s, magical: %s, plus: %s", qual, subtype, magical, plus)
end
-- ====================================================================
-- ๋ฆฌํฉํฐ๋ง๋ ํฌํผ ํจ์๋ค (Refactored Helper Functions)
-- ====================================================================
--- ์ธ๋ฒคํ ๋ฆฌ์ ํน์ ์ด๋ฆ์ ๊ฐ์ง ์์ดํ
์ด ์๋์ง ํ์ธํฉ๋๋ค.
-- @param item_name ํ์ธํ ์์ดํ
์ ์ ์ฒด ์ด๋ฆ (์: "orb of destruction")
-- @return boolean ํด๋น ์์ดํ
์ ๊ฐ์ง๊ณ ์์ผ๋ฉด true
local function has_item_in_inventory(item_name)
for item in items.inventory() do
if item.name() == item_name then
return true
end
end
return false
end
--- ํ์ฌ ์ฐฉ์ฉํ ์์ดํ
(cur)์ด ์ด๋ฏธ ์ถฉ๋ถํ ์ข์์
-- ๋ค๋ฅธ ์์ดํ
์ ์ฃผ์ธ ํ์๊ฐ ์๋์ง ํ์ธํฉ๋๋ค.
-- @param cur ํ์ฌ ์ฐฉ์ฉ ์ค์ธ ์์ดํ
-- @return boolean ์ค์ง ์์์ผ ํ๋ฉด true
local function is_pickup_declined(cur)
-- ํ์ฌ ์์ดํ
์ด nil์ด๊ฑฐ๋, ๋ง๋ฒ ์์ฑ์ด ์์ผ๋ฉด ์ค๋ ๊ฒ์ ๊ฑฐ์ ํ ์ด์ ๊ฐ ์์ต๋๋ค.
if cur == nil or not is_magical(cur) then
return false
end
-- ์ด๋ฏธ ๋ง๋ฒ ์์ฑ์ด ๋ถ์ฌ๋ ์์ดํ
์ด๋ ๋๋๊ณค ๊ฐ์ท์ ์ฐฉ์ฉ ์ค์ด๋ผ๋ฉด,
-- ๋ค๋ฅธ ์์ดํ
์ผ๋ก ๊ต์ฒดํ๋ ๊ฒ์ ๊ณ ๋ คํ์ง ์๊ณ ์ค์ง ์์ต๋๋ค.
local is_dragon_scales = string.find(cur.name("qual"), "dragon scale")
if is_magical(cur) or is_dragon_scales then
return true
end
return false
end
--- ๋ฐ๋ฅ์ ์์ดํ
(i2)์ด ํ์ฌ ์ฐฉ์ฉํ ์์ดํ
(cur)์ ๋นํด
-- ๋ช
๋ฐฑํ๊ฒ ๋ ์ข์ ์
๊ทธ๋ ์ด๋์ธ์ง ํ์ธํฉ๋๋ค.
-- @param cur ํ์ฌ ์ฐฉ์ฉ ์ค์ธ ์์ดํ
-- @param i2 ๋ฐ๋ฅ์ ์๋ ์์ดํ
-- @return boolean ๋ช
๋ฐฑํ ์
๊ทธ๋ ์ด๋์ผ ๊ฒฝ์ฐ true
local function is_clear_upgrade(cur, i2)
-- 1. ํ์ฌ ์ฅ๋น ์ฌ๋กฏ์ด ๋น์ด์์ผ๋ฉด ๋ฌด์กฐ๊ฑด ์ค์ต๋๋ค.
if cur == nil then
return true
end
-- 2. ํ์ฌ ์์ดํ
์ด ์ผ๋ฐ ์์ดํ
์ธ๋ฐ, ๋ฐ๋ฅ์ ์์ดํ
์ ๋ง๋ฒ ์์ฑ์ด ๋ถ์ด์์ผ๋ฉด ์ค์ต๋๋ค.
local more_magical = not is_magical(cur) and is_magical(i2)
if more_magical then
return true
end
-- 3. ๋ ์์ดํ
์ ๊ธฐ๋ณธ ์ด๋ฆ์ด ๊ฐ์ ๋, ๊ฐํ ์์น๊ฐ ๋ ๋์ผ๋ฉด ์ค์ต๋๋ค.
local higher_plus = i2.plus ~= nil and i2.plus > (cur.plus or 0)
if cur.name("qual") == i2.name("qual") and higher_plus then
return true
end
return false
end
-- ====================================================================
-- ํต์ฌ ๋ก์ง ํจ์ (Core Logic Function)
-- ====================================================================
--- ํ์ฌ ์ฐฉ์ฉํ ์์ดํ
(cur)๊ณผ ๋ฐ๋ฅ์ ์์ดํ
(i2)์ ๋น๊ตํ์ฌ ์ฃผ์ธ์ง ์ฌ๋ถ๋ฅผ ์ต์ข
๊ฒฐ์ ํฉ๋๋ค.
-- @param cur ํ์ฌ ์ฐฉ์ฉ ์ค์ธ ์์ดํ
-- @param i2 ๋ฐ๋ฅ์ ์๋ ์์ดํ
-- @return boolean ์ฃผ์์ผ ํ๋ฉด true
local function should_pickup(cur, i2)
-- ์ ์ด ์ ๋ฌผํ ์์ดํ
์ ํญ์ ์ค์ต๋๋ค.
if i2.god_gift then return true end
-- 1. ์ค์ง ๋ง์์ผ ํ ๋ช
๋ฐฑํ ์ด์ ๊ฐ ์๋์ง ๋จผ์ ํ์ธํฉ๋๋ค. (์: ์ด๋ฏธ ์ข์ ์ํฐํฉํธ ์ฐฉ์ฉ ์ค)
if is_pickup_declined(cur) then
return false
end
-- 2. ์ฃผ์์ผ ํ ๋ช
๋ฐฑํ ์ด์ ๊ฐ ์๋์ง ํ์ธํฉ๋๋ค. (์: ๋น ์ฌ๋กฏ, ํ์คํ ์ฑ๋ฅ ํฅ์)
if is_clear_upgrade(cur, i2) then
return true
end
-- 3. ๊ทธ ์ธ์ ๊ฒฝ์ฐ (ํ๋์ฝ๋ฉ๋ ์ค์ ๊ฐ์ ๋ฐ๋ผ ํ๋จ, ํ์ฌ๋ ๋ ๋ค false)
-- ๋ง์ฝ ์๊ณ /๋ธ๋๋ ์์ดํ
์ ์ ํธํ๋ค๋ฉด ์ค์ต๋๋ค.
if favor_egos and is_magical(i2) then return true end
-- ๋ง์ฝ ๊ฐํ ์์น๋ฅผ ์ ํธํ๊ณ , ๊ฐํ ์์น๊ฐ ๋ ๋๋ค๋ฉด ์ค์ต๋๋ค.
local higher_plus = i2.plus ~= nil and i2.plus > (cur.plus or 0)
if favor_plus and higher_plus then return true end
-- ์์ ๋ชจ๋ ์กฐ๊ฑด์ ํด๋นํ์ง ์์ผ๋ฉด ๊ธฐ๋ณธ์ ์ผ๋ก ์ค์ง ์์ต๋๋ค.
return false
end
-- ์์ดํ
์ข
๋ฅ์ ๋ฐ๋ผ ํด๋นํ๋ ์ฅ๋น ์ฌ๋กฏ์ ์ฐพ์, ํ์ฌ ์ฐฉ์ฉ ์ค์ธ ์์ดํ
์ ๋ฐํํฉ๋๋ค.
local item_subtype_equip_slot = {
cloak="Cloak",
helmet="Helmet",
gloves="Gloves",
boots="Boots",
shield="Shield"}
local function equip_slot(item_sub_type)
-- ๊ฐ์ท(body armour)์ ๊ฒฝ์ฐ, ๋ก์ปฌ๊ณผ ์นํ์ผ์์ ์ฌ์ฉํ๋ ์ฌ๋กฏ ์ด๋ฆ์ด ๋ฌ๋ผ ๋ ๋ค ์๋ํฉ๋๋ค.
if item_sub_type == "body" then
local body_armour = items.equipped_at("Body Armour");
local armour = items.equipped_at("Armour");
return body_armour or armour;
end
-- ๊ทธ ์ธ ๋ฐฉ์ด๊ตฌ๋ ํ
์ด๋ธ์ ํตํด ์ฌ๋กฏ์ ์ฐพ์ต๋๋ค.
local equip_slot_name = item_subtype_equip_slot[item_sub_type];
return items.equipped_at(equip_slot_name);
end
--- ์๋ ์ต๋ ๊ธฐ๋ฅ์ ๋ฉ์ธ ์ง์
ํจ์์
๋๋ค.
-- ๊ฒ์ ๋ด์์ ์์ดํ
์ ๋ฐ๊ฒฌํ ๋๋ง๋ค ํธ์ถ๋ฉ๋๋ค.
function pickup_equipment(it, name)
local class = it.class(true)
-- ์ ์๊ฒ ๊ธ์ง๋๊ฑฐ๋ ์ธ๋ชจ์๋ ์์ดํ
์ ์ค์ง ์์ต๋๋ค.
if string.match(name, "forbidden") then return end
if it.is_useless then return end
-- ์ํฐํฉํธ๋ ํญ์ ์ค์ต๋๋ค.
if it.artefact then return true end
if class == "weapon" then
local currentWeapon = items.equipped_at("weapon");
-- ๋งจ์ ๊ฒฉํฌ ์ํ์ผ ๋๋, ์ ์ ์ ๋ฌผ์ ์ ์ธํ๊ณ ๋ฌด๊ธฐ๋ฅผ ์ค์ง ์์ต๋๋ค.
if currentWeapon == nil then
if it.god_gift then return true end
return false
end
if should_pickup(currentWeapon, it) then return true end
elseif class == "armour" then
local sub_type = it.subtype();
-- ๋ฐํฑ์ด ์๋ ์ข
์กฑ์ ์ฅ๊ฐ์ ์ค์ง ์์ต๋๋ค.
if sub_type == "gloves" and you.has_claws() > 0 then return end
-- โผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผ
-- ์๋ก์ด ๋ฐฉํจ/๋ณด์ฃผ ๋ก์ง
-- โผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผโผ
if sub_type == "shield" then
local is_orb = string.find(it.name("qual"), "orb")
if is_orb then
-- [์ค๋ธ ๊ท์น] ์ธ๋ฒคํ ๋ฆฌ์ ๋์ผํ ์ด๋ฆ์ ์ค๋ธ๊ฐ ์ด๋ฏธ ์๋ค๋ฉด ์ค์ง ์์ต๋๋ค.
if has_item_in_inventory(it.name()) then
return false -- ์ค๋ณต์ด๋ฏ๋ก ์ค์ง ์์
else
-- ์ธ๋ฒคํ ๋ฆฌ์ ์๋ ์๋ก์ด ์ข
๋ฅ์ ์ค๋ธ๋ ๋ฌด์กฐ๊ฑด ์ค์ต๋๋ค.
return true -- ์๋ก์ด ์ค๋ธ์ด๋ฏ๋ก ์ค๊ธฐ
end
else -- ๋ฐฉํจ์ธ ๊ฒฝ์ฐ
-- [๋ฐฉํจ ๊ท์น] ๋ฐฉํจ์ ์คํฌ์ด 5๋ณด๋ค ์์ผ๋ฉด ์ค์ง ์์ต๋๋ค.
if you.skill("Shields") < 5 then
return -- ์คํฌ ๋ ๋ฒจ์ด ๋ฎ์ผ๋ฏ๋ก ์ค์ง ์์
end
-- ์คํฌ ๋ ๋ฒจ์ด ์ถฉ๋ถํ๋ค๋ฉด, ์๋์ ์ผ๋ฐ ์ฅ๋น ๋น๊ต ๋ก์ง์ ๋ฐ๋ฆ
๋๋ค.
end
end
-- โฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒ
-- ํ์ฌ ์ฐฉ์ฉํ ์์ดํ
๊ณผ ๋น๊ตํ์ฌ ์ฃผ์ธ์ง ๊ฒฐ์ ํฉ๋๋ค.
local equipped_item = equip_slot(sub_type)
if should_pickup(equipped_item, it) then return true end
end
return
end
-- ์คํฌ๋ฆฝํธ๊ฐ ๋ก๋๋ ๋, ์ด ํจ์๋ฅผ ๊ฒ์์ ์๋ ์ต๋ ๊ธฐ๋ฅ์ ๋ฑ๋กํฉ๋๋ค.
add_autopickup_func(pickup_equipment)
}
##
## NoteVersion.lua
################################################################################################
{
local didRun = false
function note_version()
if didRun then
return
end
local version = "magus.rc [v1.11.6]"
crawl.take_note(version)
didRun = true
end
}
function rc_msg(msg)
rc_out("๐ค", "blue", msg, "diagnostic")
end
##
## TurnReady.lua
################################################################################################
{
-- Run every player turn
function ready()
-- rc_msg("Running ready function...")
-- Display damage taken in log
AnnounceDamage()
note_version()
end
}