@Override public boolean useItem(Playable playable, ItemInstance item, boolean ctrl) { Player player; if (playable.isPlayer()) player = (Player) playable; else if (playable.isPet()) player = playable.getPlayer(); else return false; GameObject target = player.getTarget(); if (target == null || !target.isMonster()) { player.sendPacket(SystemMsg.THAT_IS_AN_INCORRECT_TARGET); return false; } MonsterInstance monster = (MonsterInstance) player.getTarget(); if (!monster.isDead()) { player.sendPacket(SystemMsg.THAT_IS_AN_INCORRECT_TARGET); return false; } Skill skill = SkillTable.getInstance().getInfo(HARVESTER_SKILL_ID, 1); if (skill != null && skill.checkCondition(player, monster, false, false, true)) { player.getAI().Cast(skill, monster); return true; } return false; }
public static long removeItem(Playable playable, ItemInstance item, long count, boolean notify) { long removed = 0; if (playable == null || count < 1) return removed; Playable player = playable.getPlayer(); if (item.getTemplate().isStackable()) { if (player.getInventory().destroyItem(item, count)) removed = count; } else for (long i = 0; i < count; i++) if (player.getInventory().destroyItem(item, 1)) removed++; if (removed > 0 && notify) player.sendPacket(SystemMessage2.removeItems(item.getItemId(), removed)); return removed; }
@Override public boolean useItem(Playable playable, ItemInstance item, boolean ctrl) { if (playable == null || !playable.isPlayer()) return false; Player player = playable.getPlayer(); if (player.getTarget() == null || !player.getTarget().isMonster()) { player.sendPacket(SystemMsg.INVALID_TARGET, ActionFail.STATIC); return false; } if (player.isImmobilized() || player.isCastingNow()) { player.sendActionFailed(); return false; } MonsterInstance target = (MonsterInstance) player.getTarget(); // u can use soul crystal only when target hp goes to <50% if (target.getCurrentHpPercents() >= 50) { player.sendPacket( SystemMsg.THE_SOUL_CRYSTAL_WAS_NOT_ABLE_TO_ABSORB_THE_SOUL, ActionFail.STATIC); return false; } // Soul Crystal Casting section int skillHitTime = SkillTable.getInstance().getInfo(SOUL_CRYSTAL_SKILL_ID, 1).getHitTime(); player.broadcastPacket(new MagicSkillUse(player, SOUL_CRYSTAL_SKILL_ID, 1, skillHitTime, 0)); player.sendPacket(new SetupGauge(player, SetupGauge.Colors.BLUE, skillHitTime)); // End Soul Crystal Casting section // Continue execution later player._skillTask = ThreadPoolManager.getInstance() .schedule(new CrystalFinalizer(player, target), skillHitTime); return true; }
/** * Возвращает количество предметов в инвентаре игрока * * @param playable Владелец инвентаря * @param itemId ID предмета * @return количество */ public static long getItemCount(Playable playable, int itemId) { if (playable == null) return 0; Playable player = playable.getPlayer(); return player.getInventory().getCountOf(itemId); }
/** * Добавляет предмет в инвентарь игрока, корректно обрабатывает нестыкуемые вещи * * @param playable Владелец инвентаря * @param itemId ID предмета * @param count количество */ public static void addItem(Playable playable, int itemId, long count, boolean notify) { if (playable == null || count < 1) return; Playable player; if (playable.isSummon()) player = playable.getPlayer(); else player = playable; if (itemId > 0) { ItemTemplate t = ItemHolder.getInstance().getTemplate(itemId); if (t.isStackable()) player.getInventory().addItem(itemId, count); else for (long i = 0; i < count; i++) player.getInventory().addItem(itemId, 1); if (notify) player.sendPacket(SystemMessage2.obtainItems(itemId, count, 0)); } else if (itemId == -100 && player.isPlayer()) { player.getPlayer().addPcBangPoints((int) count, false); } else if (itemId == -200 && player.isPlayer()) { if (player.getPlayer().getClan() != null) player.getPlayer().getClan().incReputation((int) count, false, "itemFunction"); } else if (itemId == -300 && player.isPlayer()) { player.getPlayer().setFame((int) count + player.getPlayer().getFame(), "itemFunction"); } }
public static boolean checkIfCanPickup(Playable playable, ItemInstance item) { Player player = playable.getPlayer(); return item.getDropTimeOwner() <= System.currentTimeMillis() || item.getDropPlayers().contains(player.getObjectId()); }