veloren_common/
explosion.rs

1use crate::{
2    combat::Attack,
3    comp::{ability::Dodgeable, item::Reagent},
4    effect::Effect,
5};
6use rand::{Rng, thread_rng};
7use serde::{Deserialize, Serialize};
8use vek::Rgb;
9
10#[derive(Clone, Debug, Serialize, Deserialize)]
11pub struct Explosion {
12    pub effects: Vec<RadiusEffect>,
13    pub radius: f32,
14    pub reagent: Option<Reagent>,
15    pub min_falloff: f32,
16}
17
18#[derive(Clone, Debug, Serialize, Deserialize)]
19pub enum RadiusEffect {
20    TerrainDestruction(f32, Rgb<f32>),
21    ReplaceTerrain(f32, TerrainReplacementPreset),
22    Entity(Effect),
23    Attack {
24        attack: Attack,
25        dodgeable: Dodgeable,
26    },
27}
28
29#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
30pub enum ColorPreset {
31    Black,
32    InkBomb,
33    IceBomb,
34}
35
36impl ColorPreset {
37    pub fn to_rgb(&self) -> Rgb<f32> {
38        match self {
39            Self::Black => Rgb::black(),
40            Self::InkBomb => Rgb::new(4.0, 7.0, 32.0),
41            Self::IceBomb => {
42                let variation = thread_rng().gen::<f32>();
43                Rgb::new(
44                    83.0 - (20.0 * variation),
45                    212.0 - (52.0 * variation),
46                    255.0 - (62.0 * variation),
47                )
48            },
49        }
50    }
51}
52
53#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
54pub enum TerrainReplacementPreset {
55    Lava {
56        timeout: f32,
57        timeout_offset: f32,
58        timeout_chance: f32,
59    },
60}