Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: add auto open chest feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Aug 13, 2023
1 parent b19c496 commit fcf27e7
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 1 deletion.
3 changes: 3 additions & 0 deletions RotationSolver.Basic/Configuration/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ public enum PluginConfigBool : byte
[Default(true)] UseGroundBeneficialAbility,
[Default(false)] TargetAllForFriendly,
[Default(false)] ShowCooldownWindow,

[Default(true)] AutoOpenChest,
[Default(true)] AutoCloseChestWindow,
}

public enum PluginConfigFloat : byte
Expand Down
4 changes: 4 additions & 0 deletions RotationSolver/Localization/ConfigTranslation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ internal static class ConfigTranslation
PluginConfigBool.ShowHealthRatio => LocalizationManager.RightLang.ConfigWindow_Param_ShowHealthRatio,
PluginConfigBool.ShowTooltips => LocalizationManager.RightLang.ConfigWindow_Param_ShowTooltips,
PluginConfigBool.InDebug => LocalizationManager.RightLang.ConfigWindow_Param_InDebug,
PluginConfigBool.AutoOpenChest => "Auto Open the treasure chest",
PluginConfigBool.AutoCloseChestWindow => "Auto close the loot window when auto opened the chest.",

//Rotations
PluginConfigBool.DownloadRotations => LocalizationManager.RightLang.ConfigWindow_Rotation_DownloadRotations,
Expand Down Expand Up @@ -199,6 +201,8 @@ internal static class ConfigTranslation
PluginConfigBool.AutoProvokeForTank => LocalizationManager.RightLang.ConfigWindow_Param_AutoProvokeForTankDesc,
PluginConfigBool.CanAttackMarkAOE => LocalizationManager.RightLang.ConfigWindow_Param_AttackMarkAOEDesc,
PluginConfigBool.MoveTowardsScreenCenter => LocalizationManager.RightLang.ConfigWindow_Param_MoveTowardsScreenDesc,

PluginConfigBool.AutoOpenChest => "Because of the feature in pandora, there is an issue the treasure chest cannot be opened in some cases, I find the code from roll for loot. Once Pandora fixed that, this feature will be deleted.",
_ => string.Empty,
};

Expand Down
4 changes: 4 additions & 0 deletions RotationSolver/UI/RotationConfigWindowNew_Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ private static void DrawTarget()
new DragFloatRangeSearchPlugin(PluginConfigFloat.StopCastingDelayMin, PluginConfigFloat.StopCastingDelayMin, 0.002f)
}),

new CheckBoxSearchPlugin(PluginConfigBool.AutoOpenChest, new ISearchable[]
{
new CheckBoxSearchPlugin(PluginConfigBool.AutoCloseChestWindow),
}),
};
private static void DrawExtra()
{
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/UI/SearchableConfigs/Searchable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected void ShowTooltip(Job job, bool showHand = true)
}
var wholeWidth = ImGui.GetWindowWidth();

foreach (var tooltip in Tooltips)
if(Tooltips != null) foreach (var tooltip in Tooltips)
{
RotationConfigWindowNew.DrawLinkDescription(tooltip, wholeWidth, false);
}
Expand Down
87 changes: 87 additions & 0 deletions RotationSolver/Updaters/MajorUpdater.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
using Dalamud.Game;
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Game.ClientState.Objects.Enums;
using Dalamud.Logging;
using ECommons.DalamudServices;
using ECommons.GameHelpers;
using ECommons.ImGuiMethods;
using FFXIVClientStructs.FFXIV.Client.Game.Control;
using FFXIVClientStructs.FFXIV.Client.Game.UI;
using FFXIVClientStructs.FFXIV.Component.GUI;
using RotationSolver.Commands;
using RotationSolver.UI;
using System.Runtime.InteropServices;

namespace RotationSolver.Updaters;

Expand Down Expand Up @@ -93,6 +99,9 @@ private unsafe static void FrameworkUpdate(Framework framework)
}

MacroUpdater.UpdateMacro();

CloseWindow();
OpenChest();
}
catch (Exception ex)
{
Expand Down Expand Up @@ -169,6 +178,84 @@ private static void UpdateWork()
_work = false;
}

static DateTime _closeWindowTime = DateTime.Now;
private unsafe static void CloseWindow()
{
if (_closeWindowTime < DateTime.Now) return;

var needGreedWindow = Svc.GameGui.GetAddonByName("NeedGreed", 1);
if (needGreedWindow == IntPtr.Zero) return;

var notification = (AtkUnitBase*)Svc.GameGui.GetAddonByName("_Notification", 1);
if (notification == null) return;

var atkValues = (AtkValue*)Marshal.AllocHGlobal(2 * sizeof(AtkValue));
atkValues[0].Type = atkValues[1].Type = FFXIVClientStructs.FFXIV.Component.GUI.ValueType.Int;
atkValues[0].Int = 0;
atkValues[1].Int = 2;
try
{
notification->FireCallback(2, atkValues);
}
catch (Exception ex)
{
PluginLog.Warning(ex, "Failed to close the window!");
}
finally
{
Marshal.FreeHGlobal(new IntPtr(atkValues));
}
}

static DateTime _nextOpenTime = DateTime.Now;
static uint _lastChest = 0;
private unsafe static void OpenChest()
{
if (!Service.ConfigNew.GetValue(Basic.Configuration.PluginConfigBool.AutoOpenChest)) return;
var player = Player.Object;

var treasure = Svc.Objects.FirstOrDefault(o =>
{
if (o == null) return false;
var dis = Vector3.Distance(player.Position, o.Position) - player.HitboxRadius - o.HitboxRadius;
if (dis > 0.5f) return false;

var address = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)(void*)o.Address;
if ((ObjectKind)address->ObjectKind != ObjectKind.Treasure) return false;

//Opened!
foreach (var item in Loot.Instance()->ItemArraySpan)
{
if (item.ChestObjectId == o.ObjectId) return false;
}

return true;
});

if (treasure == null) return;
if (DateTime.Now < _nextOpenTime) return;
if (treasure.ObjectId == _lastChest && DateTime.Now - _nextOpenTime < TimeSpan.FromSeconds(10)) return;

_nextOpenTime = DateTime.Now.AddSeconds(new Random().NextDouble() + 0.2);
_lastChest = treasure.ObjectId;

try
{
Svc.Targets.Target =treasure;

TargetSystem.Instance()->InteractWithObject((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)(void*)treasure.Address);

Notify.Plain($"Try to open the chest {treasure.Name}");
}
catch (Exception ex)
{
PluginLog.Error(ex, "Failed to open the chest!");
}

if (!Service.ConfigNew.GetValue(Basic.Configuration.PluginConfigBool.AutoOpenChest)) return;
_closeWindowTime = DateTime.Now.AddSeconds(0.1);
}

public static void Dispose()
{
Svc.Framework.Update -= FrameworkUpdate;
Expand Down

0 comments on commit fcf27e7

Please sign in to comment.