veloren/common/src/outcome.rs

122 lines
3.2 KiB
Rust
Raw Normal View History

2022-05-02 19:10:55 +00:00
use crate::{combat::DamageContributor, comp, uid::Uid};
use comp::{beam, item::Reagent, poise::PoiseState, skillset::SkillGroupKind, UtteranceKind};
use hashbrown::HashSet;
2020-07-31 17:16:20 +00:00
use serde::{Deserialize, Serialize};
use vek::*;
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct HealthChangeInfo {
pub amount: f32,
2022-05-17 19:30:51 +00:00
pub crit: bool,
pub target: Uid,
pub by: Option<DamageContributor>,
2022-01-26 10:16:45 +00:00
pub instance: u64,
}
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>,
},
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: comp::skillset::SkillGroupKind,
total_points: u16,
},
2021-03-04 20:43:58 +00:00
ComboChange {
uid: Uid,
combo: u32,
},
BreakBlock {
pos: Vec3<i32>,
color: Option<Rgb<u8>>,
},
2021-03-27 15:47:56 +00:00
SummonedCreature {
pos: Vec3<f32>,
body: comp::Body,
},
HealthChange {
2021-04-04 03:04:02 +00:00
pos: Vec3<f32>,
info: HealthChangeInfo,
2021-04-04 03:04:02 +00:00
},
Death {
pos: Vec3<f32>,
},
Block {
pos: Vec3<f32>,
parry: bool,
uid: Uid,
},
PoiseChange {
pos: Vec3<f32>,
state: PoiseState,
},
2021-04-28 22:41:04 +00:00
GroundSlam {
pos: Vec3<f32>,
},
2021-06-15 16:15:58 +00:00
Utterance {
pos: Vec3<f32>,
body: comp::Body,
kind: UtteranceKind,
},
Glider {
pos: Vec3<f32>,
wielded: bool,
},
Jump {
pos: Vec3<f32>,
}
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::ProjectileHit { pos, .. }
2021-03-04 20:43:58 +00:00
| Outcome::Beam { pos, .. }
2021-04-04 03:04:02 +00:00
| Outcome::SummonedCreature { pos, .. }
| Outcome::HealthChange { pos, .. }
| Outcome::Death { pos, .. }
| Outcome::Block { pos, .. }
| Outcome::PoiseChange { pos, .. }
2021-06-15 16:15:58 +00:00
| Outcome::GroundSlam { pos }
| Outcome::Utterance { pos, .. }
| Outcome::Glider { pos, .. }
| Outcome::Jump { pos, .. } => Some(*pos),
Outcome::BreakBlock { pos, .. } => Some(pos.map(|e| e as f32 + 0.5)),
Outcome::ExpChange { .. } | Outcome::ComboChange { .. } | Outcome::SkillPointGain { .. } => None,
2020-07-31 17:16:20 +00:00
}
}
}