Unverified Commit 5b6698f5 authored by natsu's avatar natsu Committed by GitHub
Browse files

Extend setConstCommand "all" (#1884)



* Extend give command "talent"

* Update src/main/java/emu/grasscutter/data/excels/AvatarSkillDepotData.java

Shorten IntStream for getCombatSkills
Co-authored-by: default avatarLuke H-W <Birdulon@users.noreply.github.com>

* Fix setSkillLevel to work during avatar construction
Shortening getCombatSkills

* changeSkillLevel now acts as intermediate operation to fetch skillIds

* setSkillLevel changes to allow out of range levels to be normalized

* Update src/main/java/emu/grasscutter/command/commands/GiveCommand.java

Removing recalcStats since it's redundant
Co-authored-by: default avatarLuke H-W <Birdulon@users.noreply.github.com>

* Major changes and cleanup:
- AvatarSkillDepotData: removed getCombatSkills since it's unused
- TalentCommand: shortened /talent all using getSkillsAndEnergySkill
- GiveCommand: changed changeSkillLevel to setSkillLevel
- Avatar: delete changeSkillLevel and moved the operation inside setSkillLevel,updated skillId to Integer to catch special cases from GiveCommand

* Small cleanup:
Removed the special case from Avatar to be handled inside of GiveCommand

* Added "all" parameter to SetConst

* Changed all to [all] int SetConstCommand usage
Co-authored-by: default avatarLuke H-W <Birdulon@users.noreply.github.com>
Co-authored-by: default avatarLuke H-W <Birdulon@users.noreply.github.com>
parent 496cd671
package emu.grasscutter.command.commands; package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; 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.avatar.Avatar;
import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
...@@ -12,14 +9,13 @@ import emu.grasscutter.game.world.Scene; ...@@ -12,14 +9,13 @@ import emu.grasscutter.game.world.Scene;
import emu.grasscutter.game.world.World; import emu.grasscutter.game.world.World;
import emu.grasscutter.server.packet.send.*; import emu.grasscutter.server.packet.send.*;
import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Position;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import java.util.List; import java.util.List;
@Command( @Command(
label = "setConst", label = "setConst",
aliases = {"setconstellation"}, aliases = {"setconstellation"},
usage = {"<constellation level>"}, usage = {"<constellation level> [all]"},
permission = "player.setconstellation", permission = "player.setconstellation",
permissionTargeted = "player.setconstellation.others") permissionTargeted = "player.setconstellation.others")
public final class SetConstCommand implements CommandHandler { public final class SetConstCommand implements CommandHandler {
...@@ -29,21 +25,28 @@ public final class SetConstCommand implements CommandHandler { ...@@ -29,21 +25,28 @@ public final class SetConstCommand implements CommandHandler {
sendUsageMessage(sender); sendUsageMessage(sender);
return; return;
} }
try { try {
int constLevel = Integer.parseInt(args.get(0)); int constLevel = Integer.parseInt(args.get(0));
// Check if level is out of range
if (constLevel < -1 || constLevel > 6) { if (constLevel < -1 || constLevel > 6) {
CommandHandler.sendTranslatedMessage(sender, "commands.setConst.range_error"); CommandHandler.sendTranslatedMessage(sender, "commands.setConst.range_error");
return; return;
} }
// If it's either empty or anything else other than "all" just do normal setConstellation
EntityAvatar entity = targetPlayer.getTeamManager().getCurrentAvatarEntity(); if (args.size() == 1) {
if (entity == null) return; EntityAvatar entity = targetPlayer.getTeamManager().getCurrentAvatarEntity();
Avatar avatar = entity.getAvatar(); if (entity == null) return;
Avatar avatar = entity.getAvatar();
this.setConstellation(targetPlayer, avatar, constLevel); this.setConstellation(targetPlayer, avatar, constLevel);
CommandHandler.sendTranslatedMessage(sender, "commands.setConst.success", avatar.getAvatarData().getName(), constLevel);
CommandHandler.sendTranslatedMessage(sender, "commands.setConst.success", avatar.getAvatarData().getName(), constLevel); return;
}
// Check if there's an additional argument which is "all", if it does then go setAllConstellation
if (args.size() > 1 && args.get(1).equalsIgnoreCase("all")) {
this.setAllConstellation(targetPlayer, constLevel);
CommandHandler.sendTranslatedMessage(sender, "commands.setConst.successall", constLevel);
}
else sendUsageMessage(sender);
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendTranslatedMessage(sender, "commands.setConst.level_error"); CommandHandler.sendTranslatedMessage(sender, "commands.setConst.level_error");
} }
...@@ -55,13 +58,7 @@ public final class SetConstCommand implements CommandHandler { ...@@ -55,13 +58,7 @@ public final class SetConstCommand implements CommandHandler {
// force player to reload scene when necessary // force player to reload scene when necessary
if (constLevel < currentConstLevel) { if (constLevel < currentConstLevel) {
World world = player.getWorld(); this.reloadScene(player);
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 // ensure that all changes are visible to the player
...@@ -69,4 +66,24 @@ public final class SetConstCommand implements CommandHandler { ...@@ -69,4 +66,24 @@ public final class SetConstCommand implements CommandHandler {
avatar.recalcStats(true); avatar.recalcStats(true);
avatar.save(); avatar.save();
} }
private void setAllConstellation(Player player, int constLevel) {
player.getAvatars().forEach(avatar -> {
avatar.forceConstellationLevel(constLevel);
avatar.recalcConstellations();
avatar.recalcStats(true);
avatar.save();
});
// Just reload scene once, shorter than having to check for each constLevel < currentConstLevel
this.reloadScene(player);
}
private void reloadScene(Player player) {
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));
}
} }
...@@ -264,6 +264,7 @@ ...@@ -264,6 +264,7 @@
"fail": "Failed to set constellation.", "fail": "Failed to set constellation.",
"failed_success": "Constellations for %s have been set to %s. Please reload scene to see changes.", "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.", "success": "Constellations for %s have been set to %s.",
"successall": "Constellations for all characters have been set to %s.",
"description": "Sets constellation level for your current active character" "description": "Sets constellation level for your current active character"
}, },
"setFetterLevel": { "setFetterLevel": {
......
...@@ -264,6 +264,7 @@ ...@@ -264,6 +264,7 @@
"fail": "Error al establecer la constelación.", "fail": "Error al establecer la constelación.",
"failed_success": "Las constelaciones de %s han sido establecidas a %s. Por favor reinicia el escenario para ver los cambios.", "failed_success": "Las constelaciones de %s han sido establecidas a %s. Por favor reinicia el escenario para ver los cambios.",
"success": "Las constelaciones de %s han sido establecidas a %s.", "success": "Las constelaciones de %s han sido establecidas a %s.",
"successall": "🇺🇸Constellations for all characters have been set to %s.",
"description": "Establece el nivel de constelación para tu personaje actual" "description": "Establece el nivel de constelación para tu personaje actual"
}, },
"setFetterLevel": { "setFetterLevel": {
......
...@@ -264,6 +264,7 @@ ...@@ -264,6 +264,7 @@
"fail": "🇺🇸Failed to set constellation.", "fail": "🇺🇸Failed to set constellation.",
"failed_success": "🇺🇸Constellations for %s have been set to %s. Please reload scene to see changes.", "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.", "success": "🇺🇸Constellations for %s have been set to %s.",
"successall": "🇺🇸Constellations for all characters have been set to %s.",
"description": "🇺🇸Sets constellation level for your current active character" "description": "🇺🇸Sets constellation level for your current active character"
}, },
"setFetterLevel": { "setFetterLevel": {
......
...@@ -264,6 +264,7 @@ ...@@ -264,6 +264,7 @@
"fail": "星座の設定に失敗しました。", "fail": "星座の設定に失敗しました。",
"failed_success": "%s の星座は %s に設定されました。 シーンをリロードして変更を確認してください。", "failed_success": "%s の星座は %s に設定されました。 シーンをリロードして変更を確認してください。",
"success": "%s の星座は %s に設定されました。", "success": "%s の星座は %s に設定されました。",
"successall": "🇺🇸Constellations for all characters have been set to %s.",
"description": "現在アクティブなキャラクターの星座レベルを設定します" "description": "現在アクティブなキャラクターの星座レベルを設定します"
}, },
"setFetterLevel": { "setFetterLevel": {
......
...@@ -264,6 +264,7 @@ ...@@ -264,6 +264,7 @@
"fail": "🇺🇸Failed to set constellation.", "fail": "🇺🇸Failed to set constellation.",
"failed_success": "🇺🇸Constellations for %s have been set to %s. Please reload scene to see changes.", "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.", "success": "🇺🇸Constellations for %s have been set to %s.",
"successall": "🇺🇸Constellations for all characters have been set to %s.",
"description": "🇺🇸Sets constellation level for your current active character" "description": "🇺🇸Sets constellation level for your current active character"
}, },
"setFetterLevel": { "setFetterLevel": {
......
...@@ -264,6 +264,7 @@ ...@@ -264,6 +264,7 @@
"fail": "Nie udało się ustawić konstelacji.", "fail": "Nie udało się ustawić konstelacji.",
"failed_success": "Konstelacje dla %s zostały ustawione na %s. Proszę przeładować scenę aby zobaczyć zmiany.", "failed_success": "Konstelacje dla %s zostały ustawione na %s. Proszę przeładować scenę aby zobaczyć zmiany.",
"success": "Konstelacje dla %s zostały ustawione na %s.", "success": "Konstelacje dla %s zostały ustawione na %s.",
"successall": "🇺🇸Constellations for all characters have been set to %s.",
"description": "Ustawia poziom konstelacji dla aktywnej postaci" "description": "Ustawia poziom konstelacji dla aktywnej postaci"
}, },
"setFetterLevel": { "setFetterLevel": {
......
...@@ -264,6 +264,7 @@ ...@@ -264,6 +264,7 @@
"fail": "🇺🇸Failed to set constellation.", "fail": "🇺🇸Failed to set constellation.",
"failed_success": "🇺🇸Constellations for %s have been set to %s. Please reload scene to see changes.", "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.", "success": "🇺🇸Constellations for %s have been set to %s.",
"successall": "🇺🇸Constellations for all characters have been set to %s.",
"description": "🇺🇸Sets constellation level for your current active character" "description": "🇺🇸Sets constellation level for your current active character"
}, },
"setFetterLevel": { "setFetterLevel": {
......
...@@ -264,6 +264,7 @@ ...@@ -264,6 +264,7 @@
"fail": "Не удалось установить уровень созвездия.", "fail": "Не удалось установить уровень созвездия.",
"failed_success": "Созвездия для %s установлены на %s. Перезайдите чтобы изменения вступили в силу.", "failed_success": "Созвездия для %s установлены на %s. Перезайдите чтобы изменения вступили в силу.",
"success": "Созвездия для %s были установлены на %s.", "success": "Созвездия для %s были установлены на %s.",
"successall": "🇺🇸Constellations for all characters have been set to %s.",
"description": "Задает уровень созвездия для активного персонажа" "description": "Задает уровень созвездия для активного персонажа"
}, },
"setFetterLevel": { "setFetterLevel": {
......
...@@ -264,6 +264,7 @@ ...@@ -264,6 +264,7 @@
"fail": "命之座等级设置失败。", "fail": "命之座等级设置失败。",
"failed_success": "命之座 %s 已设置为 %s。", "failed_success": "命之座 %s 已设置为 %s。",
"success": "命之座 %s 已设置为 %s。", "success": "命之座 %s 已设置为 %s。",
"successall": "🇺🇸Constellations for all characters have been set to %s.",
"description": "为当前活跃角色设置命座等级" "description": "为当前活跃角色设置命座等级"
}, },
"setFetterLevel": { "setFetterLevel": {
......
...@@ -264,6 +264,7 @@ ...@@ -264,6 +264,7 @@
"fail": "設定命座失敗。", "fail": "設定命座失敗。",
"failed_success": "%s的命之座已設定為成%s,重新登入後將會生效。", "failed_success": "%s的命之座已設定為成%s,重新登入後將會生效。",
"success": "%s的命之座已設定為成%s。", "success": "%s的命之座已設定為成%s。",
"successall": "🇺🇸Constellations for all characters have been set to %s.",
"description": "設定當前角色的命之座。" "description": "設定當前角色的命之座。"
}, },
"setFetterLevel": { "setFetterLevel": {
......
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