name: Ghost
card_text: During either turn, except the End Phase (Quick Effect): You can discard this card; apply this effect this turn. You can only use this effect of "Ghost Sister & Spooky Dogwood" once per turn.
  ● Each time your opponent Special Summons an Effect Monster(s) during the Main Phase or Battle Phase, you gain LP equal to that monster's ATK. If you did not gain LP by this effect, your LP are halved during the End Phase.
external_ids: local CARD_ID_0 = 60643554 --Ghost Sister & Spooky Dogwood
  
lua: local CARD_ID_0 = 60643554 --Ghost Sister & Spooky Dogwood
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.condition)
  	e1:SetCost(s.cost)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() ~= PHASE_END
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsDiscardable()
  	end
  	Duel.SendtoGrave(e:GetHandler(), REASON_COST + REASON_DISCARD)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCondition(s.lpcon1)
  	e1:SetOperation(s.lpop1)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	--sp_summon effect
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetCondition(s.regcon)
  	e2:SetOperation(s.regop)
  	e2:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e2, tp)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e3:SetCode(EVENT_CHAIN_SOLVED)
  	e3:SetCondition(s.lpcon2)
  	e3:SetOperation(s.lpop2)
  	e3:SetLabelObject(e2)
  	e3:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e3, tp)
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e4:SetCode(EVENT_PHASE + PHASE_END)
  	e4:SetCountLimit(1)
  	e4:SetCondition(s.damcon)
  	e4:SetOperation(s.damop)
  	e4:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e4, tp)
  end
  function s.cfilter(c, sp)
  	return c:IsType(TYPE_EFFECT) and c:IsSummonPlayer(sp) and c:IsFaceup()
  end
  function s.lpcon1(e, tp, eg, ep, ev, re, r, rp)
  	local ph = Duel.GetCurrentPhase()
  	return eg:IsExists(s.cfilter, 1, nil, 1 - tp) and (ph == PHASE_MAIN1 or ph == PHASE_MAIN2 or (ph >= PHASE_BATTLE_START and ph <= PHASE_BATTLE)) and not Duel.IsChainSolving()
  end
  function s.lpop1(e, tp, eg, ep, ev, re, r, rp)
  	local lg = eg:Filter(s.cfilter, nil, 1 - tp)
  	local rnum = lg:GetSum(Card.GetAttack)
  	if Duel.Recover(tp, rnum, REASON_EFFECT) < 1 then
  		return
  	end
  	Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.regcon(e, tp, eg, ep, ev, re, r, rp)
  	local ph = Duel.GetCurrentPhase()
  	return eg:IsExists(s.cfilter, 1, nil, 1 - tp) and (ph == PHASE_MAIN1 or ph == PHASE_MAIN2 or (ph >= PHASE_BATTLE_START and ph <= PHASE_BATTLE)) and Duel.IsChainSolving()
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	local lg = eg:Filter(s.cfilter, nil, 1 - tp)
  	local g = e:GetLabelObject()
  	if g == nil or #g == 0 then
  		lg:KeepAlive()
  		e:SetLabelObject(lg)
  	else
  		g:Merge(lg)
  	end
  	Duel.RegisterFlagEffect(tp, id + 1, RESET_CHAIN, 0, 1)
  end
  function s.lpcon2(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetFlagEffect(tp, id + 1) > 0
  end
  function s.lpop2(e, tp, eg, ep, ev, re, r, rp)
  	Duel.ResetFlagEffect(tp, id + 1)
  	local lg = e:GetLabelObject():GetLabelObject()
  	lg = lg:Filter(Card.IsLocation, nil, LOCATION_MZONE)
  	local rnum = lg:GetSum(Card.GetAttack)
  	local g = Group.CreateGroup()
  	g:KeepAlive()
  	e:GetLabelObject():SetLabelObject(g)
  	lg:DeleteGroup()
  	if Duel.Recover(tp, rnum, REASON_EFFECT) < 1 then
  		return
  	end
  	Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetFlagEffect(tp, id) < 1
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.SetLP(tp, math.ceil(Duel.GetLP(tp) / 2))
  end
  
  
source_text: Ghost
  During either turn, except the End Phase (Quick Effect): You can discard this card; apply this effect this turn. You can only use this effect of "Ghost Sister & Spooky Dogwood" once per turn.
  ● Each time your opponent Special Summons an Effect Monster(s) during the Main Phase or Battle Phase, you gain LP equal to that monster's ATK. If you did not gain LP by this effect, your LP are halved during the End Phase.
target_text: -- Ghost
  local CARD_ID_0 = 60643554 --Ghost Sister & Spooky Dogwood
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.condition)
  	e1:SetCost(s.cost)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() ~= PHASE_END
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsDiscardable()
  	end
  	Duel.SendtoGrave(e:GetHandler(), REASON_COST + REASON_DISCARD)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCondition(s.lpcon1)
  	e1:SetOperation(s.lpop1)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	--sp_summon effect
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetCondition(s.regcon)
  	e2:SetOperation(s.regop)
  	e2:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e2, tp)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e3:SetCode(EVENT_CHAIN_SOLVED)
  	e3:SetCondition(s.lpcon2)
  	e3:SetOperation(s.lpop2)
  	e3:SetLabelObject(e2)
  	e3:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e3, tp)
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e4:SetCode(EVENT_PHASE + PHASE_END)
  	e4:SetCountLimit(1)
  	e4:SetCondition(s.damcon)
  	e4:SetOperation(s.damop)
  	e4:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e4, tp)
  end
  function s.cfilter(c, sp)
  	return c:IsType(TYPE_EFFECT) and c:IsSummonPlayer(sp) and c:IsFaceup()
  end
  function s.lpcon1(e, tp, eg, ep, ev, re, r, rp)
  	local ph = Duel.GetCurrentPhase()
  	return eg:IsExists(s.cfilter, 1, nil, 1 - tp) and (ph == PHASE_MAIN1 or ph == PHASE_MAIN2 or (ph >= PHASE_BATTLE_START and ph <= PHASE_BATTLE)) and not Duel.IsChainSolving()
  end
  function s.lpop1(e, tp, eg, ep, ev, re, r, rp)
  	local lg = eg:Filter(s.cfilter, nil, 1 - tp)
  	local rnum = lg:GetSum(Card.GetAttack)
  	if Duel.Recover(tp, rnum, REASON_EFFECT) < 1 then
  		return
  	end
  	Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.regcon(e, tp, eg, ep, ev, re, r, rp)
  	local ph = Duel.GetCurrentPhase()
  	return eg:IsExists(s.cfilter, 1, nil, 1 - tp) and (ph == PHASE_MAIN1 or ph == PHASE_MAIN2 or (ph >= PHASE_BATTLE_START and ph <= PHASE_BATTLE)) and Duel.IsChainSolving()
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	local lg = eg:Filter(s.cfilter, nil, 1 - tp)
  	local g = e:GetLabelObject()
  	if g == nil or #g == 0 then
  		lg:KeepAlive()
  		e:SetLabelObject(lg)
  	else
  		g:Merge(lg)
  	end
  	Duel.RegisterFlagEffect(tp, id + 1, RESET_CHAIN, 0, 1)
  end
  function s.lpcon2(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetFlagEffect(tp, id + 1) > 0
  end
  function s.lpop2(e, tp, eg, ep, ev, re, r, rp)
  	Duel.ResetFlagEffect(tp, id + 1)
  	local lg = e:GetLabelObject():GetLabelObject()
  	lg = lg:Filter(Card.IsLocation, nil, LOCATION_MZONE)
  	local rnum = lg:GetSum(Card.GetAttack)
  	local g = Group.CreateGroup()
  	g:KeepAlive()
  	e:GetLabelObject():SetLabelObject(g)
  	lg:DeleteGroup()
  	if Duel.Recover(tp, rnum, REASON_EFFECT) < 1 then
  		return
  	end
  	Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetFlagEffect(tp, id) < 1
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.SetLP(tp, math.ceil(Duel.GetLP(tp) / 2))
  end
  
  