GameModifierDataBuilder - rspforhp/WildfrostModdingDocumentation GitHub Wiki

GameModifierDataBuilder

GameModifierDataBuilder(WildfrostMod mod)

  • The builder for creating game modifiers: sun bells, storm bells, and daily bells.
  • All vanilla modifiers can be found in references.

Example

Below is how the Sun Bell of Hands and the Sun Bell and Sun Bell of Recall could be coded with the builders.

//These builders are made in your main mod class (the one that extends the WildfrostMod class)
GameModifierDataBuilder blessingHand = new GameModifierDataBuilder(this)
        .Create("BlessingHand")
        .WithTitle("Sun Bell of Hands")
        .WithDescription("Card Draw <+1>")
        .WithBellAndDinger(this, "handBell.png", "handDinger.png")      //Helper Method! See the "Extra Code" section.
        .WithRingSfxEvent(FMODUnity.RuntimeManager.PathToEventReference("event:/sfx/modifiers/daily_bell_ringing"))
        .FreeModify(
        (data) =>
        {
            ScriptChangeHandSize handSize = ScriptableObject.CreateInstance<ScriptChangeHandSize>(); //The script to increase cards drawn.
            handSize.name = "Increase Hand Size By 2";
            handSize.set = false;
            handSize.value = 1;
            data.startScripts = new Script[] { handSize };
        });

GameModifierDataBuilder blessingRecall = new GameModifierDataBuilder(this)
        .Create("BlessingRecall")
        .WithTitle("Sun Bell of Recall")
        .WithDescription("<Recalling> a <Companion> will count down the <Redraw Bell> by <2>")
        .WithBellAndDinger(this, "recallBell.png", "recallDinger.png")      //Helper Method! See the "Extra Code" section.
        .WithRingSfxEvent(FMODUnity.RuntimeManager.PathToEventReference("event:/sfx/modifiers/daily_bell_ringing"))
        .WithSystemToAdd("RecallChargeRedrawBellModifierSystem");

//Note: making the builder is not the same as loading the GameModifierData into the game. There is an additional step involving AddAssets. 
//See Tutorial 2.

Warning

The source code assumes modifier systems are classes in Assembly-CSharp.dll. For custom modifier systems, you need to add a Harmony Patch to have it run properly. See the "Extra Code" section.

Extra Code

Bell Sprites and Dingers

When a bell is picked up, they will appear in the top-left of the screen. The sprites are assumed to have their pivot at the top of the bell in order for the dinging animation to look nice. This conflicts with the builder's implementation for adding sprites. Below are methods that perform the necessary changes.

//This is an Extension method. If you haven't already, make a new *static* class named Extensions or Ext and add this method.
//Visual Studio will pretend that this method actually belongs to GameModifierDataBuilder, so you can still perform the method chaining in the example above.
public static GameModifierDataBuilder WithBellAndDinger(this GameModifierDataBuilder b, WildfrostMod mod, string bell = null, string dinger = null)
{
    //Bell Sprite: dimensions-252x352px
    Texture2D bellTex = mod.ImagePath(bell).ToTex();
    Sprite bellSprite = Sprite.Create(bellTex, new Rect(0, 0, bellTex .width, bellTex .height), new Vector2(0.5f, 0.9f), 327);
    //Tune the numbers above (0.5, 0.9, 327) if your bell sprite is not of the right dimensions.
    b.WithBellSprite(bellSprite);
            
    //Dinger Sprite: dimensions-90x160px
    Texture2D dingerTex = mod.ImagePath(dinger).ToTex();
    Sprite dingerSprite = Sprite.Create(dingerTex, new Rect(0, 0, dingerTex.width, dingerTex.height), new Vector2(0.5f, 1.5f), 327);
    //Tune the numbers above (0.5, 1.5, 327) if your bell dinger is not of the right dimensions.
    b.WithDingerSprite(dingerSprite);
    return b;
}

Custom Modifier Systems

In order to reference your own modifier systems in your dll, you need the patch below somewhere in the same namespace as your modifier system.

[HarmonyPatch(typeof(GameObjectExt), "AddComponentByName")]
class PatchAddComponent
{
    static string assem => typeof(PatchAddComponent).Assembly.GetName().Name; //Find the proper assembly name
    static string namesp => typeof(PatchAddComponent).Namespace;              //Find the proper namespace name

    static Component Postfix(Component __result, GameObject gameObject, string componentName)
    {
        if (__result == null)
        {
            Type type = Type.GetType(namesp + "." + componentName + "," + assem); //Concat the pieces together
            if (type != null)
            {
                return gameObject.AddComponent(type);
            }
        }
        return __result;
    }
}

Methods

Some methods inherited from DataFileBuilder are not shown. They can be found on the Builders page.

Create (Inherited from DataFileBuilder)

Create(string name) OR Create<T>(string name) where T is a class that inherits from GameModifierData

  • Used to create a game modifier.
  • name is the internal name for your status effect.
  • T is a class that inherits from GameModifierData (there isn't any special ones in the base game)
  • This is the first method to use after creating builder.

WithBellSprite [Not Recommended]

WithBellSprite(string bellSprite) OR WithBellSprite(Sprite bellSprite)

  • Used to set the bell's dinger sprite.
  • bellSprite is the sprite file's relative address or the sprite itself.
  • Directory format for using this: Mods/ModName/images/test.png and Mods/ModName/Images/testBell.png , WithBellSprite("Images/testBell.png")
  • The sprite dimensions vary from bell to bell.
  • Width is about 252 pixels.
  • Height is about 352 pixels.

WithBlockedBy [Verification Needed]

WithBlockedBy(params GameModifierData[] blockedBy)

  • (Theory) Used to block the bell from appearing in rewards if other bells are present in inventory/choices.
  • blockedBy determines which bells are blocked by/block this bell.
  • You can assign several blocking/blocked bells by separating them with a comma (",").
  • Consider using SubscribeToAfterAllBuildEvent if you need to set a different custom bell (or self) to be blocked.

WithDescription

WithDescription(string title, SystemLanguage lang = English) OR WithDescription(LocalizedString title)

  • Used to set the description of the bell's popup.
  • title is the description displayed for the popup.
  • lang defines what localization your card's title is to be used in and is equal to SystemLanguage.English by default.

WithDingerSprite [Not Recommended]

WithDingerSprite(string dingerSprite) OR WithDingerSprite(Sprite dingerSprite)

  • Used to set the bell's dinger sprite.
  • dingerSprite is the sprite file's relative address or the sprite itself.
  • Directory format for using this: Mods/ModName/images/test.png and Mods/ModName/Images/testDinger.png , WithDingerSprite("Images/testDinger.png")
  • The sprite dimensions vary from bell to bell.
  • Width is around 87 pixels.
  • Height is about 160 pixels.

WithLinkedStormBell

WithLinkedStormBell(HardModeModifierData linkedStormBell)

  • Used to link the modifier with a storm bell.
  • linkedStormBell is the associated HardModeModifierData, holding info about unlock requirements and storm points.

WithSfxEvent

WithSfxEvent(EventReference ringSfxEvent)

  • Used to determine the sound effect for hovering/picking the bell.
  • ringSfxEvent is the reference to the sound effect file.
  • Use FMODUnity.RuntimeManager.PathToEventReference(string path) to make the sfx reference.
  • All path can be found in the references.

WithSfxPitch

WithSfxPitch(Vector2 ringSfxPitch) OR WithSfxPitch()

  • Modify the pitch range of the bell.
  • ringSfxPitch is the pitch range. By default, this is always [1,1] (constant).
  • The argument-less version resets the pitch range to [1,1] (constant).

WithScriptPriority

WithScriptPriority(int scriptPriority)

  • Used to determine the order in which setup/start scripts execute in campaign generation.
  • scriptPriority is the script's priority. Scripts with higher priority execute first.

WithSetupScripts / WithStartScripts

WithSetupScripts(params Script[] setupScript) OR WithStartScripts(params Script[] startScripts)

  • Used to execute scripts on pickup or before the game begins
  • setupScript are for scripts that execute before campaign generation (Events.OnCampaignInit) or immediately after pickup.
  • startScripts are for scripts that execute after campaign generation (Events.OnCampaignGenerated) or immediately after pickup.
  • You can assign several scripts by separating them with a comma (",").

WithSystemsToAdd

WithSystemsToAdd(params string[] systemsToAdd)

  • Used to add a modifier system component to the current campaign systems.
  • Use systems for modifiers with ongoing effects (i.e., Bell of Recall, Bell of Charge).
  • Systems are added sometime around campaign generation (???) or immediately after pickup.
  • systemsToAdd are the name of the systems to add.
  • Each name must be associated to a GameSystem-derived class of the same name.
  • GameSystem-derived classes must extend its OnEnable and OnDisable methods.
  • You can assign several system names by separating them with a comma (",").
  • For adding custom modifier systems, see the "Extra Code" section.

WithTitle

WithTitle(string title, SystemLanguage lang = English) OR WithTitle(LocalizedString title)

  • Used to make the title of the bell's popup.
  • title is the title that would be displayed in the popup.
  • lang defines what localization your card's title is to be used in and is equal to SystemLanguage.English by default.

WithValue

WithValue(int value = 100)

  • Used to determine the beneficial value of the bell.
  • Used in calculating starting bells in dailies.
  • value is the value of the bell. By default, value is 100 without using this method.

WithVisible [Verification Needed]

WithVisible(bool visible = true)

  • Affects the chance of appearing in dailies. Although the bell has to be manually added to the daily bell pool anyway.
  • Possibly affects actual visibility?
⚠️ **GitHub.com Fallback** ⚠️