-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtown_defence.rs
More file actions
69 lines (65 loc) · 2.09 KB
/
town_defence.rs
File metadata and controls
69 lines (65 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use super::*;
use crate::game::buildings::Building;
use crate::game::fight::Aura;
use crate::game::visits::attacks::Attack;
use crate::net::graphql::attacks_query::{AttacksQueryVillageAttacksUnits, HoboAttributeType};
use paddlers_shared_lib::game_mechanics::town::*;
use paddlers_shared_lib::graphql_types::*;
use specs::prelude::*;
pub(crate) struct AttackingHobo<'a> {
pub unit: AttacksQueryVillageAttacksUnits,
pub attack: &'a Attack,
}
impl<'a> IAttackingHobo for AttackingHobo<'a> {
fn max_hp(&self) -> u32 {
self.unit.hobo.hp as u32
}
fn speed(&self) -> f32 {
self.unit.hobo.speed as f32
}
fn hurried(&self) -> bool {
self.unit.hobo.hurried
}
fn arrival(&self) -> Timestamp {
self.attack.arrival
}
fn released(&self) -> Option<Timestamp> {
self.unit
.info
.released
.as_ref()
.map(|t| GqlTimestamp::from_string(&t).unwrap().to_chrono().into())
}
fn effects_strength(&self) -> i32 {
self.unit
.hobo
.effects
.iter()
.filter(|e| e.attribute == HoboAttributeType::HEALTH)
.filter(|e| e.strength.is_some())
.fold(0, |acc, e| acc + e.strength.unwrap() as i64) as i32
}
}
impl<'a, 'b> ITownLayoutMarker for Game<'a, 'b> {
const LAYOUT: TownLayout = TownLayout::Basic;
}
impl<'a, 'b> IDefendingTown for Game<'a, 'b> {
type AuraId = u32;
fn auras_in_range(&self, index: &Self::Index, time: Timestamp) -> Vec<(Self::AuraId, i32)> {
let mut out = vec![];
let auras = self.world.read_component::<Aura>();
let buildings = self.world.read_component::<Building>();
let entities = self.world.entities();
for (aura, e, b) in (&auras, &entities, &buildings).join() {
if time < b.built {
continue;
}
for tile in &aura.affected_tiles {
if tile.0 == index.0 && tile.1 == index.1 {
out.push((e.id(), aura.effect as i32))
}
}
}
out
}
}