mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added range check to mounting
This commit is contained in:
parent
a556d2b5e7
commit
95163a5a65
@ -3,7 +3,8 @@ use crate::{
|
|||||||
Server,
|
Server,
|
||||||
};
|
};
|
||||||
use common::{
|
use common::{
|
||||||
comp::{self, item},
|
comp::{self, item, Pos},
|
||||||
|
consts::MAX_MOUNT_RANGE,
|
||||||
msg::ServerGeneral,
|
msg::ServerGeneral,
|
||||||
sync::{Uid, WorldSyncExt},
|
sync::{Uid, WorldSyncExt},
|
||||||
};
|
};
|
||||||
@ -65,7 +66,12 @@ pub fn handle_mount(server: &mut Server, mounter: EcsEntity, mountee: EcsEntity)
|
|||||||
Some(comp::MountState::Unmounted)
|
Some(comp::MountState::Unmounted)
|
||||||
);
|
);
|
||||||
|
|
||||||
if not_mounting_yet {
|
let within_range = within_mounting_range(
|
||||||
|
state.ecs().read_storage::<comp::Pos>().get(mounter),
|
||||||
|
state.ecs().read_storage::<comp::Pos>().get(mountee),
|
||||||
|
);
|
||||||
|
|
||||||
|
if not_mounting_yet && within_range {
|
||||||
if let (Some(mounter_uid), Some(mountee_uid)) = (
|
if let (Some(mounter_uid), Some(mountee_uid)) = (
|
||||||
state.ecs().uid_from_entity(mounter),
|
state.ecs().uid_from_entity(mounter),
|
||||||
state.ecs().uid_from_entity(mountee),
|
state.ecs().uid_from_entity(mountee),
|
||||||
@ -193,3 +199,10 @@ pub fn handle_possess(server: &Server, possessor_uid: Uid, possesse_uid: Uid) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn within_mounting_range(player_position: Option<&Pos>, mount_position: Option<&Pos>) -> bool {
|
||||||
|
match (player_position, mount_position) {
|
||||||
|
(Some(ppos), Some(ipos)) => ppos.0.distance_squared(ipos.0) < MAX_MOUNT_RANGE.powi(2),
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user