Add functions to properly handle IDs of entities

This commit is contained in:
Nobody 2022-02-04 22:56:54 +05:00
parent 7cd3c6bae6
commit 1c70db7459

View File

@ -10,6 +10,9 @@ impl IdManager {
const PROUD_SKILL_MULT: u32 = 100;
const PROUD_SKILL_OFFSET: u32 = 1;
const ENTITY_ID_OFFSET: u32 = 24;
const ENTITY_ID_MASK: u32 = ((1<<Self::ENTITY_ID_OFFSET)-1); //0xFFFFFF;
pub fn get_avatar_id_by_char_id(character_id: u32) -> u32 {
if (character_id > 100) {
panic!("Invalid character ID: {}", character_id);
@ -32,4 +35,15 @@ impl IdManager {
return character_id * Self::DEPOT_ID_MULT + offset;
}
pub fn get_entity_type_by_id(entity_id: u32) -> proto::ProtEntityType {
match proto::ProtEntityType::from_i32((entity_id >> Self::ENTITY_ID_OFFSET) as i32) {
Some(t) => t,
None => panic!("Invalid entity ID {}: can't figure out type!", entity_id),
}
}
pub fn get_entity_id_by_type_and_sub_id(t: &proto::ProtEntityType, sub_id: u32) -> u32 {
return ((*t as u32) << Self::ENTITY_ID_OFFSET) | (sub_id & Self::ENTITY_ID_MASK);
}
}