TaxManager
A class in Root.Township, Alta.Trading.
Part of a TradeVendor that takes TaxedAmount coins from the tax dock every taxingTime seconds. When coins run out it fires NoCoinsLeft and the stall closes. Server side; clients show a tax meter.
- Listed in Crafting and making
- Inherits or implements
NetworkEntityBehaviour,ISavable<TaxSaveData>,ISavableSave<TaxSaveData>,ISavableSaveBase - Derived types
TaxSaveData - Documented in Trading
Constructors
| Member | What it is |
|---|---|
TaxManager() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
11 private and internal fields
| Member | What it is |
|---|---|
private static Logger logger | NLog logger for this class. |
private AltaEvent noCoinsLeft | Event fired when taxing ends because the tax dock is empty or the vendor has no stock. Exposed as NoCoinsLeft. |
private MethodSyncStruct<bool> sync | Method sync on SyncD that carries the tax tick state to clients. |
private int taxedAmount | Coins taken from the tax dock each interval. Defaults to 1. |
private Timeline.IEntry taxEntry | The repeating Timeline entry that calls TakeTax. Saved and reloaded with the vendor. |
private int taxingTime | Length of one tax interval, in seconds. |
private GaugeProgressBar taxMeterBar | Gauge bar that shows how much of the current tax interval is left. |
private float taxMeterProgressLerpSpeed | How fast the tax meter bar moves toward its target value, per second. |
private float timeRemaining | Seconds left in the current tax interval, used to drive the meter. |
private TradeVendor tradeVendor | The trade vendor whose tax dock and stock this manager reads. |
private IUnityUpdateMethod update | Handle for the registered UpdateTaxTime update method, null when the meter isn't animating. |
Properties
| Member | What it is |
|---|---|
bool IsTaxingInProgress { get; private set; } | True while the stall is being taxed. |
int TaxedAmount { get; } | Coins taken each interval. |
Events
| Member | What it is |
|---|---|
event Action NoCoinsLeft | Fired when tax can't be paid (or stock runs out while taxing). |
Methods
| Member | What it is |
|---|---|
void CancelTimer() | Stops taxing and resets the meter. |
void InitialiseTaxProcess() | Server: starts the repeating tax and takes the first payment now. |
override void Initialize() | Sets up the meter sync. |
void Load(TaxSaveData data, ISerializeChildren childSerializer) | Restores the tax timer and takes any payments missed while unloaded. |
override void OnConnected(Player player) | Server: sends a joining player the time left if taxing. |
TaxSaveData Save(ISerializeChildren childSerializer) | Saves whether it is taxing and the time to the next payment. |
9 private and internal methods
| Member | What it is |
|---|---|
private void AnimateTaxMeter() | Client: registers UpdateTaxTime with the update loop (once) so the tax meter bar counts down. |
private void EnableTimer() | Server: schedules TakeTax on the Timeline to repeat every taxingTime seconds. |
private void FinishTax() | Ends taxing: cancels the timer, zeroes the remaining time and fires noCoinsLeft. |
private void OnDestroy() | Cancels the tax timer on the server and stops the meter update on clients. |
private void Sync(IPlayer player, Stream stream, bool isTickOver) | Method sync for the tax tick. Sends whether a tick just finished, plus the seconds left; clients restart the meter animation. |
private void TakeTax() | Timeline callback that takes one interval of tax. |
private void TakeTaxAmount(int intervals = 1) | Server: removes taxedAmount coins per interval from the vendor's tax dock, or finishes taxing when coins or stock run out. |
private void UpdateTaxMeter(float deltaTime) | Counts down timeRemaining and eases the meter bar toward the remaining fraction; deregisters itself at zero. |
private void UpdateTaxTime() | Per-frame update that calls UpdateTaxMeter with the frame's delta time. |
Used in
Members of other types that take, return or hold a TaxManager: