Search in sources :

Example 16 with BattleFieldObject

use of eidolons.entity.obj.BattleFieldObject in project Eidolons by IDemiurge.

the class GridPanel method init.

public GridPanel init(DequeImpl<BattleFieldObject> units) {
    this.viewMap = new HashMap<>();
    emptyImage = TextureCache.getOrCreateR(getCellImagePath());
    cornerRegion = TextureCache.getOrCreateR(gridCornerElementPath);
    cells = new GridCellContainer[cols][rows];
    int rows1 = rows - 1;
    for (int x = 0; x < cols; x++) {
        for (int y = 0; y < rows; y++) {
            cells[x][y] = new GridCellContainer(emptyImage, x, rows1 - y);
            cells[x][y].setX(x * GridMaster.CELL_W);
            cells[x][y].setY(y * GridMaster.CELL_H);
            addActor(cells[x][y].init());
            checkAddBorder(x, y);
        }
    }
    if (OptionsMaster.getGraphicsOptions().getBooleanValue(GRAPHIC_OPTION.SPRITE_CACHE_ON))
        TextureManager.addCellsToCache(cols, rows);
    addActor(new CellBorderManager());
    bindEvents();
    createUnitsViews(units);
    setHeight(cells[0][0].getHeight() * rows);
    setWidth(cells[0][0].getWidth() * cols);
    addListener(new BattleClickListener() {

        @Override
        public boolean mouseMoved(InputEvent event, float x, float y) {
            GridPanel.this.getStage().setScrollFocus(GridPanel.this);
            return false;
        }

        @Override
        public boolean touchDown(InputEvent e, float x, float y, int pointer, int button) {
            // return PhaseAnimator.getInstance().checkAnimClicked(x, y, pointer, button);
            return false;
        }
    });
    addActor(overlayManager = new OverlaysManager(this));
    addActor(animMaster = AnimMaster.getInstance());
    animMaster.bindEvents();
    if (AnimationConstructor.isPreconstructAllOnGameInit())
        units.forEach(unit -> {
            if (unit instanceof Unit)
                animMaster.getConstructor().preconstructAll((Unit) unit);
        });
    if (fpsDebug) {
        fpsLabel = new Label("0", StyleHolder.getDefaultLabelStyle());
        addActor(fpsLabel);
        fpsLabel.setAlignment(Align.topLeft);
    }
    return this;
}
Also used : StrPathBuilder(main.system.auxiliary.StrPathBuilder) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) LastSeenMaster(eidolons.game.battlecraft.logic.battlefield.vision.LastSeenMaster) GuiEventType(main.system.GuiEventType) MapMaster(main.system.auxiliary.data.MapMaster) Entrance(eidolons.game.module.dungeoncrawl.dungeon.Entrance) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) DungeonScreen(eidolons.libgdx.screens.DungeonScreen) Ref(main.entity.Ref) Pair(org.apache.commons.lang3.tuple.Pair) Vector2(com.badlogic.gdx.math.Vector2) GdxMaster(eidolons.libgdx.GdxMaster) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) OptionsMaster(eidolons.system.options.OptionsMaster) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) HpBar(eidolons.libgdx.bf.overlays.HpBar) OUTLINE_TYPE(main.content.enums.rules.VisionEnums.OUTLINE_TYPE) MoveAnimation(eidolons.libgdx.anims.std.MoveAnimation) TextureManager(eidolons.libgdx.texture.TextureManager) DC_Obj(eidolons.entity.obj.DC_Obj) ActorMaster(eidolons.libgdx.anims.ActorMaster) Event(main.game.logic.event.Event) FadeOutAction(eidolons.libgdx.anims.actions.FadeOutAction) Align(com.badlogic.gdx.utils.Align) DC_Game(eidolons.game.core.game.DC_Game) BattleFieldObject(eidolons.entity.obj.BattleFieldObject) ShadowMap(eidolons.libgdx.bf.light.ShadowMap) HelpMaster(eidolons.system.text.HelpMaster) List(java.util.List) OutlineMaster(eidolons.game.battlecraft.logic.battlefield.vision.OutlineMaster) Keys(com.badlogic.gdx.Input.Keys) Coordinates(main.game.bf.Coordinates) WallMap(eidolons.libgdx.bf.overlays.WallMap) STANDARD_EVENT_TYPE(main.game.logic.event.Event.STANDARD_EVENT_TYPE) java.util(java.util) DequeImpl(main.system.datatypes.DequeImpl) DeathAnim(eidolons.libgdx.anims.std.DeathAnim) BattleClickListener(eidolons.libgdx.bf.mouse.BattleClickListener) AnimMaster(eidolons.libgdx.anims.AnimMaster) EVENT_TYPE(main.game.logic.event.Event.EVENT_TYPE) Gdx(com.badlogic.gdx.Gdx) Batch(com.badlogic.gdx.graphics.g2d.Batch) WaitMaster(main.system.threading.WaitMaster) GuiEventManager(main.system.GuiEventManager) StringMaster(main.system.auxiliary.StringMaster) DC_Engine(eidolons.game.battlecraft.DC_Engine) OverlaysManager(eidolons.libgdx.bf.overlays.OverlaysManager) PanelActionsDataSource(eidolons.libgdx.gui.panels.dc.actionpanel.datasource.PanelActionsDataSource) GRAPHIC_OPTION(eidolons.system.options.GraphicsOptions.GRAPHIC_OPTION) VisionManager(eidolons.game.battlecraft.logic.battlefield.vision.VisionManager) LogMaster(main.system.auxiliary.log.LogMaster) EventCallback(main.system.EventCallback) KEYS(main.entity.Ref.KEYS) AnimationConstructor(eidolons.libgdx.anims.AnimationConstructor) FloatingTextMaster(eidolons.libgdx.anims.text.FloatingTextMaster) ResourceSourceImpl(eidolons.libgdx.gui.panels.dc.unitinfo.datasource.ResourceSourceImpl) Group(com.badlogic.gdx.scenes.scene2d.Group) StyleHolder(eidolons.libgdx.StyleHolder) TEXT_CASES(eidolons.libgdx.anims.text.FloatingTextMaster.TEXT_CASES) eidolons.libgdx.bf(eidolons.libgdx.bf) WAIT_OPERATIONS(main.system.threading.WaitMaster.WAIT_OPERATIONS) java.awt(java.awt) TextureCache(eidolons.libgdx.texture.TextureCache) Eidolons(eidolons.game.core.Eidolons) Unit(eidolons.entity.obj.unit.Unit) DC_SoundMaster(eidolons.system.audio.DC_SoundMaster) SHADE_LIGHT(eidolons.libgdx.bf.light.ShadowMap.SHADE_LIGHT) OverlaysManager(eidolons.libgdx.bf.overlays.OverlaysManager) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) BattleClickListener(eidolons.libgdx.bf.mouse.BattleClickListener) Unit(eidolons.entity.obj.unit.Unit)

Example 17 with BattleFieldObject

use of eidolons.entity.obj.BattleFieldObject in project Eidolons by IDemiurge.

the class GridPanel method act.

@Override
public void act(float delta) {
    if (resetVisibleRequired) {
        resetVisible();
    }
    super.act(delta);
    if (updateRequired) {
        resetZIndices();
        update();
    }
    if (isAutoResetVisibleOn()) {
        if (resetTimer <= 0) {
            resetTimer = 0.5f;
            for (BattleFieldObject sub : DC_Game.game.getVisionMaster().getVisible()) {
                setVisible(viewMap.get(sub), true);
            }
            for (BattleFieldObject sub : DC_Game.game.getVisionMaster().getInvisible()) {
                setVisible(viewMap.get(sub), false);
            }
        }
        resetTimer -= delta;
    }
}
Also used : BattleFieldObject(eidolons.entity.obj.BattleFieldObject)

Example 18 with BattleFieldObject

use of eidolons.entity.obj.BattleFieldObject in project Eidolons by IDemiurge.

the class GridPanel method bindEvents.

private void bindEvents() {
    GuiEventManager.bind(GuiEventType.ANIMATION_QUEUE_FINISHED, (p) -> {
        resetVisible();
    });
    GuiEventManager.bind(GuiEventType.UPDATE_LAST_SEEN_VIEWS, p -> {
        List<BattleFieldObject> list = (List<BattleFieldObject>) p.get();
        for (BattleFieldObject sub : viewMap.keySet()) {
            GridUnitView view = (GridUnitView) viewMap.get(sub);
            if (list.contains(sub)) {
                setVisible(view.getLastSeenView(), true);
            } else {
                setVisible(view.getLastSeenView(), false);
            }
        }
    });
    GuiEventManager.bind(UNIT_GREYED_OUT_ON, obj -> {
        BattleFieldObject bfObj = (BattleFieldObject) obj.get();
        if (bfObj.isOverlaying())
            return;
        UnitView unitView = getUnitView(bfObj);
        unitView.setFlickering(true);
        unitView.setGreyedOut(true);
    // unitView.setVisible(true);
    });
    GuiEventManager.bind(UNIT_GREYED_OUT_OFF, obj -> {
        BattleFieldObject bfObj = (BattleFieldObject) obj.get();
        if (bfObj.isOverlaying())
            return;
        UnitView unitView = getUnitView(bfObj);
        unitView.setGreyedOut(false);
        unitView.setFlickering(false);
        // ActorMaster.getActionsOfClass(unitView, AlphaAction.class);
        unitView.getActions().clear();
    // unitView.setVisible(true);
    });
    GuiEventManager.bind(UNIT_STARTS_MOVING, obj -> {
        detachUnitView((BattleFieldObject) obj.get());
    });
    // GuiEventManager.bind(GRID_OBJ_HOVER_ON, (event) -> {
    // resetZIndices();
    // });
    // GuiEventManager.bind(GRID_OBJ_HOVER_OFF, (event) -> {
    // resetZIndices();
    // });
    GuiEventManager.bind(UNIT_MOVED, obj -> {
        moveUnitView((BattleFieldObject) obj.get());
    });
    GuiEventManager.bind(UPDATE_GUI, obj -> {
        if (!VisionManager.isVisionHacked())
            if (OutlineMaster.isAutoOutlinesOff())
                if (OutlineMaster.isOutlinesOn()) {
                    updateOutlines();
                }
        firstUpdateDone = true;
        resetVisibleRequired = true;
        updateRequired = true;
        DungeonScreen.getInstance().updateGui();
    });
    GuiEventManager.bind(SELECT_MULTI_OBJECTS, obj -> {
        Pair<Set<DC_Obj>, TargetRunnable> p = (Pair<Set<DC_Obj>, TargetRunnable>) obj.get();
        if (p.getLeft().isEmpty()) {
            FloatingTextMaster.getInstance().createFloatingText(TEXT_CASES.REQUIREMENT, "No targets available!", Eidolons.getGame().getManager().getControlledObj());
            return;
        }
        Map<Borderable, Runnable> map = new HashMap<>();
        for (DC_Obj obj1 : p.getLeft()) {
            Borderable b = viewMap.get(obj1);
            if (b == null) {
                b = cells[obj1.getX()][rows - 1 - obj1.getY()];
            }
            if (b instanceof GridUnitView) {
                final GridUnitView gridView = (GridUnitView) b;
                final UnitView unitView = gridView.getInitiativeQueueUnitView();
                map.put(unitView, () -> p.getRight().run(obj1));
            }
            map.put(b, () -> p.getRight().run(obj1));
        }
        GuiEventManager.trigger(SHOW_BLUE_BORDERS, map);
    });
    GuiEventManager.bind(DESTROY_UNIT_MODEL, param -> {
        BattleFieldObject unit = (BattleFieldObject) param.get();
        removeUnitView(unit);
    });
    GuiEventManager.bind(INGAME_EVENT_TRIGGERED, onIngameEvent());
    GuiEventManager.bind(UPDATE_GRAVEYARD, obj -> {
        final Coordinates coordinates = (Coordinates) obj.get();
        cells[coordinates.getX()][rows - 1 - coordinates.getY()].updateGraveyard();
    });
    GuiEventManager.bind(ACTIVE_UNIT_SELECTED, obj -> {
        BattleFieldObject hero = (BattleFieldObject) obj.get();
        DungeonScreen.getInstance().activeUnitSelected(hero);
        if (hero instanceof Unit)
            animMaster.getConstructor().tryPreconstruct((Unit) hero);
        BaseView view = viewMap.get(hero);
        if (view == null) {
            System.out.println("viewMap not initiatilized at ACTIVE_UNIT_SELECTED!");
            return;
        }
        if (view.getParent() instanceof GridCellContainer) {
            ((GridCellContainer) view.getParent()).popupUnitView((GridUnitView) view);
        }
        viewMap.values().stream().forEach(v -> v.setActive(false));
        view.setActive(true);
        if (hero.isMine()) {
            GuiEventManager.trigger(SHOW_TEAM_COLOR_BORDER, view);
            GuiEventManager.trigger(BOTTOM_PANEL_UPDATE, new PanelActionsDataSource((Unit) hero));
        } else {
            GuiEventManager.trigger(SHOW_TEAM_COLOR_BORDER, view);
            GuiEventManager.trigger(BOTTOM_PANEL_UPDATE, null);
        }
        if (!firstUpdateDone) {
            DC_Game.game.getVisionMaster().triggerGuiEvents();
            GuiEventManager.trigger(UPDATE_GUI, null);
            GuiEventManager.trigger(UPDATE_LIGHT);
        }
        if (HelpMaster.isDefaultTextOn())
            if (!welcomeInfoShown) {
                new Thread(() -> {
                    WaitMaster.WAIT(2000);
                    GuiEventManager.trigger(SHOW_TEXT_CENTERED, HelpMaster.getWelcomeText());
                }, " thread").start();
                welcomeInfoShown = true;
            }
    });
    // GuiEventManager.bind(UPDATE_UNIT_VISIBLE, obj -> {
    // final Pair<Unit, Boolean> pair = (Pair<Unit, Boolean>) obj.get();
    // final BaseView baseView = viewMap.get(pair.getLeft());
    // if (baseView instanceof GridUnitView) {
    // final Boolean isVisible = pair.getRight();
    // //TODO ???
    // ((GridUnitView) baseView).setVisibleVal(isVisible ? 100 : 50);
    // }
    // });
    GuiEventManager.bind(UNIT_VISIBLE_ON, p -> {
        if (p.get() instanceof Collection) {
            for (Object sub : ((Collection) p.get())) {
                setVisible((BattleFieldObject) sub, true);
            }
            return;
        }
        setVisible((BattleFieldObject) p.get(), true);
    });
    GuiEventManager.bind(UNIT_VISIBLE_OFF, p -> {
        if (p.get() instanceof Collection) {
            for (Object sub : ((Collection) p.get())) {
                setVisible((BattleFieldObject) sub, false);
            }
            return;
        }
        setVisible((BattleFieldObject) p.get(), false);
    });
    GuiEventManager.bind(UPDATE_UNIT_ACT_STATE, obj -> {
        final Pair<Unit, Boolean> pair = (Pair<Unit, Boolean>) obj.get();
        final BaseView baseView = viewMap.get(pair.getLeft());
        if (baseView instanceof GridUnitView) {
            final boolean mobilityState = pair.getRight();
            ((GridUnitView) baseView).getInitiativeQueueUnitView().setQueueMoving(mobilityState);
        }
    });
    GuiEventManager.bind(GuiEventType.HP_BAR_UPDATE_MANY, p -> {
        List list = (List) p.get();
        list.forEach(o -> updateHpBar(o));
    });
    GuiEventManager.bind(GuiEventType.HP_BAR_UPDATE, p -> {
        updateHpBar(p.get());
    });
}
Also used : Unit(eidolons.entity.obj.unit.Unit) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) Coordinates(main.game.bf.Coordinates) DC_Obj(eidolons.entity.obj.DC_Obj) BattleFieldObject(eidolons.entity.obj.BattleFieldObject) PanelActionsDataSource(eidolons.libgdx.gui.panels.dc.actionpanel.datasource.PanelActionsDataSource) BattleFieldObject(eidolons.entity.obj.BattleFieldObject)

Example 19 with BattleFieldObject

use of eidolons.entity.obj.BattleFieldObject in project Eidolons by IDemiurge.

the class PriorityManagerImpl method getUnitPriority.

@Override
public int getUnitPriority(UnitAI unit_ai, Obj targetObj, Boolean less_or_more_for_health) {
    BattleFieldObject target_unit = (BattleFieldObject) targetObj;
    if (targetObj instanceof DC_HeroAttachedObj) {
        DC_HeroAttachedObj attachedObj = (DC_HeroAttachedObj) targetObj;
        targetObj = attachedObj.getOwnerObj();
    }
    Integer basePriority = targetObj.getIntParam(PARAMS.POWER);
    if (unit_ai != null) {
        if (unit_ai.getBehaviorMode() == AiEnums.BEHAVIOR_MODE.BERSERK) {
            basePriority = 100;
        } else if (targetObj.getOBJ_TYPE_ENUM() == DC_TYPE.BF_OBJ) {
            if (!Analyzer.isBlockingMovement(unit_ai.getUnit(), (Unit) targetObj)) {
                return 0;
            }
            basePriority = 20;
        }
    }
    Integer healthMod = 100;
    if (less_or_more_for_health != null) {
        healthMod = getHealthFactor(targetObj, less_or_more_for_health);
    } else {
        if (targetObj instanceof Unit)
            if (((Unit) targetObj).isUnconscious()) {
                return Math.round(// [QUICK FIX] - more subtle?
                basePriority * getConstValue(AiConst.UNCONSCIOUS_UNIT_PRIORITY_MOD));
            }
    }
    basePriority = basePriority * healthMod / 100;
    // TODO
    return basePriority;
// limit?
}
Also used : DC_HeroAttachedObj(eidolons.entity.obj.attach.DC_HeroAttachedObj) BattleFieldObject(eidolons.entity.obj.BattleFieldObject) Unit(eidolons.entity.obj.unit.Unit)

Example 20 with BattleFieldObject

use of eidolons.entity.obj.BattleFieldObject 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)

Aggregations

BattleFieldObject (eidolons.entity.obj.BattleFieldObject)52 Unit (eidolons.entity.obj.unit.Unit)24 Coordinates (main.game.bf.Coordinates)22 DC_Obj (eidolons.entity.obj.DC_Obj)12 Ref (main.entity.Ref)12 DC_ActiveObj (eidolons.entity.active.DC_ActiveObj)10 Obj (main.entity.obj.Obj)9 DequeImpl (main.system.datatypes.DequeImpl)8 Event (main.game.logic.event.Event)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 DIRECTION (main.game.bf.Coordinates.DIRECTION)5 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)4 Vector2 (com.badlogic.gdx.math.Vector2)4 Align (com.badlogic.gdx.utils.Align)4 Eidolons (eidolons.game.core.Eidolons)4 Gdx (com.badlogic.gdx.Gdx)3 Keys (com.badlogic.gdx.Input.Keys)3 Batch (com.badlogic.gdx.graphics.g2d.Batch)3 Group (com.badlogic.gdx.scenes.scene2d.Group)3