public void AuthenticateLogin() { GetLatestLauncherVersion(); EFTWebRequest.HardwareId = _config.HardwareId; var loginDetails = new LoginRequest { email = _config.Email, pass = _config.Password, hwCode = EFTWebRequest.HardwareId, captcha = null }; var gameWebRequest = new EFTWebRequest(Log); _loginResponse = _api.CreateLoginRequest(loginDetails); _authResponse = _api.CreateLoginAuthRequest(_loginResponse, _config.HardwareId); int authResponseCode = (int)_authResponse?.err; if (authResponseCode > 0) { Log($"Received error {authResponseCode} - {_authResponse.errmsg}... Unable to continue."); } GetLatestGameVersion(); }
private void SearchForMultipleOfExistingType(List <BuyOfferPurchase> allPurchasingOffers, CurrentItemPrice currentPrice, string itemName) { var newSearchRequest = new SearchRequest(currentPrice.Id); var gameRequest = new GameRequest(LinkManager._searchMarketEndPoint, newSearchRequest); var gameWebRequest = new EFTWebRequest(Log, SessionCookie); SearchResponse?data = null; while (data == null) { var searchResp = gameWebRequest.EftGameRequest <SearchResponse>(gameRequest); if (!CanProcess(searchResp)) { break; } if (searchResp.Data?.data != null) { data = searchResp.Data; } if (data == null) { Thread.Sleep(LinkManager.Timer); } } //Get all offers, cheapest first. Gotta save those dollar bills yo //Ensure they only require roubles and no other items in order to buy. var allOffers = data.data.offers.OrderBy(o => o.requirementsCost) .Where(offer => currentPrice.Price > offer.requirementsCost) .Take(5) .ToList(); if (allOffers.Count <= 0) { Log($"Unable to find any offers that will make us profit for item {itemName}"); //Thread.Sleep(LinkManager.Timer); return; } foreach (var offer in allOffers) { var itemProfit = currentPrice.Price - offer.requirementsCost; if (itemProfit <= 0) { continue; } //TODO: Why is offer.items[0].id null???? Compare with working API... Majority of our buy requests are failing qq //TODO: Compare our buying with our selling properly in code to see where we're going wrong. Log($"Found offer - costs {offer.requirementsCost} to buy {itemName} (can be sold for {currentPrice.Price} - {itemProfit} profit)"); AddPurchaseOffer(allPurchasingOffers, offer, itemName, itemProfit); } }
public void UpdateItemPrices(PlayerProfile playerProf) { Log($"Updating item prices..."); var gameWebRequest = new EFTWebRequest(Log, SessionCookie); var gameRequest = new GameRequest(LinkManager._searchTraderForPrices, new object()); ItemPrice?traderPricesResponse = null; while (traderPricesResponse == null) { var itemPriceReq = gameWebRequest.EftGameRequest <ItemPrice>(gameRequest); if (!CanProcess(itemPriceReq)) { Thread.Sleep(500); return; } traderPricesResponse = itemPriceReq.Data; if (traderPricesResponse == null) { Thread.Sleep(500); } } Dictionary <string, List <List <ItemData> > > traderPrices = traderPricesResponse.Data; foreach (var item in LinkManager.CurrentItemPrices) { foreach (var traderPrice in traderPrices) { PlayerItem currentItem = playerProf.Inventory.Items.FirstOrDefault(pi => pi.Id == traderPrice.Key); if (currentItem != null) { if (currentItem.ItemTypeId == item.Id) { long curPrice = item.Price; long newPrice = traderPrice.Value[0][0].Count; if (item.Price == newPrice) { //Nothing has changed... next! break; } item.Price = traderPrice.Value[0][0].Count; Log($"Updated item {item.Id}'s price from {curPrice} to {item.Price}"); break; } } } } }
private bool BuyItemsInternal(List <BuyOfferPurchase> itemsToBuy) { var marketBuyRequest = new BuyOfferRequest(itemsToBuy); var gameRequest = new GameRequest(LinkManager._moveItemEndPoint, marketBuyRequest); var gameWebRequest = new EFTWebRequest(Log, SessionCookie); var offerResp = gameWebRequest.EftGameRequest <BuyOfferResponse>(gameRequest); if (!CanProcess(offerResp)) { return(false); } BuyOfferResponse marketResponse = offerResp.Data; if (marketResponse != null) { if (marketResponse.Data?.BadRequest.Count > 0) { string formattedIds = string.Join(", ", itemsToBuy.Select(itb => itb.id)); foreach (var req in marketResponse.Data.BadRequest) { Log($"Bad request during buy offer ({formattedIds})... {req.err} - {req.index} - {req.errmsg}"); } return(false); } if (marketResponse.ErrorCode != (int)APIErrorCodes.Ok) { return(false); } var itemNames = itemsToBuy.Select(bi => new { Item = bi, Name = LinkManager.ItemsToLookFor[bi.Offer.items[0]._tpl] }) .GroupBy(bi => bi.Name, bi => bi) .Select(bi => new { Count = bi.Count(), Name = bi.Key }) .ToList(); List <BoughtItem> boughtItems = GetAllBoughtItems(itemsToBuy); LinkManager.AllCurrentItems.BoughtItems.AddRange(boughtItems); Log($"Successfully bought {itemNames.Count} type(s) of item ({string.Join(", ", itemNames.Select(i => $"{i.Count}x {i.Name}"))})"); return(true); } return(false); }
public void SelectPMCProfile() { GetLatestPlayerProfile(); var gameWebRequest = new EFTWebRequest(Log, SessionCookie); var selectRequest = new ProfileSelectRequest { uid = _profile.Id }; var gameRequest = new GameRequest(LinkManager._selectProfileEndPoint, selectRequest); var selectResponse = gameWebRequest.EftGameRequest <ProfileSelectResponse>(gameRequest); gameRequest.URL = LinkManager._selectLocalizationEndPoint; gameRequest.body = new object(); //TODO: This may be useful for getting all traders possible? As currently I believe we're very specific with what we pick var localizationData = gameWebRequest.EftGameRequest <LocalizationData>(gameRequest); }
public PlayerProfile GetLatestPlayerProfile() { var gameWebRequest = new EFTWebRequest(Log, SessionCookie); var gameRequest = new GameRequest(LinkManager._getProfileListEndPoint, new object()); PlayerProfile profile = null; //Sometimes the web request can return null so we'll do a check to make sure we have actually grabbed our latest profile while (profile == null) { var profResp = gameWebRequest.EftGameRequest <ProfileResponse>(gameRequest); if (CanProcess(profResp)) { profile = profResp.Data.data.FirstOrDefault(info => info.Info.Side != "Savage"); break; } } return(_profile = profile); }
private void SearchForFirstItemOfType(List <BuyOfferPurchase> allPurchasingOffers, CurrentItemPrice currentPrice, string itemName) { var newSearchRequest = new SearchRequest(currentPrice.Id); var gameRequest = new GameRequest(LinkManager._searchMarketEndPoint, newSearchRequest); var gameWebRequest = new EFTWebRequest(Log, SessionCookie); Offer?offer = null; while (offer == null) { try { var searchResp = gameWebRequest.EftGameRequest <SearchResponse>(gameRequest); if (searchResp.Error != null) { Log( $"Unable to process search request. Error: {searchResp.Error.ErrorMessage}. Data: {searchResp.Error.Data}"); break; } offer = searchResp.Data.data.offers?.OrderBy(o => o.requirementsCost).FirstOrDefault(); } catch (Exception ex) { Log(ex.ToString()); } if (offer == null) { Thread.Sleep(500); } } Log($"Found offer - costs {offer.requirementsCost} to buy {itemName} (can be sold for {currentPrice.Price})"); AddPurchaseOffer(allPurchasingOffers, offer, itemName, 0); }
//public void SellItem(SellablePlayerItem sellableItem) //{ // if (sellableItem == null) return; // Log($"Selling item {sellableItem.Item.Id} of type {sellableItem.Item.ItemTypeId} for {sellableItem.AmountToSell} profit"); // SellItemsIndividually(new List<SellablePlayerItem>{ sellableItem }); //} ///// <summary> ///// Sells items slowly as a player would.<br/> ///// Attempts once per item. ///// </summary> //private void SellItemsIndividually(List<SellablePlayerItem> sellableItems) //{ // for(int i = 0; i < sellableItems.Count; i++) { // Log($"Selling item {i + 1} of {sellableItems.Count}"); // var itemsToSell = sellableItems.Skip(i).Take(1); // SellItems(itemsToSell); // Thread.Sleep(INDIVIDUAL_ITEM_DELAY); // } //} private List <SellItemResponseModel> SellItems(IEnumerable <SellablePlayerItem> sellables) { var itemsToSell = sellables.ToDictionary(s => s.Item.Id, s => s.AmountToSell); var gameWebRequest = new EFTWebRequest(Log, _sessionCookie); var newTraderDeal = new SellItemTrader(itemsToSell); var responseModels = new List <SellItemResponseModel>(); try { var newGameRequest = new GameRequest(LinkManager._sellItemsToTraderEndPoint, newTraderDeal); SellTraderResponse sellReq = null; while (sellReq == null) { var sellResp = gameWebRequest.EftGameRequest <SellTraderResponse>(newGameRequest); if (!CanProcess(sellResp)) { Log($"Attempted to sell {itemsToSell.Count} items. Failed."); return(null); } sellReq = sellResp.Data; } if (sellReq.data.badRequest.Count > 0) { Log($"Unable to sell {itemsToSell.Count} items... {sellReq.data.badRequest.Count} bad request(s)"); foreach (var badReq in sellReq.data.badRequest) { Log(badReq.ToString()); } return(null); } else { foreach (var item in sellReq.data.items.del) { var match = sellables.First(si => si.Item.Id == item._id); string itemName = item._id; if (LinkManager.ItemsToLookFor.TryGetValue(match.Item.ItemTypeId, out var itemToLookFor)) { itemName = itemToLookFor; } responseModels.Add(new SellItemResponseModel() { ActualProfit = match.AmountToSell }); Log($"Successfully sold item {itemName}"); } } } catch (Exception ex) { Log(ex.ToString()); } return(responseModels); }