name: Uzuhime
card_text: 2 Level 3 "Mikanko" monsters
  If this card is Special Summoned: You can add 1 Equip Spell from your Deck or GY to your hand. You can only use this effect of "Uzuhime the Manifested Mikanko" once per turn. Cannot be destroyed by battle, also your opponent takes any battle damage you would have taken from battles involving this card. If this card attacks, at the end of the Damage Step: You can detach 1 material from this card; it can make another attack in a row.
external_ids: local SETCARD_ID_0 = 0x18d --Mikanko
  
lua: local SETCARD_ID_0 = 0x18d --Mikanko
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, aux.FilterBoolFunction(Card.IsSetCard, SETCARD_ID_0), 3, 2)
  	c:EnableReviveLimit()
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	--battle indestructable
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--reflect battle damage
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetCode(EFFECT_REFLECT_BATTLE_DAMAGE)
  	e3:SetValue(1)
  	c:RegisterEffect(e3)
  	--chain attack
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 2))
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_DAMAGE_STEP_END)
  	e4:SetCondition(s.atcon)
  	e4:SetCost(s.atcost)
  	e4:SetOperation(s.atop)
  	c:RegisterEffect(e4)
  end
  function s.thfilter(c)
  	return c:IsType(TYPE_EQUIP) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(aux.NecroValleyFilter(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
  function s.atcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return Duel.GetAttacker() == c and c:IsChainAttackable(0)
  end
  function s.atcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.atop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.ChainAttack()
  end
  
  
source_text: Uzuhime
  2 Level 3 "Mikanko" monsters
  If this card is Special Summoned: You can add 1 Equip Spell from your Deck or GY to your hand. You can only use this effect of "Uzuhime the Manifested Mikanko" once per turn. Cannot be destroyed by battle, also your opponent takes any battle damage you would have taken from battles involving this card. If this card attacks, at the end of the Damage Step: You can detach 1 material from this card; it can make another attack in a row.
target_text: -- Uzuhime
  local SETCARD_ID_0 = 0x18d --Mikanko
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, aux.FilterBoolFunction(Card.IsSetCard, SETCARD_ID_0), 3, 2)
  	c:EnableReviveLimit()
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	--battle indestructable
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--reflect battle damage
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetCode(EFFECT_REFLECT_BATTLE_DAMAGE)
  	e3:SetValue(1)
  	c:RegisterEffect(e3)
  	--chain attack
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 2))
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_DAMAGE_STEP_END)
  	e4:SetCondition(s.atcon)
  	e4:SetCost(s.atcost)
  	e4:SetOperation(s.atop)
  	c:RegisterEffect(e4)
  end
  function s.thfilter(c)
  	return c:IsType(TYPE_EQUIP) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(aux.NecroValleyFilter(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
  function s.atcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return Duel.GetAttacker() == c and c:IsChainAttackable(0)
  end
  function s.atcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.atop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.ChainAttack()
  end
  
  