Search in sources :

Example 26 with DC_ActiveObj

use of eidolons.entity.active.DC_ActiveObj in project Eidolons by IDemiurge.

the class ActionExecutor method createTargeter.

@Override
protected Targeter createTargeter(DC_ActiveObj active, ActiveMaster entityMaster) {
    return new Targeter(active, entityMaster) {

        @Override
        public Targeting getTargeting() {
            initTargetingMode();
            if (AI_Manager.isRunning()) {
                return super.getTargeting();
            }
            if (getAction().isAttackGeneric()) {
                Conditions conditions = new OrConditions();
                int maxRange = 0;
                for (DC_ActiveObj attack : getAction().getSubActions()) {
                    if (attack.isThrow()) {
                        continue;
                    }
                    if (!attack.canBeActivated()) {
                        continue;
                    }
                    conditions.add(attack.getTargeting().getFilter().getConditions());
                    if (maxRange < attack.getRange()) {
                        maxRange = attack.getRange();
                    }
                }
                conditions.setFastFailOnCheck(true);
                conditions = ConditionMaster.getFilteredConditions(conditions, DistanceCondition.class);
                conditions.add(new DistanceCondition("" + maxRange));
                SelectiveTargeting selectiveTargeting = new SelectiveTargeting(SELECTIVE_TARGETING_TEMPLATES.ATTACK, conditions);
                return selectiveTargeting;
            }
            return super.getTargeting();
        }
    };
}
Also used : SelectiveTargeting(main.elements.targeting.SelectiveTargeting) OrConditions(main.elements.conditions.OrConditions) DistanceCondition(main.elements.conditions.DistanceCondition) Targeter(eidolons.entity.handlers.active.Targeter) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj) Conditions(main.elements.conditions.Conditions) OrConditions(main.elements.conditions.OrConditions)

Example 27 with DC_ActiveObj

use of eidolons.entity.active.DC_ActiveObj in project Eidolons by IDemiurge.

the class PathChoiceMaster method getChoices.

