Search in sources :

Example 1 with WeightMap

use of main.system.datatypes.WeightMap in project Eidolons by IDemiurge.

the class UnitShop method buy.

private static boolean buy(String repertoire, Unit unit, ITEM_SLOT slot, OBJ_TYPE OBJ_TYPE_ENUM) {
    // Map<ObjType, Integer>
    List<ObjType> itemPool = new ArrayList<>();
    // ++ add weight! choose from repertoire!
    WeightMap<ObjType> map = new WeightMap<>(new RandomWizard<ObjType>().constructWeightMap(repertoire, ObjType.class, OBJ_TYPE_ENUM));
    Loop.startLoop(map.size());
    while (!Loop.loopEnded() && !map.isEmpty()) {
        ObjType baseType = getItem(map);
        map.remove(baseType);
        if (baseType == null) {
            // *empty*
            return false;
        }
        for (ObjType type : DataManager.getTypes(OBJ_TYPE_ENUM)) {
            if (!checkItemType(type, baseType)) {
                continue;
            }
            if (!checkCanEquip(baseType, unit, slot)) {
                continue;
            }
            if (!specialCheck(unit, type)) {
                continue;
            }
            // TODO for potions/jewelry?
            if (// for potions/ammo?
            !checkQualityRange(type, unit)) {
                continue;
            }
            itemPool.add(type);
        }
        try {
            itemPool = (List<ObjType>) SortMaster.sortByValue(itemPool, PARAMS.GOLD_COST, true);
        } catch (Exception e) {
            main.system.ExceptionMaster.printStackTrace(e);
        }
        DC_HeroItemObj item = null;
        for (ObjType type : itemPool) {
            // sort by cost? then go from top to bottom trying to buy...
            if (!checkCost(type, unit)) {
                continue;
            }
            item = buy(type, unit);
            break;
        }
        if (item == null) {
            continue;
        }
        equip(unit, item, slot);
        return true;
    }
    return false;
// ++ sell TODO
}
Also used : ObjType(main.entity.type.ObjType) RandomWizard(main.system.auxiliary.RandomWizard) ArrayList(java.util.ArrayList) DC_HeroItemObj(eidolons.entity.item.DC_HeroItemObj) WeightMap(main.system.datatypes.WeightMap)

Example 2 with WeightMap

use of main.system.datatypes.WeightMap in project Eidolons by IDemiurge.

the class UnitTrainer method initXpItemPool.

private static WeightMap<ObjType> initXpItemPool(Unit trainee) {
    if (StringMaster.isEmpty(getPlan(trainee)) || getPlan(trainee).contains(StringMaster.BASE_CHAR)) {
        generateSkillPlan(trainee);
    }
    WeightMap<ObjType> pool = new WeightMap<>();
    Map<ObjType, Integer> map = new RandomWizard<ObjType>().constructWeightMap(getPlan(trainee), ObjType.class, DC_TYPE.SKILLS);
    for (ObjType type : map.keySet()) {
        if (type == null)
            continue;
        if (trainee.checkProperty(PROPS.SKILLS, type.getName())) {
            // TODO ++ exceptions
            continue;
        }
        String reason = trainee.getGame().getRequirementsManager().check(trainee, type);
        if (reason != null) {
            continue;
        }
        pool.put(type, map.get(type));
    // we really can't have weights here - must be more or less
    // sequential, since it'll be skill trees!
    // and i dont wanna override reqs
    }
    // random-pick
    return pool;
}
Also used : ObjType(main.entity.type.ObjType) WeightMap(main.system.datatypes.WeightMap)

Example 3 with WeightMap

use of main.system.datatypes.WeightMap in project Eidolons by IDemiurge.

the class RandomWizard method constructWeightMap.

public WeightMap<E> constructWeightMap(String property, Class<? extends E> CLASS, OBJ_TYPE TYPE, boolean inverse) {
    WeightMap<E> map = new WeightMap<>();
    if (inverse) {
        invertedMap = new LinkedHashMap<>();
    }
    for (String string : StringMaster.open(property)) {
        Integer value = 0;
        try {
            value = StringMaster.getWeight(string, inverse);
        } catch (Exception e) {
            main.system.ExceptionMaster.printStackTrace(e);
        }
        if (value <= 0) {
            value = 1;
        }
        string = StringMaster.getWeightItem(string, inverse);
        E object;
        if (CLASS != ObjType.class) {
            object = new EnumMaster<E>().retrieveEnumConst(CLASS, string);
        } else {
            object = (E) DataManager.getType(string, TYPE);
            if (object == null) {
                object = (E) DataManager.findType(string, TYPE);
            }
        }
        // if (object != null) //EMPTY option allowed!
        map.put(object, value);
        if (inverse) {
            invertedMap.put(value, object);
        }
    }
    return map;
}
Also used : OBJ_TYPE(main.content.OBJ_TYPE) WeightMap(main.system.datatypes.WeightMap)

Example 4 with WeightMap

use of main.system.datatypes.WeightMap in project Eidolons by IDemiurge.

the class UnitShop method buyNew.

public static boolean buyNew(String repertoire, Unit unit, ITEM_SLOT slot, int costLimit, boolean canExceed, OBJ_TYPE OBJ_TYPE_ENUM) {
    // choose instead of stumble
    WeightMap<ObjType> map = new WeightMap<>(new RandomWizard<ObjType>().constructWeightMap(repertoire, ObjType.class, OBJ_TYPE_ENUM));
    // TODO preconstruct more item types?
    if (map.isEmpty()) {
        return false;
    }
    ObjType baseType = getItem(map);
    MATERIAL materialType = chooseMaterialType(costLimit, unit, baseType, canExceed);
    ObjType itemType = null;
    if (materialType != null) {
        itemType = chooseQualityForItem(materialType, costLimit, unit, baseType, canExceed);
    } else {
        if (baseType.getOBJ_TYPE_ENUM() != DC_TYPE.ITEMS)
            return false;
        List<ObjType> types = DataManager.getUpgradedTypes(baseType);
        // types = (List<ObjType>) SortMaster.sortByValue(types, PARAMS.GOLD_COST, true);
        SortMaster.sortEntitiesByExpression(types, (type) -> -type.getIntParam(PARAMS.GOLD_COST));
        for (ObjType type : types) {
            if (!checkCost(type, unit)) {
                continue;
            }
            itemType = type;
            break;
        }
    }
    if (itemType == null) {
        // return buy(repertoire, unit, slot, OBJ_TYPE_ENUM);
        return false;
    }
    DC_HeroItemObj item = buy(itemType, unit);
    equip(unit, item, slot);
    return true;
}
Also used : ObjType(main.entity.type.ObjType) RandomWizard(main.system.auxiliary.RandomWizard) DC_HeroItemObj(eidolons.entity.item.DC_HeroItemObj) WeightMap(main.system.datatypes.WeightMap) MATERIAL(main.content.enums.entity.ItemEnums.MATERIAL)

Aggregations

WeightMap (main.system.datatypes.WeightMap)4 ObjType (main.entity.type.ObjType)3 DC_HeroItemObj (eidolons.entity.item.DC_HeroItemObj)2 RandomWizard (main.system.auxiliary.RandomWizard)2 ArrayList (java.util.ArrayList)1 OBJ_TYPE (main.content.OBJ_TYPE)1 MATERIAL (main.content.enums.entity.ItemEnums.MATERIAL)1