--假面英雄 厄诡椪
local s,id,o=GetID()
function s.initial_effect(c)
	--search
	local e1=Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_TOHAND+CATEGORY_SEARCH)
	e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O)
	e1:SetCode(EVENT_SUMMON_SUCCESS)
	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP+EFFECT_FLAG_DELAY)
	e1:SetTarget(s.thtg1)
	e1:SetOperation(s.tgop1)
	c:RegisterEffect(e1)
	--attribute change
	local e2=Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_IGNITION)
	e2:SetRange(LOCATION_MZONE)
	e2:SetCountLimit(1,id)
	e2:SetCost(s.accost)
	e2:SetOperation(s.acop)
	c:RegisterEffect(e2)
	--indes
	local e3=Effect.CreateEffect(c)
	e3:SetType(EFFECT_TYPE_FIELD)
	e3:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
	e3:SetRange(LOCATION_GRAVE)
	e3:SetTargetRange(LOCATION_MZONE,0)
	e3:SetTarget(s.tg1)
	e3:SetValue(1)
	c:RegisterEffect(e3)
	local e4=e3:Clone()
	e4:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
	c:RegisterEffect(e4)
	--can not be target
	local e5=e3:Clone()
	e5:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
	e5:SetTarget(s.tg2)
	c:RegisterEffect(e5)
	--atk up
	local e6=e3:Clone()
	e6:SetCode(EFFECT_UPDATE_ATTACK)
	e6:SetTarget(s.tg3)
	e6:SetValue(2000)
	c:RegisterEffect(e6)
	--atk up 2
	local e7=e3:Clone()
	e7:SetCode(EFFECT_UPDATE_ATTACK)
	e7:SetTarget(s.tg4)
	e7:SetValue(500)
	c:RegisterEffect(e7)
	--chainlimit
	local e8=Effect.CreateEffect(c)
	e8:SetType(EFFECT_TYPE_FIELD)
	e8:SetCode(EVENT_CHAINING)
	e8:SetRange(LOCATION_GRAVE)
	e8:SetTargetRange(LOCATION_MZONE,0)
	e8:SetTarget(s.tg4)
	e8:SetOperation(s.chainop)
	c:RegisterEffect(e8)
end
function s.thfilter1(c)
	return c:IsSetCard(0xa5) and c:IsType(TYPE_QUICKPLAY) and c:IsAbleToHand()
end
function s.thtg1(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.IsExistingMatchingCard(s.thfilter1,tp,LOCATION_DECK,0,1,nil) end
	Duel.SetOperationInfo(0,CATEGORY_TOHAND,nil,1,tp,LOCATION_DECK)
	Duel.Hint(HINT_OPSELECTED,1-tp,e:GetDescription())
end
function s.tgop1(e,tp,eg,ep,ev,re,r,rp)
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND)
	local g=Duel.SelectMatchingCard(tp,s.thfilter1,tp,LOCATION_DECK,0,1,1,nil)
	if g:GetCount()>0 then
		Duel.SendtoHand(g,nil,REASON_EFFECT)
		Duel.ConfirmCards(1-tp,g)
	end
end
function s.acfilter(c,e)
	return not c:IsAttribute(e:GetHandler():GetAttribute()) and c:IsSetCard(0x8) and c:IsType(TYPE_NORMAL) and c:IsAbleToGraveAsCost() 
end
function s.accost(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.IsExistingMatchingCard(s.acfilter,tp,LOCATION_DECK,0,1,nil,e) end
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_TOGRAVE)
	local cg=Duel.SelectMatchingCard(tp,s.acfilter,tp,LOCATION_DECK,0,1,1,nil,e)
	Duel.SendtoGrave(cg,REASON_COST)
	e:SetLabel(cg:GetFirst():GetAttribute())
end
function s.acop(e,tp,eg,ep,ev,re,r,rp)
	local c=e:GetHandler()
	if not c:IsRelateToEffect(e) or c:IsFacedown() then return end
	local e1=Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_SINGLE)
	e1:SetCode(EFFECT_CHANGE_ATTRIBUTE)
	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
	e1:SetValue(e:GetLabel())
	c:RegisterEffect(e1)
end
function s.tg1(e,c)
	return c:IsSetCard(0xa008) and c:IsAttribute(ATTRIBUTE_EARTH)
end
function s.tg2(e,c)
	return c:IsSetCard(0xa008) and c:IsAttribute(ATTRIBUTE_WATER)
end
function s.tg3(e,c)
	return c:IsSetCard(0xa008) and c:IsAttribute(ATTRIBUTE_FIRE)
end
function s.tg4(e,c)
	return c:IsSetCard(0xa008) and c:IsAttribute(ATTRIBUTE_WIND)
end
function s.chainop(e,tp,eg,ep,ev,re,r,rp)
	if  ep==tp then
		Duel.SetChainLimit(s.chainlm)
	end
end
function s.chainlm(e,ep,tp)
	return tp==ep
end