name: Walls
card_text: This card's name becomes "King's Sarcophagus" while in the Field Zone. During your Main Phase: You can add 1 "Horus" monster from your Deck to your hand, then place 1 card from your hand on the bottom of the Deck. You can only use this effect of "Walls of the Imperial Tomb" once per turn. If you activate the effect of "Horus the Black Flame Deity": You can draw 1 card.
external_ids: local CARD_ID_0 = 16528181 --King's Sarcophagus
  local CARD_ID_1 = 99307040 --Horus the Black Flame Deity
  local SETCARD_ID_0 = 0x19d --Horus
  
lua: local CARD_ID_0 = 16528181 --King's Sarcophagus
  local CARD_ID_1 = 99307040 --Horus the Black Flame Deity
  local SETCARD_ID_0 = 0x19d --Horus
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--change code
  	aux.EnableChangeCode(c, CARD_ID_0, LOCATION_FZONE)
  	--search and send to deck
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TODECK + CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.schtg)
  	e2:SetOperation(s.schop)
  	c:RegisterEffect(e2)
  	--draw
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_DRAW)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_CHAINING)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetRange(LOCATION_FZONE)
  	e3:SetCondition(s.drcon)
  	e3:SetTarget(s.drtg)
  	e3:SetOperation(s.drop)
  	c:RegisterEffect(e3)
  end
  function s.schfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.schtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.schfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 1, tp, LOCATION_HAND)
  end
  function s.schop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.schfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 and Duel.SendtoHand(g, nil, REASON_EFFECT) ~= 0 then
  		Duel.ConfirmCards(1 - tp, g)
  		Duel.ShuffleHand(tp)
  		Duel.ShuffleDeck(tp)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  		local g2 = Duel.SelectMatchingCard(tp, Card.IsAbleToDeck, tp, LOCATION_HAND, 0, 1, 1, nil)
  		if #g2 > 0 then
  			Duel.BreakEffect()
  			Duel.SendtoDeck(g2, nil, SEQ_DECKBOTTOM, REASON_EFFECT)
  		end
  	end
  end
  function s.drcon(e, tp, eg, ep, ev, re, r, rp)
  	return rp == tp and re:GetHandler():IsCode(CARD_ID_1)
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 1)
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(1)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Draw(p, d, REASON_EFFECT)
  end
  
  
source_text: Walls
  This card's name becomes "King's Sarcophagus" while in the Field Zone. During your Main Phase: You can add 1 "Horus" monster from your Deck to your hand, then place 1 card from your hand on the bottom of the Deck. You can only use this effect of "Walls of the Imperial Tomb" once per turn. If you activate the effect of "Horus the Black Flame Deity": You can draw 1 card.
target_text: -- Walls
  local CARD_ID_0 = 16528181 --King's Sarcophagus
  local CARD_ID_1 = 99307040 --Horus the Black Flame Deity
  local SETCARD_ID_0 = 0x19d --Horus
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--change code
  	aux.EnableChangeCode(c, CARD_ID_0, LOCATION_FZONE)
  	--search and send to deck
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TODECK + CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.schtg)
  	e2:SetOperation(s.schop)
  	c:RegisterEffect(e2)
  	--draw
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_DRAW)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_CHAINING)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetRange(LOCATION_FZONE)
  	e3:SetCondition(s.drcon)
  	e3:SetTarget(s.drtg)
  	e3:SetOperation(s.drop)
  	c:RegisterEffect(e3)
  end
  function s.schfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.schtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.schfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 1, tp, LOCATION_HAND)
  end
  function s.schop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.schfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 and Duel.SendtoHand(g, nil, REASON_EFFECT) ~= 0 then
  		Duel.ConfirmCards(1 - tp, g)
  		Duel.ShuffleHand(tp)
  		Duel.ShuffleDeck(tp)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  		local g2 = Duel.SelectMatchingCard(tp, Card.IsAbleToDeck, tp, LOCATION_HAND, 0, 1, 1, nil)
  		if #g2 > 0 then
  			Duel.BreakEffect()
  			Duel.SendtoDeck(g2, nil, SEQ_DECKBOTTOM, REASON_EFFECT)
  		end
  	end
  end
  function s.drcon(e, tp, eg, ep, ev, re, r, rp)
  	return rp == tp and re:GetHandler():IsCode(CARD_ID_1)
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 1)
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(1)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Draw(p, d, REASON_EFFECT)
  end
  
  