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

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


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

            int monsterTemplate = target.getTemplate().npcId;
            L2NpcTemplate template1 = NpcTable.getInstance().getTemplate(monsterTemplate);
            if (template1 == null)
            {
                activeChar.sendMessage("Incorrect monster template.");
                _log.warning("ERROR: NPC " + target.getObjectId() + " has a 'null' template.");
                return;
            }

            L2Spawn spawn = target.getSpawn();
            if (spawn == null)
            {
                activeChar.sendMessage("Incorrect monster spawn.");
                _log.warning("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);

                if (Config.DEBUG)
                {
                    _log.fine("Spawn at X="+spawn.getLocx()+" Y="+spawn.getLocy()+" Z="+spawn.getLocz());
                    _log.warning("GM: "+activeChar.getName()+"("+activeChar.getObjectId()+") moved NPC " + target.getObjectId());
                }
            }
            catch (Exception e)
            {
                activeChar.sendMessage("Target is not in game.");
View Full Code Here


                for (AutoChatDefinition chatDef : chatDefinitions)
                {
                    try
                    {
                        L2NpcInstance chatNpc = chatDef._npcInstance;
                        List<L2PcInstance> nearbyPlayers = new FastList<L2PcInstance>();
                        List<L2PcInstance> nearbyGMs = new FastList<L2PcInstance>();

                        for (L2Character player : chatNpc.getKnownList().getKnownCharactersInRadius(1500))
                        {
                            if (!(player instanceof L2PcInstance)) continue;

                            if (((L2PcInstance) player).isGM()) nearbyGMs.add((L2PcInstance) player);
                            else nearbyPlayers.add((L2PcInstance) player);
                        }

                        int maxIndex = chatDef.getChatTexts().length;
                        int lastIndex = Rnd.nextInt(maxIndex);

                        String creatureName = chatNpc.getName();
                        String text;

                        if (!chatDef.isRandomChat())
                        {
                            lastIndex = chatDef._chatIndex;
                            lastIndex++;

                            if (lastIndex == maxIndex) lastIndex = 0;

                            chatDef._chatIndex = lastIndex;
                        }

                        text = chatDef.getChatTexts()[lastIndex];

                        if (text == null) return;

                        if (!nearbyPlayers.isEmpty())
                        {
                            int randomPlayerIndex = Rnd.nextInt(nearbyPlayers.size());

                            L2PcInstance randomPlayer = nearbyPlayers.get(randomPlayerIndex);

                            final int winningCabal = SevenSigns.getInstance().getCabalHighestScore();
                            int losingCabal = SevenSigns.CABAL_NULL;

                            if (winningCabal == SevenSigns.CABAL_DAWN) losingCabal = SevenSigns.CABAL_DUSK;
                            else if (winningCabal == SevenSigns.CABAL_DUSK)
                                losingCabal = SevenSigns.CABAL_DAWN;

                            if (text.indexOf("%player_random%") > -1)
                                text = text.replaceAll("%player_random%", randomPlayer.getName());

                            if (text.indexOf("%player_cabal_winner%") > -1)
                            {
                                for (L2PcInstance nearbyPlayer : nearbyPlayers)
                                {
                                    if (SevenSigns.getInstance().getPlayerCabal(nearbyPlayer) == winningCabal)
                                    {
                                        text = text.replaceAll("%player_cabal_winner%",
                                                               nearbyPlayer.getName());
                                        break;
                                    }
                                }
                            }

                            if (text.indexOf("%player_cabal_loser%") > -1)
                            {
                                for (L2PcInstance nearbyPlayer : nearbyPlayers)
                                {
                                    if (SevenSigns.getInstance().getPlayerCabal(nearbyPlayer) == losingCabal)
                                    {
                                        text = text.replaceAll("%player_cabal_loser%",
                                                               nearbyPlayer.getName());
                                        break;
                                    }
                                }
                            }
                        }

                        if (text == null) return;

                        if (text.contains("%player_cabal_loser%")
                            || text.contains("%player_cabal_winner%")
                            || text.contains("%player_random%")) return;

                        CreatureSay cs = new CreatureSay(chatNpc.getObjectId(), 0, creatureName, text);

                        for (L2PcInstance nearbyPlayer : nearbyPlayers)
                            nearbyPlayer.sendPacket(cs);
                        for (L2PcInstance nearbyGM : nearbyGMs)
                            nearbyGM.sendPacket(cs);

                        if (Config.DEBUG)
                            _log.fine("AutoChatHandler: Chat propogation for object ID "
                                + chatNpc.getObjectId() + " (" + creatureName + ") with text '" + text
                                + "' sent to " + nearbyPlayers.size() + " nearby players.");
                    }
                    catch (Exception e)
                    {
                        e.printStackTrace();
View Full Code Here

       return name;

   }

   void destroyEventNpcs(){
       L2NpcInstance npc;
       while(L2Event.npcs.size()>0){
           try{
               npc = (L2NpcInstance) L2World.getInstance().findObject(Integer.parseInt(L2Event.npcs.getFirst()));


           L2Spawn spawn = npc.getSpawn();

           if (spawn != null)
           {
               spawn.stopRespawn();
               SpawnTable.getInstance().deleteSpawn(spawn, true);
           }
           npc.deleteMe();
           L2Event.npcs.removeFirst();}catch(Exception e) {L2Event.npcs.removeFirst();}
       }
   }
View Full Code Here

  {
    L2Object obj = activeChar.getTarget();
    if (obj == null) return;
    if (obj instanceof L2NpcInstance)
    {
      L2NpcInstance temp = (L2NpcInstance) obj;
      temp.setTarget(activeChar);
      temp.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO,
          new L2CharPosition(activeChar.getX(),activeChar.getY(), activeChar.getZ(), 0 ));
//      temp.moveTo(player.getX(),player.getY(), player.getZ(), 0 );
    }

  }
View Full Code Here

        _log.fine("Deleting all visible NPC's in Region: " + getName());
        for (L2Object obj : _visibleObjects)
        {
            if (obj instanceof L2NpcInstance)
            {
                L2NpcInstance target = (L2NpcInstance) obj;
                target.deleteMe();
                L2Spawn spawn = target.getSpawn();
                if (spawn != null)
                {
                    spawn.stopRespawn();
                    SpawnTable.getInstance().deleteSpawn(spawn, false);
                }
                _log.finest("Removed NPC " + target.getObjectId());
            }
        }
        _log.info("All visible NPC's deleted in Region: " + getName());
    }
View Full Code Here

        }

        // Add the new spawn information to the spawn table, but do not
        // store it.
        SpawnTable.getInstance().addNewSpawn(newSpawn, false);
        L2NpcInstance npcInst = null;

        if (spawnInst._spawnCount == 1)
        {
          npcInst = newSpawn.doSpawn();
          npcInst.setXYZ(npcInst.getX(), npcInst.getY(), npcInst.getZ());
          spawnInst.addNpcInstance(npcInst);
        } else
        {
          for (int i = 0; i < spawnInst._spawnCount; i++)
          {
            npcInst = newSpawn.doSpawn();

            // To prevent spawning of more than one NPC in the exact
            // same spot,
            // move it slightly by a small random offset.
            npcInst.setXYZ(npcInst.getX() + Rnd.nextInt(50), npcInst.getY() + Rnd.nextInt(50),
                npcInst.getZ());

            // Add the NPC instance to the list of managed
            // instances.
            spawnInst.addNpcInstance(npcInst);
          }
        }

        String nearestTown = MapRegionTable.getInstance().getClosestTownName(npcInst);

        // Announce to all players that the spawn has taken place, with
        // the nearest town location.
        if (spawnInst.isBroadcasting())
          Announcements.getInstance().announceToAll("The " + npcInst.getName() + " has spawned near "
              + nearestTown + "!");

        if (Config.DEBUG)
          _log.info("AutoSpawnHandler: Spawned NPC ID "
              + spawnInst.getNpcId() + " at " + x + ", " + y
View Full Code Here

                }
                _log.info("DayNightSpawnManager: Deleted " + i + " "+UnspawnLogInfo+" creatures");
            }

            int i = 0;
            L2NpcInstance creature = null;
            for (L2Spawn spawnDat : SpawnCreatures.keySet())
            {
                if (SpawnCreatures.get(spawnDat) == null)
                {
                    creature = spawnDat.doSpawn();
                    if (creature == null) continue;

                    SpawnCreatures.remove(spawnDat);
                    SpawnCreatures.put(spawnDat, creature);
                    creature.setCurrentHp(creature.getMaxHp());
                    creature.setCurrentMp(creature.getMaxMp());
          creature = SpawnCreatures.get(spawnDat);
          creature.getSpawn().startRespawn();
                }
                else
                {
                    creature = SpawnCreatures.get(spawnDat);
                    if (creature == null) continue;

                    creature.getSpawn().startRespawn();
                    creature.setCurrentHp(creature.getMaxHp());
                    creature.setCurrentMp(creature.getMaxMp());
                    creature.spawnMe();
                }

                i++;
            }
View Full Code Here

        {
            if (cha == null) continue;

            if (!(cha instanceof L2NpcInstance)) continue;

            L2NpcInstance npc = (L2NpcInstance) cha;

            if (faction_id != npc.getFactionId()) continue;

            // Check if the L2Object is inside the Faction Range of the actor
            if ((npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE || npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE)
                && _actor.isInsideRadius(npc, npc.getFactionRange(), false, true)
                && npc.getTarget() == null
                && _attackTarget.isInsideRadius(npc, npc.getFactionRange(), false, true)
                )
            {
                if (Config.GEODATA > 0)
                {
                  if (GeoData.getInstance().canSeeTarget(npc, _attackTarget))
                    // Notify the L2Object AI with EVT_AGGRESSION
                        npc.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, _attackTarget, 1);
                }
                else
                {
                  if (Math.abs(_attackTarget.getZ() - npc.getZ()) < 600)
                    // Notify the L2Object AI with EVT_AGGRESSION
                        npc.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, _attackTarget, 1);
                }
            }
        }
    }
View Full Code Here

        for (L2Object obj : _actor.getKnownList().getKnownObjects().values())
                {
                    if (!(obj instanceof L2NpcInstance))
                        continue;

                    L2NpcInstance npc = (L2NpcInstance) obj;

                    if (faction_id != npc.getFactionId())
                        continue;

                    if (_actor.isInsideRadius(npc, npc.getFactionRange(), false, true)
                            && Math.abs(getAttackTarget().getZ() - npc.getZ()) < 200)
                    {
                        npc.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, getAttackTarget(), 1);
                    }
        }
      }

      L2Skill[] skills = null;
View Full Code Here

                        // Check if player's clan is attacker
                        List<L2NpcInstance> flags = castle.getSiege().getFlag(player.getClan());
                        if (flags != null && !flags.isEmpty())
                        {
                            // Spawn to flag - Need more work to get player to the nearest flag
                            L2NpcInstance flag = flags.get(0);
                            return new Location(flag.getX(), flag.getY(), flag.getZ());
                        }
                    }
                }
            }
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.