Custom Relic Effects - brandonandzeus/Trainworks2 GitHub Wiki

Custom Relic Effects.

Writing a RelicEffect is a mix of writing a RoomModifier and CardEffect concepts from both are used. To start RelicEffects are a subclass of RelicEffectBase like RoomModifiers just subclassing RelicEffectBase isn't enough. In addition, implementing any of the subinterfaces of IRelicEffect determines when your RelicEffect's effect is called. Much like in the CardEffect tutorial, be mindful that if you intend to mutate the state of anything other than a CharacterState, it should not be done in preview mode.

Steps to make a custom relic effect.

  1. Create a class inheriting from RelicEffectBase
  2. Implement one or more of the IRelicEffect sub-interfaces. This determines when your Relic Effect is triggered. You can implement as many as you want.

RelicEffectDrawCardPerEmber

A Simple relic effect that gives you extra cards next turn if you did not use all of your ember.

    // Implement IEndTurnPreHandDiscardRelicEffect
    // Inputs ParamInt: Number of cards to draw next turn per ember.
    class RelicEffectDrawCardPerEmber : RelicEffectBase, IEndTurnPreHandDiscardRelicEffect, IRelicEffect
    {
        private int emberPerCard;
        public override bool CanApplyInPreviewMode => false;
        public override bool CanShowNotifications => false;

        public override void Initialize(RelicState relicState, RelicData relicData, RelicEffectData relicEffectData)
        {
            // If you override this method be sure to call the base class's Initialize method otherwise you will get a null reference exception.
            base.Initialize(relicState, relicData, relicEffectData);
            // Fetch parameters here.
            emberPerCard = relicEffectData.GetParamInt();
        }

        public bool TestEffect(EndTurnPreHandDiscardRelicEffectParams relicEffectParams)
        {
            return relicEffectParams.playerManager.GetEnergy() > emberPerCard;
        }

        public IEnumerator ApplyEffect(EndTurnPreHandDiscardRelicEffectParams relicEffectParams)
        {
            int cards = relicEffectParams.playerManager.GetEnergy() / emberPerCard;
            relicEffectParams.cardManager.AdjustDrawCountModifier(cards);
            yield break;
        }
    }

Simple enough that it doesn't need any explanation.

Ember Exchanger

Again by now, this should be routine.

    public class EmberExchanger
    {
        public static readonly string ID = TestPlugin.CLANID + "_EmberExchanger";

        public static void BuildAndRegister()
        {
            new CollectableRelicDataBuilder
            {
                CollectableRelicID = ID,
                Name = "Ember Exchanger",
                Description = "Draw 1 card for every 1 ember you have at the end of the turn.",
                RelicPoolIDs = { VanillaRelicPoolIDs.MegaRelicPool },
                IconPath = "assets/ember.png",
                ClanID = Clan.ID,
                EffectBuilders =
                {
                    new RelicEffectDataBuilder
                    {
                        RelicEffectClassType = typeof(RelicEffectDrawCardPerEmber),
                        ParamInt = 1,
                        ParamSourceTeam = Team.Type.Monsters,
                    }
                },
                Rarity = CollectableRarity.Common
            }.BuildAndRegister();
        }
    }

Last up: Custom-Triggers