Пример #1
0
		public Travel(Library.Point position, Library.Point destination)
		{
			var interval = new Library.Interval(position, destination);
			double distance = interval.Length;
			int count = (int)Math.Ceiling(distance / INTERVAL) + 1;
			if (count > 1)
				Waypoints = interval.Split(count);
			else
				Waypoints = new Library.Point[] { };
		}
Пример #2
0
        public Travel(Library.Point position, Library.Point destination)
        {
            var    interval = new Library.Interval(position, destination);
            double distance = interval.Length;
            int    count    = (int)Math.Ceiling(distance / INTERVAL) + 1;

            if (count > 1)
            {
                Waypoints = interval.Split(count);
            }
            else
            {
                Waypoints = new Library.Point[] { }
            };
        }
Пример #3
0
		private void MoveStuffThread()
		{
			while (State >= State.Begun)
			{
				lock(World)
					foreach (var obj in World) // Todo test speed World.OfType(Model.Creature)
						if (obj is Model.Creature)
						{
							// Есть вероятность, что позицию можно расчитывать "на лету", по запросу.
							// Можно, если сервер при расчёте следования за движущейся целью переодически присылает пакеты.
							var creature = (Model.Creature)obj;
							if (creature.IsMoving)
							{
								if (creature.MoveTarget != 0 && creature.MoveTarget != creature.ObjectId)
								{
									var target = World[creature.MoveTarget] as Model.Creature;
									if (target != null)
										creature.Destination = target.Position;
								}

								double vx = creature.Destination.X - creature.Position.X;
								double vy = creature.Destination.Y - creature.Position.Y;
								double vz = creature.Destination.Z - creature.Position.Z;

								double movespeed = ((double)creature.RunSpd) * creature.MoveSpdMult;
								double time = ((System.TimeSpan)(System.DateTime.Now - creature.LastMoveTime)).Milliseconds / 1000.0f;
								double distance = new Library.Interval(creature.Position, creature.Destination).Length;
								double vxx = (movespeed * time) / distance;

								if (vxx > 1) //if we are moving past our dest
									vxx = 1; //lets cap it at the dest

								creature.Position = new Library.Point(
									creature.Position.X + (vx * vxx),
									creature.Position.Y + (vy * vxx),
									creature.Position.Z + (vz * vxx)
								);
								creature.LastMoveTime = System.DateTime.Now;

								distance = new Library.Interval(creature.Position, creature.Destination).Length;
								if (creature.MoveTarget == 0 && distance < 5.0)
									creature.IsMoving = false;
							}
						}

				System.Threading.Thread.Sleep(MoveInterval); //moved sleep to the top for when breaking to top
			}
		}