Support for victory cards with variable score, implement Gardens
This commit is contained in:
parent
73bce1bc6d
commit
60c213baa6
15
src/card.rs
15
src/card.rs
@ -33,6 +33,16 @@ where
|
||||
serializer.serialize_str("ActionSer")
|
||||
}
|
||||
|
||||
fn serialize_card_type_0<S>(
|
||||
_: &fn(&super::Game, usize) -> u32,
|
||||
serializer: S,
|
||||
) -> Result<S::Ok, S::Error>
|
||||
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<u32> {
|
||||
pub fn victory(&self) -> Option<fn(&Game, usize) -> u32> {
|
||||
for t in &self.types {
|
||||
match t {
|
||||
CardType::Victory(points) => return Some(*points),
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user