SHARE
TWEET

Untitled

a guest Jan 23rd, 2020 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     pub fn handle_state<UI: GameUI, Res: ResourceContext>(
  2.         &mut self,
  3.         state: &State,
  4.         ui: &mut UI,
  5.         res: &Res,
  6.     ) -> StateResult {
  7.         match state {
  8.             State::PushRegisterStack => {
  9.                 self.push_register_stack();
  10.                 completed![]
  11.             }
  12.  
  13.             State::PopRegisterStack => {
  14.                 self.pop_register_stack();
  15.                 completed![]
  16.             }
  17.  
  18.             State::TakeTurn => completed![
  19.                 State::DrawHand,
  20.                 State::ActionPhase,
  21.                 State::CleanUp,
  22.                 State::TakeTurn
  23.             ],
  24.  
  25.             State::DrawHand => completed![State::DrawPlayerCards(5)],
  26.  
  27.             State::ActionPhase => {
  28.                 if self.actions > 0 {
  29.                     if let Some(res) = ui
  30.                         .get_card_or_button(&self.get_cards(Place::Hand), &[("Stop playing actions", ())])
  31.                     {
  32.                         match res {
  33.                             CardOrButton::Card(id) => {
  34.                                 completed![State::ResolveAction(id), State::ActionPhase]
  35.                             }
  36.                             CardOrButton::Button(_) => completed!(),
  37.                         }
  38.                     } else {
  39.                         blocked!()
  40.                     }
  41.                 } else {
  42.                     if let Some(()) = ui.get_button(&[("Stop playing actions", ())]) {
  43.                         completed!()
  44.                     } else {
  45.                         blocked!()
  46.                     }
  47.                 }
  48.             }
  49.  
  50.             State::CleanUp => completed![
  51.                 State::MoveAllCards(Place::Played, Place::Discard),
  52.                 State::MoveAllCards(Place::Hand, Place::Discard),
  53.             ],
  54.  
  55.             State::CardAction(action) => match action {
  56.                 &CardAction::GainExperience(n) => {
  57.                     completed![State::ModifyExperience(self.get_number(n) as i32)]
  58.                 }
  59.                 &CardAction::GainActions(n) => {
  60.                     completed![State::ModifyActions(self.get_number(n) as i32)]
  61.                 }
  62.                 &CardAction::DrawCards(n) => completed![State::DrawPlayerCards(self.get_number(n))],
  63.                 &CardAction::SetVar(n, v) => {
  64.                     self.set_register_value(v.into(), self.get_number(n));
  65.                     completed![]
  66.                 }
  67.             },
  68.  
  69.             &State::ResolveAction(card) => {
  70.                 if let CardType::Player(card_type) = self.get_card_type(res, card) {
  71.                     completed![
  72.                         State::PushRegisterStack,
  73.                         State::MoveCard(card, Place::Active),
  74.                         card_type.onplay.iter().map(|&a| State::CardAction(a)),
  75.                         State::MoveCard(card, Place::Played),
  76.                         State::PopRegisterStack,
  77.                     ]
  78.                 } else {
  79.                     //TODO handle this more nicely
  80.                     panic!("Tried to resolve a non-action card as an action");
  81.                 }
  82.             }
  83.  
  84.             &State::MoveCard(card, to) => {
  85.                 let from = self.get_card_location(card);
  86.                 self.move_card(card, from, to);
  87.                 ui.move_card(card, from, to);
  88.                 completed![]
  89.             }
  90.  
  91.             &State::MoveNCards(count, from, to) => {
  92.                 let count = u32::min(count, self.get_deck_length(from));
  93.                 for _ in 0..count {
  94.                     let card = self.get_top(from);
  95.                     self.move_card(card, from, to);
  96.                     ui.move_card(card, from, to);
  97.                 }
  98.                 completed![]
  99.             }
  100.  
  101.             &State::MoveAllCards(from, to) => {
  102.                 completed![State::MoveNCards(self.get_deck_length(from), from, to)]
  103.             }
  104.  
  105.             &State::Shuffle(place) => {
  106.                 self.shuffle(place);
  107.                 completed![]
  108.             }
  109.  
  110.             &State::DrawPlayerCards(count) => {
  111.                 let deck_count = self.get_place_count(Place::Deck);
  112.  
  113.                 if deck_count >= count {
  114.                     completed![State::MoveNCards(count, Place::Deck, Place::Hand)]
  115.                 } else {
  116.                     let remainder = count - deck_count;
  117.                     completed![
  118.                         State::MoveNCards(deck_count, Place::Deck, Place::Hand),
  119.                         State::MoveAllCards(Place::Discard, Place::Deck),
  120.                         State::Shuffle(Place::Deck),
  121.                         State::MoveNCards(remainder, Place::Deck, Place::Hand)
  122.                     ]
  123.                 }
  124.             }
  125.  
  126.             &State::ModifyActions(n) => {
  127.                 self.actions += n;
  128.                 ui.set_counter(Counter::Actions, self.actions);
  129.                 completed![]
  130.             }
  131.  
  132.             &State::ModifyExperience(n) => {
  133.                 self.experience += n;
  134.                 ui.set_counter(Counter::Experience, self.experience);
  135.                 completed![]
  136.             }
  137.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top