001/*
002 * This file is part of Baritone.
003 *
004 * Baritone is free software: you can redistribute it and/or modify
005 * it under the terms of the GNU Lesser General Public License as published by
006 * the Free Software Foundation, either version 3 of the License, or
007 * (at your option) any later version.
008 *
009 * Baritone is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012 * GNU Lesser General Public License for more details.
013 *
014 * You should have received a copy of the GNU Lesser General Public License
015 * along with Baritone.  If not, see <https://www.gnu.org/licenses/>.
016 */
017
018package baritone.api.behavior;
019
020import baritone.api.pathing.calc.IPath;
021import baritone.api.pathing.calc.IPathFinder;
022import baritone.api.pathing.goals.Goal;
023import baritone.api.pathing.path.IPathExecutor;
024
025import java.util.Optional;
026
027/**
028 * @author Brady
029 * @since 9/23/2018
030 */
031public interface IPathingBehavior extends IBehavior {
032
033    /**
034     * Returns the estimated remaining ticks in the current pathing
035     * segment. Given that the return type is an optional, {@link Optional#empty()}
036     * will be returned in the case that there is no current segment being pathed.
037     *
038     * @return The estimated remaining ticks in the current segment.
039     */
040    default Optional<Double> ticksRemainingInSegment() {
041        return ticksRemainingInSegment(true);
042    }
043
044    /**
045     * Returns the estimated remaining ticks in the current pathing
046     * segment. Given that the return type is an optional, {@link Optional#empty()}
047     * will be returned in the case that there is no current segment being pathed.
048     *
049     * @param includeCurrentMovement whether or not to include the entirety of the cost of the currently executing movement in the total
050     * @return The estimated remaining ticks in the current segment.
051     */
052    default Optional<Double> ticksRemainingInSegment(boolean includeCurrentMovement) {
053        IPathExecutor current = getCurrent();
054        if (current == null) {
055            return Optional.empty();
056        }
057        int start = includeCurrentMovement ? current.getPosition() : current.getPosition() + 1;
058        return Optional.of(current.getPath().ticksRemainingFrom(start));
059    }
060
061    /**
062     * Returns the estimated remaining ticks to the current goal.
063     * Given that the return type is an optional, {@link Optional#empty()}
064     * will be returned in the case that there is no current goal.
065     *
066     * @return The estimated remaining ticks to the current goal.
067     */
068    Optional<Double> estimatedTicksToGoal();
069
070    /**
071     * @return The current pathing goal
072     */
073    Goal getGoal();
074
075    /**
076     * @return Whether or not a path is currently being executed. This will be false if there's currently a pause.
077     * @see #hasPath()
078     */
079    boolean isPathing();
080
081    /**
082     * @return If there is a current path. Note that the path is not necessarily being executed, for example when there
083     * is a pause in effect.
084     * @see #isPathing()
085     */
086    default boolean hasPath() {
087        return getCurrent() != null;
088    }
089
090    /**
091     * Cancels the pathing behavior or the current path calculation, and all processes that could be controlling path.
092     * <p>
093     * Basically, "MAKE IT STOP".
094     *
095     * @return Whether or not the pathing behavior was canceled. All processes are guaranteed to be canceled, but the
096     * PathingBehavior might be in the middle of an uncancelable action like a parkour jump
097     */
098    boolean cancelEverything();
099
100    /**
101     * PLEASE never call this
102     * <p>
103     * If cancelEverything was like "kill" this is "sudo kill -9". Or shutting off your computer.
104     */
105    void forceCancel();
106
107    /**
108     * Returns the current path, from the current path executor, if there is one.
109     *
110     * @return The current path
111     */
112    default Optional<IPath> getPath() {
113        return Optional.ofNullable(getCurrent()).map(IPathExecutor::getPath);
114    }
115
116    /**
117     * @return The current path finder being executed
118     */
119    Optional<? extends IPathFinder> getInProgress();
120
121    /**
122     * @return The current path executor
123     */
124    IPathExecutor getCurrent();
125
126    /**
127     * Returns the next path executor, created when planning ahead.
128     *
129     * @return The next path executor
130     */
131    IPathExecutor getNext();
132}