mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
portal event -> change body and teleport to
This commit is contained in:
parent
8fe5f2e708
commit
26ada89bb9
@ -4,11 +4,6 @@ use vek::Vec3;
|
||||
|
||||
use crate::resources::{Secs, Time};
|
||||
|
||||
pub enum TeleporterEvent {
|
||||
PortalTeleport { entity: Entity, target: Vec3<f32> },
|
||||
SetPortalActive { portal: Entity, active: bool },
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Teleporter {
|
||||
pub target: Vec3<f32>,
|
||||
|
@ -332,7 +332,10 @@ pub enum ServerEvent {
|
||||
RemoveLightEmitter {
|
||||
entity: EcsEntity,
|
||||
},
|
||||
PortalEvent(comp::teleport::TeleporterEvent),
|
||||
TeleportToPosition {
|
||||
entity: EcsEntity,
|
||||
position: Vec3<f32>,
|
||||
},
|
||||
}
|
||||
|
||||
pub struct EventBus<E> {
|
||||
|
@ -21,8 +21,6 @@ use common::{
|
||||
inventory::item::{AbilityMap, MaterialStatManifest},
|
||||
item::flatten_counted_items,
|
||||
loot_owner::LootOwnerKind,
|
||||
object,
|
||||
teleport::TeleporterEvent,
|
||||
Alignment, Auras, Body, CharacterState, Energy, Group, Health, HealthChange, Inventory,
|
||||
Player, Poise, Pos, SkillSet, Stats,
|
||||
},
|
||||
@ -1659,30 +1657,19 @@ pub fn handle_remove_light_emitter(server: &mut Server, entity: EcsEntity) {
|
||||
.remove(entity);
|
||||
}
|
||||
|
||||
pub fn handle_portal_event(server: &mut Server, event: TeleporterEvent) {
|
||||
pub fn handle_teleport_to_position_event(
|
||||
server: &mut Server,
|
||||
entity: EcsEntity,
|
||||
position: Vec3<f32>,
|
||||
) {
|
||||
let ecs = server.state.ecs();
|
||||
|
||||
match event {
|
||||
TeleporterEvent::PortalTeleport { entity, target } => {
|
||||
ecs.write_storage::<comp::Pos>()
|
||||
.get_mut(entity)
|
||||
.map(|old_position| {
|
||||
old_position.0 = target;
|
||||
});
|
||||
ecs.write_storage::<comp::ForceUpdate>()
|
||||
.get_mut(entity)
|
||||
.map(|forced_update| forced_update.update());
|
||||
},
|
||||
TeleporterEvent::SetPortalActive { portal, active } => {
|
||||
ecs.write_storage::<comp::Body>()
|
||||
.get_mut(portal)
|
||||
.map(|mut body| {
|
||||
*body = comp::body::Body::Object(if active {
|
||||
object::Body::PortalActive
|
||||
} else {
|
||||
object::Body::Portal
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
ecs.write_storage::<comp::Pos>()
|
||||
.get_mut(entity)
|
||||
.map(|old_position| {
|
||||
old_position.0 = position;
|
||||
});
|
||||
ecs.write_storage::<comp::ForceUpdate>()
|
||||
.get_mut(entity)
|
||||
.map(|forced_update| forced_update.update());
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
events::{
|
||||
entity_creation::handle_create_teleporter,
|
||||
entity_manipulation::handle_portal_event,
|
||||
entity_manipulation::handle_teleport_to_position_event,
|
||||
interaction::{handle_mount_volume, handle_tame_pet},
|
||||
},
|
||||
persistence::PersistedComponents,
|
||||
@ -300,7 +300,9 @@ impl Server {
|
||||
ServerEvent::RemoveLightEmitter { entity } => {
|
||||
handle_remove_light_emitter(self, entity)
|
||||
},
|
||||
ServerEvent::PortalEvent(event) => handle_portal_event(self, event),
|
||||
ServerEvent::TeleportToPosition { entity, position } => {
|
||||
handle_teleport_to_position_event(self, entity, position)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,5 @@
|
||||
use common::{
|
||||
comp::{
|
||||
object, teleport::TeleporterEvent, Agent, Body, CharacterState, Player, Pos, Teleporter,
|
||||
Teleporting,
|
||||
},
|
||||
comp::{object, Agent, Body, CharacterState, Player, Pos, Teleporter, Teleporting},
|
||||
event::{EventBus, ServerEvent},
|
||||
resources::Time,
|
||||
CachedSpatialGrid,
|
||||
@ -56,15 +53,6 @@ impl<'a> System<'a> for Sys {
|
||||
event_bus,
|
||||
): Self::SystemData,
|
||||
) {
|
||||
let mut player_data = (
|
||||
&entities,
|
||||
&positions,
|
||||
&players,
|
||||
&character_states,
|
||||
teleporting.entries(),
|
||||
)
|
||||
.join();
|
||||
|
||||
let check_aggro = |entity, pos: Vec3<f32>| {
|
||||
spatial_grid
|
||||
.0
|
||||
@ -87,6 +75,15 @@ impl<'a> System<'a> for Sys {
|
||||
|
||||
let mut is_active = false;
|
||||
|
||||
let mut player_data = (
|
||||
&entities,
|
||||
&positions,
|
||||
&players,
|
||||
&character_states,
|
||||
teleporting.entries(),
|
||||
)
|
||||
.join();
|
||||
|
||||
for (entity, pos, _, character_state, teleporting) in
|
||||
nearby_entities.filter_map(|entity| {
|
||||
player_data
|
||||
@ -120,10 +117,14 @@ impl<'a> System<'a> for Sys {
|
||||
}
|
||||
|
||||
if (*body == Body::Object(object::Body::PortalActive)) != is_active {
|
||||
event_bus.emit_now(ServerEvent::PortalEvent(TeleporterEvent::SetPortalActive {
|
||||
portal: portal_entity,
|
||||
active: is_active,
|
||||
}));
|
||||
event_bus.emit_now(ServerEvent::ChangeBody {
|
||||
entity: portal_entity,
|
||||
new_body: Body::Object(if is_active {
|
||||
object::Body::PortalActive
|
||||
} else {
|
||||
object::Body::Portal
|
||||
}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,10 +144,10 @@ impl<'a> System<'a> for Sys {
|
||||
teleporting.remove();
|
||||
} else if teleporting.get().end_time.0 <= time.0 {
|
||||
teleporting.remove();
|
||||
event_bus.emit_now(ServerEvent::PortalEvent(TeleporterEvent::PortalTeleport {
|
||||
event_bus.emit_now(ServerEvent::TeleportToPosition {
|
||||
entity,
|
||||
target: teleporter.target,
|
||||
}));
|
||||
position: teleporter.target,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user