negotiate draw through WS - closes #2817
parent
7d26938bac
commit
02241811db
|
@ -246,6 +246,12 @@ object Event {
|
|||
def data = reloadOr("rematchTaken", nextId)
|
||||
}
|
||||
|
||||
case class DrawOffer(by: Option[Color]) extends Event {
|
||||
def typ = "reload"
|
||||
def data = reloadOr("drawOffer", by)
|
||||
override def owner = true
|
||||
}
|
||||
|
||||
case class Premove(color: Color) extends Empty {
|
||||
def typ = "premove"
|
||||
override def only = Some(color)
|
||||
|
|
|
@ -27,23 +27,23 @@ private[round] final class Drawer(
|
|||
finisher.other(pov.game, _.Draw)
|
||||
case pov if pov.opponent.isOfferingDraw =>
|
||||
finisher.other(pov.game, _.Draw, None, Some(_.drawOfferAccepted))
|
||||
case Pov(g, color) if (g playerCanOfferDraw color) => proxy.save {
|
||||
case Pov(g, color) if g playerCanOfferDraw color => proxy.save {
|
||||
messenger.system(g, color.fold(_.whiteOffersDraw, _.blackOffersDraw))
|
||||
Progress(g) map { g => g.updatePlayer(color, _ offerDraw g.turns) }
|
||||
} inject List(Event.ReloadOwner)
|
||||
case _ => fuccess(Nil)
|
||||
} inject List(Event.DrawOffer(by = color.some)).pp
|
||||
case _ => fuccess(List(Event.ReloadOwner))
|
||||
}
|
||||
|
||||
def no(pov: Pov)(implicit proxy: GameProxy): Fu[Events] = pov match {
|
||||
case Pov(g, color) if pov.player.isOfferingDraw => proxy.save {
|
||||
messenger.system(g, _.drawOfferCanceled)
|
||||
Progress(g) map { g => g.updatePlayer(color, _.removeDrawOffer) }
|
||||
} inject List(Event.ReloadOwner)
|
||||
} inject List(Event.DrawOffer(by = none))
|
||||
case Pov(g, color) if pov.opponent.isOfferingDraw => proxy.save {
|
||||
messenger.system(g, color.fold(_.whiteDeclinesDraw, _.blackDeclinesDraw))
|
||||
Progress(g) map { g => g.updatePlayer(!color, _.removeDrawOffer) }
|
||||
} inject List(Event.ReloadOwner)
|
||||
case _ => fuccess(Nil)
|
||||
} inject List(Event.DrawOffer(by = none))
|
||||
case _ => fuccess(List(Event.ReloadOwner))
|
||||
}
|
||||
|
||||
def claim(pov: Pov)(implicit proxy: GameProxy): Fu[Events] =
|
||||
|
|
|
@ -73,6 +73,11 @@ module.exports = function(socket, ctrl) {
|
|||
if (!ctrl.data.player.spectator) ctrl.setLoading(true);
|
||||
else ctrl.redraw();
|
||||
},
|
||||
drawOffer: function(by) {
|
||||
ctrl.data.player.offeringDraw = by === ctrl.data.player.color;
|
||||
ctrl.data.opponent.offeringDraw = by === ctrl.data.opponent.color;
|
||||
ctrl.redraw();
|
||||
},
|
||||
berserk: function(color) {
|
||||
ctrl.setBerserk(color);
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue