mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Remove is_stay function
Clean code
This commit is contained in:
parent
6f0997705f
commit
9597810e3d
@ -1477,7 +1477,7 @@ impl Client {
|
|||||||
|
|
||||||
pub fn unmount(&mut self) { self.send_msg(ClientGeneral::ControlEvent(ControlEvent::Unmount)); }
|
pub fn unmount(&mut self) { self.send_msg(ClientGeneral::ControlEvent(ControlEvent::Unmount)); }
|
||||||
|
|
||||||
pub fn toggle_stay(&mut self, entity: EcsEntity){
|
pub fn toggle_stay(&mut self, entity: EcsEntity) {
|
||||||
if let Some(uid) = self.state.read_component_copied(entity) {
|
if let Some(uid) = self.state.read_component_copied(entity) {
|
||||||
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::ToggleStay(uid)));
|
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::ToggleStay(uid)));
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,6 @@ synced_components!(reexport_comps);
|
|||||||
|
|
||||||
use crate::sync::{NetSync, SyncFrom};
|
use crate::sync::{NetSync, SyncFrom};
|
||||||
|
|
||||||
|
|
||||||
// These are synced from any entity within range.
|
// These are synced from any entity within range.
|
||||||
impl NetSync for PetStates {
|
impl NetSync for PetStates {
|
||||||
const SYNC_FROM: SyncFrom = SyncFrom::AnyEntity;
|
const SYNC_FROM: SyncFrom = SyncFrom::AnyEntity;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use crate::comp::{body::Body, phys::Mass, quadruped_medium, quadruped_small};
|
use crate::comp::{body::Body, phys::Mass, quadruped_medium, quadruped_small};
|
||||||
use crossbeam_utils::atomic::AtomicCell;
|
use crossbeam_utils::atomic::AtomicCell;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use specs::{Component, DerefFlaggedStorage};
|
use specs::{Component, DerefFlaggedStorage};
|
||||||
use std::{num::NonZeroU64, sync::Arc};
|
use std::{num::NonZeroU64, sync::Arc};
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
pub type PetId = AtomicCell<Option<NonZeroU64>>;
|
pub type PetId = AtomicCell<Option<NonZeroU64>>;
|
||||||
|
|
||||||
@ -109,24 +109,17 @@ impl Component for Pet {
|
|||||||
type Storage = specs::VecStorage<Self>;
|
type Storage = specs::VecStorage<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub enum StayFollow{
|
pub enum StayFollow {
|
||||||
Stay,
|
Stay,
|
||||||
Follow,
|
Follow,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, Default)]
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, Default)]
|
||||||
pub struct PetState{
|
pub struct PetState {
|
||||||
pub stay: bool,
|
pub stay: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PetState {
|
|
||||||
pub fn get_state(&self) -> bool{
|
|
||||||
self.stay
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for PetState {
|
impl Component for PetState {
|
||||||
type Storage = DerefFlaggedStorage<Self>;
|
type Storage = DerefFlaggedStorage<Self>;
|
||||||
}
|
}
|
||||||
|
@ -65,11 +65,12 @@ 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
|
||||||
.uid_allocator
|
.id_maps
|
||||||
.retrieve_entity_internal(pet_uid.id()){
|
.uid_entity(pet_uid)
|
||||||
|
{
|
||||||
server_emitter.emit(ServerEvent::ToggleStay(pet_entity));
|
server_emitter.emit(ServerEvent::ToggleStay(pet_entity));
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
ControlEvent::RemoveBuff(buff_id) => {
|
ControlEvent::RemoveBuff(buff_id) => {
|
||||||
server_emitter.emit(ServerEvent::Buff {
|
server_emitter.emit(ServerEvent::Buff {
|
||||||
entity,
|
entity,
|
||||||
|
@ -12,9 +12,10 @@ use common::{
|
|||||||
},
|
},
|
||||||
slot::EquipSlot,
|
slot::EquipSlot,
|
||||||
},
|
},
|
||||||
|
pet::PetState,
|
||||||
ActiveAbilities, Alignment, Body, CharacterState, Combo, Energy, Health, Inventory,
|
ActiveAbilities, Alignment, Body, CharacterState, Combo, Energy, Health, Inventory,
|
||||||
LightEmitter, LootOwner, Ori, PhysicsState, Poise, Pos, Presence, Scale, SkillSet, Stance,
|
LightEmitter, LootOwner, Ori, PhysicsState, Poise, Pos, Presence, Scale, SkillSet, Stance,
|
||||||
Stats, Vel, pet::PetState,
|
Stats, Vel,
|
||||||
},
|
},
|
||||||
consts::GRAVITY,
|
consts::GRAVITY,
|
||||||
link::Is,
|
link::Is,
|
||||||
|
@ -202,15 +202,23 @@ pub fn handle_unmount(server: &mut Server, rider: EcsEntity) {
|
|||||||
state.ecs().write_storage::<Is<VolumeRider>>().remove(rider);
|
state.ecs().write_storage::<Is<VolumeRider>>().remove(rider);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_toggle_stay(server: &mut Server, pet: EcsEntity){
|
pub fn handle_toggle_stay(server: &mut Server, pet: EcsEntity) {
|
||||||
let state = server.state_mut();
|
let state = server.state_mut();
|
||||||
if state.ecs()
|
if state
|
||||||
|
.ecs()
|
||||||
.read_storage::<PetState>()
|
.read_storage::<PetState>()
|
||||||
.get(pet)
|
.get(pet)
|
||||||
.map_or(false, |s| s.stay){
|
.map_or(false, |s| s.stay)
|
||||||
let _ = state.ecs().write_storage::<PetState>().insert(pet, PetState { stay: false });
|
{
|
||||||
|
let _ = state
|
||||||
|
.ecs()
|
||||||
|
.write_storage::<PetState>()
|
||||||
|
.insert(pet, PetState { stay: false });
|
||||||
} else {
|
} else {
|
||||||
let _ = state.ecs().write_storage::<PetState>().insert(pet, PetState { stay: true });
|
let _ = state
|
||||||
|
.ecs()
|
||||||
|
.write_storage::<PetState>()
|
||||||
|
.insert(pet, PetState { stay: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ use group_manip::handle_group;
|
|||||||
use information::handle_site_info;
|
use information::handle_site_info;
|
||||||
use interaction::{
|
use interaction::{
|
||||||
handle_create_sprite, handle_lantern, handle_mine_block, handle_mount, handle_npc_interaction,
|
handle_create_sprite, handle_lantern, handle_mine_block, handle_mount, handle_npc_interaction,
|
||||||
handle_sound, handle_unmount, handle_toggle_stay,
|
handle_sound, handle_toggle_stay, handle_unmount,
|
||||||
};
|
};
|
||||||
use inventory_manip::handle_inventory;
|
use inventory_manip::handle_inventory;
|
||||||
use invite::{handle_invite, handle_invite_response};
|
use invite::{handle_invite, handle_invite_response};
|
||||||
|
@ -160,8 +160,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
.map_or(false, |item| {
|
.map_or(false, |item| {
|
||||||
matches!(&*item.kind(), comp::item::ItemKind::Glider)
|
matches!(&*item.kind(), comp::item::ItemKind::Glider)
|
||||||
});
|
});
|
||||||
let is_stay = pet_state
|
let is_stay = pet_state.map_or(false, |s| s.stay);
|
||||||
.map_or(false, |s| s.stay);
|
|
||||||
|
|
||||||
let is_gliding = matches!(
|
let is_gliding = matches!(
|
||||||
read_data.char_states.get(entity),
|
read_data.char_states.get(entity),
|
||||||
|
@ -408,7 +408,7 @@ fn follow_if_far_away(bdata: &mut BehaviorData) -> bool {
|
|||||||
if let Some(tgt_pos) = bdata.read_data.positions.get(target) {
|
if let Some(tgt_pos) = bdata.read_data.positions.get(target) {
|
||||||
let dist_sqrd = bdata.agent_data.pos.0.distance_squared(tgt_pos.0);
|
let dist_sqrd = bdata.agent_data.pos.0.distance_squared(tgt_pos.0);
|
||||||
let stay = bdata.agent_data.is_stay;
|
let stay = bdata.agent_data.is_stay;
|
||||||
if dist_sqrd > (MAX_PATROL_DIST * bdata.agent.psyche.idle_wander_factor).powi(2) && !stay{
|
if dist_sqrd > (MAX_PATROL_DIST * bdata.agent.psyche.idle_wander_factor).powi(2) && !stay {
|
||||||
bdata
|
bdata
|
||||||
.agent_data
|
.agent_data
|
||||||
.follow(bdata.agent, bdata.controller, bdata.read_data, tgt_pos);
|
.follow(bdata.agent, bdata.controller, bdata.read_data, tgt_pos);
|
||||||
@ -432,7 +432,7 @@ fn attack_if_owner_hurt(bdata: &mut BehaviorData) -> bool {
|
|||||||
false
|
false
|
||||||
};
|
};
|
||||||
let stay = bdata.agent_data.is_stay;
|
let stay = bdata.agent_data.is_stay;
|
||||||
if owner_recently_attacked && !stay{
|
if owner_recently_attacked && !stay {
|
||||||
bdata.agent_data.attack_target_attacker(
|
bdata.agent_data.attack_target_attacker(
|
||||||
bdata.agent,
|
bdata.agent,
|
||||||
bdata.read_data,
|
bdata.read_data,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use common::{
|
use common::{
|
||||||
comp::{Alignment, Pet, PhysicsState, Pos, pet::PetState},
|
comp::{pet::PetState, Alignment, Pet, PhysicsState, Pos},
|
||||||
terrain::TerrainGrid,
|
terrain::TerrainGrid,
|
||||||
uid::IdMaps,
|
uid::IdMaps,
|
||||||
};
|
};
|
||||||
|
@ -2317,7 +2317,6 @@ impl Hud {
|
|||||||
poise,
|
poise,
|
||||||
(alignment, is_mount, is_rider, stance),
|
(alignment, is_mount, is_rider, stance),
|
||||||
)| {
|
)| {
|
||||||
|
|
||||||
// Use interpolated position if available
|
// Use interpolated position if available
|
||||||
let pos = interpolated.map_or(pos.0, |i| i.pos);
|
let pos = interpolated.map_or(pos.0, |i| i.pos);
|
||||||
let in_group = client.group_members().contains_key(uid);
|
let in_group = client.group_members().contains_key(uid);
|
||||||
@ -2433,31 +2432,21 @@ impl Hud {
|
|||||||
i18n.get_msg("hud-mount").to_string(),
|
i18n.get_msg("hud-mount").to_string(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
let p = entity;
|
let pet_stay = is_stay.get(entity).map(|st| st.stay);
|
||||||
|
match pet_stay {
|
||||||
let s = is_stay.get(p)
|
Some(false) => options.push((
|
||||||
.map(|st| st.stay);
|
|
||||||
match s {
|
|
||||||
Some(false) => {
|
|
||||||
options.push((
|
|
||||||
GameInput::StayFollow,
|
GameInput::StayFollow,
|
||||||
i18n.get_msg("hud-stay").to_string(),
|
i18n.get_msg("hud-stay").to_string(),
|
||||||
))
|
)),
|
||||||
},
|
Some(true) => options.push((
|
||||||
Some(true) => {
|
|
||||||
options.push((
|
|
||||||
GameInput::StayFollow,
|
GameInput::StayFollow,
|
||||||
i18n.get_msg("hud-follow").to_string(),
|
i18n.get_msg("hud-follow").to_string(),
|
||||||
))
|
)),
|
||||||
},
|
None => options.push((
|
||||||
None => {
|
|
||||||
options.push((
|
|
||||||
GameInput::StayFollow,
|
GameInput::StayFollow,
|
||||||
i18n.get_msg("hud-stay").to_string(),
|
i18n.get_msg("hud-stay").to_string(),
|
||||||
))
|
)),
|
||||||
},
|
|
||||||
}
|
}
|
||||||
options
|
options
|
||||||
},
|
},
|
||||||
|
@ -963,12 +963,10 @@ impl PlayState for SessionState {
|
|||||||
*dist_sqr < MAX_MOUNT_RANGE.powi(2)
|
*dist_sqr < MAX_MOUNT_RANGE.powi(2)
|
||||||
})
|
})
|
||||||
.min_by_key(|(_, dist_sqr)| OrderedFloat(*dist_sqr));
|
.min_by_key(|(_, dist_sqr)| OrderedFloat(*dist_sqr));
|
||||||
if let Some((pet_entity, _)) = closest_pet
|
if let Some((pet_entity, _)) = closest_pet {
|
||||||
{
|
|
||||||
client.toggle_stay(pet_entity);
|
client.toggle_stay(pet_entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
GameInput::Interact => {
|
GameInput::Interact => {
|
||||||
if state {
|
if state {
|
||||||
|
Loading…
Reference in New Issue
Block a user