Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Refactoring determine forge type (#303)
Browse files Browse the repository at this point in the history
* removed obsolet rarity check
* added helper classes and fixed itemtype check

---------

Co-authored-by: darkfriend77 <darkfriend@swissonline.ch>
Co-authored-by: Didac Semente Fernandez <didac@ajuna.io>
  • Loading branch information
3 people authored Jun 7, 2023
1 parent 6e9147a commit 44ecf8f
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,26 @@ impl AvatarUtils {
Self::read_attribute(avatar, attribute) == Self::read_attribute(other, attribute)
}

pub fn same_item_type(avatar: &Avatar, other: &Avatar) -> bool {
Self::has_attribute_with_same_value_as(avatar, other, &AvatarAttributes::ItemType)
}

pub fn same_item_sub_type(avatar: &Avatar, other: &Avatar) -> bool {
Self::has_attribute_with_same_value_as(avatar, other, &AvatarAttributes::ItemSubType)
}

pub fn same_rarity_tier(avatar: &Avatar, other: &Avatar) -> bool {
Self::has_attribute_with_same_value_as(avatar, other, &AvatarAttributes::RarityTier)
}

pub fn same_class_type1(avatar: &Avatar, other: &Avatar) -> bool {
Self::has_attribute_with_same_value_as(avatar, other, &AvatarAttributes::ClassType1)
}

pub fn same_class_type2(avatar: &Avatar, other: &Avatar) -> bool {
Self::has_attribute_with_same_value_as(avatar, other, &AvatarAttributes::ClassType2)
}

pub fn has_attribute_set_with_same_values_as(
avatar: &Avatar,
other: &Avatar,
Expand Down Expand Up @@ -645,6 +665,14 @@ impl AvatarUtils {
Self::has_attribute_with_value_raw(avatar, attribute, value.as_byte())
}

pub fn has_item_type<T: ByteConvertible>(avatar: &Avatar, value: T) -> bool {
Self::has_attribute_with_value(avatar, &AvatarAttributes::ItemType, value)
}

pub fn has_item_sub_type<T: ByteConvertible>(avatar: &Avatar, value: T) -> bool {
Self::has_attribute_with_value(avatar, &AvatarAttributes::ItemSubType, value)
}

pub fn has_attribute_with_value_different_than<T>(
avatar: &Avatar,
attribute: &AvatarAttributes,
Expand All @@ -671,6 +699,22 @@ impl AvatarUtils {
T::from_byte(Self::read_attribute(avatar, attribute))
}

pub fn read_item_type<T: ByteConvertible>(avatar: &Avatar) -> T {
Self::read_attribute_as::<T>(avatar, &AvatarAttributes::ItemType)
}

pub fn read_sub_type<T: ByteConvertible>(avatar: &Avatar) -> T {
Self::read_attribute_as::<T>(avatar, &AvatarAttributes::ItemSubType)
}

pub fn read_rarity<T: ByteConvertible>(avatar: &Avatar) -> T {
Self::read_attribute_as::<T>(avatar, &AvatarAttributes::RarityTier)
}

pub fn read_quantity(avatar: &Avatar) -> u8 {
Self::read_attribute(avatar, &AvatarAttributes::Quantity)
}

pub fn read_attribute(avatar: &Avatar, attribute: &AvatarAttributes) -> u8 {
match attribute {
AvatarAttributes::ItemType => Self::read_dna_strand(avatar, 0, &ByteType::High),
Expand Down
Loading

0 comments on commit 44ecf8f

Please sign in to comment.