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
pub use artifact::ArtifactCard;
mod artifact;
pub use weapon::WeaponCard;
mod weapon;
pub use talent::TalentCard;
mod talent;
use crate::CardCost;
use super::Price;
#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq)]
pub enum EquipmentCard {
Talent(TalentCard),
Weapon(WeaponCard),
Artifact(ArtifactCard),
}
impl EquipmentCard {
pub fn name(&self) -> &'static str {
match self {
Self::Talent(card) => card.name(),
Self::Weapon(card) => card.name(),
Self::Artifact(card) => card.name(),
}
}
pub fn shop_price(&self) -> Option<Price> {
match self {
Self::Talent(_) => None,
Self::Weapon(card) => Some(card.shop_price()),
Self::Artifact(card) => Some(card.shop_price()),
}
}
pub fn cost(&self) -> CardCost {
match self {
Self::Talent(card) => card.cost(),
Self::Weapon(card) => card.cost(),
Self::Artifact(card) => card.cost(),
}
}
}
use std::cmp::Ordering;
use super::CardOrd;
impl CardOrd for EquipmentCard {
fn cmp(&self, other: &Self) -> Ordering {
match (self, other) {
(Self::Talent(x), Self::Talent(y)) => x.cmp(y),
(Self::Weapon(x), Self::Weapon(y)) => x.cmp(y),
(Self::Artifact(x), Self::Artifact(y)) => x.cmp(y),
(Self::Talent(_), _) => Ordering::Less,
(_, Self::Talent(_)) => Ordering::Greater,
(Self::Weapon(_), _) => Ordering::Less,
(_, Self::Weapon(_)) => Ordering::Greater,
}
}
}