Skip to content
Davis Cook edited this page Feb 25, 2018 · 19 revisions

Constructor

AbstractPlayer(String name, AbstractPlayer.PlayerClass chosenClass)

  • name - the character id
  • chosenClass - the chosen class for the player

For an example of what must be done in the constructor take a look in the example section down below.

Enums

The base game denotes character options using the AbstractPlayer.PlayerClass enum so in order to add a new color to the game you must patch the enum using ModTheSpire's enum patching feature in addition to registering it with BaseMod. Here is an example of how to do so:

import com.evacipated.cardcrawl.modthespire.lib.SpireEnum;
import com.megacrit.cardcrawl.characters.AbstractPlayer;

public class MyPlayerClassEnum {

	@SpireEnum
	public static AbstractPlayer.PlayerClass MY_PLAYER_CLASS;
	
	
}

API

addCharacter(Class characterClass, String titleString, String classString, String color, String selectText, String selectButton, String portrait, String characterID)

  • characterClass - the actual Class for your character (instance of java.lang.Class) (obtainable by MyCharacter.class)
  • titleString - the name of your character, e.g. My Character
  • classString - honest I don't know what this one is used for so do anything non-null here
  • color - the name of the custom color for this character, e.g. MY_CUSTOM_COLOR.toString() where MY_CUSTOM_COLOR is the enum value for this character's color
  • selectText - the description that shows up on the character select screen
  • selectButton - the path to the select button texture (starting at the root of your jar)
  • portrait - the path to your character select portrait texture (starting at the root of your jar) (size: 1920px x 1200px)
  • characterID - should be MY_PLAYER_CLASS.toString() where MY_PLAYER_CLASS is the enum value for this character's class

Example

Too add the custom player you must do two steps - define the custom player and register it with BaseMod.

Define a Custom Player

import java.util.ArrayList;

import com.badlogic.gdx.math.MathUtils;
import com.esotericsoftware.spine.AnimationState;
import com.megacrit.cardcrawl.actions.utility.ExhaustAllEtherealAction;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.EnergyManager;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.powers.AbstractPower;
import com.megacrit.cardcrawl.screens.CharSelectInfo;
import com.megacrit.cardcrawl.unlock.UnlockTracker;

public class MyCharacter extends AbstractPlayer {
	public static final int ENERGY_PER_TURN = 3;
	public static final String MY_CHARACTER_SHOULDER_2 = "img/char/shoulder2.png";
        public static final String MY_CHARACTER_SHOULDER_1 = "img/char/shoulder1.png";
	public static final String MY_CHARACTER_CORPSE = "img/char/corpse.png";
        public static final String MY_CHARACTER_SKELETON_ATLAS = "img/char/skeleton.atlas";
        public static final String MY_CHARACTER_SKELETON_JSON = "img/char/skeleton.json";

	public MyCharacter (String name, PlayerClass chonseClass) {
		super(name, setClass);
		
		this.dialogX = (this.drawX + 0.0F * Settings.scale);
		this.dialogY = (this.drawY + 220.0F * Settings.scale);
		
		initializeClass(null, MY_CHARACTER_SHOULDER_2,
				MY_CHARACTER_SHOULDER_1,
				MY_CHARACTER_CORPSE, 
				getLoadout(), 20.0F, -10.0F, 220.0F, 290.0F, new EnergyManager(ENERGY_PER_TURN));
		
		loadAnimation(MY_CHARACTER_SKELETON_ATLAS, MY_CHARCTER_SKELETON_JSON, 1.0F);
		
		AnimationState.TrackEntry e = this.state.setAnimation(0, "animation", true);
		e.setTime(e.getEndTime() * MathUtils.random());
	}

	public static ArrayList<String> getStartingDeck() {
		ArrayList<String> retVal = new ArrayList<>();
		retVal.add("MyCard0");
		retVal.add("MyCard0");
		retVal.add("MyCard0");
		retVal.add("MyCard0");
		retVal.add("MyCard1");
		retVal.add("MyCard1");
		retVal.add("MyCard1");
		retVal.add("MyCard1");
		retVal.add("MyCard2");
		return retVal;
	}
	
	public static ArrayList<String> getStartingRelics() {
		ArrayList<String> retVal = new ArrayList<>();
		retVal.add("MyRelic");
		UnlockTracker.markRelicAsSeen("MyRelic");
		return retVal;
	}
	
        public static final int STARTING_HP = 75;
        public static final int MAX_HP = 75;
        public static final int STARTING_GOLD = 99;
        public static final int HAND_SIZE = 5;

	public static CharSelectInfo getLoadout() {
		return new CharSelectInfo("My Character", "My character is a person from the outer worlds. He makes magic stuff happen.",
				STARTING_HP, MAX_HP, STARTING_GOLD, HAND_SIZE,
			MyPlayerClassEnum.MY_PLAYER_CLASS, getStartingRelics(), getStartingDeck(), false);
	}
	
}

Add to BaseMod

Note that for this to work your mod must add the necessary custom color for the character like the wiki page on custom colors says.

@SpireInitializer
public class MyMod implements EditCharactersSubscriber {
	
        public MyMod() {
                BaseMod.subscribeToEditCharacters(this);
        }

        public static void initialize() {
                MyMod mod = new MyMod();
        }

        @Override
	public void receiveEditCharacters() {
		logger.info("begin editting characters");
		
		logger.info("add " + MyPlayerClassEnum.MY_PLAYER_CLASS.toString());
		BaseMod.addCharacter(MyCharcter.class, "My Character", "character class string",
				AbstractCardEnum.MY_CUSTOM_COLOR.toString(), "My Character",
				MY_CHARACTER_BUTTON , MY_CHARACTER_PORTRAIT,
				MyPlayerClassEnum.MY_PLAYER_CLASS.toString());
		
		logger.info("done editting characters");
	}

}
Clone this wiki locally