package emu.grasscutter.command.commands; import emu.grasscutter.Grasscutter; import emu.grasscutter.command.Command; import emu.grasscutter.command.CommandHandler; import emu.grasscutter.data.GenshinData; import emu.grasscutter.data.def.AvatarData; import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.avatar.GenshinAvatar; import java.util.List; @Command(label = "givechar", usage = "givechar [level]", description = "Gives the player a specified character", aliases = {"givec"}, permission = "player.givechar") public class GiveChar implements CommandHandler { @Override public void onCommand(GenshinPlayer sender, List args) { int target, avatarId, level = 1, ascension; if (sender == null && args.size() < 2) { CommandHandler.sendMessage(null, "Usage: givechar [amount]"); return; } switch (args.size()) { default: CommandHandler.sendMessage(sender, "Usage: givechar [level]"); return; case 2: try { target = Integer.parseInt(args.get(0)); if (Grasscutter.getGameServer().getPlayerByUid(target) == null && sender != null) { target = sender.getUid(); level = Integer.parseInt(args.get(1)); avatarId = Integer.parseInt(args.get(0)); } else { avatarId = Integer.parseInt(args.get(1)); } } catch (NumberFormatException ignored) { // TODO: Parse from avatar name using GM Handbook. CommandHandler.sendMessage(sender, "Invalid avatar or player ID."); return; } break; case 3: try { target = Integer.parseInt(args.get(0)); if (Grasscutter.getGameServer().getPlayerByUid(target) == null) { CommandHandler.sendMessage(sender, "Invalid player ID."); return; } avatarId = Integer.parseInt(args.get(1)); level = Integer.parseInt(args.get(2)); } catch (NumberFormatException ignored) { // TODO: Parse from avatar name using GM Handbook. CommandHandler.sendMessage(sender, "Invalid avatar or player ID."); return; } break; } GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); if (targetPlayer == null) { CommandHandler.sendMessage(sender, "Player not found."); return; } AvatarData avatarData = GenshinData.getAvatarDataMap().get(avatarId); if (avatarData == null) { CommandHandler.sendMessage(sender, "Invalid avatar id."); return; } // Calculate ascension level. if (level <= 40) { ascension = (int) Math.ceil(level / 20f); } else { ascension = (int) Math.ceil(level / 10f) - 3; } GenshinAvatar avatar = new GenshinAvatar(avatarId); avatar.setLevel(level); avatar.setPromoteLevel(ascension); // This will handle stats and talents avatar.recalcStats(); targetPlayer.addAvatar(avatar); CommandHandler.sendMessage(sender, String.format("Given %s to %s.", avatarId, target)); } }