Advertisement
jarppaaja

MyMonsterColoringV2

Mar 30th, 2019
945
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 27.73 KB | None | 0 0
  1. // MyMonsterColoringV2.cs "$Revision: 2341 $" "$Date: 2019-06-22 11:45:04 +0300 (la, 22 kesä 2019) $"
  2. // https://www.ownedcore.com/forums/diablo-3/turbohud/turbohud-community-plugins/782208-v9-minimal-plugin-theme.html
  3. // https://pastebin.com/KfrUAThF
  4. using SharpDX;
  5. using SharpDX.Direct2D1;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using Turbo.Plugins.Default;
  10.  
  11. namespace Turbo.Plugins.User
  12. {
  13.     public class MyMonsterColoringV2 : BasePlugin, ICustomizer, IInGameTopPainter, IInGameWorldPainter
  14.     {
  15.         public double RiftProgressionRange { get; set; } = 50;              // Calculate rift pprogression from monsters inside this range.
  16.  
  17.         public float GreenThreshold { get; set; } = 2.50f;                  // 33% of rift orb value limit for "green" monsters.
  18.         public float BlueThreshold { get; set; } = 3.75f;                   // 50% of rift orb value limit for "blue" monsters.
  19.  
  20.         // Monster decorators by type.
  21.         public WorldDecoratorCollection EliteDecorator { get; set; }        // Supports GroundLabelDecorator (elite names).
  22.         public WorldDecoratorCollection EliteMinionDecorator { get; set; }  // Supports GroundLabelDecorator (minion names).
  23.         public WorldDecoratorCollection BlueDecorator { get; set; }
  24.         public WorldDecoratorCollection GreenDecorator { get; set; }
  25.         public WorldDecoratorCollection GreyDecorator { get; set; }
  26.         public bool HideOnIllusions { get; set; } = true;
  27.  
  28.         // Monster health formats.
  29.         public string HealthFormat1 { get; set; } = "{0:0.00}";             // Less than 1.0 % remaining
  30.         public string HealthFormat2 { get; set; } = "{0:0}";                // No decimals when health > 1.0 %
  31.  
  32.         // Optional coloring methods are controlled by helper class.
  33.         public ColoringHelper Helper { get; set; }
  34.  
  35.         public MyMonsterColoringV2() { Enabled = true; Order = 500; }
  36.  
  37.         private GroundCircleDecorator EliteCircle1 = null;
  38.         private GroundCircleDecorator EliteCircle2 = null;
  39.         private GroundLabelDecorator EliteLabel = null;
  40.  
  41.         public void Customize()
  42.         {
  43.             Hud.RunOnPlugin<MonsterRiftProgressionColoringPlugin>(plugin =>
  44.             {
  45.                 plugin.Enabled = false;
  46.             });
  47.             Hud.RunOnPlugin<StandardMonsterPlugin>(plugin =>
  48.             {
  49.                 plugin.Enabled = false;
  50.             });
  51.         }
  52.  
  53.         public override void Load(IController hud)
  54.         {
  55.             base.Load(hud);
  56.  
  57.             Helper = new ColoringHelper(Hud);
  58.  
  59.             var ShadowBrush = Hud.Render.CreateBrush(96, 0, 0, 0, 1);
  60.  
  61.             EliteDecorator = new WorldDecoratorCollection(
  62.                 new MapShapeDecorator(Hud)
  63.                 {
  64.                     ShapePainter = new CircleShapePainter(Hud),
  65.                     Brush = Hud.Render.CreateBrush(255, 255, 200, 100, 2),  // Yellow circle
  66.                     ShadowBrush = ShadowBrush,
  67.                     Radius = 4f,
  68.                 });
  69.             EliteMinionDecorator = new WorldDecoratorCollection(
  70.                 new MapShapeDecorator(Hud)
  71.                 {
  72.                     ShapePainter = new CircleShapePainter(Hud),
  73.                     Brush = Hud.Render.CreateBrush(255, 255, 255, 255, 2),  // White circle
  74.                     ShadowBrush = ShadowBrush,
  75.                     Radius = 4f,
  76.                 });
  77.             BlueDecorator = new WorldDecoratorCollection(
  78.                 new MapShapeDecorator(Hud)
  79.                 {
  80.                     ShapePainter = new CircleShapePainter(Hud),
  81.                     Brush = Hud.Render.CreateBrush(255, 60, 128, 255, 3),   // Dodger blue circle
  82.                     ShadowBrush = ShadowBrush,
  83.                     Radius = 3.5f,
  84.                 });
  85.             GreenDecorator = new WorldDecoratorCollection(
  86.                 new MapShapeDecorator(Hud)
  87.                 {
  88.                     ShapePainter = new CircleShapePainter(Hud),
  89.                     Brush = Hud.Render.CreateBrush(255, 128, 255, 0, 3),    // Green circle
  90.                     ShadowBrush = ShadowBrush,
  91.                     Radius = 3f,
  92.                 });
  93.             GreyDecorator = new WorldDecoratorCollection(
  94.                 new MapShapeDecorator(Hud)
  95.                 {
  96.                     Brush = Hud.Render.CreateBrush(128, 217, 217, 217, 0),  // Light grey dot for normal trash mobs
  97.                     ShadowBrush = ShadowBrush,
  98.                     ShapePainter = new CircleShapePainter(Hud),
  99.                     Radius = 2.5f,
  100.                 });
  101.         }
  102.  
  103.         public void ShowEliteFootCircles()
  104.         {
  105.             EliteCircle1 = new GroundCircleDecorator(Hud)
  106.             {
  107.                 Brush = Hud.Render.CreateBrush(255, 255, 0, 255, 2.5f),     // Violet circle for elite hitbox
  108.                 Radius = -1,
  109.                 HasShadow = false,
  110.             };
  111.             EliteCircle2 = new GroundCircleDecorator(Hud)
  112.             {
  113.                 Brush = Hud.Render.CreateBrush(255, 255, 255, 255, 1f),     // White larger circle for elite hitbox "highlight"
  114.                 HasShadow = false,
  115.             };
  116.             EliteLabel = new GroundLabelDecorator(Hud)
  117.             {
  118.                 BackgroundBrush = Hud.Render.CreateBrush(255, 220, 120, 240, 0),
  119.                 TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, true, false, 220, 32, 32, 32, true),
  120.             };
  121.             if (EliteDecorator != null)
  122.             {
  123.                 EliteDecorator.Add(EliteCircle1);
  124.                 EliteDecorator.Add(EliteCircle2);
  125.                 EliteDecorator.Add(EliteLabel);
  126.             }
  127.             if (EliteMinionDecorator != null)
  128.             {
  129.                 EliteMinionDecorator.Add(
  130.                 new GroundCircleDecorator(Hud)
  131.                 {
  132.                     Brush = Hud.Render.CreateBrush(255, 255, 0, 255, 2f, DashStyle.Dash),   // Violet dashed circle for minion hitbox
  133.                     Radius = -1,    // Show monster hitbox
  134.                 });
  135.             }
  136.         }
  137.  
  138.         public void PaintTopInGame(ClipState clipState)
  139.         {
  140.             if (clipState != ClipState.BeforeClip) return;
  141.             if (Hud.Game.IsInTown) return;
  142.             if ((Hud.Game.MapMode == MapMode.WaypointMap) || (Hud.Game.MapMode == MapMode.ActMap) || (Hud.Game.MapMode == MapMode.Map)) return;
  143.             if (Helper != null)
  144.             {
  145.                 Helper.PaintTopInGame();
  146.             }
  147.         }
  148.  
  149.         public void PaintWorld(WorldLayer layer)
  150.         {
  151.             if (Hud.Game.IsInTown) return;
  152.             if ((Hud.Game.MapMode == MapMode.WaypointMap) || (Hud.Game.MapMode == MapMode.ActMap) || (Hud.Game.MapMode == MapMode.Map)) return;
  153.  
  154.             var inRift = Hud.Game.SpecialArea == SpecialArea.Rift || Hud.Game.SpecialArea == SpecialArea.GreaterRift;
  155.             foreach (var monster in Hud.Game.AliveMonsters)
  156.             {
  157.                 if (monster.IsElite)    // Elites are drawn always
  158.                 {
  159.                     if (HideOnIllusions &&
  160.                         (monster.SummonerAcdDynamicId != 0) &&
  161.                         ((monster.Rarity == ActorRarity.RareMinion) || (monster.Rarity == ActorRarity.Rare) || (monster.Rarity == ActorRarity.Champion)))
  162.                     {
  163.                         continue;   // Skip illusionist copies!
  164.                     }
  165.                     if (monster.Rarity == ActorRarity.RareMinion && EliteMinionDecorator != null)
  166.                     {
  167.                         EliteMinionDecorator.Paint(layer, monster, monster.FloorCoordinate, monster.SnoMonster.NameLocalized);
  168.                     }
  169.                     else
  170.                     {
  171.                         if (EliteCircle1 != null)
  172.                         {
  173.                             var radius = Math.Min(monster.RadiusBottom, 20);
  174.                             EliteCircle2.Radius = radius + 0.1f;
  175.                             var health = monster.CurHealth / monster.MaxHealth * 100d;
  176.                             var label = health < 1 ? string.Format(HealthFormat1, health) : string.Format(HealthFormat2, health);
  177.                             EliteLabel.Enabled = monster.IsOnScreen;    // Show label only for visible monsters.
  178.                             EliteDecorator.Paint(layer, monster, monster.FloorCoordinate, label);
  179.                         }
  180.                         else
  181.                         {
  182.                             EliteDecorator.Paint(layer, monster, monster.FloorCoordinate, monster.SnoMonster.NameLocalized);
  183.                         }
  184.                     }
  185.                     continue;
  186.                 }
  187.                 if (inRift)
  188.                 {
  189.                     var progression = monster.SnoMonster.RiftProgression;
  190.                     if (progression > 0 && monster.NormalizedXyDistanceToMe < RiftProgressionRange)
  191.                     {
  192.                         if (progression < GreenThreshold)
  193.                         {
  194.                             GreyDecorator.Paint(layer, monster, monster.FloorCoordinate, null);     // Trash.
  195.                         }
  196.                         else if (progression < BlueThreshold)
  197.                         {
  198.                             GreenDecorator.Paint(layer, monster, monster.FloorCoordinate, null);    // Some value (green).
  199.                         }
  200.                         else
  201.                         {
  202.                             BlueDecorator.Paint(layer, monster, monster.FloorCoordinate, null);     // Rest is best (blue).
  203.                         }
  204.                         continue;
  205.                     }
  206.                 }
  207.                 // Draw all other mobs we can see.
  208.                 GreyDecorator.Paint(layer, monster, monster.FloorCoordinate, null);
  209.             }
  210.             if (Helper != null)
  211.             {
  212.                 var monsters = Hud.Game.AliveMonsters.Where(x => x.SnoMonster.RiftProgression > 0 || x.IsElite);
  213.                 Helper.PaintWorld(layer, monsters);
  214.             }
  215.         }
  216.     }
  217.  
  218.     public class ColoringHelper
  219.     {
  220.         // Special decorators.
  221.         public WorldDecoratorCollection BossDecorator { get; set; }         // Draws 50 yard circle around boss.
  222.         public WorldDecoratorCollection PlayerDecorator { get; set; }       // Draws player hitbox to show where player is during boss/elite fights.
  223.         public WorldDecoratorCollection InnerKillDecorator { get; set; }    // Near monsters decorator.
  224.         public WorldDecoratorCollection OuterKillDecorator { get; set; }    // Far monsters decorator.
  225.         public int ProgressionMarkerCooldownFrames { get; set; } = 60;      // One second delay before dots go off.
  226.  
  227.         public WorldDecoratorCollection PercentProgressRadiusDecorator { get; set; }    // Draw circle around player when this percent rift progress inside it.
  228.         public double PercentProgressRadiusPercentLimit { get; set; } = 2;
  229.         public double PercentProgressRadiusMinRadius { get; set; } = 20;    // For close comabat minimum radius.
  230.         public double PercentProgressRadiusMaxRadius { get; set; } = 200;   // Ignore progress if radius is larger than this.
  231.  
  232.         public bool IsProgressionLabelEnabled { get; set; } = true;         // Show rift progression percent (label).
  233.         public float ProgressionLabelLimit { get; set; } = 1.00f;           // Rift pprogression label percent limit to include in calculations.
  234.  
  235.         public bool ShowKillDensityOnMinimap { get; set; } = true;          // Show rift progression density on minimap for trash mobs to kill them.
  236.         public double KillDensityRangeNear { get; set; } = 50;              // Near rift progression density calculation outer limit.
  237.         public double KillDensityRangeFar { get; set; } = 100;              // Far rift progression density calculation outer limit.
  238.         public float KillDensityLimitNear { get; set; } = 2.00f;            // Near rift progression density percent limit to include.
  239.         public float KillDensityLimitFar { get; set; } = 1.00f;             // Far rift progression density percent limit to include.
  240.  
  241.         public IFont ProgressionLabelBright { get; set; }                   // Rift pprogression labels and configuration below.
  242.         public IFont ProgressionLabelDim { get; set; }
  243.         public IBrush BackgroundBrush { get; set; }                         // BackgroundBrush for the label is it overlaps with other data.
  244.         public bool ProgressionLabelRightAligned { get; set; } = false;     // Right-align text relative to X coordinate.
  245.         public bool ProgressionLabelOnMinimap { get; set; } = false;        // Postion label relative to minimap X coordinate.
  246.         public float XRatioTop { get; set; } = 0.250f;                      // Label X offset relative to screen (or minimap).
  247.         public float YRatioTop { get; set; } = 0.025f;                      // Label Y offset relative to screen (always).
  248.  
  249.         public float BossCirleRadius { get; set; } = 50f;
  250.  
  251.         private float labelX => Hud.Window.Size.Width * XRatioTop;          // Default label position calculation functions.
  252.         private float labelY => Hud.Window.Size.Height * YRatioTop;
  253.  
  254.         private readonly IController Hud;
  255.  
  256.         public ColoringHelper(IController hud)
  257.         {
  258.             Hud = hud;
  259.             var textColor = Color.Lime;     // Bright green with black tranparent shadow.
  260.             ProgressionLabelBright = Hud.Render.CreateFont("tahoma", 10, textColor.A, textColor.R, textColor.G, textColor.B, true, false, 160, 0, 0, 0, true);
  261.             textColor = Color.Green;        // Dim green with black tranparent shadow.
  262.             ProgressionLabelDim = Hud.Render.CreateFont("tahoma", 10, textColor.A, textColor.R, textColor.G, textColor.B, true, false, 160, 0, 0, 0, true);
  263.  
  264.             var ShadowBrush = Hud.Render.CreateBrush(96, 0, 0, 0, 1);
  265.  
  266.             BossDecorator = new WorldDecoratorCollection(
  267.                 new GroundCircleDecorator(Hud)
  268.                 {
  269.                     Brush = Hud.Render.CreateBrush(255, 192, 96, 0, 1.5f),  // Dim orange circle
  270.                     Radius = BossCirleRadius,
  271.                 });
  272.             PlayerDecorator = new WorldDecoratorCollection(
  273.                 new GroundCircleDecorator(Hud)
  274.                 {
  275.                     Brush = Hud.Render.CreateBrush(255, 153, 204, 255, 3.5f, DashStyle.DashDot),    // Light blue dash-dotted circle
  276.                     Radius = -1,
  277.                 });
  278.             /*InnerKillDecorator = new WorldDecoratorCollection(
  279.                 new MapShapeDecorator(Hud)
  280.                 {
  281.                     Brush = Hud.Render.CreateBrush(128, 255, 51, 153, 0),
  282.                     ShadowBrush = ShadowBrush,
  283.                     ShapePainter = new CircleShapePainter(Hud),
  284.                     Radius = 2.5f,
  285.                 });
  286.             OuterKillDecorator = new WorldDecoratorCollection(
  287.                 new MapShapeDecorator(Hud)
  288.                 {
  289.                     Brush = Hud.Render.CreateBrush(128, 102, 204, 255, 0),
  290.                     ShadowBrush = ShadowBrush,
  291.                     ShapePainter = new CircleShapePainter(Hud),
  292.                     Radius = 2.5f,
  293.                 });*/
  294.             InnerKillDecorator = new WorldDecoratorCollection(
  295.                 new MapShapeDecorator(Hud)
  296.                 {
  297.                     Brush = Hud.Render.CreateBrush(90, 255, 51, 153, 0),   // Background pink-reddish
  298.                     ShadowBrush = ShadowBrush,
  299.                     ShapePainter = new CircleShapePainter(Hud),
  300.                     Radius = 4,
  301.                 }/*,
  302.                 new MapShapeDecorator(Hud)
  303.                 {
  304.                     Brush = Hud.Render.CreateBrush(90, 230, 230, 230, 1.0f),  // With light border
  305.                     ShadowBrush = ShadowBrush,
  306.                     ShapePainter = new CircleShapePainter(Hud),
  307.                     Radius = 5,
  308.                 }*/);
  309.             OuterKillDecorator = new WorldDecoratorCollection(
  310.                 new MapShapeDecorator(Hud)
  311.                 {
  312.                     Brush = Hud.Render.CreateBrush(90, 102, 204, 255, 0),   // Background blueish
  313.                     ShadowBrush = ShadowBrush,
  314.                     ShapePainter = new CircleShapePainter(Hud),
  315.                     Radius = 4,
  316.                 }/*,
  317.                 new MapShapeDecorator(Hud)
  318.                 {
  319.                     Brush = Hud.Render.CreateBrush(90, 230, 230, 230, 1.0f),  // With light border
  320.                     ShadowBrush = ShadowBrush,
  321.                     ShapePainter = new CircleShapePainter(Hud),
  322.                     Radius = 5,
  323.                 }*/);
  324.             PercentProgressRadiusDecorator = new WorldDecoratorCollection(new MapShapeDecorator(Hud)
  325.             {
  326.                 Brush = Hud.Render.CreateBrush(255, 192, 96, 0, 1.5f),  // Dim orange circle
  327.                 ShapePainter = new CircleShapePainter(Hud),
  328.                 Radius = -1,
  329.             });
  330.         }
  331.  
  332.         public void PaintTopInGame()
  333.         {
  334.             var inRift = Hud.Game.SpecialArea == SpecialArea.Rift || Hud.Game.SpecialArea == SpecialArea.GreaterRift;
  335.             if (!inRift) return;
  336.  
  337.             if (IsProgressionLabelEnabled && Hud.Game.CurrentQuestProgress < Hud.Game.MaxQuestProgress)
  338.             {
  339.                 if (progressionNearPercent > 0)
  340.                 {
  341.                     var text = string.Format("Progress {0:0.0}%", progressionNearPercent);
  342.                     if (progressionNearPercent > ProgressionLabelLimit)
  343.                     {
  344.                         if (ProgressionLabelBright != null) drawProgressionText(ProgressionLabelBright, text);
  345.                     }
  346.                     else
  347.                     {
  348.                         if (ProgressionLabelDim != null) drawProgressionText(ProgressionLabelDim, text);
  349.                     }
  350.                 }
  351.             }
  352.         }
  353.  
  354.         private void drawProgressionText(IFont font, string text)
  355.         {
  356.             var layout = font.GetTextLayout(text);
  357.             var x = labelX;
  358.             if (ProgressionLabelOnMinimap)
  359.             {
  360.                 x += Hud.Render.MinimapUiElement?.Rectangle.X ?? 0;
  361.             }
  362.             if (ProgressionLabelRightAligned)
  363.             {
  364.                 x -= layout.Metrics.Width;
  365.             }
  366.             var y = labelY;
  367.             if (BackgroundBrush != null)
  368.             {
  369.                 // We have to inflate this a bit.
  370.                 BackgroundBrush.DrawRectangle(x - 2f, y - 2f, layout.Metrics.Width + 4f, layout.Metrics.Height + 4f);
  371.             }
  372.             font.DrawText(layout, x, y);
  373.         }
  374.  
  375.         private double progressionNearPercent = 0;
  376.         private double progressionFarPercent = 0;
  377.         private int progressionNearCooldown = 0;
  378.         private int progressionFarCooldown = 0;
  379.  
  380.         private double onePercentDecoratorRadius = 0;
  381.  
  382.         public void PaintWorld(WorldLayer layer, IEnumerable<IMonster> monsters)
  383.         {
  384.             var inRift = Hud.Game.SpecialArea == SpecialArea.Rift || Hud.Game.SpecialArea == SpecialArea.GreaterRift;
  385.             if (!inRift)
  386.             {
  387.                 var eliteCount0 = 0;
  388.                 foreach (var monster in monsters)
  389.                 {
  390.                     if (monster.IsElite)    // Elites are drawn always
  391.                     {
  392.                         eliteCount0 += 1;
  393.                         if (monster.SnoMonster.Priority == MonsterPriority.boss && BossDecorator != null)
  394.                         {
  395.                             BossDecorator.Paint(layer, monster, monster.FloorCoordinate, null);
  396.                         }
  397.                         if (eliteCount0 == 1 && PlayerDecorator != null)
  398.                         {
  399.                             PlayerDecorator.Paint(layer, Hud.Game.Me, Hud.Game.Me.FloorCoordinate, null);
  400.                         }
  401.                         continue;
  402.                     }
  403.                 }
  404.                 return;
  405.             }
  406.             float progressionNear = 0;
  407.             float progressionFar = 0;
  408.             double onePercentPercent = 0;
  409.             var hasOnePercent = false;
  410.             double onePercentDistance = 0;
  411.             // Calculate all monsters with progression within range.
  412.             var sorted = monsters.ToList();
  413.             sorted.Sort((a, b) => { return a.NormalizedXyDistanceToMe.CompareTo(b.NormalizedXyDistanceToMe); });
  414.             var currentGameTick = Hud.Game.CurrentGameTick;
  415.             foreach (var monster in sorted)
  416.             {
  417.                 var riftProgression = monster.SnoMonster.RiftProgression;
  418.                 var distance = monster.NormalizedXyDistanceToMe;
  419.                 if (PercentProgressRadiusPercentLimit > 0 && !hasOnePercent && onePercentPercent < PercentProgressRadiusPercentLimit)
  420.                 {
  421.                     onePercentPercent += riftProgression / Hud.Game.MaxQuestProgress * 100d;
  422.                     if (onePercentPercent >= PercentProgressRadiusPercentLimit)
  423.                     {
  424.                         hasOnePercent = true;
  425.                         onePercentDistance = distance;    // Stop radius here, can be negative in close comabat.
  426.                     }
  427.                 }
  428.                 if (distance < KillDensityRangeNear)
  429.                 {
  430.                     progressionNear += riftProgression;
  431.                 }
  432.                 else if (distance < KillDensityRangeFar)
  433.                 {
  434.                     progressionFar += riftProgression;
  435.                 }
  436.             }
  437.             progressionNearPercent = progressionNear / Hud.Game.MaxQuestProgress * 100d;
  438.             progressionFarPercent = progressionFar / Hud.Game.MaxQuestProgress * 100d;
  439.             if (progressionNearPercent > KillDensityLimitNear && ProgressionMarkerCooldownFrames > 0)
  440.             {
  441.                 progressionNearCooldown = currentGameTick + ProgressionMarkerCooldownFrames;
  442.             }
  443.             if (progressionFarPercent > KillDensityLimitFar && ProgressionMarkerCooldownFrames > 0)
  444.             {
  445.                 progressionFarCooldown = currentGameTick + ProgressionMarkerCooldownFrames;
  446.             }
  447.             var eliteCount = 0;
  448.             foreach (var monster in monsters)
  449.             {
  450.                 if (monster.IsElite)    // Elites are drawn always
  451.                 {
  452.                     eliteCount += 1;
  453.                     if (monster.SnoMonster.Priority == MonsterPriority.boss && BossDecorator != null)
  454.                     {
  455.                         BossDecorator.Paint(layer, monster, monster.FloorCoordinate, null);
  456.                     }
  457.                     if (eliteCount == 1 && PlayerDecorator != null)
  458.                     {
  459.                         PlayerDecorator.Paint(layer, Hud.Game.Me, Hud.Game.Me.FloorCoordinate, null);
  460.                     }
  461.                     continue;
  462.                 }
  463.                 var distance = monster.NormalizedXyDistanceToMe;
  464.                 if (distance < KillDensityRangeNear)
  465.                 {
  466.                     if (progressionNearPercent > KillDensityLimitNear || currentGameTick < progressionNearCooldown)
  467.                     {
  468.                         if (InnerKillDecorator != null) InnerKillDecorator.Paint(layer, monster, monster.FloorCoordinate, null);
  469.                     }
  470.                     else if (progressionNearPercent > KillDensityLimitFar || currentGameTick < progressionFarCooldown)
  471.                     {
  472.                         if (OuterKillDecorator != null) OuterKillDecorator.Paint(layer, monster, monster.FloorCoordinate, null);
  473.                     }
  474.                 }
  475.                 else if (distance < KillDensityRangeFar)
  476.                 {
  477.                     if (progressionFarPercent > KillDensityLimitFar || currentGameTick < progressionFarCooldown)
  478.                     {
  479.                         if (OuterKillDecorator != null) OuterKillDecorator.Paint(layer, monster, monster.FloorCoordinate, null);
  480.                     }
  481.                 }
  482.             }
  483.             if (hasOnePercent && PercentProgressRadiusDecorator != null)
  484.             {
  485.                 if (onePercentDistance <= PercentProgressRadiusMaxRadius)
  486.                 {
  487.                     var radius = Math.Max(onePercentDistance, PercentProgressRadiusMinRadius);
  488.                     if (onePercentDecoratorRadius != radius)
  489.                     {
  490.                         onePercentDecoratorRadius = radius;
  491.                         foreach (var d in PercentProgressRadiusDecorator.GetDecorators<MapShapeDecorator>())
  492.                         {
  493.                             d.Radius = (float)radius;
  494.                         }
  495.                     }
  496.                     PercentProgressRadiusDecorator.Paint(layer, Hud.Game.Me, Hud.Game.Me.FloorCoordinate, null);
  497.                 }
  498.             }
  499.         }
  500.     }
  501.  
  502.     /*public class GroundHealthDecorator : IWorldDecorator
  503.     {
  504.         public bool Enabled { get; set; }
  505.         public WorldLayer Layer { get; } = WorldLayer.Ground;
  506.         public IController Hud { get; }
  507.  
  508.         public IBrush BackgroundBrushEmpty { get; set; }
  509.         public IBrush BackgroundBrushFill { get; set; }
  510.  
  511.         public float Radius { get; set; }
  512.  
  513.         public GroundHealthDecorator(IController hud)
  514.         {
  515.             Enabled = true;
  516.             Hud = hud;
  517.         }
  518.  
  519.         public void Paint(IActor actor, IWorldCoordinate coord, string text)
  520.         {
  521.             if (!Enabled) return;
  522.             if (actor == null) return;
  523.             if (!(actor is IMonster monster) || monster.CurHealth == 0)
  524.                 return;
  525.  
  526.             var radius = Radius != -1 ? Radius : Math.Min(monster.RadiusBottom, 20);
  527.             var rad = radius / 1200.0f * Hud.Window.Size.Height;
  528.             var max = 100d;
  529.             var elapsed = monster.CurHealth / monster.MaxHealth * 100d;
  530.             if (elapsed < 0) return;
  531.             if (elapsed > max) elapsed = max;
  532.  
  533.             var screenCoord = coord.ToScreenCoordinate();
  534.             var startAngle = Convert.ToInt32(360 / max * elapsed) - 90;
  535.             var endAngle = 360 - 90;
  536.  
  537.             using (var pg = Hud.Render.CreateGeometry())
  538.             {
  539.                 using (var gs = pg.Open())
  540.                 {
  541.                     gs.BeginFigure(new Vector2(screenCoord.X, screenCoord.Y), FigureBegin.Filled);
  542.                     for (var angle = startAngle; angle <= endAngle; angle++)
  543.                     {
  544.                         var mx = rad * (float)Math.Cos(angle * Math.PI / 180.0f);
  545.                         var my = rad * (float)Math.Sin(angle * Math.PI / 180.0f);
  546.                         var vector = new Vector2(screenCoord.X + mx, screenCoord.Y + my);
  547.                         gs.AddLine(vector);
  548.                     }
  549.  
  550.                     gs.EndFigure(FigureEnd.Closed);
  551.                     gs.Close();
  552.                 }
  553.  
  554.                 BackgroundBrushFill.DrawGeometry(pg);
  555.             }
  556.  
  557.             using (var pg = Hud.Render.CreateGeometry())
  558.             {
  559.                 using (var gs = pg.Open())
  560.                 {
  561.                     gs.BeginFigure(new Vector2(screenCoord.X, screenCoord.Y), FigureBegin.Filled);
  562.                     for (var angle = endAngle; angle <= startAngle + 360; angle++)
  563.                     {
  564.                         var mx = rad * (float)Math.Cos(angle * Math.PI / 180.0f);
  565.                         var my = rad * (float)Math.Sin(angle * Math.PI / 180.0f);
  566.                         var vector = new Vector2(screenCoord.X + mx, screenCoord.Y + my);
  567.                         gs.AddLine(vector);
  568.                     }
  569.  
  570.                     gs.EndFigure(FigureEnd.Closed);
  571.                     gs.Close();
  572.                 }
  573.  
  574.                 BackgroundBrushEmpty.DrawGeometry(pg);
  575.             }
  576.         }
  577.  
  578.         public IEnumerable<ITransparent> GetTransparents()
  579.         {
  580.             yield return BackgroundBrushEmpty;
  581.             yield return BackgroundBrushFill;
  582.         }
  583.     }*/
  584. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement