Refactor some commands and move inventory/team limits to the config

This commit is contained in:
Melledy
2022-04-19 02:22:21 -07:00
parent 7417a1b62c
commit d9fc159550
39 changed files with 116 additions and 109 deletions

View File

@@ -156,17 +156,17 @@ public class GenshinPlayer {
this.getRotation().set(0, 307, 0);
}
public int getId() {
public int getUid() {
return id;
}
public void setId(int id) {
public void setUid(int id) {
this.id = id;
}
public long getNextGuid() {
public long getNextGenshinGuid() {
long nextId = ++this.nextGuid;
return ((long) this.getId() << 32) + nextId;
return ((long) this.getUid() << 32) + nextId;
}
public Account getAccount() {
@@ -175,7 +175,7 @@ public class GenshinPlayer {
public void setAccount(Account account) {
this.account = account;
this.account.setPlayerId(getId());
this.account.setPlayerId(getUid());
}
public GameSession getSession() {
@@ -560,7 +560,7 @@ public class GenshinPlayer {
}
public void dropMessage(Object message) {
this.sendPacket(new PacketPrivateChatNotify(GenshinConstants.SERVER_CONSOLE_UID, getId(), message.toString()));
this.sendPacket(new PacketPrivateChatNotify(GenshinConstants.SERVER_CONSOLE_UID, getUid(), message.toString()));
}
/**
@@ -569,7 +569,7 @@ public class GenshinPlayer {
* @param message The message to send.
*/
public void sendMessage(GenshinPlayer sender, Object message) {
this.sendPacket(new PacketPrivateChatNotify(sender.getId(), this.getId(), message.toString()));
this.sendPacket(new PacketPrivateChatNotify(sender.getUid(), this.getUid(), message.toString()));
}
public void interactWith(int gadgetEntityId) {
@@ -614,7 +614,7 @@ public class GenshinPlayer {
public OnlinePlayerInfo getOnlinePlayerInfo() {
OnlinePlayerInfo.Builder onlineInfo = OnlinePlayerInfo.newBuilder()
.setUid(this.getId())
.setUid(this.getUid())
.setNickname(this.getNickname())
.setPlayerLevel(this.getLevel())
.setMpSettingType(this.getMpSetting())
@@ -633,7 +633,7 @@ public class GenshinPlayer {
public SocialDetail.Builder getSocialDetail() {
SocialDetail.Builder social = SocialDetail.newBuilder()
.setUid(this.getId())
.setUid(this.getUid())
.setAvatar(HeadImage.newBuilder().setAvatarId(this.getHeadImage()))
.setNickname(this.getNickname())
.setSignature(this.getSignature())
@@ -649,7 +649,7 @@ public class GenshinPlayer {
public PlayerLocationInfo getPlayerLocationInfo() {
return PlayerLocationInfo.newBuilder()
.setUid(this.getId())
.setUid(this.getUid())
.setPos(this.getPos().toProto())
.setRot(this.getRotation().toProto())
.build();
@@ -699,7 +699,7 @@ public class GenshinPlayer {
// Check if player object exists in server
// TODO - optimize
GenshinPlayer exists = this.getServer().getPlayerById(getId());
GenshinPlayer exists = this.getServer().getPlayerByUid(getUid());
if (exists != null) {
exists.getSession().close();
}

View File

@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import emu.grasscutter.GenshinConstants;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.avatar.GenshinAvatar;
public class TeamInfo {
@@ -12,7 +13,7 @@ public class TeamInfo {
public TeamInfo() {
this.name = "";
this.avatars = new ArrayList<>(GenshinConstants.MAX_AVATARS_IN_TEAM);
this.avatars = new ArrayList<>(Grasscutter.getConfig().getServerOptions().MaxAvatarsInTeam);
}
public String getName() {
@@ -36,7 +37,7 @@ public class TeamInfo {
}
public boolean addAvatar(GenshinAvatar avatar) {
if (size() >= GenshinConstants.MAX_AVATARS_IN_TEAM || contains(avatar)) {
if (size() >= Grasscutter.getConfig().getServerOptions().MaxAvatarsInTeam || contains(avatar)) {
return false;
}
@@ -56,7 +57,7 @@ public class TeamInfo {
}
public void copyFrom(TeamInfo team) {
copyFrom(team, GenshinConstants.MAX_AVATARS_IN_TEAM);
copyFrom(team, Grasscutter.getConfig().getServerOptions().MaxAvatarsInTeam);
}
public void copyFrom(TeamInfo team, int maxTeamSize) {

View File

@@ -10,6 +10,7 @@ import java.util.Set;
import dev.morphia.annotations.Transient;
import emu.grasscutter.GenshinConstants;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.def.AvatarSkillDepotData;
import emu.grasscutter.game.avatar.GenshinAvatar;
import emu.grasscutter.game.entity.EntityAvatar;
@@ -163,12 +164,13 @@ public class TeamManager {
public int getMaxTeamSize() {
if (getPlayer().isInMultiplayer()) {
int max = Grasscutter.getConfig().getServerOptions().MaxAvatarsInTeamMultiplayer;
if (getPlayer().getWorld().getHost() == this.getPlayer()) {
return Math.max(1, (int) Math.ceil(GenshinConstants.MAX_AVATARS_IN_TEAM / (double) getWorld().getPlayerCount()));
return Math.max(1, (int) Math.ceil(max / (double) getWorld().getPlayerCount()));
}
return Math.max(1, (int) Math.floor(GenshinConstants.MAX_AVATARS_IN_TEAM / (double) getWorld().getPlayerCount()));
return Math.max(1, (int) Math.floor(max / (double) getWorld().getPlayerCount()));
}
return GenshinConstants.MAX_AVATARS_IN_TEAM;
return Grasscutter.getConfig().getServerOptions().MaxAvatarsInTeam;
}
// Methods

View File

@@ -148,8 +148,8 @@ public class GenshinAvatar {
public void setOwner(GenshinPlayer player) {
this.owner = player;
this.ownerId = player.getId();
this.guid = player.getNextGuid();
this.ownerId = player.getUid();
this.guid = player.getNextGenshinGuid();
}
public int getSatiation() {

View File

@@ -107,7 +107,7 @@ public class EntityAvatar extends GenshinEntity {
public SceneAvatarInfo getSceneAvatarInfo() {
SceneAvatarInfo.Builder avatarInfo = SceneAvatarInfo.newBuilder()
.setPlayerId(this.getPlayer().getId())
.setPlayerId(this.getPlayer().getUid())
.setAvatarId(this.getAvatar().getAvatarId())
.setGuid(this.getAvatar().getGuid())
.setPeerId(this.getPlayer().getPeerId())

View File

@@ -36,7 +36,7 @@ public class EntityItem extends EntityGadget {
this.id = getScene().getWorld().getNextEntityId(EntityIdType.GADGET);
this.pos = new Position(pos);
this.rot = new Position();
this.guid = player.getNextGuid();
this.guid = player.getNextGenshinGuid();
this.item = new GenshinItem(itemData, count);
}

View File

@@ -79,11 +79,11 @@ public class FriendsList {
}
// Make sure asker cant do anything
if (myFriendship.getAskerId() == this.getPlayer().getId()) {
if (myFriendship.getAskerId() == this.getPlayer().getUid()) {
return;
}
GenshinPlayer target = getPlayer().getSession().getServer().forceGetPlayerById(targetUid);
GenshinPlayer target = getPlayer().getSession().getServer().getPlayerByUid(targetUid, true);
if (target == null) {
return; // Should never happen
}
@@ -91,7 +91,7 @@ public class FriendsList {
// Get target's friendship
Friendship theirFriendship = null;
if (target.isOnline()) {
theirFriendship = target.getFriendsList().getPendingFriendById(this.getPlayer().getId());
theirFriendship = target.getFriendsList().getPendingFriendById(this.getPlayer().getUid());
} else {
theirFriendship = DatabaseHelper.getReverseFriendship(myFriendship);
}
@@ -112,7 +112,7 @@ public class FriendsList {
this.addFriend(myFriendship);
if (target.isOnline()) {
target.getFriendsList().getPendingFriends().remove(this.getPlayer().getId());
target.getFriendsList().getPendingFriends().remove(this.getPlayer().getUid());
target.getFriendsList().addFriend(theirFriendship);
}
@@ -124,7 +124,7 @@ public class FriendsList {
myFriendship.delete();
// Delete from target uid
if (target.isOnline()) {
theirFriendship = target.getFriendsList().getPendingFriendById(this.getPlayer().getId());
theirFriendship = target.getFriendsList().getPendingFriendById(this.getPlayer().getUid());
}
theirFriendship.delete();
}
@@ -146,7 +146,7 @@ public class FriendsList {
GenshinPlayer friend = myFriendship.getFriendProfile().getPlayer();
if (friend != null) {
// Friend online
theirFriendship = friend.getFriendsList().getFriendById(this.getPlayer().getId());
theirFriendship = friend.getFriendsList().getFriendById(this.getPlayer().getUid());
if (theirFriendship != null) {
friend.getFriendsList().getFriends().remove(theirFriendship.getFriendId());
theirFriendship.delete();
@@ -165,7 +165,7 @@ public class FriendsList {
}
public synchronized void sendFriendRequest(int targetUid) {
GenshinPlayer target = getPlayer().getSession().getServer().forceGetPlayerById(targetUid);
GenshinPlayer target = getPlayer().getSession().getServer().getPlayerByUid(targetUid, true);
if (target == null || target == this.getPlayer()) {
return;
@@ -220,14 +220,14 @@ public class FriendsList {
friendship.setOwner(getPlayer());
// Check if friend is online
GenshinPlayer friend = getPlayer().getSession().getServer().getPlayerById(friendship.getFriendProfile().getId());
GenshinPlayer friend = getPlayer().getSession().getServer().getPlayerByUid(friendship.getFriendProfile().getId());
if (friend != null) {
// Set friend to online mode
friendship.setFriendProfile(friend);
// Update our status on friend's client if theyre online
if (friend.getFriendsList().hasLoaded()) {
Friendship theirFriendship = friend.getFriendsList().getFriendshipById(getPlayer().getId());
Friendship theirFriendship = friend.getFriendsList().getFriendshipById(getPlayer().getUid());
if (theirFriendship != null) {
// Update friend profile
theirFriendship.setFriendProfile(getPlayer());

View File

@@ -27,10 +27,10 @@ public class Friendship {
public Friendship(GenshinPlayer owner, GenshinPlayer friend, GenshinPlayer asker) {
this.setOwner(owner);
this.ownerId = owner.getId();
this.friendId = friend.getId();
this.ownerId = owner.getUid();
this.friendId = friend.getUid();
this.profile = friend.getProfile();
this.askerId = asker.getId();
this.askerId = asker.getUid();
}
public GenshinPlayer getOwner() {
@@ -70,7 +70,7 @@ public class Friendship {
}
public void setFriendProfile(GenshinPlayer character) {
if (character == null || this.friendId != character.getId()) return;
if (character == null || this.friendId != character.getUid()) return;
this.profile = character.getProfile();
}

View File

@@ -22,7 +22,7 @@ public class PlayerProfile {
public PlayerProfile() { }
public PlayerProfile(GenshinPlayer player) {
this.id = player.getId();
this.id = player.getUid();
this.syncWithCharacter(player);
}

View File

@@ -125,8 +125,8 @@ public class GenshinItem {
}
public void setOwner(GenshinPlayer player) {
this.ownerId = player.getId();
this.guid = player.getNextGuid();
this.ownerId = player.getUid();
this.guid = player.getNextGenshinGuid();
}
public int getItemId() {
return itemId;

View File

@@ -6,6 +6,7 @@ import java.util.LinkedList;
import java.util.List;
import emu.grasscutter.GenshinConstants;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GenshinData;
import emu.grasscutter.data.def.AvatarCostumeData;
import emu.grasscutter.data.def.AvatarData;
@@ -36,10 +37,10 @@ public class Inventory implements Iterable<GenshinItem> {
this.store = new Long2ObjectOpenHashMap<>();
this.inventoryTypes = new Int2ObjectOpenHashMap<>();
this.createInventoryTab(ItemType.ITEM_WEAPON, new EquipInventoryTab(GenshinConstants.LIMIT_WEAPON));
this.createInventoryTab(ItemType.ITEM_RELIQUARY, new EquipInventoryTab(GenshinConstants.LIMIT_RELIC));
this.createInventoryTab(ItemType.ITEM_MATERIAL, new MaterialInventoryTab(GenshinConstants.LIMIT_MATERIAL));
this.createInventoryTab(ItemType.ITEM_FURNITURE, new MaterialInventoryTab(GenshinConstants.LIMIT_FURNITURE));
this.createInventoryTab(ItemType.ITEM_WEAPON, new EquipInventoryTab(Grasscutter.getConfig().getServerOptions().InventoryLimitWeapon));
this.createInventoryTab(ItemType.ITEM_RELIQUARY, new EquipInventoryTab(Grasscutter.getConfig().getServerOptions().InventoryLimitRelic));
this.createInventoryTab(ItemType.ITEM_MATERIAL, new MaterialInventoryTab(Grasscutter.getConfig().getServerOptions().InventoryLimitMaterial));
this.createInventoryTab(ItemType.ITEM_FURNITURE, new MaterialInventoryTab(Grasscutter.getConfig().getServerOptions().InventoryLimitFurniture));
}
public GenshinPlayer getPlayer() {

View File

@@ -36,14 +36,14 @@ public class ChatManager {
}
// Get target
GenshinPlayer target = getServer().getPlayerById(targetUid);
GenshinPlayer target = getServer().getPlayerByUid(targetUid);
if (target == null) {
return;
}
// Create chat packet
GenshinPacket packet = new PacketPrivateChatNotify(player.getId(), target.getId(), message);
GenshinPacket packet = new PacketPrivateChatNotify(player.getUid(), target.getUid(), message);
player.sendPacket(packet);
target.sendPacket(packet);
@@ -51,14 +51,14 @@ public class ChatManager {
public void sendPrivateMessage(GenshinPlayer player, int targetUid, int emote) {
// Get target
GenshinPlayer target = getServer().getPlayerById(targetUid);
GenshinPlayer target = getServer().getPlayerByUid(targetUid);
if (target == null) {
return;
}
// Create chat packet
GenshinPacket packet = new PacketPrivateChatNotify(player.getId(), target.getId(), emote);
GenshinPacket packet = new PacketPrivateChatNotify(player.getUid(), target.getUid(), emote);
player.sendPacket(packet);
target.sendPacket(packet);

View File

@@ -24,7 +24,7 @@ public class MultiplayerManager {
}
public void applyEnterMp(GenshinPlayer player, int targetUid) {
GenshinPlayer target = getServer().getPlayerById(targetUid);
GenshinPlayer target = getServer().getPlayerByUid(targetUid);
if (target == null) {
player.sendPacket(new PacketPlayerApplyEnterMpResultNotify(targetUid, "", false, PlayerApplyEnterMpReason.PlayerCannotEnterMp));
return;
@@ -43,7 +43,7 @@ public class MultiplayerManager {
*/
// Get request
CoopRequest request = target.getCoopRequests().get(player.getId());
CoopRequest request = target.getCoopRequests().get(player.getUid());
if (request != null && !request.isExpired()) {
// Join request already exists
@@ -52,7 +52,7 @@ public class MultiplayerManager {
// Put request in
request = new CoopRequest(player);
target.getCoopRequests().put(player.getId(), request);
target.getCoopRequests().put(player.getUid(), request);
// Packet
target.sendPacket(new PacketPlayerApplyEnterMpNotify(player));
@@ -137,7 +137,7 @@ public class MultiplayerManager {
}
// Get victim and sanity checks
GenshinPlayer victim = player.getServer().getPlayerById(targetUid);
GenshinPlayer victim = player.getServer().getPlayerByUid(targetUid);
if (victim == null || victim == player) {
return false;