e-champ-durak
Advanced tools
Comparing version 1.3.1 to 1.3.2
@@ -74,5 +74,8 @@ /** | ||
if (play.isAttackLimit()) { | ||
play.hands.forEach(hand => hand.turned = true); | ||
for (const hand of play.hands) { | ||
hand.turned = true; | ||
} | ||
} | ||
play.defender.turned = false; | ||
play.changedDefendingCards = false; | ||
play.addEvent('attack', [this.hand.pos, data]); | ||
@@ -79,0 +82,0 @@ play.endTurn(); |
@@ -22,2 +22,5 @@ /** | ||
} | ||
if (play.getActiveAttacker()) { | ||
return this.setError('Attack is not over yet'); | ||
} | ||
for (const item of items) { | ||
@@ -52,8 +55,12 @@ const [attacking, defending] = item; | ||
} | ||
this.play.updateEmptyHands(this.hand); | ||
this.play.updateFacedCards(); | ||
this.play.updateTurnedHands(); | ||
this.play.addEvent('defend', [this.hand.pos, data]); | ||
this.play.endTurn(); | ||
const play = this.play; | ||
play.changedDefendingCards = true; | ||
play.updateEmptyHands(this.hand); | ||
play.updateFacedCards(); | ||
if (!play.table.hasOpenAttack()) { | ||
play.updateTurnedHands(); | ||
} | ||
play.addEvent('defend', [this.hand.pos, data]); | ||
play.endTurn(); | ||
} | ||
}; |
@@ -15,4 +15,9 @@ /** | ||
const play = this.play; | ||
if (this.hand === play.defender && !play.table.hasOpenAttack()) { | ||
return this.setError('No attack to pass'); | ||
if (this.hand === play.defender) { | ||
if (play.getActiveAttacker()) { | ||
return this.setError('Attack is not over yet'); | ||
} | ||
if (!play.table.hasOpenAttack()) { | ||
return this.setError('No attack to pass'); | ||
} | ||
} | ||
@@ -28,4 +33,4 @@ if (this.hand === play.attacker && play.table.isEmpty()) { | ||
play.addEvent('pass', [this.hand.pos]); | ||
if (this.hand === play.defender && play.options.stopAttackOnPickingUp) { | ||
play.hands.forEach(hand => hand.turned = true); | ||
if (this.hand === play.defender && play.changedDefendingCards && !play.options.stopAttackOnPickingUp) { | ||
play.updateTurnedHands(); | ||
} | ||
@@ -32,0 +37,0 @@ this.hand.turned = true; |
@@ -24,2 +24,5 @@ /** | ||
} | ||
if (play.getActiveAttacker()) { | ||
return this.setError('Attack is not over yet'); | ||
} | ||
const cards = play.deck.parseCards(this.data.cards); | ||
@@ -26,0 +29,0 @@ if (!cards || !cards.length) { |
{ | ||
"name": "e-champ-durak", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "Online card game Durak for the E-Champ platform", | ||
@@ -5,0 +5,0 @@ "author": "Maxim Khorin", |
@@ -80,2 +80,3 @@ /** | ||
this.picked = false; | ||
this.changedDefendingCards = false; | ||
this.updateTurnedHands(); | ||
@@ -372,12 +373,11 @@ this.addEvent('turn', { | ||
} | ||
if (!this.isAttackLimit()) { | ||
const attacker = this.getActiveAttacker(); | ||
if (attacker) { | ||
return attacker?.isBot() ? this.startBot(attacker) : null; | ||
} | ||
} | ||
if (!this.defender.turned && this.defender.isBot() && this.table.hasOpenAttack()) { | ||
this.startBot(this.defender); | ||
} | ||
if (this.isAttackLimit()) { | ||
return; | ||
} | ||
const attacker = this.getActiveAttacker(); | ||
if (attacker?.isBot()) { | ||
this.startBot(attacker); | ||
} | ||
} | ||
@@ -384,0 +384,0 @@ |
@@ -21,2 +21,5 @@ /** | ||
arrangeCard (card) { | ||
if (!this.isMaster()) { | ||
this.closeCard(card); | ||
} | ||
const index = this.table.getAttackingIndex(card); | ||
@@ -28,7 +31,3 @@ this.table.getDefendingCard(index - 1)?.after(card); | ||
cards.forEach(this.processCard, this); | ||
this.play.motion.done(() => { | ||
this.player.arrange(); | ||
this.play.table.arrange(); | ||
this.finish(); | ||
}); | ||
this.play.motion.done(this.onMotionDone.bind(this)); | ||
} | ||
@@ -41,4 +40,10 @@ | ||
onMotionDone () { | ||
this.player.arrange(); | ||
this.play.table.arrange(); | ||
this.finishAfterMotion(); | ||
} | ||
processHidden () { | ||
this.execute().forEach(this.openCard, this); | ||
this.execute(); | ||
this.finish(); | ||
@@ -54,2 +59,3 @@ } | ||
card = attacker.cards.last(); | ||
card.open(rank, suit); | ||
} | ||
@@ -56,0 +62,0 @@ if (card) { |
@@ -21,7 +21,3 @@ /** | ||
pairs.forEach(this.processPair, this); | ||
this.play.motion.done(() => { | ||
this.player.arrange(); | ||
this.play.table.arrange(); | ||
this.finish(); | ||
}); | ||
this.play.motion.done(this.onMotionDone.bind(this)); | ||
} | ||
@@ -35,2 +31,8 @@ | ||
onMotionDone () { | ||
this.player.arrange(); | ||
this.play.table.arrange(); | ||
this.finishAfterMotion(); | ||
} | ||
processHidden () { | ||
@@ -56,5 +58,6 @@ this.execute().forEach(({defending}, index) => this.openCard(defending, index)); | ||
} | ||
this.play.updateTurnedPlayers(); | ||
if (!this.table.hasOpenAttack()) { | ||
this.play.updateTurnedPlayers(); | ||
} | ||
this.play.updatePlayerMessages(); | ||
this.play.master.update(); | ||
this.play.resolveWinner(defender); | ||
@@ -61,0 +64,0 @@ return cards; |
@@ -10,2 +10,4 @@ /** | ||
super(...arguments); | ||
this.from = this.play.defender; | ||
this.target = this.player; | ||
this.items = this.data[1]; | ||
@@ -16,3 +18,3 @@ } | ||
this.table.arrange(this.items.length); | ||
this.execute().forEach(this.processCard, this); | ||
this.executeCards().forEach(this.processCard, this); | ||
this.play.motion.done(this.processTurn.bind(this)); | ||
@@ -22,2 +24,5 @@ } | ||
processCard (card, index) { | ||
if (this.from !== this.play.master) { | ||
this.closeCard(card); | ||
} | ||
const offset = this.table.getAttackingOffset(card); | ||
@@ -28,3 +33,4 @@ this.play.moveCard(card, offset).done(() => this.openCard(card, index)); | ||
processTurn () { | ||
this.play.attacker.arrange(); | ||
this.from.arrange(); | ||
this.executeTurn(); | ||
this.play.showTurn(); | ||
@@ -35,16 +41,17 @@ this.finishAfterMotion(this.constructor.PROCESS_DELAY); | ||
processHidden () { | ||
this.execute().forEach(this.openCard, this); | ||
this.executeCards(); | ||
this.executeTurn(); | ||
this.finish(); | ||
} | ||
execute () { | ||
const defender = this.play.defender; | ||
executeCards () { | ||
const cards = []; | ||
for (const {rank, suit} of this.items) { | ||
let card = defender.cards.find(rank, suit); | ||
if (!card && this.play.defender !== this.play.master) { | ||
card = defender.cards.last(); | ||
let card = this.from.cards.find(rank, suit); | ||
if (!card && this.from !== this.play.master) { | ||
card = this.from.cards.last(); | ||
card.open(rank, suit); | ||
} | ||
if (card) { | ||
defender.removeCard(card); | ||
this.from.removeCard(card); | ||
this.table.addAttack(card); | ||
@@ -54,9 +61,16 @@ cards.push(card); | ||
} | ||
this.play.setAttacker(defender); | ||
this.play.setDefender(this.player); | ||
this.play.updateTurnedPlayers(); | ||
this.play.updatePlayerMessages(); | ||
this.play.resolveWinner(defender); | ||
return cards; | ||
} | ||
executeTurn () { | ||
const play = this.play; | ||
play.setAttacker(this.from); | ||
play.setDefender(this.target); | ||
play.isAttackLimit() | ||
? play.players.forEach(player => player.setTurned(true)) | ||
: play.updateTurnedPlayers(); | ||
play.defender.setTurned(false); | ||
play.updatePlayerMessages(); | ||
play.resolveWinner(this.from); | ||
} | ||
}; |
@@ -37,3 +37,3 @@ /** | ||
if (this.isDefender()) { | ||
return table.hasOpenAttack(); | ||
return table.hasOpenAttack() && !this.play.getActiveAttacker(); | ||
} | ||
@@ -130,4 +130,4 @@ if (table.isEmpty()) { | ||
const cards = [this.selection.getData()]; | ||
this.addPredictedEvent(Club.DurakEvent.ATTACK, [this.pos, cards]); | ||
this.send(Club.Durak.ACTION_ATTACK, {cards}); | ||
this.addPredictedEvent(Club.DurakEvent.ATTACK, [this.pos, cards]); | ||
return true; | ||
@@ -140,4 +140,4 @@ } | ||
const pairs = [[target.getData(), this.selection.getData()]]; | ||
this.addPredictedEvent(Club.DurakEvent.DEFEND, [this.pos, pairs]); | ||
this.send(Club.Durak.ACTION_DEFEND, {pairs}); | ||
this.addPredictedEvent(Club.DurakEvent.DEFEND, [this.pos, pairs]); | ||
return true; | ||
@@ -149,5 +149,5 @@ } | ||
const cards = [this.selection.getData()]; | ||
this.send(Club.Durak.ACTION_TRANSFER, {cards}); | ||
const target = this.play.getTransferTarget(); | ||
this.addPredictedEvent(Club.DurakEvent.TRANSFER, [target.pos, cards]); | ||
this.send(Club.Durak.ACTION_TRANSFER, {cards}); | ||
return true; | ||
@@ -203,5 +203,5 @@ } | ||
send () { | ||
this.play.send(...arguments); | ||
this.selection = null; | ||
this.deactivate(); | ||
this.play.send(...arguments); | ||
} | ||
@@ -208,0 +208,0 @@ |
@@ -58,4 +58,7 @@ /** | ||
} | ||
return this.turned | ||
? Club.Durak.MESSAGE_PICK_UP | ||
if (this.turned) { | ||
return Club.Durak.MESSAGE_PICK_UP; | ||
} | ||
return this.play.getActiveAttacker() | ||
? Club.Durak.MESSAGE_WAIT | ||
: Club.Durak.MESSAGE_THINK; | ||
@@ -62,0 +65,0 @@ } |
@@ -479,4 +479,7 @@ /* @copyright Copyright (c) 2021 Maxim Khorin <maksimovichu@gmail.com> */ | ||
} | ||
return this.turned | ||
? Club.Durak.MESSAGE_PICK_UP | ||
if (this.turned) { | ||
return Club.Durak.MESSAGE_PICK_UP; | ||
} | ||
return this.play.getActiveAttacker() | ||
? Club.Durak.MESSAGE_WAIT | ||
: Club.Durak.MESSAGE_THINK; | ||
@@ -618,2 +621,5 @@ } | ||
arrangeCard (card) { | ||
if (!this.isMaster()) { | ||
this.closeCard(card); | ||
} | ||
const index = this.table.getAttackingIndex(card); | ||
@@ -625,7 +631,3 @@ this.table.getDefendingCard(index - 1)?.after(card); | ||
cards.forEach(this.processCard, this); | ||
this.play.motion.done(() => { | ||
this.player.arrange(); | ||
this.play.table.arrange(); | ||
this.finish(); | ||
}); | ||
this.play.motion.done(this.onMotionDone.bind(this)); | ||
} | ||
@@ -638,4 +640,10 @@ | ||
onMotionDone () { | ||
this.player.arrange(); | ||
this.play.table.arrange(); | ||
this.finishAfterMotion(); | ||
} | ||
processHidden () { | ||
this.execute().forEach(this.openCard, this); | ||
this.execute(); | ||
this.finish(); | ||
@@ -651,2 +659,3 @@ } | ||
card = attacker.cards.last(); | ||
card.open(rank, suit); | ||
} | ||
@@ -768,7 +777,3 @@ if (card) { | ||
pairs.forEach(this.processPair, this); | ||
this.play.motion.done(() => { | ||
this.player.arrange(); | ||
this.play.table.arrange(); | ||
this.finish(); | ||
}); | ||
this.play.motion.done(this.onMotionDone.bind(this)); | ||
} | ||
@@ -782,2 +787,8 @@ | ||
onMotionDone () { | ||
this.player.arrange(); | ||
this.play.table.arrange(); | ||
this.finishAfterMotion(); | ||
} | ||
processHidden () { | ||
@@ -803,5 +814,6 @@ this.execute().forEach(({defending}, index) => this.openCard(defending, index)); | ||
} | ||
this.play.updateTurnedPlayers(); | ||
if (!this.table.hasOpenAttack()) { | ||
this.play.updateTurnedPlayers(); | ||
} | ||
this.play.updatePlayerMessages(); | ||
this.play.master.update(); | ||
this.play.resolveWinner(defender); | ||
@@ -972,2 +984,4 @@ return cards; | ||
super(...arguments); | ||
this.from = this.play.defender; | ||
this.target = this.player; | ||
this.items = this.data[1]; | ||
@@ -978,3 +992,3 @@ } | ||
this.table.arrange(this.items.length); | ||
this.execute().forEach(this.processCard, this); | ||
this.executeCards().forEach(this.processCard, this); | ||
this.play.motion.done(this.processTurn.bind(this)); | ||
@@ -984,2 +998,5 @@ } | ||
processCard (card, index) { | ||
if (this.from !== this.play.master) { | ||
this.closeCard(card); | ||
} | ||
const offset = this.table.getAttackingOffset(card); | ||
@@ -990,3 +1007,4 @@ this.play.moveCard(card, offset).done(() => this.openCard(card, index)); | ||
processTurn () { | ||
this.play.attacker.arrange(); | ||
this.from.arrange(); | ||
this.executeTurn(); | ||
this.play.showTurn(); | ||
@@ -997,16 +1015,17 @@ this.finishAfterMotion(this.constructor.PROCESS_DELAY); | ||
processHidden () { | ||
this.execute().forEach(this.openCard, this); | ||
this.executeCards(); | ||
this.executeTurn(); | ||
this.finish(); | ||
} | ||
execute () { | ||
const defender = this.play.defender; | ||
executeCards () { | ||
const cards = []; | ||
for (const {rank, suit} of this.items) { | ||
let card = defender.cards.find(rank, suit); | ||
if (!card && this.play.defender !== this.play.master) { | ||
card = defender.cards.last(); | ||
let card = this.from.cards.find(rank, suit); | ||
if (!card && this.from !== this.play.master) { | ||
card = this.from.cards.last(); | ||
card.open(rank, suit); | ||
} | ||
if (card) { | ||
defender.removeCard(card); | ||
this.from.removeCard(card); | ||
this.table.addAttack(card); | ||
@@ -1016,9 +1035,16 @@ cards.push(card); | ||
} | ||
this.play.setAttacker(defender); | ||
this.play.setDefender(this.player); | ||
this.play.updateTurnedPlayers(); | ||
this.play.updatePlayerMessages(); | ||
this.play.resolveWinner(defender); | ||
return cards; | ||
} | ||
executeTurn () { | ||
const play = this.play; | ||
play.setAttacker(this.from); | ||
play.setDefender(this.target); | ||
play.isAttackLimit() | ||
? play.players.forEach(player => player.setTurned(true)) | ||
: play.updateTurnedPlayers(); | ||
play.defender.setTurned(false); | ||
play.updatePlayerMessages(); | ||
play.resolveWinner(this.from); | ||
} | ||
}; | ||
@@ -1152,3 +1178,3 @@ Club.DurakTurnEvent = class DurakTurnEvent extends Club.DurakEvent { | ||
if (this.isDefender()) { | ||
return table.hasOpenAttack(); | ||
return table.hasOpenAttack() && !this.play.getActiveAttacker(); | ||
} | ||
@@ -1245,4 +1271,4 @@ if (table.isEmpty()) { | ||
const cards = [this.selection.getData()]; | ||
this.addPredictedEvent(Club.DurakEvent.ATTACK, [this.pos, cards]); | ||
this.send(Club.Durak.ACTION_ATTACK, {cards}); | ||
this.addPredictedEvent(Club.DurakEvent.ATTACK, [this.pos, cards]); | ||
return true; | ||
@@ -1255,4 +1281,4 @@ } | ||
const pairs = [[target.getData(), this.selection.getData()]]; | ||
this.addPredictedEvent(Club.DurakEvent.DEFEND, [this.pos, pairs]); | ||
this.send(Club.Durak.ACTION_DEFEND, {pairs}); | ||
this.addPredictedEvent(Club.DurakEvent.DEFEND, [this.pos, pairs]); | ||
return true; | ||
@@ -1264,5 +1290,5 @@ } | ||
const cards = [this.selection.getData()]; | ||
this.send(Club.Durak.ACTION_TRANSFER, {cards}); | ||
const target = this.play.getTransferTarget(); | ||
this.addPredictedEvent(Club.DurakEvent.TRANSFER, [target.pos, cards]); | ||
this.send(Club.Durak.ACTION_TRANSFER, {cards}); | ||
return true; | ||
@@ -1318,5 +1344,5 @@ } | ||
send () { | ||
this.play.send(...arguments); | ||
this.selection = null; | ||
this.deactivate(); | ||
this.play.send(...arguments); | ||
} | ||
@@ -1323,0 +1349,0 @@ |
Sorry, the diff of this file is not supported yet
275476
4882