Buying fuel

FuelBought tells your mod when the player has paid for fuel at a station.

FuelStations fuel purchase event

FuelBought is the event on this class. FuelStations.All() lists the stations, and it is covered on the gas stations page.

public static class FuelStations
{
    public static event Action<FuelBoughtArgs> FuelBought;
}
Event Gives you When it fires
FuelBought FuelBoughtArgs The player has paid for fuel.

FuelBoughtArgs what FuelBought tells you

FuelBought gives you this. The framework builds it from a hook on the game’s GasStation.PayFuelOc payment, so it is the framework’s own type.

public sealed class FuelBoughtArgs
{
    public string StationId { get; }
    public float Amount { get; }
    public int Cost { get; }
    public MoneyCurrency Currency { get; }
}
Property Type What it means
StationId string The station, the same as FuelStationInfo.Id.
Amount float How many units of fuel were paid for, over all pumps.
Cost int The money paid.
Currency MoneyCurrency The money the cost is in. OC for now.

Things to know

  • FuelBought fires when a payment goes through. If the player cannot afford the bill, nothing is paid and the event does not fire. (It fires after GasStation.PayFuelOc when the game’s priceToPayOc went from above zero back to zero.)
  • Currency is always OC for now. The game only pays this kind of bill in OC (Open Sewer Coins, see the glossary).
  • Amount is the fuel the payment covers. The framework reads it before the game empties the pumps. (It is FuelPump.filledAmount, added up over the station’s pumps.)
  • The money side of the same payment is Cash.MoneyChanged. See Economy. FuelBought tells you what the money was spent on.
  • The event fires for every way the game starts a payment. The game calls the payment method from scene or dialogue wiring, not from its code, and the framework changes the method itself so every caller is covered. (PayFuelOc has no C# caller in the game code.)

Limits

  • Cost and Amount can disagree when the player filled more than one pump. Cost is the bill the game holds, and the game overwrites that bill each time it changes instead of adding to it. So Cost is the last pump’s bill, while Amount adds up every pump. This is how the game counts, and the framework does not fix it. (Cost is priceToPayOc, and GasStation.UpdatePriceToPayOc overwrites it.)
  • The framework does not hold the event back while a save loads. A handler that should ignore events raised then can check SaveData.Busy, which is true while a save is loading or being written.