mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-12 20:34:36 +01:00
Fix commission bonus rewards
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -8,6 +8,7 @@ import dev.morphia.annotations.Entity;
|
||||
import dev.morphia.annotations.Id;
|
||||
import emu.nebula.data.GameData;
|
||||
import emu.nebula.database.GameDatabaseObject;
|
||||
import emu.nebula.game.character.GameCharacter;
|
||||
import emu.nebula.game.player.Player;
|
||||
import emu.nebula.game.player.PlayerChangeInfo;
|
||||
import emu.nebula.game.player.PlayerManager;
|
||||
@@ -58,13 +59,23 @@ public class AgentManager extends PlayerManager implements GameDatabaseObject {
|
||||
}
|
||||
|
||||
// Make sure we own the characters
|
||||
var characters = new ArrayList<GameCharacter>();
|
||||
|
||||
for (int charId : charIds) {
|
||||
if (!getPlayer().getCharacters().hasCharacter(charId)) {
|
||||
var character = getPlayer().getCharacters().getCharacterById(charId);
|
||||
|
||||
// Also check if character fits the commission level requirement
|
||||
if (character == null || character.getLevel() < data.getLevel()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
characters.add(character);
|
||||
}
|
||||
|
||||
// TODO verify char tags for rewards
|
||||
// Check char tags
|
||||
if (!data.hasTags(characters)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create agent
|
||||
var agent = new Agent(data, processTime, charIds.toArray());
|
||||
@@ -139,12 +150,30 @@ public class AgentManager extends PlayerManager implements GameDatabaseObject {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create rewards
|
||||
var rewards = duration.getRewards().generate();
|
||||
result.setRewards(rewards);
|
||||
// Check if we had extra tags
|
||||
var characters = new ArrayList<GameCharacter>();
|
||||
|
||||
// Add to inventory
|
||||
this.getPlayer().getInventory().addItems(rewards, change);
|
||||
for (int charId : agent.getCharIds()) {
|
||||
var character = getPlayer().getCharacters().getCharacterById(charId);
|
||||
if (character == null) continue;
|
||||
|
||||
characters.add(character);
|
||||
}
|
||||
|
||||
// Create rewards
|
||||
result.setRewards(duration.getRewards().generate());
|
||||
|
||||
// Add rewards to inventory
|
||||
this.getPlayer().getInventory().addItems(result.getRewards(), change);
|
||||
|
||||
// Add bonus rewards if we meet the requirements
|
||||
if (data.hasExtraTags(characters)) {
|
||||
// Get bonus rewards
|
||||
result.setBonus(duration.getBonus().generate());
|
||||
|
||||
// Add rewards to inventory
|
||||
this.getPlayer().getInventory().addItems(result.getBonus(), change);
|
||||
}
|
||||
}
|
||||
|
||||
// Set results in change info
|
||||
|
||||
Reference in New Issue
Block a user