manabrew_engine/ability/effects/
counters_move_effect.rs1use super::{parse_counter_type, EffectContext};
7use forge_foundation::ZoneType;
8
9#[manabrew_engine_macros::spell_effect(CountersMoveEffect)]
13fn resolve(ctx: &mut EffectContext, sa: &crate::spellability::SpellAbility) {
14 let counter_type_str = sa
15 .ir
16 .counter_type
17 .as_ref()
18 .map(|s| s.to_string())
19 .unwrap_or_else(|| "P1P1".to_string());
20 let counter_type = parse_counter_type(&counter_type_str);
21 let amount = super::resolve_numeric_svar(ctx.game, sa, "CounterNum", 1).max(0);
22
23 let source_card = sa
25 .source
26 .filter(|&cid| ctx.game.card(cid).zone == ZoneType::Battlefield);
27 let target_card = sa
29 .target_chosen
30 .target_card
31 .filter(|&cid| ctx.game.card(cid).zone == ZoneType::Battlefield);
32
33 let (Some(from), Some(to)) = (source_card, target_card) else {
34 return;
35 };
36 if from == to {
37 return;
38 }
39
40 let current = *ctx
42 .game
43 .card(from)
44 .counters
45 .get(&counter_type)
46 .unwrap_or(&0);
47 let to_move = amount.min(current);
48 if to_move <= 0 {
49 return;
50 }
51
52 ctx.game
53 .card_mut(from)
54 .remove_counter(&counter_type, to_move);
55 ctx.game.card_mut(to).add_counter(&counter_type, to_move);
56}