use of main.content.enums.entity.ItemEnums.ITEM_RARITY in project Eidolons by IDemiurge.
the class ContainerMaster method getItem.
public ObjType getItem(CONTAINER_CONTENTS c, int maxCost) {
int random = RandomWizard.getRandomInt(100);
ITEM_RARITY rarity = ITEM_RARITY.COMMON;
for (ITEM_RARITY sub : ITEM_RARITY.values()) {
if (sub.getChance() >= random) {
rarity = sub;
break;
}
}
main.system.auxiliary.log.LogMaster.log(1, "getItem " + c + "; " + rarity + maxCost);
ObjType type = preselectBaseType(c, rarity);
main.system.auxiliary.log.LogMaster.log(1, "preselectBaseType " + type);
if (type == null)
return null;
// base types!
List<ObjType> pool = new ArrayList<>(getItemPool(c, rarity, type));
main.system.auxiliary.log.LogMaster.log(1, "pool= " + pool);
if (pool.isEmpty())
return null;
if (isRemoveBase(c, type))
pool.removeIf(item -> !item.isGenerated());
else {
pool.size();
}
if (pool.isEmpty())
return null;
pool.removeIf(item -> item.getIntParam(PARAMS.GOLD_COST) > maxCost);
if (pool.isEmpty())
return null;
if (pool.size() > 20) {
SortMaster.sortEntitiesByExpression(pool, (item) -> item.getIntParam(PARAMS.GOLD_COST));
pool.removeIf(item -> pool.indexOf(item) > pool.size() / 2);
}
main.system.auxiliary.log.LogMaster.log(1, "filtered pool= " + pool + " max cost: " + maxCost);
if (pool.isEmpty())
return null;
ObjType baseType = new RandomWizard<ObjType>().getRandomListItem(pool);
return baseType;
}
Aggregations