Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.arrow.server.game.world.entity.player;
- import java.io.Serializable;
- import java.util.concurrent.ConcurrentLinkedQueue;
- import com.arrow.GameConstants;
- import com.arrow.server.cache.definitions.ItemDefinitions;
- import com.arrow.server.game.content.action.ActionQueue;
- import com.arrow.server.game.content.dialogue.DialogueInterpreter;
- import com.arrow.server.game.content.eoc.CombatStyle;
- import com.arrow.server.game.content.eoc.ability.AbilityBook;
- import com.arrow.server.game.content.eoc.actionbar.ActionBar;
- import com.arrow.server.game.content.exchange.GrandExchange;
- import com.arrow.server.game.world.entity.Entity;
- import com.arrow.server.game.world.entity.item.Item;
- import com.arrow.server.game.world.entity.item.inventory.Inventory;
- import com.arrow.server.game.world.entity.item.inventory.equipment.EquipSlot;
- import com.arrow.server.game.world.entity.item.inventory.equipment.Equipment;
- import com.arrow.server.game.world.entity.item.inventory.pouch.MoneyPouch;
- import com.arrow.server.game.world.entity.player.manager.CS2ScriptManager;
- import com.arrow.server.game.world.entity.player.manager.EmotesManager;
- import com.arrow.server.game.world.entity.player.manager.InterfaceManager;
- import com.arrow.server.game.world.entity.player.manager.PerformanceManager;
- import com.arrow.server.game.world.entity.player.manager.PropertiesManager;
- import com.arrow.server.game.world.entity.player.skills.Skill;
- import com.arrow.server.game.world.entity.player.skills.Skills;
- import com.arrow.server.game.world.entity.render.NPCRendering;
- import com.arrow.server.game.world.entity.render.PlayerRendering;
- import com.arrow.server.game.world.entity.render.block.movement.route.RouteEvent;
- import com.arrow.server.game.world.region.location.Location;
- import com.arrow.server.network.packet.PacketRepository;
- import com.arrow.server.network.packet.PacketWriter;
- import com.arrow.server.network.packet.event.PacketEventContext;
- import com.arrow.server.network.protocol.login.LoginReadEvent.LoginRequest;
- import com.arrow.server.network.session.Session;
- import com.arrow.server.network.session.impl.GameSession;
- public class Player extends Entity implements Serializable {
- /* Represents Serial UID */
- private static final long serialVersionUID = -4881853363279394569L;
- /**
- * Player Information
- */
- /* Current Route Event */
- private transient RouteEvent routeEvent;
- /* Current Queued Actions */
- private transient ActionQueue actionQueue;
- /* Player's Session */
- private transient GameSession session;
- /* Player Rendering */
- private transient PlayerRendering playerRendering;
- /* NPC Rendering */
- private transient NPCRendering npcRendering;
- /* Player's Information */
- private PlayerInformation playerInformation;
- /**
- * Networking Attributes
- */
- /* Decoder Timeout */
- private transient long decoderTimeout;
- /* Packet Writer */
- private PacketWriter packetWriter;
- /**
- * Player's Containers
- */
- /* Player's Skills */
- private Skills skills;
- /* Player's Equipment */
- private Equipment equipment;
- /* Player's Inventory */
- private Inventory inventory;
- /* Player's Money Pouch */
- private MoneyPouch moneyPouch;
- /* Players Grand Exchange Data */
- private GrandExchange grandExchange;
- /* Player's Action Bar State */
- private ActionBar actionBar;
- /* Player's Ability Book Data */
- private AbilityBook abilityBook;
- /**
- * Player's Managers
- */
- /* Performance Manager */
- private transient PerformanceManager performanceManager;
- /* Interface Manager */
- private transient InterfaceManager interfaceManager;
- /* Dialogue Interpreter */
- private transient DialogueInterpreter dialogueInterpreter;
- /* CS2 Script Manager */
- private transient CS2ScriptManager cs2ScriptManager;
- /* Emotes Manager */
- private EmotesManager emotesManager;
- /* Properties Manager */
- private PropertiesManager propertiesManager;
- /**
- * Constructor used to create Player
- * @param playerInformation
- */
- public Player(PlayerInformation playerInformation) {
- /**
- * Player Networking
- */
- setPlayerRendering(new PlayerRendering(this));
- setNpcRendering(new NPCRendering(this));
- setPacketSender(new PacketWriter(this));
- /**
- * Player Information
- */
- setPlayerInformation(playerInformation);
- setSkills(new Skills(this));
- /**
- * Player Containers
- */
- setEquipment(new Equipment(this));
- setInventory(new Inventory(this));
- setMoneyPouch(new MoneyPouch(this));
- setGrandExchange(new GrandExchange(this));
- /**
- * Action Bars
- */
- setActionBar(new ActionBar(this));
- setAbilityBook(new AbilityBook(this));
- /**
- * Managers
- */
- setPerformanceManager(new PerformanceManager(this));
- setInterfaceManager(new InterfaceManager(this));
- setDialogueInterpreter(new DialogueInterpreter(this));
- setEmotesManager(new EmotesManager(this));
- setCs2ScriptManager(new CS2ScriptManager(this));
- setPropertiesManager(new PropertiesManager(this));
- }
- /**
- * Processes Login
- * @param session
- * @param request
- */
- public void sendLogin(Session session, LoginRequest request) {
- this.session = (GameSession) session;
- switch (request) {
- case REQUEST_LOBBY:
- getPacketManager().sendConfig(1749, 3977);
- getPacketManager().sendConfig(1754, 20);
- getPacketManager().sendConfig(2863, 117440512);
- getPacketManager().sendConfig(2897, -805091453);
- getPacketManager().sendConfig(3184, 1);
- break;
- case REQUEST_WORLD:
- init();
- refreshRegion(true);
- GameConstants.getWorld().getRegionManager().refreshRegionForEntity(this);
- GameConstants.getWorld().getRegionManager().refreshSpawnedObjects(this);
- getPacketManager().sendConfig(1295, 1000);// TUTORIAL
- getInventory().refreshInventory();
- getEquipment().refreshEquipment();
- getSkills().initialize();
- getEmotesManager().refreshEmotes();
- getActionBar().refresh();
- getAbilityBook().refreshBook();
- getMoneyPouch().refreshMoneyPouch();
- getPropertiesManager().refreshRunEnergy();
- getCombatProperties().setMaxHealth(((getSkills().getLevel(Skill.CONSTITUTION) * 40) * 2)
- + getCombatProperties().getBonuses().getLifepoints());
- getCombatProperties().refreshHealth();
- getPacketManager().sendConfig(3274, (getSkills().getLevel(Skill.PRAYER) * 100));
- getPacketManager().sendPlayerOption(1, "Follow");
- getPacketManager().sendPlayerOption(2, "Trade");
- getPacketManager().sendPlayerOption(3, "Req Assist");
- getPacketManager().sendPlayerOption(4, "Challange");
- getPacketManager().sendPlayerOption(5, "Examine");
- getPacketManager().sendOnlineStatus();
- getPacketManager().sendUnlockFriendsList();
- getInterfaceManager().sendInterfaces();
- getRenderProcessor().getAppearance().renderBlock(null);
- setNextLocation(new Location(3222, 3222, 0));
- getPacketManager().sendGlobalConfig(823, 1);// EXTRAS CONFIG
- getPacketManager().sendCS2Script(1211, new Object[] { "Welcome to " + GameConstants.SERVER_NAME + ".", 0, -120, 0 });
- getPacketManager().sendGameMessage("Welcome to " + GameConstants.SERVER_NAME + ".");
- break;
- default:
- break;
- }
- }
- /**
- * Process Logout
- * @param toLobby
- */
- public void sendLogout(boolean toLobby) {
- if (GameConstants.getWorld().containsPlayer(getPlayerInformation().getUsername()))
- GameConstants.getWorld().removePlayer(this);
- if (getActionQueue() != null)
- getActionQueue().emptyRepository();
- if (getCombatSchedule().isCombatStance() && getCombatSchedule().isCombatting()) {
- getCombatSchedule().getVictim().getCombatSchedule().setLock(null);
- getCombatSchedule().getVictim().getCombatSchedule().end();
- getCombatSchedule().setCombatting(false);
- }
- setFinished(true);
- GameConstants.getWorld().getRegionManager().refreshRegionForEntity(this);
- }
- /**
- * Encode packet for player.
- * @param clazz
- * @param event
- */
- public void writePacket(Class<?> clazz, PacketEventContext event) {
- getSession().write(clazz, PacketRepository.writePacket(event));
- }
- /**
- * Force load region.
- */
- public void refreshRegion(boolean login) {
- super.refreshRegion(login);
- getPacketManager().sendRegion(login);
- }
- /**
- * Checks if Player is online.
- * @return online
- */
- public boolean isOnline() {
- if (GameConstants.getWorld().containsPlayer(getPlayerInformation().getUsername()))
- return true;
- return false;
- }
- /**
- * Quick Reset.
- */
- public void reset() {
- reset(true);
- }
- /**
- * Resets all players attributes.
- * @param stopWalk
- */
- public void reset(boolean stopWalk) {
- if (stopWalk)
- getMovement().resetWalkSteps();
- setRouteEvent(null);
- getCombatSchedule().end();
- getActionQueue().dequeAction();
- resetFaceEntity();
- }
- /*
- * (non-Javadoc)
- * @see com.arrow.game.node.entity.Entity#init()
- */
- @Override
- public void init() {
- setSize(1);
- getMovement().setWalkSteps(new ConcurrentLinkedQueue<Object[]>());
- setActionQueue(new ActionQueue());
- setLastFaceEntity(-1);
- setFaceEntity(-2);
- getMovement().setNextWalkDirection(-1);
- getMovement().setNextRunDirection(-1);
- super.init();
- }
- /*
- * (non-Javadoc)
- * @see com.arrow.game.node.entity.Entity#startCycle()
- */
- @Override
- public void startCycle() {
- if (getRouteEvent() != null && getRouteEvent().processEvent(this))
- setRouteEvent(null);
- getMovement().processMovement();
- getActionQueue().cycleAction();
- super.startCycle();
- }
- /*
- * (non-Javadoc)
- * @see com.arrow.game.node.entity.Entity#resetCycle()
- */
- @Override
- public void resetCycle() {
- if (getMovement().getNextWalkDirection() == -1)
- getMovement().setNextFaceLocation(null);
- setFaceEntity(-2);
- getPlayerRendering().reset();
- if (needRegionUpdate())
- GameConstants.getWorld().getRegionManager().refreshSpawnedObjects(this);
- super.resetCycle();
- }
- /*
- * (non-Javadoc)
- * @see com.arrow.game.node.entity.Entity#needMasksUpdate()
- */
- @Override
- public boolean needMasksUpdate() {
- return super.needMasksUpdate() || getFaceEntity() != -2
- || (getMovement().getNextWalkDirection() == -1 && getMovement().getNextFaceLocation() != null);
- }
- /*
- * (non-Javadoc)
- * @see com.arrow.game.node.entity.Entity#getCombatStyle(boolean)
- */
- @Override
- public CombatStyle getCombatStyle(boolean offhand) {
- Item weapon = getEquipment().get(offhand ? EquipSlot.MAIN_HAND : EquipSlot.OFF_HAND);
- if (weapon != null) {
- CombatStyle style = weapon.getDefinitions().getCombatStyle();
- if (style != null) {
- return style;
- }
- }
- return offhand ? null : CombatStyle.MELEE;
- }
- /*
- * (non-Javadoc)
- * @see com.arrow.game.node.entity.Entity#getCombatAnimation(int)
- */
- @Override
- public int getCombatAnimation(int index) {
- int slot = index == 0 ? EquipSlot.MAIN_HAND.ordinal() : EquipSlot.OFF_HAND.ordinal();
- int animId = -1;
- Item item;
- if (index < 2) {
- if ((item = getEquipment().get(slot)) == null) {
- animId = 18226;
- } else {
- animId = item.getDefinitions().getMainhandEmote();
- if (index == 1) {
- animId = item.getDefinitions().getOffhandEmote();
- }
- }
- }
- return animId;
- }
- /*
- * (non-Javadoc)
- * @see com.arrow.game.node.entity.Entity#getRenderEmote()
- */
- @Override
- public int getRenderEmote() {
- int renderId = getRenderProcessor().getAppearance().getCustomRenderAnimation() == -1 ? 2699
- : getRenderProcessor().getAppearance().getCustomRenderAnimation();
- Item item = getEquipment().get(EquipSlot.MAIN_HAND);
- if (getCombatSchedule().isCombatStance()) {
- if (item == null) {
- renderId = 2687;
- } else {
- ItemDefinitions def = getEquipment().get(EquipSlot.MAIN_HAND).getDefinitions();
- renderId = def.getAggressiveAnimation();
- }
- } else {
- if (item == null || getActionBar().isSheathing()) {
- renderId = getRenderProcessor().getAppearance().getCustomRenderAnimation() == -1 ? 2699
- : getRenderProcessor().getAppearance().getCustomRenderAnimation();
- } else {
- ItemDefinitions def = getEquipment().get(EquipSlot.MAIN_HAND).getDefinitions();
- renderId = def.getPassiveAnimation();
- }
- }
- return renderId;
- }
- /*
- * (non-Javadoc)
- * @see com.arrow.game.node.entity.Entity#processDeath()
- */
- @Override
- public void processDeath() {
- // TODO Auto-generated method stub
- }
- /**
- *
- * @return the session
- */
- public GameSession getSession() {
- return session;
- }
- /**
- * @return the routeEvent
- */
- public RouteEvent getRouteEvent() {
- return routeEvent;
- }
- /**
- * @param routeEvent the routeEvent to set
- */
- public void setRouteEvent(RouteEvent routeEvent) {
- this.routeEvent = routeEvent;
- }
- /**
- * @return the actionQueue
- */
- public ActionQueue getActionQueue() {
- return actionQueue;
- }
- /**
- * @param actionQueue the actionQueue to set
- */
- public void setActionQueue(ActionQueue actionQueue) {
- this.actionQueue = actionQueue;
- }
- /**
- * @return the playerRendering
- */
- public PlayerRendering getPlayerRendering() {
- return playerRendering;
- }
- /**
- * @param playerRendering the playerRendering to set
- */
- public void setPlayerRendering(PlayerRendering playerRendering) {
- this.playerRendering = playerRendering;
- }
- /**
- * @return the npcRendering
- */
- public NPCRendering getNpcRendering() {
- return npcRendering;
- }
- /**
- * @param npcRendering the npcRendering to set
- */
- public void setNpcRendering(NPCRendering npcRendering) {
- this.npcRendering = npcRendering;
- }
- /**
- * @return the playerInformation
- */
- public PlayerInformation getPlayerInformation() {
- return playerInformation;
- }
- /**
- * @param playerInformation the playerInformation to set
- */
- public void setPlayerInformation(PlayerInformation playerInformation) {
- this.playerInformation = playerInformation;
- }
- /**
- * @return the packetSender
- */
- public PacketWriter getPacketManager() {
- return packetWriter;
- }
- /**
- * @param packetSender the packetSender to set
- */
- public void setPacketSender(PacketWriter packetSender) {
- this.packetWriter = packetSender;
- }
- /**
- *
- * @return decoderTimeout
- */
- public long getDecoderTimeout() {
- return decoderTimeout;
- }
- /**
- * @return the skills
- */
- public Skills getSkills() {
- return skills;
- }
- /**
- * @param skills the skills to set
- */
- public void setSkills(Skills skills) {
- this.skills = skills;
- }
- /**
- * @return the equipment
- */
- public Equipment getEquipment() {
- return equipment;
- }
- /**
- * @param equipment the equipment to set
- */
- public void setEquipment(Equipment equipment) {
- this.equipment = equipment;
- }
- /**
- * @return the inventory
- */
- public Inventory getInventory() {
- return inventory;
- }
- /**
- * @param inventory the inventory to set
- */
- public void setInventory(Inventory inventory) {
- this.inventory = inventory;
- }
- /**
- * @return the moneyPouch
- */
- public MoneyPouch getMoneyPouch() {
- return moneyPouch;
- }
- /**
- * @param moneyPouch the moneyPouch to set
- */
- public void setMoneyPouch(MoneyPouch moneyPouch) {
- this.moneyPouch = moneyPouch;
- }
- /**
- * @return the grandExchange
- */
- public GrandExchange getGrandExchange() {
- return grandExchange;
- }
- /**
- * @param grandExchange the grandExchange to set
- */
- public void setGrandExchange(GrandExchange grandExchange) {
- this.grandExchange = grandExchange;
- }
- /**
- * @return the actionBar
- */
- public ActionBar getActionBar() {
- return actionBar;
- }
- /**
- * @param actionBar the actionBar to set
- */
- public void setActionBar(ActionBar actionBar) {
- this.actionBar = actionBar;
- }
- /**
- * @return the abilityBook
- */
- public AbilityBook getAbilityBook() {
- return abilityBook;
- }
- /**
- * @param abilityBook the abilityBook to set
- */
- public void setAbilityBook(AbilityBook abilityBook) {
- this.abilityBook = abilityBook;
- }
- /**
- * @return the performanceManager
- */
- public PerformanceManager getPerformanceManager() {
- return performanceManager;
- }
- /**
- * @param performanceManager the performanceManager to set
- */
- public void setPerformanceManager(PerformanceManager performanceManager) {
- this.performanceManager = performanceManager;
- }
- /**
- * @return the interfaceManager
- */
- public InterfaceManager getInterfaceManager() {
- return interfaceManager;
- }
- /**
- * @param interfaceManager the interfaceManager to set
- */
- public void setInterfaceManager(InterfaceManager interfaceManager) {
- this.interfaceManager = interfaceManager;
- }
- /**
- * @return the dialogueInterpreter
- */
- public DialogueInterpreter getDialogueInterpreter() {
- return dialogueInterpreter;
- }
- /**
- * @param dialogueInterpreter the dialogueInterpreter to set
- */
- public void setDialogueInterpreter(DialogueInterpreter dialogueInterpreter) {
- this.dialogueInterpreter = dialogueInterpreter;
- }
- /**
- * @return the cs2ScriptManager
- */
- public CS2ScriptManager getCs2ScriptManager() {
- return cs2ScriptManager;
- }
- /**
- * @param cs2ScriptManager the cs2ScriptManager to set
- */
- public void setCs2ScriptManager(CS2ScriptManager cs2ScriptManager) {
- this.cs2ScriptManager = cs2ScriptManager;
- }
- /**
- * @return the emotesManager
- */
- public EmotesManager getEmotesManager() {
- return emotesManager;
- }
- /**
- * @param emotesManager the emotesManager to set
- */
- public void setEmotesManager(EmotesManager emotesManager) {
- this.emotesManager = emotesManager;
- }
- /**
- * @return the propertiesManager
- */
- public PropertiesManager getPropertiesManager() {
- return propertiesManager;
- }
- /**
- * @param propertiesManager the propertiesManager to set
- */
- public void setPropertiesManager(PropertiesManager propertiesManager) {
- this.propertiesManager = propertiesManager;
- }
- /**
- * @param session the session to set
- */
- public void setSession(GameSession session) {
- this.session = session;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement