Skip to content

Commit

Permalink
MinionRoulette 1.1.2.3 [PUSH]
Browse files Browse the repository at this point in the history
Added toggle command
  • Loading branch information
InitialDet committed Jan 18, 2023
1 parent e86ef1e commit f5e3729
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 37 deletions.
46 changes: 25 additions & 21 deletions MinionRoulette/MinionRoulette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public sealed partial class Plugin : IDalamudPlugin
{
public string Name => Service.PluginName;

private const string cmdMrCfg = "/mrcfg";
private const string cmdMrOn = "/mron";
private const string cmdMrOff = "/mroff";
private const string cmdMrCfg = "/minionroulette";
private const string cmdMrCfgShort = "/mrcfg";
private const string cmdMrToggle = "/mrtoggle";

readonly MinionSwap currentZone;
private readonly SwapManager currentZone;
private static PluginUI PluginUI = null!;

public Plugin(DalamudPluginInterface pluginInterface)
Expand All @@ -24,14 +24,15 @@ public Plugin(DalamudPluginInterface pluginInterface)
Service.PluginInterface!.UiBuilder.Draw += Service.WindowSystem.Draw;
Service.PluginInterface!.UiBuilder.OpenConfigUi += OnOpenConfigUi;

Service.Commands.AddHandler(cmdMrOff, new CommandInfo(OnCommand)
Service.Commands.AddHandler(cmdMrToggle, new CommandInfo(OnCommand)
{
HelpMessage = "Disables MinionRoulette",
HelpMessage = "Toggles MinionRoulette"
});

Service.Commands.AddHandler(cmdMrOn, new CommandInfo(OnCommand)
Service.Commands.AddHandler(cmdMrCfgShort, new CommandInfo(OnCommand)
{
HelpMessage = "Enables MinionRoulette"
HelpMessage = "Opens Config Window"

});

Service.Commands.AddHandler(cmdMrCfg, new CommandInfo(OnCommand)
Expand All @@ -44,20 +45,25 @@ public Plugin(DalamudPluginInterface pluginInterface)

private void OnCommand(string command, string args)
{
if (command.Trim().Equals(cmdMrCfg)) {
if (command.Trim().Equals(cmdMrCfg) || command.Trim().Equals(cmdMrCfgShort)) {
OnOpenConfigUi();
return;
}

if (command.Trim().Equals(cmdMrOn))
if (command.Trim().Equals(cmdMrToggle))
{
Service.Chat.Print("MinionRoulette Enabled");
Service.Configuration.PluginEnabled = true;
}
if (Service.Configuration.PluginEnabled)
{
Service.Chat.Print("MinionRoulette Disabled");
Service.Configuration.PluginEnabled = false;
}
else
{
Service.Chat.Print("MinionRoulette Enabled");
Service.Configuration.PluginEnabled = true;
}

if (command.Trim().Equals(cmdMrOff))
{
Service.Chat.Print("MinionRoulette Disabled");
Service.Configuration.PluginEnabled = false;
return;
}
}

Expand All @@ -72,9 +78,7 @@ public void Dispose()
Service.PluginInterface!.UiBuilder.Draw -= Service.WindowSystem.Draw;
Service.PluginInterface.UiBuilder.OpenConfigUi -= OnOpenConfigUi;
Service.Commands.RemoveHandler(cmdMrCfg);
Service.Commands.RemoveHandler(cmdMrOn);
Service.Commands.RemoveHandler(cmdMrOff);
Service.Commands.RemoveHandler(cmdMrCfgShort);
Service.Commands.RemoveHandler(cmdMrToggle);
}


}
2 changes: 1 addition & 1 deletion MinionRoulette/MinionRoulette.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Authors>Det</Authors>
<Version>1.1.2.2</Version>
<Version>1.1.2.3</Version>
<Description>Swaps between your favorite minions</Description>
<PackageProjectUrl>https://github.com/InitialDet/MinionRoulette</PackageProjectUrl>
<Configurations>Release;Debug</Configurations>
Expand Down
2 changes: 1 addition & 1 deletion MinionRoulette/MinionRoulette.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"ApplicableVersion": "any",
"DalamudApiLevel": 8,
"LoadPriority": 0,
"Changelog": "Disabled on Island Sanctuary, since it removed minions placed there"
"Changelog": ""
}

1 change: 0 additions & 1 deletion MinionRoulette/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public static void Initialize(DalamudPluginInterface pluginInterface)

[PluginService][RequiredVersion("1.0")] public static DalamudPluginInterface PluginInterface { get; set; } = null!;
[PluginService][RequiredVersion("1.0")] public static ClientState ClientState { get; private set; } = null!;
//[PluginService][RequiredVersion("1.0")] public static Framework Framework { get; private set; } = null!;
[PluginService][RequiredVersion("1.0")] public static Dalamud.Game.ClientState.Conditions.Condition Condition { get; private set; } = null!;
[PluginService][RequiredVersion("1.0")] public static ObjectTable ObjectTable { get; private set; } = null!;
[PluginService][RequiredVersion("1.0")] public static CommandManager Commands { get; private set; } = null!;
Expand Down
26 changes: 13 additions & 13 deletions MinionRoulette/SwapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
namespace MinionRoulette;
public sealed partial class Plugin
{
public class MinionSwap : IDisposable
public class SwapManager : IDisposable
{
public ushort lastZoneID;
public ushort lastZone;

const uint idMinionRoulette = 10; //GeneralAction

Expand All @@ -21,24 +21,24 @@ public void Init()
Service.ClientState!.TerritoryChanged += TerritoryChanged;
}

public void TerritoryChanged(object? sender, ushort zoneID)
public void TerritoryChanged(object? sender, ushort currentZone)
{
if (!Service.Configuration.PluginEnabled) {
lastZoneID = zoneID;
lastZone = currentZone;
return;
}

if (InvalidPlaces(zoneID))
if (InvalidPlaces(currentZone))
{
lastZoneID = zoneID;
lastZone = currentZone;
return;
}

if (zoneID != lastZoneID)
SwapMinion(zoneID);
if (currentZone != lastZone)
SwapMinion(currentZone);
}

private bool InvalidPlaces(int zoneID)
private static bool InvalidPlaces(int zoneID)
{
return zoneID switch
{
Expand All @@ -51,15 +51,15 @@ private async void SwapMinion(ushort zoneID)
{
int trys = 0;

while ((this.lastZoneID != zoneID))
while (this.lastZone != zoneID)
{
await Task.Delay(500); //Theres no need to loop like crazy while waiting for the game to load.
if ((Service.ClientState.LocalContentId == 0 && Service.ClientState.LocalPlayer == null) || BetweenAreas())
continue;

if (BoundByDuty()) // Dont proceed if player is Bound By Duty
{
this.lastZoneID = zoneID;
this.lastZone = zoneID;
return;
}

Expand All @@ -68,14 +68,14 @@ private async void SwapMinion(ushort zoneID)

if (!IsMinionSummoned())
{
this.lastZoneID = zoneID;
this.lastZone = zoneID;
break;
}

if (ActionAvailable(idMinionRoulette))
{
if (CastAction(idMinionRoulette)) {
this.lastZoneID = zoneID;
this.lastZone = zoneID;
break;
}
}
Expand Down

0 comments on commit f5e3729

Please sign in to comment.