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

Commit

Permalink
fix: add items control.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Mar 1, 2023
1 parent d5cb641 commit 3698f0a
Show file tree
Hide file tree
Showing 24 changed files with 110 additions and 43 deletions.
6 changes: 3 additions & 3 deletions RotationSolver/Actions/BaseAction/BaseAction_BasicInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ public string CateName
}
public bool IsEnabled
{
get => !Service.Configuration.DiabledActions.Contains((uint)ID);
get => !Service.Configuration.DiabledActions.Contains(ID);
set
{
if (value)
{
Service.Configuration.DiabledActions.Remove((uint)ID);
Service.Configuration.DiabledActions.Remove(ID);
}
else
{
Service.Configuration.DiabledActions.Add((uint)ID);
Service.Configuration.DiabledActions.Add(ID);
}
}
}
Expand Down
20 changes: 19 additions & 1 deletion RotationSolver/Actions/BaseItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,25 @@ internal class BaseItem : IBaseItem

public string CateName => "Item";

public BaseItem(uint row, uint a4 = 0)
public bool IsEnabled
{
get => !Service.Configuration.DiabledActions.Contains(ID);
set
{
if (value)
{
Service.Configuration.DiabledActions.Remove(ID);
}
else
{
Service.Configuration.DiabledActions.Add(ID);
}
}
}

public string Description => string.Empty;

