/// <summary> /// Hides the card thumbnail. /// </summary> public override void Begin() { base.Begin(); BattleScreen = ParentScreen as BattleScreen; Card.LocalPosition = Vector2.Zero; }
public NewGameCommand() : base() { Debug.Assert(ParentScreen is BattleScreen); BattleScreen = ParentScreen as BattleScreen; GameHandleInput = false; }
/// <summary> /// If we mouse over with the left control down we show the ship as a preview. /// If we release the left control it goes back to normal. /// </summary> /// <param name="elapsedGameTime"></param> /// <param name="mousePosition"></param> public override void HandleInput(float elapsedGameTime, Vector2 mousePosition) { base.HandleInput(elapsedGameTime, mousePosition); BattleScreen battleScreen = ScreenManager.Instance.GetCurrentScreenAs <BattleScreen>(); DebugUtils.AssertNotNull(CardShipPair.Ship.Collider); if (!scaled) { if (IsInputValidToPreviewShip(battleScreen, CardShipPair.Ship.Collider)) { CardShipPair.Scale(scale); CardShipPair.LocalPosition = PreviewPosition; ToolTip.Hide(); scaled = true; } } else { if (!GameKeyboard.Instance.IsKeyDown(Keys.LeftControl)) { CardShipPair.Scale(inverseScale); CardShipPair.LocalPosition = CardControlPosition; ToolTip.Show(); scaled = false; } } }
/// <summary> /// A function which returns whether our input is sufficient for us to show the ship preview. /// Returns true if we are in the battle screen, the mouse is over our ship and LeftCtrl is held down. /// Otherwise returns false. /// </summary> /// <param name="battlScreen"></param> /// <param name="colliderToCheck"></param> /// <returns></returns> private bool IsInputValidToPreviewShip(BattleScreen battleScreen, Collider colliderToCheck) { if (battleScreen.TurnState == TurnState.kBattle) { return(colliderToCheck.IsMouseOver && GameKeyboard.Instance.IsKeyDown(Keys.LeftControl)); } return(false); }
/// <summary> /// Creates a reference to the battle screen and sets up our targeting line /// </summary> public override void Begin() { base.Begin(); Debug.Assert(ParentScreen is BattleScreen); BattleScreen = ParentScreen as BattleScreen; SelectingLine = BattleScreen.AddInGameUIObject(new TargetingLine(CardToChooseTargetFor.WorldPosition), true, true); }
/// <summary> /// Set up some event call backs from the main screen /// </summary> public override void Initialise() { CheckShouldInitialise(); BattleScreen battleScreen = ScreenManager.Instance.GetCurrentScreenAs <BattleScreen>(); battleScreen.OnCardPlacementStateStarted += SetUpGameObjectsForCardPlacement; battleScreen.OnBattleStateStarted += SetUpGameObjectsForBattle; battleScreen.OnTurnEnd += GameObjectsOnTurnEnd; base.Initialise(); }
/// <summary> /// For now, just transitions to a new instance of the current screen we are on to simulate restarting. /// Might be more efficient to restart the current screen somehow, but this is much easier. /// </summary> /// <param name="clickedObject"></param> private void ReplayMission(BaseObject clickedObject) { BattleScreen battleScreen = ScreenManager.Instance.GetCurrentScreenAs <BattleScreen>(); DebugUtils.AssertNotNull(battleScreen); BattleScreen newScreen = (BattleScreen)Activator.CreateInstance(battleScreen.GetType(), BattleScreen.Player.DeckInstance.Deck, BattleScreen.Opponent.DeckInstance.Deck); DebugUtils.AssertNotNull(newScreen); battleScreen.Transition(newScreen); }
/// <summary> /// When we lay this card, we do damage all the opponent's ships with defence + speed <= 5 /// </summary> public override void UseAbility(CardObjectPair target) { BattleScreen battleScreen = ScreenManager.Instance.GetCurrentScreenAs <BattleScreen>(); foreach (CardShipPair pair in battleScreen.Board.NonActivePlayerBoardSection.GameBoardSection.ShipCardControl) { // Add up the ship's speed and defence and if it is less than or equal to 5, we do one damage to it if (pair.Ship.ShipData.Defence + pair.Ship.ShipData.Speed <= 5) { pair.Ship.DamageModule.Damage(1, this); SpawnMissileAtTarget(pair.Ship); } } // Kill our parent which will kill us and the object we are paired to too Parent.Die(); }
/// <summary> /// Gets the appropriate text for the turn state button based on the current turn state /// </summary> /// <returns></returns> private string GetTurnStateButtonText() { BattleScreen battleScreen = ScreenManager.Instance.GetCurrentScreenAs <BattleScreen>(); switch (battleScreen.TurnState) { case TurnState.kPlaceCards: return("Start Battle"); case TurnState.kBattle: return("End Turn"); default: Debug.Fail(""); return(""); } }
/// <summary> /// The callback to execute when we choose our deck /// </summary> /// <param name="image"></param> private void ChooseDeckBoxClicked(BaseObject baseObject) { Debug.Assert(baseObject is UIObject); UIObject clickableImage = baseObject as UIObject; DebugUtils.AssertNotNull(clickableImage.StoredObject); Debug.Assert(clickableImage.StoredObject is Deck); // Create our opponent's deck using the cards in our mission data Deck opponentDeck = new Deck(); opponentDeck.Create(MissionData.OpponentDeckData.CardDataAssets); // Find the appropriate type of screen we should transition to based on the mission Type missionScreenType = Assembly.GetExecutingAssembly().GetType("SpaceCardGame." + MissionData.MissionName + "Mission"); DebugUtils.AssertNotNull(missionScreenType); // Transition to the new screen BattleScreen missionScreen = (BattleScreen)Activator.CreateInstance(missionScreenType, clickableImage.StoredObject as Deck, opponentDeck); ScreenManager.Instance.CurrentScreen.Transition(missionScreen); }
/// <summary> /// A function for determining whether the input in our game is sufficient to add the card info image to the screen. /// In the battle screen we have two possibilities: /// In card placement this returns true when our mouse is over the object. /// In battle phase this returns true when the mouse is over the object and LeftShift is held. /// /// In a menu screen, we just check whether the mouse is over the card /// </summary> /// <param name="battleScreen"></param> /// <param name="colliderToCheck"></param> /// <returns></returns> protected override bool IsInputValidToShowToolTip() { DebugUtils.AssertNotNull(AttachedCard.Collider); BattleScreen battleScreen = ScreenManager.Instance.CurrentScreen as BattleScreen; if (battleScreen != null) { // Depending on the turn state, show this UI based on the card or the object's collider if (battleScreen.TurnState == TurnState.kPlaceCards) { return(AttachedCard.Collider.IsMouseOver); } else { DebugUtils.AssertNotNull(AttachedCard.GetCardObjectPair <CardObjectPair>().CardObject.Collider); return(GameKeyboard.Instance.IsKeyDown(Keys.LeftShift) && AttachedCard.GetCardObjectPair <CardObjectPair>().CardObject.Collider.IsMouseOver); } } else { return(AttachedCard.Collider.IsMouseOver); } }
/// <summary> /// Disables our button if we are in the Battle phase and still have unresolved bullets. /// </summary> /// <param name="elapsedGameTime"></param> public override void Update(float elapsedGameTime) { base.Update(elapsedGameTime); // See if we have any explosion animations left to finish in our battle screen // Loop through both player boards and check to see if any turret has unresolved bullets // If one exists, disable this button BattleScreen battleScreen = ScreenManager.Instance.GetCurrentScreenAs <BattleScreen>(); if (battleScreen.FindInGameUIObject <Explosion>(x => x is Explosion) != null) { CanProgress = false; return; } foreach (CardShipPair shipPair in battleScreen.Board.NonActivePlayerBoardSection.GameBoardSection.ShipCardControl) { if (shipPair.Ship.Turret.ChildrenCount > 0) { CanProgress = false; return; } } foreach (CardShipPair shipPair in battleScreen.Board.ActivePlayerBoardSection.GameBoardSection.ShipCardControl) { if (shipPair.Ship.Turret.ChildrenCount > 0) { CanProgress = false; return; } } CanProgress = true; }
/// <summary> /// A callback which adds a card in our hand to the game /// </summary> /// <param name="clickable"></param> public void RunPlaceCardCommand(BaseObject baseObject) { Debug.Assert(baseObject is Card); Card card = baseObject as Card; BattleScreen battleScreen = ScreenManager.Instance.GetCurrentScreenAs <BattleScreen>(); // Only lay our cards during the card placement phase if (battleScreen.TurnState == TurnState.kPlaceCards) { string error = ""; if (card.CanLay(Player, ref error)) { // Make sure the references to the cards in the player's hand are in sync with the actual UI Player.RemoveCardFromHand(card); PlaceCardCommand placeCommand = CommandManager.Instance.AddChild(new PlaceCardCommand(card), true, true); } else { CommandManager.Instance.AddChild(new FlashingTextCommand(error, ScreenManager.Instance.ScreenCentre, Color.White, false, 2), true, true); } } }