Merge branch 'master' of ssh://cryps.gg:40022/~/cryps
This commit is contained in:
+28
-8
@@ -753,6 +753,32 @@ fn generate_mob(lvl: u8) -> Cryp {
|
||||
|
||||
}
|
||||
|
||||
fn generate_mob_team(mode: String, cryps: &Vec<Cryp>) -> Team {
|
||||
|
||||
let mut mob_team = Team::new(Uuid::nil());
|
||||
|
||||
// Default settings
|
||||
let mut team_size = 1;
|
||||
let mut mob_lvl = 1;
|
||||
|
||||
// Modify the NPC cryps for game mode settings
|
||||
if (mode == "normal") {
|
||||
team_size = cryps.len();
|
||||
mob_lvl = cryps.iter().max_by_key(|c| c.lvl).unwrap().lvl;
|
||||
} else if (mode == "boss") {
|
||||
mob_lvl = cryps.iter().max_by_key(|c| c.lvl).unwrap().lvl + 2;
|
||||
}
|
||||
|
||||
// Generate and return the NPC team based on settings
|
||||
let mobs = iter::repeat_with(|| generate_mob(mob_lvl).set_account(Uuid::nil()))
|
||||
.take(team_size)
|
||||
.collect::<Vec<Cryp>>();
|
||||
mob_team.set_cryps(mobs);
|
||||
|
||||
return mob_team;
|
||||
|
||||
}
|
||||
|
||||
pub fn game_pve(params: GamePveParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
|
||||
let cryps = params.cryp_ids
|
||||
.iter()
|
||||
@@ -773,19 +799,13 @@ pub fn game_pve(params: GamePveParams, tx: &mut Transaction, account: &Account)
|
||||
.set_team_size(cryps.len());
|
||||
|
||||
// create the mob team
|
||||
let mut mob_team = Team::new(Uuid::nil());
|
||||
let mob_lvl = cryps.iter().max_by_key(|c| c.lvl).unwrap().lvl;
|
||||
let mobs = iter::repeat_with(|| generate_mob(mob_lvl).set_account(Uuid::nil()))
|
||||
.take(cryps.len())
|
||||
.collect::<Vec<Cryp>>();
|
||||
|
||||
let mut mob_team = generate_mob_team(params.mode, &cryps);
|
||||
|
||||
// add the players
|
||||
let mut plr_team = Team::new(account.id);
|
||||
plr_team
|
||||
.set_cryps(cryps);
|
||||
|
||||
mob_team
|
||||
.set_cryps(mobs);
|
||||
|
||||
game
|
||||
.team_add(plr_team)?
|
||||
|
||||
@@ -395,6 +395,7 @@ struct GamePveMsg {
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
pub struct GamePveParams {
|
||||
pub cryp_ids: Vec<Uuid>,
|
||||
pub mode: String,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
|
||||
Reference in New Issue
Block a user