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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
//! A testing framework for the game [Super Auto Pets](https://teamwoodgames.com/).
//!
//! Game information is scraped and parsed from the [Super Auto Pets Wiki](https://superautopets.wiki.gg/wiki/Super_Auto_Pets_Wiki) before being stored in a [SQLite](https://www.sqlite.org/index.html) database.
//!
//! ### Teams
//! Build a [`Team`] and simulate battles between them.
//!
//! Then visualize the results in `.dot` format!
//! ```
//! use saptest::{
//! Pet, PetName, Food, FoodName,
//! Team, TeamCombat, Position, create_battle_digraph
//! };
//!
//! // Create a team.
//! let mut team = Team::new(
//! &vec![Some(Pet::try_from(PetName::Ant).unwrap()); 5],
//! 5
//! ).unwrap();
//! let mut enemy_team = team.clone();
//!
//! // Set a seed for a team.
//! team.set_seed(Some(25));
//!
//! // Give food to pets.
//! team.set_item(&Position::First, Food::try_from(FoodName::Garlic).ok());
//! enemy_team.set_item(&Position::First, Food::try_from(FoodName::Garlic).ok());
//!
//! // And fight!
//! team.fight(&mut enemy_team).unwrap();
//!
//! // Create a graph of the fight.
//! println!("{}", create_battle_digraph(&team, false));
//! ```
//!
//! ```bash
//! digraph {
//! rankdir=LR
//! node [shape=box, style="rounded, filled", fontname="Arial"]
//! edge [fontname="Arial"]
//! 0 [ label = "Ant_0 - The Fragile Truckers_copy" ]
//! 1 [ label = "Ant_0 - The Fragile Truckers", fillcolor = "yellow" ]
//! 2 [ label = "Ant_3 - The Fragile Truckers", fillcolor = "yellow" ]
//! 3 [ label = "Ant_4 - The Fragile Truckers_copy" ]
//! 0 -> 1 [ label = "(Attack, Damage (0, 2), Phase: 1)" ]
//! 1 -> 0 [ label = "(Attack, Damage (0, 2), Phase: 1)" ]
//! 1 -> 2 [ label = "(Faint, Add (1, 1), Phase: 1)" ]
//! 0 -> 3 [ label = "(Faint, Add (1, 1), Phase: 1)" ]
//! }
//! ```
//! ### Shops
//! Add shop functionality to a [`Team`] and roll, freeze, buy/sell pets and foods.
//! ```
//! use saptest::{
//! Entity, EntityName, Pet, PetName, Food, FoodName,
//! Shop, ShopItem, TeamShopping,
//! Team, TeamViewer, Position,
//! db::pack::Pack
//! };
//!
//! // All teams are constructed with a shop at tier 1.
//! let mut team = Team::new(
//! &vec![Some(Pet::try_from(PetName::Ant).unwrap()); 4],
//! 5
//! ).unwrap();
//!
//! // All shop functionality is supported.
//! team.set_shop_seed(Some(1212))
//! .set_shop_packs(&[Pack::Turtle])
//! .open_shop().unwrap()
//! .buy(
//! &Position::First, // From first.
//! &Entity::Pet, // Pet
//! &Position::First // To first position, merging if possible.
//! ).unwrap()
//! .sell(&Position::First).unwrap()
//! .move_pets(
//! &Position::First, // From first pet
//! &Position::Relative(-2), // To 2nd pet behind.
//! true // And merge them if possible.
//! ).unwrap()
//! .freeze_shop(&Position::Last, &Entity::Pet).unwrap()
//! .roll_shop().unwrap()
//! .close_shop().unwrap();
//!
//! // Shops can be built separately and can replace a team's shop.
//! let mut tier_5_shop = Shop::new(3, Some(42)).unwrap();
//! let weakness = ShopItem::new(
//! Food::try_from(FoodName::Weak).unwrap()
//! );
//! tier_5_shop.add_item(weakness).unwrap();
//! team.replace_shop(tier_5_shop).unwrap();
//! ```
//!
//! ### Pets
//! Build custom [`Pet`]s and [`Effect`]s.
//! ```
//! use saptest::{
//! Pet, PetName, PetCombat,
//! Food, FoodName,
//! Position, Effect, Statistics,
//! effects::{
//! trigger::TRIGGER_START_BATTLE,
//! actions::GainType,
//! state::Target,
//! actions::Action
//! }
//! };
//!
//! // Create known pets.
//! let mut pet = Pet::try_from(PetName::Ant).unwrap();
//!
//! // A custom pet and effect.
//! let custom_effect = Effect::new(
//! TRIGGER_START_BATTLE, // Effect trigger
//! Target::Friend, // Target
//! Position::Adjacent, // Positions
//! Action::Gain(GainType::DefaultItem(FoodName::Melon)), // Action
//! Some(1), // Number of uses.
//! false, // Is temporary.
//! );
//! let mut custom_pet = Pet::custom(
//! "MelonBear",
//! Statistics::new(50, 50).unwrap(),
//! &[custom_effect],
//! );
//! // Fight two pets individually as well.
//! // Note: Effects don't activate here.
//! pet.attack(&mut custom_pet);
//! ```
//!
//! ### Logging
//! Enable logging with a crate like [`simple_logger`](https://docs.rs/simple_logger/latest/simple_logger/#).
//!
//! ### Config
//! To configure the global [`SapDB`]'s startup, create a `.saptest.toml` file in the root of your project.
//! * Specify page version for pets, foods, and tokens to query.
//! * Toggle recurring updates on startup.
//! * Set database filename.
//!
//! Read more under the [`db`] module.
// TODO: Split errors into smaller categories?
extern crate lazy_regex;
use lazy_static;
use read_to_string;
pub use crate;
pub use crate;
use crate;
pub use crate;
pub use crate;
pub use crate;
pub use crate;
pub use crate;
pub use crate;
const DB_FNAME: &str = "./sap.db";
const ENV_SAPTEST_CONFIG: &str = "CONFIG_SAPTEST";
lazy_static!