Code:
using System;
using Turbo.Plugins;
using Turbo.Plugins.Default;
using System.Globalization;
using System.Linq;
namespace Turbo.Plugins.Custom
{
public class ChestDropRatePlugin : BasePlugin, IInGameWorldPainter
{
public WorldDecoratorCollection NormalChestDecorator { get; set; }
public WorldDecoratorCollection ResplendentChestDecorator { get; set; }
public WorldDecoratorCollection SpecialChestDecorator { get; set; }
// Para el indicador visual de carga
private bool _pluginLoadedNotificationShown = false;
private DateTime _lastDebugCheck = DateTime.MinValue;
private string _statusText = "Cargando...";
private IFont _statusFont;
public ChestDropRatePlugin()
{
Enabled = true;
}
public override void Load(IController hud)
{
base.Load(hud);
// Crear font para el texto de estado
_statusFont = Hud.Render.CreateFont("tahoma", 10, 255, 0, 255, 0, true, false, false);
// Mostrar notificación de carga en consola
Hud.TextLog.Log("ChestDropRatePlugin", "Plugin cargado correctamente", true, false);
// Decorador para cofres normales
NormalChestDecorator = new WorldDecoratorCollection(
new MapShapeDecorator(Hud)
{
Brush = Hud.Render.CreateBrush(255, 255, 255, 0, 2),
ShapePainter = new CircleShapePainter(Hud),
Radius = 1f
},
new GroundLabelDecorator(Hud)
{
BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 0, 0),
TextFont = Hud.Render.CreateFont("tahoma", 6.5f, 255, 255, 255, 0, false, false, false)
}
);
// Decorador para cofres resplandecientes
ResplendentChestDecorator = new WorldDecoratorCollection(
new MapShapeDecorator(Hud)
{
Brush = Hud.Render.CreateBrush(255, 255, 215, 0, 2),
ShapePainter = new CircleShapePainter(Hud),
Radius = 1.5f
},
new GroundLabelDecorator(Hud)
{
BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 0, 0),
TextFont = Hud.Render.CreateFont("tahoma", 7f, 255, 255, 215, 0, true, false, false)
}
);
// Decorador para cofres especiales (como a2dun_Swr_Chest)
SpecialChestDecorator = new WorldDecoratorCollection(
new MapShapeDecorator(Hud)
{
Brush = Hud.Render.CreateBrush(255, 0, 255, 255, 2),
ShapePainter = new CircleShapePainter(Hud),
Radius = 1.2f
},
new GroundLabelDecorator(Hud)
{
BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 0, 0),
TextFont = Hud.Render.CreateFont("tahoma", 7f, 255, 0, 255, 255, true, false, false)
}
);
_statusText = "Plugin ACTIVO - Buscando cofres";
}
public void PaintWorld(WorldLayer layer)
{
// Solo procesar en la capa de suelo
if (layer != WorldLayer.Ground) return;
// Dibujar indicador de estado en la esquina superior izquierda
_statusFont.DrawText(_statusText, 50, 50);
// Mostrar notificación de carga una vez
if (!_pluginLoadedNotificationShown)
{
Hud.TextLog.Log("ChestDropRatePlugin", "Plugin iniciado - Visualizando probabilidades de cofres", true, false);
_pluginLoadedNotificationShown = true;
}
// Información de depuración periódica
if ((DateTime.Now - _lastDebugCheck).TotalSeconds > 5)
{
_lastDebugCheck = DateTime.Now;
var chestCount = Hud.Game.Actors.Count(x => x.SnoActor.Kind == ActorKind.Chest);
Hud.TextLog.Log("ChestDropRatePlugin", $"{chestCount} cofres detectados en el área", true, false);
// Actualizar texto de estado
_statusText = $"Plugin ACTIVO - {chestCount} cofres detectados";
}
if (Hud.Game.IsInTown) return;
var chests = Hud.Game.Actors.Where(x => x.SnoActor.Kind == ActorKind.Chest).ToList();
foreach (var chest in chests)
{
// Debug: registrar nombres de cofres para verificar
Hud.TextLog.Log("ChestDebug", $"Cofre detectado: {chest.SnoActor.NameEnglish}", true, false);
var chestName = chest.SnoActor.NameEnglish?.ToLower();
switch (chestName)
{
case "normal chest":
NormalChestDecorator.Paint(layer, chest, chest.FloorCoordinate, GetDropRates(chest));
break;
case "resplendent chest":
ResplendentChestDecorator.Paint(layer, chest, chest.FloorCoordinate, GetDropRates(chest));
break;
case "a2dun_swr_chest": // Cofre especial de fallas
SpecialChestDecorator.Paint(layer, chest, chest.FloorCoordinate, GetDropRates(chest));
break;
default:
// Para otros cofres no identificados, usar decorador normal
if (chestName != null && chestName.Contains("chest"))
{
NormalChestDecorator.Paint(layer, chest, chest.FloorCoordinate, GetDropRates(chest));
}
break;
}
}
}
private string GetDropRates(IActor chest)
{
GameDifficulty difficulty = Hud.Game.GameDifficulty;
bool isResplendent = chest.SnoActor.NameEnglish?.ToLower().Contains("resplendent") ?? false;
bool isSpecialChest = chest.SnoActor.NameEnglish?.ToLower().Contains("a2dun_swr") ?? false;
double legendaryChance = 0;
double setChance = 0;
if (isResplendent)
{
switch (difficulty)
{
case GameDifficulty.t1:
legendaryChance = 0.25;
setChance = 0.15;
break;
case GameDifficulty.t6:
legendaryChance = 0.50;
setChance = 0.30;
break;
case GameDifficulty.t16:
legendaryChance = 1.00;
setChance = 0.50;
break;
default:
if (difficulty >= GameDifficulty.t7 && difficulty <= GameDifficulty.t15)
{
int tormentLevel = (int)difficulty - 3;
legendaryChance = 0.25 + (0.05 * (tormentLevel - 1));
setChance = 0.15 + (0.03 * (tormentLevel - 1));
}
else
{
legendaryChance = 0.10;
setChance = 0.05;
}
break;
}
}
else if (isSpecialChest)
{
// Probabilidades específicas para cofres especiales como a2dun_Swr_Chest
switch (difficulty)
{
case GameDifficulty.t1:
legendaryChance = 0.30;
setChance = 0.20;
break;
case GameDifficulty.t6:
legendaryChance = 0.60;
setChance = 0.35;
break;
case GameDifficulty.t16:
legendaryChance = 1.20; // Puede ser mayor que 100% para indicar múltiples legendarios
setChance = 0.60;
break;
default:
if (difficulty >= GameDifficulty.t7 && difficulty <= GameDifficulty.t15)
{
int tormentLevel = (int)difficulty - 3;
legendaryChance = 0.30 + (0.06 * (tormentLevel - 1));
setChance = 0.20 + (0.04 * (tormentLevel - 1));
}
else
{
legendaryChance = 0.15;
setChance = 0.10;
}
break;
}
}
else
{
// Cofres normales
switch (difficulty)
{
case GameDifficulty.t1:
legendaryChance = 0.10;
setChance = 0.05;
break;
case GameDifficulty.t6:
legendaryChance = 0.25;
setChance = 0.12;
break;
case GameDifficulty.t16:
legendaryChance = 0.50;
setChance = 0.25;
break;
default:
if (difficulty >= GameDifficulty.t7 && difficulty <= GameDifficulty.t15)
{
int tormentLevel = (int)difficulty - 3;
legendaryChance = 0.10 + (0.03 * (tormentLevel - 1));
setChance = 0.05 + (0.02 * (tormentLevel - 1));
}
else
{
legendaryChance = 0.05;
setChance = 0.02;
}
break;
}
}
return $"{legendaryChance:P0} L / {setChance:P0} S";
}
}
}