Пример #1
0
  private void recallNPC(L2PcInstance activeChar) {
    L2Object obj = activeChar.getTarget();

    if (obj != null && obj.isNpc) {
      L2NpcInstance target = (L2NpcInstance) obj;

      int monsterTemplate = target.getTemplate().npcId;

      L2NpcTemplate template1 = NpcTable.getInstance().getTemplate(monsterTemplate);

      if (template1 == null) {
        activeChar.sendMessage("Incorrect monster template.");
        _log.warn("ERROR: NPC " + target.getObjectId() + " has a 'null' template.");
        return;
      }

      L2Spawn spawn = target.getSpawn();

      if (spawn == null) {
        activeChar.sendMessage("Incorrect monster spawn.");
        _log.warn("ERROR: NPC " + target.getObjectId() + " has a 'null' spawn.");
        return;
      }

      int respawnTime = spawn.getRespawnDelay();

      target.deleteMe();
      spawn.stopRespawn();
      SpawnTable.getInstance().deleteSpawn(spawn, true);

      try {
        // L2MonsterInstance mob = new L2MonsterInstance(monsterTemplate, template1);

        spawn = new L2Spawn(template1);
        spawn.setLocx(activeChar.getX());
        spawn.setLocy(activeChar.getY());
        spawn.setLocz(activeChar.getZ());
        spawn.setAmount(1);
        spawn.setHeading(activeChar.getHeading());
        spawn.setRespawnDelay(respawnTime);
        SpawnTable.getInstance().addNewSpawn(spawn, true);
        spawn.init();

        SystemMessage sm = new SystemMessage(SystemMessageId.S1_S2);
        sm.addString("Created " + template1.name + " on " + target.getObjectId() + ".");
        activeChar.sendPacket(sm);
        sm = null;

        if (Config.DEBUG) {
          _log.info(
              "Spawn at X=" + spawn.getLocx() + " Y=" + spawn.getLocy() + " Z=" + spawn.getLocz());
          _log.warn(
              "GM: "
                  + activeChar.getName()
                  + "("
                  + activeChar.getObjectId()
                  + ") moved NPC "
                  + target.getObjectId());
        }

        spawn = null;
        template1 = null;
        target = null;
      } catch (Exception e) {
        activeChar.sendMessage("Target is not in game.");
      }
    } else {
      activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
    }

    obj = null;
  }