Skip to content

Commit

Permalink
Further refactor new Quirk and SPA processors for safety
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleet01 committed Sep 18, 2023
1 parent cdabe37 commit 44348b6
Showing 1 changed file with 46 additions and 28 deletions.
74 changes: 46 additions & 28 deletions megamek/src/megamek/common/actions/WeaponAttackAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -3076,7 +3076,7 @@ private static ToHitData compileWeaponToHitMods(Game game, Entity ae, Entity spo

// VSP Lasers

// Quirks
// Quirks and SPAs now handled in toHit
processAttackerQuirks(toHit, ae, target, weapon);

// SPAs
Expand Down Expand Up @@ -4278,14 +4278,12 @@ else if ((atype != null)
}
}

// blood stalker SPA
if (ae.getBloodStalkerTarget() > Entity.NONE) {
if (ae.getBloodStalkerTarget() == target.getId()) {
toHit.addModifier(-1, Messages.getString("WeaponAttackAction.BloodStalkerTarget"));
} else {
toHit.addModifier(+2, Messages.getString("WeaponAttackAction.BloodStalkerNonTarget"));
}
}
// Quirks
processAttackerQuirks(toHit, ae, te, weapon);

// SPAs
processAttackerSPAs(toHit, ae, te, weapon, game);
processDefenderSPAs(toHit, ae, te, weapon, game);

return toHit;
}
Expand Down Expand Up @@ -4873,6 +4871,14 @@ private static ToHitData artilleryDirectToHit(Game game, Entity ae, Targetable t
// Per TO:AR 6th printing, p153, other mods are: Flak (-2), AMM, damage, intervening trees/jungle
int distance = Compute.effectiveDistance(game, ae, target);
toHit = new ToHitData(ae.getCrew().getGunnery(), Messages.getString("WeaponAttackAction.GunSkill"));

// Quirks
processAttackerQuirks(toHit, ae, te, weapon);

// SPAs
processAttackerSPAs(toHit, ae, te, weapon, game);
processDefenderSPAs(toHit, ae, te, weapon, game);

// Flak; ADA won't hit the later artillery flak check so add this modifier directly.
toHit.addModifier(-2, Messages.getString("WeaponAttackAction.Flak"));
// AMM
Expand Down Expand Up @@ -5086,31 +5092,43 @@ public static ToHitData processAttackerQuirks(ToHitData toHit, Entity ae, Target
toHit.addModifier(+1, Messages.getString("WeaponAttackAction.SensorGhosts"));
}

// Flat -1 for Accurate Weapon
if (weapon.hasQuirk(OptionsConstants.QUIRK_WEAP_POS_ACCURATE)) {
toHit.addModifier(-1, Messages.getString("WeaponAttackAction.AccWeapon"));
}
// Flat +1 for Inaccurate Weapon
if (weapon.hasQuirk(OptionsConstants.QUIRK_WEAP_NEG_INACCURATE)) {
toHit.addModifier(+1, Messages.getString("WeaponAttackAction.InAccWeapon"));
}
// Stable Weapon - Reduces running/flanking penalty by 1
if (weapon.hasQuirk(OptionsConstants.QUIRK_WEAP_POS_STABLE_WEAPON) && (ae.moved == EntityMovementType.MOVE_RUN)) {
toHit.addModifier(-1, Messages.getString("WeaponAttackAction.StableWeapon"));
}
// +1 for a Misrepaired Weapon - See StratOps Partial Repairs
if (weapon.hasQuirk(OptionsConstants.QUIRK_WEAP_NEG_MISREPAIRED)) {
toHit.addModifier(+1, Messages.getString("WeaponAttackAction.MisrepairedWeapon"));
}
// +1 for a Misreplaced Weapon - See StratOps Partial Repairs
if (weapon.hasQuirk(OptionsConstants.QUIRK_WEAP_NEG_MISREPLACED)) {
toHit.addModifier(+1, Messages.getString("WeaponAttackAction.MisreplacedWeapon"));
if (null != weapon) {

// Flat -1 for Accurate Weapon
if (weapon.hasQuirk(OptionsConstants.QUIRK_WEAP_POS_ACCURATE)) {
toHit.addModifier(-1, Messages.getString("WeaponAttackAction.AccWeapon"));
}
// Flat +1 for Inaccurate Weapon
if (weapon.hasQuirk(OptionsConstants.QUIRK_WEAP_NEG_INACCURATE)) {
toHit.addModifier(+1, Messages.getString("WeaponAttackAction.InAccWeapon"));
}
// Stable Weapon - Reduces running/flanking penalty by 1
if (weapon.hasQuirk(OptionsConstants.QUIRK_WEAP_POS_STABLE_WEAPON) && (ae.moved == EntityMovementType.MOVE_RUN)) {
toHit.addModifier(-1, Messages.getString("WeaponAttackAction.StableWeapon"));
}
// +1 for a Misrepaired Weapon - See StratOps Partial Repairs
if (weapon.hasQuirk(OptionsConstants.QUIRK_WEAP_NEG_MISREPAIRED)) {
toHit.addModifier(+1, Messages.getString("WeaponAttackAction.MisrepairedWeapon"));
}
// +1 for a Misreplaced Weapon - See StratOps Partial Repairs
if (weapon.hasQuirk(OptionsConstants.QUIRK_WEAP_NEG_MISREPLACED)) {
toHit.addModifier(+1, Messages.getString("WeaponAttackAction.MisreplacedWeapon"));
}
}
return toHit;
}

public static ToHitData processAttackerSPAs(ToHitData toHit, Entity ae, Targetable target, Mounted weapon, Game game){

// blood stalker SPA
if (ae.getBloodStalkerTarget() > Entity.NONE) {
if (ae.getBloodStalkerTarget() == target.getId()) {
toHit.addModifier(-1, Messages.getString("WeaponAttackAction.BloodStalkerTarget"));
} else {
toHit.addModifier(+2, Messages.getString("WeaponAttackAction.BloodStalkerNonTarget"));
}
}

WeaponType wtype = ((weapon != null) && (weapon.getType() instanceof WeaponType)) ? (WeaponType) weapon.getType() : null;

if (wtype != null) {
Expand Down

0 comments on commit 44348b6

Please sign in to comment.