Advertisement
s4000

DAV_WallPlugin

Sep 23rd, 2020 (edited)
1,606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 KB | None | 0 0
  1. using System;
  2. using Turbo.Plugins.Default;
  3.  
  4. namespace Turbo.Plugins.DAV
  5. {
  6.     public class DAV_WallPlugin : BasePlugin, IInGameWorldPainter {
  7.         public double WallWidth { get; set; } = 1.5d;
  8.         public double WallLength { get; set; } = 18d;
  9.         public IBrush WallBrush { get; set; }
  10.        
  11.         private double toRad { get; set; } = Math.PI / 180d;
  12.  
  13.         public DAV_WallPlugin() {
  14.             Enabled = true;
  15.         }
  16.  
  17.         public override void Load(IController hud) {
  18.             base.Load(hud);
  19.  
  20.             WallBrush = Hud.Render.CreateBrush(255, 51, 255, 51, 2);
  21.         }
  22.  
  23.         public void PaintWorld(WorldLayer layer) {
  24.             foreach (var actor in Hud.Game.Actors) {
  25.                 if (actor.SnoActor.Sno == ActorSnoEnum._monsteraffix_waller_model)
  26.                     DrawWall(WallBrush, actor.FloorCoordinate, Direction(actor));
  27.             }
  28.         }
  29.  
  30.         private float Direction(IActor actor) {
  31.             var diffX = (double) (actor.FloorCoordinate.X - actor.CollisionCoordinate.X);
  32.             var diffY = (double) (actor.FloorCoordinate.Y - actor.CollisionCoordinate.Y);
  33.  
  34.             if (diffX == 0 && diffY == 0)
  35.                 return -45f;
  36.  
  37.             return (float) (Math.Atan2(diffY, diffX) / toRad) - 45f;
  38.         }
  39.  
  40.         private void DrawWall(IBrush cBrush, IWorldCoordinate worldCoord, float rotation) {
  41.             if (cBrush == null) return;
  42.  
  43.             var radius = ((float) Math.Sqrt(WallLength * WallLength + WallWidth * WallWidth)) * 0.5f;
  44.             if (radius <= 0f) return;
  45.  
  46.             var revAngle = rotation * toRad + Math.Atan2(WallWidth, WallLength);
  47.             var revX = radius * (float)Math.Cos(revAngle);
  48.             var revY = radius * (float)Math.Sin(revAngle);
  49.             var wCoord_1 = worldCoord.Offset(revX, revY, 0);
  50.             var wCoord_3 = worldCoord.Offset(-revX, -revY, 0);
  51.  
  52.             revAngle = rotation * toRad - Math.Atan2(WallWidth, WallLength);
  53.             revX = radius * (float)Math.Cos(revAngle);
  54.             revY = radius * (float)Math.Sin(revAngle);
  55.             var wCoord_2 = worldCoord.Offset(revX, revY, 0);
  56.             var wCoord_4 = worldCoord.Offset(-revX, -revY, 0);
  57.  
  58.             cBrush.DrawLineWorld(wCoord_1, wCoord_2);
  59.             cBrush.DrawLineWorld(wCoord_2, wCoord_3);
  60.             cBrush.DrawLineWorld(wCoord_3, wCoord_4);
  61.             cBrush.DrawLineWorld(wCoord_4, wCoord_1);
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement