Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Commit

Permalink
Fix rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Ezro committed Jun 20, 2022
1 parent 6de22e7 commit 27346bd
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 163 deletions.
9 changes: 5 additions & 4 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from char.basic_ranged import Basic_Ranged
from ui_manager import wait_until_hidden, wait_until_visible, ScreenObjects, is_visible, detect_screen_object
from ui import meters, skills, view, character_select, main_menu
from ui.skills import SkillName
from inventory import personal, vendor, belt, common

from run import Pindle, ShenkEld, Trav, Nihlathak, Arcane, Diablo
Expand Down Expand Up @@ -272,12 +273,12 @@ def on_start_from_town(self):
hotkeys.discover_hotkey_mappings(saved_games_folder, key_file)
self._hotkeys_discovered = True
self._char.discover_capabilities()
teleport_selected = skills.select_tp(hotkeys.right_skill_key_map[skills.SkillName.Teleport])
teleport_selected = skills.select_tp(hotkeys.right_skill_key_map[SkillName.Teleport])
if corpse_present and self._char.capabilities.can_teleport_with_charges and not teleport_selected:
keybind = hotkeys.right_skill_key_map[skills.SkillName.Teleport]
keybind = hotkeys.right_skill_key_map[SkillName.Teleport]
Logger.info(f"Teleport keybind is lost upon death. Rebinding teleport to '{keybind}'")
hotkeys.remap_skill_hotkey(
skills.SkillName.Teleport.value,
SkillName.Teleport.value,
keybind,
Config().ui_roi["skill_right"],
Config().ui_roi["skill_right_expanded"]
Expand Down Expand Up @@ -378,7 +379,7 @@ def on_maintenance(self):
# Check if we are out of tps or need repairing
need_repair = is_visible(ScreenObjects.NeedRepair)
need_routine_repair = False if not Config().char["runs_per_repair"] else self._game_stats._run_counter % Config().char["runs_per_repair"] == 0
teleport_selected = skills.select_tp(hotkeys.right_skill_key_map[skills.SkillName.Teleport])
teleport_selected = skills.select_tp(hotkeys.right_skill_key_map[SkillName.Teleport])
need_refill_teleport = self._char.capabilities.can_teleport_with_charges and (not teleport_selected or self._char.is_low_on_teleport_charges())
if need_repair or need_routine_repair or need_refill_teleport or sell_items:
if need_repair:
Expand Down
12 changes: 6 additions & 6 deletions src/char/barbarian.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _cast_war_cry(self, time_in_s: float):
keyboard.send(hotkeys.d2r_keymap[hotkeys.HotkeyName.StandStill], do_release=False)
wait(0.05, 0.1)
if SkillName.WarCry in hotkeys.right_skill_key_map:
keyboard.send(hotkeys.right_skill_map[SkillName.WarCry])
keyboard.send(hotkeys.right_skill_key_map[SkillName.WarCry])
wait(0.05, 0.1)
start = time.time()
while (time.time() - start) < time_in_s:
Expand All @@ -45,7 +45,7 @@ def on_capabilities_discovered(self, capabilities: CharacterCapabilities):
def _do_hork(self, hork_time: int):
wait(0.5)
if SkillName.FindItem in hotkeys.right_skill_key_map:
keyboard.send(hotkeys.right_skill_map[SkillName.FindItem])
keyboard.send(hotkeys.right_skill_key_map[SkillName.FindItem])
wait(0.5, 0.15)
pos_m = convert_abs_to_monitor((0, -20))
mouse.move(*pos_m)
Expand All @@ -56,15 +56,15 @@ def _do_hork(self, hork_time: int):
wait(1)

def pre_buff(self):
keyboard.send(hotkeys.right_skill_map[SkillName.BattleCommand])
keyboard.send(hotkeys.right_skill_key_map[SkillName.BattleCommand])
wait(0.08, 0.19)
mouse.click(button="right")
wait(self._cast_duration + 0.08, self._cast_duration + 0.1)
keyboard.send(hotkeys.right_skill_map[SkillName.BattleOrders])
keyboard.send(hotkeys.right_skill_key_map[SkillName.BattleOrders])
wait(0.08, 0.19)
mouse.click(button="right")
wait(self._cast_duration + 0.08, self._cast_duration + 0.1)
keyboard.send(hotkeys.right_skill_map[SkillName.Shout])
keyboard.send(hotkeys.right_skill_key_map[SkillName.Shout])
wait(0.08, 0.19)
mouse.click(button="right")
wait(self._cast_duration + 0.08, self._cast_duration + 0.1)
Expand All @@ -76,7 +76,7 @@ def pre_move(self):
should_cast_leap = SkillName.Leap in hotkeys.right_skill_key_map and not is_left_skill_selected(SkillName.Leap.value)
can_teleport = self.capabilities.can_teleport_natively and is_right_skill_active()
if should_cast_leap and not can_teleport:
keyboard.send(hotkeys.right_skill_map[SkillName.Leap])
keyboard.send(hotkeys.right_skill_key_map[SkillName.Leap])
wait(0.15, 0.25)

def _move_and_attack(self, abs_move: tuple[int, int], atk_len: float):
Expand Down
4 changes: 2 additions & 2 deletions src/char/bone_necro.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def bone_wall(self, cast_pos_abs: tuple[float, float], spray: int):
if SkillName.BoneWall not in hotkeys.right_skill_key_map:
raise ValueError("You did not set bone_wall hotkey!")
keyboard.send(hotkeys.d2r_keymap[hotkeys.HotkeyName.StandStill], do_release=False)
keyboard.send(hotkeys.right_skill_map[SkillName.BoneWall])
keyboard.send(hotkeys.right_skill_key_map[SkillName.BoneWall])
wait(0.02, 0.08)
x = cast_pos_abs[0] + (random.random() * 2*spray - spray)
y = cast_pos_abs[1] + (random.random() * 2*spray - spray)
Expand Down Expand Up @@ -84,7 +84,7 @@ def _corpse_explosion(self, cast_pos_abs: tuple[float, float], spray: int = 10,c
Logger.debug(f'casting corpse explosion {cast_count} times with spray = {spray}')
for _ in range(cast_count):
if SkillName.CorpseExplosion in hotkeys.right_skill_key_map:
keyboard.send(hotkeys.right_skill_map[SkillName.CorpseExplosion])
keyboard.send(hotkeys.right_skill_key_map[SkillName.CorpseExplosion])
x = cast_pos_abs[0] + (random.random() * 2*spray - spray)
y = cast_pos_abs[1] + (random.random() * 2*spray - spray)
cast_pos_monitor = convert_abs_to_monitor((x, y))
Expand Down
44 changes: 14 additions & 30 deletions src/char/i_char.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
from char.capabilities import CharacterCapabilities
from ui_manager import is_visible, wait_until_visible
from ui import skills
from ui.skills import SkillName
from utils import hotkeys
from utils.hotkeys import HotkeyName
from utils.custom_mouse import mouse
from utils.misc import wait, cut_roi, is_in_roi, color_filter, arc_spread
from logger import Logger
Expand Down Expand Up @@ -37,11 +39,11 @@ def __init__(self, skill_hotkeys: dict):
def _set_active_skill(self, mouse_click_type: str = "left", skill: str =""):
self._active_skill[mouse_click_type] = skill

def _select_skill(self, skill: skills.SkillName, mouse_click_type: str = "left", delay: float | list | tuple = None):
def _select_skill(self, skill: SkillName, mouse_click_type: str = "left", delay: float | list | tuple = None):
if skill not in hotkeys.right_skill_key_map:
Logger.warning(f"No hotkey for skill: {skill.value}")
return False
keyboard.send(hotkeys.d2r_keymap[skill])
keyboard.send(hotkeys.right_skill_key_map[skill])
self._set_active_skill(mouse_click_type, skill.value)
if delay:
try:
Expand All @@ -56,8 +58,8 @@ def _select_skill(self, skill: skills.SkillName, mouse_click_type: str = "left",
def _discover_capabilities(self) -> CharacterCapabilities:
override = Config().advanced_options["override_capabilities"]
if override is None:
if skills.SkillName.Teleport in hotkeys.right_skill_key_map:
if skills.select_tp(hotkeys.right_skill_key_map[skills.SkillName.Teleport]):
if SkillName.Teleport in hotkeys.right_skill_key_map:
if skills.select_tp(hotkeys.right_skill_key_map[SkillName.Teleport]):
if self.skill_is_charged():
return CharacterCapabilities(can_teleport_natively=False, can_teleport_with_charges=True)
else:
Expand Down Expand Up @@ -146,36 +148,18 @@ def is_low_on_teleport_charges(self):
Logger.error("is_low_on_teleport_charges: unable to determine skill charges, assume zero")
return True

def _remap_skill_hotkey(self, skill_asset, hotkey, skill_roi, expanded_skill_roi):
x, y, w, h = skill_roi
x, y = convert_screen_to_monitor((x, y))
mouse.move(x + w/2, y + h / 2)
mouse.click("left")
wait(0.3)
match = template_finder.search(skill_asset, grab(), threshold=0.84, roi=expanded_skill_roi)
if match.valid:
mouse.move(*match.center_monitor)
wait(0.3)
keyboard.send(hotkey)
wait(0.3)
mouse.click("left")
wait(0.3)

def remap_right_skill_hotkey(self, skill_asset, hotkey):
return self._remap_skill_hotkey(skill_asset, hotkey, Config().ui_roi["skill_right"], Config().ui_roi["skill_right_expanded"])

def select_teleport(self):
return skills.select_tp(hotkeys.right_skill_key_map[SkillName.Teleport])

def pre_move(self):
# if teleport hotkey is set and if teleport is not already selected
if skills.SkillName.Teleport in hotkeys.right_skill_key_map:
skills.select_tp(hotkeys.right_skill_key_map[skills.SkillName.Teleport])
if SkillName.Teleport in hotkeys.right_skill_key_map:
skills.select_tp(hotkeys.right_skill_key_map[SkillName.Teleport])
self._set_active_skill("right", "teleport")

def move(self, pos_monitor: tuple[float, float], force_tp: bool = False, force_move: bool = False):
factor = Config().advanced_options["pathing_delay_factor"]
if skills.SkillName.Teleport in hotkeys.right_skill_key_map and force_tp:
if SkillName.Teleport in hotkeys.right_skill_key_map and force_tp:
self._set_active_skill("right", "teleport")
mouse.move(pos_monitor[0], pos_monitor[1], randomize=3, delay_factor=[factor*0.1, factor*0.14])
wait(0.012, 0.02)
Expand Down Expand Up @@ -264,14 +248,14 @@ def _pre_buff_cta(self):
# Try to switch weapons and select bo until we find the skill on the right skill slot
start = time.time()
switch_sucess = False
if skills.SkillName.BattleCommand not in hotkeys.right_skill_key_map:
if SkillName.BattleCommand not in hotkeys.right_skill_key_map:
return
while time.time() - start < 4:
keyboard.send(hotkeys.d2r_keymap[HotkeyName.SwapWeapons])
wait(0.3, 0.35)
keyboard.send(hotkeys.right_skill_key_map[skills.SkillName.BattleCommand])
keyboard.send(hotkeys.right_skill_key_map[SkillName.BattleCommand])
wait(0.15)
if skills.is_right_skill_selected([skills.SkillName.BattleCommand.value, skills.SkillName.BattleOrders.value]):
if skills.is_right_skill_selected([SkillName.BattleCommand.value, SkillName.BattleOrders.value]):
switch_sucess = True
break
if not switch_sucess:
Expand All @@ -281,7 +265,7 @@ def _pre_buff_cta(self):
# We switched succesfully, let's pre buff
mouse.click(button="right")
wait(self._cast_duration + 0.16, self._cast_duration + 0.18)
self._select_skill(skill = skills.SkillName.BattleOrders, mouse_click_type="right", delay=(0.1, 0.2))
self._select_skill(skill = SkillName.BattleOrders, mouse_click_type="right", delay=(0.1, 0.2))
mouse.click(button="right")
wait(self._cast_duration + 0.16, self._cast_duration + 0.18)

Expand All @@ -306,7 +290,7 @@ def vec_to_monitor(self, target):
def _lerp(self,a: float,b: float, f:float):
return a + f * (b - a)

def cast_in_arc(self, skill_name: skills.SkillName, cast_pos_abs: tuple[float, float] = [0,-100], time_in_s: float = 3, spread_deg: float = 10, hold=True):
def cast_in_arc(self, skill_name: SkillName, cast_pos_abs: tuple[float, float] = [0,-100], time_in_s: float = 3, spread_deg: float = 10, hold=True):
#scale cast time by damage_scaling
time_in_s *= self.damage_scaling
Logger.debug(f'Casting {skill_name.value} for {time_in_s:.02f}s at {cast_pos_abs} with {spread_deg}°')
Expand Down
20 changes: 10 additions & 10 deletions src/char/necro.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def _revive(self, cast_pos_abs: tuple[float, float], spray: int = 10, cast_count
return
keyboard.send(hotkeys.d2r_keymap[hotkeys.HotkeyName.StandStill], do_release=False)
for _ in range(cast_count):
keyboard.send(hotkeys.right_skill_map[SkillName.Revive])
keyboard.send(hotkeys.right_skill_key_map[SkillName.Revive])
#Logger.info("revive -> cast")
x = cast_pos_abs[0] + (random.random() * 2*spray - spray)
y = cast_pos_abs[1] + (random.random() * 2*spray - spray)
Expand Down Expand Up @@ -188,7 +188,7 @@ def _raise_skeleton(self, cast_pos_abs: tuple[float, float], spray: int = 10, ca
return
keyboard.send(hotkeys.d2r_keymap[hotkeys.HotkeyName.StandStill], do_release=False)
for _ in range(cast_count):
keyboard.send(hotkeys.right_skill_map[SkillName.RaiseSkeleton])
keyboard.send(hotkeys.right_skill_key_map[SkillName.RaiseSkeleton])
#Logger.info("raise skeleton -> cast")
x = cast_pos_abs[0] + (random.random() * 2*spray - spray)
y = cast_pos_abs[1] + (random.random() * 2*spray - spray)
Expand Down Expand Up @@ -218,7 +218,7 @@ def _raise_mage(self, cast_pos_abs: tuple[float, float], spray: int = 10, cast_c
return
keyboard.send(hotkeys.d2r_keymap[hotkeys.HotkeyName.StandStill], do_release=False)
for _ in range(cast_count):
keyboard.send(hotkeys.right_skill_map[SkillName.RaiseSkeletalMage])
keyboard.send(hotkeys.right_skill_key_map[SkillName.RaiseSkeletalMage])
#Logger.info("raise skeleton -> cast")
x = cast_pos_abs[0] + (random.random() * 2*spray - spray)
y = cast_pos_abs[1] + (random.random() * 2*spray - spray)
Expand Down Expand Up @@ -255,34 +255,34 @@ def pre_buff(self):

def _heart_of_wolverine(self):
Logger.info('\033[94m'+"buff ~> heart_of_wolverine"+'\033[0m')
keyboard.send(hotkeys.right_skill_map[SkillName.HeartOfWolverine])
keyboard.send(hotkeys.right_skill_key_map[SkillName.HeartOfWolverine])
wait(0.05, 0.2)
mouse.click(button="right")
wait(self._cast_duration)

def _clay_golem(self):
Logger.info('\033[94m'+"cast ~> clay golem"+'\033[0m')
keyboard.send(hotkeys.right_skill_map[SkillName.ClayGolem])
keyboard.send(hotkeys.right_skill_key_map[SkillName.ClayGolem])
wait(0.05, 0.2)
mouse.click(button="right")
wait(self._cast_duration)


def bone_armor(self):
if SkillName.BoneArmor in hotkeys.right_skill_key_map:
keyboard.send(hotkeys.right_skill_map[SkillName.BoneArmor])
keyboard.send(hotkeys.right_skill_key_map[SkillName.BoneArmor])
wait(0.04, 0.1)
mouse.click(button="right")
wait(self._cast_duration)
if SkillName.ClayGolem in hotkeys.right_skill_key_map:
keyboard.send(hotkeys.right_skill_map[SkillName.ClayGolem])
keyboard.send(hotkeys.right_skill_key_map[SkillName.ClayGolem])
wait(0.04, 0.1)
mouse.click(button="right")
wait(self._cast_duration)

def _bone_armor(self):
if SkillName.BoneArmor in hotkeys.right_skill_key_map:
keyboard.send(hotkeys.right_skill_map[SkillName.BoneArmor])
keyboard.send(hotkeys.right_skill_key_map[SkillName.BoneArmor])
wait(0.04, 0.1)
mouse.click(button="right")
wait(self._cast_duration)
Expand Down Expand Up @@ -321,7 +321,7 @@ def _left_attack_single(self, cast_pos_abs: tuple[float, float], spray: int = 10

def _amp_dmg(self, cast_pos_abs: tuple[float, float], spray: float = 10):
if SkillName.AmplifyDamage in hotkeys.right_skill_key_map:
keyboard.send(hotkeys.right_skill_map[SkillName.AmplifyDamage])
keyboard.send(hotkeys.right_skill_key_map[SkillName.AmplifyDamage])

x = cast_pos_abs[0] + (random.random() * 2*spray - spray)
y = cast_pos_abs[1] + (random.random() * 2*spray - spray)
Expand All @@ -336,7 +336,7 @@ def _corpse_explosion(self, cast_pos_abs: tuple[float, float], spray: int = 10,c
Logger.info('\033[93m'+"corpse explosion~> random cast"+'\033[0m')
for _ in range(cast_count):
if SkillName.CorpseExplosion in hotkeys.right_skill_key_map:
keyboard.send(hotkeys.right_skill_map[SkillName.CorpseExplosion])
keyboard.send(hotkeys.right_skill_key_map[SkillName.CorpseExplosion])
x = cast_pos_abs[0] + (random.random() * 2*spray - spray)
y = cast_pos_abs[1] + (random.random() * 2*spray - spray)
cast_pos_monitor = convert_abs_to_monitor((x, y))
Expand Down
8 changes: 4 additions & 4 deletions src/char/paladin/fohdin.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def kill_pindle(self) -> bool:
if not self._pather.traverse_nodes([103], self, timeout=1.0, do_pre_move=False, force_move=True, force_tp=False, use_tp_charge=False):
return False
else:
keyboard.send(hotkeys.right_skill_map[SkillName.Conviction])
keyboard.send(hotkeys.right_skill_key_map[SkillName.Conviction])
wait(0.15)
self._pather.traverse_nodes([103], self, timeout=1.0, do_pre_move=False)

Expand All @@ -120,7 +120,7 @@ def kill_pindle(self) -> bool:
if self.capabilities.can_teleport_natively:
self._pather.traverse_nodes_fixed("pindle_end", self)
else:
keyboard.send(hotkeys.right_skill_map[SkillName.Redemption])
keyboard.send(hotkeys.right_skill_key_map[SkillName.Redemption])
wait(0.15)
self._pather.traverse_nodes((Location.A5_PINDLE_SAFE_DIST, Location.A5_PINDLE_END), self, timeout=1.0, do_pre_move=False)

Expand All @@ -134,7 +134,7 @@ def kill_pindle(self) -> bool:
def kill_council(self) -> bool:
atk_len_dur = float(Config().char["atk_len_trav"])

keyboard.send(hotkeys.right_skill_map[SkillName.Conviction])
keyboard.send(hotkeys.right_skill_key_map[SkillName.Conviction])
wait(.15)
# traverse to nodes and attack
nodes = [225, 226, 300]
Expand Down Expand Up @@ -175,7 +175,7 @@ def kill_shenk(self):
atk_len_dur = float(Config().char["atk_len_shenk"])

# traverse to shenk
keyboard.send(hotkeys.right_skill_map[SkillName.Conviction])
keyboard.send(hotkeys.right_skill_key_map[SkillName.Conviction])
wait(0.15)
self._pather.traverse_nodes((Location.A5_SHENK_SAFE_DIST, Location.A5_SHENK_END), self, timeout=1.0, do_pre_move=False, force_tp=True, use_tp_charge=True)
wait(0.05, 0.1)
Expand Down
Loading

0 comments on commit 27346bd

Please sign in to comment.