Search in sources :

Example 1 with CONTAINER_CONTENT_VALUE

use of main.content.enums.entity.DungeonObjEnums.CONTAINER_CONTENT_VALUE 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);
}
Also used : CONTAINER_CONTENT_VALUE(main.content.enums.entity.DungeonObjEnums.CONTAINER_CONTENT_VALUE) Loop(main.system.auxiliary.Loop) CONTAINER_CONTENTS(main.content.enums.entity.DungeonObjEnums.CONTAINER_CONTENTS) ObjType(main.entity.type.ObjType) RandomWizard(main.system.auxiliary.RandomWizard)

Aggregations

CONTAINER_CONTENTS (main.content.enums.entity.DungeonObjEnums.CONTAINER_CONTENTS)1 CONTAINER_CONTENT_VALUE (main.content.enums.entity.DungeonObjEnums.CONTAINER_CONTENT_VALUE)1 ObjType (main.entity.type.ObjType)1 Loop (main.system.auxiliary.Loop)1 RandomWizard (main.system.auxiliary.RandomWizard)1