buy/combine from vbox wip

This commit is contained in:
Mashy
2019-11-19 13:09:50 +10:00
parent f2add9a836
commit 2ba8a63d81
3 changed files with 10 additions and 5 deletions
+7 -1
View File
@@ -142,10 +142,16 @@ impl Vbox {
Ok(self)
}
pub fn combine(&mut self, mut inv_indices: Vec<usize>, mut vbox_indicies: Vec<Vec<usize>>) -> Result<&mut Vbox, Error> {
pub fn combine(&mut self, mut inv_indices: Vec<usize>, vbox_indicies: Vec<Vec<usize>>) -> Result<&mut Vbox, Error> {
if !inv_indices.iter().all(|i| self.bound.get(*i).is_some()) {
return Err(err_msg("item missing index"));
}
// try to buy up the vbox indicies and add them to the inventory indicies for combining
for vi in vbox_indicies.iter() {
inv_indices.push(self.bound.len());
self.accept(vi[0], vi[1], Some(Uuid::nil()))?;
}
// have to sort the indices and keep track of the iteration
// because when removing the elements the array shifts
inv_indices.sort_unstable();