public static void RefreshBuffAt(Player player, int pos) { if (player.noItems) { return; } int buffType = player.buffType[pos]; if (buffType == BuffID.PotionSickness) { player.DelBuff(pos); player.potionDelay = 0; player.QuickHeal(); return; } for (int i = 0; i < player.inventory.Length; i++) { Item item = player.inventory[i]; if (!item.IsAir && item.stack > 0 && item.consumable) { if (item.buffType == buffType) { BetterBuffHelpers.ConsumeItemForBuff(player, item, pos); break; } } } }
//////////////// public void UpdateBuffTimes() { ISet <int> activeBuffTypes = new HashSet <int>(); for (int i = 0; i < this.player.buffType.Length; i++) { int buffType = this.player.buffType[i]; int buffTime = this.player.buffTime[i]; if (buffType <= 0) { continue; } activeBuffTypes.Add(buffType); if (!this.MaxBuffTimes.ContainsKey(buffType)) { this.MaxBuffTimes[buffType] = buffTime; } if (buffTime == 1 && this.BuffLocks.Contains(buffType)) { if (BetterBuffHelpers.CanRefreshBuffAt(this.player, i)) { BetterBuffHelpers.RefreshBuffAt(this.player, i); } } } foreach (int buffType in this.MaxBuffTimes.Keys.ToList()) { if (!activeBuffTypes.Contains(buffType)) { if (this.MaxBuffTimes.ContainsKey(buffType)) { this.MaxBuffTimes.Remove(buffType); } if (this.BuffLocks.Contains(buffType)) { this.BuffLocks.Remove(buffType); } continue; } } }
//////////////// public override void PreUpdate() { this.UpdateBuffTimes(); if (this.player.whoAmI == Main.myPlayer) { if (Main.mouseLeftRelease && Main.mouseLeft) { if (!this.IsLeftClickAndRelease && !Main.playerInventory) { var mouse = new Rectangle(Main.mouseX, Main.mouseY, 1, 1); foreach (var kv in BetterBuffHelpers.GetBuffIconRectanglesByPosition(true)) { int pos = kv.Key; if (kv.Value.Intersects(mouse)) { if (!BetterBuffHelpers.CanRefreshBuffAt(this.player, pos)) { continue; } if (this.player.controlTorch) { this.ToggleBuffLock(pos); } else if (this.player.buffType[pos] != BuffID.PotionSickness) { BetterBuffHelpers.RefreshBuffAt(this.player, pos); } break; } } } this.IsLeftClickAndRelease = true; } else { this.IsLeftClickAndRelease = false; } } }
public static IDictionary <int, Rectangle> GetBuffIconRectanglesByPosition(bool applyInterfaceScaling) { var rects = new Dictionary <int, Rectangle>(); var player = Main.LocalPlayer; int dim = 32; Vector2 screenOffset = Vector2.Zero; if (applyInterfaceScaling) { var worldFrame = BetterBuffHelpers.GetWorldFrameOfScreen(); screenOffset.X = worldFrame.X - Main.screenPosition.X; screenOffset.Y = worldFrame.Y - Main.screenPosition.Y; } //if( scaleType == InterfaceScaleType.UI ) { //if( scaleType == InterfaceScaleType.Game ) { if (applyInterfaceScaling) { dim = (int)(((float)dim * Main.UIScale) / Main.GameZoomTarget); } for (int i = 0; i < player.buffType.Length; i++) { if (player.buffType[i] <= 0) { continue; } int x = 32 + ((i % 11) * 38); int y = 76 + (50 * (i / 11)); //if( scaleType == InterfaceScaleType.UI ) { //if( scaleType == InterfaceScaleType.Game ) { if (applyInterfaceScaling) { x = (int)((((float)x * Main.UIScale) / Main.GameZoomTarget) + screenOffset.X); y = (int)((((float)y * Main.UIScale) / Main.GameZoomTarget) + screenOffset.Y); } rects[i] = new Rectangle(x, y, dim, dim); } return(rects); }
//////////////// public override void ModifyInterfaceLayers(List <GameInterfaceLayer> layers) { int idx = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Inventory")); if (idx != -1) { var interfaceLayer = new LegacyGameInterfaceLayer("BetterBuffDisplays: Buff Overlay", delegate { if (Main.playerInventory) { return(true); } Player player = Main.LocalPlayer; var modplayer = player.GetModPlayer <BetterBuffsPlayer>(); foreach (var kv in BetterBuffHelpers.GetBuffIconRectanglesByPosition(false)) { int pos = kv.Key; Rectangle rect = kv.Value; int buffType = player.buffType[pos]; int buffTime = player.buffTime[pos]; this.DrawShadow(player, rect, buffType, buffTime); if (modplayer.BuffLocks.Contains(buffType)) { this.DrawLock(player, rect, buffType, buffTime); } } return(true); }, InterfaceScaleType.UI); layers.Insert(idx, interfaceLayer); } }