Skip to content

Commit

Permalink
Merge pull request #409 from FFXIV-CombatReborn/chocobocommands
Browse files Browse the repository at this point in the history
Update subproject, add entries, and refine command handling
  • Loading branch information
LTS-FFXIV authored Sep 25, 2024
2 parents c22bfe0 + 83ae861 commit 755354a
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 82 deletions.
1 change: 1 addition & 0 deletions Resources/AnimationLockTime.json
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@
"34686": 0.6,
"34711": 0.1,
"35663": 0.1,
"36623": 0.1,
"36920": 0.6,
"36921": 0.6,
"36922": 0.6,
Expand Down
3 changes: 0 additions & 3 deletions Resources/ContributorsHash.json

This file was deleted.

8 changes: 7 additions & 1 deletion Resources/HostileCastingArea.json
Original file line number Diff line number Diff line change
Expand Up @@ -634,5 +634,11 @@
37744,
37716,
37718,
36384
36384,
14553,
36606,
36610,
36612,
27145,
27181
]
5 changes: 3 additions & 2 deletions Resources/HostileCastingTank.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
37754,
33965,
35715,
37845
]
37845,
29023
]
29 changes: 0 additions & 29 deletions Resources/Supporters.json

This file was deleted.

2 changes: 0 additions & 2 deletions Resources/UsersHash.json

This file was deleted.

5 changes: 0 additions & 5 deletions Resources/downloadList.json

This file was deleted.

23 changes: 1 addition & 22 deletions RotationSolver.Basic/Helpers/ObjectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,28 +169,7 @@ internal static bool IsParty(this IGameObject gameObject)
if (gameObject.GameObjectId == Player.Object?.GameObjectId) return true;
if (Svc.Party.Any(p => p.GameObject?.GameObjectId == gameObject.GameObjectId)) return true;
if (Service.Config.FriendlyPartyNpcHealRaise && gameObject.GetBattleNPCSubKind() == BattleNpcSubKind.NpcPartyMember) return true;

// Check if ChocoboPartyMember is enabled
if (Service.Config.ChocoboPartyMember)
{
// Add Player Chocobo Companion to Party List
unsafe
{
try
{
BattleChara* companionChocobo = DataCenter.GetCompanion();
if (companionChocobo != null)
{
return true;
}
}
catch (Exception ex)
{
Svc.Log.Error(ex, "Error accessing companionChocobo");
}
}
}

if (Service.Config.ChocoboPartyMember && gameObject.GetNameplateKind() == NameplateKind.PlayerCharacterChocobo) return true;
if (Service.Config.FriendlyBattleNpcHeal && gameObject.GetNameplateKind() == NameplateKind.FriendlyBattleNPC) return true;

}
Expand Down
120 changes: 104 additions & 16 deletions RotationSolver/Commands/RSCommands_OtherCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,28 @@ private static void DoOtherCommand(OtherCommandType otherType, string str)

private static void DoSettingCommand(string str)
{
var strs = str.Split(' ');
var strs = str.Split(' ', 3);
if (strs.Length < 2)
{
Svc.Chat.PrintError("Invalid setting command format.");
return;
}

var settingName = strs[0];
var value = strs.LastOrDefault();
if (settingName == null || value == null)
var command = strs.Length > 1 ? string.Join(' ', strs.Skip(1)) : null;

if (string.IsNullOrEmpty(settingName))
{
Svc.Chat.PrintError("Invalid setting command format.");
return;
}

if (settingName.Equals("TargetingTypes", StringComparison.OrdinalIgnoreCase))
{
HandleTargetingTypesCommand(settingName, command);
return;
}

foreach (var property in typeof(Configs).GetRuntimeProperties().Where(p => p.GetMethod?.IsPublic ?? false))
{
if (!settingName.Equals(property.Name, StringComparison.OrdinalIgnoreCase))
Expand All @@ -62,7 +75,7 @@ private static void DoSettingCommand(string str)

if (type.IsEnum)
{
valueParsedSuccessfully = Enum.TryParse(type, value, ignoreCase: true, out var parsedEnum);
valueParsedSuccessfully = Enum.TryParse(type, command, ignoreCase: true, out var parsedEnum);
if (valueParsedSuccessfully)
{
convertedValue = parsedEnum;
Expand All @@ -72,7 +85,7 @@ private static void DoSettingCommand(string str)
{
try
{
convertedValue = Convert.ChangeType(value, type);
convertedValue = Convert.ChangeType(command, type);
}
catch
{
Expand Down Expand Up @@ -104,10 +117,8 @@ private static void DoSettingCommand(string str)

if (convertedValue == null)
{
#if DEBUG
Svc.Chat.Print("Failed to parse the value.");
#endif
continue;
Svc.Chat.PrintError("Failed to parse the value.");
return;
}

if (property.PropertyType == typeof(ConditionBoolean))
Expand All @@ -118,16 +129,86 @@ private static void DoSettingCommand(string str)
}

property.SetValue(Service.Config, convertedValue);
value = convertedValue.ToString();
command = convertedValue.ToString();

Svc.Chat.Print(string.Format(UiString.CommandsChangeSettingsValue.GetDescription(), property.Name, value));
Svc.Chat.Print(string.Format(UiString.CommandsChangeSettingsValue.GetDescription(), property.Name, command));

return;
}

Svc.Chat.PrintError(UiString.CommandsCannotFindConfig.GetDescription());
Svc.Chat.PrintError("Failed to find the config in this rotation, please check it.");
}

private static void HandleTargetingTypesCommand(string settingName, string? command)
{
if (string.IsNullOrEmpty(command))
{
Svc.Chat.PrintError("Invalid command for TargetingTypes.");
return;
}

var commandParts = command.Split(' ', 2);
if (commandParts.Length < 1)
{
Svc.Chat.PrintError("Invalid command format for TargetingTypes.");
return;
}

var action = commandParts[0];
var value = commandParts.Length > 1 ? commandParts[1] : null;

switch (action.ToLower())
{
case "add":
if (string.IsNullOrEmpty(value) || !Enum.TryParse(typeof(TargetingType), value, true, out var parsedEnumAdd))
{
Svc.Chat.PrintError("Invalid TargetingType value.");
return;
}

var targetingTypeAdd = (TargetingType)parsedEnumAdd;
if (!Service.Config.TargetingTypes.Contains(targetingTypeAdd))
{
Service.Config.TargetingTypes.Add(targetingTypeAdd);
Svc.Chat.Print($"Added {targetingTypeAdd} to TargetingTypes.");
}
else
{
Svc.Chat.Print($"{targetingTypeAdd} is already in TargetingTypes.");
}
break;

case "remove":
if (string.IsNullOrEmpty(value) || !Enum.TryParse(typeof(TargetingType), value, true, out var parsedEnumRemove))
{
Svc.Chat.PrintError("Invalid TargetingType value.");
return;
}

var targetingTypeRemove = (TargetingType)parsedEnumRemove;
if (Service.Config.TargetingTypes.Contains(targetingTypeRemove))
{
Service.Config.TargetingTypes.Remove(targetingTypeRemove);
Svc.Chat.Print($"Removed {targetingTypeRemove} from TargetingTypes.");
}
else
{
Svc.Chat.Print($"{targetingTypeRemove} is not in TargetingTypes.");
}
break;

case "removeall":
Service.Config.TargetingTypes.Clear();
Svc.Chat.Print("Removed all TargetingTypes.");
break;

default:
Svc.Chat.PrintError("Invalid action for TargetingTypes.");
break;
}

Service.Config.Save();
}

private static Enum GetNextEnumValue(Enum currentEnumValue)
{
Expand Down Expand Up @@ -159,14 +240,21 @@ private static void ToggleActionCommand(string str)

private static void DoActionCommand(string str)
{
var strs = str.Split('-');
var lastHyphenIndex = str.LastIndexOf('-');
if (lastHyphenIndex == -1 || lastHyphenIndex == str.Length - 1)
{
Svc.Chat.PrintError(UiString.CommandsInsertActionFailure.GetDescription());
return;
}

var actName = str.Substring(0, lastHyphenIndex).Trim();
var timeStr = str.Substring(lastHyphenIndex + 1).Trim();

if (strs != null && strs.Length == 2 && double.TryParse(strs[1], out var time))
if (double.TryParse(timeStr, out var time))
{
var actName = strs[0];
foreach (var iAct in RotationUpdater.RightRotationActions)
{
if (actName == iAct.Name)
if (actName.Equals(iAct.Name, StringComparison.OrdinalIgnoreCase))
{
DataCenter.AddCommandAction(iAct, time);

Expand Down
3 changes: 3 additions & 0 deletions RotationSolver/Commands/RSCommands_StateSpecialCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ public static unsafe void DoStateCommandType(StateCommandType stateType, int ind
{
if (index == -1)
{
// Increment the TargetingIndex to cycle through the TargetingTypes
index = Service.Config.TargetingIndex + 1;
}
// Ensure the index wraps around if it exceeds the number of TargetingTypes
index %= Service.Config.TargetingTypes.Count;
// Update the TargetingIndex in the configuration
Service.Config.TargetingIndex = index;
}
}
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/Data/UiString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ internal enum UiString
[Description("Hostile")]
ConfigWindow_List_Hostile,

[Description("Enemy targeting logic. Adding more options cycles them when using /rotation Auto.")]
[Description("Enemy targeting logic. Adding more options cycles them when using /rotation Auto.\nUse /rotation Settings TargetingTypes add <option> to add,\n/rotation Settings TargetingTypes remove <option> to remove,\nand /rotation Settings TargetingTypes removeall to remove all options.")]
ConfigWindow_Param_HostileDesc,

[Description("Move Up")]
Expand Down

0 comments on commit 755354a

Please sign in to comment.