Skip to content
This repository has been archived by the owner on Aug 4, 2018. It is now read-only.

Cherry-pick a4301a3 to get SOI support #148

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ let App = {
ws.on('message', message)
},
send(...args) {
console.log('Sending', args)
let msg = JSON.stringify(args)
this.ws.send(msg)
},
Expand Down
63 changes: 52 additions & 11 deletions public/src/cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,37 @@ for (let name in Cards)
let rawPack, clicked
export let Zones = {
pack: {},
pile: {},
main: {},
side: {},
junk: {}
}

function moveCardsToZone(cards, zoneName, dropTo) {
rawPack = cards
if (dropTo !== undefined) {
Zones[zoneName] = dropTo
}
let theZone = Zones[zoneName]
for (let card of cards) {
let {name} = card
Cards[name] = card
theZone[name] || (theZone[name] = 0)
theZone[name]++
}
App.update()
if (App.state.beep)
document.getElementById('beep').play()
}

function replaceCardsInZone(cards, zoneName) {
moveCardsToZone(cards, zoneName, {})
}

function addCardsToZone(cards, zoneName) {
moveCardsToZone(cards, zoneName)
}

function hash() {
let {main, side} = Zones
App.send('hash', { main, side })
Expand Down Expand Up @@ -70,6 +96,25 @@ let events = {

App.update()
},
takePile(zoneName, cards, e) {
let src = Zones[zoneName]
let dst = Zones [e.shiftKey
? zoneName === 'junk' ? 'main' : 'junk'
: zoneName === 'side' ? 'main' : 'side']
cards.forEach((card) => {
dst[card.name] || (dst[card.name] = 0)
src[card.name]--
dst[card.name]++
if (!src[card.name])
delete src[card.name]
})
App.send('takePile', {})
App.update()
},
passPile(zoneName, cards, e) {
App.send('passPile', {})
App.update()
},
copy(ref) {
let node = ref.getDOMNode()
node.value = filetypes.txt()
Expand All @@ -88,17 +133,13 @@ let events = {
App.send('start', options)
},
pack(cards) {
rawPack = cards
let pack = Zones.pack = {}

for (let card of cards) {
let {name} = card
Cards[name] = card
pack[name] = 1
}
App.update()
if (App.state.beep)
document.getElementById('beep').play()
replaceCardsInZone(cards, 'pack')
},
pile(cards) {
replaceCardsInZone(cards, 'pile')
},
winstonCard(card) {
addCardsToZone([card], 'junk')
},
create() {
let {type, seats} = App.state
Expand Down
4 changes: 3 additions & 1 deletion public/src/components/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ export default React.createClass({
Cards() {
if (Object.keys(Zones.pack).length)
let pack = Grid({ zones: ['pack'] })
else
let pile = Grid({ zones: ['pile'] })
let component = App.state.cols ? Cols : Grid
let pool = component({ zones: ['main', 'side', 'junk'] })
return [pack, pool]
return [pack, pile, pool]
},
Start() {
if (App.state.round || !App.state.isHost)
Expand Down
25 changes: 23 additions & 2 deletions public/src/components/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,36 @@ function zone(zoneName) {
let zone = getZone(zoneName)
let values = _.values(zone)
let cards = _.flat(values)
let perPileEmission = zoneName === 'pile'

let emitMaybe = (card) => {
if (! perPileEmission)
return App._emit('click', zoneName, card.name)
return () => {}
}

let pileControlsMaybe = () => {
if (perPileEmission) {
return d.div({},
d.button({
onClick: App._emit('passPile', zoneName, cards)
}, 'pass pile'),
d.button({
onClick: App._emit('takePile', zoneName, cards)
}, 'take pile')
)
}
return d.span({})
}

let items = cards.map(card =>
d.img({
onClick: App._emit('click', zoneName, card.name),
onClick: emitMaybe(card),
src: card.url,
alt: card.name
}))

return d.div({ className: 'zone' },
d.h1({}, `${zoneName} ${cards.length}`),
items)
[pileControlsMaybe(), items])
}
3 changes: 2 additions & 1 deletion public/src/components/lobby.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function content() {
case 'sealed': return [setsTop, setsBot]
case 'cube draft' : return [cube, cubeDraft]
case 'cube sealed': return cube
case 'cube winston': return [cube, cubeDraft]
case 'editor': return d.a({ href: 'http://editor.draft.wtf' }, 'editor')
}
}
Expand All @@ -74,7 +75,7 @@ function Create() {
let seats = _.seq(8, 2).map(x =>
d.option({}, x))

let types = ['draft', 'sealed', 'cube draft', 'cube sealed', 'editor']
let types = ['draft', 'sealed', 'cube draft', 'cube sealed', 'cube winston', 'editor']
.map(type =>
d.button({
disabled: type === App.state.type,
Expand Down
1 change: 1 addition & 0 deletions public/src/data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export default {
expansion: {
"Shadows Over Innistrad": "SOI",
"Oath of the Gatewatch": "OGW",
"Battle for Zendikar": "BFZ",
"Dragons of Tarkir": "DTK",
Expand Down
2 changes: 1 addition & 1 deletion src/_.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
},
at(arr, index) {
var {length} = arr
index = (index % length + length) % length//please kill me it hurts to live
index = (index % length + length) % length
return arr[index]
},
count(arr, attr) {
Expand Down
62 changes: 60 additions & 2 deletions src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = class Game extends Room {
title: sets.join(' / ')})
else {
var title = type
if (type === 'cube draft')
if (type === 'cube draft' || type === 'cube winston')
title += ' ' + cube.packs + 'x' + cube.cards
Object.assign(this, { cube, title })
}
Expand All @@ -52,7 +52,8 @@ module.exports = class Game extends Room {
id: gameID,
players: [],
round: 0,
rounds: cube ? cube.packs : 3
rounds: cube ? cube.packs : 3,
winston: (type === 'cube winston')
})
this.renew()
games[gameID] = this
Expand Down Expand Up @@ -173,6 +174,34 @@ module.exports = class Game extends Room {
this.meta()
}

bumpAp() {
return (this.ap + 1) % this.players.length
}

takePile(p) {
if (p.id !== this.players[this.ap].id)
return

this.piles[this.pile].forEach((x) => { this.players[this.ap].pool.push(x) })
this.piles[this.pile] = [this.pool.pop()]
this.players[this.ap].sendPile([])

this.ap = this.bumpAp()
this.pile = 0

this.startWinstonPileSelection()
}

passPile(p) {
if (p.id !== this.players[this.ap].id)
return

this.piles[this.pile].push(this.pool.pop())
this.pile++

this.startWinstonPileSelection()
}

startRound() {
if (this.round++ === this.rounds)
return this.end()
Expand All @@ -199,6 +228,21 @@ module.exports = class Game extends Room {
this.meta({ round: this.round })
}

startWinstonPileSelection() {
if ( this.pile >= this.piles.length ) {
let topCard = this.pool.pop()
this.players[this.ap].pool.push(topCard)
this.players[this.ap].sendCard(topCard)
this.players[this.ap].sendPile([])
this.ap = this.bumpAp()
this.pile = 0
this.startWinstonPileSelection()
}
else {
this.players[this.ap].sendPile(this.piles[this.pile])
}
}

hash(h, deck) {
h.hash = hash(deck)
this.meta()
Expand All @@ -222,6 +266,20 @@ module.exports = class Game extends Room {
return
}

if (/winston/.test(this.type)) {
this.pile = 0
this.ap = 0
var [pool] = Pool(src, 1, true)
this.pool = pool
this.piles = [[this.pool.pop()], [this.pool.pop()], [this.pool.pop()]]
players.forEach((p, i) => {
p.on('takePile', this.takePile.bind(this, p))
p.on('passPile', this.passPile.bind(this, p))
p.send('set', { self: i })
})
return this.startWinstonPileSelection()
}

for (p of players)
p.useTimer = useTimer

Expand Down
12 changes: 12 additions & 0 deletions src/human.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = class extends EventEmitter {
name: sock.name,
time: 0,
packs: [],
pile: [],
pool: []
})
this.attach(sock)
Expand All @@ -21,6 +22,8 @@ module.exports = class extends EventEmitter {
sock.mixin(this)
sock.on('pick', this._pick.bind(this))
sock.on('hash', this._hash.bind(this))
sock.on('takePile', (() => this.emit('takePile')).bind(this))
sock.on('passPile', (() => this.emit('passPile')).bind(this))

var [pack] = this.packs
if (pack)
Expand Down Expand Up @@ -52,6 +55,15 @@ module.exports = class extends EventEmitter {

this.send('pack', pack)
}
sendCard(card) {
this.send('winstonCard', card)
}
sendPile(pile) {
if (this.useTimer)
this.time = 20 + 5 * pile.length

this.send('pile', pile)
}
pick(index) {
var pack = this.packs.shift()
var card = pack.splice(index, 1)[0]
Expand Down
50 changes: 50 additions & 0 deletions src/make/cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ function before() {
|| /draft/.test(card.text))
card.rarity = 'special'

for (card of raw.SOI.cards) {
if (card.layout === 'double-faced') {
card.rarity = 'special'
}
}

for (card of raw.FRF.cards)
if (card.types[0] === 'Land'
&& (card.name !== 'Crucible of the Spirit Dragon'))
Expand Down Expand Up @@ -130,6 +136,50 @@ function after() {
'scorned villager'
]
}
var {SOI} = Sets
SOI.special = {
mythic: [
'archangel avacyn',
'startled awake',
'arlinn kord'
],
rare: [
'hanweir militia captain',
'thing in the ice',
'elusive tormentor',
'geier reach bandit',
'sage of ancient lore'
],
uncommon: [
'avacynian missionaries',
'pious evangel',
'town gossipmonger',
'aberrant researcher',
'daring sleuth',
'uninvited geist',
'accursed witch',
'heir of falkenrath',
'kindly stranger',
'breakneck rider',
'kessig forgemaster',
'skin invasion',
'village messenger',
'autumnal gloom',
'cult of the waxing moon',
'duskwatch recruiter',
'hermit of the natterknolls',
'lambholt pacifist',
'harvest hand',
'neglected heirloom',
'thraben gargoyle'
],
common: [
'convicted killer',
'gatstaf arsonists',
'hinterland logger',
'solitary hunter'
]
}
var {DGM} = Sets
DGM.mythic.splice(DGM.mythic.indexOf("maze's end"), 1)
DGM.special = {
Expand Down
Loading