private Ship.GenericShip TryToDeclareTarget(Ship.GenericShip targetShip, float distance) { Ship.GenericShip selectedTargetShip = targetShip; if (DebugManager.DebugAI) { Debug.Log("AI checks target for attack: " + targetShip); } if (DebugManager.DebugAI) { Debug.Log("Ship is selected before validation: " + selectedTargetShip); } Selection.TryToChangeAnotherShip("ShipId:" + selectedTargetShip.ShipId); Ship.IShipWeapon chosenWeapon = null; foreach (var upgrade in Selection.ThisShip.UpgradeBar.GetUpgradesOnlyFaceup()) { Ship.IShipWeapon secondaryWeapon = (upgrade as Ship.IShipWeapon); if (secondaryWeapon != null) { if (secondaryWeapon.IsShotAvailable(targetShip)) { chosenWeapon = secondaryWeapon; break; } } } chosenWeapon = chosenWeapon ?? Selection.ThisShip.PrimaryWeapon; Combat.ChosenWeapon = chosenWeapon; Combat.ShotInfo = new Board.ShipShotDistanceInformation(Selection.ThisShip, Selection.AnotherShip, Combat.ChosenWeapon); if (Rules.TargetIsLegalForShot.IsLegal(true) && Combat.ChosenWeapon.IsShotAvailable(Selection.AnotherShip)) { if (DebugManager.DebugAI) { Debug.Log("AI target legal: " + Selection.AnotherShip); } } else { if (DebugManager.DebugAI) { Debug.Log("But validation is not passed: " + selectedTargetShip); } selectedTargetShip = null; } if (DebugManager.DebugAI) { Debug.Log("AI decision about " + targetShip + " : " + selectedTargetShip); } return(selectedTargetShip); }
private static bool IsTargetLegalForAttack() { bool result = false; if (Rules.TargetIsLegalForShot.IsLegal(true) && ChosenWeapon.IsShotAvailable(Selection.AnotherShip)) { result = true; } return(result); }
public static void TryPerformAttack() { Game.UI.HideContextMenu(); MovementTemplates.ReturnRangeRuler(); if (Rules.TargetIsLegalForShot.IsLegal() && ChosenWeapon.IsShotAvailable(Selection.AnotherShip)) { Game.UI.HideSkipButton(); ShotInfo = (ChosenWeapon.GetType() == typeof(Ship.PrimaryWeaponClass)) ? ShotInfo : new ShipShotDistanceInformation(Selection.ThisShip, Selection.AnotherShip, ChosenWeapon); ShotInfo.CheckFirelineCollisions(delegate { PerformAttack(Selection.ThisShip, Selection.AnotherShip); }); } else { if (Roster.GetPlayer(Phases.CurrentPhasePlayer).GetType() == typeof(Players.HumanPlayer)) { // TODO: Better explanations if (!Rules.TargetIsLegalForShot.IsLegal()) { Messages.ShowError("Attack is not legal (this ship cannot attack or target cannot be attacked)"); } else if (!ShotInfo.InShotAngle) { Messages.ShowError("Target is outside your firing arc"); } else if (ShotInfo.Distance > ChosenWeapon.MaxRange || ShotInfo.Distance < ChosenWeapon.MinRange) { Messages.ShowError("Target is outside your firing range"); } //TODO: except non-legal targets, bupmed for example, biggs? Roster.HighlightShipsFiltered(Roster.AnotherPlayer(Phases.CurrentPhasePlayer)); Game.UI.HighlightNextButton(); } else { Selection.ThisShip.IsAttackPerformed = true; Phases.FinishSubPhase(typeof(SubPhases.CombatSubPhase)); } } }