Sort initial relic sub affixes like on official server

Relics created by commands are not affected, unless the "-sorted" flag is added
This commit is contained in:
Melledy 2024-02-06 23:09:26 -08:00
parent 1bad1b85a5
commit f67450203d
3 changed files with 19 additions and 1 deletions

View File

@ -268,6 +268,8 @@ public class CommandArgs {
} }
item.getSubAffixes().forEach(subAffix -> subAffix.setStep(subAffix.getCount() * 2)); item.getSubAffixes().forEach(subAffix -> subAffix.setStep(subAffix.getCount() * 2));
} if (this.hasFlag("-sorted")) {
item.sortSubAffixes();
} }
} }

View File

@ -1,6 +1,7 @@
package emu.lunarcore.game.inventory; package emu.lunarcore.game.inventory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.bson.types.ObjectId; import org.bson.types.ObjectId;
@ -103,6 +104,8 @@ public class GameItem {
// Sub affixes // Sub affixes
int baseSubAffixes = Math.min(Math.max(getExcel().getRarity().getVal() - 2, 0), 3); int baseSubAffixes = Math.min(Math.max(getExcel().getRarity().getVal() - 2, 0), 3);
this.addSubAffixes(Utils.randomRange(baseSubAffixes, baseSubAffixes + 1)); this.addSubAffixes(Utils.randomRange(baseSubAffixes, baseSubAffixes + 1));
// Sort sub affixes
this.sortSubAffixes();
} }
break; break;
default: default:
@ -239,6 +242,14 @@ public class GameItem {
return (getExcel().getRarity().getVal() - 1) + (int) Math.floor(this.getLevel() / 3.0); return (getExcel().getRarity().getVal() - 1) + (int) Math.floor(this.getLevel() / 3.0);
} }
public void sortSubAffixes() {
if (this.subAffixes == null || this.subAffixes.size() == 0) {
return;
}
Collections.sort(this.subAffixes);
}
// Database // Database
public void save() { public void save() {

View File

@ -9,7 +9,7 @@ import lombok.Setter;
@Getter @Getter
@Entity(useDiscriminator = false) @Entity(useDiscriminator = false)
public class GameItemSubAffix { public class GameItemSubAffix implements Comparable<GameItemSubAffix> {
private int id; // Affix id private int id; // Affix id
@Setter private int count; @Setter private int count;
@ -43,4 +43,9 @@ public class GameItemSubAffix {
return proto; return proto;
} }
@Override
public int compareTo(GameItemSubAffix o) {
return this.getId() - o.getId();
}
} }