<commit_before>package be.yurimoens.runemate.cabysscrafter.task.walking;

import be.yurimoens.runemate.cabysscrafter.Constants;
import com.runemate.game.api.hybrid.entities.Actor;
import com.runemate.game.api.hybrid.entities.Npc;
import com.runemate.game.api.hybrid.entities.Player;
import com.runemate.game.api.hybrid.location.Coordinate;
import com.runemate.game.api.hybrid.location.navigation.basic.PredefinedPath;
import com.runemate.game.api.hybrid.region.Npcs;
import com.runemate.game.api.hybrid.region.Players;
import com.runemate.game.api.rs3.local.hud.interfaces.eoc.ActionBar;
import com.runemate.game.api.rs3.local.hud.interfaces.eoc.SlotAction;
import com.runemate.game.api.script.Execution;
import com.runemate.game.api.script.framework.task.Task;

class WalkToMage extends Task {

    private final SlotAction surge;

    public WalkToMage() {
        surge = ActionBar.getFirstAction("Surge");
    }

    @Override
    public boolean validate() {
        Player player = Players.getLocal();

        return (getParent().validate()
                && !((WalkToAbyss) getParent()).underAttack
                && (player.getPosition().getY() >= Constants.wildernessWall.getY() || player.getAnimationId() == 18224)
                && !Constants.mageArea.contains(player));
    }

    @Override
    public void execute() {
        Player player = Players.getLocal();

        if (surge != null && !surge.isCoolingDown()) {
            surge.activate(false);
            Execution.delayUntil(surge::isCoolingDown, 1000);
        }

        PredefinedPath path = PredefinedPath.create(
                new Coordinate(3103, 3545, 0).randomize(2, 2),
                new Coordinate(3102, 3558, 0).randomize(2, 2)
        );

        Execution.delayUntil(() -> {
            if (!player.isMoving() || player.distanceTo(path.getNext()) < 17.5D) {
                path.step(true);
                Execution.delayUntil(player::isMoving, 1500, 2500);
            }

            for (Player otherPlayers : Players.getLoaded()) {
                Actor target;
                if ((target = otherPlayers.getTarget()) != null && target.getName() != null && target.getName().equals(player.getName())) {
                    ((WalkToAbyss) getParent()).underAttack = true;
                    return false;
                }
            }

            Npc zamorakMage = Npcs.newQuery().models(Constants.MAGE_MODEL).results().first();

            return Constants.mageArea.contains(player)
                    || (zamorakMage != null && zamorakMage.isVisible());
        }, 10000, 13000);
    }
}<commit_msg>Optimize usage of surge.<commit_after>package be.yurimoens.runemate.cabysscrafter.task.walking;

import be.yurimoens.runemate.cabysscrafter.Constants;
import com.runemate.game.api.hybrid.entities.Actor;
import com.runemate.game.api.hybrid.entities.Npc;
import com.runemate.game.api.hybrid.entities.Player;
import com.runemate.game.api.hybrid.entities.details.Interactable;
import com.runemate.game.api.hybrid.input.Mouse;
import com.runemate.game.api.hybrid.location.Coordinate;
import com.runemate.game.api.hybrid.location.navigation.basic.PredefinedPath;
import com.runemate.game.api.hybrid.region.Npcs;
import com.runemate.game.api.hybrid.region.Players;
import com.runemate.game.api.rs3.local.hud.interfaces.eoc.ActionBar;
import com.runemate.game.api.rs3.local.hud.interfaces.eoc.SlotAction;
import com.runemate.game.api.script.Execution;
import com.runemate.game.api.script.framework.task.Task;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

class WalkToMage extends Task {

    private final SlotAction surge;

    public WalkToMage() {
        surge = ActionBar.getFirstAction("Surge");
    }

    @Override
    public boolean validate() {
        Player player = Players.getLocal();

        return (getParent().validate()
                && !((WalkToAbyss) getParent()).underAttack
                && (player.getPosition().getY() >= Constants.wildernessWall.getY() || player.getAnimationId() == 18224)
                && !Constants.mageArea.contains(player));
    }

    @Override
    public void execute() {
        Player player = Players.getLocal();

        if (surge != null && !surge.isCoolingDown()) {
            surge.activate(false);
            Execution.delayUntil(surge::isCoolingDown, 1000);
        }

        surge();

        PredefinedPath path = PredefinedPath.create(
                new Coordinate(3103, 3545, 0).randomize(2, 2),
                new Coordinate(3102, 3558, 0).randomize(2, 2)
        );

        Execution.delayUntil(() -> {
            if (!player.isMoving() || player.distanceTo(path.getNext()) < 17.5D) {
                path.step(true);
                Execution.delayUntil(player::isMoving, 1500, 2500);
            }

            for (Player otherPlayers : Players.getLoaded()) {
                Actor target;
                if ((target = otherPlayers.getTarget()) != null && target.getName() != null && target.getName().equals(player.getName())) {
                    ((WalkToAbyss) getParent()).underAttack = true;
                    return false;
                }
            }

            Npc zamorakMage = Npcs.newQuery().models(Constants.MAGE_MODEL).results().first();

            return Constants.mageArea.contains(player)
                    || (zamorakMage != null && zamorakMage.isVisible());
        }, 10000, 13000);
    }

    private Future<Boolean> surge() {
        if (surge == null || surge.isCoolingDown()) {
            return new FutureTask<>(() -> false);
        }

        FutureTask task = new FutureTask(() -> surge.activate(false));

        ExecutorService executorService = Executors.newSingleThreadExecutor();

        executorService.submit(task);

        return task;
    }
}
{'fraction_non_alphanumeric': 0.13222297756628143, 'fraction_numerical': 0.018354860639021073, 'mean_word_length': 2.619311193111931, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1217902', 'n_tokens_mistral': 1918, 'n_tokens_neox': 1750, 'n_words': 274}