Package net.sf.l2j.gameserver.model

Examples of net.sf.l2j.gameserver.model.L2Attackable


  }

  private L2Character findNextRndTarget()
    {
        int aggroRange  = ((L2Attackable)_actor).getAggroRange();
        L2Attackable npc = (L2Attackable)_actor;
        int npcX, npcY, targetX, targetY;
        double dy, dx;
        double dblAggroRange = aggroRange*aggroRange;

    List<L2Character> potentialTarget = new FastList<L2Character>();

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

            npcX    = npc.getX();
            npcY    = npc.getY();
            targetX = obj.getX();
            targetY = obj.getY();

            dx      = npcX - targetX;
            dy      = npcY - targetY;
View Full Code Here


     * @return
     */
    private boolean autoAttackCondition(L2Character target)
    {
        if (target == null || !(_actor instanceof L2Attackable)) return false;
        L2Attackable me = (L2Attackable) _actor;

        // Check if the target isn't invulnerable
        if (target.isInvul())
        {
            // However EffectInvincible requires to check GMs specially
          if (target instanceof L2PcInstance && ((L2PcInstance)target).isGM())
                return false;
            if (target instanceof L2Summon && ((L2Summon)target).getOwner().isGM())
                return false;
        }

        // Check if the target isn't a Folk or a Door
        if (target instanceof L2FolkInstance || target instanceof L2DoorInstance) return false;

        // Check if the target isn't dead, is in the Aggro range and is at the same height
        if (target.isAlikeDead()
            || !me.isInsideRadius(target, me.getAggroRange(), false, false)
            || Math.abs(_actor.getZ() - target.getZ()) > 300) return false;

        // Check if the target is a L2PcInstance
        if (target instanceof L2PcInstance)
        {
            // Don't take the aggro if the GM has the access level below or equal to GM_DONT_TAKE_AGGRO
            if (((L2PcInstance)target).isGM() && ((L2PcInstance)target).getAccessLevel() <= Config.GM_DONT_TAKE_AGGRO)
                return false;

            // Check if the AI isn't a Raid Boss and the target isn't in silent move mode
            if (!(me instanceof L2RaidBossInstance) && ((L2PcInstance)target).isSilentMoving())
                return false;

            // Check if player is an ally //TODO! [Nemesiss] it should be rather boolean or smth like that
            // Comparing String isnt good idea!
            if (me.getFactionId() == "varka" && ((L2PcInstance)target).isAlliedWithVarka())
                return false;
            if (me.getFactionId() == "ketra" && ((L2PcInstance)target).isAlliedWithKetra())
                return false;
            // check if the target is within the grace period for JUST getting up from fake death
            if (((L2PcInstance)target).isRecentFakeDeath())
                return false;

            if (target.isInParty() && target.getParty().isInDimensionalRift())
            {
                byte riftType = target.getParty().getDimensionalRift().getType();
                byte riftRoom = target.getParty().getDimensionalRift().getCurrentRoom();

                if (me instanceof L2RiftInvaderInstance
                        && !DimensionalRiftManager.getInstance().getRoom(riftType, riftRoom).checkIfInZone(me.getX(), me.getY(), me.getZ()))
                    return false;
            }
        }

        // Check if the actor is a L2GuardInstance
        if (_actor instanceof L2GuardInstance)
        {

            // Check if the L2PcInstance target has karma (=PK)
            if (target instanceof L2PcInstance && ((L2PcInstance) target).getKarma() > 0)
                // Los Check
                return GeoData.getInstance().canSeeTarget(me, target);

            //if (target instanceof L2Summon)
            //    return ((L2Summon)target).getKarma() > 0;

            // Check if the L2MonsterInstance target is aggressive
            if (target instanceof L2MonsterInstance)
                return (((L2MonsterInstance) target).isAggressive() && GeoData.getInstance().canSeeTarget(me, target));

            return false;
        }
        else if (_actor instanceof L2FriendlyMobInstance)
        { // the actor is a L2FriendlyMobInstance

            // Check if the target isn't another L2NpcInstance
            if (target instanceof L2NpcInstance) return false;

            // Check if the L2PcInstance target has karma (=PK)
            if (target instanceof L2PcInstance && ((L2PcInstance) target).getKarma() > 0)
                // Los Check
               return GeoData.getInstance().canSeeTarget(me, target);
      return false;
        }
        else
        { //The actor is a L2MonsterInstance

            // Check if the target isn't another L2NpcInstance
            if (target instanceof L2NpcInstance) return false;

            // depending on config, do not allow mobs to attack _new_ players in peacezones,
            // unless they are already following those players from outside the peacezone.
            if (!Config.ALT_MOB_AGRO_IN_PEACEZONE && target.isInsideZone(L2Character.ZONE_PEACE))
                return false;

            // Check if the actor is Aggressive
            return (me.isAggressive() && GeoData.getInstance().canSeeTarget(me, target));
        }
    }
View Full Code Here

        if (intention == AI_INTENTION_IDLE || intention == AI_INTENTION_ACTIVE)
        {
            // Check if actor is not dead
            if (!_actor.isAlikeDead())
            {
                L2Attackable npc = (L2Attackable) _actor;

                // If its _knownPlayer isn't empty set the Intention to AI_INTENTION_ACTIVE
                if (npc.getKnownList().getKnownPlayers().size() > 0) intention = AI_INTENTION_ACTIVE;
            }

            if (intention == AI_INTENTION_IDLE)
            {
                // Set the Intention of this L2AttackableAI to AI_INTENTION_IDLE
View Full Code Here

     * <li>If the actor is a L2MonsterInstance that can't attack, order to it to random walk (1/100)</li><BR><BR>
     *
     */
    private void thinkActive()
    {
        L2Attackable npc = (L2Attackable) _actor;

        // Update every 1s the _globalAggro counter to come close to 0
        if (_globalAggro != 0)
        {
            if (_globalAggro < 0) _globalAggro++;
            else _globalAggro--;
        }

        // Add all autoAttackable L2Character in L2Attackable Aggro Range to its _aggroList with 0 damage and 1 hate
        // A L2Attackable isn't aggressive during 10s after its spawn because _globalAggro is set to -10
        if (_globalAggro >= 0)
        {
            // Get all visible objects inside its Aggro Range
            //L2Object[] objects = L2World.getInstance().getVisibleObjects(_actor, ((L2NpcInstance)_actor).getAggroRange());
            // Go through visible objects
            for (L2Object obj : npc.getKnownList().getKnownObjects().values())
            {
                if (obj == null || !(obj instanceof L2Character)) continue;
                L2Character target = (L2Character) obj;

                /*
                 * Check to see if this is a festival mob spawn.
                 * If it is, then check to see if the aggro trigger
                 * is a festival participant...if so, move to attack it.
                 */
                if ((_actor instanceof L2FestivalMonsterInstance) && obj instanceof L2PcInstance)
                {
                    L2PcInstance targetPlayer = (L2PcInstance) obj;

                    if (!(targetPlayer.isFestivalParticipant())) continue;
                }

                // For each L2Character check if the target is autoattackable
                if (autoAttackCondition(target)) // check aggression
                {
                    // Get the hate level of the L2Attackable against this L2Character target contained in _aggroList
                    int hating = npc.getHating(target);

                    // Add the attacker to the L2Attackable _aggroList with 0 damage and 1 hate
                    if (hating == 0) npc.addDamageHate(target, 0, 1);
                }
            }

            // Chose a target from its aggroList
            L2Character hated;
            if (_actor.isConfused()) hated = getAttackTarget(); // Force mobs to attak anybody if confused
            else hated = npc.getMostHated();

            // Order to the L2Attackable to attack the target
            if (hated != null)
            {
                // Get the hate level of the L2Attackable against this L2Character target contained in _aggroList
                int aggro = npc.getHating(hated);

                if (aggro + _globalAggro > 0)
                {
                    // Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
                    if (!_actor.isRunning()) _actor.setRunning();

                    // Set the AI Intention to AI_INTENTION_ATTACK
                    setIntention(CtrlIntention.AI_INTENTION_ATTACK, hated);
                }

                return;
            }

        }

        // Check if the actor is a L2GuardInstance
        if (_actor instanceof L2GuardInstance)
        {
            // Order to the L2GuardInstance to return to its home location because there's no target to attack
            ((L2GuardInstance) _actor).returnHome();
        }

        // If this is a festival monster, then it remains in the same location.
        if (_actor instanceof L2FestivalMonsterInstance) return;

        // Minions following leader
        if (_actor instanceof L2MinionInstance && ((L2MinionInstance)_actor).getLeader() != null)
        {
            int offset;

            if (_actor.isRaid()) offset = 500; // for Raids - need correction
            else offset = 200; // for normal minions - need correction :)

            if(((L2MinionInstance)_actor).getLeader().isRunning())  _actor.setRunning();
            else _actor.setWalking();

            if (_actor.getPlanDistanceSq(((L2MinionInstance)_actor).getLeader()) > offset*offset)
            {
                int x1, y1, z1;
                x1 = ((L2MinionInstance)_actor).getLeader().getX() + Rnd.nextInt( (offset - 30) * 2 ) - ( offset - 30 );
                y1 = ((L2MinionInstance)_actor).getLeader().getY() + Rnd.nextInt( (offset - 30) * 2 ) - ( offset - 30 );
                z1 = ((L2MinionInstance)_actor).getLeader().getZ();
                // Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)
                moveTo(x1, y1, z1);
                return;
            }
        }
        // Order to the L2MonsterInstance to random walk (1/100)
        else if (npc.getSpawn() != null && Rnd.nextInt(RANDOM_WALK_RATE) == 0)
        {
            int x1, y1, z1;

            // If NPC with random coord in territory
            if (npc.getSpawn().getLocx() == 0 && npc.getSpawn().getLocy() == 0)
            {
                // If NPC with random fixed coord, don't move
                if (Territory.getInstance().getProcMax(npc.getSpawn().getLocation()) > 0) return;

                // Calculate a destination point in the spawn area
                int p[] = Territory.getInstance().getRandomPoint(npc.getSpawn().getLocation());
                x1 = p[0];
                y1 = p[1];
                z1 = p[2];

                // Calculate the distance between the current position of the L2Character and the target (x,y)
                double distance2 = _actor.getPlanDistanceSq(x1, y1);

                if (distance2 > Config.MAX_DRIFT_RANGE * Config.MAX_DRIFT_RANGE)
                {
                    npc.setisReturningToSpawnPoint(true);
                  float delay = (float) Math.sqrt(distance2) / Config.MAX_DRIFT_RANGE;
                    x1 = _actor.getX() + (int) ((x1 - _actor.getX()) / delay);
                    y1 = _actor.getY() + (int) ((y1 - _actor.getY()) / delay);
                }
                else
                  npc.setisReturningToSpawnPoint(false);

            }
            else
            {
                // If NPC with fixed coord
                x1 = npc.getSpawn().getLocx() + Rnd.nextInt(Config.MAX_DRIFT_RANGE * 2)
                    - Config.MAX_DRIFT_RANGE;
                y1 = npc.getSpawn().getLocy() + Rnd.nextInt(Config.MAX_DRIFT_RANGE * 2)
                    - Config.MAX_DRIFT_RANGE;
                z1 = npc.getZ();
            }

            //_log.config("Curent pos ("+getX()+", "+getY()+"), moving to ("+x1+", "+y1+").");
            // Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)
            moveTo(x1, y1, z1);
View Full Code Here

            || _attackTimeout < GameTimeController.getGameTicks())
        {
            // Stop hating this target after the attack timeout or if target is dead
            if (getAttackTarget() != null)
            {
                L2Attackable npc = (L2Attackable) _actor;
                npc.stopHating(getAttackTarget());
            }

            // Set the AI Intention to AI_INTENTION_ACTIVE
            setIntention(AI_INTENTION_ACTIVE);

            _actor.setWalking();
        }
        else
        {
            // Call all L2Object of its Faction inside the Faction Range
            if (((L2NpcInstance) _actor).getFactionId() != null)
            {
                String faction_id = ((L2NpcInstance) _actor).getFactionId();

                // 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

     *
     */
    @Override
  protected void onEvtAggression(L2Character target, int aggro)
    {
        L2Attackable me = (L2Attackable) _actor;

      if (target != null)
        {
            // Add the target to the actor _aggroList or update hate if already present
            me.addDamageHate(target, 0, aggro);

            // Set the actor AI Intention to AI_INTENTION_ATTACK
            if (getIntention() != CtrlIntention.AI_INTENTION_ATTACK)
            {
                // Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
View Full Code Here

TOP

Related Classes of net.sf.l2j.gameserver.model.L2Attackable

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.