Skip to content
Blank edited this page Apr 3, 2018 · 16 revisions

CustomCard Constructor

CustomCard(String id, String name, String img, int cost, String rawDescription, CardType type, CardColor color, CardRarity rarity, CardTarget target, int cardPool)

  • id - the card id
  • name - the name of the card
  • img - the path to the img for this card (image path starts at the root of your jar) (250px x 190px); the path to your larger version of the img (500 x 380p) should be img + "_p" so if img is "my_card.png" then the portrait version should be at "my_card_p.png"
  • cost - the energy cost of the card
  • rawDescription - the description for the card
  • type - the card type, e.g. ATTACK, SKILL, POWER
  • color - the color of the card; base game options are RED, GREEN, COLORLESS, CURSE, STATUS however you can use custom colors here too
  • rarity - the card rarity, e.g. COMMON, UNCOMMON, RARE
  • target - the type of target for the card, e.g. does it target ENEMY, ALL_ENEMIES, SELF, etc...
  • cardPool - the card pool (this actually does nothing but the game requires it so just set it to 1)

CustomCardWithRender Constructor

CustomCardWithRender(String id, String name, String img, String bgTexture, String bgTexture_p, int cost, String rawDescription, CardType type, CardColor color, CardRarity rarity, CardTarget target, int cardPool)

  • id - the card id
  • name - the name of the card
  • img - the path to the img for this card (image path starts at the root of your jar) (250px x 190px); the path to your larger version of the img (500 x 380p) should be img + "_p" so if img is "my_card.png" then the portrait version should be at "my_card_p.png"
  • bgTexture - the path to the card frame you want to use
  • bgTexture_p - the path to the card frame you want to use in the card portrait screen (this one is larger)
  • cost - the energy cost of the card
  • rawDescription - the description for the card
  • type - the card type, e.g. ATTACK, SKILL, POWER
  • color - the color of the card; base game options are RED, GREEN, COLORLESS, CURSE, STATUS however you can use custom colors here too
  • rarity - the card rarity, e.g. COMMON, UNCOMMON, RARE
  • target - the type of target for the card, e.g. does it target ENEMY, ALL_ENEMIES, SELF, etc...
  • cardPool - the card pool (this actually does nothing but the game requires it so just set it to 1)

Registering

In order to use the methods below to add or remove cards you must implement EditCardsSubscriber and then override the receiveEditCards method. Inside that method is when you should add or remove cards.

  • BaseMod.addCard(AbstractCard card) (note: CustomCard extends AbstractCard).
  • BaseMod.removeCard(AbstractCard card) removes a card from the game (note: removing a card used by an event is currently untested/undefined behavior)

Example of CustomCard

Let's say you wanted to create a card called Flare that would deal 3 damage to an enemy and apply 1 stack of vulnerable to it unupgraded and would deal 6 damage to the enemy and apply 2 stacks of vulnerable when upgraded.

If the card is going to be RED and have it's art located at img/my_card_img.png in you jar file, the following code would create this card:

import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.powers.VulnerablePower;

import basemod.abstracts.CustomCard;

public class Flare
extends CustomCard {
    public static final String ID = "Flare";
    public static final String NAME = "Flare";
    public static final String DESCRIPTION = "Deal !D! damage. Apply !M! Vulnerable.";
    public static final String IMG_PATH = "img/my_card_img.png";
    private static final int COST = 0;
    private static final int ATTACK_DMG = 3;
    private static final int UPGRADE_PLUS_DMG = 3;
    private static final int VULNERABLE_AMT = 1;
    private static final int UPGRADE_PLUS_VULNERABLE = 1;
    private static final int POOL = 1;

    public Flare() {
        super(ID, NAME, IMG_PATH, COST, DESCRIPTION,
        		AbstractCard.CardType.ATTACK, AbstractCard.CardColor.RED,
        		AbstractCard.CardRarity.UNCOMMON, AbstractCard.CardTarget.ENEMY, POOL);
        this.magicNumber = this.baseMagicNumber = VULNERABLE_AMT;
        this.damage=this.baseDamage = ATTACK_DMG;
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
    	AbstractDungeon.actionManager.addToBottom(new com.megacrit.cardcrawl.actions.common.DamageAction(m,
				new DamageInfo(p, this.damage, this.damageTypeForTurn),
				AbstractGameAction.AttackEffect.SLASH_DIAGONAL));
    	AbstractDungeon.actionManager.addToBottom(new ApplyPowerAction(m, p, new VulnerablePower(m, this.magicNumber, false), this.magicNumber, true, AbstractGameAction.AttackEffect.NONE));
    }

    @Override
    public AbstractCard makeCopy() {
        return new Flare();
    }

    @Override
    public void upgrade() {
        if (!this.upgraded) {
            this.upgradeName();
            this.upgradeDamage(UPGRADE_PLUS_DMG);
            this.upgradeMagicNumber(UPGRADE_PLUS_VULNERABLE);
        }
    }
}

