public void newRace() {
    int random = 0;

    for (int i = 0; i < 8; i++) {
      int id = 31003;
      random = Rnd.get(24);
      while (true) {
        for (int j = i - 1; j >= 0; j--) {
          if (_monsters[j].getTemplate().getId() == (id + random)) {
            random = Rnd.get(24);
            continue;
          }
        }
        break;
      }
      try {
        L2NpcTemplate template = NpcData.getInstance().getTemplate(id + random);
        _constructor =
            Class.forName(
                    "com.l2jserver.gameserver.model.actor.instance."
                        + template.getType()
                        + "Instance")
                .getConstructors()[0];
        int objectId = IdFactory.getInstance().getNextId();
        _monsters[i] = (L2Npc) _constructor.newInstance(objectId, template);
      } catch (Exception e) {
        _log.log(Level.WARNING, "", e);
      }
      // _log.info("Monster "+i+" is id: "+(id+random));
    }
    newSpeeds();
  }
  private void spawnMonster(
      L2PcInstance activeChar, String monsterId, int respawnTime, int mobCount, boolean permanent) {
    L2Object target = activeChar.getTarget();
    if (target == null) {
      target = activeChar;
    }

    L2NpcTemplate template1;
    if (monsterId.matches("[0-9]*")) {
      // First parameter was an ID number
      int monsterTemplate = Integer.parseInt(monsterId);
      template1 = NpcData.getInstance().getTemplate(monsterTemplate);
    } else {
      // First parameter wasn't just numbers so go by name not ID
      monsterId = monsterId.replace('_', ' ');
      template1 = NpcData.getInstance().getTemplateByName(monsterId);
    }

    try {
      L2Spawn spawn = new L2Spawn(template1);
      if (Config.SAVE_GMSPAWN_ON_CUSTOM) {
        spawn.setCustom(true);
      }
      spawn.setX(target.getX());
      spawn.setY(target.getY());
      spawn.setZ(target.getZ());
      spawn.setAmount(mobCount);
      spawn.setHeading(activeChar.getHeading());
      spawn.setRespawnDelay(respawnTime);
      if (activeChar.getInstanceId() > 0) {
        spawn.setInstanceId(activeChar.getInstanceId());
        permanent = false;
      } else {
        spawn.setInstanceId(0);
      }
      // TODO add checks for GrandBossSpawnManager
      if (RaidBossSpawnManager.getInstance().isDefined(spawn.getId())) {
        activeChar.sendMessage("You cannot spawn another instance of " + template1.getName() + ".");
      } else {
        if (RaidBossSpawnManager.getInstance().getValidTemplate(spawn.getId()) != null) {
          spawn.setRespawnMinDelay(43200);
          spawn.setRespawnMaxDelay(129600);
          RaidBossSpawnManager.getInstance()
              .addNewSpawn(spawn, 0, template1.getBaseHpMax(), template1.getBaseMpMax(), permanent);
        } else {
          SpawnTable.getInstance().addNewSpawn(spawn, permanent);
          spawn.init();
        }
        if (!permanent) {
          spawn.stopRespawn();
        }
        activeChar.sendMessage("Created " + template1.getName() + " on " + target.getObjectId());
      }
    } catch (Exception e) {
      activeChar.sendPacket(SystemMessageId.TARGET_CANT_FOUND);
    }
  }
示例#3
0
  private RangeGuard() {
    super(RangeGuard.class.getSimpleName(), "ai/group_template");

    final List<L2NpcTemplate> monsters = NpcData.getInstance().getAllNpcOfClassType("L2Monster");
    for (L2NpcTemplate template : monsters) {
      if (template.hasParameters()
          && (template.getParameters().getInt("LongRangeGuardRate", -1) > 0)) {
        addAttackId(template.getId());
      }
    }
  }
示例#4
0
  public void loadDiary(int charId) {
    final List<StatsSet> _diary = new FastList<>();
    int diaryentries = 0;
    try (Connection con = L2DatabaseFactory.getInstance().getConnection();
        PreparedStatement statement =
            con.prepareStatement("SELECT * FROM  heroes_diary WHERE charId=? ORDER BY time ASC")) {
      statement.setInt(1, charId);
      try (ResultSet rset = statement.executeQuery()) {
        while (rset.next()) {
          StatsSet _diaryentry = new StatsSet();

          long time = rset.getLong("time");
          int action = rset.getInt("action");
          int param = rset.getInt("param");

          String date = (new SimpleDateFormat("yyyy-MM-dd HH")).format(new Date(time));
          _diaryentry.set("date", date);

          if (action == ACTION_RAID_KILLED) {
            L2NpcTemplate template = NpcData.getInstance().getTemplate(param);
            if (template != null) {
              _diaryentry.set("action", template.getName() + " was defeated");
            }
          } else if (action == ACTION_HERO_GAINED) {
            _diaryentry.set("action", "Gained Hero status");
          } else if (action == ACTION_CASTLE_TAKEN) {
            Castle castle = CastleManager.getInstance().getCastleById(param);
            if (castle != null) {
              _diaryentry.set("action", castle.getName() + " Castle was successfuly taken");
            }
          }
          _diary.add(_diaryentry);
          diaryentries++;
        }
      }
      _herodiary.put(charId, _diary);

      _log.info(
          "Hero System: Loaded "
              + diaryentries
              + " diary entries for Hero: "
              + CharNameTable.getInstance().getNameById(charId));
    } catch (SQLException e) {
      _log.log(Level.WARNING, "Hero System: Couldnt load Hero Diary for CharId: " + charId, e);
    }
  }
示例#5
0
  public void setRBkilled(int charId, int npcId) {
    setDiaryData(charId, ACTION_RAID_KILLED, npcId);

    L2NpcTemplate template = NpcData.getInstance().getTemplate(npcId);

    if (_herodiary.containsKey(charId) && (template != null)) {
      // Get Data
      List<StatsSet> _list = _herodiary.get(charId);
      // Clear old data
      _herodiary.remove(charId);
      // Prepare new data
      StatsSet _diaryentry = new StatsSet();
      String date =
          (new SimpleDateFormat("yyyy-MM-dd HH")).format(new Date(System.currentTimeMillis()));
      _diaryentry.set("date", date);
      _diaryentry.set("action", template.getName() + " was defeated");
      // Add to old list
      _list.add(_diaryentry);
      // Put new list into diary
      _herodiary.put(charId, _list);
    }
  }
示例#6
0
 public ConfirmDlg addNpcName(L2NpcTemplate tpl) {
   if (tpl.isCustom()) {
     return addString(tpl.getName());
   }
   return addNpcName(tpl.getNpcId());
 }