Search in sources :

Example 46 with Obj

use of main.entity.obj.Obj 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 47 with Obj

use of main.entity.obj.Obj in project Eidolons by IDemiurge.

the class DC_BattleFieldManager method resetWalls.

public void resetWalls() {
    doorMap.clear();
    Map<Coordinates, BattleFieldObject> wallObjects = new HashMap<>();
    for (Obj obj : game.getObjects(DC_TYPE.BF_OBJ)) {
        BattleFieldObject bfObj = (BattleFieldObject) obj;
        if (bfObj.getZ() == game.getDungeon().getZ()) {
            if (bfObj.isWall()) {
                wallObjects.put(obj.getCoordinates(), bfObj);
            }
            if (bfObj instanceof Door) {
                doorMap.put(obj.getCoordinates(), ((Door) bfObj).getState());
            }
        }
    }
    if (wallMap == null) {
        wallMap = new HashMap<>();
    }
    wallMap.clear();
    ArrayList<Coordinates> coordinates = new ArrayList<>(wallObjects.keySet());
    for (Coordinates coordinate : coordinates) {
        BattleFieldObject wall = wallObjects.get(coordinate);
        if (wall.isDead()) {
            continue;
        }
        List<DIRECTION> list = new ArrayList<>();
        for (Coordinates c : coordinate.getAdjacent(false)) {
            BattleFieldObject adjWall = wallObjects.get(c);
            if (adjWall != null) {
                if (adjWall.isWall() && !adjWall.isDead()) {
                    DIRECTION side = DirectionMaster.getRelativeDirection(coordinate, c);
                    list.add(side);
                }
            }
        }
        adjacent: for (Coordinates c : coordinate.getAdjacent(true)) {
            BattleFieldObject adjWall = wallObjects.get(c);
            if (adjWall != null) {
                if (adjWall.isWall() && !adjWall.isDead()) {
                    DIRECTION side = DirectionMaster.getRelativeDirection(coordinate, c);
                    if (!side.isDiagonal()) {
                        continue;
                    }
                    for (DIRECTION s : list) {
                        if (s.isDiagonal()) {
                            continue;
                        }
                        if (side.getXDirection() == s) {
                            continue adjacent;
                        }
                        if (side.getYDirection() == s) {
                            continue adjacent;
                        }
                    }
                    list.add(side);
                }
            }
        }
        if (!list.isEmpty()) {
            if (coordinate == null)
                continue;
            wallMap.put(coordinate, list);
        }
    }
    if (diagonalJoints == null) {
        diagonalJoints = new HashMap<>();
    }
    diagonalJoints.clear();
    loop: for (Coordinates c : wallMap.keySet()) {
        for (DIRECTION s : wallMap.get(c)) {
            if (s.isDiagonal()) {
                // for (Coordinates c :
                // o.getCoordinates().getAdjacentCoordinates(null)) {
                // if (wallObjects.get(c) != null) {
                // if (containsAdjacentDiagonal in X direction
                // }
                // }
                List<DIRECTION> list = diagonalJoints.get(c);
                if (list == null) {
                    list = new ArrayList<>();
                }
                diagonalJoints.put(c, list);
                if (list.size() == 1) {
                    DIRECTION d = list.get(0);
                    if (s.growX)
                        if (!d.growX)
                            continue;
                        else if (d.growX)
                            continue;
                    if (s.growY)
                        if (!d.growY)
                            continue;
                        else if (d.growY)
                            continue;
                }
                list.add(s);
                continue loop;
            }
        }
    }
    wallResetRequired = false;
}
Also used : BattleFieldObject(eidolons.entity.obj.BattleFieldObject) DC_Obj(eidolons.entity.obj.DC_Obj) Obj(main.entity.obj.Obj) Coordinates(main.game.bf.Coordinates) DIRECTION(main.game.bf.Coordinates.DIRECTION) Door(eidolons.game.module.dungeoncrawl.objects.Door)

Example 48 with Obj

use of main.entity.obj.Obj in project Eidolons by IDemiurge.

