diff --git a/public/src/cards.js b/public/src/cards.js index f92c01a..300fe1a 100644 --- a/public/src/cards.js +++ b/public/src/cards.js @@ -218,10 +218,20 @@ function cube() { } function clickPack(cardName) { - if (clicked !== cardName) - return clicked = cardName - let index = rawPack.findIndex(x => x.name === cardName) + let card = rawPack[index] + + if (clicked !== cardName) { + clicked = cardName + // There may be duplicate cards in a pack, but only one copy of a card is + // shown in the pick view. We must be sure to mark them all since we don't + // know which one is being displayed. + rawPack.forEach(card => card.isAutopick = card.name === cardName) + App.update() + App.send('autopick', index) + return clicked + } + clicked = null Zones.pack = {} App.update() diff --git a/public/src/components/grid.js b/public/src/components/grid.js index 4a47ceb..c4e4d6d 100644 --- a/public/src/components/grid.js +++ b/public/src/components/grid.js @@ -15,12 +15,19 @@ function zone(zoneName) { let values = _.values(zone) let cards = _.flat(values) + let isAutopickable = card => zoneName === 'pack' && card.isAutopick + let items = cards.map(card => - d.img({ - onClick: App._emit('click', zoneName, card.name), - src: card.url, - alt: card.name - })) + d.span( + { + className: `card ${isAutopickable(card) ? 'autopick-card' : ''}`, + title: isAutopickable(card) ? 'This card will be automatically picked if your time expires.' : '', + onClick: App._emit('click', zoneName, card.name), + }, + d.img({ + src: card.url, + alt: card.name, + }))) return d.div({ className: 'zone' }, d.h1({}, `${zoneName} ${cards.length}`), diff --git a/public/style.css b/public/style.css index 2eb5c41..baecae6 100644 --- a/public/style.css +++ b/public/style.css @@ -39,6 +39,50 @@ time { color: white; } +.card { + display: inline-block; + position: relative; + margin: 0; + cursor: pointer; +} + +.card:hover:before, .autopick-card:before { + content: ''; + + display: block; + position: absolute; + + top: 0; + bottom: 0; + left: 0; + right: 0; + + margin-bottom: 5px; + border-radius: 12px; + + background: rgba(200, 200, 200, 0.25); +} + +.autopick-card:after { + content: 'Autopick'; + + display: inline-block; + position: absolute; + + /* Center in the middle of the bottom border on the card. */ + line-height: 25px; + bottom: 5px; + left: 0; + right: 0; + + color: #fff; + font-family: Verdana, Arial, sans-serif; + font-size: 13px; + font-weight: 700; + text-align: center; + text-shadow: 0px 0px 2px #000; +} + .error { color: red; } diff --git a/src/game.js b/src/game.js index ef002cb..f6ff306 100644 --- a/src/game.js +++ b/src/game.js @@ -17,7 +17,7 @@ var games = {} continue for (var p of game.players) if (p.time && !--p.time) - p.pickRand() + p.pickOnTimeout() } setTimeout(playerTimer, SECOND) })() diff --git a/src/human.js b/src/human.js index 510d1f6..24c85dd 100644 --- a/src/human.js +++ b/src/human.js @@ -10,6 +10,7 @@ module.exports = class extends EventEmitter { name: sock.name, time: 0, packs: [], + autopick_index: -1, pool: [] }) this.attach(sock) @@ -19,6 +20,7 @@ module.exports = class extends EventEmitter { this.sock.ws.close() sock.mixin(this) + sock.on('autopick', this._autopick.bind(this)) sock.on('pick', this._pick.bind(this)) sock.on('hash', this._hash.bind(this)) @@ -34,6 +36,11 @@ module.exports = class extends EventEmitter { this.hash = hash(deck) this.emit('meta') } + _autopick(index) { + var [pack] = this.packs + if (pack && index < pack.length) + this.autopick_index = index + } _pick(index) { var [pack] = this.packs if (pack && index < pack.length) @@ -65,17 +72,20 @@ module.exports = class extends EventEmitter { else this.sendPack(next) + this.autopick_index = -1 this.emit('pass', pack) } - pickRand() { - var index = _.rand(this.packs[0].length) + pickOnTimeout() { + let index = this.autopick_index + if (index === -1) + index = _.rand(this.packs[0].length) this.pick(index) } kick() { this.send = ()=>{} while(this.packs.length) - this.pickRand() - this.sendPack = this.pickRand + this.pickOnTimeout() + this.sendPack = this.pickOnTimeout this.isBot = true } } diff --git a/src/make/cards.js b/src/make/cards.js index 0a9d2ff..b7d9fd3 100644 --- a/src/make/cards.js +++ b/src/make/cards.js @@ -76,6 +76,60 @@ function before() { } function after() { + var {ISD} = Sets + ISD.special = { + mythic: [ + 'garruk relentless' + ], + rare: [ + 'bloodline keeper', + 'daybreak ranger', + 'instigator gang', + 'kruin outlaw', + 'ludevic\'s test subject', + 'mayor of avabruck' + ], + uncommon: [ + 'civilized scholar', + 'cloistered youth', + 'gatstaf shepherd', + 'hanweir watchkeep', + 'reckless waif', + 'screeching bat', + 'ulvenwald mystics' + ], + common: [ + 'delver of secrets', + 'grizzled outcasts', + 'thraben sentry', + 'tormented pariah', + 'village ironsmith', + 'villagers of estwald' + ] + } + var {DKA} = Sets + DKA.special = { + mythic: [ + 'elbrus, the binding blade', + 'huntmaster of the fells' + ], + rare: [ + 'mondronen shaman', + 'ravenous demon' + ], + uncommon: [ + 'afflicted deserter', + 'chalice of life', + 'lambholt elder', + 'soul seizer' + ], + common: [ + 'chosen of markov', + 'hinterland hermit', + 'loyal cathar', + 'scorned villager' + ] + } var {DGM} = Sets DGM.mythic.splice(DGM.mythic.indexOf("maze's end"), 1) DGM.special = { @@ -167,7 +221,7 @@ function doCard(rawCard, cards, code, set) { var {name} = rawCard if (['double-faced', 'flip'].indexOf(rawCard.layout) > -1 - && name !== rawCard.names[0]) + && rawCard.number.indexOf('b') > -1) return if (rawCard.layout === 'split') diff --git a/src/pool.js b/src/pool.js index 991d2c8..34b8768 100644 --- a/src/pool.js +++ b/src/pool.js @@ -32,6 +32,8 @@ function toPack(code) { _.choose(1, rare) ) + let specialrnd + switch (code) { case 'DGM': special = _.rand(20) @@ -53,7 +55,33 @@ function toPack(code) { special = _.rand(20) ? special.common : special.fetch - break + break + case 'ISD': + //http://www.mtgsalvation.com/forums/magic-fundamentals/magic-general/327956-innistrad-block-transforming-card-pack-odds?comment=4 + //121 card sheet, 1 mythic, 12 rare (13), 42 uncommon (55), 66 common + specialrnd = _.rand(121) + if (specialrnd == 0) + special = special.mythic + else if (specialrnd < 13) + special = special.rare + else if (specialrnd < 55) + special = special.uncommon + else + special = special.common + break + case 'DKA': + //http://www.mtgsalvation.com/forums/magic-fundamentals/magic-general/327956-innistrad-block-transforming-card-pack-odds?comment=4 + //80 card sheet, 2 mythic, 6 rare (8), 24 uncommon (32), 48 common + specialrnd = _.rand(80) + if (specialrnd <= 1) + special = special.mythic + else if (specialrnd < 8) + special = special.rare + else if (specialrnd < 32) + special = special.uncommon + else + special = special.common + break } if (special)