Skip to content

Commit

Permalink
reorganize project into a library
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-dupre committed Nov 10, 2019
1 parent 9265316 commit 0f7f2bb
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 80 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ before_script:

script:
- cargo check
- cargo test
- cargo clippy -- -D warnings
- cargo +nightly fmt --all -- --check

before_deploy:
- cargo build --release
- mkdir dofus-generate-stuff
&& cp target/release/dofus-generate-stuff dofus-generate-stuff
&& cp target/release/stuffer dofus-generate-stuff
&& cp -r data examples dofus-generate-stuff
- tar -czf dofus-generate-stuff.tar.gz dofus-generate-stuff

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "dofus-generate-stuff"
name = "dofus_stuff"
version = "0.1.0"
authors = ["Rémi Dupré <remim.dupre@gmail.com>"]
edition = "2018"
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ can download an archive containing both the binary and required item databases.
wget https://github.com/remi-dupre/dofus-generate-stuff/releases/download/${VERSION}/dofus-generate-stuff.tar.gz
tar -xf dofus-generate-stuff.tar.gz
cd dofus-generate-stuff
./dofus-generate-stuff examples/earth_iop.json
./stuffer examples/earth_iop.json
```

### From sources
Expand Down Expand Up @@ -66,15 +66,15 @@ following kind of statistics:
```json
{
"level": 200,
"target", [
["Resiliance", 10000],
[{"Carac": "Lock"}, 150],
[{"Carac": "AP"}, 11],
[{"Carac": "MP"}, 6],
[{"PowStats": "Air"}, 800],
[{"Carac": "MP Resistance"}, 70],
[{"Carac": "AP Resistance"}, 70],
[{"Carac": "AP Reduction"}, 100]
"target": [
["Resiliance", 10000],
[{"Carac": "Lock"}, 150],
[{"Carac": "AP"}, 11],
[{"Carac": "MP"}, 6],
[{"PowStats": "Air"}, 800],
[{"Carac": "MP Resistance"}, 70],
[{"Carac": "AP Resistance"}, 70],
[{"Carac": "AP Reduction"}, 100]
]
}
```
Expand Down
5 changes: 3 additions & 2 deletions examples/earth_iop.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"level": 200,
"banned_types": ["Trophy"],
"target": [
[{"Carac": "AP"}, 12],
[{"Carac": "MP"}, 5],
Expand All @@ -20,7 +21,7 @@
]
}
},
5000
3500
],
[
{
Expand All @@ -35,7 +36,7 @@
]
}
},
500
600
]
]
}
51 changes: 41 additions & 10 deletions src/main.rs → src/bin/stuffer.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
pub mod character;
pub mod dofapi;
pub mod input;
pub mod rls;
pub mod search;

#[macro_use]
extern crate lazy_static;
extern crate dofus_stuff;
extern crate rand;
extern crate rayon;
extern crate regex;
Expand All @@ -17,10 +12,19 @@ use std::io;

use regex::Regex;

use crate::character::{Character, RawCaracsValue};
use crate::dofapi::{fix_all_trophy, CaracKind, Element, Equipement, Set};
use crate::input::InputRequest;
use crate::search::{eval_character, optimize_character};
use dofus_stuff::character::{Character, RawCaracsValue};
use dofus_stuff::dofapi::{
fix_all_trophy, CaracKind, Element, Equipement, ItemType, Set,
};
use dofus_stuff::search::{eval_character, optimize_character};
use serde::Deserialize;

// ____ _ _
// / ___|___ _ __ ___| |_ __ _ _ __ | |_ ___
// | | / _ \| '_ \/ __| __/ _` | '_ \| __/ __|
// | |__| (_) | | | \__ \ || (_| | | | | |_\__ \
// \____\___/|_| |_|___/\__\__,_|_| |_|\__|___/
//

/// List of files containing the list of equipements.
const EQUIPEMENT_FILES: [&str; 4] = [
Expand All @@ -36,6 +40,33 @@ const SET_FILE: &str = "./data/sets.json";
/// Default file to read as input when no parameter is specified.
const DEFAULT_INPUT_PATH: &str = "input.json";

// ___ _
// |_ _|_ __ _ __ _ _| |_
// | || '_ \| '_ \| | | | __|
// | || | | | |_) | |_| | |_
// |___|_| |_| .__/ \__,_|\__|
// |_|

/// Input request for building a stuff.
#[derive(Deserialize)]
pub struct InputRequest {
/// Level of the character to build a stuff for.
#[serde(default = "default_level")]
pub level: u8,

/// Types of items that can't be used in the output.
#[serde(default)]
pub banned_types: Vec<ItemType>,

/// List of approximate expected statistics in the output.
pub target: Vec<(RawCaracsValue, f64)>,
}

/// Default level of a character.
fn default_level() -> u8 {
200
}

fn main() -> io::Result<()> {
// --- Open item database
eprintln!("-- Loading data...");
Expand Down
69 changes: 40 additions & 29 deletions src/character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<'a, 'i> ItemSlot<'a, 'i> {
// \____|_| |_|\__,_|_| \__,_|\___|\__\___|_|
//

#[derive(Debug)]
#[derive(Debug, Eq, PartialEq)]
pub enum CharacterError<'c> {
NotEnoughPoints,
NotEnoughCaracs(&'c CaracKind),
Expand Down Expand Up @@ -174,8 +174,8 @@ impl<'i> Character<'i> {
/// # Examples
///
/// ```
/// use crate::dofapi::carac::CaracKind::*;
/// use crate::dofapi::effect::Element::*;
/// use dofus_stuff::character::*;
/// use dofus_stuff::dofapi::{CaracKind::*, Element::*};
///
/// assert_eq!(Character::carac_cost_from_zero(&Wisdom, 100), 300);
/// assert_eq!(Character::carac_cost_from_zero(&Stats(Air), 100), 100);
Expand Down Expand Up @@ -204,16 +204,19 @@ impl<'i> Character<'i> {
/// # Examples
///
/// ```
/// use crate::dofapi::carac::CaracKind::*;
/// use crate::dofapi::effect::Element::*;
/// # use std::collections::HashMap;
/// use dofus_stuff::character::*;
/// use dofus_stuff::dofapi::{CaracKind::*, Element::*};
///
/// let db_sets = HashMap::new();
/// let mut character = Character::new(200, &db_sets);
///
/// let mut character = Character::new();
/// assert_eq!(character.carac_spend_cost(&Stats(Air), 100), 100);
/// assert_eq!(character.carac_spend_cost(&Stats(Air), 150), 200);
///
/// character.carac_spend(&Stats(Air), 200).unwrap();
/// character.carac_spend(&Stats(Air), 100).unwrap();
/// assert_eq!(character.carac_spend_cost(&Stats(Air), 50), 100);
/// assert_eq!(character.carac_spend_cost(&Stats(Air), 150), 400);
/// assert_eq!(character.carac_spend_cost(&Stats(Air), 150), 350);
/// ```
pub fn carac_spend_cost(&self, kind: &CaracKind, amount: u16) -> u16 {
let current = *self.base_stats.get(kind).unwrap_or(&0);
Expand All @@ -226,15 +229,17 @@ impl<'i> Character<'i> {
/// # Examples
///
/// ```
/// use crate::dofapi::carac::CaracKind::*;
/// use crate::dofapi::effect::Element::*;
/// # use std::collections::HashMap;
/// use dofus_stuff::character::*;
/// use dofus_stuff::dofapi::{CaracKind::*, Element::*};
///
/// let mut character = Character::new();
/// let db_sets = HashMap::new();
/// let mut character = Character::new(200, &db_sets);
/// character.carac_spend(&Stats(Air), 200).unwrap();
///
/// assert_eq!(character.carac_unspend_recover(&Stats(Air), 100), Ok(200))
/// assert_eq!(character.carac_unspend_recover(&Stats(Air), 200), Ok(300))
/// assert!(character.carac_unspend_recover(&Stats(Air), 201).is_err())
/// assert_eq!(character.carac_unspend_recover(&Stats(Air), 100), Ok(200));
/// assert_eq!(character.carac_unspend_recover(&Stats(Air), 200), Ok(300));
/// assert!(character.carac_unspend_recover(&Stats(Air), 201).is_err());
/// ```
pub fn carac_unspend_recover(
&self,
Expand All @@ -256,13 +261,15 @@ impl<'i> Character<'i> {
/// # Examples
///
/// ```
/// use crate::dofapi::carac::CaracKind::*;
/// use crate::dofapi::effect::Element::*;
/// # use std::collections::HashMap;
/// use dofus_stuff::character::*;
/// use dofus_stuff::dofapi::{CaracKind::*, Element::*};
///
/// let mut character = Character::new();
/// let db_sets = HashMap::new();
/// let mut character = Character::new(200, &db_sets);
///
/// assert!(character.carac_spend(Stats(Air), 100).is_ok());
/// assert!(character.carac_spend(Stats(Air), 400).is_err());
/// assert!(character.carac_spend(&Stats(Air), 100).is_ok());
/// assert!(character.carac_spend(&Stats(Air), 400).is_err());
/// ```
pub fn carac_spend(
&mut self,
Expand All @@ -288,15 +295,17 @@ impl<'i> Character<'i> {
/// # Examples
///
/// ```
/// use crate::dofapi::carac::CaracKind::*;
/// use crate::dofapi::effect::Element::*;
/// # use std::collections::HashMap;
/// use dofus_stuff::character::*;
/// use dofus_stuff::dofapi::{CaracKind::*, Element::*};
///
/// let mut character = Character::new();
/// let db_sets = HashMap::new();
/// let mut character = Character::new(200, &db_sets);
/// character.carac_spend(&Stats(Air), 200).unwrap();
///
/// assert_eq!(character.carac_unspend(Stats(Air), 100), Ok(100));
/// assert_eq!(character.carac_unspend(Stats(Air), 99), Ok(100));
/// assert!(character.carac_unspend(Stats(Air), 201).is_err());
/// assert_eq!(character.carac_unspend(&Stats(Air), 100), Ok(()));
/// assert_eq!(character.carac_unspend(&Stats(Air), 99), Ok(()));
/// assert!(character.carac_unspend(&Stats(Air), 201).is_err());
/// ```
pub fn carac_unspend(
&mut self,
Expand All @@ -322,15 +331,17 @@ impl<'i> Character<'i> {
/// # Examples
///
/// ```
/// use crate::dofapi::carac::CaracKind::*;
/// use crate::dofapi::effect::Element::*;
/// # use std::collections::HashMap;
/// use dofus_stuff::character::*;
/// use dofus_stuff::dofapi::{CaracKind::*, Element::*};
///
/// let mut character = Character::new();
/// let db_sets = HashMap::new();
/// let mut character = Character::new(200, &db_sets);
///
/// // Seek from unspent points
/// assert!(
/// character
/// .carac_spend_or_seek(&Stats(Air), 200, &Wisdom)
/// .carac_spend_or_seek(&Stats(Air), 150, &Wisdom)
/// .is_ok()
/// );
/// assert!(
Expand Down
24 changes: 0 additions & 24 deletions src/input.rs

This file was deleted.

8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[macro_use]
extern crate lazy_static;

pub mod character;
pub mod dofapi;
pub mod search;

mod rls;
4 changes: 2 additions & 2 deletions src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::character::{Character, RawCaracsValue};
use crate::dofapi::{CaracKind, Element, Equipement};
use crate::rls::rls;

const STEPS: u32 = 1_000_000;
const STEPS: u32 = 100_000;
const ASSIGNABLE_CARACS: &[CaracKind] = &[
CaracKind::Vitality,
CaracKind::Wisdom,
Expand Down Expand Up @@ -76,7 +76,7 @@ pub fn eval_character(
.product();

let count_item_conflicts = character.count_item_conflicts();
let conflicts_weight = 0.1f64.powi(count_item_conflicts.into());
let conflicts_weight = 0.05f64.powi(count_item_conflicts.into());

let conditions_weight = target_zero(
200.,
Expand Down

0 comments on commit 0f7f2bb

Please sign in to comment.