RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
Player.java
1package com.osroyale.game.world.entity.mob.player;
2
3import com.osroyale.Config;
4import com.osroyale.content.ActivityLog;
5import com.osroyale.content.ActivityLogger;
6import com.osroyale.content.achievement.AchievementKey;
7import com.osroyale.content.activity.Activity;
8import com.osroyale.content.activity.impl.barrows.BrotherData;
9import com.osroyale.content.activity.record.PlayerRecord;
10import com.osroyale.content.bags.impl.CoalBag;
11import com.osroyale.content.bags.impl.GemBag;
12import com.osroyale.content.clanchannel.channel.ClanChannel;
13import com.osroyale.content.clanchannel.channel.ClanChannelHandler;
14import com.osroyale.content.clanchannel.content.ClanViewer;
15import com.osroyale.content.collectionlog.CollectionLog;
16import com.osroyale.content.collectionlog.CollectionLogData;
17import com.osroyale.content.collectionlog.CollectionLogPage;
18import com.osroyale.content.collectionlog.CollectionLogSaving;
19import com.osroyale.content.combat.Killstreak;
20import com.osroyale.content.combat.Skulling;
21import com.osroyale.content.dailyeffect.DailyEffect;
22import com.osroyale.content.dailyeffect.impl.DailySlayerTaskSkip;
23import com.osroyale.content.dailyeffect.impl.DailySlayerTaskTeleport;
24import com.osroyale.content.dailyeffect.impl.DailySpellBookSwap;
25import com.osroyale.content.dialogue.ChatBoxItemDialogue;
26import com.osroyale.content.dialogue.Dialogue;
27import com.osroyale.content.dialogue.DialogueFactory;
28import com.osroyale.content.dialogue.OptionDialogue;
29import com.osroyale.content.donators.Donation;
30import com.osroyale.content.emote.EmoteUnlockable;
31import com.osroyale.content.event.EventDispatcher;
32import com.osroyale.content.event.impl.LogInEvent;
33import com.osroyale.content.gambling.GambleManager;
34import com.osroyale.content.lms.LMSGame;
35import com.osroyale.content.lms.lobby.LMSLobby;
36import com.osroyale.content.lms.lobby.LMSLobbyEvent;
37import com.osroyale.content.mysterybox.MysteryBoxManager;
38import com.osroyale.content.overrides.Overrides;
39import com.osroyale.content.pet.PetData;
40import com.osroyale.content.pet.Pets;
41import com.osroyale.content.preset.PresetManager;
42import com.osroyale.content.prestige.Prestige;
43import com.osroyale.content.puzzle.PuzzleDisplay;
44import com.osroyale.content.skill.impl.construction.House;
45import com.osroyale.content.skill.impl.farming.Farming;
46import com.osroyale.content.skill.impl.hunter.birdhouse.PlayerBirdHouseData;
47import com.osroyale.content.skill.impl.hunter.trap.TrapManager;
48import com.osroyale.content.skill.impl.magic.RunePouch;
49import com.osroyale.content.skill.impl.magic.Spellbook;
50import com.osroyale.content.skill.impl.magic.spell.SpellCasting;
51import com.osroyale.content.skill.impl.runecrafting.RunecraftPouch;
52import com.osroyale.content.skill.impl.slayer.Slayer;
53import com.osroyale.content.store.impl.PersonalStore;
54import com.osroyale.content.teleport.Teleport;
55import com.osroyale.content.tittle.PlayerTitle;
56import com.osroyale.content.tradingpost.TradingPost;
57import com.osroyale.game.event.impl.MovementEvent;
58import com.osroyale.game.plugin.PluginManager;
59import com.osroyale.game.service.Highscores;
60import com.osroyale.game.task.impl.PvPTimerTask;
61import com.osroyale.game.task.impl.TeleblockTask;
62import com.osroyale.game.world.World;
63import com.osroyale.game.world.entity.EntityType;
64import com.osroyale.game.world.entity.combat.Combat;
65import com.osroyale.game.world.entity.combat.CombatConstants;
66import com.osroyale.game.world.entity.combat.attack.FightType;
67import com.osroyale.game.world.entity.combat.effect.AntifireDetails;
68import com.osroyale.game.world.entity.combat.magic.CombatSpell;
69import com.osroyale.game.world.entity.combat.ranged.RangedAmmunition;
70import com.osroyale.game.world.entity.combat.ranged.RangedWeaponDefinition;
71import com.osroyale.game.world.entity.combat.strategy.CombatStrategy;
72import com.osroyale.game.world.entity.combat.strategy.player.special.CombatSpecial;
73import com.osroyale.game.world.entity.combat.weapon.WeaponInterface;
74import com.osroyale.game.world.entity.mob.Mob;
75import com.osroyale.game.world.entity.mob.UpdateFlag;
76import com.osroyale.game.world.entity.mob.Viewport;
77import com.osroyale.game.world.entity.mob.movement.waypoint.PickupWaypoint;
78import com.osroyale.game.world.entity.mob.movement.waypoint.Waypoint;
79import com.osroyale.game.world.entity.mob.npc.Npc;
80import com.osroyale.game.world.entity.mob.player.appearance.Appearance;
81import com.osroyale.game.world.entity.mob.player.exchange.ExchangeSessionManager;
82import com.osroyale.game.world.entity.mob.player.relations.ChatMessage;
83import com.osroyale.game.world.entity.mob.player.relations.PlayerRelation;
84import com.osroyale.game.world.entity.mob.player.requests.PlayerPunishment;
85import com.osroyale.game.world.entity.mob.player.requests.RequestManager;
86import com.osroyale.game.world.entity.mob.prayer.Prayer;
87import com.osroyale.game.world.entity.mob.prayer.PrayerBook;
88import com.osroyale.game.world.items.Item;
89import com.osroyale.game.world.items.containers.bank.Bank;
90import com.osroyale.game.world.items.containers.bank.BankPin;
91import com.osroyale.game.world.items.containers.bank.BankVault;
92import com.osroyale.game.world.items.containers.bank.DonatorDeposit;
93import com.osroyale.game.world.items.containers.equipment.Equipment;
94import com.osroyale.game.world.items.containers.impl.LootingBag;
95import com.osroyale.game.world.items.containers.impl.LostUntradeables;
96import com.osroyale.game.world.items.containers.inventory.Inventory;
97import com.osroyale.game.world.items.containers.pricechecker.PriceChecker;
98import com.osroyale.game.world.object.CustomGameObject;
99import com.osroyale.game.world.object.ObjectDirection;
100import com.osroyale.game.world.object.ObjectType;
101import com.osroyale.game.world.position.Area;
102import com.osroyale.game.world.position.Boundary;
103import com.osroyale.game.world.position.Position;
104import com.osroyale.game.world.region.Region;
105import com.osroyale.net.packet.OutgoingPacket;
106import com.osroyale.net.packet.out.*;
107import com.osroyale.net.session.GameSession;
108import com.osroyale.util.*;
109import org.apache.logging.log4j.LogManager;
110import org.apache.logging.log4j.Logger;
111import org.jire.tarnishps.event.Events;
112
113import java.util.*;
114import java.util.concurrent.TimeUnit;
115import java.util.concurrent.atomic.AtomicBoolean;
116import java.util.concurrent.atomic.AtomicInteger;
117import java.util.function.Consumer;
118
156
157* This class represents a character controlled by a player.
158 *
159 * @author Daniel
160 * @author Michael | Chex
161 */
162public class Player extends Mob {
163
164 private final Events events = new Events();
165
166 public List<PlayerBirdHouseData> birdHouseData = new ArrayList<>();
167 public int wintertodtPoints;
168 public int menuOpened, optionOpened = -1;
169
170 private final GambleManager gamblingManager = new GambleManager();
171 public Map<String, Position> waypoints = new HashMap<>();
172 public Teleport lastTeleport = null;
173 public GambleManager getGambling() {
174 return gamblingManager;
175 }
176
177 private long lastModification;
178
179 public void setLastModification(long lastModification) {
180 this.lastModification = lastModification;
181 }
182
183 public long getLastModification() {
184 return lastModification;
185 }
186
187 private boolean gambleLocked;
188
189 public void setGambleLock(boolean gambleLocked) {
190 this.gambleLocked = gambleLocked;
191 }
192
193 public boolean isGambleLocked() {
194 return gambleLocked;
195 }
196
200 public int lastFogSent;
201 public transient long lmsImmunity;
202 public long lastLMSRopeCross;
203 public List<Integer> unlockedLMSItems = new ArrayList<>();
204 public int lmsKills;
205 public int lmsDeaths;
206
207 public int answeredTrivias;
208 public int lmsPoints;
209 public int lmsTotalKills;
210 public int lmsTotalDeaths;
211 public int lmsWins;
212
213 public GemBag gemBag = new GemBag();
214
215 public CoalBag coalBag = new CoalBag();
216
217 public CollectionLogPage collectionLogPageOpen = null;
218 public CollectionLogData collectionLogView = null;
219
220 private CollectionLog collectionLog = new CollectionLog();
221
222 public void setCollectionLog(CollectionLog collectionLog) {
223 this.collectionLog = collectionLog;
224 }
225
226 public HashMap<WeaponInterface, FightType> fightStyles = new HashMap<>();
227
228 public CollectionLog getCollectionLog() {
229 return this.collectionLog;
230 }
231
232 private static final Logger logger = LogManager.getLogger(Player.class);
233 private int memberId = -1;
234 public final Viewport viewport = new Viewport(this);
235 public boolean debug;
236 public Npc pet;
237 public CombatSpell autocast;
238 public CombatSpell singleCast;
239 public Appearance appearance = Config.DEFAULT_APPEARANCE;
240 public PlayerRight right = PlayerRight.PLAYER;
241 public PlayerTitle playerTitle = PlayerTitle.empty();
242 public Spellbook spellbook = Spellbook.MODERN;
243 public Spellbook spellbook_copy = Spellbook.MODERN;
244 public ChatBoxItemDialogue chatBoxItemDialogue;
245 private Optional<ChatMessage> chatMessage = Optional.empty();
246 public DailyEffect dailySlayerTaskTeleport = new DailySlayerTaskTeleport();
247 public DailyEffect dailySlayerTaskSkip = new DailySlayerTaskSkip();
248 public DailyEffect dailySpellBookSwap = new DailySpellBookSwap();
249 public PrayerBook quickPrayers = new PrayerBook();
250 public HashSet<Prayer> unlockedPrayers = new HashSet<>();
251 public RangedWeaponDefinition rangedDefinition;
252 public RangedAmmunition rangedAmmo;
253 private AntifireDetails antifireDetails;
254 private WeaponInterface weapon = WeaponInterface.UNARMED;
255 private CombatSpecial combatSpecial;
256 public Optional<Player> managing;
257 public boolean completedMageArena;
258 public boolean pvpInstance;
259 public boolean hasPvPTimer;
260 public Stopwatch pvpTimer = Stopwatch.start();
261 public Optional<Dialogue> dialogue = Optional.empty();
262 public Optional<OptionDialogue> optionDialogue = Optional.empty();
263 public Optional<Consumer<String>> enterInputListener = Optional.empty();
264 public boolean[] barrowKills = new boolean[BrotherData.values().length];
265 public final PlayerRelation relations = new PlayerRelation(this);
266 public final Donation donation = new Donation(this);
267 public final LostUntradeables lostUntradeables = new LostUntradeables(this);
268 public LinkedList<Item> lostItems = new LinkedList<>();
269 public BrotherData hiddenBrother;
270 public int barrowsKillCount;
271 public int sequence;
272 public int playTime;
273 public int kill;
274 public int death;
275 public int shop;
276 public int headIcon;
277 public int valueIcon = -1;
278 public int skillingPoints;
279 public int pestPoints;
280 public int votePoints;
281 public int totalVotes;
282 public int[] achievedSkills = new int[7];
283
284 public int mageArenaPoints;
285 public int ringOfRecoil = 40;
286 public int whipCharges = 2500;
287 public int agsCharges = 750;
288 public int wilderness;
289 public int runEnergy;
290 public int energyRate;
291 public int glovesTier;
292 public int royaltyLevel = 1;
293 public int royalty;
294
295 public int smallPouch;
296 public int mediumPouch;
297 public int largePouch;
298 public int giantPouch;
299 public final RunecraftPouch runecraftPouch = new RunecraftPouch(this);
300 public double experienceRate = Config.COMBAT_MODIFICATION;
301 public long usernameLong;
302 public boolean idle;
303 public boolean resting;
304 public boolean newPlayer;
305 public boolean needsStarter;
306 public boolean venged;
307 private boolean specialActivated;
308 public boolean warriorGuidTask;
309 public boolean isBot;
310 public int trapsLaid;
311 private String username = "";
312 private String password = "";
313 public String uuid;
314 public String lastHost;
315 public String created = Utility.getDate();
316 public String lastClan = "";
317 public ClanChannel clanChannel;
318 public String clan = "";
319 public String clanTag = "";
320 public String clanTagColor = "";
321 public final AtomicBoolean saved = new AtomicBoolean(false);
322 public Stopwatch yellDelay = Stopwatch.start();
323 public Stopwatch godwarsDelay = Stopwatch.start();
324 public Stopwatch buttonDelay = Stopwatch.start();
325 public Stopwatch itemDelay = Stopwatch.start();
326 public Stopwatch foodDelay = Stopwatch.start();
327 public Stopwatch fastFoodDelay = Stopwatch.start();
328 public Stopwatch potionDelay = Stopwatch.start();
329 public Stopwatch revstele = Stopwatch.start();
330 public int cooldown = 7 * 60 * 1000;
331 public long lastUsed = 0;
332 public Stopwatch restoreDelay = Stopwatch.start();
333 public Stopwatch diceDelay = Stopwatch.start();
334 public Stopwatch aggressionTimer = Stopwatch.start();
335 public Stopwatch databaseRequest = Stopwatch.start();
336 public Set<PetData> petInsurance = new HashSet<>();
337 public Set<PetData> lostPets = new HashSet<>();
338 public final PuzzleDisplay puzzle = new PuzzleDisplay(this);
339 public final ClanViewer clanViewer = new ClanViewer(this);
340 public final PlayerRecord gameRecord = new PlayerRecord(this);
341 public final Farming farming = new Farming(this);
342 public final ExchangeSessionManager exchangeSession = new ExchangeSessionManager(this);
343 public final Map<Integer, PersonalStore> viewing_shops = new HashMap<>();
344 public final PlayerAssistant playerAssistant = new PlayerAssistant(this);
345 public final InterfaceManager interfaceManager = new InterfaceManager(this);
346 public final RequestManager requestManager = new RequestManager(this);
347 public final MysteryBoxManager mysteryBox = new MysteryBoxManager(this);
348 public final Settings settings = new Settings(this);
349 public final Inventory inventory = new Inventory(this);
350 public final Inventory inventory_copy = new Inventory(this);
351 public final Bank bank = new Bank(this);
352 public final BankVault bankVault = new BankVault(this);
353 public final BankPin bankPin = new BankPin(this);
354 public final RunePouch runePouch = new RunePouch(this);
355 public final RunePouch runePouch_copy = new RunePouch(this);
356 public final Killstreak killstreak = new Killstreak(this);
357 public final LootingBag lootingBag = new LootingBag(this);
358 public final PlayerPunishment punishment = new PlayerPunishment(this);
359 public final Equipment equipment = new Equipment(this);
360 public final Equipment equipment_copy = new Equipment(this);
361 public final PresetManager presetManager = new PresetManager(this);
362 public final Prestige prestige = new Prestige(this);
363 public final PriceChecker priceChecker = new PriceChecker(this);
364 public final DonatorDeposit donatorDeposit = new DonatorDeposit(this);
365 public DialogueFactory dialogueFactory = new DialogueFactory(this);
366 public final House house = new House(this);
367 public Slayer slayer = new Slayer(this);
368 public Skulling skulling = new Skulling(this);
369 public SpellCasting spellCasting = new SpellCasting(this);
370 private final Combat<Player> combat = new Combat<>(this);
371 public final ActivityLogger activityLogger = new ActivityLogger(this);
372 private final MutableNumber poisonImmunity = new MutableNumber();
373 private final MutableNumber venomImmunity = new MutableNumber();
374 private final MutableNumber specialPercentage = new MutableNumber();
375 public Deque<String> lastKilled = new ArrayDeque<>(3);
376 public List<EmoteUnlockable> emoteUnlockable = new LinkedList<>();
377 public List<Teleport> favoriteTeleport = new ArrayList<>();
378 public final Set<String> hostList = new HashSet<>();
379 public final TradingPost tradingPost = new TradingPost(this);
380 public final Overrides overrides = new Overrides(this);
381
382
383 public HashMap<ActivityLog, Integer> loggedActivities = new HashMap<ActivityLog, Integer>(ActivityLog.values().length) {
384 {
385 for (final ActivityLog achievement : ActivityLog.values())
386 put(achievement, 0);
387 }
388 };
389
390 public HashMap<AchievementKey, Integer> playerAchievements = new HashMap<AchievementKey, Integer>(AchievementKey.values().length) {
391 {
392 for (final AchievementKey achievement : AchievementKey.values())
393 put(achievement, 0);
394 }
395 };
396
397 public float blowpipeScales;
398 public Item blowpipeDarts;
399
400
401 public int crawsBowCharges;
402 public int viggorasChainmaceCharges;
403 public int thammoranSceptreCharges;
404 public int tridentSeasCharges;
405 public int tridentSwampCharges;
406
407 public int celestialRingCharges;
408
409 public int serpentineHelmCharges;
410 public int tanzaniteHelmCharges;
411 public int magmaHelmCharges;
412
413 public Stopwatch staffOfDeadSpecial = Stopwatch.start().reset(200);
414 private Optional<GameSession> session = Optional.empty();
415 public int dragonfireCharges;
416 public long dragonfireUsed;
417
418 public Player(String username) {
419 super(Config.DEFAULT_POSITION, false);
420 this.username = username;
421 this.usernameLong = Utility.nameToLong(username);
422 }
423
424 public Player(String username, Position position) {
426 this.setPosition(position);
427 this.setUsername(username);
428 this.isBot = true;
429 }
430
431 public void chat(ChatMessage chatMessage) {
432 if (!chatMessage.isValid()) {
433 return;
434 }
435 this.chatMessage = Optional.of(chatMessage);
436 this.updateFlags.add(UpdateFlag.CHAT);
437 }
438
439 public void setUsername(String username) {
440 this.username = username;
441 this.usernameLong = Utility.nameToLong(username);
442 }
443
444 public void send(OutgoingPacket encoder) {
445 encoder.execute(this);
446 }
447
448 private void login() {
449 positionChange = true;
450 regionChange = true;
451
452 onStep();
453
454 skills.login();
455
456 mobAnimation.reset();
457
458 inventory.refresh();
459
460 CombatSpell autocast = getAutocastSpell();
461 equipment.login();
462
463 settings.login();
464
465 relations.onLogin();
466
467 sendInitialPackets();
468
469 playerAssistant.login();
470
471
472 send(new SendSpecialEnabled(0));
473 send(new SendConfig(301, 0));
474
475 setAutocast(autocast);
476 if (isAutocast() && equipment.hasWeapon()) {
477 send(new SendConfig(43, 3));
478 send(new SendConfig(108, 1));
479 } else {
480 setAutocast(null);
481 send(new SendConfig(108, 0));
482 send(new SendString("Spell", 18584));
483 }
484 }
485
486 private void sendInitialPackets() {
487 int players = World.getPlayerCount();
488 send(new SendRunEnergy());
489 send(new SendPlayerDetails());
490 send(new SendCameraReset());
491 send(new SendExpCounter(skills.getExpCounter()));
492 World.sendMessage("<img=15> " +getPlayer().getName()+ " has logged in.");
493 message(true, String.format("Welcome to %s. ", Config.SERVER_NAME));
494 message(true, "We are currently in early access.");
495
496 if (Config.DOUBLE_EXPERIENCE) {
497 message("Double experience is currently active!");
498 }
499
500 if (players > GameSaver.MAX_PLAYERS) {
501 GameSaver.MAX_PLAYERS = players;
502 }
503 if (needsStarter) {
504 newPlayer = true;
505 }
506
507 playerAssistant.welcomeScreen();
508 }
509
510 private boolean canLogout() {
511 if (getCombat().inCombat()) {
512 send(new SendMessage("You can not logout whilst in combat!"));
513 return false;
514 }
515
516 if (!getCombat().hasPassed(CombatConstants.COMBAT_LOGOUT_COOLDOWN)) {
517 final long seconds = TimeUnit.SECONDS.convert(
518 CombatConstants.COMBAT_LOGOUT_COOLDOWN - combat.elapsedTime(),
519 TimeUnit.MILLISECONDS);
520 send(new SendMessage("You must wait " + seconds + " second" + (seconds > 1 ? "s" : "")
521 + " before you can logout as you were recently in combat."));
522 return false;
523 }
524
525 if (!interfaceManager.isMainClear()) {
526 send(new SendMessage("Please close what you are doing before logging out!"));
527 return false;
528 }
529
530 return !Activity.evaluate(this, it -> !it.canLogout(this));
531 }
532
533 public final Set<PlayerOption> contextMenus = new HashSet<>();
534
535 public final void logout() {
536 logout(false);
537 }
538
539 public final void logout(boolean force) {
540 if (!canLogout() && !force) {
541 return;
542 }
543
544 send(new SendLogout());
545 setVisible(false);
546 World.queueLogout(this);
547 }
548
549 public void loadRegion() {
550 for(PlayerBirdHouseData playerBirdHouseData : birdHouseData) {
551
552 if(Utility.goodDistance(playerBirdHouseData.birdhousePosition.getX(), playerBirdHouseData.birdhousePosition.getY(), getPosition().getX(), getPosition().getY(), 60)) {
553 int objectId = playerBirdHouseData.birdhouseData.objectData[playerBirdHouseData.seedAmount >= 10 ? 1 : 0];
554 send(new SendAddObject(new CustomGameObject(objectId, playerBirdHouseData.birdhousePosition, ObjectDirection.valueOf(playerBirdHouseData.rotation).get(), ObjectType.valueOf(playerBirdHouseData.type).get())));
555 }
556 }
557
558 Activity.forActivity(this, minigame -> minigame.onRegionChange(this));
559
560 Region[] surrounding = World.getRegions().getSurroundingRegions(getPosition());
561
562 for (Region region : surrounding) {
563 region.sendGroundItems(this);
564 region.sendGameObjects(this);
565
566 //Npc Face
567 for (Npc npc : region.getNpcs(getHeight())) {
568 if (!npc.getCombat().inCombat())
569 npc.face(npc.faceDirection);
570 }
571 }
572
573 farming.regionChange(this);
574 TrapManager.handleRegionChange(this);
575
576 if (debug && PlayerRight.isDeveloper(this)) {
577 send(new SendMessage("[REGION] Loaded new region.", MessageColor.DEVELOPER));
578 }
579 }
580
581 public void pickup(Item item, Position position) {
582 Waypoint waypoint = new PickupWaypoint(this, item, position);
583 if (cachedWaypoint == null || (!cachedWaypoint.isRunning() || !waypoint.equals(cachedWaypoint))) {
585 action.clearNonWalkableActions();
586 movement.reset();
587 getCombat().reset();
588 World.schedule(cachedWaypoint = waypoint);
589 }
590 }
591
592 public void forClan(Consumer<ClanChannel> action) {
593 if (clanChannel != null)
594 action.accept(clanChannel);
595 }
596 public void message(String message) {
597 send(new SendMessage(message));
598 }
599
600 @Override
601 public void register() {
602 if (!isRegistered() && !World.getPlayers().contains(this)) {
603 setRegistered(World.getPlayers().add(this));
604 setPosition(getPosition());
605
606 login();
607
608 logger.info("[REGISTERED]: " + Utility.formatName(getName()) + " [" + lastHost + "]");
609 EventDispatcher.execute(this, new LogInEvent());
610 }
611 }
612
613 @Override
614 public void unregister() {
615 if (!isRegistered()) {
616 return;
617 }
618
619 if (!World.getPlayers().contains(this)) {
620 return;
621 }
622 if (LMSGame.isActivePlayer(this))
623 LMSGame.onDeath(this, true);
624 World.sendMessage("<img=15> " +getPlayer().getName()+ " has logged out.");
625 send(new SendLogout());
626 Activity.forActivity(this, minigame -> minigame.onLogout(this));
627 relations.updateLists(false);
628 TrapManager.handleLogout(this);
629 ClanChannelHandler.disconnect(this, true);
630 interfaceManager.close();
631 new Highscores(this).execute();
632 //HighscoreService.saveHighscores(this);
633 World.cancelTask(this, true);
634 Pets.onLogout(this);
635 CollectionLogSaving.save(this);
636 World.getPlayers().remove((Player) destroy());
637 getGambling().decline(this);
638 logger.info(String.format("[UNREGISTERED]: %s [%s]", getName(), lastHost));
639 }
640
641 @Override
642 public void addToRegion(Region region) {
643 region.addPlayer(this);
644 aggressionTimer.reset();
645 }
646
647 @Override
648 public void removeFromRegion(Region region) {
649 region.removePlayer(this);
650 }
651
652 @Override
653 public void sequence() {
654 if (!idle) {
655 playTime++;
656 }
657
658 action.sequence();
659 playerAssistant.sequence();
660 sequence++;
661
662 if(Area.inLMSLobby(this) || Area.inLMSBuilding(this)) {
663 send(new SendString("Next Game: ", 44654));
664 send(new SendString("" + ((LMSLobbyEvent.lobbyTicks * 600) / 1000), 44655));
665 send(new SendString("" + LMSLobby.currentGameType.getClass().getSimpleName(), 44657));
666 send(new SendString("<col="+(LMSLobby.lobbyMembers.size() >= LMSLobby.requiredPlayers ? "65280" : "ff0000")+">" + LMSLobby.lobbyMembers.size() + "/" + LMSLobby.maxPlayers + "</col>", 44659));
667 }
668 }
669
670 @Override
671 public void onStep() {
672 PluginManager.getDataBus().publish(this, new MovementEvent(getPlayer().getPosition().copy()));
673 send(new SendMultiIcon(Area.inMulti(this) ? 1 : -1));
674
675 if (Activity.evaluate(this, activity -> activity.onStep(this))) {
676 return;
677 }
678
679 // Reset the options
680 send(new SendPlayerOption(PlayerOption.GAMBLE_REQUEST, false, true));
681 send(new SendPlayerOption(PlayerOption.ATTACK, false, true));
682 send(new SendPlayerOption(PlayerOption.DUEL_REQUEST, false, true));
683 send(new SendPlayerOption(PlayerOption.FOLLOW, false));
686
687 if(Boundary.isIn(this, GambleManager.GAMBLING_ZONE)) {
688 //send(new SendPlayerOption(PlayerOption.TRADE_REQUEST, false, true));
689 send(new SendPlayerOption(PlayerOption.GAMBLE_REQUEST, false));
690 }
691 else if(LMSGame.inGameArea(this)){
692 send(new SendPlayerOption(PlayerOption.ATTACK, true));
693 if (interfaceManager.getWalkable() != 44660)
694 interfaceManager.openWalkable(44660);
695 }
696 else if(Area.inLMSLobby(this) || Area.inLMSBuilding(this)) {
697 if (interfaceManager.getWalkable() != 44650)
698 interfaceManager.openWalkable(44650);
699 }
700 // pvp instance
701 else if (pvpInstance) {
702 if (hasPvPTimer) {
703 send(new SendPlayerOption(PlayerOption.ATTACK, true));
704 send(new SendPlayerOption(PlayerOption.DUEL_REQUEST, false, true));
705 } else if (Area.inPvP(this)) {
706 send(new SendString("<col=E68A00>" + playerAssistant.getCombatRange(), 23327));
707 send(new SendPlayerOption(PlayerOption.ATTACK, true));
708 send(new SendPlayerOption(PlayerOption.DUEL_REQUEST, false, true));
709 if (interfaceManager.getWalkable() != 23400) {
710 interfaceManager.openWalkable(23400);
711 }
712 return;
713 } else {
714 if (!hasPvPTimer && getCombat().inCombat()) {
715 World.schedule(new PvPTimerTask(this));
716 } else {
717 send(new SendString("<col=36CF4D>Safe", 23327));
718 send(new SendPlayerOption(PlayerOption.ATTACK, false, true));
719 send(new SendPlayerOption(PlayerOption.DUEL_REQUEST, false, true));
720 }
721 }
722 if (interfaceManager.getWalkable() != 23410) {
723 interfaceManager.openWalkable(23410);
724 }
725
726 // wilderness
727 } else if (Area.inWilderness(this)) {
728 int modY = getPosition().getY() > 6400 ? getPosition().getY() - 6400 : getPosition().getY();
729 wilderness = (((modY - 3521) / 8) + 1);
730 send(new SendString("Level " + wilderness, 23327));
731 send(new SendPlayerOption(PlayerOption.ATTACK, true));
732 send(new SendPlayerOption(PlayerOption.DUEL_REQUEST, false, true));
733 if (interfaceManager.getWalkable() != 23400)
734 interfaceManager.openWalkable(23400);
735
736 // duel arena lobby
737 } else if (Area.inDuelArenaLobby(this)) {
738 send(new SendPlayerOption(PlayerOption.DUEL_REQUEST, false));
739 send(new SendPlayerOption(PlayerOption.ATTACK, false, true));
740 if (interfaceManager.getWalkable() != 201)
741 interfaceManager.openWalkable(201);
742 // duel arena
743 } else if (Area.inDuelArena(this) || Area.inDuelObsticleArena(this)) {
744 send(new SendPlayerOption(PlayerOption.ATTACK, true));
745 send(new SendPlayerOption(PlayerOption.DUEL_REQUEST, false, true));
746 if (interfaceManager.getWalkable() != 201)
747 interfaceManager.openWalkable(201);
748
749 // event arena
750 /* } else if (Area.inEventArena(this)) {
751 send(new SendPlayerOption(PlayerOption.ATTACK, true));
752 send(new SendPlayerOption(PlayerOption.DUEL_REQUEST, false, true));
753 send(new SendString("Fun PK", 23327));
754 if (interfaceManager.getWalkable() != 23400)
755 interfaceManager.openWalkable(23400);*/
756
757 //
758 } else if (Area.inSuperDonatorZone(this) && (Area.inRegularDonatorZone(this) && !PlayerRight.isDonator(this))) {
759 move(Config.DEFAULT_POSITION);
760 send(new SendMessage("You're not supposed to be here!"));
761
762 // clear
763 } else if (!inActivity()) {
764 send(new SendPlayerOption(PlayerOption.GAMBLE_REQUEST, false, true));
765 send(new SendPlayerOption(PlayerOption.ATTACK, false, true));
766 send(new SendPlayerOption(PlayerOption.DUEL_REQUEST, false, true));
767 send(new SendPlayerOption(PlayerOption.FOLLOW, false));
768 send(new SendPlayerOption(PlayerOption.TRADE_REQUEST, false));
769 send(new SendPlayerOption(PlayerOption.VIEW_PROFILE, false));
770//
771// if (!interfaceManager.isClear())
772 interfaceManager.close();
773 if (wilderness > 0)
774 wilderness = 0;
775 }
776 }
777
778 @Override
779 public Combat<Player> getCombat() {
780 return combat;
781 }
782
783 @Override
784 public CombatStrategy<Player> getStrategy() {
785 return playerAssistant.getStrategy();
786 }
787
788 @Override
789 public void appendDeath() {
790 World.schedule(new PlayerDeath(this));
791 }
792
793 @Override
794 public String getName() {
795 return Utility.formatName(username);
796 }
797
798 @Override
800 return EntityType.PLAYER;
801 }
802
803 @Override
804 public boolean isValid() {
805 return (isBot || session != null) && super.isValid();
806 }
807
808 @Override
809 public boolean equals(Object obj) {
810 if (obj == this) {
811 return true;
812 }
813
814 if (obj == null || !(obj instanceof Player)) {
815 return false;
816 }
817
818 Player other = (Player) obj;
819 return Objects.equals(getIndex(), other.getIndex()) && Objects.equals(username, other.username) && Objects.equals(password, other.password) && Objects.equals(isBot, other.isBot);
820 }
821
822 @Override
823 public int hashCode() {
824 return Objects.hash(getIndex(), username);
825 }
826
827 @Override
828 public String toString() {
829 return String.format("Player[index=%d member_id=%d username=%s pos=%s bot=%b]", getIndex(), getMemberId(), getUsername(), getPosition(), isBot);
830 }
831
832 public void message(boolean filtered, String... messages) {
833 for (String message : messages) {
834 send(new SendMessage(message, filtered));
835 }
836 }
837
838 public void message(String... messages) {
839 for (String message : messages) {
840 send(new SendMessage(message));
841 }
842 }
843
844 public boolean isAutoRetaliate() {
845 return settings.autoRetaliate;
846 }
847
848 public boolean isSpecialActivated() {
849 return specialActivated;
850 }
851
852 public void setSpecialActivated(boolean activated) {
853 this.specialActivated = activated;
854 }
855
856 public void setCombatSpecial(CombatSpecial special) {
857 this.combatSpecial = special;
858 }
859
860 public boolean isSingleCast() {
861 return singleCast != null;
862 }
863
864 CombatSpell getSingleCastSpell() {
865 return singleCast;
866 }
867
868 public void setSingleCast(CombatSpell singleCast) {
869 this.singleCast = singleCast;
870 }
871
872 public boolean isAutocast() {
873 return autocast != null;
874 }
875
876 CombatSpell getAutocastSpell() {
877 return autocast;
878 }
879
880 public void setAutocast(CombatSpell autocast) {
881 this.autocast = autocast;
882 }
883
884 public MutableNumber getSpecialPercentage() {
885 return specialPercentage;
886 }
887
888 public final AtomicInteger teleblockTimer = new AtomicInteger(0);
889
890 public void teleblock(int time) {
891 if (time <= 0 || (teleblockTimer.get() > 0)) {
892 return;
893 }
894
895 teleblockTimer.set(time);
896 send(new SendMessage("A teleblock spell has been casted on you!"));
897 send(new SendWidget(SendWidget.WidgetType.TELEBLOCK, (int) ((double) teleblockTimer.get() / 1000D * 600D)));
898 World.schedule(new TeleblockTask(this));
899 }
900
901 public boolean isTeleblocked() {
902 return teleblockTimer.get() > 0;
903 }
904
905 public CombatSpecial getCombatSpecial() {
906 return combatSpecial;
907 }
908
909 public WeaponInterface getWeapon() {
910 return weapon;
911 }
912
913 public void setWeapon(WeaponInterface weapon) {
914 this.weapon = weapon;
915 }
916
917 public Optional<AntifireDetails> getAntifireDetails() {
918 return Optional.ofNullable(antifireDetails);
919 }
920
921 public void setAntifireDetail(AntifireDetails antifireDetails) {
922 this.antifireDetails = antifireDetails;
923 }
924
925 public final MutableNumber getPoisonImmunity() {
926 return poisonImmunity;
927 }
928
929 public final MutableNumber getVenomImmunity() {
930 return venomImmunity;
931 }
932
933 public Optional<ChatMessage> getChatMessage() {
934 return chatMessage;
935 }
936
937 public String getUsername() {
938 return username;
939 }
940
941 public void setMemberId(int memberId) {
942 this.memberId = memberId;
943 }
944
945 public int getMemberId() {
946 return memberId;
947 }
948
949 public Optional<GameSession> getSession() {
950 return session;
951 }
952
953 public void setSession(GameSession session) {
954 this.session = Optional.of(session);
955
956 final String host = session.getHost();
957 this.lastHost = host;
958 this.hostList.add(host);
959 }
960
961 public void setPassword(String password) {
962 this.password = password;
963 }
964
965 public String getPassword() {
966 return password;
967 }
968
969 public Appearance getAppearance() {
970 return appearance;
971 }
972
973 public Events getEvents() {
974 return events;
975 }
976
977}
static final Appearance DEFAULT_APPEARANCE
Definition Config.java:250
static final Position DEFAULT_POSITION
Definition Config.java:235
static final double COMBAT_MODIFICATION
Definition Config.java:286
static boolean disconnect(Player player, boolean logout)
static void onDeath(Player player, boolean forceRemove)
Definition LMSGame.java:671
static boolean isActivePlayer(Player player)
Definition LMSGame.java:188
static void onLogout(Player player)
Definition Pets.java:254
static void sendMessage(String... messages)
Definition World.java:433
static void schedule(Task task)
Definition World.java:284
void move(Position position)
Definition Mob.java:377
static String getDate()
Definition Utility.java:163
static long nameToLong(String text)
Definition Utility.java:222