mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-05-08 21:15:54 +08:00
Extend give command "skill level" & shortening /talent all (#1865)
* Extend give command "talent" * Update src/main/java/emu/grasscutter/data/excels/AvatarSkillDepotData.java Shorten IntStream for getCombatSkills Co-authored-by: Luke 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: Luke 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 Co-authored-by: Luke H-W <Birdulon@users.noreply.github.com>
This commit is contained in:
parent
b5940da36b
commit
2b08738043
@ -13,6 +13,7 @@ public class CommandHelpers {
|
|||||||
public static final Pattern refineRegex = Pattern.compile("(?<!\\w)r(\\d+)");
|
public static final Pattern refineRegex = Pattern.compile("(?<!\\w)r(\\d+)");
|
||||||
public static final Pattern rankRegex = Pattern.compile("(\\d+)\\*");
|
public static final Pattern rankRegex = Pattern.compile("(\\d+)\\*");
|
||||||
public static final Pattern constellationRegex = Pattern.compile("(?<!\\w)c(\\d+)");
|
public static final Pattern constellationRegex = Pattern.compile("(?<!\\w)c(\\d+)");
|
||||||
|
public static final Pattern skillLevelRegex = Pattern.compile("sl(\\d+)");
|
||||||
public static final Pattern stateRegex = Pattern.compile("state(\\d+)");
|
public static final Pattern stateRegex = Pattern.compile("state(\\d+)");
|
||||||
public static final Pattern blockRegex = Pattern.compile("blk(\\d+)");
|
public static final Pattern blockRegex = Pattern.compile("blk(\\d+)");
|
||||||
public static final Pattern groupRegex = Pattern.compile("grp(\\d+)");
|
public static final Pattern groupRegex = Pattern.compile("grp(\\d+)");
|
||||||
|
@ -5,6 +5,7 @@ import emu.grasscutter.command.CommandHandler;
|
|||||||
import emu.grasscutter.data.GameData;
|
import emu.grasscutter.data.GameData;
|
||||||
import emu.grasscutter.data.GameDepot;
|
import emu.grasscutter.data.GameDepot;
|
||||||
import emu.grasscutter.data.excels.AvatarData;
|
import emu.grasscutter.data.excels.AvatarData;
|
||||||
|
import emu.grasscutter.data.excels.AvatarSkillDepotData;
|
||||||
import emu.grasscutter.data.excels.ItemData;
|
import emu.grasscutter.data.excels.ItemData;
|
||||||
import emu.grasscutter.data.excels.ReliquaryAffixData;
|
import emu.grasscutter.data.excels.ReliquaryAffixData;
|
||||||
import emu.grasscutter.data.excels.ReliquaryMainPropData;
|
import emu.grasscutter.data.excels.ReliquaryMainPropData;
|
||||||
@ -29,7 +30,7 @@ import static emu.grasscutter.command.CommandHelpers.*;
|
|||||||
label = "give",
|
label = "give",
|
||||||
aliases = {"g", "item", "giveitem"},
|
aliases = {"g", "item", "giveitem"},
|
||||||
usage = {
|
usage = {
|
||||||
"(<itemId>|<avatarId>|all|weapons|mats|avatars) [lv<level>] [r<refinement>] [x<amount>] [c<constellation>]",
|
"(<itemId>|<avatarId>|all|weapons|mats|avatars) [lv<level>] [r<refinement>] [x<amount>] [c<constellation>] [sl<skilllevel>]",
|
||||||
"<artifactId> [lv<level>] [x<amount>] [<mainPropId>] [<appendPropId>[,<times>]]..."},
|
"<artifactId> [lv<level>] [x<amount>] [<mainPropId>] [<appendPropId>[,<times>]]..."},
|
||||||
permission = "player.give",
|
permission = "player.give",
|
||||||
permissionTargeted = "player.give.others",
|
permissionTargeted = "player.give.others",
|
||||||
@ -47,7 +48,8 @@ public final class GiveCommand implements CommandHandler {
|
|||||||
Map.entry(lvlRegex, GiveItemParameters::setLvl),
|
Map.entry(lvlRegex, GiveItemParameters::setLvl),
|
||||||
Map.entry(refineRegex, GiveItemParameters::setRefinement),
|
Map.entry(refineRegex, GiveItemParameters::setRefinement),
|
||||||
Map.entry(amountRegex, GiveItemParameters::setAmount),
|
Map.entry(amountRegex, GiveItemParameters::setAmount),
|
||||||
Map.entry(constellationRegex, GiveItemParameters::setConstellation)
|
Map.entry(constellationRegex, GiveItemParameters::setConstellation),
|
||||||
|
Map.entry(skillLevelRegex, GiveItemParameters::setSkillLevel)
|
||||||
);
|
);
|
||||||
|
|
||||||
private static class GiveItemParameters {
|
private static class GiveItemParameters {
|
||||||
@ -56,6 +58,7 @@ public final class GiveCommand implements CommandHandler {
|
|||||||
@Setter public int amount = 1;
|
@Setter public int amount = 1;
|
||||||
@Setter public int refinement = 1;
|
@Setter public int refinement = 1;
|
||||||
@Setter public int constellation = -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;
|
||||||
@ -212,30 +215,28 @@ public final class GiveCommand implements CommandHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Avatar makeAvatar(GiveItemParameters param) {
|
private static Avatar makeAvatar(GiveItemParameters param) {
|
||||||
return makeAvatar(param.avatarData, param.lvl, Avatar.getMinPromoteLevel(param.lvl), param.constellation);
|
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) {
|
private static Avatar makeAvatar(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.getSkillDepot().getSkillsAndEnergySkill().forEach(id -> avatar.setSkillLevel(id, skillLevel));
|
||||||
avatar.forceConstellationLevel(constellation);
|
avatar.forceConstellationLevel(constellation);
|
||||||
avatar.recalcStats();
|
avatar.recalcStats(true);
|
||||||
|
avatar.save();
|
||||||
return avatar;
|
return avatar;
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
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;
|
|
||||||
}
|
|
||||||
for (AvatarData avatarData : GameData.getAvatarDataMap().values()) {
|
for (AvatarData avatarData : GameData.getAvatarDataMap().values()) {
|
||||||
// Exclude test avatars
|
|
||||||
int id = avatarData.getId();
|
int id = avatarData.getId();
|
||||||
if (id < 10000002 || id >= 11000000) continue;
|
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(makeAvatar(avatarData, param.lvl, promoteLevel, param.constellation), false);
|
player.addAvatar(makeAvatar(avatarData, param.lvl, promoteLevel, param.constellation, param.skillLevel), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -372,7 +373,7 @@ public final class GiveCommand implements CommandHandler {
|
|||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
param.appendPropIdList.add(appendPropId);
|
param.appendPropIdList.add(appendPropId);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addItemsChunked(Player player, List<GameItem> items, int packetSize) {
|
private static void addItemsChunked(Player player, List<GameItem> items, int packetSize) {
|
||||||
|
@ -103,10 +103,8 @@ public final class TalentCommand implements CommandHandler {
|
|||||||
CommandHandler.sendTranslatedMessage(sender, "commands.talent.out_of_range");
|
CommandHandler.sendTranslatedMessage(sender, "commands.talent.out_of_range");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// This is small so array is not needed imo
|
int finalNewLevel = newLevel;
|
||||||
setTalentLevel(sender, avatar, skillDepot.getSkills().get(0), newLevel);
|
skillDepot.getSkillsAndEnergySkill().forEach(id -> setTalentLevel(sender, avatar, id, finalNewLevel));
|
||||||
setTalentLevel(sender, avatar, skillDepot.getSkills().get(1), newLevel);
|
|
||||||
setTalentLevel(sender, avatar, skillDepot.getEnergySkill(), newLevel);
|
|
||||||
}
|
}
|
||||||
case "getid" -> {
|
case "getid" -> {
|
||||||
var map = GameData.getAvatarSkillDataMap();
|
var map = GameData.getAvatarSkillDataMap();
|
||||||
|
@ -750,14 +750,16 @@ public class Avatar {
|
|||||||
if (level < 0 || level > 15) return false;
|
if (level < 0 || level > 15) return false;
|
||||||
var validLevels = GameData.getAvatarSkillLevels(skillId);
|
var validLevels = GameData.getAvatarSkillLevels(skillId);
|
||||||
if (validLevels != null && !validLevels.contains(level)) return false;
|
if (validLevels != null && !validLevels.contains(level)) return false;
|
||||||
|
|
||||||
int oldLevel = this.skillLevelMap.getOrDefault(skillId, 0); // just taking the return value of put would have null concerns
|
int oldLevel = this.skillLevelMap.getOrDefault(skillId, 0); // just taking the return value of put would have null concerns
|
||||||
this.skillLevelMap.put(skillId, level);
|
this.skillLevelMap.put(skillId, level);
|
||||||
this.save();
|
this.save();
|
||||||
|
|
||||||
// Packet
|
// Packet
|
||||||
this.getPlayer().sendPacket(new PacketAvatarSkillChangeNotify(this, skillId, oldLevel, level));
|
val player = this.getPlayer();
|
||||||
this.getPlayer().sendPacket(new PacketAvatarSkillUpgradeRsp(this, skillId, oldLevel, level));
|
if (player != null) {
|
||||||
|
player.sendPacket(new PacketAvatarSkillChangeNotify(this, skillId, oldLevel, level));
|
||||||
|
player.sendPacket(new PacketAvatarSkillUpgradeRsp(this, skillId, oldLevel, level));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user