Advertisement
Guest User

AreaDamageHelperPlugin.cs

a guest
Apr 10th, 2017
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.77 KB | None | 0 0
  1. using SharpDX.DirectInput;
  2. using System.Linq;
  3. using System.Text;
  4. using Turbo.Plugins.Default;
  5.  
  6. namespace Turbo.Plugins.Csavo // Plugin for showing density within 10 yards around each monster for area damage calculating purposes.
  7. {
  8.     public class AreaDamageHelperPlugin : BasePlugin, IInGameWorldPainter, IKeyEventHandler // version 1.1 - April 11th, 2017
  9.     {
  10.         public bool Show { get; set; }
  11.         public bool ShowEnabled { get; set; }
  12.         public bool ShowLabel { get; set; }
  13.         public bool ShowList { get; set; }
  14.         public bool ShowAdCircle { get; set; }
  15.         public bool ShowHitBox { get; set; }
  16.         public int Distance { get; set; }
  17.         public WorldDecoratorCollection MonstersInRangeLabel { get; set; }
  18.         public WorldDecoratorCollection MonsterHitBox { get; set; }
  19.         public IBrush CircleBrush { get; set; }
  20.         public float XPos { get; set; }
  21.         public float YPos { get; set; }    
  22.         public IFont TextFontList { get; set; }
  23.         private StringBuilder textBuilder;
  24.         public IKeyEvent ToggleKeyEvent { get; set; }
  25.         public Key HotKey
  26.         {
  27.             get { return ToggleKeyEvent.Key; }
  28.             set { ToggleKeyEvent = Hud.Input.CreateKeyEvent(true, value, false, false, false); }
  29.         }
  30.  
  31.         public AreaDamageHelperPlugin()
  32.         {
  33.             Enabled = true;
  34.             Show = false;
  35.             ShowEnabled = true;
  36.         }
  37.  
  38.         public override void Load(IController hud)
  39.         {
  40.             base.Load(hud);
  41.  
  42.             HotKey = Key.F8;
  43.  
  44.             ShowLabel = true; // show density in area damage range for every alive monster
  45.             ShowList = false; // show a list of all alive monsters on the screen with density in area damage range
  46.             ShowAdCircle = false; // show the area damage range (Distance) as a circle
  47.             ShowHitBox = false; // show monster hitbox
  48.  
  49.             Distance = 10; // distance for area damage is 10. only change this for testing
  50.  
  51.             XPos = Hud.Window.Size.Width * 0.01f;
  52.             YPos = Hud.Window.Size.Height * 0.16f;
  53.  
  54.             TextFontList = Hud.Render.CreateFont("tahoma", 7f, 255, 180, 147, 109, false, false, 160, 0, 0, 0, true);
  55.  
  56.             textBuilder = new StringBuilder();
  57.  
  58.             MonstersInRangeLabel = new WorldDecoratorCollection(
  59.                 new GroundLabelDecorator(Hud) {
  60.                     BackgroundBrush = Hud.Render.CreateBrush(80, 0, 0, 0, 0),
  61.                     TextFont = Hud.Render.CreateFont("tahoma", 6f, 255, 180, 147, 109, false, false, 160, 0, 0, 0, true),
  62.                 }
  63.             );
  64.  
  65.             MonsterHitBox = new WorldDecoratorCollection(
  66.                 new GroundCircleDecorator(Hud) {
  67.                     Brush = Hud.Render.CreateBrush(51, 255, 255, 255, 0),
  68.                     Radius = -1
  69.                 }
  70.             );
  71.            
  72.             CircleBrush = Hud.Render.CreateBrush(51, 255, 255, 255, 1, SharpDX.Direct2D1.DashStyle.Dash);
  73.         }
  74.  
  75.         public void OnKeyEvent(IKeyEvent keyEvent)
  76.         {
  77.             if (keyEvent.IsPressed && ToggleKeyEvent.Matches(keyEvent))
  78.             {
  79.                 Show = !Show;
  80.             }
  81.         }
  82.  
  83.         public void PaintWorld(WorldLayer layer)
  84.         {
  85.             if (ShowEnabled && Show)
  86.             {
  87.                 textBuilder.Clear();
  88.                 var monsters = Hud.Game.AliveMonsters;
  89.                 foreach (var monster in monsters)
  90.                 {
  91.                     var count = Hud.Game.AliveMonsters.Count(m => (monster.FloorCoordinate.XYZDistanceTo(m.FloorCoordinate) - m.RadiusBottom) <= Distance);
  92.                     if (monster.IsOnScreen && ShowLabel)
  93.                     {
  94.                         MonstersInRangeLabel.Paint(layer, monster, monster.FloorCoordinate, (count - 1).ToString());
  95.                     }
  96.                     if (ShowAdCircle)
  97.                     {
  98.                         CircleBrush.DrawWorldEllipse(Distance, -1, monster.FloorCoordinate);
  99.                     }
  100.                     if (ShowHitBox)
  101.                     {
  102.                         MonsterHitBox.Paint(layer, monster, monster.FloorCoordinate, monster.SnoMonster.NameLocalized);
  103.                     }
  104.                     if (monster.IsOnScreen && ShowList)
  105.                     {
  106.                         var monsterTypeName = (monster.SnoMonster.NameLocalized).ToString();
  107.                         textBuilder.AppendFormat("{0}: {1}", monsterTypeName, (count - 1).ToString());
  108.                         textBuilder.AppendLine();
  109.                     }
  110.                     var layout = TextFontList.GetTextLayout(textBuilder.ToString());
  111.                     TextFontList.DrawText(layout, XPos, YPos);
  112.                 }
  113.             }
  114.             else return;
  115.         }
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement