- Add a line of sight check
- Add Package dir to gitignore - Limit distance
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -32,6 +32,7 @@ bld/
|
|||||||
[Oo]ut/
|
[Oo]ut/
|
||||||
[Ll]og/
|
[Ll]og/
|
||||||
[Ll]ogs/
|
[Ll]ogs/
|
||||||
|
[Pp]ackage/
|
||||||
|
|
||||||
# Visual Studio 2015/2017 cache/options directory
|
# Visual Studio 2015/2017 cache/options directory
|
||||||
.vs/
|
.vs/
|
||||||
|
@@ -23,8 +23,8 @@ namespace DrakiaXYZ.LootRadius.Helpers
|
|||||||
"Loot Radius",
|
"Loot Radius",
|
||||||
2f,
|
2f,
|
||||||
new ConfigDescription(
|
new ConfigDescription(
|
||||||
"The distance to include loot from. Note that increasing this may result in pulling loot through walls/floors",
|
"The distance to include loot from",
|
||||||
null,
|
new AcceptableValueRange<float>(0f, 10f),
|
||||||
new ConfigurationManagerAttributes { })));
|
new ConfigurationManagerAttributes { })));
|
||||||
|
|
||||||
RecalcOrder();
|
RecalcOrder();
|
||||||
|
@@ -75,13 +75,14 @@ namespace DrakiaXYZ.LootRadius.Patches
|
|||||||
// Collect the items around the player, and add them to the fake stash
|
// Collect the items around the player, and add them to the fake stash
|
||||||
var grid = _stash.Grids[0];
|
var grid = _stash.Grids[0];
|
||||||
Vector3 playerPosition = Singleton<GameWorld>.Instance.MainPlayer.Position;
|
Vector3 playerPosition = Singleton<GameWorld>.Instance.MainPlayer.Position;
|
||||||
|
playerPosition += (Vector3.up * 0.5f);
|
||||||
Collider[] colliders = Physics.OverlapSphere(playerPosition, Settings.LootRadius.Value, _interactiveLayerMask);
|
Collider[] colliders = Physics.OverlapSphere(playerPosition, Settings.LootRadius.Value, _interactiveLayerMask);
|
||||||
if (colliders.Length > 0)
|
if (colliders.Length > 0)
|
||||||
{
|
{
|
||||||
foreach (Collider collider in colliders)
|
foreach (Collider collider in colliders)
|
||||||
{
|
{
|
||||||
var item = collider.gameObject.GetComponentInParent<LootItem>();
|
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;
|
item.Item.OriginalAddress = item.Item.CurrentAddress;
|
||||||
_removeMethod.Invoke(item.Item.CurrentAddress, new object[] { item.Item, string.Empty, false });
|
_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 });
|
_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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user