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 setAccount = value => ({ type: 'SET_ACCOUNT', value });
|
||||||
export const setActiveConstruct = value => ({ type: 'SET_ACTIVE_CONSTRUCT', 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 setActiveItem = value => ({ type: 'SET_ACTIVE_VAR', value });
|
||||||
export const setActiveSkill = (constructId, skill) => ({ type: 'SET_ACTIVE_SKILL', value: constructId ? { constructId, skill } : null });
|
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) });
|
export const setCombiner = value => ({ type: 'SET_COMBINER', value: Array.from(value) });
|
||||||
|
|||||||
@ -21,4 +21,4 @@ pub fn img_molecular_create(id: Uuid) -> Result<Uuid, Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Err(err_msg("too many missing molecules. wrong directory?"))
|
return Err(err_msg("too many missing molecules. wrong directory?"))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,11 +17,12 @@ use rpc::{InstanceLobbyParams, InstanceJoinParams, InstanceReadyParams, Instance
|
|||||||
use account::Account;
|
use account::Account;
|
||||||
use player::{Player, player_create};
|
use player::{Player, player_create};
|
||||||
use construct::{Construct, construct_get};
|
use construct::{Construct, construct_get};
|
||||||
use mob::{instance_mobs};
|
use mob::{bot_player};
|
||||||
use game::{Game, Phase, game_get, game_write};
|
use game::{Game, Phase, game_get, game_write};
|
||||||
use item::{Item};
|
use item::{Item};
|
||||||
use rpc::{RpcResult};
|
use rpc::{RpcResult};
|
||||||
use names::{name};
|
use names::{name};
|
||||||
|
use img::{img_molecular_create};
|
||||||
|
|
||||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||||
enum InstancePhase {
|
enum InstancePhase {
|
||||||
@ -207,22 +208,6 @@ impl Instance {
|
|||||||
self
|
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> {
|
fn add_player(&mut self, player: Player) -> Result<&mut Instance, Error> {
|
||||||
if self.players.len() >= self.max_players {
|
if self.players.len() >= self.max_players {
|
||||||
return Err(err_msg("game full"))
|
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> {
|
pub fn instance_new(params: InstanceLobbyParams, tx: &mut Transaction, account: &Account) -> Result<Instance, Error> {
|
||||||
let mut instance = match params.pve {
|
let mut instance = match params.pve {
|
||||||
true => Instance::new()
|
true => {
|
||||||
.set_time_control(TimeControl::Practice)
|
let bot = bot_player();
|
||||||
.set_max_rounds(10)
|
|
||||||
.set_name(params.name)?
|
|
||||||
.add_bots(),
|
|
||||||
|
|
||||||
|
// 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)?;
|
||||||
|
|
||||||
|
instance.add_player(bot)?;
|
||||||
|
|
||||||
|
instance
|
||||||
|
},
|
||||||
false => Instance::new()
|
false => Instance::new()
|
||||||
.set_name(params.name)?
|
.set_name(params.name)?
|
||||||
};
|
};
|
||||||
@ -795,11 +791,10 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn instance_pve_test() {
|
fn instance_pve_test() {
|
||||||
let mut instance = Instance::new().add_bots();
|
let mut instance = Instance::new();
|
||||||
|
|
||||||
let player_account = Uuid::new_v4();
|
let player = bot_player();
|
||||||
let constructs = instance_mobs(player_account);
|
let player_account = player.id;
|
||||||
let player = Player::new(player_account, &"test".to_string(), constructs).set_bot(true);
|
|
||||||
|
|
||||||
instance.add_player(player).expect("could not add player");
|
instance.add_player(player).expect("could not add player");
|
||||||
|
|
||||||
@ -813,9 +808,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn instance_bot_vbox_test() {
|
fn instance_bot_vbox_test() {
|
||||||
let _instance = Instance::new();
|
let _instance = Instance::new();
|
||||||
let player_account = Uuid::new_v4();
|
let player = bot_player();
|
||||||
let constructs = instance_mobs(player_account);
|
|
||||||
let _player = Player::new(player_account, &"test".to_string(), constructs).set_bot(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -824,17 +817,13 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(instance.max_players, 2);
|
assert_eq!(instance.max_players, 2);
|
||||||
|
|
||||||
let player_account = Uuid::new_v4();
|
let player = bot_player();
|
||||||
let constructs = instance_mobs(player_account);
|
|
||||||
let player = Player::new(player_account, &"a".to_string(), constructs);
|
|
||||||
let a_id = player.id;
|
let a_id = player.id;
|
||||||
|
|
||||||
instance.add_player(player).expect("could not add player");
|
instance.add_player(player).expect("could not add player");
|
||||||
assert!(!instance.can_start());
|
assert!(!instance.can_start());
|
||||||
|
|
||||||
let player_account = Uuid::new_v4();
|
let player = bot_player();
|
||||||
let constructs = instance_mobs(player_account);
|
|
||||||
let player = Player::new(player_account, &"b".to_string(), constructs);
|
|
||||||
let b_id = player.id;
|
let b_id = player.id;
|
||||||
|
|
||||||
instance.add_player(player).expect("could not add player");
|
instance.add_player(player).expect("could not add player");
|
||||||
@ -861,17 +850,13 @@ mod tests {
|
|||||||
fn instance_upkeep_test() {
|
fn instance_upkeep_test() {
|
||||||
let mut instance = Instance::new();
|
let mut instance = Instance::new();
|
||||||
|
|
||||||
let player_account = Uuid::new_v4();
|
let player = bot_player();
|
||||||
let constructs = instance_mobs(player_account);
|
|
||||||
let player = Player::new(player_account, &"a".to_string(), constructs);
|
|
||||||
let a_id = player.id;
|
let a_id = player.id;
|
||||||
|
|
||||||
instance.add_player(player).expect("could not add player");
|
instance.add_player(player).expect("could not add player");
|
||||||
assert!(!instance.can_start());
|
assert!(!instance.can_start());
|
||||||
|
|
||||||
let player_account = Uuid::new_v4();
|
let player = bot_player();
|
||||||
let constructs = instance_mobs(player_account);
|
|
||||||
let player = Player::new(player_account, &"b".to_string(), constructs);
|
|
||||||
let b_id = player.id;
|
let b_id = player.id;
|
||||||
instance.add_player(player).expect("could not add player");
|
instance.add_player(player).expect("could not add player");
|
||||||
|
|
||||||
@ -901,9 +886,7 @@ mod tests {
|
|||||||
fn instance_upkeep_idle_lobby_test() {
|
fn instance_upkeep_idle_lobby_test() {
|
||||||
let mut instance = Instance::new();
|
let mut instance = Instance::new();
|
||||||
|
|
||||||
let player_account = Uuid::new_v4();
|
let player = bot_player();
|
||||||
let constructs = instance_mobs(player_account);
|
|
||||||
let player = Player::new(player_account, &"a".to_string(), constructs);
|
|
||||||
let _a_id = player.id;
|
let _a_id = player.id;
|
||||||
|
|
||||||
instance.add_player(player).expect("could not add player");
|
instance.add_player(player).expect("could not add player");
|
||||||
|
|||||||
@ -4,6 +4,7 @@ use std::iter;
|
|||||||
|
|
||||||
use construct::{Construct};
|
use construct::{Construct};
|
||||||
use names::{name};
|
use names::{name};
|
||||||
|
use player::{Player};
|
||||||
|
|
||||||
pub fn generate_mob() -> Construct {
|
pub fn generate_mob() -> Construct {
|
||||||
let mob = Construct::new()
|
let mob = Construct::new()
|
||||||
@ -20,3 +21,12 @@ pub fn instance_mobs(player_id: Uuid) -> Vec<Construct> {
|
|||||||
.take(3)
|
.take(3)
|
||||||
.collect::<Vec<Construct>>()
|
.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