using System;

namespace Assets.src.player
{
	internal class BigBoss : CPlayer
	{
		public const sbyte TURTLE = 1;

		public const sbyte DRAGON = 2;

		public const sbyte KYLAN = 3;

		public const sbyte PHOENIX = 4;

		public const sbyte PSTATE_JUMP_SKILL = 20;

		public const sbyte PSTATE_BITE = 21;

		public const sbyte PSTATE_GAP_THA1 = 22;

		public const sbyte PSTATE_GAP_THA2 = 23;

		public const sbyte PSTATE_GAP_THA3 = 24;

		public const sbyte PSTATE_GAP_THA4 = 25;

		public int xTha;

		public int yTha;

		public int xSave;

		public int ySave;

		public int dAngle;

		public sbyte chairVictim;

		public EffectData data;

		public int[] fBite;

		public int[] fShot;

		public int[] fShot2;

		public int[] fInjury;

		public int[] fCarry;

		private int tFire;

		private bool isSkill = true;

		public BigBoss(sbyte type)
		{
			base.type = type;
			getData(type);
			look = 2;
			lookAngle = 2;
			switch (type)
			{
			case 1:
				feStand = new int[4] { 0, 0, 1, 1 };
				fMove = new int[8] { 1, 1, 2, 2, 3, 3, 2, 2 };
				fRun = new int[8] { 1, 1, 2, 2, 3, 3, 2, 2 };
				fBite = new int[3] { 5, 6, 7 };
				fShot = new int[3] { 1, 9, 10 };
				fShot2 = new int[12]
				{
					0, 0, 8, 8, 0, 0, 8, 8, 0, 0,
					8, 8
				};
				fInjury = new int[4] { 1, 1, 11, 11 };
				break;
			case 2:
				feStand = new int[4] { 0, 1, 2, 1 };
				fMove = new int[4] { 0, 1, 2, 1 };
				fRun = new int[4] { 0, 1, 2, 1 };
				fShot = new int[6] { 3, 3, 4, 4, 5, 5 };
				fInjury = new int[4] { 0, 0, 7, 7 };
				fCarry = new int[8] { 0, 0, 1, 1, 2, 2, 5, 5 };
				break;
			}
			status = 0;
		}

		public void unload()
		{
			data.img = null;
			data = null;
		}

		public void getData(sbyte type)
		{
			data = null;
			data = new EffectData();
			int num = 28;
			switch (type)
			{
			case 1:
				num = 28;
				break;
			case 2:
				num = 30;
				break;
			}
			string patch = "/effect/" + num + "/data";
			try
			{
				data.readData2(patch);
				data.img = CCanvas.loadImage2("/effect/" + num + "/x" + mGraphics.zoomLevel + ".png");
			}
			catch (Exception)
			{
			}
			status = 0;
			w = data.width;
			h = data.height;
		}

		public void updateFrameHurt()
		{
			int num = ((!CScreen.isUseHighFrameRate()) ? 3 : 6);
			dem++;
			if (dem >= fInjury.Length * num)
			{
				dem = 0;
			}
			else
			{
				cf = fInjury[dem / num];
			}
		}

		public void updateCharShot()
		{
			int num = ((!CScreen.isUseHighFrameRate()) ? 3 : 6);
			dem++;
			if (dem >= fShot.Length * num)
			{
				dem = 0;
				state = 0;
			}
			else
			{
				cf = fShot[dem / num];
			}
		}

		public void updateCharCarry()
		{
			int num = ((!CScreen.isUseHighFrameRate()) ? 3 : 6);
			dem++;
			if (dem >= fCarry.Length * num)
			{
				dem = 0;
				state = 25;
				if (PM.p[chairVictim] != null)
				{
					GameScr.cam.setPlayerMode(chairVictim);
				}
			}
			else
			{
				cf = fCarry[dem / num];
			}
		}

		public void updateCharShot2()
		{
			int num = ((!CScreen.isUseHighFrameRate()) ? 3 : 6);
			dem++;
			if (dem >= fShot2.Length * num)
			{
				dem = 0;
				state = 0;
			}
			else
			{
				cf = fShot2[dem / num];
			}
		}

		public void updateCharBite()
		{
			int num = ((!CScreen.isUseHighFrameRate()) ? 3 : 6);
			dem++;
			if (dem >= fBite.Length * num)
			{
				mSystem.mNotify();
				dem = 0;
				state = 0;
			}
			else
			{
				cf = fBite[dem / num];
			}
		}

		public void jump()
		{
			vJump = 15;
			isSkill = true;
			falling = true;
		}

		public override void update()
		{
			updateDust();
			if (dieEffect)
			{
				if (dyDie > 0)
				{
					if (dyDie % 3 == 0)
					{
						startDust(0, x - 6, y + 3);
						startDust(2, x + 6, y + 3);
					}
					dyDie--;
				}
				if (clipDie < 25)
				{
					clipDie++;
				}
			}
			updateHPChange();
			switch (type)
			{
			case 1:
				if (state == 4 || state == 8)
				{
					tFire++;
				}
				else
				{
					tFire = 0;
				}
				switch (state)
				{
				case 4:
					if (tFire > 50)
					{
						updateCharShot();
					}
					else
					{
						cf = 0;
					}
					break;
				case 8:
					if (tFire > 50)
					{
						state = 0;
					}
					else
					{
						updateFrameHurt();
					}
					break;
				case 20:
					updateCharShot2();
					break;
				case 21:
					updateCharBite();
					break;
				default:
					cf = 0;
					break;
				}
				break;
			case 2:
				if (state == 4 || state == 8)
				{
					tFire++;
				}
				else
				{
					tFire = 0;
				}
				switch (state)
				{
				case 4:
					if (tFire > 50)
					{
						updateCharShot();
					}
					else
					{
						cf = 0;
					}
					break;
				case 8:
					if (tFire > 50)
					{
						state = 0;
					}
					else
					{
						updateFrameHurt();
					}
					break;
				case 23:
					if (PM.p[chairVictim] != null)
					{
						PM.p[chairVictim].x2 = (PM.p[chairVictim].x = (PM.p[chairVictim].xToNow = ((look != 2) ? (x - 15) : (x + 15))));
						PM.p[chairVictim].y = (PM.p[chairVictim].yToNow = y + 20);
					}
					updateFrameStand();
					break;
				case 24:
					updateCharCarry();
					if (PM.p[chairVictim] != null)
					{
						PM.p[chairVictim].x2 = (PM.p[chairVictim].x = (PM.p[chairVictim].xToNow = ((look != 2) ? (x - 15) : (x + 15))));
						PM.p[chairVictim].y = (PM.p[chairVictim].yToNow = y + 20);
					}
					break;
				case 25:
					if (PM.p[chairVictim] != null)
					{
						int num = 40;
						dAngle = CRes.angle(xTha - PM.p[chairVictim].x, yTha - PM.p[chairVictim].y);
						if (Math.abs(xTha - PM.p[chairVictim].x) <= num)
						{
							PM.p[chairVictim].x = xTha;
						}
						else
						{
							PM.p[chairVictim].x = PM.p[chairVictim].x + (num * CRes.cos(dAngle) >> 10);
						}
						if (Math.abs(yTha - PM.p[chairVictim].y) <= num)
						{
							PM.p[chairVictim].y = yTha;
						}
						else
						{
							PM.p[chairVictim].y = PM.p[chairVictim].y + (num * CRes.sin(dAngle) >> 10);
						}
						PM.p[chairVictim].x2 = PM.p[chairVictim].x;
						if (xTha == PM.p[chairVictim].x && yTha == PM.p[chairVictim].y)
						{
							PM.p[chairVictim].x2 = (PM.p[chairVictim].x = xTha);
							PM.p[chairVictim].xToNow = xTha;
							PM.p[chairVictim].nextx = xTha;
							PM.p[chairVictim].lastx = (short)xTha;
							PM.p[chairVictim].y = (PM.p[chairVictim].yToNow = yTha);
							PM.p[chairVictim].nexty = yTha;
							PM.p[chairVictim].lasty = (short)yTha;
							new Explosion(xTha, yTha, 7);
							mSystem.mNotify();
							state = 0;
						}
					}
					break;
				default:
					updateFrameStand();
					break;
				}
				break;
			}
			if (state != 1)
			{
				x2 = x;
			}
			if (isCom && !isFlyAvenger() && !flyPlayer && !isJump)
			{
				if (((CRes.abs(nextx - x) == 0 && !isRunSpeed) || (CRes.abs(x - nextx) <= 2 && isRunSpeed)) && ((CRes.abs(nexty - y) == 0 && !isRunSpeed) || (CRes.abs(nexty - y) <= 2 && isRunSpeed)) && (isMove || state == 1 || state == 0))
				{
					state = 0;
					updateFrameStand();
				}
				if (nextx < x && !falling)
				{
					move(2);
				}
				else if (nextx > x && !falling)
				{
					move(0);
				}
				if (nextx == x && nexty != y && state == 0 && !falling)
				{
					y = nexty;
				}
			}
			if (activeFallbyEx && !BM.active)
			{
				falling = true;
				activeFallbyEx = false;
				isActiveFall = true;
			}
			if (vJump > 0)
			{
				vJump--;
			}
			if (falling)
			{
				y -= vJump;
				fall();
				if (!falling && isSkill)
				{
					new Explosion(x - 20, y + 10, 1);
					new Explosion(x, y + 10, 1);
					new Explosion(x + 20, y + 10, 1);
					Camera.shaking = 2;
					isSkill = false;
					mSystem.mNotify();
				}
			}
			if (!isUsedItem && index == GameScr.myIndex)
			{
				angleReset();
			}
			if (poisonEff)
			{
				tPEff++;
				if (tPEff == 20)
				{
					tPEff = 0;
					poisonEff = false;
					CCanvas.lockNotify = true;
				}
				if (CCanvas.gameTick % 2 == 0)
				{
					new Explosion(CRes.random(x - 10, x + 10), CRes.random(y - 20, y + 2), 10);
				}
			}
			if (state != 1 && !flyActive && state != 22 && state != 23)
			{
				return;
			}
			if (!isFlyAvenger())
			{
				if (((CRes.abs(x - xToNow) == 0 && !isRunSpeed) || (CRes.abs(x - xToNow) <= 2 && isRunSpeed)) && ((CRes.abs(y - yToNow) == 0 && !isRunSpeed) || (CRes.abs(y - yToNow) <= 2 && isRunSpeed)) && isMove)
				{
					isMove = false;
					state = 0;
					CRes.outz("DA TOI NOI DA TOI NOI DA TOI NOI x= " + x + "y = " + y);
					mSystem.mNotify();
				}
			}
			else
			{
				if ((!CCanvas.isTouch || index != MyMidlet.myInfo.index || GameScr.curFocus == 5 || GameScr.curFocus == 6) && !isCom)
				{
					return;
				}
				float num2 = 5f;
				if (state == 22 || state == 23)
				{
					num2 = 12f;
				}
				isPoint = false;
				if ((float)Math.abs((int)((float)xToNow - x2)) <= num2)
				{
					x2 = xToNow;
				}
				else if ((float)xToNow - x2 > num2)
				{
					x2 += num2;
					look = 0;
					isMoveAvenger = true;
				}
				else if ((float)xToNow - x2 < num2)
				{
					x2 -= num2;
					look = 2;
					isMoveAvenger = true;
				}
				if ((float)Math.abs(yToNow - y) <= num2)
				{
					y = yToNow;
					nexty = y;
				}
				else if ((float)(yToNow - y) > num2)
				{
					y += (int)num2;
					nexty = y;
					isMoveAvenger = true;
				}
				else if (movePoint < (float)MAX_MOVE_POINT)
				{
					nexty = y;
					y -= (int)num2;
					isMoveAvenger = true;
				}
				x = (int)x2;
				if (x == xToNow && y == yToNow && !isFreeze)
				{
					xToNow = x;
					yToNow = y;
					CRes.outz("|||||||||||||||| send move " + flyActive + " " + state);
					flyActive = false;
					if (CCanvas.isTouch)
					{
						isMoveAvenger = false;
					}
					switch (state)
					{
					case 22:
						state = 23;
						changeDirection(xSave);
						xToNow = xSave;
						yToNow = ySave;
						break;
					case 23:
						look = lookAngle;
						state = 24;
						dem = 0;
						cf = fCarry[0];
						break;
					case 24:
						break;
					case 25:
						break;
					default:
						mSystem.mNotify();
						state = 0;
						break;
					}
				}
			}
		}

