Code:
package org.dementhium.model.player;
import java.nio.ByteBuffer;
import java.util.LinkedList;
import java.util.Queue;
import org.dementhium.model.Animation;
import org.dementhium.model.Entity;
import org.dementhium.model.ForceText;
import org.dementhium.model.Graphics;
import org.dementhium.model.Heal;
import org.dementhium.model.Hits;
import org.dementhium.model.Item;
import org.dementhium.model.LocalEntityList;
import org.dementhium.model.Position;
import org.dementhium.model.Hits.Hit;
import org.dementhium.model.Hits.HitType;
import org.dementhium.model.combat.Combat.FightType;
import org.dementhium.model.npc.Npc;
import org.dementhium.net.Frames;
import org.dementhium.net.codec.ConnectionHandler;
import org.dementhium.skills.cooking.Cooking;
import org.dementhium.skills.fletching.FletchingManager;
import org.dementhium.skills.prayer.Prayer;
import org.dementhium.skills.woodcutting.WoodCutting;
import org.dementhium.util.BufferUtils;
import org.jboss.netty.buffer.ChannelBuffer;
/**
*
* @author Dragonkk
* @author 'Mystic Flow
* @author `Discardedx2
* @author Khaled
*/
public final class Player extends Entity {
private String Username;
private String DisplayName;
private String Password;
private byte rights = 2;
private boolean isLoggedIn;
public boolean autoRetaliate;
private int specialAmount = 100;
private final Appearance appearance = new Appearance();
private final Inventory inventory = new Inventory(this);
private final Equipment equipment = new Equipment(this);
private final Skills skills = new Skills(this);
private final Banking bank = new Banking(this);
private final Bonuses bonuses = new Bonuses(this);
private ConnectionHandler connection;
private LocalEntityList localEntities;
private final Frames frames = new Frames(this);
private final Mask mask = new Mask(this);
private final Gpi gpi = new Gpi(this);
private final Gni gni = new Gni(this);
private final MusicManager musicmanager = new MusicManager(this);
private final InterfaceManager intermanager = new InterfaceManager(this);
private final HintIconManager hinticonmanager = new HintIconManager(this);
private final Queue<Hit> queuedHits = new LinkedList<Hit>();
private final Hits hits = new Hits();
private boolean isOnline;
private boolean inClient;
private WoodCutting woodCutting;
private FletchingManager fletching;
private Cooking cooking;
private final Prayer prayer = new Prayer(this);
private int attackStyle;
public Player(String Username, String Password) {
this.setUsername(Username);
this.setDisplayName(Username);
this.setPassword(Password);
}
public void LoadPlayer(ConnectionHandler connection) {
this.setConnection(connection);
this.EntityLoad();
frames.loginResponce();
frames.sendLoginInterfaces();
frames.sendLoginConfigurations();
frames.sendOtherLoginPackets();
setOnline(true);
skills.startBoostingSkill();
if (isDead())
skills.sendDead();
}
public Frames getFrames() {
return frames;
}
public void setConnection(ConnectionHandler connection) {
this.connection = connection;
}
public ConnectionHandler getConnection() {
return connection;
}
public void setUsername(String username) {
Username = username;
}
public String getUsername() {
return Username;
}
public void setDisplayName(String displayName) {
DisplayName = displayName;
}
public String getDisplayName() {
if (DisplayName == null) {
return Username;
}
return DisplayName;
}
public void setPassword(String password) {
Password = password;
}
public String getPassword() {
return Password;
}
public void load(ByteBuffer buffer) {
setLocation(Position.create(buffer.getShort(), buffer.getShort(),
buffer.get()));
for (int i = 0; i < Skills.SKILL_COUNT; i++) {
skills.setLevelAndXP(i, buffer.get(), buffer.getInt());
}
for (int i = 0; i < Inventory.SIZE; i++) {
int id = buffer.getShort();
if (id == -1) {
continue;
}
inventory.getContainer().set(i,
new Item(id, BufferUtils.readItemSmart(buffer)));
}
for (int i = 0; i < Equipment.SIZE; i++) {
int id = buffer.getShort();
if (id == -1) {
continue;
}
equipment.getEquipment().set(i,
new Item(id, BufferUtils.readItemSmart(buffer)));
}
for (int i = 0; i < Banking.SIZE; i++) {
int id = buffer.getShort();
if (id == -1) {
continue;
}
bank.getContainer().set(i,
new Item(id, BufferUtils.readItemSmart(buffer)));
}
}
public void save(ChannelBuffer buffer) { // we use a dynamic buffer
buffer.writeShort((short) getLocation().getX());
buffer.writeShort((short) getLocation().getY());
buffer.writeByte((byte) getLocation().getZ());
for (int i = 0; i < Skills.SKILL_COUNT; i++) {
buffer.writeByte((byte) skills.getLevel(i));
buffer.writeInt((int) skills.getXp(i)); // channel buffer dun have
// double
}
for (int i = 0; i < Inventory.SIZE; i++) {
Item item = inventory.get(i);
if (item == null) {
buffer.writeShort((short) -1);
} else {
buffer.writeShort(item.getId());
BufferUtils.writeItemSmart(item.getAmount(), buffer);
}
}
for (int i = 0; i < Equipment.SIZE; i++) {
Item item = equipment.get(i);
if (item == null) {
buffer.writeShort((short) -1);
} else {
buffer.writeShort(item.getId());
BufferUtils.writeItemSmart(item.getAmount(), buffer);
}
}
for (int i = 0; i < Banking.SIZE; i++) {
Item item = bank.getContainer().get(i);
if (item == null) {
buffer.writeShort((short) -1);
} else {
buffer.writeShort(item.getId());
BufferUtils.writeItemSmart(item.getAmount(), buffer);
}
}
}
public void setSpecialAmount(int amt) {
this.specialAmount = amt;
getFrames().sendConfig2(300, specialAmount);
}
public void setOnline(boolean isOnline) {
this.isOnline = isOnline;
}
public boolean isOnline() {
return isOnline;
}
public void setRights(byte rights) {
this.rights = rights;
}
public byte getRights() {
return rights;
}
public void setNpcListSize(int npcListSize) {
localEntities.npcListSize = npcListSize;
}
public int getNpcListSize() {
return localEntities.npcListSize;
}
public void setNpcList(Npc[] npcList) {
localEntities.npcList = npcList;
}
public Npc[] getNpcList() {
return localEntities.npcList;
}
public void setNpcsInList(byte[] npcsInList) {
localEntities.npcsInList = npcsInList;
}
public byte[] getNpcsInList() {
return localEntities.npcsInList;
}
@Override
public void animate(int id) {
this.getMask().setLastAnimation(new Animation((short) id, (short) 0));
this.getMask().setAnimationUpdate(true);
}
@Override
public void animate(int id, int delay) {
this.getMask().setLastAnimation(
new Animation((short) id, (short) delay));
this.getMask().setAnimationUpdate(true);
}
@Override
public void graphics(int id) {
this.getMask().setLastGraphics(new Graphics((short)id, (short)0, (short)0));
this.getMask().setGraphicUpdate(true);
}
public void graphics2(int id) {
this.getMask().setLastGraphics2(new Graphics((short)id, (short)0, (short)0));
this.getMask().setGraphic2Update(true);
}
public void graphics2(int id, int delay) {
this.getMask().setLastGraphics2(new Graphics((short)id, (short)delay, (short)0));
this.getMask().setGraphic2Update(true);
}
public void graphics2(int id, int delay, int height) {
this.getMask().setLastGraphics2(new Graphics((short)id, (short)delay, (short)height));
this.getMask().setGraphic2Update(true);
}
@Override
public void graphics(int id, int delay, int height) {
this.getMask().setLastGraphics(new Graphics((short)id, (short)delay, (short)height));
this.getMask().setGraphicUpdate(true);
}
@Override
public void graphics(int id, int delay) {
this.getMask().setLastGraphics(new Graphics((short)id, (short)delay, (short)0));
this.getMask().setGraphicUpdate(true);
}
@Override
public void heal(int amount) {
getMask().setLastHeal(new Heal((short) amount, (byte) 0, (byte) 0));
getMask().setHealUpdate(true);
}
public void heal(int healdelay, int bardelay, int healspeed) {
getMask().setLastHeal(
new Heal((short) healdelay, (byte) bardelay, (byte) healspeed));
getMask().setHealUpdate(true);
}
public void processQueuedHits() {
if (!this.getMask().isHitUpdate()) {
if (queuedHits.size() > 0) {
Hit h = queuedHits.poll();
this.hit(h.getDamage(), h.getType());
}
}
if (!this.getMask().isHit2Update()) {
if (queuedHits.size() > 0) {
Hit h = queuedHits.poll();
this.hit(h.getDamage(), h.getType());
}
}
}
public void hit(int damage, Hits.HitType type) {
if (this.skills.getHitPoints() <= 0) {
return;
}
if (!this.getMask().isHitUpdate()) {
this.hits.setHit1(new Hit(damage, type));
this.getMask().setHitUpdate(true);
this.getSkills().hit(damage);
} else if (!this.getMask().isHit2Update()) {
this.hits.setHit2(new Hit(damage, type));
this.getMask().setHit2Update(true);
this.getSkills().hit(damage);
} else {
queuedHits.add(new Hit(damage, type));
}
}
@Override
public void hit(int damage) {
if (damage > this.skills.getHitPoints())
damage = this.skills.getHitPoints();
if (damage == 0) {
hit(damage, Hits.HitType.NO_DAMAGE);
} else if (damage >= 100) {
hit(damage, Hits.HitType.NORMAL_BIG_DAMAGE);
} else {
hit(damage, Hits.HitType.NORMAL_DAMAGE);
}
}
public void hitType(int damage, HitType hitType) {
if (damage > this.skills.getHitPoints())
damage = this.skills.getHitPoints();
hit(damage, hitType);
}
@Override
public void resetTurnTo() {
this.mask.setTurnToIndex(-1);
this.mask.setTurnToReset(true);
this.mask.setTurnToUpdate(true);
}
@Override
public void turnTemporarilyTo(Entity entity) {
this.mask.setTurnToIndex(entity.getClientIndex());
this.mask.setTurnToReset(true);
this.mask.setTurnToUpdate(true);
}
public void turnTemporarilyTo(Position location) {
this.mask.setTurnToLocation(location);
this.mask.setTurnToUpdate1(true);
}
@Override
public void turnTo(Entity entity) {
this.mask.setTurnToIndex(entity.getClientIndex());
this.mask.setTurnToReset(false);
this.mask.setTurnToUpdate(true);
}
public void forceText(String text) {
this.getMask().setLastForceText(new ForceText(text));
this.getMask().setForceTextUpdate(true);
}
public Mask getMask() {
return mask;
}
public void setLocalEntities(LocalEntityList localEntities) {
this.localEntities = localEntities;
}
public LocalEntityList getLocalEntities() {
return localEntities;
}
public Appearance getAppearence() {
return appearance;
}
public Inventory getInventory() {
return inventory;
}
public Equipment getEquipment() {
return equipment;
}
public Skills getSkills() {
return skills;
}
public InterfaceManager getIntermanager() {
return intermanager;
}
public HintIconManager getHinticonmanager() {
return hinticonmanager;
}
public void setInClient(boolean inClient) {
this.inClient = inClient;
}
public boolean isInClient() {
return inClient;
}
public Prayer getPrayer() {
return prayer;
}
public Queue<Hit> getQueuedHits() {
return queuedHits;
}
public Hits getHits() {
return hits;
}
public Gpi getGpi() {
return gpi;
}
public MusicManager getMusicmanager() {
return musicmanager;
}
public Banking getBank() {
return bank;
}
public boolean isLoggedIn() {
return isLoggedIn;
}
public void setLoggedIn(boolean b) {
this.isLoggedIn = b;
}
public WoodCutting getWoodCutting() {
return woodCutting;
}
public Gni getGni() {
return gni;
}
@Override
public void graphics(short gfx, int i, int j) {
}
public int getAttackStyle() {
return attackStyle;
}
public void setAttackStyle(int maxSize) {
this.attackStyle = maxSize;
}
public FletchingManager getFletching() {
return fletching;
}
public Cooking getCooking() {
return cooking;
}
public void resetSkills() {
cooking.reset();
fletching.reset();
}
public boolean itemName(String string) {
if(equipment.get(Equipment.SLOT_WEAPON) == null) {
return false;
}
return this.getEquipment().get(Equipment.SLOT_WEAPON).getDefinition().name.toLowerCase().contains(string);
}
@Override
public FightType getFightType() {
if (equipment.usingRanged()) {
return FightType.RANGE;
}
return FightType.MELEE;
}
@Override
public int getAttackAnimation() {
if (itemName("whip"))
return 1658;
else if (itemName("claws"))
return 393;
else if (itemName("pickaxe"))
return attackStyle == 2 ? 402 : 401;
else if (itemName("Dharok"))
return attackStyle == 2 ? 2067 : 2066;
else if (itemName("Verac"))
return 2062;
else if (itemName("Granite maul"))
return 1665;
else if (itemName("Guthan"))
return attackStyle == 2 ? 2081 : 2080;
else if (itemName("godsword") || itemName("2h sword"))
return attackStyle == 2 ? 7048 : 7041;
else if (itemName("Keris") || itemName("dagger"))
return attackStyle == 2 ? 401 : 402;
else if (itemName("Karil"))
return 2075;
else if (!itemName("Karil") && itemName("crossbow"))
return 4230;
else if (itemName("dart"))
return 582;
else if (itemName("knife"))
return 806;
else if (itemName("bow"))
return 426;
return attackStyle == 2 ? 422 : 423;
}
@Override
public int getAttackDelay() {
return 3;
}
@Override
public int getDefenceAnimation() {
return 1156;
}
public Bonuses getBonuses() {
return bonuses;
}
}