mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-02-09 10:53:21 +08:00
chore: fix codestyle indentation
This commit is contained in:
parent
809009f96c
commit
db280387ba
@ -1,59 +1,43 @@
|
|||||||
package emu.grasscutter.command.commands;
|
package emu.grasscutter.command.commands;
|
||||||
|
|
||||||
|
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.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;
|
||||||
|
import emu.grasscutter.game.inventory.GameItem;
|
||||||
|
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 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.GameConstants.*;
|
||||||
import static emu.grasscutter.command.CommandHelpers.*;
|
import static emu.grasscutter.command.CommandHelpers.*;
|
||||||
|
|
||||||
import emu.grasscutter.command.*;
|
@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)
|
||||||
import emu.grasscutter.data.*;
|
|
||||||
import emu.grasscutter.data.excels.ItemData;
|
|
||||||
import emu.grasscutter.data.excels.avatar.AvatarData;
|
|
||||||
import emu.grasscutter.data.excels.reliquary.*;
|
|
||||||
import emu.grasscutter.game.avatar.Avatar;
|
|
||||||
import emu.grasscutter.game.inventory.*;
|
|
||||||
import emu.grasscutter.game.player.Player;
|
|
||||||
import emu.grasscutter.game.props.*;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
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)
|
|
||||||
public final class GiveCommand implements CommandHandler {
|
public final class GiveCommand implements CommandHandler {
|
||||||
private static final Map<Pattern, BiConsumer<GiveItemParameters, Integer>> intCommandHandlers =
|
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));
|
||||||
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) {
|
private static Avatar makeAvatar(GiveItemParameters param) {
|
||||||
return makeAvatar(
|
return makeAvatar(param.avatarData, param.lvl, Avatar.getMinPromoteLevel(param.lvl), param.constellation, param.skillLevel);
|
||||||
param.avatarData,
|
|
||||||
param.lvl,
|
|
||||||
Avatar.getMinPromoteLevel(param.lvl),
|
|
||||||
param.constellation,
|
|
||||||
param.skillLevel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Avatar makeAvatar(
|
private static Avatar makeAvatar(AvatarData avatarData, int level, int promoteLevel, int constellation, int skillLevel) {
|
||||||
AvatarData avatarData, int level, int promoteLevel, int constellation, int skillLevel) {
|
|
||||||
Avatar avatar = new Avatar(avatarData);
|
Avatar avatar = new Avatar(avatarData);
|
||||||
avatar.setLevel(level);
|
avatar.setLevel(level);
|
||||||
avatar.setPromoteLevel(promoteLevel);
|
avatar.setPromoteLevel(promoteLevel);
|
||||||
avatar
|
avatar.getSkillDepot().getSkillsAndEnergySkill().forEach(id -> avatar.setSkillLevel(id, skillLevel));
|
||||||
.getSkillDepot()
|
|
||||||
.getSkillsAndEnergySkill()
|
|
||||||
.forEach(id -> avatar.setSkillLevel(id, skillLevel));
|
|
||||||
avatar.forceConstellationLevel(constellation);
|
avatar.forceConstellationLevel(constellation);
|
||||||
avatar.recalcStats(true);
|
avatar.recalcStats(true);
|
||||||
avatar.save();
|
avatar.save();
|
||||||
@ -63,16 +47,13 @@ public final class GiveCommand implements CommandHandler {
|
|||||||
private static void giveAllAvatars(Player player, GiveItemParameters param) {
|
private static void giveAllAvatars(Player player, GiveItemParameters param) {
|
||||||
int promoteLevel = Avatar.getMinPromoteLevel(param.lvl);
|
int promoteLevel = Avatar.getMinPromoteLevel(param.lvl);
|
||||||
if (param.constellation < 0 || param.constellation > 6)
|
if (param.constellation < 0 || param.constellation > 6)
|
||||||
param.constellation =
|
param.constellation = 6; // constellation's default is -1 so if no parameters set for constellations it'll
|
||||||
6; // constellation's default is -1 so if no parameters set for constellations it'll
|
|
||||||
// automatically be 6
|
// automatically be 6
|
||||||
for (AvatarData avatarData : GameData.getAvatarDataMap().values()) {
|
for (AvatarData avatarData : GameData.getAvatarDataMap().values()) {
|
||||||
int id = avatarData.getId();
|
int id = avatarData.getId();
|
||||||
if (id < 10000002 || id >= 11000000) continue; // Exclude test avatars
|
if (id < 10000002 || id >= 11000000) continue; // Exclude test avatars
|
||||||
// Don't try to add each avatar to the current team
|
// Don't try to add each avatar to the current team
|
||||||
player.addAvatar(
|
player.addAvatar(makeAvatar(avatarData, param.lvl, promoteLevel, param.constellation, param.skillLevel), false);
|
||||||
makeAvatar(avatarData, param.lvl, promoteLevel, param.constellation, param.skillLevel),
|
|
||||||
false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +93,7 @@ public final class GiveCommand implements CommandHandler {
|
|||||||
item.setTotalExp(totalExp);
|
item.setTotalExp(totalExp);
|
||||||
int numAffixes = param.data.getAppendPropNum() + (param.lvl - 1) / 4;
|
int numAffixes = param.data.getAppendPropNum() + (param.lvl - 1) / 4;
|
||||||
if (param.mainPropId > 0) // Keep random mainProp if we didn't specify one
|
if (param.mainPropId > 0) // Keep random mainProp if we didn't specify one
|
||||||
item.setMainPropId(param.mainPropId);
|
item.setMainPropId(param.mainPropId);
|
||||||
if (param.appendPropIdList != null) {
|
if (param.appendPropIdList != null) {
|
||||||
item.getAppendPropIdList().clear();
|
item.getAppendPropIdList().clear();
|
||||||
item.getAppendPropIdList().addAll(param.appendPropIdList);
|
item.getAppendPropIdList().addAll(param.appendPropIdList);
|
||||||
@ -124,17 +105,14 @@ public final class GiveCommand implements CommandHandler {
|
|||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getArtifactMainProp(ItemData itemData, FightProperty prop)
|
private static int getArtifactMainProp(ItemData itemData, FightProperty prop) throws IllegalArgumentException {
|
||||||
throws IllegalArgumentException {
|
|
||||||
if (prop != FightProperty.FIGHT_PROP_NONE)
|
if (prop != FightProperty.FIGHT_PROP_NONE)
|
||||||
for (ReliquaryMainPropData data :
|
for (ReliquaryMainPropData data : GameDepot.getRelicMainPropList(itemData.getMainPropDepotId()))
|
||||||
GameDepot.getRelicMainPropList(itemData.getMainPropDepotId()))
|
|
||||||
if (data.getWeight() > 0 && data.getFightProp() == prop) return data.getId();
|
if (data.getWeight() > 0 && data.getFightProp() == prop) return data.getId();
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Integer> getArtifactAffixes(ItemData itemData, FightProperty prop)
|
private static List<Integer> getArtifactAffixes(ItemData itemData, FightProperty prop) throws IllegalArgumentException {
|
||||||
throws IllegalArgumentException {
|
|
||||||
if (prop == FightProperty.FIGHT_PROP_NONE) {
|
if (prop == FightProperty.FIGHT_PROP_NONE) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
@ -147,8 +125,7 @@ public final class GiveCommand implements CommandHandler {
|
|||||||
return affixes;
|
return affixes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getAppendPropId(String substatText, ItemData itemData)
|
private static int getAppendPropId(String substatText, ItemData itemData) throws IllegalArgumentException {
|
||||||
throws IllegalArgumentException {
|
|
||||||
// If the given substat text is an integer, we just use that as the append prop ID.
|
// If the given substat text is an integer, we just use that as the append prop ID.
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(substatText);
|
return Integer.parseInt(substatText);
|
||||||
@ -165,8 +142,7 @@ public final class GiveCommand implements CommandHandler {
|
|||||||
substatTier = Integer.parseInt(substatArgs[1]);
|
substatTier = Integer.parseInt(substatArgs[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Integer> substats =
|
List<Integer> substats = getArtifactAffixes(itemData, FightProperty.getPropByShortName(substatType));
|
||||||
getArtifactAffixes(itemData, FightProperty.getPropByShortName(substatType));
|
|
||||||
|
|
||||||
if (substats.isEmpty()) {
|
if (substats.isEmpty()) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
@ -178,8 +154,7 @@ public final class GiveCommand implements CommandHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void parseRelicArgs(GiveItemParameters param, List<String> args)
|
private static void parseRelicArgs(GiveItemParameters param, List<String> args) throws IllegalArgumentException {
|
||||||
throws IllegalArgumentException {
|
|
||||||
// Get the main stat from the arguments.
|
// Get the main stat from the arguments.
|
||||||
// If the given argument is an integer, we use that.
|
// If the given argument is an integer, we use that.
|
||||||
// If not, we check if the argument string is in the main prop map.
|
// If not, we check if the argument string is in the main prop map.
|
||||||
@ -189,8 +164,7 @@ public final class GiveCommand implements CommandHandler {
|
|||||||
param.mainPropId = Integer.parseInt(mainPropIdString);
|
param.mainPropId = Integer.parseInt(mainPropIdString);
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
// This can in turn throw an exception which we don't want to catch here.
|
// This can in turn throw an exception which we don't want to catch here.
|
||||||
param.mainPropId =
|
param.mainPropId = getArtifactMainProp(param.data, FightProperty.getPropByShortName(mainPropIdString));
|
||||||
getArtifactMainProp(param.data, FightProperty.getPropByShortName(mainPropIdString));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get substats.
|
// Get substats.
|
||||||
@ -271,8 +245,7 @@ public final class GiveCommand implements CommandHandler {
|
|||||||
giveAllWeapons(player, param);
|
giveAllWeapons(player, param);
|
||||||
}
|
}
|
||||||
|
|
||||||
private GiveItemParameters parseArgs(Player sender, List<String> args)
|
private GiveItemParameters parseArgs(Player sender, List<String> args) throws IllegalArgumentException {
|
||||||
throws IllegalArgumentException {
|
|
||||||
GiveItemParameters param = new GiveItemParameters();
|
GiveItemParameters param = new GiveItemParameters();
|
||||||
|
|
||||||
// Extract any tagged arguments (e.g. "lv90", "x100", "r5")
|
// Extract any tagged arguments (e.g. "lv90", "x100", "r5")
|
||||||
@ -314,9 +287,7 @@ public final class GiveCommand implements CommandHandler {
|
|||||||
param.avatarData = GameData.getAvatarDataMap().get(param.id - 1000 + 10_000_000);
|
param.avatarData = GameData.getAvatarDataMap().get(param.id - 1000 + 10_000_000);
|
||||||
isRelic = ((param.data != null) && (param.data.getItemType() == ItemType.ITEM_RELIQUARY));
|
isRelic = ((param.data != null) && (param.data.getItemType() == ItemType.ITEM_RELIQUARY));
|
||||||
|
|
||||||
if (!isRelic
|
if (!isRelic && !args.isEmpty() && (param.amount == 1)) { // A concession for the people that truly hate [x<amount>].
|
||||||
&& !args.isEmpty()
|
|
||||||
&& (param.amount == 1)) { // A concession for the people that truly hate [x<amount>].
|
|
||||||
try {
|
try {
|
||||||
param.amount = Integer.parseInt(args.remove(0));
|
param.amount = Integer.parseInt(args.remove(0));
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
@ -394,8 +365,7 @@ public final class GiveCommand implements CommandHandler {
|
|||||||
if (param.avatarData != null) {
|
if (param.avatarData != null) {
|
||||||
Avatar avatar = makeAvatar(param);
|
Avatar avatar = makeAvatar(param);
|
||||||
targetPlayer.addAvatar(avatar);
|
targetPlayer.addAvatar(avatar);
|
||||||
CommandHandler.sendTranslatedMessage(
|
CommandHandler.sendTranslatedMessage(sender, "commands.give.given_avatar", param.id, param.lvl, targetPlayer.getUid());
|
||||||
sender, "commands.give.given_avatar", param.id, param.lvl, targetPlayer.getUid());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// If it's not an avatar, it needs to be a valid item
|
// If it's not an avatar, it needs to be a valid item
|
||||||
@ -406,54 +376,37 @@ public final class GiveCommand implements CommandHandler {
|
|||||||
|
|
||||||
switch (param.data.getItemType()) {
|
switch (param.data.getItemType()) {
|
||||||
case ITEM_WEAPON:
|
case ITEM_WEAPON:
|
||||||
targetPlayer
|
targetPlayer.getInventory().addItems(makeUnstackableItems(param), ActionReason.SubfieldDrop);
|
||||||
.getInventory()
|
CommandHandler.sendTranslatedMessage(sender, "commands.give.given_with_level_and_refinement", param.id, param.lvl, param.refinement, param.amount, targetPlayer.getUid());
|
||||||
.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;
|
return;
|
||||||
case ITEM_RELIQUARY:
|
case ITEM_RELIQUARY:
|
||||||
targetPlayer.getInventory().addItems(makeArtifacts(param), ActionReason.SubfieldDrop);
|
targetPlayer.getInventory().addItems(makeArtifacts(param), ActionReason.SubfieldDrop);
|
||||||
CommandHandler.sendTranslatedMessage(
|
CommandHandler.sendTranslatedMessage(sender, "commands.give.given_level", param.id, param.lvl, param.amount, targetPlayer.getUid());
|
||||||
sender,
|
|
||||||
"commands.give.given_level",
|
|
||||||
param.id,
|
|
||||||
param.lvl,
|
|
||||||
param.amount,
|
|
||||||
targetPlayer.getUid());
|
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
targetPlayer
|
targetPlayer.getInventory().addItem(new GameItem(param.data, param.amount), ActionReason.SubfieldDrop);
|
||||||
.getInventory()
|
CommandHandler.sendTranslatedMessage(sender, "commands.give.given", param.amount, param.id, targetPlayer.getUid());
|
||||||
.addItem(new GameItem(param.data, param.amount), ActionReason.SubfieldDrop);
|
|
||||||
CommandHandler.sendTranslatedMessage(
|
|
||||||
sender, "commands.give.given", param.amount, param.id, targetPlayer.getUid());
|
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException ignored) {
|
} catch (IllegalArgumentException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum GiveAllType {
|
private enum GiveAllType {
|
||||||
NONE,
|
NONE, ALL, WEAPONS, MATS, AVATARS
|
||||||
ALL,
|
|
||||||
WEAPONS,
|
|
||||||
MATS,
|
|
||||||
AVATARS
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class GiveItemParameters {
|
private static class GiveItemParameters {
|
||||||
public int id;
|
public int id;
|
||||||
@Setter public int lvl = 0;
|
@Setter
|
||||||
@Setter public int amount = 1;
|
public int lvl = 0;
|
||||||
@Setter public int refinement = 1;
|
@Setter
|
||||||
@Setter public int constellation = -1;
|
public int amount = 1;
|
||||||
@Setter public int skillLevel = 1;
|
@Setter
|
||||||
|
public int refinement = 1;
|
||||||
|
@Setter
|
||||||
|
public int constellation = -1;
|
||||||
|
@Setter
|
||||||
|
public int skillLevel = 1;
|
||||||
public int mainPropId = -1;
|
public int mainPropId = -1;
|
||||||
public List<Integer> appendPropIdList;
|
public List<Integer> appendPropIdList;
|
||||||
public ItemData data;
|
public ItemData data;
|
||||||
|
@ -4,7 +4,8 @@ import emu.grasscutter.data.GameData;
|
|||||||
import emu.grasscutter.data.common.ItemParamData;
|
import emu.grasscutter.data.common.ItemParamData;
|
||||||
import emu.grasscutter.data.excels.CompoundData;
|
import emu.grasscutter.data.excels.CompoundData;
|
||||||
import emu.grasscutter.game.inventory.GameItem;
|
import emu.grasscutter.game.inventory.GameItem;
|
||||||
import emu.grasscutter.game.player.*;
|
import emu.grasscutter.game.player.BasePlayerManager;
|
||||||
|
import emu.grasscutter.game.player.Player;
|
||||||
import emu.grasscutter.game.props.ActionReason;
|
import emu.grasscutter.game.props.ActionReason;
|
||||||
import emu.grasscutter.net.proto.CompoundQueueDataOuterClass.CompoundQueueData;
|
import emu.grasscutter.net.proto.CompoundQueueDataOuterClass.CompoundQueueData;
|
||||||
import emu.grasscutter.net.proto.GetCompoundDataReqOuterClass.GetCompoundDataReq;
|
import emu.grasscutter.net.proto.GetCompoundDataReqOuterClass.GetCompoundDataReq;
|
||||||
@ -12,8 +13,12 @@ import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam;
|
|||||||
import emu.grasscutter.net.proto.PlayerCompoundMaterialReqOuterClass.PlayerCompoundMaterialReq;
|
import emu.grasscutter.net.proto.PlayerCompoundMaterialReqOuterClass.PlayerCompoundMaterialReq;
|
||||||
import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode;
|
import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode;
|
||||||
import emu.grasscutter.net.proto.TakeCompoundOutputReqOuterClass.TakeCompoundOutputReq;
|
import emu.grasscutter.net.proto.TakeCompoundOutputReqOuterClass.TakeCompoundOutputReq;
|
||||||
import emu.grasscutter.server.packet.send.*;
|
import emu.grasscutter.server.packet.send.PackageTakeCompoundOutputRsp;
|
||||||
|
import emu.grasscutter.server.packet.send.PacketCompoundDataNotify;
|
||||||
|
import emu.grasscutter.server.packet.send.PacketGetCompoundDataRsp;
|
||||||
|
import emu.grasscutter.server.packet.send.PacketPlayerCompoundMaterialRsp;
|
||||||
import emu.grasscutter.utils.Utils;
|
import emu.grasscutter.utils.Utils;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class CookingCompoundManager extends BasePlayerManager {
|
public class CookingCompoundManager extends BasePlayerManager {
|
||||||
@ -29,33 +34,24 @@ public class CookingCompoundManager extends BasePlayerManager {
|
|||||||
public static void initialize() {
|
public static void initialize() {
|
||||||
defaultUnlockedCompounds = new HashSet<>();
|
defaultUnlockedCompounds = new HashSet<>();
|
||||||
compoundGroups = new HashMap<>();
|
compoundGroups = new HashMap<>();
|
||||||
GameData.getCompoundDataMap()
|
GameData.getCompoundDataMap().forEach((id, compound) -> {
|
||||||
.forEach(
|
if (compound.isDefaultUnlocked()) {
|
||||||
(id, compound) -> {
|
defaultUnlockedCompounds.add(id);
|
||||||
if (compound.isDefaultUnlocked()) {
|
}
|
||||||
defaultUnlockedCompounds.add(id);
|
compoundGroups.computeIfAbsent(compound.getGroupId(), gid -> new HashSet<>()).add(id);
|
||||||
}
|
});
|
||||||
compoundGroups.computeIfAbsent(compound.getGroupId(), gid -> new HashSet<>()).add(id);
|
|
||||||
});
|
|
||||||
// TODO:Because we haven't implemented fishing feature,unlock all compounds related to
|
// TODO:Because we haven't implemented fishing feature,unlock all compounds related to
|
||||||
// fish.Besides,it should be bound to player rather than manager.
|
// fish.Besides,it should be bound to player rather than manager.
|
||||||
unlocked = new HashSet<>(defaultUnlockedCompounds);
|
unlocked = new HashSet<>(defaultUnlockedCompounds);
|
||||||
if (compoundGroups.containsKey(3)) // Avoid NPE from Resources error
|
if (compoundGroups.containsKey(3)) // Avoid NPE from Resources error
|
||||||
unlocked.addAll(compoundGroups.get(3));
|
unlocked.addAll(compoundGroups.get(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized List<CompoundQueueData> getCompoundQueueData() {
|
private synchronized List<CompoundQueueData> getCompoundQueueData() {
|
||||||
List<CompoundQueueData> compoundQueueData =
|
List<CompoundQueueData> compoundQueueData = new ArrayList<>(player.getActiveCookCompounds().size());
|
||||||
new ArrayList<>(player.getActiveCookCompounds().size());
|
|
||||||
int currentTime = Utils.getCurrentSeconds();
|
int currentTime = Utils.getCurrentSeconds();
|
||||||
for (var item : player.getActiveCookCompounds().values()) {
|
for (var item : player.getActiveCookCompounds().values()) {
|
||||||
var data =
|
var data = CompoundQueueData.newBuilder().setCompoundId(item.getCompoundId()).setOutputCount(item.getOutputCount(currentTime)).setOutputTime(item.getOutputTime(currentTime)).setWaitCount(item.getWaitCount(currentTime)).build();
|
||||||
CompoundQueueData.newBuilder()
|
|
||||||
.setCompoundId(item.getCompoundId())
|
|
||||||
.setOutputCount(item.getOutputCount(currentTime))
|
|
||||||
.setOutputTime(item.getOutputTime(currentTime))
|
|
||||||
.setWaitCount(item.getWaitCount(currentTime))
|
|
||||||
.build();
|
|
||||||
compoundQueueData.add(data);
|
compoundQueueData.add(data);
|
||||||
}
|
}
|
||||||
return compoundQueueData;
|
return compoundQueueData;
|
||||||
@ -77,16 +73,14 @@ public class CookingCompoundManager extends BasePlayerManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// check whether the queue is full
|
// check whether the queue is full
|
||||||
if (activeCompounds.containsKey(id)
|
if (activeCompounds.containsKey(id) && activeCompounds.get(id).getTotalCount() + count > compound.getQueueSize()) {
|
||||||
&& activeCompounds.get(id).getTotalCount() + count > compound.getQueueSize()) {
|
|
||||||
player.sendPacket(new PacketPlayerCompoundMaterialRsp(Retcode.RET_COMPOUND_QUEUE_FULL_VALUE));
|
player.sendPacket(new PacketPlayerCompoundMaterialRsp(Retcode.RET_COMPOUND_QUEUE_FULL_VALUE));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// try to consume raw materials
|
// try to consume raw materials
|
||||||
if (!player.getInventory().payItems(compound.getInputVec(), count)) {
|
if (!player.getInventory().payItems(compound.getInputVec(), count)) {
|
||||||
// TODO:I'm not sure whether retcode is correct.
|
// TODO:I'm not sure whether retcode is correct.
|
||||||
player.sendPacket(
|
player.sendPacket(new PacketPlayerCompoundMaterialRsp(Retcode.RET_ITEM_COUNT_NOT_ENOUGH_VALUE));
|
||||||
new PacketPlayerCompoundMaterialRsp(Retcode.RET_ITEM_COUNT_NOT_ENOUGH_VALUE));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ActiveCookCompoundData c;
|
ActiveCookCompoundData c;
|
||||||
@ -98,13 +92,7 @@ public class CookingCompoundManager extends BasePlayerManager {
|
|||||||
c = new ActiveCookCompoundData(id, compound.getCostTime(), count, currentTime);
|
c = new ActiveCookCompoundData(id, compound.getCostTime(), count, currentTime);
|
||||||
activeCompounds.put(id, c);
|
activeCompounds.put(id, c);
|
||||||
}
|
}
|
||||||
var data =
|
var data = CompoundQueueData.newBuilder().setCompoundId(id).setOutputCount(c.getOutputCount(currentTime)).setOutputTime(c.getOutputTime(currentTime)).setWaitCount(c.getWaitCount(currentTime)).build();
|
||||||
CompoundQueueData.newBuilder()
|
|
||||||
.setCompoundId(id)
|
|
||||||
.setOutputCount(c.getOutputCount(currentTime))
|
|
||||||
.setOutputTime(c.getOutputTime(currentTime))
|
|
||||||
.setWaitCount(c.getWaitCount(currentTime))
|
|
||||||
.build();
|
|
||||||
player.sendPacket(new PacketPlayerCompoundMaterialRsp(data));
|
player.sendPacket(new PacketPlayerCompoundMaterialRsp(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,20 +124,9 @@ public class CookingCompoundManager extends BasePlayerManager {
|
|||||||
// give player the rewards
|
// give player the rewards
|
||||||
if (success) {
|
if (success) {
|
||||||
player.getInventory().addItems(allRewards.values(), ActionReason.Compound);
|
player.getInventory().addItems(allRewards.values(), ActionReason.Compound);
|
||||||
player.sendPacket(
|
player.sendPacket(new PackageTakeCompoundOutputRsp(allRewards.values().stream().map(i -> ItemParam.newBuilder().setItemId(i.getItemId()).setCount(i.getCount()).build()).toList(), Retcode.RET_SUCC_VALUE));
|
||||||
new PackageTakeCompoundOutputRsp(
|
|
||||||
allRewards.values().stream()
|
|
||||||
.map(
|
|
||||||
i ->
|
|
||||||
ItemParam.newBuilder()
|
|
||||||
.setItemId(i.getItemId())
|
|
||||||
.setCount(i.getCount())
|
|
||||||
.build())
|
|
||||||
.toList(),
|
|
||||||
Retcode.RET_SUCC_VALUE));
|
|
||||||
} else {
|
} else {
|
||||||
player.sendPacket(
|
player.sendPacket(new PackageTakeCompoundOutputRsp(null, Retcode.RET_COMPOUND_NOT_FINISH_VALUE));
|
||||||
new PackageTakeCompoundOutputRsp(null, Retcode.RET_COMPOUND_NOT_FINISH_VALUE));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,31 +1,51 @@
|
|||||||
package emu.grasscutter.game.world;
|
package emu.grasscutter.game.world;
|
||||||
|
|
||||||
import dev.morphia.annotations.*;
|
import dev.morphia.annotations.Entity;
|
||||||
|
import dev.morphia.annotations.Id;
|
||||||
|
import dev.morphia.annotations.Indexed;
|
||||||
import emu.grasscutter.database.DatabaseHelper;
|
import emu.grasscutter.database.DatabaseHelper;
|
||||||
import emu.grasscutter.game.player.Player;
|
import emu.grasscutter.game.player.Player;
|
||||||
import emu.grasscutter.scripts.data.*;
|
import emu.grasscutter.scripts.data.SceneGadget;
|
||||||
import java.util.*;
|
import emu.grasscutter.scripts.data.SceneGroup;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import lombok.Getter;
|
||||||
import lombok.*;
|
import lombok.Setter;
|
||||||
import org.bson.types.ObjectId;
|
import org.bson.types.ObjectId;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@Entity(value = "group_instances", useDiscriminator = false)
|
@Entity(value = "group_instances", useDiscriminator = false)
|
||||||
public final class SceneGroupInstance {
|
public final class SceneGroupInstance {
|
||||||
@Id private ObjectId id;
|
@Id
|
||||||
|
private ObjectId id;
|
||||||
|
|
||||||
@Indexed private int ownerUid; // This group is owned by the host player
|
@Indexed
|
||||||
@Getter private int groupId;
|
private int ownerUid; // This group is owned by the host player
|
||||||
|
@Getter
|
||||||
|
private int groupId;
|
||||||
|
|
||||||
@Getter private transient SceneGroup luaGroup;
|
@Getter
|
||||||
@Getter @Setter private int targetSuiteId;
|
private transient SceneGroup luaGroup;
|
||||||
@Getter @Setter private int activeSuiteId;
|
@Getter
|
||||||
@Getter private final Set<Integer> deadEntities; // Config_ids
|
@Setter
|
||||||
|
private int targetSuiteId;
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private int activeSuiteId;
|
||||||
|
@Getter
|
||||||
|
private final Set<Integer> deadEntities; // Config_ids
|
||||||
private boolean isCached;
|
private boolean isCached;
|
||||||
|
|
||||||
@Getter private final Map<Integer, Integer> cachedGadgetStates;
|
@Getter
|
||||||
@Getter private final Map<String, Integer> cachedVariables;
|
private final Map<Integer, Integer> cachedGadgetStates;
|
||||||
|
@Getter
|
||||||
|
private final Map<String, Integer> cachedVariables;
|
||||||
|
|
||||||
@Getter @Setter private int lastTimeRefreshed;
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private int lastTimeRefreshed;
|
||||||
|
|
||||||
public SceneGroupInstance(SceneGroup group, Player owner) {
|
public SceneGroupInstance(SceneGroup group, Player owner) {
|
||||||
this.luaGroup = group;
|
this.luaGroup = group;
|
||||||
@ -39,10 +59,11 @@ public final class SceneGroupInstance {
|
|||||||
this.cachedVariables = new ConcurrentHashMap<>();
|
this.cachedVariables = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
this.isCached =
|
this.isCached =
|
||||||
false; // This is true when the group is not loaded on scene but caches suite data
|
false; // This is true when the group is not loaded on scene but caches suite data
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated // Morphia only!
|
@Deprecated
|
||||||
|
// Morphia only!
|
||||||
SceneGroupInstance() {
|
SceneGroupInstance() {
|
||||||
this.cachedVariables = new ConcurrentHashMap<>();
|
this.cachedVariables = new ConcurrentHashMap<>();
|
||||||
this.deadEntities = new HashSet<>();
|
this.deadEntities = new HashSet<>();
|
||||||
@ -65,7 +86,7 @@ public final class SceneGroupInstance {
|
|||||||
|
|
||||||
public void cacheGadgetState(SceneGadget g, int state) {
|
public void cacheGadgetState(SceneGadget g, int state) {
|
||||||
if (g.persistent) // Only cache when is persistent
|
if (g.persistent) // Only cache when is persistent
|
||||||
cachedGadgetStates.put(g.config_id, state);
|
cachedGadgetStates.put(g.config_id, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCachedGadgetState(SceneGadget g) {
|
public int getCachedGadgetState(SceneGadget g) {
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
package emu.grasscutter.server.game;
|
package emu.grasscutter.server.game;
|
||||||
|
|
||||||
import static emu.grasscutter.config.Configuration.GAME_INFO;
|
|
||||||
|
|
||||||
import emu.grasscutter.Grasscutter;
|
import emu.grasscutter.Grasscutter;
|
||||||
import emu.grasscutter.Grasscutter.ServerDebugMode;
|
import emu.grasscutter.Grasscutter.ServerDebugMode;
|
||||||
import emu.grasscutter.net.packet.*;
|
import emu.grasscutter.net.packet.Opcodes;
|
||||||
|
import emu.grasscutter.net.packet.PacketHandler;
|
||||||
|
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||||
|
import emu.grasscutter.net.packet.PacketOpcodesUtils;
|
||||||
import emu.grasscutter.server.event.game.ReceivePacketEvent;
|
import emu.grasscutter.server.event.game.ReceivePacketEvent;
|
||||||
import emu.grasscutter.server.game.GameSession.SessionState;
|
import emu.grasscutter.server.game.GameSession.SessionState;
|
||||||
import it.unimi.dsi.fastutil.ints.*;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
|
||||||
|
import static emu.grasscutter.config.Configuration.GAME_INFO;
|
||||||
|
|
||||||
public final class GameServerPacketHandler {
|
public final class GameServerPacketHandler {
|
||||||
private final Int2ObjectMap<PacketHandler> handlers;
|
private final Int2ObjectMap<PacketHandler> handlers;
|
||||||
@ -29,7 +33,7 @@ public final class GameServerPacketHandler {
|
|||||||
this.handlers.put(opcode.value(), packetHandler);
|
this.handlers.put(opcode.value(), packetHandler);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Grasscutter.getLogger()
|
Grasscutter.getLogger()
|
||||||
.warn("Unable to register handler {}.", handlerClass.getSimpleName(), e);
|
.warn("Unable to register handler {}.", handlerClass.getSimpleName(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +83,7 @@ public final class GameServerPacketHandler {
|
|||||||
ReceivePacketEvent event = new ReceivePacketEvent(session, opcode, payload);
|
ReceivePacketEvent event = new ReceivePacketEvent(session, opcode, payload);
|
||||||
event.call();
|
event.call();
|
||||||
if (!event.isCanceled()) // If event is not canceled, continue.
|
if (!event.isCanceled()) // If event is not canceled, continue.
|
||||||
handler.handle(session, header, event.getPacketData());
|
handler.handle(session, header, event.getPacketData());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
// TODO Remove this when no more needed
|
// TODO Remove this when no more needed
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
@ -89,7 +93,7 @@ public final class GameServerPacketHandler {
|
|||||||
|
|
||||||
// Log unhandled packets
|
// Log unhandled packets
|
||||||
if (GAME_INFO.logPackets == ServerDebugMode.MISSING
|
if (GAME_INFO.logPackets == ServerDebugMode.MISSING
|
||||||
|| GAME_INFO.logPackets == ServerDebugMode.ALL) {
|
|| GAME_INFO.logPackets == ServerDebugMode.ALL) {
|
||||||
Grasscutter.getLogger()
|
Grasscutter.getLogger()
|
||||||
.info("Unhandled packet ({}): {}", opcode, PacketOpcodesUtils.getOpcodeName(opcode));
|
.info("Unhandled packet ({}): {}", opcode, PacketOpcodesUtils.getOpcodeName(opcode));
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,25 @@
|
|||||||
package emu.grasscutter.utils;
|
package emu.grasscutter.utils;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.TypeAdapter;
|
||||||
|
import com.google.gson.TypeAdapterFactory;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import com.google.gson.stream.*;
|
import com.google.gson.stream.JsonReader;
|
||||||
|
import com.google.gson.stream.JsonToken;
|
||||||
|
import com.google.gson.stream.JsonWriter;
|
||||||
import emu.grasscutter.data.common.DynamicFloat;
|
import emu.grasscutter.data.common.DynamicFloat;
|
||||||
import emu.grasscutter.game.world.*;
|
import emu.grasscutter.game.world.GridPosition;
|
||||||
|
import emu.grasscutter.game.world.Position;
|
||||||
import it.unimi.dsi.fastutil.floats.FloatArrayList;
|
import it.unimi.dsi.fastutil.floats.FloatArrayList;
|
||||||
import it.unimi.dsi.fastutil.ints.*;
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntList;
|
||||||
|
import lombok.val;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
import lombok.val;
|
import java.util.HashMap;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public interface JsonAdapters {
|
public interface JsonAdapters {
|
||||||
class DynamicFloatAdapter extends TypeAdapter<DynamicFloat> {
|
class DynamicFloatAdapter extends TypeAdapter<DynamicFloat> {
|
||||||
@ -31,24 +40,25 @@ public interface JsonAdapters {
|
|||||||
val opStack = new ArrayList<DynamicFloat.StackOp>();
|
val opStack = new ArrayList<DynamicFloat.StackOp>();
|
||||||
while (reader.hasNext()) {
|
while (reader.hasNext()) {
|
||||||
opStack.add(
|
opStack.add(
|
||||||
switch (reader.peek()) {
|
switch (reader.peek()) {
|
||||||
case STRING -> new DynamicFloat.StackOp(reader.nextString());
|
case STRING -> new DynamicFloat.StackOp(reader.nextString());
|
||||||
case NUMBER -> new DynamicFloat.StackOp((float) reader.nextDouble());
|
case NUMBER -> new DynamicFloat.StackOp((float) reader.nextDouble());
|
||||||
case BOOLEAN -> new DynamicFloat.StackOp(reader.nextBoolean());
|
case BOOLEAN -> new DynamicFloat.StackOp(reader.nextBoolean());
|
||||||
default -> throw new IOException(
|
default -> throw new IOException(
|
||||||
"Invalid DynamicFloat definition - " + reader.peek().name());
|
"Invalid DynamicFloat definition - " + reader.peek().name());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
reader.endArray();
|
reader.endArray();
|
||||||
return new DynamicFloat(opStack);
|
return new DynamicFloat(opStack);
|
||||||
}
|
}
|
||||||
default -> throw new IOException(
|
default -> throw new IOException(
|
||||||
"Invalid DynamicFloat definition - " + reader.peek().name());
|
"Invalid DynamicFloat definition - " + reader.peek().name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(JsonWriter writer, DynamicFloat f) {}
|
public void write(JsonWriter writer, DynamicFloat f) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IntListAdapter extends TypeAdapter<IntList> {
|
class IntListAdapter extends TypeAdapter<IntList> {
|
||||||
@ -70,7 +80,7 @@ public interface JsonAdapters {
|
|||||||
public void write(JsonWriter writer, IntList l) throws IOException {
|
public void write(JsonWriter writer, IntList l) throws IOException {
|
||||||
writer.beginArray();
|
writer.beginArray();
|
||||||
for (val i : l) // .forEach() doesn't appreciate exceptions
|
for (val i : l) // .forEach() doesn't appreciate exceptions
|
||||||
writer.value(i);
|
writer.value(i);
|
||||||
writer.endArray();
|
writer.endArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,7 +117,7 @@ public interface JsonAdapters {
|
|||||||
throw new IOException("Invalid GridPosition definition - " + in.peek().name());
|
throw new IOException("Invalid GridPosition definition - " + in.peek().name());
|
||||||
|
|
||||||
return new GridPosition(
|
return new GridPosition(
|
||||||
Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]));
|
Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user