s4000

DAV_PoolsList

Jun 27th, 2020
2,175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.96 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_PoolsList : BasePlugin, IInGameTopPainter, IAfterCollectHandler, INewAreaHandler {
  9.         public float xPos { get; set; }
  10.         public float yPos { get; set; }
  11.         public string PoolSumHeader { get; set; }
  12.         public IFont Font_Pool_Summary { get; set; }
  13.         public Func<int, int, string> PoolSumMessage { get; set; }
  14.  
  15.         public float mapOffsetX { get; set; }
  16.         public float mapOffsetY { get; set; }
  17.         public IFont Font_Pool { get; set; }
  18.         public IFont Font_Pool_Used { get; set; }
  19.         public Func<int, string> mapPoolMessage { get; set; }
  20.  
  21.         private uint lastWayPointSno { get; set; } = 0;
  22.         private uint lastWorldId { get; set; } = 0;
  23.         private int[] poolAvailable { get; set; } = new int[] { 0, 0, 0, 0, 0 };
  24.         private List<DAV_WayPointSno> wayPointList { get; set; } = new List<DAV_WayPointSno>();
  25.         private Dictionary<string, DAV_PoolInfo> PoolMarkers { get; set; } = new Dictionary<string, DAV_PoolInfo>();
  26.  
  27.         public DAV_PoolsList() {
  28.             Enabled = true;
  29.         }
  30.  
  31.         public void OnNewArea(bool newGame, ISnoArea area) {
  32.             if (newGame) {
  33.                 PoolMarkers.Clear();
  34.                 lastWorldId = 0;
  35.                 lastWayPointSno = 0;
  36.                 return;
  37.             }
  38.  
  39.             if (area.IsTown) {
  40.                 lastWorldId = 0;
  41.                 lastWayPointSno = 0;
  42.                 return;
  43.             }
  44.  
  45.             if (wayPointList.Any(x => x.AreaSno == area.Sno))
  46.                 lastWayPointSno = area.Sno;
  47.         }
  48.  
  49.         public void AfterCollect() {
  50.             if (Hud.Game.Me.SnoArea == null || Hud.Game.IsInTown || Hud.Game.Me.SnoArea.Code.StartsWith("x1_lr_l")) return;
  51.  
  52.             var newWayPoint = Hud.Game.Actors.FirstOrDefault(x => x.SnoActor.Sno == ActorSnoEnum._waypoint || x.SnoActor.Sno == ActorSnoEnum._waypoint_oldtristram || x.SnoActor.Sno == ActorSnoEnum._a4_heaven_waypoint);
  53.             if (newWayPoint != null)
  54.                 lastWorldId = newWayPoint.WorldId;
  55.  
  56.             var act = Hud.Game.Me.SnoArea.ActFixed();
  57.             if (act == 0) return; // Cow Level
  58.  
  59.             foreach (var marker in Hud.Game.Markers.Where(x => x.IsPoolOfReflection)) {
  60.                 if (PoolMarkers.ContainsKey(marker.Id)) {
  61.                     if (marker.IsUsed != PoolMarkers[marker.Id].IsUsed) {
  62.                         PoolMarkers[marker.Id].IsUsed = marker.IsUsed;
  63.                         poolAvailable[act - 1]--;
  64.                     }
  65.                     continue;
  66.                 }
  67.  
  68.                 var dist = float.MaxValue;
  69.                 var useAreaSno = lastWayPointSno;
  70.                 foreach(var waypoint in wayPointList.Where(x => x.WorldId == lastWorldId && x.Act == act)) {
  71.                     var thisDist = waypoint.FloorCoordinate.XYDistanceTo(marker.FloorCoordinate);
  72.                     if (thisDist < dist) {
  73.                         dist = thisDist;
  74.                         useAreaSno = waypoint.AreaSno;
  75.                     }
  76.                 }
  77.  
  78.                 PoolMarkers.Add(marker.Id, new DAV_PoolInfo(marker.IsUsed, act, useAreaSno, marker.Id));
  79.                 poolAvailable[act - 1]++;
  80.             }
  81.         }
  82.  
  83.         public void PaintTopInGame(ClipState clipState) {
  84.             if (PoolMarkers.Count == 0) return;
  85.             if (clipState != ClipState.AfterClip) return;
  86.             if (Hud.Game.SpecialArea != SpecialArea.None) return;
  87.  
  88.             var SummaryMsg = "";
  89.             for (var i = 0; i < 5; i++) {
  90.                 if (poolAvailable[i] > 0)
  91.                     SummaryMsg += PoolSumMessage(i + 1, poolAvailable[i]) + "\n";
  92.             }
  93.  
  94.             if (!string.IsNullOrEmpty(SummaryMsg))
  95.                 Font_Pool_Summary.DrawText(PoolSumHeader + "\n" + SummaryMsg, xPos, yPos);
  96.  
  97.             if (!Hud.Render.WorldMapUiElement.Visible || Hud.Render.ActMapUiElement.Visible) return;
  98.  
  99.             var mapCurrentAct = Hud.Game.ActMapCurrentAct;
  100.             var w = 110 * Hud.Window.HeightUiRatio;
  101.  
  102.             var poolList = PoolMarkers.Values.ToList();
  103.             foreach (var waypoint in Hud.Game.ActMapWaypoints.Where(x => x.BountyAct == mapCurrentAct)) {
  104.                 var thisList = poolList.Where(x1 => x1.nearWayPointSno == waypoint.TargetSnoArea.Sno);
  105.                 var qtyT = thisList.Count();
  106.                 if (qtyT == 0) continue;
  107.  
  108.                 var x = Hud.Render.WorldMapUiElement.Rectangle.X + waypoint.CoordinateOnMapUiElement.X * Hud.Window.HeightUiRatio;
  109.                 var y = Hud.Render.WorldMapUiElement.Rectangle.Y + waypoint.CoordinateOnMapUiElement.Y * Hud.Window.HeightUiRatio;
  110.                 var qty1 = thisList.Count(x2 => x2.IsUsed);
  111.                 var qty2 = qtyT - qty1;
  112.  
  113.                 if (qty1 > 0) {
  114.                     var layout = Font_Pool_Used.GetTextLayout(mapPoolMessage(qty1));
  115.                     Font_Pool_Used.DrawText(layout, x + w - layout.Metrics.Width - mapOffsetX, y + mapOffsetY);
  116.                 }
  117.                 if (qty2 > 0)
  118.                     Font_Pool.DrawText(mapPoolMessage(qty2), x + w + mapOffsetX, y + mapOffsetY);
  119.             }
  120.         }
  121.  
  122.         public override void Load(IController hud) {
  123.             base.Load(hud);
  124.  
  125.             xPos = 770; // Hud.Window.Size.Width * 0.4f;
  126.             yPos = 10; // Hud.Window.Size.Height * 0.01f;
  127.             PoolSumHeader = "Pool Quantity Summary";
  128.             PoolSumMessage = (act, qty) => "A" + act.ToString() + " : " + qty.ToString() + " x Pool";
  129.             Font_Pool_Summary = Hud.Render.CreateFont("Arial", 8f, 250, 255, 250, 0, false, false, false);
  130.  
  131.             mapOffsetX = 6f;
  132.             mapOffsetY = 0f;
  133.             mapPoolMessage = (qty) => "Pool x " + qty.ToString();
  134.             Font_Pool = Hud.Render.CreateFont("Arial", 7f, 255, 255, 255, 51, true, true, 160, 51, 51, 51, true);
  135.             Font_Pool_Used = Hud.Render.CreateFont("Arial", 7f, 120, 255, 255, 51, true, true, 160, 51, 51, 51, true);
  136.  
  137.             wayPointList.Add(new DAV_WayPointSno(Hud, 1, 91133, 1999831045, 1976.710f, 2788.146f, 41.2f));
  138.             wayPointList.Add(new DAV_WayPointSno(Hud, 1, 19780, 1999962119, 820.000f, 749.307f, 0.0f));
  139.             wayPointList.Add(new DAV_WayPointSno(Hud, 1, 19783, 2000027656, 820.000f, 701.500f, 0.0f));
  140.             wayPointList.Add(new DAV_WayPointSno(Hud, 1, 19785, 2000093193, 820.000f, 1229.307f, 0.0f));
  141.             wayPointList.Add(new DAV_WayPointSno(Hud, 1, 19787, 2000158730, 1059.357f, 578.648f, 0.0f));
  142.             wayPointList.Add(new DAV_WayPointSno(Hud, 1, 19954, 1999831045, 2895.395f, 2371.276f, 0.0f));
  143.             wayPointList.Add(new DAV_WayPointSno(Hud, 1, 72712, 1999831045, 2161.802f, 1826.882f, 1.9f));
  144.             wayPointList.Add(new DAV_WayPointSno(Hud, 1, 19952, 1999831045, 2037.839f, 910.656f, 1.9f));
  145.             wayPointList.Add(new DAV_WayPointSno(Hud, 1, 61573, 1999831045, 1263.054f, 827.765f, 63.1f));
  146.             wayPointList.Add(new DAV_WayPointSno(Hud, 1, 19953, 1999831045, 423.106f, 781.156f, 21.2f));
  147.             wayPointList.Add(new DAV_WayPointSno(Hud, 1, 93632, 1999831045, 2310.500f, 4770.000f, 1.0f));
  148.             wayPointList.Add(new DAV_WayPointSno(Hud, 1, 78572, 2000617489, 1339.771f, 1159.466f, 0.0f));
  149.             wayPointList.Add(new DAV_WayPointSno(Hud, 1, 19941, 1999831045, 1688.828f, 3890.089f, 41.9f));
  150.             wayPointList.Add(new DAV_WayPointSno(Hud, 1, 19943, 1999831045, 1080.022f, 3444.448f, 62.4f));
  151.             wayPointList.Add(new DAV_WayPointSno(Hud, 1, 19774, 2000814100, 820.000f, 736.500f, 0.0f));
  152.             wayPointList.Add(new DAV_WayPointSno(Hud, 1, 119870, 2001207322, 56.772f, 146.284f, 0.0f));
  153.             wayPointList.Add(new DAV_WayPointSno(Hud, 1, 19775, 2000879637, 452.500f, 820.000f, 0.0f));
  154.             wayPointList.Add(new DAV_WayPointSno(Hud, 1, 19776, 2000945174, 979.000f, 1060.000f, 0.0f));
  155.  
  156.             wayPointList.Add(new DAV_WayPointSno(Hud, 2, 19836, 2001272859, 2760.302f, 1631.820f, 187.5f));
  157.             wayPointList.Add(new DAV_WayPointSno(Hud, 2, 63666, 2001272859, 1419.449f, 321.863f, 176.3f));
  158.             wayPointList.Add(new DAV_WayPointSno(Hud, 2, 19835, 2001272859, 1427.769f, 1185.675f, 186.2f));
  159.             wayPointList.Add(new DAV_WayPointSno(Hud, 2, 460671, 2001403933, 1747.454f, 549.045f, 0.5f));
  160.             wayPointList.Add(new DAV_WayPointSno(Hud, 2, 456638, 2001469470, 400.119f, 889.819f, 0.2f));
  161.             wayPointList.Add(new DAV_WayPointSno(Hud, 2, 210451, 2001600544, 612.485f, 936.556f, -29.8f));
  162.             wayPointList.Add(new DAV_WayPointSno(Hud, 2, 57425, 2001272859, 3548.838f, 4269.278f, 101.9f));
  163.             wayPointList.Add(new DAV_WayPointSno(Hud, 2, 62752, 2001797155, 90.000f, 59.500f, 2.7f));
  164.             wayPointList.Add(new DAV_WayPointSno(Hud, 2, 53834, 2001272859, 1257.886f, 3968.300f, 111.8f));
  165.             wayPointList.Add(new DAV_WayPointSno(Hud, 2, 19800, 2002124840, 799.995f, 680.024f, -0.1f));
  166.  
  167.             wayPointList.Add(new DAV_WayPointSno(Hud, 3, 75436, 1999568897, 1065.148f, 472.449f, 0.0f));
  168.             wayPointList.Add(new DAV_WayPointSno(Hud, 3, 93103, 2002321451, 825.148f, 1192.449f, 0.0f));
  169.             wayPointList.Add(new DAV_WayPointSno(Hud, 3, 136448, 2002386988, 825.148f, 472.449f, 0.0f));
  170.             wayPointList.Add(new DAV_WayPointSno(Hud, 3, 93173, 2002452525, 4272.158f, 4252.097f, -24.8f));
  171.             wayPointList.Add(new DAV_WayPointSno(Hud, 3, 154644, 1999699971, 4356.238f, 408.241f, -2.9f));
  172.             wayPointList.Add(new DAV_WayPointSno(Hud, 3, 155048, 1999699971, 3452.838f, 609.227f, 0.2f));
  173.             wayPointList.Add(new DAV_WayPointSno(Hud, 3, 69504, 1999699971, 2708.557f, 586.267f, 0.0f));
  174.             wayPointList.Add(new DAV_WayPointSno(Hud, 3, 86080, 2002583599, 1679.054f, 744.707f, 0.0f));
  175.             wayPointList.Add(new DAV_WayPointSno(Hud, 3, 80791, 2002714673, 1041.245f, 983.039f, -10.0f));
  176.             wayPointList.Add(new DAV_WayPointSno(Hud, 3, 119305, 2002845747, 2573.769f, 1206.666f, 0.0f));
  177.             wayPointList.Add(new DAV_WayPointSno(Hud, 3, 119653, 2002976821, 959.404f, 1097.913f, -10.0f));
  178.             wayPointList.Add(new DAV_WayPointSno(Hud, 3, 119306, 2003107895, 1162.255f, 686.218f, 0.0f));
  179.             wayPointList.Add(new DAV_WayPointSno(Hud, 3, 428494, 2003238969, 606.110f, 1065.332f, 0.0f));
  180.  
  181.             wayPointList.Add(new DAV_WayPointSno(Hud, 4, 109526, 2003435580, 1073.872f, 786.390f, 0.0f));
  182.             wayPointList.Add(new DAV_WayPointSno(Hud, 4, 464857, 2003501117, 1340.086f, 110.277f, 0.0f));
  183.             wayPointList.Add(new DAV_WayPointSno(Hud, 4, 409001, 2003566654, 1339.833f, 359.946f, -1.3f));
  184.             wayPointList.Add(new DAV_WayPointSno(Hud, 4, 464065, 2003697728, 1030.028f, 870.214f, 15.0f));
  185.             wayPointList.Add(new DAV_WayPointSno(Hud, 4, 409512, 2003632191, 2072.500f, 2747.500f, -30.0f));
  186.             wayPointList.Add(new DAV_WayPointSno(Hud, 4, 109514, 2003763265, 873.785f, 1114.032f, -14.9f));
  187.             wayPointList.Add(new DAV_WayPointSno(Hud, 4, 409517, 2003828802, 2520.398f, 1979.950f, 15.0f));
  188.             wayPointList.Add(new DAV_WayPointSno(Hud, 4, 109538, 2003894339, 1079.837f, 856.173f, -1.3f));
  189.             wayPointList.Add(new DAV_WayPointSno(Hud, 4, 109540, 2004090950, 345.398f, 359.990f, -1.3f));
  190.             wayPointList.Add(new DAV_WayPointSno(Hud, 4, 464066, 2004222024, 2500.083f, 1390.092f, 31.0f));
  191.             wayPointList.Add(new DAV_WayPointSno(Hud, 4, 475856, 2004222024, 348.659f, 341.491f, 50.8f));
  192.             wayPointList.Add(new DAV_WayPointSno(Hud, 4, 475854, 2004287561, 1559.163f, 3636.186f, -23.3f));
  193.             wayPointList.Add(new DAV_WayPointSno(Hud, 4, 464063, 2004287561, 350.023f, 350.276f, 0.0f));
  194.  
  195.             wayPointList.Add(new DAV_WayPointSno(Hud, 5, 263493, 2004353098, 1026.961f, 418.969f, 10.8f));
  196.             wayPointList.Add(new DAV_WayPointSno(Hud, 5, 338946, 2004484172, 1260.250f, 540.750f, 3.3f));
  197.             wayPointList.Add(new DAV_WayPointSno(Hud, 5, 261758, 2004549709, 402.102f, 419.735f, 10.3f));
  198.             wayPointList.Add(new DAV_WayPointSno(Hud, 5, 283553, 2004680783, 608.812f, 417.468f, 0.0f));
  199.             wayPointList.Add(new DAV_WayPointSno(Hud, 5, 258142, 2004746320, 1140.714f, 540.347f, 12.4f));
  200.             wayPointList.Add(new DAV_WayPointSno(Hud, 5, 283567, 2004877394, 877.314f, 399.194f, 0.0f));
  201.             wayPointList.Add(new DAV_WayPointSno(Hud, 5, 338602, 2004942931, 1433.629f, 220.720f, 0.3f));
  202.             wayPointList.Add(new DAV_WayPointSno(Hud, 5, 271234, 2005139542, 1069.580f, 679.856f, 20.2f));
  203.             wayPointList.Add(new DAV_WayPointSno(Hud, 5, 459863, 2005205079, 1000.500f, 1160.500f, 0.5f));
  204.             wayPointList.Add(new DAV_WayPointSno(Hud, 5, 427763, 2005270616, 661.430f, 423.897f, 2.9f));
  205.         }
  206.     }
  207.  
  208.     public class DAV_WayPointSno {
  209.         public int Act { get; set; }
  210.         public uint AreaSno { get; set; }
  211.         public uint WorldId { get; set; }
  212.         public IWorldCoordinate FloorCoordinate { get; set; }
  213.  
  214.         public DAV_WayPointSno(IController hud, int act, uint areaSno, uint worldId, float x, float y, float z) {
  215.             Act = act;
  216.             AreaSno = areaSno;
  217.             WorldId = worldId;
  218.             FloorCoordinate = hud.Window.CreateWorldCoordinate(x, y, z);
  219.         }
  220.     }
  221.  
  222.     public class DAV_PoolInfo {
  223.         public int Act { get; set; }
  224.         public bool IsUsed { get; set; }
  225.         public uint nearWayPointSno { get; set; }
  226.         public string uniqueID { get; set; }
  227.  
  228.         public DAV_PoolInfo(bool used, int act, uint areaSno, string id) {
  229.             Act = act;
  230.             IsUsed = used;
  231.             nearWayPointSno = areaSno;
  232.             uniqueID = id;
  233.         }
  234.     }
  235. }
Advertisement
Add Comment
Please, Sign In to add comment