Advertisement
s4000

DAV_VisitedMapPlugin

Apr 9th, 2020 (edited)
858
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.90 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using Turbo.Plugins.Default;
  5.  
  6. namespace Turbo.Plugins.DAV
  7. {
  8.     public class DAV_VisitedMapPlugin : BasePlugin, IInGameTopPainter, IInGameWorldPainter, IAfterCollectHandler, INewAreaHandler {
  9.         public float offsetY { get; set; }
  10.         public string visitedMessage { get; set; }
  11.         public IFont textFont { get; set; }
  12.         public WorldDecoratorCollection PortalDecorator { get; set; }
  13.  
  14.         public bool Cow_Enable { get; set; }
  15.         public bool Cow_InTownOnly { get; set; }
  16.         public float Cow_xPos { get; set; }
  17.         public float Cow_yPos { get; set; }
  18.         public string Cow_Message { get; set; }
  19.         public IFont Cow_Font { get; set; }
  20.  
  21.         private bool isListEmpty { get; set; } = true;
  22.         private uint[] currentSno { get; set; } = new uint[] { 0, 0, 0, 0 };
  23.         private List<uint> visitedList { get; set; } = new List<uint>();
  24.         private List<uint> blackList { get; set; } = new List<uint> {
  25.             380773, 380774, 483058, 483085, // Vault
  26.             257116, 256767, 256106, 256742, 374239, // Uber
  27.         };
  28.  
  29.         public DAV_VisitedMapPlugin() {
  30.             Enabled = true;
  31.             Order = 30000;
  32.         }
  33.  
  34.         public override void Load(IController hud) {
  35.             base.Load(hud);
  36.  
  37.             offsetY = 2f;
  38.             visitedMessage = "Visited";
  39.             textFont = Hud.Render.CreateFont("Arial", 7f, 255, 255, 128, 51, true, true, 160, 51, 51, 51, true);
  40.  
  41.             Cow_Enable = true;
  42.             Cow_InTownOnly = false;
  43.             Cow_xPos = 120;
  44.             Cow_yPos = 20;
  45.             Cow_Message = "Not Cow Level Opened";
  46.             Cow_Font = Hud.Render.CreateFont("Arial", 10f, 255, 255, 128, 51, true, true, 160, 51, 51, 51, true);
  47.  
  48.             PortalDecorator = new WorldDecoratorCollection(
  49.                 new MapLabelDecorator(Hud) {
  50.                     LabelFont = Hud.Render.CreateFont("Arial", 6f, 255, 255, 128, 51, true, true, 160, 51, 51, 51, true),
  51.                     RadiusOffset = 7.0f,
  52.                     Up = true,
  53.                 }
  54.             );
  55.         }
  56.  
  57.         public void PaintTopInGame(ClipState clipState) {
  58.             if (isListEmpty) return;
  59.             if (clipState != ClipState.AfterClip) return;
  60.             if (!Hud.Render.WorldMapUiElement.Visible || Hud.Render.ActMapUiElement.Visible) return;
  61.  
  62.             var mapCurrentAct = Hud.Game.ActMapCurrentAct;
  63.             var w = 220 * Hud.Window.HeightUiRatio;
  64.  
  65.             foreach (var waypoint in Hud.Game.ActMapWaypoints.Where(x => x.BountyAct == mapCurrentAct)) {
  66.                 if (!visitedList.Contains(waypoint.TargetSnoArea.Sno)) continue;
  67.  
  68.                 var x = Hud.Render.WorldMapUiElement.Rectangle.X + waypoint.CoordinateOnMapUiElement.X * Hud.Window.HeightUiRatio;
  69.                 var y = Hud.Render.WorldMapUiElement.Rectangle.Y + waypoint.CoordinateOnMapUiElement.Y * Hud.Window.HeightUiRatio;
  70.                 var layout = textFont.GetTextLayout(visitedMessage);
  71.                 textFont.DrawText(layout, x + (w - layout.Metrics.Width) / 2, y - layout.Metrics.Height + offsetY);
  72.             }
  73.         }
  74.  
  75.         public void PaintWorld(WorldLayer layer) {
  76.             if (isListEmpty) return;
  77.  
  78.             if (Cow_Enable && Hud.Game.SpecialArea == SpecialArea.None && visitedList.Contains(434650)) {
  79.                 if (!Cow_InTownOnly || (Cow_InTownOnly && Hud.Game.IsInTown))
  80.                     Cow_Font.DrawText(Cow_Message, Cow_xPos, Cow_yPos);
  81.             }
  82.  
  83.             foreach (var portal in Hud.Game.Portals) {
  84.                 if (portal.TargetArea.Code.StartsWith("x1_lr_l")) continue; // Skip Rift Map
  85.                 if (blackList.Contains(portal.TargetArea.Sno)) continue;
  86.                 if (!visitedList.Contains(portal.TargetArea.Sno)) continue;
  87.  
  88.                 PortalDecorator.Paint(layer, null, portal.FloorCoordinate, visitedMessage);
  89.             }
  90.         }
  91.  
  92.         public void AfterCollect() {
  93.             if (!Hud.Game.IsInGame) return;
  94.  
  95.             foreach (var player in Hud.Game.Players) {
  96.                 if (player.IsInTown) continue;
  97.                 if (player.SnoArea.Sno == currentSno[player.Index]) continue;
  98.                 if (visitedList.Contains(player.SnoArea.Sno)) continue;
  99.  
  100.                 visitedList.Add(player.SnoArea.Sno);
  101.                 isListEmpty = false;
  102.                 currentSno[player.Index] = player.SnoArea.Sno;
  103.             }
  104.         }
  105.  
  106.         public void OnNewArea(bool newGame, ISnoArea area) {
  107.             if (newGame) {
  108.                 isListEmpty = true;
  109.                 visitedList.Clear();
  110.             }
  111.         }
  112.     }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement