Skip to content

Commit

Permalink
Set world level automatically on level up.
Browse files Browse the repository at this point in the history
  • Loading branch information
GanyusLeftHorn authored and Melledy committed Jun 24, 2022
1 parent f5145ef commit 3a2ebd1
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions src/main/java/emu/grasscutter/game/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,14 @@ public int getLevel() {
return this.getProperty(PlayerProperty.PROP_PLAYER_LEVEL);
}

public void setLevel(int level) {
this.setProperty(PlayerProperty.PROP_PLAYER_LEVEL, level);
this.sendPacket(new PacketPlayerPropNotify(this, PlayerProperty.PROP_PLAYER_LEVEL));

this.updateWorldLevel();
this.updateProfile();
}

public int getExp() {
return this.getProperty(PlayerProperty.PROP_PLAYER_EXP);
}
Expand All @@ -440,6 +448,8 @@ public int getWorldLevel() {
public void setWorldLevel(int level) {
this.setProperty(PlayerProperty.PROP_PLAYER_WORLD_LEVEL, level);
this.sendPacket(new PacketPlayerPropNotify(this, PlayerProperty.PROP_PLAYER_WORLD_LEVEL));

this.updateProfile();
}

public int getPrimogems() {
Expand Down Expand Up @@ -508,12 +518,7 @@ public void addExpDirectly(int gain) {
}

if (hasLeveledUp) {
// Set level property
this.setProperty(PlayerProperty.PROP_PLAYER_LEVEL, level);
// Update social status
this.updateProfile();
// Update player with packet
this.sendPacket(new PacketPlayerPropNotify(this, PlayerProperty.PROP_PLAYER_LEVEL));
this.setLevel(level);
}

// Set exp
Expand All @@ -523,6 +528,27 @@ public void addExpDirectly(int gain) {
this.sendPacket(new PacketPlayerPropNotify(this, PlayerProperty.PROP_PLAYER_EXP));
}

private void updateWorldLevel() {
int currentWorldLevel = this.getWorldLevel();
int currentLevel = this.getLevel();

int newWorldLevel =
(currentLevel >= 55) ? 8 :
(currentLevel >= 50) ? 7 :
(currentLevel >= 45) ? 6 :
(currentLevel >= 40) ? 5 :
(currentLevel >= 35) ? 4 :
(currentLevel >= 30) ? 3 :
(currentLevel >= 25) ? 2 :
(currentLevel >= 20) ? 1 :
0;

if (newWorldLevel != currentWorldLevel) {
this.getWorld().setWorldLevel(newWorldLevel);
this.setWorldLevel(newWorldLevel);
}
}

private void updateProfile() {
getProfile().syncWithCharacter(this);
}
Expand Down

0 comments on commit 3a2ebd1

Please sign in to comment.