Fix commission bonus rewards

This commit is contained in:
Melledy
2025-11-28 14:29:57 -08:00
parent 7577bf87d4
commit 29db60fd0a
2 changed files with 112 additions and 7 deletions
@@ -1,10 +1,15 @@
package emu.nebula.data.resources;
import java.util.List;
import emu.nebula.data.BaseDef;
import emu.nebula.data.ResourceType;
import emu.nebula.game.character.GameCharacter;
import emu.nebula.game.inventory.ItemRewardList;
import emu.nebula.game.inventory.ItemRewardParam;
import emu.nebula.util.JsonUtils;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import lombok.Getter;
@@ -35,6 +40,8 @@ public class AgentDef extends BaseDef {
private String BonusPreview4;
private transient Int2ObjectMap<AgentDurationDef> durations;
private transient Int2IntOpenHashMap tags;
private transient Int2IntOpenHashMap extraTags;
@Override
public int getId() {
@@ -45,14 +52,83 @@ public class AgentDef extends BaseDef {
this.durations.put(duration.getTime(), duration);
}
public boolean hasTags(List<GameCharacter> characters) {
// Get character tags
var characterTags = new Int2IntOpenHashMap();
for (var character : characters) {
var data = character.getData().getDes();
for (int tag : data.getTag()) {
characterTags.addTo(tag, 1);
}
}
// Validate that we have the tags
for (var entry : this.tags.int2IntEntrySet()) {
int reqTagId = entry.getIntKey();
int reqTagCount = entry.getIntValue();
// Get amount of tags that we have from our characters
int characterTagCount = characterTags.get(reqTagId);
if (reqTagCount > characterTagCount) {
return false;
}
}
return true;
}
public boolean hasExtraTags(List<GameCharacter> characters) {
// Get character tags
var characterTags = new Int2IntOpenHashMap();
for (var character : characters) {
var data = character.getData().getDes();
for (int tag : data.getTag()) {
characterTags.addTo(tag, 1);
}
}
// Validate that we have the tags
for (var entry : this.extraTags.int2IntEntrySet()) {
int reqTagId = entry.getIntKey();
int reqTagCount = entry.getIntValue();
// Get amount of tags that we have from our characters
int characterTagCount = characterTags.get(reqTagId);
if (reqTagCount > characterTagCount) {
return false;
}
}
return true;
}
@Override
public void onLoad() {
// Cache durations
this.durations = new Int2ObjectOpenHashMap<>();
this.addDuration(new AgentDurationDef(this.Time1, this.RewardPreview1, this.BonusPreview1));
this.addDuration(new AgentDurationDef(this.Time2, this.RewardPreview2, this.BonusPreview2));
this.addDuration(new AgentDurationDef(this.Time3, this.RewardPreview3, this.BonusPreview3));
this.addDuration(new AgentDurationDef(this.Time4, this.RewardPreview4, this.BonusPreview4));
// Cache tags
this.tags = new Int2IntOpenHashMap();
this.extraTags = new Int2IntOpenHashMap();
for (int tag : this.Tags) {
this.tags.addTo(tag, 1);
}
for (int tag : this.ExtraTags) {
this.extraTags.addTo(tag, 1);
}
}
@Getter