veloren_common/
outcome.rs

1use crate::{
2    DamageSource,
3    combat::DamageContributor,
4    comp::{self, item::ToolKind},
5    terrain::SpriteKind,
6    uid::Uid,
7};
8use comp::{UtteranceKind, beam, item::Reagent, poise::PoiseState, skillset::SkillGroupKind};
9use hashbrown::HashSet;
10use serde::{Deserialize, Serialize};
11use vek::*;
12
13#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
14pub struct HealthChangeInfo {
15    pub amount: f32,
16    pub precise: bool,
17    pub target: Uid,
18    pub by: Option<DamageContributor>,
19    pub cause: Option<DamageSource>,
20    pub instance: u64,
21}
22
23/// An outcome represents the final result of an instantaneous event. It implies
24/// that said event has already occurred. It is not a request for that event to
25/// occur, nor is it something that may be cancelled or otherwise altered. Its
26/// primary purpose is to act as something for frontends (both server and
27/// client) to listen to in order to receive feedback about events in the world.
28#[derive(Clone, Debug, Serialize, Deserialize, strum::VariantNames)]
29pub enum Outcome {
30    Explosion {
31        pos: Vec3<f32>,
32        power: f32,
33        radius: f32,
34        is_attack: bool,
35        reagent: Option<Reagent>, // How can we better define this?
36    },
37    Lightning {
38        pos: Vec3<f32>,
39    },
40    ProjectileShot {
41        pos: Vec3<f32>,
42        body: comp::Body,
43        vel: Vec3<f32>,
44    },
45    ProjectileHit {
46        pos: Vec3<f32>,
47        body: comp::Body,
48        vel: Vec3<f32>,
49        source: Option<Uid>,
50        target: Option<Uid>,
51    },
52    Beam {
53        pos: Vec3<f32>,
54        specifier: beam::FrontendSpecifier,
55    },
56    ExpChange {
57        uid: Uid,
58        exp: u32,
59        xp_pools: HashSet<SkillGroupKind>,
60    },
61    SkillPointGain {
62        uid: Uid,
63        skill_tree: SkillGroupKind,
64        total_points: u16,
65    },
66    ComboChange {
67        uid: Uid,
68        combo: u32,
69    },
70    BreakBlock {
71        pos: Vec3<i32>,
72        tool: Option<ToolKind>,
73        color: Option<Rgb<u8>>,
74    },
75    DamagedBlock {
76        pos: Vec3<i32>,
77        tool: Option<ToolKind>,
78        stage_changed: bool,
79    },
80    SummonedCreature {
81        pos: Vec3<f32>,
82        body: comp::Body,
83    },
84    HealthChange {
85        pos: Vec3<f32>,
86        info: HealthChangeInfo,
87    },
88    Death {
89        pos: Vec3<f32>,
90    },
91    Block {
92        pos: Vec3<f32>,
93        parry: bool,
94        uid: Uid,
95    },
96    PoiseChange {
97        pos: Vec3<f32>,
98        state: PoiseState,
99    },
100    GroundSlam {
101        pos: Vec3<f32>,
102    },
103    IceSpikes {
104        pos: Vec3<f32>,
105    },
106    IceCrack {
107        pos: Vec3<f32>,
108    },
109    FlashFreeze {
110        pos: Vec3<f32>,
111    },
112    Steam {
113        pos: Vec3<f32>,
114    },
115    LaserBeam {
116        pos: Vec3<f32>,
117    },
118    CyclopsCharge {
119        pos: Vec3<f32>,
120    },
121    FlamethrowerCharge {
122        pos: Vec3<f32>,
123    },
124    FuseCharge {
125        pos: Vec3<f32>,
126    },
127    TerracottaStatueCharge {
128        pos: Vec3<f32>,
129    },
130    SurpriseEgg {
131        pos: Vec3<f32>,
132    },
133    Utterance {
134        pos: Vec3<f32>,
135        body: comp::Body,
136        kind: UtteranceKind,
137    },
138    Glider {
139        pos: Vec3<f32>,
140        wielded: bool,
141    },
142    SpriteDelete {
143        pos: Vec3<i32>,
144        sprite: SpriteKind,
145    },
146    SpriteUnlocked {
147        pos: Vec3<i32>,
148    },
149    FailedSpriteUnlock {
150        pos: Vec3<i32>,
151    },
152    Whoosh {
153        pos: Vec3<f32>,
154    },
155    Swoosh {
156        pos: Vec3<f32>,
157    },
158    Slash {
159        pos: Vec3<f32>,
160    },
161    FireShockwave {
162        pos: Vec3<f32>,
163    },
164    GroundDig {
165        pos: Vec3<f32>,
166    },
167    PortalActivated {
168        pos: Vec3<f32>,
169    },
170    TeleportedByPortal {
171        pos: Vec3<f32>,
172    },
173    FromTheAshes {
174        pos: Vec3<f32>,
175    },
176    ClayGolemDash {
177        pos: Vec3<f32>,
178    },
179    Bleep {
180        pos: Vec3<f32>,
181    },
182    Charge {
183        pos: Vec3<f32>,
184    },
185    HeadLost {
186        uid: Uid,
187        head: usize,
188    },
189    Splash {
190        vel: Vec3<f32>,
191        pos: Vec3<f32>,
192        mass: f32,
193        kind: comp::fluid_dynamics::LiquidKind,
194    },
195}
196
197impl Outcome {
198    pub fn get_pos(&self) -> Option<Vec3<f32>> {
199        match self {
200            Outcome::Explosion { pos, .. }
201            // TODO: Include this, but allow it to be sent to clients when outside of the VD
202            // | Outcome::Lightning { pos }
203            | Outcome::ProjectileShot { pos, .. }
204            | Outcome::ProjectileHit { pos, .. }
205            | Outcome::Beam { pos, .. }
206            | Outcome::SummonedCreature { pos, .. }
207            | Outcome::HealthChange { pos, .. }
208            | Outcome::Death { pos, .. }
209            | Outcome::Block { pos, .. }
210            | Outcome::PoiseChange { pos, .. }
211            | Outcome::GroundSlam { pos }
212            | Outcome::FlashFreeze { pos }
213            | Outcome::Whoosh { pos }
214            | Outcome::Swoosh { pos }
215            | Outcome::Slash { pos }
216            | Outcome::Bleep { pos }
217            | Outcome::Charge { pos }
218            | Outcome::IceSpikes { pos }
219            | Outcome::Steam { pos }
220            | Outcome::FireShockwave { pos }
221            | Outcome::IceCrack { pos }
222            | Outcome::Utterance { pos, .. }
223            | Outcome::CyclopsCharge { pos }
224            | Outcome::FlamethrowerCharge { pos }
225            | Outcome::FuseCharge { pos }
226            | Outcome::TerracottaStatueCharge { pos }
227            | Outcome::SurpriseEgg { pos }
228            | Outcome::LaserBeam { pos }
229            | Outcome::GroundDig { pos }
230            | Outcome::PortalActivated { pos }
231            | Outcome::TeleportedByPortal { pos}
232            | Outcome::FromTheAshes { pos }
233            | Outcome::ClayGolemDash { pos }
234            | Outcome::Glider { pos, .. }
235            | Outcome::Splash { pos, .. } => Some(*pos),
236            Outcome::BreakBlock { pos, .. }
237            | Outcome::DamagedBlock { pos, .. }
238            | Outcome::SpriteUnlocked { pos }
239            | Outcome::SpriteDelete { pos, .. }
240            | Outcome::FailedSpriteUnlock { pos } => Some(pos.map(|e| e as f32 + 0.5)),
241            Outcome::ExpChange { .. }
242            | Outcome::ComboChange { .. }
243            | Outcome::Lightning { .. }
244            | Outcome::SkillPointGain { .. }
245            | Outcome::HeadLost { .. } => None,
246        }
247    }
248}