calculate direction server side

This commit is contained in:
Mashy
2019-12-06 20:24:14 +10:00
parent a6f654fac1
commit 261ab1d48b
4 changed files with 54 additions and 48 deletions
+29 -2
View File
@@ -517,13 +517,40 @@ impl Game {
self
}
fn direction(&mut self, cast: Cast) -> (i8, i8) {
let i = self.players.iter()
.find(|t| t.constructs.iter().any(|c| c.id == cast.source))
.unwrap().constructs
.iter()
.position(|c| c.id == cast.source)
.unwrap() as i8;
let j = self.players.iter()
.find(|t| t.constructs.iter().any(|c| c.id == cast.target))
.unwrap().constructs
.iter()
.position(|c| c.id == cast.target)
.unwrap() as i8;
let x = j - i;
let target = self.construct_by_id(cast.target).unwrap();
// is the caster player account same as target player account side of screen
let y = match cast.player == target.account {
true => 0,
false => 1
};
(x, y)
}
fn cast(&mut self, cast: Cast) -> &mut Game {
self.event_add(vec![EventVariant::Cast()], cast);
let (x, y) = self.direction(cast);
self.event_add(vec![EventVariant::Cast { target: cast.source, x, y, player: cast.player }], cast);
self
}
fn hit(&mut self, cast: Cast) -> &mut Game {
self.event_add(vec![EventVariant::Hit()], cast);
let (x, y) = self.direction(cast);
self.event_add(vec![EventVariant::Hit { target: cast.target, x, y, player: cast.player }], cast);
self
}
+6 -5
View File
@@ -237,9 +237,9 @@ pub struct Event {
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
pub enum EventVariant {
Cast (),
Hit (),
HitAoe (),
Cast { target: Uuid, player: Uuid, x: i8, y: i8 },
Hit { target: Uuid, player: Uuid, x: i8, y: i8 },
HitAoe { target: Uuid },
Damage { target: Uuid, amount: usize, mitigation: usize, colour: Colour, display: EventConstruct },
Effect { target: Uuid, effect: Effect, duration: u8, display: EventConstruct },
@@ -265,8 +265,9 @@ impl EventVariant {
let combat_text_overlap = 600; // overlap between animation and combat text
match self {
EventVariant::Hit() => target_duration - combat_text_overlap,
EventVariant::Cast() => target_delay,
EventVariant::Cast { target: _, x: _, y: _, player: _ } => target_delay,
EventVariant::Hit { target: _, x: _, y: _, player: _ } |
EventVariant::HitAoe { target: _ } => target_duration - combat_text_overlap,
_ => combat_text_delay,
}
}