Move attribute base from Entity to Mob.

This commit is contained in:
Major-
2014-07-22 00:46:27 +01:00
parent ba80bb8b06
commit 7eaccb4960
3 changed files with 112 additions and 108 deletions
@@ -1,10 +1,6 @@
package org.apollo.game.model.entity;
import java.util.Map;
import org.apollo.game.model.Position;
import org.apollo.game.model.entity.attr.Attribute;
import org.apollo.game.model.entity.attr.AttributeMap;
/**
* Represents an in-game entity, such as a mob, object, projectile etc.
@@ -47,11 +43,6 @@ public abstract class Entity {
}
/**
* The attribute map of this entity.
*/
protected final AttributeMap attributes = new AttributeMap();
/**
* The position of this entity.
*/
@@ -66,25 +57,6 @@ public abstract class Entity {
this.position = position;
}
/**
* Gets the value of the attribute with the specified name.
*
* @param name The name of the attribute.
* @return The value of the attribute.
*/
public final Attribute<?> getAttribute(String name) {
return attributes.getAttribute(name);
}
/**
* Gets a shallow copy of the attributes of this entity, as a {@link Map}.
*
* @return The map of attributes.
*/
public final Map<String, Attribute<?>> getAttributes() {
return attributes.getAttributes();
}
/**
* Gets the {@link EntityType} of this entity.
*
@@ -101,14 +73,4 @@ public abstract class Entity {
return position;
}
/**
* Sets the value of the attribute with the specified name.
*
* @param name The name of the attribute.
* @param value The attribute.
*/
public final void setAttribute(String name, Attribute<?> value) {
attributes.setAttribute(name, value);
}
}
+90 -52
View File
@@ -2,6 +2,7 @@ package org.apollo.game.model.entity;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apollo.game.action.Action;
import org.apollo.game.model.Animation;
@@ -10,9 +11,11 @@ import org.apollo.game.model.Graphic;
import org.apollo.game.model.Position;
import org.apollo.game.model.World;
import org.apollo.game.model.def.NpcDefinition;
import org.apollo.game.model.entity.attr.Attribute;
import org.apollo.game.model.entity.attr.AttributeMap;
import org.apollo.game.model.inv.Inventory;
import org.apollo.game.model.inv.InventoryConstants;
import org.apollo.game.model.inv.Inventory.StackMode;
import org.apollo.game.model.inv.InventoryConstants;
import org.apollo.game.scheduling.impl.SkillNormalizationTask;
import org.apollo.game.sync.block.SynchronizationBlock;
import org.apollo.game.sync.block.SynchronizationBlockSet;
@@ -21,6 +24,7 @@ import org.apollo.game.sync.block.SynchronizationBlockSet;
* A {@link Mob} is a living entity in the world, such as a player or NPC.
*
* @author Graham
* @author Major
*/
public abstract class Mob extends Entity {
@@ -29,21 +33,6 @@ public abstract class Mob extends Entity {
*/
private transient Action<?> action;
/**
* 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 NpcDefinition definition;
/**
* This mob's equipment.
*/
protected final Inventory equipment = new Inventory(InventoryConstants.EQUIPMENT_CAPACITY, StackMode.STACK_ALWAYS);
/**
* The position this mob is facing towards.
*/
@@ -54,21 +43,6 @@ public abstract class Mob extends Entity {
*/
private transient Direction firstDirection = Direction.NONE;
/**
* The index of this mob.
*/
protected int index = -1;
/**
* The mob this mob is interacting with.
*/
protected Mob interactingMob;
/**
* This mob's inventory.
*/
protected final Inventory inventory = new Inventory(InventoryConstants.INVENTORY_CAPACITY);
/**
* This mob's list of local npcs.
*/
@@ -84,16 +58,51 @@ public abstract class Mob extends Entity {
*/
private transient Direction secondDirection = Direction.NONE;
/**
* This mob's skill set.
*/
protected final SkillSet skillSet = new SkillSet();
/**
* Indicates whether this mob is currently teleporting or not.
*/
private transient boolean teleporting = false;
/**
* The attribute map of this 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 NpcDefinition 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;
/**
* This mob's inventory.
*/
protected final Inventory inventory = new Inventory(InventoryConstants.INVENTORY_CAPACITY);
/**
* This mob's skill set.
*/
protected final SkillSet skillSet = new SkillSet();
/**
* This mob's walking queue.
*/
@@ -124,6 +133,25 @@ public abstract class Mob extends Entity {
skillSet.setSkill(Skill.HITPOINTS, new Skill(hitpoints.getExperience(), current, maximum));
}
/**
* Gets the value of the attribute with the specified name.
*
* @param name The name of the attribute.
* @return The value of the attribute.
*/
public final Attribute<?> getAttribute(String name) {
return attributes.getAttribute(name);
}
/**
* Gets a shallow copy of the attributes of this entity, as a {@link Map}.
*
* @return The map of attributes.
*/
public final Map<String, Attribute<?>> getAttributes() {
return attributes.getAttributes();
}
/**
* Gets this mob's {@link SynchronizationBlockSet}.
*
@@ -133,6 +161,15 @@ public abstract class Mob extends Entity {
return blockSet;
}
/**
* Gets this mob's {@link NpcDefinition}.
*
* @param definition The definition.
*/
public final NpcDefinition getDefinition() {
return definition;
}
/**
* Gets this mob's movement {@link Direction}s, as an array.
*
@@ -220,15 +257,6 @@ public abstract class Mob extends Entity {
return localPlayers;
}
/**
* Gets this mob's {@link NpcDefinition}.
*
* @param definition The definition.
*/
public final NpcDefinition getDefinition() {
return definition;
}
/**
* Gets this mob's second movement {@link Direction}.
*
@@ -256,13 +284,6 @@ public abstract class Mob extends Entity {
return walkingQueue;
}
/**
* Initialises this mob.
*/
private void init() {
World.getWorld().schedule(new SkillNormalizationTask(this));
}
/**
* Checks if this mob is active.
*
@@ -314,6 +335,16 @@ public abstract class Mob extends Entity {
blockSet.add(SynchronizationBlock.createInteractingMobBlock(65535));
}
/**
* Sets the value of the attribute with the specified name.
*
* @param name The name of the attribute.
* @param value The attribute.
*/
public final void setAttribute(String name, Attribute<?> value) {
attributes.setAttribute(name, value);
}
/**
* Sets this mob's {@link NpcDefinition}.
*
@@ -445,4 +476,11 @@ public abstract class Mob extends Entity {
blockSet.add(SynchronizationBlock.createTurnToPositionBlock(this.facingPosition = position));
}
/**
* Initialises this mob.
*/
private void init() {
World.getWorld().schedule(new SkillNormalizationTask(this));
}
}
+22 -18
View File
@@ -26,10 +26,10 @@ import org.apollo.game.model.inter.bank.BankInterfaceListener;
import org.apollo.game.model.inv.AppearanceInventoryListener;
import org.apollo.game.model.inv.FullInventoryListener;
import org.apollo.game.model.inv.Inventory;
import org.apollo.game.model.inv.Inventory.StackMode;
import org.apollo.game.model.inv.InventoryConstants;
import org.apollo.game.model.inv.InventoryListener;
import org.apollo.game.model.inv.SynchronizationInventoryListener;
import org.apollo.game.model.inv.Inventory.StackMode;
import org.apollo.game.model.setting.PrivacyState;
import org.apollo.game.model.setting.PrivilegeLevel;
import org.apollo.game.model.setting.ScreenBrightness;
@@ -44,6 +44,7 @@ import org.apollo.util.Point;
* A {@link Player} is a {@link Mob} that a user is controlling.
*
* @author Graham
* @author Major
*/
public final class Player extends Mob {
@@ -452,9 +453,9 @@ public final class Player extends Mob {
}
/**
* Gets the player's name.
* Gets this player's name.
*
* @return The player's name.
* @return The name.
*/
public String getUsername() {
return credentials.getUsername();
@@ -573,7 +574,7 @@ public final class Player extends Mob {
}
/**
* Checks if this player account has membership.
* Checks if this player has membership.
*
* @return {@code true} if so, {@code false} if not.
*/
@@ -591,7 +592,7 @@ public final class Player extends Mob {
}
/**
* Gets whether the player is running or not.
* Checks if this player is running.
*
* @return {@code true} if the player is running, otherwise {@code false}.
*/
@@ -600,9 +601,9 @@ public final class Player extends Mob {
}
/**
* Gets the withdrawing notes flag.
* Checks if this player is withdrawing noted items.
*
* @return The flag.
* @return {@code true} if the player is currently withdrawing notes, otherwise {@code false}.
*/
public boolean isWithdrawingNotes() {
return withdrawingNotes;
@@ -788,7 +789,7 @@ public final class Player extends Mob {
}
/**
* Sets the value denoting the client's modified version.
* Sets the value denoting the client's modified version. TODO make this an attribute?
*
* @param clientVersion The client version.
*/
@@ -815,7 +816,7 @@ public final class Player extends Mob {
}
/**
* Sets whether or not the player is skulled.
* Sets whether or not the player is skulled. TODO make this an attribute
*
* @param isSkulled Whether or not the player is skulled.
*/
@@ -851,7 +852,7 @@ public final class Player extends Mob {
}
/**
* Sets the new player flag.
* Sets the new player flag. TODO make this an attribute?
*
* @param newPlayer A flag indicating if the player has played before.
*/
@@ -860,7 +861,7 @@ public final class Player extends Mob {
}
/**
* Sets the player's prayer icon.
* Sets the player's prayer icon. TODO make this an attribute?
*
* @param prayerIcon The prayer icon.
*/
@@ -887,12 +888,13 @@ public final class Player extends Mob {
}
/**
* Sets the player's run energy.
* Sets the player's run energy. TODO make this an attribute?
*
* @param runEnergy The energy.
*/
public void setRunEnergy(int runEnergy) {
send(new UpdateRunEnergyEvent(this.runEnergy = runEnergy));
this.runEnergy = runEnergy;
send(new UpdateRunEnergyEvent(runEnergy));
}
/**
@@ -928,9 +930,9 @@ public final class Player extends Mob {
}
/**
* Sets whether the player is withdrawing notes from the bank.
* Sets whether or not the player is withdrawing notes from the bank.
*
* @param withdrawingNotes Whether the player is withdrawing noted items or not.
* @param withdrawingNotes Whether or not the player is withdrawing noted items.
*/
public void setWithdrawingNotes(boolean withdrawingNotes) {
this.withdrawingNotes = withdrawingNotes;
@@ -959,16 +961,18 @@ public final class Player extends Mob {
}
/**
* Toggles whether the player is running or not.
* Toggles the player's run status.
*/
public void toggleRunning() {
walkingQueue.setRunningQueue(running = !running);
running = !running;
walkingQueue.setRunningQueue(running);
send(new ConfigEvent(173, running ? 1 : 0));
}
@Override
public String toString() {
return Player.class.getName() + " [username=" + getUsername() + ", privilege=" + privilegeLevel + "]";
return Player.class.getName() + " [username=" + getUsername() + ", privilege=" + privilegeLevel
+ ", clientVersion=" + clientVersion + "]";
}
}