Jump to content
McKay Development

Checking card sets on incoming trade offer ?


SENPAY98K

Recommended Posts

If I remember correctly, you can specify language in Options ( https://github.com/DoctorMcKay/node-steam-tradeoffer-manager/wiki/TradeOfferManager#language )
In this case, you will receive all data like name and tags.

This can take up a lot of memory. (in my case, this required several gigabytes with a large number of trading offers / items in offers)

 If language disabled, you can check only classid. I don't know of any database that gives any additional information by classid.

Link to comment
Share on other sites

1 minute ago, PonyExpress said:

If I remember correctly, you can specify language in Options ( https://github.com/DoctorMcKay/node-steam-tradeoffer-manager/wiki/TradeOfferManager#language )
In this case, you will receive all data like name and tags.

This can take up a lot of memory. (in my case, this required several gigabytes with a large number of trading offers / items in offers)

 If language disabled, you can check only classid. I don't know of any database that gives any additional information by classid.

 

The language is not the problem here, 
I receive the offer, i check the offer details, then filter items for trading cards only,
after that i have a database of {appid, number of cards in set} which i need to compare against it
and retrun the amount of sets

Im lacking the idea of how to process it!

Link to comment
Share on other sites

In my case it works like this. Maybe this will help you.

// lodash
// cards = { "<appid>": ["<classid>": [ {<item>}, ... ], ... ], ... }
// cardData = {"220":{"amount":8,"name":"Half-Life 2"} ... }

function getSets(cards, callback) {
	let cardSets = {}
	let extraCards = []
	let unknownCards = []
	lodash.forOwn(cards, (cards, id) => {
		id = id.toString()
		if (cardData[id]) {
			let cardCount = lodash.mapValues(cards, array => array.length)
			cardCount = Object.keys(cardCount).map(number => cardCount[number])
			let min = Math.min(...cardCount)
			let max = Math.max(...cardCount)

			// There is at least one full set.
			if (Object.keys(cards).length == cardData[id].amount) {
				cardSets[id] = []
				for (let i = 0; i < min; i++) {
					let set = []
					lodash.forOwn(cards, item => {
						set.push(item[i])
					})
					cardSets[id].push(set)
				}

			// There are no full sets.
			} else {
				min = 0
			}

			// Extra cards:
			for (let i = min; i < max; i++) {
				lodash.forOwn(cards, item => {
					if (item[i]) {
						extraCards.push(item[i])
					}
				})
			}

		// Unknown cards:
		} else {
			lodash.forOwn(cards, item => {
				unknownCards.push(item)
			})
		}
	})
	callback(cardSets, extraCards, unknownCards)
}

 

Link to comment
Share on other sites

2 minutes ago, PonyExpress said:

In my case it works like this. Maybe this will help you.

// lodash
// cards = { "<appid>": ["<classid>": [ {<item>}, ... ], ... ], ... }
// cardData = {"220":{"amount":8,"name":"Half-Life 2"} ... }

function getSets(cards, callback) {
	let cardSets = {}
	let extraCards = []
	let unknownCards = []
	lodash.forOwn(cards, (cards, id) => {
		id = id.toString()
		if (cardData[id]) {
			let cardCount = lodash.mapValues(cards, array => array.length)
			cardCount = Object.keys(cardCount).map(number => cardCount[number])
			let min = Math.min(...cardCount)
			let max = Math.max(...cardCount)

			// There is at least one full set.
			if (Object.keys(cards).length == cardData[id].amount) {
				cardSets[id] = []
				for (let i = 0; i < min; i++) {
					let set = []
					lodash.forOwn(cards, item => {
						set.push(item[i])
					})
					cardSets[id].push(set)
				}

			// There are no full sets.
			} else {
				min = 0
			}

			// Extra cards:
			for (let i = min; i < max; i++) {
				lodash.forOwn(cards, item => {
					if (item[i]) {
						extraCards.push(item[i])
					}
				})
			}

		// Unknown cards:
		} else {
			lodash.forOwn(cards, item => {
				unknownCards.push(item)
			})
		}
	})
	callback(cardSets, extraCards, unknownCards)
}

 


I will try it, thank you :)

Link to comment
Share on other sites

@PonyExpress

Does not work i guess, returns empty object and arrays

 

const database = {
    "730": { "amount": 5},
    "603750": { "amount": 5},
	...
}

const cards = OFFER.itemsToGive;

await getSets(cards, (cardSets, extraCards, unknownCards) => {
if (cardSets) console.log(cardSets);
if (extraCards) console.log(extraCards);
if (unknownCards) console.log(unknownCards);
})

 

Edited by SENPAY98K
added code
Link to comment
Share on other sites

  • 3 weeks later...
  • 4 months later...

You have to pass the client's/bot's trade window to your getSets function that you use to sort your bot's/client's inventory when making an offer. And yes, you need to set your language to get the appid's of items in trade window otherwise you will end up with "0" sets. Also, you need to check if there are extra cards on the trade-offer as it will be not counted as a set.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...