Advertisement
s4000

DAV_GRPylonPlugin

Sep 27th, 2019
1,664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.56 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Globalization;
  4. using System.Collections.Generic;
  5. using Turbo.Plugins.Default;
  6.  
  7. namespace Turbo.Plugins.DAV
  8. {
  9.     public class DAV_GRPylonPlugin : BasePlugin, IInGameWorldPainter, INewAreaHandler {
  10.         public IFont Font_Used { get; set; }
  11.         public IFont Font_SameLvl { get; set; }
  12.         public IFont Font_DiffLvl { get; set; }
  13.         public DAV_PylonInfo[] grPylon { get; set; } = new DAV_PylonInfo[5];
  14.         public double pylonChanceLow { get; set; } = 30d;
  15.         public double pylonChanceHigh { get; set; } = 60d;
  16.         public WorldDecoratorCollection PossiblePylonDecorator_low { get; set; }
  17.         public WorldDecoratorCollection PossiblePylonDecorator_middle { get; set; }
  18.         public WorldDecoratorCollection PossiblePylonDecorator_high { get; set; }
  19.         public string PossiblePylonMessage { get; set; } = "pylon? ";
  20.         public string message_percent { get; set; } = "Last Pylon";
  21.         public string message_pylonChance { get; set; } = "Chance";
  22.         public string replaceArea_from { get; set; } = "Rift Level";
  23.         public string replaceArea_to { get; set; } = "Floor";
  24.         public Func<double, double> CalcPylon { get; set; }
  25.  
  26.         private bool inGR { get; set; } = false;
  27.         private int PylonNum { get; set; } = 0;
  28.         private double preProgress { get; set; } = 0;
  29.         public float offsetX { get; set; }
  30.  
  31.         public DAV_GRPylonPlugin() {
  32.             Enabled = true;
  33.         }
  34.  
  35.         public override void Load(IController hud) {
  36.             base.Load(hud);
  37.  
  38.             offsetX = Hud.Window.Size.Height * 35 / 1080;
  39.             Font_Used = Hud.Render.CreateFont("arial", 7, 255, 170, 170, 170, false, false, 160, 0, 0, 0, true);
  40.             Font_SameLvl = Hud.Render.CreateFont("arial", 7, 255, 250, 150, 250, false, false, 160, 0, 0, 0, true);
  41.             Font_DiffLvl = Hud.Render.CreateFont("arial", 7, 255, 255, 51, 51, false, false, 160, 0, 0, 0, true);
  42.  
  43.             CalcPylon = (progress) => {
  44.                 var pylonChance = 98d;
  45.                 if (progress < 30d)
  46.                     pylonChance = 1d + Math.Pow(0.2d * progress + 1d, 2d);
  47.                 else if (progress < 60d)
  48.                     pylonChance = 99d - Math.Pow(0.2d * progress - 13d, 2d);
  49.  
  50.                 return pylonChance;
  51.             };
  52.  
  53.             grPylon[0] = new DAV_PylonInfo("Power", Hud.Texture.GetTexture(2350065673), Hud.Sno.SnoPowers.Generic_PagesBuffDamage.Sno); // Power
  54.             grPylon[1] = new DAV_PylonInfo("Speed", Hud.Texture.GetTexture(1927801803), Hud.Sno.SnoPowers.Generic_PagesBuffRunSpeed.Sno); // Speed
  55.             grPylon[2] = new DAV_PylonInfo("Sheild", Hud.Texture.GetTexture(455040081) , Hud.Sno.SnoPowers.Generic_PagesBuffInvulnerable.Sno); // Shield
  56.             grPylon[3] = new DAV_PylonInfo("Channel", Hud.Texture.GetTexture(3254056115), Hud.Sno.SnoPowers.Generic_PagesBuffInfiniteCasting.Sno); // Channeling
  57.             grPylon[4] = new DAV_PylonInfo("Condit", Hud.Texture.GetTexture(1751750314), Hud.Sno.SnoPowers.Generic_PagesBuffElectrifiedTieredRift.Sno); // Condit
  58.  
  59.             PossiblePylonDecorator_low = new WorldDecoratorCollection(
  60.                 new MapShapeDecorator(Hud) {
  61.                     Brush = Hud.Render.CreateBrush(192, 255, 55, 55, 3),
  62.                     ShadowBrush = Hud.Render.CreateBrush(96, 0, 0, 0, 1),
  63.                     Radius = 5.0f,
  64.                     ShapePainter = new CircleShapePainter(Hud),
  65.                 },
  66.                 new MapLabelDecorator(Hud) {
  67.                     LabelFont = Hud.Render.CreateFont("tahoma", 6f, 192, 255, 55, 55, false, false, 128, 0, 0, 0, true),
  68.                     RadiusOffset = 5.0f,
  69.                 }
  70.             );
  71.  
  72.             PossiblePylonDecorator_middle = new WorldDecoratorCollection(
  73.                 new MapShapeDecorator(Hud) {
  74.                     Brush = Hud.Render.CreateBrush(192, 255, 255, 55, 3),
  75.                     ShadowBrush = Hud.Render.CreateBrush(96, 0, 0, 0, 1),
  76.                     Radius = 5.0f,
  77.                     ShapePainter = new CircleShapePainter(Hud),
  78.                 },
  79.                 new MapLabelDecorator(Hud) {
  80.                     LabelFont = Hud.Render.CreateFont("tahoma", 6f, 192, 255, 255, 55, false, false, 128, 0, 0, 0, true),
  81.                     RadiusOffset = 5.0f,
  82.                 }
  83.             );
  84.  
  85.             PossiblePylonDecorator_high = new WorldDecoratorCollection(
  86.                 new MapShapeDecorator(Hud) {
  87.                     Brush = Hud.Render.CreateBrush(192, 55, 255, 55, 3),
  88.                     ShadowBrush = Hud.Render.CreateBrush(96, 0, 0, 0, 1),
  89.                     Radius = 5.0f,
  90.                     ShapePainter = new CircleShapePainter(Hud),
  91.                 },
  92.                 new MapLabelDecorator(Hud) {
  93.                     LabelFont = Hud.Render.CreateFont("tahoma", 6f, 192, 55, 255, 55, false, false, 128, 0, 0, 0, true),
  94.                     RadiusOffset = 5.0f,
  95.                 }
  96.             );
  97.         }
  98.  
  99.         public void OnNewArea(bool newGame, ISnoArea area) {
  100.             if (newGame)
  101.                 PylonClear();
  102.         }
  103.  
  104.         public void PaintWorld(WorldLayer layer) {
  105.             if (Hud.Game.SpecialArea != SpecialArea.GreaterRift) return;
  106.  
  107.             var percent = Hud.Game.RiftPercentage;
  108.             if (percent <= 0) {
  109.                 if (!inGR) {
  110.                     PylonClear();
  111.                     inGR = true;
  112.                     return;
  113.                 }
  114.             }
  115.             else inGR = false;
  116.  
  117.             var ui = Hud.Render.GreaterRiftBarUiElement;
  118.             if (!ui.Visible) return;
  119.            
  120.             foreach (var actor in Hud.Game.Shrines) {
  121.                 var powerRank = -1;
  122.                 switch (actor.SnoActor.Sno) {
  123.                     case ActorSnoEnum._x1_lr_shrine_damage : powerRank = 0; break;
  124.                     case ActorSnoEnum._x1_lr_shrine_run_speed : powerRank = 1; break;
  125.                     case ActorSnoEnum._x1_lr_shrine_invulnerable : powerRank = 2; break;
  126.                     case ActorSnoEnum._x1_lr_shrine_infinite_casting : powerRank = 3; break;
  127.                     case ActorSnoEnum._x1_lr_shrine_electrified_tieredrift : powerRank = 4; break;
  128.                 }
  129.                 if (powerRank == -1) continue;
  130.  
  131.                 if (actor.IsDisabled || actor.IsOperated) {
  132.                     if (grPylon[powerRank].Used(Hud.Game.Me.SnoArea.NameEnglish, percent, PylonNum, preProgress))
  133.                         PylonAdd(percent);
  134.                 }
  135.                 else if (grPylon[powerRank].Add(Hud.Game.Me.SnoArea.NameEnglish, percent, PylonNum, preProgress))
  136.                     PylonAdd(percent);
  137.             }
  138.  
  139.             for (var i = 0; i < 5; i++) {
  140.                 if (grPylon[i].state == 2) continue;
  141.                 if (Hud.Game.Players.Any(y => y.Powers.BuffIsActive(grPylon[i].sno, 0)))
  142.                     if (grPylon[i].Used(Hud.Game.Me.SnoArea.NameEnglish, percent, PylonNum, preProgress))
  143.                         PylonAdd(percent);
  144.             }
  145.  
  146.             var uiRect = ui.Rectangle;
  147.             for (var j = 0; j < 5; j++) {
  148.                 if (grPylon[j].state == 0) continue;
  149.  
  150.                 var pylonFont = grPylon[j].state == 2 ? Font_Used : (grPylon[j].area == Hud.Game.Me.SnoArea.NameEnglish ? Font_SameLvl : Font_DiffLvl);
  151.                 var layout = pylonFont.GetTextLayout(grPylon[j].getInfo(replaceArea_from, replaceArea_to));
  152.                 var size = layout.Metrics.Height;
  153.                 var yref = uiRect.Bottom + offsetX + grPylon[j].rank*size;
  154.                 grPylon[j].buffIcon.Draw(uiRect.Left, yref, size, size);
  155.                 pylonFont.DrawText(layout, uiRect.Left + 1.5f * size, yref);
  156.  
  157.                 size = uiRect.Height / 2;
  158.                 var xref = uiRect.Left + (float)(grPylon[j].progress1) * uiRect.Width / 100;
  159.                 if (grPylon[j].rank == 1 || grPylon[j].rank == 3)
  160.                     yref = uiRect.Top + size;
  161.                 else yref = uiRect.Top;
  162.                 grPylon[j].buffIcon.Draw(xref, yref, size, size);
  163.             }
  164.  
  165.             if (PylonNum < 4 && percent < 100) {
  166.                 var progressDiff = percent - preProgress;
  167.                 var pylonChance = CalcPylon(progressDiff);
  168.                 var layout = Font_SameLvl.GetTextLayout(message_percent + " : " + progressDiff.ToString("F1") + "% (" + message_pylonChance + " : " + pylonChance.ToString("F1") + "%)");
  169.                 Font_SameLvl.DrawText(layout, uiRect.Left + (uiRect.Width - layout.Metrics.Width) / 2 , uiRect.Bottom + uiRect.Height * 0.2f);
  170.  
  171.                 var PossibleRiftPylonDecorator = pylonChance < pylonChanceLow ? PossiblePylonDecorator_low : (pylonChance < pylonChanceHigh ? PossiblePylonDecorator_middle : PossiblePylonDecorator_high);
  172.                 foreach (var actor in Hud.Game.Actors.Where(x1 => x1.SnoActor.Sno == ActorSnoEnum._markerlocation_tieredriftpylon))
  173.                     PossibleRiftPylonDecorator.Paint(layer, actor, actor.FloorCoordinate, PossiblePylonMessage + pylonChance.ToString("F1") + "%");
  174.             }
  175.         }
  176.  
  177.         public void PylonClear() {
  178.             PylonNum = 0;
  179.             preProgress = 0;
  180.             for (var i = 0; i < 5; i++)
  181.                 grPylon[i].Clear();
  182.         }
  183.  
  184.         public void PylonAdd(double curProgress) {
  185.             PylonNum++;
  186.             preProgress = curProgress;
  187.         }
  188.     }
  189.  
  190.     public class DAV_PylonInfo {
  191.         public string name { get; set; }
  192.         public uint sno { get; set; }
  193.         public int state { get; set; } // 0 no pylon, 1 not used, 2 used
  194.         public int rank { get; set; }
  195.         public string area { get; set; }
  196.         public double progress1 { get; set; }
  197.         public double progress2 { get; set; }
  198.         public ITexture buffIcon { get; set; }
  199.  
  200.         public DAV_PylonInfo(string desc, ITexture Icon, uint actorSno) {
  201.             name = desc;
  202.             sno = actorSno;
  203.             buffIcon = Icon;
  204.             state = 0;
  205.         }
  206.  
  207.         public bool Add(string grLvl, double curProgress, int numPylon, double lastProgress) {
  208.             area = grLvl;
  209.             if (state > 0) return false;
  210.  
  211.             state = 1;
  212.             rank = numPylon;
  213.             progress1 = curProgress;
  214.             progress2 = lastProgress;
  215.             return true;
  216.         }
  217.  
  218.         public bool Used(string grLvl, double curProgress, int numPylon, double lastProgress) {
  219.             if (state == 2) return false;
  220.  
  221.             area = grLvl;
  222.             if (state == 0) {
  223.                 rank = numPylon;
  224.  
  225.                 progress1 = curProgress;
  226.                 progress2 = lastProgress;
  227.                 state = 2;
  228.                 return true;
  229.             }
  230.             state = 2;
  231.             return false;
  232.         }
  233.  
  234.         public void Clear() { state = 0; }
  235.  
  236.         public string getInfo(string A, string B) {
  237.             if (state == 0) return "";
  238.  
  239.             var message = progress1.ToString("F1") + "%\t" + name + "\t" + area.Replace(A, B);;
  240.             if (rank > 0)
  241.                 message += "\t[+" + (progress1 - progress2).ToString("F1") + "%]";
  242.  
  243.             return message;
  244.         }
  245.     }
  246. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement