Package net.sf.l2j.gameserver.model.actor.instance

Examples of net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance


                // Go through all L2Object that belong to its faction
                for (L2Object obj : _actor.getKnownList().getKnownObjects().values())
                {
                    if (obj instanceof L2NpcInstance)
                    {
                        L2NpcInstance npc = (L2NpcInstance) obj;
                        if (getAttackTarget() == null || faction_id != npc.getFactionId())
                            continue;

                        // Check if the L2Object is inside the Faction Range of the actor
                        if (_actor.isInsideRadius(npc, npc.getFactionRange(), true, false)
                            && GeoData.getInstance().canSeeTarget(_actor, npc)
                            && Math.abs(getAttackTarget().getZ() - npc.getZ()) < 600
                            && npc.getAI() != null
                            && _actor.getAttackByList().contains(getAttackTarget())
                            && (npc.getAI()._intention == CtrlIntention.AI_INTENTION_IDLE
                            || npc.getAI()._intention == CtrlIntention.AI_INTENTION_ACTIVE))
                        {
                            if (getAttackTarget() instanceof L2PcInstance
                                && getAttackTarget().isInParty()
                                && getAttackTarget().getParty().isInDimensionalRift())
                            {
                                byte riftType = getAttackTarget().getParty().getDimensionalRift().getType();
                                byte riftRoom = getAttackTarget().getParty().getDimensionalRift().getCurrentRoom();

                                if (_actor instanceof L2RiftInvaderInstance
                                    && !DimensionalRiftManager.getInstance().getRoom(riftType, riftRoom).checkIfInZone(npc.getX(), npc.getY(), npc.getZ()))
                                    continue;
                            }

                            // Notify the L2Object AI with EVT_AGGRESSION
                            npc.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, getAttackTarget(), 1);
                        }
                    }
                }
            }
