Merge remote-tracking branch 'origin' into skilltiers

This commit is contained in:
Mashy
2019-05-27 15:16:22 +10:00
131 changed files with 1602 additions and 11135 deletions
+18 -13
View File
@@ -9,13 +9,13 @@ 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;
use failure::err_msg;
static PASSWORD_MIN_LEN: usize = 12;
static PASSWORD_MIN_LEN: usize = 11;
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct Account {
@@ -65,6 +65,10 @@ pub fn account_create(params: AccountCreateParams, tx: &mut Transaction) -> Resu
return Err(err_msg("password must be at least 12 characters"));
}
if params.password != "grepgrepgrep" {
return Err(err_msg("https://discord.gg/YJJgurM"));
}
if params.name.len() == 0 {
return Err(err_msg("account name not supplied"));
}
@@ -151,34 +155,35 @@ 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() {
warn!("{:?}", constructs);
return Err(err_msg("could not deserialise 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> {
+153 -153
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(),
@@ -70,24 +70,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
}
@@ -108,11 +108,11 @@ pub enum Stat {
Int,
GreenLife,
Speed,
RedDamage,
RedPower,
BluePower,
GreenPower,
RedDamageTaken,
BlueDamage,
BlueDamageTaken,
GreenDamage,
GreenDamageTaken,
RedLife,
BlueLife,
@@ -120,20 +120,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))
@@ -142,19 +142,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
@@ -163,7 +163,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;
@@ -173,45 +173,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_power: ConstructStat,
pub red_life: ConstructStat,
pub blue_life: ConstructStat,
pub blue_power: ConstructStat,
pub green_power: 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_power: ConstructStat { base: 256, value: 256, max: 256, stat: Stat::RedPower },
red_life: ConstructStat { base: 0, value: 0, max: 0, stat: Stat::RedLife },
blue_power: ConstructStat { base: 256, value: 256, max: 256, stat: Stat::BluePower },
blue_life: ConstructStat { base: 0, value: 0, max: 0, stat: Stat::BlueLife },
green_power: ConstructStat { base: 256, value: 256, max: 256, stat: Stat::GreenPower },
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![],
@@ -220,28 +220,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);
@@ -251,7 +251,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"));
}
@@ -260,7 +260,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")),
@@ -269,21 +269,21 @@ 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);
self.red_power.recalculate(&self.specs, &self.colours, player_colours);
self.red_life.recalculate(&self.specs, &self.colours, player_colours);
self.blue_damage.recalculate(&self.specs, &self.colours, player_colours);
self.blue_power.recalculate(&self.specs, &self.colours, player_colours);
self.blue_life.recalculate(&self.specs, &self.colours, player_colours);
self.evasion.recalculate(&self.specs, &self.colours, player_colours);
self.speed.recalculate(&self.specs, &self.colours, player_colours);
self.green_damage.recalculate(&self.specs, &self.colours, player_colours);
self.green_power.recalculate(&self.specs, &self.colours, player_colours);
self.green_life.recalculate(&self.specs, &self.colours, player_colours);
self
@@ -293,7 +293,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
}
@@ -341,7 +341,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())
@@ -378,19 +378,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() {
@@ -413,7 +413,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);
@@ -423,43 +423,43 @@ impl Cryp {
// info!("reduced effect {:?}", effect);
return Some(effect);
}).collect::<Vec<CrypEffect>>();
}).collect::<Vec<ConstructEffect>>();
self
}
// Stats
pub fn red_damage(&self) -> u64 {
let red_damage_mods = self.effects.iter()
.filter(|e| e.effect.modifications().contains(&Stat::RedDamage))
pub fn red_power(&self) -> u64 {
let red_power_mods = self.effects.iter()
.filter(|e| e.effect.modifications().contains(&Stat::RedPower))
.map(|e| (e.effect, e.meta))
.collect::<Vec<(Effect, Option<EffectMeta>)>>();
let modified_red_damage = red_damage_mods.iter()
.fold(self.red_damage.value, |acc, fx| fx.0.apply(acc, fx.1));
return modified_red_damage;
let modified_red_power = red_power_mods.iter()
.fold(self.red_power.value, |acc, fx| fx.0.apply(acc, fx.1));
return modified_red_power;
}
pub fn blue_damage(&self) -> u64 {
let blue_damage_mods = self.effects.iter()
.filter(|e| e.effect.modifications().contains(&Stat::BlueDamage))
pub fn blue_power(&self) -> u64 {
let blue_power_mods = self.effects.iter()
.filter(|e| e.effect.modifications().contains(&Stat::BluePower))
.map(|e| (e.effect, e.meta))
.collect::<Vec<(Effect, Option<EffectMeta>)>>();
let modified_blue_damage = blue_damage_mods.iter()
.fold(self.blue_damage.value, |acc, fx| fx.0.apply(acc, fx.1));
return modified_blue_damage;
let modified_blue_power = blue_power_mods.iter()
.fold(self.blue_power.value, |acc, fx| fx.0.apply(acc, fx.1));
return modified_blue_power;
}
pub fn green_damage(&self) -> u64 {
let green_damage_mods = self.effects.iter()
.filter(|e| e.effect.modifications().contains(&Stat::GreenDamage))
pub fn green_power(&self) -> u64 {
let green_power_mods = self.effects.iter()
.filter(|e| e.effect.modifications().contains(&Stat::GreenPower))
.map(|e| (e.effect, e.meta))
.collect::<Vec<(Effect, Option<EffectMeta>)>>();
let modified_green_damage = green_damage_mods.iter()
.fold(self.green_damage.value, |acc, fx| fx.0.apply(acc, fx.1));
return modified_green_damage;
let modified_green_power = green_power_mods.iter()
.fold(self.green_power.value, |acc, fx| fx.0.apply(acc, fx.1));
return modified_green_power;
}
pub fn skill_speed(&self, s: Skill) -> u64 {
@@ -539,17 +539,17 @@ impl Cryp {
.map(|e| (e.effect, e.meta))
.collect::<Vec<(Effect, Option<EffectMeta>)>>();
let modified_damage = mods.iter()
let modified_power = mods.iter()
.fold(amount, |acc, fx| fx.0.apply(acc, fx.1));
match self.affected(Effect::Invert) {
false => {
let current_green_life = self.green_life();
self.green_life.increase(modified_damage);
self.green_life.increase(modified_power);
let new_green_life = self.green_life.value;
let healing = new_green_life - current_green_life;
let overhealing = modified_damage - healing;
let overhealing = modified_power - healing;
events.push(Event::Healing {
skill,
@@ -562,7 +562,7 @@ impl Cryp {
// there is no green shield (yet)
let current_green_life = self.green_life();
self.reduce_green_life(modified_damage);
self.reduce_green_life(modified_power);
let delta = current_green_life - self.green_life();
events.push(Event::Damage {
@@ -598,7 +598,7 @@ impl Cryp {
.map(|e| (e.effect, e.meta))
.collect::<Vec<(Effect, Option<EffectMeta>)>>();
let modified_damage = mods.iter()
let modified_power = mods.iter()
.fold(amount, |acc, fx| fx.0.apply(acc, fx.1));
match self.affected(Effect::Invert) {
@@ -607,8 +607,8 @@ impl Cryp {
// eg 50 red_life 25 damage -> 0 remainder 25 mitigation
// 50 red_life 100 damage -> 50 remainder 50 mitigation
// 50 red_life 5 damage -> 0 remainder 5 mitigation
let remainder = modified_damage.saturating_sub(self.red_life.value);
let mitigation = modified_damage.saturating_sub(remainder);
let remainder = modified_power.saturating_sub(self.red_life.value);
let mitigation = modified_power.saturating_sub(remainder);
// reduce red_life by mitigation amount
self.red_life.reduce(mitigation);
@@ -629,10 +629,10 @@ impl Cryp {
events.push(Event::Inversion { skill });
let current_green_life = self.green_life();
self.green_life.increase(modified_damage);
self.green_life.increase(modified_power);
let new_green_life = self.green_life.value;
let healing = new_green_life - current_green_life;
let overhealing = modified_damage - healing;
let overhealing = modified_power - healing;
let current_life = self.red_life.value;
self.red_life.increase(overhealing);
@@ -677,13 +677,13 @@ impl Cryp {
.map(|e| (e.effect, e.meta))
.collect::<Vec<(Effect, Option<EffectMeta>)>>();
let modified_damage = mods.iter()
let modified_power = mods.iter()
.fold(amount, |acc, fx| fx.0.apply(acc, fx.1));
match self.affected(Effect::Invert) {
false => {
let remainder = modified_damage.saturating_sub(self.blue_life.value);
let mitigation = modified_damage.saturating_sub(remainder);
let remainder = modified_power.saturating_sub(self.blue_life.value);
let mitigation = modified_power.saturating_sub(remainder);
// reduce blue_life by mitigation amount
self.blue_life.reduce(mitigation);
@@ -704,10 +704,10 @@ impl Cryp {
events.push(Event::Inversion { skill });
let current_green_life = self.green_life();
self.green_life.increase(modified_damage);
self.green_life.increase(modified_power);
let new_green_life = self.green_life.value;
let healing = new_green_life - current_green_life;
let overhealing = modified_damage - healing;
let overhealing = modified_power - healing;
let current_life = self.blue_life.value;
self.blue_life.increase(overhealing);
@@ -735,7 +735,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,
@@ -777,10 +777,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;
";
@@ -788,110 +788,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::StrikeI);
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::StrikeI);
construct.spec_add(Spec::GreenLifeI).unwrap();
construct.spec_add(Spec::RedPowerI).unwrap();
construct.spec_add(Spec::RedPowerI).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::RedPowerI).unwrap();
construct.spec_add(Spec::GreenPowerI).unwrap();
construct.spec_add(Spec::BluePowerI).unwrap();
let player_colours = Colours {
red: 5,
@@ -899,11 +899,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_power.value == construct.red_power.base + construct.red_power.base.pct(20));
assert!(construct.green_power.value == construct.green_power.base + construct.green_power.base.pct(40));
assert!(construct.blue_power.value == construct.blue_power.base + construct.blue_power.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_power.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::RiposteI.multiplier())));
assert_eq!(game.player_by_id(y_player.id).unwrap().constructs[0].green_life(), (1024 - x_construct.red_power().pct(Skill::RiposteI.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::ScatterI);
game.construct_by_id(x_construct.id).unwrap().learn_mut(Skill::ScatterI);
while game.cryp_by_id(x_cryp.id).unwrap().skill_on_cd(Skill::ScatterI).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::ScatterI).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::ScatterI).unwrap();
game.add_skill(x_player.id, x_construct.id, Some(y_construct.id), Skill::ScatterI).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::RuinI);
game.construct_by_id(x_construct.id).unwrap().learn_mut(Skill::RuinI);
while game.cryp_by_id(x_cryp.id).unwrap().skill_on_cd(Skill::RuinI).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::RuinI).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::RuinI).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::RuinI).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::TauntI);
game.construct_by_id(x_construct.id).unwrap().learn_mut(Skill::TauntI);
while game.cryp_by_id(x_cryp.id).unwrap().skill_on_cd(Skill::TauntI).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::TauntI).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::TauntI).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::TauntI).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::DecayI);
while game.cryp_by_id(x_cryp.id).unwrap().skill_on_cd(Skill::DecayI).is_some() {
game.cryp_by_id(x_cryp.id).unwrap().reduce_cooldowns();
game.construct_by_id(x_construct.id).unwrap().learn_mut(Skill::DecayI);
while game.construct_by_id(x_construct.id).unwrap().skill_on_cd(Skill::DecayI).is_some() {
game.construct_by_id(x_construct.id).unwrap().reduce_cooldowns();
}
game.cryp_by_id(x_cryp.id).unwrap().learn_mut(Skill::SiphonI);
while game.cryp_by_id(x_cryp.id).unwrap().skill_on_cd(Skill::SiphonI).is_some() {
game.cryp_by_id(x_cryp.id).unwrap().reduce_cooldowns();
game.construct_by_id(x_construct.id).unwrap().learn_mut(Skill::SiphonI);
while game.construct_by_id(x_construct.id).unwrap().skill_on_cd(Skill::SiphonI).is_some() {
game.construct_by_id(x_construct.id).unwrap().reduce_cooldowns();
}
game.cryp_by_id(y_cryp.id).unwrap().learn_mut(Skill::PurifyI);
while game.cryp_by_id(y_cryp.id).unwrap().skill_on_cd(Skill::PurifyI).is_some() {
game.cryp_by_id(y_cryp.id).unwrap().reduce_cooldowns();
game.construct_by_id(y_construct.id).unwrap().learn_mut(Skill::PurifyI);
while game.construct_by_id(y_construct.id).unwrap().skill_on_cd(Skill::PurifyI).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::DecayI).unwrap();
game.add_skill(x_player.id, x_construct.id, Some(y_construct.id), Skill::DecayI).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::PurifyI).unwrap();
game.add_skill(y_player.id, y_construct.id, Some(y_construct.id), Skill::PurifyI).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::SiphonI).unwrap();
game.add_skill(y_player.id, x_construct.id, Some(y_construct.id), Skill::SiphonI).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::PurifyI).unwrap();
game.add_skill(y_player.id, y_construct.id, Some(y_construct.id), Skill::PurifyI).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");
+101 -94
View File
@@ -1,6 +1,6 @@
use skill::{Skill, Colour};
use spec::{Spec};
use cryp::{Colours};
use construct::{Colours};
#[derive(Debug,Copy,Clone,Serialize,Deserialize,PartialEq,PartialOrd,Ord,Eq)]
pub enum Item {
@@ -18,7 +18,7 @@ pub enum Item {
// specs
// Base
Damage,
Power,
Life,
Speed,
@@ -30,10 +30,10 @@ pub enum Item {
GBLI,
RBLI,
// Damage Upgrades
RedDamageI,
BlueDamageI,
GreenDamageI,
// Power Upgrades
RedPowerI,
BluePowerI,
GreenPowerI,
GRDI,
GBDI,
RBDI,
@@ -188,7 +188,7 @@ impl Item {
Item::Debuff => 2,
Item::Stun => 2,
Item::Damage => 3,
Item::Power => 3,
Item::Life => 3,
Item::Speed => 3,
@@ -338,10 +338,10 @@ impl Item {
Item::GBSpeedI => Some(Spec::GBSpeedI),
Item::RBSpeedI => Some(Spec::RBSpeedI),
Item::Damage => Some(Spec::Damage),
Item::RedDamageI => Some(Spec::RedDamageI),
Item::BlueDamageI => Some(Spec::BlueDamageI),
Item::GreenDamageI => Some(Spec::GreenDamageI),
Item::Power => Some(Spec::Power),
Item::RedPowerI => Some(Spec::RedPowerI),
Item::BluePowerI => Some(Spec::BluePowerI),
Item::GreenPowerI => Some(Spec::GreenPowerI),
Item::GRDI => Some(Spec::GRDI),
Item::GBDI => Some(Spec::GBDI),
Item::RBDI => Some(Spec::RBDI),
@@ -375,52 +375,52 @@ impl Item {
Item::Red => format!("Combine with skills and specs to create upgraded items. \n Speed and chaos."),
// base skills
Item::Attack => format!("Deal red damage based on {:?}% red power",
Item::Attack => format!("Deal RedDamage based on {:?}% RedPower",
self.into_skill().unwrap().multiplier()),
Item::Block => format!("Reduce incoming red damage by {:?}%",
Item::Block => format!("Reduce incoming RedDamage by {:?}%",
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 RedPower 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::Power => format!("Base ITEM for increased Power. Power determines the damage caused by 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.
RedDamage dealt to your construct reduces RedLife before GreenLife."),
Item::BlueLifeI => format!("Increases CONSTRUCT BlueLife.
BlueDamage 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."),
// Power Upgrades
Item::RedPowerI => format!("Increases CONSTRUCT RedPower."),
Item::BluePowerI => format!("Increases CONSTRUCT BluePower."),
Item::GreenPowerI => format!("Increases CONSTRUCT GreenPower."),
Item::GRDI => format!("Increases CONSTRUCT GreenPower + RedPower."),
Item::GBDI => format!("Increases CONSTRUCT GreenPower + BluePower."),
Item::RBDI => format!("Increases CONSTRUCT RedPower + BluePower."),
// 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::AmplifyI |
@@ -432,12 +432,12 @@ impl Item {
Item::BanishI |
Item::BanishII |
Item::BanishIII => 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::BlastI |
Item::BlastII |
Item::BlastIII => format!("Deals blue damage {:?}% blue power.", self.into_skill().unwrap().multiplier()),
Item::BlastIII => format!("Deals Blue Damage {:?}% Blue Power.", self.into_skill().unwrap().multiplier()),
Item::ChaosI |
Item::ChaosII |
@@ -447,19 +447,18 @@ impl Item {
Item::ClutchI |
Item::ClutchII |
Item::ClutchIII => format!("Cryp cannot be KO'd while active.
Additionally provides immunity to disables."),
Item::ClutchIII => format!("Construct cannot be KO'd while active. Additionally provides immunity to disables."),
Item::Corrupt => format!(
"Self targetting defensive for {:?}T. Applies corrupt to attackers dealing blue damage {:?}% blue power per turn for {:?}T.",
"Self targetting defensive for {:?}T. Applies corrupt to attackers dealing BlueDamage {:?}% \
BluePower per turn for {:?}T.",
self.into_skill().unwrap().effect().first().unwrap().get_duration(),
Skill::Corrupt.multiplier(),
self.into_skill().unwrap().effect().last().unwrap().get_duration()),
Item::CurseI |
Item::CurseII |
Item::CurseIII => format!(
Item::CurseII |
Item::CurseIII => format!(
"Increases red and blue damage taken by {:?}%. Lasts {:?}T",
self.into_skill().unwrap().effect().first().unwrap().get_multiplier() - 100,
self.into_skill().unwrap().effect().first().unwrap().get_duration()),
@@ -475,14 +474,14 @@ impl Item {
Item::Hostility => format!(
"Gain Hostility for {:?}T. {} Hatred lasts {:?}T",
self.into_skill().unwrap().effect().first().unwrap().get_duration(),
"When attacked by Hostility you gain Hatred which increased red and blue power based on damage taken.",
"When attacked by Hostility you gain Hatred which increased red and blue power based on Damage taken.",
self.into_skill().unwrap().effect().last().unwrap().get_duration()),
Item::Haste => format!(
"Haste increases Speed by {:?}%, Red based Attack skills will strike again dealing {:?}{}. Lasts {:?}T",
self.into_skill().unwrap().effect().first().unwrap().get_multiplier() - 100,
Skill::HasteStrike.multiplier(),
"% Speed as Red Damage",
"% Speed as RedDamage",
self.into_skill().unwrap().effect().first().unwrap().get_duration()),
Item::HealI |
@@ -495,12 +494,11 @@ impl Item {
Hexed targets cannot cast any skills.",
self.into_skill().unwrap().effect().first().unwrap().get_duration()),
Item::Impurity => format!(
"Impurity increases Green Power by {:?}%, Blue based Attack skills will blast again dealing {:?}{}. Lasts {:?}T",
self.into_skill().unwrap().effect().first().unwrap().get_multiplier() - 100,
Skill::ImpureBlast.multiplier(),
"% Green Power as Blue Damage",
"% GreenPower as BluePower",
self.into_skill().unwrap().effect().first().unwrap().get_duration()),
Item::InvertI |
@@ -515,12 +513,12 @@ 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::RiposteI.multiplier()),
Item::PurgeI |
Item::PurgeII |
Item::PurgeIII => format!("Remove buffs from target cryp"),
Item::PurgeIII => format!("Remove buffs from target construct"),
Item::PurifyI |
Item::PurifyII |
@@ -533,6 +531,7 @@ impl Item {
Item::ReflectIII => format!(
"Reflect incoming skills to source. Lasts {:?}T",
self.into_skill().unwrap().effect().first().unwrap().get_duration()),
Item::RechargeI |
Item::RechargeII |
Item::RechargeIII => format!(
@@ -542,13 +541,13 @@ impl Item {
Item::RuinI |
Item::RuinII |
Item::RuinIII => 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::ScatterI |
Item::ScatterII |
Item::ScatterIII => 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 Life {:?}% of BluePower",
self.into_skill().unwrap().multiplier()),
Item::SilenceI |
@@ -557,61 +556,68 @@ impl Item {
"Block the target from using blue skills for {:?}T and deals blue damage {:?}% blue power. {}",
self.into_skill().unwrap().effect().first().unwrap().get_duration(),
self.into_skill().unwrap().multiplier(),
"Deals 45% more damage per blue skill on target"),
"Deals 45% more Damage per blue skill on target"),
Item::RechargeI |
Item::RechargeII |
Item::RechargeIII => format!(
"Recharge Red and Blue Life based on {:?} RedPower and BluePower",
self.into_skill().unwrap().multiplier()),
Item::SlayI |
Item::SlayII |
Item::SlayIII => format!(
"Deals red damage {:?}% red power and provides self healing based on damage dealt.",
"Deals RedDamage {:?}% RedPower and provides self healing based on damage dealt.",
self.into_skill().unwrap().multiplier()),
Item::SleepI |
Item::SleepII |
Item::SleepIII => format!(
"Stun for {:?}T and heal for {:?}% green power.",
"Stun for {:?}T and heal for {:?}% GreenPower.",
self.into_skill().unwrap().effect().first().unwrap().get_duration(),
self.into_skill().unwrap().multiplier()),
Item::SnareI |
Item::SnareII |
Item::SnareIII => format!(
"Block the target from using red skills for {:?}T and deals red damage {:?}% red power. {}",
"Block the target from using red skills for {:?}T and deals RedDamage {:?}% RedPower. {}",
self.into_skill().unwrap().effect().first().unwrap().get_duration(),
self.into_skill().unwrap().multiplier(),
"Deals 35% more damage per red skill on target"),
"Deals 35% more Damage per red skill on target"),
Item::StrangleI |
Item::StrangleII |
Item::StrangleIII => format!(
"Strangle the target disabling skills from both the caster and the target.
While strangling deal red damage each turn {:?}% red power. Lasts {:?}T.",
While strangling deal RedDamage each turn {:?}% RedPower. Lasts {:?}T.",
self.into_skill().unwrap().multiplier(),
self.into_skill().unwrap().effect().first().unwrap().get_duration()),
Item::StrikeI |
Item::StrikeII |
Item::StrikeIII => format!(
"Hits at maximum speed dealing red damage {:?}% red power",
"Hits at maximum speed dealing RedDamage {:?}% RedPower",
self.into_skill().unwrap().multiplier()),
Item::SiphonI |
Item::SiphonII |
Item::SiphonIII => format!(
"Deals blue damage {:?}% blue power each turn and heals caster based on damage dealt. Lasts {:?}T",
"Deals BlueDamage {:?}% BluePower each turn and heals caster based on Damage dealt. Lasts {:?}T",
self.into_skill().unwrap().multiplier(),
self.into_skill().unwrap().effect().first().unwrap().get_duration()),
Item::TauntI |
Item::TauntII |
Item::TauntIII => format!("{} {:?}T. Recharges RedLife for {:?} red power.",
"Taunt redirects skills against the team to target, lasts",
Item::TauntIII => format!("Taunt redirects skills against the team to target, lasts {:?}T.\
Recharges RedLife for {:?} RedPower.",
self.into_skill().unwrap().effect().first().unwrap().get_duration(),
self.into_skill().unwrap().multiplier()),
Item::ThrowI |
Item::ThrowII |
Item::ThrowIII => format!(
"Stun the target for {:?}T and applies Vulnerable increasing red damage taken by {:?}% for {:?}T",
"Stun the target for {:?}T and applies Vulnerable increasing RedDamage taken by {:?}% for {:?}T",
self.into_skill().unwrap().effect().first().unwrap().get_duration(),
self.into_skill().unwrap().effect().first().unwrap().get_multiplier() - 100,
self.into_skill().unwrap().effect().last().unwrap().get_duration()),
@@ -619,12 +625,10 @@ impl Item {
Item::TriageI |
Item::TriageII |
Item::TriageIII => format!(
"Heals target for {:?}% green power each turn. Lasts {:?}T",
"Heals target for {:?}% GreenPower each turn. Lasts {:?}T",
self.into_skill().unwrap().multiplier(),
self.into_skill().unwrap().effect().first().unwrap().get_duration()),
_ => format!("..."),
}
}
@@ -721,12 +725,12 @@ impl Item {
Item::ChaosII => vec![Item::ChaosI, Item::ChaosI, Item::ChaosI],
Item::ChaosIII => vec![Item::ChaosII, Item::ChaosII, Item::ChaosII],
Item::RedDamageI => vec![Item::Damage, Item::Red, Item::Red],
Item::GreenDamageI => vec![Item::Damage, Item::Green, Item::Green],
Item::BlueDamageI => vec![Item::Damage, Item::Blue, Item::Blue],
Item::GRDI => vec![Item::Damage, Item::Red, Item::Green],
Item::GBDI => vec![Item::Damage, Item::Green, Item::Blue],
Item::RBDI => vec![Item::Damage, Item::Red, Item::Blue],
Item::RedPowerI => vec![Item::Power, Item::Red, Item::Red],
Item::GreenPowerI => vec![Item::Power, Item::Green, Item::Green],
Item::BluePowerI => vec![Item::Power, Item::Blue, Item::Blue],
Item::GRDI => vec![Item::Power, Item::Red, Item::Green],
Item::GBDI => vec![Item::Power, Item::Green, Item::Blue],
Item::RBDI => vec![Item::Power, Item::Red, Item::Blue],
Item::RedLifeI => vec![Item::Life, Item::Red, Item::Red],
Item::GreenLifeI => vec![Item::Life, Item::Green, Item::Green],
@@ -864,10 +868,10 @@ impl From<Spec> for Item {
Spec::GBSpeedI => Item::GBSpeedI,
Spec::RBSpeedI => Item::RBSpeedI,
Spec::Damage => Item::Damage,
Spec::RedDamageI => Item::RedDamageI,
Spec::BlueDamageI => Item::BlueDamageI,
Spec::GreenDamageI => Item::GreenDamageI,
Spec::Power => Item::Power,
Spec::RedPowerI => Item::RedPowerI,
Spec::BluePowerI => Item::BluePowerI,
Spec::GreenPowerI => Item::GreenPowerI,
Spec::GRDI => Item::GRDI,
Spec::GBDI => Item::GBDI,
Spec::RBDI => Item::RBDI,
@@ -904,8 +908,10 @@ pub fn get_combos() -> Vec<Combo> {
Combo { components: Item::ScatterI.combo(), item: Item::ScatterI },
Combo { components: Item::ScatterII.combo(), item: Item::ScatterII },
Combo { components: Item::ScatterIII.combo(), item: Item::ScatterIII },
Combo { components: Item::Haste.combo(), item: Item::Haste },
Combo { components: Item::Impurity.combo(), item: Item::Impurity },
Combo { components: Item::AmplifyI.combo(), item: Item::AmplifyI },
Combo { components: Item::AmplifyII.combo(), item: Item::AmplifyII },
Combo { components: Item::AmplifyIII.combo(), item: Item::AmplifyIII },
@@ -938,7 +944,9 @@ pub fn get_combos() -> Vec<Combo> {
Combo { components: Item::PurifyI.combo(), item: Item::PurifyI },
Combo { components: Item::PurifyII.combo(), item: Item::PurifyII },
Combo { components: Item::PurifyIII.combo(), item: Item::PurifyIII },
Combo { components: Item::Corrupt.combo(), item: Item::Corrupt },
Combo { components: Item::ClutchI.combo(), item: Item::ClutchI },
Combo { components: Item::ClutchII.combo(), item: Item::ClutchII },
Combo { components: Item::ClutchIII.combo(), item: Item::ClutchIII },
@@ -961,7 +969,6 @@ pub fn get_combos() -> Vec<Combo> {
Combo { components: Item::RuinII.combo(), item: Item::RuinII },
Combo { components: Item::RuinIII.combo(), item: Item::RuinIII },
Combo { components: Item::ThrowI.combo(), item: Item::ThrowI },
Combo { components: Item::ThrowII.combo(), item: Item::ThrowII },
Combo { components: Item::ThrowIII.combo(), item: Item::ThrowIII },
@@ -992,21 +999,21 @@ pub fn get_combos() -> Vec<Combo> {
Combo { components: Item::ChaosII.combo(), item: Item::ChaosII },
Combo { components: Item::ChaosIII.combo(), item: Item::ChaosIII },
Combo { components: Item::RedDamageI.combo(), item: Item::RedDamageI },
Combo { components: Item::GreenDamageI.combo(), item: Item::GreenDamageI },
Combo { components: Item::BlueDamageI.combo(), item: Item::BlueDamageI },
Combo { components: Item::GRDI.combo(), item: Item::GRDI },
Combo { components: Item::GBDI.combo(), item: Item::GBDI },
Combo { components: Item::RBDI.combo(), item: Item::RBDI },
Combo { components: Item::RedPowerI.combo(), item: Item::RedPowerI },
Combo { components: Item::GreenPowerI.combo(), item: Item::GreenPowerI },
Combo { components: Item::BluePowerI.combo(), item: Item::BluePowerI },
Combo { components: Item::GRDI.combo(), item: Item::GRDI },
Combo { components: Item::GBDI.combo(), item: Item::GBDI },
Combo { components: Item::RBDI.combo(), item: Item::RBDI },
Combo { components: Item::RedLifeI.combo(), item: Item::RedLifeI },
Combo { components: Item::GreenLifeI.combo(), item: Item::GreenLifeI },
Combo { components: Item::BlueLifeI.combo(), item: Item::BlueLifeI },
Combo { components: Item::GRLI.combo(), item: Item::GRLI },
Combo { components: Item::GBLI.combo(), item: Item::GBLI },
Combo { components: Item::RBLI.combo(), item: Item::RBLI },
Combo { components: Item::RedLifeI.combo(), item: Item::RedLifeI },
Combo { components: Item::GreenLifeI.combo(), item: Item::GreenLifeI },
Combo { components: Item::BlueLifeI.combo(), item: Item::BlueLifeI },
Combo { components: Item::GRLI.combo(), item: Item::GRLI },
Combo { components: Item::GBLI.combo(), item: Item::GBLI },
Combo { components: Item::RBLI.combo(), item: Item::RBLI },
Combo { components: Item::RedSpeedI.combo(), item: Item::RedSpeedI },
Combo { components: Item::RedSpeedI.combo(), item: Item::RedSpeedI },
Combo { components: Item::GreenSpeedI.combo(), item: Item::GreenSpeedI },
Combo { components: Item::BlueSpeedI.combo(), item: Item::BlueSpeedI },
Combo { components: Item::GRSpeedI.combo(), item: Item::GRSpeedI },
+2 -2
View File
@@ -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/mnml.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));
}
}
+70 -72
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};
@@ -57,7 +57,6 @@ impl Rpc {
match v.method.as_ref() {
"account_create" => (),
"account_login" => (),
"account_demo" => (),
_ => match account {
Some(_) => (),
None => return Err(err_msg("auth required")),
@@ -70,14 +69,13 @@ impl Rpc {
// no auth methods
"account_create" => Rpc::account_create(data, &mut tx, client),
"account_login" => Rpc::account_login(data, &mut tx, client),
"account_demo" => Rpc::account_demo(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),
@@ -88,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),
@@ -167,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> {
@@ -204,35 +202,35 @@ impl Rpc {
}
}
fn account_demo(_data: Vec<u8>, tx: &mut Transaction, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
let mut rng = thread_rng();
// fn account_demo(_data: Vec<u8>, tx: &mut Transaction, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
// let mut rng = thread_rng();
let acc_name: String = iter::repeat(()).map(|()| rng.sample(Alphanumeric)).take(8).collect();
// let acc_name: String = iter::repeat(()).map(|()| rng.sample(Alphanumeric)).take(8).collect();
let account = account_create(AccountCreateParams { name: acc_name, password: "grepgrepgrep".to_string() }, tx)?;
// 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)?;
// let name: String = iter::repeat(()).map(|()| rng.sample(Alphanumeric)).take(8).collect();
// construct_spawn(ConstructSpawnParams { name }, tx, &account)?;
let name: String = iter::repeat(()).map(|()| rng.sample(Alphanumeric)).take(8).collect();
cryp_spawn(CrypSpawnParams { name }, tx, &account)?;
// let name: String = iter::repeat(()).map(|()| rng.sample(Alphanumeric)).take(8).collect();
// construct_spawn(ConstructSpawnParams { name }, tx, &account)?;
let name: String = iter::repeat(()).map(|()| rng.sample(Alphanumeric)).take(8).collect();
cryp_spawn(CrypSpawnParams { name }, tx, &account)?;
// let name: String = iter::repeat(()).map(|()| rng.sample(Alphanumeric)).take(8).collect();
// construct_spawn(ConstructSpawnParams { name }, tx, &account)?;
let res = RpcResponse {
method: "account_create".to_string(),
params: RpcResult::Account(account),
};
// let res = RpcResponse {
// method: "account_create".to_string(),
// params: RpcResult::Account(account),
// };
return Ok(res);
}
// return Ok(res);
// }
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)?)
})
}
@@ -302,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);
@@ -356,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);
@@ -383,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);
@@ -399,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)>),
@@ -424,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)]
@@ -489,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)]
@@ -501,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,
}
@@ -531,7 +529,7 @@ pub struct AccountLoginParams {
}
#[derive(Debug,Clone,Serialize,Deserialize)]
struct AccountCrypsMsg {
struct AccountConstructsMsg {
method: String,
params: (),
}
@@ -544,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>,
@@ -559,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)]
@@ -585,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)]
@@ -640,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,
}
@@ -653,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,
}
@@ -676,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));
// }
+222 -226
View File
File diff suppressed because it is too large Load Diff
+25 -25
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)]
@@ -20,10 +20,10 @@ pub enum Spec {
GBLI,
RBLI,
Damage,
RedDamageI,
GreenDamageI,
BlueDamageI,
Power,
RedPowerI,
GreenPowerI,
BluePowerI,
GRDI,
GBDI,
RBDI,
@@ -32,13 +32,13 @@ pub enum Spec {
impl Spec {
pub fn affects(&self) -> Vec<Stat> {
match *self {
Spec::Damage => vec![Stat::BlueDamage, Stat::RedDamage, Stat::GreenDamage],
Spec::RedDamageI => vec![Stat::RedDamage],
Spec::GreenDamageI => vec![Stat::GreenDamage],
Spec::BlueDamageI => vec![Stat::BlueDamage],
Spec::GRDI => vec![Stat::GreenDamage, Stat::RedDamage],
Spec::GBDI => vec![Stat::GreenDamage, Stat::BlueDamage],
Spec::RBDI => vec![Stat::RedDamage, Stat::BlueDamage],
Spec::Power => vec![Stat::BluePower, Stat::RedPower, Stat::GreenPower],
Spec::RedPowerI => vec![Stat::RedPower],
Spec::GreenPowerI => vec![Stat::GreenPower],
Spec::BluePowerI => vec![Stat::BluePower],
Spec::GRDI => vec![Stat::GreenPower, Stat::RedPower],
Spec::GBDI => vec![Stat::GreenPower, Stat::BluePower],
Spec::RBDI => vec![Stat::RedPower, Stat::BluePower],
Spec::Speed => vec![Stat::Speed],
Spec::RedSpeedI => vec![Stat::Speed],
@@ -59,26 +59,26 @@ 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),
Spec::RedDamageI => modified + {
// Upgrades to Power Spec
Spec::Power => modified + base.pct(5),
Spec::RedPowerI => modified + {
let mut pct = 10;
if player_colours.red >= 5 { pct += 10 };
if player_colours.red >= 10 { pct += 20 };
if player_colours.red >= 20 { pct += 40 };
base.pct(pct)
},
Spec::GreenDamageI => modified + {
Spec::GreenPowerI => modified + {
let mut pct = 10;
if player_colours.green >= 5 { pct += 10 };
if player_colours.green >= 10 { pct += 20 };
if player_colours.green >= 20 { pct += 40 };
base.pct(pct)
},
Spec::BlueDamageI => modified + {
Spec::BluePowerI => modified + {
let mut pct = 10;
if player_colours.blue >= 5 { pct += 10 };
if player_colours.blue >= 10 { pct += 20 };
@@ -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
},
}
}
+4 -4
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::*;
@@ -70,7 +70,7 @@ impl Vbox {
];
let specs = vec![
(Item::Damage, 1),
(Item::Power, 1),
(Item::Life, 1),
(Item::Speed, 1),
];
@@ -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);