Skip to content

Commit

Permalink
Update for arc event changes & improve doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerthox committed Jul 3, 2024
1 parent 9bb3064 commit c716a38
Show file tree
Hide file tree
Showing 20 changed files with 783 additions and 394 deletions.
2 changes: 1 addition & 1 deletion evtc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "evtc"
version = "0.8.0"
version = "0.9.0"
authors = ["Zerthox"]
edition = "2021"
description = "Rust bindings for the ArcDPS EVTC API"
Expand Down
40 changes: 40 additions & 0 deletions evtc/src/agent/attack_target.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use crate::{extract::Extract, AgentId, Event, StateChange, TryExtract};

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// Agent is now an attack target.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct AttackTargetEvent {
/// Time of registering the attack target.
pub time: u64,

/// Agent that is an attack target.
pub agent: AgentId,

/// Parent gadget agent.
pub parent: AgentId,

/// Current targetable state.
pub targetable: bool,
}

impl Extract for AttackTargetEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
Self {
time: event.time,
agent: AgentId::from_src(event),
parent: AgentId::from_dst(event),
targetable: event.value != 0,
}
}
}

impl TryExtract for AttackTargetEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
event.get_statechange() == StateChange::AttackTarget
}
}
47 changes: 47 additions & 0 deletions evtc/src/agent/combat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use crate::{
extract::Extract, AgentId, Event, Profession, Specialization, StateChange, TryExtract,
};
use std::mem;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// Agent entered combat.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct EnterCombatEvent {
/// Time of registering the combat enter.
pub time: u64,

/// Agent that entered combat.
pub agent: AgentId,

/// Agent subgroup.
pub subgroup: u64,

/// Agent profession.
pub profession: Profession,

/// Agent elite specialization.
pub elite: Specialization,
}

impl Extract for EnterCombatEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
Self {
time: event.time,
agent: AgentId::from_src(event),
subgroup: event.dst_agent,
profession: unsafe { mem::transmute::<i32, u32>(event.value) }.into(),
elite: unsafe { mem::transmute::<i32, u32>(event.buff_dmg) }.into(),
}
}
}

impl TryExtract for EnterCombatEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
event.get_statechange() == StateChange::EnterCombat
}
}
35 changes: 35 additions & 0 deletions evtc/src/agent/glider.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use crate::{extract::Extract, AgentId, Event, StateChange, TryExtract};

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// Agent gliding state change.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct GliderEvent {
/// Time of registering the gliding state.
pub time: u64,

/// Agent that changed gliding state.
pub agent: AgentId,

pub deployed: bool,
}

impl Extract for GliderEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
Self {
time: event.time,
agent: AgentId::from_src(event),
deployed: event.value != 0,
}
}
}

impl TryExtract for GliderEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
event.get_statechange() == StateChange::Glider
}
}
110 changes: 110 additions & 0 deletions evtc/src/agent/health.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
use crate::{extract::Extract, AgentId, Event, StateChange, TryExtract};

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// Agent max health change.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct MaxHealthEvent {
/// Time of registering the max health change.
pub time: u64,

/// Agent that had their max health changed.
pub agent: AgentId,

/// New agent max health.
pub max_health: u64,
}

impl Extract for MaxHealthEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
Self {
time: event.time,
agent: AgentId::from_src(event),
max_health: event.dst_agent,
}
}
}

impl TryExtract for MaxHealthEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
event.get_statechange() == StateChange::MaxHealthUpdate
}
}

/// Agent health percent change.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct HealthUpdateEvent {
/// Time of registering the health percent change.
pub time: u64,

/// Agent that had their health percent changed.
pub agent: AgentId,

/// Current health percent with `1.0` being max.
pub health: f32,
}

impl HealthUpdateEvent {
/// Conversion ratio.
pub const CONVERT: f32 = 10_000.0;
}

impl Extract for HealthUpdateEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
Self {
time: event.time,
agent: AgentId::from_src(event),
health: event.dst_agent as f32 / Self::CONVERT,
}
}
}

impl TryExtract for HealthUpdateEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
event.get_statechange() == StateChange::HealthUpdate
}
}

/// Agent barrier percent change.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BarrierUpdateEvent {
/// Time of registering the barrier change.
pub time: u64,

/// Agent that had their current barrier changed.
pub agent: AgentId,

/// Current barrier percent with `1.0` being max.
pub barrier: f32,
}

impl BarrierUpdateEvent {
/// Conversion ratio.
pub const CONVERT: f32 = 10_000.0;
}

impl Extract for BarrierUpdateEvent {
#[inline]
unsafe fn extract(event: &Event) -> Self {
Self {
time: event.time,
agent: AgentId::from_src(event),
barrier: event.dst_agent as f32 / Self::CONVERT,
}
}
}

impl TryExtract for BarrierUpdateEvent {
#[inline]
fn can_extract(event: &Event) -> bool {
event.get_statechange() == StateChange::BarrierUpdate
}
}
15 changes: 10 additions & 5 deletions evtc/src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@

mod affinity;
mod agent_kind;
mod attack_target;
mod breakbar;
mod combat;
mod glider;
mod health;
mod id;
mod status;
mod targetable;
mod team;

pub use self::affinity::*;
pub use self::agent_kind::*;
pub use self::breakbar::*;
pub use self::id::*;
pub use self::status::*;
pub use self::{
affinity::*, agent_kind::*, attack_target::*, breakbar::*, combat::*, glider::*, health::*,
id::*, status::*, targetable::*, team::*,
};
Loading

0 comments on commit c716a38

Please sign in to comment.