Skip to content

Commit

Permalink
Adjust _get_average_ingredient_level()
Browse files Browse the repository at this point in the history
No change to behavior
Generate permanent item list and use it to get, sum, item count and
\ avg level
  • Loading branch information
Kvel2D committed Oct 8, 2024
1 parent a6335ee commit c09d6d3
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/game_scene/horadric_cube.gd
Original file line number Diff line number Diff line change
Expand Up @@ -277,29 +277,29 @@ static func _get_ingredient_rarity(item_list: Array[Item]) -> Rarity.enm:
return rarity


# NOTE: only check level of permanent items. Skip oils and
# consumables. This is needed because Imbue recipe uses a
# mix of permanent items and oils as ingredients.
static func _get_average_ingredient_level(item_list: Array[Item]) -> int:
if item_list.is_empty():
return 0

var sum: float = 0.0
var item_count: int = 0

for item in item_list:
# NOTE: only check level of permanent items. Skip oils
# and consumables. Important for Imbue recipe.
var item_is_permanent: bool = ItemProperties.get_type(item.get_id()) == ItemType.enm.REGULAR
var permanent_item_list: Array[Item] = item_list.filter(
func(item: Item) -> bool:
var item_id: int = item.get_id()
var item_type: ItemType.enm = ItemProperties.get_type(item_id)
var item_is_permanent: bool = item_type == ItemType.enm.REGULAR

if !item_is_permanent:
continue
return item_is_permanent
)

var sum: float = 0.0
for item in permanent_item_list:
var item_id: int = item.get_id()
var level: int = ItemProperties.get_required_wave_level(item_id)
sum += level
item_count += 1

if item_count == 0:
return 0

var item_count: int = permanent_item_list.size()
var average_level: int = floori(sum / item_count)

return average_level
Expand Down

0 comments on commit c09d6d3

Please sign in to comment.