Example of CustomCardWithRender

So for whatever reason you want to create a card that has a different colored frame than the rest of your other cards, but you don't want to create an entirely new card color. Here is an example of a card from BlackMageMod that does exactly that.

package blackmage.cards;

import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.LoseHPAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.monsters.AbstractMonster;

import basemod.abstracts.CustomCardWithRender;
import blackmage.BlackMageMod;
import blackmage.patches.EnumPatch;

public class ShadowStrike extends CustomCardWithRender {
	
	public static final String ID = "ShadowStrike";
	private static final String NAME = "Shadow Strike";
	private static final String IMG = "img/cards/icons/shadowstrike.png";

        //These next two variables are where the card frame path is defined so we can use them in the constructor.
	private static final String BG_IMG = "img/cards/frames/small/shadow_frame.png";
	private static final String BG_IMG_P = "img/cards/frames/portrait/shadow_frame.png";

	private static final String DESCRIPTION = "Deal !D! dark damage.";
	
	private static final AbstractCard.CardType TYPE = AbstractCard.CardType.ATTACK;
	private static final AbstractCard.CardColor COLOR = EnumPatch.BLACK_MAGE;
	private static final AbstractCard.CardRarity RARITY = AbstractCard.CardRarity.COMMON;
	private static final AbstractCard.CardTarget TARGET = AbstractCard.CardTarget.ENEMY;

	private static final int COST = 1;
	private static final int ATK_DMG = 7;
	
	public ShadowStrike() {
                //This is all you need to do in the constructor to have a card with a different frame but the same card color
		super(ID, NAME, IMG, BG_IMG, BG_IMG_P, COST, DESCRIPTION, TYPE, COLOR, RARITY, TARGET, 1);
		this.baseDamage = ATK_DMG;
	}

	@Override
	public AbstractCard makeCopy() {
		return new ShadowStrike();
	}

	@Override
	public void upgrade() {
		if(!this.upgraded) {
			this.upgradeName();
			this.upgradeDamage(3);
		}
	}

	@Override
	public void use(AbstractPlayer p, AbstractMonster m) {
		AbstractDungeon.actionManager.addToBottom(new LoseHPAction(m, p, this.damage, AbstractGameAction.AttackEffect.BLUNT_HEAVY));
	}

}

Note about Inspect View

In the Card Library screen in the Compendium there is an inspect view that brings up a larger version of your card. This is found automatically based off of the original image location by adding a _p to the name. This art should have size 500px x 380px. An example of how the name changes works is img/my_card.png becomes img/my_card_p.png.

Per-Card Energy Cost Orbs

When using CustomCardWithRender you can change the energy cost orb per card. For example if you wanted the orb to turn green when the card is ready to be played, or simply if you want the card to have a special orb because it is super rare.

CustomCardWithRender.setOrbTexture(String orbSmallString, String orbLargeString)

Example of how to use setOrbTexture

This is called in the constructor but it should work outside of the constructor as well.

public SuperRareCard(){
    super(id, name, img, bgTexture, bgTexture_p, cost, rawDescription, type, color, rarity, target, cardPool);

    this.setOrbTexture("img/cards/small/orb-super-rare.png", "img/cards/portrait/orb-super-rare.png");
}
Clone this wiki locally