--神心一刀流·樱尽消华
function c66914008.initial_effect(c)
	--Activate
	local e1=Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCategory(CATEGORY_NEGATE)
	e1:SetCode(EVENT_CHAINING)
	e1:SetCountLimit(1,66914008+EFFECT_COUNT_CODE_OATH)
	e1:SetCondition(c66914008.condition)
	e1:SetTarget(c66914008.target)
	e1:SetOperation(c66914008.activate)
	c:RegisterEffect(e1)	
end
function c66914008.condition(e,tp,eg,ep,ev,re,r,rp)
	if Duel.GetCurrentChain()<1 then return false end
	for i=1,ev do
		local te,tgp=Duel.GetChainInfo(i,CHAININFO_TRIGGERING_EFFECT,CHAININFO_TRIGGERING_PLAYER)
		if tgp==tp and (te:IsActiveType(TYPE_MONSTER) or te:IsHasType(EFFECT_TYPE_ACTIVATE)) and Duel.IsChainNegatable(i) then
			return true
		end
	end
	return false
end
function c66914008.target(e,tp,eg,ep,ev,re,r,rp,chk)
	local ng=Group.CreateGroup()
	local dg=Group.CreateGroup()
	for i=1,ev do
		local te,tgp=Duel.GetChainInfo(i,CHAININFO_TRIGGERING_EFFECT,CHAININFO_TRIGGERING_PLAYER)
		if tgp==tp and (te:IsActiveType(TYPE_MONSTER) or te:IsHasType(EFFECT_TYPE_ACTIVATE)) and Duel.IsChainNegatable(i) then
			local tc=te:GetHandler()
			ng:AddCard(tc)
			if tc:IsOnField() and tc:IsRelateToEffect(te) and tc:IsAbleToDeck() then
				dg:AddCard(tc)
			end
		end
	end
	local dc=dg:GetCount()
	if chk==0 then return (dc<3 or Duel.IsPlayerCanDraw(tp,dc)) and (dc<2 or Duel.IsExistingMatchingCard(aux.TRUE,tp,0,LOCATION_ONFIELD,1,nil)) end
	Duel.SetTargetCard(dg)
	Duel.SetOperationInfo(0,CATEGORY_NEGATE,ng,ng:GetCount(),0,0)
end
function c66914008.activate(e,tp,eg,ep,ev,re,r,rp)
	local dg=Group.CreateGroup()
	local count=0
	for i=1,ev do
		local te,tgp=Duel.GetChainInfo(i,CHAININFO_TRIGGERING_EFFECT,CHAININFO_TRIGGERING_PLAYER)
		if tgp~=tp and (te:IsActiveType(TYPE_MONSTER) or te:IsHasType(EFFECT_TYPE_ACTIVATE)) then
			count=count+1
		end
		if tgp==tp and (te:IsActiveType(TYPE_MONSTER) or te:IsHasType(EFFECT_TYPE_ACTIVATE)) and Duel.NegateActivation(i) then
			local tc=te:GetHandler()
			dg:AddCard(tc)
		end
	end
	if dg:GetCount()>=1 then
		Duel.Damage(1-tp,count*1500,REASON_EFFECT)
	end
	if dg:GetCount()>=2 then
		local tg=Duel.GetMatchingGroup(aux.TRUE,tp,0,LOCATION_ONFIELD,nil)
		local cg=math.min(tg:GetCount(),dg:GetCount())
		local g=tg:Select(tp,1,cg,nil)
		Duel.Destroy(g,REASON_EFFECT)
	end
	if dg:GetCount()>=3 then
		Duel.Draw(tp,dg:GetCount(),REASON_EFFECT)
	end
	if dg:GetCount()>=4 then
		for i=1,ev do
			local te,tgp=Duel.GetChainInfo(i,CHAININFO_TRIGGERING_EFFECT,CHAININFO_TRIGGERING_PLAYER)
			if tgp~=tp and (te:IsActiveType(TYPE_MONSTER) or te:IsHasType(EFFECT_TYPE_ACTIVATE)) then
				Duel.NegateActivation(i)
			end
		end
	end
end