RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
LMSGame.java
1package com.osroyale.content.lms;
2
3import com.osroyale.Config;
4import com.osroyale.content.lms.crate.LMSCrate;
5import com.osroyale.content.lms.fog.Fog;
6import com.osroyale.content.lms.loadouts.LMSLoadout;
7import com.osroyale.content.lms.loadouts.LMSLoadoutManager;
8import com.osroyale.content.lms.lobby.LMSLobby;
9import com.osroyale.content.lms.lobby.LMSLobbyEvent;
10import com.osroyale.content.lms.safezone.LMSSafezone;
11import com.osroyale.game.Animation;
12import com.osroyale.game.Graphic;
13import com.osroyale.game.world.World;
14import com.osroyale.game.world.entity.combat.hit.Hit;
15import com.osroyale.game.world.entity.combat.hit.HitIcon;
16import com.osroyale.game.world.entity.combat.hit.Hitsplat;
17import com.osroyale.game.world.entity.combat.strategy.player.special.CombatSpecial;
18import com.osroyale.game.world.entity.combat.weapon.WeaponInterface;
19import com.osroyale.game.world.entity.mob.Direction;
20import com.osroyale.game.world.entity.mob.UpdateFlag;
21import com.osroyale.game.world.entity.mob.player.Player;
22import com.osroyale.game.world.entity.mob.player.PlayerOption;
23import com.osroyale.game.world.entity.mob.player.persist.PlayerSerializer;
24import com.osroyale.game.world.entity.skill.Skill;
25import com.osroyale.game.world.items.Item;
26import com.osroyale.game.world.items.ItemDefinition;
27import com.osroyale.game.world.items.ground.GroundItem;
28import com.osroyale.game.world.object.CustomGameObject;
29import com.osroyale.game.world.position.Area;
30import com.osroyale.game.world.position.Boundary;
31import com.osroyale.game.world.position.Position;
32import com.osroyale.net.packet.out.*;
33import com.osroyale.util.StringUtils;
34import com.osroyale.util.Utility;
35
36import java.util.*;
37
74
75public class LMSGame {
76
80 public static List<Player> gamePlayers = new ArrayList<>();
81
85 public static boolean gameInProgress;
86
90 public static boolean canAttack = false;
91
95 private static Fog currentFog = new Fog(-1, -1, -1, -1);
96
97 private static int lastFogCycle;
98
102 public static int gameTicks;
103
107 public static int startingTicks;
108
112 public static int crateTicks;
113
117 public static LMSCrate lmsCrate;
118
122 private static LMSSafezone safeZone;
123
127 private static List<CustomGameObject> storedObjects = new ArrayList<>();
128
132 private static LMSLoadout currentGameType;
133
134 private static String getGameTypeName() {
135 return currentGameType.getClass().getSimpleName();
136 }
137
141 private static List<Position> possible_spawns = Arrays.asList(
142 new Position(3399, 5766, 0),
143 new Position(3409, 5784, 0),
144 new Position(3401, 5774, 0),
145 new Position(3422, 5770, 0),
146 new Position(3453, 5816, 0),
147 new Position(3441, 5812, 0),
148 new Position(3433, 5804, 0),
149 new Position(3415, 5821, 0),
150 new Position(3402, 5832, 0),
151 new Position(3400, 5851, 0),
152 new Position(3410, 5865, 0),
153 new Position(3400, 5876, 0),
154 new Position(3423, 5872, 0),
155 new Position(3439, 5875, 0),
156 new Position(3451, 5859, 0),
157 new Position(3467, 5869, 0),
158 new Position(3466, 5819, 0),
159 new Position(3480, 5810, 0),
160 new Position(3495, 5801, 0),
161 new Position(3494, 5790, 0),
162 new Position(3511, 5790, 0),
163 new Position(3505, 5771, 0),
164 new Position(3513, 5766, 0),
165 new Position(3492, 5772, 0),
166 new Position(3460, 5787, 0),
167 new Position(3468, 5788, 0),
168 new Position(3476, 5796, 0),
169 new Position(3477, 5779, 0),
170 new Position(3491, 5773, 0)
171
172 );
173
179 public static boolean inGameArea(Player player) {
180 return Boundary.isIn(player, new Boundary(3390, 5757, 3524, 5901));
181 }
182
188 public static boolean isActivePlayer(Player player) {
189 return gamePlayers != null && gamePlayers.contains(player) && inGameArea(player);
190 }
191
198 public static boolean canAttack(Player player, Player target) {
199 if (!inGameArea(player)) {
200 return false;
201 }
202
203 if (!canAttack) {
204 player.message("The game has not started yet.");
205 return false;
206 }
207
208 if (target.lmsImmunity > System.currentTimeMillis()) {
209 player.message(target.getUsername() + " has temporary immunity from being attacked!");
210 return false;
211 }
212
213 if (target.getCombat().isUnderAttack() && !target.getCombat().isUnderAttackBy(player)) {
214 if (!Area.inMulti(player) || !Area.inMulti(target)) {
215 player.send(new SendMessage(target.getName() + " is currently in combat and can not be attacked."));
216 return false;
217 }
218 }
219
220 return true;
221 }
222
229 public static void rollChest(Player player, int keyId, boolean lootCrate) {
230 if (player == null || !player.inventory.contains(keyId) && !lootCrate)
231 return;
232
233 LMSLoadout currentLoadout = currentGameType;
234
235 boolean upgradedKey = keyId == 20608;
236
237 int lootTable = Utility.random(1);
238
239 int loot = -1;
240
241 int amount = 1;
242
243 int maximumUnlocks = currentLoadout.getOffensiveItem().length + currentLoadout.getDefensiveItem().length + currentLoadout.getOffensiveItemUpgrades().length;
244
245 if (player.unlockedLMSItems.size() >= maximumUnlocks) return;
246
247 if (!upgradedKey) {
248 if (lootTable == 0)
249 loot = currentLoadout.getOffensiveItem()[Utility.random(currentLoadout.getOffensiveItem().length - 1)];
250 else if (lootTable == 1)
251 loot = currentLoadout.getDefensiveItem()[Utility.random(currentLoadout.getDefensiveItem().length - 1)];
252 } else
253 loot = currentLoadout.getOffensiveItemUpgrades()[Utility.random(currentLoadout.getOffensiveItemUpgrades().length - 1)];
254
255 //Handles duplicated items
256 if (player.unlockedLMSItems.contains(loot)) {
257 rollChest(player, keyId, lootCrate);
258 return;
259 }
260
261 player.unlockedLMSItems.add(loot);
262
263 //Add dragon arrows when its a dark bow
264 if (loot == 11235) player.unlockedLMSItems.add(11212);
265 //Add dragon javelins if its a balista
266 if (loot == 19481) player.unlockedLMSItems.add(19484);
267 //Add opal bolts e if its a arma cbow
268 //if (loot == 11785) player.unlockedLMSItems.add(8723);
269
270 if (!lootCrate) player.inventory.remove(keyId);
271
272 //Set the amount of certain items
273 if (loot == 22636 || loot == 299) amount = 1000;
274
275 giveChestItems(loot, amount, player);
276
277 if (lootCrate) {
278 player.animate(832);
279 World.sendObjectAnimation(86, lmsCrate.getLootCrate());
280 lmsCrate.destroy();
281 lmsCrate = null;
282 }
283
284 //Checks if the loot was javelins or dragon arrows
285
286 int secondary = -1;
287
288 if (loot == 11235) secondary = 11212;
289 else if(loot == 19481) secondary = 19484;
290 //else if(loot == 11785) secondary = 8723;
291
292 if(secondary != -1)
293 giveChestItems(secondary, getItemAmountForItem(secondary), player);
294 }
295
302 private static void giveChestItems(int loot, int amount, Player player) {
303 boolean space = player.inventory.getFreeSlots() > 0;
304
305 if (space) {
306 player.inventory.add(loot, amount);
307 } else
308 GroundItem.create(player, new Item(loot, amount));
309
310 player.message("You have received " + amount + "x " + ItemDefinition.get(loot).getName() + ". It has been added to " + (space ? "your inventory" : "the ground"));
311 }
312
317 public static void moveToGame(List<Player> players) {
318 currentGameType = LMSLobby.currentGameType;
319 gamePlayers.addAll(players);
320 gameInProgress = true;
321 canAttack = false;
322 start();
323
324 //Handles setting a different loadout for next game
325 LMSLoadout loadout = null;
326 do {
327 loadout = LMSLoadoutManager.getLmsLoadouts().get(Utility.random(LMSLoadoutManager.getLmsLoadouts().size()));
328 } while(!(loadout != LMSLobby.currentGameType));
329 LMSLobby.currentGameType = loadout;
330 }
331
335 private static void start() {
336 gearUpPlayers();
337 startingTicks = 10;
338 safeZone = null;
339 gameTicks = 0;
340 crateTicks = 0;
341 currentFog.reset();
342 }
343
347 private static void gearUpPlayers() {
348 List<Position> copySpawns = new ArrayList<>();
349 copySpawns.addAll(possible_spawns);
350
351 gamePlayers.stream().filter(Objects::nonNull).forEach(player -> {
352 //Turns of all the prayers
353 player.prayer.reset();
354 //Clears all unlocked items
355 player.unlockedLMSItems = new ArrayList<>();
356 //Toggles the fog on
357 player.send(new SendLMSFog(true));
358 //Sets the levels
359 setLevels(player);
360 //Gives the items & equipment
361 giveItems(player, false);
362 //Reset kills
363 player.lmsKills = 0;
364 //Pick a random spawn
365 Collections.shuffle(copySpawns);
366 int randomPick = Utility.random(copySpawns.size() - 1);
367 player.move(copySpawns.get(randomPick));
368 copySpawns.remove(randomPick);
369 });
370 }
371
377 public static void setLevels(Player player) {
378 for(int index = 0; index < currentGameType.getSkills().length; index++) {
379 int level = currentGameType.getSkills()[index];
380 Skill skill = player.skills.get(index);
381
382 skill.setLevel(level);
383 skill.setMaxLevel(level);
384 skill.setExperience(skill.getExperienceForLevel(level));
385 }
386
387 player.skills.refresh();
388 }
389
395 public static void giveItems(Player player, boolean clear) {
396 LMSLoadout loadout = currentGameType;
397
398 if(clear) {
399 player.equipment.clear();
400 player.inventory.clear();
401 player.runePouch.clear();
402 }
403
404 //Handles setting the correct spellbook
405 player.spellbook = loadout.getSpellbook();
406 player.interfaceManager.setSidebar(Config.MAGIC_TAB, player.spellbook.getInterfaceId());
407
408 //Handles setting up the inventory
409 player.inventory.set(loadout.getInventorySetup().getItems().clone());
410
411 //Handles setting up the equipment
412 player.equipment.clear();
413 player.equipment.set(loadout.getEquipmentSetup().getItems().clone());
414 player.equipment.updateAnimation();
415 WeaponInterface.execute(player, player.equipment.getWeapon());
416
417 //Handles the rune pouch
418 for(int index = 0; index < loadout.getRunePouchRunes().length; index++)
419 player.runePouch.runes.add(new Item(loadout.getRunePouchRunes()[index][0], loadout.getRunePouchRunes()[index][1]));
420
421 player.inventory.refresh();
422 player.equipment.refresh();
423 player.equipment.updateRangedEquipment();
424 player.runePouch.refresh();
425
426
427 //Call the appearance update flag
428 player.updateFlags.add(UpdateFlag.APPEARANCE);
429 }
430
435 public static void reset(Player player) {
436 player.send(new SendHintArrow(0));
437
438 player.face(Direction.SOUTH);
439 player.equipment.updateAnimation();
440 player.animate(Animation.RESET, true);
441 player.graphic(Graphic.RESET, true);
442
443 player.inventory.clear();
444 player.equipment.clear();
445 player.runePouch.clear(false);
446
447 player.inventory.set(player.inventory_copy.getItems().clone());
448
449 player.equipment.set(player.equipment_copy.getItems().clone());
450 for(int index = 0; index < player.runePouch_copy.runes.size(); index++)
451 player.runePouch.runes.add(player.runePouch_copy.runes.get(index));
452 player.equipment.updateAnimation();
453 WeaponInterface.execute(player, player.equipment.getWeapon());
454
455
456 //Handles clearing the copies of the containers
457 player.inventory_copy.clear();
458 player.equipment_copy.clear();
459 player.runePouch_copy.clear(false);
460
461 player.inventory.refresh();
462 player.equipment.refresh();
463 player.runePouch.refresh();
464
465 //Handles reseting the spellbook
466 player.spellbook = player.spellbook_copy;
467 player.interfaceManager.setSidebar(Config.MAGIC_TAB, player.spellbook.getInterfaceId());
468
469 player.prayer.reset();
470 player.send(new SendPlayerOption(PlayerOption.ATTACK, false, true));
471
472 resetLevels(player);
473 player.send(new SendLMSFog(false));
474 if (gamePlayers.contains(player))
475 gamePlayers.remove(player);
477 player.move(new Position(LMSLobby.finish.getX() + Utility.random(1), LMSLobby.finish.getY() + Utility.random(3), 0));
478 PlayerSerializer.save(player);
479 }
480
485 private static void resetLevels(Player player) {
486 for(int index = 0; index < player.skills.getSkills().length; index++) {
487 Skill skill = player.skills.get(index);
488 Skill copy_skill = player.skills_copy.get(index);
489
490 skill.setLevel(copy_skill.getLevel());
491 skill.setMaxLevel(copy_skill.getMaxLevel());
492 skill.setExperience(skill.getExperienceForLevel(copy_skill.getLevel()));
493 }
494
495 player.skills.refresh();
496 }
497
501 public static void setupSafezone() {
502 safeZone = LMSSafezone.values()[Utility.random(LMSSafezone.values().length - 1)];
503 gamePlayers.stream().forEach(player -> player.message("@red@Fog approaching. Get to the safezone at "+ StringUtils.capitalize(safeZone.name().toLowerCase().replaceAll("_", " ")+"!")));
504
505 for (int i = safeZone.boundsYSW; i < safeZone.boundsYSW + 10; i++) {
506 CustomGameObject gameObject = new CustomGameObject(34905, new Position(safeZone.boundsXSW, i));
507 gameObject.register();
508 storedObjects.add(gameObject);
509 }
510 for (int i = safeZone.boundsXSW; i < safeZone.boundsXSW + 10; i++) {
511 CustomGameObject gameObject = new CustomGameObject(34905, new Position(i, safeZone.boundsYSW));
512 gameObject.register();
513 storedObjects.add(gameObject);
514 }
515 for (int i = safeZone.boundsXNE - 10; i < safeZone.boundsXNE; i++) {
516 CustomGameObject gameObject = new CustomGameObject(34905, new Position(i, safeZone.boundsYNE));
517 gameObject.register();
518 storedObjects.add(gameObject);
519 }
520 for (int i = safeZone.boundsYNE - 10; i <= safeZone.boundsYNE; i++) {
521 CustomGameObject gameObject = new CustomGameObject(34905, new Position(safeZone.boundsXNE, i));
522 gameObject.register();
523 storedObjects.add(gameObject);
524 }
525
526 currentFog = new Fog(safeZone.boundsXSW - 100, safeZone.boundsYSW - 100, safeZone.boundsXNE + 100, safeZone.boundsYNE + 100);
528 gamePlayers.stream().forEach(player -> player.send(new SendHintArrow(new Position(safeZone.boundsXSW + 5, safeZone.boundsYSW + 5, 0), 7)));
529 }
530
535 public static void processPlayer(Player player) {
536
537 if (!isActivePlayer(player))
538 return;
539
540 handleFogDamage(player);
541 }
542
547 private static void handleFogDamage(Player player) {
548 if(safeZone == null) return;
549
550 if(safeZone.inSafeZone(player)) return;
551
552 if(!Boundary.isIn(player, new Boundary(currentFog.getLowX(), currentFog.getLowY(), currentFog.getHighX(), currentFog.getHighY()))) {
553 int distanceX = player.getPosition().getDistances(new Position(currentFog.getLowX(), currentFog.getLowY()));
554 int distanceY = player.getPosition().getDistances(new Position(currentFog.getHighX(), currentFog.getHighY()));
555
556 int damage = (distanceX > distanceY) ? distanceY / 10 : distanceX / 10;
557 if (damage <= 0)
558 damage = 1;
559
560 if (gameTicks > 600)
561 damage *= 2;
562 else if (gameTicks > 900)
563 damage *= 3;
564
565 int fogStrength = (distanceX > distanceY) ? distanceY * 3 : distanceX * 3;
566 player.lastFogSent = fogStrength;
567 player.send(new SendLMSFog(fogStrength > 155 ? 155 : fogStrength));
568 player.damage(new Hit(damage > 10 ? 10 : damage, Hitsplat.NORMAL, HitIcon.NONE, true));
569 } else if (player.lastFogSent != 0)
570 player.send(new SendLMSFog(0));
571 }
572
576 public static void handleFog() {
577 lastFogCycle++;
578 if (lastFogCycle == 10) {
579 if (currentFog == null) {
580 lastFogCycle = 0;
581 return;
582 }
583
584 if (safeZone.boundsXSW == currentFog.getLowX() && safeZone.boundsYSW == currentFog.getLowY() && safeZone.boundsXNE == currentFog.getHighX() && safeZone.boundsYNE == currentFog.getHighY()) {
585 lastFogCycle = 0;
586 return;
587 }
588
589 currentFog.decrease();
590 lastFogCycle = 0;
591 }
592 }
593
597 public static void updateInterface() {
598 gamePlayers.stream().filter(Objects::nonNull).forEach(player -> {
599 player.send(new SendString("Survivors: " + gamePlayers.size() + "/" + LMSLobby.maxPlayers, 44664));
600 player.send(new SendString("Kills: " + player.lmsKills, 44665));
601 player.send(new SendString("Fog: " + (currentFog.isSafe() ? "Safe" : "Approaching"), 44666));
602 });
603 }
604
609 public static void onKill(Player killer) {
610
611 killer.lmsImmunity = System.currentTimeMillis() + 20_000;
612 killer.runEnergy = 100;
613 CombatSpecial.restore(killer, 100);
614 killer.skills.get(Skill.HITPOINTS).modifyLevel(level -> level + 99, 0, 99);
615
616 killer.lmsKills++;
617 killer.lmsTotalKills++;
619
620 if (killer.lmsKills == 5)
621 killer.lmsPoints += 2;
622 else if (killer.lmsKills == 3)
623 killer.lmsPoints += 1;
624
625 boolean inventory = killer.inventory.getFreeSlots() > 0;
626
627 Item key = new Item(getKeyId(), 1);
628 if (inventory)
629 killer.inventory.add(key);
630 else
631 GroundItem.create(killer, key);
632
633 for(int index = 0; index < killer.inventory.getItems().length; index++) {
634 if(killer.inventory.get(index) == null) continue;
635 Item potion = killer.inventory.get(index);
636
637 ItemDefinition def = ItemDefinition.get(potion.getId());
638 if(def == null || !def.isPotion()) continue;
639
640 killer.inventory.remove(potion);
641 }
642
643 resupplyKiller(killer);
644 }
645
650 public static void resupplyKiller(Player player) {
651 LMSLoadout loadout = currentGameType;
652 for (int i = 6; i < loadout.getInventory().length; i++) {
653 int itemId = loadout.getInventory()[i];
654 if(itemId == -1) continue;
655
656 ItemDefinition def = ItemDefinition.get(itemId);
657 if(def == null || !def.isPotion()) continue;
658
659 player.inventory.add(itemId, 1);
660 }
661 player.inventory.add(385, player.inventory.getFreeSlots());
662
663 player.inventory.refresh();
664 }
665
671 public static void onDeath(Player player, boolean forceRemove) {
672 player.lmsTotalDeaths++;
673 if (!forceRemove) {
674 Player killer = (Player) player.getCombat().getDamageCache().calculateProperKiller().orElse(null);
675
676 int containerSize = player.unlockedLMSItems.size();
677 if(containerSize != 0) {
678 for (int i = 0; i < containerSize; i++) {
679 int itemId = player.unlockedLMSItems.get(i);
680 Item item = new Item(itemId, getItemAmountForItem(itemId));
681 if (killer == null)
682 GroundItem.createGlobal(player, item);
683 else
684 GroundItem.create(killer, item);
685 }
686 }
687
688 player.lmsPoints += getPointsForPlacement(gamePlayers.size());
689 player.message("You have been awarded: @red@"+getPointsForPlacement(gamePlayers.size())+" @bla@points for placing @red@#"+gamePlayers.size());
690 }
691
692 reset(player);
693
694 if(gamePlayers.size() == 1) {
695 gameInProgress = false;
696 LMSLobbyEvent.lobbyTicks = LMSLobbyEvent.defaultLobbyTime;
697 Player winner = gamePlayers.get(0);
698 winner.lmsPoints+= 5;
699 winner.lmsWins++;
700 winner.message("Congratulations! You've won the LMS Game!");
701 winner.message("You have been awarded: @red@5 points@bla@ for your win!");
702 reset(winner);
703 if (lmsCrate != null) {
704 lmsCrate.destroy();
705 lmsCrate = null;
706 }
707 for(CustomGameObject gameObject : storedObjects)
708 gameObject.unregister();
709 storedObjects.clear();
710 gamePlayers.clear();
711 }
712 }
713
719 private static int getItemAmountForItem(int loot) {
720 switch(loot){
721 case 22636:
722 case 299:
723 case 11212:
724 case 19481:
725 return 1000;
726 default:
727 return 1;
728 }
729 }
730
736 private static int getPointsForPlacement(int remaining) {
737 if (remaining == 2)
738 return 4;
739 else if (remaining == 3 || remaining == 4)
740 return 3;
741 else if (remaining >= 5 && remaining <= 9)
742 return 2;
743 else if (remaining >= 10 && remaining <= 19)
744 return 1;
745
746 return 0;
747 }
748
753 public static int getKeyId() {
754 return gamePlayers.size() <= 4 ? 20608 : 20526;
755 }
756}
static List< Player > gamePlayers
Definition LMSGame.java:80
static void onDeath(Player player, boolean forceRemove)
Definition LMSGame.java:671
static boolean inGameArea(Player player)
Definition LMSGame.java:179
static void resupplyKiller(Player player)
Definition LMSGame.java:650
static void moveToGame(List< Player > players)
Definition LMSGame.java:317
static void rollChest(Player player, int keyId, boolean lootCrate)
Definition LMSGame.java:229
static void giveItems(Player player, boolean clear)
Definition LMSGame.java:395
static void onKill(Player killer)
Definition LMSGame.java:609
static void processPlayer(Player player)
Definition LMSGame.java:535
static boolean isActivePlayer(Player player)
Definition LMSGame.java:188
static void reset(Player player)
Definition LMSGame.java:435
static void setLevels(Player player)
Definition LMSGame.java:377
static boolean canAttack(Player player, Player target)
Definition LMSGame.java:198
static void sendObjectAnimation(int animation, GameObject object)
Definition World.java:321
void move(Position position)
Definition Mob.java:377
void face(GameObject object)
Definition Mob.java:326
void modifyLevel(Function< Integer, Integer > function)
Definition Skill.java:318
static void createGlobal(Player player, Item item)
static GroundItem create(Player player, Item item)