public class Smoke
{
	public const sbyte SMOKE = 0;

	public const sbyte BLACK_SMOKE = 1;

	public const sbyte ROCK = 2;

	public const sbyte ROCK_2 = 3;

	public const sbyte BLACKSMOKE_EX = 4;

	public const sbyte SMALL_BLACKSMOKE_EX = 5;

	public const sbyte GLASS_FLY = 6;

	public const sbyte REDSMOKE = 7;

	public const sbyte CHICKEN_HAIR = 8;

	public const sbyte CHUOT = 9;

	public const sbyte GA = 10;

	public const sbyte WATER = 11;

	public const sbyte LACAY = 12;

	public const sbyte LAZER_SMOKE = 13;

	public const sbyte GLASS_FLY_2 = 14;

	public const sbyte NUKE_SMOKE = 15;

	public const sbyte LAZER = 16;

	public const sbyte BAT = 17;

	public const sbyte SMOKE_BG = 18;

	public const sbyte LONG_SMOKE = 19;

	public const sbyte LUCKY = 20;

	public const sbyte FIRE_SMOKE = 21;

	public const sbyte WIND = 22;

	public const int REDLAZER = 0;

	public const int GREENLAZER = 1;

	private FrameImage frmImg;

	public static int rockColor;

	private float x;

	private float y;

	private float vx;

	private float vy;

	private int endY;

	private int curFrame;

	private int delay;

	private bool isSmallSmoke;

	private int smallSmokeDelay;

	private bool isWaterBum;

	private bool isLand;

	public bool isChageColor;

	public Image rockImgColor;

	public static MyVector vImageID = new MyVector();

	public static MyVector vImageIDF = new MyVector();

	public sbyte type;

	private int xLazer;

	private int yLazer;

	private int num;

	private int[] smokeX;

	private int[] smokeY;

	private int[] smokeRadius;

	private int smokeHeight;

	private int typeLazer;

	public int xBat;

	public int yBat;

	public int angle;

	public int tWind;

	private int va;

	public static Image smoke;

	public static Image longSmoke;

	public static Image fireSmoke;

	public static Image redSmoke;

	public static Image lazerSmoke;

	public static Image nukeSmoke;

	public static Image water;

	public static Image blackSmoke;

	public static Image wind;

	public static Image bat;

	public static Image longga;

	public static Image lacay;

	public static Image chuotbay;

	public static Image gatruilong;

	public static Image lacay2;

	public static Image rock1;

	public static Image rock2;

	public static Image star;

	public static FrameImage frRock1;

	public static FrameImage frRock2;

	public static FrameImage frSmoke;

	public static FrameImage frLongSmoke;

	public static FrameImage frFireSmoke;

	public static FrameImage frRedSmoke;

	public static FrameImage fzLazerSmoke;

	public static FrameImage frNukeSmoke;

	public static FrameImage frWater;

	public static FrameImage frBlackSmoke;

	public static FrameImage frWind;

	public static FrameImage frLongga;

	public static FrameImage frLacay;

	public static FrameImage frChuotbay;

	public static FrameImage frGatruilong;

	public static FrameImage frLacay2;

	public bool isStop;

	public int timeStop;

	private bool activeLazer;

	private int wLazer;

	public Smoke(float xF, float yF, float xT, float yT, int typeLazer)
	{
		xLazer = (int)xF;
		yLazer = (int)yF;
		x = xT;
		y = yT;
		this.typeLazer = typeLazer;
		delay = 0;
		type = 16;
		activeLazer = true;
		if (typeLazer == 0)
		{
			wLazer = 25;
		}
		if (typeLazer == 1)
		{
			wLazer = 15;
		}
	}

	public Smoke(int xF, int yF, int xT, int yT)
	{
		x = xF;
		y = yF;
		xBat = xT;
		yBat = yT;
		angle = 90;
		va = 256;
		type = 17;
		load(type);
		frmImg = new FrameImage(bat, 19, 19);
	}

	public Smoke(float x, float y, sbyte Type)
	{
		load(Type);
		this.x = x;
		this.y = y;
		endY = (int)y - CRes.random(60, 80);
		delay = 0;
		type = Type;
		switch (Type)
		{
		case 0:
			if (frSmoke == null)
			{
				frSmoke = new FrameImage(smoke, 14, 15);
			}
			frmImg = frSmoke;
			break;
		case 19:
			curFrame = CRes.random(0, 4);
			if (frLongSmoke == null)
			{
				frLongSmoke = new FrameImage(longSmoke, 14, 15);
			}
			frmImg = frLongSmoke;
			break;
		case 21:
			curFrame = CRes.random(1, 2);
			if (frFireSmoke == null)
			{
				frFireSmoke = new FrameImage(fireSmoke, 14, 15);
			}
			frmImg = frFireSmoke;
			break;
		case 7:
			if (frRedSmoke == null)
			{
				frRedSmoke = new FrameImage(redSmoke, 10, 10);
			}
			frmImg = frRedSmoke;
			break;
		case 13:
			if (fzLazerSmoke == null)
			{
				fzLazerSmoke = new FrameImage(lazerSmoke, 10, 10);
			}
			frmImg = fzLazerSmoke;
			break;
		case 15:
			if (frNukeSmoke == null)
			{
				frNukeSmoke = new FrameImage(nukeSmoke, 27, 27);
			}
			frmImg = frNukeSmoke;
			break;
		case 11:
			if (frWater == null)
			{
				frWater = new FrameImage(water, 3, 3);
			}
			frmImg = frWater;
			break;
		case 1:
			if (frBlackSmoke == null)
			{
				frBlackSmoke = new FrameImage(blackSmoke, 12, 13);
			}
			frmImg = frBlackSmoke;
			break;
		case 16:
			xLazer = CRes.random(Camera.x, Camera.x + CCanvas.w);
			yLazer = Camera.y;
			activeLazer = true;
			break;
		case 4:
		case 5:
		case 18:
		{
			byte b = 10;
			if (Type == 5)
			{
				b = 6;
			}
			b = ((!BackgroundNew.lowGraphic) ? ((byte)(b - 4)) : ((byte)(b - 6)));
			if (b < 3)
			{
				b = 3;
			}
			this.num = CRes.random(b / 2, b);
			vx = GameScr.windx / 12;
			vy = CRes.random(-3, -1);
			smokeHeight = 25;
			smokeX = new int[this.num];
			smokeY = new int[this.num];
			smokeRadius = new int[this.num];
			int num = 20;
			int b2 = 16;
			if (Type == 5)
			{
				num = 4;
				b2 = 8;
			}
			for (int i = 0; i < this.num; i++)
			{
				smokeX[i] = CRes.random((int)x - num, (int)x + num);
				smokeY[i] = CRes.random((int)y - num / 2, (int)y + num / 2);
				smokeRadius[i] = CRes.random(6, b2);
			}
			break;
		}
		case 22:
			if (frWind == null)
			{
				frWind = new FrameImage(wind, 32, 32);
			}
			frmImg = frWind;
			break;
		case 2:
		case 3:
		case 6:
		case 8:
		case 9:
		case 10:
		case 12:
		case 14:
		case 17:
		case 20:
			break;
		}
	}

	public Smoke(int x, int y, int vx, int vy, sbyte Type)
	{
		this.x = x;
		this.y = y;
		this.vx = vx;
		this.vy = vy;
		type = Type;
		load(type);
		if (Type == 3)
		{
			frmImg = getRandomImageF();
		}
		else if (Type == 2)
		{
			rockImgColor = getRandomImage();
		}
		else if (Type == 8)
		{
			if (frLongga == null)
			{
				frLongga = new FrameImage(longga, 16, 10);
			}
			frmImg = frLongga;
		}
		else if (Type == 12)
		{
			if (frLacay == null)
			{
				frLacay = new FrameImage(lacay, 8, 5);
			}
			frmImg = frLacay;
		}
		else if (Type == 9)
		{
			if (frChuotbay == null)
			{
				frChuotbay = new FrameImage(chuotbay, 22, 18);
			}
			frmImg = frChuotbay;
		}
		else if (Type == 10)
		{
			if (frGatruilong == null)
			{
				frGatruilong = new FrameImage(gatruilong, 19, 17);
			}
			frmImg = frGatruilong;
		}
		else if (Type == 14)
		{
			if (frLacay2 == null)
			{
				frLacay2 = new FrameImage(lacay2, 16, 10);
			}
			frmImg = frLacay2;
		}
		isSmallSmoke = false;
	}

	public static void loadImage()
	{
		rock1 = CCanvas.loadImage("/eff/rock1.png");
		rock2 = CCanvas.loadImage("/eff/rock2.png");
		star = CCanvas.loadImage("/eff/star.png");
		frRock1 = new FrameImage(rock1, 7, 6);
		frRock2 = new FrameImage(rock2, 7, 7);
	}

	public static bool isExistImgRock(int id)
	{
		for (int i = 0; i < vImageID.size(); i++)
		{
			if (((ImageRock)vImageID.elementAt(i)).id == id)
			{
				return true;
			}
		}
		return false;
	}

	public static bool isExistImgRockF(int id)
	{
		for (int i = 0; i < vImageIDF.size(); i++)
		{
			if (((ImageRock)vImageIDF.elementAt(i)).id == id)
			{
				return true;
			}
		}
		return false;
	}

	public bool isRock()
	{
		if (type == 2 || type == 3)
		{
			return true;
		}
		return false;
	}

	public static void unload()
	{
		smoke = null;
		longSmoke = null;
		fireSmoke = null;
		redSmoke = null;
		lazerSmoke = null;
		nukeSmoke = null;
		water = null;
		blackSmoke = null;
		wind = null;
		bat = null;
		longga = null;
		lacay = null;
		chuotbay = null;
		gatruilong = null;
		lacay2 = null;
		frSmoke = null;
		frLongSmoke = null;
		frFireSmoke = null;
		frRedSmoke = null;
		fzLazerSmoke = null;
		frNukeSmoke = null;
		frWater = null;
		frBlackSmoke = null;
		frWind = null;
		frLongga = null;
		frLacay = null;
		frChuotbay = null;
		frGatruilong = null;
		frLacay2 = null;
	}

	public static void load(sbyte type)
	{
		switch (type)
		{
		case 0:
			if (smoke == null)
			{
				smoke = CCanvas.loadImage("/eff/smoke.png");
			}
			break;
		case 19:
			if (longSmoke == null)
			{
				longSmoke = CCanvas.loadImage("/eff/smoke2.png");
			}
			break;
		case 21:
			if (fireSmoke == null)
			{
				fireSmoke = CCanvas.loadImage("/eff/smokeFire.png");
			}
			break;
		case 7:
			if (redSmoke == null)
			{
				redSmoke = CCanvas.loadImage("/eff/blueSmoke.png");
			}
			break;
		case 13:
			if (lazerSmoke == null)
			{
				lazerSmoke = CCanvas.loadImage("/eff/blueSmoke2.png");
			}
			break;
		case 15:
			if (nukeSmoke == null)
			{
				nukeSmoke = CCanvas.loadImage("/eff/khoi.png");
			}
			break;
		case 11:
			if (water == null)
			{
				water = CCanvas.loadImage("/eff/water.png");
			}
			break;
		case 1:
			if (blackSmoke == null)
			{
				blackSmoke = CCanvas.loadImage("/eff/blacksmoke.png");
			}
			break;
		case 22:
			if (wind == null)
			{
				wind = CCanvas.loadImage("/eff/locxoay2.png");
			}
			break;
		case 17:
			if (bat == null)
			{
				bat = CCanvas.loadImage("/eff/bat.png");
			}
			break;
		case 8:
			if (longga == null)
			{
				longga = CCanvas.loadImage("/eff/longga.png");
			}
			break;
		case 12:
			if (lacay == null)
			{
				lacay = CCanvas.loadImage("/eff/lacay.png");
			}
			break;
		case 9:
			if (chuotbay == null)
			{
				chuotbay = CCanvas.loadImage("/eff/chuotbay.png");
			}
			break;
		case 10:
			if (gatruilong == null)
			{
				gatruilong = CCanvas.loadImage("/eff/gatruilong.png");
			}
			break;
		case 14:
			if (lacay2 == null)
			{
				lacay2 = CCanvas.loadImage("/eff/lacay2.png");
			}
			break;
		case 2:
		case 3:
		case 4:
		case 5:
		case 6:
		case 16:
		case 18:
		case 20:
			break;
		}
	}

	public Image getRandomImage()
	{
		if (vImageID.size() == 0)
		{
			return rock1;
		}
		int num = CRes.random(0, vImageID.size());
		CRes.outz("random= " + num + " vSize= " + vImageID.size());
		if ((ImageRock)vImageID.elementAt(num) != null)
		{
			return ((ImageRock)vImageID.elementAt(num)).img;
		}
		return null;
	}

	public FrameImage getRandomImageF()
	{
		if (vImageIDF.size() == 0)
		{
			return frRock2;
		}
		int index = CRes.random(0, vImageIDF.size());
		if ((ImageRock)vImageIDF.elementAt(index) != null)
		{
			return ((ImageRock)vImageIDF.elementAt(index)).frImg;
		}
		return null;
	}

	public void createSmoke(sbyte TYPE)
	{
		smallSmokeDelay++;
		if (smallSmokeDelay > 2)
		{
			GameScr.sm.addSmoke(x, y, TYPE);
			smallSmokeDelay = 0;
		}
	}

	public void checkWaterCollide()
	{
	}

	public static int checkWay(int x, int y, int xTo, int yTo)
	{
		int num = 0;
		int num2 = 1;
		int num3 = 2;
		int num4 = 3;
		int result = -1;
		if (xTo >= x && yTo <= y)
		{
			int num5 = xTo - x;
			int num6 = y - yTo;
			result = ((num5 <= num6) ? num3 : num2);
		}
		if (xTo >= x && yTo >= y)
		{
			int num7 = xTo - x;
			int num8 = yTo - y;
			result = ((num7 <= num8) ? num4 : num2);
		}
		if (xTo <= x && yTo <= y)
		{
			int num9 = x - xTo;
			int num10 = y - yTo;
			result = ((num9 <= num10) ? num3 : num);
		}
		if (xTo <= x && yTo >= y)
		{
			int num11 = x - xTo;
			int num12 = yTo - y;
			result = ((num11 <= num12) ? num4 : num);
		}
		return result;
	}

	public void flyTo()
	{
		float num = (float)xBat - x;
		float num2 = (float)yBat - y;
		if (Math.abs((int)num) < 16 && Math.abs((int)num2) < 16)
		{
			GameScr.sm.removeSmoke(this);
			return;
		}
		int num3 = CRes.angle((int)num, (int)num2);
		if (Math.abs(num3 - angle) < 90 || num * num + num2 * num2 > 4096f)
		{
			if (Math.abs(num3 - angle) < 15)
			{
				angle = num3;
			}
			else if ((num3 - angle >= 0 && num3 - angle < 180) || num3 - angle < -180)
			{
				angle = CRes.fixangle(angle + 15);
			}
			else
			{
				angle = CRes.fixangle(angle - 15);
			}
		}
		if (va < 8192)
		{
			va += 1024;
		}
		vx = va * CRes.cos(angle) >> 10;
		vy = va * CRes.sin(angle) >> 10;
		num += vx;
		int num4 = (int)num >> 10;
		x += num4;
		num = (int)num & 0x3FF;
		num2 += vy;
		int num5 = (int)num2 >> 10;
		y += num5;
		num2 = (int)num2 & 0x3FF;
	}

	public void update()
	{
		switch (type)
		{
		case 0:
		case 7:
		case 11:
		case 13:
			if (curFrame == 3)
			{
				GameScr.sm.removeSmoke(this);
			}
			else
			{
				updateFrame();
			}
			break;
		case 19:
			if (!isStop)
			{
				timeStop++;
				if (timeStop == 10)
				{
					timeStop = 0;
					isStop = true;
				}
				if (curFrame > 4)
				{
					curFrame = 0;
				}
				if (CCanvas.gameTick % ((!CScreen.isUseHighFrameRate()) ? 2 : 4) == 0)
				{
					curFrame++;
				}
			}
			else if (CCanvas.gameTick % ((!CScreen.isUseHighFrameRate()) ? 2 : 4) == 0)
			{
				if (curFrame == 7)
				{
					GameScr.sm.removeSmoke(this);
				}
				else
				{
					curFrame++;
				}
			}
			break;
		case 21:
			if (curFrame == 7)
			{
				GameScr.sm.removeSmoke(this);
			}
			else
			{
				curFrame++;
			}
			break;
		case 15:
			if (curFrame == 3)
			{
				GameScr.sm.removeSmoke(this);
			}
			else
			{
				updateFrame();
			}
			break;
		case 1:
			if (curFrame == 3)
			{
				GameScr.sm.removeSmoke(this);
			}
			else
			{
				updateFrame();
			}
			break;
		case 2:
		case 3:
			if (!isLand)
			{
				if (type == 3)
				{
					updateFrame();
					if (curFrame > 3)
					{
						curFrame = 0;
					}
				}
				if (y > (float)MM.mapHeight)
				{
					GameScr.sm.removeSmoke(this);
					break;
				}
				x += vx * ((!CScreen.isUseHighFrameRate()) ? 1f : 0.5f);
				y += vy * ((!CScreen.isUseHighFrameRate()) ? 1f : 0.5f);
				vy += ((!CScreen.isUseHighFrameRate()) ? 1f : 0.5f) * (float)CRes.random(1, 3);
				checkWaterCollide();
				if (isSmallSmoke)
				{
					createSmoke(1);
				}
				if (GameScr.mm.isLand((int)x, (int)y) && vy > 1f)
				{
					isLand = true;
				}
			}
			else
			{
				delay++;
				if (delay == 100 || GameScr.sm.smokes.size() > 50)
				{
					GameScr.sm.removeSmoke(this);
				}
			}
			break;
		case 20:
			if (y > (float)MM.mapHeight)
			{
				GameScr.sm.removeSmoke(this);
				break;
			}
			x += vx;
			y += vy;
			vy += 1f;
			break;
		case 4:
		case 5:
		case 18:
		{
			for (int i = 0; i < num; i++)
			{
				smokeX[i] += (int)vx;
				smokeY[i] += (int)vy;
				if (smokeY[i] < endY)
				{
					GameScr.sm.removeSmoke(this);
					return;
				}
			}
			smokeHeight += 5;
			if (smokeHeight > 255)
			{
				smokeHeight = 255;
			}
			break;
		}
		case 6:
		case 8:
		case 12:
		case 14:
			if (CScreen.highFrameRate())
			{
				break;
			}
			updateFrame();
			if (vy > 0f)
			{
				vx = GameScr.windx / 20;
				if (curFrame > 3)
				{
					curFrame = 0;
				}
			}
			else
			{
				curFrame = 0;
			}
			if (y > (float)MM.mapHeight)
			{
				GameScr.sm.removeSmoke(this);
				break;
			}
			x += vx;
			y += vy;
			if (vy < 2f)
			{
				vy += 1f;
			}
			break;
		case 9:
		case 10:
			if (!CScreen.highFrameRate())
			{
				if (y > (float)MM.mapHeight)
				{
					GameScr.sm.removeSmoke(this);
					break;
				}
				x += vx;
				y += vy;
				vy += 1f;
				checkWaterCollide();
			}
			break;
		case 17:
			delay++;
			if (delay == 10)
			{
				delay = 0;
			}
			if (delay < 5)
			{
				curFrame = 0;
			}
			else
			{
				curFrame = 1;
			}
			flyTo();
			break;
		case 22:
			if (curFrame == 3)
			{
				curFrame = 0;
			}
			tWind++;
			if (tWind == 50)
			{
				tWind = 0;
				GameScr.sm.removeSmoke(this);
			}
			updateFrame();
			break;
		case 16:
			break;
		}
	}

	private void updateFrame()
	{
		if (!CScreen.highFrameRate())
		{
			delay++;
			if (delay > 1)
			{
				curFrame++;
				delay = 0;
			}
		}
	}

	public void paintEffect(mGraphics g)
	{
		switch (type)
		{
		case 0:
		case 1:
		case 7:
		case 13:
		case 15:
		case 19:
		case 21:
			frmImg.drawFrame(curFrame, x, y, 0, mGraphics.HCENTER | mGraphics.VCENTER, g, false);
			break;
		case 2:
			g.drawImage(rockImgColor, x, y, mGraphics.HCENTER | mGraphics.VCENTER, false);
			break;
		case 20:
			g.drawImage(star, x, y, mGraphics.HCENTER | mGraphics.VCENTER, false);
			break;
		case 3:
			frmImg.drawFrame(curFrame, x, y, 0, mGraphics.HCENTER | mGraphics.VCENTER, g, false);
			break;
		case 4:
		case 5:
			break;
		case 18:
			break;
		case 6:
		case 8:
		case 9:
		case 10:
		case 11:
		case 12:
		case 14:
			frmImg.drawFrame(curFrame, x, y, 0, mGraphics.HCENTER | mGraphics.VCENTER, g, false);
			break;
		case 16:
		{
			if (!activeLazer)
			{
				break;
			}
			for (int i = 0; i < wLazer; i++)
			{
				if (i < wLazer / 2 + wLazer / 4 && i > wLazer / 2 - wLazer / 4)
				{
					g.setColor(16777215);
				}
				else
				{
					if (typeLazer == 1)
					{
						g.setColor(718162);
					}
					if (typeLazer == 0)
					{
						g.setColor(16729670);
					}
				}
				g.drawLineWp(xLazer - wLazer / 2 + i, yLazer, (int)x - wLazer / 2 + i, (int)y, false);
			}
			wLazer--;
			if (wLazer == 0)
			{
				activeLazer = false;
				GameScr.sm.removeSmoke(this);
			}
			break;
		}
		case 17:
			frmImg.drawFrame(curFrame, x, y, 0, mGraphics.HCENTER | mGraphics.VCENTER, g, false);
			break;
		case 22:
			frmImg.drawFrame(curFrame, x, y, 0, 33, g, false);
			break;
		}
	}

	public void paint(mGraphics g)
	{
		paintEffect(g);
	}
}
