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() public PlayerInstance getActingPlayer()
{ {
return null; return null;

View File

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

View File

@@ -281,7 +281,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
_calculators = new Calculator[Stat.NUM_STATS]; _calculators = new Calculator[Stat.NUM_STATS];
Formulas.getInstance().addFuncsToNewCharacter(this); Formulas.getInstance().addFuncsToNewCharacter(this);
if (!(this instanceof Attackable) && !isAttackable() && !(this instanceof DoorInstance)) if (!isAttackable() && !canBeAttacked() && !(this instanceof DoorInstance))
{ {
setInvul(true); 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 (player.isConfused() || player.isBlocked())
{ {
// If target is confused, send a Server->Client packet ActionFailed // 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 // 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. // 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 (((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) if (this instanceof PlayerInstance)
@@ -7459,6 +7466,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
getAI().clientStartAutoAttack(); getAI().clientStartAutoAttack();
} }
} }
if (this instanceof PlayerInstance) if (this instanceof PlayerInstance)
{ {
final PlayerInstance currPlayer = (PlayerInstance) this; final PlayerInstance currPlayer = (PlayerInstance) this;
@@ -7469,7 +7477,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
{ {
getAI().setIntention(AI_INTENTION_ATTACK, _target); getAI().setIntention(AI_INTENTION_ATTACK, _target);
} }
getAI().clientStartAutoAttack(); getAI().clientStartAutoAttack();
} }
} }
@@ -7479,7 +7486,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
{ {
getAI().setIntention(AI_INTENTION_ATTACK, _target); getAI().setIntention(AI_INTENTION_ATTACK, _target);
} }
getAI().clientStartAutoAttack(); getAI().clientStartAutoAttack();
} }
} }

View File

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

View File

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

View File

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

View File

@@ -310,9 +310,9 @@ public class NpcInstance extends Creature
} }
@Override @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 // Pk protection config
if (Config.ALLOW_CHAR_KILL_PROTECT && skill.isOffensive() && !isGM() && target.isPlayer() && (target.getActingPlayer().getPvpFlag() == 0) && (target.getActingPlayer().getKarma() == 0)) if (Config.ALLOW_CHAR_KILL_PROTECT && skill.isOffensive() && !isGM() && target.isPlayer() && (target.getActingPlayer().getPvpFlag() == 0) && (target.getActingPlayer().getKarma() == 0))
{ {

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() public PlayerInstance getActingPlayer()
{ {
return null; return null;

View File

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

View File

@@ -283,7 +283,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
_calculators = new Calculator[Stat.NUM_STATS]; _calculators = new Calculator[Stat.NUM_STATS];
Formulas.getInstance().addFuncsToNewCharacter(this); Formulas.getInstance().addFuncsToNewCharacter(this);
if (!(this instanceof Attackable) && !isAttackable() && !(this instanceof DoorInstance)) if (!isAttackable() && !canBeAttacked() && !(this instanceof DoorInstance))
{ {
setInvul(true); 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 (player.isConfused() || player.isBlocked())
{ {
// If target is confused, send a Server->Client packet ActionFailed // 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 // 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. // 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 (((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) if (this instanceof PlayerInstance)
@@ -7506,6 +7513,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
getAI().clientStartAutoAttack(); getAI().clientStartAutoAttack();
} }
} }
if (this instanceof PlayerInstance) if (this instanceof PlayerInstance)
{ {
final PlayerInstance currPlayer = (PlayerInstance) this; final PlayerInstance currPlayer = (PlayerInstance) this;
@@ -7516,7 +7524,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
{ {
getAI().setIntention(AI_INTENTION_ATTACK, _target); getAI().setIntention(AI_INTENTION_ATTACK, _target);
} }
getAI().clientStartAutoAttack(); getAI().clientStartAutoAttack();
} }
} }
@@ -7526,7 +7533,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
{ {
getAI().setIntention(AI_INTENTION_ATTACK, _target); getAI().setIntention(AI_INTENTION_ATTACK, _target);
} }
getAI().clientStartAutoAttack(); getAI().clientStartAutoAttack();
} }
} }

View File

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

View File

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

View File

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

View File

@@ -312,9 +312,9 @@ public class NpcInstance extends Creature
} }
@Override @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? // 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()))) if (isInDuel() && (!(target instanceof PlayerInstance) || (target.getActingPlayer().getDuelId() != getDuelId())) && (!(target instanceof SummonInstance) || (((Summon) target).getOwner().getDuelId() != getDuelId())))
{ {