Advertisement
RNNCode

SimulacrumsAlertIcon

Oct 31st, 2020 (edited)
1,187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.79 KB | None | 0 0
  1. using Turbo.Plugins.Default;
  2. using System;
  3. using System.Linq;
  4. using System.Threading;
  5.  
  6. namespace Turbo.Plugins.RNN
  7. {
  8.     public class SimulacrumsAlertIcon : BasePlugin, IInGameTopPainter, ICustomizer
  9.     {
  10.         private SharpDX.DirectWrite.TextLayout layout { get; set; } = null;
  11.         private MapTextureDecorator SimulacrumMapTexture { get; set; }
  12.  
  13.         private IBrush SimulacrumBrushDefault { get; set; } = null;
  14.         private IBrush SimulacrumBrushMe { get; set; }
  15.         private IBrush SimulacrumBrushOther { get; set; }
  16.         private ITexture SimulacrumTexture { get; set; } = null;
  17.         private ITexture SimulacrumTextureMe { get; set; }
  18.         private ITexture SimulacrumTextureOther { get; set; }
  19.         private float SizeGroundTexture {get; set; }
  20.         public float SizeGroundTextureMultiplier {get; set; } = 0.45f;
  21.  
  22.         private IFont FontWhite { get; set; }
  23.         private IFont FontStacks0 { get; set; }
  24.         private IFont FontStacks1 { get; set; }
  25.         private IFont SimulacrumFont { get; set; }
  26.  
  27.         private float SizeIcon  { get; set; }
  28.         private bool fixLoad  {get; set; } = true;
  29.         private bool AreAlive { get; set; } = false;
  30.  
  31.         public bool ShowSimulacrums { get; set; }
  32.         public bool OnlyGR { get; set; }
  33.         public bool ShowInTown { get; set; }
  34.         public bool ShowIcon { get; set; }
  35.         public float Xpor  { get; set; }
  36.         public float Ypor  { get; set; }
  37.         public float SizeIconMultiplier {get; set; }
  38.         public float Opacity { get; set; }
  39.         public bool SoundEnabled { get; set; }
  40.         public string FileSound { get; set; }
  41.         public bool HideOnMinimap { get; set; }
  42.         public bool ShowCounterSkillUi { get; set; }
  43.  
  44.         public SimulacrumsAlertIcon()
  45.         {
  46.             Enabled = true;
  47.         }
  48.  
  49.         public override void Load(IController hud)
  50.         {
  51.             base.Load(hud);
  52.             Order = 30001;
  53.  
  54.             OnlyGR = false;             // Show in GreaterRift only
  55.             ShowInTown = false;         // Is independent of the value of OnlyGR. For Testing
  56.             ShowSimulacrums = true;     // Show Simulacrums in Map and Ground
  57.             HideOnMinimap = false;      // Hide or not the simulacrums on the minimap. Will be ignored if ShowSimulacrums = false
  58.             ShowIcon = true;            // Display an icon for your character when the number of Simulacrums is less than 2
  59.             ShowCounterSkillUi = true;
  60.             Xpor = 0.51f;               // To set the x coordinate of the icon
  61.             Ypor = 0.34f;               // To set the y coordinate of the icon
  62.             SizeIconMultiplier = 0.55f; // Size icon Simulacrum
  63.             Opacity = 0.75f;            // 0f..1f  Opacity for icon
  64.             SoundEnabled = false;       // Play sound when you lose all simulacrum
  65.             FileSound = "notification_8.wav";  // File to be played. It must be in the Sounds\ folder
  66.  
  67.             SimulacrumTextureMe = Hud.Texture.GetTexture(124715741);
  68.             SimulacrumTextureOther = Hud.Texture.GetTexture(670858621);
  69.             SimulacrumBrushMe = Hud.Render.CreateBrush(255, 255, 0, 0, 3f);
  70.             SimulacrumBrushOther = Hud.Render.CreateBrush(255, 0, 255, 0, 3f);
  71.             SimulacrumFont = Hud.Render.CreateFont("tahoma", 8, 220, 0, 255, 0, false, false, true);
  72.  
  73.             SimulacrumMapTexture = new MapTextureDecorator(Hud)
  74.             {
  75.                 Texture = SimulacrumTextureOther,
  76.                 Radius = 0.35f,
  77.                 RadiusTransformator = new StandardPingRadiusTransformator(Hud, 700) {  RadiusMinimumMultiplier = 0.75f, }
  78.             };
  79.         }
  80.  
  81.         public void Customize()
  82.         {
  83.             FontWhite = Hud.Render.CreateFont("tahoma", 11f * SizeIconMultiplier, 255, 255, 255, 255, true, false, 255, 0, 0, 0, true);
  84.             FontStacks0 = Hud.Render.CreateFont("tahoma", 11f * SizeIconMultiplier, 255, 255, 0, 0, true, false, 255, 0, 0, 0, true);
  85.             FontStacks1 = Hud.Render.CreateFont("tahoma", 11f * SizeIconMultiplier, 255, 255, 255, 0, true, false, 255, 0, 0, 0, true);
  86.         }
  87.  
  88.         public void Play_Sound(string Sonido)
  89.         {
  90.             var playSonido = Hud.Sound.LoadSoundPlayer(Sonido);
  91.             ThreadPool.QueueUserWorkItem(state =>
  92.             {
  93.                 try  { playSonido.PlaySync(); }
  94.                 catch (Exception)  {   }
  95.             }   );
  96.         }
  97.  
  98.         public void DrawIcon(float x, float y, float width, float height, IPlayerSkill skill, int num = 0)
  99.         {
  100.             Hud.Texture.GetTexture(skill.SnoPower.NormalIconTextureId).Draw(x, y, width, height, Opacity);
  101.             Hud.Texture.BuffFrameTexture.Draw(x, y, width, height, Opacity);
  102.             if (skill.CooldownFinishTick > Hud.Game.CurrentGameTick)
  103.             {
  104.                 double remaining = (skill.CooldownFinishTick - Hud.Game.CurrentGameTick) / 60.0d;
  105.                 layout = FontWhite.GetTextLayout( remaining.ToString((remaining < 1)? "F1":"F0") );
  106.             }
  107.             else { layout = FontWhite.GetTextLayout("✔️"); }
  108.             FontWhite.DrawText(layout, x + ((width - (float)Math.Ceiling(layout.Metrics.Width))/4.0f), y + ((height - (float)Math.Ceiling(layout.Metrics.Height))/6.0f));
  109.             layout = FontStacks0.GetTextLayout(num.ToString());
  110.             (num==0?FontStacks0:FontStacks1).DrawText(layout, x + ((SizeIcon - (float)Math.Ceiling(layout.Metrics.Width))/1.15f), y + ((SizeIcon - (float)Math.Ceiling(layout.Metrics.Height))/1.15f));
  111.         }
  112.  
  113.         public void PaintTopInGame(ClipState clipState)
  114.         {
  115.             if (clipState != ClipState.BeforeClip) return;
  116.             if (!Hud.Game.IsInGame) return;
  117.             if (Hud.Game.Me.IsInTown)
  118.             {
  119.                 if (!ShowInTown) return;
  120.             }
  121.             else if (OnlyGR && (Hud.Game.Me.InGreaterRiftRank == 0))  return;
  122.  
  123.             if (fixLoad)
  124.             {
  125.                 SizeGroundTexture = SimulacrumTextureOther.Width * Hud.Window.Size.Height/1200.0f * SizeGroundTextureMultiplier;
  126.                 SizeIcon = Hud.Texture.BuffFrameTexture.Width   * Hud.Window.Size.Height/1200.0f * SizeIconMultiplier;
  127.                 fixLoad = false;
  128.             }
  129.  
  130.             var n = 0;
  131.             var actors = Hud.Game.Actors.Where(a => a.SnoActor.Sno == ActorSnoEnum._p6_necro_simulacrum_a || a.SnoActor.Sno == ActorSnoEnum._p6_necro_simulacrum_a_set ); // 467053 , 484304
  132.             if (ShowSimulacrums)
  133.             {
  134.                 foreach (var actor in actors)
  135.                 {
  136.                     if (actor.SummonerAcdDynamicId == Hud.Game.Me.SummonerId)
  137.                     {
  138.                         n++;
  139.                         SimulacrumTexture = SimulacrumTextureMe; SimulacrumBrushDefault = SimulacrumBrushMe;
  140.                     }
  141.                     else
  142.                     {
  143.                         SimulacrumTexture = SimulacrumTextureOther; SimulacrumBrushDefault = SimulacrumBrushOther;
  144.                     }
  145.                     SimulacrumBrushDefault.DrawWorldEllipse(0.80f, -1, actor.FloorCoordinate); // Ground Circle
  146.                     SimulacrumTexture.Draw(actor.FloorCoordinate.ToScreenCoordinate().X - SizeGroundTexture/2, actor.FloorCoordinate.ToScreenCoordinate().Y - SizeGroundTexture/2, SizeGroundTexture, SizeGroundTexture, 1f); // Ground texture
  147.                     if (!HideOnMinimap)
  148.                     {
  149.                         SimulacrumMapTexture.Texture = SimulacrumTexture;
  150.                         SimulacrumMapTexture.Paint(actor, actor.FloorCoordinate, string.Empty); // Map texture
  151.                     }
  152.                 }
  153.             }
  154.             else { n = actors.Where(a => a.SummonerAcdDynamicId == Hud.Game.Me.SummonerId).Count(); }
  155.  
  156.             IPlayerSkill skill = Hud.Game.Me.Powers.UsedNecromancerPowers.Simulacrum;  // 465350 - Simulacrum
  157.             if (skill != null)
  158.             {
  159.                 if (ShowCounterSkillUi)
  160.                 {
  161.                     var ui = Hud.Render.GetPlayerSkillUiElement(skill.Key);
  162.                     if (ui != null) SimulacrumFont.DrawText(SimulacrumFont.GetTextLayout(n.ToString()), ui.Rectangle.X + 7, ui.Rectangle.Y + 3);
  163.                 }
  164.                 if (Hud.Game.Me.Powers.BuffIsActive(484309))    // Amuleto
  165.                 {
  166.                     var i = ((skill.Rune == 3) || Hud.Game.Me.Powers.BuffIsActive(484301)) ? 2 : 1; // New Set Necromancer , bonus 2 items
  167.                     if (n == i)
  168.                     {
  169.                         if (!AreAlive)  { AreAlive = true; }
  170.                     }
  171.                     else if (n < i)
  172.                     {
  173.                         if (ShowIcon) DrawIcon(Hud.Window.Size.Width * Xpor, Hud.Window.Size.Height * Ypor, SizeIcon, SizeIcon, skill, n);
  174.                         if (AreAlive)
  175.                         {
  176.                             if (!Hud.Game.Me.Powers.BuffIsActive(465350))
  177.                             {
  178.                                 AreAlive = false;
  179.                                 if (SoundEnabled && !Hud.Game.Me.IsInTown) Play_Sound(FileSound);
  180.                             }
  181.                         }
  182.                     }
  183.                     else // (n > i) , no debería llegar nunca aquí , añadido por precaución
  184.                     {
  185.                         if (ShowIcon) DrawIcon(Hud.Window.Size.Width * Xpor, Hud.Window.Size.Height * Ypor, SizeIcon, SizeIcon, skill, n);
  186.                         if (!AreAlive)  { AreAlive = true; }
  187.                     }
  188.                 }
  189.             }
  190.         }
  191.     }
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement