Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using Turbo.Plugins.Default;
- namespace Turbo.Plugins.DavPlayer
- {
- public class DAV_COE : BasePlugin, IInGameTopPainter, ICustomizer {
- public float offsetX { get; set; } = 0.45f; // Percent-X pos me
- public float offsetY { get; set; } = 0.65f; // Percent-Y pos me
- public bool ShowParty { get; set; } = true;
- public float partyOffsetX { get; set; } = 0.00f; // Percent-X pos for other players
- public float partyOffsetY { get; set; } = 0.18f; // Percent-Y pos for other players -0.27 for default plug-in
- public float CoeBarH { get; set; } = 10.0f; // COE bar height
- public bool ShowCoeTime { get; set; } = true; // Show time until highest elemental
- public string CoeMaxIndicator { get; set; } = "Max";
- public IFont CoeTimeFont { get; set; }
- public GroundLabelDecorator AttackFont1 { get; set; }
- public GroundLabelDecorator AttackFont2 { get; set; }
- public float MeOffsetX { get; set; } = -10f;
- public float MeOffsetY { get; set; } = -10f;
- public IBrush BackgroundBrush { get; set; }
- public IBrush GreenBrush { get; set; }
- public IBrush YellowBrush { get; set; }
- public IBrush RedBrush { get; set; }
- public BuffPainter COEPainter { get; set; }
- private BuffRuleCalculator CoeRuleCalculator;
- public bool SpeakOK { get; set; } = true;
- public double VolumeMultiplier { get; set; } = 2.0; // Set to 1 for default volume, -1 to disable setting.
- public double Attacktime2 { get; set; } = 4.0; // for other player, change to yellow bar before max bonus
- public Dictionary<HeroClass, Tuple<double, string, int, int>> TimeRule { get; set; }
- public DAV_COE() {
- Enabled = true;
- }
- public override void Load(IController hud) {
- base.Load(hud);
- if (VolumeMultiplier > 0 && Hud.Sound.VolumeMultiplier != VolumeMultiplier)
- Hud.Sound.VolumeMultiplier = VolumeMultiplier;
- CoeTimeFont = Hud.Render.CreateFont("arial", 9, 255, 255, 255, 255, false, false, 255, 0, 0, 0, true);
- AttackFont1 = new GroundLabelDecorator(hud) {
- TextFont = Hud.Render.CreateFont("arial", 15, 255, 255, 255, 51, true, true, 255, 255, 51, 51, true),
- };
- AttackFont2 = new GroundLabelDecorator(hud) {
- TextFont = Hud.Render.CreateFont("arial", 15, 255, 255, 51, 51, true, true, 255, 255, 255, 51, true),
- };
- BackgroundBrush = Hud.Render.CreateBrush(255, 200, 200, 200, 0);
- GreenBrush = Hud.Render.CreateBrush(240, 128, 255, 0, 0);
- YellowBrush = Hud.Render.CreateBrush(240, 255, 255, 102, 0);
- RedBrush = Hud.Render.CreateBrush(240, 255, 51, 51, 0);
- // attack time before max bonus | the message | role of your character | message type
- // Role : -2 no speak
- // -1 speak all the time except in town
- // 0 speak all the time in GR
- // 1 speak as trash killer in GR
- // 2 speak as RGK in GR
- // Message type : -1 none
- // 0 text
- // 1 sound
- // 2 sound + text
- TimeRule = new Dictionary<HeroClass, Tuple<double, string, int, int>> {
- {HeroClass.Barbarian, new Tuple<double, string, int, int>(4.0, "Attack", 0, 2)},
- {HeroClass.Monk, new Tuple<double, string, int, int>(4.0, "Attack", 0, 2)},
- {HeroClass.Necromancer, new Tuple<double, string, int, int>(1.0, "Charge", 2, 2)},
- {HeroClass.Wizard, new Tuple<double, string, int, int>(4.0, "Attack", 1, 2)},
- {HeroClass.WitchDoctor, new Tuple<double, string, int, int>(4.0, "Attack", 0, 2)},
- {HeroClass.Crusader, new Tuple<double, string, int, int>(4.0, "Attack", 0, 2)},
- {HeroClass.DemonHunter, new Tuple<double, string, int, int>(1.0, "Attack", 0, 2)}
- };
- COEPainter = new BuffPainter(Hud, true) {
- Opacity = 1.0f,
- TimeLeftFont = Hud.Render.CreateFont("arial", 9, 255, 255, 255, 255, true, false, 255, 0, 0, 0, true),
- };
- CoeRuleCalculator = new BuffRuleCalculator(Hud) { SizeMultiplier = 0.85f };
- CoeRuleCalculator.Rules.Add(new BuffRule(430674) { IconIndex = 1, MinimumIconCount = 0, DisableName = true }); // Arcane
- CoeRuleCalculator.Rules.Add(new BuffRule(430674) { IconIndex = 2, MinimumIconCount = 0, DisableName = true }); // Cold
- CoeRuleCalculator.Rules.Add(new BuffRule(430674) { IconIndex = 3, MinimumIconCount = 0, DisableName = true }); // Fire
- CoeRuleCalculator.Rules.Add(new BuffRule(430674) { IconIndex = 4, MinimumIconCount = 0, DisableName = true }); // Holy
- CoeRuleCalculator.Rules.Add(new BuffRule(430674) { IconIndex = 5, MinimumIconCount = 0, DisableName = true }); // Lightning
- CoeRuleCalculator.Rules.Add(new BuffRule(430674) { IconIndex = 6, MinimumIconCount = 0, DisableName = true }); // Physical
- CoeRuleCalculator.Rules.Add(new BuffRule(430674) { IconIndex = 7, MinimumIconCount = 0, DisableName = true }); // Poison
- }
- private IEnumerable<BuffRule> GetCurrentRules(HeroClass heroClass) {
- for (int i = 1; i <= 7; i++) {
- switch (heroClass) {
- case HeroClass.Barbarian: if (i == 1 || i == 4 || i == 7) continue; break;
- case HeroClass.Crusader: if (i == 1 || i == 2 || i == 7) continue; break;
- case HeroClass.DemonHunter: if (i == 1 || i == 4 || i == 7) continue; break;
- case HeroClass.Monk: if (i == 1 || i == 7) continue; break;
- case HeroClass.Necromancer: if (i == 1 || i == 3 || i == 4 || i == 5) continue; break;
- case HeroClass.WitchDoctor: if (i == 1 || i == 4 || i == 5) continue; break;
- case HeroClass.Wizard: if (i == 4 || i == 6 || i == 7) continue; break;
- }
- yield return CoeRuleCalculator.Rules[i - 1];
- }
- }
- public void PaintTopInGame(ClipState clipState) {
- if (clipState != ClipState.BeforeClip) return;
- foreach (var player in Hud.Game.Players) {
- if (!player.HasValidActor) continue;
- if (!player.IsMe && !ShowParty) continue;
- var buff = player.Powers.GetBuff(430674);
- if ((buff == null) || (buff.IconCounts[0] <= 0)) continue;
- var classSpecificRules = GetCurrentRules(player.HeroClassDefinition.HeroClass);
- CoeRuleCalculator.CalculatePaintInfo(player, classSpecificRules);
- var NumElement = CoeRuleCalculator.PaintInfoList.Count;
- var best = false;
- var maxindex = 0;
- var curindex = 0;
- var timeLeft = 0.0d;
- var highestElementalBonus = player.Offense.HighestElementalDamageBonus;
- for (int i = NumElement - 1; i >= 0; i--) {
- var info = CoeRuleCalculator.PaintInfoList[i];
- switch (info.Rule.IconIndex) {
- case 1: best = player.Offense.BonusToArcane == highestElementalBonus; break;
- case 2: best = player.Offense.BonusToCold == highestElementalBonus; break;
- case 3: best = player.Offense.BonusToFire == highestElementalBonus; break;
- case 4: best = player.Offense.BonusToHoly == highestElementalBonus; break;
- case 5: best = player.Offense.BonusToLightning == highestElementalBonus; break;
- case 6: best = player.Offense.BonusToPhysical == highestElementalBonus; break;
- case 7: best = player.Offense.BonusToPoison == highestElementalBonus; break;
- }
- if (best && maxindex == 0) { maxindex = i + 1; }
- if (info.TimeLeft > 0.0f) {
- curindex = i + 1;
- timeLeft = curindex * 4d - info.TimeLeft;
- }
- }
- if (maxindex < curindex) timeLeft -= maxindex * 4;
- else timeLeft += (NumElement - maxindex) * 4;
- for (int i = 0; i < maxindex; i++) {
- var info = CoeRuleCalculator.PaintInfoList[0];
- CoeRuleCalculator.PaintInfoList.RemoveAt(0);
- CoeRuleCalculator.PaintInfoList.Add(info);
- }
- var barW = CoeRuleCalculator.StandardIconSize * NumElement;
- var barH = CoeBarH;
- var timeW = NumElement * 4;
- var eleW = (float) timeLeft / timeW * barW;
- float x, y;
- double timeyellow;
- if (player.IsMe) {
- x = Hud.Window.Size.Width * offsetX;
- y = Hud.Window.Size.Height * offsetY;
- timeyellow = timeW - 4 - TimeRule[player.HeroClassDefinition.HeroClass].Item1;
- }
- else {
- var portraitRect = player.PortraitUiElement.Rectangle;
- x = portraitRect.Right + portraitRect.Width * partyOffsetX;
- y = portraitRect.Top + portraitRect.Height * partyOffsetY;
- timeyellow = timeW - 4 - Attacktime2;
- }
- COEPainter.PaintHorizontal(CoeRuleCalculator.PaintInfoList, x, y, CoeRuleCalculator.StandardIconSize, 0);
- BackgroundBrush.DrawRectangle(x, y - barH, barW, barH);
- if (timeLeft > timeW - 4 && highestElementalBonus > 0) {
- RedBrush.DrawRectangle(x, y - barH, eleW, barH);
- if (player.IsMe) {
- Message(timeLeft);
- if (!SpeakOK)
- SpeakOK = true;
- }
- }
- else if (timeLeft > timeyellow && highestElementalBonus > 0) {
- YellowBrush.DrawRectangle(x, y - barH, eleW, barH);
- if (player.IsMe) {
- Message(timeLeft);
- Speak();
- }
- }
- else {GreenBrush.DrawRectangle(x, y - barH, eleW, barH);}
- if (ShowCoeTime && highestElementalBonus > 0) {
- var timeWait = 4 * (NumElement - 1) - timeLeft;
- var layout = CoeTimeFont.GetTextLayout(timeWait > 0 ? timeWait.ToString("F1", CultureInfo.InvariantCulture) : CoeMaxIndicator);
- CoeTimeFont.DrawText(layout, x + barW + CoeRuleCalculator.StandardIconSpacing, y - barH);
- }
- }
- }
- public bool IsGuardianAlive { get { return (Hud.Game.RiftPercentage == 100); } }
- private void Message(double time) {
- if (Hud.Game.IsInTown) return;
- var charRule = TimeRule[Hud.Game.Me.HeroClassDefinition.HeroClass];
- if (charRule.Item4 != 0 && charRule.Item4 != 2) return;
- var MessageEnable = false;
- var role = charRule.Item3;
- if (role == -1)
- MessageEnable = true;
- else if (Hud.Game.SpecialArea == SpecialArea.GreaterRift && role >= 0){
- // var BossState = IsGuardianAlive;
- switch (role) {
- case 0 : MessageEnable = true; break;
- case 1 : MessageEnable = !IsGuardianAlive; break;
- case 2 : MessageEnable = IsGuardianAlive; break;
- }
- }
- if (!MessageEnable) return;
- var textDecorator = time%2 > 1f ? AttackFont1 : AttackFont2;
- textDecorator.Paint(null, Hud.Game.Me.FloorCoordinate.Offset(MeOffsetX, MeOffsetY, 0), charRule.Item2);
- }
- private void Speak() {
- if (Hud.Game.IsInTown || !SpeakOK) return;
- var charRule = TimeRule[Hud.Game.Me.HeroClassDefinition.HeroClass];
- if (charRule.Item4 < 1) return;
- var SpeakEnable = false;
- var role = charRule.Item3;
- if (role == -1)
- SpeakEnable = true;
- else if (Hud.Game.SpecialArea == SpecialArea.GreaterRift && role >= 0){
- // var BossState = IsGuardianAlive;
- switch (role) {
- case 0 : SpeakEnable = true; break;
- case 1 : SpeakEnable = !IsGuardianAlive; break;
- case 2 : SpeakEnable = IsGuardianAlive; break;
- }
- }
- if (!SpeakEnable) return;
- if(SpeakOK) {
- Hud.Sound.Speak(charRule.Item2);
- SpeakOK = false;
- }
- }
- public void Customize() {
- Hud.TogglePlugin<ConventionOfElementsBuffListPlugin>(false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement