Convert into Possessor for /into_npc

This commit is contained in:
juliancoffee 2024-02-02 15:17:58 +02:00
parent 7e2f219de1
commit 0caa54bf5b

View File

@ -676,6 +676,39 @@ fn handle_into_npc(
args: Vec<String>,
action: &ServerChatCommand,
) -> CmdResult<()> {
// Black magic
use crate::IdMaps;
use comp::{Presence, PresenceKind};
let id_to_drop = {
let ecs = server.state.ecs();
let presences = ecs.read_storage::<Presence>();
let presence = presences.get(target);
if let Some(PresenceKind::Character(character_id)) = presence.map(|p| p.kind) {
Some(character_id)
} else {
None
}
};
{
if let Some(id) = id_to_drop {
server
.state
.mut_resource::<IdMaps>()
.remove_entity(Some(target), None, Some(id), None);
}
}
{
let ecs_mut = server.state.ecs_mut();
let mut presences = ecs_mut.write_storage::<Presence>();
if let Some(presence) = presences.get_mut(target) {
presence.kind = PresenceKind::Possessor;
}
}
// End of black magic
if client != target {
server.notify_client(
client,