TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches

◆ AddBuff()

void Terraria.Player.AddBuff ( int type,
int timeToAdd,
bool quiet = true,
bool foodHack = false )
inline

Gives the player the provided buff. This accounts for if the player is immune to the buff. This also accounts for adjusting the buff time for different game modes. If the player already has the buff, the re-apply logic will happen. Vanilla buff types are found in T:Terraria.ID.BuffID and modded buffs are typically retrieved using M:Terraria.ModLoader.ModContent.BuffType``1. The quiet parameter will determine if the network sync message should happen. This should only be set to false in non-deterministic situations (such as random chance) and code that only runs locally. Other situations run on all clients so the buff should automatically be applied on all clients, keeping the player buff data in sync without burdening the network. When in doubt, consult vanilla source code examples or test your code.
If applying a buff to a player other than the local player in pvp, quiet should be false and the buff must be true in F:Terraria.Main.pvpBuff to properly sync.

Parameters
typeThe buff type
timeToAddThe desired buff time in ticks. 60 ticks is 1 second
quietIf true, the network sync message is skipped.
foodHackunused

Definition at line 5700 of file Player.cs.

5701 {
5702 if (buffImmune[type])
5703 {
5704 return;
5705 }
5706 bool flag = !quiet && Main.netMode == 1 && Main.pvpBuff[type] && Main.myPlayer != whoAmI;
5707 if (!flag && BuffID.Sets.IsFedState[type])
5708 {
5709 for (int i = 0; i < maxBuffs; i++)
5710 {
5712 {
5713 DelBuff(i);
5714 }
5715 }
5716 }
5719 {
5720 return;
5721 }
5722 if (!quiet && Main.netMode == 1)
5723 {
5724 NetMessage.SendData(55, -1, -1, null, whoAmI, type, num);
5725 if (flag)
5726 {
5727 return;
5728 }
5729 }
5733 }
int whoAmI
The index of this Entity within its specific array. These arrays track the entities in the world....
Definition Entity.cs:16
static bool[] IsFedState
If true for a given T:Terraria.ID.BuffID, then that buff is related to player hunger....
Definition BuffID.cs:40
bool[] buffImmune
Indexed by T:Terraria.ID.BuffID. If true for a given T:Terraria.ID.BuffID, then this player cannot be...
Definition Player.cs:1699
void AddBuff_RemoveOldPetBuffsOfMatchingType(int type)
Definition Player.cs:5787
int AddBuff_DetermineBuffTimeToAdd(int type, int time1)
Definition Player.cs:5842
bool AddBuff_ActuallyTryToAddTheBuff(int type, int time)
Definition Player.cs:5735
bool AddBuff_TryUpdatingExistingBuffTime(int type, int time)
Definition Player.cs:5812
void AddBuff_RemoveOldMeleeBuffsOfMatchingType(int type)
Definition Player.cs:5771
int[] buffType
The T:Terraria.ID.BuffIDs of all buffs this player has active. A value of 0 means that buff slot is...
Definition Player.cs:1684
static int maxBuffs
Definition Player.cs:3380
void DelBuff(int b)
Removes the buff at the provided index in F:Terraria.Player.buffType and F:Terraria....
Definition Player.cs:5868

References Terraria.Player.AddBuff_ActuallyTryToAddTheBuff(), Terraria.Player.AddBuff_DetermineBuffTimeToAdd(), Terraria.Player.AddBuff_RemoveOldMeleeBuffsOfMatchingType(), Terraria.Player.AddBuff_RemoveOldPetBuffsOfMatchingType(), Terraria.Player.AddBuff_TryUpdatingExistingBuffTime(), Terraria.Player.buffImmune, Terraria.Player.buffType, Terraria.Player.DelBuff(), Terraria.ID.BuffID.Sets.IsFedState, Terraria.Player.maxBuffs, Terraria.Main.netMode, Terraria.Main.pvpBuff, Terraria.NetMessage.SendData(), and Terraria.Entity.whoAmI.

Referenced by Terraria.NPC.AI_107_ImprovedWalkers(), Terraria.Projectile.AI_111_DryadsWard(), Terraria.NPC.AI_123_Deerclops(), Terraria.Player.ApplyEquipFunctional(), Terraria.Player.ApplyLifeAndOrMana(), Terraria.Player.ApplyPotionDelay(), Terraria.Player.ApplyTouchDamage(), Terraria.Player.AutoFinchStaff(), Terraria.Player.BrainOfConfusionDodge(), Terraria.NPC.CheckCatchNPC(), Terraria.Player.ConsumeSolarFlare(), Terraria.Player.FloorVisuals(), Terraria.Player.Hurt(), Terraria.Player.ItemCheck_ApplyPetBuffs(), Terraria.Player.ItemCheck_Inner(), Terraria.Player.ItemCheck_UseTeleportRod(), Terraria.Projectile.Kill(), Terraria.Player.NebulaLevelup(), Terraria.Player.OnHit_Inner(), Terraria.Player.OnHurt_Part1(), Terraria.Player.OnHurt_Part2(), Terraria.Player.OnKillNPC(), Terraria.Player.QuickBuff(), Terraria.Player.QuickHeal(), Terraria.Player.StatusFromNPC(), Terraria.Player.TileInteractionsUse(), Terraria.Player.TorchAttack(), Terraria.Player.Update(), Terraria.Player.Update_NPCCollision(), Terraria.Player.UpdateArmorSets(), Terraria.Player.UpdateBuffs(), Terraria.Player.UpdateHungerBuffs(), Terraria.Player.UpdatePet(), Terraria.Player.UpdatePetLight(), Terraria.Player.UpdateStarvingState(), and Terraria.Player.WOFTongue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: