RuneHive-Game
Loading...
Searching...
No Matches
LMSLobby.java
Go to the documentation of this file.
1package com.runehive.content.lms.lobby;
2
3import com.runehive.content.lms.LMSGame;
4import com.runehive.content.lms.loadouts.LMSLoadout;
5import com.runehive.game.world.entity.combat.weapon.WeaponInterface;
6import com.runehive.game.world.entity.mob.UpdateFlag;
7import com.runehive.game.world.entity.mob.player.Player;
8import com.runehive.game.world.entity.skill.Skill;
9import com.runehive.game.world.items.Item;
10import com.runehive.game.world.position.Position;
11import com.runehive.util.Utility;
12
13import java.util.ArrayList;
14import java.util.List;
15
16public class LMSLobby {
17
18 public static boolean DEVELOPMENT_MODE = false;
19
20 /**
21 * The position the player gets put on when finishing a game
22 */
23 public static Position finish = new Position(3141, 3634, 0);
24
25 /**
26 * A list with all the players in the lobby
27 */
28 public static List<Player> lobbyMembers = new ArrayList<>();
29
30 /**
31 * The amount of players in the lobby required
32 */
33 public static int requiredPlayers = DEVELOPMENT_MODE ? 2 : 4;
34
35 /**
36 * The max amount of players allowed in a single game
37 */
38 public static int maxPlayers = 24;
39
40 /**
41 * The current game type
42 */
44
45 public static String getGameTypeName() {
46 return currentGameType.getClass().getSimpleName();
47 }
48
49 /**
50 * Handles joining the lobby
51 * @param player
52 */
53 public static void joinLobby(Player player) {
54
55 if(lobbyMembers.size() >= maxPlayers) {
56 //TODO: Make a dialogue
57 return;
58 }
59
60 if (LMSGame.isActivePlayer(player)) return;
61
62 if (player.pet != null) {
63 //TODO: Make a dialogue
64 return;
65 }
66
67 if(!lobbyMembers.contains(player))
68 lobbyMembers.add(player);
69
70 player.move(player.getPosition().north());
71
73 player.message("A game is currently on-going and should end shortly.");
74
75 //Handles making a copy of the spellbook
76 player.spellbook_copy = player.spellbook;
77
78 //Handles making a copy of the inventory
79 player.inventory_copy.set(player.inventory.getItems().clone());
80 player.inventory.clear();
81 player.inventory.refresh();
82
83 //Handles making a copy of the equipment
84 player.equipment_copy.set(player.equipment.getItems().clone());
85 player.equipment.clear();
86 player.equipment.refresh();
89
90 //Handles making a copy of the rune pouch
91 player.runePouch_copy.clear(false);
92 for(Item rune : player.runePouch.runes)
93 player.runePouch_copy.runes.add(new Item(rune.getId(), rune.getAmount()));
94 player.runePouch.clear(false);
95
96 //Handles making a copy of the skills
97 for(int index = 0; index < player.skills.getSkills().length; index++) {
98 Skill skill = player.skills_copy.get(index);
99 Skill real_skill = player.skills.get(index);
100
101 skill.setLevel(real_skill.getLevel());
102 skill.setMaxLevel(real_skill.getMaxLevel());
103 skill.setExperience(skill.getExperienceForLevel(real_skill.getLevel()));
104 }
105 player.skills_copy.experienceCounter = player.skills.experienceCounter;
106
108 }
109
110 /**
111 * Handles leaving the lobby
112 * @param player
113 */
114 public static void leaveLobby(Player player, boolean logout) {
115 lobbyMembers.remove(player);
116
117 //Sets back the players old inventory
118 player.inventory.set(player.inventory_copy.getItems().clone());
119 player.inventory_copy.clear();
120 player.inventory.refresh();
121
122 //Sets back the players old equipment
123 player.equipment.set(player.equipment_copy.getItems().clone());
124 player.equipment_copy.clear();
125 player.equipment.refresh();
126 player.equipment.updateAnimation();
127 WeaponInterface.execute(player, player.equipment.getWeapon());
128
129 //Sets back the old rune pouch
130 player.runePouch.clear();
131 for(Item rune : player.runePouch_copy.runes)
132 player.runePouch.runes.add(new Item(rune.getId(), rune.getAmount()));
133 player.runePouch_copy.clear(false);
134
136
137 if(logout)
138 player.move(new Position(finish.getX() + Utility.random(1), finish.getY() + Utility.random(3), 0));
139 else {
140 int diffX = player.getPosition().getX() >= 3142 ? 3142 - player.getPosition().getX() : 3141 - player.getPosition().getX();
141 int diffY = 3638 - player.getPosition().getY();
142 player.move(player.getPosition().copy().transform(diffX, diffY, 0));
143 }
144 }
145}
static boolean isActivePlayer(Player player)
Checks if a player is a active player within the LMS game.
Definition LMSGame.java:151
static boolean gameInProgress
Checks if there is currently a game in progress.
Definition LMSGame.java:48
static int maxPlayers
The max amount of players allowed in a single game.
Definition LMSLobby.java:38
static List< Player > lobbyMembers
A list with all the players in the lobby.
Definition LMSLobby.java:28
static void joinLobby(Player player)
Handles joining the lobby.
Definition LMSLobby.java:53
static LMSLoadout currentGameType
The current game type.
Definition LMSLobby.java:43
static Position finish
The position the player gets put on when finishing a game.
Definition LMSLobby.java:23
static int requiredPlayers
The amount of players in the lobby required.
Definition LMSLobby.java:33
static void leaveLobby(Player player, boolean logout)
Handles leaving the lobby.
List< Item > runes
The runes stores in the rune pouch;.
final EnumSet< UpdateFlag > updateFlags
Definition Mob.java:94
final SkillManager skills_copy
Definition Mob.java:97
void move(Position position)
Moves the mob to a set position.
Definition Mob.java:340
This class represents a character controlled by a player.
Definition Player.java:125
Represents a trainable and usable skill.
Definition Skill.java:18
int getLevel()
Gets the current skill level.
Definition Skill.java:205
int getMaxLevel()
Gets the maximum skill level.
Definition Skill.java:214
double experienceCounter
The experience counter.
Skill[] getSkills()
Gets the skills of the mob.
Skill get(int id)
Gets the skill for an id.
The container class that represents an item that can be interacted with.
Definition Item.java:21
final int getId()
Gets the identification of this item.
Definition Item.java:324
final int getAmount()
Gets the quantity of this item.
Definition Item.java:342
void clear()
Removes all of the items from this container.
void clear()
Removes all of the items from this container.
void refresh()
Forces a refresh of Equipment items to the EQUIPMENT_DISPLAY_ID widget.
void refresh()
Refreshes the players inventory.
Represents a single tile on the game world.
Definition Position.java:14
int getY()
Gets the absolute y coordinate.
Definition Position.java:46
int getX()
Gets the absolute x coordinate.
Definition Position.java:41
Position transform(int diffX, int diffY, int diffZ)
Creates a new location based on this location.
Position copy()
Creates a deep copy of this location.
Handles miscellaneous methods.
Definition Utility.java:27
static int random(int bound)
Definition Utility.java:239
The enumerated type whose elements represent the weapon interfaces.
static void execute(Player player, Item item)
The method executed when weapon item is equipped or unequipped that assigns a weapon interface to pla...