use crate::drop::{Drop, DropSim, Item};
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Run {
pub barters: Vec<Drop>,
pub fights: Vec<Drop>,
}
impl Run {
pub fn new(barters: Vec<Drop>, fights: Vec<Drop>) -> Self {
Self { barters, fights }
}
pub fn total_barters(&self) -> u32 {
self.barters.len() as u32
}
pub fn successful_barters(&self) -> u32 {
self.barters
.iter()
.filter(|drop| drop.item == Item::EnderPearl)
.count() as u32
}
pub fn total_pearls(&self) -> u32 {
self.barters
.iter()
.filter(|drop| drop.item == Item::EnderPearl)
.map(|drop| drop.count)
.sum()
}
pub fn total_fights(&self) -> u32 {
self.fights.len() as u32
}
pub fn successful_fights(&self) -> u32 {
self.barters
.iter()
.filter(|drop| drop.item == Item::BlazeRod)
.count() as u32
}
pub fn total_rods(&self) -> u32 {
self.fights
.iter()
.filter(|drop| drop.item == Item::BlazeRod)
.map(|drop| drop.count)
.sum()
}
}
#[derive(Debug, Clone, Copy, Deserialize, Serialize)]
pub struct RunGoals {
pub target_pearls: u32,
pub target_rods: u32,
}
#[derive(Debug)]
pub struct RunSim<'a, 'b> {
barter_drop_sim: &'a mut DropSim,
blaze_drop_sim: &'b mut DropSim,
pearl_target: u32,
rods_target: u32,
}
impl<'a, 'b> RunSim<'a, 'b> {
pub fn new(
barter_drop_sim: &'a mut DropSim,
blaze_drop_sim: &'b mut DropSim,
pearl_target: u32,
rods_target: u32,
) -> Self {
Self {
barter_drop_sim,
blaze_drop_sim,
pearl_target,
rods_target,
}
}
pub fn run(&mut self) -> Run {
Run::new(self.barter_for_pearls(), self.fight_for_rods())
}
pub fn barter_for_pearls(&mut self) -> Vec<Drop> {
RunSim::farm_for_item(
&mut self.barter_drop_sim,
Item::EnderPearl,
self.pearl_target,
)
}
pub fn fight_for_rods(&mut self) -> Vec<Drop> {
RunSim::farm_for_item(&mut self.blaze_drop_sim, Item::BlazeRod, self.rods_target)
}
pub fn farm_for_item(drop_sim: &mut DropSim, item: Item, minimum: u32) -> Vec<Drop> {
let mut drops = Vec::new();
let mut count = 0;
while count < minimum {
let drop = drop_sim.get_drop();
if drop.item == item {
count += drop.count;
}
drops.push(drop);
}
drops
}
}