public static ToHitData toHit(Game game, int attackerId, Targetable target, int arm) { final Entity ae = game.getEntity(attackerId); int targetId = Entity.NONE; Entity te = null; if ( target.getTargetType() == Targetable.TYPE_ENTITY ) { te = (Entity) target; targetId = target.getTargetId(); } final int armLoc = (arm == BrushOffAttackAction.RIGHT) ? Mech.LOC_RARM : Mech.LOC_LARM; ToHitData toHit;   if (!(ae instanceof Mech)) { return new ToHitData(ToHitData.IMPOSSIBLE, "Only mechs can brush off swarming infantry"); }   if ( arm != BrushOffAttackAction.RIGHT && arm != BrushOffAttackAction.LEFT ) { throw new IllegalArgumentException("Arm must be LEFT or RIGHT"); } if (ae == null || target == null) { throw new IllegalArgumentException("Attacker or target not valid"); } if ( targetId != ae.getSwarmAttackerId() || te == null || !(te instanceof Infantry) ) { return new ToHitData(ToHitData.IMPOSSIBLE, "Can only brush off swarming infantry" ); }   if ( ae.entityIsQuad() ) { return new ToHitData(ToHitData.IMPOSSIBLE, "Attacker is a quad"); }   if (ae.getArmsFlipped()) { return new ToHitData(ToHitData.IMPOSSIBLE, "Arms are flipped to the rear. Can not punch."); }   if (ae.isLocationBad(armLoc)) { return new ToHitData(ToHitData.IMPOSSIBLE, "Arm missing"); }   if (!ae.hasWorkingSystem(Mech.ACTUATOR_SHOULDER, armLoc)) { return new ToHitData(ToHitData.IMPOSSIBLE, "Shoulder destroyed"); }   if (ae.weaponFiredFrom(armLoc)) { return new ToHitData(ToHitData.IMPOSSIBLE, "Weapons fired from arm this turn"); }   if ( te != null && te.isMakingDfa() ) { return new ToHitData(ToHitData.IMPOSSIBLE, "Target is making a DFA attack"); }   if (ae.isProne()) { return new ToHitData(ToHitData.IMPOSSIBLE, "Attacker is prone"); }   if ( target.getTargetType() == Targetable.TYPE_BUILDING || target.getTargetType() == Targetable.TYPE_BLDG_IGNITE || target.getTargetType() == Targetable.TYPE_HEX_CLEAR || target.getTargetType() == Targetable.TYPE_HEX_IGNITE ) { return new ToHitData( ToHitData.IMPOSSIBLE, "Invalid attack"); }   toHit = new ToHitData(ae.getCrew().getPiloting(), "base PSR"); toHit.addModifier( 4, "brush off swarming infantry" );   if (!ae.hasWorkingSystem(Mech.ACTUATOR_UPPER_ARM, armLoc)) { toHit.addModifier(2, "Upper arm actuator destroyed"); } if (!ae.hasWorkingSystem(Mech.ACTUATOR_LOWER_ARM, armLoc)) { toHit.addModifier(2, "Lower arm actuator missing or destroyed"); } if (!ae.hasWorkingSystem(Mech.ACTUATOR_HAND, armLoc)) { toHit.addModifier(1, "Hand actuator missing or destroyed"); }  Compute.modifyPhysicalBTHForAdvantages(ae, te, toHit, game);    for ( Enumeration iter = te.getMisc(); iter.hasMoreElements(); ) { Mounted mount = (Mounted) iter.nextElement(); EquipmentType equip = mount.getType(); if ( BattleArmor.ASSAULT_CLAW.equals (equip.getInternalName()) ) { toHit.addModifier( 1, "defender has assault claws" ); break; } }   return toHit;
public ToHitData toHit(Game game) { return toHit(game, getEntityId(), game.getTarget(getTargetType(), getTargetId()), getArm());
    public static ToHitData toHit(Game game, int attackerId, Targetable target, int arm) {		final Entity ae = game.getEntity(attackerId);		int targetId = Entity.NONE;		Entity te = null;		if ( target.getTargetType() == Targetable.TYPE_ENTITY ) {			te = (Entity) target;			targetId = target.getTargetId();		}		final int armLoc = (arm == BrushOffAttackAction.RIGHT)						   ? Mech.LOC_RARM : Mech.LOC_LARM;		ToHitData toHit;		// non-mechs can't BrushOff		if (!(ae instanceof Mech)) {			return new ToHitData(ToHitData.IMPOSSIBLE,								 "Only mechs can brush off swarming infantry");		}		// arguments legal?		if ( arm != BrushOffAttackAction.RIGHT &&			 arm != BrushOffAttackAction.LEFT ) {			throw new IllegalArgumentException("Arm must be LEFT or RIGHT");		}		if (ae == null || target == null) {			throw new IllegalArgumentException("Attacker or target not valid");		}		if ( targetId != ae.getSwarmAttackerId() ||			 te == null || !(te instanceof Infantry) ) {			return new ToHitData(ToHitData.IMPOSSIBLE,								 "Can only brush off swarming infantry" );		}		// Quads can't brush off.		if ( ae.entityIsQuad() ) {			return new ToHitData(ToHitData.IMPOSSIBLE, "Attacker is a quad");		}		// Can't brush off with flipped arms		if (ae.getArmsFlipped()) {			return new ToHitData(ToHitData.IMPOSSIBLE, "Arms are flipped to the rear. Can not punch.");		}		// check if arm is present		if (ae.isLocationBad(armLoc)) {			return new ToHitData(ToHitData.IMPOSSIBLE, "Arm missing");		}		// check if shoulder is functional		if (!ae.hasWorkingSystem(Mech.ACTUATOR_SHOULDER, armLoc)) {			return new ToHitData(ToHitData.IMPOSSIBLE, "Shoulder destroyed");		}		// check if attacker has fired arm-mounted weapons		if (ae.weaponFiredFrom(armLoc)) {			return new ToHitData(ToHitData.IMPOSSIBLE, "Weapons fired from arm this turn");		}		// can't physically attack mechs making dfa attacks		if ( te != null && te.isMakingDfa() ) {			return new ToHitData(ToHitData.IMPOSSIBLE, "Target is making a DFA attack");		}		// Can't brush off while prone.		if (ae.isProne()) {			return new ToHitData(ToHitData.IMPOSSIBLE, "Attacker is prone");		}		// Can't target woods or a building with a brush off attack.		if ( target.getTargetType() == Targetable.TYPE_BUILDING ||			 target.getTargetType() == Targetable.TYPE_BLDG_IGNITE ||			 target.getTargetType() == Targetable.TYPE_HEX_CLEAR ||			 target.getTargetType() == Targetable.TYPE_HEX_IGNITE ) {			return new ToHitData( ToHitData.IMPOSSIBLE, "Invalid attack");		}		// okay, modifiers...		toHit = new ToHitData(ae.getCrew().getPiloting(), "base PSR");		toHit.addModifier( 4, "brush off swarming infantry" );		// damaged or missing actuators		if (!ae.hasWorkingSystem(Mech.ACTUATOR_UPPER_ARM, armLoc)) {			toHit.addModifier(2, "Upper arm actuator destroyed");		}		if (!ae.hasWorkingSystem(Mech.ACTUATOR_LOWER_ARM, armLoc)) {			toHit.addModifier(2, "Lower arm actuator missing or destroyed");		}		if (!ae.hasWorkingSystem(Mech.ACTUATOR_HAND, armLoc)) {			toHit.addModifier(1, "Hand actuator missing or destroyed");		}		Compute.modifyPhysicalBTHForAdvantages(ae, te, toHit, game);		// If the target has Assault claws, give a 1 modifier.		// We can stop looking when we find our first match.		for ( Enumeration iter = te.getMisc(); iter.hasMoreElements(); ) {			Mounted mount = (Mounted) iter.nextElement();			EquipmentType equip = mount.getType();			if ( BattleArmor.ASSAULT_CLAW.equals				 (equip.getInternalName()) ) {				toHit.addModifier( 1, "defender has assault claws" );				break;			}		}		// done!		return toHit;    }