Exemplo n.º 1
0
 private void UpdateMovement()
 {
     if (TNPC.aiStyle == 11)
     {
         return;
     }
     if (!withinFollowing)
     {
         if (TNPC.Distance(TargetPlayer.Center) <= followingDistance)
         {
             withinFollowing = true;
             fakeTarget      = (2 * TargetPlayer.Center + Center) / 3;                // center____ __target
         }
         else
         {
             float   s     = TNPC.Distance(TargetPlayer.Center) / 16;
             Vector2 vMax  = (TargetPlayer.Center - Center).ToLenOf(s * s / 100);
             Vector2 accel = (vMax - FakeVelocity) / 120;
             FakeVelocity += (Vector)accel;
         }
     }
     else
     {
         if (TNPC.Distance(TargetPlayer.Center) > followingDistance)
         {
             withinFollowing = false;
         }
     }
     if (withinFollowing)
     {
         if (posLockto != null)
         {
             relativePos  = (Vector)posLockto;
             FakeVelocity = (Vector)(relativePos + TargetPlayer.Center - Center) / 4;
         }
         else
         {
             double t = trackPara * Math.PI / 180;
             double ρ = (2 + Math.Abs(3 * Math.Sin(2 * t)) + Math.Abs(2 * Math.Cos(3 * t))) * 16 * 12;
             relativePos = new Vector2
             {
                 X = (float)(ρ * Math.Cos(t + Math.PI / 2)),
                 Y = (float)(ρ * Math.Sin(t + Math.PI / 2))
             };
             FakeVelocity = (Vector)((relativePos + fakeTarget) - Center) / 4;
             if (FakeVelocity.Length > 20)
             {
                 FakeVelocity.Length = 20;
             }
             if (Vector2.Distance(fakeTarget, TargetPlayer.Center) > 10)
             {
                 fakeTarget += (TargetPlayer.Center - fakeTarget).ToLenOf(9);
             }
             trackPara++;
         }
     }
     Velocity = FakeVelocity;
     UpdateToClient();
 }