Advertisement
RNNCode

PacksCounter

Sep 22nd, 2019 (edited)
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.27 KB | None | 0 0
  1. using Turbo.Plugins.Default;  
  2. using System;
  3. using System.Linq;    
  4. using System.Collections.Generic;
  5.  
  6. namespace Turbo.Plugins.RNN
  7. {        
  8.     public class PacksCounter : BasePlugin, IInGameTopPainter, IMonsterKilledHandler, INewAreaHandler, IAfterCollectHandler
  9.     {
  10.         private uint InRiftLastAreaSno { get; set; }
  11.         private bool MapRiftGR { get; set; }
  12.         private Dictionary<IMonsterPack, int[]> DicPacks { get; set; } = new Dictionary<IMonsterPack, int[]>();    
  13.  
  14.         private IFont FontW { get; set; }
  15.         private IFont FontY { get; set; }
  16.         private IFont FontB { get; set; }
  17.        
  18.         public float Xpor  { get; set; }
  19.         public float Ypor  { get; set; }
  20.         public bool OnlyGR { get; set; }
  21.         public bool ResetAtEachLevel { get; set; }
  22.         public bool Vertical { get; set; }
  23.        
  24.         public  PacksCounter()
  25.         {
  26.             Enabled = true;    
  27.         }      
  28.         public override void Load(IController hud)
  29.         {
  30.             base.Load(hud);
  31.             Order = 30001;
  32.            
  33.             Xpor = 0.18f;   // 0.89f  Valid values: from 0 to 1 .
  34.             Ypor = 0.002f;  // 0.91f  Valid values: from 0 to 1 .
  35.             OnlyGR = false;
  36.             ResetAtEachLevel = false;
  37.             Vertical  = false;
  38.            
  39.             FontW = Hud.Render.CreateFont("tahoma", 8, 255, 255, 255, 255, false, false, 255, 0, 0, 0, true);
  40.             FontY = Hud.Render.CreateFont("tahoma", 8, 255, 243, 215, 0, false, false, 255, 0, 0, 0, true);
  41.             FontB = Hud.Render.CreateFont("tahoma", 8, 255, 48, 140, 255, false, false, 255, 0, 0, 0, true);
  42.         }  
  43.         public void OnMonsterKilled(IMonster monster)
  44.         {
  45.             if (MapRiftGR)
  46.             {
  47.                 if ( ((monster.Rarity == ActorRarity.Champion) || (monster.Rarity == ActorRarity.Rare)) && (monster.SummonerAcdDynamicId == 0))
  48.                 {
  49.                     if ((Hud.Game.RiftPercentage  < 100) || !Hud.Game.Me.InGreaterRift)
  50.                     {
  51.                         var p = monster.Pack;
  52.                         if (p == null) return;
  53.                         if (DicPacks.ContainsKey(p))
  54.                         {
  55.                             DicPacks[p][1] = DicPacks[p][1] + 1 ;
  56.                         }
  57.                         else
  58.                         {
  59.                             DicPacks.Add(p,new int[] {1,1}); // Hud.Sound.Speak("Pack Not Found " + monster.Rarity);  // por si acaso
  60.                         }
  61.                     }
  62.                 }
  63.             }
  64.         }
  65.        
  66.         public void AfterCollect()  
  67.         {
  68.             if ((InRiftLastAreaSno != 0) && (Hud.Game.Quests.FirstOrDefault(q => (q.SnoQuest.Sno == 337492) && (q.State == QuestState.started || q.State == QuestState.completed )) == null))  
  69.             {
  70.                 InRiftLastAreaSno = 0;
  71.             }
  72.         }  
  73.        
  74.         public void OnNewArea(bool newGame, ISnoArea area)
  75.         {  
  76.             if (newGame)
  77.             {
  78.                 InRiftLastAreaSno = 0;
  79.                 MapRiftGR = false;
  80.             }
  81.             if ((area.HostAreaSno == 288482) || (area.Sno == 288482))
  82.             {
  83.                 MapRiftGR = true;
  84.                 if (InRiftLastAreaSno != area.Sno)
  85.                 {
  86.                     if ((InRiftLastAreaSno == 0) || ResetAtEachLevel)
  87.                     {
  88.                         DicPacks.Clear();
  89.                     }
  90.                     InRiftLastAreaSno = area.Sno;
  91.                 }
  92.             }
  93.             else
  94.             {
  95.                 MapRiftGR = false;
  96.             }
  97.         }      
  98.        
  99.         public void PaintTopInGame(ClipState clipState)
  100.         {
  101.             if (clipState != ClipState.BeforeClip) return;
  102.             if (!Hud.Game.IsInGame) return;
  103.             if (MapRiftGR && (!OnlyGR || Hud.Game.Me.InGreaterRift))
  104.             {  
  105.                 foreach(IMonsterPack p in Hud.Game.MonsterPacks)
  106.                 {  
  107.                     int n = p.MonstersAlive.Where(a => ( ((a.Rarity == ActorRarity.Champion) || (a.Rarity == ActorRarity.Rare)) && (a.SummonerAcdDynamicId == 0)) ).Count();
  108.                     if (n > 0)  // Solo actualizaremos packs con elites cerca. Además me di cuenta de un problema si no exijo esto porque .. al iniciar rápido una nueva GR existen packs de la GR anterior
  109.                     {
  110.                         if (DicPacks.TryGetValue(p,out var h))
  111.                         {
  112.                             if (n > h[0]) { DicPacks[p][0] = n; }
  113.                         }
  114.                         else
  115.                         {            
  116.                             DicPacks.Add(p,new int[] {n,0});
  117.                         }
  118.                     }
  119.                 }
  120.                 int blues = 0, bluesdead = 0, rares = 0, raresdead = 0;
  121.                 foreach(IMonsterPack p in DicPacks.Keys)
  122.                 {      
  123.                     bool deads = DicPacks[p][0] <= DicPacks[p][1];
  124.                     if (p.IsFullChampionPack)
  125.                     {
  126.                         blues += 1;
  127.                         if  (deads) { bluesdead += 1; }
  128.                          
  129.                     }
  130.                     else
  131.                     {
  132.                         rares += 1;
  133.                         if  (deads) { raresdead += 1; }
  134.                     }  
  135.                 }
  136.                 var x = Hud.Window.Size.Width * Xpor;
  137.                 var y = Hud.Window.Size.Height * Ypor;         
  138.                 if (Vertical)
  139.                 {
  140.                     var layout = FontW.GetTextLayout("P: " + (blues + rares) + " [" + (bluesdead + raresdead) + "]");
  141.                     FontW.DrawText(layout, x , y );                
  142.                     y += layout.Metrics.Height;
  143.                     layout = FontB.GetTextLayout("B: " + blues + " [" + bluesdead + "]");          
  144.                     FontB.DrawText(layout, x , y );
  145.                     y += layout.Metrics.Height;
  146.                     layout = FontY.GetTextLayout("Y: " + rares + " [" + raresdead + "]");  
  147.                     FontY.DrawText(layout, x , y );                    
  148.                 }
  149.                 else
  150.                 {
  151.                     var layout = FontW.GetTextLayout("Packs: " + (blues + rares) + " [" + (bluesdead + raresdead) + "]");
  152.                     FontW.DrawText(layout, x , y );                
  153.                     x += layout.Metrics.Width;
  154.                     layout = FontW.GetTextLayout(" /");
  155.                     FontW.DrawText(layout, x , y );                
  156.                     x += layout.Metrics.Width;
  157.                     layout = FontB.GetTextLayout( " " + blues + " [" + bluesdead + "]");           
  158.                     FontB.DrawText(layout, x , y );
  159.                     x += layout.Metrics.Width;
  160.                     layout = FontW.GetTextLayout(" /");
  161.                     FontW.DrawText(layout, x , y );                
  162.                     x += layout.Metrics.Width;
  163.                     layout = FontY.GetTextLayout( " " + rares + " [" + raresdead + "]");   
  164.                     FontY.DrawText(layout, x , y );                    
  165.                 }                  
  166.             }
  167.         }      
  168.     }  
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement