Added chest looter

This commit is contained in:
Erik 2025-12-09 17:31:27 +01:00
parent 5fe0f85369
commit 2eb9a7773e
5 changed files with 569 additions and 9 deletions

View file

@ -220,5 +220,109 @@ namespace MosswartMassacre
int rawIcon = GetItemIcon(itemName);
return rawIcon != 0 ? rawIcon + 0x6000000 : 0x6002D14;
}
/* ----------------------------------------------------------
* 5) Chest Looter helper methods
* -------------------------------------------------------- */
/// <summary>
/// Calculate 3D distance from player to a world object
/// </summary>
/// <param name="objectId">World object ID</param>
/// <returns>Distance in meters, or float.MaxValue if object is invalid</returns>
public static float GetDistanceToWorldObject(int objectId)
{
try
{
if (!CoreManager.Current.Actions.IsValidObject(objectId))
return float.MaxValue;
Vector3 playerPos = GetPlayerPosition();
Vector3 objectPos = GetWorldObjectPosition(objectId);
return Vector3.Distance(playerPos, objectPos);
}
catch
{
return float.MaxValue;
}
}
/// <summary>
/// Find the closest chest with the specified name in the game world
/// </summary>
/// <param name="chestName">Name of the chest to find</param>
/// <returns>WorldObject of the closest chest, or null if not found</returns>
public static WorldObject FindClosestChestByName(string chestName)
{
try
{
WorldObject closestChest = null;
float closestDistance = float.MaxValue;
// Search all objects in WorldFilter
using (var objects = CoreManager.Current.WorldFilter.GetAll())
{
foreach (WorldObject wo in objects)
{
// Check if this is a container (chest)
if (wo.ObjectClass != ObjectClass.Container)
continue;
// Check if name matches (case-insensitive, partial match allowed)
if (!wo.Name.Contains(chestName) &&
!string.Equals(wo.Name, chestName, StringComparison.OrdinalIgnoreCase))
continue;
// Calculate distance
float distance = GetDistanceToWorldObject(wo.Id);
// Update closest if this is nearer
if (distance < closestDistance)
{
closestDistance = distance;
closestChest = wo;
}
}
}
return closestChest;
}
catch
{
return null;
}
}
/// <summary>
/// Find a key in the player's inventory by name
/// </summary>
/// <param name="keyName">Name of the key to find</param>
/// <returns>WorldObject of the key, or null if not found</returns>
public static WorldObject FindKeyInInventory(string keyName)
{
try
{
foreach (WorldObject wo in CoreManager.Current.WorldFilter.GetInventory())
{
// Check if this is a key
if (wo.ObjectClass != ObjectClass.Key)
continue;
// Check if name matches (case-insensitive, partial match allowed)
if (wo.Name.Contains(keyName) ||
string.Equals(wo.Name, keyName, StringComparison.OrdinalIgnoreCase))
{
return wo;
}
}
return null;
}
catch
{
return null;
}
}
}
}