s4000

DAV_MissingBuff

Sep 4th, 2019
1,405
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections.Generic;
  2. using System.Globalization;
  3. using System.Linq;
  4. using System.Media;
  5. using System;
  6. using Turbo.Plugins.Default;
  7.  
  8. namespace Turbo.Plugins.DAV
  9. {
  10.     public class DAV_MissingBuff : BasePlugin, IInGameWorldPainter {
  11.         public float xPos { get; set; }
  12.         public float yPos { get; set; }
  13.         public float partyOffsetX { get; set; }
  14.         public float partyOffsetY { get; set; }
  15.         public bool GRonly { get; set; }
  16.         public int SpeakInterval { get; set; }
  17.         public DAV_NoBuffLsit HeroNoBuffList { get; set; } = new DAV_NoBuffLsit();
  18.  
  19.         public DAV_MissingBuff() {
  20.             Enabled = true;
  21.         }
  22.  
  23.         public override void Load(IController hud) {
  24.             base.Load(hud);
  25.         }
  26.  
  27.         public void PaintWorld(WorldLayer layer) {
  28.             if (Hud.Game.IsInTown) return;
  29.             if (GRonly && Hud.Game.SpecialArea != SpecialArea.GreaterRift) return;
  30.  
  31.             foreach(var player in Hud.Game.Players.Where(x => x.CoordinateKnown)){
  32.                 if (player.IsMe) {
  33.                     var soundMessage = "";
  34.                     HeroNoBuffList.PaintVerticalFull(player, xPos, yPos, ref soundMessage);
  35.  
  36.                     if (soundMessage != "" && Hud.Sound.LastSpeak.TimerTest(SpeakInterval))
  37.                         Hud.Sound.Speak(soundMessage);
  38.                 }
  39.                 else {
  40.                     var portraitRect = player.PortraitUiElement.Rectangle;
  41.                     var xref = portraitRect.Right + portraitRect.Width * partyOffsetX;
  42.                     var yref = portraitRect.Top + portraitRect.Height * partyOffsetY;
  43.                     HeroNoBuffList.PaintHorizontal(player, xref, yref);
  44.                 }
  45.             }
  46.         }
  47.     }
  48.  
  49.     public class DAV_NoBuffLsit {
  50.         public Dictionary<HeroClass, List<DAV_NoBuffRule>> FullNoBuffList { get; set; }
  51.        
  52.         public DAV_NoBuffLsit() {
  53.             FullNoBuffList = new Dictionary<HeroClass, List<DAV_NoBuffRule>> {
  54.                 {HeroClass.DemonHunter, new List<DAV_NoBuffRule>()},
  55.                 {HeroClass.Barbarian, new List<DAV_NoBuffRule>()},
  56.                 {HeroClass.Wizard, new List<DAV_NoBuffRule>()},
  57.                 {HeroClass.WitchDoctor, new List<DAV_NoBuffRule>()},
  58.                 {HeroClass.Monk, new List<DAV_NoBuffRule>()},
  59.                 {HeroClass.Crusader, new List<DAV_NoBuffRule>()},
  60.                 {HeroClass.Necromancer, new List<DAV_NoBuffRule>()}
  61.             };
  62.         }
  63.        
  64.         public void Add(HeroClass Hclass, DAV_NoBuffRule newRule) {
  65.             if (Hclass == HeroClass.None) {
  66.                 FullNoBuffList[HeroClass.DemonHunter].Add(newRule);
  67.                 FullNoBuffList[HeroClass.Barbarian].Add(newRule);
  68.                 FullNoBuffList[HeroClass.Wizard].Add(newRule);
  69.                 FullNoBuffList[HeroClass.WitchDoctor].Add(newRule);
  70.                 FullNoBuffList[HeroClass.Monk].Add(newRule);
  71.                 FullNoBuffList[HeroClass.Crusader].Add(newRule);
  72.                 FullNoBuffList[HeroClass.Necromancer].Add(newRule);
  73.             }
  74.             else FullNoBuffList[Hclass].Add(newRule);
  75.         }
  76.        
  77.         public void PaintHorizontal(IPlayer player, float x, float y) {
  78.             var hereNoBuff = FullNoBuffList[player.HeroClassDefinition.HeroClass];
  79.             var xref = x;
  80.             foreach (var noBuff in hereNoBuff) {
  81.                 if (!noBuff.ShowOnList(player)) continue;
  82.                
  83.                 noBuff.PaintIcon(player, xref, y);
  84.                 xref += noBuff.IconSize;
  85.             }
  86.         }
  87.        
  88.         public void PaintVerticalFull(IPlayer player, float x, float y, ref string speak) {
  89.             var hereNoBuff = FullNoBuffList[player.HeroClassDefinition.HeroClass];
  90.             var yref = y;
  91.             foreach (var noBuff in hereNoBuff) {
  92.                 if (!noBuff.ShowOnList(player)) continue;
  93.                
  94.                 noBuff.PaintIconFull(player, x, yref);
  95.                 yref += noBuff.IconSize;
  96.  
  97.                 if (noBuff.SpeakEnable)
  98.                     speak += noBuff.Message + "\n";
  99.             }
  100.         }
  101.     }
  102.    
  103.     public class DAV_NoBuffRule {
  104.         public bool InCombatOnly { get; set; }
  105.         public Func<IPlayer, bool> IsRelevant { get; set; }
  106.         public Func<IPlayer, bool> IsBuffOn { get; set; }
  107.         public Func<IPlayer, string> IconMsg { get; set; }
  108.         public bool SpeakEnable { get; set; }
  109.         public string Message { get; set; }
  110.         public IFont warmFont { get; set; }
  111.         public float IconSize { get; set; }
  112.         public IBrush Icon_Brush { get; set; }
  113.         public ITexture Icon_BG { get; set; }
  114.         public ITexture Icon_Texture { get; set; }
  115.  
  116.         public DAV_NoBuffRule() {}
  117.  
  118.         public bool ShowOnList(IPlayer player) {
  119.             if (InCombatOnly && !player.InCombat)
  120.                 return false;
  121.             if (!IsRelevant(player))
  122.                 return false;
  123.            
  124.             return !IsBuffOn(player);
  125.         }
  126.  
  127.         public void PaintIconFull(IPlayer player, float x, float y) {
  128.             PaintIcon(player, x, y);
  129.             var layout = warmFont.GetTextLayout(Message);
  130.             warmFont.DrawText(layout, x + IconSize + 3, y + (IconSize - (float)layout.Metrics.Height)/2);
  131.         }
  132.  
  133.         public void PaintIcon(IPlayer player, float x, float y) {
  134.             if (Icon_BG != null) Icon_BG.Draw(x, y, IconSize, IconSize);
  135.             if (Icon_Texture != null) {
  136.                 Icon_Texture.Draw(x, y, IconSize, IconSize);
  137.                 if (IconMsg != null) {
  138.                     var layout = warmFont.GetTextLayout(IconMsg(player));
  139.                     warmFont.DrawText(layout, x + (IconSize - layout.Metrics.Width)/2, y + (IconSize - (float)layout.Metrics.Height)/2);
  140.                 }
  141.             }
  142.             if (Icon_Brush != null) Icon_Brush.DrawRectangle(x, y, IconSize, IconSize);
  143.         }
  144.     }
  145. }
RAW Paste Data