private bool CheckCurrency(CustomerInfo customer, double margin = 0.1) { // Give the customer a little time to move currency to trade window. Thread.Sleep(5000); double chaosValueInTrade = 0.0; double chaosValueExpected = customer.CurrencyType.ChaosEquivalent * customer.Cost; int amountInTrade = 0; // Count Currency in trade window while (ClientManager.Instance.GetAbsoluteAssetPosition(StaticUtils.GetUIFragmentPath("trade_window_title")).IsVisible) { customer.TradeStatus = CustomerInfo.TradeStatuses.STARTED; foreach (Position offerSlot in TradePositions.GetPositions(ClientManager.Instance.ResolutionEnum)) { if (customer.TradeStatus != CustomerInfo.TradeStatuses.STARTED) { return(false); } ClientManager.Instance.HoverPosition(ClientManager.Instance.TranslatePosition(offerSlot)); Thread.Sleep(100); } foreach (Position offerSlot in TradePositions.GetPositions(ClientManager.Instance.ResolutionEnum)) { if (customer.TradeStatus != CustomerInfo.TradeStatuses.STARTED) { break; } ItemInfoParser itemInfo = ClientManager.Instance.GetItemInfo(offerSlot); if (itemInfo.Item.ChaosValue != 0) { chaosValueInTrade += itemInfo.Item.ChaosValue; } if (itemInfo.Item.SizeInStack != 0) { amountInTrade += itemInfo.Item.SizeInStack; } if (chaosValueInTrade >= chaosValueExpected - (chaosValueExpected * margin) || amountInTrade >= customer.Cost) { break; // No need to keep checking } } if (chaosValueInTrade >= chaosValueExpected - (chaosValueExpected * margin) || amountInTrade >= customer.Cost) { break; // we are ready to accept the trade } } return(true); }
private bool ApiAcceptTrade(CustomerInfo customer) { while (ClientManager.Instance.GetAbsoluteAssetPosition(StaticUtils.GetUIFragmentPath("trade_window_title")).IsVisible) { customer.TradeStatus = CustomerInfo.TradeStatuses.STARTED; foreach (Position offerSlot in TradePositions.GetPositions(ClientManager.Instance.ResolutionEnum)) { if (customer.TradeStatus != CustomerInfo.TradeStatuses.STARTED) { return(false); } ClientManager.Instance.HoverPosition(ClientManager.Instance.TranslatePosition(offerSlot)); Thread.Sleep(100); } Position button = ClientManager.Instance.GetAbsoluteAssetPosition(StaticUtils.GetUIFragmentPath("accept_tradewindow")); if (button.IsVisible) { ClientManager.Instance.ClickPosition(button); } Thread.Sleep(500); } return(true); }