Commit 61e4491e authored by Melledy's avatar Melledy
Browse files

Properly level up characters with the character exp virtual item

parent ab343aeb
...@@ -15,6 +15,7 @@ import emu.grasscutter.database.DatabaseHelper; ...@@ -15,6 +15,7 @@ import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.avatar.AvatarStorage; import emu.grasscutter.game.avatar.AvatarStorage;
import emu.grasscutter.game.avatar.GenshinAvatar; import emu.grasscutter.game.avatar.GenshinAvatar;
import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam; import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam;
import emu.grasscutter.server.packet.send.PacketAvatarEquipChangeNotify; import emu.grasscutter.server.packet.send.PacketAvatarEquipChangeNotify;
import emu.grasscutter.server.packet.send.PacketStoreItemChangeNotify; import emu.grasscutter.server.packet.send.PacketStoreItemChangeNotify;
...@@ -187,6 +188,8 @@ public class Inventory implements Iterable<GenshinItem> { ...@@ -187,6 +188,8 @@ public class Inventory implements Iterable<GenshinItem> {
existingItem.save(); existingItem.save();
return existingItem; return existingItem;
} }
} else {
return null;
} }
// Set ownership and save to db // Set ownership and save to db
...@@ -207,6 +210,11 @@ public class Inventory implements Iterable<GenshinItem> { ...@@ -207,6 +210,11 @@ public class Inventory implements Iterable<GenshinItem> {
private void addVirtualItem(int itemId, int count) { private void addVirtualItem(int itemId, int count) {
switch (itemId) { switch (itemId) {
case 101: // Character exp
for (EntityAvatar entity : getPlayer().getTeamManager().getActiveTeam()) {
getPlayer().getServer().getInventoryManager().upgradeAvatar(player, entity.getAvatar(), count);
}
break;
case 102: // Adventure exp case 102: // Adventure exp
getPlayer().addExpDirectly(count); getPlayer().addExpDirectly(count);
break; break;
......
...@@ -660,6 +660,19 @@ public class InventoryManager { ...@@ -660,6 +660,19 @@ public class InventoryManager {
player.getInventory().removeItem(feedItem, count); player.getInventory().removeItem(feedItem, count);
// Level up // Level up
upgradeAvatar(player, avatar, promoteData, expGain);
}
public void upgradeAvatar(GenshinPlayer player, GenshinAvatar avatar, int expGain) {
AvatarPromoteData promoteData = GenshinData.getAvatarPromoteData(avatar.getAvatarData().getAvatarPromoteId(), avatar.getPromoteLevel());
if (promoteData == null) {
return;
}
upgradeAvatar(player, avatar, promoteData, expGain);
}
public void upgradeAvatar(GenshinPlayer player, GenshinAvatar avatar, AvatarPromoteData promoteData, int expGain) {
int maxLevel = promoteData.getUnlockMaxLevel(); int maxLevel = promoteData.getUnlockMaxLevel();
int level = avatar.getLevel(); int level = avatar.getLevel();
int oldLevel = level; int oldLevel = level;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment