Refactor LootInventory & LootManager
This commit is contained in:
@@ -30,13 +30,13 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* @author Ronan
|
* @author Ronan
|
||||||
*/
|
*/
|
||||||
public class LootInventory {
|
class LootInventory {
|
||||||
Map<Integer, Integer> items = new HashMap<>(50);
|
private final Map<Integer, Integer> items = new HashMap<>(50);
|
||||||
|
|
||||||
public LootInventory(Character from) {
|
LootInventory(Character from) {
|
||||||
for (InventoryType values : InventoryType.values()) {
|
for (InventoryType invType : InventoryType.values()) {
|
||||||
|
|
||||||
for (Item it : from.getInventory(values).list()) {
|
for (Item it : from.getInventory(invType).list()) {
|
||||||
Integer itemQty = items.get(it.getItemId());
|
Integer itemQty = items.get(it.getItemId());
|
||||||
|
|
||||||
if (itemQty == null) {
|
if (itemQty == null) {
|
||||||
@@ -48,9 +48,9 @@ public class LootInventory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hasItem(int itemid, int quantity) {
|
boolean hasItem(int itemId, int quantity) {
|
||||||
Integer itemQty = items.get(itemid);
|
Integer itemQty = items.get(itemId);
|
||||||
return itemQty == null ? 0 : itemQty >= quantity ? 2 : itemQty > 0 ? 1 : 0;
|
return itemQty != null && itemQty >= quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import server.life.MonsterDropEntry;
|
|||||||
import server.life.MonsterInformationProvider;
|
import server.life.MonsterInformationProvider;
|
||||||
import server.quest.Quest;
|
import server.quest.Quest;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,66 +32,50 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class LootManager {
|
public class LootManager {
|
||||||
|
|
||||||
private static boolean isRelevantDrop(MonsterDropEntry dropEntry, List<Character> players, List<LootInventory> playersInv) {
|
private static boolean isRelevantDrop(MonsterDropEntry dropEntry, List<Character> chrs, List<LootInventory> inventories) {
|
||||||
int qStartAmount = 0, qCompleteAmount = 0;
|
if (dropEntry.questid <= 0) {
|
||||||
Quest quest = Quest.getInstance(dropEntry.questid);
|
return true;
|
||||||
if (quest != null) {
|
|
||||||
qStartAmount = quest.getStartItemAmountNeeded(dropEntry.itemId);
|
|
||||||
qCompleteAmount = quest.getCompleteItemAmountNeeded(dropEntry.itemId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//boolean restricted = ItemInformationProvider.getInstance().isPickupRestricted(dropEntry.itemId);
|
Quest quest = Quest.getInstance(dropEntry.questid);
|
||||||
for (int i = 0; i < players.size(); i++) {
|
int questStartAmount = quest.getStartItemAmountNeeded(dropEntry.itemId);
|
||||||
LootInventory chrInv = playersInv.get(i);
|
int questCompleteAmount = quest.getCompleteItemAmountNeeded(dropEntry.itemId);
|
||||||
|
|
||||||
if (dropEntry.questid > 0) {
|
for (int i = 0; i < chrs.size(); i++) {
|
||||||
int qItemAmount, chrQuestStatus = players.get(i).getQuestStatus(dropEntry.questid);
|
|
||||||
if (chrQuestStatus == 0) {
|
|
||||||
qItemAmount = qStartAmount;
|
|
||||||
} else if (chrQuestStatus != 1) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
qItemAmount = qCompleteAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
// thanks kvmba for noticing quest items with no required amount failing to be detected as such
|
int chrQuestStatus = chrs.get(i).getQuestStatus(dropEntry.questid);
|
||||||
|
final int questItemAmount;
|
||||||
int qItemStatus = chrInv.hasItem(dropEntry.itemId, qItemAmount);
|
if (chrQuestStatus == 0) {
|
||||||
if (qItemStatus == 2) {
|
questItemAmount = questStartAmount;
|
||||||
continue;
|
} else if (chrQuestStatus == 1) {
|
||||||
} /*else if (restricted && qItemStatus == 1) { // one-of-a-kind loots should be available everytime, thanks onechord for noticing
|
questItemAmount = questCompleteAmount;
|
||||||
continue;
|
} else {
|
||||||
}*/
|
|
||||||
} /*else if (restricted && chrInv.hasItem(dropEntry.itemId, 1) > 0) { // thanks Conrad, Legalize for noticing eligible loots not being available to drop for non-killer parties
|
|
||||||
continue;
|
continue;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
return true;
|
LootInventory chrInv = inventories.get(i);
|
||||||
|
boolean hasQuestItems = chrInv.hasItem(dropEntry.itemId, questItemAmount);
|
||||||
|
if (!hasQuestItems) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<MonsterDropEntry> retrieveRelevantDrops(int monsterId, List<Character> players) {
|
public static List<MonsterDropEntry> retrieveRelevantDrops(int monsterId, List<Character> chrs) {
|
||||||
List<MonsterDropEntry> loots = MonsterInformationProvider.getInstance().retrieveEffectiveDrop(monsterId);
|
List<MonsterDropEntry> drops = MonsterInformationProvider.getInstance().retrieveEffectiveDrop(monsterId);
|
||||||
if (loots.isEmpty()) {
|
if (drops.isEmpty()) {
|
||||||
return loots;
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<LootInventory> playersInv = new LinkedList<>();
|
List<LootInventory> inventories = chrs.stream()
|
||||||
for (Character chr : players) {
|
.map(LootInventory::new)
|
||||||
LootInventory lootInv = new LootInventory(chr);
|
.toList();
|
||||||
playersInv.add(lootInv);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<MonsterDropEntry> effectiveLoot = new LinkedList<>();
|
return drops.stream()
|
||||||
for (MonsterDropEntry mde : loots) {
|
.filter(entry -> isRelevantDrop(entry, chrs, inventories))
|
||||||
if (isRelevantDrop(mde, players, playersInv)) {
|
.toList();
|
||||||
effectiveLoot.add(mde);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return effectiveLoot;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user