Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Turbo.Plugins.Default;
- using System.Linq;
- using System.Collections.Generic;
- using System.Threading;
- using SharpDX.DirectInput;
- namespace Turbo.Plugins.RNN
- {
- public class PandemoniumIconBuff : BasePlugin, IInGameTopPainter, ICustomizer, INewAreaHandler, IKeyEventHandler
- {
- private IKeyEvent ToogleKeyEventOn { get; set; } // Show/Hide.
- private IKeyEvent ToggleKeyEventCircle { get; set; }
- private MapShapeDecorator YardMapShapeDecorator;
- public bool TurnOffWhenNewGameStarts { get; set; }
- private bool PI_On { get; set; } = true;
- private ITexture TextureBG { get; set; } = null;
- private ITexture TextureRS { get; set; } = null;
- private IFont BuffOtherFont { get; set; }
- private IFont BuffOtherFontMax { get; set; }
- private IFont TimeleftFont { get; set; }
- private IFont StackFont { get; set; }
- private IFont StackFontOther { get; set; }
- private IFont NextFont { get; set; }
- private IFont NextFontY { get; set; }
- private IFont NextFontN { get; set; }
- private IFont MyFont { get; set; } = null;
- private IFont MonsterCounterFont { get; set; }
- private IFont YardFont { get; set; }
- private int MyIndex { get; set; } = -1;
- private bool Buffon { get; set; } = false;
- private int NewTarget { get; set; } = 0;
- private int Kills { get; set; } = 0;
- private int YardsTarget { get; set; } = 0;
- private SortedDictionary<int,string> NextBuff { get; set; } = new SortedDictionary<int,string>
- //private Dictionary<int,string> NextBuff { get; set; } = new Dictionary<int,string>
- {
- {15,"15"}, {30,"30"}, {50,"50"}, {100,"100"}, {150,"150"}, {200,"200"}, {300,"300"}, {400,"400"}, {500,"500"}, {1000,"1000"} , {int.MaxValue,"∞"}
- };
- public float Xpor { get; set; }
- public float Ypor { get; set; }
- private float _SizeMultiplier { get; set; }
- public float SizeMultiplier
- {
- get { return _SizeMultiplier; }
- set
- {
- if (_SizeMultiplier != value)
- {
- _SizeMultiplier = value;
- NextFont = Hud.Render.CreateFont("tahoma", 4.5f * _SizeMultiplier, 255, 225 , 170, 0, true, false, 160, 0, 0, 0, true);
- NextFontY = Hud.Render.CreateFont("tahoma", 4.5f * _SizeMultiplier, 255, 0 , 204, 102, true, false, 160, 0, 0, 0, true);
- NextFontN = Hud.Render.CreateFont("tahoma", 4.5f * _SizeMultiplier, 255, 0 , 150, 0, true, false, 160, 0, 0, 0, true);
- YardFont = Hud.Render.CreateFont("tahoma", 4.5f * _SizeMultiplier, 255, 200 , 200, 200, true, false, 160, 0, 0, 0, true);
- MonsterCounterFont = Hud.Render.CreateFont("tahoma", 4.5f * _SizeMultiplier, 255, 200 , 200, 200, true, false, 160, 0, 0, 0, true);
- TimeleftFont = Hud.Render.CreateFont("tahoma", 6.2f * _SizeMultiplier, 255, 255, 255, 255, true, false, 255, 0, 0, 0, true);
- StackFont = Hud.Render.CreateFont("tahoma", 8f * _SizeMultiplier, 255, 255, 220, 0, true, false, 160, 0, 0, 0, true);
- StackFontOther = Hud.Render.CreateFont("tahoma", 8f * _SizeMultiplier, 255, 255, 150, 0, true, false, 160, 0, 0, 0, true);
- BuffOtherFont = Hud.Render.CreateFont("tahoma", 4f * _SizeMultiplier, 255, 255, 220, 0, true, false, 160, 0, 0, 0, true);
- BuffOtherFontMax = Hud.Render.CreateFont("tahoma", 4f * _SizeMultiplier, 255, 255, 150, 0, true, false, 160, 0, 0, 0, true);
- }
- }
- }
- public bool ShowIcon { get; set; }
- public bool SoundLost { get; set; }
- public bool SoundTarget { get; set; }
- public string FileSoundLost { get; set; }
- public string FileSoundTarget { get; set; }
- public int MinKillsLost { get; set; }
- public int MinTarget { get; set; }
- public int YardsMinTarget { get; set; }
- public int YardsMaxTarget { get; set; }
- public bool ShowCircle { get; set; }
- public bool ShowMonsterCounter { get; set; }
- public bool ShowBuffOthers { get; set; }
- public PandemoniumIconBuff()
- {
- Enabled = true;
- }
- public override void Load(IController hud)
- {
- base.Load(hud);
- Order = 90002;
- Xpor = 0.44f; // Valid values: from 0 to 1 . To set the x coordinate of the icon
- Ypor = 0.45f; // Valid values: from 0 to 1 . To set the y coordinate of the icon
- SizeMultiplier = 1.2f; // Size multiplier for icons
- SoundLost = true; //Notify with a sound when the buff is lost
- SoundTarget = true; //Notify with a sound when a target (15,30,50,100,150,200,300,400,500,1000) was reached
- FileSoundTarget = "PandemoniumTarget.wav"; // File to be played. It must be in the Sounds\ folder
- FileSoundLost = "PandemoniumLost.wav"; // File to be played. It must be in the Sounds\ folder
- MinTarget = 100; // The minimum target where you will begin to notify
- MinKillsLost = 100; // Minimum kills required to notify Buff was lost
- ShowIcon = true; // Show/Hide icon. Maybe someone just wants sound
- YardsMinTarget = 40; // Green text when the next target can be achieved by killing the monsters that are at this distance. Control key to switch between YardsMax and YardsMin
- YardsMaxTarget = 120; // Green text when the next target can be achieved by killing the monsters that are at this distance. Control key to switch between YardsMax and YardsMin
- ShowCircle = true; // Show circle on the Map, radio YardsMinTarget/YardsMaxTarget. Control key to switch between YardsMin and YardsMax
- ShowMonsterCounter = true; // Show Monster Counter
- ShowBuffOthers = true; // Show the counter of kills of nearby players.
- TurnOffWhenNewGameStarts = false;
- ToggleKeyEventCircle = Hud.Input.CreateKeyEvent(true, Key.LeftControl, true, false, false);
- ToogleKeyEventOn = Hud.Input.CreateKeyEvent(true, Key.F6, controlPressed: true, altPressed: false, shiftPressed: false);
- TextureBG = Hud.Texture.BuffFrameTexture;
- TextureRS = Hud.Texture.GetItemTexture(Hud.Sno.SnoItems.P4_Unique_Spear_002);
- YardMapShapeDecorator = new MapShapeDecorator(Hud)
- {
- Brush = Hud.Render.CreateBrush(150, 180, 147, 109, 1),
- ShapePainter = new CircleShapePainter(Hud),
- Radius = 40,
- };
- }
- public void Customize()
- {
- YardsTarget = YardsMinTarget;
- YardMapShapeDecorator.Radius = YardsTarget;
- if (MinTarget < 15) { MinTarget = 15; }
- }
- public void OnKeyEvent(IKeyEvent keyEvent)
- {
- if (keyEvent.IsPressed)
- {
- if (ToggleKeyEventCircle.Matches(keyEvent))
- {
- YardsTarget = (YardsTarget != YardsMaxTarget) ? YardsMaxTarget : YardsMinTarget;
- YardMapShapeDecorator.Radius = YardsTarget;
- }
- else if (ToogleKeyEventOn.Matches(keyEvent))
- {
- PI_On = !PI_On;
- Buffon = false;
- }
- }
- }
- public void OnNewArea(bool newGame, ISnoArea area)
- {
- if (newGame || (MyIndex != Hud.Game.Me.Index) )
- {
- MyIndex = Hud.Game.Me.Index;
- Buffon = false;
- if (TurnOffWhenNewGameStarts) { PI_On = false; }
- }
- }
- public void Play_Sound(string Sonido)
- {
- var playSonido = Hud.Sound.LoadSoundPlayer(Sonido);
- ThreadPool.QueueUserWorkItem(state =>
- {
- try { playSonido.PlaySync(); }
- catch (Exception) { }
- } );
- }
- public void PaintTopInGame(ClipState clipState)
- {
- if (clipState != ClipState.BeforeClip) return;
- if (!Hud.Game.IsInGame) return;
- if (PI_On && Hud.Game.Me.Powers.BuffIsActive(483967)) // Jugando en temporada
- {
- var players = Hud.Game.Players.Where(p => p.HasValidActor && (p.Powers.GetBuff(483967) != null) && (p.Powers.GetBuff(483967).IconCounts[1] > 0));
- if (players.Any())
- {
- var playerc = players.OrderByDescending(o => o.Powers.GetBuff(483967).IconCounts[1]).FirstOrDefault();
- int c = playerc.Powers.GetBuff(483967).IconCounts[1];
- int cme = Hud.Game.Me.Powers.GetBuff(483967).IconCounts[1];
- if (!Buffon) { Buffon = true; NewTarget = 0; }
- foreach(var d in NextBuff)
- {
- if (d.Key > c)
- {
- if (d.Key != NewTarget)
- {
- if (SoundTarget)
- {
- if (c >= MinTarget)
- {
- if ( (NewTarget > 0) && (d.Key > NewTarget) && (cme == c) )
- Play_Sound(FileSoundTarget);
- }
- }
- NewTarget = d.Key;
- }
- break;
- }
- }
- if (Kills != c) { Kills = c; }
- if (ShowIcon)
- {
- var x = Hud.Window.Size.Width * Xpor; var y = Hud.Window.Size.Height * Ypor;
- var SizeIconWidth = TextureBG.Width * 0.61f * SizeMultiplier; var SizeIconHeight = TextureBG.Height * 0.68f * SizeMultiplier;
- Hud.Texture.Button2TextureOrange.Draw(x, y, SizeIconWidth, SizeIconHeight, 0.7f);
- Hud.Texture.BackgroundTextureYellow.Draw(x, y, SizeIconWidth, SizeIconHeight, 1f);
- TextureRS.Draw(x, y, SizeIconWidth, SizeIconHeight, 1f);
- if (cme == 0) { Hud.Texture.DebuffFrameTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, 1f); }
- else { TextureBG.Draw(x, y, SizeIconWidth, SizeIconHeight, 1f); }
- double t = playerc.Powers.GetBuff(483967).TimeLeftSeconds[1];
- var layout = TimeleftFont.GetTextLayout(t.ToString( (t < 1)? "F1" : "F0") );
- TimeleftFont.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/2.58f));
- MyFont = (c > cme)? StackFontOther : StackFont ;
- layout = MyFont.GetTextLayout(c.ToString());
- MyFont.DrawText(layout, x + (SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width)) - SizeIconWidth/15, y + (SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height)) - SizeIconHeight/30 );
- var monsters = Hud.Game.AliveMonsters.Where(m => m.FloorCoordinate.XYDistanceTo(Hud.Game.Me.FloorCoordinate) <= YardsTarget);
- var mc = monsters.Count();
- if (NewTarget != 0)
- {
- MyFont = ((c + mc) < NewTarget)? NextFont : (((c + monsters.Where(m => m.Rarity == ActorRarity.Normal).Count()) < NewTarget)? NextFontN : NextFontY) ;
- MyFont.DrawText(NextFont.GetTextLayout(NextBuff[NewTarget]), x + SizeIconWidth/12, y + SizeIconHeight/18 );
- }
- if (ShowMonsterCounter)
- {
- layout = MonsterCounterFont.GetTextLayout(mc.ToString());
- MonsterCounterFont.DrawText(layout, x + SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width) - SizeIconWidth/12, y + SizeIconHeight/18);
- }
- else
- {
- layout = YardFont.GetTextLayout((YardsTarget == YardsMaxTarget)? "+":"-");
- YardFont.DrawText(layout, x + SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width) - SizeIconWidth/12, y + SizeIconHeight/18);
- }
- if (ShowBuffOthers && Hud.Game.NumberOfPlayersInGame > 1)
- {
- if (Hud.Game.IsInTown) return;
- x += SizeIconWidth + 1;
- Hud.Texture.Button2TextureOrange.Draw(x, y, SizeIconWidth, SizeIconHeight, 0.4f);
- Hud.Texture.BackgroundTextureYellow.Draw(x, y, SizeIconWidth, SizeIconHeight, 0.5f);
- foreach (var pl in Hud.Game.Players)
- {
- MyFont = (!pl.IsMe && pl.Powers.GetBuff(483967)?.IconCounts[1] > cme)? BuffOtherFontMax : BuffOtherFont ;
- layout = MyFont.GetTextLayout(!pl.HasValidActor ? "?" : (pl.Powers.GetBuff(483967) == null)? "-": pl.Powers.GetBuff(483967).IconCounts[1].ToString());
- MyFont.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), y + (int)(SizeIconHeight/10) + (layout.Metrics.Height * 0.93f * pl.PortraitIndex));
- }
- Hud.Texture.DebuffFrameTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, 0.5f);
- }
- }
- if (ShowCircle) { YardMapShapeDecorator.Paint(null, Hud.Game.Me.FloorCoordinate, null); }
- }
- else
- {
- if (Buffon)
- {
- Buffon = false;
- if (SoundLost)
- {
- if ((Kills >= MinKillsLost) && !Hud.Game.IsInTown)
- {
- Play_Sound(FileSoundLost);
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment