RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
PlayerBot.java
1package com.osroyale.content.bot;
2
3import com.osroyale.Config;
4import com.osroyale.content.bot.botclass.BotClass;
5import com.osroyale.content.bot.objective.BotObjective;
6import com.osroyale.content.consume.PotionData;
7import com.osroyale.content.skill.impl.magic.Spellbook;
8import com.osroyale.content.skill.impl.magic.teleport.Teleportation;
9import com.osroyale.content.skill.impl.magic.teleport.TeleportationData;
10import com.osroyale.content.teleport.TeleportTablet;
11import com.osroyale.game.Animation;
12import com.osroyale.game.UpdatePriority;
13import com.osroyale.game.event.impl.ItemClickEvent;
14import com.osroyale.game.world.World;
15import com.osroyale.game.world.entity.combat.strategy.player.special.CombatSpecial;
16import com.osroyale.game.world.entity.mob.Mob;
17import com.osroyale.game.world.entity.mob.player.Player;
18import com.osroyale.game.world.entity.skill.Skill;
19import com.osroyale.game.world.items.Item;
20import com.osroyale.util.Utility;
21
22import java.util.concurrent.atomic.AtomicInteger;
23
65
66public class PlayerBot extends Player {
67 public static final AtomicInteger BOT_COUNT = new AtomicInteger(0);
68
69 private int ticks;
70 private Runnable action;
71 private boolean loop;
72 public int foodRemaining;
73 public int statBoostersRemaining;
74 public BotClass botClass;
75 public Player opponent;
76
77 public int consumableDelay;
78
79 public PlayerBot() {
80 this(BotUtility.nameGenerator());
81 }
82
83 public PlayerBot(String name) {
84 super(name);
85 setVisible(true);
86 isBot = true;
87 headIcon = -1;
88 clanTag = "";
89 clanTagColor = "";
90 newPlayer = false;
91 regionChange = true;
92 positionChange = true;
93 settings.acceptAid = false;
94 settings.autoRetaliate = true;
95 playerTitle = BotUtility.TITLE;
96 appearance = BotUtility.APPEARANCE;
97 spellbook = Spellbook.LUNAR;
98 prayer.reset();
99 mobAnimation.reset();
100 playerAssistant.setPrayer();
101 movement.setRunningToggled(true);
102 skills.setCombatLevel();
103 settings.lockExperience = true;
104 CombatSpecial.restore(this, 100);
105 }
106
107 @Override
108 public void register() {
109 if (!isRegistered() && !World.getPlayers().contains(this)) {
110 setRegistered(World.getPlayers().add(this));
111 setPosition(getPosition());
112 BOT_COUNT.incrementAndGet();
113 }
114 }
115
116 @Override
117 public void unregister() {
118 if (!isRegistered()) {
119 return;
120 }
121
122 if (!World.getPlayers().contains(this)) {
123 return;
124 }
125
126 World.cancelTask(this, true);
127 World.getPlayers().remove((Player) destroy());
128 BOT_COUNT.decrementAndGet();
129 }
130
131 @Override
132 public void sequence() {
133 super.sequence();
134
135 if (ticks > 0) {
136 ticks--;
137 }
138
139 if (ticks == 0 && action != null) {
140 Runnable tmp = action;
141 action.run();
142 if (!loop && action == tmp)
143 action = null;
144 }
145
146 if (opponent != null) {
147 loopCombat();
148 }
149 }
150
151 public void schedule(int ticks, Runnable action) {
152 this.ticks = ticks;
153 this.action = action;
154 loop = false;
155 }
156
157 public void loop(int ticks, Runnable action) {
158 this.ticks = ticks;
159 this.action = action;
160 loop = true;
161 }
162
163 public void pause(int ticks) {
164 this.ticks += ticks;
165 }
166
167 public void stopLoop() {
168 loop = false;
169 }
170
171 public void pot(Mob opponent, ItemClickEvent event, PotionData potion) {
172 if (!potion.canDrink(this)) {
173 return;
174 }
175
176 animate(new Animation(829, UpdatePriority.LOW));
177 potionDelay.reset();
178
179 Item replace = PotionData.getReplacementItem(event.getItem());
180
181 if (replace.getId() == 229) {
182 inventory.remove(event.getItem());
183 } else {
184 inventory.replace(event.getItem().getId(), replace.getId(), event.getSlot(), true);
185 }
186
187 potion.onEffect(this);
188 getCombat().attack(opponent);
189 }
190
191 public void postDeath() {
192 move(Config.DEFAULT_POSITION);
193 skills.restoreAll();
194 equipment.login();
195 playerAssistant.reset();
196 setSpecialActivated(false);
197 getCombat().getDamageCache().clear();
198 CombatSpecial.restore(this, 100);
199 movement.reset();
200 teleblockTimer.set(0);
201 schedule(2, () -> BotObjective.WALK_TO_BANK.init(this));
202 }
203
204 public void retaliate(Player defender) {
205 if (getCombat().isAttacking() && !getCombat().isAttacking(defender)) {
206 endFight();
207 return;
208 }
209
210 if (defender.getCombat().isUnderAttack() && !defender.getCombat().isUnderAttackBy(this)) {
211 endFight();
212 return;
213 }
214
215 if (opponent != null && opponent.equals(defender)) {
216 return;
217 }
218
219 if (opponent != null && !opponent.equals(defender)) {
220 endFight();
221 return;
222 }
223
224 BotObjective.COMBAT.init(this);
225 }
226
227 private void loopCombat() {
228 if (opponent.isDead()) {
229 schedule(4, this::endFight);
230 return;
231 }
232
233 if (foodRemaining == 0 || skills.getLevel(Skill.PRAYER) == 0) {
234 endFight();
235 return;
236 }
237
238 if (isDead() || getCurrentHealth() <= 0) {
239 speak(Utility.randomElement(BotUtility.DEATH_MESSAGES));
240 schedule(7, () -> BotObjective.WALK_TO_BANK.init(this));
241 opponent = null;
242 getCombat().reset();
243 return;
244 }
245
246 if (!getCombat().inCombat()
247 || (opponent.getCombat().isUnderAttack() && !opponent.getCombat().isUnderAttackBy(this))) {
248 endFight();
249 return;
250 }
251
252 getCombat().attack(opponent);
253
254 if (consumableDelay > 0) {
255 consumableDelay--;
256 }
257
258 if (consumableDelay == 0) {
259 botClass.pot(opponent, this);
260 botClass.eat(opponent, this);
261 }
262
263 botClass.handleCombat(opponent, this);
264 }
265
266 public void endFight() {
267 unpoison();
268 unvenom();
269 opponent = null;
270 botClass.endFight(this);
271 getCombat().reset();
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));
275 }
276 }
277}
static final Appearance APPEARANCE
void move(Position position)
Definition Mob.java:377
void speak(String forceChat)
Definition Mob.java:164