示例#1
0
        public override bool?ModifyInfo(ref BigProgressBarInfo info, ref float lifePercent, ref float shieldPercent)
        {
            NPC npc = FargoSoulsUtil.NPCExists(info.npcIndexToAimAt);

            if (npc == null || !npc.active)
            {
                return(false);
            }

            bossHeadIndex = npc.GetBossHeadTextureIndex();

            int life    = npc.life;
            int lifeMax = npc.lifeMax;

            bool retval = true;

            if (npc.ModNPC is TrojanSquirrel trojanSquirrel)
            {
                if (trojanSquirrel.head != null)
                {
                    life += trojanSquirrel.head.life;
                }
                if (trojanSquirrel.arms != null)
                {
                    life += trojanSquirrel.arms.life;
                }

                lifeMax += trojanSquirrel.lifeMaxHead;
                lifeMax += trojanSquirrel.lifeMaxArms;
            }
            else if (npc.type == ModContent.NPCType <ShadowChampion>())
            {
                if (npc.ai[0] == -1)
                {
                    shieldPercent = 1;
                }
                else
                {
                    int ballCount      = 0;
                    int untouchedBalls = 0;
                    foreach (NPC n in Main.npc.Where(n => n.active && n.type == ModContent.NPCType <ShadowOrb>() && n.ai[0] == npc.whoAmI))
                    {
                        ballCount++;
                        if (!n.dontTakeDamage)
                        {
                            untouchedBalls++;
                        }
                    }
                    shieldPercent = Utils.Clamp((float)untouchedBalls / ballCount, 0f, 1f);
                }
            }
            else
            {
                retval = false;
            }

            lifePercent = Utils.Clamp((float)life / lifeMax, 0f, 1f);

            return(retval);
        }
示例#2
0
        public static bool PreDraw(SpriteBatch spriteBatch, BigProgressBarInfo info, ref BossBarDrawParams drawParams)
        {
            int index = info.npcIndexToAimAt;

            if (index < 0 || index > Main.maxNPCs)
            {
                return(false);                //Invalid data, abort
            }
            NPC npc = Main.npc[index];

            bool isModded = NpcToBossBar(npc, out ModBossBar bossBar);

            if (isModded)
            {
                drawParams.barTexture = GetTexture(bossBar).Value;
            }

            bool modify = true;

            foreach (GlobalBossBar globalBossBar in globalBossBars)
            {
                modify &= globalBossBar.PreDraw(spriteBatch, npc, ref drawParams);
            }

            if (modify && isModded)
            {
                modify = bossBar.PreDraw(spriteBatch, npc, ref drawParams);
            }

            return(modify);
        }
示例#3
0
        public bool ValidateAndCollectNecessaryInfo(ref BigProgressBarInfo info)
        {
            if (info.npcIndexToAimAt < 0 || info.npcIndexToAimAt > Main.maxNPCs)
            {
                return(false);
            }

            //No GlobalBossBar hook for this as info should not be modified from the outside
            bool?modify = ModifyInfo(ref info, ref lifePercent, ref shieldPercent);

            if (!modify.HasValue)
            {
                NPC npc = Main.npc[info.npcIndexToAimAt];

                if (!npc.active)
                {
                    return(false);
                }

                lifePercent = Utils.Clamp(npc.life / (float)npc.lifeMax, 0f, 1f);

                return(true);
            }
            return(modify.Value);
        }
示例#4
0
        public override bool?ModifyInfo(ref BigProgressBarInfo info, ref float lifePercent, ref float shieldPercent)
        {
            //Here the game wants to know if to draw the boss bar or not. Return false whenever the conditions don't apply.
            //If there is no possibility of returning false (or null) the bar will get drawn at times when it shouldn't, so write defensive code!

            NPC npc = Main.npc[info.npcIndexToAimAt];

            if (!npc.active)
            {
                return(false);
            }

            //We assign bossHeadIndex here because we need to use it in GetIconTexture
            bossHeadIndex = npc.GetBossHeadTextureIndex();

            lifePercent = Utils.Clamp(npc.life / (float)npc.lifeMax, 0f, 1f);

            if (npc.ModNPC is MinionBossBody body)
            {
                //We did all the calculation work on RemainingShields inside the body NPC already so we just have to fetch the value again
                shieldPercent = Utils.Clamp(body.RemainingShields, 0f, 1f);
            }

            return(true);
        }
示例#5
0
        public void Draw(ref BigProgressBarInfo info, SpriteBatch spriteBatch)
        {
            //Questionmark icon as fallback
            Rectangle?iconFrame   = null;
            Texture2D iconTexture = (GetIconTexture(ref iconFrame) ?? TextureAssets.NpcHead[0]).Value;

            iconFrame ??= iconTexture.Frame();

            //TML handles modifying draw parameters inside of it
            BigProgressBarHelper.DrawFancyBar(spriteBatch, lifePercent, iconTexture, iconFrame.Value, shieldPercent);
        }
示例#6
0
        public static void PostDraw(SpriteBatch spriteBatch, BigProgressBarInfo info, BossBarDrawParams drawParams)
        {
            int index = info.npcIndexToAimAt;

            if (index < 0 || index > Main.maxNPCs)
            {
                return;                 //Invalid data, abort
            }
            NPC npc = Main.npc[index];

            if (NpcToBossBar(npc, out ModBossBar bossBar))
            {
                bossBar.PostDraw(spriteBatch, npc, drawParams);
            }

            foreach (GlobalBossBar globalBossBar in globalBossBars)
            {
                globalBossBar.PostDraw(spriteBatch, npc, drawParams);
            }
        }
示例#7
0
 /// <summary>
 /// Runs after draw code for boss bars (skipped if PreventDraw returns true), can be used to draw your own bars, or reinvoke draw for currently selected-to-draw bar
 /// </summary>
 /// <param name="spriteBatch">The spriteBatch that is drawn on</param>
 /// <param name="currentBar">The boss bar that vanilla update code decided to draw. Can be null if skipped or if no suitable NPCs found. Can be casted to ModBossBar</param>
 /// <param name="info">Contains the index of the NPC the game decided to focus on</param>
 public virtual void Draw(SpriteBatch spriteBatch, IBigProgressBar currentBar, BigProgressBarInfo info)
 {
 }
示例#8
0
 /// <summary>
 /// Runs after update code for boss bars (skipped if PreventUpdate returns true), can be used to identify which NPCs to draw.
 /// </summary>
 /// <param name="currentBar">The boss bar that vanilla update code decided to draw. Can be null if skipped or if no suitable NPCs found. Can be casted to ModBossBar</param>
 /// <param name="info">Contains the index of the NPC the game decided to focus on</param>
 public virtual void Update(IBigProgressBar currentBar, ref BigProgressBarInfo info)
 {
 }
示例#9
0
        public override bool PreventDraw => true;         //Prevents the default drawing code

        public override void Draw(SpriteBatch spriteBatch, IBigProgressBar currentBar, BigProgressBarInfo info)
        {
            if (currentBar == null)
            {
                return;
                //Only draw if vanilla decided to draw one (we let it update because we didn't override PreventUpdate to return true)
            }

            if (currentBar is CommonBossBigProgressBar)
            {
                //If this is a regular bar without any special features, we draw our own thing. Sadly, "life to display" is not a variable we can access,
                //but since we are dealing with the very basic implementation that only tracks a single NPC, we can use "info"

                NPC   npc         = Main.npc[info.npcIndexToAimAt];
                float lifePercent = Utils.Clamp(npc.life / (float)npc.lifeMax, 0f, 1f);

                //Unused method by vanilla, which simply draws a few boxes that represent a boss bar (fixed position, colors, no icon)
                BigProgressBarHelper.DrawBareBonesBar(spriteBatch, lifePercent);
            }
            else
            {
                //If a bar with special behavior is currently selected, draw it instead because we don't have access to its special features

                currentBar.Draw(ref info, spriteBatch);
            }
        }
示例#10
0
 /// <summary>
 /// Allows you to handle the logic for when and how this ModBossBar should work. You want to override this if you have a multisegment NPC. Returns null by default. Failing to return false otherwise will lead to your bar being displayed at wrong times.
 /// <para>Return null to let the basic logic run after this hook is called (index validity check and assigning lifePercent to match the health of the NPC) and then allowing it to be drawn.</para>
 /// <para>Return true to allow this ModBossBar to be drawn.</para>
 /// <para>Return false to prevent this ModBossBar from being drawn so that the game will try to pick a different one.</para>
 /// </summary>
 /// <param name="info">Contains the index of the NPC the game decided to focus on</param>
 /// <param name="lifePercent">The % the bar should be filled with</param>
 /// <param name="shieldPercent">The % the bar should be filled with (shield)</param>
 /// <returns><see langword="null"/> for "single-segment" NPC logic, <see langword="true"/> for allowing drawing, <see langword="false"/> for preventing drawing</returns>
 public virtual bool?ModifyInfo(ref BigProgressBarInfo info, ref float lifePercent, ref float shieldPercent) => null;