public BaseItem(uint row, uint a4 = 65535)
{
_item = Service.DataManager.GetExcelSheet<Item>().GetRow(row);
IconID = _item.Icon;
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/Actions/IBaseItem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace RotationSolver.Actions
{
internal interface IBaseItem : IAction
internal interface IBaseItem : IAction, IEnable
{
bool CanUse(out IAction item);
}
Expand Down
21 changes: 21 additions & 0 deletions RotationSolver/Actions/RoleItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using RotationSolver.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RotationSolver.Actions
{
internal class RoleItem : BaseItem
{
private JobRole[] _roles;
public RoleItem(uint row, JobRole[] roles, uint a4 = 65535) : base(row, a4)
{
_roles = roles;
}

internal bool InRole(JobRole role) => _roles.Contains(role);

}
}
2 changes: 1 addition & 1 deletion RotationSolver/Attributes/RotationDescAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private RotationDescAttribute()

public void Display(ICustomRotation rotation)
{
var acts = rotation.AllActions;
var acts = rotation.AllBaseActions;

var allActions = Actions.Select(i => acts.FirstOrDefault(a => a.ID == (uint)i))
.Where(i => i != null);
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/Helpers/ConditionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal static bool CheckBaseAction(ICustomRotation rotation, ActionID id, ref
{
if (id != ActionID.None && (action == null || (ActionID)action.ID != id))
{
action = rotation.AllActions.OfType<BaseAction>().FirstOrDefault(a => (ActionID)a.ID == id);
action = rotation.AllBaseActions.OfType<BaseAction>().FirstOrDefault(a => (ActionID)a.ID == id);
}
if (action == null || Service.ClientState.LocalPlayer == null) return false;
return true;
Expand Down
1 change: 1 addition & 0 deletions RotationSolver/RotationSolverPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
using Lumina.Excel.GeneratedSheets;
using RotationSolver.Actions;
using RotationSolver.Commands;
using RotationSolver.Configuration;
using RotationSolver.Data;
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/Rotations/Basic/BLU_Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ private protected override bool EmergencyGCD(out IAction act)
protected static bool AllOnSlot(params IBLUAction[] actions) => actions.All(a => a.OnSlot);
protected static uint OnSlotCount(params IBLUAction[] actions) => (uint)actions.Count(a => a.OnSlot);

public override IBaseAction[] AllActions => base.AllActions.Where(a =>
public override IBaseAction[] AllBaseActions => base.AllBaseActions.Where(a =>
{
if (a is not BLUAction b) return false;
return b.OnSlot;
Expand Down
26 changes: 19 additions & 7 deletions RotationSolver/Rotations/CustomRotation/CustomRotation_Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using RotationSolver.SigReplacers;
using RotationSolver.Updaters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

Expand Down Expand Up @@ -217,7 +218,9 @@ internal RoleAction(ActionID actionID, JobRole[] roles, bool isFriendly = false,
/// <summary>
/// 当前这个类所有的BaseAction
/// </summary>
public virtual IBaseAction[] AllActions => GetBaseActions(GetType());
public virtual IBaseAction[] AllBaseActions => GetBaseActions(GetType()).ToArray();

public IAction[] AllActions => new IAction[0].Union(GetBaseItems(GetType())).Union(AllBaseActions).ToArray();

/// <summary>
/// 这个类所有的公开bool值
Expand All @@ -241,17 +244,26 @@ internal RoleAction(ActionID actionID, JobRole[] roles, bool isFriendly = false,
return types.Length == 2 && types[0].ParameterType == typeof(uint) && types[1].ParameterType == typeof(uint);
});

private IBaseAction[] GetBaseActions(Type type)
private IEnumerable<IBaseAction> GetBaseActions(Type type)
{
return GetIActions(type).OfType<IBaseAction>().Where(a => a is RoleAction role ? role.InRole(Job.GetJobRole()) : true);
}

private IEnumerable<IBaseItem> GetBaseItems(Type type)
{
return GetIActions(type).OfType<IBaseItem>().Where(a => a is RoleItem role ? role.InRole(Job.GetJobRole()) : true).Reverse();
}

private IEnumerable<IAction> GetIActions(Type type)
{
if (type == null) return new IBaseAction[0];
if (type == null) return new IAction[0];

var acts = from prop in type.GetProperties()
where typeof(IBaseAction).IsAssignableFrom(prop.PropertyType) && !(prop.GetMethod?.IsPrivate ?? true)
select (IBaseAction)prop.GetValue(this) into act
where typeof(IAction).IsAssignableFrom(prop.PropertyType) && !(prop.GetMethod?.IsPrivate ?? true)
select (IAction)prop.GetValue(this) into act
orderby act.ID
where act is RoleAction role ? role.InRole(Job.GetJobRole()) : true
select act;

return acts.Union(GetBaseActions(type.BaseType)).ToArray();
return acts.Union(GetIActions(type.BaseType));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@
namespace RotationSolver.Rotations.CustomRotation;
internal abstract partial class CustomRotation
{
private static readonly IBaseItem
TinctureofStrength6 = new BaseItem(36109, 196625),
TinctureofDexterity6 = new BaseItem(36110, 65535),
TinctureofMind6 = new BaseItem(36113, 65535),
TinctureofIntelligence6 = new BaseItem(36112, 65535),

TinctureofStrength7 = new BaseItem(37840, 196625),
TinctureofDexterity7 = new BaseItem(37841, 65535),
TinctureofMind7 = new BaseItem(37843, 65535),
TinctureofIntelligence7 = new BaseItem(37844, 65535);

protected bool UseTincture(out IAction act)
public static IBaseItem TinctureofStrength6 { get; } = new RoleItem(36109,
new JobRole[] { JobRole.Tank, JobRole.Melee }, 196625);
public static IBaseItem TinctureofDexterity6 { get; } = new RoleItem(36110,
new JobRole[] { JobRole.RangedPhysical });
public static IBaseItem TinctureofIntelligence6 { get; } = new RoleItem(36112,
new JobRole[] { JobRole.RangedMagicial });
public static IBaseItem TinctureofMind6 { get; } = new RoleItem(36113,
new JobRole[] { JobRole.Healer });

public static IBaseItem TinctureofStrength7 { get; } = new RoleItem(37840,
new JobRole[] { JobRole.Tank, JobRole.Melee });
public static IBaseItem TinctureofDexterity7 { get; } = new RoleItem(37841,
new JobRole[] { JobRole.RangedPhysical });
public static IBaseItem TinctureofIntelligence7 { get; } = new RoleItem(37843,
new JobRole[] { JobRole.RangedMagicial });
public static IBaseItem TinctureofMind7 { get; } = new RoleItem(37844,
new JobRole[] { JobRole.Healer });

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


protected bool UseBurstMedicine(out IAction act)
{
act = null;

Expand Down
3 changes: 2 additions & 1 deletion RotationSolver/Rotations/CustomRotation/ICustomRotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ internal interface ICustomRotation : ITexture, IEnable

BattleChara MoveTarget { get; }

IBaseAction[] AllActions { get; }
IBaseAction[] AllBaseActions { get; }
IAction[] AllActions { get; }
PropertyInfo[] AllBools { get; }
PropertyInfo[] AllBytes { get; }

Expand Down
6 changes: 5 additions & 1 deletion RotationSolver/Rotations/Healer/AST/AST_Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private protected override IAction CountDownAction(float remainTime)
{
if (remainTime < Malefic.CastTime + Service.Configuration.CountDownAhead
&& Malefic.CanUse(out var act)) return act;
if (remainTime < 3 && UseTincture(out act)) return act;
if (remainTime < 3 && UseBurstMedicine(out act)) return act;
if (remainTime < 4 && AspectedBeneficDefense.CanUse(out act)) return act;
if (remainTime < Configs.GetFloat("UseEarthlyStarTime")
&& EarthlyStar.CanUse(out act)) return act;
Expand Down Expand Up @@ -97,6 +97,10 @@ private protected override bool EmergencyAbility(byte abilityRemain, IAction nex
{
if (base.EmergencyAbility(abilityRemain, nextGCD, out act)) return true;

if (TargetUpdater.PartyHealers.Count() == 1 && Player.HasStatus(false, StatusID.Silence)
&& HasHostilesInRange && EchoDrops.CanUse(out act)) return true;


if (!InCombat) return false;

//如果要群奶了,先上个天宫图!
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/Rotations/Magicial/BLM/BLM_Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private protected override IAction CountDownAction(float remainTime)

private protected override bool AttackAbility(byte abilitiesRemaining, out IAction act)
{
if (InBurst && UseTincture(out act)) return true;
if (InBurst && UseBurstMedicine(out act)) return true;
if (InUmbralIce)
{
if (UmbralIceStacks == 2 && !HasFire
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/Rotations/Magicial/RDM/RDM_Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private protected override bool AttackAbility(byte abilitiesRemaining, out IActi
}
}

if(InBurst && UseTincture(out act)) return true;
if(InBurst && UseBurstMedicine(out act)) return true;

//Attack abilities.
if (ContreSixte.CanUse(out act, mustUse: true)) return true;
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/Rotations/Melee/NIN/NIN_Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ private protected override bool AttackAbility(byte abilitiesRemaining, out IActi

if (!IsMoving && TenChiJin.CanUse(out act)) return true;
if (Kassatsu.CanUse(out act)) return true;
if (UseTincture(out act)) return true;
if (UseBurstMedicine(out act)) return true;

if (Bunshin.CanUse(out act)) return true;
if (HellfrogMedium.CanUse(out act)) return true;
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/Rotations/Tank/DRK/DRK_Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private protected override IAction CountDownAction(float remainTime)
{
//Provoke when has Shield.
if (HasTankStance && remainTime <= Service.Configuration.AbilitiesInterval && Provoke.CanUse(out var act)) return act;
if (remainTime <= 2 && UseTincture(out act)) return act;
if (remainTime <= 2 && UseBurstMedicine(out act)) return act;
if (remainTime <= 3 && TheBlackestNight.CanUse(out act)) return act;
if (remainTime <= 4 && BloodWeapon.CanUse(out act)) return act;
return base.CountDownAction(remainTime);
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/Rotations/Tank/PLD/PLD_Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private protected override bool AttackAbility(byte abilitiesRemaining, out IActi
}
else if(InBurst)
{
if(UseTincture(out act)) return true;
if(UseBurstMedicine(out act)) return true;
}

if (CircleofScorn.CanUse(out act, mustUse: true)) return true;
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/Timeline/ActionCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void Draw(ICustomRotation combo)
var name = _action?.Name ?? string.Empty;
ImGui.SetNextItemWidth(Math.Max(80, ImGui.CalcTextSize(name).X + 30));

ImGuiHelper.SearchCombo($"##ActionChoice{GetHashCode()}", name, ref searchTxt, combo.AllActions, i =>
ImGuiHelper.SearchCombo($"##ActionChoice{GetHashCode()}", name, ref searchTxt, combo.AllBaseActions, i =>
{
_action = (BaseAction)i;
ID = (ActionID)_action.ID;
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/Timeline/RotationCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public void Draw(ICustomRotation rotation)

ImGui.SameLine();
var name = _action?.Name ?? string.Empty;
ImGuiHelper.SearchCombo($"##ActionChoice{GetHashCode()}", name, ref searchTxt, rotation.AllActions, i =>
ImGuiHelper.SearchCombo($"##ActionChoice{GetHashCode()}", name, ref searchTxt, rotation.AllBaseActions, i =>
{
_action = (BaseAction)i;
ID = (ActionID)_action.ID;
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/Timeline/TargetCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void Draw(ICustomRotation combo)
IsTarget = false;
}

ImGuiHelper.SearchItems(ref searchTxt, combo.AllActions, i =>
ImGuiHelper.SearchItems(ref searchTxt, combo.AllBaseActions, i =>
{
_action = (BaseAction)i;
ID = (ActionID)_action.ID;
Expand Down
7 changes: 4 additions & 3 deletions RotationSolver/Updaters/ActionUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ internal unsafe static void UpdateActionInfo()
BluSlots[i] = ActionManager.Instance()->GetActiveBlueMageActionInSlot(i);
}
UPdateMPTimer();
UpdateWeaponTime();
}

internal static unsafe void UpdateWeaponTime()
private static unsafe void UpdateWeaponTime()
{
var player = Service.ClientState.LocalPlayer;
if (player == null) return;
Expand All @@ -117,8 +118,8 @@ internal static unsafe void UpdateWeaponTime()

//确认能力技的相关信息
var interval = Service.Configuration.AbilitiesInterval;
var checkRemain = WeaponRemain;
var checkElapsed = WeaponElapsed;
var checkRemain = WeaponRemain + Service.Configuration.ActionAhead;
var checkElapsed = WeaponElapsed - Service.Configuration.ActionAhead;
if (checkRemain < interval || WeaponElapsed == 0)
{
AbilityRemain = 0;
Expand Down
1 change: 0 additions & 1 deletion RotationSolver/Updaters/MajorUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ private static void FrameworkUpdate(Framework framework)
ActionUpdater.DoAction();

//Late for update weapon time.
Task.Run(ActionUpdater.UpdateWeaponTime);
MacroUpdater.UpdateMacro();
}

Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/Updaters/RotationUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static void UpdateRotation()
if (!group.classJobIds.Contains(_job)) continue;

RightNowRotation = GetChoosedRotation(group, _rotationName);
RightRotationBaseActions = RightNowRotation.AllActions;
RightRotationBaseActions = RightNowRotation.AllBaseActions;
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/Windows/RotationConfigWindow_Action.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private void DrawActionList()

if (ImGui.BeginChild("Action List", new Vector2(0f, -1f), true))
{
foreach (var pair in RotationUpdater.RightRotationBaseActions.GroupBy(a => a.CateName).OrderBy(g => g.Key))
foreach (var pair in RotationUpdater.RightNowRotation.AllActions.GroupBy(a => a.CateName).OrderBy(g => g.Key))
{
if (ImGui.CollapsingHeader(pair.Key))
{
Expand Down

0 comments on commit 3698f0a

Please sign in to comment.