name: Cloudian
card_text: Cannot be destroyed by battle. If this card is in face-up Defense Position, destroy it. If this card is Normal Summoned: Place 1 Fog Counter on it for each "Cloudian" monster on the field. You can remove 3 Fog Counters from anywhere on the field; discard 1 random card from your opponent's hand.
external_ids: local SETCARD_ID_0 = 0x18 --Cloudian
  local COUNTER_ID_0 = 0x1019 --Fog
  
lua: local SETCARD_ID_0 = 0x18 --Cloudian
  local COUNTER_ID_0 = 0x1019 --Fog
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--battle indestructable
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	--selfdes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCode(EFFECT_SELF_DESTROY)
  	e2:SetCondition(s.sdcon)
  	c:RegisterEffect(e2)
  	--counter
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_COUNTER)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e3:SetCode(EVENT_SUMMON_SUCCESS)
  	e3:SetOperation(s.addc)
  	c:RegisterEffect(e3)
  	--handes
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_HANDES)
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCost(s.hdcost)
  	e4:SetTarget(s.hdtg)
  	e4:SetOperation(s.hdop)
  	c:RegisterEffect(e4)
  end
  function s.sdcon(e)
  	return e:GetHandler():IsPosition(POS_FACEUP_DEFENSE)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.addc(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetHandler():IsRelateToEffect(e) then
  		local ct = Duel.GetMatchingGroupCount(s.cfilter, tp, LOCATION_MZONE, LOCATION_MZONE, nil)
  		e:GetHandler():AddCounter(COUNTER_ID_0, ct)
  	end
  end
  function s.hdcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsCanRemoveCounter(tp, 1, 1, COUNTER_ID_0, 3, REASON_COST)
  	end
  	Duel.RemoveCounter(tp, 1, 1, COUNTER_ID_0, 3, REASON_COST)
  end
  function s.hdtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFieldGroupCount(tp, 0, LOCATION_HAND) ~= 0
  	end
  	Duel.SetOperationInfo(0, CATEGORY_HANDES, nil, 0, tp, 1)
  end
  function s.hdop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetFieldGroup(tp, 0, LOCATION_HAND):RandomSelect(tp, 1)
  	Duel.SendtoGrave(g, REASON_EFFECT + REASON_DISCARD)
  end
  
  
source_text: Cloudian
  Cannot be destroyed by battle. If this card is in face-up Defense Position, destroy it. If this card is Normal Summoned: Place 1 Fog Counter on it for each "Cloudian" monster on the field. You can remove 3 Fog Counters from anywhere on the field; discard 1 random card from your opponent's hand.
target_text: -- Cloudian
  local SETCARD_ID_0 = 0x18 --Cloudian
  local COUNTER_ID_0 = 0x1019 --Fog
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--battle indestructable
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	--selfdes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCode(EFFECT_SELF_DESTROY)
  	e2:SetCondition(s.sdcon)
  	c:RegisterEffect(e2)
  	--counter
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_COUNTER)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e3:SetCode(EVENT_SUMMON_SUCCESS)
  	e3:SetOperation(s.addc)
  	c:RegisterEffect(e3)
  	--handes
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_HANDES)
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCost(s.hdcost)
  	e4:SetTarget(s.hdtg)
  	e4:SetOperation(s.hdop)
  	c:RegisterEffect(e4)
  end
  function s.sdcon(e)
  	return e:GetHandler():IsPosition(POS_FACEUP_DEFENSE)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.addc(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetHandler():IsRelateToEffect(e) then
  		local ct = Duel.GetMatchingGroupCount(s.cfilter, tp, LOCATION_MZONE, LOCATION_MZONE, nil)
  		e:GetHandler():AddCounter(COUNTER_ID_0, ct)
  	end
  end
  function s.hdcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsCanRemoveCounter(tp, 1, 1, COUNTER_ID_0, 3, REASON_COST)
  	end
  	Duel.RemoveCounter(tp, 1, 1, COUNTER_ID_0, 3, REASON_COST)
  end
  function s.hdtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFieldGroupCount(tp, 0, LOCATION_HAND) ~= 0
  	end
  	Duel.SetOperationInfo(0, CATEGORY_HANDES, nil, 0, tp, 1)
  end
  function s.hdop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetFieldGroup(tp, 0, LOCATION_HAND):RandomSelect(tp, 1)
  	Duel.SendtoGrave(g, REASON_EFFECT + REASON_DISCARD)
  end
  
  