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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
use crate::{combat::DamageContributor, comp, terrain::SpriteKind, uid::Uid, DamageSource};
use comp::{beam, item::Reagent, poise::PoiseState, skillset::SkillGroupKind, UtteranceKind};
use hashbrown::HashSet;
use serde::{Deserialize, Serialize};
use vek::*;

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct HealthChangeInfo {
    pub amount: f32,
    pub precise: bool,
    pub target: Uid,
    pub by: Option<DamageContributor>,
    pub cause: Option<DamageSource>,
    pub instance: u64,
}

/// An outcome represents the final result of an instantaneous event. It implies
/// that said event has already occurred. It is not a request for that event to
/// occur, nor is it something that may be cancelled or otherwise altered. Its
/// primary purpose is to act as something for frontends (both server and
/// client) to listen to in order to receive feedback about events in the world.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum Outcome {
    Explosion {
        pos: Vec3<f32>,
        power: f32,
        radius: f32,
        is_attack: bool,
        reagent: Option<Reagent>, // How can we better define this?
    },
    Lightning {
        pos: Vec3<f32>,
    },
    ProjectileShot {
        pos: Vec3<f32>,
        body: comp::Body,
        vel: Vec3<f32>,
    },
    ProjectileHit {
        pos: Vec3<f32>,
        body: comp::Body,
        vel: Vec3<f32>,
        source: Option<Uid>,
        target: Option<Uid>,
    },
    Beam {
        pos: Vec3<f32>,
        specifier: beam::FrontendSpecifier,
    },
    ExpChange {
        uid: Uid,
        exp: u32,
        xp_pools: HashSet<SkillGroupKind>,
    },
    SkillPointGain {
        uid: Uid,
        skill_tree: SkillGroupKind,
        total_points: u16,
    },
    ComboChange {
        uid: Uid,
        combo: u32,
    },
    BreakBlock {
        pos: Vec3<i32>,
        color: Option<Rgb<u8>>,
    },
    SummonedCreature {
        pos: Vec3<f32>,
        body: comp::Body,
    },
    HealthChange {
        pos: Vec3<f32>,
        info: HealthChangeInfo,
    },
    Death {
        pos: Vec3<f32>,
    },
    Block {
        pos: Vec3<f32>,
        parry: bool,
        uid: Uid,
    },
    PoiseChange {
        pos: Vec3<f32>,
        state: PoiseState,
    },
    GroundSlam {
        pos: Vec3<f32>,
    },
    IceSpikes {
        pos: Vec3<f32>,
    },
    IceCrack {
        pos: Vec3<f32>,
    },
    FlashFreeze {
        pos: Vec3<f32>,
    },
    Steam {
        pos: Vec3<f32>,
    },
    LaserBeam {
        pos: Vec3<f32>,
    },
    CyclopsCharge {
        pos: Vec3<f32>,
    },
    FlamethrowerCharge {
        pos: Vec3<f32>,
    },
    FuseCharge {
        pos: Vec3<f32>,
    },
    TerracottaStatueCharge {
        pos: Vec3<f32>,
    },
    SurpriseEgg {
        pos: Vec3<f32>,
    },
    Utterance {
        pos: Vec3<f32>,
        body: comp::Body,
        kind: UtteranceKind,
    },
    Glider {
        pos: Vec3<f32>,
        wielded: bool,
    },
    SpriteDelete {
        pos: Vec3<i32>,
        sprite: SpriteKind,
    },
    SpriteUnlocked {
        pos: Vec3<i32>,
    },
    FailedSpriteUnlock {
        pos: Vec3<i32>,
    },
    Whoosh {
        pos: Vec3<f32>,
    },
    Swoosh {
        pos: Vec3<f32>,
    },
    Slash {
        pos: Vec3<f32>,
    },
    FireShockwave {
        pos: Vec3<f32>,
    },
    GroundDig {
        pos: Vec3<f32>,
    },
    PortalActivated {
        pos: Vec3<f32>,
    },
    TeleportedByPortal {
        pos: Vec3<f32>,
    },
    FromTheAshes {
        pos: Vec3<f32>,
    },
    ClayGolemDash {
        pos: Vec3<f32>,
    },
    Bleep {
        pos: Vec3<f32>,
    },
    Charge {
        pos: Vec3<f32>,
    },
}

impl Outcome {
    pub fn get_pos(&self) -> Option<Vec3<f32>> {
        match self {
            Outcome::Explosion { pos, .. }
            // TODO: Include this, but allow it to be sent to clients when outside of the VD
            // | Outcome::Lightning { pos }
            | Outcome::ProjectileShot { pos, .. }
            | Outcome::ProjectileHit { pos, .. }
            | Outcome::Beam { pos, .. }
            | Outcome::SummonedCreature { pos, .. }
            | Outcome::HealthChange { pos, .. }
            | Outcome::Death { pos, .. }
            | Outcome::Block { pos, .. }
            | Outcome::PoiseChange { pos, .. }
            | Outcome::GroundSlam { pos }
            | Outcome::FlashFreeze { pos }
            | Outcome::Whoosh { pos }
            | Outcome::Swoosh { pos }
            | Outcome::Slash { pos }
            | Outcome::Bleep { pos }
            | Outcome::Charge { pos }
            | Outcome::IceSpikes { pos }
            | Outcome::Steam { pos }
            | Outcome::FireShockwave { pos }
            | Outcome::IceCrack { pos }
            | Outcome::Utterance { pos, .. }
            | Outcome::CyclopsCharge { pos }
            | Outcome::FlamethrowerCharge { pos }
            | Outcome::FuseCharge { pos }
            | Outcome::TerracottaStatueCharge { pos }
            | Outcome::SurpriseEgg { pos }
            | Outcome::LaserBeam { pos }
            | Outcome::GroundDig { pos }
            | Outcome::PortalActivated { pos }
            | Outcome::TeleportedByPortal { pos}
            | Outcome::FromTheAshes { pos }
            | Outcome::ClayGolemDash { pos }
            | Outcome::Glider { pos, .. } => Some(*pos),
            Outcome::BreakBlock { pos, .. }
            | Outcome::SpriteUnlocked { pos }
            | Outcome::SpriteDelete { pos, .. }
            | Outcome::FailedSpriteUnlock { pos } => Some(pos.map(|e| e as f32 + 0.5)),
            Outcome::ExpChange { .. }
            | Outcome::ComboChange { .. }
            | Outcome::Lightning { .. }
            | Outcome::SkillPointGain { .. } => None,
        }
    }
}