Game.Citizens.ResourceBought
Assembly: Assembly-CSharp
Namespace: Game.Citizens
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary: Represents a single resource purchase transaction between two entities. Stores the seller and payer entities, which resource was bought, the purchased amount, and the travel distance associated with that transaction. Implements serialization so it can be written to/read from the game's binary streams (used by save/load or network replication).
Fields
-
public Entity m_Seller
Holds the Entity that sold the resource (the provider/source). -
public Entity m_Payer
Holds the Entity that paid for the resource (the consumer/receiver). -
public Resource m_Resource
The type of resource that was bought. Resource is looked up/encoded using EconomyUtils (see serialization comments below). -
public int m_Amount
The integer amount/quantity of the resource that was purchased. -
public float m_Distance
The distance associated with the transaction (e.g., travel distance between seller and payer). Useful for economic calculations or statistics.
Properties
- This type does not declare any C# properties. It exposes only the public fields listed above.
Constructors
public ResourceBought()
No explicit constructor is defined in the source. The default parameterless constructor (value-initializing the fields) is used when instances are created.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Serializes the struct fields to the provided writer in the following order:- m_Seller — written as an Entity
- m_Payer — written as an Entity
- m_Resource — converted to a sbyte index via EconomyUtils.GetResourceIndex(m_Resource) and written as sbyte
- m_Amount — written as int
-
m_Distance — written as float Important: the resource is encoded as a small integer (sbyte) for compactness; both sides must use the same EconomyUtils mappings.
-
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads data from the provided reader in the same order as Serialize and assigns to the struct fields: - Reads Entity into m_Seller
- Reads Entity into m_Payer
- Reads sbyte value for the resource index, then maps it back to a Resource using EconomyUtils.GetResource(value)
- Reads int into m_Amount
- Reads float into m_Distance Because the resource is stored as an index, the deserialization must call EconomyUtils.GetResource to reconstruct the Resource enum/object.
Usage Example
// Create and populate
ResourceBought rb = new ResourceBought();
rb.m_Seller = sellerEntity;
rb.m_Payer = payerEntity;
rb.m_Resource = EconomyUtils.GetResource( /* some index or enum value */ );
rb.m_Amount = 100;
rb.m_Distance = 12.5f;
// Serialize (writer must implement IWriter and know how to write Entity/sbyte/int/float)
rb.Serialize(writer);
// Later, or when reading from stream:
ResourceBought rb2 = new ResourceBought();
rb2.Deserialize(reader);
// rb2 now contains the same data (assuming writer/reader order and EconomyUtils mappings match)
Notes: - Keep serialization/deserialization order consistent to avoid data corruption. - EconomyUtils.GetResourceIndex and EconomyUtils.GetResource must be in sync between versions; changes in resource indexing can break save compatibility. - This struct is suitable as an ECS component payload or as a transient record used during economy updates and logging.