name: Elementsaber
card_text: You can send 2 other monsters from your hand to the GY; Special Summon this card from your hand. You can only use this effect of "Elementsaber Lapauila Mana" once per turn. Apply the following effect(s) to "Elementsaber" and "Elemental Lord" monsters you control, depending on the original Attributes of any "Elementsaber" monsters sent to the GY to activate this card's effect.
  ● EARTH or WIND: Cannot be destroyed by battle.
  ● WATER or FIRE: Cannot be destroyed by effects.
  ● LIGHT or DARK: Your opponent cannot target it with card effects.
external_ids: local CARD_ID_0 = 61557074 --Palace of the Elemental Lords
  local SETCARD_ID_0 = 0x400d --Elementsaber
  
lua: local CARD_ID_0 = 61557074 --Palace of the Elemental Lords
  local SETCARD_ID_0 = 0x400d --Elementsaber
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.spcost)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--summon success
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetCondition(s.regcon)
  	e2:SetOperation(s.regop)
  	c:RegisterEffect(e2)
  	e2:SetLabelObject(e1)
  end
  function s.costfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsAbleToGraveAsCost() and (c:IsSetCard(SETCARD_ID_0) or c:IsLocation(LOCATION_HAND))
  end
  function s.regfilter(c, attr)
  	return c:IsSetCard(SETCARD_ID_0) and bit.band(c:GetOriginalAttribute(), attr) ~= 0
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local fe = Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)
  	local loc = LOCATION_HAND
  	if fe then
  		loc = LOCATION_HAND + LOCATION_DECK
  	end
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, loc, 0, 2, e:GetHandler())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.costfilter, tp, loc, 0, 2, 2, e:GetHandler())
  	if g:IsExists(Card.IsLocation, 1, nil, LOCATION_DECK) then
  		Duel.Hint(HINT_CARD, 0, CARD_ID_0)
  		fe:UseCountLimit(tp)
  	end
  	local flag = 0
  	if g:IsExists(s.regfilter, 1, nil, ATTRIBUTE_EARTH + ATTRIBUTE_WIND) then
  		flag = bit.bor(flag, 0x1)
  	end
  	if g:IsExists(s.regfilter, 1, nil, ATTRIBUTE_WATER + ATTRIBUTE_FIRE) then
  		flag = bit.bor(flag, 0x2)
  	end
  	if g:IsExists(s.regfilter, 1, nil, ATTRIBUTE_LIGHT + ATTRIBUTE_DARK) then
  		flag = bit.bor(flag, 0x4)
  	end
  	Duel.SendtoGrave(g, REASON_COST)
  	e:SetLabel(flag)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SpecialSummon(c, SUMMON_VALUE_SELF, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.regcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetSummonType() == SUMMON_TYPE_SPECIAL + SUMMON_VALUE_SELF and e:GetLabelObject():GetLabel() ~= 0
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	local flag = e:GetLabelObject():GetLabel()
  	local c = e:GetHandler()
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_FIELD)
  	e0:SetProperty(EFFECT_FLAG_CLIENT_HINT)
  	e0:SetRange(LOCATION_MZONE)
  	e0:SetTargetRange(LOCATION_MZONE, 0)
  	e0:SetTarget(s.immtg)
  	e0:SetReset(RESET_EVENT + RESETS_STANDARD)
  	if bit.band(flag, 0x1) ~= 0 then
  		local e1 = e0:Clone()
  		e1:SetDescription(aux.Stringid(id, 1))
  		e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  		e1:SetValue(1)
  		c:RegisterEffect(e1)
  	end
  	if bit.band(flag, 0x2) ~= 0 then
  		local e2 = e0:Clone()
  		e2:SetDescription(aux.Stringid(id, 2))
  		e2:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  		e2:SetValue(1)
  		c:RegisterEffect(e2)
  	end
  	if bit.band(flag, 0x4) ~= 0 then
  		local e3 = e0:Clone()
  		e3:SetDescription(aux.Stringid(id, 3))
  		e3:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  		e3:SetValue(aux.tgoval)
  		c:RegisterEffect(e3)
  	end
  end
  function s.immtg(e, c)
  	return c:IsSetCard(SETCARD_ID_0, 0x113)
  end
  
  
source_text: Elementsaber
  You can send 2 other monsters from your hand to the GY; Special Summon this card from your hand. You can only use this effect of "Elementsaber Lapauila Mana" once per turn. Apply the following effect(s) to "Elementsaber" and "Elemental Lord" monsters you control, depending on the original Attributes of any "Elementsaber" monsters sent to the GY to activate this card's effect.
  ● EARTH or WIND: Cannot be destroyed by battle.
  ● WATER or FIRE: Cannot be destroyed by effects.
  ● LIGHT or DARK: Your opponent cannot target it with card effects.
target_text: -- Elementsaber
  local CARD_ID_0 = 61557074 --Palace of the Elemental Lords
  local SETCARD_ID_0 = 0x400d --Elementsaber
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.spcost)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--summon success
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetCondition(s.regcon)
  	e2:SetOperation(s.regop)
  	c:RegisterEffect(e2)
  	e2:SetLabelObject(e1)
  end
  function s.costfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsAbleToGraveAsCost() and (c:IsSetCard(SETCARD_ID_0) or c:IsLocation(LOCATION_HAND))
  end
  function s.regfilter(c, attr)
  	return c:IsSetCard(SETCARD_ID_0) and bit.band(c:GetOriginalAttribute(), attr) ~= 0
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local fe = Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)
  	local loc = LOCATION_HAND
  	if fe then
  		loc = LOCATION_HAND + LOCATION_DECK
  	end
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, loc, 0, 2, e:GetHandler())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.costfilter, tp, loc, 0, 2, 2, e:GetHandler())
  	if g:IsExists(Card.IsLocation, 1, nil, LOCATION_DECK) then
  		Duel.Hint(HINT_CARD, 0, CARD_ID_0)
  		fe:UseCountLimit(tp)
  	end
  	local flag = 0
  	if g:IsExists(s.regfilter, 1, nil, ATTRIBUTE_EARTH + ATTRIBUTE_WIND) then
  		flag = bit.bor(flag, 0x1)
  	end
  	if g:IsExists(s.regfilter, 1, nil, ATTRIBUTE_WATER + ATTRIBUTE_FIRE) then
  		flag = bit.bor(flag, 0x2)
  	end
  	if g:IsExists(s.regfilter, 1, nil, ATTRIBUTE_LIGHT + ATTRIBUTE_DARK) then
  		flag = bit.bor(flag, 0x4)
  	end
  	Duel.SendtoGrave(g, REASON_COST)
  	e:SetLabel(flag)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SpecialSummon(c, SUMMON_VALUE_SELF, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.regcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetSummonType() == SUMMON_TYPE_SPECIAL + SUMMON_VALUE_SELF and e:GetLabelObject():GetLabel() ~= 0
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	local flag = e:GetLabelObject():GetLabel()
  	local c = e:GetHandler()
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_FIELD)
  	e0:SetProperty(EFFECT_FLAG_CLIENT_HINT)
  	e0:SetRange(LOCATION_MZONE)
  	e0:SetTargetRange(LOCATION_MZONE, 0)
  	e0:SetTarget(s.immtg)
  	e0:SetReset(RESET_EVENT + RESETS_STANDARD)
  	if bit.band(flag, 0x1) ~= 0 then
  		local e1 = e0:Clone()
  		e1:SetDescription(aux.Stringid(id, 1))
  		e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  		e1:SetValue(1)
  		c:RegisterEffect(e1)
  	end
  	if bit.band(flag, 0x2) ~= 0 then
  		local e2 = e0:Clone()
  		e2:SetDescription(aux.Stringid(id, 2))
  		e2:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  		e2:SetValue(1)
  		c:RegisterEffect(e2)
  	end
  	if bit.band(flag, 0x4) ~= 0 then
  		local e3 = e0:Clone()
  		e3:SetDescription(aux.Stringid(id, 3))
  		e3:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  		e3:SetValue(aux.tgoval)
  		c:RegisterEffect(e3)
  	end
  end
  function s.immtg(e, c)
  	return c:IsSetCard(SETCARD_ID_0, 0x113)
  end
  
  