Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

Commit

Permalink
feat: min bin searching
Browse files Browse the repository at this point in the history
Updated Min BIN search to FIFA 19
  • Loading branch information
Tim Klingeleers committed Sep 28, 2018
2 parents 76b8224 + 620ca2b commit 7bd921d
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 74 deletions.
9 changes: 5 additions & 4 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import { analytics, Settings, Queue } from './core';

import { Logger } from '../fut';
/*
import {
CardInfoSettings,
RefreshListSettings,
RemoveSoldAuctionsSettings,
RelistAuctionsSettings,
MinBinSettings,
ListSizeSettings,
} from './transferlist';
*/
import {
MinBinSettings,
} from './transferlist';

import {
FutbinSettings,
} from './futbin';
Expand Down Expand Up @@ -55,7 +56,7 @@ services.Authentication._oAuthentication.observe(
// settings.registerEntry(new RefreshListSettings());
// settings.registerEntry(new RemoveSoldAuctionsSettings());
// settings.registerEntry(new RelistAuctionsSettings());
// settings.registerEntry(new MinBinSettings());
settings.registerEntry(new MinBinSettings());
// settings.registerEntry(new CardInfoSettings());
// settings.registerEntry(new ListSizeSettings());

Expand Down
126 changes: 67 additions & 59 deletions app/transferlist/min-bin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* globals
gNavManager
window $ document
*/
import { BaseScript, SettingsEntry } from '../core';
Expand Down Expand Up @@ -52,97 +51,106 @@ class MinBin extends BaseScript {
mutationRecords.forEach(function (mutation) {
if ($(mutation.target).hasClass('DetailView') && $(mutation.target)
.find('.DetailPanel') && mutation.addedNodes.length > 0) {
if ($(mutation.target).find('#searchMinBin').length === 0) {
let selectedItem = this._getSelectedItem();
const searchMinBin = $(mutation.target).find('#searchMinBin');
searchMinBin.remove();

if (selectedItem == null || selectedItem.resourceId === 0) {
return;
let selectedItem = this._getSelectedItem();

if (selectedItem == null || selectedItem.resourceId === 0) {
return;
}
const knownPlayerPrice = this._playerPrices
.find(p => p.resourceId === selectedItem.resourceId);
let price = '';
if (knownPlayerPrice != null) {
price = `(${knownPlayerPrice.minimumBin})`;

this._updateListPrice(knownPlayerPrice.minimumBin);
}
$(mutation.target).find('.DetailPanel > .ut-button-group').prepend(`<button id="searchMinBin" data-resource-id="${selectedItem.resourceId}" class="list"><span class="btn-text">Search minimum BIN ${price}</span><span class="btn-subtext"></span></button>`);

$('#searchMinBin').bind('click', async () => {
const btn = $('#searchMinBin');
btn.find('.btn-text').html('Searching minimum BIN...');
const settings = this.getSettings();
const minimumBin = await new TransferMarket().searchMinBuy(selectedItem, parseInt(settings['mean-count'], 10));
const playerPrice = this._playerPrices.find(p => p.resourceId === btn.data('resource-id'));
if (playerPrice != null) {
this._playerPrices.splice(this._playerPrices.indexOf(playerPrice), 1);
}
const knownPlayerPrice = this._playerPrices
.find(p => p.resourceId === selectedItem.resourceId);
let price = '';
if (knownPlayerPrice != null) {
price = `(${knownPlayerPrice.minimumBin})`;
this._playerPrices.push({
resourceId: btn.data('resource-id'),
minimumBin,
});

this._updateListPrice(knownPlayerPrice.minimumBin);
selectedItem = this._getSelectedItem();

if (btn.data('resource-id') === selectedItem.resourceId) {
btn.find('.btn-text').html(`Search minimum BIN (${minimumBin})`);

this._updateListPrice(minimumBin);
}
$(mutation.target).find('.DetailPanel ul').prepend(`<button id="searchMinBin" data-resource-id="${selectedItem.resourceId}" class="list"><span class="btn-text">Search minimum BIN ${price}</span><span class="btn-subtext"></span></button>`);

$('#searchMinBin').bind('click', async () => {
const btn = $('#searchMinBin');
btn.find('.btn-text').html('Searching minimum BIN...');
const settings = this.getSettings();
const minimumBin = await new TransferMarket().searchMinBuy(selectedItem, parseInt(settings['mean-count'], 10));
const playerPrice = this._playerPrices.find(p => p.resourceId === btn.data('resource-id'));
if (playerPrice != null) {
this._playerPrices.splice(this._playerPrices.indexOf(playerPrice), 1);
}
this._playerPrices.push({
resourceId: btn.data('resource-id'),
minimumBin,
});

selectedItem = this._getSelectedItem();

if (btn.data('resource-id') === selectedItem.resourceId) {
btn.find('.btn-text').html(`Search minimum BIN (${minimumBin})`);

this._updateListPrice(minimumBin);
}

GM_notification({
text: `Minimum BIN found for ${selectedItem._staticData.name} is ${minimumBin}`,
title: 'FUT 18 Web App',
timeout: 5000,
onclick: () => window.focus(),
});

GM_notification({
text: `Minimum BIN found for ${selectedItem._staticData.name} is ${minimumBin}`,
title: 'FUT 19 Web App',
timeout: 5000,
onclick: () => window.focus(),
});
}
});
}
}, this);
}

_updateListPrice(minimumBin) {
const settings = this.getSettings();
if (settings['adjust-list-price'] &&
gNavManager.getCurrentScreenController()._controller._rightController
._currentController._quickListPanel) {
const quicklistpanelController = gNavManager.getCurrentScreenController()
._controller._rightController
._currentController._quickListPanel;
const quicklistpanel = quicklistpanelController._view;
const quicklistPanel = getAppMain().getRootViewController()
.getPresentedViewController()
.getCurrentViewController()
.getCurrentController()
._rightController._currentController._quickListPanel;

if (settings['adjust-list-price'] && quicklistPanel) {
const quicklistpanelView = quicklistPanel._view;

const listPrice = priceTiers.determineListPrice(
minimumBin * (settings['start-price-percentage'] / 100),
minimumBin * (settings['buy-now-price-percentage'] / 100),
);

if (quicklistpanelController._item) {
if (quicklistPanel._item) {
// sets the values when the quicklistpanel hasn't been initialized
const auction = quicklistpanelController._item._auction;
const auction = quicklistPanel._item._auction;
if (auction.tradeState !== 'active') {
auction.startingBid = listPrice.start;
auction.buyNowPrice = listPrice.buyNow;
quicklistpanelController._item.setAuctionData(auction);
quicklistPanel._item.setAuctionData(auction);
}
}

const bidSpinner = quicklistpanel._bidNumericStepper;
const buySpinner = quicklistpanel._buyNowNumericStepper;
const bidSpinner = quicklistpanelView._bidNumericStepper;
const buySpinner = quicklistpanelView._buyNowNumericStepper;
bidSpinner.value = listPrice.start;
buySpinner.value = listPrice.buyNow;
}
}

/* eslint-disable class-methods-use-this */
_getSelectedItem() {
if (gNavManager.getCurrentScreenController()._controller._listController) {
return gNavManager.getCurrentScreenController()._controller._listController
.getIterator().current();
const listController = getAppMain().getRootViewController()
.getPresentedViewController()
.getCurrentViewController()
.getCurrentController()._listController;
if (listController) {
return listController.getIterator().current();
}

if (gNavManager.getCurrentScreenController()._controller._rightController._currentController) {
const current = gNavManager.getCurrentScreenController()._controller._rightController
const detailController = getAppMain().getRootViewController()
.getPresentedViewController()
.getCurrentViewController()
.getCurrentController()._rightController;
if (detailController) {
const current = detailController
._currentController._viewmodel.current();

return current._item ? current._item : current;
Expand Down
8 changes: 4 additions & 4 deletions fut/pinEvent.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* globals gPinManager PinManager utils enums */
/* globals PIN_PAGEVIEW_EVT_TYPE services enums */

export class PinEvent {
static sendPageView(pageId, delay = 2000) {
return new Promise(resolve =>
setTimeout(() => {
gPinManager.trigger(utils.PinFactory.createEvent(enums.PIN.EVENT.PAGE_VIEW, {
type: PinManager.PAGEVIEW_EVT_TYPE,
services.PIN.sendData(enums.PIN.EVENT.PAGE_VIEW, {
type: PIN_PAGEVIEW_EVT_TYPE,
pgid: pageId,
}));
});
resolve();
}, delay));
}
Expand Down
8 changes: 4 additions & 4 deletions fut/priceTiers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global utils components */
/* global utils views */
export default {
roundValueToNearestPriceTiers(value) {
const tier = utils.JS.find(components.NumericInput.PRICE_TIERS, i => value > i.min);
const tier = utils.JS.find(views.controls.CurrencyInput.PRICE_TIERS, i => value > i.min);

const diff = value % tier.inc;

Expand All @@ -14,7 +14,7 @@ export default {
},

roundDownToNearestPriceTiers(value) {
const tier = utils.JS.find(components.NumericInput.PRICE_TIERS, i => value > i.min);
const tier = utils.JS.find(views.controls.CurrencyInput.PRICE_TIERS, i => value > i.min);

const diff = value % tier.inc;

Expand All @@ -25,7 +25,7 @@ export default {
},

determineListPrice(start, buyNow) {
const tier = utils.JS.find(components.NumericInput.PRICE_TIERS, i => buyNow > i.min);
const tier = utils.JS.find(views.controls.CurrencyInput.PRICE_TIERS, i => buyNow > i.min);

const startPrice = this.roundValueToNearestPriceTiers(start);
let buyNowPrice = this.roundValueToNearestPriceTiers(buyNow);
Expand Down
9 changes: 6 additions & 3 deletions fut/transferMarket.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ export class TransferMarket {
async _findLowUp(item, itemsForMean) {
const searchCriteria = this._defineSearchCriteria(item, 200);
await PinEvent.sendPageView('Transfer Market Search');
await utils.sleep(5000);
await utils.sleep(3000);
await PinEvent.sendPageView('Transfer Market Results - List View', 0);
await PinEvent.sendPageView('Item - Detail View', 0);
const items = await this._find(searchCriteria);
if (items.length > itemsForMean) {
// we find more than X listed at this price, so it must be low value
Expand All @@ -142,7 +143,9 @@ export class TransferMarket {
for (let minBuyFound = false; minBuyFound === false;) {
/* eslint-disable no-await-in-loop */
await PinEvent.sendPageView('Transfer Market Search');
await utils.sleep(800);
await PinEvent.sendPageView('Transfer Market Results - List View', 0);
await PinEvent.sendPageView('Item - Detail View', 0);
const items = await this._find(searchCriteria);
/* eslint-enable no-await-in-loop */
if (items.length > 0) {
Expand Down Expand Up @@ -195,9 +198,9 @@ export class TransferMarket {

// if it is TOTW or other special, set it to TOTW. See enums.ItemRareType.
// Can only search for "Specials", not more specific on Rare Type
if (item.rareflag >= enums.ItemRareType.TOTW) {
if (item.rareflag >= 3) { // 3 = TOTW
searchCriteria.level = factories.DataProvider.getItemLevelDP(true)
.filter(d => d.id === enums.ItemRareType.TOTW)[0].value;
.filter(d => d.id === 3)[0].value;
}

searchCriteria.category = enums.SearchCategory.ANY;
Expand Down

0 comments on commit 7bd921d

Please sign in to comment.