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

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

View File

@@ -281,7 +281,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);
}
@@ -6332,6 +6332,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
@@ -7432,9 +7439,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)
@@ -7459,6 +7466,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
getAI().clientStartAutoAttack();
}
}
if (this instanceof PlayerInstance)
{
final PlayerInstance currPlayer = (PlayerInstance) this;
@@ -7469,7 +7477,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
{
getAI().setIntention(AI_INTENTION_ATTACK, _target);
}
getAI().clientStartAutoAttack();
}
}
@@ -7479,7 +7486,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

@@ -310,9 +310,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

@@ -9904,6 +9904,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;
}
// Pk protection config
if (Config.ALLOW_CHAR_KILL_PROTECT && skill.isOffensive() && !isGM() && target.isPlayer() && (target.getActingPlayer().getPvpFlag() == 0) && (target.getActingPlayer().getKarma() == 0))
{