# Kikubaaqudgha's caged human altar vault by tgw

# This vault contains a caged human who is killed with miasma once you see it
# and then is turned into a zombie.
#
# The show's end is not clear: the chance for getting a corpse (and then a
# zombie) is 50%. Very rarely, the human survives -- this is also okay. All of
# these shows still point out how Kikubaaqudgha enjoys suffering.

{{
function callback.tgw_kikubaaqudgha_kill_human(data, triggerable,
                                                triggerer, marker, ev)
  if data.turns ~= you.turns() then
    data.tc = data.tc + 1
    data.turns = you.turns()
  end

  if data.tc < 3 then
    return
  end

  if data.triggered == true then
    return
  end

  local m = dgn.find_marker_positions_by_prop("replica_name", "zombie")[1]
  if m ~= nil then
    local _x, _y = m:xy()

    if not you.see_cell(_x, _y) then
      return
    end
        dgn.place_cloud(_x, _y, "foul pestilence", 4)
        crawl.god_speaks("Kikubaaqudgha",
                         "Miasma emanates from the human's flesh.")
    data.triggered = true
  end
end

function callback.tgw_kikubaaqudgha_zombify(data, triggerable,
                                            triggerer, marker, ev)
  local pt = dgn.find_marker_positions_by_prop("replica_name", "zombie")
  if #pt == 0 then
    return
  end

  dgn.create_monster(pt[1].x, pt[1].y, "generate_awake human zombie")
  if you.see_cell(pt[1].x, pt[1].y) then
    crawl.god_speaks("Kikubaaqudgha", "The human rises from the dead!")
  end
end
}}

NAME:   tgw_kikubaaqudgha
TAGS:   temple_overflow_1 temple_overflow_kikubaaqudgha patrolling
KFEAT:  _ = altar_kikubaaqudgha
{{
local tm = TriggerableFunction:new{
  func="callback.tgw_kikubaaqudgha_kill_human",
  repeated=true,
  data={turns=you.turns(), tc=0, triggered=false} }
tm:add_triggerer(DgnTriggerer:new{type="player_los"})
lua_marker('_', tm)
}}

{{
local tm = TriggerableFunction:new{
  func="callback.tgw_kikubaaqudgha_zombify", repeated=false}
tm:add_triggerer(DgnTriggerer:new{type="monster_dies", target="dreplica"})
lua_marker('_', tm)
}}
KMONS:   h = generate_awake att:neutral human never_corpse hp:12 ; nothing
KFEAT:   h = .
: if you.depth() > 4 then
MONS:    burial acolyte, zombie
SHUFFLE: 12 / '' / '' / '' / '' / ''
: else
SUBST:   12 = .
: end
MARKER:  h = lua:portal_desc {replica_name="zombie"}
MARKER:  h = lua:MonPropsMarker:new{dreplica="dreplica"}
KPROP:   h = no_tele_into
TILE:    m = dngn_transparent_wall_darkgray
MAP
xxxxxxx
@.1mmmx
@_.mhmx
@.2mmmx
xxxxxxx
ENDMAP
