Beispiel #1
0
        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");
            }
        }
Beispiel #2
0
        public static void UpdateNPCTracker()
        {
            if (DEBUG_TRACKER && Main.time % 60 == 0)
            {
                string tracked = "list: ";
                foreach (NPC npc in TrackedNPCs.Keys)
                {
                    tracked += string.Concat("[", npc.whoAmI, "]");//(char)(65 + npc.whoAmI);
                    Main.NewText(string.Concat(npc.GivenOrTypeName + ":", npc.active, "|", npc.timeLeft, "|", npc.life, "|", npc.lifeMax, "|trackable?", CanTrackNPCHealth(npc)));
                }
                Main.NewTextMultiline(tracked);
            }

            // Add and remove NPCs on the list
            foreach (NPC npc in Main.npc)
            {
                // Is NPC still trackable
                if (CanTrackNPCHealth(npc))
                {
                    // Not in list yet?
                    if (!TrackedNPCs.ContainsKey(npc))
                    {
                        TrackedNPCs.Add(npc, (short)Config.HealthBarUIFadeTime);
                        if (DEBUG_TRACKER)
                        {
                            Main.NewText(npc.GivenOrTypeName + " [" + npc.whoAmI + "] added - " + TrackedNPCs[npc]);
                        }
                    }
                }
                else
                {
                    // But in was in the list before?
                    //if (TrackedNPCs.ContainsKey(npc))
                    foreach (NPC tracked in TrackedNPCs.Keys)
                    {
                        if (npc == tracked)
                        {
                            if (DEBUG_TRACKER)
                            {
                                Main.NewText(npc.GivenOrTypeName + " [" + npc.whoAmI + "] flagged for removal");
                            }

                            RemoveTrackedNPC(npc);
                            break;
                        }
                        // Look for clashing npcs caused by npc spawning on same slot as defeated npc
                        else if (npc.whoAmI == tracked.whoAmI)
                        {
                            if (DEBUG_TRACKER)
                            {
                                Main.NewText("Clash! [" + npc.whoAmI + "] " + npc.GivenOrTypeName + " over " + tracked.GivenOrTypeName);
                            }

                            RemoveTrackedNPC(tracked);
                            break;
                        }
                    }
                }

                if (Config.HealthBarFXShake)
                {
                    // Not got it
                    if (TrackedNPCs.ContainsKey(npc) && !TrackedNPCOldLife.ContainsKey(npc))
                    {
                        TrackedNPCOldLife.Add(npc, 0);
                    }
                    // Shouldn't have it
                    else if (!TrackedNPCs.ContainsKey(npc) && TrackedNPCOldLife.ContainsKey(npc))
                    {
                        TrackedNPCOldLife.Remove(npc);
                    }
                }

                if (Config.HealthBarFXChip)
                {
                    // Not got it
                    if (TrackedNPCs.ContainsKey(npc) && !TrackedNPCChipLife.ContainsKey(npc))
                    {
                        TrackedNPCChipLife.Add(npc, 0);
                        TrackedNPCChipTime.Add(npc, 0);
                    }
                    // Shouldn't have it
                    else if (!TrackedNPCs.ContainsKey(npc) && TrackedNPCChipLife.ContainsKey(npc))
                    {
                        TrackedNPCChipLife.Remove(npc);
                        TrackedNPCChipTime.Remove(npc);
                    }
                }
            }

            // Sort the timers
            foreach (NPC tracked in TrackedNPCs.Keys.ToList())
            {
                bool      disableFadeIn = false, disableFadeOut = false;
                HealthBar hb;
                if (BossDisplayInfo.NPCHealthBars.TryGetValue(tracked.type, out hb))
                {
                    disableFadeIn  = hb.DisableFadeInFor(tracked.type);
                    disableFadeOut = hb.DisableFadeOutFor(tracked.type);
                }
                // FADE IN
                if (TrackedNPCs[tracked] > 0)
                {
                    // Fade to 0
                    TrackedNPCs[tracked]--;

                    if (disableFadeIn) // No fade in, immediate
                    {
                        TrackedNPCs[tracked] = 0;
                    }
                }
                // FADE OUT
                else if (TrackedNPCs[tracked] <= -1)
                {
                    if (TrackedNPCs[tracked] == -1 ||
                        disableFadeOut) // No fade out, immediate
                    {
                        // If reached -1, delete
                        TrackedNPCs.Remove(tracked);
                    }
                    else
                    {
                        // otherwise count UP to -1
                        TrackedNPCs[tracked]++;
                    }
                }
            }
        }