using System;
using Assets.src.model;

public class Explosion
{
	public const sbyte EXPLODE_NORMAL = 0;

	public const sbyte EXPLORE_NORMAL_2 = 11;

	public const sbyte TELEPORT = 1;

	public const sbyte WATER_BUM = 2;

	public const sbyte RAIN_EFFECT = 6;

	public const sbyte ITEM_USE_EFFECT = 3;

	public const sbyte ITEM_BLINK = 4;

	public const sbyte ITEM_ICON_FLY = 5;

	public const sbyte NUKE = 7;

	public const sbyte ELECTRIC = 8;

	public const sbyte ELECTRIC_2 = 9;

	public const sbyte POISON = 10;

	public const sbyte EYE_SMOKE = 12;

	public const sbyte SUICIDE = 13;

	public const sbyte FREEZE = 14;

	public const sbyte POSION_SMOKE = 15;

	public const sbyte LASER = 16;

	public const sbyte THOR_STORM = 17;

	public static Image explode;

	public static Image teleport;

	public static Image waterBum;

	public static Image imgRain;

	public static Image imgNuke;

	public static Image electric;

	public static Image poison_attack;

	public static Image freeze;

	public static Image khoidoc;

	public static Image explode_normal;

	public static Image itemEffImg;

	public static Image invisibleEff;

	public static Image dongbang;

	public static Image timeBomb;

	public static FrameImage frItemEffImg;

	public static FrameImage frInvisibleEff;

	public static FrameImage frExplode;

	public static FrameImage frTeleport;

	public static FrameImage frWaterBum;

	public static FrameImage frImgRain;

	public static FrameImage frImgNuke;

	public static FrameImage frElectric;

	public static FrameImage frPoison;

	public static FrameImage frFreeze;

	public static FrameImage frKhoiDoc;

	public static FrameImage frExplodeNornal;

	private FrameImage frmImg;

	private int x;

	private int y;

	private int endY;

	private int wE;

	private int delay;

	private int frameCountDelay;

	private int curFrame;

	public sbyte whoUseEffect;

	public sbyte itemID;

	private int[][] array;

	public sbyte type;

	private short iconUse;

	private int maxDelay = 1;

	private int tLazer;

	private int toX;

	private int toY;

	private int x1000;

	private int y1000;

	private int fRemove;

	private int timeAddNum;

	private int f;

	private MyVector VecEff;

	private MyVector VecSubEff;

	public Explosion(int x, int y, sbyte exType)
	{
		this.x = x;
		this.y = y;
		if (BackgroundNew.lowGraphic && (exType == 8 || exType == 9 || exType == 7))
		{
			exType = 0;
		}
		type = exType;
		load(type);
		switch (exType)
		{
		case 0:
			if (frExplodeNornal == null)
			{
				frExplodeNornal = new FrameImage(explode_normal, 27, 27);
			}
			frmImg = frExplodeNornal;
			break;
		case 13:
			if (frExplode == null)
			{
				frExplode = new FrameImage(explode, 59, 64);
			}
			frmImg = frExplode;
			break;
		case 1:
			if (frTeleport == null)
			{
				frTeleport = new FrameImage(teleport, 32, 32);
			}
			frmImg = frTeleport;
			break;
		case 2:
			if (frWaterBum == null)
			{
				frWaterBum = new FrameImage(waterBum, 32, 48);
			}
			frmImg = frWaterBum;
			break;
		case 6:
			if (frImgRain == null)
			{
				frImgRain = new FrameImage(imgRain, 13, 7);
			}
			frmImg = frImgRain;
			break;
		case 7:
			if (frImgNuke == null)
			{
				frImgNuke = new FrameImage(imgNuke, 48, 62);
			}
			frmImg = frImgNuke;
			break;
		case 8:
		case 9:
			if (frElectric == null)
			{
				frElectric = new FrameImage(electric, 59, 64);
			}
			frmImg = frElectric;
			break;
		case 10:
			if (frPoison == null)
			{
				frPoison = new FrameImage(poison_attack, 12, 12);
			}
			frmImg = frPoison;
			break;
		case 14:
			if (frFreeze == null)
			{
				frFreeze = new FrameImage(freeze, 40, 40);
			}
			frmImg = frFreeze;
			break;
		case 15:
			if (frKhoiDoc == null)
			{
				frKhoiDoc = new FrameImage(khoidoc, 32, 32);
			}
			frmImg = frKhoiDoc;
			break;
		}
		GameScr.exs.addElement(this);
	}

	public Explosion(int x, int y, sbyte exType, sbyte WhoUseEffect, sbyte itemID, short iconUse)
	{
		this.x = x;
		this.y = y;
		this.iconUse = iconUse;
		type = exType;
		this.itemID = itemID;
		whoUseEffect = WhoUseEffect;
		if (exType == 3)
		{
			if (itemEffImg == null)
			{
				itemEffImg = CCanvas.loadImage("/eff/Eff.png");
			}
			if (frItemEffImg == null)
			{
				frItemEffImg = new FrameImage(itemEffImg, 40, 40);
			}
			frmImg = frItemEffImg;
		}
		else if (exType == 5)
		{
			this.y -= 24;
			endY = this.y - 50;
		}
		if (itemID == 4 || itemID == 34)
		{
			if (invisibleEff == null)
			{
				invisibleEff = CCanvas.loadImage("/eff/tangHinhEffect.png");
			}
			if (frInvisibleEff == null)
			{
				frInvisibleEff = new FrameImage(invisibleEff, 24, 32);
			}
			frmImg = frInvisibleEff;
		}
		GameScr.exs.addElement(this);
	}

	public Explosion(int x, int y, int toX, int toY, sbyte type)
	{
		this.x = x;
		this.y = y;
		this.toX = toX;
		this.toY = toY;
		this.type = type;
		if (type == 17)
		{
			VecEff = new MyVector(string.Empty);
			VecSubEff = new MyVector(string.Empty);
			fRemove = 10;
			timeAddNum = 7;
			int a = CRes.angle(toX - x, toY - y);
			int num = CRes.abs(getDistance(x, y, toX, toY)) + 30;
			x1000 = x + CRes.cos(a) * num / 1000;
			y1000 = y + CRes.sin(a) * num / 1000;
			createLighting(x, y, x1000, y1000, true);
		}
		GameScr.exs.addElement(this);
	}

	public static void loadOnce()
	{
		dongbang = CCanvas.loadImage("/eff/dongbang.png");
	}

	public static void load(sbyte type)
	{
		switch (type)
		{
		case 0:
			if (explode_normal == null)
			{
				explode_normal = CCanvas.loadImage("/eff/khoi.png");
			}
			break;
		case 13:
			if (explode == null)
			{
				explode = CCanvas.loadImage("/eff/ex3.png");
			}
			break;
		case 1:
			if (teleport == null)
			{
				teleport = CCanvas.loadImage("/eff/teleport_eff.png");
			}
			break;
		case 2:
			if (waterBum == null)
			{
				waterBum = CCanvas.loadImage("/eff/waterBum.png");
			}
			break;
		case 6:
			if (imgRain == null)
			{
				imgRain = CCanvas.loadImage("/eff/mua.png");
			}
			break;
		case 7:
			if (imgNuke == null)
			{
				imgNuke = CCanvas.loadImage("/eff/bomnguyentu.png");
			}
			break;
		case 8:
		case 9:
			if (electric == null)
			{
				electric = CCanvas.loadImage("/eff/electric.png");
			}
			break;
		case 10:
			if (poison_attack == null)
			{
				poison_attack = CCanvas.loadImage("/eff/poison-attack.png");
			}
			break;
		case 14:
			if (freeze == null)
			{
				freeze = CCanvas.loadImage("/eff/freeze.png");
			}
			break;
		case 15:
			if (khoidoc == null)
			{
				khoidoc = CCanvas.loadImage("/eff/khoidoc.png");
			}
			break;
		case 3:
		case 4:
		case 5:
		case 11:
		case 12:
			break;
		}
	}

	public static void unload()
	{
		explode = null;
		teleport = null;
		waterBum = null;
		imgRain = null;
		imgNuke = null;
		electric = null;
		poison_attack = null;
		freeze = null;
		khoidoc = null;
		itemEffImg = null;
		invisibleEff = null;
		frItemEffImg = null;
		frInvisibleEff = null;
		frExplode = null;
		frTeleport = null;
		frWaterBum = null;
		frImgRain = null;
		frImgNuke = null;
		frElectric = null;
		frPoison = null;
		frFreeze = null;
		frKhoiDoc = null;
	}

	private int getDistance(int x1, int y1, int x2, int y2)
	{
		return (int)System.Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
	}

	private void createLighting(int xFrom, int yFrom, int xTo, int yTo, bool isEnd)
	{
		int num = 0;
		int num2 = 0;
		int num3 = 0;
		int num4 = getDistance(xFrom, yFrom, xTo, yTo) / 15 + CRes.random(3);
		int num5 = CRes.random(2);
		num2 = CRes.angle(xTo - xFrom, yTo - yFrom);
		int num6 = 20;
		for (int i = 0; i < num4; i++)
		{
			Point point = new Point();
			if (i == 0)
			{
				point.x = xFrom * 1000;
				point.y = yFrom * 1000;
			}
			else
			{
				Point point2 = (Point)VecEff.elementAt(i - 1);
				num6 = 20 + CRes.random_Am_0(10);
				int distance = getDistance(point2.x / 1000, point2.y / 1000, xTo, yTo);
				if ((distance < 25 || i == num4 - 1) && isEnd)
				{
					point.x = xTo * 1000;
					point.y = yTo * 1000;
					break;
				}
				num3 = num2;
				num3 = (isEnd ? ((CRes.abs(num) > 50) ? ((num <= 0) ? (num3 + CRes.random(5, 50)) : (num3 - CRes.random(5, 50))) : ((i % 2 != num5) ? (num3 + CRes.random(5, 50)) : (num3 - CRes.random(5, 50)))) : ((CRes.abs(num) > 50) ? ((num <= 0) ? (num3 + CRes.random(5, 50)) : (num3 - CRes.random(5, 50))) : ((i % 2 != num5) ? (num3 + CRes.random(10, 40)) : (num3 - CRes.random(10, 40)))));
				num += num3 - num2;
				num3 = CRes.fixangle(num3);
				point.x = point2.x + CRes.cos(num3) * num6;
				point.y = point2.y + CRes.sin(num3) * num6;
				if (CRes.random(6) < 5)
				{
					VecSubEff.addElement(point);
					Point point3 = new Point();
					point3 = point;
					int num7 = 10;
					int num8 = num3;
					int num9 = CRes.random(3, 7);
					for (int j = 0; j < num9; j++)
					{
						num7 = 5 + CRes.random_Am_0(3);
						num8 = num3;
						num8 = ((j % 2 != num5) ? (num8 + CRes.random(10, 40)) : (num8 - CRes.random(10, 40)));
						num8 = CRes.fixangle(num8);
						Point point4 = new Point();
						point4.x = point3.x + CRes.cos(num8) * num7;
						point4.y = point3.y + CRes.sin(num8) * num7;
						VecSubEff.addElement(point4);
						point3 = point4;
					}
					point3.x = -1;
					VecSubEff.addElement(point3);
				}
			}
			VecEff.addElement(point);
		}
	}

	public void update()
	{
		if (CScreen.highFrameRate())
		{
			return;
		}
		switch (type)
		{
		case 0:
			if (curFrame == 6)
			{
				GameScr.exs.removeElement(this);
				return;
			}
			break;
		case 11:
		case 13:
			if (curFrame == 5)
			{
				GameScr.exs.removeElement(this);
				return;
			}
			break;
		case 8:
		case 9:
			maxDelay = 2;
			if (curFrame == 7)
			{
				GameScr.exs.removeElement(this);
				return;
			}
			break;
		case 1:
			if (curFrame == 4)
			{
				GameScr.exs.removeElement(this);
				return;
			}
			break;
		case 2:
			if (curFrame == 4)
			{
				GameScr.exs.removeElement(this);
				return;
			}
			break;
		case 7:
			if (curFrame == 3)
			{
				GameScr.exs.removeElement(this);
				return;
			}
			maxDelay = 3;
			break;
		case 10:
			if (curFrame == 3)
			{
				GameScr.exs.removeElement(this);
				return;
			}
			break;
		case 3:
			if (PM.p[whoUseEffect] != null)
			{
				x = PM.p[whoUseEffect].x;
				y = PM.p[whoUseEffect].y;
			}
			if (curFrame == 4)
			{
				GameScr.exs.removeElement(this);
				return;
			}
			break;
		case 5:
			x = PM.p[whoUseEffect].x;
			y--;
			if (y < endY)
			{
				GameScr.exs.removeElement(this);
				return;
			}
			break;
		case 4:
			if (PM.p[whoUseEffect] == null)
			{
				break;
			}
			x = PM.p[whoUseEffect].x;
			y = PM.p[whoUseEffect].y - 13;
			if (itemID == 4 || itemID == 34)
			{
				if (!PM.p[whoUseEffect].isInvisible)
				{
					GameScr.exs.removeElement(this);
					return;
				}
				if (curFrame == 4)
				{
					curFrame = 0;
				}
			}
			else if (itemID == 3 && !PM.p[whoUseEffect].isRunSpeed)
			{
				GameScr.exs.removeElement(this);
				return;
			}
			break;
		case 6:
			if (curFrame == 2)
			{
				GameScr.exs.removeElement(this);
			}
			break;
		case 14:
			maxDelay = 2;
			if (curFrame == 4)
			{
				GameScr.exs.removeElement(this);
			}
			break;
		case 15:
			maxDelay = 2;
			if (curFrame == 4)
			{
				GameScr.exs.removeElement(this);
			}
			break;
		case 16:
			tLazer++;
			if (tLazer > 40)
			{
				tLazer = 0;
				GameScr.exs.removeElement(this);
			}
			break;
		case 17:
			f++;
			if (f >= fRemove)
			{
				GameScr.exs.removeElement(this);
			}
			break;
		}
		delay++;
		if (delay > maxDelay)
		{
			curFrame++;
			delay = 0;
		}
	}

	public void paint(mGraphics g)
	{
		MyVector vLine = new MyVector();
		switch (type)
		{
		case 0:
		case 1:
		case 3:
		case 7:
		case 8:
		case 9:
		case 11:
		case 14:
		case 15:
			frmImg.drawFrame(curFrame, x, y - 12, 0, mGraphics.HCENTER | mGraphics.VCENTER, g, false);
			break;
		case 13:
			frmImg.drawFrame(curFrame, x, y - 12, 0, mGraphics.HCENTER | mGraphics.VCENTER, g, false);
			frmImg.drawFrame(curFrame, x + 10, y - 12 + 10, 0, mGraphics.HCENTER | mGraphics.VCENTER, g, false);
			frmImg.drawFrame(curFrame, x - 10, y - 12 + 10, 0, mGraphics.HCENTER | mGraphics.VCENTER, g, false);
			frmImg.drawFrame(curFrame, x + 10, y - 12 - 10, 0, mGraphics.HCENTER | mGraphics.VCENTER, g, false);
			frmImg.drawFrame(curFrame, x - 10, y - 12 - 10, 0, mGraphics.HCENTER | mGraphics.VCENTER, g, false);
			frmImg.drawFrame(curFrame, x, y - 12 + 20, 0, mGraphics.HCENTER | mGraphics.VCENTER, g, false);
			frmImg.drawFrame(curFrame, x, y - 12 - 20, 0, mGraphics.HCENTER | mGraphics.VCENTER, g, false);
			frmImg.drawFrame(curFrame, x + 20, y - 12, 0, mGraphics.HCENTER | mGraphics.VCENTER, g, false);
			frmImg.drawFrame(curFrame, x - 20, y - 12, 0, mGraphics.HCENTER | mGraphics.VCENTER, g, false);
			break;
		case 2:
			frmImg.drawFrame(curFrame, x, y + 6, 0, mGraphics.HCENTER | mGraphics.BOTTOM, g, false);
			break;
		case 10:
			frmImg.drawFrame(curFrame, x, y - 6, 0, 3, g, false);
			break;
		case 5:
			Item.DrawItem(g, iconUse, x - 8, y);
			break;
		case 4:
			if (itemID == 4 || itemID == 34)
			{
				if (PM.p[whoUseEffect].team == PM.p[GameScr.myIndex].team || whoUseEffect == GameScr.myIndex)
				{
					frmImg.drawFrame(curFrame, x, y - 2, 0, mGraphics.HCENTER | mGraphics.VCENTER, g, false);
					if (CCanvas.gameTick % 10 > 2)
					{
						Item.DrawItem(g, iconUse, x - 8, y - 37);
					}
				}
			}
			else if (!PM.p[whoUseEffect].isInvisible && CCanvas.gameTick % 10 > 2)
			{
				Item.DrawItem(g, iconUse, x - 29, y - 47);
			}
			break;
		case 6:
			frmImg.drawFrame(curFrame, x, y - 5, 0, mGraphics.HCENTER | mGraphics.VCENTER, g, false);
			break;
		case 12:
			CRes.outz("eye smoke");
			g.setColor(16777215);
			g.fillArc2(x - wE / 2, y - wE / 2, wE, wE, 0, 360);
			wE += 60;
			if (wE > 1000)
			{
				x = 0;
				wE = 0;
				GameScr.exs.removeElement(this);
			}
			break;
		case 16:
			if (tLazer < 40)
			{
				if (tLazer < 35)
				{
					g.drawLine(x, y - 1, toX, toY - 1, 16777215, ref vLine);
				}
				g.drawLine(x, y + 2, toX, toY + 2, 16777215, ref vLine);
			}
			if (tLazer < 30)
			{
				if (tLazer < 25)
				{
					g.drawLine(x, y, toX, toY, 16737792, ref vLine);
				}
				g.drawLine(x, y + 1, toX, toY + 1, 16737792, ref vLine);
			}
			break;
		case 17:
		{
			if (f % 5 >= 2 && f % 5 != 3)
			{
				break;
			}
			for (int i = 1; i < VecEff.size(); i++)
			{
				Point point = (Point)VecEff.elementAt(i - 1);
				Point point2 = (Point)VecEff.elementAt(i);
				g.drawLine(point.x / 1000, point.y / 1000 - 1, point2.x / 1000, point2.y / 1000 - 1, 15791864, ref vLine);
				g.drawLine(point.x / 1000, point.y / 1000 + 1, point2.x / 1000, point2.y / 1000 + 1, 15791864, ref vLine);
				g.drawLine(point.x / 1000, point.y / 1000 + 2, point2.x / 1000, point2.y / 1000 + 2, 15791864, ref vLine);
				g.drawLine(point.x / 1000, point.y / 1000, point2.x / 1000, point2.y / 1000, 11068406, ref vLine);
			}
			for (int j = 1; j < VecSubEff.size(); j++)
			{
				Point point3 = (Point)VecSubEff.elementAt(j - 1);
				Point point4 = (Point)VecSubEff.elementAt(j);
				if (point4.x != -1 && point3.x != -1)
				{
					g.drawLine(point3.x / 1000, point3.y / 1000, point4.x / 1000, point4.y / 1000, 15791864, ref vLine);
					g.drawLine(point3.x / 1000, point3.y / 1000 + 1, point4.x / 1000, point4.y / 1000 + 1, 15791864, ref vLine);
				}
			}
			break;
		}
		}
		g.drawlineGL(vLine);
	}
}
