/// <summary> /// Cancel the clearing of the <see cref="Obstacle"/> if <see cref="IsClearing"/> is <c>true</c>; otherwise /// it throws an <see cref="InvalidOperationException"/>. /// </summary> /// <exception cref="InvalidOperationException"><see cref="IsClearing"/> is <c>false</c>.</exception> public void CancelClearing(int ctick) { if (!IsClearing) { throw new InvalidOperationException("Obstacle object is not being cleared."); } Village.WorkerManager.DeallotateWorker(this); _timer.Stop(); }
/// <summary> /// Cancels the construction of the <see cref="Buildable{TCsvData}"/>. /// </summary> public void CancelConstruction(int ctick) { if (!IsConstructing) { throw new InvalidOperationException("Buildable object is not in construction."); } _timer.Stop(); Village.WorkerManager.DeallotateWorker(this); var level = Village.Level; var data = NextUpgrade; var buildCost = GetBuildCost(data); var buildResource = GetBuildResource(data); // 50% of build cost. var refund = (int)Math.Round(0.5 * buildCost); level.Avatar.UseResource(buildResource, -refund); }