2020-11-11 23:59:09 +00:00
|
|
|
use crate::{
|
|
|
|
character::CharacterId,
|
|
|
|
sync::Uid,
|
|
|
|
util::Dir,
|
|
|
|
comp,
|
|
|
|
Explosion,
|
|
|
|
rtsim::RtSimEntity,
|
|
|
|
};
|
2020-08-08 22:22:21 +00:00
|
|
|
use comp::{
|
|
|
|
item::{Item, Reagent},
|
|
|
|
Ori, Pos,
|
|
|
|
};
|
2019-08-15 22:19:54 +00:00
|
|
|
use parking_lot::Mutex;
|
2019-08-07 15:39:16 +00:00
|
|
|
use specs::Entity as EcsEntity;
|
2020-06-28 15:21:12 +00:00
|
|
|
use std::{collections::VecDeque, ops::DerefMut};
|
2019-08-07 15:39:16 +00:00
|
|
|
use vek::*;
|
|
|
|
|
2019-08-25 14:49:54 +00:00
|
|
|
pub enum LocalEvent {
|
2020-03-21 22:55:20 +00:00
|
|
|
/// Applies upward force to entity's `Vel`
|
2019-08-25 14:49:54 +00:00
|
|
|
Jump(EcsEntity),
|
2020-09-19 16:55:31 +00:00
|
|
|
/// Applies the `impulse` to `entity`'s `Vel`
|
|
|
|
ApplyImpulse {
|
|
|
|
entity: EcsEntity,
|
|
|
|
impulse: Vec3<f32>,
|
|
|
|
},
|
2020-03-21 22:55:20 +00:00
|
|
|
/// Applies leaping force to `entity`'s `Vel` away from `wall_dir` direction
|
|
|
|
WallLeap {
|
2019-09-09 19:11:40 +00:00
|
|
|
entity: EcsEntity,
|
2020-03-21 22:55:20 +00:00
|
|
|
wall_dir: Vec3<f32>,
|
2019-09-09 19:11:40 +00:00
|
|
|
},
|
2020-03-21 22:55:20 +00:00
|
|
|
/// Applies `vel` velocity to `entity`
|
|
|
|
Boost { entity: EcsEntity, vel: Vec3<f32> },
|
2019-08-25 14:49:54 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 19:47:36 +00:00
|
|
|
#[allow(clippy::large_enum_variant)] // TODO: Pending review in #587
|
2019-08-25 14:49:54 +00:00
|
|
|
pub enum ServerEvent {
|
2019-08-23 10:11:37 +00:00
|
|
|
Explosion {
|
|
|
|
pos: Vec3<f32>,
|
2020-10-15 00:43:53 +00:00
|
|
|
explosion: Explosion,
|
2020-03-22 19:39:50 +00:00
|
|
|
owner: Option<Uid>,
|
2020-08-11 14:05:34 +00:00
|
|
|
reagent: Option<Reagent>,
|
2019-08-23 10:11:37 +00:00
|
|
|
},
|
2019-09-21 12:43:24 +00:00
|
|
|
Damage {
|
2020-11-02 00:26:01 +00:00
|
|
|
entity: EcsEntity,
|
2019-10-17 20:59:36 +00:00
|
|
|
change: comp::HealthChange,
|
2019-09-21 12:43:24 +00:00
|
|
|
},
|
2020-11-11 11:42:22 +00:00
|
|
|
Delete(EcsEntity),
|
2019-09-17 12:43:19 +00:00
|
|
|
Destroy {
|
2019-08-23 10:11:37 +00:00
|
|
|
entity: EcsEntity,
|
|
|
|
cause: comp::HealthSource,
|
|
|
|
},
|
2019-10-15 04:06:14 +00:00
|
|
|
InventoryManip(EcsEntity, comp::InventoryManip),
|
2020-04-26 17:03:19 +00:00
|
|
|
GroupManip(EcsEntity, comp::GroupManip),
|
2019-08-23 10:11:37 +00:00
|
|
|
Respawn(EcsEntity),
|
2019-09-28 19:35:28 +00:00
|
|
|
Shoot {
|
|
|
|
entity: EcsEntity,
|
2020-03-28 01:31:22 +00:00
|
|
|
dir: Dir,
|
2019-10-11 04:30:34 +00:00
|
|
|
body: comp::Body,
|
|
|
|
light: Option<comp::LightEmitter>,
|
2019-09-28 19:35:28 +00:00
|
|
|
projectile: comp::Projectile,
|
2019-10-17 20:59:36 +00:00
|
|
|
gravity: Option<comp::Gravity>,
|
2020-08-06 18:17:38 +00:00
|
|
|
speed: f32,
|
2019-09-28 19:35:28 +00:00
|
|
|
},
|
2020-08-08 22:22:21 +00:00
|
|
|
Shockwave {
|
|
|
|
properties: comp::shockwave::Properties,
|
|
|
|
pos: Pos,
|
|
|
|
ori: Ori,
|
|
|
|
},
|
2020-08-23 20:10:58 +00:00
|
|
|
Knockback {
|
|
|
|
entity: EcsEntity,
|
2020-09-19 16:55:31 +00:00
|
|
|
impulse: Vec3<f32>,
|
2020-08-23 20:10:58 +00:00
|
|
|
},
|
2020-09-24 02:02:30 +00:00
|
|
|
BeamSegment {
|
2020-09-05 16:27:36 +00:00
|
|
|
properties: comp::beam::Properties,
|
|
|
|
pos: Pos,
|
|
|
|
ori: Ori,
|
|
|
|
},
|
2019-10-08 16:50:26 +00:00
|
|
|
LandOnGround {
|
|
|
|
entity: EcsEntity,
|
|
|
|
vel: Vec3<f32>,
|
|
|
|
},
|
2020-10-07 02:23:20 +00:00
|
|
|
EnableLantern(EcsEntity),
|
|
|
|
DisableLantern(EcsEntity),
|
2019-09-09 19:11:40 +00:00
|
|
|
Mount(EcsEntity, EcsEntity),
|
|
|
|
Unmount(EcsEntity),
|
2019-10-11 04:30:34 +00:00
|
|
|
Possess(Uid, Uid),
|
2020-06-01 09:21:33 +00:00
|
|
|
LevelUp(EcsEntity, u32),
|
2020-06-16 01:00:32 +00:00
|
|
|
/// Inserts default components for a character when loading into the game
|
|
|
|
InitCharacterData {
|
2019-10-15 04:06:14 +00:00
|
|
|
entity: EcsEntity,
|
2020-09-17 23:02:14 +00:00
|
|
|
character_id: CharacterId,
|
2020-06-16 01:00:32 +00:00
|
|
|
},
|
|
|
|
UpdateCharacterData {
|
|
|
|
entity: EcsEntity,
|
2020-11-03 00:12:49 +00:00
|
|
|
components: (
|
|
|
|
comp::Body,
|
|
|
|
comp::Stats,
|
|
|
|
comp::Inventory,
|
|
|
|
comp::Loadout,
|
|
|
|
Option<comp::Waypoint>,
|
|
|
|
),
|
2019-10-15 04:06:14 +00:00
|
|
|
},
|
2019-12-31 08:10:51 +00:00
|
|
|
ExitIngame {
|
|
|
|
entity: EcsEntity,
|
|
|
|
},
|
2020-11-11 23:59:09 +00:00
|
|
|
// TODO: to avoid breakage when adding new fields, perhaps have an `NpcBuilder` type?
|
2019-10-20 05:19:50 +00:00
|
|
|
CreateNpc {
|
|
|
|
pos: comp::Pos,
|
|
|
|
stats: comp::Stats,
|
2020-10-31 22:34:08 +00:00
|
|
|
health: comp::Health,
|
2020-02-26 17:04:43 +00:00
|
|
|
loadout: comp::Loadout,
|
2019-10-20 05:19:50 +00:00
|
|
|
body: comp::Body,
|
2020-07-05 12:39:28 +00:00
|
|
|
agent: Option<comp::Agent>,
|
2020-01-24 21:24:57 +00:00
|
|
|
alignment: comp::Alignment,
|
2019-10-20 05:19:50 +00:00
|
|
|
scale: comp::Scale,
|
2020-11-22 21:03:06 +00:00
|
|
|
home_chunk: Option<comp::HomeChunk>,
|
2020-05-15 15:05:50 +00:00
|
|
|
drop_item: Option<Item>,
|
2020-11-11 23:59:09 +00:00
|
|
|
rtsim_entity: Option<RtSimEntity>,
|
2019-10-20 05:19:50 +00:00
|
|
|
},
|
2020-01-25 02:15:15 +00:00
|
|
|
CreateWaypoint(Vec3<f32>),
|
2019-10-15 04:06:14 +00:00
|
|
|
ClientDisconnect(EcsEntity),
|
|
|
|
ChunkRequest(EcsEntity, Vec2<i32>),
|
|
|
|
ChatCmd(EcsEntity, String),
|
2020-06-11 05:16:42 +00:00
|
|
|
/// Send a chat message to the player from an npc or other player
|
2020-07-12 20:18:57 +00:00
|
|
|
Chat(comp::UnresolvedChatMsg),
|
2020-10-01 00:40:46 +00:00
|
|
|
Buff {
|
2020-10-25 01:20:03 +00:00
|
|
|
entity: EcsEntity,
|
2020-10-01 02:32:38 +00:00
|
|
|
buff_change: comp::BuffChange,
|
2020-10-01 00:40:46 +00:00
|
|
|
},
|
2020-10-30 21:49:58 +00:00
|
|
|
EnergyChange {
|
2020-11-02 00:26:01 +00:00
|
|
|
entity: EcsEntity,
|
2020-10-30 21:49:58 +00:00
|
|
|
change: comp::EnergyChange,
|
|
|
|
},
|
2019-08-07 15:39:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-25 14:49:54 +00:00
|
|
|
pub struct EventBus<E> {
|
|
|
|
queue: Mutex<VecDeque<E>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<E> Default for EventBus<E> {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
queue: Mutex::new(VecDeque::new()),
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 15:39:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-25 14:49:54 +00:00
|
|
|
impl<E> EventBus<E> {
|
|
|
|
pub fn emitter(&self) -> Emitter<E> {
|
2019-08-07 15:39:16 +00:00
|
|
|
Emitter {
|
|
|
|
bus: self,
|
|
|
|
events: VecDeque::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-22 04:49:32 +00:00
|
|
|
pub fn emit_now(&self, event: E) { self.queue.lock().push_back(event); }
|
2019-08-07 17:17:04 +00:00
|
|
|
|
2019-08-25 14:49:54 +00:00
|
|
|
pub fn recv_all(&self) -> impl ExactSizeIterator<Item = E> {
|
2019-08-15 22:19:54 +00:00
|
|
|
std::mem::replace(self.queue.lock().deref_mut(), VecDeque::new()).into_iter()
|
2019-08-07 15:39:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-25 14:49:54 +00:00
|
|
|
pub struct Emitter<'a, E> {
|
|
|
|
bus: &'a EventBus<E>,
|
|
|
|
events: VecDeque<E>,
|
2019-08-07 15:39:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-25 14:49:54 +00:00
|
|
|
impl<'a, E> Emitter<'a, E> {
|
2020-03-22 04:49:32 +00:00
|
|
|
pub fn emit(&mut self, event: E) { self.events.push_back(event); }
|
2020-02-03 21:02:32 +00:00
|
|
|
|
|
|
|
pub fn append(&mut self, other: &mut VecDeque<E>) { self.events.append(other) }
|
2019-08-07 15:39:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-25 14:49:54 +00:00
|
|
|
impl<'a, E> Drop for Emitter<'a, E> {
|
2020-02-01 20:39:39 +00:00
|
|
|
fn drop(&mut self) { self.bus.queue.lock().append(&mut self.events); }
|
2019-08-07 15:39:16 +00:00
|
|
|
}
|