		private void painthp(mGraphics g)
		{
			if (bossType != 5 && bossType != 6 && GameScr.res.Equals(string.Empty) && state != 5 && hp > 0)
			{
				int num = 70;
				if (type == 2)
				{
					num += 45;
				}
				int num2 = x - 16;
				int num3 = y - 14 - num;
				g.drawImage(GameScr.frBarHP0, num2, num3 - 8, 0, true);
				int num4 = hpRectW * 27 / 25;
				if (num4 <= 1)
				{
					num4 = 2;
				}
				g.drawRegion(GameScr.frBarHP1, 0, 0, num4, 10, 0, num2, num3 - 8, 0, false);
				mFont.smallFontYellow.drawString(g, hp + string.Empty, num2 + 13, num3 - 7, 2);
			}
		}

		public new void paintName(mGraphics g)
		{
			int num = 72;
			if (type == 2)
			{
				num = 112;
			}
			mFont.tahoma_7_red.drawString(g, name, x, y - num, 2, mFont.tahoma_7_grey);
		}

		public new void paintBiaMo(mGraphics g)
		{
			if (stateDie == 2)
			{
				if (clipDie < 25)
				{
					g.drawRegion(CPlayer.imgBiaMo, 0, 0, 25, clipDie, 0, x - 12, y + 3 - clipDie, 0, false);
				}
				else
				{
					g.drawImage(CPlayer.imgBiaMo, x - 12, y + 3 + dyDie, mGraphics.BOTTOM | mGraphics.LEFT, false);
				}
			}
		}

