# TEAMCAPTAIN offering

default_manual_training = true
autofight_stop = 69
#show_more = true
tile_web_mouse_control = false
runrest_ignore_message += wither
autofight_throw = false

############################
### Careful Play Items   ###
############################
travel_delay = -1 
explore_delay = 20
travel_open_doors = false
# force_more_message = curse toe, enormous slime creature, titanic slime creature, Erolcha, Meliai, hell sentinel, Jorgrun, Moth of Wrath, Floating Eye, Flayed Ghosts, Tzitzim, tormentor, catoblepas 
bold_brightens_foreground=true
explore_auto_rest=true

flash_screen_message += Ashenzari invites you to partake
flash_screen_message += Ru believes you are ready to make a new sacrifice
force_more_message += You can now merge with and destroy a victim.
force_more_message += transformation is almost over
more += distortion
flash_screen_message += distortion
flash_screen_message += primal bloodlust
--more += holy wrath
more += suddenly seem different
more += A sentinel's mark
more +- alarm
show_more = false
more += have finished your manual
--more += curare
more += is.*carrying a wand of
explore_stop += greedy_pickup,stairs,shops,altars,portals,branches,runed_doors
bindkey = [s] CMD_NO_CMD_DEFAULT
note_chat_messages = true
stop += Your transformation is almost over
easy_floor_use = true
more += you are ready to recite again

tile_viewport_scale = 1.1

###########################
###BEGIN LUA BLACK MAGIC###
###########################

<
  function ready()
    AnnounceDamage()
    --SpoilerAlert()
    OpenSkills()
  end
>


###############
# Damage Calc #
###############
<
  local previous_hp = 0
  local previous_mp = 0
  local previous_form = ""
  local was_berserk_last_turn = false

  function AnnounceDamage()
    local current_hp, max_hp = you.hp()
    local current_mp, max_mp = you.mp()
    --Things that increase hp/mp temporarily really mess with this
    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")) or
          previous_form:find("hydra")then
        max_hp_decreased = true
      elseif (current_form:find("dragon") or
          current_form:find("statue") or
          current_form:find("tree") or
          previous_form:find("ice")) or
          previous_form:find("hydra")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

    --crawl.mpr(string.format("previous_form is: %s", previous_form))
    --crawl.mpr(string.format("current_form is: %s", current_form))
    --crawl.mpr(string.format("max_hp_increased is: %s", max_hp_increased and "True" or "False"))
    --crawl.mpr(string.format("max_hp_decreased is: %s", max_hp_decreased and "True" or "False"))

    --crawl.mpr(string:format("you_are_berserk is: %s", you_are_berserk and "True" or "False"))
    --crawl.mpr(string:format("was_berserk_last_turn is: %s", was_berserk_last_turn and "True" or "False"))


    --Skips message on initializing game
    if previous_hp > 0 then
      local hp_difference = previous_hp - current_hp
      local mp_difference = previous_mp - current_mp

      if max_hp_increased or max_hp_decreased then
        if max_hp_increased then
          crawl.mpr("<green>You now have " .. current_hp .. "/" .. max_hp .. " hp.</green>")
        else
          crawl.mpr("<yellow>You now have " .. current_hp .. "/" .. max_hp .. " hp.</yellow>")
        end
      else
        --On losing health
        if (current_hp < previous_hp) then
          if current_hp <= (max_hp * 0.30) then
            crawl.mpr("<red>You take " .. hp_difference .. " damage,</red><lightred> and have " .. current_hp .. "/" .. max_hp .. " hp.</lightred>")
          elseif current_hp <= (max_hp * 0.50) then
            crawl.mpr("<red>You take " .. hp_difference .. " damage, and have " .. current_hp .. "/" .. max_hp .. " hp.</red>")
          elseif current_hp <= (max_hp *  0.70) then
            crawl.mpr("<red>You take " .. hp_difference .. " damage,</red><yellow> and have " .. current_hp .. "/" .. max_hp .. " hp.</yellow>")
          elseif current_hp <= (max_hp * 0.90) then
            crawl.mpr("<red>You take " .. hp_difference .. " damage,</red><lightgrey> and have " .. current_hp .. "/" .. max_hp .. " hp.</lightgrey>")
          else
            crawl.mpr("<red>You take " .. hp_difference .. " damage,</red><green> and have " .. current_hp .. "/" .. max_hp .. " hp.</green>")
          end
          if hp_difference > (max_hp * 0.20) then
            crawl.mpr("<lightred>MASSIVE DAMAGE!!</lightred>")
          end
        end

        --On gaining more than 1 health
        if (current_hp > previous_hp) then
          --Removes the negative sign
          local health_inturn = (0 - hp_difference)
          if (health_inturn > 1) and not (current_hp == max_hp) then
            if current_hp <= (max_hp * 0.30) then
              crawl.mpr("<green>You regained " .. health_inturn .. " hp,</green><lightred> and now have " .. current_hp .. "/" .. max_hp .. " hp.</lightred>")
            elseif current_hp <= (max_hp * 0.50) then
              crawl.mpr("<green>You regained " .. health_inturn .. " hp,</green><red> and now have " .. current_hp .. "/" .. max_hp .. " hp.</red>")
            elseif current_hp <= (max_hp *  0.70) then
              crawl.mpr("<green>You regained " .. health_inturn .. " hp,</green><yellow> and now have " .. current_hp .. "/" .. max_hp .. " hp.</yellow>")
            elseif current_hp <= (max_hp * 0.90) then
              crawl.mpr("<green>You regained " .. health_inturn .. " hp,</green><lightgrey> and now have " .. current_hp .. "/" .. max_hp .. " hp.</lightgrey>")
            else
              crawl.mpr("<green>You regained " .. health_inturn .. " hp, and now have " .. current_hp .. "/" .. max_hp .. " hp.</green>")
            end
          end
          if (current_hp == max_hp) then
            crawl.mpr("<green>Health restored: " .. current_hp .. "</green>")
          end
        end

        --On gaining more than 1 magic
        if (current_mp > previous_mp) then
          --Removes the negative sign
          local mp_inturn = (0 - mp_difference)
          if (mp_inturn > 1) and not (current_mp == max_mp) then
            if current_mp < (max_mp * 0.25) then
              crawl.mpr("<lightcyan>You regained " .. mp_inturn .. " mp,</lightcyan><red> and now have " .. current_mp .. "/" .. max_mp .. " mp.</red>")
            elseif current_mp < (max_mp * 0.50) then
              crawl.mpr("<lightcyan>You regained " .. mp_inturn .. " mp,</lightcyan><yellow> and now have " .. current_mp .. "/" .. max_mp .. " mp.</yellow>")
            else
              crawl.mpr("<lightcyan>You regained " .. mp_inturn .. " mp,</lightcyan><green> and now have " .. current_mp .. "/" .. max_mp .. " mp.</green>")
            end
          end
          if (current_mp == max_mp) then
            crawl.mpr("<lightcyan>MP restored: " .. current_mp .. "</lightcyan>")
          end
        end

        --On losing magic
        if current_mp < previous_mp then
          if current_mp <= (max_mp / 5) then
            crawl.mpr("<lightcyan>You now have </lightcyan><red>" .. current_mp .. "/" ..max_mp .." mp.</red>")
          elseif current_mp <= (max_mp / 2) then
            crawl.mpr("<lightcyan>You now have </lightcyan><yellow>" .. current_mp .. "/" ..max_mp .." mp.</yellow>")
          else
            crawl.mpr("<lightcyan>You now have </lightcyan><green>" .. current_mp .. "/" ..max_mp .." mp.</green>")
          end
        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
>


####################
# Opens skill menu #
####################
<
  local need_skills_opened = true
  function OpenSkills()
    if you.turns() == 0 and need_skills_opened then
      need_skills_opened = false
      crawl.sendkeys("m")
    end
  end
>

###############
# Spell slots #
###############

force_targeter=true

# Set Alias for Spell Slots
slot := spell_slot

# Try to keep in alphabetic order (by keybind)
slot += Freeze:a
slot += Shroud:a
slot += Frozen Ramparts:b
slot += Blink:B
slot += Call Canine Familiar:c
slot += Confuse:c
slot += Conjure Flame:c
slot += Control Undead:c
slot += Freezing Aura:c
slot += Petrify:c
slot += Spider Form:b
slot += Summon Ice Beast:c
slot += Summon Lightning Spire:c
slot += Fireball:f
slot += Irradiate:i
slot += Apportation:g
slot += Lehudib's Crystal Spear:l
slot += Sublimation of Blood:m
slot += Slow:s
slot += Sticky Flame:s
slot += Starburst:s
slot += Swiftness:s
slot += Orb Of Destruction:o
slot += Passwall:w
slot += Corona:v
slot += Blade Hands:z
slot += Iskenderun's Mystic Blast:x
slot += Lightning Bolt:x
slot += Mephitic Cloud:x
slot += Stone Arrow:x
slot += Vampiric Draining:x
slot += Iskenderun's Battlesphere:z
slot += Lee's Rapid Deconstruction:z
slot += Animate Dead:A
slot += Animate Skeleton:A
slot += Ozocubu's Armour:A
slot += Death's Door:D
slot += Borgnjor's Revivification:R

item_slot ^= potions? of curing:q
item_slot ^= potions? of heal wounds:l
item_slot ^= potions? of haste:h
item_slot ^= potions? of might:d
item_slot ^= potions? of agility:s
item_slot ^= potions? of resistance:n
item_slot ^= ring of poison resistance:P
item_slot ^= ring of positive energy:N
item_slot ^= ring of protection from cold:I
item_slot ^= ring of protection from fire:F
item_slot ^= ring of protection from magic:mM
item_slot ^= ring of resist corrosion:C
item_slot ^= ring of see invisible:S
item_slot ^= ring of wizardry:W
item_slot ^= scrolls? of blinking:B
item_slot ^= scrolls? of fear:g
item_slot ^= scrolls? of identify:r
item_slot ^= scrolls? of teleportation:t
item_slot ^= scrolls? of remove curse:w
item_slot ^= wand of digging:D

#################
### Interface ###
#################

easy_confirm = all
default_manual_training = true
equip_unequip = true
sort_menus = true:equipped,identified,>qty,basename,art,ego,glowing,qualname

autofight_caught = true
autofight_wait = false
autofight_stop = 69

{
local need_skills_opened = true
local oldready = ready
function ready()
  if you.turns() == 0 and need_skills_opened then
    need_skills_opened = false
    crawl.sendkeys("m")
  end
  oldready()
end
}

#: if you.race() == "Troll" or you.race() == "Hill Orc" then
#    autofight_stop = 50
#: end
#: if you.race() == "Ghoul" then
#    autofight_stop = 50
#: end
#: if you.race() == "Minotaur" or you.race() == "Gargoyle" then
#    autofight_stop = 40
#: end
#: if you.race() == "Deep Dwarf" then
#    autofight_stop = 40
#: end
#: if you.race() == "Gargoyle" then
#    autofight_stop = 69
#: end

############################
### Travel & Exploration ###
############################

show_more = false
rest_wait_both = true
travel_delay = -1
explore_delay = -1
rest_delay = -1

show_travel_trail = false
explore_stop = artefacts,greedy_pickup_smart
explore_stop += stairs,shops
explore_stop += altars,portals,branches,runed_doors
view_delay = 200

##################
### Autopickup ###
##################

# Add staves, misc; note you can't use += with this option.
autopickup = $?!:"/}

ae := autopickup_exceptions
ae += <throwing net
ae += <curare-tipped dart
ae ^= <tin of tremorstones
ae ^= <potions? of mutation

# Exceptions
# I use immolation somewhat early on, and vulnerability is useful the entire
# game.
ae += <vulnerability|immolation
# Tend to not use these.
# ae += >scrolls? of silence
ae += >Xom's Chess Piece
# Don't ever need a second stave
ae += >ring of stealth
ae += >ring of protection from cold
ae += >ring of protection from fire
ae += >ring of protection from magic
ae += >ring of positive energy
ae += >ring of fire
ae += >ring of flight
ae += >ring of ice
ae += >ring of magical power
ae += >ring of strength
ae += >ring of intelligence
ae += >ring of dexterity
ae += >ring of wizardry
ae += >ring of poison resistance
ae += >ring of resist corrosion
ae += >ring of see invisible
#ae += >identified jewellery

ae += >amulet of faith
ae += >amulet of reflection
ae += >amulet of the acrobat
ae += >amulet of regeneration
ae += >amulet of magic regeneration
ae += >amulet of guardian spirit
ae += >amulet of nothing
ae += >amulet of inaccuracy

###########
### Lua ###
###########

{
-- Equipment autopickup (by Medar and various others)
local function pickup_equipment(it, name)
  if it.is_useless then return end

  local class = it.class(true)
  if class == "armour" then
    local good_slots = {cloak="Cloak", helmet="Helmet",
                        gloves="Gloves", boots="Boots"}
    st, _ = it.subtype()

    -- Autopickup found aux armour if 1) we don't have any or 2) it's artefact,
    -- or 3) if we don't have artefact or ego armour, and the found armour is
    -- ego.
    if good_slots[st] ~= nil then
      if good_slots[st] == "Gloves" and you.has_claws() > 0 then return end

      if it.artefact then return true end

      local cur = items.equipped_at(good_slots[st])
      if cur == nil then return true end

      if cur.branded or cur.artefact then return end
      if it.branded then return true end
      -- Autopickup found body armour of the same kind we're wearing, according
      -- to conditions (2) and (3) above used for aux slots.
    elseif st == "body" then
      local cur = items.equipped_at("armour")
      if cur == nil then return end
      if cur.name("qual") ~= it.name("qual") then return end

      if it.artefact then return true end

      if cur.branded or cur.artefact then return end
      if it.branded then return true end
    end
  end
  return
end

add_autopickup_func(pickup_equipment)

-- Spellcasting spam reduction by monqy
local function generic_cast_spell(cmd)
  crawl.mpr('<cyan>Cast which spell?</cyan>')
  crawl.flush_prev_message()
  crawl.process_keys(cmd)
end

function cast_spell()
  generic_cast_spell('z')
end

function force_cast_spell()
  generic_cast_spell('Z')
end
}

# Note: My final RC file has code from lua files found at:
#     https://github.com/gammafunk/dcss-rc/blob/master/README.md
# starting from the line below.
{

----------------------------
---- Begin load_message ----
----------------------------

-- See README.md for documentation.

message_color = "white"

-- Wrapper of crawl.mpr() that prints text in white by default.
if not mpr then
  mpr = function (msg, color)
    if not color then
      color = "white"
    end
    crawl.mpr("<" .. color .. ">" .. msg .. "</" .. color .. ">")
  end
end

function save_with_message()
  if you.turns() == 0 then
    crawl.sendkeys("S")
    return
  end
  crawl.formatted_mpr("Save game and exit?", "prompt")
  local res = crawl.getch()
  if not (string.char(res) == "y" or string.char(res) == "Y") then
    crawl.formatted_mpr("Okay, then.", "prompt")
    return
  end
  crawl.formatted_mpr("Leave a message: ", "prompt")
  local res = crawl.c_input_line()
  c_persist.message = res
  crawl.sendkeys(control("s"))
end

function load_message()
  if c_persist.message and c_persist.message ~= "nil"
  and c_persist.message ~= "" then
    mpr("MESSAGE: " .. c_persist.message, message_color)
    c_persist.message = nil
  end
end

-----------------------------------
---- End leave message on save ----
-----------------------------------
}

flash_screen_message += Vehumet offers you knowledge 
note_messages += Saving game
note_messages += Your magical essence is drained by the effort!
# travel_key_stop = false

###This should be for safe walking###

{
  safe = you.feel_safe()

  function update_safe()
    local old_safe = safe
    safe = you.feel_safe()
    if not safe and old_safe then
      crawl.mpr("Danger!", "warning")
      crawl.more()
    end
  end

  function ready()
    update_safe()
  end
}


#######################
### Mini Map Colors ###
#######################

tile_upstairs_col = green
tile_branchstairs_col = red
tile_downstairs_col = red
tile_door_col = #c27149
tile_wall_col = #4c4141
tile_explore_horizon_col = #919191
tile_floor_col = #0f0d0d
tile_item_col = #0f0d0d
tile_feature_col = #d4be21
tile_plant_col = #3e5a2f
tile_water_col = #0b5d79
tile_deep_water_col = #1212b3
tile_trap_col = #f447ff
tile_transporter_col = #ff5656
tile_transporter_landing_col = #59ff89
tile_lava_col = #5f0a00

############################
### Irrad Contam Warning ###
############################

{
  function check_contam()
    if you.contaminated() > 1 then
      crawl.setopt("confirm_action += Irradiate")
    else
      crawl.setopt("confirm_action -= Irradiate")
    end

  end

  function ready()
    check_contam()
  end
}