- Add a line of sight check

- Add Package dir to gitignore
- Limit distance
This commit is contained in:
DrakiaXYZ
2024-04-21 22:43:06 -07:00
parent e66681c90a
commit 6ddde5ec4e
3 changed files with 36 additions and 3 deletions

1
.gitignore vendored
View File

@@ -32,6 +32,7 @@ bld/
[Oo]ut/
[Ll]og/
[Ll]ogs/
[Pp]ackage/
# Visual Studio 2015/2017 cache/options directory
.vs/

View File

@@ -23,8 +23,8 @@ namespace DrakiaXYZ.LootRadius.Helpers
"Loot Radius",
2f,
new ConfigDescription(
"The distance to include loot from. Note that increasing this may result in pulling loot through walls/floors",
null,
"The distance to include loot from",
new AcceptableValueRange<float>(0f, 10f),
new ConfigurationManagerAttributes { })));
RecalcOrder();

View File

@@ -75,13 +75,14 @@ namespace DrakiaXYZ.LootRadius.Patches
// Collect the items around the player, and add them to the fake stash
var grid = _stash.Grids[0];
Vector3 playerPosition = Singleton<GameWorld>.Instance.MainPlayer.Position;
playerPosition += (Vector3.up * 0.5f);
Collider[] colliders = Physics.OverlapSphere(playerPosition, Settings.LootRadius.Value, _interactiveLayerMask);
if (colliders.Length > 0)
{
foreach (Collider collider in colliders)
{
var item = collider.gameObject.GetComponentInParent<LootItem>();
if (item != null && item.Item.Parent.Container != grid)
if (item != null && item.Item.Parent.Container != grid && (IsCloseEnough(item.transform.position) || IsLineOfSight(item.transform.position)))
{
item.Item.OriginalAddress = item.Item.CurrentAddress;
_removeMethod.Invoke(item.Item.CurrentAddress, new object[] { item.Item, string.Empty, false });
@@ -97,5 +98,36 @@ namespace DrakiaXYZ.LootRadius.Patches
_rightPaneField.SetValue(ItemUiContext.Instance, new LootItemClass[] { _stash });
}
/**
* Return true if the item is close enough to the player's feet to bypass the line of sight check
*/
private static bool IsCloseEnough(Vector3 endPos)
{
float sqDist = (Singleton<GameWorld>.Instance.MainPlayer.Position - endPos).sqrMagnitude;
if (sqDist < 0.5f)
{
return true;
}
return false;
}
/**
* Return true if the end position is within line of sight of the player
*/
private static bool IsLineOfSight(Vector3 endPos)
{
// Start at the player's head
Vector3 startPos = Singleton<GameWorld>.Instance.MainPlayer.MainParts[BodyPartType.head].Position;
// LineCast returns true if it hits a HighPolyCollider, indicating the item isn't within line of sight of the player's head
if (Physics.Linecast(startPos, endPos, LayerMaskClass.HighPolyWithTerrainMask))
{
return false;
}
return true;
}
}
}