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")
|
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)]
|
#[derive(Clone, Serialize)]
|
||||||
pub enum CardType {
|
pub enum CardType {
|
||||||
#[serde(serialize_with = "serialize_card_type")]
|
#[serde(serialize_with = "serialize_card_type")]
|
||||||
@ -42,7 +52,8 @@ pub enum CardType {
|
|||||||
#[serde(serialize_with = "serialize_card_type")]
|
#[serde(serialize_with = "serialize_card_type")]
|
||||||
Reaction(fn(&mut Game)),
|
Reaction(fn(&mut Game)),
|
||||||
Treasure(u32),
|
Treasure(u32),
|
||||||
Victory(u32),
|
#[serde(serialize_with = "serialize_card_type_0")]
|
||||||
|
Victory(fn(&Game, usize) -> u32),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -97,7 +108,7 @@ impl Card {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn victory(&self) -> Option<u32> {
|
pub fn victory(&self) -> Option<fn(&Game, usize) -> u32> {
|
||||||
for t in &self.types {
|
for t in &self.types {
|
||||||
match t {
|
match t {
|
||||||
CardType::Victory(points) => return Some(*points),
|
CardType::Victory(points) => return Some(*points),
|
||||||
|
@ -805,7 +805,7 @@ async fn broadcast_state(game: &Game) {
|
|||||||
.map(|(i, p)| {
|
.map(|(i, p)| {
|
||||||
let score = p.draw_pile.iter().fold(0, |acc, card| {
|
let score = p.draw_pile.iter().fold(0, |acc, card| {
|
||||||
if let Some(points) = card.victory() {
|
if let Some(points) = card.victory() {
|
||||||
acc + points
|
acc + points(&game, i)
|
||||||
} else if let Some(_) = card.curse() {
|
} else if let Some(_) = card.curse() {
|
||||||
acc - 1
|
acc - 1
|
||||||
} else {
|
} else {
|
||||||
|
@ -67,15 +67,15 @@ fn gold() -> Card {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn estate() -> 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 {
|
fn duchy() -> Card {
|
||||||
Card::new("Duchy", 5).with_type(CardType::Victory(3))
|
Card::new("Duchy", 5).with_type(CardType::Victory(|_, _| 3))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn province() -> Card {
|
fn province() -> Card {
|
||||||
Card::new("Province", 8).with_type(CardType::Victory(6))
|
Card::new("Province", 8).with_type(CardType::Victory(|_, _| 6))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn curse() -> Card {
|
fn curse() -> Card {
|
||||||
@ -105,7 +105,7 @@ fn bureaucrat() -> Card {
|
|||||||
game.add_effect(Effect::Resolving {
|
game.add_effect(Effect::Resolving {
|
||||||
card: "Bureaucrat".into(),
|
card: "Bureaucrat".into(),
|
||||||
request: ResolveRequest::ChooseHandCardsToDiscard {
|
request: ResolveRequest::ChooseHandCardsToDiscard {
|
||||||
filter: CardFilter::Type(CardType::Victory(0)),
|
filter: CardFilter::Type(CardType::Victory(|_, _| 0)), //FIXME!
|
||||||
},
|
},
|
||||||
player: ResolvingPlayer::AllNonActivePlayers,
|
player: ResolvingPlayer::AllNonActivePlayers,
|
||||||
effect: |game, message, player, _request, _state| {
|
effect: |game, message, player, _request, _state| {
|
||||||
@ -222,7 +222,9 @@ fn festival() -> Card {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn gardens() -> 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 {
|
fn moat() -> Card {
|
||||||
|
Loading…
Reference in New Issue
Block a user