66public class PlayerBot
extends Player {
67 public static final AtomicInteger BOT_COUNT =
new AtomicInteger(0);
70 private Runnable action;
72 public int foodRemaining;
73 public int statBoostersRemaining;
74 public BotClass botClass;
75 public Player opponent;
77 public int consumableDelay;
83 public PlayerBot(String name) {
92 positionChange =
true;
93 settings.acceptAid =
false;
94 settings.autoRetaliate =
true;
100 playerAssistant.setPrayer();
101 movement.setRunningToggled(
true);
102 skills.setCombatLevel();
103 settings.lockExperience =
true;
109 if (!isRegistered() && !
World.getPlayers().contains(
this)) {
110 setRegistered(
World.getPlayers().add(
this));
112 BOT_COUNT.incrementAndGet();
118 if (!isRegistered()) {
122 if (!
World.getPlayers().contains(
this)) {
126 World.cancelTask(
this,
true);
128 BOT_COUNT.decrementAndGet();
139 if (ticks == 0 && action !=
null) {
140 Runnable tmp = action;
142 if (!loop && action == tmp)
146 if (opponent !=
null) {
151 public void schedule(
int ticks, Runnable action) {
153 this.action = action;
157 public void loop(
int ticks, Runnable action) {
159 this.action = action;
163 public void pause(
int ticks) {
167 public void stopLoop() {
171 public void pot(
Mob opponent, ItemClickEvent event, PotionData potion) {
172 if (!potion.canDrink(
this)) {
176 animate(
new Animation(829, UpdatePriority.LOW));
179 Item replace = PotionData.getReplacementItem(event.getItem());
181 if (replace.getId() == 229) {
182 inventory.remove(event.getItem());
184 inventory.replace(event.getItem().getId(), replace.getId(), event.getSlot(),
true);
187 potion.onEffect(
this);
191 public void postDeath() {
192 move(Config.DEFAULT_POSITION);
195 playerAssistant.reset();
196 setSpecialActivated(
false);
198 CombatSpecial.restore(
this, 100);
200 teleblockTimer.set(0);
201 schedule(2, () -> BotObjective.WALK_TO_BANK.init(
this));
204 public void retaliate(Player defender) {
210 if (defender.getCombat().isUnderAttack() && !defender.getCombat().isUnderAttackBy(
this)) {
215 if (opponent !=
null && opponent.equals(defender)) {
219 if (opponent !=
null && !opponent.equals(defender)) {
224 BotObjective.COMBAT.init(
this);
227 private void loopCombat() {
228 if (opponent.isDead()) {
229 schedule(4, this::endFight);
233 if (foodRemaining == 0 || skills.getLevel(Skill.PRAYER) == 0) {
238 if (isDead() || getCurrentHealth() <= 0) {
239 speak(Utility.randomElement(BotUtility.DEATH_MESSAGES));
240 schedule(7, () -> BotObjective.WALK_TO_BANK.init(
this));
247 || (opponent.getCombat().isUnderAttack() && !opponent.getCombat().isUnderAttackBy(
this))) {
254 if (consumableDelay > 0) {
258 if (consumableDelay == 0) {
259 botClass.pot(opponent,
this);
260 botClass.eat(opponent,
this);
263 botClass.handleCombat(opponent,
this);
266 public void endFight() {
270 botClass.endFight(
this);
272 damageImmunity.reset(3_000);
273 if (!isDead() && getCurrentHealth() > 0) {
274 Teleportation.teleport(
this, Config.DEFAULT_POSITION, 20, TeleportationData.MODERN, () -> BotObjective.WALK_TO_BANK.init(
this));
static final Appearance APPEARANCE