Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // CheckMissingItems.cs "$Revision: 2578 $" "$Date: 2019-09-05 19:16:59 +0300 (to, 05 syys 2019) $"
- // https://www.ownedcore.com/forums/diablo-3/turbohud/turbohud-community-plugins/791893-intl-jarjar-checkmissingitems.html
- // https://pastebin.com/G66Ar9Xe
- using System.Collections.Generic;
- using System.Linq;
- using Turbo.Plugins.Default;
- namespace Turbo.Plugins.JarJar.DefaultUI
- {
- public class CheckMissingItems : BasePlugin, IInGameTopPainter
- {
- public string Title { get; set; } = "\uD83D\uDC80 Item Check \uD83D\uDC80"; // 💀 skull
- public string Bullet { get; set; } = "\u25CF"; // ● black circle
- public string Note { get; set; } = "\u24BE"; // Ⓘ circled latin capital letter i
- public string GemsWarningZero { get; set; } = "{0} You do not have any active gems equipped";
- public string GemsWarning { get; set; } = "{0} You have only {1} active gem(s) equipped";
- public string BrokenCrownWarning { get; set; } = "{0} Broken Crown is equipped";
- public string FollowerWarning { get; set; } = "{0} Check follower items";
- public bool DoLegacyOfDreamsCheck { get; set; } = true;
- public string LegacyOfDreamsOK { get; set; } = "{0} Legacy Of Dreams is active";
- public string LegacyOfDreamsWarning { get; set; } = "{0} Legacy Of Dreams is NOT ACTIVE";
- public float OffsetX { get; set; } = 0.20f; // Percent-X pos
- public float OffsetY { get; set; } = 0.01f; // Percent-Y pos
- public TopLabelWithTitleDecorator LabelDecorator { get; set; }
- public CheckMissingItems() { Enabled = true; }
- public override void Load(IController hud)
- {
- base.Load(hud);
- LabelDecorator = new TopLabelWithTitleDecorator(Hud)
- {
- BorderBrush = Hud.Render.CreateBrush(255, 230, 30, 30, -1),
- BackgroundBrush = Hud.Render.CreateBrush(190, 0, 0, 0, 0),
- TextFont = Hud.Render.CreateFont("tahoma", 8, 255, 230, 30, 30, false, false, false),
- TitleFont = Hud.Render.CreateFont("tahoma", 10, 255, 255, 0, 0, true, false, false),
- };
- }
- public void PaintTopInGame(ClipState clipState)
- {
- var player = Hud.Game.Me;
- if (player.IsDead || !player.HasValidActor)
- return;
- if (player.CurrentLevelParagon == 0)
- return; // Ignore player without paragon points.
- if (player.CubedItems.Count() == 0)
- return; // Ignore player without cubed items.
- if (Hud.Render.UiHidden)
- return;
- if (clipState != ClipState.BeforeClip)
- return;
- if ((Hud.Game.MapMode == MapMode.WaypointMap) || (Hud.Game.MapMode == MapMode.ActMap) || (Hud.Game.MapMode == MapMode.Map))
- return;
- if (Hud.Inventory.HoveredItem != null)
- return;
- var textLines = new List<string>();
- // Check active gems.
- var activeGems = ActiveGemPrimaryBuffs(player).Count();
- if (activeGems < 3)
- {
- var socketCount = getJewelryWithSockets().Count();
- if (socketCount > activeGems)
- {
- textLines.Add(string.Format(activeGems == 0 ? GemsWarningZero : GemsWarning, Bullet, activeGems));
- if (DoLegacyOfDreamsCheck && Hud.Game.NumberOfPlayersInGame == 1)
- {
- doLegacyOfDreamsCheck(player, textLines);
- }
- }
- }
- if (Hud.Game.NumberOfPlayersInGame == 1)
- {
- // Broken Crown.
- foreach (var item in Hud.Game.Items.Where(x => x.Location == ItemLocation.Head))
- {
- if (item.SnoItem.NameEnglish == "Broken Crown")
- {
- textLines.Add(string.Format(BrokenCrownWarning, Bullet));
- }
- }
- // Follower shield and weapon.
- var followerItems = Hud.Game.Items.Count(x => x.Location == ItemLocation.Unknown1 || x.Location == ItemLocation.Unknown2);
- if (followerItems == 0)
- {
- textLines.Add(string.Format(FollowerWarning, Bullet));
- }
- }
- if (textLines.Count > 0)
- {
- paint(textLines);
- }
- }
- private void doLegacyOfDreamsCheck(IPlayer player, List<string> textLines)
- {
- var ok = 0;
- var warning = 1;
- var result = isLegacyOfDreamsEquipped(player, ok, warning);
- if (result == ok)
- {
- textLines.Add(string.Format(LegacyOfDreamsOK, Note));
- }
- else if (result == warning)
- {
- textLines.Add(string.Format(LegacyOfDreamsWarning, Bullet));
- }
- }
- private int isLegacyOfDreamsEquipped(IPlayer player, int ok, int warning)
- {
- var found = -1;
- var equipped = -1;
- var buff = player.Powers.UsedLegendaryGems.LegacyOfDreamsPrimary;
- if (buff == null)
- {
- if (isLegacyOfDreamsInSocket())
- {
- return warning; // No buff - and is equipped.
- }
- countLegacyOfDreams(out found, out equipped);
- if (equipped > 0)
- {
- return warning; // No buff - and equipped.
- }
- return -1; // No buff - not equipped - ignored!
- }
- if (buff.Active)
- {
- return ok; // Buff is active - must be equipped!
- }
- if (isLegacyOfDreamsInSocket())
- {
- return warning; // Buff is passive - and equipped.
- }
- countLegacyOfDreams(out found, out equipped);
- if (equipped > 0)
- {
- return warning; // Buff is passive - and equipped.
- }
- return -2; // Buff is passive - not equipped - ignored!
- }
- private bool isLegacyOfDreamsInSocket()
- {
- // Check if "Legacy of Dreams" gem is equipped in any jewelry socket - but not 100% reliable!
- foreach (var item in getJewelryWithSockets())
- {
- if (item.ItemsInSocket != null && item.ItemsInSocket.Length == 1 && item.ItemsInSocket[0].SnoItem.NameEnglish == "Legacy of Dreams")
- {
- return true;
- }
- }
- // Not found but this does not mean nothing as it can be equipped or not (due to a bug in THUD reading items in socket)!
- return false;
- }
- private void countLegacyOfDreams(out int found, out int equipped)
- {
- found = 0;
- equipped = 0;
- foreach (var item in Hud.Game.Items.Where(x => x.SnoItem.NameEnglish == "Legacy of Dreams"))
- {
- if (item.Location == ItemLocation.InSocket)
- {
- equipped += 1;
- }
- else
- {
- found += 1;
- }
- }
- }
- private IEnumerable<IItem> getJewelryWithSockets()
- {
- return Hud.Game.Items.Where(x => x.Location >= ItemLocation.LeftRing && x.Location <= ItemLocation.Neck && x.SocketCount > 0);
- }
- private void paint(List<string> lines)
- {
- var w = 0f;
- var margin = 0f;
- foreach (var line in lines)
- {
- var layout = LabelDecorator.TextFont.GetTextLayout(line);
- if (w < layout.Metrics.Width)
- {
- w = layout.Metrics.Width;
- }
- if (margin == 0f)
- {
- margin = layout.Metrics.Height * 2f;
- }
- }
- var text = string.Join("\r\n", lines);
- var h = LabelDecorator.TitleFont.GetTextLayout(Title).Metrics.Height + LabelDecorator.TextFont.GetTextLayout(text).Metrics.Height;
- var x = Hud.Window.Size.Width * OffsetX;
- var y = Hud.Window.Size.Height * OffsetY;
- LabelDecorator.Paint(x, y, w + margin, h + margin, text, Title);
- }
- private static IEnumerable<IBuff> ActiveGemPrimaryBuffs(IPlayer player)
- {
- var gems = player.Powers.UsedLegendaryGems;
- var buffs = new IBuff[]
- {
- gems.BaneOfThePowerfulPrimary,
- gems.BaneOfTheStrickenPrimary,
- gems.BaneOfTheTrappedPrimary,
- gems.BoonOfTheHoarderPrimary,
- gems.BoyarskysChipPrimary,
- gems.EnforcerPrimary,
- gems.EsotericAlterationPrimary,
- //gems.GemOfEasePrimary, // Ignore in this context.
- gems.GemOfEfficaciousToxinPrimary,
- gems.GogokOfSwiftnessPrimary,
- gems.IceblinkPrimary,
- gems.InvigoratingGemstonePrimary,
- gems.LegacyOfDreamsPrimary,
- gems.MoltenWildebeestsGizzardPrimary,
- gems.MoratoriumPrimary,
- gems.MirinaeTeardropOfTheStarweaverPrimary,
- gems.MutilationGuardPrimary,
- gems.PainEnhancerPrimary,
- //gems.RedSoulShardPrimary, // Ignore in this context.
- gems.SimplicitysStrengthPrimary,
- gems.TaegukPrimary,
- gems.WreathOfLightningPrimary,
- gems.ZeisStoneOfVengeancePrimary,
- };
- foreach (var buff in buffs)
- {
- if (buff != null && buff.Active)
- yield return buff;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement