Package com.l2jfrozen.gameserver.model

Examples of com.l2jfrozen.gameserver.model.L2Attackable$RewardItem


                _Nurses.add((L2MonsterInstance) addSpawn(NURSE, npc.getX(), npc.getY(), npc.getZ(), 0, true, 0));
            }
            break;
            case DESPAWN_MINIONS: {
                for (int i = 0; i < _Minions.size(); i++) {
                    L2Attackable mob = _Minions.get(i);
                    if (mob != null) {
                        mob.decayMe();
                    }
                }
                for (int k = 0; k < _Nurses.size(); k++) {
                    L2MonsterInstance _nurse = _Nurses.get(k);
                    if (_nurse != null)
                        _nurse.decayMe();
                }
                _Nurses.clear();
                _Minions.clear();
            }
            break;
            case CHECK_MINIONS_ZONE: {
                for (int i = 0; i < _Minions.size(); i++) {
                    L2Attackable mob = _Minions.get(i);

                    if (mob != null && !mob.isInsideRadius(npc.getX(), npc.getY(), 700, false))/* !_Zone.isInsideZone(mob)) */ {
                        mob.teleToLocation(npc.getX(), npc.getY(), npc.getZ());
                    }
                }
            }
            break;
            case CHECK_NURSE_ALIVE: {
View Full Code Here


            if(Rnd.get(100) < 33) //mobs that summon minions only on certain chance
            {
              Integer[] minions = MINIONS.get(npcId);
              for(Integer minion : minions)
              {
                L2Attackable newNpc = (L2Attackable) this.addSpawn(minion, (npc.getX() + Rnd.get(-150, 150)), (npc.getY() + Rnd.get(-150, 150)), npc.getZ(), 0, false, 0);
                newNpc.setRunning();
                newNpc.addDamageHate(attacker, 0, 999);
                newNpc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker);
              }
              minions = null;
            }
          }
        }
        else if(npcId == 22257 || npcId == 22258 || npcId == 22259 || npcId == 22260 || npcId == 22261 || npcId == 22262 || npcId == 22263 || npcId == 22264 || npcId == 22265 || npcId == 22266)
        {
          if(isPet)
          {
            attacker = attacker.getPet().getOwner();
          }
          if(attacker.getParty() != null)
          {
            for(L2PcInstance member : attacker.getParty().getPartyMembers())
            {
              if(_attackersList.get(npcObjId) == null)
              {
                FastList<L2PcInstance> player = new FastList<L2PcInstance>();
                player.add(member);
                _attackersList.put(npcObjId, player);
              }
              else if(!_attackersList.get(npcObjId).contains(member))
              {
                _attackersList.get(npcObjId).add(member);
              }
            }
          }
          else
          {
            if(_attackersList.get(npcObjId) == null)
            {
              FastList<L2PcInstance> player = new FastList<L2PcInstance>();
              player.add(attacker);
              _attackersList.put(npcObjId, player);
            }
            else if(!_attackersList.get(npcObjId).contains(attacker))
            {
              _attackersList.get(npcObjId).add(attacker);
            }
          }
          if((attacker.getParty() != null) && attacker.getParty().getMemberCount() > 2 || _attackersList.get(npcObjId).size() > 2) //Just to make sure..
          {
            HasSpawned = 0;
            Integer[] minions = MINIONS.get(npcId);
            for(Integer minion : minions)
            {
              L2Attackable newNpc = (L2Attackable) addSpawn(minion, npc.getX() + Rnd.get(-150, 150), npc.getY() + Rnd.get(-150, 150), npc.getZ(), 0, false, 0);
              newNpc.setRunning();
              newNpc.addDamageHate(attacker, 0, 999);
              newNpc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker);
            }
            minions = null;
          }
        }
        else
        //mobs without special conditions
        {
          HasSpawned = 0;
          Integer[] minions = MINIONS.get(npcId);
          if(npcId != 20767)
          {
            for(Integer minion : minions)
            {
              L2Attackable newNpc = (L2Attackable) this.addSpawn(minion, npc.getX() + Rnd.get(-150, 150), npc.getY() + Rnd.get(-150, 150), npc.getZ(), 0, false, 0);
              newNpc.setRunning();
              newNpc.addDamageHate(attacker, 0, 999);
              newNpc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker);
            }
          }
          else
          {
            for(Integer minion : minions)
View Full Code Here

    for(int index = 0; index < targets.length; index++)
    {
      if(!(targets[index] instanceof L2Attackable))
        continue;

      L2Attackable target = (L2Attackable) targets[index];
      L2Attackable.RewardItem[] items = null;
      boolean isSweeping = false;
      synchronized (target)
      {
        if(target.isSweepActive())
        {
          items = target.takeSweep();
          isSweeping = true;
        }
      }

      if(isSweeping)
      {
        if(items == null || items.length == 0)
          continue;
        for(L2Attackable.RewardItem ritem : items)
        {
          if(player.isInParty())
            player.getParty().distributeItem(player, ritem, true, target);
          else
          {
            L2ItemInstance item = player.getInventory().addItem("Sweep", ritem.getItemId(), ritem.getCount(), player, target);
            if(iu != null)
              iu.addItem(item);
            send = true;
            item = null;

            SystemMessage smsg;

            if(ritem.getCount() > 1)
            {
              smsg = new SystemMessage(SystemMessageId.EARNED_S2_S1_S); // earned $s2$s1
              smsg.addItemName(ritem.getItemId());
              smsg.addNumber(ritem.getCount());
            }
            else
            {
              smsg = new SystemMessage(SystemMessageId.EARNED_ITEM); // earned $s1
              smsg.addItemName(ritem.getItemId());
            }
            player.sendPacket(smsg);
            smsg = null;
          }
        }
      }
      target.endDecayTask();

      if(send)
      {
        if(iu != null)
          player.sendPacket(iu);
View Full Code Here

  private L2Character _forcedTarget;
  private MobGroup _targetGroup;

  protected void thinkFollow()
  {
    L2Attackable me = (L2Attackable) _actor;

    if(!Util.checkIfInRange(MobGroupTable.FOLLOW_RANGE, me, getForcedTarget(), true))
    {
      int signX = Rnd.nextInt(2) == 0 ? -1 : 1;
      int signY = Rnd.nextInt(2) == 0 ? -1 : 1;
View Full Code Here

    if(getAttackTarget() == null || getAttackTarget().isAlikeDead())
    {
      if(getAttackTarget() != null)
      {
        // stop hating
        L2Attackable npc = (L2Attackable) _actor;
        npc.stopHating(getAttackTarget());
        npc = null;
      }

      setIntention(AI_INTENTION_ACTIVE);
    }
    else
    {
      // notify aggression
      if(((L2NpcInstance) _actor).getFactionId() != null)
      {
        for(L2Object obj : _actor.getKnownList().getKnownObjects().values())
        {
          if(!(obj instanceof L2NpcInstance))
          {
            continue;
          }

          L2NpcInstance npc = (L2NpcInstance) obj;
          String faction_id = ((L2NpcInstance) _actor).getFactionId();

          if(!faction_id.equalsIgnoreCase(npc.getFactionId()))
          {
            continue;
          }

          faction_id = null;

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

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

    L2Attackable me = (L2Attackable) _actor;

    if(target instanceof L2FolkInstance || target instanceof L2DoorInstance)
      return false;

    if(target.isAlikeDead() || !me.isInsideRadius(target, me.getAggroRange(), false, false) || Math.abs(_actor.getZ() - target.getZ()) > 100)
      return false;

    // Check if the target isn't invulnerable
    if(target.isInvul())
      return false;

    // Check if the target is a L2PcInstance
    if(target instanceof L2PcInstance)
    {
      // Check if the target isn't in silent move mode
      if(((L2PcInstance) target).isSilentMoving())
        return false;
    }

    if(target instanceof L2NpcInstance)
      return false;

    return me.isAggressive();
  }
View Full Code Here

  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

  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().canTakeAggro())
        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;

      //if in offline mode
      if(((L2PcInstance) target).isOffline())
        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;

      // check player is in away mod
      if(((L2PcInstance) target).isAway() && !Config.AWAY_PLAYER_TAKE_AGGRO)
        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 target is a L2Summon
    if (target instanceof L2Summon)
    {
      L2PcInstance owner = ((L2Summon) target).getOwner();
      if (owner != null)
      {
        // Don't take the aggro if the GM has the access level below or equal to GM_DONT_TAKE_AGGRO
        if (owner.isGM() && (owner.isInvul() || !owner.getAccessLevel().canTakeAggro()))
          return false;
        // Check if player is an ally (comparing mem addr)   
        if (me.getFactionId() == "varka" && owner.isAlliedWithVarka())
          return false;
        if (me.getFactionId() == "ketra" && owner.isAlliedWithKetra())
          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(L2Character.isInsidePeaceZone(me,target))
        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;
        }

        npc = null;
View Full Code Here

   * location</li> <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;
          }

          targetPlayer = null;
        }

        if(obj instanceof L2PcInstance
          || obj instanceof L2Summon)
        {
          if(!target.isAlikeDead() && !npc.isInsideRadius(obj, npc.getAggroRange(), true, false))
          {
            L2PcInstance targetPlayer = obj instanceof L2PcInstance ? (L2PcInstance) obj : ((L2Summon) obj).getOwner();

            for(Quest quest : npc.getTemplate().getEventQuests(Quest.QuestEventType.ON_AGGRO_RANGE_ENTER))
            {
              quest.notifyAggroRangeEnter(npc, targetPlayer, obj instanceof L2Summon);
            }
          }
        }

        // 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);
          }
        }

        target = null;
      }

      // Chose a target from its aggroList
      L2Character hated;

      // Force mobs to attak anybody if confused
      if(_actor.isConfused())
      {
        hated = getAttackTarget();
      }
      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;

    // Check if the mob should not return to spawn point
    if(!npc.canReturnToSpawnPoint())
      return;

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

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

      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 instanceof L2ChestInstance) && 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(TerritoryTable.getInstance().getProcMax(npc.getSpawn().getLocation()) > 0)
          return;

        // Calculate a destination point in the spawn area
        int p[] = TerritoryTable.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(Config.MONSTER_RETURN_DELAY > 0 && npc instanceof L2MonsterInstance && !npc.isAlikeDead() && !npc.isDead() && npc.getSpawn() != null && !npc.isInsideRadius(npc.getSpawn().getLocx(), npc.getSpawn().getLocy(), Config.MAX_DRIFT_RANGE, false))
        {
          ((L2MonsterInstance) _actor).returnHome();
        }

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

TOP

Related Classes of com.l2jfrozen.gameserver.model.L2Attackable$RewardItem

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.