Search in sources :

Example 1 with GOAL_TYPE

use of main.content.enums.system.AiEnums.GOAL_TYPE in project Eidolons by IDemiurge.

the class AiScriptExecutor method executeCommand.

private void executeCommand(Unit unit, COMBAT_SCRIPT_FUNCTION function, String arg, boolean free, boolean immediate, String... args) {
    ActionSequence sequence = null;
    GOAL_TYPE goal = getGoalType(function);
    Task task = new Task(true, unit.getAI(), goal, arg);
    UnitAI ai = unit.getAI();
    switch(function) {
        case MOVE_TO:
            // via a path!
            ActionPath path = getPathSequenceConstructor().getOptimalPathSequence(unit.getAI(), new Coordinates(arg.toString()));
            sequence = new ActionSequence(path.getActions(), task, unit.getAI());
            break;
        case TURN_TO:
            // cell id
            sequence = new ActionSequence(getTurnSequenceConstructor().getTurnSequence(FACING_SINGLE.IN_FRONT, unit, new Coordinates(arg.toString())), task, unit.getAI());
            break;
        case ACTION:
            Action action = AiActionFactory.newAction(arg.toString(), ai);
            // new ActionSequence();
            sequence = getActionSequenceConstructor().constructSingleActionSequence(action, new Task(ai, goal, args[0]));
            break;
        case ATTACK:
            break;
        case FREEZE:
            break;
        case UNFREEZE:
            break;
        case ORDER:
            // OrderFactory.getOrder();
            Order a = new Order(arg.toString());
            unit.getAI().setCurrentOrder(a);
            return;
    }
    if (immediate) {
        unit.getAI().setStandingOrders(sequence);
        unit.getAI().setFree(free);
    } else
        sequence.getActions().forEach(// TODO wait?
        action -> getExecutor().execute(action, free));
}
Also used : Order(eidolons.game.battlecraft.ai.advanced.companion.Order) Action(eidolons.game.battlecraft.ai.elements.actions.Action) ScriptExecutor(eidolons.game.battlecraft.logic.meta.scenario.script.ScriptExecutor) ActionSequence(eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence) AiHandler(eidolons.game.battlecraft.ai.elements.generic.AiHandler) AiMaster(eidolons.game.battlecraft.ai.elements.generic.AiMaster) FACING_SINGLE(main.content.enums.entity.UnitEnums.FACING_SINGLE) Order(eidolons.game.battlecraft.ai.advanced.companion.Order) COMBAT_SCRIPT_FUNCTION(eidolons.game.battlecraft.logic.battle.mission.CombatScriptExecutor.COMBAT_SCRIPT_FUNCTION) Ref(main.entity.Ref) UnitAI(eidolons.game.battlecraft.ai.UnitAI) DataManager(main.data.DataManager) GOAL_TYPE(main.content.enums.system.AiEnums.GOAL_TYPE) AiActionFactory(eidolons.game.battlecraft.ai.elements.actions.AiActionFactory) Task(eidolons.game.battlecraft.ai.elements.task.Task) Coordinates(main.game.bf.Coordinates) Unit(eidolons.entity.obj.unit.Unit) ActionPath(eidolons.game.battlecraft.ai.tools.path.ActionPath) EnumMaster(main.system.auxiliary.EnumMaster) Task(eidolons.game.battlecraft.ai.elements.task.Task) Action(eidolons.game.battlecraft.ai.elements.actions.Action) ActionSequence(eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence) UnitAI(eidolons.game.battlecraft.ai.UnitAI) Coordinates(main.game.bf.Coordinates) GOAL_TYPE(main.content.enums.system.AiEnums.GOAL_TYPE) ActionPath(eidolons.game.battlecraft.ai.tools.path.ActionPath)

Example 2 with GOAL_TYPE

use of main.content.enums.system.AiEnums.GOAL_TYPE in project Eidolons by IDemiurge.

the class GoalManager method getGoalsForUnit.

public static List<GOAL_TYPE> getGoalsForUnit(UnitAI ai) {
    Unit unit = ai.getUnit();
    List<GOAL_TYPE> list = getBehaviorGoals(unit);
    if (list != null) {
        return list;
    }
    if (ai.getCurrentOrder() != null)
        if (ai.getCurrentOrder().getStrictPriority() != null)
            return new ArrayList<>(Arrays.asList(ai.getCurrentOrder().getStrictPriority().getGoalTypes()));
    list = new ArrayList<>();
    if (unit.getAiType() == AiEnums.AI_TYPE.SNEAK) {
        list.add(AiEnums.GOAL_TYPE.STEALTH);
    }
    if (Analyzer.getVisibleEnemies(unit.getUnitAI()).isEmpty()) {
        list = new ListMaster<GOAL_TYPE>().getList(AiEnums.GOAL_TYPE.SEARCH);
        addNonEnemyGoals(list);
        return list;
    }
    if (unit.checkAiMod(AI_MODIFIERS.TRUE_BRUTE)) {
        return new ListMaster<GOAL_TYPE>().getList(AiEnums.GOAL_TYPE.ATTACK);
    }
    list.addAll(getDefaultGoals());
    if (unit.getAiType() == AiEnums.AI_TYPE.CASTER || unit.getAiType() == AiEnums.AI_TYPE.ARCHER) {
        if (!unit.checkPassive(UnitEnums.STANDARD_PASSIVES.FEARLESS)) {
            if (DC_PriorityManager.getMeleeDangerFactor(unit) > 0) {
                list.add(AiEnums.GOAL_TYPE.RETREAT);
            }
        }
    }
    if (Analyzer.hasAnySpecialActions(unit)) {
        addNonEnemyGoals(list);
        addEnemyGoals(list);
    }
    list.sort(getSorter(ai));
    // FLEE
    return list;
}
Also used : ArrayList(java.util.ArrayList) GOAL_TYPE(main.content.enums.system.AiEnums.GOAL_TYPE) ListMaster(main.system.auxiliary.data.ListMaster) Unit(eidolons.entity.obj.unit.Unit)

Example 3 with GOAL_TYPE

use of main.content.enums.system.AiEnums.GOAL_TYPE in project Eidolons by IDemiurge.

the class ActionManager method getForcedAction.

public Action getForcedAction(UnitAI ai) {
    BEHAVIOR_MODE behaviorMode = ai.getBehaviorMode();
    GOAL_TYPE goal = AiEnums.GOAL_TYPE.PREPARE;
    Action action = null;
    if (behaviorMode != null) {
        if (behaviorMode == AiEnums.BEHAVIOR_MODE.PANIC) {
            action = new Action(ai.getUnit().getAction("Cower"));
        }
        if (behaviorMode == AiEnums.BEHAVIOR_MODE.CONFUSED) {
            action = new Action(ai.getUnit().getAction("Stumble"));
        }
        if (behaviorMode == AiEnums.BEHAVIOR_MODE.BERSERK) {
            action = new Action(ai.getUnit().getAction("Rage"));
        }
        action.setTaskDescription("Forced Behavior");
    }
    action = getAtomicAi().getAtomicActionForced(ai);
    if (action != null)
        return action;
    try {
        action = getAtomicAi().getAtomicActionPrepare(getUnit().getAI());
    } catch (Exception e) {
        main.system.ExceptionMaster.printStackTrace(e);
    }
    if (action != null) {
        return action;
    }
    List<ActionSequence> actions = getActionSequenceConstructor().createActionSequencesForGoal(new Goal(goal, ai, true), ai);
    if (ai.checkMod(AI_MODIFIERS.TRUE_BRUTE)) {
        goal = AiEnums.GOAL_TYPE.ATTACK;
        actions.addAll(getActionSequenceConstructor().createActionSequencesForGoal(new Goal(goal, ai, true), ai));
    }
    if (behaviorMode == null) {
        if (ParamAnalyzer.isFatigued(getUnit())) {
            actions.add(new ActionSequence(AiEnums.GOAL_TYPE.PREPARE, getAction(getUnit(), STD_MODE_ACTIONS.Rest.name())));
        }
        if (ParamAnalyzer.isHazed(getUnit())) {
            // when is that used?
            actions.add(new ActionSequence(AiEnums.GOAL_TYPE.PREPARE, getAction(getUnit(), STD_MODE_ACTIONS.Concentrate.name())));
        }
    }
    if (actions.isEmpty()) {
        return getAction(getUnit(), STD_MODE_ACTIONS.Defend.name(), null);
    }
    ActionSequence sequence = getPriorityManager().chooseByPriority(actions);
    LogMaster.log(1, getUnit() + " has been Forced to choose " + "" + sequence + " with priorioty of " + sequence.getPriority());
    getMaster().getMessageBuilder().append("Forced Task: " + sequence.getTask().toShortString());
    action = sequence.nextAction();
    if (action == null) {
        return getAction(getUnit(), STD_MODE_ACTIONS.Defend.name(), null);
    }
    return action;
}
Also used : DC_UnitAction(eidolons.entity.active.DC_UnitAction) Goal(eidolons.game.battlecraft.ai.elements.goal.Goal) ActionSequence(eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence) GOAL_TYPE(main.content.enums.system.AiEnums.GOAL_TYPE) BEHAVIOR_MODE(main.content.enums.system.AiEnums.BEHAVIOR_MODE)

Example 4 with GOAL_TYPE

use of main.content.enums.system.AiEnums.GOAL_TYPE 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 5 with GOAL_TYPE

use of main.content.enums.system.AiEnums.GOAL_TYPE 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

GOAL_TYPE (main.content.enums.system.AiEnums.GOAL_TYPE)6 Action (eidolons.game.battlecraft.ai.elements.actions.Action)3 ActionSequence (eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence)3 DC_UnitAction (eidolons.entity.active.DC_UnitAction)2 Unit (eidolons.entity.obj.unit.Unit)2 Goal (eidolons.game.battlecraft.ai.elements.goal.Goal)2 ArrayList (java.util.ArrayList)2 RollEffect (eidolons.ability.effects.oneshot.mechanic.RollEffect)1 DC_ActiveObj (eidolons.entity.active.DC_ActiveObj)1 DC_QuickItemAction (eidolons.entity.active.DC_QuickItemAction)1 UnitAI (eidolons.game.battlecraft.ai.UnitAI)1 Order (eidolons.game.battlecraft.ai.advanced.companion.Order)1 AiActionFactory (eidolons.game.battlecraft.ai.elements.actions.AiActionFactory)1 AiQuickItemAction (eidolons.game.battlecraft.ai.elements.actions.AiQuickItemAction)1 AiHandler (eidolons.game.battlecraft.ai.elements.generic.AiHandler)1 AiMaster (eidolons.game.battlecraft.ai.elements.generic.AiMaster)1 Task (eidolons.game.battlecraft.ai.elements.task.Task)1 ActionPath (eidolons.game.battlecraft.ai.tools.path.ActionPath)1 COMBAT_SCRIPT_FUNCTION (eidolons.game.battlecraft.logic.battle.mission.CombatScriptExecutor.COMBAT_SCRIPT_FUNCTION)1 ScriptExecutor (eidolons.game.battlecraft.logic.meta.scenario.script.ScriptExecutor)1