mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-24 17:32:52 +08:00
Format code [skip actions]
This commit is contained in:
parent
f51fd55cb5
commit
f9906c4492
@ -47,7 +47,7 @@ public final class AccountCommand implements CommandHandler {
|
||||
if (Configuration.ACCOUNT.EXPERIMENTAL_RealPassword) {
|
||||
if (args.size() < 3) {
|
||||
CommandHandler.sendMessage(
|
||||
sender, "EXPERIMENTAL_RealPassword requires a password argument");
|
||||
sender, "EXPERIMENTAL_RealPassword requires a password argument");
|
||||
CommandHandler.sendMessage(sender, "Usage: account create <username> <password> [uid]");
|
||||
return;
|
||||
}
|
||||
@ -60,10 +60,10 @@ public final class AccountCommand implements CommandHandler {
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.account.invalid"));
|
||||
if (Configuration.ACCOUNT.EXPERIMENTAL_RealPassword) {
|
||||
CommandHandler.sendMessage(
|
||||
sender,
|
||||
"EXPERIMENTAL_RealPassword requires argument 2 to be a password, not a uid");
|
||||
sender,
|
||||
"EXPERIMENTAL_RealPassword requires argument 2 to be a password, not a uid");
|
||||
CommandHandler.sendMessage(
|
||||
sender, "Usage: account create <username> <password> [uid]");
|
||||
sender, "Usage: account create <username> <password> [uid]");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -90,7 +90,7 @@ public final class AccountCommand implements CommandHandler {
|
||||
account.save(); // Save account to database.
|
||||
|
||||
CommandHandler.sendMessage(
|
||||
sender, translate(sender, "commands.account.create", account.getReservedPlayerUid()));
|
||||
sender, translate(sender, "commands.account.create", account.getReservedPlayerUid()));
|
||||
}
|
||||
}
|
||||
case "delete" -> {
|
||||
@ -106,7 +106,7 @@ public final class AccountCommand implements CommandHandler {
|
||||
case "resetpass" -> {
|
||||
if (!Configuration.ACCOUNT.EXPERIMENTAL_RealPassword) {
|
||||
CommandHandler.sendMessage(
|
||||
sender, "resetpass requires EXPERIMENTAL_RealPassword to be true.");
|
||||
sender, "resetpass requires EXPERIMENTAL_RealPassword to be true.");
|
||||
return;
|
||||
}
|
||||
if (args.size() != 3) {
|
||||
@ -128,23 +128,27 @@ public final class AccountCommand implements CommandHandler {
|
||||
}
|
||||
case "list" -> {
|
||||
CommandHandler.sendMessage(sender, "Note: This command might take a while to complete.");
|
||||
CommandHandler.sendMessage(sender,
|
||||
"Accounts: \n" + DatabaseManager.getAccountDatastore()
|
||||
.find(Account.class).stream()
|
||||
.map(acc -> "%s: %s (%s)".formatted(
|
||||
acc.getId(), acc.getUsername(),
|
||||
acc.getReservedPlayerUid() == 0 ?
|
||||
this.getPlayerUid(acc) :
|
||||
acc.getReservedPlayerUid()))
|
||||
.collect(Collectors.joining("\n"))
|
||||
);
|
||||
CommandHandler.sendMessage(
|
||||
sender,
|
||||
"Accounts: \n"
|
||||
+ DatabaseManager.getAccountDatastore().find(Account.class).stream()
|
||||
.map(
|
||||
acc ->
|
||||
"%s: %s (%s)"
|
||||
.formatted(
|
||||
acc.getId(),
|
||||
acc.getUsername(),
|
||||
acc.getReservedPlayerUid() == 0
|
||||
? this.getPlayerUid(acc)
|
||||
: acc.getReservedPlayerUid()))
|
||||
.collect(Collectors.joining("\n")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the UID of the player associated with the given account.
|
||||
* If the player is not found, returns "no UID".
|
||||
* Returns the UID of the player associated with the given account. If the player is not found,
|
||||
* returns "no UID".
|
||||
*
|
||||
* @param account The account to get the UID of.
|
||||
* @return The UID of the player associated with the given account.
|
||||
|
@ -1,11 +1,14 @@
|
||||
package emu.grasscutter.command.commands;
|
||||
|
||||
import static emu.grasscutter.GameConstants.*;
|
||||
import static emu.grasscutter.command.CommandHelpers.*;
|
||||
|
||||
import emu.grasscutter.command.Command;
|
||||
import emu.grasscutter.command.CommandHandler;
|
||||
import emu.grasscutter.data.GameData;
|
||||
import emu.grasscutter.data.GameDepot;
|
||||
import emu.grasscutter.data.excels.avatar.AvatarData;
|
||||
import emu.grasscutter.data.excels.ItemData;
|
||||
import emu.grasscutter.data.excels.avatar.AvatarData;
|
||||
import emu.grasscutter.data.excels.reliquary.ReliquaryAffixData;
|
||||
import emu.grasscutter.data.excels.reliquary.ReliquaryMainPropData;
|
||||
import emu.grasscutter.game.avatar.Avatar;
|
||||
@ -14,45 +17,50 @@ import emu.grasscutter.game.inventory.ItemType;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.game.props.ActionReason;
|
||||
import emu.grasscutter.game.props.FightProperty;
|
||||
import emu.grasscutter.utils.SparseSet;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static emu.grasscutter.GameConstants.*;
|
||||
import static emu.grasscutter.command.CommandHelpers.*;
|
||||
import lombok.Setter;
|
||||
|
||||
@Command(
|
||||
label = "give",
|
||||
aliases = {"g", "item", "giveitem"},
|
||||
usage = {
|
||||
"(<itemId>|<avatarId>|all|weapons|mats|avatars) [lv<level>] [r<refinement>] [x<amount>] [c<constellation>] [sl<skilllevel>]",
|
||||
"<artifactId> [lv<level>] [x<amount>] [<mainPropId>] [<appendPropId>[,<times>]]..."},
|
||||
permission = "player.give",
|
||||
permissionTargeted = "player.give.others",
|
||||
threading = true)
|
||||
label = "give",
|
||||
aliases = {"g", "item", "giveitem"},
|
||||
usage = {
|
||||
"(<itemId>|<avatarId>|all|weapons|mats|avatars) [lv<level>] [r<refinement>] [x<amount>] [c<constellation>] [sl<skilllevel>]",
|
||||
"<artifactId> [lv<level>] [x<amount>] [<mainPropId>] [<appendPropId>[,<times>]]..."
|
||||
},
|
||||
permission = "player.give",
|
||||
permissionTargeted = "player.give.others",
|
||||
threading = true)
|
||||
public final class GiveCommand implements CommandHandler {
|
||||
private static final Map<Pattern, BiConsumer<GiveItemParameters, Integer>> intCommandHandlers = Map.ofEntries(
|
||||
Map.entry(lvlRegex, GiveItemParameters::setLvl),
|
||||
Map.entry(refineRegex, GiveItemParameters::setRefinement),
|
||||
Map.entry(amountRegex, GiveItemParameters::setAmount),
|
||||
Map.entry(constellationRegex, GiveItemParameters::setConstellation),
|
||||
Map.entry(skillLevelRegex, GiveItemParameters::setSkillLevel)
|
||||
);
|
||||
private static final Map<Pattern, BiConsumer<GiveItemParameters, Integer>> intCommandHandlers =
|
||||
Map.ofEntries(
|
||||
Map.entry(lvlRegex, GiveItemParameters::setLvl),
|
||||
Map.entry(refineRegex, GiveItemParameters::setRefinement),
|
||||
Map.entry(amountRegex, GiveItemParameters::setAmount),
|
||||
Map.entry(constellationRegex, GiveItemParameters::setConstellation),
|
||||
Map.entry(skillLevelRegex, GiveItemParameters::setSkillLevel));
|
||||
|
||||
private static Avatar makeAvatar(GiveItemParameters param) {
|
||||
return makeAvatar(param.avatarData, param.lvl, Avatar.getMinPromoteLevel(param.lvl), param.constellation, param.skillLevel);
|
||||
return makeAvatar(
|
||||
param.avatarData,
|
||||
param.lvl,
|
||||
Avatar.getMinPromoteLevel(param.lvl),
|
||||
param.constellation,
|
||||
param.skillLevel);
|
||||
}
|
||||
|
||||
private static Avatar makeAvatar(AvatarData avatarData, int level, int promoteLevel, int constellation, int skillLevel) {
|
||||
private static Avatar makeAvatar(
|
||||
AvatarData avatarData, int level, int promoteLevel, int constellation, int skillLevel) {
|
||||
Avatar avatar = new Avatar(avatarData);
|
||||
avatar.setLevel(level);
|
||||
avatar.setPromoteLevel(promoteLevel);
|
||||
avatar.getSkillDepot().getSkillsAndEnergySkill().forEach(id -> avatar.setSkillLevel(id, skillLevel));
|
||||
avatar
|
||||
.getSkillDepot()
|
||||
.getSkillsAndEnergySkill()
|
||||
.forEach(id -> avatar.setSkillLevel(id, skillLevel));
|
||||
avatar.forceConstellationLevel(constellation);
|
||||
avatar.recalcStats(true);
|
||||
avatar.save();
|
||||
@ -62,12 +70,16 @@ public final class GiveCommand implements CommandHandler {
|
||||
private static void giveAllAvatars(Player player, GiveItemParameters param) {
|
||||
int promoteLevel = Avatar.getMinPromoteLevel(param.lvl);
|
||||
if (param.constellation < 0 || param.constellation > 6)
|
||||
param.constellation = 6; // constellation's default is -1 so if no parameters set for constellations it'll automatically be 6
|
||||
param.constellation =
|
||||
6; // constellation's default is -1 so if no parameters set for constellations it'll
|
||||
// automatically be 6
|
||||
for (AvatarData avatarData : GameData.getAvatarDataMap().values()) {
|
||||
int id = avatarData.getId();
|
||||
if (id < 10000002 || id >= 11000000) continue; // Exclude test avatars
|
||||
// Don't try to add each avatar to the current team
|
||||
player.addAvatar(makeAvatar(avatarData, param.lvl, promoteLevel, param.constellation, param.skillLevel), false);
|
||||
player.addAvatar(
|
||||
makeAvatar(avatarData, param.lvl, promoteLevel, param.constellation, param.skillLevel),
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,8 +88,7 @@ public final class GiveCommand implements CommandHandler {
|
||||
int totalExp = 0;
|
||||
if (param.data.getItemType() == ItemType.ITEM_WEAPON) {
|
||||
int rankLevel = param.data.getRankLevel();
|
||||
for (int i = 1; i < param.lvl; i++)
|
||||
totalExp += GameData.getWeaponExpRequired(rankLevel, i);
|
||||
for (int i = 1; i < param.lvl; i++) totalExp += GameData.getWeaponExpRequired(rankLevel, i);
|
||||
}
|
||||
|
||||
List<GameItem> items = new ArrayList<>(param.amount);
|
||||
@ -87,7 +98,7 @@ public final class GiveCommand implements CommandHandler {
|
||||
if (item.getItemType() == ItemType.ITEM_WEAPON) {
|
||||
item.setPromoteLevel(promoteLevel);
|
||||
item.setTotalExp(totalExp);
|
||||
item.setRefinement(param.refinement - 1); // Actual refinement data is 0..4 not 1..5
|
||||
item.setRefinement(param.refinement - 1); // Actual refinement data is 0..4 not 1..5
|
||||
}
|
||||
items.add(item);
|
||||
}
|
||||
@ -98,8 +109,7 @@ public final class GiveCommand implements CommandHandler {
|
||||
param.lvl = Math.min(param.lvl, param.data.getMaxLevel());
|
||||
int rank = param.data.getRankLevel();
|
||||
int totalExp = 0;
|
||||
for (int i = 1; i < param.lvl; i++)
|
||||
totalExp += GameData.getRelicExpRequired(rank, i);
|
||||
for (int i = 1; i < param.lvl; i++) totalExp += GameData.getRelicExpRequired(rank, i);
|
||||
|
||||
List<GameItem> items = new ArrayList<>(param.amount);
|
||||
for (int i = 0; i < param.amount; i++) {
|
||||
@ -108,8 +118,8 @@ public final class GiveCommand implements CommandHandler {
|
||||
item.setLevel(param.lvl);
|
||||
item.setTotalExp(totalExp);
|
||||
int numAffixes = param.data.getAppendPropNum() + (param.lvl - 1) / 4;
|
||||
if (param.mainPropId > 0) // Keep random mainProp if we didn't specify one
|
||||
item.setMainPropId(param.mainPropId);
|
||||
if (param.mainPropId > 0) // Keep random mainProp if we didn't specify one
|
||||
item.setMainPropId(param.mainPropId);
|
||||
if (param.appendPropIdList != null) {
|
||||
item.getAppendPropIdList().clear();
|
||||
item.getAppendPropIdList().addAll(param.appendPropIdList);
|
||||
@ -121,15 +131,17 @@ public final class GiveCommand implements CommandHandler {
|
||||
return items;
|
||||
}
|
||||
|
||||
private static int getArtifactMainProp(ItemData itemData, FightProperty prop) throws IllegalArgumentException {
|
||||
private static int getArtifactMainProp(ItemData itemData, FightProperty prop)
|
||||
throws IllegalArgumentException {
|
||||
if (prop != FightProperty.FIGHT_PROP_NONE)
|
||||
for (ReliquaryMainPropData data : GameDepot.getRelicMainPropList(itemData.getMainPropDepotId()))
|
||||
if (data.getWeight() > 0 && data.getFightProp() == prop)
|
||||
return data.getId();
|
||||
for (ReliquaryMainPropData data :
|
||||
GameDepot.getRelicMainPropList(itemData.getMainPropDepotId()))
|
||||
if (data.getWeight() > 0 && data.getFightProp() == prop) return data.getId();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
private static List<Integer> getArtifactAffixes(ItemData itemData, FightProperty prop) throws IllegalArgumentException {
|
||||
private static List<Integer> getArtifactAffixes(ItemData itemData, FightProperty prop)
|
||||
throws IllegalArgumentException {
|
||||
if (prop == FightProperty.FIGHT_PROP_NONE) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
@ -142,7 +154,8 @@ public final class GiveCommand implements CommandHandler {
|
||||
return affixes;
|
||||
}
|
||||
|
||||
private static int getAppendPropId(String substatText, ItemData itemData) throws IllegalArgumentException {
|
||||
private static int getAppendPropId(String substatText, ItemData itemData)
|
||||
throws IllegalArgumentException {
|
||||
// If the given substat text is an integer, we just use that as the append prop ID.
|
||||
try {
|
||||
return Integer.parseInt(substatText);
|
||||
@ -159,19 +172,21 @@ public final class GiveCommand implements CommandHandler {
|
||||
substatTier = Integer.parseInt(substatArgs[1]);
|
||||
}
|
||||
|
||||
List<Integer> substats = getArtifactAffixes(itemData, FightProperty.getPropByShortName(substatType));
|
||||
List<Integer> substats =
|
||||
getArtifactAffixes(itemData, FightProperty.getPropByShortName(substatType));
|
||||
|
||||
if (substats.isEmpty()) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
substatTier -= 1; // 1-indexed to 0-indexed
|
||||
substatTier -= 1; // 1-indexed to 0-indexed
|
||||
substatTier = Math.min(Math.max(0, substatTier), substats.size() - 1);
|
||||
return substats.get(substatTier);
|
||||
}
|
||||
}
|
||||
|
||||
private static void parseRelicArgs(GiveItemParameters param, List<String> args) throws IllegalArgumentException {
|
||||
private static void parseRelicArgs(GiveItemParameters param, List<String> args)
|
||||
throws IllegalArgumentException {
|
||||
// Get the main stat from the arguments.
|
||||
// If the given argument is an integer, we use that.
|
||||
// If not, we check if the argument string is in the main prop map.
|
||||
@ -181,7 +196,8 @@ public final class GiveCommand implements CommandHandler {
|
||||
param.mainPropId = Integer.parseInt(mainPropIdString);
|
||||
} catch (NumberFormatException ignored) {
|
||||
// This can in turn throw an exception which we don't want to catch here.
|
||||
param.mainPropId = getArtifactMainProp(param.data, FightProperty.getPropByShortName(mainPropIdString));
|
||||
param.mainPropId =
|
||||
getArtifactMainProp(param.data, FightProperty.getPropByShortName(mainPropIdString));
|
||||
}
|
||||
|
||||
// Get substats.
|
||||
@ -219,7 +235,7 @@ public final class GiveCommand implements CommandHandler {
|
||||
List<GameItem> itemList = new ArrayList<>();
|
||||
for (ItemData itemdata : GameData.getItemDataMap().values()) {
|
||||
int id = itemdata.getId();
|
||||
if (id < 100_000) continue; // Nothing meaningful below this
|
||||
if (id < 100_000) continue; // Nothing meaningful below this
|
||||
if (ILLEGAL_ITEMS.contains(id)) continue;
|
||||
if (itemdata.isEquip()) continue;
|
||||
|
||||
@ -239,7 +255,7 @@ public final class GiveCommand implements CommandHandler {
|
||||
List<GameItem> itemList = new ArrayList<>();
|
||||
for (ItemData itemdata : GameData.getItemDataMap().values()) {
|
||||
int id = itemdata.getId();
|
||||
if (id < 11100 || id > 16000) continue; // All extant weapons are within this range
|
||||
if (id < 11100 || id > 16000) continue; // All extant weapons are within this range
|
||||
if (ILLEGAL_WEAPONS.contains(id)) continue;
|
||||
if (!itemdata.isEquip()) continue;
|
||||
if (itemdata.getItemType() != ItemType.ITEM_WEAPON) continue;
|
||||
@ -262,7 +278,8 @@ public final class GiveCommand implements CommandHandler {
|
||||
giveAllWeapons(player, param);
|
||||
}
|
||||
|
||||
private GiveItemParameters parseArgs(Player sender, List<String> args) throws IllegalArgumentException {
|
||||
private GiveItemParameters parseArgs(Player sender, List<String> args)
|
||||
throws IllegalArgumentException {
|
||||
GiveItemParameters param = new GiveItemParameters();
|
||||
|
||||
// Extract any tagged arguments (e.g. "lv90", "x100", "r5")
|
||||
@ -270,7 +287,7 @@ public final class GiveCommand implements CommandHandler {
|
||||
|
||||
// At this point, first remaining argument MUST be itemId/avatarId
|
||||
if (args.size() < 1) {
|
||||
sendUsageMessage(sender); // Reachable if someone does `/give lv90` or similar
|
||||
sendUsageMessage(sender); // Reachable if someone does `/give lv90` or similar
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
String id = args.remove(0);
|
||||
@ -304,7 +321,9 @@ public final class GiveCommand implements CommandHandler {
|
||||
param.avatarData = GameData.getAvatarDataMap().get(param.id - 1000 + 10_000_000);
|
||||
isRelic = ((param.data != null) && (param.data.getItemType() == ItemType.ITEM_RELIQUARY));
|
||||
|
||||
if (!isRelic && !args.isEmpty() && (param.amount == 1)) { // A concession for the people that truly hate [x<amount>].
|
||||
if (!isRelic
|
||||
&& !args.isEmpty()
|
||||
&& (param.amount == 1)) { // A concession for the people that truly hate [x<amount>].
|
||||
try {
|
||||
param.amount = Integer.parseInt(args.remove(0));
|
||||
} catch (NumberFormatException e) {
|
||||
@ -382,7 +401,8 @@ public final class GiveCommand implements CommandHandler {
|
||||
if (param.avatarData != null) {
|
||||
Avatar avatar = makeAvatar(param);
|
||||
targetPlayer.addAvatar(avatar);
|
||||
CommandHandler.sendTranslatedMessage(sender, "commands.give.given_avatar", param.id, param.lvl, targetPlayer.getUid());
|
||||
CommandHandler.sendTranslatedMessage(
|
||||
sender, "commands.give.given_avatar", param.id, param.lvl, targetPlayer.getUid());
|
||||
return;
|
||||
}
|
||||
// If it's not an avatar, it needs to be a valid item
|
||||
@ -393,16 +413,34 @@ public final class GiveCommand implements CommandHandler {
|
||||
|
||||
switch (param.data.getItemType()) {
|
||||
case ITEM_WEAPON:
|
||||
targetPlayer.getInventory().addItems(makeUnstackableItems(param), ActionReason.SubfieldDrop);
|
||||
CommandHandler.sendTranslatedMessage(sender, "commands.give.given_with_level_and_refinement", param.id, param.lvl, param.refinement, param.amount, targetPlayer.getUid());
|
||||
targetPlayer
|
||||
.getInventory()
|
||||
.addItems(makeUnstackableItems(param), ActionReason.SubfieldDrop);
|
||||
CommandHandler.sendTranslatedMessage(
|
||||
sender,
|
||||
"commands.give.given_with_level_and_refinement",
|
||||
param.id,
|
||||
param.lvl,
|
||||
param.refinement,
|
||||
param.amount,
|
||||
targetPlayer.getUid());
|
||||
return;
|
||||
case ITEM_RELIQUARY:
|
||||
targetPlayer.getInventory().addItems(makeArtifacts(param), ActionReason.SubfieldDrop);
|
||||
CommandHandler.sendTranslatedMessage(sender, "commands.give.given_level", param.id, param.lvl, param.amount, targetPlayer.getUid());
|
||||
CommandHandler.sendTranslatedMessage(
|
||||
sender,
|
||||
"commands.give.given_level",
|
||||
param.id,
|
||||
param.lvl,
|
||||
param.amount,
|
||||
targetPlayer.getUid());
|
||||
return;
|
||||
default:
|
||||
targetPlayer.getInventory().addItem(new GameItem(param.data, param.amount), ActionReason.SubfieldDrop);
|
||||
CommandHandler.sendTranslatedMessage(sender, "commands.give.given", param.amount, param.id, targetPlayer.getUid());
|
||||
targetPlayer
|
||||
.getInventory()
|
||||
.addItem(new GameItem(param.data, param.amount), ActionReason.SubfieldDrop);
|
||||
CommandHandler.sendTranslatedMessage(
|
||||
sender, "commands.give.given", param.amount, param.id, targetPlayer.getUid());
|
||||
}
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
@ -418,16 +456,11 @@ public final class GiveCommand implements CommandHandler {
|
||||
|
||||
private static class GiveItemParameters {
|
||||
public int id;
|
||||
@Setter
|
||||
public int lvl = 0;
|
||||
@Setter
|
||||
public int amount = 1;
|
||||
@Setter
|
||||
public int refinement = 1;
|
||||
@Setter
|
||||
public int constellation = -1;
|
||||
@Setter
|
||||
public int skillLevel = 1;
|
||||
@Setter public int lvl = 0;
|
||||
@Setter public int amount = 1;
|
||||
@Setter public int refinement = 1;
|
||||
@Setter public int constellation = -1;
|
||||
@Setter public int skillLevel = 1;
|
||||
public int mainPropId = -1;
|
||||
public List<Integer> appendPropIdList;
|
||||
public ItemData data;
|
||||
|
@ -5,7 +5,6 @@ import emu.grasscutter.game.quest.GameQuest;
|
||||
import emu.grasscutter.game.quest.QuestValueExec;
|
||||
import emu.grasscutter.game.quest.enums.QuestExec;
|
||||
import emu.grasscutter.game.quest.handlers.QuestExecHandler;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@QuestValueExec(QuestExec.QUEST_EXEC_SET_IS_GAME_TIME_LOCKED)
|
||||
|
@ -510,8 +510,7 @@ public final class Scene {
|
||||
|
||||
this.finishLoading();
|
||||
this.checkPlayerRespawn();
|
||||
if (this.tickCount++ % 10 == 0)
|
||||
this.broadcastPacket(new PacketSceneTimeNotify(this));
|
||||
if (this.tickCount++ % 10 == 0) this.broadcastPacket(new PacketSceneTimeNotify(this));
|
||||
}
|
||||
|
||||
/** Validates a player's current position. Teleports the player if the player is out of bounds. */
|
||||
|
@ -1,5 +1,7 @@
|
||||
package emu.grasscutter.server.http.documentation;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.HANDBOOK;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.Grasscutter.ServerRunMode;
|
||||
import emu.grasscutter.data.GameData;
|
||||
@ -12,16 +14,14 @@ import emu.grasscutter.utils.objects.HandbookBody;
|
||||
import io.javalin.Javalin;
|
||||
import io.javalin.http.Context;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.HANDBOOK;
|
||||
|
||||
/** Handles requests for the new GM Handbook. */
|
||||
public final class HandbookHandler implements Router {
|
||||
private final byte[] handbook;
|
||||
private final boolean serve;
|
||||
|
||||
/**
|
||||
* Constructor for the handbook router.
|
||||
* Enables serving the handbook if the handbook file is found.
|
||||
* Constructor for the handbook router. Enables serving the handbook if the handbook file is
|
||||
* found.
|
||||
*/
|
||||
public HandbookHandler() {
|
||||
this.handbook = FileUtils.readResource("/handbook.html");
|
||||
@ -44,8 +44,7 @@ public final class HandbookHandler implements Router {
|
||||
* @return True if the server can execute handbook commands.
|
||||
*/
|
||||
private boolean controlSupported() {
|
||||
return HANDBOOK.enable &&
|
||||
Grasscutter.getRunMode() == ServerRunMode.HYBRID;
|
||||
return HANDBOOK.enable && Grasscutter.getRunMode() == ServerRunMode.HYBRID;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,16 +100,16 @@ public final class HandbookHandler implements Router {
|
||||
var avatar = new Avatar(avatarData);
|
||||
avatar.setLevel(request.getLevel());
|
||||
avatar.setPromoteLevel(Avatar.getMinPromoteLevel(avatar.getLevel()));
|
||||
avatar.getSkillDepot().getSkillsAndEnergySkill().forEach(id ->
|
||||
avatar.setSkillLevel(id, request.getTalentLevels()));
|
||||
avatar
|
||||
.getSkillDepot()
|
||||
.getSkillsAndEnergySkill()
|
||||
.forEach(id -> avatar.setSkillLevel(id, request.getTalentLevels()));
|
||||
avatar.forceConstellationLevel(request.getConstellations());
|
||||
avatar.recalcStats(true); avatar.save();
|
||||
avatar.recalcStats(true);
|
||||
avatar.save();
|
||||
|
||||
player.addAvatar(avatar); // Add the avatar.
|
||||
ctx.json(HandbookBody.Response.builder()
|
||||
.status(200)
|
||||
.message("Avatar granted.")
|
||||
.build());
|
||||
ctx.json(HandbookBody.Response.builder().status(200).message("Avatar granted.").build());
|
||||
} catch (NumberFormatException ignored) {
|
||||
ctx.status(500).result("Invalid player UID or avatar ID.");
|
||||
} catch (Exception exception) {
|
||||
@ -159,10 +158,7 @@ public final class HandbookHandler implements Router {
|
||||
// Add the item to the inventory.
|
||||
player.getInventory().addItem(itemStack, ActionReason.Gm);
|
||||
|
||||
ctx.json(HandbookBody.Response.builder()
|
||||
.status(200)
|
||||
.message("Item granted.")
|
||||
.build());
|
||||
ctx.json(HandbookBody.Response.builder().status(200).message("Item granted.").build());
|
||||
} catch (NumberFormatException ignored) {
|
||||
ctx.status(500).result("Invalid player UID or item ID.");
|
||||
} catch (Exception exception) {
|
||||
|
@ -10,9 +10,12 @@ public final class PacketWindSeedClientNotify extends BasePacket {
|
||||
public PacketWindSeedClientNotify(byte[] compiledLua) {
|
||||
super(PacketOpcodes.WindSeedClientNotify);
|
||||
|
||||
this.setData(WindSeedClientNotify.newBuilder()
|
||||
.setAreaNotify(AreaNotify.newBuilder()
|
||||
.setAreaId(1).setAreaType(1)
|
||||
.setAreaCode(ByteString.copyFrom(compiledLua))));
|
||||
this.setData(
|
||||
WindSeedClientNotify.newBuilder()
|
||||
.setAreaNotify(
|
||||
AreaNotify.newBuilder()
|
||||
.setAreaId(1)
|
||||
.setAreaType(1)
|
||||
.setAreaCode(ByteString.copyFrom(compiledLua))));
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,6 @@ import emu.grasscutter.game.inventory.ItemType;
|
||||
import emu.grasscutter.game.props.SceneType;
|
||||
import emu.grasscutter.utils.JsonUtils;
|
||||
import emu.grasscutter.utils.Language;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
@ -19,6 +17,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
public interface Dumpers {
|
||||
// See `src/handbook/data/README.md` for attributions.
|
||||
@ -50,8 +49,8 @@ public interface Dumpers {
|
||||
*/
|
||||
private static String miniEncode(Map<Integer, ?> dump) {
|
||||
return dump.entrySet().stream()
|
||||
.map(entry -> entry.getKey() + "," + entry.getValue().toString())
|
||||
.collect(Collectors.joining("\n"));
|
||||
.map(entry -> entry.getKey() + "," + entry.getValue().toString())
|
||||
.collect(Collectors.joining("\n"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,25 +65,34 @@ public interface Dumpers {
|
||||
|
||||
// Convert all registered commands to an info map.
|
||||
var dump = new HashMap<String, CommandInfo>();
|
||||
commandMap.getAnnotationsAsList().forEach(command -> {
|
||||
var description = Dumpers.commandDescription(locale, command);
|
||||
var labels = new ArrayList<String>(){{
|
||||
this.add(command.label());
|
||||
this.addAll(List.of(command.aliases()));
|
||||
}};
|
||||
commandMap
|
||||
.getAnnotationsAsList()
|
||||
.forEach(
|
||||
command -> {
|
||||
var description = Dumpers.commandDescription(locale, command);
|
||||
var labels =
|
||||
new ArrayList<String>() {
|
||||
{
|
||||
this.add(command.label());
|
||||
this.addAll(List.of(command.aliases()));
|
||||
}
|
||||
};
|
||||
|
||||
// Add the command info to the list.
|
||||
dump.put(command.label(), new CommandInfo(
|
||||
labels, description, List.of(command.usage()), List.of(
|
||||
command.permission(), command.permissionTargeted()),
|
||||
command.targetRequirement()));
|
||||
});
|
||||
// Add the command info to the list.
|
||||
dump.put(
|
||||
command.label(),
|
||||
new CommandInfo(
|
||||
labels,
|
||||
description,
|
||||
List.of(command.usage()),
|
||||
List.of(command.permission(), command.permissionTargeted()),
|
||||
command.targetRequirement()));
|
||||
});
|
||||
|
||||
try {
|
||||
// Create a file for the dump.
|
||||
var file = new File("commands.json");
|
||||
if (file.exists() && !file.delete())
|
||||
throw new RuntimeException("Failed to delete file.");
|
||||
if (file.exists() && !file.delete()) throw new RuntimeException("Failed to delete file.");
|
||||
if (!file.exists() && !file.createNewFile())
|
||||
throw new RuntimeException("Failed to create file.");
|
||||
|
||||
@ -107,19 +115,25 @@ public interface Dumpers {
|
||||
|
||||
// Convert all known avatars to an avatar map.
|
||||
var dump = new HashMap<Integer, AvatarInfo>();
|
||||
GameData.getAvatarDataMap().forEach((id, avatar) -> {
|
||||
var langHash = avatar.getNameTextMapHash();
|
||||
dump.put(id, new AvatarInfo(
|
||||
langHash == 0 ? avatar.getName() : Language.getTextMapKey(langHash).get(locale),
|
||||
avatar.getQualityType().equals("QUALITY_PURPLE") ? Quality.EPIC : Quality.LEGENDARY
|
||||
));
|
||||
});
|
||||
GameData.getAvatarDataMap()
|
||||
.forEach(
|
||||
(id, avatar) -> {
|
||||
var langHash = avatar.getNameTextMapHash();
|
||||
dump.put(
|
||||
id,
|
||||
new AvatarInfo(
|
||||
langHash == 0
|
||||
? avatar.getName()
|
||||
: Language.getTextMapKey(langHash).get(locale),
|
||||
avatar.getQualityType().equals("QUALITY_PURPLE")
|
||||
? Quality.EPIC
|
||||
: Quality.LEGENDARY));
|
||||
});
|
||||
|
||||
try {
|
||||
// Create a file for the dump.
|
||||
var file = new File("avatars.csv");
|
||||
if (file.exists() && !file.delete())
|
||||
throw new RuntimeException("Failed to delete file.");
|
||||
if (file.exists() && !file.delete()) throw new RuntimeException("Failed to delete file.");
|
||||
if (!file.exists() && !file.createNewFile())
|
||||
throw new RuntimeException("Failed to create file.");
|
||||
|
||||
@ -142,30 +156,35 @@ public interface Dumpers {
|
||||
|
||||
// Convert all known items to an item map.
|
||||
var originalDump = new ArrayList<ItemInfo>();
|
||||
GameData.getItemDataMap().forEach((id, item) -> originalDump.add(new ItemInfo(id,
|
||||
Language.getTextMapKey(item.getNameTextMapHash()).get(locale),
|
||||
Quality.from(item.getRankLevel()), item.getItemType(),
|
||||
item.getIcon().length() > 0 ? item.getIcon().substring(3) : ""
|
||||
)));
|
||||
GameData.getItemDataMap()
|
||||
.forEach(
|
||||
(id, item) ->
|
||||
originalDump.add(
|
||||
new ItemInfo(
|
||||
id,
|
||||
Language.getTextMapKey(item.getNameTextMapHash()).get(locale),
|
||||
Quality.from(item.getRankLevel()),
|
||||
item.getItemType(),
|
||||
item.getIcon().length() > 0 ? item.getIcon().substring(3) : "")));
|
||||
|
||||
// Create a new dump with filtered duplicates.
|
||||
var names = new ArrayList<String>();
|
||||
var dump = new HashMap<Integer, ItemInfo>();
|
||||
originalDump.forEach(item -> {
|
||||
// Validate the item.
|
||||
if (item.name.contains("[CHS]")) return;
|
||||
if (names.contains(item.name)) return;
|
||||
if (dump.containsKey(item.id)) return;
|
||||
// Add the item to the dump.
|
||||
names.add(item.name);
|
||||
dump.put(item.id, item);
|
||||
});
|
||||
originalDump.forEach(
|
||||
item -> {
|
||||
// Validate the item.
|
||||
if (item.name.contains("[CHS]")) return;
|
||||
if (names.contains(item.name)) return;
|
||||
if (dump.containsKey(item.id)) return;
|
||||
// Add the item to the dump.
|
||||
names.add(item.name);
|
||||
dump.put(item.id, item);
|
||||
});
|
||||
|
||||
try {
|
||||
// Create a file for the dump.
|
||||
var file = new File("items.csv");
|
||||
if (file.exists() && !file.delete())
|
||||
throw new RuntimeException("Failed to delete file.");
|
||||
if (file.exists() && !file.delete()) throw new RuntimeException("Failed to delete file.");
|
||||
if (!file.exists() && !file.createNewFile())
|
||||
throw new RuntimeException("Failed to create file.");
|
||||
|
||||
@ -176,9 +195,7 @@ public interface Dumpers {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps all scenes to a JSON file.
|
||||
*/
|
||||
/** Dumps all scenes to a JSON file. */
|
||||
static void dumpScenes() {
|
||||
// Reload resources.
|
||||
ResourceLoader.loadAll();
|
||||
@ -186,14 +203,15 @@ public interface Dumpers {
|
||||
|
||||
// Convert all known scenes to a scene map.
|
||||
var dump = new HashMap<Integer, SceneInfo>();
|
||||
GameData.getSceneDataMap().forEach((id, scene) ->
|
||||
dump.put(id, new SceneInfo(scene.getScriptData(), scene.getSceneType())));
|
||||
GameData.getSceneDataMap()
|
||||
.forEach(
|
||||
(id, scene) ->
|
||||
dump.put(id, new SceneInfo(scene.getScriptData(), scene.getSceneType())));
|
||||
|
||||
try {
|
||||
// Create a file for the dump.
|
||||
var file = new File("scenes.csv");
|
||||
if (file.exists() && !file.delete())
|
||||
throw new RuntimeException("Failed to delete file.");
|
||||
if (file.exists() && !file.delete()) throw new RuntimeException("Failed to delete file.");
|
||||
if (!file.exists() && !file.createNewFile())
|
||||
throw new RuntimeException("Failed to create file.");
|
||||
|
||||
@ -216,20 +234,23 @@ public interface Dumpers {
|
||||
|
||||
// Convert all known avatars to an avatar map.
|
||||
var dump = new HashMap<Integer, EntityInfo>();
|
||||
GameData.getMonsterDataMap().forEach((id, monster) -> {
|
||||
var langHash = monster.getNameTextMapHash();
|
||||
dump.put(id, new EntityInfo(
|
||||
langHash == 0 ? monster.getMonsterName() :
|
||||
Language.getTextMapKey(langHash).get(locale),
|
||||
monster.getMonsterName()
|
||||
));
|
||||
});
|
||||
GameData.getMonsterDataMap()
|
||||
.forEach(
|
||||
(id, monster) -> {
|
||||
var langHash = monster.getNameTextMapHash();
|
||||
dump.put(
|
||||
id,
|
||||
new EntityInfo(
|
||||
langHash == 0
|
||||
? monster.getMonsterName()
|
||||
: Language.getTextMapKey(langHash).get(locale),
|
||||
monster.getMonsterName()));
|
||||
});
|
||||
|
||||
try {
|
||||
// Create a file for the dump.
|
||||
var file = new File("entities.csv");
|
||||
if (file.exists() && !file.delete())
|
||||
throw new RuntimeException("Failed to delete file.");
|
||||
if (file.exists() && !file.delete()) throw new RuntimeException("Failed to delete file.");
|
||||
if (!file.exists() && !file.createNewFile())
|
||||
throw new RuntimeException("Failed to create file.");
|
||||
|
||||
@ -256,8 +277,7 @@ public interface Dumpers {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name + ","
|
||||
+ this.quality;
|
||||
return this.name + "," + this.quality;
|
||||
}
|
||||
}
|
||||
|
||||
@ -271,10 +291,7 @@ public interface Dumpers {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name + ","
|
||||
+ this.quality + ","
|
||||
+ this.type + ","
|
||||
+ this.icon;
|
||||
return this.name + "," + this.quality + "," + this.type + "," + this.icon;
|
||||
}
|
||||
}
|
||||
|
||||
@ -285,8 +302,7 @@ public interface Dumpers {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.identifier + ","
|
||||
+ this.type;
|
||||
return this.identifier + "," + this.type;
|
||||
}
|
||||
}
|
||||
|
||||
@ -297,13 +313,17 @@ public interface Dumpers {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name + ","
|
||||
+ this.internal;
|
||||
return this.name + "," + this.internal;
|
||||
}
|
||||
}
|
||||
|
||||
enum Quality {
|
||||
LEGENDARY, EPIC, RARE, UNCOMMON, COMMON, UNKNOWN;
|
||||
LEGENDARY,
|
||||
EPIC,
|
||||
RARE,
|
||||
UNCOMMON,
|
||||
COMMON,
|
||||
UNKNOWN;
|
||||
|
||||
/**
|
||||
* Convert a rank level to a quality.
|
||||
|
@ -8,10 +8,9 @@ import emu.grasscutter.BuildConfig;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.Grasscutter.ServerRunMode;
|
||||
import emu.grasscutter.net.packet.PacketOpcodesUtils;
|
||||
import emu.grasscutter.tools.Dumpers;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import emu.grasscutter.tools.Dumpers;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/** A parser for start-up arguments. */
|
||||
|
Loading…
Reference in New Issue
Block a user