* Pets are now saved on logout and spawned with the player on login

* Pets now teleport to their owner when they are too far away from them
* Limited the animals that can be tamed to `QuadrupedLow` and `QuadrupedSmall` to prevent players taming overly powerful creatures before the pet feature is further developed
* Added `Pet` component used to store pet information about an entity - currently only used to store the pet's database ID
* Added `pet` database table which stores a pet's `body_id` and `name`, alongside the `character_id` that it belongs to
* Replaced `HomeChunk` component with more flexible `Anchor` component which supports anchoring entities to other entities as well as chunks.
This commit is contained in:
Ben Wallis
2021-07-28 22:36:41 +00:00
parent 2849117a13
commit 01ca6911a9
33 changed files with 808 additions and 157 deletions

View File

@ -1045,31 +1045,12 @@ fn handle_spawn(
// Add to group system if a pet
if matches!(alignment, comp::Alignment::Owned { .. }) {
let state = server.state();
let clients = state.ecs().read_storage::<Client>();
let uids = state.ecs().read_storage::<Uid>();
let mut group_manager =
state.ecs().write_resource::<comp::group::GroupManager>();
group_manager.new_pet(
new_entity,
target,
&mut state.ecs().write_storage(),
&state.ecs().entities(),
&state.ecs().read_storage(),
&uids,
&mut |entity, group_change| {
clients
.get(entity)
.and_then(|c| {
group_change
.try_map(|e| uids.get(e).copied())
.map(|g| (g, c))
})
.map(|(g, c)| {
c.send_fallible(ServerGeneral::GroupUpdate(g));
});
},
);
let server_eventbus =
server.state.ecs().read_resource::<EventBus<ServerEvent>>();
server_eventbus.emit_now(ServerEvent::TamePet {
owner_entity: target,
pet_entity: new_entity,
});
} else if let Some(group) = match alignment {
comp::Alignment::Wild => None,
comp::Alignment::Passive => None,