Banner

Struct Banner 

Source
pub struct Banner {
    pub pool: HashMap<u8, Vec<String>>,
    pub rate_up: HashMap<u8, Vec<String>>,
    pub rarity: Rarity,
    /* private fields */
}

Fields§

§pool: HashMap<u8, Vec<String>>§rate_up: HashMap<u8, Vec<String>>§rarity: Rarity

Implementations§

Source§

impl Banner

Source

pub fn from_banner_type(banner_type: BannerType) -> Self

Create new banner from BannerType BannerType can be one of the following:

  • BannerType::Standard
  • BannerType::Limited
    You have to set operator pool and operator rate up using set_pool and set_rate_up yourself
    The only diffirent is rate_up_rate. 70% up for 6 star operator in Limited and 50% up for 6 star operator in Standard. Both have 50% rate up rate for 5 star operator
§Example
use prts::{Banner, BannerType};
 
let mut banner = Banner::from_banner_type(BannerType::Limited);
Source

pub fn from_file(file_name: String) -> Self

Create new instance of Banner by read .toml file
See sample file

§Example
use prts::Banner;
 
let mut banner = Banner::from_file("./data/operators.toml".to_string());
let (star, opname, is_up) = banner.gacha_operator();
println!("{} {} {}", is_up, star, opname);
Source

pub fn set_pool(&mut self, star: u8, operators: Vec<String>)

Set banner pool with specific operator bound to specific star

§Example
use prts::{Banner, BannerType};
 
let mut banner = Banner::from_banner_type(BannerType::Standard);
// set pool 6 star have 2 operators 
banner.set_pool(6, vec!["Silver Ash".to_string(), "Angelina".to_string()]);
// set pool 5 star have 2 operators 
banner.set_pool(5, vec!["Andreana".to_string(), "Projekt Red".to_string()]);
// set pool 4 star have 2 operators 
banner.set_pool(4, vec!["Utage".to_string(), "Myrtle".to_string()]);
// set pool 3 star have 2 operators 
banner.set_pool(3, vec!["Lava".to_string(), "Hibicus".to_string()]);
 
// set rate up 6 star have 2 operator
banner.set_rate_up(6, vec!["Surtr".to_string(), "Skadi".to_string()]);
// set rate up 5 star have 3 operator
banner.set_rate_up(5, vec!["Specter".to_string(), "Ptilopsis".to_string(), "Lappland".to_string()]);
 
let (star, opname, is_up) = banner.gacha_operator();
println!("{} {} {}", is_up, star, opname);
Source

pub fn set_rate_up(&mut self, star: u8, rateup_operators: Vec<String>)

Set banner rate up operator with specific operator bound to specific star

§Example
use prts::{Banner, BannerType};
 
let mut banner = Banner::from_banner_type(BannerType::Standard);
// set pool 6 star have 2 operators 
banner.set_pool(6, vec!["Silver Ash".to_string(), "Angelina".to_string()]);
// set pool 5 star have 2 operators 
banner.set_pool(5, vec!["Andreana".to_string(), "Projekt Red".to_string()]);
// set pool 4 star have 2 operators 
banner.set_pool(4, vec!["Utage".to_string(), "Myrtle".to_string()]);
// set pool 3 star have 2 operators 
banner.set_pool(3, vec!["Lava".to_string(), "Hibicus".to_string()]);
 
// set rate up 6 star have 2 operator
banner.set_rate_up(6, vec!["Surtr".to_string(), "Skadi".to_string()]);
// set rate up 5 star have 3 operator
banner.set_rate_up(5, vec!["Specter".to_string(), "Ptilopsis".to_string(), "Lappland".to_string()]);
 
let (star, opname, is_up) = banner.gacha_operator();
println!("{} {} {}", is_up, star, opname);
Source

pub fn gacha_operator(&mut self) -> (u8, String, bool)

Simulate Arknights headhunt once
It have the exact same mechanic in game (or i think that have :)))) )
Mechanism:
In a single headhunt, you have the following change to get an operator:

  • 2% to get 6 star operator
  • 8% to get 5 star operator
  • 50% to get 4 star operator
  • 40% to get 3 star operator
    In the first 10 headhunt in a banner, if you don’t get a 5 star or higher star operator the 10th headhunt guaranteed a 5 star operator
    If for 50 headhunt, you don’t get a 6 star operator, from the 51st headhunt will increase change to get six star operator by 2% (change to get 6 star operator in the 51st headhunt is 4%, 52nd is 6%, …)
    If the result is 5 star operator or 6 star operator, you will have change to get the rate up operator
  • 50% to get 5 star rate up operator
  • 70% to get 6 star rate up operator in Limited banner
  • 50% to get 6 star rate up operator in Standard banner

Function returns: (star_result, operator_name, is_up)

  • star_result: can be any number in range 3..=6
  • operator_name: name of the operator
  • is_up: the operator is rate up or not
§Example
use prts::Banner;
 
let mut banner = Banner::from_file("./data/operators.toml".to_string());
let (star, opname, is_up) = banner.gacha_operator();
println!("{} {} {}", is_up, star, opname);
§Panics

May Panik if operator pool or operator rate up is not set

Source

pub fn gacha_10_times(&mut self) -> Vec<(u8, String, bool)>

Simulate Arknights headhunt 10 times

§Example
use prts::Banner;
 
let mut banner = Banner::from_file("./data/operators.toml".to_string());
let res = banner.gacha_10_times();
for (star, name, is_up) in &res {
    println!("{} {} {}", is_up, star, name);
}
§Panics

May Panik if operator pool or operator rate up is not set

Source

pub fn set_dokutah_info( &mut self, non_six_star_count: u8, guarantee_five_star: i8, )

set non_six_star_count and guarantee_five_star of Banner can be useful when have many doctor, but need to create only 1 banner

§Example
use prts::Banner;
 
let mut banner = Banner::from_file("./data/operators.toml".to_string());
let res = banner.gacha_10_times();
for (star, name, is_up) in &res {
    println!("{} {} {}", is_up, star, name);
}
let old_dokutah_infor = (banner.rarity.non_six_star_count, banner.rarity.guarantee_five_star);
banner.set_dokutah_info(90, 0);
let res = banner.gacha_10_times();
for (star, name, is_up) in &res {
    println!("{} {} {}", is_up, star, name);
}

Trait Implementations§

Source§

impl Debug for Banner

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Banner

§

impl RefUnwindSafe for Banner

§

impl Send for Banner

§

impl Sync for Banner

§

impl Unpin for Banner

§

impl UnwindSafe for Banner

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V