List<Choice> getChoices(ActionPath path, Coordinates c_coordinate, Coordinates targetCoordinate, FACING_DIRECTION c_facing) {
    Chronos.mark("Finding choices for " + path);
    pathBuilder.adjustUnit();
    List<Choice> choices = new ArrayList<>();
    for (Coordinates c : getDefaultCoordinateTargets(path, c_coordinate)) {
        Choice stdMoveChoice = constructStdMoveChoice(c, c_coordinate, c_facing);
        if (stdMoveChoice != null) {
            choices.add(stdMoveChoice);
        }
    }
    Chronos.mark("Finding custom choices for " + path);
    List<Choice> specialChoices = new ArrayList<>();
    if (ListMaster.isNotEmpty(moveActions)) {
        for (DC_ActiveObj a : moveActions) {
            if (!a.canBeActivated()) {
                if (firstStep) {
                    if (!ReasonMaster.checkReasonCannotActivate(a, PARAMS.C_N_OF_ACTIONS.getName())) {
                        // exception for AP TODO
                        continue;
                    }
                }
            }
            if (path.hasAction(a)) {
                if (a.getIntParam(PARAMS.COOLDOWN) >= 0) {
                    continue;
                }
            }
            Targeting targeting = a.getTargeting();
            Collection<Obj> objects = null;
            if (targeting instanceof FixedTargeting) {
                Targeting t = a.getAbilities().getTargeting();
                if (t != null) {
                    objects = t.getFilter().getObjects(a.getRef());
                }
                Effect e = a.getAbilities().getEffects().getEffects().get(0);
                e.setRef(unit.getRef());
                if (e instanceof SelfMoveEffect) {
                    try {
                        Coordinates coordinates = ((SelfMoveEffect) e).getCoordinates();
                        if (coordinates != null) {
                            objects = new ArrayList<>(Arrays.asList(unit.getGame().getCellByCoordinate(coordinates)));
                        }
                    } catch (Exception ex) {
                        main.system.ExceptionMaster.printStackTrace(ex);
                    }
                }
            } else {
                pathBuilder.adjustUnit();
                objects = targeting.getFilter().getObjects(a.getRef());
            }
            if (objects != null) {
                List<Choice> choicesForAction = new ArrayList<>();
                for (Object obj : objects) {
                    if (obj instanceof DC_Cell) {
                        Coordinates coordinates = ((DC_Cell) obj).getCoordinates();
                        // if (a.getName().equals("Clumsy Leap"))
                        if (PositionMaster.getDistance(coordinates, c_coordinate) > Math.max(1, a.getIntParam(PARAMS.RANGE))) {
                            continue;
                        }
                        if (PositionMaster.getDistance(coordinates, targetCoordinate) > PositionMaster.getDistance(c_coordinate, targetCoordinate)) {
                            // TODO will this not eliminate good
                            continue;
                        }
                        // choices?
                        Ref ref = unit.getRef().getCopy();
                        ref.setTarget(((DC_Cell) obj).getId());
                        Choice choice = new Choice(coordinates, c_coordinate, new Action(a, ref));
                        choicesForAction.add(choice);
                    }
                }
                Chronos.mark("Filter custom choices for " + a);
                specialChoices.addAll(filterSpecialMoveChoices(choicesForAction, a, c_coordinate, path));
                Chronos.logTimeElapsedForMark("Filter custom choices for " + a);
            }
        // if (choices.size() > 1)
        }
    }
    Chronos.logTimeElapsedForMark("Finding custom choices for " + path);
    choices.addAll(specialChoices);
    Chronos.mark("Sort choices");
    sortChoices(choices);
    Chronos.logTimeElapsedForMark("Sort choices");
    // resetUnit();// TODO is that right?
    Chronos.logTimeElapsedForMark("Finding choices for " + path);
    // Chronos.logTimeElapsedForMark("Sorting choices for " + path);
    return choices;
}
Also used : Action(eidolons.game.battlecraft.ai.elements.actions.Action) DC_UnitAction(eidolons.entity.active.DC_UnitAction) FixedTargeting(main.elements.targeting.FixedTargeting) Targeting(main.elements.targeting.Targeting) Coordinates(main.game.bf.Coordinates) Ref(main.entity.Ref) FixedTargeting(main.elements.targeting.FixedTargeting) DC_Cell(eidolons.entity.obj.DC_Cell) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj) Obj(main.entity.obj.Obj) SelfMoveEffect(eidolons.ability.effects.oneshot.move.SelfMoveEffect) SelfMoveEffect(eidolons.ability.effects.oneshot.move.SelfMoveEffect) Effect(main.ability.effects.Effect) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj)

Example 28 with DC_ActiveObj

use of eidolons.entity.active.DC_ActiveObj in project Eidolons by IDemiurge.

the class ParamPriorityAnalyzer method getResistanceFactor.

public static int getResistanceFactor(Action action) {
    DC_ActiveObj active = action.getActive();
    DC_Obj target = action.getTarget();
    Integer resistance = target.getIntParam(PARAMS.RESISTANCE);
    resistance -= action.getSource().getIntParam(PARAMS.RESISTANCE_PENETRATION);
    Integer mod = active.getIntParam(PARAMS.RESISTANCE_MODIFIER);
    if (mod > 0) {
        resistance = resistance * mod / 100;
    }
    return Math.min(0, -resistance);
}
Also used : DC_Obj(eidolons.entity.obj.DC_Obj) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj)

Example 29 with DC_ActiveObj

use of eidolons.entity.active.DC_ActiveObj in project Eidolons by IDemiurge.

the class PriorityManagerImpl method getAttackPriority.

@Override
public int getAttackPriority(ActionSequence as) {
    Action action = as.getLastAction();
    if (action.getTarget() instanceof DC_Cell) {
        return 0;
    }
    Unit targetObj = (Unit) action.getTarget();
    DC_ActiveObj active = action.getActive();
    return getAttackPriority(active, targetObj);
}
Also used : Action(eidolons.game.battlecraft.ai.elements.actions.Action) AiQuickItemAction(eidolons.game.battlecraft.ai.elements.actions.AiQuickItemAction) DC_UnitAction(eidolons.entity.active.DC_UnitAction) DC_QuickItemAction(eidolons.entity.active.DC_QuickItemAction) DC_Cell(eidolons.entity.obj.DC_Cell) Unit(eidolons.entity.obj.unit.Unit) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj)

Example 30 with DC_ActiveObj

use of eidolons.entity.active.DC_ActiveObj in project Eidolons by IDemiurge.

the class ThreatAnalyzer method getMeleeThreat.

public int getMeleeThreat(Unit enemy, boolean now) {
    if (now) {
        if (!enemy.canActNow() || !enemy.canAttack()) {
            return 0;
        }
    }
    int distance = 1 + PositionMaster.getDistance(getUnit(), enemy);
    if (distance > 5)
        return 0;
    int threat = 0;
    int factor = 1;
    DC_UnitAction attack = enemy.getAction(DC_ActionManager.ATTACK);
    if (attack == null) {
        return 0;
    }
    DC_ActiveObj subAttack = (DC_ActiveObj) FuncMaster.getGreatestEntity(attack.getSubActions(), atk -> {
        if (enemy.getIntParam(PARAMS.C_N_OF_ACTIONS) > atk.getIntParam(PARAMS.AP_COST))
            return atk.getIntParam(PARAMS.AP_COST);
        return 0;
    });
    DC_PriorityManager.toggleImplementation(new PriorityManagerImpl(getMaster()) {

        @Override
        public Unit getUnit() {
            return enemy;
        }
    });
    try {
        threat = DC_PriorityManager.getAttackPriority(subAttack, getUnit()) * factor;
    } catch (Exception e) {
        main.system.ExceptionMaster.printStackTrace(e);
    } finally {
        DC_PriorityManager.toggleImplementation(null);
    }
    // special attacks? dual wielding?
    threat /= distance;
    main.system.auxiliary.log.LogMaster.log(1, getUnit() + " feels " + threat + " threat from " + enemy);
    return threat;
}
Also used : Context(main.game.logic.action.context.Context) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj) DC_UnitAction(eidolons.entity.active.DC_UnitAction) DC_AttackMaster(eidolons.game.battlecraft.rules.combat.attack.DC_AttackMaster) PARAMS(eidolons.content.PARAMS) AiHandler(eidolons.game.battlecraft.ai.elements.generic.AiHandler) HashMap(java.util.HashMap) AiMaster(eidolons.game.battlecraft.ai.elements.generic.AiMaster) FuncMaster(main.system.math.FuncMaster) AttackCalculator(eidolons.game.battlecraft.rules.combat.attack.AttackCalculator) UnitAI(eidolons.game.battlecraft.ai.UnitAI) Map(java.util.Map) DC_ActionManager(eidolons.entity.active.DC_ActionManager) Unit(eidolons.entity.obj.unit.Unit) DC_SpellObj(eidolons.entity.active.DC_SpellObj) PositionMaster(main.system.math.PositionMaster) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj) Unit(eidolons.entity.obj.unit.Unit) DC_UnitAction(eidolons.entity.active.DC_UnitAction)

Aggregations

DC_ActiveObj (eidolons.entity.active.DC_ActiveObj)73 Unit (eidolons.entity.obj.unit.Unit)22 ArrayList (java.util.ArrayList)17 Obj (main.entity.obj.Obj)15 DC_UnitAction (eidolons.entity.active.DC_UnitAction)12 DC_Obj (eidolons.entity.obj.DC_Obj)12 Ref (main.entity.Ref)9 Action (eidolons.game.battlecraft.ai.elements.actions.Action)8 BattleFieldObject (eidolons.entity.obj.BattleFieldObject)7 ActiveObj (main.entity.obj.ActiveObj)7 Effect (main.ability.effects.Effect)5 SelectiveTargeting (main.elements.targeting.SelectiveTargeting)5 Targeting (main.elements.targeting.Targeting)5 AddBuffEffect (eidolons.ability.effects.attachment.AddBuffEffect)4 DC_SpellObj (eidolons.entity.active.DC_SpellObj)4 ActionPath (eidolons.game.battlecraft.ai.tools.path.ActionPath)4 FixedTargeting (main.elements.targeting.FixedTargeting)4 Coordinates (main.game.bf.Coordinates)4 RollEffect (eidolons.ability.effects.oneshot.mechanic.RollEffect)3 ActionSequence (eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence)3