03-13-2017, 12:07 AM
Проблема такая, по задумке - гварды должны атаковать вражескую фракцию и не бить свою, так и есть, но бывает так, после того как убьют врага, переключает атаку на игрока своей фракции, так быть не должно.
Яву не особо хорошо знаю, но код вроде как верный, может быть что-то упустил, посмотрите пожалуйста, подскажите, где может быть проблема ?
Яву не особо хорошо знаю, но код вроде как верный, может быть что-то упустил, посмотрите пожалуйста, подскажите, где может быть проблема ?
AI Ranger
[SRC="java"]package l2p.gameserver.ai;
import l2p.gameserver.geodata.GeoEngine;
import l2p.gameserver.model.AggroList;
import l2p.gameserver.model.Creature;
import l2p.gameserver.model.Player;
import l2p.gameserver.model.instances.MonsterInstance;
import l2p.gameserver.model.instances.NpcInstance;
public class Ranger extends DefaultAI
{
public Ranger(NpcInstance actor)
{
super(actor);
}
@Override
protected boolean thinkActive()
{
return super.thinkActive() || defaultThinkBuff(10);
}
@Override
protected void onEvtAttacked(Creature attacker, int damage)
{
super.onEvtAttacked(attacker, damage);
NpcInstance actor = getActor();
if(actor.isDead() || attacker == null || actor.getDistance(attacker) > 200)
return;
if(actor.isMoving)
return;
int posX = actor.getX();
int posY = actor.getY();
int posZ = actor.getZ();
int old_posX = posX;
int old_posY = posY;
int old_posZ = posZ;
int signx = posX < attacker.getX() ? -1 : 1;
int signy = posY < attacker.getY() ? -1 : 1;
// int range = (int) ((actor.calculateAttackSpeed() /1000 * actor.getWalkSpeed() )* 0.71); // was "actor.getPhysicalAttackRange()" 0.71 = sqrt(2) / 2
int range = (int) (0.71 * actor.calculateAttackDelay() / 1000 * actor.getMoveSpeed());
posX += signx * range;
posY += signy * range;
posZ = GeoEngine.getHeight(posX, posY, posZ, actor.getGeoIndex());
if(GeoEngine.canMoveToCoord(old_posX, old_posY, old_posZ, posX, posY, posZ, actor.getGeoIndex()))
{
addTaskMove(posX, posY, posZ, false);
addTaskAttack(attacker);
}
}
public boolean canAttackCharacter(Creature target)
{
NpcInstance actor = getActor();
if(getIntention() == CtrlIntention.AI_INTENTION_ATTACK)
{
AggroList.AggroInfo ai = actor.getAggroList().get(target);
return ai != null && ai.hate > 0;
}
if(target instanceof Player)
{
if(target.getFactionId() == actor.getFactionId())
return false;
}
return target.isMonster() || target.isPlayable();
}
public boolean checkAggression(Creature target)
{
NpcInstance actor = getActor();
if(getIntention() != CtrlIntention.AI_INTENTION_ACTIVE || !isGlobalAggro())
return false;
if(target.isPlayable())
{
if(target.getFactionId() == actor.getFactionId())
return false;
}
if(target.isMonster())
{
if(!((MonsterInstance)target).isAggressive())
return false;
}
return super.checkAggression(target);
}
@Override
protected boolean createNewTask()
{
return defaultFightTask();
}
@Override
public int getRatePHYS()
{
return 25;
}
@Override
public int getRateDOT()
{
return 40;
}
@Override
public int getRateDEBUFF()
{
return 25;
}
@Override
public int getRateDAM()
{
return 50;
}
@Override
public int getRateSTUN()
{
return 50;
}
@Override
public int getRateBUFF()
{
return 5;
}
@Override
public int getRateHEAL()
{
return 50;
}
[/SRC]
import l2p.gameserver.geodata.GeoEngine;
import l2p.gameserver.model.AggroList;
import l2p.gameserver.model.Creature;
import l2p.gameserver.model.Player;
import l2p.gameserver.model.instances.MonsterInstance;
import l2p.gameserver.model.instances.NpcInstance;
public class Ranger extends DefaultAI
{
public Ranger(NpcInstance actor)
{
super(actor);
}
@Override
protected boolean thinkActive()
{
return super.thinkActive() || defaultThinkBuff(10);
}
@Override
protected void onEvtAttacked(Creature attacker, int damage)
{
super.onEvtAttacked(attacker, damage);
NpcInstance actor = getActor();
if(actor.isDead() || attacker == null || actor.getDistance(attacker) > 200)
return;
if(actor.isMoving)
return;
int posX = actor.getX();
int posY = actor.getY();
int posZ = actor.getZ();
int old_posX = posX;
int old_posY = posY;
int old_posZ = posZ;
int signx = posX < attacker.getX() ? -1 : 1;
int signy = posY < attacker.getY() ? -1 : 1;
// int range = (int) ((actor.calculateAttackSpeed() /1000 * actor.getWalkSpeed() )* 0.71); // was "actor.getPhysicalAttackRange()" 0.71 = sqrt(2) / 2
int range = (int) (0.71 * actor.calculateAttackDelay() / 1000 * actor.getMoveSpeed());
posX += signx * range;
posY += signy * range;
posZ = GeoEngine.getHeight(posX, posY, posZ, actor.getGeoIndex());
if(GeoEngine.canMoveToCoord(old_posX, old_posY, old_posZ, posX, posY, posZ, actor.getGeoIndex()))
{
addTaskMove(posX, posY, posZ, false);
addTaskAttack(attacker);
}
}
public boolean canAttackCharacter(Creature target)
{
NpcInstance actor = getActor();
if(getIntention() == CtrlIntention.AI_INTENTION_ATTACK)
{
AggroList.AggroInfo ai = actor.getAggroList().get(target);
return ai != null && ai.hate > 0;
}
if(target instanceof Player)
{
if(target.getFactionId() == actor.getFactionId())
return false;
}
return target.isMonster() || target.isPlayable();
}
public boolean checkAggression(Creature target)
{
NpcInstance actor = getActor();
if(getIntention() != CtrlIntention.AI_INTENTION_ACTIVE || !isGlobalAggro())
return false;
if(target.isPlayable())
{
if(target.getFactionId() == actor.getFactionId())
return false;
}
if(target.isMonster())
{
if(!((MonsterInstance)target).isAggressive())
return false;
}
return super.checkAggression(target);
}
@Override
protected boolean createNewTask()
{
return defaultFightTask();
}
@Override
public int getRatePHYS()
{
return 25;
}
@Override
public int getRateDOT()
{
return 40;
}
@Override
public int getRateDEBUFF()
{
return 25;
}
@Override
public int getRateDAM()
{
return 50;
}
@Override
public int getRateSTUN()
{
return 50;
}
@Override
public int getRateBUFF()
{
return 5;
}
@Override
public int getRateHEAL()
{
return 50;
}
[/SRC]
FactionRanger AI собственно который прописан у гварда
[SRC="java"]package l2p.gameserver.ai;
import l2p.gameserver.geodata.GeoEngine;
import l2p.gameserver.model.Creature;
import l2p.gameserver.model.instances.NpcInstance;
public class FactionRanger extends Ranger
{
public FactionRanger(NpcInstance actor)
{
super(actor);
}
@Override
public boolean canAttackCharacter(Creature target)
{
return super.canAttackCharacter(target);
}
@Override
protected boolean randomWalk()
{
return false;
}
}[/SRC]
import l2p.gameserver.geodata.GeoEngine;
import l2p.gameserver.model.Creature;
import l2p.gameserver.model.instances.NpcInstance;
public class FactionRanger extends Ranger
{
public FactionRanger(NpcInstance actor)
{
super(actor);
}
@Override
public boolean canAttackCharacter(Creature target)
{
return super.canAttackCharacter(target);
}
@Override
protected boolean randomWalk()
{
return false;
}
}[/SRC]
ну и GuardInstance
[SRC="java"]package l2p.gameserver.model.instances;
import l2p.gameserver.model.Creature;
import l2p.gameserver.model.Player;
import l2p.gameserver.model.Skill;
import l2p.gameserver.templates.npc.NpcTemplate;
public class GuardInstance extends NpcInstance
{
public GuardInstance(int objectId, NpcTemplate template)
{
super(objectId, template);
}
@Override
public boolean isAutoAttackable(Creature attacker)
{
if(attacker.isPlayable())
{
if(attacker.getFactionId() == this.getFactionId())
{
return false;
}
}
return true;
}
@Override
public boolean isAttackable(Creature attacker)
{
if(attacker.isPlayable())
{
if(attacker.getFactionId() == this.getFactionId())
{
return false;
}
}
return true;
}
@Override
public String getHtmlPath(int npcId, int val, Player player)
{
String pom;
if(val == 0)
pom = "" + npcId;
else
pom = npcId + "-" + val;
return "guard/" + pom + ".htm";
}
@Override
public boolean isInvul()
{
return false;
}
@Override
public boolean isFearImmune()
{
return true;
}
@Override
public boolean isParalyzeImmune()
{
return true;
}
@Override
protected void onReduceCurrentHp(double damage, Creature attacker, Skill skill, boolean awake, boolean standUp, boolean directHp)
{
getAggroList().addDamageHate(attacker, (int)damage, 0);
super.onReduceCurrentHp(damage, attacker, skill, awake, standUp, directHp);
}
[/SRC]
import l2p.gameserver.model.Creature;
import l2p.gameserver.model.Player;
import l2p.gameserver.model.Skill;
import l2p.gameserver.templates.npc.NpcTemplate;
public class GuardInstance extends NpcInstance
{
public GuardInstance(int objectId, NpcTemplate template)
{
super(objectId, template);
}
@Override
public boolean isAutoAttackable(Creature attacker)
{
if(attacker.isPlayable())
{
if(attacker.getFactionId() == this.getFactionId())
{
return false;
}
}
return true;
}
@Override
public boolean isAttackable(Creature attacker)
{
if(attacker.isPlayable())
{
if(attacker.getFactionId() == this.getFactionId())
{
return false;
}
}
return true;
}
@Override
public String getHtmlPath(int npcId, int val, Player player)
{
String pom;
if(val == 0)
pom = "" + npcId;
else
pom = npcId + "-" + val;
return "guard/" + pom + ".htm";
}
@Override
public boolean isInvul()
{
return false;
}
@Override
public boolean isFearImmune()
{
return true;
}
@Override
public boolean isParalyzeImmune()
{
return true;
}
@Override
protected void onReduceCurrentHp(double damage, Creature attacker, Skill skill, boolean awake, boolean standUp, boolean directHp)
{
getAggroList().addDamageHate(attacker, (int)damage, 0);
super.onReduceCurrentHp(damage, attacker, skill, awake, standUp, directHp);
}
[/SRC]