Addition of WorldObject instance overrides.

This commit is contained in:
MobiusDevelopment 2019-11-24 12:37:12 +00:00
parent b7701eefb4
commit 6d011be2ff
11 changed files with 135 additions and 15 deletions

View File

@ -184,11 +184,11 @@ public class Spawn
mob.setObjectId(IdFactory.getInstance().getNextId());
if (mob instanceof MonsterInstance)
{
mob.setAttackable(true);
mob.setAutoAttackable(true);
}
else
{
mob.setAttackable(false);
mob.setAutoAttackable(false);
}
if (getRandomx() > 0)
{

View File

@ -32,7 +32,7 @@ public class WorldObject implements Serializable
private int _y;
private int _z;
protected Set<WorldObject> _knownObjects = ConcurrentHashMap.newKeySet();
private final Set<PlayerInstance> _knownPlayer = ConcurrentHashMap.newKeySet();
private final Set<PlayerInstance> _knownPlayers = ConcurrentHashMap.newKeySet();
public int getObjectId()
{
@ -87,7 +87,7 @@ public class WorldObject implements Serializable
}
/**
* Calculates the 2D distance between this WorldObject and given location.
* Calculates the 2D distance between this WorldObject and given object.
* @param obj the location object
* @return distance between object and given location.
*/
@ -109,7 +109,7 @@ public class WorldObject implements Serializable
}
/**
* Calculates 3D distance between this WorldObject and given location.
* Calculates 3D distance between this WorldObject and given object.
* @param obj the location object
* @return distance between object and given location.
*/
@ -143,7 +143,7 @@ public class WorldObject implements Serializable
_knownObjects.add(object);
if (object instanceof PlayerInstance)
{
_knownPlayer.add((PlayerInstance) object);
_knownPlayers.add((PlayerInstance) object);
}
}
@ -152,7 +152,7 @@ public class WorldObject implements Serializable
_knownObjects.remove(object);
if (object instanceof PlayerInstance)
{
_knownPlayer.remove(object);
_knownPlayers.remove(object);
}
}
@ -167,11 +167,83 @@ public class WorldObject implements Serializable
public Set<PlayerInstance> getKnownPlayers()
{
return _knownPlayer;
return _knownPlayers;
}
public PlayerInstance getActingPlayer()
{
return null;
}
/**
* Verify if object is instance of Attackable.
* @return {@code true} if object is instance of Attackable, {@code false} otherwise
*/
public boolean isAttackable()
{
return false;
}
/**
* Verify if object is instance of Creature.
* @return {@code true} if object is instance of Creature, {@code false} otherwise
*/
public boolean isCreature()
{
return false;
}
/**
* Verify if object is instance of DoorInstance.
* @return {@code true} if object is instance of DoorInstance, {@code false} otherwise
*/
public boolean isDoor()
{
return false;
}
/**
* Verify if object is instance of ItemInstance.
* @return {@code true} if object is instance of ItemInstance, {@code false} otherwise
*/
public boolean isItem()
{
return false;
}
/**
* Verify if object is instance of MonsterInstance.
* @return {@code true} if object is instance of MonsterInstance, {@code false} otherwise
*/
public boolean isMonster()
{
return false;
}
/**
* Verify if object is instance of Npc.
* @return {@code true} if object is instance of Npc, {@code false} otherwise
*/
public boolean isNpc()
{
return false;
}
/**
* Verify if object is instance of PetInstance.
* @return {@code true} if object is instance of PetInstance, {@code false} otherwise
*/
public boolean isPet()
{
return false;
}
/**
* Verify if object is instance of PlayerInstance.
* @return {@code true} if object is instance of PlayerInstance, {@code false} otherwise
*/
public boolean isPlayer()
{
return false;
}
}

View File

@ -445,4 +445,10 @@ public class Attackable extends NpcInstance
moveTo(x1, y1, getZ(), 0);
}
}
@Override
public boolean isAttackable()
{
return true;
}
}

View File

@ -1524,4 +1524,10 @@ public abstract class Creature extends WorldObject
World.getInstance().addVisibleObject(this);
}, 2000);
}
@Override
public boolean isCreature()
{
return true;
}
}

View File

@ -71,4 +71,10 @@ public class DoorInstance extends WorldObject
{
_unknown = unknown;
}
@Override
public boolean isDoor()
{
return true;
}
}

View File

@ -134,4 +134,10 @@ public class ItemInstance extends WorldObject
{
_onTheGround = b;
}
@Override
public boolean isItem()
{
return true;
}
}

View File

@ -86,4 +86,10 @@ public class MonsterInstance extends Attackable
{
return !player.isInvul() && !player.isDead() && (Math.abs(getZ() - player.getZ()) <= 100);
}
@Override
public boolean isMonster()
{
return true;
}
}

View File

@ -87,14 +87,14 @@ public class NpcInstance extends Creature
return _npcTemplate;
}
public boolean isAttackable()
public boolean isAutoAttackable()
{
return _attackable;
}
public void setAttackable(boolean b)
public void setAutoAttackable(boolean value)
{
_attackable = b;
_attackable = value;
}
public int getLeftHandItem()
@ -130,7 +130,7 @@ public class NpcInstance extends Creature
player.setTarget(this);
final MyTargetSelected my = new MyTargetSelected(getObjectId(), player.getLevel() - getLevel());
player.sendPacket(my);
if (isAttackable())
if (isAutoAttackable())
{
final StatusUpdate su = new StatusUpdate(getObjectId());
su.addAttribute(StatusUpdate.CUR_HP, (int) getCurrentHp());
@ -141,11 +141,11 @@ public class NpcInstance extends Creature
}
else
{
if (isAttackable() && !isDead() && !player.isInCombat() && (Math.abs(player.getZ() - getZ()) < 200))
if (isAutoAttackable() && !isDead() && !player.isInCombat() && (Math.abs(player.getZ() - getZ()) < 200))
{
player.startAttack(this);
}
if (!isAttackable())
if (!isAutoAttackable())
{
final double distance = getDistance(player.getX(), player.getY());
if (distance > INTERACTION_DISTANCE)
@ -343,4 +343,10 @@ public class NpcInstance extends Creature
World.getInstance().removeObject(this);
removeAllKnownObjects();
}
@Override
public boolean isNpc()
{
return true;
}
}

View File

@ -613,4 +613,10 @@ public class PetInstance extends Creature
{
return _owner;
}
@Override
public boolean isPet()
{
return true;
}
}

View File

@ -1893,6 +1893,12 @@ public class PlayerInstance extends Creature
}
}
@Override
public boolean isPlayer()
{
return true;
}
@Override
public PlayerInstance getActingPlayer()
{

View File

@ -44,7 +44,7 @@ public class NpcInfo extends ServerBasePacket
writeC(34);
writeD(_cha.getObjectId());
writeD(_cha.getNpcTemplate().getNpcId() + 1000000);
if (_cha.isAttackable())
if (_cha.isAutoAttackable())
{
writeD(1);
}