1 using Microsoft.Xna.Framework;
2 using Microsoft.Xna.Framework.Graphics;
5 using System.Collections.Generic;
16 internal static int extraPlayerBuffCount;
17 private static int nextBuff = BuffID.Count;
18 internal static readonly IList<ModBuff> buffs =
new List<ModBuff>();
19 internal static readonly IList<GlobalBuff> globalBuffs =
new List<GlobalBuff>();
20 private static readonly
bool[] vanillaLongerExpertDebuff =
new bool[BuffID.Count];
21 private static readonly
bool[] vanillaCanBeCleared =
new bool[BuffID.Count];
23 private delegate
void DelegateUpdatePlayer(
int type, Player player, ref
int buffIndex);
25 private delegate
void DelegateUpdateNPC(
int type, NPC npc, ref
int buffIndex);
29 private delegate
void DelegateModifyBuffTip(
int type, ref
string tip, ref
int rare);
35 for (
int k = 0; k < BuffID.Count; k++) {
36 vanillaCanBeCleared[k] =
true;
38 vanillaLongerExpertDebuff[BuffID.Poisoned] =
true;
39 vanillaLongerExpertDebuff[BuffID.Darkness] =
true;
40 vanillaLongerExpertDebuff[BuffID.Cursed] =
true;
41 vanillaLongerExpertDebuff[BuffID.OnFire] =
true;
42 vanillaLongerExpertDebuff[BuffID.Bleeding] =
true;
43 vanillaLongerExpertDebuff[BuffID.Confused] =
true;
44 vanillaLongerExpertDebuff[BuffID.Slow] =
true;
45 vanillaLongerExpertDebuff[BuffID.Weak] =
true;
46 vanillaLongerExpertDebuff[BuffID.Silenced] =
true;
47 vanillaLongerExpertDebuff[BuffID.BrokenArmor] =
true;
48 vanillaLongerExpertDebuff[BuffID.CursedInferno] =
true;
49 vanillaLongerExpertDebuff[BuffID.Frostburn] =
true;
50 vanillaLongerExpertDebuff[BuffID.Chilled] =
true;
51 vanillaLongerExpertDebuff[BuffID.Frozen] =
true;
52 vanillaLongerExpertDebuff[BuffID.Ichor] =
true;
53 vanillaLongerExpertDebuff[BuffID.Venom] =
true;
54 vanillaLongerExpertDebuff[BuffID.Blackout] =
true;
55 vanillaCanBeCleared[BuffID.PotionSickness] =
false;
56 vanillaCanBeCleared[BuffID.Werewolf] =
false;
57 vanillaCanBeCleared[BuffID.Merfolk] =
false;
58 vanillaCanBeCleared[BuffID.WaterCandle] =
false;
59 vanillaCanBeCleared[BuffID.Campfire] =
false;
60 vanillaCanBeCleared[BuffID.HeartLamp] =
false;
61 vanillaCanBeCleared[BuffID.NoBuilding] =
false;
64 internal static int ReserveBuffID() {
67 int reserveID = nextBuff;
72 public static int BuffCount => nextBuff;
78 return type >= BuffID.Count && type < BuffCount ? buffs[type - BuffID.Count] : null;
81 internal static void ResizeArrays() {
82 Array.Resize(ref Main.pvpBuff, nextBuff);
83 Array.Resize(ref Main.persistentBuff, nextBuff);
84 Array.Resize(ref Main.vanityPet, nextBuff);
85 Array.Resize(ref Main.lightPet, nextBuff);
86 Array.Resize(ref Main.meleeBuff, nextBuff);
87 Array.Resize(ref Main.debuff, nextBuff);
88 Array.Resize(ref Main.buffNoSave, nextBuff);
89 Array.Resize(ref Main.buffNoTimeDisplay, nextBuff);
90 Array.Resize(ref Main.buffDoubleApply, nextBuff);
91 Array.Resize(ref Main.buffAlpha, nextBuff);
92 Array.Resize(ref Main.buffTexture, nextBuff);
93 Array.Resize(ref Lang._buffNameCache, nextBuff);
94 Array.Resize(ref Lang._buffDescriptionCache, nextBuff);
95 for (
int k = BuffID.Count; k < nextBuff; k++) {
96 Lang._buffNameCache[k] = LocalizedText.Empty;
97 Lang._buffDescriptionCache[k] = LocalizedText.Empty;
101 ModLoader.BuildGlobalHook(ref HookUpdatePlayer, globalBuffs, g => g.Update);
102 ModLoader.BuildGlobalHook(ref HookUpdateNPC, globalBuffs, g => g.Update);
103 ModLoader.BuildGlobalHook(ref HookReApplyPlayer, globalBuffs, g => g.ReApply);
104 ModLoader.BuildGlobalHook(ref HookReApplyNPC, globalBuffs, g => g.ReApply);
105 ModLoader.BuildGlobalHook(ref HookModifyBuffTip, globalBuffs, g => g.ModifyBuffTip);
106 ModLoader.BuildGlobalHook(ref HookCustomBuffTipSize, globalBuffs, g => g.CustomBuffTipSize);
107 ModLoader.BuildGlobalHook(ref HookDrawCustomBuffTip, globalBuffs, g => g.DrawCustomBuffTip);
110 internal static void Unload() {
112 nextBuff = BuffID.Count;
116 internal static bool IsModBuff(
int type) {
117 return type >= BuffID.Count;
120 public static void Update(
int buff, Player player, ref
int buffIndex) {
121 int originalIndex = buffIndex;
122 if (IsModBuff(buff)) {
123 GetBuff(buff).Update(player, ref buffIndex);
125 foreach (var hook
in HookUpdatePlayer) {
126 if (buffIndex != originalIndex) {
129 hook(buff, player, ref buffIndex);
133 public static void Update(
int buff, NPC npc, ref
int buffIndex) {
134 if (IsModBuff(buff)) {
135 GetBuff(buff).Update(npc, ref buffIndex);
137 foreach (var hook
in HookUpdateNPC) {
138 hook(buff, npc, ref buffIndex);
142 public static bool ReApply(
int buff, Player player,
int time,
int buffIndex) {
143 foreach (var hook
in HookReApplyPlayer) {
144 if (hook(buff, player, time, buffIndex)) {
148 if (IsModBuff(buff)) {
149 return GetBuff(buff).ReApply(player, time, buffIndex);
154 public static bool ReApply(
int buff, NPC npc,
int time,
int buffIndex) {
155 foreach (var hook
in HookReApplyNPC) {
156 if (hook(buff, npc, time, buffIndex)) {
160 if (IsModBuff(buff)) {
161 return GetBuff(buff).ReApply(npc, time, buffIndex);
167 return GetBuff(buff)?.longerExpertDebuff ?? vanillaLongerExpertDebuff[buff];
171 return GetBuff(buff)?.canBeCleared ?? vanillaCanBeCleared[buff];
175 if (IsModBuff(buff)) {
176 GetBuff(buff).ModifyBuffTip(ref tip, ref rare);
178 foreach (var hook
in HookModifyBuffTip) {
179 hook(buff, ref tip, ref rare);
184 foreach (var hook
in HookCustomBuffTipSize) {
185 hook(buffTip, sizes);
189 public static void DrawCustomBuffTip(
string buffTip, SpriteBatch spriteBatch,
int originX,
int originY) {
190 foreach (var hook
in HookDrawCustomBuffTip) {
191 hook(buffTip, spriteBatch, originX, originY);
static bool ReApply(int buff, NPC npc, int time, int buffIndex)
static bool AllowVanillaClients
static DelegateUpdatePlayer[] HookUpdatePlayer
static bool CanBeCleared(int buff)
This serves as the central class which loads mods. It contains many static fields and methods related...
static Func< int, NPC, int, int, bool >[] HookReApplyNPC
static void CustomBuffTipSize(string buffTip, List< Vector2 > sizes)
static void DrawCustomBuffTip(string buffTip, SpriteBatch spriteBatch, int originX, int originY)
static DelegateUpdateNPC[] HookUpdateNPC
static Action< string, List< Vector2 > >[] HookCustomBuffTipSize
This class serves as a place for you to define a new buff and how that buff behaves.
static ModBuff GetBuff(int type)
Gets the ModBuff instance with the given type. If no ModBuff with the given type exists, returns null.
This serves as the central class from which buff-related functions are supported and carried out...
static void Update(int buff, NPC npc, ref int buffIndex)
static Func< int, Player, int, int, bool >[] HookReApplyPlayer
static DelegateModifyBuffTip[] HookModifyBuffTip
static bool LongerExpertDebuff(int buff)
static Action< string, SpriteBatch, int, int >[] HookDrawCustomBuffTip
static void ModifyBuffTip(int buff, ref string tip, ref int rare)
static void Update(int buff, Player player, ref int buffIndex)
static bool ReApply(int buff, Player player, int time, int buffIndex)