Properly level up characters with the character exp virtual item

This commit is contained in:
Melledy 2022-04-18 00:45:28 -07:00
parent ab343aebd4
commit 61e4491ed1
2 changed files with 21 additions and 0 deletions

View File

@ -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<GenshinItem> {
existingItem.save();
return existingItem;
}
} else {
return null;
}
// Set ownership and save to db
@ -207,6 +210,11 @@ public class Inventory implements Iterable<GenshinItem> {
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;

View File

@ -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;