public bool TryTracking(int npcIndex) { if (npcIndex < 0 || npcIndex > 200) { return(false); } NPC npc = Main.npc[npcIndex]; if (!npc.active) { return(false); } BigProgressBarInfo info = new BigProgressBarInfo() { npcIndexToAimAt = npcIndex }; IBigProgressBar bigProgressBar1 = (IBigProgressBar)this._bossBar; IBigProgressBar bigProgressBar2; if (this._bossBarsByNpcNetId.TryGetValue(npc.netID, out bigProgressBar2)) { bigProgressBar1 = bigProgressBar2; } if (!bigProgressBar1.ValidateAndCollectNecessaryInfo(ref info)) { return(false); } this._currentBar = bigProgressBar1; this._info = info; return(true); }
public bool TryTracking(int npcIndex) { if (npcIndex < 0 || npcIndex > 200) { return(false); } NPC nPC = Main.npc[npcIndex]; if (!nPC.active) { return(false); } BigProgressBarInfo bigProgressBarInfo = default(BigProgressBarInfo); bigProgressBarInfo.npcIndexToAimAt = npcIndex; BigProgressBarInfo info = bigProgressBarInfo; IBigProgressBar bigProgressBar = _bossBar; if (_bossBarsByNpcNetId.TryGetValue(nPC.netID, out var value)) { bigProgressBar = value; } if (!bigProgressBar.ValidateAndCollectNecessaryInfo(info)) { return(false); } _currentBar = bigProgressBar; _info = info; return(true); }
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); } }
public void Update() { if (_currentBar == null) { TryFindingNPCToTrack(); } if (_currentBar != null && !_currentBar.ValidateAndCollectNecessaryInfo(_info)) { _currentBar = null; } }
public void Update() { if (this._currentBar == null) { this.TryFindingNPCToTrack(); } if (this._currentBar == null || this._currentBar.ValidateAndCollectNecessaryInfo(ref this._info)) { return; } this._currentBar = (IBigProgressBar)null; }
/// <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) { }
/// <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) { }
//If any mods need to fetch special vanilla bars /// <summary> /// Gets the special IBigProgressBar associated with this vanilla NPCs netID (usually the type). /// <para> Reminder: If no special bar exists or NPC.BossBar is not assigned, any NPC with a boss head index will automatically display a common boss bar shared among all simple bosses.</para> /// </summary> /// <param name="netID">The NPC netID (usually the type)</param> /// <param name="bossBar">When this method returns, contains the IBigProgressBar associated with the specified NPC netID</param> /// <returns><see langword="true"/> if IBigProgressBar exists; otherwise, <see langword="false"/>.</returns> public bool TryGetSpecialVanillaBossBar(int netID, out IBigProgressBar bossBar) => _bossBarsByNpcNetId.TryGetValue(netID, out bossBar);