Advertisement
Guest User

PoolState.cs

a guest
Nov 18th, 2020
1,124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.40 KB | None | 0 0
  1. //https://www.ownedcore.com/forums/diablo-3/turbohud/turbohud-community-plugins/613631-international-gz-poolstate.html
  2. //Supported Hud Plugins [v9.2]
  3.  
  4. using System;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Collections.Generic;
  8. using System.Globalization;
  9. using Turbo.Plugins.Default;
  10.  
  11. namespace Turbo.Plugins.gjuz
  12. {
  13.     public class PoolState : BasePlugin, IInGameTopPainter, IAfterCollectHandler, INewAreaHandler
  14.     {
  15.         public int DeathsTotal { get; private set; }
  16.         public int DeathsInRift { get; private set; }
  17.         private SpecialArea? currentRun;
  18.         private bool alive;
  19.        
  20.         public string DeathsTotalSymbol { get; set; }
  21.         public string DeathsInRiftSymbol { get; set; }
  22.         public string HasPoolSymbol { get; set; }
  23.         public string EmptyPoolSymbol { get; set; }
  24.        
  25.         public bool IsNephalemRift { get{ return riftQuest != null && (riftQuest.QuestStepId == 1 || riftQuest.QuestStepId == 3 || riftQuest.QuestStepId == 10); } }
  26.         public bool IsGreaterRift { get{ return riftQuest != null && (riftQuest.QuestStepId == 13 || riftQuest.QuestStepId == 16 || riftQuest.QuestStepId == 34 || riftQuest.QuestStepId == 46); } }
  27.         private IQuest riftQuest { get{ return Hud.Game.Quests.FirstOrDefault(q => q.SnoQuest.Sno == 337492) /*rift*/ ?? Hud.Game.Quests.FirstOrDefault(q => q.SnoQuest.Sno == 382695); /*gr*/ } }
  28.        
  29.         public IFont PortraitInfoFont { get; set; }
  30.         public float OffsetXmultiplier { get; set; }
  31.         public float OffsetYmultiplier { get; set; }
  32.        
  33.         public bool ShowDeathCounter { get; set; }
  34.         public bool ShowGRDeathCounter { get; set; }
  35.         public bool ShowGRSecondsCounter { get; set; }
  36.         public bool BracketGRDeathCounter { get; set; }
  37.        
  38.         private readonly StringBuilder textBuilder;
  39.        
  40.         private long[] BonusPool { get; set; }
  41.         private bool[] BonusPoolRecorded { get; set; }
  42.         private int PlayerCount { get; set; }
  43.        
  44.         public PoolState()
  45.         {
  46.             Enabled = true;
  47.            
  48.             ShowDeathCounter = true;
  49.             ShowGRDeathCounter = true;
  50.             ShowGRSecondsCounter = true;
  51.             BracketGRDeathCounter = true;
  52.            
  53.             textBuilder = new StringBuilder();
  54.         }
  55.        
  56.         public override void Load(IController hud)
  57.         {
  58.             base.Load(hud);
  59.            
  60.             DeathsTotal = 0;
  61.             DeathsInRift = 0;
  62.             alive = true;
  63.            
  64.             DeathsTotalSymbol = Char.ConvertFromUtf32(0x00002620);  //Unicode Character 'SKULL AND CROSSBONES' (U+2620)
  65.             DeathsInRiftSymbol = Char.ConvertFromUtf32(0x0001F548); //Unicode Character 'CELTIC CROSS' (U+1F548)
  66.             HasPoolSymbol = Char.ConvertFromUtf32(0x00002B1F);      //Unicode Character 'BLACK PENTAGON' (U+2B1F)
  67.             EmptyPoolSymbol = Char.ConvertFromUtf32(0x00002B20);    //Unicode Character 'WHITE PENTAGON' (U+2B20)
  68.            
  69.             PortraitInfoFont = Hud.Render.CreateFont("tahoma", 7f, 255, 180, 147, 109, false, false, true);
  70.             OffsetXmultiplier = 0.05f;
  71.             OffsetYmultiplier = 0.117f;
  72.            
  73.             BonusPool = new long[4];
  74.             ResetBonusPool();
  75.             BonusPoolRecorded = new bool[4];
  76.         }
  77.        
  78.         public void AfterCollect()
  79.         {
  80.             if (riftQuest == null || (riftQuest != null && riftQuest.State == QuestState.none))
  81.             {
  82.                 DeathsInRift = 0;
  83.                 currentRun = null;
  84.             }
  85.            
  86.             //resets not used BonusPool
  87.             if (PlayerCount != Hud.Game.Players.Count())
  88.             {
  89.                 List<int> l = new List<int> {0,1,2,3};
  90.                 foreach (var player in Hud.Game.Players)
  91.                     l.Remove(player.Index);
  92.                
  93.                 foreach (int i in l)
  94.                     BonusPool[i] = long.MinValue;
  95.  
  96.                 PlayerCount = Hud.Game.Players.Count();
  97.             }
  98.         }
  99.        
  100.         public void PaintTopInGame(ClipState clipState)
  101.         {
  102.             if (clipState != ClipState.BeforeClip) return;
  103.            
  104.             if (currentRun == null)
  105.             {
  106.                 currentRun = IsNephalemRift ? SpecialArea.Rift : SpecialArea.GreaterRift;
  107.             }
  108.            
  109.             CheckDeathState();
  110.             foreach (IPlayer player in Hud.Game.Players)
  111.             {
  112.                 DrawPlayerInfo(player);
  113.             }
  114.         }
  115.        
  116.         private string GetPlayerInfoText(IPlayer player)
  117.         {
  118.             textBuilder.Clear();
  119.            
  120.             var _bonuspool = BonusPoolInfo(player);
  121.             var _pool = BonusPoolRecorded[player.Index] ? (_bonuspool > 0 ? 10*((float)_bonuspool / player.ParagonExpToNextLevel) : 0f) : float.PositiveInfinity;
  122.             var _poolSymbol = _bonuspool > 0 ? HasPoolSymbol : EmptyPoolSymbol;
  123.            
  124.             textBuilder.AppendFormat("{0} {1:0.##}", _poolSymbol, _pool);
  125.            
  126.             if (player.IsMe)
  127.             {
  128.                 textBuilder.Append("\t");
  129.                
  130.                 if (ShowDeathCounter)
  131.                     textBuilder.AppendFormat("{0} {1}  ", DeathsTotalSymbol, DeathsTotal);
  132.                
  133.                 if (IsGreaterRift)
  134.                 {
  135.                     bool brackets = false;
  136.                     if (ShowGRDeathCounter)
  137.                     {
  138.                         textBuilder.AppendFormat("{0}{1}{2}", (BracketGRDeathCounter ? "[" : ""), DeathsInRiftSymbol, DeathsInRift);
  139.                         brackets = BracketGRDeathCounter;
  140.                     }
  141.                    
  142.                     if (ShowGRSecondsCounter)
  143.                     {
  144.                         textBuilder.AppendFormat("{0}{1}s", (BracketGRDeathCounter && !brackets ? "[" : " "), (DeathsInRift > 5 ? 30 : DeathsInRift*5));
  145.                         brackets = BracketGRDeathCounter;
  146.                     }
  147.                    
  148.                     textBuilder.AppendFormat("{0}", brackets ? "]" : "");
  149.                 }
  150.             }
  151.            
  152.             return textBuilder.ToString();
  153.         }
  154.        
  155.         private long BonusPoolInfo(IPlayer player)
  156.         {
  157.             if (player.IsMe || (player.NormalizedXyDistanceToMe > 0 && player.NormalizedXyDistanceToMe < 80))
  158.             {
  159.                 BonusPool[player.Index] = player.BonusPoolRemaining;
  160.                 BonusPoolRecorded[player.Index] = true;
  161.             }
  162.            
  163.             return BonusPool[player.Index];
  164.         }
  165.        
  166.         private void DrawPlayerInfo(IPlayer player)
  167.         {
  168.             var OffsetX = Hud.Window.Size.Width * OffsetXmultiplier;
  169.             var OffsetY = Hud.Window.Size.Height * OffsetYmultiplier;
  170.             var portraitRect = player.PortraitUiElement.Rectangle;
  171.             var YPos = portraitRect.Y + OffsetY;
  172.             var XPos = portraitRect.X + OffsetX;
  173.            
  174.             var Layout = PortraitInfoFont.GetTextLayout(GetPlayerInfoText(player));
  175.             PortraitInfoFont.DrawText(Layout, XPos, YPos);
  176.         }
  177.        
  178.         private void CheckDeathState()
  179.         {
  180.             var me = Hud.Game.Me; //player
  181.             if(me.IsDeadSafeCheck && alive)
  182.             {
  183.                 DeathsTotal++;
  184.                 if (currentRun != null)
  185.                     DeathsInRift++;
  186.                 alive = !alive;
  187.             }
  188.             if (!me.IsDeadSafeCheck && !alive)
  189.                 alive = !alive;
  190.         }
  191.        
  192.         public void OnNewArea(bool newGame, ISnoArea area)
  193.         {
  194.             if (newGame)
  195.             {
  196.                 PlayerCount = Hud.Game.Players.Count();
  197.                
  198.                 //reset
  199.                 ResetBonusPool();
  200.             }
  201.         }
  202.        
  203.         private void ResetBonusPool()
  204.         {
  205.             for(int i=0; i < 4; i++)
  206.             {
  207.                 BonusPool[i] = long.MinValue;
  208.             }
  209.             BonusPool[Hud.Game.Me.Index] = Hud.Game.Me.BonusPoolRemaining;
  210.         }
  211.        
  212.        
  213.     }
  214. }
  215.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement