RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
PlayerAssistant.java
1package com.osroyale.game.world.entity.mob.player;
2
3import com.osroyale.Config;
4import com.osroyale.content.StarterKit;
5import com.osroyale.content.ValueIcon;
6import com.osroyale.content.achievement.AchievementWriter;
7import com.osroyale.content.activity.Activity;
8import com.osroyale.content.activity.ActivityType;
9import com.osroyale.content.activity.GroupActivity;
10import com.osroyale.content.activity.impl.CerberusActivity;
11import com.osroyale.content.activity.impl.JailActivity;
12import com.osroyale.content.activity.impl.VorkathActivity;
13import com.osroyale.content.activity.impl.barrows.Barrows;
14import com.osroyale.content.activity.impl.godwars.GodwarsActivity;
15import com.osroyale.content.activity.impl.kraken.KrakenActivity;
16import com.osroyale.content.activity.impl.warriorguild.WarriorGuild;
17import com.osroyale.content.clanchannel.channel.ClanChannelHandler;
18import com.osroyale.content.collectionlog.CollectionLogSaving;
19import com.osroyale.content.emote.EmoteHandler;
20import com.osroyale.content.pet.Pets;
21import com.osroyale.content.skill.impl.farming.Farming;
22import com.osroyale.content.skill.impl.magic.teleport.TeleportType;
23import com.osroyale.content.skillcape.SkillCape;
24import com.osroyale.content.writer.InterfaceWriter;
25import com.osroyale.content.writer.impl.InformationWriter;
26import com.osroyale.game.task.impl.SuperAntipoisonTask;
27import com.osroyale.game.task.impl.TeleblockTask;
28import com.osroyale.game.world.World;
29import com.osroyale.game.world.entity.combat.CombatConstants;
30import com.osroyale.game.world.entity.combat.CombatTarget;
31import com.osroyale.game.world.entity.combat.CombatType;
32import com.osroyale.game.world.entity.combat.CombatUtil;
33import com.osroyale.game.world.entity.combat.attack.FormulaFactory;
34import com.osroyale.game.world.entity.combat.attack.listener.other.PrayerListener;
35import com.osroyale.game.world.entity.combat.attack.listener.other.VengeanceListener;
36import com.osroyale.game.world.entity.combat.effect.CombatEffectType;
37import com.osroyale.game.world.entity.combat.strategy.CombatStrategy;
38import com.osroyale.game.world.entity.combat.strategy.player.PlayerMagicStrategy;
39import com.osroyale.game.world.entity.combat.strategy.player.PlayerMeleeStrategy;
40import com.osroyale.game.world.entity.combat.strategy.player.PlayerRangedStrategy;
41import com.osroyale.game.world.entity.combat.strategy.player.custom.*;
42import com.osroyale.game.world.entity.combat.strategy.player.special.CombatSpecial;
43import com.osroyale.game.world.entity.combat.weapon.WeaponInterface;
44import com.osroyale.game.world.entity.mob.Mob;
45import com.osroyale.game.world.entity.mob.UpdateFlag;
46import com.osroyale.game.world.entity.mob.npc.definition.NpcDefinition;
47import com.osroyale.game.world.entity.mob.prayer.Prayer;
48import com.osroyale.game.world.entity.skill.Skill;
49import com.osroyale.game.world.items.Item;
50import com.osroyale.game.world.items.containers.ItemContainer;
51import com.osroyale.game.world.items.containers.equipment.Equipment;
52import com.osroyale.game.world.items.containers.pricechecker.PriceType;
53import com.osroyale.game.world.position.Area;
54import com.osroyale.game.world.position.Position;
55import com.osroyale.net.packet.out.*;
56import com.osroyale.net.packet.out.SendWidget.WidgetType;
57import com.osroyale.util.TinterfaceText;
58import com.osroyale.util.Utility;
59
60import java.util.Arrays;
61import java.util.HashMap;
62import java.util.Map;
63import java.util.function.Consumer;
64
106
107public class PlayerAssistant {
108
110 private final Player player;
111
113 private Map<Integer, TinterfaceText> interfaceText = new HashMap<>();
114
116 PlayerAssistant(Player player) {
117 this.player = player;
118 }
119
121 public final void login() {
122 reset();
123 setAttribute();
124 setPrayer();
125 initialize();
126 setSidebar(false, true);
127 setActivity();
128 setContextMenu();
129 setEffects();
130 Pets.onLogin(player);
131 EmoteHandler.refresh(player);
133 player.setCollectionLog(CollectionLogSaving.load(player));
134 player.runePouch.refresh();
135 }
136
138 private void setEffects() {
139 if (player.getPoisonImmunity().get() > 0) {
140 World.schedule(new SuperAntipoisonTask(player).attach(player));
141 }
142 if (player.skulling.getSkullRemoveTask().getSkullTime() > 0) {
143 player.skulling.skull();
144 }
145
146 if (player.teleblockTimer.get() > 0) {
147 player.send(new SendWidget(SendWidget.WidgetType.TELEBLOCK, (int) ((double) player.teleblockTimer.get() / 1000D * 600D)));
148 World.schedule(new TeleblockTask(player));
149 }
150
151 }
152
154 private void initialize() {
155 player.getCombat().resetTimers(-CombatConstants.COMBAT_LOGOUT_COOLDOWN);
156 player.send(new SendEntityFeed());
157 player.send(new SendSpecialAmount());
158 InterfaceWriter.write(new InformationWriter(player));
159 InterfaceWriter.write(new AchievementWriter(player));
160 }
161
163 public void sequence() {
164 skillRestore();
165 updateSpecial();
166 prayerDrain();
167 run();
168 runRestore();
169 player.getCombat().tick();
170 Activity.forActivity(player, it -> {
171 if (!(it instanceof GroupActivity))
172 it.sequence();
173 });
174
175 CombatTarget.checkAggression(player);
176
177 if (player.sequence % 20 == 0) {
178 Farming.tick(player);
179 }
180 }
181
183 public CombatStrategy<Player> getStrategy() {
184 if (player.isSingleCast())
185 return new PlayerMagicStrategy(player.getSingleCastSpell());
186 if (player.isAutocast())
187 return new PlayerMagicStrategy(player.getAutocastSpell());
188 if (player.isSpecialActivated()) {
189 if (player.getCombatSpecial() == null) {
190 player.setSpecialActivated(false);
191 player.send(new SendSpecialEnabled(0));
192 } else {
193 return player.getCombatSpecial().getStrategy();
194 }
195 }
196 Item item = player.equipment.get(Equipment.WEAPON_SLOT);
197 if (item != null) {
198 if(item.getId() == 22325) {
199 return ScytheOfViturStrategy.get();
200 }
201 if (item.getId() == 11907) {
202 return TridentOfTheSeasStrategy.get();
203 }
204 if (item.getId() == 27275) {
205 return TumekenStrategy.get();
206 }
207
208 if (item.getId() == 12899) {
209 return TridentOfTheSwampStrategy.get();
210 }
211
212 if (item.getId() == 12926) {
213 return ToxicBlowpipeStrategy.get();
214 }
215
216 if (item.getRangedDefinition().isPresent()) {
217 return PlayerRangedStrategy.get();
218 }
219 }
220 return PlayerMeleeStrategy.get();
221 }
222
224 private void updateSpecial() {
225 if (player.getSpecialPercentage().get() < 100 && player.sequence % 60 == 0)
226 CombatSpecial.restore(player, 10);
227 }
228
230 public final void setSidebar(boolean disabled) {
231 setSidebar(disabled, false);
232 }
233
234 public final void setSidebar(boolean disabled, boolean login) {
235 for (int index = 0; index < Config.SIDEBAR_INTERFACE.length; index++) {
236 player.interfaceManager.setSidebar(Config.SIDEBAR_INTERFACE[index][0], disabled ? -1 : Config.SIDEBAR_INTERFACE[index][1]);
237 }
238 player.interfaceManager.setSidebar(Config.MAGIC_TAB, disabled ? -1 : player.spellbook.getInterfaceId());
239 if (!disabled) {
240 WeaponInterface.execute(player, player.equipment.getWeapon(), login);
241 player.send(new SendConfig(980, 0));
242 }
243 }
244
246 private void setAttribute() {
247 player.attributes.set("OBELISK", -1);
248 player.attributes.set("BANK_KEY", false);
249 player.attributes.set("TRADE_KEY", false);
250 player.attributes.set("DUEL_KEY", false);
251 player.attributes.set("RUN_FLAG_KEY", 10);
252 player.attributes.set("PLAYER_TITLE_KEY", 0);
253 player.attributes.set("FORCE_MOVEMENT", false);
254 player.attributes.set("PRELOADING_SLOT_KEY", 0);
255 player.attributes.set("PERSONAL_STORE_KEY", null);
256 player.attributes.set("PRICE_CHECKER_KEY", false);
257 player.attributes.set("DONATOR_DEPOSIT_KEY", false);
258 player.attributes.set("TELEPORT_TYPE_KEY", TeleportType.FAVORITES);
259 }
260
262 private void setActivity() {
263
264 if (player.punishment.isJailed()) {
265 JailActivity.create(player);
266 } else if (player.needsStarter) {
267 StarterKit.open(player);
268 } else if (Area.inGodwars(player)) {
269 GodwarsActivity.create(player);
270 } else if (Area.inWarriorGuild(player)) {
271 WarriorGuild.create(player);
272 } else if (Area.inBarrows(player)) {
273 Barrows.create(player);
274 } else if (Area.inVorkath(player)) {
275 VorkathActivity.create(player);
276 } else if (Area.inKraken(player)) {
277 KrakenActivity.create(player);
278 } else if (Area.inCerberus(player)) {
279 CerberusActivity.create(player);
280 } else if (Area.inWilderness(player)) {
281 player.valueIcon = getValueIcon(player).getCode();
282 player.updateFlags.add(UpdateFlag.APPEARANCE);
283 }
284 }
285
287 private void setContextMenu() {
288 if (Area.inDuelArenaLobby(player)) {
289 player.send(new SendPlayerOption(PlayerOption.DUEL_REQUEST, false));
290 player.send(new SendPlayerOption(PlayerOption.ATTACK, false, true));
291 /* } else if (Area.inWilderness(player) || Area.inEventArena(player)) {
292 player.send(new SendPlayerOption(PlayerOption.ATTACK, true));
293 player.send(new SendPlayerOption(PlayerOption.DUEL_REQUEST, false, true));*/
294 } else if (Area.inDuelArena(player) || Area.inDuelObsticleArena(player)) {
295 player.send(new SendPlayerOption(PlayerOption.ATTACK, true));
296 player.send(new SendPlayerOption(PlayerOption.DUEL_REQUEST, false, true));
297 } else {
298 player.send(new SendPlayerOption(PlayerOption.ATTACK, false, true));
299 player.send(new SendPlayerOption(PlayerOption.DUEL_REQUEST, false, true));
300 }
301 player.send(new SendPlayerOption(PlayerOption.FOLLOW, false));
302 player.send(new SendPlayerOption(PlayerOption.TRADE_REQUEST, false));
303 player.send(new SendPlayerOption(PlayerOption.VIEW_PROFILE, false));
304 }
305
307 public void setPrayer() {
308 Consumer<Prayer> enable = prayer -> {
309 if (player.prayer.anyActive(Prayer.RETRIBUTION, Prayer.REDEMPTION, Prayer.SMITE)) {
310 player.getCombat().addListener(PrayerListener.get());
311 }
312 player.send(new SendConfig(prayer.getConfig(), 1));
313 prayer.getListener().ifPresent(listener -> player.getCombat().addListener(listener));
314 };
315 Consumer<Prayer> disable = prayer -> {
316 if (prayer == Prayer.RETRIBUTION || prayer == Prayer.REDEMPTION || prayer == Prayer.SMITE) {
317 player.getCombat().removeListener(PrayerListener.get());
318 }
319 player.send(new SendConfig(prayer.getConfig(), 0));
320 prayer.getListener().ifPresent(listener -> player.getCombat().removeListener(listener));
321 };
322 Consumer<Prayer> overhead = prayer -> {
323 player.headIcon = prayer.getHeadIcon();
324 player.updateFlags.add(UpdateFlag.APPEARANCE);
325 };
326 Consumer<Prayer> noOverhead = prayer -> {
327 player.headIcon = -1;
328 player.updateFlags.add(UpdateFlag.APPEARANCE);
329 };
330 player.prayer.setOnChange(enable, disable, overhead, noOverhead);
331 Consumer<Prayer> qEnable = prayer -> player.send(new SendConfig(prayer.getQConfig(), 0));
332 Consumer<Prayer> qDisable = prayer -> player.send(new SendConfig(prayer.getQConfig(), 1));
333 player.quickPrayers.setOnChange(qEnable, qDisable, null, null);
334 Arrays.stream(Prayer.values()).forEach(prayer -> {
335 disable.accept(prayer);
336
337 if (player.quickPrayers.isActive(prayer)) {
338 qEnable.accept(prayer);
339 } else {
340 qDisable.accept(prayer);
341 }
342 });
343 }
344
346 public void restore() {
347 reset();
348 player.runEnergy = 100;
349 player.skulling.unskull();
350 player.skills.restoreAll();
351 player.inventory.refresh();
352 player.equipment.login();
353 player.action.reset();
354 player.interfaceManager.close();
355 player.setSpecialActivated(false);
356 player.send(new SendSpecialEnabled(0));
357 player.getCombat().getDamageCache().clear();
358 player.send(new SendRunEnergy());
359 player.movement.reset();
360 player.teleblockTimer.set(0);
361 player.spellCasting.castingDelay.reset();
362 player.spellCasting.vengeanceDelay.reset();
363
364 if (player.venged) {
365 player.venged = false;
366 player.getCombat().removeListener(VengeanceListener.get());
367 }
368
369 CombatSpecial.restore(player, 100);
370 }
371
373 public void reset() {
374 player.unpoison();
375 player.unvenom();
376 resetEffects();
377 setWidget();
378 player.movement.reset();
379 player.getCombat().reset();
380 player.prayer.reset();
381 player.headIcon = -1;
382 player.updateFlags.add(UpdateFlag.APPEARANCE);
383 }
384
386 public void resetEffects() {
387 CombatUtil.cancelEffect(player, CombatEffectType.TELEBLOCK);
388 CombatUtil.cancelEffect(player, CombatEffectType.ANTIFIRE_POTION);
391 }
392
394 public void setWidget() {
395 for (WidgetType widget : WidgetType.values()) {
396 player.send(new SendWidget(widget, 0));
397 }
398 }
399
401 private void run() {
402 if (player.movement.isRunning() && player.movement.isMoving() && !player.isBot && !PlayerRight.isDeveloper(player)) {
403 player.runEnergy--;
404 if (player.runEnergy < 0)
405 player.runEnergy = 0;
406 if (player.runEnergy == 0)
407 player.movement.setRunningToggled(false);
408 player.send(new SendRunEnergy());
409 }
410 }
411
413 private void runRestore() {
414 if (player.resting && player.sequence % 50 == 0) {
415 player.animate(player.right.getRestAnimation());
416 }
417 if (player.runEnergy < 100) {
418 int rate = player.energyRate > 0 ? 2 : player.resting || SkillCape.isEquipped(player, SkillCape.AGILITY) ? 3 : 4;
419 if (player.sequence % rate == 0) {
420 player.runEnergy++;
421 player.send(new SendRunEnergy());
422 }
423 }
424 if (player.energyRate > 0) {
425 player.energyRate--;
426 }
427 }
428
429 public void activateSkilling(int amount) {
430 if (Utility.hasOneOutOf(30)) {
431 player.skillingPoints += amount;
432 player.message("<col=D4379A>You have earned " + amount + " skilling point" + (amount > 1 ? "" : "s") + ". You now have a total of " + Utility.formatDigits(player.skillingPoints) + ".");
433 }
434 }
435
437 private void skillRestore() {
438 if (player.sequence % 120 != 0 && player.sequence % 50 != 0)
439 return;
440 if (player.sequence % (SkillCape.isEquipped(player, SkillCape.HITPOINTS) ? 50 : 100) == 0) {
441 player.skills.regress(Skill.HITPOINTS);
442 } else if (player.sequence % 50 == 0 && player.prayer.isActive(Prayer.RAPID_HEAL)) {
443 player.skills.regress(Skill.HITPOINTS);
444 }
445 for (int index = 0; index <= 6; index++) {
446 if (index == Skill.HITPOINTS || index == Skill.PRAYER) continue;
447 int amount = 100;
448 Skill skill = player.skills.get(index);
449 if (skill.getLevel() < skill.getMaxLevel() && player.prayer.isActive(Prayer.RAPID_RESTORE))
450 amount = 50;
451 if (skill.getLevel() > skill.getMaxLevel() && player.prayer.isActive(Prayer.PRESERVE))
452 amount = 150;
453 if (player.sequence % amount == 0)
454 player.skills.regress(index);
455 }
456 }
457
459 private void prayerDrain() {
460 if (!player.prayer.isActive()) {
461 return;
462 }
463 int bonus = player.getBonus(Equipment.PRAYER_BONUS);
464 int rate = player.prayer.drainAmount(bonus);
465 drainPrayer(rate);
466 }
467
468 public void drainPrayer(int amount) {
469 if (amount > 0) {
470 Skill skill = player.skills.get(Skill.PRAYER);
471 skill.modifyLevel(level -> level - amount, 0, skill.getLevel());
472 player.skills.refresh(Skill.PRAYER);
473
474 if (skill.getLevel() == 0) {
475 player.send(new SendMessage("You have run out of prayer points; you must recharge at an altar."));
476 player.prayer.reset();
477 player.getPlayer().send(new SendConfig(659, 0));
478 }
479 }
480 }
481
482 public void claimIronmanArmour() {
483 if (player.right == PlayerRight.IRONMAN) {
484 player.inventory.addOrDrop(new Item(12810), new Item(12811), new Item(12812));
485 } else if (player.right == PlayerRight.ULTIMATE_IRONMAN) {
486 player.inventory.addOrDrop(new Item(12813), new Item(12814), new Item(12815));
487 } else if (player.right == PlayerRight.HARDCORE_IRONMAN) {
488 player.inventory.addOrDrop(new Item(20792), new Item(20794), new Item(20796));
489 }
490 else {
491 player.message("You must be an ironman to claim this armour.");
492 }
493 }
494
496 public void copy(Player other) {
497 Item[] inventory = other.inventory.toArray();
498 Item[] equipment = other.equipment.toArray();
499 player.inventory.clear(false);
500 player.equipment.clear(false);
501 player.inventory.addAll(inventory);
502 player.equipment.manualWearAll(equipment);
503 player.inventory.refresh();
504 player.equipment.login();
505 }
506
508 public void transform(int npc) {
509 if (npc == -1) {
510 player.mobAnimation.reset();
511 player.setWidth(1);
512 player.setLength(1);
513 } else {
515 if (def != null) {
516 player.mobAnimation.setStand(def.getStand());
517 player.mobAnimation.setWalk(def.getWalk());
518 player.mobAnimation.setTurn180(def.getTurn180());
519 player.mobAnimation.setTurn90CW(def.getTurn90CW());
520 player.mobAnimation.setTurn90CCW(def.getTurn90CCW());
521 player.setWidth(def.getSize());
522 player.setLength(def.getSize());
523 }
524 }
525 player.id = npc;
526 player.updateFlags.add(UpdateFlag.APPEARANCE);
527 }
528
530 void welcomeScreen() {
531 player.setVisible(true);
532
533// boolean wants = player.settings.welcomeScreen;
534// if (!wants || Area.inWilderness(player) || player.getCombat().inCombat() || player.newPlayer || player.needsStarter) {
535// player.setVisible(true);
536// player.send(new SendScreenMode(player.settings.clientWidth, player.settings.clientHeight));
537// return;
538// }
539// if (player.settings.clientWidth > 765 || player.settings.clientWidth > 503) {
540// player.settings.clientWidth = 765;
541// player.settings.clientHeight = 503;
542// player.send(new SendScreenMode(765, 503));
543// }
544// for (int index = 0; index < 3; index++) {
545// player.send(new SendString(Config.WELCOME_DIALOGUE[index], 21315 + index));
546// }
547// player.send(new SendInterfaceAnimation(21310, Expression.HAPPY.getId()));
548// player.send(new SendMarquee(21319, Config.WELCOME_MARQUEE));
549// player.send(new SendString("You last logged in <col=EB4646>earlier today</col>.", 21318));//TODO
550// //black marks
551// player.send(new SendString("", 21320));
552// player.send(new SendString("You have 0 black marks!", 21321));
553// player.send(new SendString("Keep up the good work!", 21322));
554// player.send(new SendString("", 21323));
555// //bank pins
556// player.send(new SendString("You do not have a bank", 21324));
557// player.send(new SendString("pin set! Speak to any", 21325));
558// player.send(new SendString("banker to set one.", 21326));
559// player.send(new SendString("Bank pins are security!", 21327));
560// //other
561// player.send(new SendString("Click to vote", 21328));
562// player.send(new SendString("Click to donate", 21329));
563// player.send(new SendString("Click change e-mail", 21330));
564// player.send(new SendString("Click to change pass", 21331));
565// //announcement
566// player.send(new SendString(Config.WELCOME_ANNOUNCEMENT[0], 21332));
567// player.send(new SendString(Config.WELCOME_ANNOUNCEMENT[1], 21333));
568// player.send(new SendString(Config.WELCOME_ANNOUNCEMENT[2], 21334));
569// player.send(new SendString(Config.WELCOME_ANNOUNCEMENT[3], 21335));
570// player.send(new SendString(Config.WELCOME_ANNOUNCEMENT[4], 21336));
571// //update
572// player.send(new SendString(Config.WELCOME_UPDATE[0], 21337));
573// player.send(new SendString(Config.WELCOME_UPDATE[1], 21338));
574// player.send(new SendString(Config.WELCOME_UPDATE[2], 21339));
575// player.send(new SendString(Config.WELCOME_UPDATE[3], 21340));
576// player.send(new SendString(Config.WELCOME_UPDATE[4], 21341));
577// player.interfaceManager.open(450);
578 }
579
581 public void destroyItem(Item item, int slot) {
582 player.send(new SendItemOnInterfaceSlot(14171, item, 0));
583 player.send(new SendString("Are you sure you want to destroy this item?", 14174));
584 player.send(new SendString("Yes.", 14175));
585 player.send(new SendString("No.", 14176));
586 player.send(new SendString("", 14177));
587 player.send(new SendString(/*item.getDestroyMessage()*/"Doing this action is permanent!", 14182));
588 player.send(new SendString("", 14183));
589 player.send(new SendString(item.getName(), 14184));
590 player.send(new SendChatBoxInterface(14170));
591 player.attributes.set("DESTROY_ITEM_KEY", slot);
592 }
593
595 public void handleDestroyItem() {
596 if (player.attributes.has("UNCHARGE_HELM_KEY")) {
597 Item item = player.attributes.get("UNCHARGE_HELM_KEY");
598 player.dialogueFactory.clear();
599 player.inventory.replace(item, new Item(12_934, 20_000), true);
600 player.send(new SendMessage("You have dismantled your " + item.getName() + "."));
601 player.attributes.remove("UNCHARGE_HELM_KEY");
602 return;
603 }
604
605 if (player.attributes.has("RESTORE_HELM_KEY")) {
606 Item item = player.attributes.get("RESTORE_HELM_KEY");
607 player.dialogueFactory.clear();
608 if (item.matchesId(13_197)) {
609 player.serpentineHelmCharges += player.tanzaniteHelmCharges;
610 player.tanzaniteHelmCharges = 0;
611 if (player.serpentineHelmCharges > 11_000) {
612 player.inventory.addOrDrop(new Item(12934, player.serpentineHelmCharges - 11_000));
613 player.serpentineHelmCharges = 11_000;
614 }
615 player.inventory.replace(item, new Item(player.serpentineHelmCharges <= 0 ? 12_929 : 12_931), true);
616 } else if (item.matchesId(13_199)) {
617 player.serpentineHelmCharges += player.magmaHelmCharges;
618 player.magmaHelmCharges = 0;
619 if (player.serpentineHelmCharges > 11_000) {
620 player.inventory.addOrDrop(new Item(12934, player.serpentineHelmCharges - 11_000));
621 player.serpentineHelmCharges = 11_000;
622 }
623 }
624 player.inventory.replace(item, new Item(player.serpentineHelmCharges <= 0 ? 12_929 : 12_931), true);
625 player.send(new SendMessage("You have restored your " + item.getName() + "."));
626 player.attributes.remove("RESTORE_HELM_KEY");
627 return;
628 }
629
630 int index = player.attributes.get("DESTROY_ITEM_KEY", Integer.class);
631 if (index == -1)
632 return;
633 Item item = player.inventory.get(index);
634 if (item == null)
635 return;
636 player.dialogueFactory.clear();
637 player.inventory.remove(item, index);
638 player.send(new SendMessage("You have destroyed your " + item.getName() + "."));
639 player.attributes.remove("DESTROY_ITEM_KEY");
640 }
641
642 public boolean contains(Item item) {
643 return player.inventory.contains(item) || player.equipment.contains(item) || player.bank.contains(item);
644 }
645
647 public String kdr() {
648 double KDR = (player.kill / (double) player.death);
649 return Double.isNaN(KDR) ? "0.0" : String.format("%.2f", KDR);
650 }
651
653 public int getMaxHit(Mob defender, CombatType type) {
654 player.getCombat().addFirst(player.getStrategy());
655 int max = FormulaFactory.getModifiedMaxHit(player, defender, type);
656 player.getCombat().removeFirst();
657 return max;
658 }
659
661 public int instance() {
662 return player.getIndex() << 2;
663 }
664
666 public int getMaxSkillCount() {
667 int count = 0;
668 for (int index = 0; index < Skill.SKILL_COUNT; index++) {
669 if (player.skills.getMaxLevel(index) == 99)
670 count++;
671 }
672 return count;
673 }
674
675 public long networth() {
676 return networth(player.inventory, player.equipment, player.bank);
677 }
678
680 public long networth(ItemContainer... containers) {
681 long networth = 0;
682 for (ItemContainer container : containers) {
683 networth += container.containerValue(PriceType.VALUE);
684 }
685 return networth;
686 }
687
689 public double weight() {
690 double weight = player.inventory.getWeight();
691 weight += player.equipment.getWeight();
692 return weight;
693 }
694
695 public ValueIcon getValueIcon(Player player) {
696 ValueIcon icon = ValueIcon.NONE;
697 long carrying = networth(player.inventory, player.equipment);
698
699 if (carrying < 500_000)
700 icon = ValueIcon.BRONZE;
701 if (carrying > 500_000 && carrying < 1_500_000)
702 icon = ValueIcon.SILVER;
703 if (carrying > 1_500_000 && carrying < 5_000_000)
704 icon = ValueIcon.GREEN;
705 if (carrying > 5_000_000 && carrying < 25_000_000)
706 icon = ValueIcon.BLUE;
707 if (carrying > 25_000_000)
708 icon = ValueIcon.RED;
709
710 return icon;
711 }
712
713 public void setValueIcon() {
714 ValueIcon icon = getValueIcon(player);
715
716 final int currentIcon = player.valueIcon;
717
718 if (icon.getCode() == currentIcon) {
719 return;
720 }
721
722 player.valueIcon = icon.getCode();
723 player.updateFlags.add(UpdateFlag.APPEARANCE);
724 }
725
726 String getCombatRange() {
727 return (player.skills.getCombatLevel() - 10 < 3 ? 3 : player.skills.getCombatLevel() - 10) + " - " + (player.skills.getCombatLevel() + 10 > 126 ? 126 : player.skills.getCombatLevel() + 10);
728 }
729
731 public boolean busy() {
732 return !player.interfaceManager.isMainClear() || player.isDead() || player.newPlayer ||
733 player.needsStarter || player.locking.locked() || player.inActivity(ActivityType.DUEL_ARENA);
734 }
735
736 public void moveCamera(Position position, int resetDelay) {
737 player.send(new SendCameraTurn(position.getChunkX(), position.getChunkY(), position.getHeight(), 5, 5));
738 World.schedule(resetDelay, () -> player.send(new SendCameraReset()));
739 }
740
741 private static final int[] RING_OF_WEALTH = {
742 2572, 11988, 11986, 11984, 11982, 11980
743 };
744
745 private int getROWIndex(int item) {
746 int index = -1;
747 for (int amulet = 0; amulet < RING_OF_WEALTH.length; amulet++) {
748 if (item == RING_OF_WEALTH[amulet]) {
749 return amulet;
750 }
751 }
752 return index;
753 }
754
755 public void useROW() {
756 for (int row : RING_OF_WEALTH) {
757 int index = getROWIndex(row);
758 if (player.equipment.contains(row)) {
759 player.equipment.set(Equipment.RING_SLOT, new Item(RING_OF_WEALTH[index]), true);
760 player.message("<col=7F007F>" + (index == 0 ? "You have used your last charge." : "Your ring of wealth has " + Utility.convertWord(index).toLowerCase() + "charge" + (index == 1 ? "" : "s") + " remaining."));
761 break;
762 }
763 }
764 }
765
767 public boolean checkSendString(String text, int id) {
768 if (!interfaceText.containsKey(id)) {
769 interfaceText.put(id, new TinterfaceText(text, id));
770 return true;
771 }
772 TinterfaceText t = interfaceText.get(id);
773 if (t.currentState.equals(text))
774 return false;
775 t.currentState = text;
776 return true;
777 }
778
780 public void clearSendStrings() {
781 interfaceText.clear();
782 }
783}
static final int[][] SIDEBAR_INTERFACE
Definition Config.java:276
static void refresh(Player player)
static void onLogin(Player player)
Definition Pets.java:261
static void schedule(Task task)
Definition World.java:284
static boolean cancelEffect(Mob mob, CombatEffectType effect)
void modifyLevel(Function< Integer, Integer > function)
Definition Skill.java:318
static String formatDigits(final int amount)
Definition Utility.java:78
static String convertWord(int amount)
Definition Utility.java:173