mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-27 08:22:52 +08:00
fb1bacb0f8
Ensures Traveler retains talent levels and constellations on inactive elements when switching elements. Relevant for any other skillDepot-changing activities like Windtrace too, though keeping those in the db might not be as useful. Refactor avatar talent upgrade and access Refactor skillExtraCharges
73 lines
2.7 KiB
Java
73 lines
2.7 KiB
Java
package emu.grasscutter.command.commands;
|
|
|
|
import emu.grasscutter.Grasscutter;
|
|
import emu.grasscutter.command.Command;
|
|
import emu.grasscutter.command.CommandHandler;
|
|
import emu.grasscutter.data.GameData;
|
|
import emu.grasscutter.data.excels.AvatarTalentData;
|
|
import emu.grasscutter.game.avatar.Avatar;
|
|
import emu.grasscutter.game.entity.EntityAvatar;
|
|
import emu.grasscutter.game.player.Player;
|
|
import emu.grasscutter.game.world.Scene;
|
|
import emu.grasscutter.game.world.World;
|
|
import emu.grasscutter.server.packet.send.*;
|
|
import emu.grasscutter.utils.Position;
|
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
@Command(
|
|
label = "setConst",
|
|
aliases = {"setconstellation"},
|
|
usage = {"<constellation level>"},
|
|
permission = "player.setconstellation",
|
|
permissionTargeted = "player.setconstellation.others")
|
|
public final class SetConstCommand implements CommandHandler {
|
|
@Override
|
|
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
|
if (args.size() < 1) {
|
|
sendUsageMessage(sender);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
int constLevel = Integer.parseInt(args.get(0));
|
|
if (constLevel < -1 || constLevel > 6) {
|
|
CommandHandler.sendTranslatedMessage(sender, "commands.setConst.range_error");
|
|
return;
|
|
}
|
|
|
|
EntityAvatar entity = targetPlayer.getTeamManager().getCurrentAvatarEntity();
|
|
if (entity == null) return;
|
|
Avatar avatar = entity.getAvatar();
|
|
|
|
this.setConstellation(targetPlayer, avatar, constLevel);
|
|
|
|
CommandHandler.sendTranslatedMessage(sender, "commands.setConst.success", avatar.getAvatarData().getName(), constLevel);
|
|
} catch (NumberFormatException ignored) {
|
|
CommandHandler.sendTranslatedMessage(sender, "commands.setConst.level_error");
|
|
}
|
|
}
|
|
|
|
private void setConstellation(Player player, Avatar avatar, int constLevel) {
|
|
int currentConstLevel = avatar.getCoreProudSkillLevel();
|
|
avatar.forceConstellationLevel(constLevel);
|
|
|
|
// force player to reload scene when necessary
|
|
if (constLevel < currentConstLevel) {
|
|
World world = player.getWorld();
|
|
Scene scene = player.getScene();
|
|
Position pos = player.getPosition();
|
|
|
|
world.transferPlayerToScene(player, 1, pos);
|
|
world.transferPlayerToScene(player, scene.getId(), pos);
|
|
scene.broadcastPacket(new PacketSceneEntityAppearNotify(player));
|
|
}
|
|
|
|
// ensure that all changes are visible to the player
|
|
avatar.recalcConstellations();
|
|
avatar.recalcStats(true);
|
|
avatar.save();
|
|
}
|
|
}
|