Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MyMonsterColoringV2.cs "$Revision: 2341 $" "$Date: 2019-06-22 11:45:04 +0300 (la, 22 kesä 2019) $"
- // https://www.ownedcore.com/forums/diablo-3/turbohud/turbohud-community-plugins/782208-v9-minimal-plugin-theme.html
- // https://pastebin.com/KfrUAThF
- using SharpDX;
- using SharpDX.Direct2D1;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Turbo.Plugins.Default;
- namespace Turbo.Plugins.User
- {
- public class MyMonsterColoringV2 : BasePlugin, ICustomizer, IInGameTopPainter, IInGameWorldPainter
- {
- public double RiftProgressionRange { get; set; } = 50; // Calculate rift pprogression from monsters inside this range.
- public float GreenThreshold { get; set; } = 2.50f; // 33% of rift orb value limit for "green" monsters.
- public float BlueThreshold { get; set; } = 3.75f; // 50% of rift orb value limit for "blue" monsters.
- // Monster decorators by type.
- public WorldDecoratorCollection EliteDecorator { get; set; } // Supports GroundLabelDecorator (elite names).
- public WorldDecoratorCollection EliteMinionDecorator { get; set; } // Supports GroundLabelDecorator (minion names).
- public WorldDecoratorCollection BlueDecorator { get; set; }
- public WorldDecoratorCollection GreenDecorator { get; set; }
- public WorldDecoratorCollection GreyDecorator { get; set; }
- public bool HideOnIllusions { get; set; } = true;
- // Monster health formats.
- public string HealthFormat1 { get; set; } = "{0:0.00}"; // Less than 1.0 % remaining
- public string HealthFormat2 { get; set; } = "{0:0}"; // No decimals when health > 1.0 %
- // Optional coloring methods are controlled by helper class.
- public ColoringHelper Helper { get; set; }
- public MyMonsterColoringV2() { Enabled = true; Order = 500; }
- private GroundCircleDecorator EliteCircle1 = null;
- private GroundCircleDecorator EliteCircle2 = null;
- private GroundLabelDecorator EliteLabel = null;
- public void Customize()
- {
- Hud.RunOnPlugin<MonsterRiftProgressionColoringPlugin>(plugin =>
- {
- plugin.Enabled = false;
- });
- Hud.RunOnPlugin<StandardMonsterPlugin>(plugin =>
- {
- plugin.Enabled = false;
- });
- }
- public override void Load(IController hud)
- {
- base.Load(hud);
- Helper = new ColoringHelper(Hud);
- var ShadowBrush = Hud.Render.CreateBrush(96, 0, 0, 0, 1);
- EliteDecorator = new WorldDecoratorCollection(
- new MapShapeDecorator(Hud)
- {
- ShapePainter = new CircleShapePainter(Hud),
- Brush = Hud.Render.CreateBrush(255, 255, 200, 100, 2), // Yellow circle
- ShadowBrush = ShadowBrush,
- Radius = 4f,
- });
- EliteMinionDecorator = new WorldDecoratorCollection(
- new MapShapeDecorator(Hud)
- {
- ShapePainter = new CircleShapePainter(Hud),
- Brush = Hud.Render.CreateBrush(255, 255, 255, 255, 2), // White circle
- ShadowBrush = ShadowBrush,
- Radius = 4f,
- });
- BlueDecorator = new WorldDecoratorCollection(
- new MapShapeDecorator(Hud)
- {
- ShapePainter = new CircleShapePainter(Hud),
- Brush = Hud.Render.CreateBrush(255, 60, 128, 255, 3), // Dodger blue circle
- ShadowBrush = ShadowBrush,
- Radius = 3.5f,
- });
- GreenDecorator = new WorldDecoratorCollection(
- new MapShapeDecorator(Hud)
- {
- ShapePainter = new CircleShapePainter(Hud),
- Brush = Hud.Render.CreateBrush(255, 128, 255, 0, 3), // Green circle
- ShadowBrush = ShadowBrush,
- Radius = 3f,
- });
- GreyDecorator = new WorldDecoratorCollection(
- new MapShapeDecorator(Hud)
- {
- Brush = Hud.Render.CreateBrush(128, 217, 217, 217, 0), // Light grey dot for normal trash mobs
- ShadowBrush = ShadowBrush,
- ShapePainter = new CircleShapePainter(Hud),
- Radius = 2.5f,
- });
- }
- public void ShowEliteFootCircles()
- {
- EliteCircle1 = new GroundCircleDecorator(Hud)
- {
- Brush = Hud.Render.CreateBrush(255, 255, 0, 255, 2.5f), // Violet circle for elite hitbox
- Radius = -1,
- HasShadow = false,
- };
- EliteCircle2 = new GroundCircleDecorator(Hud)
- {
- Brush = Hud.Render.CreateBrush(255, 255, 255, 255, 1f), // White larger circle for elite hitbox "highlight"
- HasShadow = false,
- };
- EliteLabel = new GroundLabelDecorator(Hud)
- {
- BackgroundBrush = Hud.Render.CreateBrush(255, 220, 120, 240, 0),
- TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, true, false, 220, 32, 32, 32, true),
- };
- if (EliteDecorator != null)
- {
- EliteDecorator.Add(EliteCircle1);
- EliteDecorator.Add(EliteCircle2);
- EliteDecorator.Add(EliteLabel);
- }
- if (EliteMinionDecorator != null)
- {
- EliteMinionDecorator.Add(
- new GroundCircleDecorator(Hud)
- {
- Brush = Hud.Render.CreateBrush(255, 255, 0, 255, 2f, DashStyle.Dash), // Violet dashed circle for minion hitbox
- Radius = -1, // Show monster hitbox
- });
- }
- }
- public void PaintTopInGame(ClipState clipState)
- {
- if (clipState != ClipState.BeforeClip) return;
- if (Hud.Game.IsInTown) return;
- if ((Hud.Game.MapMode == MapMode.WaypointMap) || (Hud.Game.MapMode == MapMode.ActMap) || (Hud.Game.MapMode == MapMode.Map)) return;
- if (Helper != null)
- {
- Helper.PaintTopInGame();
- }
- }
- public void PaintWorld(WorldLayer layer)
- {
- if (Hud.Game.IsInTown) return;
- if ((Hud.Game.MapMode == MapMode.WaypointMap) || (Hud.Game.MapMode == MapMode.ActMap) || (Hud.Game.MapMode == MapMode.Map)) return;
- var inRift = Hud.Game.SpecialArea == SpecialArea.Rift || Hud.Game.SpecialArea == SpecialArea.GreaterRift;
- foreach (var monster in Hud.Game.AliveMonsters)
- {
- if (monster.IsElite) // Elites are drawn always
- {
- if (HideOnIllusions &&
- (monster.SummonerAcdDynamicId != 0) &&
- ((monster.Rarity == ActorRarity.RareMinion) || (monster.Rarity == ActorRarity.Rare) || (monster.Rarity == ActorRarity.Champion)))
- {
- continue; // Skip illusionist copies!
- }
- if (monster.Rarity == ActorRarity.RareMinion && EliteMinionDecorator != null)
- {
- EliteMinionDecorator.Paint(layer, monster, monster.FloorCoordinate, monster.SnoMonster.NameLocalized);
- }
- else
- {
- if (EliteCircle1 != null)
- {
- var radius = Math.Min(monster.RadiusBottom, 20);
- EliteCircle2.Radius = radius + 0.1f;
- var health = monster.CurHealth / monster.MaxHealth * 100d;
- var label = health < 1 ? string.Format(HealthFormat1, health) : string.Format(HealthFormat2, health);
- EliteLabel.Enabled = monster.IsOnScreen; // Show label only for visible monsters.
- EliteDecorator.Paint(layer, monster, monster.FloorCoordinate, label);
- }
- else
- {
- EliteDecorator.Paint(layer, monster, monster.FloorCoordinate, monster.SnoMonster.NameLocalized);
- }
- }
- continue;
- }
- if (inRift)
- {
- var progression = monster.SnoMonster.RiftProgression;
- if (progression > 0 && monster.NormalizedXyDistanceToMe < RiftProgressionRange)
- {
- if (progression < GreenThreshold)
- {
- GreyDecorator.Paint(layer, monster, monster.FloorCoordinate, null); // Trash.
- }
- else if (progression < BlueThreshold)
- {
- GreenDecorator.Paint(layer, monster, monster.FloorCoordinate, null); // Some value (green).
- }
- else
- {
- BlueDecorator.Paint(layer, monster, monster.FloorCoordinate, null); // Rest is best (blue).
- }
- continue;
- }
- }
- // Draw all other mobs we can see.
- GreyDecorator.Paint(layer, monster, monster.FloorCoordinate, null);
- }
- if (Helper != null)
- {
- var monsters = Hud.Game.AliveMonsters.Where(x => x.SnoMonster.RiftProgression > 0 || x.IsElite);
- Helper.PaintWorld(layer, monsters);
- }
- }
- }
- public class ColoringHelper
- {
- // Special decorators.
- public WorldDecoratorCollection BossDecorator { get; set; } // Draws 50 yard circle around boss.
- public WorldDecoratorCollection PlayerDecorator { get; set; } // Draws player hitbox to show where player is during boss/elite fights.
- public WorldDecoratorCollection InnerKillDecorator { get; set; } // Near monsters decorator.
- public WorldDecoratorCollection OuterKillDecorator { get; set; } // Far monsters decorator.
- public int ProgressionMarkerCooldownFrames { get; set; } = 60; // One second delay before dots go off.
- public WorldDecoratorCollection PercentProgressRadiusDecorator { get; set; } // Draw circle around player when this percent rift progress inside it.
- public double PercentProgressRadiusPercentLimit { get; set; } = 2;
- public double PercentProgressRadiusMinRadius { get; set; } = 20; // For close comabat minimum radius.
- public double PercentProgressRadiusMaxRadius { get; set; } = 200; // Ignore progress if radius is larger than this.
- public bool IsProgressionLabelEnabled { get; set; } = true; // Show rift progression percent (label).
- public float ProgressionLabelLimit { get; set; } = 1.00f; // Rift pprogression label percent limit to include in calculations.
- public bool ShowKillDensityOnMinimap { get; set; } = true; // Show rift progression density on minimap for trash mobs to kill them.
- public double KillDensityRangeNear { get; set; } = 50; // Near rift progression density calculation outer limit.
- public double KillDensityRangeFar { get; set; } = 100; // Far rift progression density calculation outer limit.
- public float KillDensityLimitNear { get; set; } = 2.00f; // Near rift progression density percent limit to include.
- public float KillDensityLimitFar { get; set; } = 1.00f; // Far rift progression density percent limit to include.
- public IFont ProgressionLabelBright { get; set; } // Rift pprogression labels and configuration below.
- public IFont ProgressionLabelDim { get; set; }
- public IBrush BackgroundBrush { get; set; } // BackgroundBrush for the label is it overlaps with other data.
- public bool ProgressionLabelRightAligned { get; set; } = false; // Right-align text relative to X coordinate.
- public bool ProgressionLabelOnMinimap { get; set; } = false; // Postion label relative to minimap X coordinate.
- public float XRatioTop { get; set; } = 0.250f; // Label X offset relative to screen (or minimap).
- public float YRatioTop { get; set; } = 0.025f; // Label Y offset relative to screen (always).
- public float BossCirleRadius { get; set; } = 50f;
- private float labelX => Hud.Window.Size.Width * XRatioTop; // Default label position calculation functions.
- private float labelY => Hud.Window.Size.Height * YRatioTop;
- private readonly IController Hud;
- public ColoringHelper(IController hud)
- {
- Hud = hud;
- var textColor = Color.Lime; // Bright green with black tranparent shadow.
- ProgressionLabelBright = Hud.Render.CreateFont("tahoma", 10, textColor.A, textColor.R, textColor.G, textColor.B, true, false, 160, 0, 0, 0, true);
- textColor = Color.Green; // Dim green with black tranparent shadow.
- ProgressionLabelDim = Hud.Render.CreateFont("tahoma", 10, textColor.A, textColor.R, textColor.G, textColor.B, true, false, 160, 0, 0, 0, true);
- var ShadowBrush = Hud.Render.CreateBrush(96, 0, 0, 0, 1);
- BossDecorator = new WorldDecoratorCollection(
- new GroundCircleDecorator(Hud)
- {
- Brush = Hud.Render.CreateBrush(255, 192, 96, 0, 1.5f), // Dim orange circle
- Radius = BossCirleRadius,
- });
- PlayerDecorator = new WorldDecoratorCollection(
- new GroundCircleDecorator(Hud)
- {
- Brush = Hud.Render.CreateBrush(255, 153, 204, 255, 3.5f, DashStyle.DashDot), // Light blue dash-dotted circle
- Radius = -1,
- });
- /*InnerKillDecorator = new WorldDecoratorCollection(
- new MapShapeDecorator(Hud)
- {
- Brush = Hud.Render.CreateBrush(128, 255, 51, 153, 0),
- ShadowBrush = ShadowBrush,
- ShapePainter = new CircleShapePainter(Hud),
- Radius = 2.5f,
- });
- OuterKillDecorator = new WorldDecoratorCollection(
- new MapShapeDecorator(Hud)
- {
- Brush = Hud.Render.CreateBrush(128, 102, 204, 255, 0),
- ShadowBrush = ShadowBrush,
- ShapePainter = new CircleShapePainter(Hud),
- Radius = 2.5f,
- });*/
- InnerKillDecorator = new WorldDecoratorCollection(
- new MapShapeDecorator(Hud)
- {
- Brush = Hud.Render.CreateBrush(90, 255, 51, 153, 0), // Background pink-reddish
- ShadowBrush = ShadowBrush,
- ShapePainter = new CircleShapePainter(Hud),
- Radius = 4,
- }/*,
- new MapShapeDecorator(Hud)
- {
- Brush = Hud.Render.CreateBrush(90, 230, 230, 230, 1.0f), // With light border
- ShadowBrush = ShadowBrush,
- ShapePainter = new CircleShapePainter(Hud),
- Radius = 5,
- }*/);
- OuterKillDecorator = new WorldDecoratorCollection(
- new MapShapeDecorator(Hud)
- {
- Brush = Hud.Render.CreateBrush(90, 102, 204, 255, 0), // Background blueish
- ShadowBrush = ShadowBrush,
- ShapePainter = new CircleShapePainter(Hud),
- Radius = 4,
- }/*,
- new MapShapeDecorator(Hud)
- {
- Brush = Hud.Render.CreateBrush(90, 230, 230, 230, 1.0f), // With light border
- ShadowBrush = ShadowBrush,
- ShapePainter = new CircleShapePainter(Hud),
- Radius = 5,
- }*/);
- PercentProgressRadiusDecorator = new WorldDecoratorCollection(new MapShapeDecorator(Hud)
- {
- Brush = Hud.Render.CreateBrush(255, 192, 96, 0, 1.5f), // Dim orange circle
- ShapePainter = new CircleShapePainter(Hud),
- Radius = -1,
- });
- }
- public void PaintTopInGame()
- {
- var inRift = Hud.Game.SpecialArea == SpecialArea.Rift || Hud.Game.SpecialArea == SpecialArea.GreaterRift;
- if (!inRift) return;
- if (IsProgressionLabelEnabled && Hud.Game.CurrentQuestProgress < Hud.Game.MaxQuestProgress)
- {
- if (progressionNearPercent > 0)
- {
- var text = string.Format("Progress {0:0.0}%", progressionNearPercent);
- if (progressionNearPercent > ProgressionLabelLimit)
- {
- if (ProgressionLabelBright != null) drawProgressionText(ProgressionLabelBright, text);
- }
- else
- {
- if (ProgressionLabelDim != null) drawProgressionText(ProgressionLabelDim, text);
- }
- }
- }
- }
- private void drawProgressionText(IFont font, string text)
- {
- var layout = font.GetTextLayout(text);
- var x = labelX;
- if (ProgressionLabelOnMinimap)
- {
- x += Hud.Render.MinimapUiElement?.Rectangle.X ?? 0;
- }
- if (ProgressionLabelRightAligned)
- {
- x -= layout.Metrics.Width;
- }
- var y = labelY;
- if (BackgroundBrush != null)
- {
- // We have to inflate this a bit.
- BackgroundBrush.DrawRectangle(x - 2f, y - 2f, layout.Metrics.Width + 4f, layout.Metrics.Height + 4f);
- }
- font.DrawText(layout, x, y);
- }
- private double progressionNearPercent = 0;
- private double progressionFarPercent = 0;
- private int progressionNearCooldown = 0;
- private int progressionFarCooldown = 0;
- private double onePercentDecoratorRadius = 0;
- public void PaintWorld(WorldLayer layer, IEnumerable<IMonster> monsters)
- {
- var inRift = Hud.Game.SpecialArea == SpecialArea.Rift || Hud.Game.SpecialArea == SpecialArea.GreaterRift;
- if (!inRift)
- {
- var eliteCount0 = 0;
- foreach (var monster in monsters)
- {
- if (monster.IsElite) // Elites are drawn always
- {
- eliteCount0 += 1;
- if (monster.SnoMonster.Priority == MonsterPriority.boss && BossDecorator != null)
- {
- BossDecorator.Paint(layer, monster, monster.FloorCoordinate, null);
- }
- if (eliteCount0 == 1 && PlayerDecorator != null)
- {
- PlayerDecorator.Paint(layer, Hud.Game.Me, Hud.Game.Me.FloorCoordinate, null);
- }
- continue;
- }
- }
- return;
- }
- float progressionNear = 0;
- float progressionFar = 0;
- double onePercentPercent = 0;
- var hasOnePercent = false;
- double onePercentDistance = 0;
- // Calculate all monsters with progression within range.
- var sorted = monsters.ToList();
- sorted.Sort((a, b) => { return a.NormalizedXyDistanceToMe.CompareTo(b.NormalizedXyDistanceToMe); });
- var currentGameTick = Hud.Game.CurrentGameTick;
- foreach (var monster in sorted)
- {
- var riftProgression = monster.SnoMonster.RiftProgression;
- var distance = monster.NormalizedXyDistanceToMe;
- if (PercentProgressRadiusPercentLimit > 0 && !hasOnePercent && onePercentPercent < PercentProgressRadiusPercentLimit)
- {
- onePercentPercent += riftProgression / Hud.Game.MaxQuestProgress * 100d;
- if (onePercentPercent >= PercentProgressRadiusPercentLimit)
- {
- hasOnePercent = true;
- onePercentDistance = distance; // Stop radius here, can be negative in close comabat.
- }
- }
- if (distance < KillDensityRangeNear)
- {
- progressionNear += riftProgression;
- }
- else if (distance < KillDensityRangeFar)
- {
- progressionFar += riftProgression;
- }
- }
- progressionNearPercent = progressionNear / Hud.Game.MaxQuestProgress * 100d;
- progressionFarPercent = progressionFar / Hud.Game.MaxQuestProgress * 100d;
- if (progressionNearPercent > KillDensityLimitNear && ProgressionMarkerCooldownFrames > 0)
- {
- progressionNearCooldown = currentGameTick + ProgressionMarkerCooldownFrames;
- }
- if (progressionFarPercent > KillDensityLimitFar && ProgressionMarkerCooldownFrames > 0)
- {
- progressionFarCooldown = currentGameTick + ProgressionMarkerCooldownFrames;
- }
- var eliteCount = 0;
- foreach (var monster in monsters)
- {
- if (monster.IsElite) // Elites are drawn always
- {
- eliteCount += 1;
- if (monster.SnoMonster.Priority == MonsterPriority.boss && BossDecorator != null)
- {
- BossDecorator.Paint(layer, monster, monster.FloorCoordinate, null);
- }
- if (eliteCount == 1 && PlayerDecorator != null)
- {
- PlayerDecorator.Paint(layer, Hud.Game.Me, Hud.Game.Me.FloorCoordinate, null);
- }
- continue;
- }
- var distance = monster.NormalizedXyDistanceToMe;
- if (distance < KillDensityRangeNear)
- {
- if (progressionNearPercent > KillDensityLimitNear || currentGameTick < progressionNearCooldown)
- {
- if (InnerKillDecorator != null) InnerKillDecorator.Paint(layer, monster, monster.FloorCoordinate, null);
- }
- else if (progressionNearPercent > KillDensityLimitFar || currentGameTick < progressionFarCooldown)
- {
- if (OuterKillDecorator != null) OuterKillDecorator.Paint(layer, monster, monster.FloorCoordinate, null);
- }
- }
- else if (distance < KillDensityRangeFar)
- {
- if (progressionFarPercent > KillDensityLimitFar || currentGameTick < progressionFarCooldown)
- {
- if (OuterKillDecorator != null) OuterKillDecorator.Paint(layer, monster, monster.FloorCoordinate, null);
- }
- }
- }
- if (hasOnePercent && PercentProgressRadiusDecorator != null)
- {
- if (onePercentDistance <= PercentProgressRadiusMaxRadius)
- {
- var radius = Math.Max(onePercentDistance, PercentProgressRadiusMinRadius);
- if (onePercentDecoratorRadius != radius)
- {
- onePercentDecoratorRadius = radius;
- foreach (var d in PercentProgressRadiusDecorator.GetDecorators<MapShapeDecorator>())
- {
- d.Radius = (float)radius;
- }
- }
- PercentProgressRadiusDecorator.Paint(layer, Hud.Game.Me, Hud.Game.Me.FloorCoordinate, null);
- }
- }
- }
- }
- /*public class GroundHealthDecorator : IWorldDecorator
- {
- public bool Enabled { get; set; }
- public WorldLayer Layer { get; } = WorldLayer.Ground;
- public IController Hud { get; }
- public IBrush BackgroundBrushEmpty { get; set; }
- public IBrush BackgroundBrushFill { get; set; }
- public float Radius { get; set; }
- public GroundHealthDecorator(IController hud)
- {
- Enabled = true;
- Hud = hud;
- }
- public void Paint(IActor actor, IWorldCoordinate coord, string text)
- {
- if (!Enabled) return;
- if (actor == null) return;
- if (!(actor is IMonster monster) || monster.CurHealth == 0)
- return;
- var radius = Radius != -1 ? Radius : Math.Min(monster.RadiusBottom, 20);
- var rad = radius / 1200.0f * Hud.Window.Size.Height;
- var max = 100d;
- var elapsed = monster.CurHealth / monster.MaxHealth * 100d;
- if (elapsed < 0) return;
- if (elapsed > max) elapsed = max;
- var screenCoord = coord.ToScreenCoordinate();
- var startAngle = Convert.ToInt32(360 / max * elapsed) - 90;
- var endAngle = 360 - 90;
- using (var pg = Hud.Render.CreateGeometry())
- {
- using (var gs = pg.Open())
- {
- gs.BeginFigure(new Vector2(screenCoord.X, screenCoord.Y), FigureBegin.Filled);
- for (var angle = startAngle; angle <= endAngle; angle++)
- {
- var mx = rad * (float)Math.Cos(angle * Math.PI / 180.0f);
- var my = rad * (float)Math.Sin(angle * Math.PI / 180.0f);
- var vector = new Vector2(screenCoord.X + mx, screenCoord.Y + my);
- gs.AddLine(vector);
- }
- gs.EndFigure(FigureEnd.Closed);
- gs.Close();
- }
- BackgroundBrushFill.DrawGeometry(pg);
- }
- using (var pg = Hud.Render.CreateGeometry())
- {
- using (var gs = pg.Open())
- {
- gs.BeginFigure(new Vector2(screenCoord.X, screenCoord.Y), FigureBegin.Filled);
- for (var angle = endAngle; angle <= startAngle + 360; angle++)
- {
- var mx = rad * (float)Math.Cos(angle * Math.PI / 180.0f);
- var my = rad * (float)Math.Sin(angle * Math.PI / 180.0f);
- var vector = new Vector2(screenCoord.X + mx, screenCoord.Y + my);
- gs.AddLine(vector);
- }
- gs.EndFigure(FigureEnd.Closed);
- gs.Close();
- }
- BackgroundBrushEmpty.DrawGeometry(pg);
- }
- }
- public IEnumerable<ITransparent> GetTransparents()
- {
- yield return BackgroundBrushEmpty;
- yield return BackgroundBrushFill;
- }
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement