name: CXyz
card_text: 3 Level 11 monsters
  When this card destroys a monster by battle and sends it to the Graveyard: Inflict damage to your opponent equal to half the original ATK of the destroyed monster in the Graveyard. If this card has "Skypalace Gangaridai" as an Xyz Material, it gains this effect.
  ● Once per turn, if this card destroys a monster by battle: You can detach 1 Xyz Material from this card; it can make a second attack in a row.
external_ids: local CARD_ID_0 = 3814632 --Skypalace Gangaridai
  
lua: local CARD_ID_0 = 3814632 --Skypalace Gangaridai
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, nil, 11, 3)
  	c:EnableReviveLimit()
  	--damage
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DAMAGE)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetCode(EVENT_BATTLE_DESTROYING)
  	e1:SetCondition(aux.bdgcon)
  	e1:SetTarget(s.damtg)
  	e1:SetOperation(s.damop)
  	c:RegisterEffect(e1)
  	--chain attack
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BATTLE_DESTROYING)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.atcon)
  	e2:SetCost(s.atcost)
  	e2:SetOperation(s.atop)
  	c:RegisterEffect(e2)
  end
  function s.damtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local bc = e:GetHandler():GetBattleTarget()
  	Duel.SetTargetCard(bc)
  	local dam = math.floor(bc:GetAttack() / 2)
  	if dam < 0 then
  		dam = 0
  	end
  	Duel.SetTargetPlayer(1 - tp)
  	Duel.SetTargetParam(dam)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, dam)
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		local p = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER)
  		local dam = math.floor(tc:GetAttack() / 2)
  		if dam < 0 then
  			dam = 0
  		end
  		Duel.Damage(p, dam, REASON_EFFECT)
  	end
  end
  function s.atcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return aux.bdcon(e, tp, eg, ep, ev, re, r, rp) and c:IsChainAttackable() and c:GetOverlayGroup():IsExists(Card.IsCode, 1, nil, CARD_ID_0)
  end
  function s.atcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.atop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.ChainAttack()
  end
  
  
source_text: CXyz
  3 Level 11 monsters
  When this card destroys a monster by battle and sends it to the Graveyard: Inflict damage to your opponent equal to half the original ATK of the destroyed monster in the Graveyard. If this card has "Skypalace Gangaridai" as an Xyz Material, it gains this effect.
  ● Once per turn, if this card destroys a monster by battle: You can detach 1 Xyz Material from this card; it can make a second attack in a row.
target_text: -- CXyz
  local CARD_ID_0 = 3814632 --Skypalace Gangaridai
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, nil, 11, 3)
  	c:EnableReviveLimit()
  	--damage
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DAMAGE)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetCode(EVENT_BATTLE_DESTROYING)
  	e1:SetCondition(aux.bdgcon)
  	e1:SetTarget(s.damtg)
  	e1:SetOperation(s.damop)
  	c:RegisterEffect(e1)
  	--chain attack
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BATTLE_DESTROYING)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.atcon)
  	e2:SetCost(s.atcost)
  	e2:SetOperation(s.atop)
  	c:RegisterEffect(e2)
  end
  function s.damtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local bc = e:GetHandler():GetBattleTarget()
  	Duel.SetTargetCard(bc)
  	local dam = math.floor(bc:GetAttack() / 2)
  	if dam < 0 then
  		dam = 0
  	end
  	Duel.SetTargetPlayer(1 - tp)
  	Duel.SetTargetParam(dam)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, dam)
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		local p = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER)
  		local dam = math.floor(tc:GetAttack() / 2)
  		if dam < 0 then
  			dam = 0
  		end
  		Duel.Damage(p, dam, REASON_EFFECT)
  	end
  end
  function s.atcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return aux.bdcon(e, tp, eg, ep, ev, re, r, rp) and c:IsChainAttackable() and c:GetOverlayGroup():IsExists(Card.IsCode, 1, nil, CARD_ID_0)
  end
  function s.atcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.atop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.ChainAttack()
  end
  
  