/// <summary> /// Adds a weapon to our ship /// </summary> /// <param name="cardShipPair"></param> public override void AddToCardShipPair(CardShipPair cardShipPair) { // Reparent under the ship card ReparentTo(cardShipPair); // Set up the reference to the CardShipPair CardShipPair = cardShipPair; // Change the size and position of the card so it appears to the top right of the ship card WeaponCard.Size = cardShipPair.Card.Size / 3; LocalPosition = new Vector2((cardShipPair.Card.Size.X + WeaponCard.Size.X) * 0.5f, (3 * WeaponCard.Size.Y - cardShipPair.Card.Size.Y) * 0.5f); // Finally, scale the turret down by the same scaling as the ship float yScale = CardShipPair.CardObject.Size.Y / (2 * CardShipPair.CardObject.TextureCentre.Y); Turret.Scale(yScale); // Do scaling if we are not the default turret if (!Turret.IsDefaultTurret) { float scalingAmount = 2; // If our turret is more than 3 times the size of our ship, we want to scale it down Vector2 potentialScaling = Vector2.Divide(cardShipPair.Card.Size, Turret.Size * scalingAmount); if (potentialScaling.X < 1 || potentialScaling.Y < 1) { // We need to scale the turret down Turret.Size *= (Math.Min(potentialScaling.X, potentialScaling.Y) / scalingAmount); } } // Set up the reference to this turret on the inputted ship cardShipPair.Ship.Turret = Turret; }
/// <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 calculates this ship's attack. /// By default returns the attack in the ship data, but if we have another turret attached, returns that turret's damage /// </summary> /// <returns></returns> public virtual float CalculateAttack(BaseObject targetBaseObject) { CardShipPair cardShipPair = GetCardObjectPair <CardShipPair>(); if (cardShipPair.Ship.Turret.IsDefaultTurret) { return(cardShipPair.Ship.ShipData.Attack); } else { return(cardShipPair.Ship.Turret.BulletData.Damage); } }
/// <summary> /// The callback we call when this ship is damaged. /// The object doing the damaging should be a CardShipPair and we analyse the speed of it against our own to see whether we can nullify some damage. /// </summary> /// <param name="shipDamageModule"></param> /// <param name="objectDoingTheDamage"></param> public override float CalculateDamageDoneToThis(BaseObject objectDoingTheDamage, float inputDamage) { // Some sources of damage may not come from a ship (and indeed could be healing) so we wish to ignore those if (objectDoingTheDamage is CardShipPair) { CardShipPair cardShipPair = GetCardObjectPair <CardShipPair>(); CardShipPair attackingShipPair = objectDoingTheDamage as CardShipPair; if (attackingShipPair.Ship.ShipData.Speed < cardShipPair.Ship.ShipData.Speed) { // We are being damaged by a ship which is slower than us so we can remove one damage inputDamage--; } } return(inputDamage); }
/// <summary> /// Callback for calculating how much damage this ship does. /// We analyse the inputted target and if this ship has higher speed, we deal one extra damage /// </summary> /// <returns></returns> public override float CalculateAttack(BaseObject targetBaseObject) { float baseAttack = base.CalculateAttack(targetBaseObject); CardShipPair cardShipPair = GetCardObjectPair <CardShipPair>(); if (targetBaseObject != null && targetBaseObject is CardShipPair) { CardShipPair targetCardShipPair = targetBaseObject as CardShipPair; if (cardShipPair.Ship.ShipData.Speed > targetCardShipPair.Ship.ShipData.Speed) { // If we have a higher speed, we do more damage baseAttack++; } } return(baseAttack); }
/// <summary> /// Adds a shield to a ship /// </summary> /// <param name="cardShipPair"></param> public override void AddToCardShipPair(CardShipPair cardShipPair) { // Reparent under the ship card ReparentTo(cardShipPair); // Change the size and position of the card so it appears to the top right of the ship card ShieldCard.Size = cardShipPair.Card.Size / 3; LocalPosition = new Vector2((cardShipPair.Card.Size.X + ShieldCard.Size.X) * 0.5f, (ShieldCard.Size.Y - cardShipPair.Card.Size.Y) * 0.5f); // Set up the reference to this shield on the inputted ship cardShipPair.Ship.Shield = Shield; // Set our Shield's position so that it will be centred at the centre of the ship Shield.LocalPosition = cardShipPair.WorldPosition - WorldPosition; // Change our Shield size to wrap around the ship float maxDimension = MathHelper.Max(cardShipPair.Ship.Size.X, cardShipPair.Ship.Size.Y); float maxPadding = MathHelper.Max(30, 0.85f * maxDimension); // Either add an absolute or relative amount depending on which is bigger (first for small ships, second for large ships) Shield.Size = new Vector2(maxPadding + maxDimension); // Add a little extra padding for safety }
/// <summary> /// If the ship is selected and ready, we trigger a script to handle the attacking of other ships /// </summary> /// <param name="elapsedGameTime"></param> /// <param name="mousePosition"></param> public override void HandleInput(float elapsedGameTime, Vector2 mousePosition) { base.HandleInput(elapsedGameTime, mousePosition); CardShipPair cardShipPair = GetCardObjectPair <CardShipPair>(); DebugUtils.AssertNotNull(Collider); // Check to see that the player who is interacting is the owner of this card bool isOwningPlayersTurn = cardShipPair.Card.Player == ScreenManager.Instance.GetCurrentScreenAs <BattleScreen>().ActivePlayer; if (isOwningPlayersTurn && Collider.IsClicked && Turret.CanFire && cardShipPair.IsReady) { DebugUtils.AssertNotNull(Parent); Debug.Assert(Parent is CardShipPair); CommandManager.Instance.AddChild(new AttackOpponentShipCommand(Parent as CardShipPair), true, true); } // Updates the colour of the ship if our mouse is over it // Green if we can attack - red if we cannot Color hoverColour = (Turret.CanFire && cardShipPair.IsReady) ? Color.LightGreen : Color.Red; Parent.Colour = Collider.IsMouseOver ? hoverColour : Color.White; }
/// <summary> /// Pass in the card ship 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="cardShipPair"></param> public ShipCardHoverInfoModule(CardShipPair cardShipPair) : base(cardShipPair) { CardShipPair = cardShipPair; }
/// <summary> /// Adds an ability to our ship /// </summary> /// <param name="cardShipPair"></param> public override void AddToCardShipPair(CardShipPair cardShipPair) { Debug.Fail("Empty"); }
/// <summary> /// A function which returns whether the card we are looking to use can be used on the current target /// </summary> /// <param name="cardToChooseTargetFor"></param> /// <param name="currentTarget"></param> /// <returns></returns> private bool ValidIfCanUseOn(CardShipPair currentTarget) { return(CardToChooseTargetFor.CanUseOn(currentTarget)); }
/// <summary> /// A function called when this card is added to a card ship pair. /// This occurs with abilities, weapons etc. /// Allows us to apply custom effects based on the card type. /// </summary> /// <param name="cardShipPair"></param> public abstract void AddToCardShipPair(CardShipPair cardShipPair);
public AttackOpponentShipCommand(CardShipPair attackingShipPair) : base(attackingShipPair.ShipCard) { AttackingShipCardPair = attackingShipPair; ValidTargetFunction += IsShipDamageModuleAlive; // All the alive opponent ships will be valid }
/// <summary> /// Returns true if the ship's damage module is alive and false if it is Dead /// </summary> /// <param name="cardToChooseTargetFor"></param> /// <param name="currentTarget"></param> /// <returns></returns> protected bool IsShipDamageModuleAlive(CardShipPair currentTarget) { return(!currentTarget.Ship.DamageModule.Dead); }
/// <summary> /// Cannot add ships to other ships /// </summary> /// <param name="cardShipPair"></param> public override void AddToCardShipPair(CardShipPair cardShipPair) { Debug.Fail("Cannot add ships to other ships"); }
public ShipInfoImage(CardShipPair cardShipPair, Vector2 size, Vector2 localPosition) : base(size, localPosition, cardShipPair.Card.TextureAsset) { CardShipPair = cardShipPair; }
/// <summary> /// Cannot add a resource to a ship /// </summary> /// <param name="cardShipPair"></param> public override void AddToCardShipPair(CardShipPair cardShipPair) { Debug.Fail("Cannot add a resource to a ship"); }
/// <summary> /// Always returns true no matter the target /// </summary> /// <param name="cardToChooseTargetFor"></param> /// <param name="currentTarget"></param> /// <returns></returns> protected bool AlwaysValid(CardShipPair currentTarget) { return(true); }