Class ItemGenerator
Handles random attribute generation and management for items, including applying/removing attributes to characters. Supports equippable and template-based attribute logic, and exposes events for attribute changes.
public class ItemGenerator
- Inheritance
-
ItemGenerator
- Inherited Members
Fields
seed
The random seed used for attribute generation.
protected int seed
Field Value
Properties
Attributes
Exposes the generated attributes for external access.
public Dictionary<string, ItemAttribute> Attributes { get; }
Property Value
Seed
Gets or sets the seed for generation. Changing the seed triggers attribute regeneration.
public int Seed { get; set; }
Property Value
Methods
ApplyAttributes(ICharacter)
Applies all generated attributes to the specified character, adding values to their stats/resources.
public void ApplyAttributes(ICharacter character)
Parameters
characterICharacterThe character to apply attributes to.
Remarks
Keyed by the item, so applying twice is applying once. A character loaded from the database, restored from a spawn payload and then corrected by a reconcile can reach this more than once for the same item; under the old accumulate-and-negate shape each arrival doubled the bonus and something downstream had to undo it.
Does nothing for an item with no identity yet — see TryResolveLedgerSource(int, out ModifierSource).
BuildTooltip(TooltipBuilder)
Populates the tooltip builder with generator information and all generated attributes. Uses TooltipColors for consistent formatting.
public void BuildTooltip(TooltipBuilder builder)
Parameters
builderTooltipBuilderThe tooltip builder to populate.
Destroy()
Cleans up the generator, detaching from the item.
public void Destroy()
Generate()
Triggers attribute generation using the current seed and item template.
public void Generate()
Generate(int, BaseItemTemplate)
Generates item attributes using the provided seed and template. Handles equippable logic, random attributes, and additional template attributes.
public void Generate(int seed, BaseItemTemplate template = null)
Parameters
seedintThe random seed for generation.
templateBaseItemTemplateThe item template to use. If null, uses the item's template.
GetAttribute(string)
Gets the generated attribute by name, or null if not found.
public ItemAttribute GetAttribute(string name)
Parameters
namestringThe attribute name.
Returns
- ItemAttribute
The ItemAttribute instance, or null.
Initialize(Item, int)
Initializes the generator with its parent item and seed, triggering attribute generation.
public void Initialize(Item item, int seed)
Parameters
RemoveAttributes(ICharacter)
Removes all generated attributes from the specified character, subtracting values from their stats/resources.
public void RemoveAttributes(ICharacter character)
Parameters
characterICharacterThe character to remove attributes from.
SetAttribute(string, int)
Sets the value of a generated attribute by name, and updates the character's attribute modifiers if equipped.
public void SetAttribute(string name, int newValue)