Search in sources :

Example 31 with Unit

use of eidolons.entity.obj.unit.Unit in project Eidolons by IDemiurge.

the class ForcedActionEffect method applyThis.

@Override
public boolean applyThis() {
    Unit unit = (Unit) ref.getTargetObj();
    Ref REF = unit.getRef();
    if (key != null) {
        REF.setTarget(ref.getId(key));
    }
    Action action = new Action(unit.getAction(actionName), REF);
    unit.getGame().getAiManager().getAI(unit).getForcedActions().add(action);
    return true;
}
Also used : Ref(main.entity.Ref) Action(eidolons.game.battlecraft.ai.elements.actions.Action) Unit(eidolons.entity.obj.unit.Unit)

Example 32 with Unit

use of eidolons.entity.obj.unit.Unit in project Eidolons by IDemiurge.

the class MoveEffect method applyThis.

@Override
public boolean applyThis() {
    Unit obj = (Unit) ref.getObj(obj_to_move);
    origin = obj.getCoordinates();
    if (direction != null) {
        destination = obj.getCoordinates().getAdjacentCoordinate(DirectionMaster.getDirectionByFacing(obj.getFacing(), direction));
        game.getMovementManager().move(obj, destination, free, MOVE_MODIFIER.DISPLACEMENT, ref);
        return true;
    }
    destination = getCoordinates();
    game.getMovementManager().move(obj, destination, free, MOVE_MODIFIER.DISPLACEMENT, ref);
    // 
    // FacingManager.
    Coordinates.FACING_DIRECTION facing = obj.getFacing();
    return true;
}
Also used : Coordinates(main.game.bf.Coordinates) Unit(eidolons.entity.obj.unit.Unit)

Example 33 with Unit

use of eidolons.entity.obj.unit.Unit in project Eidolons by IDemiurge.

the class DC_AttackMaster method attack.

private Boolean attack(Attack attack, Ref ref, boolean free, boolean canCounter, Effect onHit, Effect onKill, boolean offhand, boolean counter) {
    ENTRY_TYPE type = ENTRY_TYPE.ATTACK;
    boolean extraAttack = true;
    if (attack.getAction().isCounterMode()) {
        type = ENTRY_TYPE.COUNTER_ATTACK;
    } else if (attack.getAction().isInstantMode()) {
        type = ENTRY_TYPE.INSTANT_ATTACK;
    } else if (attack.getAction().isAttackOfOpportunityMode()) {
        type = ENTRY_TYPE.ATTACK_OF_OPPORTUNITY;
    } else {
        extraAttack = false;
    }
    // LogEntryNode entry = game.getLogManager().newLogEntryNode(type,
    // attack.getAttacker().getName(), attack.getAttackedUnit().getName(), attack.getAction());
    Boolean result = null;
    if (!extraAttack) {
        Unit guard = (Unit) GuardRule.checkTargetChanged(attack.getAction());
        if (guard != null) {
            game.getLogManager().log(guard.getNameIfKnown() + " intercepts " + attack.toLogString());
            ref.setTarget(guard.getId());
            attack.setRef(ref);
            attack.setAttacked(guard);
        }
    }
    attack.setSneak(SneakRule.checkSneak(ref));
    try {
        main.system.auxiliary.log.LogMaster.log(1, attack.getAttacker() + " attacks " + attack.getAttacked() + " with " + attack.getAction());
        result = attackNow(attack, ref, free, canCounter, onHit, onKill, offhand, counter);
        boolean countered = false;
        if (result == null) {
            // first strike
            main.system.auxiliary.log.LogMaster.log(1, "Counter attack with first strike against " + attack.getAction());
            ActiveObj action = counterRule.tryCounter(attack, false);
            if (action != null) {
                AttackEffect effect = EffectMaster.getAttackEffect(action);
                waitForAttackAnimation(effect.getAttack());
            }
            attackNow(attack, ref, free, false, onHit, onKill, offhand, counter);
            countered = true;
            result = true;
        }
        if ((!countered) || attack.getAttacker().hasDoubleCounter()) {
            if (canCounter) {
                if (!counter) {
                    counterRule.tryCounter(attack);
                }
            }
        }
    } catch (Exception e) {
        result = false;
        main.system.ExceptionMaster.printStackTrace(e);
    } finally {
        if (!extraAttack) {
            game.getLogManager().doneLogEntryNode(ENTRY_TYPE.ACTION);
        }
        game.getLogManager().doneLogEntryNode(type);
    }
    return result;
}
Also used : ActiveObj(main.entity.obj.ActiveObj) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj) AttackEffect(eidolons.ability.effects.oneshot.attack.AttackEffect) Unit(eidolons.entity.obj.unit.Unit) ENTRY_TYPE(main.system.text.EntryNodeMaster.ENTRY_TYPE)

Example 34 with Unit

use of eidolons.entity.obj.unit.Unit in project Eidolons by IDemiurge.

the class GuardRule method checkTargetChanged.

public static BattleFieldObject checkTargetChanged(DC_ActiveObj action) {
    BattleFieldObject target = (BattleFieldObject) action.getTargetObj();
    // attack.getAttackedUnit();
    List<Unit> guards = new ArrayList<>();
    Collection<Unit> units = target.getGame().getUnitsForCoordinates(target.getCoordinates());
    for (Unit unit : units) {
        if (unit.isAlliedTo(target.getOwner())) {
            if (unit.getMode() == STD_MODES.GUARDING || unit.checkStatus(STATUS.GUARDING)) {
                Ref ref = Ref.getCopy(action.getRef());
                ref.setTarget(target.getId());
                if (!SneakRule.checkSneak(ref))
                    guards.add(unit);
            }
        }
    }
    // TODO sort
    for (Unit guard : guards) {
        if (guard == target)
            continue;
        if (action.isAttackAny()) {
            if (action.isRanged()) {
                if (checkDefenderTakesMissile(action, guard))
                    return guard;
                continue;
            }
            Attack attack = EffectFinder.getAttackFromAction(action);
            if (checkDefenderTakesAttack(attack, guard))
                return guard;
        } else {
            if (checkDefenderTakesMissile(action, guard))
                return guard;
        }
    }
    // what kind of animation would there be?
    return null;
}
Also used : Ref(main.entity.Ref) BattleFieldObject(eidolons.entity.obj.BattleFieldObject) ArrayList(java.util.ArrayList) Unit(eidolons.entity.obj.unit.Unit)

Example 35 with Unit

use of eidolons.entity.obj.unit.Unit in project Eidolons by IDemiurge.

the class ParryRule method tryParry.

protected boolean tryParry(Attack attack) {
    // absorbed!
    if (!RuleMaster.isRuleTestOn(RULE.PARRYING)) {
        if (!canParry(attack)) {
            return false;
        }
    }
    int attackValue = DefenseVsAttackRule.getAttackValue(attack);
    int defenseValue = DefenseVsAttackRule.getDefenseValue(attack);
    float chance = DefenseVsAttackRule.getProportionBasedChance(attackValue, defenseValue, false);
    chance += attack.getAttackedUnit().getIntParam(PARAMS.PARRY_CHANCE);
    chance += -attack.getAttacker().getIntParam(PARAMS.PARRY_PENETRATION);
    Integer chanceRounded = Math.round(chance);
    // if (!simulation)
    if (attack.getAction().getGame().getCombatMaster().isChancesOff()) {
        if (chanceRounded < 50)
            chanceRounded = 0;
        else
            chanceRounded = 100;
    }
    game.getLogManager().newLogEntryNode(ENTRY_TYPE.PARRY, attack.getAttackedUnit().getName(), attack.getAction().getName(), attack.getAttacker().getName(), chanceRounded.toString());
    if (!RandomWizard.chance(chanceRounded)) {
        game.getLogManager().log(attack.getAttackedUnit().getName() + " fails to parry " + attack.getAction().getName() + " from " + attack.getAttacker().getNameIfKnown() + StringMaster.wrapInParenthesis(chanceRounded + "%"));
        game.getLogManager().doneLogEntryNode();
        if (!RuleMaster.isRuleTestOn(RULE.PARRYING)) {
            return false;
        }
    }
    Unit attacked = (Unit) attack.getAttackedUnit();
    Unit attacker = attack.getAttacker();
    boolean dual = false;
    if (attacked.checkDualWielding()) {
        dual = true;
    }
    int damage = // raw damage
    attack.getPrecalculatedDamageAmount();
    // attack.getDamage();
    game.getLogManager().log(attack.getAttackedUnit().getName() + " parries " + attack.getAction().getName() + " from " + attack.getAttacker().getNameIfKnown() + StringMaster.wrapInParenthesis(chanceRounded + "%") + ", deflecting " + damage + " " + attack.getDamageType() + " damage");
    int mod = DC_Formulas.DEFAULT_PARRY_DURABILITY_DAMAGE_MOD;
    if (dual) {
        mod /= 2;
    }
    AnimPhase animPhase = new AnimPhase(PHASE_TYPE.PARRY, chanceRounded);
    int durabilityLost = attacked.getWeapon(false).reduceDurabilityForDamage(damage, damage, mod, false);
    animPhase.addArg(durabilityLost);
    if (dual) {
        durabilityLost += attacked.getWeapon(true).reduceDurabilityForDamage(damage, damage, mod, false);
        animPhase.addArg(durabilityLost);
    }
    // if (BROKEN)
    // return false
    mod = DC_Formulas.DEFAULT_PARRY_DURABILITY_DAMAGE_MOD;
    durabilityLost = durabilityLost * mod / 100;
    attacker.getActiveWeapon(attack.isOffhand()).reduceDurability(durabilityLost);
    animPhase.addArg(durabilityLost);
    attack.getAnimation().addPhase(animPhase);
    // game.getLogManager().doneLogEntryNode(); ???
    return true;
}
Also used : AnimPhase(main.system.graphics.AnimPhase) Unit(eidolons.entity.obj.unit.Unit)

Aggregations

Unit (eidolons.entity.obj.unit.Unit)258 Coordinates (main.game.bf.Coordinates)53 Ref (main.entity.Ref)33 DC_ActiveObj (eidolons.entity.active.DC_ActiveObj)30 BattleFieldObject (eidolons.entity.obj.BattleFieldObject)26 DC_Obj (eidolons.entity.obj.DC_Obj)26 ArrayList (java.util.ArrayList)26 Obj (main.entity.obj.Obj)26 ObjType (main.entity.type.ObjType)23 DC_SpellObj (eidolons.entity.active.DC_SpellObj)13 DC_Cell (eidolons.entity.obj.DC_Cell)11 Event (main.game.logic.event.Event)11 DC_UnitAction (eidolons.entity.active.DC_UnitAction)10 List (java.util.List)10 DC_Game (eidolons.game.core.game.DC_Game)9 Action (eidolons.game.battlecraft.ai.elements.actions.Action)8 DequeImpl (main.system.datatypes.DequeImpl)8 OUTLINE_TYPE (main.content.enums.rules.VisionEnums.OUTLINE_TYPE)7 Entity (main.entity.Entity)7 DIRECTION (main.game.bf.Coordinates.DIRECTION)7