mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
review
This commit is contained in:
parent
b7c56c9057
commit
13dbf679c5
@ -1477,9 +1477,11 @@ 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 set_pet_stay(&mut self, entity: EcsEntity, stay: bool) {
|
||||||
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::SetPetStay(
|
||||||
|
uid, stay,
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ pub enum ControlEvent {
|
|||||||
Mount(Uid),
|
Mount(Uid),
|
||||||
MountVolume(VolumePos),
|
MountVolume(VolumePos),
|
||||||
Unmount,
|
Unmount,
|
||||||
ToggleStay(Uid),
|
SetPetStay(Uid, bool),
|
||||||
InventoryEvent(InventoryEvent),
|
InventoryEvent(InventoryEvent),
|
||||||
GroupManip(GroupManip),
|
GroupManip(GroupManip),
|
||||||
RemoveBuff(BuffKind),
|
RemoveBuff(BuffKind),
|
||||||
|
@ -200,7 +200,7 @@ pub enum ServerEvent {
|
|||||||
Mount(EcsEntity, EcsEntity),
|
Mount(EcsEntity, EcsEntity),
|
||||||
MountVolume(EcsEntity, VolumePos),
|
MountVolume(EcsEntity, VolumePos),
|
||||||
Unmount(EcsEntity),
|
Unmount(EcsEntity),
|
||||||
ToggleStay(EcsEntity, EcsEntity),
|
SetPetStay(EcsEntity, EcsEntity, bool),
|
||||||
Possess(Uid, Uid),
|
Possess(Uid, Uid),
|
||||||
/// Inserts default components for a character when loading into the game
|
/// Inserts default components for a character when loading into the game
|
||||||
InitCharacterData {
|
InitCharacterData {
|
||||||
|
@ -63,9 +63,9 @@ impl<'a> System<'a> for Sys {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ControlEvent::ToggleStay(pet_uid) => {
|
ControlEvent::SetPetStay(pet_uid, stay) => {
|
||||||
if let Some(pet_entity) = read_data.id_maps.uid_entity(pet_uid) {
|
if let Some(pet_entity) = read_data.id_maps.uid_entity(pet_uid) {
|
||||||
server_emitter.emit(ServerEvent::ToggleStay(entity, pet_entity));
|
server_emitter.emit(ServerEvent::SetPetStay(entity, pet_entity, stay));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ControlEvent::RemoveBuff(buff_id) => {
|
ControlEvent::RemoveBuff(buff_id) => {
|
||||||
|
@ -210,7 +210,12 @@ 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, command_giver: EcsEntity, pet: EcsEntity) {
|
pub fn handle_set_pet_stay(
|
||||||
|
server: &mut Server,
|
||||||
|
command_giver: EcsEntity,
|
||||||
|
pet: EcsEntity,
|
||||||
|
stay: bool,
|
||||||
|
) {
|
||||||
let state = server.state_mut();
|
let state = server.state_mut();
|
||||||
let positions = state.ecs().read_storage::<Pos>();
|
let positions = state.ecs().read_storage::<Pos>();
|
||||||
let is_owner = state
|
let is_owner = state
|
||||||
@ -226,15 +231,8 @@ pub fn handle_toggle_stay(server: &mut Server, command_giver: EcsEntity, pet: Ec
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let previous_pet_pos = state
|
let current_pet_position = positions.get(pet).copied();
|
||||||
.ecs()
|
let stay = stay && current_pet_position.is_some();
|
||||||
.read_storage::<comp::Agent>()
|
|
||||||
.get(pet)
|
|
||||||
.and_then(|s| s.stay_pos);
|
|
||||||
let new_pet_pos = previous_pet_pos
|
|
||||||
.is_none()
|
|
||||||
.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()
|
||||||
@ -243,12 +241,12 @@ pub fn handle_toggle_stay(server: &mut Server, command_giver: EcsEntity, pet: Ec
|
|||||||
.ecs()
|
.ecs()
|
||||||
.write_storage::<comp::CharacterActivity>()
|
.write_storage::<comp::CharacterActivity>()
|
||||||
.get_mut(pet)
|
.get_mut(pet)
|
||||||
.map(|mut activity| activity.is_pet_staying = new_pet_pos.is_some());
|
.map(|mut activity| activity.is_pet_staying = stay);
|
||||||
state
|
state
|
||||||
.ecs()
|
.ecs()
|
||||||
.write_storage::<comp::Agent>()
|
.write_storage::<comp::Agent>()
|
||||||
.get_mut(pet)
|
.get_mut(pet)
|
||||||
.map(|s| s.stay_pos = new_pet_pos);
|
.map(|s| s.stay_pos = current_pet_position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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_toggle_stay, handle_unmount,
|
handle_set_pet_stay, handle_sound, 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};
|
||||||
@ -144,8 +144,8 @@ impl Server {
|
|||||||
handle_mount_volume(self, mounter, volume)
|
handle_mount_volume(self, mounter, volume)
|
||||||
},
|
},
|
||||||
ServerEvent::Unmount(mounter) => handle_unmount(self, mounter),
|
ServerEvent::Unmount(mounter) => handle_unmount(self, mounter),
|
||||||
ServerEvent::ToggleStay(command_giver, pet) => {
|
ServerEvent::SetPetStay(command_giver, pet, stay) => {
|
||||||
handle_toggle_stay(self, command_giver, pet)
|
handle_set_pet_stay(self, command_giver, pet, stay)
|
||||||
},
|
},
|
||||||
ServerEvent::Possess(possessor_uid, possesse_uid) => {
|
ServerEvent::Possess(possessor_uid, possesse_uid) => {
|
||||||
handle_possess(self, possessor_uid, possesse_uid)
|
handle_possess(self, possessor_uid, possesse_uid)
|
||||||
|
@ -13,14 +13,14 @@ use vek::*;
|
|||||||
|
|
||||||
use client::{self, Client};
|
use client::{self, Client};
|
||||||
use common::{
|
use common::{
|
||||||
comp,
|
|
||||||
comp::{
|
comp::{
|
||||||
|
self,
|
||||||
dialogue::Subject,
|
dialogue::Subject,
|
||||||
inventory::slot::{EquipSlot, Slot},
|
inventory::slot::{EquipSlot, Slot},
|
||||||
invite::InviteKind,
|
invite::InviteKind,
|
||||||
item::{tool::ToolKind, ItemDesc},
|
item::{tool::ToolKind, ItemDesc},
|
||||||
ChatType, Content, InputKind, InventoryUpdateEvent, Pos, PresenceKind, Stats,
|
CharacterActivity, ChatType, Content, InputKind, InventoryUpdateEvent, Pos, PresenceKind,
|
||||||
UtteranceKind, Vel,
|
Stats, UtteranceKind, Vel,
|
||||||
},
|
},
|
||||||
consts::MAX_MOUNT_RANGE,
|
consts::MAX_MOUNT_RANGE,
|
||||||
event::UpdateCharacterMetadata,
|
event::UpdateCharacterMetadata,
|
||||||
@ -949,6 +949,7 @@ impl PlayState for SessionState {
|
|||||||
|
|
||||||
let mut close_pet = None;
|
let mut close_pet = None;
|
||||||
if let Some(player_pos) = player_pos {
|
if let Some(player_pos) = player_pos {
|
||||||
|
let positions = client.state().read_storage::<Pos>();
|
||||||
close_pet = client.state().ecs().read_resource::<CachedSpatialGrid>().0
|
close_pet = client.state().ecs().read_resource::<CachedSpatialGrid>().0
|
||||||
.in_circle_aabr(player_pos.0.xy(), MAX_MOUNT_RANGE)
|
.in_circle_aabr(player_pos.0.xy(), MAX_MOUNT_RANGE)
|
||||||
.filter(|e|
|
.filter(|e|
|
||||||
@ -962,9 +963,7 @@ impl PlayState for SessionState {
|
|||||||
client.state().ecs().read_storage::<Is<Mount>>().get(*e).is_none()
|
client.state().ecs().read_storage::<Is<Mount>>().get(*e).is_none()
|
||||||
)
|
)
|
||||||
.min_by_key(|e| {
|
.min_by_key(|e| {
|
||||||
OrderedFloat(client
|
OrderedFloat(positions
|
||||||
.state()
|
|
||||||
.read_storage::<Pos>()
|
|
||||||
.get(*e)
|
.get(*e)
|
||||||
.map_or(MAX_MOUNT_RANGE * MAX_MOUNT_RANGE, |x| {
|
.map_or(MAX_MOUNT_RANGE * MAX_MOUNT_RANGE, |x| {
|
||||||
player_pos.0.distance_squared(x.0)
|
player_pos.0.distance_squared(x.0)
|
||||||
@ -972,8 +971,11 @@ impl PlayState for SessionState {
|
|||||||
))
|
))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if let Some(pet_entity)= close_pet && client.state().read_storage::<Is<Mount>>().get(pet_entity).is_none() {
|
if let Some(pet_entity) = close_pet && client.state().read_storage::<Is<Mount>>().get(pet_entity).is_none() {
|
||||||
client.toggle_stay(pet_entity);
|
let is_staying = client.state()
|
||||||
|
.read_component_copied::<CharacterActivity>(pet_entity)
|
||||||
|
.map_or(false, |activity| activity.is_pet_staying);
|
||||||
|
client.set_pet_stay(pet_entity, !is_staying);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
GameInput::Interact => {
|
GameInput::Interact => {
|
||||||
|
Loading…
Reference in New Issue
Block a user