Code:
using System;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using Turbo.Plugins.Default;
namespace Turbo.Plugins.DAV
{
public class DAV_GRPylonPlugin : BasePlugin, IInGameWorldPainter {
public IFont Font_Used { get; set; }
public IFont Font_SameLvl { get; set; }
public IFont Font_DiffLvl { get; set; }
public DAV_PylonInfo[] grPylon { get; set; } = new DAV_PylonInfo[5];
public double pylonChanceLow { get; set; } = 30d;
public double pylonChanceHigh { get; set; } = 60d;
public WorldDecoratorCollection PossiblePylonDecorator_low { get; set; }
public WorldDecoratorCollection PossiblePylonDecorator_middle { get; set; }
public WorldDecoratorCollection PossiblePylonDecorator_high { get; set; }
public double chanceMultiplier { get; set; } = 2d;
public string PossiblePylonMessage { get; set; } = "pylon?";
public string message_percent { get; set; } = "Last Pylon";
public string message_pylonChance { get; set; } = "Chance";
private string message_floor { get; set; } = "Level";
private bool inGR { get; set; } = false;
private int PylonNum { get; set; } = 0;
private double preProgress { get; set; } = 0;
private float py { get; set; }
public DAV_GRPylonPlugin() {
Enabled = true;
}
public override void Load(IController hud) {
base.Load(hud);
py = Hud.Window.Size.Height / 31;
Font_Used = Hud.Render.CreateFont("arial", 7, 255, 170, 170, 170, false, false, 160, 0, 0, 0, true);
Font_SameLvl = Hud.Render.CreateFont("arial", 7, 255, 250, 150, 250, false, false, 160, 0, 0, 0, true);
Font_DiffLvl = Hud.Render.CreateFont("arial", 7, 255, 255, 51, 51, false, false, 160, 0, 0, 0, true);
grPylon[0] = new DAV_PylonInfo("力量", Hud.Texture.GetTexture(2350065673), Hud.Sno.SnoPowers.Generic_PagesBuffDamage.Sno); // Power
grPylon[1] = new DAV_PylonInfo("速度", Hud.Texture.GetTexture(1927801803), Hud.Sno.SnoPowers.Generic_PagesBuffRunSpeed.Sno); // Speed
grPylon[2] = new DAV_PylonInfo("護盾", Hud.Texture.GetTexture(455040081) , Hud.Sno.SnoPowers.Generic_PagesBuffInvulnerable.Sno); // Shield
grPylon[3] = new DAV_PylonInfo("引能", Hud.Texture.GetTexture(3254056115), Hud.Sno.SnoPowers.Generic_PagesBuffInfiniteCasting.Sno); // Channeling
grPylon[4] = new DAV_PylonInfo("幻雷", Hud.Texture.GetTexture(1751750314), Hud.Sno.SnoPowers.Generic_PagesBuffElectrifiedTieredRift.Sno); // Condit
PossiblePylonDecorator_low = new WorldDecoratorCollection(
new MapShapeDecorator(Hud) {
Brush = Hud.Render.CreateBrush(192, 255, 55, 55, 3),
ShadowBrush = Hud.Render.CreateBrush(96, 0, 0, 0, 1),
Radius = 5.0f,
ShapePainter = new CircleShapePainter(Hud),
},
new MapLabelDecorator(Hud) {
LabelFont = Hud.Render.CreateFont("tahoma", 6f, 192, 255, 55, 55, false, false, 128, 0, 0, 0, true),
RadiusOffset = 5.0f,
}
);
PossiblePylonDecorator_middle = new WorldDecoratorCollection(
new MapShapeDecorator(Hud) {
Brush = Hud.Render.CreateBrush(192, 255, 255, 55, 3),
ShadowBrush = Hud.Render.CreateBrush(96, 0, 0, 0, 1),
Radius = 5.0f,
ShapePainter = new CircleShapePainter(Hud),
},
new MapLabelDecorator(Hud) {
LabelFont = Hud.Render.CreateFont("tahoma", 6f, 192, 255, 255, 55, false, false, 128, 0, 0, 0, true),
RadiusOffset = 5.0f,
}
);
PossiblePylonDecorator_high = new WorldDecoratorCollection(
new MapShapeDecorator(Hud) {
Brush = Hud.Render.CreateBrush(192, 55, 255, 55, 3),
ShadowBrush = Hud.Render.CreateBrush(96, 0, 0, 0, 1),
Radius = 5.0f,
ShapePainter = new CircleShapePainter(Hud),
},
new MapLabelDecorator(Hud) {
LabelFont = Hud.Render.CreateFont("tahoma", 6f, 192, 55, 255, 55, false, false, 128, 0, 0, 0, true),
RadiusOffset = 5.0f,
}
);
}
public void PaintWorld(WorldLayer layer) {
if (Hud.Game.SpecialArea != SpecialArea.GreaterRift) return;
var percent = Hud.Game.RiftPercentage;
if (percent <= 0) {
if (!inGR) {
PylonClear();
inGR = true;
return;
}
}
else inGR = false;
var ui = Hud.Render.GreaterRiftBarUiElement;
if (!ui.Visible) return;
foreach (var actor in Hud.Game.Shrines) {
var powerRank = -1;
switch (actor.SnoActor.Sno) {
case ActorSnoEnum._x1_lr_shrine_damage : powerRank = 0; break;
case ActorSnoEnum._x1_lr_shrine_run_speed : powerRank = 1; break;
case ActorSnoEnum._x1_lr_shrine_invulnerable : powerRank = 2; break;
case ActorSnoEnum._x1_lr_shrine_infinite_casting : powerRank = 3; break;
case ActorSnoEnum._x1_lr_shrine_electrified_tieredrift : powerRank = 4; break;
}
if (powerRank == -1) continue;
if (actor.IsDisabled || actor.IsOperated) {
if (grPylon[powerRank].Used(string.IsNullOrEmpty(message_floor) ? Hud.Game.Me.SnoArea.NameEnglish : Hud.Game.Me.SnoArea.NameEnglish.Replace("Rift Level", message_floor), percent, PylonNum, preProgress))
PylonAdd(percent);
}
else if (grPylon[powerRank].Add(string.IsNullOrEmpty(message_floor) ? Hud.Game.Me.SnoArea.NameEnglish : Hud.Game.Me.SnoArea.NameEnglish.Replace("Rift Level", message_floor), percent, PylonNum, preProgress))
PylonAdd(percent);
}
for (var i = 0; i < 5; i++) {
if (grPylon[i].state == 2) continue;
if (Hud.Game.Players.Any(y => y.Powers.BuffIsActive(grPylon[i].sno, 0)))
if (grPylon[i].Used(string.IsNullOrEmpty(message_floor) ? Hud.Game.Me.SnoArea.NameEnglish : Hud.Game.Me.SnoArea.NameEnglish.Replace("Rift Level", message_floor), percent, PylonNum, preProgress))
PylonAdd(percent);
}
var uiRect = ui.Rectangle;
for (var j = 0; j < 5; j++) {
if (grPylon[j].state == 0) continue;
var pylonFont = grPylon[j].state == 2 ? Font_Used : (grPylon[j].area == Hud.Game.Me.SnoArea.NameEnglish ? Font_SameLvl : Font_DiffLvl);
var layout = pylonFont.GetTextLayout(grPylon[j].getInfo());
var size = layout.Metrics.Height;
var yref = uiRect.Bottom + py + grPylon[j].rank*size;
grPylon[j].buffIcon.Draw(uiRect.Left, yref, size, size);
pylonFont.DrawText(layout, uiRect.Left + 1.5f * size, yref);
size = uiRect.Height / 2;
var xref = uiRect.Left + (float)(grPylon[j].progress1) * uiRect.Width / 100;
if (grPylon[j].rank == 1 || grPylon[j].rank == 3)
yref = uiRect.Top + size;
else yref = uiRect.Top;
grPylon[j].buffIcon.Draw(xref - size, yref, size, size);
}
if (PylonNum < 4 && percent < 100) {
var pylonChance = Math.Min((percent - preProgress) * chanceMultiplier, 100d);
var layout = Font_SameLvl.GetTextLayout(message_percent + " : " + (percent - preProgress).ToString("F1") + "% (" + message_pylonChance + " : " + pylonChance.ToString("F1") + "%)");
Font_SameLvl.DrawText(layout, uiRect.Left + (uiRect.Width - layout.Metrics.Width) / 2 , uiRect.Bottom + uiRect.Height * 0.2f);
var PossibleRiftPylonDecorator = pylonChance < pylonChanceLow ? PossiblePylonDecorator_low : (pylonChance < pylonChanceHigh ? PossiblePylonDecorator_middle : PossiblePylonDecorator_high);
var riftPylonSpawnPoints = Hud.Game.Actors.Where(x => x.SnoActor.Sno == ActorSnoEnum._markerlocation_tieredriftpylon);
foreach (var actor in riftPylonSpawnPoints)
PossibleRiftPylonDecorator.Paint(layer, actor, actor.FloorCoordinate, PossiblePylonMessage);
}
}
public void PylonClear() {
PylonNum = 0;
preProgress = 0;
for (var i = 0; i < 5; i++)
grPylon[i].Clear();
}
public void PylonAdd(double curProgress) {
PylonNum++;
preProgress = curProgress;
}
}
public class DAV_PylonInfo {
public string name { get; set; }
public uint sno { get; set; }
public int state { get; set; } // 0 no pylon, 1 not used, 2 used
public int rank { get; set; }
public string area { get; set; }
public double progress1 { get; set; }
public double progress2 { get; set; }
public ITexture buffIcon { get; set; }
public DAV_PylonInfo(string desc, ITexture Icon, uint actorSno) {
name = desc;
sno = actorSno;
buffIcon = Icon;
state = 0;
}
public bool Add(string grLvl, double curProgress, int numPylon, double lastProgress) {
area = grLvl;
if (state > 0) return false;
state = 1;
rank = numPylon;
progress1 = curProgress;
progress2 = lastProgress;
return true;
}
public bool Used(string grLvl, double curProgress, int numPylon, double lastProgress) {
if (state == 2) return false;
area = grLvl;
if (state == 0) {
rank = numPylon;
progress1 = curProgress;
progress2 = lastProgress;
state = 2;
return true;
}
state = 2;
return false;
}
public void Clear() { state = 0; }
public string getInfo() {
if (state == 0) return "";
var message = progress1.ToString("F1") + "%\t" + name + "\t" + area;
if (rank > 0)
message += "\t[+" + (progress1 - progress2).ToString("F1") + "%]";
return message;
}
}
}