From 59a412cc83b2ea157e522a552b7a59725869cacd Mon Sep 17 00:00:00 2001 From: lactose <15185244+juuyokka@users.noreply.github.com> Date: Mon, 25 Jul 2022 23:14:17 -0800 Subject: [PATCH] Set Constellation Command (#1565) Original commits: * create `SetConstCommand` class and translations * (partially) functional `setconst` command * fixed punctuation * added success message * implemented `SetConstCommand` * added translation keys * update keys * refactor + automatic reload * Nitpick (Co-authored-by: AnimeGitB ) --- .../command/commands/SetConstCommand.java | 85 +++++++++++++++++++ src/main/resources/languages/en-US.json | 8 ++ src/main/resources/languages/es-ES.json | 8 ++ src/main/resources/languages/fr-FR.json | 8 ++ src/main/resources/languages/pl-PL.json | 8 ++ src/main/resources/languages/ro-RO.json | 8 ++ src/main/resources/languages/ru-RU.json | 8 ++ src/main/resources/languages/zh-CN.json | 8 ++ src/main/resources/languages/zh-TW.json | 8 ++ 9 files changed, 149 insertions(+) create mode 100644 src/main/java/emu/grasscutter/command/commands/SetConstCommand.java diff --git a/src/main/java/emu/grasscutter/command/commands/SetConstCommand.java b/src/main/java/emu/grasscutter/command/commands/SetConstCommand.java new file mode 100644 index 000000000..dfdb1169d --- /dev/null +++ b/src/main/java/emu/grasscutter/command/commands/SetConstCommand.java @@ -0,0 +1,85 @@ +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; +import java.util.Set; + +@Command( + label = "setConst", + aliases = {"setconstellation"}, + usage = {""}, + permission = "player.setconstellation", + permissionTargeted = "player.setconstellation.others") +public final class SetConstCommand implements CommandHandler { + @Override + public void execute(Player sender, Player targetPlayer, List args) { + if (args.size() < 1) { + sendUsageMessage(sender); + return; + } + + try { + int constLevel = Integer.parseInt(args.get(0)); + if (constLevel < 0 || 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(); + IntArrayList talentIds = new IntArrayList(avatar.getSkillDepot().getTalents()); + Set talentIdList = avatar.getTalentIdList(); + + talentIdList.clear(); + avatar.setCoreProudSkillLevel(0); + + for(int talent = 0; talent < constLevel; talent++) { + AvatarTalentData talentData = GameData.getAvatarTalentDataMap().get(talentIds.getInt(talent)); + int mainCostItemId = talentData.getMainCostItemId(); + + player.getInventory().addItem(mainCostItemId); + Grasscutter.getGameServer().getInventorySystem().unlockAvatarConstellation(player, avatar.getGuid()); + } + + // 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(); + } +} diff --git a/src/main/resources/languages/en-US.json b/src/main/resources/languages/en-US.json index d3aca0349..c1b9a6d24 100644 --- a/src/main/resources/languages/en-US.json +++ b/src/main/resources/languages/en-US.json @@ -256,6 +256,14 @@ "success": "Message sent.", "description": "Sends a message to a player as the server. If used with no target, sends to all players on the server." }, + "setConst": { + "range_error": "Constellation level must be between 0 and 6.", + "level_error": "Invalid constellation level.", + "fail": "Failed to set constellation.", + "failed_success": "Constellations for %s have been set to %s. Please reload scene to see changes.", + "success": "Constellations for %s have been set to %s.", + "description": "Sets constellation level for your current active character" + }, "setFetterLevel": { "range_error": "Fetter level must be between 0 and 10.", "success": "Fetter level set to %s.", diff --git a/src/main/resources/languages/es-ES.json b/src/main/resources/languages/es-ES.json index 11cde5c67..e32edc8af 100644 --- a/src/main/resources/languages/es-ES.json +++ b/src/main/resources/languages/es-ES.json @@ -256,6 +256,14 @@ "success": "Mensaje enviado.", "description": "Envía un mensaje a un jugador como servidor. Si se usa sin un objetivo fijado, lo envía a todos los jugadores del servidor." }, + "setConst": { + "range_error": "Constellation level must be between 0 and 6.", + "level_error": "Invalid constellation level.", + "fail": "Failed to set constellation.", + "failed_success": "Constellations for %s have been set to %s. Please reload scene to see changes.", + "success": "Constellations for %s have been set to %s.", + "description": "Sets constellation level for your current active character" + }, "setFetterLevel": { "range_error": "El nivel de amistad debe estar entre 0 y 10.", "success": "Nivel de amistad establecido a %s.", diff --git a/src/main/resources/languages/fr-FR.json b/src/main/resources/languages/fr-FR.json index 58d2b6a2b..094a73ab7 100644 --- a/src/main/resources/languages/fr-FR.json +++ b/src/main/resources/languages/fr-FR.json @@ -256,6 +256,14 @@ "success": "Message envoyé.", "description": "Envoie un message au joueur spécifié en tant que Serveur" }, + "setConst": { + "range_error": "Constellation level must be between 0 and 6.", + "level_error": "Invalid constellation level.", + "fail": "Failed to set constellation.", + "failed_success": "Constellations for %s have been set to %s. Please reload scene to see changes.", + "success": "Constellations for %s have been set to %s.", + "description": "Sets constellation level for your current active character" + }, "setFetterLevel": { "range_error": "Le niveau d'affinité doit être compris entre 0 et 10.", "success": "Niveau d'affinité défini à %s.", diff --git a/src/main/resources/languages/pl-PL.json b/src/main/resources/languages/pl-PL.json index 99949c0f7..ac89069b3 100644 --- a/src/main/resources/languages/pl-PL.json +++ b/src/main/resources/languages/pl-PL.json @@ -256,6 +256,14 @@ "success": "Wiadomość wysłana.", "description": "Wyślij wiadomość do gracza jako serwer. Jeśli nie określono celu, wysyła do wszystkich graczy na serwerze." }, + "setConst": { + "range_error": "Constellation level must be between 0 and 6.", + "level_error": "Invalid constellation level.", + "fail": "Failed to set constellation.", + "failed_success": "Constellations for %s have been set to %s. Please reload scene to see changes.", + "success": "Constellations for %s have been set to %s.", + "description": "Sets constellation level for your current active character" + }, "setFetterLevel": { "range_error": "Poziom przyjaźni musi być pomiędzy 0 a 10.", "success": "Poziom przyjaźni został pomyślnie ustawiony na %s.", diff --git a/src/main/resources/languages/ro-RO.json b/src/main/resources/languages/ro-RO.json index 9bcff519e..c0226496c 100644 --- a/src/main/resources/languages/ro-RO.json +++ b/src/main/resources/languages/ro-RO.json @@ -256,6 +256,14 @@ "success": "Mesaj trimis.", "description": "Trimite un mesaj unui jucător în calitate de server. Dacă este utilizat fără țintă, trimite mesajul către toți jucătorii de pe server." }, + "setConst": { + "range_error": "Constellation level must be between 0 and 6.", + "level_error": "Invalid constellation level.", + "fail": "Failed to set constellation.", + "failed_success": "Constellations for %s have been set to %s. Please reload scene to see changes.", + "success": "Constellations for %s have been set to %s.", + "description": "Sets constellation level for your current active character" + }, "setFetterLevel": { "range_error": "Nivelul Fetter trebuie să fie între 0 și 10.", "success": "Nivelul Fetter setat ca %s.", diff --git a/src/main/resources/languages/ru-RU.json b/src/main/resources/languages/ru-RU.json index 9cd67ac49..328499f62 100644 --- a/src/main/resources/languages/ru-RU.json +++ b/src/main/resources/languages/ru-RU.json @@ -256,6 +256,14 @@ "success": "Сообщение было отправлено.", "description": "Отправляет сообщение выбранному игроку от имени сервера. При отсутствии конкретной цели, отправляет сообщение всем игрокам на сервере." }, + "setConst": { + "range_error": "Constellation level must be between 0 and 6.", + "level_error": "Invalid constellation level.", + "fail": "Failed to set constellation.", + "failed_success": "Constellations for %s have been set to %s. Please reload scene to see changes.", + "success": "Constellations for %s have been set to %s.", + "description": "Sets constellation level for your current active character" + }, "setFetterLevel": { "range_error": "Значение уровня дружбы должно быть между 0 и 10.", "success": "Уровень дружбы стал равен %s.", diff --git a/src/main/resources/languages/zh-CN.json b/src/main/resources/languages/zh-CN.json index 7980a06bd..a46c023bf 100644 --- a/src/main/resources/languages/zh-CN.json +++ b/src/main/resources/languages/zh-CN.json @@ -256,6 +256,14 @@ "success": "消息已发送。", "description": "向玩家以服务器的身份发送消息。如果没有指定目标,则向服务器的全部玩家发送" }, + "setConst": { + "range_error": "Constellation level must be between 0 and 6.", + "level_error": "Invalid constellation level.", + "fail": "Failed to set constellation.", + "failed_success": "Constellations for %s have been set to %s. Please reload scene to see changes.", + "success": "Constellations for %s have been set to %s.", + "description": "Sets constellation level for your current active character" + }, "setFetterLevel": { "range_error": "好感度等级必须在 0-10 之间。", "success": "好感度已设为 %s 级。", diff --git a/src/main/resources/languages/zh-TW.json b/src/main/resources/languages/zh-TW.json index 7abaa56af..f44dd3c65 100644 --- a/src/main/resources/languages/zh-TW.json +++ b/src/main/resources/languages/zh-TW.json @@ -256,6 +256,14 @@ "success": "訊息已發送。", "description": "向指定玩家發送訊息。" }, + "setConst": { + "range_error": "Constellation level must be between 0 and 6.", + "level_error": "Invalid constellation level.", + "fail": "Failed to set constellation.", + "failed_success": "Constellations for %s have been set to %s. Please reload scene to see changes.", + "success": "Constellations for %s have been set to %s.", + "description": "Sets constellation level for your current active character" + }, "setFetterLevel": { "range_error": "好感度必須在 0 到 10 之間。", "success": "好感等級已設定為 %s",