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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//! Synthesis mechanic: Crafting, research, fusion, and transformation systems.
//!
//! This module provides a policy-based system for modeling how items, technologies,
//! skills, and entities are created through combination and transformation.
//!
//! # Key Insight: Synthesis is Transformation
//!
//! At its core, synthesis is about transforming inputs into outputs:
//! - **Crafting**: Materials → Items
//! - **Research**: Resources + Time → Technology
//! - **Skills**: Experience → Abilities
//! - **Fusion**: Entities → New Entity (with inheritance)
//!
//! # Architecture
//!
//! The synthesis mechanic follows **Policy-Based Design**:
//! - The core `SynthesisMechanic<P>` is generic over `SynthesisPolicy`
//! - `P: SynthesisPolicy` determines success rates, quality, and outcomes
//! - All logic is resolved at compile time via static dispatch
//!
//! # Outcome System
//!
//! Unlike simple success/failure, synthesis supports rich outcomes:
//!
//! - **Success**: Normal completion at expected quality
//! - **Critical Success**: Exceptional result with bonuses
//! - **Partial Success**: Degraded output with defects
//! - **Unexpected**: Accident or mutation (can be beneficial or harmful)
//! - **Transmutation**: Output transforms into different result
//! - **Failure**: No output, partial material consumption
//!
//! # Quick Start
//!
//! ```
//! use issun_core::mechanics::synthesis::prelude::*;
//! use issun_core::mechanics::{Mechanic, EventEmitter};
//!
//! // Define synthesis type (using default CraftingPolicy)
//! type Crafting = SynthesisMechanic;
//!
//! // Create configuration
//! let config = SynthesisConfig::default();
//! let mut state = SynthesisState::default();
//!
//! // Define a recipe
//! let recipe = Recipe::new("health_potion", "Health Potion")
//! .with_category(RecipeCategory::Alchemy)
//! .with_difficulty(1.2)
//! .with_ingredient(Ingredient::new("red_herb", 2))
//! .with_ingredient(Ingredient::new("water", 1))
//! .with_prerequisite(Prerequisite::tech("basic_alchemy"))
//! .with_output(SynthesisOutput::new("health_potion", 1))
//! .with_base_quality(QualityLevel::Common);
//!
//! // Prepare input
//! let input = SynthesisInput {
//! recipe,
//! ingredients: vec![
//! IngredientInput { id: "red_herb".into(), quantity: 2, quality: QualityLevel::Common },
//! IngredientInput { id: "water".into(), quantity: 1, quality: QualityLevel::Common },
//! ],
//! synthesizer: SynthesizerStats {
//! entity_id: "alchemist".into(),
//! skill_level: 0.7,
//! luck: 0.1,
//! quality_bonus: 0.0,
//! specializations: [(RecipeCategory::Alchemy, 0.2)].into_iter().collect(),
//! },
//! context: SynthesisContext::default(),
//! unlocked: {
//! let mut u = UnlockedPrerequisites::default();
//! u.techs.insert(TechId("basic_alchemy".into()));
//! u
//! },
//! rng: 0.6,
//! current_tick: 100,
//! };
//!
//! // Event collector
//! # struct TestEmitter { events: Vec<SynthesisEvent> }
//! # impl EventEmitter<SynthesisEvent> for TestEmitter {
//! # fn emit(&mut self, event: SynthesisEvent) { self.events.push(event); }
//! # }
//! let mut emitter = TestEmitter { events: vec![] };
//!
//! // Execute synthesis
//! Crafting::step(&config, &mut state, input, &mut emitter);
//!
//! // Check result
//! if let Some(outcome) = &state.outcome {
//! if outcome.is_success() {
//! println!("Created health potion!");
//! }
//! }
//! ```
//!
//! # Use Cases
//!
//! - **Item Crafting**: Blacksmithing, cooking, alchemy
//! - **Technology Research**: Science trees, unlocking capabilities
//! - **Skill Systems**: Learning abilities, talent trees
//! - **Demon Fusion**: Megaten-style entity combination
//! - **Enchanting**: Adding properties to items
//! - **Recipe Discovery**: Finding hidden combinations
// Re-export core types
pub use ;
pub use SynthesisPolicy;
pub use ;
/// Prelude module for convenient imports.
///
/// Import everything needed to use the synthesis mechanic:
///
/// ```
/// use issun_core::mechanics::synthesis::prelude::*;
/// ```