the class DC_GraveyardManager method addCorpse.

@Override
public void addCorpse(Obj unit) {
    graveMap.get(getZCoordinate(unit.getCoordinates())).push(unit);
    Obj cell = game.getCellByCoordinate(getZCoordinate(unit.getCoordinates()));
    cell.setParam(G_PARAMS.N_OF_CORPSES, graveMap.get(getZCoordinate(unit.getCoordinates())).size());
    if (game.getObjectByCoordinate(getZCoordinate(unit.getCoordinates())) != null) {
        game.getObjectByCoordinate(getZCoordinate(unit.getCoordinates())).setParam(G_PARAMS.N_OF_CORPSES, graveMap.get(getZCoordinate(unit.getCoordinates())).size());
    }
    GuiEventManager.trigger(UPDATE_GRAVEYARD, unit.getCoordinates());
}
Also used : Obj(main.entity.obj.Obj) BfObj(main.entity.obj.BfObj)

Example 49 with Obj

use of main.entity.obj.Obj in project Eidolons by IDemiurge.

the class DC_ObjInitializer method initializePartyPositions.

public static void initializePartyPositions(String playerPartyData, Collection<? extends Obj> units) {
    List<String> items = Arrays.asList(playerPartyData.split(OBJ_SEPARATOR));
    for (String item : items) {
        Coordinates c = getCoordinatesFromObjString(item);
        String typeName = item.split(COORDINATES_OBJ_SEPARATOR)[1];
        for (Obj unit : units) {
            if (unit.getType().getName().equals(typeName)) {
                if (!DC_Game.game.getRules().getStackingRule().canBeMovedOnto(unit, c)) {
                    // TODO tactics?
                    // direction
                    c = Positioner.adjustCoordinate(c, FacingMaster.getRandomFacing());
                // preference?
                }
                unit.setCoordinates(c);
            }
        }
    }
}
Also used : Obj(main.entity.obj.Obj) MicroObj(main.entity.obj.MicroObj) ZCoordinates(main.game.bf.ZCoordinates) Coordinates(main.game.bf.Coordinates)

Example 50 with Obj

use of main.entity.obj.Obj in project Eidolons by IDemiurge.

the class DroppedItemManager method findDroppedItem.

public DC_HeroItemObj findDroppedItem(String typeName, Coordinates coordinates) {
    Obj cell = game.getCellByCoordinate(coordinates);
    Obj item = new ListMaster<Obj>().findType(typeName, new ArrayList<>(getDroppedItems(cell)));
    return (DC_HeroItemObj) item;
}
Also used : Obj(main.entity.obj.Obj) DC_HeroItemObj(eidolons.entity.item.DC_HeroItemObj) DC_HeroItemObj(eidolons.entity.item.DC_HeroItemObj)

Aggregations

Obj (main.entity.obj.Obj)127 DC_ActiveObj (eidolons.entity.active.DC_ActiveObj)34 DC_Obj (eidolons.entity.obj.DC_Obj)30 Coordinates (main.game.bf.Coordinates)27 Unit (eidolons.entity.obj.unit.Unit)24 ArrayList (java.util.ArrayList)19 Ref (main.entity.Ref)15 DC_SpellObj (eidolons.entity.active.DC_SpellObj)14 BuffObj (main.entity.obj.BuffObj)13 DC_WeaponObj (eidolons.entity.item.DC_WeaponObj)12 DC_QuickItemObj (eidolons.entity.item.DC_QuickItemObj)11 ActiveObj (main.entity.obj.ActiveObj)10 BattleFieldObject (eidolons.entity.obj.BattleFieldObject)9 PassiveAbilityObj (main.ability.PassiveAbilityObj)9 ObjType (main.entity.type.ObjType)8 DC_HeroItemObj (eidolons.entity.item.DC_HeroItemObj)7 DC_BuffObj (eidolons.entity.obj.attach.DC_BuffObj)7 PARAMETER (main.content.values.parameters.PARAMETER)7 Conditions (main.elements.conditions.Conditions)6 MicroObj (main.entity.obj.MicroObj)6