use of main.content.enums.entity.DungeonObjEnums.CONTAINER_CONTENTS 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;
}
use of main.content.enums.entity.DungeonObjEnums.CONTAINER_CONTENTS in project Eidolons by IDemiurge.
the class ContainerMaster method initContents.
public void initContents(BattleFieldObject obj) {
String contents = "";
RandomWizard<CONTAINER_CONTENTS> wizard = new RandomWizard<>();
String prop = obj.getProperty(PROPS.CONTAINER_CONTENTS);
if (test_mode)
prop = "Food(10);";
Map<CONTAINER_CONTENTS, Integer> map = wizard.constructWeightMap(prop, CONTAINER_CONTENTS.class);
prop = obj.getProperty(PROPS.CONTAINER_CONTENT_VALUE);
RandomWizard<CONTAINER_CONTENT_VALUE> wizard_ = new RandomWizard<>();
Map<CONTAINER_CONTENT_VALUE, Integer> typeMap = wizard_.constructWeightMap(prop, CONTAINER_CONTENT_VALUE.class);
List<CONTAINER_CONTENT_VALUE> itemValueList = new ArrayList<>();
Integer maxCost = obj.getIntParam(PARAMS.GOLD_TOTAL);
int totalCost = 0;
// size prop!
int maxGroups = 2;
Loop overLoop = new Loop(maxGroups);
while (overLoop.continues()) {
CONTAINER_CONTENT_VALUE rarity = wizard_.getObjectByWeight(typeMap);
if (rarity == null)
rarity = CONTAINER_CONTENT_VALUE.COMMON;
if (noDuplicates)
typeMap.remove(rarity);
if (totalCost + rarity.getGoldCost() > maxCost)
break;
itemValueList.add(rarity);
totalCost += rarity.getGoldCost();
}
float randomization = (isRandomizationOn()) ? new Random().nextFloat() + 0.5f : 1;
for (CONTAINER_CONTENT_VALUE rarity : itemValueList) {
maxCost = Math.round(randomization * Math.min(totalCost, rarity.getGoldCost()));
CONTAINER_CONTENTS c = wizard.getObjectByWeight(map);
if (noDuplicates)
map.remove(c);
Integer maxItems = c.getMaxItems();
Integer cost = 0;
int items = 0;
Loop loop = new Loop(maxItems * 3);
while (cost < maxCost && items <= maxItems) {
if (!loop.continues())
break;
int max = Math.round((maxCost - cost) * 1.2f);
ObjType item = getItem(c, max);
if (item == null)
if (c == CONTAINER_CONTENTS.FOOD)
continue;
main.system.auxiliary.log.LogMaster.log(1, c + " rarity " + rarity + " = " + item + "; total : " + cost);
if (item == null)
continue;
contents += item.getName() + StringMaster.SEPARATOR;
cost += item.getIntParam(PARAMS.GOLD_COST);
items++;
}
}
if (contents.isEmpty()) {
main.system.auxiliary.log.LogMaster.log(1, ">> " + obj + " has contents: " + contents + itemValueList);
} else
main.system.auxiliary.log.LogMaster.log(1, ">> " + obj + " has contents: " + contents + itemValueList);
obj.setProperty(PROPS.INVENTORY, contents);
}
Aggregations