add vbox indicies as a combine param
This commit is contained in:
parent
f850a8806b
commit
0d08536837
@ -107,8 +107,8 @@ function createSocket(events) {
|
||||
events.clearInstance();
|
||||
}
|
||||
|
||||
function sendVboxCombine(instanceId, indices) {
|
||||
send(['VboxCombine', { instance_id: instanceId, indices }]);
|
||||
function sendVboxCombine(instanceId, invIndicies) {
|
||||
send(['VboxCombine', { instance_id: instanceId, inv_indices: invIndicies, vbox_indices: [] }]);
|
||||
events.clearInstance();
|
||||
}
|
||||
|
||||
|
||||
@ -480,10 +480,10 @@ impl Instance {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn vbox_combine(mut self, account: Uuid, indices: Vec<usize>) -> Result<Instance, Error> {
|
||||
pub fn vbox_combine(mut self, account: Uuid, inv_indices: Vec<usize>, vbox_indices: Vec<Vec<usize>>) -> Result<Instance, Error> {
|
||||
self.vbox_action_allowed(account)?;
|
||||
self.account_player(account)?
|
||||
.vbox_combine(indices)?;
|
||||
.vbox_combine(inv_indices, vbox_indices)?;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
|
||||
@ -229,7 +229,7 @@ impl Player {
|
||||
};
|
||||
|
||||
// first 2 colours can be whatever
|
||||
self.vbox_combine(vec![0, 1, combo_i]).ok();
|
||||
self.vbox_combine(vec![0, 1, combo_i], vec![]).ok();
|
||||
let item_i = self.vbox.bound.len() - 1;
|
||||
self.vbox_apply(item_i, target_construct_id).ok();
|
||||
}
|
||||
@ -257,8 +257,8 @@ impl Player {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn vbox_combine(&mut self, indices: Vec<usize>) -> Result<&mut Player, Error> {
|
||||
self.vbox.combine(indices)?;
|
||||
pub fn vbox_combine(&mut self, inv_indices: Vec<usize>, vbox_indices: Vec<Vec<usize>>) -> Result<&mut Player, Error> {
|
||||
self.vbox.combine(inv_indices, vbox_indices)?;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
|
||||
@ -115,7 +115,7 @@ pub enum RpcRequest {
|
||||
VboxAccept { instance_id: Uuid, group: usize, index: usize },
|
||||
VboxAcceptEquip { instance_id: Uuid, group: usize, index: usize, construct_id: Uuid },
|
||||
VboxDiscard { instance_id: Uuid },
|
||||
VboxCombine { instance_id: Uuid, indices: Vec<usize> },
|
||||
VboxCombine { instance_id: Uuid, inv_indices: Vec<usize>, vbox_indices: Vec<Vec<usize>> },
|
||||
VboxApply { instance_id: Uuid, construct_id: Uuid, index: usize },
|
||||
VboxUnequip { instance_id: Uuid, construct_id: Uuid, target: Item },
|
||||
VboxUnequipApply { instance_id: Uuid, construct_id: Uuid, target: Item, target_construct_id: Uuid },
|
||||
@ -249,8 +249,8 @@ impl Connection {
|
||||
RpcRequest::VboxApply { instance_id, construct_id, index } =>
|
||||
Ok(RpcMessage::InstanceState(vbox_apply(&mut tx, account, instance_id, construct_id, index)?)),
|
||||
|
||||
RpcRequest::VboxCombine { instance_id, indices } =>
|
||||
Ok(RpcMessage::InstanceState(vbox_combine(&mut tx, account, instance_id, indices)?)),
|
||||
RpcRequest::VboxCombine { instance_id, inv_indices, vbox_indices } =>
|
||||
Ok(RpcMessage::InstanceState(vbox_combine(&mut tx, account, instance_id, inv_indices, vbox_indices)?)),
|
||||
|
||||
RpcRequest::VboxDiscard { instance_id } =>
|
||||
Ok(RpcMessage::InstanceState(vbox_discard(&mut tx, account, instance_id)?)),
|
||||
|
||||
@ -142,19 +142,14 @@ impl Vbox {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn combine(&mut self, mut indices: Vec<usize>) -> Result<&mut Vbox, Error> {
|
||||
if indices.len() != 3 {
|
||||
return Err(err_msg("exactly 3 indices required"));
|
||||
}
|
||||
|
||||
if !indices.iter().all(|i| self.bound.get(*i).is_some()) {
|
||||
pub fn combine(&mut self, mut inv_indices: Vec<usize>, mut 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"));
|
||||
}
|
||||
|
||||
// have to sort the indices and keep track of the iteration
|
||||
// because when removing the elements the array shifts
|
||||
indices.sort_unstable();
|
||||
let mut input = indices
|
||||
inv_indices.sort_unstable();
|
||||
let mut input = inv_indices
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, index)| {
|
||||
@ -187,9 +182,9 @@ pub fn vbox_accept(tx: &mut Transaction, account: &Account, instance_id: Uuid, g
|
||||
return instance_update(tx, instance);
|
||||
}
|
||||
|
||||
pub fn vbox_combine(tx: &mut Transaction, account: &Account, instance_id: Uuid, indices: Vec<usize>) -> Result<Instance, Error> {
|
||||
pub fn vbox_combine(tx: &mut Transaction, account: &Account, instance_id: Uuid, inv_indices: Vec<usize>, vbox_indices: Vec<Vec<usize>>) -> Result<Instance, Error> {
|
||||
let instance = instance_get(tx, instance_id)?
|
||||
.vbox_combine(account.id, indices)?;
|
||||
.vbox_combine(account.id, inv_indices, vbox_indices)?;
|
||||
return instance_update(tx, instance);
|
||||
}
|
||||
|
||||
@ -219,7 +214,7 @@ mod tests {
|
||||
fn combine_test() {
|
||||
let mut vbox = Vbox::new();
|
||||
vbox.bound = vec![Item::Attack, Item::Green, Item::Green];
|
||||
vbox.combine(vec![1,2,0]).unwrap();
|
||||
vbox.combine(vec![1,2,0], vec![]).unwrap();
|
||||
assert_eq!(vbox.bound[0], Item::Heal);
|
||||
}
|
||||
|
||||
@ -240,7 +235,7 @@ mod tests {
|
||||
let mut vbox = Vbox::new();
|
||||
vbox.bound = vec![Item::Strike];
|
||||
vbox.reclaim(0).unwrap();
|
||||
assert_eq!(vbox.bits, 20);
|
||||
assert_eq!(vbox.bits, 32);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user