Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        public void MoveEntity(AbstractEntity entity)
        {
            if (entity.MovementInterval == 0)
            {
                entity.MovementInterval = Util.Next(10000, 25000);
            }

            if (entity.NextMovementTime == 0)
            {
                entity.NextMovementTime = UpdateTime + entity.MovementInterval;
            }

            if (entity.NextMovementTime > UpdateTime)
            {
                return;
            }

            entity.NextMovementTime = UpdateTime + entity.MovementInterval;

            // Move only if there is a player on the map, else it is useless
            if (m_playerCount == 0)
            {
                return;
            }

            var cellId = entity.LastCellId;

            if (cellId < 1)
            {
                cellId = GetNearestMovementCell(entity.CellId);
            }

            if (entity.LastCellId == 0)
            {
                entity.LastCellId = entity.CellId;
            }
            else
            {
                entity.LastCellId = 0;
            }

            if (cellId < 1)
            {
                return;
            }

            Move(entity, entity.CellId, Pathmaker.FindPathAsString(entity.CellId, cellId, false));

            entity.StopAction(GameActionTypeEnum.MAP_MOVEMENT);
        }