use forge_foundation::ZoneType;
use crate::game::GameState;
use crate::ids::{CardId, PlayerId};
pub fn do_phasing(game: &mut GameState, turn_player: PlayerId) {
for i in 0..game.cards.len() {
if game.cards[i].phased_out
&& game.cards[i].controller == turn_player
&& game.cards[i].zone == ZoneType::Battlefield
{
game.cards[i].phased_out = false;
}
}
for i in 0..game.cards.len() {
if !game.cards[i].phased_out
&& game.cards[i].controller == turn_player
&& game.cards[i].zone == ZoneType::Battlefield
&& game.cards[i].has_keyword("Phasing")
{
game.cards[i].phased_out = true;
}
}
}
pub fn do_day_time(game: &mut GameState, previous_player: Option<PlayerId>) {
let previous = match previous_player {
Some(p) => p,
None => return,
};
let spells_cast = game.player(previous).spells_cast_this_turn;
if !game.is_night && spells_cast == 0 {
game.day_night_started = true;
game.is_night = true; } else if game.is_night && spells_cast > 1 {
game.day_night_started = true;
game.is_night = false; }
}
pub fn execute_at(
game: &mut GameState,
turn_player: PlayerId,
previous_player: Option<PlayerId>,
) -> Vec<CardId> {
do_phasing(game, turn_player);
do_day_time(game, previous_player);
do_untap(game, turn_player)
}
pub fn do_untap(game: &mut GameState, active: PlayerId) -> Vec<CardId> {
let cards: Vec<CardId> = game.cards_in_zone(ZoneType::Battlefield, active).to_vec();
let mut untapped = Vec::new();
for cid in cards {
if !game.card(cid).tapped {
continue;
}
if game
.card(cid)
.has_keyword("CARDNAME doesn't untap during your untap step.")
{
continue;
}
if game.card(cid).exerted {
game.card_mut(cid).exerted = false;
continue;
}
let has_skip = game
.card(cid)
.has_keyword("This card doesn't untap during your next untap step.");
if has_skip {
game.card_mut(cid)
.keywords
.remove("This card doesn't untap during your next untap step.");
continue;
}
game.untap_during_untap_step(cid, active);
untapped.push(cid);
}
for i in 0..game.cards.len() {
if game.cards[i].zone == ZoneType::Battlefield {
game.cards[i].exerted = false;
}
}
untapped
}
#[cfg(test)]
mod tests {
#[test]
fn do_phasing_phases_in() {
}
}