Skip to content

Commit

Permalink
fix aspects
Browse files Browse the repository at this point in the history
  • Loading branch information
aeon0 committed Nov 2, 2023
1 parent 4473baa commit a7092ea
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 47 deletions.
87 changes: 79 additions & 8 deletions config/filter_affixes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@


Filters:
# Rogue
# =====================================
- Helm:
itemType: helm
minPower: 725
Expand Down Expand Up @@ -39,16 +41,85 @@ Filters:
itemType: gloves
minPower: 725
affixPool:
- [dexterity, 10]
- [attack_speed, 7]
- [dexterity, 38]
- [lucky_hit_chance, 7.8]
- [critical_strike_chance, 5.5]
- lucky_hit_up_to_a_chance_to_slow
- [ranks_of_twisting_blades, 3]
- [ranks_of_rapid_fire, 3]
minAffixCount: 3

- Boots:
itemType: boots
minPower: 725
affixPool:
- [movement_speed, 16]
- [dexterity, 40]
- [dodge_chance, 5]
- [energy_cost_reduction, 6]
minAffixCount: 3

- Amulet:
itemType: amulet
minPower: 725
affixPool:
- [cooldown_reduction, 6]
- [damage_reduction, 6.7]
- [damage_reduction_from_close_enemies, 10]
- [damage_reduction_from_distant_enemies, 12]
- [damage_reduction, 5]
- [total_armor, 9]
- [maximum_life, 700]
- [energy_cost_reduction, 6]
- [movement_speed, 14]
- [ranks_of_all_imbuement_skills, 2]
- [ranks_of_the_exploit_passive, 2]
- [ranks_of_the_weapon_mastery_passive, 2]
- [ranks_of_the_malice_passive, 2]
- [ranks_of_the_frigid_finesse_passive, 2]
- [ranks_of_the_deadly_venom_passive, 2]
minAffixCount: 3

# Example take all boots and rings
- TakeAll:
itemType: [boots]
minPower: 0
- Ring:
itemType: ring
minPower: 725
affixPool:
minAffixCount: 0
- [critical_strike_chance, 4]
- [lucky_hit_chance, 5]
- [resource_generation, 8]
- [maximum_life, 680]
- [damage_to_crowd_controlled_enemies, 9]
minAffixCount: 3

- WeaponClose:
itemType: [dagger, sword]
minPower: 915
affixPool:
- [all_stats, 22]
- [dexterity, 44]
- [core_skill_damage, 17]
- [damage_to_close_enemies, 19]
- [vulnerable_damage, 16]
minAffixCount: 3

- WeaponFar:
itemType: [crossbow]
minPower: 725
affixPool:
- [all_stats, 44]
- [dexterity, 90]
- [core_skill_damage, 25]
- [damage_to_close_enemies, 37]
- [vulnerable_damage, 34]
minAffixCount: 3

# Sorc
- Focus:
itemType: [focus]
minPower: 725
affixPool:
- [cooldown_reduction, 5]
- [resource_generation, 8]
- [critical_strike_chance, 3]
- [lucky_hit_chance, 5]
- [mana_cost_reduction, 5]
minAffixCount: 3
53 changes: 37 additions & 16 deletions config/filter_aspects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,45 @@
# CONDITON can be "larger" or "smaller" and defaults to "larger"

Aspects:
- [accelerating_aspect, 25]
- [aspect_of_disobedience, 0.5]
- [aspect_of_might, 20]
- aspect_of_artful_initiative
- [aspect_of_the_expectant, 9]
- [aspect_of_the_umbral, 4]
# General
- [accelerating_aspect, 24]
- [aspect_of_might, 5.5]
- [aspect_of_disobedience, 1.1]
- [aspect_of_inner_calm, 10]
- [aspect_of_retribution, 20]
- [aspect_of_the_expectant, 10]
- [edgemasters_aspect, 20]
- [rapid_aspect, 29]
- [aspect_of_corruption, 40]
- [aspect_of_shared_misery, 48]
- [ghostwalker_aspect, 25]
- [aspect_of_the_umbral, 4]
- [conceited_aspect, 25]
- [starlight_aspect, 35]

# Rogue
- [aspect_of_artful_initiative]
- [aspect_of_bursting_venoms]
- [aspect_of_corruption, 39]
- [aspect_of_elusive_menace, 7]
- [aspect_of_noxious_ice, 20]
- aspect_of_quickening_fog
- aspect_of_surprise
- [aspect_of_pestilent_points, 140]
- [aspect_of_noxious_ice, 29]
- [aspect_of_quickening_fog, 0.6]
- [aspect_of_repeating, 45]
- [bladedancers_aspect, 14]
- [aspect_of_surprise]
- [assimilation_aspect, 8]
- [cheats_aspect, 24]
- [energizing_aspect, 7]
- frostbitten_aspect
- ravagers_aspect
- shadowslicer_aspect
- snap_frozen_aspect
- umbrous_aspect
- [energizing_aspect, 9]
- [enshrouding_aspect, 4]
- [frostbitten_aspect, 20]
- [manglers_aspect, 45]
- [ravenous_aspect, 65]
- [umbrous_aspect, 55]

# Sorceress

# Barbarian

# Druid

# Necromancer
2 changes: 1 addition & 1 deletion src/item/data/item_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class ItemType(Enum):
# Armor
Helm = "helm"
Armor = "armor"
Armor = "chest armor"
Legs = "pants"
Gloves = "gloves"
Boots = "boots"
Expand Down
31 changes: 15 additions & 16 deletions src/item/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,21 @@ def should_keep(item: Item):
Logger.info(f"Matched {filter_name}: {affix_debug_msg}")
return True

if item.aspect:
if item.aspect and filter_aspects is not None:
for filter_data in filter_aspects:
filter_aspect_pool = [filter_data] if isinstance(filter_data, str) else filter_data
for aspect in filter_aspect_pool:
aspect_name, *rest = aspect if isinstance(aspect, list) else [aspect]
threshold = rest[0] if rest else None
condition = rest[1] if len(rest) > 1 else "larger"

if item.aspect.type == aspect_name:
if (
threshold is None
or item.aspect.value is None
or (condition == "larger" and item.aspect.value >= threshold)
or (condition == "smaller" and item.aspect.value <= threshold)
):
Logger.info(f"Matched: [{item.aspect.type}, {item.aspect.value}]")
return True
filter_aspect = [filter_data] if isinstance(filter_data, str) else filter_data
aspect_name, *rest = aspect if isinstance(filter_aspect, list) else [filter_aspect]
threshold = rest[0] if rest else None
condition = rest[1] if len(rest) > 1 else "larger"

if item.aspect.type == aspect_name:
if (
threshold is None
or item.aspect.value is None
or (condition == "larger" and item.aspect.value >= threshold)
or (condition == "smaller" and item.aspect.value <= threshold)
):
Logger.info(f"Matched: [{item.aspect.type}, {item.aspect.value}]")
return True

return False
23 changes: 20 additions & 3 deletions src/item/read_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def read_descr(rarity: ItemRarity, img_item_descr: np.ndarray) -> Item:
max_length = len(item_type.value)
# common mistake is that "Armor" is on a seperate line and can not be detected properly
if item.type is None:
if "chest" in concatenated_str:
if "chest" in concatenated_str or "armor" in concatenated_str:
item.type = ItemType.Armor

if item.power is None or item.type is None:
Expand Down Expand Up @@ -151,6 +151,9 @@ def read_descr(rarity: ItemRarity, img_item_descr: np.ndarray) -> Item:
# default for: Pants, Amulets, Boots, All Weapons
remove_top_most = 1
affix_bullets.matches = affix_bullets.matches[remove_top_most:]
if len(affix_bullets.matches) > 4:
Logger.debug("Still too many bullet points, removing so we have only 4 left")
affix_bullets.matches = affix_bullets.matches[-4:]
empty_sockets = search("empty_socket", img_item_descr, 0.87, roi_bullets, True, mode="all")
empty_sockets.matches = sorted(empty_sockets.matches, key=lambda match: match.center[1])
aspect_bullets = search("aspect_bullet_point", img_item_descr, 0.87, roi_bullets, True, mode="first")
Expand Down Expand Up @@ -228,9 +231,23 @@ def read_descr(rarity: ItemRarity, img_item_descr: np.ndarray) -> Item:
# cv2.imwrite("img_full_aspect.png", img_full_aspect)
concatenated_str = image_to_text(img_full_aspect).text.lower().replace("\n", " ")
cleaned_str = _clean_str(concatenated_str)

found_key = _closest_match(cleaned_str, aspect_dict, min_score=77)
idx = 1 if found_key in ["frostbitten_aspect", "aspect_of_artful_initiative"] else 0

# some aspects have their variable number as second:
number_idx_1 = [
"frostbitten_aspect",
"aspect_of_artful_initiative",
"aspect_of_noxious_ice",
]
number_idx_2 = [
"aspect_of_retribution",
]
if found_key in number_idx_1:
idx = 1
elif found_key in number_idx_2:
idx = 2
else:
idx = 0
found_value = _find_number(concatenated_str, idx)

if found_key is not None:
Expand Down
4 changes: 2 additions & 2 deletions src/loot_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def check_items(inv: InventoryBase):
inv.hover_item(item)
wait(0.35)
img = Cam().grab()
found, top_left_center, rarity, croped_descr = find_descr(img, item.center)
found, top_left_center, rarity, cropped_descr = find_descr(img, item.center)
if found:
# Sometimes we go to the next item, but the previous one still shows
if last_item_center is not None and compare_tuples(top_left_center, last_item_center, 5):
Expand All @@ -59,7 +59,7 @@ def check_items(inv: InventoryBase):
continue
start_time_read = time.time()
# Detect contents of item descr
item_descr = read_descr(rarity, croped_descr)
item_descr = read_descr(rarity, cropped_descr)
if item_descr is None:
Logger.warning("Failed to read properties. Keeping it")
continue
Expand Down
4 changes: 3 additions & 1 deletion src/ui/inventory_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from utils.image_operations import crop, threshold
from utils.roi_operations import get_center, to_grid
from utils.custom_mouse import mouse
from utils.misc import wait


@dataclass
Expand Down Expand Up @@ -38,7 +39,8 @@ def get_item_slots(self, img: Optional[np.ndarray] = None) -> tuple[list[ItemSlo
:return: Two sets of coordinates. The first set represents the centers of the occupied slots, and the second set represents the centers of the empty slots.
"""
if img is None:
mouse.move(*Cam().abs_window_to_monitor((0, 0)), randomize=5)
mouse.move(*Cam().abs_window_to_monitor((0, -int(Cam().window_roi["height"] * 0.4))), randomize=5)
wait(0.5)
img = Cam().grab()
grid = to_grid(self.slots_roi, self.rows, self.columns)
occupied_slots = []
Expand Down
Binary file added test/assets/item/read_descr_rare_1920x1080_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions test/item/read_descr_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@
],
),
),
(
(1920, 1080),
f"{BASE_PATH}/read_descr_rare_1920x1080_2.png",
Item(
ItemRarity.Rare,
ItemType.Legs,
844,
None,
[
Affix("potion_capacity", 3),
Affix("thorns", 873),
Affix("damage_reduction_from_close_enemies", 11),
Affix("imbuement_skill_cooldown_reduction", 5.8),
],
),
),
(
(2560, 1440),
f"{BASE_PATH}/read_descr_legendary_2560x1440_1.png",
Expand Down

0 comments on commit a7092ea

Please sign in to comment.