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

Commit

Permalink
fix: add a collision check for action target.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed May 26, 2023
1 parent 728f2e8 commit 95ddb00
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 26 deletions.
2 changes: 2 additions & 0 deletions Resources/AnimationLockTime.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"116": 0.6,
"117": 0.6,
"118": 0.6,
"121": 0.6,
"124": 0.1,
"125": 0.6,
"127": 0.1,
Expand Down Expand Up @@ -350,6 +351,7 @@
"25865": 0.1,
"25870": 0.6,
"25885": 0.6,
"26768": 0.1,
"26798": 2.1,
"26802": 2.1,
"31323": 2.1,
Expand Down
8 changes: 8 additions & 0 deletions Resources/HostileCastingArea.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@
13314,
13343,
13389,
13397,
13404,
13440,
13461,
13462,
14119,
14120,
14191,
14195,
14470,
15042,
15813,
15824,
15832,
Expand Down
34 changes: 11 additions & 23 deletions RotationSolver.Basic/Actions/BaseAction_Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using ECommons.ExcelServices;
using ECommons.GameHelpers;
using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Common.Component.BGCollision;

namespace RotationSolver.Basic.Actions;

Expand Down Expand Up @@ -63,7 +64,6 @@ private bool FindTarget(bool mustUse, out BattleChara target)

float range = Range;

//如果都没有距离,这个还需要选对象嘛?选自己啊!
if (range == 0 && EffectRange == 0)
{
target = player;
Expand Down Expand Up @@ -206,13 +206,11 @@ private bool TargetPartyAndHostile(float range, bool mustUse, out BattleChara ta
#region Target party
private bool TargetParty(float range, int aoeCount, bool mustUse, out BattleChara target)
{
//还消耗2400的蓝,那肯定是复活的。
if (_action.PrimaryCostType == 3 && _action.PrimaryCostValue == 24 || (ActionID)ID == ActionID.AngelWhisper)
{
return TargetDeath(out target);
}

//找到没死的队友们。
var availableCharas = DataCenter.PartyMembers.Where(player => player.CurrentHp != 0);

if (Service.Config.TargetFriendly ? _action.CanTargetFriendly : (ActionID)ID == ActionID.AethericMimicry)
Expand All @@ -229,10 +227,8 @@ private bool TargetParty(float range, int aoeCount, bool mustUse, out BattleChar
return false;
}

//判断是否是范围。
if (_action.CastType > 1 && (ActionID)ID != ActionID.DeploymentTactics)
{
//找到能覆盖最多的位置,并且选血最少的来。
target = ChoiceTarget(GetMostObjects(availableCharas, aoeCount), mustUse);
}
else
Expand All @@ -242,7 +238,7 @@ private bool TargetParty(float range, int aoeCount, bool mustUse, out BattleChar
availableCharas = availableCharas.Where(b => b.IsJobCategory(JobRole.Tank));
}
availableCharas = TargetFilter.GetObjectInRadius(availableCharas, range).Where(CanUseTo);
//特殊选队友的方法。

target = ChoiceTarget(availableCharas, mustUse);
}
if (target == null) return false;
Expand All @@ -261,7 +257,6 @@ private static bool TargetDeath(out BattleChara target)
#region Target Hostile
private bool TargetHostile(float range, bool mustUse, int aoeCount, out BattleChara target)
{
//如果不用自动找目标,那就直接返回。
if (DataCenter.StateType == StateCommandType.Manual)
{
if (Svc.Targets.Target is BattleChara b && b.IsNPCEnemy() && b.DistanceToPlayer() <= range)
Expand All @@ -279,7 +274,6 @@ private bool TargetHostile(float range, bool mustUse, int aoeCount, out BattleCh
return false;
}

//找到被标记攻击的怪
if (Service.Config.ChooseAttackMark)
{
var b = MarkingHelper.GetAttackMarkChara(DataCenter.HostileTargets);
Expand Down Expand Up @@ -361,13 +355,10 @@ private IEnumerable<BattleChara> GetMostObjects(IEnumerable<BattleChara> targets

if (_action.CastType == 1) return canGetObj;

//能打到MaxCount以上数量的怪的怪。
List<BattleChara> objectMax = new(canGetObj.Count());

//循环能打中的目标。
foreach (var t in canGetObj)
{
//计算能达到的所有怪的数量。
int count = CanGetTargetCount(t, canAttack);

if (count == maxCount)
Expand Down Expand Up @@ -421,19 +412,19 @@ public bool CanGetTarget(BattleChara target, BattleChara subTarget)

switch (_action.CastType)
{
case 2: // 圆形范围攻击
case 2: // Circle
return Vector3.Distance(target.Position, subTarget.Position) - subTarget.HitboxRadius <= EffectRange;

case 3: // Sector
if(subTarget.DistanceToPlayer() > EffectRange) return false;
tdir += dir / dir.Length() * target.HitboxRadius / (float)Math.Sin(_alpha);
return Vector3.Dot(dir, tdir) / (dir.Length() * tdir.Length()) >= Math.Cos(_alpha);

case 4: //直线范围攻击
case 4: //Line
if (subTarget.DistanceToPlayer() > EffectRange) return false;
return Vector3.Cross(dir, tdir).Length() / dir.Length() <= 2 + target.HitboxRadius;

case 10: //环形范围攻击也就这么判断吧,我烦了。
case 10: //Donut
var dis = Vector3.Distance(target.Position, subTarget.Position) - subTarget.HitboxRadius;
return dis <= EffectRange && dis >= 8;
}
Expand Down Expand Up @@ -484,21 +475,18 @@ bool CheckStatus(BattleChara tar)

public unsafe bool CanUseTo(BattleChara tar)
{
if (tar == null) return false;
if (tar == null || !Player.Available) return false;

var tarAddress = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)tar.Address;
var tarAddress = tar.GetAddress();

if (!ActionManager.CanUseActionOnTarget(AdjustedID, tarAddress)) return false;

if((IntPtr)Player.BattleChara == IntPtr.Zero || (IntPtr)tarAddress == IntPtr.Zero) return false;
var point = Player.Object.Position;
var tarPt = tar.Position;
var direction = tarPt - point;
if(BGCollisionModule.Raycast2(point, direction, out var _, direction.Length())) return false;

return true;

// var id = ActionManager.GetActionInRangeOrLoS(AdjustedID,
//(FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)Service.RawPlayer,
// tarAddress);

// return id is 0 or 565;
}

private static bool NoAOE
Expand Down
2 changes: 0 additions & 2 deletions RotationSolver.Basic/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Dalamud.Configuration;
using Dalamud.Game.ClientState.GamePad;
using Dalamud.Logging;
using ECommons.DalamudServices;
using ECommons.ExcelServices;

Expand Down
1 change: 0 additions & 1 deletion RotationSolver.Basic/Data/IconSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public static TextureWrap GetTexture(uint id)
public static TextureWrap GetTexture(string path)
=> ThreadLoadImageHandler.TryGetTextureWrap(path, out var texture) ? texture : null;


private static readonly Dictionary<IconType, uint[]> _icons = new()
{
{ IconType.Gold, new uint[40]
Expand Down
Binary file not shown.

0 comments on commit 95ddb00

Please sign in to comment.