Skip to content

Commit

Permalink
More s6 fixes (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisoro authored Oct 14, 2024
1 parent 7806332 commit 5544f08
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 28 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ coverage
cryptography
httpx
keyboard
levenshtein
lxml
mouse
mss
Expand Down
2 changes: 1 addition & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

TP = concurrent.futures.ThreadPoolExecutor()

__version__ = "5.8.4"
__version__ = "5.8.5"
12 changes: 8 additions & 4 deletions src/gui/importer/maxroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ def _find_item_affixes(mapping_data: dict, item_affixes: dict) -> list[Affix]:
attr_desc = f"to {skill_data["name"]}"
break
else:
if affix["attributes"][0]["param"] == -1460542966:
if affix["attributes"][0]["param"] == -1460542966 and affix["attributes"][0]["id"] == 1033:
attr_desc = "to core skills"
elif affix["attributes"][0]["param"] == -755407686:
elif affix["attributes"][0]["param"] == -755407686 and affix["attributes"][0]["id"] == 1034:
attr_desc = "to defensive skills"
elif affix["attributes"][0]["param"] == 746476422:
elif affix["attributes"][0]["param"] == 746476422 and affix["attributes"][0]["id"] == 1034:
attr_desc = "to mastery skills"
elif affix["attributes"][0]["param"] == -954965341:
elif affix["attributes"][0]["param"] == -954965341 and affix["attributes"][0]["id"] == 1091:
attr_desc = "to basic skills"
clean_desc = re.sub(r"\[.*?\]|[^a-zA-Z ]", "", attr_desc)
clean_desc = clean_desc.replace("SecondSeconds", "seconds")
Expand All @@ -185,6 +185,10 @@ def _attr_desc_special_handling(affix_id: str) -> str:
return "subterfuge cooldown reduction"
case 2123788:
return "chance for core skills to hit twice"
case 2119054:
return "chance for basic skills to deal double damage"
case 2119058:
return "basic lucky hit chance"
case _:
return ""

Expand Down
35 changes: 14 additions & 21 deletions src/item/descr/item_type.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Levenshtein
import numpy as np

from src.config.data import COLORS
Expand Down Expand Up @@ -69,38 +70,30 @@ def read_item_type_and_rarity(

def _find_item_power_and_type(item: Item, concatenated_str: str) -> Item:
idx = None
start = 0
if item.rarity is not None:
start = concatenated_str.find(item.rarity.value) + len(item.rarity.value)
if Dataloader().tooltips["ItemPower"] in concatenated_str:
idx = concatenated_str.index(Dataloader().tooltips["ItemPower"])
preceding_word = ""
if idx is not None:
preceding_word = concatenated_str[:idx].split()[-1]
preceding_word = concatenated_str[start:idx].split()[-1]
if preceding_word.isdigit():
item.power = int(preceding_word)
elif "+" in preceding_word:
item_power_numbers = preceding_word.split("+")
if item_power_numbers[0].isdigit() and item_power_numbers[1].isdigit():
item.power = int(item_power_numbers[0]) + int(item_power_numbers[1])

max_length = 0
last_char_idx = 0
best_match = (None, 100)
for item_type in ItemType:
if (found_idx := concatenated_str.rfind(item_type.value)) != -1:
tmp_idx = found_idx + len(item_type.value)
if tmp_idx >= last_char_idx and ("two-handed" not in item_type.value or len(item_type.value) > max_length):
item.item_type = item_type
last_char_idx = tmp_idx
max_length = len(item_type.value)
# common mistake is that "Armor" is on a seperate line and can not be detected properly
if item.item_type is None and ("chest" in concatenated_str or "armor" in concatenated_str):
item.item_type = ItemType.ChestArmor
if any(substring in concatenated_str for substring in ["two -handed", "two handed", "two- handed", "two-handed"]):
if item.item_type == ItemType.Sword:
item.item_type = ItemType.Sword2H
elif item.item_type == ItemType.Mace:
item.item_type = ItemType.Mace2H
elif item.item_type == ItemType.Scythe:
item.item_type = ItemType.Scythe2H
elif item.item_type == ItemType.Axe:
item.item_type = ItemType.Axe2H
if (
distance := Levenshtein.distance(
concatenated_str[start : concatenated_str.rfind(preceding_word)], item_type.value, score_cutoff=100
)
) < best_match[1]:
best_match = (item_type, distance)
item.item_type = best_match[0]
return item


Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 38 additions & 2 deletions tests/item/read_descr_season6_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,50 @@
from src.cam import Cam
from src.config import BASE_DIR
from src.item.data.affix import Affix, AffixType
from src.item.data.aspect import Aspect
from src.item.data.item_type import ItemType
from src.item.data.rarity import ItemRarity
from src.item.descr.read_descr import read_descr
from src.item.models import Item

BASE_PATH = BASE_DIR / "tests/assets/item/season6"

items = []
items = [
(
(2160, 1440),
f"{BASE_PATH}/1440p_small_read_descr_1.png",
Item(
affixes=[
Affix(name="dexterity", value=194),
Affix(name="basic_lucky_hit_chance", value=5),
Affix(name="chance_for_basic_skills_to_deal_double_damage", value=27),
Affix(name="to_follow_through", value=2),
],
aspect=Aspect(name="sepazontec", value=68),
inherent=[Affix(name="block_chance", value=40, type=AffixType.inherent)],
item_type=ItemType.Quarterstaff,
power=750,
rarity=ItemRarity.Unique,
),
),
(
(2160, 1440),
f"{BASE_PATH}/1440p_small_read_descr_2.png",
Item(
affixes=[
Affix(name="maximum_resource", value=8),
Affix(name="critical_strike_damage", value=76),
Affix(name="chance_for_core_skills_to_hit_twice", value=24),
Affix(name="to_velocity", value=3),
],
aspect=Aspect(name="rod_of_kepeleke", value=2.2),
inherent=[Affix(name="block_chance", value=40, type=AffixType.inherent)],
item_type=ItemType.Quarterstaff,
power=750,
rarity=ItemRarity.Unique,
),
),
]

materials = [
(
Expand Down Expand Up @@ -96,7 +132,7 @@ def _run_test_helper(img_res: tuple[int, int], input_img: str, expected_item: It


@pytest.mark.parametrize(("img_res", "input_img", "expected_item"), items)
def test_item(img_res: tuple[int, int], input_img: str, expected_item: Item):
def test_items(img_res: tuple[int, int], input_img: str, expected_item: Item):
_run_test_helper(img_res=img_res, input_img=input_img, expected_item=expected_item)


Expand Down

0 comments on commit 5544f08

Please sign in to comment.