RNNCode

SpiritBarrageIcon

Mar 20th, 2020 (edited)
1,717
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.58 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using Turbo.Plugins.Default;
  5.  
  6. namespace Turbo.Plugins.RNN
  7. {
  8.     public class SpiritBarrageIcon : BasePlugin, IInGameTopPainter, ICustomizer, INewAreaHandler
  9.     {
  10.         private Dictionary<uint,int> Phantasms { get;set; } = new Dictionary<uint,int>();
  11.         private int MyIndex { get; set; } = -1;
  12.         private IFont FontCounter { get; set; }
  13.         private IFont FontExpl { get; set; }
  14.         private IFont FontLimit { get; set; }
  15.         private IFont FontDefault { get; set; } = null;
  16.  
  17.         private float SizeIconWidth  { get; set; }
  18.         private float SizeIconHeight  { get; set; }
  19.         public int duration { get; set; } = 10;
  20.         public float warning { get; set; } = 2.0f;
  21.  
  22.         public float Xpor  { get; set; }
  23.         public float Ypor  { get; set; }
  24.         public float SizeMultiplier  { get; set; }
  25.         public float Opacity { get; set; } = 1f;
  26.         public bool OnlyGR { get; set; }
  27.         public bool OnlyMe { get; set; }
  28.  
  29.         public SpiritBarrageIcon()
  30.         {
  31.             Enabled = true;
  32.         }
  33.  
  34.         public override void Load(IController hud)
  35.         {
  36.             base.Load(hud);
  37.             Order = 30002;
  38.  
  39.             Xpor = 0.46f;           // Valid values: from 0 to 1 . To set the x coordinate of the icon
  40.             Ypor = 0.43f;           // Valid values: from 0 to 1 . To set the y coordinate of the icon
  41.             SizeMultiplier = 1f;    // Size multiplier for icons
  42.             Opacity = 0.75f;        // 0..1 Textures
  43.             OnlyGR = false;         // Show in GR only
  44.             OnlyMe = false;         // Ignore phantasm created by others players
  45.             warning = 2.0f;         // 9.0f...0f Text will take the color yellow when it reaches this value
  46.         }
  47.  
  48.         public void Customize()
  49.         {
  50.             FontCounter = Hud.Render.CreateFont("tahoma", 7f * SizeMultiplier, 255, 0, 255, 0, true, false, 160, 0, 0, 0, true);
  51.             FontLimit = Hud.Render.CreateFont("tahoma", 7f * SizeMultiplier, 255, 255, 255, 0, true, false, 160, 0, 0, 0, true);
  52.             FontExpl = Hud.Render.CreateFont("tahoma", 8f * SizeMultiplier, 255, 50, 150, 255, true, false, 160, 0, 0, 0, true);
  53.  
  54.             if ((warning < 0f) || (warning > 9f)) { warning = 2; }
  55.         }
  56.  
  57.  
  58.         public void OnNewArea(bool newGame, ISnoArea area)
  59.         {
  60.             if (newGame || (MyIndex != Hud.Game.Me.Index) )   // Fix partialment the newGame limitation
  61.             {
  62.                 MyIndex = Hud.Game.Me.Index;
  63.                 Phantasms.Clear();
  64.             }
  65.         }
  66.  
  67.  
  68.         public void PaintTopInGame(ClipState clipState)
  69.         {
  70.             if (clipState != ClipState.BeforeClip) return;
  71.             if (!Hud.Game.IsInGame) return;
  72.             if (OnlyGR && !Hud.Game.Me.InGreaterRift) return;
  73.  
  74.             var players = Hud.Game.Players.Where( p => p.HasValidActor && (p.IsMe || !OnlyMe) && p.Powers.UsedSkills.Any(s => s.SnoPower.Sno == 108506 && (s.Rune == 2 || p.Powers.BuffIsActive(484270))) );
  75.             if ( players.Any() )
  76.             {
  77.                 SizeIconWidth = Hud.Texture.BuffFrameTexture.Width  * 0.60f * SizeMultiplier;
  78.                 SizeIconHeight = Hud.Texture.BuffFrameTexture.Height * 0.68f * SizeMultiplier;
  79.                 var actors = Hud.Game.Actors.Where(a => (a.SnoActor.Sno == ActorSnoEnum._wd_spiritbarragerune_aoe_ghostmodel) && ((a.SummonerAcdDynamicId == Hud.Game.Me.SummonerId) || !OnlyMe));
  80.                 var x = Hud.Window.Size.Width * Xpor; var y = Hud.Window.Size.Height * Ypor;
  81.                 Hud.Texture.GetTexture(1117784160).Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);
  82.                 if (actors.Any())
  83.                 {
  84.                     foreach(var a in actors)
  85.                     {
  86.                       if (!Phantasms.ContainsKey(a.AnnId)) { Phantasms[a.AnnId] = a.CreatedAtInGameTick; }
  87.                     }
  88.                     actors = actors.OrderByDescending(a => Phantasms[a.AnnId]);
  89.                     Hud.Texture.BuffFrameTexture.Draw(x, y, SizeIconWidth , SizeIconHeight, Opacity);
  90.                     var c = 0;
  91.                     foreach (var actor in actors)
  92.                     {
  93.                         if (c++ == 3) break;
  94.                         duration  = (players.FirstOrDefault(p => (actor.SummonerAcdDynamicId == p.SummonerId) && p.Powers.BuffIsActive(484270)) != null) ? 10 : 5;
  95.                         var t = duration - (Hud.Game.CurrentGameTick - Phantasms[actor.AnnId]) /  60f;
  96.                         if (t <= 0)
  97.                         {
  98.                             var layout = FontExpl.GetTextLayout("🞴");
  99.                             FontExpl.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), y +(layout.Metrics.Height * 0.53f * (c - 1)) );
  100.                         }
  101.                         else
  102.                         {
  103.                             FontDefault = (t > warning)? FontCounter:FontLimit;
  104.                             var layout = FontDefault.GetTextLayout( (t < 1)? String.Format("{0:N1}",t) : String.Format("{0:0}",(int) (t + 0.90)) ); // Redondeará a X si es menor  a X.10
  105.                             FontDefault.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), y + (layout.Metrics.Height * 0.73f * (c - 1)) );
  106.                         }
  107.                     }
  108.                 }
  109.                 else
  110.                 {
  111.                     Hud.Texture.DebuffFrameTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);
  112.                 }
  113.             }
  114.         }
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment