Repository navigation
Buffs
Buffs are the timed effects that show up as small icons while they last: Well
Fed, Regeneration, Poisoned, On Fire!. Helpful ones are called buffs and
harmful ones debuffs, but in code they are the same thing. A mod adds new ones
with ModBuff and changes the game's own with GlobalBuff.
public class ExampleLifeRegenDebuff : ModBuff
{
public override void SetStaticDefaults()
{
Main.debuff[Type] = true;
Main.pvpBuff[Type] = true;
Main.buffNoSave[Type] = true;
BuffID.Sets.BuffTimeIsExtendedWithGameDifficulty[Type] = true;
}
public override void Update(Player player, ref int buffIndex) =>
player.GetModPlayer<ExampleLifeRegenDebuffPlayer>().lifeRegenDebuff = true;
}A ModBuff gets a type after the game's (BuffID.Count is 401):
ModContent.BuffType<T>(), BuffLoader.GetBuff(type). The icon is the
class's texture (ExampleLifeRegenDebuff.png, 32x32), the name and
description come from Mods.<Mod>.Buffs.<Name>.DisplayName/Description.
SetStaticDefaults runs when the game's buff tables (Main.debuff,
Main.buffNoSave, BuffID.Sets...) have the type; give it to a player with
player.AddBuff(type, time) or to an item with Item.buffType. The
Bunny Loader also patches the places where the phone's game had the buff
count compiled in (the buff bar, the nurse, the network) and saves the mod
buffs of a character by name.
Hook (ModBuff; GlobalBuff has the type first, for every buff) |
When |
|---|---|
Update(Player player, ref int buffIndex) |
each frame, after the game's Player.UpdateBuffs
|
Update(NPC npc, ref int buffIndex) |
each frame, after the game's NPC.UpdateNPC_BuffSetFlags
|
ReApply(Player player, int time, int buffIndex), ReApply(NPC ...)
|
when the buff is given again; true keeps the game from renewing the time |
ModifyBuffText(ref string buffName, ref string tip, ref int rare) |
for the name (Lang.GetBuffName) and the tip (Main.GetBuffTooltip) the buff bar shows; rare has no effect on the phone |
RightClick(int buffIndex) |
when the player taps the buff to cancel it; false keeps it |
GlobalBuff.Update runs for each active buff, the game's included, after
the ModBuff's; a hook that removes the buff lowers buffIndex, as in
tModLoader.
The icon in the buff bar: PreDraw(spriteBatch, buffIndex, ref BuffDrawParams drawParams) (GlobalBuffs first, then the ModBuff) and PostDraw. The
params start as the game draws it: Position is the icon's top left corner,
TextPosition the time text's, DrawColor the bar's fade
(Main.buffAlpha). A change to Texture, Position, SourceRectangle or
DrawColor goes to the game's draw of that icon, a change to TextPosition
moves its time text, and false hides the icon (the text stays, as in
tModLoader). The phone draws the bar at a 0.8 scale.
The buff's tip (tapping the icon shows it through Main.MouseText):
GlobalBuff.CustomBuffTipSize(buffTip, sizes) adds the sizes of what a mod
draws under it, so the game moves the box back on screen, and
DrawCustomBuffTip(buffTip, spriteBatch, originX, originY) draws it, with the
origin just under the tip text. FontAssets.MouseText, ItemStack and
DeathText are Asset<SpriteFont>s, as in tModLoader:
public override void DrawCustomBuffTip(string buffTip, SpriteBatch spriteBatch, int originX, int originY) =>
spriteBatch.DrawString(FontAssets.MouseText.Value, "More text", new Vector2(originX, originY), Color.Yellow);
Bunny Loader wiki ·
Discord ·
Repository ·
BL Editor
Written for Bunny Loader 0.5.5-beta and Terraria Mobile 1.4.5.8.6.
Bunny Loader is not affiliated with Re-Logic or 505 Games.
