vbox split
This commit is contained in:
parent
fd1c693f01
commit
897ace6ed2
@ -193,7 +193,7 @@ impl Instance {
|
|||||||
|
|
||||||
fn bot_vbox_phase(&mut self) -> &mut Instance {
|
fn bot_vbox_phase(&mut self) -> &mut Instance {
|
||||||
for bot in self.players.iter_mut().filter(|p| p.bot) {
|
for bot in self.players.iter_mut().filter(|p| p.bot) {
|
||||||
bot.vbox.fill(false);
|
bot.vbox.fill();
|
||||||
bot.set_ready(true);
|
bot.set_ready(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,7 +401,7 @@ pub fn instance_join(params: InstanceJoinParams, tx: &mut Transaction, account:
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut player = Player::new(account.id, instance.id, cryps);
|
let mut player = Player::new(account.id, instance.id, cryps);
|
||||||
player.vbox.fill(true);
|
player.vbox.fill();
|
||||||
player_create(tx, &player, account)?;
|
player_create(tx, &player, account)?;
|
||||||
|
|
||||||
instance.add_player(player.clone());
|
instance.add_player(player.clone());
|
||||||
@ -496,7 +496,7 @@ pub fn instance_game_finished(tx: &mut Transaction, game: &Game, instance_id: Uu
|
|||||||
.iter()
|
.iter()
|
||||||
.filter(|p| !p.bot) {
|
.filter(|p| !p.bot) {
|
||||||
let mut player = player_get(tx, player.account, instance_id)?;
|
let mut player = player_get(tx, player.account, instance_id)?;
|
||||||
player.vbox.fill(false);
|
player.vbox.fill();
|
||||||
player_update(tx, player)?;
|
player_update(tx, player)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -598,6 +598,7 @@ struct VboxAcceptMsg {
|
|||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
pub struct VboxAcceptParams {
|
pub struct VboxAcceptParams {
|
||||||
pub instance_id: Uuid,
|
pub instance_id: Uuid,
|
||||||
|
pub group: usize,
|
||||||
pub index: usize,
|
pub index: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -34,9 +34,13 @@ pub enum Var {
|
|||||||
// specs
|
// specs
|
||||||
Damage,
|
Damage,
|
||||||
Protection,
|
Protection,
|
||||||
Healing,
|
Speed,
|
||||||
Hp,
|
Hp,
|
||||||
|
|
||||||
|
HpI,
|
||||||
|
StamI,
|
||||||
|
SpeedI,
|
||||||
|
|
||||||
Amplify,
|
Amplify,
|
||||||
Banish,
|
Banish,
|
||||||
Blast,
|
Blast,
|
||||||
@ -135,20 +139,20 @@ impl Vbox {
|
|||||||
Var::Attack,
|
Var::Attack,
|
||||||
Var::Attack,
|
Var::Attack,
|
||||||
Var::Attack,
|
Var::Attack,
|
||||||
Var::Stam5,
|
Var::HpI,
|
||||||
Var::Stam5,
|
Var::SpeedI,
|
||||||
Var::Speed5,
|
|
||||||
Var::Speed5,
|
|
||||||
Var::Damage,
|
|
||||||
Var::Damage,
|
Var::Damage,
|
||||||
|
Var::Red,
|
||||||
|
Var::Green,
|
||||||
|
Var::Blue,
|
||||||
];
|
];
|
||||||
|
|
||||||
let vbox = Vbox {
|
let mut vbox = Vbox {
|
||||||
id: Uuid::new_v4(),
|
id: Uuid::new_v4(),
|
||||||
account: account_id,
|
account: account_id,
|
||||||
instance: instance_id,
|
instance: instance_id,
|
||||||
free: starting_items,
|
free: vec![],
|
||||||
bound: vec![],
|
bound: starting_items,
|
||||||
balance: 9,
|
balance: 9,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -175,36 +179,37 @@ impl Vbox {
|
|||||||
let specs = vec![
|
let specs = vec![
|
||||||
(Var::Damage, 1),
|
(Var::Damage, 1),
|
||||||
(Var::Protection, 1),
|
(Var::Protection, 1),
|
||||||
(Var::Healing, 1),
|
(Var::Speed, 1),
|
||||||
(Var::Hp, 1),
|
(Var::Hp, 1),
|
||||||
];
|
];
|
||||||
|
|
||||||
let mut free = vec![];
|
|
||||||
|
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
for i in 0..18 {
|
|
||||||
let vars = match i {
|
|
||||||
0...5 => &colours,
|
|
||||||
6...11 => &skills,
|
|
||||||
12...17 => &specs,
|
|
||||||
_ => panic!("vars oor"),
|
|
||||||
};
|
|
||||||
let dist = WeightedIndex::new(vars.iter().map(|item| item.1)).unwrap();
|
|
||||||
free.push(vars[dist.sample(&mut rng)].0);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.free = free;
|
self.free = [&colours, &skills, &specs].iter()
|
||||||
|
.map(|vars| {
|
||||||
|
let dist = WeightedIndex::new(vars.iter().map(|item| item.1)).unwrap();
|
||||||
|
|
||||||
|
iter::repeat_with(|| {
|
||||||
|
vars[dist.sample(&mut rng)].0
|
||||||
|
})
|
||||||
|
.take(6)
|
||||||
|
.collect::<Vec<Var>>()
|
||||||
|
})
|
||||||
|
.collect::<Vec<Vec<Var>>>();
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn accept(&mut self, i: usize) -> Result<&mut Vbox, Error> {
|
pub fn accept(&mut self, i: usize, j: usize) -> Result<&mut Vbox, Error> {
|
||||||
if self.bound.len() >= 9 {
|
if self.bound.len() >= 9 {
|
||||||
return Err(err_msg("too many vars bound"));
|
return Err(err_msg("too many vars bound"));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.free.get(i).ok_or(format_err!("no var at index {:?}", i))?;
|
self.free
|
||||||
self.bound.push(self.free.remove(i));
|
.get(i).ok_or(format_err!("no var group at index {:?}", i))?
|
||||||
|
.get(j).ok_or(format_err!("no var at index {:?}", j))?;
|
||||||
|
|
||||||
|
self.bound.push(self.free[i].remove(j));
|
||||||
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
@ -318,13 +323,13 @@ impl Vbox {
|
|||||||
|
|
||||||
pub fn vbox_discard(params: VboxDiscardParams, tx: &mut Transaction, account: &Account) -> Result<Player, Error> {
|
pub fn vbox_discard(params: VboxDiscardParams, tx: &mut Transaction, account: &Account) -> Result<Player, Error> {
|
||||||
let mut player = player_get(tx, account.id, params.instance_id)?;
|
let mut player = player_get(tx, account.id, params.instance_id)?;
|
||||||
player.vbox.fill(false);
|
player.vbox.fill();
|
||||||
return player_update(tx, player);
|
return player_update(tx, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn vbox_accept(params: VboxAcceptParams, tx: &mut Transaction, account: &Account) -> Result<Player, Error> {
|
pub fn vbox_accept(params: VboxAcceptParams, tx: &mut Transaction, account: &Account) -> Result<Player, Error> {
|
||||||
let mut player = player_get(tx, account.id, params.instance_id)?;
|
let mut player = player_get(tx, account.id, params.instance_id)?;
|
||||||
player.vbox.accept(params.index)?;
|
player.vbox.accept(params.group, params.index)?;
|
||||||
return player_update(tx, player);
|
return player_update(tx, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user