mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'fix-611' into 'master'
fix #611; add distance check when mounting pet Closes #611 See merge request veloren/veloren!1208
This commit is contained in:
commit
9195c06c95
@ -43,7 +43,7 @@ pub use last::Last;
|
||||
pub use location::{Waypoint, WaypointArea};
|
||||
pub use misc::Object;
|
||||
pub use phys::{Collider, ForceUpdate, Gravity, Mass, Ori, PhysicsState, Pos, Scale, Sticky, Vel};
|
||||
pub use player::Player;
|
||||
pub use player::{Player, MAX_MOUNT_RANGE_SQR};
|
||||
pub use projectile::Projectile;
|
||||
pub use skills::{Skill, SkillGroup, SkillGroupType, SkillSet};
|
||||
pub use stats::{Exp, HealthChange, HealthSource, Level, Stats};
|
||||
|
@ -4,6 +4,7 @@ use specs::{Component, FlaggedStorage, NullStorage};
|
||||
use specs_idvs::IdvStorage;
|
||||
|
||||
const MAX_ALIAS_LEN: usize = 32;
|
||||
pub const MAX_MOUNT_RANGE_SQR: i32 = 20000;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Player {
|
||||
|
@ -15,7 +15,10 @@ use common::{
|
||||
assets::{load_expect, load_watched, watch},
|
||||
clock::Clock,
|
||||
comp,
|
||||
comp::{ChatMsg, ChatType, InventoryUpdateEvent, Pos, Vel, MAX_PICKUP_RANGE_SQR},
|
||||
comp::{
|
||||
ChatMsg, ChatType, InventoryUpdateEvent, Pos, Vel, MAX_MOUNT_RANGE_SQR,
|
||||
MAX_PICKUP_RANGE_SQR,
|
||||
},
|
||||
event::EventBus,
|
||||
msg::ClientState,
|
||||
terrain::{Block, BlockKind},
|
||||
@ -430,25 +433,36 @@ impl PlayState for SessionState {
|
||||
.copied();
|
||||
if let Some(player_pos) = player_pos {
|
||||
// Find closest mountable entity
|
||||
let closest_mountable = (
|
||||
let mut closest_mountable: Option<(specs::Entity, i32)> = None;
|
||||
|
||||
for (entity, pos, ms) in (
|
||||
&client.state().ecs().entities(),
|
||||
&client.state().ecs().read_storage::<comp::Pos>(),
|
||||
&client.state().ecs().read_storage::<comp::MountState>(),
|
||||
)
|
||||
.join()
|
||||
.filter(|(_, _, ms)| {
|
||||
if let comp::MountState::Unmounted = ms {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
.min_by_key(|(_, pos, _)| {
|
||||
(player_pos.0.distance_squared(pos.0) * 1000.0) as i32
|
||||
})
|
||||
.map(|(uid, _, _)| uid);
|
||||
.filter(|(entity, _, _)| *entity != client.entity())
|
||||
{
|
||||
if comp::MountState::Unmounted != *ms {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(mountee_entity) = closest_mountable {
|
||||
let dist =
|
||||
(player_pos.0.distance_squared(pos.0) * 1000.0) as i32;
|
||||
if dist > MAX_MOUNT_RANGE_SQR {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(previous) = closest_mountable.as_mut() {
|
||||
if dist < previous.1 {
|
||||
*previous = (entity, dist);
|
||||
}
|
||||
} else {
|
||||
closest_mountable = Some((entity, dist));
|
||||
}
|
||||
}
|
||||
|
||||
if let Some((mountee_entity, _)) = closest_mountable {
|
||||
client.mount(mountee_entity);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user