Skip to content

Commit

Permalink
support: adds self heal spell and await heal casting 500ms
Browse files Browse the repository at this point in the history
  • Loading branch information
Slyker committed Apr 8, 2024
1 parent e2ed459 commit d2c7370
Showing 1 changed file with 75 additions and 69 deletions.
144 changes: 75 additions & 69 deletions src-tauri/src/behavior/support_behavior.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::time::{Duration, Instant};
use std::time::{ Duration, Instant };

use slog::Logger;
use tauri::Window;
Expand All @@ -8,9 +8,9 @@ use super::Behavior;
use crate::{
data::Point,
image_analyzer::ImageAnalyzer,
ipc::{BotConfig, FrontendInfo, SlotType, SupportConfig},
movement::{prelude::*, MovementAccessor},
platform::{eval_simple_click, send_slot_eval},
ipc::{ BotConfig, FrontendInfo, SlotType, SupportConfig },
movement::{ prelude::*, MovementAccessor },
platform::{ eval_simple_click, send_slot_eval },
play,
};

Expand Down Expand Up @@ -76,13 +76,13 @@ impl<'a> Behavior<'a> for SupportBehavior<'a> {
&mut self,
_frontend_info: &mut FrontendInfo,
config: &BotConfig,
image: &mut ImageAnalyzer,
image: &mut ImageAnalyzer
) {
let config = config.support_config();
self.has_target = image.client_stats.target_is_mover;
self.update_slots_usage(config);
self.use_party_skills(config);
self.check_restorations(config, image, false);
self.check_self_restorations(config, image);
if self.has_target == false {
if config.is_in_party() {
self.select_party_leader(config);
Expand All @@ -93,7 +93,7 @@ impl<'a> Behavior<'a> for SupportBehavior<'a> {
if self.is_waiting_for_revive {
if image.client_stats.target_hp.value > 0 {
self.is_waiting_for_revive = false;
self.check_restorations(config, image, true);
self.check_target_restorations(config, image);
} else {
return;
}
Expand All @@ -119,7 +119,7 @@ impl<'a> Behavior<'a> for SupportBehavior<'a> {
None,
SlotType::BuffSkill,
false,
Some(self.self_buff_usage_last_time),
Some(self.self_buff_usage_last_time)
);

self.send_buff(config, self_buff, true);
Expand Down Expand Up @@ -169,11 +169,7 @@ impl SupportBehavior<'_> {
]);

self.avoid_obstacle_direction = {
if self.avoid_obstacle_direction == "D" {
"A".to_owned()
} else {
"D".to_owned()
}
if self.avoid_obstacle_direction == "D" { "A".to_owned() } else { "D".to_owned() }
};
}
fn is_target_in_range(&mut self, config: &SupportConfig, image: &mut ImageAnalyzer) -> bool {
Expand All @@ -190,8 +186,9 @@ impl SupportBehavior<'_> {
self.move_circle_pattern();
} else {
if let Some(last_far_from_target) = self.last_far_from_target {
if last_far_from_target.elapsed().as_millis() > 3000
&& last_target_distance < distance
if
last_far_from_target.elapsed().as_millis() > 3000 &&
last_target_distance < distance
{
self.last_far_from_target = Some(Instant::now());
self.move_circle_pattern();
Expand All @@ -216,7 +213,7 @@ impl SupportBehavior<'_> {
&mut self,
config: &SupportConfig,
buff: Option<(usize, usize)>,
is_self_buff: bool,
is_self_buff: bool
) {
if buff.is_some() {
if is_self_buff {
Expand Down Expand Up @@ -358,14 +355,10 @@ impl SupportBehavior<'_> {
threshold: Option<u32>,
slot_type: SlotType,
send: bool,
last_slots_usage: Option<[[Option<Instant>; 10]; 9]>,
last_slots_usage: Option<[[Option<Instant>; 10]; 9]>
) -> Option<(usize, usize)> {
let is_self_buff = {
if let Some(_) = last_slots_usage {
true
} else {
false
}
if let Some(_) = last_slots_usage { true } else { false }
};
let slot_usage = {
if let Some(last_slots_usage) = last_slots_usage {
Expand Down Expand Up @@ -395,65 +388,78 @@ impl SupportBehavior<'_> {
}

fn use_party_skills(&mut self, config: &SupportConfig) {
let party_skills =
config.get_all_usable_slot_for_type(SlotType::PartySkill, self.slots_usage_last_time);
let party_skills = config.get_all_usable_slot_for_type(
SlotType::PartySkill,
self.slots_usage_last_time
);
for slot_index in party_skills {
self.send_slot(slot_index, false);
}
}

fn check_restorations(
&mut self,
config: &SupportConfig,
image: &mut ImageAnalyzer,
target_only: bool,
) {
if target_only == false {
let health_stat = Some(image.client_stats.hp.value);
// Use a HealSkill if configured when health is under 85
let pill = self.get_slot_for(config, health_stat, SlotType::Pill, true, None);
if pill.is_none() {
let heal = self.get_slot_for(config, health_stat, SlotType::HealSkill, true, None);
if heal.is_none() {
let aoe_heal =
self.get_slot_for(config, health_stat, SlotType::AOEHealSkill, true, None);
if aoe_heal.is_none() {
self.get_slot_for(config, health_stat, SlotType::Food, true, None);
} else {
std::thread::sleep(Duration::from_millis(100));
self.get_slot_for(config, health_stat, SlotType::AOEHealSkill, true, None);
std::thread::sleep(Duration::from_millis(100));
self.get_slot_for(config, health_stat, SlotType::AOEHealSkill, true, None);
}
fn check_self_restorations(&mut self, config: &SupportConfig, image: &mut ImageAnalyzer) {
let health_stat = Some(image.client_stats.hp.value);
// Use a HealSkill if configured when health is under 85
let pill = self.get_slot_for(config, health_stat, SlotType::Pill, true, None);
if pill.is_none() {
let heal = self.get_slot_for(config, health_stat, SlotType::HealSkill, false, None);
if heal.is_none() {
let aoe_heal = self.get_slot_for(
config,
health_stat,
SlotType::AOEHealSkill,
true,
None
);
if aoe_heal.is_none() {
self.get_slot_for(config, health_stat, SlotType::Food, true, None);
} else {
std::thread::sleep(Duration::from_millis(100));
self.get_slot_for(config, health_stat, SlotType::AOEHealSkill, true, None);
std::thread::sleep(Duration::from_millis(100));
self.get_slot_for(config, health_stat, SlotType::AOEHealSkill, true, None);
}
} else {
if config.is_in_party() {
self.lose_target();
std::thread::sleep(Duration::from_millis(5));
}
self.send_slot(heal.unwrap(), false);
self.wait(Duration::from_millis(500));
}

// Check MP
let mp_stat = Some(image.client_stats.mp.value);
self.get_slot_for(config, mp_stat, SlotType::MpRestorer, true, None);
// Check MP
let mp_stat = Some(image.client_stats.mp.value);
self.get_slot_for(config, mp_stat, SlotType::MpRestorer, true, None);

// Check FP
// Check FP

let fp_stat = Some(image.client_stats.fp.value);
self.get_slot_for(config, fp_stat, SlotType::FpRestorer, true, None);
}
let fp_stat = Some(image.client_stats.fp.value);
self.get_slot_for(config, fp_stat, SlotType::FpRestorer, true, None);
}
}

if self.has_target == false {
return;
}
//Check target HP
let target_hp = Some(image.client_stats.target_hp.value);
fn check_target_restorations(&mut self, config: &SupportConfig, image: &mut ImageAnalyzer) {
let target_health_stat = Some(image.client_stats.target_hp.value);
// Use a HealSkill if configured when health is under 85

if image.client_stats.target_hp.value > 0 {
let heal_skill =
self.get_slot_for(config, target_hp, SlotType::HealSkill, true, None);
if heal_skill.is_none() {
let aoe_skill =
self.get_slot_for(config, target_hp, SlotType::AOEHealSkill, true, None);
if aoe_skill.is_some() {
std::thread::sleep(Duration::from_millis(200));
}
}
let heal = self.get_slot_for(config, target_health_stat, SlotType::HealSkill, true, None);
if heal.is_none() {
let aoe_heal = self.get_slot_for(
config,
target_health_stat,
SlotType::AOEHealSkill,
true,
None
);
if aoe_heal.is_some() {
self.get_slot_for(config, target_health_stat, SlotType::AOEHealSkill, true, None);
std::thread::sleep(Duration::from_millis(100));
self.get_slot_for(config, target_health_stat, SlotType::AOEHealSkill, true, None);
std::thread::sleep(Duration::from_millis(100));
}
} else {
self.wait(Duration::from_millis(500));
}
}
}

0 comments on commit d2c7370

Please sign in to comment.