function ComparePetEqItem(Context) {

    //the pets class; 
    //type is Number.
    const PetClass = Context.PetClass;
    //the slot of the alternate item;
    //type is Number;
    const EquipSlot = Context.EquipSlot;
    // information of the equipped item, value is the item information.
    const Equipped = Context.Equipped;
    // information about the alternate item
    const Alternate = Context.Alternate;

    // logic
    if (EquipSlot == 4) {
        // Weapon
        return matchPetWeapon(PetClass, Equipped, Alternate);
    } else if (EquipSlot == 5) {
        // Shields
        if (PetClass == 3) {
            let anotherProp = Alternate.Propertys.get(10);
            if (anotherProp != null) {
                let rightHandItem = d.GetEquippedItem(4);
                if (rightHandItem == null || rightHandItem.Propertys.get(15) == null) {
                    if (Equipped == null) {
                        return true;
                    }
                    if (Alternate.ItemQualities > Equipped.ItemQualities) {
                        return true;
                    }
                    let prop = Equipped.Propertys.get(10);
                    if (prop != null) {
                        if (Alternate.ItemQualities == Equipped.ItemQualities && parseInt(anotherProp.Values[0]) > parseInt(prop.Values[0])) {
                            return true;
                        }
                    }
                }
            }
        } else if (PetClass == 5) {
            return matchPetWeapon(PetClass, Equipped, Alternate);
        }
    } else {
        if (Equipped == null) {
            return true;
        }
        if (Alternate.ItemQualities > Equipped.ItemQualities) {
            return true;
        }
        prop = Equipped.Propertys.get(10);
        anotherProp = Alternate.Propertys.get(10);
        if (prop != null && anotherProp != null) {
            {
                if (Alternate.ItemQualities == Equipped.ItemQualities && parseInt(anotherProp.Values[0]) > parseInt(prop.Values[0])) {
                    return true;
                }
            }
        }
    }
    return false;
}

function matchPetWeapon(petClass, equipped, alternate) {
    if (alternate.ItemType == 38) {
        return false;
    }
    if (equipped == null) {
        return true;
    }
    let prop = equipped.Propertys.get(14);
    let prop2 = equipped.Propertys.get(15);
    let anotherProp = alternate.Propertys.get(14);
    let anotherProp2 = alternate.Propertys.get(15);
    if (prop != null) {
        if (petClass == 3 && alternate.ItemQualities > equipped.ItemQualities) {
            return true;
        }
        let val = 0;
        if (prop != null) {
            val = parseInt(prop.Values[1]) * 2;
        } else if (prop2 != null) {
            val = parseInt(prop2.Values[1]);
        }
        let aVal = 0;
        if (anotherProp != null) {
            aVal = parseInt(anotherProp.Values[1]) * 2;
        } else if (anotherProp2 != null) {
            aVal = parseInt(anotherProp2.Values[1]);
        }
        if (aVal > val) {
            return true;
        } else if (aVal == val) {
            return alternate.ItemQualities > equipped.ItemQualities;
        } else {
            return false;
        }
    }
    return false;
}