Exemplo n.º 1
0
		public override void AI()
		{
			NPC npc = Main.npc[octopus];
			if (!npc.active || npc.type != mod.NPCType("Octopus"))
			{
				return;
			}
			projectile.timeLeft = 2;
			Player player = Main.player[npc.target];
			projectile.position = npc.Center;
			Vector2 offset = player.Center - projectile.position;
			float distance = offset.Length() + 32f;
			Angle currAngle = new Angle(projectile.rotation);
			Angle angleToPlayer = new Angle((float)Math.Atan2(offset.Y, offset.X));
			Angle min = new Angle(minAngle);
			Angle max = new Angle(maxAngle);
			Angle limit = new Angle((minAngle + maxAngle) / 2f);
			if (limit.Between(min, max))
			{
				limit = limit.Opposite();
			}
			Angle buffer = new Angle(angleBuffer);
			if (angleToPlayer.Between(min - buffer, max + buffer))
			{
				if (currAngle.Between(max, limit))
				{
					angleSpeed -= maxAngleSpeed / 10f;
				}
				else if (currAngle.Between(limit, min))
				{
					angleSpeed += maxAngleSpeed / 10f;
				}
				else if (currAngle.ClockwiseFrom(angleToPlayer))
				{
					angleSpeed += maxAngleSpeed / 10f;
				}
				else
				{
					angleSpeed -= maxAngleSpeed / 10f;
				}
				if (length > maxLength)
				{
					lengthSpeed -= maxLengthSpeed / 10f;
				}
				else if (length < minLength)
				{
					lengthSpeed += maxLengthSpeed / 10f;
				}
				else if (distance > length)
				{
					lengthSpeed += maxLengthSpeed / 10f;
				}
				else if (distance < length)
				{
					lengthSpeed -= maxLengthSpeed / 10f;
				}
			}
			else
			{
				if (currAngle.Between(max, limit))
				{
					angleSpeed -= maxAngleSpeed / 10f;
				}
				else if (currAngle.Between(limit, min))
				{
					angleSpeed += maxAngleSpeed / 10f;
				}
				else if (angleSpeed > 0f)
				{
					angleSpeed += maxAngleSpeed / 20f;
				}
				else if (angleSpeed < 0f)
				{
					angleSpeed -= maxAngleSpeed / 20f;
				}
				else
				{
					angleSpeed = maxAngleSpeed / 20f;
				}
				if (length > minLength)
				{
					lengthSpeed -= maxLengthSpeed / 10f;
				}
				else
				{
					lengthSpeed += maxLengthSpeed / 10f;
				}
			}
			if (angleSpeed > maxAngleSpeed)
			{
				angleSpeed = maxAngleSpeed;
			}
			else if (angleSpeed < -maxAngleSpeed)
			{
				angleSpeed = -maxAngleSpeed;
			}
			if (lengthSpeed > maxLengthSpeed)
			{
				lengthSpeed = maxLengthSpeed;
			}
			else if (lengthSpeed < -maxLengthSpeed)
			{
				lengthSpeed = -maxLengthSpeed;
			}
			projectile.rotation += angleSpeed;
			length += lengthSpeed;
			if (Main.netMode == 2)
			{
				netUpdateCounter++;
				if (netUpdateCounter >= 300)
				{
					projectile.netUpdate = true;
					netUpdateCounter = 0;
				}
			}
		}