Skip to main content

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.

Constructors​

MemberWhat it is
TaxManager()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

11 private and internal fields
MemberWhat it is
private static Logger loggerNLog logger for this class.
private AltaEvent noCoinsLeftEvent fired when taxing ends because the tax dock is empty or the vendor has no stock. Exposed as NoCoinsLeft.
private MethodSyncStruct<bool> syncMethod sync on SyncD that carries the tax tick state to clients.
private int taxedAmountCoins taken from the tax dock each interval. Defaults to 1.
private Timeline.IEntry taxEntryThe repeating Timeline entry that calls TakeTax. Saved and reloaded with the vendor.
private int taxingTimeLength of one tax interval, in seconds.
private GaugeProgressBar taxMeterBarGauge bar that shows how much of the current tax interval is left.
private float taxMeterProgressLerpSpeedHow fast the tax meter bar moves toward its target value, per second.
private float timeRemainingSeconds left in the current tax interval, used to drive the meter.
private TradeVendor tradeVendorThe trade vendor whose tax dock and stock this manager reads.
private IUnityUpdateMethod updateHandle for the registered UpdateTaxTime update method, null when the meter isn't animating.

Properties​

MemberWhat it is
bool IsTaxingInProgress { get; private set; }True while the stall is being taxed.
int TaxedAmount { get; }Coins taken each interval.

Events​

MemberWhat it is
event Action NoCoinsLeftFired when tax can't be paid (or stock runs out while taxing).

Methods​

MemberWhat 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
MemberWhat 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: