/**
   * @param item
   * @param cgs
   */
  public static void onItemEquipment(Item item, Player owner) {
    owner.getController().cancelUseItem();
    ItemTemplate itemTemplate = item.getItemTemplate();

    onItemEquipment(item, owner.getGameStats());

    // Check if belongs to ItemSet
    if (itemTemplate.isItemSet()) {
      recalculateItemSet(itemTemplate.getItemSet(), owner, item.getItemTemplate().isWeapon());
    }
    if (item.hasManaStones()) addStonesStats(item, item.getItemStones(), owner.getGameStats());

    if (item.hasFusionStones()) addStonesStats(item, item.getFusionStones(), owner.getGameStats());
    IdianStone idianStone = item.getIdianStone();

    if (idianStone != null
        && (owner.getEquipment().getOffHandWeapon() != item
            || item.getItemTemplate().isTwoHandWeapon())) {
      idianStone.onEquip(owner);
    }
    addGodstoneEffect(owner, item);
    RandomStats randomStats = item.getRandomStats();
    if (randomStats != null) {
      randomStats.onEquip(owner);
    }
    if (item.getConditioningInfo() != null) {
      owner.getObserveController().addObserver(item.getConditioningInfo());
      item.getConditioningInfo().setPlayer(owner);
    }
    if (item.getItemTemplate().isStigma()) StigmaService.recheckHiddenStigma(owner);
    EnchantService.onItemEquip(owner, item);
  }
  /**
   * @param item
   * @param owner
   */
  public static void onItemUnequipment(Item item, Player owner) {
    owner.getController().cancelUseItem();

    ItemTemplate itemTemplate = item.getItemTemplate();
    // Check if belongs to ItemSet
    if (itemTemplate.isItemSet()) {
      recalculateItemSet(itemTemplate.getItemSet(), owner, item.getItemTemplate().isWeapon());
    }

    owner.getGameStats().endEffect(item);

    if (item.hasManaStones()) removeStoneStats(item.getItemStones(), owner.getGameStats());

    if (item.hasFusionStones()) removeStoneStats(item.getFusionStones(), owner.getGameStats());

    if (item.getConditioningInfo() != null) {
      owner.getObserveController().removeObserver(item.getConditioningInfo());
      item.getConditioningInfo().setPlayer(null);
    }
    IdianStone idianStone = item.getIdianStone();
    if (idianStone != null) {
      idianStone.onUnEquip(owner);
    }
    removeGodstoneEffect(owner, item);
    RandomStats randomStats = item.getRandomStats();

    if (randomStats != null) {
      randomStats.onUnEquip(owner);
    }
  }
 @Override
 public boolean accept(ItemTemplate template) {
   ItemActions actions = template.getActions();
   if (actions != null) {
     CraftLearnAction craftAction = actions.getCraftLearnAction();
     if (craftAction != null) {
       int id = craftAction.getRecipeId();
       RecipeTemplate recipeTemplate = DataManager.RECIPE_DATA.getRecipeTemplateById(id);
       if (recipeTemplate != null && recipeTemplate.getSkillid() == craftSkillId) {
         return ArrayUtils.contains(masks, template.getTemplateId() / 100000);
       }
     }
   }
   return false;
 }
  private static List<StatFunction> wrapModifiersW(Item item, List<StatFunction> modifiers) {
    List<StatFunction> allModifiers = new ArrayList<StatFunction>();
    ItemTemplate itemTemplate = item.getItemTemplate();
    WeaponStats weaponStats = itemTemplate.getWeaponStats();
    for (StatFunction modifier : modifiers) {
      switch (modifier.getName()) {
        default:
          allModifiers.add(modifier);
      }
    }
    allModifiers.add(new StatAddFunction(StatEnum.PARRY, weaponStats.getParry(), false));
    allModifiers.add(
        new StatAddFunction(StatEnum.MAGICAL_ACCURACY, weaponStats.getMagicalAccuracy(), false));
    allModifiers.add(
        new StatAddFunction(StatEnum.PHYSICAL_ACCURACY, weaponStats.getPhysicalAccuracy(), false));

    return allModifiers;
  }
  /**
   * @param itemTemplate
   * @param slot
   * @param cgs
   */
  private static void onItemEquipment(Item item, CreatureGameStats<?> cgs) {
    ItemTemplate itemTemplate = item.getItemTemplate();
    long slot = item.getEquipmentSlot();
    List<StatFunction> modifiers = itemTemplate.getModifiers();
    if (modifiers == null) {
      return;
    }

    List<StatFunction> allModifiers = null;

    if ((slot & ItemSlot.MAIN_OR_SUB.getSlotIdMask()) != 0) {
      allModifiers = wrapModifiers(item, modifiers);
      if (item.hasFusionedItem()) {
        // add all bonus modifiers according to rules
        ItemTemplate fusionedItemTemplate = item.getFusionedItemTemplate();
        WeaponType weaponType = fusionedItemTemplate.getWeaponType();
        List<StatFunction> fusionedItemModifiers = fusionedItemTemplate.getModifiers();
        if (fusionedItemModifiers != null) {
          allModifiers.addAll(wrapModifiers(item, fusionedItemModifiers));
        }
        // add 10% of Magic Boost and Attack
        WeaponStats weaponStats = fusionedItemTemplate.getWeaponStats();
        if (weaponStats != null) {
          int boostMagicalSkill = Math.round(0.1f * weaponStats.getBoostMagicalSkill());
          int attack = Math.round(0.1f * weaponStats.getMeanDamage());
          if (weaponType == WeaponType.ORB_2H
              || weaponType == WeaponType.BOOK_2H
              || weaponType == WeaponType.GUN_1H
              || weaponType == WeaponType.KEYBLADE_2H
              || weaponType == WeaponType.CANNON_2H
              || weaponType == WeaponType.HARP_2H) {
            allModifiers.add(new StatAddFunction(StatEnum.MAGICAL_ATTACK, attack, false));
            allModifiers.add(
                new StatAddFunction(StatEnum.BOOST_MAGICAL_SKILL, boostMagicalSkill, false));
          } else allModifiers.add(new StatAddFunction(StatEnum.PHYSICAL_ATTACK, attack, false));
        }
      }
    } else {
      WeaponStats weaponStat = itemTemplate.getWeaponStats();
      if (weaponStat != null) {
        allModifiers = wrapModifiersW(item, modifiers);
      } else allModifiers = modifiers;
    }

    item.setCurrentModifiers(allModifiers);
    cgs.addEffect(item, allModifiers);
  }