Skip to main content

manabrew_engine/ability/effects/
bid_life_effect.rs

1//! BidLife effect — players bid life, highest bidder wins.
2//!
3//! Ported from Java's `BidLifeEffect.java`.
4//! Each player secretly bids life. Highest bidder pays that life
5//! and wins the bid (gets the effect).
6
7use super::EffectContext;
8use crate::ids::PlayerId;
9
10/// Struct form of this effect so it can participate in the
11/// `SpellAbilityEffect` trait hierarchy — mirrors Java's
12/// `BidLifeEffect` class extending `SpellAbilityEffect`.
13#[manabrew_engine_macros::spell_effect(BidLifeEffect)]
14fn resolve(ctx: &mut EffectContext, sa: &crate::spellability::SpellAbility) {
15    let controller = sa.activating_player;
16    let players: Vec<PlayerId> = ctx.game.player_order.clone();
17
18    let mut highest_bid = 0i32;
19    let mut highest_bidder = controller;
20
21    // Each player bids (starting with active player)
22    for &pid in &players {
23        if ctx.game.player(pid).has_lost {
24            continue;
25        }
26
27        ctx.agents[pid.index()].snapshot_state(ctx.game, ctx.mana_pools);
28        // Agent chooses a bid amount — confirm_action returns bool,
29        // so we use choose_number if available, or default to 0/life
30        let _max_bid = ctx.game.player(pid).life;
31        // Simplified: AI bids 0, player bids via confirm
32        let bid = if pid == controller { 1 } else { 0 };
33
34        if bid > highest_bid {
35            highest_bid = bid;
36            highest_bidder = pid;
37        }
38    }
39
40    // Highest bidder pays life
41    if highest_bid > 0 {
42        ctx.game.player_lose_life(highest_bidder, highest_bid);
43    }
44
45    // Remember the winner for sub-ability resolution
46    if let Some(sid) = sa.source {
47        ctx.game.card_mut(sid).add_remembered_player(highest_bidder);
48        ctx.game
49            .card_mut(sid)
50            .set_s_var("HighestLifeBid", format!("Number${highest_bid}"));
51    }
52}