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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations