Release 0.1.7 #26
|
|
@ -7,6 +7,8 @@ expected_values.md
|
|||
releases/*
|
||||
.whl
|
||||
pyinstaller_log.txt
|
||||
llvm/*
|
||||
/coverage/*
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
|
|
|
|||
|
|
@ -63,6 +63,22 @@ dependencies = [
|
|||
"os_str_bytes",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ctor"
|
||||
version = "0.1.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "diff"
|
||||
version = "0.1.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.2.8"
|
||||
|
|
@ -192,6 +208,15 @@ version = "6.4.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
|
||||
|
||||
[[package]]
|
||||
name = "output_vt100"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.12.1"
|
||||
|
|
@ -215,6 +240,18 @@ dependencies = [
|
|||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pretty_assertions"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a25e9bcb20aa780fd0bb16b72403a9064d6b3f22f026946029acb941a50af755"
|
||||
dependencies = [
|
||||
"ctor",
|
||||
"diff",
|
||||
"output_vt100",
|
||||
"yansi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error"
|
||||
version = "1.0.4"
|
||||
|
|
@ -552,14 +589,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"
|
||||
|
||||
[[package]]
|
||||
name = "xiv_craft_solver"
|
||||
version = "0.1.4"
|
||||
name = "xiv_csolver"
|
||||
version = "0.1.7"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"lazy_static",
|
||||
"pretty_assertions",
|
||||
"pyo3",
|
||||
"strum",
|
||||
"strum_macros",
|
||||
"threadpool",
|
||||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yansi"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"
|
||||
|
|
|
|||
24
Cargo.toml
|
|
@ -1,13 +1,13 @@
|
|||
[package]
|
||||
name = "xiv_craft_solver"
|
||||
version = "0.1.5"
|
||||
name = "xiv_csolver"
|
||||
version = "0.1.7"
|
||||
edition = "2021"
|
||||
authors = ["谭俊健","Dandaedre","Vkyfox"]
|
||||
description = "Small XIV solver library in rust, with python and rust bindings"
|
||||
homepage = "https://proxy.dandaedre.com/gitea/Dandaedre/rcraft_solver"
|
||||
documentation = "https://proxy.dandaedre.com/gitea/Dandaedre/rcraft_solver"
|
||||
repository = "https://proxy.dandaedre.com/gitea/Dandaedre/rcraft_solver.git"
|
||||
license = "MIT OR Apache-2.0"
|
||||
homepage = "https://proxy.dandaedre.com/gitea/Dandaedre/xiv_csolver"
|
||||
documentation = "https://proxy.dandaedre.com/gitea/Dandaedre/xiv_csolver"
|
||||
repository = "https://proxy.dandaedre.com/gitea/Dandaedre/xiv_csolver.git"
|
||||
license = "Apache-2.0"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
|
@ -27,6 +27,9 @@ pyo3 = { version = "0.18.0", features = ["extension-module"] }
|
|||
# [build]
|
||||
# target = ["x86_64-unknown-linux-gnu", "x86_64-unknown-windows-gnu"]
|
||||
|
||||
[dev-dependencies]
|
||||
pretty_assertions = "1"
|
||||
|
||||
[profile.release]
|
||||
panic = 'abort'
|
||||
opt-level = 3
|
||||
|
|
@ -39,13 +42,10 @@ no_python = [] # Removes the python bindings
|
|||
fast = [] # Remove some under optimisations that try to find other routes
|
||||
|
||||
[lib]
|
||||
name = "xiv_craft_solver" # Pending rename ffcraft_solver_lib
|
||||
name = "xiv_csolver_lib"
|
||||
path = "src/lib.rs"
|
||||
crate-type = ["cdylib","rlib"]
|
||||
|
||||
[[bin]]
|
||||
name = "ffcraft_solver_cli"
|
||||
path = "src/bin/ffcraft.rs"
|
||||
|
||||
[tool.maturin]
|
||||
python-source = "python"
|
||||
name = "xiv_csolver_cli"
|
||||
path = "src/bin/xiv_csolver.rs"
|
||||
|
|
@ -14,8 +14,8 @@ dependencies = [
|
|||
script_runner="@shell"
|
||||
ignore_errors = true
|
||||
script = [
|
||||
"twine upload releases/ffcraft_solver*.whl --repository gitea",
|
||||
"twine upload releases/xiv_craft_solver*.whl --repository gitea",
|
||||
"twine upload releases/xiv_csolver*.whl --repository gitea",
|
||||
"twine upload releases/xiv_csolver_lib*.whl --repository gitea",
|
||||
]
|
||||
|
||||
[tasks.format]
|
||||
|
|
@ -23,6 +23,16 @@ install_crate = "rustfmt"
|
|||
command = "cargo"
|
||||
args = ["fmt", "--", "--emit=files"]
|
||||
|
||||
[tasks.testcov]
|
||||
script_runner = "@shell"
|
||||
ignore_errors = true
|
||||
script = [
|
||||
"mkdir -p coverage",
|
||||
"mkdir -p coverage/html",
|
||||
"CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' LLVM_PROFILE_FILE='llvm/cargo-test-%p-%m.profraw' cargo test",
|
||||
"grcov . --binary-path ./target/debug/deps/ -s . -t html --branch --ignore-not-existing --ignore '../*' --ignore '/*' -o coverage/html/"
|
||||
]
|
||||
|
||||
[tasks.clean]
|
||||
command = "cargo"
|
||||
args = ["clean"]
|
||||
|
|
@ -46,8 +56,8 @@ script_runner = "@shell"
|
|||
script = '''
|
||||
mkdir -p releases # Add version as an arg and things
|
||||
cp target/wheels/*.whl releases/
|
||||
zip releases/ffcraft_solver_cli.zip -j target/release/ffcraft_solver_cli craft.toml -j target/release/libxiv_craft_solver.so
|
||||
cd python/dist/ && zip ../../releases/ffcraft_solver_gui.zip -r ffcraft_solver_gui_linux/
|
||||
zip releases/xiv_csolver_cli_linux.zip -j target/release/xiv_csolver_cli craft.toml -j target/release/libxiv_craft_solver.so
|
||||
cd python/dist/ && zip ../../releases/xiv_csolver_gui_linux.zip -r xiv_csolver_gui_linux/
|
||||
'''
|
||||
|
||||
[tasks.zip_win]
|
||||
|
|
@ -55,8 +65,8 @@ script_runner = "@shell"
|
|||
script = '''
|
||||
mkdir -p releases # Add version as an arg and things
|
||||
cp target/wheels/*.whl releases/
|
||||
tar acvf releases/ff_craft_solver_cli_win.zip .\craft.toml -C .\target\release\ ffcraft_solver_cli.exe libxiv_craft_solver.d
|
||||
tar acvf releases/ff_craft_solver_gui_win.zip -C .\python\dist\ .\ffcraft_solver_gui_win\*
|
||||
tar acvf releases/xiv_csolver_cli_win.zip .\craft.toml -C .\target\release\ xiv_csolver_cli.exe libxiv_craft_solver.d
|
||||
tar acvf releases/xiv_csolver_gui_win.zip -C .\python\dist\ .\xiv_csolver_gui_win\*
|
||||
'''
|
||||
|
||||
[tasks.pip]
|
||||
|
|
@ -78,13 +88,14 @@ linux_alias = "linux_pyinstaller"
|
|||
script_runner = "@shell"
|
||||
script = '''
|
||||
cd python
|
||||
pyinstaller src/ffcraft_solver/__main__.py -i "src/ffcraft_solver/ressources/ffcraft_solver.ico" --add-data "src/ffcraft_solver/configs/:ffcraft_solver/configs" --add-data "src/ffcraft_solver/ressources/:ffcraft_solver/ressources" --name ffcraft_solver_gui_linux -y
|
||||
pyinstaller src/xiv_csolver/__main__.py -i "src/xiv_csolver/ressources/xiv_csolver.ico" --add-data "src/xiv_csolver/configs/:xiv_csolver/configs" --add-data "src/xiv_csolver/ressources/:xiv_csolver/ressources" --name xiv_csolver_gui_linux -y
|
||||
'''
|
||||
|
||||
[tasks.windows_pyinstaller]
|
||||
script_runner = "@shell"
|
||||
script = '''
|
||||
cd python && pyinstaller src\ffcraft_solver\__main__.py --add-data "src\ffcraft_solver\configs\;ffcraft_solver\configs" --add-data "src\ffcraft_solver\ressources\;ffcraft_solver\ressources" --name ffcraft_solver_gui_win -y
|
||||
cd python
|
||||
pyinstaller src\xiv_csolver\__main__.py -i "src/xiv_csolver/ressources/xiv_csolver.ico" --add-data "src\xiv_csolver\configs\;xiv_csolver\configs" --add-data "src\xiv_csolver\ressources\;xiv_csolver\ressources" --name xiv_csolver_gui_win -y
|
||||
'''
|
||||
|
||||
[tasks.build]
|
||||
|
|
@ -100,6 +111,8 @@ args = ["develop", "--release"]
|
|||
command = "maturin"
|
||||
args = ["build", "--release"]
|
||||
|
||||
[tasks.rebuild]
|
||||
dependencies = ["clean","build","maturin","pip"]
|
||||
|
||||
[tasks.rust]
|
||||
dependencies = ["build","maturin"]
|
||||
19
README.md
|
|
@ -1,9 +1,12 @@
|
|||
# xiv_craft_solver
|
||||
# xiv_csolver
|
||||
A rust program for solving FFXIV craft recipe.
|
||||
|
||||
Originaly written by [RikaKagurasaka](https://github.com/RikaKagurasaka/xiv_craft_solver),
|
||||
it now is widely improved and provides python bindings for a GUI (or anything else really)
|
||||
|
||||
|
||||

|
||||
|
||||
### Basic RUST CLI Usage
|
||||
Everything is done through the regular cargo interface
|
||||
1. Download the latest release.
|
||||
|
|
@ -19,7 +22,7 @@ When building the CLI invocation is done with the following parameters
|
|||
```
|
||||
Small XIV solver library in rust, with python and rust bindings
|
||||
|
||||
Usage: ffcraft [OPTIONS]
|
||||
Usage: xiv_csolver_cli [OPTIONS]
|
||||
|
||||
Options:
|
||||
-r, --recipe-name <RECIPE_NAME>
|
||||
|
|
@ -43,7 +46,13 @@ Options:
|
|||
-V, --version
|
||||
Print version
|
||||
```
|
||||
|
||||
## Developpement
|
||||
Please remember to set and use a venv before building
|
||||
While not mandatory, using ``cargo-make`` will provide you with the commands:
|
||||
- cargo make rebuild (rebuilding both the rust and pip bindings)
|
||||
- cargo make release (rebuilding and bundling the executables (for your os)) in a releases folder
|
||||
|
||||
### Rust
|
||||
Everything is located in the root & src.
|
||||
You can build the program (CLI) with cargo build the following features are available
|
||||
|
|
@ -51,8 +60,9 @@ You can build the program (CLI) with cargo build the following features are avai
|
|||
- The ``no_python`` will not build the lib (WIP, not fully implemented)
|
||||
- The ``fast`` feature will not allow some under-optimisation to run (saving global run-time)
|
||||
- The ``verbose`` feature will allow even more debug messages (They might not be shown depending on the verbosity level hoever)
|
||||
|
||||
#### Maturin
|
||||
To build the python module, run ``maturin develop`` or ``maturin build`` then ``maturin install``
|
||||
To build the python module, run either ``maturin develop`` or ``maturin build`` then ``maturin install``
|
||||
|
||||
### Python
|
||||
#### Developping the GUI
|
||||
|
|
@ -60,10 +70,9 @@ To build the python module, run ``maturin develop`` or ``maturin build`` then ``
|
|||
1. Go to the ``python`` directory
|
||||
2. Install the dev dependencies ``pip install -r requirements_dev.txt``
|
||||
3. Install the project (in editable mode) ``pip install -e .``
|
||||
4. Invoke the project (from anywhere) ``python -m ffcraft_solver``
|
||||
4. Invoke the project (from anywhere) ``python -m xiv_csolver``
|
||||
5. Edit the project and re-invoke it (no need to install / compile again)
|
||||
|
||||
|
||||
#### Rust CLI Example
|
||||
Note: The recipe data can be retrieved from a [FFXIV Crafting Optimizer](https://yyyy.games/crafter/#/simulator)
|
||||
with checking of **Custom Recipe** after selecting the recipe.
|
||||
|
|
|
|||
9
Todo.md
|
|
@ -5,20 +5,23 @@
|
|||
✅ (GUI) Make macros work
|
||||
🟩 (GUI) Visual feedback when pressing solve
|
||||
🟩 (GUI) Update on the Quality %
|
||||
🟩 (GUI) Ability to save
|
||||
✅ (GUI) Ability to save
|
||||
✅ (GUI) Make the logging work
|
||||
🟩 (PKG) Rename libs, bin, python, exe
|
||||
✅ (PKG) Rename libs, bin, python, exe
|
||||
### Important
|
||||
✅ (PKG) Have cargo-make setup for release/cleanup/build
|
||||
✅ (PKG) Merge latest pre-release for the GUI
|
||||
✅ (PKG) Have a rebuild function
|
||||
🟩 (CLI) Rework the parameters and return structs to only have one ref each
|
||||
### Features
|
||||
🟩 (GUI) Refactor code
|
||||
🟩 (GUI) Restore GUI state
|
||||
|
||||
# Roadmap
|
||||
## v1.0.0
|
||||
|
||||
### Important
|
||||
🟩 (LIB) Rust API docs
|
||||
✅ (LIB) Rust API docs
|
||||
🟩 (CLI) Accept and copy from the base recipes
|
||||
🟩 (CLI) Accept and copy pots & food
|
||||
🟩 (PKG) Have a unified toml/yaml way of registering recipes
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 22%">
|
||||
<title>coverage: 22%</title>
|
||||
<linearGradient id="s" x2="0" y2="100%">
|
||||
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
|
||||
<stop offset="1" stop-opacity=".1"/>
|
||||
</linearGradient>
|
||||
<clipPath id="r">
|
||||
<rect width="96" height="20" rx="3" fill="#fff"/>
|
||||
</clipPath>
|
||||
<g clip-path="url(#r)">
|
||||
<rect width="61" height="20" fill="#555"/>
|
||||
<rect x="61" width="35" height="20" fill="#e05d44"/>
|
||||
<rect width="96" height="20" fill="url(#s)"/>
|
||||
</g>
|
||||
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110">
|
||||
<text aria-hidden="true" x="315" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="510">coverage</text>
|
||||
<text x="315" y="140" transform="scale(.1)" fill="#fff" textLength="510">coverage</text>
|
||||
<text aria-hidden="true" x="775" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">22%</text>
|
||||
<text x="775" y="140" transform="scale(.1)" fill="#fff" textLength="250">22%</text>
|
||||
</g>
|
||||
<script xmlns=""/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
|
|
@ -0,0 +1,13 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 22%">
|
||||
<title>coverage: 22%</title>
|
||||
<g shape-rendering="crispEdges">
|
||||
<rect width="61" height="20" fill="#555"/>
|
||||
<rect x="61" width="35" height="20" fill="#e05d44"/>
|
||||
</g>
|
||||
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110">
|
||||
<text x="315" y="140" transform="scale(.1)" fill="#fff" textLength="510">coverage</text>
|
||||
<text x="775" y="140" transform="scale(.1)" fill="#fff" textLength="250">22%</text>
|
||||
</g>
|
||||
<script xmlns=""/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 712 B |
|
|
@ -0,0 +1,13 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink" width="142.5" height="28" role="img" aria-label="COVERAGE: 22%">
|
||||
<title>COVERAGE: 22%</title>
|
||||
<g shape-rendering="crispEdges">
|
||||
<rect width="91" height="28" fill="#555"/>
|
||||
<rect x="91" width="51.5" height="28" fill="#e05d44"/>
|
||||
</g>
|
||||
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="100">
|
||||
<text fill="#fff" x="455" y="175" transform="scale(.1)" textLength="670">COVERAGE</text>
|
||||
<text fill="#fff" x="1167.5" y="175" font-weight="bold" transform="scale(.1)" textLength="275">22%</text>
|
||||
</g>
|
||||
<script xmlns=""/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 739 B |
|
|
@ -0,0 +1,25 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="18" role="img" aria-label="coverage: 22%">
|
||||
<title>coverage: 22%</title>
|
||||
<linearGradient id="s" x2="0" y2="100%">
|
||||
<stop offset="0" stop-color="#fff" stop-opacity=".7"/>
|
||||
<stop offset=".1" stop-color="#aaa" stop-opacity=".1"/>
|
||||
<stop offset=".9" stop-color="#000" stop-opacity=".3"/>
|
||||
<stop offset="1" stop-color="#000" stop-opacity=".5"/>
|
||||
</linearGradient>
|
||||
<clipPath id="r">
|
||||
<rect width="96" height="18" rx="4" fill="#fff"/>
|
||||
</clipPath>
|
||||
<g clip-path="url(#r)">
|
||||
<rect width="61" height="18" fill="#555"/>
|
||||
<rect x="61" width="35" height="18" fill="#e05d44"/>
|
||||
<rect width="96" height="18" fill="url(#s)"/>
|
||||
</g>
|
||||
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110">
|
||||
<text aria-hidden="true" x="315" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="510">coverage</text>
|
||||
<text x="315" y="130" transform="scale(.1)" fill="#fff" textLength="510">coverage</text>
|
||||
<text aria-hidden="true" x="775" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">22%</text>
|
||||
<text x="775" y="130" transform="scale(.1)" fill="#fff" textLength="250">22%</text>
|
||||
</g>
|
||||
<script xmlns=""/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
|
|
@ -0,0 +1,27 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink" width="99" height="20" role="img" aria-label="Coverage: 22%">
|
||||
<title>Coverage: 22%</title>
|
||||
<style>a:hover #llink{fill:url(#b);stroke:#ccc}a:hover #rlink{fill:#4183c4}</style>
|
||||
<linearGradient id="a" x2="0" y2="100%">
|
||||
<stop offset="0" stop-color="#fcfcfc" stop-opacity="0"/>
|
||||
<stop offset="1" stop-opacity=".1"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="b" x2="0" y2="100%">
|
||||
<stop offset="0" stop-color="#ccc" stop-opacity=".1"/>
|
||||
<stop offset="1" stop-opacity=".1"/>
|
||||
</linearGradient>
|
||||
<g stroke="#d5d5d5">
|
||||
<rect stroke="none" fill="#fcfcfc" x="0.5" y="0.5" width="61" height="19" rx="2"/>
|
||||
<rect x="67.5" y="0.5" width="31" height="19" rx="2" fill="#fafafa"/>
|
||||
<rect x="67" y="7.5" width="0.5" height="5" stroke="#fafafa"/>
|
||||
<path d="M67.5 6.5 l-3 3v1 l3 3" stroke="d5d5d5" fill="#fafafa"/>
|
||||
</g>
|
||||
<g aria-hidden="true" fill="#333" text-anchor="middle" font-family="Helvetica Neue,Helvetica,Arial,sans-serif" text-rendering="geometricPrecision" font-weight="700" font-size="110px" line-height="14px">
|
||||
<rect id="llink" stroke="#d5d5d5" fill="url(#a)" x=".5" y=".5" width="61" height="19" rx="2"/>
|
||||
<text aria-hidden="true" x="305" y="150" fill="#fff" transform="scale(.1)" textLength="510">Coverage</text>
|
||||
<text x="305" y="140" transform="scale(.1)" textLength="510">Coverage</text>
|
||||
<text aria-hidden="true" x="825" y="150" fill="#fff" transform="scale(.1)" textLength="230">22%</text>
|
||||
<text id="rlink" x="825" y="140" transform="scale(.1)" textLength="230">22%</text>
|
||||
</g>
|
||||
<script xmlns=""/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.7 KiB |
|
|
@ -3,9 +3,9 @@ requires = ["maturin>=0.14,<0.15"]
|
|||
build-backend = "maturin"
|
||||
|
||||
[project] # The rust bindings
|
||||
name = "xiv_craft_solver"
|
||||
name = "xiv_csolver_lib"
|
||||
requires-python = ">=3.7"
|
||||
version = "0.1.5"
|
||||
version = "0.1.7"
|
||||
classifiers = [
|
||||
"Programming Language :: Rust",
|
||||
"Programming Language :: Python :: Implementation :: CPython",
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ classifiers =
|
|||
|
||||
[options]
|
||||
packages =
|
||||
ffcraft_solver
|
||||
ffcraft_solver.modules
|
||||
xiv_csolver
|
||||
xiv_csolver.modules
|
||||
install_requires =
|
||||
pyyaml>=6.0
|
||||
python_requires = >=3.9
|
||||
|
|
@ -21,7 +21,7 @@ zip_safe = no
|
|||
[options.packages.find]
|
||||
where =
|
||||
= src
|
||||
= src/ffcraft_solver
|
||||
= src/xiv_csolver
|
||||
|
||||
[options.extras_require]
|
||||
testing =
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@ requires = ["setuptools>=42.0", "wheel"]
|
|||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project] # The Python GUI
|
||||
name = "ffcraft_solver"
|
||||
name = "xiv_csolver"
|
||||
authors = [
|
||||
{name="Vkyfox"},
|
||||
{name="Dandaedre"},
|
||||
]
|
||||
requires-python = ">=3.7"
|
||||
version = "0.1.5"
|
||||
version = "0.1.7"
|
||||
license = {text="Mozilla Public License Version 2.0"}
|
||||
classifiers = [
|
||||
"Programming Language :: Rust",
|
||||
|
|
@ -18,7 +18,7 @@ classifiers = [
|
|||
]
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
addopts = "--cov=ffcraft_solver"
|
||||
addopts = "--cov=xiv_csolver"
|
||||
testpaths = [
|
||||
"tests",
|
||||
]
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 248 KiB |
|
Before Width: | Height: | Size: 352 KiB |
|
|
@ -1,4 +1,4 @@
|
|||
"""
|
||||
A rust program for solving FFXIV craft recipe.
|
||||
- ffcraft_solver
|
||||
- xiv_csolver
|
||||
"""
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
import time
|
||||
|
||||
import re
|
||||
import dearpygui.dearpygui as dpg
|
||||
from ffcraft_solver.modules import loader, log, solver
|
||||
import rich
|
||||
from xiv_csolver.modules import loader, log, solver, printer
|
||||
|
||||
|
||||
class User:
|
||||
|
|
@ -110,6 +108,22 @@ class User:
|
|||
dpg.set_value(user_stats, [self.initial_craftsmanship, self.initial_control, self.initial_cp])
|
||||
return self.name
|
||||
|
||||
@staticmethod
|
||||
def save_users() -> True:
|
||||
if dpg.get_value(save_user_as) == '':
|
||||
loggers.add_log('Cannot save user without a name.')
|
||||
elif re.search(r'^\s+$', dpg.get_value(save_user_as)):
|
||||
loggers.add_log('Name cannot be only whitespaces.')
|
||||
elif re.search(r'^\s.+', dpg.get_value(save_user_as)):
|
||||
loggers.add_log('Name cannot start with a whitespace.')
|
||||
elif re.search(r'\s$', dpg.get_value(save_user_as)):
|
||||
loggers.add_log('Name cannot end with a whitespace.')
|
||||
else:
|
||||
saver.save_users(dpg.get_value(save_user_as), dpg.get_value(user_stats))
|
||||
loggers.add_log('User saved!')
|
||||
dpg.configure_item('user_combo', items=full_config.get_users_names())
|
||||
return True
|
||||
|
||||
|
||||
class Recipe:
|
||||
name = ' '
|
||||
|
|
@ -122,7 +136,7 @@ class Recipe:
|
|||
progress_extra_difficulty = 0
|
||||
|
||||
def refresh_gui(self):
|
||||
dpg.set_value(recipe_stats, self.get_recipe_stats()[0:3])
|
||||
dpg.set_value(basic_recipe_stats, self.get_recipe_stats()[0:3])
|
||||
dpg.set_value(advanced_recipe_stats, self.get_recipe_stats()[3:7])
|
||||
if self.name != ' ':
|
||||
dpg.set_value(save_recipe_as, self.name)
|
||||
|
|
@ -133,11 +147,11 @@ class Recipe:
|
|||
stats = [0, 0, 0]
|
||||
advanced_stats = [0, 0, 0, 0]
|
||||
|
||||
if tag == 'recipe_tooltip':
|
||||
if tag == 'basic_recipe_stats':
|
||||
stats = app_data
|
||||
advanced_stats = dpg.get_value(advanced_recipe_stats)
|
||||
elif tag == 'advanced_recipe_tooltip':
|
||||
stats = dpg.get_value(recipe_stats)
|
||||
elif tag == 'advanced_recipe_stats':
|
||||
stats = dpg.get_value(basic_recipe_stats)
|
||||
advanced_stats = app_data
|
||||
elif tag == 0:
|
||||
stats = [app_data[0], app_data[1], app_data[2]]
|
||||
|
|
@ -169,6 +183,22 @@ class Recipe:
|
|||
def get_recipe_name(self) -> str:
|
||||
return self.name
|
||||
|
||||
@staticmethod
|
||||
def save_recipe() -> True:
|
||||
if dpg.get_value(save_recipe_as) == '':
|
||||
loggers.add_log('Cannot save recipe without a name.')
|
||||
elif re.search(r'^\s+$', dpg.get_value(save_recipe_as)):
|
||||
loggers.add_log('Name cannot be only whitespaces.')
|
||||
elif re.search(r'^\s.+', dpg.get_value(save_recipe_as)):
|
||||
loggers.add_log('Name cannot start with a whitespace.')
|
||||
elif re.search(r'\s$', dpg.get_value(save_recipe_as)):
|
||||
loggers.add_log('Name cannot end with a whitespace.')
|
||||
else:
|
||||
saver.save_recipe(dpg.get_value(save_recipe_as), dpg.get_value(basic_recipe_stats), dpg.get_value(advanced_recipe_stats))
|
||||
loggers.add_log('Recipe saved!')
|
||||
dpg.configure_item('recipe_combo', items=full_config.get_recipes_names())
|
||||
return True
|
||||
|
||||
|
||||
class Solution:
|
||||
def __init__(self, title, logger):
|
||||
|
|
@ -238,10 +268,12 @@ if __name__ == '__main__':
|
|||
pots_names = full_config.get_pots_names()
|
||||
recipe_names = full_config.get_recipes_names()
|
||||
|
||||
saver = printer.Printer(full_config)
|
||||
|
||||
# Start of GUI drawing
|
||||
# CHARACTER
|
||||
dpg.add_text("Character")
|
||||
user_combo = dpg.add_combo(items=characters_names, label="Your character", callback=user.set_name_combo)
|
||||
user_combo = dpg.add_combo(tag='user_combo', items=characters_names, label="Your character", callback=user.set_name_combo)
|
||||
dpg.set_value(user_combo, ' ')
|
||||
# TODO: Load 1rst user in users.yaml by default
|
||||
user_stats = dpg.add_input_intx(size=3, label="Stats", tag="stats_tooltip", callback=user.set_initial_stats)
|
||||
|
|
@ -249,8 +281,8 @@ if __name__ == '__main__':
|
|||
dpg.add_text("Craftsmanship / Control / CP")
|
||||
with dpg.group(horizontal=True):
|
||||
save_user_as = dpg.add_input_text(hint='Save as...')
|
||||
dpg.add_button(label="Save!")
|
||||
# TODO: Can't save if value == ' '
|
||||
# TODO: make it so field is not cleared at every input in stats
|
||||
dpg.add_button(label="Save!", callback=user.save_users)
|
||||
|
||||
# EFFECTIVE STATS
|
||||
dpg.add_separator()
|
||||
|
|
@ -264,24 +296,25 @@ if __name__ == '__main__':
|
|||
food_combo = dpg.add_combo(items=foods_names, label="Food", callback=user.set_food)
|
||||
pot_combo = dpg.add_combo(items=pots_names, label="Pot", callback=user.set_pot)
|
||||
specialist_checkbox = dpg.add_checkbox(label="Specialist", tag="specialist", callback=user.set_specialist)
|
||||
# TODO : possibility to add new food/pots without manually adding them to the config files
|
||||
|
||||
# RECIPE
|
||||
dpg.add_separator()
|
||||
dpg.add_text("Recipe")
|
||||
recipe_combo = dpg.add_combo(items=recipe_names, label="Recipe", callback=recipe.set_recipe_name)
|
||||
recipe_combo = dpg.add_combo(items=recipe_names, tag='recipe_combo', label="Recipe", callback=recipe.set_recipe_name)
|
||||
dpg.set_value(recipe_combo, " ")
|
||||
recipe_stats = dpg.add_input_intx(size=3, label="Stats", tag="recipe_tooltip", callback=recipe.set_recipe_stats)
|
||||
with dpg.tooltip("recipe_tooltip"):
|
||||
basic_recipe_stats = dpg.add_input_intx(size=3, label="Stats", tag="basic_recipe_stats", callback=recipe.set_recipe_stats)
|
||||
with dpg.tooltip("basic_recipe_stats"):
|
||||
dpg.add_text("Progress / Quality / Durability")
|
||||
advanced_recipe_stats = dpg.add_input_intx(
|
||||
size=4, label="Advanced stats", tag="advanced_recipe_tooltip", callback=recipe.set_recipe_stats
|
||||
size=4, label="Advanced stats", tag="advanced_recipe_stats", callback=recipe.set_recipe_stats
|
||||
)
|
||||
with dpg.tooltip("advanced_recipe_tooltip"):
|
||||
with dpg.tooltip("advanced_recipe_stats"):
|
||||
dpg.add_text("Progress / Quality difficulty // Progress / Quality extra difficulty")
|
||||
# TODO: add a log if recipe matches a known recipe
|
||||
with dpg.group(horizontal=True):
|
||||
save_recipe_as = dpg.add_input_text(hint='Save as...')
|
||||
dpg.add_button(label="Save!", callback=request_solve)
|
||||
dpg.add_button(label="Save!", callback=recipe.save_recipe)
|
||||
# TODO: Can't save if value == ' '
|
||||
|
||||
# SOLVE
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
# as can be found on other solver websites, such as https://yyyy.games/crafter/index.html#/simulator and checking custom recipe.
|
||||
# The language option is the second menu to the left from the top-right hand corner.
|
||||
# If this seems super convoluted, and you'd rather it was just the three in-game values, know that me too.
|
||||
# Unfortunately that is how Square Enix chose to make crafting work in FFXIV.
|
||||
# Unfortunately that is how the craft system works in FFXIV.
|
||||
|
||||
Grade 7 Tincture of Strength: [5060, 12628, 70, 130, 115, 80, 70]
|
||||
Grade 5 Strength Alkahest: [1300, 6200, 40, 123, 107, 100, 100]
|
||||
Grade 5 Strength Alkahest: [1300, 6200, 40, 123, 107, 100, 100]
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
# Name: [Craftsmanship, control, cp]
|
||||
# You are encouraged to use this either for multiple characters if you have them, or different jobs having
|
||||
# different gear or melds.
|
||||
# The top line will always be selected by default
|
||||
# The top line will always be selected by default
|
||||
|
||||
|
||||
Vicky Crosia: [4021, 3933, 587]
|
||||
Dandaedre Zadiel: [0, 0, 0]
|
||||
Sekundes Dullahan: [2566, 2443, 522]
|
||||
Sekundes Dullahan: [2566, 2443, 522]
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
import xiv_craft_solver
|
||||
import xiv_csolver_lib
|
||||
import rich
|
||||
|
||||
rich.inspect(xiv_craft_solver)
|
||||
rich.inspect(xiv_craft_solver.test_result)
|
||||
rich.inspect(xiv_craft_solver.test_result())
|
||||
rich.inspect(xiv_craft_solver.test_result())
|
||||
rich.inspect(xiv_csolver_lib)
|
||||
rich.inspect(xiv_csolver_lib.test_result)
|
||||
rich.inspect(xiv_csolver_lib.test_result())
|
||||
rich.inspect(xiv_csolver_lib.test_result())
|
||||
|
||||
|
||||
class FeedMeDaddy:
|
||||
|
|
@ -28,5 +28,5 @@ class FeedMeDaddy:
|
|||
|
||||
|
||||
el_daddy = FeedMeDaddy()
|
||||
rich.inspect(xiv_craft_solver.solve_from_python(el_daddy))
|
||||
rich.inspect(xiv_csolver_lib.solve_from_python(el_daddy))
|
||||
|
||||
|
|
@ -1,17 +1,21 @@
|
|||
import rich
|
||||
import yaml
|
||||
import os
|
||||
from ffcraft_solver.modules import log
|
||||
from xiv_csolver.modules import log
|
||||
|
||||
|
||||
class DefaultConfig:
|
||||
yaml_user = 'configs/users.yaml'
|
||||
yaml_consumable = 'configs/consumables.yaml'
|
||||
yaml_recipes = 'configs/recipes.yaml'
|
||||
yaml_dir = 'configs/'
|
||||
yaml_user = yaml_dir + 'users.yaml'
|
||||
yaml_consumable = yaml_dir + 'consumables.yaml'
|
||||
yaml_recipes = yaml_dir + 'recipes.yaml'
|
||||
|
||||
|
||||
class Loader:
|
||||
# TODO: create folder/file if missing when clicking "save"
|
||||
# TODO: log any missing file(s) or the whole folder
|
||||
# TODO: find a way to log at initialization
|
||||
# TODO: except ParserError and handle it
|
||||
def __init__(self, loggers: log.Loggers):
|
||||
self.loggers = loggers
|
||||
self.user_list = {' ': [0, 0, 0]}
|
||||
|
|
@ -20,32 +24,53 @@ class Loader:
|
|||
self.recipes_list = {' ': [0, 0, 0, 0, 0, 0, 0]}
|
||||
self.config = DefaultConfig()
|
||||
|
||||
if not os.path.exists(self.relative_import(self.config.yaml_dir)):
|
||||
os.mkdir(self.relative_import(self.config.yaml_dir))
|
||||
try:
|
||||
with open(self.relative_import(self.config.yaml_user), 'r') as file:
|
||||
self.user_list.update(yaml.safe_load(file))
|
||||
loaded_file = yaml.safe_load(file)
|
||||
if loaded_file:
|
||||
self.user_list.update(loaded_file)
|
||||
except FileNotFoundError as e:
|
||||
self.loggers.add_log(e)
|
||||
print(e)
|
||||
# self.loggers.add_log(f'File {self.config.yaml_user} not found.')
|
||||
print(f'File {self.config.yaml_user} not found.')
|
||||
print(f'Creating {self.config.yaml_user}.')
|
||||
with open(self.relative_import(self.config.yaml_user), 'w+') as _:
|
||||
pass
|
||||
|
||||
try:
|
||||
with open(self.relative_import(self.config.yaml_consumable), 'r') as file:
|
||||
loaded_file = yaml.safe_load(file)
|
||||
self.foods_list.update(loaded_file['Foods'])
|
||||
self.pots_list.update(loaded_file['Pots'])
|
||||
if loaded_file:
|
||||
loaded_file = yaml.safe_load(file)
|
||||
self.foods_list.update(loaded_file['Foods'])
|
||||
self.pots_list.update(loaded_file['Pots'])
|
||||
except FileNotFoundError as e:
|
||||
self.loggers.add_log(e)
|
||||
print(e)
|
||||
# self.loggers.add_log(f'File {self.config.yaml_consumable} not found.')
|
||||
print(f'File {self.config.yaml_consumable} not found.')
|
||||
print(f'Creating {self.config.yaml_consumable}.')
|
||||
with open(self.relative_import(self.config.yaml_consumable), 'w+') as _:
|
||||
pass
|
||||
|
||||
try:
|
||||
with open(self.relative_import(self.config.yaml_recipes), 'r') as file:
|
||||
self.recipes_list.update(yaml.safe_load(file))
|
||||
loaded_file = yaml.safe_load(file)
|
||||
if loaded_file:
|
||||
self.recipes_list.update(loaded_file)
|
||||
except (FileNotFoundError, IsADirectoryError) as e:
|
||||
self.loggers.add_log(e)
|
||||
print(e)
|
||||
# self.loggers.add_log(f'File {self.config.yaml_recipes} not found.')
|
||||
print(f'File {self.config.yaml_recipes} not found.')
|
||||
print(f'Creating {self.config.yaml_recipes}.')
|
||||
with open(self.relative_import(self.config.yaml_recipes), 'w+') as _:
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def relative_import(path):
|
||||
return os.path.normpath(os.path.join(__file__, "../..", path))
|
||||
|
||||
def get_users_dict(self) -> dict:
|
||||
self.loggers.add_log('Loaded user dictionary from users.yaml')
|
||||
return self.user_list
|
||||
|
||||
def get_users_names(self) -> list:
|
||||
|
|
@ -3,12 +3,9 @@ import dearpygui.dearpygui as dpg
|
|||
|
||||
|
||||
class Loggers:
|
||||
def __init__(self, log=None):
|
||||
def __init__(self):
|
||||
timestamp = self.get_timestamp()
|
||||
if not log:
|
||||
self.log = f"{timestamp} Log initialised."
|
||||
else:
|
||||
self.log = log
|
||||
self.log = f"{timestamp} Log initialised."
|
||||
|
||||
def add_log(self, other: str) -> str:
|
||||
timestamp = self.get_timestamp()
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
from xiv_csolver.modules import loader
|
||||
|
||||
|
||||
class Printer:
|
||||
def __init__(self, full_config: loader.Loader):
|
||||
self.full_config = full_config
|
||||
self.help_text_dict = {
|
||||
'users': '''# Name: [Craftsmanship, control, cp]
|
||||
# You are encouraged to use this either for multiple characters if you have them, or different jobs having
|
||||
# different gear or melds.
|
||||
# The top line will always be selected by default
|
||||
''',
|
||||
'foods': '''Foods:
|
||||
# Name: [[Bonus craftsmanship%, max value], [bonus control%, max value], [bonus cp%, max value]]
|
||||
# For example, Calamari Ripieni HQ gives 5% craftsmanship up to a maximum of 120, and 26% CP up to a
|
||||
# maximum of 82, and is hence noted as:
|
||||
# Calamari Ripieni HQ: [[5, 120], [0, 0], [26, 82]]
|
||||
#
|
||||
# Here is your template to copy/paste and fill in:
|
||||
# Name: [[0, 0], [0, 0], [0, 0]]''',
|
||||
'pots': ''' # Same as above:
|
||||
# Name: [[Bonus craftsmanship%, max value], [bonus control%, max value], [bonus cp%, max value]]
|
||||
# For example, Cunning Craftsman's Draught HQ gives 6% CP up to a maximum of 21, and is hence noted as:
|
||||
# Cunning Craftsman's Draught HQ: [[0, 0], [0, 0], [6, 21]]
|
||||
#
|
||||
# Here is your template to copy/paste and fill in:
|
||||
# Name: [[0, 0], [0, 0], [0, 0]]''',
|
||||
'recipe': '''# Name: [Progress, quality, durability, progress difficulty, quality difficulty, extra progress difficulty, extra quality difficulty]
|
||||
# as can be found on other solver websites, such as https://yyyy.games/crafter/index.html#/simulator and checking custom recipe.
|
||||
# The language option is the second menu to the left from the top-right hand corner.
|
||||
# If this seems super convoluted, and you'd rather it was just the three in-game values, know that me too.
|
||||
# Unfortunately that is how the craft system works in FFXIV.'''
|
||||
}
|
||||
|
||||
def save_users(self, user_name: str = None, user_stats: list = None) -> dict:
|
||||
output = self.help_text_dict['users'] + '\n\n'
|
||||
|
||||
if user_name.title() == '':
|
||||
for user, stats in self.full_config.get_users_dict().items():
|
||||
if user != ' ':
|
||||
output += f'{user}: [{stats[0]}, {stats[1]}, {stats[2]}]\n'
|
||||
|
||||
else:
|
||||
self.full_config.get_users_dict()[user_name] = user_stats
|
||||
for user, stats in self.full_config.get_users_dict().items():
|
||||
if user != ' ':
|
||||
output += f'{user}: [{stats[0]}, {stats[1]}, {stats[2]}]\n'
|
||||
|
||||
self.print_users(output)
|
||||
return self.full_config.get_users_dict()
|
||||
|
||||
def print_users(self, output: str) -> True:
|
||||
with open(self.full_config.relative_import(self.full_config.config.yaml_user), 'w') as file:
|
||||
file.write(output)
|
||||
return True
|
||||
|
||||
def save_recipe(self, recipe_name: str = None, recipe_basic_stats: list = None, recipe_advanced_stats: list = None) -> dict:
|
||||
output = self.help_text_dict['recipe'] + '\n\n'
|
||||
|
||||
if recipe_name.title() == '':
|
||||
for recipe, stats in self.full_config.get_recipes_dict().items():
|
||||
if recipe != ' ':
|
||||
output += f'{recipe}: [{stats[0]}, {stats[1]}, {stats[2]}, {stats[3]}, {stats[4]}, {stats[5]}, {stats[6]}]\n'
|
||||
|
||||
else:
|
||||
self.full_config.get_recipes_dict()[recipe_name] = recipe_basic_stats[:-1] + recipe_advanced_stats
|
||||
for recipe, stats in self.full_config.get_recipes_dict().items():
|
||||
if recipe != ' ':
|
||||
output += f'{recipe}: [{stats[0]}, {stats[1]}, {stats[2]}, {stats[3]}, {stats[4]}, {stats[5]}, {stats[6]}]\n'
|
||||
|
||||
self.print_recipe(output)
|
||||
return self.full_config.get_recipes_dict()
|
||||
|
||||
def print_recipe(self, output) -> True:
|
||||
with open(self.full_config.relative_import(self.full_config.config.yaml_recipes), 'w') as file:
|
||||
file.write(output)
|
||||
return True
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import rich
|
||||
import xiv_craft_solver as xcs
|
||||
from ffcraft_solver.__main__ import User, Recipe
|
||||
from ffcraft_solver.modules import log, translator
|
||||
import xiv_csolver_lib as xcs
|
||||
from xiv_csolver.__main__ import User, Recipe
|
||||
from xiv_csolver.modules import log, translator
|
||||
|
||||
|
||||
class Result:
|
||||
|
|
@ -125,7 +125,7 @@ class Solver:
|
|||
|
||||
def solve(self) -> str:
|
||||
self.solutions = xcs.solve_from_python(self)
|
||||
return xcs.solve_from_python(self)
|
||||
return self.solutions
|
||||
|
||||
def compute_all(self) -> True:
|
||||
if self.solutions:
|
||||
|
|
@ -149,24 +149,24 @@ class Solver:
|
|||
if s.quality > threshold:
|
||||
self.safe_50 = Result(s, 'Safe 50')
|
||||
done = True
|
||||
else:
|
||||
break
|
||||
|
||||
if not done:
|
||||
self.loggers.add_log('Could not find a rotation for a 50% Safe Margin.\n'
|
||||
' Defaulting to Best Quality.')
|
||||
self.safe_50 = self.best_quality
|
||||
|
||||
# self.safe_50 = Result(self.solutions[round(len(self.solutions)/2)+1], 'Safe 50') # old version
|
||||
return self.safe_50
|
||||
|
||||
def compute_least_steps(self) -> Result:
|
||||
least_steps = 100
|
||||
output = None
|
||||
if self.solutions:
|
||||
for e in self.solutions:
|
||||
if e.steps < least_steps:
|
||||
least_steps = e.steps
|
||||
output = e
|
||||
self.least_steps = Result(output, 'Least steps')
|
||||
for e in self.solutions:
|
||||
if e.steps < least_steps:
|
||||
least_steps = e.steps
|
||||
output = e
|
||||
self.least_steps = Result(output, 'Least steps')
|
||||
|
||||
return self.least_steps
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
from ffcraft_solver.modules import log
|
||||
from xiv_csolver.modules import log
|
||||
|
||||
loggers = log.Loggers
|
||||
|
||||
|
Before Width: | Height: | Size: 248 KiB After Width: | Height: | Size: 248 KiB |
|
Before Width: | Height: | Size: 352 KiB After Width: | Height: | Size: 352 KiB |
|
|
@ -1,29 +0,0 @@
|
|||
[tox]
|
||||
minversion = 3.8.0
|
||||
envlist = py37, py38, py39, flake8, mypy
|
||||
isolated_build = true
|
||||
|
||||
[gh-actions]
|
||||
python =
|
||||
3.7: py36, mypy, flake8
|
||||
3.8: py38
|
||||
3.9: py39
|
||||
|
||||
[testenv]
|
||||
setenv =
|
||||
PYTHONPATH = {toxinidir}
|
||||
deps =
|
||||
-r{toxinidir}/requirements_dev.txt
|
||||
commands =
|
||||
pytest --basetemp={envtmpdir}
|
||||
|
||||
[testenv:flake8]
|
||||
basepython = python3.10
|
||||
deps = flake8
|
||||
commands = flake8 src tests
|
||||
|
||||
[testenv:mypy]
|
||||
basepython = python3.10
|
||||
deps =
|
||||
-r{toxinidir}/requirements_dev.txt
|
||||
commands = mypy src
|
||||
154
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](crate::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,110 @@ 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 +451,6 @@ impl Default for ActionList {
|
|||
}
|
||||
|
||||
lazy_static! {
|
||||
/// Initialize a static pseudo &Craft: ACTIONS
|
||||
pub static ref ACTIONS: ActionList = ActionList::default();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,74 +0,0 @@
|
|||
// #![warn(missing_docs,unsafe_code,unstable_features,)]
|
||||
use clap::Parser;
|
||||
use std::time::Instant;
|
||||
use xiv_craft_solver;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct CustomError(String);
|
||||
|
||||
fn main() {
|
||||
let args = xiv_craft_solver::io::Args::parse();
|
||||
let params = xiv_craft_solver::io::Parameters::from_args(&args);
|
||||
|
||||
// Start timer
|
||||
let now = Instant::now();
|
||||
println!("Solving...");
|
||||
|
||||
// Solve from config
|
||||
let (recipe, stats) = xiv_craft_solver::load_from_config(
|
||||
&args.recipe_name,
|
||||
&args.file_name,
|
||||
&args.character_name,
|
||||
);
|
||||
let results = xiv_craft_solver::solve_craft(recipe, stats, params);
|
||||
|
||||
// Stop timer
|
||||
let t_final = now.elapsed().as_millis();
|
||||
|
||||
// Show best result depending on selected value
|
||||
match results {
|
||||
None => {
|
||||
println!(
|
||||
"[Error] No solutions found for craft '{}' with crafter '{}' (ms)",
|
||||
args.recipe_name, args.character_name
|
||||
);
|
||||
return;
|
||||
}
|
||||
Some(ref res) => {
|
||||
// Show best results
|
||||
if args.verbose > 0 {
|
||||
println!("[Final] {} results were found:", res.len());
|
||||
#[cfg(feature = "verbose")]
|
||||
if args.verbose > 1 {
|
||||
xiv_craft_solver::print_routes(&results);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("\n > SOLUTION [Least steps] <");
|
||||
xiv_craft_solver::find_fast_route(&results)
|
||||
.unwrap()
|
||||
.pretty_print();
|
||||
println!("\n > SOLUTION [Most durability] <");
|
||||
xiv_craft_solver::find_safe_route(&results)
|
||||
.unwrap()
|
||||
.pretty_print();
|
||||
println!("\n > SOLUTION [Most quality] < ");
|
||||
xiv_craft_solver::find_quality_route(&results)
|
||||
.unwrap()
|
||||
.pretty_print();
|
||||
|
||||
// #[cfg(feature = "verbose")]
|
||||
// if params.verbose>2{
|
||||
// println!("[F] Top routes {:?}",results);
|
||||
// }
|
||||
|
||||
// Wait for user input
|
||||
println!(
|
||||
"\nProgram finished successfully in {}ms\nPress enter to exit...",
|
||||
t_final
|
||||
);
|
||||
let mut input = String::new();
|
||||
std::io::stdin().read_line(&mut input).unwrap();
|
||||
()
|
||||
}
|
||||
|
|
@ -0,0 +1,168 @@
|
|||
//! # 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
|
||||
//!
|
||||
//! ### Development
|
||||
//!
|
||||
//! #### Rust
|
||||
//! To set up the whole development environment, 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, package them and make them ready to release
|
||||
//!
|
||||
//! #### Python
|
||||
//!
|
||||
//! It is really recommended to set up a venv to handle the python development
|
||||
//!
|
||||
//! All bindings and the explanation of how to use them can be found in the [`io`](crate::io) module.
|
||||
//!
|
||||
//! ### Features
|
||||
//!
|
||||
//! Use these by running `cargo run/build --features <name of feature>`
|
||||
//!
|
||||
//! - ``no_python`` : Don't 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
|
||||
//! ```
|
||||
//! ## Solving and bias
|
||||
//!
|
||||
//! The solving algorithm used has a very strong bias toward a particular method:
|
||||
//!
|
||||
//! - **Step 1** : Try to push the progression of the craft one step before being finishable
|
||||
//! - **Step 2** : Try to increase the quality as much as possible.
|
||||
//! - **Step 3** : Finish the craft
|
||||
//!
|
||||
//! To account for a lot of possibilities, step one generates all methods to try and finish the craft
|
||||
//! and step two tests all methods to up the quality until all crafting points are depleted
|
||||
//! Doing so ensures by brute force that all permutations are thoroughly tested.
|
||||
//!
|
||||
//! While this method works and is very likely the best method for the current patch,
|
||||
//! a rework of the crafting actions could very well make this method subpar or at least
|
||||
//! on par with another method.
|
||||
//!
|
||||
//! In layman's term, only the groundwork opening is tested and no delicate synthesis spam is tested.
|
||||
//! However, for now, these two crafting techniques remain subpar and discarding them comes at no
|
||||
//! loss for the crafter.
|
||||
//!
|
||||
//! Others algorithm exists and could very well cover all other basis at the expense of runtime.
|
||||
//! We have chosen not to implement them as they (for now) would be very unlikely to uncover anything
|
||||
//! meaningful.
|
||||
//!
|
||||
//! ### Leveling
|
||||
//!
|
||||
//! We have (for now at least) no intention to release a leveling feature to the crafting solver
|
||||
//! However, selecting some spells and buffs and have them disabled could be added as a feature
|
||||
//! hence making a "leveling" option
|
||||
//!
|
||||
//! If it is ever released, this feature is likely to be heavily reliant on the python GUI.
|
||||
//!
|
||||
//!
|
||||
//! ## Contributing
|
||||
//!
|
||||
//! All form of contributions are welcome !
|
||||
//!
|
||||
//! While this project was originally a collab and didn't strive to encompass every need
|
||||
//! of a modern FFXIV crafter, more polish and finish is always welcome.
|
||||
//!
|
||||
//! ## License
|
||||
//!
|
||||
//! The original code was released without a license 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;
|
||||
use xiv_csolver_lib;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct CustomError(String);
|
||||
|
||||
fn main() {
|
||||
let args = xiv_csolver_lib::io::Args::parse();
|
||||
let params = xiv_csolver_lib::io::Parameters::from_args(&args);
|
||||
|
||||
// Start timer
|
||||
let now = Instant::now();
|
||||
println!("Solving...");
|
||||
|
||||
// Solve from config
|
||||
let (recipe, stats) =
|
||||
xiv_csolver_lib::load_from_config(&args.recipe_name, &args.file_name, &args.character_name);
|
||||
let results = xiv_csolver_lib::solve_craft(recipe, stats, params);
|
||||
|
||||
// Stop timer
|
||||
let t_final = now.elapsed().as_millis();
|
||||
|
||||
// Show best result depending on selected value
|
||||
match results {
|
||||
None => {
|
||||
println!(
|
||||
"[Error] No solutions found for craft '{}' with crafter '{}' (ms)",
|
||||
args.recipe_name, args.character_name
|
||||
);
|
||||
return;
|
||||
}
|
||||
Some(ref res) => {
|
||||
// Show best results
|
||||
if args.verbose > 0 {
|
||||
println!("[Final] {} results were found:", res.len());
|
||||
#[cfg(feature = "verbose")]
|
||||
if args.verbose > 1 {
|
||||
xiv_csolver_lib::print_routes(&results);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("\n > SOLUTION [Least steps] <");
|
||||
xiv_csolver_lib::find_fast_route(&results)
|
||||
.unwrap()
|
||||
.pretty_print();
|
||||
println!("\n > SOLUTION [Most durability] <");
|
||||
xiv_csolver_lib::find_safe_route(&results)
|
||||
.unwrap()
|
||||
.pretty_print();
|
||||
println!("\n > SOLUTION [Most quality] < ");
|
||||
xiv_csolver_lib::find_quality_route(&results)
|
||||
.unwrap()
|
||||
.pretty_print();
|
||||
|
||||
// #[cfg(feature = "verbose")]
|
||||
// if params.verbose>2{
|
||||
// println!("[F] Top routes {:?}",results);
|
||||
// }
|
||||
|
||||
// Wait for user input
|
||||
println!(
|
||||
"\nProgram finished successfully in {}ms\nPress enter to exit...",
|
||||
t_final
|
||||
);
|
||||
let mut input = String::new();
|
||||
std::io::stdin().read_line(&mut input).unwrap();
|
||||
()
|
||||
}
|
||||
47
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;
|
||||
|
|
@ -145,3 +183,10 @@ impl<'a> Display for Craft<'a> {
|
|||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
// Struct Test
|
||||
#[test]
|
||||
pub fn struct_tests() {}
|
||||
}
|
||||
|
|
|
|||
195
src/io.rs
|
|
@ -1,19 +1,37 @@
|
|||
//! 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;
|
||||
|
||||
#[cfg(not(feature = "no_python"))]
|
||||
// #[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,47 +70,61 @@ 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,
|
||||
}
|
||||
|
||||
/// Pretty display for SolverResult
|
||||
impl Display for SolverResult {
|
||||
fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
println!("{:?}", self.actions);
|
||||
Ok(())
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
write!(f, "{:?}", self.actions)
|
||||
}
|
||||
}
|
||||
|
||||
//#[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,
|
||||
|
|
@ -104,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 {
|
||||
|
|
@ -136,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 {
|
||||
|
|
@ -155,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 : {}",
|
||||
|
|
@ -171,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 },
|
||||
|
|
@ -187,7 +229,7 @@ impl Parameters {
|
|||
/// A Python module implemented in Rust.
|
||||
#[cfg(not(feature = "no_python"))]
|
||||
#[pymodule]
|
||||
fn xiv_craft_solver(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
fn xiv_csolver_lib(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
m.add_function(wrap_pyfunction!(test_result, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(solve_from_python, m)?)?;
|
||||
Ok(())
|
||||
|
|
@ -204,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__`
|
||||
///
|
||||
/// ```python
|
||||
/// 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
|
||||
pub fn solve_from_python(py: Python<'_>, values: &PyAny) -> PyResult<Option<Vec<SolverResult>>> {
|
||||
// Create Recipe
|
||||
let recipe = Recipe {
|
||||
durability: values.getattr("durability")?.extract()?,
|
||||
progress: values.getattr("progress")?.extract()?,
|
||||
|
|
@ -235,6 +304,112 @@ pub fn solve_from_python(values: &PyAny) -> PyResult<Option<Vec<SolverResult>>>
|
|||
};
|
||||
|
||||
// println!("{:?} len: {:?} ",values,values.getattr("len()"));
|
||||
let res = solve_craft(recipe, stats, param);
|
||||
Ok(res)
|
||||
py.allow_threads(move || {
|
||||
let res = solve_craft(recipe, stats, param);
|
||||
Ok(res)
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::io::Args;
|
||||
use crate::{Parameters, SolverResult};
|
||||
use clap::Parser;
|
||||
use pretty_assertions::{assert_eq, assert_ne};
|
||||
|
||||
impl PartialEq for Parameters {
|
||||
fn eq(&self, rhs: &Parameters) -> bool {
|
||||
(self.byregot_step == rhs.byregot_step)
|
||||
& (self.depth == rhs.depth)
|
||||
& (self.desperate == rhs.desperate)
|
||||
& (self.threads == rhs.threads)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_parameters_derived_attributes() {
|
||||
let def = Parameters {
|
||||
byregot_step: 0,
|
||||
depth: 0,
|
||||
desperate: false,
|
||||
threads: 42,
|
||||
verbose: 1,
|
||||
};
|
||||
let def2 = def;
|
||||
let def3 = def2.clone();
|
||||
|
||||
assert_eq!(def2, def3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_display() {
|
||||
let def = SolverResult::default();
|
||||
assert_ne!(def.to_string(), "");
|
||||
assert_eq!(def.to_string(), "[\"Act1\", \"Act2\"]");
|
||||
def.pretty_print();
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_debug() {
|
||||
let def = SolverResult::default();
|
||||
assert_eq!(format!("{:?}", def),"SolverResult { steps: 0, quality: 0, progression: 0, durability: 0, cp: 0, total_cp: 0, total_progression: 0, total_quality: 0, total_durability: 0, actions: [\"Act1\", \"Act2\"], step1_solutions: 0, step2_solutions: 0, found_100_percent: false }");
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_arguments() {
|
||||
// Create false argument parameter
|
||||
let a = Args {
|
||||
character_name: "Bob GZ".to_string(),
|
||||
depth: 77,
|
||||
desperate: false,
|
||||
file_name: "test.toml".to_string(),
|
||||
long: false,
|
||||
recipe_name: "Belladone".to_string(),
|
||||
threads: 11,
|
||||
verbose: 1,
|
||||
};
|
||||
let a2 = a.clone();
|
||||
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 _ = 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);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_parameters() {}
|
||||
}
|
||||
|
|
|
|||
100
src/lib.rs
|
|
@ -1,3 +1,101 @@
|
|||
//! # 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
|
||||
//!
|
||||
//! ### Development
|
||||
//!
|
||||
//! #### Rust
|
||||
//! To set up the whole development environment, 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, package them and make them ready to release
|
||||
//!
|
||||
//! #### Python
|
||||
//!
|
||||
//! It is really recommended to set up a venv to handle the python development
|
||||
//!
|
||||
//! All bindings and the explanation of how to use them can be found in the [`io`](crate::io) module.
|
||||
//!
|
||||
//! ### Features
|
||||
//!
|
||||
//! Use these by running `cargo run/build --features <name of feature>`
|
||||
//!
|
||||
//! - ``no_python`` : Don't 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
|
||||
//! ```
|
||||
//! ## Solving and bias
|
||||
//!
|
||||
//! The solving algorithm used has a very strong bias toward a particular method:
|
||||
//!
|
||||
//! - **Step 1** : Try to push the progression of the craft one step before being finishable
|
||||
//! - **Step 2** : Try to increase the quality as much as possible.
|
||||
//! - **Step 3** : Finish the craft
|
||||
//!
|
||||
//! To account for a lot of possibilities, step one generates all methods to try and finish the craft
|
||||
//! and step two tests all methods to up the quality until all crafting points are depleted
|
||||
//! Doing so ensures by brute force that all permutations are thoroughly tested.
|
||||
//!
|
||||
//! While this method works and is very likely the best method for the current patch,
|
||||
//! a rework of the crafting actions could very well make this method subpar or at least
|
||||
//! on par with another method.
|
||||
//!
|
||||
//! In layman's term, only the groundwork opening is tested and no delicate synthesis spam is tested.
|
||||
//! However, for now, these two crafting techniques remain subpar and discarding them comes at no
|
||||
//! loss for the crafter.
|
||||
//!
|
||||
//! Others algorithm exists and could very well cover all other basis at the expense of runtime.
|
||||
//! We have chosen not to implement them as they (for now) would be very unlikely to uncover anything
|
||||
//! meaningful.
|
||||
//!
|
||||
//! ### Leveling
|
||||
//!
|
||||
//! We have (for now at least) no intention to release a leveling feature to the crafting solver
|
||||
//! However, selecting some spells and buffs and have them disabled could be added as a feature
|
||||
//! hence making a "leveling" option
|
||||
//!
|
||||
//! If it is ever released, this feature is likely to be heavily reliant on the python GUI.
|
||||
//!
|
||||
//!
|
||||
//! ## Contributing
|
||||
//!
|
||||
//! All form of contributions are welcome !
|
||||
//!
|
||||
//! While this project was originally a collab and didn't strive to encompass every need
|
||||
//! of a modern FFXIV crafter, more polish and finish is always welcome.
|
||||
//!
|
||||
//! ## License
|
||||
//!
|
||||
//! The original code was released without a license 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 +109,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>(
|
||||
|
|
|
|||
145
src/specs.rs
|
|
@ -1,54 +1,106 @@
|
|||
//! 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
|
||||
/// On some websites the fields are instead called
|
||||
/// [Progress, quality, durability, progress difficulty, quality difficulty, extra progress difficulty, extra quality difficulty]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Recipe {
|
||||
/// The recipe durability (also called solidity) (35, 40, 70 or 80 usually)
|
||||
pub durability: u32,
|
||||
/// The total recipe progress needed
|
||||
pub progress: u32,
|
||||
/// The total recipe quality
|
||||
pub quality: u32,
|
||||
/// How much the progress is hard to set,
|
||||
/// it's an (hidden) extra progress multiplier,
|
||||
/// inflicting a -10% to -30% to starred recipes
|
||||
/// Also called `progress_difficulty`
|
||||
pub progress_divider: u32,
|
||||
/// The same (hidden) difficulty multiplier, for quality
|
||||
/// Also called `progress_difficulty`
|
||||
pub quality_divider: u32,
|
||||
/// Modifies how much the base stats are affecting the craft progress
|
||||
/// Also called `progress_extra_difficulty`
|
||||
pub progress_modifier: u32,
|
||||
/// Modifies how much the base stats are affectif the craft quality
|
||||
/// Also called `quality_extra_difficulty`
|
||||
pub quality_modifier: u32,
|
||||
}
|
||||
|
||||
/// The craftsman stats
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Stats {
|
||||
/// The craftsmanship, influences the progress
|
||||
pub craftsmanship: u32,
|
||||
/// The control, inluences the quality
|
||||
pub control: u32,
|
||||
/// The amount of cp, ressource used for actions
|
||||
pub max_cp: u32,
|
||||
}
|
||||
|
||||
/// The buffs available for the crafter
|
||||
#[derive(Debug, Clone, Copy, PartialEq, EnumIter)]
|
||||
pub enum Buff {
|
||||
/// Gain a stack of Inner Quiet with every increase in quality, up to a maximum of 10.
|
||||
/// Grants a 10% bonus to the efficiency of Touch actions for each stack.
|
||||
InnerQuiet,
|
||||
/// Reduces loss of durability by 50%.
|
||||
WasteNot,
|
||||
/// Increases the efficiency of next Touch action by 100%.
|
||||
GreatStrides,
|
||||
/// Increases efficiency of Touch actions by 50%.
|
||||
Innovation,
|
||||
/// Increases efficiency of Synthesis actions by 50%.
|
||||
Veneration,
|
||||
/// Restores 5 points of durability after each step.
|
||||
Manipulation,
|
||||
/// 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.
|
||||
MuscleMemory,
|
||||
// v Hidden v
|
||||
/// (Hidden) Combo with Standart touch costs 18 cp.
|
||||
BasicTouch,
|
||||
/// (Hidden) Combo with Advanced touch costs 18 cp.
|
||||
StandardTouch,
|
||||
/// (Hidden) Do nothing for one step.
|
||||
Observe,
|
||||
}
|
||||
|
||||
/// Keeps track of all the durations remaining on all buffs
|
||||
/// Also called buff tracker in the docs
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct BuffState {
|
||||
/// Caps at 10 for a 100% extra efficiency in quality increase
|
||||
pub inner_quiet: u8,
|
||||
/// Lasts for four steps if Waste not was used, height if Waste Not II was.
|
||||
pub waste_not: u8,
|
||||
/// Effect active for three steps, dissipates after a quality action is used.
|
||||
pub great_strides: u8,
|
||||
/// Lasts four steps
|
||||
pub innovation: u8,
|
||||
/// Lasts four steps.
|
||||
pub veneration: u8,
|
||||
/// Lasts height steps
|
||||
pub manipulation: u8,
|
||||
/// Lasts five steps, dissipate after a progression action is used.
|
||||
pub muscle_memory: u8,
|
||||
/// Lasts one step
|
||||
pub basic_touch: u8,
|
||||
/// Lasts one step
|
||||
pub standard_touch: u8,
|
||||
/// Lasts one step
|
||||
pub observe: u8,
|
||||
}
|
||||
|
||||
impl BuffState {
|
||||
/// Default state of buffs (all at zero) as per the beggining of craft
|
||||
pub fn default() -> Self {
|
||||
Self {
|
||||
inner_quiet: 0,
|
||||
|
|
@ -64,6 +116,7 @@ impl BuffState {
|
|||
}
|
||||
}
|
||||
|
||||
/// Remove the given buff from the buff tracker
|
||||
pub fn remove(&mut self, buff: Buff) {
|
||||
match buff {
|
||||
Buff::InnerQuiet => self.inner_quiet = 0,
|
||||
|
|
@ -79,6 +132,8 @@ impl BuffState {
|
|||
}
|
||||
}
|
||||
|
||||
/// Apply the given buff to the buff tracker for `value` steps
|
||||
/// In the case of Inner Quiet, it inseads adds one to the stack counter
|
||||
pub fn apply(&mut self, buff: Buff, value: u8) {
|
||||
match buff {
|
||||
Buff::InnerQuiet => {
|
||||
|
|
@ -96,10 +151,11 @@ impl BuffState {
|
|||
Buff::MuscleMemory => self.muscle_memory = value,
|
||||
Buff::BasicTouch => self.basic_touch = value,
|
||||
Buff::StandardTouch => self.standard_touch = value,
|
||||
Buff::Observe => self.standard_touch = value,
|
||||
Buff::Observe => self.observe = value,
|
||||
}
|
||||
}
|
||||
|
||||
/// Tick downs the remaining duration of all buffs, if up
|
||||
pub fn tick(&mut self) {
|
||||
if self.waste_not > 0 {
|
||||
self.waste_not -= 1;
|
||||
|
|
@ -128,9 +184,94 @@ impl BuffState {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
/// State the craft is in, used to keep track of wether the craft
|
||||
/// is to be worked on, added to the success vector or discarded
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Success {
|
||||
/// Pending success and therefor still ongoing
|
||||
Pending,
|
||||
/// Finised, not ongoing and finished without breaking (Doens't take quality into account)
|
||||
Success,
|
||||
/// Finised because of lack of remaining durability
|
||||
Failure,
|
||||
}
|
||||
|
||||
// Test unit
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
// Test default values
|
||||
use pretty_assertions::assert_eq;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
#[test]
|
||||
pub fn test_structs() {
|
||||
format!(
|
||||
"{:?}",
|
||||
crate::specs::Recipe {
|
||||
durability: 0,
|
||||
progress: 0,
|
||||
progress_divider: 0,
|
||||
progress_modifier: 0,
|
||||
quality: 0,
|
||||
quality_divider: 0,
|
||||
quality_modifier: 0,
|
||||
}
|
||||
.clone()
|
||||
);
|
||||
|
||||
format!(
|
||||
"{:?}",
|
||||
crate::specs::Stats {
|
||||
craftsmanship: 0,
|
||||
control: 0,
|
||||
max_cp: 0,
|
||||
}
|
||||
.clone()
|
||||
);
|
||||
|
||||
let iq = crate::specs::Buff::InnerQuiet;
|
||||
assert_eq!(crate::specs::Buff::InnerQuiet, iq);
|
||||
for buff in crate::specs::Buff::iter() {
|
||||
format!("{:?}", buff);
|
||||
}
|
||||
format!("{:?}", crate::specs::BuffState::default().clone());
|
||||
|
||||
let sc = crate::specs::Success::Pending;
|
||||
assert!(crate::specs::Success::Pending == sc);
|
||||
assert!(crate::specs::Success::Success != sc);
|
||||
format!("{:?}", sc);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_buffstate() {
|
||||
let mut bbs = crate::specs::BuffState::default();
|
||||
for buff in crate::specs::Buff::iter() {
|
||||
bbs.apply(buff, 2);
|
||||
}
|
||||
assert_eq!(bbs.inner_quiet, 2);
|
||||
assert_eq!(bbs.waste_not, 2);
|
||||
assert_eq!(bbs.great_strides, 2);
|
||||
assert_eq!(bbs.innovation, 2);
|
||||
assert_eq!(bbs.veneration, 2);
|
||||
assert_eq!(bbs.manipulation, 2);
|
||||
assert_eq!(bbs.muscle_memory, 2);
|
||||
assert_eq!(bbs.basic_touch, 2);
|
||||
assert_eq!(bbs.standard_touch, 2);
|
||||
assert_eq!(bbs.observe, 2);
|
||||
bbs.apply(crate::specs::Buff::InnerQuiet, 0);
|
||||
bbs.apply(crate::specs::Buff::Innovation, 5);
|
||||
assert_eq!(bbs.inner_quiet, 0);
|
||||
assert_eq!(bbs.innovation, 5);
|
||||
bbs.apply(crate::specs::Buff::InnerQuiet, 2);
|
||||
bbs.apply(crate::specs::Buff::InnerQuiet, 1);
|
||||
assert_eq!(bbs.inner_quiet, 3);
|
||||
bbs.tick();
|
||||
assert_eq!(bbs.inner_quiet, 3);
|
||||
assert_eq!(bbs.innovation, 4);
|
||||
for buff in crate::specs::Buff::iter() {
|
||||
bbs.remove(buff);
|
||||
}
|
||||
assert_eq!(bbs.inner_quiet, 0);
|
||||
assert_eq!(bbs.innovation, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
|
||||
|
|
@ -0,0 +1 @@
|
|||
|
||||