From a880127c5f6e831f4f818a88da488cceeb32f36c Mon Sep 17 00:00:00 2001 From: Major- Date: Wed, 10 Feb 2016 19:32:32 +0000 Subject: [PATCH] Improve internal Mob code --- .../org/apollo/game/model/entity/Mob.java | 121 +++++++++--------- 1 file changed, 60 insertions(+), 61 deletions(-) diff --git a/game/src/main/org/apollo/game/model/entity/Mob.java b/game/src/main/org/apollo/game/model/entity/Mob.java index 1ee4e2c9..b5b1f0f8 100644 --- a/game/src/main/org/apollo/game/model/entity/Mob.java +++ b/game/src/main/org/apollo/game/model/entity/Mob.java @@ -1,10 +1,5 @@ package org.apollo.game.model.entity; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; - import org.apollo.cache.def.NpcDefinition; import org.apollo.game.action.Action; import org.apollo.game.model.Animation; @@ -25,8 +20,13 @@ import org.apollo.game.sync.block.InteractingMobBlock; import org.apollo.game.sync.block.SynchronizationBlock; import org.apollo.game.sync.block.SynchronizationBlockSet; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; + /** - * A {@link Mob} is a living entity in the world, such as a player or npc. + * A living entity in the world, such as a player or npc. * * @author Graham * @author Major @@ -38,31 +38,10 @@ public abstract class Mob extends Entity { */ protected final AttributeMap attributes = new AttributeMap(); - /** - * This mob's set of synchronization blocks. - */ - protected transient SynchronizationBlockSet blockSet = new SynchronizationBlockSet(); - - /** - * This mob's npc definition. A player only uses this if they are appearing as an npc. - */ - protected Optional definition; - /** * This mob's equipment. */ - protected final Inventory equipment = new Inventory(InventoryConstants.EQUIPMENT_CAPACITY, - StackMode.STACK_ALWAYS); - - /** - * The index of this mob. - */ - protected int index = -1; - - /** - * The mob this mob is interacting with. - */ - protected Mob interactingMob; + protected final Inventory equipment = new Inventory(InventoryConstants.EQUIPMENT_CAPACITY, StackMode.STACK_ALWAYS); /** * This mob's inventory. @@ -77,52 +56,62 @@ public abstract class Mob extends Entity { /** * This mob's walking queue. */ - protected final transient WalkingQueue walkingQueue = new WalkingQueue(this); - - /** - * This mob's current action. - */ - private transient Action action; - - /** - * The position this mob is facing towards. - */ - private transient Position facingPosition = position; - - /** - * This mob's first movement direction. - */ - private transient Direction firstDirection = Direction.NONE; + protected final WalkingQueue walkingQueue = new WalkingQueue(this); /** * This mob's list of local npcs. */ - private final transient List localNpcs = new ArrayList<>(); + private final List localNpcs = new ArrayList<>(); /** * This mob's list of local players. */ - private final transient List localPlayers = new ArrayList<>(); + private final List localPlayers = new ArrayList<>(); + + /** + * This mob's set of synchronization blocks. + */ + protected SynchronizationBlockSet blockSet = new SynchronizationBlockSet(); + + /** + * This mob's npc definition. A player only uses this if they are appearing as an npc. + */ + protected Optional definition; + + /** + * The index of this mob. + */ + protected int index = -1; + + /** + * The mob this mob is interacting with. + */ + protected Mob interactingMob; + + /** + * This mob's current action. + */ + private Action action; + + /** + * The position this mob is facing towards. + */ + private Position facingPosition = position; + + /** + * This mob's first movement direction. + */ + private Direction firstDirection = Direction.NONE; /** * This mob's second movement direction. */ - private transient Direction secondDirection = Direction.NONE; + private Direction secondDirection = Direction.NONE; /** * Indicates whether this mob is currently teleporting or not. */ - private transient boolean teleporting = false; - - /** - * Creates the Mob. - * - * @param world The {@link World} containing the Mob - * @param position The {@link Position} of the Mob. - */ - public Mob(World world, Position position) { - this(world, position, null); - } + private boolean teleporting; /** * Creates the Mob. @@ -131,13 +120,23 @@ public abstract class Mob extends Entity { * @param position The {@link Position} of the Mob. * @param definition The {@link NpcDefinition} of the Mob. */ - public Mob(World world, Position position, NpcDefinition definition) { + protected Mob(World world, Position position, NpcDefinition definition) { super(world, position); this.definition = Optional.ofNullable(definition); init(); } + /** + * Creates the Mob. + * + * @param world The {@link World} containing the Mob + * @param position The {@link Position} of the Mob. + */ + protected Mob(World world, Position position) { + this(world, position, null); + } + /** * Deals damage to this mob. * @@ -197,8 +196,8 @@ public abstract class Mob extends Entity { */ public final Direction[] getDirections() { if (firstDirection != Direction.NONE) { - return secondDirection == Direction.NONE ? new Direction[] { firstDirection } - : new Direction[] { firstDirection, secondDirection }; + return secondDirection == Direction.NONE ? new Direction[]{ firstDirection } + : new Direction[]{ firstDirection, secondDirection }; } return Direction.EMPTY_DIRECTION_ARRAY;