zjqyf

PartyBuffPlugin.cs

Aug 29th, 2017
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using Turbo.Plugins.Default;
  4.  
  5. namespace Turbo.Plugins.Gigi
  6. {
  7.  
  8.     public class PartyBuffPlugin : BasePlugin, IInGameWorldPainter
  9.     {
  10.         public BuffPainter BuffPainter { get; set; }
  11.         public BuffRuleCalculator RuleCalculatorMe { get; private set;}
  12.         public Dictionary<HeroClass, BuffRuleCalculator> RuleCalculators { get; private set; }
  13.         public WorldDecoratorCollection DebugDecorator { get; set; }
  14.         public bool MePortraitPaint { get; set; }
  15.         public bool MeScreenPaint { get; set; }
  16.         public bool OtherPortraitPaint { get; set; }
  17.         public bool OtherScreenPaint { get; set; }
  18.         public bool Tooltips { get; set; }
  19.         public bool Debug { get; set; }
  20.         private float SizeMultiplier { get; set; }
  21.         public float Opacity { get; set; }
  22.         public float PositionOffset { get; set; }
  23.         public float MePositionOffset { get; set; }
  24.         private BuffRuleFactory buffRuleFactory;
  25.        
  26.         public PartyBuffPlugin()
  27.         {
  28.             Enabled = true;
  29.             MeScreenPaint = true;
  30.             MePortraitPaint = true;
  31.             OtherScreenPaint = true;
  32.             OtherPortraitPaint = true;
  33.             Tooltips = true;
  34.         }
  35.  
  36.  
  37.         public override void Load(IController hud)
  38.         {  
  39.             base.Load(hud);
  40.             buffRuleFactory = new BuffRuleFactory(hud);
  41.             SizeMultiplier = 0.85f;
  42.             PositionOffset = 0.085f;
  43.             MePositionOffset = 0.04f;
  44.             Debug = false;
  45.             Opacity = 0.85f;
  46.             RuleCalculatorMe = new BuffRuleCalculator(Hud);
  47.             RuleCalculatorMe.SizeMultiplier = SizeMultiplier;
  48.             RuleCalculators = new Dictionary<HeroClass, BuffRuleCalculator>();
  49.             foreach(HeroClass h in Enum.GetValues(typeof(HeroClass))){
  50.                 RuleCalculators.Add(h, new BuffRuleCalculator(Hud));
  51.                 RuleCalculators[h].SizeMultiplier = SizeMultiplier;
  52.             }
  53.  
  54.             BuffPainter = new BuffPainter(Hud, true)
  55.             {
  56.                 Opacity = Opacity,
  57.                 ShowTimeLeftNumbers = true,
  58.                 ShowTooltips = Tooltips,
  59.                 TimeLeftFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, false, false, 255, 0, 0, 0, true),
  60.                 StackFont = Hud.Render.CreateFont("tahoma", 6, 255, 255, 255, 255, false, false, 255, 0, 0, 0, true),
  61.             };
  62.  
  63.             DebugDecorator = new WorldDecoratorCollection(
  64.                 new GroundLabelDecorator(Hud)
  65.                 {
  66.                     BackgroundBrush = Hud.Render.CreateBrush(100, 20, 20, 20, 0),
  67.                     TextFont = Hud.Render.CreateFont("tahoma", 6.5f, 255, 255, 255, 255, false, false, false),
  68.                 }
  69.             );
  70.         }
  71.  
  72.         public void PaintWorld(WorldLayer layer)
  73.         {
  74.             var players = Hud.Game.Players;
  75.             foreach(var p in players){
  76.                 var portraitRect = p.PortraitUiElement.Rectangle;
  77.                 if (p.IsMe){
  78.                     RuleCalculatorMe.CalculatePaintInfo(p);
  79.                     if (RuleCalculatorMe.PaintInfoList.Count != 0)
  80.                         if (MeScreenPaint)
  81.                         {
  82.                             BuffPainter.PaintHorizontalCenter(
  83.                             RuleCalculatorMe.PaintInfoList,
  84.                             0,
  85.                             Hud.Window.Size.Height * 0.5f + Hud.Window.Size.Height * MePositionOffset,
  86.                             Hud.Window.Size.Width,
  87.                             RuleCalculatorMe.StandardIconSize,
  88.                             RuleCalculatorMe.StandardIconSpacing
  89.                         );
  90.                         }
  91.                         if (MePortraitPaint)
  92.                         {
  93.                             BuffPainter.PaintHorizontal(
  94.                             RuleCalculatorMe.PaintInfoList,
  95.                             portraitRect.Right,
  96.                             portraitRect.Top + portraitRect.Height * 0.72f,
  97.                             RuleCalculatorMe.StandardIconSize,
  98.                             RuleCalculatorMe.StandardIconSpacing
  99.                             );
  100.                         }
  101.                 }else{
  102.                     if (p.IsOnScreen && p.CoordinateKnown){
  103.                         RuleCalculators[p.HeroClassDefinition.HeroClass].CalculatePaintInfo(p);
  104.                         if (RuleCalculators[p.HeroClassDefinition.HeroClass].PaintInfoList.Count != 0){
  105.                             if(OtherScreenPaint)
  106.                             {
  107.                             BuffPainter.PaintHorizontalCenter(
  108.                                 RuleCalculators[p.HeroClassDefinition.HeroClass].PaintInfoList,
  109.                                 p.ScreenCoordinate.X,
  110.                                 p.ScreenCoordinate.Y + Hud.Window.Size.Height * PositionOffset,
  111.                                 0,
  112.                                 RuleCalculators[p.HeroClassDefinition.HeroClass].StandardIconSize,
  113.                                 RuleCalculators[p.HeroClassDefinition.HeroClass].StandardIconSpacing
  114.                                 );
  115.                             }
  116.                             if(OtherPortraitPaint)
  117.                             {
  118.                             BuffPainter.PaintHorizontal(
  119.                                 RuleCalculators[p.HeroClassDefinition.HeroClass].PaintInfoList,
  120.                                 portraitRect.Right,
  121.                                 portraitRect.Top + portraitRect.Height * 0.72f,
  122.                                 RuleCalculators[p.HeroClassDefinition.HeroClass].StandardIconSize,
  123.                                 RuleCalculators[p.HeroClassDefinition.HeroClass].StandardIconSpacing
  124.                             );
  125.                             }
  126.                         }
  127.                     }
  128.                 }
  129.  
  130.                 if (Debug)
  131.                     DebugPrint(layer, p);
  132.             }
  133.         }
  134.  
  135.         private void DebugPrint(WorldLayer layer, IPlayer p){
  136.             string data = "";
  137.             foreach(IBuff b in p.Powers.AllBuffs)
  138.                 if (BuffRuleExsitsForPlayer(p, b))
  139.                     data += DataOnBuff(b) + "\n";
  140.             DebugDecorator.Paint(layer, p, p.FloorCoordinate, data);
  141.         }
  142.  
  143.         private bool BuffRuleExsitsForPlayer(IPlayer p, IBuff b){
  144.             BuffRuleCalculator r = (p.IsMe) ? RuleCalculatorMe : RuleCalculators[p.HeroClassDefinition.HeroClass];
  145.             foreach(BuffRule t in r.Rules)
  146.                 if (t.PowerSno == b.SnoPower.Sno)
  147.                     return true;
  148.             return false;
  149.         }
  150.  
  151.         private string DataOnBuff(IBuff b){
  152.             string res = "";
  153.             res += b.SnoPower.Sno.ToString() + " \t";
  154.             res += "["+string.Join(",", b.IconCounts)+"]" + "\t";
  155.             res += b.Active.ToString() + " \t";
  156.             res += b.SnoPower.NameLocalized + " \t";
  157.             res += b.SnoPower.Code + " \t";
  158.             //res += t.SnoPower.DescriptionEnglish;  
  159.             return res;
  160.         }
  161.  
  162.         public void DisplayOnAll(params uint[] pwrs){
  163.             foreach(HeroClass h in Enum.GetValues(typeof(HeroClass)))
  164.                 AddPower(RuleCalculators[h], pwrs);
  165.             AddPower(RuleCalculatorMe, pwrs);      
  166.         }
  167.  
  168.         public void DisplayOnMe(params uint[] pwrs){
  169.             AddPower(RuleCalculatorMe, pwrs);
  170.         }
  171.  
  172.         public void DisplayOnAllClassesExceptMe(params uint[] pwrs){
  173.             foreach(HeroClass h in Enum.GetValues(typeof(HeroClass)))
  174.                 AddPower(RuleCalculators[h], pwrs);      
  175.         }
  176.  
  177.         public void DisplayOnClassExceptMe(HeroClass h, params uint[] pwrs){
  178.             AddPower(RuleCalculators[h], pwrs);
  179.         }
  180.  
  181.         private void AddPower(BuffRuleCalculator bf, params uint[] pwrs){
  182.             if (pwrs == null) return;
  183.             foreach(uint p in pwrs)
  184.                 AddPower(bf, p);
  185.         }
  186.  
  187.         private void AddPower(BuffRuleCalculator bf, uint pwr){
  188.             var buffRules = buffRuleFactory.CreateBuffRules(pwr);       //ty jack!
  189.             if (buffRules != null){
  190.                 bf.Rules.AddRange(buffRules);
  191.             }
  192.         }
  193.     }
  194. }
Add Comment
Please, Sign In to add comment