public class Effect
{
	public const int NEAR_PLAYER = 1;

	public const int LOOP_NORMAL = 0;

	public const int LOOP_TRANS = 2;

	public const int BACKGROUND = 3;

	public const int FIRE_TD = 0;

	public const int BIRD = 1;

	public const int FIRE_NAMEK = 2;

	public const int FIRE_SAYAI = 3;

	public const int FROG = 5;

	public const int CA = 4;

	public const int ECH = 6;

	public const int TACKE = 7;

	public const int RAN = 8;

	public const int KHI = 9;

	public const int GACON = 10;

	public const int DANONG = 11;

	public const int DANBUOM = 12;

	public const int QUA = 13;

	public const int THIENTHACH = 14;

	public const int CAVOI = 15;

	public const int NAM = 16;

	public const int RONGTHAN = 17;

	public int ID;

	public int effId;

	public int typeEff;

	public int indexFrom;

	public int indexTo;

	public bool isNearPlayer;

	public int t;

	public int currFrame;

	public int x;

	public int y;

	public int loop;

	public int tLoop;

	public int tLoopCount;

	private bool isPaint = true;

	public int layer;

	public static MyVector vEffData = new MyVector("vEffData");

	public int trans;

	public static MyVector lastEff = new MyVector("lastEff");

	public static MyVector newEff = new MyVector("newEff");

	private bool isGetTime;

	public Effect(int id, int x, int y, int layer, int loop, int loopCount)
	{
		this.x = x;
		this.y = y;
		effId = id;
		this.layer = layer;
		this.loop = loop;
		tLoop = loopCount;
		if (getEffDataById(id) == null)
		{
			EffectData effectData = new EffectData
			{
				ID = id
			};
			string text = "/effect/" + id + "/data";
			DataInputStream dataInputStream = MyStream.readFile(text);
			if (dataInputStream != null)
			{
				effectData.readData(text);
				effectData.img = CCanvas.loadImage2("/effect/" + id + "/x" + mGraphics.zoomLevel + ".png");
			}
			else
			{
				GameService.gI().getEffData((short)id);
			}
			addEffData(effectData);
			lastEff.addElement(id + string.Empty);
		}
		indexFrom = -1;
		indexTo = -1;
		typeEff = 0;
		if (!isExistNewEff(id + string.Empty))
		{
			newEff.addElement(id + string.Empty);
		}
	}

	public static void removeEffData(int id)
	{
		for (int i = 0; i < vEffData.size(); i++)
		{
			EffectData effectData = (EffectData)vEffData.elementAt(i);
			if (effectData.ID == id)
			{
				vEffData.removeElement(effectData);
				break;
			}
		}
	}

	public static void addEffData(EffectData eff)
	{
		vEffData.addElement(eff);
		if (vEffData.size() > 10)
		{
			for (int i = 0; i < 5; i++)
			{
				vEffData.removeElementAt(0);
			}
		}
	}

	public static EffectData getEffDataById(int id)
	{
		for (int i = 0; i < vEffData.size(); i++)
		{
			EffectData effectData = (EffectData)vEffData.elementAt(i);
			if (effectData.ID == id)
			{
				return effectData;
			}
		}
		return null;
	}

	public static bool isExistNewEff(string id)
	{
		for (int i = 0; i < newEff.size(); i++)
		{
			string text = (string)newEff.elementAt(i);
			if (text.Equals(id))
			{
				return true;
			}
		}
		return false;
	}

	public bool isPaintz()
	{
		if (!isPaint)
		{
			return false;
		}
		return true;
	}

	public void paintUnderBackground(mGraphics g, int xLayer, int yLayer)
	{
		if (isPaintz() && getEffDataById(effId).img != null)
		{
			getEffDataById(effId).paintFrame(g, currFrame, x + xLayer, y + yLayer, trans, layer);
		}
	}

	public void paint2(mGraphics g)
	{
		if (isPaintz())
		{
			int num = 1;
			switch (BackgroundNew.typeBg)
			{
			case 2:
				num = 4;
				break;
			case 14:
			case 15:
				num = 3;
				break;
			case 6:
				num = 2;
				break;
			}
			if (getEffDataById(effId).img != null)
			{
				getEffDataById(effId).paintFrame(g, currFrame, x - Camera.x, y - (Camera.y >> num), trans, layer);
			}
		}
	}

	public void paint(mGraphics g)
	{
		if (isPaintz() && getEffDataById(effId).img != null)
		{
			getEffDataById(effId).paintFrame(g, currFrame, x, y, trans, layer);
		}
	}

	public void update()
	{
		if (CScreen.highFrameRate() || getEffDataById(effId).img == null)
		{
			return;
		}
		if (getEffDataById(effId).arrFrame != null)
		{
			if (!isGetTime)
			{
				isGetTime = true;
				int num = getEffDataById(effId).arrFrame.Length - 1;
				if (num > 0 && typeEff != 0)
				{
					t = CRes.random(0, num);
				}
				if (typeEff == 1)
				{
					t = CRes.random(indexFrom, indexTo);
				}
			}
			switch (typeEff)
			{
			case 0:
			case 3:
				if (t < getEffDataById(effId).arrFrame.Length)
				{
					t++;
				}
				break;
			case 2:
				if (t < getEffDataById(effId).arrFrame.Length)
				{
					t++;
				}
				tLoopCount++;
				if (tLoopCount == tLoop)
				{
					tLoopCount = 0;
					trans = CRes.random(0, 2);
				}
				break;
			}
			if (t <= getEffDataById(effId).arrFrame.Length - 1)
			{
				currFrame = getEffDataById(effId).arrFrame[t];
			}
		}
		if (t >= getEffDataById(effId).arrFrame.Length - 1)
		{
			if (typeEff == 1 || typeEff == 3)
			{
				isPaint = false;
			}
			if (tLoop == -1)
			{
				EffecMn.vEff.removeElement(this);
			}
			if (typeEff == 2)
			{
				t = 0;
				return;
			}
			isNearPlayer = false;
			if (loop == -1)
			{
				tLoopCount++;
				if (tLoopCount == tLoop)
				{
					tLoopCount = 0;
					t = 0;
					if (tLoop > 1)
					{
						trans = CRes.random(0, 2);
					}
				}
				return;
			}
			tLoopCount++;
			if (tLoopCount == tLoop)
			{
				tLoopCount = 0;
				loop--;
				t = 0;
				if (loop == 0)
				{
					EffecMn.vEff.removeElement(this);
				}
			}
		}
		else
		{
			isPaint = true;
		}
	}

	public static void FillTransparentRect(mGraphics g, int x2, int y2, int w, int h)
	{
	}
}
