Search in sources :

Example 6 with RandomWizard

use of main.system.auxiliary.RandomWizard 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)

Example 7 with RandomWizard

use of main.system.auxiliary.RandomWizard in project Eidolons by IDemiurge.

the class ContainerMaster method preselectBaseType.

private ObjType preselectBaseType(CONTAINER_CONTENTS contents, ITEM_RARITY rarity) {
    DC_TYPE TYPE = getRandomTYPE(contents);
    boolean iterate = isIterateAlways() || TYPE == DC_TYPE.ITEMS || TYPE == DC_TYPE.JEWELRY;
    if (isFastSelect()) {
        String group = getItemGroup(contents, false, TYPE);
        String subgroup = getItemGroup(contents, true, TYPE);
        ObjType type = null;
        List<ObjType> types = DataManager.getTypes(TYPE, iterate);
        main.system.auxiliary.log.LogMaster.log(1, " group= " + group + " subgroup= " + subgroup + "; types = " + types);
        Iterator<ObjType> iterator = types.iterator();
        int n = 0;
        // Math.min(50, types.size() / 3));
        Loop loop = new Loop(5);
        while (true) {
            if (iterate) {
                if (!iterator.hasNext())
                    return null;
                type = iterator.next();
            } else {
                n++;
                type = new RandomWizard<ObjType>().getRandomListItem(types);
                if (n > types.size() / 5) {
                    if (!loop.continues())
                        return null;
                    group = getItemGroup(contents, false, TYPE);
                    subgroup = getItemGroup(contents, true, TYPE);
                    n = 0;
                }
            }
            if (type == null)
                break;
            if (type.isGenerated())
                continue;
            if (isRemoveBase(contents, type) && TYPE != DC_TYPE.JEWELRY)
                if (!type.checkProperty(PROPS.ITEM_RARITY, rarity.name()))
                    continue;
            if (group != null)
                if (!type.checkGroupingProperty(group))
                    continue;
            if (subgroup != null)
                if (!type.checkSubGroup(subgroup))
                    continue;
            break;
        }
        return type;
    }
    List<ObjType> list = new ArrayList<>();
    String groups = getItemGroups(contents, TYPE);
    if (groups == null)
        groups = " ;";
    for (String sub : groups.split(";")) {
        if (sub.trim().isEmpty())
            sub = null;
        List<ObjType> group = new ArrayList<>(isGroupsOrSubgroups(contents, TYPE) ? DataManager.getTypesGroup(TYPE, sub) : DataManager.getTypesSubGroup(TYPE, sub));
        // TODO set rarity to common by default
        FilterMaster.filterByPropJ8(group, PROPS.ITEM_RARITY.getName(), rarity.name());
        filter(contents, group, rarity, TYPE);
        if (group.isEmpty())
            continue;
        // group = generateTypes(c, rarity, group);
        // group.removeIf(type -> !type.isGenerated()); //remove base types
        list.addAll(group);
    }
    main.system.auxiliary.log.LogMaster.log(1, "type list= " + list);
    if (list.isEmpty()) {
        return null;
    }
    return new RandomWizard<ObjType>().getRandomListItem(list);
}
Also used : Loop(main.system.auxiliary.Loop) DC_TYPE(main.content.DC_TYPE) ObjType(main.entity.type.ObjType) RandomWizard(main.system.auxiliary.RandomWizard)

Example 8 with RandomWizard

use of main.system.auxiliary.RandomWizard in project Eidolons by IDemiurge.

the class LocationBuilder method placeAdditionalRooms.

private void placeAdditionalRooms() {
    // TODO SET ROOM_TYPE AFTER TO FIT BEST? E.G.TREASURE/SECRET MOST
    // DISTANT FROM ENTRANCE
    int attempts = plan.getCellsX() * plan.getCellsY() * 10;
    int remainingAttempts = attempts;
    while (remainingAttempts > 0) {
        remainingAttempts--;
        boolean spec = false;
        if (attempts - remainingAttempts > 6) {
            spec = RandomWizard.chance(85);
        }
        String string = getDungeon().getProperty(PROPS.ADDITIONAL_ROOM_TYPES);
        ROOM_TYPE roomType = new RandomWizard<ROOM_TYPE>().getObjectByWeight(string, ROOM_TYPE.class);
        if (roomType == null) {
            string = helper.getParams().getValue(BUILD_PARAMS.ADDITIONAL_ROOMS);
            roomType = new RandomWizard<ROOM_TYPE>().getRandomListItem(Arrays.asList(spec ? spec_room_types : std_room_types));
        }
        Coordinates c = getRandomCoordinate(roomType);
        if (c == null) {
            continue;
        }
        XDimension size = helper.getRoomSize(roomType);
        // boolean flipX = location.isFlipX(c);
        // boolean flipY = location.isFlipY(c); // TODO
        helper.tryPlaceRoom(roomType, c, size.width, size.height, flipX, flipY);
        if (helper.getUsedCoordinates().size() * 100 / (getDungeon().getCellsX() * getDungeon().getCellsY()) > helper.getParams().PREFERRED_FILL_PERCENTAGE) {
            break;
        }
    }
// distance from other blocks?
}
Also used : XDimension(main.swing.XDimension) RandomWizard(main.system.auxiliary.RandomWizard) Coordinates(main.game.bf.Coordinates)

Example 9 with RandomWizard

use of main.system.auxiliary.RandomWizard in project Eidolons by IDemiurge.

the class AreaManager method getRandomCreepGroup.

// TODO pass MIN_MAX !
private static MacroGroup getRandomCreepGroup(Area area) {
    Loop.startLoop(10);
    while (!Loop.loopEnded()) {
        ENCOUNTER_SUBGROUP group = new RandomWizard<ENCOUNTER_SUBGROUP>().getObjectByWeight(area.getProperty(MACRO_PROPS.ENCOUNTER_SUBGROUPS), // TODO
        ENCOUNTER_SUBGROUP.class);
        List<ObjType> pool;
        if (group != null) {
            pool = DataManager.getTypesSubGroup(DC_TYPE.ENCOUNTERS, group.toString());
        } else // TODO
        {
            pool = DataManager.getTypes(DC_TYPE.ENCOUNTERS);
        }
        FilterMaster.filterByParam(pool, PARAMS.POWER_MINIMUM, EncounterMaster.getMaxCreepWavePower(), DC_TYPE.ENCOUNTERS, false);
        FilterMaster.filterByParam(pool, PARAMS.POWER_MAXIMUM, EncounterMaster.getMinCreepWavePower(), DC_TYPE.ENCOUNTERS, true);
        // more filter! By TYPE? TODO
        if (pool.isEmpty()) {
            continue;
        }
        // higher probability for non-bosses?
        String waveName = new RandomWizard<ObjType>().getRandomListItem(pool).getName();
        MacroGroup macroGroup = new MacroGroup(waveName, area);
        return macroGroup;
    }
    return null;
}
Also used : MacroGroup(eidolons.game.module.adventure.travel.MacroGroup) ObjType(main.entity.type.ObjType) RandomWizard(main.system.auxiliary.RandomWizard) ENCOUNTER_SUBGROUP(main.content.enums.EncounterEnums.ENCOUNTER_SUBGROUP)

Example 10 with RandomWizard

use of main.system.auxiliary.RandomWizard in project Eidolons by IDemiurge.

the class TaskManager method getTasks.

public List<Task> getTasks(GOAL_TYPE goal, UnitAI ai, boolean forced, DC_ActiveObj action) {
    List<Task> list = new XList<>();
    if (ai.getCurrentOrder() != null)
        if (ai.getCurrentOrder().getArg() != null)
            return new ArrayList<>(Arrays.asList(new Task(ai, goal, ai.getCurrentOrder().getArg())));
    List<Integer> ids = new ArrayList<>();
    List<? extends DC_Obj> targets = new ArrayList<>();
    List<? extends DC_Obj> targets2 = new ArrayList<>();
    BEHAVIOR_MODE behaviorMode = ai.getBehaviorMode();
    // ai.getGroup().getKnownEnemyCoordinatesMap();
    switch(goal) {
        case STAND_GUARD:
        case AMBUSH:
        // preCheck engagement level, default prefs
        case SELF:
        case STEALTH:
            list.add(new Task(forced, ai, goal, ai.getUnit().getId()));
            break;
        // SPEC MODE - KIND OF ON ALERT...
        case PATROL:
            targets = Analyzer.getWanderCells(ai);
            break;
        case // RANDOM DESTINATION MOVEMENT, BLOCK SPECIAL MOVES
        WANDER:
            // limit max distance from original spawning position
            // TODO sometimes in chosen direction
            targets = Analyzer.getWanderCells(ai);
            break;
        case STALK:
            // ai.getGroup().getKnownEnemies
            break;
        case APPROACH:
            targets = getCellPrioritizer().getApproachCells(ai);
            break;
        case SEARCH:
            // or maybe the last-seen enemies?
            if (!forced) {
                if (ai.getUnit().getBuff("Search Mode") == null) {
                    list.add(new Task(forced, ai, goal, ai.getUnit().getId()));
                    break;
                }
            }
            targets = Analyzer.getSearchCells(ai);
            break;
        case RETREAT:
            if (ai.getBehaviorMode() == AiEnums.BEHAVIOR_MODE.PANIC) {
            // only border cells => flee
            }
            targets = Analyzer.getSafeCells(ai);
            break;
        case MOVE:
            targets = Analyzer.getMoveTargetCells(ai);
            break;
        case CUSTOM_HOSTILE:
            targets = Analyzer.getVisibleEnemies(ai);
            checkPrune(targets, goal, ai, action);
            break;
        case CUSTOM_SUPPORT:
            targets = Analyzer.getAllies(ai);
            checkPrune(targets, goal, ai, action);
            break;
        case ZONE_DAMAGE:
            targets = Analyzer.getZoneDamageCells(ai.getUnit());
            targets2 = Analyzer.getAdjacentEnemies(ai.getUnit(), false);
            checkPrune(targets, goal, ai, action);
            break;
        case SUMMONING:
            targets = Analyzer.getSummonCells(ai, action);
            break;
        case DEBILITATE:
        case DEBUFF:
        case ATTACK:
            if (behaviorMode == AiEnums.BEHAVIOR_MODE.BERSERK || behaviorMode == AiEnums.BEHAVIOR_MODE.CONFUSED) {
                targets = (Analyzer.getUnits(ai, true, true, true, false));
            } else {
                // if (forced)
                // targets = (Analyzer.getUnits(ai, false, true, true,
                // false, true));
                // else
                // TODO detected!
                targets = Analyzer.getVisibleEnemies(ai);
            }
            checkPrune(targets, goal, ai, action);
            break;
        case AUTO_DAMAGE:
        case AUTO_DEBUFF:
        case AUTO_BUFF:
        // list.add(new Task(ai, goal, null));
        case RESTORE:
        case BUFF:
            targets = Analyzer.getAllies(ai);
            checkPrune(targets, goal, ai, action);
            break;
        case WAIT:
            if (!DC_Engine.isAtbMode())
                targets = Analyzer.getWaitUnits(ai);
            break;
        case PROTECT:
            if (RuleMaster.isRuleOn(RULE.GUARD))
                if (GuardRule.on)
                    targets = Analyzer.getProtectCells(ai);
            break;
        case COATING:
            Set<Obj> objects = action.getTargeting().getFilter().getObjects(action.getRef());
            for (Obj q : objects) {
                if (q.getRef().getSourceObj() == getUnit()) {
                    // q.isOwnedBy(ai.getUnit().getOwner())
                    ids.add(q.getId());
                }
            }
            break;
        default:
            list.add(new Task(forced, ai, goal, null));
            break;
    }
    if (targets.isEmpty()) {
        return new ArrayList<>();
    }
    if (behaviorMode == AiEnums.BEHAVIOR_MODE.CONFUSED) {
        DC_Obj target = targets.get(new RandomWizard<>().getRandomListIndex(targets));
        List<Task> tasks = new ArrayList<>();
        tasks.add(new Task(forced, ai, goal, target.getId()));
        return tasks;
    }
    if (list.isEmpty()) {
        for (DC_Obj obj : targets) {
            list.add(new Task(forced, ai, goal, obj.getId()));
        }
        for (DC_Obj obj : targets2) {
            list.add(new Task(forced, ai, goal, obj.getId()));
        }
        for (Integer id : ids) {
            list.add(new Task(forced, ai, goal, id));
        }
    }
    return list;
}
Also used : DC_Obj(eidolons.entity.obj.DC_Obj) DC_Obj(eidolons.entity.obj.DC_Obj) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj) Obj(main.entity.obj.Obj) RandomWizard(main.system.auxiliary.RandomWizard) ArrayList(java.util.ArrayList) XList(main.data.XList) BEHAVIOR_MODE(main.content.enums.system.AiEnums.BEHAVIOR_MODE)

Aggregations

RandomWizard (main.system.auxiliary.RandomWizard)11 ObjType (main.entity.type.ObjType)7 Ref (main.entity.Ref)3 Loop (main.system.auxiliary.Loop)3 DC_ActiveObj (eidolons.entity.active.DC_ActiveObj)2 DC_HeroItemObj (eidolons.entity.item.DC_HeroItemObj)2 ArrayList (java.util.ArrayList)2 DC_TYPE (main.content.DC_TYPE)2 CONTAINER_CONTENTS (main.content.enums.entity.DungeonObjEnums.CONTAINER_CONTENTS)2 CONTAINER_CONTENT_VALUE (main.content.enums.entity.DungeonObjEnums.CONTAINER_CONTENT_VALUE)2 MATERIAL (main.content.enums.entity.ItemEnums.MATERIAL)2 InventoryTransactionManager (eidolons.ability.InventoryTransactionManager)1 DC_Effect (eidolons.ability.effects.DC_Effect)1 AddBuffEffect (eidolons.ability.effects.attachment.AddBuffEffect)1 CharacterCreator (eidolons.client.cc.CharacterCreator)1 ItemGenerator (eidolons.client.cc.logic.items.ItemGenerator)1 ItemMaster (eidolons.client.cc.logic.items.ItemMaster)1 JEWELRY_ITEM_TRAIT (eidolons.content.DC_CONSTS.JEWELRY_ITEM_TRAIT)1 MAGICAL_ITEM_LEVEL (eidolons.content.DC_CONSTS.MAGICAL_ITEM_LEVEL)1 PARAMS (eidolons.content.PARAMS)1