public static void DrawHealthBars(SpriteBatch spriteBatch) { // Reset static vars such as collective healthbars HealthBar.ResetStaticVars(); // The bottom of thhe screen with some offset int maxYStack = (int)(Main.screenHeight * (1f - Config.HealthBarUIMaxStackSize)); int stackY = Main.screenHeight - Config.HealthBarUIScreenOffset; foreach (NPC npc in TrackedNPCs.Keys) { // Get the healthbar for this tracked NPC HealthBar hb = BossDisplayInfo.GetHealthBarForNPCOrNull(npc.type); if (hb == null) { hb = new HealthBar(); } stackY = hb.DrawHealthBarDefault( spriteBatch, GetAlpha(npc), stackY, maxYStack, npc.life, npc.lifeMax, npc); if (stackY < maxYStack - Config.HealthBarUIMaxStackSize) { break; } } }
private static void RemoveTrackedNPC(NPC npc) { // First check if it's a multi-bar NPC HealthBar hb = BossDisplayInfo.GetHealthBarForNPCOrNull(npc.type); int fadeTime = Config.HealthBarUIFadeTime - TrackedNPCs[npc]; if (hb != null) { if (hb.DisplayMode == HealthBar.DisplayType.Multiple && hb.multiShowCount > 1) { // Just remove it if there's more than 1 left TrackedNPCs.Remove(npc); return; } } // Make a temp copy that won't be changing // Do this to keep info of dead NPCs for a while // Also, if fade time is 1 or less, just skip this. if (fadeTime > 1) { NPC temp = new NPC(); temp = (NPC)npc.Clone(); temp.whoAmI = -1 - npc.whoAmI; if (temp.life <= 0 || (temp.dontTakeDamage && npc.life == npc.lifeMax)) { temp.life = 0; } TrackedNPCs.Add(temp, -fadeTime - 1); } TrackedNPCs.Remove(npc); if (DEBUG_TRACKER) { Main.NewText(npc.GivenOrTypeName + " [" + npc.whoAmI + "] removed"); } }
public static bool CanTrackNPCHealth(NPC npc) { // Cannot track non-active entities if (!npc.active) { return(false); } if (npc.timeLeft <= 0) { return(false); } if (npc.life <= 0) { return(false); } // Don't track NPCs which are part of a shared life chain (except the head of course) if (npc.realLife >= 0 && npc.realLife != npc.whoAmI) { return(false); } // Too far away to bother showing a health bar bool tooFar = (npc.position.X <Main.LocalPlayer.position.X - Config.HealthBarDrawDistance || npc.position.X> Main.LocalPlayer.position.X + Config.HealthBarDrawDistance || npc.position.Y <Main.LocalPlayer.position.Y - Config.HealthBarDrawDistance || npc.position.Y> Main.LocalPlayer.position.Y + Config.HealthBarDrawDistance); HealthBar hb = BossDisplayInfo.GetHealthBarForNPCOrNull(npc.type); if (hb != null) { if (hb.DisplayMode == HealthBar.DisplayType.Disabled || hb.HideHealthBarOverride(npc, tooFar)) { return(false); } if (hb.ShowHealthBarOverride(npc, tooFar)) { return(true); } } // Cannot track npcs without a health bar if (npc.immortal || npc.dontTakeDamage || npc.dontTakeDamageFromHostiles || tooFar) { return(false); } // The modded NPC doesn't want to show health? if (npc.modNPC != null) { float scale = 1f; Vector2 position = new Vector2(npc.position.X + npc.width / 2, npc.position.Y + npc.gfxOffY); bool? result = npc.modNPC.DrawHealthBar(Main.HealthBarDrawSettings, ref scale, ref position); if (result == false) { return(false); } } // Someone has specified a healthbar for this NPC? if (hb != null) { return(true); } // Otherwise if it's a boss then also sure if (npc.boss) { return(true); } return(false); }