use super::{Mana, ManaPool};
use crate::ids::PlayerId;
#[derive(Debug, Clone)]
pub struct ManaRefundService {
activating_player: PlayerId,
}
impl ManaRefundService {
pub fn new(player: PlayerId) -> Self {
Self {
activating_player: player,
}
}
pub fn activating_player(&self) -> PlayerId {
self.activating_player
}
pub fn refund_mana_paid(&self, pool: &mut ManaPool, mana_spent: &mut Vec<Mana>) {
for m in mana_spent.drain(..) {
pool.add_mana(m);
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use forge_foundation::mana::ManaAtom;
#[test]
fn refund_returns_mana_to_pool() {
let service = ManaRefundService::new(PlayerId(0));
let mut pool = ManaPool::new();
let mut spent = vec![
Mana::simple(ManaAtom::RED),
Mana::simple(ManaAtom::GREEN),
Mana::simple(ManaAtom::BLUE),
];
service.refund_mana_paid(&mut pool, &mut spent);
assert_eq!(pool.total_mana(), 3);
assert!(spent.is_empty());
}
#[test]
fn activating_player_stored() {
let service = ManaRefundService::new(PlayerId(42));
assert_eq!(service.activating_player(), PlayerId(42));
}
}