Search in sources :

Example 6 with DAMAGE_TYPE

use of main.content.enums.GenericEnums.DAMAGE_TYPE in project Eidolons by IDemiurge.

the class ResistanceRule method getResistance.

public static int getResistance(Ref ref) {
    DC_ActiveObj spell = (DC_ActiveObj) ref.getObj(KEYS.SPELL);
    if (spell == null) {
        return 0;
    }
    Obj target = ref.getTargetObj();
    Obj source = ref.getSourceObj();
    DAMAGE_TYPE type = spell.getEnergyType();
    int specResist = 0;
    PARAMETER typeResistance = DC_ContentManager.getDamageTypeResistance(type);
    if (typeResistance != null) {
        specResist = target.getIntParam(typeResistance);
    }
    int resistance = specResist;
    // int resistance = target.getIntParam(PARAMS.RESISTANCE);
    // resistance = MathMaster.addFactor(resistance, specResist);
    resistance -= source.getIntParam(PARAMS.RESISTANCE_PENETRATION);
    int mod = spell.getIntParam(PARAMS.RESISTANCE_MOD);
    resistance = MathMaster.applyMod(resistance, mod);
    return resistance;
}
Also used : DC_ActiveObj(eidolons.entity.active.DC_ActiveObj) Obj(main.entity.obj.Obj) DAMAGE_TYPE(main.content.enums.GenericEnums.DAMAGE_TYPE) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj) PARAMETER(main.content.values.parameters.PARAMETER)

Example 7 with DAMAGE_TYPE

use of main.content.enums.GenericEnums.DAMAGE_TYPE in project Eidolons by IDemiurge.

the class DamageCalculator method precalculateDamage.

/**
 * Calculates damage for AI's FutureBuilder (AttackEffect)
 *
 * @param attack
 * @return
 */
public static int precalculateDamage(Attack attack, Boolean min_max_normal) {
    BattleFieldObject attacked = attack.getAttacked();
    Unit attacker = attack.getAttacker();
    if (!attacked.checkPassive(UnitEnums.STANDARD_PASSIVES.SNEAK_IMMUNE)) {
        attack.setSneak(SneakRule.checkSneak(attack.getRef()));
    }
    // TODO ref.setFuture(true) -> average dice, auto-reset action etc
    AttackCalculator calculator = new AttackCalculator(attack, true);
    if (min_max_normal != null)
        if (min_max_normal) {
            calculator.setMin(true);
        } else {
            calculator.setMax(true);
        }
    int amount = calculator.calculateFinalDamage();
    DAMAGE_TYPE dmg_type = attack.getDamageType();
    if (dmg_type == DAMAGE_TYPE.PURE || dmg_type == DAMAGE_TYPE.POISON) {
        return amount;
    }
    if (!(attacked instanceof Unit)) {
        return amount;
    }
    int blocked = attacked.getGame().getArmorSimulator().getShieldDamageBlocked(amount, (Unit) attacked, attacker, attack.getAction(), attack.getWeapon(), attack.getDamageType());
    blocked += attacked.getGame().getArmorSimulator().getArmorBlockDamage(amount, (Unit) attacked, attacker, attack.getAction());
    amount = calculateDamage(true, attacked, attacker, amount, null, blocked, attack.getDamageType());
    if (attack.getAction().isAttackGeneric()) {
        return amount;
    }
    return amount;
}
Also used : AttackCalculator(eidolons.game.battlecraft.rules.combat.attack.AttackCalculator) BattleFieldObject(eidolons.entity.obj.BattleFieldObject) DAMAGE_TYPE(main.content.enums.GenericEnums.DAMAGE_TYPE) Unit(eidolons.entity.obj.unit.Unit)

Example 8 with DAMAGE_TYPE

use of main.content.enums.GenericEnums.DAMAGE_TYPE in project Eidolons by IDemiurge.

the class ResistMaster method initUnitResistances.

public static void initUnitResistances(Unit unit) {
    int resist = unit.getIntParam(PARAMS.RESISTANCE);
    for (DAMAGE_TYPE dmg_type : GenericEnums.DAMAGE_TYPE.values()) {
        PARAMETER resistForDmgType = DC_ContentManager.getResistForDmgType(dmg_type);
        if (resistForDmgType != null) {
            if (dmg_type.isMagical()) {
                RESIST_GRADE grade = new EnumMaster<RESIST_GRADE>().retrieveEnumConst(RESIST_GRADE.class, unit.getProperty(DC_ContentManager.getResistGradeForDmgType(dmg_type)));
                if (grade == null) {
                    grade = GenericEnums.RESIST_GRADE.Normal;
                }
                int amount = resist * grade.getPercent() / 100;
                unit.modifyParameter(resistForDmgType, amount);
            }
        }
    }
}
Also used : RESIST_GRADE(main.content.enums.GenericEnums.RESIST_GRADE) DAMAGE_TYPE(main.content.enums.GenericEnums.DAMAGE_TYPE) PARAMETER(main.content.values.parameters.PARAMETER)

Example 9 with DAMAGE_TYPE

use of main.content.enums.GenericEnums.DAMAGE_TYPE in project Eidolons by IDemiurge.

the class DC_AttackMaster method attackNow.

/**
 * @return null  if attack has been delayed by target's first strike; false if target is killed; true otherwise
 */
private Boolean attackNow(Attack attack, Ref ref, boolean free, boolean canCounter, Effect onHit, Effect onKill, boolean offhand, boolean isCounter) {
    if (!(ref.getTargetObj() instanceof BattleFieldObject)) {
        return true;
    }
    // PhaseAnimation animation =
    // game.getAnimationManager().getAnimation(attack.getAction().getAnimationKey());
    DC_ActiveObj action = (DC_ActiveObj) ref.getObj(KEYS.ACTIVE);
    if (action.checkProperty(G_PROPS.ACTION_TAGS, "" + ActionEnums.ACTION_TAGS.OFF_HAND)) {
        offhand = true;
    }
    if (!offhand) {
        if (action.isRanged()) {
            if (!action.isThrow()) {
                if (getAttackWeapon(ref, true).isRanged()) {
                    offhand = true;
                }
            }
        }
    }
    BattleFieldObject attacked = (BattleFieldObject) ref.getTargetObj();
    Unit attacker = (Unit) ref.getSourceObj();
    if (attack.isSneak()) {
        if (attacked.checkPassive(UnitEnums.STANDARD_PASSIVES.SNEAK_IMMUNE)) {
            attack.setSneak(false);
            log(StringMaster.MESSAGE_PREFIX_INFO + attacked.getName() + " is immune to Sneak Attacks!");
        } else {
            log(StringMaster.MESSAGE_PREFIX_ALERT + attacker.getNameIfKnown() + " makes a Sneak Attack against " + attacked.getName());
        }
    }
    if (canCounter) {
        if (!attacked.canCounter(action, attack.isSneak())) {
            canCounter = false;
        }
    }
    LogMaster.log(LogMaster.ATTACKING_DEBUG, attacker.getNameIfKnown() + " attacks " + attacked.getName());
    // } ====> Need a common messaging interface for actions/costs
    String damage_mods = "";
    // if (sneak)
    // damage_mods+=DAMAGE_MODIFIER.SNEAK;
    ref.setValue(KEYS.DAMAGE_MODS, damage_mods);
    boolean countered = false;
    if (canCounter) {
        if (attacked.hasFirstStrike() && !attacker.hasFirstStrike()) {
            if (!attacker.hasNoRetaliation()) {
                // countered = tryCounter(attack);
                return null;
            }
        }
    }
    if (attacker.isDead()) {
        attack.getAnimation().addPhase(new AnimPhase(PHASE_TYPE.INTERRUPTED, ref));
        return false;
    }
    // TODO revamp
    DC_SoundMaster.playEffectSound(SOUNDS.ATTACK, attacker);
    if (action.isRanged()) {
        DC_SoundMaster.playRangedAttack(getAttackWeapon(ref, offhand));
    }
    int amount = attacker.getIntParam(PARAMS.BASE_DAMAGE);
    ref.setAmount(amount);
    Event event = new Event(STANDARD_EVENT_TYPE.UNIT_IS_BEING_ATTACKED, ref);
    if (!event.fire()) {
        attack.getAnimation().addPhase(new AnimPhase(PHASE_TYPE.INTERRUPTED, ref));
        return false;
    }
    // initializeFullModifiers(attack.isSneak(), offhand, action, ref);
    Boolean dodged = false;
    if (ref.getEffect().isInterrupted()) {
        event.getRef().getEffect().setInterrupted(false);
        dodged = true;
    }
    if (!attacked.isDead())
        if (!dodged) {
            boolean parried = parryRule.tryParry(attack);
            if (parried) {
                attack.setParried(true);
                // if (
                // EventMaster.fireStandard(STANDARD_EVENT_TYPE.ATTACK_DODGED, ref)) {
                attacked.applySpecialEffects(SPECIAL_EFFECTS_CASE.ON_PARRY, attacker, ref);
                attacker.applySpecialEffects(SPECIAL_EFFECTS_CASE.ON_PARRY_SELF, attacked, ref);
                // }
                return true;
            }
            dodged = DefenseVsAttackRule.checkDodgedOrCrit(attack);
        }
    // BEFORE_HIT
    if (!attacked.isDead())
        if (dodged == null) {
            if (!new Event(STANDARD_EVENT_TYPE.UNIT_HAS_BEEN_HIT, ref).fire()) {
                return false;
            }
            if (attacker.isDead()) {
                return true;
            }
        // if (attacked.isDead()) {  // now in unit.kill()
        // if (onKill != null) {
        // onKill.apply(ref);
        // }
        // attacked.applySpecialEffects(SPECIAL_EFFECTS_CASE.ON_DEATH, attacker, ref);
        // return true;
        // }
        } else {
            if (dodged) {
                attack.setDodged(true);
                log(attacked.getName() + " has dodged an attack from " + attacker.getNameIfKnown());
                DC_SoundMaster.playMissedSound(attacker, getAttackWeapon(ref, offhand));
                StackingRule.actionMissed(action);
                // ++ animation? *MISS* //TODO ++ true strike
                action.setFailedLast(true);
                if (checkEffectsInterrupt(attacked, attacker, SPECIAL_EFFECTS_CASE.ON_DODGE, ref, offhand)) {
                    return true;
                }
                if (canCounter) {
                    if ((!countered) || attacked.hasDoubleCounter()) {
                        // tryCounter(attack); TODO ?
                        return true;
                    }
                }
            } else {
                if (attacked.checkPassive(UnitEnums.STANDARD_PASSIVES.CRITICAL_IMMUNE)) {
                    log(StringMaster.MESSAGE_PREFIX_INFO + attacked.getName() + " is immune to Critical Hits!");
                } else {
                    log(StringMaster.MESSAGE_PREFIX_ALERT + attacker.getNameIfKnown() + " scores a critical hit on " + attacked.getName());
                    attack.setCritical(true);
                }
            }
        }
    attacked.applySpecialEffects(SPECIAL_EFFECTS_CASE.BEFORE_HIT, attacker, ref);
    attacker.applySpecialEffects(SPECIAL_EFFECTS_CASE.BEFORE_ATTACK, attacked, ref);
    Integer final_amount = attack.getDamage();
    // TODO REAL CALC How to calc damage w/o crit (for parry)?
    if (final_amount == Attack.DAMAGE_NOT_SET) {
        AttackCalculator calculator = new AttackCalculator(attack, false);
        final_amount = calculator.calculateFinalDamage();
    }
    // TODO different for multiDamageType
    if (CoreEngine.isPhaseAnimsOn())
        PhaseAnimator.getInstance().initAttackAnimRawDamage(attack);
    ref.setAmount(final_amount);
    if (final_amount < 0) {
        return true;
    }
    ref.setAmount(final_amount);
    DAMAGE_TYPE dmg_type = ref.getDamageType();
    if (attack.isCritical()) {
        if (attacker.checkPassive(UnitEnums.STANDARD_PASSIVES.CLEAVING_CRITICALS)) {
            // TODO add default cleave?
            CleaveRule.addCriticalCleave(attacker);
            dmg_type = GenericEnums.DAMAGE_TYPE.SLASHING;
        }
    }
    if (dmg_type == null) {
        dmg_type = action.getDamageType();
    }
    if (dmg_type == null) {
        if (!checkWeapon(ref)) {
            dmg_type = attacker.getDamageType();
        } else {
            dmg_type = getAttackWeapon(ref, offhand).getDamageType();
        }
    }
    attack.setDamageType(dmg_type);
    if (attack.getDamage() == Attack.DAMAGE_NOT_SET) {
        attack.setDamage(final_amount);
    }
    if (!new Event(STANDARD_EVENT_TYPE.UNIT_HAS_BEEN_ATTACKED, ref).fire()) {
        return false;
    }
    if (!new Event(STANDARD_EVENT_TYPE.UNIT_HAS_BEEN_HIT, ref).fire()) {
        return false;
    }
    Unit attackedUnit = null;
    if (attacked instanceof Unit) {
        attackedUnit = (Unit) attacked;
    }
    if (!attacked.isDead())
        if (attackedUnit != null)
            if (attackedUnit.getOffhandWeapon() != null) {
                if (attackedUnit.getOffhandWeapon().isShield()) {
                    if (!attack.isSneak()) {
                        // && !isCounter) {
                        int blocked = game.getArmorMaster().getShieldDamageBlocked(final_amount, attackedUnit, attacker, action, getAttackWeapon(ref, attack.isOffhand()), attack.getDamageType());
                        final_amount -= blocked;
                        if (blocked > 0) {
                            Ref REF = ref.getCopy();
                            REF.setAmount(blocked);
                            if (checkEffectsInterrupt(attackedUnit, attacker, SPECIAL_EFFECTS_CASE.ON_SHIELD_BLOCK, REF, offhand)) {
                                return true;
                            }
                            if (checkEffectsInterrupt(attacker, attackedUnit, SPECIAL_EFFECTS_CASE.ON_SHIELD_BLOCK_SELF, REF, offhand)) {
                                return true;
                            }
                        }
                    }
                }
            }
    // armor penetration?
    attack.setDamage(final_amount);
    if (checkAttackEventsInterrupt(attack, ref)) {
        return true;
    }
    // ForceRule.addForceEffects(action); now in executor.resolve() for all actions
    Damage damageObj = DamageFactory.getDamageForAttack(dmg_type, ref, final_amount);
    int damageDealt = DamageDealer.dealDamage(damageObj);
    attack.damageDealt(damageDealt);
    attack.reset();
    if (attacked.isDead()) {
        if (!attack.isTriggered()) {
            game.getRules().getCleaveRule().apply(ref, attack);
        }
    }
    if (onHit != null) {
        onHit.apply(ref);
    }
    if (!action.isRanged()) {
        // e.g.
        attacked.applySpecialEffects(SPECIAL_EFFECTS_CASE.ON_HIT, attacker, ref);
    }
    if (attackedUnit != null)
        // e.g.
        attacker.applySpecialEffects(SPECIAL_EFFECTS_CASE.ON_ATTACK, attackedUnit, ref, offhand);
    try {
        // map=
        CoatingRule.unitIsHit(attacked, attacker, offhand, action, attack, attack.getWeapon());
    } catch (Exception e) {
        main.system.ExceptionMaster.printStackTrace(e);
    }
    if (attackedUnit != null) {
        InjuryRule.applyInjuryRule(action);
        if (attack.isCritical()) {
            checkEffectsInterrupt(attackedUnit, attacker, SPECIAL_EFFECTS_CASE.ON_CRIT_SELF, ref, offhand);
            checkEffectsInterrupt(attacker, attackedUnit, SPECIAL_EFFECTS_CASE.ON_CRIT, ref, offhand);
        }
    }
    return true;
}
Also used : AnimPhase(main.system.graphics.AnimPhase) DAMAGE_TYPE(main.content.enums.GenericEnums.DAMAGE_TYPE) Unit(eidolons.entity.obj.unit.Unit) Ref(main.entity.Ref) BattleFieldObject(eidolons.entity.obj.BattleFieldObject) Event(main.game.logic.event.Event) DC_ActiveObj(eidolons.entity.active.DC_ActiveObj) Damage(eidolons.game.battlecraft.rules.combat.damage.Damage)

Example 10 with DAMAGE_TYPE

use of main.content.enums.GenericEnums.DAMAGE_TYPE in project Eidolons by IDemiurge.

the class AttackAnimation method drawRawDamage.

protected void drawRawDamage(List<Damage> rawDamage) {
    Image image = ImageManager.getDamageTypeImage(GenericEnums.DAMAGE_TYPE.PHYSICAL.getName());
    Point p = GeometryMaster.getFarthestPointInRectangleForImage(w, h, image, direction.flip());
    // - rawDamage.size()*20
    int y = p.y;
    if (BooleanMaster.isTrue((direction.growY))) {
        y -= 30;
    }
    int x = p.x;
    for (Damage dmg : rawDamage) {
        int damage = dmg.getAmount();
        if (damage >= 0) {
            DAMAGE_TYPE dmg_type = dmg.getDmgType();
            image = ImageManager.getDamageTypeImage(dmg_type.getName());
            Font font = getFontNegative();
            int max = Math.max(image.getWidth(null), FontMaster.getFontHeight(font));
            drawOnTarget(image, x, y);
            addMouseItem(false, x, y, 32, 32, new MouseItemImpl(MOUSE_ITEM.SUB_PHASE, PHASE_TYPE.DAMAGE_FORMULA));
            y = y + (image.getHeight(null));
            if (direction.isVertical()) {
                y += drawTextOnTarget(StringMaster.wrapInBraces(damage + ""), font, x, y);
            } else {
                drawTextOnTarget(StringMaster.wrapInBraces(damage + ""), font, x, y);
            }
        // x += max;
        // direction = direction.rotate45(true); TODO
        // GeometryMaster.getFarthestPointInRectangleForImage(w, h, 40,
        // 32+fontHeight, direction);
        }
    }
}
Also used : DAMAGE_TYPE(main.content.enums.GenericEnums.DAMAGE_TYPE) Damage(eidolons.game.battlecraft.rules.combat.damage.Damage)

Aggregations

DAMAGE_TYPE (main.content.enums.GenericEnums.DAMAGE_TYPE)18 RESIST_GRADE (main.content.enums.GenericEnums.RESIST_GRADE)4 DC_ActiveObj (eidolons.entity.active.DC_ActiveObj)3 Unit (eidolons.entity.obj.unit.Unit)3 PARAMETER (main.content.values.parameters.PARAMETER)3 BattleFieldObject (eidolons.entity.obj.BattleFieldObject)2 Damage (eidolons.game.battlecraft.rules.combat.damage.Damage)2 ValueContainer (eidolons.libgdx.gui.generic.ValueContainer)2 HashMap (java.util.HashMap)2 Ref (main.entity.Ref)2 PARAMS (eidolons.content.PARAMS)1 DC_HeroSlotItem (eidolons.entity.item.DC_HeroSlotItem)1 AttackCalculator (eidolons.game.battlecraft.rules.combat.attack.AttackCalculator)1 MultiValueContainer (eidolons.libgdx.gui.panels.dc.unitinfo.MultiValueContainer)1 ValueTooltip (eidolons.libgdx.gui.tooltips.ValueTooltip)1 PROPERTY (main.content.values.properties.PROPERTY)1 Obj (main.entity.obj.Obj)1 Event (main.game.logic.event.Event)1 EnumMaster (main.system.auxiliary.EnumMaster)1 AnimPhase (main.system.graphics.AnimPhase)1