mob imgs
This commit is contained in:
parent
f72a9b85a5
commit
c54c6f00e7
@ -1,5 +1,6 @@
|
||||
export const setAccount = value => ({ type: 'SET_ACCOUNT', value });
|
||||
export const setActiveConstruct = value => ({ type: 'SET_ACTIVE_CONSTRUCT', value });
|
||||
export const setAvatarAnimation = value => ({ type: 'SET_AVATAR_ANIMATION', value });
|
||||
export const setActiveItem = value => ({ type: 'SET_ACTIVE_VAR', value });
|
||||
export const setActiveSkill = (constructId, skill) => ({ type: 'SET_ACTIVE_SKILL', value: constructId ? { constructId, skill } : null });
|
||||
export const setCombiner = value => ({ type: 'SET_COMBINER', value: Array.from(value) });
|
||||
|
||||
@ -17,11 +17,12 @@ use rpc::{InstanceLobbyParams, InstanceJoinParams, InstanceReadyParams, Instance
|
||||
use account::Account;
|
||||
use player::{Player, player_create};
|
||||
use construct::{Construct, construct_get};
|
||||
use mob::{instance_mobs};
|
||||
use mob::{bot_player};
|
||||
use game::{Game, Phase, game_get, game_write};
|
||||
use item::{Item};
|
||||
use rpc::{RpcResult};
|
||||
use names::{name};
|
||||
use img::{img_molecular_create};
|
||||
|
||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||
enum InstancePhase {
|
||||
@ -207,22 +208,6 @@ impl Instance {
|
||||
self
|
||||
}
|
||||
|
||||
fn add_bots(mut self) -> Instance {
|
||||
self.open = false;
|
||||
iter::repeat_with(|| {
|
||||
let bot_id = Uuid::new_v4();
|
||||
let constructs = instance_mobs(bot_id);
|
||||
let mut p = Player::new(bot_id, &name(), constructs).set_bot(true);
|
||||
p.set_ready(true);
|
||||
p
|
||||
})
|
||||
// .take(self.max_players - self.players.len())
|
||||
.take(1)
|
||||
.for_each(|p| self.players.push(p));
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
fn add_player(&mut self, player: Player) -> Result<&mut Instance, Error> {
|
||||
if self.players.len() >= self.max_players {
|
||||
return Err(err_msg("game full"))
|
||||
@ -718,12 +703,23 @@ pub fn instances_idle(tx: &mut Transaction) -> Result<Vec<Instance>, Error> {
|
||||
|
||||
pub fn instance_new(params: InstanceLobbyParams, tx: &mut Transaction, account: &Account) -> Result<Instance, Error> {
|
||||
let mut instance = match params.pve {
|
||||
true => Instance::new()
|
||||
true => {
|
||||
let bot = bot_player();
|
||||
|
||||
// generate bot imgs only in the real world
|
||||
for c in bot.constructs.iter() {
|
||||
img_molecular_create(c.img)?;
|
||||
}
|
||||
|
||||
let mut instance = Instance::new()
|
||||
.set_time_control(TimeControl::Practice)
|
||||
.set_max_rounds(10)
|
||||
.set_name(params.name)?
|
||||
.add_bots(),
|
||||
.set_name(params.name)?;
|
||||
|
||||
instance.add_player(bot)?;
|
||||
|
||||
instance
|
||||
},
|
||||
false => Instance::new()
|
||||
.set_name(params.name)?
|
||||
};
|
||||
@ -795,11 +791,10 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn instance_pve_test() {
|
||||
let mut instance = Instance::new().add_bots();
|
||||
let mut instance = Instance::new();
|
||||
|
||||
let player_account = Uuid::new_v4();
|
||||
let constructs = instance_mobs(player_account);
|
||||
let player = Player::new(player_account, &"test".to_string(), constructs).set_bot(true);
|
||||
let player = bot_player();
|
||||
let player_account = player.id;
|
||||
|
||||
instance.add_player(player).expect("could not add player");
|
||||
|
||||
@ -813,9 +808,7 @@ mod tests {
|
||||
#[test]
|
||||
fn instance_bot_vbox_test() {
|
||||
let _instance = Instance::new();
|
||||
let player_account = Uuid::new_v4();
|
||||
let constructs = instance_mobs(player_account);
|
||||
let _player = Player::new(player_account, &"test".to_string(), constructs).set_bot(true);
|
||||
let player = bot_player();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -824,17 +817,13 @@ mod tests {
|
||||
|
||||
assert_eq!(instance.max_players, 2);
|
||||
|
||||
let player_account = Uuid::new_v4();
|
||||
let constructs = instance_mobs(player_account);
|
||||
let player = Player::new(player_account, &"a".to_string(), constructs);
|
||||
let player = bot_player();
|
||||
let a_id = player.id;
|
||||
|
||||
instance.add_player(player).expect("could not add player");
|
||||
assert!(!instance.can_start());
|
||||
|
||||
let player_account = Uuid::new_v4();
|
||||
let constructs = instance_mobs(player_account);
|
||||
let player = Player::new(player_account, &"b".to_string(), constructs);
|
||||
let player = bot_player();
|
||||
let b_id = player.id;
|
||||
|
||||
instance.add_player(player).expect("could not add player");
|
||||
@ -861,17 +850,13 @@ mod tests {
|
||||
fn instance_upkeep_test() {
|
||||
let mut instance = Instance::new();
|
||||
|
||||
let player_account = Uuid::new_v4();
|
||||
let constructs = instance_mobs(player_account);
|
||||
let player = Player::new(player_account, &"a".to_string(), constructs);
|
||||
let player = bot_player();
|
||||
let a_id = player.id;
|
||||
|
||||
instance.add_player(player).expect("could not add player");
|
||||
assert!(!instance.can_start());
|
||||
|
||||
let player_account = Uuid::new_v4();
|
||||
let constructs = instance_mobs(player_account);
|
||||
let player = Player::new(player_account, &"b".to_string(), constructs);
|
||||
let player = bot_player();
|
||||
let b_id = player.id;
|
||||
instance.add_player(player).expect("could not add player");
|
||||
|
||||
@ -901,9 +886,7 @@ mod tests {
|
||||
fn instance_upkeep_idle_lobby_test() {
|
||||
let mut instance = Instance::new();
|
||||
|
||||
let player_account = Uuid::new_v4();
|
||||
let constructs = instance_mobs(player_account);
|
||||
let player = Player::new(player_account, &"a".to_string(), constructs);
|
||||
let player = bot_player();
|
||||
let _a_id = player.id;
|
||||
|
||||
instance.add_player(player).expect("could not add player");
|
||||
|
||||
@ -4,6 +4,7 @@ use std::iter;
|
||||
|
||||
use construct::{Construct};
|
||||
use names::{name};
|
||||
use player::{Player};
|
||||
|
||||
pub fn generate_mob() -> Construct {
|
||||
let mob = Construct::new()
|
||||
@ -20,3 +21,12 @@ pub fn instance_mobs(player_id: Uuid) -> Vec<Construct> {
|
||||
.take(3)
|
||||
.collect::<Vec<Construct>>()
|
||||
}
|
||||
|
||||
pub fn bot_player() -> Player {
|
||||
let bot_id = Uuid::new_v4();
|
||||
let constructs = instance_mobs(bot_id);
|
||||
let mut p = Player::new(bot_id, &name(), constructs).set_bot(true);
|
||||
p.set_ready(true);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user