core init

This commit is contained in:
ntr
2019-12-02 16:24:40 +10:00
parent 677cec24a2
commit 4475887410
24 changed files with 8716 additions and 703 deletions
+3 -95
View File
@@ -17,7 +17,7 @@ use account::Account;
use pg::Db;
use construct::{Construct};
use skill::{Skill, Cast, Resolution, Event, resolution_steps};
use skill::{Skill, Cast, Resolution, Event, resolve};
use effect::{Effect};
use player::{Player};
use instance::{TimeControl, instance_game_finished};
@@ -217,6 +217,7 @@ impl Game {
fn pve_add_skills(&mut self) -> &mut Game {
let mut pve_skills = vec![];
let mut rng = thread_rng();
for mobs in self.players
.iter()
@@ -228,8 +229,6 @@ impl Game {
// info!("{:?} {:?}", mob.name, skill);
match skill {
Some(s) => {
let mut rng = thread_rng();
// the mut marks it as being able to be called
// more than once
let mut find_target = || {
@@ -479,7 +478,7 @@ impl Game {
while let Some(cast) = self.stack.pop() {
// info!("{:} casts ", cast);
let mut resolutions = resolution_steps(&cast, &mut self);
let mut resolutions = resolve(&cast, &mut self);
r_animation_ms = resolutions.iter().fold(r_animation_ms, |acc, r| acc + r.clone().get_delay());
@@ -807,91 +806,6 @@ pub fn game_delete(tx: &mut Transaction, id: Uuid) -> Result<(), Error> {
return Ok(());
}
// pub fn game_global_startup(tx: &mut Transaction) -> Result<(), Error> {
// if game_global_get(tx).is_ok() {
// info!("global mm game exists");
// return Ok(());
// }
// let mut game = Game::new();
// game
// .set_player_num(2)
// .set_player_constructs(3)
// .set_mode(GameMode::Pvp);
// game_write(tx, &game)?;
// let query = "
// INSERT INTO matchmaking (id, game)
// VALUES ($1, $2)
// RETURNING id;
// ";
// let result = tx
// .query(query, &[&Uuid::nil(), &game.id])?;
// result.iter().next().ok_or(format_err!("no game written"))?;
// info!("{:} wrote global mm startup", game.id);
// return Ok(());
// }
// pub fn game_global_set(tx: &mut Transaction, game: &Game) -> Result<(), Error> {
// let query = "
// UPDATE matchmaking
// SET game = $1
// WHERE id = $2
// RETURNING id, game;
// ";
// let result = tx
// .query(query, &[&game.id, &Uuid::nil()])?;
// result.iter()
// .next()
// .ok_or(err_msg("could not set global game mm"))?;
// return Ok(());
// }
// pub fn game_global_get(tx: &mut Transaction) -> Result<Game, Error> {
// let query = "
// SELECT * from games
// WHERE id = (
// SELECT game
// FROM matchmaking
// WHERE id = $1
// );
// ";
// let delete_query = "
// DELETE from matchmaking;
// ";
// let result = tx
// .query(query, &[&Uuid::nil()])?;
// let returned = match result.iter().next() {
// Some(row) => row,
// None => return Err(err_msg("game not found")),
// };
// // 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,
// Err(_) => {
// tx.query(delete_query, &[])?;
// return Err(err_msg("matchmaking game was invalid"))
// }
// };
// return Ok(game);
// }
pub fn game_update(tx: &mut Transaction, game: &Game) -> Result<(), Error> {
let game_bytes = to_vec(&game)?;
@@ -964,13 +878,7 @@ pub fn game_concede(tx: &mut Transaction, account: &Account, game_id: Uuid) -> R
pub fn game_skill_clear(tx: &mut Transaction, account: &Account, game_id: Uuid) -> Result<Game, Error> {
let mut game = game_get(tx, game_id)?;
game.clear_skill(account.id)?;
if game.skill_phase_finished() {
game = game.resolve_phase_start();
}
game_update(tx, &game)?;
Ok(game)
+22 -34
View File
@@ -18,18 +18,12 @@ pub fn dev_resolve(a_id: Uuid, b_id: Uuid, skill: Skill) -> Resolutions {
if skill.aoe() { // Send an aoe skill event for anims
resolutions.push(Resolution::new(&a, &b).event(Event::AoeSkill { skill }).stages(EventStages::StartEnd));
}
return resolve(skill, &mut a, &mut b, resolutions);
return resolve_skill(skill, &mut a, &mut b, resolutions);
}
pub fn resolution_steps(cast: &Cast, game: &mut Game) -> Resolutions {
pub fn resolve(cast: &Cast, game: &mut Game) -> Resolutions {
let mut resolutions = vec![];
resolutions = pre_resolve(cast, game, resolutions);
return resolutions;
}
pub fn pre_resolve(cast: &Cast, game: &mut Game, mut resolutions: Resolutions) -> Resolutions {
let skill = cast.skill;
let source = game.construct_by_id(cast.source_construct_id).unwrap().clone();
let targets = game.get_targets(cast.skill, &source, cast.target_construct_id);
@@ -54,7 +48,7 @@ pub fn pre_resolve(cast: &Cast, game: &mut Game, mut resolutions: Resolutions) -
continue;
}
resolutions = resolve(cast.skill, &mut source, &mut target, resolutions);
resolutions = resolve_skill(cast.skill, &mut source, &mut target, resolutions);
// save the changes to the game
game.update_construct(&mut source);
@@ -67,7 +61,7 @@ pub fn pre_resolve(cast: &Cast, game: &mut Game, mut resolutions: Resolutions) -
return resolutions;
}
pub fn resolve(skill: Skill, source: &mut Construct, target: &mut Construct, mut resolutions: Vec<Resolution>) -> Resolutions {
pub fn resolve_skill(skill: Skill, source: &mut Construct, target: &mut Construct, mut resolutions: Vec<Resolution>) -> Resolutions {
if let Some(_disable) = source.disabled(skill) {
// resolutions.push(Resolution::new(source, target).event(Event::Disable { disable, skill }).stages(EventStages::PostOnly));
return resolutions;
@@ -84,7 +78,7 @@ pub fn resolve(skill: Skill, source: &mut Construct, target: &mut Construct, mut
return resolutions;
}
resolutions.push(Resolution::new(source, target).event(Event::Reflection { skill }));
return resolve(skill, &mut source.clone(), source, resolutions);
return resolve_skill(skill, &mut source.clone(), source, resolutions);
}
if source.affected(Effect::Haste) {
@@ -175,14 +169,14 @@ pub fn resolve(skill: Skill, source: &mut Construct, target: &mut Construct, mut
Skill::Decay|
Skill::DecayPlus |
Skill::DecayPlusPlus => decay(source, target, resolutions, skill), // dot
Skill::DecayPlusPlus => decay(source, target, resolutions, skill),
Skill::DecayTick|
Skill::DecayTickPlus |
Skill::DecayTickPlusPlus => decay_tick(source, target, resolutions, skill), // dot
Skill::DecayTickPlusPlus => decay_tick(source, target, resolutions, skill),
Skill::Haste|
Skill::HastePlus |
Skill::HastePlusPlus => haste(source, target, resolutions, skill), // speed slow
Skill::HastePlusPlus => haste(source, target, resolutions, skill),
Skill::Heal|
Skill::HealPlus |
@@ -206,7 +200,7 @@ pub fn resolve(skill: Skill, source: &mut Construct, target: &mut Construct, mut
Skill::Purge|
Skill::PurgePlus |
Skill::PurgePlusPlus => purge(source, target, resolutions, skill), // dispel all buffs
Skill::PurgePlusPlus => purge(source, target, resolutions, skill),
Skill::Purify|
Skill::PurifyPlus |
@@ -226,26 +220,26 @@ pub fn resolve(skill: Skill, source: &mut Construct, target: &mut Construct, mut
Skill::Link|
Skill::LinkPlus |
Skill::LinkPlusPlus => link(source, target, resolutions, skill), // target is immune to magic damage and fx
Skill::LinkPlusPlus => link(source, target, resolutions, skill),
Skill::Silence|
Skill::SilencePlus |
Skill::SilencePlusPlus => silence(source, target, resolutions, skill), // target cannot cast spells
Skill::SilencePlusPlus => silence(source, target, resolutions, skill),
Skill::Siphon|
Skill::SiphonPlus |
Skill::SiphonPlusPlus => siphon(source, target, resolutions, skill), // dot
Skill::SiphonPlusPlus => siphon(source, target, resolutions, skill),
Skill::SiphonTick|
Skill::SiphonTickPlus |
Skill::SiphonTickPlusPlus => siphon_tick(source, target, resolutions, skill), // dot
Skill::SiphonTickPlusPlus => siphon_tick(source, target, resolutions, skill),
Skill::Slay|
Skill::SlayPlus |
Skill::SlayPlusPlus => slay(source, target, resolutions, skill), // hybrid dmg self heal
Skill::SlayPlusPlus => slay(source, target, resolutions, skill),
Skill::Sleep|
Skill::SleepPlus |
Skill::SleepPlusPlus => sleep(source, target, resolutions, skill), // heal stun
Skill::SleepPlusPlus => sleep(source, target, resolutions, skill),
Skill::Restrict|
Skill::RestrictPlus |
@@ -261,24 +255,24 @@ pub fn resolve(skill: Skill, source: &mut Construct, target: &mut Construct, mut
Skill::Break|
Skill::BreakPlus |
Skill::BreakPlusPlus => break_(source, target, resolutions, skill), // no damage stun, adds vulnerable
Skill::BreakPlusPlus => break_(source, target, resolutions, skill),
Skill::Triage|
Skill::TriagePlus |
Skill::TriagePlusPlus => triage(source, target, resolutions, skill), // hot
Skill::TriagePlusPlus => triage(source, target, resolutions, skill),
Skill::TriageTick|
Skill::TriageTickPlus |
Skill::TriageTickPlusPlus => triage_tick(source, target, resolutions, skill), // hot
Skill::TriageTickPlusPlus => triage_tick(source, target, resolutions, skill),
// Base Skills
Skill::Attack => attack(source, target, resolutions, skill),
Skill::Block => block(source, target, resolutions, skill),
Skill::Buff => buff(source, target, resolutions, skill),
Skill::Debuff => debuff(source, target, resolutions, skill), // speed slow
Skill::Debuff => debuff(source, target, resolutions, skill),
Skill::Stun => stun(source, target, resolutions, skill),
//Triggered
// Triggered
Skill::Electrocute |
Skill::ElectrocutePlus |
Skill::ElectrocutePlusPlus => panic!("should only trigger from electrify hit"),
@@ -1267,8 +1261,6 @@ impl Skill {
}
pub fn defensive(&self) -> bool {
let mut rng = thread_rng();
match self {
Skill::Amplify|
Skill::AmplifyPlus |
@@ -1311,10 +1303,6 @@ impl Skill {
Skill::TriagePlus |
Skill::TriagePlusPlus => true,
Skill::Banish |
Skill::BanishPlus |
Skill::BanishPlusPlus => rng.gen_bool(0.5),
_ => false,
}
}
@@ -2021,7 +2009,7 @@ mod tests {
assert!(y.affected(Effect::Reflect));
let mut results = vec![];
results = resolve(Skill::Blast, &mut x, &mut y, results);
results = resolve_skill(Skill::Blast, &mut x, &mut y, results);
assert!(x.green_life() < 1024);
@@ -2052,7 +2040,7 @@ mod tests {
y.blue_life.force(0);
x.green_life.reduce(512);
let mut results = resolve(Skill::Siphon, &mut x, &mut y, vec![]);
let mut results = resolve_skill(Skill::Siphon, &mut x, &mut y, vec![]);
assert!(y.affected(Effect::Siphon));
assert!(x.green_life() == (512 + 256.pct(Skill::SiphonTick.multiplier()) + 220.pct(Skill::SiphonTick.multiplier())));