Implementation of canBeAttacked method.

This commit is contained in:
MobiusDevelopment
2021-04-18 08:28:35 +00:00
parent 5dd1b7a4d2
commit a9d81a5b17
16 changed files with 98 additions and 32 deletions

View File

@ -395,6 +395,15 @@ public abstract class WorldObject
}
}
/**
* Verify if object can be attacked.
* @return {@code true} if object can be attacked, {@code false} otherwise
*/
public boolean canBeAttacked()
{
return false;
}
public PlayerInstance getActingPlayer()
{
return null;

View File

@ -2915,9 +2915,12 @@ public class Attackable extends NpcInstance
return bonusOverhit;
}
/**
* Return True.
*/
@Override
public boolean canBeAttacked()
{
return true;
}
@Override
public boolean isAttackable()
{

View File

@ -283,7 +283,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
_calculators = new Calculator[Stat.NUM_STATS];
Formulas.getInstance().addFuncsToNewCharacter(this);
if (!(this instanceof Attackable) && !isAttackable() && !(this instanceof DoorInstance))
if (!isAttackable() && !canBeAttacked() && !(this instanceof DoorInstance))
{
setInvul(true);
}
@ -6379,6 +6379,13 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
}
}
if ((player.getTarget() != null) && !player.getTarget().canBeAttacked() && !player.getAccessLevel().allowPeaceAttack())
{
// If target is not attackable, send a Server->Client packet ActionFailed
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
if (player.isConfused() || player.isBlocked())
{
// If target is confused, send a Server->Client packet ActionFailed
@ -7479,9 +7486,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
// if the skill has changed the character's state to something other than STATE_CASTING
// then just leave it that way, otherwise switch back to STATE_IDLE.
if ((skill.getId() != 345) && (skill.getId() != 346))
if ((skill.getId() != 345) && (skill.getId() != 346) && _target.canBeAttacked())
{
// Like L2OFF while use a skill and next interntion == null the char stop auto attack
// Like L2OFF while use a skill and next intention == null the char stop auto attack
if (((getAI().getNextIntention() == null) && ((skill.getSkillType() == SkillType.PDAM) && (skill.getCastRange() < 400))) || (skill.getSkillType() == SkillType.BLOW) || (skill.getSkillType() == SkillType.DRAIN_SOUL) || (skill.getSkillType() == SkillType.SOW) || (skill.getSkillType() == SkillType.SPOIL))
{
if (this instanceof PlayerInstance)
@ -7506,6 +7513,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
getAI().clientStartAutoAttack();
}
}
if (this instanceof PlayerInstance)
{
final PlayerInstance currPlayer = (PlayerInstance) this;
@ -7516,7 +7524,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
{
getAI().setIntention(AI_INTENTION_ATTACK, _target);
}
getAI().clientStartAutoAttack();
}
}
@ -7526,7 +7533,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
{
getAI().setIntention(AI_INTENTION_ATTACK, _target);
}
getAI().clientStartAutoAttack();
}
}

View File

@ -182,10 +182,12 @@ public abstract class Playable extends Creature
return true;
}
/**
* Return True.
* @return true, if is attackable
*/
@Override
public boolean canBeAttacked()
{
return true;
}
@Override
public boolean isAttackable()
{

View File

@ -287,7 +287,7 @@ public abstract class Summon extends Playable
getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
return;
}
if (!target.isAttackable() && !(this instanceof SiegeSummonInstance))
if (!target.canBeAttacked() && !(this instanceof SiegeSummonInstance))
{
getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
return;
@ -699,7 +699,7 @@ public abstract class Summon extends Playable
}
else
{
if (!target.isAttackable() && (_owner != null) && _owner.getAccessLevel().allowPeaceAttack())
if (!target.canBeAttacked() && (_owner != null) && _owner.getAccessLevel().allowPeaceAttack())
{
return;
}

View File

@ -57,6 +57,12 @@ public class ArtefactInstance extends NpcInstance
return false;
}
@Override
public boolean canBeAttacked()
{
return false;
}
@Override
public boolean isAttackable()
{

View File

@ -312,9 +312,9 @@ public class NpcInstance extends Creature
}
@Override
public boolean isAttackable()
public boolean canBeAttacked()
{
return Config.NPC_ATTACKABLE || (this instanceof Attackable);
return Config.NPC_ATTACKABLE;
}
/**

View File

@ -10067,6 +10067,13 @@ public class PlayerInstance extends Playable
}
}
// If target is not attackable, send a Server->Client packet ActionFailed
if (!target.canBeAttacked() && !getAccessLevel().allowPeaceAttack() && !target.isDoor())
{
sendPacket(ActionFailed.STATIC_PACKET);
return;
}
// Are the target and the player in the same duel?
if (isInDuel() && (!(target instanceof PlayerInstance) || (target.getActingPlayer().getDuelId() != getDuelId())) && (!(target instanceof SummonInstance) || (((Summon) target).getOwner().getDuelId() != getDuelId())))
{