Skip to content

Commit

Permalink
Extend give command "skill level" & shortening /talent all (#1865)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
natsurepo and Birdulon committed Oct 18, 2022
1 parent b5940da commit 2b08738
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
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("(?<!\\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+)");
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 @@ -5,6 +5,7 @@
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;
Expand All @@ -29,7 +30,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 +48,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 +58,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 +215,28 @@ 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.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);
}
}

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.getSkillsAndEnergySkill().forEach(id -> setTalentLevel(sender, avatar, id, finalNewLevel));
}
case "getid" -> {
var map = GameData.getAvatarSkillDataMap();
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/emu/grasscutter/game/avatar/Avatar.java
Original file line number Diff line number Diff line change
Expand Up @@ -750,14 +750,16 @@ public boolean setSkillLevel(int skillId, int level) {
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;
}

Expand Down

0 comments on commit 2b08738

Please sign in to comment.