Search in sources :

Example 26 with FACING_DIRECTION

use of main.game.bf.Coordinates.FACING_DIRECTION in project Eidolons by IDemiurge.

the class ActionManager method chooseAction.

public Action chooseAction() {
    UnitAI ai = getMaster().getUnitAI();
    if (ai.checkStandingOrders()) {
        return ai.getStandingOrders().get(0);
    }
    // TODO try not to? :)
    getPathSequenceConstructor().clearCache();
    if (getUnit() != ai.getUnit()) {
        getCellPrioritizer().reset();
    } else {
    }
    checkDeactivate();
    if (ListMaster.isNotEmpty(ai.getForcedActions())) {
        Action action = ai.getForcedActions().get(0);
        ai.getForcedActions().remove(0);
        return action;
    }
    // if (!ai.isEngaged()) {
    // TODO      return behaviorMaster.getBehaviorAction(ai);
    // }
    FACING_DIRECTION originalFacing = getUnit().getFacing();
    Coordinates originalCoordinates = getUnit().getCoordinates();
    Action action = null;
    ActionSequence chosenSequence = null;
    boolean atomic = false;
    if (isAtomicAiOn())
        try {
            atomic = getAtomicAi().checkAtomicActionRequired(ai);
        } catch (Exception e) {
            main.system.ExceptionMaster.printStackTrace(e);
        }
    if (atomic)
        if (isAtomicAiOn())
            try {
                action = getAtomicAi().getAtomicAction(ai);
            } catch (Exception e) {
                main.system.ExceptionMaster.printStackTrace(e);
                action = getAtomicAi().getAtomicWait(ai.getUnit());
            }
    if (action == null) {
        List<ActionSequence> actions = new ArrayList<>();
        try {
            List<ActionSequence> sequences = getActionSequenceConstructor().createActionSequences(ai);
            for (ActionSequence a : sequences) {
                if (a.get(0).canBeActivated()) {
                    // if (a.getOrCreate(0).canBeTargeted())
                    actions.add(a);
                }
            }
            if (ListMaster.isNotEmpty(actions)) {
                chosenSequence = DC_PriorityManager.chooseByPriority(actions);
            }
        } catch (Exception e) {
            main.system.ExceptionMaster.printStackTrace(e);
        } finally {
            getUnit().setCoordinates(originalCoordinates);
            getUnit().setFacing(originalFacing);
        }
    }
    if (chosenSequence == null) {
        if (action == null) {
            action = getForcedAction(ai);
        }
        return action;
    } else {
        if (chosenSequence.getType() == GOAL_TYPE.DEFEND)
            return chosenSequence.nextAction();
    }
    if (getUnit().getUnitAI().getLogLevel() > UnitAI.LOG_LEVEL_NONE) {
        if (Launcher.DEV_MODE)
            game.getLogManager().log(LOG.GAME_INFO, ai.getUnit().getName() + " chooses task: " + chosenSequence.getTask().toShortString());
        String message = getUnit() + " has chosen: " + chosenSequence + " with priority of " + StringMaster.wrapInParenthesis(chosenSequence.getPriority() + "");
        LogMaster.log(LOG_CHANNEL.AI_DEBUG, message);
        SpecialLogger.getInstance().appendSpecialLog(SPECIAL_LOG.AI, message);
    }
    // TODO for behaviors? ai-issued-orders?
    ai.checkSetOrders(chosenSequence);
    return chosenSequence.nextAction();
}
Also used : DC_UnitAction(eidolons.entity.active.DC_UnitAction) FACING_DIRECTION(main.game.bf.Coordinates.FACING_DIRECTION) ActionSequence(eidolons.game.battlecraft.ai.elements.actions.sequence.ActionSequence) UnitAI(eidolons.game.battlecraft.ai.UnitAI) Coordinates(main.game.bf.Coordinates) ArrayList(java.util.ArrayList)

Example 27 with FACING_DIRECTION

use of main.game.bf.Coordinates.FACING_DIRECTION in project Eidolons by IDemiurge.

the class StructureResetter method resetFacing.

public void resetFacing() {
    FACING_DIRECTION facing = null;
    if (facing != null) {
        setProperty(PROPS.FACING_DIRECTION, facing.getName());
    } else {
        String name = getProperty(PROPS.FACING_DIRECTION);
        facing = (new EnumMaster<FACING_DIRECTION>().retrieveEnumConst(FACING_DIRECTION.class, name));
        if (facing == null) {
            if (getEntity().getDirection() != null) {
                FacingMaster.getFacingFromDirection(getEntity().getDirection());
            } else if (getRef().getObj(KEYS.SUMMONER) != null) {
                facing = ((DC_UnitModel) getRef().getObj(KEYS.SUMMONER)).getFacing();
            } else {
                facing = FacingMaster.getRandomFacing();
            }
        }
    }
    getEntity().setFacing(facing);
// getEntity().setFacing(facing);
}
Also used : FACING_DIRECTION(main.game.bf.Coordinates.FACING_DIRECTION) DC_UnitModel(eidolons.entity.obj.unit.DC_UnitModel)

Example 28 with FACING_DIRECTION

use of main.game.bf.Coordinates.FACING_DIRECTION in project Eidolons by IDemiurge.

the class UnitResetter method resetFacing.

public void resetFacing() {
    FACING_DIRECTION facing = null;
    if (facing != null) {
        setProperty(PROPS.FACING_DIRECTION, facing.getName());
    } else {
        String name = getProperty(PROPS.FACING_DIRECTION);
        facing = (new EnumMaster<FACING_DIRECTION>().retrieveEnumConst(FACING_DIRECTION.class, name));
        if (facing == null) {
            if (getEntity().getDirection() != null) {
                FacingMaster.getFacingFromDirection(getEntity().getDirection());
            } else if (getRef().getObj(KEYS.SUMMONER) != null) {
                facing = ((DC_UnitModel) getRef().getObj(KEYS.SUMMONER)).getFacing();
            } else {
                facing = FacingMaster.getRandomFacing();
            }
        }
    }
    getEntity().setFacing(facing);
}
Also used : FACING_DIRECTION(main.game.bf.Coordinates.FACING_DIRECTION) DC_UnitModel(eidolons.entity.obj.unit.DC_UnitModel)

Example 29 with FACING_DIRECTION

use of main.game.bf.Coordinates.FACING_DIRECTION in project Eidolons by IDemiurge.

the class Targeter method canTargetAny.

public boolean canTargetAny() {
    Targeting targeting = getTargeting();
    if (!(targeting instanceof SelectiveTargeting)) {
        return true;
    }
    Map<FACING_DIRECTION, Boolean> map = getTargetingAnyCache().get(getOwnerObj().getCoordinates());
    if (map == null) {
        map = new HashMap<>();
        targetingAnyCache.put(getOwnerObj().getCoordinates(), map);
    }
    Boolean canTargetAny = map.get(getOwnerObj().getFacing());
    if (canTargetAny == null) {
        canTargetAny = !targeting.getFilter().getObjects(getRef()).isEmpty();
    }
    map.put(getOwnerObj().getFacing(), canTargetAny);
    return canTargetAny;
}
Also used : TemplateSelectiveTargeting(eidolons.ability.targeting.TemplateSelectiveTargeting) SelectiveTargeting(main.elements.targeting.SelectiveTargeting) FACING_DIRECTION(main.game.bf.Coordinates.FACING_DIRECTION) Targeting(main.elements.targeting.Targeting) MultiTargeting(main.elements.targeting.MultiTargeting) AutoTargeting(main.elements.targeting.AutoTargeting) TemplateSelectiveTargeting(eidolons.ability.targeting.TemplateSelectiveTargeting) SelectiveTargeting(main.elements.targeting.SelectiveTargeting)

Example 30 with FACING_DIRECTION

use of main.game.bf.Coordinates.FACING_DIRECTION in project Eidolons by IDemiurge.

the class Targeter method canBeTargeted.

