bigtime renaming

This commit is contained in:
ntr
2019-05-25 15:20:38 +10:00
parent 4800609df7
commit 760106e0e7
91 changed files with 1642 additions and 1615 deletions
+13 -13
View File
@@ -1,5 +1,5 @@
use uuid::Uuid;
use bcrypt::{hash, verify};
use bconstructt::{hash, verify};
use rand::{thread_rng, Rng};
use rand::distributions::Alphanumeric;
use std::iter;
@@ -9,7 +9,7 @@ use postgres::transaction::Transaction;
use rpc::{AccountCreateParams, AccountLoginParams};
use cryp::{Cryp, cryp_recover};
use construct::{Construct, construct_recover};
use instance::{Instance, instance_delete};
use failure::Error;
@@ -155,34 +155,34 @@ pub fn account_login(params: AccountLoginParams, tx: &mut Transaction) -> Result
return Ok(account);
}
pub fn account_cryps(tx: &mut Transaction, account: &Account) -> Result<Vec<Cryp>, Error> {
pub fn account_constructs(tx: &mut Transaction, account: &Account) -> Result<Vec<Construct>, Error> {
let query = "
SELECT data
FROM cryps
FROM constructs
WHERE account = $1;
";
let result = tx
.query(query, &[&account.id])?;
let cryps: Result<Vec<Cryp>, _> = result.iter()
let constructs: Result<Vec<Construct>, _> = result.iter()
.map(|row| {
let cryp_bytes: Vec<u8> = row.get(0);
match from_slice::<Cryp>(&cryp_bytes) {
let construct_bytes: Vec<u8> = row.get(0);
match from_slice::<Construct>(&construct_bytes) {
Ok(c) => Ok(c),
Err(_e) => cryp_recover(cryp_bytes, tx),
Err(_e) => construct_recover(construct_bytes, tx),
}
})
.collect();
// catch any errors
if cryps.is_err() {
return Err(err_msg("could not deserialize a cryp"));
if constructs.is_err() {
return Err(err_msg("could not deserialize a construct"));
}
let mut cryps = cryps.unwrap();
cryps.sort_by_key(|c| c.id);
return Ok(cryps);
let mut constructs = constructs.unwrap();
constructs.sort_by_key(|c| c.id);
return Ok(constructs);
}
pub fn account_instances(tx: &mut Transaction, account: &Account) -> Result<Vec<Instance>, Error> {
+115 -115
View File
@@ -8,7 +8,7 @@ use failure::Error;
use failure::err_msg;
use account::{Account};
use rpc::{CrypSpawnParams};
use rpc::{ConstructSpawnParams};
use skill::{Skill, Cooldown, Effect, Cast, Colour, Immunity, Disable, Event};
use spec::{Spec};
use item::{Item};
@@ -25,15 +25,15 @@ impl Colours {
Colours { red: 0, green: 0, blue: 0 }
}
pub fn from_cryp(cryp: &Cryp) -> Colours {
pub fn from_construct(construct: &Construct) -> Colours {
let mut count = Colours::new();
for spec in cryp.specs.iter() {
for spec in construct.specs.iter() {
let v = Item::from(*spec);
v.colours(&mut count);
}
for cs in cryp.skills.iter() {
for cs in construct.skills.iter() {
let v = Item::from(cs.skill);
v.colours(&mut count);
}
@@ -44,15 +44,15 @@ impl Colours {
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
pub struct CrypSkill {
pub struct ConstructSkill {
pub skill: Skill,
pub self_targeting: bool,
pub cd: Cooldown,
}
impl CrypSkill {
pub fn new(skill: Skill) -> CrypSkill {
CrypSkill {
impl ConstructSkill {
pub fn new(skill: Skill) -> ConstructSkill {
ConstructSkill {
skill,
self_targeting: skill.self_targeting(),
cd: skill.base_cd(),
@@ -69,24 +69,24 @@ pub enum EffectMeta {
}
#[derive(Debug,Clone,PartialEq,Serialize,Deserialize)]
pub struct CrypEffect {
pub struct ConstructEffect {
pub effect: Effect,
pub duration: u8,
pub meta: Option<EffectMeta>,
pub tick: Option<Cast>,
}
impl CrypEffect {
pub fn new(effect: Effect, duration: u8) -> CrypEffect {
CrypEffect { effect, duration, meta: None, tick: None }
impl ConstructEffect {
pub fn new(effect: Effect, duration: u8) -> ConstructEffect {
ConstructEffect { effect, duration, meta: None, tick: None }
}
pub fn set_tick(mut self, tick: Cast) -> CrypEffect {
pub fn set_tick(mut self, tick: Cast) -> ConstructEffect {
self.tick = Some(tick);
self
}
pub fn set_meta(mut self, meta: EffectMeta) -> CrypEffect {
pub fn set_meta(mut self, meta: EffectMeta) -> ConstructEffect {
self.meta = Some(meta);
self
}
@@ -119,20 +119,20 @@ pub enum Stat {
}
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
pub struct CrypStat {
pub struct ConstructStat {
base: u64,
value: u64,
max: u64,
pub stat: Stat,
}
impl CrypStat {
// pub fn set(&mut self, v: u64, specs: &Vec<Spec>) -> &mut CrypStat {
impl ConstructStat {
// pub fn set(&mut self, v: u64, specs: &Vec<Spec>) -> &mut ConstructStat {
// self.base = v;
// self.recalculate(specs)
// }
pub fn recalculate(&mut self, specs: &Vec<Spec>, cryp_colours: &Colours, player_colours: &Colours) -> &mut CrypStat {
pub fn recalculate(&mut self, specs: &Vec<Spec>, construct_colours: &Colours, player_colours: &Colours) -> &mut ConstructStat {
let specs = specs
.iter()
.filter(|s| s.affects().contains(&self.stat))
@@ -141,19 +141,19 @@ impl CrypStat {
// applied with fold because it can be zeroed or multiplied
// but still needs access to the base amount
let value = specs.iter().fold(self.base, |acc, s| s.apply(acc, self.base, cryp_colours, player_colours));
let value = specs.iter().fold(self.base, |acc, s| s.apply(acc, self.base, construct_colours, player_colours));
self.value = value;
self.max = value;
self
}
pub fn reduce(&mut self, amt: u64) -> &mut CrypStat {
pub fn reduce(&mut self, amt: u64) -> &mut ConstructStat {
self.value = self.value.saturating_sub(amt);
self
}
pub fn increase(&mut self, amt: u64) -> &mut CrypStat {
pub fn increase(&mut self, amt: u64) -> &mut ConstructStat {
self.value = *[
self.value.saturating_add(amt),
self.max
@@ -162,7 +162,7 @@ impl CrypStat {
self
}
pub fn force(&mut self, v: u64) -> &mut CrypStat {
pub fn force(&mut self, v: u64) -> &mut ConstructStat {
self.base = v;
self.value = v;
self.max = v;
@@ -172,45 +172,45 @@ impl CrypStat {
}
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct CrypRecover {
pub struct ConstructRecover {
pub id: Uuid,
pub account: Uuid,
pub name: String,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct Cryp {
pub struct Construct {
pub id: Uuid,
pub account: Uuid,
pub red_damage: CrypStat,
pub red_life: CrypStat,
pub blue_life: CrypStat,
pub blue_damage: CrypStat,
pub green_damage: CrypStat,
pub speed: CrypStat,
pub green_life: CrypStat,
pub evasion: CrypStat,
pub skills: Vec<CrypSkill>,
pub effects: Vec<CrypEffect>,
pub red_damage: ConstructStat,
pub red_life: ConstructStat,
pub blue_life: ConstructStat,
pub blue_damage: ConstructStat,
pub green_damage: ConstructStat,
pub speed: ConstructStat,
pub green_life: ConstructStat,
pub evasion: ConstructStat,
pub skills: Vec<ConstructSkill>,
pub effects: Vec<ConstructEffect>,
pub specs: Vec<Spec>,
pub colours: Colours,
pub name: String,
}
impl Cryp {
pub fn new() -> Cryp {
impl Construct {
pub fn new() -> Construct {
let id = Uuid::new_v4();
return Cryp {
return Construct {
id,
account: id,
red_damage: CrypStat { base: 256, value: 256, max: 256, stat: Stat::RedDamage },
red_life: CrypStat { base: 0, value: 0, max: 0, stat: Stat::RedLife },
blue_damage: CrypStat { base: 256, value: 256, max: 256, stat: Stat::BlueDamage },
blue_life: CrypStat { base: 0, value: 0, max: 0, stat: Stat::BlueLife },
green_damage: CrypStat { base: 256, value: 256, max: 256, stat: Stat::GreenDamage },
green_life: CrypStat { base: 1024, value: 1024, max: 1024, stat: Stat::GreenLife },
speed: CrypStat { base: 128, value: 128, max: 128, stat: Stat::Speed },
evasion: CrypStat { base: 0, value: 0, max: 0, stat: Stat::Evasion },
red_damage: ConstructStat { base: 256, value: 256, max: 256, stat: Stat::RedDamage },
red_life: ConstructStat { base: 0, value: 0, max: 0, stat: Stat::RedLife },
blue_damage: ConstructStat { base: 256, value: 256, max: 256, stat: Stat::BlueDamage },
blue_life: ConstructStat { base: 0, value: 0, max: 0, stat: Stat::BlueLife },
green_damage: ConstructStat { base: 256, value: 256, max: 256, stat: Stat::GreenDamage },
green_life: ConstructStat { base: 1024, value: 1024, max: 1024, stat: Stat::GreenLife },
speed: ConstructStat { base: 128, value: 128, max: 128, stat: Stat::Speed },
evasion: ConstructStat { base: 0, value: 0, max: 0, stat: Stat::Evasion },
skills: vec![],
effects: vec![],
specs: vec![],
@@ -219,28 +219,28 @@ impl Cryp {
};
}
pub fn named(mut self, name: &String) -> Cryp {
pub fn named(mut self, name: &String) -> Construct {
self.name = name.clone();
self
}
pub fn set_account(mut self, account: Uuid) -> Cryp {
pub fn set_account(mut self, account: Uuid) -> Construct {
self.account = account;
self
}
pub fn learn(mut self, s: Skill) -> Cryp {
self.skills.push(CrypSkill::new(s));
self.colours = Colours::from_cryp(&self);
pub fn learn(mut self, s: Skill) -> Construct {
self.skills.push(ConstructSkill::new(s));
self.colours = Colours::from_construct(&self);
self
}
pub fn learn_mut(&mut self, s: Skill) -> &mut Cryp {
self.skills.push(CrypSkill::new(s));
pub fn learn_mut(&mut self, s: Skill) -> &mut Construct {
self.skills.push(ConstructSkill::new(s));
self.calculate_colours()
}
pub fn forget(&mut self, skill: Skill) -> Result<&mut Cryp, Error> {
pub fn forget(&mut self, skill: Skill) -> Result<&mut Construct, Error> {
match self.skills.iter().position(|s| s.skill == skill) {
Some(i) => {
self.skills.remove(i);
@@ -250,7 +250,7 @@ impl Cryp {
}
}
pub fn spec_add(&mut self, spec: Spec) -> Result<&mut Cryp, Error> {
pub fn spec_add(&mut self, spec: Spec) -> Result<&mut Construct, Error> {
if self.specs.len() >= 6 {
return Err(err_msg("maximum specs equipped"));
}
@@ -259,7 +259,7 @@ impl Cryp {
return Ok(self.calculate_colours());
}
pub fn spec_remove(&mut self, spec: Spec) -> Result<&mut Cryp, Error> {
pub fn spec_remove(&mut self, spec: Spec) -> Result<&mut Construct, Error> {
match self.specs.iter().position(|s| *s == spec) {
Some(p) => self.specs.remove(p),
None => return Err(err_msg("spec not found")),
@@ -268,12 +268,12 @@ impl Cryp {
Ok(self.calculate_colours())
}
fn calculate_colours(&mut self) -> &mut Cryp {
self.colours = Colours::from_cryp(&self);
fn calculate_colours(&mut self) -> &mut Construct {
self.colours = Colours::from_construct(&self);
self
}
pub fn apply_modifiers(&mut self, player_colours: &Colours) -> &mut Cryp {
pub fn apply_modifiers(&mut self, player_colours: &Colours) -> &mut Construct {
self.specs.sort_unstable();
self.red_damage.recalculate(&self.specs, &self.colours, player_colours);
@@ -292,7 +292,7 @@ impl Cryp {
self.green_life.value == 0
}
pub fn force_ko(&mut self) -> &mut Cryp {
pub fn force_ko(&mut self) -> &mut Construct {
self.green_life.value = 0;
self
}
@@ -340,7 +340,7 @@ impl Cryp {
self.effects.iter().any(|s| s.effect == effect)
}
pub fn available_skills(&self) -> Vec<&CrypSkill> {
pub fn available_skills(&self) -> Vec<&ConstructSkill> {
self.skills.iter()
.filter(|s| s.cd.is_none())
.filter(|s| self.disabled(s.skill).is_none())
@@ -377,19 +377,19 @@ impl Cryp {
self.skills.iter().any(|s| s.skill == skill)
}
pub fn skill_on_cd(&self, skill: Skill) -> Option<&CrypSkill> {
pub fn skill_on_cd(&self, skill: Skill) -> Option<&ConstructSkill> {
self.skills.iter().find(|s| s.skill == skill && s.cd.is_some())
}
pub fn skill_set_cd(&mut self, skill: Skill) -> &mut Cryp {
pub fn skill_set_cd(&mut self, skill: Skill) -> &mut Construct {
let i = self.skills.iter().position(|s| s.skill == skill).unwrap();
self.skills.remove(i);
self.skills.push(CrypSkill::new(skill));
self.skills.push(ConstructSkill::new(skill));
self
}
pub fn reduce_cooldowns(&mut self) -> &mut Cryp {
pub fn reduce_cooldowns(&mut self) -> &mut Construct {
for skill in self.skills.iter_mut() {
// if used cooldown
if skill.skill.base_cd().is_some() {
@@ -412,7 +412,7 @@ impl Cryp {
self
}
pub fn reduce_effect_durations(&mut self) -> &mut Cryp {
pub fn reduce_effect_durations(&mut self) -> &mut Construct {
self.effects = self.effects.clone().into_iter().filter_map(|mut effect| {
effect.duration = effect.duration.saturating_sub(1);
@@ -422,7 +422,7 @@ impl Cryp {
// info!("reduced effect {:?}", effect);
return Some(effect);
}).collect::<Vec<CrypEffect>>();
}).collect::<Vec<ConstructEffect>>();
self
}
@@ -734,7 +734,7 @@ impl Cryp {
return events;
}
pub fn add_effect(&mut self, skill: Skill, effect: CrypEffect) -> Event {
pub fn add_effect(&mut self, skill: Skill, effect: ConstructEffect) -> Event {
if let Some(immunity) = self.immune(skill) {
return Event::Immunity {
skill,
@@ -776,10 +776,10 @@ impl Cryp {
}
}
pub fn cryp_get(tx: &mut Transaction, id: Uuid, account_id: Uuid) -> Result<Cryp, Error> {
pub fn construct_get(tx: &mut Transaction, id: Uuid, account_id: Uuid) -> Result<Construct, Error> {
let query = "
SELECT data
FROM cryps
FROM constructs
WHERE id = $1
AND account = $2;
";
@@ -787,110 +787,110 @@ pub fn cryp_get(tx: &mut Transaction, id: Uuid, account_id: Uuid) -> Result<Cryp
let result = tx
.query(query, &[&id, &account_id])?;
let result = result.iter().next().ok_or(format_err!("cryp {:} not found", id))?;
let cryp_bytes: Vec<u8> = result.get(0);
let cryp = from_slice::<Cryp>(&cryp_bytes).or_else(|_| cryp_recover(cryp_bytes, tx))?;
let result = result.iter().next().ok_or(format_err!("construct {:} not found", id))?;
let construct_bytes: Vec<u8> = result.get(0);
let construct = from_slice::<Construct>(&construct_bytes).or_else(|_| construct_recover(construct_bytes, tx))?;
return Ok(cryp);
return Ok(construct);
}
pub fn cryp_spawn(params: CrypSpawnParams, tx: &mut Transaction, account: &Account) -> Result<Cryp, Error> {
let cryp = Cryp::new()
pub fn construct_spawn(params: ConstructSpawnParams, tx: &mut Transaction, account: &Account) -> Result<Construct, Error> {
let construct = Construct::new()
.named(&params.name)
.set_account(account.id);
let cryp_bytes = to_vec(&cryp)?;
let construct_bytes = to_vec(&construct)?;
let query = "
INSERT INTO cryps (id, account, data)
INSERT INTO constructs (id, account, data)
VALUES ($1, $2, $3)
RETURNING id, account;
";
let result = tx
.query(query, &[&cryp.id, &account.id, &cryp_bytes])?;
.query(query, &[&construct.id, &account.id, &construct_bytes])?;
let _returned = result.iter().next().ok_or(err_msg("no row returned"))?;
// info!("{:?} spawned cryp {:}", account.id, cryp.id);
// info!("{:?} spawned construct {:}", account.id, construct.id);
return Ok(cryp);
return Ok(construct);
}
pub fn cryp_write(cryp: Cryp, tx: &mut Transaction) -> Result<Cryp, Error> {
let cryp_bytes = to_vec(&cryp)?;
pub fn construct_write(construct: Construct, tx: &mut Transaction) -> Result<Construct, Error> {
let construct_bytes = to_vec(&construct)?;
let query = "
UPDATE cryps
UPDATE constructs
SET data = $1, updated_at = now()
WHERE id = $2
RETURNING id, account, data;
";
let result = tx
.query(query, &[&cryp_bytes, &cryp.id])?;
.query(query, &[&construct_bytes, &construct.id])?;
let _returned = result.iter().next().expect("no row returned");
// info!("{:?} wrote cryp", cryp.id);
// info!("{:?} wrote construct", construct.id);
return Ok(cryp);
return Ok(construct);
}
pub fn cryp_recover(cryp_bytes: Vec<u8>, tx: &mut Transaction) -> Result<Cryp, Error> {
let c = from_slice::<CrypRecover>(&cryp_bytes)?;
pub fn construct_recover(construct_bytes: Vec<u8>, tx: &mut Transaction) -> Result<Construct, Error> {
let c = from_slice::<ConstructRecover>(&construct_bytes)?;
let mut cryp = Cryp::new()
let mut construct = Construct::new()
.named(&c.name)
.set_account(c.account);
cryp.id = c.id;
construct.id = c.id;
info!("recovered cryp {:?}", c.name);
info!("recovered construct {:?}", c.name);
return cryp_write(cryp, tx);
return construct_write(construct, tx);
}
#[cfg(test)]
mod tests {
use cryp::*;
use construct::*;
use util::IntPct;
#[test]
fn create_cryp_test() {
let cryp = Cryp::new()
fn create_construct_test() {
let construct = Construct::new()
.named(&"hatchling".to_string());
assert_eq!(cryp.name, "hatchling".to_string());
assert_eq!(construct.name, "hatchling".to_string());
return;
}
#[test]
fn cryp_colours_test() {
let mut cryp = Cryp::new()
fn construct_colours_test() {
let mut construct = Construct::new()
.named(&"redboi".to_string());
cryp.learn_mut(Skill::Strike);
cryp.spec_add(Spec::GreenLifeI).unwrap();
cryp.spec_add(Spec::RedDamageI).unwrap();
cryp.spec_add(Spec::RedDamageI).unwrap();
cryp.spec_add(Spec::BlueLifeI).unwrap();
construct.learn_mut(Skill::Strike);
construct.spec_add(Spec::GreenLifeI).unwrap();
construct.spec_add(Spec::RedDamageI).unwrap();
construct.spec_add(Spec::RedDamageI).unwrap();
construct.spec_add(Spec::BlueLifeI).unwrap();
assert_eq!(cryp.colours.red, 6);
assert_eq!(cryp.colours.green, 2);
assert_eq!(cryp.colours.blue, 2);
assert_eq!(construct.colours.red, 6);
assert_eq!(construct.colours.green, 2);
assert_eq!(construct.colours.blue, 2);
return;
}
#[test]
fn cryp_player_modifiers_test() {
let mut cryp = Cryp::new()
fn construct_player_modifiers_test() {
let mut construct = Construct::new()
.named(&"player player".to_string());
cryp.spec_add(Spec::RedDamageI).unwrap();
cryp.spec_add(Spec::GreenDamageI).unwrap();
cryp.spec_add(Spec::BlueDamageI).unwrap();
construct.spec_add(Spec::RedDamageI).unwrap();
construct.spec_add(Spec::GreenDamageI).unwrap();
construct.spec_add(Spec::BlueDamageI).unwrap();
let player_colours = Colours {
red: 5,
@@ -898,11 +898,11 @@ mod tests {
blue: 25,
};
cryp.apply_modifiers(&player_colours);
construct.apply_modifiers(&player_colours);
assert!(cryp.red_damage.value == cryp.red_damage.base + cryp.red_damage.base.pct(20));
assert!(cryp.green_damage.value == cryp.green_damage.base + cryp.green_damage.base.pct(40));
assert!(cryp.blue_damage.value == cryp.blue_damage.base + cryp.blue_damage.base.pct(80));
assert!(construct.red_damage.value == construct.red_damage.base + construct.red_damage.base.pct(20));
assert!(construct.green_damage.value == construct.green_damage.base + construct.green_damage.base.pct(40));
assert!(construct.blue_damage.value == construct.blue_damage.base + construct.blue_damage.base.pct(80));
return;
}
+213 -213
View File
@@ -13,7 +13,7 @@ use failure::err_msg;
use account::Account;
use rpc::{GameStateParams, GameSkillParams};
use cryp::{Cryp};
use construct::{Construct};
use skill::{Skill, Effect, Cast, Resolution, Event, resolution_steps};
use player::{Player};
use instance::{instance_game_finished, global_game_finished};
@@ -29,7 +29,7 @@ pub enum Phase {
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct Game {
pub id: Uuid,
pub player_cryps: usize,
pub player_constructs: usize,
pub player_num: usize,
pub players: Vec<Player>,
pub phase: Phase,
@@ -44,7 +44,7 @@ impl Game {
pub fn new() -> Game {
return Game {
id: Uuid::new_v4(),
player_cryps: 0,
player_constructs: 0,
player_num: 0,
players: vec![],
phase: Phase::Start,
@@ -61,8 +61,8 @@ impl Game {
self
}
pub fn set_player_cryps(&mut self, size: usize) -> &mut Game {
self.player_cryps = size;
pub fn set_player_constructs(&mut self, size: usize) -> &mut Game {
self.player_constructs = size;
self
}
@@ -84,12 +84,12 @@ impl Game {
return Err(err_msg("player already in game"));
}
if player.cryps.iter().all(|c| c.skills.len() == 0) {
if player.constructs.iter().all(|c| c.skills.len() == 0) {
info!("WARNING: {:?} has no skills and has forfeited {:?}", player.name, self.id);
player.forfeit();
}
let player_description = player.cryps.iter().map(|c| c.name.clone()).collect::<Vec<String>>().join(", ");
let player_description = player.constructs.iter().map(|c| c.name.clone()).collect::<Vec<String>>().join(", ");
self.log.push(format!("{:} has joined the game. [{:}]", player.name, player_description));
self.players.push(player);
@@ -105,42 +105,42 @@ impl Game {
.ok_or(format_err!("{:?} not in game", id))
}
pub fn cryp_by_id(&mut self, id: Uuid) -> Option<&mut Cryp> {
match self.players.iter_mut().find(|t| t.cryps.iter().any(|c| c.id == id)) {
Some(player) => player.cryps.iter_mut().find(|c| c.id == id),
pub fn construct_by_id(&mut self, id: Uuid) -> Option<&mut Construct> {
match self.players.iter_mut().find(|t| t.constructs.iter().any(|c| c.id == id)) {
Some(player) => player.constructs.iter_mut().find(|c| c.id == id),
None => None,
}
}
pub fn cryp_by_id_take(&mut self, id: Uuid) -> Cryp {
match self.players.iter_mut().find(|t| t.cryps.iter().any(|c| c.id == id)) {
pub fn construct_by_id_take(&mut self, id: Uuid) -> Construct {
match self.players.iter_mut().find(|t| t.constructs.iter().any(|c| c.id == id)) {
Some(player) => {
let i = player.cryps.iter().position(|c| c.id == id).unwrap();
player.cryps.remove(i)
let i = player.constructs.iter().position(|c| c.id == id).unwrap();
player.constructs.remove(i)
}
None => panic!("id not in game {:}", id),
}
}
fn all_cryps(&self) -> Vec<Cryp> {
fn all_constructs(&self) -> Vec<Construct> {
self.players.clone()
.into_iter()
.flat_map(
|t| t.cryps
|t| t.constructs
.into_iter())
.collect::<Vec<Cryp>>()
.collect::<Vec<Construct>>()
}
pub fn update_cryp(&mut self, cryp: &mut Cryp) -> &mut Game {
match self.players.iter_mut().find(|t| t.cryps.iter().any(|c| c.id == cryp.id)) {
pub fn update_construct(&mut self, construct: &mut Construct) -> &mut Game {
match self.players.iter_mut().find(|t| t.constructs.iter().any(|c| c.id == construct.id)) {
Some(player) => {
let index = player.cryps.iter().position(|t| t.id == cryp.id).unwrap();
player.cryps.remove(index);
player.cryps.push(cryp.clone());
player.cryps.sort_unstable_by_key(|c| c.id);
let index = player.constructs.iter().position(|t| t.id == construct.id).unwrap();
player.constructs.remove(index);
player.constructs.push(construct.clone());
player.constructs.sort_unstable_by_key(|c| c.id);
},
None => panic!("cryp not in game"),
None => panic!("construct not in game"),
};
self
@@ -148,7 +148,7 @@ impl Game {
pub fn can_start(&self) -> bool {
return self.players.len() == self.player_num
&& self.players.iter().all(|t| t.cryps.len() == self.player_cryps)
&& self.players.iter().all(|t| t.constructs.len() == self.player_constructs)
}
pub fn start(mut self) -> Game {
@@ -198,7 +198,7 @@ impl Game {
.filter(|t| t.bot) {
let player_player = self.players.iter().find(|t| t.id != mobs.id).unwrap();
for mob in mobs.cryps.iter() {
for mob in mobs.constructs.iter() {
let skill = mob.mob_select_skill();
// info!("{:?} {:?}", mob.name, skill);
match skill {
@@ -209,8 +209,8 @@ impl Game {
// more than once
let mut find_target = || {
match s.defensive() {
true => &mobs.cryps[rng.gen_range(0, mobs.cryps.len())],
false => &player_player.cryps[rng.gen_range(0, player_player.cryps.len())],
true => &mobs.constructs[rng.gen_range(0, mobs.constructs.len())],
false => &player_player.constructs[rng.gen_range(0, player_player.constructs.len())],
}
};
@@ -231,7 +231,7 @@ impl Game {
match self.add_skill(player_id, mob_id, target_id, s) {
Ok(_) => (),
Err(e) => {
info!("{:?}", self.cryp_by_id(mob_id));
info!("{:?}", self.construct_by_id(mob_id));
panic!("{:?} unable to add pve mob skill {:?}", e, s);
},
}
@@ -242,7 +242,7 @@ impl Game {
self
}
fn add_skill(&mut self, player_id: Uuid, source_cryp_id: Uuid, target_cryp_id: Option<Uuid>, skill: Skill) -> Result<&mut Game, Error> {
fn add_skill(&mut self, player_id: Uuid, source_construct_id: Uuid, target_construct_id: Option<Uuid>, skill: Skill) -> Result<&mut Game, Error> {
// check player in game
self.player_by_id(player_id)?;
@@ -251,8 +251,8 @@ impl Game {
}
let final_target_id = match skill.self_targeting() {
true => source_cryp_id,
false => match target_cryp_id {
true => source_construct_id,
false => match target_construct_id {
Some(t) => t,
None => return Err(err_msg("skill requires a target")),
}
@@ -260,49 +260,49 @@ impl Game {
// target checks
{
let target = match self.cryp_by_id(final_target_id) {
let target = match self.construct_by_id(final_target_id) {
Some(c) => c,
None => return Err(err_msg("target cryp not in game")),
None => return Err(err_msg("target construct not in game")),
};
// fixme for rez
if target.is_ko() {
return Err(err_msg("target cryp is ko"));
return Err(err_msg("target construct is ko"));
}
}
// cryp checks
// construct checks
{
let cryp = match self.cryp_by_id(source_cryp_id) {
let construct = match self.construct_by_id(source_construct_id) {
Some(c) => c,
None => return Err(err_msg("cryp not in game")),
None => return Err(err_msg("construct not in game")),
};
if cryp.is_ko() {
return Err(err_msg("cryp is ko"));
if construct.is_ko() {
return Err(err_msg("construct is ko"));
}
// check the cryp has the skill
if !cryp.knows(skill) {
return Err(err_msg("cryp does not have that skill"));
// check the construct has the skill
if !construct.knows(skill) {
return Err(err_msg("construct does not have that skill"));
}
if cryp.skill_on_cd(skill).is_some() {
if construct.skill_on_cd(skill).is_some() {
return Err(err_msg("abiltity on cooldown"));
}
// check here as well so uncastable spells don't go on the stack
if let Some(disable) = cryp.disabled(skill) {
if let Some(disable) = construct.disabled(skill) {
return Err(format_err!("skill disabled {:?}", disable));
}
}
// replace cryp skill
if let Some(s) = self.stack.iter_mut().position(|s| s.source_cryp_id == source_cryp_id) {
// replace construct skill
if let Some(s) = self.stack.iter_mut().position(|s| s.source_construct_id == source_construct_id) {
self.stack.remove(s);
}
let skill = Cast::new(source_cryp_id, player_id, final_target_id, skill);
let skill = Cast::new(source_construct_id, player_id, final_target_id, skill);
self.stack.push(skill);
return Ok(self);
@@ -349,7 +349,7 @@ impl Game {
let mut sorted = self.stack.clone();
sorted.iter_mut()
.for_each(|s| {
let caster = self.cryp_by_id(s.source_cryp_id).unwrap();
let caster = self.construct_by_id(s.source_construct_id).unwrap();
let speed = caster.skill_speed(s.skill);
s.speed = speed;
});
@@ -361,19 +361,19 @@ impl Game {
self
}
fn cryp_aoe_targets(&self, cryp_id: Uuid) -> Vec<Uuid> {
fn construct_aoe_targets(&self, construct_id: Uuid) -> Vec<Uuid> {
self.players.iter()
.find(|t| t.cryps.iter().any(|c| c.id == cryp_id))
.find(|t| t.constructs.iter().any(|c| c.id == construct_id))
.unwrap()
.cryps
.constructs
.iter()
.map(|c| c.id)
.collect()
}
pub fn get_targets(&self, skill: Skill, source: &Cryp, target_cryp_id: Uuid) -> Vec<Uuid> {
pub fn get_targets(&self, skill: Skill, source: &Construct, target_construct_id: Uuid) -> Vec<Uuid> {
let target_player = self.players.iter()
.find(|t| t.cryps.iter().any(|c| c.id == target_cryp_id))
.find(|t| t.constructs.iter().any(|c| c.id == target_construct_id))
.unwrap();
if let Some(t) = target_player.taunting() {
@@ -381,8 +381,8 @@ impl Game {
}
match source.skill_is_aoe(skill) {
true => self.cryp_aoe_targets(target_cryp_id),
false => vec![target_cryp_id],
true => self.construct_aoe_targets(target_construct_id),
false => vec![target_construct_id],
}
}
@@ -392,7 +392,7 @@ impl Game {
}
// find their statuses with ticks
let mut ticks = self.all_cryps()
let mut ticks = self.all_constructs()
.iter()
.flat_map(
|c| c.effects
@@ -442,30 +442,30 @@ impl Game {
}
fn progress_durations(&mut self, resolved: &Vec<Cast>) -> &mut Game {
for mut cryp in self.all_cryps() {
// info!("progressing durations for {:}", cryp.name);
for mut construct in self.all_constructs() {
// info!("progressing durations for {:}", construct.name);
if cryp.is_ko() {
if construct.is_ko() {
continue;
}
// only reduce cooldowns if no cd was used
// have to borrow self for the skill check
{
if let Some(skill) = resolved.iter().find(|s| s.source_cryp_id == cryp.id) {
if let Some(skill) = resolved.iter().find(|s| s.source_construct_id == construct.id) {
if skill.used_cooldown() {
cryp.skill_set_cd(skill.skill);
construct.skill_set_cd(skill.skill);
} else {
cryp.reduce_cooldowns();
construct.reduce_cooldowns();
}
} else {
cryp.reduce_cooldowns();
construct.reduce_cooldowns();
}
}
// always reduce durations
cryp.reduce_effect_durations();
self.update_cryp(&mut cryp);
construct.reduce_effect_durations();
self.update_construct(&mut construct);
}
self
@@ -536,11 +536,11 @@ impl Game {
}
pub fn finished(&self) -> bool {
self.players.iter().any(|t| t.cryps.iter().all(|c| c.is_ko()))
self.players.iter().any(|t| t.constructs.iter().all(|c| c.is_ko()))
}
pub fn winner(&self) -> Option<&Player> {
self.players.iter().find(|t| t.cryps.iter().any(|c| !c.is_ko()))
self.players.iter().find(|t| t.constructs.iter().any(|c| !c.is_ko()))
}
fn finish(mut self) -> Game {
@@ -548,7 +548,7 @@ impl Game {
self.log.push(format!("Game finished."));
{
let winner = self.players.iter().find(|t| t.cryps.iter().any(|c| !c.is_ko()));
let winner = self.players.iter().find(|t| t.constructs.iter().any(|c| !c.is_ko()));
match winner {
Some(w) => self.log.push(format!("Winner: {:}", w.name)),
None => self.log.push(format!("Game was drawn.")),
@@ -630,7 +630,7 @@ pub fn game_get(tx: &mut Transaction, id: Uuid) -> Result<Game, Error> {
None => return Err(err_msg("game not found")),
};
// tells from_slice to cast into a cryp
// tells from_slice to cast into a construct
let game_bytes: Vec<u8> = returned.get("data");
let game = from_slice::<Game>(&game_bytes)?;
@@ -700,7 +700,7 @@ pub fn game_delete(tx: &mut Transaction, id: Uuid) -> Result<(), Error> {
// game
// .set_player_num(2)
// .set_player_cryps(3)
// .set_player_constructs(3)
// .set_mode(GameMode::Pvp);
// game_write(tx, &game)?;
@@ -761,7 +761,7 @@ pub fn game_delete(tx: &mut Transaction, id: Uuid) -> Result<(), Error> {
// None => return Err(err_msg("game not found")),
// };
// // tells from_slice to cast into a cryp
// // tells from_slice to cast into a construct
// let game_bytes: Vec<u8> = returned.get("data");
// let game = match from_slice::<Game>(&game_bytes) {
// Ok(g) => g,
@@ -805,7 +805,7 @@ pub fn game_update(tx: &mut Transaction, game: &Game) -> Result<(), Error> {
pub fn game_skill(params: GameSkillParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
let mut game = game_get(tx, params.game_id)?;
game.add_skill(account.id, params.cryp_id, params.target_cryp_id, params.skill)?;
game.add_skill(account.id, params.construct_id, params.target_construct_id, params.skill)?;
if game.skill_phase_finished() {
game = game.resolve_phase_start();
@@ -830,17 +830,17 @@ pub fn game_ready(params: GameStateParams, tx: &mut Transaction, account: &Accou
Ok(game)
}
// pub fn game_pve_new(cryp_ids: Vec<Uuid>, mode: GameMode, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
// if cryp_ids.len() == 0 {
// return Err(err_msg("no cryps selected"));
// pub fn game_pve_new(construct_ids: Vec<Uuid>, mode: GameMode, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
// if construct_ids.len() == 0 {
// return Err(err_msg("no constructs selected"));
// }
// let cryps = cryp_ids
// let constructs = construct_ids
// .iter()
// .map(|id| cryp_get(tx, *id, account.id))
// .collect::<Result<Vec<Cryp>, Error>>()?;
// .map(|id| construct_get(tx, *id, account.id))
// .collect::<Result<Vec<Construct>, Error>>()?;
// if cryps.len() > 3 {
// if constructs.len() > 3 {
// return Err(err_msg("player size too large (3 max)"));
// }
@@ -850,16 +850,16 @@ pub fn game_ready(params: GameStateParams, tx: &mut Transaction, account: &Accou
// game;
// .set_player_num(2)
// .set_player_cryps(cryps.len())
// .set_player_constructs(constructs.len())
// .set_mode(mode);
// // create the mob player
// let mob_player = generate_mob_player(mode, &cryps);
// let mob_player = generate_mob_player(mode, &constructs);
// // add the players
// let mut plr_player = Player::new(account.id);
// plr_player
// .set_cryps(cryps);
// .set_constructs(constructs);
// game
@@ -872,7 +872,7 @@ pub fn game_ready(params: GameStateParams, tx: &mut Transaction, account: &Accou
// }
// pub fn game_pve(params: GamePveParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
// let game = game_pve_new(params.cryp_ids, GameMode::Normal, tx, account)?;
// let game = game_pve_new(params.construct_ids, GameMode::Normal, tx, account)?;
// // persist
// game_write(tx, &game)?;
@@ -887,7 +887,7 @@ pub fn game_instance_new(tx: &mut Transaction, players: Vec<Player>, game_id: Uu
game
.set_player_num(2)
.set_player_cryps(3)
.set_player_constructs(3)
.set_instance(instance_id);
// create the initiators player
@@ -924,11 +924,11 @@ pub fn game_instance_new(tx: &mut Transaction, players: Vec<Player>, game_id: Uu
#[cfg(test)]
mod tests {
use game::*;
use cryp::*;
use construct::*;
use util::IntPct;
fn create_test_game() -> Game {
let mut x = Cryp::new()
let mut x = Construct::new()
.named(&"pronounced \"creeep\"".to_string())
.learn(Skill::Attack)
.learn(Skill::TestStun)
@@ -940,7 +940,7 @@ mod tests {
.learn(Skill::Stun)
.learn(Skill::Block);
let mut y = Cryp::new()
let mut y = Construct::new()
.named(&"lemongrass tea".to_string())
.learn(Skill::Attack)
.learn(Skill::TestStun)
@@ -956,7 +956,7 @@ mod tests {
game
.set_player_num(2)
.set_player_cryps(1);
.set_player_constructs(1);
let x_player_id = Uuid::new_v4();
x.account = x_player_id;
@@ -976,22 +976,22 @@ mod tests {
}
fn create_2v2_test_game() -> Game {
let mut i = Cryp::new()
let mut i = Construct::new()
.named(&"pretaliate".to_string())
.learn(Skill::Attack)
.learn(Skill::TestTouch);
let mut j = Cryp::new()
let mut j = Construct::new()
.named(&"poy sian".to_string())
.learn(Skill::Attack)
.learn(Skill::TestTouch);
let mut x = Cryp::new()
let mut x = Construct::new()
.named(&"pronounced \"creeep\"".to_string())
.learn(Skill::Attack)
.learn(Skill::TestTouch);
let mut y = Cryp::new()
let mut y = Construct::new()
.named(&"lemongrass tea".to_string())
.learn(Skill::Attack)
.learn(Skill::TestTouch);
@@ -1000,7 +1000,7 @@ mod tests {
game
.set_player_num(2)
.set_player_cryps(2);
.set_player_constructs(2);
let i_player_id = Uuid::new_v4();
i.account = i_player_id;
@@ -1028,11 +1028,11 @@ mod tests {
let x_player = game.players[0].clone();
let y_player = game.players[1].clone();
let x_cryp = x_player.cryps[0].clone();
let y_cryp = y_player.cryps[0].clone();
let x_construct = x_player.constructs[0].clone();
let y_construct = y_player.constructs[0].clone();
game.add_skill(x_player.id, x_cryp.id, Some(y_cryp.id), Skill::Attack).unwrap();
game.add_skill(y_player.id, y_cryp.id, Some(x_cryp.id), Skill::Attack).unwrap();
game.add_skill(x_player.id, x_construct.id, Some(y_construct.id), Skill::Attack).unwrap();
game.add_skill(y_player.id, y_construct.id, Some(x_construct.id), Skill::Attack).unwrap();
game.player_ready(x_player.id).unwrap();
game.player_ready(y_player.id).unwrap();
@@ -1053,11 +1053,11 @@ mod tests {
let x_player = game.players[0].clone();
let y_player = game.players[1].clone();
let x_cryp = x_player.cryps[0].clone();
let y_cryp = y_player.cryps[0].clone();
let x_construct = x_player.constructs[0].clone();
let y_construct = y_player.constructs[0].clone();
game.add_skill(x_player.id, x_cryp.id, Some(y_cryp.id), Skill::TestStun).unwrap();
game.add_skill(y_player.id, y_cryp.id, Some(x_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(x_player.id, x_construct.id, Some(y_construct.id), Skill::TestStun).unwrap();
game.add_skill(y_player.id, y_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap();
game.player_ready(x_player.id).unwrap();
game.player_ready(y_player.id).unwrap();
@@ -1068,7 +1068,7 @@ mod tests {
// should auto progress back to skill phase
assert!(game.phase == Phase::Skill);
// assert!(game.player_by_id(y_player.id).cryps[0].is_stunned());
// assert!(game.player_by_id(y_player.id).constructs[0].is_stunned());
// assert!(game.player_by_id(y_player.id).skills_required() == 0);
}
@@ -1079,18 +1079,18 @@ mod tests {
let x_player = game.players[0].clone();
let y_player = game.players[1].clone();
let x_cryp = x_player.cryps[0].clone();
let y_cryp = y_player.cryps[0].clone();
let x_construct = x_player.constructs[0].clone();
let y_construct = y_player.constructs[0].clone();
game.player_by_id(y_player.id).unwrap().cryp_by_id(y_cryp.id).unwrap().red_damage.force(1000000000);
game.player_by_id(y_player.id).unwrap().cryp_by_id(y_cryp.id).unwrap().speed.force(1000000000);
game.player_by_id(y_player.id).unwrap().construct_by_id(y_construct.id).unwrap().red_damage.force(1000000000);
game.player_by_id(y_player.id).unwrap().construct_by_id(y_construct.id).unwrap().speed.force(1000000000);
// just in case
// remove all mitigation
game.player_by_id(x_player.id).unwrap().cryp_by_id(x_cryp.id).unwrap().red_life.force(0);
game.player_by_id(x_player.id).unwrap().construct_by_id(x_construct.id).unwrap().red_life.force(0);
game.add_skill(x_player.id, x_cryp.id, Some(y_cryp.id), Skill::TestStun).unwrap();
game.add_skill(y_player.id, y_cryp.id, Some(x_cryp.id), Skill::Attack).unwrap();
game.add_skill(x_player.id, x_construct.id, Some(y_construct.id), Skill::TestStun).unwrap();
game.add_skill(y_player.id, y_construct.id, Some(x_construct.id), Skill::Attack).unwrap();
game.player_ready(x_player.id).unwrap();
game.player_ready(y_player.id).unwrap();
@@ -1098,7 +1098,7 @@ mod tests {
assert!(game.skill_phase_finished());
game = game.resolve_phase_start();
assert!(!game.player_by_id(y_player.id).unwrap().cryps[0].is_stunned());
assert!(!game.player_by_id(y_player.id).unwrap().constructs[0].is_stunned());
assert!(game.phase == Phase::Finish);
}
@@ -1109,18 +1109,18 @@ mod tests {
let x_player = game.players[0].clone();
let y_player = game.players[1].clone();
let x_cryp = x_player.cryps[0].clone();
let y_cryp = y_player.cryps[0].clone();
let x_construct = x_player.constructs[0].clone();
let y_construct = y_player.constructs[0].clone();
// should auto progress back to skill phase
assert!(game.phase == Phase::Skill);
assert!(game.player_by_id(y_player.id).unwrap().cryps[0].skill_on_cd(Skill::Block).is_none());
assert!(game.player_by_id(y_player.id).unwrap().cryps[0].skill_on_cd(Skill::Stun).is_some());
assert!(game.player_by_id(x_player.id).unwrap().cryps[0].skill_on_cd(Skill::Block).is_none());
assert!(game.player_by_id(y_player.id).unwrap().constructs[0].skill_on_cd(Skill::Block).is_none());
assert!(game.player_by_id(y_player.id).unwrap().constructs[0].skill_on_cd(Skill::Stun).is_some());
assert!(game.player_by_id(x_player.id).unwrap().constructs[0].skill_on_cd(Skill::Block).is_none());
game.add_skill(x_player.id, x_cryp.id, Some(y_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(y_player.id, y_cryp.id, Some(x_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(x_player.id, x_construct.id, Some(y_construct.id), Skill::TestTouch).unwrap();
game.add_skill(y_player.id, y_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap();
game.player_ready(x_player.id).unwrap();
game.player_ready(y_player.id).unwrap();
@@ -1129,20 +1129,20 @@ mod tests {
// should auto progress back to skill phase
assert!(game.phase == Phase::Skill);
assert!(game.player_by_id(y_player.id).unwrap().cryps[0].skill_on_cd(Skill::Stun).is_some());
assert!(game.player_by_id(y_player.id).unwrap().constructs[0].skill_on_cd(Skill::Stun).is_some());
// second round
// now we block and it should go back on cd
// game.add_skill(x_player.id, x_cryp.id, Some(y_cryp.id), Skill::Stun).unwrap();
game.add_skill(y_player.id, y_cryp.id, Some(x_cryp.id), Skill::TestTouch).unwrap();
// game.add_skill(x_player.id, x_construct.id, Some(y_construct.id), Skill::Stun).unwrap();
game.add_skill(y_player.id, y_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap();
game.player_ready(x_player.id).unwrap();
game.player_ready(y_player.id).unwrap();
game = game.resolve_phase_start();
assert!(game.player_by_id(x_player.id).unwrap().cryps[0].skill_on_cd(Skill::Stun).is_none());
assert!(game.player_by_id(y_player.id).unwrap().cryps[0].skill_on_cd(Skill::Block).is_none());
assert!(game.player_by_id(x_player.id).unwrap().constructs[0].skill_on_cd(Skill::Stun).is_none());
assert!(game.player_by_id(y_player.id).unwrap().constructs[0].skill_on_cd(Skill::Block).is_none());
}
#[test]
@@ -1152,11 +1152,11 @@ mod tests {
let x_player = game.players[0].clone();
let y_player = game.players[1].clone();
let x_cryp = x_player.cryps[0].clone();
let y_cryp = y_player.cryps[0].clone();
let x_construct = x_player.constructs[0].clone();
let y_construct = y_player.constructs[0].clone();
game.add_skill(x_player.id, x_cryp.id, None, Skill::TestParry).unwrap();
game.add_skill(y_player.id, y_cryp.id, Some(x_cryp.id), Skill::TestStun).unwrap();
game.add_skill(x_player.id, x_construct.id, None, Skill::TestParry).unwrap();
game.add_skill(y_player.id, y_construct.id, Some(x_construct.id), Skill::TestStun).unwrap();
game.player_ready(x_player.id).unwrap();
game.player_ready(y_player.id).unwrap();
@@ -1164,9 +1164,9 @@ mod tests {
game = game.resolve_phase_start();
// should not be stunned because of parry
assert!(game.player_by_id(x_player.id).unwrap().cryps[0].is_stunned() == false);
assert!(game.player_by_id(x_player.id).unwrap().constructs[0].is_stunned() == false);
// riposte
assert_eq!(game.player_by_id(y_player.id).unwrap().cryps[0].green_life(), (1024 - x_cryp.red_damage().pct(Skill::Riposte.multiplier())));
assert_eq!(game.player_by_id(y_player.id).unwrap().constructs[0].green_life(), (1024 - x_construct.red_damage().pct(Skill::Riposte.multiplier())));
}
#[test]
@@ -1176,29 +1176,29 @@ mod tests {
let x_player = game.players[0].clone();
let y_player = game.players[1].clone();
let x_cryp = x_player.cryps[0].clone();
let y_cryp = y_player.cryps[0].clone();
let x_construct = x_player.constructs[0].clone();
let y_construct = y_player.constructs[0].clone();
game.cryp_by_id(x_cryp.id).unwrap().learn_mut(Skill::Corrupt);
game.construct_by_id(x_construct.id).unwrap().learn_mut(Skill::Corrupt);
while game.cryp_by_id(x_cryp.id).unwrap().skill_on_cd(Skill::Corrupt).is_some() {
game.cryp_by_id(x_cryp.id).unwrap().reduce_cooldowns();
while game.construct_by_id(x_construct.id).unwrap().skill_on_cd(Skill::Corrupt).is_some() {
game.construct_by_id(x_construct.id).unwrap().reduce_cooldowns();
}
// apply buff
game.add_skill(x_player.id, x_cryp.id, None, Skill::Corrupt).unwrap();
game.add_skill(x_player.id, x_construct.id, None, Skill::Corrupt).unwrap();
game.player_ready(x_player.id).unwrap();
game.player_ready(y_player.id).unwrap();
game = game.resolve_phase_start();
assert!(game.cryp_by_id(x_cryp.id).unwrap().affected(Effect::Corrupt));
assert!(game.construct_by_id(x_construct.id).unwrap().affected(Effect::Corrupt));
// attack and receive debuff
game.add_skill(y_player.id, y_cryp.id, Some(x_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(y_player.id, y_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap();
game.player_ready(x_player.id).unwrap();
game.player_ready(y_player.id).unwrap();
game = game.resolve_phase_start();
assert!(game.cryp_by_id(y_cryp.id).unwrap().affected(Effect::Corruption));
assert!(game.construct_by_id(y_construct.id).unwrap().affected(Effect::Corruption));
}
#[test]
@@ -1208,21 +1208,21 @@ mod tests {
let x_player = game.players[0].clone();
let y_player = game.players[1].clone();
let x_cryp = x_player.cryps[0].clone();
let y_cryp = y_player.cryps[0].clone();
let x_construct = x_player.constructs[0].clone();
let y_construct = y_player.constructs[0].clone();
game.cryp_by_id(x_cryp.id).unwrap().learn_mut(Skill::Scatter);
game.construct_by_id(x_construct.id).unwrap().learn_mut(Skill::Scatter);
while game.cryp_by_id(x_cryp.id).unwrap().skill_on_cd(Skill::Scatter).is_some() {
game.cryp_by_id(x_cryp.id).unwrap().reduce_cooldowns();
while game.construct_by_id(x_construct.id).unwrap().skill_on_cd(Skill::Scatter).is_some() {
game.construct_by_id(x_construct.id).unwrap().reduce_cooldowns();
}
// apply buff
game.add_skill(x_player.id, x_cryp.id, Some(y_cryp.id), Skill::Scatter).unwrap();
game.add_skill(x_player.id, x_construct.id, Some(y_construct.id), Skill::Scatter).unwrap();
game.player_ready(x_player.id).unwrap();
game.player_ready(y_player.id).unwrap();
game = game.resolve_phase_start();
assert!(game.cryp_by_id(x_cryp.id).unwrap().affected(Effect::Scatter));
assert!(game.construct_by_id(x_construct.id).unwrap().affected(Effect::Scatter));
let Resolution { source: _, target: _, event } = game.resolved.pop().unwrap();
match event {
@@ -1237,13 +1237,13 @@ mod tests {
}
// attack and receive scatter hit
game.add_skill(y_player.id, y_cryp.id, Some(x_cryp.id), Skill::Attack).unwrap();
game.add_skill(y_player.id, y_construct.id, Some(x_construct.id), Skill::Attack).unwrap();
game.player_ready(x_player.id).unwrap();
game.player_ready(y_player.id).unwrap();
game = game.resolve_phase_start();
let Resolution { source: _, target, event } = game.resolved.pop().unwrap();
assert_eq!(target.id, y_cryp.id);
assert_eq!(target.id, y_construct.id);
match event {
Event::Damage { amount, skill: _, mitigation: _, colour: _} =>
assert_eq!(amount, 256.pct(Skill::Attack.multiplier()) >> 1),
@@ -1258,30 +1258,30 @@ mod tests {
// let x_player = game.players[0].clone();
// let y_player = game.players[1].clone();
// let x_cryp = x_player.cryps[0].clone();
// let y_cryp = y_player.cryps[0].clone();
// let x_construct = x_player.constructs[0].clone();
// let y_construct = y_player.constructs[0].clone();
// game.cryp_by_id(x_cryp.id).unwrap().learn_mut(Skill::Hostility);
// game.construct_by_id(x_construct.id).unwrap().learn_mut(Skill::Hostility);
// while game.cryp_by_id(x_cryp.id).unwrap().skill_on_cd(Skill::Hostility).is_some() {
// game.cryp_by_id(x_cryp.id).unwrap().reduce_cooldowns();
// while game.construct_by_id(x_construct.id).unwrap().skill_on_cd(Skill::Hostility).is_some() {
// game.construct_by_id(x_construct.id).unwrap().reduce_cooldowns();
// }
// // apply buff
// game.add_skill(x_player.id, x_cryp.id, Some(x_cryp.id), Skill::Hostility).unwrap();
// game.add_skill(x_player.id, x_construct.id, Some(x_construct.id), Skill::Hostility).unwrap();
// game.player_ready(x_player.id).unwrap();
// game.player_ready(y_player.id).unwrap();
// game = game.resolve_phase_start();
// assert!(game.cryp_by_id(x_cryp.id).unwrap().affected(Effect::Hostility));
// assert!(game.construct_by_id(x_construct.id).unwrap().affected(Effect::Hostility));
// // attack and receive debuff
// game.add_skill(y_player.id, y_cryp.id, Some(x_cryp.id), Skill::TestAttack).unwrap();
// game.add_skill(y_player.id, y_construct.id, Some(x_construct.id), Skill::TestAttack).unwrap();
// game.player_ready(x_player.id).unwrap();
// game.player_ready(y_player.id).unwrap();
// game = game.resolve_phase_start();
// info!("{:#?}", game);
// assert!(game.cryp_by_id(y_cryp.id).unwrap().affected(Effect::Hatred));
// assert!(game.construct_by_id(y_construct.id).unwrap().affected(Effect::Hatred));
// }
#[test]
@@ -1291,21 +1291,21 @@ mod tests {
let i_player = game.players[0].clone();
let x_player = game.players[1].clone();
let i_cryp = i_player.cryps[0].clone();
let j_cryp = i_player.cryps[1].clone();
let x_cryp = x_player.cryps[0].clone();
let y_cryp = x_player.cryps[1].clone();
let i_construct = i_player.constructs[0].clone();
let j_construct = i_player.constructs[1].clone();
let x_construct = x_player.constructs[0].clone();
let y_construct = x_player.constructs[1].clone();
game.cryp_by_id(x_cryp.id).unwrap().learn_mut(Skill::Ruin);
game.construct_by_id(x_construct.id).unwrap().learn_mut(Skill::Ruin);
while game.cryp_by_id(x_cryp.id).unwrap().skill_on_cd(Skill::Ruin).is_some() {
game.cryp_by_id(x_cryp.id).unwrap().reduce_cooldowns();
while game.construct_by_id(x_construct.id).unwrap().skill_on_cd(Skill::Ruin).is_some() {
game.construct_by_id(x_construct.id).unwrap().reduce_cooldowns();
}
game.add_skill(i_player.id, i_cryp.id, Some(x_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(i_player.id, j_cryp.id, Some(x_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(x_player.id, x_cryp.id, Some(i_cryp.id), Skill::Ruin).unwrap();
game.add_skill(x_player.id, y_cryp.id, Some(i_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(i_player.id, i_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap();
game.add_skill(i_player.id, j_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap();
game.add_skill(x_player.id, x_construct.id, Some(i_construct.id), Skill::Ruin).unwrap();
game.add_skill(x_player.id, y_construct.id, Some(i_construct.id), Skill::TestTouch).unwrap();
game.player_ready(i_player.id).unwrap();
game.player_ready(x_player.id).unwrap();
@@ -1316,7 +1316,7 @@ mod tests {
.into_iter()
.filter(|r| {
let Resolution { source, target: _, event } = r;
match source.id == x_cryp.id {
match source.id == x_construct.id {
true => match event {
Event::Effect { effect, duration, skill: _ } => {
assert!(*effect == Effect::Stun);
@@ -1341,21 +1341,21 @@ mod tests {
let i_player = game.players[0].clone();
let x_player = game.players[1].clone();
let i_cryp = i_player.cryps[0].clone();
let j_cryp = i_player.cryps[1].clone();
let x_cryp = x_player.cryps[0].clone();
let y_cryp = x_player.cryps[1].clone();
let i_construct = i_player.constructs[0].clone();
let j_construct = i_player.constructs[1].clone();
let x_construct = x_player.constructs[0].clone();
let y_construct = x_player.constructs[1].clone();
game.cryp_by_id(x_cryp.id).unwrap().learn_mut(Skill::Taunt);
game.construct_by_id(x_construct.id).unwrap().learn_mut(Skill::Taunt);
while game.cryp_by_id(x_cryp.id).unwrap().skill_on_cd(Skill::Taunt).is_some() {
game.cryp_by_id(x_cryp.id).unwrap().reduce_cooldowns();
while game.construct_by_id(x_construct.id).unwrap().skill_on_cd(Skill::Taunt).is_some() {
game.construct_by_id(x_construct.id).unwrap().reduce_cooldowns();
}
game.add_skill(i_player.id, i_cryp.id, Some(x_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(i_player.id, j_cryp.id, Some(x_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(x_player.id, x_cryp.id, Some(i_cryp.id), Skill::Taunt).unwrap();
game.add_skill(x_player.id, y_cryp.id, Some(i_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(i_player.id, i_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap();
game.add_skill(i_player.id, j_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap();
game.add_skill(x_player.id, x_construct.id, Some(i_construct.id), Skill::Taunt).unwrap();
game.add_skill(x_player.id, y_construct.id, Some(i_construct.id), Skill::TestTouch).unwrap();
game.player_ready(i_player.id).unwrap();
game.player_ready(x_player.id).unwrap();
@@ -1365,8 +1365,8 @@ mod tests {
assert!(game.resolved.len() == 5);
while let Some(r) = game.resolved.pop() {
let Resolution { source , target, event: _ } = r;
if [i_cryp.id, j_cryp.id].contains(&source.id) {
assert!(target.id == x_cryp.id);
if [i_construct.id, j_construct.id].contains(&source.id) {
assert!(target.id == x_construct.id);
}
}
}
@@ -1378,15 +1378,15 @@ mod tests {
let i_player = game.players[0].clone();
let x_player = game.players[1].clone();
let i_cryp = i_player.cryps[0].clone();
let j_cryp = i_player.cryps[1].clone();
let x_cryp = x_player.cryps[0].clone();
let y_cryp = x_player.cryps[1].clone();
let i_construct = i_player.constructs[0].clone();
let j_construct = i_player.constructs[1].clone();
let x_construct = x_player.constructs[0].clone();
let y_construct = x_player.constructs[1].clone();
game.add_skill(i_player.id, i_cryp.id, Some(x_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(i_player.id, j_cryp.id, Some(x_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(x_player.id, x_cryp.id, Some(i_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(x_player.id, y_cryp.id, Some(i_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(i_player.id, i_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap();
game.add_skill(i_player.id, j_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap();
game.add_skill(x_player.id, x_construct.id, Some(i_construct.id), Skill::TestTouch).unwrap();
game.add_skill(x_player.id, y_construct.id, Some(i_construct.id), Skill::TestTouch).unwrap();
game.player_ready(i_player.id).unwrap();
game.player_ready(x_player.id).unwrap();
@@ -1396,17 +1396,17 @@ mod tests {
assert!([Phase::Skill, Phase::Finish].contains(&game.phase));
// kill a cryp
game.player_by_id(i_player.id).unwrap().cryp_by_id(i_cryp.id).unwrap().green_life.reduce(u64::max_value());
// kill a construct
game.player_by_id(i_player.id).unwrap().construct_by_id(i_construct.id).unwrap().green_life.reduce(u64::max_value());
assert!(game.player_by_id(i_player.id).unwrap().skills_required() == 1);
assert!(game.player_by_id(x_player.id).unwrap().skills_required() == 2);
// add some more skills
game.add_skill(i_player.id, j_cryp.id, Some(x_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(x_player.id, x_cryp.id, Some(j_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(x_player.id, y_cryp.id, Some(j_cryp.id), Skill::TestTouch).unwrap();
assert!(game.add_skill(x_player.id, x_cryp.id, Some(i_cryp.id), Skill::TestTouch).is_err());
game.add_skill(i_player.id, j_construct.id, Some(x_construct.id), Skill::TestTouch).unwrap();
game.add_skill(x_player.id, x_construct.id, Some(j_construct.id), Skill::TestTouch).unwrap();
game.add_skill(x_player.id, y_construct.id, Some(j_construct.id), Skill::TestTouch).unwrap();
assert!(game.add_skill(x_player.id, x_construct.id, Some(i_construct.id), Skill::TestTouch).is_err());
game.player_ready(i_player.id).unwrap();
game.player_ready(x_player.id).unwrap();
@@ -1426,33 +1426,33 @@ mod tests {
let x_player = game.players[0].clone();
let y_player = game.players[1].clone();
let x_cryp = x_player.cryps[0].clone();
let y_cryp = y_player.cryps[0].clone();
let x_construct = x_player.constructs[0].clone();
let y_construct = y_player.constructs[0].clone();
// make the purify cryp super fast so it beats out decay
game.cryp_by_id(y_cryp.id).unwrap().speed.force(10000000);
// make the purify construct super fast so it beats out decay
game.construct_by_id(y_construct.id).unwrap().speed.force(10000000);
game.cryp_by_id(x_cryp.id).unwrap().learn_mut(Skill::Decay);
while game.cryp_by_id(x_cryp.id).unwrap().skill_on_cd(Skill::Decay).is_some() {
game.cryp_by_id(x_cryp.id).unwrap().reduce_cooldowns();
game.construct_by_id(x_construct.id).unwrap().learn_mut(Skill::Decay);
while game.construct_by_id(x_construct.id).unwrap().skill_on_cd(Skill::Decay).is_some() {
game.construct_by_id(x_construct.id).unwrap().reduce_cooldowns();
}
game.cryp_by_id(x_cryp.id).unwrap().learn_mut(Skill::Siphon);
while game.cryp_by_id(x_cryp.id).unwrap().skill_on_cd(Skill::Siphon).is_some() {
game.cryp_by_id(x_cryp.id).unwrap().reduce_cooldowns();
game.construct_by_id(x_construct.id).unwrap().learn_mut(Skill::Siphon);
while game.construct_by_id(x_construct.id).unwrap().skill_on_cd(Skill::Siphon).is_some() {
game.construct_by_id(x_construct.id).unwrap().reduce_cooldowns();
}
game.cryp_by_id(y_cryp.id).unwrap().learn_mut(Skill::Purify);
while game.cryp_by_id(y_cryp.id).unwrap().skill_on_cd(Skill::Purify).is_some() {
game.cryp_by_id(y_cryp.id).unwrap().reduce_cooldowns();
game.construct_by_id(y_construct.id).unwrap().learn_mut(Skill::Purify);
while game.construct_by_id(y_construct.id).unwrap().skill_on_cd(Skill::Purify).is_some() {
game.construct_by_id(y_construct.id).unwrap().reduce_cooldowns();
}
// apply buff
game.add_skill(x_player.id, x_cryp.id, Some(y_cryp.id), Skill::Decay).unwrap();
game.add_skill(x_player.id, x_construct.id, Some(y_construct.id), Skill::Decay).unwrap();
game.player_ready(x_player.id).unwrap();
game.player_ready(y_player.id).unwrap();
game = game.resolve_phase_start();
assert!(game.cryp_by_id(y_cryp.id).unwrap().affected(Effect::Decay));
assert!(game.construct_by_id(y_construct.id).unwrap().affected(Effect::Decay));
let Resolution { source: _, target: _, event } = game.resolved.pop().unwrap();
match event {
@@ -1463,7 +1463,7 @@ mod tests {
game.resolved.clear();
// remove
game.add_skill(y_player.id, y_cryp.id, Some(y_cryp.id), Skill::Purify).unwrap();
game.add_skill(y_player.id, y_construct.id, Some(y_construct.id), Skill::Purify).unwrap();
game.player_ready(x_player.id).unwrap();
game.player_ready(y_player.id).unwrap();
game = game.resolve_phase_start();
@@ -1476,14 +1476,14 @@ mod tests {
}
};
game.add_skill(y_player.id, x_cryp.id, Some(y_cryp.id), Skill::Siphon).unwrap();
game.add_skill(y_player.id, x_construct.id, Some(y_construct.id), Skill::Siphon).unwrap();
game.player_ready(x_player.id).unwrap();
game.player_ready(y_player.id).unwrap();
game = game.resolve_phase_start();
game.resolved.clear();
game.add_skill(y_player.id, y_cryp.id, Some(y_cryp.id), Skill::Purify).unwrap();
game.add_skill(y_player.id, y_construct.id, Some(y_construct.id), Skill::Purify).unwrap();
game.player_ready(x_player.id).unwrap();
game.player_ready(y_player.id).unwrap();
game = game.resolve_phase_start();
+28 -28
View File
@@ -16,7 +16,7 @@ use chrono::Duration;
use rpc::{InstanceLobbyParams, InstanceJoinParams, InstanceReadyParams, InstanceStateParams};
use account::Account;
use player::{Player, player_create, player_get, player_global_update};
use cryp::{Cryp, cryp_get};
use construct::{Construct, construct_get};
use mob::{instance_mobs};
use game::{Game, Phase, game_get, game_write};
use item::{Item};
@@ -144,8 +144,8 @@ impl Instance {
self.open = false;
self.players = iter::repeat_with(|| {
let bot_id = Uuid::new_v4();
let cryps = instance_mobs(bot_id);
let mut p = Player::new(bot_id, &name(), cryps).set_bot(true);
let constructs = instance_mobs(bot_id);
let mut p = Player::new(bot_id, &name(), constructs).set_bot(true);
p.set_ready(true);
p
})
@@ -202,8 +202,8 @@ impl Instance {
self.players[i].set_ready(v);
// start the game even if afk noobs have no skills
if !self.phase_timed_out() && self.players[i].cryps.iter().all(|c| c.skills.len() == 0) {
return Err(err_msg("your cryps have no skills"));
if !self.phase_timed_out() && self.players[i].constructs.iter().all(|c| c.skills.len() == 0) {
return Err(err_msg("your constructs have no skills"));
}
// create a game object if both players are ready
@@ -247,7 +247,7 @@ impl Instance {
game
.set_player_num(2)
.set_player_cryps(3)
.set_player_constructs(3)
.set_instance(self.id);
// create the initiators player
@@ -472,17 +472,17 @@ impl Instance {
Ok(self)
}
pub fn vbox_apply(mut self, account: Uuid, index: usize, cryp_id: Uuid) -> Result<Instance, Error> {
pub fn vbox_apply(mut self, account: Uuid, index: usize, construct_id: Uuid) -> Result<Instance, Error> {
self.vbox_action_allowed(account)?;
self.account_player(account)?
.vbox_apply(index, cryp_id)?;
.vbox_apply(index, construct_id)?;
Ok(self)
}
pub fn vbox_unequip(mut self, account: Uuid, target: Item, cryp_id: Uuid) -> Result<Instance, Error> {
pub fn vbox_unequip(mut self, account: Uuid, target: Item, construct_id: Uuid) -> Result<Instance, Error> {
self.vbox_action_allowed(account)?;
self.account_player(account)?
.vbox_unequip(target, cryp_id)?;
.vbox_unequip(target, construct_id)?;
Ok(self)
}
}
@@ -627,7 +627,7 @@ pub fn instance_new(params: InstanceLobbyParams, tx: &mut Transaction, account:
};
instance = instance_create(tx, instance)?;
let join_params = InstanceJoinParams { instance_id: instance.id, cryp_ids: params.cryp_ids };
let join_params = InstanceJoinParams { instance_id: instance.id, construct_ids: params.construct_ids };
instance_join(join_params, tx, account)
}
@@ -635,16 +635,16 @@ pub fn instance_new(params: InstanceLobbyParams, tx: &mut Transaction, account:
pub fn instance_join(params: InstanceJoinParams, tx: &mut Transaction, account: &Account) -> Result<Instance, Error> {
let mut instance = instance_get(tx, params.instance_id)?;
let cryps = params.cryp_ids
let constructs = params.construct_ids
.iter()
.map(|id| cryp_get(tx, *id, account.id))
.collect::<Result<Vec<Cryp>, Error>>()?;
.map(|id| construct_get(tx, *id, account.id))
.collect::<Result<Vec<Construct>, Error>>()?;
if cryps.len() != 3 {
if constructs.len() != 3 {
return Err(format_err!("incorrect player size. ({:})", 3));
}
let player = player_create(tx, Player::new(account.id, &account.name, cryps), instance.id, account)?;
let player = player_create(tx, Player::new(account.id, &account.name, constructs), instance.id, account)?;
instance.add_player(player)?;
@@ -736,8 +736,8 @@ mod tests {
.add_bots();
let player_account = Uuid::new_v4();
let cryps = instance_mobs(player_account);
let player = Player::new(player_account, &"test".to_string(), cryps).set_bot(true);
let constructs = instance_mobs(player_account);
let player = Player::new(player_account, &"test".to_string(), constructs).set_bot(true);
let player_id = player.id;
instance.add_player(player).expect("could not add player");
@@ -754,8 +754,8 @@ mod tests {
fn instance_bot_vbox_test() {
let instance = Instance::new();
let player_account = Uuid::new_v4();
let cryps = instance_mobs(player_account);
let _player = Player::new(player_account, &"test".to_string(), cryps).set_bot(true);
let constructs = instance_mobs(player_account);
let _player = Player::new(player_account, &"test".to_string(), constructs).set_bot(true);
}
#[test]
@@ -767,16 +767,16 @@ mod tests {
assert_eq!(instance.max_players, 2);
let player_account = Uuid::new_v4();
let cryps = instance_mobs(player_account);
let player = Player::new(player_account, &"a".to_string(), cryps);
let constructs = instance_mobs(player_account);
let player = Player::new(player_account, &"a".to_string(), constructs);
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 cryps = instance_mobs(player_account);
let player = Player::new(player_account, &"b".to_string(), cryps);
let constructs = instance_mobs(player_account);
let player = Player::new(player_account, &"b".to_string(), constructs);
let b_id = player.id;
instance.add_player(player).expect("could not add player");
@@ -806,16 +806,16 @@ mod tests {
.expect("could not create instance");
let player_account = Uuid::new_v4();
let cryps = instance_mobs(player_account);
let player = Player::new(player_account, &"a".to_string(), cryps);
let constructs = instance_mobs(player_account);
let player = Player::new(player_account, &"a".to_string(), constructs);
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 cryps = instance_mobs(player_account);
let player = Player::new(player_account, &"b".to_string(), cryps);
let constructs = instance_mobs(player_account);
let player = Player::new(player_account, &"b".to_string(), constructs);
let b_id = player.id;
instance.add_player(player).expect("could not add player");
+34 -34
View File
@@ -1,6 +1,6 @@
use skill::{Skill, Effect, Colour};
use spec::{Spec};
use cryp::{Colours};
use construct::{Colours};
#[derive(Debug,Copy,Clone,Serialize,Deserialize,PartialEq,PartialOrd,Ord,Eq)]
pub enum Item {
@@ -277,46 +277,46 @@ impl Item {
100 - self.into_skill().unwrap().effect().first().unwrap().get_multiplier()),
Item::Stun => format!("Stun target cryp for {:?}T",
Item::Stun => format!("Stun target construct for {:?}T",
self.into_skill().unwrap().effect().first().unwrap().get_duration()),
Item::Buff => format!("Increase target cryp red damage and speed by {:?}%",
Item::Buff => format!("Increase target construct red damage and speed by {:?}%",
self.into_skill().unwrap().effect().first().unwrap().get_multiplier() - 100),
Item::Debuff => format!("Slow target cryp speed by {:?}%",
Item::Debuff => format!("Slow target construct speed by {:?}%",
100 - self.into_skill().unwrap().effect().first().unwrap().get_multiplier()),
// specs
// Base
Item::Damage => format!("Base ITEM for increased DAMAGE. DAMAGE determines the power of your SKILLS."),
Item::Life => format!("Base ITEM for increased LIFE.
When your CRYP reaches 0 GreenLife it becomes KO and cannot cast SKILLS."),
When your CONSTRUCT reaches 0 GreenLife it becomes KO and cannot cast SKILLS."),
Item::Speed => format!("Base ITEM for increased SPEED.
SPEED determines the order in which skills resolve."),
// Lifes Upgrades
Item::GreenLifeI => format!("Increases CRYP GreenLife.
When your CRYP reaches 0 GreenLife it becomes KO and cannot cast SKILLS."),
Item::RedLifeI => format!("Increases CRYP RedLife.
Red damage dealt to your cryp reduces RedLife before GreenLife."),
Item::BlueLifeI => format!("Increases CRYP BlueLife.
Blue damage dealt to your cryp reduces BlueLife before GreenLife."),
Item::GRLI => format!("Increases CRYP GreenLife + RedLife"),
Item::GBLI => format!("Increases CRYP GreenLife + BlueLife"),
Item::RBLI => format!("Increases CRYP RedLife + BlueLife"),
Item::GreenLifeI => format!("Increases CONSTRUCT GreenLife.
When your CONSTRUCT reaches 0 GreenLife it becomes KO and cannot cast SKILLS."),
Item::RedLifeI => format!("Increases CONSTRUCT RedLife.
Red damage dealt to your construct reduces RedLife before GreenLife."),
Item::BlueLifeI => format!("Increases CONSTRUCT BlueLife.
Blue damage dealt to your construct reduces BlueLife before GreenLife."),
Item::GRLI => format!("Increases CONSTRUCT GreenLife + RedLife"),
Item::GBLI => format!("Increases CONSTRUCT GreenLife + BlueLife"),
Item::RBLI => format!("Increases CONSTRUCT RedLife + BlueLife"),
// Damage Upgrades
Item::RedDamageI => format!("Increases CRYP RedDamage."),
Item::BlueDamageI => format!("Increases CRYP BlueDamage."),
Item::GreenDamageI => format!("Increases CRYP GreenDamage."),
Item::GRDI => format!("Increases CRYP GreenDamage + RedDamage."),
Item::GBDI => format!("Increases CRYP GreenDamage + BlueDamage."),
Item::RBDI => format!("Increases CRYP RedDamage + BlueDamage."),
Item::RedDamageI => format!("Increases CONSTRUCT RedDamage."),
Item::BlueDamageI => format!("Increases CONSTRUCT BlueDamage."),
Item::GreenDamageI => format!("Increases CONSTRUCT GreenDamage."),
Item::GRDI => format!("Increases CONSTRUCT GreenDamage + RedDamage."),
Item::GBDI => format!("Increases CONSTRUCT GreenDamage + BlueDamage."),
Item::RBDI => format!("Increases CONSTRUCT RedDamage + BlueDamage."),
// Speed Upgrades
Item::RedSpeedI => format!("Increases CRYP SPEED and provides COLOUR BONUSES"),
Item::BlueSpeedI => format!("Increases CRYP SPEED and provides COLOUR BONUSES"),
Item::GreenSpeedI => format!("Increases CRYP SPEED and provides COLOUR BONUSES"),
Item::GRSpeedI => format!("Increases CRYP SPEED and provides COLOUR BONUSES"),
Item::GBSpeedI => format!("Increases CRYP SPEED and provides COLOUR BONUSES"),
Item::RBSpeedI => format!("Increases CRYP SPEED and provides COLOUR BONUSES"),
Item::RedSpeedI => format!("Increases CONSTRUCT SPEED and provides COLOUR BONUSES"),
Item::BlueSpeedI => format!("Increases CONSTRUCT SPEED and provides COLOUR BONUSES"),
Item::GreenSpeedI => format!("Increases CONSTRUCT SPEED and provides COLOUR BONUSES"),
Item::GRSpeedI => format!("Increases CONSTRUCT SPEED and provides COLOUR BONUSES"),
Item::GBSpeedI => format!("Increases CONSTRUCT SPEED and provides COLOUR BONUSES"),
Item::RBSpeedI => format!("Increases CONSTRUCT SPEED and provides COLOUR BONUSES"),
// Skills <- need to move effect mulltipliers into skills
Item::Amplify => format!("Increase red and blue power by {:?}%. Lasts {:?}T",
@@ -324,7 +324,7 @@ impl Item {
self.into_skill().unwrap().effect().first().unwrap().get_duration()),
Item::Banish => format!("Banish target for {:?}T.
Banished cryps are immune to all skills and effects.",
Banished constructs are immune to all skills and effects.",
self.into_skill().unwrap().effect().first().unwrap().get_duration()),
Item::Blast => format!("Deals blue damage {:?}% blue power.", self.into_skill().unwrap().multiplier()),
@@ -333,7 +333,7 @@ impl Item {
"Hits twice for red and blue damage. Damage is random 0 to 30% + {:?}% red and blue power.",
self.into_skill().unwrap().multiplier()),
Item::Clutch => format!("Cryp cannot be KO'd while active.
Item::Clutch => format!("Construct cannot be KO'd while active.
Additionally provides immunity to disables."),
Item::Corrupt => format!(
@@ -370,7 +370,7 @@ impl Item {
Item::Heal => format!("Heals for {:?}% green power.", self.into_skill().unwrap().multiplier()),
Item::Hex => format!("Blue based skill that applies Hex for {:?}T. \
Hexed targets cannot cast any skills.",
Hexed targets cannot cast any skills.",
self.into_skill().unwrap().effect().first().unwrap().get_duration()),
@@ -389,10 +389,10 @@ impl Item {
"Self targetting skill. Recharges RedLife for",
self.into_skill().unwrap().multiplier(),
self.into_skill().unwrap().effect().first().unwrap().get_duration(),
"If a red skill is parried the cryp will riposte the source dealing red damage",
"If a red skill is parried the construct will riposte the source dealing red damage",
Skill::Riposte.multiplier()),
Item::Purge => format!("Remove buffs from target cryp"),
Item::Purge => format!("Remove buffs from target construct"),
Item::Purify => format!(
"Remove debuffs and heals for {:?}% green power per debuff removed.",
@@ -406,11 +406,11 @@ impl Item {
self.into_skill().unwrap().multiplier()),
Item::Ruin => format!(
"Team wide Stun for {:?}T. Stunned cryps are unable to cast skills.",
"Team wide Stun for {:?}T. Stunned constructs are unable to cast skills.",
self.into_skill().unwrap().effect().first().unwrap().get_duration()),
Item::Scatter => format!(
"Caster links with target. Linked cryps split incoming damage evenly. Recharges target blue shield {:?}% of blue power",
"Caster links with target. Linked constructs split incoming damage evenly. Recharges target blue shield {:?}% of blue power",
self.into_skill().unwrap().multiplier()),
Item::Silence => format!(
+3 -3
View File
@@ -1,7 +1,7 @@
extern crate rand;
extern crate uuid;
extern crate tungstenite;
extern crate bcrypt;
extern crate bconstructt;
extern crate chrono;
extern crate dotenv;
@@ -18,7 +18,7 @@ extern crate fern;
#[macro_use] extern crate log;
mod account;
mod cryp;
mod construct;
mod game;
mod instance;
mod item;
@@ -51,7 +51,7 @@ fn setup_logger() -> Result<(), fern::InitError> {
.level_for("tungstenite", log::LevelFilter::Info)
.level(log::LevelFilter::Debug)
.chain(std::io::stdout())
.chain(fern::log_file("log/cryps.log")?)
.chain(fern::log_file("log/constructs.log")?)
.apply()?;
Ok(())
}
+30 -30
View File
@@ -4,10 +4,10 @@ use rand::prelude::*;
use rand::distributions::Alphanumeric;
use std::iter;
use cryp::{Cryp};
use construct::{Construct};
use skill::{Skill};
pub fn generate_mob() -> Cryp {
pub fn generate_mob() -> Construct {
let mut rng = thread_rng();
let name: String = iter::repeat(())
@@ -15,86 +15,86 @@ pub fn generate_mob() -> Cryp {
.take(8)
.collect();
let mob = Cryp::new()
let mob = Construct::new()
.named(&name);
return mob;
}
// fn quick_game(player_size: usize) -> Vec<Cryp> {
// fn quick_game(player_size: usize) -> Vec<Construct> {
// iter::repeat_with(||
// generate_mob()
// .set_account(Uuid::nil())
// .learn(Skill::Attack))
// .take(player_size)
// .collect::<Vec<Cryp>>()
// .collect::<Vec<Construct>>()
// }
pub fn instance_mobs(player_id: Uuid) -> Vec<Cryp> {
pub fn instance_mobs(player_id: Uuid) -> Vec<Construct> {
iter::repeat_with(||
generate_mob()
.set_account(player_id))
// .learn(Skill::Attack))
.take(3)
.collect::<Vec<Cryp>>()
.collect::<Vec<Construct>>()
}
// fn zone_3v2_attack(player_lvl: u8) -> Vec<Cryp> {
// let x = Cryp::new()
// fn zone_3v2_attack(player_lvl: u8) -> Vec<Construct> {
// let x = Construct::new()
// .named(&"hench".to_string())
// .learn(Skill::Attack);
// let y = Cryp::new()
// let y = Construct::new()
// .named(&"bench".to_string())
// .learn(Skill::Attack);
// return vec![x, y];
// }
// fn zone_2v2_caster(player_lvl: u8) -> Vec<Cryp> {
// let x = Cryp::new()
// fn zone_2v2_caster(player_lvl: u8) -> Vec<Construct> {
// let x = Construct::new()
// .named(&"robe".to_string())
// .learn(Skill::Blast);
// let y = Cryp::new()
// let y = Construct::new()
// .named(&"wizard hat".to_string())
// .learn(Skill::Blast);
// return vec![x, y];
// }
// fn zone_3v3_melee_miniboss(player_lvl: u8) -> Vec<Cryp> {
// let x = Cryp::new()
// fn zone_3v3_melee_miniboss(player_lvl: u8) -> Vec<Construct> {
// let x = Construct::new()
// .named(&"jungle juice".to_string())
// .learn(Skill::Attack);
// let y = Cryp::new()
// let y = Construct::new()
// .named(&"bamboo basher".to_string())
// .learn(Skill::Attack)
// .learn(Skill::Stun);
// let z = Cryp::new()
// let z = Construct::new()
// .named(&"lemongrass tea".to_string())
// .learn(Skill::Attack);
// return vec![x, y, z];
// }
// fn zone_3v3_healer_boss(player_lvl: u8) -> Vec<Cryp> {
// let x = Cryp::new()
// fn zone_3v3_healer_boss(player_lvl: u8) -> Vec<Construct> {
// let x = Construct::new()
// .named(&"coinage".to_string())
// .learn(Skill::Attack)
// .learn(Skill::Parry)
// .learn(Skill::Block);
// let y = Cryp::new()
// let y = Construct::new()
// .named(&"wololo".to_string())
// // big strong
// // .learn(Skill::Blast)
// .learn(Skill::Heal)
// .learn(Skill::Triage);
// let z = Cryp::new()
// let z = Construct::new()
// .named(&"quarry".to_string())
// .learn(Skill::Attack)
// .learn(Skill::Parry)
@@ -104,22 +104,22 @@ pub fn instance_mobs(player_id: Uuid) -> Vec<Cryp> {
// }
// pub fn generate_mob_player(mode: GameMode, cryps: &Vec<Cryp>) -> Player {
// pub fn generate_mob_player(mode: GameMode, constructs: &Vec<Construct>) -> Player {
// let mut mob_player = Player::new(Uuid::nil());
// let cryp_lvl = cryps.iter().max_by_key(|c| c.lvl).unwrap().lvl;
// let player_size = cryps.len();
// let construct_lvl = constructs.iter().max_by_key(|c| c.lvl).unwrap().lvl;
// let player_size = constructs.len();
// let mobs = match mode {
// GameMode::Normal => quick_game(cryp_lvl, player_size),
// GameMode::Zone3v2Attack => zone_3v2_attack(cryp_lvl),
// GameMode::Zone2v2Caster => zone_2v2_caster(cryp_lvl),
// GameMode::Zone3v3MeleeMiniboss => zone_3v3_melee_miniboss(cryp_lvl),
// GameMode::Zone3v3HealerBoss => zone_3v3_healer_boss(cryp_lvl),
// GameMode::Normal => quick_game(construct_lvl, player_size),
// GameMode::Zone3v2Attack => zone_3v2_attack(construct_lvl),
// GameMode::Zone2v2Caster => zone_2v2_caster(construct_lvl),
// GameMode::Zone3v3MeleeMiniboss => zone_3v3_melee_miniboss(construct_lvl),
// GameMode::Zone3v3HealerBoss => zone_3v3_healer_boss(construct_lvl),
// _ => panic!("{:?} not handled for pve mobs", mode),
// };
// mob_player.set_cryps(mobs);
// mob_player.set_constructs(mobs);
// return mob_player;
+64 -64
View File
@@ -9,10 +9,10 @@ use failure::Error;
use failure::err_msg;
use account::Account;
use cryp::{Cryp, Colours, cryp_get};
use construct::{Construct, Colours, construct_get};
use vbox::{Vbox};
use item::{Item, ItemEffect};
use rpc::{PlayerCrypsSetParams};
use rpc::{PlayerConstructsSetParams};
use instance::{Instance};
use skill::{Effect};
@@ -30,20 +30,20 @@ pub struct Player {
pub name: String,
pub vbox: Vbox,
pub score: Score,
pub cryps: Vec<Cryp>,
pub constructs: Vec<Construct>,
pub bot: bool,
pub ready: bool,
pub warnings: u8,
}
impl Player {
pub fn new(account: Uuid, name: &String, cryps: Vec<Cryp>) -> Player {
pub fn new(account: Uuid, name: &String, constructs: Vec<Construct>) -> Player {
Player {
id: account,
name: name.clone(),
vbox: Vbox::new(),
score: Score { wins: 0, losses: 0 },
cryps,
constructs,
bot: false,
ready: false,
warnings: 0,
@@ -66,8 +66,8 @@ impl Player {
}
pub fn forfeit(&mut self) -> &mut Player {
for cryp in self.cryps.iter_mut() {
cryp.force_ko();
for construct in self.constructs.iter_mut() {
construct.force_ko();
}
self
}
@@ -84,19 +84,19 @@ impl Player {
self
}
pub fn cryp_get(&mut self, id: Uuid) -> Result<&mut Cryp, Error> {
self.cryps.iter_mut().find(|c| c.id == id).ok_or(err_msg("cryp not found"))
pub fn construct_get(&mut self, id: Uuid) -> Result<&mut Construct, Error> {
self.constructs.iter_mut().find(|c| c.id == id).ok_or(err_msg("construct not found"))
}
pub fn autobuy(&mut self) -> &mut Player {
let mut rng = thread_rng();
// first check if any cryps have no skills
// 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.cryps.iter().position(|c| c.skills.len() == 0) {
while let Some(c) = self.constructs.iter().position(|c| c.skills.len() == 0) {
if let Some(s) = self.vbox.bound.iter().position(|v| v.into_skill().is_some()) {
let cryp_id = self.cryps[c].id;
self.vbox_apply(s, cryp_id).expect("could not apply");
let construct_id = self.constructs[c].id;
self.vbox_apply(s, construct_id).expect("could not apply");
continue;
}
info!("no skills available...");
@@ -106,23 +106,23 @@ impl Player {
// inb4 montecarlo gan
loop {
let (target_cryp_i, target_cryp_id) = match self.cryps.iter().any(|c| c.skills.len() < 3) {
let (target_construct_i, target_construct_id) = match self.constructs.iter().any(|c| c.skills.len() < 3) {
true => {
let mut target_cryp_i = 0;
for (j, c) in self.cryps.iter().enumerate() {
if c.skills.len() < self.cryps[target_cryp_i].skills.len() {
target_cryp_i = j;
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_cryp_i, self.cryps[target_cryp_i].id)
(target_construct_i, self.constructs[target_construct_i].id)
},
false => {
let i = rng.gen_range(0, 3);
(i, self.cryps[i].id)
(i, self.constructs[i].id)
},
};
let needs_skills = self.cryps[target_cryp_i].skills.len() < 3;
let needs_skills = self.constructs[target_construct_i].skills.len() < 3;
let group_i = match needs_skills {
true => 1,
false => 2,
@@ -161,7 +161,7 @@ impl Player {
// first 2 colours can be whatever
self.vbox_combine(vec![0, 1, combo_i]).ok();
let item_i = self.vbox.bound.len() - 1;
self.vbox_apply(item_i, target_cryp_id).ok();
self.vbox_apply(item_i, target_construct_id).ok();
}
return self;
@@ -188,7 +188,7 @@ impl Player {
Ok(self)
}
pub fn vbox_apply(&mut self, index: usize, cryp_id: Uuid) -> Result<&mut Player, Error> {
pub fn vbox_apply(&mut self, index: usize, construct_id: Uuid) -> Result<&mut Player, Error> {
if self.vbox.bound.get(index).is_none() {
return Err(format_err!("no item at index {:?}", index));
}
@@ -198,31 +198,31 @@ impl Player {
match item.effect() {
Some(ItemEffect::Skill) => {
let skill = item.into_skill().ok_or(format_err!("item {:?} has no associated skill", item))?;
let cryp = self.cryp_get(cryp_id)?;
let construct = self.construct_get(construct_id)?;
// done here because i teach them a tonne of skills for tests
let max_skills = 3;
if cryp.skills.len() >= max_skills {
return Err(format_err!("cryp at max skills ({:?})", max_skills));
if construct.skills.len() >= max_skills {
return Err(format_err!("construct at max skills ({:?})", max_skills));
}
if cryp.knows(skill) {
return Err(format_err!("cryp already knows skill ({:?})" , skill));
if construct.knows(skill) {
return Err(format_err!("construct already knows skill ({:?})" , skill));
}
cryp.learn_mut(skill);
construct.learn_mut(skill);
},
Some(ItemEffect::Spec) => {
let spec = item.into_spec().ok_or(format_err!("item {:?} has no associated spec", item))?;
let cryp = self.cryp_get(cryp_id)?;
cryp.spec_add(spec)?;
let construct = self.construct_get(construct_id)?;
construct.spec_add(spec)?;
},
None => return Err(err_msg("item has no effect on cryps")),
None => return Err(err_msg("item has no effect on constructs")),
}
// now the item has been applied
// recalculate the stats of the whole player
let player_colours = self.cryps.iter().fold(Colours::new(), |tc, c| {
let player_colours = self.constructs.iter().fold(Colours::new(), |tc, c| {
Colours {
red: tc.red + c.colours.red,
green: tc.green + c.colours.green,
@@ -230,14 +230,14 @@ impl Player {
}
});
for cryp in self.cryps.iter_mut() {
cryp.apply_modifiers(&player_colours);
for construct in self.constructs.iter_mut() {
construct.apply_modifiers(&player_colours);
}
Ok(self)
}
pub fn vbox_unequip(&mut self, target: Item, cryp_id: Uuid) -> Result<&mut Player, Error> {
pub fn vbox_unequip(&mut self, target: Item, construct_id: Uuid) -> Result<&mut Player, Error> {
if self.vbox.bound.len() >= 9 {
return Err(err_msg("too many items bound"));
}
@@ -245,20 +245,20 @@ impl Player {
match target.effect() {
Some(ItemEffect::Skill) => {
let skill = target.into_skill().ok_or(format_err!("item {:?} has no associated skill", target))?;
let cryp = self.cryp_get(cryp_id)?;
cryp.forget(skill)?;
let construct = self.construct_get(construct_id)?;
construct.forget(skill)?;
},
Some(ItemEffect::Spec) => {
let spec = target.into_spec().ok_or(format_err!("item {:?} has no associated spec", target))?;
let cryp = self.cryp_get(cryp_id)?;
cryp.spec_remove(spec)?;
let construct = self.construct_get(construct_id)?;
construct.spec_remove(spec)?;
},
None => return Err(err_msg("item has no effect on cryps")),
None => return Err(err_msg("item has no effect on constructs")),
}
// now the item has been applied
// recalculate the stats of the whole player
let player_colours = self.cryps.iter().fold(Colours::new(), |tc, c| {
let player_colours = self.constructs.iter().fold(Colours::new(), |tc, c| {
Colours {
red: tc.red + c.colours.red,
green: tc.green + c.colours.green,
@@ -266,8 +266,8 @@ impl Player {
}
});
for cryp in self.cryps.iter_mut() {
cryp.apply_modifiers(&player_colours);
for construct in self.constructs.iter_mut() {
construct.apply_modifiers(&player_colours);
}
self.vbox.bound.push(target);
@@ -278,27 +278,27 @@ impl Player {
// GAME METHODS
pub fn skills_required(&self) -> usize {
let required = self.cryps.iter()
let required = self.constructs.iter()
.filter(|c| !c.is_ko())
.filter(|c| c.available_skills().len() > 0)
.collect::<Vec<&Cryp>>().len();
.collect::<Vec<&Construct>>().len();
// info!("{:} requires {:} skills this turn", self.id, required);
return required;
}
pub fn taunting(&self) -> Option<&Cryp> {
self.cryps.iter()
pub fn taunting(&self) -> Option<&Construct> {
self.constructs.iter()
.find(|c| c.affected(Effect::Taunt))
}
pub fn set_cryps(&mut self, mut cryps: Vec<Cryp>) -> &mut Player {
cryps.sort_unstable_by_key(|c| c.id);
self.cryps = cryps;
pub fn set_constructs(&mut self, mut constructs: Vec<Construct>) -> &mut Player {
constructs.sort_unstable_by_key(|c| c.id);
self.constructs = constructs;
self
}
pub fn cryp_by_id(&mut self, id: Uuid) -> Option<&mut Cryp> {
self.cryps.iter_mut().find(|c| c.id == id)
pub fn construct_by_id(&mut self, id: Uuid) -> Option<&mut Construct> {
self.constructs.iter_mut().find(|c| c.id == id)
}
}
@@ -320,7 +320,7 @@ pub fn player_get(tx: &mut Transaction, account_id: Uuid, instance_id: Uuid) ->
None => return Err(err_msg("player not found")),
};
// tells from_slice to cast into a cryp
// tells from_slice to cast into a construct
let bytes: Vec<u8> = returned.get("data");
let data = from_slice::<Player>(&bytes)?;
@@ -386,24 +386,24 @@ pub fn player_delete(tx: &mut Transaction, id: Uuid) -> Result<(), Error> {
return Ok(());
}
pub fn player_mm_cryps_set(params: PlayerCrypsSetParams, tx: &mut Transaction, account: &Account) -> Result<Instance, Error> {
if params.cryp_ids.len() != 3 {
pub fn player_mm_constructs_set(params: PlayerConstructsSetParams, tx: &mut Transaction, account: &Account) -> Result<Instance, Error> {
if params.construct_ids.len() != 3 {
return Err(err_msg("player size is 3"));
}
let cryps = params.cryp_ids
let constructs = params.construct_ids
.iter()
.map(|id| cryp_get(tx, *id, account.id))
.collect::<Result<Vec<Cryp>, Error>>()?;
.map(|id| construct_get(tx, *id, account.id))
.collect::<Result<Vec<Construct>, Error>>()?;
let player = match player_get(tx, account.id, Uuid::nil()) {
Ok(mut p) => {
p.cryps = cryps;
p.constructs = constructs;
p.vbox = Vbox::new();
player_global_update(tx, p, false)?
},
Err(_) => {
player_create(tx, Player::new(account.id, &account.name, cryps), Uuid::nil(), &account)?
player_create(tx, Player::new(account.id, &account.name, constructs), Uuid::nil(), &account)?
}
};
@@ -419,12 +419,12 @@ mod tests {
#[test]
fn player_bot_vbox_test() {
let player_account = Uuid::new_v4();
let cryps = instance_mobs(player_account);
let mut player = Player::new(player_account, &"test".to_string(), cryps).set_bot(true);
let constructs = instance_mobs(player_account);
let mut player = Player::new(player_account, &"test".to_string(), constructs).set_bot(true);
player.vbox.fill();
player.autobuy();
assert!(player.cryps.iter().all(|c| c.skills.len() >= 1));
assert!(player.constructs.iter().all(|c| c.skills.len() >= 1));
}
}
+57 -57
View File
@@ -16,12 +16,12 @@ use failure::Error;
use failure::err_msg;
use net::Db;
use cryp::{Cryp, cryp_spawn};
use construct::{Construct, construct_spawn};
use game::{Game, game_state, game_skill, game_ready};
use account::{Account, account_create, account_login, account_from_token, account_cryps, account_instances};
use account::{Account, account_create, account_login, account_from_token, account_constructs, account_instances};
use skill::{Skill};
use spec::{Spec};
use player::{Score, player_mm_cryps_set};
use player::{Score, player_mm_constructs_set};
use instance::{Instance, instance_state, instance_new, instance_ready, instance_join};
use vbox::{vbox_accept, vbox_apply, vbox_discard, vbox_combine, vbox_reclaim, vbox_unequip};
use item::{Item, ItemInfoCtr, item_info};
@@ -71,11 +71,11 @@ impl Rpc {
"account_login" => Rpc::account_login(data, &mut tx, client),
// auth methods
"account_cryps" => Rpc::account_cryps(data, &mut tx, account.unwrap(), client),
"account_constructs" => Rpc::account_constructs(data, &mut tx, account.unwrap(), client),
"account_instances" => Rpc::account_instances(data, &mut tx, account.unwrap(), client),
// "account_zone" => Rpc::account_zone(data, &mut tx, account.unwrap(), client),
"cryp_spawn" => Rpc::cryp_spawn(data, &mut tx, account.unwrap(), client),
"construct_spawn" => Rpc::construct_spawn(data, &mut tx, account.unwrap(), client),
"game_state" => Rpc::game_state(data, &mut tx, account.unwrap(), client),
"game_skill" => Rpc::game_skill(data, &mut tx, account.unwrap(), client),
@@ -86,7 +86,7 @@ impl Rpc {
"instance_new" => Rpc::instance_new(data, &mut tx, account.unwrap(), client),
"instance_state" => Rpc::instance_state(data, &mut tx, account.unwrap(), client),
"player_mm_cryps_set" => Rpc::player_mm_cryps_set(data, &mut tx, account.unwrap(), client),
"player_mm_constructs_set" => Rpc::player_mm_constructs_set(data, &mut tx, account.unwrap(), client),
"player_vbox_accept" => Rpc::player_vbox_accept(data, &mut tx, account.unwrap(), client),
"player_vbox_apply" => Rpc::player_vbox_apply(data, &mut tx, account.unwrap(), client),
"player_vbox_combine" => Rpc::player_vbox_combine(data, &mut tx, account.unwrap(), client),
@@ -165,20 +165,20 @@ impl Rpc {
}
fn cryp_spawn(data: Vec<u8>, tx: &mut Transaction, account: Account, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
let msg = from_slice::<CrypSpawnMsg>(&data).or(Err(err_msg("invalid params")))?;
fn construct_spawn(data: Vec<u8>, tx: &mut Transaction, account: Account, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
let msg = from_slice::<ConstructSpawnMsg>(&data).or(Err(err_msg("invalid params")))?;
Rpc::send_msg(client, RpcResponse {
method: "cryp_spawn".to_string(),
params: RpcResult::CrypSpawn(cryp_spawn(msg.params, tx, &account)?)
method: "construct_spawn".to_string(),
params: RpcResult::ConstructSpawn(construct_spawn(msg.params, tx, &account)?)
})?;
let cryp_list = RpcResponse {
method: "account_cryps".to_string(),
params: RpcResult::CrypList(account_cryps(tx, &account)?)
let construct_list = RpcResponse {
method: "account_constructs".to_string(),
params: RpcResult::ConstructList(account_constructs(tx, &account)?)
};
Ok(cryp_list)
Ok(construct_list)
}
fn account_create(data: Vec<u8>, tx: &mut Transaction, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
@@ -210,13 +210,13 @@ impl Rpc {
// let account = account_create(AccountCreateParams { name: acc_name, password: "grepgrepgrep".to_string() }, tx)?;
// let name: String = iter::repeat(()).map(|()| rng.sample(Alphanumeric)).take(8).collect();
// cryp_spawn(CrypSpawnParams { name }, tx, &account)?;
// construct_spawn(ConstructSpawnParams { name }, tx, &account)?;
// let name: String = iter::repeat(()).map(|()| rng.sample(Alphanumeric)).take(8).collect();
// cryp_spawn(CrypSpawnParams { name }, tx, &account)?;
// construct_spawn(ConstructSpawnParams { name }, tx, &account)?;
// let name: String = iter::repeat(()).map(|()| rng.sample(Alphanumeric)).take(8).collect();
// cryp_spawn(CrypSpawnParams { name }, tx, &account)?;
// construct_spawn(ConstructSpawnParams { name }, tx, &account)?;
// let res = RpcResponse {
// method: "account_create".to_string(),
@@ -227,10 +227,10 @@ impl Rpc {
// }
fn account_cryps(_data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
fn account_constructs(_data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
Ok(RpcResponse {
method: "account_cryps".to_string(),
params: RpcResult::CrypList(account_cryps(tx, &account)?)
method: "account_constructs".to_string(),
params: RpcResult::ConstructList(account_constructs(tx, &account)?)
})
}
@@ -300,12 +300,12 @@ impl Rpc {
}
}
fn player_mm_cryps_set(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
let msg = from_slice::<PlayerCrypsSetMsg>(&data).or(Err(err_msg("invalid params")))?;
fn player_mm_constructs_set(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
let msg = from_slice::<PlayerConstructsSetMsg>(&data).or(Err(err_msg("invalid params")))?;
let response = RpcResponse {
method: "instance_state".to_string(),
params: RpcResult::InstanceState(player_mm_cryps_set(msg.params, tx, &account)?)
params: RpcResult::InstanceState(player_mm_constructs_set(msg.params, tx, &account)?)
};
return Ok(response);
@@ -354,8 +354,8 @@ impl Rpc {
};
Rpc::send_msg(client, RpcResponse {
method: "account_cryps".to_string(),
params: RpcResult::CrypList(account_cryps(tx, &account)?)
method: "account_constructs".to_string(),
params: RpcResult::ConstructList(account_constructs(tx, &account)?)
})?;
return Ok(response);
@@ -381,8 +381,8 @@ impl Rpc {
};
Rpc::send_msg(client, RpcResponse {
method: "account_cryps".to_string(),
params: RpcResult::CrypList(account_cryps(tx, &account)?)
method: "account_constructs".to_string(),
params: RpcResult::ConstructList(account_constructs(tx, &account)?)
})?;
return Ok(response);
@@ -397,12 +397,12 @@ pub struct RpcResponse {
#[derive(Debug,Clone,Serialize,Deserialize)]
pub enum RpcResult {
CrypSpawn(Cryp),
CrypForget(Cryp),
CrypLearn(Cryp),
CrypUnspec(Cryp),
ConstructSpawn(Construct),
ConstructForget(Construct),
ConstructLearn(Construct),
ConstructUnspec(Construct),
Account(Account),
CrypList(Vec<Cryp>),
ConstructList(Vec<Construct>),
GameState(Game),
ItemInfo(ItemInfoCtr),
InstanceScores(Vec<(String, Score)>),
@@ -422,50 +422,50 @@ pub struct RpcMessage {
}
#[derive(Debug,Clone,Serialize,Deserialize)]
struct CrypSpawnMsg {
struct ConstructSpawnMsg {
method: String,
params: CrypSpawnParams,
params: ConstructSpawnParams,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct CrypSpawnParams {
pub struct ConstructSpawnParams {
pub name: String,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
struct CrypLearnMsg {
struct ConstructLearnMsg {
method: String,
params: CrypLearnParams,
params: ConstructLearnParams,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct CrypLearnParams {
pub struct ConstructLearnParams {
pub id: Uuid,
pub skill: Skill,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct CrypForgetParams {
pub struct ConstructForgetParams {
pub id: Uuid,
pub skill: Skill,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
struct CrypForgetMsg {
struct ConstructForgetMsg {
method: String,
params: CrypForgetParams,
params: ConstructForgetParams,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct CrypUnspecParams {
pub struct ConstructUnspecParams {
pub id: Uuid,
pub spec: Spec,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
struct CrypUnspecMsg {
struct ConstructUnspecMsg {
method: String,
params: CrypUnspecParams,
params: ConstructUnspecParams,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
@@ -487,7 +487,7 @@ pub struct GameStateParams {
// #[derive(Debug,Clone,Serialize,Deserialize)]
// pub struct GamePveParams {
// pub cryp_ids: Vec<Uuid>,
// pub construct_ids: Vec<Uuid>,
// }
#[derive(Debug,Clone,Serialize,Deserialize)]
@@ -499,8 +499,8 @@ struct GameSkillMsg {
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct GameSkillParams {
pub game_id: Uuid,
pub cryp_id: Uuid,
pub target_cryp_id: Option<Uuid>,
pub construct_id: Uuid,
pub target_construct_id: Option<Uuid>,
pub skill: Skill,
}
@@ -529,7 +529,7 @@ pub struct AccountLoginParams {
}
#[derive(Debug,Clone,Serialize,Deserialize)]
struct AccountCrypsMsg {
struct AccountConstructsMsg {
method: String,
params: (),
}
@@ -542,7 +542,7 @@ struct InstanceLobbyMsg {
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct InstanceLobbyParams {
pub cryp_ids: Vec<Uuid>,
pub construct_ids: Vec<Uuid>,
pub name: String,
pub players: usize,
pub password: Option<String>,
@@ -557,7 +557,7 @@ struct InstanceJoinMsg {
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct InstanceJoinParams {
pub instance_id: Uuid,
pub cryp_ids: Vec<Uuid>,
pub construct_ids: Vec<Uuid>,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
@@ -583,14 +583,14 @@ pub struct InstanceStateParams {
}
#[derive(Debug,Clone,Serialize,Deserialize)]
struct PlayerCrypsSetMsg {
struct PlayerConstructsSetMsg {
method: String,
params: PlayerCrypsSetParams,
params: PlayerConstructsSetParams,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct PlayerCrypsSetParams {
pub cryp_ids: Vec<Uuid>,
pub struct PlayerConstructsSetParams {
pub construct_ids: Vec<Uuid>,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
@@ -638,7 +638,7 @@ struct VboxApplyMsg {
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct VboxApplyParams {
pub instance_id: Uuid,
pub cryp_id: Uuid,
pub construct_id: Uuid,
pub index: usize,
}
@@ -651,7 +651,7 @@ struct VboxUnequipMsg {
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct VboxUnequipParams {
pub instance_id: Uuid,
pub cryp_id: Uuid,
pub construct_id: Uuid,
pub target: Item,
}
@@ -674,7 +674,7 @@ pub struct VboxReclaimParams {
// #[test]
// fn rpc_parse() {
// let rpc = Rpc {};
// let msg = GenerateMsg { method: "cryp_generate".to_string(), params: GenerateParams { level: 64 } };
// let msg = GenerateMsg { method: "construct_generate".to_string(), params: GenerateParams { level: 64 } };
// let v = to_vec(&msg).unwrap();
// let received = rpc.receive(Message::Binary(v));
// }
+141 -141
View File
@@ -2,7 +2,7 @@ use rand::{thread_rng, Rng};
use uuid::Uuid;
use util::{IntPct};
use cryp::{Cryp, CrypEffect, EffectMeta, Stat};
use construct::{Construct, ConstructEffect, EffectMeta, Stat};
use item::{Item};
use game::{Game};
@@ -17,19 +17,19 @@ pub fn resolution_steps(cast: &Cast, game: &mut Game) -> Resolutions {
pub fn pre_resolve(cast: &Cast, game: &mut Game, mut resolutions: Resolutions) -> Resolutions {
let skill = cast.skill;
let source = game.cryp_by_id(cast.source_cryp_id).unwrap().clone();
let targets = game.get_targets(cast.skill, &source, cast.target_cryp_id);
let source = game.construct_by_id(cast.source_construct_id).unwrap().clone();
let targets = game.get_targets(cast.skill, &source, cast.target_construct_id);
if skill.aoe() { // Send an aoe skill event for anims
resolutions.push(Resolution::new(&source, &game.cryp_by_id(cast.target_cryp_id).unwrap().clone()).event(Event::AoeSkill { skill }));
resolutions.push(Resolution::new(&source, &game.construct_by_id(cast.target_construct_id).unwrap().clone()).event(Event::AoeSkill { skill }));
}
for target_id in targets {
// we clone the current state of the target and source
// so we can modify them during the resolution
// no more than 1 mutable ref allowed on game
let mut source = game.cryp_by_id(cast.source_cryp_id).unwrap().clone();
let mut target = game.cryp_by_id(target_id).unwrap().clone();
let mut source = game.construct_by_id(cast.source_construct_id).unwrap().clone();
let mut target = game.construct_by_id(target_id).unwrap().clone();
// bail out on ticks that have been removed
if skill.is_tick() && target.effects.iter().find(|ce| match ce.tick {
@@ -42,8 +42,8 @@ pub fn pre_resolve(cast: &Cast, game: &mut Game, mut resolutions: Resolutions) -
resolutions = resolve(cast.skill, &mut source, &mut target, resolutions);
// save the changes to the game
game.update_cryp(&mut source);
game.update_cryp(&mut target);
game.update_construct(&mut source);
game.update_construct(&mut target);
// do additional steps
resolutions = post_resolve(cast.skill, game, resolutions);
@@ -52,7 +52,7 @@ pub fn pre_resolve(cast: &Cast, game: &mut Game, mut resolutions: Resolutions) -
return resolutions;
}
pub fn resolve(skill: Skill, source: &mut Cryp, target: &mut Cryp, mut resolutions: Vec<Resolution>) -> Resolutions {
pub fn resolve(skill: Skill, source: &mut Construct, target: &mut Construct, mut resolutions: Vec<Resolution>) -> Resolutions {
if let Some(disable) = source.disabled(skill) {
resolutions.push(Resolution::new(source, target).event(Event::Disable { disable, skill }));
return resolutions;
@@ -179,8 +179,8 @@ pub fn resolve(skill: Skill, source: &mut Cryp, target: &mut Cryp, mut resolutio
fn post_resolve(_skill: Skill, game: &mut Game, mut resolutions: Resolutions) -> Resolutions {
for Resolution { source, target, event } in resolutions.clone() {
let mut source = game.cryp_by_id(source.id).unwrap().clone();
let mut target = game.cryp_by_id(target.id).unwrap().clone();
let mut source = game.construct_by_id(source.id).unwrap().clone();
let mut target = game.construct_by_id(target.id).unwrap().clone();
match event {
Event::Damage { amount, skill, mitigation: _, colour: _ } => {
@@ -208,8 +208,8 @@ fn post_resolve(_skill: Skill, game: &mut Game, mut resolutions: Resolutions) ->
_ => (),
};
game.update_cryp(&mut source);
game.update_cryp(&mut target);
game.update_construct(&mut source);
game.update_construct(&mut target);
};
return resolutions;
@@ -221,30 +221,30 @@ fn post_resolve(_skill: Skill, game: &mut Game, mut resolutions: Resolutions) ->
pub struct Cast {
pub id: Uuid,
pub source_player_id: Uuid,
pub source_cryp_id: Uuid,
pub target_cryp_id: Uuid,
pub source_construct_id: Uuid,
pub target_construct_id: Uuid,
pub skill: Skill,
pub speed: u64,
}
impl Cast {
pub fn new(source_cryp_id: Uuid, source_player_id: Uuid, target_cryp_id: Uuid, skill: Skill) -> Cast {
pub fn new(source_construct_id: Uuid, source_player_id: Uuid, target_construct_id: Uuid, skill: Skill) -> Cast {
return Cast {
id: Uuid::new_v4(),
source_cryp_id,
source_construct_id,
source_player_id,
target_cryp_id,
target_construct_id,
skill,
speed: 0,
};
}
pub fn new_tick(source: &mut Cryp, target: &mut Cryp, skill: Skill) -> Cast {
pub fn new_tick(source: &mut Construct, target: &mut Construct, skill: Skill) -> Cast {
Cast {
id: Uuid::new_v4(),
source_cryp_id: source.id,
source_construct_id: source.id,
source_player_id: source.account,
target_cryp_id: target.id,
target_construct_id: target.id,
skill,
speed: 0,
}
@@ -259,23 +259,23 @@ pub type Disable = Vec<Effect>;
pub type Immunity = Vec<Effect>;
#[derive(Debug,Clone,PartialEq,Serialize,Deserialize)]
pub struct LogCryp {
pub struct LogConstruct {
pub id: Uuid,
pub name: String,
}
#[derive(Debug,Clone,PartialEq,Serialize,Deserialize)]
pub struct Resolution {
pub source: LogCryp,
pub target: LogCryp,
pub source: LogConstruct,
pub target: LogConstruct,
pub event: Event,
}
impl Resolution {
fn new(source: &Cryp, target: &Cryp) -> Resolution {
fn new(source: &Construct, target: &Construct) -> Resolution {
Resolution {
source: LogCryp { id: source.id, name: source.name.clone() },
target: LogCryp { id: target.id, name: target.name.clone() },
source: LogConstruct { id: source.id, name: source.name.clone() },
target: LogConstruct { id: target.id, name: target.name.clone() },
event: Event::Incomplete,
}
}
@@ -641,49 +641,49 @@ impl Skill {
}
}
pub fn effect(&self) -> Vec<CrypEffect> {
pub fn effect(&self) -> Vec<ConstructEffect> {
match self {
// Modifiers
Skill::Amplify => vec![CrypEffect {effect: Effect::Amplify, duration: 2, meta: Some(EffectMeta::Multiplier(150)), tick: None}],
Skill::Banish => vec![CrypEffect {effect: Effect::Banish, duration: 1, meta: None, tick: None}],
Skill::Block => vec![CrypEffect {effect: Effect::Block, duration: 1, meta: Some(EffectMeta::Multiplier(50)), tick: None}],
Skill::Buff => vec![CrypEffect {effect: Effect::Buff, duration: 2, meta: Some(EffectMeta::Multiplier(125)), tick: None }],
Skill::Corrupt => vec![CrypEffect {effect: Effect::Corrupt, duration: 2, meta: None, tick: None},
CrypEffect {effect: Effect::Corruption, duration: 3, meta: None, tick: None}],
Skill::Clutch => vec![CrypEffect {effect: Effect::Clutch, duration: 1, meta: None, tick: None }],
Skill::Curse => vec![CrypEffect {effect: Effect::Curse, duration: 2, meta: Some(EffectMeta::Multiplier(150)), tick: None}],
Skill::Debuff => vec![CrypEffect {effect: Effect::Slow, duration: 3, meta: Some(EffectMeta::Multiplier(50)), tick: None }],
Skill::Decay => vec![CrypEffect {effect: Effect::Wither, duration: 3, meta: Some(EffectMeta::Multiplier(50)), tick: None },
CrypEffect {effect: Effect::Decay, duration: 3, meta: None, tick: None }],
Skill::Haste => vec![CrypEffect {effect: Effect::Haste, duration: 2, meta: Some(EffectMeta::Multiplier(150)), tick: None }],
Skill::Hex => vec![CrypEffect {effect: Effect::Hex, duration: 2, meta: None, tick: None}],
Skill::Hostility => vec![CrypEffect {effect: Effect::Hostility, duration: 2, meta: None, tick: None},
CrypEffect {effect: Effect::Hatred, duration: 5, meta: None, tick: None}],
Skill::Impurity => vec![CrypEffect {effect: Effect::Impurity, duration: 3, meta: Some(EffectMeta::Multiplier(150)), tick: None }],
Skill::Invert => vec![CrypEffect {effect: Effect::Invert, duration: 2, meta: None, tick: None}],
Skill::Amplify => vec![ConstructEffect {effect: Effect::Amplify, duration: 2, meta: Some(EffectMeta::Multiplier(150)), tick: None}],
Skill::Banish => vec![ConstructEffect {effect: Effect::Banish, duration: 1, meta: None, tick: None}],
Skill::Block => vec![ConstructEffect {effect: Effect::Block, duration: 1, meta: Some(EffectMeta::Multiplier(50)), tick: None}],
Skill::Buff => vec![ConstructEffect {effect: Effect::Buff, duration: 2, meta: Some(EffectMeta::Multiplier(125)), tick: None }],
Skill::Parry => vec![CrypEffect {effect: Effect::Parry, duration: 2, meta: None, tick: None }],
Skill::Reflect => vec![CrypEffect {effect: Effect::Reflect, duration: 1, meta: None, tick: None }],
Skill::Throw => vec![CrypEffect {effect: Effect::Stun, duration: 1, meta: None, tick: None},
CrypEffect {effect: Effect::Vulnerable, duration: 3, meta: Some(EffectMeta::Multiplier(150)), tick: None}],
Skill::Corrupt => vec![ConstructEffect {effect: Effect::Corrupt, duration: 2, meta: None, tick: None},
ConstructEffect {effect: Effect::Corruption, duration: 3, meta: None, tick: None}],
Skill::Ruin => vec![CrypEffect {effect: Effect::Stun, duration: 1, meta: None, tick: None}],
Skill::Clutch => vec![ConstructEffect {effect: Effect::Clutch, duration: 1, meta: None, tick: None }],
Skill::Curse => vec![ConstructEffect {effect: Effect::Curse, duration: 2, meta: Some(EffectMeta::Multiplier(150)), tick: None}],
Skill::Debuff => vec![ConstructEffect {effect: Effect::Slow, duration: 3, meta: Some(EffectMeta::Multiplier(50)), tick: None }],
Skill::Decay => vec![ConstructEffect {effect: Effect::Wither, duration: 3, meta: Some(EffectMeta::Multiplier(50)), tick: None },
ConstructEffect {effect: Effect::Decay, duration: 3, meta: None, tick: None }],
Skill::Haste => vec![ConstructEffect {effect: Effect::Haste, duration: 2, meta: Some(EffectMeta::Multiplier(150)), tick: None }],
Skill::Hex => vec![ConstructEffect {effect: Effect::Hex, duration: 2, meta: None, tick: None}],
Skill::Hostility => vec![ConstructEffect {effect: Effect::Hostility, duration: 2, meta: None, tick: None},
ConstructEffect {effect: Effect::Hatred, duration: 5, meta: None, tick: None}],
Skill::Impurity => vec![ConstructEffect {effect: Effect::Impurity, duration: 3, meta: Some(EffectMeta::Multiplier(150)), tick: None }],
Skill::Invert => vec![ConstructEffect {effect: Effect::Invert, duration: 2, meta: None, tick: None}],
Skill::Parry => vec![ConstructEffect {effect: Effect::Parry, duration: 2, meta: None, tick: None }],
Skill::Reflect => vec![ConstructEffect {effect: Effect::Reflect, duration: 1, meta: None, tick: None }],
Skill::Throw => vec![ConstructEffect {effect: Effect::Stun, duration: 1, meta: None, tick: None},
ConstructEffect {effect: Effect::Vulnerable, duration: 3, meta: Some(EffectMeta::Multiplier(150)), tick: None}],
Skill::Ruin => vec![ConstructEffect {effect: Effect::Stun, duration: 1, meta: None, tick: None}],
Skill::Scatter => vec![CrypEffect {effect: Effect::Scatter, duration: 2, meta: None, tick: None}],
Skill::Silence => vec![CrypEffect {effect: Effect::Silence, duration: 2, meta: None, tick: None}],
Skill::Siphon => vec![CrypEffect {effect: Effect::Siphon, duration: 2, meta: None, tick: None}],
Skill::Sleep => vec![CrypEffect {effect: Effect::Stun, duration: 2, meta: None, tick: None}],
Skill::Snare => vec![CrypEffect {effect: Effect::Snare, duration: 2, meta: None, tick: None}],
Skill::Strangle => vec![CrypEffect {effect: Effect::Strangle, duration: 2, meta: None, tick: None}],
Skill::Stun => vec![CrypEffect {effect: Effect::Stun, duration: 2, meta: None, tick: None}],
Skill::Taunt => vec![CrypEffect {effect: Effect::Taunt, duration: 2, meta: None, tick: None}],
Skill::Triage => vec![CrypEffect {effect: Effect::Triage, duration: 2, meta: None, tick: None}],
Skill::Scatter => vec![ConstructEffect {effect: Effect::Scatter, duration: 2, meta: None, tick: None}],
Skill::Silence => vec![ConstructEffect {effect: Effect::Silence, duration: 2, meta: None, tick: None}],
Skill::Siphon => vec![ConstructEffect {effect: Effect::Siphon, duration: 2, meta: None, tick: None}],
Skill::Sleep => vec![ConstructEffect {effect: Effect::Stun, duration: 2, meta: None, tick: None}],
Skill::Snare => vec![ConstructEffect {effect: Effect::Snare, duration: 2, meta: None, tick: None}],
Skill::Strangle => vec![ConstructEffect {effect: Effect::Strangle, duration: 2, meta: None, tick: None}],
Skill::Stun => vec![ConstructEffect {effect: Effect::Stun, duration: 2, meta: None, tick: None}],
Skill::Taunt => vec![ConstructEffect {effect: Effect::Taunt, duration: 2, meta: None, tick: None}],
Skill::Triage => vec![ConstructEffect {effect: Effect::Triage, duration: 2, meta: None, tick: None}],
//Unused
Skill::Injure => vec![CrypEffect {effect: Effect::Injured, duration: 2, meta: None, tick: None }],
Skill::Injure => vec![ConstructEffect {effect: Effect::Injured, duration: 2, meta: None, tick: None }],
_ => {
panic!("{:?} no skill effect", self);
@@ -876,7 +876,7 @@ impl Skill {
}
}
fn touch(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn touch(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
target.deal_red_damage(skill, 0)
.into_iter()
.for_each(|e| results.push(Resolution::new(source, target).event(e)));
@@ -884,7 +884,7 @@ fn touch(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill:
return results;
}
fn attack(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn attack(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = source.red_damage().pct(skill.multiplier());
target.deal_red_damage(skill, amount)
.into_iter()
@@ -893,7 +893,7 @@ fn attack(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill:
return results;
}
fn strike(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn strike(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = source.red_damage().pct(skill.multiplier());
target.deal_red_damage(skill, amount)
.into_iter()
@@ -902,7 +902,7 @@ fn strike(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill:
return results;
}
fn injure(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn injure(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = source.red_damage().pct(skill.multiplier());
target.deal_red_damage(skill, amount)
.into_iter()
@@ -910,21 +910,21 @@ fn injure(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill:
skill.effect().into_iter()
.for_each(|e| (results.push(Resolution::new(source, target).event(target.add_effect(skill, e)))));
return results;
}
fn stun(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn stun(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter()
.for_each(|e| (results.push(Resolution::new(source, target).event(target.add_effect(skill, e)))));
return results;
}
fn sleep(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn sleep(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter()
.for_each(|e| (results.push(Resolution::new(source, target).event(target.add_effect(skill, e)))));
let amount = source.green_damage().pct(skill.multiplier());
target.deal_green_damage(skill, amount)
.into_iter()
@@ -933,13 +933,13 @@ fn sleep(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill:
return results;
}
fn clutch(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn clutch(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter()
.for_each(|e| (results.push(Resolution::new(source, target).event(target.add_effect(skill, e)))));
return results;
}
fn taunt(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn taunt(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
let red_amount = source.red_damage().pct(skill.multiplier());
results.push(Resolution::new(source, target).event(target.recharge(skill, red_amount, 0)));
@@ -948,27 +948,27 @@ fn taunt(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill:
return results;
}
fn throw(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn throw(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter()
.for_each(|e| (results.push(Resolution::new(source, target).event(target.add_effect(skill, e)))));
return results;
}
fn strangle(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn strangle(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter().for_each(|e| {
let CrypEffect { effect: _, duration, meta: _, tick: _ } = e;
let ConstructEffect { effect: _, duration, meta: _, tick: _ } = e;
let strangle = e.clone().set_tick(Cast::new_tick(source, target, Skill::StrangleTick));
results.push(Resolution::new(source, target).event(target.add_effect(skill, strangle)));
let attacker_strangle = CrypEffect::new(Effect::Strangling, duration);
let attacker_strangle = ConstructEffect::new(Effect::Strangling, duration);
results.push(Resolution::new(source, source).event(source.add_effect(skill, attacker_strangle)));
});
return strangle_tick(source, target, results, Skill::StrangleTick);
}
fn strangle_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn strangle_tick(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = source.red_damage().pct(skill.multiplier());
target.deal_red_damage(skill, amount)
.into_iter()
@@ -979,7 +979,7 @@ fn strangle_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions,
let i = source.effects
.iter()
.position(|e| e.effect == Effect::Strangling)
.expect("no strangling on cryp");
.expect("no strangling on construct");
source.effects.remove(i);
results.push(Resolution::new(source, source).event(Event::Removal { effect: Effect::Strangling }));
}
@@ -987,19 +987,19 @@ fn strangle_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions,
return results;
}
fn block(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn block(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter()
.for_each(|e| (results.push(Resolution::new(source, target).event(target.add_effect(skill, e)))));
return results;
}
fn buff(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn buff(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter()
.for_each(|e| (results.push(Resolution::new(source, target).event(target.add_effect(skill, e)))));
return results;
}
fn parry(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn parry(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
let red_amount = source.red_damage().pct(skill.multiplier());
results.push(Resolution::new(source, target).event(target.recharge(skill, red_amount, 0)));
@@ -1008,7 +1008,7 @@ fn parry(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill:
return results;
}
fn riposte(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn riposte(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = source.red_damage().pct(skill.multiplier());
target.deal_red_damage(skill, amount)
.into_iter()
@@ -1017,7 +1017,7 @@ fn riposte(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill
return results;
}
fn snare(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn snare(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter()
.for_each(|e| (results.push(Resolution::new(source, target).event(target.add_effect(skill, e)))));
@@ -1037,7 +1037,7 @@ fn snare(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill:
return results;
}
fn slay(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn slay(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = source.red_damage().pct(skill.multiplier());
let slay_events = target.deal_red_damage(skill, amount);
@@ -1057,7 +1057,7 @@ fn slay(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: S
return results;
}
fn heal(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn heal(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = source.green_damage().pct(skill.multiplier());
target.deal_green_damage(skill, amount)
.into_iter()
@@ -1065,7 +1065,7 @@ fn heal(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: S
return results;
}
fn triage(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn triage(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter().for_each(|e| {
let triage = e.clone().set_tick(Cast::new_tick(source, target, Skill::TriageTick));
results.push(Resolution::new(source, target).event(target.add_effect(skill, triage)));
@@ -1074,7 +1074,7 @@ fn triage(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill:
return triage_tick(source, target, results, Skill::TriageTick);
}
fn triage_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn triage_tick(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = source.green_damage().pct(skill.multiplier());
target.deal_green_damage(Skill::TriageTick, amount)
.into_iter()
@@ -1082,7 +1082,7 @@ fn triage_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, s
return results;
}
fn chaos(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn chaos(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
let mut rng = thread_rng();
let b_rng: u64 = rng.gen_range(0, 30);
let amount = source.blue_damage().pct(skill.multiplier() + b_rng);
@@ -1097,7 +1097,7 @@ fn chaos(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill:
return results;
}
fn blast(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn blast(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = source.blue_damage().pct(skill.multiplier());
target.deal_blue_damage(skill, amount)
.into_iter()
@@ -1105,28 +1105,28 @@ fn blast(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill:
return results;
}
fn amplify(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn amplify(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter()
.for_each(|e| (results.push(Resolution::new(source, target).event(target.add_effect(skill, e)))));
return results;;
}
fn haste(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn haste(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter()
.for_each(|e| (results.push(Resolution::new(source, target).event(target.add_effect(skill, e)))));
return results;;
}
fn debuff(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn debuff(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter()
.for_each(|e| (results.push(Resolution::new(source, target).event(target.add_effect(skill, e)))));
return results;;
}
fn decay(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn decay(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter().for_each(|e| {
let CrypEffect { effect, duration: _, meta: _, tick: _ } = e;
let ConstructEffect { effect, duration: _, meta: _, tick: _ } = e;
let apply_effect = match effect {
Effect::Wither => e.clone(),
Effect::Decay => e.clone().set_tick(Cast::new_tick(source, target, Skill::DecayTick)),
@@ -1138,7 +1138,7 @@ fn decay(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill:
return decay_tick(source, target, results, Skill::DecayTick);
}
fn decay_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn decay_tick(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = source.blue_damage().pct(skill.multiplier());
target.deal_blue_damage(skill, amount)
.into_iter()
@@ -1148,13 +1148,13 @@ fn decay_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, sk
// corrupt is the buff effect
// when attacked it runs corruption and applies a debuff
fn corrupt(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn corrupt(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
let corrupt = skill.effect().first().unwrap().clone();
results.push(Resolution::new(source, target).event(target.add_effect(skill, corrupt)));
return results;;
}
fn corruption(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn corruption(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
let corruption = skill.effect().last().unwrap().clone()
.set_tick(Cast::new_tick(source, target, Skill::CorruptionTick));
@@ -1162,7 +1162,7 @@ fn corruption(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, sk
return corruption_tick(source, target, results, Skill::CorruptionTick);
}
fn corruption_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn corruption_tick(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = source.blue_damage().pct(skill.multiplier());
target.deal_blue_damage(skill, amount)
.into_iter()
@@ -1170,26 +1170,26 @@ fn corruption_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolution
return results;
}
fn ruin(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn ruin(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter()
.for_each(|e| (results.push(Resolution::new(source, target).event(target.add_effect(skill, e)))));
return results;;
}
fn hex(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn hex(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter()
.for_each(|e| (results.push(Resolution::new(source, target).event(target.add_effect(skill, e)))));
return results;;
}
fn hostility(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn hostility(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
let hostility = skill.effect().first().unwrap().clone();
results.push(Resolution::new(source, target).event(target.add_effect(skill, hostility)));
return results;;
}
fn hatred(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, reflect_skill: Skill, amount: u64, skill: Skill) -> Resolutions {
fn hatred(source: &mut Construct, target: &mut Construct, mut results: Resolutions, reflect_skill: Skill, amount: u64, skill: Skill) -> Resolutions {
let hatred = skill.effect().last().unwrap().clone()
.set_meta(EffectMeta::AddedDamage(amount));
@@ -1197,25 +1197,25 @@ fn hatred(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, reflec
return results;;
}
fn curse(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn curse(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter()
.for_each(|e| (results.push(Resolution::new(source, target).event(target.add_effect(skill, e)))));
return results;;
}
fn impurity(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn impurity(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter()
.for_each(|e| (results.push(Resolution::new(source, target).event(target.add_effect(skill, e)))));
return results;;
}
fn invert(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn invert(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter()
.for_each(|e| (results.push(Resolution::new(source, target).event(target.add_effect(skill, e)))));
return results;;
}
fn reflect(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn reflect(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter()
.for_each(|e| (results.push(Resolution::new(source, target).event(target.add_effect(skill, e)))));
@@ -1225,7 +1225,7 @@ fn reflect(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill
return results;;
}
fn recharge(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn recharge(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
let red_amount = source.red_damage().pct(skill.multiplier());
let blue_amount = source.blue_damage().pct(skill.multiplier());
@@ -1233,7 +1233,7 @@ fn recharge(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skil
return results;
}
fn siphon(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn siphon(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter().for_each(|e| {
let siphon = e.clone().set_tick(Cast::new_tick(source, target, Skill::SiphonTick));
results.push(Resolution::new(source, target).event(target.add_effect(skill, siphon)));
@@ -1242,7 +1242,7 @@ fn siphon(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill:
return siphon_tick(source, target, results, Skill::SiphonTick);
}
fn siphon_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn siphon_tick(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
let amount = source.blue_damage().pct(skill.multiplier());
let siphon_events = target.deal_blue_damage(Skill::SiphonTick, amount);
@@ -1262,7 +1262,7 @@ fn siphon_tick(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, s
return results;
}
fn scatter(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn scatter(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
let blue_amount = source.blue_damage().pct(skill.multiplier());
results.push(Resolution::new(source, target).event(target.recharge(skill, 0, blue_amount)));
@@ -1274,13 +1274,13 @@ fn scatter(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill
return results;
}
fn scatter_hit(source: &Cryp, target: &Cryp, mut results: Resolutions, game: &mut Game, event: Event) -> Resolutions {
fn scatter_hit(source: &Construct, target: &Construct, mut results: Resolutions, game: &mut Game, event: Event) -> Resolutions {
match event {
Event::Damage { amount, skill, mitigation: _, colour } => {
let scatter = target.effects.iter().find(|e| e.effect == Effect::Scatter).unwrap();
if let Some(EffectMeta::ScatterTarget(scatter_target_id)) = scatter.meta {
let mut scatter_target = game.cryp_by_id(scatter_target_id).unwrap();
let mut scatter_target = game.construct_by_id(scatter_target_id).unwrap();
let res = match colour {
Colour::Red => scatter_target.deal_red_damage(skill, amount),
@@ -1300,7 +1300,7 @@ fn scatter_hit(source: &Cryp, target: &Cryp, mut results: Resolutions, game: &mu
}
}
fn silence(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn silence(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter()
.for_each(|e| (results.push(Resolution::new(source, target).event(target.add_effect(skill, e)))));
@@ -1319,7 +1319,7 @@ fn silence(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill
return results;
}
fn purge(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, _skill: Skill) -> Resolutions {
fn purge(source: &mut Construct, target: &mut Construct, mut results: Resolutions, _skill: Skill) -> Resolutions {
while let Some(i) = target.effects
.iter()
.position(|ce| ce.effect.category() == EffectCategory::Buff) {
@@ -1330,7 +1330,7 @@ fn purge(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, _skill:
return results;
}
fn purify(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn purify(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
results.push(Resolution::new(source, target).event(Event::Skill { skill }));
let amount = source.green_damage().pct(skill.multiplier());
while let Some(i) = target.effects
@@ -1346,7 +1346,7 @@ fn purify(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill:
return results;
}
fn banish(source: &mut Cryp, target: &mut Cryp, mut results: Resolutions, skill: Skill) -> Resolutions {
fn banish(source: &mut Construct, target: &mut Construct, mut results: Resolutions, skill: Skill) -> Resolutions {
skill.effect().into_iter()
.for_each(|e| (results.push(Resolution::new(source, target).event(target.add_effect(skill, e)))));
return results;
@@ -1358,11 +1358,11 @@ mod tests {
#[test]
fn heal_test() {
let mut x = Cryp::new()
let mut x = Construct::new()
.named(&"muji".to_string())
.learn(Skill::Heal);
let mut y = Cryp::new()
let mut y = Construct::new()
.named(&"camel".to_string())
.learn(Skill::Heal);
@@ -1373,10 +1373,10 @@ mod tests {
#[test]
fn decay_test() {
let mut x = Cryp::new()
let mut x = Construct::new()
.named(&"muji".to_string());
let mut y = Cryp::new()
let mut y = Construct::new()
.named(&"camel".to_string());
decay(&mut x, &mut y, vec![], Skill::Decay);
@@ -1390,10 +1390,10 @@ mod tests {
#[test]
fn block_test() {
let mut x = Cryp::new()
let mut x = Construct::new()
.named(&"muji".to_string());
let mut y = Cryp::new()
let mut y = Construct::new()
.named(&"camel".to_string());
// ensure it doesn't have 0 pd
@@ -1414,10 +1414,10 @@ mod tests {
#[test]
fn clutch_test() {
let mut x = Cryp::new()
let mut x = Construct::new()
.named(&"muji".to_string());
let mut y = Cryp::new()
let mut y = Construct::new()
.named(&"camel".to_string());
x.red_damage.force(10000000000000); // multiplication of int max will cause overflow
@@ -1444,10 +1444,10 @@ mod tests {
#[test]
fn injure_test() {
let mut x = Cryp::new()
let mut x = Construct::new()
.named(&"muji".to_string());
let mut y = Cryp::new()
let mut y = Construct::new()
.named(&"camel".to_string());
resolve(Skill::Injure, &mut x, &mut y, vec![]);
@@ -1457,10 +1457,10 @@ mod tests {
#[test]
fn invert_test() {
let mut x = Cryp::new()
let mut x = Construct::new()
.named(&"muji".to_string());
let mut y = Cryp::new()
let mut y = Construct::new()
.named(&"camel".to_string());
// give red shield but reduce to 0
@@ -1496,10 +1496,10 @@ mod tests {
#[test]
fn reflect_test() {
let mut x = Cryp::new()
let mut x = Construct::new()
.named(&"muji".to_string());
let mut y = Cryp::new()
let mut y = Construct::new()
.named(&"camel".to_string());
reflect(&mut y.clone(), &mut y, vec![], Skill::Reflect);
@@ -1525,10 +1525,10 @@ mod tests {
#[test]
fn siphon_test() {
let mut x = Cryp::new()
let mut x = Construct::new()
.named(&"muji".to_string());
let mut y = Cryp::new()
let mut y = Construct::new()
.named(&"camel".to_string());
x.green_life.reduce(512);
@@ -1562,10 +1562,10 @@ mod tests {
#[test]
fn triage_test() {
let mut x = Cryp::new()
let mut x = Construct::new()
.named(&"muji".to_string());
let mut y = Cryp::new()
let mut y = Construct::new()
.named(&"pretaliation".to_string());
// ensure it doesn't have 0 sd
@@ -1586,10 +1586,10 @@ mod tests {
#[test]
fn recharge_test() {
let mut x = Cryp::new()
let mut x = Construct::new()
.named(&"muji".to_string());
let mut y = Cryp::new()
let mut y = Construct::new()
.named(&"pretaliation".to_string());
y.red_life.force(50);
@@ -1613,7 +1613,7 @@ mod tests {
#[test]
fn silence_test() {
let mut x = Cryp::new()
let mut x = Construct::new()
.named(&"muji".to_string());
silence(&mut x.clone(), &mut x, vec![], Skill::Silence);
@@ -1623,7 +1623,7 @@ mod tests {
#[test]
fn amplify_test() {
let mut x = Cryp::new()
let mut x = Construct::new()
.named(&"muji".to_string());
x.blue_damage.force(50);
@@ -1635,7 +1635,7 @@ mod tests {
#[test]
fn purify_test() {
let mut x = Cryp::new()
let mut x = Construct::new()
.named(&"muji".to_string());
decay(&mut x.clone(), &mut x, vec![], Skill::Decay);
+9 -9
View File
@@ -1,4 +1,4 @@
use cryp::{Stat, Colours};
use construct::{Stat, Colours};
use util::{IntPct};
#[derive(Debug,Copy,Clone,Serialize,Deserialize,PartialEq,PartialOrd,Ord,Eq)]
@@ -59,8 +59,8 @@ impl Spec {
}
}
pub fn apply(&self, modified: u64, base: u64, cryp_colours: &Colours, player_colours: &Colours) -> u64 {
let cryp_colour_total: u64 = (cryp_colours.red + cryp_colours.green + cryp_colours.blue) as u64;
pub fn apply(&self, modified: u64, base: u64, construct_colours: &Colours, player_colours: &Colours) -> u64 {
let construct_colour_total: u64 = (construct_colours.red + construct_colours.green + construct_colours.blue) as u64;
match *self {
// Upgrades to Damage Spec
Spec::Damage => modified + base.pct(5),
@@ -157,42 +157,42 @@ impl Spec {
if player_colours.green >= 5 { mult += 15 };
if player_colours.green >= 10 { mult += 30 };
if player_colours.green >= 20 { mult += 45 };
mult * cryp_colour_total
mult * construct_colour_total
},
Spec::RedLifeI => modified + {
let mut mult: u64 = 25;
if player_colours.red >= 5 { mult += 15 };
if player_colours.red >= 10 { mult += 30 };
if player_colours.red >= 20 { mult += 45 };
mult * cryp_colour_total
mult * construct_colour_total
},
Spec::BlueLifeI => modified + {
let mut mult: u64 = 25;
if player_colours.blue >= 5 { mult += 15 };
if player_colours.blue >= 10 { mult += 30 };
if player_colours.blue >= 20 { mult += 45 };
mult * cryp_colour_total
mult * construct_colour_total
},
Spec::GRLI => modified + {
let mut mult: u64 = 15;
if player_colours.green >= 2 && player_colours.red >= 2 { mult += 10 };
if player_colours.green >= 5 && player_colours.red >= 5 { mult += 20 };
if player_colours.green >= 10 && player_colours.red >= 10 { mult += 40 };
mult * cryp_colour_total
mult * construct_colour_total
},
Spec::GBLI => modified + {
let mut mult: u64 = 15;
if player_colours.green >= 2 && player_colours.red >= 2 { mult += 10 };
if player_colours.green >= 5 && player_colours.red >= 5 { mult += 20 };
if player_colours.green >= 10 && player_colours.red >= 10 { mult += 40 };
mult * cryp_colour_total
mult * construct_colour_total
},
Spec::RBLI => modified + {
let mut mult: u64 = 15;
if player_colours.blue >= 2 && player_colours.red >= 2 { mult += 10 };
if player_colours.blue >= 5 && player_colours.red >= 5 { mult += 20 };
if player_colours.blue >= 10 && player_colours.red >= 10 { mult += 40 };
mult * cryp_colour_total
mult * construct_colour_total
},
}
}
+3 -3
View File
@@ -13,7 +13,7 @@ use failure::err_msg;
use account::Account;
use rpc::{VboxAcceptParams, VboxDiscardParams, VboxCombineParams, VboxApplyParams, VboxReclaimParams, VboxUnequipParams};
use instance::{Instance, instance_get, instance_update};
use cryp::{Colours};
use construct::{Colours};
use item::*;
@@ -181,13 +181,13 @@ pub fn vbox_reclaim(params: VboxReclaimParams, tx: &mut Transaction, account: &A
pub fn vbox_apply(params: VboxApplyParams, tx: &mut Transaction, account: &Account) -> Result<Instance, Error> {
let instance = instance_get(tx, params.instance_id)?
.vbox_apply(account.id, params.index, params.cryp_id)?;
.vbox_apply(account.id, params.index, params.construct_id)?;
return instance_update(tx, instance);
}
pub fn vbox_unequip(params: VboxUnequipParams, tx: &mut Transaction, account: &Account) -> Result<Instance, Error> {
let instance = instance_get(tx, params.instance_id)?
.vbox_unequip(account.id, params.target, params.cryp_id)?;
.vbox_unequip(account.id, params.target, params.construct_id)?;
return instance_update(tx, instance);
}
+2 -2
View File
@@ -101,7 +101,7 @@ pub fn zone_get(tx: &mut Transaction, id: Uuid) -> Result<Zone, Error> {
None => return Err(err_msg("zone not found")),
};
// tells from_slice to cast into a cryp
// tells from_slice to cast into a construct
let bytes: Vec<u8> = returned.get("data");
let zone = match from_slice::<Zone>(&bytes) {
Ok(z) => z,
@@ -180,7 +180,7 @@ pub fn zone_join(params: ZoneJoinParams, tx: &mut Transaction, account: &Account
"BOSS" => GameMode::Zone3v3HealerBoss,
_ => return Err(err_msg("unknown zone tag")),
};
game = game_pve_new(params.cryp_ids, mode, tx, account)?;
game = game_pve_new(params.construct_ids, mode, tx, account)?;
game.set_zone(zone.id, params.node_id);
encounter.game_id = Some(game.id);