From 60c213baa6f5749312806b0492af379f8c955e73 Mon Sep 17 00:00:00 2001 From: Markus Wagner Date: Mon, 8 Feb 2021 17:58:17 +0100 Subject: [PATCH] Support for victory cards with variable score, implement Gardens --- src/card.rs | 15 +++++++++++++-- src/main.rs | 2 +- src/sets/base.rs | 12 +++++++----- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/card.rs b/src/card.rs index dc1883f..c7b5fdb 100644 --- a/src/card.rs +++ b/src/card.rs @@ -33,6 +33,16 @@ where serializer.serialize_str("ActionSer") } +fn serialize_card_type_0( + _: &fn(&super::Game, usize) -> u32, + serializer: S, +) -> Result +where + S: Serializer, +{ + serializer.serialize_str("ActionSer") +} + #[derive(Clone, Serialize)] pub enum CardType { #[serde(serialize_with = "serialize_card_type")] @@ -42,7 +52,8 @@ pub enum CardType { #[serde(serialize_with = "serialize_card_type")] Reaction(fn(&mut Game)), Treasure(u32), - Victory(u32), + #[serde(serialize_with = "serialize_card_type_0")] + Victory(fn(&Game, usize) -> u32), } #[derive(Clone)] @@ -97,7 +108,7 @@ impl Card { None } - pub fn victory(&self) -> Option { + pub fn victory(&self) -> Option u32> { for t in &self.types { match t { CardType::Victory(points) => return Some(*points), diff --git a/src/main.rs b/src/main.rs index 371cc37..7bd0637 100644 --- a/src/main.rs +++ b/src/main.rs @@ -805,7 +805,7 @@ async fn broadcast_state(game: &Game) { .map(|(i, p)| { let score = p.draw_pile.iter().fold(0, |acc, card| { if let Some(points) = card.victory() { - acc + points + acc + points(&game, i) } else if let Some(_) = card.curse() { acc - 1 } else { diff --git a/src/sets/base.rs b/src/sets/base.rs index 56a8c00..b3b6dc3 100644 --- a/src/sets/base.rs +++ b/src/sets/base.rs @@ -67,15 +67,15 @@ fn gold() -> Card { } fn estate() -> Card { - Card::new("Estate", 2).with_type(CardType::Victory(1)) + Card::new("Estate", 2).with_type(CardType::Victory(|_, _| 1)) } fn duchy() -> Card { - Card::new("Duchy", 5).with_type(CardType::Victory(3)) + Card::new("Duchy", 5).with_type(CardType::Victory(|_, _| 3)) } fn province() -> Card { - Card::new("Province", 8).with_type(CardType::Victory(6)) + Card::new("Province", 8).with_type(CardType::Victory(|_, _| 6)) } fn curse() -> Card { @@ -105,7 +105,7 @@ fn bureaucrat() -> Card { game.add_effect(Effect::Resolving { card: "Bureaucrat".into(), request: ResolveRequest::ChooseHandCardsToDiscard { - filter: CardFilter::Type(CardType::Victory(0)), + filter: CardFilter::Type(CardType::Victory(|_, _| 0)), //FIXME! }, player: ResolvingPlayer::AllNonActivePlayers, effect: |game, message, player, _request, _state| { @@ -222,7 +222,9 @@ fn festival() -> Card { } fn gardens() -> Card { - Card::new("Gardens", 4).with_type(CardType::Victory(0)) + Card::new("Gardens", 4).with_type(CardType::Victory(|game, player| { + game.players[player].draw_pile.len() as u32 / 10 + })) } fn moat() -> Card {