Skip to content

Commit

Permalink
Fix overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerthox committed Sep 20, 2023
1 parent 0fbf24c commit f8a3fa2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ fn main() {
} = skill;
let hits = quote_option(hits);
let expected = quote_option(expected);
let max_duration = quote_option(max_duration);
quote! {
SkillDef {
id: #id,
Expand Down
16 changes: 8 additions & 8 deletions src/data/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use serde::{Deserialize, Serialize};
// TODO: instead of hits allow counting buff apply?
// TODO: support instant casts with buff apply?

/// Extra error margin for max duration.
const DURATION_EPSILON: i32 = 500;

/// Skill information.
#[derive(Debug, Clone)]
pub struct SkillInfo {
Expand Down Expand Up @@ -37,7 +40,9 @@ impl From<SkillDef> for SkillInfo {
max,
expected: expected.unwrap_or((max + 1) / 2),
}),
max_duration,
max_duration: max_duration
.map(|dur| dur + DURATION_EPSILON)
.unwrap_or(i32::MAX),
minion,
}
}
Expand Down Expand Up @@ -74,18 +79,13 @@ pub struct SkillDef {
pub expected: Option<usize>,

/// Maximum duration (ms) to count as one cast.
#[serde(default = "default_as_max")]
pub max_duration: i32,
pub max_duration: Option<i32>,

/// Whether to include minion hits.
#[serde(default)]
pub minion: bool,
}

const fn default_as_true() -> bool {
fn default_as_true() -> bool {
true
}

const fn default_as_max() -> i32 {
i32::MAX
}
5 changes: 1 addition & 4 deletions src/plugin/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ use crate::combat::{
use arcdps::{evtc::EventKind, Activation, Agent, CombatEvent, StateChange, Strike};
use log::debug;

/// Extra error margin for max duration.
const DURATION_EPSILON: i32 = 500;

impl Plugin {
/// Handles a combat event from area stats.
pub fn area_event(
Expand Down Expand Up @@ -205,7 +202,7 @@ impl Plugin {
// replace skill id
skill.id = info.id;

let max = info.max_duration + DURATION_EPSILON;
let max = info.max_duration;
match self.latest_cast_mut(skill.id) {
Some(cast) if time - cast.time <= max => {
cast.hit(target);
Expand Down

0 comments on commit f8a3fa2

Please sign in to comment.