veloren_common/comp/
beam.rs

1use crate::{combat::Attack, resources::Secs};
2use hashbrown::HashMap;
3use serde::{Deserialize, Serialize};
4use specs::{Component, DerefFlaggedStorage, Entity as EcsEntity};
5use vek::*;
6
7#[derive(Clone, Debug, Serialize, Deserialize)]
8pub struct Beam {
9    pub attack: Attack,
10    pub end_radius: f32,
11    pub range: f32,
12    pub duration: Secs,
13    pub tick_dur: Secs,
14    pub specifier: FrontendSpecifier,
15    pub bezier: QuadraticBezier3<f32>,
16    #[serde(skip)]
17    pub hit_entities: Vec<EcsEntity>,
18    #[serde(skip)]
19    pub hit_durations: HashMap<EcsEntity, u32>,
20}
21
22impl Beam {
23    pub fn hit_entities_and_durations(
24        &mut self,
25    ) -> (&Vec<EcsEntity>, &mut HashMap<EcsEntity, u32>) {
26        (&self.hit_entities, &mut self.hit_durations)
27    }
28}
29
30impl Component for Beam {
31    type Storage = DerefFlaggedStorage<Self, specs::DenseVecStorage<Self>>;
32}
33
34#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, strum::EnumString)]
35pub enum FrontendSpecifier {
36    Flamethrower,
37    LifestealBeam,
38    Cultist,
39    Gravewarden,
40    Bubbles,
41    Steam,
42    Frost,
43    WebStrand,
44    Poison,
45    Ink,
46    Lightning,
47    PhoenixLaser,
48}
49
50impl FrontendSpecifier {
51    pub fn particles_per_sec(self) -> f32 {
52        (match self {
53            FrontendSpecifier::Flamethrower
54            | FrontendSpecifier::Bubbles
55            | FrontendSpecifier::Steam
56            | FrontendSpecifier::Frost
57            | FrontendSpecifier::Poison
58            | FrontendSpecifier::Ink
59            | FrontendSpecifier::PhoenixLaser
60            | FrontendSpecifier::Gravewarden => 300.0,
61            FrontendSpecifier::LifestealBeam => 420.0,
62            FrontendSpecifier::Cultist => 960.0,
63            FrontendSpecifier::WebStrand => 180.0,
64            FrontendSpecifier::Lightning => 120.0,
65        }) / 1000.0
66    }
67}