diff options
author | Daniel Schadt <kingdread@gmx.de> | 2019-05-15 04:49:15 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2019-05-15 04:49:15 +0200 |
commit | 32bf6396a65e9aa83f746b964ed822fd5f839773 (patch) | |
tree | 6d1c0c5ce693b1f4f862be2e5d03cef34670408e /src/event.rs | |
parent | 59e18747cbb50f78d79a19e2edf8ba0f634161c3 (diff) | |
download | evtclib-32bf6396a65e9aa83f746b964ed822fd5f839773.tar.gz evtclib-32bf6396a65e9aa83f746b964ed822fd5f839773.tar.bz2 evtclib-32bf6396a65e9aa83f746b964ed822fd5f839773.zip |
add support for Event::Guild parsing
Diffstat (limited to 'src/event.rs')
-rw-r--r-- | src/event.rs | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/event.rs b/src/event.rs index bafa43c..ce4f815 100644 --- a/src/event.rs +++ b/src/event.rs @@ -1,6 +1,9 @@ use super::raw; +use std::io; + use num_traits::FromPrimitive; +use byteorder::{BigEndian, WriteBytesExt}; /// A rusty enum for all possible combat events. /// @@ -102,6 +105,13 @@ pub enum EventKind { longest_stack: i32, removal: raw::CbtBuffRemove, }, + + /// Guild identification + Guild { + source_agent_addr: u64, + raw_bytes: [u8; 16], + api_guild_id: Option<String>, + }, } /// A higher-level representation of a combat event. @@ -199,8 +209,13 @@ impl Event { reward_id: raw_event.dst_agent, reward_type: raw_event.value, }, + CbtStateChange::Guild => EventKind::Guild { + source_agent_addr: raw_event.src_agent, + raw_bytes: get_guild_id_bytes(raw_event), + api_guild_id: get_api_guild_string(&get_guild_id_bytes(raw_event)), + }, // XXX: implement proper handling of those events! - CbtStateChange::BuffInitial | CbtStateChange::Position | CbtStateChange::Velocity | CbtStateChange::Facing | CbtStateChange::TeamChange | CbtStateChange::AttackTarget | CbtStateChange::Targetable | CbtStateChange::MapId | CbtStateChange::ReplInfo | CbtStateChange::StackActive | CbtStateChange::StackReset | CbtStateChange::Guild=> { + CbtStateChange::BuffInitial | CbtStateChange::Position | CbtStateChange::Velocity | CbtStateChange::Facing | CbtStateChange::TeamChange | CbtStateChange::AttackTarget | CbtStateChange::Targetable | CbtStateChange::MapId | CbtStateChange::ReplInfo | CbtStateChange::StackActive | CbtStateChange::StackReset => { return None } @@ -298,6 +313,27 @@ fn check_damage(raw_event: &raw::CbtEvent) -> Option<EventKind> { } } +fn get_guild_id_bytes(raw_event: &raw::CbtEvent) -> [u8; 16] { + let mut result = [0; 16]; + let mut cursor = io::Cursor::new(&mut result as &mut [u8]); + cursor.write_u64::<BigEndian>(raw_event.dst_agent).unwrap(); + cursor.write_i32::<BigEndian>(raw_event.value).unwrap(); + cursor.write_i32::<BigEndian>(raw_event.buff_dmg).unwrap(); + result +} + +fn get_api_guild_string(bytes: &[u8; 16]) -> Option<String> { + if bytes == &[0; 16] { + return None; + } + let result = format!( + "{:02X}{:02X}{:02X}{:02X}-{:02X}{:02X}-{:02X}{:02X}-{:02X}{:02X}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}", + bytes[4], bytes[5], bytes[6], bytes[7], bytes[2], bytes[3], bytes[0], bytes[1], bytes[11], + bytes[10], bytes[9], bytes[8], bytes[15], bytes[14], bytes[13], bytes[12] + ); + Some(result) +} + /// The different weapon-sets in game. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum WeaponSet { |