Example #1
0
        /// <summary>
        /// Defence cards can only be targetted on ships, so we just check that we have a CardShipPair which is not dead
        /// </summary>
        /// <param name="pairToValidate"></param>
        /// <returns></returns>
        public override bool CanUseOn(CardObjectPair pairToValidate)
        {
            if (pairToValidate is CardShipPair)
            {
                // If we are targeting a ship, it is valid if it is not dead
                return(!(pairToValidate as CardShipPair).Ship.DamageModule.Dead);
            }

            // Otherwise the target is invalid
            return(false);
        }
        /// <summary>
        /// A function called right at the start of the game to add our player's station to this control.
        /// We load and initialise the station too and handle all parenting problems.
        /// We have a separate function, because the station is a special card and we do no want it to go through the same pipeline as the normal CardShipPairs (i.e. AddChild)
        /// </summary>
        /// <param name="stationCardPair"></param>
        public void AddStation(CardObjectPair stationCardPair)
        {
            Debug.Assert(stationCardPair is CardStationPair);

            // Do a shallow reparent - we do not want to go through AddChild because it will do unnecessary things to this station
            // Instead we have to manually do a bit of hacking
            bool dontWantToBeAddedViaAddChild = false;
            stationCardPair.ReparentTo(this, dontWantToBeAddedViaAddChild);       // This does set up our new parent however
            Children.AddChild(stationCardPair, true, true);

            stationCardPair.LocalPosition = StationPosition;
        }
        /// <summary>
        /// Adds our card to the section, but calls functions on the CardObjectPair to perform extra setup.
        /// Also charges the resources to the player.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="gameObjectToAdd"></param>
        /// <param name="load"></param>
        /// <param name="initialise"></param>
        /// <returns></returns>
        public CardObjectPair AddCard(Card card, Vector2 desiredWorldPosition, bool load = true, bool initialise = true)
        {
            // Once we have clicked this card for placement, do not want this event to run any more
            card.ClickableModule.OnLeftClicked -= BattleScreen.Board.ActivePlayerBoardSection.UIBoardSection.HandUI.RunPlaceCardCommand;

            CardObjectPair pair = AddChild(card.CreateCardObjectPair(), load, initialise);

            pair.LocalPosition = desiredWorldPosition - WorldPosition;

            // Deduct the resources
            pair.WhenAddedToGameBoard(this);
            BattleScreen.Board.ActivePlayerBoardSection.UIBoardSection.HandUI.NeedsRebuild = true;

            return(pair);
        }
        /// <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>
        /// Set up the reference to the battle screen and add the card outlines for the ships.
        /// </summary>
        public override void Begin()
        {
            base.Begin();

            BattleScreen = ScreenManager.Instance.GetCurrentScreenAs <BattleScreen>();

            ShipCard       stationCard = Player.GetStationData();
            CardObjectPair stationPair = AddCard(stationCard, WorldPosition, false, false);

            CardOutlines = new CardOutline[ShipCardControl.LocalXPositions.Length];
            for (int i = 0; i < ShipCardControl.LocalXPositions.Length; ++i)
            {
                CardOutlines[i]       = AddChild(new CardOutline(stationPair.Card.Size, ShipCardControl.LocalPosition + new Vector2(ShipCardControl.LocalXPositions[i], 0)), true, true);
                CardOutlines[i].Valid = false;
            }

            BattleScreen.OnCardPlacementStateStarted += ToggleCardOutlines;
            BattleScreen.OnBattleStateStarted        += ToggleCardOutlines;
        }
Example #6
0
 /// <summary>
 /// Pass in the card object pair here because the attached object will not be set in the constructor.
 /// Also provides a way of limiting what objects can use this module.
 /// </summary>
 /// <param name="cardObjectPair"></param>
 public CardHoverInfoModule(CardObjectPair cardObjectPair) :
     this(cardObjectPair.Card)
 {
 }
Example #7
0
 /// <summary>
 /// Override this to perform the actual implementation for the ability
 /// </summary>
 /// <param name="target"></param>
 public virtual void UseAbility(CardObjectPair target)
 {
 }
Example #8
0
 /// <summary>
 /// Some cards require us to choose a target before laying them, or for an ability.
 /// This is a virtual function which can be used to work out whether the inputted proposed target is a valid one for this card.
 /// </summary>
 /// <param name="pair"></param>
 /// <returns></returns>
 public virtual bool CanUseOn(CardObjectPair pairToValidate)
 {
     return(true);
 }