Skip to main content

manabrew_protocol/prompts/
common.rs

1use serde::{Deserialize, Serialize};
2use ts_rs::TS;
3
4use crate::game::{Mana, TargetingIntent};
5
6#[derive(Debug, Clone, Serialize, Deserialize, TS)]
7#[serde(rename_all = "camelCase")]
8#[ts(export, export_to = "prompts/common.ts")]
9pub struct PromptPresentation {
10    pub title: String,
11    #[serde(default, skip_serializing_if = "Option::is_none")]
12    #[ts(optional)]
13    pub description: Option<String>,
14    #[serde(default, skip_serializing_if = "Option::is_none")]
15    #[ts(optional)]
16    pub text: Option<String>,
17    #[serde(default)]
18    pub targets: Vec<TargetRef>,
19}
20
21/// Mirrors the engine's `AlternativeCost` (itself a mirror of Java's).
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
23#[serde(rename_all = "camelCase")]
24#[ts(export, export_to = "prompts/common.ts")]
25pub enum AlternativeCostKind {
26    Flashback,
27    Spectacle,
28    Evoke,
29    Dash,
30    Blitz,
31    Escape,
32    Overload,
33    Madness,
34    Foretell,
35    Emerge,
36    Suspend,
37    Morph,
38    Megamorph,
39    Bestow,
40    Warp,
41    SacrificeAlt,
42    Plot,
43    Awaken,
44    Disturb,
45    Harmonize,
46    Freerunning,
47    Impending,
48    Mayhem,
49    #[serde(rename = "moreThanMeetsTheEye")]
50    MTMtE,
51    Mutate,
52    Prowl,
53    Sneak,
54    Surge,
55    WebSlinging,
56    Plotted,
57}
58
59/// Mirrors the engine's `PlayCardMode`.
60#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
61#[serde(
62    tag = "type",
63    rename_all = "camelCase",
64    rename_all_fields = "camelCase"
65)]
66#[ts(export, export_to = "prompts/common.ts")]
67pub enum PlayCardMode {
68    Normal,
69    BackFaceLand,
70    RoomRightSplit,
71    Alternative { cost: AlternativeCostKind },
72    StaticAlternative,
73    ForetellExile,
74    UnlockDoor,
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize, TS)]
78#[serde(rename_all = "camelCase")]
79#[ts(export, export_to = "prompts/common.ts")]
80pub struct ActivatableAbilityInfo {
81    pub card_id: String,
82    pub ability_index: usize,
83    pub description: String,
84    pub is_mana_ability: bool,
85    #[serde(default, skip_serializing_if = "Option::is_none")]
86    #[ts(optional)]
87    pub is_class_level_up: Option<bool>,
88    #[serde(default, skip_serializing_if = "Option::is_none")]
89    #[ts(optional)]
90    pub cost: Option<String>,
91    #[serde(default, skip_serializing_if = "Option::is_none")]
92    #[ts(optional)]
93    pub produced_mana: Option<Vec<Mana>>,
94}
95
96#[derive(Debug, Clone, Serialize, Deserialize, TS)]
97#[serde(
98    tag = "type",
99    rename_all = "camelCase",
100    rename_all_fields = "camelCase"
101)]
102#[ts(export, export_to = "prompts/common.ts")]
103pub enum AvailableActionKind {
104    Cast {
105        card_id: String,
106        mode: PlayCardMode,
107        label: String,
108    },
109    ActivateAbility(ActivatableAbilityInfo),
110    UndoMana {
111        card_id: String,
112    },
113}
114
115#[derive(Debug, Clone, Serialize, Deserialize, TS)]
116#[ts(export, export_to = "prompts/common.ts")]
117pub struct AvailableAction {
118    pub id: String,
119    #[serde(flatten)]
120    #[ts(flatten)]
121    pub kind: AvailableActionKind,
122}
123
124#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
125#[serde(rename_all = "camelCase")]
126#[ts(export, export_to = "prompts/common.ts")]
127pub enum PaymentResourceKind {
128    Convoke,
129    Improvise,
130    Delve,
131    Waterbend,
132}
133
134#[derive(Debug, Clone, Serialize, Deserialize, TS)]
135#[serde(
136    tag = "type",
137    rename_all = "camelCase",
138    rename_all_fields = "camelCase"
139)]
140#[ts(export, export_to = "prompts/common.ts")]
141pub enum PaymentActionKind {
142    ActivateManaAbility(ActivatableAbilityInfo),
143    UndoMana {
144        card_id: String,
145    },
146    UseResource {
147        card_id: String,
148        resource: PaymentResourceKind,
149    },
150    ReleaseResource {
151        card_id: String,
152        resource: PaymentResourceKind,
153    },
154    PayLife {
155        amount: u32,
156    },
157}
158
159#[derive(Debug, Clone, Serialize, Deserialize, TS)]
160#[ts(export, export_to = "prompts/common.ts")]
161pub struct PaymentAction {
162    pub id: String,
163    #[serde(flatten)]
164    #[ts(flatten)]
165    pub kind: PaymentActionKind,
166}
167
168#[derive(Debug, Clone, Serialize, Deserialize, TS)]
169#[serde(rename_all = "camelCase")]
170#[ts(export, export_to = "prompts/common.ts")]
171pub enum AttackTargetKind {
172    Player,
173    Planeswalker,
174    Battle,
175}
176
177#[derive(Debug, Clone, Serialize, Deserialize, TS)]
178#[serde(rename_all = "camelCase")]
179#[ts(export, export_to = "prompts/common.ts")]
180pub struct AttackTargetDto {
181    pub id: String,
182    pub label: String,
183    pub kind: AttackTargetKind,
184}
185
186#[derive(Debug, Clone, Serialize, Deserialize, TS)]
187#[serde(rename_all = "camelCase")]
188#[ts(export, export_to = "prompts/common.ts")]
189pub struct BlockAssignment {
190    pub blocker_id: String,
191    pub attacker_id: String,
192}
193
194#[derive(Debug, Clone, Serialize, Deserialize, TS)]
195#[serde(rename_all = "camelCase")]
196#[ts(export, export_to = "prompts/common.ts")]
197pub struct AttackAssignment {
198    pub attacker_id: String,
199    pub target_id: String,
200}
201
202#[derive(Debug, Clone, Serialize, Deserialize, TS)]
203#[serde(rename_all = "camelCase")]
204#[ts(export, export_to = "prompts/common.ts")]
205pub struct CombatDamageAssignmentEntry {
206    pub assignee_id: String,
207    pub damage: i32,
208}
209
210#[derive(Debug, Clone, Serialize, Deserialize, TS)]
211#[serde(
212    tag = "kind",
213    rename_all = "camelCase",
214    rename_all_fields = "camelCase"
215)]
216#[ts(export, export_to = "prompts/common.ts")]
217pub enum TargetAnyChoice {
218    Player { player_id: String },
219    Card { card_id: String },
220    None,
221}
222
223#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
224#[serde(rename_all = "camelCase")]
225#[ts(export, export_to = "prompts/common.ts")]
226pub enum TargetKind {
227    Player,
228    Card,
229    Spell,
230}
231
232#[derive(Debug, Clone, Serialize, Deserialize, TS)]
233#[serde(rename_all = "camelCase")]
234#[ts(export, export_to = "prompts/common.ts")]
235pub struct TargetRef {
236    pub kind: TargetKind,
237    pub id: String,
238    #[serde(default, skip_serializing_if = "Option::is_none")]
239    #[ts(optional)]
240    pub intent: Option<TargetingIntent>,
241    #[serde(default, skip_serializing_if = "Option::is_none")]
242    #[ts(optional)]
243    pub oracle: Option<String>,
244}