1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
pub use equip::*;
mod equip;

pub use event::*;
mod event;

pub use support::*;
mod support;

pub use cost::{CardCost, DiceCost};
mod cost;

type Price = u16;

#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq)]
pub enum ActionCard {
    Equipment(EquipmentCard),
    Support(SupportCard),
    Event(EventCard),
}

impl ActionCard {
    pub fn name(&self) -> &'static str {
        match self {
            Self::Equipment(card) => card.name(),
            Self::Support(card)   => card.name(),
            Self::Event(card)     => card.name(),
        }
    }

    /// Returns `Some(price)` in Lucky Coins to buy the given card in the shop.
    /// 
    /// Cards not sold in the shop (such as [talent] cards or [`Paimon`]) return `None`
    /// 
    /// [talent]: TalentCard
    /// [`Paimon`]: CompanionCard::Paimon
    pub fn shop_price(&self) -> Option<Price> {
        match self {
            Self::Equipment(card) => card.shop_price(),
            Self::Support(card)   => card.shop_price(),
            Self::Event(card)     => card.shop_price(),
        }
    }

    pub fn cost(&self) -> CardCost {
        match self {
            Self::Equipment(card) => card.cost(),
            Self::Support(card)   => card.cost(),
            Self::Event(card)     => card.cost(),
        }
    }
}

use std::cmp::Ordering;
use super::CardOrd;
impl CardOrd for ActionCard {
    fn cmp(&self, other: &Self) -> Ordering {
        // Equipment < Support < Event
        match (self, other) {
            (Self::Equipment(x), Self::Equipment(y)) => x.cmp(y),
            (Self::Support(x), Self::Support(y))     => x.cmp(y),
            (Self::Event(x), Self::Event(y))         => x.cmp(y),
            (Self::Equipment(_), _) => Ordering::Less,
            (_, Self::Equipment(_)) => Ordering::Greater,
            (Self::Support(_), _)   => Ordering::Less,
            (_, Self::Support(_))   => Ordering::Greater,
        }
    }
}