Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend give command "skill level" & shortening /talent all #1865

Merged
merged 15 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Extend give command "talent"
  • Loading branch information
natsurepo committed Oct 16, 2022
commit 0b253cf46f33519e5cf0b2a4139a06631e4e7ecb
1 change: 1 addition & 0 deletions src/main/java/emu/grasscutter/command/CommandHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class CommandHelpers {
public static final Pattern refineRegex = Pattern.compile("r(\\d+)");
public static final Pattern rankRegex = Pattern.compile("(\\d+)\\*");
public static final Pattern constellationRegex = Pattern.compile("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+)");
Expand Down
27 changes: 14 additions & 13 deletions src/main/java/emu/grasscutter/command/commands/GiveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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",
Expand All @@ -47,7 +47,8 @@ private enum GiveAllType {
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 {
Expand All @@ -56,6 +57,7 @@ private static class GiveItemParameters {
@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;
Expand Down Expand Up @@ -212,30 +214,29 @@ public void execute(Player sender, Player targetPlayer, List<String> args) {
}

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.changeSkillLevel(skillLevel);
avatar.forceConstellationLevel(constellation);
avatar.recalcStats();
avatar.recalcConstellations();
natsurepo marked this conversation as resolved.
Show resolved Hide resolved
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);
}
}

Expand Down Expand Up @@ -372,7 +373,7 @@ private static void parseRelicArgs(GiveItemParameters param, List<String> args)
for (int i = 0; i < n; i++) {
param.appendPropIdList.add(appendPropId);
}
};
}
}

private static void addItemsChunked(Player player, List<GameItem> items, int packetSize) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,8 @@ public void execute(Player sender, Player targetPlayer, List<String> args) {
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.getCombatSkills().forEach(id -> setTalentLevel(sender, avatar, id, finalNewLevel));
}
case "getid" -> {
var map = GameData.getAvatarSkillDataMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,10 @@ public IntStream getSkillsAndEnergySkill() {
return IntStream.concat(this.skills.stream().mapToInt(i -> i), IntStream.of(this.energySkill))
.filter(skillId -> skillId > 0);
}

public IntStream getCombatSkills() {
return IntStream.concat(IntStream.of(this.getSkills().get(0), this.getSkills().get(1)), IntStream.of(this.energySkill))
natsurepo marked this conversation as resolved.
Show resolved Hide resolved
.filter(SkillId -> SkillId > 0);
}

}
9 changes: 9 additions & 0 deletions src/main/java/emu/grasscutter/game/avatar/Avatar.java
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,15 @@ public boolean setSkillLevel(int skillId, int level) {
return true;
}

public void changeSkillLevel(int skillLevel) {
natsurepo marked this conversation as resolved.
Show resolved Hide resolved
if (skillLevel < 1) skillLevel = 1;
if (skillLevel > 12) skillLevel = 12; // Set max to 12 at the moment instead of 15 (it will conflict with constellation's talent level bonus)
natsurepo marked this conversation as resolved.
Show resolved Hide resolved
int finalSkillLevel = skillLevel;
skillDepot.getCombatSkills().forEach(id -> this.skillLevelMap.put(id, finalSkillLevel));
this.save();
this.recalcStats(true);
}

public boolean unlockConstellation() {
return this.unlockConstellation(false);
}
Expand Down