mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
clean up mounting
This commit is contained in:
parent
a6b2f04518
commit
a7588e274d
@ -94,6 +94,7 @@ pub fn is_mountable(mount: &Body, rider: Option<&Body>) -> bool {
|
||||
| quadruped_low::Species::Elbst
|
||||
| quadruped_low::Species::Tortoise
|
||||
),
|
||||
Body::Ship(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
use crate::{
|
||||
comp,
|
||||
comp::{pet::is_mountable, Body},
|
||||
link::{Is, Link, LinkHandle, Role},
|
||||
terrain::TerrainGrid,
|
||||
uid::{Uid, UidAllocator},
|
||||
@ -29,6 +28,7 @@ pub struct Mounting {
|
||||
pub rider: Uid,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum MountingError {
|
||||
NoSuchEntity,
|
||||
NotMountable,
|
||||
@ -39,7 +39,6 @@ impl Link for Mounting {
|
||||
Read<'a, UidAllocator>,
|
||||
WriteStorage<'a, Is<Mount>>,
|
||||
WriteStorage<'a, Is<Rider>>,
|
||||
WriteStorage<'a, Body>,
|
||||
);
|
||||
type DeleteData<'a> = (
|
||||
Read<'a, UidAllocator>,
|
||||
@ -60,7 +59,7 @@ impl Link for Mounting {
|
||||
|
||||
fn create(
|
||||
this: &LinkHandle<Self>,
|
||||
(uid_allocator, mut is_mounts, mut is_riders, body): Self::CreateData<'_>,
|
||||
(uid_allocator, mut is_mounts, mut is_riders): Self::CreateData<'_>,
|
||||
) -> Result<(), Self::Error> {
|
||||
let entity = |uid: Uid| uid_allocator.retrieve_entity_internal(uid.into());
|
||||
|
||||
@ -68,8 +67,6 @@ impl Link for Mounting {
|
||||
// Forbid self-mounting
|
||||
Err(MountingError::NotMountable)
|
||||
} else if let Some((mount, rider)) = entity(this.mount).zip(entity(this.rider)) {
|
||||
if let Some(mount_body) = body.get(mount) {
|
||||
if is_mountable(mount_body, body.get(rider)) {
|
||||
let can_mount_with =
|
||||
|entity| is_mounts.get(entity).is_none() && is_riders.get(entity).is_none();
|
||||
|
||||
@ -82,12 +79,6 @@ impl Link for Mounting {
|
||||
} else {
|
||||
Err(MountingError::NotMountable)
|
||||
}
|
||||
} else {
|
||||
Err(MountingError::NotMountable)
|
||||
}
|
||||
} else {
|
||||
Err(MountingError::NotMountable)
|
||||
}
|
||||
} else {
|
||||
Err(MountingError::NoSuchEntity)
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ use common::{
|
||||
inventory::slot::EquipSlot,
|
||||
loot_owner::LootOwnerKind,
|
||||
tool::ToolKind,
|
||||
Inventory, LootOwner, Pos, SkillGroupKind,
|
||||
Inventory, LootOwner, Pos, SkillGroupKind, pet::is_mountable,
|
||||
},
|
||||
consts::{MAX_MOUNT_RANGE, SOUND_TRAVEL_DIST_PER_VOLUME},
|
||||
event::EventBus,
|
||||
@ -119,7 +119,12 @@ pub fn handle_mount(server: &mut Server, rider: EcsEntity, mount: EcsEntity) {
|
||||
Some(comp::Alignment::Owned(owner)) if *owner == rider_uid,
|
||||
);
|
||||
|
||||
if is_pet {
|
||||
let can_ride = state.ecs()
|
||||
.read_storage()
|
||||
.get(mount)
|
||||
.map_or(false, |mount_body| is_mountable(mount_body, state.ecs().read_storage().get(rider)));
|
||||
|
||||
if is_pet && can_ride {
|
||||
drop(uids);
|
||||
drop(healths);
|
||||
let _ = state.link(Mounting {
|
||||
|
Loading…
Reference in New Issue
Block a user