Doc(Addentum) - Added a lot of documentation and some code examples
This commit is contained in:
parent
47792825f7
commit
0c5ed39573
156
src/action.rs
156
src/action.rs
|
|
@ -1,24 +1,55 @@
|
|||
//! Module containing all actions that a crafter can execute
|
||||
//!
|
||||
//! All actions are defined as Action, containing all methods to actively use it in a craft
|
||||
//! while ActionBuilder is used only initally as a lazy_static setup
|
||||
//!
|
||||
|
||||
use crate::craft::Craft;
|
||||
use crate::specs::{Buff, Success};
|
||||
use lazy_static::lazy_static;
|
||||
#[allow(dead_code)]
|
||||
use std::fmt::Debug;
|
||||
|
||||
/// Hold an action for the solver to try using
|
||||
///
|
||||
/// It will be used heavily to try/discard actions durin craft
|
||||
pub struct Action {
|
||||
/// The action name, in a human readable format, it will be used to generate a short_name
|
||||
pub name: String,
|
||||
/// The natural durability cost, without buff or reductions
|
||||
pub dur: u32,
|
||||
/// The cost in cp
|
||||
pub cp: u32,
|
||||
/// The amount of progression provided in percent (not the actual value added to the craft)
|
||||
pub progress: u32,
|
||||
/// The amount of quality provided in percent (not the acual value added to the craft)
|
||||
pub quality: u32,
|
||||
/// The name of the buff given, if any
|
||||
pub buff: Option<(Buff, u8)>,
|
||||
/// The short name of the action, as used by most crafting simulator (aka: stripped of whitespace)
|
||||
pub short_name: String,
|
||||
}
|
||||
|
||||
/// Builds an action based on an action
|
||||
///
|
||||
/// Made to initialize lazy_static and nothing more
|
||||
pub struct ActionBuilder {
|
||||
action: Action,
|
||||
}
|
||||
|
||||
impl ActionBuilder {
|
||||
/// Base creator, takes a name and initialize an empty action with the short_name
|
||||
/// and name setup and default values for all other fields
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use xiv_csolver_lib::action::ActionBuilder;
|
||||
/// use xiv_csolver_lib::specs::Buff;
|
||||
/// ActionBuilder::new("Muscle Memory")
|
||||
/// .cp(6)
|
||||
/// .progress(300)
|
||||
/// .buff(Some((Buff::MuscleMemory, 5)))
|
||||
/// .build();
|
||||
/// ```
|
||||
pub fn new(name: &str) -> Self {
|
||||
let mut short_name = name.to_string();
|
||||
short_name = short_name.replace("II", "2");
|
||||
|
|
@ -46,31 +77,46 @@ impl ActionBuilder {
|
|||
},
|
||||
}
|
||||
}
|
||||
/// Changes the durability consumption of an action
|
||||
pub fn dur(mut self, dur: u32) -> Self {
|
||||
self.action.dur = dur;
|
||||
self
|
||||
}
|
||||
|
||||
/// Changes the crafting points (cp) consumption of an action
|
||||
pub fn cp(mut self, cp: u32) -> Self {
|
||||
self.action.cp = cp;
|
||||
self
|
||||
}
|
||||
/// Changes the amount of progress of an action
|
||||
pub fn progress(mut self, progress: u32) -> Self {
|
||||
self.action.progress = progress;
|
||||
self
|
||||
}
|
||||
/// Changes the amount of quality of an action
|
||||
pub fn quality(mut self, quality: u32) -> Self {
|
||||
self.action.quality = quality;
|
||||
self
|
||||
}
|
||||
/// Makes an action add a buff for certain number of actions
|
||||
/// The buffs available are defined in [specs.rs](xiv_csolver::specs::Buff)
|
||||
///
|
||||
/// ``
|
||||
/// (self.recipe.progress as f32 - self.progression as f32) / self.get_base_progression() as f32;
|
||||
/// ``
|
||||
pub fn buff(mut self, buff: Option<(Buff, u8)>) -> Self {
|
||||
self.action.buff = buff;
|
||||
self
|
||||
}
|
||||
/// Finalize the usage of the ActionBuilder and return the action
|
||||
/// Once again, all this is for the usage of lazy_static
|
||||
pub fn build(self) -> Action {
|
||||
self.action
|
||||
}
|
||||
}
|
||||
|
||||
/// Custom implementation of the equality operator, it is used to compare actions during the
|
||||
/// the crafting process
|
||||
impl PartialEq for Action {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.cp == other.cp
|
||||
|
|
@ -80,10 +126,14 @@ impl PartialEq for Action {
|
|||
}
|
||||
}
|
||||
|
||||
/// A craft action, after compilation (with lazy_static)
|
||||
// no other actions should be created
|
||||
impl Action {
|
||||
/// Get the printable name of the action
|
||||
pub fn get_name(&self) -> String {
|
||||
self.name.clone()
|
||||
}
|
||||
/// Get the CP cost, reduced by the eventual chain buffs currently active in the craft
|
||||
pub fn get_cp_cost(&self, _craft: &Craft) -> u32 {
|
||||
if self == &ACTIONS.standard_touch && _craft.buffs.basic_touch > 0 {
|
||||
return 18;
|
||||
|
|
@ -93,6 +143,8 @@ impl Action {
|
|||
};
|
||||
self.cp
|
||||
}
|
||||
/// Get the durability cost this action would have if used at this stage of the craft
|
||||
/// This method accounts for the effects of **master mend** and **waste not**.
|
||||
pub fn get_durability_cost(&self, _craft: &Craft) -> u32 {
|
||||
if self == &ACTIONS.masters_mend {
|
||||
return 30;
|
||||
|
|
@ -109,6 +161,14 @@ impl Action {
|
|||
}
|
||||
dur
|
||||
}
|
||||
/// Get the progress effect this action would have if used at this stage of the craft
|
||||
/// This method accounts for the effects of **groundwork** under 20 durability,
|
||||
/// and the effects of **veneration** and **muscle memory**
|
||||
/// # Exemple
|
||||
/// ```md
|
||||
/// - Groundwork will return 200 if the durability remaining is above 20
|
||||
/// - Basic Synthesis will return 100 if no buffs are up and 150 with veneration
|
||||
/// ```
|
||||
pub fn get_progress(&self, _craft: &Craft) -> u32 {
|
||||
let mut prog = self.progress as f64;
|
||||
if self.dur == 20 && _craft.durability < self.get_durability_cost(_craft) as i32 {
|
||||
|
|
@ -123,6 +183,9 @@ impl Action {
|
|||
}
|
||||
(prog * mult).floor() as u32
|
||||
}
|
||||
|
||||
/// Get the quality effect this action would have if used at this stage of the craft.
|
||||
/// This method account for the **inner quiet** stacking effect, **innovation** and **great strides**
|
||||
pub fn get_quality(&self, _craft: &Craft) -> u32 {
|
||||
let mut qual = self.quality as f64;
|
||||
if self == &ACTIONS.byregot_blessing {
|
||||
|
|
@ -141,9 +204,19 @@ impl Action {
|
|||
let iq_mult = (_craft.buffs.inner_quiet as f64 * 0.1) + 1.0;
|
||||
(qual * mult * iq_mult).floor() as u32
|
||||
}
|
||||
/// Returns the Buff (if any) up at this time of the craft
|
||||
pub fn get_buff(&self) -> Option<(Buff, u8)> {
|
||||
self.buff
|
||||
}
|
||||
/// Returns a bool representing if this action **can** be used, note that this does only account
|
||||
/// for the game limitations and not viability limitation
|
||||
///
|
||||
/// # Improvements
|
||||
/// This function could easily prune useless actions by considering them not available.
|
||||
/// Doing so could stop early refresh of buffs and spam of observe and such.
|
||||
/// However some of such "optimisations" could just plain hurt the craft by forbidding a *seemingly*
|
||||
/// useless action. The "bruteforce" method being easily computatble on a modern computer, such
|
||||
/// optimisations arent warrented and left to aother time.
|
||||
pub fn can_use(&self, _craft: &Craft) -> bool {
|
||||
if self.get_cp_cost(_craft) > _craft.cp as u32 {
|
||||
return false;
|
||||
|
|
@ -170,32 +243,112 @@ impl Debug for Action {
|
|||
}
|
||||
}
|
||||
|
||||
/// The callable actionlist, to be used in conjunction with lazy_static
|
||||
pub struct ActionList {
|
||||
/// Increases progress.
|
||||
/// Efficiency: 300%
|
||||
/// Success Rate: 100%
|
||||
/// Additional Effect: Efficiency of your next Synthesis action is increased by 100%
|
||||
/// Available only on the first step.
|
||||
/// Additional effect is active for five steps.
|
||||
pub muscle_memory: Action,
|
||||
/// Increases quality.
|
||||
/// Efficiency: 100%
|
||||
/// Success Rate: 100%
|
||||
/// Additional Effect: Increases Inner Quiet stack by one (up to 10)
|
||||
/// Availabe only on the first step.
|
||||
pub reflect: Action,
|
||||
/// Increases progress.
|
||||
/// Efficiency: 120%
|
||||
/// Success Rate: 100%
|
||||
pub basic_synthesis: Action,
|
||||
/// Increases progress.
|
||||
/// Efficiency: 120%
|
||||
/// Success Rate: 100%
|
||||
pub careful_synthesis: Action,
|
||||
/// Increases progress at greater cost to durability.
|
||||
/// Efficiency decreases by half when durability is below durability cost.
|
||||
/// Efficiency: 300%
|
||||
/// Success Rate: 100%
|
||||
/// Durability Cost: 20
|
||||
pub groundwork: Action,
|
||||
/// Increases progress at half the durability cost.
|
||||
/// Efficiency: 180%
|
||||
/// Success Rate: 100%
|
||||
/// Unavailable when Waste Not or Waste Not II is active.
|
||||
pub prudent_synthesis: Action,
|
||||
/// Increases both progress and quality.
|
||||
/// Efficiency: 100%
|
||||
/// Success Rate: 100%
|
||||
pub delicate_synthesis: Action,
|
||||
/// Increases quality.
|
||||
/// Efficiency: 100%
|
||||
/// Success Rate: 100%
|
||||
pub basic_touch: Action,
|
||||
/// Increases quality.
|
||||
/// Efficiency: 125%
|
||||
/// Success Rate: 100%
|
||||
/// Combo action: Basic Touch
|
||||
/// Combo bonus: CP cost reduced to 18
|
||||
pub standard_touch: Action,
|
||||
/// Increases quality. Inner Quiet effect ends upon use.
|
||||
/// Efficiency: 100% plus 20% for each count of your Inner Quiet stack, up to a maximum of 300%
|
||||
/// Success Rate: 100%
|
||||
/// Requires at least one stack of Inner Quiet.
|
||||
pub byregot_blessing: Action,
|
||||
/// Increases quality at half the durability cost.
|
||||
/// Efficiency: 100%
|
||||
/// Success Rate: 100%
|
||||
/// Unavailable when Waste Not or Waste Not II are active.
|
||||
pub prudent_touch: Action,
|
||||
/// Increases quality at a greater cost to durability.
|
||||
/// Additional Effect: Increases Inner Quiet stack by one (up to 11)
|
||||
/// Efficiency: 200%
|
||||
/// Success Rate: 100%
|
||||
/// Durability Cost: 20
|
||||
pub preparatory_touch: Action,
|
||||
/// Increases quality.
|
||||
/// Efficiency: 150%
|
||||
/// Success Rate: 100%
|
||||
/// Combo action: Standard Touch
|
||||
/// Combo bonus: CP cost reduced to 18
|
||||
pub advanced_touch: Action,
|
||||
/// Increases quality at no cost to durability.
|
||||
/// Efficiency: 100%
|
||||
/// Success Rate: 100%
|
||||
/// Available only when Inner Quiet stack size is 10.
|
||||
pub trained_finesse: Action,
|
||||
/// Restores item durability by 30.
|
||||
pub masters_mend: Action,
|
||||
|
||||
// Restores item durability by 60.
|
||||
// pub masters_mend_2: Action,
|
||||
|
||||
/// Reduces loss of durability by 50% for the next four steps.
|
||||
pub waste_not: Action,
|
||||
/// Reduces loss of durability by 50% for the next eight steps.
|
||||
pub waste_not_ii: Action,
|
||||
/// Restores 5 points of durability after each step for the next eight steps.
|
||||
pub manipulation: Action,
|
||||
/// Increases efficiency of Synthesis actions by 50% for the next four steps.
|
||||
pub veneration: Action,
|
||||
/// Increases the efficiency of next Touch action by 100%.
|
||||
/// Effect active for three steps.
|
||||
pub great_strides: Action,
|
||||
/// Increases efficiency of Touch actions by 50% for the next four steps.
|
||||
pub innovation: Action,
|
||||
|
||||
// Do nothing for one step.
|
||||
//pub observe: Action,
|
||||
// Increases progress.
|
||||
// Efficiency: 200%
|
||||
// Success Rate: 50%
|
||||
// Combo Action: Observe
|
||||
// Combo Bonus: Increases success rate to 100%
|
||||
//pub focused_synthesis: Action,
|
||||
}
|
||||
|
||||
/// Create all base actions as a default (for lazy_static)
|
||||
impl Default for ActionList {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
|
@ -300,5 +453,6 @@ impl Default for ActionList {
|
|||
}
|
||||
|
||||
lazy_static! {
|
||||
/// Initialize a static pseudo &Craft: ACTIONS
|
||||
pub static ref ACTIONS: ActionList = ActionList::default();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,64 @@
|
|||
// #![warn(missing_docs,unsafe_code,unstable_features,)]
|
||||
// #![feature(no_coverage)]
|
||||
//! # Solver bin for FFXIV Crafting in Rust
|
||||
//!
|
||||
//! This project strives to provide a fast, accurate and reliable way to craft
|
||||
//! in FFXIV and obtain HQ results
|
||||
//!
|
||||
//! This project also provides bindings for python to allow hooking it to any form of better GUI/CLI
|
||||
//!
|
||||
//! The project is (for now) self hosted and hosted on [Github](https://github.com/Dandaedre/xiv_csolver)
|
||||
//!
|
||||
//! ## Getting started
|
||||
//!
|
||||
//! ### Developpement
|
||||
//!
|
||||
//! To setup the whole developpement environement it is recommended to use cargo-make
|
||||
//!
|
||||
//! Doing so will allow you custom commands to
|
||||
//!
|
||||
//! ```sh
|
||||
//! cargo make rebuild
|
||||
//! ```
|
||||
//! To rebuild the whole project
|
||||
//!
|
||||
//! ```sh
|
||||
//! cargo make release
|
||||
//! ```
|
||||
//! To generate the release files, bins and libs, pakage them and make them ready to release
|
||||
//!
|
||||
//!
|
||||
//! It is really recommanded to setup a venv to handle the python developpement
|
||||
//!
|
||||
//! ### Features
|
||||
//!
|
||||
//! Use these by running `cargo run/build --features <name of feature>`
|
||||
//!
|
||||
//! - ``no_python`` : Dont build the lib & python bindings (WIP, not fully implemented)
|
||||
//! - ``fast`` : Don't allow some under-optimisation to run (saving global run-time)
|
||||
//! - ``verbose`` : Allow for more debug messages (note that -v(vv) must still be passed to activate them)
|
||||
//!
|
||||
//! ## Regenerating the API Bindings
|
||||
//!
|
||||
//! The python bindings are generated using maturin
|
||||
//!
|
||||
//! ```sh
|
||||
//! cargo install maturin
|
||||
//! maturin develop
|
||||
//! ```
|
||||
//!
|
||||
//! ## Contributing
|
||||
//!
|
||||
//! All form of contributions are welcome !
|
||||
//!
|
||||
//! While this project was originnaly a collab and didn't strive to encompass every need
|
||||
//! of a modern FFXIV crafter, more polish and finish is always welcome.
|
||||
//!
|
||||
//! ## Licence
|
||||
//!
|
||||
//! The original code was released without a licence by [RikaKagurasaka](https://github.com/RikaKagurasaka/xiv_craft_solver)
|
||||
//!
|
||||
//! All this fork's code is released under [Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
||||
#![warn(missing_docs)]
|
||||
|
||||
use clap::Parser;
|
||||
use std::time::Instant;
|
||||
|
|
|
|||
40
src/craft.rs
40
src/craft.rs
|
|
@ -1,24 +1,48 @@
|
|||
//! Module containing everything to create a craft and all methods to get the current state of the craft
|
||||
//!
|
||||
//! A craft represent the state of the recipe with a vector of actions applied to it.
|
||||
//! Applying actions to it will make the craft progress, while branching and trying other actions
|
||||
//! will be done by cloning
|
||||
//!
|
||||
|
||||
use crate::action::Action;
|
||||
use crate::specs::{Buff, BuffState, Recipe, Stats, Success};
|
||||
use crate::Parameters;
|
||||
use std::fmt::{Debug, Display, Formatter};
|
||||
|
||||
/// The craft structure, note that there is no standard way of backtracking
|
||||
/// and a traditional branching method is applied when solving.
|
||||
#[derive(Clone)]
|
||||
pub struct Craft<'a> {
|
||||
/// The recipe used, contains all needed information on the difficulty and target
|
||||
pub recipe: Recipe,
|
||||
/// The stats of the crafter
|
||||
pub stats: Stats,
|
||||
/// The buffs currently running
|
||||
pub buffs: BuffState,
|
||||
/// The step count, aka number of steps done from the beggining of the craft
|
||||
pub step_count: u32,
|
||||
/// The remaining durability
|
||||
pub durability: i32,
|
||||
/// The current progression
|
||||
pub progression: u32,
|
||||
/// The current quality
|
||||
pub quality: u32,
|
||||
/// The cp currently remaining
|
||||
pub cp: i32,
|
||||
/// Wether the craft has succeded, is pending sucess, or failed
|
||||
pub success: Success,
|
||||
/// The vector of action already applied, structs are used for the vector since
|
||||
/// static references are used and therefore take no additional memory at runtime
|
||||
pub actions: Vec<&'a Action>,
|
||||
/// The parameters used for the craft
|
||||
/// TODO: The usage of a non reference is quite an oversight and should be changed ASAP
|
||||
pub args: Parameters,
|
||||
}
|
||||
|
||||
impl<'a> Craft<'a> {
|
||||
/// Create a new craft with a recipe, stats and parameters
|
||||
///
|
||||
pub fn new(recipe: Recipe, stats: Stats, params: Parameters) -> Craft<'a> {
|
||||
Self {
|
||||
recipe,
|
||||
|
|
@ -35,13 +59,18 @@ impl<'a> Craft<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// How much progression will be done by an action with 100 efficiency and no buffs
|
||||
/// This function is mainly used to know wether or not the craft will finish in
|
||||
/// 1, 1.2 or 2.0 actions.
|
||||
pub fn get_base_progression(&self) -> u32 {
|
||||
let base_value = (self.stats.craftsmanship as f64 / 10.0)
|
||||
/ (self.recipe.progress_divider as f64 / 100.0)
|
||||
+ 2.0;
|
||||
(base_value * (self.recipe.progress_modifier as f64 / 100.0) as f64).floor() as u32
|
||||
}
|
||||
|
||||
/// How much quality will the crafter generate with one action with 100 efficiency and no buffs
|
||||
/// This function is usually called by [`run_action`](crate::craft::Craft::run_action)
|
||||
/// wich will then apply all needed buff and progress the craft
|
||||
pub fn get_base_quality(&self) -> u32 {
|
||||
let base_value = (self.stats.control as f64 / 10.0)
|
||||
/ (self.recipe.quality_divider as f64 / 100.0)
|
||||
|
|
@ -49,6 +78,15 @@ impl<'a> Craft<'a> {
|
|||
(base_value * (self.recipe.quality_modifier as f64 / 100.0) as f64).floor() as u32
|
||||
}
|
||||
|
||||
/// Add an action to the current craft
|
||||
/// This method will:
|
||||
/// - Check wether the action can be used
|
||||
/// - Increment the step count
|
||||
/// - Decrease cp
|
||||
/// - Decrease or increase durability
|
||||
/// - Increase progression
|
||||
/// - "Tick" buffs (substract 1 from their remaining time) and remove them if consumed
|
||||
/// - Add the used action to the vec of actions used
|
||||
pub fn run_action(&mut self, action: &'a Action) -> &mut Craft<'a> {
|
||||
if !action.can_use(self) {
|
||||
self.success = Success::Failure;
|
||||
|
|
|
|||
129
src/io.rs
129
src/io.rs
|
|
@ -1,3 +1,9 @@
|
|||
//! The main IO module
|
||||
//! For now it contains the python bindings, the Args bindings (for clap) and the struct
|
||||
//! needed to hold all parameters needed at runtime
|
||||
//!
|
||||
//! Moving the bindings and making them non mandatory is a WIP
|
||||
|
||||
use crate::Craft;
|
||||
use clap::Parser;
|
||||
use core::fmt::Display;
|
||||
|
|
@ -5,15 +11,27 @@ use core::fmt::Display;
|
|||
// #[cfg(not(feature = "no_python"))]
|
||||
use pyo3::prelude::*;
|
||||
|
||||
/// The parameters needed at runtime, used since Args cannot easily be passed to python
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Parameters {
|
||||
/// The number of threads to use
|
||||
/// TODO: Add an auto feature to guess threads depending on architecture and action pool
|
||||
pub threads: usize,
|
||||
/// The level of verbosity from 0 to 3
|
||||
pub verbose: u8,
|
||||
/// How many steps are allowed for finishing the craft
|
||||
/// TODO: Be a little smarted about this approach and stop guessing if enough starters are found
|
||||
/// and continue guessing if more are needed
|
||||
pub depth: u32,
|
||||
/// Wether to try every mesure to finish the craft or not
|
||||
pub desperate: bool,
|
||||
/// How early byregot will be used, setting it too low high miss easy solutions (for small crafts)
|
||||
/// but setting it too low will have the solver try byregot way too often adding many useless crafts
|
||||
/// in the pool of solutions
|
||||
pub byregot_step: u8,
|
||||
}
|
||||
|
||||
/// The args passed to the CLI, used by clap to generate a nice argument parser
|
||||
#[derive(Parser, Debug, Clone)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
pub struct Args {
|
||||
|
|
@ -52,34 +70,48 @@ pub struct Args {
|
|||
|
||||
/// A final stripped down version of a craft
|
||||
/// used for final print and talking with python
|
||||
/// TODO: Half of these parameter are unique and SHOULD NOT be replicated on every solution
|
||||
#[derive(Debug)]
|
||||
#[pyclass]
|
||||
pub struct SolverResult {
|
||||
/// The number of steps this particular craft takes
|
||||
#[pyo3(get)]
|
||||
pub steps: u32,
|
||||
/// The quality obtained at the end of the craft (absolute value)
|
||||
#[pyo3(get)]
|
||||
pub quality: u32,
|
||||
/// The amount of progression obtained at the end of the craft (absolute value)
|
||||
#[pyo3(get)]
|
||||
pub progression: u32,
|
||||
/// The remaining durability at the end of this craft
|
||||
#[pyo3(get)]
|
||||
pub durability: i32,
|
||||
/// The remaining crafting points at the end of this craft
|
||||
#[pyo3(get)]
|
||||
pub cp: i32,
|
||||
/// The total amount of crafting points the crafter had available (Deprecated)
|
||||
#[pyo3(get)]
|
||||
pub total_cp: u32,
|
||||
/// The total amount of progression needed to finish the craft (Deprecated)
|
||||
#[pyo3(get)]
|
||||
pub total_progression: u32,
|
||||
/// The total quality needed to make this craft 100% HQ (Deprecated)
|
||||
#[pyo3(get)]
|
||||
pub total_quality: u32,
|
||||
/// The total durability for this craft (Deprecated)
|
||||
#[pyo3(get)]
|
||||
pub total_durability: u32,
|
||||
/// The list of actions, as a string
|
||||
#[pyo3(get)]
|
||||
pub actions: Vec<String>,
|
||||
/// The amount of solutions found during the first step of the solving (Used for debug) (Deprecated)
|
||||
#[pyo3(get)]
|
||||
pub step1_solutions: usize,
|
||||
/// The amount of solutions found at the end of the second step of solving (Used for debug) (Deprecated)
|
||||
#[pyo3(get)]
|
||||
pub step2_solutions: usize,
|
||||
#[pyo3(get)]
|
||||
/// Wether a 100% HQ solution was found (Deprecated)
|
||||
pub found_100_percent: bool,
|
||||
}
|
||||
|
||||
|
|
@ -90,8 +122,9 @@ impl Display for SolverResult {
|
|||
}
|
||||
}
|
||||
|
||||
//#[pymethods]
|
||||
impl SolverResult {
|
||||
/// Create a SolverResult from a solution
|
||||
/// Using this returns a solution, usable by Python
|
||||
pub fn from_craft(
|
||||
craft: &Craft,
|
||||
step1_solutions: usize,
|
||||
|
|
@ -103,6 +136,7 @@ impl SolverResult {
|
|||
.iter()
|
||||
.map(|action| format!("{}", action.short_name))
|
||||
.collect::<Vec<String>>();
|
||||
// Todo: Stop adding these by hand
|
||||
let arg = (craft.recipe.progress as f32 - craft.progression as f32)
|
||||
/ craft.get_base_progression() as f32;
|
||||
if 0.0 < arg && arg < 1.2 {
|
||||
|
|
@ -135,6 +169,12 @@ impl SolverResult {
|
|||
|
||||
#[pymethods]
|
||||
impl SolverResult {
|
||||
/// Default method to create an empty solution, only used for debug purposes
|
||||
/// to test wether the import worked
|
||||
/// ```py
|
||||
/// import xiv_csolver_lib
|
||||
/// print(xiv_csolver_lib.default())
|
||||
/// ```
|
||||
#[staticmethod]
|
||||
pub fn default() -> Self {
|
||||
Self {
|
||||
|
|
@ -154,6 +194,8 @@ impl SolverResult {
|
|||
}
|
||||
}
|
||||
|
||||
/// Implement a pretty_print method
|
||||
/// Mainly used for debug purposes
|
||||
pub fn pretty_print(&self) {
|
||||
println!(
|
||||
"Quality: [{}/{}] | Durability: [{}/{}] | Cp : [{}/{}] | Steps : {}",
|
||||
|
|
@ -170,6 +212,7 @@ impl SolverResult {
|
|||
}
|
||||
|
||||
impl Parameters {
|
||||
/// Create parameters from the arguments parsed by clap
|
||||
pub fn from_args(args: &Args) -> Self {
|
||||
Self {
|
||||
depth: if args.desperate { 11 } else { 8 },
|
||||
|
|
@ -203,10 +246,37 @@ pub fn test_result() -> SolverResult {
|
|||
#[cfg(not(feature = "no_python"))]
|
||||
use crate::{solve_craft, Recipe, Stats};
|
||||
|
||||
/// Solve a craft from parameters given by python
|
||||
/// The values are all obtained by a `&PyAny`, wich must guaranty that several attributes are
|
||||
/// accesible by `__getattr__`
|
||||
///
|
||||
/// ```py
|
||||
/// import xiv_craft_solver, rich
|
||||
///
|
||||
/// class FeedingClass:
|
||||
/// durability = 70
|
||||
/// progress = 3900
|
||||
/// quality = 10920
|
||||
/// progress_divider = 130
|
||||
/// quality_divider = 115
|
||||
/// progress_modifier = 80
|
||||
/// quality_modifier = 70
|
||||
/// craftsmanship = 4041
|
||||
/// control = 3959
|
||||
/// max_cp = 602
|
||||
/// # Config
|
||||
/// depth = 10
|
||||
/// byregot_step = 10
|
||||
/// desperate = False
|
||||
/// threads = 8
|
||||
/// verbose = 0
|
||||
/// crafting_feeder = FeedingClass()
|
||||
/// rich.inspect(xiv_csolver_lib.solve_from_python(crafting_feeder))
|
||||
/// ```
|
||||
#[cfg(not(feature = "no_python"))]
|
||||
#[pyfunction]
|
||||
pub fn solve_from_python(values: &PyAny) -> PyResult<Option<Vec<SolverResult>>> {
|
||||
// // Create Recipe
|
||||
// Create Recipe
|
||||
let recipe = Recipe {
|
||||
durability: values.getattr("durability")?.extract()?,
|
||||
progress: values.getattr("progress")?.extract()?,
|
||||
|
|
@ -242,8 +312,8 @@ pub fn solve_from_python(values: &PyAny) -> PyResult<Option<Vec<SolverResult>>>
|
|||
mod tests {
|
||||
use crate::io::Args;
|
||||
use crate::{Parameters, SolverResult};
|
||||
use pretty_assertions::{assert_eq, assert_ne};
|
||||
use clap::Parser;
|
||||
use pretty_assertions::{assert_eq, assert_ne};
|
||||
|
||||
impl PartialEq for Parameters {
|
||||
fn eq(&self, rhs: &Parameters) -> bool {
|
||||
|
|
@ -297,30 +367,45 @@ mod tests {
|
|||
verbose: 1,
|
||||
};
|
||||
let a2 = a.clone();
|
||||
println!("{:?}",a2);
|
||||
println!("{:?}", a2);
|
||||
// Test Custom recipe
|
||||
let a3 = Args::parse_from(["ultraman","-r", "recipe","-c","dan","-f","bigfile.toml","-d","45","-t","4","-D","-l","-vvv"]);
|
||||
let a3 = Args::parse_from([
|
||||
"ultraman",
|
||||
"-r",
|
||||
"recipe",
|
||||
"-c",
|
||||
"dan",
|
||||
"-f",
|
||||
"bigfile.toml",
|
||||
"-d",
|
||||
"45",
|
||||
"-t",
|
||||
"4",
|
||||
"-D",
|
||||
"-l",
|
||||
"-vvv",
|
||||
]);
|
||||
let _ = Args::parse_from(["-V"]);
|
||||
let _ = Args::parse_from(["-H"]);
|
||||
assert_eq!(a3.recipe_name,"recipe");
|
||||
assert_eq!(a3.character_name,"dan");
|
||||
assert_eq!(a3.file_name,"bigfile.toml");
|
||||
assert_eq!(a3.verbose,3);
|
||||
assert_eq!(a3.depth,45);
|
||||
assert_eq!(a3.threads,4);
|
||||
assert_eq!(a3.desperate,true);
|
||||
assert_eq!(a3.long,true);
|
||||
assert_eq!(a3.recipe_name, "recipe");
|
||||
assert_eq!(a3.character_name, "dan");
|
||||
assert_eq!(a3.file_name, "bigfile.toml");
|
||||
assert_eq!(a3.verbose, 3);
|
||||
assert_eq!(a3.depth, 45);
|
||||
assert_eq!(a3.threads, 4);
|
||||
assert_eq!(a3.desperate, true);
|
||||
assert_eq!(a3.long, true);
|
||||
|
||||
// Test default parameters
|
||||
let a4 = Args::parse_from(["bobGZ"]);
|
||||
assert_eq!(a4.recipe_name,"default_recipe");
|
||||
assert_eq!(a4.character_name,"default_character");
|
||||
assert_eq!(a4.file_name,"craft.toml");
|
||||
assert_eq!(a4.verbose,0);
|
||||
assert_eq!(a4.depth,8);
|
||||
assert_eq!(a4.threads,4);
|
||||
assert_eq!(a4.desperate,false);
|
||||
assert_eq!(a4.long,false);
|
||||
let a4 = Args::parse_from(["bobGZ"]);
|
||||
assert_eq!(a4.recipe_name, "default_recipe");
|
||||
assert_eq!(a4.character_name, "default_character");
|
||||
assert_eq!(a4.file_name, "craft.toml");
|
||||
assert_eq!(a4.verbose, 0);
|
||||
assert_eq!(a4.depth, 8);
|
||||
assert_eq!(a4.threads, 4);
|
||||
assert_eq!(a4.desperate, false);
|
||||
assert_eq!(a4.long, false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
64
src/lib.rs
64
src/lib.rs
|
|
@ -1,3 +1,65 @@
|
|||
//! # Solver bin for FFXIV Crafting in Rust
|
||||
//!
|
||||
//! This project strives to provide a fast, accurate and reliable way to craft
|
||||
//! in FFXIV and obtain HQ results
|
||||
//!
|
||||
//! This project also provides bindings for python to allow hooking it to any form of better GUI/CLI
|
||||
//!
|
||||
//! The project is (for now) self hosted and hosted on [Github](https://github.com/Dandaedre/xiv_csolver)
|
||||
//!
|
||||
//! ## Getting started
|
||||
//!
|
||||
//! ### Developpement
|
||||
//!
|
||||
//! To setup the whole developpement environement it is recommended to use cargo-make
|
||||
//!
|
||||
//! Doing so will allow you custom commands to
|
||||
//!
|
||||
//! ```sh
|
||||
//! cargo make rebuild
|
||||
//! ```
|
||||
//! To rebuild the whole project
|
||||
//!
|
||||
//! ```sh
|
||||
//! cargo make release
|
||||
//! ```
|
||||
//! To generate the release files, bins and libs, pakage them and make them ready to release
|
||||
//!
|
||||
//!
|
||||
//! It is really recommanded to setup a venv to handle the python developpement
|
||||
//!
|
||||
//! ### Features
|
||||
//!
|
||||
//! Use these by running `cargo run/build --features <name of feature>`
|
||||
//!
|
||||
//! - ``no_python`` : Dont build the lib & python bindings (WIP, not fully implemented)
|
||||
//! - ``fast``: Don't allow some under-optimisation to run (saving global run-time)
|
||||
//! - ``verbose`` : Allow for more debug messages (note that -v(vv) must still be passed to activate them)
|
||||
//!
|
||||
//! ## Regenerating the API Bindings
|
||||
//!
|
||||
//! The python bindings are generated using maturin
|
||||
//!
|
||||
//! ```sh
|
||||
//! cargo install maturin
|
||||
//! maturin develop
|
||||
//! ```
|
||||
//!
|
||||
//! ## Contributing
|
||||
//!
|
||||
//! All form of contributions are welcome !
|
||||
//!
|
||||
//! While this project was originnaly a collab and didn't strive to encompass every need
|
||||
//! of a modern FFXIV crafter, more polish and finish is always welcome.
|
||||
//!
|
||||
//! ## Licence
|
||||
//!
|
||||
//! The original code was released without a licence by [RikaKagurasaka](https://github.com/RikaKagurasaka/xiv_craft_solver)
|
||||
//!
|
||||
//! All this fork's code is released under [Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
||||
#![warn(missing_docs)]
|
||||
|
||||
use crate::io::SolverResult;
|
||||
use crate::{
|
||||
craft::Craft,
|
||||
|
|
@ -11,7 +73,7 @@ pub mod action;
|
|||
pub mod craft;
|
||||
pub mod io;
|
||||
mod solver;
|
||||
mod specs;
|
||||
pub mod specs;
|
||||
|
||||
/// Solve the craft with given arguments, this functions calls threads and must own it's values
|
||||
pub fn solve_craft<'a>(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
//! This modules instanciate all the tools needed to load and use the solver
|
||||
|
||||
use std::fmt::Debug;
|
||||
use strum_macros::EnumIter;
|
||||
|
||||
/// The recipe to craft
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Recipe {
|
||||
/// The craft durability (also called solidity)
|
||||
pub durability: u32,
|
||||
pub progress: u32,
|
||||
pub quality: u32,
|
||||
|
|
|
|||
Reference in New Issue