tModLoader

tModLoader

Block's Better Bars
 此主题已被置顶,因此可能具有重要性
BlockCrusader  [开发者] 8 月 10 日 下午 12:04
Mod.Call Guide (v1.3+)
Mod.Call Guide
Does a boss in your mod have special logic for its health display (and/or a shield display)? By default, this mod isn't able to pick up on such logic, but with a Mod.Call you can implement it to the boss bar style added by this mod. With the V2 version of the call, you can even add a custom sprite for your boss's bar!

This thread will walk you through each of the arguments you must provide when making a Call to this mod.

Note that this guide is written for the improved Call added in version 1.3 of the mod. If you're using a version of the mod older than 1.3, this won't work! In that case, you should refer to the Mod.Call Guide (Legacy) discussion thread instead. Keep in mind that the old guide and Call are inferior, though they are still compatible.



Getting started
First, you'll need to know how make a Call in general; this guide on the tML GitHub[github.com] can help.

On a related note, be warned that this guide assumes you are well-versed in (at least) the basics of coding with C# and tML (after all, if you're here, you've presumably programmed your own boss)
While this guide does explain what arguments are needed for the Call, it does not provide example code beyond an example of the Call itself.

You should place your call in the PostSetupContent() hook of a ModSystem class.

Many of the arguments in this call are delegate methods, so make sure you have a place for those. The same ModSystem class you place your Call in should suffice.
Alternatively, you can place them in your NPC's ModNPC class, just remember to make the methods static!

Don't forget to check that this mod is loaded (its internal name is BBossBars) before attempting to make the Call. You can use this example code below;
if (ModLoader.TryGetMod("BBossBars", out Mod bossBarMod)) { // Mod.Call goes here }



The Call
The call you'll make requires 4-8 arguments (The latter 4 are optional). Note that many of them are delegate methods!

Here is an example of the call;
bossBarMod.Call( "AddCustomBarV2", // Call's name ModContent.NPCType<ExampleBoss>(), // The NPC type of the boss ExampleBossGetAssociatedNPCs, // Returns a list of NPC types associated with the boss ExampleBossGetStats, // Returns current/max health/shield values // The latter 4 arguments are optional ExampleBossGetName, // Returns a string of the boss's name ExampleBossGetIcon, // Returns a Asset<Texture2D> of the boss's head icon ExampleBossGetBar, // Returns a Asset<Texture2D> of a custom boss bar texture false, // True if for a miniboss );
Note how the methods (3rd through 7th arguments) are not invoked, as they are delegates.

See below for details on the expected types of data to be passed in for each argument. Make sure to read it in full so you know what the different delegate methods should do!



0: Call Name (string)
The name of the call being made. Should always be "AddCustomBarV2".



1: Npc Type (int)
The NPC.type of the boss your logic is for.



2: Get Associated NPCs (method)
Method arguments:
  • (NPC) boss: The boss's respective NPC
  • (bool) shield: True when the boss’s shield (if any) is active, false otherwise

Method returns:
  • (List<int>): List of NPC.whoAmIs of all NPCs that contribute to the boss’s cumulative life (bool is false) or shield (bool is true) value, including the boss itself.

Notes:
  • The returned list is used by Block’s Boss Bars to implement its bar shake and bar chip effects.
    If your boss has no shield, you can ignore the shield argument.



3: Get Stat (method)
Method arguments:
  • (NPC) boss: The boss's respective NPC
  • (bool) shield: True when the boss’s shield (if any) is active, false otherwise
  • (bool) getMax: True when max life/shield is desired, false if current life/shield is desired

Method returns:
  • (float): The boss’s max or current value of their life or shield, based on shield and getMax.

Notes:
  • If your boss has no shield, you can ignore the shield argument.



4: Get Icon (method)
Method arguments:
  • (NPC) boss: The boss's respective NPC

Method returns:
  • (Asset<Texture2D>): The head icon of the boss (i.e. its icon on the minimap)

Notes:
  • You are free to return any texture you want, not necessarily the boss’s head icon. However, keep in mind that particularly large or small textures may look bad.

This argument is optional! If skipped, the default behavior is as follows:
The mod will attempt to retrieve the boss’s head icon. If it fails, a fallback icon is used.



5: Get Name (method)
Method arguments:
  • (NPC) boss: The boss's respective NPC

Method returns:
  • (string): The name the boss’s bar will display

Notes:
  • The mod will automatically account for shields (by adding “ Shield” to the end of the name), so don’t worry about adjusting the name if your boss uses the shield bar.

This argument is optional! If skipped, the default behavior is as follows:
The mod will automatically retrieve and use the boss’s normal display name.



6: Custom Bar Texture (method)
Method arguments:
  • (bool) longBar: If the user has the ‘long bars’ option enabled. If true, a longer bar texture is expected.

Method returns:
  • (Asset<Texture2D>): A custom bar texture for the boss

Notes:
  • Custom textures will only be used if the user has enabled the Signature Boss Bars option in the mod’s config!
  • Bar textures are expected to have very specific dimensions and metrics! You’ll want to follow a template to avoid issues. Such templates can be found at my mods’ github repo, here[github.com].
  • You are not obligated to make an extended version of your texture; just ignore the long bar argument if you don’t have one.

This argument is optional! If skipped, the default behavior is as follows:
The boss will not use a custom texture if the Signature Boss Bars feature is enabled



7: Is Miniboss (bool)
Whether or not the boss’s bar should behave as a miniboss bar. Miniboss bars have the following differences;
  • The bar’s appearance is changed
  • No boss icon is drawn
  • Text displays are smaller
Note that if the boss is given a custom bar texture (See Argument 6 above), its miniboss status is overridden and treated as false, regardless of this argument.

This argument is optional! If skipped, the default behavior is as follows:
Defaults to false



For more details on the Call and its arguments, feel free to inquiry here.
It may also be beneficial to extract the mod's source code (via. tML’s in-game extract function) and explore that to better understand the Call's inner workings.
Another useful resource is one of my other mods, Corruption Core Boss, which includes Mod.Call support for the boss it adds. Its source code can also be extracted, so you can use its Call to this mod as an example.
最后由 BlockCrusader 编辑于; 8 月 13 日 下午 1:15