예제 #1
0
 public void Update(TimeSpan time)
 {
     if ((_update -= time.Milliseconds) <= 0)
     {
         _update = _interval;
         var msg = _creature.View.CreateStream(_entry.AllocSize);
         _entry.OnSerialize(msg); _creature.View.SendStream(msg);
     }
 }
예제 #2
0
 public void Update(TimeSpan time)
 {
     if (!_locked)
     {
         _speed = _creature.Stats.Speed;
         if (!(_scriptedAI.Target?.IsDead ?? true))
         {
             _direction = Vector3.Normalize(_scriptedAI.Target.Position - _position);
             _rotation  = MathHelper.GetRotation(Vector3.UnitZ, _direction, Vector3.UnitY);
             var distanceSquared = Vector3.DistanceSquared(_position, _scriptedAI.Target.Position);
             if (distanceSquared > (Constants.MaxMeleeCombatDistanceSquared + Constants.EpsilonX1))
             {
                 var offset = (_direction * ((time.Milliseconds / 1000f) * _speed / 45f));
                 if (distanceSquared > Constants.MaxMeleeCombatDistanceSquared + offset.LengthSquared() + Constants.EpsilonX1)
                 {
                     _position += offset;
                 }
                 else
                 {
                     _position = _scriptedAI.Target.Position - (_direction * Constants.MaxMeleeCombatDistance);
                 }
             }
         }
         else
         {
             var distanceSquared = Vector3.DistanceSquared(_position, _creature.SpawnPosition);
             if (distanceSquared > 0)
             {
                 _direction = Vector3.Normalize(_creature.SpawnPosition - _position);
                 _rotation  = MathHelper.GetRotation(Vector3.UnitZ, _direction, Vector3.UnitY);
                 var offset = (_direction * ((time.Milliseconds / 1000f) * _speed / 45f));
                 if (distanceSquared > offset.LengthSquared())
                 {
                     _position += offset;
                 }
                 else
                 {
                     _position = _creature.SpawnPosition;
                 }
             }
         }
     }
     if ((_update -= time.Milliseconds) <= 0)
     {
         _update         = _interval;
         _entry.Position = _position;
         _entry.Rotation = _rotation;
         _entry.Time     = PNet.Utilities.Now;
         var msg = _creature.View.CreateStream(_entry.AllocSize);
         _entry.OnSerialize(msg); _creature.View.SendStream(msg);
     }
 }
예제 #3
0
 public void Update(TimeSpan time)
 {
     if (_locked <= 0 && _current != null)
     {
         if (_position != _current.Position)
         {
             var offset = (_direction * ((time.Milliseconds / 1000f) * _speed / 45f));
             if (Vector3.DistanceSquared(_position, _current.Position) > (offset.LengthSquared() + Constants.EpsilonX1))
             {
                 _position += offset;
             }
             else
             {
                 if (!_waiting)
                 {
                     Execute();
                     offset     = (_direction * ((time.Milliseconds / 1000f) * _speed / 45f));
                     _position += offset;
                 }
                 else
                 {
                     _position = _current.Position;
                 }
             }
         }
         else if (_waiting)
         {
             _rotation = _current.Rotation.ToRadians();
             if (_wait == null && _current.Data01 > 0)
             {
                 _wait = new MovementWait(this, (_current.Data01 < _current.Data02 ?
                                                 TimeSpan.FromSeconds(Constants.RND.Next(_current.Data01, _current.Data02)) :
                                                 TimeSpan.FromSeconds(_current.Data01)));
             }
         }
         else
         {
             Execute();
         }
     }
     if ((_update -= time.Milliseconds) <= 0)
     {
         _update         = _interval;
         _entry.Position = _position;
         _entry.Rotation = _rotation;
         _entry.Time     = PNet.Utilities.Now;
         var msg = _creature.View.CreateStream(_entry.AllocSize);
         _entry.OnSerialize(msg); _creature.View.SendStream(msg);
     }
 }