Code:
using System;
using Turbo.Plugins.Default;
using System.Linq;
using System.Collections.Generic;
using SharpDX;
using SharpDX.Direct2D1;
namespace Turbo.Plugins.RNN
{
public class SpiritBarrageAndCoE : BasePlugin, IInGameTopPainter
{
private int[] _IndexToBonus = new int[8] { 7, 5, 3, 1, 6, 2, 0, 4 };
private List<int> _WDBonusElements = new List<int> {3,6,7,2}; // 1 = Arcane, 2 = Cold, 3 = Fire, 4 = Holy, 5 = Lightning, 6 = Physical, 7 = Poison
private float _SizeIconWidth;
private float _SizeIconHeight;
private float _CurrentX;
private float _CurrentY;
public IFont FontCoeNoBestElement { get; set; }
public IFont FontCoeActiveElement { get; set; }
public IFont FontCoeBestElementActive { get; set; }
public IFont FontCoeBestElementWarn { get; set; }
public IFont FontCoeBestElementInactive { get; set; }
public IFont FontCoeElementBonus { get; set; }
public IFont FontNoStacksTimeLeft { get; set; }
public IFont FontGlobeCount { get; set; }
public IFont FontStacks { get; set; }
public IFont FontTimeLeft { get; set; }
public IFont FontStacksNone { get; set; }
public IBrush TimeLeftClockBrush { get; set; }
public IBrush BrushGlobesBackground { get; set; }
public IBrush BrushCoeBackground { get; set; }
public IBrush BrushCoeBestElementActive { get; set; }
public IBrush BrushCoeBestElementWarn { get; set; }
public IBrush BrushCoeBestElementInactive { get; set; }
public IBrush BrushCoeNoPrimaryElement { get; set; }
public IBrush BrushDefault { get; set; }
public float OffsetX { get; set; }
public float OffsetY { get; set; }
public bool ShowIndividualPhantasms { get; set; }
public bool ShowSoulHarvest { get; set; }
public bool ShowBigBadVoodoo { get; set; }
public bool ShowRushOfEssence { get; set; }
public bool ShowGruesomeFeast { get; set; }
public bool ShowGlobes { get; set; }
public bool ShowCoe { get; set; }
public bool OnlyGR { get; set; }
public bool OnlyMe { get; set; }
public float Opacity { get; set; }
private float _SizeMultiplier;
public float SizeMultiplier {
get { return _SizeMultiplier; }
set {
_SizeMultiplier = value;
_SizeIconWidth = Hud.Texture.BuffFrameTexture.Width * _SizeMultiplier;
_SizeIconHeight = Hud.Texture.BuffFrameTexture.Height * _SizeMultiplier;
}
}
public SpiritBarrageAndCoE() {
Enabled = true;
}
public override void Load(IController hud) {
base.Load(hud);
Order = 30001;
OffsetX = 0.75f; // To set the x coordinate of the icon
OffsetY = 0.05f; // To set the y coordinate of the icon
SizeMultiplier = 0.9f; // Size multiplier for icons
ShowSoulHarvest = true; // Show SoulHarvest status for WD
ShowBigBadVoodoo = true; // Show BigBadVoodoo status for WD
ShowRushOfEssence = true; // Show RushOfEssence status for WD
ShowGruesomeFeast = true; // Show GruesomeFeast status for WD
ShowGlobes = true; // Health Globes Counter (floor)
ShowCoe = true; // Show COE status for WD
ShowIndividualPhantasms = true; // Show Phantasm status seperately for WD
OnlyMe = false; // Show only for my character
OnlyGR = false; // Show in GR only
Opacity = 0.85f; // 0f..1f Opacity for icon texture
var OpacityBrush = (int) (Opacity * 255);
FontNoStacksTimeLeft = Hud.Render.CreateFont("tahoma", 10f * SizeMultiplier, 255, 0, 255, 0, true, false, 255, 0, 0, 0, true); // Green
FontStacks = Hud.Render.CreateFont("tahoma", 10f * SizeMultiplier, 255, 255, 225, 0, true, false, 160, 0, 0, 0, true);
FontStacksNone = Hud.Render.CreateFont("tahoma", 10f * SizeMultiplier, 255, 255, 0, 0, true, false, 160, 0, 0, 0, true);
FontTimeLeft = Hud.Render.CreateFont("tahoma", 8f * SizeMultiplier, 255, 0, 255, 0, true, false, 255, 0, 0, 0, true);
TimeLeftClockBrush = Hud.Render.CreateBrush(220, 0, 0, 0, 0);
FontGlobeCount = Hud.Render.CreateFont("tahoma", 9f, 255, 255, 255, 255, true, false, 255, 0, 0, 0, true); //White
BrushGlobesBackground = Hud.Render.CreateBrush(OpacityBrush, 255, 50 , 50, 0);
FontCoeNoBestElement = Hud.Render.CreateFont("tahoma", 9f * SizeMultiplier, 255, 255, 255, 255, true, false, 255, 0, 0, 0, true); // White
FontCoeActiveElement = Hud.Render.CreateFont("tahoma", 8f * SizeMultiplier, 235, 235, 235, 235, true, false, 255, 0, 0, 0, true); // Grey
FontCoeBestElementActive = Hud.Render.CreateFont("tahoma", 12f * SizeMultiplier, 255, 0, 255, 0, true, false, 255, 0, 0, 0, true); // Green
FontCoeBestElementWarn = Hud.Render.CreateFont("tahoma", 12f * SizeMultiplier, 255, 255, 255, 0, true, false, 255, 0, 0, 0, true); // Yellow
FontCoeBestElementInactive = Hud.Render.CreateFont("tahoma", 12f * SizeMultiplier, 255, 255, 150, 0, true, false, 255, 0, 0, 0, true); // Orange
FontCoeElementBonus = Hud.Render.CreateFont("tahoma", 8f * SizeMultiplier, 255, 50, 150, 250, true, false, 255, 0, 0, 0, true); // Blue
BrushCoeBackground = Hud.Render.CreateBrush(255, 80, 80, 80, 0); // Grey
BrushCoeBestElementActive = Hud.Render.CreateBrush(255, 0, 255 , 0, 0); // Green
BrushCoeBestElementWarn = Hud.Render.CreateBrush(255, 255, 255 , 0, 0); // Yellow
BrushCoeBestElementInactive = Hud.Render.CreateBrush(255, 255, 185 , 0, 0); // Orange
BrushCoeNoPrimaryElement = Hud.Render.CreateBrush(255, 50, 150 , 250, 0); // Blue
}
private void DrawTimeLeftClock(RectangleF rect, double elapsed, double timeLeft) { // plugins\Default\BuffLists\Painter\BuffPainter.cs
if ((timeLeft > 0) && (elapsed >= 0) && (TimeLeftClockBrush != null)) {
var endAngle = Convert.ToInt32(360.0d / (timeLeft + elapsed) * elapsed);
var startAngle = 0;
TimeLeftClockBrush.Opacity = 1 - (float)(0.3f / (timeLeft + elapsed) * elapsed);
var rad = rect.Width * 0.45f;
using (var pg = Hud.Render.CreateGeometry()) {
using (var gs = pg.Open()) {
gs.BeginFigure(rect.Center, FigureBegin.Filled);
for (var angle = startAngle; angle <= endAngle; angle++) {
var mx = rad * (float)Math.Cos((angle - 90) * Math.PI / 180.0f);
var my = rad * (float)Math.Sin((angle - 90) * Math.PI / 180.0f);
var vec = new Vector2(rect.Center.X + mx, rect.Center.Y + my);
gs.AddLine(vec);
}
gs.EndFigure(FigureEnd.Closed);
gs.Close();
}
TimeLeftClockBrush.DrawGeometry(pg);
}
}
}
public void DrawIcon(uint idtexture, double timeleft, double elapsed, int stacks) {
Hud.Texture.GetTexture(idtexture).Draw(_CurrentX, _CurrentY, _SizeIconWidth, _SizeIconHeight, Opacity);
if (stacks > 0) Hud.Texture.BuffFrameTexture.Draw(_CurrentX, _CurrentY, _SizeIconWidth, _SizeIconHeight, Opacity);
else if ( timeleft <=0) Hud.Texture.DebuffFrameTexture.Draw(_CurrentX, _CurrentY, _SizeIconWidth, _SizeIconHeight, Opacity);
if (timeleft > 0) {
DrawTimeLeftClock(new RectangleF(_CurrentX, _CurrentY , _SizeIconWidth, _SizeIconHeight), elapsed , timeleft);
var layout1 = FontTimeLeft.GetTextLayout(timeleft.ToString( (timeleft < 1)? "F1" : "F0") );
FontTimeLeft.DrawText(layout1, _CurrentX + ((_SizeIconWidth - (float)Math.Ceiling(layout1.Metrics.Width))/5.0f), _CurrentY + ((_SizeIconHeight - (float)Math.Ceiling(layout1.Metrics.Height))/10.0f));
}
var layout2 = FontStacks.GetTextLayout( stacks.ToString() );
(stacks == 0?FontStacksNone:FontStacks).DrawText(layout2, _CurrentX + _SizeIconWidth - (float)Math.Ceiling(layout2.Metrics.Width) - 3, _CurrentY + _SizeIconHeight - (float)Math.Ceiling(layout2.Metrics.Height) - 1 );
_CurrentX += _SizeIconWidth;
}
public void DrawIconNoStacks(uint idtexture, double timeleft, double elapsed) {
Hud.Texture.GetTexture(idtexture).Draw(_CurrentX, _CurrentY, _SizeIconWidth, _SizeIconHeight, Opacity);
if ( timeleft > 0) Hud.Texture.BuffFrameTexture.Draw(_CurrentX, _CurrentY, _SizeIconWidth, _SizeIconHeight, Opacity);
if (timeleft > 0) {
DrawTimeLeftClock(new RectangleF(_CurrentX, _CurrentY , _SizeIconWidth, _SizeIconHeight), elapsed , timeleft);
var layout = FontNoStacksTimeLeft.GetTextLayout(timeleft.ToString( (timeleft < 1)? "F1" : "F0") );
FontNoStacksTimeLeft.DrawText(layout, _CurrentX + ((_SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), _CurrentY + ((_SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/2.0f));
}
_CurrentX += _SizeIconWidth;
}
public void DrawIconNoBuff(uint idtexture) {
Hud.Texture.GetTexture(idtexture).Draw(_CurrentX, _CurrentY, _SizeIconWidth, _SizeIconHeight, Opacity);
Hud.Texture.DebuffFrameTexture.Draw(_CurrentX, _CurrentY, _SizeIconWidth, _SizeIconHeight, Opacity);
_CurrentX += _SizeIconWidth;
}
public void PaintTopInGame(ClipState clipState) {
if (clipState != ClipState.BeforeClip) return;
if (!Hud.Game.IsInGame) return;
if (OnlyGR && !Hud.Game.Me.InGreaterRift) return;
var players = Hud.Game.Players.Where(p => p.HasValidActor && p.Powers.UsedSkills.Any(s => s.SnoPower.Sno == Hud.Sno.SnoPowers.WitchDoctor_SpiritBarrage.Sno /* && s.Rune == 4 */ )).OrderBy(p => p.PortraitIndex); // 108506
if (players.Count() == 0) return;
_CurrentY = Hud.Window.Size.Height * OffsetY ;
foreach(var player in players) {
if (OnlyMe && !player.IsMe) continue;
_CurrentX = Hud.Window.Size.Width * OffsetX;
IPlayerSkill SpiritBarrage = player.Powers.UsedWitchDoctorPowers.SpiritBarrage;
if (SpiritBarrage != null) {
double TimeElapsedSeconds = 0d;
double TimeLeftSeconds = 0d;
var Phantasms = Hud.Game.Actors.Where(a => a.SnoActor.Sno == ActorSnoEnum._wd_spiritbarragerune_aoe_ghostmodel && (a.SummonerAcdDynamicId == player.SummonerId)).OrderByDescending(a => a.CreatedAtInGameTick);
if (ShowIndividualPhantasms)
{
int NumPhantasms = 0;
foreach (var Phantasm in Phantasms){
if (NumPhantasms++ == 3) break;
TimeElapsedSeconds = (Hud.Game.CurrentGameTick - Phantasm.CreatedAtInGameTick) / 60d;
TimeLeftSeconds = (player.Powers.BuffIsActive(Hud.Sno.SnoPowers.GazingDemise.Sno, 0) ? 10d : 5d) - TimeElapsedSeconds; //484270
DrawIconNoStacks(SpiritBarrage.SnoPower.NormalIconTextureId, TimeLeftSeconds, TimeElapsedSeconds); // 1117784160
}
for (var NoPhantasmCount = NumPhantasms; NoPhantasmCount < 3; NoPhantasmCount++) {
DrawIconNoBuff(Hud.Sno.SnoPowers.WitchDoctor_SpiritBarrage.NormalIconTextureId);
}
_CurrentX = Hud.Window.Size.Width * OffsetX; _CurrentY = _CurrentY + _SizeIconHeight;
}
else {
if (Phantasms.Count()>0){
TimeElapsedSeconds = (Hud.Game.CurrentGameTick - Phantasms.First().CreatedAtInGameTick) / 60d;
TimeLeftSeconds = (player.Powers.BuffIsActive(Hud.Sno.SnoPowers.GazingDemise.Sno, 0) ? 10d : 5d) - TimeElapsedSeconds; //484270
}
DrawIcon(SpiritBarrage.SnoPower.NormalIconTextureId, TimeLeftSeconds, TimeElapsedSeconds, Math.Min(Phantasms.Count(),3)); // 1117784160
}
}
if (ShowSoulHarvest) {
IPlayerSkill SoulHarvest = player.Powers.UsedWitchDoctorPowers.SoulHarvest;
if (SoulHarvest != null) {
if (SoulHarvest.Buff != null) {
DrawIcon(SoulHarvest.SnoPower.NormalIconTextureId, SoulHarvest.Buff.TimeLeftSeconds[0], SoulHarvest.Buff.TimeElapsedSeconds[0], SoulHarvest.Buff.IconCounts[0]); // 2196086897
}
else {
DrawIcon(SoulHarvest.SnoPower.NormalIconTextureId, 0, 0, 0); // 2196086897
}
}
else {
DrawIconNoBuff(Hud.Sno.SnoPowers.WitchDoctor_SoulHarvest.NormalIconTextureId);// 2196086897
}
}
if (ShowBigBadVoodoo) {
IPlayerSkill BigBadVoodoo = player.Powers.UsedWitchDoctorPowers.BigBadVoodoo;
if (BigBadVoodoo != null) {
double CooldownRemaining = 0d;
double CooldownElapsed = 0d;
if (BigBadVoodoo.CooldownFinishTick > Hud.Game.CurrentGameTick) {
CooldownRemaining = (BigBadVoodoo.CooldownFinishTick - Hud.Game.CurrentGameTick) / 60.0d;
CooldownElapsed = (Hud.Game.CurrentGameTick - BigBadVoodoo.CooldownStartTick) / 60.0d;
}
DrawIcon(BigBadVoodoo.SnoPower.NormalIconTextureId, CooldownRemaining, CooldownElapsed, (int)(BigBadVoodoo.Buff != null? BigBadVoodoo.Buff.TimeLeftSeconds[4] : 0));
}
else {
DrawIconNoBuff(Hud.Sno.SnoPowers.WitchDoctor_BigBadVoodoo.NormalIconTextureId);
}
}
if (ShowRushOfEssence) {
IBuff BuffRushOfEssence = player.Powers.GetBuff(Hud.Sno.SnoPowers.WitchDoctor_Passive_RushOfEssence.Sno); // 208594
if (BuffRushOfEssence != null && BuffRushOfEssence.Active) {
DrawIcon(Hud.Sno.SnoPowers.WitchDoctor_Passive_RushOfEssence.NormalIconTextureId, BuffRushOfEssence.TimeLeftSeconds[1], BuffRushOfEssence.TimeElapsedSeconds[1], BuffRushOfEssence.IconCounts[1]);
}
}
if (ShowGruesomeFeast) {
IBuff BuffGruesomeFeast = player.Powers.GetBuff(Hud.Sno.SnoPowers.WitchDoctor_Passive_GruesomeFeast.Sno); // 208594
if (BuffGruesomeFeast != null && BuffGruesomeFeast.Active) {
DrawIcon(Hud.Sno.SnoPowers.WitchDoctor_Passive_GruesomeFeast.NormalIconTextureId, BuffGruesomeFeast.TimeLeftSeconds[1], BuffGruesomeFeast.TimeElapsedSeconds[1], BuffGruesomeFeast.IconCounts[1]); // 1591242582
}
}
if (ShowGlobes) {
var HealthGlobeCount = Hud.Game.Actors.Where(a => a.SnoActor.Kind == ActorKind.HealthGlobe).Count();
if (HealthGlobeCount > 0) {
var layout = FontGlobeCount.GetTextLayout(HealthGlobeCount.ToString());
BrushGlobesBackground.DrawEllipse(_CurrentX + _SizeIconWidth / 2 , _CurrentY + _SizeIconHeight / 2 , layout.Metrics.Width + 1, layout.Metrics.Width + 1);
FontGlobeCount.DrawText(layout,_CurrentX + (_SizeIconWidth - layout.Metrics.Width) / 2 , _CurrentY + (_SizeIconHeight - layout.Metrics.Height) / 2 );
_CurrentX += _SizeIconWidth;
}
}
if (_CurrentX != Hud.Window.Size.Width * OffsetX)
{
_CurrentY = _CurrentY + _SizeIconHeight;
_CurrentX = Hud.Window.Size.Width * OffsetX;
}
var CoEBarheight = _SizeIconHeight * 0.1f;
_CurrentY = _CurrentY + CoEBarheight;
if (ShowCoe){
IBuff BuffCoE = player.Powers.GetBuff(Hud.Sno.SnoPowers.ConventionOfElements.Sno); // 430674
if (BuffCoE != null)
{
var j = _WDBonusElements.Count; var ActiveElement = -1; var BestElement = -1; double MaxBonus = -1; bool UniqueBestElement = false;
for(var k = j - 1; k > -1 ; k--)
{
var index = _WDBonusElements[k];
if (BuffCoE.IconCounts[index] > 0) { ActiveElement = index; }
var bonus = player.Offense.ElementalDamageBonus[_IndexToBonus[index]];
if (bonus > MaxBonus)
{
MaxBonus = bonus;
BestElement = index;
UniqueBestElement = true;
}
else if (bonus == MaxBonus) UniqueBestElement = false;
}
if ((ActiveElement != -1) && (BestElement != -1) )
{
for (var l = 0; l < j; l++)
{
if (_WDBonusElements[j - 1] != BestElement)
{
_WDBonusElements.Insert(0,_WDBonusElements[j - 1]);
_WDBonusElements.RemoveAt(j);
}
else { break; }
}
foreach(var index in _WDBonusElements)
{
IFont FontDefault = null;
Hud.Texture.GetTexture(BuffCoE.SnoPower.Icons[index].TextureId).Draw(_CurrentX, _CurrentY, _SizeIconWidth, _SizeIconHeight, Opacity);
DrawTimeLeftClock(new RectangleF(_CurrentX, _CurrentY, _SizeIconWidth, _SizeIconHeight), BuffCoE.TimeElapsedSeconds[index], BuffCoE.TimeLeftSeconds[index]);
double s = 0;
if (UniqueBestElement)
{
if (index == ActiveElement)
{
s = BuffCoE.TimeLeftSeconds[index];
if (index == BestElement) { FontDefault = FontCoeBestElementActive; BrushDefault = BrushCoeBestElementActive; }
else { FontDefault = FontCoeActiveElement; }
Hud.Texture.BuffFrameTexture.Draw(_CurrentX, _CurrentY, _SizeIconWidth, _SizeIconHeight, Opacity);
}
else
{
if (index == BestElement)
{
s = (j - _WDBonusElements.IndexOf(ActiveElement) - 1) * 4 - BuffCoE.TimeElapsedSeconds[ActiveElement] ;
if ( s > ((j - 1) * 2) ) { FontDefault = FontCoeBestElementInactive; BrushDefault = BrushCoeBestElementInactive; }
else { FontDefault = FontCoeBestElementWarn; BrushDefault = BrushCoeBestElementWarn; }
}
Hud.Texture.DebuffFrameTexture.Draw(_CurrentX, _CurrentY, _SizeIconWidth, _SizeIconHeight, Opacity);
}
}
else
{
if (player.Offense.ElementalDamageBonus[_IndexToBonus[index]] == player.Offense.HighestElementalDamageBonus)
{
var layout1 = FontCoeElementBonus.GetTextLayout( (player.Offense.HighestElementalDamageBonus * 100).ToString() );
FontCoeElementBonus.DrawText(layout1, _CurrentX + _SizeIconWidth - (float)Math.Ceiling(layout1.Metrics.Width) - 3, _CurrentY + _SizeIconHeight - (float)Math.Ceiling(layout1.Metrics.Height) - 2);
}
s = BuffCoE.TimeLeftSeconds[index];
BrushDefault = BrushCoeNoPrimaryElement; FontDefault = FontCoeNoBestElement;
}
if (s > 0)
{
var layout2 = FontDefault.GetTextLayout(s.ToString( (s < 1)? "F1" : "F0") );
FontDefault.DrawText(layout2, _CurrentX + ((_SizeIconWidth - (float)Math.Ceiling(layout2.Metrics.Width))/2.0f), _CurrentY + ((_SizeIconHeight - (float)Math.Ceiling(layout2.Metrics.Height))/2.0f));
}
_CurrentX += _SizeIconWidth;
}
BrushCoeBackground.DrawRectangle(_CurrentX, _CurrentY - CoEBarheight, - _SizeIconWidth * j , CoEBarheight);
BrushDefault.DrawRectangle(_CurrentX, _CurrentY - CoEBarheight, (float) ( (_SizeIconWidth * ( (j - _WDBonusElements.IndexOf(ActiveElement)) * 4 - BuffCoE.TimeElapsedSeconds[ActiveElement] )) / -4) , CoEBarheight);
_CurrentX = Hud.Window.Size.Width * OffsetX; _CurrentY = _CurrentY + _SizeIconHeight;
}
}
}
_CurrentY = _CurrentY + _SizeIconHeight / 2;
}
}
}
}