		public override void paint(mGraphics g)
		{
			try
			{
				if (stateDie != 2 && data != null && isPaint)
				{
					if (!GameScr.res.Equals(string.Empty))
					{
						painthp(g);
						paintName(g);
					}
					else if (!isInvisible)
					{
						painthp(g);
						paintName(g);
					}
					else if (index == GameScr.myIndex || team == PM.getMyPlayer().team)
					{
						painthp(g);
						paintName(g);
					}
					data.paintFrame(g, cf, x, y, (look != 0) ? 1 : 0, 2);
					painthpChange(g);
					paintDust(g);
				}
			}
			catch (Exception)
			{
			}
		}

		private new void painthpChange(mGraphics g)
		{
			if (!hpChangeVisible)
			{
				return;
			}
			g.setColor(16711680);
			int num = hp - hpGoc;
			mFont mFont2 = ((num <= 0) ? mFont.tahoma_7b_red : mFont.tahoma_7b_green);
			if (num != 0)
			{
				int num2 = 110;
				if (type == 2)
				{
					num2 += 45;
				}
				mFont2.drawString(g, ((num <= 0) ? string.Empty : "+") + num, x, y - num2, mGraphics.VCENTER | mGraphics.HCENTER, mFont.tahoma_7b_dark);
			}
			if (hp == nextHP)
			{
				timer1++;
				if (timer1 > 30)
				{
					timer1 = 0;
					hpChangeVisible = false;
					hpText = string.Empty;
					CCanvas.lockNotify = true;
				}
			}
		}
	}
}