View Full Code Here


            ok = false;
        }
        else
          ok = false;

        L2NpcInstance merchant = null;

        if (ok)
          merchant = (L2NpcInstance)target;
        else if (!ok && !player.isGM())
        {
          player.sendMessage("Invalid Target: Seller must be targetted");
          return;
        }

        L2TradeList list = null;

        if (merchant != null)
        {
          List<L2TradeList> lists = TradeController.getInstance().getBuyListByNpcId(merchant.getNpcId());

          if(!player.isGM() )
          {
            if (lists == null)
            {
              Util.handleIllegalPlayerAction(player,"Warning!! Character "+player.getName()+" of account "+player.getAccountName()+" sent a false BuyList list_id.",Config.DEFAULT_PUNISH);
              return;
            }
            for (L2TradeList tradeList : lists)
            {
              if (tradeList.getListId() == _listId)
              {
                list = tradeList;
              }
            }
          }
          else
          {
            list = TradeController.getInstance().getBuyList(_listId);
          }
        }
        else
          list = TradeController.getInstance().getBuyList(_listId);
        if (list == null)
        {
          Util.handleIllegalPlayerAction(player,"Warning!! Character "+player.getName()+" of account "+player.getAccountName()+" sent a false BuyList list_id.",Config.DEFAULT_PUNISH);
          return;
        }

        _listId = list.getListId();

        if (_listId > 1000000) // lease
    {
      if (merchant != null && merchant.getTemplate().npcId != _listId-1000000)
      {
        sendPacket(new ActionFailed());
        return;
      }
    }
        if(_count < 1)
    {
            sendPacket(new ActionFailed());
        return;
    }
    double taxRate = 0;
    if (merchant != null && merchant.getIsInTown()) taxRate = merchant.getCastle().getTaxRate();
    long subTotal = 0;
    int tax = 0;

    // Check for buylist validity and calculates summary values
    long slots = 0;
    long weight = 0;
    for (int i = 0; i < _count; i++)
    {
      int itemId = _items[i * 2 + 0];
      int count  = _items[i * 2 + 1];
      int price = -1;

      if (!list.containsItemId(itemId))
      {
        Util.handleIllegalPlayerAction(player,"Warning!! Character "+player.getName()+" of account "+player.getAccountName()+" sent a false BuyList list_id.",Config.DEFAULT_PUNISH);
        return;
      }

            L2Item template = ItemTable.getInstance().getTemplate(itemId);

            if (template == null) continue;
            if (count > Integer.MAX_VALUE || (!template.isStackable() && count > 1))
      {
        Util.handleIllegalPlayerAction(player,"Warning!! Character "+player.getName()+" of account "+player.getAccountName()+" tried to purchase invalid quantity of items at the same time.",Config.DEFAULT_PUNISH);
        SystemMessage sm = new SystemMessage(SystemMessageId.YOU_HAVE_EXCEEDED_QUANTITY_THAT_CAN_BE_INPUTTED);
        sendPacket(sm);
        sm = null;

        return;
      }

      if (_listId < 1000000)
      {
        //list = TradeController.getInstance().getBuyList(_listId);
        price = list.getPriceForItemId(itemId);
                if (itemId >= 3960 && itemId <= 4026) price *= Config.RATE_SIEGE_GUARDS_PRICE;

      }
/* TODO: Disabled until Leaseholders are rewritten ;-)
      } else {
        L2ItemInstance li = merchant.findLeaseItem(itemId, 0);
        if (li == null || li.getCount() < cnt) {
          cnt = li.getCount();
          if (cnt <= 0) {
            items.remove(i);
            continue;
          }
          items.get(i).setCount((int)cnt);
        }
        price = li.getPriceToSell(); // lease holder sells the item
        weight = li.getItem().getWeight();
      }

*/
      if (price < 0)
      {
        _log.warning("ERROR, no price found .. wrong buylist ??");
                sendPacket(new ActionFailed());
                return;
      }

      if(price == 0 && !player.isGM() && Config.ONLY_GM_ITEMS_FREE)
      {
        player.sendMessage("Ohh Cheat dont work? You have a problem now!");
        Util.handleIllegalPlayerAction(player,"Warning!! Character "+player.getName()+" of account "+player.getAccountName()+" tried buy item for 0 adena.", Config.DEFAULT_PUNISH);
        return;
      }

      subTotal += (long)count * price;  // Before tax
      tax = (int)(subTotal * taxRate);
            if (subTotal + tax > Integer.MAX_VALUE)
            {
                Util.handleIllegalPlayerAction(player,"Warning!! Character "+player.getName()+" of account "+player.getAccountName()+" tried to purchase over "+Integer.MAX_VALUE+" adena worth of goods.", Config.DEFAULT_PUNISH);
                return;
            }

            weight += (long)count * template.getWeight();
      if (!template.isStackable()) slots += count;
            else if (player.getInventory().getItemByItemId(itemId) == null) slots++;
    }

    if (weight > Integer.MAX_VALUE || weight < 0 || !player.getInventory().validateWeight((int)weight))
    {
      sendPacket(new SystemMessage(SystemMessageId.WEIGHT_LIMIT_EXCEEDED));
      return;
    }

    if (slots > Integer.MAX_VALUE || slots < 0 || !player.getInventory().validateCapacity((int)slots))
    {
      sendPacket(new SystemMessage(SystemMessageId.SLOTS_FULL));
      return;
    }

    // Charge buyer and add tax to castle treasury if not owned by npc clan
    if ((subTotal < 0) || !player.reduceAdena("Buy", (int)(subTotal + tax), player.getLastFolkNPC(), false))
    {
      sendPacket(new SystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
      return;
    }

    if (merchant != null && merchant.getIsInTown() && merchant.getCastle().getOwnerId() > 0)
        merchant.getCastle().addToTreasury(tax);

    // Proceed the purchase
    for (int i=0; i < _count; i++)
    {
      int itemId = _items[i * 2 + 0];
      int count  = _items[i * 2 + 1];
      if (count < 0) count = 0;

      if (!list.containsItemId(itemId))
      {
        Util.handleIllegalPlayerAction(player,"Warning!! Character "+player.getName()+" of account "+player.getAccountName()+" sent a false BuyList list_id.",Config.DEFAULT_PUNISH);
        return;
      }
      if(list.countDecrease(itemId))
        list.decreaseCount(itemId,count);
      // Add item to Inventory and adjust update packet
      player.getInventory().addItem("Buy", itemId, count, player, merchant);
/* TODO: Disabled until Leaseholders are rewritten ;-)
      // Update Leaseholder list
      if (_listId >= 1000000)
      {
        L2ItemInstance li = merchant.findLeaseItem(item.getItemId(), 0);
        if (li == null)
          continue;
        if (li.getCount() < item.getCount())
          item.setCount(li.getCount());
        li.setCount(li.getCount() - item.getCount());
        li.updateDatabase();
        price = item.getCount() + li.getPriceToSell();
        L2ItemInstance la = merchant.getLeaseAdena();
        la.setCount(la.getCount() + price);

        la.updateDatabase();
        player.getInventory().addItem(item);
        item.updateDatabase();
      }
*/
    }

    if (merchant != null)
    {
      String html = HtmCache.getInstance().getHtm("data/html/"+ htmlFolder +"/" + merchant.getNpcId() + "-bought.htm");

      if (html != null)
      {
        NpcHtmlMessage boughtMsg = new NpcHtmlMessage(merchant.getObjectId());
        boughtMsg.setHtml(html.replaceAll("%objectId%", String.valueOf(merchant.getObjectId())));
        player.sendPacket(boughtMsg);
      }
    }

    StatusUpdate su = new StatusUpdate(player.getObjectId());
View Full Code Here

    setAmount(1);
  }

  public L2NpcInstance doGroupSpawn()
    {
    L2NpcInstance mob = null;

    try
    {
            if (_template.type.equalsIgnoreCase("L2Pet") ||
                    _template.type.equalsIgnoreCase("L2Minion"))
                return null;

      Object[] parameters = {IdFactory.getInstance().getNextId(), _template};
      Object  tmp = _constructor.newInstance(parameters);

      if (!(tmp instanceof L2NpcInstance))
        return null;

      mob = (L2NpcInstance)tmp;

      int newlocx, newlocy, newlocz;

      if  (getLocx() == 0 && getLocy() == 0)
            {
          if (getLocation() == 0)
                    return null;

                int p[] = Territory.getInstance().getRandomPoint(getLocation());
        newlocx = p[0];
        newlocy = p[1];
        newlocz = p[2];
      }
      else
            {
        newlocx = getLocx();
        newlocy = getLocy();
        newlocz = getLocz();
      }

      mob.setCurrentHpMp(mob.getMaxHp(), mob.getMaxMp());

      if (getHeading() == -1)
        mob.setHeading(Rnd.nextInt(61794));
      else
        mob.setHeading(getHeading());

      mob.setSpawn(this);
      mob.spawnMe(newlocx, newlocy, newlocz);
      mob.onSpawn();

      if (Config.DEBUG)
        _log.finest("spawned Mob ID: "+_template.npcId+" ,at: "
            +mob.getX()+" x, "+mob.getY()+" y, "+mob.getZ()+" z");

      return mob;

    }
    catch (Exception e)
View Full Code Here

      return addSpawn(npcId, cha.getX(), cha.getY(), cha.getZ(), cha.getHeading(), false, 0);
  }
 
    public L2NpcInstance addSpawn(int npcId, int x, int y, int z,int heading, boolean randomOffset, int despawnDelay)
    {
      L2NpcInstance result = null;
        try
        {
            L2NpcTemplate template = NpcTable.getInstance().getTemplate(npcId);
            if (template != null)
            {
View Full Code Here

            ok = false;
        }
        else
          ok = false;

        L2NpcInstance merchant = null;

        if (ok)
          merchant = (L2NpcInstance)target;

    if (_listId > 1000000) // lease
    {
      if (merchant.getTemplate().npcId != _listId-1000000)
      {
        sendPacket(new ActionFailed());
        return;
      }
    }

    long totalPrice = 0;
    // Proceed the sell
    for (int i = 0; i < _count; i++)
    {
      int objectId = _items[i * 3 + 0];
      @SuppressWarnings("unused")
      int itemId   = _items[i * 3 + 1];
      int count   = _items[i * 3 + 2];

      if (count < 0 || count > Integer.MAX_VALUE)
      {
        Util.handleIllegalPlayerAction(player,"Warning!! Character "+player.getName()+" of account "+player.getAccountName()+" tried to purchase over "+Integer.MAX_VALUE+" items at the same time.",  Config.DEFAULT_PUNISH);
        SystemMessage sm = new SystemMessage(SystemMessageId.YOU_HAVE_EXCEEDED_QUANTITY_THAT_CAN_BE_INPUTTED);
        sendPacket(sm);
        sm = null;
        return;
      }

      L2ItemInstance item = player.checkItemManipulation(objectId, count, "sell");
          if (item == null || (!item.getItem().isSellable())) continue;

            totalPrice += item.getReferencePrice() * count /2;
            if (totalPrice > Integer.MAX_VALUE)
            {
                Util.handleIllegalPlayerAction(player,"Warning!! Character "+player.getName()+" of account "+player.getAccountName()+" tried to purchase over "+Integer.MAX_VALUE+" adena worth of goods.",  Config.DEFAULT_PUNISH);
                return;
            }

      item = player.getInventory().destroyItem("Sell", objectId, count, player, null);

/* TODO: Disabled until Leaseholders are rewritten ;-)
      int price = item.getReferencePrice()*(int)count/2;
      L2ItemInstance li = null;
      L2ItemInstance la = null;
      if (_listId > 1000000) {
        li = merchant.findLeaseItem(item.getItemId(),item.getEnchantLevel());
        la = merchant.getLeaseAdena();
        if (li == null || la == null) continue;
        price = li.getPriceToBuy()*(int)count; // player sells, thus merchant buys.
        if (price > la.getCount()) continue;
      }
*/
/* TODO: Disabled until Leaseholders are rewritten ;-)
        if (item != null && _listId > 1000000) {
          li.setCount(li.getCount()+(int)count);
          li.updateDatabase();
          la.setCount(la.getCount()-price);
          la.updateDatabase();
        }
*/
    }
    player.addAdena("Sell", (int)totalPrice, merchant, false);

    String html = HtmCache.getInstance().getHtm("data/html/"+ htmlFolder +"/" + merchant.getNpcId() + "-sold.htm");

    if (html != null)
    {
      NpcHtmlMessage soldMsg = new NpcHtmlMessage(merchant.getObjectId());
      soldMsg.setHtml(html.replaceAll("%objectId%", String.valueOf(merchant.getObjectId())));
      player.sendPacket(soldMsg);
    }

      // Update current load as well
    StatusUpdate su = new StatusUpdate(player.getObjectId());
View Full Code Here

        L2PcInstance caster = (this instanceof L2PcInstance) ? (L2PcInstance) this : ((L2Summon) this).getOwner();
        for (L2Object target : targets)
        {
          if (target instanceof L2NpcInstance)
          {
            L2NpcInstance npc = (L2NpcInstance) target;
            if (npc.getTemplate().getEventQuests(Quest.QuestEventType.MOB_TARGETED_BY_SKILL) != null)
            {
              for (Quest quest : npc.getTemplate().getEventQuests(Quest.QuestEventType.MOB_TARGETED_BY_SKILL))
              {
                quest.notifySkillUse(npc, caster, skill);
              }
            }
          }
        }
        if (skill.getAggroPoints() > 0)
        {
          for (L2Object spMob : caster.getKnownList().getKnownObjects().values())
          {
            if (spMob instanceof L2NpcInstance)
            {
              L2NpcInstance npcMob = (L2NpcInstance) spMob;
              if (npcMob.isInsideRadius(caster, 1000, true, true) && npcMob.hasAI() && (npcMob.getAI().getIntention() == AI_INTENTION_ATTACK))
              {
                L2Object npcTarget = npcMob.getTarget();
                for (L2Object target : targets)
                {
                  if ((npcTarget == target) || (npcMob == target))
                  {
                    npcMob.seeSpell(caster, target, skill);
                  }
                }
              }
            }
          }
View Full Code Here

   * @return
   *
   */
  public L2NpcInstance doSpawn()
  {
    L2NpcInstance mob = null;
    try
    {
      // Check if the L2Spawn is not a L2Pet or L2Minion spawn
            if (_template.type.equalsIgnoreCase("L2Pet") || _template.type.equalsIgnoreCase("L2Minion"))
            {
View Full Code Here

    private void handleDelete(L2PcInstance activeChar)
    {
        L2Object obj = activeChar.getTarget();
        if ((obj != null) && (obj instanceof L2NpcInstance))
        {
            L2NpcInstance target = (L2NpcInstance) obj;
            target.deleteMe();

            L2Spawn spawn = target.getSpawn();
            if (spawn != null)
            {
                spawn.stopRespawn();

                if (RaidBossSpawnManager.getInstance().isDefined(spawn.getNpcid())) RaidBossSpawnManager.getInstance().deleteSpawn(
                                                                                                                                   spawn,
                                                                                                                                   true);
                else SpawnTable.getInstance().deleteSpawn(spawn, true);
            }

            SystemMessage sm = new SystemMessage(SystemMessageId.S1_S2);
            sm.addString("Deleted " + target.getName() + " from " + target.getObjectId() + ".");
            activeChar.sendPacket(sm);
        }
        else
        {
            SystemMessage sm = new SystemMessage(SystemMessageId.S1_S2);
View Full Code Here

  @Override
  public void onStart()
  {
    if(getEffected() instanceof L2NpcInstance)
    {
      L2NpcInstance npc = (L2NpcInstance)getEffected();
      npc.setCollisionHeight((int)(npc.getCollisionHeight()*1.24));
      npc.setCollisionRadius((int)(npc.getCollisionRadius()*1.19));
     
      getEffected().startAbnormalEffect(L2Character.ABNORMAL_EFFECT_GROW);
    }
  }
 
View Full Code Here

  @Override
  public boolean onActionTime()
  {
    if(getEffected() instanceof L2NpcInstance)
    {
      L2NpcInstance npc = (L2NpcInstance)getEffected();
      npc.setCollisionHeight(npc.getTemplate().collisionHeight);
      npc.setCollisionRadius(npc.getTemplate().collisionRadius);
     
      getEffected().stopAbnormalEffect(L2Character.ABNORMAL_EFFECT_GROW);
    }
    return false;
  }
View Full Code Here

TOP

Related Classes of net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.