fix(kit): kit extras found by item definition; stage 5 pairs in sight (#20, #22) #24

Merged
whitlocktech merged 2 commits from fix/kit-extras-belt-only into edge 2026-11-02 05:46:21 -06:00
Showing only changes of commit 5c3a360b70 - Show all commits

View File

@@ -2784,13 +2784,29 @@ namespace Oxide.Plugins
if (container == null)
continue;
foreach (Item item in container.itemList)
if (item != null && item.GetHeldEntity() is T)
if (item != null && HeldAs<T>(item) != null)
return item;
}
return null;
}
/// <summary>
/// The item's held entity as a <typeparamref name="T"/>, or, when it has none, its definition's
/// entity prefab's. Since Rust's November 2026 build a "player-only" item (a syringe) has a held
/// entity only in the belt (<c>ItemModEntity.playerOnlyEntityBeltOnly</c>), and an extra waits in
/// the main inventory until <see cref="Hold"/> moves it (issue #20).
/// </summary>
private static T HeldAs<T>(Item item) where T : HeldEntity
{
BaseEntity held = item.GetHeldEntity();
if (held != null)
return held as T;
ItemModEntity mod = item.info.GetComponent<ItemModEntity>();
GameObject prefab = mod != null && mod.entityPrefab != null && mod.entityPrefab.isValid ? mod.entityPrefab.Get() : null;
return prefab != null ? prefab.GetComponent<T>() : null;
}
/// <summary>Puts an item in its hands; only the belt can be held, so it is moved there first.</summary>
private static bool Hold(RunicNpcPlayer npc, Item item)
{
@@ -2914,7 +2930,8 @@ namespace Oxide.Plugins
if (amount <= 0f)
return false;
Hold(npc, item);
if (!Hold(npc, item))
return false; // a full belt: nowhere to hold it.
npc.SignalBroadcast(BaseEntity.Signal.Attack);
item.UseItem(1);
npc.Heal(amount);
@@ -3011,8 +3028,10 @@ namespace Oxide.Plugins
private static bool HasFuel(RunicNpcPlayer npc, Item flameItem)
{
FlameThrower f = flameItem.GetHeldEntity() as FlameThrower;
return f != null && (f.ammo > 0 || (f.fuelType != null && npc.inventory.FindItemByItemName(f.fuelType.shortname) != null));
// Off the belt it may have no held entity, so no tank (HeldAs): only the kit's fuel counts then.
FlameThrower held = flameItem.GetHeldEntity() as FlameThrower;
FlameThrower f = HeldAs<FlameThrower>(flameItem);
return f != null && ((held != null && held.ammo > 0) || (f.fuelType != null && npc.inventory.FindItemByItemName(f.fuelType.shortname) != null));
}
/// <summary>