Skip to content

Commit

Permalink
Update various life regen and related hook docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
JavidPack committed Jan 16, 2024
1 parent baa7ff1 commit 1b105d7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
5 changes: 4 additions & 1 deletion patches/tModLoader/Terraria/ModLoader/GlobalNPC.cs
Expand Up @@ -188,7 +188,10 @@ public virtual void HitEffect(NPC npc, NPC.HitInfo hit)
}

/// <summary>
/// Allows you to make the NPC either regenerate health or take damage over time by setting npc.lifeRegen. Regeneration or damage will occur at a rate of half of npc.lifeRegen per second. The damage parameter is the number that appears above the NPC's head if it takes damage over time.
/// Allows you to make the NPC either regenerate health or take damage over time by setting <see cref="NPC.lifeRegen"/>. This is useful for implementing damage over time debuffs such as <see cref="BuffID.Poisoned"/> or <see cref="BuffID.OnFire"/>. Regeneration or damage will occur at a rate of half of <see cref="NPC.lifeRegen"/> per second.
/// <para/>Essentially, modders implementing damage over time debuffs should subtract from <see cref="NPC.lifeRegen"/> a number that is twice as large as the intended damage per second. See <see href="https://github.com/tModLoader/tModLoader/blob/stable/ExampleMod/Common/GlobalNPCs/DamageOverTimeGlobalNPC.cs#L16">DamageOverTimeGlobalNPC.cs</see> for an example of this.
/// <para/>The damage parameter is the number that appears above the NPC's head if it takes damage over time.
/// <para/>Multiple debuffs work together by following some conventions: <see cref="NPC.lifeRegen"/> should not be assigned a number, rather it should be subtracted from. <paramref name="damage"/> should only be assigned if the intended popup text is larger then its current value.
/// </summary>
/// <param name="npc"></param>
/// <param name="damage"></param>
Expand Down
5 changes: 4 additions & 1 deletion patches/tModLoader/Terraria/ModLoader/ModNPC.cs
Expand Up @@ -278,7 +278,10 @@ public virtual void HitEffect(NPC.HitInfo hit)
}

/// <summary>
/// Allows you to make the NPC either regenerate health or take damage over time by setting NPC.lifeRegen. Regeneration or damage will occur at a rate of half of NPC.lifeRegen per second. The damage parameter is the number that appears above the NPC's head if it takes damage over time.
/// Allows you to make the NPC either regenerate health or take damage over time by setting <see cref="NPC.lifeRegen"/>. This is useful for implementing damage over time debuffs such as <see cref="BuffID.Poisoned"/> or <see cref="BuffID.OnFire"/>. Regeneration or damage will occur at a rate of half of <see cref="NPC.lifeRegen"/> per second.
/// <para/>Essentially, modders implementing damage over time debuffs should subtract from <see cref="NPC.lifeRegen"/> a number that is twice as large as the intended damage per second. See <see href="https://github.com/tModLoader/tModLoader/blob/stable/ExampleMod/Common/GlobalNPCs/DamageOverTimeGlobalNPC.cs#L16">DamageOverTimeGlobalNPC.cs</see> for an example of this.
/// <para/>The damage parameter is the number that appears above the NPC's head if it takes damage over time.
/// <para/>Multiple debuffs work together by following some conventions: <see cref="NPC.lifeRegen"/> should not be assigned a number, rather it should be subtracted from. <paramref name="damage"/> should only be assigned if the intended popup text is larger then its current value.
/// </summary>
/// <param name="damage"></param>
public virtual void UpdateLifeRegen(ref int damage)
Expand Down
20 changes: 20 additions & 0 deletions patches/tModLoader/Terraria/NPC.cs.patch
Expand Up @@ -120,6 +120,26 @@
public bool canDisplayBuffs = true;
public bool midas;
public bool ichor;
@@ -136,7 +_,19 @@
public bool shadowFlame;
public bool soulDrain;
public bool shimmering;
+ /// <summary>
+ /// The rate of this player's life regeneration or loss in health per tick, divided by <c>120</c>. To put it another way, it is health regeneration every 2 seconds. Used to implement the damage over time of debuffs.
+ /// <br/> For example, subtracting <c>12</c> from this value loses <c>12 / 120</c> = <c>1/10</c> health per tick, or 6 health per second.
+ /// <br/> Life regeneration is accumulated every tick in <see cref="lifeRegenCount"/>.
+ /// <br/> This value should be subtracted from in <see cref="ModNPC.UpdateLifeRegen(ref int)"/> or <see cref="GlobalNPC.UpdateLifeRegen(NPC, ref int)"/>. See <see href="https://github.com/tModLoader/tModLoader/blob/stable/ExampleMod/Common/GlobalNPCs/DamageOverTimeGlobalNPC.cs#L16">DamageOverTimeGlobalNPC.cs</see> for an example. The game does not actually use positive life regen for NPC, so positive values might not work as expected.
+ /// </summary>
public int lifeRegen;
+ /// <summary>
+ /// This NPC's accumulated life regeneration.
+ /// <br/> If this value reaches or exceeds <c>120</c>, the NPC gains <c><see cref="lifeRegenCount"/> / 120</c> health and this value decreases until it no longer exceeds <c>120</c>.
+ /// <br/> If this value reaches or exceeds <c>-120</c>, the NPC loses health in the same way.
+ /// <br/> In either case, text will appear above the NPC indicating the life regeneration or life loss.
+ /// </summary>
public int lifeRegenCount;
public int lifeRegenExpectedLossPerSecond = -1;
public bool confused;
@@ -182,35 +_,149 @@
public static bool unlockedArmsDealerSpawn = false;
public static bool unlockedNurseSpawn = false;
Expand Down
5 changes: 3 additions & 2 deletions patches/tModLoader/Terraria/Player.cs.patch
Expand Up @@ -397,7 +397,7 @@
public float manaCost = 1f;
public bool fireWalk;
public bool channel;
@@ -961,23 +_,96 @@
@@ -961,23 +_,97 @@
public int golferScoreAccumulated;
public int bartenderQuestLog;
public bool downedDD2EventAnyDifficulty;
Expand Down Expand Up @@ -464,7 +464,7 @@
public int statManaMax2;
+
+ /// <summary>
+ /// The rate of this player's life regeneration in health/ticks, divided by <c>120</c>.
+ /// The rate of this player's life regeneration in health per tick, divided by <c>120</c>. To put it another way, it is health regeneration every 2 seconds. Used to implement the damage over time of debuffs and life regeneration accessories such as <see cref="ItemID.BandofRegeneration"/>.
+ /// <br/> For example, adding <c>10</c> to this value regenerates <c>10 / 120</c> = <c>1/6</c> health per tick, or 5 health per second.
+ /// <br/> Life regeneration is accumulated every tick in <see cref="lifeRegenCount"/>.
+ /// <br/> This value should be subtracted from in <see cref="ModPlayer.UpdateBadLifeRegen"/> and added to in <see cref="ModPlayer.UpdateLifeRegen"/>.
Expand All @@ -475,6 +475,7 @@
+ /// This player's accumulated life regeneration.
+ /// <br/> If this value reaches or exceeds <c>120</c>, the player gains <c><see cref="lifeRegenCount"/> / 120</c> health and this value decreases until it no longer exceeds <c>120</c>.
+ /// <br/> If this value reaches or exceeds <c>-120</c>, the player loses health in the same way.
+ /// <br/> In either case, text will appear above the player indicating the life regeneration or life loss.
+ /// </summary>
public int lifeRegenCount;
+
Expand Down

0 comments on commit 1b105d7

Please sign in to comment.