1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use forge_foundation::ZoneType;
use super::EffectContext;
/// `SP$ Encode` — exile the spell card and encode it onto a creature (Cipher).
///
/// Mirrors Java's `EncodeEffect.java`.
/// The encoded spell is exiled attached to the chosen creature. Whenever that
/// creature deals combat damage to a player, its controller may cast a copy
/// of the encoded card without paying its mana cost.
///
/// Simplified: exiles the spell card and stores its ID in the creature's
/// `encoded_cards` list. The combat damage copy trigger is handled separately
/// in the trigger system.
///
/// # Card script examples
/// ```text
/// A:SP$ Encode | Defined$ Self
/// ```
/// Struct form of this effect so it can participate in the
/// `SpellAbilityEffect` trait hierarchy — mirrors Java's
/// `EncodeEffect` class extending `SpellAbilityEffect`.
#[manabrew_engine_macros::spell_effect(EncodeEffect)]
fn resolve(ctx: &mut EffectContext, sa: &crate::spellability::SpellAbility) {
let controller = sa.activating_player;
let spell_card = match sa.source {
Some(id) => id,
None => return,
};
// Find a creature to encode onto — use target or let player choose
let target = sa.target_chosen.target_card.or_else(|| {
let bf = ctx
.game
.cards_in_zone(ZoneType::Battlefield, controller)
.to_vec();
let creatures: Vec<_> = bf
.into_iter()
.filter(|&cid| {
let c = ctx.game.card(cid);
c.is_creature() && c.controller == controller
})
.collect();
if creatures.is_empty() {
return None;
}
let chosen =
ctx.agents[controller.index()].choose_cards_for_effect(controller, &creatures, 1, 1);
chosen.into_iter().next()
});
let creature_id = match target {
Some(id)
if ctx.game.card(id).zone == ZoneType::Battlefield
&& ctx.game.card(id).is_creature() =>
{
id
}
_ => return,
};
// Exile the spell card
let owner = ctx.game.card(spell_card).owner;
if ctx.game.card(spell_card).zone != ZoneType::Exile {
ctx.move_card(spell_card, ZoneType::Exile, owner);
}
// Encode it onto the creature
ctx.game
.card_mut(creature_id)
.encoded_cards
.push(spell_card);
}