mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
display if pet is currently following or staying
This commit is contained in:
parent
4bdbb3ff6b
commit
1ea0f249f5
@ -54,6 +54,7 @@ hud-mine-needs_unhandled_case = Needs ???
|
|||||||
hud-talk = Talk
|
hud-talk = Talk
|
||||||
hud-trade = Trade
|
hud-trade = Trade
|
||||||
hud-mount = Mount
|
hud-mount = Mount
|
||||||
hud-stay-follow = Stay/Follow
|
hud-follow = Follow
|
||||||
|
hud-stay= Stay
|
||||||
hud-sit = Sit
|
hud-sit = Sit
|
||||||
hud-steer = Steer
|
hud-steer = Steer
|
||||||
|
@ -1004,6 +1004,9 @@ pub struct CharacterActivity {
|
|||||||
/// `None` means that the look direction should be derived from the
|
/// `None` means that the look direction should be derived from the
|
||||||
/// orientation
|
/// orientation
|
||||||
pub look_dir: Option<Dir>,
|
pub look_dir: Option<Dir>,
|
||||||
|
/// If true, the owner has set this pet to stay at a fixed location and
|
||||||
|
/// to not engage in combat
|
||||||
|
pub is_pet_staying: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Component for CharacterActivity {
|
impl Component for CharacterActivity {
|
||||||
|
@ -64,10 +64,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
ControlEvent::ToggleStay(pet_uid) => {
|
ControlEvent::ToggleStay(pet_uid) => {
|
||||||
if let Some(pet_entity) = read_data
|
if let Some(pet_entity) = read_data.id_maps.uid_entity(pet_uid) {
|
||||||
.id_maps
|
|
||||||
.uid_entity(pet_uid)
|
|
||||||
{
|
|
||||||
server_emitter.emit(ServerEvent::ToggleStay(entity, pet_entity));
|
server_emitter.emit(ServerEvent::ToggleStay(entity, pet_entity));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -3,6 +3,8 @@ pub const FLEE_DURATION: f32 = 3.0;
|
|||||||
pub const NPC_PICKUP_RANGE: f32 = 2.5;
|
pub const NPC_PICKUP_RANGE: f32 = 2.5;
|
||||||
pub const MAX_PATROL_DIST: f32 = 50.0;
|
pub const MAX_PATROL_DIST: f32 = 50.0;
|
||||||
pub const MAX_PATH_DIST: f32 = 170.0;
|
pub const MAX_PATH_DIST: f32 = 170.0;
|
||||||
|
/// If the pet is any further than this value from its stay position, it will
|
||||||
|
/// start walking back there
|
||||||
pub const MAX_STAY_DISTANCE: f32 = 10.0;
|
pub const MAX_STAY_DISTANCE: f32 = 10.0;
|
||||||
pub const PARTIAL_PATH_DIST: f32 = 50.0;
|
pub const PARTIAL_PATH_DIST: f32 = 50.0;
|
||||||
pub const SEPARATION_DIST: f32 = 10.0;
|
pub const SEPARATION_DIST: f32 = 10.0;
|
||||||
|
@ -212,30 +212,38 @@ pub fn handle_unmount(server: &mut Server, rider: EcsEntity) {
|
|||||||
|
|
||||||
pub fn handle_toggle_stay(server: &mut Server, command_giver: EcsEntity, pet: EcsEntity) {
|
pub fn handle_toggle_stay(server: &mut Server, command_giver: EcsEntity, pet: EcsEntity) {
|
||||||
let state = server.state_mut();
|
let state = server.state_mut();
|
||||||
let mut is_owner = false;
|
|
||||||
let positions = state.ecs().read_storage::<Pos>();
|
let positions = state.ecs().read_storage::<Pos>();
|
||||||
if let Some(owner_uid) = state.ecs().uid_from_entity(command_giver) {
|
let is_owner = state
|
||||||
is_owner = matches!(
|
.ecs()
|
||||||
state
|
.uid_from_entity(command_giver)
|
||||||
.ecs()
|
.map_or(false, |owner_uid| {
|
||||||
.read_storage::<comp::Alignment>()
|
matches!(
|
||||||
.get(pet),
|
state
|
||||||
Some(comp::Alignment::Owned(pet_owner)) if *pet_owner == owner_uid,
|
.ecs()
|
||||||
);
|
.read_storage::<comp::Alignment>()
|
||||||
}
|
.get(pet),
|
||||||
let prev_pet_pos = state
|
Some(comp::Alignment::Owned(pet_owner)) if *pet_owner == owner_uid,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let previous_pet_pos = state
|
||||||
.ecs()
|
.ecs()
|
||||||
.read_storage::<comp::Agent>()
|
.read_storage::<comp::Agent>()
|
||||||
.get(pet)
|
.get(pet)
|
||||||
.and_then(|s| s.stay_pos);
|
.and_then(|s| s.stay_pos);
|
||||||
let mut new_pet_pos = None;
|
let new_pet_pos = previous_pet_pos
|
||||||
if prev_pet_pos.is_none() {
|
.is_none()
|
||||||
new_pet_pos = state.ecs().read_storage::<Pos>().get(pet).copied();
|
.then_some(positions.get(pet).copied())
|
||||||
}
|
.flatten();
|
||||||
if is_owner
|
if is_owner
|
||||||
&& within_mounting_range(positions.get(command_giver), positions.get(pet))
|
&& within_mounting_range(positions.get(command_giver), positions.get(pet))
|
||||||
&& state.ecs().read_storage::<Is<Mount>>().get(pet).is_none()
|
&& state.ecs().read_storage::<Is<Mount>>().get(pet).is_none()
|
||||||
{
|
{
|
||||||
|
state
|
||||||
|
.ecs()
|
||||||
|
.write_storage::<comp::CharacterActivity>()
|
||||||
|
.get_mut(pet)
|
||||||
|
.map(|mut activity| activity.is_pet_staying = new_pet_pos.is_some());
|
||||||
state
|
state
|
||||||
.ecs()
|
.ecs()
|
||||||
.write_storage::<comp::Agent>()
|
.write_storage::<comp::Agent>()
|
||||||
|
@ -406,9 +406,7 @@ fn do_pickup_loot(bdata: &mut BehaviorData) -> bool {
|
|||||||
fn follow_if_far_away(bdata: &mut BehaviorData) -> bool {
|
fn follow_if_far_away(bdata: &mut BehaviorData) -> bool {
|
||||||
if let Some(Target { target, .. }) = bdata.agent.target {
|
if let Some(Target { target, .. }) = bdata.agent.target {
|
||||||
if let Some(tgt_pos) = bdata.read_data.positions.get(target) {
|
if let Some(tgt_pos) = bdata.read_data.positions.get(target) {
|
||||||
let stay = bdata.agent.stay_pos.is_some();
|
if let Some(stay_pos) = bdata.agent.stay_pos {
|
||||||
if stay {
|
|
||||||
let stay_pos = bdata.agent.stay_pos.map_or(Pos(Vec3::zero()), |v| v);
|
|
||||||
let distance_from_stay = stay_pos.0.distance_squared(bdata.agent_data.pos.0);
|
let distance_from_stay = stay_pos.0.distance_squared(bdata.agent_data.pos.0);
|
||||||
bdata.controller.push_action(ControlAction::Sit);
|
bdata.controller.push_action(ControlAction::Sit);
|
||||||
if distance_from_stay > (MAX_STAY_DISTANCE).powi(2) {
|
if distance_from_stay > (MAX_STAY_DISTANCE).powi(2) {
|
||||||
|
@ -1505,6 +1505,7 @@ impl Hud {
|
|||||||
let is_mounts = ecs.read_storage::<Is<Mount>>();
|
let is_mounts = ecs.read_storage::<Is<Mount>>();
|
||||||
let is_riders = ecs.read_storage::<Is<Rider>>();
|
let is_riders = ecs.read_storage::<Is<Rider>>();
|
||||||
let stances = ecs.read_storage::<comp::Stance>();
|
let stances = ecs.read_storage::<comp::Stance>();
|
||||||
|
let char_activities = ecs.read_storage::<comp::CharacterActivity>();
|
||||||
let time = ecs.read_resource::<Time>();
|
let time = ecs.read_resource::<Time>();
|
||||||
|
|
||||||
// Check if there was a persistence load error of the skillset, and if so
|
// Check if there was a persistence load error of the skillset, and if so
|
||||||
@ -2271,6 +2272,7 @@ impl Hud {
|
|||||||
dist_sqr,
|
dist_sqr,
|
||||||
alignment,
|
alignment,
|
||||||
is_mount,
|
is_mount,
|
||||||
|
character_activity,
|
||||||
) in (
|
) in (
|
||||||
&entities,
|
&entities,
|
||||||
&pos,
|
&pos,
|
||||||
@ -2285,6 +2287,7 @@ impl Hud {
|
|||||||
&mut hp_floater_lists,
|
&mut hp_floater_lists,
|
||||||
&uids,
|
&uids,
|
||||||
&inventories,
|
&inventories,
|
||||||
|
char_activities.maybe(),
|
||||||
poises.maybe(),
|
poises.maybe(),
|
||||||
(
|
(
|
||||||
alignments.maybe(),
|
alignments.maybe(),
|
||||||
@ -2313,6 +2316,7 @@ impl Hud {
|
|||||||
hpfl,
|
hpfl,
|
||||||
uid,
|
uid,
|
||||||
inventory,
|
inventory,
|
||||||
|
character_activity,
|
||||||
poise,
|
poise,
|
||||||
(alignment, is_mount, is_rider, stance),
|
(alignment, is_mount, is_rider, stance),
|
||||||
)| {
|
)| {
|
||||||
@ -2375,8 +2379,22 @@ impl Hud {
|
|||||||
};
|
};
|
||||||
(info.is_some() || bubble.is_some()).then_some({
|
(info.is_some() || bubble.is_some()).then_some({
|
||||||
(
|
(
|
||||||
entity, pos, info, bubble, stats, skill_set, health, buffs, scale,
|
entity,
|
||||||
body, hpfl, in_group, dist_sqr, alignment, is_mount,
|
pos,
|
||||||
|
info,
|
||||||
|
bubble,
|
||||||
|
stats,
|
||||||
|
skill_set,
|
||||||
|
health,
|
||||||
|
buffs,
|
||||||
|
scale,
|
||||||
|
body,
|
||||||
|
hpfl,
|
||||||
|
in_group,
|
||||||
|
dist_sqr,
|
||||||
|
alignment,
|
||||||
|
is_mount,
|
||||||
|
character_activity,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@ -2431,9 +2449,18 @@ impl Hud {
|
|||||||
i18n.get_msg("hud-mount").to_string(),
|
i18n.get_msg("hud-mount").to_string(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let is_staying = character_activity
|
||||||
|
.map_or(false, |activity| activity.is_pet_staying);
|
||||||
|
|
||||||
options.push((
|
options.push((
|
||||||
GameInput::StayFollow,
|
GameInput::StayFollow,
|
||||||
i18n.get_msg("hud-stay-follow").to_string(),
|
i18n.get_msg(if is_staying {
|
||||||
|
"hud-stay"
|
||||||
|
} else {
|
||||||
|
"hud-follow"
|
||||||
|
})
|
||||||
|
.to_string(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
options
|
options
|
||||||
|
Loading…
Reference in New Issue
Block a user