/** 每提升10级,需要的钻石数量+10颗,颜色每提升1个等级,则需要1.2倍钻石数量 1 1 2 10 3 45 4 80 5 125 6 180 7 245 8 320 9 405 */
  public static ScriptResult func(Object[] parameters) {
    ScriptResult result = ScriptManager.checkParameters(parameters, 2);
    if (result != null) {
      return result;
    }

    User user = (User) parameters[0];
    PropData propData = (PropData) parameters[1];
    int count = 0;
    WeaponPojo weapon = EquipManager.getInstance().getWeaponById(propData.getItemId());
    if (weapon != null) {
      int userLevel = weapon.getUserLevel();
      if (userLevel == 0) {
        count = 1;
      } else if (userLevel == 10) {
        count = 10;
      } else if (userLevel < 90) {
        count = (userLevel / 10 + 1) * (userLevel / 10 + 1) * 5;
        int colorIndex = propData.getWeaponColor().ordinal();
        if (colorIndex > 0) {
          count = Math.round(count * 1.2f * colorIndex);
        }
      }
    }

    List list = new ArrayList();
    list.add(count);
    result = new ScriptResult();
    result.setType(ScriptResult.Type.SUCCESS_RETURN);
    result.setResult(list);
    return result;
  }
  @Test
  public void testWearAndUnWearBloodPercentEquip() {
    ScriptManager manager = ScriptManager.getInstance();
    User user = UserManager.getInstance().createDefaultUser();
    user.setBlood(100);
    User expectUser = UserManager.getInstance().createDefaultUser();
    expectUser.setBlood(100);

    WeaponPojo weapon = new WeaponPojo();
    weapon.setAddBloodPercent(15);

    user.getBag().removeOtherPropDatas(Bag.BAG_WEAR_COUNT);
    user.getBag().addOtherPropDatas(weapon.toPropData(30, WeaponColor.WHITE));
    user.getBag().wearPropData(Bag.BAG_WEAR_COUNT, PropDataEquipIndex.WEAPON.index());

    // default power = 2980
    assertEquals(Math.round(expectUser.getBlood() * 1.15), user.getBlood());

    user.getBag().wearPropData(PropDataEquipIndex.WEAPON.index(), -1);

    assertEquals(expectUser.getBlood(), user.getBlood());
  }
  @Test
  public void testBagUnwear() {
    ScriptManager manager = ScriptManager.getInstance();
    User user = UserManager.getInstance().createDefaultUser();
    User expectUser = UserManager.getInstance().createDefaultUser();

    WeaponPojo weapon = new WeaponPojo();
    weapon.setAddAttack(10);
    weapon.setAddDefend(20);
    weapon.setAddAgility(30);
    weapon.setAddLuck(40);
    weapon.setAddBlood(50);
    weapon.setAddBloodPercent(60);
    weapon.setAddThew(70);
    weapon.setAddDamage(80);
    weapon.setAddSkin(90);

    user.getBag().removeOtherPropDatas(Bag.BAG_WEAR_COUNT);
    user.getBag().addOtherPropDatas(weapon.toPropData(30, WeaponColor.WHITE));
    user.getBag().wearPropData(Bag.BAG_WEAR_COUNT, PropDataEquipIndex.WEAPON.index());

    // default power = 2980
    assertTrue(user.getPower() > 0);
    assertEquals(expectUser.getAttack() + weapon.getAddAttack(), user.getAttack());
    assertEquals(expectUser.getDefend() + weapon.getAddDefend(), user.getDefend());
    assertEquals(expectUser.getAgility() + weapon.getAddAgility(), user.getAgility());
    assertEquals(expectUser.getLuck() + weapon.getAddLuck(), user.getLuck());
    assertEquals(
        (int)
            ((expectUser.getBlood() + weapon.getAddBlood())
                * (1.0 + weapon.getAddBloodPercent() / 100.0)),
        user.getBlood());
    assertEquals(expectUser.getTkew() + weapon.getAddThew() + 6, user.getTkew());
    assertEquals(expectUser.getDamage() + weapon.getAddDamage(), user.getDamage());
    assertEquals(expectUser.getSkin() + weapon.getAddSkin(), user.getSkin());

    user.getBag().wearPropData(PropDataEquipIndex.WEAPON.index(), Bag.BAG_WEAR_COUNT);

    assertEquals(expectUser.getAttack(), user.getAttack());
    assertEquals(expectUser.getDefend(), user.getDefend());
    assertEquals(expectUser.getAgility(), user.getAgility());
    assertEquals(expectUser.getLuck(), user.getLuck());
    assertEquals(expectUser.getTkew(), user.getTkew());
    assertEquals(expectUser.getDamage(), user.getDamage());
    assertEquals(expectUser.getSkin(), user.getSkin());
  }