name: Ohime
card_text: You can Ritual Summon this card with "Mikanko Kagura". Cannot be destroyed by battle, also your opponent takes any battle damage you would have taken from battles involving this card. You can only use each of the following effects of "Ohime the Manifested Mikanko" once per turn. You can reveal this card in your hand; add 1 "Mikanko" card from your Deck to your hand, except "Ohime the Manifested Mikanko", then discard 1 card. (Quick Effect): You can target 1 Equip Spell in your GY; equip it to 1 appropriate monster on the field.
external_ids: local CARD_ID_0 = 81260680 --Ohime the Manifested Mikanko
  local SETCARD_ID_0 = 0x18d --Mikanko
  
lua: local CARD_ID_0 = 81260680 --Ohime the Manifested Mikanko
  local SETCARD_ID_0 = 0x18d --Mikanko
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND + CATEGORY_HANDES)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.thcost)
  	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)
  	--equip
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_EQUIP)
  	e4:SetType(EFFECT_TYPE_QUICK_O)
  	e4:SetCode(EVENT_FREE_CHAIN)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e4:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e4:SetCountLimit(1, id + 1)
  	e4:SetTarget(s.eqtg)
  	e4:SetOperation(s.eqop)
  	c:RegisterEffect(e4)
  end
  function s.thcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return not e:GetHandler():IsPublic()
  	end
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) 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, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_HANDES, nil, 0, tp, 1)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  		Duel.ShuffleHand(tp)
  		Duel.BreakEffect()
  		Duel.DiscardHand(tp, nil, 1, 1, REASON_EFFECT + REASON_DISCARD)
  	end
  end
  function s.filter(c, tp)
  	return c:IsType(TYPE_EQUIP) and c:CheckUniqueOnField(tp) and not c:IsForbidden() and Duel.GetMatchingGroupCount(s.eqfilter, tp, LOCATION_MZONE, LOCATION_MZONE, nil, c) > 0
  end
  function s.eqfilter(c, ec)
  	return c:IsFaceup() and ec:CheckEquipTarget(c)
  end
  function s.eqtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, nil, tp)
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, g, 1, 0, 0)
  end
  function s.eqop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	local g = Duel.GetMatchingGroup(s.eqfilter, tp, LOCATION_MZONE, LOCATION_MZONE, nil, tc)
  	if Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and g:GetCount() > 0 and tc:IsRelateToEffect(e) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  		local sg = g:Select(tp, 1, 1, nil)
  		Duel.Equip(tp, tc, sg:GetFirst())
  	end
  end
  
  
source_text: Ohime
  You can Ritual Summon this card with "Mikanko Kagura". Cannot be destroyed by battle, also your opponent takes any battle damage you would have taken from battles involving this card. You can only use each of the following effects of "Ohime the Manifested Mikanko" once per turn. You can reveal this card in your hand; add 1 "Mikanko" card from your Deck to your hand, except "Ohime the Manifested Mikanko", then discard 1 card. (Quick Effect): You can target 1 Equip Spell in your GY; equip it to 1 appropriate monster on the field.
target_text: -- Ohime
  local CARD_ID_0 = 81260680 --Ohime the Manifested Mikanko
  local SETCARD_ID_0 = 0x18d --Mikanko
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND + CATEGORY_HANDES)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.thcost)
  	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)
  	--equip
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_EQUIP)
  	e4:SetType(EFFECT_TYPE_QUICK_O)
  	e4:SetCode(EVENT_FREE_CHAIN)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e4:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e4:SetCountLimit(1, id + 1)
  	e4:SetTarget(s.eqtg)
  	e4:SetOperation(s.eqop)
  	c:RegisterEffect(e4)
  end
  function s.thcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return not e:GetHandler():IsPublic()
  	end
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) 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, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_HANDES, nil, 0, tp, 1)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  		Duel.ShuffleHand(tp)
  		Duel.BreakEffect()
  		Duel.DiscardHand(tp, nil, 1, 1, REASON_EFFECT + REASON_DISCARD)
  	end
  end
  function s.filter(c, tp)
  	return c:IsType(TYPE_EQUIP) and c:CheckUniqueOnField(tp) and not c:IsForbidden() and Duel.GetMatchingGroupCount(s.eqfilter, tp, LOCATION_MZONE, LOCATION_MZONE, nil, c) > 0
  end
  function s.eqfilter(c, ec)
  	return c:IsFaceup() and ec:CheckEquipTarget(c)
  end
  function s.eqtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, nil, tp)
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, g, 1, 0, 0)
  end
  function s.eqop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	local g = Duel.GetMatchingGroup(s.eqfilter, tp, LOCATION_MZONE, LOCATION_MZONE, nil, tc)
  	if Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and g:GetCount() > 0 and tc:IsRelateToEffect(e) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  		local sg = g:Select(tp, 1, 1, nil)
  		Duel.Equip(tp, tc, sg:GetFirst())
  	end
  end
  
  