Talk

Kraken Attack

From Shadow Era Wiki

Here's an explanation of the Shadow Era card code for Kraken Attack:
Detailed explanation is below the code.


FILE REFERENCE
KEY FUNCTIONS

rr155.cs:
Includes the logic for handling specific cards and abilities, such as

  • `OnCast()`,
  • `CanCast()`,
  • `StartTargeting()`,
  • `GetTargets()`,
  • `IsValidTarget()`, and
  • `NumberOfTargets()`.
  • `Init`: Initializes card properties.
  • `NumberOfTargets`: Returns the number of targets.
  • `IsValidTarget`: Determines if a card is a valid target.
  • `GetTargets`: Retrieves a list of valid targets.
  • `CanCast`: Checks if the card can be cast.
  • `OnCast`: Executes the card's effect.
  • `StartTargeting`: Prepares for targeting.
DETAILED CODE
using System.Collections.Generic;
 
public class rr155 : SpecificCard
{
	public override void Init()
	{
		parent.cardName = "Kraken Attack";
		parent.rarity = RarityEnum.Common;
		parent.usableBy = UsableBy.Neutral;
		parent.cardType = CardTypeEnum.Ability;
		parent.castCost = 2;
	}
 
	public override int NumberOfTargets()
	{
		return 1;
	}
 
	private bool IsValidTarget(ShadowEraCard check)
	{
		if (!check.CanBeTargetedBy(parent) || check.cardType != CardTypeEnum.Item)
		{
			return false;
		}
		if (check.cardSubType == CardSubTypeEnum.Ship)
		{
			return true;
		}
		if (check.cardSubType == CardSubTypeEnum.Trap)
		{
			return false;
		}
		return check.castCost <= 2;
	}
 
	public override List<ShadowEraCard> GetTargets()
	{
		List<ShadowEraCard> list = new List<ShadowEraCard>();
		for (int i = 0; i < GameModel.ItemsCount(); i++)
		{
			ShadowEraCard item = GameModel.GetItem(i);
			if (IsValidTarget(item))
			{
				list.Add(item);
			}
		}
		for (int j = 0; j < GameModel.EnemyItemsCount(); j++)
		{
			ShadowEraCard enemyItem = GameModel.GetEnemyItem(j);
			if (IsValidTarget(enemyItem))
			{
				list.Add(enemyItem);
			}
		}
		return list;
	}
 
	public override bool CanCast()
	{
		return GetTargets().Count > 0;
	}
 
	public override void OnCast()
	{
		if (targets.Count > 0)
		{
			ShadowEraCard shadowEraCard = targets[0];
			if (GameModel.CheckCanItemBeDestroyed(shadowEraCard))
			{
				if (shadowEraCard.cardSubType == CardSubTypeEnum.Ship)
				{
					int num = 999;
					ShadowEraCard shadowEraCard2 = null;
					for (int i = 0; i < shadowEraCard.attachedCards.Count; i++)
					{
						ShadowEraCard shadowEraCard3 = shadowEraCard.attachedCards[i];
						if (shadowEraCard3.originalCardType == CardTypeEnum.Ally && shadowEraCard3.castCost < num)
						{
							shadowEraCard2 = shadowEraCard3;
							num = shadowEraCard3.castCost;
						}
					}
					if (shadowEraCard2 != null)
					{
						GameModel.Exile(shadowEraCard2);
					}
					int num2 = -1;
					ShadowEraCard shadowEraCard4 = null;
					for (int j = 0; j < shadowEraCard.attachedCards.Count; j++)
					{
						ShadowEraCard shadowEraCard5 = shadowEraCard.attachedCards[j];
						if (shadowEraCard5.originalCardType == CardTypeEnum.Ally && shadowEraCard5.castCost > num2)
						{
							shadowEraCard4 = shadowEraCard5;
							num2 = shadowEraCard5.castCost;
						}
					}
					if (shadowEraCard4 != null)
					{
						GameModel.Exile(shadowEraCard4);
					}
				}
				shadowEraCard.DestroyCard();
			}
		}
		targets.Clear();
		MoveCastCardToGraveyard();
	}
 
	public override void StartTargeting()
	{
		targets.Clear();
		MoveToCastPosition();
		MoveCameraToEnemy();
	}
}

Detailed explanation


Init Method:

  • This method initializes the card with its properties:
    1. `parent.cardName`: Sets the card's name to "Kraken Attack."
    2. `parent.rarity`: Sets the card's rarity to Common.
    3. `parent.usableBy`: Defines that the card can be used by Neutral factions.
    4. `parent.cardType`: Specifies the card type as Ability.
    5. `parent.castCost`: Sets the cost to cast the card as 2.


NumberOfTargets Method:

  • Returns the number of targets that this card can select, which is 1.


IsValidTarget Method:

  • Checks if a given card (`ShadowEraCard` check) is a valid target:
    1. The card must be targetable by this card (`check.CanBeTargetedBy(parent)`).
    2. The card type must be Item.
    3. If the card subtype is Ship, it is valid.
    4. If the card subtype is Trap, it is invalid.
    5. The card's casting cost must be less than or equal to 2.


GetTargets Method:

  • Retrieves a list of valid target cards:
    1. Iterates over all items in the game (`GameModel.ItemsCount()` and `GameModel.GetItem(i)`).
    2. Adds items that are valid targets to the list.
    3. Also checks enemy items (`GameModel.EnemyItemsCount()` and `GameModel.GetEnemyItem(j)`).
    4. Adds valid enemy items to the list.
    5. Returns the list of valid targets.


CanCast Method:

  • Determines if the card can be cast by checking if there are any valid targets available (`GetTargets().Count > 0`).


OnCast Method:

  • Executes the card's effect:
    1. If there are targets, it processes the first target (`targets[0]`).
    2. Checks if the target can be destroyed (`GameModel.CheckCanItemBeDestroyed(shadowEraCard)`).
    3. If the target's subtype is Ship:
      1. Finds the attached ally card with the lowest cost and exiles it (`GameModel.Exile(shadowEraCard2)`).
      2. Finds the attached ally card with the highest cost and exiles it (`GameModel.Exile(shadowEraCard4)`).
    1. Destroys the target card (`shadowEraCard.DestroyCard()`).
    2. Clears the list of targets and moves the cast card to the graveyard (`MoveCastCardToGraveyard()`).


StartTargeting Method:

  • Prepares for targeting:
    1. Clears the list of targets (`targets.Clear()`).
    2. Moves the card to the casting position (`MoveToCastPosition()`).
    3. Moves the camera to focus on the enemy (`MoveCameraToEnemy()`).