Skip to content

Commit

Permalink
Add -maxsteps and -takerewards flags to commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Melledy committed Dec 31, 2023
1 parent 09fba3b commit ed1f292
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
32 changes: 32 additions & 0 deletions src/main/java/emu/lunarcore/command/CommandArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
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
Expand All @@ -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;
Expand Down Expand Up @@ -64,6 +67,10 @@ public CommandArgs(Player sender, List<String> args) {
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) {
Expand Down Expand Up @@ -118,6 +125,11 @@ public void sendMessage(String message) {
}
}

public boolean hasFlag(String flag) {
if (this.flags == null) return false;
return this.flags.contains(flag);
}

// Utility commands

/**
Expand Down Expand Up @@ -161,6 +173,17 @@ public boolean setProperties(GameAvatar avatar) {
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;
}

Expand Down Expand Up @@ -237,6 +260,15 @@ public boolean setProperties(GameItem item) {

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;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/emu/lunarcore/game/avatar/GameAvatar.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ public void setHeroPath(AvatarHeroPath heroPath) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
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() {
Expand Down

0 comments on commit ed1f292

Please sign in to comment.