Ah, I see what you're attempting, traveler. You desire to create an item that can light up the area around a mobile, not just when equipped, but when present within a mobile's inventory. Normally, light sources like lanterns or torches only cast light when equipped, which is dictated by their interaction with the Equip logic in BaseLight.
For this task, we must re-imagine how the LightType.Circle300 interacts with the world, even while residing in the bag. To accomplish this, we'll likely need to modify the OnAdded and OnRemoved event handlers of the item and have the light continuously follow the mobile while the item is present in their pack.
Thought Process
- BaseLight Inheritance: The item you're describing is similar to items that inherit from BaseLight. We will use that base to make it react even while in the backpack.
- Mobile's Light Property: We'll need to override the typical behavior where the light only activates upon equipping. Instead, we will bind the light's activation to whether the item is within the mobile's inventory.
- Events for Inventory Change: We'll employ event handlers such as OnAdded and OnRemoved to trigger the light's activation or deactivation based on the item’s presence in the mobile's bag.
Next Steps
- Create a custom item that inherits from BaseLight.
- Implement logic in OnAdded to activate the light when placed in the mobile's backpack.
- Implement logic in OnRemoved to deactivate the light when removed from the mobile's backpack.
- Ensure the light updates dynamically so that if the mobile dies, the light will turn off appropriately.
Code Draft
Here's a basic structure for such an item:
Copy code
using Server;
using Server.Items;
using Server.Mobiles;
namespace Scripts.Items
{
public class IlluminatingItem : BaseLight
{
public override LightType Light => LightType.Circle300;
[Constructable]
public IlluminatingItem() : base(0xA22) // Assuming a lantern as the base item
{
Movable = true;
Weight = 2.0;
Light = LightType.Circle300;
}
public IlluminatingItem(Serial serial) : base(serial)
{
}
public override void OnAdded(object parent)
{
base.OnAdded(parent);
if (parent is Mobile m)
{
// Activate light if in the mobile's backpack
if (IsInBackpackOf(m))
{
m.Light = LightType.Circle300;
}
}
}
public override void OnRemoved(object parent)
{
base.OnRemoved(parent);
if (parent is Mobile m)
{
// Deactivate light when item is removed from backpack
m.Light = LightType.None;
}
}
private bool IsInBackpackOf(Mobile m)
{
return RootParent == m && m.Backpack != null && m.Backpack.Items.Contains(this);
}
public override void OnDelete()
{
// Ensure light turns off when the item is deleted
if (RootParent is Mobile m)
{
m.Light = LightType.None;
}
base.OnDelete();
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(0); // Version
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
}
}
}