Package ai

Source Code of ai.RndTeleportFighter

package ai;

import l2p.Config;
import l2p.common.ThreadPoolManager;
import l2p.gameserver.ai.Fighter;
import l2p.gameserver.geodata.GeoEngine;
import l2p.gameserver.model.L2Character;
import l2p.gameserver.model.L2Spawn;
import l2p.gameserver.model.instances.L2NpcInstance;
import l2p.gameserver.serverpackets.MagicSkillUse;
import l2p.gameserver.tables.TerritoryTable;
import l2p.util.Location;
import l2p.util.Rnd;

/**
* Моб использует телепортацию вместо рандом валка.
*
* @author SYS
*/
public class RndTeleportFighter extends Fighter
{
  private long _lastTeleport;

  public RndTeleportFighter(L2Character actor)
  {
    super(actor);
  }

  @Override
  protected boolean maybeMoveToHome()
  {
    L2NpcInstance actor = getActor();
    if(actor == null || System.currentTimeMillis() - _lastTeleport < 10000)
    {
      return false;
    }
    boolean randomWalk = actor.hasRandomWalk();
    Location sloc = actor.getSpawnedLoc();
    if(sloc == null)
    {
      return false;
    }
    // Random walk or not?
    if(randomWalk && (!Config.RND_WALK || Rnd.chance(Config.RND_WALK_RATE)))
    {
      return false;
    }
    if(!randomWalk && actor.isInRangeZ(sloc, Config.MAX_DRIFT_RANGE))
    {
      return false;
    }
    int x = sloc.x + Rnd.get(-Config.MAX_DRIFT_RANGE, Config.MAX_DRIFT_RANGE);
    int y = sloc.y + Rnd.get(-Config.MAX_DRIFT_RANGE, Config.MAX_DRIFT_RANGE);
    int z = GeoEngine.getHeight(x, y, sloc.z, actor.getReflection().getGeoIndex());
    if(sloc.z - z > 64)
    {
      return false;
    }
    L2Spawn spawn = actor.getSpawn();
    if(spawn != null && spawn.getLocation() != 0 && !TerritoryTable.getInstance().getLocation(spawn.getLocation()).isInside(x, y))
    {
      return false;
    }
    actor.broadcastPacketToOthers(new MagicSkillUse(actor, actor, 4671, 1, 500, 0));
    ThreadPoolManager.getInstance().scheduleAi(new Teleport(new Location(x, y, z)), 500, false);
    _lastTeleport = System.currentTimeMillis();
    return true;
  }
}
TOP

Related Classes of ai.RndTeleportFighter

TOP
Copyright © 2018 www.massapi.com. 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.