Various code cleanups.

This commit is contained in:
MobiusDevelopment 2019-08-21 06:32:36 +00:00
parent a706b4eb99
commit 359479b570
11 changed files with 16 additions and 338 deletions

View File

@ -550,7 +550,7 @@ abstract class AbstractAI implements Ctrl
setTarget(pawn);
_moveToPawnTimeout = GameTimeController.getGameTicks();
_moveToPawnTimeout += /* 1000 */200 / GameTimeController.MILLIS_IN_TICK;
_moveToPawnTimeout += /* 1000 */ 200 / GameTimeController.MILLIS_IN_TICK;
if ((pawn == null) || (_accessor == null))
{
@ -560,6 +560,10 @@ abstract class AbstractAI implements Ctrl
// Calculate movement data for a move to location action and add the actor to movingObjects of GameTimeController
_accessor.moveTo(pawn.getX(), pawn.getY(), pawn.getZ(), offset);
// Mobius: Solves moving to wrong Z when not using geodata,
// but probably is not accurate and you should use geodata.
// _accessor.moveTo(pawn.getX(), pawn.getY(), _actor.getZ(), offset);
if (!_actor.isMoving())
{
_actor.sendPacket(ActionFailed.STATIC_PACKET);
@ -651,10 +655,6 @@ abstract class AbstractAI implements Ctrl
*/
protected void clientStopMoving(Location pos)
{
/*
* if (true && _actor instanceof PlayerInstance){ LOGGER.warning("clientStopMoving();"); Thread.dumpStack(); }
*/
// Stop movement of the Creature
if (_actor.isMoving())
{
@ -696,27 +696,6 @@ abstract class AbstractAI implements Ctrl
_clientMoving = false;
}
/**
* Start the actor Auto Attack client side by sending Server->Client packet AutoAttackStart <I>(broadcast)</I>.<BR>
* <BR>
* <FONT COLOR=#FF0000><B> <U>Caution</U> : Low level function, used by AI subclasses</B></FONT><BR>
* <BR>
*/
/*
* public void clientStartAutoAttack() { if(!isAutoAttacking()) { // Send a Server->Client packet AutoAttackStart to the actor and all PlayerInstance in its _knownPlayers _actor.broadcastPacket(new AutoAttackStart(_actor.getObjectId())); setAutoAttacking(true); }
* AttackStanceTaskManager.getInstance().addAttackStanceTask(_actor); }
*/
/**
* Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop <I>(broadcast)</I>.<BR>
* <BR>
* <FONT COLOR=#FF0000><B> <U>Caution</U> : Low level function, used by AI subclasses</B></FONT><BR>
* <BR>
*/
/*
* public void clientStopAutoAttack() { if(_actor instanceof PlayerInstance) { if(!AttackStanceTaskManager.getInstance().getAttackStanceTask(_actor) && isAutoAttacking()) { AttackStanceTaskManager.getInstance().addAttackStanceTask(_actor); } } else if(isAutoAttacking()) {
* _actor.broadcastPacket(new AutoAttackStop(_actor.getObjectId())); } setAutoAttacking(false); }
*/
/**
* Start the actor Auto Attack client side by sending Server->Client packet AutoAttackStart <I>(broadcast)</I>.<BR>
* <BR>

View File

@ -330,18 +330,6 @@ public class CreatureAI extends AbstractAI
if ((_actor instanceof PlayerInstance) && (_actor.isAttackingNow() || _actor.isCastingNow()) && !_actor.isMoving())
{
final PlayerInstance player = (PlayerInstance) _actor;
// start MoveOnAttack Task
// Schedule a move task
if (!player.isMovingTaskDefined())
{ // if not already started the task
player.defineNewMovingTask(pos);
}
else
{
player.modifyMovingTask(pos);
}
// Cancel action client side by sending Server->Client packet ActionFailed to the PlayerInstance actor
clientActionFailed();
return;

View File

@ -27,7 +27,6 @@ import java.util.EmptyStackException;
import java.util.Stack;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Location;
import org.l2jmobius.gameserver.model.Skill;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Creature;
@ -178,17 +177,6 @@ public class PlayerAI extends CreatureAI
}
}
@Override
protected void clientStopMoving(Location pos)
{
super.clientStopMoving(pos);
final PlayerInstance _player = (PlayerInstance) _actor;
if (_player.getPosticipateSit())
{
_player.sitDown();
}
}
@Override
protected void onIntentionActive()
{

View File

@ -836,17 +836,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
return;
}
// Like L2OFF wait that the hit task finish and then player can move
if ((this instanceof PlayerInstance) && ((PlayerInstance) this).isMovingTaskDefined() && !((PlayerInstance) this).isAttackingNow())
{
final ItemInstance rhand = ((PlayerInstance) this).getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
if (((rhand != null) && (rhand.getItemType() != WeaponType.BOW)) || (rhand == null))
{
((PlayerInstance) this).startMovingTask();
return;
}
}
if (isAlikeDead())
{
// If PlayerInstance is dead or the target is dead, the action is stoped
@ -1089,6 +1078,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
wasSSCharged = (weaponInst != null) && (weaponInst.getChargedSoulshot() != ItemInstance.CHARGED_NONE);
}
// Mobius: Do not move when attack is launched.
if (isMoving())
{
stopMove(getPosition().getWorldPosition());
}
// Get the Attack Speed of the Creature (delay (in milliseconds) before next attack)
// the hit is calculated to happen halfway to the animation - might need further tuning e.g. in bow case
final int timeAtk = calculateTimeBetweenAttacks(target, weaponItem);
@ -1794,7 +1789,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
// Like L2OFF after a skill the player must stop the movement, unless it is toggle or potion.
if (!skill.isToggle() && !skill.isPotion() && (this instanceof PlayerInstance))
{
((PlayerInstance) this).stopMove(null);
stopMove(null);
}
// Start the effect as long as the player is casting.
@ -2135,15 +2130,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
// Update active skills in progress (In Use and Not In Use because stacked) icones on client
updateEffectIcons();
// After dead mob check if the killer got a moving task actived
if (killer instanceof PlayerInstance)
{
if (((PlayerInstance) killer).isMovingTaskDefined())
{
((PlayerInstance) killer).startMovingTask();
}
}
return true;
}
@ -5688,7 +5674,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
// All data are contained in a CharPosition object
if (pos != null)
{
getPosition().setXYZ(pos.getX(), pos.getY(), GeoEngine.getInstance().getHeight(pos.getX(), pos.getY(), pos.getZ()));
getPosition().setXYZ(pos.getX(), pos.getY(), pos.getZ());
setHeading(pos.getHeading());
if (this instanceof PlayerInstance)
@ -5853,12 +5839,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
}
}
// when start to move again, it has to stop sitdown task
if (this instanceof PlayerInstance)
{
((PlayerInstance) this).setPosticipateSit(false);
}
// Fix archer bug with movement/hittask
if ((this instanceof PlayerInstance) && isAttackingNow())
{
@ -6807,27 +6787,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
{
activeWeapon.getSkillEffects(this, target, crit);
}
if ((this instanceof PlayerInstance) && ((PlayerInstance) this).isMovingTaskDefined())
{
final ItemInstance rhand = ((PlayerInstance) this).getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
if ((rhand != null) && (rhand.getItemType() == WeaponType.BOW))
{
((PlayerInstance) this).startMovingTask();
}
}
return;
}
if ((this instanceof PlayerInstance) && ((PlayerInstance) this).isMovingTaskDefined())
{
final ItemInstance rhand = ((PlayerInstance) this).getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
if ((rhand != null) && (rhand.getItemType() == WeaponType.BOW))
{
((PlayerInstance) this).startMovingTask();
}
}
getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
}
@ -8776,11 +8738,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
{
LOGGER.warning(e.getMessage());
}
if ((this instanceof PlayerInstance) && ((PlayerInstance) this).isMovingTaskDefined() && !skill.isPotion())
{
((PlayerInstance) this).startMovingTask();
}
}
/**

View File

@ -16,8 +16,6 @@
*/
package org.l2jmobius.gameserver.model.actor.instance;
import static org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_MOVE_TO;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -273,8 +271,6 @@ public class PlayerInstance extends Playable
public int _originalNameColourVIP;
public int _originalKarmaVIP;
private long _voteTimestamp = 0;
private boolean _posticipateSit;
protected boolean sittingTaskLaunched;
private PlayerStatsHolder saved_status = null;
private final long _instanceLoginTime;
private long _lastTeleportAction = 0;
@ -522,8 +518,6 @@ public class PlayerInstance extends Playable
private boolean _dual_mastery = false;
private boolean _2hands_mastery = false;
private int _masteryWeapPenalty = 0;
protected MoveOnAttack launchedMovingTask = null;
protected Boolean _movingTaskDefined = false;
private boolean _learningSkill = false;
private ScheduledFuture<?> _taskWarnUserTakeBreak;
private boolean _wasInvisible = false;
@ -3484,113 +3478,6 @@ public class PlayerInstance extends Playable
_shortCuts.deleteShortCutByObjectId(objectId);
}
public class MoveOnAttack implements Runnable
{
final PlayerInstance _player;
Location _pos;
public MoveOnAttack(PlayerInstance player, Location pos)
{
_player = player;
_pos = pos;
}
@Override
public void run()
{
synchronized (_movingTaskDefined)
{
launchedMovingTask = null;
_movingTaskDefined = false;
}
// Set the Intention of this AbstractAI to AI_INTENTION_MOVE_TO
_player.getAI().changeIntention(AI_INTENTION_MOVE_TO, _pos, null);
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
_player.getAI().clientStopAutoAttack();
// Abort the attack of the Creature and send Server->Client ActionFailed packet
_player.abortAttack();
// Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)
_player.getAI().moveTo(_pos.getX(), _pos.getY(), _pos.getZ());
}
/**
* Sets the new position.
* @param pos the new new position
*/
public void setNewPosition(Location pos)
{
_pos = pos;
}
}
/**
* Checks if is moving task defined.
* @return true, if is moving task defined
*/
public boolean isMovingTaskDefined()
{
return _movingTaskDefined;
}
public void setMovingTaskDefined(boolean value)
{
_movingTaskDefined = value;
}
/**
* Define new moving task.
* @param pos the pos
*/
public void defineNewMovingTask(Location pos)
{
synchronized (_movingTaskDefined)
{
launchedMovingTask = new MoveOnAttack(this, pos);
_movingTaskDefined = true;
}
}
/**
* Modify moving task.
* @param pos the pos
*/
public void modifyMovingTask(Location pos)
{
synchronized (_movingTaskDefined)
{
if (!_movingTaskDefined)
{
return;
}
launchedMovingTask.setNewPosition(pos);
}
}
/**
* Start moving task.
*/
public void startMovingTask()
{
synchronized (_movingTaskDefined)
{
if (!_movingTaskDefined)
{
return;
}
if ((isMoving() && isAttackingNow()))
{
return;
}
ThreadPool.execute(launchedMovingTask);
}
}
/**
* Return True if the PlayerInstance is sitting.<BR>
* <BR>
@ -3598,17 +3485,7 @@ public class PlayerInstance extends Playable
*/
public boolean isSitting()
{
return _waitTypeSitting || sittingTaskLaunched;
}
/**
* Return True if the PlayerInstance is sitting task launched.<BR>
* <BR>
* @return true, if is sitting task launched
*/
public boolean isSittingTaskLaunched()
{
return sittingTaskLaunched;
return _waitTypeSitting;
}
/**
@ -3620,28 +3497,8 @@ public class PlayerInstance extends Playable
_waitTypeSitting = state;
}
/**
* Sets the posticipate sit.
* @param act the new posticipate sit
*/
public void setPosticipateSit(boolean act)
{
_posticipateSit = act;
}
/**
* Gets the posticipate sit.
* @return the posticipate sit
*/
public boolean getPosticipateSit()
{
return _posticipateSit;
}
/**
* Sit down the PlayerInstance, set the AI Intention to AI_INTENTION_REST and send a Server->Client ChangeWaitType packet (broadcast)<BR>
* <BR>
* .
*/
public void sitDown()
{
@ -3650,32 +3507,16 @@ public class PlayerInstance extends Playable
stopFakeDeath(null);
}
if (isMoving()) // since you are moving and want sit down the posticipate sitdown task will be always true
{
setPosticipateSit(true);
return;
}
// we are going to sitdown, so posticipate is false
setPosticipateSit(false);
if (isCastingNow() && !_relax)
{
return;
}
if (sittingTaskLaunched)
{
// just return
return;
}
if (!_waitTypeSitting && !isAttackingDisabled() && !isOutOfControl() && !isImobilised())
{
breakAttack();
setIsSitting(true);
broadcastPacket(new ChangeWaitType(this, ChangeWaitType.WT_SITTING));
sittingTaskLaunched = true;
// Schedule a sit down task to wait for the animation to finish
ThreadPool.schedule(new SitDownTask(this), 2500);
setIsParalyzed(true);
@ -3696,7 +3537,6 @@ public class PlayerInstance extends Playable
{
setIsSitting(true);
_player.setIsParalyzed(false);
sittingTaskLaunched = false;
_player.getAI().setIntention(CtrlIntention.AI_INTENTION_REST);
}
}
@ -3733,11 +3573,6 @@ public class PlayerInstance extends Playable
stopFakeDeath(null);
}
if (sittingTaskLaunched)
{
return;
}
if (GameEvent.active && eventSitForced)
{
sendMessage("A dark force beyond your mortal understanding makes your knees to shake when you try to stand up ...");
@ -3766,7 +3601,6 @@ public class PlayerInstance extends Playable
// Schedule a stand up task to wait for the animation to finish
setIsImobilised(true);
ThreadPool.schedule(new StandUpTask(this), 2500);
}
}
@ -6813,15 +6647,6 @@ public class PlayerInstance extends Playable
// Refresh focus force like L2OFF
sendPacket(new EtcStatusUpdate(this));
// After dead mob check if the killer got a moving task actived
if (killer instanceof PlayerInstance)
{
if (((PlayerInstance) killer).isMovingTaskDefined())
{
((PlayerInstance) killer).startMovingTask();
}
}
return true;
}
@ -13948,12 +13773,7 @@ public class PlayerInstance extends Playable
*/
public boolean isInWater()
{
if (_taskWater != null)
{
return true;
}
return false;
return _taskWater != null;
}
/**
@ -13961,13 +13781,6 @@ public class PlayerInstance extends Playable
*/
public void checkWaterState()
{
// checking if char is over base level of water (sea, rivers)
if (getZ() > -3750)
{
stopWaterTask();
return;
}
if (isInsideZone(ZoneId.WATER))
{
startWaterTask();
@ -13975,7 +13788,6 @@ public class PlayerInstance extends Playable
else
{
stopWaterTask();
return;
}
}

View File

@ -30,7 +30,7 @@ import org.l2jmobius.gameserver.util.Util;
public class WorldObjectKnownList
{
private final WorldObject _activeObject;
private Map<Integer, WorldObject> _knownObjects;
private final Map<Integer, WorldObject> _knownObjects = new ConcurrentHashMap<>();
public WorldObjectKnownList(WorldObject activeObject)
{
@ -220,11 +220,6 @@ public class WorldObjectKnownList
*/
public Map<Integer, WorldObject> getKnownObjects()
{
if (_knownObjects == null)
{
_knownObjects = new ConcurrentHashMap<>();
}
return _knownObjects;
}

View File

@ -96,12 +96,6 @@ public class Action extends GameClientPacket
return;
}
// reset old Moving task
if (player.isMovingTaskDefined())
{
player.setMovingTaskDefined(false);
}
// Check if the target is valid, if the player haven't a shop or isn't the requester of a transaction (ex : FriendInvite, JoinAlly, JoinParty...)
if (player.getPrivateStoreType() == 0/* && activeChar.getActiveRequester() == null */)
{

View File

@ -376,12 +376,6 @@ public class RequestActionUse extends GameClientPacket
getClient().sendPacket(ActionFailed.STATIC_PACKET);
return;
}
// You can't open Manufacture when the task is launched
if (player.isSittingTaskLaunched())
{
sendPacket(ActionFailed.STATIC_PACKET);
return;
}
if (player.getPrivateStoreType() == PlayerInstance.STORE_PRIVATE_MANUFACTURE)
{
player.setPrivateStoreType(PlayerInstance.STORE_PRIVATE_NONE);
@ -462,12 +456,6 @@ public class RequestActionUse extends GameClientPacket
getClient().sendPacket(ActionFailed.STATIC_PACKET);
return;
}
// You can't open Manufacture when the task is launched
if (player.isSittingTaskLaunched())
{
sendPacket(ActionFailed.STATIC_PACKET);
return;
}
if (player.getPrivateStoreType() == PlayerInstance.STORE_PRIVATE_MANUFACTURE)
{
player.setPrivateStoreType(PlayerInstance.STORE_PRIVATE_NONE);

View File

@ -79,13 +79,6 @@ public class RequestPrivateStoreManageBuy extends GameClientPacket
return;
}
// You can't open store when the task is launched
if (player.isSittingTaskLaunched())
{
sendPacket(ActionFailed.STATIC_PACKET);
return;
}
// Like L2OFF - You can't open buy/sell when you are sitting
if (player.isSitting() && (player.getPrivateStoreType() == 0))
{

View File

@ -79,13 +79,6 @@ public class RequestPrivateStoreManageSell extends GameClientPacket
return;
}
// You can't open store when the task is launched
if (player.isSittingTaskLaunched())
{
sendPacket(ActionFailed.STATIC_PACKET);
return;
}
// Like L2OFF - You can't open buy/sell when you are sitting
if (player.isSitting() && (player.getPrivateStoreType() == 0))
{

View File

@ -17,7 +17,6 @@
package org.l2jmobius.gameserver.network.serverpackets;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
/**
* 0000: 01 7a 73 10 4c b2 0b 00 00 a3 fc 00 00 e8 f1 ff .zs.L........... 0010: ff bd 0b 00 00 b3 fc 00 00 e8 f1 ff ff ............. ddddddd
@ -47,14 +46,6 @@ public class CharMoveToLocation extends GameServerPacket
@Override
protected final void writeImpl()
{
final PlayerInstance player = getClient().getPlayer();
// reset old Moving task
if ((player != null) && player.isMovingTaskDefined())
{
player.setMovingTaskDefined(false);
}
writeC(0x01);
writeD(_objectId);