public boolean canBeTargeted(Integer id, boolean caching) {
    Targeting targeting = getTargeting();
    Map<FACING_DIRECTION, Map<Integer, Boolean>> map = getTargetingCache().get(getOwnerObj().getCoordinates());
    if (map == null) {
        map = new HashMap<>();
        getTargetingCache().put(getOwnerObj().getCoordinates(), map);
    }
    Map<Integer, Boolean> map2 = map.get(getOwnerObj().getFacing());
    if (map2 == null) {
        map2 = new HashMap<>();
        map.put(getOwnerObj().getFacing(), map2);
    }
    // TODO for ai?
    Boolean result = map2.get(id);
    if (caching) {
        if (result != null)
            return result;
    }
    if (targeting == null) {
        // TODO ??
        if (getEntity().getActives().size() > 1) {
            return true;
        }
        if (!getEntity().getActives().isEmpty()) {
            if (getEntity().getActives().get(0).getAbilities().getAbils().size() > 1) {
                return true;
            }
        }
        return false;
    }
    Ref REF = getEntity().getRef().getCopy();
    REF.setMatch(id);
    if (targeting instanceof MultiTargeting) {
    // TODO ??
    }
    Conditions conditions = targeting.getFilter().getConditions();
    if (result != null) {
        if (result) {
            if (!conditions.preCheck(REF)) {
                return false;
            }
        }
        if (!result) {
            if (conditions.preCheck(REF)) {
                return true;
            }
        }
    }
    if (conditions.isEmpty())
        if (targeting instanceof TemplateSelectiveTargeting)
            ((TemplateSelectiveTargeting) targeting).initTargeting();
    getEntity().getRef().getSourceObj().getRef().setInfoEntity(getEntity());
    result = conditions.preCheck(REF);
    map2.put(id, result);
    return result;
}
Also used : FACING_DIRECTION(main.game.bf.Coordinates.FACING_DIRECTION) Ref(main.entity.Ref) TemplateSelectiveTargeting(eidolons.ability.targeting.TemplateSelectiveTargeting) Targeting(main.elements.targeting.Targeting) MultiTargeting(main.elements.targeting.MultiTargeting) AutoTargeting(main.elements.targeting.AutoTargeting) TemplateSelectiveTargeting(eidolons.ability.targeting.TemplateSelectiveTargeting) SelectiveTargeting(main.elements.targeting.SelectiveTargeting) MultiTargeting(main.elements.targeting.MultiTargeting) HashMap(java.util.HashMap) Map(java.util.Map) Conditions(main.elements.conditions.Conditions)

Aggregations

FACING_DIRECTION (main.game.bf.Coordinates.FACING_DIRECTION)31 Coordinates (main.game.bf.Coordinates)17 Unit (eidolons.entity.obj.unit.Unit)5 ArrayList (java.util.ArrayList)5 Ref (main.entity.Ref)5 ObjType (main.entity.type.ObjType)5 Obj (main.entity.obj.Obj)4 BattleFieldObject (eidolons.entity.obj.BattleFieldObject)3 DC_UnitModel (eidolons.entity.obj.unit.DC_UnitModel)3 ObjAtCoordinate (main.entity.type.ObjAtCoordinate)3 TemplateSelectiveTargeting (eidolons.ability.targeting.TemplateSelectiveTargeting)2 UnitLevelManager (eidolons.client.cc.logic.UnitLevelManager)2 DC_UnitAction (eidolons.entity.active.DC_UnitAction)2 MapBlock (eidolons.game.battlecraft.logic.dungeon.location.building.MapBlock)2 FACING_SINGLE (main.content.enums.entity.UnitEnums.FACING_SINGLE)2 Conditions (main.elements.conditions.Conditions)2 AutoTargeting (main.elements.targeting.AutoTargeting)2 MultiTargeting (main.elements.targeting.MultiTargeting)2 SelectiveTargeting (main.elements.targeting.SelectiveTargeting)2 Targeting (main.elements.targeting.Targeting)2