function ComparePetEqItem(Context) {

//d.log("------------------pet equipment changing----------------------");

    //the pets class; 
    //type is Number.
	//d.Log("Pet换装中...");
    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
	//d.log("start pet equipment detection");
	// runewords will note be replaced

	let AltSockets = Alternate.Propertys.get(2)==null ? 0:parseInt(Alternate.Propertys.get(2).Values[0]);
	
	if(AltSockets!=0 && Alternate.SocketItems.Count<AltSockets && Alternate.SocketItems.Count>0){
		return false;
	}
	
    if (Equipped != null) {
  
		
		if(true){
			//d.log("Code"+Alternate.Code+" unique rating alternate: "+uniqueRatingPet(Alternate));
			//d.log("Code"+Equipped.Code+" unique rating equipped: "+uniqueRatingPet(Equipped));
			if(uniqueRatingPet(Alternate,EquipSlot)>uniqueRatingPet(Equipped,EquipSlot)  ){
				//d.log("候选装备命中配装！！！");
				d.Log("候选装备Unique评分胜出！！！");
				return true;
			}
			if(uniqueRatingPet(Alternate,EquipSlot)<uniqueRatingPet(Equipped,EquipSlot)){
				return false;
			}
		}
		
		let prop_fr=Equipped.Propertys.get(31)==null ? 0 : parseInt(Equipped.Propertys.get(31).Values[0]);
		let prop_ir=Equipped.Propertys.get(32)==null ? 0 : parseInt(Equipped.Propertys.get(32).Values[0]);
		let prop_lr=Equipped.Propertys.get(33)==null ? 0 : parseInt(Equipped.Propertys.get(33).Values[0]);
		let prop_pr=Equipped.Propertys.get(35)==null ? 0 : parseInt(Equipped.Propertys.get(35).Values[0]);
		let prop_ar=Equipped.Propertys.get(177)==null ? 0 : parseInt(Equipped.Propertys.get(177).Values[0]);
		
	

    }
    if (EquipSlot == 4) {
        // Weapon
       //d.log("start pet --- weapon");
        return matchPetWeapon(PetClass, Equipped, Alternate);
    } else if (EquipSlot == 5 ) {
	//d.log("55555");
        // 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) {
						return matchPetWeapon(PetClass, Equipped, Alternate);
                    }
                }
            }
        } else if (PetClass == 5) {
            return matchPetWeapon(PetClass, Equipped, Alternate);
        }
    } else {
        if (Equipped == null) {
//d.log("666");
            return true;
        }
        if (Alternate.ItemQualities > Equipped.ItemQualities) {
            //return true;
        }
		
	//d.log("start res and ll calculation");
		//get all res and life leech properties
		let prop_fr=Equipped.Propertys.get(31)==null ? 0 : parseInt(Equipped.Propertys.get(31).Values[0]);
		let prop_ir=Equipped.Propertys.get(32)==null ? 0 : parseInt(Equipped.Propertys.get(32).Values[0]);
		let prop_lr=Equipped.Propertys.get(33)==null ? 0 : parseInt(Equipped.Propertys.get(33).Values[0]);
		let prop_pr=Equipped.Propertys.get(35)==null ? 0 : parseInt(Equipped.Propertys.get(35).Values[0]);
		let prop_ar=Equipped.Propertys.get(177)==null ? 0 : parseInt(Equipped.Propertys.get(177).Values[0]);
		let prop_ll=Equipped.Propertys.get(71)==null ? 0 : parseInt(Equipped.Propertys.get(71).Values[0]);
		
		let prop_weighted = prop_fr*5+prop_ir+prop_lr*5+prop_pr+prop_ar*12+prop_ll*100;
		
		let Aprop_fr=Alternate.Propertys.get(31)==null ? 0 : parseInt(Alternate.Propertys.get(31).Values[0]);
		let Aprop_ir=Alternate.Propertys.get(32)==null ? 0 : parseInt(Alternate.Propertys.get(32).Values[0]);
		let Aprop_lr=Alternate.Propertys.get(33)==null ? 0 : parseInt(Alternate.Propertys.get(33).Values[0]);
		let Aprop_pr=Alternate.Propertys.get(35)==null ? 0 : parseInt(Alternate.Propertys.get(35).Values[0]);
		let Aprop_ar=Alternate.Propertys.get(177)==null ? 0 : parseInt(Alternate.Propertys.get(177).Values[0]);
		let Aprop_ll=Alternate.Propertys.get(71)==null ? 0 : parseInt(Alternate.Propertys.get(71).Values[0]);
		
		let Aprop_weighted = Aprop_fr*5+Aprop_ir+Aprop_lr*5+Aprop_pr+Aprop_ar*12+Aprop_ll*20;

////d.log("armors: "+parseInt(prop.Values[0])+" "+prop_weighted+"vs"+parseInt(anotherProp.Values[0])+" "+Aprop_weighted);
		
        prop = Equipped.Propertys.get(10);
        anotherProp = Alternate.Propertys.get(10);
		
		if (Aprop_weighted>prop_weighted){
			return true;
		}else{
			return false;
		}

    }
    return false;
}

function matchPetWeapon(petClass, equipped, alternate) {
	//d.Log("计算武器伤害中...");
    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 (equipped!=null) {
        if (petClass == 3 && alternate.ItemQualities > equipped.ItemQualities) {
            return true;
        }
        let val = 0;
        if (prop != null) {
            val = (parseInt(prop.Values[0])+parseInt(prop.Values[1])) * 2;
        } else if (prop2 != null) {
			////d.log("caonima");
            val = (parseInt(prop2.Values[0])+parseInt(prop2.Values[1]));
        }
		//d.log("Equipped weapon dam total = "+val);
        let aVal = 0;
       if (anotherProp != null) {
            aVal = (parseInt(anotherProp.Values[0])+parseInt(anotherProp.Values[1])) * 2;
        } else if (anotherProp2 != null) {
            aVal = (parseInt(anotherProp2.Values[0])+parseInt(anotherProp2.Values[1]));
        }
		
		//d.Log("Alternate weapon dam total = "+aVal);
//	if (petClass!=2 && petClass!=1){
		
		//d.Log("当前装备武器伤害（上下限总和） "+val);
		//d.Log("候选装备武器伤害（上下限总和） "+aVal);
        if (aVal > val) {
//d.log(aVal+"vs"+val);
////d.log("888");
            return true;
        } else if (aVal == val ) {
	//d.log("777");
//d.log(aVal+"vs"+val);
            return false;//alternate.ItemQualities > equipped.ItemQualities;
        } else {
            return false;
        }
//	}
    }
    return false;
}



function beltSlot(code){
	if(code==null){
		return 0;
	}
	if(code=="lbl" | code =="vbl"){
		return 2;
	}
	if(code=="mbl" | code =="tbl"){
		return 3;
	}
	return 4;
}

function uniqueRatingPet(item,es){
	

	//d.log("pet装备编号是 "+item.Code);
	////d.log("rating unique item...");
	////d.log(item.Code);
	if(es!=null){
	if((es==4 || es==5)&& item.ItemQualities!=7 && item.ItemQualities!=5){
		
		if (item.SocketItems.Count>0){
			return 70;
		}
		return 0;
	}
	}
	
	

	//胸甲
	
		//督瑞尔的殻
	if(item.Code=="xrs" && item.ItemQualities==7){
		return 100;
	}
	//鬥士的禍根
	if(item.Code=="utu" && item.ItemQualities==7){
		return 110;
	}

	//守护天使
	if(item.Code=="xlt" && item.ItemQualities==7){
		return 120;
	}
	
	//奇拉
	if(item.Code=="ci2" && item.ItemQualities==7){
		return 170;
	}

	if(item.Code=="uld" && item.ItemQualities==7){
		return 70;
	}

	if(item.Code=="xhn" && item.ItemQualities==7){
		return 70;
	}

	if(item.Code=="xhm" && item.ItemQualities==5){
		return 0;
	}


	//死神丧钟
	if(item.Code=="7s8" && item.ItemQualities==7){
		////d.log("牛逼，出丧钟了！！！！");
		return 10086;
	}	

	return 0;
	

	
}