Advertisement
jarppaaja

MyMonsterColoring

Mar 24th, 2019
811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 15.47 KB | None | 0 0
  1. // MyMonsterColoring.cs "$Revision: 1531 $" "$Date: 2019-03-29 16:54:25 +0200 (pe, 29 maalis 2019) $"
  2. using SharpDX;
  3. using SharpDX.Direct2D1;
  4. using System.Linq;
  5. using Turbo.Plugins.Default;
  6.  
  7. namespace Turbo.Plugins.User
  8. {
  9.     // See: https://www.ownedcore.com/forums/diablo-3/turbohud/turbohud-community-plugins/782208-v9-minimal-plugin-theme.html
  10.     //      https://pastebin.com/MFRAU43k
  11.  
  12.     public class MyMonsterColoring : BasePlugin, ICustomizer, IInGameTopPainter, IInGameWorldPainter
  13.     {
  14.         public float TrashBreakpoint { get; set; } = 2.50f;                 // 33% of rift orb value breakpoint.
  15.         public float KillBreakpoint { get; set; } = 3.75f;                  // 50% of rift orb value breakpoint.
  16.  
  17.         // Monster decorators by type.
  18.         public WorldDecoratorCollection EliteDecorator { get; set; }        // Supports GroundLabelDecorator, other decorators do not!
  19.         public WorldDecoratorCollection EliteMinionDecorator { get; set; }  // Supports GroundLabelDecorator, other decorators do not!
  20.         public WorldDecoratorCollection BlueDecorator { get; set; }
  21.         public WorldDecoratorCollection GreenDecorator { get; set; }
  22.         public WorldDecoratorCollection GreyDecorator { get; set; }
  23.  
  24.         // Special decorators.
  25.         public WorldDecoratorCollection BossDecorator { get; set; }         // Draws 50 yard circle around boss.
  26.         public WorldDecoratorCollection PlayerDecorator { get; set; }       // Draws player hitbox to show where player is during boss/elite fights.
  27.         public WorldDecoratorCollection KillDecorator { get; set; }         // All monsters that award rift progression when RiftProgressionEnabled
  28.  
  29.         public bool IsRiftProgressionEnabled { get; set; } = true;          // Show rift progression percent (label).
  30.         public float RiftProgressionLimit { get; set; } = 1.15f;            // Rift pprogression percent limit to include in calculations.
  31.         public double RiftProgressionRange { get; set; } = 50;              // Calculate rift pprogression from monsters inside this range.
  32.  
  33.         public bool ShowKillDensityOnMinimap { get; set; } = true;          // Show rift progression density on minimap for trash mobs to kill them.
  34.         public float KillDensityLimit { get; set; } = 1.15f;                // Rift pprogression percent limit to include
  35.  
  36.         public IFont ProgressionLabelBright { get; set; }                   // Rift pprogression labels and configuration below.
  37.         public IFont ProgressionLabelDim { get; set; }
  38.         public IBrush BackgroundBrush { get; set; }                         // BackgroundBrush for the label is it overlaps with other data.
  39.         public bool ProgressionLabelRightAligned { get; set; } = false;     // Right-align text relative to X coordinate.
  40.         public bool ProgressionLabelOnMinimap { get; set; } = false;        // Postion label relative to minimap X coordinate.
  41.         public float XRatioTop { get; set; } = 0.250f;                      // Label X offset relative to screen (or minimap).
  42.         public float YRatioTop { get; set; } = 0.025f;                      // Label Y offset relative to screen (always).
  43.  
  44.         public int RiftProgressionCooldown { get; set; } = 60;              // Ticks until KillDecorator disappers to smooth KillDecorator work.
  45.         public float BossCirleRadius { get; set; } = 50f;
  46.  
  47.         float labelX => Hud.Window.Size.Width * XRatioTop;                  // Default label position calculation functions.
  48.         float labelY => Hud.Window.Size.Height * YRatioTop;
  49.  
  50.         public MyMonsterColoring() { Enabled = true; Order = 500; }
  51.  
  52.         public override void Load(IController hud)
  53.         {
  54.             base.Load(hud);
  55.  
  56.             var textColor = Color.Lime;     // Bright green with black tranparent shadow.
  57.             ProgressionLabelBright = Hud.Render.CreateFont("tahoma", 10, textColor.A, textColor.R, textColor.G, textColor.B, true, false, 160, 0, 0, 0, true);
  58.             textColor = Color.Green;        // Dim green with black tranparent shadow.
  59.             ProgressionLabelDim = Hud.Render.CreateFont("tahoma", 10, textColor.A, textColor.R, textColor.G, textColor.B, true, false, 160, 0, 0, 0, true);
  60.  
  61.             var ShadowBrush = Hud.Render.CreateBrush(96, 0, 0, 0, 1);
  62.  
  63.             BossDecorator = new WorldDecoratorCollection(
  64.                 new GroundCircleDecorator(Hud)
  65.                 {
  66.                     Brush = Hud.Render.CreateBrush(255, 192, 96, 0, 1.5f),  // Dim orange circle
  67.                     Radius = BossCirleRadius,
  68.                 }
  69.                 );
  70.             PlayerDecorator = new WorldDecoratorCollection(
  71.                 new GroundCircleDecorator(Hud)
  72.                 {
  73.                     Brush = Hud.Render.CreateBrush(255, 153, 204, 255, 3.5f, DashStyle.DashDot),    // Light blue dash-dotted circle
  74.                     Radius = -1,
  75.                 }
  76.                 );
  77.             KillDecorator = new WorldDecoratorCollection(                   // This is fancy!
  78.                 new MapShapeDecorator(Hud)
  79.                 {
  80.                     Brush = Hud.Render.CreateBrush(60, 102, 204, 255, 0),   // Background blueish
  81.                     ShadowBrush = ShadowBrush,
  82.                     ShapePainter = new CircleShapePainter(Hud),
  83.                     Radius = 4,
  84.                 },
  85.                 new MapShapeDecorator(Hud)
  86.                 {
  87.                     Brush = Hud.Render.CreateBrush(90, 0, 102, 255, 1.0f),  // With border
  88.                     ShadowBrush = ShadowBrush,
  89.                     ShapePainter = new CircleShapePainter(Hud),
  90.                     Radius = 5,
  91.                 }
  92.                 );
  93.             EliteDecorator = new WorldDecoratorCollection(
  94.                 new MapShapeDecorator(Hud)
  95.                 {
  96.                     ShapePainter = new CircleShapePainter(Hud),
  97.                     Brush = Hud.Render.CreateBrush(255, 255, 200, 100, 2),  // Dim yellow circle
  98.                     ShadowBrush = ShadowBrush,
  99.                     Radius = 4f,
  100.                 },
  101.                 new GroundCircleDecorator(Hud)
  102.                 {
  103.                     Brush = Hud.Render.CreateBrush(255, 255, 0, 255, 2f),   // Violet circle for monster hitbox
  104.                     Radius = -1,    // Show monster hitbox
  105.                 }
  106.                 );
  107.             EliteMinionDecorator = new WorldDecoratorCollection(
  108.                 new MapShapeDecorator(Hud)
  109.                 {
  110.                     ShapePainter = new CircleShapePainter(Hud),
  111.                     Brush = Hud.Render.CreateBrush(255, 255, 255, 255, 2),  // White circle
  112.                     ShadowBrush = ShadowBrush,
  113.                     Radius = 4f,
  114.                 },
  115.                 new GroundCircleDecorator(Hud)
  116.                 {
  117.                     Brush = Hud.Render.CreateBrush(255, 255, 0, 255, 2f, DashStyle.Dash),   // Violet dashed circle for monster hitbox
  118.                     Radius = -1,    // Show monster hitbox
  119.                 }
  120.                 );
  121.             BlueDecorator = new WorldDecoratorCollection(
  122.                 new MapShapeDecorator(Hud)
  123.                 {
  124.                     ShapePainter = new CircleShapePainter(Hud),
  125.                     Brush = Hud.Render.CreateBrush(255, 60, 128, 255, 3),   // Dodger blue circle
  126.                     ShadowBrush = ShadowBrush,
  127.                     Radius = 3.5f,
  128.                 }
  129.                 );
  130.             GreenDecorator = new WorldDecoratorCollection(
  131.                 new MapShapeDecorator(Hud)
  132.                 {
  133.                     ShapePainter = new CircleShapePainter(Hud),
  134.                     Brush = Hud.Render.CreateBrush(255, 128, 255, 0, 3),    // Green circle
  135.                     ShadowBrush = ShadowBrush,
  136.                     Radius = 3f,
  137.                 }
  138.                 );
  139.             GreyDecorator = new WorldDecoratorCollection(
  140.                 new MapShapeDecorator(Hud)
  141.                 {
  142.                     Brush = Hud.Render.CreateBrush(128, 217, 217, 217, 0),  // Light grey dot for normal trash mobs
  143.                     ShadowBrush = ShadowBrush,
  144.                     ShapePainter = new CircleShapePainter(Hud),
  145.                     Radius = 2.5f,
  146.                 }
  147.                 );
  148.         }
  149.  
  150.         public void Customize()
  151.         {
  152.             Hud.RunOnPlugin<MonsterRiftProgressionColoringPlugin>(plugin =>
  153.             {
  154.                 plugin.Enabled = false;
  155.             });
  156.             Hud.RunOnPlugin<StandardMonsterPlugin>(plugin =>
  157.             {
  158.                 plugin.Enabled = false;
  159.             });
  160.         }
  161.  
  162.         public void PaintTopInGame(ClipState clipState)
  163.         {
  164.             if (clipState != ClipState.BeforeClip) return;
  165.             if (Hud.Game.IsInTown) return;
  166.             if ((Hud.Game.MapMode == MapMode.WaypointMap) || (Hud.Game.MapMode == MapMode.ActMap) || (Hud.Game.MapMode == MapMode.Map)) return;
  167.  
  168.             if (IsRiftProgressionEnabled && Hud.Game.CurrentQuestProgress < Hud.Game.MaxQuestProgress)
  169.             {
  170.                 var text = string.Format("Progress {0:0.0}%", progressionPercent);
  171.                 if (ProgressionLabelBright != null && progressionPercent > RiftProgressionLimit)
  172.                 {
  173.                     DrawProgressionText(ProgressionLabelBright, text);
  174.                 }
  175.                 else if (ProgressionLabelDim != null && progressionPercent > 0)
  176.                 {
  177.                     DrawProgressionText(ProgressionLabelDim, text);
  178.                 }
  179.             }
  180.         }
  181.  
  182.         void DrawProgressionText(IFont font, string text)
  183.         {
  184.             var layout = font.GetTextLayout(text);
  185.             float x = labelX;
  186.             if (ProgressionLabelOnMinimap)
  187.             {
  188.                 x += Hud.Render.MinimapUiElement?.Rectangle.X ?? 0;
  189.             }
  190.             if (ProgressionLabelRightAligned)
  191.             {
  192.                 x -= layout.Metrics.Width;
  193.             }
  194.             float y = labelY;
  195.             if (BackgroundBrush != null)
  196.             {
  197.                 // We have to inflate this a bit.
  198.                 BackgroundBrush.DrawRectangle(x - 2f, y - 2f, layout.Metrics.Width + 4f, layout.Metrics.Height + 4f);
  199.             }
  200.             font.DrawText(layout, x, y);
  201.         }
  202.  
  203.         bool hasTrashProgression;       // Trash is decorated differently if enouugh progression from trash mobs.
  204.         double progressionPercent;
  205.         int progressionCooldown;
  206.  
  207.         public void PaintWorld(WorldLayer layer)
  208.         {
  209.             if (Hud.Game.IsInTown) return;
  210.             if ((Hud.Game.MapMode == MapMode.WaypointMap) || (Hud.Game.MapMode == MapMode.ActMap) || (Hud.Game.MapMode == MapMode.Map)) return;
  211.  
  212.             bool inRift = Hud.Game.SpecialArea == SpecialArea.Rift || Hud.Game.SpecialArea == SpecialArea.GreaterRift;
  213.             int eliteCount = 0;
  214.             bool isKillDecorator = false;
  215.             if (inRift && (IsRiftProgressionEnabled || ShowKillDensityOnMinimap))
  216.             {
  217.                 // Calculate all monsters with progression within range.
  218.                 float progressionTrash = 0;
  219.                 float progressionGood = 0;
  220.                 foreach (var monster in Hud.Game.AliveMonsters.Where(x => x.SnoMonster.RiftProgression > 0 && x.NormalizedXyDistanceToMe < RiftProgressionRange))
  221.                 {
  222.                     if (monster.SnoMonster.RiftProgression < TrashBreakpoint)
  223.                     {
  224.                         progressionTrash += monster.SnoMonster.RiftProgression;
  225.                     }
  226.                     else
  227.                     {
  228.                         progressionGood += monster.SnoMonster.RiftProgression;
  229.                     }
  230.                 }
  231.                 progressionPercent = (progressionTrash + progressionGood) / Hud.Game.MaxQuestProgress * 100d;
  232.                 if (ShowKillDensityOnMinimap)
  233.                 {
  234.                     var progressionTrashPercent = progressionTrash / Hud.Game.MaxQuestProgress * 100d;
  235.                     if (progressionTrashPercent > KillDensityLimit)
  236.                     {
  237.                         isKillDecorator = true;
  238.                         hasTrashProgression = true;
  239.                         progressionCooldown = Hud.Game.CurrentGameTick + RiftProgressionCooldown;
  240.                     }
  241.                     else if (hasTrashProgression)
  242.                     {
  243.                         if (progressionCooldown > Hud.Game.CurrentGameTick)
  244.                         {
  245.                             isKillDecorator = true;
  246.                         }
  247.                         else
  248.                         {
  249.                             hasTrashProgression = false;
  250.                         }
  251.                     }
  252.                 }
  253.             }
  254.             else if (progressionPercent > 0)
  255.             {
  256.                 progressionPercent = 0;
  257.             }
  258.             foreach (var monster in Hud.Game.AliveMonsters)
  259.             {
  260.                 if (monster.IsElite)    // Elites are drawn always
  261.                 {
  262.                     eliteCount += 1;
  263.                     if (monster.Rarity == ActorRarity.RareMinion && EliteMinionDecorator != null)
  264.                     {
  265.                         EliteMinionDecorator.Paint(layer, monster, monster.FloorCoordinate, monster.SnoMonster.NameLocalized);
  266.                     }
  267.                     else
  268.                     {
  269.                         EliteDecorator.Paint(layer, monster, monster.FloorCoordinate, monster.SnoMonster.NameLocalized);
  270.                     }
  271.                     if (monster.SnoMonster.Priority == MonsterPriority.boss && BossDecorator != null)
  272.                     {
  273.                         BossDecorator.Paint(layer, monster, monster.FloorCoordinate, null);
  274.                     }
  275.                     if (eliteCount == 1 && PlayerDecorator != null)
  276.                     {
  277.                         PlayerDecorator.Paint(layer, Hud.Game.Me, Hud.Game.Me.FloorCoordinate, null);
  278.                     }
  279.                 }
  280.                 else if (inRift)        // Rift progression, some mobs far out can be left out from drawing!
  281.                 {
  282.                     if (monster.SnoMonster.RiftProgression > 0 && monster.NormalizedXyDistanceToMe < RiftProgressionRange)
  283.                     {
  284.                         if (monster.SnoMonster.RiftProgression < TrashBreakpoint)
  285.                         {
  286.                             if (isKillDecorator && KillDecorator != null)
  287.                             {
  288.                                 KillDecorator.Paint(layer, monster, monster.FloorCoordinate, null);     // Progression to kill!
  289.                             }
  290.                             else
  291.                             {
  292.                                 GreyDecorator.Paint(layer, monster, monster.FloorCoordinate, null);     // Trash.
  293.                             }
  294.                         }
  295.                         else if (monster.SnoMonster.RiftProgression < KillBreakpoint)
  296.                         {
  297.                             GreenDecorator.Paint(layer, monster, monster.FloorCoordinate, null);        // Some value.
  298.                         }
  299.                         else
  300.                         {
  301.                             BlueDecorator.Paint(layer, monster, monster.FloorCoordinate, null);         // Rest is best.
  302.                         }
  303.                     }
  304.                 }
  305.                 else                    // Draw all mobs we can see.
  306.                 {
  307.                     GreyDecorator.Paint(layer, monster, monster.FloorCoordinate, null);                 // What ever.
  308.                 }
  309.             }
  310.         }
  311.     }
  312. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement