Search in sources :

Example 16 with Action

use of eidolons.game.battlecraft.ai.elements.actions.Action in project Eidolons by IDemiurge.

the class PriorityManagerImpl method getAttackPriority.

@Override
public int getAttackPriority(DC_ActiveObj active, BattleFieldObject targetObj) {
    if (getUnit().getBehaviorMode() != AiEnums.BEHAVIOR_MODE.BERSERK && getUnit().getBehaviorMode() != AiEnums.BEHAVIOR_MODE.CONFUSED) {
        if (targetObj.isOwnedBy(active.getOwnerObj().getOwner())) {
            return -10000;
        }
    }
    boolean attack = !(active instanceof DC_SpellObj);
    int enemy_priority = getUnitPriority(targetObj);
    int priority = enemy_priority;
    int damage_priority = getDamagePriority(active, targetObj, attack);
    if (active.isThrow()) {
        if (damage_priority < getUnitPriority(targetObj) * 2) {
            // TODO
            return -1;
        }
    }
    // getActionNumberFactor
    int counter_penalty = 0;
    if (active.getActionGroup() != ActionEnums.ACTION_TYPE_GROUPS.ATTACK) {
    // if (AttackOfOpportunityRule.checkAction(active)) {
    // counter_penalty = getAttackOfOpportunityPenalty(active,
    // targetObj);
    // }
    } else {
        if (!active.isRanged() && targetObj.canCounter() && !getUnit().checkPassive(UnitEnums.STANDARD_PASSIVES.NO_RETALIATION) && !active.checkProperty(G_PROPS.STANDARD_PASSIVES, UnitEnums.STANDARD_PASSIVES.NO_RETALIATION.getName())) {
            if ((damage_priority != getLethalDamagePriority() && damage_priority != getUnconsciousDamagePriority()) || targetObj.checkPassive(UnitEnums.STANDARD_PASSIVES.FIRST_STRIKE)) {
                counter_penalty = getCounterPenalty(active, (Unit) targetObj);
            }
        }
    }
    // TODO spells!
    if (active instanceof DC_SpellObj) {
        // check mod effects too
        Action action = AiActionFactory.newAction(active, new Context(getUnit(), targetObj));
        damage_priority += getSpellPriority(GOAL_TYPE.DEBILITATE, action);
        damage_priority += getSpellPriority(GOAL_TYPE.DEBUFF, action);
        if (getUnit().getAiType().isCaster()) {
            damage_priority *= 4;
        }
    } else {
        if (active.isRanged()) {
            if (getUnit().getAiType() == AiEnums.AI_TYPE.ARCHER) {
                damage_priority *= 2;
            }
        } else if (getUnit().getAiType() == AiEnums.AI_TYPE.BRUTE) {
            damage_priority *= 2;
        }
    }
    damage_priority = Math.max(getConstInt(AiConst.DAMAGE_PERCENTAGE_MOD_MINIMUM), damage_priority - counter_penalty);
    priority = priority * damage_priority / 100;
    priority += getConstInt((active instanceof DC_SpellObj) ? AiConst.DEFAULT_SPELL_ATTACK_PRIORITY : AiConst.DEFAULT_ATTACK_PRIORITY);
    if (active.isThrow()) {
        try {
            applyThrowPenalty(active);
            priority = this.priority;
        } catch (Exception e) {
            main.system.ExceptionMaster.printStackTrace(e);
            addMultiplier(-50, "throw");
        }
    }
    if (targetObj.isNeutral()) {
        addMultiplier(-90, "Neutral");
    }
    return priority;
}
Also used : Context(main.game.logic.action.context.Context) 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_SpellObj(eidolons.entity.active.DC_SpellObj) Unit(eidolons.entity.obj.unit.Unit)

Example 17 with Action

use of eidolons.game.battlecraft.ai.elements.actions.Action in project Eidolons by IDemiurge.

the class PriorityManagerImpl method getPriorityForActionSequence.

@Override
public int getPriorityForActionSequence(ActionSequence as) {
    priority = 0;
    modifier = 0;
    // compare damage or default priority on non-damage actions (formula?)
    // 
    setUnit(as.getAi().getUnit());
    GOAL_TYPE goal = as.getType();
    initLogChannel(goal);
    Action action = as.getLastAction();
    try {
        action.getActive().getGame().getEffectManager().setEffectRefs(action.getActive().getAbilities(), action.getRef());
    } catch (Exception e) {
        main.system.ExceptionMaster.printStackTrace(e);
    }
    if (!action.getActive().getProperty(PROPS.AI_PRIORITY_FORMULA).isEmpty()) {
        setBasePriority(evaluatePriorityFormula(action, action.getActive().getProperty(PROPS.AI_PRIORITY_FORMULA)));
        if (EffectFinder.check(action.getActive(), RollEffect.class)) {
            try {
                applyRollPriorityMod((RollEffect) EffectFinder.getEffectsOfClass(action.getActive(), RollEffect.class).get(0));
            } catch (Exception e) {
                main.system.ExceptionMaster.printStackTrace(e);
            }
        }
        applyResistPenalty(action);
    } else {
        switch(goal) {
            case PROTECT:
                setBasePriority(getGuardPriority(action));
                break;
            case ATTACK:
                setBasePriority(getAttackPriority(as));
                break;
            case WAIT:
                setBasePriority(getWaitPriority(action));
                break;
            case DEFEND:
            case PREPARE:
                setBasePriority(getModePriority(action));
                break;
            case SUMMONING:
                setBasePriority(getSummonPriority(action));
                break;
            case AUTO_DAMAGE:
            case ZONE_DAMAGE:
            case AUTO_DEBUFF:
            case AUTO_BUFF:
            case SELF:
            case BUFF:
            case DEBUFF:
            case RESTORE:
            case DEBILITATE:
            case CUSTOM_HOSTILE:
            case CUSTOM_SUPPORT:
                setBasePriority(getSpellPriority(goal, action));
                break;
            case STEALTH:
                setBasePriority(getStealthPriority(action));
                break;
            case SEARCH:
                // TODO sight range/detection factors,
                setBasePriority(getSearchPriority(as));
                break;
            case COWER:
                setBasePriority(getCowerPriority(getUnit()));
                break;
            case RETREAT:
                setBasePriority(getRetreatPriority(as));
                break;
            case COATING:
                setBasePriority(getCoatingPriority(action.getActive(), action.getTarget()));
                break;
            case AGGRO:
            case AMBUSH:
            case APPROACH:
            case STAND_GUARD:
            case MOVE:
            case OTHER:
            case PATROL:
            case STALK:
            case WANDER:
                priority = 100;
                break;
            case ZONE_SPECIAL:
            default:
                setBasePriority(getSpellPriority(goal, action));
                break;
        }
    }
    if (priority <= 0) {
        if (goal == GOAL_TYPE.ATTACK)
            LogMaster.log(1, "ATK FAILED" + priority + " priority for " + as);
        else
            LogMaster.log(1, priority + " priority for " + as);
        return priority;
    }
    // Integer bonus = unit_ai.getActionPriorityBonuses().get(action.getActive().getName());
    // if (bonus != null) {
    // priority += bonus;
    // }
    as.setPriority(priority);
    Integer mod = as.getPriorityMultiplier();
    mod += (int) (modifier);
    if (mod != null) {
        priority = MathMaster.applyMod(priority, mod);
    }
    LogMaster.log(1, "AI: " + priority + " priority for " + as);
    return priority;
}
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) RollEffect(eidolons.ability.effects.oneshot.mechanic.RollEffect) GOAL_TYPE(main.content.enums.system.AiEnums.GOAL_TYPE)

Example 18 with Action

use of eidolons.game.battlecraft.ai.elements.actions.Action 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 19 with Action

use of eidolons.game.battlecraft.ai.elements.actions.Action in project Eidolons by IDemiurge.

the class DC_MovementManager method moveTo.

public void moveTo(Coordinates coordinates) {
    Unit unit = game.getManager().getActiveObj();
    List<ActionPath> paths = pathCache.get(unit);
    if (paths == null) {
        paths = buildPath(unit, coordinates);
        // Coordinates adjacentCoordinate = coordinates.getAdjacentCoordinate(DirectionMaster
        // .getRelativeDirection(unit.getCoordinates(), coordinates));
        // if (DialogMaster.confirm("No path could be built to " + coordinates
        // + "; proceed to the closest cell? - " + adjacentCoordinate)) {
        // moveTo(adjacentCoordinate);
        // } else {
        // return;
        // }
        pathCache.put(unit, paths);
    }
    if (paths == null) {
        return;
    }
    Action action = null;
    for (ActionPath path : paths) {
        // if (DialogMaster.confirm("Path built to : " + path + "\nExecute "
        // + path.getActions().get(0).toString() + "?")) {
        // action = path.getActions().get(0);
        // break;
        // }
        // just check if still passible
        // if (path.getActions().get(0))
        action = path.getActions().get(0);
        break;
    }
    if (action == null) {
        pathCache.remove(unit);
        return;
    }
    // ActionAnimation anim = new ActionAnimation(action);
    // anim.start();
    Context context = new Context(unit.getRef());
    if (action.getActive().isMove()) {
        context.setTarget(game.getCellByCoordinate(coordinates).getId());
    }
    unit.getGame().getGameLoop().actionInput(new ActionInput(action.getActive(), context));
}
Also used : Context(main.game.logic.action.context.Context) Action(eidolons.game.battlecraft.ai.elements.actions.Action) DC_UnitAction(eidolons.entity.active.DC_UnitAction) ActionInput(eidolons.game.core.ActionInput) ActionPath(eidolons.game.battlecraft.ai.tools.path.ActionPath) Unit(eidolons.entity.obj.unit.Unit)

Example 20 with Action

use of eidolons.game.battlecraft.ai.elements.actions.Action in project Eidolons by IDemiurge.

the class TargetingMaster method selectTargetForAction.

public static Integer selectTargetForAction(DC_ActiveObj a) {
    /*
         * getOrCreate possible targets init goal type prioritize
		 */
    GOAL_TYPE type = GoalManager.getGoalFromAction(a);
    Obj target = null;
    int max_priority = Integer.MIN_VALUE;
    Set<Obj> objects = null;
    a.getTargeting().getFilter().setRef(a.getRef());
    try {
        objects = a.getTargeting().getFilter().getObjects();
    } catch (Exception e) {
        main.system.ExceptionMaster.printStackTrace(e);
    }
    for (Obj obj : objects) {
        ActionSequence sequence = new ActionSequence(type, new Action(a, obj));
        sequence.setAi(a.getOwnerObj().getUnitAI());
        sequence.setType(type);
        int priority = DC_PriorityManager.getPriority(sequence);
        if (priority > max_priority) {
            target = obj;
            max_priority = priority;
        }
    }
    if (target == null) {
        return null;
    }
    return target.getId();
}
Also used : Action(eidolons.game.battlecraft.ai.elements.actions.Action) ActionSequence(eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence) ActiveObj(main.entity.obj.ActiveObj) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj) Obj(main.entity.obj.Obj) GOAL_TYPE(main.content.enums.system.AiEnums.GOAL_TYPE)

Aggregations

Action (eidolons.game.battlecraft.ai.elements.actions.Action)32 DC_UnitAction (eidolons.entity.active.DC_UnitAction)16 Coordinates (main.game.bf.Coordinates)11 Unit (eidolons.entity.obj.unit.Unit)9 ArrayList (java.util.ArrayList)9 DC_ActiveObj (eidolons.entity.active.DC_ActiveObj)8 AiQuickItemAction (eidolons.game.battlecraft.ai.elements.actions.AiQuickItemAction)7 ActionSequence (eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence)7 ActionPath (eidolons.game.battlecraft.ai.tools.path.ActionPath)7 Ref (main.entity.Ref)6 DC_QuickItemAction (eidolons.entity.active.DC_QuickItemAction)4 FACING_SINGLE (main.content.enums.entity.UnitEnums.FACING_SINGLE)3 GOAL_TYPE (main.content.enums.system.AiEnums.GOAL_TYPE)3 Obj (main.entity.obj.Obj)3 DC_Cell (eidolons.entity.obj.DC_Cell)2 DC_Obj (eidolons.entity.obj.DC_Obj)2 UnitAI (eidolons.game.battlecraft.ai.UnitAI)2 Task (eidolons.game.battlecraft.ai.elements.task.Task)2 Effect (main.ability.effects.Effect)2 Context (main.game.logic.action.context.Context)2