--Take Your Heart
local s,id,o=GetID()
function s.initial_effect(c)
	--activate
	local e1=Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(id,0))
	e1:SetCategory(CATEGORY_DISABLE+CATEGORY_DAMAGE)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_CHAINING)
	e1:SetCountLimit(1,id)
	e1:SetCondition(s.condition)
	e1:SetTarget(s.target)
	e1:SetOperation(s.activate)
	c:RegisterEffect(e1) 
	--to hand
	local e3=Effect.CreateEffect(c)
	e3:SetDescription(aux.Stringid(id,1))
	e3:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_O)
	e3:SetProperty(EFFECT_FLAG_DAMAGE_STEP+EFFECT_FLAG_DELAY)
	e3:SetCode(EVENT_TO_GRAVE)
	e3:SetRange(LOCATION_GRAVE)
	e3:SetCountLimit(1,id+o)
	e3:SetCondition(s.thcon)
	e3:SetCost(aux.bfgcost)
	e3:SetTarget(s.thtg)
	e3:SetOperation(s.thop)
	c:RegisterEffect(e3)
	--act in hand
	local e2=Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_SINGLE)
	e2:SetCode(EFFECT_TRAP_ACT_IN_HAND)
	c:RegisterEffect(e2)
end
function s.ffilter1(c)
	return c:IsFaceup() and c:IsSetCard(0x152)
end
function s.ffilter2(c)
	return c:IsFaceup() and c:IsSetCard(0x153)
end
function s.condition(e,tp,eg,ep,ev,re,r,rp)
	local a=Duel.IsExistingMatchingCard(s.ffilter1,tp,LOCATION_ONFIELD,0,1,nil)
	local b=Duel.IsExistingMatchingCard(s.ffilter2,tp,LOCATION_ONFIELD,0,1,nil)
	if not (a and b) then return end
	return ep==1-tp and re:IsActiveType(TYPE_MONSTER) and Duel.IsChainDisablable(ev)
end
function s.target(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return true end
	Duel.SetOperationInfo(0,CATEGORY_DISABLE,eg,1,0,0)
end
function s.activate(e,tp,eg,ep,ev,re,r,rp)
	local rc=re:GetHandler()
	local c=e:GetHandler()
	if Duel.NegateEffect(ev) then
		if not c:IsStatus(STATUS_ACT_FROM_HAND) and c:IsLocation(LOCATION_SZONE) then
			if rc:IsOnField() and rc:IsControlerCanBeChanged() then
				Duel.BreakEffect()
				Duel.GetControl(rc,tp,PHASE_END,1)
			end
		end
	end
end
function s.cfilter(c,tp)
	return c:IsPreviousControler(1-tp) and c:IsControler(1-tp) and c:IsPreviousLocation(LOCATION_MZONE) and not c:IsType(TYPE_TRAPMONSTER)
end
function s.thcon(e,tp,eg,ep,ev,re,r,rp)
	return not eg:IsContains(e:GetHandler()) and eg:IsExists(s.cfilter,1,nil,tp)
end
function s.thtg(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return true end
end
function s.thop(e,tp,eg,ep,ev,re,r,rp)
	local e1=Effect.CreateEffect(e:GetHandler())
	e1:SetType(EFFECT_TYPE_FIELD)
	e1:SetCode(EFFECT_UPDATE_ATTACK)
	e1:SetTargetRange(LOCATION_MZONE,0)
	e1:SetValue(500)
	e1:SetTarget(s.atktg)
	Duel.RegisterEffect(e1,tp)
	local e12=Effect.CreateEffect(e:GetHandler())
	e12:SetType(EFFECT_TYPE_FIELD)
	e12:SetCode(EFFECT_UPDATE_ATTACK)
	e12:SetTargetRange(LOCATION_MZONE,0)
	e12:SetValue(600)
	e12:SetTarget(aux.TargetBoolFunction(Card.IsCode,62098216))
	Duel.RegisterEffect(e12,tp)
end
function s.atktg(e,c)
	return c:IsSetCard(0x153) or c:IsSetCard(0x152)
end