using RynthCore.PluginSdk; using RynthCore.Plugin.Shared; namespace RynthCore.Plugin.RynthAi.Loot; /// What did. internal enum LootPickupResult { /// MoveItemExternal into one of our packs was sent. Moved, /// UseObject was sent (no move call on this engine, and the item can't be worn). Used, /// No pack of ours has a free slot. NoRoom, /// No move call, and a use could put the item on the character, so nothing was sent. Refused, /// The engine turned the call down. Failed, } /// /// Picks a corpse item up into a pack. Looting used to send UseObject (a double-click). On /// a wearable item outside the pack the client turns a use into get-and-wield when the slot /// is free, so jewellery looted for salvage went onto the character whenever its ring, /// bracelet or necklace slot was empty (2026-10-02 tester report). A move into a pack never /// wields anything, so it is the only call used when the engine has it. /// internal static class LootPickup { public static LootPickupResult Send(RynthCoreHost host, WorldObjectCache? cache, uint itemId, uint playerId, out uint destination) { destination = 0; if (itemId == 0) return LootPickupResult.Failed; if (host.HasMoveItemExternal) { if (playerId == 0) return LootPickupResult.Failed; int pid = unchecked((int)playerId); int dest = cache == null ? pid : WorldObjectCache.FindLootDestination(cache.GetDirectInventory(forceRefresh: false), pid, host); if (dest == 0) return LootPickupResult.NoRoom; destination = unchecked((uint)dest); return host.MoveItemExternal(itemId, destination, 0) ? LootPickupResult.Moved : LootPickupResult.Failed; } if (CouldBeWorn(cache?[unchecked((int)itemId)])) return LootPickupResult.Refused; return host.HasUseObject && host.UseFor(itemId, "Loot", "pick up from the open corpse") ? LootPickupResult.Used : LootPickupResult.Failed; } /// /// True when a use on could wield it: it has equip slots, or it is /// a kind of thing that is worn or wielded. Unknown items count as wearable. /// public static bool CouldBeWorn(WorldObject? wo) { if (wo == null) return true; if (wo.Values(LongValueKey.Locations, 0) != 0) return true; return wo.ObjectClass is AcObjectClass.Unknown or AcObjectClass.Jewelry or AcObjectClass.Armor or AcObjectClass.Clothing or AcObjectClass.MeleeWeapon or AcObjectClass.MissileWeapon or AcObjectClass.WandStaffOrb; } }