name: Zaralaam
card_text: While you control a monster equipped with "Dunnell, the Noble Arms of Light", your opponent cannot activate cards or effects during the Battle Phase. Once per turn, when your "Adventurer Token" destroys an opponent's monster by battle: You can inflict damage to your opponent equal to that destroyed monster's original ATK. Once per turn, during your Main Phase, if the previous effect was activated this turn: You can add 1 Field Spell that mentions "Adventurer Token" from your Deck or GY to your hand, except "Zaralaam the Dark Palace".
external_ids: local CARD_ID_0 = 65952776 --Dunnell, the Noble Arms of Light
  local CARD_ID_1 = 3285552 --Adventurer Token
  
lua: local CARD_ID_0 = 65952776 --Dunnell, the Noble Arms of Light
  local CARD_ID_1 = 3285552 --Adventurer Token
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_1)
  	--Activate
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_ACTIVATE)
  	e0:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e0)
  	--cannot activate effect
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetRange(LOCATION_FZONE)
  	e1:SetTargetRange(0, 1)
  	e1:SetCondition(s.actlimcon)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	--damage
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_DAMAGE)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BATTLE_DESTROYING)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.damcon)
  	e2:SetTarget(s.damtg)
  	e2:SetOperation(s.damop)
  	c:RegisterEffect(e2)
  	--search
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_FZONE)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.thcon)
  	e3:SetTarget(s.thtg)
  	e3:SetOperation(s.thop)
  	c:RegisterEffect(e3)
  end
  function s.actlimfilter(c)
  	return c:GetEquipCount() > 0 and c:GetEquipGroup():IsExists(Card.IsCode, 1, nil, CARD_ID_0)
  end
  function s.actlimcon(e)
  	local ph = Duel.GetCurrentPhase()
  	local tp = e:GetHandlerPlayer()
  	return ph >= PHASE_BATTLE_START and ph <= PHASE_BATTLE and Duel.IsExistingMatchingCard(s.actlimfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	local rc = eg:GetFirst()
  	return rc:IsRelateToBattle() and rc:IsStatus(STATUS_OPPO_BATTLE) and rc:IsFaceup() and rc:IsCode(CARD_ID_1) and rc:IsControler(tp)
  end
  function s.damtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local c = eg:GetFirst()
  	local bc = c:GetBattleTarget()
  	Duel.SetTargetCard(bc)
  	local dam = bc:GetBaseAttack()
  	if dam < 0 then
  		dam = 0
  	end
  	Duel.SetTargetPlayer(1 - tp)
  	Duel.SetTargetParam(dam)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, dam)
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  		Duel.Damage(p, d, REASON_EFFECT)
  	end
  	c:RegisterFlagEffect(id, RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) > 0 and Duel.GetCurrentPhase() == PHASE_MAIN2
  end
  function s.thfilter(c)
  	return aux.IsCodeListed(c, CARD_ID_1) and c:IsType(TYPE_FIELD) and not c:IsCode(id) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK + LOCATION_GRAVE)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.thfilter), tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  
source_text: Zaralaam
  While you control a monster equipped with "Dunnell, the Noble Arms of Light", your opponent cannot activate cards or effects during the Battle Phase. Once per turn, when your "Adventurer Token" destroys an opponent's monster by battle: You can inflict damage to your opponent equal to that destroyed monster's original ATK. Once per turn, during your Main Phase, if the previous effect was activated this turn: You can add 1 Field Spell that mentions "Adventurer Token" from your Deck or GY to your hand, except "Zaralaam the Dark Palace".
target_text: -- Zaralaam
  local CARD_ID_0 = 65952776 --Dunnell, the Noble Arms of Light
  local CARD_ID_1 = 3285552 --Adventurer Token
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_1)
  	--Activate
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_ACTIVATE)
  	e0:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e0)
  	--cannot activate effect
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetRange(LOCATION_FZONE)
  	e1:SetTargetRange(0, 1)
  	e1:SetCondition(s.actlimcon)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	--damage
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_DAMAGE)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BATTLE_DESTROYING)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.damcon)
  	e2:SetTarget(s.damtg)
  	e2:SetOperation(s.damop)
  	c:RegisterEffect(e2)
  	--search
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_FZONE)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.thcon)
  	e3:SetTarget(s.thtg)
  	e3:SetOperation(s.thop)
  	c:RegisterEffect(e3)
  end
  function s.actlimfilter(c)
  	return c:GetEquipCount() > 0 and c:GetEquipGroup():IsExists(Card.IsCode, 1, nil, CARD_ID_0)
  end
  function s.actlimcon(e)
  	local ph = Duel.GetCurrentPhase()
  	local tp = e:GetHandlerPlayer()
  	return ph >= PHASE_BATTLE_START and ph <= PHASE_BATTLE and Duel.IsExistingMatchingCard(s.actlimfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	local rc = eg:GetFirst()
  	return rc:IsRelateToBattle() and rc:IsStatus(STATUS_OPPO_BATTLE) and rc:IsFaceup() and rc:IsCode(CARD_ID_1) and rc:IsControler(tp)
  end
  function s.damtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local c = eg:GetFirst()
  	local bc = c:GetBattleTarget()
  	Duel.SetTargetCard(bc)
  	local dam = bc:GetBaseAttack()
  	if dam < 0 then
  		dam = 0
  	end
  	Duel.SetTargetPlayer(1 - tp)
  	Duel.SetTargetParam(dam)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, dam)
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  		Duel.Damage(p, d, REASON_EFFECT)
  	end
  	c:RegisterFlagEffect(id, RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) > 0 and Duel.GetCurrentPhase() == PHASE_MAIN2
  end
  function s.thfilter(c)
  	return aux.IsCodeListed(c, CARD_ID_1) and c:IsType(TYPE_FIELD) and not c:IsCode(id) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK + LOCATION_GRAVE)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.thfilter), tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  