weiss_core/state/modifiers.rs
1use serde::{Deserialize, Serialize};
2
3use crate::db::{AbilitySpec, CardId};
4use crate::effects::EffectSpec;
5
6use super::CardInstanceId;
7
8/// Modifier kinds applied to cards or zones.
9#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
10pub enum ModifierKind {
11 /// Modify card power.
12 Power,
13 /// Modify card soul.
14 Soul,
15 /// Modify effective level.
16 Level,
17 /// Modify stock cost to attack.
18 AttackCost,
19 /// Prevent declaring attacks.
20 CannotAttack,
21 /// Prevent declaring side attacks.
22 CannotSideAttack,
23 /// Prevent declaring frontal attacks.
24 CannotFrontalAttack,
25 /// Prevent a character from becoming reversed.
26 CannotBecomeReverse,
27 /// Prevent being chosen by opponent effects.
28 CannotBeChosenByOpponentEffects,
29 /// Prevent moving stage position.
30 CannotMoveStagePosition,
31 /// Prevent playing events from hand.
32 CannotPlayEventsFromHand,
33 /// Prevent playing backup from hand.
34 CannotPlayBackupFromHand,
35 /// Prevent standing during the stand phase.
36 CannotStandDuringStandPhase,
37 /// On reverse, move the battle opponent to memory.
38 BattleOpponentMoveToMemoryOnReverse,
39 /// Modify stock cost to encore.
40 EncoreStockCost,
41}
42
43/// Modifier duration semantics.
44#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
45pub enum ModifierDuration {
46 /// Expires during end-of-turn cleanup.
47 UntilEndOfTurn,
48 /// Persists while the card remains on stage.
49 WhileOnStage,
50}
51
52/// Modifier layer for ordering purposes.
53#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
54pub enum ModifierLayer {
55 /// Continuous effects.
56 Continuous,
57 /// Effect resolution layer (default).
58 #[default]
59 Effect,
60}
61
62/// Concrete modifier instance applied to a target.
63#[derive(Clone, Debug, Hash, Serialize, Deserialize)]
64pub struct ModifierInstance {
65 /// Unique modifier id.
66 pub id: u32,
67 /// Source card id that created the modifier.
68 pub source: CardId,
69 /// Optional source slot when the source is on stage.
70 #[serde(default)]
71 pub source_slot: Option<u8>,
72 /// Target player seat.
73 pub target_player: u8,
74 /// Target stage slot index.
75 pub target_slot: u8,
76 /// Target card id (for debugging and validation).
77 pub target_card: CardId,
78 /// Modifier kind.
79 pub kind: ModifierKind,
80 /// Modifier magnitude (kind-dependent).
81 pub magnitude: i32,
82 /// Duration for which the modifier remains active.
83 pub duration: ModifierDuration,
84 /// Layer used when applying modifiers.
85 #[serde(default)]
86 pub layer: ModifierLayer,
87 /// Insertion order used as a tie-breaker.
88 pub insertion: u32,
89}
90
91/// Runtime granted ability attached to a specific stage card instance.
92#[derive(Clone, Debug, Hash, Serialize, Deserialize)]
93pub struct GrantedAbilityInstance {
94 /// Stable grant id.
95 pub grant_id: u64,
96 /// Target player seat.
97 pub target_player: u8,
98 /// Target stage slot index.
99 pub target_slot: u8,
100 /// Target card instance id.
101 pub target_instance_id: CardInstanceId,
102 /// Ability spec (template + conditions + cost).
103 pub spec: AbilitySpec,
104 /// Compiled effect specs derived from `spec`.
105 pub compiled_effects: Vec<EffectSpec>,
106 /// Turn number at which this grant expires during end-phase cleanup.
107 pub expires_turn_number: u32,
108}