Advertisement
s4000

DAV_PlayersLifeArcPlugin

Nov 20th, 2019
979
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.75 KB | None | 0 0
  1. using SharpDX;
  2. using SharpDX.Direct2D1;
  3. using System;
  4. using System.Linq;
  5. using System.Globalization;
  6. using System.Collections.Generic;
  7. using Turbo.Plugins.Default;
  8.  
  9. namespace Turbo.Plugins.DAV
  10. {
  11.     public class DAV_PlayersLifeArcPlugin : BasePlugin, IInGameWorldPainter, ICustomizer {
  12.         public Dictionary<HeroClass, DAV_Hero> Decorator_Hero { get; set; }
  13.         public int Arc_Start { get; set; }
  14.         public int Arc_End { get; set; }
  15.  
  16.         private bool[] playerIsMale { get; set; }
  17.         private Dictionary<ActorSnoEnum, bool> heroIsMale { get; set; }
  18.  
  19.         public DAV_PlayersLifeArcPlugin() {
  20.             Enabled = true;
  21.             Order = 2009;
  22.         }
  23.  
  24.         public void PaintWorld(WorldLayer layer) {
  25.             var players = Hud.Game.Players.Where(x => x.CoordinateKnown && Hud.Game.Me.SnoArea.Sno == x.SnoArea.Sno && x.HeadStone == null);
  26.             foreach(var player in players) {
  27.                 if (player.IsOnScreen && player.SnoActor != null)
  28.                     playerIsMale[player.PortraitIndex] = heroIsMale[player.SnoActor.Sno];
  29.  
  30.                 Decorator_Hero[player.HeroClassDefinition.HeroClass].Paint(layer, player, playerIsMale[player.PortraitIndex], Arc_Start, Arc_End);
  31.             }
  32.         }
  33.  
  34.         public override void Load(IController hud) {
  35.             base.Load(hud);
  36.  
  37.             Arc_Start = -45;
  38.             Arc_End = 180;
  39.  
  40.             var stdIconSize = Hud.Window.Size.Height * 30 / 1080;
  41.             var stdMapSize = Hud.Window.Size.Height * 20 / 1080;
  42.             var stdPlayerSize = 3.3f;
  43.             // DAV_Hero(Hud, iconMale, iconFemale, playerArcSize, iconSize, iconSizeMap, r, g, b, bg_r = 255, bg_g = 255, bg_b = 255, LabelOffset = 50)
  44.             Decorator_Hero = new Dictionary<HeroClass, DAV_Hero>();
  45.             Decorator_Hero.Add(HeroClass.Barbarian, new DAV_Hero(Hud, 3921484788, 1030273087, stdPlayerSize, stdIconSize, stdMapSize, 255, 128, 64));
  46.             Decorator_Hero.Add(HeroClass.Crusader, new DAV_Hero(Hud, 3742271755, 3435775766, stdPlayerSize, stdIconSize, stdMapSize, 240, 240, 240, 51, 51, 51));
  47.             Decorator_Hero.Add(HeroClass.Monk, new DAV_Hero(Hud, 2227317895, 2918463890, stdPlayerSize, stdIconSize, stdMapSize, 255, 255, 0, 51, 51, 51));
  48.             Decorator_Hero.Add(HeroClass.DemonHunter, new DAV_Hero(Hud, 3785199803, 2939779782, stdPlayerSize, stdIconSize, stdMapSize, 0, 255, 255, 51, 51, 51));
  49.             Decorator_Hero.Add(HeroClass.Necromancer, new DAV_Hero(Hud, 3285997023, 473831658, stdPlayerSize, stdIconSize, stdMapSize, 0, 190, 190));
  50.             Decorator_Hero.Add(HeroClass.WitchDoctor, new DAV_Hero(Hud, 3925954876, 1603231623, stdPlayerSize, stdIconSize, stdMapSize, 0, 255, 0));
  51.             Decorator_Hero.Add(HeroClass.Wizard, new DAV_Hero(Hud, 44435619, 876580014, stdPlayerSize, stdIconSize, stdMapSize, 255, 0, 255));
  52.  
  53.             playerIsMale = new bool[4] { true, true, true, true };
  54.             heroIsMale = new Dictionary<ActorSnoEnum, bool>() {
  55.                 { ActorSnoEnum._barbarian_male, true }, // Male
  56.                 { ActorSnoEnum._x1_crusader_male, true },
  57.                 { ActorSnoEnum._demonhunter_male, true },
  58.                 { ActorSnoEnum._monk_male, true },
  59.                 { ActorSnoEnum._p6_necro_male, true },
  60.                 { ActorSnoEnum._witchdoctor_male, true },
  61.                 { ActorSnoEnum._wizard_male, true },
  62.                 { ActorSnoEnum._barbarian_female, false }, // Female
  63.                 { ActorSnoEnum._x1_crusader_female, false },
  64.                 { ActorSnoEnum._demonhunter_female, false },
  65.                 { ActorSnoEnum._monk_female, false },
  66.                 { ActorSnoEnum._p6_necro_female, false },
  67.                 { ActorSnoEnum._witchdoctor_female, false },
  68.                 { ActorSnoEnum._wizard_female, false },
  69.             };
  70.         }
  71.  
  72.         public void Customize() {
  73.             Hud.TogglePlugin<OtherPlayersPlugin>(false);
  74.         }
  75.     }
  76.  
  77.     public class DAV_Hero {
  78.         public IController Hud { get; set; }
  79.         public IBrush Brush_BG { get; set; }
  80.         public IBrush Brush_Life { get; set; }
  81.         public IBrush Brush_InnerSan { get; set; }
  82.         public ITexture Hero_male { get; set; }
  83.         public ITexture Hero_female { get; set; }
  84.         public float IconSize { get; set; }
  85.         public float IconSizeMap { get; set; }
  86.         public float LifeArcSize { get; set; }
  87.         public WorldDecoratorCollection HeroDecorator { get; set; }
  88.  
  89.         public DAV_Hero(IController hud, uint iconMale, uint iconFemale, float playerSize, float iconSize, float mapSize, int r, int g, int b, int bg_r = 51, int bg_g = 51, int bg_b = 51, float offset = 60) {
  90.             Hud = hud;
  91.             IconSize = iconSize;
  92.             IconSizeMap = mapSize;
  93.             LifeArcSize = playerSize;
  94.             Hero_male = Hud.Texture.GetTexture(iconMale);
  95.             Hero_female = Hud.Texture.GetTexture(iconFemale);
  96.             Brush_BG = Hud.Render.CreateBrush(255, bg_r, bg_g, bg_b, 5, DashStyle.Solid, CapStyle.Round, CapStyle.Round);
  97.             Brush_Life = Hud.Render.CreateBrush(255, r, g, b, 2, DashStyle.Solid, CapStyle.Round, CapStyle.Round);
  98.             Brush_InnerSan = Hud.Render.CreateBrush(153, r, g, b, 0);
  99.             HeroDecorator = new WorldDecoratorCollection(
  100.                 new GroundLabelDecorator(Hud) {
  101.                     BackgroundBrush = Hud.Render.CreateBrush(255, r, g, b, 0),
  102.                     BorderBrush = Hud.Render.CreateBrush(255, 0, 0, 0, 1),
  103.                     TextFont = Hud.Render.CreateFont("arial", 8f, 255, 0, 0, 0, true, false, 128, 255, 255, 255, true),
  104.                     OffsetY = offset,
  105.                 },
  106.                 new MapLabelDecorator(Hud) {
  107.                     LabelFont = Hud.Render.CreateFont("arial", 7f, 255, r, g, b, false, false, true),
  108.                     Up = false,
  109.                     RadiusOffset = 10
  110.                 }
  111.             );
  112.         }
  113.  
  114.         public void Paint(WorldLayer layer, IPlayer player, bool IsMale, int start, int end) {
  115.             if (!player.IsMe)
  116.                 HeroDecorator.Paint(layer, null, player.FloorCoordinate, player.BattleTagAbovePortrait);
  117.  
  118.             if (player.Powers.BuffIsActive(317076, 1) || player.Powers.BuffIsActive(266254, 0)) {
  119.                 var screenCoord = player.FloorCoordinate.ToScreenCoordinate(true);
  120.                 var size = IconSize * 0.6f;
  121.                 Brush_BG.DrawEllipse(screenCoord.X, screenCoord.Y, size, size, -2);
  122.                 Brush_InnerSan.DrawEllipse(screenCoord.X, screenCoord.Y, size, size);
  123.             }
  124.  
  125.             PaintHeroIcon(player, IsMale);
  126.             PaintLifeArc(player, start, end);
  127.         }
  128.  
  129.         public void PaintHeroIcon(IPlayer player, bool IsMale) {
  130.             var heroIcon = IsMale ? Hero_male : Hero_female;
  131.             if (heroIcon == null) return;
  132.  
  133.             Hud.Render.GetMinimapCoordinates(player.FloorCoordinate.X, player.FloorCoordinate.Y, out var mapX, out var mapY);
  134.             heroIcon.Draw(mapX - IconSizeMap / 2, mapY - IconSizeMap / 2, IconSizeMap, IconSizeMap);
  135.  
  136.             if (player.IsOnScreen) {
  137.                 var screenCoord = player.FloorCoordinate.ToScreenCoordinate(true);
  138.                 heroIcon.Draw(screenCoord.X - IconSize / 2, screenCoord.Y - IconSize / 2, IconSize, IconSize);
  139.             }
  140.         }
  141.  
  142.         public void PaintLifeArc(IPlayer player, int Angle_Start, int Angle_End) {
  143.             if (!player.IsOnScreen) return;
  144.  
  145.             var worldCoord = player.FloorCoordinate;
  146.             var lifeArc = (int)(player.Defense.HealthPct * (Angle_End - Angle_Start) / 100f) + Angle_Start;
  147.  
  148.             using (var pg1 = Hud.Render.CreateGeometry()) {
  149.             using (var pg2 = Hud.Render.CreateGeometry()) {
  150.                 using (var gs1 = pg1.Open()) {
  151.                 using (var gs2 = pg2.Open()) {
  152.                     var mx = LifeArcSize * (float)Math.Cos(Angle_Start * Math.PI / 180f);
  153.                     var my = LifeArcSize * (float)Math.Sin(Angle_Start * Math.PI / 180f);
  154.                     var screenCoord = worldCoord.Offset(mx, my, 0).ToScreenCoordinate(true);
  155.                     var vector = new Vector2(screenCoord.X, screenCoord.Y);
  156.  
  157.                     gs1.BeginFigure(vector, FigureBegin.Filled); // FigureBegin.Filled , FigureBegin.Hollow
  158.                     gs2.BeginFigure(vector, FigureBegin.Filled);
  159.  
  160.                     for (int angle = Angle_Start + 1; angle <= Angle_End; angle++) {
  161.                         mx = LifeArcSize * (float)Math.Cos(angle * Math.PI / 180f);
  162.                         my = LifeArcSize * (float)Math.Sin(angle * Math.PI / 180f);
  163.                         screenCoord = worldCoord.Offset(mx, my, 0).ToScreenCoordinate(true);
  164.                         vector = new Vector2(screenCoord.X, screenCoord.Y);
  165.  
  166.                         gs1.AddLine(vector);
  167.                         if (angle <= lifeArc)
  168.                             gs2.AddLine(vector);
  169.                     }
  170.  
  171.                     gs1.EndFigure(FigureEnd.Open);
  172.                     gs1.Close();
  173.                     gs2.EndFigure(FigureEnd.Open);
  174.                     gs2.Close();
  175.                 }}
  176.  
  177.                 Brush_BG.DrawGeometry(pg1);
  178.                 Brush_Life.DrawGeometry(pg2);
  179.             }}
  180.         }
  181.     }
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement