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:
natsu 2022-10-18 16:15:24 +07:00 committed by GitHub
parent b5940da36b
commit 2b08738043
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 20 deletions

View File

@ -13,6 +13,7 @@ public class CommandHelpers {
public static final Pattern refineRegex = Pattern.compile("(?<!\\w)r(\\d+)");
public static final Pattern rankRegex = Pattern.compile("(\\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 blockRegex = Pattern.compile("blk(\\d+)");
public static final Pattern groupRegex = Pattern.compile("grp(\\d+)");

View File

@ -5,6 +5,7 @@ import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.GameDepot;
import emu.grasscutter.data.excels.AvatarData;
import emu.grasscutter.data.excels.AvatarSkillDepotData;
import emu.grasscutter.data.excels.ItemData;
import emu.grasscutter.data.excels.ReliquaryAffixData;
import emu.grasscutter.data.excels.ReliquaryMainPropData;
@ -29,7 +30,7 @@ import static emu.grasscutter.command.CommandHelpers.*;
label = "give",
aliases = {"g", "item", "giveitem"},
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>]]..."},
permission = "player.give",
permissionTargeted = "player.give.others",
@ -47,7 +48,8 @@ public final class GiveCommand implements CommandHandler {
Map.entry(lvlRegex, GiveItemParameters::setLvl),
Map.entry(refineRegex, GiveItemParameters::setRefinement),
Map.entry(amountRegex, GiveItemParameters::setAmount),
Map.entry(constellationRegex, GiveItemParameters::setConstellation)
Map.entry(constellationRegex, GiveItemParameters::setConstellation),
Map.entry(skillLevelRegex, GiveItemParameters::setSkillLevel)
);
private static class GiveItemParameters {
@ -56,6 +58,7 @@ public final class GiveCommand implements CommandHandler {
@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;
@ -212,30 +215,28 @@ public final class GiveCommand implements CommandHandler {
}
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.setLevel(level);
avatar.setPromoteLevel(promoteLevel);
avatar.getSkillDepot().getSkillsAndEnergySkill().forEach(id -> avatar.setSkillLevel(id, skillLevel));
avatar.forceConstellationLevel(constellation);
avatar.recalcStats();
avatar.recalcStats(true);
avatar.save();
return avatar;
}
private static void giveAllAvatars(Player player, GiveItemParameters param) {
int promoteLevel = Avatar.getMinPromoteLevel(param.lvl);
if (param.constellation < 0) {
param.constellation = 6;
}
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
for (AvatarData avatarData : GameData.getAvatarDataMap().values()) {
// Exclude test avatars
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
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++) {
param.appendPropIdList.add(appendPropId);
}
};
}
}
private static void addItemsChunked(Player player, List<GameItem> items, int packetSize) {

View File

@ -103,10 +103,8 @@ public final class TalentCommand implements CommandHandler {
CommandHandler.sendTranslatedMessage(sender, "commands.talent.out_of_range");
return;
}
// This is small so array is not needed imo
setTalentLevel(sender, avatar, skillDepot.getSkills().get(0), newLevel);
setTalentLevel(sender, avatar, skillDepot.getSkills().get(1), newLevel);
setTalentLevel(sender, avatar, skillDepot.getEnergySkill(), newLevel);
int finalNewLevel = newLevel;
skillDepot.getSkillsAndEnergySkill().forEach(id -> setTalentLevel(sender, avatar, id, finalNewLevel));
}
case "getid" -> {
var map = GameData.getAvatarSkillDataMap();

View File

@ -750,14 +750,16 @@ public class Avatar {
if (level < 0 || level > 15) return false;
var validLevels = GameData.getAvatarSkillLevels(skillId);
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
this.skillLevelMap.put(skillId, level);
this.save();
// Packet
this.getPlayer().sendPacket(new PacketAvatarSkillChangeNotify(this, skillId, oldLevel, level));
this.getPlayer().sendPacket(new PacketAvatarSkillUpgradeRsp(this, skillId, oldLevel, level));
val player = this.getPlayer();
if (player != null) {
player.sendPacket(new PacketAvatarSkillChangeNotify(this, skillId, oldLevel, level));
player.sendPacket(new PacketAvatarSkillUpgradeRsp(this, skillId, oldLevel, level));
}
return true;
}