Commit 59a412cc authored by lactose's avatar lactose Committed by GitHub
Browse files

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 <AnimeGitB@bigblueball.in>)
parent 63fd4dfe
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 = {"<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 < 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<Integer> 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();
}
}
...@@ -256,6 +256,14 @@ ...@@ -256,6 +256,14 @@
"success": "Message sent.", "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." "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": { "setFetterLevel": {
"range_error": "Fetter level must be between 0 and 10.", "range_error": "Fetter level must be between 0 and 10.",
"success": "Fetter level set to %s.", "success": "Fetter level set to %s.",
......
...@@ -256,6 +256,14 @@ ...@@ -256,6 +256,14 @@
"success": "Mensaje enviado.", "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." "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": { "setFetterLevel": {
"range_error": "El nivel de amistad debe estar entre 0 y 10.", "range_error": "El nivel de amistad debe estar entre 0 y 10.",
"success": "Nivel de amistad establecido a %s.", "success": "Nivel de amistad establecido a %s.",
......
...@@ -256,6 +256,14 @@ ...@@ -256,6 +256,14 @@
"success": "Message envoyé.", "success": "Message envoyé.",
"description": "Envoie un message au joueur spécifié en tant que Serveur" "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": { "setFetterLevel": {
"range_error": "Le niveau d'affinité doit être compris entre 0 et 10.", "range_error": "Le niveau d'affinité doit être compris entre 0 et 10.",
"success": "Niveau d'affinité défini à %s.", "success": "Niveau d'affinité défini à %s.",
......
...@@ -256,6 +256,14 @@ ...@@ -256,6 +256,14 @@
"success": "Wiadomość wysłana.", "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." "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": { "setFetterLevel": {
"range_error": "Poziom przyjaźni musi być pomiędzy 0 a 10.", "range_error": "Poziom przyjaźni musi być pomiędzy 0 a 10.",
"success": "Poziom przyjaźni został pomyślnie ustawiony na %s.", "success": "Poziom przyjaźni został pomyślnie ustawiony na %s.",
......
...@@ -256,6 +256,14 @@ ...@@ -256,6 +256,14 @@
"success": "Mesaj trimis.", "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." "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": { "setFetterLevel": {
"range_error": "Nivelul Fetter trebuie să fie între 0 și 10.", "range_error": "Nivelul Fetter trebuie să fie între 0 și 10.",
"success": "Nivelul Fetter setat ca %s.", "success": "Nivelul Fetter setat ca %s.",
......
...@@ -256,6 +256,14 @@ ...@@ -256,6 +256,14 @@
"success": "Сообщение было отправлено.", "success": "Сообщение было отправлено.",
"description": "Отправляет сообщение выбранному игроку от имени сервера. При отсутствии конкретной цели, отправляет сообщение всем игрокам на сервере." "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": { "setFetterLevel": {
"range_error": "Значение уровня дружбы должно быть между 0 и 10.", "range_error": "Значение уровня дружбы должно быть между 0 и 10.",
"success": "Уровень дружбы стал равен %s.", "success": "Уровень дружбы стал равен %s.",
......
...@@ -256,6 +256,14 @@ ...@@ -256,6 +256,14 @@
"success": "消息已发送。", "success": "消息已发送。",
"description": "向玩家以服务器的身份发送消息。如果没有指定目标,则向服务器的全部玩家发送" "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": { "setFetterLevel": {
"range_error": "好感度等级必须在 0-10 之间。", "range_error": "好感度等级必须在 0-10 之间。",
"success": "好感度已设为 %s 级。", "success": "好感度已设为 %s 级。",
......
...@@ -256,6 +256,14 @@ ...@@ -256,6 +256,14 @@
"success": "訊息已發送。", "success": "訊息已發送。",
"description": "向指定玩家發送訊息。" "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": { "setFetterLevel": {
"range_error": "好感度必須在 0 到 10 之間。", "range_error": "好感度必須在 0 到 10 之間。",
"success": "好感等級已設定為 %s", "success": "好感等級已設定為 %s",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment