-
-
Save markovichecha/03f491c990520bc5988175fdd2b0a11d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug, Clone, PartialEq, Eq, Default)] | |
pub(crate) struct Charms(pub u16); | |
impl Charms { | |
pub(crate) fn new() -> Self { | |
Self(0) | |
} | |
pub(crate) fn set(&mut self, charm: Charm) -> Charms { | |
self.0 |= 1 << charm as u16; | |
self.clone() | |
} | |
pub(crate) fn is_set(&self, charm: Charm) -> bool { | |
self.0 & (1 << charm as u16) != 0 | |
} | |
pub(crate) fn is_empty(&self) -> bool { | |
self.0 == 0 | |
} | |
pub(crate) fn unset(&mut self, charm: Charm) -> Charms { | |
self.0 &= !(1 << charm as u16); | |
self.clone() | |
} | |
pub(crate) fn iter(&self) -> impl Iterator<Item = Charm> + '_ { | |
Charm::ALL | |
.iter() | |
.copied() | |
.filter(move |&charm| self.is_set(charm)) | |
} | |
pub(crate) fn set_with_sat(&mut self, sat: Sat) -> Charms { | |
if sat.nineball() { | |
self.set(Charm::Nineball); | |
} | |
if sat.coin() { | |
self.set(Charm::Coin); | |
} | |
match sat.rarity() { | |
Rarity::Common | Rarity::Mythic => self.clone(), | |
Rarity::Uncommon => self.set(Charm::Uncommon), | |
Rarity::Rare => self.set(Charm::Rare), | |
Rarity::Epic => self.set(Charm::Epic), | |
Rarity::Legendary => self.set(Charm::Legendary), | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment