veloren/common/src/outcome.rs

57 lines
1.6 KiB
Rust
Raw Normal View History

use crate::{comp, uid::Uid};
use comp::{beam, item::Reagent};
2020-07-31 17:16:20 +00:00
use serde::{Deserialize, Serialize};
use vek::*;
2020-08-06 16:41:43 +00:00
/// 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.
2020-07-31 17:16:20 +00:00
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum Outcome {
Explosion {
pos: Vec3<f32>,
power: f32,
radius: f32,
is_attack: bool,
2020-08-11 14:05:34 +00:00
reagent: Option<Reagent>, // How can we better define this?
2020-07-31 17:16:20 +00:00
},
ProjectileShot {
pos: Vec3<f32>,
body: comp::Body,
vel: Vec3<f32>,
},
Beam {
pos: Vec3<f32>,
specifier: beam::FrontendSpecifier,
},
ExpChange {
uid: Uid,
exp: i32,
},
SkillPointGain {
uid: Uid,
skill_tree: comp::skills::SkillGroupKind,
total_points: u16,
// TODO: Access ECS to get position from Uid to conserve bandwidth
pos: Vec3<f32>,
},
2021-03-04 20:43:58 +00:00
ComboChange {
uid: Uid,
combo: u32,
},
2020-07-31 17:16:20 +00:00
}
impl Outcome {
pub fn get_pos(&self) -> Option<Vec3<f32>> {
match self {
2021-03-04 20:43:58 +00:00
Outcome::Explosion { pos, .. }
| Outcome::ProjectileShot { pos, .. }
| Outcome::Beam { pos, .. }
| Outcome::SkillPointGain { pos, .. } => Some(*pos),
Outcome::ExpChange { .. } | Outcome::ComboChange { .. } => None,
2020-07-31 17:16:20 +00:00
}
}
}