diff --git a/src/main/java/emu/grasscutter/game/inventory/Inventory.java b/src/main/java/emu/grasscutter/game/inventory/Inventory.java index 0bd888e7c..5629521c8 100644 --- a/src/main/java/emu/grasscutter/game/inventory/Inventory.java +++ b/src/main/java/emu/grasscutter/game/inventory/Inventory.java @@ -15,6 +15,7 @@ import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.avatar.AvatarStorage; import emu.grasscutter.game.avatar.GenshinAvatar; +import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam; import emu.grasscutter.server.packet.send.PacketAvatarEquipChangeNotify; import emu.grasscutter.server.packet.send.PacketStoreItemChangeNotify; @@ -187,6 +188,8 @@ public class Inventory implements Iterable { existingItem.save(); return existingItem; } + } else { + return null; } // Set ownership and save to db @@ -207,6 +210,11 @@ public class Inventory implements Iterable { private void addVirtualItem(int itemId, int count) { 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 getPlayer().addExpDirectly(count); break; diff --git a/src/main/java/emu/grasscutter/game/managers/InventoryManager.java b/src/main/java/emu/grasscutter/game/managers/InventoryManager.java index 79b3fe812..282cd2cd8 100644 --- a/src/main/java/emu/grasscutter/game/managers/InventoryManager.java +++ b/src/main/java/emu/grasscutter/game/managers/InventoryManager.java @@ -660,6 +660,19 @@ public class InventoryManager { player.getInventory().removeItem(feedItem, count); // 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 level = avatar.getLevel(); int oldLevel = level;