Skip to main content

manabrew_engine/ability/effects/
incubate_effect.rs

1//! Incubate effect — create Incubator artifact token with +1/+1 counters.
2//!
3//! Ported from Java's `IncubateEffect.java`.
4//! Incubate N: Create an Incubator token with N +1/+1 counters on it.
5//! (It's a transforming double-faced token. Pay {2}: Transform it.
6//! It becomes a 0/0 Phyrexian artifact creature.)
7
8use super::token_effect_base::{TokenEffectBase, TOKEN_EFFECT_BASE};
9use super::{parse_counter_type, EffectContext};
10use crate::card::card_zone_table::CardZoneTable;
11
12/// Struct form of this effect so it can participate in the
13/// `SpellAbilityEffect` trait hierarchy — mirrors Java's
14/// `IncubateEffect` class extending `SpellAbilityEffect`.
15#[manabrew_engine_macros::spell_effect(IncubateEffect)]
16fn resolve(ctx: &mut EffectContext, sa: &crate::spellability::SpellAbility) {
17    let amount = super::resolve_numeric_svar(ctx.game, sa, "Amount", 1).max(0);
18    let times = super::resolve_numeric_svar(ctx.game, sa, "Times", 1).max(0) as usize;
19    let controller = sa.activating_player;
20
21    let players = if let Some(def) = sa.defined_player() {
22        super::resolve_defined_players(def, controller, ctx.game)
23    } else {
24        vec![controller]
25    };
26
27    for &pid in &players {
28        for _ in 0..times {
29            let mut token = TOKEN_EFFECT_BASE
30                .require_token_template(ctx.token_templates, "incubator_c_0_0_a_phyrexian");
31            if amount > 0 {
32                let ct = parse_counter_type("P1P1");
33                token.add_counter(&ct, amount);
34            }
35            let token_table = TOKEN_EFFECT_BASE.make_token_table_internal(pid, token, 1);
36            let mut trigger_list = CardZoneTable::default();
37            let result =
38                TOKEN_EFFECT_BASE.make_token_table(ctx, token_table, false, &mut trigger_list, sa);
39            if !result.created.is_empty() {
40                trigger_list.trigger_changes_zone_all(ctx.trigger_handler, ctx.game, Some(sa));
41            }
42        }
43    }
44}