Add -maxsteps and -takerewards flags to commands

This commit is contained in:
Melledy
2023-12-30 16:46:10 -08:00
parent 09fba3bc9b
commit ed1f292af0
3 changed files with 47 additions and 2 deletions

View File

@@ -11,6 +11,8 @@ import emu.lunarcore.game.player.Player;
import emu.lunarcore.util.Utils;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import it.unimi.dsi.fastutil.objects.ObjectSet;
import lombok.Getter;
@Getter
@@ -28,6 +30,7 @@ public class CommandArgs {
private int stage = -1;
private Int2IntMap map;
private ObjectSet<String> flags;
public CommandArgs(Player sender, List<String> args) {
this.sender = sender;
@@ -64,6 +67,10 @@ public class CommandArgs {
this.stage = Utils.parseSafeInt(arg.substring(1));
it.remove();
}
} else if (arg.startsWith("-")) { // Flag
if (this.flags == null) this.flags = new ObjectOpenHashSet<>();
this.flags.add(arg);
it.remove();
} else if (arg.contains(":")) {
String[] split = arg.split(":");
if (split.length >= 2) {
@@ -118,6 +125,11 @@ public class CommandArgs {
}
}
public boolean hasFlag(String flag) {
if (this.flags == null) return false;
return this.flags.contains(flag);
}
// Utility commands
/**
@@ -161,6 +173,17 @@ public class CommandArgs {
hasChanged = true;
}
// Handle flags
if (this.hasFlag("-takerewards")) {
if (avatar.setRewards(0b00101010)) {
hasChanged = true;
}
} else if (this.hasFlag("-clearrewards")) {
if (avatar.setRewards(0)) { // Note: Requires the player to restart their game to show
hasChanged = true;
}
}
return hasChanged;
}
@@ -237,6 +260,15 @@ public class CommandArgs {
hasChanged = true;
}
// Handle flags
if (this.hasFlag("-maxsteps")) {
if (item.getSubAffixes() == null) {
item.resetSubAffixes();
}
item.getSubAffixes().forEach(subAffix -> subAffix.setStep(subAffix.getCount() * 2));
}
}
return hasChanged;

View File

@@ -195,6 +195,17 @@ public class GameAvatar implements GameEntity {
this.heroPath.setAvatar(this);
}
// Rewards
public boolean setRewards(int flag) {
if (this.rewards != flag) {
this.rewards = flag;
return true;
}
return false;
}
public boolean hasTakenReward(int promotion) {
return (this.rewards & (1 << promotion)) != 0;
}

View File

@@ -5,13 +5,15 @@ import emu.lunarcore.data.excel.RelicSubAffixExcel;
import emu.lunarcore.proto.RelicAffixOuterClass.RelicAffix;
import emu.lunarcore.util.Utils;
import lombok.Getter;
import lombok.Setter;
@Getter
@Entity(useDiscriminator = false)
public class GameItemSubAffix {
private int id; // Affix id
private int count;
private int step;
@Setter private int count;
@Setter private int step;
@Deprecated
public GameItemSubAffix() {