clean up equipping api
This commit is contained in:
parent
18126c1b0c
commit
91c82324e2
@ -84,7 +84,7 @@ function createSocket(events) {
|
||||
}
|
||||
|
||||
function sendVboxBuyEquip(instanceId, group, index, constructId) {
|
||||
send(['VboxBuyEquip', { instance_id: instanceId, group, index, construct_id: constructId }]);
|
||||
send(['VboxBuy', { instance_id: instanceId, group, index, construct_id: constructId }]);
|
||||
events.clearInstance();
|
||||
}
|
||||
|
||||
|
||||
@ -497,7 +497,7 @@ impl Instance {
|
||||
pub fn vbox_apply(mut self, account: Uuid, index: String, construct_id: Uuid) -> Result<Instance, Error> {
|
||||
self.vbox_action_allowed(account)?;
|
||||
self.account_player(account)?
|
||||
.vbox_apply(index, construct_id)?;
|
||||
.vbox_equip(index, construct_id)?;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
|
||||
@ -174,7 +174,8 @@ impl Player {
|
||||
// AAAAAAAAAAAAAAAAAAAA
|
||||
// there's a bad bug here where if this apply fails
|
||||
// the item in question will be silently dropped
|
||||
self.vbox_apply(i, construct_id).ok();
|
||||
let item = self.vbox.stash.remove(&i).unwrap();
|
||||
self.vbox_apply(item, construct_id).ok();
|
||||
continue;
|
||||
}
|
||||
// need to buy one
|
||||
@ -228,7 +229,8 @@ impl Player {
|
||||
// AAAAAAAAAAAAAAAAAAAA
|
||||
// there's a bad bug here where if this apply fails
|
||||
// the item in question will be silently dropped
|
||||
self.vbox_apply(i, construct_id).ok();
|
||||
let item = self.vbox.stash.remove(&i).unwrap();
|
||||
self.vbox_apply(item, construct_id).ok();
|
||||
continue;
|
||||
}
|
||||
// need to buy one
|
||||
@ -267,79 +269,6 @@ impl Player {
|
||||
// upgrading phase
|
||||
// NYI
|
||||
|
||||
// // first check if any constructs have no skills
|
||||
// // if there is one find an item in vbox that gives a skill
|
||||
// while let Some(c) = self.constructs.iter().position(|c| c.skills.len() == 0) {
|
||||
// if let Some(s) = self.vbox.stash.iter().position(|(i, v)| v.into_skill().is_some()) {
|
||||
// let construct_id = self.constructs[c].id;
|
||||
// self.vbox_apply(s, construct_id).expect("could not apply");
|
||||
// continue;
|
||||
// }
|
||||
// info!("no skills available...");
|
||||
// }
|
||||
|
||||
// // now keep buying and applying items cause whynot
|
||||
// // inb4 montecarlo gan
|
||||
// loop {
|
||||
// let (target_construct_i, target_construct_id) = match self.constructs.iter().any(|c| c.skills.len() < 3) {
|
||||
// true => {
|
||||
// let mut target_construct_i = 0;
|
||||
// for (j, c) in self.constructs.iter().enumerate() {
|
||||
// if c.skills.len() < self.constructs[target_construct_i].skills.len() {
|
||||
// target_construct_i = j;
|
||||
// }
|
||||
// }
|
||||
// (target_construct_i, self.constructs[target_construct_i].id)
|
||||
// },
|
||||
// false => {
|
||||
// let i = rng.gen_range(0, 3);
|
||||
// (i, self.constructs[i].id)
|
||||
// },
|
||||
// };
|
||||
|
||||
// let needs_skills = self.constructs[target_construct_i].skills.len() < 3;
|
||||
// let group_i = match needs_skills {
|
||||
// true => 1,
|
||||
// false => 2,
|
||||
// };
|
||||
|
||||
|
||||
// let num_colours = self.vbox.stash
|
||||
// .iter()
|
||||
// .filter(|(i, v)| [Item::Red, Item::Green, Item::Blue].contains(v))
|
||||
// .count();
|
||||
|
||||
// if self.vbox.stash.len() < 3 || num_colours < 2 {
|
||||
// if (needs_skills && self.vbox.bits < 4) || self.vbox.bits < 5 {
|
||||
// // info!("insufficient balance");
|
||||
// break;
|
||||
// }
|
||||
|
||||
// // get 2 colours and something else
|
||||
// let store_colours = self.vbox.store[&ItemType::Colours].len();
|
||||
// if store_colours < 2 {
|
||||
// break;
|
||||
// }
|
||||
// self.bot_vbox_accept(0).expect("could't accept colour item");
|
||||
// self.bot_vbox_accept(0).expect("could't accept colour item");
|
||||
// self.bot_vbox_accept(group_i).expect("could't accept group item");
|
||||
// }
|
||||
|
||||
// // info!("{:?}", self.vbox.stash);
|
||||
|
||||
// let skills = [Item::Attack, Item::Block, Item::Buff, Item::Debuff, Item::Stun];
|
||||
// let combo_i = match group_i {
|
||||
// 1 => self.vbox.stash.iter().position(|v| skills.contains(v)).expect("no skill found"),
|
||||
// 2 => self.vbox.stash.iter().position(|v| v.into_spec().is_some()).expect("no spec found"),
|
||||
// _ => panic!("unknown group_i"),
|
||||
// };
|
||||
|
||||
// // first 2 colours can be whatever
|
||||
// self.vbox_combine(vec![0, 1, combo_i], vec![]).ok();
|
||||
// let item_i = self.vbox.stash.len() - 1;
|
||||
// self.vbox_apply(item_i, target_construct_id).ok();
|
||||
// }
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -359,7 +288,7 @@ impl Player {
|
||||
let item = self.vbox.buy(group, &index)?;
|
||||
|
||||
match construct_id {
|
||||
Some(id) => { self.vbox_apply(index, id)?; },
|
||||
Some(id) => { self.vbox_apply(item, id)?; },
|
||||
None => { self.vbox.stash_add(item, None)?; },
|
||||
};
|
||||
|
||||
@ -376,10 +305,14 @@ impl Player {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn vbox_apply(&mut self, index: String, construct_id: Uuid) -> Result<&mut Player, Error> {
|
||||
pub fn vbox_equip(&mut self, index: String, construct_id: Uuid) -> Result<&mut Player, Error> {
|
||||
let item = self.vbox.stash.remove(&index)
|
||||
.ok_or(format_err!("no item at index {:?} {:?}", self.vbox.stash, index))?;
|
||||
.ok_or(format_err!("no item at index {:?} {:}", self, &index))?;
|
||||
|
||||
self.vbox_apply(item, construct_id)
|
||||
}
|
||||
|
||||
pub fn vbox_apply(&mut self, item: Item, construct_id: Uuid) -> Result<&mut Player, Error> {
|
||||
match item.effect() {
|
||||
Some(ItemEffect::Skill) => {
|
||||
let skill = item.into_skill().ok_or(format_err!("item {:?} has no associated skill", item))?;
|
||||
@ -455,12 +388,10 @@ impl Player {
|
||||
construct.apply_modifiers(&player_colours);
|
||||
}
|
||||
|
||||
let equip_index = self.vbox.stash_add(target, None)?;
|
||||
|
||||
if target_construct_id.is_some() {
|
||||
self.vbox_apply(equip_index, target_construct_id.expect("no construct"))?;
|
||||
}
|
||||
// self.vbox.stash.sort_unstable();
|
||||
match target_construct_id {
|
||||
Some(cid) => { self.vbox_apply(target, cid)?; },
|
||||
None => { self.vbox.stash_add(target, None)?; },
|
||||
};
|
||||
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
@ -115,8 +115,7 @@ pub enum RpcRequest {
|
||||
InstanceState { instance_id: Uuid },
|
||||
InstanceChat { instance_id: Uuid, index: usize },
|
||||
|
||||
VboxBuy { instance_id: Uuid, group: ItemType, index: String },
|
||||
VboxBuyEquip { instance_id: Uuid, group: ItemType, index: String, construct_id: Uuid },
|
||||
VboxBuy { instance_id: Uuid, group: ItemType, index: String, construct_id: Option<Uuid> },
|
||||
VboxRefill { instance_id: Uuid },
|
||||
VboxCombine { instance_id: Uuid, inv_indices: Vec<String>, vbox_indices: Option<HashMap<ItemType, Vec<String>>> },
|
||||
VboxApply { instance_id: Uuid, construct_id: Uuid, index: String },
|
||||
@ -246,11 +245,8 @@ impl Connection {
|
||||
RpcRequest::InstanceAbandon { instance_id } =>
|
||||
Ok(instance_abandon(&mut tx, account, instance_id)?),
|
||||
|
||||
RpcRequest::VboxBuy { instance_id, group, index } =>
|
||||
Ok(RpcMessage::InstanceState(vbox_buy(&mut tx, account, instance_id, group, index, None)?)),
|
||||
|
||||
RpcRequest::VboxBuyEquip { instance_id, group, index, construct_id } =>
|
||||
Ok(RpcMessage::InstanceState(vbox_buy(&mut tx, account, instance_id, group, index, Some(construct_id))?)),
|
||||
RpcRequest::VboxBuy { instance_id, group, index, construct_id } =>
|
||||
Ok(RpcMessage::InstanceState(vbox_buy(&mut tx, account, instance_id, group, index, construct_id)?)),
|
||||
|
||||
RpcRequest::VboxApply { instance_id, construct_id, index } =>
|
||||
Ok(RpcMessage::InstanceState(vbox_apply(&mut tx, account, instance_id, construct_id, index)?)),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user