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

Commit

Permalink
fix: add heal potion.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed May 1, 2023
1 parent b4dd209 commit 408992f
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 38 deletions.
9 changes: 5 additions & 4 deletions RotationSolver.Basic/Actions/BaseItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public bool IsInCooldown

public float AnimationLockTime => OtherConfiguration.AnimationLockTime.TryGetValue(AdjustedID, out var time) ? time : 1.1f;

public bool IsActionSequencer => false;
public virtual bool IsActionSequencer => false;

protected virtual bool CanUseThis => true;

public unsafe BaseItem(uint row, uint a4 = 65535)
{
Expand All @@ -78,12 +80,11 @@ public unsafe BaseItem(uint row, uint a4 = 65535)
SortKey = (uint)ActionManager.Instance()->GetRecastGroup((int)ActionType.Item, ID);
}

public unsafe bool CanUse(out IAction item)
public virtual unsafe bool CanUse(out IAction item)
{
item = this;
if (_item == null) return false;

if (!Service.Config.UseItem) return false;
if (!CanUseThis) return false;

if (ConfigurationHelper.BadStatus.Contains(ActionManager.Instance()->GetActionStatus(ActionType.Item, ID))
&& ConfigurationHelper.BadStatus.Contains(ActionManager.Instance()->GetActionStatus(ActionType.Item, ID + 1000000))) return false;
Expand Down
32 changes: 32 additions & 0 deletions RotationSolver.Basic/Actions/HealPotionItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace RotationSolver.Basic.Actions;

internal class HealPotionItem : BaseItem
{
readonly float _percent;
readonly uint _maxHp;

public uint MaxHealHp
{
get
{
if (Service.Player == null) return 0;
return Math.Min((uint)(Service.Player.MaxHp * _percent), _maxHp);
}
}

protected override bool CanUseThis => Service.Config.UseHealPotions;

public HealPotionItem(uint row, float percent, uint maxHp, uint a4 = 65535) : base(row, a4)
{
_percent = percent;
_maxHp = maxHp;
}

public override bool CanUse(out IAction item)
{
item = null;
if (Service.Player == null) return false;
if (Service.Player.MaxHp - Service.Player.CurrentHp < MaxHealHp) return false;
return base.CanUse(out item);
}
}
28 changes: 19 additions & 9 deletions RotationSolver.Basic/Actions/MedicineItem.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
namespace RotationSolver.Basic.Actions
namespace RotationSolver.Basic.Actions;

public enum MedicineType : byte
{
internal class MedicineItem : BaseItem
{
private MedicineType _type;
public MedicineItem(uint row, MedicineType type, uint a4 = 65535) : base(row, a4)
{
_type = type;
}
Strength,
Dexterity,
Intelligence,
Mind,
}

internal class MedicineItem : BaseItem
{
private MedicineType _type;

protected override bool CanUseThis => Service.Config.UseTinctures;

internal bool InType(ICustomRotation rotation) => rotation.MedicineType == _type;
public MedicineItem(uint row, MedicineType type, uint a4 = 65535) : base(row, a4)
{
_type = type;
}

internal bool InType(ICustomRotation rotation) => rotation.MedicineType == _type;
}
3 changes: 2 additions & 1 deletion RotationSolver.Basic/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public class PluginConfiguration : IPluginConfiguration
public bool RaiseBrinkOfDeath = true;
public int LessMPNoRaise = 0;
public bool AddEnemyListToHostile = true;
public bool UseItem = false;
public bool UseTinctures = false;
public bool UseHealPotions = false;
public bool PositionalFeedback = true;
public bool DrawPositional = true;
public bool DrawMeleeRange = true;
Expand Down
6 changes: 5 additions & 1 deletion RotationSolver.Basic/Rotations/CustomRotation_Ability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ private bool GeneralHealAbility(SpecialCommandType specialType, out IAction act)
if ((DataCenter.HPNotFull || Job.GetJobRole() != JobRole.Healer) && InCombat)
{
if ((DataCenter.SpecialType == SpecialCommandType.HealArea || CanHealAreaAbility) && HealAreaAbility(out act)) return true;
if ((DataCenter.SpecialType == SpecialCommandType.HealSingle || CanHealSingleAbility) && HealSingleAbility(out act)) return true;
if (DataCenter.SpecialType == SpecialCommandType.HealSingle || CanHealSingleAbility)
{
if (HealSingleAbility(out act)) return true;
if (UseHealPotion(out act)) return true;
}
}

return false;
Expand Down
48 changes: 30 additions & 18 deletions RotationSolver.Basic/Rotations/CustomRotation_Medicine.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
namespace RotationSolver.Basic.Rotations;

public enum MedicineType : byte
{
Strength,
Dexterity,
Intelligence,
Mind,
}

public abstract partial class CustomRotation
{
#region Tincture
public abstract MedicineType MedicineType { get; }
public static IBaseItem TinctureOfStrength6 { get; }
public static IBaseItem TinctureOfStrength6 { get; }
= new MedicineItem(36109, MedicineType.Strength, 196625);
public static IBaseItem TinctureOfDexterity6 { get; }
= new MedicineItem(36110, MedicineType.Dexterity);
public static IBaseItem TinctureOfIntelligence6 { get; }
= new MedicineItem(36112, MedicineType.Intelligence);
public static IBaseItem TinctureOfMind6 { get; }
public static IBaseItem TinctureOfMind6 { get; }
= new MedicineItem(36113, MedicineType.Mind);
public static IBaseItem TinctureOfStrength7 { get; }
public static IBaseItem TinctureOfStrength7 { get; }
= new MedicineItem(37840, MedicineType.Strength);
public static IBaseItem TinctureOfDexterity7 { get; }
public static IBaseItem TinctureOfDexterity7 { get; }
= new MedicineItem(37841, MedicineType.Dexterity);
public static IBaseItem TinctureOfIntelligence7 { get; }
public static IBaseItem TinctureOfIntelligence7 { get; }
= new MedicineItem(37843, MedicineType.Intelligence);
public static IBaseItem TinctureOfMind7 { get; }
= new MedicineItem(37844, MedicineType.Mind);
public static IBaseItem TinctureOfMind7 { get; }
= new MedicineItem(37844, MedicineType.Mind);

public static IBaseItem EchoDrops { get; } = new BaseItem(4566);

static bool UseStrength(out IAction act)
{
if (TinctureOfStrength7.CanUse(out act)) return true;
Expand Down Expand Up @@ -58,7 +49,7 @@ static bool UseMind(out IAction act)
protected bool UseBurstMedicine(out IAction act)
{
act = null;

if (!(Target?.IsDummy() ?? false) && !DataCenter.InHighEndDuty) return false;

switch (MedicineType)
Expand All @@ -74,4 +65,25 @@ protected bool UseBurstMedicine(out IAction act)
}
return false;
}
#endregion

public static IBaseItem EchoDrops { get; } = new BaseItem(4566);

#region Heal Potion
public static IBaseItem HyperPotion { get; } = new HealPotionItem(38956, 0.25f, 11000);

private bool UseHealPotion(out IAction act)
{
var acts = from prop in GetType().GetProperties()
where typeof(HealPotionItem).IsAssignableFrom(prop.PropertyType) && !(prop.GetMethod?.IsPrivate ?? true)
select (HealPotionItem)prop.GetValue(this) into a
where a != null && a.CanUse(out _)
orderby a.MaxHealHp
select a;

act = acts.LastOrDefault();
return act != null;
}

#endregion
}
4 changes: 2 additions & 2 deletions RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ internal partial class Strings
public string ConfigWindow_Param_RaisePlayerByCasting { get; set; } = "Raise player by casting when swift is in cooldown";
public string ConfigWindow_Param_UseHealWhenNotAHealer { get; set; } = "Use heal when not-healer";
public string ConfigWindow_Param_LessMPNoRaise { get; set; } = "Never raise player if MP is less than the set value";
public string ConfigWindow_Param_UseItem { get; set; } = "Use items";
public string ConfigWindow_Param_UseItemDesc { get; set; } = "Use poison, WIP";
public string ConfigWindow_Param_UseTinctures { get; set; } = "Use Tinctures";
public string ConfigWindow_Param_UseHealPotions { get; set; } = "Use Heal Potions";
public string ConfigWindow_Param_Conditon { get; set; } = "Condition";
public string ConfigWindow_Param_StartOnCountdown { get; set; } = "Auto turn smart on countdown";
public string ConfigWindow_Param_EsunaAll { get; set; } = "Esuna All Statuses.";
Expand Down
8 changes: 5 additions & 3 deletions RotationSolver/UI/RotationConfigWindow_Param.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,11 @@ private void DrawParamAction()

DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_AutoBurst, SettingsCommand.AutoBurst);

DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_UseItem,
ref Service.Config.UseItem, Service.Default.UseItem,
LocalizationManager.RightLang.ConfigWindow_Param_UseItemDesc);
DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_UseTinctures,
ref Service.Config.UseTinctures, Service.Default.UseTinctures);

DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_UseHealPotions,
ref Service.Config.UseHealPotions, Service.Default.UseHealPotions);

DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_UseAbility,
SettingsCommand.UseAbility);
Expand Down

0 comments on commit 408992f

Please sign in to comment.